diff options
127 files changed, 13469 insertions, 13373 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json index 77e139dbd..829f8f492 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -52,7 +52,7 @@ "request": "attach", "name": "Typescript Server", "protocol": "inspector", - "port": 9230, + "port": 9229, "localRoot": "${workspaceFolder}", "remoteRoot": "${workspaceFolder}" }, diff --git a/deploy/assets/greencheck.png b/deploy/assets/greencheck.png Binary files differnew file mode 100644 index 000000000..064e9def1 --- /dev/null +++ b/deploy/assets/greencheck.png diff --git a/deploy/assets/pdf.worker.js b/deploy/assets/pdf.worker.js index 8a362bd75..6b07e439e 100644 --- a/deploy/assets/pdf.worker.js +++ b/deploy/assets/pdf.worker.js @@ -2,7 +2,7 @@ * @licstart The following is the entire license notice for the * Javascript code in this page * - * Copyright 2018 Mozilla Foundation + * Copyright 2019 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -123,8 +123,8 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; -var pdfjsVersion = '2.1.266'; -var pdfjsBuild = '81f5835c'; +var pdfjsVersion = '2.3.200'; +var pdfjsBuild = '4ae3f9fc'; var pdfjsCoreWorker = __w_pdfjs_require__(1); @@ -144,25 +144,27 @@ exports.WorkerMessageHandler = exports.WorkerTask = void 0; var _regenerator = _interopRequireDefault(__w_pdfjs_require__(2)); -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _pdf_manager = __w_pdfjs_require__(151); +var _primitives = __w_pdfjs_require__(183); -var _is_node = _interopRequireDefault(__w_pdfjs_require__(9)); +var _pdf_manager = __w_pdfjs_require__(184); -var _message_handler = __w_pdfjs_require__(189); +var _is_node = _interopRequireDefault(__w_pdfjs_require__(8)); -var _primitives = __w_pdfjs_require__(155); +var _message_handler = __w_pdfjs_require__(223); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +var _worker_stream = __w_pdfjs_require__(224); -function _typeof(obj) { 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 _core_utils = __w_pdfjs_require__(186); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } -function _iterableToArrayLimit(arr, i) { 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 _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { 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; } @@ -198,141 +200,6 @@ var WorkerTask = function WorkerTaskClosure() { }(); exports.WorkerTask = WorkerTask; - -var PDFWorkerStream = function PDFWorkerStreamClosure() { - function PDFWorkerStream(msgHandler) { - this._msgHandler = msgHandler; - this._contentLength = null; - this._fullRequestReader = null; - this._rangeRequestReaders = []; - } - - PDFWorkerStream.prototype = { - getFullReader: function getFullReader() { - (0, _util.assert)(!this._fullRequestReader); - this._fullRequestReader = new PDFWorkerStreamReader(this._msgHandler); - return this._fullRequestReader; - }, - getRangeReader: function getRangeReader(begin, end) { - var reader = new PDFWorkerStreamRangeReader(begin, end, this._msgHandler); - - this._rangeRequestReaders.push(reader); - - return reader; - }, - cancelAllRequests: function cancelAllRequests(reason) { - if (this._fullRequestReader) { - this._fullRequestReader.cancel(reason); - } - - var readers = this._rangeRequestReaders.slice(0); - - readers.forEach(function (reader) { - reader.cancel(reason); - }); - } - }; - - function PDFWorkerStreamReader(msgHandler) { - var _this = this; - - this._msgHandler = msgHandler; - this._contentLength = null; - this._isRangeSupported = false; - this._isStreamingSupported = false; - - var readableStream = this._msgHandler.sendWithStream('GetReader'); - - this._reader = readableStream.getReader(); - this._headersReady = this._msgHandler.sendWithPromise('ReaderHeadersReady').then(function (data) { - _this._isStreamingSupported = data.isStreamingSupported; - _this._isRangeSupported = data.isRangeSupported; - _this._contentLength = data.contentLength; - }); - } - - PDFWorkerStreamReader.prototype = { - get headersReady() { - return this._headersReady; - }, - - get contentLength() { - return this._contentLength; - }, - - get isStreamingSupported() { - return this._isStreamingSupported; - }, - - get isRangeSupported() { - return this._isRangeSupported; - }, - - read: function read() { - return this._reader.read().then(function (_ref) { - var value = _ref.value, - done = _ref.done; - - if (done) { - return { - value: undefined, - done: true - }; - } - - return { - value: value.buffer, - done: false - }; - }); - }, - cancel: function cancel(reason) { - this._reader.cancel(reason); - } - }; - - function PDFWorkerStreamRangeReader(begin, end, msgHandler) { - this._msgHandler = msgHandler; - this.onProgress = null; - - var readableStream = this._msgHandler.sendWithStream('GetRangeReader', { - begin: begin, - end: end - }); - - this._reader = readableStream.getReader(); - } - - PDFWorkerStreamRangeReader.prototype = { - get isStreamingSupported() { - return false; - }, - - read: function read() { - return this._reader.read().then(function (_ref2) { - var value = _ref2.value, - done = _ref2.done; - - if (done) { - return { - value: undefined, - done: true - }; - } - - return { - value: value.buffer, - done: false - }; - }); - }, - cancel: function cancel(reason) { - this._reader.cancel(reason); - } - }; - return PDFWorkerStream; -}(); - var WorkerMessageHandler = { setup: function setup(handler, port) { var testMessageProcessed = false; @@ -344,28 +211,13 @@ var WorkerMessageHandler = { testMessageProcessed = true; if (!(data instanceof Uint8Array)) { - handler.send('test', false); + handler.send('test', null); return; } var supportTransfers = data[0] === 255; handler.postMessageTransfers = supportTransfers; - var xhr = new XMLHttpRequest(); - var responseExists = 'response' in xhr; - - try { - xhr.responseType; - } catch (e) { - responseExists = false; - } - - if (!responseExists) { - handler.send('test', false); - return; - } - handler.send('test', { - supportTypedArray: true, supportTransfers: supportTransfers }); }); @@ -381,8 +233,9 @@ var WorkerMessageHandler = { var terminated = false; var cancelXHRs = null; var WorkerTasks = []; + var verbosity = (0, _util.getVerbosityLevel)(); var apiVersion = docParams.apiVersion; - var workerVersion = '2.1.266'; + var workerVersion = '2.3.200'; if (apiVersion !== workerVersion) { throw new Error("The API version \"".concat(apiVersion, "\" does not match ") + "the Worker version \"".concat(workerVersion, "\".")); @@ -417,10 +270,10 @@ var WorkerMessageHandler = { function _loadDocument() { _loadDocument = _asyncToGenerator( /*#__PURE__*/ - _regenerator.default.mark(function _callee(recoveryMode) { - var _ref6, _ref7, numPages, fingerprint; + _regenerator["default"].mark(function _callee(recoveryMode) { + var _ref4, _ref5, numPages, fingerprint; - return _regenerator.default.wrap(function _callee$(_context) { + return _regenerator["default"].wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: @@ -449,10 +302,10 @@ var WorkerMessageHandler = { return Promise.all([pdfManager.ensureDoc('numPages'), pdfManager.ensureDoc('fingerprint')]); case 11: - _ref6 = _context.sent; - _ref7 = _slicedToArray(_ref6, 2); - numPages = _ref7[0]; - fingerprint = _ref7[1]; + _ref4 = _context.sent; + _ref5 = _slicedToArray(_ref4, 2); + numPages = _ref5[0]; + fingerprint = _ref5[1]; return _context.abrupt("return", { numPages: numPages, fingerprint: fingerprint @@ -463,7 +316,7 @@ var WorkerMessageHandler = { return _context.stop(); } } - }, _callee, this); + }, _callee); })); return _loadDocument.apply(this, arguments); } @@ -488,7 +341,7 @@ var WorkerMessageHandler = { cachedChunks = []; try { - pdfStream = new PDFWorkerStream(handler); + pdfStream = new _worker_stream.PDFWorkerStream(handler); } catch (ex) { pdfManagerCapability.reject(ex); return pdfManagerCapability.promise; @@ -516,7 +369,7 @@ var WorkerMessageHandler = { cachedChunks = []; pdfManagerCapability.resolve(pdfManager); cancelXHRs = null; - }).catch(function (reason) { + })["catch"](function (reason) { pdfManagerCapability.reject(reason); cancelXHRs = null; }); @@ -577,13 +430,13 @@ var WorkerMessageHandler = { fullRequest.read().then(readChunk, reject); }); - readPromise.catch(function (e) { + readPromise["catch"](function (e) { pdfManagerCapability.reject(e); cancelXHRs = null; }); - cancelXHRs = function cancelXHRs() { - pdfStream.cancelAllRequests('abort'); + cancelXHRs = function cancelXHRs(reason) { + pdfStream.cancelAllRequests(reason); }; return pdfManagerCapability.promise; @@ -607,7 +460,7 @@ var WorkerMessageHandler = { finishWorkerTask(task); pdfManager.updatePassword(data.password); pdfManagerReady(); - }).catch(function (boundException) { + })["catch"](function (boundException) { finishWorkerTask(task); handler.send('PasswordException', boundException); }.bind(null, e)); @@ -627,7 +480,7 @@ var WorkerMessageHandler = { loadDocument(false).then(onSuccess, function loadFailure(ex) { ensureNotTerminated(); - if (!(ex instanceof _util.XRefParseException)) { + if (!(ex instanceof _core_utils.XRefParseException)) { onFailure(ex); return; } @@ -651,7 +504,7 @@ var WorkerMessageHandler = { }; getPdfManager(data, evaluatorOptions).then(function (newPdfManager) { if (terminated) { - newPdfManager.terminate(); + newPdfManager.terminate(new _util.AbortException('Worker was terminated.')); throw new Error('Worker was terminated'); } @@ -666,12 +519,12 @@ var WorkerMessageHandler = { handler.on('GetPage', function wphSetupGetPage(data) { return pdfManager.getPage(data.pageIndex).then(function (page) { - return Promise.all([pdfManager.ensure(page, 'rotate'), pdfManager.ensure(page, 'ref'), pdfManager.ensure(page, 'userUnit'), pdfManager.ensure(page, 'view')]).then(function (_ref3) { - var _ref4 = _slicedToArray(_ref3, 4), - rotate = _ref4[0], - ref = _ref4[1], - userUnit = _ref4[2], - view = _ref4[3]; + return Promise.all([pdfManager.ensure(page, 'rotate'), pdfManager.ensure(page, 'ref'), pdfManager.ensure(page, 'userUnit'), pdfManager.ensure(page, 'view')]).then(function (_ref) { + var _ref2 = _slicedToArray(_ref, 4), + rotate = _ref2[0], + ref = _ref2[1], + userUnit = _ref2[2], + view = _ref2[3]; return { rotate: rotate, @@ -683,7 +536,8 @@ var WorkerMessageHandler = { }); }); handler.on('GetPageIndex', function wphSetupGetPageIndex(data) { - var ref = new _primitives.Ref(data.ref.num, data.ref.gen); + var ref = _primitives.Ref.get(data.ref.num, data.ref.gen); + var catalog = pdfManager.pdfDocument.catalog; return catalog.getPageIndex(ref); }); @@ -696,10 +550,16 @@ var WorkerMessageHandler = { handler.on('GetPageLabels', function wphSetupGetPageLabels(data) { return pdfManager.ensureCatalog('pageLabels'); }); + handler.on('GetPageLayout', function wphSetupGetPageLayout(data) { + return pdfManager.ensureCatalog('pageLayout'); + }); handler.on('GetPageMode', function wphSetupGetPageMode(data) { return pdfManager.ensureCatalog('pageMode'); }); - handler.on('getOpenActionDestination', function (data) { + handler.on('GetViewerPreferences', function (data) { + return pdfManager.ensureCatalog('viewerPreferences'); + }); + handler.on('GetOpenActionDestination', function (data) { return pdfManager.ensureCatalog('openActionDestination'); }); handler.on('GetAttachments', function wphSetupGetAttachments(data) { @@ -726,29 +586,34 @@ var WorkerMessageHandler = { handler.on('GetStats', function wphSetupGetStats(data) { return pdfManager.pdfDocument.xref.stats; }); - handler.on('GetAnnotations', function (_ref5) { - var pageIndex = _ref5.pageIndex, - intent = _ref5.intent; + handler.on('GetAnnotations', function (_ref3) { + var pageIndex = _ref3.pageIndex, + intent = _ref3.intent; return pdfManager.getPage(pageIndex).then(function (page) { return page.getAnnotationsData(intent); }); }); - handler.on('RenderPageRequest', function wphSetupRenderPage(data) { + handler.on('GetOperatorList', function wphSetupRenderPage(data, sink) { var pageIndex = data.pageIndex; pdfManager.getPage(pageIndex).then(function (page) { - var task = new WorkerTask('RenderPageRequest: page ' + pageIndex); + var task = new WorkerTask("GetOperatorList: page ".concat(pageIndex)); startWorkerTask(task); - var pageNum = pageIndex + 1; - var start = Date.now(); + var start = verbosity >= _util.VerbosityLevel.INFOS ? Date.now() : 0; page.getOperatorList({ handler: handler, + sink: sink, task: task, intent: data.intent, renderInteractiveForms: data.renderInteractiveForms - }).then(function (operatorList) { + }).then(function (operatorListInfo) { finishWorkerTask(task); - (0, _util.info)('page=' + pageNum + ' - getOperatorList: time=' + (Date.now() - start) + 'ms, len=' + operatorList.totalLength); - }, function (e) { + + if (start) { + (0, _util.info)("page=".concat(pageIndex + 1, " - getOperatorList: time=") + "".concat(Date.now() - start, "ms, len=").concat(operatorListInfo.length)); + } + + sink.close(); + }, function (reason) { finishWorkerTask(task); if (task.terminated) { @@ -758,31 +623,7 @@ var WorkerMessageHandler = { handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.unknown }); - var minimumStackMessage = 'worker.js: while trying to getPage() and getOperatorList()'; - var wrappedException; - - if (typeof e === 'string') { - wrappedException = { - message: e, - stack: minimumStackMessage - }; - } else if (_typeof(e) === 'object') { - wrappedException = { - message: e.message || e.toString(), - stack: e.stack || minimumStackMessage - }; - } else { - wrappedException = { - message: 'Unknown exception type: ' + _typeof(e), - stack: minimumStackMessage - }; - } - - handler.send('PageError', { - pageNum: pageNum, - error: wrappedException, - intent: data.intent - }); + sink.error(reason); }); }); }, this); @@ -796,8 +637,7 @@ var WorkerMessageHandler = { pdfManager.getPage(pageIndex).then(function (page) { var task = new WorkerTask('GetTextContent: page ' + pageIndex); startWorkerTask(task); - var pageNum = pageIndex + 1; - var start = Date.now(); + var start = verbosity >= _util.VerbosityLevel.INFOS ? Date.now() : 0; page.extractTextContent({ handler: handler, task: task, @@ -806,7 +646,11 @@ var WorkerMessageHandler = { combineTextItems: data.combineTextItems }).then(function () { finishWorkerTask(task); - (0, _util.info)('text indexing: page=' + pageNum + ' - time=' + (Date.now() - start) + 'ms'); + + if (start) { + (0, _util.info)("page=".concat(pageIndex + 1, " - getTextContent: time=") + "".concat(Date.now() - start, "ms")); + } + sink.close(); }, function (reason) { finishWorkerTask(task); @@ -816,7 +660,6 @@ var WorkerMessageHandler = { } sink.error(reason); - throw reason; }); }); }); @@ -830,14 +673,15 @@ var WorkerMessageHandler = { terminated = true; if (pdfManager) { - pdfManager.terminate(); + pdfManager.terminate(new _util.AbortException('Worker was terminated.')); pdfManager = null; } if (cancelXHRs) { - cancelXHRs(); + cancelXHRs(new _util.AbortException('Worker was terminated.')); } + (0, _primitives.clearPrimitiveCaches)(); var waitOn = []; WorkerTasks.forEach(function (task) { waitOn.push(task.finished); @@ -866,7 +710,7 @@ function isMessagePort(maybePort) { return typeof maybePort.postMessage === 'function' && 'onmessage' in maybePort; } -if (typeof window === 'undefined' && !(0, _is_node.default)() && typeof self !== 'undefined' && isMessagePort(self)) { +if (typeof window === 'undefined' && !(0, _is_node["default"])() && typeof self !== 'undefined' && isMessagePort(self)) { WorkerMessageHandler.initializeFromPort(self); } @@ -884,39 +728,11 @@ module.exports = __w_pdfjs_require__(3); /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - - -function _typeof(obj) { 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 g = function () { - return this || (typeof self === "undefined" ? "undefined" : _typeof(self)) === "object" && self; -}() || Function("return this")(); - -var hadRuntime = g.regeneratorRuntime && Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime") >= 0; -var oldRuntime = hadRuntime && g.regeneratorRuntime; -g.regeneratorRuntime = undefined; -module.exports = __w_pdfjs_require__(4); - -if (hadRuntime) { - g.regeneratorRuntime = oldRuntime; -} else { - try { - delete g.regeneratorRuntime; - } catch (e) { - g.regeneratorRuntime = undefined; - } -} - -/***/ }), -/* 4 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; /* WEBPACK VAR INJECTION */(function(module) { function _typeof(obj) { 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 (global) { +var runtime = function (exports) { "use strict"; var Op = Object.prototype; @@ -926,18 +742,6 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat var iteratorSymbol = $Symbol.iterator || "@@iterator"; var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; - var inModule = ( false ? undefined : _typeof(module)) === "object"; - var runtime = global.regeneratorRuntime; - - if (runtime) { - if (inModule) { - module.exports = runtime; - } - - return; - } - - runtime = global.regeneratorRuntime = inModule ? module.exports : {}; function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; @@ -947,7 +751,7 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat return generator; } - runtime.wrap = wrap; + exports.wrap = wrap; function tryCatch(fn, obj, arg) { try { @@ -1001,12 +805,12 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat }); } - runtime.isGeneratorFunction = function (genFun) { + exports.isGeneratorFunction = function (genFun) { var ctor = typeof genFun === "function" && genFun.constructor; return ctor ? ctor === GeneratorFunction || (ctor.displayName || ctor.name) === "GeneratorFunction" : false; }; - runtime.mark = function (genFun) { + exports.mark = function (genFun) { if (Object.setPrototypeOf) { Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); } else { @@ -1021,7 +825,7 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat return genFun; }; - runtime.awrap = function (arg) { + exports.awrap = function (arg) { return { __await: arg }; @@ -1075,11 +879,11 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat return this; }; - runtime.AsyncIterator = AsyncIterator; + exports.AsyncIterator = AsyncIterator; - runtime.async = function (innerFn, outerFn, self, tryLocsList) { + exports.async = function (innerFn, outerFn, self, tryLocsList) { var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList)); - return runtime.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { + return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }; @@ -1157,7 +961,7 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat context.delegate = null; if (context.method === "throw") { - if (delegate.iterator.return) { + if (delegate.iterator["return"]) { context.method = "return"; context.arg = undefined; maybeInvokeDelegate(delegate, context); @@ -1251,7 +1055,7 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat this.reset(true); } - runtime.keys = function (object) { + exports.keys = function (object) { var keys = []; for (var key in object) { @@ -1312,7 +1116,7 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat }; } - runtime.values = values; + exports.values = values; function doneResult() { return { @@ -1490,13 +1294,18 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat return ContinueSentinel; } }; -}(function () { - return this || (typeof self === "undefined" ? "undefined" : _typeof(self)) === "object" && self; -}() || Function("return this")()); -/* WEBPACK VAR INJECTION */}.call(this, __w_pdfjs_require__(5)(module))) + return exports; +}(( false ? undefined : _typeof(module)) === "object" ? module.exports : {}); + +try { + regeneratorRuntime = runtime; +} catch (accidentalStrictMode) { + Function("r", "regeneratorRuntime = r")(runtime); +} +/* WEBPACK VAR INJECTION */}.call(this, __w_pdfjs_require__(4)(module))) /***/ }), -/* 5 */ +/* 4 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -1527,7 +1336,7 @@ module.exports = function (module) { }; /***/ }), -/* 6 */ +/* 5 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -1536,18 +1345,15 @@ module.exports = function (module) { Object.defineProperty(exports, "__esModule", { value: true }); -exports.toRomanNumerals = toRomanNumerals; exports.arrayByteLength = arrayByteLength; exports.arraysToBytes = arraysToBytes; exports.assert = assert; exports.bytesToString = bytesToString; exports.createPromiseCapability = createPromiseCapability; -exports.deprecated = deprecated; -exports.getInheritableProperty = getInheritableProperty; -exports.getLookupTableFactory = getLookupTableFactory; exports.getVerbosityLevel = getVerbosityLevel; exports.info = info; exports.isArrayBuffer = isArrayBuffer; +exports.isArrayEqual = isArrayEqual; exports.isBool = isBool; exports.isEmptyObj = isEmptyObj; exports.isNum = isNum; @@ -1573,26 +1379,34 @@ exports.warn = warn; exports.unreachable = unreachable; Object.defineProperty(exports, "ReadableStream", { enumerable: true, - get: function get() { + get: function () { return _streams_polyfill.ReadableStream; } }); -Object.defineProperty(exports, "URL", { - enumerable: true, - get: function get() { - return _url_polyfill.URL; - } -}); -exports.createObjectURL = exports.FormatError = exports.XRefParseException = exports.XRefEntryException = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.NativeImageDecoding = exports.MissingPDFException = exports.MissingDataException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = void 0; +exports.createObjectURL = exports.FormatError = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.NativeImageDecoding = exports.MissingPDFException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = exports.BaseException = void 0; -__w_pdfjs_require__(7); +__w_pdfjs_require__(6); -var _streams_polyfill = __w_pdfjs_require__(147); +var _streams_polyfill = __w_pdfjs_require__(181); -var _url_polyfill = __w_pdfjs_require__(149); +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; } function _typeof(obj) { 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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; exports.IDENTITY_MATRIX = IDENTITY_MATRIX; var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0]; @@ -1662,6 +1476,29 @@ var AnnotationType = { REDACT: 26 }; exports.AnnotationType = AnnotationType; +var AnnotationStateModelType = { + MARKED: 'Marked', + REVIEW: 'Review' +}; +exports.AnnotationStateModelType = AnnotationStateModelType; +var AnnotationMarkedState = { + MARKED: 'Marked', + UNMARKED: 'Unmarked' +}; +exports.AnnotationMarkedState = AnnotationMarkedState; +var AnnotationReviewState = { + ACCEPTED: 'Accepted', + REJECTED: 'Rejected', + CANCELLED: 'Cancelled', + COMPLETED: 'Completed', + NONE: 'None' +}; +exports.AnnotationReviewState = AnnotationReviewState; +var AnnotationReplyType = { + GROUP: 'Group', + REPLY: 'R' +}; +exports.AnnotationReplyType = AnnotationReplyType; var AnnotationFlag = { INVISIBLE: 0x01, HIDDEN: 0x02, @@ -1706,30 +1543,30 @@ var AnnotationBorderStyleType = { }; exports.AnnotationBorderStyleType = AnnotationBorderStyleType; var StreamType = { - UNKNOWN: 0, - FLATE: 1, - LZW: 2, - DCT: 3, - JPX: 4, - JBIG: 5, - A85: 6, - AHX: 7, - CCF: 8, - RL: 9 + UNKNOWN: 'UNKNOWN', + FLATE: 'FLATE', + LZW: 'LZW', + DCT: 'DCT', + JPX: 'JPX', + JBIG: 'JBIG', + A85: 'A85', + AHX: 'AHX', + CCF: 'CCF', + RLX: 'RLX' }; exports.StreamType = StreamType; var FontType = { - UNKNOWN: 0, - TYPE1: 1, - TYPE1C: 2, - CIDFONTTYPE0: 3, - CIDFONTTYPE0C: 4, - TRUETYPE: 5, - CIDFONTTYPE2: 6, - TYPE3: 7, - OPENTYPE: 8, - TYPE0: 9, - MMTYPE1: 10 + UNKNOWN: 'UNKNOWN', + TYPE1: 'TYPE1', + TYPE1C: 'TYPE1C', + CIDFONTTYPE0: 'CIDFONTTYPE0', + CIDFONTTYPE0C: 'CIDFONTTYPE0C', + TRUETYPE: 'TRUETYPE', + CIDFONTTYPE2: 'CIDFONTTYPE2', + TYPE3: 'TYPE3', + OPENTYPE: 'OPENTYPE', + TYPE0: 'TYPE0', + MMTYPE1: 'MMTYPE1' }; exports.FontType = FontType; var VerbosityLevel = { @@ -1866,20 +1703,16 @@ function getVerbosityLevel() { function info(msg) { if (verbosity >= VerbosityLevel.INFOS) { - console.log('Info: ' + msg); + console.log("Info: ".concat(msg)); } } function warn(msg) { if (verbosity >= VerbosityLevel.WARNINGS) { - console.log('Warning: ' + msg); + console.log("Warning: ".concat(msg)); } } -function deprecated(details) { - console.log('Deprecated API usage: ' + details); -} - function unreachable(msg) { throw new Error(msg); } @@ -1891,8 +1724,10 @@ function assert(cond, msg) { } function isSameOrigin(baseUrl, otherUrl) { + var base; + try { - var base = new _url_polyfill.URL(baseUrl); + base = new URL(baseUrl); if (!base.origin || base.origin === 'null') { return false; @@ -1901,7 +1736,7 @@ function isSameOrigin(baseUrl, otherUrl) { return false; } - var other = new _url_polyfill.URL(otherUrl, base); + var other = new URL(otherUrl, base); return base.origin === other.origin; } @@ -1929,7 +1764,7 @@ function createValidAbsoluteUrl(url, baseUrl) { } try { - var absoluteUrl = baseUrl ? new _url_polyfill.URL(url, baseUrl) : new _url_polyfill.URL(url); + var absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url); if (_isValidProtocol(absoluteUrl)) { return absoluteUrl; @@ -1949,151 +1784,144 @@ function shadow(obj, prop, value) { return value; } -function getLookupTableFactory(initializer) { - var lookup; - return function () { - if (initializer) { - lookup = Object.create(null); - initializer(lookup); - initializer = null; +var BaseException = function BaseExceptionClosure() { + function BaseException(message) { + if (this.constructor === BaseException) { + unreachable('Cannot initialize BaseException.'); } - return lookup; - }; -} + this.message = message; + this.name = this.constructor.name; + } + + BaseException.prototype = new Error(); + BaseException.constructor = BaseException; + return BaseException; +}(); + +exports.BaseException = BaseException; + +var PasswordException = +/*#__PURE__*/ +function (_BaseException) { + _inherits(PasswordException, _BaseException); -var PasswordException = function PasswordExceptionClosure() { function PasswordException(msg, code) { - this.name = 'PasswordException'; - this.message = msg; - this.code = code; + var _this; + + _classCallCheck(this, PasswordException); + + _this = _possibleConstructorReturn(this, _getPrototypeOf(PasswordException).call(this, msg)); + _this.code = code; + return _this; } - PasswordException.prototype = new Error(); - PasswordException.constructor = PasswordException; return PasswordException; -}(); +}(BaseException); exports.PasswordException = PasswordException; -var UnknownErrorException = function UnknownErrorExceptionClosure() { +var UnknownErrorException = +/*#__PURE__*/ +function (_BaseException2) { + _inherits(UnknownErrorException, _BaseException2); + function UnknownErrorException(msg, details) { - this.name = 'UnknownErrorException'; - this.message = msg; - this.details = details; + var _this2; + + _classCallCheck(this, UnknownErrorException); + + _this2 = _possibleConstructorReturn(this, _getPrototypeOf(UnknownErrorException).call(this, msg)); + _this2.details = details; + return _this2; } - UnknownErrorException.prototype = new Error(); - UnknownErrorException.constructor = UnknownErrorException; return UnknownErrorException; -}(); +}(BaseException); exports.UnknownErrorException = UnknownErrorException; -var InvalidPDFException = function InvalidPDFExceptionClosure() { - function InvalidPDFException(msg) { - this.name = 'InvalidPDFException'; - this.message = msg; +var InvalidPDFException = +/*#__PURE__*/ +function (_BaseException3) { + _inherits(InvalidPDFException, _BaseException3); + + function InvalidPDFException() { + _classCallCheck(this, InvalidPDFException); + + return _possibleConstructorReturn(this, _getPrototypeOf(InvalidPDFException).apply(this, arguments)); } - InvalidPDFException.prototype = new Error(); - InvalidPDFException.constructor = InvalidPDFException; return InvalidPDFException; -}(); +}(BaseException); exports.InvalidPDFException = InvalidPDFException; -var MissingPDFException = function MissingPDFExceptionClosure() { - function MissingPDFException(msg) { - this.name = 'MissingPDFException'; - this.message = msg; - } - - MissingPDFException.prototype = new Error(); - MissingPDFException.constructor = MissingPDFException; - return MissingPDFException; -}(); +var MissingPDFException = +/*#__PURE__*/ +function (_BaseException4) { + _inherits(MissingPDFException, _BaseException4); -exports.MissingPDFException = MissingPDFException; + function MissingPDFException() { + _classCallCheck(this, MissingPDFException); -var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() { - function UnexpectedResponseException(msg, status) { - this.name = 'UnexpectedResponseException'; - this.message = msg; - this.status = status; + return _possibleConstructorReturn(this, _getPrototypeOf(MissingPDFException).apply(this, arguments)); } - UnexpectedResponseException.prototype = new Error(); - UnexpectedResponseException.constructor = UnexpectedResponseException; - return UnexpectedResponseException; -}(); + return MissingPDFException; +}(BaseException); -exports.UnexpectedResponseException = UnexpectedResponseException; +exports.MissingPDFException = MissingPDFException; -var MissingDataException = function MissingDataExceptionClosure() { - function MissingDataException(begin, end) { - this.begin = begin; - this.end = end; - this.message = 'Missing data [' + begin + ', ' + end + ')'; - } +var UnexpectedResponseException = +/*#__PURE__*/ +function (_BaseException5) { + _inherits(UnexpectedResponseException, _BaseException5); - MissingDataException.prototype = new Error(); - MissingDataException.prototype.name = 'MissingDataException'; - MissingDataException.constructor = MissingDataException; - return MissingDataException; -}(); + function UnexpectedResponseException(msg, status) { + var _this3; -exports.MissingDataException = MissingDataException; + _classCallCheck(this, UnexpectedResponseException); -var XRefEntryException = function XRefEntryExceptionClosure() { - function XRefEntryException(msg) { - this.message = msg; + _this3 = _possibleConstructorReturn(this, _getPrototypeOf(UnexpectedResponseException).call(this, msg)); + _this3.status = status; + return _this3; } - XRefEntryException.prototype = new Error(); - XRefEntryException.prototype.name = 'XRefEntryException'; - XRefEntryException.constructor = XRefEntryException; - return XRefEntryException; -}(); - -exports.XRefEntryException = XRefEntryException; + return UnexpectedResponseException; +}(BaseException); -var XRefParseException = function XRefParseExceptionClosure() { - function XRefParseException(msg) { - this.message = msg; - } +exports.UnexpectedResponseException = UnexpectedResponseException; - XRefParseException.prototype = new Error(); - XRefParseException.prototype.name = 'XRefParseException'; - XRefParseException.constructor = XRefParseException; - return XRefParseException; -}(); +var FormatError = +/*#__PURE__*/ +function (_BaseException6) { + _inherits(FormatError, _BaseException6); -exports.XRefParseException = XRefParseException; + function FormatError() { + _classCallCheck(this, FormatError); -var FormatError = function FormatErrorClosure() { - function FormatError(msg) { - this.message = msg; + return _possibleConstructorReturn(this, _getPrototypeOf(FormatError).apply(this, arguments)); } - FormatError.prototype = new Error(); - FormatError.prototype.name = 'FormatError'; - FormatError.constructor = FormatError; return FormatError; -}(); +}(BaseException); exports.FormatError = FormatError; -var AbortException = function AbortExceptionClosure() { - function AbortException(msg) { - this.name = 'AbortException'; - this.message = msg; +var AbortException = +/*#__PURE__*/ +function (_BaseException7) { + _inherits(AbortException, _BaseException7); + + function AbortException() { + _classCallCheck(this, AbortException); + + return _possibleConstructorReturn(this, _getPrototypeOf(AbortException).apply(this, arguments)); } - AbortException.prototype = new Error(); - AbortException.constructor = AbortException; return AbortException; -}(); +}(BaseException); exports.AbortException = AbortException; var NullCharactersRegExp = /\x00/g; @@ -2149,26 +1977,23 @@ function arrayByteLength(arr) { } function arraysToBytes(arr) { - if (arr.length === 1 && arr[0] instanceof Uint8Array) { + var length = arr.length; + + if (length === 1 && arr[0] instanceof Uint8Array) { return arr[0]; } var resultLength = 0; - var i, - ii = arr.length; - var item, itemLength; - for (i = 0; i < ii; i++) { - item = arr[i]; - itemLength = arrayByteLength(item); - resultLength += itemLength; + for (var i = 0; i < length; i++) { + resultLength += arrayByteLength(arr[i]); } var pos = 0; var data = new Uint8Array(resultLength); - for (i = 0; i < ii; i++) { - item = arr[i]; + for (var _i = 0; _i < length; _i++) { + var item = arr[_i]; if (!(item instanceof Uint8Array)) { if (typeof item === 'string') { @@ -2178,7 +2003,7 @@ function arraysToBytes(arr) { } } - itemLength = item.byteLength; + var itemLength = item.byteLength; data.set(item, pos); pos += itemLength; } @@ -2226,189 +2051,143 @@ function isEvalSupported() { } } -function getInheritableProperty(_ref) { - var dict = _ref.dict, - key = _ref.key, - _ref$getArray = _ref.getArray, - getArray = _ref$getArray === void 0 ? false : _ref$getArray, - _ref$stopWhenFound = _ref.stopWhenFound, - stopWhenFound = _ref$stopWhenFound === void 0 ? true : _ref$stopWhenFound; - var LOOP_LIMIT = 100; - var loopCount = 0; - var values; - - while (dict) { - var value = getArray ? dict.getArray(key) : dict.get(key); +var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')']; - if (value !== undefined) { - if (stopWhenFound) { - return value; - } - - if (!values) { - values = []; - } +var Util = +/*#__PURE__*/ +function () { + function Util() { + _classCallCheck(this, Util); + } - values.push(value); + _createClass(Util, null, [{ + key: "makeCssRgb", + value: function makeCssRgb(r, g, b) { + rgbBuf[1] = r; + rgbBuf[3] = g; + rgbBuf[5] = b; + return rgbBuf.join(''); } - - if (++loopCount > LOOP_LIMIT) { - warn("getInheritableProperty: maximum loop count exceeded for \"".concat(key, "\"")); - break; + }, { + key: "transform", + value: function transform(m1, m2) { + return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]]; } - - dict = dict.get('Parent'); - } - - return values; -} - -var Util = function UtilClosure() { - function Util() {} - - var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')']; - - Util.makeCssRgb = function Util_makeCssRgb(r, g, b) { - rgbBuf[1] = r; - rgbBuf[3] = g; - rgbBuf[5] = b; - return rgbBuf.join(''); - }; - - Util.transform = function Util_transform(m1, m2) { - return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]]; - }; - - Util.applyTransform = function Util_applyTransform(p, m) { - var xt = p[0] * m[0] + p[1] * m[2] + m[4]; - var yt = p[0] * m[1] + p[1] * m[3] + m[5]; - return [xt, yt]; - }; - - Util.applyInverseTransform = function Util_applyInverseTransform(p, m) { - var d = m[0] * m[3] - m[1] * m[2]; - var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d; - var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d; - return [xt, yt]; - }; - - Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) { - var p1 = Util.applyTransform(r, m); - var p2 = Util.applyTransform(r.slice(2, 4), m); - var p3 = Util.applyTransform([r[0], r[3]], m); - var p4 = Util.applyTransform([r[2], r[1]], m); - return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])]; - }; - - Util.inverseTransform = function Util_inverseTransform(m) { - var d = m[0] * m[3] - m[1] * m[2]; - return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d]; - }; - - Util.apply3dTransform = function Util_apply3dTransform(m, v) { - return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]]; - }; - - Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) { - var transpose = [m[0], m[2], m[1], m[3]]; - var a = m[0] * transpose[0] + m[1] * transpose[2]; - var b = m[0] * transpose[1] + m[1] * transpose[3]; - var c = m[2] * transpose[0] + m[3] * transpose[2]; - var d = m[2] * transpose[1] + m[3] * transpose[3]; - var first = (a + d) / 2; - var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2; - var sx = first + second || 1; - var sy = first - second || 1; - return [Math.sqrt(sx), Math.sqrt(sy)]; - }; - - Util.normalizeRect = function Util_normalizeRect(rect) { - var r = rect.slice(0); - - if (rect[0] > rect[2]) { - r[0] = rect[2]; - r[2] = rect[0]; + }, { + key: "applyTransform", + value: function applyTransform(p, m) { + var xt = p[0] * m[0] + p[1] * m[2] + m[4]; + var yt = p[0] * m[1] + p[1] * m[3] + m[5]; + return [xt, yt]; } - - if (rect[1] > rect[3]) { - r[1] = rect[3]; - r[3] = rect[1]; + }, { + key: "applyInverseTransform", + value: function applyInverseTransform(p, m) { + var d = m[0] * m[3] - m[1] * m[2]; + var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d; + var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d; + return [xt, yt]; + } + }, { + key: "getAxialAlignedBoundingBox", + value: function getAxialAlignedBoundingBox(r, m) { + var p1 = Util.applyTransform(r, m); + var p2 = Util.applyTransform(r.slice(2, 4), m); + var p3 = Util.applyTransform([r[0], r[3]], m); + var p4 = Util.applyTransform([r[2], r[1]], m); + return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])]; + } + }, { + key: "inverseTransform", + value: function inverseTransform(m) { + var d = m[0] * m[3] - m[1] * m[2]; + return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d]; } + }, { + key: "apply3dTransform", + value: function apply3dTransform(m, v) { + return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]]; + } + }, { + key: "singularValueDecompose2dScale", + value: function singularValueDecompose2dScale(m) { + var transpose = [m[0], m[2], m[1], m[3]]; + var a = m[0] * transpose[0] + m[1] * transpose[2]; + var b = m[0] * transpose[1] + m[1] * transpose[3]; + var c = m[2] * transpose[0] + m[3] * transpose[2]; + var d = m[2] * transpose[1] + m[3] * transpose[3]; + var first = (a + d) / 2; + var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2; + var sx = first + second || 1; + var sy = first - second || 1; + return [Math.sqrt(sx), Math.sqrt(sy)]; + } + }, { + key: "normalizeRect", + value: function normalizeRect(rect) { + var r = rect.slice(0); - return r; - }; + if (rect[0] > rect[2]) { + r[0] = rect[2]; + r[2] = rect[0]; + } - Util.intersect = function Util_intersect(rect1, rect2) { - function compare(a, b) { - return a - b; + if (rect[1] > rect[3]) { + r[1] = rect[3]; + r[3] = rect[1]; + } + + return r; } + }, { + key: "intersect", + value: function intersect(rect1, rect2) { + function compare(a, b) { + return a - b; + } - var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare), - orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare), - result = []; - rect1 = Util.normalizeRect(rect1); - rect2 = Util.normalizeRect(rect2); + var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare); + var orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare); + var result = []; + rect1 = Util.normalizeRect(rect1); + rect2 = Util.normalizeRect(rect2); - if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) { - result[0] = orderedX[1]; - result[2] = orderedX[2]; - } else { - return false; - } + if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) { + result[0] = orderedX[1]; + result[2] = orderedX[2]; + } else { + return null; + } - if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) { - result[1] = orderedY[1]; - result[3] = orderedY[2]; - } else { - return false; - } + if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) { + result[1] = orderedY[1]; + result[3] = orderedY[2]; + } else { + return null; + } - return result; - }; + return result; + } + }]); return Util; }(); exports.Util = Util; -var ROMAN_NUMBER_MAP = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']; - -function toRomanNumerals(number) { - var lowerCase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - assert(Number.isInteger(number) && number > 0, 'The number should be a positive integer.'); - var pos, - romanBuf = []; - - while (number >= 1000) { - number -= 1000; - romanBuf.push('M'); - } - - pos = number / 100 | 0; - number %= 100; - romanBuf.push(ROMAN_NUMBER_MAP[pos]); - pos = number / 10 | 0; - number %= 10; - romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]); - romanBuf.push(ROMAN_NUMBER_MAP[20 + number]); - var romanStr = romanBuf.join(''); - return lowerCase ? romanStr.toLowerCase() : romanStr; -} - var PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C, 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160, 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC]; function stringToPDFString(str) { - var i, - n = str.length, + var length = str.length, strBuf = []; if (str[0] === '\xFE' && str[1] === '\xFF') { - for (i = 2; i < n; i += 2) { + for (var i = 2; i < length; i += 2) { strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1))); } } else { - for (i = 0; i < n; ++i) { - var code = PDFStringTranslateTable[str.charCodeAt(i)]; - strBuf.push(code ? String.fromCharCode(code) : str.charAt(i)); + for (var _i2 = 0; _i2 < length; ++_i2) { + var code = PDFStringTranslateTable[str.charCodeAt(_i2)]; + strBuf.push(code ? String.fromCharCode(code) : str.charAt(_i2)); } } @@ -2447,6 +2226,16 @@ function isArrayBuffer(v) { return _typeof(v) === 'object' && v !== null && v.byteLength !== undefined; } +function isArrayEqual(arr1, arr2) { + if (arr1.length !== arr2.length) { + return false; + } + + return arr1.every(function (element, index) { + return element === arr2[index]; + }); +} + function isSpace(ch) { return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A; } @@ -2478,14 +2267,14 @@ var createObjectURL = function createObjectURLClosure() { return function createObjectURL(data, contentType) { var forceDataSchema = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - if (!forceDataSchema && _url_polyfill.URL.createObjectURL) { + if (!forceDataSchema && URL.createObjectURL) { var blob = new Blob([data], { type: contentType }); - return _url_polyfill.URL.createObjectURL(blob); + return URL.createObjectURL(blob); } - var buffer = 'data:' + contentType + ';base64,'; + var buffer = "data:".concat(contentType, ";base64,"); for (var i = 0, ii = data.length; i < ii; i += 3) { var b1 = data[i] & 0xFF; @@ -2505,7 +2294,7 @@ var createObjectURL = function createObjectURLClosure() { exports.createObjectURL = createObjectURL; /***/ }), -/* 7 */ +/* 6 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -2513,12 +2302,12 @@ exports.createObjectURL = createObjectURL; function _typeof(obj) { 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 globalScope = __w_pdfjs_require__(8); +var globalScope = __w_pdfjs_require__(7); if (!globalScope._pdfjsCompatibilityChecked) { globalScope._pdfjsCompatibilityChecked = true; - var isNodeJS = __w_pdfjs_require__(9); + var isNodeJS = __w_pdfjs_require__(8); var hasDOM = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && (typeof document === "undefined" ? "undefined" : _typeof(document)) === 'object'; @@ -2578,8 +2367,8 @@ if (!globalScope._pdfjsCompatibilityChecked) { tokens[_key] = arguments[_key]; } - for (var _i = 0; _i < tokens.length; _i++) { - var token = tokens[_i]; + for (var _i = 0, _tokens = tokens; _i < _tokens.length; _i++) { + var token = _tokens[_i]; OriginalDOMTokenListAdd.call(this, token); } }; @@ -2589,8 +2378,8 @@ if (!globalScope._pdfjsCompatibilityChecked) { tokens[_key2] = arguments[_key2]; } - for (var _i2 = 0; _i2 < tokens.length; _i2++) { - var token = tokens[_i2]; + for (var _i2 = 0, _tokens2 = tokens; _i2 < _tokens2.length; _i2++) { + var token = _tokens2[_i2]; OriginalDOMTokenListRemove.call(this, token); } }; @@ -2618,7 +2407,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - __w_pdfjs_require__(10); + __w_pdfjs_require__(9); })(); (function checkStringEndsWith() { @@ -2626,7 +2415,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - __w_pdfjs_require__(40); + __w_pdfjs_require__(61); })(); (function checkStringIncludes() { @@ -2634,7 +2423,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - __w_pdfjs_require__(42); + __w_pdfjs_require__(63); })(); (function checkArrayIncludes() { @@ -2642,7 +2431,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - __w_pdfjs_require__(44); + __w_pdfjs_require__(65); })(); (function checkArrayFrom() { @@ -2650,7 +2439,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - __w_pdfjs_require__(51); + __w_pdfjs_require__(72); })(); (function checkObjectAssign() { @@ -2658,7 +2447,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - __w_pdfjs_require__(74); + __w_pdfjs_require__(93); })(); (function checkMathLog2() { @@ -2666,7 +2455,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - Math.log2 = __w_pdfjs_require__(79); + Math.log2 = __w_pdfjs_require__(96); })(); (function checkNumberIsNaN() { @@ -2674,7 +2463,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - Number.isNaN = __w_pdfjs_require__(81); + Number.isNaN = __w_pdfjs_require__(98); })(); (function checkNumberIsInteger() { @@ -2682,15 +2471,19 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - Number.isInteger = __w_pdfjs_require__(83); + Number.isInteger = __w_pdfjs_require__(100); })(); (function checkPromise() { - if (globalScope.Promise && globalScope.Promise.prototype && globalScope.Promise.prototype.finally) { + if (globalScope.Promise && globalScope.Promise.prototype && globalScope.Promise.prototype["finally"]) { return; } - globalScope.Promise = __w_pdfjs_require__(86); + globalScope.Promise = __w_pdfjs_require__(103); + })(); + + (function checkURL() { + globalScope.URL = __w_pdfjs_require__(125); })(); (function checkWeakMap() { @@ -2698,7 +2491,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - globalScope.WeakMap = __w_pdfjs_require__(106); + globalScope.WeakMap = __w_pdfjs_require__(132); })(); (function checkWeakSet() { @@ -2706,15 +2499,15 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - globalScope.WeakSet = __w_pdfjs_require__(123); + globalScope.WeakSet = __w_pdfjs_require__(142); })(); (function checkStringCodePointAt() { - if (String.codePointAt) { + if (String.prototype.codePointAt) { return; } - String.codePointAt = __w_pdfjs_require__(127); + __w_pdfjs_require__(144); })(); (function checkStringFromCodePoint() { @@ -2722,7 +2515,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - String.fromCodePoint = __w_pdfjs_require__(129); + String.fromCodePoint = __w_pdfjs_require__(146); })(); (function checkSymbol() { @@ -2730,7 +2523,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - __w_pdfjs_require__(131); + __w_pdfjs_require__(148); })(); (function checkStringPadStart() { @@ -2738,7 +2531,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - __w_pdfjs_require__(138); + __w_pdfjs_require__(171); })(); (function checkStringPadEnd() { @@ -2746,7 +2539,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - __w_pdfjs_require__(142); + __w_pdfjs_require__(176); })(); (function checkObjectValues() { @@ -2754,12 +2547,12 @@ if (!globalScope._pdfjsCompatibilityChecked) { return; } - Object.values = __w_pdfjs_require__(144); + Object.values = __w_pdfjs_require__(178); })(); } /***/ }), -/* 8 */ +/* 7 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -2768,7 +2561,7 @@ if (!globalScope._pdfjsCompatibilityChecked) { module.exports = typeof window !== 'undefined' && window.Math === Math ? window : typeof global !== 'undefined' && global.Math === Math ? global : typeof self !== 'undefined' && self.Math === Math ? self : {}; /***/ }), -/* 9 */ +/* 8 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -2777,134 +2570,145 @@ module.exports = typeof window !== 'undefined' && window.Math === Math ? window function _typeof(obj) { 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); } module.exports = function isNodeJS() { - return (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && process + '' === '[object process]' && !process.versions['nw']; + return (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && process + '' === '[object process]' && !process.versions['nw'] && !process.versions['electron']; }; /***/ }), -/* 10 */ +/* 9 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(11); - -module.exports = __w_pdfjs_require__(14).String.startsWith; +__w_pdfjs_require__(10); +var entryUnbind = __w_pdfjs_require__(58); +module.exports = entryUnbind('String', 'startsWith'); /***/ }), -/* 11 */ +/* 10 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var $export = __w_pdfjs_require__(12); - -var toLength = __w_pdfjs_require__(30); - -var context = __w_pdfjs_require__(32); - -var STARTS_WITH = 'startsWith'; -var $startsWith = ''[STARTS_WITH]; -$export($export.P + $export.F * __w_pdfjs_require__(39)(STARTS_WITH), 'String', { - startsWith: function startsWith(searchString) { - var that = context(this, searchString, STARTS_WITH); - var index = toLength(Math.min(arguments.length > 1 ? arguments[1] : undefined, that.length)); - var search = String(searchString); - return $startsWith ? $startsWith.call(that, search, index) : that.slice(index, index + search.length) === search; - } +var $ = __w_pdfjs_require__(11); +var toLength = __w_pdfjs_require__(47); +var notARegExp = __w_pdfjs_require__(53); +var requireObjectCoercible = __w_pdfjs_require__(21); +var correctIsRegExpLogic = __w_pdfjs_require__(57); +var nativeStartsWith = ''.startsWith; +var min = Math.min; +$({ + target: 'String', + proto: true, + forced: !correctIsRegExpLogic('startsWith') +}, { + startsWith: function startsWith(searchString) { + var that = String(requireObjectCoercible(this)); + notARegExp(searchString); + var index = toLength(min(arguments.length > 1 ? arguments[1] : undefined, that.length)); + var search = String(searchString); + return nativeStartsWith ? nativeStartsWith.call(that, search, index) : that.slice(index, index + search.length) === search; + } }); /***/ }), -/* 12 */ +/* 11 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var global = __w_pdfjs_require__(13); - -var core = __w_pdfjs_require__(14); - -var hide = __w_pdfjs_require__(15); - -var redefine = __w_pdfjs_require__(25); - -var ctx = __w_pdfjs_require__(28); - -var PROTOTYPE = 'prototype'; - -var $export = function $export(type, name, source) { - var IS_FORCED = type & $export.F; - var IS_GLOBAL = type & $export.G; - var IS_STATIC = type & $export.S; - var IS_PROTO = type & $export.P; - var IS_BIND = type & $export.B; - var target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE]; - var exports = IS_GLOBAL ? core : core[name] || (core[name] = {}); - var expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {}); - var key, own, out, exp; - if (IS_GLOBAL) source = name; - +var global = __w_pdfjs_require__(12); +var getOwnPropertyDescriptor = __w_pdfjs_require__(13).f; +var hide = __w_pdfjs_require__(27); +var redefine = __w_pdfjs_require__(30); +var setGlobal = __w_pdfjs_require__(32); +var copyConstructorProperties = __w_pdfjs_require__(40); +var isForced = __w_pdfjs_require__(52); +module.exports = function (options, source) { + var TARGET = options.target; + var GLOBAL = options.global; + var STATIC = options.stat; + var FORCED, target, key, targetProperty, sourceProperty, descriptor; + if (GLOBAL) { + target = global; + } else if (STATIC) { + target = global[TARGET] || setGlobal(TARGET, {}); + } else { + target = (global[TARGET] || {}).prototype; + } + if (target) for (key in source) { - own = !IS_FORCED && target && target[key] !== undefined; - out = (own ? target : source)[key]; - exp = IS_BIND && own ? ctx(out, global) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out; - if (target) redefine(target, key, out, type & $export.U); - if (exports[key] != out) hide(exports, key, exp); - if (IS_PROTO && expProto[key] != out) expProto[key] = out; + sourceProperty = source[key]; + if (options.noTargetGet) { + descriptor = getOwnPropertyDescriptor(target, key); + targetProperty = descriptor && descriptor.value; + } else + targetProperty = target[key]; + FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced); + if (!FORCED && targetProperty !== undefined) { + if (typeof sourceProperty === typeof targetProperty) + continue; + copyConstructorProperties(sourceProperty, targetProperty); + } + if (options.sham || targetProperty && targetProperty.sham) { + hide(sourceProperty, 'sham', true); + } + redefine(target, key, sourceProperty, options); } }; -global.core = core; -$export.F = 1; -$export.G = 2; -$export.S = 4; -$export.P = 8; -$export.B = 16; -$export.W = 32; -$export.U = 64; -$export.R = 128; -module.exports = $export; +/***/ }), +/* 12 */ +/***/ (function(module, exports) { + +var O = 'object'; +var check = function (it) { + return it && it.Math == Math && it; +}; +module.exports = check(typeof globalThis == O && globalThis) || check(typeof window == O && window) || check(typeof self == O && self) || check(typeof global == O && global) || Function('return this')(); /***/ }), /* 13 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var global = module.exports = typeof window != 'undefined' && window.Math == Math ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); -if (typeof __g == 'number') __g = global; +var DESCRIPTORS = __w_pdfjs_require__(14); +var propertyIsEnumerableModule = __w_pdfjs_require__(16); +var createPropertyDescriptor = __w_pdfjs_require__(17); +var toIndexedObject = __w_pdfjs_require__(18); +var toPrimitive = __w_pdfjs_require__(22); +var has = __w_pdfjs_require__(24); +var IE8_DOM_DEFINE = __w_pdfjs_require__(25); +var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; +exports.f = DESCRIPTORS ? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) { + O = toIndexedObject(O); + P = toPrimitive(P, true); + if (IE8_DOM_DEFINE) + try { + return nativeGetOwnPropertyDescriptor(O, P); + } catch (error) { + } + if (has(O, P)) + return createPropertyDescriptor(!propertyIsEnumerableModule.f.call(O, P), O[P]); +}; /***/ }), /* 14 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var core = module.exports = { - version: '2.6.2' -}; -if (typeof __e == 'number') __e = core; +var fails = __w_pdfjs_require__(15); +module.exports = !fails(function () { + return Object.defineProperty({}, 'a', { + get: function () { + return 7; + } + }).a != 7; +}); /***/ }), /* 15 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; +/***/ (function(module, exports) { - -var dP = __w_pdfjs_require__(16); - -var createDesc = __w_pdfjs_require__(24); - -module.exports = __w_pdfjs_require__(20) ? function (object, key, value) { - return dP.f(object, key, createDesc(1, value)); -} : function (object, key, value) { - object[key] = value; - return object; +module.exports = function (exec) { + try { + return !!exec(); + } catch (error) { + return true; + } }; /***/ }), @@ -2913,968 +2717,686 @@ module.exports = __w_pdfjs_require__(20) ? function (object, key, value) { "use strict"; - -var anObject = __w_pdfjs_require__(17); - -var IE8_DOM_DEFINE = __w_pdfjs_require__(19); - -var toPrimitive = __w_pdfjs_require__(23); - -var dP = Object.defineProperty; -exports.f = __w_pdfjs_require__(20) ? Object.defineProperty : function defineProperty(O, P, Attributes) { - anObject(O); - P = toPrimitive(P, true); - anObject(Attributes); - if (IE8_DOM_DEFINE) try { - return dP(O, P, Attributes); - } catch (e) {} - if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!'); - if ('value' in Attributes) O[P] = Attributes.value; - return O; -}; +var nativePropertyIsEnumerable = {}.propertyIsEnumerable; +var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; +var NASHORN_BUG = getOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 1: 2 }, 1); +exports.f = NASHORN_BUG ? function propertyIsEnumerable(V) { + var descriptor = getOwnPropertyDescriptor(this, V); + return !!descriptor && descriptor.enumerable; +} : nativePropertyIsEnumerable; /***/ }), /* 17 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - +/***/ (function(module, exports) { -var isObject = __w_pdfjs_require__(18); - -module.exports = function (it) { - if (!isObject(it)) throw TypeError(it + ' is not an object!'); - return it; +module.exports = function (bitmap, value) { + return { + enumerable: !(bitmap & 1), + configurable: !(bitmap & 2), + writable: !(bitmap & 4), + value: value + }; }; /***/ }), /* 18 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -function _typeof(obj) { 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 IndexedObject = __w_pdfjs_require__(19); +var requireObjectCoercible = __w_pdfjs_require__(21); module.exports = function (it) { - return _typeof(it) === 'object' ? it !== null : typeof it === 'function'; + return IndexedObject(requireObjectCoercible(it)); }; /***/ }), /* 19 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -module.exports = !__w_pdfjs_require__(20) && !__w_pdfjs_require__(21)(function () { - return Object.defineProperty(__w_pdfjs_require__(22)('div'), 'a', { - get: function get() { - return 7; - } - }).a != 7; -}); +var fails = __w_pdfjs_require__(15); +var classof = __w_pdfjs_require__(20); +var split = ''.split; +module.exports = fails(function () { + return !Object('z').propertyIsEnumerable(0); +}) ? function (it) { + return classof(it) == 'String' ? split.call(it, '') : Object(it); +} : Object; /***/ }), /* 20 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - +/***/ (function(module, exports) { -module.exports = !__w_pdfjs_require__(21)(function () { - return Object.defineProperty({}, 'a', { - get: function get() { - return 7; - } - }).a != 7; -}); +var toString = {}.toString; +module.exports = function (it) { + return toString.call(it).slice(8, -1); +}; /***/ }), /* 21 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; +/***/ (function(module, exports) { - -module.exports = function (exec) { - try { - return !!exec(); - } catch (e) { - return true; - } +module.exports = function (it) { + if (it == undefined) + throw TypeError("Can't call method on " + it); + return it; }; /***/ }), /* 22 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var isObject = __w_pdfjs_require__(18); - -var document = __w_pdfjs_require__(13).document; - -var is = isObject(document) && isObject(document.createElement); - -module.exports = function (it) { - return is ? document.createElement(it) : {}; +var isObject = __w_pdfjs_require__(23); +module.exports = function (input, PREFERRED_STRING) { + if (!isObject(input)) + return input; + var fn, val; + if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) + return val; + if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) + return val; + if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) + return val; + throw TypeError("Can't convert object to primitive value"); }; /***/ }), /* 23 */ -/***/ (function(module, exports, __w_pdfjs_require__) { +/***/ (function(module, exports) { -"use strict"; - - -var isObject = __w_pdfjs_require__(18); - -module.exports = function (it, S) { - if (!isObject(it)) return it; - var fn, val; - if (S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it))) return val; - if (typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it))) return val; - if (!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it))) return val; - throw TypeError("Can't convert object to primitive value"); +module.exports = function (it) { + return typeof it === 'object' ? it !== null : typeof it === 'function'; }; /***/ }), /* 24 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - +/***/ (function(module, exports) { -module.exports = function (bitmap, value) { - return { - enumerable: !(bitmap & 1), - configurable: !(bitmap & 2), - writable: !(bitmap & 4), - value: value - }; +var hasOwnProperty = {}.hasOwnProperty; +module.exports = function (it, key) { + return hasOwnProperty.call(it, key); }; /***/ }), /* 25 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var global = __w_pdfjs_require__(13); - -var hide = __w_pdfjs_require__(15); - -var has = __w_pdfjs_require__(26); - -var SRC = __w_pdfjs_require__(27)('src'); - -var TO_STRING = 'toString'; -var $toString = Function[TO_STRING]; -var TPL = ('' + $toString).split(TO_STRING); - -__w_pdfjs_require__(14).inspectSource = function (it) { - return $toString.call(it); -}; - -(module.exports = function (O, key, val, safe) { - var isFunction = typeof val == 'function'; - if (isFunction) has(val, 'name') || hide(val, 'name', key); - if (O[key] === val) return; - if (isFunction) has(val, SRC) || hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key))); - - if (O === global) { - O[key] = val; - } else if (!safe) { - delete O[key]; - hide(O, key, val); - } else if (O[key]) { - O[key] = val; - } else { - hide(O, key, val); +var DESCRIPTORS = __w_pdfjs_require__(14); +var fails = __w_pdfjs_require__(15); +var createElement = __w_pdfjs_require__(26); +module.exports = !DESCRIPTORS && !fails(function () { + return Object.defineProperty(createElement('div'), 'a', { + get: function () { + return 7; } -})(Function.prototype, TO_STRING, function toString() { - return typeof this == 'function' && this[SRC] || $toString.call(this); + }).a != 7; }); /***/ }), /* 26 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var hasOwnProperty = {}.hasOwnProperty; - -module.exports = function (it, key) { - return hasOwnProperty.call(it, key); +var global = __w_pdfjs_require__(12); +var isObject = __w_pdfjs_require__(23); +var document = global.document; +var EXISTS = isObject(document) && isObject(document.createElement); +module.exports = function (it) { + return EXISTS ? document.createElement(it) : {}; }; /***/ }), /* 27 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var id = 0; -var px = Math.random(); - -module.exports = function (key) { - return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); +var DESCRIPTORS = __w_pdfjs_require__(14); +var definePropertyModule = __w_pdfjs_require__(28); +var createPropertyDescriptor = __w_pdfjs_require__(17); +module.exports = DESCRIPTORS ? function (object, key, value) { + return definePropertyModule.f(object, key, createPropertyDescriptor(1, value)); +} : function (object, key, value) { + object[key] = value; + return object; }; /***/ }), /* 28 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var aFunction = __w_pdfjs_require__(29); - -module.exports = function (fn, that, length) { - aFunction(fn); - if (that === undefined) return fn; - - switch (length) { - case 1: - return function (a) { - return fn.call(that, a); - }; - - case 2: - return function (a, b) { - return fn.call(that, a, b); - }; - - case 3: - return function (a, b, c) { - return fn.call(that, a, b, c); - }; - } - - return function () { - return fn.apply(that, arguments); - }; +var DESCRIPTORS = __w_pdfjs_require__(14); +var IE8_DOM_DEFINE = __w_pdfjs_require__(25); +var anObject = __w_pdfjs_require__(29); +var toPrimitive = __w_pdfjs_require__(22); +var nativeDefineProperty = Object.defineProperty; +exports.f = DESCRIPTORS ? nativeDefineProperty : function defineProperty(O, P, Attributes) { + anObject(O); + P = toPrimitive(P, true); + anObject(Attributes); + if (IE8_DOM_DEFINE) + try { + return nativeDefineProperty(O, P, Attributes); + } catch (error) { + } + if ('get' in Attributes || 'set' in Attributes) + throw TypeError('Accessors not supported'); + if ('value' in Attributes) + O[P] = Attributes.value; + return O; }; /***/ }), /* 29 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - +var isObject = __w_pdfjs_require__(23); module.exports = function (it) { - if (typeof it != 'function') throw TypeError(it + ' is not a function!'); - return it; + if (!isObject(it)) { + throw TypeError(String(it) + ' is not an object'); + } + return it; }; /***/ }), /* 30 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var toInteger = __w_pdfjs_require__(31); - -var min = Math.min; - -module.exports = function (it) { - return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; -}; +var global = __w_pdfjs_require__(12); +var shared = __w_pdfjs_require__(31); +var hide = __w_pdfjs_require__(27); +var has = __w_pdfjs_require__(24); +var setGlobal = __w_pdfjs_require__(32); +var nativeFunctionToString = __w_pdfjs_require__(34); +var InternalStateModule = __w_pdfjs_require__(35); +var getInternalState = InternalStateModule.get; +var enforceInternalState = InternalStateModule.enforce; +var TEMPLATE = String(nativeFunctionToString).split('toString'); +shared('inspectSource', function (it) { + return nativeFunctionToString.call(it); +}); +(module.exports = function (O, key, value, options) { + var unsafe = options ? !!options.unsafe : false; + var simple = options ? !!options.enumerable : false; + var noTargetGet = options ? !!options.noTargetGet : false; + if (typeof value == 'function') { + if (typeof key == 'string' && !has(value, 'name')) + hide(value, 'name', key); + enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : ''); + } + if (O === global) { + if (simple) + O[key] = value; + else + setGlobal(key, value); + return; + } else if (!unsafe) { + delete O[key]; + } else if (!noTargetGet && O[key]) { + simple = true; + } + if (simple) + O[key] = value; + else + hide(O, key, value); +})(Function.prototype, 'toString', function toString() { + return typeof this == 'function' && getInternalState(this).source || nativeFunctionToString.call(this); +}); /***/ }), /* 31 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var ceil = Math.ceil; -var floor = Math.floor; - -module.exports = function (it) { - return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); -}; +var global = __w_pdfjs_require__(12); +var setGlobal = __w_pdfjs_require__(32); +var IS_PURE = __w_pdfjs_require__(33); +var SHARED = '__core-js_shared__'; +var store = global[SHARED] || setGlobal(SHARED, {}); +(module.exports = function (key, value) { + return store[key] || (store[key] = value !== undefined ? value : {}); +})('versions', []).push({ + version: '3.2.1', + mode: IS_PURE ? 'pure' : 'global', + copyright: '© 2019 Denis Pushkarev (zloirock.ru)' +}); /***/ }), /* 32 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var isRegExp = __w_pdfjs_require__(33); - -var defined = __w_pdfjs_require__(38); - -module.exports = function (that, searchString, NAME) { - if (isRegExp(searchString)) throw TypeError('String#' + NAME + " doesn't accept regex!"); - return String(defined(that)); +var global = __w_pdfjs_require__(12); +var hide = __w_pdfjs_require__(27); +module.exports = function (key, value) { + try { + hide(global, key, value); + } catch (error) { + global[key] = value; + } + return value; }; /***/ }), /* 33 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var isObject = __w_pdfjs_require__(18); +/***/ (function(module, exports) { -var cof = __w_pdfjs_require__(34); - -var MATCH = __w_pdfjs_require__(35)('match'); - -module.exports = function (it) { - var isRegExp; - return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : cof(it) == 'RegExp'); -}; +module.exports = false; /***/ }), /* 34 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var toString = {}.toString; - -module.exports = function (it) { - return toString.call(it).slice(8, -1); -}; +var shared = __w_pdfjs_require__(31); +module.exports = shared('native-function-to-string', Function.toString); /***/ }), /* 35 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var store = __w_pdfjs_require__(36)('wks'); - -var uid = __w_pdfjs_require__(27); - -var _Symbol = __w_pdfjs_require__(13).Symbol; - -var USE_SYMBOL = typeof _Symbol == 'function'; - -var $exports = module.exports = function (name) { - return store[name] || (store[name] = USE_SYMBOL && _Symbol[name] || (USE_SYMBOL ? _Symbol : uid)('Symbol.' + name)); +var NATIVE_WEAK_MAP = __w_pdfjs_require__(36); +var global = __w_pdfjs_require__(12); +var isObject = __w_pdfjs_require__(23); +var hide = __w_pdfjs_require__(27); +var objectHas = __w_pdfjs_require__(24); +var sharedKey = __w_pdfjs_require__(37); +var hiddenKeys = __w_pdfjs_require__(39); +var WeakMap = global.WeakMap; +var set, get, has; +var enforce = function (it) { + return has(it) ? get(it) : set(it, {}); +}; +var getterFor = function (TYPE) { + return function (it) { + var state; + if (!isObject(it) || (state = get(it)).type !== TYPE) { + throw TypeError('Incompatible receiver, ' + TYPE + ' required'); + } + return state; + }; +}; +if (NATIVE_WEAK_MAP) { + var store = new WeakMap(); + var wmget = store.get; + var wmhas = store.has; + var wmset = store.set; + set = function (it, metadata) { + wmset.call(store, it, metadata); + return metadata; + }; + get = function (it) { + return wmget.call(store, it) || {}; + }; + has = function (it) { + return wmhas.call(store, it); + }; +} else { + var STATE = sharedKey('state'); + hiddenKeys[STATE] = true; + set = function (it, metadata) { + hide(it, STATE, metadata); + return metadata; + }; + get = function (it) { + return objectHas(it, STATE) ? it[STATE] : {}; + }; + has = function (it) { + return objectHas(it, STATE); + }; +} +module.exports = { + set: set, + get: get, + has: has, + enforce: enforce, + getterFor: getterFor }; - -$exports.store = store; /***/ }), /* 36 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var core = __w_pdfjs_require__(14); - -var global = __w_pdfjs_require__(13); - -var SHARED = '__core-js_shared__'; -var store = global[SHARED] || (global[SHARED] = {}); -(module.exports = function (key, value) { - return store[key] || (store[key] = value !== undefined ? value : {}); -})('versions', []).push({ - version: core.version, - mode: __w_pdfjs_require__(37) ? 'pure' : 'global', - copyright: '© 2019 Denis Pushkarev (zloirock.ru)' -}); +var global = __w_pdfjs_require__(12); +var nativeFunctionToString = __w_pdfjs_require__(34); +var WeakMap = global.WeakMap; +module.exports = typeof WeakMap === 'function' && /native code/.test(nativeFunctionToString.call(WeakMap)); /***/ }), /* 37 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -module.exports = false; +var shared = __w_pdfjs_require__(31); +var uid = __w_pdfjs_require__(38); +var keys = shared('keys'); +module.exports = function (key) { + return keys[key] || (keys[key] = uid(key)); +}; /***/ }), /* 38 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; +/***/ (function(module, exports) { - -module.exports = function (it) { - if (it == undefined) throw TypeError("Can't call method on " + it); - return it; +var id = 0; +var postfix = Math.random(); +module.exports = function (key) { + return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36); }; /***/ }), /* 39 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var MATCH = __w_pdfjs_require__(35)('match'); - -module.exports = function (KEY) { - var re = /./; +/***/ (function(module, exports) { - try { - '/./'[KEY](re); - } catch (e) { - try { - re[MATCH] = false; - return !'/./'[KEY](re); - } catch (f) {} - } - - return true; -}; +module.exports = {}; /***/ }), /* 40 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(41); - -module.exports = __w_pdfjs_require__(14).String.endsWith; +var has = __w_pdfjs_require__(24); +var ownKeys = __w_pdfjs_require__(41); +var getOwnPropertyDescriptorModule = __w_pdfjs_require__(13); +var definePropertyModule = __w_pdfjs_require__(28); +module.exports = function (target, source) { + var keys = ownKeys(source); + var defineProperty = definePropertyModule.f; + var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + if (!has(target, key)) + defineProperty(target, key, getOwnPropertyDescriptor(source, key)); + } +}; /***/ }), /* 41 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var $export = __w_pdfjs_require__(12); - -var toLength = __w_pdfjs_require__(30); - -var context = __w_pdfjs_require__(32); - -var ENDS_WITH = 'endsWith'; -var $endsWith = ''[ENDS_WITH]; -$export($export.P + $export.F * __w_pdfjs_require__(39)(ENDS_WITH), 'String', { - endsWith: function endsWith(searchString) { - var that = context(this, searchString, ENDS_WITH); - var endPosition = arguments.length > 1 ? arguments[1] : undefined; - var len = toLength(that.length); - var end = endPosition === undefined ? len : Math.min(toLength(endPosition), len); - var search = String(searchString); - return $endsWith ? $endsWith.call(that, search, end) : that.slice(end - search.length, end) === search; - } -}); +var getBuiltIn = __w_pdfjs_require__(42); +var getOwnPropertyNamesModule = __w_pdfjs_require__(44); +var getOwnPropertySymbolsModule = __w_pdfjs_require__(51); +var anObject = __w_pdfjs_require__(29); +module.exports = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) { + var keys = getOwnPropertyNamesModule.f(anObject(it)); + var getOwnPropertySymbols = getOwnPropertySymbolsModule.f; + return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys; +}; /***/ }), /* 42 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(43); - -module.exports = __w_pdfjs_require__(14).String.includes; +var path = __w_pdfjs_require__(43); +var global = __w_pdfjs_require__(12); +var aFunction = function (variable) { + return typeof variable == 'function' ? variable : undefined; +}; +module.exports = function (namespace, method) { + return arguments.length < 2 ? aFunction(path[namespace]) || aFunction(global[namespace]) : path[namespace] && path[namespace][method] || global[namespace] && global[namespace][method]; +}; /***/ }), /* 43 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var $export = __w_pdfjs_require__(12); - -var context = __w_pdfjs_require__(32); - -var INCLUDES = 'includes'; -$export($export.P + $export.F * __w_pdfjs_require__(39)(INCLUDES), 'String', { - includes: function includes(searchString) { - return !!~context(this, searchString, INCLUDES).indexOf(searchString, arguments.length > 1 ? arguments[1] : undefined); - } -}); +module.exports = __w_pdfjs_require__(12); /***/ }), /* 44 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(45); - -module.exports = __w_pdfjs_require__(14).Array.includes; +var internalObjectKeys = __w_pdfjs_require__(45); +var enumBugKeys = __w_pdfjs_require__(50); +var hiddenKeys = enumBugKeys.concat('length', 'prototype'); +exports.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { + return internalObjectKeys(O, hiddenKeys); +}; /***/ }), /* 45 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var $export = __w_pdfjs_require__(12); - -var $includes = __w_pdfjs_require__(46)(true); - -$export($export.P, 'Array', { - includes: function includes(el) { - return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined); - } -}); - -__w_pdfjs_require__(50)('includes'); +var has = __w_pdfjs_require__(24); +var toIndexedObject = __w_pdfjs_require__(18); +var indexOf = __w_pdfjs_require__(46).indexOf; +var hiddenKeys = __w_pdfjs_require__(39); +module.exports = function (object, names) { + var O = toIndexedObject(object); + var i = 0; + var result = []; + var key; + for (key in O) + !has(hiddenKeys, key) && has(O, key) && result.push(key); + while (names.length > i) + if (has(O, key = names[i++])) { + ~indexOf(result, key) || result.push(key); + } + return result; +}; /***/ }), /* 46 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var toIObject = __w_pdfjs_require__(47); - -var toLength = __w_pdfjs_require__(30); - +var toIndexedObject = __w_pdfjs_require__(18); +var toLength = __w_pdfjs_require__(47); var toAbsoluteIndex = __w_pdfjs_require__(49); - -module.exports = function (IS_INCLUDES) { - return function ($this, el, fromIndex) { - var O = toIObject($this); - var length = toLength(O.length); - var index = toAbsoluteIndex(fromIndex, length); - var value; - if (IS_INCLUDES && el != el) while (length > index) { - value = O[index++]; - if (value != value) return true; - } else for (; length > index; index++) { - if (IS_INCLUDES || index in O) { - if (O[index] === el) return IS_INCLUDES || index || 0; - } - } - return !IS_INCLUDES && -1; - }; +var createMethod = function (IS_INCLUDES) { + return function ($this, el, fromIndex) { + var O = toIndexedObject($this); + var length = toLength(O.length); + var index = toAbsoluteIndex(fromIndex, length); + var value; + if (IS_INCLUDES && el != el) + while (length > index) { + value = O[index++]; + if (value != value) + return true; + } + else + for (; length > index; index++) { + if ((IS_INCLUDES || index in O) && O[index] === el) + return IS_INCLUDES || index || 0; + } + return !IS_INCLUDES && -1; + }; +}; +module.exports = { + includes: createMethod(true), + indexOf: createMethod(false) }; /***/ }), /* 47 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var IObject = __w_pdfjs_require__(48); - -var defined = __w_pdfjs_require__(38); - -module.exports = function (it) { - return IObject(defined(it)); +var toInteger = __w_pdfjs_require__(48); +var min = Math.min; +module.exports = function (argument) { + return argument > 0 ? min(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; }; /***/ }), /* 48 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - +/***/ (function(module, exports) { -var cof = __w_pdfjs_require__(34); - -module.exports = Object('z').propertyIsEnumerable(0) ? Object : function (it) { - return cof(it) == 'String' ? it.split('') : Object(it); +var ceil = Math.ceil; +var floor = Math.floor; +module.exports = function (argument) { + return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor : ceil)(argument); }; /***/ }), /* 49 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var toInteger = __w_pdfjs_require__(31); - +var toInteger = __w_pdfjs_require__(48); var max = Math.max; var min = Math.min; - module.exports = function (index, length) { - index = toInteger(index); - return index < 0 ? max(index + length, 0) : min(index, length); + var integer = toInteger(index); + return integer < 0 ? max(integer + length, 0) : min(integer, length); }; /***/ }), /* 50 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var UNSCOPABLES = __w_pdfjs_require__(35)('unscopables'); - -var ArrayProto = Array.prototype; -if (ArrayProto[UNSCOPABLES] == undefined) __w_pdfjs_require__(15)(ArrayProto, UNSCOPABLES, {}); - -module.exports = function (key) { - ArrayProto[UNSCOPABLES][key] = true; -}; +/***/ (function(module, exports) { + +module.exports = [ + 'constructor', + 'hasOwnProperty', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'toLocaleString', + 'toString', + 'valueOf' +]; /***/ }), /* 51 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - +/***/ (function(module, exports) { -__w_pdfjs_require__(52); - -__w_pdfjs_require__(67); - -module.exports = __w_pdfjs_require__(14).Array.from; +exports.f = Object.getOwnPropertySymbols; /***/ }), /* 52 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var $at = __w_pdfjs_require__(53)(true); - -__w_pdfjs_require__(54)(String, 'String', function (iterated) { - this._t = String(iterated); - this._i = 0; -}, function () { - var O = this._t; - var index = this._i; - var point; - if (index >= O.length) return { - value: undefined, - done: true - }; - point = $at(O, index); - this._i += point.length; - return { - value: point, - done: false - }; -}); +var fails = __w_pdfjs_require__(15); +var replacement = /#|\.prototype\./; +var isForced = function (feature, detection) { + var value = data[normalize(feature)]; + return value == POLYFILL ? true : value == NATIVE ? false : typeof detection == 'function' ? fails(detection) : !!detection; +}; +var normalize = isForced.normalize = function (string) { + return String(string).replace(replacement, '.').toLowerCase(); +}; +var data = isForced.data = {}; +var NATIVE = isForced.NATIVE = 'N'; +var POLYFILL = isForced.POLYFILL = 'P'; +module.exports = isForced; /***/ }), /* 53 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var toInteger = __w_pdfjs_require__(31); - -var defined = __w_pdfjs_require__(38); - -module.exports = function (TO_STRING) { - return function (that, pos) { - var s = String(defined(that)); - var i = toInteger(pos); - var l = s.length; - var a, b; - if (i < 0 || i >= l) return TO_STRING ? '' : undefined; - a = s.charCodeAt(i); - return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff ? TO_STRING ? s.charAt(i) : a : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000; - }; +var isRegExp = __w_pdfjs_require__(54); +module.exports = function (it) { + if (isRegExp(it)) { + throw TypeError("The method doesn't accept regular expressions"); + } + return it; }; /***/ }), /* 54 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var LIBRARY = __w_pdfjs_require__(37); - -var $export = __w_pdfjs_require__(12); - -var redefine = __w_pdfjs_require__(25); - -var hide = __w_pdfjs_require__(15); - -var Iterators = __w_pdfjs_require__(55); - -var $iterCreate = __w_pdfjs_require__(56); - -var setToStringTag = __w_pdfjs_require__(64); - -var getPrototypeOf = __w_pdfjs_require__(65); - -var ITERATOR = __w_pdfjs_require__(35)('iterator'); - -var BUGGY = !([].keys && 'next' in [].keys()); -var FF_ITERATOR = '@@iterator'; -var KEYS = 'keys'; -var VALUES = 'values'; - -var returnThis = function returnThis() { - return this; -}; - -module.exports = function (Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED) { - $iterCreate(Constructor, NAME, next); - - var getMethod = function getMethod(kind) { - if (!BUGGY && kind in proto) return proto[kind]; - - switch (kind) { - case KEYS: - return function keys() { - return new Constructor(this, kind); - }; - - case VALUES: - return function values() { - return new Constructor(this, kind); - }; - } - - return function entries() { - return new Constructor(this, kind); - }; - }; - - var TAG = NAME + ' Iterator'; - var DEF_VALUES = DEFAULT == VALUES; - var VALUES_BUG = false; - var proto = Base.prototype; - var $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT]; - var $default = $native || getMethod(DEFAULT); - var $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined; - var $anyNative = NAME == 'Array' ? proto.entries || $native : $native; - var methods, key, IteratorPrototype; - - if ($anyNative) { - IteratorPrototype = getPrototypeOf($anyNative.call(new Base())); - - if (IteratorPrototype !== Object.prototype && IteratorPrototype.next) { - setToStringTag(IteratorPrototype, TAG, true); - if (!LIBRARY && typeof IteratorPrototype[ITERATOR] != 'function') hide(IteratorPrototype, ITERATOR, returnThis); - } - } - - if (DEF_VALUES && $native && $native.name !== VALUES) { - VALUES_BUG = true; - - $default = function values() { - return $native.call(this); - }; - } - - if ((!LIBRARY || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])) { - hide(proto, ITERATOR, $default); - } - - Iterators[NAME] = $default; - Iterators[TAG] = returnThis; - - if (DEFAULT) { - methods = { - values: DEF_VALUES ? $default : getMethod(VALUES), - keys: IS_SET ? $default : getMethod(KEYS), - entries: $entries - }; - if (FORCED) for (key in methods) { - if (!(key in proto)) redefine(proto, key, methods[key]); - } else $export($export.P + $export.F * (BUGGY || VALUES_BUG), NAME, methods); - } - - return methods; +var isObject = __w_pdfjs_require__(23); +var classof = __w_pdfjs_require__(20); +var wellKnownSymbol = __w_pdfjs_require__(55); +var MATCH = wellKnownSymbol('match'); +module.exports = function (it) { + var isRegExp; + return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : classof(it) == 'RegExp'); }; /***/ }), /* 55 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -module.exports = {}; +var global = __w_pdfjs_require__(12); +var shared = __w_pdfjs_require__(31); +var uid = __w_pdfjs_require__(38); +var NATIVE_SYMBOL = __w_pdfjs_require__(56); +var Symbol = global.Symbol; +var store = shared('wks'); +module.exports = function (name) { + return store[name] || (store[name] = NATIVE_SYMBOL && Symbol[name] || (NATIVE_SYMBOL ? Symbol : uid)('Symbol.' + name)); +}; /***/ }), /* 56 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var create = __w_pdfjs_require__(57); - -var descriptor = __w_pdfjs_require__(24); - -var setToStringTag = __w_pdfjs_require__(64); - -var IteratorPrototype = {}; - -__w_pdfjs_require__(15)(IteratorPrototype, __w_pdfjs_require__(35)('iterator'), function () { - return this; +var fails = __w_pdfjs_require__(15); +module.exports = !!Object.getOwnPropertySymbols && !fails(function () { + return !String(Symbol()); }); -module.exports = function (Constructor, NAME, next) { - Constructor.prototype = create(IteratorPrototype, { - next: descriptor(1, next) - }); - setToStringTag(Constructor, NAME + ' Iterator'); -}; - /***/ }), /* 57 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var anObject = __w_pdfjs_require__(17); - -var dPs = __w_pdfjs_require__(58); - -var enumBugKeys = __w_pdfjs_require__(62); - -var IE_PROTO = __w_pdfjs_require__(61)('IE_PROTO'); - -var Empty = function Empty() {}; - -var PROTOTYPE = 'prototype'; - -var _createDict = function createDict() { - var iframe = __w_pdfjs_require__(22)('iframe'); - - var i = enumBugKeys.length; - var lt = '<'; - var gt = '>'; - var iframeDocument; - iframe.style.display = 'none'; - - __w_pdfjs_require__(63).appendChild(iframe); - - iframe.src = 'javascript:'; - iframeDocument = iframe.contentWindow.document; - iframeDocument.open(); - iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt); - iframeDocument.close(); - _createDict = iframeDocument.F; - - while (i--) { - delete _createDict[PROTOTYPE][enumBugKeys[i]]; +var wellKnownSymbol = __w_pdfjs_require__(55); +var MATCH = wellKnownSymbol('match'); +module.exports = function (METHOD_NAME) { + var regexp = /./; + try { + '/./'[METHOD_NAME](regexp); + } catch (e) { + try { + regexp[MATCH] = false; + return '/./'[METHOD_NAME](regexp); + } catch (f) { } - - return _createDict(); -}; - -module.exports = Object.create || function create(O, Properties) { - var result; - - if (O !== null) { - Empty[PROTOTYPE] = anObject(O); - result = new Empty(); - Empty[PROTOTYPE] = null; - result[IE_PROTO] = O; - } else result = _createDict(); - - return Properties === undefined ? result : dPs(result, Properties); + } + return false; }; /***/ }), /* 58 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var dP = __w_pdfjs_require__(16); - -var anObject = __w_pdfjs_require__(17); - -var getKeys = __w_pdfjs_require__(59); - -module.exports = __w_pdfjs_require__(20) ? Object.defineProperties : function defineProperties(O, Properties) { - anObject(O); - var keys = getKeys(Properties); - var length = keys.length; - var i = 0; - var P; - - while (length > i) { - dP.f(O, P = keys[i++], Properties[P]); - } - - return O; +var global = __w_pdfjs_require__(12); +var bind = __w_pdfjs_require__(59); +var call = Function.call; +module.exports = function (CONSTRUCTOR, METHOD, length) { + return bind(call, global[CONSTRUCTOR].prototype[METHOD], length); }; /***/ }), /* 59 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var $keys = __w_pdfjs_require__(60); - -var enumBugKeys = __w_pdfjs_require__(62); - -module.exports = Object.keys || function keys(O) { - return $keys(O, enumBugKeys); +var aFunction = __w_pdfjs_require__(60); +module.exports = function (fn, that, length) { + aFunction(fn); + if (that === undefined) + return fn; + switch (length) { + case 0: + return function () { + return fn.call(that); + }; + case 1: + return function (a) { + return fn.call(that, a); + }; + case 2: + return function (a, b) { + return fn.call(that, a, b); + }; + case 3: + return function (a, b, c) { + return fn.call(that, a, b, c); + }; + } + return function () { + return fn.apply(that, arguments); + }; }; /***/ }), /* 60 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var has = __w_pdfjs_require__(26); - -var toIObject = __w_pdfjs_require__(47); - -var arrayIndexOf = __w_pdfjs_require__(46)(false); - -var IE_PROTO = __w_pdfjs_require__(61)('IE_PROTO'); - -module.exports = function (object, names) { - var O = toIObject(object); - var i = 0; - var result = []; - var key; - - for (key in O) { - if (key != IE_PROTO) has(O, key) && result.push(key); - } +/***/ (function(module, exports) { - while (names.length > i) { - if (has(O, key = names[i++])) { - ~arrayIndexOf(result, key) || result.push(key); - } - } - - return result; +module.exports = function (it) { + if (typeof it != 'function') { + throw TypeError(String(it) + ' is not a function'); + } + return it; }; /***/ }), /* 61 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var shared = __w_pdfjs_require__(36)('keys'); - -var uid = __w_pdfjs_require__(27); - -module.exports = function (key) { - return shared[key] || (shared[key] = uid(key)); -}; +__w_pdfjs_require__(62); +var entryUnbind = __w_pdfjs_require__(58); +module.exports = entryUnbind('String', 'endsWith'); /***/ }), /* 62 */ @@ -3882,19 +3404,36 @@ module.exports = function (key) { "use strict"; - -module.exports = 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'.split(','); +var $ = __w_pdfjs_require__(11); +var toLength = __w_pdfjs_require__(47); +var notARegExp = __w_pdfjs_require__(53); +var requireObjectCoercible = __w_pdfjs_require__(21); +var correctIsRegExpLogic = __w_pdfjs_require__(57); +var nativeEndsWith = ''.endsWith; +var min = Math.min; +$({ + target: 'String', + proto: true, + forced: !correctIsRegExpLogic('endsWith') +}, { + endsWith: function endsWith(searchString) { + var that = String(requireObjectCoercible(this)); + notARegExp(searchString); + var endPosition = arguments.length > 1 ? arguments[1] : undefined; + var len = toLength(that.length); + var end = endPosition === undefined ? len : min(toLength(endPosition), len); + var search = String(searchString); + return nativeEndsWith ? nativeEndsWith.call(that, search, end) : that.slice(end - search.length, end) === search; + } +}); /***/ }), /* 63 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var document = __w_pdfjs_require__(13).document; - -module.exports = document && document.documentElement; +__w_pdfjs_require__(64); +var entryUnbind = __w_pdfjs_require__(58); +module.exports = entryUnbind('String', 'includes'); /***/ }), /* 64 */ @@ -3902,45 +3441,27 @@ module.exports = document && document.documentElement; "use strict"; - -var def = __w_pdfjs_require__(16).f; - -var has = __w_pdfjs_require__(26); - -var TAG = __w_pdfjs_require__(35)('toStringTag'); - -module.exports = function (it, tag, stat) { - if (it && !has(it = stat ? it : it.prototype, TAG)) def(it, TAG, { - configurable: true, - value: tag - }); -}; +var $ = __w_pdfjs_require__(11); +var notARegExp = __w_pdfjs_require__(53); +var requireObjectCoercible = __w_pdfjs_require__(21); +var correctIsRegExpLogic = __w_pdfjs_require__(57); +$({ + target: 'String', + proto: true, + forced: !correctIsRegExpLogic('includes') +}, { + includes: function includes(searchString) { + return !!~String(requireObjectCoercible(this)).indexOf(notARegExp(searchString), arguments.length > 1 ? arguments[1] : undefined); + } +}); /***/ }), /* 65 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var has = __w_pdfjs_require__(26); - -var toObject = __w_pdfjs_require__(66); - -var IE_PROTO = __w_pdfjs_require__(61)('IE_PROTO'); - -var ObjectProto = Object.prototype; - -module.exports = Object.getPrototypeOf || function (O) { - O = toObject(O); - if (has(O, IE_PROTO)) return O[IE_PROTO]; - - if (typeof O.constructor == 'function' && O instanceof O.constructor) { - return O.constructor.prototype; - } - - return O instanceof Object ? ObjectProto : null; -}; +__w_pdfjs_require__(66); +var entryUnbind = __w_pdfjs_require__(58); +module.exports = entryUnbind('Array', 'includes'); /***/ }), /* 66 */ @@ -3948,537 +3469,939 @@ module.exports = Object.getPrototypeOf || function (O) { "use strict"; - -var defined = __w_pdfjs_require__(38); - -module.exports = function (it) { - return Object(defined(it)); -}; +var $ = __w_pdfjs_require__(11); +var $includes = __w_pdfjs_require__(46).includes; +var addToUnscopables = __w_pdfjs_require__(67); +$({ + target: 'Array', + proto: true +}, { + includes: function includes(el) { + return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined); + } +}); +addToUnscopables('includes'); /***/ }), /* 67 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var ctx = __w_pdfjs_require__(28); - -var $export = __w_pdfjs_require__(12); - -var toObject = __w_pdfjs_require__(66); - -var call = __w_pdfjs_require__(68); - -var isArrayIter = __w_pdfjs_require__(69); - -var toLength = __w_pdfjs_require__(30); - -var createProperty = __w_pdfjs_require__(70); - -var getIterFn = __w_pdfjs_require__(71); - -$export($export.S + $export.F * !__w_pdfjs_require__(73)(function (iter) { - Array.from(iter); -}), 'Array', { - from: function from(arrayLike) { - var O = toObject(arrayLike); - var C = typeof this == 'function' ? this : Array; - var aLen = arguments.length; - var mapfn = aLen > 1 ? arguments[1] : undefined; - var mapping = mapfn !== undefined; - var index = 0; - var iterFn = getIterFn(O); - var length, result, step, iterator; - if (mapping) mapfn = ctx(mapfn, aLen > 2 ? arguments[2] : undefined, 2); - - if (iterFn != undefined && !(C == Array && isArrayIter(iterFn))) { - for (iterator = iterFn.call(O), result = new C(); !(step = iterator.next()).done; index++) { - createProperty(result, index, mapping ? call(iterator, mapfn, [step.value, index], true) : step.value); - } - } else { - length = toLength(O.length); - - for (result = new C(length); length > index; index++) { - createProperty(result, index, mapping ? mapfn(O[index], index) : O[index]); - } - } - - result.length = index; - return result; - } -}); +var wellKnownSymbol = __w_pdfjs_require__(55); +var create = __w_pdfjs_require__(68); +var hide = __w_pdfjs_require__(27); +var UNSCOPABLES = wellKnownSymbol('unscopables'); +var ArrayPrototype = Array.prototype; +if (ArrayPrototype[UNSCOPABLES] == undefined) { + hide(ArrayPrototype, UNSCOPABLES, create(null)); +} +module.exports = function (key) { + ArrayPrototype[UNSCOPABLES][key] = true; +}; /***/ }), /* 68 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var anObject = __w_pdfjs_require__(17); - -module.exports = function (iterator, fn, value, entries) { - try { - return entries ? fn(anObject(value)[0], value[1]) : fn(value); - } catch (e) { - var ret = iterator['return']; - if (ret !== undefined) anObject(ret.call(iterator)); - throw e; - } +var anObject = __w_pdfjs_require__(29); +var defineProperties = __w_pdfjs_require__(69); +var enumBugKeys = __w_pdfjs_require__(50); +var hiddenKeys = __w_pdfjs_require__(39); +var html = __w_pdfjs_require__(71); +var documentCreateElement = __w_pdfjs_require__(26); +var sharedKey = __w_pdfjs_require__(37); +var IE_PROTO = sharedKey('IE_PROTO'); +var PROTOTYPE = 'prototype'; +var Empty = function () { +}; +var createDict = function () { + var iframe = documentCreateElement('iframe'); + var length = enumBugKeys.length; + var lt = '<'; + var script = 'script'; + var gt = '>'; + var js = 'java' + script + ':'; + var iframeDocument; + iframe.style.display = 'none'; + html.appendChild(iframe); + iframe.src = String(js); + iframeDocument = iframe.contentWindow.document; + iframeDocument.open(); + iframeDocument.write(lt + script + gt + 'document.F=Object' + lt + '/' + script + gt); + iframeDocument.close(); + createDict = iframeDocument.F; + while (length--) + delete createDict[PROTOTYPE][enumBugKeys[length]]; + return createDict(); }; +module.exports = Object.create || function create(O, Properties) { + var result; + if (O !== null) { + Empty[PROTOTYPE] = anObject(O); + result = new Empty(); + Empty[PROTOTYPE] = null; + result[IE_PROTO] = O; + } else + result = createDict(); + return Properties === undefined ? result : defineProperties(result, Properties); +}; +hiddenKeys[IE_PROTO] = true; /***/ }), /* 69 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var Iterators = __w_pdfjs_require__(55); - -var ITERATOR = __w_pdfjs_require__(35)('iterator'); - -var ArrayProto = Array.prototype; - -module.exports = function (it) { - return it !== undefined && (Iterators.Array === it || ArrayProto[ITERATOR] === it); +var DESCRIPTORS = __w_pdfjs_require__(14); +var definePropertyModule = __w_pdfjs_require__(28); +var anObject = __w_pdfjs_require__(29); +var objectKeys = __w_pdfjs_require__(70); +module.exports = DESCRIPTORS ? Object.defineProperties : function defineProperties(O, Properties) { + anObject(O); + var keys = objectKeys(Properties); + var length = keys.length; + var index = 0; + var key; + while (length > index) + definePropertyModule.f(O, key = keys[index++], Properties[key]); + return O; }; /***/ }), /* 70 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var $defineProperty = __w_pdfjs_require__(16); - -var createDesc = __w_pdfjs_require__(24); - -module.exports = function (object, index, value) { - if (index in object) $defineProperty.f(object, index, createDesc(0, value));else object[index] = value; +var internalObjectKeys = __w_pdfjs_require__(45); +var enumBugKeys = __w_pdfjs_require__(50); +module.exports = Object.keys || function keys(O) { + return internalObjectKeys(O, enumBugKeys); }; /***/ }), /* 71 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var classof = __w_pdfjs_require__(72); - -var ITERATOR = __w_pdfjs_require__(35)('iterator'); - -var Iterators = __w_pdfjs_require__(55); - -module.exports = __w_pdfjs_require__(14).getIteratorMethod = function (it) { - if (it != undefined) return it[ITERATOR] || it['@@iterator'] || Iterators[classof(it)]; -}; +var getBuiltIn = __w_pdfjs_require__(42); +module.exports = getBuiltIn('document', 'documentElement'); /***/ }), /* 72 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; +__w_pdfjs_require__(73); +__w_pdfjs_require__(85); +var path = __w_pdfjs_require__(43); +module.exports = path.Array.from; +/***/ }), +/* 73 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var cof = __w_pdfjs_require__(34); +"use strict"; -var TAG = __w_pdfjs_require__(35)('toStringTag'); +var charAt = __w_pdfjs_require__(74).charAt; +var InternalStateModule = __w_pdfjs_require__(35); +var defineIterator = __w_pdfjs_require__(75); +var STRING_ITERATOR = 'String Iterator'; +var setInternalState = InternalStateModule.set; +var getInternalState = InternalStateModule.getterFor(STRING_ITERATOR); +defineIterator(String, 'String', function (iterated) { + setInternalState(this, { + type: STRING_ITERATOR, + string: String(iterated), + index: 0 + }); +}, function next() { + var state = getInternalState(this); + var string = state.string; + var index = state.index; + var point; + if (index >= string.length) + return { + value: undefined, + done: true + }; + point = charAt(string, index); + state.index += point.length; + return { + value: point, + done: false + }; +}); -var ARG = cof(function () { - return arguments; -}()) == 'Arguments'; +/***/ }), +/* 74 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var tryGet = function tryGet(it, key) { - try { - return it[key]; - } catch (e) {} +var toInteger = __w_pdfjs_require__(48); +var requireObjectCoercible = __w_pdfjs_require__(21); +var createMethod = function (CONVERT_TO_STRING) { + return function ($this, pos) { + var S = String(requireObjectCoercible($this)); + var position = toInteger(pos); + var size = S.length; + var first, second; + if (position < 0 || position >= size) + return CONVERT_TO_STRING ? '' : undefined; + first = S.charCodeAt(position); + return first < 0xD800 || first > 0xDBFF || position + 1 === size || (second = S.charCodeAt(position + 1)) < 0xDC00 || second > 0xDFFF ? CONVERT_TO_STRING ? S.charAt(position) : first : CONVERT_TO_STRING ? S.slice(position, position + 2) : (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000; + }; }; - -module.exports = function (it) { - var O, T, B; - return it === undefined ? 'Undefined' : it === null ? 'Null' : typeof (T = tryGet(O = Object(it), TAG)) == 'string' ? T : ARG ? cof(O) : (B = cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B; +module.exports = { + codeAt: createMethod(false), + charAt: createMethod(true) }; /***/ }), -/* 73 */ +/* 75 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var ITERATOR = __w_pdfjs_require__(35)('iterator'); - -var SAFE_CLOSING = false; - -try { - var riter = [7][ITERATOR](); - - riter['return'] = function () { - SAFE_CLOSING = true; +var $ = __w_pdfjs_require__(11); +var createIteratorConstructor = __w_pdfjs_require__(76); +var getPrototypeOf = __w_pdfjs_require__(78); +var setPrototypeOf = __w_pdfjs_require__(83); +var setToStringTag = __w_pdfjs_require__(81); +var hide = __w_pdfjs_require__(27); +var redefine = __w_pdfjs_require__(30); +var wellKnownSymbol = __w_pdfjs_require__(55); +var IS_PURE = __w_pdfjs_require__(33); +var Iterators = __w_pdfjs_require__(82); +var IteratorsCore = __w_pdfjs_require__(77); +var IteratorPrototype = IteratorsCore.IteratorPrototype; +var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS; +var ITERATOR = wellKnownSymbol('iterator'); +var KEYS = 'keys'; +var VALUES = 'values'; +var ENTRIES = 'entries'; +var returnThis = function () { + return this; +}; +module.exports = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, IS_SET, FORCED) { + createIteratorConstructor(IteratorConstructor, NAME, next); + var getIterationMethod = function (KIND) { + if (KIND === DEFAULT && defaultIterator) + return defaultIterator; + if (!BUGGY_SAFARI_ITERATORS && KIND in IterablePrototype) + return IterablePrototype[KIND]; + switch (KIND) { + case KEYS: + return function keys() { + return new IteratorConstructor(this, KIND); + }; + case VALUES: + return function values() { + return new IteratorConstructor(this, KIND); + }; + case ENTRIES: + return function entries() { + return new IteratorConstructor(this, KIND); + }; + } + return function () { + return new IteratorConstructor(this); }; + }; + var TO_STRING_TAG = NAME + ' Iterator'; + var INCORRECT_VALUES_NAME = false; + var IterablePrototype = Iterable.prototype; + var nativeIterator = IterablePrototype[ITERATOR] || IterablePrototype['@@iterator'] || DEFAULT && IterablePrototype[DEFAULT]; + var defaultIterator = !BUGGY_SAFARI_ITERATORS && nativeIterator || getIterationMethod(DEFAULT); + var anyNativeIterator = NAME == 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator; + var CurrentIteratorPrototype, methods, KEY; + if (anyNativeIterator) { + CurrentIteratorPrototype = getPrototypeOf(anyNativeIterator.call(new Iterable())); + if (IteratorPrototype !== Object.prototype && CurrentIteratorPrototype.next) { + if (!IS_PURE && getPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype) { + if (setPrototypeOf) { + setPrototypeOf(CurrentIteratorPrototype, IteratorPrototype); + } else if (typeof CurrentIteratorPrototype[ITERATOR] != 'function') { + hide(CurrentIteratorPrototype, ITERATOR, returnThis); + } + } + setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true, true); + if (IS_PURE) + Iterators[TO_STRING_TAG] = returnThis; + } + } + if (DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) { + INCORRECT_VALUES_NAME = true; + defaultIterator = function values() { + return nativeIterator.call(this); + }; + } + if ((!IS_PURE || FORCED) && IterablePrototype[ITERATOR] !== defaultIterator) { + hide(IterablePrototype, ITERATOR, defaultIterator); + } + Iterators[NAME] = defaultIterator; + if (DEFAULT) { + methods = { + values: getIterationMethod(VALUES), + keys: IS_SET ? defaultIterator : getIterationMethod(KEYS), + entries: getIterationMethod(ENTRIES) + }; + if (FORCED) + for (KEY in methods) { + if (BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) { + redefine(IterablePrototype, KEY, methods[KEY]); + } + } + else + $({ + target: NAME, + proto: true, + forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME + }, methods); + } + return methods; +}; - Array.from(riter, function () { - throw 2; - }); -} catch (e) {} - -module.exports = function (exec, skipClosing) { - if (!skipClosing && !SAFE_CLOSING) return false; - var safe = false; - - try { - var arr = [7]; - var iter = arr[ITERATOR](); - - iter.next = function () { - return { - done: safe = true - }; - }; - - arr[ITERATOR] = function () { - return iter; - }; +/***/ }), +/* 76 */ +/***/ (function(module, exports, __w_pdfjs_require__) { - exec(arr); - } catch (e) {} +"use strict"; - return safe; +var IteratorPrototype = __w_pdfjs_require__(77).IteratorPrototype; +var create = __w_pdfjs_require__(68); +var createPropertyDescriptor = __w_pdfjs_require__(17); +var setToStringTag = __w_pdfjs_require__(81); +var Iterators = __w_pdfjs_require__(82); +var returnThis = function () { + return this; +}; +module.exports = function (IteratorConstructor, NAME, next) { + var TO_STRING_TAG = NAME + ' Iterator'; + IteratorConstructor.prototype = create(IteratorPrototype, { next: createPropertyDescriptor(1, next) }); + setToStringTag(IteratorConstructor, TO_STRING_TAG, false, true); + Iterators[TO_STRING_TAG] = returnThis; + return IteratorConstructor; }; /***/ }), -/* 74 */ +/* 77 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; +var getPrototypeOf = __w_pdfjs_require__(78); +var hide = __w_pdfjs_require__(27); +var has = __w_pdfjs_require__(24); +var wellKnownSymbol = __w_pdfjs_require__(55); +var IS_PURE = __w_pdfjs_require__(33); +var ITERATOR = wellKnownSymbol('iterator'); +var BUGGY_SAFARI_ITERATORS = false; +var returnThis = function () { + return this; +}; +var IteratorPrototype, PrototypeOfArrayIteratorPrototype, arrayIterator; +if ([].keys) { + arrayIterator = [].keys(); + if (!('next' in arrayIterator)) + BUGGY_SAFARI_ITERATORS = true; + else { + PrototypeOfArrayIteratorPrototype = getPrototypeOf(getPrototypeOf(arrayIterator)); + if (PrototypeOfArrayIteratorPrototype !== Object.prototype) + IteratorPrototype = PrototypeOfArrayIteratorPrototype; + } +} +if (IteratorPrototype == undefined) + IteratorPrototype = {}; +if (!IS_PURE && !has(IteratorPrototype, ITERATOR)) + hide(IteratorPrototype, ITERATOR, returnThis); +module.exports = { + IteratorPrototype: IteratorPrototype, + BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS +}; -__w_pdfjs_require__(75); +/***/ }), +/* 78 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -module.exports = __w_pdfjs_require__(14).Object.assign; +var has = __w_pdfjs_require__(24); +var toObject = __w_pdfjs_require__(79); +var sharedKey = __w_pdfjs_require__(37); +var CORRECT_PROTOTYPE_GETTER = __w_pdfjs_require__(80); +var IE_PROTO = sharedKey('IE_PROTO'); +var ObjectPrototype = Object.prototype; +module.exports = CORRECT_PROTOTYPE_GETTER ? Object.getPrototypeOf : function (O) { + O = toObject(O); + if (has(O, IE_PROTO)) + return O[IE_PROTO]; + if (typeof O.constructor == 'function' && O instanceof O.constructor) { + return O.constructor.prototype; + } + return O instanceof Object ? ObjectPrototype : null; +}; /***/ }), -/* 75 */ +/* 79 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - +var requireObjectCoercible = __w_pdfjs_require__(21); +module.exports = function (argument) { + return Object(requireObjectCoercible(argument)); +}; -var $export = __w_pdfjs_require__(12); +/***/ }), +/* 80 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -$export($export.S + $export.F, 'Object', { - assign: __w_pdfjs_require__(76) +var fails = __w_pdfjs_require__(15); +module.exports = !fails(function () { + function F() { + } + F.prototype.constructor = null; + return Object.getPrototypeOf(new F()) !== F.prototype; }); /***/ }), -/* 76 */ +/* 81 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var getKeys = __w_pdfjs_require__(59); +var defineProperty = __w_pdfjs_require__(28).f; +var has = __w_pdfjs_require__(24); +var wellKnownSymbol = __w_pdfjs_require__(55); +var TO_STRING_TAG = wellKnownSymbol('toStringTag'); +module.exports = function (it, TAG, STATIC) { + if (it && !has(it = STATIC ? it : it.prototype, TO_STRING_TAG)) { + defineProperty(it, TO_STRING_TAG, { + configurable: true, + value: TAG + }); + } +}; -var gOPS = __w_pdfjs_require__(77); +/***/ }), +/* 82 */ +/***/ (function(module, exports) { -var pIE = __w_pdfjs_require__(78); +module.exports = {}; -var toObject = __w_pdfjs_require__(66); +/***/ }), +/* 83 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var IObject = __w_pdfjs_require__(48); +var anObject = __w_pdfjs_require__(29); +var aPossiblePrototype = __w_pdfjs_require__(84); +module.exports = Object.setPrototypeOf || ('__proto__' in {} ? function () { + var CORRECT_SETTER = false; + var test = {}; + var setter; + try { + setter = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set; + setter.call(test, []); + CORRECT_SETTER = test instanceof Array; + } catch (error) { + } + return function setPrototypeOf(O, proto) { + anObject(O); + aPossiblePrototype(proto); + if (CORRECT_SETTER) + setter.call(O, proto); + else + O.__proto__ = proto; + return O; + }; +}() : undefined); -var $assign = Object.assign; -module.exports = !$assign || __w_pdfjs_require__(21)(function () { - var A = {}; - var B = {}; - var S = Symbol(); - var K = 'abcdefghijklmnopqrst'; - A[S] = 7; - K.split('').forEach(function (k) { - B[k] = k; - }); - return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K; -}) ? function assign(target, source) { - var T = toObject(target); - var aLen = arguments.length; - var index = 1; - var getSymbols = gOPS.f; - var isEnum = pIE.f; +/***/ }), +/* 84 */ +/***/ (function(module, exports, __w_pdfjs_require__) { - while (aLen > index) { - var S = IObject(arguments[index++]); - var keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S); - var length = keys.length; - var j = 0; - var key; +var isObject = __w_pdfjs_require__(23); +module.exports = function (it) { + if (!isObject(it) && it !== null) { + throw TypeError("Can't set " + String(it) + ' as a prototype'); + } + return it; +}; - while (length > j) { - if (isEnum.call(S, key = keys[j++])) T[key] = S[key]; - } - } +/***/ }), +/* 85 */ +/***/ (function(module, exports, __w_pdfjs_require__) { - return T; -} : $assign; +var $ = __w_pdfjs_require__(11); +var from = __w_pdfjs_require__(86); +var checkCorrectnessOfIteration = __w_pdfjs_require__(92); +var INCORRECT_ITERATION = !checkCorrectnessOfIteration(function (iterable) { + Array.from(iterable); +}); +$({ + target: 'Array', + stat: true, + forced: INCORRECT_ITERATION +}, { from: from }); /***/ }), -/* 77 */ +/* 86 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -exports.f = Object.getOwnPropertySymbols; +var bind = __w_pdfjs_require__(59); +var toObject = __w_pdfjs_require__(79); +var callWithSafeIterationClosing = __w_pdfjs_require__(87); +var isArrayIteratorMethod = __w_pdfjs_require__(88); +var toLength = __w_pdfjs_require__(47); +var createProperty = __w_pdfjs_require__(89); +var getIteratorMethod = __w_pdfjs_require__(90); +module.exports = function from(arrayLike) { + var O = toObject(arrayLike); + var C = typeof this == 'function' ? this : Array; + var argumentsLength = arguments.length; + var mapfn = argumentsLength > 1 ? arguments[1] : undefined; + var mapping = mapfn !== undefined; + var index = 0; + var iteratorMethod = getIteratorMethod(O); + var length, result, step, iterator; + if (mapping) + mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined, 2); + if (iteratorMethod != undefined && !(C == Array && isArrayIteratorMethod(iteratorMethod))) { + iterator = iteratorMethod.call(O); + result = new C(); + for (; !(step = iterator.next()).done; index++) { + createProperty(result, index, mapping ? callWithSafeIterationClosing(iterator, mapfn, [ + step.value, + index + ], true) : step.value); + } + } else { + length = toLength(O.length); + result = new C(length); + for (; length > index; index++) { + createProperty(result, index, mapping ? mapfn(O[index], index) : O[index]); + } + } + result.length = index; + return result; +}; /***/ }), -/* 78 */ +/* 87 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; +var anObject = __w_pdfjs_require__(29); +module.exports = function (iterator, fn, value, ENTRIES) { + try { + return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value); + } catch (error) { + var returnMethod = iterator['return']; + if (returnMethod !== undefined) + anObject(returnMethod.call(iterator)); + throw error; + } +}; +/***/ }), +/* 88 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -exports.f = {}.propertyIsEnumerable; +var wellKnownSymbol = __w_pdfjs_require__(55); +var Iterators = __w_pdfjs_require__(82); +var ITERATOR = wellKnownSymbol('iterator'); +var ArrayPrototype = Array.prototype; +module.exports = function (it) { + return it !== undefined && (Iterators.Array === it || ArrayPrototype[ITERATOR] === it); +}; /***/ }), -/* 79 */ +/* 89 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; +var toPrimitive = __w_pdfjs_require__(22); +var definePropertyModule = __w_pdfjs_require__(28); +var createPropertyDescriptor = __w_pdfjs_require__(17); +module.exports = function (object, key, value) { + var propertyKey = toPrimitive(key); + if (propertyKey in object) + definePropertyModule.f(object, propertyKey, createPropertyDescriptor(0, value)); + else + object[propertyKey] = value; +}; -__w_pdfjs_require__(80); +/***/ }), +/* 90 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -module.exports = __w_pdfjs_require__(14).Math.log2; +var classof = __w_pdfjs_require__(91); +var Iterators = __w_pdfjs_require__(82); +var wellKnownSymbol = __w_pdfjs_require__(55); +var ITERATOR = wellKnownSymbol('iterator'); +module.exports = function (it) { + if (it != undefined) + return it[ITERATOR] || it['@@iterator'] || Iterators[classof(it)]; +}; /***/ }), -/* 80 */ +/* 91 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - +var classofRaw = __w_pdfjs_require__(20); +var wellKnownSymbol = __w_pdfjs_require__(55); +var TO_STRING_TAG = wellKnownSymbol('toStringTag'); +var CORRECT_ARGUMENTS = classofRaw(function () { + return arguments; +}()) == 'Arguments'; +var tryGet = function (it, key) { + try { + return it[key]; + } catch (error) { + } +}; +module.exports = function (it) { + var O, tag, result; + return it === undefined ? 'Undefined' : it === null ? 'Null' : typeof (tag = tryGet(O = Object(it), TO_STRING_TAG)) == 'string' ? tag : CORRECT_ARGUMENTS ? classofRaw(O) : (result = classofRaw(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : result; +}; -var $export = __w_pdfjs_require__(12); +/***/ }), +/* 92 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -$export($export.S, 'Math', { - log2: function log2(x) { - return Math.log(x) / Math.LN2; +var wellKnownSymbol = __w_pdfjs_require__(55); +var ITERATOR = wellKnownSymbol('iterator'); +var SAFE_CLOSING = false; +try { + var called = 0; + var iteratorWithReturn = { + next: function () { + return { done: !!called++ }; + }, + 'return': function () { + SAFE_CLOSING = true; } -}); + }; + iteratorWithReturn[ITERATOR] = function () { + return this; + }; + Array.from(iteratorWithReturn, function () { + throw 2; + }); +} catch (error) { +} +module.exports = function (exec, SKIP_CLOSING) { + if (!SKIP_CLOSING && !SAFE_CLOSING) + return false; + var ITERATION_SUPPORT = false; + try { + var object = {}; + object[ITERATOR] = function () { + return { + next: function () { + return { done: ITERATION_SUPPORT = true }; + } + }; + }; + exec(object); + } catch (error) { + } + return ITERATION_SUPPORT; +}; /***/ }), -/* 81 */ +/* 93 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - +__w_pdfjs_require__(94); +var path = __w_pdfjs_require__(43); +module.exports = path.Object.assign; -__w_pdfjs_require__(82); +/***/ }), +/* 94 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -module.exports = __w_pdfjs_require__(14).Number.isNaN; +var $ = __w_pdfjs_require__(11); +var assign = __w_pdfjs_require__(95); +$({ + target: 'Object', + stat: true, + forced: Object.assign !== assign +}, { assign: assign }); /***/ }), -/* 82 */ +/* 95 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var $export = __w_pdfjs_require__(12); - -$export($export.S, 'Number', { - isNaN: function isNaN(number) { - return number != number; +var DESCRIPTORS = __w_pdfjs_require__(14); +var fails = __w_pdfjs_require__(15); +var objectKeys = __w_pdfjs_require__(70); +var getOwnPropertySymbolsModule = __w_pdfjs_require__(51); +var propertyIsEnumerableModule = __w_pdfjs_require__(16); +var toObject = __w_pdfjs_require__(79); +var IndexedObject = __w_pdfjs_require__(19); +var nativeAssign = Object.assign; +module.exports = !nativeAssign || fails(function () { + var A = {}; + var B = {}; + var symbol = Symbol(); + var alphabet = 'abcdefghijklmnopqrst'; + A[symbol] = 7; + alphabet.split('').forEach(function (chr) { + B[chr] = chr; + }); + return nativeAssign({}, A)[symbol] != 7 || objectKeys(nativeAssign({}, B)).join('') != alphabet; +}) ? function assign(target, source) { + var T = toObject(target); + var argumentsLength = arguments.length; + var index = 1; + var getOwnPropertySymbols = getOwnPropertySymbolsModule.f; + var propertyIsEnumerable = propertyIsEnumerableModule.f; + while (argumentsLength > index) { + var S = IndexedObject(arguments[index++]); + var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S); + var length = keys.length; + var j = 0; + var key; + while (length > j) { + key = keys[j++]; + if (!DESCRIPTORS || propertyIsEnumerable.call(S, key)) + T[key] = S[key]; } -}); + } + return T; +} : nativeAssign; /***/ }), -/* 83 */ +/* 96 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - +__w_pdfjs_require__(97); +var path = __w_pdfjs_require__(43); +module.exports = path.Math.log2; -__w_pdfjs_require__(84); +/***/ }), +/* 97 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -module.exports = __w_pdfjs_require__(14).Number.isInteger; +var $ = __w_pdfjs_require__(11); +var log = Math.log; +var LN2 = Math.LN2; +$({ + target: 'Math', + stat: true +}, { + log2: function log2(x) { + return log(x) / LN2; + } +}); /***/ }), -/* 84 */ +/* 98 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - +__w_pdfjs_require__(99); +var path = __w_pdfjs_require__(43); +module.exports = path.Number.isNaN; -var $export = __w_pdfjs_require__(12); +/***/ }), +/* 99 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -$export($export.S, 'Number', { - isInteger: __w_pdfjs_require__(85) +var $ = __w_pdfjs_require__(11); +$({ + target: 'Number', + stat: true +}, { + isNaN: function isNaN(number) { + return number != number; + } }); /***/ }), -/* 85 */ +/* 100 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; +__w_pdfjs_require__(101); +var path = __w_pdfjs_require__(43); +module.exports = path.Number.isInteger; +/***/ }), +/* 101 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var isObject = __w_pdfjs_require__(18); +var $ = __w_pdfjs_require__(11); +var isInteger = __w_pdfjs_require__(102); +$({ + target: 'Number', + stat: true +}, { isInteger: isInteger }); -var floor = Math.floor; +/***/ }), +/* 102 */ +/***/ (function(module, exports, __w_pdfjs_require__) { +var isObject = __w_pdfjs_require__(23); +var floor = Math.floor; module.exports = function isInteger(it) { - return !isObject(it) && isFinite(it) && floor(it) === it; + return !isObject(it) && isFinite(it) && floor(it) === it; }; /***/ }), -/* 86 */ +/* 103 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(87); - -__w_pdfjs_require__(52); - -__w_pdfjs_require__(88); - -__w_pdfjs_require__(91); - __w_pdfjs_require__(104); +__w_pdfjs_require__(73); +__w_pdfjs_require__(106); +__w_pdfjs_require__(109); +__w_pdfjs_require__(123); +__w_pdfjs_require__(124); +var path = __w_pdfjs_require__(43); +module.exports = path.Promise; -__w_pdfjs_require__(105); +/***/ }), +/* 104 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -module.exports = __w_pdfjs_require__(14).Promise; +var redefine = __w_pdfjs_require__(30); +var toString = __w_pdfjs_require__(105); +var ObjectPrototype = Object.prototype; +if (toString !== ObjectPrototype.toString) { + redefine(ObjectPrototype, 'toString', toString, { unsafe: true }); +} /***/ }), -/* 87 */ +/* 105 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var classof = __w_pdfjs_require__(72); - +var classof = __w_pdfjs_require__(91); +var wellKnownSymbol = __w_pdfjs_require__(55); +var TO_STRING_TAG = wellKnownSymbol('toStringTag'); var test = {}; -test[__w_pdfjs_require__(35)('toStringTag')] = 'z'; - -if (test + '' != '[object z]') { - __w_pdfjs_require__(25)(Object.prototype, 'toString', function toString() { - return '[object ' + classof(this) + ']'; - }, true); -} +test[TO_STRING_TAG] = 'z'; +module.exports = String(test) !== '[object z]' ? function toString() { + return '[object ' + classof(this) + ']'; +} : test.toString; /***/ }), -/* 88 */ +/* 106 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; +var global = __w_pdfjs_require__(12); +var DOMIterables = __w_pdfjs_require__(107); +var ArrayIteratorMethods = __w_pdfjs_require__(108); +var hide = __w_pdfjs_require__(27); +var wellKnownSymbol = __w_pdfjs_require__(55); +var ITERATOR = wellKnownSymbol('iterator'); +var TO_STRING_TAG = wellKnownSymbol('toStringTag'); +var ArrayValues = ArrayIteratorMethods.values; +for (var COLLECTION_NAME in DOMIterables) { + var Collection = global[COLLECTION_NAME]; + var CollectionPrototype = Collection && Collection.prototype; + if (CollectionPrototype) { + if (CollectionPrototype[ITERATOR] !== ArrayValues) + try { + hide(CollectionPrototype, ITERATOR, ArrayValues); + } catch (error) { + CollectionPrototype[ITERATOR] = ArrayValues; + } + if (!CollectionPrototype[TO_STRING_TAG]) + hide(CollectionPrototype, TO_STRING_TAG, COLLECTION_NAME); + if (DOMIterables[COLLECTION_NAME]) + for (var METHOD_NAME in ArrayIteratorMethods) { + if (CollectionPrototype[METHOD_NAME] !== ArrayIteratorMethods[METHOD_NAME]) + try { + hide(CollectionPrototype, METHOD_NAME, ArrayIteratorMethods[METHOD_NAME]); + } catch (error) { + CollectionPrototype[METHOD_NAME] = ArrayIteratorMethods[METHOD_NAME]; + } + } + } +} +/***/ }), +/* 107 */ +/***/ (function(module, exports) { -var $iterators = __w_pdfjs_require__(89); - -var getKeys = __w_pdfjs_require__(59); - -var redefine = __w_pdfjs_require__(25); - -var global = __w_pdfjs_require__(13); - -var hide = __w_pdfjs_require__(15); - -var Iterators = __w_pdfjs_require__(55); - -var wks = __w_pdfjs_require__(35); - -var ITERATOR = wks('iterator'); -var TO_STRING_TAG = wks('toStringTag'); -var ArrayValues = Iterators.Array; -var DOMIterables = { - CSSRuleList: true, - CSSStyleDeclaration: false, - CSSValueList: false, - ClientRectList: false, - DOMRectList: false, - DOMStringList: false, - DOMTokenList: true, - DataTransferItemList: false, - FileList: false, - HTMLAllCollection: false, - HTMLCollection: false, - HTMLFormElement: false, - HTMLSelectElement: false, - MediaList: true, - MimeTypeArray: false, - NamedNodeMap: false, - NodeList: true, - PaintRequestList: false, - Plugin: false, - PluginArray: false, - SVGLengthList: false, - SVGNumberList: false, - SVGPathSegList: false, - SVGPointList: false, - SVGStringList: false, - SVGTransformList: false, - SourceBufferList: false, - StyleSheetList: true, - TextTrackCueList: false, - TextTrackList: false, - TouchList: false +module.exports = { + CSSRuleList: 0, + CSSStyleDeclaration: 0, + CSSValueList: 0, + ClientRectList: 0, + DOMRectList: 0, + DOMStringList: 0, + DOMTokenList: 1, + DataTransferItemList: 0, + FileList: 0, + HTMLAllCollection: 0, + HTMLCollection: 0, + HTMLFormElement: 0, + HTMLSelectElement: 0, + MediaList: 0, + MimeTypeArray: 0, + NamedNodeMap: 0, + NodeList: 1, + PaintRequestList: 0, + Plugin: 0, + PluginArray: 0, + SVGLengthList: 0, + SVGNumberList: 0, + SVGPathSegList: 0, + SVGPointList: 0, + SVGStringList: 0, + SVGTransformList: 0, + SourceBufferList: 0, + StyleSheetList: 0, + TextTrackCueList: 0, + TextTrackList: 0, + TouchList: 0 }; -for (var collections = getKeys(DOMIterables), i = 0; i < collections.length; i++) { - var NAME = collections[i]; - var explicit = DOMIterables[NAME]; - var Collection = global[NAME]; - var proto = Collection && Collection.prototype; - var key; - - if (proto) { - if (!proto[ITERATOR]) hide(proto, ITERATOR, ArrayValues); - if (!proto[TO_STRING_TAG]) hide(proto, TO_STRING_TAG, NAME); - Iterators[NAME] = ArrayValues; - if (explicit) for (key in $iterators) { - if (!proto[key]) redefine(proto, key, $iterators[key], true); - } - } -} - /***/ }), -/* 89 */ +/* 108 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var addToUnscopables = __w_pdfjs_require__(50); - -var step = __w_pdfjs_require__(90); - -var Iterators = __w_pdfjs_require__(55); - -var toIObject = __w_pdfjs_require__(47); - -module.exports = __w_pdfjs_require__(54)(Array, 'Array', function (iterated, kind) { - this._t = toIObject(iterated); - this._i = 0; - this._k = kind; +var toIndexedObject = __w_pdfjs_require__(18); +var addToUnscopables = __w_pdfjs_require__(67); +var Iterators = __w_pdfjs_require__(82); +var InternalStateModule = __w_pdfjs_require__(35); +var defineIterator = __w_pdfjs_require__(75); +var ARRAY_ITERATOR = 'Array Iterator'; +var setInternalState = InternalStateModule.set; +var getInternalState = InternalStateModule.getterFor(ARRAY_ITERATOR); +module.exports = defineIterator(Array, 'Array', function (iterated, kind) { + setInternalState(this, { + type: ARRAY_ITERATOR, + target: toIndexedObject(iterated), + index: 0, + kind: kind + }); }, function () { - var O = this._t; - var kind = this._k; - var index = this._i++; - - if (!O || index >= O.length) { - this._t = undefined; - return step(1); - } - - if (kind == 'keys') return step(0, index); - if (kind == 'values') return step(0, O[index]); - return step(0, [index, O[index]]); + var state = getInternalState(this); + var target = state.target; + var kind = state.kind; + var index = state.index++; + if (!target || index >= target.length) { + state.target = undefined; + return { + value: undefined, + done: true + }; + } + if (kind == 'keys') + return { + value: index, + done: false + }; + if (kind == 'values') + return { + value: target[index], + done: false + }; + return { + value: [ + index, + target[index] + ], + done: false + }; }, 'values'); Iterators.Arguments = Iterators.Array; addToUnscopables('keys'); @@ -4486,2197 +4409,3629 @@ addToUnscopables('values'); addToUnscopables('entries'); /***/ }), -/* 90 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -module.exports = function (done, value) { - return { - value: value, - done: !!done - }; -}; - -/***/ }), -/* 91 */ +/* 109 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var LIBRARY = __w_pdfjs_require__(37); - -var global = __w_pdfjs_require__(13); - -var ctx = __w_pdfjs_require__(28); - -var classof = __w_pdfjs_require__(72); - -var $export = __w_pdfjs_require__(12); - -var isObject = __w_pdfjs_require__(18); - -var aFunction = __w_pdfjs_require__(29); - -var anInstance = __w_pdfjs_require__(92); - -var forOf = __w_pdfjs_require__(93); - -var speciesConstructor = __w_pdfjs_require__(94); - -var task = __w_pdfjs_require__(95).set; - -var microtask = __w_pdfjs_require__(97)(); - -var newPromiseCapabilityModule = __w_pdfjs_require__(98); - -var perform = __w_pdfjs_require__(99); - -var userAgent = __w_pdfjs_require__(100); - -var promiseResolve = __w_pdfjs_require__(101); - +var $ = __w_pdfjs_require__(11); +var IS_PURE = __w_pdfjs_require__(33); +var global = __w_pdfjs_require__(12); +var path = __w_pdfjs_require__(43); +var NativePromise = __w_pdfjs_require__(110); +var redefine = __w_pdfjs_require__(30); +var redefineAll = __w_pdfjs_require__(111); +var setToStringTag = __w_pdfjs_require__(81); +var setSpecies = __w_pdfjs_require__(112); +var isObject = __w_pdfjs_require__(23); +var aFunction = __w_pdfjs_require__(60); +var anInstance = __w_pdfjs_require__(113); +var classof = __w_pdfjs_require__(20); +var iterate = __w_pdfjs_require__(114); +var checkCorrectnessOfIteration = __w_pdfjs_require__(92); +var speciesConstructor = __w_pdfjs_require__(115); +var task = __w_pdfjs_require__(116).set; +var microtask = __w_pdfjs_require__(117); +var promiseResolve = __w_pdfjs_require__(119); +var hostReportErrors = __w_pdfjs_require__(121); +var newPromiseCapabilityModule = __w_pdfjs_require__(120); +var perform = __w_pdfjs_require__(122); +var userAgent = __w_pdfjs_require__(118); +var InternalStateModule = __w_pdfjs_require__(35); +var isForced = __w_pdfjs_require__(52); +var wellKnownSymbol = __w_pdfjs_require__(55); +var SPECIES = wellKnownSymbol('species'); var PROMISE = 'Promise'; +var getInternalState = InternalStateModule.get; +var setInternalState = InternalStateModule.set; +var getInternalPromiseState = InternalStateModule.getterFor(PROMISE); +var PromiseConstructor = NativePromise; var TypeError = global.TypeError; +var document = global.document; var process = global.process; +var $fetch = global.fetch; var versions = process && process.versions; var v8 = versions && versions.v8 || ''; -var $Promise = global[PROMISE]; -var isNode = classof(process) == 'process'; - -var empty = function empty() {}; - -var Internal, newGenericPromiseCapability, OwnPromiseCapability, Wrapper; -var newPromiseCapability = newGenericPromiseCapability = newPromiseCapabilityModule.f; -var USE_NATIVE = !!function () { - try { - var promise = $Promise.resolve(1); - - var FakePromise = (promise.constructor = {})[__w_pdfjs_require__(35)('species')] = function (exec) { - exec(empty, empty); - }; - - return (isNode || typeof PromiseRejectionEvent == 'function') && promise.then(empty) instanceof FakePromise && v8.indexOf('6.6') !== 0 && userAgent.indexOf('Chrome/66') === -1; - } catch (e) {} -}(); - -var isThenable = function isThenable(it) { - var then; - return isObject(it) && typeof (then = it.then) == 'function' ? then : false; +var newPromiseCapability = newPromiseCapabilityModule.f; +var newGenericPromiseCapability = newPromiseCapability; +var IS_NODE = classof(process) == 'process'; +var DISPATCH_EVENT = !!(document && document.createEvent && global.dispatchEvent); +var UNHANDLED_REJECTION = 'unhandledrejection'; +var REJECTION_HANDLED = 'rejectionhandled'; +var PENDING = 0; +var FULFILLED = 1; +var REJECTED = 2; +var HANDLED = 1; +var UNHANDLED = 2; +var Internal, OwnPromiseCapability, PromiseWrapper, nativeThen; +var FORCED = isForced(PROMISE, function () { + var promise = PromiseConstructor.resolve(1); + var empty = function () { + }; + var FakePromise = (promise.constructor = {})[SPECIES] = function (exec) { + exec(empty, empty); + }; + return !((IS_NODE || typeof PromiseRejectionEvent == 'function') && (!IS_PURE || promise['finally']) && promise.then(empty) instanceof FakePromise && v8.indexOf('6.6') !== 0 && userAgent.indexOf('Chrome/66') === -1); +}); +var INCORRECT_ITERATION = FORCED || !checkCorrectnessOfIteration(function (iterable) { + PromiseConstructor.all(iterable)['catch'](function () { + }); +}); +var isThenable = function (it) { + var then; + return isObject(it) && typeof (then = it.then) == 'function' ? then : false; }; - -var notify = function notify(promise, isReject) { - if (promise._n) return; - promise._n = true; - var chain = promise._c; - microtask(function () { - var value = promise._v; - var ok = promise._s == 1; - var i = 0; - - var run = function run(reaction) { - var handler = ok ? reaction.ok : reaction.fail; - var resolve = reaction.resolve; - var reject = reaction.reject; - var domain = reaction.domain; - var result, then, exited; - - try { - if (handler) { - if (!ok) { - if (promise._h == 2) onHandleUnhandled(promise); - promise._h = 1; - } - - if (handler === true) result = value;else { - if (domain) domain.enter(); - result = handler(value); - - if (domain) { - domain.exit(); - exited = true; - } - } - - if (result === reaction.promise) { - reject(TypeError('Promise-chain cycle')); - } else if (then = isThenable(result)) { - then.call(result, resolve, reject); - } else resolve(result); - } else reject(value); - } catch (e) { - if (domain && !exited) domain.exit(); - reject(e); - } - }; - - while (chain.length > i) { - run(chain[i++]); - } - - promise._c = []; - promise._n = false; - if (isReject && !promise._h) onUnhandled(promise); - }); +var notify = function (promise, state, isReject) { + if (state.notified) + return; + state.notified = true; + var chain = state.reactions; + microtask(function () { + var value = state.value; + var ok = state.state == FULFILLED; + var index = 0; + while (chain.length > index) { + var reaction = chain[index++]; + var handler = ok ? reaction.ok : reaction.fail; + var resolve = reaction.resolve; + var reject = reaction.reject; + var domain = reaction.domain; + var result, then, exited; + try { + if (handler) { + if (!ok) { + if (state.rejection === UNHANDLED) + onHandleUnhandled(promise, state); + state.rejection = HANDLED; + } + if (handler === true) + result = value; + else { + if (domain) + domain.enter(); + result = handler(value); + if (domain) { + domain.exit(); + exited = true; + } + } + if (result === reaction.promise) { + reject(TypeError('Promise-chain cycle')); + } else if (then = isThenable(result)) { + then.call(result, resolve, reject); + } else + resolve(result); + } else + reject(value); + } catch (error) { + if (domain && !exited) + domain.exit(); + reject(error); + } + } + state.reactions = []; + state.notified = false; + if (isReject && !state.rejection) + onUnhandled(promise, state); + }); }; - -var onUnhandled = function onUnhandled(promise) { - task.call(global, function () { - var value = promise._v; - var unhandled = isUnhandled(promise); - var result, handler, console; - - if (unhandled) { - result = perform(function () { - if (isNode) { - process.emit('unhandledRejection', value, promise); - } else if (handler = global.onunhandledrejection) { - handler({ - promise: promise, - reason: value - }); - } else if ((console = global.console) && console.error) { - console.error('Unhandled promise rejection', value); - } - }); - promise._h = isNode || isUnhandled(promise) ? 2 : 1; - } - - promise._a = undefined; - if (unhandled && result.e) throw result.v; - }); +var dispatchEvent = function (name, promise, reason) { + var event, handler; + if (DISPATCH_EVENT) { + event = document.createEvent('Event'); + event.promise = promise; + event.reason = reason; + event.initEvent(name, false, true); + global.dispatchEvent(event); + } else + event = { + promise: promise, + reason: reason + }; + if (handler = global['on' + name]) + handler(event); + else if (name === UNHANDLED_REJECTION) + hostReportErrors('Unhandled promise rejection', reason); }; - -var isUnhandled = function isUnhandled(promise) { - return promise._h !== 1 && (promise._a || promise._c).length === 0; +var onUnhandled = function (promise, state) { + task.call(global, function () { + var value = state.value; + var IS_UNHANDLED = isUnhandled(state); + var result; + if (IS_UNHANDLED) { + result = perform(function () { + if (IS_NODE) { + process.emit('unhandledRejection', value, promise); + } else + dispatchEvent(UNHANDLED_REJECTION, promise, value); + }); + state.rejection = IS_NODE || isUnhandled(state) ? UNHANDLED : HANDLED; + if (result.error) + throw result.value; + } + }); }; - -var onHandleUnhandled = function onHandleUnhandled(promise) { - task.call(global, function () { - var handler; - - if (isNode) { - process.emit('rejectionHandled', promise); - } else if (handler = global.onrejectionhandled) { - handler({ - promise: promise, - reason: promise._v - }); - } - }); +var isUnhandled = function (state) { + return state.rejection !== HANDLED && !state.parent; }; - -var $reject = function $reject(value) { - var promise = this; - if (promise._d) return; - promise._d = true; - promise = promise._w || promise; - promise._v = value; - promise._s = 2; - if (!promise._a) promise._a = promise._c.slice(); - notify(promise, true); +var onHandleUnhandled = function (promise, state) { + task.call(global, function () { + if (IS_NODE) { + process.emit('rejectionHandled', promise); + } else + dispatchEvent(REJECTION_HANDLED, promise, state.value); + }); }; - -var $resolve = function $resolve(value) { - var promise = this; - var then; - if (promise._d) return; - promise._d = true; - promise = promise._w || promise; - - try { - if (promise === value) throw TypeError("Promise can't be resolved itself"); - - if (then = isThenable(value)) { - microtask(function () { - var wrapper = { - _w: promise, - _d: false - }; - - try { - then.call(value, ctx($resolve, wrapper, 1), ctx($reject, wrapper, 1)); - } catch (e) { - $reject.call(wrapper, e); - } - }); - } else { - promise._v = value; - promise._s = 1; - notify(promise, false); - } - } catch (e) { - $reject.call({ - _w: promise, - _d: false - }, e); - } +var bind = function (fn, promise, state, unwrap) { + return function (value) { + fn(promise, state, value, unwrap); + }; }; - -if (!USE_NATIVE) { - $Promise = function Promise(executor) { - anInstance(this, $Promise, PROMISE, '_h'); - aFunction(executor); - Internal.call(this); - +var internalReject = function (promise, state, value, unwrap) { + if (state.done) + return; + state.done = true; + if (unwrap) + state = unwrap; + state.value = value; + state.state = REJECTED; + notify(promise, state, true); +}; +var internalResolve = function (promise, state, value, unwrap) { + if (state.done) + return; + state.done = true; + if (unwrap) + state = unwrap; + try { + if (promise === value) + throw TypeError("Promise can't be resolved itself"); + var then = isThenable(value); + if (then) { + microtask(function () { + var wrapper = { done: false }; try { - executor(ctx($resolve, this, 1), ctx($reject, this, 1)); - } catch (err) { - $reject.call(this, err); - } - }; - - Internal = function Promise(executor) { - this._c = []; - this._a = undefined; - this._s = 0; - this._d = false; - this._v = undefined; - this._h = 0; - this._n = false; - }; - - Internal.prototype = __w_pdfjs_require__(102)($Promise.prototype, { - then: function then(onFulfilled, onRejected) { - var reaction = newPromiseCapability(speciesConstructor(this, $Promise)); - reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true; - reaction.fail = typeof onRejected == 'function' && onRejected; - reaction.domain = isNode ? process.domain : undefined; - - this._c.push(reaction); - - if (this._a) this._a.push(reaction); - if (this._s) notify(this, false); - return reaction.promise; - }, - 'catch': function _catch(onRejected) { - return this.then(undefined, onRejected); + then.call(value, bind(internalResolve, promise, wrapper, state), bind(internalReject, promise, wrapper, state)); + } catch (error) { + internalReject(promise, wrapper, error, state); } + }); + } else { + state.value = value; + state.state = FULFILLED; + notify(promise, state, false); + } + } catch (error) { + internalReject(promise, { done: false }, error, state); + } +}; +if (FORCED) { + PromiseConstructor = function Promise(executor) { + anInstance(this, PromiseConstructor, PROMISE); + aFunction(executor); + Internal.call(this); + var state = getInternalState(this); + try { + executor(bind(internalResolve, this, state), bind(internalReject, this, state)); + } catch (error) { + internalReject(this, state, error); + } + }; + Internal = function Promise(executor) { + setInternalState(this, { + type: PROMISE, + done: false, + notified: false, + parent: false, + reactions: [], + rejection: false, + state: PENDING, + value: undefined }); - - OwnPromiseCapability = function OwnPromiseCapability() { - var promise = new Internal(); - this.promise = promise; - this.resolve = ctx($resolve, promise, 1); - this.reject = ctx($reject, promise, 1); - }; - - newPromiseCapabilityModule.f = newPromiseCapability = function newPromiseCapability(C) { - return C === $Promise || C === Wrapper ? new OwnPromiseCapability(C) : newGenericPromiseCapability(C); - }; + }; + Internal.prototype = redefineAll(PromiseConstructor.prototype, { + then: function then(onFulfilled, onRejected) { + var state = getInternalPromiseState(this); + var reaction = newPromiseCapability(speciesConstructor(this, PromiseConstructor)); + reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true; + reaction.fail = typeof onRejected == 'function' && onRejected; + reaction.domain = IS_NODE ? process.domain : undefined; + state.parent = true; + state.reactions.push(reaction); + if (state.state != PENDING) + notify(this, state, false); + return reaction.promise; + }, + 'catch': function (onRejected) { + return this.then(undefined, onRejected); + } + }); + OwnPromiseCapability = function () { + var promise = new Internal(); + var state = getInternalState(promise); + this.promise = promise; + this.resolve = bind(internalResolve, promise, state); + this.reject = bind(internalReject, promise, state); + }; + newPromiseCapabilityModule.f = newPromiseCapability = function (C) { + return C === PromiseConstructor || C === PromiseWrapper ? new OwnPromiseCapability(C) : newGenericPromiseCapability(C); + }; + if (!IS_PURE && typeof NativePromise == 'function') { + nativeThen = NativePromise.prototype.then; + redefine(NativePromise.prototype, 'then', function then(onFulfilled, onRejected) { + var that = this; + return new PromiseConstructor(function (resolve, reject) { + nativeThen.call(that, resolve, reject); + }).then(onFulfilled, onRejected); + }); + if (typeof $fetch == 'function') + $({ + global: true, + enumerable: true, + forced: true + }, { + fetch: function fetch(input) { + return promiseResolve(PromiseConstructor, $fetch.apply(global, arguments)); + } + }); + } } - -$export($export.G + $export.W + $export.F * !USE_NATIVE, { - Promise: $Promise -}); - -__w_pdfjs_require__(64)($Promise, PROMISE); - -__w_pdfjs_require__(103)(PROMISE); - -Wrapper = __w_pdfjs_require__(14)[PROMISE]; -$export($export.S + $export.F * !USE_NATIVE, PROMISE, { - reject: function reject(r) { - var capability = newPromiseCapability(this); - var $$reject = capability.reject; - $$reject(r); - return capability.promise; - } +$({ + global: true, + wrap: true, + forced: FORCED +}, { Promise: PromiseConstructor }); +setToStringTag(PromiseConstructor, PROMISE, false, true); +setSpecies(PROMISE); +PromiseWrapper = path[PROMISE]; +$({ + target: PROMISE, + stat: true, + forced: FORCED +}, { + reject: function reject(r) { + var capability = newPromiseCapability(this); + capability.reject.call(undefined, r); + return capability.promise; + } }); -$export($export.S + $export.F * (LIBRARY || !USE_NATIVE), PROMISE, { - resolve: function resolve(x) { - return promiseResolve(LIBRARY && this === Wrapper ? $Promise : this, x); - } +$({ + target: PROMISE, + stat: true, + forced: IS_PURE || FORCED +}, { + resolve: function resolve(x) { + return promiseResolve(IS_PURE && this === PromiseWrapper ? PromiseConstructor : this, x); + } }); -$export($export.S + $export.F * !(USE_NATIVE && __w_pdfjs_require__(73)(function (iter) { - $Promise.all(iter)['catch'](empty); -})), PROMISE, { - all: function all(iterable) { - var C = this; - var capability = newPromiseCapability(C); - var resolve = capability.resolve; - var reject = capability.reject; - var result = perform(function () { - var values = []; - var index = 0; - var remaining = 1; - forOf(iterable, false, function (promise) { - var $index = index++; - var alreadyCalled = false; - values.push(undefined); - remaining++; - C.resolve(promise).then(function (value) { - if (alreadyCalled) return; - alreadyCalled = true; - values[$index] = value; - --remaining || resolve(values); - }, reject); - }); - --remaining || resolve(values); - }); - if (result.e) reject(result.v); - return capability.promise; - }, - race: function race(iterable) { - var C = this; - var capability = newPromiseCapability(C); - var reject = capability.reject; - var result = perform(function () { - forOf(iterable, false, function (promise) { - C.resolve(promise).then(capability.resolve, reject); - }); - }); - if (result.e) reject(result.v); - return capability.promise; - } +$({ + target: PROMISE, + stat: true, + forced: INCORRECT_ITERATION +}, { + all: function all(iterable) { + var C = this; + var capability = newPromiseCapability(C); + var resolve = capability.resolve; + var reject = capability.reject; + var result = perform(function () { + var $promiseResolve = aFunction(C.resolve); + var values = []; + var counter = 0; + var remaining = 1; + iterate(iterable, function (promise) { + var index = counter++; + var alreadyCalled = false; + values.push(undefined); + remaining++; + $promiseResolve.call(C, promise).then(function (value) { + if (alreadyCalled) + return; + alreadyCalled = true; + values[index] = value; + --remaining || resolve(values); + }, reject); + }); + --remaining || resolve(values); + }); + if (result.error) + reject(result.value); + return capability.promise; + }, + race: function race(iterable) { + var C = this; + var capability = newPromiseCapability(C); + var reject = capability.reject; + var result = perform(function () { + var $promiseResolve = aFunction(C.resolve); + iterate(iterable, function (promise) { + $promiseResolve.call(C, promise).then(capability.resolve, reject); + }); + }); + if (result.error) + reject(result.value); + return capability.promise; + } }); /***/ }), -/* 92 */ +/* 110 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - +var global = __w_pdfjs_require__(12); +module.exports = global.Promise; -module.exports = function (it, Constructor, name, forbiddenField) { - if (!(it instanceof Constructor) || forbiddenField !== undefined && forbiddenField in it) { - throw TypeError(name + ': incorrect invocation!'); - } +/***/ }), +/* 111 */ +/***/ (function(module, exports, __w_pdfjs_require__) { - return it; +var redefine = __w_pdfjs_require__(30); +module.exports = function (target, src, options) { + for (var key in src) + redefine(target, key, src[key], options); + return target; }; /***/ }), -/* 93 */ +/* 112 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; +var getBuiltIn = __w_pdfjs_require__(42); +var definePropertyModule = __w_pdfjs_require__(28); +var wellKnownSymbol = __w_pdfjs_require__(55); +var DESCRIPTORS = __w_pdfjs_require__(14); +var SPECIES = wellKnownSymbol('species'); +module.exports = function (CONSTRUCTOR_NAME) { + var Constructor = getBuiltIn(CONSTRUCTOR_NAME); + var defineProperty = definePropertyModule.f; + if (DESCRIPTORS && Constructor && !Constructor[SPECIES]) { + defineProperty(Constructor, SPECIES, { + configurable: true, + get: function () { + return this; + } + }); + } +}; -var ctx = __w_pdfjs_require__(28); - -var call = __w_pdfjs_require__(68); - -var isArrayIter = __w_pdfjs_require__(69); - -var anObject = __w_pdfjs_require__(17); - -var toLength = __w_pdfjs_require__(30); +/***/ }), +/* 113 */ +/***/ (function(module, exports) { -var getIterFn = __w_pdfjs_require__(71); +module.exports = function (it, Constructor, name) { + if (!(it instanceof Constructor)) { + throw TypeError('Incorrect ' + (name ? name + ' ' : '') + 'invocation'); + } + return it; +}; -var BREAK = {}; -var RETURN = {}; +/***/ }), +/* 114 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var _exports = module.exports = function (iterable, entries, fn, that, ITERATOR) { - var iterFn = ITERATOR ? function () { - return iterable; - } : getIterFn(iterable); - var f = ctx(fn, that, entries ? 2 : 1); - var index = 0; - var length, step, iterator, result; - if (typeof iterFn != 'function') throw TypeError(iterable + ' is not iterable!'); - if (isArrayIter(iterFn)) for (length = toLength(iterable.length); length > index; index++) { - result = entries ? f(anObject(step = iterable[index])[0], step[1]) : f(iterable[index]); - if (result === BREAK || result === RETURN) return result; - } else for (iterator = iterFn.call(iterable); !(step = iterator.next()).done;) { - result = call(iterator, f, step.value, entries); - if (result === BREAK || result === RETURN) return result; +var anObject = __w_pdfjs_require__(29); +var isArrayIteratorMethod = __w_pdfjs_require__(88); +var toLength = __w_pdfjs_require__(47); +var bind = __w_pdfjs_require__(59); +var getIteratorMethod = __w_pdfjs_require__(90); +var callWithSafeIterationClosing = __w_pdfjs_require__(87); +var Result = function (stopped, result) { + this.stopped = stopped; + this.result = result; +}; +var iterate = module.exports = function (iterable, fn, that, AS_ENTRIES, IS_ITERATOR) { + var boundFunction = bind(fn, that, AS_ENTRIES ? 2 : 1); + var iterator, iterFn, index, length, result, step; + if (IS_ITERATOR) { + iterator = iterable; + } else { + iterFn = getIteratorMethod(iterable); + if (typeof iterFn != 'function') + throw TypeError('Target is not iterable'); + if (isArrayIteratorMethod(iterFn)) { + for (index = 0, length = toLength(iterable.length); length > index; index++) { + result = AS_ENTRIES ? boundFunction(anObject(step = iterable[index])[0], step[1]) : boundFunction(iterable[index]); + if (result && result instanceof Result) + return result; + } + return new Result(false); } + iterator = iterFn.call(iterable); + } + while (!(step = iterator.next()).done) { + result = callWithSafeIterationClosing(iterator, boundFunction, step.value, AS_ENTRIES); + if (result && result instanceof Result) + return result; + } + return new Result(false); +}; +iterate.stop = function (result) { + return new Result(true, result); }; - -_exports.BREAK = BREAK; -_exports.RETURN = RETURN; /***/ }), -/* 94 */ +/* 115 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var anObject = __w_pdfjs_require__(17); - -var aFunction = __w_pdfjs_require__(29); - -var SPECIES = __w_pdfjs_require__(35)('species'); - -module.exports = function (O, D) { - var C = anObject(O).constructor; - var S; - return C === undefined || (S = anObject(C)[SPECIES]) == undefined ? D : aFunction(S); +var anObject = __w_pdfjs_require__(29); +var aFunction = __w_pdfjs_require__(60); +var wellKnownSymbol = __w_pdfjs_require__(55); +var SPECIES = wellKnownSymbol('species'); +module.exports = function (O, defaultConstructor) { + var C = anObject(O).constructor; + var S; + return C === undefined || (S = anObject(C)[SPECIES]) == undefined ? defaultConstructor : aFunction(S); }; /***/ }), -/* 95 */ +/* 116 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var ctx = __w_pdfjs_require__(28); - -var invoke = __w_pdfjs_require__(96); - -var html = __w_pdfjs_require__(63); - -var cel = __w_pdfjs_require__(22); - -var global = __w_pdfjs_require__(13); - +var global = __w_pdfjs_require__(12); +var fails = __w_pdfjs_require__(15); +var classof = __w_pdfjs_require__(20); +var bind = __w_pdfjs_require__(59); +var html = __w_pdfjs_require__(71); +var createElement = __w_pdfjs_require__(26); +var location = global.location; +var set = global.setImmediate; +var clear = global.clearImmediate; var process = global.process; -var setTask = global.setImmediate; -var clearTask = global.clearImmediate; var MessageChannel = global.MessageChannel; var Dispatch = global.Dispatch; var counter = 0; var queue = {}; var ONREADYSTATECHANGE = 'onreadystatechange'; var defer, channel, port; - -var run = function run() { - var id = +this; - - if (queue.hasOwnProperty(id)) { - var fn = queue[id]; - delete queue[id]; - fn(); - } +var run = function (id) { + if (queue.hasOwnProperty(id)) { + var fn = queue[id]; + delete queue[id]; + fn(); + } }; - -var listener = function listener(event) { - run.call(event.data); +var runner = function (id) { + return function () { + run(id); + }; }; - -if (!setTask || !clearTask) { - setTask = function setImmediate(fn) { - var args = []; - var i = 1; - - while (arguments.length > i) { - args.push(arguments[i++]); - } - - queue[++counter] = function () { - invoke(typeof fn == 'function' ? fn : Function(fn), args); - }; - - defer(counter); - return counter; +var listener = function (event) { + run(event.data); +}; +var post = function (id) { + global.postMessage(id + '', location.protocol + '//' + location.host); +}; +if (!set || !clear) { + set = function setImmediate(fn) { + var args = []; + var i = 1; + while (arguments.length > i) + args.push(arguments[i++]); + queue[++counter] = function () { + (typeof fn == 'function' ? fn : Function(fn)).apply(undefined, args); }; - - clearTask = function clearImmediate(id) { - delete queue[id]; + defer(counter); + return counter; + }; + clear = function clearImmediate(id) { + delete queue[id]; + }; + if (classof(process) == 'process') { + defer = function (id) { + process.nextTick(runner(id)); }; - - if (__w_pdfjs_require__(34)(process) == 'process') { - defer = function defer(id) { - process.nextTick(ctx(run, id, 1)); - }; - } else if (Dispatch && Dispatch.now) { - defer = function defer(id) { - Dispatch.now(ctx(run, id, 1)); - }; - } else if (MessageChannel) { - channel = new MessageChannel(); - port = channel.port2; - channel.port1.onmessage = listener; - defer = ctx(port.postMessage, port, 1); - } else if (global.addEventListener && typeof postMessage == 'function' && !global.importScripts) { - defer = function defer(id) { - global.postMessage(id + '', '*'); - }; - - global.addEventListener('message', listener, false); - } else if (ONREADYSTATECHANGE in cel('script')) { - defer = function defer(id) { - html.appendChild(cel('script'))[ONREADYSTATECHANGE] = function () { - html.removeChild(this); - run.call(id); - }; - }; - } else { - defer = function defer(id) { - setTimeout(ctx(run, id, 1), 0); - }; - } + } else if (Dispatch && Dispatch.now) { + defer = function (id) { + Dispatch.now(runner(id)); + }; + } else if (MessageChannel) { + channel = new MessageChannel(); + port = channel.port2; + channel.port1.onmessage = listener; + defer = bind(port.postMessage, port, 1); + } else if (global.addEventListener && typeof postMessage == 'function' && !global.importScripts && !fails(post)) { + defer = post; + global.addEventListener('message', listener, false); + } else if (ONREADYSTATECHANGE in createElement('script')) { + defer = function (id) { + html.appendChild(createElement('script'))[ONREADYSTATECHANGE] = function () { + html.removeChild(this); + run(id); + }; + }; + } else { + defer = function (id) { + setTimeout(runner(id), 0); + }; + } } - module.exports = { - set: setTask, - clear: clearTask + set: set, + clear: clear }; /***/ }), -/* 96 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -module.exports = function (fn, args, that) { - var un = that === undefined; - - switch (args.length) { - case 0: - return un ? fn() : fn.call(that); - - case 1: - return un ? fn(args[0]) : fn.call(that, args[0]); - - case 2: - return un ? fn(args[0], args[1]) : fn.call(that, args[0], args[1]); - - case 3: - return un ? fn(args[0], args[1], args[2]) : fn.call(that, args[0], args[1], args[2]); - - case 4: - return un ? fn(args[0], args[1], args[2], args[3]) : fn.call(that, args[0], args[1], args[2], args[3]); - } - - return fn.apply(that, args); -}; - -/***/ }), -/* 97 */ +/* 117 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var global = __w_pdfjs_require__(13); - -var macrotask = __w_pdfjs_require__(95).set; - -var Observer = global.MutationObserver || global.WebKitMutationObserver; +var global = __w_pdfjs_require__(12); +var getOwnPropertyDescriptor = __w_pdfjs_require__(13).f; +var classof = __w_pdfjs_require__(20); +var macrotask = __w_pdfjs_require__(116).set; +var userAgent = __w_pdfjs_require__(118); +var MutationObserver = global.MutationObserver || global.WebKitMutationObserver; var process = global.process; var Promise = global.Promise; -var isNode = __w_pdfjs_require__(34)(process) == 'process'; - -module.exports = function () { - var head, last, notify; - - var flush = function flush() { - var parent, fn; - if (isNode && (parent = process.domain)) parent.exit(); - - while (head) { - fn = head.fn; - head = head.next; - - try { - fn(); - } catch (e) { - if (head) notify();else last = undefined; - throw e; - } - } - - last = undefined; - if (parent) parent.enter(); - }; - - if (isNode) { - notify = function notify() { - process.nextTick(flush); - }; - } else if (Observer && !(global.navigator && global.navigator.standalone)) { - var toggle = true; - var node = document.createTextNode(''); - new Observer(flush).observe(node, { - characterData: true - }); - - notify = function notify() { - node.data = toggle = !toggle; - }; - } else if (Promise && Promise.resolve) { - var promise = Promise.resolve(undefined); - - notify = function notify() { - promise.then(flush); - }; - } else { - notify = function notify() { - macrotask.call(global, flush); - }; +var IS_NODE = classof(process) == 'process'; +var queueMicrotaskDescriptor = getOwnPropertyDescriptor(global, 'queueMicrotask'); +var queueMicrotask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value; +var flush, head, last, notify, toggle, node, promise, then; +if (!queueMicrotask) { + flush = function () { + var parent, fn; + if (IS_NODE && (parent = process.domain)) + parent.exit(); + while (head) { + fn = head.fn; + head = head.next; + try { + fn(); + } catch (error) { + if (head) + notify(); + else + last = undefined; + throw error; + } } - - return function (fn) { - var task = { - fn: fn, - next: undefined - }; - if (last) last.next = task; - - if (!head) { - head = task; - notify(); - } - - last = task; + last = undefined; + if (parent) + parent.enter(); + }; + if (IS_NODE) { + notify = function () { + process.nextTick(flush); }; -}; - -/***/ }), -/* 98 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var aFunction = __w_pdfjs_require__(29); - -function PromiseCapability(C) { - var resolve, reject; - this.promise = new C(function ($$resolve, $$reject) { - if (resolve !== undefined || reject !== undefined) throw TypeError('Bad Promise constructor'); - resolve = $$resolve; - reject = $$reject; - }); - this.resolve = aFunction(resolve); - this.reject = aFunction(reject); + } else if (MutationObserver && !/(iphone|ipod|ipad).*applewebkit/i.test(userAgent)) { + toggle = true; + node = document.createTextNode(''); + new MutationObserver(flush).observe(node, { characterData: true }); + notify = function () { + node.data = toggle = !toggle; + }; + } else if (Promise && Promise.resolve) { + promise = Promise.resolve(undefined); + then = promise.then; + notify = function () { + then.call(promise, flush); + }; + } else { + notify = function () { + macrotask.call(global, flush); + }; + } } - -module.exports.f = function (C) { - return new PromiseCapability(C); -}; - -/***/ }), -/* 99 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -module.exports = function (exec) { - try { - return { - e: false, - v: exec() - }; - } catch (e) { - return { - e: true, - v: e - }; - } +module.exports = queueMicrotask || function (fn) { + var task = { + fn: fn, + next: undefined + }; + if (last) + last.next = task; + if (!head) { + head = task; + notify(); + } + last = task; }; /***/ }), -/* 100 */ +/* 118 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var global = __w_pdfjs_require__(13); - -var navigator = global.navigator; -module.exports = navigator && navigator.userAgent || ''; +var getBuiltIn = __w_pdfjs_require__(42); +module.exports = getBuiltIn('navigator', 'userAgent') || ''; /***/ }), -/* 101 */ +/* 119 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var anObject = __w_pdfjs_require__(17); - -var isObject = __w_pdfjs_require__(18); - -var newPromiseCapability = __w_pdfjs_require__(98); - +var anObject = __w_pdfjs_require__(29); +var isObject = __w_pdfjs_require__(23); +var newPromiseCapability = __w_pdfjs_require__(120); module.exports = function (C, x) { - anObject(C); - if (isObject(x) && x.constructor === C) return x; - var promiseCapability = newPromiseCapability.f(C); - var resolve = promiseCapability.resolve; - resolve(x); - return promiseCapability.promise; + anObject(C); + if (isObject(x) && x.constructor === C) + return x; + var promiseCapability = newPromiseCapability.f(C); + var resolve = promiseCapability.resolve; + resolve(x); + return promiseCapability.promise; }; /***/ }), -/* 102 */ +/* 120 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var redefine = __w_pdfjs_require__(25); - -module.exports = function (target, src, safe) { - for (var key in src) { - redefine(target, key, src[key], safe); - } - - return target; +var aFunction = __w_pdfjs_require__(60); +var PromiseCapability = function (C) { + var resolve, reject; + this.promise = new C(function ($$resolve, $$reject) { + if (resolve !== undefined || reject !== undefined) + throw TypeError('Bad Promise constructor'); + resolve = $$resolve; + reject = $$reject; + }); + this.resolve = aFunction(resolve); + this.reject = aFunction(reject); +}; +module.exports.f = function (C) { + return new PromiseCapability(C); }; /***/ }), -/* 103 */ +/* 121 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var global = __w_pdfjs_require__(13); - -var dP = __w_pdfjs_require__(16); - -var DESCRIPTORS = __w_pdfjs_require__(20); +var global = __w_pdfjs_require__(12); +module.exports = function (a, b) { + var console = global.console; + if (console && console.error) { + arguments.length === 1 ? console.error(a) : console.error(a, b); + } +}; -var SPECIES = __w_pdfjs_require__(35)('species'); +/***/ }), +/* 122 */ +/***/ (function(module, exports) { -module.exports = function (KEY) { - var C = global[KEY]; - if (DESCRIPTORS && C && !C[SPECIES]) dP.f(C, SPECIES, { - configurable: true, - get: function get() { - return this; - } - }); +module.exports = function (exec) { + try { + return { + error: false, + value: exec() + }; + } catch (error) { + return { + error: true, + value: error + }; + } }; /***/ }), -/* 104 */ +/* 123 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var $export = __w_pdfjs_require__(12); - -var core = __w_pdfjs_require__(14); - -var global = __w_pdfjs_require__(13); - -var speciesConstructor = __w_pdfjs_require__(94); - -var promiseResolve = __w_pdfjs_require__(101); - -$export($export.P + $export.R, 'Promise', { - 'finally': function _finally(onFinally) { - var C = speciesConstructor(this, core.Promise || global.Promise); - var isFunction = typeof onFinally == 'function'; - return this.then(isFunction ? function (x) { - return promiseResolve(C, onFinally()).then(function () { - return x; - }); - } : onFinally, isFunction ? function (e) { - return promiseResolve(C, onFinally()).then(function () { - throw e; - }); - } : onFinally); - } +var $ = __w_pdfjs_require__(11); +var aFunction = __w_pdfjs_require__(60); +var newPromiseCapabilityModule = __w_pdfjs_require__(120); +var perform = __w_pdfjs_require__(122); +var iterate = __w_pdfjs_require__(114); +$({ + target: 'Promise', + stat: true +}, { + allSettled: function allSettled(iterable) { + var C = this; + var capability = newPromiseCapabilityModule.f(C); + var resolve = capability.resolve; + var reject = capability.reject; + var result = perform(function () { + var promiseResolve = aFunction(C.resolve); + var values = []; + var counter = 0; + var remaining = 1; + iterate(iterable, function (promise) { + var index = counter++; + var alreadyCalled = false; + values.push(undefined); + remaining++; + promiseResolve.call(C, promise).then(function (value) { + if (alreadyCalled) + return; + alreadyCalled = true; + values[index] = { + status: 'fulfilled', + value: value + }; + --remaining || resolve(values); + }, function (e) { + if (alreadyCalled) + return; + alreadyCalled = true; + values[index] = { + status: 'rejected', + reason: e + }; + --remaining || resolve(values); + }); + }); + --remaining || resolve(values); + }); + if (result.error) + reject(result.value); + return capability.promise; + } }); /***/ }), -/* 105 */ +/* 124 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var $export = __w_pdfjs_require__(12); - -var newPromiseCapability = __w_pdfjs_require__(98); - -var perform = __w_pdfjs_require__(99); - -$export($export.S, 'Promise', { - 'try': function _try(callbackfn) { - var promiseCapability = newPromiseCapability.f(this); - var result = perform(callbackfn); - (result.e ? promiseCapability.reject : promiseCapability.resolve)(result.v); - return promiseCapability.promise; - } +var $ = __w_pdfjs_require__(11); +var IS_PURE = __w_pdfjs_require__(33); +var NativePromise = __w_pdfjs_require__(110); +var getBuiltIn = __w_pdfjs_require__(42); +var speciesConstructor = __w_pdfjs_require__(115); +var promiseResolve = __w_pdfjs_require__(119); +var redefine = __w_pdfjs_require__(30); +$({ + target: 'Promise', + proto: true, + real: true +}, { + 'finally': function (onFinally) { + var C = speciesConstructor(this, getBuiltIn('Promise')); + var isFunction = typeof onFinally == 'function'; + return this.then(isFunction ? function (x) { + return promiseResolve(C, onFinally()).then(function () { + return x; + }); + } : onFinally, isFunction ? function (e) { + return promiseResolve(C, onFinally()).then(function () { + throw e; + }); + } : onFinally); + } }); +if (!IS_PURE && typeof NativePromise == 'function' && !NativePromise.prototype['finally']) { + redefine(NativePromise.prototype, 'finally', getBuiltIn('Promise').prototype['finally']); +} /***/ }), -/* 106 */ +/* 125 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(87); - -__w_pdfjs_require__(88); - -__w_pdfjs_require__(107); - -__w_pdfjs_require__(119); - -__w_pdfjs_require__(121); - -module.exports = __w_pdfjs_require__(14).WeakMap; +__w_pdfjs_require__(126); +__w_pdfjs_require__(131); +__w_pdfjs_require__(129); +var path = __w_pdfjs_require__(43); +module.exports = path.URL; /***/ }), -/* 107 */ +/* 126 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var each = __w_pdfjs_require__(108)(0); - -var redefine = __w_pdfjs_require__(25); - -var meta = __w_pdfjs_require__(112); - -var assign = __w_pdfjs_require__(76); - -var weak = __w_pdfjs_require__(113); - -var isObject = __w_pdfjs_require__(18); - -var fails = __w_pdfjs_require__(21); - -var validate = __w_pdfjs_require__(114); - -var WEAK_MAP = 'WeakMap'; -var getWeak = meta.getWeak; -var isExtensible = Object.isExtensible; -var uncaughtFrozenStore = weak.ufstore; -var tmp = {}; -var InternalMap; - -var wrapper = function wrapper(get) { - return function WeakMap() { - return get(this, arguments.length > 0 ? arguments[0] : undefined); - }; +__w_pdfjs_require__(73); +var $ = __w_pdfjs_require__(11); +var DESCRIPTORS = __w_pdfjs_require__(14); +var USE_NATIVE_URL = __w_pdfjs_require__(127); +var global = __w_pdfjs_require__(12); +var defineProperties = __w_pdfjs_require__(69); +var redefine = __w_pdfjs_require__(30); +var anInstance = __w_pdfjs_require__(113); +var has = __w_pdfjs_require__(24); +var assign = __w_pdfjs_require__(95); +var arrayFrom = __w_pdfjs_require__(86); +var codeAt = __w_pdfjs_require__(74).codeAt; +var toASCII = __w_pdfjs_require__(128); +var setToStringTag = __w_pdfjs_require__(81); +var URLSearchParamsModule = __w_pdfjs_require__(129); +var InternalStateModule = __w_pdfjs_require__(35); +var NativeURL = global.URL; +var URLSearchParams = URLSearchParamsModule.URLSearchParams; +var getInternalSearchParamsState = URLSearchParamsModule.getState; +var setInternalState = InternalStateModule.set; +var getInternalURLState = InternalStateModule.getterFor('URL'); +var floor = Math.floor; +var pow = Math.pow; +var INVALID_AUTHORITY = 'Invalid authority'; +var INVALID_SCHEME = 'Invalid scheme'; +var INVALID_HOST = 'Invalid host'; +var INVALID_PORT = 'Invalid port'; +var ALPHA = /[A-Za-z]/; +var ALPHANUMERIC = /[\d+\-.A-Za-z]/; +var DIGIT = /\d/; +var HEX_START = /^(0x|0X)/; +var OCT = /^[0-7]+$/; +var DEC = /^\d+$/; +var HEX = /^[\dA-Fa-f]+$/; +var FORBIDDEN_HOST_CODE_POINT = /[\u0000\u0009\u000A\u000D #%/:?@[\\]]/; +var FORBIDDEN_HOST_CODE_POINT_EXCLUDING_PERCENT = /[\u0000\u0009\u000A\u000D #/:?@[\\]]/; +var LEADING_AND_TRAILING_C0_CONTROL_OR_SPACE = /^[\u0000-\u001F ]+|[\u0000-\u001F ]+$/g; +var TAB_AND_NEW_LINE = /[\u0009\u000A\u000D]/g; +var EOF; +var parseHost = function (url, input) { + var result, codePoints, index; + if (input.charAt(0) == '[') { + if (input.charAt(input.length - 1) != ']') + return INVALID_HOST; + result = parseIPv6(input.slice(1, -1)); + if (!result) + return INVALID_HOST; + url.host = result; + } else if (!isSpecial(url)) { + if (FORBIDDEN_HOST_CODE_POINT_EXCLUDING_PERCENT.test(input)) + return INVALID_HOST; + result = ''; + codePoints = arrayFrom(input); + for (index = 0; index < codePoints.length; index++) { + result += percentEncode(codePoints[index], C0ControlPercentEncodeSet); + } + url.host = result; + } else { + input = toASCII(input); + if (FORBIDDEN_HOST_CODE_POINT.test(input)) + return INVALID_HOST; + result = parseIPv4(input); + if (result === null) + return INVALID_HOST; + url.host = result; + } }; - -var methods = { - get: function get(key) { - if (isObject(key)) { - var data = getWeak(key); - if (data === true) return uncaughtFrozenStore(validate(this, WEAK_MAP)).get(key); - return data ? data[this._i] : undefined; +var parseIPv4 = function (input) { + var parts = input.split('.'); + var partsLength, numbers, index, part, radix, number, ipv4; + if (parts.length && parts[parts.length - 1] == '') { + parts.pop(); + } + partsLength = parts.length; + if (partsLength > 4) + return input; + numbers = []; + for (index = 0; index < partsLength; index++) { + part = parts[index]; + if (part == '') + return input; + radix = 10; + if (part.length > 1 && part.charAt(0) == '0') { + radix = HEX_START.test(part) ? 16 : 8; + part = part.slice(radix == 8 ? 1 : 2); + } + if (part === '') { + number = 0; + } else { + if (!(radix == 10 ? DEC : radix == 8 ? OCT : HEX).test(part)) + return input; + number = parseInt(part, radix); + } + numbers.push(number); + } + for (index = 0; index < partsLength; index++) { + number = numbers[index]; + if (index == partsLength - 1) { + if (number >= pow(256, 5 - partsLength)) + return null; + } else if (number > 255) + return null; + } + ipv4 = numbers.pop(); + for (index = 0; index < numbers.length; index++) { + ipv4 += numbers[index] * pow(256, 3 - index); + } + return ipv4; +}; +var parseIPv6 = function (input) { + var address = [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ]; + var pieceIndex = 0; + var compress = null; + var pointer = 0; + var value, length, numbersSeen, ipv4Piece, number, swaps, swap; + var char = function () { + return input.charAt(pointer); + }; + if (char() == ':') { + if (input.charAt(1) != ':') + return; + pointer += 2; + pieceIndex++; + compress = pieceIndex; + } + while (char()) { + if (pieceIndex == 8) + return; + if (char() == ':') { + if (compress !== null) + return; + pointer++; + pieceIndex++; + compress = pieceIndex; + continue; + } + value = length = 0; + while (length < 4 && HEX.test(char())) { + value = value * 16 + parseInt(char(), 16); + pointer++; + length++; + } + if (char() == '.') { + if (length == 0) + return; + pointer -= length; + if (pieceIndex > 6) + return; + numbersSeen = 0; + while (char()) { + ipv4Piece = null; + if (numbersSeen > 0) { + if (char() == '.' && numbersSeen < 4) + pointer++; + else + return; } - }, - set: function set(key, value) { - return weak.def(validate(this, WEAK_MAP), key, value); + if (!DIGIT.test(char())) + return; + while (DIGIT.test(char())) { + number = parseInt(char(), 10); + if (ipv4Piece === null) + ipv4Piece = number; + else if (ipv4Piece == 0) + return; + else + ipv4Piece = ipv4Piece * 10 + number; + if (ipv4Piece > 255) + return; + pointer++; + } + address[pieceIndex] = address[pieceIndex] * 256 + ipv4Piece; + numbersSeen++; + if (numbersSeen == 2 || numbersSeen == 4) + pieceIndex++; + } + if (numbersSeen != 4) + return; + break; + } else if (char() == ':') { + pointer++; + if (!char()) + return; + } else if (char()) + return; + address[pieceIndex++] = value; + } + if (compress !== null) { + swaps = pieceIndex - compress; + pieceIndex = 7; + while (pieceIndex != 0 && swaps > 0) { + swap = address[pieceIndex]; + address[pieceIndex--] = address[compress + swaps - 1]; + address[compress + --swaps] = swap; + } + } else if (pieceIndex != 8) + return; + return address; +}; +var findLongestZeroSequence = function (ipv6) { + var maxIndex = null; + var maxLength = 1; + var currStart = null; + var currLength = 0; + var index = 0; + for (; index < 8; index++) { + if (ipv6[index] !== 0) { + if (currLength > maxLength) { + maxIndex = currStart; + maxLength = currLength; + } + currStart = null; + currLength = 0; + } else { + if (currStart === null) + currStart = index; + ++currLength; } + } + if (currLength > maxLength) { + maxIndex = currStart; + maxLength = currLength; + } + return maxIndex; }; - -var $WeakMap = module.exports = __w_pdfjs_require__(115)(WEAK_MAP, wrapper, methods, weak, true, true); - -if (fails(function () { - return new $WeakMap().set((Object.freeze || Object)(tmp), 7).get(tmp) != 7; -})) { - InternalMap = weak.getConstructor(wrapper, WEAK_MAP); - assign(InternalMap.prototype, methods); - meta.NEED = true; - each(['delete', 'has', 'get', 'set'], function (key) { - var proto = $WeakMap.prototype; - var method = proto[key]; - redefine(proto, key, function (a, b) { - if (isObject(a) && !isExtensible(a)) { - if (!this._f) this._f = new InternalMap(); - - var result = this._f[key](a, b); - - return key == 'set' ? this : result; - } - - return method.call(this, a, b); - }); +var serializeHost = function (host) { + var result, index, compress, ignore0; + if (typeof host == 'number') { + result = []; + for (index = 0; index < 4; index++) { + result.unshift(host % 256); + host = floor(host / 256); + } + return result.join('.'); + } else if (typeof host == 'object') { + result = ''; + compress = findLongestZeroSequence(host); + for (index = 0; index < 8; index++) { + if (ignore0 && host[index] === 0) + continue; + if (ignore0) + ignore0 = false; + if (compress === index) { + result += index ? ':' : '::'; + ignore0 = true; + } else { + result += host[index].toString(16); + if (index < 7) + result += ':'; + } + } + return '[' + result + ']'; + } + return host; +}; +var C0ControlPercentEncodeSet = {}; +var fragmentPercentEncodeSet = assign({}, C0ControlPercentEncodeSet, { + ' ': 1, + '"': 1, + '<': 1, + '>': 1, + '`': 1 +}); +var pathPercentEncodeSet = assign({}, fragmentPercentEncodeSet, { + '#': 1, + '?': 1, + '{': 1, + '}': 1 +}); +var userinfoPercentEncodeSet = assign({}, pathPercentEncodeSet, { + '/': 1, + ':': 1, + ';': 1, + '=': 1, + '@': 1, + '[': 1, + '\\': 1, + ']': 1, + '^': 1, + '|': 1 +}); +var percentEncode = function (char, set) { + var code = codeAt(char, 0); + return code > 0x20 && code < 0x7F && !has(set, char) ? char : encodeURIComponent(char); +}; +var specialSchemes = { + ftp: 21, + file: null, + gopher: 70, + http: 80, + https: 443, + ws: 80, + wss: 443 +}; +var isSpecial = function (url) { + return has(specialSchemes, url.scheme); +}; +var includesCredentials = function (url) { + return url.username != '' || url.password != ''; +}; +var cannotHaveUsernamePasswordPort = function (url) { + return !url.host || url.cannotBeABaseURL || url.scheme == 'file'; +}; +var isWindowsDriveLetter = function (string, normalized) { + var second; + return string.length == 2 && ALPHA.test(string.charAt(0)) && ((second = string.charAt(1)) == ':' || !normalized && second == '|'); +}; +var startsWithWindowsDriveLetter = function (string) { + var third; + return string.length > 1 && isWindowsDriveLetter(string.slice(0, 2)) && (string.length == 2 || ((third = string.charAt(2)) === '/' || third === '\\' || third === '?' || third === '#')); +}; +var shortenURLsPath = function (url) { + var path = url.path; + var pathSize = path.length; + if (pathSize && (url.scheme != 'file' || pathSize != 1 || !isWindowsDriveLetter(path[0], true))) { + path.pop(); + } +}; +var isSingleDot = function (segment) { + return segment === '.' || segment.toLowerCase() === '%2e'; +}; +var isDoubleDot = function (segment) { + segment = segment.toLowerCase(); + return segment === '..' || segment === '%2e.' || segment === '.%2e' || segment === '%2e%2e'; +}; +var SCHEME_START = {}; +var SCHEME = {}; +var NO_SCHEME = {}; +var SPECIAL_RELATIVE_OR_AUTHORITY = {}; +var PATH_OR_AUTHORITY = {}; +var RELATIVE = {}; +var RELATIVE_SLASH = {}; +var SPECIAL_AUTHORITY_SLASHES = {}; +var SPECIAL_AUTHORITY_IGNORE_SLASHES = {}; +var AUTHORITY = {}; +var HOST = {}; +var HOSTNAME = {}; +var PORT = {}; +var FILE = {}; +var FILE_SLASH = {}; +var FILE_HOST = {}; +var PATH_START = {}; +var PATH = {}; +var CANNOT_BE_A_BASE_URL_PATH = {}; +var QUERY = {}; +var FRAGMENT = {}; +var parseURL = function (url, input, stateOverride, base) { + var state = stateOverride || SCHEME_START; + var pointer = 0; + var buffer = ''; + var seenAt = false; + var seenBracket = false; + var seenPasswordToken = false; + var codePoints, char, bufferCodePoints, failure; + if (!stateOverride) { + url.scheme = ''; + url.username = ''; + url.password = ''; + url.host = null; + url.port = null; + url.path = []; + url.query = null; + url.fragment = null; + url.cannotBeABaseURL = false; + input = input.replace(LEADING_AND_TRAILING_C0_CONTROL_OR_SPACE, ''); + } + input = input.replace(TAB_AND_NEW_LINE, ''); + codePoints = arrayFrom(input); + while (pointer <= codePoints.length) { + char = codePoints[pointer]; + switch (state) { + case SCHEME_START: + if (char && ALPHA.test(char)) { + buffer += char.toLowerCase(); + state = SCHEME; + } else if (!stateOverride) { + state = NO_SCHEME; + continue; + } else + return INVALID_SCHEME; + break; + case SCHEME: + if (char && (ALPHANUMERIC.test(char) || char == '+' || char == '-' || char == '.')) { + buffer += char.toLowerCase(); + } else if (char == ':') { + if (stateOverride && (isSpecial(url) != has(specialSchemes, buffer) || buffer == 'file' && (includesCredentials(url) || url.port !== null) || url.scheme == 'file' && !url.host)) + return; + url.scheme = buffer; + if (stateOverride) { + if (isSpecial(url) && specialSchemes[url.scheme] == url.port) + url.port = null; + return; + } + buffer = ''; + if (url.scheme == 'file') { + state = FILE; + } else if (isSpecial(url) && base && base.scheme == url.scheme) { + state = SPECIAL_RELATIVE_OR_AUTHORITY; + } else if (isSpecial(url)) { + state = SPECIAL_AUTHORITY_SLASHES; + } else if (codePoints[pointer + 1] == '/') { + state = PATH_OR_AUTHORITY; + pointer++; + } else { + url.cannotBeABaseURL = true; + url.path.push(''); + state = CANNOT_BE_A_BASE_URL_PATH; + } + } else if (!stateOverride) { + buffer = ''; + state = NO_SCHEME; + pointer = 0; + continue; + } else + return INVALID_SCHEME; + break; + case NO_SCHEME: + if (!base || base.cannotBeABaseURL && char != '#') + return INVALID_SCHEME; + if (base.cannotBeABaseURL && char == '#') { + url.scheme = base.scheme; + url.path = base.path.slice(); + url.query = base.query; + url.fragment = ''; + url.cannotBeABaseURL = true; + state = FRAGMENT; + break; + } + state = base.scheme == 'file' ? FILE : RELATIVE; + continue; + case SPECIAL_RELATIVE_OR_AUTHORITY: + if (char == '/' && codePoints[pointer + 1] == '/') { + state = SPECIAL_AUTHORITY_IGNORE_SLASHES; + pointer++; + } else { + state = RELATIVE; + continue; + } + break; + case PATH_OR_AUTHORITY: + if (char == '/') { + state = AUTHORITY; + break; + } else { + state = PATH; + continue; + } + case RELATIVE: + url.scheme = base.scheme; + if (char == EOF) { + url.username = base.username; + url.password = base.password; + url.host = base.host; + url.port = base.port; + url.path = base.path.slice(); + url.query = base.query; + } else if (char == '/' || char == '\\' && isSpecial(url)) { + state = RELATIVE_SLASH; + } else if (char == '?') { + url.username = base.username; + url.password = base.password; + url.host = base.host; + url.port = base.port; + url.path = base.path.slice(); + url.query = ''; + state = QUERY; + } else if (char == '#') { + url.username = base.username; + url.password = base.password; + url.host = base.host; + url.port = base.port; + url.path = base.path.slice(); + url.query = base.query; + url.fragment = ''; + state = FRAGMENT; + } else { + url.username = base.username; + url.password = base.password; + url.host = base.host; + url.port = base.port; + url.path = base.path.slice(); + url.path.pop(); + state = PATH; + continue; + } + break; + case RELATIVE_SLASH: + if (isSpecial(url) && (char == '/' || char == '\\')) { + state = SPECIAL_AUTHORITY_IGNORE_SLASHES; + } else if (char == '/') { + state = AUTHORITY; + } else { + url.username = base.username; + url.password = base.password; + url.host = base.host; + url.port = base.port; + state = PATH; + continue; + } + break; + case SPECIAL_AUTHORITY_SLASHES: + state = SPECIAL_AUTHORITY_IGNORE_SLASHES; + if (char != '/' || buffer.charAt(pointer + 1) != '/') + continue; + pointer++; + break; + case SPECIAL_AUTHORITY_IGNORE_SLASHES: + if (char != '/' && char != '\\') { + state = AUTHORITY; + continue; + } + break; + case AUTHORITY: + if (char == '@') { + if (seenAt) + buffer = '%40' + buffer; + seenAt = true; + bufferCodePoints = arrayFrom(buffer); + for (var i = 0; i < bufferCodePoints.length; i++) { + var codePoint = bufferCodePoints[i]; + if (codePoint == ':' && !seenPasswordToken) { + seenPasswordToken = true; + continue; + } + var encodedCodePoints = percentEncode(codePoint, userinfoPercentEncodeSet); + if (seenPasswordToken) + url.password += encodedCodePoints; + else + url.username += encodedCodePoints; + } + buffer = ''; + } else if (char == EOF || char == '/' || char == '?' || char == '#' || char == '\\' && isSpecial(url)) { + if (seenAt && buffer == '') + return INVALID_AUTHORITY; + pointer -= arrayFrom(buffer).length + 1; + buffer = ''; + state = HOST; + } else + buffer += char; + break; + case HOST: + case HOSTNAME: + if (stateOverride && url.scheme == 'file') { + state = FILE_HOST; + continue; + } else if (char == ':' && !seenBracket) { + if (buffer == '') + return INVALID_HOST; + failure = parseHost(url, buffer); + if (failure) + return failure; + buffer = ''; + state = PORT; + if (stateOverride == HOSTNAME) + return; + } else if (char == EOF || char == '/' || char == '?' || char == '#' || char == '\\' && isSpecial(url)) { + if (isSpecial(url) && buffer == '') + return INVALID_HOST; + if (stateOverride && buffer == '' && (includesCredentials(url) || url.port !== null)) + return; + failure = parseHost(url, buffer); + if (failure) + return failure; + buffer = ''; + state = PATH_START; + if (stateOverride) + return; + continue; + } else { + if (char == '[') + seenBracket = true; + else if (char == ']') + seenBracket = false; + buffer += char; + } + break; + case PORT: + if (DIGIT.test(char)) { + buffer += char; + } else if (char == EOF || char == '/' || char == '?' || char == '#' || char == '\\' && isSpecial(url) || stateOverride) { + if (buffer != '') { + var port = parseInt(buffer, 10); + if (port > 0xFFFF) + return INVALID_PORT; + url.port = isSpecial(url) && port === specialSchemes[url.scheme] ? null : port; + buffer = ''; + } + if (stateOverride) + return; + state = PATH_START; + continue; + } else + return INVALID_PORT; + break; + case FILE: + url.scheme = 'file'; + if (char == '/' || char == '\\') + state = FILE_SLASH; + else if (base && base.scheme == 'file') { + if (char == EOF) { + url.host = base.host; + url.path = base.path.slice(); + url.query = base.query; + } else if (char == '?') { + url.host = base.host; + url.path = base.path.slice(); + url.query = ''; + state = QUERY; + } else if (char == '#') { + url.host = base.host; + url.path = base.path.slice(); + url.query = base.query; + url.fragment = ''; + state = FRAGMENT; + } else { + if (!startsWithWindowsDriveLetter(codePoints.slice(pointer).join(''))) { + url.host = base.host; + url.path = base.path.slice(); + shortenURLsPath(url); + } + state = PATH; + continue; + } + } else { + state = PATH; + continue; + } + break; + case FILE_SLASH: + if (char == '/' || char == '\\') { + state = FILE_HOST; + break; + } + if (base && base.scheme == 'file' && !startsWithWindowsDriveLetter(codePoints.slice(pointer).join(''))) { + if (isWindowsDriveLetter(base.path[0], true)) + url.path.push(base.path[0]); + else + url.host = base.host; + } + state = PATH; + continue; + case FILE_HOST: + if (char == EOF || char == '/' || char == '\\' || char == '?' || char == '#') { + if (!stateOverride && isWindowsDriveLetter(buffer)) { + state = PATH; + } else if (buffer == '') { + url.host = ''; + if (stateOverride) + return; + state = PATH_START; + } else { + failure = parseHost(url, buffer); + if (failure) + return failure; + if (url.host == 'localhost') + url.host = ''; + if (stateOverride) + return; + buffer = ''; + state = PATH_START; + } + continue; + } else + buffer += char; + break; + case PATH_START: + if (isSpecial(url)) { + state = PATH; + if (char != '/' && char != '\\') + continue; + } else if (!stateOverride && char == '?') { + url.query = ''; + state = QUERY; + } else if (!stateOverride && char == '#') { + url.fragment = ''; + state = FRAGMENT; + } else if (char != EOF) { + state = PATH; + if (char != '/') + continue; + } + break; + case PATH: + if (char == EOF || char == '/' || char == '\\' && isSpecial(url) || !stateOverride && (char == '?' || char == '#')) { + if (isDoubleDot(buffer)) { + shortenURLsPath(url); + if (char != '/' && !(char == '\\' && isSpecial(url))) { + url.path.push(''); + } + } else if (isSingleDot(buffer)) { + if (char != '/' && !(char == '\\' && isSpecial(url))) { + url.path.push(''); + } + } else { + if (url.scheme == 'file' && !url.path.length && isWindowsDriveLetter(buffer)) { + if (url.host) + url.host = ''; + buffer = buffer.charAt(0) + ':'; + } + url.path.push(buffer); + } + buffer = ''; + if (url.scheme == 'file' && (char == EOF || char == '?' || char == '#')) { + while (url.path.length > 1 && url.path[0] === '') { + url.path.shift(); + } + } + if (char == '?') { + url.query = ''; + state = QUERY; + } else if (char == '#') { + url.fragment = ''; + state = FRAGMENT; + } + } else { + buffer += percentEncode(char, pathPercentEncodeSet); + } + break; + case CANNOT_BE_A_BASE_URL_PATH: + if (char == '?') { + url.query = ''; + state = QUERY; + } else if (char == '#') { + url.fragment = ''; + state = FRAGMENT; + } else if (char != EOF) { + url.path[0] += percentEncode(char, C0ControlPercentEncodeSet); + } + break; + case QUERY: + if (!stateOverride && char == '#') { + url.fragment = ''; + state = FRAGMENT; + } else if (char != EOF) { + if (char == "'" && isSpecial(url)) + url.query += '%27'; + else if (char == '#') + url.query += '%23'; + else + url.query += percentEncode(char, C0ControlPercentEncodeSet); + } + break; + case FRAGMENT: + if (char != EOF) + url.fragment += percentEncode(char, fragmentPercentEncodeSet); + break; + } + pointer++; + } +}; +var URLConstructor = function URL(url) { + var that = anInstance(this, URLConstructor, 'URL'); + var base = arguments.length > 1 ? arguments[1] : undefined; + var urlString = String(url); + var state = setInternalState(that, { type: 'URL' }); + var baseState, failure; + if (base !== undefined) { + if (base instanceof URLConstructor) + baseState = getInternalURLState(base); + else { + failure = parseURL(baseState = {}, String(base)); + if (failure) + throw TypeError(failure); + } + } + failure = parseURL(state, urlString, null, baseState); + if (failure) + throw TypeError(failure); + var searchParams = state.searchParams = new URLSearchParams(); + var searchParamsState = getInternalSearchParamsState(searchParams); + searchParamsState.updateSearchParams(state.query); + searchParamsState.updateURL = function () { + state.query = String(searchParams) || null; + }; + if (!DESCRIPTORS) { + that.href = serializeURL.call(that); + that.origin = getOrigin.call(that); + that.protocol = getProtocol.call(that); + that.username = getUsername.call(that); + that.password = getPassword.call(that); + that.host = getHost.call(that); + that.hostname = getHostname.call(that); + that.port = getPort.call(that); + that.pathname = getPathname.call(that); + that.search = getSearch.call(that); + that.searchParams = getSearchParams.call(that); + that.hash = getHash.call(that); + } +}; +var URLPrototype = URLConstructor.prototype; +var serializeURL = function () { + var url = getInternalURLState(this); + var scheme = url.scheme; + var username = url.username; + var password = url.password; + var host = url.host; + var port = url.port; + var path = url.path; + var query = url.query; + var fragment = url.fragment; + var output = scheme + ':'; + if (host !== null) { + output += '//'; + if (includesCredentials(url)) { + output += username + (password ? ':' + password : '') + '@'; + } + output += serializeHost(host); + if (port !== null) + output += ':' + port; + } else if (scheme == 'file') + output += '//'; + output += url.cannotBeABaseURL ? path[0] : path.length ? '/' + path.join('/') : ''; + if (query !== null) + output += '?' + query; + if (fragment !== null) + output += '#' + fragment; + return output; +}; +var getOrigin = function () { + var url = getInternalURLState(this); + var scheme = url.scheme; + var port = url.port; + if (scheme == 'blob') + try { + return new URL(scheme.path[0]).origin; + } catch (error) { + return 'null'; + } + if (scheme == 'file' || !isSpecial(url)) + return 'null'; + return scheme + '://' + serializeHost(url.host) + (port !== null ? ':' + port : ''); +}; +var getProtocol = function () { + return getInternalURLState(this).scheme + ':'; +}; +var getUsername = function () { + return getInternalURLState(this).username; +}; +var getPassword = function () { + return getInternalURLState(this).password; +}; +var getHost = function () { + var url = getInternalURLState(this); + var host = url.host; + var port = url.port; + return host === null ? '' : port === null ? serializeHost(host) : serializeHost(host) + ':' + port; +}; +var getHostname = function () { + var host = getInternalURLState(this).host; + return host === null ? '' : serializeHost(host); +}; +var getPort = function () { + var port = getInternalURLState(this).port; + return port === null ? '' : String(port); +}; +var getPathname = function () { + var url = getInternalURLState(this); + var path = url.path; + return url.cannotBeABaseURL ? path[0] : path.length ? '/' + path.join('/') : ''; +}; +var getSearch = function () { + var query = getInternalURLState(this).query; + return query ? '?' + query : ''; +}; +var getSearchParams = function () { + return getInternalURLState(this).searchParams; +}; +var getHash = function () { + var fragment = getInternalURLState(this).fragment; + return fragment ? '#' + fragment : ''; +}; +var accessorDescriptor = function (getter, setter) { + return { + get: getter, + set: setter, + configurable: true, + enumerable: true + }; +}; +if (DESCRIPTORS) { + defineProperties(URLPrototype, { + href: accessorDescriptor(serializeURL, function (href) { + var url = getInternalURLState(this); + var urlString = String(href); + var failure = parseURL(url, urlString); + if (failure) + throw TypeError(failure); + getInternalSearchParamsState(url.searchParams).updateSearchParams(url.query); + }), + origin: accessorDescriptor(getOrigin), + protocol: accessorDescriptor(getProtocol, function (protocol) { + var url = getInternalURLState(this); + parseURL(url, String(protocol) + ':', SCHEME_START); + }), + username: accessorDescriptor(getUsername, function (username) { + var url = getInternalURLState(this); + var codePoints = arrayFrom(String(username)); + if (cannotHaveUsernamePasswordPort(url)) + return; + url.username = ''; + for (var i = 0; i < codePoints.length; i++) { + url.username += percentEncode(codePoints[i], userinfoPercentEncodeSet); + } + }), + password: accessorDescriptor(getPassword, function (password) { + var url = getInternalURLState(this); + var codePoints = arrayFrom(String(password)); + if (cannotHaveUsernamePasswordPort(url)) + return; + url.password = ''; + for (var i = 0; i < codePoints.length; i++) { + url.password += percentEncode(codePoints[i], userinfoPercentEncodeSet); + } + }), + host: accessorDescriptor(getHost, function (host) { + var url = getInternalURLState(this); + if (url.cannotBeABaseURL) + return; + parseURL(url, String(host), HOST); + }), + hostname: accessorDescriptor(getHostname, function (hostname) { + var url = getInternalURLState(this); + if (url.cannotBeABaseURL) + return; + parseURL(url, String(hostname), HOSTNAME); + }), + port: accessorDescriptor(getPort, function (port) { + var url = getInternalURLState(this); + if (cannotHaveUsernamePasswordPort(url)) + return; + port = String(port); + if (port == '') + url.port = null; + else + parseURL(url, port, PORT); + }), + pathname: accessorDescriptor(getPathname, function (pathname) { + var url = getInternalURLState(this); + if (url.cannotBeABaseURL) + return; + url.path = []; + parseURL(url, pathname + '', PATH_START); + }), + search: accessorDescriptor(getSearch, function (search) { + var url = getInternalURLState(this); + search = String(search); + if (search == '') { + url.query = null; + } else { + if ('?' == search.charAt(0)) + search = search.slice(1); + url.query = ''; + parseURL(url, search, QUERY); + } + getInternalSearchParamsState(url.searchParams).updateSearchParams(url.query); + }), + searchParams: accessorDescriptor(getSearchParams), + hash: accessorDescriptor(getHash, function (hash) { + var url = getInternalURLState(this); + hash = String(hash); + if (hash == '') { + url.fragment = null; + return; + } + if ('#' == hash.charAt(0)) + hash = hash.slice(1); + url.fragment = ''; + parseURL(url, hash, FRAGMENT); + }) + }); +} +redefine(URLPrototype, 'toJSON', function toJSON() { + return serializeURL.call(this); +}, { enumerable: true }); +redefine(URLPrototype, 'toString', function toString() { + return serializeURL.call(this); +}, { enumerable: true }); +if (NativeURL) { + var nativeCreateObjectURL = NativeURL.createObjectURL; + var nativeRevokeObjectURL = NativeURL.revokeObjectURL; + if (nativeCreateObjectURL) + redefine(URLConstructor, 'createObjectURL', function createObjectURL(blob) { + return nativeCreateObjectURL.apply(NativeURL, arguments); + }); + if (nativeRevokeObjectURL) + redefine(URLConstructor, 'revokeObjectURL', function revokeObjectURL(url) { + return nativeRevokeObjectURL.apply(NativeURL, arguments); }); } +setToStringTag(URLConstructor, 'URL'); +$({ + global: true, + forced: !USE_NATIVE_URL, + sham: !DESCRIPTORS +}, { URL: URLConstructor }); /***/ }), -/* 108 */ +/* 127 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var ctx = __w_pdfjs_require__(28); - -var IObject = __w_pdfjs_require__(48); - -var toObject = __w_pdfjs_require__(66); - -var toLength = __w_pdfjs_require__(30); - -var asc = __w_pdfjs_require__(109); - -module.exports = function (TYPE, $create) { - var IS_MAP = TYPE == 1; - var IS_FILTER = TYPE == 2; - var IS_SOME = TYPE == 3; - var IS_EVERY = TYPE == 4; - var IS_FIND_INDEX = TYPE == 6; - var NO_HOLES = TYPE == 5 || IS_FIND_INDEX; - var create = $create || asc; - return function ($this, callbackfn, that) { - var O = toObject($this); - var self = IObject(O); - var f = ctx(callbackfn, that, 3); - var length = toLength(self.length); - var index = 0; - var result = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined; - var val, res; - - for (; length > index; index++) { - if (NO_HOLES || index in self) { - val = self[index]; - res = f(val, index, O); - - if (TYPE) { - if (IS_MAP) result[index] = res;else if (res) switch (TYPE) { - case 3: - return true; - - case 5: - return val; - - case 6: - return index; - - case 2: - result.push(val); - } else if (IS_EVERY) return false; - } - } - } - - return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result; - }; -}; +var fails = __w_pdfjs_require__(15); +var wellKnownSymbol = __w_pdfjs_require__(55); +var IS_PURE = __w_pdfjs_require__(33); +var ITERATOR = wellKnownSymbol('iterator'); +module.exports = !fails(function () { + var url = new URL('b?e=1', 'http://a'); + var searchParams = url.searchParams; + url.pathname = 'c%20d'; + return IS_PURE && !url.toJSON || !searchParams.sort || url.href !== 'http://a/c%20d?e=1' || searchParams.get('e') !== '1' || String(new URLSearchParams('?a=1')) !== 'a=1' || !searchParams[ITERATOR] || new URL('https://a@b').username !== 'a' || new URLSearchParams(new URLSearchParams('a=b')).get('a') !== 'b' || new URL('http://тест').host !== 'xn--e1aybc' || new URL('http://a#б').hash !== '#%D0%B1'; +}); /***/ }), -/* 109 */ +/* 128 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var speciesConstructor = __w_pdfjs_require__(110); - -module.exports = function (original, length) { - return new (speciesConstructor(original))(length); +var maxInt = 2147483647; +var base = 36; +var tMin = 1; +var tMax = 26; +var skew = 38; +var damp = 700; +var initialBias = 72; +var initialN = 128; +var delimiter = '-'; +var regexNonASCII = /[^\0-\u007E]/; +var regexSeparators = /[.\u3002\uFF0E\uFF61]/g; +var OVERFLOW_ERROR = 'Overflow: input needs wider integers to process'; +var baseMinusTMin = base - tMin; +var floor = Math.floor; +var stringFromCharCode = String.fromCharCode; +var ucs2decode = function (string) { + var output = []; + var counter = 0; + var length = string.length; + while (counter < length) { + var value = string.charCodeAt(counter++); + if (value >= 0xD800 && value <= 0xDBFF && counter < length) { + var extra = string.charCodeAt(counter++); + if ((extra & 0xFC00) == 0xDC00) { + output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); + } else { + output.push(value); + counter--; + } + } else { + output.push(value); + } + } + return output; }; - -/***/ }), -/* 110 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var isObject = __w_pdfjs_require__(18); - -var isArray = __w_pdfjs_require__(111); - -var SPECIES = __w_pdfjs_require__(35)('species'); - -module.exports = function (original) { - var C; - - if (isArray(original)) { - C = original.constructor; - if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined; - - if (isObject(C)) { - C = C[SPECIES]; - if (C === null) C = undefined; - } +var digitToBasic = function (digit) { + return digit + 22 + 75 * (digit < 26); +}; +var adapt = function (delta, numPoints, firstTime) { + var k = 0; + delta = firstTime ? floor(delta / damp) : delta >> 1; + delta += floor(delta / numPoints); + for (; delta > baseMinusTMin * tMax >> 1; k += base) { + delta = floor(delta / baseMinusTMin); + } + return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); +}; +var encode = function (input) { + var output = []; + input = ucs2decode(input); + var inputLength = input.length; + var n = initialN; + var delta = 0; + var bias = initialBias; + var i, currentValue; + for (i = 0; i < input.length; i++) { + currentValue = input[i]; + if (currentValue < 0x80) { + output.push(stringFromCharCode(currentValue)); } - - return C === undefined ? Array : C; + } + var basicLength = output.length; + var handledCPCount = basicLength; + if (basicLength) { + output.push(delimiter); + } + while (handledCPCount < inputLength) { + var m = maxInt; + for (i = 0; i < input.length; i++) { + currentValue = input[i]; + if (currentValue >= n && currentValue < m) { + m = currentValue; + } + } + var handledCPCountPlusOne = handledCPCount + 1; + if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { + throw RangeError(OVERFLOW_ERROR); + } + delta += (m - n) * handledCPCountPlusOne; + n = m; + for (i = 0; i < input.length; i++) { + currentValue = input[i]; + if (currentValue < n && ++delta > maxInt) { + throw RangeError(OVERFLOW_ERROR); + } + if (currentValue == n) { + var q = delta; + for (var k = base;; k += base) { + var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias; + if (q < t) + break; + var qMinusT = q - t; + var baseMinusT = base - t; + output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT))); + q = floor(qMinusT / baseMinusT); + } + output.push(stringFromCharCode(digitToBasic(q))); + bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); + delta = 0; + ++handledCPCount; + } + } + ++delta; + ++n; + } + return output.join(''); }; - -/***/ }), -/* 111 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var cof = __w_pdfjs_require__(34); - -module.exports = Array.isArray || function isArray(arg) { - return cof(arg) == 'Array'; +module.exports = function (input) { + var encoded = []; + var labels = input.toLowerCase().replace(regexSeparators, '\u002E').split('.'); + var i, label; + for (i = 0; i < labels.length; i++) { + label = labels[i]; + encoded.push(regexNonASCII.test(label) ? 'xn--' + encode(label) : label); + } + return encoded.join('.'); }; /***/ }), -/* 112 */ +/* 129 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -function _typeof(obj) { 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 META = __w_pdfjs_require__(27)('meta'); - -var isObject = __w_pdfjs_require__(18); - -var has = __w_pdfjs_require__(26); - -var setDesc = __w_pdfjs_require__(16).f; - -var id = 0; - -var isExtensible = Object.isExtensible || function () { - return true; +__w_pdfjs_require__(108); +var $ = __w_pdfjs_require__(11); +var USE_NATIVE_URL = __w_pdfjs_require__(127); +var redefine = __w_pdfjs_require__(30); +var redefineAll = __w_pdfjs_require__(111); +var setToStringTag = __w_pdfjs_require__(81); +var createIteratorConstructor = __w_pdfjs_require__(76); +var InternalStateModule = __w_pdfjs_require__(35); +var anInstance = __w_pdfjs_require__(113); +var hasOwn = __w_pdfjs_require__(24); +var bind = __w_pdfjs_require__(59); +var anObject = __w_pdfjs_require__(29); +var isObject = __w_pdfjs_require__(23); +var getIterator = __w_pdfjs_require__(130); +var getIteratorMethod = __w_pdfjs_require__(90); +var wellKnownSymbol = __w_pdfjs_require__(55); +var ITERATOR = wellKnownSymbol('iterator'); +var URL_SEARCH_PARAMS = 'URLSearchParams'; +var URL_SEARCH_PARAMS_ITERATOR = URL_SEARCH_PARAMS + 'Iterator'; +var setInternalState = InternalStateModule.set; +var getInternalParamsState = InternalStateModule.getterFor(URL_SEARCH_PARAMS); +var getInternalIteratorState = InternalStateModule.getterFor(URL_SEARCH_PARAMS_ITERATOR); +var plus = /\+/g; +var sequences = Array(4); +var percentSequence = function (bytes) { + return sequences[bytes - 1] || (sequences[bytes - 1] = RegExp('((?:%[\\da-f]{2}){' + bytes + '})', 'gi')); }; - -var FREEZE = !__w_pdfjs_require__(21)(function () { - return isExtensible(Object.preventExtensions({})); -}); - -var setMeta = function setMeta(it) { - setDesc(it, META, { - value: { - i: 'O' + ++id, - w: {} - } - }); +var percentDecode = function (sequence) { + try { + return decodeURIComponent(sequence); + } catch (error) { + return sequence; + } }; - -var fastKey = function fastKey(it, create) { - if (!isObject(it)) return _typeof(it) == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it; - - if (!has(it, META)) { - if (!isExtensible(it)) return 'F'; - if (!create) return 'E'; - setMeta(it); +var deserialize = function (it) { + var result = it.replace(plus, ' '); + var bytes = 4; + try { + return decodeURIComponent(result); + } catch (error) { + while (bytes) { + result = result.replace(percentSequence(bytes--), percentDecode); } - - return it[META].i; + return result; + } }; - -var getWeak = function getWeak(it, create) { - if (!has(it, META)) { - if (!isExtensible(it)) return true; - if (!create) return false; - setMeta(it); - } - - return it[META].w; +var find = /[!'()~]|%20/g; +var replace = { + '!': '%21', + "'": '%27', + '(': '%28', + ')': '%29', + '~': '%7E', + '%20': '+' }; - -var onFreeze = function onFreeze(it) { - if (FREEZE && meta.NEED && isExtensible(it) && !has(it, META)) setMeta(it); - return it; +var replacer = function (match) { + return replace[match]; }; - -var meta = module.exports = { - KEY: META, - NEED: false, - fastKey: fastKey, - getWeak: getWeak, - onFreeze: onFreeze +var serialize = function (it) { + return encodeURIComponent(it).replace(find, replacer); }; - -/***/ }), -/* 113 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var redefineAll = __w_pdfjs_require__(102); - -var getWeak = __w_pdfjs_require__(112).getWeak; - -var anObject = __w_pdfjs_require__(17); - -var isObject = __w_pdfjs_require__(18); - -var anInstance = __w_pdfjs_require__(92); - -var forOf = __w_pdfjs_require__(93); - -var createArrayMethod = __w_pdfjs_require__(108); - -var $has = __w_pdfjs_require__(26); - -var validate = __w_pdfjs_require__(114); - -var arrayFind = createArrayMethod(5); -var arrayFindIndex = createArrayMethod(6); -var id = 0; - -var uncaughtFrozenStore = function uncaughtFrozenStore(that) { - return that._l || (that._l = new UncaughtFrozenStore()); +var parseSearchParams = function (result, query) { + if (query) { + var attributes = query.split('&'); + var index = 0; + var attribute, entry; + while (index < attributes.length) { + attribute = attributes[index++]; + if (attribute.length) { + entry = attribute.split('='); + result.push({ + key: deserialize(entry.shift()), + value: deserialize(entry.join('=')) + }); + } + } + } }; - -var UncaughtFrozenStore = function UncaughtFrozenStore() { - this.a = []; +var updateSearchParams = function (query) { + this.entries.length = 0; + parseSearchParams(this.entries, query); }; - -var findUncaughtFrozen = function findUncaughtFrozen(store, key) { - return arrayFind(store.a, function (it) { - return it[0] === key; - }); +var validateArgumentsLength = function (passed, required) { + if (passed < required) + throw TypeError('Not enough arguments'); }; - -UncaughtFrozenStore.prototype = { - get: function get(key) { - var entry = findUncaughtFrozen(this, key); - if (entry) return entry[1]; - }, - has: function has(key) { - return !!findUncaughtFrozen(this, key); - }, - set: function set(key, value) { - var entry = findUncaughtFrozen(this, key); - if (entry) entry[1] = value;else this.a.push([key, value]); +var URLSearchParamsIterator = createIteratorConstructor(function Iterator(params, kind) { + setInternalState(this, { + type: URL_SEARCH_PARAMS_ITERATOR, + iterator: getIterator(getInternalParamsState(params).entries), + kind: kind + }); +}, 'Iterator', function next() { + var state = getInternalIteratorState(this); + var kind = state.kind; + var step = state.iterator.next(); + var entry = step.value; + if (!step.done) { + step.value = kind === 'keys' ? entry.key : kind === 'values' ? entry.value : [ + entry.key, + entry.value + ]; + } + return step; +}); +var URLSearchParamsConstructor = function URLSearchParams() { + anInstance(this, URLSearchParamsConstructor, URL_SEARCH_PARAMS); + var init = arguments.length > 0 ? arguments[0] : undefined; + var that = this; + var entries = []; + var iteratorMethod, iterator, step, entryIterator, first, second, key; + setInternalState(that, { + type: URL_SEARCH_PARAMS, + entries: entries, + updateURL: function () { }, - 'delete': function _delete(key) { - var index = arrayFindIndex(this.a, function (it) { - return it[0] === key; - }); - if (~index) this.a.splice(index, 1); - return !!~index; + updateSearchParams: updateSearchParams + }); + if (init !== undefined) { + if (isObject(init)) { + iteratorMethod = getIteratorMethod(init); + if (typeof iteratorMethod === 'function') { + iterator = iteratorMethod.call(init); + while (!(step = iterator.next()).done) { + entryIterator = getIterator(anObject(step.value)); + if ((first = entryIterator.next()).done || (second = entryIterator.next()).done || !entryIterator.next().done) + throw TypeError('Expected sequence with length 2'); + entries.push({ + key: first.value + '', + value: second.value + '' + }); + } + } else + for (key in init) + if (hasOwn(init, key)) + entries.push({ + key: key, + value: init[key] + '' + }); + } else { + parseSearchParams(entries, typeof init === 'string' ? init.charAt(0) === '?' ? init.slice(1) : init : init + ''); } + } }; +var URLSearchParamsPrototype = URLSearchParamsConstructor.prototype; +redefineAll(URLSearchParamsPrototype, { + append: function append(name, value) { + validateArgumentsLength(arguments.length, 2); + var state = getInternalParamsState(this); + state.entries.push({ + key: name + '', + value: value + '' + }); + state.updateURL(); + }, + 'delete': function (name) { + validateArgumentsLength(arguments.length, 1); + var state = getInternalParamsState(this); + var entries = state.entries; + var key = name + ''; + var index = 0; + while (index < entries.length) { + if (entries[index].key === key) + entries.splice(index, 1); + else + index++; + } + state.updateURL(); + }, + get: function get(name) { + validateArgumentsLength(arguments.length, 1); + var entries = getInternalParamsState(this).entries; + var key = name + ''; + var index = 0; + for (; index < entries.length; index++) { + if (entries[index].key === key) + return entries[index].value; + } + return null; + }, + getAll: function getAll(name) { + validateArgumentsLength(arguments.length, 1); + var entries = getInternalParamsState(this).entries; + var key = name + ''; + var result = []; + var index = 0; + for (; index < entries.length; index++) { + if (entries[index].key === key) + result.push(entries[index].value); + } + return result; + }, + has: function has(name) { + validateArgumentsLength(arguments.length, 1); + var entries = getInternalParamsState(this).entries; + var key = name + ''; + var index = 0; + while (index < entries.length) { + if (entries[index++].key === key) + return true; + } + return false; + }, + set: function set(name, value) { + validateArgumentsLength(arguments.length, 1); + var state = getInternalParamsState(this); + var entries = state.entries; + var found = false; + var key = name + ''; + var val = value + ''; + var index = 0; + var entry; + for (; index < entries.length; index++) { + entry = entries[index]; + if (entry.key === key) { + if (found) + entries.splice(index--, 1); + else { + found = true; + entry.value = val; + } + } + } + if (!found) + entries.push({ + key: key, + value: val + }); + state.updateURL(); + }, + sort: function sort() { + var state = getInternalParamsState(this); + var entries = state.entries; + var slice = entries.slice(); + var entry, entriesIndex, sliceIndex; + entries.length = 0; + for (sliceIndex = 0; sliceIndex < slice.length; sliceIndex++) { + entry = slice[sliceIndex]; + for (entriesIndex = 0; entriesIndex < sliceIndex; entriesIndex++) { + if (entries[entriesIndex].key > entry.key) { + entries.splice(entriesIndex, 0, entry); + break; + } + } + if (entriesIndex === sliceIndex) + entries.push(entry); + } + state.updateURL(); + }, + forEach: function forEach(callback) { + var entries = getInternalParamsState(this).entries; + var boundFunction = bind(callback, arguments.length > 1 ? arguments[1] : undefined, 3); + var index = 0; + var entry; + while (index < entries.length) { + entry = entries[index++]; + boundFunction(entry.value, entry.key, this); + } + }, + keys: function keys() { + return new URLSearchParamsIterator(this, 'keys'); + }, + values: function values() { + return new URLSearchParamsIterator(this, 'values'); + }, + entries: function entries() { + return new URLSearchParamsIterator(this, 'entries'); + } +}, { enumerable: true }); +redefine(URLSearchParamsPrototype, ITERATOR, URLSearchParamsPrototype.entries); +redefine(URLSearchParamsPrototype, 'toString', function toString() { + var entries = getInternalParamsState(this).entries; + var result = []; + var index = 0; + var entry; + while (index < entries.length) { + entry = entries[index++]; + result.push(serialize(entry.key) + '=' + serialize(entry.value)); + } + return result.join('&'); +}, { enumerable: true }); +setToStringTag(URLSearchParamsConstructor, URL_SEARCH_PARAMS); +$({ + global: true, + forced: !USE_NATIVE_URL +}, { URLSearchParams: URLSearchParamsConstructor }); module.exports = { - getConstructor: function getConstructor(wrapper, NAME, IS_MAP, ADDER) { - var C = wrapper(function (that, iterable) { - anInstance(that, C, NAME, '_i'); - that._t = NAME; - that._i = id++; - that._l = undefined; - if (iterable != undefined) forOf(iterable, IS_MAP, that[ADDER], that); - }); - redefineAll(C.prototype, { - 'delete': function _delete(key) { - if (!isObject(key)) return false; - var data = getWeak(key); - if (data === true) return uncaughtFrozenStore(validate(this, NAME))['delete'](key); - return data && $has(data, this._i) && delete data[this._i]; - }, - has: function has(key) { - if (!isObject(key)) return false; - var data = getWeak(key); - if (data === true) return uncaughtFrozenStore(validate(this, NAME)).has(key); - return data && $has(data, this._i); - } - }); - return C; - }, - def: function def(that, key, value) { - var data = getWeak(anObject(key), true); - if (data === true) uncaughtFrozenStore(that).set(key, value);else data[that._i] = value; - return that; - }, - ufstore: uncaughtFrozenStore + URLSearchParams: URLSearchParamsConstructor, + getState: getInternalParamsState }; /***/ }), -/* 114 */ +/* 130 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var isObject = __w_pdfjs_require__(18); - -module.exports = function (it, TYPE) { - if (!isObject(it) || it._t !== TYPE) throw TypeError('Incompatible receiver, ' + TYPE + ' required!'); - return it; +var anObject = __w_pdfjs_require__(29); +var getIteratorMethod = __w_pdfjs_require__(90); +module.exports = function (it) { + var iteratorMethod = getIteratorMethod(it); + if (typeof iteratorMethod != 'function') { + throw TypeError(String(it) + ' is not iterable'); + } + return anObject(iteratorMethod.call(it)); }; /***/ }), -/* 115 */ +/* 131 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var global = __w_pdfjs_require__(13); - -var $export = __w_pdfjs_require__(12); - -var redefine = __w_pdfjs_require__(25); - -var redefineAll = __w_pdfjs_require__(102); - -var meta = __w_pdfjs_require__(112); - -var forOf = __w_pdfjs_require__(93); - -var anInstance = __w_pdfjs_require__(92); - -var isObject = __w_pdfjs_require__(18); - -var fails = __w_pdfjs_require__(21); - -var $iterDetect = __w_pdfjs_require__(73); - -var setToStringTag = __w_pdfjs_require__(64); - -var inheritIfRequired = __w_pdfjs_require__(116); - -module.exports = function (NAME, wrapper, methods, common, IS_MAP, IS_WEAK) { - var Base = global[NAME]; - var C = Base; - var ADDER = IS_MAP ? 'set' : 'add'; - var proto = C && C.prototype; - var O = {}; - - var fixMethod = function fixMethod(KEY) { - var fn = proto[KEY]; - redefine(proto, KEY, KEY == 'delete' ? function (a) { - return IS_WEAK && !isObject(a) ? false : fn.call(this, a === 0 ? 0 : a); - } : KEY == 'has' ? function has(a) { - return IS_WEAK && !isObject(a) ? false : fn.call(this, a === 0 ? 0 : a); - } : KEY == 'get' ? function get(a) { - return IS_WEAK && !isObject(a) ? undefined : fn.call(this, a === 0 ? 0 : a); - } : KEY == 'add' ? function add(a) { - fn.call(this, a === 0 ? 0 : a); - return this; - } : function set(a, b) { - fn.call(this, a === 0 ? 0 : a, b); - return this; - }); - }; - - if (typeof C != 'function' || !(IS_WEAK || proto.forEach && !fails(function () { - new C().entries().next(); - }))) { - C = common.getConstructor(wrapper, NAME, IS_MAP, ADDER); - redefineAll(C.prototype, methods); - meta.NEED = true; - } else { - var instance = new C(); - var HASNT_CHAINING = instance[ADDER](IS_WEAK ? {} : -0, 1) != instance; - var THROWS_ON_PRIMITIVES = fails(function () { - instance.has(1); - }); - var ACCEPT_ITERABLES = $iterDetect(function (iter) { - new C(iter); - }); - var BUGGY_ZERO = !IS_WEAK && fails(function () { - var $instance = new C(); - var index = 5; - - while (index--) { - $instance[ADDER](index, index); - } - - return !$instance.has(-0); - }); - - if (!ACCEPT_ITERABLES) { - C = wrapper(function (target, iterable) { - anInstance(target, C, NAME); - var that = inheritIfRequired(new Base(), target, C); - if (iterable != undefined) forOf(iterable, IS_MAP, that[ADDER], that); - return that; - }); - C.prototype = proto; - proto.constructor = C; - } - - if (THROWS_ON_PRIMITIVES || BUGGY_ZERO) { - fixMethod('delete'); - fixMethod('has'); - IS_MAP && fixMethod('get'); - } - - if (BUGGY_ZERO || HASNT_CHAINING) fixMethod(ADDER); - if (IS_WEAK && proto.clear) delete proto.clear; - } - - setToStringTag(C, NAME); - O[NAME] = C; - $export($export.G + $export.W + $export.F * (C != Base), O); - if (!IS_WEAK) common.setStrong(C, NAME, IS_MAP); - return C; -}; +var $ = __w_pdfjs_require__(11); +$({ + target: 'URL', + proto: true, + enumerable: true +}, { + toJSON: function toJSON() { + return URL.prototype.toString.call(this); + } +}); /***/ }), -/* 116 */ +/* 132 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var isObject = __w_pdfjs_require__(18); - -var setPrototypeOf = __w_pdfjs_require__(117).set; - -module.exports = function (that, target, C) { - var S = target.constructor; - var P; - - if (S !== C && typeof S == 'function' && (P = S.prototype) !== C.prototype && isObject(P) && setPrototypeOf) { - setPrototypeOf(that, P); - } - - return that; -}; +__w_pdfjs_require__(104); +__w_pdfjs_require__(133); +__w_pdfjs_require__(106); +var path = __w_pdfjs_require__(43); +module.exports = path.WeakMap; /***/ }), -/* 117 */ +/* 133 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var isObject = __w_pdfjs_require__(18); - -var anObject = __w_pdfjs_require__(17); - -var check = function check(O, proto) { - anObject(O); - if (!isObject(proto) && proto !== null) throw TypeError(proto + ": can't set as prototype!"); -}; - -module.exports = { - set: Object.setPrototypeOf || ('__proto__' in {} ? function (test, buggy, set) { - try { - set = __w_pdfjs_require__(28)(Function.call, __w_pdfjs_require__(118).f(Object.prototype, '__proto__').set, 2); - set(test, []); - buggy = !(test instanceof Array); - } catch (e) { - buggy = true; - } - - return function setPrototypeOf(O, proto) { - check(O, proto); - if (buggy) O.__proto__ = proto;else set(O, proto); - return O; - }; - }({}, false) : undefined), - check: check +var global = __w_pdfjs_require__(12); +var redefineAll = __w_pdfjs_require__(111); +var InternalMetadataModule = __w_pdfjs_require__(134); +var collection = __w_pdfjs_require__(136); +var collectionWeak = __w_pdfjs_require__(138); +var isObject = __w_pdfjs_require__(23); +var enforceIternalState = __w_pdfjs_require__(35).enforce; +var NATIVE_WEAK_MAP = __w_pdfjs_require__(36); +var IS_IE11 = !global.ActiveXObject && 'ActiveXObject' in global; +var isExtensible = Object.isExtensible; +var InternalWeakMap; +var wrapper = function (get) { + return function WeakMap() { + return get(this, arguments.length ? arguments[0] : undefined); + }; }; +var $WeakMap = module.exports = collection('WeakMap', wrapper, collectionWeak, true, true); +if (NATIVE_WEAK_MAP && IS_IE11) { + InternalWeakMap = collectionWeak.getConstructor(wrapper, 'WeakMap', true); + InternalMetadataModule.REQUIRED = true; + var WeakMapPrototype = $WeakMap.prototype; + var nativeDelete = WeakMapPrototype['delete']; + var nativeHas = WeakMapPrototype.has; + var nativeGet = WeakMapPrototype.get; + var nativeSet = WeakMapPrototype.set; + redefineAll(WeakMapPrototype, { + 'delete': function (key) { + if (isObject(key) && !isExtensible(key)) { + var state = enforceIternalState(this); + if (!state.frozen) + state.frozen = new InternalWeakMap(); + return nativeDelete.call(this, key) || state.frozen['delete'](key); + } + return nativeDelete.call(this, key); + }, + has: function has(key) { + if (isObject(key) && !isExtensible(key)) { + var state = enforceIternalState(this); + if (!state.frozen) + state.frozen = new InternalWeakMap(); + return nativeHas.call(this, key) || state.frozen.has(key); + } + return nativeHas.call(this, key); + }, + get: function get(key) { + if (isObject(key) && !isExtensible(key)) { + var state = enforceIternalState(this); + if (!state.frozen) + state.frozen = new InternalWeakMap(); + return nativeHas.call(this, key) ? nativeGet.call(this, key) : state.frozen.get(key); + } + return nativeGet.call(this, key); + }, + set: function set(key, value) { + if (isObject(key) && !isExtensible(key)) { + var state = enforceIternalState(this); + if (!state.frozen) + state.frozen = new InternalWeakMap(); + nativeHas.call(this, key) ? nativeSet.call(this, key, value) : state.frozen.set(key, value); + } else + nativeSet.call(this, key, value); + return this; + } + }); +} /***/ }), -/* 118 */ +/* 134 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var pIE = __w_pdfjs_require__(78); - -var createDesc = __w_pdfjs_require__(24); - -var toIObject = __w_pdfjs_require__(47); - -var toPrimitive = __w_pdfjs_require__(23); - -var has = __w_pdfjs_require__(26); - -var IE8_DOM_DEFINE = __w_pdfjs_require__(19); - -var gOPD = Object.getOwnPropertyDescriptor; -exports.f = __w_pdfjs_require__(20) ? gOPD : function getOwnPropertyDescriptor(O, P) { - O = toIObject(O); - P = toPrimitive(P, true); - if (IE8_DOM_DEFINE) try { - return gOPD(O, P); - } catch (e) {} - if (has(O, P)) return createDesc(!pIE.f.call(O, P), O[P]); +var hiddenKeys = __w_pdfjs_require__(39); +var isObject = __w_pdfjs_require__(23); +var has = __w_pdfjs_require__(24); +var defineProperty = __w_pdfjs_require__(28).f; +var uid = __w_pdfjs_require__(38); +var FREEZING = __w_pdfjs_require__(135); +var METADATA = uid('meta'); +var id = 0; +var isExtensible = Object.isExtensible || function () { + return true; +}; +var setMetadata = function (it) { + defineProperty(it, METADATA, { + value: { + objectID: 'O' + ++id, + weakData: {} + } + }); +}; +var fastKey = function (it, create) { + if (!isObject(it)) + return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it; + if (!has(it, METADATA)) { + if (!isExtensible(it)) + return 'F'; + if (!create) + return 'E'; + setMetadata(it); + } + return it[METADATA].objectID; +}; +var getWeakData = function (it, create) { + if (!has(it, METADATA)) { + if (!isExtensible(it)) + return true; + if (!create) + return false; + setMetadata(it); + } + return it[METADATA].weakData; }; +var onFreeze = function (it) { + if (FREEZING && meta.REQUIRED && isExtensible(it) && !has(it, METADATA)) + setMetadata(it); + return it; +}; +var meta = module.exports = { + REQUIRED: false, + fastKey: fastKey, + getWeakData: getWeakData, + onFreeze: onFreeze +}; +hiddenKeys[METADATA] = true; /***/ }), -/* 119 */ +/* 135 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(120)('WeakMap'); +var fails = __w_pdfjs_require__(15); +module.exports = !fails(function () { + return Object.isExtensible(Object.preventExtensions({})); +}); /***/ }), -/* 120 */ +/* 136 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var $export = __w_pdfjs_require__(12); - -module.exports = function (COLLECTION) { - $export($export.S, COLLECTION, { - of: function of() { - var length = arguments.length; - var A = new Array(length); - - while (length--) { - A[length] = arguments[length]; - } - - return new this(A); - } +var $ = __w_pdfjs_require__(11); +var global = __w_pdfjs_require__(12); +var isForced = __w_pdfjs_require__(52); +var redefine = __w_pdfjs_require__(30); +var InternalMetadataModule = __w_pdfjs_require__(134); +var iterate = __w_pdfjs_require__(114); +var anInstance = __w_pdfjs_require__(113); +var isObject = __w_pdfjs_require__(23); +var fails = __w_pdfjs_require__(15); +var checkCorrectnessOfIteration = __w_pdfjs_require__(92); +var setToStringTag = __w_pdfjs_require__(81); +var inheritIfRequired = __w_pdfjs_require__(137); +module.exports = function (CONSTRUCTOR_NAME, wrapper, common, IS_MAP, IS_WEAK) { + var NativeConstructor = global[CONSTRUCTOR_NAME]; + var NativePrototype = NativeConstructor && NativeConstructor.prototype; + var Constructor = NativeConstructor; + var ADDER = IS_MAP ? 'set' : 'add'; + var exported = {}; + var fixMethod = function (KEY) { + var nativeMethod = NativePrototype[KEY]; + redefine(NativePrototype, KEY, KEY == 'add' ? function add(value) { + nativeMethod.call(this, value === 0 ? 0 : value); + return this; + } : KEY == 'delete' ? function (key) { + return IS_WEAK && !isObject(key) ? false : nativeMethod.call(this, key === 0 ? 0 : key); + } : KEY == 'get' ? function get(key) { + return IS_WEAK && !isObject(key) ? undefined : nativeMethod.call(this, key === 0 ? 0 : key); + } : KEY == 'has' ? function has(key) { + return IS_WEAK && !isObject(key) ? false : nativeMethod.call(this, key === 0 ? 0 : key); + } : function set(key, value) { + nativeMethod.call(this, key === 0 ? 0 : key, value); + return this; + }); + }; + if (isForced(CONSTRUCTOR_NAME, typeof NativeConstructor != 'function' || !(IS_WEAK || NativePrototype.forEach && !fails(function () { + new NativeConstructor().entries().next(); + })))) { + Constructor = common.getConstructor(wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER); + InternalMetadataModule.REQUIRED = true; + } else if (isForced(CONSTRUCTOR_NAME, true)) { + var instance = new Constructor(); + var HASNT_CHAINING = instance[ADDER](IS_WEAK ? {} : -0, 1) != instance; + var THROWS_ON_PRIMITIVES = fails(function () { + instance.has(1); }); + var ACCEPT_ITERABLES = checkCorrectnessOfIteration(function (iterable) { + new NativeConstructor(iterable); + }); + var BUGGY_ZERO = !IS_WEAK && fails(function () { + var $instance = new NativeConstructor(); + var index = 5; + while (index--) + $instance[ADDER](index, index); + return !$instance.has(-0); + }); + if (!ACCEPT_ITERABLES) { + Constructor = wrapper(function (dummy, iterable) { + anInstance(dummy, Constructor, CONSTRUCTOR_NAME); + var that = inheritIfRequired(new NativeConstructor(), dummy, Constructor); + if (iterable != undefined) + iterate(iterable, that[ADDER], that, IS_MAP); + return that; + }); + Constructor.prototype = NativePrototype; + NativePrototype.constructor = Constructor; + } + if (THROWS_ON_PRIMITIVES || BUGGY_ZERO) { + fixMethod('delete'); + fixMethod('has'); + IS_MAP && fixMethod('get'); + } + if (BUGGY_ZERO || HASNT_CHAINING) + fixMethod(ADDER); + if (IS_WEAK && NativePrototype.clear) + delete NativePrototype.clear; + } + exported[CONSTRUCTOR_NAME] = Constructor; + $({ + global: true, + forced: Constructor != NativeConstructor + }, exported); + setToStringTag(Constructor, CONSTRUCTOR_NAME); + if (!IS_WEAK) + common.setStrong(Constructor, CONSTRUCTOR_NAME, IS_MAP); + return Constructor; }; /***/ }), -/* 121 */ +/* 137 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(122)('WeakMap'); +var isObject = __w_pdfjs_require__(23); +var setPrototypeOf = __w_pdfjs_require__(83); +module.exports = function ($this, dummy, Wrapper) { + var NewTarget, NewTargetPrototype; + if (setPrototypeOf && typeof (NewTarget = dummy.constructor) == 'function' && NewTarget !== Wrapper && isObject(NewTargetPrototype = NewTarget.prototype) && NewTargetPrototype !== Wrapper.prototype) + setPrototypeOf($this, NewTargetPrototype); + return $this; +}; /***/ }), -/* 122 */ +/* 138 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var $export = __w_pdfjs_require__(12); - -var aFunction = __w_pdfjs_require__(29); - -var ctx = __w_pdfjs_require__(28); - -var forOf = __w_pdfjs_require__(93); - -module.exports = function (COLLECTION) { - $export($export.S, COLLECTION, { - from: function from(source) { - var mapFn = arguments[1]; - var mapping, A, n, cb; - aFunction(this); - mapping = mapFn !== undefined; - if (mapping) aFunction(mapFn); - if (source == undefined) return new this(); - A = []; - - if (mapping) { - n = 0; - cb = ctx(mapFn, arguments[2], 2); - forOf(source, false, function (nextItem) { - A.push(cb(nextItem, n++)); - }); - } else { - forOf(source, false, A.push, A); - } - - return new this(A); - } +var redefineAll = __w_pdfjs_require__(111); +var getWeakData = __w_pdfjs_require__(134).getWeakData; +var anObject = __w_pdfjs_require__(29); +var isObject = __w_pdfjs_require__(23); +var anInstance = __w_pdfjs_require__(113); +var iterate = __w_pdfjs_require__(114); +var ArrayIterationModule = __w_pdfjs_require__(139); +var $has = __w_pdfjs_require__(24); +var InternalStateModule = __w_pdfjs_require__(35); +var setInternalState = InternalStateModule.set; +var internalStateGetterFor = InternalStateModule.getterFor; +var find = ArrayIterationModule.find; +var findIndex = ArrayIterationModule.findIndex; +var id = 0; +var uncaughtFrozenStore = function (store) { + return store.frozen || (store.frozen = new UncaughtFrozenStore()); +}; +var UncaughtFrozenStore = function () { + this.entries = []; +}; +var findUncaughtFrozen = function (store, key) { + return find(store.entries, function (it) { + return it[0] === key; + }); +}; +UncaughtFrozenStore.prototype = { + get: function (key) { + var entry = findUncaughtFrozen(this, key); + if (entry) + return entry[1]; + }, + has: function (key) { + return !!findUncaughtFrozen(this, key); + }, + set: function (key, value) { + var entry = findUncaughtFrozen(this, key); + if (entry) + entry[1] = value; + else + this.entries.push([ + key, + value + ]); + }, + 'delete': function (key) { + var index = findIndex(this.entries, function (it) { + return it[0] === key; }); + if (~index) + this.entries.splice(index, 1); + return !!~index; + } +}; +module.exports = { + getConstructor: function (wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER) { + var C = wrapper(function (that, iterable) { + anInstance(that, C, CONSTRUCTOR_NAME); + setInternalState(that, { + type: CONSTRUCTOR_NAME, + id: id++, + frozen: undefined + }); + if (iterable != undefined) + iterate(iterable, that[ADDER], that, IS_MAP); + }); + var getInternalState = internalStateGetterFor(CONSTRUCTOR_NAME); + var define = function (that, key, value) { + var state = getInternalState(that); + var data = getWeakData(anObject(key), true); + if (data === true) + uncaughtFrozenStore(state).set(key, value); + else + data[state.id] = value; + return that; + }; + redefineAll(C.prototype, { + 'delete': function (key) { + var state = getInternalState(this); + if (!isObject(key)) + return false; + var data = getWeakData(key); + if (data === true) + return uncaughtFrozenStore(state)['delete'](key); + return data && $has(data, state.id) && delete data[state.id]; + }, + has: function has(key) { + var state = getInternalState(this); + if (!isObject(key)) + return false; + var data = getWeakData(key); + if (data === true) + return uncaughtFrozenStore(state).has(key); + return data && $has(data, state.id); + } + }); + redefineAll(C.prototype, IS_MAP ? { + get: function get(key) { + var state = getInternalState(this); + if (isObject(key)) { + var data = getWeakData(key); + if (data === true) + return uncaughtFrozenStore(state).get(key); + return data ? data[state.id] : undefined; + } + }, + set: function set(key, value) { + return define(this, key, value); + } + } : { + add: function add(value) { + return define(this, value, true); + } + }); + return C; + } }; /***/ }), -/* 123 */ +/* 139 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(87); - -__w_pdfjs_require__(88); - -__w_pdfjs_require__(124); - -__w_pdfjs_require__(125); - -__w_pdfjs_require__(126); - -module.exports = __w_pdfjs_require__(14).WeakSet; +var bind = __w_pdfjs_require__(59); +var IndexedObject = __w_pdfjs_require__(19); +var toObject = __w_pdfjs_require__(79); +var toLength = __w_pdfjs_require__(47); +var arraySpeciesCreate = __w_pdfjs_require__(140); +var push = [].push; +var createMethod = function (TYPE) { + var IS_MAP = TYPE == 1; + var IS_FILTER = TYPE == 2; + var IS_SOME = TYPE == 3; + var IS_EVERY = TYPE == 4; + var IS_FIND_INDEX = TYPE == 6; + var NO_HOLES = TYPE == 5 || IS_FIND_INDEX; + return function ($this, callbackfn, that, specificCreate) { + var O = toObject($this); + var self = IndexedObject(O); + var boundFunction = bind(callbackfn, that, 3); + var length = toLength(self.length); + var index = 0; + var create = specificCreate || arraySpeciesCreate; + var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined; + var value, result; + for (; length > index; index++) + if (NO_HOLES || index in self) { + value = self[index]; + result = boundFunction(value, index, O); + if (TYPE) { + if (IS_MAP) + target[index] = result; + else if (result) + switch (TYPE) { + case 3: + return true; + case 5: + return value; + case 6: + return index; + case 2: + push.call(target, value); + } + else if (IS_EVERY) + return false; + } + } + return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target; + }; +}; +module.exports = { + forEach: createMethod(0), + map: createMethod(1), + filter: createMethod(2), + some: createMethod(3), + every: createMethod(4), + find: createMethod(5), + findIndex: createMethod(6) +}; /***/ }), -/* 124 */ +/* 140 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var weak = __w_pdfjs_require__(113); - -var validate = __w_pdfjs_require__(114); - -var WEAK_SET = 'WeakSet'; - -__w_pdfjs_require__(115)(WEAK_SET, function (get) { - return function WeakSet() { - return get(this, arguments.length > 0 ? arguments[0] : undefined); - }; -}, { - add: function add(value) { - return weak.def(validate(this, WEAK_SET), value, true); +var isObject = __w_pdfjs_require__(23); +var isArray = __w_pdfjs_require__(141); +var wellKnownSymbol = __w_pdfjs_require__(55); +var SPECIES = wellKnownSymbol('species'); +module.exports = function (originalArray, length) { + var C; + if (isArray(originalArray)) { + C = originalArray.constructor; + if (typeof C == 'function' && (C === Array || isArray(C.prototype))) + C = undefined; + else if (isObject(C)) { + C = C[SPECIES]; + if (C === null) + C = undefined; } -}, weak, false, true); + } + return new (C === undefined ? Array : C)(length === 0 ? 0 : length); +}; /***/ }), -/* 125 */ +/* 141 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(120)('WeakSet'); +var classof = __w_pdfjs_require__(20); +module.exports = Array.isArray || function isArray(arg) { + return classof(arg) == 'Array'; +}; /***/ }), -/* 126 */ +/* 142 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(122)('WeakSet'); +__w_pdfjs_require__(104); +__w_pdfjs_require__(143); +__w_pdfjs_require__(106); +var path = __w_pdfjs_require__(43); +module.exports = path.WeakSet; /***/ }), -/* 127 */ +/* 143 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; +var collection = __w_pdfjs_require__(136); +var collectionWeak = __w_pdfjs_require__(138); +collection('WeakSet', function (get) { + return function WeakSet() { + return get(this, arguments.length ? arguments[0] : undefined); + }; +}, collectionWeak, false, true); -__w_pdfjs_require__(128); +/***/ }), +/* 144 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -module.exports = __w_pdfjs_require__(14).String.codePointAt; +__w_pdfjs_require__(145); +var entryUnbind = __w_pdfjs_require__(58); +module.exports = entryUnbind('String', 'codePointAt'); /***/ }), -/* 128 */ +/* 145 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var $export = __w_pdfjs_require__(12); - -var $at = __w_pdfjs_require__(53)(false); - -$export($export.P, 'String', { - codePointAt: function codePointAt(pos) { - return $at(this, pos); - } +var $ = __w_pdfjs_require__(11); +var codeAt = __w_pdfjs_require__(74).codeAt; +$({ + target: 'String', + proto: true +}, { + codePointAt: function codePointAt(pos) { + return codeAt(this, pos); + } }); /***/ }), -/* 129 */ +/* 146 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(130); - -module.exports = __w_pdfjs_require__(14).String.fromCodePoint; +__w_pdfjs_require__(147); +var path = __w_pdfjs_require__(43); +module.exports = path.String.fromCodePoint; /***/ }), -/* 130 */ +/* 147 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var $export = __w_pdfjs_require__(12); - +var $ = __w_pdfjs_require__(11); var toAbsoluteIndex = __w_pdfjs_require__(49); - var fromCharCode = String.fromCharCode; -var $fromCodePoint = String.fromCodePoint; -$export($export.S + $export.F * (!!$fromCodePoint && $fromCodePoint.length != 1), 'String', { - fromCodePoint: function fromCodePoint(x) { - var res = []; - var aLen = arguments.length; - var i = 0; - var code; - - while (aLen > i) { - code = +arguments[i++]; - if (toAbsoluteIndex(code, 0x10ffff) !== code) throw RangeError(code + ' is not a valid code point'); - res.push(code < 0x10000 ? fromCharCode(code) : fromCharCode(((code -= 0x10000) >> 10) + 0xd800, code % 0x400 + 0xdc00)); - } - - return res.join(''); +var nativeFromCodePoint = String.fromCodePoint; +var INCORRECT_LENGTH = !!nativeFromCodePoint && nativeFromCodePoint.length != 1; +$({ + target: 'String', + stat: true, + forced: INCORRECT_LENGTH +}, { + fromCodePoint: function fromCodePoint(x) { + var elements = []; + var length = arguments.length; + var i = 0; + var code; + while (length > i) { + code = +arguments[i++]; + if (toAbsoluteIndex(code, 0x10FFFF) !== code) + throw RangeError(code + ' is not a valid code point'); + elements.push(code < 0x10000 ? fromCharCode(code) : fromCharCode(((code -= 0x10000) >> 10) + 0xD800, code % 0x400 + 0xDC00)); } + return elements.join(''); + } }); /***/ }), -/* 131 */ +/* 148 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(132); - -__w_pdfjs_require__(87); - -module.exports = __w_pdfjs_require__(14).Symbol; +__w_pdfjs_require__(149); +__w_pdfjs_require__(104); +__w_pdfjs_require__(151); +__w_pdfjs_require__(155); +__w_pdfjs_require__(156); +__w_pdfjs_require__(157); +__w_pdfjs_require__(158); +__w_pdfjs_require__(159); +__w_pdfjs_require__(160); +__w_pdfjs_require__(161); +__w_pdfjs_require__(162); +__w_pdfjs_require__(163); +__w_pdfjs_require__(164); +__w_pdfjs_require__(165); +__w_pdfjs_require__(166); +__w_pdfjs_require__(167); +__w_pdfjs_require__(168); +__w_pdfjs_require__(169); +__w_pdfjs_require__(170); +var path = __w_pdfjs_require__(43); +module.exports = path.Symbol; /***/ }), -/* 132 */ +/* 149 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; +var $ = __w_pdfjs_require__(11); +var fails = __w_pdfjs_require__(15); +var isArray = __w_pdfjs_require__(141); +var isObject = __w_pdfjs_require__(23); +var toObject = __w_pdfjs_require__(79); +var toLength = __w_pdfjs_require__(47); +var createProperty = __w_pdfjs_require__(89); +var arraySpeciesCreate = __w_pdfjs_require__(140); +var arrayMethodHasSpeciesSupport = __w_pdfjs_require__(150); +var wellKnownSymbol = __w_pdfjs_require__(55); +var IS_CONCAT_SPREADABLE = wellKnownSymbol('isConcatSpreadable'); +var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; +var MAXIMUM_ALLOWED_INDEX_EXCEEDED = 'Maximum allowed index exceeded'; +var IS_CONCAT_SPREADABLE_SUPPORT = !fails(function () { + var array = []; + array[IS_CONCAT_SPREADABLE] = false; + return array.concat()[0] !== array; +}); +var SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('concat'); +var isConcatSpreadable = function (O) { + if (!isObject(O)) + return false; + var spreadable = O[IS_CONCAT_SPREADABLE]; + return spreadable !== undefined ? !!spreadable : isArray(O); +}; +var FORCED = !IS_CONCAT_SPREADABLE_SUPPORT || !SPECIES_SUPPORT; +$({ + target: 'Array', + proto: true, + forced: FORCED +}, { + concat: function concat(arg) { + var O = toObject(this); + var A = arraySpeciesCreate(O, 0); + var n = 0; + var i, k, length, len, E; + for (i = -1, length = arguments.length; i < length; i++) { + E = i === -1 ? O : arguments[i]; + if (isConcatSpreadable(E)) { + len = toLength(E.length); + if (n + len > MAX_SAFE_INTEGER) + throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED); + for (k = 0; k < len; k++, n++) + if (k in E) + createProperty(A, n, E[k]); + } else { + if (n >= MAX_SAFE_INTEGER) + throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED); + createProperty(A, n++, E); + } + } + A.length = n; + return A; + } +}); -function _typeof(obj) { 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 global = __w_pdfjs_require__(13); - -var has = __w_pdfjs_require__(26); - -var DESCRIPTORS = __w_pdfjs_require__(20); - -var $export = __w_pdfjs_require__(12); - -var redefine = __w_pdfjs_require__(25); - -var META = __w_pdfjs_require__(112).KEY; - -var $fails = __w_pdfjs_require__(21); - -var shared = __w_pdfjs_require__(36); - -var setToStringTag = __w_pdfjs_require__(64); - -var uid = __w_pdfjs_require__(27); - -var wks = __w_pdfjs_require__(35); - -var wksExt = __w_pdfjs_require__(133); - -var wksDefine = __w_pdfjs_require__(134); - -var enumKeys = __w_pdfjs_require__(135); - -var isArray = __w_pdfjs_require__(111); - -var anObject = __w_pdfjs_require__(17); - -var isObject = __w_pdfjs_require__(18); - -var toIObject = __w_pdfjs_require__(47); - -var toPrimitive = __w_pdfjs_require__(23); - -var createDesc = __w_pdfjs_require__(24); - -var _create = __w_pdfjs_require__(57); - -var gOPNExt = __w_pdfjs_require__(136); - -var $GOPD = __w_pdfjs_require__(118); - -var $DP = __w_pdfjs_require__(16); +/***/ }), +/* 150 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var $keys = __w_pdfjs_require__(59); +var fails = __w_pdfjs_require__(15); +var wellKnownSymbol = __w_pdfjs_require__(55); +var SPECIES = wellKnownSymbol('species'); +module.exports = function (METHOD_NAME) { + return !fails(function () { + var array = []; + var constructor = array.constructor = {}; + constructor[SPECIES] = function () { + return { foo: 1 }; + }; + return array[METHOD_NAME](Boolean).foo !== 1; + }); +}; -var gOPD = $GOPD.f; -var dP = $DP.f; -var gOPN = gOPNExt.f; -var $Symbol = global.Symbol; -var $JSON = global.JSON; +/***/ }), +/* 151 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var _stringify = $JSON && $JSON.stringify; +"use strict"; +var $ = __w_pdfjs_require__(11); +var global = __w_pdfjs_require__(12); +var IS_PURE = __w_pdfjs_require__(33); +var DESCRIPTORS = __w_pdfjs_require__(14); +var NATIVE_SYMBOL = __w_pdfjs_require__(56); +var fails = __w_pdfjs_require__(15); +var has = __w_pdfjs_require__(24); +var isArray = __w_pdfjs_require__(141); +var isObject = __w_pdfjs_require__(23); +var anObject = __w_pdfjs_require__(29); +var toObject = __w_pdfjs_require__(79); +var toIndexedObject = __w_pdfjs_require__(18); +var toPrimitive = __w_pdfjs_require__(22); +var createPropertyDescriptor = __w_pdfjs_require__(17); +var nativeObjectCreate = __w_pdfjs_require__(68); +var objectKeys = __w_pdfjs_require__(70); +var getOwnPropertyNamesModule = __w_pdfjs_require__(44); +var getOwnPropertyNamesExternal = __w_pdfjs_require__(152); +var getOwnPropertySymbolsModule = __w_pdfjs_require__(51); +var getOwnPropertyDescriptorModule = __w_pdfjs_require__(13); +var definePropertyModule = __w_pdfjs_require__(28); +var propertyIsEnumerableModule = __w_pdfjs_require__(16); +var hide = __w_pdfjs_require__(27); +var redefine = __w_pdfjs_require__(30); +var shared = __w_pdfjs_require__(31); +var sharedKey = __w_pdfjs_require__(37); +var hiddenKeys = __w_pdfjs_require__(39); +var uid = __w_pdfjs_require__(38); +var wellKnownSymbol = __w_pdfjs_require__(55); +var wrappedWellKnownSymbolModule = __w_pdfjs_require__(153); +var defineWellKnownSymbol = __w_pdfjs_require__(154); +var setToStringTag = __w_pdfjs_require__(81); +var InternalStateModule = __w_pdfjs_require__(35); +var $forEach = __w_pdfjs_require__(139).forEach; +var HIDDEN = sharedKey('hidden'); +var SYMBOL = 'Symbol'; var PROTOTYPE = 'prototype'; -var HIDDEN = wks('_hidden'); -var TO_PRIMITIVE = wks('toPrimitive'); -var isEnum = {}.propertyIsEnumerable; -var SymbolRegistry = shared('symbol-registry'); +var TO_PRIMITIVE = wellKnownSymbol('toPrimitive'); +var setInternalState = InternalStateModule.set; +var getInternalState = InternalStateModule.getterFor(SYMBOL); +var ObjectPrototype = Object[PROTOTYPE]; +var $Symbol = global.Symbol; +var JSON = global.JSON; +var nativeJSONStringify = JSON && JSON.stringify; +var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; +var nativeDefineProperty = definePropertyModule.f; +var nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f; +var nativePropertyIsEnumerable = propertyIsEnumerableModule.f; var AllSymbols = shared('symbols'); -var OPSymbols = shared('op-symbols'); -var ObjectProto = Object[PROTOTYPE]; -var USE_NATIVE = typeof $Symbol == 'function'; +var ObjectPrototypeSymbols = shared('op-symbols'); +var StringToSymbolRegistry = shared('string-to-symbol-registry'); +var SymbolToStringRegistry = shared('symbol-to-string-registry'); +var WellKnownSymbolsStore = shared('wks'); var QObject = global.QObject; -var setter = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild; -var setSymbolDesc = DESCRIPTORS && $fails(function () { - return _create(dP({}, 'a', { - get: function get() { - return dP(this, 'a', { - value: 7 - }).a; - } - })).a != 7; -}) ? function (it, key, D) { - var protoDesc = gOPD(ObjectProto, key); - if (protoDesc) delete ObjectProto[key]; - dP(it, key, D); - if (protoDesc && it !== ObjectProto) dP(ObjectProto, key, protoDesc); -} : dP; - -var wrap = function wrap(tag) { - var sym = AllSymbols[tag] = _create($Symbol[PROTOTYPE]); - - sym._k = tag; - return sym; +var USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild; +var setSymbolDescriptor = DESCRIPTORS && fails(function () { + return nativeObjectCreate(nativeDefineProperty({}, 'a', { + get: function () { + return nativeDefineProperty(this, 'a', { value: 7 }).a; + } + })).a != 7; +}) ? function (O, P, Attributes) { + var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(ObjectPrototype, P); + if (ObjectPrototypeDescriptor) + delete ObjectPrototype[P]; + nativeDefineProperty(O, P, Attributes); + if (ObjectPrototypeDescriptor && O !== ObjectPrototype) { + nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor); + } +} : nativeDefineProperty; +var wrap = function (tag, description) { + var symbol = AllSymbols[tag] = nativeObjectCreate($Symbol[PROTOTYPE]); + setInternalState(symbol, { + type: SYMBOL, + tag: tag, + description: description + }); + if (!DESCRIPTORS) + symbol.description = description; + return symbol; }; - -var isSymbol = USE_NATIVE && _typeof($Symbol.iterator) == 'symbol' ? function (it) { - return _typeof(it) == 'symbol'; +var isSymbol = NATIVE_SYMBOL && typeof $Symbol.iterator == 'symbol' ? function (it) { + return typeof it == 'symbol'; } : function (it) { - return it instanceof $Symbol; + return Object(it) instanceof $Symbol; }; - -var $defineProperty = function defineProperty(it, key, D) { - if (it === ObjectProto) $defineProperty(OPSymbols, key, D); - anObject(it); - key = toPrimitive(key, true); - anObject(D); - - if (has(AllSymbols, key)) { - if (!D.enumerable) { - if (!has(it, HIDDEN)) dP(it, HIDDEN, createDesc(1, {})); - it[HIDDEN][key] = true; - } else { - if (has(it, HIDDEN) && it[HIDDEN][key]) it[HIDDEN][key] = false; - D = _create(D, { - enumerable: createDesc(0, false) - }); - } - - return setSymbolDesc(it, key, D); +var $defineProperty = function defineProperty(O, P, Attributes) { + if (O === ObjectPrototype) + $defineProperty(ObjectPrototypeSymbols, P, Attributes); + anObject(O); + var key = toPrimitive(P, true); + anObject(Attributes); + if (has(AllSymbols, key)) { + if (!Attributes.enumerable) { + if (!has(O, HIDDEN)) + nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, {})); + O[HIDDEN][key] = true; + } else { + if (has(O, HIDDEN) && O[HIDDEN][key]) + O[HIDDEN][key] = false; + Attributes = nativeObjectCreate(Attributes, { enumerable: createPropertyDescriptor(0, false) }); } - - return dP(it, key, D); + return setSymbolDescriptor(O, key, Attributes); + } + return nativeDefineProperty(O, key, Attributes); }; - -var $defineProperties = function defineProperties(it, P) { - anObject(it); - var keys = enumKeys(P = toIObject(P)); - var i = 0; - var l = keys.length; - var key; - - while (l > i) { - $defineProperty(it, key = keys[i++], P[key]); - } - - return it; +var $defineProperties = function defineProperties(O, Properties) { + anObject(O); + var properties = toIndexedObject(Properties); + var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties)); + $forEach(keys, function (key) { + if (!DESCRIPTORS || $propertyIsEnumerable.call(properties, key)) + $defineProperty(O, key, properties[key]); + }); + return O; }; - -var $create = function create(it, P) { - return P === undefined ? _create(it) : $defineProperties(_create(it), P); +var $create = function create(O, Properties) { + return Properties === undefined ? nativeObjectCreate(O) : $defineProperties(nativeObjectCreate(O), Properties); }; - -var $propertyIsEnumerable = function propertyIsEnumerable(key) { - var E = isEnum.call(this, key = toPrimitive(key, true)); - if (this === ObjectProto && has(AllSymbols, key) && !has(OPSymbols, key)) return false; - return E || !has(this, key) || !has(AllSymbols, key) || has(this, HIDDEN) && this[HIDDEN][key] ? E : true; +var $propertyIsEnumerable = function propertyIsEnumerable(V) { + var P = toPrimitive(V, true); + var enumerable = nativePropertyIsEnumerable.call(this, P); + if (this === ObjectPrototype && has(AllSymbols, P) && !has(ObjectPrototypeSymbols, P)) + return false; + return enumerable || !has(this, P) || !has(AllSymbols, P) || has(this, HIDDEN) && this[HIDDEN][P] ? enumerable : true; }; - -var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(it, key) { - it = toIObject(it); - key = toPrimitive(key, true); - if (it === ObjectProto && has(AllSymbols, key) && !has(OPSymbols, key)) return; - var D = gOPD(it, key); - if (D && has(AllSymbols, key) && !(has(it, HIDDEN) && it[HIDDEN][key])) D.enumerable = true; - return D; +var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) { + var it = toIndexedObject(O); + var key = toPrimitive(P, true); + if (it === ObjectPrototype && has(AllSymbols, key) && !has(ObjectPrototypeSymbols, key)) + return; + var descriptor = nativeGetOwnPropertyDescriptor(it, key); + if (descriptor && has(AllSymbols, key) && !(has(it, HIDDEN) && it[HIDDEN][key])) { + descriptor.enumerable = true; + } + return descriptor; }; - -var $getOwnPropertyNames = function getOwnPropertyNames(it) { - var names = gOPN(toIObject(it)); - var result = []; - var i = 0; - var key; - - while (names.length > i) { - if (!has(AllSymbols, key = names[i++]) && key != HIDDEN && key != META) result.push(key); - } - - return result; +var $getOwnPropertyNames = function getOwnPropertyNames(O) { + var names = nativeGetOwnPropertyNames(toIndexedObject(O)); + var result = []; + $forEach(names, function (key) { + if (!has(AllSymbols, key) && !has(hiddenKeys, key)) + result.push(key); + }); + return result; }; - -var $getOwnPropertySymbols = function getOwnPropertySymbols(it) { - var IS_OP = it === ObjectProto; - var names = gOPN(IS_OP ? OPSymbols : toIObject(it)); - var result = []; - var i = 0; - var key; - - while (names.length > i) { - if (has(AllSymbols, key = names[i++]) && (IS_OP ? has(ObjectProto, key) : true)) result.push(AllSymbols[key]); - } - - return result; +var $getOwnPropertySymbols = function getOwnPropertySymbols(O) { + var IS_OBJECT_PROTOTYPE = O === ObjectPrototype; + var names = nativeGetOwnPropertyNames(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O)); + var result = []; + $forEach(names, function (key) { + if (has(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || has(ObjectPrototype, key))) { + result.push(AllSymbols[key]); + } + }); + return result; }; - -if (!USE_NATIVE) { - $Symbol = function _Symbol() { - if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor!'); - var tag = uid(arguments.length > 0 ? arguments[0] : undefined); - - var $set = function $set(value) { - if (this === ObjectProto) $set.call(OPSymbols, value); - if (has(this, HIDDEN) && has(this[HIDDEN], tag)) this[HIDDEN][tag] = false; - setSymbolDesc(this, tag, createDesc(1, value)); - }; - - if (DESCRIPTORS && setter) setSymbolDesc(ObjectProto, tag, { - configurable: true, - set: $set - }); - return wrap(tag); +if (!NATIVE_SYMBOL) { + $Symbol = function Symbol() { + if (this instanceof $Symbol) + throw TypeError('Symbol is not a constructor'); + var description = !arguments.length || arguments[0] === undefined ? undefined : String(arguments[0]); + var tag = uid(description); + var setter = function (value) { + if (this === ObjectPrototype) + setter.call(ObjectPrototypeSymbols, value); + if (has(this, HIDDEN) && has(this[HIDDEN], tag)) + this[HIDDEN][tag] = false; + setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value)); }; - - redefine($Symbol[PROTOTYPE], 'toString', function toString() { - return this._k; + if (DESCRIPTORS && USE_SETTER) + setSymbolDescriptor(ObjectPrototype, tag, { + configurable: true, + set: setter + }); + return wrap(tag, description); + }; + redefine($Symbol[PROTOTYPE], 'toString', function toString() { + return getInternalState(this).tag; + }); + propertyIsEnumerableModule.f = $propertyIsEnumerable; + definePropertyModule.f = $defineProperty; + getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor; + getOwnPropertyNamesModule.f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames; + getOwnPropertySymbolsModule.f = $getOwnPropertySymbols; + if (DESCRIPTORS) { + nativeDefineProperty($Symbol[PROTOTYPE], 'description', { + configurable: true, + get: function description() { + return getInternalState(this).description; + } }); - $GOPD.f = $getOwnPropertyDescriptor; - $DP.f = $defineProperty; - __w_pdfjs_require__(137).f = gOPNExt.f = $getOwnPropertyNames; - __w_pdfjs_require__(78).f = $propertyIsEnumerable; - __w_pdfjs_require__(77).f = $getOwnPropertySymbols; - - if (DESCRIPTORS && !__w_pdfjs_require__(37)) { - redefine(ObjectProto, 'propertyIsEnumerable', $propertyIsEnumerable, true); + if (!IS_PURE) { + redefine(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { unsafe: true }); } - - wksExt.f = function (name) { - return wrap(wks(name)); - }; + } + wrappedWellKnownSymbolModule.f = function (name) { + return wrap(wellKnownSymbol(name), name); + }; } - -$export($export.G + $export.W + $export.F * !USE_NATIVE, { - Symbol: $Symbol +$({ + global: true, + wrap: true, + forced: !NATIVE_SYMBOL, + sham: !NATIVE_SYMBOL +}, { Symbol: $Symbol }); +$forEach(objectKeys(WellKnownSymbolsStore), function (name) { + defineWellKnownSymbol(name); }); - -for (var es6Symbols = 'hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables'.split(','), j = 0; es6Symbols.length > j;) { - wks(es6Symbols[j++]); -} - -for (var wellKnownSymbols = $keys(wks.store), k = 0; wellKnownSymbols.length > k;) { - wksDefine(wellKnownSymbols[k++]); -} - -$export($export.S + $export.F * !USE_NATIVE, 'Symbol', { - 'for': function _for(key) { - return has(SymbolRegistry, key += '') ? SymbolRegistry[key] : SymbolRegistry[key] = $Symbol(key); - }, - keyFor: function keyFor(sym) { - if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol!'); - - for (var key in SymbolRegistry) { - if (SymbolRegistry[key] === sym) return key; - } - }, - useSetter: function useSetter() { - setter = true; - }, - useSimple: function useSimple() { - setter = false; - } +$({ + target: SYMBOL, + stat: true, + forced: !NATIVE_SYMBOL +}, { + 'for': function (key) { + var string = String(key); + if (has(StringToSymbolRegistry, string)) + return StringToSymbolRegistry[string]; + var symbol = $Symbol(string); + StringToSymbolRegistry[string] = symbol; + SymbolToStringRegistry[symbol] = string; + return symbol; + }, + keyFor: function keyFor(sym) { + if (!isSymbol(sym)) + throw TypeError(sym + ' is not a symbol'); + if (has(SymbolToStringRegistry, sym)) + return SymbolToStringRegistry[sym]; + }, + useSetter: function () { + USE_SETTER = true; + }, + useSimple: function () { + USE_SETTER = false; + } }); -$export($export.S + $export.F * !USE_NATIVE, 'Object', { - create: $create, - defineProperty: $defineProperty, - defineProperties: $defineProperties, - getOwnPropertyDescriptor: $getOwnPropertyDescriptor, - getOwnPropertyNames: $getOwnPropertyNames, - getOwnPropertySymbols: $getOwnPropertySymbols +$({ + target: 'Object', + stat: true, + forced: !NATIVE_SYMBOL, + sham: !DESCRIPTORS +}, { + create: $create, + defineProperty: $defineProperty, + defineProperties: $defineProperties, + getOwnPropertyDescriptor: $getOwnPropertyDescriptor }); -$JSON && $export($export.S + $export.F * (!USE_NATIVE || $fails(function () { - var S = $Symbol(); - return _stringify([S]) != '[null]' || _stringify({ - a: S - }) != '{}' || _stringify(Object(S)) != '{}'; -})), 'JSON', { - stringify: function stringify(it) { - var args = [it]; - var i = 1; - var replacer, $replacer; - - while (arguments.length > i) { - args.push(arguments[i++]); - } - - $replacer = replacer = args[1]; - if (!isObject(replacer) && it === undefined || isSymbol(it)) return; - if (!isArray(replacer)) replacer = function replacer(key, value) { - if (typeof $replacer == 'function') value = $replacer.call(this, key, value); - if (!isSymbol(value)) return value; - }; - args[1] = replacer; - return _stringify.apply($JSON, args); - } +$({ + target: 'Object', + stat: true, + forced: !NATIVE_SYMBOL +}, { + getOwnPropertyNames: $getOwnPropertyNames, + getOwnPropertySymbols: $getOwnPropertySymbols }); -$Symbol[PROTOTYPE][TO_PRIMITIVE] || __w_pdfjs_require__(15)($Symbol[PROTOTYPE], TO_PRIMITIVE, $Symbol[PROTOTYPE].valueOf); -setToStringTag($Symbol, 'Symbol'); -setToStringTag(Math, 'Math', true); -setToStringTag(global.JSON, 'JSON', true); +$({ + target: 'Object', + stat: true, + forced: fails(function () { + getOwnPropertySymbolsModule.f(1); + }) +}, { + getOwnPropertySymbols: function getOwnPropertySymbols(it) { + return getOwnPropertySymbolsModule.f(toObject(it)); + } +}); +JSON && $({ + target: 'JSON', + stat: true, + forced: !NATIVE_SYMBOL || fails(function () { + var symbol = $Symbol(); + return nativeJSONStringify([symbol]) != '[null]' || nativeJSONStringify({ a: symbol }) != '{}' || nativeJSONStringify(Object(symbol)) != '{}'; + }) +}, { + stringify: function stringify(it) { + var args = [it]; + var index = 1; + var replacer, $replacer; + while (arguments.length > index) + args.push(arguments[index++]); + $replacer = replacer = args[1]; + if (!isObject(replacer) && it === undefined || isSymbol(it)) + return; + if (!isArray(replacer)) + replacer = function (key, value) { + if (typeof $replacer == 'function') + value = $replacer.call(this, key, value); + if (!isSymbol(value)) + return value; + }; + args[1] = replacer; + return nativeJSONStringify.apply(JSON, args); + } +}); +if (!$Symbol[PROTOTYPE][TO_PRIMITIVE]) + hide($Symbol[PROTOTYPE], TO_PRIMITIVE, $Symbol[PROTOTYPE].valueOf); +setToStringTag($Symbol, SYMBOL); +hiddenKeys[HIDDEN] = true; /***/ }), -/* 133 */ +/* 152 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -exports.f = __w_pdfjs_require__(35); +var toIndexedObject = __w_pdfjs_require__(18); +var nativeGetOwnPropertyNames = __w_pdfjs_require__(44).f; +var toString = {}.toString; +var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames ? Object.getOwnPropertyNames(window) : []; +var getWindowNames = function (it) { + try { + return nativeGetOwnPropertyNames(it); + } catch (error) { + return windowNames.slice(); + } +}; +module.exports.f = function getOwnPropertyNames(it) { + return windowNames && toString.call(it) == '[object Window]' ? getWindowNames(it) : nativeGetOwnPropertyNames(toIndexedObject(it)); +}; /***/ }), -/* 134 */ +/* 153 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; +exports.f = __w_pdfjs_require__(55); +/***/ }), +/* 154 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var global = __w_pdfjs_require__(13); - -var core = __w_pdfjs_require__(14); - -var LIBRARY = __w_pdfjs_require__(37); - -var wksExt = __w_pdfjs_require__(133); +var path = __w_pdfjs_require__(43); +var has = __w_pdfjs_require__(24); +var wrappedWellKnownSymbolModule = __w_pdfjs_require__(153); +var defineProperty = __w_pdfjs_require__(28).f; +module.exports = function (NAME) { + var Symbol = path.Symbol || (path.Symbol = {}); + if (!has(Symbol, NAME)) + defineProperty(Symbol, NAME, { value: wrappedWellKnownSymbolModule.f(NAME) }); +}; -var defineProperty = __w_pdfjs_require__(16).f; +/***/ }), +/* 155 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -module.exports = function (name) { - var $Symbol = core.Symbol || (core.Symbol = LIBRARY ? {} : global.Symbol || {}); - if (name.charAt(0) != '_' && !(name in $Symbol)) defineProperty($Symbol, name, { - value: wksExt.f(name) - }); -}; +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('asyncIterator'); /***/ }), -/* 135 */ +/* 156 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; +var $ = __w_pdfjs_require__(11); +var DESCRIPTORS = __w_pdfjs_require__(14); +var global = __w_pdfjs_require__(12); +var has = __w_pdfjs_require__(24); +var isObject = __w_pdfjs_require__(23); +var defineProperty = __w_pdfjs_require__(28).f; +var copyConstructorProperties = __w_pdfjs_require__(40); +var NativeSymbol = global.Symbol; +if (DESCRIPTORS && typeof NativeSymbol == 'function' && (!('description' in NativeSymbol.prototype) || NativeSymbol().description !== undefined)) { + var EmptyStringDescriptionStore = {}; + var SymbolWrapper = function Symbol() { + var description = arguments.length < 1 || arguments[0] === undefined ? undefined : String(arguments[0]); + var result = this instanceof SymbolWrapper ? new NativeSymbol(description) : description === undefined ? NativeSymbol() : NativeSymbol(description); + if (description === '') + EmptyStringDescriptionStore[result] = true; + return result; + }; + copyConstructorProperties(SymbolWrapper, NativeSymbol); + var symbolPrototype = SymbolWrapper.prototype = NativeSymbol.prototype; + symbolPrototype.constructor = SymbolWrapper; + var symbolToString = symbolPrototype.toString; + var native = String(NativeSymbol('test')) == 'Symbol(test)'; + var regexp = /^Symbol\((.*)\)[^)]+$/; + defineProperty(symbolPrototype, 'description', { + configurable: true, + get: function description() { + var symbol = isObject(this) ? this.valueOf() : this; + var string = symbolToString.call(symbol); + if (has(EmptyStringDescriptionStore, symbol)) + return ''; + var desc = native ? string.slice(7, -1) : string.replace(regexp, '$1'); + return desc === '' ? undefined : desc; + } + }); + $({ + global: true, + forced: true + }, { Symbol: SymbolWrapper }); +} -var getKeys = __w_pdfjs_require__(59); - -var gOPS = __w_pdfjs_require__(77); +/***/ }), +/* 157 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var pIE = __w_pdfjs_require__(78); +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('hasInstance'); -module.exports = function (it) { - var result = getKeys(it); - var getSymbols = gOPS.f; +/***/ }), +/* 158 */ +/***/ (function(module, exports, __w_pdfjs_require__) { - if (getSymbols) { - var symbols = getSymbols(it); - var isEnum = pIE.f; - var i = 0; - var key; +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('isConcatSpreadable'); - while (symbols.length > i) { - if (isEnum.call(it, key = symbols[i++])) result.push(key); - } - } +/***/ }), +/* 159 */ +/***/ (function(module, exports, __w_pdfjs_require__) { - return result; -}; +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('iterator'); /***/ }), -/* 136 */ +/* 160 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('match'); +/***/ }), +/* 161 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -function _typeof(obj) { 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 defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('matchAll'); -var toIObject = __w_pdfjs_require__(47); +/***/ }), +/* 162 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var gOPN = __w_pdfjs_require__(137).f; +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('replace'); -var toString = {}.toString; -var windowNames = (typeof window === "undefined" ? "undefined" : _typeof(window)) == 'object' && window && Object.getOwnPropertyNames ? Object.getOwnPropertyNames(window) : []; +/***/ }), +/* 163 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var getWindowNames = function getWindowNames(it) { - try { - return gOPN(it); - } catch (e) { - return windowNames.slice(); - } -}; - -module.exports.f = function getOwnPropertyNames(it) { - return windowNames && toString.call(it) == '[object Window]' ? getWindowNames(it) : gOPN(toIObject(it)); -}; +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('search'); /***/ }), -/* 137 */ +/* 164 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('species'); +/***/ }), +/* 165 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var $keys = __w_pdfjs_require__(60); +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('split'); -var hiddenKeys = __w_pdfjs_require__(62).concat('length', 'prototype'); +/***/ }), +/* 166 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -exports.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { - return $keys(O, hiddenKeys); -}; +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('toPrimitive'); /***/ }), -/* 138 */ +/* 167 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('toStringTag'); -__w_pdfjs_require__(139); +/***/ }), +/* 168 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -module.exports = __w_pdfjs_require__(14).String.padStart; +var defineWellKnownSymbol = __w_pdfjs_require__(154); +defineWellKnownSymbol('unscopables'); /***/ }), -/* 139 */ +/* 169 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - +var setToStringTag = __w_pdfjs_require__(81); +setToStringTag(Math, 'Math', true); -var $export = __w_pdfjs_require__(12); +/***/ }), +/* 170 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -var $pad = __w_pdfjs_require__(140); +var global = __w_pdfjs_require__(12); +var setToStringTag = __w_pdfjs_require__(81); +setToStringTag(global.JSON, 'JSON', true); -var userAgent = __w_pdfjs_require__(100); +/***/ }), +/* 171 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -$export($export.P + $export.F * /Version\/10\.\d+(\.\d+)? Safari\//.test(userAgent), 'String', { - padStart: function padStart(maxLength) { - return $pad(this, maxLength, arguments.length > 1 ? arguments[1] : undefined, true); - } -}); +__w_pdfjs_require__(172); +var entryUnbind = __w_pdfjs_require__(58); +module.exports = entryUnbind('String', 'padStart'); /***/ }), -/* 140 */ +/* 172 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; +var $ = __w_pdfjs_require__(11); +var $padStart = __w_pdfjs_require__(173).start; +var WEBKIT_BUG = __w_pdfjs_require__(175); +$({ + target: 'String', + proto: true, + forced: WEBKIT_BUG +}, { + padStart: function padStart(maxLength) { + return $padStart(this, maxLength, arguments.length > 1 ? arguments[1] : undefined); + } +}); -var toLength = __w_pdfjs_require__(30); - -var repeat = __w_pdfjs_require__(141); - -var defined = __w_pdfjs_require__(38); +/***/ }), +/* 173 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -module.exports = function (that, maxLength, fillString, left) { - var S = String(defined(that)); +var toLength = __w_pdfjs_require__(47); +var repeat = __w_pdfjs_require__(174); +var requireObjectCoercible = __w_pdfjs_require__(21); +var ceil = Math.ceil; +var createMethod = function (IS_END) { + return function ($this, maxLength, fillString) { + var S = String(requireObjectCoercible($this)); var stringLength = S.length; var fillStr = fillString === undefined ? ' ' : String(fillString); var intMaxLength = toLength(maxLength); - if (intMaxLength <= stringLength || fillStr == '') return S; - var fillLen = intMaxLength - stringLength; - var stringFiller = repeat.call(fillStr, Math.ceil(fillLen / fillStr.length)); - if (stringFiller.length > fillLen) stringFiller = stringFiller.slice(0, fillLen); - return left ? stringFiller + S : S + stringFiller; + var fillLen, stringFiller; + if (intMaxLength <= stringLength || fillStr == '') + return S; + fillLen = intMaxLength - stringLength; + stringFiller = repeat.call(fillStr, ceil(fillLen / fillStr.length)); + if (stringFiller.length > fillLen) + stringFiller = stringFiller.slice(0, fillLen); + return IS_END ? S + stringFiller : stringFiller + S; + }; +}; +module.exports = { + start: createMethod(false), + end: createMethod(true) }; /***/ }), -/* 141 */ +/* 174 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var toInteger = __w_pdfjs_require__(31); - -var defined = __w_pdfjs_require__(38); - -module.exports = function repeat(count) { - var str = String(defined(this)); - var res = ''; - var n = toInteger(count); - if (n < 0 || n == Infinity) throw RangeError("Count can't be negative"); - - for (; n > 0; (n >>>= 1) && (str += str)) { - if (n & 1) res += str; - } - - return res; +var toInteger = __w_pdfjs_require__(48); +var requireObjectCoercible = __w_pdfjs_require__(21); +module.exports = ''.repeat || function repeat(count) { + var str = String(requireObjectCoercible(this)); + var result = ''; + var n = toInteger(count); + if (n < 0 || n == Infinity) + throw RangeError('Wrong number of repetitions'); + for (; n > 0; (n >>>= 1) && (str += str)) + if (n & 1) + result += str; + return result; }; /***/ }), -/* 142 */ +/* 175 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; +var userAgent = __w_pdfjs_require__(118); +module.exports = /Version\/10\.\d+(\.\d+)?( Mobile\/\w+)? Safari\//.test(userAgent); +/***/ }), +/* 176 */ +/***/ (function(module, exports, __w_pdfjs_require__) { -__w_pdfjs_require__(143); - -module.exports = __w_pdfjs_require__(14).String.padEnd; +__w_pdfjs_require__(177); +var entryUnbind = __w_pdfjs_require__(58); +module.exports = entryUnbind('String', 'padEnd'); /***/ }), -/* 143 */ +/* 177 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; - -var $export = __w_pdfjs_require__(12); - -var $pad = __w_pdfjs_require__(140); - -var userAgent = __w_pdfjs_require__(100); - -$export($export.P + $export.F * /Version\/10\.\d+(\.\d+)? Safari\//.test(userAgent), 'String', { - padEnd: function padEnd(maxLength) { - return $pad(this, maxLength, arguments.length > 1 ? arguments[1] : undefined, false); - } +var $ = __w_pdfjs_require__(11); +var $padEnd = __w_pdfjs_require__(173).end; +var WEBKIT_BUG = __w_pdfjs_require__(175); +$({ + target: 'String', + proto: true, + forced: WEBKIT_BUG +}, { + padEnd: function padEnd(maxLength) { + return $padEnd(this, maxLength, arguments.length > 1 ? arguments[1] : undefined); + } }); /***/ }), -/* 144 */ +/* 178 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -__w_pdfjs_require__(145); - -module.exports = __w_pdfjs_require__(14).Object.values; +__w_pdfjs_require__(179); +var path = __w_pdfjs_require__(43); +module.exports = path.Object.values; /***/ }), -/* 145 */ +/* 179 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var $export = __w_pdfjs_require__(12); - -var $values = __w_pdfjs_require__(146)(false); - -$export($export.S, 'Object', { - values: function values(it) { - return $values(it); - } +var $ = __w_pdfjs_require__(11); +var $values = __w_pdfjs_require__(180).values; +$({ + target: 'Object', + stat: true +}, { + values: function values(O) { + return $values(O); + } }); /***/ }), -/* 146 */ +/* 180 */ /***/ (function(module, exports, __w_pdfjs_require__) { -"use strict"; - - -var getKeys = __w_pdfjs_require__(59); - -var toIObject = __w_pdfjs_require__(47); - -var isEnum = __w_pdfjs_require__(78).f; - -module.exports = function (isEntries) { - return function (it) { - var O = toIObject(it); - var keys = getKeys(O); - var length = keys.length; - var i = 0; - var result = []; - var key; - - while (length > i) { - if (isEnum.call(O, key = keys[i++])) { - result.push(isEntries ? [key, O[key]] : O[key]); - } - } - - return result; - }; +var DESCRIPTORS = __w_pdfjs_require__(14); +var objectKeys = __w_pdfjs_require__(70); +var toIndexedObject = __w_pdfjs_require__(18); +var propertyIsEnumerable = __w_pdfjs_require__(16).f; +var createMethod = function (TO_ENTRIES) { + return function (it) { + var O = toIndexedObject(it); + var keys = objectKeys(O); + var length = keys.length; + var i = 0; + var result = []; + var key; + while (length > i) { + key = keys[i++]; + if (!DESCRIPTORS || propertyIsEnumerable.call(O, key)) { + result.push(TO_ENTRIES ? [ + key, + O[key] + ] : O[key]); + } + } + return result; + }; +}; +module.exports = { + entries: createMethod(true), + values: createMethod(false) }; /***/ }), -/* 147 */ +/* 181 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -6699,4472 +8054,3200 @@ module.exports = function (isEntries) { if (isReadableStreamSupported) { exports.ReadableStream = ReadableStream; } else { - exports.ReadableStream = __w_pdfjs_require__(148).ReadableStream; + exports.ReadableStream = __w_pdfjs_require__(182).ReadableStream; } } /***/ }), -/* 148 */ -/***/ (function(module, exports, __w_pdfjs_require__) { +/* 182 */ +/***/ (function(__webpack_module__, __webpack_exports__, __w_pdfjs_require__) { "use strict"; - - -function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); } - -(function (e, a) { - for (var i in a) { - e[i] = a[i]; - } -})(exports, function (modules) { - var installedModules = {}; - - function __w_pdfjs_require__(moduleId) { - if (installedModules[moduleId]) return installedModules[moduleId].exports; - var module = installedModules[moduleId] = { - i: moduleId, - l: false, - exports: {} +__w_pdfjs_require__.r(__webpack_exports__); +/* harmony export (binding) */ __w_pdfjs_require__.d(__webpack_exports__, "ByteLengthQueuingStrategy", function() { return ByteLengthQueuingStrategy; }); +/* harmony export (binding) */ __w_pdfjs_require__.d(__webpack_exports__, "CountQueuingStrategy", function() { return CountQueuingStrategy; }); +/* harmony export (binding) */ __w_pdfjs_require__.d(__webpack_exports__, "ReadableStream", function() { return ReadableStream; }); +/* harmony export (binding) */ __w_pdfjs_require__.d(__webpack_exports__, "TransformStream", function() { return TransformStream; }); +/* harmony export (binding) */ __w_pdfjs_require__.d(__webpack_exports__, "WritableStream", function() { return WritableStream; }); +var SymbolPolyfill = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? Symbol : function (description) { + return "Symbol(" + description + ")"; +}; +function noop() { +} +var NumberIsNaN = Number.isNaN || function (x) { + return x !== x; +}; +function typeIsObject(x) { + return typeof x === 'object' && x !== null || typeof x === 'function'; +} +function createArrayFromList(elements) { + return elements.slice(); +} +function ArrayBufferCopy(dest, destOffset, src, srcOffset, n) { + new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset); +} +function IsFiniteNonNegativeNumber(v) { + if (IsNonNegativeNumber(v) === false) { + return false; + } + if (v === Infinity) { + return false; + } + return true; +} +function IsNonNegativeNumber(v) { + if (typeof v !== 'number') { + return false; + } + if (NumberIsNaN(v)) { + return false; + } + if (v < 0) { + return false; + } + return true; +} +function Call(F, V, args) { + if (typeof F !== 'function') { + throw new TypeError('Argument is not a function'); + } + return Function.prototype.apply.call(F, V, args); +} +function CreateAlgorithmFromUnderlyingMethod(underlyingObject, methodName, algoArgCount, extraArgs) { + var method = underlyingObject[methodName]; + if (method !== undefined) { + if (typeof method !== 'function') { + throw new TypeError(method + " is not a method"); + } + switch (algoArgCount) { + case 0: { + return function () { + return PromiseCall(method, underlyingObject, extraArgs); }; - modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__); - module.l = true; - return module.exports; - } - - __w_pdfjs_require__.m = modules; - __w_pdfjs_require__.c = installedModules; - - __w_pdfjs_require__.i = function (value) { - return value; - }; - - __w_pdfjs_require__.d = function (exports, name, getter) { - if (!__w_pdfjs_require__.o(exports, name)) { - Object.defineProperty(exports, name, { - configurable: false, - enumerable: true, - get: getter - }); - } - }; - - __w_pdfjs_require__.n = function (module) { - var getter = module && module.__esModule ? function getDefault() { - return module['default']; - } : function getModuleExports() { - return module; + } + case 1: { + return function (arg) { + var fullArgs = [arg].concat(extraArgs); + return PromiseCall(method, underlyingObject, fullArgs); }; - - __w_pdfjs_require__.d(getter, 'a', getter); - - return getter; - }; - - __w_pdfjs_require__.o = function (object, property) { - return Object.prototype.hasOwnProperty.call(object, property); - }; - - __w_pdfjs_require__.p = ""; - return __w_pdfjs_require__(__w_pdfjs_require__.s = 7); -}([function (module, exports, __w_pdfjs_require__) { - "use strict"; - - var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) { - return _typeof2(obj); - } : function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj); - }; - - var _require = __w_pdfjs_require__(1), - assert = _require.assert; - - function IsPropertyKey(argument) { - return typeof argument === 'string' || (typeof argument === 'undefined' ? 'undefined' : _typeof(argument)) === 'symbol'; + } } - - exports.typeIsObject = function (x) { - return (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && x !== null || typeof x === 'function'; - }; - - exports.createDataProperty = function (o, p, v) { - assert(exports.typeIsObject(o)); - Object.defineProperty(o, p, { - value: v, - writable: true, - enumerable: true, - configurable: true - }); - }; - - exports.createArrayFromList = function (elements) { - return elements.slice(); - }; - - exports.ArrayBufferCopy = function (dest, destOffset, src, srcOffset, n) { - new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset); + } + return function () { + return Promise.resolve(); + }; +} +function InvokeOrNoop(O, P, args) { + var method = O[P]; + if (method === undefined) { + return undefined; + } + return Call(method, O, args); +} +function PromiseCall(F, V, args) { + try { + return Promise.resolve(Call(F, V, args)); + } catch (value) { + return Promise.reject(value); + } +} +function TransferArrayBuffer(O) { + return O; +} +function IsDetachedBuffer(O) { + return false; +} +function ValidateAndNormalizeHighWaterMark(highWaterMark) { + highWaterMark = Number(highWaterMark); + if (NumberIsNaN(highWaterMark) || highWaterMark < 0) { + throw new RangeError('highWaterMark property of a queuing strategy must be non-negative and non-NaN'); + } + return highWaterMark; +} +function MakeSizeAlgorithmFromSizeFunction(size) { + if (size === undefined) { + return function () { + return 1; }; - - exports.CreateIterResultObject = function (value, done) { - assert(typeof done === 'boolean'); - var obj = {}; - Object.defineProperty(obj, 'value', { - value: value, - enumerable: true, - writable: true, - configurable: true - }); - Object.defineProperty(obj, 'done', { - value: done, - enumerable: true, - writable: true, - configurable: true - }); - return obj; + } + if (typeof size !== 'function') { + throw new TypeError('size property of a queuing strategy must be a function'); + } + return function (chunk) { + return size(chunk); + }; +} +var QUEUE_MAX_ARRAY_SIZE = 16384; +var SimpleQueue = function () { + function SimpleQueue() { + this._cursor = 0; + this._size = 0; + this._front = { + _elements: [], + _next: undefined }; - - exports.IsFiniteNonNegativeNumber = function (v) { - if (Number.isNaN(v)) { - return false; - } - - if (v === Infinity) { - return false; - } - - if (v < 0) { - return false; + this._back = this._front; + this._cursor = 0; + this._size = 0; + } + Object.defineProperty(SimpleQueue.prototype, "length", { + get: function () { + return this._size; + }, + enumerable: true, + configurable: true + }); + SimpleQueue.prototype.push = function (element) { + var oldBack = this._back; + var newBack = oldBack; + if (oldBack._elements.length === QUEUE_MAX_ARRAY_SIZE - 1) { + newBack = { + _elements: [], + _next: undefined + }; + } + oldBack._elements.push(element); + if (newBack !== oldBack) { + this._back = newBack; + oldBack._next = newBack; + } + ++this._size; + }; + SimpleQueue.prototype.shift = function () { + var oldFront = this._front; + var newFront = oldFront; + var oldCursor = this._cursor; + var newCursor = oldCursor + 1; + var elements = oldFront._elements; + var element = elements[oldCursor]; + if (newCursor === QUEUE_MAX_ARRAY_SIZE) { + newFront = oldFront._next; + newCursor = 0; + } + --this._size; + this._cursor = newCursor; + if (oldFront !== newFront) { + this._front = newFront; + } + elements[oldCursor] = undefined; + return element; + }; + SimpleQueue.prototype.forEach = function (callback) { + var i = this._cursor; + var node = this._front; + var elements = node._elements; + while (i !== elements.length || node._next !== undefined) { + if (i === elements.length) { + node = node._next; + elements = node._elements; + i = 0; + if (elements.length === 0) { + break; } - - return true; + } + callback(elements[i]); + ++i; + } + }; + SimpleQueue.prototype.peek = function () { + var front = this._front; + var cursor = this._cursor; + return front._elements[cursor]; + }; + return SimpleQueue; +}(); +function ReadableStreamCreateReadResult(value, done, forAuthorCode) { + var prototype = null; + if (forAuthorCode === true) { + prototype = Object.prototype; + } + var obj = Object.create(prototype); + obj.value = value; + obj.done = done; + return obj; +} +function ReadableStreamReaderGenericInitialize(reader, stream) { + reader._forAuthorCode = true; + reader._ownerReadableStream = stream; + stream._reader = reader; + if (stream._state === 'readable') { + defaultReaderClosedPromiseInitialize(reader); + } else if (stream._state === 'closed') { + defaultReaderClosedPromiseInitializeAsResolved(reader); + } else { + defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError); + } +} +function ReadableStreamReaderGenericCancel(reader, reason) { + var stream = reader._ownerReadableStream; + return ReadableStreamCancel(stream, reason); +} +function ReadableStreamReaderGenericRelease(reader) { + if (reader._ownerReadableStream._state === 'readable') { + defaultReaderClosedPromiseReject(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness')); + } else { + defaultReaderClosedPromiseResetToRejected(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness')); + } + reader._ownerReadableStream._reader = undefined; + reader._ownerReadableStream = undefined; +} +function readerLockException(name) { + return new TypeError('Cannot ' + name + ' a stream using a released reader'); +} +function defaultReaderClosedPromiseInitialize(reader) { + reader._closedPromise = new Promise(function (resolve, reject) { + reader._closedPromise_resolve = resolve; + reader._closedPromise_reject = reject; + }); +} +function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) { + defaultReaderClosedPromiseInitialize(reader); + defaultReaderClosedPromiseReject(reader, reason); +} +function defaultReaderClosedPromiseInitializeAsResolved(reader) { + defaultReaderClosedPromiseInitialize(reader); + defaultReaderClosedPromiseResolve(reader); +} +function defaultReaderClosedPromiseReject(reader, reason) { + reader._closedPromise.catch(noop); + reader._closedPromise_reject(reason); + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; +} +function defaultReaderClosedPromiseResetToRejected(reader, reason) { + defaultReaderClosedPromiseInitializeAsRejected(reader, reason); +} +function defaultReaderClosedPromiseResolve(reader) { + reader._closedPromise_resolve(undefined); + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; +} +var CancelSteps = SymbolPolyfill('[[CancelSteps]]'); +var PullSteps = SymbolPolyfill('[[PullSteps]]'); +function AcquireReadableStreamDefaultReader(stream, forAuthorCode) { + if (forAuthorCode === void 0) { + forAuthorCode = false; + } + var reader = new ReadableStreamDefaultReader(stream); + reader._forAuthorCode = forAuthorCode; + return reader; +} +function ReadableStreamAddReadRequest(stream) { + var promise = new Promise(function (resolve, reject) { + var readRequest = { + _resolve: resolve, + _reject: reject }; - - function Call(F, V, args) { - if (typeof F !== 'function') { - throw new TypeError('Argument is not a function'); - } - - return Function.prototype.apply.call(F, V, args); + stream._reader._readRequests.push(readRequest); + }); + return promise; +} +function ReadableStreamFulfillReadRequest(stream, chunk, done) { + var reader = stream._reader; + var readRequest = reader._readRequests.shift(); + readRequest._resolve(ReadableStreamCreateReadResult(chunk, done, reader._forAuthorCode)); +} +function ReadableStreamGetNumReadRequests(stream) { + return stream._reader._readRequests.length; +} +function ReadableStreamHasDefaultReader(stream) { + var reader = stream._reader; + if (reader === undefined) { + return false; + } + if (!IsReadableStreamDefaultReader(reader)) { + return false; + } + return true; +} +var ReadableStreamDefaultReader = function () { + function ReadableStreamDefaultReader(stream) { + if (IsReadableStream(stream) === false) { + throw new TypeError('ReadableStreamDefaultReader can only be constructed with a ReadableStream instance'); } - - exports.InvokeOrNoop = function (O, P, args) { - assert(O !== undefined); - assert(IsPropertyKey(P)); - assert(Array.isArray(args)); - var method = O[P]; - - if (method === undefined) { - return undefined; - } - - return Call(method, O, args); - }; - - exports.PromiseInvokeOrNoop = function (O, P, args) { - assert(O !== undefined); - assert(IsPropertyKey(P)); - assert(Array.isArray(args)); - - try { - return Promise.resolve(exports.InvokeOrNoop(O, P, args)); - } catch (returnValueE) { - return Promise.reject(returnValueE); - } - }; - - exports.PromiseInvokeOrPerformFallback = function (O, P, args, F, argsF) { - assert(O !== undefined); - assert(IsPropertyKey(P)); - assert(Array.isArray(args)); - assert(Array.isArray(argsF)); - var method = void 0; - - try { - method = O[P]; - } catch (methodE) { - return Promise.reject(methodE); - } - - if (method === undefined) { - return F.apply(null, argsF); - } - - try { - return Promise.resolve(Call(method, O, args)); - } catch (e) { - return Promise.reject(e); - } - }; - - exports.TransferArrayBuffer = function (O) { - return O.slice(); + if (IsReadableStreamLocked(stream) === true) { + throw new TypeError('This stream has already been locked for exclusive reading by another reader'); + } + ReadableStreamReaderGenericInitialize(this, stream); + this._readRequests = new SimpleQueue(); + } + Object.defineProperty(ReadableStreamDefaultReader.prototype, "closed", { + get: function () { + if (!IsReadableStreamDefaultReader(this)) { + return Promise.reject(defaultReaderBrandCheckException('closed')); + } + return this._closedPromise; + }, + enumerable: true, + configurable: true + }); + ReadableStreamDefaultReader.prototype.cancel = function (reason) { + if (!IsReadableStreamDefaultReader(this)) { + return Promise.reject(defaultReaderBrandCheckException('cancel')); + } + if (this._ownerReadableStream === undefined) { + return Promise.reject(readerLockException('cancel')); + } + return ReadableStreamReaderGenericCancel(this, reason); + }; + ReadableStreamDefaultReader.prototype.read = function () { + if (!IsReadableStreamDefaultReader(this)) { + return Promise.reject(defaultReaderBrandCheckException('read')); + } + if (this._ownerReadableStream === undefined) { + return Promise.reject(readerLockException('read from')); + } + return ReadableStreamDefaultReaderRead(this); + }; + ReadableStreamDefaultReader.prototype.releaseLock = function () { + if (!IsReadableStreamDefaultReader(this)) { + throw defaultReaderBrandCheckException('releaseLock'); + } + if (this._ownerReadableStream === undefined) { + return; + } + if (this._readRequests.length > 0) { + throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled'); + } + ReadableStreamReaderGenericRelease(this); + }; + return ReadableStreamDefaultReader; +}(); +function IsReadableStreamDefaultReader(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) { + return false; + } + return true; +} +function ReadableStreamDefaultReaderRead(reader) { + var stream = reader._ownerReadableStream; + stream._disturbed = true; + if (stream._state === 'closed') { + return Promise.resolve(ReadableStreamCreateReadResult(undefined, true, reader._forAuthorCode)); + } + if (stream._state === 'errored') { + return Promise.reject(stream._storedError); + } + return stream._readableStreamController[PullSteps](); +} +function defaultReaderBrandCheckException(name) { + return new TypeError("ReadableStreamDefaultReader.prototype." + name + " can only be used on a ReadableStreamDefaultReader"); +} +var _a; +var AsyncIteratorPrototype; +if (typeof SymbolPolyfill.asyncIterator === 'symbol') { + AsyncIteratorPrototype = (_a = {}, _a[SymbolPolyfill.asyncIterator] = function () { + return this; + }, _a); + Object.defineProperty(AsyncIteratorPrototype, SymbolPolyfill.asyncIterator, { enumerable: false }); +} +var ReadableStreamAsyncIteratorPrototype = { + next: function () { + if (IsReadableStreamAsyncIterator(this) === false) { + return Promise.reject(streamAsyncIteratorBrandCheckException('next')); + } + var reader = this._asyncIteratorReader; + if (reader._ownerReadableStream === undefined) { + return Promise.reject(readerLockException('iterate')); + } + return ReadableStreamDefaultReaderRead(reader).then(function (result) { + var done = result.done; + if (done) { + ReadableStreamReaderGenericRelease(reader); + } + var value = result.value; + return ReadableStreamCreateReadResult(value, done, true); + }); + }, + return: function (value) { + if (IsReadableStreamAsyncIterator(this) === false) { + return Promise.reject(streamAsyncIteratorBrandCheckException('next')); + } + var reader = this._asyncIteratorReader; + if (reader._ownerReadableStream === undefined) { + return Promise.reject(readerLockException('finish iterating')); + } + if (reader._readRequests.length > 0) { + return Promise.reject(new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled')); + } + if (this._preventCancel === false) { + var result = ReadableStreamReaderGenericCancel(reader, value); + ReadableStreamReaderGenericRelease(reader); + return result.then(function () { + return ReadableStreamCreateReadResult(value, true, true); + }); + } + ReadableStreamReaderGenericRelease(reader); + return Promise.resolve(ReadableStreamCreateReadResult(value, true, true)); + } +}; +if (AsyncIteratorPrototype !== undefined) { + Object.setPrototypeOf(ReadableStreamAsyncIteratorPrototype, AsyncIteratorPrototype); +} +Object.defineProperty(ReadableStreamAsyncIteratorPrototype, 'next', { enumerable: false }); +Object.defineProperty(ReadableStreamAsyncIteratorPrototype, 'return', { enumerable: false }); +function AcquireReadableStreamAsyncIterator(stream, preventCancel) { + if (preventCancel === void 0) { + preventCancel = false; + } + var reader = AcquireReadableStreamDefaultReader(stream); + var iterator = Object.create(ReadableStreamAsyncIteratorPrototype); + iterator._asyncIteratorReader = reader; + iterator._preventCancel = Boolean(preventCancel); + return iterator; +} +function IsReadableStreamAsyncIterator(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_asyncIteratorReader')) { + return false; + } + return true; +} +function streamAsyncIteratorBrandCheckException(name) { + return new TypeError("ReadableStreamAsyncIterator." + name + " can only be used on a ReadableSteamAsyncIterator"); +} +var rethrowAssertionErrorRejection = noop; +function DequeueValue(container) { + var pair = container._queue.shift(); + container._queueTotalSize -= pair.size; + if (container._queueTotalSize < 0) { + container._queueTotalSize = 0; + } + return pair.value; +} +function EnqueueValueWithSize(container, value, size) { + size = Number(size); + if (!IsFiniteNonNegativeNumber(size)) { + throw new RangeError('Size must be a finite, non-NaN, non-negative number.'); + } + container._queue.push({ + value: value, + size: size + }); + container._queueTotalSize += size; +} +function PeekQueueValue(container) { + var pair = container._queue.peek(); + return pair.value; +} +function ResetQueue(container) { + container._queue = new SimpleQueue(); + container._queueTotalSize = 0; +} +var AbortSteps = SymbolPolyfill('[[AbortSteps]]'); +var ErrorSteps = SymbolPolyfill('[[ErrorSteps]]'); +var WritableStream = function () { + function WritableStream(underlyingSink, strategy) { + if (underlyingSink === void 0) { + underlyingSink = {}; + } + if (strategy === void 0) { + strategy = {}; + } + InitializeWritableStream(this); + var size = strategy.size; + var highWaterMark = strategy.highWaterMark; + var type = underlyingSink.type; + if (type !== undefined) { + throw new RangeError('Invalid type is specified'); + } + var sizeAlgorithm = MakeSizeAlgorithmFromSizeFunction(size); + if (highWaterMark === undefined) { + highWaterMark = 1; + } + highWaterMark = ValidateAndNormalizeHighWaterMark(highWaterMark); + SetUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, highWaterMark, sizeAlgorithm); + } + Object.defineProperty(WritableStream.prototype, "locked", { + get: function () { + if (IsWritableStream(this) === false) { + throw streamBrandCheckException('locked'); + } + return IsWritableStreamLocked(this); + }, + enumerable: true, + configurable: true + }); + WritableStream.prototype.abort = function (reason) { + if (IsWritableStream(this) === false) { + return Promise.reject(streamBrandCheckException('abort')); + } + if (IsWritableStreamLocked(this) === true) { + return Promise.reject(new TypeError('Cannot abort a stream that already has a writer')); + } + return WritableStreamAbort(this, reason); + }; + WritableStream.prototype.getWriter = function () { + if (IsWritableStream(this) === false) { + throw streamBrandCheckException('getWriter'); + } + return AcquireWritableStreamDefaultWriter(this); + }; + return WritableStream; +}(); +function AcquireWritableStreamDefaultWriter(stream) { + return new WritableStreamDefaultWriter(stream); +} +function CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) { + if (highWaterMark === void 0) { + highWaterMark = 1; + } + if (sizeAlgorithm === void 0) { + sizeAlgorithm = function () { + return 1; }; - - exports.ValidateAndNormalizeHighWaterMark = function (highWaterMark) { - highWaterMark = Number(highWaterMark); - - if (Number.isNaN(highWaterMark) || highWaterMark < 0) { - throw new RangeError('highWaterMark property of a queuing strategy must be non-negative and non-NaN'); - } - - return highWaterMark; + } + var stream = Object.create(WritableStream.prototype); + InitializeWritableStream(stream); + var controller = Object.create(WritableStreamDefaultController.prototype); + SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm); + return stream; +} +function InitializeWritableStream(stream) { + stream._state = 'writable'; + stream._storedError = undefined; + stream._writer = undefined; + stream._writableStreamController = undefined; + stream._writeRequests = new SimpleQueue(); + stream._inFlightWriteRequest = undefined; + stream._closeRequest = undefined; + stream._inFlightCloseRequest = undefined; + stream._pendingAbortRequest = undefined; + stream._backpressure = false; +} +function IsWritableStream(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) { + return false; + } + return true; +} +function IsWritableStreamLocked(stream) { + if (stream._writer === undefined) { + return false; + } + return true; +} +function WritableStreamAbort(stream, reason) { + var state = stream._state; + if (state === 'closed' || state === 'errored') { + return Promise.resolve(undefined); + } + if (stream._pendingAbortRequest !== undefined) { + return stream._pendingAbortRequest._promise; + } + var wasAlreadyErroring = false; + if (state === 'erroring') { + wasAlreadyErroring = true; + reason = undefined; + } + var promise = new Promise(function (resolve, reject) { + stream._pendingAbortRequest = { + _promise: undefined, + _resolve: resolve, + _reject: reject, + _reason: reason, + _wasAlreadyErroring: wasAlreadyErroring }; - - exports.ValidateAndNormalizeQueuingStrategy = function (size, highWaterMark) { - if (size !== undefined && typeof size !== 'function') { - throw new TypeError('size property of a queuing strategy must be a function'); - } - - highWaterMark = exports.ValidateAndNormalizeHighWaterMark(highWaterMark); - return { - size: size, - highWaterMark: highWaterMark - }; + }); + stream._pendingAbortRequest._promise = promise; + if (wasAlreadyErroring === false) { + WritableStreamStartErroring(stream, reason); + } + return promise; +} +function WritableStreamAddWriteRequest(stream) { + var promise = new Promise(function (resolve, reject) { + var writeRequest = { + _resolve: resolve, + _reject: reject }; -}, function (module, exports, __w_pdfjs_require__) { - "use strict"; - - function rethrowAssertionErrorRejection(e) { - if (e && e.constructor === AssertionError) { - setTimeout(function () { - throw e; - }, 0); - } + stream._writeRequests.push(writeRequest); + }); + return promise; +} +function WritableStreamDealWithRejection(stream, error) { + var state = stream._state; + if (state === 'writable') { + WritableStreamStartErroring(stream, error); + return; + } + WritableStreamFinishErroring(stream); +} +function WritableStreamStartErroring(stream, reason) { + var controller = stream._writableStreamController; + stream._state = 'erroring'; + stream._storedError = reason; + var writer = stream._writer; + if (writer !== undefined) { + WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason); + } + if (WritableStreamHasOperationMarkedInFlight(stream) === false && controller._started === true) { + WritableStreamFinishErroring(stream); + } +} +function WritableStreamFinishErroring(stream) { + stream._state = 'errored'; + stream._writableStreamController[ErrorSteps](); + var storedError = stream._storedError; + stream._writeRequests.forEach(function (writeRequest) { + writeRequest._reject(storedError); + }); + stream._writeRequests = new SimpleQueue(); + if (stream._pendingAbortRequest === undefined) { + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + return; + } + var abortRequest = stream._pendingAbortRequest; + stream._pendingAbortRequest = undefined; + if (abortRequest._wasAlreadyErroring === true) { + abortRequest._reject(storedError); + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + return; + } + var promise = stream._writableStreamController[AbortSteps](abortRequest._reason); + promise.then(function () { + abortRequest._resolve(); + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + }, function (reason) { + abortRequest._reject(reason); + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + }); +} +function WritableStreamFinishInFlightWrite(stream) { + stream._inFlightWriteRequest._resolve(undefined); + stream._inFlightWriteRequest = undefined; +} +function WritableStreamFinishInFlightWriteWithError(stream, error) { + stream._inFlightWriteRequest._reject(error); + stream._inFlightWriteRequest = undefined; + WritableStreamDealWithRejection(stream, error); +} +function WritableStreamFinishInFlightClose(stream) { + stream._inFlightCloseRequest._resolve(undefined); + stream._inFlightCloseRequest = undefined; + var state = stream._state; + if (state === 'erroring') { + stream._storedError = undefined; + if (stream._pendingAbortRequest !== undefined) { + stream._pendingAbortRequest._resolve(); + stream._pendingAbortRequest = undefined; } - - function AssertionError(message) { - this.name = 'AssertionError'; - this.message = message || ''; - this.stack = new Error().stack; + } + stream._state = 'closed'; + var writer = stream._writer; + if (writer !== undefined) { + defaultWriterClosedPromiseResolve(writer); + } +} +function WritableStreamFinishInFlightCloseWithError(stream, error) { + stream._inFlightCloseRequest._reject(error); + stream._inFlightCloseRequest = undefined; + if (stream._pendingAbortRequest !== undefined) { + stream._pendingAbortRequest._reject(error); + stream._pendingAbortRequest = undefined; + } + WritableStreamDealWithRejection(stream, error); +} +function WritableStreamCloseQueuedOrInFlight(stream) { + if (stream._closeRequest === undefined && stream._inFlightCloseRequest === undefined) { + return false; + } + return true; +} +function WritableStreamHasOperationMarkedInFlight(stream) { + if (stream._inFlightWriteRequest === undefined && stream._inFlightCloseRequest === undefined) { + return false; + } + return true; +} +function WritableStreamMarkCloseRequestInFlight(stream) { + stream._inFlightCloseRequest = stream._closeRequest; + stream._closeRequest = undefined; +} +function WritableStreamMarkFirstWriteRequestInFlight(stream) { + stream._inFlightWriteRequest = stream._writeRequests.shift(); +} +function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) { + if (stream._closeRequest !== undefined) { + stream._closeRequest._reject(stream._storedError); + stream._closeRequest = undefined; + } + var writer = stream._writer; + if (writer !== undefined) { + defaultWriterClosedPromiseReject(writer, stream._storedError); + } +} +function WritableStreamUpdateBackpressure(stream, backpressure) { + var writer = stream._writer; + if (writer !== undefined && backpressure !== stream._backpressure) { + if (backpressure === true) { + defaultWriterReadyPromiseReset(writer); + } else { + defaultWriterReadyPromiseResolve(writer); } - - AssertionError.prototype = Object.create(Error.prototype); - AssertionError.prototype.constructor = AssertionError; - - function assert(value, message) { - if (!value) { - throw new AssertionError(message); - } + } + stream._backpressure = backpressure; +} +var WritableStreamDefaultWriter = function () { + function WritableStreamDefaultWriter(stream) { + if (IsWritableStream(stream) === false) { + throw new TypeError('WritableStreamDefaultWriter can only be constructed with a WritableStream instance'); + } + if (IsWritableStreamLocked(stream) === true) { + throw new TypeError('This stream has already been locked for exclusive writing by another writer'); + } + this._ownerWritableStream = stream; + stream._writer = this; + var state = stream._state; + if (state === 'writable') { + if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._backpressure === true) { + defaultWriterReadyPromiseInitialize(this); + } else { + defaultWriterReadyPromiseInitializeAsResolved(this); + } + defaultWriterClosedPromiseInitialize(this); + } else if (state === 'erroring') { + defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError); + defaultWriterClosedPromiseInitialize(this); + } else if (state === 'closed') { + defaultWriterReadyPromiseInitializeAsResolved(this); + defaultWriterClosedPromiseInitializeAsResolved(this); + } else { + var storedError = stream._storedError; + defaultWriterReadyPromiseInitializeAsRejected(this, storedError); + defaultWriterClosedPromiseInitializeAsRejected(this, storedError); } - - module.exports = { - rethrowAssertionErrorRejection: rethrowAssertionErrorRejection, - AssertionError: AssertionError, - assert: assert + } + Object.defineProperty(WritableStreamDefaultWriter.prototype, "closed", { + get: function () { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('closed')); + } + return this._closedPromise; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(WritableStreamDefaultWriter.prototype, "desiredSize", { + get: function () { + if (IsWritableStreamDefaultWriter(this) === false) { + throw defaultWriterBrandCheckException('desiredSize'); + } + if (this._ownerWritableStream === undefined) { + throw defaultWriterLockException('desiredSize'); + } + return WritableStreamDefaultWriterGetDesiredSize(this); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(WritableStreamDefaultWriter.prototype, "ready", { + get: function () { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('ready')); + } + return this._readyPromise; + }, + enumerable: true, + configurable: true + }); + WritableStreamDefaultWriter.prototype.abort = function (reason) { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('abort')); + } + if (this._ownerWritableStream === undefined) { + return Promise.reject(defaultWriterLockException('abort')); + } + return WritableStreamDefaultWriterAbort(this, reason); + }; + WritableStreamDefaultWriter.prototype.close = function () { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('close')); + } + var stream = this._ownerWritableStream; + if (stream === undefined) { + return Promise.reject(defaultWriterLockException('close')); + } + if (WritableStreamCloseQueuedOrInFlight(stream) === true) { + return Promise.reject(new TypeError('cannot close an already-closing stream')); + } + return WritableStreamDefaultWriterClose(this); + }; + WritableStreamDefaultWriter.prototype.releaseLock = function () { + if (IsWritableStreamDefaultWriter(this) === false) { + throw defaultWriterBrandCheckException('releaseLock'); + } + var stream = this._ownerWritableStream; + if (stream === undefined) { + return; + } + WritableStreamDefaultWriterRelease(this); + }; + WritableStreamDefaultWriter.prototype.write = function (chunk) { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('write')); + } + if (this._ownerWritableStream === undefined) { + return Promise.reject(defaultWriterLockException('write to')); + } + return WritableStreamDefaultWriterWrite(this, chunk); + }; + return WritableStreamDefaultWriter; +}(); +function IsWritableStreamDefaultWriter(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) { + return false; + } + return true; +} +function WritableStreamDefaultWriterAbort(writer, reason) { + var stream = writer._ownerWritableStream; + return WritableStreamAbort(stream, reason); +} +function WritableStreamDefaultWriterClose(writer) { + var stream = writer._ownerWritableStream; + var state = stream._state; + if (state === 'closed' || state === 'errored') { + return Promise.reject(new TypeError("The stream (in " + state + " state) is not in the writable state and cannot be closed")); + } + var promise = new Promise(function (resolve, reject) { + var closeRequest = { + _resolve: resolve, + _reject: reject }; -}, function (module, exports, __w_pdfjs_require__) { - "use strict"; - - 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; - }; - }(); - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - var _require = __w_pdfjs_require__(0), - InvokeOrNoop = _require.InvokeOrNoop, - PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop, - ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy, - typeIsObject = _require.typeIsObject; - - var _require2 = __w_pdfjs_require__(1), - assert = _require2.assert, - rethrowAssertionErrorRejection = _require2.rethrowAssertionErrorRejection; - - var _require3 = __w_pdfjs_require__(3), - DequeueValue = _require3.DequeueValue, - EnqueueValueWithSize = _require3.EnqueueValueWithSize, - PeekQueueValue = _require3.PeekQueueValue, - ResetQueue = _require3.ResetQueue; - - var WritableStream = function () { - function WritableStream() { - var underlyingSink = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - size = _ref.size, - _ref$highWaterMark = _ref.highWaterMark, - highWaterMark = _ref$highWaterMark === undefined ? 1 : _ref$highWaterMark; - - _classCallCheck(this, WritableStream); - - this._state = 'writable'; - this._storedError = undefined; - this._writer = undefined; - this._writableStreamController = undefined; - this._writeRequests = []; - this._inFlightWriteRequest = undefined; - this._closeRequest = undefined; - this._inFlightCloseRequest = undefined; - this._pendingAbortRequest = undefined; - this._backpressure = false; - var type = underlyingSink.type; - - if (type !== undefined) { - throw new RangeError('Invalid type is specified'); + stream._closeRequest = closeRequest; + }); + if (stream._backpressure === true && state === 'writable') { + defaultWriterReadyPromiseResolve(writer); + } + WritableStreamDefaultControllerClose(stream._writableStreamController); + return promise; +} +function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) { + var stream = writer._ownerWritableStream; + var state = stream._state; + if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { + return Promise.resolve(); + } + if (state === 'errored') { + return Promise.reject(stream._storedError); + } + return WritableStreamDefaultWriterClose(writer); +} +function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) { + if (writer._closedPromiseState === 'pending') { + defaultWriterClosedPromiseReject(writer, error); + } else { + defaultWriterClosedPromiseResetToRejected(writer, error); + } +} +function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) { + if (writer._readyPromiseState === 'pending') { + defaultWriterReadyPromiseReject(writer, error); + } else { + defaultWriterReadyPromiseResetToRejected(writer, error); + } +} +function WritableStreamDefaultWriterGetDesiredSize(writer) { + var stream = writer._ownerWritableStream; + var state = stream._state; + if (state === 'errored' || state === 'erroring') { + return null; + } + if (state === 'closed') { + return 0; + } + return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController); +} +function WritableStreamDefaultWriterRelease(writer) { + var stream = writer._ownerWritableStream; + var releasedError = new TypeError('Writer was released and can no longer be used to monitor the stream\'s closedness'); + WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError); + WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError); + stream._writer = undefined; + writer._ownerWritableStream = undefined; +} +function WritableStreamDefaultWriterWrite(writer, chunk) { + var stream = writer._ownerWritableStream; + var controller = stream._writableStreamController; + var chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk); + if (stream !== writer._ownerWritableStream) { + return Promise.reject(defaultWriterLockException('write to')); + } + var state = stream._state; + if (state === 'errored') { + return Promise.reject(stream._storedError); + } + if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { + return Promise.reject(new TypeError('The stream is closing or closed and cannot be written to')); + } + if (state === 'erroring') { + return Promise.reject(stream._storedError); + } + var promise = WritableStreamAddWriteRequest(stream); + WritableStreamDefaultControllerWrite(controller, chunk, chunkSize); + return promise; +} +var WritableStreamDefaultController = function () { + function WritableStreamDefaultController() { + throw new TypeError('WritableStreamDefaultController cannot be constructed explicitly'); + } + WritableStreamDefaultController.prototype.error = function (e) { + if (IsWritableStreamDefaultController(this) === false) { + throw new TypeError('WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController'); + } + var state = this._controlledWritableStream._state; + if (state !== 'writable') { + return; + } + WritableStreamDefaultControllerError(this, e); + }; + WritableStreamDefaultController.prototype[AbortSteps] = function (reason) { + var result = this._abortAlgorithm(reason); + WritableStreamDefaultControllerClearAlgorithms(this); + return result; + }; + WritableStreamDefaultController.prototype[ErrorSteps] = function () { + ResetQueue(this); + }; + return WritableStreamDefaultController; +}(); +function IsWritableStreamDefaultController(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_controlledWritableStream')) { + return false; + } + return true; +} +function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) { + controller._controlledWritableStream = stream; + stream._writableStreamController = controller; + controller._queue = undefined; + controller._queueTotalSize = undefined; + ResetQueue(controller); + controller._started = false; + controller._strategySizeAlgorithm = sizeAlgorithm; + controller._strategyHWM = highWaterMark; + controller._writeAlgorithm = writeAlgorithm; + controller._closeAlgorithm = closeAlgorithm; + controller._abortAlgorithm = abortAlgorithm; + var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); + WritableStreamUpdateBackpressure(stream, backpressure); + var startResult = startAlgorithm(); + var startPromise = Promise.resolve(startResult); + startPromise.then(function () { + controller._started = true; + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + }, function (r) { + controller._started = true; + WritableStreamDealWithRejection(stream, r); + }).catch(rethrowAssertionErrorRejection); +} +function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, highWaterMark, sizeAlgorithm) { + var controller = Object.create(WritableStreamDefaultController.prototype); + function startAlgorithm() { + return InvokeOrNoop(underlyingSink, 'start', [controller]); + } + var writeAlgorithm = CreateAlgorithmFromUnderlyingMethod(underlyingSink, 'write', 1, [controller]); + var closeAlgorithm = CreateAlgorithmFromUnderlyingMethod(underlyingSink, 'close', 0, []); + var abortAlgorithm = CreateAlgorithmFromUnderlyingMethod(underlyingSink, 'abort', 1, []); + SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm); +} +function WritableStreamDefaultControllerClearAlgorithms(controller) { + controller._writeAlgorithm = undefined; + controller._closeAlgorithm = undefined; + controller._abortAlgorithm = undefined; + controller._strategySizeAlgorithm = undefined; +} +function WritableStreamDefaultControllerClose(controller) { + EnqueueValueWithSize(controller, 'close', 0); + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); +} +function WritableStreamDefaultControllerGetChunkSize(controller, chunk) { + try { + return controller._strategySizeAlgorithm(chunk); + } catch (chunkSizeE) { + WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE); + return 1; + } +} +function WritableStreamDefaultControllerGetDesiredSize(controller) { + return controller._strategyHWM - controller._queueTotalSize; +} +function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) { + var writeRecord = { chunk: chunk }; + try { + EnqueueValueWithSize(controller, writeRecord, chunkSize); + } catch (enqueueE) { + WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE); + return; + } + var stream = controller._controlledWritableStream; + if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._state === 'writable') { + var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); + WritableStreamUpdateBackpressure(stream, backpressure); + } + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); +} +function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) { + var stream = controller._controlledWritableStream; + if (controller._started === false) { + return; + } + if (stream._inFlightWriteRequest !== undefined) { + return; + } + var state = stream._state; + if (state === 'erroring') { + WritableStreamFinishErroring(stream); + return; + } + if (controller._queue.length === 0) { + return; + } + var writeRecord = PeekQueueValue(controller); + if (writeRecord === 'close') { + WritableStreamDefaultControllerProcessClose(controller); + } else { + WritableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk); + } +} +function WritableStreamDefaultControllerErrorIfNeeded(controller, error) { + if (controller._controlledWritableStream._state === 'writable') { + WritableStreamDefaultControllerError(controller, error); + } +} +function WritableStreamDefaultControllerProcessClose(controller) { + var stream = controller._controlledWritableStream; + WritableStreamMarkCloseRequestInFlight(stream); + DequeueValue(controller); + var sinkClosePromise = controller._closeAlgorithm(); + WritableStreamDefaultControllerClearAlgorithms(controller); + sinkClosePromise.then(function () { + WritableStreamFinishInFlightClose(stream); + }, function (reason) { + WritableStreamFinishInFlightCloseWithError(stream, reason); + }).catch(rethrowAssertionErrorRejection); +} +function WritableStreamDefaultControllerProcessWrite(controller, chunk) { + var stream = controller._controlledWritableStream; + WritableStreamMarkFirstWriteRequestInFlight(stream); + var sinkWritePromise = controller._writeAlgorithm(chunk); + sinkWritePromise.then(function () { + WritableStreamFinishInFlightWrite(stream); + var state = stream._state; + DequeueValue(controller); + if (WritableStreamCloseQueuedOrInFlight(stream) === false && state === 'writable') { + var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); + WritableStreamUpdateBackpressure(stream, backpressure); + } + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + }, function (reason) { + if (stream._state === 'writable') { + WritableStreamDefaultControllerClearAlgorithms(controller); + } + WritableStreamFinishInFlightWriteWithError(stream, reason); + }).catch(rethrowAssertionErrorRejection); +} +function WritableStreamDefaultControllerGetBackpressure(controller) { + var desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller); + return desiredSize <= 0; +} +function WritableStreamDefaultControllerError(controller, error) { + var stream = controller._controlledWritableStream; + WritableStreamDefaultControllerClearAlgorithms(controller); + WritableStreamStartErroring(stream, error); +} +function streamBrandCheckException(name) { + return new TypeError("WritableStream.prototype." + name + " can only be used on a WritableStream"); +} +function defaultWriterBrandCheckException(name) { + return new TypeError("WritableStreamDefaultWriter.prototype." + name + " can only be used on a WritableStreamDefaultWriter"); +} +function defaultWriterLockException(name) { + return new TypeError('Cannot ' + name + ' a stream using a released writer'); +} +function defaultWriterClosedPromiseInitialize(writer) { + writer._closedPromise = new Promise(function (resolve, reject) { + writer._closedPromise_resolve = resolve; + writer._closedPromise_reject = reject; + writer._closedPromiseState = 'pending'; + }); +} +function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) { + defaultWriterClosedPromiseInitialize(writer); + defaultWriterClosedPromiseReject(writer, reason); +} +function defaultWriterClosedPromiseInitializeAsResolved(writer) { + defaultWriterClosedPromiseInitialize(writer); + defaultWriterClosedPromiseResolve(writer); +} +function defaultWriterClosedPromiseReject(writer, reason) { + writer._closedPromise.catch(noop); + writer._closedPromise_reject(reason); + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'rejected'; +} +function defaultWriterClosedPromiseResetToRejected(writer, reason) { + defaultWriterClosedPromiseInitializeAsRejected(writer, reason); +} +function defaultWriterClosedPromiseResolve(writer) { + writer._closedPromise_resolve(undefined); + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'resolved'; +} +function defaultWriterReadyPromiseInitialize(writer) { + writer._readyPromise = new Promise(function (resolve, reject) { + writer._readyPromise_resolve = resolve; + writer._readyPromise_reject = reject; + }); + writer._readyPromiseState = 'pending'; +} +function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) { + defaultWriterReadyPromiseInitialize(writer); + defaultWriterReadyPromiseReject(writer, reason); +} +function defaultWriterReadyPromiseInitializeAsResolved(writer) { + defaultWriterReadyPromiseInitialize(writer); + defaultWriterReadyPromiseResolve(writer); +} +function defaultWriterReadyPromiseReject(writer, reason) { + writer._readyPromise.catch(noop); + writer._readyPromise_reject(reason); + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'rejected'; +} +function defaultWriterReadyPromiseReset(writer) { + defaultWriterReadyPromiseInitialize(writer); +} +function defaultWriterReadyPromiseResetToRejected(writer, reason) { + defaultWriterReadyPromiseInitializeAsRejected(writer, reason); +} +function defaultWriterReadyPromiseResolve(writer) { + writer._readyPromise_resolve(undefined); + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'fulfilled'; +} +function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) { + var reader = AcquireReadableStreamDefaultReader(source); + var writer = AcquireWritableStreamDefaultWriter(dest); + var shuttingDown = false; + var currentWrite = Promise.resolve(); + return new Promise(function (resolve, reject) { + var abortAlgorithm; + if (signal !== undefined) { + abortAlgorithm = function () { + var error = new DOMException('Aborted', 'AbortError'); + var actions = []; + if (preventAbort === false) { + actions.push(function () { + if (dest._state === 'writable') { + return WritableStreamAbort(dest, error); } - - this._writableStreamController = new WritableStreamDefaultController(this, underlyingSink, size, highWaterMark); - - this._writableStreamController.__startSteps(); + return Promise.resolve(); + }); } - - _createClass(WritableStream, [{ - key: 'abort', - value: function abort(reason) { - if (IsWritableStream(this) === false) { - return Promise.reject(streamBrandCheckException('abort')); - } - - if (IsWritableStreamLocked(this) === true) { - return Promise.reject(new TypeError('Cannot abort a stream that already has a writer')); - } - - return WritableStreamAbort(this, reason); + if (preventCancel === false) { + actions.push(function () { + if (source._state === 'readable') { + return ReadableStreamCancel(source, error); } - }, { - key: 'getWriter', - value: function getWriter() { - if (IsWritableStream(this) === false) { - throw streamBrandCheckException('getWriter'); - } - - return AcquireWritableStreamDefaultWriter(this); - } - }, { - key: 'locked', - get: function get() { - if (IsWritableStream(this) === false) { - throw streamBrandCheckException('locked'); - } - - return IsWritableStreamLocked(this); - } - }]); - - return WritableStream; - }(); - - module.exports = { - AcquireWritableStreamDefaultWriter: AcquireWritableStreamDefaultWriter, - IsWritableStream: IsWritableStream, - IsWritableStreamLocked: IsWritableStreamLocked, - WritableStream: WritableStream, - WritableStreamAbort: WritableStreamAbort, - WritableStreamDefaultControllerError: WritableStreamDefaultControllerError, - WritableStreamDefaultWriterCloseWithErrorPropagation: WritableStreamDefaultWriterCloseWithErrorPropagation, - WritableStreamDefaultWriterRelease: WritableStreamDefaultWriterRelease, - WritableStreamDefaultWriterWrite: WritableStreamDefaultWriterWrite, - WritableStreamCloseQueuedOrInFlight: WritableStreamCloseQueuedOrInFlight - }; - - function AcquireWritableStreamDefaultWriter(stream) { - return new WritableStreamDefaultWriter(stream); - } - - function IsWritableStream(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) { - return false; - } - - return true; - } - - function IsWritableStreamLocked(stream) { - assert(IsWritableStream(stream) === true, 'IsWritableStreamLocked should only be used on known writable streams'); - - if (stream._writer === undefined) { - return false; - } - - return true; - } - - function WritableStreamAbort(stream, reason) { - var state = stream._state; - - if (state === 'closed') { - return Promise.resolve(undefined); - } - - if (state === 'errored') { - return Promise.reject(stream._storedError); - } - - var error = new TypeError('Requested to abort'); - - if (stream._pendingAbortRequest !== undefined) { - return Promise.reject(error); - } - - assert(state === 'writable' || state === 'erroring', 'state must be writable or erroring'); - var wasAlreadyErroring = false; - - if (state === 'erroring') { - wasAlreadyErroring = true; - reason = undefined; - } - - var promise = new Promise(function (resolve, reject) { - stream._pendingAbortRequest = { - _resolve: resolve, - _reject: reject, - _reason: reason, - _wasAlreadyErroring: wasAlreadyErroring - }; - }); - - if (wasAlreadyErroring === false) { - WritableStreamStartErroring(stream, error); - } - - return promise; - } - - function WritableStreamAddWriteRequest(stream) { - assert(IsWritableStreamLocked(stream) === true); - assert(stream._state === 'writable'); - var promise = new Promise(function (resolve, reject) { - var writeRequest = { - _resolve: resolve, - _reject: reject - }; - - stream._writeRequests.push(writeRequest); + return Promise.resolve(); + }); + } + shutdownWithAction(function () { + return Promise.all(actions.map(function (action) { + return action(); + })); + }, true, error); + }; + if (signal.aborted === true) { + abortAlgorithm(); + return; + } + signal.addEventListener('abort', abortAlgorithm); + } + function pipeLoop() { + return new Promise(function (resolveLoop, rejectLoop) { + function next(done) { + if (done) { + resolveLoop(); + } else { + pipeStep().then(next, rejectLoop); + } + } + next(false); + }); + } + function pipeStep() { + if (shuttingDown === true) { + return Promise.resolve(true); + } + return writer._readyPromise.then(function () { + return ReadableStreamDefaultReaderRead(reader).then(function (_a) { + var value = _a.value, done = _a.done; + if (done === true) { + return true; + } + currentWrite = WritableStreamDefaultWriterWrite(writer, value).catch(noop); + return false; }); - return promise; - } - - function WritableStreamDealWithRejection(stream, error) { - var state = stream._state; - - if (state === 'writable') { - WritableStreamStartErroring(stream, error); - return; - } - - assert(state === 'erroring'); - WritableStreamFinishErroring(stream); - } - - function WritableStreamStartErroring(stream, reason) { - assert(stream._storedError === undefined, 'stream._storedError === undefined'); - assert(stream._state === 'writable', 'state must be writable'); - var controller = stream._writableStreamController; - assert(controller !== undefined, 'controller must not be undefined'); - stream._state = 'erroring'; - stream._storedError = reason; - var writer = stream._writer; - - if (writer !== undefined) { - WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason); - } - - if (WritableStreamHasOperationMarkedInFlight(stream) === false && controller._started === true) { - WritableStreamFinishErroring(stream); - } - } - - function WritableStreamFinishErroring(stream) { - assert(stream._state === 'erroring', 'stream._state === erroring'); - assert(WritableStreamHasOperationMarkedInFlight(stream) === false, 'WritableStreamHasOperationMarkedInFlight(stream) === false'); - stream._state = 'errored'; - - stream._writableStreamController.__errorSteps(); - - var storedError = stream._storedError; - - for (var i = 0; i < stream._writeRequests.length; i++) { - var writeRequest = stream._writeRequests[i]; - - writeRequest._reject(storedError); - } - - stream._writeRequests = []; - - if (stream._pendingAbortRequest === undefined) { - WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); - return; - } - - var abortRequest = stream._pendingAbortRequest; - stream._pendingAbortRequest = undefined; - - if (abortRequest._wasAlreadyErroring === true) { - abortRequest._reject(storedError); - - WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); - return; - } - - var promise = stream._writableStreamController.__abortSteps(abortRequest._reason); - - promise.then(function () { - abortRequest._resolve(); - - WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); - }, function (reason) { - abortRequest._reject(reason); - - WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + }); + } + isOrBecomesErrored(source, reader._closedPromise, function (storedError) { + if (preventAbort === false) { + shutdownWithAction(function () { + return WritableStreamAbort(dest, storedError); + }, true, storedError); + } else { + shutdown(true, storedError); + } + }); + isOrBecomesErrored(dest, writer._closedPromise, function (storedError) { + if (preventCancel === false) { + shutdownWithAction(function () { + return ReadableStreamCancel(source, storedError); + }, true, storedError); + } else { + shutdown(true, storedError); + } + }); + isOrBecomesClosed(source, reader._closedPromise, function () { + if (preventClose === false) { + shutdownWithAction(function () { + return WritableStreamDefaultWriterCloseWithErrorPropagation(writer); }); + } else { + shutdown(); + } + }); + if (WritableStreamCloseQueuedOrInFlight(dest) === true || dest._state === 'closed') { + var destClosed_1 = new TypeError('the destination writable stream closed before all data could be piped to it'); + if (preventCancel === false) { + shutdownWithAction(function () { + return ReadableStreamCancel(source, destClosed_1); + }, true, destClosed_1); + } else { + shutdown(true, destClosed_1); + } } - - function WritableStreamFinishInFlightWrite(stream) { - assert(stream._inFlightWriteRequest !== undefined); - - stream._inFlightWriteRequest._resolve(undefined); - - stream._inFlightWriteRequest = undefined; - } - - function WritableStreamFinishInFlightWriteWithError(stream, error) { - assert(stream._inFlightWriteRequest !== undefined); - - stream._inFlightWriteRequest._reject(error); - - stream._inFlightWriteRequest = undefined; - assert(stream._state === 'writable' || stream._state === 'erroring'); - WritableStreamDealWithRejection(stream, error); - } - - function WritableStreamFinishInFlightClose(stream) { - assert(stream._inFlightCloseRequest !== undefined); - - stream._inFlightCloseRequest._resolve(undefined); - - stream._inFlightCloseRequest = undefined; - var state = stream._state; - assert(state === 'writable' || state === 'erroring'); - - if (state === 'erroring') { - stream._storedError = undefined; - - if (stream._pendingAbortRequest !== undefined) { - stream._pendingAbortRequest._resolve(); - - stream._pendingAbortRequest = undefined; - } - } - - stream._state = 'closed'; - var writer = stream._writer; - - if (writer !== undefined) { - defaultWriterClosedPromiseResolve(writer); - } - - assert(stream._pendingAbortRequest === undefined, 'stream._pendingAbortRequest === undefined'); - assert(stream._storedError === undefined, 'stream._storedError === undefined'); - } - - function WritableStreamFinishInFlightCloseWithError(stream, error) { - assert(stream._inFlightCloseRequest !== undefined); - - stream._inFlightCloseRequest._reject(error); - - stream._inFlightCloseRequest = undefined; - assert(stream._state === 'writable' || stream._state === 'erroring'); - - if (stream._pendingAbortRequest !== undefined) { - stream._pendingAbortRequest._reject(error); - - stream._pendingAbortRequest = undefined; - } - - WritableStreamDealWithRejection(stream, error); - } - - function WritableStreamCloseQueuedOrInFlight(stream) { - if (stream._closeRequest === undefined && stream._inFlightCloseRequest === undefined) { - return false; - } - - return true; - } - - function WritableStreamHasOperationMarkedInFlight(stream) { - if (stream._inFlightWriteRequest === undefined && stream._inFlightCloseRequest === undefined) { - return false; - } - - return true; - } - - function WritableStreamMarkCloseRequestInFlight(stream) { - assert(stream._inFlightCloseRequest === undefined); - assert(stream._closeRequest !== undefined); - stream._inFlightCloseRequest = stream._closeRequest; - stream._closeRequest = undefined; - } - - function WritableStreamMarkFirstWriteRequestInFlight(stream) { - assert(stream._inFlightWriteRequest === undefined, 'there must be no pending write request'); - assert(stream._writeRequests.length !== 0, 'writeRequests must not be empty'); - stream._inFlightWriteRequest = stream._writeRequests.shift(); - } - - function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) { - assert(stream._state === 'errored', '_stream_.[[state]] is `"errored"`'); - - if (stream._closeRequest !== undefined) { - assert(stream._inFlightCloseRequest === undefined); - - stream._closeRequest._reject(stream._storedError); - - stream._closeRequest = undefined; - } - - var writer = stream._writer; - - if (writer !== undefined) { - defaultWriterClosedPromiseReject(writer, stream._storedError); - - writer._closedPromise.catch(function () {}); - } - } - - function WritableStreamUpdateBackpressure(stream, backpressure) { - assert(stream._state === 'writable'); - assert(WritableStreamCloseQueuedOrInFlight(stream) === false); - var writer = stream._writer; - - if (writer !== undefined && backpressure !== stream._backpressure) { - if (backpressure === true) { - defaultWriterReadyPromiseReset(writer); - } else { - assert(backpressure === false); - defaultWriterReadyPromiseResolve(writer); - } - } - - stream._backpressure = backpressure; - } - - var WritableStreamDefaultWriter = function () { - function WritableStreamDefaultWriter(stream) { - _classCallCheck(this, WritableStreamDefaultWriter); - - if (IsWritableStream(stream) === false) { - throw new TypeError('WritableStreamDefaultWriter can only be constructed with a WritableStream instance'); - } - - if (IsWritableStreamLocked(stream) === true) { - throw new TypeError('This stream has already been locked for exclusive writing by another writer'); - } - - this._ownerWritableStream = stream; - stream._writer = this; - var state = stream._state; - - if (state === 'writable') { - if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._backpressure === true) { - defaultWriterReadyPromiseInitialize(this); - } else { - defaultWriterReadyPromiseInitializeAsResolved(this); - } - - defaultWriterClosedPromiseInitialize(this); - } else if (state === 'erroring') { - defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError); - - this._readyPromise.catch(function () {}); - - defaultWriterClosedPromiseInitialize(this); - } else if (state === 'closed') { - defaultWriterReadyPromiseInitializeAsResolved(this); - defaultWriterClosedPromiseInitializeAsResolved(this); - } else { - assert(state === 'errored', 'state must be errored'); - var storedError = stream._storedError; - defaultWriterReadyPromiseInitializeAsRejected(this, storedError); - - this._readyPromise.catch(function () {}); - - defaultWriterClosedPromiseInitializeAsRejected(this, storedError); - - this._closedPromise.catch(function () {}); - } - } - - _createClass(WritableStreamDefaultWriter, [{ - key: 'abort', - value: function abort(reason) { - if (IsWritableStreamDefaultWriter(this) === false) { - return Promise.reject(defaultWriterBrandCheckException('abort')); - } - - if (this._ownerWritableStream === undefined) { - return Promise.reject(defaultWriterLockException('abort')); - } - - return WritableStreamDefaultWriterAbort(this, reason); - } - }, { - key: 'close', - value: function close() { - if (IsWritableStreamDefaultWriter(this) === false) { - return Promise.reject(defaultWriterBrandCheckException('close')); - } - - var stream = this._ownerWritableStream; - - if (stream === undefined) { - return Promise.reject(defaultWriterLockException('close')); - } - - if (WritableStreamCloseQueuedOrInFlight(stream) === true) { - return Promise.reject(new TypeError('cannot close an already-closing stream')); - } - - return WritableStreamDefaultWriterClose(this); - } - }, { - key: 'releaseLock', - value: function releaseLock() { - if (IsWritableStreamDefaultWriter(this) === false) { - throw defaultWriterBrandCheckException('releaseLock'); - } - - var stream = this._ownerWritableStream; - - if (stream === undefined) { - return; - } - - assert(stream._writer !== undefined); - WritableStreamDefaultWriterRelease(this); - } - }, { - key: 'write', - value: function write(chunk) { - if (IsWritableStreamDefaultWriter(this) === false) { - return Promise.reject(defaultWriterBrandCheckException('write')); - } - - if (this._ownerWritableStream === undefined) { - return Promise.reject(defaultWriterLockException('write to')); - } - - return WritableStreamDefaultWriterWrite(this, chunk); - } - }, { - key: 'closed', - get: function get() { - if (IsWritableStreamDefaultWriter(this) === false) { - return Promise.reject(defaultWriterBrandCheckException('closed')); - } - - return this._closedPromise; - } - }, { - key: 'desiredSize', - get: function get() { - if (IsWritableStreamDefaultWriter(this) === false) { - throw defaultWriterBrandCheckException('desiredSize'); - } - - if (this._ownerWritableStream === undefined) { - throw defaultWriterLockException('desiredSize'); - } - - return WritableStreamDefaultWriterGetDesiredSize(this); - } - }, { - key: 'ready', - get: function get() { - if (IsWritableStreamDefaultWriter(this) === false) { - return Promise.reject(defaultWriterBrandCheckException('ready')); - } - - return this._readyPromise; - } - }]); - - return WritableStreamDefaultWriter; - }(); - - function IsWritableStreamDefaultWriter(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) { - return false; - } - - return true; - } - - function WritableStreamDefaultWriterAbort(writer, reason) { - var stream = writer._ownerWritableStream; - assert(stream !== undefined); - return WritableStreamAbort(stream, reason); - } - - function WritableStreamDefaultWriterClose(writer) { - var stream = writer._ownerWritableStream; - assert(stream !== undefined); - var state = stream._state; - - if (state === 'closed' || state === 'errored') { - return Promise.reject(new TypeError('The stream (in ' + state + ' state) is not in the writable state and cannot be closed')); - } - - assert(state === 'writable' || state === 'erroring'); - assert(WritableStreamCloseQueuedOrInFlight(stream) === false); - var promise = new Promise(function (resolve, reject) { - var closeRequest = { - _resolve: resolve, - _reject: reject - }; - stream._closeRequest = closeRequest; - }); - - if (stream._backpressure === true && state === 'writable') { - defaultWriterReadyPromiseResolve(writer); - } - - WritableStreamDefaultControllerClose(stream._writableStreamController); - return promise; + pipeLoop().catch(rethrowAssertionErrorRejection); + function waitForWritesToFinish() { + var oldCurrentWrite = currentWrite; + return currentWrite.then(function () { + return oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : undefined; + }); + } + function isOrBecomesErrored(stream, promise, action) { + if (stream._state === 'errored') { + action(stream._storedError); + } else { + promise.catch(action).catch(rethrowAssertionErrorRejection); + } } - - function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) { - var stream = writer._ownerWritableStream; - assert(stream !== undefined); - var state = stream._state; - - if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { - return Promise.resolve(); - } - - if (state === 'errored') { - return Promise.reject(stream._storedError); - } - - assert(state === 'writable' || state === 'erroring'); - return WritableStreamDefaultWriterClose(writer); + function isOrBecomesClosed(stream, promise, action) { + if (stream._state === 'closed') { + action(); + } else { + promise.then(action).catch(rethrowAssertionErrorRejection); + } } - - function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) { - if (writer._closedPromiseState === 'pending') { - defaultWriterClosedPromiseReject(writer, error); - } else { - defaultWriterClosedPromiseResetToRejected(writer, error); - } - - writer._closedPromise.catch(function () {}); + function shutdownWithAction(action, originalIsError, originalError) { + if (shuttingDown === true) { + return; + } + shuttingDown = true; + if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) { + waitForWritesToFinish().then(doTheRest); + } else { + doTheRest(); + } + function doTheRest() { + action().then(function () { + return finalize(originalIsError, originalError); + }, function (newError) { + return finalize(true, newError); + }).catch(rethrowAssertionErrorRejection); + } } - - function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) { - if (writer._readyPromiseState === 'pending') { - defaultWriterReadyPromiseReject(writer, error); - } else { - defaultWriterReadyPromiseResetToRejected(writer, error); - } - - writer._readyPromise.catch(function () {}); + function shutdown(isError, error) { + if (shuttingDown === true) { + return; + } + shuttingDown = true; + if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) { + waitForWritesToFinish().then(function () { + return finalize(isError, error); + }).catch(rethrowAssertionErrorRejection); + } else { + finalize(isError, error); + } } - - function WritableStreamDefaultWriterGetDesiredSize(writer) { - var stream = writer._ownerWritableStream; - var state = stream._state; - - if (state === 'errored' || state === 'erroring') { - return null; - } - - if (state === 'closed') { - return 0; - } - - return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController); + function finalize(isError, error) { + WritableStreamDefaultWriterRelease(writer); + ReadableStreamReaderGenericRelease(reader); + if (signal !== undefined) { + signal.removeEventListener('abort', abortAlgorithm); + } + if (isError) { + reject(error); + } else { + resolve(undefined); + } } - - function WritableStreamDefaultWriterRelease(writer) { - var stream = writer._ownerWritableStream; - assert(stream !== undefined); - assert(stream._writer === writer); - var releasedError = new TypeError('Writer was released and can no longer be used to monitor the stream\'s closedness'); - WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError); - WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError); - stream._writer = undefined; - writer._ownerWritableStream = undefined; + }); +} +var ReadableStreamDefaultController = function () { + function ReadableStreamDefaultController() { + throw new TypeError(); + } + Object.defineProperty(ReadableStreamDefaultController.prototype, "desiredSize", { + get: function () { + if (IsReadableStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('desiredSize'); + } + return ReadableStreamDefaultControllerGetDesiredSize(this); + }, + enumerable: true, + configurable: true + }); + ReadableStreamDefaultController.prototype.close = function () { + if (IsReadableStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('close'); + } + if (ReadableStreamDefaultControllerCanCloseOrEnqueue(this) === false) { + throw new TypeError('The stream is not in a state that permits close'); + } + ReadableStreamDefaultControllerClose(this); + }; + ReadableStreamDefaultController.prototype.enqueue = function (chunk) { + if (IsReadableStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('enqueue'); + } + if (ReadableStreamDefaultControllerCanCloseOrEnqueue(this) === false) { + throw new TypeError('The stream is not in a state that permits enqueue'); + } + return ReadableStreamDefaultControllerEnqueue(this, chunk); + }; + ReadableStreamDefaultController.prototype.error = function (e) { + if (IsReadableStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('error'); + } + ReadableStreamDefaultControllerError(this, e); + }; + ReadableStreamDefaultController.prototype[CancelSteps] = function (reason) { + ResetQueue(this); + var result = this._cancelAlgorithm(reason); + ReadableStreamDefaultControllerClearAlgorithms(this); + return result; + }; + ReadableStreamDefaultController.prototype[PullSteps] = function () { + var stream = this._controlledReadableStream; + if (this._queue.length > 0) { + var chunk = DequeueValue(this); + if (this._closeRequested === true && this._queue.length === 0) { + ReadableStreamDefaultControllerClearAlgorithms(this); + ReadableStreamClose(stream); + } else { + ReadableStreamDefaultControllerCallPullIfNeeded(this); + } + return Promise.resolve(ReadableStreamCreateReadResult(chunk, false, stream._reader._forAuthorCode)); } - - function WritableStreamDefaultWriterWrite(writer, chunk) { - var stream = writer._ownerWritableStream; - assert(stream !== undefined); - var controller = stream._writableStreamController; - var chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk); - - if (stream !== writer._ownerWritableStream) { - return Promise.reject(defaultWriterLockException('write to')); - } - - var state = stream._state; - - if (state === 'errored') { - return Promise.reject(stream._storedError); - } - - if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { - return Promise.reject(new TypeError('The stream is closing or closed and cannot be written to')); - } - - if (state === 'erroring') { - return Promise.reject(stream._storedError); - } - - assert(state === 'writable'); - var promise = WritableStreamAddWriteRequest(stream); - WritableStreamDefaultControllerWrite(controller, chunk, chunkSize); - return promise; + var pendingPromise = ReadableStreamAddReadRequest(stream); + ReadableStreamDefaultControllerCallPullIfNeeded(this); + return pendingPromise; + }; + return ReadableStreamDefaultController; +}(); +function IsReadableStreamDefaultController(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableStream')) { + return false; + } + return true; +} +function ReadableStreamDefaultControllerCallPullIfNeeded(controller) { + var shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller); + if (shouldPull === false) { + return; + } + if (controller._pulling === true) { + controller._pullAgain = true; + return; + } + controller._pulling = true; + var pullPromise = controller._pullAlgorithm(); + pullPromise.then(function () { + controller._pulling = false; + if (controller._pullAgain === true) { + controller._pullAgain = false; + ReadableStreamDefaultControllerCallPullIfNeeded(controller); + } + }, function (e) { + ReadableStreamDefaultControllerError(controller, e); + }).catch(rethrowAssertionErrorRejection); +} +function ReadableStreamDefaultControllerShouldCallPull(controller) { + var stream = controller._controlledReadableStream; + if (ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) === false) { + return false; + } + if (controller._started === false) { + return false; + } + if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { + return true; + } + var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller); + if (desiredSize > 0) { + return true; + } + return false; +} +function ReadableStreamDefaultControllerClearAlgorithms(controller) { + controller._pullAlgorithm = undefined; + controller._cancelAlgorithm = undefined; + controller._strategySizeAlgorithm = undefined; +} +function ReadableStreamDefaultControllerClose(controller) { + var stream = controller._controlledReadableStream; + controller._closeRequested = true; + if (controller._queue.length === 0) { + ReadableStreamDefaultControllerClearAlgorithms(controller); + ReadableStreamClose(stream); + } +} +function ReadableStreamDefaultControllerEnqueue(controller, chunk) { + var stream = controller._controlledReadableStream; + if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { + ReadableStreamFulfillReadRequest(stream, chunk, false); + } else { + var chunkSize = void 0; + try { + chunkSize = controller._strategySizeAlgorithm(chunk); + } catch (chunkSizeE) { + ReadableStreamDefaultControllerError(controller, chunkSizeE); + throw chunkSizeE; } - - var WritableStreamDefaultController = function () { - function WritableStreamDefaultController(stream, underlyingSink, size, highWaterMark) { - _classCallCheck(this, WritableStreamDefaultController); - - if (IsWritableStream(stream) === false) { - throw new TypeError('WritableStreamDefaultController can only be constructed with a WritableStream instance'); - } - - if (stream._writableStreamController !== undefined) { - throw new TypeError('WritableStreamDefaultController instances can only be created by the WritableStream constructor'); - } - - this._controlledWritableStream = stream; - this._underlyingSink = underlyingSink; - this._queue = undefined; - this._queueTotalSize = undefined; - ResetQueue(this); - this._started = false; - var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark); - this._strategySize = normalizedStrategy.size; - this._strategyHWM = normalizedStrategy.highWaterMark; - var backpressure = WritableStreamDefaultControllerGetBackpressure(this); - WritableStreamUpdateBackpressure(stream, backpressure); - } - - _createClass(WritableStreamDefaultController, [{ - key: 'error', - value: function error(e) { - if (IsWritableStreamDefaultController(this) === false) { - throw new TypeError('WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController'); - } - - var state = this._controlledWritableStream._state; - - if (state !== 'writable') { - return; - } - - WritableStreamDefaultControllerError(this, e); - } - }, { - key: '__abortSteps', - value: function __abortSteps(reason) { - return PromiseInvokeOrNoop(this._underlyingSink, 'abort', [reason]); - } - }, { - key: '__errorSteps', - value: function __errorSteps() { - ResetQueue(this); - } - }, { - key: '__startSteps', - value: function __startSteps() { - var _this = this; - - var startResult = InvokeOrNoop(this._underlyingSink, 'start', [this]); - var stream = this._controlledWritableStream; - Promise.resolve(startResult).then(function () { - assert(stream._state === 'writable' || stream._state === 'erroring'); - _this._started = true; - WritableStreamDefaultControllerAdvanceQueueIfNeeded(_this); - }, function (r) { - assert(stream._state === 'writable' || stream._state === 'erroring'); - _this._started = true; - WritableStreamDealWithRejection(stream, r); - }).catch(rethrowAssertionErrorRejection); - } - }]); - - return WritableStreamDefaultController; - }(); - - function WritableStreamDefaultControllerClose(controller) { - EnqueueValueWithSize(controller, 'close', 0); - WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + try { + EnqueueValueWithSize(controller, chunk, chunkSize); + } catch (enqueueE) { + ReadableStreamDefaultControllerError(controller, enqueueE); + throw enqueueE; } - - function WritableStreamDefaultControllerGetChunkSize(controller, chunk) { - var strategySize = controller._strategySize; - - if (strategySize === undefined) { - return 1; - } - - try { - return strategySize(chunk); - } catch (chunkSizeE) { - WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE); - return 1; + } + ReadableStreamDefaultControllerCallPullIfNeeded(controller); +} +function ReadableStreamDefaultControllerError(controller, e) { + var stream = controller._controlledReadableStream; + if (stream._state !== 'readable') { + return; + } + ResetQueue(controller); + ReadableStreamDefaultControllerClearAlgorithms(controller); + ReadableStreamError(stream, e); +} +function ReadableStreamDefaultControllerGetDesiredSize(controller) { + var stream = controller._controlledReadableStream; + var state = stream._state; + if (state === 'errored') { + return null; + } + if (state === 'closed') { + return 0; + } + return controller._strategyHWM - controller._queueTotalSize; +} +function ReadableStreamDefaultControllerHasBackpressure(controller) { + if (ReadableStreamDefaultControllerShouldCallPull(controller) === true) { + return false; + } + return true; +} +function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) { + var state = controller._controlledReadableStream._state; + if (controller._closeRequested === false && state === 'readable') { + return true; + } + return false; +} +function SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) { + controller._controlledReadableStream = stream; + controller._queue = undefined; + controller._queueTotalSize = undefined; + ResetQueue(controller); + controller._started = false; + controller._closeRequested = false; + controller._pullAgain = false; + controller._pulling = false; + controller._strategySizeAlgorithm = sizeAlgorithm; + controller._strategyHWM = highWaterMark; + controller._pullAlgorithm = pullAlgorithm; + controller._cancelAlgorithm = cancelAlgorithm; + stream._readableStreamController = controller; + var startResult = startAlgorithm(); + Promise.resolve(startResult).then(function () { + controller._started = true; + ReadableStreamDefaultControllerCallPullIfNeeded(controller); + }, function (r) { + ReadableStreamDefaultControllerError(controller, r); + }).catch(rethrowAssertionErrorRejection); +} +function SetUpReadableStreamDefaultControllerFromUnderlyingSource(stream, underlyingSource, highWaterMark, sizeAlgorithm) { + var controller = Object.create(ReadableStreamDefaultController.prototype); + function startAlgorithm() { + return InvokeOrNoop(underlyingSource, 'start', [controller]); + } + var pullAlgorithm = CreateAlgorithmFromUnderlyingMethod(underlyingSource, 'pull', 0, [controller]); + var cancelAlgorithm = CreateAlgorithmFromUnderlyingMethod(underlyingSource, 'cancel', 1, []); + SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm); +} +function defaultControllerBrandCheckException(name) { + return new TypeError("ReadableStreamDefaultController.prototype." + name + " can only be used on a ReadableStreamDefaultController"); +} +function ReadableStreamTee(stream, cloneForBranch2) { + var reader = AcquireReadableStreamDefaultReader(stream); + var reading = false; + var canceled1 = false; + var canceled2 = false; + var reason1; + var reason2; + var branch1; + var branch2; + var resolveCancelPromise; + var cancelPromise = new Promise(function (resolve) { + resolveCancelPromise = resolve; + }); + function pullAlgorithm() { + if (reading === true) { + return Promise.resolve(); + } + reading = true; + var readPromise = ReadableStreamDefaultReaderRead(reader).then(function (result) { + reading = false; + var done = result.done; + if (done === true) { + if (canceled1 === false) { + ReadableStreamDefaultControllerClose(branch1._readableStreamController); + } + if (canceled2 === false) { + ReadableStreamDefaultControllerClose(branch2._readableStreamController); } + return; + } + var value = result.value; + var value1 = value; + var value2 = value; + if (canceled1 === false) { + ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, value1); + } + if (canceled2 === false) { + ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, value2); + } + }); + readPromise.catch(rethrowAssertionErrorRejection); + return Promise.resolve(); + } + function cancel1Algorithm(reason) { + canceled1 = true; + reason1 = reason; + if (canceled2 === true) { + var compositeReason = createArrayFromList([ + reason1, + reason2 + ]); + var cancelResult = ReadableStreamCancel(stream, compositeReason); + resolveCancelPromise(cancelResult); + } + return cancelPromise; + } + function cancel2Algorithm(reason) { + canceled2 = true; + reason2 = reason; + if (canceled1 === true) { + var compositeReason = createArrayFromList([ + reason1, + reason2 + ]); + var cancelResult = ReadableStreamCancel(stream, compositeReason); + resolveCancelPromise(cancelResult); + } + return cancelPromise; + } + function startAlgorithm() { + } + branch1 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel1Algorithm); + branch2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel2Algorithm); + reader._closedPromise.catch(function (r) { + ReadableStreamDefaultControllerError(branch1._readableStreamController, r); + ReadableStreamDefaultControllerError(branch2._readableStreamController, r); + }); + return [ + branch1, + branch2 + ]; +} +var NumberIsInteger = Number.isInteger || function (value) { + return typeof value === 'number' && isFinite(value) && Math.floor(value) === value; +}; +var ReadableStreamBYOBRequest = function () { + function ReadableStreamBYOBRequest() { + throw new TypeError('ReadableStreamBYOBRequest cannot be used directly'); + } + Object.defineProperty(ReadableStreamBYOBRequest.prototype, "view", { + get: function () { + if (IsReadableStreamBYOBRequest(this) === false) { + throw byobRequestBrandCheckException('view'); + } + return this._view; + }, + enumerable: true, + configurable: true + }); + ReadableStreamBYOBRequest.prototype.respond = function (bytesWritten) { + if (IsReadableStreamBYOBRequest(this) === false) { + throw byobRequestBrandCheckException('respond'); + } + if (this._associatedReadableByteStreamController === undefined) { + throw new TypeError('This BYOB request has been invalidated'); + } + if (IsDetachedBuffer(this._view.buffer) === true); + ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten); + }; + ReadableStreamBYOBRequest.prototype.respondWithNewView = function (view) { + if (IsReadableStreamBYOBRequest(this) === false) { + throw byobRequestBrandCheckException('respond'); + } + if (this._associatedReadableByteStreamController === undefined) { + throw new TypeError('This BYOB request has been invalidated'); + } + if (!ArrayBuffer.isView(view)) { + throw new TypeError('You can only respond with array buffer views'); + } + if (IsDetachedBuffer(view.buffer) === true); + ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view); + }; + return ReadableStreamBYOBRequest; +}(); +var ReadableByteStreamController = function () { + function ReadableByteStreamController() { + throw new TypeError('ReadableByteStreamController constructor cannot be used directly'); + } + Object.defineProperty(ReadableByteStreamController.prototype, "byobRequest", { + get: function () { + if (IsReadableByteStreamController(this) === false) { + throw byteStreamControllerBrandCheckException('byobRequest'); + } + if (this._byobRequest === undefined && this._pendingPullIntos.length > 0) { + var firstDescriptor = this._pendingPullIntos.peek(); + var view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled); + var byobRequest = Object.create(ReadableStreamBYOBRequest.prototype); + SetUpReadableStreamBYOBRequest(byobRequest, this, view); + this._byobRequest = byobRequest; + } + return this._byobRequest; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(ReadableByteStreamController.prototype, "desiredSize", { + get: function () { + if (IsReadableByteStreamController(this) === false) { + throw byteStreamControllerBrandCheckException('desiredSize'); + } + return ReadableByteStreamControllerGetDesiredSize(this); + }, + enumerable: true, + configurable: true + }); + ReadableByteStreamController.prototype.close = function () { + if (IsReadableByteStreamController(this) === false) { + throw byteStreamControllerBrandCheckException('close'); + } + if (this._closeRequested === true) { + throw new TypeError('The stream has already been closed; do not close it again!'); + } + var state = this._controlledReadableByteStream._state; + if (state !== 'readable') { + throw new TypeError("The stream (in " + state + " state) is not in the readable state and cannot be closed"); + } + ReadableByteStreamControllerClose(this); + }; + ReadableByteStreamController.prototype.enqueue = function (chunk) { + if (IsReadableByteStreamController(this) === false) { + throw byteStreamControllerBrandCheckException('enqueue'); + } + if (this._closeRequested === true) { + throw new TypeError('stream is closed or draining'); + } + var state = this._controlledReadableByteStream._state; + if (state !== 'readable') { + throw new TypeError("The stream (in " + state + " state) is not in the readable state and cannot be enqueued to"); + } + if (!ArrayBuffer.isView(chunk)) { + throw new TypeError('You can only enqueue array buffer views when using a ReadableByteStreamController'); + } + if (IsDetachedBuffer(chunk.buffer) === true); + ReadableByteStreamControllerEnqueue(this, chunk); + }; + ReadableByteStreamController.prototype.error = function (e) { + if (IsReadableByteStreamController(this) === false) { + throw byteStreamControllerBrandCheckException('error'); + } + ReadableByteStreamControllerError(this, e); + }; + ReadableByteStreamController.prototype[CancelSteps] = function (reason) { + if (this._pendingPullIntos.length > 0) { + var firstDescriptor = this._pendingPullIntos.peek(); + firstDescriptor.bytesFilled = 0; + } + ResetQueue(this); + var result = this._cancelAlgorithm(reason); + ReadableByteStreamControllerClearAlgorithms(this); + return result; + }; + ReadableByteStreamController.prototype[PullSteps] = function () { + var stream = this._controlledReadableByteStream; + if (this._queueTotalSize > 0) { + var entry = this._queue.shift(); + this._queueTotalSize -= entry.byteLength; + ReadableByteStreamControllerHandleQueueDrain(this); + var view = void 0; + try { + view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength); + } catch (viewE) { + return Promise.reject(viewE); + } + return Promise.resolve(ReadableStreamCreateReadResult(view, false, stream._reader._forAuthorCode)); + } + var autoAllocateChunkSize = this._autoAllocateChunkSize; + if (autoAllocateChunkSize !== undefined) { + var buffer = void 0; + try { + buffer = new ArrayBuffer(autoAllocateChunkSize); + } catch (bufferE) { + return Promise.reject(bufferE); + } + var pullIntoDescriptor = { + buffer: buffer, + byteOffset: 0, + byteLength: autoAllocateChunkSize, + bytesFilled: 0, + elementSize: 1, + ctor: Uint8Array, + readerType: 'default' + }; + this._pendingPullIntos.push(pullIntoDescriptor); + } + var promise = ReadableStreamAddReadRequest(stream); + ReadableByteStreamControllerCallPullIfNeeded(this); + return promise; + }; + return ReadableByteStreamController; +}(); +function IsReadableByteStreamController(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableByteStream')) { + return false; + } + return true; +} +function IsReadableStreamBYOBRequest(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) { + return false; + } + return true; +} +function ReadableByteStreamControllerCallPullIfNeeded(controller) { + var shouldPull = ReadableByteStreamControllerShouldCallPull(controller); + if (shouldPull === false) { + return; + } + if (controller._pulling === true) { + controller._pullAgain = true; + return; + } + controller._pulling = true; + var pullPromise = controller._pullAlgorithm(); + pullPromise.then(function () { + controller._pulling = false; + if (controller._pullAgain === true) { + controller._pullAgain = false; + ReadableByteStreamControllerCallPullIfNeeded(controller); + } + }, function (e) { + ReadableByteStreamControllerError(controller, e); + }).catch(rethrowAssertionErrorRejection); +} +function ReadableByteStreamControllerClearPendingPullIntos(controller) { + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + controller._pendingPullIntos = new SimpleQueue(); +} +function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) { + var done = false; + if (stream._state === 'closed') { + done = true; + } + var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); + if (pullIntoDescriptor.readerType === 'default') { + ReadableStreamFulfillReadRequest(stream, filledView, done); + } else { + ReadableStreamFulfillReadIntoRequest(stream, filledView, done); + } +} +function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) { + var bytesFilled = pullIntoDescriptor.bytesFilled; + var elementSize = pullIntoDescriptor.elementSize; + return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize); +} +function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) { + controller._queue.push({ + buffer: buffer, + byteOffset: byteOffset, + byteLength: byteLength + }); + controller._queueTotalSize += byteLength; +} +function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) { + var elementSize = pullIntoDescriptor.elementSize; + var currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize; + var maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled); + var maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy; + var maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize; + var totalBytesToCopyRemaining = maxBytesToCopy; + var ready = false; + if (maxAlignedBytes > currentAlignedBytes) { + totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled; + ready = true; + } + var queue = controller._queue; + while (totalBytesToCopyRemaining > 0) { + var headOfQueue = queue.peek(); + var bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength); + var destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; + ArrayBufferCopy(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy); + if (headOfQueue.byteLength === bytesToCopy) { + queue.shift(); + } else { + headOfQueue.byteOffset += bytesToCopy; + headOfQueue.byteLength -= bytesToCopy; } - - function WritableStreamDefaultControllerGetDesiredSize(controller) { - return controller._strategyHWM - controller._queueTotalSize; + controller._queueTotalSize -= bytesToCopy; + ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor); + totalBytesToCopyRemaining -= bytesToCopy; + } + return ready; +} +function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) { + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + pullIntoDescriptor.bytesFilled += size; +} +function ReadableByteStreamControllerHandleQueueDrain(controller) { + if (controller._queueTotalSize === 0 && controller._closeRequested === true) { + ReadableByteStreamControllerClearAlgorithms(controller); + ReadableStreamClose(controller._controlledReadableByteStream); + } else { + ReadableByteStreamControllerCallPullIfNeeded(controller); + } +} +function ReadableByteStreamControllerInvalidateBYOBRequest(controller) { + if (controller._byobRequest === undefined) { + return; + } + controller._byobRequest._associatedReadableByteStreamController = undefined; + controller._byobRequest._view = undefined; + controller._byobRequest = undefined; +} +function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) { + while (controller._pendingPullIntos.length > 0) { + if (controller._queueTotalSize === 0) { + return; } - - function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) { - var writeRecord = { - chunk: chunk - }; - - try { - EnqueueValueWithSize(controller, writeRecord, chunkSize); - } catch (enqueueE) { - WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE); - return; - } - - var stream = controller._controlledWritableStream; - - if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._state === 'writable') { - var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); - WritableStreamUpdateBackpressure(stream, backpressure); - } - - WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + var pullIntoDescriptor = controller._pendingPullIntos.peek(); + if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { + ReadableByteStreamControllerShiftPendingPullInto(controller); + ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor); } - - function IsWritableStreamDefaultController(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSink')) { - return false; - } - - return true; + } +} +function ReadableByteStreamControllerPullInto(controller, view) { + var stream = controller._controlledReadableByteStream; + var elementSize = 1; + if (view.constructor !== DataView) { + elementSize = view.constructor.BYTES_PER_ELEMENT; + } + var ctor = view.constructor; + var buffer = TransferArrayBuffer(view.buffer); + var pullIntoDescriptor = { + buffer: buffer, + byteOffset: view.byteOffset, + byteLength: view.byteLength, + bytesFilled: 0, + elementSize: elementSize, + ctor: ctor, + readerType: 'byob' + }; + if (controller._pendingPullIntos.length > 0) { + controller._pendingPullIntos.push(pullIntoDescriptor); + return ReadableStreamAddReadIntoRequest(stream); + } + if (stream._state === 'closed') { + var emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0); + return Promise.resolve(ReadableStreamCreateReadResult(emptyView, true, stream._reader._forAuthorCode)); + } + if (controller._queueTotalSize > 0) { + if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { + var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); + ReadableByteStreamControllerHandleQueueDrain(controller); + return Promise.resolve(ReadableStreamCreateReadResult(filledView, false, stream._reader._forAuthorCode)); } - - function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) { - var stream = controller._controlledWritableStream; - - if (controller._started === false) { - return; - } - - if (stream._inFlightWriteRequest !== undefined) { - return; - } - - var state = stream._state; - - if (state === 'closed' || state === 'errored') { - return; - } - - if (state === 'erroring') { - WritableStreamFinishErroring(stream); - return; - } - - if (controller._queue.length === 0) { - return; - } - - var writeRecord = PeekQueueValue(controller); - - if (writeRecord === 'close') { - WritableStreamDefaultControllerProcessClose(controller); - } else { - WritableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk); - } + if (controller._closeRequested === true) { + var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); + ReadableByteStreamControllerError(controller, e); + return Promise.reject(e); } - - function WritableStreamDefaultControllerErrorIfNeeded(controller, error) { - if (controller._controlledWritableStream._state === 'writable') { - WritableStreamDefaultControllerError(controller, error); - } + } + controller._pendingPullIntos.push(pullIntoDescriptor); + var promise = ReadableStreamAddReadIntoRequest(stream); + ReadableByteStreamControllerCallPullIfNeeded(controller); + return promise; +} +function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) { + firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer); + var stream = controller._controlledReadableByteStream; + if (ReadableStreamHasBYOBReader(stream) === true) { + while (ReadableStreamGetNumReadIntoRequests(stream) > 0) { + var pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller); + ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor); } - - function WritableStreamDefaultControllerProcessClose(controller) { - var stream = controller._controlledWritableStream; - WritableStreamMarkCloseRequestInFlight(stream); - DequeueValue(controller); - assert(controller._queue.length === 0, 'queue must be empty once the final write record is dequeued'); - var sinkClosePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'close', []); - sinkClosePromise.then(function () { - WritableStreamFinishInFlightClose(stream); - }, function (reason) { - WritableStreamFinishInFlightCloseWithError(stream, reason); - }).catch(rethrowAssertionErrorRejection); + } +} +function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) { + if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) { + throw new RangeError('bytesWritten out of range'); + } + ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor); + if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) { + return; + } + ReadableByteStreamControllerShiftPendingPullInto(controller); + var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize; + if (remainderSize > 0) { + var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; + var remainder = pullIntoDescriptor.buffer.slice(end - remainderSize, end); + ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength); + } + pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); + pullIntoDescriptor.bytesFilled -= remainderSize; + ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor); + ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); +} +function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) { + var firstDescriptor = controller._pendingPullIntos.peek(); + var stream = controller._controlledReadableByteStream; + if (stream._state === 'closed') { + if (bytesWritten !== 0) { + throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream'); + } + ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor); + } else { + ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor); + } + ReadableByteStreamControllerCallPullIfNeeded(controller); +} +function ReadableByteStreamControllerShiftPendingPullInto(controller) { + var descriptor = controller._pendingPullIntos.shift(); + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + return descriptor; +} +function ReadableByteStreamControllerShouldCallPull(controller) { + var stream = controller._controlledReadableByteStream; + if (stream._state !== 'readable') { + return false; + } + if (controller._closeRequested === true) { + return false; + } + if (controller._started === false) { + return false; + } + if (ReadableStreamHasDefaultReader(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { + return true; + } + if (ReadableStreamHasBYOBReader(stream) === true && ReadableStreamGetNumReadIntoRequests(stream) > 0) { + return true; + } + var desiredSize = ReadableByteStreamControllerGetDesiredSize(controller); + if (desiredSize > 0) { + return true; + } + return false; +} +function ReadableByteStreamControllerClearAlgorithms(controller) { + controller._pullAlgorithm = undefined; + controller._cancelAlgorithm = undefined; +} +function ReadableByteStreamControllerClose(controller) { + var stream = controller._controlledReadableByteStream; + if (controller._queueTotalSize > 0) { + controller._closeRequested = true; + return; + } + if (controller._pendingPullIntos.length > 0) { + var firstPendingPullInto = controller._pendingPullIntos.peek(); + if (firstPendingPullInto.bytesFilled > 0) { + var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); + ReadableByteStreamControllerError(controller, e); + throw e; } - - function WritableStreamDefaultControllerProcessWrite(controller, chunk) { - var stream = controller._controlledWritableStream; - WritableStreamMarkFirstWriteRequestInFlight(stream); - var sinkWritePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'write', [chunk, controller]); - sinkWritePromise.then(function () { - WritableStreamFinishInFlightWrite(stream); - var state = stream._state; - assert(state === 'writable' || state === 'erroring'); - DequeueValue(controller); - - if (WritableStreamCloseQueuedOrInFlight(stream) === false && state === 'writable') { - var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); - WritableStreamUpdateBackpressure(stream, backpressure); - } - - WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); - }, function (reason) { - WritableStreamFinishInFlightWriteWithError(stream, reason); - }).catch(rethrowAssertionErrorRejection); + } + ReadableByteStreamControllerClearAlgorithms(controller); + ReadableStreamClose(stream); +} +function ReadableByteStreamControllerEnqueue(controller, chunk) { + var stream = controller._controlledReadableByteStream; + var buffer = chunk.buffer; + var byteOffset = chunk.byteOffset; + var byteLength = chunk.byteLength; + var transferredBuffer = TransferArrayBuffer(buffer); + if (ReadableStreamHasDefaultReader(stream) === true) { + if (ReadableStreamGetNumReadRequests(stream) === 0) { + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); + } else { + var transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength); + ReadableStreamFulfillReadRequest(stream, transferredView, false); + } + } else if (ReadableStreamHasBYOBReader(stream) === true) { + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); + ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); + } else { + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); + } + ReadableByteStreamControllerCallPullIfNeeded(controller); +} +function ReadableByteStreamControllerError(controller, e) { + var stream = controller._controlledReadableByteStream; + if (stream._state !== 'readable') { + return; + } + ReadableByteStreamControllerClearPendingPullIntos(controller); + ResetQueue(controller); + ReadableByteStreamControllerClearAlgorithms(controller); + ReadableStreamError(stream, e); +} +function ReadableByteStreamControllerGetDesiredSize(controller) { + var stream = controller._controlledReadableByteStream; + var state = stream._state; + if (state === 'errored') { + return null; + } + if (state === 'closed') { + return 0; + } + return controller._strategyHWM - controller._queueTotalSize; +} +function ReadableByteStreamControllerRespond(controller, bytesWritten) { + bytesWritten = Number(bytesWritten); + if (IsFiniteNonNegativeNumber(bytesWritten) === false) { + throw new RangeError('bytesWritten must be a finite'); + } + ReadableByteStreamControllerRespondInternal(controller, bytesWritten); +} +function ReadableByteStreamControllerRespondWithNewView(controller, view) { + var firstDescriptor = controller._pendingPullIntos.peek(); + if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) { + throw new RangeError('The region specified by view does not match byobRequest'); + } + if (firstDescriptor.byteLength !== view.byteLength) { + throw new RangeError('The buffer of view has different capacity than byobRequest'); + } + firstDescriptor.buffer = view.buffer; + ReadableByteStreamControllerRespondInternal(controller, view.byteLength); +} +function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) { + controller._controlledReadableByteStream = stream; + controller._pullAgain = false; + controller._pulling = false; + controller._byobRequest = undefined; + controller._queue = controller._queueTotalSize = undefined; + ResetQueue(controller); + controller._closeRequested = false; + controller._started = false; + controller._strategyHWM = ValidateAndNormalizeHighWaterMark(highWaterMark); + controller._pullAlgorithm = pullAlgorithm; + controller._cancelAlgorithm = cancelAlgorithm; + controller._autoAllocateChunkSize = autoAllocateChunkSize; + controller._pendingPullIntos = new SimpleQueue(); + stream._readableStreamController = controller; + var startResult = startAlgorithm(); + Promise.resolve(startResult).then(function () { + controller._started = true; + ReadableByteStreamControllerCallPullIfNeeded(controller); + }, function (r) { + ReadableByteStreamControllerError(controller, r); + }).catch(rethrowAssertionErrorRejection); +} +function SetUpReadableByteStreamControllerFromUnderlyingSource(stream, underlyingByteSource, highWaterMark) { + var controller = Object.create(ReadableByteStreamController.prototype); + function startAlgorithm() { + return InvokeOrNoop(underlyingByteSource, 'start', [controller]); + } + var pullAlgorithm = CreateAlgorithmFromUnderlyingMethod(underlyingByteSource, 'pull', 0, [controller]); + var cancelAlgorithm = CreateAlgorithmFromUnderlyingMethod(underlyingByteSource, 'cancel', 1, []); + var autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize; + if (autoAllocateChunkSize !== undefined) { + autoAllocateChunkSize = Number(autoAllocateChunkSize); + if (NumberIsInteger(autoAllocateChunkSize) === false || autoAllocateChunkSize <= 0) { + throw new RangeError('autoAllocateChunkSize must be a positive integer'); } - - function WritableStreamDefaultControllerGetBackpressure(controller) { - var desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller); - return desiredSize <= 0; + } + SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize); +} +function SetUpReadableStreamBYOBRequest(request, controller, view) { + request._associatedReadableByteStreamController = controller; + request._view = view; +} +function byobRequestBrandCheckException(name) { + return new TypeError("ReadableStreamBYOBRequest.prototype." + name + " can only be used on a ReadableStreamBYOBRequest"); +} +function byteStreamControllerBrandCheckException(name) { + return new TypeError("ReadableByteStreamController.prototype." + name + " can only be used on a ReadableByteStreamController"); +} +function AcquireReadableStreamBYOBReader(stream, forAuthorCode) { + if (forAuthorCode === void 0) { + forAuthorCode = false; + } + var reader = new ReadableStreamBYOBReader(stream); + reader._forAuthorCode = forAuthorCode; + return reader; +} +function ReadableStreamAddReadIntoRequest(stream) { + var promise = new Promise(function (resolve, reject) { + var readIntoRequest = { + _resolve: resolve, + _reject: reject + }; + stream._reader._readIntoRequests.push(readIntoRequest); + }); + return promise; +} +function ReadableStreamFulfillReadIntoRequest(stream, chunk, done) { + var reader = stream._reader; + var readIntoRequest = reader._readIntoRequests.shift(); + readIntoRequest._resolve(ReadableStreamCreateReadResult(chunk, done, reader._forAuthorCode)); +} +function ReadableStreamGetNumReadIntoRequests(stream) { + return stream._reader._readIntoRequests.length; +} +function ReadableStreamHasBYOBReader(stream) { + var reader = stream._reader; + if (reader === undefined) { + return false; + } + if (!IsReadableStreamBYOBReader(reader)) { + return false; + } + return true; +} +var ReadableStreamBYOBReader = function () { + function ReadableStreamBYOBReader(stream) { + if (!IsReadableStream(stream)) { + throw new TypeError('ReadableStreamBYOBReader can only be constructed with a ReadableStream instance given a ' + 'byte source'); } - - function WritableStreamDefaultControllerError(controller, error) { - var stream = controller._controlledWritableStream; - assert(stream._state === 'writable'); - WritableStreamStartErroring(stream, error); + if (IsReadableByteStreamController(stream._readableStreamController) === false) { + throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' + 'source'); } - - function streamBrandCheckException(name) { - return new TypeError('WritableStream.prototype.' + name + ' can only be used on a WritableStream'); + if (IsReadableStreamLocked(stream)) { + throw new TypeError('This stream has already been locked for exclusive reading by another reader'); } - - function defaultWriterBrandCheckException(name) { - return new TypeError('WritableStreamDefaultWriter.prototype.' + name + ' can only be used on a WritableStreamDefaultWriter'); + ReadableStreamReaderGenericInitialize(this, stream); + this._readIntoRequests = new SimpleQueue(); + } + Object.defineProperty(ReadableStreamBYOBReader.prototype, "closed", { + get: function () { + if (!IsReadableStreamBYOBReader(this)) { + return Promise.reject(byobReaderBrandCheckException('closed')); + } + return this._closedPromise; + }, + enumerable: true, + configurable: true + }); + ReadableStreamBYOBReader.prototype.cancel = function (reason) { + if (!IsReadableStreamBYOBReader(this)) { + return Promise.reject(byobReaderBrandCheckException('cancel')); + } + if (this._ownerReadableStream === undefined) { + return Promise.reject(readerLockException('cancel')); + } + return ReadableStreamReaderGenericCancel(this, reason); + }; + ReadableStreamBYOBReader.prototype.read = function (view) { + if (!IsReadableStreamBYOBReader(this)) { + return Promise.reject(byobReaderBrandCheckException('read')); + } + if (this._ownerReadableStream === undefined) { + return Promise.reject(readerLockException('read from')); + } + if (!ArrayBuffer.isView(view)) { + return Promise.reject(new TypeError('view must be an array buffer view')); + } + if (IsDetachedBuffer(view.buffer) === true); + if (view.byteLength === 0) { + return Promise.reject(new TypeError('view must have non-zero byteLength')); + } + return ReadableStreamBYOBReaderRead(this, view); + }; + ReadableStreamBYOBReader.prototype.releaseLock = function () { + if (!IsReadableStreamBYOBReader(this)) { + throw byobReaderBrandCheckException('releaseLock'); + } + if (this._ownerReadableStream === undefined) { + return; + } + if (this._readIntoRequests.length > 0) { + throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled'); + } + ReadableStreamReaderGenericRelease(this); + }; + return ReadableStreamBYOBReader; +}(); +function IsReadableStreamBYOBReader(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) { + return false; + } + return true; +} +function ReadableStreamBYOBReaderRead(reader, view) { + var stream = reader._ownerReadableStream; + stream._disturbed = true; + if (stream._state === 'errored') { + return Promise.reject(stream._storedError); + } + return ReadableByteStreamControllerPullInto(stream._readableStreamController, view); +} +function byobReaderBrandCheckException(name) { + return new TypeError("ReadableStreamBYOBReader.prototype." + name + " can only be used on a ReadableStreamBYOBReader"); +} +var ReadableStream = function () { + function ReadableStream(underlyingSource, strategy) { + if (underlyingSource === void 0) { + underlyingSource = {}; + } + if (strategy === void 0) { + strategy = {}; + } + InitializeReadableStream(this); + var size = strategy.size; + var highWaterMark = strategy.highWaterMark; + var type = underlyingSource.type; + var typeString = String(type); + if (typeString === 'bytes') { + if (size !== undefined) { + throw new RangeError('The strategy for a byte stream cannot have a size function'); + } + if (highWaterMark === undefined) { + highWaterMark = 0; + } + highWaterMark = ValidateAndNormalizeHighWaterMark(highWaterMark); + SetUpReadableByteStreamControllerFromUnderlyingSource(this, underlyingSource, highWaterMark); + } else if (type === undefined) { + var sizeAlgorithm = MakeSizeAlgorithmFromSizeFunction(size); + if (highWaterMark === undefined) { + highWaterMark = 1; + } + highWaterMark = ValidateAndNormalizeHighWaterMark(highWaterMark); + SetUpReadableStreamDefaultControllerFromUnderlyingSource(this, underlyingSource, highWaterMark, sizeAlgorithm); + } else { + throw new RangeError('Invalid type is specified'); } + } + Object.defineProperty(ReadableStream.prototype, "locked", { + get: function () { + if (IsReadableStream(this) === false) { + throw streamBrandCheckException$1('locked'); + } + return IsReadableStreamLocked(this); + }, + enumerable: true, + configurable: true + }); + ReadableStream.prototype.cancel = function (reason) { + if (IsReadableStream(this) === false) { + return Promise.reject(streamBrandCheckException$1('cancel')); + } + if (IsReadableStreamLocked(this) === true) { + return Promise.reject(new TypeError('Cannot cancel a stream that already has a reader')); + } + return ReadableStreamCancel(this, reason); + }; + ReadableStream.prototype.getReader = function (_a) { + var mode = (_a === void 0 ? {} : _a).mode; + if (IsReadableStream(this) === false) { + throw streamBrandCheckException$1('getReader'); + } + if (mode === undefined) { + return AcquireReadableStreamDefaultReader(this, true); + } + mode = String(mode); + if (mode === 'byob') { + return AcquireReadableStreamBYOBReader(this, true); + } + throw new RangeError('Invalid mode is specified'); + }; + ReadableStream.prototype.pipeThrough = function (_a, _b) { + var writable = _a.writable, readable = _a.readable; + var _c = _b === void 0 ? {} : _b, preventClose = _c.preventClose, preventAbort = _c.preventAbort, preventCancel = _c.preventCancel, signal = _c.signal; + if (IsReadableStream(this) === false) { + throw streamBrandCheckException$1('pipeThrough'); + } + if (IsWritableStream(writable) === false) { + throw new TypeError('writable argument to pipeThrough must be a WritableStream'); + } + if (IsReadableStream(readable) === false) { + throw new TypeError('readable argument to pipeThrough must be a ReadableStream'); + } + preventClose = Boolean(preventClose); + preventAbort = Boolean(preventAbort); + preventCancel = Boolean(preventCancel); + if (signal !== undefined && !isAbortSignal(signal)) { + throw new TypeError('ReadableStream.prototype.pipeThrough\'s signal option must be an AbortSignal'); + } + if (IsReadableStreamLocked(this) === true) { + throw new TypeError('ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream'); + } + if (IsWritableStreamLocked(writable) === true) { + throw new TypeError('ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream'); + } + var promise = ReadableStreamPipeTo(this, writable, preventClose, preventAbort, preventCancel, signal); + promise.catch(noop); + return readable; + }; + ReadableStream.prototype.pipeTo = function (dest, _a) { + var _b = _a === void 0 ? {} : _a, preventClose = _b.preventClose, preventAbort = _b.preventAbort, preventCancel = _b.preventCancel, signal = _b.signal; + if (IsReadableStream(this) === false) { + return Promise.reject(streamBrandCheckException$1('pipeTo')); + } + if (IsWritableStream(dest) === false) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo\'s first argument must be a WritableStream')); + } + preventClose = Boolean(preventClose); + preventAbort = Boolean(preventAbort); + preventCancel = Boolean(preventCancel); + if (signal !== undefined && !isAbortSignal(signal)) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo\'s signal option must be an AbortSignal')); + } + if (IsReadableStreamLocked(this) === true) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream')); + } + if (IsWritableStreamLocked(dest) === true) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream')); + } + return ReadableStreamPipeTo(this, dest, preventClose, preventAbort, preventCancel, signal); + }; + ReadableStream.prototype.tee = function () { + if (IsReadableStream(this) === false) { + throw streamBrandCheckException$1('tee'); + } + var branches = ReadableStreamTee(this); + return createArrayFromList(branches); + }; + ReadableStream.prototype.getIterator = function (_a) { + var _b = (_a === void 0 ? {} : _a).preventCancel, preventCancel = _b === void 0 ? false : _b; + if (IsReadableStream(this) === false) { + throw streamBrandCheckException$1('getIterator'); + } + return AcquireReadableStreamAsyncIterator(this, preventCancel); + }; + return ReadableStream; +}(); +if (typeof SymbolPolyfill.asyncIterator === 'symbol') { + Object.defineProperty(ReadableStream.prototype, SymbolPolyfill.asyncIterator, { + value: ReadableStream.prototype.getIterator, + enumerable: false, + writable: true, + configurable: true + }); +} +function CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) { + if (highWaterMark === void 0) { + highWaterMark = 1; + } + if (sizeAlgorithm === void 0) { + sizeAlgorithm = function () { + return 1; + }; + } + var stream = Object.create(ReadableStream.prototype); + InitializeReadableStream(stream); + var controller = Object.create(ReadableStreamDefaultController.prototype); + SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm); + return stream; +} +function InitializeReadableStream(stream) { + stream._state = 'readable'; + stream._reader = undefined; + stream._storedError = undefined; + stream._disturbed = false; +} +function IsReadableStream(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) { + return false; + } + return true; +} +function IsReadableStreamLocked(stream) { + if (stream._reader === undefined) { + return false; + } + return true; +} +function ReadableStreamCancel(stream, reason) { + stream._disturbed = true; + if (stream._state === 'closed') { + return Promise.resolve(undefined); + } + if (stream._state === 'errored') { + return Promise.reject(stream._storedError); + } + ReadableStreamClose(stream); + var sourceCancelPromise = stream._readableStreamController[CancelSteps](reason); + return sourceCancelPromise.then(function () { + return undefined; + }); +} +function ReadableStreamClose(stream) { + stream._state = 'closed'; + var reader = stream._reader; + if (reader === undefined) { + return; + } + if (IsReadableStreamDefaultReader(reader)) { + reader._readRequests.forEach(function (readRequest) { + readRequest._resolve(ReadableStreamCreateReadResult(undefined, true, reader._forAuthorCode)); + }); + reader._readRequests = new SimpleQueue(); + } + defaultReaderClosedPromiseResolve(reader); +} +function ReadableStreamError(stream, e) { + stream._state = 'errored'; + stream._storedError = e; + var reader = stream._reader; + if (reader === undefined) { + return; + } + if (IsReadableStreamDefaultReader(reader)) { + reader._readRequests.forEach(function (readRequest) { + readRequest._reject(e); + }); + reader._readRequests = new SimpleQueue(); + } else { + reader._readIntoRequests.forEach(function (readIntoRequest) { + readIntoRequest._reject(e); + }); + reader._readIntoRequests = new SimpleQueue(); + } + defaultReaderClosedPromiseReject(reader, e); +} +function isAbortSignal(value) { + if (typeof value !== 'object' || value === null) { + return false; + } + var aborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted').get; + try { + aborted.call(value); + return true; + } catch (e) { + return false; + } +} +function streamBrandCheckException$1(name) { + return new TypeError("ReadableStream.prototype." + name + " can only be used on a ReadableStream"); +} +var ByteLengthQueuingStrategy = function () { + function ByteLengthQueuingStrategy(_a) { + var highWaterMark = _a.highWaterMark; + this.highWaterMark = highWaterMark; + } + ByteLengthQueuingStrategy.prototype.size = function (chunk) { + return chunk.byteLength; + }; + return ByteLengthQueuingStrategy; +}(); +var CountQueuingStrategy = function () { + function CountQueuingStrategy(_a) { + var highWaterMark = _a.highWaterMark; + this.highWaterMark = highWaterMark; + } + CountQueuingStrategy.prototype.size = function () { + return 1; + }; + return CountQueuingStrategy; +}(); +var TransformStream = function () { + function TransformStream(transformer, writableStrategy, readableStrategy) { + if (transformer === void 0) { + transformer = {}; + } + if (writableStrategy === void 0) { + writableStrategy = {}; + } + if (readableStrategy === void 0) { + readableStrategy = {}; + } + var writableSizeFunction = writableStrategy.size; + var writableHighWaterMark = writableStrategy.highWaterMark; + var readableSizeFunction = readableStrategy.size; + var readableHighWaterMark = readableStrategy.highWaterMark; + var writableType = transformer.writableType; + if (writableType !== undefined) { + throw new RangeError('Invalid writable type specified'); + } + var writableSizeAlgorithm = MakeSizeAlgorithmFromSizeFunction(writableSizeFunction); + if (writableHighWaterMark === undefined) { + writableHighWaterMark = 1; + } + writableHighWaterMark = ValidateAndNormalizeHighWaterMark(writableHighWaterMark); + var readableType = transformer.readableType; + if (readableType !== undefined) { + throw new RangeError('Invalid readable type specified'); + } + var readableSizeAlgorithm = MakeSizeAlgorithmFromSizeFunction(readableSizeFunction); + if (readableHighWaterMark === undefined) { + readableHighWaterMark = 0; + } + readableHighWaterMark = ValidateAndNormalizeHighWaterMark(readableHighWaterMark); + var startPromise_resolve; + var startPromise = new Promise(function (resolve) { + startPromise_resolve = resolve; + }); + InitializeTransformStream(this, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm); + SetUpTransformStreamDefaultControllerFromTransformer(this, transformer); + var startResult = InvokeOrNoop(transformer, 'start', [this._transformStreamController]); + startPromise_resolve(startResult); + } + Object.defineProperty(TransformStream.prototype, "readable", { + get: function () { + if (IsTransformStream(this) === false) { + throw streamBrandCheckException$2('readable'); + } + return this._readable; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(TransformStream.prototype, "writable", { + get: function () { + if (IsTransformStream(this) === false) { + throw streamBrandCheckException$2('writable'); + } + return this._writable; + }, + enumerable: true, + configurable: true + }); + return TransformStream; +}(); +function InitializeTransformStream(stream, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm) { + function startAlgorithm() { + return startPromise; + } + function writeAlgorithm(chunk) { + return TransformStreamDefaultSinkWriteAlgorithm(stream, chunk); + } + function abortAlgorithm(reason) { + return TransformStreamDefaultSinkAbortAlgorithm(stream, reason); + } + function closeAlgorithm() { + return TransformStreamDefaultSinkCloseAlgorithm(stream); + } + stream._writable = CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, writableHighWaterMark, writableSizeAlgorithm); + function pullAlgorithm() { + return TransformStreamDefaultSourcePullAlgorithm(stream); + } + function cancelAlgorithm(reason) { + TransformStreamErrorWritableAndUnblockWrite(stream, reason); + return Promise.resolve(); + } + stream._readable = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark, readableSizeAlgorithm); + stream._backpressure = undefined; + stream._backpressureChangePromise = undefined; + stream._backpressureChangePromise_resolve = undefined; + TransformStreamSetBackpressure(stream, true); + stream._transformStreamController = undefined; +} +function IsTransformStream(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) { + return false; + } + return true; +} +function TransformStreamError(stream, e) { + ReadableStreamDefaultControllerError(stream._readable._readableStreamController, e); + TransformStreamErrorWritableAndUnblockWrite(stream, e); +} +function TransformStreamErrorWritableAndUnblockWrite(stream, e) { + TransformStreamDefaultControllerClearAlgorithms(stream._transformStreamController); + WritableStreamDefaultControllerErrorIfNeeded(stream._writable._writableStreamController, e); + if (stream._backpressure === true) { + TransformStreamSetBackpressure(stream, false); + } +} +function TransformStreamSetBackpressure(stream, backpressure) { + if (stream._backpressureChangePromise !== undefined) { + stream._backpressureChangePromise_resolve(); + } + stream._backpressureChangePromise = new Promise(function (resolve) { + stream._backpressureChangePromise_resolve = resolve; + }); + stream._backpressure = backpressure; +} +var TransformStreamDefaultController = function () { + function TransformStreamDefaultController() { + throw new TypeError('TransformStreamDefaultController instances cannot be created directly'); + } + Object.defineProperty(TransformStreamDefaultController.prototype, "desiredSize", { + get: function () { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException$1('desiredSize'); + } + var readableController = this._controlledTransformStream._readable._readableStreamController; + return ReadableStreamDefaultControllerGetDesiredSize(readableController); + }, + enumerable: true, + configurable: true + }); + TransformStreamDefaultController.prototype.enqueue = function (chunk) { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException$1('enqueue'); + } + TransformStreamDefaultControllerEnqueue(this, chunk); + }; + TransformStreamDefaultController.prototype.error = function (reason) { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException$1('error'); + } + TransformStreamDefaultControllerError(this, reason); + }; + TransformStreamDefaultController.prototype.terminate = function () { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException$1('terminate'); + } + TransformStreamDefaultControllerTerminate(this); + }; + return TransformStreamDefaultController; +}(); +function IsTransformStreamDefaultController(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) { + return false; + } + return true; +} +function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) { + controller._controlledTransformStream = stream; + stream._transformStreamController = controller; + controller._transformAlgorithm = transformAlgorithm; + controller._flushAlgorithm = flushAlgorithm; +} +function SetUpTransformStreamDefaultControllerFromTransformer(stream, transformer) { + var controller = Object.create(TransformStreamDefaultController.prototype); + var transformAlgorithm = function (chunk) { + try { + TransformStreamDefaultControllerEnqueue(controller, chunk); + return Promise.resolve(); + } catch (transformResultE) { + return Promise.reject(transformResultE); + } + }; + var transformMethod = transformer.transform; + if (transformMethod !== undefined) { + if (typeof transformMethod !== 'function') { + throw new TypeError('transform is not a method'); + } + transformAlgorithm = function (chunk) { + return PromiseCall(transformMethod, transformer, [ + chunk, + controller + ]); + }; + } + var flushAlgorithm = CreateAlgorithmFromUnderlyingMethod(transformer, 'flush', 0, [controller]); + SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm); +} +function TransformStreamDefaultControllerClearAlgorithms(controller) { + controller._transformAlgorithm = undefined; + controller._flushAlgorithm = undefined; +} +function TransformStreamDefaultControllerEnqueue(controller, chunk) { + var stream = controller._controlledTransformStream; + var readableController = stream._readable._readableStreamController; + if (ReadableStreamDefaultControllerCanCloseOrEnqueue(readableController) === false) { + throw new TypeError('Readable side is not in a state that permits enqueue'); + } + try { + ReadableStreamDefaultControllerEnqueue(readableController, chunk); + } catch (e) { + TransformStreamErrorWritableAndUnblockWrite(stream, e); + throw stream._readable._storedError; + } + var backpressure = ReadableStreamDefaultControllerHasBackpressure(readableController); + if (backpressure !== stream._backpressure) { + TransformStreamSetBackpressure(stream, true); + } +} +function TransformStreamDefaultControllerError(controller, e) { + TransformStreamError(controller._controlledTransformStream, e); +} +function TransformStreamDefaultControllerPerformTransform(controller, chunk) { + var transformPromise = controller._transformAlgorithm(chunk); + return transformPromise.catch(function (r) { + TransformStreamError(controller._controlledTransformStream, r); + throw r; + }); +} +function TransformStreamDefaultControllerTerminate(controller) { + var stream = controller._controlledTransformStream; + var readableController = stream._readable._readableStreamController; + if (ReadableStreamDefaultControllerCanCloseOrEnqueue(readableController) === true) { + ReadableStreamDefaultControllerClose(readableController); + } + var error = new TypeError('TransformStream terminated'); + TransformStreamErrorWritableAndUnblockWrite(stream, error); +} +function TransformStreamDefaultSinkWriteAlgorithm(stream, chunk) { + var controller = stream._transformStreamController; + if (stream._backpressure === true) { + var backpressureChangePromise = stream._backpressureChangePromise; + return backpressureChangePromise.then(function () { + var writable = stream._writable; + var state = writable._state; + if (state === 'erroring') { + throw writable._storedError; + } + return TransformStreamDefaultControllerPerformTransform(controller, chunk); + }); + } + return TransformStreamDefaultControllerPerformTransform(controller, chunk); +} +function TransformStreamDefaultSinkAbortAlgorithm(stream, reason) { + TransformStreamError(stream, reason); + return Promise.resolve(); +} +function TransformStreamDefaultSinkCloseAlgorithm(stream) { + var readable = stream._readable; + var controller = stream._transformStreamController; + var flushPromise = controller._flushAlgorithm(); + TransformStreamDefaultControllerClearAlgorithms(controller); + return flushPromise.then(function () { + if (readable._state === 'errored') { + throw readable._storedError; + } + var readableController = readable._readableStreamController; + if (ReadableStreamDefaultControllerCanCloseOrEnqueue(readableController) === true) { + ReadableStreamDefaultControllerClose(readableController); + } + }).catch(function (r) { + TransformStreamError(stream, r); + throw readable._storedError; + }); +} +function TransformStreamDefaultSourcePullAlgorithm(stream) { + TransformStreamSetBackpressure(stream, false); + return stream._backpressureChangePromise; +} +function defaultControllerBrandCheckException$1(name) { + return new TypeError("TransformStreamDefaultController.prototype." + name + " can only be used on a TransformStreamDefaultController"); +} +function streamBrandCheckException$2(name) { + return new TypeError("TransformStream.prototype." + name + " can only be used on a TransformStream"); +} - function defaultWriterLockException(name) { - return new TypeError('Cannot ' + name + ' a stream using a released writer'); - } - function defaultWriterClosedPromiseInitialize(writer) { - writer._closedPromise = new Promise(function (resolve, reject) { - writer._closedPromise_resolve = resolve; - writer._closedPromise_reject = reject; - writer._closedPromiseState = 'pending'; - }); - } +/***/ }), +/* 183 */ +/***/ (function(module, exports, __w_pdfjs_require__) { - function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) { - writer._closedPromise = Promise.reject(reason); - writer._closedPromise_resolve = undefined; - writer._closedPromise_reject = undefined; - writer._closedPromiseState = 'rejected'; - } +"use strict"; - function defaultWriterClosedPromiseInitializeAsResolved(writer) { - writer._closedPromise = Promise.resolve(undefined); - writer._closedPromise_resolve = undefined; - writer._closedPromise_reject = undefined; - writer._closedPromiseState = 'resolved'; - } - function defaultWriterClosedPromiseReject(writer, reason) { - assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined'); - assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined'); - assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending'); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.clearPrimitiveCaches = clearPrimitiveCaches; +exports.isEOF = isEOF; +exports.isCmd = isCmd; +exports.isDict = isDict; +exports.isName = isName; +exports.isRef = isRef; +exports.isRefsEqual = isRefsEqual; +exports.isStream = isStream; +exports.RefSetCache = exports.RefSet = exports.Ref = exports.Name = exports.Dict = exports.Cmd = exports.EOF = void 0; - writer._closedPromise_reject(reason); +var _regenerator = _interopRequireDefault(__w_pdfjs_require__(2)); - writer._closedPromise_resolve = undefined; - writer._closedPromise_reject = undefined; - writer._closedPromiseState = 'rejected'; - } +var _util = __w_pdfjs_require__(5); - function defaultWriterClosedPromiseResetToRejected(writer, reason) { - assert(writer._closedPromise_resolve === undefined, 'writer._closedPromise_resolve === undefined'); - assert(writer._closedPromise_reject === undefined, 'writer._closedPromise_reject === undefined'); - assert(writer._closedPromiseState !== 'pending', 'writer._closedPromiseState is not pending'); - writer._closedPromise = Promise.reject(reason); - writer._closedPromiseState = 'rejected'; - } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } - function defaultWriterClosedPromiseResolve(writer) { - assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined'); - assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined'); - assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending'); +function _typeof(obj) { 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); } - writer._closedPromise_resolve(undefined); +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); } } - writer._closedPromise_resolve = undefined; - writer._closedPromise_reject = undefined; - writer._closedPromiseState = 'resolved'; - } +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 defaultWriterReadyPromiseInitialize(writer) { - writer._readyPromise = new Promise(function (resolve, reject) { - writer._readyPromise_resolve = resolve; - writer._readyPromise_reject = reject; - }); - writer._readyPromiseState = 'pending'; - } +var EOF = {}; +exports.EOF = EOF; - function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) { - writer._readyPromise = Promise.reject(reason); - writer._readyPromise_resolve = undefined; - writer._readyPromise_reject = undefined; - writer._readyPromiseState = 'rejected'; - } +var Name = function NameClosure() { + var nameCache = Object.create(null); - function defaultWriterReadyPromiseInitializeAsResolved(writer) { - writer._readyPromise = Promise.resolve(undefined); - writer._readyPromise_resolve = undefined; - writer._readyPromise_reject = undefined; - writer._readyPromiseState = 'fulfilled'; + function Name(name) { + this.name = name; } - function defaultWriterReadyPromiseReject(writer, reason) { - assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined'); - assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined'); - - writer._readyPromise_reject(reason); + Name.prototype = {}; - writer._readyPromise_resolve = undefined; - writer._readyPromise_reject = undefined; - writer._readyPromiseState = 'rejected'; - } + Name.get = function Name_get(name) { + var nameValue = nameCache[name]; + return nameValue ? nameValue : nameCache[name] = new Name(name); + }; - function defaultWriterReadyPromiseReset(writer) { - assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined'); - assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined'); - writer._readyPromise = new Promise(function (resolve, reject) { - writer._readyPromise_resolve = resolve; - writer._readyPromise_reject = reject; - }); - writer._readyPromiseState = 'pending'; - } + Name._clearCache = function () { + nameCache = Object.create(null); + }; - function defaultWriterReadyPromiseResetToRejected(writer, reason) { - assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined'); - assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined'); - writer._readyPromise = Promise.reject(reason); - writer._readyPromiseState = 'rejected'; - } + return Name; +}(); - function defaultWriterReadyPromiseResolve(writer) { - assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined'); - assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined'); +exports.Name = Name; - writer._readyPromise_resolve(undefined); +var Cmd = function CmdClosure() { + var cmdCache = Object.create(null); - writer._readyPromise_resolve = undefined; - writer._readyPromise_reject = undefined; - writer._readyPromiseState = 'fulfilled'; + function Cmd(cmd) { + this.cmd = cmd; } -}, function (module, exports, __w_pdfjs_require__) { - "use strict"; - - var _require = __w_pdfjs_require__(0), - IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber; - - var _require2 = __w_pdfjs_require__(1), - assert = _require2.assert; - exports.DequeueValue = function (container) { - assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: DequeueValue should only be used on containers with [[queue]] and [[queueTotalSize]].'); - assert(container._queue.length > 0, 'Spec-level failure: should never dequeue from an empty queue.'); - - var pair = container._queue.shift(); - - container._queueTotalSize -= pair.size; - - if (container._queueTotalSize < 0) { - container._queueTotalSize = 0; - } - - return pair.value; - }; - - exports.EnqueueValueWithSize = function (container, value, size) { - assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: EnqueueValueWithSize should only be used on containers with [[queue]] and ' + '[[queueTotalSize]].'); - size = Number(size); - - if (!IsFiniteNonNegativeNumber(size)) { - throw new RangeError('Size must be a finite, non-NaN, non-negative number.'); - } - - container._queue.push({ - value: value, - size: size - }); + Cmd.prototype = {}; - container._queueTotalSize += size; + Cmd.get = function Cmd_get(cmd) { + var cmdValue = cmdCache[cmd]; + return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd); }; - exports.PeekQueueValue = function (container) { - assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: PeekQueueValue should only be used on containers with [[queue]] and [[queueTotalSize]].'); - assert(container._queue.length > 0, 'Spec-level failure: should never peek at an empty queue.'); - var pair = container._queue[0]; - return pair.value; + Cmd._clearCache = function () { + cmdCache = Object.create(null); }; - exports.ResetQueue = function (container) { - assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: ResetQueue should only be used on containers with [[queue]] and [[queueTotalSize]].'); - container._queue = []; - container._queueTotalSize = 0; - }; -}, function (module, exports, __w_pdfjs_require__) { - "use strict"; + return Cmd; +}(); - 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); - } - } +exports.Cmd = Cmd; - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; - }(); +var Dict = function DictClosure() { + var nonSerializable = function nonSerializableClosure() { + return nonSerializable; + }; - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } + function Dict(xref) { + this._map = Object.create(null); + this.xref = xref; + this.objId = null; + this.suppressEncryption = false; + this.__nonSerializable__ = nonSerializable; } - var _require = __w_pdfjs_require__(0), - ArrayBufferCopy = _require.ArrayBufferCopy, - CreateIterResultObject = _require.CreateIterResultObject, - IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber, - InvokeOrNoop = _require.InvokeOrNoop, - PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop, - TransferArrayBuffer = _require.TransferArrayBuffer, - ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy, - ValidateAndNormalizeHighWaterMark = _require.ValidateAndNormalizeHighWaterMark; - - var _require2 = __w_pdfjs_require__(0), - createArrayFromList = _require2.createArrayFromList, - createDataProperty = _require2.createDataProperty, - typeIsObject = _require2.typeIsObject; - - var _require3 = __w_pdfjs_require__(1), - assert = _require3.assert, - rethrowAssertionErrorRejection = _require3.rethrowAssertionErrorRejection; - - var _require4 = __w_pdfjs_require__(3), - DequeueValue = _require4.DequeueValue, - EnqueueValueWithSize = _require4.EnqueueValueWithSize, - ResetQueue = _require4.ResetQueue; - - var _require5 = __w_pdfjs_require__(2), - AcquireWritableStreamDefaultWriter = _require5.AcquireWritableStreamDefaultWriter, - IsWritableStream = _require5.IsWritableStream, - IsWritableStreamLocked = _require5.IsWritableStreamLocked, - WritableStreamAbort = _require5.WritableStreamAbort, - WritableStreamDefaultWriterCloseWithErrorPropagation = _require5.WritableStreamDefaultWriterCloseWithErrorPropagation, - WritableStreamDefaultWriterRelease = _require5.WritableStreamDefaultWriterRelease, - WritableStreamDefaultWriterWrite = _require5.WritableStreamDefaultWriterWrite, - WritableStreamCloseQueuedOrInFlight = _require5.WritableStreamCloseQueuedOrInFlight; - - var ReadableStream = function () { - function ReadableStream() { - var underlyingSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - size = _ref.size, - highWaterMark = _ref.highWaterMark; - - _classCallCheck(this, ReadableStream); - - this._state = 'readable'; - this._reader = undefined; - this._storedError = undefined; - this._disturbed = false; - this._readableStreamController = undefined; - var type = underlyingSource.type; - var typeString = String(type); - - if (typeString === 'bytes') { - if (highWaterMark === undefined) { - highWaterMark = 0; - } - - this._readableStreamController = new ReadableByteStreamController(this, underlyingSource, highWaterMark); - } else if (type === undefined) { - if (highWaterMark === undefined) { - highWaterMark = 1; - } - - this._readableStreamController = new ReadableStreamDefaultController(this, underlyingSource, size, highWaterMark); - } else { - throw new RangeError('Invalid type is specified'); - } - } + Dict.prototype = { + assignXref: function Dict_assignXref(newXref) { + this.xref = newXref; + }, + get: function get(key1, key2, key3) { + var value = this._map[key1]; - _createClass(ReadableStream, [{ - key: 'cancel', - value: function cancel(reason) { - if (IsReadableStream(this) === false) { - return Promise.reject(streamBrandCheckException('cancel')); - } + if (value === undefined && !(key1 in this._map) && key2 !== undefined) { + value = this._map[key2]; - if (IsReadableStreamLocked(this) === true) { - return Promise.reject(new TypeError('Cannot cancel a stream that already has a reader')); + if (value === undefined && !(key2 in this._map) && key3 !== undefined) { + value = this._map[key3]; } - - return ReadableStreamCancel(this, reason); } - }, { - key: 'getReader', - value: function getReader() { - var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, - mode = _ref2.mode; - - if (IsReadableStream(this) === false) { - throw streamBrandCheckException('getReader'); - } - if (mode === undefined) { - return AcquireReadableStreamDefaultReader(this); - } - - mode = String(mode); - - if (mode === 'byob') { - return AcquireReadableStreamBYOBReader(this); - } - - throw new RangeError('Invalid mode is specified'); - } - }, { - key: 'pipeThrough', - value: function pipeThrough(_ref3, options) { - var writable = _ref3.writable, - readable = _ref3.readable; - var promise = this.pipeTo(writable, options); - ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise); - return readable; + if (value instanceof Ref && this.xref) { + return this.xref.fetch(value, this.suppressEncryption); } - }, { - key: 'pipeTo', - value: function pipeTo(dest) { - var _this = this; - - var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - preventClose = _ref4.preventClose, - preventAbort = _ref4.preventAbort, - preventCancel = _ref4.preventCancel; - - if (IsReadableStream(this) === false) { - return Promise.reject(streamBrandCheckException('pipeTo')); - } - - if (IsWritableStream(dest) === false) { - return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo\'s first argument must be a WritableStream')); - } - - preventClose = Boolean(preventClose); - preventAbort = Boolean(preventAbort); - preventCancel = Boolean(preventCancel); - - if (IsReadableStreamLocked(this) === true) { - return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream')); - } - - if (IsWritableStreamLocked(dest) === true) { - return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream')); - } - - var reader = AcquireReadableStreamDefaultReader(this); - var writer = AcquireWritableStreamDefaultWriter(dest); - var shuttingDown = false; - var currentWrite = Promise.resolve(); - return new Promise(function (resolve, reject) { - function pipeLoop() { - currentWrite = Promise.resolve(); - if (shuttingDown === true) { - return Promise.resolve(); - } + return value; + }, + getAsync: function () { + var _getAsync = _asyncToGenerator( + /*#__PURE__*/ + _regenerator["default"].mark(function _callee(key1, key2, key3) { + var value; + return _regenerator["default"].wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + value = this._map[key1]; - return writer._readyPromise.then(function () { - return ReadableStreamDefaultReaderRead(reader).then(function (_ref5) { - var value = _ref5.value, - done = _ref5.done; + if (value === undefined && !(key1 in this._map) && key2 !== undefined) { + value = this._map[key2]; - if (done === true) { - return; + if (value === undefined && !(key2 in this._map) && key3 !== undefined) { + value = this._map[key3]; + } } - currentWrite = WritableStreamDefaultWriterWrite(writer, value).catch(function () {}); - }); - }).then(pipeLoop); - } - - isOrBecomesErrored(_this, reader._closedPromise, function (storedError) { - if (preventAbort === false) { - shutdownWithAction(function () { - return WritableStreamAbort(dest, storedError); - }, true, storedError); - } else { - shutdown(true, storedError); - } - }); - isOrBecomesErrored(dest, writer._closedPromise, function (storedError) { - if (preventCancel === false) { - shutdownWithAction(function () { - return ReadableStreamCancel(_this, storedError); - }, true, storedError); - } else { - shutdown(true, storedError); - } - }); - isOrBecomesClosed(_this, reader._closedPromise, function () { - if (preventClose === false) { - shutdownWithAction(function () { - return WritableStreamDefaultWriterCloseWithErrorPropagation(writer); - }); - } else { - shutdown(); - } - }); - - if (WritableStreamCloseQueuedOrInFlight(dest) === true || dest._state === 'closed') { - var destClosed = new TypeError('the destination writable stream closed before all data could be piped to it'); - - if (preventCancel === false) { - shutdownWithAction(function () { - return ReadableStreamCancel(_this, destClosed); - }, true, destClosed); - } else { - shutdown(true, destClosed); - } - } - - pipeLoop().catch(function (err) { - currentWrite = Promise.resolve(); - rethrowAssertionErrorRejection(err); - }); - - function waitForWritesToFinish() { - var oldCurrentWrite = currentWrite; - return currentWrite.then(function () { - return oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : undefined; - }); - } - - function isOrBecomesErrored(stream, promise, action) { - if (stream._state === 'errored') { - action(stream._storedError); - } else { - promise.catch(action).catch(rethrowAssertionErrorRejection); - } - } - - function isOrBecomesClosed(stream, promise, action) { - if (stream._state === 'closed') { - action(); - } else { - promise.then(action).catch(rethrowAssertionErrorRejection); - } - } - - function shutdownWithAction(action, originalIsError, originalError) { - if (shuttingDown === true) { - return; - } - - shuttingDown = true; - - if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) { - waitForWritesToFinish().then(doTheRest); - } else { - doTheRest(); - } - - function doTheRest() { - action().then(function () { - return finalize(originalIsError, originalError); - }, function (newError) { - return finalize(true, newError); - }).catch(rethrowAssertionErrorRejection); - } - } - - function shutdown(isError, error) { - if (shuttingDown === true) { - return; - } - - shuttingDown = true; + if (!(value instanceof Ref && this.xref)) { + _context.next = 4; + break; + } - if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) { - waitForWritesToFinish().then(function () { - return finalize(isError, error); - }).catch(rethrowAssertionErrorRejection); - } else { - finalize(isError, error); - } - } + return _context.abrupt("return", this.xref.fetchAsync(value, this.suppressEncryption)); - function finalize(isError, error) { - WritableStreamDefaultWriterRelease(writer); - ReadableStreamReaderGenericRelease(reader); + case 4: + return _context.abrupt("return", value); - if (isError) { - reject(error); - } else { - resolve(undefined); + case 5: + case "end": + return _context.stop(); } } - }); - } - }, { - key: 'tee', - value: function tee() { - if (IsReadableStream(this) === false) { - throw streamBrandCheckException('tee'); - } - - var branches = ReadableStreamTee(this, false); - return createArrayFromList(branches); - } - }, { - key: 'locked', - get: function get() { - if (IsReadableStream(this) === false) { - throw streamBrandCheckException('locked'); - } - - return IsReadableStreamLocked(this); - } - }]); - - return ReadableStream; - }(); - - module.exports = { - ReadableStream: ReadableStream, - IsReadableStreamDisturbed: IsReadableStreamDisturbed, - ReadableStreamDefaultControllerClose: ReadableStreamDefaultControllerClose, - ReadableStreamDefaultControllerEnqueue: ReadableStreamDefaultControllerEnqueue, - ReadableStreamDefaultControllerError: ReadableStreamDefaultControllerError, - ReadableStreamDefaultControllerGetDesiredSize: ReadableStreamDefaultControllerGetDesiredSize - }; - - function AcquireReadableStreamBYOBReader(stream) { - return new ReadableStreamBYOBReader(stream); - } - - function AcquireReadableStreamDefaultReader(stream) { - return new ReadableStreamDefaultReader(stream); - } - - function IsReadableStream(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) { - return false; - } - - return true; - } - - function IsReadableStreamDisturbed(stream) { - assert(IsReadableStream(stream) === true, 'IsReadableStreamDisturbed should only be used on known readable streams'); - return stream._disturbed; - } - - function IsReadableStreamLocked(stream) { - assert(IsReadableStream(stream) === true, 'IsReadableStreamLocked should only be used on known readable streams'); - - if (stream._reader === undefined) { - return false; - } - - return true; - } - - function ReadableStreamTee(stream, cloneForBranch2) { - assert(IsReadableStream(stream) === true); - assert(typeof cloneForBranch2 === 'boolean'); - var reader = AcquireReadableStreamDefaultReader(stream); - var teeState = { - closedOrErrored: false, - canceled1: false, - canceled2: false, - reason1: undefined, - reason2: undefined - }; - teeState.promise = new Promise(function (resolve) { - teeState._resolve = resolve; - }); - var pull = create_ReadableStreamTeePullFunction(); - pull._reader = reader; - pull._teeState = teeState; - pull._cloneForBranch2 = cloneForBranch2; - var cancel1 = create_ReadableStreamTeeBranch1CancelFunction(); - cancel1._stream = stream; - cancel1._teeState = teeState; - var cancel2 = create_ReadableStreamTeeBranch2CancelFunction(); - cancel2._stream = stream; - cancel2._teeState = teeState; - var underlyingSource1 = Object.create(Object.prototype); - createDataProperty(underlyingSource1, 'pull', pull); - createDataProperty(underlyingSource1, 'cancel', cancel1); - var branch1Stream = new ReadableStream(underlyingSource1); - var underlyingSource2 = Object.create(Object.prototype); - createDataProperty(underlyingSource2, 'pull', pull); - createDataProperty(underlyingSource2, 'cancel', cancel2); - var branch2Stream = new ReadableStream(underlyingSource2); - pull._branch1 = branch1Stream._readableStreamController; - pull._branch2 = branch2Stream._readableStreamController; - - reader._closedPromise.catch(function (r) { - if (teeState.closedOrErrored === true) { - return; - } - - ReadableStreamDefaultControllerError(pull._branch1, r); - ReadableStreamDefaultControllerError(pull._branch2, r); - teeState.closedOrErrored = true; - }); - - return [branch1Stream, branch2Stream]; - } - - function create_ReadableStreamTeePullFunction() { - function f() { - var reader = f._reader, - branch1 = f._branch1, - branch2 = f._branch2, - teeState = f._teeState; - return ReadableStreamDefaultReaderRead(reader).then(function (result) { - assert(typeIsObject(result)); - var value = result.value; - var done = result.done; - assert(typeof done === 'boolean'); - - if (done === true && teeState.closedOrErrored === false) { - if (teeState.canceled1 === false) { - ReadableStreamDefaultControllerClose(branch1); - } - - if (teeState.canceled2 === false) { - ReadableStreamDefaultControllerClose(branch2); - } - - teeState.closedOrErrored = true; - } - - if (teeState.closedOrErrored === true) { - return; - } - - var value1 = value; - var value2 = value; - - if (teeState.canceled1 === false) { - ReadableStreamDefaultControllerEnqueue(branch1, value1); - } - - if (teeState.canceled2 === false) { - ReadableStreamDefaultControllerEnqueue(branch2, value2); - } - }); - } - - return f; - } - - function create_ReadableStreamTeeBranch1CancelFunction() { - function f(reason) { - var stream = f._stream, - teeState = f._teeState; - teeState.canceled1 = true; - teeState.reason1 = reason; - - if (teeState.canceled2 === true) { - var compositeReason = createArrayFromList([teeState.reason1, teeState.reason2]); - var cancelResult = ReadableStreamCancel(stream, compositeReason); - - teeState._resolve(cancelResult); - } - - return teeState.promise; - } - - return f; - } - - function create_ReadableStreamTeeBranch2CancelFunction() { - function f(reason) { - var stream = f._stream, - teeState = f._teeState; - teeState.canceled2 = true; - teeState.reason2 = reason; - - if (teeState.canceled1 === true) { - var compositeReason = createArrayFromList([teeState.reason1, teeState.reason2]); - var cancelResult = ReadableStreamCancel(stream, compositeReason); - - teeState._resolve(cancelResult); - } - - return teeState.promise; - } - - return f; - } - - function ReadableStreamAddReadIntoRequest(stream) { - assert(IsReadableStreamBYOBReader(stream._reader) === true); - assert(stream._state === 'readable' || stream._state === 'closed'); - var promise = new Promise(function (resolve, reject) { - var readIntoRequest = { - _resolve: resolve, - _reject: reject - }; - - stream._reader._readIntoRequests.push(readIntoRequest); - }); - return promise; - } - - function ReadableStreamAddReadRequest(stream) { - assert(IsReadableStreamDefaultReader(stream._reader) === true); - assert(stream._state === 'readable'); - var promise = new Promise(function (resolve, reject) { - var readRequest = { - _resolve: resolve, - _reject: reject - }; - - stream._reader._readRequests.push(readRequest); - }); - return promise; - } - - function ReadableStreamCancel(stream, reason) { - stream._disturbed = true; - - if (stream._state === 'closed') { - return Promise.resolve(undefined); - } - - if (stream._state === 'errored') { - return Promise.reject(stream._storedError); - } - - ReadableStreamClose(stream); - - var sourceCancelPromise = stream._readableStreamController.__cancelSteps(reason); - - return sourceCancelPromise.then(function () { - return undefined; - }); - } - - function ReadableStreamClose(stream) { - assert(stream._state === 'readable'); - stream._state = 'closed'; - var reader = stream._reader; - - if (reader === undefined) { - return undefined; - } - - if (IsReadableStreamDefaultReader(reader) === true) { - for (var i = 0; i < reader._readRequests.length; i++) { - var _resolve = reader._readRequests[i]._resolve; - - _resolve(CreateIterResultObject(undefined, true)); - } - - reader._readRequests = []; - } - - defaultReaderClosedPromiseResolve(reader); - return undefined; - } - - function ReadableStreamError(stream, e) { - assert(IsReadableStream(stream) === true, 'stream must be ReadableStream'); - assert(stream._state === 'readable', 'state must be readable'); - stream._state = 'errored'; - stream._storedError = e; - var reader = stream._reader; - - if (reader === undefined) { - return undefined; - } - - if (IsReadableStreamDefaultReader(reader) === true) { - for (var i = 0; i < reader._readRequests.length; i++) { - var readRequest = reader._readRequests[i]; - - readRequest._reject(e); - } - - reader._readRequests = []; - } else { - assert(IsReadableStreamBYOBReader(reader), 'reader must be ReadableStreamBYOBReader'); - - for (var _i = 0; _i < reader._readIntoRequests.length; _i++) { - var readIntoRequest = reader._readIntoRequests[_i]; - - readIntoRequest._reject(e); - } - - reader._readIntoRequests = []; - } - - defaultReaderClosedPromiseReject(reader, e); - - reader._closedPromise.catch(function () {}); - } - - function ReadableStreamFulfillReadIntoRequest(stream, chunk, done) { - var reader = stream._reader; - assert(reader._readIntoRequests.length > 0); - - var readIntoRequest = reader._readIntoRequests.shift(); - - readIntoRequest._resolve(CreateIterResultObject(chunk, done)); - } - - function ReadableStreamFulfillReadRequest(stream, chunk, done) { - var reader = stream._reader; - assert(reader._readRequests.length > 0); - - var readRequest = reader._readRequests.shift(); - - readRequest._resolve(CreateIterResultObject(chunk, done)); - } - - function ReadableStreamGetNumReadIntoRequests(stream) { - return stream._reader._readIntoRequests.length; - } - - function ReadableStreamGetNumReadRequests(stream) { - return stream._reader._readRequests.length; - } - - function ReadableStreamHasBYOBReader(stream) { - var reader = stream._reader; - - if (reader === undefined) { - return false; - } - - if (IsReadableStreamBYOBReader(reader) === false) { - return false; - } - - return true; - } - - function ReadableStreamHasDefaultReader(stream) { - var reader = stream._reader; - - if (reader === undefined) { - return false; - } - - if (IsReadableStreamDefaultReader(reader) === false) { - return false; - } - - return true; - } - - var ReadableStreamDefaultReader = function () { - function ReadableStreamDefaultReader(stream) { - _classCallCheck(this, ReadableStreamDefaultReader); - - if (IsReadableStream(stream) === false) { - throw new TypeError('ReadableStreamDefaultReader can only be constructed with a ReadableStream instance'); - } - - if (IsReadableStreamLocked(stream) === true) { - throw new TypeError('This stream has already been locked for exclusive reading by another reader'); - } - - ReadableStreamReaderGenericInitialize(this, stream); - this._readRequests = []; - } - - _createClass(ReadableStreamDefaultReader, [{ - key: 'cancel', - value: function cancel(reason) { - if (IsReadableStreamDefaultReader(this) === false) { - return Promise.reject(defaultReaderBrandCheckException('cancel')); - } - - if (this._ownerReadableStream === undefined) { - return Promise.reject(readerLockException('cancel')); - } - - return ReadableStreamReaderGenericCancel(this, reason); - } - }, { - key: 'read', - value: function read() { - if (IsReadableStreamDefaultReader(this) === false) { - return Promise.reject(defaultReaderBrandCheckException('read')); - } - - if (this._ownerReadableStream === undefined) { - return Promise.reject(readerLockException('read from')); - } - - return ReadableStreamDefaultReaderRead(this); - } - }, { - key: 'releaseLock', - value: function releaseLock() { - if (IsReadableStreamDefaultReader(this) === false) { - throw defaultReaderBrandCheckException('releaseLock'); - } - - if (this._ownerReadableStream === undefined) { - return; - } - - if (this._readRequests.length > 0) { - throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled'); - } - - ReadableStreamReaderGenericRelease(this); - } - }, { - key: 'closed', - get: function get() { - if (IsReadableStreamDefaultReader(this) === false) { - return Promise.reject(defaultReaderBrandCheckException('closed')); - } - - return this._closedPromise; - } - }]); - - return ReadableStreamDefaultReader; - }(); - - var ReadableStreamBYOBReader = function () { - function ReadableStreamBYOBReader(stream) { - _classCallCheck(this, ReadableStreamBYOBReader); - - if (!IsReadableStream(stream)) { - throw new TypeError('ReadableStreamBYOBReader can only be constructed with a ReadableStream instance given a ' + 'byte source'); - } - - if (IsReadableByteStreamController(stream._readableStreamController) === false) { - throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' + 'source'); - } - - if (IsReadableStreamLocked(stream)) { - throw new TypeError('This stream has already been locked for exclusive reading by another reader'); - } - - ReadableStreamReaderGenericInitialize(this, stream); - this._readIntoRequests = []; - } - - _createClass(ReadableStreamBYOBReader, [{ - key: 'cancel', - value: function cancel(reason) { - if (!IsReadableStreamBYOBReader(this)) { - return Promise.reject(byobReaderBrandCheckException('cancel')); - } - - if (this._ownerReadableStream === undefined) { - return Promise.reject(readerLockException('cancel')); - } - - return ReadableStreamReaderGenericCancel(this, reason); - } - }, { - key: 'read', - value: function read(view) { - if (!IsReadableStreamBYOBReader(this)) { - return Promise.reject(byobReaderBrandCheckException('read')); - } - - if (this._ownerReadableStream === undefined) { - return Promise.reject(readerLockException('read from')); - } - - if (!ArrayBuffer.isView(view)) { - return Promise.reject(new TypeError('view must be an array buffer view')); - } - - if (view.byteLength === 0) { - return Promise.reject(new TypeError('view must have non-zero byteLength')); - } - - return ReadableStreamBYOBReaderRead(this, view); - } - }, { - key: 'releaseLock', - value: function releaseLock() { - if (!IsReadableStreamBYOBReader(this)) { - throw byobReaderBrandCheckException('releaseLock'); - } - - if (this._ownerReadableStream === undefined) { - return; - } - - if (this._readIntoRequests.length > 0) { - throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled'); - } - - ReadableStreamReaderGenericRelease(this); - } - }, { - key: 'closed', - get: function get() { - if (!IsReadableStreamBYOBReader(this)) { - return Promise.reject(byobReaderBrandCheckException('closed')); - } - - return this._closedPromise; - } - }]); - - return ReadableStreamBYOBReader; - }(); - - function IsReadableStreamBYOBReader(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) { - return false; - } - - return true; - } - - function IsReadableStreamDefaultReader(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) { - return false; - } - - return true; - } - - function ReadableStreamReaderGenericInitialize(reader, stream) { - reader._ownerReadableStream = stream; - stream._reader = reader; - - if (stream._state === 'readable') { - defaultReaderClosedPromiseInitialize(reader); - } else if (stream._state === 'closed') { - defaultReaderClosedPromiseInitializeAsResolved(reader); - } else { - assert(stream._state === 'errored', 'state must be errored'); - defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError); - - reader._closedPromise.catch(function () {}); - } - } - - function ReadableStreamReaderGenericCancel(reader, reason) { - var stream = reader._ownerReadableStream; - assert(stream !== undefined); - return ReadableStreamCancel(stream, reason); - } - - function ReadableStreamReaderGenericRelease(reader) { - assert(reader._ownerReadableStream !== undefined); - assert(reader._ownerReadableStream._reader === reader); - - if (reader._ownerReadableStream._state === 'readable') { - defaultReaderClosedPromiseReject(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness')); - } else { - defaultReaderClosedPromiseResetToRejected(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness')); - } - - reader._closedPromise.catch(function () {}); - - reader._ownerReadableStream._reader = undefined; - reader._ownerReadableStream = undefined; - } - - function ReadableStreamBYOBReaderRead(reader, view) { - var stream = reader._ownerReadableStream; - assert(stream !== undefined); - stream._disturbed = true; - - if (stream._state === 'errored') { - return Promise.reject(stream._storedError); - } - - return ReadableByteStreamControllerPullInto(stream._readableStreamController, view); - } - - function ReadableStreamDefaultReaderRead(reader) { - var stream = reader._ownerReadableStream; - assert(stream !== undefined); - stream._disturbed = true; - - if (stream._state === 'closed') { - return Promise.resolve(CreateIterResultObject(undefined, true)); - } - - if (stream._state === 'errored') { - return Promise.reject(stream._storedError); - } - - assert(stream._state === 'readable'); - return stream._readableStreamController.__pullSteps(); - } - - var ReadableStreamDefaultController = function () { - function ReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark) { - _classCallCheck(this, ReadableStreamDefaultController); - - if (IsReadableStream(stream) === false) { - throw new TypeError('ReadableStreamDefaultController can only be constructed with a ReadableStream instance'); - } - - if (stream._readableStreamController !== undefined) { - throw new TypeError('ReadableStreamDefaultController instances can only be created by the ReadableStream constructor'); - } - - this._controlledReadableStream = stream; - this._underlyingSource = underlyingSource; - this._queue = undefined; - this._queueTotalSize = undefined; - ResetQueue(this); - this._started = false; - this._closeRequested = false; - this._pullAgain = false; - this._pulling = false; - var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark); - this._strategySize = normalizedStrategy.size; - this._strategyHWM = normalizedStrategy.highWaterMark; - var controller = this; - var startResult = InvokeOrNoop(underlyingSource, 'start', [this]); - Promise.resolve(startResult).then(function () { - controller._started = true; - assert(controller._pulling === false); - assert(controller._pullAgain === false); - ReadableStreamDefaultControllerCallPullIfNeeded(controller); - }, function (r) { - ReadableStreamDefaultControllerErrorIfNeeded(controller, r); - }).catch(rethrowAssertionErrorRejection); - } - - _createClass(ReadableStreamDefaultController, [{ - key: 'close', - value: function close() { - if (IsReadableStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('close'); - } - - if (this._closeRequested === true) { - throw new TypeError('The stream has already been closed; do not close it again!'); - } - - var state = this._controlledReadableStream._state; - - if (state !== 'readable') { - throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be closed'); - } - - ReadableStreamDefaultControllerClose(this); - } - }, { - key: 'enqueue', - value: function enqueue(chunk) { - if (IsReadableStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('enqueue'); - } - - if (this._closeRequested === true) { - throw new TypeError('stream is closed or draining'); - } - - var state = this._controlledReadableStream._state; - - if (state !== 'readable') { - throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be enqueued to'); - } - - return ReadableStreamDefaultControllerEnqueue(this, chunk); - } - }, { - key: 'error', - value: function error(e) { - if (IsReadableStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('error'); - } - - var stream = this._controlledReadableStream; - - if (stream._state !== 'readable') { - throw new TypeError('The stream is ' + stream._state + ' and so cannot be errored'); - } - - ReadableStreamDefaultControllerError(this, e); - } - }, { - key: '__cancelSteps', - value: function __cancelSteps(reason) { - ResetQueue(this); - return PromiseInvokeOrNoop(this._underlyingSource, 'cancel', [reason]); - } - }, { - key: '__pullSteps', - value: function __pullSteps() { - var stream = this._controlledReadableStream; - - if (this._queue.length > 0) { - var chunk = DequeueValue(this); - - if (this._closeRequested === true && this._queue.length === 0) { - ReadableStreamClose(stream); - } else { - ReadableStreamDefaultControllerCallPullIfNeeded(this); - } - - return Promise.resolve(CreateIterResultObject(chunk, false)); - } - - var pendingPromise = ReadableStreamAddReadRequest(stream); - ReadableStreamDefaultControllerCallPullIfNeeded(this); - return pendingPromise; - } - }, { - key: 'desiredSize', - get: function get() { - if (IsReadableStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('desiredSize'); - } - - return ReadableStreamDefaultControllerGetDesiredSize(this); - } - }]); - - return ReadableStreamDefaultController; - }(); - - function IsReadableStreamDefaultController(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSource')) { - return false; - } - - return true; - } - - function ReadableStreamDefaultControllerCallPullIfNeeded(controller) { - var shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller); - - if (shouldPull === false) { - return undefined; - } - - if (controller._pulling === true) { - controller._pullAgain = true; - return undefined; - } - - assert(controller._pullAgain === false); - controller._pulling = true; - var pullPromise = PromiseInvokeOrNoop(controller._underlyingSource, 'pull', [controller]); - pullPromise.then(function () { - controller._pulling = false; - - if (controller._pullAgain === true) { - controller._pullAgain = false; - return ReadableStreamDefaultControllerCallPullIfNeeded(controller); - } - - return undefined; - }, function (e) { - ReadableStreamDefaultControllerErrorIfNeeded(controller, e); - }).catch(rethrowAssertionErrorRejection); - return undefined; - } - - function ReadableStreamDefaultControllerShouldCallPull(controller) { - var stream = controller._controlledReadableStream; - - if (stream._state === 'closed' || stream._state === 'errored') { - return false; - } - - if (controller._closeRequested === true) { - return false; - } - - if (controller._started === false) { - return false; - } - - if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { - return true; - } - - var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller); - - if (desiredSize > 0) { - return true; - } - - return false; - } - - function ReadableStreamDefaultControllerClose(controller) { - var stream = controller._controlledReadableStream; - assert(controller._closeRequested === false); - assert(stream._state === 'readable'); - controller._closeRequested = true; - - if (controller._queue.length === 0) { - ReadableStreamClose(stream); - } - } - - function ReadableStreamDefaultControllerEnqueue(controller, chunk) { - var stream = controller._controlledReadableStream; - assert(controller._closeRequested === false); - assert(stream._state === 'readable'); - - if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { - ReadableStreamFulfillReadRequest(stream, chunk, false); - } else { - var chunkSize = 1; - - if (controller._strategySize !== undefined) { - var strategySize = controller._strategySize; - - try { - chunkSize = strategySize(chunk); - } catch (chunkSizeE) { - ReadableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE); - throw chunkSizeE; - } - } + }, _callee, this); + })); - try { - EnqueueValueWithSize(controller, chunk, chunkSize); - } catch (enqueueE) { - ReadableStreamDefaultControllerErrorIfNeeded(controller, enqueueE); - throw enqueueE; + function getAsync(_x, _x2, _x3) { + return _getAsync.apply(this, arguments); } - } - - ReadableStreamDefaultControllerCallPullIfNeeded(controller); - return undefined; - } - - function ReadableStreamDefaultControllerError(controller, e) { - var stream = controller._controlledReadableStream; - assert(stream._state === 'readable'); - ResetQueue(controller); - ReadableStreamError(stream, e); - } - - function ReadableStreamDefaultControllerErrorIfNeeded(controller, e) { - if (controller._controlledReadableStream._state === 'readable') { - ReadableStreamDefaultControllerError(controller, e); - } - } - - function ReadableStreamDefaultControllerGetDesiredSize(controller) { - var stream = controller._controlledReadableStream; - var state = stream._state; - - if (state === 'errored') { - return null; - } - - if (state === 'closed') { - return 0; - } - - return controller._strategyHWM - controller._queueTotalSize; - } - var ReadableStreamBYOBRequest = function () { - function ReadableStreamBYOBRequest(controller, view) { - _classCallCheck(this, ReadableStreamBYOBRequest); - - this._associatedReadableByteStreamController = controller; - this._view = view; - } - - _createClass(ReadableStreamBYOBRequest, [{ - key: 'respond', - value: function respond(bytesWritten) { - if (IsReadableStreamBYOBRequest(this) === false) { - throw byobRequestBrandCheckException('respond'); - } - - if (this._associatedReadableByteStreamController === undefined) { - throw new TypeError('This BYOB request has been invalidated'); - } + return getAsync; + }(), + getArray: function getArray(key1, key2, key3) { + var value = this.get(key1, key2, key3); - ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten); + if (!Array.isArray(value) || !this.xref) { + return value; } - }, { - key: 'respondWithNewView', - value: function respondWithNewView(view) { - if (IsReadableStreamBYOBRequest(this) === false) { - throw byobRequestBrandCheckException('respond'); - } - if (this._associatedReadableByteStreamController === undefined) { - throw new TypeError('This BYOB request has been invalidated'); - } + value = value.slice(); - if (!ArrayBuffer.isView(view)) { - throw new TypeError('You can only respond with array buffer views'); + for (var i = 0, ii = value.length; i < ii; i++) { + if (!(value[i] instanceof Ref)) { + continue; } - ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view); - } - }, { - key: 'view', - get: function get() { - return this._view; + value[i] = this.xref.fetch(value[i], this.suppressEncryption); } - }]); - - return ReadableStreamBYOBRequest; - }(); - - var ReadableByteStreamController = function () { - function ReadableByteStreamController(stream, underlyingByteSource, highWaterMark) { - _classCallCheck(this, ReadableByteStreamController); - - if (IsReadableStream(stream) === false) { - throw new TypeError('ReadableByteStreamController can only be constructed with a ReadableStream instance given ' + 'a byte source'); - } - - if (stream._readableStreamController !== undefined) { - throw new TypeError('ReadableByteStreamController instances can only be created by the ReadableStream constructor given a byte ' + 'source'); - } - - this._controlledReadableStream = stream; - this._underlyingByteSource = underlyingByteSource; - this._pullAgain = false; - this._pulling = false; - ReadableByteStreamControllerClearPendingPullIntos(this); - this._queue = this._queueTotalSize = undefined; - ResetQueue(this); - this._closeRequested = false; - this._started = false; - this._strategyHWM = ValidateAndNormalizeHighWaterMark(highWaterMark); - var autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize; - if (autoAllocateChunkSize !== undefined) { - if (Number.isInteger(autoAllocateChunkSize) === false || autoAllocateChunkSize <= 0) { - throw new RangeError('autoAllocateChunkSize must be a positive integer'); - } + return value; + }, + getRaw: function Dict_getRaw(key) { + return this._map[key]; + }, + getKeys: function Dict_getKeys() { + return Object.keys(this._map); + }, + set: function Dict_set(key, value) { + this._map[key] = value; + }, + has: function Dict_has(key) { + return key in this._map; + }, + forEach: function Dict_forEach(callback) { + for (var key in this._map) { + callback(key, this.get(key)); } - - this._autoAllocateChunkSize = autoAllocateChunkSize; - this._pendingPullIntos = []; - var controller = this; - var startResult = InvokeOrNoop(underlyingByteSource, 'start', [this]); - Promise.resolve(startResult).then(function () { - controller._started = true; - assert(controller._pulling === false); - assert(controller._pullAgain === false); - ReadableByteStreamControllerCallPullIfNeeded(controller); - }, function (r) { - if (stream._state === 'readable') { - ReadableByteStreamControllerError(controller, r); - } - }).catch(rethrowAssertionErrorRejection); } + }; + Dict.empty = new Dict(null); - _createClass(ReadableByteStreamController, [{ - key: 'close', - value: function close() { - if (IsReadableByteStreamController(this) === false) { - throw byteStreamControllerBrandCheckException('close'); - } - - if (this._closeRequested === true) { - throw new TypeError('The stream has already been closed; do not close it again!'); - } - - var state = this._controlledReadableStream._state; - - if (state !== 'readable') { - throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be closed'); - } - - ReadableByteStreamControllerClose(this); - } - }, { - key: 'enqueue', - value: function enqueue(chunk) { - if (IsReadableByteStreamController(this) === false) { - throw byteStreamControllerBrandCheckException('enqueue'); - } - - if (this._closeRequested === true) { - throw new TypeError('stream is closed or draining'); - } - - var state = this._controlledReadableStream._state; - - if (state !== 'readable') { - throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be enqueued to'); - } - - if (!ArrayBuffer.isView(chunk)) { - throw new TypeError('You can only enqueue array buffer views when using a ReadableByteStreamController'); - } - - ReadableByteStreamControllerEnqueue(this, chunk); - } - }, { - key: 'error', - value: function error(e) { - if (IsReadableByteStreamController(this) === false) { - throw byteStreamControllerBrandCheckException('error'); - } - - var stream = this._controlledReadableStream; - - if (stream._state !== 'readable') { - throw new TypeError('The stream is ' + stream._state + ' and so cannot be errored'); - } - - ReadableByteStreamControllerError(this, e); - } - }, { - key: '__cancelSteps', - value: function __cancelSteps(reason) { - if (this._pendingPullIntos.length > 0) { - var firstDescriptor = this._pendingPullIntos[0]; - firstDescriptor.bytesFilled = 0; - } - - ResetQueue(this); - return PromiseInvokeOrNoop(this._underlyingByteSource, 'cancel', [reason]); - } - }, { - key: '__pullSteps', - value: function __pullSteps() { - var stream = this._controlledReadableStream; - assert(ReadableStreamHasDefaultReader(stream) === true); - - if (this._queueTotalSize > 0) { - assert(ReadableStreamGetNumReadRequests(stream) === 0); - - var entry = this._queue.shift(); - - this._queueTotalSize -= entry.byteLength; - ReadableByteStreamControllerHandleQueueDrain(this); - var view = void 0; - - try { - view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength); - } catch (viewE) { - return Promise.reject(viewE); - } - - return Promise.resolve(CreateIterResultObject(view, false)); - } - - var autoAllocateChunkSize = this._autoAllocateChunkSize; - - if (autoAllocateChunkSize !== undefined) { - var buffer = void 0; - - try { - buffer = new ArrayBuffer(autoAllocateChunkSize); - } catch (bufferE) { - return Promise.reject(bufferE); - } - - var pullIntoDescriptor = { - buffer: buffer, - byteOffset: 0, - byteLength: autoAllocateChunkSize, - bytesFilled: 0, - elementSize: 1, - ctor: Uint8Array, - readerType: 'default' - }; + Dict.merge = function (xref, dictArray) { + var mergedDict = new Dict(xref); - this._pendingPullIntos.push(pullIntoDescriptor); - } + for (var i = 0, ii = dictArray.length; i < ii; i++) { + var dict = dictArray[i]; - var promise = ReadableStreamAddReadRequest(stream); - ReadableByteStreamControllerCallPullIfNeeded(this); - return promise; + if (!isDict(dict)) { + continue; } - }, { - key: 'byobRequest', - get: function get() { - if (IsReadableByteStreamController(this) === false) { - throw byteStreamControllerBrandCheckException('byobRequest'); - } - if (this._byobRequest === undefined && this._pendingPullIntos.length > 0) { - var firstDescriptor = this._pendingPullIntos[0]; - var view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled); - this._byobRequest = new ReadableStreamBYOBRequest(this, view); - } - - return this._byobRequest; - } - }, { - key: 'desiredSize', - get: function get() { - if (IsReadableByteStreamController(this) === false) { - throw byteStreamControllerBrandCheckException('desiredSize'); + for (var keyName in dict._map) { + if (mergedDict._map[keyName] !== undefined) { + continue; } - return ReadableByteStreamControllerGetDesiredSize(this); - } - }]); - - return ReadableByteStreamController; - }(); - - function IsReadableByteStreamController(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_underlyingByteSource')) { - return false; - } - - return true; - } - - function IsReadableStreamBYOBRequest(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) { - return false; - } - - return true; - } - - function ReadableByteStreamControllerCallPullIfNeeded(controller) { - var shouldPull = ReadableByteStreamControllerShouldCallPull(controller); - - if (shouldPull === false) { - return undefined; - } - - if (controller._pulling === true) { - controller._pullAgain = true; - return undefined; - } - - assert(controller._pullAgain === false); - controller._pulling = true; - var pullPromise = PromiseInvokeOrNoop(controller._underlyingByteSource, 'pull', [controller]); - pullPromise.then(function () { - controller._pulling = false; - - if (controller._pullAgain === true) { - controller._pullAgain = false; - ReadableByteStreamControllerCallPullIfNeeded(controller); - } - }, function (e) { - if (controller._controlledReadableStream._state === 'readable') { - ReadableByteStreamControllerError(controller, e); - } - }).catch(rethrowAssertionErrorRejection); - return undefined; - } - - function ReadableByteStreamControllerClearPendingPullIntos(controller) { - ReadableByteStreamControllerInvalidateBYOBRequest(controller); - controller._pendingPullIntos = []; - } - - function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) { - assert(stream._state !== 'errored', 'state must not be errored'); - var done = false; - - if (stream._state === 'closed') { - assert(pullIntoDescriptor.bytesFilled === 0); - done = true; - } - - var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); - - if (pullIntoDescriptor.readerType === 'default') { - ReadableStreamFulfillReadRequest(stream, filledView, done); - } else { - assert(pullIntoDescriptor.readerType === 'byob'); - ReadableStreamFulfillReadIntoRequest(stream, filledView, done); - } - } - - function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) { - var bytesFilled = pullIntoDescriptor.bytesFilled; - var elementSize = pullIntoDescriptor.elementSize; - assert(bytesFilled <= pullIntoDescriptor.byteLength); - assert(bytesFilled % elementSize === 0); - return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize); - } - - function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) { - controller._queue.push({ - buffer: buffer, - byteOffset: byteOffset, - byteLength: byteLength - }); - - controller._queueTotalSize += byteLength; - } - - function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) { - var elementSize = pullIntoDescriptor.elementSize; - var currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize; - var maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled); - var maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy; - var maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize; - var totalBytesToCopyRemaining = maxBytesToCopy; - var ready = false; - - if (maxAlignedBytes > currentAlignedBytes) { - totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled; - ready = true; - } - - var queue = controller._queue; - - while (totalBytesToCopyRemaining > 0) { - var headOfQueue = queue[0]; - var bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength); - var destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; - ArrayBufferCopy(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy); - - if (headOfQueue.byteLength === bytesToCopy) { - queue.shift(); - } else { - headOfQueue.byteOffset += bytesToCopy; - headOfQueue.byteLength -= bytesToCopy; - } - - controller._queueTotalSize -= bytesToCopy; - ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor); - totalBytesToCopyRemaining -= bytesToCopy; - } - - if (ready === false) { - assert(controller._queueTotalSize === 0, 'queue must be empty'); - assert(pullIntoDescriptor.bytesFilled > 0); - assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize); - } - - return ready; - } - - function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) { - assert(controller._pendingPullIntos.length === 0 || controller._pendingPullIntos[0] === pullIntoDescriptor); - ReadableByteStreamControllerInvalidateBYOBRequest(controller); - pullIntoDescriptor.bytesFilled += size; - } - - function ReadableByteStreamControllerHandleQueueDrain(controller) { - assert(controller._controlledReadableStream._state === 'readable'); - - if (controller._queueTotalSize === 0 && controller._closeRequested === true) { - ReadableStreamClose(controller._controlledReadableStream); - } else { - ReadableByteStreamControllerCallPullIfNeeded(controller); - } - } - - function ReadableByteStreamControllerInvalidateBYOBRequest(controller) { - if (controller._byobRequest === undefined) { - return; - } - - controller._byobRequest._associatedReadableByteStreamController = undefined; - controller._byobRequest._view = undefined; - controller._byobRequest = undefined; - } - - function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) { - assert(controller._closeRequested === false); - - while (controller._pendingPullIntos.length > 0) { - if (controller._queueTotalSize === 0) { - return; - } - - var pullIntoDescriptor = controller._pendingPullIntos[0]; - - if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { - ReadableByteStreamControllerShiftPendingPullInto(controller); - ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor); - } - } - } - - function ReadableByteStreamControllerPullInto(controller, view) { - var stream = controller._controlledReadableStream; - var elementSize = 1; - - if (view.constructor !== DataView) { - elementSize = view.constructor.BYTES_PER_ELEMENT; - } - - var ctor = view.constructor; - var pullIntoDescriptor = { - buffer: view.buffer, - byteOffset: view.byteOffset, - byteLength: view.byteLength, - bytesFilled: 0, - elementSize: elementSize, - ctor: ctor, - readerType: 'byob' - }; - - if (controller._pendingPullIntos.length > 0) { - pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); - - controller._pendingPullIntos.push(pullIntoDescriptor); - - return ReadableStreamAddReadIntoRequest(stream); - } - - if (stream._state === 'closed') { - var emptyView = new view.constructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0); - return Promise.resolve(CreateIterResultObject(emptyView, true)); - } - - if (controller._queueTotalSize > 0) { - if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { - var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); - ReadableByteStreamControllerHandleQueueDrain(controller); - return Promise.resolve(CreateIterResultObject(filledView, false)); - } - - if (controller._closeRequested === true) { - var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); - ReadableByteStreamControllerError(controller, e); - return Promise.reject(e); - } - } - - pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); - - controller._pendingPullIntos.push(pullIntoDescriptor); - - var promise = ReadableStreamAddReadIntoRequest(stream); - ReadableByteStreamControllerCallPullIfNeeded(controller); - return promise; - } - - function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) { - firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer); - assert(firstDescriptor.bytesFilled === 0, 'bytesFilled must be 0'); - var stream = controller._controlledReadableStream; - - if (ReadableStreamHasBYOBReader(stream) === true) { - while (ReadableStreamGetNumReadIntoRequests(stream) > 0) { - var pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller); - ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor); - } - } - } - - function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) { - if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) { - throw new RangeError('bytesWritten out of range'); - } - - ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor); - - if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) { - return; - } - - ReadableByteStreamControllerShiftPendingPullInto(controller); - var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize; - - if (remainderSize > 0) { - var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; - var remainder = pullIntoDescriptor.buffer.slice(end - remainderSize, end); - ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength); - } - - pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); - pullIntoDescriptor.bytesFilled -= remainderSize; - ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor); - ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); - } - - function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) { - var firstDescriptor = controller._pendingPullIntos[0]; - var stream = controller._controlledReadableStream; - - if (stream._state === 'closed') { - if (bytesWritten !== 0) { - throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream'); - } - - ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor); - } else { - assert(stream._state === 'readable'); - ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor); - } - } - - function ReadableByteStreamControllerShiftPendingPullInto(controller) { - var descriptor = controller._pendingPullIntos.shift(); - - ReadableByteStreamControllerInvalidateBYOBRequest(controller); - return descriptor; - } - - function ReadableByteStreamControllerShouldCallPull(controller) { - var stream = controller._controlledReadableStream; - - if (stream._state !== 'readable') { - return false; - } - - if (controller._closeRequested === true) { - return false; - } - - if (controller._started === false) { - return false; - } - - if (ReadableStreamHasDefaultReader(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { - return true; - } - - if (ReadableStreamHasBYOBReader(stream) === true && ReadableStreamGetNumReadIntoRequests(stream) > 0) { - return true; - } - - if (ReadableByteStreamControllerGetDesiredSize(controller) > 0) { - return true; - } - - return false; - } - - function ReadableByteStreamControllerClose(controller) { - var stream = controller._controlledReadableStream; - assert(controller._closeRequested === false); - assert(stream._state === 'readable'); - - if (controller._queueTotalSize > 0) { - controller._closeRequested = true; - return; - } - - if (controller._pendingPullIntos.length > 0) { - var firstPendingPullInto = controller._pendingPullIntos[0]; - - if (firstPendingPullInto.bytesFilled > 0) { - var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); - ReadableByteStreamControllerError(controller, e); - throw e; - } - } - - ReadableStreamClose(stream); - } - - function ReadableByteStreamControllerEnqueue(controller, chunk) { - var stream = controller._controlledReadableStream; - assert(controller._closeRequested === false); - assert(stream._state === 'readable'); - var buffer = chunk.buffer; - var byteOffset = chunk.byteOffset; - var byteLength = chunk.byteLength; - var transferredBuffer = TransferArrayBuffer(buffer); - - if (ReadableStreamHasDefaultReader(stream) === true) { - if (ReadableStreamGetNumReadRequests(stream) === 0) { - ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); - } else { - assert(controller._queue.length === 0); - var transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength); - ReadableStreamFulfillReadRequest(stream, transferredView, false); - } - } else if (ReadableStreamHasBYOBReader(stream) === true) { - ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); - ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); - } else { - assert(IsReadableStreamLocked(stream) === false, 'stream must not be locked'); - ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); - } - } - - function ReadableByteStreamControllerError(controller, e) { - var stream = controller._controlledReadableStream; - assert(stream._state === 'readable'); - ReadableByteStreamControllerClearPendingPullIntos(controller); - ResetQueue(controller); - ReadableStreamError(stream, e); - } - - function ReadableByteStreamControllerGetDesiredSize(controller) { - var stream = controller._controlledReadableStream; - var state = stream._state; - - if (state === 'errored') { - return null; - } - - if (state === 'closed') { - return 0; - } - - return controller._strategyHWM - controller._queueTotalSize; - } - - function ReadableByteStreamControllerRespond(controller, bytesWritten) { - bytesWritten = Number(bytesWritten); - - if (IsFiniteNonNegativeNumber(bytesWritten) === false) { - throw new RangeError('bytesWritten must be a finite'); - } - - assert(controller._pendingPullIntos.length > 0); - ReadableByteStreamControllerRespondInternal(controller, bytesWritten); - } - - function ReadableByteStreamControllerRespondWithNewView(controller, view) { - assert(controller._pendingPullIntos.length > 0); - var firstDescriptor = controller._pendingPullIntos[0]; - - if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) { - throw new RangeError('The region specified by view does not match byobRequest'); - } - - if (firstDescriptor.byteLength !== view.byteLength) { - throw new RangeError('The buffer of view has different capacity than byobRequest'); - } - - firstDescriptor.buffer = view.buffer; - ReadableByteStreamControllerRespondInternal(controller, view.byteLength); - } - - function streamBrandCheckException(name) { - return new TypeError('ReadableStream.prototype.' + name + ' can only be used on a ReadableStream'); - } - - function readerLockException(name) { - return new TypeError('Cannot ' + name + ' a stream using a released reader'); - } - - function defaultReaderBrandCheckException(name) { - return new TypeError('ReadableStreamDefaultReader.prototype.' + name + ' can only be used on a ReadableStreamDefaultReader'); - } - - function defaultReaderClosedPromiseInitialize(reader) { - reader._closedPromise = new Promise(function (resolve, reject) { - reader._closedPromise_resolve = resolve; - reader._closedPromise_reject = reject; - }); - } - - function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) { - reader._closedPromise = Promise.reject(reason); - reader._closedPromise_resolve = undefined; - reader._closedPromise_reject = undefined; - } - - function defaultReaderClosedPromiseInitializeAsResolved(reader) { - reader._closedPromise = Promise.resolve(undefined); - reader._closedPromise_resolve = undefined; - reader._closedPromise_reject = undefined; - } - - function defaultReaderClosedPromiseReject(reader, reason) { - assert(reader._closedPromise_resolve !== undefined); - assert(reader._closedPromise_reject !== undefined); - - reader._closedPromise_reject(reason); - - reader._closedPromise_resolve = undefined; - reader._closedPromise_reject = undefined; - } - - function defaultReaderClosedPromiseResetToRejected(reader, reason) { - assert(reader._closedPromise_resolve === undefined); - assert(reader._closedPromise_reject === undefined); - reader._closedPromise = Promise.reject(reason); - } - - function defaultReaderClosedPromiseResolve(reader) { - assert(reader._closedPromise_resolve !== undefined); - assert(reader._closedPromise_reject !== undefined); - - reader._closedPromise_resolve(undefined); - - reader._closedPromise_resolve = undefined; - reader._closedPromise_reject = undefined; - } - - function byobReaderBrandCheckException(name) { - return new TypeError('ReadableStreamBYOBReader.prototype.' + name + ' can only be used on a ReadableStreamBYOBReader'); - } - - function defaultControllerBrandCheckException(name) { - return new TypeError('ReadableStreamDefaultController.prototype.' + name + ' can only be used on a ReadableStreamDefaultController'); - } - - function byobRequestBrandCheckException(name) { - return new TypeError('ReadableStreamBYOBRequest.prototype.' + name + ' can only be used on a ReadableStreamBYOBRequest'); - } - - function byteStreamControllerBrandCheckException(name) { - return new TypeError('ReadableByteStreamController.prototype.' + name + ' can only be used on a ReadableByteStreamController'); - } - - function ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise) { - try { - Promise.prototype.then.call(promise, undefined, function () {}); - } catch (e) {} - } -}, function (module, exports, __w_pdfjs_require__) { - "use strict"; - - var transformStream = __w_pdfjs_require__(6); - - var readableStream = __w_pdfjs_require__(4); - - var writableStream = __w_pdfjs_require__(2); - - exports.TransformStream = transformStream.TransformStream; - exports.ReadableStream = readableStream.ReadableStream; - exports.IsReadableStreamDisturbed = readableStream.IsReadableStreamDisturbed; - exports.ReadableStreamDefaultControllerClose = readableStream.ReadableStreamDefaultControllerClose; - exports.ReadableStreamDefaultControllerEnqueue = readableStream.ReadableStreamDefaultControllerEnqueue; - exports.ReadableStreamDefaultControllerError = readableStream.ReadableStreamDefaultControllerError; - exports.ReadableStreamDefaultControllerGetDesiredSize = readableStream.ReadableStreamDefaultControllerGetDesiredSize; - exports.AcquireWritableStreamDefaultWriter = writableStream.AcquireWritableStreamDefaultWriter; - exports.IsWritableStream = writableStream.IsWritableStream; - exports.IsWritableStreamLocked = writableStream.IsWritableStreamLocked; - exports.WritableStream = writableStream.WritableStream; - exports.WritableStreamAbort = writableStream.WritableStreamAbort; - exports.WritableStreamDefaultControllerError = writableStream.WritableStreamDefaultControllerError; - exports.WritableStreamDefaultWriterCloseWithErrorPropagation = writableStream.WritableStreamDefaultWriterCloseWithErrorPropagation; - exports.WritableStreamDefaultWriterRelease = writableStream.WritableStreamDefaultWriterRelease; - exports.WritableStreamDefaultWriterWrite = writableStream.WritableStreamDefaultWriterWrite; -}, function (module, exports, __w_pdfjs_require__) { - "use strict"; - - 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); + mergedDict._map[keyName] = dict._map[keyName]; } } - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; - }(); - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - var _require = __w_pdfjs_require__(1), - assert = _require.assert; - - var _require2 = __w_pdfjs_require__(0), - InvokeOrNoop = _require2.InvokeOrNoop, - PromiseInvokeOrPerformFallback = _require2.PromiseInvokeOrPerformFallback, - PromiseInvokeOrNoop = _require2.PromiseInvokeOrNoop, - typeIsObject = _require2.typeIsObject; - - var _require3 = __w_pdfjs_require__(4), - ReadableStream = _require3.ReadableStream, - ReadableStreamDefaultControllerClose = _require3.ReadableStreamDefaultControllerClose, - ReadableStreamDefaultControllerEnqueue = _require3.ReadableStreamDefaultControllerEnqueue, - ReadableStreamDefaultControllerError = _require3.ReadableStreamDefaultControllerError, - ReadableStreamDefaultControllerGetDesiredSize = _require3.ReadableStreamDefaultControllerGetDesiredSize; - - var _require4 = __w_pdfjs_require__(2), - WritableStream = _require4.WritableStream, - WritableStreamDefaultControllerError = _require4.WritableStreamDefaultControllerError; - - function TransformStreamCloseReadable(transformStream) { - if (transformStream._errored === true) { - throw new TypeError('TransformStream is already errored'); - } - - if (transformStream._readableClosed === true) { - throw new TypeError('Readable side is already closed'); - } - - TransformStreamCloseReadableInternal(transformStream); - } - - function TransformStreamEnqueueToReadable(transformStream, chunk) { - if (transformStream._errored === true) { - throw new TypeError('TransformStream is already errored'); - } - - if (transformStream._readableClosed === true) { - throw new TypeError('Readable side is already closed'); - } - - var controller = transformStream._readableController; - - try { - ReadableStreamDefaultControllerEnqueue(controller, chunk); - } catch (e) { - transformStream._readableClosed = true; - TransformStreamErrorIfNeeded(transformStream, e); - throw transformStream._storedError; - } - - var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller); - var maybeBackpressure = desiredSize <= 0; - - if (maybeBackpressure === true && transformStream._backpressure === false) { - TransformStreamSetBackpressure(transformStream, true); - } - } - - function TransformStreamError(transformStream, e) { - if (transformStream._errored === true) { - throw new TypeError('TransformStream is already errored'); - } - - TransformStreamErrorInternal(transformStream, e); - } - - function TransformStreamCloseReadableInternal(transformStream) { - assert(transformStream._errored === false); - assert(transformStream._readableClosed === false); - - try { - ReadableStreamDefaultControllerClose(transformStream._readableController); - } catch (e) { - assert(false); - } - - transformStream._readableClosed = true; - } - - function TransformStreamErrorIfNeeded(transformStream, e) { - if (transformStream._errored === false) { - TransformStreamErrorInternal(transformStream, e); - } - } - - function TransformStreamErrorInternal(transformStream, e) { - assert(transformStream._errored === false); - transformStream._errored = true; - transformStream._storedError = e; - - if (transformStream._writableDone === false) { - WritableStreamDefaultControllerError(transformStream._writableController, e); - } - - if (transformStream._readableClosed === false) { - ReadableStreamDefaultControllerError(transformStream._readableController, e); - } - } - - function TransformStreamReadableReadyPromise(transformStream) { - assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); - - if (transformStream._backpressure === false) { - return Promise.resolve(); - } - - assert(transformStream._backpressure === true, '_backpressure should have been initialized'); - return transformStream._backpressureChangePromise; - } - - function TransformStreamSetBackpressure(transformStream, backpressure) { - assert(transformStream._backpressure !== backpressure, 'TransformStreamSetBackpressure() should be called only when backpressure is changed'); - - if (transformStream._backpressureChangePromise !== undefined) { - transformStream._backpressureChangePromise_resolve(backpressure); - } - - transformStream._backpressureChangePromise = new Promise(function (resolve) { - transformStream._backpressureChangePromise_resolve = resolve; - }); - - transformStream._backpressureChangePromise.then(function (resolution) { - assert(resolution !== backpressure, '_backpressureChangePromise should be fulfilled only when backpressure is changed'); - }); - - transformStream._backpressure = backpressure; - } - - function TransformStreamDefaultTransform(chunk, transformStreamController) { - var transformStream = transformStreamController._controlledTransformStream; - TransformStreamEnqueueToReadable(transformStream, chunk); - return Promise.resolve(); - } - - function TransformStreamTransform(transformStream, chunk) { - assert(transformStream._errored === false); - assert(transformStream._transforming === false); - assert(transformStream._backpressure === false); - transformStream._transforming = true; - var transformer = transformStream._transformer; - var controller = transformStream._transformStreamController; - var transformPromise = PromiseInvokeOrPerformFallback(transformer, 'transform', [chunk, controller], TransformStreamDefaultTransform, [chunk, controller]); - return transformPromise.then(function () { - transformStream._transforming = false; - return TransformStreamReadableReadyPromise(transformStream); - }, function (e) { - TransformStreamErrorIfNeeded(transformStream, e); - return Promise.reject(e); - }); - } - - function IsTransformStreamDefaultController(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) { - return false; - } + return mergedDict; + }; - return true; - } + return Dict; +}(); - function IsTransformStream(x) { - if (!typeIsObject(x)) { - return false; - } +exports.Dict = Dict; - if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) { - return false; - } +var Ref = function RefClosure() { + var refCache = Object.create(null); - return true; + function Ref(num, gen) { + this.num = num; + this.gen = gen; } - var TransformStreamSink = function () { - function TransformStreamSink(transformStream, startPromise) { - _classCallCheck(this, TransformStreamSink); - - this._transformStream = transformStream; - this._startPromise = startPromise; - } - - _createClass(TransformStreamSink, [{ - key: 'start', - value: function start(c) { - var transformStream = this._transformStream; - transformStream._writableController = c; - return this._startPromise.then(function () { - return TransformStreamReadableReadyPromise(transformStream); - }); - } - }, { - key: 'write', - value: function write(chunk) { - var transformStream = this._transformStream; - return TransformStreamTransform(transformStream, chunk); - } - }, { - key: 'abort', - value: function abort() { - var transformStream = this._transformStream; - transformStream._writableDone = true; - TransformStreamErrorInternal(transformStream, new TypeError('Writable side aborted')); - } - }, { - key: 'close', - value: function close() { - var transformStream = this._transformStream; - assert(transformStream._transforming === false); - transformStream._writableDone = true; - var flushPromise = PromiseInvokeOrNoop(transformStream._transformer, 'flush', [transformStream._transformStreamController]); - return flushPromise.then(function () { - if (transformStream._errored === true) { - return Promise.reject(transformStream._storedError); - } - - if (transformStream._readableClosed === false) { - TransformStreamCloseReadableInternal(transformStream); - } - - return Promise.resolve(); - }).catch(function (r) { - TransformStreamErrorIfNeeded(transformStream, r); - return Promise.reject(transformStream._storedError); - }); - } - }]); - - return TransformStreamSink; - }(); - - var TransformStreamSource = function () { - function TransformStreamSource(transformStream, startPromise) { - _classCallCheck(this, TransformStreamSource); - - this._transformStream = transformStream; - this._startPromise = startPromise; - } - - _createClass(TransformStreamSource, [{ - key: 'start', - value: function start(c) { - var transformStream = this._transformStream; - transformStream._readableController = c; - return this._startPromise.then(function () { - assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); - - if (transformStream._backpressure === true) { - return Promise.resolve(); - } - - assert(transformStream._backpressure === false, '_backpressure should have been initialized'); - return transformStream._backpressureChangePromise; - }); - } - }, { - key: 'pull', - value: function pull() { - var transformStream = this._transformStream; - assert(transformStream._backpressure === true, 'pull() should be never called while _backpressure is false'); - assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); - TransformStreamSetBackpressure(transformStream, false); - return transformStream._backpressureChangePromise; - } - }, { - key: 'cancel', - value: function cancel() { - var transformStream = this._transformStream; - transformStream._readableClosed = true; - TransformStreamErrorInternal(transformStream, new TypeError('Readable side canceled')); - } - }]); - - return TransformStreamSource; - }(); - - var TransformStreamDefaultController = function () { - function TransformStreamDefaultController(transformStream) { - _classCallCheck(this, TransformStreamDefaultController); - - if (IsTransformStream(transformStream) === false) { - throw new TypeError('TransformStreamDefaultController can only be ' + 'constructed with a TransformStream instance'); - } - - if (transformStream._transformStreamController !== undefined) { - throw new TypeError('TransformStreamDefaultController instances can ' + 'only be created by the TransformStream constructor'); - } - - this._controlledTransformStream = transformStream; - } - - _createClass(TransformStreamDefaultController, [{ - key: 'enqueue', - value: function enqueue(chunk) { - if (IsTransformStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('enqueue'); - } - - TransformStreamEnqueueToReadable(this._controlledTransformStream, chunk); - } - }, { - key: 'close', - value: function close() { - if (IsTransformStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('close'); - } - - TransformStreamCloseReadable(this._controlledTransformStream); - } - }, { - key: 'error', - value: function error(reason) { - if (IsTransformStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('error'); - } - - TransformStreamError(this._controlledTransformStream, reason); - } - }, { - key: 'desiredSize', - get: function get() { - if (IsTransformStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('desiredSize'); - } - - var transformStream = this._controlledTransformStream; - var readableController = transformStream._readableController; - return ReadableStreamDefaultControllerGetDesiredSize(readableController); + Ref.prototype = { + toString: function Ref_toString() { + if (this.gen === 0) { + return "".concat(this.num, "R"); } - }]); - return TransformStreamDefaultController; - }(); - - var TransformStream = function () { - function TransformStream() { - var transformer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - - _classCallCheck(this, TransformStream); - - this._transformer = transformer; - var readableStrategy = transformer.readableStrategy, - writableStrategy = transformer.writableStrategy; - this._transforming = false; - this._errored = false; - this._storedError = undefined; - this._writableController = undefined; - this._readableController = undefined; - this._transformStreamController = undefined; - this._writableDone = false; - this._readableClosed = false; - this._backpressure = undefined; - this._backpressureChangePromise = undefined; - this._backpressureChangePromise_resolve = undefined; - this._transformStreamController = new TransformStreamDefaultController(this); - var startPromise_resolve = void 0; - var startPromise = new Promise(function (resolve) { - startPromise_resolve = resolve; - }); - var source = new TransformStreamSource(this, startPromise); - this._readable = new ReadableStream(source, readableStrategy); - var sink = new TransformStreamSink(this, startPromise); - this._writable = new WritableStream(sink, writableStrategy); - assert(this._writableController !== undefined); - assert(this._readableController !== undefined); - var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(this._readableController); - TransformStreamSetBackpressure(this, desiredSize <= 0); - var transformStream = this; - var startResult = InvokeOrNoop(transformer, 'start', [transformStream._transformStreamController]); - startPromise_resolve(startResult); - startPromise.catch(function (e) { - if (transformStream._errored === false) { - transformStream._errored = true; - transformStream._storedError = e; - } - }); + return "".concat(this.num, "R").concat(this.gen); } - - _createClass(TransformStream, [{ - key: 'readable', - get: function get() { - if (IsTransformStream(this) === false) { - throw streamBrandCheckException('readable'); - } - - return this._readable; - } - }, { - key: 'writable', - get: function get() { - if (IsTransformStream(this) === false) { - throw streamBrandCheckException('writable'); - } - - return this._writable; - } - }]); - - return TransformStream; - }(); - - module.exports = { - TransformStream: TransformStream }; - function defaultControllerBrandCheckException(name) { - return new TypeError('TransformStreamDefaultController.prototype.' + name + ' can only be used on a TransformStreamDefaultController'); - } - - function streamBrandCheckException(name) { - return new TypeError('TransformStream.prototype.' + name + ' can only be used on a TransformStream'); - } -}, function (module, exports, __w_pdfjs_require__) { - module.exports = __w_pdfjs_require__(5); -}])); - -/***/ }), -/* 149 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -function _typeof(obj) { 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 isURLSupported = false; - - try { - if (typeof URL === 'function' && _typeof(URL.prototype) === 'object' && 'origin' in URL.prototype) { - var u = new URL('b', 'http://a'); - u.pathname = 'c%20d'; - isURLSupported = u.href === 'http://a/c%20d'; - } - } catch (ex) {} - - if (isURLSupported) { - exports.URL = URL; - } else { - var PolyfillURL = __w_pdfjs_require__(150).URL; - - var OriginalURL = __w_pdfjs_require__(8).URL; - - if (OriginalURL) { - PolyfillURL.createObjectURL = function (blob) { - return OriginalURL.createObjectURL.apply(OriginalURL, arguments); - }; - - PolyfillURL.revokeObjectURL = function (url) { - OriginalURL.revokeObjectURL(url); - }; - } - - exports.URL = PolyfillURL; - } -} - -/***/ }), -/* 150 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -(function URLConstructorClosure() { - 'use strict'; - - var relative = Object.create(null); - relative['ftp'] = 21; - relative['file'] = 0; - relative['gopher'] = 70; - relative['http'] = 80; - relative['https'] = 443; - relative['ws'] = 80; - relative['wss'] = 443; - var relativePathDotMapping = Object.create(null); - relativePathDotMapping['%2e'] = '.'; - relativePathDotMapping['.%2e'] = '..'; - relativePathDotMapping['%2e.'] = '..'; - relativePathDotMapping['%2e%2e'] = '..'; - - function isRelativeScheme(scheme) { - return relative[scheme] !== undefined; - } - - function invalid() { - clear.call(this); - this._isInvalid = true; - } - - function IDNAToASCII(h) { - if (h === '') { - invalid.call(this); - } - - return h.toLowerCase(); - } - - function percentEscape(c) { - var unicode = c.charCodeAt(0); - - if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) { - return c; - } - - return encodeURIComponent(c); - } - - function percentEscapeQuery(c) { - var unicode = c.charCodeAt(0); - - if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) { - return c; - } - - return encodeURIComponent(c); - } - - var EOF, - ALPHA = /[a-zA-Z]/, - ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/; - - function parse(input, stateOverride, base) { - function err(message) { - errors.push(message); - } - - var state = stateOverride || 'scheme start', - cursor = 0, - buffer = '', - seenAt = false, - seenBracket = false, - errors = []; - - loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) { - var c = input[cursor]; - - switch (state) { - case 'scheme start': - if (c && ALPHA.test(c)) { - buffer += c.toLowerCase(); - state = 'scheme'; - } else if (!stateOverride) { - buffer = ''; - state = 'no scheme'; - continue; - } else { - err('Invalid scheme.'); - break loop; - } - - break; - - case 'scheme': - if (c && ALPHANUMERIC.test(c)) { - buffer += c.toLowerCase(); - } else if (c === ':') { - this._scheme = buffer; - buffer = ''; - - if (stateOverride) { - break loop; - } - - if (isRelativeScheme(this._scheme)) { - this._isRelative = true; - } - - if (this._scheme === 'file') { - state = 'relative'; - } else if (this._isRelative && base && base._scheme === this._scheme) { - state = 'relative or authority'; - } else if (this._isRelative) { - state = 'authority first slash'; - } else { - state = 'scheme data'; - } - } else if (!stateOverride) { - buffer = ''; - cursor = 0; - state = 'no scheme'; - continue; - } else if (c === EOF) { - break loop; - } else { - err('Code point not allowed in scheme: ' + c); - break loop; - } - - break; - - case 'scheme data': - if (c === '?') { - this._query = '?'; - state = 'query'; - } else if (c === '#') { - this._fragment = '#'; - state = 'fragment'; - } else { - if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') { - this._schemeData += percentEscape(c); - } - } - - break; - - case 'no scheme': - if (!base || !isRelativeScheme(base._scheme)) { - err('Missing scheme.'); - invalid.call(this); - } else { - state = 'relative'; - continue; - } - - break; - - case 'relative or authority': - if (c === '/' && input[cursor + 1] === '/') { - state = 'authority ignore slashes'; - } else { - err('Expected /, got: ' + c); - state = 'relative'; - continue; - } - - break; - - case 'relative': - this._isRelative = true; - - if (this._scheme !== 'file') { - this._scheme = base._scheme; - } - - if (c === EOF) { - this._host = base._host; - this._port = base._port; - this._path = base._path.slice(); - this._query = base._query; - this._username = base._username; - this._password = base._password; - break loop; - } else if (c === '/' || c === '\\') { - if (c === '\\') { - err('\\ is an invalid code point.'); - } - - state = 'relative slash'; - } else if (c === '?') { - this._host = base._host; - this._port = base._port; - this._path = base._path.slice(); - this._query = '?'; - this._username = base._username; - this._password = base._password; - state = 'query'; - } else if (c === '#') { - this._host = base._host; - this._port = base._port; - this._path = base._path.slice(); - this._query = base._query; - this._fragment = '#'; - this._username = base._username; - this._password = base._password; - state = 'fragment'; - } else { - var nextC = input[cursor + 1]; - var nextNextC = input[cursor + 2]; - - if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') { - this._host = base._host; - this._port = base._port; - this._username = base._username; - this._password = base._password; - this._path = base._path.slice(); - - this._path.pop(); - } - - state = 'relative path'; - continue; - } - - break; - - case 'relative slash': - if (c === '/' || c === '\\') { - if (c === '\\') { - err('\\ is an invalid code point.'); - } - - if (this._scheme === 'file') { - state = 'file host'; - } else { - state = 'authority ignore slashes'; - } - } else { - if (this._scheme !== 'file') { - this._host = base._host; - this._port = base._port; - this._username = base._username; - this._password = base._password; - } - - state = 'relative path'; - continue; - } - - break; - - case 'authority first slash': - if (c === '/') { - state = 'authority second slash'; - } else { - err('Expected \'/\', got: ' + c); - state = 'authority ignore slashes'; - continue; - } - - break; - - case 'authority second slash': - state = 'authority ignore slashes'; - - if (c !== '/') { - err('Expected \'/\', got: ' + c); - continue; - } - - break; - - case 'authority ignore slashes': - if (c !== '/' && c !== '\\') { - state = 'authority'; - continue; - } else { - err('Expected authority, got: ' + c); - } - - break; - - case 'authority': - if (c === '@') { - if (seenAt) { - err('@ already seen.'); - buffer += '%40'; - } - - seenAt = true; - - for (var i = 0; i < buffer.length; i++) { - var cp = buffer[i]; - - if (cp === '\t' || cp === '\n' || cp === '\r') { - err('Invalid whitespace in authority.'); - continue; - } - - if (cp === ':' && this._password === null) { - this._password = ''; - continue; - } - - var tempC = percentEscape(cp); - - if (this._password !== null) { - this._password += tempC; - } else { - this._username += tempC; - } - } - - buffer = ''; - } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') { - cursor -= buffer.length; - buffer = ''; - state = 'host'; - continue; - } else { - buffer += c; - } - - break; - - case 'file host': - if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') { - if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) { - state = 'relative path'; - } else if (buffer.length === 0) { - state = 'relative path start'; - } else { - this._host = IDNAToASCII.call(this, buffer); - buffer = ''; - state = 'relative path start'; - } - - continue; - } else if (c === '\t' || c === '\n' || c === '\r') { - err('Invalid whitespace in file host.'); - } else { - buffer += c; - } - - break; - - case 'host': - case 'hostname': - if (c === ':' && !seenBracket) { - this._host = IDNAToASCII.call(this, buffer); - buffer = ''; - state = 'port'; - - if (stateOverride === 'hostname') { - break loop; - } - } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') { - this._host = IDNAToASCII.call(this, buffer); - buffer = ''; - state = 'relative path start'; - - if (stateOverride) { - break loop; - } - - continue; - } else if (c !== '\t' && c !== '\n' && c !== '\r') { - if (c === '[') { - seenBracket = true; - } else if (c === ']') { - seenBracket = false; - } - - buffer += c; - } else { - err('Invalid code point in host/hostname: ' + c); - } - - break; - - case 'port': - if (/[0-9]/.test(c)) { - buffer += c; - } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) { - if (buffer !== '') { - var temp = parseInt(buffer, 10); - - if (temp !== relative[this._scheme]) { - this._port = temp + ''; - } - - buffer = ''; - } - - if (stateOverride) { - break loop; - } - - state = 'relative path start'; - continue; - } else if (c === '\t' || c === '\n' || c === '\r') { - err('Invalid code point in port: ' + c); - } else { - invalid.call(this); - } - - break; - - case 'relative path start': - if (c === '\\') { - err('\'\\\' not allowed in path.'); - } - - state = 'relative path'; - - if (c !== '/' && c !== '\\') { - continue; - } - - break; - - case 'relative path': - if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) { - if (c === '\\') { - err('\\ not allowed in relative path.'); - } - - var tmp; - - if (tmp = relativePathDotMapping[buffer.toLowerCase()]) { - buffer = tmp; - } - - if (buffer === '..') { - this._path.pop(); - - if (c !== '/' && c !== '\\') { - this._path.push(''); - } - } else if (buffer === '.' && c !== '/' && c !== '\\') { - this._path.push(''); - } else if (buffer !== '.') { - if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') { - buffer = buffer[0] + ':'; - } - - this._path.push(buffer); - } - - buffer = ''; - - if (c === '?') { - this._query = '?'; - state = 'query'; - } else if (c === '#') { - this._fragment = '#'; - state = 'fragment'; - } - } else if (c !== '\t' && c !== '\n' && c !== '\r') { - buffer += percentEscape(c); - } - - break; - - case 'query': - if (!stateOverride && c === '#') { - this._fragment = '#'; - state = 'fragment'; - } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') { - this._query += percentEscapeQuery(c); - } - - break; - - case 'fragment': - if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') { - this._fragment += c; - } - - break; - } + Ref.get = function (num, gen) { + var key = gen === 0 ? "".concat(num, "R") : "".concat(num, "R").concat(gen); + var refValue = refCache[key]; + return refValue ? refValue : refCache[key] = new Ref(num, gen); + }; - cursor++; - } - } + Ref._clearCache = function () { + refCache = Object.create(null); + }; - function clear() { - this._scheme = ''; - this._schemeData = ''; - this._username = ''; - this._password = null; - this._host = ''; - this._port = ''; - this._path = []; - this._query = ''; - this._fragment = ''; - this._isInvalid = false; - this._isRelative = false; - } + return Ref; +}(); - function JURL(url, base) { - if (base !== undefined && !(base instanceof JURL)) { - base = new JURL(String(base)); - } +exports.Ref = Ref; - this._url = url; - clear.call(this); - var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, ''); - parse.call(this, input, null, base); +var RefSet = function RefSetClosure() { + function RefSet() { + this.dict = Object.create(null); } - JURL.prototype = { - toString: function toString() { - return this.href; - }, - - get href() { - if (this._isInvalid) { - return this._url; - } - - var authority = ''; - - if (this._username !== '' || this._password !== null) { - authority = this._username + (this._password !== null ? ':' + this._password : '') + '@'; - } - - return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment; - }, - - set href(value) { - clear.call(this); - parse.call(this, value); - }, - - get protocol() { - return this._scheme + ':'; - }, - - set protocol(value) { - if (this._isInvalid) { - return; - } - - parse.call(this, value + ':', 'scheme start'); - }, - - get host() { - return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host; - }, - - set host(value) { - if (this._isInvalid || !this._isRelative) { - return; - } - - parse.call(this, value, 'host'); - }, - - get hostname() { - return this._host; + RefSet.prototype = { + has: function RefSet_has(ref) { + return ref.toString() in this.dict; }, - - set hostname(value) { - if (this._isInvalid || !this._isRelative) { - return; - } - - parse.call(this, value, 'hostname'); + put: function RefSet_put(ref) { + this.dict[ref.toString()] = true; }, + remove: function RefSet_remove(ref) { + delete this.dict[ref.toString()]; + } + }; + return RefSet; +}(); - get port() { - return this._port; - }, +exports.RefSet = RefSet; - set port(value) { - if (this._isInvalid || !this._isRelative) { - return; - } +var RefSetCache = function RefSetCacheClosure() { + function RefSetCache() { + this.dict = Object.create(null); + } - parse.call(this, value, 'port'); + RefSetCache.prototype = { + get: function RefSetCache_get(ref) { + return this.dict[ref.toString()]; }, - - get pathname() { - return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData; + has: function RefSetCache_has(ref) { + return ref.toString() in this.dict; }, - - set pathname(value) { - if (this._isInvalid || !this._isRelative) { - return; - } - - this._path = []; - parse.call(this, value, 'relative path start'); + put: function RefSetCache_put(ref, obj) { + this.dict[ref.toString()] = obj; }, - - get search() { - return this._isInvalid || !this._query || this._query === '?' ? '' : this._query; + putAlias: function RefSetCache_putAlias(ref, aliasRef) { + this.dict[ref.toString()] = this.get(aliasRef); }, - - set search(value) { - if (this._isInvalid || !this._isRelative) { - return; - } - - this._query = '?'; - - if (value[0] === '?') { - value = value.slice(1); + forEach: function RefSetCache_forEach(fn, thisArg) { + for (var i in this.dict) { + fn.call(thisArg, this.dict[i]); } - - parse.call(this, value, 'query'); - }, - - get hash() { - return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment; }, + clear: function RefSetCache_clear() { + this.dict = Object.create(null); + } + }; + return RefSetCache; +}(); - set hash(value) { - if (this._isInvalid) { - return; - } - - this._fragment = '#'; - - if (value[0] === '#') { - value = value.slice(1); - } +exports.RefSetCache = RefSetCache; - parse.call(this, value, 'fragment'); - }, +function isEOF(v) { + return v === EOF; +} - get origin() { - var host; +function isName(v, name) { + return v instanceof Name && (name === undefined || v.name === name); +} - if (this._isInvalid || !this._scheme) { - return ''; - } +function isCmd(v, cmd) { + return v instanceof Cmd && (cmd === undefined || v.cmd === cmd); +} - switch (this._scheme) { - case 'data': - case 'file': - case 'javascript': - case 'mailto': - return 'null'; +function isDict(v, type) { + return v instanceof Dict && (type === undefined || isName(v.get('Type'), type)); +} - case 'blob': - try { - return new JURL(this._schemeData).origin || 'null'; - } catch (_) {} +function isRef(v) { + return v instanceof Ref; +} - return 'null'; - } +function isRefsEqual(v1, v2) { + return v1.num === v2.num && v1.gen === v2.gen; +} - host = this.host; +function isStream(v) { + return _typeof(v) === 'object' && v !== null && v.getBytes !== undefined; +} - if (!host) { - return ''; - } +function clearPrimitiveCaches() { + Cmd._clearCache(); - return this._scheme + '://' + host; - } + Name._clearCache(); - }; - exports.URL = JURL; -})(); + Ref._clearCache(); +} /***/ }), -/* 151 */ +/* 184 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -11177,15 +11260,17 @@ exports.NetworkPdfManager = exports.LocalPdfManager = void 0; var _regenerator = _interopRequireDefault(__w_pdfjs_require__(2)); -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _chunked_stream = __w_pdfjs_require__(152); +var _chunked_stream = __w_pdfjs_require__(185); -var _document = __w_pdfjs_require__(153); +var _core_utils = __w_pdfjs_require__(186); -var _stream = __w_pdfjs_require__(157); +var _document = __w_pdfjs_require__(187); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +var _stream = __w_pdfjs_require__(190); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _typeof(obj) { 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); } @@ -11193,12 +11278,12 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } -function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } - 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); }); }; } @@ -11260,8 +11345,8 @@ function () { value: function () { var _ensure = _asyncToGenerator( /*#__PURE__*/ - _regenerator.default.mark(function _callee(obj, prop, args) { - return _regenerator.default.wrap(function _callee$(_context) { + _regenerator["default"].mark(function _callee(obj, prop, args) { + return _regenerator["default"].wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: @@ -11272,7 +11357,7 @@ function () { return _context.stop(); } } - }, _callee, this); + }, _callee); })); function ensure(_x, _x2, _x3) { @@ -11303,7 +11388,7 @@ function () { } }, { key: "terminate", - value: function terminate() { + value: function terminate(reason) { (0, _util.unreachable)('Abstract method `terminate` called'); } }, { @@ -11354,7 +11439,7 @@ function (_BasePdfManager) { _this._docBaseUrl = docBaseUrl; _this.evaluatorOptions = evaluatorOptions; var stream = new _stream.Stream(data); - _this.pdfDocument = new _document.PDFDocument(_assertThisInitialized(_assertThisInitialized(_this)), stream); + _this.pdfDocument = new _document.PDFDocument(_assertThisInitialized(_this), stream); _this._loadedStreamPromise = Promise.resolve(stream); return _this; } @@ -11364,9 +11449,9 @@ function (_BasePdfManager) { value: function () { var _ensure2 = _asyncToGenerator( /*#__PURE__*/ - _regenerator.default.mark(function _callee2(obj, prop, args) { + _regenerator["default"].mark(function _callee2(obj, prop, args) { var value; - return _regenerator.default.wrap(function _callee2$(_context2) { + return _regenerator["default"].wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: @@ -11387,7 +11472,7 @@ function (_BasePdfManager) { return _context2.stop(); } } - }, _callee2, this); + }, _callee2); })); function ensure(_x4, _x5, _x6) { @@ -11411,7 +11496,7 @@ function (_BasePdfManager) { } }, { key: "terminate", - value: function terminate() {} + value: function terminate(reason) {} }]); return LocalPdfManager; @@ -11441,7 +11526,7 @@ function (_BasePdfManager2) { disableAutoFetch: args.disableAutoFetch, rangeChunkSize: args.rangeChunkSize }); - _this2.pdfDocument = new _document.PDFDocument(_assertThisInitialized(_assertThisInitialized(_this2)), _this2.streamManager.getStream()); + _this2.pdfDocument = new _document.PDFDocument(_assertThisInitialized(_this2), _this2.streamManager.getStream()); return _this2; } @@ -11450,9 +11535,9 @@ function (_BasePdfManager2) { value: function () { var _ensure3 = _asyncToGenerator( /*#__PURE__*/ - _regenerator.default.mark(function _callee3(obj, prop, args) { + _regenerator["default"].mark(function _callee3(obj, prop, args) { var value; - return _regenerator.default.wrap(function _callee3$(_context3) { + return _regenerator["default"].wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: @@ -11473,7 +11558,7 @@ function (_BasePdfManager2) { _context3.prev = 7; _context3.t0 = _context3["catch"](0); - if (_context3.t0 instanceof _util.MissingDataException) { + if (_context3.t0 instanceof _core_utils.MissingDataException) { _context3.next = 11; break; } @@ -11525,8 +11610,8 @@ function (_BasePdfManager2) { } }, { key: "terminate", - value: function terminate() { - this.streamManager.abort(); + value: function terminate(reason) { + this.streamManager.abort(reason); } }]); @@ -11536,7 +11621,7 @@ function (_BasePdfManager2) { exports.NetworkPdfManager = NetworkPdfManager; /***/ }), -/* 152 */ +/* 185 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -11547,7 +11632,9 @@ Object.defineProperty(exports, "__esModule", { }); exports.ChunkedStreamManager = exports.ChunkedStream = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); + +var _core_utils = __w_pdfjs_require__(186); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -11643,6 +11730,10 @@ function () { }, { key: "ensureByte", value: function ensureByte(pos) { + if (pos < this.progressiveDataLength) { + return; + } + var chunk = Math.floor(pos / this.chunkSize); if (chunk === this.lastSuccessfulEnsureByteChunk) { @@ -11650,7 +11741,7 @@ function () { } if (!this.loadedChunks[chunk]) { - throw new _util.MissingDataException(pos, pos + 1); + throw new _core_utils.MissingDataException(pos, pos + 1); } this.lastSuccessfulEnsureByteChunk = chunk; @@ -11672,7 +11763,7 @@ function () { for (var chunk = beginChunk; chunk < endChunk; ++chunk) { if (!this.loadedChunks[chunk]) { - throw new _util.MissingDataException(begin, end); + throw new _core_utils.MissingDataException(begin, end); } } } @@ -11705,7 +11796,10 @@ function () { return -1; } - this.ensureByte(pos); + if (pos >= this.progressiveDataLength) { + this.ensureByte(pos); + } + return this.bytes[this.pos++]; } }, { @@ -11738,7 +11832,9 @@ function () { var strEnd = this.end; if (!length) { - this.ensureRange(pos, strEnd); + if (strEnd > this.progressiveDataLength) { + this.ensureRange(pos, strEnd); + } var _subarray = bytes.subarray(pos, strEnd); @@ -11751,7 +11847,10 @@ function () { end = strEnd; } - this.ensureRange(pos, end); + if (end > this.progressiveDataLength) { + this.ensureRange(pos, end); + } + this.pos = end; var subarray = bytes.subarray(pos, end); return forceClamped ? new Uint8ClampedArray(subarray) : subarray; @@ -11774,7 +11873,18 @@ function () { }, { key: "getByteRange", value: function getByteRange(begin, end) { - this.ensureRange(begin, end); + if (begin < 0) { + begin = 0; + } + + if (end > this.end) { + end = this.end; + } + + if (end > this.progressiveDataLength) { + this.ensureRange(begin, end); + } + return this.bytes.subarray(begin, end); } }, { @@ -11799,7 +11909,15 @@ function () { }, { key: "makeSubStream", value: function makeSubStream(start, length, dict) { - this.ensureRange(start, start + length); + if (length) { + if (start + length > this.progressiveDataLength) { + this.ensureRange(start, start + length); + } + } else { + if (start >= this.progressiveDataLength) { + this.ensureByte(start); + } + } function ChunkedStreamSubstream() {} @@ -11953,8 +12071,8 @@ function () { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); + if (!_iteratorNormalCompletion && _iterator["return"] != null) { + _iterator["return"](); } } finally { if (_didIteratorError) { @@ -12003,8 +12121,8 @@ function () { _iteratorError2 = err; } finally { try { - if (!_iteratorNormalCompletion2 && _iterator2.return != null) { - _iterator2.return(); + if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { + _iterator2["return"](); } } finally { if (_didIteratorError2) { @@ -12060,8 +12178,8 @@ function () { _iteratorError3 = err; } finally { try { - if (!_iteratorNormalCompletion3 && _iterator3.return != null) { - _iterator3.return(); + if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) { + _iterator3["return"](); } } finally { if (_didIteratorError3) { @@ -12167,8 +12285,8 @@ function () { _iteratorError4 = err; } finally { try { - if (!_iteratorNormalCompletion4 && _iterator4.return != null) { - _iterator4.return(); + if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) { + _iterator4["return"](); } } finally { if (_didIteratorError4) { @@ -12196,8 +12314,8 @@ function () { } } - for (var _i = 0; _i < loadedRequests.length; _i++) { - var _requestId = loadedRequests[_i]; + for (var _i = 0, _loadedRequests = loadedRequests; _i < _loadedRequests.length; _i++) { + var _requestId = _loadedRequests[_i]; var capability = this.promisesByRequest[_requestId]; delete this.promisesByRequest[_requestId]; capability.resolve(); @@ -12225,15 +12343,15 @@ function () { } }, { key: "abort", - value: function abort() { + value: function abort(reason) { this.aborted = true; if (this.pdfNetworkStream) { - this.pdfNetworkStream.cancelAllRequests('abort'); + this.pdfNetworkStream.cancelAllRequests(reason); } for (var requestId in this.promisesByRequest) { - this.promisesByRequest[requestId].reject(new Error('Request was aborted')); + this.promisesByRequest[requestId].reject(reason); } } }]); @@ -12244,7 +12362,165 @@ function () { exports.ChunkedStreamManager = ChunkedStreamManager; /***/ }), -/* 153 */ +/* 186 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.getLookupTableFactory = getLookupTableFactory; +exports.getInheritableProperty = getInheritableProperty; +exports.toRomanNumerals = toRomanNumerals; +exports.XRefParseException = exports.XRefEntryException = exports.MissingDataException = void 0; + +var _util = __w_pdfjs_require__(5); + +function _typeof(obj) { 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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +function getLookupTableFactory(initializer) { + var lookup; + return function () { + if (initializer) { + lookup = Object.create(null); + initializer(lookup); + initializer = null; + } + + return lookup; + }; +} + +var MissingDataException = +/*#__PURE__*/ +function (_BaseException) { + _inherits(MissingDataException, _BaseException); + + function MissingDataException(begin, end) { + var _this; + + _classCallCheck(this, MissingDataException); + + _this = _possibleConstructorReturn(this, _getPrototypeOf(MissingDataException).call(this, "Missing data [".concat(begin, ", ").concat(end, ")"))); + _this.begin = begin; + _this.end = end; + return _this; + } + + return MissingDataException; +}(_util.BaseException); + +exports.MissingDataException = MissingDataException; + +var XRefEntryException = +/*#__PURE__*/ +function (_BaseException2) { + _inherits(XRefEntryException, _BaseException2); + + function XRefEntryException() { + _classCallCheck(this, XRefEntryException); + + return _possibleConstructorReturn(this, _getPrototypeOf(XRefEntryException).apply(this, arguments)); + } + + return XRefEntryException; +}(_util.BaseException); + +exports.XRefEntryException = XRefEntryException; + +var XRefParseException = +/*#__PURE__*/ +function (_BaseException3) { + _inherits(XRefParseException, _BaseException3); + + function XRefParseException() { + _classCallCheck(this, XRefParseException); + + return _possibleConstructorReturn(this, _getPrototypeOf(XRefParseException).apply(this, arguments)); + } + + return XRefParseException; +}(_util.BaseException); + +exports.XRefParseException = XRefParseException; + +function getInheritableProperty(_ref) { + var dict = _ref.dict, + key = _ref.key, + _ref$getArray = _ref.getArray, + getArray = _ref$getArray === void 0 ? false : _ref$getArray, + _ref$stopWhenFound = _ref.stopWhenFound, + stopWhenFound = _ref$stopWhenFound === void 0 ? true : _ref$stopWhenFound; + var LOOP_LIMIT = 100; + var loopCount = 0; + var values; + + while (dict) { + var value = getArray ? dict.getArray(key) : dict.get(key); + + if (value !== undefined) { + if (stopWhenFound) { + return value; + } + + if (!values) { + values = []; + } + + values.push(value); + } + + if (++loopCount > LOOP_LIMIT) { + (0, _util.warn)("getInheritableProperty: maximum loop count exceeded for \"".concat(key, "\"")); + break; + } + + dict = dict.get('Parent'); + } + + return values; +} + +var ROMAN_NUMBER_MAP = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']; + +function toRomanNumerals(number) { + var lowerCase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + (0, _util.assert)(Number.isInteger(number) && number > 0, 'The number should be a positive integer.'); + var pos, + romanBuf = []; + + while (number >= 1000) { + number -= 1000; + romanBuf.push('M'); + } + + pos = number / 100 | 0; + number %= 100; + romanBuf.push(ROMAN_NUMBER_MAP[pos]); + pos = number / 10 | 0; + number %= 10; + romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]); + romanBuf.push(ROMAN_NUMBER_MAP[20 + number]); + var romanStr = romanBuf.join(''); + return lowerCase ? romanStr.toLowerCase() : romanStr; +} + +/***/ }), +/* 187 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -12255,31 +12531,33 @@ Object.defineProperty(exports, "__esModule", { }); exports.PDFDocument = exports.Page = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); + +var _obj = __w_pdfjs_require__(188); -var _obj = __w_pdfjs_require__(154); +var _primitives = __w_pdfjs_require__(183); -var _primitives = __w_pdfjs_require__(155); +var _core_utils = __w_pdfjs_require__(186); -var _stream2 = __w_pdfjs_require__(157); +var _stream2 = __w_pdfjs_require__(190); -var _annotation = __w_pdfjs_require__(169); +var _annotation = __w_pdfjs_require__(202); -var _crypto = __w_pdfjs_require__(167); +var _crypto = __w_pdfjs_require__(200); -var _parser = __w_pdfjs_require__(156); +var _parser = __w_pdfjs_require__(189); -var _operator_list = __w_pdfjs_require__(170); +var _operator_list = __w_pdfjs_require__(203); -var _evaluator = __w_pdfjs_require__(171); +var _evaluator = __w_pdfjs_require__(204); -var _function = __w_pdfjs_require__(185); +var _function = __w_pdfjs_require__(218); function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } -function _iterableToArrayLimit(arr, i) { 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 _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { 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; } @@ -12321,13 +12599,15 @@ function () { this.pdfFunctionFactory = pdfFunctionFactory; this.evaluatorOptions = pdfManager.evaluatorOptions; this.resourcesPromise = null; - var uniquePrefix = "p".concat(this.pageIndex, "_"); var idCounters = { obj: 0 }; this.idFactory = { createObjId: function createObjId() { - return uniquePrefix + ++idCounters.obj; + return "p".concat(pageIndex, "_").concat(++idCounters.obj); + }, + getDocId: function getDocId() { + return "g_".concat(pdfManager.docId); } }; } @@ -12336,7 +12616,7 @@ function () { key: "_getInheritableProperty", value: function _getInheritableProperty(key) { var getArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - var value = (0, _util.getInheritableProperty)({ + var value = (0, _core_utils.getInheritableProperty)({ dict: this.pageDict, key: key, getArray: getArray, @@ -12354,6 +12634,21 @@ function () { return _primitives.Dict.merge(this.xref, value); } }, { + key: "_getBoundingBox", + value: function _getBoundingBox(name) { + var box = this._getInheritableProperty(name, true); + + if (Array.isArray(box) && box.length === 4) { + if (box[2] - box[0] !== 0 && box[3] - box[1] !== 0) { + return box; + } + + (0, _util.warn)("Empty /".concat(name, " entry.")); + } + + return null; + } + }, { key: "getContentStream", value: function getContentStream() { var content = this.content; @@ -12376,8 +12671,8 @@ function () { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); + if (!_iteratorNormalCompletion && _iterator["return"] != null) { + _iterator["return"](); } } finally { if (_didIteratorError) { @@ -12415,13 +12710,13 @@ function () { var _this2 = this; var handler = _ref2.handler, + sink = _ref2.sink, task = _ref2.task, intent = _ref2.intent, renderInteractiveForms = _ref2.renderInteractiveForms; var contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream'); var resourcesPromise = this.loadResources(['ExtGState', 'ColorSpace', 'Pattern', 'Shading', 'XObject', 'Font']); var partialEvaluator = new _evaluator.PartialEvaluator({ - pdfManager: this.pdfManager, xref: this.xref, handler: handler, pageIndex: this.pageIndex, @@ -12436,7 +12731,7 @@ function () { var _ref4 = _slicedToArray(_ref3, 1), contentStream = _ref4[0]; - var opList = new _operator_list.OperatorList(intent, handler, _this2.pageIndex); + var opList = new _operator_list.OperatorList(intent, sink, _this2.pageIndex); handler.send('StartRenderPage', { transparency: partialEvaluator.hasBlendModes(_this2.resources), pageIndex: _this2.pageIndex, @@ -12458,7 +12753,9 @@ function () { if (annotations.length === 0) { pageOpList.flush(true); - return pageOpList; + return { + length: pageOpList.totalLength + }; } var opListPromises = []; @@ -12479,8 +12776,8 @@ function () { _iteratorError2 = err; } finally { try { - if (!_iteratorNormalCompletion2 && _iterator2.return != null) { - _iterator2.return(); + if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { + _iterator2["return"](); } } finally { if (_didIteratorError2) { @@ -12505,8 +12802,8 @@ function () { _iteratorError3 = err; } finally { try { - if (!_iteratorNormalCompletion3 && _iterator3.return != null) { - _iterator3.return(); + if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) { + _iterator3["return"](); } } finally { if (_didIteratorError3) { @@ -12517,7 +12814,9 @@ function () { pageOpList.addOp(_util.OPS.endAnnotations, []); pageOpList.flush(true); - return pageOpList; + return { + length: pageOpList.totalLength + }; }); }); } @@ -12539,7 +12838,6 @@ function () { contentStream = _ref9[0]; var partialEvaluator = new _evaluator.PartialEvaluator({ - pdfManager: _this3.pdfManager, xref: _this3.xref, handler: handler, pageIndex: _this3.pageIndex, @@ -12587,24 +12885,12 @@ function () { }, { key: "mediaBox", get: function get() { - var mediaBox = this._getInheritableProperty('MediaBox', true); - - if (!Array.isArray(mediaBox) || mediaBox.length !== 4) { - return (0, _util.shadow)(this, 'mediaBox', LETTER_SIZE_MEDIABOX); - } - - return (0, _util.shadow)(this, 'mediaBox', mediaBox); + return (0, _util.shadow)(this, 'mediaBox', this._getBoundingBox('MediaBox') || LETTER_SIZE_MEDIABOX); } }, { key: "cropBox", get: function get() { - var cropBox = this._getInheritableProperty('CropBox', true); - - if (!Array.isArray(cropBox) || cropBox.length !== 4) { - return (0, _util.shadow)(this, 'cropBox', this.mediaBox); - } - - return (0, _util.shadow)(this, 'cropBox', cropBox); + return (0, _util.shadow)(this, 'cropBox', this._getBoundingBox('CropBox') || this.mediaBox); } }, { key: "userUnit", @@ -12620,16 +12906,23 @@ function () { }, { key: "view", get: function get() { - var mediaBox = this.mediaBox, - cropBox = this.cropBox; + var cropBox = this.cropBox, + mediaBox = this.mediaBox; + var view; - if (mediaBox === cropBox) { - return (0, _util.shadow)(this, 'view', mediaBox); - } + if (cropBox === mediaBox || (0, _util.isArrayEqual)(cropBox, mediaBox)) { + view = mediaBox; + } else { + var box = _util.Util.intersect(cropBox, mediaBox); - var intersection = _util.Util.intersect(cropBox, mediaBox); + if (box && box[2] - box[0] !== 0 && box[3] - box[1] !== 0) { + view = box; + } else { + (0, _util.warn)('Empty /CropBox and /MediaBox intersection.'); + } + } - return (0, _util.shadow)(this, 'view', intersection || mediaBox); + return (0, _util.shadow)(this, 'view', view || mediaBox); } }, { key: "rotate", @@ -12684,22 +12977,10 @@ exports.Page = Page; var FINGERPRINT_FIRST_BYTES = 1024; var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00'; -function find(stream, needle, limit, backwards) { - var pos = stream.pos; - var end = stream.end; - - if (pos + limit > end) { - limit = end - pos; - } - - var strBuf = []; - - for (var i = 0; i < limit; ++i) { - strBuf.push(String.fromCharCode(stream.getByte())); - } - - var str = strBuf.join(''); - stream.pos = pos; +function find(stream, needle, limit) { + var backwards = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + (0, _util.assert)(limit > 0, 'The "limit" must be a positive integer.'); + var str = (0, _util.bytesToString)(stream.peekBytes(limit)); var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle); if (index === -1) { @@ -12757,18 +13038,32 @@ function () { this.xfa = this.acroForm.get('XFA'); var fields = this.acroForm.get('Fields'); - if ((!fields || !Array.isArray(fields) || fields.length === 0) && !this.xfa) { + if ((!Array.isArray(fields) || fields.length === 0) && !this.xfa) { this.acroForm = null; } } } catch (ex) { - if (ex instanceof _util.MissingDataException) { + if (ex instanceof _core_utils.MissingDataException) { throw ex; } (0, _util.info)('Cannot fetch AcroForm entry; assuming no AcroForms are present'); this.acroForm = null; } + + try { + var collection = this.catalog.catDict.get('Collection'); + + if ((0, _primitives.isDict)(collection) && collection.getKeys().length > 0) { + this.collection = collection; + } + } catch (ex) { + if (ex instanceof _core_utils.MissingDataException) { + throw ex; + } + + (0, _util.info)('Cannot fetch Collection dictionary.'); + } } }, { key: "checkHeader", @@ -12814,7 +13109,9 @@ function () { var catalog = this.catalog, linearization = this.linearization; (0, _util.assert)(linearization && linearization.pageFirst === pageIndex); - var ref = new _primitives.Ref(linearization.objectNumberFirst, 0); + + var ref = _primitives.Ref.get(linearization.objectNumberFirst, 0); + return this.xref.fetchAsync(ref).then(function (obj) { if ((0, _primitives.isDict)(obj, 'Page') || (0, _primitives.isDict)(obj) && !obj.has('Type') && obj.has('Contents')) { if (ref && !catalog.pageKidsCountCache.has(ref)) { @@ -12825,7 +13122,7 @@ function () { } throw new _util.FormatError('The Linearization dictionary doesn\'t point ' + 'to a valid Page dictionary.'); - }).catch(function (reason) { + })["catch"](function (reason) { (0, _util.info)(reason); return catalog.getPageDict(pageIndex); }); @@ -12864,13 +13161,13 @@ function () { value: function checkFirstPage() { var _this6 = this; - return this.getPage(0).catch(function (reason) { - if (reason instanceof _util.XRefEntryException) { + return this.getPage(0)["catch"](function (reason) { + if (reason instanceof _core_utils.XRefEntryException) { _this6._pagePromises.length = 0; _this6.cleanup(); - throw new _util.XRefParseException(); + throw new _core_utils.XRefParseException(); } }); } @@ -12892,7 +13189,7 @@ function () { try { linearization = _parser.Linearization.create(this.stream); } catch (err) { - if (err instanceof _util.MissingDataException) { + if (err instanceof _core_utils.MissingDataException) { throw err; } @@ -12980,14 +13277,15 @@ function () { PDFFormatVersion: this.pdfFormatVersion, IsLinearized: !!this.linearization, IsAcroFormPresent: !!this.acroForm, - IsXFAPresent: !!this.xfa + IsXFAPresent: !!this.xfa, + IsCollectionPresent: !!this.collection }; var infoDict; try { infoDict = this.xref.trailer.get('Info'); } catch (err) { - if (err instanceof _util.MissingDataException) { + if (err instanceof _core_utils.MissingDataException) { throw err; } @@ -13034,8 +13332,8 @@ function () { _iteratorError4 = err; } finally { try { - if (!_iteratorNormalCompletion4 && _iterator4.return != null) { - _iterator4.return(); + if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) { + _iterator4["return"](); } } finally { if (_didIteratorError4) { @@ -13056,21 +13354,17 @@ function () { if (Array.isArray(idArray) && idArray[0] && (0, _util.isString)(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) { hash = (0, _util.stringToBytes)(idArray[0]); } else { - if (this.stream.ensureRange) { - this.stream.ensureRange(0, Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end)); - } - - hash = (0, _crypto.calculateMD5)(this.stream.bytes.subarray(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES); + hash = (0, _crypto.calculateMD5)(this.stream.getByteRange(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES); } - var fingerprint = ''; + var fingerprintBuf = []; for (var i = 0, ii = hash.length; i < ii; i++) { var hex = hash[i].toString(16); - fingerprint += hex.length === 1 ? '0' + hex : hex; + fingerprintBuf.push(hex.padStart(2, '0')); } - return (0, _util.shadow)(this, 'fingerprint', fingerprint); + return (0, _util.shadow)(this, 'fingerprint', fingerprintBuf.join('')); } }]); @@ -13080,7 +13374,7 @@ function () { exports.PDFDocument = PDFDocument; /***/ }), -/* 154 */ +/* 188 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -13093,19 +13387,21 @@ exports.FileSpec = exports.XRef = exports.ObjectLoader = exports.Catalog = void var _regenerator = _interopRequireDefault(__w_pdfjs_require__(2)); -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _primitives = __w_pdfjs_require__(155); +var _primitives = __w_pdfjs_require__(183); -var _parser = __w_pdfjs_require__(156); +var _parser = __w_pdfjs_require__(189); -var _chunked_stream = __w_pdfjs_require__(152); +var _core_utils = __w_pdfjs_require__(186); -var _crypto = __w_pdfjs_require__(167); +var _chunked_stream = __w_pdfjs_require__(185); -var _colorspace = __w_pdfjs_require__(168); +var _crypto = __w_pdfjs_require__(200); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +var _colorspace = __w_pdfjs_require__(201); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } @@ -13125,7 +13421,7 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArra function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } -function _iterableToArrayLimit(arr, i) { 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 _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { 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; } @@ -13211,6 +13507,7 @@ function () { var title = outlineDict.get('Title'); var flags = outlineDict.get('F') || 0; var color = outlineDict.getArray('C'); + var count = outlineDict.get('Count'); var rgbColor = blackColor; if (Array.isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) { @@ -13224,7 +13521,7 @@ function () { newWindow: data.newWindow, title: (0, _util.stringToPDFString)(title), color: rgbColor, - count: outlineDict.get('Count'), + count: Number.isInteger(count) ? count : undefined, bold: !!(flags & 2), italic: !!(flags & 1), items: [] @@ -13302,6 +13599,8 @@ function () { } else if (this.catDict.has('Dests')) { return this.catDict.get('Dests'); } + + return undefined; } }, { key: "_readPageLabels", @@ -13376,7 +13675,7 @@ function () { case 'R': case 'r': - currentLabel = (0, _util.toRomanNumerals)(currentIndex, style === 'r'); + currentLabel = (0, _core_utils.toRomanNumerals)(currentIndex, style === 'r'); break; case 'A': @@ -13436,8 +13735,8 @@ function () { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); + if (!_iteratorNormalCompletion && _iterator["return"] != null) { + _iterator["return"](); } } finally { if (_didIteratorError) { @@ -13452,6 +13751,7 @@ function () { value: function cleanup() { var _this = this; + (0, _primitives.clearPrimitiveCaches)(); this.pageKidsCountCache.clear(); var promises = []; this.fontCache.forEach(function (promise) { @@ -13696,7 +13996,7 @@ function () { try { metadata = (0, _util.stringToUTF8String)((0, _util.bytesToString)(stream.getBytes())); } catch (e) { - if (e instanceof _util.MissingDataException) { + if (e instanceof _core_utils.MissingDataException) { throw e; } @@ -13726,7 +14026,7 @@ function () { try { obj = this._readDocumentOutline(); } catch (ex) { - if (ex instanceof _util.MissingDataException) { + if (ex instanceof _core_utils.MissingDataException) { throw ex; } @@ -13743,7 +14043,7 @@ function () { try { permissions = this._readPermissions(); } catch (ex) { - if (ex instanceof _util.MissingDataException) { + if (ex instanceof _core_utils.MissingDataException) { throw ex; } @@ -13793,7 +14093,7 @@ function () { try { obj = this._readPageLabels(); } catch (ex) { - if (ex instanceof _util.MissingDataException) { + if (ex instanceof _core_utils.MissingDataException) { throw ex; } @@ -13803,6 +14103,26 @@ function () { return (0, _util.shadow)(this, 'pageLabels', obj); } }, { + key: "pageLayout", + get: function get() { + var obj = this.catDict.get('PageLayout'); + var pageLayout = ''; + + if ((0, _primitives.isName)(obj)) { + switch (obj.name) { + case 'SinglePage': + case 'OneColumn': + case 'TwoColumnLeft': + case 'TwoColumnRight': + case 'TwoPageLeft': + case 'TwoPageRight': + pageLayout = obj.name; + } + } + + return (0, _util.shadow)(this, 'pageLayout', pageLayout); + } + }, { key: "pageMode", get: function get() { var obj = this.catDict.get('PageMode'); @@ -13823,6 +14143,162 @@ function () { return (0, _util.shadow)(this, 'pageMode', pageMode); } }, { + key: "viewerPreferences", + get: function get() { + var _this2 = this; + + var ViewerPreferencesValidators = { + HideToolbar: _util.isBool, + HideMenubar: _util.isBool, + HideWindowUI: _util.isBool, + FitWindow: _util.isBool, + CenterWindow: _util.isBool, + DisplayDocTitle: _util.isBool, + NonFullScreenPageMode: _primitives.isName, + Direction: _primitives.isName, + ViewArea: _primitives.isName, + ViewClip: _primitives.isName, + PrintArea: _primitives.isName, + PrintClip: _primitives.isName, + PrintScaling: _primitives.isName, + Duplex: _primitives.isName, + PickTrayByPDFSize: _util.isBool, + PrintPageRange: Array.isArray, + NumCopies: Number.isInteger + }; + var obj = this.catDict.get('ViewerPreferences'); + var prefs = Object.create(null); + + if ((0, _primitives.isDict)(obj)) { + for (var key in ViewerPreferencesValidators) { + if (!obj.has(key)) { + continue; + } + + var value = obj.get(key); + + if (!ViewerPreferencesValidators[key](value)) { + (0, _util.info)("Bad value in ViewerPreferences for \"".concat(key, "\".")); + continue; + } + + var prefValue = void 0; + + switch (key) { + case 'NonFullScreenPageMode': + switch (value.name) { + case 'UseNone': + case 'UseOutlines': + case 'UseThumbs': + case 'UseOC': + prefValue = value.name; + break; + + default: + prefValue = 'UseNone'; + } + + break; + + case 'Direction': + switch (value.name) { + case 'L2R': + case 'R2L': + prefValue = value.name; + break; + + default: + prefValue = 'L2R'; + } + + break; + + case 'ViewArea': + case 'ViewClip': + case 'PrintArea': + case 'PrintClip': + switch (value.name) { + case 'MediaBox': + case 'CropBox': + case 'BleedBox': + case 'TrimBox': + case 'ArtBox': + prefValue = value.name; + break; + + default: + prefValue = 'CropBox'; + } + + break; + + case 'PrintScaling': + switch (value.name) { + case 'None': + case 'AppDefault': + prefValue = value.name; + break; + + default: + prefValue = 'AppDefault'; + } + + break; + + case 'Duplex': + switch (value.name) { + case 'Simplex': + case 'DuplexFlipShortEdge': + case 'DuplexFlipLongEdge': + prefValue = value.name; + break; + + default: + prefValue = 'None'; + } + + break; + + case 'PrintPageRange': + var length = value.length; + + if (length % 2 !== 0) { + break; + } + + var isValid = value.every(function (page, i, arr) { + return Number.isInteger(page) && page > 0 && (i === 0 || page >= arr[i - 1]) && page <= _this2.numPages; + }); + + if (isValid) { + prefValue = value; + } + + break; + + case 'NumCopies': + if (value > 0) { + prefValue = value; + } + + break; + + default: + (0, _util.assert)(typeof value === 'boolean'); + prefValue = value; + } + + if (prefValue !== undefined) { + prefs[key] = prefValue; + } else { + (0, _util.info)("Bad value in ViewerPreferences for \"".concat(key, "\".")); + } + } + } + + return (0, _util.shadow)(this, 'viewerPreferences', prefs); + } + }, { key: "openActionDestination", get: function get() { var obj = this.catDict.get('OpenAction'); @@ -14112,10 +14588,10 @@ var XRef = function XRefClosure() { this.pdfManager = pdfManager; this.entries = []; this.xrefstms = Object.create(null); - this.cache = []; + this._cacheMap = new Map(); this.stats = { - streamTypes: [], - fontTypes: [] + streamTypes: Object.create(null), + fontTypes: Object.create(null) }; } @@ -14140,7 +14616,7 @@ var XRef = function XRefClosure() { try { encrypt = trailerDict.get('Encrypt'); } catch (ex) { - if (ex instanceof _util.MissingDataException) { + if (ex instanceof _core_utils.MissingDataException) { throw ex; } @@ -14159,7 +14635,7 @@ var XRef = function XRefClosure() { try { root = trailerDict.get('Root'); } catch (ex) { - if (ex instanceof _util.MissingDataException) { + if (ex instanceof _core_utils.MissingDataException) { throw ex; } @@ -14170,7 +14646,7 @@ var XRef = function XRefClosure() { this.root = root; } else { if (!recoveryMode) { - throw new _util.XRefParseException(); + throw new _core_utils.XRefParseException(); } throw new _util.FormatError('Invalid root reference'); @@ -14240,10 +14716,16 @@ var XRef = function XRefClosure() { entry.gen = parser.getObj(); var type = parser.getObj(); - if ((0, _primitives.isCmd)(type, 'f')) { - entry.free = true; - } else if ((0, _primitives.isCmd)(type, 'n')) { - entry.uncompressed = true; + if (type instanceof _primitives.Cmd) { + switch (type.cmd) { + case 'f': + entry.free = true; + break; + + case 'n': + entry.uncompressed = true; + break; + } } if (!Number.isInteger(entry.offset) || !Number.isInteger(entry.gen) || !(entry.free || entry.uncompressed)) { @@ -14527,7 +15009,12 @@ var XRef = function XRefClosure() { for (i = 0, ii = trailers.length; i < ii; ++i) { stream.pos = trailers[i]; - var parser = new _parser.Parser(new _parser.Lexer(stream), true, this, true); + var parser = new _parser.Parser({ + lexer: new _parser.Lexer(stream), + xref: this, + allowStreams: true, + recoveryMode: true + }); var obj = parser.getObj(); if (!(0, _primitives.isCmd)(obj, 'trailer')) { @@ -14545,7 +15032,7 @@ var XRef = function XRefClosure() { try { rootDict = dict.get('Root'); } catch (ex) { - if (ex instanceof _util.MissingDataException) { + if (ex instanceof _core_utils.MissingDataException) { throw ex; } @@ -14585,7 +15072,11 @@ var XRef = function XRefClosure() { startXRefParsedCache[startXRef] = true; stream.pos = startXRef + stream.start; - var parser = new _parser.Parser(new _parser.Lexer(stream), true, this); + var parser = new _parser.Parser({ + lexer: new _parser.Lexer(stream), + xref: this, + allowStreams: true + }); var obj = parser.getObj(); var dict; @@ -14637,7 +15128,7 @@ var XRef = function XRefClosure() { return this.topDict; } catch (e) { - if (e instanceof _util.MissingDataException) { + if (e instanceof _core_utils.MissingDataException) { throw e; } @@ -14645,10 +15136,10 @@ var XRef = function XRefClosure() { } if (recoveryMode) { - return; + return undefined; } - throw new _util.XRefParseException(); + throw new _core_utils.XRefParseException(); }, getEntry: function XRef_getEntry(i) { var xrefEntry = this.entries[i]; @@ -14660,21 +15151,21 @@ var XRef = function XRefClosure() { return null; }, fetchIfRef: function XRef_fetchIfRef(obj, suppressEncryption) { - if (!(0, _primitives.isRef)(obj)) { - return obj; + if (obj instanceof _primitives.Ref) { + return this.fetch(obj, suppressEncryption); } - return this.fetch(obj, suppressEncryption); + return obj; }, fetch: function XRef_fetch(ref, suppressEncryption) { - if (!(0, _primitives.isRef)(ref)) { + if (!(ref instanceof _primitives.Ref)) { throw new Error('ref object is not a reference'); } var num = ref.num; - if (num in this.cache) { - var cacheEntry = this.cache[num]; + if (this._cacheMap.has(num)) { + var cacheEntry = this._cacheMap.get(num); if (cacheEntry instanceof _primitives.Dict && !cacheEntry.objId) { cacheEntry.objId = ref.toString(); @@ -14686,7 +15177,9 @@ var XRef = function XRefClosure() { var xrefEntry = this.getEntry(num); if (xrefEntry === null) { - return this.cache[num] = null; + this._cacheMap.set(num, xrefEntry); + + return xrefEntry; } if (xrefEntry.uncompressed) { @@ -14709,11 +15202,15 @@ var XRef = function XRefClosure() { var num = ref.num; if (xrefEntry.gen !== gen) { - throw new _util.XRefEntryException("Inconsistent generation in XRef: ".concat(ref)); + throw new _core_utils.XRefEntryException("Inconsistent generation in XRef: ".concat(ref)); } var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start); - var parser = new _parser.Parser(new _parser.Lexer(stream), true, this); + var parser = new _parser.Parser({ + lexer: new _parser.Lexer(stream), + xref: this, + allowStreams: true + }); var obj1 = parser.getObj(); var obj2 = parser.getObj(); var obj3 = parser.getObj(); @@ -14726,8 +15223,8 @@ var XRef = function XRefClosure() { obj2 = parseInt(obj2, 10); } - if (obj1 !== num || obj2 !== gen || !(0, _primitives.isCmd)(obj3)) { - throw new _util.XRefEntryException("Bad (uncompressed) XRef entry: ".concat(ref)); + if (obj1 !== num || obj2 !== gen || !(obj3 instanceof _primitives.Cmd)) { + throw new _core_utils.XRefEntryException("Bad (uncompressed) XRef entry: ".concat(ref)); } if (obj3.cmd !== 'obj') { @@ -14739,7 +15236,7 @@ var XRef = function XRefClosure() { } } - throw new _util.XRefEntryException("Bad (uncompressed) XRef entry: ".concat(ref)); + throw new _core_utils.XRefEntryException("Bad (uncompressed) XRef entry: ".concat(ref)); } if (this.encrypt && !suppressEncryption) { @@ -14749,7 +15246,7 @@ var XRef = function XRefClosure() { } if (!(0, _primitives.isStream)(xrefEntry)) { - this.cache[num] = xrefEntry; + this._cacheMap.set(num, xrefEntry); } return xrefEntry; @@ -14757,7 +15254,7 @@ var XRef = function XRefClosure() { fetchCompressed: function fetchCompressed(ref, xrefEntry) { var suppressEncryption = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; var tableOffset = xrefEntry.offset; - var stream = this.fetch(new _primitives.Ref(tableOffset, 0)); + var stream = this.fetch(_primitives.Ref.get(tableOffset, 0)); if (!(0, _primitives.isStream)(stream)) { throw new _util.FormatError('bad ObjStm stream'); @@ -14770,8 +15267,11 @@ var XRef = function XRefClosure() { throw new _util.FormatError('invalid first and n parameters for ObjStm stream'); } - var parser = new _parser.Parser(new _parser.Lexer(stream), false, this); - parser.allowStreams = true; + var parser = new _parser.Parser({ + lexer: new _parser.Lexer(stream), + xref: this, + allowStreams: true + }); var i, entries = [], num, @@ -14803,14 +15303,14 @@ var XRef = function XRefClosure() { var entry = this.entries[num]; if (entry && entry.offset === tableOffset && entry.gen === i) { - this.cache[num] = entries[i]; + this._cacheMap.set(num, entries[i]); } } xrefEntry = entries[xrefEntry.gen]; if (xrefEntry === undefined) { - throw new _util.XRefEntryException("Bad (compressed) XRef entry: ".concat(ref)); + throw new _core_utils.XRefEntryException("Bad (compressed) XRef entry: ".concat(ref)); } return xrefEntry; @@ -14818,20 +15318,20 @@ var XRef = function XRefClosure() { fetchIfRefAsync: function () { var _fetchIfRefAsync = _asyncToGenerator( /*#__PURE__*/ - _regenerator.default.mark(function _callee(obj, suppressEncryption) { - return _regenerator.default.wrap(function _callee$(_context) { + _regenerator["default"].mark(function _callee(obj, suppressEncryption) { + return _regenerator["default"].wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: - if ((0, _primitives.isRef)(obj)) { + if (!(obj instanceof _primitives.Ref)) { _context.next = 2; break; } - return _context.abrupt("return", obj); + return _context.abrupt("return", this.fetchAsync(obj, suppressEncryption)); case 2: - return _context.abrupt("return", this.fetchAsync(obj, suppressEncryption)); + return _context.abrupt("return", obj); case 3: case "end": @@ -14850,8 +15350,8 @@ var XRef = function XRefClosure() { fetchAsync: function () { var _fetchAsync = _asyncToGenerator( /*#__PURE__*/ - _regenerator.default.mark(function _callee2(ref, suppressEncryption) { - return _regenerator.default.wrap(function _callee2$(_context2) { + _regenerator["default"].mark(function _callee2(ref, suppressEncryption) { + return _regenerator["default"].wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: @@ -14862,7 +15362,7 @@ var XRef = function XRefClosure() { _context2.prev = 4; _context2.t0 = _context2["catch"](0); - if (_context2.t0 instanceof _util.MissingDataException) { + if (_context2.t0 instanceof _core_utils.MissingDataException) { _context2.next = 8; break; } @@ -15234,7 +15734,7 @@ var ObjectLoader = function () { return this.capability.promise; }, _walk: function _walk(nodesToVisit) { - var _this2 = this; + var _this3 = this; var nodesToRevisit = []; var pendingRequests = []; @@ -15251,7 +15751,7 @@ var ObjectLoader = function () { this.refSet.put(currentNode); currentNode = this.xref.fetch(currentNode); } catch (ex) { - if (!(ex instanceof _util.MissingDataException)) { + if (!(ex instanceof _core_utils.MissingDataException)) { throw ex; } @@ -15293,11 +15793,11 @@ var ObjectLoader = function () { var node = nodesToRevisit[_i4]; if ((0, _primitives.isRef)(node)) { - _this2.refSet.remove(node); + _this3.refSet.remove(node); } } - _this2._walk(nodesToRevisit); + _this3._walk(nodesToRevisit); }, this.capability.reject); return; } @@ -15312,7 +15812,7 @@ var ObjectLoader = function () { exports.ObjectLoader = ObjectLoader; /***/ }), -/* 155 */ +/* 189 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -15321,312 +15821,29 @@ exports.ObjectLoader = ObjectLoader; Object.defineProperty(exports, "__esModule", { value: true }); -exports.isEOF = isEOF; -exports.isCmd = isCmd; -exports.isDict = isDict; -exports.isName = isName; -exports.isRef = isRef; -exports.isRefsEqual = isRefsEqual; -exports.isStream = isStream; -exports.RefSetCache = exports.RefSet = exports.Ref = exports.Name = exports.Dict = exports.Cmd = exports.EOF = void 0; - -function _typeof(obj) { 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 EOF = {}; -exports.EOF = EOF; - -var Name = function NameClosure() { - function Name(name) { - this.name = name; - } - - Name.prototype = {}; - var nameCache = Object.create(null); - - Name.get = function Name_get(name) { - var nameValue = nameCache[name]; - return nameValue ? nameValue : nameCache[name] = new Name(name); - }; - - return Name; -}(); - -exports.Name = Name; - -var Cmd = function CmdClosure() { - function Cmd(cmd) { - this.cmd = cmd; - } - - Cmd.prototype = {}; - var cmdCache = Object.create(null); - - Cmd.get = function Cmd_get(cmd) { - var cmdValue = cmdCache[cmd]; - return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd); - }; - - return Cmd; -}(); - -exports.Cmd = Cmd; - -var Dict = function DictClosure() { - var nonSerializable = function nonSerializableClosure() { - return nonSerializable; - }; - - function Dict(xref) { - this._map = Object.create(null); - this.xref = xref; - this.objId = null; - this.suppressEncryption = false; - this.__nonSerializable__ = nonSerializable; - } - - Dict.prototype = { - assignXref: function Dict_assignXref(newXref) { - this.xref = newXref; - }, - get: function Dict_get(key1, key2, key3) { - var value; - var xref = this.xref, - suppressEncryption = this.suppressEncryption; - - if (typeof (value = this._map[key1]) !== 'undefined' || key1 in this._map || typeof key2 === 'undefined') { - return xref ? xref.fetchIfRef(value, suppressEncryption) : value; - } - - if (typeof (value = this._map[key2]) !== 'undefined' || key2 in this._map || typeof key3 === 'undefined') { - return xref ? xref.fetchIfRef(value, suppressEncryption) : value; - } - - value = this._map[key3] || null; - return xref ? xref.fetchIfRef(value, suppressEncryption) : value; - }, - getAsync: function Dict_getAsync(key1, key2, key3) { - var value; - var xref = this.xref, - suppressEncryption = this.suppressEncryption; - - if (typeof (value = this._map[key1]) !== 'undefined' || key1 in this._map || typeof key2 === 'undefined') { - if (xref) { - return xref.fetchIfRefAsync(value, suppressEncryption); - } - - return Promise.resolve(value); - } - - if (typeof (value = this._map[key2]) !== 'undefined' || key2 in this._map || typeof key3 === 'undefined') { - if (xref) { - return xref.fetchIfRefAsync(value, suppressEncryption); - } - - return Promise.resolve(value); - } - - value = this._map[key3] || null; - - if (xref) { - return xref.fetchIfRefAsync(value, suppressEncryption); - } - - return Promise.resolve(value); - }, - getArray: function Dict_getArray(key1, key2, key3) { - var value = this.get(key1, key2, key3); - var xref = this.xref, - suppressEncryption = this.suppressEncryption; - - if (!Array.isArray(value) || !xref) { - return value; - } - - value = value.slice(); - - for (var i = 0, ii = value.length; i < ii; i++) { - if (!isRef(value[i])) { - continue; - } - - value[i] = xref.fetch(value[i], suppressEncryption); - } - - return value; - }, - getRaw: function Dict_getRaw(key) { - return this._map[key]; - }, - getKeys: function Dict_getKeys() { - return Object.keys(this._map); - }, - set: function Dict_set(key, value) { - this._map[key] = value; - }, - has: function Dict_has(key) { - return key in this._map; - }, - forEach: function Dict_forEach(callback) { - for (var key in this._map) { - callback(key, this.get(key)); - } - } - }; - Dict.empty = new Dict(null); - - Dict.merge = function (xref, dictArray) { - var mergedDict = new Dict(xref); - - for (var i = 0, ii = dictArray.length; i < ii; i++) { - var dict = dictArray[i]; - - if (!isDict(dict)) { - continue; - } - - for (var keyName in dict._map) { - if (mergedDict._map[keyName] !== undefined) { - continue; - } - - mergedDict._map[keyName] = dict._map[keyName]; - } - } - - return mergedDict; - }; - - return Dict; -}(); - -exports.Dict = Dict; - -var Ref = function RefClosure() { - function Ref(num, gen) { - this.num = num; - this.gen = gen; - } - - Ref.prototype = { - toString: function Ref_toString() { - if (this.gen !== 0) { - return "".concat(this.num, "R").concat(this.gen); - } - - return "".concat(this.num, "R"); - } - }; - return Ref; -}(); - -exports.Ref = Ref; - -var RefSet = function RefSetClosure() { - function RefSet() { - this.dict = Object.create(null); - } - - RefSet.prototype = { - has: function RefSet_has(ref) { - return ref.toString() in this.dict; - }, - put: function RefSet_put(ref) { - this.dict[ref.toString()] = true; - }, - remove: function RefSet_remove(ref) { - delete this.dict[ref.toString()]; - } - }; - return RefSet; -}(); - -exports.RefSet = RefSet; - -var RefSetCache = function RefSetCacheClosure() { - function RefSetCache() { - this.dict = Object.create(null); - } - - RefSetCache.prototype = { - get: function RefSetCache_get(ref) { - return this.dict[ref.toString()]; - }, - has: function RefSetCache_has(ref) { - return ref.toString() in this.dict; - }, - put: function RefSetCache_put(ref, obj) { - this.dict[ref.toString()] = obj; - }, - putAlias: function RefSetCache_putAlias(ref, aliasRef) { - this.dict[ref.toString()] = this.get(aliasRef); - }, - forEach: function RefSetCache_forEach(fn, thisArg) { - for (var i in this.dict) { - fn.call(thisArg, this.dict[i]); - } - }, - clear: function RefSetCache_clear() { - this.dict = Object.create(null); - } - }; - return RefSetCache; -}(); - -exports.RefSetCache = RefSetCache; - -function isEOF(v) { - return v === EOF; -} - -function isName(v, name) { - return v instanceof Name && (name === undefined || v.name === name); -} - -function isCmd(v, cmd) { - return v instanceof Cmd && (cmd === undefined || v.cmd === cmd); -} - -function isDict(v, type) { - return v instanceof Dict && (type === undefined || isName(v.get('Type'), type)); -} - -function isRef(v) { - return v instanceof Ref; -} +exports.Parser = exports.Linearization = exports.Lexer = void 0; -function isRefsEqual(v1, v2) { - return v1.num === v2.num && v1.gen === v2.gen; -} +var _stream = __w_pdfjs_require__(190); -function isStream(v) { - return _typeof(v) === 'object' && v !== null && v.getBytes !== undefined; -} +var _util = __w_pdfjs_require__(5); -/***/ }), -/* 156 */ -/***/ (function(module, exports, __w_pdfjs_require__) { +var _primitives = __w_pdfjs_require__(183); -"use strict"; +var _ccitt_stream = __w_pdfjs_require__(191); +var _jbig2_stream = __w_pdfjs_require__(193); -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.Parser = exports.Linearization = exports.Lexer = void 0; - -var _stream = __w_pdfjs_require__(157); - -var _util = __w_pdfjs_require__(6); +var _jpeg_stream = __w_pdfjs_require__(196); -var _primitives = __w_pdfjs_require__(155); +var _jpx_stream = __w_pdfjs_require__(198); -var _ccitt_stream = __w_pdfjs_require__(158); +var _core_utils = __w_pdfjs_require__(186); -var _jbig2_stream = __w_pdfjs_require__(160); +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var _jpeg_stream = __w_pdfjs_require__(163); +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); } } -var _jpx_stream = __w_pdfjs_require__(165); +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var MAX_LENGTH_TO_CACHE = 1000; var MAX_ADLER32_LENGTH = 5552; @@ -15644,43 +15861,62 @@ function computeAdler32(bytes) { return b % 65521 << 16 | a % 65521; } -var Parser = function ParserClosure() { - function Parser(lexer, allowStreams, xref, recoveryMode) { +var Parser = +/*#__PURE__*/ +function () { + function Parser(_ref) { + var lexer = _ref.lexer, + xref = _ref.xref, + _ref$allowStreams = _ref.allowStreams, + allowStreams = _ref$allowStreams === void 0 ? false : _ref$allowStreams, + _ref$recoveryMode = _ref.recoveryMode, + recoveryMode = _ref$recoveryMode === void 0 ? false : _ref$recoveryMode; + + _classCallCheck(this, Parser); + this.lexer = lexer; - this.allowStreams = allowStreams; this.xref = xref; - this.recoveryMode = recoveryMode || false; + this.allowStreams = allowStreams; + this.recoveryMode = recoveryMode; this.imageCache = Object.create(null); this.refill(); } - Parser.prototype = { - refill: function Parser_refill() { + _createClass(Parser, [{ + key: "refill", + value: function refill() { this.buf1 = this.lexer.getObj(); this.buf2 = this.lexer.getObj(); - }, - shift: function Parser_shift() { - if ((0, _primitives.isCmd)(this.buf2, 'ID')) { + } + }, { + key: "shift", + value: function shift() { + if (this.buf2 instanceof _primitives.Cmd && this.buf2.cmd === 'ID') { this.buf1 = this.buf2; this.buf2 = null; } else { this.buf1 = this.buf2; this.buf2 = this.lexer.getObj(); } - }, - tryShift: function Parser_tryShift() { + } + }, { + key: "tryShift", + value: function tryShift() { try { this.shift(); return true; } catch (e) { - if (e instanceof _util.MissingDataException) { + if (e instanceof _core_utils.MissingDataException) { throw e; } return false; } - }, - getObj: function Parser_getObj(cipherTransform) { + } + }, { + key: "getObj", + value: function getObj() { + var cipherTransform = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var buf1 = this.buf1; this.shift(); @@ -15748,31 +15984,30 @@ var Parser = function ParserClosure() { } if (Number.isInteger(buf1)) { - var num = buf1; - if (Number.isInteger(this.buf1) && (0, _primitives.isCmd)(this.buf2, 'R')) { - var ref = new _primitives.Ref(num, this.buf1); + var ref = _primitives.Ref.get(buf1, this.buf1); + this.shift(); this.shift(); return ref; } - return num; + return buf1; } - if ((0, _util.isString)(buf1)) { - var str = buf1; - + if (typeof buf1 === 'string') { if (cipherTransform) { - str = cipherTransform.decryptString(str); + return cipherTransform.decryptString(buf1); } - return str; + return buf1; } return buf1; - }, - findDefaultInlineStreamEnd: function findDefaultInlineStreamEnd(stream) { + } + }, { + key: "findDefaultInlineStreamEnd", + value: function findDefaultInlineStreamEnd(stream) { var E = 0x45, I = 0x49, SPACE = 0x20, @@ -15838,8 +16073,10 @@ var Parser = function ParserClosure() { } return stream.pos - endOffset - startPos; - }, - findDCTDecodeInlineStreamEnd: function Parser_findDCTDecodeInlineStreamEnd(stream) { + } + }, { + key: "findDCTDecodeInlineStreamEnd", + value: function findDCTDecodeInlineStreamEnd(stream) { var startPos = stream.pos, foundEOI = false, b, @@ -15927,8 +16164,10 @@ var Parser = function ParserClosure() { this.inlineStreamSkipEI(stream); return length; - }, - findASCII85DecodeInlineStreamEnd: function Parser_findASCII85DecodeInlineStreamEnd(stream) { + } + }, { + key: "findASCII85DecodeInlineStreamEnd", + value: function findASCII85DecodeInlineStreamEnd(stream) { var TILDE = 0x7E, GT = 0x3E; var startPos = stream.pos, @@ -15936,9 +16175,18 @@ var Parser = function ParserClosure() { length; while ((ch = stream.getByte()) !== -1) { - if (ch === TILDE && stream.peekByte() === GT) { - stream.skip(); - break; + if (ch === TILDE) { + ch = stream.peekByte(); + + while ((0, _util.isSpace)(ch)) { + stream.skip(); + ch = stream.peekByte(); + } + + if (ch === GT) { + stream.skip(); + break; + } } } @@ -15952,8 +16200,10 @@ var Parser = function ParserClosure() { this.inlineStreamSkipEI(stream); return length; - }, - findASCIIHexDecodeInlineStreamEnd: function Parser_findASCIIHexDecodeInlineStreamEnd(stream) { + } + }, { + key: "findASCIIHexDecodeInlineStreamEnd", + value: function findASCIIHexDecodeInlineStreamEnd(stream) { var GT = 0x3E; var startPos = stream.pos, ch, @@ -15975,8 +16225,10 @@ var Parser = function ParserClosure() { this.inlineStreamSkipEI(stream); return length; - }, - inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) { + } + }, { + key: "inlineStreamSkipEI", + value: function inlineStreamSkipEI(stream) { var E = 0x45, I = 0x49; var state = 0, @@ -15991,12 +16243,14 @@ var Parser = function ParserClosure() { break; } } - }, - makeInlineImage: function Parser_makeInlineImage(cipherTransform) { + } + }, { + key: "makeInlineImage", + value: function makeInlineImage(cipherTransform) { var lexer = this.lexer; var stream = lexer.stream; - var dict = new _primitives.Dict(this.xref), - dictLength; + var dict = new _primitives.Dict(this.xref); + var dictLength; while (!(0, _primitives.isCmd)(this.buf1, 'ID') && !(0, _primitives.isEOF)(this.buf1)) { if (!(0, _primitives.isName)(this.buf1)) { @@ -16017,8 +16271,8 @@ var Parser = function ParserClosure() { dictLength = stream.pos - lexer.beginInlineImagePos; } - var filter = dict.get('Filter', 'F'), - filterName; + var filter = dict.get('Filter', 'F'); + var filterName; if ((0, _primitives.isName)(filter)) { filterName = filter.name; @@ -16030,8 +16284,8 @@ var Parser = function ParserClosure() { } } - var startPos = stream.pos, - length; + var startPos = stream.pos; + var length; if (filterName === 'DCTDecode' || filterName === 'DCT') { length = this.findDCTDecodeInlineStreamEnd(stream); @@ -16072,15 +16326,17 @@ var Parser = function ParserClosure() { imageStream.dict = dict; if (cacheKey !== undefined) { - imageStream.cacheKey = 'inline_' + length + '_' + cacheKey; + imageStream.cacheKey = "inline_".concat(length, "_").concat(cacheKey); this.imageCache[cacheKey] = imageStream; } this.buf2 = _primitives.Cmd.get('EI'); this.shift(); return imageStream; - }, - _findStreamLength: function _findStreamLength(startPos, signature) { + } + }, { + key: "_findStreamLength", + value: function _findStreamLength(startPos, signature) { var stream = this.lexer.stream; stream.pos = startPos; var SCAN_BLOCK_LENGTH = 2048; @@ -16115,8 +16371,10 @@ var Parser = function ParserClosure() { } return -1; - }, - makeStream: function Parser_makeStream(dict, cipherTransform) { + } + }, { + key: "makeStream", + value: function makeStream(dict, cipherTransform) { var lexer = this.lexer; var stream = lexer.stream; lexer.skipToNextLine(); @@ -16124,7 +16382,7 @@ var Parser = function ParserClosure() { var length = dict.get('Length'); if (!Number.isInteger(length)) { - (0, _util.info)('Bad ' + length + ' attribute in stream'); + (0, _util.info)("Bad length \"".concat(length, "\" in stream")); length = 0; } @@ -16181,8 +16439,10 @@ var Parser = function ParserClosure() { stream = this.filter(stream, dict, length); stream.dict = dict; return stream; - }, - filter: function Parser_filter(stream, dict, length) { + } + }, { + key: "filter", + value: function filter(stream, dict, length) { var filter = dict.get('Filter', 'F'); var params = dict.get('DecodeParms', 'DP'); @@ -16204,7 +16464,7 @@ var Parser = function ParserClosure() { filter = this.xref.fetchIfRef(filterArray[i]); if (!(0, _primitives.isName)(filter)) { - throw new _util.FormatError('Bad filter name: ' + filter); + throw new _util.FormatError("Bad filter name \"".concat(filter, "\"")); } params = null; @@ -16219,10 +16479,12 @@ var Parser = function ParserClosure() { } return stream; - }, - makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) { + } + }, { + key: "makeFilter", + value: function makeFilter(stream, name, maybeLength, params) { if (maybeLength === 0) { - (0, _util.warn)('Empty "' + name + '" stream.'); + (0, _util.warn)("Empty \"".concat(name, "\" stream.")); return new _stream.NullStream(); } @@ -16280,7 +16542,7 @@ var Parser = function ParserClosure() { } if (name === 'RunLengthDecode' || name === 'RL') { - xrefStreamStats[_util.StreamType.RL] = true; + xrefStreamStats[_util.StreamType.RLX] = true; return new _stream.RunLengthStream(stream, maybeLength); } @@ -16289,54 +16551,65 @@ var Parser = function ParserClosure() { return new _jbig2_stream.Jbig2Stream(stream, maybeLength, stream.dict, params); } - (0, _util.warn)('filter "' + name + '" not supported yet'); + (0, _util.warn)("Filter \"".concat(name, "\" is not supported.")); return stream; } catch (ex) { - if (ex instanceof _util.MissingDataException) { + if (ex instanceof _core_utils.MissingDataException) { throw ex; } - (0, _util.warn)('Invalid stream: \"' + ex + '\"'); + (0, _util.warn)("Invalid stream: \"".concat(ex, "\"")); return new _stream.NullStream(); } } - }; + }]); + return Parser; }(); exports.Parser = Parser; +var specialChars = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; -var Lexer = function LexerClosure() { - function Lexer(stream, knownCommands) { - this.stream = stream; - this.nextChar(); - this.strBuf = []; - this.knownCommands = knownCommands; - this.beginInlineImagePos = -1; +function toHexDigit(ch) { + if (ch >= 0x30 && ch <= 0x39) { + return ch & 0x0F; } - var specialChars = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) { + return (ch & 0x0F) + 9; + } - function toHexDigit(ch) { - if (ch >= 0x30 && ch <= 0x39) { - return ch & 0x0F; - } + return -1; +} - if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) { - return (ch & 0x0F) + 9; - } +var Lexer = +/*#__PURE__*/ +function () { + function Lexer(stream) { + var knownCommands = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + + _classCallCheck(this, Lexer); - return -1; + this.stream = stream; + this.nextChar(); + this.strBuf = []; + this.knownCommands = knownCommands; + this.beginInlineImagePos = -1; } - Lexer.prototype = { - nextChar: function Lexer_nextChar() { + _createClass(Lexer, [{ + key: "nextChar", + value: function nextChar() { return this.currentChar = this.stream.getByte(); - }, - peekChar: function Lexer_peekChar() { + } + }, { + key: "peekChar", + value: function peekChar() { return this.stream.peekByte(); - }, - getNumber: function Lexer_getNumber() { + } + }, { + key: "getNumber", + value: function getNumber() { var ch = this.currentChar; var eNotation = false; var divideBy = 0; @@ -16399,7 +16672,7 @@ var Lexer = function LexerClosure() { break; } } else if (ch === 0x2D) { - (0, _util.warn)('Badly formatted number'); + (0, _util.warn)('Badly formatted number: minus sign in the middle'); } else if (ch === 0x45 || ch === 0x65) { ch = this.peekChar(); @@ -16425,8 +16698,10 @@ var Lexer = function LexerClosure() { } return sign * baseValue; - }, - getString: function Lexer_getString() { + } + }, { + key: "getString", + value: function getString() { var numParen = 1; var done = false; var strBuf = this.strBuf; @@ -16549,8 +16824,10 @@ var Lexer = function LexerClosure() { } return strBuf.join(''); - }, - getName: function Lexer_getName() { + } + }, { + key: "getName", + value: function getName() { var ch, previousCh; var strBuf = this.strBuf; strBuf.length = 0; @@ -16573,7 +16850,7 @@ var Lexer = function LexerClosure() { var x2 = toHexDigit(ch); if (x2 === -1) { - (0, _util.warn)('Lexer_getName: Illegal digit (' + String.fromCharCode(ch) + ') in hexadecimal number.'); + (0, _util.warn)("Lexer_getName: Illegal digit (".concat(String.fromCharCode(ch), ") ") + 'in hexadecimal number.'); strBuf.push('#', String.fromCharCode(previousCh)); if (specialChars[ch]) { @@ -16594,18 +16871,19 @@ var Lexer = function LexerClosure() { } if (strBuf.length > 127) { - (0, _util.warn)('name token is longer than allowed by the spec: ' + strBuf.length); + (0, _util.warn)("Name token is longer than allowed by the spec: ".concat(strBuf.length)); } return _primitives.Name.get(strBuf.join('')); - }, - getHexString: function Lexer_getHexString() { + } + }, { + key: "getHexString", + value: function getHexString() { var strBuf = this.strBuf; strBuf.length = 0; var ch = this.currentChar; var isFirstHex = true; - var firstDigit; - var secondDigit; + var firstDigit, secondDigit; while (true) { if (ch < 0) { @@ -16622,7 +16900,7 @@ var Lexer = function LexerClosure() { firstDigit = toHexDigit(ch); if (firstDigit === -1) { - (0, _util.warn)('Ignoring invalid character "' + ch + '" in hex string'); + (0, _util.warn)("Ignoring invalid character \"".concat(ch, "\" in hex string")); ch = this.nextChar(); continue; } @@ -16630,7 +16908,7 @@ var Lexer = function LexerClosure() { secondDigit = toHexDigit(ch); if (secondDigit === -1) { - (0, _util.warn)('Ignoring invalid character "' + ch + '" in hex string'); + (0, _util.warn)("Ignoring invalid character \"".concat(ch, "\" in hex string")); ch = this.nextChar(); continue; } @@ -16644,8 +16922,10 @@ var Lexer = function LexerClosure() { } return strBuf.join(''); - }, - getObj: function Lexer_getObj() { + } + }, { + key: "getObj", + value: function getObj() { var comment = false; var ch = this.currentChar; @@ -16766,8 +17046,10 @@ var Lexer = function LexerClosure() { } return _primitives.Cmd.get(str); - }, - skipToNextLine: function Lexer_skipToNextLine() { + } + }, { + key: "skipToNextLine", + value: function skipToNextLine() { var ch = this.currentChar; while (ch >= 0) { @@ -16787,69 +17069,88 @@ var Lexer = function LexerClosure() { ch = this.nextChar(); } } - }; + }]); + return Lexer; }(); exports.Lexer = Lexer; -var Linearization = { - create: function LinearizationCreate(stream) { - function getInt(name, allowZeroValue) { - var obj = linDict.get(name); - if (Number.isInteger(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) { - return obj; +var Linearization = +/*#__PURE__*/ +function () { + function Linearization() { + _classCallCheck(this, Linearization); + } + + _createClass(Linearization, null, [{ + key: "create", + value: function create(stream) { + function getInt(linDict, name) { + var allowZeroValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var obj = linDict.get(name); + + if (Number.isInteger(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) { + return obj; + } + + throw new Error("The \"".concat(name, "\" parameter in the linearization ") + 'dictionary is invalid.'); } - throw new Error('The "' + name + '" parameter in the linearization ' + 'dictionary is invalid.'); - } + function getHints(linDict) { + var hints = linDict.get('H'); + var hintsLength; - function getHints() { - var hints = linDict.get('H'), - hintsLength, - item; + if (Array.isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) { + for (var index = 0; index < hintsLength; index++) { + var hint = hints[index]; - if (Array.isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) { - for (var index = 0; index < hintsLength; index++) { - if (!(Number.isInteger(item = hints[index]) && item > 0)) { - throw new Error('Hint (' + index + ') in the linearization dictionary is invalid.'); + if (!(Number.isInteger(hint) && hint > 0)) { + throw new Error("Hint (".concat(index, ") in the linearization dictionary ") + 'is invalid.'); + } } + + return hints; } - return hints; + throw new Error('Hint array in the linearization dictionary is invalid.'); } - throw new Error('Hint array in the linearization dictionary is invalid.'); - } + var parser = new Parser({ + lexer: new Lexer(stream), + xref: null + }); + var obj1 = parser.getObj(); + var obj2 = parser.getObj(); + var obj3 = parser.getObj(); + var linDict = parser.getObj(); + var obj, length; - var parser = new Parser(new Lexer(stream), false, null); - var obj1 = parser.getObj(); - var obj2 = parser.getObj(); - var obj3 = parser.getObj(); - var linDict = parser.getObj(); - var obj, length; + if (!(Number.isInteger(obj1) && Number.isInteger(obj2) && (0, _primitives.isCmd)(obj3, 'obj') && (0, _primitives.isDict)(linDict) && (0, _util.isNum)(obj = linDict.get('Linearized')) && obj > 0)) { + return null; + } else if ((length = getInt(linDict, 'L')) !== stream.length) { + throw new Error('The "L" parameter in the linearization dictionary ' + 'does not equal the stream length.'); + } - if (!(Number.isInteger(obj1) && Number.isInteger(obj2) && (0, _primitives.isCmd)(obj3, 'obj') && (0, _primitives.isDict)(linDict) && (0, _util.isNum)(obj = linDict.get('Linearized')) && obj > 0)) { - return null; - } else if ((length = getInt('L')) !== stream.length) { - throw new Error('The "L" parameter in the linearization dictionary ' + 'does not equal the stream length.'); + return { + length: length, + hints: getHints(linDict), + objectNumberFirst: getInt(linDict, 'O'), + endFirst: getInt(linDict, 'E'), + numPages: getInt(linDict, 'N'), + mainXRefEntriesOffset: getInt(linDict, 'T'), + pageFirst: linDict.has('P') ? getInt(linDict, 'P', true) : 0 + }; } + }]); + + return Linearization; +}(); - return { - length: length, - hints: getHints(), - objectNumberFirst: getInt('O'), - endFirst: getInt('E'), - numPages: getInt('N'), - mainXRefEntriesOffset: getInt('T'), - pageFirst: linDict.has('P') ? getInt('P', true) : 0 - }; - } -}; exports.Linearization = Linearization; /***/ }), -/* 157 */ +/* 190 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -16860,9 +17161,9 @@ Object.defineProperty(exports, "__esModule", { }); exports.LZWStream = exports.StringStream = exports.StreamsSequenceStream = exports.Stream = exports.RunLengthStream = exports.PredictorStream = exports.NullStream = exports.FlateStream = exports.DecodeStream = exports.DecryptStream = exports.AsciiHexStream = exports.Ascii85Stream = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _primitives = __w_pdfjs_require__(155); +var _primitives = __w_pdfjs_require__(183); function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } @@ -16947,6 +17248,17 @@ var Stream = function StreamClosure() { this.pos -= bytes.length; return bytes; }, + getByteRange: function getByteRange(begin, end) { + if (begin < 0) { + begin = 0; + } + + if (end > this.end) { + end = this.end; + } + + return this.bytes.subarray(begin, end); + }, skip: function Stream_skip(n) { if (!n) { n = 1; @@ -17105,6 +17417,9 @@ var DecodeStream = function DecodeStreamClosure() { return new Stream(this.buffer, start, length, dict); }, + getByteRange: function getByteRange(begin, end) { + (0, _util.unreachable)('Should not call DecodeStream.getByteRange'); + }, skip: function DecodeStream_skip(n) { if (!n) { n = 1; @@ -18131,7 +18446,7 @@ var NullStream = function NullStreamClosure() { exports.NullStream = NullStream; /***/ }), -/* 158 */ +/* 191 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -18142,11 +18457,11 @@ Object.defineProperty(exports, "__esModule", { }); exports.CCITTFaxStream = void 0; -var _primitives = __w_pdfjs_require__(155); +var _primitives = __w_pdfjs_require__(183); -var _ccitt = __w_pdfjs_require__(159); +var _ccitt = __w_pdfjs_require__(192); -var _stream = __w_pdfjs_require__(157); +var _stream = __w_pdfjs_require__(190); var CCITTFaxStream = function CCITTFaxStreamClosure() { function CCITTFaxStream(str, maybeLength, params) { @@ -18197,7 +18512,7 @@ var CCITTFaxStream = function CCITTFaxStreamClosure() { exports.CCITTFaxStream = CCITTFaxStream; /***/ }), -/* 159 */ +/* 192 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -18208,7 +18523,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.CCITTFaxDecoder = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); var CCITTFaxDecoder = function CCITTFaxDecoder() { var ccittEOL = -2; @@ -18895,7 +19210,7 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() { exports.CCITTFaxDecoder = CCITTFaxDecoder; /***/ }), -/* 160 */ +/* 193 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -18906,13 +19221,13 @@ Object.defineProperty(exports, "__esModule", { }); exports.Jbig2Stream = void 0; -var _primitives = __w_pdfjs_require__(155); +var _primitives = __w_pdfjs_require__(183); -var _stream = __w_pdfjs_require__(157); +var _stream = __w_pdfjs_require__(190); -var _jbig = __w_pdfjs_require__(161); +var _jbig = __w_pdfjs_require__(194); -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); var Jbig2Stream = function Jbig2StreamClosure() { function Jbig2Stream(stream, maybeLength, dict, params) { @@ -18978,7 +19293,7 @@ var Jbig2Stream = function Jbig2StreamClosure() { exports.Jbig2Stream = Jbig2Stream; /***/ }), -/* 161 */ +/* 194 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -18989,22 +19304,39 @@ Object.defineProperty(exports, "__esModule", { }); exports.Jbig2Image = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _arithmetic_decoder = __w_pdfjs_require__(162); +var _arithmetic_decoder = __w_pdfjs_require__(195); -var _ccitt = __w_pdfjs_require__(159); +var _ccitt = __w_pdfjs_require__(192); + +function _typeof(obj) { 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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +var Jbig2Error = +/*#__PURE__*/ +function (_BaseException) { + _inherits(Jbig2Error, _BaseException); -var Jbig2Error = function Jbig2ErrorClosure() { function Jbig2Error(msg) { - this.message = 'JBIG2 error: ' + msg; + _classCallCheck(this, Jbig2Error); + + return _possibleConstructorReturn(this, _getPrototypeOf(Jbig2Error).call(this, "JBIG2 error: ".concat(msg))); } - Jbig2Error.prototype = new Error(); - Jbig2Error.prototype.name = 'Jbig2Error'; - Jbig2Error.constructor = Jbig2Error; return Jbig2Error; -}(); +}(_util.BaseException); var Jbig2Image = function Jbig2ImageClosure() { function ContextCache() {} @@ -21177,7 +21509,7 @@ var Jbig2Image = function Jbig2ImageClosure() { exports.Jbig2Image = Jbig2Image; /***/ }), -/* 162 */ +/* 195 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -21547,7 +21879,7 @@ function () { exports.ArithmeticDecoder = ArithmeticDecoder; /***/ }), -/* 163 */ +/* 196 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -21558,13 +21890,13 @@ Object.defineProperty(exports, "__esModule", { }); exports.JpegStream = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _stream = __w_pdfjs_require__(157); +var _stream = __w_pdfjs_require__(190); -var _primitives = __w_pdfjs_require__(155); +var _primitives = __w_pdfjs_require__(183); -var _jpg = __w_pdfjs_require__(164); +var _jpg = __w_pdfjs_require__(197); var JpegStream = function JpegStreamClosure() { function JpegStream(stream, maybeLength, dict, params) { @@ -21659,7 +21991,7 @@ var JpegStream = function JpegStreamClosure() { exports.JpegStream = JpegStream; /***/ }), -/* 164 */ +/* 197 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -21670,43 +22002,67 @@ Object.defineProperty(exports, "__esModule", { }); exports.JpegImage = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); function _typeof(obj) { 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 JpegError = function JpegErrorClosure() { +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +var JpegError = +/*#__PURE__*/ +function (_BaseException) { + _inherits(JpegError, _BaseException); + function JpegError(msg) { - this.message = 'JPEG error: ' + msg; + _classCallCheck(this, JpegError); + + return _possibleConstructorReturn(this, _getPrototypeOf(JpegError).call(this, "JPEG error: ".concat(msg))); } - JpegError.prototype = new Error(); - JpegError.prototype.name = 'JpegError'; - JpegError.constructor = JpegError; return JpegError; -}(); +}(_util.BaseException); + +var DNLMarkerError = +/*#__PURE__*/ +function (_BaseException2) { + _inherits(DNLMarkerError, _BaseException2); -var DNLMarkerError = function DNLMarkerErrorClosure() { function DNLMarkerError(message, scanLines) { - this.message = message; - this.scanLines = scanLines; + var _this; + + _classCallCheck(this, DNLMarkerError); + + _this = _possibleConstructorReturn(this, _getPrototypeOf(DNLMarkerError).call(this, message)); + _this.scanLines = scanLines; + return _this; } - DNLMarkerError.prototype = new Error(); - DNLMarkerError.prototype.name = 'DNLMarkerError'; - DNLMarkerError.constructor = DNLMarkerError; return DNLMarkerError; -}(); +}(_util.BaseException); -var EOIMarkerError = function EOIMarkerErrorClosure() { - function EOIMarkerError(message) { - this.message = message; +var EOIMarkerError = +/*#__PURE__*/ +function (_BaseException3) { + _inherits(EOIMarkerError, _BaseException3); + + function EOIMarkerError() { + _classCallCheck(this, EOIMarkerError); + + return _possibleConstructorReturn(this, _getPrototypeOf(EOIMarkerError).apply(this, arguments)); } - EOIMarkerError.prototype = new Error(); - EOIMarkerError.prototype.name = 'EOIMarkerError'; - EOIMarkerError.constructor = EOIMarkerError; return EOIMarkerError; -}(); +}(_util.BaseException); var JpegImage = function JpegImageClosure() { var dctZigZag = new Uint8Array([0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63]); @@ -22101,7 +22457,9 @@ var JpegImage = function JpegImageClosure() { bitsCount = 0; fileMarker = findNextFileMarker(data, offset); - if (fileMarker && fileMarker.invalid) { + if (!fileMarker) { + break; + } else if (fileMarker.invalid) { (0, _util.warn)('decodeScan - unexpected MCU data, current marker is: ' + fileMarker.invalid); offset = fileMarker.offset; } @@ -22109,7 +22467,7 @@ var JpegImage = function JpegImageClosure() { var marker = fileMarker && fileMarker.marker; if (!marker || marker <= 0xFF00) { - throw new JpegError('marker was not found'); + throw new JpegError('decodeScan - a valid marker was not found.'); } if (marker >= 0xFFD0 && marker <= 0xFFD7) { @@ -22630,7 +22988,12 @@ var JpegImage = function JpegImageClosure() { break; } - throw new JpegError('unknown marker ' + fileMarker.toString(16)); + if (offset > data.length - 2) { + (0, _util.warn)('JpegImage.parse - reached the end of the image data ' + 'without finding an EOI marker (0xFFD9).'); + break markerLoop; + } + + throw new JpegError('JpegImage.parse - unknown marker: ' + fileMarker.toString(16)); } fileMarker = readUint16(); @@ -22660,6 +23023,7 @@ var JpegImage = function JpegImageClosure() { } this.numComponents = this.components.length; + return undefined; }, _getLinearizedBlockData: function _getLinearizedBlockData(width, height) { var isSourcePDF = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; @@ -22848,7 +23212,7 @@ var JpegImage = function JpegImageClosure() { exports.JpegImage = JpegImage; /***/ }), -/* 165 */ +/* 198 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -22859,11 +23223,11 @@ Object.defineProperty(exports, "__esModule", { }); exports.JpxStream = void 0; -var _stream = __w_pdfjs_require__(157); +var _stream = __w_pdfjs_require__(190); -var _jpx = __w_pdfjs_require__(166); +var _jpx = __w_pdfjs_require__(199); -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); var JpxStream = function JpxStreamClosure() { function JpxStream(stream, maybeLength, dict, params) { @@ -22935,7 +23299,7 @@ var JpxStream = function JpxStreamClosure() { exports.JpxStream = JpxStream; /***/ }), -/* 166 */ +/* 199 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -22946,20 +23310,37 @@ Object.defineProperty(exports, "__esModule", { }); exports.JpxImage = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); + +var _arithmetic_decoder = __w_pdfjs_require__(195); -var _arithmetic_decoder = __w_pdfjs_require__(162); +function _typeof(obj) { 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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + +function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } + +function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } + +var JpxError = +/*#__PURE__*/ +function (_BaseException) { + _inherits(JpxError, _BaseException); -var JpxError = function JpxErrorClosure() { function JpxError(msg) { - this.message = 'JPX error: ' + msg; + _classCallCheck(this, JpxError); + + return _possibleConstructorReturn(this, _getPrototypeOf(JpxError).call(this, "JPX error: ".concat(msg))); } - JpxError.prototype = new Error(); - JpxError.prototype.name = 'JpxError'; - JpxError.constructor = JpxError; return JpxError; -}(); +}(_util.BaseException); var JpxImage = function JpxImageClosure() { var SubbandsGainLog2 = { @@ -25253,7 +25634,7 @@ var JpxImage = function JpxImageClosure() { exports.JpxImage = JpxImage; /***/ }), -/* 167 */ +/* 200 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -25264,11 +25645,11 @@ Object.defineProperty(exports, "__esModule", { }); exports.calculateSHA512 = exports.calculateSHA384 = exports.calculateSHA256 = exports.calculateMD5 = exports.PDF20 = exports.PDF17 = exports.CipherTransformFactory = exports.ARCFourCipher = exports.AES256Cipher = exports.AES128Cipher = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _primitives = __w_pdfjs_require__(155); +var _primitives = __w_pdfjs_require__(183); -var _stream = __w_pdfjs_require__(157); +var _stream = __w_pdfjs_require__(190); function _typeof(obj) { 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); } @@ -26901,7 +27282,7 @@ var CipherTransformFactory = function CipherTransformFactoryClosure() { exports.CipherTransformFactory = CipherTransformFactory; /***/ }), -/* 168 */ +/* 201 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -26912,9 +27293,9 @@ Object.defineProperty(exports, "__esModule", { }); exports.ColorSpace = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _primitives = __w_pdfjs_require__(155); +var _primitives = __w_pdfjs_require__(183); function _typeof(obj) { 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); } @@ -28111,7 +28492,7 @@ var LabCS = function LabCSClosure() { }(); /***/ }), -/* 169 */ +/* 202 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -28120,19 +28501,26 @@ var LabCS = function LabCSClosure() { Object.defineProperty(exports, "__esModule", { value: true }); -exports.AnnotationFactory = exports.AnnotationBorderStyle = exports.Annotation = void 0; +exports.getQuadPoints = getQuadPoints; +exports.MarkupAnnotation = exports.AnnotationFactory = exports.AnnotationBorderStyle = exports.Annotation = void 0; + +var _util = __w_pdfjs_require__(5); -var _util = __w_pdfjs_require__(6); +var _obj = __w_pdfjs_require__(188); -var _obj = __w_pdfjs_require__(154); +var _primitives = __w_pdfjs_require__(183); -var _primitives = __w_pdfjs_require__(155); +var _colorspace = __w_pdfjs_require__(201); -var _colorspace = __w_pdfjs_require__(168); +var _core_utils = __w_pdfjs_require__(186); -var _operator_list = __w_pdfjs_require__(170); +var _operator_list = __w_pdfjs_require__(203); -var _stream = __w_pdfjs_require__(157); +var _stream = __w_pdfjs_require__(190); + +function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); } + +function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } function _typeof(obj) { 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); } @@ -28140,16 +28528,20 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } -function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); } - -function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } - function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } + +function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } + +function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { 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); } } @@ -28174,16 +28566,15 @@ function () { var dict = xref.fetchIfRef(ref); if (!(0, _primitives.isDict)(dict)) { - return; + return undefined; } - var id = (0, _primitives.isRef)(ref) ? ref.toString() : 'annot_' + idFactory.createObjId(); + var id = (0, _primitives.isRef)(ref) ? ref.toString() : "annot_".concat(idFactory.createObjId()); var subtype = dict.get('Subtype'); subtype = (0, _primitives.isName)(subtype) ? subtype.name : null; var parameters = { xref: xref, dict: dict, - ref: (0, _primitives.isRef)(ref) ? ref : null, subtype: subtype, id: id, pdfManager: pdfManager @@ -28197,7 +28588,7 @@ function () { return new TextAnnotation(parameters); case 'Widget': - var fieldType = (0, _util.getInheritableProperty)({ + var fieldType = (0, _core_utils.getInheritableProperty)({ dict: dict, key: 'FT' }); @@ -28220,6 +28611,9 @@ function () { case 'Popup': return new PopupAnnotation(parameters); + case 'FreeText': + return new FreeTextAnnotation(parameters); + case 'Line': return new LineAnnotation(parameters); @@ -28235,6 +28629,9 @@ function () { case 'Polygon': return new PolygonAnnotation(parameters); + case 'Caret': + return new CaretAnnotation(parameters); + case 'Ink': return new InkAnnotation(parameters); @@ -28273,13 +28670,47 @@ function () { exports.AnnotationFactory = AnnotationFactory; -function getTransformMatrix(rect, bbox, matrix) { - var bounds = _util.Util.getAxialAlignedBoundingBox(bbox, matrix); +function getQuadPoints(dict, rect) { + if (!dict.has('QuadPoints')) { + return null; + } + + var quadPoints = dict.getArray('QuadPoints'); + + if (!Array.isArray(quadPoints) || quadPoints.length % 8 > 0) { + return null; + } + + var quadPointsLists = []; - var minX = bounds[0]; - var minY = bounds[1]; - var maxX = bounds[2]; - var maxY = bounds[3]; + for (var i = 0, ii = quadPoints.length / 8; i < ii; i++) { + quadPointsLists.push([]); + + for (var j = i * 8, jj = i * 8 + 8; j < jj; j += 2) { + var x = quadPoints[j]; + var y = quadPoints[j + 1]; + + if (x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) { + return null; + } + + quadPointsLists[i].push({ + x: x, + y: y + }); + } + } + + return quadPointsLists; +} + +function getTransformMatrix(rect, bbox, matrix) { + var _Util$getAxialAligned = _util.Util.getAxialAlignedBoundingBox(bbox, matrix), + _Util$getAxialAligned2 = _slicedToArray(_Util$getAxialAligned, 4), + minX = _Util$getAxialAligned2[0], + minY = _Util$getAxialAligned2[1], + maxX = _Util$getAxialAligned2[2], + maxY = _Util$getAxialAligned2[3]; if (minX === maxX || minY === maxY) { return [1, 0, 0, 1, rect[0], rect[1]]; @@ -28297,6 +28728,8 @@ function () { _classCallCheck(this, Annotation); var dict = params.dict; + this.setContents(dict.get('Contents')); + this.setModificationDate(dict.get('M')); this.setFlags(dict.get('F')); this.setRectangle(dict.getArray('Rect')); this.setColor(dict.getArray('C')); @@ -28306,8 +28739,10 @@ function () { annotationFlags: this.flags, borderStyle: this.borderStyle, color: this.color, + contents: this.contents, hasAppearance: !!this.appearance, id: params.id, + modificationDate: this.modificationDate, rect: this.rectangle, subtype: params.subtype }; @@ -28329,6 +28764,16 @@ function () { return this._hasFlag(flags, _util.AnnotationFlag.PRINT) && !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN); } }, { + key: "setContents", + value: function setContents(contents) { + this.contents = (0, _util.stringToPDFString)(contents || ''); + } + }, { + key: "setModificationDate", + value: function setModificationDate(modificationDate) { + this.modificationDate = (0, _util.isString)(modificationDate) ? modificationDate : null; + } + }, { key: "setFlags", value: function setFlags(flags) { this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0; @@ -28399,7 +28844,7 @@ function () { var dictType = dict.get('Type'); if (!dictType || (0, _primitives.isName)(dictType, 'Border')) { - this.borderStyle.setWidth(dict.get('W')); + this.borderStyle.setWidth(dict.get('W'), this.rectangle); this.borderStyle.setStyle(dict.get('S')); this.borderStyle.setDashArray(dict.getArray('D')); } @@ -28409,7 +28854,7 @@ function () { if (Array.isArray(array) && array.length >= 3) { this.borderStyle.setHorizontalCornerRadius(array[0]); this.borderStyle.setVerticalCornerRadius(array[1]); - this.borderStyle.setWidth(array[2]); + this.borderStyle.setWidth(array[2], this.rectangle); if (array.length === 4) { this.borderStyle.setDashArray(array[3]); @@ -28449,22 +28894,11 @@ function () { this.appearance = normalAppearanceState.get(as.name); } }, { - key: "_preparePopup", - value: function _preparePopup(dict) { - if (!dict.has('C')) { - this.data.color = null; - } - - this.data.hasPopup = dict.has('Popup'); - this.data.title = (0, _util.stringToPDFString)(dict.get('T') || ''); - this.data.contents = (0, _util.stringToPDFString)(dict.get('Contents') || ''); - } - }, { key: "loadResources", value: function loadResources(keys) { return this.appearance.dict.getAsync('Resources').then(function (resources) { if (!resources) { - return; + return undefined; } var objectLoader = new _obj.ObjectLoader(resources, keys, resources.xref); @@ -28546,12 +28980,24 @@ function () { _createClass(AnnotationBorderStyle, [{ key: "setWidth", value: function setWidth(width) { + var rect = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0, 0]; + if ((0, _primitives.isName)(width)) { this.width = 0; return; } if (Number.isInteger(width)) { + if (width > 0) { + var maxWidth = (rect[2] - rect[0]) / 2; + var maxHeight = (rect[3] - rect[1]) / 2; + + if (maxWidth > 0 && maxHeight > 0 && (width > maxWidth || width > maxHeight)) { + (0, _util.warn)("AnnotationBorderStyle.setWidth - ignoring width: ".concat(width)); + width = 1; + } + } + this.width = width; } } @@ -28593,16 +29039,34 @@ function () { if (Array.isArray(dashArray) && dashArray.length > 0) { var isValid = true; var allZeros = true; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; - for (var i = 0, len = dashArray.length; i < len; i++) { - var element = dashArray[i]; - var validNumber = +element >= 0; + try { + for (var _iterator = dashArray[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var element = _step.value; + var validNumber = +element >= 0; - if (!validNumber) { - isValid = false; - break; - } else if (element > 0) { - allZeros = false; + if (!validNumber) { + isValid = false; + break; + } else if (element > 0) { + allZeros = false; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"] != null) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } } } @@ -28636,41 +29100,122 @@ function () { exports.AnnotationBorderStyle = AnnotationBorderStyle; -var WidgetAnnotation = +var MarkupAnnotation = /*#__PURE__*/ function (_Annotation) { - _inherits(WidgetAnnotation, _Annotation); + _inherits(MarkupAnnotation, _Annotation); - function WidgetAnnotation(params) { + function MarkupAnnotation(parameters) { var _this2; + _classCallCheck(this, MarkupAnnotation); + + _this2 = _possibleConstructorReturn(this, _getPrototypeOf(MarkupAnnotation).call(this, parameters)); + var dict = parameters.dict; + + if (dict.has('IRT')) { + var rawIRT = dict.getRaw('IRT'); + _this2.data.inReplyTo = (0, _primitives.isRef)(rawIRT) ? rawIRT.toString() : null; + var rt = dict.get('RT'); + _this2.data.replyType = (0, _primitives.isName)(rt) ? rt.name : _util.AnnotationReplyType.REPLY; + } + + if (_this2.data.replyType === _util.AnnotationReplyType.GROUP) { + var parent = dict.get('IRT'); + _this2.data.title = (0, _util.stringToPDFString)(parent.get('T') || ''); + + _this2.setContents(parent.get('Contents')); + + _this2.data.contents = _this2.contents; + + if (!parent.has('CreationDate')) { + _this2.data.creationDate = null; + } else { + _this2.setCreationDate(parent.get('CreationDate')); + + _this2.data.creationDate = _this2.creationDate; + } + + if (!parent.has('M')) { + _this2.data.modificationDate = null; + } else { + _this2.setModificationDate(parent.get('M')); + + _this2.data.modificationDate = _this2.modificationDate; + } + + _this2.data.hasPopup = parent.has('Popup'); + + if (!parent.has('C')) { + _this2.data.color = null; + } else { + _this2.setColor(parent.getArray('C')); + + _this2.data.color = _this2.color; + } + } else { + _this2.data.title = (0, _util.stringToPDFString)(dict.get('T') || ''); + + _this2.setCreationDate(dict.get('CreationDate')); + + _this2.data.creationDate = _this2.creationDate; + _this2.data.hasPopup = dict.has('Popup'); + + if (!dict.has('C')) { + _this2.data.color = null; + } + } + + return _this2; + } + + _createClass(MarkupAnnotation, [{ + key: "setCreationDate", + value: function setCreationDate(creationDate) { + this.creationDate = (0, _util.isString)(creationDate) ? creationDate : null; + } + }]); + + return MarkupAnnotation; +}(Annotation); + +exports.MarkupAnnotation = MarkupAnnotation; + +var WidgetAnnotation = +/*#__PURE__*/ +function (_Annotation2) { + _inherits(WidgetAnnotation, _Annotation2); + + function WidgetAnnotation(params) { + var _this3; + _classCallCheck(this, WidgetAnnotation); - _this2 = _possibleConstructorReturn(this, _getPrototypeOf(WidgetAnnotation).call(this, params)); + _this3 = _possibleConstructorReturn(this, _getPrototypeOf(WidgetAnnotation).call(this, params)); var dict = params.dict; - var data = _this2.data; + var data = _this3.data; data.annotationType = _util.AnnotationType.WIDGET; - data.fieldName = _this2._constructFieldName(dict); - data.fieldValue = (0, _util.getInheritableProperty)({ + data.fieldName = _this3._constructFieldName(dict); + data.fieldValue = (0, _core_utils.getInheritableProperty)({ dict: dict, key: 'V', getArray: true }); data.alternativeText = (0, _util.stringToPDFString)(dict.get('TU') || ''); - data.defaultAppearance = (0, _util.getInheritableProperty)({ + data.defaultAppearance = (0, _core_utils.getInheritableProperty)({ dict: dict, key: 'DA' }) || ''; - var fieldType = (0, _util.getInheritableProperty)({ + var fieldType = (0, _core_utils.getInheritableProperty)({ dict: dict, key: 'FT' }); data.fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null; - _this2.fieldResources = (0, _util.getInheritableProperty)({ + _this3.fieldResources = (0, _core_utils.getInheritableProperty)({ dict: dict, key: 'DR' }) || _primitives.Dict.empty; - data.fieldFlags = (0, _util.getInheritableProperty)({ + data.fieldFlags = (0, _core_utils.getInheritableProperty)({ dict: dict, key: 'Ff' }); @@ -28679,15 +29224,15 @@ function (_Annotation) { data.fieldFlags = 0; } - data.readOnly = _this2.hasFieldFlag(_util.AnnotationFieldFlag.READONLY); + data.readOnly = _this3.hasFieldFlag(_util.AnnotationFieldFlag.READONLY); if (data.fieldType === 'Sig') { data.fieldValue = null; - _this2.setFlags(_util.AnnotationFlag.HIDDEN); + _this3.setFlags(_util.AnnotationFlag.HIDDEN); } - return _this2; + return _this3; } _createClass(WidgetAnnotation, [{ @@ -28749,14 +29294,14 @@ function (_WidgetAnnotation) { _inherits(TextWidgetAnnotation, _WidgetAnnotation); function TextWidgetAnnotation(params) { - var _this3; + var _this4; _classCallCheck(this, TextWidgetAnnotation); - _this3 = _possibleConstructorReturn(this, _getPrototypeOf(TextWidgetAnnotation).call(this, params)); + _this4 = _possibleConstructorReturn(this, _getPrototypeOf(TextWidgetAnnotation).call(this, params)); var dict = params.dict; - _this3.data.fieldValue = (0, _util.stringToPDFString)(_this3.data.fieldValue || ''); - var alignment = (0, _util.getInheritableProperty)({ + _this4.data.fieldValue = (0, _util.stringToPDFString)(_this4.data.fieldValue || ''); + var alignment = (0, _core_utils.getInheritableProperty)({ dict: dict, key: 'Q' }); @@ -28765,8 +29310,8 @@ function (_WidgetAnnotation) { alignment = null; } - _this3.data.textAlignment = alignment; - var maximumLength = (0, _util.getInheritableProperty)({ + _this4.data.textAlignment = alignment; + var maximumLength = (0, _core_utils.getInheritableProperty)({ dict: dict, key: 'MaxLen' }); @@ -28775,10 +29320,10 @@ function (_WidgetAnnotation) { maximumLength = null; } - _this3.data.maxLen = maximumLength; - _this3.data.multiLine = _this3.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE); - _this3.data.comb = _this3.hasFieldFlag(_util.AnnotationFieldFlag.COMB) && !_this3.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE) && !_this3.hasFieldFlag(_util.AnnotationFieldFlag.PASSWORD) && !_this3.hasFieldFlag(_util.AnnotationFieldFlag.FILESELECT) && _this3.data.maxLen !== null; - return _this3; + _this4.data.maxLen = maximumLength; + _this4.data.multiLine = _this4.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE); + _this4.data.comb = _this4.hasFieldFlag(_util.AnnotationFieldFlag.COMB) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.PASSWORD) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.FILESELECT) && _this4.data.maxLen !== null; + return _this4; } _createClass(TextWidgetAnnotation, [{ @@ -28815,26 +29360,26 @@ function (_WidgetAnnotation2) { _inherits(ButtonWidgetAnnotation, _WidgetAnnotation2); function ButtonWidgetAnnotation(params) { - var _this4; + var _this5; _classCallCheck(this, ButtonWidgetAnnotation); - _this4 = _possibleConstructorReturn(this, _getPrototypeOf(ButtonWidgetAnnotation).call(this, params)); - _this4.data.checkBox = !_this4.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON); - _this4.data.radioButton = _this4.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON); - _this4.data.pushButton = _this4.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON); - - if (_this4.data.checkBox) { - _this4._processCheckBox(params); - } else if (_this4.data.radioButton) { - _this4._processRadioButton(params); - } else if (_this4.data.pushButton) { - _this4._processPushButton(params); + _this5 = _possibleConstructorReturn(this, _getPrototypeOf(ButtonWidgetAnnotation).call(this, params)); + _this5.data.checkBox = !_this5.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this5.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON); + _this5.data.radioButton = _this5.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this5.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON); + _this5.data.pushButton = _this5.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON); + + if (_this5.data.checkBox) { + _this5._processCheckBox(params); + } else if (_this5.data.radioButton) { + _this5._processRadioButton(params); + } else if (_this5.data.pushButton) { + _this5._processPushButton(params); } else { (0, _util.warn)('Invalid field flags for button widget annotation'); } - return _this4; + return _this5; } _createClass(ButtonWidgetAnnotation, [{ @@ -28891,12 +29436,31 @@ function (_WidgetAnnotation2) { return; } - var keys = normalAppearanceState.getKeys(); + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; - for (var i = 0, ii = keys.length; i < ii; i++) { - if (keys[i] !== 'Off') { - this.data.buttonValue = keys[i]; - break; + try { + for (var _iterator2 = normalAppearanceState.getKeys()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var key = _step2.value; + + if (key !== 'Off') { + this.data.buttonValue = key; + break; + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } } } } @@ -28925,13 +29489,13 @@ function (_WidgetAnnotation3) { _inherits(ChoiceWidgetAnnotation, _WidgetAnnotation3); function ChoiceWidgetAnnotation(params) { - var _this5; + var _this6; _classCallCheck(this, ChoiceWidgetAnnotation); - _this5 = _possibleConstructorReturn(this, _getPrototypeOf(ChoiceWidgetAnnotation).call(this, params)); - _this5.data.options = []; - var options = (0, _util.getInheritableProperty)({ + _this6 = _possibleConstructorReturn(this, _getPrototypeOf(ChoiceWidgetAnnotation).call(this, params)); + _this6.data.options = []; + var options = (0, _core_utils.getInheritableProperty)({ dict: params.dict, key: 'Opt' }); @@ -28942,20 +29506,20 @@ function (_WidgetAnnotation3) { for (var i = 0, ii = options.length; i < ii; i++) { var option = xref.fetchIfRef(options[i]); var isOptionArray = Array.isArray(option); - _this5.data.options[i] = { + _this6.data.options[i] = { exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option, displayValue: (0, _util.stringToPDFString)(isOptionArray ? xref.fetchIfRef(option[1]) : option) }; } } - if (!Array.isArray(_this5.data.fieldValue)) { - _this5.data.fieldValue = [_this5.data.fieldValue]; + if (!Array.isArray(_this6.data.fieldValue)) { + _this6.data.fieldValue = [_this6.data.fieldValue]; } - _this5.data.combo = _this5.hasFieldFlag(_util.AnnotationFieldFlag.COMBO); - _this5.data.multiSelect = _this5.hasFieldFlag(_util.AnnotationFieldFlag.MULTISELECT); - return _this5; + _this6.data.combo = _this6.hasFieldFlag(_util.AnnotationFieldFlag.COMBO); + _this6.data.multiSelect = _this6.hasFieldFlag(_util.AnnotationFieldFlag.MULTISELECT); + return _this6; } return ChoiceWidgetAnnotation; @@ -28963,33 +29527,40 @@ function (_WidgetAnnotation3) { var TextAnnotation = /*#__PURE__*/ -function (_Annotation2) { - _inherits(TextAnnotation, _Annotation2); +function (_MarkupAnnotation) { + _inherits(TextAnnotation, _MarkupAnnotation); function TextAnnotation(parameters) { - var _this6; + var _this7; _classCallCheck(this, TextAnnotation); var DEFAULT_ICON_SIZE = 22; - _this6 = _possibleConstructorReturn(this, _getPrototypeOf(TextAnnotation).call(this, parameters)); - _this6.data.annotationType = _util.AnnotationType.TEXT; + _this7 = _possibleConstructorReturn(this, _getPrototypeOf(TextAnnotation).call(this, parameters)); + var dict = parameters.dict; + _this7.data.annotationType = _util.AnnotationType.TEXT; - if (_this6.data.hasAppearance) { - _this6.data.name = 'NoIcon'; + if (_this7.data.hasAppearance) { + _this7.data.name = 'NoIcon'; } else { - _this6.data.rect[1] = _this6.data.rect[3] - DEFAULT_ICON_SIZE; - _this6.data.rect[2] = _this6.data.rect[0] + DEFAULT_ICON_SIZE; - _this6.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note'; + _this7.data.rect[1] = _this7.data.rect[3] - DEFAULT_ICON_SIZE; + _this7.data.rect[2] = _this7.data.rect[0] + DEFAULT_ICON_SIZE; + _this7.data.name = dict.has('Name') ? dict.get('Name').name : 'Note'; } - _this6._preparePopup(parameters.dict); + if (dict.has('State')) { + _this7.data.state = dict.get('State') || null; + _this7.data.stateModel = dict.get('StateModel') || null; + } else { + _this7.data.state = null; + _this7.data.stateModel = null; + } - return _this6; + return _this7; } return TextAnnotation; -}(Annotation); +}(MarkupAnnotation); var LinkAnnotation = /*#__PURE__*/ @@ -28997,20 +29568,25 @@ function (_Annotation3) { _inherits(LinkAnnotation, _Annotation3); function LinkAnnotation(params) { - var _this7; + var _this8; _classCallCheck(this, LinkAnnotation); - _this7 = _possibleConstructorReturn(this, _getPrototypeOf(LinkAnnotation).call(this, params)); - _this7.data.annotationType = _util.AnnotationType.LINK; + _this8 = _possibleConstructorReturn(this, _getPrototypeOf(LinkAnnotation).call(this, params)); + _this8.data.annotationType = _util.AnnotationType.LINK; + var quadPoints = getQuadPoints(params.dict, _this8.rectangle); + + if (quadPoints) { + _this8.data.quadPoints = quadPoints; + } _obj.Catalog.parseDestDictionary({ destDict: params.dict, - resultObj: _this7.data, + resultObj: _this8.data, docBaseUrl: params.pdfManager.docBaseUrl }); - return _this7; + return _this8; } return LinkAnnotation; @@ -29022,143 +29598,161 @@ function (_Annotation4) { _inherits(PopupAnnotation, _Annotation4); function PopupAnnotation(parameters) { - var _this8; + var _this9; _classCallCheck(this, PopupAnnotation); - _this8 = _possibleConstructorReturn(this, _getPrototypeOf(PopupAnnotation).call(this, parameters)); - _this8.data.annotationType = _util.AnnotationType.POPUP; - var dict = parameters.dict; - var parentItem = dict.get('Parent'); + _this9 = _possibleConstructorReturn(this, _getPrototypeOf(PopupAnnotation).call(this, parameters)); + _this9.data.annotationType = _util.AnnotationType.POPUP; + var parentItem = parameters.dict.get('Parent'); if (!parentItem) { (0, _util.warn)('Popup annotation has a missing or invalid parent annotation.'); - return _possibleConstructorReturn(_this8); + return _possibleConstructorReturn(_this9); } var parentSubtype = parentItem.get('Subtype'); - _this8.data.parentType = (0, _primitives.isName)(parentSubtype) ? parentSubtype.name : null; - _this8.data.parentId = dict.getRaw('Parent').toString(); - _this8.data.title = (0, _util.stringToPDFString)(parentItem.get('T') || ''); - _this8.data.contents = (0, _util.stringToPDFString)(parentItem.get('Contents') || ''); + _this9.data.parentType = (0, _primitives.isName)(parentSubtype) ? parentSubtype.name : null; + var rawParent = parameters.dict.getRaw('Parent'); + _this9.data.parentId = (0, _primitives.isRef)(rawParent) ? rawParent.toString() : null; + var rt = parentItem.get('RT'); + + if ((0, _primitives.isName)(rt, _util.AnnotationReplyType.GROUP)) { + parentItem = parentItem.get('IRT'); + } + + if (!parentItem.has('M')) { + _this9.data.modificationDate = null; + } else { + _this9.setModificationDate(parentItem.get('M')); + + _this9.data.modificationDate = _this9.modificationDate; + } if (!parentItem.has('C')) { - _this8.data.color = null; + _this9.data.color = null; } else { - _this8.setColor(parentItem.getArray('C')); + _this9.setColor(parentItem.getArray('C')); - _this8.data.color = _this8.color; + _this9.data.color = _this9.color; } - if (!_this8.viewable) { + if (!_this9.viewable) { var parentFlags = parentItem.get('F'); - if (_this8._isViewable(parentFlags)) { - _this8.setFlags(parentFlags); + if (_this9._isViewable(parentFlags)) { + _this9.setFlags(parentFlags); } } - return _this8; + _this9.data.title = (0, _util.stringToPDFString)(parentItem.get('T') || ''); + _this9.data.contents = (0, _util.stringToPDFString)(parentItem.get('Contents') || ''); + return _this9; } return PopupAnnotation; }(Annotation); +var FreeTextAnnotation = +/*#__PURE__*/ +function (_MarkupAnnotation2) { + _inherits(FreeTextAnnotation, _MarkupAnnotation2); + + function FreeTextAnnotation(parameters) { + var _this10; + + _classCallCheck(this, FreeTextAnnotation); + + _this10 = _possibleConstructorReturn(this, _getPrototypeOf(FreeTextAnnotation).call(this, parameters)); + _this10.data.annotationType = _util.AnnotationType.FREETEXT; + return _this10; + } + + return FreeTextAnnotation; +}(MarkupAnnotation); + var LineAnnotation = /*#__PURE__*/ -function (_Annotation5) { - _inherits(LineAnnotation, _Annotation5); +function (_MarkupAnnotation3) { + _inherits(LineAnnotation, _MarkupAnnotation3); function LineAnnotation(parameters) { - var _this9; + var _this11; _classCallCheck(this, LineAnnotation); - _this9 = _possibleConstructorReturn(this, _getPrototypeOf(LineAnnotation).call(this, parameters)); - _this9.data.annotationType = _util.AnnotationType.LINE; - var dict = parameters.dict; - _this9.data.lineCoordinates = _util.Util.normalizeRect(dict.getArray('L')); - - _this9._preparePopup(dict); - - return _this9; + _this11 = _possibleConstructorReturn(this, _getPrototypeOf(LineAnnotation).call(this, parameters)); + _this11.data.annotationType = _util.AnnotationType.LINE; + _this11.data.lineCoordinates = _util.Util.normalizeRect(parameters.dict.getArray('L')); + return _this11; } return LineAnnotation; -}(Annotation); +}(MarkupAnnotation); var SquareAnnotation = /*#__PURE__*/ -function (_Annotation6) { - _inherits(SquareAnnotation, _Annotation6); +function (_MarkupAnnotation4) { + _inherits(SquareAnnotation, _MarkupAnnotation4); function SquareAnnotation(parameters) { - var _this10; + var _this12; _classCallCheck(this, SquareAnnotation); - _this10 = _possibleConstructorReturn(this, _getPrototypeOf(SquareAnnotation).call(this, parameters)); - _this10.data.annotationType = _util.AnnotationType.SQUARE; - - _this10._preparePopup(parameters.dict); - - return _this10; + _this12 = _possibleConstructorReturn(this, _getPrototypeOf(SquareAnnotation).call(this, parameters)); + _this12.data.annotationType = _util.AnnotationType.SQUARE; + return _this12; } return SquareAnnotation; -}(Annotation); +}(MarkupAnnotation); var CircleAnnotation = /*#__PURE__*/ -function (_Annotation7) { - _inherits(CircleAnnotation, _Annotation7); +function (_MarkupAnnotation5) { + _inherits(CircleAnnotation, _MarkupAnnotation5); function CircleAnnotation(parameters) { - var _this11; + var _this13; _classCallCheck(this, CircleAnnotation); - _this11 = _possibleConstructorReturn(this, _getPrototypeOf(CircleAnnotation).call(this, parameters)); - _this11.data.annotationType = _util.AnnotationType.CIRCLE; - - _this11._preparePopup(parameters.dict); - - return _this11; + _this13 = _possibleConstructorReturn(this, _getPrototypeOf(CircleAnnotation).call(this, parameters)); + _this13.data.annotationType = _util.AnnotationType.CIRCLE; + return _this13; } return CircleAnnotation; -}(Annotation); +}(MarkupAnnotation); var PolylineAnnotation = /*#__PURE__*/ -function (_Annotation8) { - _inherits(PolylineAnnotation, _Annotation8); +function (_MarkupAnnotation6) { + _inherits(PolylineAnnotation, _MarkupAnnotation6); function PolylineAnnotation(parameters) { - var _this12; + var _this14; _classCallCheck(this, PolylineAnnotation); - _this12 = _possibleConstructorReturn(this, _getPrototypeOf(PolylineAnnotation).call(this, parameters)); - _this12.data.annotationType = _util.AnnotationType.POLYLINE; - var dict = parameters.dict; - var rawVertices = dict.getArray('Vertices'); - _this12.data.vertices = []; + _this14 = _possibleConstructorReturn(this, _getPrototypeOf(PolylineAnnotation).call(this, parameters)); + _this14.data.annotationType = _util.AnnotationType.POLYLINE; + var rawVertices = parameters.dict.getArray('Vertices'); + _this14.data.vertices = []; for (var i = 0, ii = rawVertices.length; i < ii; i += 2) { - _this12.data.vertices.push({ + _this14.data.vertices.push({ x: rawVertices[i], y: rawVertices[i + 1] }); } - _this12._preparePopup(dict); - - return _this12; + return _this14; } return PolylineAnnotation; -}(Annotation); +}(MarkupAnnotation); var PolygonAnnotation = /*#__PURE__*/ @@ -29166,184 +29760,205 @@ function (_PolylineAnnotation) { _inherits(PolygonAnnotation, _PolylineAnnotation); function PolygonAnnotation(parameters) { - var _this13; + var _this15; _classCallCheck(this, PolygonAnnotation); - _this13 = _possibleConstructorReturn(this, _getPrototypeOf(PolygonAnnotation).call(this, parameters)); - _this13.data.annotationType = _util.AnnotationType.POLYGON; - return _this13; + _this15 = _possibleConstructorReturn(this, _getPrototypeOf(PolygonAnnotation).call(this, parameters)); + _this15.data.annotationType = _util.AnnotationType.POLYGON; + return _this15; } return PolygonAnnotation; }(PolylineAnnotation); +var CaretAnnotation = +/*#__PURE__*/ +function (_MarkupAnnotation7) { + _inherits(CaretAnnotation, _MarkupAnnotation7); + + function CaretAnnotation(parameters) { + var _this16; + + _classCallCheck(this, CaretAnnotation); + + _this16 = _possibleConstructorReturn(this, _getPrototypeOf(CaretAnnotation).call(this, parameters)); + _this16.data.annotationType = _util.AnnotationType.CARET; + return _this16; + } + + return CaretAnnotation; +}(MarkupAnnotation); + var InkAnnotation = /*#__PURE__*/ -function (_Annotation9) { - _inherits(InkAnnotation, _Annotation9); +function (_MarkupAnnotation8) { + _inherits(InkAnnotation, _MarkupAnnotation8); function InkAnnotation(parameters) { - var _this14; + var _this17; _classCallCheck(this, InkAnnotation); - _this14 = _possibleConstructorReturn(this, _getPrototypeOf(InkAnnotation).call(this, parameters)); - _this14.data.annotationType = _util.AnnotationType.INK; - var dict = parameters.dict; + _this17 = _possibleConstructorReturn(this, _getPrototypeOf(InkAnnotation).call(this, parameters)); + _this17.data.annotationType = _util.AnnotationType.INK; var xref = parameters.xref; - var originalInkLists = dict.getArray('InkList'); - _this14.data.inkLists = []; + var originalInkLists = parameters.dict.getArray('InkList'); + _this17.data.inkLists = []; for (var i = 0, ii = originalInkLists.length; i < ii; ++i) { - _this14.data.inkLists.push([]); + _this17.data.inkLists.push([]); for (var j = 0, jj = originalInkLists[i].length; j < jj; j += 2) { - _this14.data.inkLists[i].push({ + _this17.data.inkLists[i].push({ x: xref.fetchIfRef(originalInkLists[i][j]), y: xref.fetchIfRef(originalInkLists[i][j + 1]) }); } } - _this14._preparePopup(dict); - - return _this14; + return _this17; } return InkAnnotation; -}(Annotation); +}(MarkupAnnotation); var HighlightAnnotation = /*#__PURE__*/ -function (_Annotation10) { - _inherits(HighlightAnnotation, _Annotation10); +function (_MarkupAnnotation9) { + _inherits(HighlightAnnotation, _MarkupAnnotation9); function HighlightAnnotation(parameters) { - var _this15; + var _this18; _classCallCheck(this, HighlightAnnotation); - _this15 = _possibleConstructorReturn(this, _getPrototypeOf(HighlightAnnotation).call(this, parameters)); - _this15.data.annotationType = _util.AnnotationType.HIGHLIGHT; + _this18 = _possibleConstructorReturn(this, _getPrototypeOf(HighlightAnnotation).call(this, parameters)); + _this18.data.annotationType = _util.AnnotationType.HIGHLIGHT; + var quadPoints = getQuadPoints(parameters.dict, _this18.rectangle); - _this15._preparePopup(parameters.dict); + if (quadPoints) { + _this18.data.quadPoints = quadPoints; + } - return _this15; + return _this18; } return HighlightAnnotation; -}(Annotation); +}(MarkupAnnotation); var UnderlineAnnotation = /*#__PURE__*/ -function (_Annotation11) { - _inherits(UnderlineAnnotation, _Annotation11); +function (_MarkupAnnotation10) { + _inherits(UnderlineAnnotation, _MarkupAnnotation10); function UnderlineAnnotation(parameters) { - var _this16; + var _this19; _classCallCheck(this, UnderlineAnnotation); - _this16 = _possibleConstructorReturn(this, _getPrototypeOf(UnderlineAnnotation).call(this, parameters)); - _this16.data.annotationType = _util.AnnotationType.UNDERLINE; + _this19 = _possibleConstructorReturn(this, _getPrototypeOf(UnderlineAnnotation).call(this, parameters)); + _this19.data.annotationType = _util.AnnotationType.UNDERLINE; + var quadPoints = getQuadPoints(parameters.dict, _this19.rectangle); - _this16._preparePopup(parameters.dict); + if (quadPoints) { + _this19.data.quadPoints = quadPoints; + } - return _this16; + return _this19; } return UnderlineAnnotation; -}(Annotation); +}(MarkupAnnotation); var SquigglyAnnotation = /*#__PURE__*/ -function (_Annotation12) { - _inherits(SquigglyAnnotation, _Annotation12); +function (_MarkupAnnotation11) { + _inherits(SquigglyAnnotation, _MarkupAnnotation11); function SquigglyAnnotation(parameters) { - var _this17; + var _this20; _classCallCheck(this, SquigglyAnnotation); - _this17 = _possibleConstructorReturn(this, _getPrototypeOf(SquigglyAnnotation).call(this, parameters)); - _this17.data.annotationType = _util.AnnotationType.SQUIGGLY; + _this20 = _possibleConstructorReturn(this, _getPrototypeOf(SquigglyAnnotation).call(this, parameters)); + _this20.data.annotationType = _util.AnnotationType.SQUIGGLY; + var quadPoints = getQuadPoints(parameters.dict, _this20.rectangle); - _this17._preparePopup(parameters.dict); + if (quadPoints) { + _this20.data.quadPoints = quadPoints; + } - return _this17; + return _this20; } return SquigglyAnnotation; -}(Annotation); +}(MarkupAnnotation); var StrikeOutAnnotation = /*#__PURE__*/ -function (_Annotation13) { - _inherits(StrikeOutAnnotation, _Annotation13); +function (_MarkupAnnotation12) { + _inherits(StrikeOutAnnotation, _MarkupAnnotation12); function StrikeOutAnnotation(parameters) { - var _this18; + var _this21; _classCallCheck(this, StrikeOutAnnotation); - _this18 = _possibleConstructorReturn(this, _getPrototypeOf(StrikeOutAnnotation).call(this, parameters)); - _this18.data.annotationType = _util.AnnotationType.STRIKEOUT; + _this21 = _possibleConstructorReturn(this, _getPrototypeOf(StrikeOutAnnotation).call(this, parameters)); + _this21.data.annotationType = _util.AnnotationType.STRIKEOUT; + var quadPoints = getQuadPoints(parameters.dict, _this21.rectangle); - _this18._preparePopup(parameters.dict); + if (quadPoints) { + _this21.data.quadPoints = quadPoints; + } - return _this18; + return _this21; } return StrikeOutAnnotation; -}(Annotation); +}(MarkupAnnotation); var StampAnnotation = /*#__PURE__*/ -function (_Annotation14) { - _inherits(StampAnnotation, _Annotation14); +function (_MarkupAnnotation13) { + _inherits(StampAnnotation, _MarkupAnnotation13); function StampAnnotation(parameters) { - var _this19; + var _this22; _classCallCheck(this, StampAnnotation); - _this19 = _possibleConstructorReturn(this, _getPrototypeOf(StampAnnotation).call(this, parameters)); - _this19.data.annotationType = _util.AnnotationType.STAMP; - - _this19._preparePopup(parameters.dict); - - return _this19; + _this22 = _possibleConstructorReturn(this, _getPrototypeOf(StampAnnotation).call(this, parameters)); + _this22.data.annotationType = _util.AnnotationType.STAMP; + return _this22; } return StampAnnotation; -}(Annotation); +}(MarkupAnnotation); var FileAttachmentAnnotation = /*#__PURE__*/ -function (_Annotation15) { - _inherits(FileAttachmentAnnotation, _Annotation15); +function (_MarkupAnnotation14) { + _inherits(FileAttachmentAnnotation, _MarkupAnnotation14); function FileAttachmentAnnotation(parameters) { - var _this20; + var _this23; _classCallCheck(this, FileAttachmentAnnotation); - _this20 = _possibleConstructorReturn(this, _getPrototypeOf(FileAttachmentAnnotation).call(this, parameters)); + _this23 = _possibleConstructorReturn(this, _getPrototypeOf(FileAttachmentAnnotation).call(this, parameters)); var file = new _obj.FileSpec(parameters.dict.get('FS'), parameters.xref); - _this20.data.annotationType = _util.AnnotationType.FILEATTACHMENT; - _this20.data.file = file.serializable; - - _this20._preparePopup(parameters.dict); - - return _this20; + _this23.data.annotationType = _util.AnnotationType.FILEATTACHMENT; + _this23.data.file = file.serializable; + return _this23; } return FileAttachmentAnnotation; -}(Annotation); +}(MarkupAnnotation); /***/ }), -/* 170 */ +/* 203 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -29354,7 +29969,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.OperatorList = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); var QueueOptimizer = function QueueOptimizerClosure() { function addState(parentState, pattern, checkFn, iterateFn, processFn) { @@ -29409,6 +30024,8 @@ var QueueOptimizer = function QueueOptimizerClosure() { case 3: return fnArray[i] === _util.OPS.restore; } + + throw new Error("iterateInlineImageGroup - invalid pos: ".concat(pos)); }, function foundInlineImageGroup(context, i) { var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10; var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200; @@ -29515,6 +30132,8 @@ var QueueOptimizer = function QueueOptimizerClosure() { case 3: return fnArray[i] === _util.OPS.restore; } + + throw new Error("iterateImageMaskGroup - invalid pos: ".concat(pos)); }, function foundImageMaskGroup(context, i) { var MIN_IMAGES_IN_MASKS_BLOCK = 10; var MAX_IMAGES_IN_MASKS_BLOCK = 100; @@ -29597,7 +30216,7 @@ var QueueOptimizer = function QueueOptimizerClosure() { var argsArray = context.argsArray; var iFirstTransform = context.iCurr - 2; return argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0; - }, function (context, i) { + }, function iterateImageGroup(context, i) { var fnArray = context.fnArray, argsArray = context.argsArray; var iFirstSave = context.iCurr - 3; @@ -29639,6 +30258,8 @@ var QueueOptimizer = function QueueOptimizerClosure() { case 3: return fnArray[i] === _util.OPS.restore; } + + throw new Error("iterateImageGroup - invalid pos: ".concat(pos)); }, function (context, i) { var MIN_IMAGES_IN_BLOCK = 3; var MAX_IMAGES_IN_BLOCK = 1000; @@ -29671,7 +30292,7 @@ var QueueOptimizer = function QueueOptimizerClosure() { argsArray.splice(iFirstSave, count * 4, args); return iFirstSave + 1; }); - addState(InitialState, [_util.OPS.beginText, _util.OPS.setFont, _util.OPS.setTextMatrix, _util.OPS.showText, _util.OPS.endText], null, function (context, i) { + addState(InitialState, [_util.OPS.beginText, _util.OPS.setFont, _util.OPS.setTextMatrix, _util.OPS.showText, _util.OPS.endText], null, function iterateShowTextGroup(context, i) { var fnArray = context.fnArray, argsArray = context.argsArray; var iFirstSave = context.iCurr - 4; @@ -29705,6 +30326,8 @@ var QueueOptimizer = function QueueOptimizerClosure() { case 4: return fnArray[i] === _util.OPS.endText; } + + throw new Error("iterateShowTextGroup - invalid pos: ".concat(pos)); }, function (context, i) { var MIN_CHARS_IN_BLOCK = 3; var MAX_CHARS_IN_BLOCK = 1000; @@ -29846,7 +30469,8 @@ var NullOptimizer = function NullOptimizerClosure() { this.queue.fnArray.push(fn); this.queue.argsArray.push(args); }, - flush: function flush() {} + flush: function flush() {}, + reset: function reset() {} }; return NullOptimizer; }(); @@ -29855,36 +30479,12 @@ var OperatorList = function OperatorListClosure() { var CHUNK_SIZE = 1000; var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; - function getTransfers(queue) { - var transfers = []; - var fnArray = queue.fnArray, - argsArray = queue.argsArray; - - for (var i = 0, ii = queue.length; i < ii; i++) { - switch (fnArray[i]) { - case _util.OPS.paintInlineImageXObject: - case _util.OPS.paintInlineImageXObjectGroup: - case _util.OPS.paintImageMaskXObject: - var arg = argsArray[i][0]; - ; - - if (!arg.cached) { - transfers.push(arg.data.buffer); - } - - break; - } - } - - return transfers; - } - - function OperatorList(intent, messageHandler, pageIndex) { - this.messageHandler = messageHandler; + function OperatorList(intent, streamSink, pageIndex) { + this._streamSink = streamSink; this.fnArray = []; this.argsArray = []; - if (messageHandler && this.intent !== 'oplist') { + if (streamSink && intent !== 'oplist') { this.optimizer = new QueueOptimizer(this); } else { this.optimizer = new NullOptimizer(this); @@ -29895,6 +30495,7 @@ var OperatorList = function OperatorListClosure() { this.pageIndex = pageIndex; this.intent = intent; this.weight = 0; + this._resolved = streamSink ? null : Promise.resolve(); } OperatorList.prototype = { @@ -29902,6 +30503,10 @@ var OperatorList = function OperatorListClosure() { return this.argsArray.length; }, + get ready() { + return this._resolved || this._streamSink.ready; + }, + get totalLength() { return this._totalLength + this.length; }, @@ -29910,7 +30515,7 @@ var OperatorList = function OperatorListClosure() { this.optimizer.push(fn, args); this.weight++; - if (this.messageHandler) { + if (this._streamSink) { if (this.weight >= CHUNK_SIZE) { this.flush(); } else if (this.weight >= CHUNK_SIZE_ABOUT && (fn === _util.OPS.restore || fn === _util.OPS.endText)) { @@ -29945,21 +30550,45 @@ var OperatorList = function OperatorListClosure() { length: this.length }; }, - flush: function flush(lastChunk) { + + get _transfers() { + var transfers = []; + var fnArray = this.fnArray, + argsArray = this.argsArray, + length = this.length; + + for (var i = 0; i < length; i++) { + switch (fnArray[i]) { + case _util.OPS.paintInlineImageXObject: + case _util.OPS.paintInlineImageXObjectGroup: + case _util.OPS.paintImageMaskXObject: + var arg = argsArray[i][0]; + ; + + if (!arg.cached) { + transfers.push(arg.data.buffer); + } + + break; + } + } + + return transfers; + }, + + flush: function flush() { + var lastChunk = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; this.optimizer.flush(); - var transfers = getTransfers(this); var length = this.length; this._totalLength += length; - this.messageHandler.send('RenderPageChunk', { - operatorList: { - fnArray: this.fnArray, - argsArray: this.argsArray, - lastChunk: lastChunk, - length: length - }, - pageIndex: this.pageIndex, - intent: this.intent - }, transfers); + + this._streamSink.enqueue({ + fnArray: this.fnArray, + argsArray: this.argsArray, + lastChunk: lastChunk, + length: length + }, 1, this._transfers); + this.dependencies = Object.create(null); this.fnArray.length = 0; this.argsArray.length = 0; @@ -29973,7 +30602,7 @@ var OperatorList = function OperatorListClosure() { exports.OperatorList = OperatorList; /***/ }), -/* 171 */ +/* 204 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -29986,45 +30615,49 @@ exports.PartialEvaluator = void 0; var _regenerator = _interopRequireDefault(__w_pdfjs_require__(2)); -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _cmap = __w_pdfjs_require__(172); +var _cmap = __w_pdfjs_require__(205); -var _stream = __w_pdfjs_require__(157); +var _primitives = __w_pdfjs_require__(183); -var _primitives = __w_pdfjs_require__(155); +var _fonts = __w_pdfjs_require__(206); -var _fonts = __w_pdfjs_require__(173); +var _encodings = __w_pdfjs_require__(209); -var _encodings = __w_pdfjs_require__(176); +var _unicode = __w_pdfjs_require__(212); -var _unicode = __w_pdfjs_require__(179); +var _standard_fonts = __w_pdfjs_require__(211); -var _standard_fonts = __w_pdfjs_require__(178); +var _pattern = __w_pdfjs_require__(215); -var _pattern = __w_pdfjs_require__(182); +var _parser = __w_pdfjs_require__(189); -var _parser = __w_pdfjs_require__(156); +var _bidi = __w_pdfjs_require__(216); -var _bidi = __w_pdfjs_require__(183); +var _colorspace = __w_pdfjs_require__(201); -var _colorspace = __w_pdfjs_require__(168); +var _stream = __w_pdfjs_require__(190); -var _glyphlist = __w_pdfjs_require__(177); +var _glyphlist = __w_pdfjs_require__(210); -var _metrics = __w_pdfjs_require__(184); +var _core_utils = __w_pdfjs_require__(186); -var _function = __w_pdfjs_require__(185); +var _metrics = __w_pdfjs_require__(217); -var _jpeg_stream = __w_pdfjs_require__(163); +var _function = __w_pdfjs_require__(218); -var _murmurhash = __w_pdfjs_require__(187); +var _jpeg_stream = __w_pdfjs_require__(196); -var _operator_list = __w_pdfjs_require__(170); +var _murmurhash = __w_pdfjs_require__(220); -var _image = __w_pdfjs_require__(188); +var _image_utils = __w_pdfjs_require__(221); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +var _operator_list = __w_pdfjs_require__(203); + +var _image = __w_pdfjs_require__(222); + +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); } } @@ -30040,77 +30673,19 @@ var PartialEvaluator = function PartialEvaluatorClosure() { isEvalSupported: true }; - function NativeImageDecoder(_ref) { + function PartialEvaluator(_ref) { + var _this = this; + var xref = _ref.xref, - resources = _ref.resources, handler = _ref.handler, - _ref$forceDataSchema = _ref.forceDataSchema, - forceDataSchema = _ref$forceDataSchema === void 0 ? false : _ref$forceDataSchema, + pageIndex = _ref.pageIndex, + idFactory = _ref.idFactory, + fontCache = _ref.fontCache, + builtInCMapCache = _ref.builtInCMapCache, + _ref$options = _ref.options, + options = _ref$options === void 0 ? null : _ref$options, pdfFunctionFactory = _ref.pdfFunctionFactory; this.xref = xref; - this.resources = resources; - this.handler = handler; - this.forceDataSchema = forceDataSchema; - this.pdfFunctionFactory = pdfFunctionFactory; - } - - NativeImageDecoder.prototype = { - canDecode: function canDecode(image) { - return image instanceof _jpeg_stream.JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources, this.pdfFunctionFactory); - }, - decode: function decode(image) { - var dict = image.dict; - var colorSpace = dict.get('ColorSpace', 'CS'); - colorSpace = _colorspace.ColorSpace.parse(colorSpace, this.xref, this.resources, this.pdfFunctionFactory); - return this.handler.sendWithPromise('JpegDecode', [image.getIR(this.forceDataSchema), colorSpace.numComps]).then(function (_ref2) { - var data = _ref2.data, - width = _ref2.width, - height = _ref2.height; - return new _stream.Stream(data, 0, data.length, image.dict); - }); - } - }; - - NativeImageDecoder.isSupported = function (image, xref, res, pdfFunctionFactory) { - var dict = image.dict; - - if (dict.has('DecodeParms') || dict.has('DP')) { - return false; - } - - var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res, pdfFunctionFactory); - - return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D')); - }; - - NativeImageDecoder.isDecodable = function (image, xref, res, pdfFunctionFactory) { - var dict = image.dict; - - if (dict.has('DecodeParms') || dict.has('DP')) { - return false; - } - - var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res, pdfFunctionFactory); - - var bpc = dict.get('BitsPerComponent', 'BPC') || 1; - return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'), bpc); - }; - - function PartialEvaluator(_ref3) { - var _this = this; - - var pdfManager = _ref3.pdfManager, - xref = _ref3.xref, - handler = _ref3.handler, - pageIndex = _ref3.pageIndex, - idFactory = _ref3.idFactory, - fontCache = _ref3.fontCache, - builtInCMapCache = _ref3.builtInCMapCache, - _ref3$options = _ref3.options, - options = _ref3$options === void 0 ? null : _ref3$options, - pdfFunctionFactory = _ref3.pdfFunctionFactory; - this.pdfManager = pdfManager; - this.xref = xref; this.handler = handler; this.pageIndex = pageIndex; this.idFactory = idFactory; @@ -30118,15 +30693,16 @@ var PartialEvaluator = function PartialEvaluatorClosure() { this.builtInCMapCache = builtInCMapCache; this.options = options || DefaultPartialEvaluatorOptions; this.pdfFunctionFactory = pdfFunctionFactory; + this.parsingType3Font = false; this.fetchBuiltInCMap = /*#__PURE__*/ function () { - var _ref4 = _asyncToGenerator( + var _ref2 = _asyncToGenerator( /*#__PURE__*/ - _regenerator.default.mark(function _callee(name) { - var data; - return _regenerator.default.wrap(function _callee$(_context) { + _regenerator["default"].mark(function _callee(name) { + var readableStream, reader, data; + return _regenerator["default"].wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: @@ -30138,12 +30714,30 @@ var PartialEvaluator = function PartialEvaluatorClosure() { return _context.abrupt("return", _this.builtInCMapCache.get(name)); case 2: - _context.next = 4; - return _this.handler.sendWithPromise('FetchBuiltInCMap', { + readableStream = _this.handler.sendWithStream('FetchBuiltInCMap', { name: name }); + reader = readableStream.getReader(); + _context.next = 6; + return new Promise(function (resolve, reject) { + function pump() { + reader.read().then(function (_ref3) { + var value = _ref3.value, + done = _ref3.done; + + if (done) { + return; + } + + resolve(value); + pump(); + }, reject); + } - case 4: + pump(); + }); + + case 6: data = _context.sent; if (data.compressionType !== _util.CMapCompressionType.NONE) { @@ -30152,16 +30746,16 @@ var PartialEvaluator = function PartialEvaluatorClosure() { return _context.abrupt("return", data); - case 7: + case 9: case "end": return _context.stop(); } } - }, _callee, this); + }, _callee); })); return function (_x) { - return _ref4.apply(this, arguments); + return _ref2.apply(this, arguments); }; }(); } @@ -30366,7 +30960,13 @@ var PartialEvaluator = function PartialEvaluatorClosure() { groupOptions.knockout = group.get('K') || false; if (group.has('CS')) { - colorSpace = _colorspace.ColorSpace.parse(group.get('CS'), this.xref, resources, this.pdfFunctionFactory); + colorSpace = group.get('CS'); + + if (colorSpace) { + colorSpace = _colorspace.ColorSpace.parse(colorSpace, this.xref, resources, this.pdfFunctionFactory); + } else { + (0, _util.warn)('buildFormXObject - invalid/non-existent Group /CS entry: ' + group.getRaw('CS')); + } } } @@ -30393,154 +30993,213 @@ var PartialEvaluator = function PartialEvaluatorClosure() { } }); }, - buildPaintImageXObject: function buildPaintImageXObject(_ref5) { - var _this2 = this; + buildPaintImageXObject: function () { + var _buildPaintImageXObject = _asyncToGenerator( + /*#__PURE__*/ + _regenerator["default"].mark(function _callee2(_ref4) { + var _this2 = this; - var resources = _ref5.resources, - image = _ref5.image, - _ref5$isInline = _ref5.isInline, - isInline = _ref5$isInline === void 0 ? false : _ref5$isInline, - operatorList = _ref5.operatorList, - cacheKey = _ref5.cacheKey, - imageCache = _ref5.imageCache, - _ref5$forceDisableNat = _ref5.forceDisableNativeImageDecoder, - forceDisableNativeImageDecoder = _ref5$forceDisableNat === void 0 ? false : _ref5$forceDisableNat; - var dict = image.dict; - var w = dict.get('Width', 'W'); - var h = dict.get('Height', 'H'); + var resources, image, _ref4$isInline, isInline, operatorList, cacheKey, imageCache, _ref4$forceDisableNat, forceDisableNativeImageDecoder, dict, w, h, maxImageSize, imageMask, imgData, args, width, height, bitStrideLength, imgArray, decode, softMask, mask, SMALL_IMAGE_DIMENSIONS, imageObj, nativeImageDecoderSupport, objId, nativeImageDecoder, imgPromise; - if (!(w && (0, _util.isNum)(w)) || !(h && (0, _util.isNum)(h))) { - (0, _util.warn)('Image dimensions are missing, or not numbers.'); - return Promise.resolve(); - } + return _regenerator["default"].wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + resources = _ref4.resources, image = _ref4.image, _ref4$isInline = _ref4.isInline, isInline = _ref4$isInline === void 0 ? false : _ref4$isInline, operatorList = _ref4.operatorList, cacheKey = _ref4.cacheKey, imageCache = _ref4.imageCache, _ref4$forceDisableNat = _ref4.forceDisableNativeImageDecoder, forceDisableNativeImageDecoder = _ref4$forceDisableNat === void 0 ? false : _ref4$forceDisableNat; + dict = image.dict; + w = dict.get('Width', 'W'); + h = dict.get('Height', 'H'); - var maxImageSize = this.options.maxImageSize; + if (!(!(w && (0, _util.isNum)(w)) || !(h && (0, _util.isNum)(h)))) { + _context2.next = 7; + break; + } - if (maxImageSize !== -1 && w * h > maxImageSize) { - (0, _util.warn)('Image exceeded maximum allowed size and was removed.'); - return Promise.resolve(); - } + (0, _util.warn)('Image dimensions are missing, or not numbers.'); + return _context2.abrupt("return", undefined); - var imageMask = dict.get('ImageMask', 'IM') || false; - var imgData, args; + case 7: + maxImageSize = this.options.maxImageSize; - if (imageMask) { - var width = dict.get('Width', 'W'); - var height = dict.get('Height', 'H'); - var bitStrideLength = width + 7 >> 3; - var imgArray = image.getBytes(bitStrideLength * height, true); - var decode = dict.getArray('Decode', 'D'); - imgData = _image.PDFImage.createMask({ - imgArray: imgArray, - width: width, - height: height, - imageIsFromDecodeStream: image instanceof _stream.DecodeStream, - inverseDecode: !!decode && decode[0] > 0 - }); - imgData.cached = true; - args = [imgData]; - operatorList.addOp(_util.OPS.paintImageMaskXObject, args); - - if (cacheKey) { - imageCache[cacheKey] = { - fn: _util.OPS.paintImageMaskXObject, - args: args - }; - } + if (!(maxImageSize !== -1 && w * h > maxImageSize)) { + _context2.next = 11; + break; + } - return Promise.resolve(); - } + (0, _util.warn)('Image exceeded maximum allowed size and was removed.'); + return _context2.abrupt("return", undefined); - var softMask = dict.get('SMask', 'SM') || false; - var mask = dict.get('Mask') || false; - var SMALL_IMAGE_DIMENSIONS = 200; + case 11: + imageMask = dict.get('ImageMask', 'IM') || false; - if (isInline && !softMask && !mask && !(image instanceof _jpeg_stream.JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS) { - var imageObj = new _image.PDFImage({ - xref: this.xref, - res: resources, - image: image, - isInline: isInline, - pdfFunctionFactory: this.pdfFunctionFactory - }); - imgData = imageObj.createImageData(true); - operatorList.addOp(_util.OPS.paintInlineImageXObject, [imgData]); - return Promise.resolve(); - } + if (!imageMask) { + _context2.next = 24; + break; + } - var nativeImageDecoderSupport = forceDisableNativeImageDecoder ? _util.NativeImageDecoding.NONE : this.options.nativeImageDecoderSupport; - var objId = 'img_' + this.idFactory.createObjId(); + width = dict.get('Width', 'W'); + height = dict.get('Height', 'H'); + bitStrideLength = width + 7 >> 3; + imgArray = image.getBytes(bitStrideLength * height, true); + decode = dict.getArray('Decode', 'D'); + imgData = _image.PDFImage.createMask({ + imgArray: imgArray, + width: width, + height: height, + imageIsFromDecodeStream: image instanceof _stream.DecodeStream, + inverseDecode: !!decode && decode[0] > 0 + }); + imgData.cached = !!cacheKey; + args = [imgData]; + operatorList.addOp(_util.OPS.paintImageMaskXObject, args); + + if (cacheKey) { + imageCache[cacheKey] = { + fn: _util.OPS.paintImageMaskXObject, + args: args + }; + } - if (nativeImageDecoderSupport !== _util.NativeImageDecoding.NONE && !softMask && !mask && image instanceof _jpeg_stream.JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources, this.pdfFunctionFactory)) { - return this.handler.sendWithPromise('obj', [objId, this.pageIndex, 'JpegStream', image.getIR(this.options.forceDataSchema)]).then(function () { - operatorList.addDependency(objId); - args = [objId, w, h]; - operatorList.addOp(_util.OPS.paintJpegXObject, args); + return _context2.abrupt("return", undefined); - if (cacheKey) { - imageCache[cacheKey] = { - fn: _util.OPS.paintJpegXObject, - args: args - }; - } - }, function (reason) { - (0, _util.warn)('Native JPEG decoding failed -- trying to recover: ' + (reason && reason.message)); - return _this2.buildPaintImageXObject({ - resources: resources, - image: image, - isInline: isInline, - operatorList: operatorList, - cacheKey: cacheKey, - imageCache: imageCache, - forceDisableNativeImageDecoder: true - }); - }); - } + case 24: + softMask = dict.get('SMask', 'SM') || false; + mask = dict.get('Mask') || false; + SMALL_IMAGE_DIMENSIONS = 200; - var nativeImageDecoder = null; + if (!(isInline && !softMask && !mask && !(image instanceof _jpeg_stream.JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS)) { + _context2.next = 32; + break; + } - if (nativeImageDecoderSupport === _util.NativeImageDecoding.DECODE && (image instanceof _jpeg_stream.JpegStream || mask instanceof _jpeg_stream.JpegStream || softMask instanceof _jpeg_stream.JpegStream)) { - nativeImageDecoder = new NativeImageDecoder({ - xref: this.xref, - resources: resources, - handler: this.handler, - forceDataSchema: this.options.forceDataSchema, - pdfFunctionFactory: this.pdfFunctionFactory - }); - } + imageObj = new _image.PDFImage({ + xref: this.xref, + res: resources, + image: image, + isInline: isInline, + pdfFunctionFactory: this.pdfFunctionFactory + }); + imgData = imageObj.createImageData(true); + operatorList.addOp(_util.OPS.paintInlineImageXObject, [imgData]); + return _context2.abrupt("return", undefined); - operatorList.addDependency(objId); - args = [objId, w, h]; + case 32: + nativeImageDecoderSupport = forceDisableNativeImageDecoder ? _util.NativeImageDecoding.NONE : this.options.nativeImageDecoderSupport; + objId = "img_".concat(this.idFactory.createObjId()); - _image.PDFImage.buildImage({ - handler: this.handler, - xref: this.xref, - res: resources, - image: image, - isInline: isInline, - nativeDecoder: nativeImageDecoder, - pdfFunctionFactory: this.pdfFunctionFactory - }).then(function (imageObj) { - var imgData = imageObj.createImageData(false); + if (this.parsingType3Font) { + (0, _util.assert)(nativeImageDecoderSupport === _util.NativeImageDecoding.NONE, 'Type3 image resources should be completely decoded in the worker.'); + objId = "".concat(this.idFactory.getDocId(), "_type3res_").concat(objId); + } - _this2.handler.send('obj', [objId, _this2.pageIndex, 'Image', imgData], [imgData.data.buffer]); - }).catch(function (reason) { - (0, _util.warn)('Unable to decode image: ' + reason); + if (!(nativeImageDecoderSupport !== _util.NativeImageDecoding.NONE && !softMask && !mask && image instanceof _jpeg_stream.JpegStream && _image_utils.NativeImageDecoder.isSupported(image, this.xref, resources, this.pdfFunctionFactory))) { + _context2.next = 37; + break; + } - _this2.handler.send('obj', [objId, _this2.pageIndex, 'Image', null]); - }); + return _context2.abrupt("return", this.handler.sendWithPromise('obj', [objId, this.pageIndex, 'JpegStream', image.getIR(this.options.forceDataSchema)]).then(function () { + operatorList.addDependency(objId); + args = [objId, w, h]; + operatorList.addOp(_util.OPS.paintJpegXObject, args); - operatorList.addOp(_util.OPS.paintImageXObject, args); + if (cacheKey) { + imageCache[cacheKey] = { + fn: _util.OPS.paintJpegXObject, + args: args + }; + } + }, function (reason) { + (0, _util.warn)('Native JPEG decoding failed -- trying to recover: ' + (reason && reason.message)); + return _this2.buildPaintImageXObject({ + resources: resources, + image: image, + isInline: isInline, + operatorList: operatorList, + cacheKey: cacheKey, + imageCache: imageCache, + forceDisableNativeImageDecoder: true + }); + })); - if (cacheKey) { - imageCache[cacheKey] = { - fn: _util.OPS.paintImageXObject, - args: args - }; + case 37: + nativeImageDecoder = null; + + if (nativeImageDecoderSupport === _util.NativeImageDecoding.DECODE && (image instanceof _jpeg_stream.JpegStream || mask instanceof _jpeg_stream.JpegStream || softMask instanceof _jpeg_stream.JpegStream)) { + nativeImageDecoder = new _image_utils.NativeImageDecoder({ + xref: this.xref, + resources: resources, + handler: this.handler, + forceDataSchema: this.options.forceDataSchema, + pdfFunctionFactory: this.pdfFunctionFactory + }); + } + + operatorList.addDependency(objId); + args = [objId, w, h]; + imgPromise = _image.PDFImage.buildImage({ + handler: this.handler, + xref: this.xref, + res: resources, + image: image, + isInline: isInline, + nativeDecoder: nativeImageDecoder, + pdfFunctionFactory: this.pdfFunctionFactory + }).then(function (imageObj) { + var imgData = imageObj.createImageData(false); + + if (_this2.parsingType3Font) { + return _this2.handler.sendWithPromise('commonobj', [objId, 'FontType3Res', imgData], [imgData.data.buffer]); + } + + _this2.handler.send('obj', [objId, _this2.pageIndex, 'Image', imgData], [imgData.data.buffer]); + + return undefined; + })["catch"](function (reason) { + (0, _util.warn)('Unable to decode image: ' + reason); + + if (_this2.parsingType3Font) { + return _this2.handler.sendWithPromise('commonobj', [objId, 'FontType3Res', null]); + } + + _this2.handler.send('obj', [objId, _this2.pageIndex, 'Image', null]); + + return undefined; + }); + + if (!this.parsingType3Font) { + _context2.next = 45; + break; + } + + _context2.next = 45; + return imgPromise; + + case 45: + operatorList.addOp(_util.OPS.paintImageXObject, args); + + if (cacheKey) { + imageCache[cacheKey] = { + fn: _util.OPS.paintImageXObject, + args: args + }; + } + + return _context2.abrupt("return", undefined); + + case 48: + case "end": + return _context2.stop(); + } + } + }, _callee2, this); + })); + + function buildPaintImageXObject(_x2) { + return _buildPaintImageXObject.apply(this, arguments); } - return Promise.resolve(); - }, + return buildPaintImageXObject; + }(), handleSMask: function PartialEvaluator_handleSmask(smask, resources, operatorList, task, stateManager) { var smaskContent = smask.get('G'); var smaskOptions = { @@ -30587,6 +31246,10 @@ var PartialEvaluator = function PartialEvaluatorClosure() { operatorList.addDependencies(tilingOpList.dependencies); operatorList.addOp(fn, tilingPatternIR); }, function (reason) { + if (reason instanceof _util.AbortException) { + return; + } + if (_this3.options.ignoreErrors) { _this3.handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.unknown @@ -30616,7 +31279,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() { return translated.loadType3Data(_this4, resources, operatorList, task).then(function () { return translated; - }).catch(function (reason) { + })["catch"](function (reason) { _this4.handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.font }); @@ -30781,7 +31444,8 @@ var PartialEvaluator = function PartialEvaluatorClosure() { var fontCapability = (0, _util.createPromiseCapability)(); var preEvaluatedFont = this.preEvaluateFont(font); - var descriptor = preEvaluatedFont.descriptor; + var descriptor = preEvaluatedFont.descriptor, + hash = preEvaluatedFont.hash; var fontRefIsRef = (0, _primitives.isRef)(fontRef), fontID; @@ -30789,13 +31453,12 @@ var PartialEvaluator = function PartialEvaluatorClosure() { fontID = fontRef.toString(); } - if ((0, _primitives.isDict)(descriptor)) { + if (hash && (0, _primitives.isDict)(descriptor)) { if (!descriptor.fontAliases) { descriptor.fontAliases = Object.create(null); } var fontAliases = descriptor.fontAliases; - var hash = preEvaluatedFont.hash; if (fontAliases[hash]) { var aliasFontRef = fontAliases[hash].aliasRef; @@ -30824,11 +31487,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() { fontID = this.idFactory.createObjId(); } - this.fontCache.put('id_' + fontID, fontCapability.promise); + this.fontCache.put("id_".concat(fontID), fontCapability.promise); } (0, _util.assert)(fontID, 'The "fontID" must be defined.'); - font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID; + font.loadedName = "".concat(this.idFactory.getDocId(), "_f").concat(fontID); font.translated = fontCapability.promise; var translatedPromise; @@ -30845,13 +31508,12 @@ var PartialEvaluator = function PartialEvaluatorClosure() { } fontCapability.resolve(new TranslatedFont(font.loadedName, translatedFont, font)); - }).catch(function (reason) { + })["catch"](function (reason) { _this6.handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.font }); try { - var descriptor = preEvaluatedFont.descriptor; var fontFile3 = descriptor && descriptor.get('FontFile3'); var subtype = fontFile3 && fontFile3.get('Subtype'); var fontType = (0, _fonts.getFontType)(preEvaluatedFont.type, subtype && subtype.name); @@ -30863,7 +31525,8 @@ var PartialEvaluator = function PartialEvaluatorClosure() { }); return fontCapability.promise; }, - buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) { + buildPath: function buildPath(operatorList, fn, args) { + var parsingText = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; var lastIndex = operatorList.length - 1; if (!args) { @@ -30871,47 +31534,90 @@ var PartialEvaluator = function PartialEvaluatorClosure() { } if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== _util.OPS.constructPath) { + if (parsingText) { + (0, _util.warn)("Encountered path operator \"".concat(fn, "\" inside of a text object.")); + operatorList.addOp(_util.OPS.save, null); + } + operatorList.addOp(_util.OPS.constructPath, [[fn], args]); + + if (parsingText) { + operatorList.addOp(_util.OPS.restore, null); + } } else { var opArgs = operatorList.argsArray[lastIndex]; opArgs[0].push(fn); Array.prototype.push.apply(opArgs[1], args); } }, - handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args, cs, patterns, resources, task) { - var patternName = args[args.length - 1]; - var pattern; + handleColorN: function () { + var _handleColorN = _asyncToGenerator( + /*#__PURE__*/ + _regenerator["default"].mark(function _callee3(operatorList, fn, args, cs, patterns, resources, task) { + var patternName, pattern, dict, typeNum, color, shading, matrix; + return _regenerator["default"].wrap(function _callee3$(_context3) { + while (1) { + switch (_context3.prev = _context3.next) { + case 0: + patternName = args[args.length - 1]; - if ((0, _primitives.isName)(patternName) && (pattern = patterns.get(patternName.name))) { - var dict = (0, _primitives.isStream)(pattern) ? pattern.dict : pattern; - var typeNum = dict.get('PatternType'); + if (!((0, _primitives.isName)(patternName) && (pattern = patterns.get(patternName.name)))) { + _context3.next = 16; + break; + } - if (typeNum === TILING_PATTERN) { - var color = cs.base ? cs.base.getRgb(args, 0) : null; - return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task); - } else if (typeNum === SHADING_PATTERN) { - var shading = dict.get('Shading'); - var matrix = dict.getArray('Matrix'); - pattern = _pattern.Pattern.parseShading(shading, matrix, this.xref, resources, this.handler, this.pdfFunctionFactory); - operatorList.addOp(fn, pattern.getIR()); - return Promise.resolve(); - } + dict = (0, _primitives.isStream)(pattern) ? pattern.dict : pattern; + typeNum = dict.get('PatternType'); + + if (!(typeNum === TILING_PATTERN)) { + _context3.next = 9; + break; + } + + color = cs.base ? cs.base.getRgb(args, 0) : null; + return _context3.abrupt("return", this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task)); + + case 9: + if (!(typeNum === SHADING_PATTERN)) { + _context3.next = 15; + break; + } + + shading = dict.get('Shading'); + matrix = dict.getArray('Matrix'); + pattern = _pattern.Pattern.parseShading(shading, matrix, this.xref, resources, this.handler, this.pdfFunctionFactory); + operatorList.addOp(fn, pattern.getIR()); + return _context3.abrupt("return", undefined); - return Promise.reject(new Error('Unknown PatternType: ' + typeNum)); + case 15: + throw new _util.FormatError("Unknown PatternType: ".concat(typeNum)); + + case 16: + throw new _util.FormatError("Unknown PatternName: ".concat(patternName)); + + case 17: + case "end": + return _context3.stop(); + } + } + }, _callee3, this); + })); + + function handleColorN(_x3, _x4, _x5, _x6, _x7, _x8, _x9) { + return _handleColorN.apply(this, arguments); } - operatorList.addOp(fn, args); - return Promise.resolve(); - }, - getOperatorList: function getOperatorList(_ref6) { + return handleColorN; + }(), + getOperatorList: function getOperatorList(_ref5) { var _this7 = this; - var stream = _ref6.stream, - task = _ref6.task, - resources = _ref6.resources, - operatorList = _ref6.operatorList, - _ref6$initialState = _ref6.initialState, - initialState = _ref6$initialState === void 0 ? null : _ref6$initialState; + var stream = _ref5.stream, + task = _ref5.task, + resources = _ref5.resources, + operatorList = _ref5.operatorList, + _ref5$initialState = _ref5.initialState, + initialState = _ref5$initialState === void 0 ? null : _ref5$initialState; resources = resources || _primitives.Dict.empty; initialState = initialState || new EvalState(); @@ -30921,6 +31627,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() { var self = this; var xref = this.xref; + var parsingText = false; var imageCache = Object.create(null); var xobjs = resources.get('XObject') || _primitives.Dict.empty; @@ -30939,7 +31646,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() { return new Promise(function promiseBody(resolve, reject) { var next = function next(promise) { - promise.then(function () { + Promise.all([promise, operatorList.ready]).then(function () { try { promiseBody(resolve, reject); } catch (ex) { @@ -31022,7 +31729,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() { } resolveXObject(); - }).catch(function (reason) { + })["catch"](function (reason) { + if (reason instanceof _util.AbortException) { + return; + } + if (self.options.ignoreErrors) { self.handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.unknown @@ -31043,6 +31754,14 @@ var PartialEvaluator = function PartialEvaluatorClosure() { })); return; + case _util.OPS.beginText: + parsingText = true; + break; + + case _util.OPS.endText: + parsingText = false; + break; + case _util.OPS.endInlineImage: var cacheKey = args[0].cacheKey; @@ -31224,11 +31943,8 @@ var PartialEvaluator = function PartialEvaluatorClosure() { case _util.OPS.curveTo2: case _util.OPS.curveTo3: case _util.OPS.closePath: - self.buildPath(operatorList, fn, args); - continue; - case _util.OPS.rectangle: - self.buildPath(operatorList, fn, args); + self.buildPath(operatorList, fn, args, parsingText); continue; case _util.OPS.markPoint: @@ -31266,7 +31982,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() { closePendingRestoreOPS(); resolve(); - }).catch(function (reason) { + })["catch"](function (reason) { + if (reason instanceof _util.AbortException) { + return; + } + if (_this7.options.ignoreErrors) { _this7.handler.send('UnsupportedFeature', { featureId: _util.UNSUPPORTED_FEATURES.unknown @@ -31280,21 +32000,21 @@ var PartialEvaluator = function PartialEvaluatorClosure() { throw reason; }); }, - getTextContent: function getTextContent(_ref7) { + getTextContent: function getTextContent(_ref6) { var _this8 = this; - var stream = _ref7.stream, - task = _ref7.task, - resources = _ref7.resources, - _ref7$stateManager = _ref7.stateManager, - stateManager = _ref7$stateManager === void 0 ? null : _ref7$stateManager, - _ref7$normalizeWhites = _ref7.normalizeWhitespace, - normalizeWhitespace = _ref7$normalizeWhites === void 0 ? false : _ref7$normalizeWhites, - _ref7$combineTextItem = _ref7.combineTextItems, - combineTextItems = _ref7$combineTextItem === void 0 ? false : _ref7$combineTextItem, - sink = _ref7.sink, - _ref7$seenStyles = _ref7.seenStyles, - seenStyles = _ref7$seenStyles === void 0 ? Object.create(null) : _ref7$seenStyles; + var stream = _ref6.stream, + task = _ref6.task, + resources = _ref6.resources, + _ref6$stateManager = _ref6.stateManager, + stateManager = _ref6$stateManager === void 0 ? null : _ref6$stateManager, + _ref6$normalizeWhites = _ref6.normalizeWhitespace, + normalizeWhitespace = _ref6$normalizeWhites === void 0 ? false : _ref6$normalizeWhites, + _ref6$combineTextItem = _ref6.combineTextItems, + combineTextItems = _ref6$combineTextItem === void 0 ? false : _ref6$combineTextItem, + sink = _ref6.sink, + _ref6$seenStyles = _ref6.seenStyles, + seenStyles = _ref6$seenStyles === void 0 ? Object.create(null) : _ref6$seenStyles; resources = resources || _primitives.Dict.empty; stateManager = stateManager || new StateManager(new TextState()); var WhitespaceRegexp = /\s/g; @@ -31349,12 +32069,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() { textContentItem.fontName = font.loadedName; var tsm = [textState.fontSize * textState.textHScale, 0, 0, textState.fontSize, 0, textState.textRise]; - if (font.isType3Font && textState.fontMatrix !== _util.FONT_IDENTITY_MATRIX && textState.fontSize === 1) { + if (font.isType3Font && textState.fontSize <= 1 && !(0, _util.isArrayEqual)(textState.fontMatrix, _util.FONT_IDENTITY_MATRIX)) { var glyphHeight = font.bbox[3] - font.bbox[1]; if (glyphHeight > 0) { - glyphHeight = glyphHeight * textState.fontMatrix[3]; - tsm[3] *= glyphHeight; + tsm[3] *= glyphHeight * textState.fontMatrix[3]; } } @@ -31804,7 +32523,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() { resolveXObject(); }, rejectXObject); - }).catch(function (reason) { + })["catch"](function (reason) { if (reason instanceof _util.AbortException) { return; } @@ -31859,7 +32578,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() { flushTextContentItem(); enqueueChunk(); resolve(); - }).catch(function (reason) { + })["catch"](function (reason) { if (reason instanceof _util.AbortException) { return; } @@ -31877,7 +32596,8 @@ var PartialEvaluator = function PartialEvaluatorClosure() { extractDataStructures: function PartialEvaluator_extractDataStructures(dict, baseDict, properties) { var _this9 = this; - var xref = this.xref; + var xref = this.xref, + cidToGidBytes; var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode'); var toUnicodePromise = toUnicode ? this.readToUnicode(toUnicode) : Promise.resolve(undefined); @@ -31895,7 +32615,7 @@ var PartialEvaluator = function PartialEvaluatorClosure() { var cidToGidMap = dict.get('CIDToGIDMap'); if ((0, _primitives.isStream)(cidToGidMap)) { - properties.cidToGidMap = this.readCidToGidMap(cidToGidMap); + cidToGidBytes = cidToGidMap.getBytes(); } } @@ -31972,6 +32692,11 @@ var PartialEvaluator = function PartialEvaluatorClosure() { return _this9.buildToUnicode(properties); }).then(function (toUnicode) { properties.toUnicode = toUnicode; + + if (cidToGidBytes) { + properties.cidToGidMap = _this9.readCidToGidMap(cidToGidBytes, toUnicode); + } + return properties; }); }, @@ -32152,18 +32877,17 @@ var PartialEvaluator = function PartialEvaluatorClosure() { return Promise.resolve(null); }, - readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) { - var glyphsData = cidToGidStream.getBytes(); + readCidToGidMap: function readCidToGidMap(glyphsData, toUnicode) { var result = []; for (var j = 0, jj = glyphsData.length; j < jj; j++) { var glyphID = glyphsData[j++] << 8 | glyphsData[j]; + var code = j >> 1; - if (glyphID === 0) { + if (glyphID === 0 && !toUnicode.has(code)) { continue; } - var code = j >> 1; result[code] = glyphID; } @@ -32398,6 +33122,9 @@ var PartialEvaluator = function PartialEvaluatorClosure() { } } + var firstChar = dict.get('FirstChar') || 0; + var lastChar = dict.get('LastChar') || (composite ? 0xFFFF : 0xFF); + hash.update("".concat(firstChar, "-").concat(lastChar)); var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode'); if ((0, _primitives.isStream)(toUnicode)) { @@ -32603,8 +33330,8 @@ var PartialEvaluator = function PartialEvaluatorClosure() { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator.return != null) { - _iterator.return(); + if (!_iteratorNormalCompletion && _iterator["return"] != null) { + _iterator["return"](); } } finally { if (_didIteratorError) { @@ -32657,7 +33384,9 @@ var TranslatedFont = function TranslatedFontClosure() { var type3Options = Object.create(evaluator.options); type3Options.ignoreErrors = false; + type3Options.nativeImageDecoderSupport = _util.NativeImageDecoding.NONE; var type3Evaluator = evaluator.clone(type3Options); + type3Evaluator.parsingType3Font = true; var translatedFont = this.font; var loadCharProcsPromise = Promise.resolve(); var charProcs = this.dict.get('CharProcs'); @@ -32678,7 +33407,7 @@ var TranslatedFont = function TranslatedFontClosure() { }).then(function () { charProcOperatorList[key] = operatorList.getIR(); parentOperatorList.addDependencies(operatorList.dependencies); - }).catch(function (reason) { + })["catch"](function (reason) { (0, _util.warn)("Type3 font resource \"".concat(key, "\" is not available.")); var operatorList = new _operator_list.OperatorList(); charProcOperatorList[key] = operatorList.getIR(); @@ -32845,7 +33574,7 @@ var EvalState = function EvalStateClosure() { }(); var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() { - var getOPMap = (0, _util.getLookupTableFactory)(function (t) { + var getOPMap = (0, _core_utils.getLookupTableFactory)(function (t) { t['w'] = { id: _util.OPS.setLineWidth, numArgs: 1, @@ -33226,7 +33955,10 @@ var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() { function EvaluatorPreprocessor(stream, xref, stateManager) { this.opMap = getOPMap(); - this.parser = new _parser.Parser(new _parser.Lexer(stream, this.opMap), false, xref); + this.parser = new _parser.Parser({ + lexer: new _parser.Lexer(stream, this.opMap), + xref: xref + }); this.stateManager = stateManager; this.nonProcessedArgs = []; this._numInvalidPathOPS = 0; @@ -33243,7 +33975,7 @@ var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() { while (true) { var obj = this.parser.getObj(); - if ((0, _primitives.isCmd)(obj)) { + if (obj instanceof _primitives.Cmd) { var cmd = obj.cmd; var opSpec = this.opMap[cmd]; @@ -33300,7 +34032,7 @@ var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() { return true; } - if ((0, _primitives.isEOF)(obj)) { + if (obj === _primitives.EOF) { return false; } @@ -33337,7 +34069,7 @@ var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() { }(); /***/ }), -/* 172 */ +/* 205 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -33348,13 +34080,15 @@ Object.defineProperty(exports, "__esModule", { }); exports.CMapFactory = exports.IdentityCMap = exports.CMap = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); + +var _primitives = __w_pdfjs_require__(183); -var _primitives = __w_pdfjs_require__(155); +var _parser = __w_pdfjs_require__(189); -var _parser = __w_pdfjs_require__(156); +var _core_utils = __w_pdfjs_require__(186); -var _stream = __w_pdfjs_require__(157); +var _stream = __w_pdfjs_require__(190); function _typeof(obj) { 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); } @@ -33774,7 +34508,9 @@ var BinaryCMapReader = function BinaryCMapReaderClosure() { var useCMap = null; var start = new Uint8Array(MAX_NUM_SIZE); var end = new Uint8Array(MAX_NUM_SIZE); - var char = new Uint8Array(MAX_NUM_SIZE); + + var _char = new Uint8Array(MAX_NUM_SIZE); + var charCode = new Uint8Array(MAX_NUM_SIZE); var tmp = new Uint8Array(MAX_NUM_SIZE); var code; @@ -33844,20 +34580,20 @@ var BinaryCMapReader = function BinaryCMapReaderClosure() { break; case 2: - stream.readHex(char, dataSize); + stream.readHex(_char, dataSize); code = stream.readNumber(); - cMap.mapOne(hexToInt(char, dataSize), code); + cMap.mapOne(hexToInt(_char, dataSize), code); for (i = 1; i < subitemsCount; i++) { - incHex(char, dataSize); + incHex(_char, dataSize); if (!sequence) { stream.readHexNumber(tmp, dataSize); - addHex(char, tmp, dataSize); + addHex(_char, tmp, dataSize); } code = stream.readSigned() + (code + 1); - cMap.mapOne(hexToInt(char, dataSize), code); + cMap.mapOne(hexToInt(_char, dataSize), code); } break; @@ -33888,22 +34624,22 @@ var BinaryCMapReader = function BinaryCMapReaderClosure() { break; case 4: - stream.readHex(char, ucs2DataSize); + stream.readHex(_char, ucs2DataSize); stream.readHex(charCode, dataSize); - cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize)); + cMap.mapOne(hexToInt(_char, ucs2DataSize), hexToStr(charCode, dataSize)); for (i = 1; i < subitemsCount; i++) { - incHex(char, ucs2DataSize); + incHex(_char, ucs2DataSize); if (!sequence) { stream.readHexNumber(tmp, ucs2DataSize); - addHex(char, tmp, ucs2DataSize); + addHex(_char, tmp, ucs2DataSize); } incHex(charCode, dataSize); stream.readHexSigned(tmp, dataSize); addHex(charCode, tmp, dataSize); - cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize)); + cMap.mapOne(hexToInt(_char, ucs2DataSize), hexToStr(charCode, dataSize)); } break; @@ -34183,7 +34919,7 @@ var CMapFactory = function CMapFactoryClosure() { } } } catch (ex) { - if (ex instanceof _util.MissingDataException) { + if (ex instanceof _core_utils.MissingDataException) { throw ex; } @@ -34289,7 +35025,7 @@ var CMapFactory = function CMapFactoryClosure() { exports.CMapFactory = CMapFactory; /***/ }), -/* 173 */ +/* 206 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -34301,31 +35037,33 @@ Object.defineProperty(exports, "__esModule", { exports.getFontType = getFontType; exports.IdentityToUnicodeMap = exports.ToUnicodeMap = exports.FontFlags = exports.Font = exports.ErrorFont = exports.SEAC_ANALYSIS_ENABLED = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _cff_parser = __w_pdfjs_require__(174); +var _cff_parser = __w_pdfjs_require__(207); -var _glyphlist = __w_pdfjs_require__(177); +var _glyphlist = __w_pdfjs_require__(210); -var _encodings = __w_pdfjs_require__(176); +var _encodings = __w_pdfjs_require__(209); -var _standard_fonts = __w_pdfjs_require__(178); +var _standard_fonts = __w_pdfjs_require__(211); -var _unicode = __w_pdfjs_require__(179); +var _unicode = __w_pdfjs_require__(212); -var _font_renderer = __w_pdfjs_require__(180); +var _font_renderer = __w_pdfjs_require__(213); -var _cmap = __w_pdfjs_require__(172); +var _cmap = __w_pdfjs_require__(205); -var _stream = __w_pdfjs_require__(157); +var _core_utils = __w_pdfjs_require__(186); -var _type1_parser = __w_pdfjs_require__(181); +var _stream = __w_pdfjs_require__(190); + +var _type1_parser = __w_pdfjs_require__(214); function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } -function _iterableToArrayLimit(arr, i) { 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 _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { 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; } @@ -35696,7 +36434,7 @@ var Font = function FontClosure() { }; } - function sanitizeMetrics(font, header, metrics, numGlyphs) { + function sanitizeMetrics(font, header, metrics, numGlyphs, dupFirstEntry) { if (!header) { if (metrics) { metrics.data = null; @@ -35734,6 +36472,12 @@ var Font = function FontClosure() { if (numMissing > 0) { var entries = new Uint8Array(metrics.length + numMissing * 2); entries.set(metrics.data); + + if (dupFirstEntry) { + entries[metrics.length] = metrics.data[2]; + entries[metrics.length + 1] = metrics.data[3]; + } + metrics.data = entries; } } @@ -36489,7 +37233,7 @@ var Font = function FontClosure() { delete tables['cvt ']; } - sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphsOut); + sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphsOut, dupFirstEntry); if (!tables['head']) { throw new _util.FormatError('Required "head" table is not found'); @@ -37105,7 +37849,7 @@ var Type1Font = function Type1FontClosure() { headerBytes = stream.getBytes(suggestedLength); headerBytesLength = headerBytes.length; } catch (ex) { - if (ex instanceof _util.MissingDataException) { + if (ex instanceof _core_utils.MissingDataException) { throw ex; } } @@ -37189,7 +37933,7 @@ var Type1Font = function Type1FontClosure() { var eexecBlock = getEexecBlock(file, eexecBlockLength); var eexecBlockParser = new _type1_parser.Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED); - var data = eexecBlockParser.extractFontProgram(); + var data = eexecBlockParser.extractFontProgram(properties); for (var info in data.properties) { properties[info] = data.properties[info]; @@ -37329,20 +38073,22 @@ var Type1Font = function Type1FontClosure() { cff.strings = strings; cff.globalSubrIndex = new _cff_parser.CFFIndex(); var count = glyphs.length; - var charsetArray = [0]; + var charsetArray = ['.notdef']; var i, ii; for (i = 0; i < count; i++) { - var index = _cff_parser.CFFStandardStrings.indexOf(charstrings[i].glyphName); + var glyphName = charstrings[i].glyphName; + + var index = _cff_parser.CFFStandardStrings.indexOf(glyphName); if (index === -1) { - index = 0; + strings.add(glyphName); } - charsetArray.push(index >> 8 & 0xff, index & 0xff); + charsetArray.push(glyphName); } - cff.charset = new _cff_parser.CFFCharset(false, 0, [], charsetArray); + cff.charset = new _cff_parser.CFFCharset(false, 0, charsetArray); var charStringsIndex = new _cff_parser.CFFIndex(); charStringsIndex.add([0x8B, 0x0E]); @@ -37422,16 +38168,18 @@ var CFFFont = function CFFFontClosure() { if (properties.composite) { charCodeToGlyphId = Object.create(null); + var charCode; if (cff.isCIDFont) { for (glyphId = 0; glyphId < charsets.length; glyphId++) { var cid = charsets[glyphId]; - var charCode = properties.cMap.charCodeOf(cid); + charCode = properties.cMap.charCodeOf(cid); charCodeToGlyphId[charCode] = glyphId; } } else { for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) { - charCodeToGlyphId[glyphId] = glyphId; + charCode = properties.cMap.charCodeOf(glyphId); + charCodeToGlyphId[charCode] = glyphId; } } @@ -37450,7 +38198,7 @@ var CFFFont = function CFFFontClosure() { }(); /***/ }), -/* 174 */ +/* 207 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -37461,15 +38209,16 @@ Object.defineProperty(exports, "__esModule", { }); exports.CFFFDSelect = exports.CFFCompiler = exports.CFFPrivateDict = exports.CFFTopDict = exports.CFFCharset = exports.CFFIndex = exports.CFFStrings = exports.CFFHeader = exports.CFF = exports.CFFParser = exports.CFFStandardStrings = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _charsets = __w_pdfjs_require__(175); +var _charsets = __w_pdfjs_require__(208); -var _encodings = __w_pdfjs_require__(176); +var _encodings = __w_pdfjs_require__(209); var MAX_SUBR_NESTING = 10; var CFFStandardStrings = ['.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency', 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl', 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior', 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior', 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003', 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold']; exports.CFFStandardStrings = CFFStandardStrings; +var NUM_STANDARD_CFF_STRINGS = 391; var CFFParser = function CFFParserClosure() { var CharstringValidationData = [null, { @@ -38466,16 +39215,31 @@ var CFFStrings = function CFFStringsClosure() { CFFStrings.prototype = { get: function CFFStrings_get(index) { - if (index >= 0 && index <= 390) { + if (index >= 0 && index <= NUM_STANDARD_CFF_STRINGS - 1) { return CFFStandardStrings[index]; } - if (index - 391 <= this.strings.length) { - return this.strings[index - 391]; + if (index - NUM_STANDARD_CFF_STRINGS <= this.strings.length) { + return this.strings[index - NUM_STANDARD_CFF_STRINGS]; } return CFFStandardStrings[0]; }, + getSID: function CFFStrings_getSID(str) { + var index = CFFStandardStrings.indexOf(str); + + if (index !== -1) { + return index; + } + + index = this.strings.indexOf(str); + + if (index !== -1) { + return index + NUM_STANDARD_CFF_STRINGS; + } + + return -1; + }, add: function CFFStrings_add(value) { this.strings.push(value); }, @@ -38812,7 +39576,7 @@ var CFFCompiler = function CFFCompilerClosure() { } } - var charset = this.compileCharset(cff.charset); + var charset = this.compileCharset(cff.charset, cff.charStrings.count, cff.strings, cff.isCIDFont); topDictTracker.setEntryLocation('charset', [output.length], output); output.add(charset); var charStrings = this.compileCharStrings(cff.charStrings); @@ -38907,13 +39671,13 @@ var CFFCompiler = function CFFCompilerClosure() { var sanitizedName = new Array(length); for (var j = 0; j < length; j++) { - var char = name[j]; + var _char = name[j]; - if (char < '!' || char > '~' || char === '[' || char === ']' || char === '(' || char === ')' || char === '{' || char === '}' || char === '<' || char === '>' || char === '/' || char === '%') { - char = '_'; + if (_char < '!' || _char > '~' || _char === '[' || _char === ']' || _char === '(' || _char === ')' || _char === '{' || _char === '}' || _char === '<' || _char === '>' || _char === '/' || _char === '%') { + _char = '_'; } - sanitizedName[j] = char; + sanitizedName[j] = _char; } sanitizedName = sanitizedName.join(''); @@ -39078,9 +39842,42 @@ var CFFCompiler = function CFFCompilerClosure() { return this.compileIndex(charStringsIndex); }, - compileCharset: function CFFCompiler_compileCharset(charset) { - var length = 1 + (this.cff.charStrings.count - 1) * 2; - var out = new Uint8Array(length); + compileCharset: function CFFCompiler_compileCharset(charset, numGlyphs, strings, isCIDFont) { + var out; + var numGlyphsLessNotDef = numGlyphs - 1; + + if (isCIDFont) { + out = new Uint8Array([2, 0, 0, numGlyphsLessNotDef >> 8 & 0xFF, numGlyphsLessNotDef & 0xFF]); + } else { + var length = 1 + numGlyphsLessNotDef * 2; + out = new Uint8Array(length); + out[0] = 0; + var charsetIndex = 0; + var numCharsets = charset.charset.length; + var warned = false; + + for (var i = 1; i < out.length; i += 2) { + var sid = 0; + + if (charsetIndex < numCharsets) { + var name = charset.charset[charsetIndex++]; + sid = strings.getSID(name); + + if (sid === -1) { + sid = 0; + + if (!warned) { + warned = true; + (0, _util.warn)("Couldn't find ".concat(name, " in CFF strings")); + } + } + } + + out[i] = sid >> 8 & 0xFF; + out[i + 1] = sid & 0xFF; + } + } + return this.compileTypedArray(out); }, compileEncoding: function CFFCompiler_compileEncoding(encoding) { @@ -39201,7 +39998,7 @@ var CFFCompiler = function CFFCompilerClosure() { exports.CFFCompiler = CFFCompiler; /***/ }), -/* 175 */ +/* 208 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -39219,7 +40016,7 @@ var ExpertSubsetCharset = ['.notdef', 'space', 'dollaroldstyle', 'dollarsuperior exports.ExpertSubsetCharset = ExpertSubsetCharset; /***/ }), -/* 176 */ +/* 209 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -39273,10 +40070,10 @@ function getEncoding(encodingName) { } /***/ }), -/* 177 */ +/* 210 */ /***/ (function(module, exports, __w_pdfjs_require__) { -var getLookupTableFactory = __w_pdfjs_require__(6).getLookupTableFactory; +var getLookupTableFactory = __w_pdfjs_require__(186).getLookupTableFactory; var getGlyphsUnicode = getLookupTableFactory(function (t) { t['A'] = 0x0041; t['AE'] = 0x00C6; @@ -41087,6 +41884,7 @@ var getGlyphsUnicode = getLookupTableFactory(function (t) { t['feicoptic'] = 0x03E5; t['female'] = 0x2640; t['ff'] = 0xFB00; + t['f_f'] = 0xFB00; t['ffi'] = 0xFB03; t['ffl'] = 0xFB04; t['fi'] = 0xFB01; @@ -43809,7 +44607,7 @@ exports.getGlyphsUnicode = getGlyphsUnicode; exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode; /***/ }), -/* 178 */ +/* 211 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -43820,9 +44618,9 @@ Object.defineProperty(exports, "__esModule", { }); exports.getSupplementalGlyphMapForCalibri = exports.getSupplementalGlyphMapForArialBlack = exports.getGlyphMapForStandardFonts = exports.getSymbolsFonts = exports.getSerifFonts = exports.getNonStdFontMap = exports.getStdFontMap = void 0; -var _util = __w_pdfjs_require__(6); +var _core_utils = __w_pdfjs_require__(186); -var getStdFontMap = (0, _util.getLookupTableFactory)(function (t) { +var getStdFontMap = (0, _core_utils.getLookupTableFactory)(function (t) { t['ArialNarrow'] = 'Helvetica'; t['ArialNarrow-Bold'] = 'Helvetica-Bold'; t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique'; @@ -43881,7 +44679,7 @@ var getStdFontMap = (0, _util.getLookupTableFactory)(function (t) { t['TimesNewRomanPSMT-Italic'] = 'Times-Italic'; }); exports.getStdFontMap = getStdFontMap; -var getNonStdFontMap = (0, _util.getLookupTableFactory)(function (t) { +var getNonStdFontMap = (0, _core_utils.getLookupTableFactory)(function (t) { t['Calibri'] = 'Helvetica'; t['Calibri-Bold'] = 'Helvetica-Bold'; t['Calibri-BoldItalic'] = 'Helvetica-BoldOblique'; @@ -43919,7 +44717,7 @@ var getNonStdFontMap = (0, _util.getLookupTableFactory)(function (t) { t['Wingdings'] = 'ZapfDingbats'; }); exports.getNonStdFontMap = getNonStdFontMap; -var getSerifFonts = (0, _util.getLookupTableFactory)(function (t) { +var getSerifFonts = (0, _core_utils.getLookupTableFactory)(function (t) { t['Adobe Jenson'] = true; t['Adobe Text'] = true; t['Albertus'] = true; @@ -44055,13 +44853,13 @@ var getSerifFonts = (0, _util.getLookupTableFactory)(function (t) { t['XITS'] = true; }); exports.getSerifFonts = getSerifFonts; -var getSymbolsFonts = (0, _util.getLookupTableFactory)(function (t) { +var getSymbolsFonts = (0, _core_utils.getLookupTableFactory)(function (t) { t['Dingbats'] = true; t['Symbol'] = true; t['ZapfDingbats'] = true; }); exports.getSymbolsFonts = getSymbolsFonts; -var getGlyphMapForStandardFonts = (0, _util.getLookupTableFactory)(function (t) { +var getGlyphMapForStandardFonts = (0, _core_utils.getLookupTableFactory)(function (t) { t[2] = 10; t[3] = 32; t[4] = 33; @@ -44457,13 +45255,13 @@ var getGlyphMapForStandardFonts = (0, _util.getLookupTableFactory)(function (t) t[3416] = 8377; }); exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts; -var getSupplementalGlyphMapForArialBlack = (0, _util.getLookupTableFactory)(function (t) { +var getSupplementalGlyphMapForArialBlack = (0, _core_utils.getLookupTableFactory)(function (t) { t[227] = 322; t[264] = 261; t[291] = 346; }); exports.getSupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack; -var getSupplementalGlyphMapForCalibri = (0, _util.getLookupTableFactory)(function (t) { +var getSupplementalGlyphMapForCalibri = (0, _core_utils.getLookupTableFactory)(function (t) { t[1] = 32; t[4] = 65; t[17] = 66; @@ -44552,10 +45350,10 @@ var getSupplementalGlyphMapForCalibri = (0, _util.getLookupTableFactory)(functio exports.getSupplementalGlyphMapForCalibri = getSupplementalGlyphMapForCalibri; /***/ }), -/* 179 */ +/* 212 */ /***/ (function(module, exports, __w_pdfjs_require__) { -var getLookupTableFactory = __w_pdfjs_require__(6).getLookupTableFactory; +var getLookupTableFactory = __w_pdfjs_require__(186).getLookupTableFactory; var getSpecialPUASymbols = getLookupTableFactory(function (t) { t[63721] = 0x00A9; t[63193] = 0x00A9; @@ -46529,7 +47327,7 @@ exports.getNormalizedUnicodes = getNormalizedUnicodes; exports.getUnicodeForGlyph = getUnicodeForGlyph; /***/ }), -/* 180 */ +/* 213 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -46540,15 +47338,15 @@ Object.defineProperty(exports, "__esModule", { }); exports.FontRendererFactory = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _cff_parser = __w_pdfjs_require__(174); +var _cff_parser = __w_pdfjs_require__(207); -var _glyphlist = __w_pdfjs_require__(177); +var _glyphlist = __w_pdfjs_require__(210); -var _encodings = __w_pdfjs_require__(176); +var _encodings = __w_pdfjs_require__(209); -var _stream = __w_pdfjs_require__(157); +var _stream = __w_pdfjs_require__(190); function _typeof(obj) { 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); } @@ -47538,7 +48336,7 @@ var FontRendererFactory = function FontRendererFactoryClosure() { exports.FontRendererFactory = FontRendererFactory; /***/ }), -/* 181 */ +/* 214 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -47549,11 +48347,11 @@ Object.defineProperty(exports, "__esModule", { }); exports.Type1Parser = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _encodings = __w_pdfjs_require__(176); +var _encodings = __w_pdfjs_require__(209); -var _stream = __w_pdfjs_require__(157); +var _stream = __w_pdfjs_require__(190); var HINTING_ENABLED = false; @@ -48019,7 +48817,7 @@ var Type1Parser = function Type1ParserClosure() { return decrypt(bytes, CHAR_STRS_ENCRYPT_KEY, lenIV); }, - extractFontProgram: function Type1Parser_extractFontProgram() { + extractFontProgram: function Type1Parser_extractFontProgram(properties) { var stream = this.stream; var subrs = [], charstrings = []; @@ -48158,6 +48956,14 @@ var Type1Parser = function Type1ParserClosure() { lsb: charString.lsb, seac: charString.seac }); + + if (properties.builtInEncoding) { + var _index = properties.builtInEncoding.indexOf(glyph); + + if (_index > -1 && properties.widths[_index] === undefined && _index >= properties.firstChar && _index <= properties.lastChar) { + properties.widths[_index] = charString.width; + } + } } return program; @@ -48231,7 +49037,7 @@ var Type1Parser = function Type1ParserClosure() { exports.Type1Parser = Type1Parser; /***/ }), -/* 182 */ +/* 215 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -48243,11 +49049,13 @@ Object.defineProperty(exports, "__esModule", { exports.getTilingPatternIR = getTilingPatternIR; exports.Pattern = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); + +var _colorspace = __w_pdfjs_require__(201); -var _colorspace = __w_pdfjs_require__(168); +var _primitives = __w_pdfjs_require__(183); -var _primitives = __w_pdfjs_require__(155); +var _core_utils = __w_pdfjs_require__(186); var ShadingType = { FUNCTION_BASED: 1, @@ -48290,7 +49098,7 @@ var Pattern = function PatternClosure() { throw new _util.FormatError('Unsupported ShadingType: ' + type); } } catch (ex) { - if (ex instanceof _util.MissingDataException) { + if (ex instanceof _core_utils.MissingDataException) { throw ex; } @@ -48318,6 +49126,14 @@ Shadings.RadialAxial = function RadialAxialClosure() { var cs = dict.get('ColorSpace', 'CS'); cs = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory); this.cs = cs; + var bbox = dict.getArray('BBox'); + + if (Array.isArray(bbox) && bbox.length === 4) { + this.bbox = _util.Util.normalizeRect(bbox); + } else { + this.bbox = null; + } + var t0 = 0.0, t1 = 1.0; @@ -48354,8 +49170,8 @@ Shadings.RadialAxial = function RadialAxialClosure() { this.extendEnd = extendEnd; var fnObj = dict.get('Function'); var fn = pdfFunctionFactory.createFromArray(fnObj); - var diff = t1 - t0; - var step = diff / 10; + var NUMBER_OF_SAMPLES = 10; + var step = (t1 - t0) / NUMBER_OF_SAMPLES; var colorStops = this.colorStops = []; if (t0 >= t1 || step <= 0) { @@ -48367,14 +49183,14 @@ Shadings.RadialAxial = function RadialAxialClosure() { ratio = new Float32Array(1); var rgbColor; - for (var i = t0; i <= t1; i += step) { - ratio[0] = i; + for (var i = 0; i <= NUMBER_OF_SAMPLES; i++) { + ratio[0] = t0 + i * step; fn(ratio, 0, color, 0); rgbColor = cs.getRgb(color, 0); var cssColor = _util.Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]); - colorStops.push([(i - t0) / diff, cssColor]); + colorStops.push([i / NUMBER_OF_SAMPLES, cssColor]); } var background = 'transparent'; @@ -48433,7 +49249,7 @@ Shadings.RadialAxial = function RadialAxialClosure() { } } - return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1]; + return ['RadialAxial', type, this.bbox, this.colorStops, p0, p1, r0, r1]; } }; return RadialAxial; @@ -49050,7 +49866,14 @@ Shadings.Mesh = function MeshClosure() { this.matrix = matrix; this.shadingType = dict.get('ShadingType'); this.type = 'Pattern'; - this.bbox = dict.getArray('BBox'); + var bbox = dict.getArray('BBox'); + + if (Array.isArray(bbox) && bbox.length === 4) { + this.bbox = _util.Util.normalizeRect(bbox); + } else { + this.bbox = null; + } + var cs = dict.get('ColorSpace', 'CS'); cs = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory); this.cs = cs; @@ -49153,7 +49976,7 @@ function getTilingPatternIR(operatorList, dict, args) { } /***/ }), -/* 183 */ +/* 216 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -49164,7 +49987,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.bidi = bidi; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); var baseTypes = ['BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS', 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'ON', 'ES', 'CS', 'ES', 'CS', 'CS', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'CS', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON', 'ON', 'BN', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON', 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L']; var arabicTypes = ['AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'ON', 'ON', 'AL', 'ET', 'ET', 'AL', 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', '', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AN', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'NSM', 'NSM', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL']; @@ -49457,7 +50280,7 @@ function bidi(str, startLevel, vertical) { } /***/ }), -/* 184 */ +/* 217 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -49468,14 +50291,14 @@ Object.defineProperty(exports, "__esModule", { }); exports.getMetrics = void 0; -var _util = __w_pdfjs_require__(6); +var _core_utils = __w_pdfjs_require__(186); -var getMetrics = (0, _util.getLookupTableFactory)(function (t) { +var getMetrics = (0, _core_utils.getLookupTableFactory)(function (t) { t['Courier'] = 600; t['Courier-Bold'] = 600; t['Courier-BoldOblique'] = 600; t['Courier-Oblique'] = 600; - t['Helvetica'] = (0, _util.getLookupTableFactory)(function (t) { + t['Helvetica'] = (0, _core_utils.getLookupTableFactory)(function (t) { t['space'] = 278; t['exclam'] = 278; t['quotedbl'] = 355; @@ -49792,7 +50615,7 @@ var getMetrics = (0, _util.getLookupTableFactory)(function (t) { t['imacron'] = 278; t['Euro'] = 556; }); - t['Helvetica-Bold'] = (0, _util.getLookupTableFactory)(function (t) { + t['Helvetica-Bold'] = (0, _core_utils.getLookupTableFactory)(function (t) { t['space'] = 278; t['exclam'] = 333; t['quotedbl'] = 474; @@ -50109,7 +50932,7 @@ var getMetrics = (0, _util.getLookupTableFactory)(function (t) { t['imacron'] = 278; t['Euro'] = 556; }); - t['Helvetica-BoldOblique'] = (0, _util.getLookupTableFactory)(function (t) { + t['Helvetica-BoldOblique'] = (0, _core_utils.getLookupTableFactory)(function (t) { t['space'] = 278; t['exclam'] = 333; t['quotedbl'] = 474; @@ -50426,7 +51249,7 @@ var getMetrics = (0, _util.getLookupTableFactory)(function (t) { t['imacron'] = 278; t['Euro'] = 556; }); - t['Helvetica-Oblique'] = (0, _util.getLookupTableFactory)(function (t) { + t['Helvetica-Oblique'] = (0, _core_utils.getLookupTableFactory)(function (t) { t['space'] = 278; t['exclam'] = 278; t['quotedbl'] = 355; @@ -50743,7 +51566,7 @@ var getMetrics = (0, _util.getLookupTableFactory)(function (t) { t['imacron'] = 278; t['Euro'] = 556; }); - t['Symbol'] = (0, _util.getLookupTableFactory)(function (t) { + t['Symbol'] = (0, _core_utils.getLookupTableFactory)(function (t) { t['space'] = 250; t['exclam'] = 333; t['universal'] = 713; @@ -50935,7 +51758,7 @@ var getMetrics = (0, _util.getLookupTableFactory)(function (t) { t['bracerightbt'] = 494; t['apple'] = 790; }); - t['Times-Roman'] = (0, _util.getLookupTableFactory)(function (t) { + t['Times-Roman'] = (0, _core_utils.getLookupTableFactory)(function (t) { t['space'] = 250; t['exclam'] = 333; t['quotedbl'] = 408; @@ -51252,7 +52075,7 @@ var getMetrics = (0, _util.getLookupTableFactory)(function (t) { t['imacron'] = 278; t['Euro'] = 500; }); - t['Times-Bold'] = (0, _util.getLookupTableFactory)(function (t) { + t['Times-Bold'] = (0, _core_utils.getLookupTableFactory)(function (t) { t['space'] = 250; t['exclam'] = 333; t['quotedbl'] = 555; @@ -51569,7 +52392,7 @@ var getMetrics = (0, _util.getLookupTableFactory)(function (t) { t['imacron'] = 278; t['Euro'] = 500; }); - t['Times-BoldItalic'] = (0, _util.getLookupTableFactory)(function (t) { + t['Times-BoldItalic'] = (0, _core_utils.getLookupTableFactory)(function (t) { t['space'] = 250; t['exclam'] = 389; t['quotedbl'] = 555; @@ -51886,7 +52709,7 @@ var getMetrics = (0, _util.getLookupTableFactory)(function (t) { t['imacron'] = 278; t['Euro'] = 500; }); - t['Times-Italic'] = (0, _util.getLookupTableFactory)(function (t) { + t['Times-Italic'] = (0, _core_utils.getLookupTableFactory)(function (t) { t['space'] = 250; t['exclam'] = 333; t['quotedbl'] = 420; @@ -52203,7 +53026,7 @@ var getMetrics = (0, _util.getLookupTableFactory)(function (t) { t['imacron'] = 278; t['Euro'] = 500; }); - t['ZapfDingbats'] = (0, _util.getLookupTableFactory)(function (t) { + t['ZapfDingbats'] = (0, _core_utils.getLookupTableFactory)(function (t) { t['space'] = 278; t['a1'] = 974; t['a2'] = 961; @@ -52411,7 +53234,7 @@ var getMetrics = (0, _util.getLookupTableFactory)(function (t) { exports.getMetrics = getMetrics; /***/ }), -/* 185 */ +/* 218 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -52423,11 +53246,11 @@ Object.defineProperty(exports, "__esModule", { exports.isPDFFunction = isPDFFunction; exports.PostScriptCompiler = exports.PostScriptEvaluator = exports.PDFFunctionFactory = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _primitives = __w_pdfjs_require__(155); +var _primitives = __w_pdfjs_require__(183); -var _ps_parser = __w_pdfjs_require__(186); +var _ps_parser = __w_pdfjs_require__(219); function _typeof(obj) { 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); } @@ -53758,7 +54581,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() { exports.PostScriptCompiler = PostScriptCompiler; /***/ }), -/* 186 */ +/* 219 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -53769,9 +54592,9 @@ Object.defineProperty(exports, "__esModule", { }); exports.PostScriptParser = exports.PostScriptLexer = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _primitives = __w_pdfjs_require__(155); +var _primitives = __w_pdfjs_require__(183); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -54051,7 +54874,7 @@ function () { exports.PostScriptLexer = PostScriptLexer; /***/ }), -/* 187 */ +/* 220 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -54062,20 +54885,31 @@ Object.defineProperty(exports, "__esModule", { }); exports.MurmurHash3_64 = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var MurmurHash3_64 = function MurmurHash3_64Closure(seed) { - var MASK_HIGH = 0xffff0000; - var MASK_LOW = 0xffff; +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 SEED = 0xc3d2e1f0; +var MASK_HIGH = 0xffff0000; +var MASK_LOW = 0xffff; + +var MurmurHash3_64 = +/*#__PURE__*/ +function () { function MurmurHash3_64(seed) { - var SEED = 0xc3d2e1f0; + _classCallCheck(this, MurmurHash3_64); + this.h1 = seed ? seed & 0xffffffff : SEED; this.h2 = seed ? seed & 0xffffffff : SEED; } - MurmurHash3_64.prototype = { - update: function MurmurHash3_64_update(input) { + _createClass(MurmurHash3_64, [{ + key: "update", + value: function update(input) { var data, length; if ((0, _util.isString)(input)) { @@ -54102,14 +54936,14 @@ var MurmurHash3_64 = function MurmurHash3_64Closure(seed) { var blockCounts = length >> 2; var tailLength = length - blockCounts * 4; var dataUint32 = new Uint32Array(data.buffer, 0, blockCounts); - var k1 = 0; - var k2 = 0; - var h1 = this.h1; - var h2 = this.h2; - var C1 = 0xcc9e2d51; - var C2 = 0x1b873593; - var C1_LOW = C1 & MASK_LOW; - var C2_LOW = C2 & MASK_LOW; + var k1 = 0, + k2 = 0; + var h1 = this.h1, + h2 = this.h2; + var C1 = 0xcc9e2d51, + C2 = 0x1b873593; + var C1_LOW = C1 & MASK_LOW, + C2_LOW = C2 & MASK_LOW; for (var _i = 0; _i < blockCounts; _i++) { if (_i & 1) { @@ -54156,11 +54990,12 @@ var MurmurHash3_64 = function MurmurHash3_64Closure(seed) { this.h1 = h1; this.h2 = h2; - return this; - }, - hexdigest: function MurmurHash3_64_hexdigest() { - var h1 = this.h1; - var h2 = this.h2; + } + }, { + key: "hexdigest", + value: function hexdigest() { + var h1 = this.h1, + h2 = this.h2; h1 ^= h2 >>> 1; h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW; h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16; @@ -54168,27 +55003,115 @@ var MurmurHash3_64 = function MurmurHash3_64Closure(seed) { h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW; h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16; h1 ^= h2 >>> 1; + var hex1 = (h1 >>> 0).toString(16), + hex2 = (h2 >>> 0).toString(16); + return hex1.padStart(8, '0') + hex2.padStart(8, '0'); + } + }]); - for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) { - var hex = (arr[i] >>> 0).toString(16); + return MurmurHash3_64; +}(); - while (hex.length < 8) { - hex = '0' + hex; - } +exports.MurmurHash3_64 = MurmurHash3_64; - str += hex; +/***/ }), +/* 221 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.NativeImageDecoder = void 0; + +var _colorspace = __w_pdfjs_require__(201); + +var _jpeg_stream = __w_pdfjs_require__(196); + +var _stream = __w_pdfjs_require__(190); + +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 NativeImageDecoder = +/*#__PURE__*/ +function () { + function NativeImageDecoder(_ref) { + var xref = _ref.xref, + resources = _ref.resources, + handler = _ref.handler, + _ref$forceDataSchema = _ref.forceDataSchema, + forceDataSchema = _ref$forceDataSchema === void 0 ? false : _ref$forceDataSchema, + pdfFunctionFactory = _ref.pdfFunctionFactory; + + _classCallCheck(this, NativeImageDecoder); + + this.xref = xref; + this.resources = resources; + this.handler = handler; + this.forceDataSchema = forceDataSchema; + this.pdfFunctionFactory = pdfFunctionFactory; + } + + _createClass(NativeImageDecoder, [{ + key: "canDecode", + value: function canDecode(image) { + return image instanceof _jpeg_stream.JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources, this.pdfFunctionFactory); + } + }, { + key: "decode", + value: function decode(image) { + var dict = image.dict; + var colorSpace = dict.get('ColorSpace', 'CS'); + colorSpace = _colorspace.ColorSpace.parse(colorSpace, this.xref, this.resources, this.pdfFunctionFactory); + return this.handler.sendWithPromise('JpegDecode', [image.getIR(this.forceDataSchema), colorSpace.numComps]).then(function (_ref2) { + var data = _ref2.data, + width = _ref2.width, + height = _ref2.height; + return new _stream.Stream(data, 0, data.length, dict); + }); + } + }], [{ + key: "isSupported", + value: function isSupported(image, xref, res, pdfFunctionFactory) { + var dict = image.dict; + + if (dict.has('DecodeParms') || dict.has('DP')) { + return false; } - return str; + var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res, pdfFunctionFactory); + + return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D')); } - }; - return MurmurHash3_64; + }, { + key: "isDecodable", + value: function isDecodable(image, xref, res, pdfFunctionFactory) { + var dict = image.dict; + + if (dict.has('DecodeParms') || dict.has('DP')) { + return false; + } + + var cs = _colorspace.ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res, pdfFunctionFactory); + + var bpc = dict.get('BitsPerComponent', 'BPC') || 1; + return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'), bpc); + } + }]); + + return NativeImageDecoder; }(); -exports.MurmurHash3_64 = MurmurHash3_64; +exports.NativeImageDecoder = NativeImageDecoder; /***/ }), -/* 188 */ +/* 222 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -54199,30 +55122,30 @@ Object.defineProperty(exports, "__esModule", { }); exports.PDFImage = void 0; -var _util = __w_pdfjs_require__(6); +var _util = __w_pdfjs_require__(5); -var _primitives = __w_pdfjs_require__(155); +var _primitives = __w_pdfjs_require__(183); -var _colorspace = __w_pdfjs_require__(168); +var _colorspace = __w_pdfjs_require__(201); -var _stream = __w_pdfjs_require__(157); +var _stream = __w_pdfjs_require__(190); -var _jpeg_stream = __w_pdfjs_require__(163); +var _jpeg_stream = __w_pdfjs_require__(196); -var _jpx = __w_pdfjs_require__(166); +var _jpx = __w_pdfjs_require__(199); function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } -function _iterableToArrayLimit(arr, i) { 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 _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { 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; } var PDFImage = function PDFImageClosure() { function handleImageData(image, nativeDecoder) { if (nativeDecoder && nativeDecoder.canDecode(image)) { - return nativeDecoder.decode(image).catch(function (reason) { + return nativeDecoder.decode(image)["catch"](function (reason) { (0, _util.warn)('Native image decoding failed -- trying to recover: ' + (reason && reason.message)); return image; }); @@ -54859,7 +55782,7 @@ var PDFImage = function PDFImageClosure() { exports.PDFImage = PDFImage; /***/ }), -/* 189 */ +/* 223 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -54870,53 +55793,21 @@ Object.defineProperty(exports, "__esModule", { }); exports.MessageHandler = MessageHandler; -var _regenerator = _interopRequireDefault(__w_pdfjs_require__(2)); - -var _util = __w_pdfjs_require__(6); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +var _util = __w_pdfjs_require__(5); function _typeof(obj) { 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 resolveCall(_x, _x2) { - return _resolveCall.apply(this, arguments); -} - -function _resolveCall() { - _resolveCall = _asyncToGenerator( - /*#__PURE__*/ - _regenerator.default.mark(function _callee(fn, args) { - var thisArg, - _args = arguments; - return _regenerator.default.wrap(function _callee$(_context) { - while (1) { - switch (_context.prev = _context.next) { - case 0: - thisArg = _args.length > 2 && _args[2] !== undefined ? _args[2] : null; - - if (fn) { - _context.next = 3; - break; - } - - return _context.abrupt("return"); - - case 3: - return _context.abrupt("return", fn.apply(thisArg, args)); - - case 4: - case "end": - return _context.stop(); - } - } - }, _callee, this); - })); - return _resolveCall.apply(this, arguments); -} +var StreamKind = { + UNKNOWN: 0, + CANCEL: 1, + CANCEL_COMPLETE: 2, + CLOSE: 3, + ENQUEUE: 4, + ERROR: 5, + PULL: 6, + PULL_COMPLETE: 7, + START_COMPLETE: 8 +}; function wrapReason(reason) { if (_typeof(reason) !== 'object') { @@ -54933,31 +55824,14 @@ function wrapReason(reason) { case 'UnexpectedResponseException': return new _util.UnexpectedResponseException(reason.message, reason.status); - default: + case 'UnknownErrorException': return new _util.UnknownErrorException(reason.message, reason.details); - } -} -function makeReasonSerializable(reason) { - if (!(reason instanceof Error) || reason instanceof _util.AbortException || reason instanceof _util.MissingPDFException || reason instanceof _util.UnexpectedResponseException || reason instanceof _util.UnknownErrorException) { - return reason; - } - - return new _util.UnknownErrorException(reason.message, reason.toString()); -} - -function resolveOrReject(capability, success, reason) { - if (success) { - capability.resolve(); - } else { - capability.reject(reason); + default: + return new _util.UnknownErrorException(reason.message, reason.toString()); } } -function finalize(promise) { - return Promise.resolve(promise).catch(function () {}); -} - function MessageHandler(sourceName, targetName, comObj) { var _this = this; @@ -54988,8 +55862,8 @@ function MessageHandler(sourceName, targetName, comObj) { var callback = callbacksCapabilities[callbackId]; delete callbacksCapabilities[callbackId]; - if ('error' in data) { - callback.reject(wrapReason(data.error)); + if ('reason' in data) { + callback.reject(wrapReason(data.reason)); } else { callback.resolve(data.data); } @@ -55002,8 +55876,8 @@ function MessageHandler(sourceName, targetName, comObj) { if (data.callbackId) { var _sourceName = _this.sourceName; var _targetName = data.sourceName; - Promise.resolve().then(function () { - return action[0].call(action[1], data.data); + new Promise(function (resolve) { + resolve(action(data.data)); }).then(function (result) { comObj.postMessage({ sourceName: _sourceName, @@ -55018,13 +55892,13 @@ function MessageHandler(sourceName, targetName, comObj) { targetName: _targetName, isReply: true, callbackId: data.callbackId, - error: makeReasonSerializable(reason) + reason: wrapReason(reason) }); }); } else if (data.streamId) { _this._createStreamSink(data); } else { - action[0].call(action[1], data.data); + action(data.data); } } else { throw new Error("Unknown action from worker: ".concat(data.action)); @@ -55035,40 +55909,38 @@ function MessageHandler(sourceName, targetName, comObj) { } MessageHandler.prototype = { - on: function on(actionName, handler, scope) { + on: function on(actionName, handler) { var ah = this.actionHandler; if (ah[actionName]) { throw new Error("There is already an actionName called \"".concat(actionName, "\"")); } - ah[actionName] = [handler, scope]; + ah[actionName] = handler; }, send: function send(actionName, data, transfers) { - var message = { + this.postMessage({ sourceName: this.sourceName, targetName: this.targetName, action: actionName, data: data - }; - this.postMessage(message, transfers); + }, transfers); }, sendWithPromise: function sendWithPromise(actionName, data, transfers) { var callbackId = this.callbackId++; - var message = { - sourceName: this.sourceName, - targetName: this.targetName, - action: actionName, - data: data, - callbackId: callbackId - }; var capability = (0, _util.createPromiseCapability)(); this.callbacksCapabilities[callbackId] = capability; try { - this.postMessage(message, transfers); - } catch (e) { - capability.reject(e); + this.postMessage({ + sourceName: this.sourceName, + targetName: this.targetName, + action: actionName, + callbackId: callbackId, + data: data + }, transfers); + } catch (ex) { + capability.reject(ex); } return capability.promise; @@ -55079,12 +55951,15 @@ MessageHandler.prototype = { var streamId = this.streamId++; var sourceName = this.sourceName; var targetName = this.targetName; + var comObj = this.comObj; return new _util.ReadableStream({ start: function start(controller) { var startCapability = (0, _util.createPromiseCapability)(); _this2.streamControllers[streamId] = { controller: controller, startCall: startCapability, + pullCall: null, + cancelCall: null, isClosed: false }; @@ -55095,44 +55970,39 @@ MessageHandler.prototype = { streamId: streamId, data: data, desiredSize: controller.desiredSize - }); + }, transfers); return startCapability.promise; }, pull: function pull(controller) { var pullCapability = (0, _util.createPromiseCapability)(); _this2.streamControllers[streamId].pullCall = pullCapability; - - _this2.postMessage({ + comObj.postMessage({ sourceName: sourceName, targetName: targetName, - stream: 'pull', + stream: StreamKind.PULL, streamId: streamId, desiredSize: controller.desiredSize }); - return pullCapability.promise; }, cancel: function cancel(reason) { + (0, _util.assert)(reason instanceof Error, 'cancel must have a valid reason'); var cancelCapability = (0, _util.createPromiseCapability)(); _this2.streamControllers[streamId].cancelCall = cancelCapability; _this2.streamControllers[streamId].isClosed = true; - - _this2.postMessage({ + comObj.postMessage({ sourceName: sourceName, targetName: targetName, - stream: 'cancel', - reason: reason, - streamId: streamId + stream: StreamKind.CANCEL, + streamId: streamId, + reason: wrapReason(reason) }); - return cancelCapability.promise; } }, queueingStrategy); }, _createStreamSink: function _createStreamSink(data) { - var _this3 = this; - var self = this; var action = this.actionHandler[data.action]; var streamId = data.streamId; @@ -55140,25 +56010,7 @@ MessageHandler.prototype = { var sourceName = this.sourceName; var targetName = data.sourceName; var capability = (0, _util.createPromiseCapability)(); - - var sendStreamRequest = function sendStreamRequest(_ref) { - var stream = _ref.stream, - chunk = _ref.chunk, - transfers = _ref.transfers, - success = _ref.success, - reason = _ref.reason; - - _this3.postMessage({ - sourceName: sourceName, - targetName: targetName, - stream: stream, - streamId: streamId, - chunk: chunk, - success: success, - reason: reason - }, transfers); - }; - + var comObj = this.comObj; var streamSink = { enqueue: function enqueue(chunk) { var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; @@ -55176,11 +56028,13 @@ MessageHandler.prototype = { this.ready = this.sinkCapability.promise; } - sendStreamRequest({ - stream: 'enqueue', - chunk: chunk, - transfers: transfers - }); + self.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: StreamKind.ENQUEUE, + streamId: streamId, + chunk: chunk + }, transfers); }, close: function close() { if (this.isCancelled) { @@ -55188,20 +56042,28 @@ MessageHandler.prototype = { } this.isCancelled = true; - sendStreamRequest({ - stream: 'close' + comObj.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: StreamKind.CLOSE, + streamId: streamId }); delete self.streamSinks[streamId]; }, error: function error(reason) { + (0, _util.assert)(reason instanceof Error, 'error must have a valid reason'); + if (this.isCancelled) { return; } this.isCancelled = true; - sendStreamRequest({ - stream: 'error', - reason: reason + comObj.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: StreamKind.ERROR, + streamId: streamId, + reason: wrapReason(reason) }); }, sinkCapability: capability, @@ -55214,138 +56076,166 @@ MessageHandler.prototype = { streamSink.sinkCapability.resolve(); streamSink.ready = streamSink.sinkCapability.promise; this.streamSinks[streamId] = streamSink; - resolveCall(action[0], [data.data, streamSink], action[1]).then(function () { - sendStreamRequest({ - stream: 'start_complete', + new Promise(function (resolve) { + resolve(action(data.data, streamSink)); + }).then(function () { + comObj.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: StreamKind.START_COMPLETE, + streamId: streamId, success: true }); }, function (reason) { - sendStreamRequest({ - stream: 'start_complete', - success: false, - reason: reason + comObj.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: StreamKind.START_COMPLETE, + streamId: streamId, + reason: wrapReason(reason) }); }); }, _processStreamMessage: function _processStreamMessage(data) { - var _this4 = this; + var _this3 = this; var sourceName = this.sourceName; var targetName = data.sourceName; var streamId = data.streamId; - - var sendStreamResponse = function sendStreamResponse(_ref2) { - var stream = _ref2.stream, - success = _ref2.success, - reason = _ref2.reason; - - _this4.comObj.postMessage({ - sourceName: sourceName, - targetName: targetName, - stream: stream, - success: success, - streamId: streamId, - reason: reason - }); - }; + var comObj = this.comObj; var deleteStreamController = function deleteStreamController() { - Promise.all([_this4.streamControllers[data.streamId].startCall, _this4.streamControllers[data.streamId].pullCall, _this4.streamControllers[data.streamId].cancelCall].map(function (capability) { - return capability && finalize(capability.promise); + Promise.all([_this3.streamControllers[streamId].startCall, _this3.streamControllers[streamId].pullCall, _this3.streamControllers[streamId].cancelCall].map(function (capability) { + return capability && capability.promise["catch"](function () {}); })).then(function () { - delete _this4.streamControllers[data.streamId]; + delete _this3.streamControllers[streamId]; }); }; switch (data.stream) { - case 'start_complete': - resolveOrReject(this.streamControllers[data.streamId].startCall, data.success, wrapReason(data.reason)); + case StreamKind.START_COMPLETE: + if (data.success) { + this.streamControllers[streamId].startCall.resolve(); + } else { + this.streamControllers[streamId].startCall.reject(wrapReason(data.reason)); + } + break; - case 'pull_complete': - resolveOrReject(this.streamControllers[data.streamId].pullCall, data.success, wrapReason(data.reason)); + case StreamKind.PULL_COMPLETE: + if (data.success) { + this.streamControllers[streamId].pullCall.resolve(); + } else { + this.streamControllers[streamId].pullCall.reject(wrapReason(data.reason)); + } + break; - case 'pull': - if (!this.streamSinks[data.streamId]) { - sendStreamResponse({ - stream: 'pull_complete', + case StreamKind.PULL: + if (!this.streamSinks[streamId]) { + comObj.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: StreamKind.PULL_COMPLETE, + streamId: streamId, success: true }); break; } - if (this.streamSinks[data.streamId].desiredSize <= 0 && data.desiredSize > 0) { - this.streamSinks[data.streamId].sinkCapability.resolve(); + if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) { + this.streamSinks[streamId].sinkCapability.resolve(); } - this.streamSinks[data.streamId].desiredSize = data.desiredSize; - resolveCall(this.streamSinks[data.streamId].onPull).then(function () { - sendStreamResponse({ - stream: 'pull_complete', + this.streamSinks[streamId].desiredSize = data.desiredSize; + var onPull = this.streamSinks[data.streamId].onPull; + new Promise(function (resolve) { + resolve(onPull && onPull()); + }).then(function () { + comObj.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: StreamKind.PULL_COMPLETE, + streamId: streamId, success: true }); }, function (reason) { - sendStreamResponse({ - stream: 'pull_complete', - success: false, - reason: reason + comObj.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: StreamKind.PULL_COMPLETE, + streamId: streamId, + reason: wrapReason(reason) }); }); break; - case 'enqueue': - (0, _util.assert)(this.streamControllers[data.streamId], 'enqueue should have stream controller'); + case StreamKind.ENQUEUE: + (0, _util.assert)(this.streamControllers[streamId], 'enqueue should have stream controller'); - if (!this.streamControllers[data.streamId].isClosed) { - this.streamControllers[data.streamId].controller.enqueue(data.chunk); + if (this.streamControllers[streamId].isClosed) { + break; } + this.streamControllers[streamId].controller.enqueue(data.chunk); break; - case 'close': - (0, _util.assert)(this.streamControllers[data.streamId], 'close should have stream controller'); + case StreamKind.CLOSE: + (0, _util.assert)(this.streamControllers[streamId], 'close should have stream controller'); - if (this.streamControllers[data.streamId].isClosed) { + if (this.streamControllers[streamId].isClosed) { break; } - this.streamControllers[data.streamId].isClosed = true; - this.streamControllers[data.streamId].controller.close(); + this.streamControllers[streamId].isClosed = true; + this.streamControllers[streamId].controller.close(); deleteStreamController(); break; - case 'error': - (0, _util.assert)(this.streamControllers[data.streamId], 'error should have stream controller'); - this.streamControllers[data.streamId].controller.error(wrapReason(data.reason)); + case StreamKind.ERROR: + (0, _util.assert)(this.streamControllers[streamId], 'error should have stream controller'); + this.streamControllers[streamId].controller.error(wrapReason(data.reason)); deleteStreamController(); break; - case 'cancel_complete': - resolveOrReject(this.streamControllers[data.streamId].cancelCall, data.success, wrapReason(data.reason)); + case StreamKind.CANCEL_COMPLETE: + if (data.success) { + this.streamControllers[streamId].cancelCall.resolve(); + } else { + this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason)); + } + deleteStreamController(); break; - case 'cancel': - if (!this.streamSinks[data.streamId]) { + case StreamKind.CANCEL: + if (!this.streamSinks[streamId]) { break; } - resolveCall(this.streamSinks[data.streamId].onCancel, [wrapReason(data.reason)]).then(function () { - sendStreamResponse({ - stream: 'cancel_complete', + var onCancel = this.streamSinks[data.streamId].onCancel; + new Promise(function (resolve) { + resolve(onCancel && onCancel(wrapReason(data.reason))); + }).then(function () { + comObj.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: StreamKind.CANCEL_COMPLETE, + streamId: streamId, success: true }); }, function (reason) { - sendStreamResponse({ - stream: 'cancel_complete', - success: false, - reason: reason + comObj.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: StreamKind.CANCEL_COMPLETE, + streamId: streamId, + reason: wrapReason(reason) }); }); - this.streamSinks[data.streamId].sinkCapability.reject(wrapReason(data.reason)); - this.streamSinks[data.streamId].isCancelled = true; - delete this.streamSinks[data.streamId]; + this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason)); + this.streamSinks[streamId].isCancelled = true; + delete this.streamSinks[streamId]; break; default: @@ -55364,6 +56254,268 @@ MessageHandler.prototype = { } }; +/***/ }), +/* 224 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.PDFWorkerStream = void 0; + +var _regenerator = _interopRequireDefault(__w_pdfjs_require__(2)); + +var _util = __w_pdfjs_require__(5); + +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); }); }; } + +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 PDFWorkerStream = +/*#__PURE__*/ +function () { + function PDFWorkerStream(msgHandler) { + _classCallCheck(this, PDFWorkerStream); + + this._msgHandler = msgHandler; + this._contentLength = null; + this._fullRequestReader = null; + this._rangeRequestReaders = []; + } + + _createClass(PDFWorkerStream, [{ + key: "getFullReader", + value: function getFullReader() { + (0, _util.assert)(!this._fullRequestReader); + this._fullRequestReader = new PDFWorkerStreamReader(this._msgHandler); + return this._fullRequestReader; + } + }, { + key: "getRangeReader", + value: function getRangeReader(begin, end) { + var reader = new PDFWorkerStreamRangeReader(begin, end, this._msgHandler); + + this._rangeRequestReaders.push(reader); + + return reader; + } + }, { + key: "cancelAllRequests", + value: function cancelAllRequests(reason) { + if (this._fullRequestReader) { + this._fullRequestReader.cancel(reason); + } + + var readers = this._rangeRequestReaders.slice(0); + + readers.forEach(function (reader) { + reader.cancel(reason); + }); + } + }]); + + return PDFWorkerStream; +}(); + +exports.PDFWorkerStream = PDFWorkerStream; + +var PDFWorkerStreamReader = +/*#__PURE__*/ +function () { + function PDFWorkerStreamReader(msgHandler) { + var _this = this; + + _classCallCheck(this, PDFWorkerStreamReader); + + this._msgHandler = msgHandler; + this.onProgress = null; + this._contentLength = null; + this._isRangeSupported = false; + this._isStreamingSupported = false; + + var readableStream = this._msgHandler.sendWithStream('GetReader'); + + this._reader = readableStream.getReader(); + this._headersReady = this._msgHandler.sendWithPromise('ReaderHeadersReady').then(function (data) { + _this._isStreamingSupported = data.isStreamingSupported; + _this._isRangeSupported = data.isRangeSupported; + _this._contentLength = data.contentLength; + }); + } + + _createClass(PDFWorkerStreamReader, [{ + key: "read", + value: function () { + var _read = _asyncToGenerator( + /*#__PURE__*/ + _regenerator["default"].mark(function _callee() { + var _ref, value, done; + + return _regenerator["default"].wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + _context.next = 2; + return this._reader.read(); + + case 2: + _ref = _context.sent; + value = _ref.value; + done = _ref.done; + + if (!done) { + _context.next = 7; + break; + } + + return _context.abrupt("return", { + value: undefined, + done: true + }); + + case 7: + return _context.abrupt("return", { + value: value.buffer, + done: false + }); + + case 8: + case "end": + return _context.stop(); + } + } + }, _callee, this); + })); + + function read() { + return _read.apply(this, arguments); + } + + return read; + }() + }, { + key: "cancel", + value: function cancel(reason) { + this._reader.cancel(reason); + } + }, { + key: "headersReady", + get: function get() { + return this._headersReady; + } + }, { + key: "contentLength", + get: function get() { + return this._contentLength; + } + }, { + key: "isStreamingSupported", + get: function get() { + return this._isStreamingSupported; + } + }, { + key: "isRangeSupported", + get: function get() { + return this._isRangeSupported; + } + }]); + + return PDFWorkerStreamReader; +}(); + +var PDFWorkerStreamRangeReader = +/*#__PURE__*/ +function () { + function PDFWorkerStreamRangeReader(begin, end, msgHandler) { + _classCallCheck(this, PDFWorkerStreamRangeReader); + + this._msgHandler = msgHandler; + this.onProgress = null; + + var readableStream = this._msgHandler.sendWithStream('GetRangeReader', { + begin: begin, + end: end + }); + + this._reader = readableStream.getReader(); + } + + _createClass(PDFWorkerStreamRangeReader, [{ + key: "read", + value: function () { + var _read2 = _asyncToGenerator( + /*#__PURE__*/ + _regenerator["default"].mark(function _callee2() { + var _ref2, value, done; + + return _regenerator["default"].wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + _context2.next = 2; + return this._reader.read(); + + case 2: + _ref2 = _context2.sent; + value = _ref2.value; + done = _ref2.done; + + if (!done) { + _context2.next = 7; + break; + } + + return _context2.abrupt("return", { + value: undefined, + done: true + }); + + case 7: + return _context2.abrupt("return", { + value: value.buffer, + done: false + }); + + case 8: + case "end": + return _context2.stop(); + } + } + }, _callee2, this); + })); + + function read() { + return _read2.apply(this, arguments); + } + + return read; + }() + }, { + key: "cancel", + value: function cancel(reason) { + this._reader.cancel(reason); + } + }, { + key: "isStreamingSupported", + get: function get() { + return false; + } + }]); + + return PDFWorkerStreamRangeReader; +}(); + /***/ }) /******/ ]); }); diff --git a/deploy/assets/redx.png b/deploy/assets/redx.png Binary files differnew file mode 100644 index 000000000..0c2c9ccc5 --- /dev/null +++ b/deploy/assets/redx.png diff --git a/package-lock.json b/package-lock.json index da0027d07..6198a568a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -547,9 +547,9 @@ } }, "@types/jsonwebtoken": { - "version": "8.3.5", - "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-8.3.5.tgz", - "integrity": "sha512-VGM1gb+LwsQ5EPevvbvdnKncajBdYqNcrvixBif1BsiDQiSF1q+j4bBTvKC6Bt9n2kqNSx+yNTY2TVJ360E7EQ==", + "version": "8.3.7", + "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-8.3.7.tgz", + "integrity": "sha512-B5SSifLkjB0ns7VXpOOtOUlynE78/hKcY8G8pOAhkLJZinwofIBYqz555nRj2W9iDWZqFhK5R+7NZDaRmKWAoQ==", "requires": { "@types/node": "*" } @@ -606,9 +606,9 @@ } }, "@types/mongoose": { - "version": "5.5.38", - "resolved": "https://registry.npmjs.org/@types/mongoose/-/mongoose-5.5.38.tgz", - "integrity": "sha512-W+vLJ4t0DUQhnV/ivLBLVCOvx3UnU/HgrKrEeHCUwE9VGDTdoOQOgOTiElErf+ome9zZUek6VZil5t7HfJvO+w==", + "version": "5.5.43", + "resolved": "https://registry.npmjs.org/@types/mongoose/-/mongoose-5.5.43.tgz", + "integrity": "sha512-ZZ/KnIyl81zrTfjwcbLBgb8bR9dnYJDQfcaEpOAz2B7cv1bm8FyOPonKcnAmbDHCTWkAFjsF/J3JhnLtUdWZSg==", "requires": { "@types/mongodb": "*", "@types/node": "*" @@ -647,7 +647,7 @@ }, "@types/passport": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@types/passport/-/passport-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/@types/passport/-/passport-1.0.0.tgz", "integrity": "sha512-Pf39AYKf8q+YoONym3150cEwfUD66dtwHJWvbeOzKxnA0GZZ/vAXhNWv9vMhKyRQBQZiQyWQnhYBEBlKW6G8wg==", "requires": { "@types/express": "*" @@ -822,9 +822,9 @@ } }, "@types/react": { - "version": "16.9.17", - "resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.17.tgz", - "integrity": "sha512-UP27In4fp4sWF5JgyV6pwVPAQM83Fj76JOcg02X5BZcpSu5Wx+fP9RMqc2v0ssBoQIFvD5JdKY41gjJJKmw6Bg==", + "version": "16.9.19", + "resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.19.tgz", + "integrity": "sha512-LJV97//H+zqKWMms0kvxaKYJDG05U2TtQB3chRLF8MPNs+MQh/H1aGlyDUxjaHvu08EAGerdX2z4LTBc7ns77A==", "requires": { "@types/prop-types": "*", "csstype": "^2.2.0" @@ -847,18 +847,18 @@ } }, "@types/react-dom": { - "version": "16.9.4", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.9.4.tgz", - "integrity": "sha512-fya9xteU/n90tda0s+FtN5Ym4tbgxpq/hb/Af24dvs6uYnYn+fspaxw5USlw0R8apDNwxsqumdRoCoKitckQqw==", + "version": "16.9.5", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.9.5.tgz", + "integrity": "sha512-BX6RQ8s9D+2/gDhxrj8OW+YD4R+8hj7FEM/OJHGNR0KipE1h1mSsf39YeyC81qafkq+N3rU3h3RFbLSwE5VqUg==", "dev": true, "requires": { "@types/react": "*" } }, "@types/react-measure": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@types/react-measure/-/react-measure-2.0.5.tgz", - "integrity": "sha512-T1Bpt8FlWbDhoInUaNrjTOiVRpRJmrRcqhFJxLGBq1VjaqBLHCvUPapgdKMWEIX4Oqsa1SSKjtNkNJGy6WAAZg==", + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@types/react-measure/-/react-measure-2.0.6.tgz", + "integrity": "sha512-FxAwgDVKvxm4SPXu24x9cwzsty8x33UueazHcpxM1UWZlGJI57yIHM2djE3xUJhYVxuzNzi4E8UL3kmCkdh+4A==", "requires": { "@types/react": "*" } @@ -962,9 +962,9 @@ "dev": true }, "@types/tapable": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@types/tapable/-/tapable-1.0.4.tgz", - "integrity": "sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==" + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/tapable/-/tapable-1.0.5.tgz", + "integrity": "sha512-/gG2M/Imw7cQFp8PGvz/SwocNrmKFjFsm5Pb8HdbHkZ1K8pmuPzOX4VeVoiEecFCVf4CsN1r3/BRvx+6sNqwtQ==" }, "@types/tough-cookie": { "version": "2.3.6", @@ -1003,9 +1003,9 @@ } }, "@types/webpack": { - "version": "4.41.1", - "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.1.tgz", - "integrity": "sha512-n9fP8UrMxOi1wiM3oM+vMZHMJJ7WoQohqd63C20cmKOFkNEy9Q8hyZyDR6PWdvSYt3V3A7cwDq/kWxHlRYYZEg==", + "version": "4.41.3", + "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.3.tgz", + "integrity": "sha512-dH+BZ6pHBZFrXpnif0YU/PbmUq3lQrvRPnqkxsciSIzvG/DE+Vm/Wrjn56T7V3+B5ryQa5fw0oGnHL8tk4ll6w==", "requires": { "@types/anymatch": "*", "@types/node": "*", @@ -1045,9 +1045,9 @@ } }, "@types/webpack-sources": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.5.tgz", - "integrity": "sha512-zfvjpp7jiafSmrzJ2/i3LqOyTYTuJ7u1KOXlKgDlvsj9Rr0x7ZiYu5lZbXwobL7lmsRNtPXlBfmaUD8eU2Hu8w==", + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.6.tgz", + "integrity": "sha512-FtAWR7wR5ocJ9+nP137DV81tveD/ZgB1sadnJ/axUGM3BUVfRPx8oQNMtv3JNfTeHx3VP7cXiyfR/jmtEsVHsQ==", "requires": { "@types/node": "*", "@types/source-list-map": "*", @@ -3361,28 +3361,33 @@ } }, "cookie-session": { - "version": "2.0.0-beta.3", - "resolved": "https://registry.npmjs.org/cookie-session/-/cookie-session-2.0.0-beta.3.tgz", - "integrity": "sha512-zyqm5tA0z9yMEB/xyP7lnRnqp8eLR2e0dap+9+rBwVigla9yPKn8XTL1jJymog8xjfrowqW2o5LUjixQChkqrw==", + "version": "2.0.0-rc.1", + "resolved": "https://registry.npmjs.org/cookie-session/-/cookie-session-2.0.0-rc.1.tgz", + "integrity": "sha512-zg80EsLe7S1J4y0XxV7SZ8Fbi90ZZoampuX2bfYDOvJfc//98sSlZC41YDzTTjtVbeU1VlVdBbldXOOyi5xzEw==", "requires": { - "cookies": "0.7.1", - "debug": "3.1.0", - "on-headers": "~1.0.1", - "safe-buffer": "5.1.1" + "cookies": "0.8.0", + "debug": "3.2.6", + "on-headers": "~1.0.2", + "safe-buffer": "5.2.0" }, "dependencies": { "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", + "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", "requires": { - "ms": "2.0.0" + "ms": "^2.1.1" } }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, "safe-buffer": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", + "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" } } }, @@ -3392,12 +3397,19 @@ "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, "cookies": { - "version": "0.7.1", - "resolved": "https://registry.npmjs.org/cookies/-/cookies-0.7.1.tgz", - "integrity": "sha1-fIphX1SBxhq58WyDNzG8uPZjuZs=", + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/cookies/-/cookies-0.8.0.tgz", + "integrity": "sha512-8aPsApQfebXnuI+537McwYsDtjVxGm8gTIzQI3FDW6t5t/DAhERxtnbEPN/8RX+uZthoz4eCOgloXaE5cYyNow==", "requires": { - "depd": "~1.1.1", - "keygrip": "~1.0.2" + "depd": "~2.0.0", + "keygrip": "~1.1.0" + }, + "dependencies": { + "depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==" + } } }, "copy-concurrently": { @@ -4042,6 +4054,11 @@ "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=" }, + "denque": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz", + "integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ==" + }, "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -5374,8 +5391,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -5393,13 +5409,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5412,18 +5426,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -5526,8 +5537,7 @@ }, "inherits": { "version": "2.0.4", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -5537,7 +5547,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5550,20 +5559,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.9.0", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -5580,7 +5586,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -5661,8 +5666,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -5672,7 +5676,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -5748,8 +5751,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -5779,7 +5781,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -5797,7 +5798,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -5836,13 +5836,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.1.1", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -7578,9 +7576,12 @@ "integrity": "sha1-PQr1bce4uOXLqNCpfxByBO7CKwQ=" }, "keygrip": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/keygrip/-/keygrip-1.0.3.tgz", - "integrity": "sha512-/PpesirAIfaklxUzp4Yb7xBper9MwP6hNRA6BGGUFCgbJ+BM5CKBtsoxinNXkLHAr+GXS1/lSlF2rP7cv5Fl+g==" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/keygrip/-/keygrip-1.1.0.tgz", + "integrity": "sha512-iYSchDJ+liQ8iwbSI2QqsQOvqv58eJCEanyJPJi+Khyu8smkcKSFUCbPwzFcL7YVtZ6eONjqRX/38caJ7QjRAQ==", + "requires": { + "tsscmp": "1.0.6" + } }, "killable": { "version": "1.0.1", @@ -8184,9 +8185,9 @@ "integrity": "sha512-vTgEjKjS89C5yHL5qWPpT6BzKuOVqABp+A3Szpbx34pIy3sngxlGaFpgHhfj6fKze1w0QKeOSDbU7SKu7wDvRQ==" }, "mobx": { - "version": "5.15.1", - "resolved": "https://registry.npmjs.org/mobx/-/mobx-5.15.1.tgz", - "integrity": "sha512-o4aN0GqKcDmKwu2wVsqbujU4F63ZvmbBLSc7WhzuAu9S9eF2wgNjqIkzrb/kbY3C9/mGYG4k1M0KbCuG1GJ7IQ==" + "version": "5.15.3", + "resolved": "https://registry.npmjs.org/mobx/-/mobx-5.15.3.tgz", + "integrity": "sha512-aKpzjJ11rRXMtoxIYIq8eaVB7qtB2C3L6PCwhVWSJrsfF5E38TjFqmvglmVEZ3HEEISeKx/UJ4XJ1n29smQlEw==" }, "mobx-react": { "version": "5.4.4", @@ -8203,9 +8204,9 @@ "integrity": "sha512-nc5IXLdEUFLn3wZal65KF3/JFEFd+mbH4KTz/IG5BOPyw7jo8z29w/8qm7+wiCyqVfUIgJ1gL4+HVKmcXIOgqA==" }, "mobx-utils": { - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/mobx-utils/-/mobx-utils-5.5.2.tgz", - "integrity": "sha512-cOlFJDWU/NHyGKvdhWqPdHmhPfeKewElAIZp5XticWIsSLGAA+4Uou3+8ookhQ/yG7qZXzvjAq90TZWXiR5+XA==" + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/mobx-utils/-/mobx-utils-5.5.3.tgz", + "integrity": "sha512-tCj3WLHp3y2/OZADAg9KHGtJNNwwEa8ZY92E6dnVuDoV2OaTV+e2N4S23ogsoxJ72ZhFJhNPcy7ppPJRb1Emhg==" }, "mocha": { "version": "5.2.0", @@ -8273,16 +8274,27 @@ } }, "mongodb": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.4.1.tgz", - "integrity": "sha512-juqt5/Z42J4DcE7tG7UdVaTKmUC6zinF4yioPfpeOSNBieWSK6qCY+0tfGQcHLKrauWPDdMZVROHJOa8q2pWsA==", + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.2.tgz", + "integrity": "sha512-Lxt4th2tK2MxmkDBR5cMik+xEnkvhwg0BC5kGcHm9RBwaNEsrIryvV5istGXOHbnif5KslMpY1FbX6YbGJ/Trg==", "requires": { + "bl": "^2.2.0", "bson": "^1.1.1", + "denque": "^1.4.1", "require_optional": "^1.0.1", "safe-buffer": "^5.1.2", "saslprep": "^1.0.0" }, "dependencies": { + "bl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.0.tgz", + "integrity": "sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==", + "requires": { + "readable-stream": "^2.3.5", + "safe-buffer": "^5.1.1" + } + }, "bson": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.3.tgz", @@ -8300,9 +8312,9 @@ } }, "mongoose": { - "version": "5.8.4", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.8.4.tgz", - "integrity": "sha512-jQjLckUILEQUqBuG+ihjtA9OLmrqcIG5n+vaeHpR++TG8/ug5yy5ogkDnybTSq8Ql5OORud3+OCOc2Uw96q32w==", + "version": "5.8.9", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.8.9.tgz", + "integrity": "sha512-gRazoLTQ0yuv4bk2z+nZEarKCyJ7WilFBkgrRqpOczUZUhk3i/FCe0rp8Mjc87dGXaHx54j8AjPJ0UKqJDXWMA==", "requires": { "bson": "~1.1.1", "kareem": "2.3.1", @@ -8322,6 +8334,17 @@ "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.3.tgz", "integrity": "sha512-TdiJxMVnodVS7r0BdL42y/pqC9cL2iKynVwA0Ho3qbsQYr428veL3l7BQyuqiw+Q5SqqoT0m4srSY/BlZ9AxXg==" }, + "mongodb": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.4.1.tgz", + "integrity": "sha512-juqt5/Z42J4DcE7tG7UdVaTKmUC6zinF4yioPfpeOSNBieWSK6qCY+0tfGQcHLKrauWPDdMZVROHJOa8q2pWsA==", + "requires": { + "bson": "^1.1.1", + "require_optional": "^1.0.1", + "safe-buffer": "^5.1.2", + "saslprep": "^1.0.0" + } + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -8672,9 +8695,9 @@ } }, "node-sass": { - "version": "4.13.0", - "resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.13.0.tgz", - "integrity": "sha512-W1XBrvoJ1dy7VsvTAS5q1V45lREbTlZQqFbiHb3R3OTTCma0XBtuG6xZ6Z4506nR4lmHPTqVRwxT6KgtWC97CA==", + "version": "4.13.1", + "resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.13.1.tgz", + "integrity": "sha512-TTWFx+ZhyDx1Biiez2nB0L3YrCZ/8oHagaDalbuBSlqXgUPsdkUSzJsVxeDO9LtPB49+Fh3WQl3slABo6AotNw==", "requires": { "async-foreach": "^0.1.3", "chalk": "^1.1.1", @@ -12109,9 +12132,9 @@ } }, "orderedmap": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/orderedmap/-/orderedmap-1.1.0.tgz", - "integrity": "sha512-abUlPCcmyI/17BWWoUWeAbnniTFUZuczP6iowD9XMBcUoD9jRtUO6w+KXkw64TDk+iHdyDfTAjIH7mTRzhXcaw==" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/orderedmap/-/orderedmap-1.1.1.tgz", + "integrity": "sha512-3Ux8um0zXbVacKUkcytc0u3HgC0b0bBLT+I60r2J/En72cI0nZffqrA7Xtf2Hqs27j1g82llR5Mhbd0Z1XW4AQ==" }, "original": { "version": "1.0.2", @@ -12471,9 +12494,9 @@ } }, "pdfjs-dist": { - "version": "2.2.228", - "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-2.2.228.tgz", - "integrity": "sha512-W5LhYPMS2UKX0ELIa4u+CFCMoox5qQNQElt0bAK2mwz1V8jZL0rvLao+0tBujce84PK6PvWG36Nwr7agCCWFGQ==", + "version": "2.3.200", + "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-2.3.200.tgz", + "integrity": "sha512-+8wBjU5h8LPZOIvR9X2uCrp/8xWQG1DRDKMLg5lzGN1qyIAZlYUxA0KQyy12Nw5jN7ozulC6v97PMaDcLgAcFg==", "requires": { "node-ensure": "^0.0.0", "worker-loader": "^2.0.0" @@ -12972,9 +12995,9 @@ } }, "prosemirror-model": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/prosemirror-model/-/prosemirror-model-1.8.2.tgz", - "integrity": "sha512-piffokzW7opZVCjf/9YaoXvTC0g7zMRWKJib1hpphPfC+4x6ZXe5CiExgycoWZJe59VxxP7uHX8aFiwg2i9mUQ==", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/prosemirror-model/-/prosemirror-model-1.9.1.tgz", + "integrity": "sha512-Qblh8pm1c7Ll64sYLauwwzjimo/tFg1zW3Q3IWhKRhvfOEgRKqa6dC5pRrAa+XHOIjBFEYrqbi52J5bqA2dV8Q==", "requires": { "orderedmap": "^1.1.0" } @@ -13014,9 +13037,9 @@ } }, "prosemirror-view": { - "version": "1.13.7", - "resolved": "https://registry.npmjs.org/prosemirror-view/-/prosemirror-view-1.13.7.tgz", - "integrity": "sha512-P9Vrxe5/PJ68rJi/665NYAdj9hs9iXvvDo4OxD4G0rVmt4lna/n+H7BW1gT/ItDXdNR+LiU8c1mf/TX5RkJbxA==", + "version": "1.13.8", + "resolved": "https://registry.npmjs.org/prosemirror-view/-/prosemirror-view-1.13.8.tgz", + "integrity": "sha512-gz3msc9ocWo0m7PxCeNTLxaBZ8VSD9J+A/x16GwXnROAtyKalEMvZInwk+lH2kIEIM3tC/m90xe5U/vf+vM9IA==", "requires": { "prosemirror-model": "^1.1.0", "prosemirror-state": "^1.0.0", @@ -13217,9 +13240,9 @@ "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" }, "query-string": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/query-string/-/query-string-6.9.0.tgz", - "integrity": "sha512-KG4bhCFYapExLsUHrFt+kQVEegF2agm4cpF/VNc6pZVthIfCc/GK8t8VyNIE3nyXG9DK3Tf2EGkxjR6/uRdYsA==", + "version": "6.10.1", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-6.10.1.tgz", + "integrity": "sha512-SHTUV6gDlgMXg/AQUuLpTiBtW/etZ9JT6k6RCtCyqADquApLX0Aq5oK/s5UeTUAWBG50IExjIr587GqfXRfM4A==", "requires": { "decode-uri-component": "^0.2.0", "split-on-first": "^1.0.0", @@ -13464,9 +13487,9 @@ "integrity": "sha512-o35fODF4GsNxEzmnRWZuoe29a6x3fXqRsLXOlAvS4d+TvO3yoLTM8iZnSZpJCkHQnjOOWRnGvDh5tryqJCKZ0w==" }, "react-color": { - "version": "2.17.3", - "resolved": "https://registry.npmjs.org/react-color/-/react-color-2.17.3.tgz", - "integrity": "sha512-1dtO8LqAVotPIChlmo6kLtFS1FP89ll8/OiA8EcFRDR+ntcK+0ukJgByuIQHRtzvigf26dV5HklnxDIvhON9VQ==", + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/react-color/-/react-color-2.18.0.tgz", + "integrity": "sha512-FyVeU1kQiSokWc8NPz22azl1ezLpJdUyTbWL0LPUpcuuYDrZ/Y1veOk9rRK5B3pMlyDGvTk4f4KJhlkIQNRjEA==", "requires": { "@icons/material": "^0.2.4", "lodash": "^4.17.11", @@ -13762,7 +13785,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "requires": { "core-util-is": "~1.0.0", @@ -15567,6 +15590,15 @@ "readable-stream": "^2.0.2" } }, + "stream-combiner": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.2.2.tgz", + "integrity": "sha1-rsjLrBd7Vrb0+kec7YwZEs7lKFg=", + "requires": { + "duplexer": "~0.1.1", + "through": "~2.3.4" + } + }, "stream-each": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/stream-each/-/stream-each-1.2.3.tgz", @@ -15669,7 +15701,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "requires": { "ansi-regex": "^2.0.0" @@ -16413,9 +16445,9 @@ } }, "tslint-loader": { - "version": "3.5.4", - "resolved": "https://registry.npmjs.org/tslint-loader/-/tslint-loader-3.5.4.tgz", - "integrity": "sha512-jBHNNppXut6SgZ7CsTBh+6oMwVum9n8azbmcYSeMlsABhWWoHwjq631vIFXef3VSd75cCdX3rc6kstsB7rSVVw==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/tslint-loader/-/tslint-loader-3.6.0.tgz", + "integrity": "sha512-Me9Qf/87BOfCY8uJJw+J7VMF4U8WiMXKLhKKKugMydF0xMhMOt9wo2mjYTNhwbF9H7SHh8PAIwRG8roisTNekQ==", "dev": true, "requires": { "loader-utils": "^1.0.2", @@ -16436,6 +16468,11 @@ } } }, + "tsscmp": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/tsscmp/-/tsscmp-1.0.6.tgz", + "integrity": "sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==" + }, "tsutils": { "version": "2.29.0", "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", @@ -16500,9 +16537,9 @@ "dev": true }, "typescript": { - "version": "3.7.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz", - "integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==" + "version": "3.7.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz", + "integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==" }, "typescript-collections": { "version": "1.3.3", @@ -16847,9 +16884,9 @@ "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" }, "uuid": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz", - "integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==" + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" }, "v8-compile-cache": { "version": "2.0.3", @@ -18236,4 +18273,4 @@ } } } -}
\ No newline at end of file +} diff --git a/package.json b/package.json index 5077e7118..dba0d84aa 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "devDependencies": { "@types/chai": "^4.2.7", "@types/mocha": "^5.2.6", - "@types/react-dom": "^16.9.4", + "@types/react-dom": "^16.9.5", "@types/webpack-dev-middleware": "^2.0.2", "@types/webpack-hot-middleware": "^2.25.0", "awesome-typescript-loader": "^5.2.1", @@ -33,8 +33,8 @@ "ts-node": "^7.0.1", "ts-node-dev": "^1.0.0-pre.44", "tslint": "^5.20.1", - "tslint-loader": "^3.5.4", - "typescript": "^3.7.4", + "tslint-loader": "^3.6.0", + "typescript": "^3.7.5", "webpack": "^4.41.5", "webpack-cli": "^3.3.10", "webpack-dev-middleware": "^3.7.2", @@ -75,11 +75,11 @@ "@types/gapi": "0.0.39", "@types/jquery": "^3.3.31", "@types/jquery-awesome-cursor": "^0.3.0", - "@types/jsonwebtoken": "^8.3.5", + "@types/jsonwebtoken": "^8.3.7", "@types/lodash": "^4.14.149", "@types/mobile-detect": "^1.3.4", "@types/mongodb": "^3.3.14", - "@types/mongoose": "^5.5.38", + "@types/mongoose": "^5.5.43", "@types/node": "^10.17.13", "@types/nodemailer": "^4.6.6", "@types/passport": "^1.0.2", @@ -99,10 +99,10 @@ "@types/prosemirror-view": "^1.11.2", "@types/pug": "^2.0.4", "@types/rc-switch": "^1.9.0", - "@types/react": "^16.9.17", + "@types/react": "^16.9.19", "@types/react-autosuggest": "^9.3.13", "@types/react-color": "^2.17.3", - "@types/react-measure": "^2.0.4", + "@types/react-measure": "^2.0.6", "@types/react-table": "^6.8.6", "@types/request": "^2.48.4", "@types/request-promise": "^4.1.45", @@ -113,7 +113,7 @@ "@types/socket.io-client": "^1.4.32", "@types/typescript": "^2.0.0", "@types/uuid": "^3.4.6", - "@types/webpack": "^4.41.1", + "@types/webpack": "^4.41.3", "@types/word-extractor": "^0.3.0", "@types/youtube": "0.0.38", "adm-zip": "^0.4.13", @@ -133,7 +133,7 @@ "connect-flash": "^0.1.1", "connect-mongo": "^2.0.3", "cookie-parser": "^1.4.4", - "cookie-session": "^2.0.0-beta.3", + "cookie-session": "^2.0.0-rc.1", "cors": "^2.8.5", "crypto-browserify": "^3.11.0", "d3-format": "^1.4.3", @@ -165,13 +165,13 @@ "jsx-to-string": "^1.4.0", "lodash": "^4.17.15", "mobile-detect": "^1.4.4", - "mobx": "^5.15.1", + "mobx": "^5.15.3", "mobx-react": "^5.3.5", "mobx-react-devtools": "^6.1.1", - "mobx-utils": "^5.5.2", - "mongodb": "^3.4.1", - "mongoose": "^5.8.4", - "node-sass": "^4.13.0", + "mobx-utils": "^5.5.3", + "mongodb": "^3.5.2", + "mongoose": "^5.8.9", + "node-sass": "^4.13.1", "node-stream-zip": "^1.9.1", "nodemailer": "^5.1.1", "nodemon": "^1.19.4", @@ -182,21 +182,21 @@ "passport-google-oauth20": "^2.0.0", "passport-local": "^1.0.0", "pdf-parse": "^1.1.1", - "pdfjs-dist": "^2.2.228", + "pdfjs-dist": "^2.3.200", "probe-image-size": "^4.0.0", "prosemirror-commands": "^1.1.3", "prosemirror-example-setup": "^1.1.2", "prosemirror-find-replace": "^0.9.0", "prosemirror-history": "^1.1.3", "prosemirror-keymap": "^1.1.3", - "prosemirror-model": "^1.8.2", + "prosemirror-model": "^1.9.1", "prosemirror-schema-basic": "^1.1.2", "prosemirror-schema-list": "^1.1.2", "prosemirror-state": "^1.3.2", "prosemirror-transform": "^1.2.3", - "prosemirror-view": "^1.13.7", + "prosemirror-view": "^1.13.8", "pug": "^2.0.3", - "query-string": "^6.9.0", + "query-string": "^6.10.1", "raw-loader": "^1.0.0", "rc-switch": "^1.9.0", "react": "^16.12.0", @@ -204,7 +204,7 @@ "react-autosuggest": "^9.4.3", "react-bootstrap": "^1.0.0-beta.16", "react-bootstrap-dropdown-menu": "^1.1.15", - "react-color": "^2.17.0", + "react-color": "^2.18.0", "react-dimensions": "^1.3.1", "react-dom": "^16.12.0", "react-golden-layout": "^1.0.6", @@ -229,7 +229,7 @@ "standard-http-error": "^2.0.1", "typescript-collections": "^1.3.3", "url-loader": "^1.1.2", - "uuid": "^3.3.3", + "uuid": "^3.4.0", "wikijs": "^6.0.1", "word-extractor": "^0.3.0", "words-to-numbers": "^1.5.1", diff --git a/solr-8.3.1/server/solr/dash/core.properties b/solr-8.3.1/server/solr/dash/core.properties index 0912a8303..70081ebc6 100644 --- a/solr-8.3.1/server/solr/dash/core.properties +++ b/solr-8.3.1/server/solr/dash/core.properties @@ -1,5 +1,5 @@ #Written by CorePropertiesLocator -#Wed Jan 08 14:44:34 UTC 2020 +#Wed Jan 29 14:30:24 UTC 2020 name=dash config=solrconfig.xml schema=schema.xml diff --git a/src/Utils.ts b/src/Utils.ts index 7bf05a6fc..4deac9035 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -48,7 +48,7 @@ export namespace Utils { } export async function getApiKey(target: string): Promise<string> { - const response = await fetch(prepend(`environment/${target.toUpperCase()}`)); + const response = await fetch(prepend(`/environment/${target.toUpperCase()}`)); return response.text(); } diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts index 966d8053a..7e5d5fe1b 100644 --- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts +++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts @@ -136,7 +136,7 @@ export namespace GooglePhotos { document.contentSize = upload.contentSize; return document; }); - const options = { width: 500, height: 500 }; + const options = { _width: 500, _height: 500 }; return constructor(children, options); }; @@ -340,7 +340,7 @@ export namespace GooglePhotos { const url = data.url.href; const target = Doc.MakeAlias(source); const description = parseDescription(target, descriptionKey); - await DocumentView.makeCustomViewClicked(target, undefined); + await DocumentView.makeCustomViewClicked(target, undefined, Docs.Create.FreeformDocument); media.push({ url, description }); } if (media.length) { diff --git a/src/client/apis/youtube/YoutubeBox.tsx b/src/client/apis/youtube/YoutubeBox.tsx index fd3d9e2f1..c940bba43 100644 --- a/src/client/apis/youtube/YoutubeBox.tsx +++ b/src/client/apis/youtube/YoutubeBox.tsx @@ -46,7 +46,7 @@ export class YoutubeBox extends React.Component<FieldViewProps> { * When component mounts, last search's results are laoded in based on the back up stored * in the document of the props. */ - async componentWillMount() { + async componentDidMount() { //DocServer.getYoutubeChannels(); const castedSearchBackUp = Cast(this.props.Document.cachedSearchResults, Doc); const awaitedBackUp = await castedSearchBackUp; @@ -337,7 +337,7 @@ export class YoutubeBox extends React.Component<FieldViewProps> { const newVideoX = NumCast(this.props.Document.x); const newVideoY = NumCast(this.props.Document.y) + NumCast(this.props.Document.height); - addFunction(Docs.Create.VideoDocument(embeddedUrl, { title: filteredTitle, width: 400, height: 315, x: newVideoX, y: newVideoY })); + addFunction(Docs.Create.VideoDocument(embeddedUrl, { title: filteredTitle, _width: 400, _height: 315, x: newVideoX, y: newVideoY })); this.videoClicked = true; } diff --git a/src/client/cognitive_services/CognitiveServices.ts b/src/client/cognitive_services/CognitiveServices.ts index 57296c961..9e2ceac62 100644 --- a/src/client/cognitive_services/CognitiveServices.ts +++ b/src/client/cognitive_services/CognitiveServices.ts @@ -185,8 +185,9 @@ export namespace CognitiveServices { results.recognitionUnits && (results = results.recognitionUnits); target[keys[0]] = Docs.Get.DocumentHierarchyFromJson(results, "Ink Analysis"); const recognizedText = results.map((item: any) => item.recognizedText); + const recognizedObjects = results.map((item: any) => item.recognizedObject); const individualWords = recognizedText.filter((text: string) => text && text.split(" ").length === 1); - target[keys[1]] = individualWords.join(" "); + target[keys[1]] = individualWords.length ? individualWords.join(" ") : recognizedObjects.join(", "); } batch.end(); diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 821185518..fa5707288 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -52,42 +52,52 @@ import { DocumentBox } from "../views/nodes/DocumentBox"; import { InkingStroke } from "../views/InkingStroke"; import { InkField } from "../../new_fields/InkField"; import { InkingControl } from "../views/InkingControl"; +import { RichTextField } from "../../new_fields/RichTextField"; const requestImageSize = require('../util/request-image-size'); const path = require('path'); export interface DocumentOptions { + _autoHeight?: boolean; + _panX?: number; + _panY?: number; + _width?: number; + _height?: number; + _nativeWidth?: number; + _nativeHeight?: number; + _fitWidth?: boolean; + _fitToBox?: boolean; // whether a freeformview should zoom/scale to create a shrinkwrapped view of its contents + _LODdisable?: boolean; + _dropAction?: dropActionType; + _chromeStatus?: string; + _viewType?: number; + _gridGap?: number; // gap between items in masonry view + _xMargin?: number; // gap between left edge of document and start of masonry/stacking layouts + _yMargin?: number; // gap between top edge of dcoument and start of masonry/stacking layouts + _textTemplate?: RichTextField; // template used by a formattedTextBox to create a text box to render + _itemIndex?: number; // which item index the carousel viewer is showing + _hideSidebar?: boolean; //whether an annotationsidebar should be displayed for text docuemnts x?: number; y?: number; z?: number; + layoutKey?: string; type?: string; - width?: number; - height?: number; - nativeWidth?: number; - nativeHeight?: number; title?: string; - panX?: number; - panY?: number; page?: number; scale?: number; - fitWidth?: boolean; - fitToBox?: boolean; // whether a freeformview should zoom/scale to create a shrinkwrapped view of its contents isDisplayPanel?: boolean; // whether the panel functions as GoldenLayout "stack" used to display documents forceActive?: boolean; preventTreeViewOpen?: boolean; // ignores the treeViewOpen Doc flag which allows a treeViewItem's expande/collapse state to be independent of other views of the same document in the tree view layout?: string | Doc; hideHeadings?: boolean; // whether stacking view column headings should be hidden - isTemplateField?: boolean; + isTemplateForField?: string; // the field key for which the containing document is a rendering template isTemplateDoc?: boolean; templates?: List<string>; - viewType?: number; backgroundColor?: string | ScriptField; ignoreClick?: boolean; lockedPosition?: boolean; // lock the x,y coordinates of the document so that it can't be dragged lockedTransform?: boolean; // lock the panx,pany and scale parameters of the document so that it be panned/zoomed opacity?: number; defaultBackgroundColor?: string; - dropAction?: dropActionType; - chromeStatus?: string; columnWidth?: number; fontSize?: number; curPage?: number; @@ -99,22 +109,19 @@ export interface DocumentOptions { sectionFilter?: string; // field key used to determine headings for sections in stacking and masonry views schemaColumns?: List<SchemaHeaderField>; dockingConfig?: string; - autoHeight?: boolean; annotationOn?: Doc; removeDropProperties?: List<string>; // list of properties that should be removed from a document when it is dropped. e.g., a creator button may be forceActive to allow it be dragged, but the forceActive property can be removed from the dropped document dbDoc?: Doc; ischecked?: ScriptField; // returns whether a font icon box is checked activePen?: Doc; // which pen document is currently active (used as the radio button state for the 'unhecked' pen tool scripts) onClick?: ScriptField; + onChildClick?: ScriptField; // script given to children of a collection to execute when they are clicked onPointerDown?: ScriptField; onPointerUp?: ScriptField; dragFactory?: Doc; // document to create when dragging with a suitable onDragStart script onDragStart?: ScriptField; //script to execute at start of drag operation -- e.g., when a "creator" button is dragged this script generates a different document to drop clipboard?: Doc; //script to execute at start of drag operation -- e.g., when a "creator" button is dragged this script generates a different document to drop icon?: string; - gridGap?: number; // gap between items in masonry view - xMargin?: number; // gap between left edge of document and start of masonry/stacking layouts - yMargin?: number; // gap between top edge of dcoument and start of masonry/stacking layouts sourcePanel?: Doc; // panel to display in 'targetContainer' as the result of a button onClick script targetContainer?: Doc; // document whose proto will be set to 'panel' as the result of a onClick click script dropConverter?: ScriptField; // script to run when documents are dropped on this Document. @@ -122,6 +129,7 @@ export interface DocumentOptions { color?: string; treeViewHideTitle?: boolean; // whether to hide the title of a tree view treeViewOpen?: boolean; // whether this document is expanded in a tree view + treeViewChecked?: ScriptField; // script to call when a tree view checkbox is checked isFacetFilter?: boolean; // whether document functions as a facet filter in a tree view limitHeight?: number; // maximum height for newly created (eg, from pasting) text documents // [key: string]: Opt<Field>; @@ -156,19 +164,19 @@ export namespace Docs { const TemplateMap: TemplateMap = new Map([ [DocumentType.TEXT, { layout: { view: FormattedTextBox, dataField: data }, - options: { height: 150, backgroundColor: "#f1efeb", defaultBackgroundColor: "#f1efeb" } + options: { _height: 150, backgroundColor: "#f1efeb", defaultBackgroundColor: "#f1efeb" } }], [DocumentType.HIST, { layout: { view: HistogramBox, dataField: data }, - options: { height: 300, backgroundColor: "black" } + options: { _height: 300, backgroundColor: "black" } }], [DocumentType.QUERY, { layout: { view: QueryBox, dataField: data }, - options: { width: 400 } + options: { _width: 400 } }], [DocumentType.COLOR, { layout: { view: ColorBox, dataField: data }, - options: { nativeWidth: 220, nativeHeight: 300 } + options: { _nativeWidth: 220, _nativeHeight: 300 } }], [DocumentType.IMG, { layout: { view: ImageBox, dataField: data }, @@ -176,19 +184,19 @@ export namespace Docs { }], [DocumentType.WEB, { layout: { view: WebBox, dataField: data }, - options: { height: 300 } + options: { _height: 300 } }], [DocumentType.COL, { layout: { view: CollectionView, dataField: data }, - options: { panX: 0, panY: 0, scale: 1, width: 500, height: 500 } + options: { _panX: 0, _panY: 0, scale: 1, _width: 500, _height: 500 } }], [DocumentType.KVP, { layout: { view: KeyValueBox, dataField: data }, - options: { height: 150 } + options: { _height: 150 } }], [DocumentType.DOCUMENT, { layout: { view: DocumentBox, dataField: data }, - options: { height: 250 } + options: { _height: 250 } }], [DocumentType.VID, { layout: { view: VideoBox, dataField: data }, @@ -196,7 +204,7 @@ export namespace Docs { }], [DocumentType.AUDIO, { layout: { view: AudioBox, dataField: data }, - options: { height: 35, backgroundColor: "lightGray" } + options: { _height: 35, backgroundColor: "lightGray" } }], [DocumentType.PDF, { layout: { view: PDFBox, dataField: data }, @@ -204,11 +212,11 @@ export namespace Docs { }], [DocumentType.ICON, { layout: { view: IconBox, dataField: data }, - options: { width: Number(MINIMIZED_ICON_SIZE), height: Number(MINIMIZED_ICON_SIZE) }, + options: { _width: Number(MINIMIZED_ICON_SIZE), _height: Number(MINIMIZED_ICON_SIZE) }, }], [DocumentType.IMPORT, { layout: { view: DirectoryImportBox, dataField: data }, - options: { height: 150 } + options: { _height: 150 } }], [DocumentType.LINKDOC, { data: new List<Doc>(), @@ -226,7 +234,7 @@ export namespace Docs { }], [DocumentType.FONTICON, { layout: { view: FontIconBox, dataField: data }, - options: { width: 40, height: 40, borderRounding: "100%" }, + options: { _width: 40, _height: 40, borderRounding: "100%" }, }], [DocumentType.LINKFOLLOW, { layout: { view: LinkFollowBox, dataField: data } @@ -241,7 +249,7 @@ export namespace Docs { ]); // All document prototypes are initialized with at least these values - const defaultOptions: DocumentOptions = { x: 0, y: 0, width: 300 }; + const defaultOptions: DocumentOptions = { x: 0, y: 0, _width: 300 }; const suffix = "Proto"; /** @@ -319,7 +327,8 @@ export namespace Docs { // whatever options pertain to this specific prototype const options = { title, type, baseProto: true, ...defaultOptions, ...(template.options || {}) }; options.layout = layout.view.LayoutString(layout.dataField); - return Doc.assign(new Doc(prototypeId, true), { ...options }); + const doc = Doc.assign(new Doc(prototypeId, true), { layoutKey: "layout", ...options }); + return doc; } } @@ -330,7 +339,8 @@ export namespace Docs { */ export namespace Create { - const delegateKeys = ["x", "y", "width", "height", "panX", "panY", "nativeWidth", "nativeHeight", "dropAction", "annotationOn", "forceActive", "fitWidth"]; + const delegateKeys = ["x", "y", "layoutKey", "_width", "_height", "_panX", "_panY", "_viewType", "_nativeWidth", "_nativeHeight", "_dropAction", "_annotationOn", + "_chromeStatus", "_forceActive", "_autoHeight", "_fitWidth", "_LODdisable", "_itemIndex", "_hideSidebar"]; /** * This function receives the relevant document prototype and uses @@ -400,11 +410,11 @@ export namespace Docs { requestImageSize(target) .then((size: any) => { const aspect = size.height / size.width; - if (!inst.nativeWidth) { - inst.nativeWidth = size.width; + if (!inst._nativeWidth) { + inst._nativeWidth = size.width; } - inst.nativeHeight = NumCast(inst.nativeWidth) * aspect; - inst.height = NumCast(inst.width) * aspect; + inst._nativeHeight = NumCast(inst._nativeWidth) * aspect; + inst._height = NumCast(inst._width) * aspect; }) .catch((err: any) => console.log(err)); // } @@ -438,8 +448,8 @@ export namespace Docs { return InstanceFromProto(Prototypes.get(DocumentType.COLOR), "", options); } - export function TextDocument(options: DocumentOptions = {}) { - return InstanceFromProto(Prototypes.get(DocumentType.TEXT), "", options); + export function TextDocument(text: string, options: DocumentOptions = {}) { + return InstanceFromProto(Prototypes.get(DocumentType.TEXT), text, options); } export function InkDocument(color: string, tool: number, strokeWidth: number, points: { X: number, Y: number }[], options: DocumentOptions = {}) { @@ -463,7 +473,7 @@ export namespace Docs { const ctlog = await Gateway.Instance.GetSchema(url, schemaName); if (ctlog && ctlog.schemas) { const schema = ctlog.schemas[0]; - const schemaDoc = Docs.Create.TreeDocument([], { ...options, nativeWidth: undefined, nativeHeight: undefined, width: 150, height: 100, title: schema.displayName! }); + const schemaDoc = Docs.Create.TreeDocument([], { ...options, _nativeWidth: undefined, _nativeHeight: undefined, _width: 150, _height: 100, title: schema.displayName! }); const schemaDocuments = Cast(schemaDoc.data, listSpec(Doc), []); if (!schemaDocuments) { return; @@ -480,13 +490,13 @@ export namespace Docs { new AttributeTransformationModel(atmod, AggregateFunction.None), new AttributeTransformationModel(atmod, AggregateFunction.Count), new AttributeTransformationModel(atmod, AggregateFunction.Count)); - docs.push(Docs.Create.HistogramDocument(histoOp, { ...columnOptions, width: 200, height: 200, title: attr.displayName! })); + docs.push(Docs.Create.HistogramDocument(histoOp, { ...columnOptions, _width: 200, _height: 200, title: attr.displayName! })); } })); }); return schemaDoc; } - return Docs.Create.TreeDocument([], { width: 50, height: 100, title: schemaName }); + return Docs.Create.TreeDocument([], { _width: 50, _height: 100, title: schemaName }); } export function WebDocument(url: string, options: DocumentOptions = {}) { @@ -506,31 +516,35 @@ export namespace Docs { } export function FreeformDocument(documents: Array<Doc>, options: DocumentOptions, id?: string) { - return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, viewType: CollectionViewType.Freeform }, id); + return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { _chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, _viewType: CollectionViewType.Freeform }, id); } export function LinearDocument(documents: Array<Doc>, options: DocumentOptions, id?: string) { - return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { chromeStatus: "collapsed", backgroundColor: "black", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, viewType: CollectionViewType.Linear }, id); + return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { _chromeStatus: "collapsed", backgroundColor: "black", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, _viewType: CollectionViewType.Linear }, id); + } + + export function CarouselDocument(documents: Array<Doc>, options: DocumentOptions) { + return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { _chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, _viewType: CollectionViewType.Carousel }); } export function SchemaDocument(schemaColumns: SchemaHeaderField[], documents: Array<Doc>, options: DocumentOptions) { - return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { chromeStatus: "collapsed", schemaColumns: new List(schemaColumns), ...options, viewType: CollectionViewType.Schema }); + return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { _chromeStatus: "collapsed", schemaColumns: new List(schemaColumns), ...options, _viewType: CollectionViewType.Schema }); } export function TreeDocument(documents: Array<Doc>, options: DocumentOptions) { - return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, viewType: CollectionViewType.Tree }); + return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { _chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, _viewType: CollectionViewType.Tree }); } export function StackingDocument(documents: Array<Doc>, options: DocumentOptions) { - return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, viewType: CollectionViewType.Stacking }); + return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { _chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, _viewType: CollectionViewType.Stacking }); } export function MulticolumnDocument(documents: Array<Doc>, options: DocumentOptions) { - return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, viewType: CollectionViewType.Multicolumn }); + return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { _chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, _viewType: CollectionViewType.Multicolumn }); } export function MasonryDocument(documents: Array<Doc>, options: DocumentOptions) { - return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, viewType: CollectionViewType.Masonry }); + return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { _chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, _viewType: CollectionViewType.Masonry }); } export function ButtonDocument(options?: DocumentOptions) { @@ -551,7 +565,7 @@ export namespace Docs { } export function DockDocument(documents: Array<Doc>, config: string, options: DocumentOptions, id?: string) { - const inst = InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { ...options, viewType: CollectionViewType.Docking, dockingConfig: config }, id); + const inst = InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { ...options, _viewType: CollectionViewType.Docking, dockingConfig: config }, id); Doc.GetProto(inst).data = new List<Doc>(documents); return inst; } @@ -673,37 +687,38 @@ export namespace Docs { const field = target[fieldKey]; const resolved = options || {}; if (field instanceof ImageField) { - created = Docs.Create.ImageDocument((field as ImageField).url.href, resolved); + created = Docs.Create.ImageDocument((field).url.href, resolved); layout = ImageBox.LayoutString; } else if (field instanceof Doc) { created = field; } else if (field instanceof VideoField) { - created = Docs.Create.VideoDocument((field as VideoField).url.href, resolved); + created = Docs.Create.VideoDocument((field).url.href, resolved); layout = VideoBox.LayoutString; } else if (field instanceof PdfField) { - created = Docs.Create.PdfDocument((field as PdfField).url.href, resolved); + created = Docs.Create.PdfDocument((field).url.href, resolved); layout = PDFBox.LayoutString; } else if (field instanceof IconField) { - created = Docs.Create.IconDocument((field as IconField).icon, resolved); + created = Docs.Create.IconDocument((field).icon, resolved); layout = IconBox.LayoutString; } else if (field instanceof AudioField) { - created = Docs.Create.AudioDocument((field as AudioField).url.href, resolved); + created = Docs.Create.AudioDocument((field).url.href, resolved); layout = AudioBox.LayoutString; } else if (field instanceof HistogramField) { - created = Docs.Create.HistogramDocument((field as HistogramField).HistoOp, resolved); + created = Docs.Create.HistogramDocument((field).HistoOp, resolved); layout = HistogramBox.LayoutString; } else if (field instanceof InkField) { const { selectedColor, selectedWidth, selectedTool } = InkingControl.Instance; - created = Docs.Create.InkDocument(selectedColor, selectedTool, Number(selectedWidth), (field as InkField).inkData, resolved); + created = Docs.Create.InkDocument(selectedColor, selectedTool, Number(selectedWidth), (field).inkData, resolved); layout = InkingStroke.LayoutString; } else if (field instanceof List && field[0] instanceof Doc) { created = Docs.Create.StackingDocument(DocListCast(field), resolved); layout = CollectionView.LayoutString; } else { - created = Docs.Create.TextDocument({ ...{ width: 200, height: 25, autoHeight: true }, ...resolved }); + created = Docs.Create.TextDocument("", { ...{ _width: 200, _height: 25, _autoHeight: true }, ...resolved }); layout = FormattedTextBox.LayoutString; } created.layout = layout?.(fieldKey); + created.title = fieldKey; proto && (created.proto = Doc.GetProto(proto)); return created; } @@ -712,24 +727,24 @@ export namespace Docs { let ctor: ((path: string, options: DocumentOptions) => (Doc | Promise<Doc | undefined>)) | undefined = undefined; if (type.indexOf("image") !== -1) { ctor = Docs.Create.ImageDocument; - if (!options.width) options.width = 300; + if (!options._width) options._width = 300; } if (type.indexOf("video") !== -1) { ctor = Docs.Create.VideoDocument; - if (!options.width) options.width = 600; - if (!options.height) options.height = options.width * 2 / 3; + if (!options._width) options._width = 600; + if (!options._height) options._height = options._width * 2 / 3; } if (type.indexOf("audio") !== -1) { ctor = Docs.Create.AudioDocument; } if (type.indexOf("pdf") !== -1) { ctor = Docs.Create.PdfDocument; - if (!options.width) options.width = 400; - if (!options.height) options.height = options.width * 1200 / 927; + if (!options._width) options._width = 400; + if (!options._height) options._height = options._width * 1200 / 927; } if (type.indexOf("excel") !== -1) { ctor = Docs.Create.DBDocument; - options.dropAction = "copy"; + options._dropAction = "copy"; } if (type.indexOf("html") !== -1) { if (path.includes(window.location.hostname)) { @@ -740,15 +755,15 @@ export namespace Docs { const alias = Doc.MakeAlias(field); alias.x = options.x || 0; alias.y = options.y || 0; - alias.width = options.width || 300; - alias.height = options.height || options.width || 300; + alias._width = options._width || 300; + alias._height = options._height || options._width || 300; return alias; } return undefined; }); } ctor = Docs.Create.WebDocument; - options = { height: options.width, ...options, title: path, nativeWidth: undefined }; + options = { _height: options._width, ...options, title: path, _nativeWidth: undefined }; } return ctor ? ctor(path, options) : undefined; } @@ -788,7 +803,6 @@ export namespace DocUtils { }); } - @undoBatch export function MakeLink(source: { doc: Doc, ctx?: Doc }, target: { doc: Doc, ctx?: Doc }, title: string = "", description: string = "", id?: string) { const sv = DocumentManager.Instance.getDocumentView(source.doc); if (sv && sv.props.ContainingCollectionDoc === target.doc) return; @@ -810,8 +824,8 @@ export namespace DocUtils { linkDocProto.anchor2Groups = new List<Doc>([]); linkDocProto.anchor1Timecode = source.doc.currentTimecode; linkDocProto.anchor2Timecode = target.doc.currentTimecode; - linkDocProto.layoutKey1 = DocuLinkBox.LayoutString("anchor1"); - linkDocProto.layoutKey2 = DocuLinkBox.LayoutString("anchor2"); + linkDocProto.layout_key1 = DocuLinkBox.LayoutString("anchor1"); + linkDocProto.layout_key2 = DocuLinkBox.LayoutString("anchor2"); linkDocProto.width = linkDocProto.height = 0; linkDocProto.isBackground = true; linkDocProto.isButton = true; diff --git a/src/client/northstar/dash-fields/HistogramField.ts b/src/client/northstar/dash-fields/HistogramField.ts index f3365e73d..076516977 100644 --- a/src/client/northstar/dash-fields/HistogramField.ts +++ b/src/client/northstar/dash-fields/HistogramField.ts @@ -7,7 +7,7 @@ import { ObjectField } from "../../../new_fields/ObjectField"; import { CurrentUserUtils } from "../../../server/authentication/models/current_user_utils"; import { OmitKeys } from "../../../Utils"; import { Deserializable } from "../../util/SerializationHelper"; -import { Copy, ToScriptString } from "../../../new_fields/FieldSymbols"; +import { Copy, ToScriptString, ToString } from "../../../new_fields/FieldSymbols"; function serialize(field: HistogramField) { const obj = OmitKeys(field, ['Links', 'BrushLinks', 'Result', 'BrushColors', 'FilterModels', 'FilterOperand']).omit; @@ -60,4 +60,7 @@ export class HistogramField extends ObjectField { [ToScriptString]() { return this.toString(); } + [ToString]() { + return this.toString(); + } }
\ No newline at end of file diff --git a/src/client/util/DictationManager.ts b/src/client/util/DictationManager.ts index 3d8f2d234..3394cb93d 100644 --- a/src/client/util/DictationManager.ts +++ b/src/client/util/DictationManager.ts @@ -325,15 +325,14 @@ export namespace DictationManager { ["open fields", { action: (target: DocumentView) => { - const kvp = Docs.Create.KVPDocument(target.props.Document, { width: 300, height: 300 }); + const kvp = Docs.Create.KVPDocument(target.props.Document, { _width: 300, _height: 300 }); target.props.addDocTab(kvp, target.props.DataDoc, "onRight"); } }], ["new outline", { action: (target: DocumentView) => { - const newBox = Docs.Create.TextDocument({ width: 400, height: 200, title: "My Outline" }); - newBox.autoHeight = true; + const newBox = Docs.Create.TextDocument("", { _width: 400, _height: 200, title: "My Outline", _autoHeight: true }); const proto = newBox.proto!; const prompt = "Press alt + r to start dictating here..."; const head = 3; @@ -379,7 +378,7 @@ export namespace DictationManager { expression: /view as (freeform|stacking|masonry|schema|tree)/g, action: (target: DocumentView, matches: RegExpExecArray) => { const mode = CollectionViewType.valueOf(matches[1]); - mode && (target.props.Document.viewType = mode); + mode && (target.props.Document._viewType = mode); }, restrictTo: [DocumentType.COL] } diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts index df2f5fe3c..c05a2de96 100644 --- a/src/client/util/DragManager.ts +++ b/src/client/util/DragManager.ts @@ -94,6 +94,7 @@ export namespace DragManager { readonly x: number, readonly y: number, readonly complete: DragCompleteEvent, + readonly shiftKey: boolean, readonly altKey: boolean, readonly metaKey: boolean, readonly ctrlKey: boolean @@ -205,7 +206,7 @@ export namespace DragManager { // drag a button template and drop a new button export function StartButtonDrag(eles: HTMLElement[], script: string, title: string, vars: { [name: string]: Field }, params: string[], initialize: (button: Doc) => void, downX: number, downY: number, options?: DragOptions) { const finishDrag = (e: DragCompleteEvent) => { - const bd = Docs.Create.ButtonDocument({ width: 150, height: 50, title: title }); + const bd = Docs.Create.ButtonDocument({ _width: 150, _height: 50, title: title }); bd.onClick = ScriptField.MakeScript(script); params.map(p => Object.keys(vars).indexOf(p) !== -1 && (Doc.GetProto(bd)[p] = new PrefetchProxy(vars[p] as Doc))); initialize && initialize(bd); @@ -340,7 +341,7 @@ export namespace DragManager { if (dragData instanceof DocumentDragData) { dragData.userDropAction = e.ctrlKey ? "alias" : undefined; } - if (e.shiftKey && CollectionDockingView.Instance) { + if (e.shiftKey && CollectionDockingView.Instance && dragData.droppedDocuments.length === 1) { AbortDrag(); finishDrag?.(new DragCompleteEvent(true, dragData)); CollectionDockingView.Instance.StartOtherDrag({ @@ -409,6 +410,7 @@ export namespace DragManager { x: e.x, y: e.y, complete: complete, + shiftKey: e.shiftKey, altKey: e.altKey, metaKey: e.metaKey, ctrlKey: e.ctrlKey diff --git a/src/client/util/DropConverter.ts b/src/client/util/DropConverter.ts index ff0e19347..d0f1d86cb 100644 --- a/src/client/util/DropConverter.ts +++ b/src/client/util/DropConverter.ts @@ -1,26 +1,31 @@ import { DragManager } from "./DragManager"; -import { CollectionViewType } from "../views/collections/CollectionView"; import { Doc, DocListCast } from "../../new_fields/Doc"; import { DocumentType } from "../documents/DocumentTypes"; import { ObjectField } from "../../new_fields/ObjectField"; import { StrCast } from "../../new_fields/Types"; import { Docs } from "../documents/Documents"; -import { ScriptField } from "../../new_fields/ScriptField"; +import { ScriptField, ComputedField } from "../../new_fields/ScriptField"; +import { RichTextField } from "../../new_fields/RichTextField"; +import { ImageField } from "../../new_fields/URLField"; -export function makeTemplate(doc: Doc, suppressTitle = false): boolean { - const layoutDoc = doc.layout instanceof Doc && doc.layout.isTemplateField ? doc.layout : doc; +export function makeTemplate(doc: Doc): boolean { + const layoutDoc = doc.layout instanceof Doc && doc.layout.isTemplateForField ? doc.layout : doc; const layout = StrCast(layoutDoc.layout).match(/fieldKey={'[^']*'}/)![0]; const fieldKey = layout.replace("fieldKey={'", "").replace(/'}$/, ""); const docs = DocListCast(layoutDoc[fieldKey]); let any = false; docs.forEach(d => { if (!StrCast(d.title).startsWith("-")) { - any = true; - Doc.MakeMetadataFieldTemplate(d, Doc.GetProto(layoutDoc), suppressTitle); - } else if (d.type === DocumentType.COL) { + any = Doc.MakeMetadataFieldTemplate(d, Doc.GetProto(layoutDoc)) || any; + } else if (d.type === DocumentType.COL || d.data instanceof RichTextField) { any = makeTemplate(d) || any; } }); + if (layoutDoc[fieldKey] instanceof RichTextField || layoutDoc[fieldKey] instanceof ImageField) { + if (!StrCast(layoutDoc.title).startsWith("-")) { + any = Doc.MakeMetadataFieldTemplate(layoutDoc, Doc.GetProto(layoutDoc)); + } + } return any; } export function convertDropDataToButtons(data: DragManager.DocumentDragData) { @@ -28,13 +33,14 @@ export function convertDropDataToButtons(data: DragManager.DocumentDragData) { let dbox = doc; // bcz: isButtonBar is intended to allow a collection of linear buttons to be dropped and nested into another collection of buttons... it's not being used yet, and isn't very elegant if (!doc.onDragStart && !doc.onClick && !doc.isButtonBar) { - const layoutDoc = doc.layout instanceof Doc && doc.layout.isTemplateField ? doc.layout : doc; - if (layoutDoc.type === DocumentType.COL) { - layoutDoc.isTemplateDoc = makeTemplate(layoutDoc); + const layoutDoc = doc.layout instanceof Doc && doc.layout.isTemplateForField ? doc.layout : doc; + if (layoutDoc.type === DocumentType.COL || layoutDoc.type === DocumentType.TEXT || layoutDoc.type === DocumentType.IMG) { + makeTemplate(layoutDoc); } else { - layoutDoc.isTemplateDoc = (layoutDoc.type === DocumentType.TEXT || layoutDoc.layout instanceof Doc) && !data.userDropAction; + (layoutDoc.layout instanceof Doc) && !data.userDropAction; } - dbox = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, backgroundColor: StrCast(doc.backgroundColor), title: "Custom", icon: layoutDoc.isTemplateDoc ? "font" : "bolt" }); + layoutDoc.isTemplateDoc = true; + dbox = Docs.Create.FontIconDocument({ _nativeWidth: 100, _nativeHeight: 100, _width: 100, _height: 100, backgroundColor: StrCast(doc.backgroundColor), title: "Custom", icon: layoutDoc.isTemplateDoc ? "font" : "bolt" }); dbox.dragFactory = layoutDoc; dbox.removeDropProperties = doc.removeDropProperties instanceof ObjectField ? ObjectField.MakeCopy(doc.removeDropProperties) : undefined; dbox.onDragStart = ScriptField.MakeFunction('getCopy(this.dragFactory, true)'); diff --git a/src/client/util/Import & Export/DirectoryImportBox.tsx b/src/client/util/Import & Export/DirectoryImportBox.tsx index 5b5bffd8c..071015193 100644 --- a/src/client/util/Import & Export/DirectoryImportBox.tsx +++ b/src/client/util/Import & Export/DirectoryImportBox.tsx @@ -116,13 +116,13 @@ export default class DirectoryImportBox extends React.Component<FieldViewProps> formData.append(Utils.GenerateGuid(), file); }); - collector.push(...(await Networking.PostFormDataToServer("/upload", formData))); + collector.push(...(await Networking.PostFormDataToServer("/uploadFormData", formData))); runInAction(() => this.completed += batch.length); }); await Promise.all(uploads.map(async ({ name, type, clientAccessPath, exifData }) => { const path = Utils.prepend(clientAccessPath); - const document = await Docs.Get.DocumentFromType(type, path, { width: 300, title: name }); + const document = await Docs.Get.DocumentFromType(type, path, { _width: 300, title: name }); const { data, error } = exifData; if (document) { Doc.GetProto(document).exif = error || Docs.Get.DocumentHierarchyFromJson(data); @@ -145,8 +145,8 @@ export default class DirectoryImportBox extends React.Component<FieldViewProps> const offset: number = this.persistent ? (height === 0 ? 0 : height + 30) : 0; const options: DocumentOptions = { title: `Import of ${directory}`, - width: 1105, - height: 500, + _width: 1105, + _height: 500, x: NumCast(doc.x), y: NumCast(doc.y) + offset }; diff --git a/src/client/util/Import & Export/ImageUtils.ts b/src/client/util/Import & Export/ImageUtils.ts index 6a9486f83..ff909cc6b 100644 --- a/src/client/util/Import & Export/ImageUtils.ts +++ b/src/client/util/Import & Export/ImageUtils.ts @@ -14,9 +14,17 @@ export namespace ImageUtils { return false; } const source = field.url.href; - const response = await Networking.PostToServer("/inspectImage", { source }); - const { error, data } = response.exifData; + const { + contentSize, + nativeWidth, + nativeHeight, + exifData: { error, data } + } = await Networking.PostToServer("/inspectImage", { source }); document.exif = error || Docs.Get.DocumentHierarchyFromJson(data); + const proto = Doc.GetProto(document); + proto["data-nativeWidth"] = nativeWidth; + proto["data-nativeHeight"] = nativeHeight; + proto.contentSize = contentSize; return data !== undefined; }; diff --git a/src/client/util/ProseMirrorEditorView.tsx b/src/client/util/ProseMirrorEditorView.tsx deleted file mode 100644 index b42adfbb4..000000000 --- a/src/client/util/ProseMirrorEditorView.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import React from "react"; -import { EditorView } from "prosemirror-view"; -import { EditorState } from "prosemirror-state"; - -export interface ProseMirrorEditorViewProps { - /* EditorState instance to use. */ - editorState: EditorState; - /* Called when EditorView produces new EditorState. */ - onEditorState: (editorState: EditorState) => any; -} - -/** - * This wraps ProseMirror's EditorView into React component. - * This code was found on https://discuss.prosemirror.net/t/using-with-react/904 - */ -export class ProseMirrorEditorView extends React.Component<ProseMirrorEditorViewProps> { - - private _editorView?: EditorView; - - _createEditorView = (element: HTMLDivElement | null) => { - if (element !== null) { - this._editorView = new EditorView(element, { - state: this.props.editorState, - dispatchTransaction: this.dispatchTransaction, - }); - } - } - - dispatchTransaction = (tx: any) => { - // In case EditorView makes any modification to a state we funnel those - // modifications up to the parent and apply to the EditorView itself. - const editorState = this.props.editorState.apply(tx); - if (this._editorView) { - this._editorView.updateState(editorState); - } - this.props.onEditorState(editorState); - } - - focus() { - if (this._editorView) { - this._editorView.focus(); - } - } - - componentWillReceiveProps(nextProps: { editorState: EditorState<any>; }) { - // In case we receive new EditorState through props — we apply it to the - // EditorView instance. - if (this._editorView) { - if (nextProps.editorState !== this.props.editorState) { - this._editorView.updateState(nextProps.editorState); - } - } - } - - componentWillUnmount() { - if (this._editorView) { - this._editorView.destroy(); - } - } - - shouldComponentUpdate() { - // Note that EditorView manages its DOM itself so we'd ratrher don't mess - // with it. - return false; - } - - render() { - // Render just an empty div which is then used as a container for an - // EditorView instance. - return ( - <div ref={this._createEditorView} /> - ); - } -}
\ No newline at end of file diff --git a/src/client/util/ProsemirrorExampleTransfer.ts b/src/client/util/ProsemirrorExampleTransfer.ts index c028dbf8b..da3815181 100644 --- a/src/client/util/ProsemirrorExampleTransfer.ts +++ b/src/client/util/ProsemirrorExampleTransfer.ts @@ -5,9 +5,7 @@ import { Schema } from "prosemirror-model"; import { liftListItem, sinkListItem } from "./prosemirrorPatches.js"; import { splitListItem, wrapInList, } from "prosemirror-schema-list"; import { EditorState, Transaction, TextSelection } from "prosemirror-state"; -import { TooltipTextMenu } from "./TooltipTextMenu"; import { SelectionManager } from "./SelectionManager"; -import { FormattedTextBox } from "../views/nodes/FormattedTextBox"; const mac = typeof navigator !== "undefined" ? /Mac/.test(navigator.platform) : false; diff --git a/src/client/util/RichTextMenu.tsx b/src/client/util/RichTextMenu.tsx index 419d7caf9..e07efe056 100644 --- a/src/client/util/RichTextMenu.tsx +++ b/src/client/util/RichTextMenu.tsx @@ -32,8 +32,9 @@ export default class RichTextMenu extends AntimodeMenu { public overMenu: boolean = false; // kind of hacky way to prevent selects not being selectable private view?: EditorView; - private editorProps: FieldViewProps & FormattedTextBoxProps | undefined; + public editorProps: FieldViewProps & FormattedTextBoxProps | undefined; + public _brushMap: Map<string, Set<Mark>> = new Map(); private fontSizeOptions: { mark: Mark | null, title: string, label: string, command: any, hidden?: boolean, style?: {} }[]; private fontFamilyOptions: { mark: Mark | null, title: string, label: string, command: any, hidden?: boolean, style?: {} }[]; private listTypeOptions: { node: NodeType | any | null, title: string, label: string, command: any, style?: {} }[]; @@ -72,7 +73,7 @@ export default class RichTextMenu extends AntimodeMenu { this.fontSizeOptions = [ { mark: schema.marks.pFontSize.create({ fontSize: 7 }), title: "Set font size", label: "7pt", command: this.changeFontSize }, { mark: schema.marks.pFontSize.create({ fontSize: 8 }), title: "Set font size", label: "8pt", command: this.changeFontSize }, - { mark: schema.marks.pFontSize.create({ fontSize: 9 }), title: "Set font size", label: "8pt", command: this.changeFontSize }, + { mark: schema.marks.pFontSize.create({ fontSize: 9 }), title: "Set font size", label: "9pt", command: this.changeFontSize }, { mark: schema.marks.pFontSize.create({ fontSize: 10 }), title: "Set font size", label: "10pt", command: this.changeFontSize }, { mark: schema.marks.pFontSize.create({ fontSize: 12 }), title: "Set font size", label: "12pt", command: this.changeFontSize }, { mark: schema.marks.pFontSize.create({ fontSize: 14 }), title: "Set font size", label: "14pt", command: this.changeFontSize }, @@ -142,6 +143,17 @@ export default class RichTextMenu extends AntimodeMenu { this.updateFromDash(view, lastState, this.editorProps); } + + public MakeLinkToSelection = (linkDocId: string, title: string, location: string, targetDocId: string): string => { + if (this.view) { + const link = this.view.state.schema.marks.link.create({ href: Utils.prepend("/doc/" + linkDocId), title: title, location: location, targetId: targetDocId }); + this.view.dispatch(this.view.state.tr.removeMark(this.view.state.selection.from, this.view.state.selection.to, this.view.state.schema.marks.link). + addMark(this.view.state.selection.from, this.view.state.selection.to, link)); + return this.view.state.selection.$from.nodeAfter?.text || ""; + } + return ""; + } + @action public async updateFromDash(view: EditorView, lastState: EditorState | undefined, props: any) { if (!view) { @@ -300,22 +312,22 @@ export default class RichTextMenu extends AntimodeMenu { } return ( - <button className={"antimodeMenu-button" + (isActive ? " active" : "")} title={title} onPointerDown={onClick}> + <button className={"antimodeMenu-button" + (isActive ? " active" : "")} key={title} title={title} onPointerDown={onClick}> <FontAwesomeIcon icon={faIcon as IconProp} size="lg" /> </button> ); } - createMarksDropdown(activeOption: string, options: { mark: Mark | null, title: string, label: string, command: (mark: Mark, view: EditorView) => void, hidden?: boolean, style?: {} }[]): JSX.Element { + createMarksDropdown(activeOption: string, options: { mark: Mark | null, title: string, label: string, command: (mark: Mark, view: EditorView) => void, hidden?: boolean, style?: {} }[], key: string): JSX.Element { const items = options.map(({ title, label, hidden, style }) => { if (hidden) { return label === activeOption ? - <option value={label} title={title} style={style ? style : {}} selected hidden>{label}</option> : - <option value={label} title={title} style={style ? style : {}} hidden>{label}</option>; + <option value={label} title={title} key={label} style={style ? style : {}} selected hidden>{label}</option> : + <option value={label} title={title} key={label} style={style ? style : {}} hidden>{label}</option>; } return label === activeOption ? - <option value={label} title={title} style={style ? style : {}} selected>{label}</option> : - <option value={label} title={title} style={style ? style : {}}>{label}</option>; + <option value={label} title={title} key={label} style={style ? style : {}} selected>{label}</option> : + <option value={label} title={title} key={label} style={style ? style : {}}>{label}</option>; }); const self = this; @@ -328,19 +340,19 @@ export default class RichTextMenu extends AntimodeMenu { } }); } - return <select onChange={onChange}>{items}</select>; + return <select onChange={onChange} key={key}>{items}</select>; } - createNodesDropdown(activeOption: string, options: { node: NodeType | any | null, title: string, label: string, command: (node: NodeType | any) => void, hidden?: boolean, style?: {} }[]): JSX.Element { + createNodesDropdown(activeOption: string, options: { node: NodeType | any | null, title: string, label: string, command: (node: NodeType | any) => void, hidden?: boolean, style?: {} }[], key: string): JSX.Element { const items = options.map(({ title, label, hidden, style }) => { if (hidden) { return label === activeOption ? - <option value={label} title={title} style={style ? style : {}} selected hidden>{label}</option> : - <option value={label} title={title} style={style ? style : {}} hidden>{label}</option>; + <option value={label} title={title} key={label} style={style ? style : {}} selected hidden>{label}</option> : + <option value={label} title={title} key={label} style={style ? style : {}} hidden>{label}</option>; } return label === activeOption ? - <option value={label} title={title} style={style ? style : {}} selected>{label}</option> : - <option value={label} title={title} style={style ? style : {}}>{label}</option>; + <option value={label} title={title} key={label} style={style ? style : {}} selected>{label}</option> : + <option value={label} title={title} key={label} style={style ? style : {}}>{label}</option>; }); const self = this; @@ -351,31 +363,15 @@ export default class RichTextMenu extends AntimodeMenu { } }); } - return <select onChange={e => onChange(e.target.value)}>{items}</select>; + return <select onChange={e => onChange(e.target.value)} key={key}>{items}</select>; } changeFontSize = (mark: Mark, view: EditorView) => { - const size = mark.attrs.fontSize; - if (this.editorProps) { - const ruleProvider = this.editorProps.ruleProvider; - const heading = NumCast(this.editorProps.Document.heading); - if (ruleProvider && heading) { - ruleProvider["ruleSize_" + heading] = size; - } - } - this.setMark(view.state.schema.marks.pFontSize.create({ fontSize: size }), view.state, view.dispatch); + this.setMark(view.state.schema.marks.pFontSize.create({ fontSize: mark.attrs.fontSize }), view.state, view.dispatch); } changeFontFamily = (mark: Mark, view: EditorView) => { - const fontName = mark.attrs.family; - if (this.editorProps) { - const ruleProvider = this.editorProps.ruleProvider; - const heading = NumCast(this.editorProps.Document.heading); - if (ruleProvider && heading) { - ruleProvider["ruleFont_" + heading] = fontName; - } - } - this.setMark(view.state.schema.marks.pFontFamily.create({ family: fontName }), view.state, view.dispatch); + this.setMark(view.state.schema.marks.pFontFamily.create({ family: mark.attrs.family }), view.state, view.dispatch); } // TODO: remove doesn't work @@ -417,6 +413,15 @@ export default class RichTextMenu extends AntimodeMenu { @action toggleBrushDropdown() { this.showBrushDropdown = !this.showBrushDropdown; } + // todo: add brushes to brushMap to save with a style name + onBrushNameKeyPress = (e: React.KeyboardEvent) => { + if (e.key === "Enter") { + RichTextMenu.Instance.brushMarks && RichTextMenu.Instance._brushMap.set(this._brushNameRef.current!.value, RichTextMenu.Instance.brushMarks); + this._brushNameRef.current!.style.background = "lightGray"; + } + } + _brushNameRef = React.createRef<HTMLInputElement>(); + createBrushButton() { const self = this; function onBrushClick(e: React.PointerEvent) { @@ -447,11 +452,11 @@ export default class RichTextMenu extends AntimodeMenu { <div className="dropdown"> <p>{label}</p> <button onPointerDown={this.clearBrush}>Clear brush</button> - {/* <input placeholder="Enter URL"></input> */} + <input placeholder="-brush name-" ref={this._brushNameRef} onKeyPress={this.onBrushNameKeyPress}></input> </div>; return ( - <ButtonDropdown view={this.view} button={button} dropdownContent={dropdownContent} /> + <ButtonDropdown view={this.view} key={"brush dropdown"} button={button} dropdownContent={dropdownContent} /> ); } @@ -514,21 +519,21 @@ export default class RichTextMenu extends AntimodeMenu { </button>; const dropdownContent = - <div className="dropdown"> + <div className="dropdown" > <p>Change font color:</p> <div className="color-wrapper"> {this.fontColors.map(color => { if (color) { return this.activeFontColor === color ? - <button className="color-button active" style={{ backgroundColor: color }} onPointerDown={e => changeColor(e, color)}></button> : - <button className="color-button" style={{ backgroundColor: color }} onPointerDown={e => changeColor(e, color)}></button>; + <button className="color-button active" key={"active" + color} style={{ backgroundColor: color }} onPointerDown={e => changeColor(e, color)}></button> : + <button className="color-button" key={"other" + color} style={{ backgroundColor: color }} onPointerDown={e => changeColor(e, color)}></button>; } })} </div> </div>; return ( - <ButtonDropdown view={this.view} button={button} dropdownContent={dropdownContent} /> + <ButtonDropdown view={this.view} key={"color dropdown"} button={button} dropdownContent={dropdownContent} /> ); } @@ -561,7 +566,7 @@ export default class RichTextMenu extends AntimodeMenu { } const button = - <button className="antimodeMenu-button color-preview-button" title="" onPointerDown={onHighlightClick}> + <button className="antimodeMenu-button color-preview-button" title="" key="highilghter-button" onPointerDown={onHighlightClick}> <FontAwesomeIcon icon="highlighter" size="lg" /> <div className="color-preview" style={{ backgroundColor: this.activeHighlightColor }}></div> </button>; @@ -573,15 +578,15 @@ export default class RichTextMenu extends AntimodeMenu { {this.highlightColors.map(color => { if (color) { return this.activeHighlightColor === color ? - <button className="color-button active" style={{ backgroundColor: color }} onPointerDown={e => changeHighlight(e, color)}>{color === "transparent" ? "X" : ""}</button> : - <button className="color-button" style={{ backgroundColor: color }} onPointerDown={e => changeHighlight(e, color)}>{color === "transparent" ? "X" : ""}</button>; + <button className="color-button active" key={`active ${color}`} style={{ backgroundColor: color }} onPointerDown={e => changeHighlight(e, color)}>{color === "transparent" ? "X" : ""}</button> : + <button className="color-button" key={`inactive ${color}`} style={{ backgroundColor: color }} onPointerDown={e => changeHighlight(e, color)}>{color === "transparent" ? "X" : ""}</button>; } })} </div> </div>; return ( - <ButtonDropdown view={this.view} button={button} dropdownContent={dropdownContent} /> + <ButtonDropdown view={this.view} key={"highlighter"} button={button} dropdownContent={dropdownContent} /> ); } @@ -614,7 +619,7 @@ export default class RichTextMenu extends AntimodeMenu { </div>; return ( - <ButtonDropdown view={this.view} button={button} dropdownContent={dropdownContent} openDropdownOnButton={true} /> + <ButtonDropdown view={this.view} key={"link button"} button={button} dropdownContent={dropdownContent} openDropdownOnButton={true} /> ); } @@ -752,7 +757,7 @@ export default class RichTextMenu extends AntimodeMenu { render() { - const row1 = <div className="antimodeMenu-row">{[ + const row1 = <div className="antimodeMenu-row" key="row1">{[ this.createButton("bold", "Bold", this.boldActive, toggleMark(schema.marks.strong)), this.createButton("italic", "Italic", this.italicsActive, toggleMark(schema.marks.em)), this.createButton("underline", "Underline", this.underlineActive, toggleMark(schema.marks.underline)), @@ -766,14 +771,14 @@ export default class RichTextMenu extends AntimodeMenu { this.createButton("indent", "Summarize", undefined, this.insertSummarizer), ]}</div>; - const row2 = <div className="antimodeMenu-row row-2"> - <div> - {[this.createMarksDropdown(this.activeFontSize, this.fontSizeOptions), - this.createMarksDropdown(this.activeFontFamily, this.fontFamilyOptions), - this.createNodesDropdown(this.activeListType, this.listTypeOptions)]} + const row2 = <div className="antimodeMenu-row row-2" key="antimodemenu row2"> + <div key="row"> + {[this.createMarksDropdown(this.activeFontSize, this.fontSizeOptions, "font size"), + this.createMarksDropdown(this.activeFontFamily, this.fontFamilyOptions, "font family"), + this.createNodesDropdown(this.activeListType, this.listTypeOptions, "nodes")]} </div> - <div> - <button className="antimodeMenu-button" title="Pin menu" onClick={this.toggleMenuPin} style={this.Pinned ? { backgroundColor: "#121212" } : {}}> + <div key="button"> + <button className="antimodeMenu-button" key="pin menu" title="Pin menu" onClick={this.toggleMenuPin} style={this.Pinned ? { backgroundColor: "#121212" } : {}}> <FontAwesomeIcon icon="thumbtack" size="lg" style={{ transition: "transform 0.1s", transform: this.Pinned ? "rotate(45deg)" : "" }} /> </button> {this.getDragger()} @@ -843,12 +848,12 @@ class ButtonDropdown extends React.Component<ButtonDropdownProps> { </button> : <> {this.props.button} - <button className="dropdown-button antimodeMenu-button" onPointerDown={this.onDropdownClick}> + <button className="dropdown-button antimodeMenu-button" key="antimodebutton" onPointerDown={this.onDropdownClick}> <FontAwesomeIcon icon="caret-down" size="sm" /> </button> </>} - {this.showDropdown ? this.props.dropdownContent : <></>} + {this.showDropdown ? this.props.dropdownContent : (null)} </div> ); } diff --git a/src/client/util/RichTextRules.ts b/src/client/util/RichTextRules.ts index 29b378299..8411cc6ee 100644 --- a/src/client/util/RichTextRules.ts +++ b/src/client/util/RichTextRules.ts @@ -2,14 +2,16 @@ import { textblockTypeInputRule, smartQuotes, emDash, ellipsis, InputRule } from import { schema } from "./RichTextSchema"; import { wrappingInputRule } from "./prosemirrorPatches"; import { NodeSelection, TextSelection } from "prosemirror-state"; -import { NumCast, Cast } from "../../new_fields/Types"; -import { Doc } from "../../new_fields/Doc"; +import { StrCast, Cast, NumCast } from "../../new_fields/Types"; +import { Doc, DataSym } from "../../new_fields/Doc"; import { FormattedTextBox } from "../views/nodes/FormattedTextBox"; -import { TooltipTextMenuManager } from "../util/TooltipTextMenu"; import { Docs, DocUtils } from "../documents/Documents"; import { Id } from "../../new_fields/FieldSymbols"; import { DocServer } from "../DocServer"; import { returnFalse, Utils } from "../../Utils"; +import RichTextMenu from "./RichTextMenu"; +import { RichTextField } from "../../new_fields/RichTextField"; +import { ComputedField } from "../../new_fields/ScriptField"; export const inpRules = { rules: [ @@ -64,35 +66,69 @@ export const inpRules = { // set the font size using #<font-size> new InputRule( - new RegExp(/^%([0-9]+)\s$/), + new RegExp(/%([0-9]+)\s$/), (state, match, start, end) => { const size = Number(match[1]); - const ruleProvider = FormattedTextBox.FocusedBox!.props.ruleProvider; - const heading = NumCast(FormattedTextBox.FocusedBox!.props.Document.heading); - if (ruleProvider && heading) { - (Cast(FormattedTextBox.FocusedBox!.props.Document, Doc) as Doc).heading = size; - return state.tr.deleteRange(start, end); - } return state.tr.deleteRange(start, end).addStoredMark(schema.marks.pFontSize.create({ fontSize: size })); }), - // make current selection a hyperlink portal (assumes % was used to initiate an EnteringStyle mode) + // create a text display of a metadata field on this or another document, or create a hyperlink portal to another document new InputRule( - new RegExp(/@$/), + new RegExp(/\[\[([a-zA-Z_ \-0-9]*)(:[a-zA-Z_ \-0-9]+)?\]\]$/), (state, match, start, end) => { - if (state.selection.to === state.selection.from || !(schema as any).EnteringStyle) return null; - - const value = state.doc.textBetween(start, end); - if (value) { - DocServer.GetRefField(value).then(docx => { - const target = ((docx instanceof Doc) && docx) || Docs.Create.FreeformDocument([], { title: value, width: 500, height: 500, }, value); - DocUtils.Publish(target, value, returnFalse, returnFalse); + if (!match[2]) { + const docId = match[1]; + DocServer.GetRefField(docId).then(docx => { + const target = ((docx instanceof Doc) && docx) || Docs.Create.FreeformDocument([], { title: docId, _width: 500, _height: 500, _LODdisable: true, }, docId); + DocUtils.Publish(target, docId, returnFalse, returnFalse); DocUtils.MakeLink({ doc: (schema as any).Document }, { doc: target }, "portal link", ""); }); - const link = state.schema.marks.link.create({ href: Utils.prepend("/doc/" + value), location: "onRight", title: value, targetId: value }); - return state.tr.addMark(start, end, link); + const link = state.schema.marks.link.create({ href: Utils.prepend("/doc/" + docId), location: "onRight", title: docId, targetId: docId }); + return state.tr.deleteRange(end - 1, end).deleteRange(start, start + 2).addMark(start, end - 3, link); } - return state.tr; + const fieldView = state.schema.nodes.dashField.create({ fieldKey: match[2]?.substring(1), docid: match[1] }); + return state.tr.deleteRange(start, end).insert(start, fieldView); + }), + // create a text display of a metadata field on this or another document, or create a hyperlink portal to another document + new InputRule( + new RegExp(/\{\{([a-zA-Z_ \-0-9]*)(:[a-zA-Z_ \-0-9]+)?\}\}$/), + (state, match, start, end) => { + const docId = match[1]; + DocServer.GetRefField(docId).then(docx => { + if (!(docx instanceof Doc && docx)) { + const docx = Docs.Create.FreeformDocument([], { title: docId, _width: 500, _height: 500, _LODdisable: true }, docId); + DocUtils.Publish(docx, docId, returnFalse, returnFalse); + } + }); + const node = (state.doc.resolve(start) as any).nodeAfter; + const dashDoc = schema.nodes.dashDoc.create({ width: 75, height: 75, title: "dashDoc", docid: docId, float: "right", fieldKey: match[2]?.substring(1), alias: Utils.GenerateGuid() }); + const sm = state.storedMarks || undefined; + return node ? state.tr.replaceRangeWith(start, end, dashDoc).setStoredMarks([...node.marks, ...(sm ? sm : [])]) : state.tr; + }), + new InputRule( + new RegExp(/##$/), + (state, match, start, end) => { + const schemaDoc = Doc.GetDataDoc((schema as any).Document); + const textDoc = Doc.GetProto(Cast(schemaDoc[DataSym], Doc, null)!); + const numInlines = NumCast(textDoc.inlineTextCount); + textDoc.inlineTextCount = numInlines + 1; + const inlineFieldKey = "inline" + numInlines; // which field on the text document this annotation will write to + const inlineLayoutKey = "layout_" + inlineFieldKey; // the field holding the layout string that will render the inline annotation + const textDocInline = Docs.Create.TextDocument("", { layoutKey: inlineLayoutKey, _width: 75, _height: 35, annotationOn: textDoc, _autoHeight: true, fontSize: 9, title: "inline comment" }); + textDocInline.title = inlineFieldKey; // give the annotation its own title + textDocInline.customTitle = true; // And make sure that it's 'custom' so that editing text doesn't change the title of the containing doc + textDocInline.isTemplateForField = inlineFieldKey; // this is needed in case the containing text doc is converted to a template at some point + textDocInline.proto = textDoc; // make the annotation inherit from the outer text doc so that it can resolve any nested field references, e.g., [[field]] + textDocInline._textContext = ComputedField.MakeFunction(`copyField(this.${inlineFieldKey})`, { this: Doc.name }); + textDoc[inlineLayoutKey] = FormattedTextBox.LayoutString(inlineFieldKey); // create a layout string for the layout key that will render the annotation text + textDoc[inlineFieldKey] = ""; // set a default value for the annotation + const node = (state.doc.resolve(start) as any).nodeAfter; + const newNode = schema.nodes.dashComment.create({ docid: textDocInline[Id] }); + const dashDoc = schema.nodes.dashDoc.create({ width: 75, height: 35, title: "dashDoc", docid: textDocInline[Id], float: "right" }); + const sm = state.storedMarks || undefined; + const replaced = node ? state.tr.insert(start, newNode).replaceRangeWith(start + 1, end + 1, dashDoc).insertText(" ", start + 2).setStoredMarks([...node.marks, ...(sm ? sm : [])]) : + state.tr; + return replaced; }), // stop using active style new InputRule( @@ -175,12 +211,6 @@ export const inpRules = { (state, match, start, end) => { const node = (state.doc.resolve(start) as any).nodeAfter; const sm = state.storedMarks || undefined; - const ruleProvider = FormattedTextBox.FocusedBox!.props.ruleProvider; - const heading = NumCast(FormattedTextBox.FocusedBox!.props.Document.heading); - if (ruleProvider && heading) { - ruleProvider["ruleAlign_" + heading] = "center"; - return node ? state.tr.deleteRange(start, end).setStoredMarks([...node.marks, ...(sm ? sm : [])]) : state.tr; - } const replaced = node ? state.tr.replaceRangeWith(start, end, schema.nodes.paragraph.create({ align: "center" })).setStoredMarks([...node.marks, ...(sm ? sm : [])]) : state.tr; return replaced.setSelection(new TextSelection(replaced.doc.resolve(end - 2))); @@ -191,12 +221,6 @@ export const inpRules = { (state, match, start, end) => { const node = (state.doc.resolve(start) as any).nodeAfter; const sm = state.storedMarks || undefined; - const ruleProvider = FormattedTextBox.FocusedBox!.props.ruleProvider; - const heading = NumCast(FormattedTextBox.FocusedBox!.props.Document.heading); - if (ruleProvider && heading) { - ruleProvider["ruleAlign_" + heading] = "left"; - return node ? state.tr.deleteRange(start, end).setStoredMarks([...node.marks, ...(sm ? sm : [])]) : state.tr; - } const replaced = node ? state.tr.replaceRangeWith(start, end, schema.nodes.paragraph.create({ align: "left" })).setStoredMarks([...node.marks, ...(sm ? sm : [])]) : state.tr; return replaced.setSelection(new TextSelection(replaced.doc.resolve(end - 2))); @@ -207,29 +231,11 @@ export const inpRules = { (state, match, start, end) => { const node = (state.doc.resolve(start) as any).nodeAfter; const sm = state.storedMarks || undefined; - const ruleProvider = FormattedTextBox.FocusedBox!.props.ruleProvider; - const heading = NumCast(FormattedTextBox.FocusedBox!.props.Document.heading); - if (ruleProvider && heading) { - ruleProvider["ruleAlign_" + heading] = "right"; - return node ? state.tr.deleteRange(start, end).setStoredMarks([...node.marks, ...(sm ? sm : [])]) : state.tr; - } const replaced = node ? state.tr.replaceRangeWith(start, end, schema.nodes.paragraph.create({ align: "right" })).setStoredMarks([...node.marks, ...(sm ? sm : [])]) : state.tr; return replaced.setSelection(new TextSelection(replaced.doc.resolve(end - 2))); }), new InputRule( - new RegExp(/%#$/), - (state, match, start, end) => { - const target = Docs.Create.TextDocument({ width: 75, height: 35, backgroundColor: "yellow", annotationOn: FormattedTextBox.FocusedBox!.dataDoc, autoHeight: true, fontSize: 9, title: "inline comment" }); - const node = (state.doc.resolve(start) as any).nodeAfter; - const newNode = schema.nodes.dashComment.create({ docid: target[Id] }); - const dashDoc = schema.nodes.dashDoc.create({ width: 75, height: 35, title: "dashDoc", docid: target[Id], float: "right" }); - const sm = state.storedMarks || undefined; - const replaced = node ? state.tr.insert(start, newNode).replaceRangeWith(start + 1, end + 1, dashDoc).insertText(" ", start + 2).setStoredMarks([...node.marks, ...(sm ? sm : [])]) : - state.tr; - return replaced;//.setSelection(new NodeSelection(replaced.doc.resolve(end))); - }), - new InputRule( new RegExp(/%\(/), (state, match, start, end) => { const node = (state.doc.resolve(start) as any).nodeAfter; @@ -264,7 +270,7 @@ export const inpRules = { new RegExp(/%[a-z]+$/), (state, match, start, end) => { const color = match[0].substring(1, match[0].length); - const marks = TooltipTextMenuManager.Instance._brushMap.get(color); + const marks = RichTextMenu.Instance._brushMap.get(color); if (marks) { const tr = state.tr.deleteRange(start, end); return marks ? Array.from(marks).reduce((tr, m) => tr.addStoredMark(m), tr) : tr; diff --git a/src/client/util/RichTextSchema.tsx b/src/client/util/RichTextSchema.tsx index ef90a7294..287a1049b 100644 --- a/src/client/util/RichTextSchema.tsx +++ b/src/client/util/RichTextSchema.tsx @@ -1,4 +1,4 @@ -import { reaction, IReactionDisposer } from "mobx"; +import { reaction, IReactionDisposer, observable, runInAction } from "mobx"; import { baseKeymap, toggleMark } from "prosemirror-commands"; import { redo, undo } from "prosemirror-history"; import { keymap } from "prosemirror-keymap"; @@ -8,7 +8,7 @@ import { EditorState, NodeSelection, TextSelection, Plugin } from "prosemirror-s import { StepMap } from "prosemirror-transform"; import { EditorView } from "prosemirror-view"; import * as ReactDOM from 'react-dom'; -import { Doc, WidthSym, HeightSym } from "../../new_fields/Doc"; +import { Doc, WidthSym, HeightSym, DataSym, Field } from "../../new_fields/Doc"; import { emptyFunction, returnEmptyString, returnFalse, returnOne, Utils } from "../../Utils"; import { DocServer } from "../DocServer"; import { DocumentView } from "../views/nodes/DocumentView"; @@ -16,8 +16,12 @@ import { DocumentManager } from "./DocumentManager"; import ParagraphNodeSpec from "./ParagraphNodeSpec"; import { Transform } from "./Transform"; import React = require("react"); -import { BoolCast, NumCast, Cast } from "../../new_fields/Types"; +import { BoolCast, NumCast, StrCast } from "../../new_fields/Types"; import { FormattedTextBox } from "../views/nodes/FormattedTextBox"; +import { ObjectField } from "../../new_fields/ObjectField"; +import { ComputedField } from "../../new_fields/ScriptField"; +import { observer } from "mobx-react"; +import { Id } from "../../new_fields/FieldSymbols"; const blockquoteDOM: DOMOutputSpecArray = ["blockquote", 0], hrDOM: DOMOutputSpecArray = ["hr"], preDOM: DOMOutputSpecArray = ["pre", ["code", 0]], brDOM: DOMOutputSpecArray = ["br"], ulDOM: DOMOutputSpecArray = ["ul", 0]; @@ -165,7 +169,23 @@ export const nodes: { [index: string]: NodeSpec } = { float: { default: "right" }, location: { default: "onRight" }, hidden: { default: false }, + fieldKey: { default: "" }, docid: { default: "" }, + alias: { default: "" } + }, + group: "inline", + draggable: false, + toDOM(node) { + const attrs = { style: `width: ${node.attrs.width}, height: ${node.attrs.height}` }; + return ["div", { ...node.attrs, ...attrs }]; + } + }, + + dashField: { + inline: true, + attrs: { + fieldKey: { default: "" }, + docid: { default: "" } }, group: "inline", draggable: false, @@ -306,7 +326,7 @@ export const marks: { [index: string]: MarkSpec } = { } }], toDOM(node: any) { - return node.attrs.color ? ['span', { style: 'color:' + node.attrs.color }] : ['span', { style: 'color: black' }]; + return node.attrs.color ? ['span', { style: 'color:' + node.attrs.color }] : ['span', 0]; } }, @@ -669,7 +689,7 @@ export class DashDocCommentView { if (target) { const expand = target.hidden; const tr = view.state.tr.setNodeMarkup(target.pos, undefined, { ...target.node.attrs, hidden: target.node.attrs.hidden ? false : true }); - view.dispatch(tr.setSelection(TextSelection.create(tr.doc, getPos() + (expand ? 2 : 1)))); // update the attrs + view.dispatch(tr.setSelection(TextSelection.create(tr.doc, getPos() + (expand ? 2 : 1)))); // update the attrs setTimeout(() => { expand && DocServer.GetRefField(node.attrs.docid).then(async dashDoc => dashDoc instanceof Doc && Doc.linkFollowHighlight(dashDoc)); try { view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.tr.doc, getPos() + (expand ? 2 : 1)))); } catch (e) { } @@ -678,7 +698,7 @@ export class DashDocCommentView { e.stopPropagation(); }; this._collapsed.onpointerenter = (e: any) => { - DocServer.GetRefField(node.attrs.docid).then(async dashDoc => dashDoc instanceof Doc && Doc.linkFollowHighlight(dashDoc)); + DocServer.GetRefField(node.attrs.docid).then(async dashDoc => dashDoc instanceof Doc && Doc.linkFollowHighlight(dashDoc, false)); e.preventDefault(); e.stopPropagation(); }; @@ -703,7 +723,7 @@ export class DashDocView { const { scale, translateX, translateY } = Utils.GetScreenTransform(this._outer); return new Transform(-translateX, -translateY, 1).scale(1 / this.contentScaling() / scale); } - contentScaling = () => NumCast(this._dashDoc!.nativeWidth) > 0 && !this._dashDoc!.ignoreAspect ? this._dashDoc![WidthSym]() / NumCast(this._dashDoc!.nativeWidth) : 1; + contentScaling = () => NumCast(this._dashDoc!._nativeWidth) > 0 && !this._dashDoc!.ignoreAspect ? this._dashDoc![WidthSym]() / NumCast(this._dashDoc!._nativeWidth) : 1; outerFocus = (target: Doc) => this._textBox.props.focus(this._textBox.props.Document); // ideally, this would scroll to show the focus target constructor(node: any, view: any, getPos: any, tbox: FormattedTextBox) { this._textBox = tbox; @@ -721,12 +741,6 @@ export class DashDocView { this._dashSpan.style.height = node.attrs.height; this._dashSpan.style.position = "absolute"; this._dashSpan.style.display = "inline-block"; - const removeDoc = () => { - const pos = getPos(); - const ns = new NodeSelection(view.state.doc.resolve(pos)); - view.dispatch(view.state.tr.setSelection(ns).deleteSelection()); - return true; - }; this._dashSpan.onpointerleave = () => { const ele = document.getElementById("DashDocCommentView-" + node.attrs.docid); if (ele) { @@ -739,47 +753,26 @@ export class DashDocView { (ele as HTMLDivElement).style.backgroundColor = "orange"; } }; - DocServer.GetRefField(node.attrs.docid).then(async dashDoc => { - if (dashDoc instanceof Doc) { - self._dashDoc = dashDoc; - dashDoc.hideSidebar = true; - if (node.attrs.width !== dashDoc.width + "px" || node.attrs.height !== dashDoc.height + "px") { - try { // bcz: an exception will be thrown if two aliases are open at the same time when a doc view comment is made - view.dispatch(view.state.tr.setNodeMarkup(getPos(), null, { ...node.attrs, width: dashDoc.width + "px", height: dashDoc.height + "px" })); - } catch (e) { - console.log(e); + const removeDoc = () => { + const pos = getPos(); + const ns = new NodeSelection(view.state.doc.resolve(pos)); + view.dispatch(view.state.tr.setSelection(ns).deleteSelection()); + return true; + }; + const alias = node.attrs.alias; + + const docid = node.attrs.docid || tbox.props.DataDoc?.[Id] || tbox.dataDoc?.[Id]; + DocServer.GetRefField(docid + alias).then(async dashDoc => { + if (!(dashDoc instanceof Doc)) { + alias && DocServer.GetRefField(docid).then(async dashDocBase => { + if (dashDocBase instanceof Doc) { + const aliasedDoc = Doc.MakeDelegate(dashDocBase, docid + alias); + aliasedDoc.layoutKey = "layout_" + node.attrs.fieldKey; + self.doRender(aliasedDoc, removeDoc, node, view, getPos); } - } - this._reactionDisposer && this._reactionDisposer(); - this._reactionDisposer = reaction(() => dashDoc[HeightSym]() + dashDoc[WidthSym](), () => { - this._dashSpan.style.height = this._outer.style.height = dashDoc[HeightSym]() + "px"; - this._dashSpan.style.width = this._outer.style.width = dashDoc[WidthSym]() + "px"; }); - ReactDOM.render(<DocumentView - Document={dashDoc} - LibraryPath={tbox.props.LibraryPath} - fitToBox={BoolCast(dashDoc.fitToBox)} - addDocument={returnFalse} - removeDocument={removeDoc} - ruleProvider={undefined} - ScreenToLocalTransform={this.getDocTransform} - addDocTab={self._textBox.props.addDocTab} - pinToPres={returnFalse} - renderDepth={1} - PanelWidth={self._dashDoc[WidthSym]} - PanelHeight={self._dashDoc[HeightSym]} - focus={self.outerFocus} - backgroundColor={returnEmptyString} - parentActive={returnFalse} - whenActiveChanged={returnFalse} - bringToFront={emptyFunction} - zoomToScale={emptyFunction} - getScale={returnOne} - dontRegisterView={false} - ContainingCollectionView={undefined} - ContainingCollectionDoc={undefined} - ContentScaling={this.contentScaling} - />, this._dashSpan); + } else { + self.doRender(dashDoc, removeDoc, node, view, getPos); } }); const self = this; @@ -795,11 +788,110 @@ export class DashDocView { this._outer.appendChild(this._dashSpan); (this as any).dom = this._outer; } + doRender(dashDoc: Doc, removeDoc: any, node: any, view: any, getPos: any) { + this._dashDoc = dashDoc; + dashDoc._hideSidebar = true; + if (node.attrs.width !== dashDoc._width + "px" || node.attrs.height !== dashDoc._height + "px") { + try { // bcz: an exception will be thrown if two aliases are open at the same time when a doc view comment is made + view.dispatch(view.state.tr.setNodeMarkup(getPos(), null, { ...node.attrs, width: dashDoc._width + "px", height: dashDoc._height + "px" })); + } catch (e) { + console.log(e); + } + } + const self = this; + const finalLayout = Doc.expandTemplateLayout(dashDoc, !Doc.AreProtosEqual(this._textBox.dataDoc, this._textBox.Document) ? this._textBox.dataDoc : undefined); + if (!finalLayout) setTimeout(() => self.doRender(dashDoc, removeDoc, node, view, getPos), 0); + else { + const layoutKey = StrCast(finalLayout.layoutKey); + const finalKey = layoutKey && StrCast(finalLayout[layoutKey]).split("'")?.[1]; + if (finalLayout !== dashDoc && finalKey) { + const finalLayoutField = finalLayout[finalKey]; + if (finalLayoutField instanceof ObjectField) { + finalLayout._textTemplate = ComputedField.MakeFunction(`copyField(this.${finalKey})`, { this: Doc.name }); + } + } + this._reactionDisposer && this._reactionDisposer(); + this._reactionDisposer = reaction(() => [finalLayout[WidthSym](), finalLayout[HeightSym]()], (dim) => { + this._dashSpan.style.width = this._outer.style.width = dim[0] + "px"; + this._dashSpan.style.height = this._outer.style.height = dim[1] + "px"; + }, { fireImmediately: true }); + ReactDOM.render(<DocumentView + Document={finalLayout} + DataDoc={!node.attrs.docid ? this._textBox.dataDoc : undefined} + LibraryPath={this._textBox.props.LibraryPath} + fitToBox={BoolCast(dashDoc._fitToBox)} + addDocument={returnFalse} + removeDocument={removeDoc} + ScreenToLocalTransform={this.getDocTransform} + addDocTab={this._textBox.props.addDocTab} + pinToPres={returnFalse} + renderDepth={1} + PanelWidth={finalLayout[WidthSym]} + PanelHeight={finalLayout[HeightSym]} + focus={this.outerFocus} + backgroundColor={returnEmptyString} + parentActive={returnFalse} + whenActiveChanged={returnFalse} + bringToFront={emptyFunction} + zoomToScale={emptyFunction} + getScale={returnOne} + dontRegisterView={false} + ContainingCollectionView={undefined} + ContainingCollectionDoc={undefined} + ContentScaling={this.contentScaling} + />, this._dashSpan); + } + } destroy() { this._reactionDisposer && this._reactionDisposer(); } } + +export class DashFieldView { + _fieldWrapper: HTMLDivElement; + _labelSpan: HTMLSpanElement; + _fieldSpan: HTMLSpanElement; + _reactionDisposer: IReactionDisposer | undefined; + _textBoxDoc: Doc; + @observable _dashDoc: Doc | undefined; + + constructor(node: any, view: any, getPos: any, tbox: FormattedTextBox) { + this._textBoxDoc = tbox.props.Document; + this._fieldWrapper = document.createElement("div"); + this._fieldWrapper.style.width = node.attrs.width; + this._fieldWrapper.style.height = node.attrs.height; + this._fieldWrapper.style.position = "relative"; + this._fieldWrapper.style.display = "inline"; + + this._fieldSpan = document.createElement("span"); + this._fieldSpan.style.position = "relative"; + this._fieldSpan.style.display = "inline"; + + this._labelSpan = document.createElement("span"); + this._labelSpan.style.position = "relative"; + this._labelSpan.style.display = "inline"; + this._labelSpan.style.fontWeight = "bold"; + this._labelSpan.style.fontSize = "larger"; + this._labelSpan.innerHTML = `${node.attrs.fieldKey}: `; + if (node.attrs.docid) { + const self = this; + DocServer.GetRefField(node.attrs.docid).then(async dashDoc => dashDoc instanceof Doc && runInAction(() => self._dashDoc = dashDoc)); + } else { + this._dashDoc = tbox.props.DataDoc || tbox.dataDoc; + } + this._reactionDisposer?.(); + this._reactionDisposer = reaction(() => this._dashDoc?.[node.attrs.fieldKey], fval => this._fieldSpan.innerHTML = Field.toString(fval as Field), { fireImmediately: true }); + + this._fieldWrapper.appendChild(this._labelSpan); + this._fieldWrapper.appendChild(this._fieldSpan); + (this as any).dom = this._fieldWrapper; + } + destroy() { + this._reactionDisposer?.(); + } +} + export class OrderedListView { update(node: any) { return false; // if attr's of an ordered_list (e.g., bulletStyle) change, return false forces the dom node to be recreated which is necessary for the bullet labels to update @@ -855,7 +947,8 @@ export class FootnoteView { }), new Plugin({ view(newView) { - return FormattedTextBox.getToolTip(newView); + // TODO -- make this work with RichTextMenu + // return FormattedTextBox.getToolTip(newView); } }) ], @@ -963,7 +1056,7 @@ export class SummaryView { view.dispatch(view.state.tr. setSelection(textSelection). // select the current summarized text (or where it will be if its collapsed) replaceSelection(!visible ? new Slice(Fragment.fromArray([]), 0, 0) : node.attrs.text). // collapse/expand it - setNodeMarkup(getPos(), undefined, attrs)); // update the attrs + setNodeMarkup(getPos(), undefined, attrs)); // update the attrs e.preventDefault(); e.stopPropagation(); this._collapsed.className = this.className(visible); diff --git a/src/client/util/TooltipLinkingMenu.tsx b/src/client/util/TooltipLinkingMenu.tsx deleted file mode 100644 index b46675a04..000000000 --- a/src/client/util/TooltipLinkingMenu.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import { EditorState } from "prosemirror-state"; -import { EditorView } from "prosemirror-view"; -import { FieldViewProps } from "../views/nodes/FieldView"; -import "./TooltipTextMenu.scss"; - -//appears above a selection of text in a RichTextBox to give user options such as Bold, Italics, etc. -export class TooltipLinkingMenu { - - private tooltip: HTMLElement; - private view: EditorView; - private editorProps: FieldViewProps; - - constructor(view: EditorView, editorProps: FieldViewProps) { - this.view = view; - this.editorProps = editorProps; - this.tooltip = document.createElement("div"); - this.tooltip.className = "tooltipMenu linking"; - - //add the div which is the tooltip - view.dom.parentNode!.parentNode!.appendChild(this.tooltip); - - const target = "https://www.google.com"; - - const link = document.createElement("a"); - link.href = target; - link.textContent = target; - link.target = "_blank"; - link.style.color = "white"; - this.tooltip.appendChild(link); - - this.update(view, undefined); - } - - //updates the tooltip menu when the selection changes - update(view: EditorView, lastState: EditorState | undefined) { - const state = view.state; - // Don't do anything if the document/selection didn't change - if (lastState && lastState.doc.eq(state.doc) && - lastState.selection.eq(state.selection)) return; - - // Hide the tooltip if the selection is empty - if (state.selection.empty) { - this.tooltip.style.display = "none"; - return; - } - - console.log("STORED:"); - console.log(state.doc.content.firstChild!.content); - - // Otherwise, reposition it and update its content - this.tooltip.style.display = ""; - const { from, to } = state.selection; - const start = view.coordsAtPos(from), end = view.coordsAtPos(to); - // The box in which the tooltip is positioned, to use as base - const box = this.tooltip.offsetParent!.getBoundingClientRect(); - // Find a center-ish x position from the selection endpoints (when - // crossing lines, end may be more to the left) - const left = Math.max((start.left + end.left) / 2, start.left + 3); - this.tooltip.style.left = (left - box.left) * this.editorProps.ScreenToLocalTransform().Scale + "px"; - const width = Math.abs(start.left - end.left) / 2 * this.editorProps.ScreenToLocalTransform().Scale; - const mid = Math.min(start.left, end.left) + width; - - this.tooltip.style.width = "auto"; - this.tooltip.style.bottom = (box.bottom - start.top) * this.editorProps.ScreenToLocalTransform().Scale + "px"; - } - - destroy() { this.tooltip.remove(); } -} diff --git a/src/client/util/TooltipTextMenu.scss b/src/client/util/TooltipTextMenu.scss deleted file mode 100644 index 2a38fe118..000000000 --- a/src/client/util/TooltipTextMenu.scss +++ /dev/null @@ -1,372 +0,0 @@ -@import "../views/globalCssVariables"; -.ProseMirror-menu-dropdown-wrap { - display: inline-block; - position: relative; -} - -.ProseMirror-menu-dropdown { - vertical-align: 1px; - cursor: pointer; - position: relative; - padding: 0 15px 0 4px; - background: white; - border-radius: 2px; - text-align: left; - font-size: 12px; - white-space: nowrap; - margin-right: 4px; - - &:after { - content: ""; - border-left: 4px solid transparent; - border-right: 4px solid transparent; - border-top: 4px solid currentColor; - opacity: .6; - position: absolute; - right: 4px; - top: calc(50% - 2px); - } -} - -.ProseMirror-menu-submenu-wrap { - position: relative; - margin-right: -4px; -} - -.ProseMirror-menu-dropdown-menu, -.ProseMirror-menu-submenu { - font-size: 12px; - background: white; - border: 1px solid rgb(223, 223, 223); - min-width: 40px; - z-index: 50000; - position: absolute; - box-sizing: content-box; - - .ProseMirror-menu-dropdown-item { - cursor: pointer; - z-index: 100000; - text-align: left; - padding: 3px; - - &:hover { - background-color: $light-color-secondary; - } - } -} - - -.ProseMirror-menu-submenu-label:after { - content: ""; - border-top: 4px solid transparent; - border-bottom: 4px solid transparent; - border-left: 4px solid currentColor; - opacity: .6; - position: absolute; - right: 4px; - top: calc(50% - 4px); -} - - .ProseMirror-icon { - display: inline-block; - // line-height: .8; - // vertical-align: -2px; /* Compensate for padding */ - // padding: 2px 8px; - cursor: pointer; - - &.ProseMirror-menu-disabled { - cursor: default; - } - - svg { - fill:white; - height: 1em; - } - - span { - vertical-align: text-top; - } - } - -.wrapper { - position: absolute; - pointer-events: all; - display: flex; - align-items: center; - transform: translateY(-85px); - - height: 35px; - background: #323232; - border-radius: 6px; - box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.25); - -} - -.tooltipMenu, .basic-tools { - z-index: 20000; - pointer-events: all; - padding: 3px; - padding-bottom: 5px; - display: flex; - align-items: center; - - .ProseMirror-example-setup-style hr { - padding: 2px 10px; - border: none; - margin: 1em 0; - } - - .ProseMirror-example-setup-style hr:after { - content: ""; - display: block; - height: 1px; - background-color: silver; - line-height: 2px; - } -} - -.menuicon { - width: 25px; - height: 25px; - cursor: pointer; - text-align: center; - line-height: 25px; - margin: 0 2px; - border-radius: 3px; - - &:hover { - background-color: black; - - #link-drag { - background-color: black; - } - } - - &> * { - margin-top: 50%; - margin-left: 50%; - transform: translate(-50%, -50%); - } - - svg { - fill: inherit; - width: 18px; - height: 18px; - } -} - -.menuicon-active { - width: 25px; - height: 25px; - cursor: pointer; - text-align: center; - line-height: 25px; - margin: 0 2px; - border-radius: 3px; - - &:hover { - background-color: black; - } - - &> * { - margin-top: 50%; - margin-left: 50%; - transform: translate(-50%, -50%); - } - - svg { - fill: greenyellow; - width: 18px; - height: 18px; - } -} - -.colorPicker { - position: relative; - - svg { - width: 18px; - height: 18px; - // margin-top: 11px; - } - - .buttonColor { - position: absolute; - top: 24px; - left: 1px; - width: 24px; - height: 4px; - margin-top: 0; - } -} - -#link-drag { - background-color: #323232; -} - -.underline svg { - margin-top: 13px; -} - - .font-size-indicator { - font-size: 12px; - padding-right: 0px; - } - .summarize{ - color: white; - height: 20px; - text-align: center; - } - - -.brush{ - display: inline-block; - width: 1em; - height: 1em; - stroke-width: 0; - stroke: currentColor; - fill: currentColor; - margin-right: 15px; -} - -.brush-active{ - display: inline-block; - width: 1em; - height: 1em; - stroke-width: 3; - fill: greenyellow; - margin-right: 15px; -} - -.dragger-wrapper { - color: #eee; - height: 22px; - padding: 0 5px; - box-sizing: content-box; - cursor: grab; - - .dragger { - width: 18px; - height: 100%; - display: flex; - justify-content: space-evenly; - } - - .dragger-line { - width: 2px; - height: 100%; - background-color: black; - } -} - -.button-dropdown-wrapper { - display: flex; - align-content: center; - - &:hover { - background-color: black; - } -} - -.buttonSettings-dropdown { - - &.ProseMirror-menu-dropdown { - width: 10px; - height: 25px; - margin: 0; - padding: 0 2px; - background-color: #323232; - text-align: center; - - &:after { - border-top: 4px solid white; - right: 2px; - } - - &:hover { - background-color: black; - } - } - - &.ProseMirror-menu-dropdown-menu { - min-width: 150px; - left: -27px; - top: 31px; - background-color: #323232; - border: 1px solid #4d4d4d; - color: $light-color-secondary; - // border: none; - // border: 1px solid $light-color-secondary; - border-radius: 0 6px 6px 6px; - padding: 3px; - box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.25); - - .ProseMirror-menu-dropdown-item{ - cursor: default; - - &:last-child { - border-bottom: none; - } - - &:hover { - background-color: #323232; - } - - .button-setting, .button-setting-disabled { - padding: 2px; - border-radius: 2px; - } - - .button-setting:hover { - cursor: pointer; - background-color: black; - } - - .separated-button { - border-top: 1px solid $light-color-secondary; - padding-top: 6px; - } - - input { - color: black; - border: none; - border-radius: 1px; - padding: 3px; - } - - button { - padding: 6px; - background-color: #323232; - border: 1px solid black; - border-radius: 1px; - - &:hover { - background-color: black; - } - } - } - - - } -} - -.colorPicker-wrapper { - display: flex; - flex-wrap: wrap; - justify-content: space-between; - margin-top: 3px; - margin-left: -3px; - width: calc(100% + 6px); -} - -button.colorPicker { - width: 20px; - height: 20px; - border-radius: 15px !important; - margin: 3px; - border: none !important; - - &.active { - border: 2px solid white !important; - } -}
\ No newline at end of file diff --git a/src/client/util/TooltipTextMenu.tsx b/src/client/util/TooltipTextMenu.tsx deleted file mode 100644 index 1c15dca7f..000000000 --- a/src/client/util/TooltipTextMenu.tsx +++ /dev/null @@ -1,1042 +0,0 @@ -import { Dropdown, icons, MenuItem } from "prosemirror-menu"; //no import css -import { Mark, MarkType, Node as ProsNode, NodeType, ResolvedPos, Schema } from "prosemirror-model"; -import { wrapInList } from 'prosemirror-schema-list'; -import { EditorState, NodeSelection, TextSelection } from "prosemirror-state"; -import { EditorView } from "prosemirror-view"; -import { Doc, Field, Opt } from "../../new_fields/Doc"; -import { Utils } from "../../Utils"; -import { DocServer } from "../DocServer"; -import { FieldViewProps } from "../views/nodes/FieldView"; -import { FormattedTextBoxProps } from "../views/nodes/FormattedTextBox"; -import { LinkManager } from "./LinkManager"; -import { schema } from "./RichTextSchema"; -import "./TooltipTextMenu.scss"; -import { Cast, NumCast, StrCast } from '../../new_fields/Types'; -import { updateBullets } from './ProsemirrorExampleTransfer'; -import { DocumentDecorations } from '../views/DocumentDecorations'; -import { SelectionManager } from './SelectionManager'; -import { PastelSchemaPalette, DarkPastelSchemaPalette } from '../../new_fields/SchemaHeaderField'; -const { toggleMark } = require("prosemirror-commands"); - -//appears above a selection of text in a RichTextBox to give user options such as Bold, Italics, etc. -export class TooltipTextMenu { - public static Toolbar: HTMLDivElement | undefined; - - // editor state properties - private view: EditorView; - private editorProps: FieldViewProps & FormattedTextBoxProps | undefined; - - private fontStyles: Mark[] = []; - private fontSizes: Mark[] = []; - private _marksToDoms: Map<MarkType, HTMLSpanElement> = new Map(); - private _collapsed: boolean = false; - - // editor doms - public tooltip: HTMLElement = document.createElement("div"); - private wrapper: HTMLDivElement = document.createElement("div"); - - // editor button doms - private colorDom?: Node; - private colorDropdownDom?: Node; - private linkDom?: Node; - private highighterDom?: Node; - private highlighterDropdownDom?: Node; - private linkDropdownDom?: Node; - private _brushdom?: Node; - private _brushDropdownDom?: Node; - private fontSizeDom?: Node; - private fontStyleDom?: Node; - private basicTools?: HTMLElement; - - static createDiv(className: string) { const div = document.createElement("div"); div.className = className; return div; } - static createSpan(className: string) { const div = document.createElement("span"); div.className = className; return div; } - constructor(view: EditorView) { - this.view = view; - - // initialize the tooltip -- sets this.tooltip - this.initTooltip(view); - - // initialize the wrapper - this.wrapper = TooltipTextMenu.createDiv("wrapper"); - this.wrapper.appendChild(this.tooltip); - - TooltipTextMenu.Toolbar = this.wrapper; - } - - private async initTooltip(view: EditorView) { - const self = this; - this.tooltip = TooltipTextMenu.createDiv("tooltipMenu"); - this.basicTools = TooltipTextMenu.createDiv("basic-tools"); - - const svgIcon = (name: string, title: string = name, dpath: string) => { - const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); - svg.setAttribute("viewBox", "-100 -100 650 650"); - const path = document.createElementNS('http://www.w3.org/2000/svg', "path"); - path.setAttributeNS(null, "d", dpath); - svg.appendChild(path); - - const span = TooltipTextMenu.createSpan(name + " menuicon"); - span.title = title; - span.appendChild(svg); - - return span; - }; - - const basicItems = [ // init basicItems in minimized toolbar -- paths to svgs are obtained from fontawesome - { mark: schema.marks.strong, dom: svgIcon("strong", "Bold", "M333.49 238a122 122 0 0 0 27-65.21C367.87 96.49 308 32 233.42 32H34a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h31.87v288H34a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h209.32c70.8 0 134.14-51.75 141-122.4 4.74-48.45-16.39-92.06-50.83-119.6zM145.66 112h87.76a48 48 0 0 1 0 96h-87.76zm87.76 288h-87.76V288h87.76a56 56 0 0 1 0 112z") }, - { mark: schema.marks.em, dom: svgIcon("em", "Italic", "M320 48v32a16 16 0 0 1-16 16h-62.76l-80 320H208a16 16 0 0 1 16 16v32a16 16 0 0 1-16 16H16a16 16 0 0 1-16-16v-32a16 16 0 0 1 16-16h62.76l80-320H112a16 16 0 0 1-16-16V48a16 16 0 0 1 16-16h192a16 16 0 0 1 16 16z") }, - { mark: schema.marks.underline, dom: svgIcon("underline", "Underline", "M32 64h32v160c0 88.22 71.78 160 160 160s160-71.78 160-160V64h32a16 16 0 0 0 16-16V16a16 16 0 0 0-16-16H272a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h32v160a80 80 0 0 1-160 0V64h32a16 16 0 0 0 16-16V16a16 16 0 0 0-16-16H32a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16zm400 384H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16z") }, - ]; - const items = [ // init items in full size toolbar - { mark: schema.marks.strikethrough, dom: svgIcon("strikethrough", "Strikethrough", "M496 224H293.9l-87.17-26.83A43.55 43.55 0 0 1 219.55 112h66.79A49.89 49.89 0 0 1 331 139.58a16 16 0 0 0 21.46 7.15l42.94-21.47a16 16 0 0 0 7.16-21.46l-.53-1A128 128 0 0 0 287.51 32h-68a123.68 123.68 0 0 0-123 135.64c2 20.89 10.1 39.83 21.78 56.36H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h480a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm-180.24 96A43 43 0 0 1 336 356.45 43.59 43.59 0 0 1 292.45 400h-66.79A49.89 49.89 0 0 1 181 372.42a16 16 0 0 0-21.46-7.15l-42.94 21.47a16 16 0 0 0-7.16 21.46l.53 1A128 128 0 0 0 224.49 480h68a123.68 123.68 0 0 0 123-135.64 114.25 114.25 0 0 0-5.34-24.36z") }, - { mark: schema.marks.superscript, dom: svgIcon("superscript", "Superscript", "M496 160h-16V16a16 16 0 0 0-16-16h-48a16 16 0 0 0-14.29 8.83l-16 32A16 16 0 0 0 400 64h16v96h-16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h96a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zM336 64h-67a16 16 0 0 0-13.14 6.87l-79.9 115-79.9-115A16 16 0 0 0 83 64H16A16 16 0 0 0 0 80v48a16 16 0 0 0 16 16h33.48l77.81 112-77.81 112H16a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h67a16 16 0 0 0 13.14-6.87l79.9-115 79.9 115A16 16 0 0 0 269 448h67a16 16 0 0 0 16-16v-48a16 16 0 0 0-16-16h-33.48l-77.81-112 77.81-112H336a16 16 0 0 0 16-16V80a16 16 0 0 0-16-16z") }, - { mark: schema.marks.subscript, dom: svgIcon("subscript", "Subscript", "M496 448h-16V304a16 16 0 0 0-16-16h-48a16 16 0 0 0-14.29 8.83l-16 32A16 16 0 0 0 400 352h16v96h-16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h96a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zM336 64h-67a16 16 0 0 0-13.14 6.87l-79.9 115-79.9-115A16 16 0 0 0 83 64H16A16 16 0 0 0 0 80v48a16 16 0 0 0 16 16h33.48l77.81 112-77.81 112H16a16 16 0 0 0-16 16v48a16 16 0 0 0 16 16h67a16 16 0 0 0 13.14-6.87l79.9-115 79.9 115A16 16 0 0 0 269 448h67a16 16 0 0 0 16-16v-48a16 16 0 0 0-16-16h-33.48l-77.81-112 77.81-112H336a16 16 0 0 0 16-16V80a16 16 0 0 0-16-16z") }, - ]; - - basicItems.map(({ dom, mark }) => this.basicTools ?.appendChild(dom.cloneNode(true))); - basicItems.concat(items).forEach(({ dom, mark }) => { - this.tooltip.appendChild(dom); - this._marksToDoms.set(mark, dom); - - //pointer down handler to activate button effects - dom.addEventListener("pointerdown", e => { - this.view.focus(); - if (dom.contains(e.target as Node)) { - e.preventDefault(); - e.stopPropagation(); - toggleMark(mark)(this.view.state, this.view.dispatch, this.view); - this.updateHighlightStateOfButtons(); - } - }); - }); - - // summarize menu - this.highighterDom = this.createHighlightTool().render(this.view).dom; - this.highlighterDropdownDom = this.createHighlightDropdown().render(this.view).dom; - this.tooltip.appendChild(this.highighterDom); - this.tooltip.appendChild(this.highlighterDropdownDom); - - // color menu - this.colorDom = this.createColorTool().render(this.view).dom; - this.colorDropdownDom = this.createColorDropdown().render(this.view).dom; - this.tooltip.appendChild(this.colorDom); - this.tooltip.appendChild(this.colorDropdownDom); - - // link menu - this.linkDom = this.createLinkTool().render(this.view).dom; - this.linkDropdownDom = this.createLinkDropdown("").render(this.view).dom; - this.tooltip.appendChild(this.linkDom); - this.tooltip.appendChild(this.linkDropdownDom); - - // list of font styles - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 7 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 8 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 9 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 10 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 12 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 14 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 16 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 18 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 20 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 24 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 32 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 48 })); - this.fontSizes.push(schema.marks.pFontSize.create({ fontSize: 72 })); - - // font sizes - this.fontStyles.push(schema.marks.pFontFamily.create({ family: "Times New Roman" })); - this.fontStyles.push(schema.marks.pFontFamily.create({ family: "Arial" })); - this.fontStyles.push(schema.marks.pFontFamily.create({ family: "Georgia" })); - this.fontStyles.push(schema.marks.pFontFamily.create({ family: "Comic Sans MS" })); - this.fontStyles.push(schema.marks.pFontFamily.create({ family: "Tahoma" })); - this.fontStyles.push(schema.marks.pFontFamily.create({ family: "Impact" })); - this.fontStyles.push(schema.marks.pFontFamily.create({ family: "Crimson Text" })); - - - // init brush tool - this._brushdom = this.createBrushTool().render(this.view).dom; - this.tooltip.appendChild(this._brushdom); - this._brushDropdownDom = this.createBrushDropdown().render(this.view).dom; - this.tooltip.appendChild(this._brushDropdownDom); - - // summarizer tool - const summarizer = new MenuItem({ - title: "Summarize", - label: "Summarize", - icon: icons.join, - css: "fill:white;", - class: "menuicon", - execEvent: "", - run: (state, dispatch) => TooltipTextMenu.insertSummarizer(state, dispatch) - }); - this.tooltip.appendChild(summarizer.render(this.view).dom); - - // list types dropdown - const listDropdownTypes = [{ mapStyle: "bullet", label: ":" }, { mapStyle: "decimal", label: "1.1" }, { mapStyle: "multi", label: "A.1" }, { label: "X" }]; - const listTypes = new Dropdown(listDropdownTypes.map(({ mapStyle, label }) => - new MenuItem({ - title: "Set Bullet Style", - label: label, - execEvent: "", - class: "dropdown-item", - css: "color: black; width: 40px;", - enable() { return true; }, - run() { - const marks = self.view.state.storedMarks || (view.state.selection.$to.parentOffset && view.state.selection.$from.marks()); - if (!wrapInList(schema.nodes.ordered_list)(view.state, (tx2: any) => { - const tx3 = updateBullets(tx2, schema, mapStyle); - marks && tx3.ensureMarks([...marks]); - marks && tx3.setStoredMarks([...marks]); - - view.dispatch(tx2); - })) { - const tx2 = view.state.tr; - const tx3 = updateBullets(tx2, schema, mapStyle); - marks && tx3.ensureMarks([...marks]); - marks && tx3.setStoredMarks([...marks]); - - view.dispatch(tx3); - } - } - })), { label: ":", css: "color:black; width: 40px;" }); - this.tooltip.appendChild(listTypes.render(this.view).dom); - - await this.updateFromDash(view, undefined, undefined); - - const draggerWrapper = TooltipTextMenu.createDiv("dragger-wrapper"); - const dragger = TooltipTextMenu.createDiv("dragger"); - dragger.appendChild(TooltipTextMenu.createSpan("dragger-line")); - dragger.appendChild(TooltipTextMenu.createSpan("dragger-line")); - dragger.appendChild(TooltipTextMenu.createSpan("dragger-line")); - draggerWrapper.appendChild(dragger); - this.wrapper.appendChild(draggerWrapper); - this.setupDragElementInteractions(draggerWrapper); - } - - setupDragElementInteractions(elmnt: HTMLElement) { - var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0; - if (elmnt) { - // if present, the header is where you move the DIV from: - elmnt.onpointerdown = dragPointerDown; - elmnt.ondblclick = onClick; - } - const self = this; - - function dragPointerDown(e: PointerEvent) { - e = e || window.event; - e.preventDefault(); - // get the mouse cursor position at startup: - pos3 = e.clientX; - pos4 = e.clientY; - document.onpointerup = closeDragElement; - // call a function whenever the cursor moves: - document.onpointermove = elementDrag; - } - - function onClick(e: MouseEvent) { - self._collapsed = !self._collapsed; - const children = self.wrapper.childNodes; - if (self._collapsed && children.length > 0) { - self.wrapper.removeChild(self.tooltip); - self.basicTools && self.wrapper.prepend(self.basicTools); - } - else { - self.wrapper.prepend(self.tooltip); - self.basicTools && self.wrapper.removeChild(self.basicTools); - } - } - - function elementDrag(e: PointerEvent) { - e = e || window.event; - //e.preventDefault(); - // calculate the new cursor position: - pos1 = pos3 - e.clientX; - pos2 = pos4 - e.clientY; - pos3 = e.clientX; - pos4 = e.clientY; - // set the element's new position: - // elmnt.style.top = (elmnt.offsetTop - pos2) + "px"; - // elmnt.style.left = (elmnt.offsetLeft - pos1) + "px"; - - self.wrapper.style.top = (self.wrapper.offsetTop - pos2) + "px"; - self.wrapper.style.left = (self.wrapper.offsetLeft - pos1) + "px"; - } - - function closeDragElement() { - // stop moving when mouse button is released: - document.onpointerup = null; - document.onpointermove = null; - } - } - - //label of dropdown will change to given label - updateFontSizeDropdown(label: string) { - //font SIZES - const fontSizeBtns: MenuItem[] = []; - const self = this; - this.fontSizes.forEach(mark => - fontSizeBtns.push(new MenuItem({ - title: "Set Font Size", - label: String(mark.attrs.fontSize), - execEvent: "", - class: "dropdown-item", - css: "color: black; width: 50px;", - enable() { return true; }, - run() { - const size = mark.attrs.fontSize; - if (size) { self.updateFontSizeDropdown(String(size) + " pt"); } - if (self.editorProps) { - const ruleProvider = self.editorProps.ruleProvider; - const heading = NumCast(self.editorProps.Document.heading); - if (ruleProvider && heading) { - ruleProvider["ruleSize_" + heading] = size; - } - } - TooltipTextMenu.setMark(self.view.state.schema.marks.pFontSize.create({ fontSize: size }), self.view.state, self.view.dispatch); - } - }))); - - const newfontSizeDom = (new Dropdown(fontSizeBtns, { label: label, css: "color:black; min-width: 60px;" }) as MenuItem).render(this.view).dom; - if (this.fontSizeDom) { - this.tooltip.replaceChild(newfontSizeDom, this.fontSizeDom); - } - else { - this.tooltip.appendChild(newfontSizeDom); - } - this.fontSizeDom = newfontSizeDom; - } - - //label of dropdown will change to given label - updateFontStyleDropdown(label: string) { - //font STYLES - const fontBtns: MenuItem[] = []; - const self = this; - this.fontStyles.forEach(mark => - fontBtns.push(new MenuItem({ - title: "Set Font Family", - label: mark.attrs.family, - execEvent: "", - class: "dropdown-item", - css: "color: black; font-family: " + mark.attrs.family + ", sans-serif; width: 125px;", - enable() { return true; }, - run() { - const fontName = mark.attrs.family; - if (fontName) { self.updateFontStyleDropdown(fontName); } - if (self.editorProps) { - const ruleProvider = self.editorProps.ruleProvider; - const heading = NumCast(self.editorProps.Document.heading); - if (ruleProvider && heading) { - ruleProvider["ruleFont_" + heading] = fontName; - } - } - TooltipTextMenu.setMark(self.view.state.schema.marks.pFontFamily.create({ family: fontName }), self.view.state, self.view.dispatch); - } - }))); - - const newfontStyleDom = (new Dropdown(fontBtns, { label: label, css: "color:black; width: 125px;" }) as MenuItem).render(this.view).dom; - if (this.fontStyleDom) { - this.tooltip.replaceChild(newfontStyleDom, this.fontStyleDom); - } - else { - this.tooltip.appendChild(newfontStyleDom); - } - this.fontStyleDom = newfontStyleDom; - } - async getTextLinkTargetTitle() { - const node = this.view.state.selection.$from.nodeAfter; - const link = node && node.marks.find(m => m.type.name === "link"); - if (link) { - const href = link.attrs.href; - if (href) { - if (href.indexOf(Utils.prepend("/doc/")) === 0) { - const linkclicked = href.replace(Utils.prepend("/doc/"), "").split("?")[0]; - if (linkclicked) { - const linkDoc = await DocServer.GetRefField(linkclicked); - if (linkDoc instanceof Doc) { - const anchor1 = await Cast(linkDoc.anchor1, Doc); - const anchor2 = await Cast(linkDoc.anchor2, Doc); - const currentDoc = SelectionManager.SelectedDocuments().length && SelectionManager.SelectedDocuments()[0].props.Document; - if (currentDoc && anchor1 && anchor2) { - if (Doc.AreProtosEqual(currentDoc, anchor1)) { - return StrCast(anchor2.title); - } - if (Doc.AreProtosEqual(currentDoc, anchor2)) { - return StrCast(anchor1.title); - } - } - } - } - } else { - return href; - } - } else { - return link.attrs.title; - } - } - } - - // LINK TOOL - createLinkTool(active: boolean = false) { - return new MenuItem({ - title: "Link tool", - label: "Link tool", - icon: icons.link, - css: "fill:white;", - class: active ? "menuicon-active" : "menuicon", - execEvent: "", - run: async (state, dispatch) => { }, - active: (state) => true - }); - } - - createLinkDropdown(targetTitle: string) { - const input = document.createElement("input"); - - // menu item for input for hyperlink url - // TODO: integrate search to allow users to search for a doc to link to - const linkInfo = new MenuItem({ - title: "", - execEvent: "", - class: "button-setting-disabled", - css: "", - render() { - const p = document.createElement("p"); - p.textContent = "Linked to:"; - - input.type = "text"; - input.placeholder = "Enter URL"; - if (targetTitle) input.value = targetTitle; - input.onclick = (e: MouseEvent) => { - input.select(); - input.focus(); - }; - - const div = document.createElement("div"); - div.appendChild(p); - div.appendChild(input); - return div; - }, - enable() { return false; }, - run(p1, p2, p3, event) { event.stopPropagation(); } - }); - - // menu item to update/apply the hyperlink to the selected text - const linkApply = new MenuItem({ - title: "", - execEvent: "", - class: "", - css: "", - render() { - const button = document.createElement("button"); - button.className = "link-url-button"; - button.textContent = "Apply hyperlink"; - return button; - }, - enable() { return false; }, - run: async (state, dispatch, view, event) => { - event.stopPropagation(); - let node = this.view.state.selection.$from.nodeAfter; - let link = this.view.state.schema.mark(this.view.state.schema.marks.link, { href: input.value, location: "onRight" }); - this.view.dispatch(this.view.state.tr.removeMark(this.view.state.selection.from, this.view.state.selection.to, this.view.state.schema.marks.link)); - this.view.dispatch(this.view.state.tr.addMark(this.view.state.selection.from, this.view.state.selection.to, link)); - node = this.view.state.selection.$from.nodeAfter; - link = node && node.marks.find(m => m.type.name === "link"); - - // update link menu - const linkDom = self.createLinkTool(true).render(self.view).dom; - const linkDropdownDom = self.createLinkDropdown(await self.getTextLinkTargetTitle()).render(self.view).dom; - self.linkDom && self.tooltip.replaceChild(linkDom, self.linkDom); - self.linkDropdownDom && self.tooltip.replaceChild(linkDropdownDom, self.linkDropdownDom); - self.linkDom = linkDom; - self.linkDropdownDom = linkDropdownDom; - } - }); - - // menu item to remove the link - // TODO: allow this to be undoable - const self = this; - const deleteLink = new MenuItem({ - title: "Delete link", - execEvent: "", - class: "separated-button", - css: "", - render() { - const button = document.createElement("button"); - button.textContent = "Remove link"; - - const wrapper = document.createElement("div"); - wrapper.appendChild(button); - return wrapper; - }, - enable() { return true; }, - async run() { - // delete the link - const node = self.view.state.selection.$from.nodeAfter; - const link = node && node.marks.find(m => m.type === self.view.state.schema.marks.link); - const href = link!.attrs.href; - if (href ?.indexOf(Utils.prepend("/doc/")) === 0) { - const linkclicked = href.replace(Utils.prepend("/doc/"), "").split("?")[0]; - linkclicked && DocServer.GetRefField(linkclicked).then(async linkDoc => { - if (linkDoc instanceof Doc) { - LinkManager.Instance.deleteLink(linkDoc); - self.view.dispatch(self.view.state.tr.removeMark(self.view.state.selection.from, self.view.state.selection.to, self.view.state.schema.marks.link)); - } - }); - } - // update link menu - const linkDom = self.createLinkTool(false).render(self.view).dom; - const linkDropdownDom = self.createLinkDropdown("").render(self.view).dom; - self.linkDom && self.tooltip.replaceChild(linkDom, self.linkDom); - self.linkDropdownDom && self.tooltip.replaceChild(linkDropdownDom, self.linkDropdownDom); - self.linkDom = linkDom; - self.linkDropdownDom = linkDropdownDom; - } - }); - - return new Dropdown(targetTitle ? [linkInfo, linkApply, deleteLink] : [linkInfo, linkApply], { class: "buttonSettings-dropdown" }) as MenuItem; - } - - public MakeLinkToSelection = (linkDocId: string, title: string, location: string, targetDocId: string): string => { - const link = this.view.state.schema.marks.link.create({ href: Utils.prepend("/doc/" + linkDocId), title: title, location: location, targetId: targetDocId }); - this.view.dispatch(this.view.state.tr.removeMark(this.view.state.selection.from, this.view.state.selection.to, this.view.state.schema.marks.link). - addMark(this.view.state.selection.from, this.view.state.selection.to, link)); - return this.view.state.selection.$from.nodeAfter ?.text || ""; - } - - // SUMMARIZER TOOL - static insertSummarizer(state: EditorState<any>, dispatch: any) { - if (!state.selection.empty) { - const mark = state.schema.marks.summarize.create(); - const tr = state.tr.addMark(state.selection.from, state.selection.to, mark); - const content = tr.selection.content(); - const newNode = state.schema.nodes.summary.create({ visibility: false, text: content, textslice: content.toJSON() }); - dispatch ?.(tr.replaceSelectionWith(newNode).removeMark(tr.selection.from - 1, tr.selection.from, mark)); - } - } - - // HIGHLIGHTER TOOL - createHighlightTool() { - return new MenuItem({ - title: "Highlight", - css: "fill:white;", - class: "menuicon", - execEvent: "", - render() { - const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); - svg.setAttribute("viewBox", "-100 -100 650 650"); - const path = document.createElementNS('http://www.w3.org/2000/svg', "path"); - path.setAttributeNS(null, "d", "M0 479.98L99.92 512l35.45-35.45-67.04-67.04L0 479.98zm124.61-240.01a36.592 36.592 0 0 0-10.79 38.1l13.05 42.83-50.93 50.94 96.23 96.23 50.86-50.86 42.74 13.08c13.73 4.2 28.65-.01 38.15-10.78l35.55-41.64-173.34-173.34-41.52 35.44zm403.31-160.7l-63.2-63.2c-20.49-20.49-53.38-21.52-75.12-2.35L190.55 183.68l169.77 169.78L530.27 154.4c19.18-21.74 18.15-54.63-2.35-75.13z"); - svg.appendChild(path); - - const color = TooltipTextMenu.createDiv("buttonColor"); - color.style.backgroundColor = TooltipTextMenuManager.Instance.highlighter.toString(); - - const wrapper = TooltipTextMenu.createDiv("colorPicker"); - wrapper.appendChild(svg); - wrapper.appendChild(color); - return wrapper; - }, - run: (state, dispatch) => TooltipTextMenu.insertHighlight(TooltipTextMenuManager.Instance.highlighter, state, dispatch) - }); - } - - static insertHighlight(color: String, state: EditorState<any>, dispatch: any) { - if (!state.selection.empty) { - toggleMark(state.schema.marks.marker, { highlight: color })(state, dispatch); - } - } - - createHighlightDropdown() { - // menu item for color picker - const self = this; - const colors = new MenuItem({ - title: "", - execEvent: "", - class: "button-setting-disabled", - css: "", - render() { - const p = document.createElement("p"); - p.textContent = "Change highlight:"; - - const colorsWrapper = TooltipTextMenu.createDiv("colorPicker-wrapper"); - - const colors = [ - PastelSchemaPalette.get("pink2"), - PastelSchemaPalette.get("purple4"), - PastelSchemaPalette.get("bluegreen1"), - PastelSchemaPalette.get("yellow4"), - PastelSchemaPalette.get("red2"), - PastelSchemaPalette.get("bluegreen7"), - PastelSchemaPalette.get("bluegreen5"), - PastelSchemaPalette.get("orange1"), - "white", - "transparent" - ]; - - colors.forEach(color => { - const button = document.createElement("button"); - button.className = color === TooltipTextMenuManager.Instance.highlighter ? "colorPicker active" : "colorPicker"; - if (color) { - button.style.backgroundColor = color; - button.textContent = color === "transparent" ? "X" : ""; - button.onclick = e => { - TooltipTextMenuManager.Instance.highlighter = color; - - TooltipTextMenu.insertHighlight(TooltipTextMenuManager.Instance.highlighter, self.view.state, self.view.dispatch); - - // update color menu - const highlightDom = self.createHighlightTool().render(self.view).dom; - const highlightDropdownDom = self.createHighlightDropdown().render(self.view).dom; - self.highighterDom && self.tooltip.replaceChild(highlightDom, self.highighterDom); - self.highlighterDropdownDom && self.tooltip.replaceChild(highlightDropdownDom, self.highlighterDropdownDom); - self.highighterDom = highlightDom; - self.highlighterDropdownDom = highlightDropdownDom; - }; - } - colorsWrapper.appendChild(button); - }); - - const div = document.createElement("div"); - div.appendChild(p); - div.appendChild(colorsWrapper); - return div; - }, - enable() { return false; }, - run(p1, p2, p3, event) { - event.stopPropagation(); - } - }); - - return new Dropdown([colors], { class: "buttonSettings-dropdown" }) as MenuItem; - } - - // COLOR TOOL - createColorTool() { - return new MenuItem({ - title: "Color", - css: "fill:white;", - class: "menuicon", - execEvent: "", - render() { - const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); - svg.setAttribute("viewBox", "-100 -100 650 650"); - const path = document.createElementNS('http://www.w3.org/2000/svg', "path"); - path.setAttributeNS(null, "d", "M204.3 5C104.9 24.4 24.8 104.3 5.2 203.4c-37 187 131.7 326.4 258.8 306.7 41.2-6.4 61.4-54.6 42.5-91.7-23.1-45.4 9.9-98.4 60.9-98.4h79.7c35.8 0 64.8-29.6 64.9-65.3C511.5 97.1 368.1-26.9 204.3 5zM96 320c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm32-128c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm128-64c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm128 64c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32z"); - svg.appendChild(path); - - const color = TooltipTextMenu.createDiv("buttonColor"); - color.style.backgroundColor = TooltipTextMenuManager.Instance.color.toString(); - - const wrapper = TooltipTextMenu.createDiv("colorPicker"); - wrapper.appendChild(svg); - wrapper.appendChild(color); - return wrapper; - }, - run: (state, dispatch) => TooltipTextMenu.insertColor(TooltipTextMenuManager.Instance.color, state, dispatch) - }); - } - - static insertColor(color: String, state: EditorState<any>, dispatch: any) { - const colorMark = state.schema.mark(state.schema.marks.pFontColor, { color: color }); - if (state.selection.empty) { - dispatch(state.tr.addStoredMark(colorMark)); - } else { - this.setMark(colorMark, state, dispatch); - } - } - - createColorDropdown() { - // menu item for color picker - const self = this; - const colors = new MenuItem({ - title: "", - execEvent: "", - class: "button-setting-disabled", - css: "", - render() { - const p = document.createElement("p"); - p.textContent = "Change color:"; - - const colorsWrapper = TooltipTextMenu.createDiv("colorPicker-wrapper"); - - const colors = [ - DarkPastelSchemaPalette.get("pink2"), - DarkPastelSchemaPalette.get("purple4"), - DarkPastelSchemaPalette.get("bluegreen1"), - DarkPastelSchemaPalette.get("yellow4"), - DarkPastelSchemaPalette.get("red2"), - DarkPastelSchemaPalette.get("bluegreen7"), - DarkPastelSchemaPalette.get("bluegreen5"), - DarkPastelSchemaPalette.get("orange1"), - "#757472", - "#000" - ]; - - colors.forEach(color => { - const button = document.createElement("button"); - button.className = color === TooltipTextMenuManager.Instance.color ? "colorPicker active" : "colorPicker"; - if (color) { - button.style.backgroundColor = color; - button.onclick = e => { - TooltipTextMenuManager.Instance.color = color; - - TooltipTextMenu.insertColor(TooltipTextMenuManager.Instance.color, self.view.state, self.view.dispatch); - - // update color menu - const colorDom = self.createColorTool().render(self.view).dom; - const colorDropdownDom = self.createColorDropdown().render(self.view).dom; - self.colorDom && self.tooltip.replaceChild(colorDom, self.colorDom); - self.colorDropdownDom && self.tooltip.replaceChild(colorDropdownDom, self.colorDropdownDom); - self.colorDom = colorDom; - self.colorDropdownDom = colorDropdownDom; - }; - } - colorsWrapper.appendChild(button); - }); - - const div = document.createElement("div"); - div.appendChild(p); - div.appendChild(colorsWrapper); - return div; - }, - enable() { return false; }, - run(p1, p2, p3, event) { event.stopPropagation(); } - }); - - return new Dropdown([colors], { class: "buttonSettings-dropdown" }) as MenuItem; - } - - // BRUSH TOOL - createBrushTool(active: boolean = false) { - const icon = { - height: 32, width: 32, - path: "M30.828 1.172c-1.562-1.562-4.095-1.562-5.657 0l-5.379 5.379-3.793-3.793-4.243 4.243 3.326 3.326-14.754 14.754c-0.252 0.252-0.358 0.592-0.322 0.921h-0.008v5c0 0.552 0.448 1 1 1h5c0 0 0.083 0 0.125 0 0.288 0 0.576-0.11 0.795-0.329l14.754-14.754 3.326 3.326 4.243-4.243-3.793-3.793 5.379-5.379c1.562-1.562 1.562-4.095 0-5.657zM5.409 30h-3.409v-3.409l14.674-14.674 3.409 3.409-14.674 14.674z" - }; - const self = this; - return new MenuItem({ - title: "Brush tool", - label: "Brush tool", - icon: icon, - css: "fill:white;", - class: active ? "menuicon-active" : "menuicon", - execEvent: "", - run: (state, dispatch) => { - this.brush_function(state, dispatch); - - // update dropdown with marks - const newBrushDropdowndom = self.createBrushDropdown().render(self.view).dom; - self._brushDropdownDom && self.tooltip.replaceChild(newBrushDropdowndom, self._brushDropdownDom); - self._brushDropdownDom = newBrushDropdowndom; - }, - active: (state) => true - }); - } - - brush_function(state: EditorState<any>, dispatch: any) { - if (TooltipTextMenuManager.Instance._brushIsEmpty) { - // get marks in the selection - const selected_marks = new Set<Mark>(); - const { from, to } = state.selection as TextSelection; - state.doc.nodesBetween(from, to, (node) => node.marks ?.forEach(m => selected_marks.add(m))); - - if (this._brushdom && selected_marks.size >= 0) { - TooltipTextMenuManager.Instance._brushMarks = selected_marks; - const newbrush = this.createBrushTool(true).render(this.view).dom; - this.tooltip.replaceChild(newbrush, this._brushdom); - this._brushdom = newbrush; - TooltipTextMenuManager.Instance._brushIsEmpty = !TooltipTextMenuManager.Instance._brushIsEmpty; - } - } - else { - const { from, to, $from } = this.view.state.selection; - if (this._brushdom) { - if (!this.view.state.selection.empty && $from && $from.nodeAfter) { - if (TooltipTextMenuManager.Instance._brushMarks && to - from > 0) { - this.view.dispatch(this.view.state.tr.removeMark(from, to)); - Array.from(TooltipTextMenuManager.Instance._brushMarks).filter(m => m.type !== schema.marks.user_mark).forEach((mark: Mark) => { - TooltipTextMenu.setMark(mark, this.view.state, this.view.dispatch); - }); - } - } - else { - const newbrush = this.createBrushTool(false).render(this.view).dom; - this.tooltip.replaceChild(newbrush, this._brushdom); - this._brushdom = newbrush; - TooltipTextMenuManager.Instance._brushIsEmpty = !TooltipTextMenuManager.Instance._brushIsEmpty; - } - } - } - } - - createBrushDropdown(active: boolean = false) { - let label = "Stored marks: "; - if (TooltipTextMenuManager.Instance._brushMarks && TooltipTextMenuManager.Instance._brushMarks.size > 0) { - TooltipTextMenuManager.Instance._brushMarks.forEach((mark: Mark) => label += mark.type.name + ", "); - label = label.substring(0, label.length - 2); - } else { - label = "No marks are currently stored"; - } - - const brushInfo = new MenuItem({ - title: "", - label: label, - execEvent: "", - class: "button-setting-disabled", - css: "", - enable() { return false; }, - run(p1, p2, p3, event) { event.stopPropagation(); } - }); - - const self = this; - const input = document.createElement("input"); - const clearBrush = new MenuItem({ - title: "Clear brush", - execEvent: "", - class: "separated-button", - css: "", - render() { - const button = document.createElement("button"); - button.textContent = "Clear brush"; - - input.textContent = "editme"; - input.style.width = "75px"; - input.style.height = "30px"; - input.style.background = "white"; - input.setAttribute("contenteditable", "true"); - input.style.whiteSpace = "nowrap"; - input.type = "text"; - input.placeholder = "Enter URL"; - input.onpointerdown = (e: PointerEvent) => { - e.stopPropagation(); - e.preventDefault(); - }; - input.onclick = (e: MouseEvent) => { - input.select(); - input.focus(); - }; - input.onkeypress = (e: KeyboardEvent) => { - if (e.key === "Enter") { - TooltipTextMenuManager.Instance._brushMarks && TooltipTextMenuManager.Instance._brushMap.set(input.value, TooltipTextMenuManager.Instance._brushMarks); - input.style.background = "lightGray"; - } - }; - - const wrapper = document.createElement("div"); - wrapper.appendChild(input); - wrapper.appendChild(button); - return wrapper; - }, - enable() { return true; }, - run() { - TooltipTextMenuManager.Instance._brushIsEmpty = true; - TooltipTextMenuManager.Instance._brushMarks = new Set(); - - // update brush tool - // TODO: this probably isn't very clean - const newBrushdom = self.createBrushTool().render(self.view).dom; - self._brushdom && self.tooltip.replaceChild(newBrushdom, self._brushdom); - self._brushdom = newBrushdom; - const newBrushDropdowndom = self.createBrushDropdown().render(self.view).dom; - self._brushDropdownDom && self.tooltip.replaceChild(newBrushDropdowndom, self._brushDropdownDom); - self._brushDropdownDom = newBrushDropdowndom; - } - }); - - const hasMarks = TooltipTextMenuManager.Instance._brushMarks && TooltipTextMenuManager.Instance._brushMarks.size > 0; - return new Dropdown(hasMarks ? [brushInfo, clearBrush] : [brushInfo], { class: "buttonSettings-dropdown" }) as MenuItem; - } - - static setMark = (mark: Mark, state: EditorState<any>, dispatch: any) => { - if (mark) { - const node = (state.selection as NodeSelection).node; - if (node ?.type === schema.nodes.ordered_list) { - let attrs = node.attrs; - if (mark.type === schema.marks.pFontFamily) attrs = { ...attrs, setFontFamily: mark.attrs.family }; - if (mark.type === schema.marks.pFontSize) attrs = { ...attrs, setFontSize: mark.attrs.fontSize }; - if (mark.type === schema.marks.pFontColor) attrs = { ...attrs, setFontColor: mark.attrs.color }; - const tr = updateBullets(state.tr.setNodeMarkup(state.selection.from, node.type, attrs), state.schema); - dispatch(tr.setSelection(new NodeSelection(tr.doc.resolve(state.selection.from)))); - } else { - toggleMark(mark.type, mark.attrs)(state, (tx: any) => { - const { from, $from, to, empty } = tx.selection; - if (!tx.doc.rangeHasMark(from, to, mark.type)) { - toggleMark(mark.type, mark.attrs)({ tr: tx, doc: tx.doc, selection: tx.selection, storedMarks: tx.storedMarks }, dispatch); - } else dispatch(tx); - }); - } - } - } - - // called by Prosemirror - update(view: EditorView, lastState: EditorState | undefined) { this.updateFromDash(view, lastState, this.editorProps); } - //updates the tooltip menu when the selection changes - public async updateFromDash(view: EditorView, lastState: EditorState | undefined, props: any) { - if (!view) { - console.log("no editor? why?"); - return; - } - this.view = view; - DocumentDecorations.Instance.showTextBar(); - props && (this.editorProps = props); - - // Don't do anything if the document/selection didn't change - if (!lastState || !lastState.doc.eq(view.state.doc) || !lastState.selection.eq(view.state.selection)) { - - // UPDATE LINK DROPDOWN - const linkTarget = await this.getTextLinkTargetTitle(); - const linkDom = this.createLinkTool(linkTarget ? true : false).render(this.view).dom; - const linkDropdownDom = this.createLinkDropdown(linkTarget).render(this.view).dom; - this.linkDom && this.tooltip.replaceChild(linkDom, this.linkDom); - this.linkDropdownDom && this.tooltip.replaceChild(linkDropdownDom, this.linkDropdownDom); - this.linkDom = linkDom; - this.linkDropdownDom = linkDropdownDom; - - //UPDATE FONT STYLE DROPDOWN - const activeStyles = this.activeFontFamilyOnSelection(); - this.updateFontStyleDropdown(activeStyles.length === 1 ? activeStyles[0] : activeStyles.length ? "various" : "default"); - - //UPDATE FONT SIZE DROPDOWN - const activeSizes = this.activeFontSizeOnSelection(); - this.updateFontSizeDropdown(activeSizes.length === 1 ? String(activeSizes[0]) + " pt" : activeSizes.length ? "various" : "default"); - - //UPDATE ALL OTHER BUTTONS - this.updateHighlightStateOfButtons(); - } - } - - updateHighlightStateOfButtons() { - Array.from(this._marksToDoms.values()).forEach(val => val.style.fill = "white"); - this.activeMarksOnSelection().filter(mark => this._marksToDoms.has(mark)).forEach(mark => - this._marksToDoms.get(mark)!.style.fill = "greenyellow"); - - // keeps brush tool highlighted if active when switching between textboxes - if (!TooltipTextMenuManager.Instance._brushIsEmpty && this._brushdom) { - const newbrush = this.createBrushTool(true).render(this.view).dom; - this.tooltip.replaceChild(newbrush, this._brushdom); - this._brushdom = newbrush; - } - } - - //finds fontSize at start of selection - activeFontSizeOnSelection() { - //current selection - const state = this.view.state; - const activeSizes: number[] = []; - const pos = this.view.state.selection.$from; - const ref_node: ProsNode = this.reference_node(pos); - if (ref_node && ref_node !== this.view.state.doc && ref_node.isText) { - ref_node.marks.forEach(m => m.type === state.schema.marks.pFontSize && activeSizes.push(m.attrs.fontSize)); - } - return activeSizes; - } - //finds fontSize at start of selection - activeFontFamilyOnSelection() { - //current selection - const state = this.view.state; - const activeFamilies: string[] = []; - const pos = this.view.state.selection.$from; - const ref_node: ProsNode = this.reference_node(pos); - if (ref_node && ref_node !== this.view.state.doc && ref_node.isText) { - ref_node.marks.forEach(m => m.type === state.schema.marks.pFontFamily && activeFamilies.push(m.attrs.family)); - } - return activeFamilies; - } - //finds all active marks on selection in given group - activeMarksOnSelection() { - const markGroup = Array.from(this._marksToDoms.keys()); - if (this.view.state.storedMarks) return this.view.state.storedMarks.map(mark => mark.type); - //current selection - const { empty, ranges, $to } = this.view.state.selection as TextSelection; - const state = this.view.state; - let activeMarks: MarkType[] = []; - if (!empty) { - activeMarks = markGroup.filter(mark => { - const has = false; - for (let i = 0; !has && i < ranges.length; i++) { - return state.doc.rangeHasMark(ranges[i].$from.pos, ranges[i].$to.pos, mark); - } - return false; - }); - } - else { - const pos = this.view.state.selection.$from; - const ref_node: ProsNode = this.reference_node(pos); - if (ref_node !== null && ref_node !== this.view.state.doc) { - if (ref_node.isText) { - } - else { - return []; - } - activeMarks = markGroup.filter(mark_type => { - if (mark_type === state.schema.marks.pFontSize) { - return ref_node.marks.some(m => m.type.name === state.schema.marks.pFontSize.name); - } - const mark = state.schema.mark(mark_type); - return ref_node.marks.includes(mark); - }); - } - } - return activeMarks; - } - - reference_node(pos: ResolvedPos<any>): ProsNode { - let ref_node: ProsNode = this.view.state.doc; - if (pos.nodeBefore !== null && pos.nodeBefore !== undefined) { - ref_node = pos.nodeBefore; - } - else if (pos.nodeAfter !== null && pos.nodeAfter !== undefined) { - ref_node = pos.nodeAfter; - } - else if (pos.pos > 0) { - let skip = false; - for (let i: number = pos.pos - 1; i > 0; i--) { - this.view.state.doc.nodesBetween(i, pos.pos, (node: ProsNode) => { - if (node.isLeaf && !skip) { - ref_node = node; - skip = true; - } - - }); - } - } - if (!ref_node.isLeaf && ref_node.childCount > 0) { - ref_node = ref_node.child(0); - } - return ref_node; - } - - destroy() { - // this.wrapper.remove(); - } -} - - -export class TooltipTextMenuManager { - private static _instance: TooltipTextMenuManager; - private _isPinned: boolean = false; - - public pinnedX: number = 0; - public pinnedY: number = 0; - public unpinnedX: number = 0; - public unpinnedY: number = 0; - - public _brushMarks: Set<Mark> | undefined; - public _brushMap: Map<string, Set<Mark>> = new Map(); - public _brushIsEmpty: boolean = true; - - public color: String = "#000"; - public highlighter: String = "transparent"; - - public activeMenu: TooltipTextMenu | undefined; - - static get Instance() { - if (!TooltipTextMenuManager._instance) { - TooltipTextMenuManager._instance = new TooltipTextMenuManager(); - } - return TooltipTextMenuManager._instance; - } - - public get isPinned() { return this._isPinned; } - - public toggleIsPinned() { this._isPinned = !this._isPinned; } -} diff --git a/src/client/util/request-image-size.js b/src/client/util/request-image-size.js index 27605d167..beb030635 100644 --- a/src/client/util/request-image-size.js +++ b/src/client/util/request-image-size.js @@ -38,7 +38,7 @@ module.exports = function requestImageSize(options) { return reject(new HttpError(res.statusCode, res.statusMessage)); } - let buffer = new Buffer([]); + let buffer = new Buffer.from([]); let size; let imageSizeError; diff --git a/src/client/util/type_decls.d b/src/client/util/type_decls.d index 622e10960..127f7b798 100644 --- a/src/client/util/type_decls.d +++ b/src/client/util/type_decls.d @@ -131,6 +131,7 @@ interface Promise<T> { declare const Update: unique symbol; declare const Self: unique symbol; declare const SelfProxy: unique symbol; +declare const DataSym: unique symbol; declare const HandleUpdate: unique symbol; declare const Id: unique symbol; declare const OnUpdate: unique symbol; diff --git a/src/client/views/ContextMenu.tsx b/src/client/views/ContextMenu.tsx index 937aff0d6..ac803d977 100644 --- a/src/client/views/ContextMenu.tsx +++ b/src/client/views/ContextMenu.tsx @@ -77,8 +77,13 @@ export class ContextMenu extends React.Component { @action clearItems() { this._items = []; + this._defaultPrefix = ""; + this._defaultItem = undefined; } + _defaultPrefix: string = ""; + _defaultItem: ((name: string) => void) | undefined; + findByDescription = (target: string, toLowerCase = false) => { return this._items.find(menuItem => { let reference = menuItem.description; @@ -93,6 +98,11 @@ export class ContextMenu extends React.Component { this._items.push(item); } } + @action + setDefaultItem(prefix: string, item: (name: string) => void) { + this._defaultPrefix = prefix; + this._defaultItem = item; + } getItems() { return this._items; @@ -248,7 +258,11 @@ export class ContextMenu extends React.Component { e.preventDefault(); } else if (e.key === "Enter" || e.key === "Tab") { const item = this.flatItems[this.selectedIndex]; - item && item.event({ x: this.pageX, y: this.pageY }); + if (item) { + item.event({ x: this.pageX, y: this.pageY }); + } else if (this._searchString.startsWith(this._defaultPrefix)) { + this._defaultItem?.(this._searchString.substring(this._defaultPrefix.length)); + } this.closeMenu(); e.preventDefault(); } diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx index 4dbf26956..ce48e1215 100644 --- a/src/client/views/DocComponent.tsx +++ b/src/client/views/DocComponent.tsx @@ -34,8 +34,7 @@ export function DocExtendableComponent<P extends DocExtendableProps, T>(schemaCt //TODO This might be pretty inefficient if doc isn't observed, because computed doesn't cache then @computed get Document(): T { return schemaCtor(this.props.Document); } @computed get layoutDoc() { return Doc.Layout(this.props.Document); } - @computed get dataDoc() { return (this.props.DataDoc && (this.props.Document.isTemplateField || this.props.Document.isTemplateDoc) ? this.props.DataDoc : Doc.GetProto(this.props.Document)) as Doc; } - @computed get extensionDoc() { return Doc.fieldExtensionDoc(this.dataDoc, this.props.fieldKey); } + @computed get dataDoc() { return (this.props.DataDoc && (this.props.Document.isTemplateForField || this.props.Document.isTemplateDoc) ? this.props.DataDoc : Cast(this.props.Document.resolvedDataDoc, Doc, null) || Doc.GetProto(this.props.Document)) as Doc; } active = (outsideReaction?: boolean) => !this.props.Document.isBackground && (this.props.Document.forceActive || this.props.isSelected(outsideReaction) || this.props.renderDepth === 0);// && !InkingControl.Instance.selectedTool; // bcz: inking state shouldn't affect static tools } return Component; @@ -43,7 +42,7 @@ export function DocExtendableComponent<P extends DocExtendableProps, T>(schemaCt /// DocAnnotatbleComponent return a base class for React views of document fields that are annotatable *and* interactive when selected (e.g., pdf, image) -interface DocAnnotatableProps { +export interface DocAnnotatableProps { Document: Doc; DataDoc?: Doc; fieldKey: string; @@ -58,15 +57,16 @@ export function DocAnnotatableComponent<P extends DocAnnotatableProps, T>(schema //TODO This might be pretty inefficient if doc isn't observed, because computed doesn't cache then @computed get Document(): T { return schemaCtor(this.props.Document); } @computed get layoutDoc() { return Doc.Layout(this.props.Document); } - @computed get dataDoc() { return (this.props.DataDoc && (this.props.Document.isTemplateField || this.props.Document.isTemplateDoc) ? this.props.DataDoc : Doc.GetProto(this.props.Document)) as Doc; } - @computed get extensionDoc() { return Doc.fieldExtensionDoc(this.dataDoc, this.props.fieldKey); } - @computed get extensionDocSync() { return Doc.fieldExtensionDocSync(this.dataDoc, this.props.fieldKey); } - @computed get annotationsKey() { return "annotations"; } + @computed get dataDoc() { return (this.props.DataDoc && (this.props.Document.isTemplateForField || this.props.Document.isTemplateDoc) ? this.props.DataDoc : Cast(this.props.Document.resolvedDataDoc, Doc, null) || Doc.GetProto(this.props.Document)) as Doc; } + + _annotationKey: string = "annotations"; + public set annotationKey(val: string) { this._annotationKey = val; } + public get annotationKey() { return this._annotationKey; } @action.bound removeDocument(doc: Doc): boolean { Doc.GetProto(doc).annotationOn = undefined; - const value = this.extensionDoc && Cast(this.extensionDoc[this.annotationsKey], listSpec(Doc), []); + const value = Cast(this.dataDoc[this.props.fieldKey + "-" + this._annotationKey], listSpec(Doc), []); const index = value ? Doc.IndexOf(doc, value.map(d => d as Doc), true) : -1; return index !== -1 && value && value.splice(index, 1) ? true : false; } @@ -79,7 +79,7 @@ export function DocAnnotatableComponent<P extends DocAnnotatableProps, T>(schema @action.bound addDocument(doc: Doc): boolean { Doc.GetProto(doc).annotationOn = this.props.Document; - return this.extensionDoc && Doc.AddDocToList(this.extensionDoc, this.annotationsKey, doc) ? true : false; + return Doc.AddDocToList(this.dataDoc, this.props.fieldKey + "-" + this._annotationKey, doc) ? true : false; } whenActiveChanged = action((isActive: boolean) => this.props.whenActiveChanged(this._isChildActive = isActive)); diff --git a/src/client/views/DocumentButtonBar.tsx b/src/client/views/DocumentButtonBar.tsx index 202bfe400..65d1ade2a 100644 --- a/src/client/views/DocumentButtonBar.tsx +++ b/src/client/views/DocumentButtonBar.tsx @@ -1,26 +1,28 @@ import { IconProp, library } from '@fortawesome/fontawesome-svg-core'; import { faArrowAltCircleDown, faArrowAltCircleUp, faCheckCircle, faCloudUploadAlt, faLink, faShare, faStopCircle, faSyncAlt, faTag, faTimes } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { action, observable, runInAction, computed } from "mobx"; +import { action, computed, observable, runInAction } from "mobx"; import { observer } from "mobx-react"; import { Doc, DocListCast } from "../../new_fields/Doc"; +import { Id } from '../../new_fields/FieldSymbols'; import { RichTextField } from '../../new_fields/RichTextField'; -import { NumCast, StrCast, Cast } from "../../new_fields/Types"; +import { NumCast, StrCast } from "../../new_fields/Types"; import { emptyFunction } from "../../Utils"; import { Pulls, Pushes } from '../apis/google_docs/GoogleApiClientUtils'; -import { DragManager } from "../util/DragManager"; +import RichTextMenu from '../util/RichTextMenu'; import { UndoManager } from "../util/UndoManager"; -import './DocumentButtonBar.scss'; +import { CollectionDockingView } from './collections/CollectionDockingView'; +import { ParentDocSelector } from './collections/ParentDocumentSelector'; import './collections/ParentDocumentSelector.scss'; +import './DocumentButtonBar.scss'; import { LinkMenu } from "./linking/LinkMenu"; -import { FormattedTextBox, GoogleRef } from "./nodes/FormattedTextBox"; +import { DocumentView } from './nodes/DocumentView'; +import { GoogleRef } from "./nodes/FormattedTextBox"; import { TemplateMenu } from "./TemplateMenu"; import { Template, Templates } from "./Templates"; import React = require("react"); -import { DocumentView } from './nodes/DocumentView'; -import { ParentDocSelector } from './collections/ParentDocumentSelector'; -import { CollectionDockingView } from './collections/CollectionDockingView'; -import { Id } from '../../new_fields/FieldSymbols'; +import { DragManager } from '../util/DragManager'; +import { MetadataEntryMenu } from './MetadataEntryMenu'; const higflyout = require("@hig/flyout"); export const { anchorPoints } = higflyout; export const Flyout = higflyout.default; @@ -42,6 +44,7 @@ const fetch: IconProp = "sync-alt"; @observer export class DocumentButtonBar extends React.Component<{ views: (DocumentView | undefined)[], stack?: any }, {}> { private _linkButton = React.createRef<HTMLDivElement>(); + private _dragRef = React.createRef<HTMLDivElement>(); private _downX = 0; private _downY = 0; private _pullAnimating = false; @@ -112,14 +115,15 @@ export class DocumentButtonBar extends React.Component<{ views: (DocumentView | const linkDrag = UndoManager.StartBatch("Drag Link"); this.view0 && DragManager.StartLinkDrag(this._linkButton.current, this.view0.props.Document, e.pageX, e.pageY, { dragComplete: dropEv => { - const linkDoc = dropEv.linkDragData?.linkDocument; // equivalent to !dropEve.aborted since linkDocument is only assigned on a completed drop - if (this.view0 && linkDoc && FormattedTextBox.ToolTipTextMenu) { + const linkDoc = dropEv.linkDragData?.linkDocument as Doc; // equivalent to !dropEve.aborted since linkDocument is only assigned on a completed drop + if (this.view0 && linkDoc) { const proto = Doc.GetProto(linkDoc); proto.sourceContext = this.view0.props.ContainingCollectionDoc; const anchor2Title = linkDoc.anchor2 instanceof Doc ? StrCast(linkDoc.anchor2.title) : "-untitled-"; + const anchor2Id = linkDoc.anchor2 instanceof Doc ? linkDoc.anchor2[Id] : ""; + const text = RichTextMenu.Instance.MakeLinkToSelection(linkDoc[Id], anchor2Title, e.ctrlKey ? "onRight" : "inTab", anchor2Id); if (linkDoc.anchor2 instanceof Doc) { - const text = FormattedTextBox.ToolTipTextMenu.MakeLinkToSelection(linkDoc[Id], anchor2Title, e.ctrlKey ? "onRight" : "inTab", linkDoc.anchor2[Id]); proto.title = text === "" ? proto.title : text + " to " + linkDoc.anchor2.title; // TODO open to more descriptive descriptions of following in text link } } @@ -199,7 +203,7 @@ export class DocumentButtonBar extends React.Component<{ views: (DocumentView | const view0 = this.view0; const linkCount = view0 && DocListCast(view0.props.Document.links).length; return !view0 ? (null) : <div title="Drag(create link) Tap(view links)" className="documentButtonBar-linkFlyout" ref={this._linkButton}> - <Flyout anchorPoint={anchorPoints.RIGHT_TOP} + <Flyout anchorPoint={anchorPoints.LEFT_TOP} content={<LinkMenu docView={view0} addDocTab={view0.props.addDocTab} changeFlyout={emptyFunction} />}> <div className={"documentButtonBar-linkButton-" + (linkCount ? "nonempty" : "empty")} onPointerDown={this.onLinkButtonDown} > {linkCount ? linkCount : <FontAwesomeIcon className="documentdecorations-icon" icon="link" size="sm" />} @@ -209,6 +213,19 @@ export class DocumentButtonBar extends React.Component<{ views: (DocumentView | } @computed + get metadataButton() { + const view0 = this.view0; + return !view0 ? (null) : <div title="Show metadata panel" className="documentButtonBar-linkFlyout" ref={this._linkButton}> + <Flyout anchorPoint={anchorPoints.LEFT_TOP} + content={<MetadataEntryMenu docs={() => this.props.views.filter(dv => dv).map(dv => dv!.props.Document)} suggestWithFunction /> /* tfs: @bcz This might need to be the data document? */}> + <div className={"documentButtonBar-linkButton-" + "empty"} > + {<FontAwesomeIcon className="documentdecorations-icon" icon="tag" size="sm" />} + </div> + </Flyout> + </div>; + } + + @computed get contextButton() { return !this.view0 ? (null) : <ParentDocSelector Views={this.props.views.filter(v => v).map(v => v as DocumentView)} Document={this.view0.props.Document} addDocTab={(doc, data, where) => { where === "onRight" ? CollectionDockingView.AddRightSplit(doc, data) : @@ -218,11 +235,61 @@ export class DocumentButtonBar extends React.Component<{ views: (DocumentView | }} />; } - render() { - if (!this.view0) return (null); + private _downx = 0; + private _downy = 0; + onAliasButtonUp = (e: PointerEvent): void => { + document.removeEventListener("pointermove", this.onAliasButtonMoved); + document.removeEventListener("pointerup", this.onAliasButtonUp); + e.stopPropagation(); + } + + onAliasButtonDown = (e: React.PointerEvent): void => { + this._downx = e.clientX; + this._downy = e.clientY; + e.stopPropagation(); + e.preventDefault(); + document.removeEventListener("pointermove", this.onAliasButtonMoved); + document.addEventListener("pointermove", this.onAliasButtonMoved); + document.removeEventListener("pointerup", this.onAliasButtonUp); + document.addEventListener("pointerup", this.onAliasButtonUp); + } + onAliasButtonMoved = (e: PointerEvent): void => { + if (this._dragRef.current !== null && (Math.abs(e.clientX - this._downx) > 4 || Math.abs(e.clientY - this._downy) > 4)) { + document.removeEventListener("pointermove", this.onAliasButtonMoved); + document.removeEventListener("pointerup", this.onAliasButtonUp); + + const dragDocView = this.props.views[0]!; + const dragData = new DragManager.DocumentDragData([dragDocView.props.Document]); + const [left, top] = dragDocView.props.ScreenToLocalTransform().inverse().transformPoint(0, 0); + dragData.embedDoc = true; + dragData.dropAction = "alias"; + DragManager.StartDocumentDrag([dragDocView.ContentDiv!], dragData, left, top, { + offsetX: dragData.offset[0], + offsetY: dragData.offset[1], + hideSource: false + }); + } + e.stopPropagation(); + } + + @computed + get templateButton() { + const view0 = this.view0; const templates: Map<Template, boolean> = new Map(); Array.from(Object.values(Templates.TemplateList)).map(template => templates.set(template, this.props.views.reduce((checked, doc) => checked || doc?.getLayoutPropStr("show" + template.Name) ? true : false, false as boolean))); + return !view0 ? (null) : <div title="Customize layout" className="documentButtonBar-linkFlyout" ref={this._dragRef}> + <Flyout anchorPoint={anchorPoints.LEFT_TOP} + content={<TemplateMenu docViews={this.props.views.filter(v => v).map(v => v as DocumentView)} templates={templates} />}> + <div className={"documentButtonBar-linkButton-" + "empty"} ref={this._dragRef} onPointerDown={this.onAliasButtonDown} > + {<FontAwesomeIcon className="documentdecorations-icon" icon="edit" size="sm" />} + </div> + </Flyout> + </div>; + } + + render() { + if (!this.view0) return (null); const isText = this.view0.props.Document.data instanceof RichTextField; // bcz: Todo - can't assume layout is using the 'data' field. need to add fieldKey to DocumentView const considerPull = isText && this.considerGoogleDocsPull; @@ -232,7 +299,13 @@ export class DocumentButtonBar extends React.Component<{ views: (DocumentView | {this.linkButton} </div> <div className="documentButtonBar-button"> - <TemplateMenu docs={this.props.views.filter(v => v).map(v => v as DocumentView)} templates={templates} /> + {this.templateButton} + </div> + <div className="documentButtonBar-button"> + {this.metadataButton} + </div> + <div className="documentButtonBar-button"> + {this.contextButton} </div> <div className="documentButtonBar-button" style={{ display: !considerPush ? "none" : "" }}> {this.considerGoogleDocsPush} @@ -240,7 +313,6 @@ export class DocumentButtonBar extends React.Component<{ views: (DocumentView | <div className="documentButtonBar-button" style={{ display: !considerPull ? "none" : "" }}> {this.considerGoogleDocsPull} </div> - {this.contextButton} </div>; } }
\ No newline at end of file diff --git a/src/client/views/DocumentDecorations.tsx b/src/client/views/DocumentDecorations.tsx index 799b3695c..c5034b901 100644 --- a/src/client/views/DocumentDecorations.tsx +++ b/src/client/views/DocumentDecorations.tsx @@ -1,33 +1,25 @@ import { IconProp, library } from '@fortawesome/fontawesome-svg-core'; import { faArrowAltCircleDown, faArrowAltCircleUp, faCheckCircle, faCloudUploadAlt, faLink, faShare, faStopCircle, faSyncAlt, faTag, faTimes } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { action, computed, observable, reaction, runInAction } from "mobx"; +import { action, computed, observable, reaction } from "mobx"; import { observer } from "mobx-react"; -import { Doc, DocListCastAsync } from "../../new_fields/Doc"; +import { Doc } from "../../new_fields/Doc"; import { PositionDocument } from '../../new_fields/documentSchemas'; -import { List } from "../../new_fields/List"; import { ObjectField } from '../../new_fields/ObjectField'; -import { Cast, NumCast, StrCast } from "../../new_fields/Types"; +import { ScriptField } from '../../new_fields/ScriptField'; +import { Cast, StrCast } from "../../new_fields/Types"; import { CurrentUserUtils } from '../../server/authentication/models/current_user_utils'; import { Utils } from "../../Utils"; -import { Docs, DocUtils } from "../documents/Documents"; -import { DocumentManager } from "../util/DocumentManager"; +import { DocUtils } from "../documents/Documents"; +import { DocumentType } from '../documents/DocumentTypes'; import { DragManager } from "../util/DragManager"; import { SelectionManager } from "../util/SelectionManager"; -import { TooltipTextMenu } from '../util/TooltipTextMenu'; import { undoBatch, UndoManager } from "../util/UndoManager"; -import { MINIMIZED_ICON_SIZE } from "../views/globalCssVariables.scss"; -import { CollectionView } from "./collections/CollectionView"; import { DocumentButtonBar } from './DocumentButtonBar'; import './DocumentDecorations.scss'; import { DocumentView } from "./nodes/DocumentView"; -import { FieldView } from "./nodes/FieldView"; import { IconBox } from "./nodes/IconBox"; import React = require("react"); -import { DocumentType } from '../documents/DocumentTypes'; -import { ScriptField } from '../../new_fields/ScriptField'; -import { render } from 'react-dom'; -import RichTextMenu from '../util/RichTextMenu'; const higflyout = require("@hig/flyout"); export const { anchorPoints } = higflyout; export const Flyout = higflyout.default; @@ -54,17 +46,13 @@ export class DocumentDecorations extends React.Component<{}, { value: string }> private _titleHeight = 20; private _downX = 0; private _downY = 0; - private _iconDoc?: Doc = undefined; private _resizeUndo?: UndoManager.Batch; private _radiusDown = [0, 0]; @observable private _accumulatedTitle = ""; - @observable private _minimizedX = 0; - @observable private _minimizedY = 0; @observable private _titleControlString: string = "#title"; @observable private _edtingTitle = false; @observable private _hidden = false; @observable private _opacity = 1; - @observable private _removeIcon = false; @observable public Interacting = false; @observable public pushIcon: IconProp = "arrow-alt-circle-up"; @@ -248,15 +236,7 @@ export class DocumentDecorations extends React.Component<{}, { value: string }> @action onMinimizeDown = (e: React.PointerEvent): void => { e.stopPropagation(); - this._iconDoc = undefined; if (e.button === 0) { - this._downX = e.pageX; - this._downY = e.pageY; - this._removeIcon = false; - const selDoc = SelectionManager.SelectedDocuments()[0]; - const selDocPos = selDoc.props.ScreenToLocalTransform().scale(selDoc.props.ContentScaling()).inverse().transformPoint(0, 0); - this._minimizedX = selDocPos[0] + 12; - this._minimizedY = selDocPos[1] + 12; document.removeEventListener("pointermove", this.onMinimizeMove); document.addEventListener("pointermove", this.onMinimizeMove); document.removeEventListener("pointerup", this.onMinimizeUp); @@ -269,20 +249,8 @@ export class DocumentDecorations extends React.Component<{}, { value: string }> e.stopPropagation(); if (Math.abs(e.pageX - this._downX) > Utils.DRAG_THRESHOLD || Math.abs(e.pageY - this._downY) > Utils.DRAG_THRESHOLD) { - const selDoc = SelectionManager.SelectedDocuments()[0]; - const selDocPos = selDoc.props.ScreenToLocalTransform().scale(selDoc.props.ContentScaling()).inverse().transformPoint(0, 0); - const snapped = Math.abs(e.pageX - selDocPos[0]) < 20 && Math.abs(e.pageY - selDocPos[1]) < 20; - this._minimizedX = snapped ? selDocPos[0] + 4 : e.clientX; - this._minimizedY = snapped ? selDocPos[1] - 18 : e.clientY; - const selectedDocs = SelectionManager.SelectedDocuments().map(sd => sd); - - if (selectedDocs.length > 1) { - this._iconDoc = this._iconDoc ? this._iconDoc : this.createIcon(SelectionManager.SelectedDocuments(), CollectionView.LayoutString("")); - this.moveIconDoc(this._iconDoc); - } else { - this.getIconDoc(selectedDocs[0]).then(icon => icon && this.moveIconDoc(this._iconDoc = icon)); - } - this._removeIcon = snapped; + document.removeEventListener("pointermove", this.onMinimizeMove); + document.removeEventListener("pointerup", this.onMinimizeUp); } } @undoBatch @@ -293,59 +261,19 @@ export class DocumentDecorations extends React.Component<{}, { value: string }> document.removeEventListener("pointermove", this.onMinimizeMove); document.removeEventListener("pointerup", this.onMinimizeUp); const selectedDocs = SelectionManager.SelectedDocuments().map(sd => sd); - if (this._iconDoc && selectedDocs.length === 1 && this._removeIcon) { - selectedDocs[0].props.removeDocument && selectedDocs[0].props.removeDocument(this._iconDoc); - } - if (!this._removeIcon && selectedDocs.length === 1) { // if you click on the top-left button when just 1 doc is selected, then collapse it. not sure why we don't do it for multiple selections - this.getIconDoc(selectedDocs[0]).then(async icon => { - const minimizedDoc = await Cast(selectedDocs[0].props.Document.minimizedDoc, Doc); - if (minimizedDoc) { - const scrpt = selectedDocs[0].props.ScreenToLocalTransform().scale(selectedDocs[0].props.ContentScaling()).inverse().transformPoint( - NumCast(minimizedDoc.x) - NumCast(selectedDocs[0].Document.x), NumCast(minimizedDoc.y) - NumCast(selectedDocs[0].Document.y)); - SelectionManager.DeselectAll(); - DocumentManager.Instance.animateBetweenPoint(scrpt, await DocListCastAsync(minimizedDoc.maximizedDocs)); - } - }); - } - this._removeIcon = false; - } - runInAction(() => this._minimizedX = this._minimizedY = 0); - } - - @undoBatch - @action createIcon = (selected: DocumentView[], layoutString: string): Doc => { - const doc = selected[0].props.Document; - const iconDoc = Docs.Create.IconDocument(layoutString); - iconDoc.isButton = true; - - IconBox.AutomaticTitle(iconDoc); - //iconDoc.proto![this._fieldKey] = selected.length > 1 ? "collection" : undefined; - iconDoc.width = Number(MINIMIZED_ICON_SIZE); - iconDoc.height = Number(MINIMIZED_ICON_SIZE); - iconDoc.x = NumCast(doc.x); - iconDoc.y = NumCast(doc.y) - 24; - iconDoc.maximizedDocs = new List<Doc>(selected.map(s => s.props.Document)); - selected.length === 1 && (doc.minimizedDoc = iconDoc); - selected[0].props.addDocument && selected[0].props.addDocument(iconDoc); - return iconDoc; - } - @action - public getIconDoc = async (docView: DocumentView): Promise<Doc | undefined> => { - const doc = docView.props.Document; - let iconDoc: Doc | undefined = await Cast(doc.minimizedDoc, Doc); - - if (!iconDoc || !DocumentManager.Instance.getDocumentView(iconDoc)) { - const layout = StrCast(doc.layout, FieldView.LayoutString(DocumentView, "")); - iconDoc = this.createIcon([docView], layout); + selectedDocs.map(dv => { + const layoutKey = Cast(dv.props.Document.layoutKey, "string", null); + const collapse = layoutKey !== "layout_icon"; + if (collapse) { + if (layoutKey && layoutKey !== "layout") dv.props.Document.deiconifyLayout = layoutKey.replace("layout_", ""); + dv.setCustomView(collapse, "icon"); + } else { + const deiconifyLayout = Cast(dv.props.Document.deiconifyLayout, "string", null); + dv.setCustomView(deiconifyLayout ? true : false, deiconifyLayout); + dv.props.Document.deiconifyLayout = undefined; + } + }); } - return iconDoc; - } - moveIconDoc(iconDoc: Doc) { - const selView = SelectionManager.SelectedDocuments()[0]; - const where = (selView.props.ScreenToLocalTransform()).scale(selView.props.ContentScaling()). - transformPoint(this._minimizedX - 12, this._minimizedY - 12); - iconDoc.x = where[0] + NumCast(selView.props.Document.x); - iconDoc.y = where[1] + NumCast(selView.props.Document.y); } @action @@ -365,14 +293,7 @@ export class DocumentDecorations extends React.Component<{}, { value: string }> onRadiusMove = (e: PointerEvent): void => { let dist = Math.sqrt((e.clientX - this._radiusDown[0]) * (e.clientX - this._radiusDown[0]) + (e.clientY - this._radiusDown[1]) * (e.clientY - this._radiusDown[1])); dist = dist < 3 ? 0 : dist; - let usingRule = false; - SelectionManager.SelectedDocuments().map(dv => { - const ruleProvider = dv.props.ruleProvider; - const heading = NumCast(dv.props.Document.heading); - ruleProvider && heading && (Doc.GetProto(ruleProvider)["ruleRounding_" + heading] = `${Math.min(100, dist)}%`); - usingRule = usingRule || (ruleProvider && heading ? true : false); - }); - !usingRule && SelectionManager.SelectedDocuments().map(dv => dv.props.Document.layout instanceof Doc ? dv.props.Document.layout : dv.props.Document.isTemplateField ? dv.props.Document : Doc.GetProto(dv.props.Document)). + SelectionManager.SelectedDocuments().map(dv => dv.props.Document.layout instanceof Doc ? dv.props.Document.layout : dv.props.Document.isTemplateForField ? dv.props.Document : Doc.GetProto(dv.props.Document)). map(d => d.borderRounding = `${Math.min(100, dist)}%`); e.stopPropagation(); e.preventDefault(); @@ -464,10 +385,10 @@ export class DocumentDecorations extends React.Component<{}, { value: string }> if (dX !== 0 || dY !== 0 || dW !== 0 || dH !== 0) { const doc = PositionDocument(element.props.Document); const layoutDoc = PositionDocument(Doc.Layout(element.props.Document)); - let nwidth = layoutDoc.nativeWidth || 0; - let nheight = layoutDoc.nativeHeight || 0; - const width = (layoutDoc.width || 0); - const height = (layoutDoc.height || (nheight / nwidth * width)); + let nwidth = layoutDoc._nativeWidth || 0; + let nheight = layoutDoc._nativeHeight || 0; + const width = (layoutDoc._width || 0); + const height = (layoutDoc._height || (nheight / nwidth * width)); const scale = element.props.ScreenToLocalTransform().Scale * element.props.ContentScaling(); const actualdW = Math.max(width + (dW * scale), 20); const actualdH = Math.max(height + (dH * scale), 20); @@ -476,34 +397,34 @@ export class DocumentDecorations extends React.Component<{}, { value: string }> const fixedAspect = e.ctrlKey || (!layoutDoc.ignoreAspect && nwidth && nheight); if (fixedAspect && e.ctrlKey && layoutDoc.ignoreAspect) { layoutDoc.ignoreAspect = false; - layoutDoc.nativeWidth = nwidth = layoutDoc.width || 0; - layoutDoc.nativeHeight = nheight = layoutDoc.height || 0; + layoutDoc._nativeWidth = nwidth = layoutDoc._width || 0; + layoutDoc._nativeHeight = nheight = layoutDoc._height || 0; } if (fixedAspect && (!nwidth || !nheight)) { - layoutDoc.nativeWidth = nwidth = layoutDoc.width || 0; - layoutDoc.nativeHeight = nheight = layoutDoc.height || 0; + layoutDoc._nativeWidth = nwidth = layoutDoc._width || 0; + layoutDoc._nativeHeight = nheight = layoutDoc._height || 0; } if (nwidth > 0 && nheight > 0 && !layoutDoc.ignoreAspect) { if (Math.abs(dW) > Math.abs(dH)) { if (!fixedAspect) { - layoutDoc.nativeWidth = actualdW / (layoutDoc.width || 1) * (layoutDoc.nativeWidth || 0); + layoutDoc._nativeWidth = actualdW / (layoutDoc._width || 1) * (layoutDoc._nativeWidth || 0); } - layoutDoc.width = actualdW; - if (fixedAspect && !layoutDoc.fitWidth) layoutDoc.height = nheight / nwidth * layoutDoc.width; - else layoutDoc.height = actualdH; + layoutDoc._width = actualdW; + if (fixedAspect && !layoutDoc._fitWidth) layoutDoc._height = nheight / nwidth * layoutDoc._width; + else layoutDoc._height = actualdH; } else { if (!fixedAspect) { - layoutDoc.nativeHeight = actualdH / (layoutDoc.height || 1) * (doc.nativeHeight || 0); + layoutDoc._nativeHeight = actualdH / (layoutDoc._height || 1) * (doc._nativeHeight || 0); } - layoutDoc.height = actualdH; - if (fixedAspect && !layoutDoc.fitWidth) layoutDoc.width = nwidth / nheight * layoutDoc.height; - else layoutDoc.width = actualdW; + layoutDoc._height = actualdH; + if (fixedAspect && !layoutDoc._fitWidth) layoutDoc._width = nwidth / nheight * layoutDoc._height; + else layoutDoc._width = actualdW; } } else { - dW && (layoutDoc.width = actualdW); - dH && (layoutDoc.height = actualdH); - dH && layoutDoc.autoHeight && (layoutDoc.autoHeight = false); + dW && (layoutDoc._width = actualdW); + dH && (layoutDoc._height = actualdH); + dH && layoutDoc._autoHeight && (layoutDoc._autoHeight = false); } } })); @@ -546,11 +467,6 @@ export class DocumentDecorations extends React.Component<{}, { value: string }> this.TextBar = ele; } } - public showTextBar = () => { - if (this.TextBar && TooltipTextMenu.Toolbar && Array.from(this.TextBar.childNodes).indexOf(TooltipTextMenu.Toolbar) === -1) { - this.TextBar.appendChild(TooltipTextMenu.Toolbar); - } - } render() { const bounds = this.Bounds; const seldoc = SelectionManager.SelectedDocuments().length ? SelectionManager.SelectedDocuments()[0] : undefined; @@ -593,8 +509,6 @@ export class DocumentDecorations extends React.Component<{}, { value: string }> }}> {minimizeIcon} - {/* <RichTextMenu /> */} - {this._edtingTitle ? <input ref={this._keyinput} className="title" type="text" name="dynbox" value={this._accumulatedTitle} onBlur={e => this.titleBlur(true)} onChange={this.titleChanged} onKeyPress={this.titleEntered} /> : <div className="title" onPointerDown={this.onTitleDown} ><span>{`${this.selectionTitle}`}</span></div>} diff --git a/src/client/views/EditableView.tsx b/src/client/views/EditableView.tsx index faf02b946..780c5b2f4 100644 --- a/src/client/views/EditableView.tsx +++ b/src/client/views/EditableView.tsx @@ -1,10 +1,12 @@ import React = require('react'); +import { action, observable } from 'mobx'; import { observer } from 'mobx-react'; -import { observable, action, trace } from 'mobx'; -import "./EditableView.scss"; import * as Autosuggest from 'react-autosuggest'; -import { undoBatch } from '../util/UndoManager'; +import { ObjectField } from '../../new_fields/ObjectField'; import { SchemaHeaderField } from '../../new_fields/SchemaHeaderField'; +import { ContextMenu } from './ContextMenu'; +import { ContextMenuProps } from './ContextMenuItem'; +import "./EditableView.scss"; export interface EditableProps { /** @@ -43,6 +45,7 @@ export interface EditableProps { editing?: boolean; onClick?: (e: React.MouseEvent) => boolean; isEditingCallback?: (isEditing: boolean) => void; + menuCallback?: (x: number, y: number) => void; HeadingObject?: SchemaHeaderField | undefined; HeadingsHack?: number; toggle?: () => void; @@ -65,7 +68,7 @@ export class EditableView extends React.Component<EditableProps> { } @action - componentWillReceiveProps(nextProps: EditableProps) { + componentDidUpdate(nextProps: EditableProps) { // this is done because when autosuggest is turned on, the suggestions are passed in as a prop, // so when the suggestions are passed in, and no editing prop is passed in, it used to set it // to false. this will no longer do so -syip @@ -87,12 +90,14 @@ export class EditableView extends React.Component<EditableProps> { } else if (this.props.OnFillDown) { this.props.OnFillDown(e.currentTarget.value); this._editing = false; - this.props.isEditingCallback && this.props.isEditingCallback(false); + this.props.isEditingCallback?.(false); } } else if (e.key === "Escape") { e.stopPropagation(); this._editing = false; - this.props.isEditingCallback && this.props.isEditingCallback(false); + this.props.isEditingCallback?.(false); + } else if (e.key === ":") { + this.props.menuCallback?.(e.currentTarget.offsetLeft, e.currentTarget.offsetTop); } } @@ -101,7 +106,7 @@ export class EditableView extends React.Component<EditableProps> { e.nativeEvent.stopPropagation(); if (!this.props.onClick || !this.props.onClick(e)) { this._editing = true; - this.props.isEditingCallback && this.props.isEditingCallback(true); + this.props.isEditingCallback?.(true); } e.stopPropagation(); } @@ -110,7 +115,7 @@ export class EditableView extends React.Component<EditableProps> { private finalizeEdit(value: string, shiftDown: boolean) { this._editing = false; if (this.props.SetValue(value, shiftDown)) { - this.props.isEditingCallback && this.props.isEditingCallback(false); + this.props.isEditingCallback?.(false); } } @@ -152,7 +157,7 @@ export class EditableView extends React.Component<EditableProps> { />; } else { if (this.props.autosuggestProps) this.props.autosuggestProps.resetValue(); - return ( + return (this.props.contents instanceof ObjectField ? (null) : <div className={`editableView-container-editing${this.props.oneLine ? "-oneLine" : ""}`} style={{ display: this.props.display, minHeight: "20px", height: `${this.props.height ? this.props.height : "auto"}`, maxHeight: `${this.props.maxHeight}` }} onClick={this.onClick}> diff --git a/src/client/views/GestureOverlay.tsx b/src/client/views/GestureOverlay.tsx index 9dd87554f..580c53a37 100644 --- a/src/client/views/GestureOverlay.tsx +++ b/src/client/views/GestureOverlay.tsx @@ -20,18 +20,12 @@ import { DocumentView } from "./nodes/DocumentView"; import { Transform } from "../util/Transform"; import { DocumentContentsView } from "./nodes/DocumentContentsView"; -/** - * This class handles all of the gesture and touch events first. Native touch and pen - * events should be ignored by all classes and handled up here, and this class will interpret - * these events before dispatching our custom Dash gesture and touch events. Classes that want - * to use touch and pen events should handle custom Dash events, as opposed to native events. - */ @observer export default class GestureOverlay extends Touchable { static Instance: GestureOverlay; - @observable public Color?: string; - @observable public Width?: number; + @observable public Color: string = "rgb(244, 67, 54)"; + @observable public Width: number = 5; @observable public SavedColor?: string; @observable public SavedWidth?: number; @observable public Tool: ToolglassTools = ToolglassTools.None; @@ -60,15 +54,6 @@ export default class GestureOverlay extends Touchable { GestureOverlay.Instance = this; } - /** - * @description - * Given a touch event, returns three arrays that represent the event's targetTouches, - * changedTouches, and touches after filtering out the touch events that are being handled - * as hands. This helps us separate hand events and touch events, as they are different - * events in the mental model that we are pursuing. - * @param e - Touch event to filter - * @returns \{ newTargetTouches, newChangedTouches, newTouches } - */ getNewTouches(e: React.TouchEvent | TouchEvent) { const ntt: (React.Touch | Touch)[] = Array.from(e.targetTouches); const nct: (React.Touch | Touch)[] = Array.from(e.changedTouches); @@ -76,7 +61,6 @@ export default class GestureOverlay extends Touchable { this._hands.forEach((hand) => { for (let i = 0; i < e.targetTouches.length; i++) { const pt = e.targetTouches.item(i); - // if there is a finger in this hand that matches the current point, ignore the current point if (pt && hand.some((finger) => finger.screenX === pt.screenX && finger.screenY === pt.screenY)) { ntt.splice(ntt.indexOf(pt), 1); } @@ -99,11 +83,7 @@ export default class GestureOverlay extends Touchable { return { ntt, nct, nt }; } - /** - * @description Handler for the native React touchStart event. - */ onReactTouchStart = (te: React.TouchEvent) => { - // clean up any ghost points that are remaining but don't actually exist const actualPts: React.Touch[] = []; for (let i = 0; i < te.touches.length; i++) { const pt: any = te.touches.item(i); @@ -111,6 +91,9 @@ export default class GestureOverlay extends Touchable { // pen is also a touch, but with a radius of 0.5 (at least with the surface pens) // and this seems to be the only way of differentiating pen and touch on touch events if (pt.radiusX > 1 && pt.radiusY > 1) { + // if (typeof pt.identifier !== "string") { + // pt.identifier = Utils.GenerateGuid(); + // } this.prevPoints.set(pt.identifier, pt); } } @@ -123,11 +106,10 @@ export default class GestureOverlay extends Touchable { }); ptsToDelete.forEach(pt => this.prevPoints.delete(pt)); - - // decide whether we should be handling this as a hand event or a touch event const nts = this.getNewTouches(te); + console.log(nts.nt.length); + if (nts.nt.length < 5) { - // dispatch a touch event const target = document.elementFromPoint(te.changedTouches.item(0).clientX, te.changedTouches.item(0).clientY); target?.dispatchEvent( new CustomEvent<InteractionUtils.MultiTouchEvent<React.TouchEvent>>("dashOnTouchStart", @@ -149,17 +131,12 @@ export default class GestureOverlay extends Touchable { document.addEventListener("touchend", this.onReactTouchEnd); } else { - // handle this event as a hand event this.handleHandDown(te); document.removeEventListener("touchmove", this.onReactTouchMove); document.removeEventListener("touchend", this.onReactTouchEnd); } } - /** - * @description Handler for the native React touchMove event. Filters and dispatches - * the custom Dash touchMove event. - */ onReactTouchMove = (e: TouchEvent) => { const nts: any = this.getNewTouches(e); document.dispatchEvent( @@ -177,11 +154,7 @@ export default class GestureOverlay extends Touchable { ); } - /** - * @description Handler for the native React touchEnd event. - */ onReactTouchEnd = (e: TouchEvent) => { - // filter and dispatch custom touchEnd event const nts: any = this.getNewTouches(e); document.dispatchEvent( new CustomEvent<InteractionUtils.MultiTouchEvent<TouchEvent>>("dashOnTouchEnd", @@ -196,8 +169,6 @@ export default class GestureOverlay extends Touchable { } }) ); - - // clean up any points that have ended for (let i = 0; i < e.changedTouches.length; i++) { const pt = e.changedTouches.item(i); if (pt) { @@ -207,7 +178,6 @@ export default class GestureOverlay extends Touchable { } } - // clean up events if (this.prevPoints.size === 0) { document.removeEventListener("touchmove", this.onReactTouchMove); document.removeEventListener("touchend", this.onReactTouchEnd); @@ -215,12 +185,8 @@ export default class GestureOverlay extends Touchable { e.stopPropagation(); } - /** - * @description Handler for "handDown" events - */ handleHandDown = async (e: React.TouchEvent) => { const fingers = new Array<React.Touch>(); - // log all the fingers on the hand for (let i = 0; i < e.touches.length; i++) { const pt: any = e.touches.item(i); if (pt.radiusX > 1 && pt.radiusY > 1) { @@ -234,8 +200,6 @@ export default class GestureOverlay extends Touchable { } } } - - // figure out left/right hand and thumb/pointer finger const thumb = fingers.reduce((a, v) => a.clientY > v.clientY ? a : v, fingers[0]); const rightMost = Math.max(...fingers.map(f => f.clientX)); const leftMost = Math.min(...fingers.map(f => f.clientX)); @@ -265,7 +229,6 @@ export default class GestureOverlay extends Touchable { const minX = Math.min(...others.map(f => f.clientX)); const minY = Math.min(...others.map(f => f.clientY)); - // pull up the palette const thumbDoc = await Cast(CurrentUserUtils.setupThumbDoc(CurrentUserUtils.UserDocument), Doc); if (thumbDoc) { runInAction(() => { @@ -283,9 +246,6 @@ export default class GestureOverlay extends Touchable { document.addEventListener("touchend", this.handleHandUp); } - /** - * @description Handler for "handMove" event - */ @action handleHandMove = (e: TouchEvent) => { const fingers = new Array<React.Touch>(); @@ -410,7 +370,7 @@ export default class GestureOverlay extends Touchable { else { const result = GestureUtils.GestureRecognizer.Recognize(new Array(points)); let actionPerformed = false; - if (result && result.Score > 0.8) { + if (result && result.Score > 0.7) { switch (result.Name) { case GestureUtils.Gestures.Box: const target = document.elementFromPoint(this._points[0].X, this._points[0].Y); @@ -478,7 +438,7 @@ export default class GestureOverlay extends Touchable { return ( <svg width={B.width} height={B.height} style={{ transform: `translate(${B.left}px, ${B.top}px)`, pointerEvents: "none", position: "absolute", zIndex: 30000 }}> - {InteractionUtils.CreatePolyline(this._points, B.left, B.top, this.Color ?? InkingControl.Instance.selectedColor, this.Width ?? parseInt(InkingControl.Instance.selectedWidth))} + {InteractionUtils.CreatePolyline(this._points, B.left, B.top, this.Color, this.Width)} </svg> ); } @@ -502,7 +462,6 @@ export default class GestureOverlay extends Touchable { addDocTab={returnFalse} pinToPres={emptyFunction} onClick={undefined} - ruleProvider={undefined} removeDocument={undefined} ScreenToLocalTransform={() => new Transform(-(this._thumbX ?? 0), -(this._thumbY ?? 0) + this.height, 1)} ContentScaling={returnOne} @@ -554,7 +513,6 @@ export default class GestureOverlay extends Touchable { export enum ToolglassTools { InkToText = "inktotext", - IgnoreGesture = "ignoregesture", None = "none", } @@ -572,7 +530,7 @@ Scripting.addGlobal(function setPen(width: any, color: any) { }); Scripting.addGlobal(function resetPen() { runInAction(() => { - GestureOverlay.Instance.Color = GestureOverlay.Instance.SavedColor ?? undefined; - GestureOverlay.Instance.Width = GestureOverlay.Instance.SavedWidth ?? undefined; + GestureOverlay.Instance.Color = GestureOverlay.Instance.SavedColor ?? "rgb(244, 67, 54)"; + GestureOverlay.Instance.Width = GestureOverlay.Instance.SavedWidth ?? 5; }); });
\ No newline at end of file diff --git a/src/client/views/InkingControl.tsx b/src/client/views/InkingControl.tsx index be07a9024..6cee702ee 100644 --- a/src/client/views/InkingControl.tsx +++ b/src/client/views/InkingControl.tsx @@ -2,14 +2,11 @@ import { action, computed, observable } from "mobx"; import { ColorState } from 'react-color'; import { Doc } from "../../new_fields/Doc"; import { InkTool } from "../../new_fields/InkField"; -import { List } from "../../new_fields/List"; -import { listSpec } from "../../new_fields/Schema"; -import { Cast, NumCast, StrCast, FieldValue } from "../../new_fields/Types"; -import { Utils } from "../../Utils"; +import { FieldValue, NumCast, StrCast } from "../../new_fields/Types"; +import { CurrentUserUtils } from "../../server/authentication/models/current_user_utils"; import { Scripting } from "../util/Scripting"; import { SelectionManager } from "../util/SelectionManager"; -import { undoBatch, UndoManager } from "../util/UndoManager"; -import { CurrentUserUtils } from "../../server/authentication/models/current_user_utils"; +import { undoBatch } from "../util/UndoManager"; import GestureOverlay from "./GestureOverlay"; export class InkingControl { @@ -41,59 +38,12 @@ export class InkingControl { if (InkingControl.Instance.selectedTool === InkTool.None) { const selected = SelectionManager.SelectedDocuments(); - const oldColors = selected.map(view => { + selected.map(view => { const targetDoc = view.props.Document.dragFactory instanceof Doc ? view.props.Document.dragFactory : view.props.Document.layout instanceof Doc ? view.props.Document.layout : - view.props.Document.isTemplateField ? view.props.Document : Doc.GetProto(view.props.Document); - const sel = window.getSelection(); - if (StrCast(targetDoc.layout).indexOf("FormattedTextBox") !== -1 && (!sel || sel.toString() !== "")) { - targetDoc.color = this._selectedColor; - return { - target: targetDoc, - previous: StrCast(targetDoc.color) - }; - } - const oldColor = StrCast(targetDoc.backgroundColor); - let matchedColor = this._selectedColor; - const cvd = view.props.ContainingCollectionDoc; - let ruleProvider = view.props.ruleProvider; - if (cvd) { - if (!cvd.colorPalette) { - const defaultPalette = ["rg(114,229,239)", "rgb(255,246,209)", "rgb(255,188,156)", "rgb(247,220,96)", "rgb(122,176,238)", - "rgb(209,150,226)", "rgb(127,235,144)", "rgb(252,188,189)", "rgb(247,175,81)",]; - const colorPalette = Cast(cvd.colorPalette, listSpec("string")); - if (!colorPalette) cvd.colorPalette = new List<string>(defaultPalette); - } - const cp = Cast(cvd.colorPalette, listSpec("string")) as string[]; - let closest = 0; - let dist = 10000000; - const ccol = Utils.fromRGBAstr(StrCast(targetDoc.backgroundColor)); - for (let i = 0; i < cp.length; i++) { - const cpcol = Utils.fromRGBAstr(cp[i]); - const d = Math.sqrt((ccol.r - cpcol.r) * (ccol.r - cpcol.r) + (ccol.b - cpcol.b) * (ccol.b - cpcol.b) + (ccol.g - cpcol.g) * (ccol.g - cpcol.g)); - if (d < dist) { - dist = d; - closest = i; - } - } - cp[closest] = "rgba(" + color.rgb.r + "," + color.rgb.g + "," + color.rgb.b + "," + color.rgb.a + ")"; - cvd.colorPalette = new List(cp); - matchedColor = cp[closest]; - ruleProvider = (view.props.Document.heading && ruleProvider) ? ruleProvider : undefined; - ruleProvider && ((Doc.GetProto(ruleProvider)["ruleColor_" + NumCast(view.props.Document.heading)] = Utils.toRGBAstr(color.rgb))); - } - (!ruleProvider && targetDoc) && (Doc.Layout(view.props.Document).backgroundColor = matchedColor); - - return { - target: targetDoc, - previous: oldColor - }; + view.props.Document.isTemplateForField ? view.props.Document : Doc.GetProto(view.props.Document); + targetDoc && (Doc.Layout(view.props.Document).backgroundColor = CurrentUserUtils.UserDocument.inkColor); }); - //let captured = this._selectedColor; - // UndoManager.AddEvent({ - // undo: () => oldColors.forEach(pair => pair.target.backgroundColor = pair.previous), - // redo: () => oldColors.forEach(pair => pair.target.backgroundColor = captured) - // }); } else { CurrentUserUtils.ActivePen && (CurrentUserUtils.ActivePen.backgroundColor = this._selectedColor); } diff --git a/src/client/views/InkingStroke.tsx b/src/client/views/InkingStroke.tsx index aca507147..f315ce12a 100644 --- a/src/client/views/InkingStroke.tsx +++ b/src/client/views/InkingStroke.tsx @@ -11,6 +11,12 @@ import { FieldView, FieldViewProps } from "./nodes/FieldView"; import React = require("react"); import { TraceMobx } from "../../new_fields/util"; import { InteractionUtils } from "../util/InteractionUtils"; +import { ContextMenu } from "./ContextMenu"; +import { CognitiveServices } from "../cognitive_services/CognitiveServices"; +import { faPaintBrush } from "@fortawesome/free-solid-svg-icons"; +import { library } from "@fortawesome/fontawesome-svg-core"; + +library.add(faPaintBrush); type InkDocument = makeInterface<[typeof documentSchema]>; const InkDocument = makeInterface(documentSchema); @@ -22,6 +28,11 @@ export class InkingStroke extends DocExtendableComponent<FieldViewProps, InkDocu @computed get PanelWidth() { return this.props.PanelWidth(); } @computed get PanelHeight() { return this.props.PanelHeight(); } + private analyzeStrokes = () => { + const data: InkData = Cast(this.Document.data, InkField)?.inkData ?? []; + CognitiveServices.Inking.Appliers.ConcatenateHandwriting(this.Document, ["inkAnalysis", "handwriting"], [data]); + } + render() { TraceMobx(); const data: InkData = Cast(this.Document.data, InkField)?.inkData ?? []; @@ -37,12 +48,23 @@ export class InkingStroke extends DocExtendableComponent<FieldViewProps, InkDocu const scaleX = this.PanelWidth / width; const scaleY = this.PanelHeight / height; return ( - <svg width={width} height={height} style={{ - transformOrigin: "top left", - transform: `scale(${scaleX}, ${scaleY})`, - mixBlendMode: this.Document.tool === InkTool.Highlighter ? "multiply" : "unset", - pointerEvents: "all" - }}> + <svg + width={width} + height={height} + style={{ + transformOrigin: "top left", + transform: `scale(${scaleX}, ${scaleY})`, + mixBlendMode: this.Document.tool === InkTool.Highlighter ? "multiply" : "unset", + pointerEvents: "all" + }} + onContextMenu={() => { + ContextMenu.Instance.addItem({ + description: "Analyze Stroke", + event: this.analyzeStrokes, + icon: "paint-brush" + }); + }} + > {points} </svg> ); diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index d7656aba4..87a81504c 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -1,6 +1,6 @@ import { library } from '@fortawesome/fontawesome-svg-core'; import { - faArrowDown, faArrowUp, faBolt, faCaretUp, faCat, faCheck, faChevronRight, faClone, faCloudUploadAlt, faCommentAlt, faCut, faEllipsisV, faExclamation, faFilePdf, faFilm, faFont, faGlobeAsia, faLongArrowAltRight, + faArrowDown, faBullseye, faFilter, faArrowUp, faBolt, faCaretUp, faCat, faCheck, faChevronRight, faClone, faCloudUploadAlt, faCommentAlt, faCut, faEllipsisV, faExclamation, faFilePdf, faFilm, faFont, faGlobeAsia, faLongArrowAltRight, faMusic, faObjectGroup, faPause, faMousePointer, faPenNib, faFileAudio, faPen, faEraser, faPlay, faPortrait, faRedoAlt, faThumbtack, faTree, faTv, faUndoAlt, faHighlighter, faMicrophone, faCompressArrowsAlt, faPhone, faStamp, faClipboard } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; @@ -64,7 +64,7 @@ export class MainView extends React.Component { public isPointerDown = false; - componentWillMount() { + componentDidMount() { const tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; @@ -131,6 +131,8 @@ export class MainView extends React.Component { library.add(faLongArrowAltRight); library.add(faCheck); library.add(faCaretUp); + library.add(faFilter); + library.add(faBullseye); library.add(faArrowDown); library.add(faArrowUp); library.add(faCloudUploadAlt); @@ -176,9 +178,9 @@ export class MainView extends React.Component { } else { if (received && this._urlState.sharing) { reaction(() => CollectionDockingView.Instance && CollectionDockingView.Instance.initialized, - initialized => initialized && received && DocServer.GetRefField(received).then(field => { - if (field instanceof Doc && field.viewType !== CollectionViewType.Docking) { - CollectionDockingView.AddRightSplit(field, undefined); + initialized => initialized && received && DocServer.GetRefField(received).then(docField => { + if (docField instanceof Doc && docField._viewType !== CollectionViewType.Docking) { + CollectionDockingView.AddRightSplit(docField, undefined); } }), ); @@ -199,8 +201,8 @@ export class MainView extends React.Component { const freeformOptions: DocumentOptions = { x: 0, y: 400, - width: this._panelWidth * .7, - height: this._panelHeight, + _width: this._panelWidth * .7, + _height: this._panelHeight, title: "Collection " + workspaceCount, backgroundColor: "white" }; @@ -276,7 +278,6 @@ export class MainView extends React.Component { addDocTab={this.addDocTabFunc} pinToPres={emptyFunction} onClick={undefined} - ruleProvider={undefined} removeDocument={undefined} ScreenToLocalTransform={Transform.Identity} ContentScaling={returnOne} @@ -307,8 +308,10 @@ export class MainView extends React.Component { </Measure>; } + _canClick = false; onPointerDown = (e: React.PointerEvent) => { if (this._flyoutTranslate) { + this._canClick = true; this._flyoutSizeOnDown = e.clientX; document.removeEventListener("pointermove", this.onPointerMove); document.removeEventListener("pointerup", this.onPointerUp); @@ -339,11 +342,12 @@ export class MainView extends React.Component { @action onPointerMove = (e: PointerEvent) => { this.flyoutWidth = Math.max(e.clientX, 0); + Math.abs(this.flyoutWidth - this._flyoutSizeOnDown) > 6 && (this._canClick = false); this.sidebarButtonsDoc.columnWidth = this.flyoutWidth / 3 - 30; } @action onPointerUp = (e: PointerEvent) => { - if (Math.abs(e.clientX - this._flyoutSizeOnDown) < 4) { + if (Math.abs(e.clientX - this._flyoutSizeOnDown) < 4 && this._canClick) { this.flyoutWidth = this.flyoutWidth < 15 ? 250 : 0; this.flyoutWidth && (this.sidebarButtonsDoc.columnWidth = this.flyoutWidth / 3 - 30); } @@ -374,7 +378,6 @@ export class MainView extends React.Component { addDocTab={this.addDocTabFunc} pinToPres={emptyFunction} removeDocument={undefined} - ruleProvider={undefined} onClick={undefined} ScreenToLocalTransform={Transform.Identity} ContentScaling={returnOne} @@ -401,7 +404,6 @@ export class MainView extends React.Component { addDocTab={this.addDocTabFunc} pinToPres={emptyFunction} removeDocument={returnFalse} - ruleProvider={undefined} onClick={undefined} ScreenToLocalTransform={this.mainContainerXf} ContentScaling={returnOne} @@ -497,7 +499,6 @@ export class MainView extends React.Component { addDocTab={this.addDocTabFunc} pinToPres={emptyFunction} removeDocument={this.remButtonDoc} - ruleProvider={undefined} onClick={undefined} ScreenToLocalTransform={this.buttonBarXf} ContentScaling={returnOne} diff --git a/src/client/views/MetadataEntryMenu.scss b/src/client/views/MetadataEntryMenu.scss index 7da55fd1c..5f4a52c0c 100644 --- a/src/client/views/MetadataEntryMenu.scss +++ b/src/client/views/MetadataEntryMenu.scss @@ -8,6 +8,10 @@ } } +#metadataEntry-outer { + overflow: auto !important; +} + .metadataEntry-keys { max-height: 80; overflow-y: auto; diff --git a/src/client/views/MetadataEntryMenu.tsx b/src/client/views/MetadataEntryMenu.tsx index 243cdb8f6..23b21ae0c 100644 --- a/src/client/views/MetadataEntryMenu.tsx +++ b/src/client/views/MetadataEntryMenu.tsx @@ -19,7 +19,6 @@ export interface MetadataEntryProps { export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{ @observable private _currentKey: string = ""; @observable private _currentValue: string = ""; - @observable private suggestions: string[] = []; private _addChildren: boolean = false; @observable _allSuggestions: string[] = []; _suggestionDispser: IReactionDisposer | undefined; @@ -178,11 +177,11 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{ } docSource = docSource as Doc[] | Doc; if (docSource instanceof Doc) { - if (docSource.viewType === undefined) { + if (docSource._viewType === undefined) { return (null); } } else if (Array.isArray(docSource)) { - if (!docSource.every(doc => doc.viewType !== undefined)) { + if (!docSource.every(doc => doc._viewType !== undefined)) { return null; } } @@ -197,7 +196,7 @@ export class MetadataEntryMenu extends React.Component<MetadataEntryProps>{ _ref = React.createRef<HTMLInputElement>(); render() { return ( - <div className="metadataEntry-outerDiv"> + <div className="metadataEntry-outerDiv" id="metadataEntry-outer"> <div className="metadataEntry-inputArea"> Key: <Autosuggest inputProps={{ value: this._currentKey, onChange: this.onKeyChange }} diff --git a/src/client/views/OverlayView.tsx b/src/client/views/OverlayView.tsx index 350a75d29..295cd7c6e 100644 --- a/src/client/views/OverlayView.tsx +++ b/src/client/views/OverlayView.tsx @@ -178,7 +178,6 @@ export class OverlayView extends React.Component { // select={emptyFunction} // layoutKey={"layout"} bringToFront={emptyFunction} - ruleProvider={undefined} addDocument={undefined} removeDocument={undefined} ContentScaling={returnOne} diff --git a/src/client/views/Palette.tsx b/src/client/views/Palette.tsx index 811c24f53..10aac96a0 100644 --- a/src/client/views/Palette.tsx +++ b/src/client/views/Palette.tsx @@ -56,7 +56,6 @@ export default class Palette extends React.Component<PaletteProps> { addDocTab={returnFalse} pinToPres={emptyFunction} removeDocument={undefined} - ruleProvider={undefined} onClick={undefined} ScreenToLocalTransform={Transform.Identity} ContentScaling={returnOne} diff --git a/src/client/views/PreviewCursor.tsx b/src/client/views/PreviewCursor.tsx index 9706d0f99..c011adb20 100644 --- a/src/client/views/PreviewCursor.tsx +++ b/src/client/views/PreviewCursor.tsx @@ -31,8 +31,8 @@ export class PreviewCursor extends React.Component<{}> { if (e.clipboardData.getData("text/plain").indexOf("www.youtube.com/watch") !== -1) { const url = e.clipboardData.getData("text/plain").replace("youtube.com/watch?v=", "youtube.com/embed/"); return PreviewCursor._addDocument(Docs.Create.VideoDocument(url, { - title: url, width: 400, height: 315, - nativeWidth: 600, nativeHeight: 472.5, + title: url, _width: 400, _height: 315, + _nativeWidth: 600, _nativeHeight: 472.5, x: newPoint[0], y: newPoint[1] })); } @@ -42,17 +42,17 @@ export class PreviewCursor extends React.Component<{}> { if (re.test(e.clipboardData.getData("text/plain"))) { const url = e.clipboardData.getData("text/plain"); return PreviewCursor._addDocument(Docs.Create.WebDocument(url, { - title: url, width: 500, height: 300, + title: url, _width: 500, _height: 300, // nativeWidth: 300, nativeHeight: 472.5, x: newPoint[0], y: newPoint[1] })); } // creates text document - return PreviewCursor._addLiveTextDoc(Docs.Create.TextDocument({ - width: 500, + return PreviewCursor._addLiveTextDoc(Docs.Create.TextDocument("", { + _width: 500, limitHeight: 400, - autoHeight: true, + _autoHeight: true, x: newPoint[0], y: newPoint[1], title: "-pasted text-" @@ -65,7 +65,7 @@ export class PreviewCursor extends React.Component<{}> { return PreviewCursor._addDocument(Docs.Create.ImageDocument( arr[1], { - width: 300, title: arr[1], + _width: 300, title: arr[1], x: newPoint[0], y: newPoint[1], })); diff --git a/src/client/views/TemplateMenu.scss b/src/client/views/TemplateMenu.scss index 69bebe0e9..bbed8cd96 100644 --- a/src/client/views/TemplateMenu.scss +++ b/src/client/views/TemplateMenu.scss @@ -15,12 +15,12 @@ .templating-button { width: 20px; height: 20px; - border-radius: 50%; - opacity: 0.9; - font-size: 14; - background-color: $dark-color; - color: $light-color; - text-align: center; + padding-left: 5px; + background: black; + color: white; + border-radius: 10px; + display: flex; + align-items: center; cursor: pointer; &:hover { @@ -42,6 +42,7 @@ .templateToggle, .chromeToggle { text-align: left; + color: black; } input { diff --git a/src/client/views/TemplateMenu.tsx b/src/client/views/TemplateMenu.tsx index d953d3bab..f61eb9cd0 100644 --- a/src/client/views/TemplateMenu.tsx +++ b/src/client/views/TemplateMenu.tsx @@ -1,16 +1,14 @@ -import { action, observable } from "mobx"; +import { action, observable, runInAction, ObservableSet } from "mobx"; import { observer } from "mobx-react"; -import { DragManager } from "../util/DragManager"; import { SelectionManager } from "../util/SelectionManager"; import { undoBatch } from "../util/UndoManager"; import './TemplateMenu.scss'; import { DocumentView } from "./nodes/DocumentView"; import { Template, Templates } from "./Templates"; import React = require("react"); -import { Doc } from "../../new_fields/Doc"; -import { StrCast } from "../../new_fields/Types"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { faEdit, faChevronCircleUp } from "@fortawesome/free-solid-svg-icons"; +import { Doc, DocListCast } from "../../new_fields/Doc"; +import { StrCast, Cast } from "../../new_fields/Types"; +import { CurrentUserUtils } from "../../server/authentication/models/current_user_utils"; const higflyout = require("@hig/flyout"); export const { anchorPoints } = higflyout; export const Flyout = higflyout.default; @@ -43,7 +41,7 @@ class OtherToggle extends React.Component<{ checked: boolean, name: string, togg } export interface TemplateMenuProps { - docs: DocumentView[]; + docViews: DocumentView[]; templates: Map<Template, boolean>; } @@ -51,20 +49,14 @@ export interface TemplateMenuProps { @observer export class TemplateMenu extends React.Component<TemplateMenuProps> { @observable private _hidden: boolean = true; - private _downx = 0; - private _downy = 0; - private _dragRef = React.createRef<HTMLUListElement>(); - toggleCustom = (e: React.ChangeEvent<HTMLInputElement>): void => { - this.props.docs.map(dv => dv.setCustomView(e.target.checked)); - } - toggleNarrative = (e: React.ChangeEvent<HTMLInputElement>): void => { - this.props.docs.map(dv => dv.setNarrativeView(e.target.checked)); + toggleLayout = (e: React.ChangeEvent<HTMLInputElement>, layout: string): void => { + this.props.docViews.map(dv => dv.setCustomView(e.target.checked, layout)); } toggleFloat = (e: React.ChangeEvent<HTMLInputElement>): void => { SelectionManager.DeselectAll(); - const topDocView = this.props.docs[0]; + const topDocView = this.props.docViews[0]; const ex = e.target.getBoundingClientRect().left; const ey = e.target.getBoundingClientRect().top; DocumentView.FloatDoc(topDocView, ex, ey); @@ -75,25 +67,12 @@ export class TemplateMenu extends React.Component<TemplateMenuProps> { @action toggleTemplate = (event: React.ChangeEvent<HTMLInputElement>, template: Template): void => { if (event.target.checked) { - this.props.docs.map(d => d.Document["show" + template.Name] = template.Name.toLowerCase()); + this.props.docViews.map(d => d.Document["show" + template.Name] = template.Name.toLowerCase()); } else { - this.props.docs.map(d => d.Document["show" + template.Name] = ""); + this.props.docViews.map(d => d.Document["show" + template.Name] = ""); } } - @undoBatch - @action - clearTemplates = (event: React.MouseEvent) => { - Templates.TemplateList.forEach(template => this.props.docs.forEach(d => d.Document["show" + template.Name] = undefined)); - ["backgroundColor", "borderRounding", "width", "height"].forEach(field => this.props.docs.forEach(d => { - if (d.Document.isTemplateDoc && d.props.DataDoc) { - d.Document[field] = undefined; - } else if (d.Document["default" + field[0].toUpperCase() + field.slice(1)] !== undefined) { - d.Document[field] = Doc.GetProto(d.Document)[field] = undefined; - } - })); - } - @action toggleTemplateActivity = (): void => { this._hidden = !this._hidden; @@ -102,68 +81,45 @@ export class TemplateMenu extends React.Component<TemplateMenuProps> { @undoBatch @action toggleChrome = (): void => { - this.props.docs.map(dv => { + this.props.docViews.map(dv => { const layout = Doc.Layout(dv.Document); - layout.chromeStatus = (layout.chromeStatus !== "disabled" ? "disabled" : "enabled"); + layout._chromeStatus = (layout._chromeStatus !== "disabled" ? "disabled" : "enabled"); }); } - onAliasButtonUp = (e: PointerEvent): void => { - document.removeEventListener("pointermove", this.onAliasButtonMoved); - document.removeEventListener("pointerup", this.onAliasButtonUp); - e.stopPropagation(); - } - onAliasButtonDown = (e: React.PointerEvent): void => { - this._downx = e.clientX; - this._downy = e.clientY; - e.stopPropagation(); - e.preventDefault(); - document.removeEventListener("pointermove", this.onAliasButtonMoved); - document.addEventListener("pointermove", this.onAliasButtonMoved); - document.removeEventListener("pointerup", this.onAliasButtonUp); - document.addEventListener("pointerup", this.onAliasButtonUp); - } - onAliasButtonMoved = (e: PointerEvent): void => { - if (this._dragRef.current !== null && (Math.abs(e.clientX - this._downx) > 4 || Math.abs(e.clientY - this._downy) > 4)) { - document.removeEventListener("pointermove", this.onAliasButtonMoved); - document.removeEventListener("pointerup", this.onAliasButtonUp); - - const dragDocView = this.props.docs[0]; - const dragData = new DragManager.DocumentDragData([dragDocView.props.Document]); - const [left, top] = dragDocView.props.ScreenToLocalTransform().inverse().transformPoint(0, 0); - dragData.embedDoc = true; - dragData.dropAction = "alias"; - DragManager.StartDocumentDrag([dragDocView.ContentDiv!], dragData, left, top, { - offsetX: dragData.offset[0], - offsetY: dragData.offset[1], - hideSource: false - }); + // todo: add brushes to brushMap to save with a style name + onCustomKeypress = (e: React.KeyboardEvent) => { + if (e.key === "Enter") { + runInAction(() => this._addedKeys.add(this._customRef.current!.value)); } - e.stopPropagation(); + } + componentDidMount() { + !this._addedKeys && (this._addedKeys = new ObservableSet()); + Array.from(Object.keys(Doc.GetProto(this.props.docViews[0].props.Document))). + filter(key => key.startsWith("layout_")). + map(key => runInAction(() => this._addedKeys.add(key.replace("layout_", "")))); + DocListCast(Cast(CurrentUserUtils.UserDocument.expandingButtons, Doc, null)?.data)?.map(btnDoc => { + if (StrCast(Cast(btnDoc?.dragFactory, Doc, null)?.title)) { + runInAction(() => this._addedKeys.add(StrCast(Cast(btnDoc?.dragFactory, Doc, null)?.title))); + } + }); } + _addedKeys = new ObservableSet(); + _customRef = React.createRef<HTMLInputElement>(); render() { - const layout = Doc.Layout(this.props.docs[0].Document); + const layout = Doc.Layout(this.props.docViews[0].Document); const templateMenu: Array<JSX.Element> = []; this.props.templates.forEach((checked, template) => templateMenu.push(<TemplateToggle key={template.Name} template={template} checked={checked} toggle={this.toggleTemplate} />)); - templateMenu.push(<OtherToggle key={"float"} name={"Float"} checked={this.props.docs[0].Document.z ? true : false} toggle={this.toggleFloat} />); - templateMenu.push(<OtherToggle key={"custom"} name={"Custom"} checked={StrCast(this.props.docs[0].Document.layoutKey, "layout") !== "layout"} toggle={this.toggleCustom} />); - templateMenu.push(<OtherToggle key={"narrative"} name={"Narrative"} checked={StrCast(this.props.docs[0].Document.layoutKey, "layout") === "layout_narrative"} toggle={this.toggleNarrative} />); - templateMenu.push(<OtherToggle key={"chrome"} name={"Chrome"} checked={layout.chromeStatus !== "disabled"} toggle={this.toggleChrome} />); - return ( - <Flyout anchorPoint={anchorPoints.LEFT_TOP} - content={<ul className="template-list" ref={this._dragRef} style={{ display: "block" }}> - {templateMenu} - {<button onClick={this.clearTemplates}>Restore Defaults</button>} - </ul>}> - <span className="parentDocumentSelector-button" > - <FontAwesomeIcon icon={faEdit} size={"lg"} /> - </span> - {/* <div className="templating-menu" onPointerDown={this.onAliasButtonDown}> - <div title="Drag:(create alias). Tap:(modify layout)." className="templating-button" onClick={() => this.toggleTemplateActivity()}>+</div> - </div> */} - </Flyout> + templateMenu.push(<OtherToggle key={"float"} name={"Float"} checked={this.props.docViews[0].Document.z ? true : false} toggle={this.toggleFloat} />); + templateMenu.push(<OtherToggle key={"chrome"} name={"Chrome"} checked={layout._chromeStatus !== "disabled"} toggle={this.toggleChrome} />); + this._addedKeys && Array.from(this._addedKeys).map(layout => + templateMenu.push(<OtherToggle key={layout} name={layout} checked={StrCast(this.props.docViews[0].Document.layoutKey, "layout") === "layout_" + layout} toggle={e => this.toggleLayout(e, layout)} />) ); + return <ul className="template-list" style={{ display: "block" }}> + {templateMenu} + <input placeholder="+ layout" ref={this._customRef} onKeyPress={this.onCustomKeypress}></input> + </ul>; } }
\ No newline at end of file diff --git a/src/client/views/Templates.tsx b/src/client/views/Templates.tsx index 8af8a6280..8c60f1c36 100644 --- a/src/client/views/Templates.tsx +++ b/src/client/views/Templates.tsx @@ -43,7 +43,7 @@ export namespace Templates { `<div> <div style="height:100%; width:100%;">{layout}</div> <div style="bottom: 0; font-size:14px; width:100%; position:absolute"> - <FormattedTextBox {...props} height="min-content" fieldKey={"caption"} hideOnLeave={"true"} /> + <FormattedTextBox {...props} fieldKey={"caption"} hideOnLeave={"true"} /> </div> </div>` ); diff --git a/src/client/views/collections/CollectionCarouselView.scss b/src/client/views/collections/CollectionCarouselView.scss new file mode 100644 index 000000000..4815f1a59 --- /dev/null +++ b/src/client/views/collections/CollectionCarouselView.scss @@ -0,0 +1,40 @@ + +.collectionCarouselView-outer { + background: gray; + .collectionCarouselView-caption { + margin-left: 10%; + margin-right: 10%; + height: 50; + display: inline-block; + width: 80%; + } + .collectionCarouselView-image { + height: calc(100% - 50px); + display: inline-block; + width: 100%; + } +} +.carouselView-back { + position: absolute; + display: flex; + left: 0; + top: 50%; + width: 30; + height: 30; + background: lightgray; + align-items: center; + border-radius: 5px; + justify-content: center; +} +.carouselView-fwd { + position: absolute; + display: flex; + right: 0; + top: 50%; + width: 30; + height: 30; + background: lightgray; + align-items: center; + border-radius: 5px; + justify-content: center; +}
\ No newline at end of file diff --git a/src/client/views/collections/CollectionCarouselView.tsx b/src/client/views/collections/CollectionCarouselView.tsx new file mode 100644 index 000000000..0933d5924 --- /dev/null +++ b/src/client/views/collections/CollectionCarouselView.tsx @@ -0,0 +1,82 @@ +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { observable, computed } from 'mobx'; +import { observer } from 'mobx-react'; +import * as React from 'react'; +import { documentSchema } from '../../../new_fields/documentSchemas'; +import { makeInterface } from '../../../new_fields/Schema'; +import { NumCast, StrCast } from '../../../new_fields/Types'; +import { DragManager } from '../../util/DragManager'; +import { ContentFittingDocumentView } from '../nodes/ContentFittingDocumentView'; +import "./CollectionCarouselView.scss"; +import { CollectionSubView } from './CollectionSubView'; +import { faCaretLeft, faCaretRight } from '@fortawesome/free-solid-svg-icons'; +import { Doc } from '../../../new_fields/Doc'; +import { FormattedTextBox } from '../nodes/FormattedTextBox'; + + + + +type CarouselDocument = makeInterface<[typeof documentSchema,]>; +const CarouselDocument = makeInterface(documentSchema); + +@observer +export class CollectionCarouselView extends CollectionSubView(CarouselDocument) { + @observable public addMenuToggle = React.createRef<HTMLInputElement>(); + private _dropDisposer?: DragManager.DragDropDisposer; + + componentWillUnmount() { + this._dropDisposer && this._dropDisposer(); + } + + componentDidMount() { + } + protected createDashEventsTarget = (ele: HTMLDivElement) => { //used for stacking and masonry view + this._dropDisposer && this._dropDisposer(); + if (ele) { + this._dropDisposer = DragManager.MakeDropTarget(ele, this.drop.bind(this)); + } + } + + advance = (e: React.MouseEvent) => { + e.stopPropagation(); + this.layoutDoc._itemIndex = (NumCast(this.layoutDoc._itemIndex) + 1) % this.childLayoutPairs.length; + } + goback = (e: React.MouseEvent) => { + e.stopPropagation(); + this.layoutDoc._itemIndex = (NumCast(this.layoutDoc._itemIndex) - 1 + this.childLayoutPairs.length) % this.childLayoutPairs.length; + } + + panelHeight = () => this.props.PanelHeight() - 50; + @computed get content() { + const index = NumCast(this.layoutDoc._itemIndex); + return !(this.childLayoutPairs?.[index]?.layout instanceof Doc) ? (null) : + <div> + <div className="collectionCarouselView-image"> + <ContentFittingDocumentView {...this.props} + Document={this.childLayoutPairs[index].layout} + DataDocument={this.childLayoutPairs[index].data} + PanelHeight={this.panelHeight} + getTransform={this.props.ScreenToLocalTransform} /> + </div> + <div className="collectionCarouselView-caption" style={{ background: `${StrCast(this.props.Document.backgroundColor)}` }}> + <FormattedTextBox key={index} {...this.props} Document={this.childLayoutPairs[index].layout} DataDoc={undefined} fieldKey={"caption"}></FormattedTextBox> + </div> + </div> + } + @computed get buttons() { + return <> + <div key="back" className="carouselView-back" style={{ background: `${StrCast(this.props.Document.backgroundColor)}` }} onClick={this.goback}> + <FontAwesomeIcon icon={faCaretLeft} size={"2x"} /> + </div> + <div key="fwd" className="carouselView-fwd" style={{ background: `${StrCast(this.props.Document.backgroundColor)}` }} onClick={this.advance}> + <FontAwesomeIcon icon={faCaretRight} size={"2x"} /> + </div> + </>; + } + render() { + return <div className="collectionCarouselView-outer"> + {this.content} + {this.buttons} + </div>; + } +}
\ No newline at end of file diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx index 5f9b4e0c7..82cb3bc88 100644 --- a/src/client/views/collections/CollectionDockingView.tsx +++ b/src/client/views/collections/CollectionDockingView.tsx @@ -132,7 +132,7 @@ export class CollectionDockingView extends React.Component<SubCollectionViewProp @undoBatch @action - public static CloseRightSplit(document: Doc): boolean { + public static CloseRightSplit(document: Opt<Doc>): boolean { if (!CollectionDockingView.Instance) return false; const instance = CollectionDockingView.Instance; let retVal = false; @@ -140,14 +140,16 @@ export class CollectionDockingView extends React.Component<SubCollectionViewProp retVal = Array.from(instance._goldenLayout.root.contentItems[0].contentItems).some((child: any) => { if (child.contentItems.length === 1 && child.contentItems[0].config.component === "DocumentFrameRenderer" && DocumentManager.Instance.getDocumentViewById(child.contentItems[0].config.props.documentId) && - Doc.AreProtosEqual(DocumentManager.Instance.getDocumentViewById(child.contentItems[0].config.props.documentId)!.Document, document)) { + ((!document && DocumentManager.Instance.getDocumentViewById(child.contentItems[0].config.props.documentId)!.Document.isDisplayPanel) || + (document && Doc.AreProtosEqual(DocumentManager.Instance.getDocumentViewById(child.contentItems[0].config.props.documentId)!.Document, document)))) { child.contentItems[0].remove(); instance.layoutChanged(document); return true; } else { Array.from(child.contentItems).filter((tab: any) => tab.config.component === "DocumentFrameRenderer").some((tab: any, j: number) => { if (DocumentManager.Instance.getDocumentViewById(tab.config.props.documentId) && - Doc.AreProtosEqual(DocumentManager.Instance.getDocumentViewById(tab.config.props.documentId)!.Document, document)) { + ((!document && DocumentManager.Instance.getDocumentViewById(tab.config.props.documentId)!.Document.isDisplayPanel) || + (document && Doc.AreProtosEqual(DocumentManager.Instance.getDocumentViewById(tab.config.props.documentId)!.Document, document)))) { child.contentItems[j].remove(); child.config.activeItemIndex = Math.max(child.contentItems.length - 1, 0); return true; @@ -172,6 +174,45 @@ export class CollectionDockingView extends React.Component<SubCollectionViewProp if (removed) CollectionDockingView.Instance._removedDocs.push(removed); this.stateChanged(); } + @undoBatch + @action + public static ReplaceRightSplit(document: Doc, dataDoc: Doc | undefined, libraryPath?: Doc[]): boolean { + if (!CollectionDockingView.Instance) return false; const instance = CollectionDockingView.Instance; + const newItemStackConfig = { + type: 'stack', + content: [CollectionDockingView.makeDocumentConfig(document, dataDoc, undefined, libraryPath)] + }; + + const newContentItem = instance._goldenLayout.root.layoutManager.createContentItem(newItemStackConfig, instance._goldenLayout); + + let retVal = false; + if (instance._goldenLayout.root.contentItems[0].isRow) { + retVal = Array.from(instance._goldenLayout.root.contentItems[0].contentItems).some((child: any) => { + if (child.contentItems.length === 1 && child.contentItems[0].config.component === "DocumentFrameRenderer" && + DocumentManager.Instance.getDocumentViewById(child.contentItems[0].config.props.documentId)?.Document.isDisplayPanle) { + child.contentItems[0].remove(); + child.addChild(newContentItem, undefined, true); + instance.layoutChanged(document); + return true; + } else { + Array.from(child.contentItems).filter((tab: any) => tab.config.component === "DocumentFrameRenderer").some((tab: any, j: number) => { + if (DocumentManager.Instance.getDocumentViewById(tab.config.props.documentId)?.Document.isDisplayPanel) { + child.contentItems[j].remove(); + child.addChild(newContentItem, undefined, true); + return true; + } + return false; + }); + } + return false; + }); + } + if (retVal) { + instance.stateChanged(); + } + return retVal; + } + // // Creates a vertical split on the right side of the docking view, and then adds the Document to the right of that split @@ -214,30 +255,9 @@ export class CollectionDockingView extends React.Component<SubCollectionViewProp @undoBatch @action public static UseRightSplit(document: Doc, dataDoc: Doc | undefined, libraryPath?: Doc[]) { - if (!CollectionDockingView.Instance) return false; - const instance = CollectionDockingView.Instance; - if (instance._goldenLayout.root.contentItems[0].isRow) { - let found: DocumentView | undefined; - Array.from(instance._goldenLayout.root.contentItems[0].contentItems).some((child: any) => { - if (child.contentItems.length === 1 && child.contentItems[0].config.component === "DocumentFrameRenderer" && - DocumentManager.Instance.getDocumentViewById(child.contentItems[0].config.props.documentId)?.props.Document.isDisplayPanel) { - found = DocumentManager.Instance.getDocumentViewById(child.contentItems[0].config.props.documentId)!; - } else { - Array.from(child.contentItems).filter((tab: any) => tab.config.component === "DocumentFrameRenderer").some((tab: any, j: number) => { - if (DocumentManager.Instance.getDocumentViewById(tab.config.props.documentId)?.props.Document.isDisplayPanel) { - found = DocumentManager.Instance.getDocumentViewById(tab.config.props.documentId)!; - return true; - } - return false; - }); - } - }); - if (found) { - Doc.GetProto(found.props.Document).data = new List<Doc>([document]); - } else { - const stackView = Docs.Create.FreeformDocument([document], { fitToBox: true, isDisplayPanel: true, title: "document viewer" }); - CollectionDockingView.AddRightSplit(stackView, undefined, []); - } + document.isDisplayPanel = true; + if (!CollectionDockingView.ReplaceRightSplit(document, dataDoc, libraryPath)) { + CollectionDockingView.AddRightSplit(document, dataDoc, libraryPath); } } @@ -505,7 +525,7 @@ export class CollectionDockingView extends React.Component<SubCollectionViewProp stack.header.element[0].style.backgroundColor = DocServer.Control.isReadOnly() ? "#228540" : undefined; stack.header.element.on('mousedown', (e: any) => { if (e.target === stack.header.element[0] && e.button === 1) { - this.AddTab(stack, Docs.Create.FreeformDocument([], { width: this.props.PanelWidth(), height: this.props.PanelHeight(), title: "Untitled Collection" }), undefined); + this.AddTab(stack, Docs.Create.FreeformDocument([], { _width: this.props.PanelWidth(), _height: this.props.PanelHeight(), title: "Untitled Collection" }), undefined); } }); @@ -625,7 +645,7 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> { if (curPres) { const pinDoc = Docs.Create.PresElementBoxDocument({ backgroundColor: "transparent" }); Doc.GetProto(pinDoc).presentationTargetDoc = doc; - Doc.GetProto(pinDoc).title = ComputedField.MakeFunction('(this.presentationTargetDoc instanceof Doc) && this.presentationTargetDoc.title.toString()'); + Doc.GetProto(pinDoc).title = ComputedField.MakeFunction('(this.presentationTargetDoc instanceof Doc) && this.presentationTargetDoc.title?.toString()'); const data = Cast(curPres.data, listSpec(Doc)); if (data) { data.push(pinDoc); @@ -665,19 +685,19 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> { } get layoutDoc() { return this._document && Doc.Layout(this._document); } - panelWidth = () => this.layoutDoc && this.layoutDoc.maxWidth ? Math.min(Math.max(NumCast(this.layoutDoc.width), NumCast(this.layoutDoc.nativeWidth)), this._panelWidth) : this._panelWidth; + panelWidth = () => this.layoutDoc && this.layoutDoc.maxWidth ? Math.min(Math.max(NumCast(this.layoutDoc._width), NumCast(this.layoutDoc._nativeWidth)), this._panelWidth) : this._panelWidth; panelHeight = () => this._panelHeight; - nativeWidth = () => !this.layoutDoc!.ignoreAspect && !this.layoutDoc!.fitWidth ? NumCast(this.layoutDoc!.nativeWidth) || this._panelWidth : 0; - nativeHeight = () => !this.layoutDoc!.ignoreAspect && !this.layoutDoc!.fitWidth ? NumCast(this.layoutDoc!.nativeHeight) || this._panelHeight : 0; + nativeWidth = () => !this.layoutDoc!.ignoreAspect && !this.layoutDoc!._fitWidth ? NumCast(this.layoutDoc!._nativeWidth) || this._panelWidth : 0; + nativeHeight = () => !this.layoutDoc!.ignoreAspect && !this.layoutDoc!._fitWidth ? NumCast(this.layoutDoc!._nativeHeight) || this._panelHeight : 0; contentScaling = () => { if (this.layoutDoc!.type === DocumentType.PDF) { - if ((this.layoutDoc && this.layoutDoc.fitWidth) || - this._panelHeight / NumCast(this.layoutDoc!.nativeHeight) > this._panelWidth / NumCast(this.layoutDoc!.nativeWidth)) { - return this._panelWidth / NumCast(this.layoutDoc!.nativeWidth); + if ((this.layoutDoc && this.layoutDoc._fitWidth) || + this._panelHeight / NumCast(this.layoutDoc!._nativeHeight) > this._panelWidth / NumCast(this.layoutDoc!._nativeWidth)) { + return this._panelWidth / NumCast(this.layoutDoc!._nativeWidth); } else { - return this._panelHeight / NumCast(this.layoutDoc!.nativeHeight); + return this._panelHeight / NumCast(this.layoutDoc!._nativeHeight); } } const nativeH = this.nativeHeight(); @@ -723,7 +743,6 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> { bringToFront={emptyFunction} addDocument={undefined} removeDocument={undefined} - ruleProvider={undefined} ContentScaling={this.contentScaling} PanelWidth={this.panelWidth} PanelHeight={this.panelHeight} @@ -746,7 +765,7 @@ export class DockedFrameRenderer extends React.Component<DockedFrameProps> { (<div className="collectionDockingView-content" ref={ref => this._mainCont = ref} style={{ transform: `translate(${this.previewPanelCenteringOffset}px, 0px)`, - height: this.layoutDoc && this.layoutDoc.fitWidth ? undefined : "100%", + height: this.layoutDoc && this.layoutDoc._fitWidth ? undefined : "100%", width: this.widthpercent }}> {this.docView} diff --git a/src/client/views/collections/CollectionLinearView.tsx b/src/client/views/collections/CollectionLinearView.tsx index 77af2dc0e..67062ae41 100644 --- a/src/client/views/collections/CollectionLinearView.tsx +++ b/src/client/views/collections/CollectionLinearView.tsx @@ -38,8 +38,8 @@ export class CollectionLinearView extends CollectionSubView(LinearDocument) { componentDidMount() { // is there any reason this needs to exist? -syip. yes, it handles autoHeight for stacking views (masonry isn't yet supported). - this._widthDisposer = reaction(() => NumCast(this.props.Document.height, 0) + this.childDocs.length + (this.props.Document.isExpanded ? 1 : 0), - () => this.props.Document.width = 5 + (this.props.Document.isExpanded ? this.childDocs.length * (this.props.Document[HeightSym]()) : 10), + this._widthDisposer = reaction(() => this.props.Document[HeightSym]() + this.childDocs.length + (this.props.Document.isExpanded ? 1 : 0), + () => this.props.Document._width = 5 + (this.props.Document.isExpanded ? this.childDocs.length * (this.props.Document[HeightSym]()) : 10), { fireImmediately: true } ); @@ -73,7 +73,7 @@ export class CollectionLinearView extends CollectionSubView(LinearDocument) { public isCurrent(doc: Doc) { return !doc.isMinimized && (Math.abs(NumCast(doc.displayTimecode, -1) - NumCast(this.Document.currentTimecode, -1)) < 1.5 || NumCast(doc.displayTimecode, -1) === -1); } - dimension = () => NumCast(this.props.Document.height); // 2 * the padding + dimension = () => NumCast(this.props.Document._height); // 2 * the padding getTransform = (ele: React.RefObject<HTMLDivElement>) => () => { if (!ele.current) return Transform.Identity(); const { scale, translateX, translateY } = Utils.GetScreenTransform(ele.current); @@ -88,11 +88,11 @@ export class CollectionLinearView extends CollectionSubView(LinearDocument) { onChange={action((e: any) => this.props.Document.isExpanded = this.addMenuToggle.current!.checked)} /> <label htmlFor={`${guid}`} style={{ marginTop: "auto", marginBottom: "auto", background: StrCast(this.props.Document.backgroundColor, "black") === StrCast(this.props.Document.color, "white") ? "black" : StrCast(this.props.Document.backgroundColor, "black") }} title="Close Menu"><p>+</p></label> - <div className="collectionLinearView-content" style={{ height: this.dimension(), width: NumCast(this.props.Document.width, 25) }}> + <div className="collectionLinearView-content" style={{ height: this.dimension(), width: NumCast(this.props.Document._width, 25) }}> {this.childLayoutPairs.filter((pair) => this.isCurrent(pair.layout)).map((pair, ind) => { - const nested = pair.layout.viewType === CollectionViewType.Linear; + const nested = pair.layout._viewType === CollectionViewType.Linear; const dref = React.createRef<HTMLDivElement>(); - const nativeWidth = NumCast(pair.layout.nativeWidth, this.dimension()); + const nativeWidth = NumCast(pair.layout._nativeWidth, this.dimension()); const deltaSize = nativeWidth * .15 / 2; return <div className={`collectionLinearView-docBtn` + (pair.layout.onClick || pair.layout.onDragStart ? "-scalable" : "")} key={pair.layout[Id]} ref={dref} style={{ @@ -108,7 +108,6 @@ export class CollectionLinearView extends CollectionSubView(LinearDocument) { addDocTab={this.props.addDocTab} pinToPres={emptyFunction} removeDocument={this.props.removeDocument} - ruleProvider={undefined} onClick={undefined} ScreenToLocalTransform={this.getTransform(dref)} ContentScaling={returnOne} diff --git a/src/client/views/collections/CollectionMasonryViewFieldRow.tsx b/src/client/views/collections/CollectionMasonryViewFieldRow.tsx index 80752303c..e25a2f5eb 100644 --- a/src/client/views/collections/CollectionMasonryViewFieldRow.tsx +++ b/src/client/views/collections/CollectionMasonryViewFieldRow.tsx @@ -136,7 +136,7 @@ export class CollectionMasonryViewFieldRow extends React.Component<CMVFieldRowPr addDocument = (value: string, shiftDown?: boolean) => { this._createAliasSelected = false; const key = StrCast(this.props.parent.props.Document.sectionFilter); - const newDoc = Docs.Create.TextDocument({ height: 18, width: 200, title: value }); + const newDoc = Docs.Create.TextDocument("", { _height: 18, _width: 200, title: value }); newDoc[key] = this.getValue(this.props.heading); return this.props.parent.props.addDocument(newDoc); } @@ -258,7 +258,7 @@ export class CollectionMasonryViewFieldRow extends React.Component<CMVFieldRowPr @computed get contentLayout() { const rows = Math.max(1, Math.min(this.props.docList.length, Math.floor((this.props.parent.props.PanelWidth() - 2 * this.props.parent.xMargin) / (this.props.parent.columnWidth + this.props.parent.gridGap)))); const style = this.props.parent; const collapsed = this._collapsed; - const chromeStatus = this.props.parent.props.Document.chromeStatus; + const chromeStatus = this.props.parent.props.Document._chromeStatus; const newEditableViewProps = { GetValue: () => "", SetValue: this.addDocument, diff --git a/src/client/views/collections/CollectionPivotView.scss b/src/client/views/collections/CollectionPivotView.scss index bd3d6c77b..505091e98 100644 --- a/src/client/views/collections/CollectionPivotView.scss +++ b/src/client/views/collections/CollectionPivotView.scss @@ -2,12 +2,14 @@ display: flex; flex-direction: row; position: absolute; - height:100%; - width:100%; + height: 100%; + width: 100%; + .collectionPivotView-flyout { width: 400px; height: 300px; display: inline-block; + .collectionPivotView-flyout-item { background-color: lightgray; text-align: left; @@ -17,41 +19,70 @@ } } + .pivotKeyEntry { + position: absolute; + top: 5px; + right: 5px; + z-index: 10; + pointer-events: all; + padding: 5px; + border: 1px solid black; + } + .collectionPivotView-treeView { - display:flex; + display: flex; flex-direction: column; width: 200px; height: 100%; + .collectionPivotView-addfacet { - display:inline-block; + display: inline-block; width: 200px; height: 30px; background: darkGray; text-align: center; + .collectionPivotView-button { align-items: center; display: flex; width: 100%; height: 100%; + .collectionPivotView-span { margin: auto; } } - > div, > div > div { + + >div, + >div>div { width: 100%; height: 100%; text-align: center; } } + .collectionPivotView-tree { - display:inline-block; - width: 200px; + display: inline-block; + width: 100%; height: calc(100% - 30px); } } + .collectionPivotView-pivot { - display:inline-block; + display: inline-block; width: calc(100% - 200px); height: 100%; } + + .collectionPivotView-dragger { + background-color: lightgray; + height: 40px; + width: 20px; + position: absolute; + border-radius: 10px; + top: 55%; + border: 1px black solid; + z-index: 2; + left: -10px; + } }
\ No newline at end of file diff --git a/src/client/views/collections/CollectionPivotView.tsx b/src/client/views/collections/CollectionPivotView.tsx index 53ad433b3..440b6856b 100644 --- a/src/client/views/collections/CollectionPivotView.tsx +++ b/src/client/views/collections/CollectionPivotView.tsx @@ -1,59 +1,41 @@ -import { CollectionSubView } from "./CollectionSubView"; -import React = require("react"); -import { computed, action, IReactionDisposer, reaction, runInAction, observable } from "mobx"; -import { faEdit, faChevronCircleUp } from "@fortawesome/free-solid-svg-icons"; -import { Doc, DocListCast } from "../../../new_fields/Doc"; -import "./CollectionPivotView.scss"; +import { faEdit } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { action, computed, IReactionDisposer, observable } from "mobx"; import { observer } from "mobx-react"; -import { CollectionFreeFormView } from "./collectionFreeForm/CollectionFreeFormView"; -import { CollectionTreeView } from "./CollectionTreeView"; -import { Cast, StrCast, NumCast } from "../../../new_fields/Types"; +import { Set } from "typescript-collections"; +import { Doc, DocListCast } from "../../../new_fields/Doc"; +import { List } from "../../../new_fields/List"; +import { listSpec } from "../../../new_fields/Schema"; +import { ComputedField, ScriptField } from "../../../new_fields/ScriptField"; +import { Cast, StrCast } from "../../../new_fields/Types"; import { Docs } from "../../documents/Documents"; -import { ScriptField } from "../../../new_fields/ScriptField"; -import { CompileScript } from "../../util/Scripting"; +import { EditableView } from "../EditableView"; import { anchorPoints, Flyout } from "../TemplateMenu"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { List } from "../../../new_fields/List"; -import { Set } from "typescript-collections"; +import { CollectionFreeFormView } from "./collectionFreeForm/CollectionFreeFormView"; +import "./CollectionPivotView.scss"; +import { CollectionSubView } from "./CollectionSubView"; +import { CollectionTreeView } from "./CollectionTreeView"; +import React = require("react"); @observer export class CollectionPivotView extends CollectionSubView(doc => doc) { - componentDidMount = () => { - this.props.Document.freeformLayoutEngine = "pivot"; - if (true || !this.props.Document.facetCollection) { - const facetCollection = Docs.Create.FreeformDocument([], { title: "facetFilters", yMargin: 0, treeViewHideTitle: true }); + componentDidMount() { + this.props.Document._freeformLayoutEngine = "pivot"; + const childDetailed = this.props.Document.childDetailed; // bcz: needs to be here to make sure the childDetailed layout template has been loaded when the first item is clicked; + if (!this.props.Document._facetCollection) { + const facetCollection = Docs.Create.TreeDocument([], { title: "facetFilters", _yMargin: 0, treeViewHideTitle: true }); facetCollection.target = this.props.Document; + this.props.Document.excludeFields = new List<string>(["_facetCollection", "_docFilter"]); - const scriptText = "setDocFilter(context.target, heading, this.title, checked)"; - const script = CompileScript(scriptText, { - params: { this: Doc.name, heading: "boolean", checked: "boolean", context: Doc.name }, - typecheck: false, - editable: true, - }); - if (script.compiled) { - facetCollection.onCheckedClick = new ScriptField(script); - } - - const openDocText = "const alias = getAlias(this); alias.layoutKey = 'layout_detailed'; useRightSplit(alias); "; - const openDocScript = CompileScript(openDocText, { - params: { this: Doc.name, heading: "boolean", checked: "boolean", context: Doc.name }, - typecheck: false, - editable: true, - }); - if (openDocScript.compiled) { - this.props.Document.onChildClick = new ScriptField(openDocScript); - } - - this.props.Document.facetCollection = facetCollection; - this.props.Document.fitToBox = true; + const scriptText = "setDocFilter(containingTreeView.target, heading, this.title, checked)"; + const childText = "const alias = getAlias(this); Doc.ApplyTemplateTo(containingCollection.childDetailed, alias, 'layout_detailed'); useRightSplit(alias); "; + facetCollection.onCheckedClick = ScriptField.MakeScript(scriptText, { this: Doc.name, heading: "boolean", checked: "boolean", containingTreeView: Doc.name }); + this.props.Document.onChildClick = ScriptField.MakeScript(childText, { this: Doc.name, heading: "boolean", containingCollection: Doc.name }); + this.props.Document._facetCollection = facetCollection; + this.props.Document._fitToBox = true; } } - - @computed get fieldExtensionDoc() { - return Doc.fieldExtensionDoc(this.props.DataDoc || this.props.Document, this.props.fieldKey); - } - - bodyPanelWidth = () => this.props.PanelWidth() - 200; + bodyPanelWidth = () => this.props.PanelWidth() - this._facetWidth; getTransform = () => this.props.ScreenToLocalTransform().translate(-200, 0); @computed get _allFacets() { @@ -62,57 +44,105 @@ export class CollectionPivotView extends CollectionSubView(doc => doc) { return facets.toArray(); } - facetClick = (facet: string) => { - const facetCollection = this.props.Document.facetCollection; + /** + * Responds to clicking the check box in the flyout menu + */ + facetClick = (facetHeader: string) => { + const facetCollection = this.props.Document._facetCollection; if (facetCollection instanceof Doc) { - const found = DocListCast(facetCollection.data).findIndex(doc => doc.title === facet); + const found = DocListCast(facetCollection.data).findIndex(doc => doc.title === facetHeader); if (found !== -1) { - //Doc.RemoveDocFromList(facetCollection, "data", DocListCast(facetCollection.data)[found]); (facetCollection.data as List<Doc>).splice(found, 1); + const docFilter = Cast(this.props.Document._docFilter, listSpec("string")); + if (docFilter) { + let index: number; + while ((index = docFilter.findIndex(item => item === facetHeader)) !== -1) { + docFilter.splice(index, 3); + } + } } else { - const facetValues = new Set<string>(); - this.childDocs.forEach(child => { - Object.keys(Doc.GetProto(child)).forEach(key => child[key] instanceof Doc && facetValues.add((child[key] as Doc)[facet]?.toString() || "(null)")); - facetValues.add(child[facet]?.toString() || "(null)"); - }); - - const newFacetVals = facetValues.toArray().map(val => Docs.Create.TextDocument({ title: val.toString() })); - const newFacet = Docs.Create.FreeformDocument(newFacetVals, { title: facet, treeViewOpen: true, isFacetFilter: true }); + const newFacet = Docs.Create.TreeDocument([], { title: facetHeader, treeViewOpen: true, isFacetFilter: true }); + const capturedVariables = { layoutDoc: this.props.Document, dataDoc: this.dataDoc }; + const params = { layoutDoc: Doc.name, dataDoc: Doc.name, }; + newFacet.data = ComputedField.MakeFunction(`readFacetData(layoutDoc, dataDoc, "${this.props.fieldKey}", "${facetHeader}")`, params, capturedVariables); Doc.AddDocToList(facetCollection, "data", newFacet); } } } + _canClick = false; + _facetWidthOnDown = 0; + @observable _facetWidth = 200; + onPointerDown = (e: React.PointerEvent) => { + this._canClick = true; + this._facetWidthOnDown = e.screenX; + document.removeEventListener("pointermove", this.onPointerMove); + document.removeEventListener("pointerup", this.onPointerUp); + document.addEventListener("pointermove", this.onPointerMove); + document.addEventListener("pointerup", this.onPointerUp); + e.stopPropagation(); + e.preventDefault(); + } + + + @action + onPointerMove = (e: PointerEvent) => { + this._facetWidth = Math.max(this.props.ScreenToLocalTransform().transformPoint(e.clientX, 0)[0], 0); + Math.abs(e.movementX) > 6 && (this._canClick = false); + } + @action + onPointerUp = (e: PointerEvent) => { + if (Math.abs(e.screenX - this._facetWidthOnDown) < 6 && this._canClick) { + this._facetWidth = this._facetWidth < 15 ? 200 : 0; + } + document.removeEventListener("pointermove", this.onPointerMove); + document.removeEventListener("pointerup", this.onPointerUp); + } render() { - const facetCollection = Cast(this.props.Document?.facetCollection, Doc, null); + const facetCollection = Cast(this.props.Document?._facetCollection, Doc, null); const flyout = ( - <div className="collectionPivotView-flyout" title=" "> - {this._allFacets.map(facet => <label className="collectionPivotView-flyout-item" onClick={e => this.facetClick(facet)}> - <input type="checkbox" checked={this.props.Document.facetCollection instanceof Doc && DocListCast(this.props.Document.facetCollection.data).some(d => { - return d.title === facet; - })} /> + <div className="collectionPivotView-flyout" style={{ width: `${this._facetWidth}` }}> + {this._allFacets.map(facet => <label className="collectionPivotView-flyout-item" key={`${facet}`} onClick={e => this.facetClick(facet)}> + <input type="checkbox" onChange={e => { }} checked={DocListCast((this.props.Document._facetCollection as Doc)?.data).some(d => d.title === facet)} /> <span className="checkmark" /> {facet} </label>)} </div> ); - return !facetCollection ? (null) : <div className="collectionPivotView"> - <div className="collectionPivotView-treeView"> - <div className="collectionPivotView-addFacet" onPointerDown={e => e.stopPropagation()}> - <Flyout anchorPoint={anchorPoints.LEFT_TOP} content={flyout}> - <div className="collectionPivotView-button"> - <span className="collectionPivotView-span">Facet Filters</span> - <FontAwesomeIcon icon={faEdit} size={"lg"} /> - </div> - </Flyout> + return !facetCollection ? (null) : + <div className="collectionPivotView" style={{ height: `calc(100% - ${this.props.Document._chromeStatus === "enabled" ? 51 : 0}px)` }}> + <div className={"pivotKeyEntry"}> + <EditableView + contents={this.props.Document.pivotField} + GetValue={() => StrCast(this.props.Document.pivotField)} + SetValue={value => { + if (value && value.length) { + this.props.Document.pivotField = value; + return true; + } + return false; + }} + /> </div> - <div className="collectionPivotView-tree"> - <CollectionTreeView {...this.props} Document={facetCollection} /> + <div className="collectionPivotView-dragger" key="dragger" onPointerDown={this.onPointerDown} style={{ transform: `translate(${this._facetWidth}px, 0px)` }} > + <span title="library View Dragger" style={{ width: "5px", position: "absolute", top: "0" }} /> </div> - </div> - <div className="collectionPivotView-pivot"> - <CollectionFreeFormView {...this.props} ScreenToLocalTransform={this.getTransform} PanelWidth={this.bodyPanelWidth} /> - </div> - </div>; + <div className="collectionPivotView-treeView" style={{ width: `${this._facetWidth}px`, overflow: this._facetWidth < 15 ? "hidden" : undefined }}> + <div className="collectionPivotView-addFacet" style={{ width: `${this._facetWidth}px` }} onPointerDown={e => e.stopPropagation()}> + <Flyout anchorPoint={anchorPoints.LEFT_TOP} content={flyout}> + <div className="collectionPivotView-button"> + <span className="collectionPivotView-span">Facet Filters</span> + <FontAwesomeIcon icon={faEdit} size={"lg"} /> + </div> + </Flyout> + </div> + <div className="collectionPivotView-tree" key="tree"> + <CollectionTreeView {...this.props} Document={facetCollection} /> + </div> + </div> + <div className="collectionPivotView-pivot" key="pivot" style={{ width: this.bodyPanelWidth() }}> + <CollectionFreeFormView {...this.props} ScreenToLocalTransform={this.getTransform} PanelWidth={this.bodyPanelWidth} /> + </div> + </div>; } }
\ No newline at end of file diff --git a/src/client/views/collections/CollectionSchemaCells.tsx b/src/client/views/collections/CollectionSchemaCells.tsx index 79a34bc00..caffa7eb1 100644 --- a/src/client/views/collections/CollectionSchemaCells.tsx +++ b/src/client/views/collections/CollectionSchemaCells.tsx @@ -145,7 +145,6 @@ export class CollectionSchemaCell extends React.Component<CellProps> { DataDoc: this.props.rowProps.original, LibraryPath: [], fieldKey: this.props.rowProps.column.id as string, - ruleProvider: undefined, ContainingCollectionView: this.props.CollectionView, ContainingCollectionDoc: this.props.CollectionView && this.props.CollectionView.props.Document, isSelected: returnFalse, @@ -226,14 +225,14 @@ export class CollectionSchemaCell extends React.Component<CellProps> { if (value.startsWith(":=")) { return this.props.setComputed(value.substring(2), props.Document, this.props.rowProps.column.id!, this.props.row, this.props.col); } - const script = CompileScript(value, { requiredType: type, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } }); + const script = CompileScript(value, { requiredType: type, typecheck: false, editable: true, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } }); if (!script.compiled) { return false; } return this.applyToDoc(props.Document, this.props.row, this.props.col, script.run); }} OnFillDown={async (value: string) => { - const script = CompileScript(value, { requiredType: type, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } }); + const script = CompileScript(value, { requiredType: type, typecheck: false, editable: true, addReturn: true, params: { this: Doc.name, $r: "number", $c: "number", $: "any" } }); if (script.compiled) { DocListCast(this.props.Document[this.props.fieldKey]). forEach((doc, i) => this.applyToDoc(doc, i, this.props.col, script.run)); diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx index b466d9511..fa8be5177 100644 --- a/src/client/views/collections/CollectionSchemaView.tsx +++ b/src/client/views/collections/CollectionSchemaView.tsx @@ -144,7 +144,6 @@ export class CollectionSchemaView extends CollectionSubView(doc => doc) { LibraryPath={this.props.LibraryPath} childDocs={this.childDocs} renderDepth={this.props.renderDepth} - ruleProvider={this.props.Document.isRuleProvider && layoutDoc && layoutDoc.type !== DocumentType.TEXT ? this.props.Document : this.props.ruleProvider} PanelWidth={this.previewWidth} PanelHeight={this.previewHeight} getTransform={this.getPreviewTransform} @@ -478,7 +477,7 @@ export class SchemaTable extends React.Component<SchemaTableProps> { @undoBatch createRow = () => { - const newDoc = Docs.Create.TextDocument({ title: "", width: 100, height: 30 }); + const newDoc = Docs.Create.TextDocument("", { title: "", _width: 100, _height: 30 }); this.props.addDocument(newDoc); } @@ -625,6 +624,19 @@ export class SchemaTable extends React.Component<SchemaTableProps> { return Array.from(Object.keys(keys)); } + @undoBatch + @action + toggleTextwrap = async () => { + const textwrappedRows = Cast(this.props.Document.textwrappedSchemaRows, listSpec("string"), []); + if (textwrappedRows.length) { + this.props.Document.textwrappedSchemaRows = new List<string>([]); + } else { + const docs = DocListCast(this.props.Document[this.props.fieldKey]); + const allRows = docs instanceof Doc ? [docs[Id]] : docs.map(doc => doc[Id]); + this.props.Document.textwrappedSchemaRows = new List<string>(allRows); + } + } + @action toggleTextWrapRow = (doc: Doc): void => { const textWrapped = this.textWrappedRows; @@ -643,7 +655,7 @@ export class SchemaTable extends React.Component<SchemaTableProps> { const expanded = {}; //@ts-ignore expandedRowsList.forEach(row => expanded[row] = true); - console.log("text wrapped rows", ...[...this.textWrappedRows]); // TODO: get component to rerender on text wrap change without needign to console.log :(((( + const rerender = [...this.textWrappedRows]; // TODO: get component to rerender on text wrap change without needign to console.log :(((( return <ReactTable style={{ position: "relative" }} @@ -679,7 +691,8 @@ export class SchemaTable extends React.Component<SchemaTableProps> { onContextMenu = (e: React.MouseEvent): void => { if (!e.isPropagationStopped() && this.props.Document[Id] !== "mainDoc") { // need to test this because GoldenLayout causes a parallel hierarchy in the React DOM for its children and the main document view7 - ContextMenu.Instance.addItem({ description: "Make DB", event: this.makeDB, icon: "table" }); + // ContextMenu.Instance.addItem({ description: "Make DB", event: this.makeDB, icon: "table" }); + ContextMenu.Instance.addItem({ description: "Toggle text wrapping", event: this.toggleTextwrap, icon: "table" }) } } diff --git a/src/client/views/collections/CollectionStackingView.scss b/src/client/views/collections/CollectionStackingView.scss index e1577cfee..843c743db 100644 --- a/src/client/views/collections/CollectionStackingView.scss +++ b/src/client/views/collections/CollectionStackingView.scss @@ -385,4 +385,4 @@ .rc-switch-checked .rc-switch-inner { left: 8px; } -}
\ No newline at end of file +} diff --git a/src/client/views/collections/CollectionStackingView.tsx b/src/client/views/collections/CollectionStackingView.tsx index 7fe42386a..91c7ca76e 100644 --- a/src/client/views/collections/CollectionStackingView.tsx +++ b/src/client/views/collections/CollectionStackingView.tsx @@ -4,7 +4,7 @@ import { CursorProperty } from "csstype"; import { action, computed, IReactionDisposer, observable, reaction, runInAction } from "mobx"; import { observer } from "mobx-react"; import Switch from 'rc-switch'; -import { Doc, HeightSym, WidthSym } from "../../../new_fields/Doc"; +import { Doc, HeightSym, WidthSym, DataSym } from "../../../new_fields/Doc"; import { Id } from "../../../new_fields/FieldSymbols"; import { List } from "../../../new_fields/List"; import { listSpec } from "../../../new_fields/Schema"; @@ -39,13 +39,13 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { @observable _scroll = 0; // used to force the document decoration to update when scrolling @computed get sectionHeaders() { return Cast(this.props.Document.sectionHeaders, listSpec(SchemaHeaderField)); } @computed get sectionFilter() { return StrCast(this.props.Document.sectionFilter); } - @computed get filteredChildren() { return this.childDocs.filter(d => !d.isMinimized).map(d => (Doc.GetLayoutDataDocPair(this.props.Document, this.props.DataDoc, this.props.fieldKey, d).layout as Doc) || d); } - @computed get xMargin() { return NumCast(this.props.Document.xMargin, 2 * this.gridGap); } - @computed get yMargin() { return Math.max(this.props.Document.showTitle && !this.props.Document.showTitleHover ? 30 : 0, NumCast(this.props.Document.yMargin, 2 * this.gridGap)); } - @computed get gridGap() { return NumCast(this.props.Document.gridGap, 10); } + @computed get filteredChildren() { return this.childLayoutPairs.filter(pair => pair.layout instanceof Doc && !pair.layout.isMinimized).map(pair => pair.layout); } + @computed get xMargin() { return NumCast(this.props.Document._xMargin, 2 * this.gridGap); } + @computed get yMargin() { return Math.max(this.props.Document.showTitle && !this.props.Document.showTitleHover ? 30 : 0, NumCast(this.props.Document._yMargin, 2 * this.gridGap)); } + @computed get gridGap() { return NumCast(this.props.Document._gridGap, 10); } @computed get isStackingView() { return BoolCast(this.props.Document.singleColumn, true); } @computed get numGroupColumns() { return this.isStackingView ? Math.max(1, this.Sections.size + (this.showAddAGroup ? 1 : 0)) : 1; } - @computed get showAddAGroup() { return (this.sectionFilter && (this.props.Document.chromeStatus !== 'view-mode' && this.props.Document.chromeStatus !== 'disabled')); } + @computed get showAddAGroup() { return (this.sectionFilter && (this.props.Document._chromeStatus !== 'view-mode' && this.props.Document._chromeStatus !== 'disabled')); } @computed get columnWidth() { return Math.min(this.props.PanelWidth() / (this.props as any).ContentScaling() - 2 * this.xMargin, this.isStackingView ? Number.MAX_VALUE : NumCast(this.props.Document.columnWidth, 250)); @@ -55,7 +55,7 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { children(docs: Doc[]) { this._docXfs.length = 0; return docs.map((d, i) => { - const width = () => Math.min(d.nativeWidth && !d.ignoreAspect && !this.props.Document.fillColumn ? d[WidthSym]() : Number.MAX_VALUE, this.columnWidth / this.numGroupColumns); + const width = () => Math.min(d._nativeWidth && !d.ignoreAspect && !this.props.Document.fillColumn ? d[WidthSym]() : Number.MAX_VALUE, this.columnWidth / this.numGroupColumns); const height = () => this.getDocHeight(d); const dref = React.createRef<HTMLDivElement>(); const dxf = () => this.getDocTransform(d, dref.current!); @@ -63,7 +63,7 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { const rowSpan = Math.ceil((height() + this.gridGap) / this.gridGap); const style = this.isStackingView ? { width: width(), marginTop: i === 0 ? 0 : this.gridGap, height: height() } : { gridRowEnd: `span ${rowSpan}` }; return <div className={`collectionStackingView-${this.isStackingView ? "columnDoc" : "masonryDoc"}`} key={d[Id]} ref={dref} style={style} > - {this.getDisplayDoc(d, (d.resolvedDataDoc as Doc) || d, dxf, width)} + {this.getDisplayDoc(d, Cast(d.resolvedDataDoc, Doc, null) || this.props.DataDoc, dxf, width)} </div>; }); } @@ -104,7 +104,7 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { componentDidMount() { super.componentDidMount(); this._heightDisposer = reaction(() => { - if (this.props.Document.autoHeight) { + if (this.props.Document._autoHeight) { const sectionsList = Array.from(this.Sections.size ? this.Sections.values() : [this.filteredChildren]); if (this.isStackingView) { const res = this.props.ContentScaling() * sectionsList.reduce((maxHght, s) => { @@ -125,7 +125,7 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { }, (hgt: number) => { const doc = hgt === -1 ? undefined : this.props.DataDoc && this.props.DataDoc.layout === this.layoutDoc ? this.props.DataDoc : this.layoutDoc; - doc && hgt > 0 && (Doc.Layout(doc).height = hgt); + doc && hgt > 0 && (Doc.Layout(doc)._height = hgt); }, { fireImmediately: true } ); @@ -151,10 +151,6 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { this.createDashEventsTarget(ele!); //so the whole grid is the drop target? } - overlays = (doc: Doc) => { - return doc.type === DocumentType.IMG || doc.type === DocumentType.VID ? { title: StrCast(this.props.Document.showTitles), titleHover: StrCast(this.props.Document.showTitleHovers), caption: StrCast(this.props.Document.showCaptions) } : {}; - } - @computed get onChildClickHandler() { return ScriptCast(this.Document.onChildClick); } @computed get onClickHandler() { return ScriptCast(this.Document.onChildClick); } @@ -165,9 +161,7 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { Document={doc} DataDocument={dataDoc} LibraryPath={this.props.LibraryPath} - showOverlays={this.overlays} renderDepth={this.props.renderDepth + 1} - ruleProvider={this.props.Document.isRuleProvider && layoutDoc.type !== DocumentType.TEXT ? this.props.Document : this.props.ruleProvider} fitToBox={this.props.fitToBox} onClick={layoutDoc.isTemplateDoc ? this.onClickHandler : this.onChildClickHandler} PanelWidth={width} @@ -188,16 +182,16 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { getDocHeight(d?: Doc) { if (!d) return 0; const layoutDoc = Doc.Layout(d); - const nw = NumCast(layoutDoc.nativeWidth); - const nh = NumCast(layoutDoc.nativeHeight); + const nw = NumCast(layoutDoc._nativeWidth); + const nh = NumCast(layoutDoc._nativeHeight); let wid = this.columnWidth / (this.isStackingView ? this.numGroupColumns : 1); - if (!layoutDoc.ignoreAspect && !layoutDoc.fitWidth && nw && nh) { + if (!layoutDoc.ignoreAspect && !layoutDoc._fitWidth && nw && nh) { const aspect = nw && nh ? nh / nw : 1; - if (!(d.nativeWidth && !layoutDoc.ignoreAspect && this.props.Document.fillColumn)) wid = Math.min(layoutDoc[WidthSym](), wid); + if (!(d._nativeWidth && !layoutDoc.ignoreAspect && this.props.Document.fillColumn)) wid = Math.min(layoutDoc[WidthSym](), wid); return wid * aspect; } - return layoutDoc.fitWidth ? !layoutDoc.nativeHeight ? this.props.PanelHeight() - 2 * this.yMargin : - Math.min(wid * NumCast(layoutDoc.scrollHeight, NumCast(layoutDoc.nativeHeight)) / NumCast(layoutDoc.nativeWidth, 1), this.props.PanelHeight() - 2 * this.yMargin) : layoutDoc[HeightSym](); + return layoutDoc._fitWidth ? !layoutDoc._nativeHeight ? this.props.PanelHeight() - 2 * this.yMargin : + Math.min(wid * NumCast(layoutDoc.scrollHeight, NumCast(layoutDoc._nativeHeight)) / NumCast(layoutDoc._nativeWidth, 1), this.props.PanelHeight() - 2 * this.yMargin) : layoutDoc[HeightSym](); } columnDividerDown = (e: React.PointerEvent) => { @@ -242,7 +236,7 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { const pos1 = cd.dxf().inverse().transformPoint(cd.width(), cd.height()); if (where[0] > pos[0] && where[0] < pos1[0] && where[1] > pos[1] && where[1] < pos1[1]) { targInd = i; - const axis = this.Document.viewType === CollectionViewType.Masonry ? 0 : 1; + const axis = this.Document._viewType === CollectionViewType.Masonry ? 0 : 1; plusOne = where[axis] > (pos[axis] + pos1[axis]) / 2 ? 1 : 0; } }); @@ -360,7 +354,7 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { } onToggle = (checked: Boolean) => { - this.props.Document.chromeStatus = checked ? "collapsed" : "view-mode"; + this.props.Document._chromeStatus = checked ? "collapsed" : "view-mode"; } onContextMenu = (e: React.MouseEvent): void => { @@ -395,6 +389,7 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { <div className={this.isStackingView ? "collectionStackingView" : "collectionMasonryView"} ref={this.createRef} style={{ + overflowY: this.props.active() ? "auto" : "hidden", transform: `scale(${Math.min(1, this.props.PanelHeight() / this.layoutDoc[HeightSym]())})`, height: `${Math.max(100, 100 * 1 / Math.min(this.props.PanelWidth() / this.layoutDoc[WidthSym](), this.props.PanelHeight() / this.layoutDoc[HeightSym]()))}%`, transformOrigin: "top" @@ -402,17 +397,17 @@ export class CollectionStackingView extends CollectionSubView(doc => doc) { onScroll={action((e: React.UIEvent<HTMLDivElement>) => this._scroll = e.currentTarget.scrollTop)} onDrop={this.onDrop.bind(this)} onContextMenu={this.onContextMenu} - onWheel={e => e.stopPropagation()} > + onWheel={e => this.props.active() && e.stopPropagation()} > {this.renderedSections} {!this.showAddAGroup ? (null) : <div key={`${this.props.Document[Id]}-addGroup`} className="collectionStackingView-addGroupButton" style={{ width: !this.isStackingView ? "100%" : this.columnWidth / this.numGroupColumns - 10, marginTop: 10 }}> <EditableView {...editableViewProps} /> </div>} - {this.props.Document.chromeStatus !== 'disabled' ? <Switch + {this.props.Document._chromeStatus !== 'disabled' ? <Switch onChange={this.onToggle} onClick={this.onToggle} - defaultChecked={this.props.Document.chromeStatus !== 'view-mode'} + defaultChecked={this.props.Document._chromeStatus !== 'view-mode'} checkedChildren="edit" unCheckedChildren="view" /> : null} diff --git a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx index 23a664359..2a9f903bb 100644 --- a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx +++ b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx @@ -4,7 +4,7 @@ import { faPalette } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { action, observable, runInAction } from "mobx"; import { observer } from "mobx-react"; -import { Doc } from "../../../new_fields/Doc"; +import { Doc, DocListCast } from "../../../new_fields/Doc"; import { PastelSchemaPalette, SchemaHeaderField } from "../../../new_fields/SchemaHeaderField"; import { ScriptField } from "../../../new_fields/ScriptField"; import { NumCast, StrCast } from "../../../new_fields/Types"; @@ -21,6 +21,9 @@ import { TraceMobx } from "../../../new_fields/util"; import { FormattedTextBox } from "../nodes/FormattedTextBox"; import { ImageField } from "../../../new_fields/URLField"; import { ImageBox } from "../nodes/ImageBox"; +import { ContextMenu } from "../ContextMenu"; +import { ContextMenuProps } from "../ContextMenuItem"; +import { RichTextField } from "../../../new_fields/RichTextField"; library.add(faPalette); @@ -135,18 +138,10 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC @action addDocument = (value: string, shiftDown?: boolean) => { - if (value === ":freeForm") { - return this.props.parent.props.addDocument(Docs.Create.FreeformDocument([], { width: 200, height: 200 })); - } else if (value.startsWith(":")) { - const { Document, addDocument } = this.props.parent.props; - const fieldKey = value.substring(1); - const proto = Doc.GetProto(Document); - const created = Docs.Get.DocumentFromField(Document, fieldKey, proto); - return created ? addDocument(created) : false; - } + if (!value) return false; this._createAliasSelected = false; const key = StrCast(this.props.parent.props.Document.sectionFilter); - const newDoc = Docs.Create.TextDocument({ height: 18, width: 200, documentText: "@@@" + value, title: value, autoHeight: true }); + const newDoc = Docs.Create.TextDocument(value, { _height: 18, _width: 200, title: value, _autoHeight: true }); newDoc[key] = this.getValue(this.props.heading); const maxHeading = this.props.docList.reduce((maxHeading, doc) => NumCast(doc.heading) > maxHeading ? NumCast(doc.heading) : maxHeading, 0); const heading = maxHeading === 0 || this.props.docList.length === 0 ? 1 : maxHeading === 1 ? 2 : 3; @@ -269,6 +264,57 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC @observable _headingsHack: number = 1; + menuCallback = (x: number, y: number) => { + ContextMenu.Instance.clearItems(); + const layoutItems: ContextMenuProps[] = []; + const docItems: ContextMenuProps[] = []; + + const dataDoc = this.props.parent.props.DataDoc || this.props.parent.Document; + Array.from(Object.keys(Doc.GetProto(dataDoc))).filter(fieldKey => dataDoc[fieldKey] instanceof RichTextField || dataDoc[fieldKey] instanceof ImageField || typeof (dataDoc[fieldKey]) === "string").map(fieldKey => + docItems.push({ + description: ":" + fieldKey, event: () => { + const created = Docs.Get.DocumentFromField(dataDoc, fieldKey, Doc.GetProto(this.props.parent.props.Document)); + if (created) { + if (this.props.parent.Document.isTemplateDoc) { + Doc.MakeMetadataFieldTemplate(created, this.props.parent.props.Document); + } + return this.props.parent.props.addDocument(created); + } + }, icon: "compress-arrows-alt" + })); + Array.from(Object.keys(Doc.GetProto(dataDoc))).filter(fieldKey => DocListCast(dataDoc[fieldKey]).length).map(fieldKey => + docItems.push({ + description: ":" + fieldKey, event: () => { + const created = Docs.Create.CarouselDocument([], { _width: 400, _height: 200, title: fieldKey }); + if (created) { + if (this.props.parent.Document.isTemplateDoc) { + Doc.MakeMetadataFieldTemplate(created, this.props.parent.props.Document); + } + return this.props.parent.props.addDocument(created); + } + }, icon: "compress-arrows-alt" + })); + layoutItems.push({ description: ":freeform", event: () => this.props.parent.props.addDocument(Docs.Create.FreeformDocument([], { _width: 200, _height: 200, _LODdisable: true })), icon: "compress-arrows-alt" }); + layoutItems.push({ description: ":carousel", event: () => this.props.parent.props.addDocument(Docs.Create.CarouselDocument([], { _width: 400, _height: 200, _LODdisable: true })), icon: "compress-arrows-alt" }); + layoutItems.push({ description: ":columns", event: () => this.props.parent.props.addDocument(Docs.Create.MulticolumnDocument([], { _width: 200, _height: 200 })), icon: "compress-arrows-alt" }); + layoutItems.push({ description: ":image", event: () => this.props.parent.props.addDocument(Docs.Create.ImageDocument("http://www.cs.brown.edu/~bcz/face.gif", { _width: 200, _height: 200 })), icon: "compress-arrows-alt" }); + + ContextMenu.Instance.addItem({ description: "Doc Fields ...", subitems: docItems, icon: "eye" }); + ContextMenu.Instance.addItem({ description: "Containers ...", subitems: layoutItems, icon: "eye" }); + ContextMenu.Instance.setDefaultItem("::", (name: string): void => { + Doc.GetProto(this.props.parent.props.Document)[name] = ""; + const created = Docs.Create.TextDocument("", { title: name, _width: 250, _autoHeight: true }); + if (created) { + if (this.props.parent.Document.isTemplateDoc) { + Doc.MakeMetadataFieldTemplate(created, this.props.parent.props.Document); + } + this.props.parent.props.addDocument(created); + } + }); + const pt = this.props.screenToLocalTransform().inverse().transformPoint(x, y); + ContextMenu.Instance.displayMenu(pt[0], pt[1]); + } + render() { TraceMobx(); const cols = this.props.cols(); @@ -304,7 +350,7 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC style={{ width: (style.columnWidth) / ((uniqueHeadings.length + - ((this.props.parent.props.Document.chromeStatus !== 'view-mode' && this.props.parent.props.Document.chromeStatus !== 'disabled') ? 1 : 0)) || 1) + ((this.props.parent.props.Document._chromeStatus !== 'view-mode' && this.props.parent.props.Document._chromeStatus !== 'disabled') ? 1 : 0)) || 1) }}> <div className={"collectionStackingView-collapseBar" + (this.props.headingObject.collapsed === true ? " active" : "")} onClick={this.collapseSection}></div> {/* the default bucket (no key value) has a tooltip that describes what it is. @@ -344,7 +390,7 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC </div> </div> : (null); for (let i = 0; i < cols; i++) templatecols += `${style.columnWidth / style.numGroupColumns}px `; - const chromeStatus = this.props.parent.props.Document.chromeStatus; + const chromeStatus = this.props.parent.props.Document._chromeStatus; return ( <div className="collectionStackingViewFieldColumn" key={heading} style={{ width: `${100 / ((uniqueHeadings.length + ((chromeStatus !== 'view-mode' && chromeStatus !== 'disabled') ? 1 : 0)) || 1)}%`, background: this._background }} ref={this.createColumnDropRef} onPointerEnter={this.pointerEntered} onPointerLeave={this.pointerLeave}> @@ -369,7 +415,7 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC {(chromeStatus !== 'view-mode' && chromeStatus !== 'disabled') ? <div key={`${heading}-add-document`} className="collectionStackingView-addDocumentButton" style={{ width: style.columnWidth / style.numGroupColumns }}> - <EditableView {...newEditableViewProps} /> + <EditableView {...newEditableViewProps} menuCallback={this.menuCallback} /> </div> : null} </div> } diff --git a/src/client/views/collections/CollectionStaffView.tsx b/src/client/views/collections/CollectionStaffView.tsx index 105061f46..8c7e113b2 100644 --- a/src/client/views/collections/CollectionStaffView.tsx +++ b/src/client/views/collections/CollectionStaffView.tsx @@ -23,10 +23,6 @@ export class CollectionStaffView extends CollectionSubView(doc => doc) { this.props.Document.staves = 5; } - @computed get fieldExtensionDoc() { - return Doc.fieldExtensionDoc(this.props.DataDoc || this.props.Document, this.props.fieldKey); - } - @computed get addStaffButton() { return <div onPointerDown={this.addStaff}>+</div>; } diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx index 5f4ee3669..8679c8bd1 100644 --- a/src/client/views/collections/CollectionSubView.tsx +++ b/src/client/views/collections/CollectionSubView.tsx @@ -1,4 +1,4 @@ -import { action, computed, IReactionDisposer, reaction } from "mobx"; +import { action, computed, IReactionDisposer, reaction, trace } from "mobx"; import * as rp from 'request-promise'; import CursorField from "../../../new_fields/CursorField"; import { Doc, DocListCast, Opt } from "../../../new_fields/Doc"; @@ -40,7 +40,6 @@ export interface CollectionViewProps extends FieldViewProps { export interface SubCollectionViewProps extends CollectionViewProps { CollectionView: Opt<CollectionView>; - ruleProvider: Doc | undefined; children?: never | (() => JSX.Element[]) | React.ReactNode; isAnnotationOverlay?: boolean; annotationsKey: string; @@ -53,9 +52,9 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { protected multiTouchDisposer?: InteractionUtils.MultiTouchEventDisposer; private _childLayoutDisposer?: IReactionDisposer; protected createDashEventsTarget = (ele: HTMLDivElement) => { //used for stacking and masonry view - this.dropDisposer && this.dropDisposer(); - this.gestureDisposer && this.gestureDisposer(); - this.multiTouchDisposer && this.multiTouchDisposer(); + this.dropDisposer?.(); + this.gestureDisposer?.(); + this.multiTouchDisposer?.(); if (ele) { this.dropDisposer = DragManager.MakeDropTarget(ele, this.drop.bind(this)); this.gestureDisposer = GestureUtils.MakeGestureTarget(ele, this.onGesture.bind(this)); @@ -67,35 +66,39 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { } componentDidMount() { - this._childLayoutDisposer = reaction(() => [this.childDocs, Cast(this.props.Document.childLayout, Doc)], - async (args) => { - if (args[1] instanceof Doc) { - this.childDocs.map(async doc => !Doc.AreProtosEqual(args[1] as Doc, (await doc).layout as Doc) && Doc.ApplyTemplateTo(args[1] as Doc, (await doc), "layoutFromParent")); + this._childLayoutDisposer = reaction(() => [this.childDocs, (Cast(this.props.Document.childLayout, Doc) as Doc)?.[Id]], + (args) => { + const childLayout = Cast(this.props.Document.childLayout, Doc); + if (childLayout instanceof Doc) { + this.childDocs.map(doc => Doc.ApplyTemplateTo(childLayout, doc, "layout_fromParent")); } - else if (!(args[1] instanceof Promise)) { - this.childDocs.filter(d => !d.isTemplateField).map(async doc => doc.layoutKey === "layoutFromParent" && (doc.layoutKey = "layout")); + else if (!(childLayout instanceof Promise)) { + this.childDocs.filter(d => !d.isTemplateForField).map(doc => doc.layoutKey === "layout_fromParent" && (doc.layoutKey = "layout")); } - }); + }, { fireImmediately: true }); } componentWillUnmount() { this._childLayoutDisposer && this._childLayoutDisposer(); } - @computed get dataDoc() { return this.props.DataDoc && this.props.Document.isTemplateField ? Doc.GetProto(this.props.DataDoc) : Doc.GetProto(this.props.Document); } - @computed get extensionDoc() { return Doc.fieldExtensionDoc(this.dataDoc, this.props.fieldKey); } + @computed get dataDoc() { return this.props.DataDoc && this.props.Document.isTemplateForField ? Doc.GetProto(this.props.DataDoc) : Doc.GetProto(this.props.Document); } // The data field for rendering this collection will be on the this.props.Document unless we're rendering a template in which case we try to use props.DataDoc. // When a document has a DataDoc but it's not a template, then it contains its own rendering data, but needs to pass the DataDoc through // to its children which may be templates. // If 'annotationField' is specified, then all children exist on that field of the extension document, otherwise, they exist directly on the data document under 'fieldKey' @computed get dataField() { - return this.props.annotationsKey ? (this.extensionDoc ? this.extensionDoc[this.props.annotationsKey] : undefined) : this.dataDoc[this.props.fieldKey]; + const { annotationsKey, fieldKey } = this.props; + if (annotationsKey) { + return this.dataDoc[fieldKey + "-" + annotationsKey]; + } + return this.dataDoc[fieldKey]; } get childLayoutPairs(): { layout: Doc; data: Doc; }[] { - const { Document, DataDoc, fieldKey } = this.props; - const validPairs = this.childDocs.map(doc => Doc.GetLayoutDataDocPair(Document, DataDoc, fieldKey, doc)).filter(pair => pair.layout); + const { Document, DataDoc } = this.props; + const validPairs = this.childDocs.map(doc => Doc.GetLayoutDataDocPair(Document, DataDoc, doc)).filter(pair => pair.layout); return validPairs.map(({ data, layout }) => ({ data: data!, layout: layout! })); // this mapping is a bit of a hack to coerce types } get childDocList() { @@ -104,7 +107,34 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { get childDocs() { const docs = DocListCast(this.dataField); const viewSpecScript = Cast(this.props.Document.viewSpecScript, ScriptField); - return viewSpecScript ? docs.filter(d => viewSpecScript.script.run({ doc: d }, console.log).result) : docs; + const viewedDocs = viewSpecScript ? docs.filter(d => viewSpecScript.script.run({ doc: d }, console.log).result) : docs; + const docFilters = Cast(this.props.Document._docFilter, listSpec("string"), []); + const clusters: { [key: string]: { [value: string]: string } } = {}; + for (let i = 0; i < docFilters.length; i += 3) { + const [key, value, modifiers] = docFilters.slice(i, i + 3); + const cluster = clusters[key]; + if (!cluster) { + const child: { [value: string]: string } = {}; + child[value] = modifiers; + clusters[key] = child; + } else { + cluster[value] = modifiers; + } + } + const filteredDocs = docFilters.length ? viewedDocs.filter(d => { + for (const key of Object.keys(clusters)) { + const cluster = clusters[key]; + const satisfiesFacet = Object.keys(cluster).some(inner => { + const modifier = cluster[inner]; + return (modifier === "x") !== Doc.matchFieldValue(d, key, inner); + }); + if (!satisfiesFacet) { + return false; + } + } + return true; + }) : viewedDocs; + return filteredDocs; } @action @@ -153,7 +183,7 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { if (docDragData && !docDragData.applyAsTemplate) { if (de.altKey && docDragData.draggedDocuments.length) { this.childDocs.map(doc => - Doc.ApplyTemplateTo(docDragData.draggedDocuments[0], doc, "layoutFromParent")); + Doc.ApplyTemplateTo(docDragData.draggedDocuments[0], doc, "layout_fromParent")); e.stopPropagation(); return true; } @@ -209,7 +239,7 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { this.props.addDocument && this.props.addDocument(Docs.Create.WebDocument(href, { ...options, title: href })); } } else if (text) { - this.props.addDocument && this.props.addDocument(Docs.Create.TextDocument({ ...options, width: 100, height: 25, documentText: "@@@" + text })); + this.props.addDocument && this.props.addDocument(Docs.Create.TextDocument(text, { ...options, _width: 100, _height: 25 })); } return; } @@ -219,7 +249,7 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { const img = tags[0].startsWith("img") ? tags[0] : tags.length > 1 && tags[1].startsWith("img") ? tags[1] : ""; if (img) { const split = img.split("src=\"")[1].split("\"")[0]; - const doc = Docs.Create.ImageDocument(split, { ...options, width: 300 }); + const doc = Docs.Create.ImageDocument(split, { ...options, _width: 300 }); ImageUtils.ExtractExif(doc); this.props.addDocument(doc); return; @@ -234,7 +264,7 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { } }); } else { - const htmlDoc = Docs.Create.HtmlDocument(html, { ...options, title: "-web page-", width: 300, height: 300, documentText: text }); + const htmlDoc = Docs.Create.HtmlDocument(html, { ...options, title: "-web page-", _width: 300, _height: 300, documentText: text }); this.props.addDocument(htmlDoc); } return; @@ -242,12 +272,12 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { } if (text && text.indexOf("www.youtube.com/watch") !== -1) { const url = text.replace("youtube.com/watch?v=", "youtube.com/embed/"); - this.props.addDocument(Docs.Create.VideoDocument(url, { ...options, title: url, width: 400, height: 315, nativeWidth: 600, nativeHeight: 472.5 })); + this.props.addDocument(Docs.Create.VideoDocument(url, { ...options, title: url, _width: 400, _height: 315, _nativeWidth: 600, _nativeHeight: 472.5 })); return; } let matches: RegExpExecArray | null; if ((matches = /(https:\/\/)?docs\.google\.com\/document\/d\/([^\\]+)\/edit/g.exec(text)) !== null) { - const newBox = Docs.Create.TextDocument({ ...options, width: 400, height: 200, title: "Awaiting title from Google Docs..." }); + const newBox = Docs.Create.TextDocument("", { ...options, _width: 400, _height: 200, title: "Awaiting title from Google Docs..." }); const proto = newBox.proto!; const documentId = matches[2]; proto[GoogleRef] = documentId; @@ -294,13 +324,20 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { formData.append('file', file); const dropFileName = file ? file.name : "-empty-"; - promises.push(Networking.PostFormDataToServer("/upload", formData).then(results => { - results.map(action(({ clientAccessPath }: any) => { - const full = { ...options, width: 300, title: dropFileName }; + promises.push(Networking.PostFormDataToServer("/uploadFormData", formData).then(results => { + results.map(action((result: any) => { + const { clientAccessPath, nativeWidth, nativeHeight, contentSize } = result; + const full = { ...options, _width: 300, title: dropFileName }; const pathname = Utils.prepend(clientAccessPath); Docs.Get.DocumentFromType(type, pathname, full).then(doc => { - doc && (Doc.GetProto(doc).fileUpload = basename(pathname).replace("upload_", "").replace(/\.[a-z0-9]*$/, "")); - doc && this.props.addDocument(doc); + if (doc) { + const proto = Doc.GetProto(doc); + proto.fileUpload = basename(pathname).replace("upload_", "").replace(/\.[a-z0-9]*$/, ""); + nativeWidth && (proto["data-nativeWidth"] = nativeWidth); + nativeHeight && (proto["data-nativeHeight"] = nativeHeight); + contentSize && (proto.contentSize = contentSize); + this.props.addDocument(doc); + } }); })); })); @@ -311,7 +348,7 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { Promise.all(promises).finally(() => { completed && completed(); batch.end(); }); } else { if (text && !text.includes("https://")) { - this.props.addDocument(Docs.Create.TextDocument({ ...options, documentText: "@@@" + text, width: 400, height: 315 })); + this.props.addDocument(Docs.Create.TextDocument(text, { ...options, _width: 400, _height: 315 })); } batch.end(); } diff --git a/src/client/views/collections/CollectionTreeView.tsx b/src/client/views/collections/CollectionTreeView.tsx index a48208bd9..a7733ab5f 100644 --- a/src/client/views/collections/CollectionTreeView.tsx +++ b/src/client/views/collections/CollectionTreeView.tsx @@ -1,19 +1,22 @@ import { library } from '@fortawesome/fontawesome-svg-core'; import { faAngleRight, faArrowsAltH, faBell, faCamera, faCaretDown, faCaretRight, faCaretSquareDown, faCaretSquareRight, faExpand, faMinus, faPlus, faTrash, faTrashAlt } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { action, computed, observable, untracked, runInAction } from "mobx"; +import { action, computed, observable, runInAction, untracked } from "mobx"; import { observer } from "mobx-react"; import { Doc, DocListCast, Field, HeightSym, WidthSym } from '../../../new_fields/Doc'; import { Id } from '../../../new_fields/FieldSymbols'; import { List } from '../../../new_fields/List'; import { Document, listSpec } from '../../../new_fields/Schema'; import { ComputedField, ScriptField } from '../../../new_fields/ScriptField'; -import { BoolCast, Cast, NumCast, StrCast, ScriptCast } from '../../../new_fields/Types'; -import { emptyFunction, Utils, returnFalse, emptyPath } from '../../../Utils'; +import { BoolCast, Cast, NumCast, ScriptCast, StrCast } from '../../../new_fields/Types'; +import { CurrentUserUtils } from '../../../server/authentication/models/current_user_utils'; +import { emptyFunction, emptyPath, returnFalse, Utils } from '../../../Utils'; import { Docs, DocUtils } from '../../documents/Documents'; import { DocumentType } from "../../documents/DocumentTypes"; import { DocumentManager } from '../../util/DocumentManager'; import { DragManager, dropActionType, SetupDrag } from "../../util/DragManager"; +import { makeTemplate } from '../../util/DropConverter'; +import { Scripting } from '../../util/Scripting'; import { SelectionManager } from '../../util/SelectionManager'; import { Transform } from '../../util/Transform'; import { undoBatch } from '../../util/UndoManager'; @@ -21,17 +24,17 @@ import { ContextMenu } from '../ContextMenu'; import { ContextMenuProps } from '../ContextMenuItem'; import { EditableView } from "../EditableView"; import { MainView } from '../MainView'; +import { ContentFittingDocumentView } from '../nodes/ContentFittingDocumentView'; +import { ImageBox } from '../nodes/ImageBox'; import { KeyValueBox } from '../nodes/KeyValueBox'; +import { ScriptBox } from '../ScriptBox'; import { Templates } from '../Templates'; -import { ContentFittingDocumentView } from '../nodes/ContentFittingDocumentView'; import { CollectionSubView } from "./CollectionSubView"; import "./CollectionTreeView.scss"; import React = require("react"); -import { CurrentUserUtils } from '../../../server/authentication/models/current_user_utils'; -import { ScriptBox } from '../ScriptBox'; -import { ImageBox } from '../nodes/ImageBox'; -import { makeTemplate } from '../../util/DropConverter'; -import { CollectionDockingView } from './CollectionDockingView'; +import { CollectionViewType } from './CollectionView'; +import { RichTextField } from '../../../new_fields/RichTextField'; +import { ObjectField } from '../../../new_fields/ObjectField'; export interface TreeViewProps { @@ -42,7 +45,6 @@ export interface TreeViewProps { prevSibling?: Doc; renderDepth: number; deleteDoc: (doc: Doc) => boolean; - ruleProvider: Doc | undefined; moveDocument: DragManager.MoveFunction; dropAction: "alias" | "copy" | undefined; addDocTab: (doc: Doc, dataDoc: Doc | undefined, where: string, libraryPath?: Doc[]) => boolean; @@ -178,8 +180,8 @@ class TreeView extends React.Component<TreeViewProps> { SetValue={undoBatch((value: string) => Doc.SetInPlace(this.props.document, key, value, false) || true)} OnFillDown={undoBatch((value: string) => { Doc.SetInPlace(this.props.document, key, value, false); - const layoutDoc = this.props.document.layoutCustom instanceof Doc ? Doc.ApplyTemplate(Doc.GetProto(this.props.document.layoutCustom)) : undefined; - const doc = layoutDoc || Docs.Create.FreeformDocument([], { title: "", x: 0, y: 0, width: 100, height: 25, templates: new List<string>([Templates.Title.Layout]) }); + const layoutDoc = this.props.document.layout_custom instanceof Doc ? Doc.ApplyTemplate(Doc.GetProto(this.props.document.layout_custom)) : undefined; + const doc = layoutDoc || Docs.Create.FreeformDocument([], { title: "", x: 0, y: 0, _width: 100, _height: 25, templates: new List<string>([Templates.Title.Layout]) }); TreeView.loadId = doc[Id]; return this.props.addDocument(doc); })} @@ -210,7 +212,7 @@ class TreeView extends React.Component<TreeViewProps> { ContextMenu.Instance.addItem({ description: "Delete Workspace", event: () => this.props.deleteDoc(this.props.document), icon: "trash-alt" }); ContextMenu.Instance.addItem({ description: "Create New Workspace", event: () => MainView.Instance.createNewWorkspace(), icon: "plus" }); } - ContextMenu.Instance.addItem({ description: "Open Fields", event: () => { const kvp = Docs.Create.KVPDocument(this.props.document, { width: 300, height: 300 }); this.props.addDocTab(kvp, this.props.dataDoc ? this.props.dataDoc : kvp, "onRight"); }, icon: "layer-group" }); + ContextMenu.Instance.addItem({ description: "Open Fields", event: () => { const kvp = Docs.Create.KVPDocument(this.props.document, { _width: 300, _height: 300 }); this.props.addDocTab(kvp, this.props.dataDoc ? this.props.dataDoc : kvp, "onRight"); }, icon: "layer-group" }); ContextMenu.Instance.addItem({ description: "Publish", event: () => DocUtils.Publish(this.props.document, StrCast(this.props.document.title), () => { }, () => { }), icon: "file" }); ContextMenu.Instance.displayMenu(e.pageX > 156 ? e.pageX - 156 : 0, e.pageY - 15); e.stopPropagation(); @@ -256,21 +258,21 @@ class TreeView extends React.Component<TreeViewProps> { } docWidth = () => { const layoutDoc = Doc.Layout(this.props.document); - const aspect = NumCast(layoutDoc.nativeHeight) / NumCast(layoutDoc.nativeWidth); + const aspect = NumCast(layoutDoc._nativeHeight) / NumCast(layoutDoc._nativeWidth); if (aspect) return Math.min(layoutDoc[WidthSym](), Math.min(this.MAX_EMBED_HEIGHT / aspect, this.props.panelWidth() - 20)); - return NumCast(layoutDoc.nativeWidth) ? Math.min(layoutDoc[WidthSym](), this.props.panelWidth() - 20) : this.props.panelWidth() - 20; + return NumCast(layoutDoc._nativeWidth) ? Math.min(layoutDoc[WidthSym](), this.props.panelWidth() - 20) : this.props.panelWidth() - 20; } docHeight = () => { const layoutDoc = Doc.Layout(this.props.document); const bounds = this.boundsOfCollectionDocument; return Math.min(this.MAX_EMBED_HEIGHT, (() => { - const aspect = NumCast(layoutDoc.nativeHeight) / NumCast(layoutDoc.nativeWidth, 1); + const aspect = NumCast(layoutDoc._nativeHeight) / NumCast(layoutDoc._nativeWidth, 1); if (aspect) return this.docWidth() * aspect; if (bounds) return this.docWidth() * (bounds.b - bounds.y) / (bounds.r - bounds.x); - return layoutDoc.fitWidth ? (!this.props.document.nativeHeight ? NumCast(this.props.containingCollection.height) : - Math.min(this.docWidth() * NumCast(layoutDoc.scrollHeight, NumCast(layoutDoc.nativeHeight)) / NumCast(layoutDoc.nativeWidth, - NumCast(this.props.containingCollection.height)))) : - NumCast(layoutDoc.height) ? NumCast(layoutDoc.height) : 50; + return layoutDoc._fitWidth ? (!this.props.document.nativeHeight ? NumCast(this.props.containingCollection._height) : + Math.min(this.docWidth() * NumCast(layoutDoc.scrollHeight, NumCast(layoutDoc._nativeHeight)) / NumCast(layoutDoc._nativeWidth, + NumCast(this.props.containingCollection._height)))) : + NumCast(layoutDoc._height) ? NumCast(layoutDoc._height) : 50; })()); } @@ -322,8 +324,6 @@ class TreeView extends React.Component<TreeViewProps> { return rows; } - noOverlays = (doc: Doc) => ({ title: "", caption: "" }); - @computed get renderContent() { const expandKey = this.treeViewExpandedView === this.fieldKey ? this.fieldKey : this.treeViewExpandedView === "links" ? "links" : undefined; if (expandKey !== undefined) { @@ -350,8 +350,6 @@ class TreeView extends React.Component<TreeViewProps> { DataDocument={this.templateDataDoc} LibraryPath={emptyPath} renderDepth={this.props.renderDepth + 1} - showOverlays={this.noOverlays} - ruleProvider={this.props.document.isRuleProvider && layoutDoc.type !== DocumentType.TEXT ? this.props.document : this.props.ruleProvider} fitToBox={this.boundsOfCollectionDocument !== undefined} PanelWidth={this.docWidth} PanelHeight={this.docHeight} @@ -372,12 +370,12 @@ class TreeView extends React.Component<TreeViewProps> { @action bulletClick = (e: React.MouseEvent) => { if (this.props.onCheckedClick && this.props.document.type !== DocumentType.COL) { - this.props.document.treeViewChecked = this.props.document.treeViewChecked === "check" ? "x" : this.props.document.treeViewChecked === "x" ? undefined : "check"; + // this.props.document.treeViewChecked = this.props.document.treeViewChecked === "check" ? "x" : this.props.document.treeViewChecked === "x" ? undefined : "check"; ScriptCast(this.props.onCheckedClick).script.run({ - this: this.props.document.isTemplateField && this.props.dataDoc ? this.props.dataDoc : this.props.document, + this: this.props.document.isTemplateForField && this.props.dataDoc ? this.props.dataDoc : this.props.document, heading: this.props.containingCollection.title, - checked: this.props.document.treeViewChecked === "check" ? false : this.props.document.treeViewChecked === "x" ? "x" : "none", - context: this.props.treeViewId + checked: this.props.document.treeViewChecked === "check" ? "x" : this.props.document.treeViewChecked === "x" ? undefined : "check", + containingTreeView: this.props.treeViewId, }, console.log); } else { this.treeViewOpen = !this.treeViewOpen; @@ -518,7 +516,7 @@ class TreeView extends React.Component<TreeViewProps> { const rowWidth = () => panelWidth() - 20; return docs.map((child, i) => { - const pair = Doc.GetLayoutDataDocPair(containingCollection, dataDoc, key, child); + const pair = Doc.GetLayoutDataDocPair(containingCollection, dataDoc, child); if (!pair.layout || pair.data instanceof Promise) { return (null); } @@ -548,7 +546,7 @@ class TreeView extends React.Component<TreeViewProps> { }; const childLayout = Doc.Layout(pair.layout); const rowHeight = () => { - const aspect = NumCast(childLayout.nativeWidth, 0) / NumCast(childLayout.nativeHeight, 0); + const aspect = NumCast(childLayout._nativeWidth, 0) / NumCast(childLayout._nativeHeight, 0); return aspect ? Math.min(childLayout[WidthSym](), rowWidth()) / aspect : childLayout[HeightSym](); }; return !(child instanceof Doc) ? (null) : <TreeView @@ -558,7 +556,6 @@ class TreeView extends React.Component<TreeViewProps> { containingCollection={containingCollection} prevSibling={docs[i]} treeViewId={treeViewId} - ruleProvider={containingCollection.isRuleProvider && pair.layout.type !== DocumentType.TEXT ? containingCollection : containingCollection.ruleProvider as Doc} key={child[Id]} indentDocument={indent} outdentDocument={outdent} @@ -633,32 +630,45 @@ export class CollectionTreeView extends CollectionSubView(Document) { } ContextMenu.Instance.addItem({ description: "Buxton Layout", icon: "eye", event: () => { - const { TextDocument, ImageDocument } = Docs.Create; - const wrapper = Docs.Create.StackingDocument([ - ImageDocument("http://www.cs.brown.edu/~bcz/face.gif", { title: "hero" }), - TextDocument({ title: "year" }), - TextDocument({ title: "degrees_of_freedom" }), - TextDocument({ title: "company" }), - TextDocument({ title: "short_description" }), - ], { autoHeight: true, chromeStatus: "disabled" }); - wrapper.disableLOD = true; - makeTemplate(wrapper, true); - const detailedLayout = Doc.MakeAlias(wrapper); - const cardLayout = ImageBox.LayoutString("hero"); - this.childLayoutPairs.forEach(({ layout }) => { - const proto = Doc.GetProto(layout); - proto.layout = cardLayout; - proto.layout_detailed = detailedLayout; - layout.showTitle = "title"; - layout.showTitleHover = "titlehover"; + DocListCast(this.dataDoc[this.props.fieldKey]).map(d => { + DocListCast(d.data).map((img, i) => { + const caption = (d.captions as any)[i]?.data; + if (caption instanceof ObjectField) { + Doc.GetProto(img).caption = ObjectField.MakeCopy(caption as ObjectField); + } + img._hideSidebar = true; + d.captions = undefined; + }); }); + const { TextDocument, ImageDocument, CarouselDocument } = Docs.Create; + const { Document } = this.props; + const fallbackImg = "http://www.cs.brown.edu/~bcz/face.gif"; + const detailedTemplate = `{ "doc": { "type": "doc", "content": [ { "type": "paragraph", "content": [ { "type": "dashField", "attrs": { "fieldKey": "short_description" } } ] }, { "type": "paragraph", "content": [ { "type": "dashField", "attrs": { "fieldKey": "year" } } ] }, { "type": "paragraph", "content": [ { "type": "dashField", "attrs": { "fieldKey": "company" } } ] } ] }, "selection":{"type":"text","anchor":1,"head":1},"storedMarks":[] }`; + + const textDoc = TextDocument("", { title: "details", _autoHeight: true }); + const detailedLayout = Docs.Create.StackingDocument([ + CarouselDocument([], { title: "data", _height: 350, _itemIndex: 0, backgroundColor: "#9b9b9b3F" }), + textDoc, + ], { _chromeStatus: "disabled", title: "detailed layout stack" }); + textDoc.data = new RichTextField(detailedTemplate, "short_description year company"); + detailedLayout.isTemplateDoc = makeTemplate(detailedLayout); + + const cardLayout = ImageDocument(fallbackImg, { title: "cardLayout", isTemplateDoc: true, isTemplateForField: "hero", }); // this acts like a template doc and a template field ... a little weird, but seems to work? + cardLayout.proto!.layout = ImageBox.LayoutString("hero"); + cardLayout.showTitle = "title"; + cardLayout.showTitleHover = "titlehover"; + + Document.childLayout = cardLayout; + Document.childDetailed = detailedLayout; + Document._viewType = CollectionViewType.Pivot; + Document.pivotField = "company"; } }); const existingOnClick = ContextMenu.Instance.findByDescription("OnClick..."); const onClicks: ContextMenuProps[] = existingOnClick && "subitems" in existingOnClick ? existingOnClick.subitems : []; onClicks.push({ description: "Edit onChecked Script", icon: "edit", event: (obj: any) => ScriptBox.EditButtonScript("On Checked Changed ...", this.props.Document, - "onCheckedClick", obj.x, obj.y, { heading: "boolean", checked: "boolean", context: Doc.name }) + "onCheckedClick", obj.x, obj.y, { heading: "boolean", checked: "boolean", treeViewContainer: Doc.name }) }); !existingOnClick && ContextMenu.Instance.addItem({ description: "OnClick...", subitems: onClicks, icon: "hand-point-right" }); } @@ -675,12 +685,12 @@ export class CollectionTreeView extends CollectionSubView(Document) { } render() { - const dropAction = StrCast(this.props.Document.dropAction) as dropActionType; + const dropAction = StrCast(this.props.Document._dropAction) as dropActionType; const addDoc = (doc: Doc, relativeTo?: Doc, before?: boolean) => Doc.AddDocToList(this.props.Document, this.props.fieldKey, doc, relativeTo, before, false, false, false); const moveDoc = (d: Doc, target: Doc | undefined, addDoc: (doc: Doc) => boolean) => this.props.moveDocument(d, target, addDoc); return !this.childDocs ? (null) : ( <div className="collectionTreeView-dropTarget" id="body" - style={{ background: StrCast(this.props.Document.backgroundColor, "lightgray"), paddingTop: `${NumCast(this.props.Document.yMargin, 20)}px` }} + style={{ background: StrCast(this.props.Document.backgroundColor, "lightgray"), paddingTop: `${NumCast(this.props.Document._yMargin, 20)}px` }} onContextMenu={this.onContextMenu} onWheel={(e: React.WheelEvent) => this._mainEle && this._mainEle.scrollHeight > this._mainEle.clientHeight && e.stopPropagation()} onDrop={this.onTreeDrop} @@ -694,8 +704,8 @@ export class CollectionTreeView extends CollectionSubView(Document) { SetValue={undoBatch((value: string) => Doc.SetInPlace(this.dataDoc, "title", value, false) || true)} OnFillDown={undoBatch((value: string) => { Doc.SetInPlace(this.dataDoc, "title", value, false); - const layoutDoc = this.props.Document.layoutCustom instanceof Doc ? Doc.ApplyTemplate(Doc.GetProto(this.props.Document.layoutCustom)) : undefined; - const doc = layoutDoc || Docs.Create.FreeformDocument([], { title: "", x: 0, y: 0, width: 100, height: 25, templates: new List<string>([Templates.Title.Layout]) }); + const layoutDoc = this.props.Document.layout_custom instanceof Doc ? Doc.ApplyTemplate(Doc.GetProto(this.props.Document.layout_custom)) : undefined; + const doc = layoutDoc || Docs.Create.FreeformDocument([], { title: "", x: 0, y: 0, _width: 100, _height: 25, templates: new List<string>([Templates.Title.Layout]) }); TreeView.loadId = doc[Id]; Doc.AddDocToList(this.props.Document, this.props.fieldKey, doc, this.childDocs.length ? this.childDocs[0] : undefined, true, false, false, false); })} />)} @@ -711,4 +721,30 @@ export class CollectionTreeView extends CollectionSubView(Document) { </div > ); } -}
\ No newline at end of file +} + +Scripting.addGlobal(function readFacetData(layoutDoc: Doc, dataDoc: Doc, dataKey: string, facetHeader: string) { + const allCollectionDocs = DocListCast(dataDoc[dataKey]); + const facetValues = Array.from(allCollectionDocs.reduce((set, child) => + set.add(Field.toString(child[facetHeader] as Field)), new Set<string>())); + + const facetValueDocSet = facetValues.sort().map(facetValue => + Docs.Create.TextDocument("", { + title: facetValue.toString(), + treeViewChecked: ComputedField.MakeFunction("determineCheckedState(layoutDoc, facetHeader, facetValue)", + { layoutDoc: Doc.name, facetHeader: "string", facetValue: "string" }, + { layoutDoc, facetHeader, facetValue }) + })); + return new List<Doc>(facetValueDocSet); +}); + +Scripting.addGlobal(function determineCheckedState(layoutDoc: Doc, facetHeader: string, facetValue: string) { + const docFilters = Cast(layoutDoc._docFilter, listSpec("string"), []); + for (let i = 0; i < docFilters.length; i += 3) { + const [header, value, state] = docFilters.slice(i, i + 3); + if (header === facetHeader && value === facetValue) { + return state; + } + } + return undefined; +});
\ No newline at end of file diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx index a665b678b..dab0ce08e 100644 --- a/src/client/views/collections/CollectionView.tsx +++ b/src/client/views/collections/CollectionView.tsx @@ -26,6 +26,7 @@ import { Touchable } from '../Touchable'; import { CollectionDockingView } from "./CollectionDockingView"; import { AddCustomFreeFormLayout } from './collectionFreeForm/CollectionFreeFormLayoutEngines'; import { CollectionFreeFormView } from './collectionFreeForm/CollectionFreeFormView'; +import { CollectionCarouselView } from './CollectionCarouselView'; import { CollectionLinearView } from './CollectionLinearView'; import { CollectionMulticolumnView } from './collectionMulticolumn/CollectionMulticolumnView'; import { CollectionPivotView } from './CollectionPivotView'; @@ -47,10 +48,11 @@ export enum CollectionViewType { Tree, Stacking, Masonry, + Multicolumn, Pivot, + Carousel, Linear, Staff, - Multicolumn, Timeline } @@ -63,9 +65,10 @@ export namespace CollectionViewType { ["tree", CollectionViewType.Tree], ["stacking", CollectionViewType.Stacking], ["masonry", CollectionViewType.Masonry], + ["multicolumn", CollectionViewType.Multicolumn], ["pivot", CollectionViewType.Pivot], + ["carousel", CollectionViewType.Carousel], ["linear", CollectionViewType.Linear], - ["multicolumn", CollectionViewType.Multicolumn] ]); export const valueOf = (value: string) => stringMapping.get(value.toLowerCase()); @@ -91,18 +94,8 @@ export class CollectionView extends Touchable<FieldViewProps> { @observable private static _safeMode = false; public static SetSafeMode(safeMode: boolean) { this._safeMode = safeMode; } - @computed get dataDoc() { return this.props.DataDoc && this.props.Document.isTemplateField ? Doc.GetProto(this.props.DataDoc) : Doc.GetProto(this.props.Document); } - @computed get extensionDoc() { return Doc.fieldExtensionDoc(this.dataDoc, this.props.fieldKey); } - get collectionViewType(): CollectionViewType | undefined { - if (!this.extensionDoc) return CollectionViewType.Invalid; - NumCast(this.props.Document.viewType) && setTimeout(() => { - if (this.props.Document.viewType) { - this.extensionDoc!.viewType = NumCast(this.props.Document.viewType); - } - Doc.GetProto(this.props.Document).viewType = this.props.Document.viewType = undefined; - }); - const viewField = NumCast(this.extensionDoc.viewType, Cast(this.props.Document.viewType, "number")); + const viewField = NumCast(this.props.Document._viewType); if (CollectionView._safeMode) { if (viewField === CollectionViewType.Freeform) { return CollectionViewType.Tree; @@ -111,15 +104,15 @@ export class CollectionView extends Touchable<FieldViewProps> { return CollectionViewType.Freeform; } } - return viewField === undefined ? CollectionViewType.Invalid : viewField; + return viewField; } componentDidMount = () => { - this._reactionDisposer = reaction(() => StrCast(this.props.Document.chromeStatus), + this._reactionDisposer = reaction(() => StrCast(this.props.Document._chromeStatus), () => { // chrome status is one of disabled, collapsed, or visible. this determines initial state from document // chrome status may also be view-mode, in reference to stacking view's toggle mode. it is essentially disabled mode, but prevents the toggle button from showing up on the left sidebar. - const chromeStatus = this.props.Document.chromeStatus; + const chromeStatus = this.props.Document._chromeStatus; if (chromeStatus && (chromeStatus === "disabled" || chromeStatus === "collapsed")) { runInAction(() => this._collapsed = true); } @@ -129,7 +122,7 @@ export class CollectionView extends Touchable<FieldViewProps> { componentWillUnmount = () => this._reactionDisposer && this._reactionDisposer(); // bcz: Argh? What's the height of the collection chromes?? - chromeHeight = () => (this.props.Document.chromeStatus === "enabled" ? -60 : 0); + chromeHeight = () => (this.props.Document._chromeStatus === "enabled" ? -60 : 0); active = (outsideReaction?: boolean) => this.props.isSelected(outsideReaction) || BoolCast(this.props.Document.forceActive) || this._isChildActive || this.props.renderDepth === 0; @@ -139,8 +132,7 @@ export class CollectionView extends Touchable<FieldViewProps> { addDocument(doc: Doc): boolean { const targetDataDoc = Doc.GetProto(this.props.Document); Doc.AddDocToList(targetDataDoc, this.props.fieldKey, doc); - const extension = Doc.fieldExtensionDoc(targetDataDoc, this.props.fieldKey); // set metadata about the field being rendered (ie, the set of documents) on an extension field for that field - extension && (extension.lastModified = new DateField(new Date(Date.now()))); + targetDataDoc[this.props.fieldKey + "-lastModified"] = new DateField(new Date(Date.now())); Doc.GetProto(doc).lastOpened = new DateField; return true; } @@ -189,23 +181,24 @@ export class CollectionView extends Touchable<FieldViewProps> { case CollectionViewType.Staff: return (<CollectionStaffView chromeCollapsed={true} key="collview" {...props} ChromeHeight={this.chromeHeight} CollectionView={this} />); case CollectionViewType.Multicolumn: return (<CollectionMulticolumnView chromeCollapsed={true} key="collview" {...props} ChromeHeight={this.chromeHeight} CollectionView={this} />); case CollectionViewType.Linear: { return (<CollectionLinearView key="collview" {...props} />); } + case CollectionViewType.Carousel: { return (<CollectionCarouselView key="collview" {...props} />); } case CollectionViewType.Stacking: { this.props.Document.singleColumn = true; return (<CollectionStackingView key="collview" {...props} />); } case CollectionViewType.Masonry: { this.props.Document.singleColumn = false; return (<CollectionStackingView key="collview" {...props} />); } case CollectionViewType.Pivot: { return (<CollectionPivotView key="collview" {...props} />); } case CollectionViewType.Freeform: - default: { this.props.Document.freeformLayoutEngine = undefined; return (<CollectionFreeFormView key="collview" {...props} />); } + default: { this.props.Document._freeformLayoutEngine = undefined; return (<CollectionFreeFormView key="collview" {...props} />); } } } @action private collapse = (value: boolean) => { this._collapsed = value; - this.props.Document.chromeStatus = value ? "collapsed" : "enabled"; + this.props.Document._chromeStatus = value ? "collapsed" : "enabled"; } private SubView = (type: CollectionViewType, renderProps: CollectionRenderProps) => { // currently cant think of a reason for collection docking view to have a chrome. mind may change if we ever have nested docking views -syip - const chrome = this.props.Document.chromeStatus === "disabled" || type === CollectionViewType.Docking ? (null) : + const chrome = this.props.Document._chromeStatus === "disabled" || type === CollectionViewType.Docking ? (null) : <CollectionViewBaseChrome CollectionView={this} key="chrome" type={type} collapse={this.collapse} />; return [chrome, this.SubViewHelper(type, renderProps)]; } @@ -215,24 +208,25 @@ export class CollectionView extends Touchable<FieldViewProps> { if (!e.isPropagationStopped() && this.props.Document[Id] !== CurrentUserUtils.MainDocId) { // need to test this because GoldenLayout causes a parallel hierarchy in the React DOM for its children and the main document view7 const existingVm = ContextMenu.Instance.findByDescription("View Modes..."); const subItems = existingVm && "subitems" in existingVm ? existingVm.subitems : []; - subItems.push({ description: "Freeform", event: () => { this.props.Document.viewType = CollectionViewType.Freeform; }, icon: "signature" }); + subItems.push({ description: "Freeform", event: () => { this.props.Document._viewType = CollectionViewType.Freeform; }, icon: "signature" }); if (CollectionView._safeMode) { - ContextMenu.Instance.addItem({ description: "Test Freeform", event: () => this.props.Document.viewType = CollectionViewType.Invalid, icon: "project-diagram" }); + ContextMenu.Instance.addItem({ description: "Test Freeform", event: () => this.props.Document._viewType = CollectionViewType.Invalid, icon: "project-diagram" }); } - subItems.push({ description: "Schema", event: () => this.props.Document.viewType = CollectionViewType.Schema, icon: "th-list" }); - subItems.push({ description: "Treeview", event: () => this.props.Document.viewType = CollectionViewType.Tree, icon: "tree" }); - subItems.push({ description: "Stacking", event: () => this.props.Document.viewType = CollectionViewType.Stacking, icon: "ellipsis-v" }); + subItems.push({ description: "Schema", event: () => this.props.Document._viewType = CollectionViewType.Schema, icon: "th-list" }); + subItems.push({ description: "Treeview", event: () => this.props.Document._viewType = CollectionViewType.Tree, icon: "tree" }); + subItems.push({ description: "Stacking", event: () => this.props.Document._viewType = CollectionViewType.Stacking, icon: "ellipsis-v" }); subItems.push({ description: "Stacking (AutoHeight)", event: () => { - this.props.Document.viewType = CollectionViewType.Stacking; - this.props.Document.autoHeight = true; + this.props.Document._viewType = CollectionViewType.Stacking; + this.props.Document._autoHeight = true; }, icon: "ellipsis-v" }); - subItems.push({ description: "Staff", event: () => this.props.Document.viewType = CollectionViewType.Staff, icon: "music" }); - subItems.push({ description: "Multicolumn", event: () => this.props.Document.viewType = CollectionViewType.Multicolumn, icon: "columns" }); - subItems.push({ description: "Masonry", event: () => this.props.Document.viewType = CollectionViewType.Masonry, icon: "columns" }); - subItems.push({ description: "Pivot", event: () => this.props.Document.viewType = CollectionViewType.Pivot, icon: "columns" }); - switch (this.props.Document.viewType) { + subItems.push({ description: "Staff", event: () => this.props.Document._viewType = CollectionViewType.Staff, icon: "music" }); + subItems.push({ description: "Multicolumn", event: () => this.props.Document._viewType = CollectionViewType.Multicolumn, icon: "columns" }); + subItems.push({ description: "Masonry", event: () => this.props.Document._viewType = CollectionViewType.Masonry, icon: "columns" }); + subItems.push({ description: "Carousel", event: () => this.props.Document._viewType = CollectionViewType.Carousel, icon: "columns" }); + subItems.push({ description: "Pivot", event: () => this.props.Document._viewType = CollectionViewType.Pivot, icon: "columns" }); + switch (this.props.Document._viewType) { case CollectionViewType.Freeform: { subItems.push({ description: "Custom", icon: "fingerprint", event: AddCustomFreeFormLayout(this.props.Document, this.props.fieldKey) }); break; @@ -244,6 +238,12 @@ export class CollectionView extends Touchable<FieldViewProps> { const existing = ContextMenu.Instance.findByDescription("Layout..."); const layoutItems = existing && "subitems" in existing ? existing.subitems : []; layoutItems.push({ description: `${this.props.Document.forceActive ? "Select" : "Force"} Contents Active`, event: () => this.props.Document.forceActive = !this.props.Document.forceActive, icon: "project-diagram" }); + if (this.props.Document.childLayout instanceof Doc) { + layoutItems.push({ description: "View Child Layout", event: () => this.props.addDocTab(this.props.Document.childLayout as Doc, undefined, "onRight"), icon: "project-diagram" }); + } + if (this.props.Document.childDetailed instanceof Doc) { + layoutItems.push({ description: "View Child Detailed Layout", event: () => this.props.addDocTab(this.props.Document.childDetailed as Doc, undefined, "onRight"), icon: "project-diagram" }); + } !existing && ContextMenu.Instance.addItem({ description: "Layout...", subitems: layoutItems, icon: "hand-point-right" }); const more = ContextMenu.Instance.findByDescription("More..."); diff --git a/src/client/views/collections/CollectionViewChromes.scss b/src/client/views/collections/CollectionViewChromes.scss index 64411b5fe..517f467b7 100644 --- a/src/client/views/collections/CollectionViewChromes.scss +++ b/src/client/views/collections/CollectionViewChromes.scss @@ -9,8 +9,7 @@ background: lightgrey; .collectionViewChrome { - display: grid; - grid-template-columns: 1fr auto; + display: flex; padding-bottom: 10px; border-bottom: .5px solid rgb(180, 180, 180); overflow: hidden; @@ -20,7 +19,7 @@ .collectionViewBaseChrome-viewPicker { font-size: 75%; - text-transform: uppercase; + //text-transform: uppercase; letter-spacing: 2px; background: rgb(238, 238, 238); color: grey; @@ -34,6 +33,26 @@ outline-color: black; } + .collectionViewBaseChrome-cmdPicker { + margin-left: 3px; + margin-right: 0px; + background: rgb(238, 238, 238); + border: none; + color: grey; + } + .commandEntry-outerDiv { + pointer-events: all; + background-color: gray; + display: flex; + flex-direction: row; + .commandEntry-drop { + color:white; + width:25px; + margin-top: auto; + margin-bottom: auto; + } + } + .collectionViewBaseChrome-collapse { transition: all .5s, opacity 0.3s; position: absolute; @@ -53,6 +72,18 @@ .collectionViewBaseChrome-viewSpecs { margin-left: 10px; display: grid; + + .collectionViewBaseChrome-filterIcon { + position: relative; + display: flex; + margin: auto; + background: gray; + color: white; + width: 40px; + height: 40px; + align-items: center; + justify-content: center; + } .collectionViewBaseChrome-viewSpecsInput { padding: 12px 10px 11px 10px; @@ -240,7 +271,6 @@ .commandEntry-outerDiv { display: flex; flex-direction: column; - width: 165px; height: 40px; } .commandEntry-inputArea { diff --git a/src/client/views/collections/CollectionViewChromes.tsx b/src/client/views/collections/CollectionViewChromes.tsx index 996c7671e..073a30330 100644 --- a/src/client/views/collections/CollectionViewChromes.tsx +++ b/src/client/views/collections/CollectionViewChromes.tsx @@ -39,31 +39,39 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewChro //(!)?\(\(\(doc.(\w+) && \(doc.\w+ as \w+\).includes\(\"(\w+)\"\) _templateCommand = { - title: "set template", script: "setChildLayout(this.target, this.source && this.source.length ? this.source[0]:undefined)", params: ["target", "source"], + title: "=> item view", script: "setChildLayout(this.target, this.source?.[0])", params: ["target", "source"], initialize: emptyFunction, immediate: (draggedDocs: Doc[]) => Doc.setChildLayout(this.props.CollectionView.props.Document, draggedDocs.length ? draggedDocs[0] : undefined) }; + _narrativeCommand = { + title: "=> click item view", script: "setChildDetailedLayout(this.target, this.source?.[0])", params: ["target", "source"], + initialize: emptyFunction, + immediate: (draggedDocs: Doc[]) => Doc.setChildDetailedLayout(this.props.CollectionView.props.Document, draggedDocs.length ? draggedDocs[0] : undefined) + }; _contentCommand = { - // title: "set content", script: "getProto(this.target).data = aliasDocs(this.source.map(async p => await p));", params: ["target", "source"], // bcz: doesn't look like we can do async stuff in scripting... - title: "set content", script: "getProto(this.target).data = aliasDocs(this.source);", params: ["target", "source"], + title: "=> content", script: "getProto(this.target).data = aliasDocs(this.source);", params: ["target", "source"], initialize: emptyFunction, immediate: (draggedDocs: Doc[]) => Doc.GetProto(this.props.CollectionView.props.Document).data = new List<Doc>(draggedDocs.map((d: any) => Doc.MakeAlias(d))) }; _viewCommand = { - title: "restore view", script: "this.target.panX = this.restoredPanX; this.target.panY = this.restoredPanY; this.target.scale = this.restoredScale;", params: ["target"], - immediate: (draggedDocs: Doc[]) => { this.props.CollectionView.props.Document.panX = 0; this.props.CollectionView.props.Document.panY = 0; this.props.CollectionView.props.Document.scale = 1; }, - initialize: (button: Doc) => { button.restoredPanX = this.props.CollectionView.props.Document.panX; button.restoredPanY = this.props.CollectionView.props.Document.panY; button.restoredScale = this.props.CollectionView.props.Document.scale; } + title: "=> saved view", script: "this.target._panX = this.restoredPanX; this.target._panY = this.restoredPanY; this.target.scale = this.restoredScale;", params: ["target"], + initialize: (button: Doc) => { button.restoredPanX = this.props.CollectionView.props.Document._panX; button.restoredPanY = this.props.CollectionView.props.Document._panY; button.restoredScale = this.props.CollectionView.props.Document.scale; }, + immediate: (draggedDocs: Doc[]) => { this.props.CollectionView.props.Document._panX = 0; this.props.CollectionView.props.Document._panY = 0; this.props.CollectionView.props.Document.scale = 1; }, }; - _freeform_commands = [this._contentCommand, this._templateCommand, this._viewCommand]; + _freeform_commands = [this._contentCommand, this._templateCommand, this._narrativeCommand, this._viewCommand]; _stacking_commands = [this._contentCommand, this._templateCommand]; _masonry_commands = [this._contentCommand, this._templateCommand]; + _schema_commands = [this._templateCommand, this._narrativeCommand]; _tree_commands = []; private get _buttonizableCommands() { switch (this.props.type) { case CollectionViewType.Tree: return this._tree_commands; + case CollectionViewType.Schema: return this._schema_commands; case CollectionViewType.Stacking: return this._stacking_commands; case CollectionViewType.Masonry: return this._stacking_commands; case CollectionViewType.Freeform: return this._freeform_commands; + case CollectionViewType.Pivot: return this._freeform_commands; + case CollectionViewType.Carousel: return this._freeform_commands; } return []; } @@ -126,7 +134,7 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewChro runInAction(() => { this.addKeyRestrictions(fields); // chrome status is one of disabled, collapsed, or visible. this determines initial state from document - const chromeStatus = this.props.CollectionView.props.Document.chromeStatus; + const chromeStatus = this.props.CollectionView.props.Document._chromeStatus; if (chromeStatus) { if (chromeStatus === "disabled") { throw new Error("how did you get here, if chrome status is 'disabled' on a collection, a chrome shouldn't even be instantiated!"); @@ -143,24 +151,35 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewChro @undoBatch viewChanged = (e: React.ChangeEvent) => { //@ts-ignore - this.props.CollectionView.props.Document.viewType = parseInt(e.target.selectedOptions[0].value); + this.props.CollectionView.props.Document._viewType = parseInt(e.target.selectedOptions[0].value); + } + + commandChanged = (e: React.ChangeEvent) => { + //@ts-ignore + runInAction(() => this._currentKey = e.target.selectedOptions[0].value); } @action openViewSpecs = (e: React.SyntheticEvent) => { - this._viewSpecsOpen = true; + if (this._viewSpecsOpen) this.closeViewSpecs(); + else { + this._viewSpecsOpen = true; - //@ts-ignore - if (!e.target.classList[0].startsWith("qs")) { - this.closeDatePicker(); - } + //@ts-ignore + if (!e.target?.classList[0]?.startsWith("qs")) { + this.closeDatePicker(); + } - e.stopPropagation(); - document.removeEventListener("pointerdown", this.closeViewSpecs); - document.addEventListener("pointerdown", this.closeViewSpecs); + e.stopPropagation(); + document.removeEventListener("pointerdown", this.closeViewSpecs); + document.addEventListener("pointerdown", this.closeViewSpecs); + } } - @action closeViewSpecs = () => { this._viewSpecsOpen = false; document.removeEventListener("pointerdown", this.closeViewSpecs); }; + @action closeViewSpecs = () => { + this._viewSpecsOpen = false; + document.removeEventListener("pointerdown", this.closeViewSpecs); + }; @action openDatePicker = (e: React.PointerEvent) => { @@ -217,12 +236,7 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewChro `(${keyRestrictionScript}) ${dateRestrictionScript.length ? "&&" : ""} ${dateRestrictionScript}` : "true"; - const docFilter = Cast(this.props.CollectionView.props.Document.docFilter, listSpec("string"), []); - const docFilterText = Doc.MakeDocFilter(docFilter); - const finalScript = docFilterText && !fullScript.startsWith("(())") ? `${fullScript} ${docFilterText ? "&&" : ""} (${docFilterText})` : - docFilterText ? docFilterText : fullScript; - - this.props.CollectionView.props.Document.viewSpecScript = ScriptField.MakeFunction(finalScript, { doc: Doc.name }); + this.props.CollectionView.props.Document.viewSpecScript = ScriptField.MakeFunction(fullScript, { doc: Doc.name }); } @action @@ -236,9 +250,9 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewChro @action toggleCollapse = () => { - this.props.CollectionView.props.Document.chromeStatus = this.props.CollectionView.props.Document.chromeStatus === "enabled" ? "collapsed" : "enabled"; + this.props.CollectionView.props.Document._chromeStatus = this.props.CollectionView.props.Document._chromeStatus === "enabled" ? "collapsed" : "enabled"; if (this.props.collapse) { - this.props.collapse(this.props.CollectionView.props.Document.chromeStatus !== "enabled"); + this.props.collapse(this.props.CollectionView.props.Document._chromeStatus !== "enabled"); } } @@ -266,7 +280,7 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewChro @observable private pivotKeyDisplay = this.pivotKey; getPivotInput = () => { - if (StrCast(this.document.freeformLayoutEngine) !== "pivot") { + if (StrCast(this.document._freeformLayoutEngine) !== "pivot") { return (null); } return (<input className="collectionViewBaseChrome-viewSpecsInput" @@ -377,7 +391,7 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewChro } render() { - const collapsed = this.props.CollectionView.props.Document.chromeStatus !== "enabled"; + const collapsed = this.props.CollectionView.props.Document._chromeStatus !== "enabled"; return ( <div className="collectionViewChrome-cont" style={{ top: collapsed ? -70 : 0, height: collapsed ? 0 : undefined }}> <div className="collectionViewChrome"> @@ -396,23 +410,21 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewChro className="collectionViewBaseChrome-viewPicker" onPointerDown={stopPropagation} onChange={this.viewChanged} - value={NumCast(this.props.CollectionView.props.Document.viewType)}> - <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="1">Freeform View</option> - <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="2">Schema View</option> - <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="4">Tree View</option> - <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="5">Stacking View</option> - <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="6">Masonry View</option> - <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="7">Pivot View</option> - <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="8">Linear View</option> + value={NumCast(this.props.CollectionView.props.Document._viewType)}> + <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="1">Freeform</option> + <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="2">schema</option> + <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="4">Tree</option> + <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="5">Stacking</option> + <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="6">Masonry</option> + <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="7">Multicolumn</option> + <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="8">Pivot</option> + <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="9">Carousel</option> + <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} value="10">Linear</option> </select> - <div className="collectionViewBaseChrome-viewSpecs" style={{ display: collapsed ? "none" : "grid" }}> - <input className="collectionViewBaseChrome-viewSpecsInput" - placeholder="FILTER" - value={this.filterValue ? this.filterValue.script.originalScript === "return true" ? "" : this.filterValue.script.originalScript : ""} - onChange={(e) => { }} - onPointerDown={this.openViewSpecs} - id="viewSpecsInput" /> - {this.getPivotInput()} + <div className="collectionViewBaseChrome-viewSpecs" title="filter documents to show" style={{ display: collapsed ? "none" : "grid" }}> + <div className="collectionViewBaseChrome-filterIcon" onPointerDown={this.openViewSpecs} > + <FontAwesomeIcon icon="filter" size="2x" /> + </div> <div className="collectionViewBaseChrome-viewSpecsMenu" onPointerDown={this.openViewSpecs} style={{ @@ -453,17 +465,20 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewChro </div> </div> <div className="collectionViewBaseChrome-template" ref={this.createDropTarget} > - <div className="commandEntry-outerDiv" ref={this._commandRef} onPointerDown={this.dragCommandDown}> - <div className="commandEntry-inputArea" onPointerDown={this.autoSuggestDown} > - <Autosuggest inputProps={{ value: this._currentKey, onChange: this.onKeyChange }} - getSuggestionValue={this.getSuggestionValue} - suggestions={this.suggestions} - alwaysRenderSuggestions={true} - renderSuggestion={this.renderSuggestion} - onSuggestionsFetchRequested={this.onSuggestionFetch} - onSuggestionsClearRequested={this.onSuggestionClear} - ref={this._autosuggestRef} /> + <div className="commandEntry-outerDiv" title="drop document to apply or drag to create button" ref={this._commandRef} onPointerDown={this.dragCommandDown}> + <div className="commandEntry-drop"> + <FontAwesomeIcon icon="bullseye" size="2x"></FontAwesomeIcon> </div> + <select + className="collectionViewBaseChrome-cmdPicker" + onPointerDown={stopPropagation} + onChange={this.commandChanged} + value={this._currentKey}> + <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} key={"empty"} value={""}>{""}</option> + {this._buttonizableCommands.map(cmd => + <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} key={cmd.title} value={cmd.title}>{cmd.title}</option> + )} + </select> </div> </div> </div> @@ -604,15 +619,6 @@ export class CollectionSchemaViewChrome extends React.Component<CollectionViewCh return ( <div className="collectionSchemaViewChrome-cont"> <div className="collectionSchemaViewChrome-toggle"> - <div className="collectionSchemaViewChrome-label">Wrap Text: </div> - <div className="collectionSchemaViewChrome-toggler" onClick={this.toggleTextwrap}> - <div className={"collectionSchemaViewChrome-togglerButton" + (textWrapped ? " on" : " off")}> - {textWrapped ? "on" : "off"} - </div> - </div> - </div> - - <div className="collectionSchemaViewChrome-toggle"> <div className="collectionSchemaViewChrome-label">Show Preview: </div> <div className="collectionSchemaViewChrome-toggler" onClick={this.togglePreview}> <div className={"collectionSchemaViewChrome-togglerButton" + (previewWidth !== 0 ? " on" : " off")}> diff --git a/src/client/views/collections/ParentDocumentSelector.scss b/src/client/views/collections/ParentDocumentSelector.scss index d293bb5ca..a266861bd 100644 --- a/src/client/views/collections/ParentDocumentSelector.scss +++ b/src/client/views/collections/ParentDocumentSelector.scss @@ -35,8 +35,6 @@ pointer-events: all; position: relative; display: inline-block; - padding-left: 5px; - padding-right: 5px; } .parentDocumentSelector-metadata { pointer-events: auto; diff --git a/src/client/views/collections/ParentDocumentSelector.tsx b/src/client/views/collections/ParentDocumentSelector.tsx index 24aa6ddfa..115f8d633 100644 --- a/src/client/views/collections/ParentDocumentSelector.tsx +++ b/src/client/views/collections/ParentDocumentSelector.tsx @@ -6,7 +6,7 @@ import { observable, action, runInAction } from "mobx"; import { Id } from "../../../new_fields/FieldSymbols"; import { SearchUtil } from "../../util/SearchUtil"; import { CollectionDockingView } from "./CollectionDockingView"; -import { NumCast } from "../../../new_fields/Types"; +import { NumCast, StrCast } from "../../../new_fields/Types"; import { CollectionViewType } from "./CollectionView"; import { DocumentButtonBar } from "../DocumentButtonBar"; import { DocumentManager } from "../../util/DocumentManager"; @@ -21,7 +21,13 @@ export const Flyout = higflyout.default; library.add(faEdit); -type SelectorProps = { Document: Doc, Views: DocumentView[], Stack?: any, addDocTab(doc: Doc, dataDoc: Doc | undefined, location: string): void }; +type SelectorProps = { + Document: Doc, + Views: DocumentView[], + Stack?: any, + addDocTab(doc: Doc, dataDoc: Doc | undefined, location: string): void +}; + @observer export class SelectorContextMenu extends React.Component<SelectorProps> { @observable private _docs: { col: Doc, target: Doc }[] = []; @@ -49,31 +55,22 @@ export class SelectorContextMenu extends React.Component<SelectorProps> { getOnClick({ col, target }: { col: Doc, target: Doc }) { return () => { col = Doc.IsPrototype(col) ? Doc.MakeDelegate(col) : col; - if (NumCast(col.viewType, CollectionViewType.Invalid) === CollectionViewType.Freeform) { - const newPanX = NumCast(target.x) + NumCast(target.width) / 2; - const newPanY = NumCast(target.y) + NumCast(target.height) / 2; - col.panX = newPanX; - col.panY = newPanY; + if (NumCast(col._viewType, CollectionViewType.Invalid) === CollectionViewType.Freeform) { + const newPanX = NumCast(target.x) + NumCast(target._width) / 2; + const newPanY = NumCast(target.y) + NumCast(target._height) / 2; + col._panX = newPanX; + col._panY = newPanY; } this.props.addDocTab(col, undefined, "inTab"); // bcz: dataDoc? }; } - get metadataMenu() { - return <div className="parentDocumentSelector-metadata"> - <Flyout anchorPoint={anchorPoints.TOP_LEFT} - content={<MetadataEntryMenu docs={() => this.props.Views.map(dv => dv.props.Document)} suggestWithFunction />}>{/* tfs: @bcz This might need to be the data document? */} - <div className="docDecs-tagButton" title="Add fields"><FontAwesomeIcon className="documentdecorations-icon" icon="tag" size="sm" /></div> - </Flyout> - </div>; - } render() { return <div > - <div key="metadata">Metadata: {this.metadataMenu}</div> <p key="contexts">Contexts:</p> - {this._docs.map(doc => <p key={doc.col[Id] + doc.target[Id]}><a onClick={this.getOnClick(doc)}>{doc.col.title}</a></p>)} + {this._docs.map(doc => <p key={doc.col[Id] + doc.target[Id]}><a onClick={this.getOnClick(doc)}>{doc.col.title?.toString()}</a></p>)} {this._otherDocs.length ? <hr key="hr" /> : null} - {this._otherDocs.map(doc => <p key="p"><a onClick={this.getOnClick(doc)}>{doc.col.title}</a></p>)} + {this._otherDocs.map(doc => <p key={"p" + doc.col[Id] + doc.target[Id]}><a onClick={this.getOnClick(doc)}>{doc.col.title?.toString()}</a></p>)} </div>; } } diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLayoutEngines.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLayoutEngines.tsx index 8c8da63cc..be1317b25 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLayoutEngines.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLayoutEngines.tsx @@ -7,8 +7,9 @@ import { OverlayView, OverlayElementOptions } from "../../OverlayView"; import { emptyFunction } from "../../../../Utils"; import React = require("react"); import { ObservableMap, runInAction } from "mobx"; -import { Id } from "../../../../new_fields/FieldSymbols"; -import { DateField } from "../../../../new_fields/DateField"; +import { Id, ToString } from "../../../../new_fields/FieldSymbols"; +import { ObjectField } from "../../../../new_fields/ObjectField"; +import { RefField } from "../../../../new_fields/RefField"; interface PivotData { type: string; @@ -35,11 +36,8 @@ export interface ViewDefResult { } function toLabel(target: FieldResult<Field>) { - if (target instanceof DateField) { - const date = DateCast(target).date; - if (date) { - return `${date.toDateString()} ${date.toTimeString()}`; - } + if (target instanceof ObjectField || target instanceof RefField) { + return target[ToString](); } return String(target); } @@ -48,8 +46,9 @@ export function computePivotLayout(poolData: ObservableMap<string, any>, pivotDo const pivotAxisWidth = NumCast(pivotDoc.pivotWidth, 200); const pivotColumnGroups = new Map<FieldResult<Field>, Doc[]>(); + const pivotFieldKey = toLabel(pivotDoc.pivotField); for (const doc of childDocs) { - const val = doc[StrCast(pivotDoc.pivotField, "title")]; + const val = Field.toString(doc[pivotFieldKey] as Field); if (val) { !pivotColumnGroups.get(val) && pivotColumnGroups.set(val, []); pivotColumnGroups.get(val)!.push(doc); @@ -60,11 +59,7 @@ export function computePivotLayout(poolData: ObservableMap<string, any>, pivotDo let numCols = NumCast(pivotDoc.pivotNumColumns, Math.ceil(Math.sqrt(minSize))); const docMap = new Map<Doc, ViewDefBounds>(); const groupNames: PivotData[] = []; - if (panelDim[0] < 2500) numCols = Math.min(5, numCols); - if (panelDim[0] < 2000) numCols = Math.min(4, numCols); - if (panelDim[0] < 1400) numCols = Math.min(3, numCols); - if (panelDim[0] < 1000) numCols = Math.min(2, numCols); - if (panelDim[0] < 600) numCols = 1; + numCols = Math.min(panelDim[0] / pivotAxisWidth, numCols); const expander = 1.05; const gap = .15; @@ -84,10 +79,10 @@ export function computePivotLayout(poolData: ObservableMap<string, any>, pivotDo for (const doc of val) { const layoutDoc = Doc.Layout(doc); let wid = pivotAxisWidth; - let hgt = layoutDoc.nativeWidth ? (NumCast(layoutDoc.nativeHeight) / NumCast(layoutDoc.nativeWidth)) * pivotAxisWidth : pivotAxisWidth; + let hgt = layoutDoc._nativeWidth ? (NumCast(layoutDoc._nativeHeight) / NumCast(layoutDoc._nativeWidth)) * pivotAxisWidth : pivotAxisWidth; if (hgt > pivotAxisWidth) { hgt = pivotAxisWidth; - wid = layoutDoc.nativeHeight ? (NumCast(layoutDoc.nativeWidth) / NumCast(layoutDoc.nativeHeight)) * pivotAxisWidth : pivotAxisWidth; + wid = layoutDoc._nativeHeight ? (NumCast(layoutDoc._nativeWidth) / NumCast(layoutDoc._nativeHeight)) * pivotAxisWidth : pivotAxisWidth; } docMap.set(doc, { x: x + xCount * pivotAxisWidth * expander + (pivotAxisWidth - wid) / 2 + (val.length < numCols ? (numCols - val.length) * pivotAxisWidth / 2 : 0), @@ -109,8 +104,8 @@ export function computePivotLayout(poolData: ObservableMap<string, any>, pivotDo x: NumCast(pair.layout.x), y: NumCast(pair.layout.y), z: NumCast(pair.layout.z), - width: NumCast(pair.layout.width), - height: NumCast(pair.layout.height) + width: NumCast(pair.layout._width), + height: NumCast(pair.layout._height) }; const pos = docMap.get(pair.layout) || defaultPosition; const data = poolData.get(pair.layout[Id]); diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index 132bf9c8e..41ef8c2a6 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -3,7 +3,7 @@ import { faEye } from "@fortawesome/free-regular-svg-icons"; import { faBraille, faChalkboard, faCompass, faCompressArrowsAlt, faExpandArrowsAlt, faFileUpload, faPaintBrush, faTable, faUpload } from "@fortawesome/free-solid-svg-icons"; import { action, computed, observable, ObservableMap, reaction, runInAction, IReactionDisposer } from "mobx"; import { observer } from "mobx-react"; -import { Doc, DocListCast, HeightSym, Opt, WidthSym, DocListCastAsync } from "../../../../new_fields/Doc"; +import { Doc, DocListCast, HeightSym, Opt, WidthSym, DocListCastAsync, Field } from "../../../../new_fields/Doc"; import { documentSchema, positionSchema } from "../../../../new_fields/documentSchemas"; import { Id } from "../../../../new_fields/FieldSymbols"; import { InkTool, InkField, InkData } from "../../../../new_fields/InkField"; @@ -41,20 +41,17 @@ import React = require("react"); import { computedFn } from "mobx-utils"; import { TraceMobx } from "../../../../new_fields/util"; import { GestureUtils } from "../../../../pen-gestures/GestureUtils"; -import { LinkManager } from "../../../util/LinkManager"; import { CognitiveServices } from "../../../cognitive_services/CognitiveServices"; -import CollectionPaletteVIew from "../../Palette"; library.add(faEye as any, faTable, faPaintBrush, faExpandArrowsAlt, faCompressArrowsAlt, faCompass, faUpload, faBraille, faChalkboard, faFileUpload); export const panZoomSchema = createSchema({ - panX: "number", - panY: "number", + _panX: "number", + _panY: "number", scale: "number", arrangeScript: ScriptField, arrangeInit: ScriptField, useClusters: "boolean", - isRuleProvider: "boolean", fitToBox: "boolean", xPadding: "number", // pixels of padding on left/right of collectionfreeformview contents when fitToBox is set yPadding: "number", // pixels of padding on left/right of collectionfreeformview contents when fitToBox is set @@ -78,20 +75,20 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { private _layoutComputeReaction: IReactionDisposer | undefined; private _layoutPoolData = new ObservableMap<string, any>(); - public get displayName() { return "CollectionFreeFormView(" + this.props.Document.title + ")"; } // this makes mobx trace() statements more descriptive + public get displayName() { return "CollectionFreeFormView(" + this.props.Document.title?.toString() + ")"; } // this makes mobx trace() statements more descriptive @observable.shallow _layoutElements: ViewDefResult[] = []; // shallow because some layout items (eg pivot labels) are just generated 'divs' and can't be frozen as observables @observable _clusterSets: (Doc[])[] = []; - @computed get fitToContent() { return (this.props.fitToBox || this.Document.fitToBox) && !this.isAnnotationOverlay; } + @computed get fitToContent() { return (this.props.fitToBox || this.Document._fitToBox) && !this.isAnnotationOverlay; } @computed get parentScaling() { return this.props.ContentScaling && this.fitToContent && !this.isAnnotationOverlay ? this.props.ContentScaling() : 1; } @computed get contentBounds() { return aggregateBounds(this._layoutElements.filter(e => e.bounds && !e.bounds.z).map(e => e.bounds!), NumCast(this.layoutDoc.xPadding, 10), NumCast(this.layoutDoc.yPadding, 10)); } - @computed get nativeWidth() { return this.Document.fitToContent ? 0 : this.Document.nativeWidth || 0; } - @computed get nativeHeight() { return this.fitToContent ? 0 : this.Document.nativeHeight || 0; } + @computed get nativeWidth() { return this.Document._fitToContent ? 0 : NumCast(this.Document._nativeWidth); } + @computed get nativeHeight() { return this.fitToContent ? 0 : NumCast(this.Document._nativeHeight); } private get isAnnotationOverlay() { return this.props.isAnnotationOverlay; } private get borderWidth() { return this.isAnnotationOverlay ? 0 : COLLECTION_BORDER_WIDTH; } private easing = () => this.props.Document.panTransformType === "Ease"; - private panX = () => this.fitToContent ? (this.contentBounds.x + this.contentBounds.r) / 2 : this.Document.panX || 0; - private panY = () => this.fitToContent ? (this.contentBounds.y + this.contentBounds.b) / 2 : this.Document.panY || 0; + private panX = () => this.fitToContent ? (this.contentBounds.x + this.contentBounds.r) / 2 : this.Document._panX || 0; + private panY = () => this.fitToContent ? (this.contentBounds.y + this.contentBounds.b) / 2 : this.Document._panY || 0; private zoomScaling = () => (1 / this.parentScaling) * (this.fitToContent ? Math.min(this.props.PanelHeight() / (this.contentBounds.b - this.contentBounds.y), this.props.PanelWidth() / (this.contentBounds.r - this.contentBounds.x)) : this.Document.scale || 1) @@ -103,14 +100,6 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { private getLocalTransform = (): Transform => Transform.Identity().scale(1 / this.zoomScaling()).translate(this.panX(), this.panY()); private addLiveTextBox = (newBox: Doc) => { FormattedTextBox.SelectOnLoad = newBox[Id];// track the new text box so we can give it a prop that tells it to focus itself when it's displayed - const maxHeading = this.childDocs.reduce((maxHeading, doc) => NumCast(doc.heading) > maxHeading ? NumCast(doc.heading) : maxHeading, 0); - let heading = maxHeading === 0 || this.childDocs.length === 0 ? 1 : maxHeading === 1 ? 2 : 0; - if (heading === 0) { - const sorted = this.childDocs.filter(d => d.type === DocumentType.TEXT && d.data_ext instanceof Doc && d.data_ext.lastModified).sort((a, b) => DateCast((Cast(a.data_ext, Doc) as Doc).lastModified).date > DateCast((Cast(b.data_ext, Doc) as Doc).lastModified).date ? 1 : - DateCast((Cast(a.data_ext, Doc) as Doc).lastModified).date < DateCast((Cast(b.data_ext, Doc) as Doc).lastModified).date ? -1 : 0); - heading = !sorted.length ? Math.max(1, maxHeading) : NumCast(sorted[sorted.length - 1].heading) === 1 ? 2 : NumCast(sorted[sorted.length - 1].heading); - } - !this.Document.isRuleProvider && (newBox.heading = heading); this.addDocument(newBox); } private addDocument = (newBox: Doc) => { @@ -155,18 +144,18 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { const layoutDoc = Doc.Layout(d); d.x = x + NumCast(d.x) - dropX; d.y = y + NumCast(d.y) - dropY; - if (!NumCast(layoutDoc.width)) { - layoutDoc.width = 300; + if (!NumCast(layoutDoc._width)) { + layoutDoc._width = 300; } - if (!NumCast(layoutDoc.height)) { - const nw = NumCast(layoutDoc.nativeWidth); - const nh = NumCast(layoutDoc.nativeHeight); - layoutDoc.height = nw && nh ? nh / nw * NumCast(layoutDoc.width) : 300; + if (!NumCast(layoutDoc._height)) { + const nw = NumCast(layoutDoc._nativeWidth); + const nh = NumCast(layoutDoc._nativeHeight); + layoutDoc._height = nw && nh ? nh / nw * NumCast(layoutDoc._width) : 300; } this.bringToFront(d); })); - de.complete.docDragData.droppedDocuments.length === 1 && this.updateCluster(de.complete.docDragData.droppedDocuments[0]); + (de.complete.docDragData.droppedDocuments.length === 1 || de.shiftKey) && this.updateClusterDocs(de.complete.docDragData.droppedDocuments); } } else if (de.complete.annoDragData) { @@ -191,8 +180,8 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { const layoutDoc = Doc.Layout(cd); const cx = NumCast(cd.x) - this._clusterDistance; const cy = NumCast(cd.y) - this._clusterDistance; - const cw = NumCast(layoutDoc.width) + 2 * this._clusterDistance; - const ch = NumCast(layoutDoc.height) + 2 * this._clusterDistance; + const cw = NumCast(layoutDoc._width) + 2 * this._clusterDistance; + const ch = NumCast(layoutDoc._height) + 2 * this._clusterDistance; return !layoutDoc.z && intersectRect({ left: cx, top: cy, width: cw, height: ch }, { left: probe[0], top: probe[1], width: 1, height: 1 }) ? NumCast(cd.cluster) : cluster; }, -1); @@ -224,6 +213,41 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { this.childLayoutPairs.map(pair => pair.layout).map(c => this.updateCluster(c)); } + @action + updateClusterDocs(docs: Doc[]) { + const childLayouts = this.childLayoutPairs.map(pair => pair.layout); + if (this.props.Document.useClusters) { + const docFirst = docs[0]; + docs.map(doc => this._clusterSets.map(set => Doc.IndexOf(doc, set) !== -1 && set.splice(Doc.IndexOf(doc, set), 1))); + const preferredInd = NumCast(docFirst.cluster); + docs.map(doc => doc.cluster = -1); + docs.map(doc => this._clusterSets.map((set, i) => set.map(member => { + if (docFirst.cluster === -1 && Doc.IndexOf(member, childLayouts) !== -1 && Doc.overlapping(doc, member, this._clusterDistance)) { + docFirst.cluster = i; + } + }))); + if (docFirst.cluster === -1 && preferredInd !== -1 && (!this._clusterSets[preferredInd] || !this._clusterSets[preferredInd].filter(member => Doc.IndexOf(member, childLayouts) !== -1).length)) { + docFirst.cluster = preferredInd; + } + this._clusterSets.map((set, i) => { + if (docFirst.cluster === -1 && !set.filter(member => Doc.IndexOf(member, childLayouts) !== -1).length) { + docFirst.cluster = i; + } + }); + if (docFirst.cluster === -1) { + docs.map(doc => { + doc.cluster = this._clusterSets.length; + this._clusterSets.push([doc]); + }); + } else { + for (let i = this._clusterSets.length; i <= NumCast(docFirst.cluster); i++) !this._clusterSets[i] && this._clusterSets.push([]); + docs.map(doc => this._clusterSets[doc.cluster = NumCast(docFirst.cluster)].push(doc)); + } + childLayouts.map(child => !this._clusterSets.some((set, i) => Doc.IndexOf(child, set) !== -1 && child.cluster === i) && this.updateCluster(child)); + childLayouts.map(child => Doc.GetProto(child).clusterStr = child.cluster?.toString()); + } + } + @undoBatch @action updateCluster(doc: Doc) { @@ -281,7 +305,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { return; } this._hitCluster = this.props.Document.useClusters ? this.pickCluster(this.getTransform().transformPoint(e.clientX, e.clientY)) !== -1 : false; - if (e.button === 0 && !e.shiftKey && !e.altKey && !e.ctrlKey && this.props.active(true)) { + if (e.button === 0 && (!e.shiftKey || this._hitCluster) && !e.altKey && !e.ctrlKey && this.props.active(true)) { document.removeEventListener("pointermove", this.onPointerMove); document.removeEventListener("pointerup", this.onPointerUp); document.addEventListener("pointermove", this.onPointerMove); @@ -363,7 +387,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { case GestureUtils.Gestures.Stroke: const points = ge.points; const B = this.getTransform().transformBounds(ge.bounds.left, ge.bounds.top, ge.bounds.width, ge.bounds.height); - const inkDoc = Docs.Create.InkDocument(InkingControl.Instance.selectedColor, InkingControl.Instance.selectedTool, parseInt(InkingControl.Instance.selectedWidth), points, { title: "ink stroke", x: B.x, y: B.y, width: B.width, height: B.height }); + const inkDoc = Docs.Create.InkDocument(InkingControl.Instance.selectedColor, InkingControl.Instance.selectedTool, parseInt(InkingControl.Instance.selectedWidth), points, { title: "ink stroke", x: B.x, y: B.y, _width: B.width, _height: B.height }); this.addDocument(inkDoc); e.stopPropagation(); break; @@ -385,7 +409,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { } return pass; }); - this.addDocument(Docs.Create.FreeformDocument(sel, { title: "nested collection", x: bounds.x, y: bounds.y, width: bWidth, height: bHeight, panX: 0, panY: 0 })); + this.addDocument(Docs.Create.FreeformDocument(sel, { title: "nested collection", x: bounds.x, y: bounds.y, _width: bWidth, _height: bHeight, _panX: 0, _panY: 0 })); sel.forEach(d => this.props.removeDocument(d)); break; @@ -407,22 +431,21 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { // I think it makes sense for the marquee menu to go away when panned. -syip2 MarqueeOptionsMenu.Instance.fadeOut(true); - let x = this.Document.panX || 0; - let y = this.Document.panY || 0; - const docs = this.childLayoutPairs.map(pair => pair.layout); + let x = this.Document._panX || 0; + let y = this.Document._panY || 0; + const docs = this.childLayoutPairs.filter(pair => pair.layout instanceof Doc && !pair.layout.isMinimized).map(pair => pair.layout); const [dx, dy] = this.getTransform().transformDirection(e.clientX - this._lastX, e.clientY - this._lastY); - if (!this.isAnnotationOverlay) { + if (!this.isAnnotationOverlay && docs.length) { PDFMenu.Instance.fadeOut(true); - const minx = docs.length ? NumCast(docs[0].x) : 0; - const maxx = docs.length ? NumCast(docs[0].width) + minx : minx; - const miny = docs.length ? NumCast(docs[0].y) : 0; - const maxy = docs.length ? NumCast(docs[0].height) + miny : miny; + const minx = this.childDataProvider(docs[0]).x;//docs.length ? NumCast(docs[0].x) : 0; + const miny = this.childDataProvider(docs[0]).y;//docs.length ? NumCast(docs[0].y) : 0; + const maxx = this.childDataProvider(docs[0]).width + minx;//docs.length ? NumCast(docs[0].width) + minx : minx; + const maxy = this.childDataProvider(docs[0]).height + miny;//docs.length ? NumCast(docs[0].height) + miny : miny; const ranges = docs.filter(doc => doc).reduce((range, doc) => { - const layoutDoc = Doc.Layout(doc); - const x = NumCast(doc.x); - const xe = x + NumCast(layoutDoc.width); - const y = NumCast(doc.y); - const ye = y + NumCast(layoutDoc.height); + const x = this.childDataProvider(doc).x;//NumCast(doc.x); + const y = this.childDataProvider(doc).y;//NumCast(doc.y); + const xe = this.childDataProvider(doc).width + x;//x + NumCast(layoutDoc.width); + const ye = this.childDataProvider(doc).height + y; //y + NumCast(layoutDoc.height); return [[range[0][0] > x ? x : range[0][0], range[0][1] < xe ? xe : range[0][1]], [range[1][0] > y ? y : range[1][0], range[1][1] < ye ? ye : range[1][1]]]; }, [[minx, maxx], [miny, maxy]]); @@ -601,8 +624,8 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { const scale = this.getLocalTransform().inverse().Scale; const newPanX = Math.min((1 - 1 / scale) * this.nativeWidth, Math.max(0, panX)); const newPanY = Math.min((this.props.Document.scrollHeight !== undefined ? NumCast(this.Document.scrollHeight) : (1 - 1 / scale) * this.nativeHeight), Math.max(0, panY)); - this.Document.panX = this.isAnnotationOverlay ? newPanX : panX; - this.Document.panY = this.isAnnotationOverlay ? newPanY : panY; + this.Document._panX = this.isAnnotationOverlay ? newPanX : panX; + this.Document._panY = this.isAnnotationOverlay ? newPanY : panY; } } @@ -626,14 +649,14 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { // TODO This technically isn't correct if type !== "doc", as // currently nothing is done, but we should probably push a new state - if (state.type === "doc" && this.Document.panX !== undefined && this.Document.panY !== undefined) { + if (state.type === "doc" && this.Document._panX !== undefined && this.Document._panY !== undefined) { const init = state.initializers![this.Document[Id]]; if (!init) { - state.initializers![this.Document[Id]] = { panX: this.Document.panX, panY: this.Document.panY }; + state.initializers![this.Document[Id]] = { panX: this.Document._panX, panY: this.Document._panY }; HistoryUtil.pushState(state); - } else if (init.panX !== this.Document.panX || init.panY !== this.Document.panY) { - init.panX = this.Document.panX; - init.panY = this.Document.panY; + } else if (init.panX !== this.Document._panX || init.panY !== this.Document._panY) { + init.panX = this.Document._panX; + init.panY = this.Document._panY; HistoryUtil.pushState(state); } } @@ -649,13 +672,13 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { } } else { const layoutdoc = Doc.Layout(doc); - const newPanX = NumCast(doc.x) + NumCast(layoutdoc.width) / 2; - const newPanY = NumCast(doc.y) + NumCast(layoutdoc.height) / 2; + const newPanX = NumCast(doc.x) + NumCast(layoutdoc._width) / 2; + const newPanY = NumCast(doc.y) + NumCast(layoutdoc._height) / 2; const newState = HistoryUtil.getState(); newState.initializers![this.Document[Id]] = { panX: newPanX, panY: newPanY }; HistoryUtil.pushState(newState); - const savedState = { px: this.Document.panX, py: this.Document.panY, s: this.Document.scale, pt: this.Document.panTransformType }; + const savedState = { px: this.Document._panX, py: this.Document._panY, s: this.Document.scale, pt: this.Document.panTransformType }; if (!doc.z) this.setPan(newPanX, newPanY, "Ease"); // docs that are floating in their collection can't be panned to from their collection -- need to propagate the pan to a parent freeform somehow Doc.BrushDoc(this.props.Document); @@ -665,8 +688,8 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { afterFocus && setTimeout(() => { if (afterFocus && afterFocus()) { - this.Document.panX = savedState.px; - this.Document.panY = savedState.py; + this.Document._panX = savedState.px; + this.Document._panY = savedState.py; this.Document.scale = savedState.s; this.Document.panTransformType = savedState.pt; } @@ -676,7 +699,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { } setScaleToZoom = (doc: Doc, scale: number = 0.5) => { - this.Document.scale = scale * Math.min(this.props.PanelWidth() / NumCast(doc.width), this.props.PanelHeight() / NumCast(doc.height)); + this.Document.scale = scale * Math.min(this.props.PanelWidth() / NumCast(doc._width), this.props.PanelHeight() / NumCast(doc._height)); } zoomToScale = (scale: number) => { @@ -695,7 +718,6 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { Document: childLayout, LibraryPath: this.libraryPath, layoutKey: undefined, - ruleProvider: this.Document.isRuleProvider && childLayout.type !== DocumentType.TEXT ? this.props.Document : this.props.ruleProvider, //bcz: hack! - currently ruleProviders apply to documents in nested colleciton, not direct children of themselves //onClick: undefined, // this.props.onClick, // bcz: check this out -- I don't think we want to inherit click handlers, or we at least need a way to ignore them onClick: this.onChildClickHandler, ScreenToLocalTransform: childLayout.z ? this.getTransformOverlay : this.getTransform, @@ -720,7 +742,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { return { ...result, transition: "transform 1s" }; } const layoutDoc = Doc.Layout(params.doc); - return { x: Cast(params.doc.x, "number"), y: Cast(params.doc.y, "number"), z: Cast(params.doc.z, "number"), width: Cast(layoutDoc.width, "number"), height: Cast(layoutDoc.height, "number") }; + return { x: Cast(params.doc.x, "number"), y: Cast(params.doc.y, "number"), z: Cast(params.doc.z, "number"), width: Cast(layoutDoc._width, "number"), height: Cast(layoutDoc._height, "number") }; } viewDefsToJSX = (views: any[]) => { @@ -738,7 +760,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { const fontSize = Cast(viewDef.fontSize, "number"); return [text, x, y, width, height].some(val => val === undefined) ? undefined : { - ele: <div className="collectionFreeform-customText" style={{ width, height, fontSize, transform: `translate(${x}px, ${y}px)` }}> + ele: <div className="collectionFreeform-customText" key={(text || "") + x + y + z} style={{ width, height, fontSize, transform: `translate(${x}px, ${y}px)` }}> {text} </div>, bounds: { x: x!, y: y!, z: z, width: width!, height: height! } @@ -746,7 +768,12 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { } } - childDataProvider = computedFn(function childDataProvider(this: any, doc: Doc) { return this._layoutPoolData.get(doc[Id]); }.bind(this)); + childDataProvider = computedFn(function childDataProvider(this: any, doc: Doc) { + if (!doc) { + console.log(doc); + } + return this._layoutPoolData.get(doc[Id]); + }.bind(this)); doPivotLayout(poolData: ObservableMap<string, any>) { return computePivotLayout(poolData, this.props.Document, this.childDocs, @@ -772,7 +799,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { get doLayoutComputation() { let computedElementData: { elements: ViewDefResult[] }; - switch (this.Document.freeformLayoutEngine) { + switch (this.Document._freeformLayoutEngine) { case "pivot": computedElementData = this.doPivotLayout(this._layoutPoolData); break; default: computedElementData = this.doFreeformLayout(this._layoutPoolData); break; } @@ -780,9 +807,8 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { computedElementData.elements.push({ ele: <CollectionFreeFormDocumentView key={pair.layout[Id]} {...this.getChildDocumentViewProps(pair.layout, pair.data)} dataProvider={this.childDataProvider} - ruleProvider={this.Document.isRuleProvider ? this.props.Document : this.props.ruleProvider} jitterRotation={NumCast(this.props.Document.jitterRotation)} - fitToBox={this.props.fitToBox || this.Document.freeformLayoutEngine === "pivot"} />, + fitToBox={this.props.fitToBox || this.Document._freeformLayoutEngine === "pivot"} />, bounds: this.childDataProvider(pair.layout) })); @@ -809,12 +835,12 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { layoutDocsInGrid = () => { UndoManager.RunInBatch(() => { const docs = DocListCast(this.Document[this.props.fieldKey]); - const startX = this.Document.panX || 0; + const startX = this.Document._panX || 0; let x = startX; - let y = this.Document.panY || 0; + let y = this.Document._panY || 0; let i = 0; - const width = Math.max(...docs.map(doc => NumCast(doc.width))); - const height = Math.max(...docs.map(doc => NumCast(doc.height))); + const width = Math.max(...docs.map(doc => NumCast(doc._width))); + const height = Math.max(...docs.map(doc => NumCast(doc._height))); for (const doc of docs) { doc.x = x; doc.y = y; @@ -828,37 +854,6 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { }, "arrange contents"); } - autoFormat = () => { - this.Document.isRuleProvider = !this.Document.isRuleProvider; - // find rule colorations when rule providing is turned on by looking at each document to see if it has a coloring -- if so, use it's color as the rule for its associated heading. - this.Document.isRuleProvider && this.childLayoutPairs.map(pair => - // iterate over the children of a displayed document (or if the displayed document is a template, iterate over the children of that template) - DocListCast(Doc.Layout(pair.layout).data).map(heading => { - const headingPair = Doc.GetLayoutDataDocPair(this.props.Document, this.props.DataDoc, this.props.fieldKey, heading); - const headingLayout = headingPair.layout && (pair.layout.data_ext instanceof Doc) && (pair.layout.data_ext[`Layout[${headingPair.layout[Id]}]`] as Doc) || headingPair.layout; - if (headingLayout && NumCast(headingLayout.heading) > 0 && headingLayout.backgroundColor !== headingLayout.defaultBackgroundColor) { - Doc.GetProto(this.props.Document)["ruleColor_" + NumCast(headingLayout.heading)] = headingLayout.backgroundColor; - } - }) - ); - } - - analyzeStrokes = async () => { - const children = await DocListCastAsync(this.dataDoc.data); - if (!children) { - return; - } - const inkData: InkData[] = []; - for (const doc of children) { - const data = Cast(doc.data, InkField)?.inkData; - data && inkData.push(data); - } - if (!inkData.length) { - return; - } - CognitiveServices.Inking.Appliers.ConcatenateHandwriting(this.dataDoc, ["inkAnalysis", "handwriting"], inkData); - } - private thumbIdentifier?: number; // @action @@ -905,16 +900,12 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { onContextMenu = (e: React.MouseEvent) => { const layoutItems: ContextMenuProps[] = []; - if (this.childDocs.some(d => BoolCast(d.isTemplateDoc))) { - layoutItems.push({ description: "Template Layout Instance", event: () => this.props.addDocTab(Doc.ApplyTemplate(this.props.Document)!, undefined, "onRight"), icon: "project-diagram" }); - } - layoutItems.push({ description: "reset view", event: () => { this.props.Document.panX = this.props.Document.panY = 0; this.props.Document.scale = 1; }, icon: "compress-arrows-alt" }); - layoutItems.push({ description: `${this.Document.LODdisable ? "Enable LOD" : "Disable LOD"}`, event: () => this.Document.LODdisable = !this.Document.LODdisable, icon: "table" }); - layoutItems.push({ description: `${this.fitToContent ? "Unset" : "Set"} Fit To Container`, event: () => this.Document.fitToBox = !this.fitToContent, icon: !this.fitToContent ? "expand-arrows-alt" : "compress-arrows-alt" }); + layoutItems.push({ description: "reset view", event: () => { this.props.Document._panX = this.props.Document._panY = 0; this.props.Document.scale = 1; }, icon: "compress-arrows-alt" }); + layoutItems.push({ description: `${this.Document._LODdisable ? "Enable LOD" : "Disable LOD"}`, event: () => this.Document._LODdisable = !this.Document._LODdisable, icon: "table" }); + layoutItems.push({ description: `${this.fitToContent ? "Unset" : "Set"} Fit To Container`, event: () => this.Document._fitToBox = !this.fitToContent, icon: !this.fitToContent ? "expand-arrows-alt" : "compress-arrows-alt" }); layoutItems.push({ description: `${this.Document.useClusters ? "Uncluster" : "Use Clusters"}`, event: () => this.updateClusters(!this.Document.useClusters), icon: "braille" }); - layoutItems.push({ description: `${this.Document.isRuleProvider ? "Stop Auto Format" : "Auto Format"}`, event: this.autoFormat, icon: "chalkboard" }); layoutItems.push({ description: "Arrange contents in grid", event: this.layoutDocsInGrid, icon: "table" }); - layoutItems.push({ description: "Analyze Strokes", event: this.analyzeStrokes, icon: "paint-brush" }); + // layoutItems.push({ description: "Analyze Strokes", event: this.analyzeStrokes, icon: "paint-brush" }); layoutItems.push({ description: "Jitter Rotation", event: action(() => this.props.Document.jitterRotation = 10), icon: "paint-brush" }); layoutItems.push({ description: "Import document", icon: "upload", event: ({ x, y }) => { @@ -948,7 +939,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { description: "Add Note ...", subitems: DocListCast((CurrentUserUtils.UserDocument.noteTypes as Doc).data).map((note, i) => ({ description: (i + 1) + ": " + StrCast(note.title), - event: (args: { x: number, y: number }) => this.addLiveTextBox(Docs.Create.TextDocument({ width: 200, height: 100, x: this.getTransform().transformPoint(args.x, args.y)[0], y: this.getTransform().transformPoint(args.x, args.y)[1], autoHeight: true, layout: note, title: StrCast(note.title) })), + event: (args: { x: number, y: number }) => this.addLiveTextBox(Docs.Create.TextDocument("", { _width: 200, _height: 100, x: this.getTransform().transformPoint(args.x, args.y)[0], y: this.getTransform().transformPoint(args.x, args.y)[1], _autoHeight: true, layout: note, title: StrCast(note.title) })), icon: "eye" })) as ContextMenuProps[], icon: "eye" @@ -969,7 +960,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { children = () => { const eles: JSX.Element[] = []; - this.extensionDoc && (eles.push(...this.childViews())); + eles.push(...this.childViews()); // this._palette && (eles.push(this._palette)); // this.currentStroke && (eles.push(this.currentStroke)); eles.push(<CollectionFreeFormRemoteCursors {...this.props} key="remoteCursors" />); @@ -977,11 +968,11 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { } @computed get placeholder() { return <div className="collectionfreeformview-placeholder" style={{ background: this.Document.backgroundColor }}> - <span className="collectionfreeformview-placeholderSpan">{this.props.Document.title}</span> + <span className="collectionfreeformview-placeholderSpan">{this.props.Document.title?.toString()}</span> </div>; } @computed get marqueeView() { - return <MarqueeView {...this.props} extensionDoc={this.extensionDoc!} activeDocuments={this.getActiveDocuments} selectDocuments={this.selectDocuments} addDocument={this.addDocument} + return <MarqueeView {...this.props} activeDocuments={this.getActiveDocuments} selectDocuments={this.selectDocuments} addDocument={this.addDocument} addLiveTextDocument={this.addLiveTextBox} getContainerTransform={this.getContainerTransform} getTransform={this.getTransform} isAnnotationOverlay={this.isAnnotationOverlay}> <CollectionFreeFormViewPannableContents centeringShiftX={this.centeringShiftX} centeringShiftY={this.centeringShiftY} easing={this.easing} zoomScaling={this.zoomScaling} panX={this.panX} panY={this.panY}> @@ -990,6 +981,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { </MarqueeView>; } @computed get contentScaling() { + if (this.props.annotationsKey) return 0; const hscale = this.nativeHeight ? this.props.PanelHeight() / this.nativeHeight : 1; const wscale = this.nativeWidth ? this.props.PanelWidth() / this.nativeWidth : 1; return wscale < hscale ? wscale : hscale; @@ -1003,7 +995,6 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { // this.Document.fitH = this.contentBounds && (this.contentBounds.b - this.contentBounds.y); // if isAnnotationOverlay is set, then children will be stored in the extension document for the fieldKey. // otherwise, they are stored in fieldKey. All annotations to this document are stored in the extension document - if (!this.extensionDoc) return (null); // let lodarea = this.Document[WidthSym]() * this.Document[HeightSym]() / this.props.ScreenToLocalTransform().Scale / this.props.ScreenToLocalTransform().Scale; return <div className={"collectionfreeformview-container"} ref={this.createDashEventsTarget} @@ -1016,7 +1007,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) { width: this.contentScaling ? `${100 / this.contentScaling}%` : "", height: this.contentScaling ? `${100 / this.contentScaling}%` : this.isAnnotationOverlay ? (this.props.Document.scrollHeight ? this.Document.scrollHeight : "100%") : this.props.PanelHeight() }}> - {!this.Document.LODdisable && !this.props.active() && !this.props.isAnnotationOverlay && !this.props.annotationsKey && this.props.renderDepth > 0 ? // && this.props.CollectionView && lodarea < NumCast(this.Document.LODarea, 100000) ? + {!this.Document._LODdisable && !this.props.active() && !this.props.isAnnotationOverlay && !this.props.annotationsKey && this.props.renderDepth > 0 ? // && this.props.CollectionView && lodarea < NumCast(this.Document.LODarea, 100000) ? this.placeholder : this.marqueeView} <CollectionFreeFormOverlayView elements={this.elementFunc} /> </div>; diff --git a/src/client/views/collections/collectionFreeForm/MarqueeOptionsMenu.tsx b/src/client/views/collections/collectionFreeForm/MarqueeOptionsMenu.tsx index 32e39d25e..71f265484 100644 --- a/src/client/views/collections/collectionFreeForm/MarqueeOptionsMenu.tsx +++ b/src/client/views/collections/collectionFreeForm/MarqueeOptionsMenu.tsx @@ -25,18 +25,21 @@ export default class MarqueeOptionsMenu extends AntimodeMenu { <button className="antimodeMenu-button" title="Create a Collection" + key="group" onPointerDown={this.createCollection}> <FontAwesomeIcon icon="object-group" size="lg" /> </button>, <button className="antimodeMenu-button" title="Summarize Documents" + key="summarize" onPointerDown={this.summarize}> <FontAwesomeIcon icon="compress-arrows-alt" size="lg" /> </button>, <button className="antimodeMenu-button" title="Delete Documents" + key="delete" onPointerDown={this.delete}> <FontAwesomeIcon icon="trash-alt" size="lg" /> </button>, diff --git a/src/client/views/collections/collectionFreeForm/MarqueeView.tsx b/src/client/views/collections/collectionFreeForm/MarqueeView.tsx index 523edb918..ef2fc2ad1 100644 --- a/src/client/views/collections/collectionFreeForm/MarqueeView.tsx +++ b/src/client/views/collections/collectionFreeForm/MarqueeView.tsx @@ -29,7 +29,6 @@ interface MarqueeViewProps { removeDocument: (doc: Doc) => boolean; addLiveTextDocument: (doc: Doc) => void; isSelected: () => boolean; - extensionDoc: Doc; isAnnotationOverlay?: boolean; setPreviewCursor?: (func: (x: number, y: number, drag: boolean) => void) => void; } @@ -85,7 +84,7 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque } ns.map(line => { const indent = line.search(/\S|$/); - const newBox = Docs.Create.TextDocument({ width: 200, height: 35, x: x + indent / 3 * 10, y: y, documentText: "@@@" + line, title: line }); + const newBox = Docs.Create.TextDocument(line, { _width: 200, _height: 35, x: x + indent / 3 * 10, y: y, title: line }); this.props.addDocument(newBox); y += 40 * this.props.getTransform().Scale; }); @@ -95,17 +94,17 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque navigator.clipboard.readText().then(text => { const ns = text.split("\n").filter(t => t.trim() !== "\r" && t.trim() !== ""); if (ns.length === 1 && text.startsWith("http")) { - this.props.addDocument(Docs.Create.ImageDocument(text, { nativeWidth: 300, width: 300, x: x, y: y }));// paste an image from its URL in the paste buffer + this.props.addDocument(Docs.Create.ImageDocument(text, { _nativeWidth: 300, _width: 300, x: x, y: y }));// paste an image from its URL in the paste buffer } else { this.pasteTable(ns, x, y); } }); } else if (!e.ctrlKey) { this.props.addLiveTextDocument( - Docs.Create.TextDocument({ width: 200, height: 100, x: x, y: y, autoHeight: true, title: "-typed text-" })); + Docs.Create.TextDocument("", { _width: 200, _height: 100, x: x, y: y, _autoHeight: true, title: "-typed text-" })); } else if (e.keyCode > 48 && e.keyCode <= 57) { const notes = DocListCast((CurrentUserUtils.UserDocument.noteTypes as Doc).data); - const text = Docs.Create.TextDocument({ width: 200, height: 100, x: x, y: y, autoHeight: true, title: "-typed text-" }); + const text = Docs.Create.TextDocument("", { _width: 200, _height: 100, x: x, y: y, _autoHeight: true, title: "-typed text-" }); text.layout = notes[(e.keyCode - 49) % notes.length]; this.props.addLiveTextDocument(text); } @@ -128,7 +127,7 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque let groupAttr: string | number = ""; const rowProto = new Doc(); rowProto.title = rowProto.Id; - rowProto.width = 200; + rowProto._width = 200; rowProto.isPrototype = true; for (let i = 1; i < ns.length - 1; i++) { const values = ns[i].split("\t"); @@ -144,10 +143,10 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque } docDataProto.title = i.toString(); const doc = Doc.MakeDelegate(docDataProto); - doc.width = 200; + doc._width = 200; docList.push(doc); } - const newCol = Docs.Create.SchemaDocument([...(groupAttr ? [new SchemaHeaderField("_group", "#f1efeb")] : []), ...columns.filter(c => c).map(c => new SchemaHeaderField(c, "#f1efeb"))], docList, { x: x, y: y, title: "droppedTable", width: 300, height: 100 }); + const newCol = Docs.Create.SchemaDocument([...(groupAttr ? [new SchemaHeaderField("_group", "#f1efeb")] : []), ...columns.filter(c => c).map(c => new SchemaHeaderField(c, "#f1efeb"))], docList, { x: x, y: y, title: "droppedTable", _width: 300, _height: 100 }); this.props.addDocument(newCol); } @@ -267,15 +266,15 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque } get inkDoc() { - return this.props.extensionDoc; + return this.props.Document; } get ink() { // ink will be stored on the extension doc for the field (fieldKey) where the container's data is stored. - return this.props.extensionDoc && Cast(this.props.extensionDoc.ink, InkField); + return Cast(this.props.Document.ink, InkField); } set ink(value: InkField | undefined) { - this.props.extensionDoc && (this.props.extensionDoc.ink = value); + this.props.Document.ink = value; } @action @@ -300,7 +299,7 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque this.hideMarquee(); } - getCollection = (selected: Doc[]) => { + getCollection = (selected: Doc[], asTemplate: boolean) => { const bounds = this.Bounds; const defaultPalette = ["rgb(114,229,239)", "rgb(255,246,209)", "rgb(255,188,156)", "rgb(247,220,96)", "rgb(122,176,238)", "rgb(209,150,226)", "rgb(127,235,144)", "rgb(252,188,189)", "rgb(247,175,81)",]; @@ -322,15 +321,17 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque const usedSequnce = Array.from(usedPaletted.keys()).sort((a, b) => usedPaletted.get(a)! < usedPaletted.get(b)! ? -1 : usedPaletted.get(a)! > usedPaletted.get(b)! ? 1 : 0); const chosenColor = (usedPaletted.size === 0) ? "white" : palette.length ? palette[0] : usedSequnce[0]; // const inkData = this.ink ? this.ink.inkData : undefined; - const newCollection = Docs.Create.FreeformDocument(selected, { + const creator = asTemplate ? Docs.Create.StackingDocument : Docs.Create.FreeformDocument; + const newCollection = creator(selected, { x: bounds.left, y: bounds.top, - panX: 0, - panY: 0, + _panX: 0, + _panY: 0, backgroundColor: this.props.isAnnotationOverlay ? undefined : chosenColor, defaultBackgroundColor: this.props.isAnnotationOverlay ? undefined : chosenColor, - width: bounds.width, - height: bounds.height, + _width: bounds.width, + _height: bounds.height, + _LODdisable: true, title: "a nested collection", }); // const dataExtensionField = Doc.CreateDocumentExtensionForField(newCollection, "data"); @@ -353,7 +354,7 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque return d; }); } - const newCollection = this.getCollection(selected); + const newCollection = this.getCollection(selected, e.key === "t"); this.props.addDocument(newCollection); this.props.selectDocuments([newCollection], []); MarqueeOptionsMenu.Instance.fadeOut(true); @@ -373,16 +374,17 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque d.page = -1; return d; }); - newCollection.chromeStatus = "disabled"; - const summary = Docs.Create.TextDocument({ x: bounds.left, y: bounds.top, width: 300, height: 100, autoHeight: true, backgroundColor: "#e2ad32" /* yellow */, title: "-summary-" }); + newCollection._chromeStatus = "disabled"; + const summary = Docs.Create.TextDocument("", { x: bounds.left, y: bounds.top, _width: 300, _height: 100, _autoHeight: true, backgroundColor: "#e2ad32" /* yellow */, title: "-summary-" }); Doc.GetProto(summary).summarizedDocs = new List<Doc>([newCollection]); newCollection.x = bounds.left + bounds.width; Doc.GetProto(newCollection).summaryDoc = summary; Doc.GetProto(newCollection).title = ComputedField.MakeFunction(`summaryTitle(this);`); if (e instanceof KeyboardEvent ? e.key === "s" : true) { // summary is wrapped in an expand/collapse container that also contains the summarized documents in a free form view. - const container = Docs.Create.FreeformDocument([summary, newCollection], { x: bounds.left, y: bounds.top, width: 300, height: 200, chromeStatus: "disabled", title: "-summary-" }); - container.viewType = CollectionViewType.Stacking; - container.autoHeight = true; + const container = Docs.Create.FreeformDocument([summary, newCollection], { + x: bounds.left, y: bounds.top, _width: 300, _height: 200, _autoHeight: true, + _viewType: CollectionViewType.Stacking, _chromeStatus: "disabled", title: "-summary-" + }); Doc.GetProto(summary).maximizeLocation = "inPlace"; // or "onRight" this.props.addLiveTextDocument(container); } else if (e instanceof KeyboardEvent ? e.key === "S" : false) { // the summary stands alone, but is linked to a collection of the summarized documents - set the OnCLick behavior to link follow to access them @@ -405,12 +407,12 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque this.delete(); e.stopPropagation(); } - if (e.key === "c" || e.key === "s" || e.key === "S") { + if (e.key === "c" || e.key === "t" || e.key === "s" || e.key === "S") { this._commandExecuted = true; e.stopPropagation(); e.preventDefault(); (e as any).propagationIsStopped = true; - if (e.key === "c") { + if (e.key === "c" || e.key === "t") { this.collection(e); } @@ -467,8 +469,8 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque const layoutDoc = Doc.Layout(doc); const x = NumCast(doc.x); const y = NumCast(doc.y); - const w = NumCast(layoutDoc.width); - const h = NumCast(layoutDoc.height); + const w = NumCast(layoutDoc._width); + const h = NumCast(layoutDoc._height); if (this.intersectRect({ left: x, top: y, width: w, height: h }, selRect)) { selection.push(doc); } @@ -478,8 +480,8 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque const layoutDoc = Doc.Layout(doc); const x = NumCast(doc.x); const y = NumCast(doc.y); - const w = NumCast(layoutDoc.width); - const h = NumCast(layoutDoc.height); + const w = NumCast(layoutDoc._width); + const h = NumCast(layoutDoc._height); if (this.intersectRect({ left: x, top: y, width: w, height: h }, selRect)) { selection.push(doc); } @@ -495,8 +497,8 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque const layoutDoc = Doc.Layout(doc); const x = NumCast(doc.x); const y = NumCast(doc.y); - const w = NumCast(layoutDoc.width); - const h = NumCast(layoutDoc.height); + const w = NumCast(layoutDoc._width); + const h = NumCast(layoutDoc._height); if (this.intersectRect({ left: x, top: y, width: w, height: h }, otherBounds)) { selection.push(doc); } diff --git a/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx b/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx index 70e56183c..041eb69da 100644 --- a/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx +++ b/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx @@ -4,7 +4,7 @@ import { documentSchema } from '../../../../new_fields/documentSchemas'; import { CollectionSubView, SubCollectionViewProps } from '../CollectionSubView'; import * as React from "react"; import { Doc } from '../../../../new_fields/Doc'; -import { NumCast, StrCast, BoolCast } from '../../../../new_fields/Types'; +import { NumCast, StrCast, BoolCast, ScriptCast } from '../../../../new_fields/Types'; import { ContentFittingDocumentView } from '../../nodes/ContentFittingDocumentView'; import { Utils } from '../../../../Utils'; import "./collectionMulticolumnView.scss"; @@ -12,6 +12,8 @@ import { computed, trace, observable, action } from 'mobx'; import { Transform } from '../../../util/Transform'; import WidthLabel from './MulticolumnWidthLabel'; import ResizeBar from './MulticolumnResizer'; +import { undoBatch } from '../../../util/UndoManager'; +import { DragManager } from '../../../util/DragManager'; type MulticolumnDocument = makeInterface<[typeof documentSchema]>; const MulticolumnDocument = makeInterface(documentSchema); @@ -186,6 +188,21 @@ export class CollectionMulticolumnView extends CollectionSubView(MulticolumnDocu return Transform.Identity(); // type coersion, this case should never be hit } + @undoBatch + @action + drop = (e: Event, de: DragManager.DropEvent) => { + if (super.drop(e, de)) { + de.complete.docDragData?.droppedDocuments.forEach(action((d: Doc) => { + d.widthUnit = "*"; + d.widthMagnitude = 1; + })); + } + return false; + } + + + @computed get onChildClickHandler() { return ScriptCast(this.Document.onChildClick); } + /** * @returns the resolved list of rendered child documents, displayed * at their resolved pixel widths, each separated by a resizer. @@ -206,9 +223,11 @@ export class CollectionMulticolumnView extends CollectionSubView(MulticolumnDocu {...this.props} Document={layout} DataDocument={layout.resolvedDataDoc as Doc} + CollectionDoc={this.props.Document} PanelWidth={() => this.lookupPixels(layout)} PanelHeight={() => PanelHeight() - (BoolCast(Document.showWidthLabels) ? 20 : 0)} getTransform={() => this.lookupIndividualTransform(layout)} + onClick={this.onChildClickHandler} /> <WidthLabel layout={layout} @@ -230,10 +249,7 @@ export class CollectionMulticolumnView extends CollectionSubView(MulticolumnDocu render(): JSX.Element { return ( - <div - className={"collectionMulticolumnView_contents"} - ref={this.createDropTarget} - > + <div className={"collectionMulticolumnView_contents"} ref={this.createDashEventsTarget}> {this.contents} </div> ); diff --git a/src/client/views/linking/LinkEditor.tsx b/src/client/views/linking/LinkEditor.tsx index bb8a8b47b..e3bf6b5f8 100644 --- a/src/client/views/linking/LinkEditor.tsx +++ b/src/client/views/linking/LinkEditor.tsx @@ -292,7 +292,7 @@ export class LinkGroupEditor extends React.Component<LinkGroupEditorProps> { if (index > -1) keys.splice(index, 1); const cols = ["anchor1", "anchor2", ...[...keys]].map(c => new SchemaHeaderField(c, "#f1efeb")); const docs: Doc[] = LinkManager.Instance.getAllMetadataDocsInGroup(groupType); - const createTable = action(() => Docs.Create.SchemaDocument(cols, docs, { width: 500, height: 300, title: groupType + " table" })); + const createTable = action(() => Docs.Create.SchemaDocument(cols, docs, { _width: 500, _height: 300, title: groupType + " table" })); const ref = React.createRef<HTMLDivElement>(); return <div ref={ref}><button className="linkEditor-button" onPointerDown={SetupDrag(ref, createTable)} title="Drag to view relationship table"><FontAwesomeIcon icon="table" size="sm" /></button></div>; } diff --git a/src/client/views/linking/LinkFollowBox.tsx b/src/client/views/linking/LinkFollowBox.tsx index 29e167ff7..325c92413 100644 --- a/src/client/views/linking/LinkFollowBox.tsx +++ b/src/client/views/linking/LinkFollowBox.tsx @@ -89,7 +89,7 @@ export class LinkFollowBox extends React.Component<FieldViewProps> { async resetPan() { if (LinkFollowBox.destinationDoc && this.sourceView && this.sourceView.props.ContainingCollectionDoc) { runInAction(() => this.canPan = false); - if (this.sourceView.props.ContainingCollectionDoc.viewType === CollectionViewType.Freeform) { + if (this.sourceView.props.ContainingCollectionDoc._viewType === CollectionViewType.Freeform) { const docs = Cast(this.sourceView.props.ContainingCollectionDoc.data, listSpec(Doc), []); const aliases = await SearchUtil.GetViewsOfDocument(Doc.GetProto(LinkFollowBox.destinationDoc)); @@ -165,11 +165,11 @@ export class LinkFollowBox extends React.Component<FieldViewProps> { @undoBatch openColFullScreen = (options: { context: Doc }) => { if (LinkFollowBox.destinationDoc) { - if (NumCast(options.context.viewType, CollectionViewType.Invalid) === CollectionViewType.Freeform) { - const newPanX = NumCast(LinkFollowBox.destinationDoc.x) + NumCast(LinkFollowBox.destinationDoc.width) / 2; - const newPanY = NumCast(LinkFollowBox.destinationDoc.y) + NumCast(LinkFollowBox.destinationDoc.height) / 2; - options.context.panX = newPanX; - options.context.panY = newPanY; + if (NumCast(options.context._viewType, CollectionViewType.Invalid) === CollectionViewType.Freeform) { + const newPanX = NumCast(LinkFollowBox.destinationDoc.x) + NumCast(LinkFollowBox.destinationDoc._width) / 2; + const newPanY = NumCast(LinkFollowBox.destinationDoc.y) + NumCast(LinkFollowBox.destinationDoc._height) / 2; + options.context._panX = newPanX; + options.context._panY = newPanY; } const view = DocumentManager.Instance.getDocumentView(options.context); view && CollectionDockingView.Instance && CollectionDockingView.Instance.OpenFullScreen(view); @@ -193,11 +193,11 @@ export class LinkFollowBox extends React.Component<FieldViewProps> { openLinkColRight = (options: { context: Doc, shouldZoom: boolean }) => { if (LinkFollowBox.destinationDoc) { options.context = Doc.IsPrototype(options.context) ? Doc.MakeDelegate(options.context) : options.context; - if (NumCast(options.context.viewType, CollectionViewType.Invalid) === CollectionViewType.Freeform) { - const newPanX = NumCast(LinkFollowBox.destinationDoc.x) + NumCast(LinkFollowBox.destinationDoc.width) / 2; - const newPanY = NumCast(LinkFollowBox.destinationDoc.y) + NumCast(LinkFollowBox.destinationDoc.height) / 2; - options.context.panX = newPanX; - options.context.panY = newPanY; + if (NumCast(options.context._viewType, CollectionViewType.Invalid) === CollectionViewType.Freeform) { + const newPanX = NumCast(LinkFollowBox.destinationDoc.x) + NumCast(LinkFollowBox.destinationDoc._width) / 2; + const newPanY = NumCast(LinkFollowBox.destinationDoc.y) + NumCast(LinkFollowBox.destinationDoc._height) / 2; + options.context._panX = newPanX; + options.context._panY = newPanY; } (LinkFollowBox._addDocTab || this.props.addDocTab)(options.context, undefined, "onRight"); @@ -245,11 +245,11 @@ export class LinkFollowBox extends React.Component<FieldViewProps> { openLinkColTab = (options: { context: Doc, shouldZoom: boolean }) => { if (LinkFollowBox.destinationDoc) { options.context = Doc.IsPrototype(options.context) ? Doc.MakeDelegate(options.context) : options.context; - if (NumCast(options.context.viewType, CollectionViewType.Invalid) === CollectionViewType.Freeform) { - const newPanX = NumCast(LinkFollowBox.destinationDoc.x) + NumCast(LinkFollowBox.destinationDoc.width) / 2; - const newPanY = NumCast(LinkFollowBox.destinationDoc.y) + NumCast(LinkFollowBox.destinationDoc.height) / 2; - options.context.panX = newPanX; - options.context.panY = newPanY; + if (NumCast(options.context._viewType, CollectionViewType.Invalid) === CollectionViewType.Freeform) { + const newPanX = NumCast(LinkFollowBox.destinationDoc.x) + NumCast(LinkFollowBox.destinationDoc._width) / 2; + const newPanY = NumCast(LinkFollowBox.destinationDoc.y) + NumCast(LinkFollowBox.destinationDoc._height) / 2; + options.context._panX = newPanX; + options.context._panY = newPanY; } (LinkFollowBox._addDocTab || this.props.addDocTab)(options.context, undefined, "inTab"); if (options.shouldZoom) this.jumpToLink({ shouldZoom: options.shouldZoom }); @@ -270,13 +270,13 @@ export class LinkFollowBox extends React.Component<FieldViewProps> { const y = NumCast(LinkFollowBox.sourceDoc.y); const x = NumCast(LinkFollowBox.sourceDoc.x); - const width = NumCast(LinkFollowBox.sourceDoc.width); - const height = NumCast(LinkFollowBox.sourceDoc.height); + const width = NumCast(LinkFollowBox.sourceDoc._width); + const height = NumCast(LinkFollowBox.sourceDoc._height); alias.x = x + width + 30; alias.y = y; - alias.width = width; - alias.height = height; + alias._width = width; + alias._height = height; this.sourceView.props.addDocument(alias); } @@ -361,7 +361,7 @@ export class LinkFollowBox extends React.Component<FieldViewProps> { get canOpenInPlace() { if (this.sourceView && this.sourceView.props.ContainingCollectionDoc) { const colDoc = this.sourceView.props.ContainingCollectionDoc; - if (colDoc.viewType && colDoc.viewType === CollectionViewType.Freeform) return true; + if (colDoc._viewType === CollectionViewType.Freeform) return true; } return false; } @@ -481,7 +481,7 @@ export class LinkFollowBox extends React.Component<FieldViewProps> { let contextMatch: boolean = false; if (this.selectedContextAliases) { this.selectedContextAliases.forEach(alias => { - if (alias.viewType === CollectionViewType.Freeform) contextMatch = true; + if (alias._viewType === CollectionViewType.Freeform) contextMatch = true; }); } if (contextMatch) return true; @@ -523,7 +523,7 @@ export class LinkFollowBox extends React.Component<FieldViewProps> { render() { return ( - <div className="linkFollowBox-main" style={{ height: NumCast(this.props.Document.height), width: NumCast(this.props.Document.width) }}> + <div className="linkFollowBox-main" style={{ height: NumCast(this.props.Document._height), width: NumCast(this.props.Document._width) }}> <div className="linkFollowBox-header"> <div className="topHeader"> {LinkFollowBox.linkDoc ? "Link Title: " + StrCast(LinkFollowBox.linkDoc.title) : "No Link Selected"} @@ -533,7 +533,7 @@ export class LinkFollowBox extends React.Component<FieldViewProps> { LinkFollowBox.sourceDoc && LinkFollowBox.destinationDoc ? "Source: " + StrCast(LinkFollowBox.sourceDoc.title) + ", Destination: " + StrCast(LinkFollowBox.destinationDoc.title) : "" : ""}</div> </div> - <div className="linkFollowBox-content" style={{ height: NumCast(this.props.Document.height) - 110 }}> + <div className="linkFollowBox-content" style={{ height: NumCast(this.props.Document._height) - 110 }}> <div className="linkFollowBox-item"> <div className="linkFollowBox-item title">Mode</div> <div className="linkFollowBox-itemContent"> diff --git a/src/client/views/linking/LinkMenu.tsx b/src/client/views/linking/LinkMenu.tsx index 52628ba4c..1a40f0c55 100644 --- a/src/client/views/linking/LinkMenu.tsx +++ b/src/client/views/linking/LinkMenu.tsx @@ -25,7 +25,7 @@ export class LinkMenu extends React.Component<Props> { @observable private _editingLink?: Doc; @action - componentWillReceiveProps() { + componentDidMount() { this._editingLink = undefined; } diff --git a/src/client/views/linking/LinkMenuGroup.tsx b/src/client/views/linking/LinkMenuGroup.tsx index ace9a9e4c..0c38ff45c 100644 --- a/src/client/views/linking/LinkMenuGroup.tsx +++ b/src/client/views/linking/LinkMenuGroup.tsx @@ -58,7 +58,7 @@ export class LinkMenuGroup extends React.Component<LinkMenuGroupProps> { if (index > -1) keys.splice(index, 1); const cols = ["anchor1", "anchor2", ...[...keys]].map(c => new SchemaHeaderField(c, "#f1efeb")); const docs: Doc[] = LinkManager.Instance.getAllMetadataDocsInGroup(groupType); - const createTable = action(() => Docs.Create.SchemaDocument(cols, docs, { width: 500, height: 300, title: groupType + " table" })); + const createTable = action(() => Docs.Create.SchemaDocument(cols, docs, { _width: 500, _height: 300, title: groupType + " table" })); const ref = React.createRef<HTMLDivElement>(); return <div ref={ref}><button className="linkEditor-button linkEditor-tableButton" onPointerDown={SetupDrag(ref, createTable)} title="Drag to view relationship table"><FontAwesomeIcon icon="table" size="sm" /></button></div>; } diff --git a/src/client/views/nodes/AudioBox.tsx b/src/client/views/nodes/AudioBox.tsx index 95c765e8a..62a479b2a 100644 --- a/src/client/views/nodes/AudioBox.tsx +++ b/src/client/views/nodes/AudioBox.tsx @@ -68,7 +68,7 @@ export class AudioBox extends DocExtendableComponent<FieldViewProps, AudioDocume this.Document.playOnSelect && sel && !Doc.AreProtosEqual(sel, this.props.Document) && this.playFrom(DateCast(sel.creationTime).date.getTime()); }); this._scrubbingDisposer = reaction(() => AudioBox._scrubTime, timeInMillisecondsFrom1970 => { - const start = this.extensionDoc && DateCast(this.extensionDoc.recordingStart); + const start = DateCast(this.dataDoc[this.props.fieldKey + "-recordingStart"]); start && this.playFrom((timeInMillisecondsFrom1970 - start.date.getTime()) / 1000); }); } @@ -128,18 +128,17 @@ export class AudioBox extends DocExtendableComponent<FieldViewProps, AudioDocume recordAudioAnnotation = () => { let gumStream: any; const self = this; - const extensionDoc = this.extensionDoc; - extensionDoc && navigator.mediaDevices.getUserMedia({ + navigator.mediaDevices.getUserMedia({ audio: true }).then(function (stream) { gumStream = stream; self._recorder = new MediaRecorder(stream); - extensionDoc.recordingStart = new DateField(new Date()); + self.dataDoc[self.props.fieldKey + "-recordingStart"] = new DateField(new Date()); AudioBox.ActiveRecordings.push(self.props.Document); self._recorder.ondataavailable = async function (e: any) { const formData = new FormData(); formData.append("file", e.data); - const res = await fetch(Utils.prepend("/upload"), { + const res = await fetch(Utils.prepend("/uploadFormData"), { method: 'POST', body: formData }); @@ -213,55 +212,53 @@ export class AudioBox extends DocExtendableComponent<FieldViewProps, AudioDocume render() { const interactive = this.active() ? "-interactive" : ""; - return (!this.extensionDoc ? (null) : - <div className={`audiobox-container`} onContextMenu={this.specificContextMenu} - onClick={!this.path ? this.recordClick : undefined}> - <div className="audiobox-handle"></div> - {!this.path ? - <button className={`audiobox-record${interactive}`} style={{ backgroundColor: this._audioState === "recording" ? "red" : "black" }}> - {this._audioState === "recording" ? "STOP" : "RECORD"} - </button> : - <div className="audiobox-controls"> - <div className="audiobox-player" onClick={this.onPlay}> - <div className="audiobox-playhead"> <FontAwesomeIcon style={{ width: "100%" }} icon={this._playing ? "pause" : "play"} size={this.props.PanelHeight() < 36 ? "1x" : "2x"} /></div> - <div className="audiobox-playhead" onClick={this.onStop}><FontAwesomeIcon style={{ width: "100%" }} icon="stop" size={this.props.PanelHeight() < 36 ? "1x" : "2x"} /></div> - <div className="audiobox-timeline" onClick={e => e.stopPropagation()} - onPointerDown={e => { - if (e.button === 0 && !e.ctrlKey) { - const rect = (e.target as any).getBoundingClientRect(); - this._ele!.currentTime = this.Document.currentTimecode = (e.clientX - rect.x) / rect.width * NumCast(this.dataDoc.duration); - this.pause(); - e.stopPropagation(); - } - }} > - {DocListCast(this.dataDoc.links).map((l, i) => { - let la1 = l.anchor1 as Doc; - let la2 = l.anchor2 as Doc; - let linkTime = NumCast(l.anchor2Timecode); - if (Doc.AreProtosEqual(la1, this.dataDoc)) { - la1 = l.anchor2 as Doc; - la2 = l.anchor1 as Doc; - linkTime = NumCast(l.anchor1Timecode); - } - return !linkTime ? (null) : - <div className={this.props.PanelHeight() < 32 ? "audiobox-marker-minicontainer" : "audiobox-marker-container"} key={l[Id]} style={{ left: `${linkTime / NumCast(this.dataDoc.duration, 1) * 100}%` }}> - <div className={this.props.PanelHeight() < 32 ? "audioBox-linker-mini" : "audioBox-linker"} key={"linker" + i}> - <DocumentView {...this.props} Document={l} layoutKey={Doc.LinkEndpoint(l, la2)} - parentActive={returnTrue} bringToFront={emptyFunction} zoomToScale={emptyFunction} getScale={returnOne} - backgroundColor={returnTransparent} /> - </div> - <div key={i} className="audiobox-marker" onPointerEnter={() => Doc.linkFollowHighlight(la1)} - onPointerDown={e => { if (e.button === 0 && !e.ctrlKey) { this.playFrom(linkTime); e.stopPropagation(); } }} - onClick={e => { if (e.button === 0 && !e.ctrlKey) { this.pause(); e.stopPropagation(); } }} /> - </div>; - })} - <div className="audiobox-current" style={{ left: `${NumCast(this.Document.currentTimecode) / NumCast(this.dataDoc.duration, 1) * 100}%` }} /> - {this.audio} - </div> + return <div className={`audiobox-container`} onContextMenu={this.specificContextMenu} + onClick={!this.path ? this.recordClick : undefined}> + <div className="audiobox-handle"></div> + {!this.path ? + <button className={`audiobox-record${interactive}`} style={{ backgroundColor: this._audioState === "recording" ? "red" : "black" }}> + {this._audioState === "recording" ? "STOP" : "RECORD"} + </button> : + <div className="audiobox-controls"> + <div className="audiobox-player" onClick={this.onPlay}> + <div className="audiobox-playhead"> <FontAwesomeIcon style={{ width: "100%" }} icon={this._playing ? "pause" : "play"} size={this.props.PanelHeight() < 36 ? "1x" : "2x"} /></div> + <div className="audiobox-playhead" onClick={this.onStop}><FontAwesomeIcon style={{ width: "100%" }} icon="stop" size={this.props.PanelHeight() < 36 ? "1x" : "2x"} /></div> + <div className="audiobox-timeline" onClick={e => e.stopPropagation()} + onPointerDown={e => { + if (e.button === 0 && !e.ctrlKey) { + const rect = (e.target as any).getBoundingClientRect(); + this._ele!.currentTime = this.Document.currentTimecode = (e.clientX - rect.x) / rect.width * NumCast(this.dataDoc.duration); + this.pause(); + e.stopPropagation(); + } + }} > + {DocListCast(this.dataDoc.links).map((l, i) => { + let la1 = l.anchor1 as Doc; + let la2 = l.anchor2 as Doc; + let linkTime = NumCast(l.anchor2Timecode); + if (Doc.AreProtosEqual(la1, this.dataDoc)) { + la1 = l.anchor2 as Doc; + la2 = l.anchor1 as Doc; + linkTime = NumCast(l.anchor1Timecode); + } + return !linkTime ? (null) : + <div className={this.props.PanelHeight() < 32 ? "audiobox-marker-minicontainer" : "audiobox-marker-container"} key={l[Id]} style={{ left: `${linkTime / NumCast(this.dataDoc.duration, 1) * 100}%` }}> + <div className={this.props.PanelHeight() < 32 ? "audioBox-linker-mini" : "audioBox-linker"} key={"linker" + i}> + <DocumentView {...this.props} Document={l} layoutKey={Doc.LinkEndpoint(l, la2)} + parentActive={returnTrue} bringToFront={emptyFunction} zoomToScale={emptyFunction} getScale={returnOne} + backgroundColor={returnTransparent} /> + </div> + <div key={i} className="audiobox-marker" onPointerEnter={() => Doc.linkFollowHighlight(la1)} + onPointerDown={e => { if (e.button === 0 && !e.ctrlKey) { this.playFrom(linkTime); e.stopPropagation(); } }} + onClick={e => { if (e.button === 0 && !e.ctrlKey) { this.pause(); e.stopPropagation(); } }} /> + </div>; + })} + <div className="audiobox-current" style={{ left: `${NumCast(this.Document.currentTimecode) / NumCast(this.dataDoc.duration, 1) * 100}%` }} /> + {this.audio} </div> </div> - } - </div> - ); + </div> + } + </div>; } }
\ No newline at end of file diff --git a/src/client/views/nodes/ButtonBox.tsx b/src/client/views/nodes/ButtonBox.tsx index d29fe1711..ee48b47b7 100644 --- a/src/client/views/nodes/ButtonBox.tsx +++ b/src/client/views/nodes/ButtonBox.tsx @@ -36,7 +36,7 @@ export class ButtonBox extends DocComponent<FieldViewProps, ButtonDocument>(Butt @computed get dataDoc() { return this.props.DataDoc && - (this.Document.isTemplateField || BoolCast(this.props.DataDoc.isTemplateField) || + (this.Document.isTemplateForField || BoolCast(this.props.DataDoc.isTemplateForField) || this.props.DataDoc.layout === this.props.Document) ? this.props.DataDoc : Doc.GetProto(this.props.Document); } diff --git a/src/client/views/nodes/CollectionFreeFormDocumentView.tsx b/src/client/views/nodes/CollectionFreeFormDocumentView.tsx index 614a68e7a..2183129cf 100644 --- a/src/client/views/nodes/CollectionFreeFormDocumentView.tsx +++ b/src/client/views/nodes/CollectionFreeFormDocumentView.tsx @@ -28,6 +28,8 @@ export interface CollectionFreeFormDocumentViewProps extends DocumentViewProps { @observer export class CollectionFreeFormDocumentView extends DocComponent<CollectionFreeFormDocumentViewProps, PositionDocument>(PositionDocument) { _disposer: IReactionDisposer | undefined = undefined; + + @observable _animPos: number[] | undefined = undefined; get displayName() { return "CollectionFreeFormDocumentView(" + this.props.Document.title + ")"; } // this makes mobx trace() statements more descriptive get transform() { return `scale(${this.props.ContentScaling()}) translate(${this.X}px, ${this.Y}px) rotate(${anime.random(-1, 1) * this.props.jitterRotation}deg)`; } get X() { return this._animPos !== undefined ? this._animPos[0] : this.renderScriptDim ? this.renderScriptDim.x : this.props.x !== undefined ? this.props.x : this.dataProvider ? this.dataProvider.x : (this.Document.x || 0); } @@ -38,57 +40,43 @@ export class CollectionFreeFormDocumentView extends DocComponent<CollectionFreeF return (hgt === undefined && this.nativeWidth && this.nativeHeight) ? this.width * this.nativeHeight / this.nativeWidth : hgt; } @computed get dataProvider() { return this.props.dataProvider && this.props.dataProvider(this.props.Document) ? this.props.dataProvider(this.props.Document) : undefined; } - @computed get nativeWidth() { return NumCast(this.layoutDoc.nativeWidth); } - @computed get nativeHeight() { return NumCast(this.layoutDoc.nativeHeight); } + @computed get nativeWidth() { return NumCast(this.layoutDoc._nativeWidth); } + @computed get nativeHeight() { return NumCast(this.layoutDoc._nativeHeight); } @computed get renderScriptDim() { if (this.Document.renderScript) { const someView = Cast(this.props.Document.someView, Doc); const minimap = Cast(this.props.Document.minimap, Doc); if (someView instanceof Doc && minimap instanceof Doc) { - const x = (NumCast(someView.panX) - NumCast(someView.width) / 2 / NumCast(someView.scale) - (NumCast(minimap.fitX) - NumCast(minimap.fitW) / 2)) / NumCast(minimap.fitW) * NumCast(minimap.width) - NumCast(minimap.width) / 2; - const y = (NumCast(someView.panY) - NumCast(someView.height) / 2 / NumCast(someView.scale) - (NumCast(minimap.fitY) - NumCast(minimap.fitH) / 2)) / NumCast(minimap.fitH) * NumCast(minimap.height) - NumCast(minimap.height) / 2; - const w = NumCast(someView.width) / NumCast(someView.scale) / NumCast(minimap.fitW) * NumCast(minimap.width); - const h = NumCast(someView.height) / NumCast(someView.scale) / NumCast(minimap.fitH) * NumCast(minimap.height); + const x = (NumCast(someView._panX) - NumCast(someView._width) / 2 / NumCast(someView.scale) - (NumCast(minimap.fitX) - NumCast(minimap.fitW) / 2)) / NumCast(minimap.fitW) * NumCast(minimap._width) - NumCast(minimap._width) / 2; + const y = (NumCast(someView._panY) - NumCast(someView._height) / 2 / NumCast(someView.scale) - (NumCast(minimap.fitY) - NumCast(minimap.fitH) / 2)) / NumCast(minimap.fitH) * NumCast(minimap._height) - NumCast(minimap._height) / 2; + const w = NumCast(someView._width) / NumCast(someView.scale) / NumCast(minimap.fitW) * NumCast(minimap.width); + const h = NumCast(someView._height) / NumCast(someView.scale) / NumCast(minimap.fitH) * NumCast(minimap.height); return { x: x, y: y, width: w, height: h }; } } return undefined; } - componentWillUnmount() { - this._disposer && this._disposer(); - } + componentWillUnmount() { this._disposer?.(); } componentDidMount() { - this._disposer = reaction(() => this.props.Document.animateToPos ? Array.from(Cast(this.props.Document.animateToPos, listSpec("number"))!) : undefined, - target => this._animPos = !target ? undefined : target[2] ? [NumCast(this.layoutDoc.x), NumCast(this.layoutDoc.y)] : this.props.ScreenToLocalTransform().transformPoint(target[0], target[1]), + this._disposer = reaction(() => Array.from(Cast(this.props.Document?.animateToPos, listSpec("number"), null) || []), + target => this._animPos = !target || !target?.length ? undefined : target[2] ? [NumCast(this.layoutDoc.x), NumCast(this.layoutDoc.y)] : + this.props.ScreenToLocalTransform().transformPoint(target[0], target[1]), { fireImmediately: true }); } - contentScaling = () => this.nativeWidth > 0 && !this.props.Document.ignoreAspect ? this.width / this.nativeWidth : 1; - panelWidth = () => this.props.PanelWidth(); - panelHeight = () => this.props.PanelHeight(); + contentScaling = () => this.nativeWidth > 0 && !this.props.Document.ignoreAspect && !this.props.fitToBox ? this.width / this.nativeWidth : 1; + clusterColorFunc = (doc: Doc) => this.clusterColor; + panelWidth = () => (this.dataProvider?.width || this.props.PanelWidth()); + panelHeight = () => (this.dataProvider?.height || this.props.PanelHeight()); getTransform = (): Transform => this.props.ScreenToLocalTransform() .translate(-this.X, -this.Y) .scale(1 / this.contentScaling()) - borderRounding = () => { - const ruleRounding = this.props.ruleProvider ? StrCast(this.props.ruleProvider["ruleRounding_" + this.Document.heading]) : undefined; - const ld = this.layoutDoc[StrCast(this.layoutDoc.layoutKey, "layout")] instanceof Doc ? this.layoutDoc[StrCast(this.layoutDoc.layoutKey, "layout")] as Doc : undefined; - const br = StrCast((ld || this.props.Document).borderRounding); - return !br && ruleRounding ? ruleRounding : br; - } - @computed get clusterColor() { return this.props.backgroundColor(this.props.Document); } - clusterColorFunc = (doc: Doc) => this.clusterColor; - - @observable _animPos: number[] | undefined = undefined; - - finalPanelWidth = () => (this.dataProvider ? this.dataProvider.width : this.panelWidth()); - finalPanelHeight = () => (this.dataProvider ? this.dataProvider.height : this.panelHeight()); - render() { TraceMobx(); return <div className="collectionFreeFormDocumentView-container" @@ -99,7 +87,7 @@ export class CollectionFreeFormDocumentView extends DocComponent<CollectionFreeF this.clusterColor ? (`${this.clusterColor} ${StrCast(this.layoutDoc.boxShadow, `0vw 0vw ${(this.layoutDoc.isBackground ? 100 : 50) / this.props.ContentScaling()}px`)}`) : // if it's just in a cluster, make the shadown roughly match the cluster border extent this.layoutDoc.isBackground ? undefined : // if it's a background & has a cluster color, make the shadow spread really big StrCast(this.layoutDoc.boxShadow, ""), - borderRadius: this.borderRounding(), + borderRadius: StrCast(Doc.Layout(this.layoutDoc).borderRounding), transform: this.transform, transition: this.Document.isAnimating ? ".5s ease-in" : this.props.transition ? this.props.transition : this.dataProvider ? this.dataProvider.transition : StrCast(this.layoutDoc.transition), width: this.width, @@ -107,21 +95,21 @@ export class CollectionFreeFormDocumentView extends DocComponent<CollectionFreeF zIndex: this.Document.zIndex || 0, }} > - {!this.props.fitToBox ? <DocumentView {...this.props} dragDivName={"collectionFreeFormDocumentView-container"} ContentScaling={this.contentScaling} ScreenToLocalTransform={this.getTransform} backgroundColor={this.clusterColorFunc} - PanelWidth={this.finalPanelWidth} - PanelHeight={this.finalPanelHeight} + PanelWidth={this.panelWidth} + PanelHeight={this.panelHeight} /> : <ContentFittingDocumentView {...this.props} + CollectionDoc={this.props.ContainingCollectionDoc} DataDocument={this.props.DataDoc} getTransform={this.getTransform} active={returnFalse} focus={(doc: Doc) => this.props.focus(doc, false)} - PanelWidth={this.finalPanelWidth} - PanelHeight={this.finalPanelHeight} + PanelWidth={this.panelWidth} + PanelHeight={this.panelHeight} />} </div>; } diff --git a/src/client/views/nodes/ContentFittingDocumentView.tsx b/src/client/views/nodes/ContentFittingDocumentView.tsx index e97445f27..51c8e00da 100644 --- a/src/client/views/nodes/ContentFittingDocumentView.tsx +++ b/src/client/views/nodes/ContentFittingDocumentView.tsx @@ -24,9 +24,7 @@ interface ContentFittingDocumentViewProps { fitToBox?: boolean; PanelWidth: () => number; PanelHeight: () => number; - ruleProvider: Doc | undefined; focus?: (doc: Doc) => void; - showOverlays?: (doc: Doc) => { title?: string, caption?: string }; CollectionView?: CollectionView; CollectionDoc?: Doc; onClick?: ScriptField; @@ -45,8 +43,8 @@ interface ContentFittingDocumentViewProps { export class ContentFittingDocumentView extends React.Component<ContentFittingDocumentViewProps>{ public get displayName() { return "DocumentView(" + this.props.Document?.title + ")"; } // this makes mobx trace() statements more descriptive private get layoutDoc() { return this.props.Document && Doc.Layout(this.props.Document); } - private get nativeWidth() { return NumCast(this.layoutDoc?.nativeWidth, this.props.PanelWidth()); } - private get nativeHeight() { return NumCast(this.layoutDoc?.nativeHeight, this.props.PanelHeight()); } + private get nativeWidth() { return NumCast(this.layoutDoc?._nativeWidth, this.props.PanelWidth()); } + private get nativeHeight() { return NumCast(this.layoutDoc?._nativeHeight, this.props.PanelHeight()); } private contentScaling = () => { const wscale = this.props.PanelWidth() / (this.nativeWidth || this.props.PanelWidth() || 1); if (wscale * this.nativeHeight > this.props.PanelHeight()) { @@ -63,16 +61,16 @@ export class ContentFittingDocumentView extends React.Component<ContentFittingDo this.props.childDocs && this.props.childDocs.map(otherdoc => { const target = Doc.GetProto(otherdoc); target.layout = ComputedField.MakeFunction("this.image_data[0]"); - target.layoutCustom = Doc.MakeDelegate(docDragData.draggedDocuments[0]); + target.layout_custom = Doc.MakeDelegate(docDragData.draggedDocuments[0]); }); e.stopPropagation(); } return true; } - private PanelWidth = () => this.nativeWidth && (!this.props.Document || !this.props.Document.fitWidth) ? this.nativeWidth * this.contentScaling() : this.props.PanelWidth(); - private PanelHeight = () => this.nativeHeight && (!this.props.Document || !this.props.Document.fitWidth) ? this.nativeHeight * this.contentScaling() : this.props.PanelHeight(); + private PanelWidth = () => this.nativeWidth && (!this.props.Document || !this.props.Document._fitWidth) ? this.nativeWidth * this.contentScaling() : this.props.PanelWidth(); + private PanelHeight = () => this.nativeHeight && (!this.props.Document || !this.props.Document._fitWidth) ? this.nativeHeight * this.contentScaling() : this.props.PanelHeight(); private getTransform = () => this.props.getTransform().translate(-this.centeringOffset, -this.centeringYOffset).scale(1 / this.contentScaling()); - private get centeringOffset() { return this.nativeWidth && (!this.props.Document || !this.props.Document.fitWidth) ? (this.props.PanelWidth() - this.nativeWidth * this.contentScaling()) / 2 : 0; } + private get centeringOffset() { return this.nativeWidth && (!this.props.Document || !this.props.Document._fitWidth) ? (this.props.PanelWidth() - this.nativeWidth * this.contentScaling()) / 2 : 0; } private get centeringYOffset() { return Math.abs(this.centeringOffset) < 0.001 ? (this.props.PanelHeight() - this.nativeHeight * this.contentScaling()) / 2 : 0; } @computed get borderRounding() { return StrCast(this.props.Document?.borderRounding); } @@ -97,8 +95,6 @@ export class ContentFittingDocumentView extends React.Component<ContentFittingDo LibraryPath={this.props.LibraryPath} fitToBox={this.props.fitToBox} onClick={this.props.onClick} - ruleProvider={this.props.ruleProvider} - showOverlays={this.props.showOverlays} addDocument={this.props.addDocument} removeDocument={this.props.removeDocument} moveDocument={this.props.moveDocument} diff --git a/src/client/views/nodes/DocuLinkBox.tsx b/src/client/views/nodes/DocuLinkBox.tsx index 0d4d50c59..a4a9a62aa 100644 --- a/src/client/views/nodes/DocuLinkBox.tsx +++ b/src/client/views/nodes/DocuLinkBox.tsx @@ -61,10 +61,12 @@ export class DocuLinkBox extends DocComponent<FieldViewProps, DocLinkSchema>(Doc } } onClick = (e: React.MouseEvent) => { - if (Math.abs(e.clientX - this._downx) < 3 && Math.abs(e.clientY - this._downy) < 3 && (e.button !== 2 && !e.ctrlKey && this.props.Document.isButton)) { - DocumentManager.Instance.FollowLink(this.props.Document, this.props.Document[this.props.fieldKey] as Doc, document => this.props.addDocTab(document, undefined, "inTab"), false); + if (!this.props.Document.onClick) { + if (Math.abs(e.clientX - this._downx) < 3 && Math.abs(e.clientY - this._downy) < 3 && (e.button !== 2 && !e.ctrlKey && this.props.Document.isButton)) { + DocumentManager.Instance.FollowLink(this.props.Document, this.props.Document[this.props.fieldKey] as Doc, document => this.props.addDocTab(document, undefined, "inTab"), false); + } + e.stopPropagation(); } - e.stopPropagation(); } render() { diff --git a/src/client/views/nodes/DocumentBox.tsx b/src/client/views/nodes/DocumentBox.tsx index 863ea748b..6b7b652c6 100644 --- a/src/client/views/nodes/DocumentBox.tsx +++ b/src/client/views/nodes/DocumentBox.tsx @@ -96,7 +96,6 @@ export class DocumentBox extends DocComponent<FieldViewProps, DocBoxSchema>(DocB addDocument={this.props.addDocument} moveDocument={this.props.moveDocument} removeDocument={this.props.removeDocument} - ruleProvider={this.props.ruleProvider} addDocTab={this.props.addDocTab} pinToPres={this.props.pinToPres} getTransform={this.getTransform} diff --git a/src/client/views/nodes/DocumentContentsView.tsx b/src/client/views/nodes/DocumentContentsView.tsx index 66886165e..0b01e6471 100644 --- a/src/client/views/nodes/DocumentContentsView.tsx +++ b/src/client/views/nodes/DocumentContentsView.tsx @@ -54,14 +54,12 @@ const ObserverJsxParser: typeof JsxParser = ObserverJsxParser1 as any; export class DocumentContentsView extends React.Component<DocumentViewProps & { isSelected: (outsideReaction: boolean) => boolean, select: (ctrl: boolean) => void, - onClick?: ScriptField, layoutKey: string, - hideOnLeave?: boolean }> { @computed get layout(): string { TraceMobx(); if (!this.layoutDoc) return "<p>awaiting layout</p>"; - const layout = Cast(this.layoutDoc[this.props.layoutKey], "string"); + const layout = Cast(this.layoutDoc[StrCast(this.layoutDoc.layoutKey, this.layoutDoc === this.props.Document ? this.props.layoutKey : "layout")], "string"); if (layout === undefined) { return this.props.Document.data ? "<FieldView {...props} fieldKey='data' />" : @@ -77,12 +75,13 @@ export class DocumentContentsView extends React.Component<DocumentViewProps & { if (this.props.DataDoc === undefined && typeof Doc.LayoutField(this.props.Document) !== "string") { // if there is no dataDoc (ie, we're not rendering a template layout), but this document has a layout document (not a layout string), // then we render the layout document as a template and use this document as the data context for the template layout. - return this.props.Document; + const proto = Doc.GetProto(this.props.Document); + return proto instanceof Promise ? undefined : proto; } - return this.props.DataDoc; + return this.props.DataDoc instanceof Promise ? undefined : this.props.DataDoc; } get layoutDoc() { - return Doc.expandTemplateLayout(Doc.Layout(this.props.Document), this.props.Document); + return Doc.Layout(this.props.Document); } CreateBindings(): JsxBindings { diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index ad28c9b1c..a7413d460 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -9,12 +9,12 @@ import { Id } from '../../../new_fields/FieldSymbols'; import { listSpec } from "../../../new_fields/Schema"; import { ScriptField } from '../../../new_fields/ScriptField'; import { BoolCast, Cast, NumCast, StrCast } from "../../../new_fields/Types"; -import { ImageField } from '../../../new_fields/URLField'; +import { ImageField, PdfField, VideoField, AudioField } from '../../../new_fields/URLField'; import { CurrentUserUtils } from "../../../server/authentication/models/current_user_utils"; import { emptyFunction, returnTransparent, returnTrue, Utils, returnOne } from "../../../Utils"; import { GooglePhotos } from '../../apis/google_docs/GooglePhotosClientUtils'; import { DocServer } from "../../DocServer"; -import { Docs, DocUtils } from "../../documents/Documents"; +import { Docs, DocUtils, DocumentOptions } from "../../documents/Documents"; import { DocumentType } from '../../documents/DocumentTypes'; import { ClientUtils } from '../../util/ClientUtils'; import { DocumentManager } from "../../util/DocumentManager"; @@ -49,6 +49,7 @@ import { RadialMenu } from './RadialMenu'; import { RadialMenuProps } from './RadialMenuItem'; import { CollectionStackingView } from '../collections/CollectionStackingView'; +import { RichTextField } from '../../../new_fields/RichTextField'; library.add(fa.faEdit, fa.faTrash, fa.faShare, fa.faDownload, fa.faExpandArrowsAlt, fa.faCompressArrowsAlt, fa.faLayerGroup, fa.faExternalLinkAlt, fa.faAlignCenter, fa.faCaretSquareRight, fa.faSquare, fa.faConciergeBell, fa.faWindowRestore, fa.faFolder, fa.faMapPin, fa.faLink, fa.faFingerprint, fa.faCrosshairs, fa.faDesktop, fa.faUnlock, fa.faLock, fa.faLaptopCode, fa.faMale, @@ -70,9 +71,7 @@ export interface DocumentViewProps { moveDocument?: (doc: Doc, targetCollection: Doc | undefined, addDocument: (document: Doc) => boolean) => boolean; ScreenToLocalTransform: () => Transform; renderDepth: number; - showOverlays?: (doc: Doc) => { title?: string, titleHover?: string, caption?: string }; ContentScaling: () => number; - ruleProvider: Doc | undefined; PanelWidth: () => number; PanelHeight: () => number; focus: (doc: Doc, willZoom: boolean, scale?: number, afterFocus?: () => boolean) => void; @@ -109,8 +108,8 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu public get ContentDiv() { return this._mainCont.current; } @computed get active() { return SelectionManager.IsSelected(this, true) || this.props.parentActive(true); } @computed get topMost() { return this.props.renderDepth === 0; } - @computed get nativeWidth() { return this.layoutDoc.nativeWidth || 0; } - @computed get nativeHeight() { return this.layoutDoc.nativeHeight || 0; } + @computed get nativeWidth() { return this.layoutDoc._nativeWidth || 0; } + @computed get nativeHeight() { return this.layoutDoc._nativeHeight || 0; } @computed get onClickHandler() { return this.props.onClick ? this.props.onClick : this.Document.onClick; } @computed get onPointerDownHandler() { return this.props.onPointerDown ? this.props.onPointerDown : this.Document.onPointerDown; } @computed get onPointerUpHandler() { return this.props.onPointerUp ? this.props.onPointerUp : this.Document.onPointerUp; } @@ -261,14 +260,14 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu let preventDefault = true; if (this._doubleTap && this.props.renderDepth && !this.onClickHandler?.script) { // disable double-click to show full screen for things that have an on click behavior since clicking them twice can be misinterpreted as a double click const fullScreenAlias = Doc.MakeAlias(this.props.Document); - if (StrCast(fullScreenAlias.layoutKey) !== "layoutCustom" && fullScreenAlias.layoutCustom !== undefined) { - fullScreenAlias.layoutKey = "layoutCustom"; + if (StrCast(fullScreenAlias.layoutKey) !== "layout_custom" && fullScreenAlias.layout_custom !== undefined) { + fullScreenAlias.layoutKey = "layout_custom"; } this.props.addDocTab(fullScreenAlias, undefined, "inTab"); SelectionManager.DeselectAll(); Doc.UnBrushDoc(this.props.Document); } else if (this.onClickHandler && this.onClickHandler.script) { - this.onClickHandler.script.run({ this: this.Document.isTemplateField && this.props.DataDoc ? this.props.DataDoc : this.props.Document }, console.log); + this.onClickHandler.script.run({ this: this.Document.isTemplateForField && this.props.DataDoc ? this.props.DataDoc : this.props.Document, containingCollection: this.props.ContainingCollectionDoc }, console.log); } else if (this.Document.type === DocumentType.BUTTON) { ScriptBox.EditButtonScript("On Button Clicked ...", this.props.Document, "onClick", e.clientX, e.clientY); } else if (this.props.Document.isButton === "Selector") { // this should be moved to an OnClick script @@ -347,7 +346,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu if (Math.abs(this._downX - touch.clientX) > 3 || Math.abs(this._downY - touch.clientY) > 3) { if (!e.altKey && (!this.topMost || this.Document.onDragStart || this.Document.onClick)) { this.cleanUpInteractions(); - this.startDragging(this._downX, this._downY, this.Document.dropAction ? this.Document.dropAction as any : e.ctrlKey || e.altKey ? "alias" : undefined, this._hitTemplateDrag); + this.startDragging(this._downX, this._downY, this.Document._dropAction ? this.Document._dropAction as any : e.ctrlKey || e.altKey ? "alias" : undefined, this._hitTemplateDrag); } } e.stopPropagation(); // doesn't actually stop propagation since all our listeners are listening to events on 'document' however it does mark the event as cancelBubble=true which we test for in the move event handlers @@ -391,10 +390,10 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu if (dX !== 0 || dY !== 0 || dW !== 0 || dH !== 0) { const doc = PositionDocument(this.props.Document); const layoutDoc = PositionDocument(Doc.Layout(this.props.Document)); - let nwidth = layoutDoc.nativeWidth || 0; - let nheight = layoutDoc.nativeHeight || 0; - const width = (layoutDoc.width || 0); - const height = (layoutDoc.height || (nheight / nwidth * width)); + let nwidth = layoutDoc._nativeWidth || 0; + let nheight = layoutDoc._nativeHeight || 0; + const width = (layoutDoc._width || 0); + const height = (layoutDoc._height || (nheight / nwidth * width)); const scale = this.props.ScreenToLocalTransform().Scale * this.props.ContentScaling(); const actualdW = Math.max(width + (dW * scale), 20); const actualdH = Math.max(height + (dH * scale), 20); @@ -404,34 +403,34 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu if (fixedAspect && e.ctrlKey && layoutDoc.ignoreAspect) { layoutDoc.ignoreAspect = false; - layoutDoc.nativeWidth = nwidth = layoutDoc.width || 0; - layoutDoc.nativeHeight = nheight = layoutDoc.height || 0; + layoutDoc._nativeWidth = nwidth = layoutDoc._width || 0; + layoutDoc._nativeHeight = nheight = layoutDoc._height || 0; } if (fixedAspect && (!nwidth || !nheight)) { - layoutDoc.nativeWidth = nwidth = layoutDoc.width || 0; - layoutDoc.nativeHeight = nheight = layoutDoc.height || 0; + layoutDoc._nativeWidth = nwidth = layoutDoc._width || 0; + layoutDoc._nativeHeight = nheight = layoutDoc._height || 0; } if (nwidth > 0 && nheight > 0 && !layoutDoc.ignoreAspect) { if (Math.abs(dW) > Math.abs(dH)) { if (!fixedAspect) { - layoutDoc.nativeWidth = actualdW / (layoutDoc.width || 1) * (layoutDoc.nativeWidth || 0); + layoutDoc._nativeWidth = actualdW / (layoutDoc._width || 1) * (layoutDoc._nativeWidth || 0); } - layoutDoc.width = actualdW; - if (fixedAspect && !layoutDoc.fitWidth) layoutDoc.height = nheight / nwidth * layoutDoc.width; - else layoutDoc.height = actualdH; + layoutDoc._width = actualdW; + if (fixedAspect && !layoutDoc._fitWidth) layoutDoc._height = nheight / nwidth * layoutDoc._width; + else layoutDoc._height = actualdH; } else { if (!fixedAspect) { - layoutDoc.nativeHeight = actualdH / (layoutDoc.height || 1) * (doc.nativeHeight || 0); + layoutDoc._nativeHeight = actualdH / (layoutDoc._height || 1) * (doc._nativeHeight || 0); } - layoutDoc.height = actualdH; - if (fixedAspect && !layoutDoc.fitWidth) layoutDoc.width = nwidth / nheight * layoutDoc.height; - else layoutDoc.width = actualdW; + layoutDoc._height = actualdH; + if (fixedAspect && !layoutDoc._fitWidth) layoutDoc._width = nwidth / nheight * layoutDoc._height; + else layoutDoc._width = actualdW; } } else { - dW && (layoutDoc.width = actualdW); - dH && (layoutDoc.height = actualdH); - dH && layoutDoc.autoHeight && (layoutDoc.autoHeight = false); + dW && (layoutDoc._width = actualdW); + dH && (layoutDoc._height = actualdH); + dH && layoutDoc._autoHeight && (layoutDoc._autoHeight = false); } } e.stopPropagation(); @@ -441,7 +440,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu onPointerDown = (e: React.PointerEvent): void => { if (this.onPointerDownHandler && this.onPointerDownHandler.script) { - this.onPointerDownHandler.script.run({ this: this.Document.isTemplateField && this.props.DataDoc ? this.props.DataDoc : this.props.Document }, console.log); + this.onPointerDownHandler.script.run({ this: this.Document.isTemplateForField && this.props.DataDoc ? this.props.DataDoc : this.props.Document }, console.log); document.removeEventListener("pointerup", this.onPointerUp); document.addEventListener("pointerup", this.onPointerUp); return; @@ -488,7 +487,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu if (!e.altKey && (!this.topMost || this.Document.onDragStart || this.Document.onClick) && (e.buttons === 1 || InteractionUtils.IsType(e, InteractionUtils.TOUCHTYPE))) { document.removeEventListener("pointermove", this.onPointerMove); document.removeEventListener("pointerup", this.onPointerUp); - this.startDragging(this._downX, this._downY, this.Document.dropAction ? this.Document.dropAction as any : e.ctrlKey || e.altKey ? "alias" : undefined, this._hitTemplateDrag); + this.startDragging(this._downX, this._downY, this.Document._dropAction ? this.Document._dropAction as any : e.ctrlKey || e.altKey ? "alias" : undefined, this._hitTemplateDrag); } } e.stopPropagation(); // doesn't actually stop propagation since all our listeners are listening to events on 'document' however it does mark the event as cancelBubble=true which we test for in the move event handlers @@ -498,7 +497,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu onPointerUp = (e: PointerEvent): void => { if (this.onPointerUpHandler && this.onPointerUpHandler.script && !InteractionUtils.IsType(e, InteractionUtils.PENTYPE)) { - this.onPointerUpHandler.script.run({ this: this.Document.isTemplateField && this.props.DataDoc ? this.props.DataDoc : this.props.Document }, console.log); + this.onPointerUpHandler.script.run({ this: this.Document.isTemplateForField && this.props.DataDoc ? this.props.DataDoc : this.props.Document }, console.log); document.removeEventListener("pointerup", this.onPointerUp); return; } @@ -520,45 +519,48 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu @undoBatch deleteClicked = (): void => { SelectionManager.DeselectAll(); this.props.removeDocument && this.props.removeDocument(this.props.Document); } - static makeNativeViewClicked = (doc: Doc) => { - undoBatch(() => doc.layoutKey = "layout")(); + static makeNativeViewClicked = (doc: Doc, prevLayout: string) => { + undoBatch(() => { + if (StrCast(doc.title).endsWith("_" + prevLayout)) doc.title = StrCast(doc.title).replace("_" + prevLayout, ""); + doc.layoutKey = "layout"; + })(); } - static makeCustomViewClicked = (doc: Doc, dataDoc: Opt<Doc>) => { + static makeCustomViewClicked = (doc: Doc, dataDoc: Opt<Doc>, creator: (documents: Array<Doc>, options: DocumentOptions, id?: string) => Doc, name: string = "custom", docLayoutTemplate?: Doc) => { const batch = UndoManager.StartBatch("CustomViewClicked"); - if (doc.layoutCustom === undefined) { - const width = NumCast(doc.width); - const height = NumCast(doc.height); - const options = { title: "data", width, x: -width / 2, y: - height / 2, }; - - let fieldTemplate: Doc; - switch (doc.type) { - case DocumentType.TEXT: - fieldTemplate = Docs.Create.TextDocument(options); - break; - case DocumentType.PDF: - fieldTemplate = Docs.Create.PdfDocument("http://www.msn.com", options); - break; - case DocumentType.VID: - fieldTemplate = Docs.Create.VideoDocument("http://www.cs.brown.edu", options); - break; - case DocumentType.AUDIO: - fieldTemplate = Docs.Create.AudioDocument("http://www.cs.brown.edu", options); - break; - default: - fieldTemplate = Docs.Create.ImageDocument("http://www.cs.brown.edu", options); + const customName = "layout_" + name; + if (!StrCast(doc.title).endsWith(name)) doc.title = doc.title + "_" + name; + if (doc[customName] === undefined) { + const _width = NumCast(doc._width); + const _height = NumCast(doc._height); + const options = { title: "data", _width, x: -_width / 2, y: - _height / 2, }; + + const field = doc.data; + let fieldTemplate: Opt<Doc>; + if (field instanceof RichTextField || typeof (field) === "string") { + fieldTemplate = Docs.Create.TextDocument("", options); + } else if (field instanceof PdfField) { + fieldTemplate = Docs.Create.PdfDocument("http://www.msn.com", options); + } else if (field instanceof VideoField) { + fieldTemplate = Docs.Create.VideoDocument("http://www.cs.brown.edu", options); + } else if (field instanceof AudioField) { + fieldTemplate = Docs.Create.AudioDocument("http://www.cs.brown.edu", options); + } else if (field instanceof ImageField) { + fieldTemplate = Docs.Create.ImageDocument("http://www.cs.brown.edu", options); } - fieldTemplate.backgroundColor = doc.backgroundColor; - fieldTemplate.heading = 1; - fieldTemplate.autoHeight = true; + if (fieldTemplate) { + fieldTemplate.backgroundColor = doc.backgroundColor; + fieldTemplate.heading = 1; + fieldTemplate._autoHeight = true; + } - const docTemplate = Docs.Create.FreeformDocument([fieldTemplate], { title: doc.title + "_layout", width: width + 20, height: Math.max(100, height + 45) }); + const docTemplate = docLayoutTemplate || creator(fieldTemplate ? [fieldTemplate] : [], { title: customName + "(" + doc.title + ")", isTemplateDoc: true, _width: _width + 20, _height: Math.max(100, _height + 45) }); - Doc.MakeMetadataFieldTemplate(fieldTemplate, Doc.GetProto(docTemplate), true); - Doc.ApplyTemplateTo(docTemplate, dataDoc || doc, "layoutCustom", undefined); + fieldTemplate && Doc.MakeMetadataFieldTemplate(fieldTemplate, Doc.GetProto(docTemplate)); + Doc.ApplyTemplateTo(docTemplate, dataDoc || doc, customName, undefined); } else { - doc.layoutKey = "layoutCustom"; + doc.layoutKey = customName; } batch.end(); } @@ -597,7 +599,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu `Link from ${StrCast(de.complete.annoDragData.annotationDocument.title)}`); } if (de.complete.docDragData && de.complete.docDragData.applyAsTemplate) { - Doc.ApplyTemplateTo(de.complete.docDragData.draggedDocuments[0], this.props.Document, "layoutCustom"); + Doc.ApplyTemplateTo(de.complete.docDragData.draggedDocuments[0], this.props.Document, "layout_custom"); e.stopPropagation(); } if (de.complete.linkDragData) { @@ -624,11 +626,11 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu @undoBatch @action freezeNativeDimensions = (): void => { - this.layoutDoc.autoHeight = this.layoutDoc.autoHeight = false; + this.layoutDoc._autoHeight = false; this.layoutDoc.ignoreAspect = !this.layoutDoc.ignoreAspect; - if (!this.layoutDoc.ignoreAspect && !this.layoutDoc.nativeWidth) { - this.layoutDoc.nativeWidth = this.props.PanelWidth(); - this.layoutDoc.nativeHeight = this.props.PanelHeight(); + if (!this.layoutDoc.ignoreAspect && !this.layoutDoc._nativeWidth) { + this.layoutDoc._nativeWidth = this.props.PanelWidth(); + this.layoutDoc._nativeHeight = this.props.PanelHeight(); } } @@ -639,7 +641,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu if (!anchors.find(anchor2 => anchor2 && anchor2.title === this.Document.title + ".portal" ? true : false)) { const portalID = (this.Document.title + ".portal").replace(/^-/, "").replace(/\([0-9]*\)$/, ""); DocServer.GetRefField(portalID).then(existingPortal => { - const portal = existingPortal instanceof Doc ? existingPortal : Docs.Create.FreeformDocument([], { width: (this.layoutDoc.width || 0) + 10, height: this.layoutDoc.height || 0, title: portalID }); + const portal = existingPortal instanceof Doc ? existingPortal : Docs.Create.FreeformDocument([], { _width: (this.layoutDoc._width || 0) + 10, _height: this.layoutDoc._height || 0, title: portalID }); DocUtils.MakeLink({ doc: this.props.Document, ctx: this.props.ContainingCollectionDoc }, { doc: portal }, portalID, "portal link"); this.Document.isButton = true; }); @@ -648,27 +650,25 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu @undoBatch @action - setNarrativeView = (custom: boolean): void => { - if (custom) { - this.props.Document.layout_narrative = CollectionView.LayoutString("narrative"); - this.props.Document.nativeWidth = this.props.Document.nativeHeight = undefined; - !this.props.Document.narrative && (Doc.GetProto(this.props.Document).narrative = new List<Doc>([])); - this.props.Document.viewType = CollectionViewType.Stacking; - this.props.Document.layoutKey = "layout_narrative"; - } else { - DocumentView.makeNativeViewClicked(this.props.Document); - } - } - - @undoBatch - @action - setCustomView = (custom: boolean): void => { - if (this.props.ContainingCollectionView?.props.DataDoc || this.props.ContainingCollectionView?.props.Document.isTemplateDoc) { - Doc.MakeMetadataFieldTemplate(this.props.Document, this.props.ContainingCollectionView.props.Document); - } else { - custom ? DocumentView.makeCustomViewClicked(this.props.Document, this.props.DataDoc) : DocumentView.makeNativeViewClicked(this.props.Document); + setCustomView = + (custom: boolean, layout: string): void => { + if (this.props.ContainingCollectionView?.props.DataDoc || this.props.ContainingCollectionView?.props.Document.isTemplateDoc) { + Doc.MakeMetadataFieldTemplate(this.props.Document, this.props.ContainingCollectionView.props.Document); + } else if (custom) { + DocumentView.makeNativeViewClicked(this.props.Document, StrCast(this.props.Document.layoutKey).split("_")[1]); + + let foundLayout: Opt<Doc> = undefined; + DocListCast(Cast(CurrentUserUtils.UserDocument.expandingButtons, Doc, null)?.data)?.map(btnDoc => { + if (StrCast(Cast(btnDoc?.dragFactory, Doc, null)?.title) === layout) { + foundLayout = btnDoc.dragFactory as Doc; + } + }) + DocumentView. + makeCustomViewClicked(this.props.Document, this.props.DataDoc, Docs.Create.StackingDocument, layout, foundLayout); + } else { + DocumentView.makeNativeViewClicked(this.props.Document, StrCast(this.props.Document.layoutKey).split("_")[1]); + } } - } @undoBatch @action @@ -712,7 +712,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu subitems.push({ description: "Open Right ", event: () => this.props.addDocTab(this.props.Document, this.props.DataDoc, "onRight", this.props.LibraryPath), icon: "caret-square-right" }); subitems.push({ description: "Open Alias Tab ", event: () => this.props.addDocTab(Doc.MakeAlias(this.props.Document), this.props.DataDoc, "inTab"), icon: "folder" }); subitems.push({ description: "Open Alias Right", event: () => this.props.addDocTab(Doc.MakeAlias(this.props.Document), this.props.DataDoc, "onRight"), icon: "caret-square-right" }); - subitems.push({ description: "Open Fields ", event: () => this.props.addDocTab(Docs.Create.KVPDocument(this.props.Document, { width: 300, height: 300 }), undefined, "onRight"), icon: "layer-group" }); + subitems.push({ description: "Open Fields ", event: () => this.props.addDocTab(Docs.Create.KVPDocument(this.props.Document, { _width: 300, _height: 300 }), undefined, "onRight"), icon: "layer-group" }); cm.addItem({ description: "Open...", subitems: subitems, icon: "external-link-alt" }); @@ -737,21 +737,15 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu const existing = ContextMenu.Instance.findByDescription("Layout..."); const layoutItems: ContextMenuProps[] = existing && "subitems" in existing ? existing.subitems : []; layoutItems.push({ description: this.Document.isBackground ? "As Foreground" : "As Background", event: this.makeBackground, icon: this.Document.lockedPosition ? "unlock" : "lock" }); - if (this.props.DataDoc) { - layoutItems.push({ description: "Make View of Metadata Field", event: () => Doc.MakeMetadataFieldTemplate(this.props.Document, this.props.DataDoc!), icon: "concierge-bell" }); - } - layoutItems.push({ description: `${this.Document.chromeStatus !== "disabled" ? "Hide" : "Show"} Chrome`, event: () => this.Document.chromeStatus = (this.Document.chromeStatus !== "disabled" ? "disabled" : "enabled"), icon: "project-diagram" }); - layoutItems.push({ description: `${this.Document.autoHeight ? "Variable Height" : "Auto Height"}`, event: () => this.layoutDoc.autoHeight = !this.layoutDoc.autoHeight, icon: "plus" }); - layoutItems.push({ description: this.Document.ignoreAspect || !this.Document.nativeWidth || !this.Document.nativeHeight ? "Freeze" : "Unfreeze", event: this.freezeNativeDimensions, icon: "snowflake" }); + layoutItems.push({ description: "Make View of Metadata Field", event: () => Doc.MakeMetadataFieldTemplate(this.props.Document, this.props.DataDoc), icon: "concierge-bell" }); + + layoutItems.push({ description: `${this.Document._chromeStatus !== "disabled" ? "Hide" : "Show"} Chrome`, event: () => this.Document._chromeStatus = (this.Document._chromeStatus !== "disabled" ? "disabled" : "enabled"), icon: "project-diagram" }); + layoutItems.push({ description: `${this.Document._autoHeight ? "Variable Height" : "Auto Height"}`, event: () => this.layoutDoc._autoHeight = !this.layoutDoc._autoHeight, icon: "plus" }); + layoutItems.push({ description: this.Document.ignoreAspect || !this.Document._nativeWidth || !this.Document._nativeHeight ? "Freeze" : "Unfreeze", event: this.freezeNativeDimensions, icon: "snowflake" }); layoutItems.push({ description: this.Document.lockedPosition ? "Unlock Position" : "Lock Position", event: this.toggleLockPosition, icon: BoolCast(this.Document.lockedPosition) ? "unlock" : "lock" }); layoutItems.push({ description: this.Document.lockedTransform ? "Unlock Transform" : "Lock Transform", event: this.toggleLockTransform, icon: BoolCast(this.Document.lockedTransform) ? "unlock" : "lock" }); layoutItems.push({ description: "Center View", event: () => this.props.focus(this.props.Document, false), icon: "crosshairs" }); layoutItems.push({ description: "Zoom to Document", event: () => this.props.focus(this.props.Document, true), icon: "search" }); - if (this.Document.type !== DocumentType.COL && this.Document.type !== DocumentType.TEMPLATE) { - layoutItems.push({ description: "Use Custom Layout", event: () => DocumentView.makeCustomViewClicked(this.props.Document, this.props.DataDoc), icon: "concierge-bell" }); - } else { - layoutItems.push({ description: "Use Native Layout", event: () => DocumentView.makeNativeViewClicked(this.props.Document), icon: "concierge-bell" }); - } !existing && cm.addItem({ description: "Layout...", subitems: layoutItems, icon: "compass" }); const more = ContextMenu.Instance.findByDescription("More..."); @@ -796,13 +790,13 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu const mode2 = mode === DocServer.WriteMode.Default ? mode : DocServer.WriteMode.Playground; DocServer.setFieldWriteMode("x", mode1); DocServer.setFieldWriteMode("y", mode1); - DocServer.setFieldWriteMode("width", mode1); - DocServer.setFieldWriteMode("height", mode1); + DocServer.setFieldWriteMode("_width", mode1); + DocServer.setFieldWriteMode("_height", mode1); - DocServer.setFieldWriteMode("panX", mode2); - DocServer.setFieldWriteMode("panY", mode2); + DocServer.setFieldWriteMode("_panX", mode2); + DocServer.setFieldWriteMode("_panY", mode2); DocServer.setFieldWriteMode("scale", mode2); - DocServer.setFieldWriteMode("viewType", mode2); + DocServer.setFieldWriteMode("_viewType", mode2); }; const aclsMenu: ContextMenuProps[] = []; aclsMenu.push({ description: "Default (write/read all)", event: () => setWriteMode(DocServer.WriteMode.Default), icon: DocServer.AclsMode === DocServer.WriteMode.Default ? "check" : "exclamation" }); @@ -847,14 +841,20 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu select = (ctrlPressed: boolean) => { SelectionManager.SelectDoc(this, ctrlPressed); }; chromeHeight = () => { - const showOverlays = this.props.showOverlays ? this.props.showOverlays(this.Document) : undefined; - const showTitle = showOverlays && "title" in showOverlays ? showOverlays.title : StrCast(this.layoutDoc.showTitle); - const showTitleHover = showOverlays && "titleHover" in showOverlays ? showOverlays.titleHover : StrCast(this.layoutDoc.showTitleHover); + const showTitle = StrCast(this.layoutDoc.showTitle); + const showTitleHover = StrCast(this.layoutDoc.showTitleHover); return (showTitle && !showTitleHover ? 0 : 0) + 1; } - @computed get finalLayoutKey() { return this.props.layoutKey || "layout"; } - childScaling = () => (this.layoutDoc.fitWidth ? this.props.PanelWidth() / this.nativeWidth : this.props.ContentScaling()); + @computed get finalLayoutKey() { + const { layoutKey } = this.props; + if (typeof layoutKey === "string") { + return layoutKey; + } + const fallback = Cast(this.props.Document.layoutKey, "string"); + return typeof fallback === "string" ? fallback : "layout"; + } + childScaling = () => (this.layoutDoc._fitWidth ? this.props.PanelWidth() / this.nativeWidth : this.props.ContentScaling()); @computed get contents() { TraceMobx(); return (<DocumentContentsView ContainingCollectionView={this.props.ContainingCollectionView} @@ -868,9 +868,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu moveDocument={this.props.moveDocument} ScreenToLocalTransform={this.props.ScreenToLocalTransform} renderDepth={this.props.renderDepth} - showOverlays={this.props.showOverlays} ContentScaling={this.childScaling} - ruleProvider={this.props.ruleProvider} PanelWidth={this.props.PanelWidth} PanelHeight={this.props.PanelHeight} focus={this.props.focus} @@ -902,10 +900,9 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu @computed get innards() { TraceMobx(); - const showOverlays = this.props.showOverlays ? this.props.showOverlays(this.Document) : undefined; - const showTitle = showOverlays && "title" in showOverlays ? showOverlays.title : StrCast(this.getLayoutPropStr("showTitle")); - const showTitleHover = showOverlays && "titleHover" in showOverlays ? showOverlays.titleHover : StrCast(this.getLayoutPropStr("showTitleHover")); - const showCaption = showOverlays && "caption" in showOverlays ? showOverlays.caption : this.getLayoutPropStr("showCaption"); + const showTitle = StrCast(this.getLayoutPropStr("showTitle")); + const showTitleHover = StrCast(this.getLayoutPropStr("showTitleHover")); + const showCaption = this.getLayoutPropStr("showCaption"); const showTextTitle = showTitle && StrCast(this.layoutDoc.layout).indexOf("FormattedTextBox") !== -1 ? showTitle : undefined; const searchHighlight = (!this.Document.searchFields ? (null) : <div className="documentView-searchHighlight"> @@ -925,9 +922,9 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu pointerEvents: SelectionManager.GetIsDragging() ? "none" : "all", }}> <EditableView ref={this._titleRef} - contents={(this.props.DataDoc || this.props.Document)[showTitle]} + contents={(this.props.DataDoc || this.props.Document)[showTitle]?.toString()} display={"block"} height={72} fontSize={12} - GetValue={() => StrCast((this.props.DataDoc || this.props.Document)[showTitle])} + GetValue={() => (this.props.DataDoc || this.props.Document)[showTitle]?.toString()} SetValue={undoBatch((value: string) => (Doc.GetProto(this.props.DataDoc || this.props.Document)[showTitle] = value) ? true : true)} /> </div>); @@ -962,16 +959,14 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu render() { if (!(this.props.Document instanceof Doc)) return (null); - const ruleColor = this.props.ruleProvider ? StrCast(this.props.ruleProvider["ruleColor_" + this.Document.heading]) : undefined; - const ruleRounding = this.props.ruleProvider ? StrCast(this.props.ruleProvider["ruleRounding_" + this.Document.heading]) : undefined; const colorSet = this.setsLayoutProp("backgroundColor"); const clusterCol = this.props.ContainingCollectionDoc && this.props.ContainingCollectionDoc.clusterOverridesDefaultBackground; const backgroundColor = (clusterCol && !colorSet) ? this.props.backgroundColor(this.Document) || StrCast(this.layoutDoc.backgroundColor) : - ruleColor && !colorSet ? ruleColor : StrCast(this.layoutDoc.backgroundColor) || this.props.backgroundColor(this.Document); + StrCast(this.layoutDoc.backgroundColor) || this.props.backgroundColor(this.Document); const fullDegree = Doc.isBrushedHighlightedDegree(this.props.Document); - const borderRounding = this.getLayoutPropStr("borderRounding") || ruleRounding; + const borderRounding = this.getLayoutPropStr("borderRounding"); const localScale = fullDegree; const animDims = this.Document.animateToDimensions ? Array.from(this.Document.animateToDimensions) : undefined; @@ -980,7 +975,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu const highlightColors = ["transparent", "maroon", "maroon", "yellow", "magenta", "cyan", "orange"]; const highlightStyles = ["solid", "dashed", "solid", "solid", "solid", "solid", "solid"]; - let highlighting = fullDegree && this.layoutDoc.type !== DocumentType.FONTICON && this.layoutDoc.viewType !== CollectionViewType.Linear; + let highlighting = fullDegree && this.layoutDoc.type !== DocumentType.FONTICON && this.layoutDoc._viewType !== CollectionViewType.Linear; highlighting = highlighting && this.props.focus !== emptyFunction; // bcz: hack to turn off highlighting onsidebar panel documents. need to flag a document as not highlightable in a more direct way return <div className={`documentView-node${this.topMost ? "-topmost" : ""}`} ref={this._mainCont} onKeyDown={this.onKeyDown} onDrop={this.onDrop} onContextMenu={this.onContextMenu} onPointerDown={this.onPointerDown} onClick={this.onClick} @@ -991,7 +986,8 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu color: StrCast(this.Document.color), outline: highlighting && !borderRounding ? `${highlightColors[fullDegree]} ${highlightStyles[fullDegree]} ${localScale}px` : "solid 0px", border: highlighting && borderRounding ? `${highlightStyles[fullDegree]} ${highlightColors[fullDegree]} ${localScale}px` : undefined, - background: this.layoutDoc.type === DocumentType.FONTICON || this.layoutDoc.viewType === CollectionViewType.Linear ? undefined : backgroundColor, + boxShadow: this.props.Document.isTemplateForField ? "black 0.2vw 0.2vw 0.8vw" : undefined, + background: this.layoutDoc.type === DocumentType.FONTICON || this.layoutDoc._viewType === CollectionViewType.Linear ? undefined : backgroundColor, width: animwidth, height: animheight, opacity: this.Document.opacity @@ -1001,4 +997,4 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu } } -Scripting.addGlobal(function toggleDetail(doc: any) { doc.layoutKey = StrCast(doc.layoutKey, "layout") === "layout" ? "layoutCustom" : "layout"; });
\ No newline at end of file +Scripting.addGlobal(function toggleDetail(doc: any) { doc.layoutKey = StrCast(doc.layoutKey, "layout") === "layout" ? "layout_custom" : "layout"; });
\ No newline at end of file diff --git a/src/client/views/nodes/FieldView.tsx b/src/client/views/nodes/FieldView.tsx index 6e6ee1712..dbbb76f83 100644 --- a/src/client/views/nodes/FieldView.tsx +++ b/src/client/views/nodes/FieldView.tsx @@ -27,7 +27,6 @@ export interface FieldViewProps { fitToBox?: boolean; ContainingCollectionView: Opt<CollectionView>; ContainingCollectionDoc: Opt<Doc>; - ruleProvider: Doc | undefined; Document: Doc; DataDoc?: Doc; LibraryPath: Doc[]; @@ -70,12 +69,12 @@ export class FieldView extends React.Component<FieldViewProps> { // if (typeof field === "string") { // return <p>{field}</p>; // } - else if (field instanceof RichTextField) { - return <FormattedTextBox {...this.props} />; - } - else if (field instanceof ImageField) { - return <ImageBox {...this.props} />; - } + // else if (field instanceof RichTextField) { + // return <FormattedTextBox {...this.props} />; + // } + // else if (field instanceof ImageField) { + // return <ImageBox {...this.props} />; + // } // else if (field instaceof PresBox) { // return <PresBox {...this.props} />; // } diff --git a/src/client/views/nodes/FontIconBox.tsx b/src/client/views/nodes/FontIconBox.tsx index 2433251b3..a191ac4f4 100644 --- a/src/client/views/nodes/FontIconBox.tsx +++ b/src/client/views/nodes/FontIconBox.tsx @@ -5,10 +5,11 @@ import { createSchema, makeInterface } from '../../../new_fields/Schema'; import { DocComponent } from '../DocComponent'; import './FontIconBox.scss'; import { FieldView, FieldViewProps } from './FieldView'; -import { StrCast } from '../../../new_fields/Types'; +import { StrCast, Cast } from '../../../new_fields/Types'; import { Utils } from "../../../Utils"; import { runInAction, observable, reaction, IReactionDisposer } from 'mobx'; import { Doc } from '../../../new_fields/Doc'; +import { ContextMenu } from '../ContextMenu'; const FontIconSchema = createSchema({ icon: "string" }); @@ -32,13 +33,25 @@ export class FontIconBox extends DocComponent<FieldViewProps, FontIconDocument>( } }, { fireImmediately: true }); } + + showTemplate = (): void => { + const dragFactory = Cast(this.props.Document.dragFactory, Doc, null); + dragFactory && this.props.addDocTab(dragFactory, undefined, "onRight"); + } + + specificContextMenu = (): void => { + const cm = ContextMenu.Instance; + cm.addItem({ description: "Show Template", event: this.showTemplate, icon: "tag" }); + } + componentWillUnmount() { - this._backgroundReaction && this._backgroundReaction(); + this._backgroundReaction?.(); } + render() { const referenceDoc = (this.props.Document.dragFactory instanceof Doc ? this.props.Document.dragFactory : this.props.Document); const referenceLayout = Doc.Layout(referenceDoc); - return <button className="fontIconBox-outerDiv" title={StrCast(this.props.Document.title)} ref={this._ref} + return <button className="fontIconBox-outerDiv" title={StrCast(this.props.Document.title)} ref={this._ref} onContextMenu={this.specificContextMenu} style={{ background: StrCast(referenceLayout.backgroundColor), boxShadow: this.props.Document.ischecked ? `4px 4px 12px black` : undefined diff --git a/src/client/views/nodes/FormattedTextBox.tsx b/src/client/views/nodes/FormattedTextBox.tsx index 60842bcb0..0d97c3029 100644 --- a/src/client/views/nodes/FormattedTextBox.tsx +++ b/src/client/views/nodes/FormattedTextBox.tsx @@ -1,7 +1,7 @@ import { library } from '@fortawesome/fontawesome-svg-core'; import { faEdit, faSmile, faTextHeight, faUpload } from '@fortawesome/free-solid-svg-icons'; import { isEqual } from "lodash"; -import { action, computed, IReactionDisposer, Lambda, observable, reaction, runInAction, trace } from "mobx"; +import { action, computed, IReactionDisposer, Lambda, observable, reaction, runInAction, trace, _allowStateChangesInsideComputed } from "mobx"; import { observer } from "mobx-react"; import { baseKeymap } from "prosemirror-commands"; import { history } from "prosemirror-history"; @@ -12,7 +12,7 @@ import { EditorState, NodeSelection, Plugin, TextSelection, Transaction } from " import { ReplaceStep } from 'prosemirror-transform'; import { EditorView } from "prosemirror-view"; import { DateField } from '../../../new_fields/DateField'; -import { Doc, DocListCastAsync, Opt, WidthSym, HeightSym } from "../../../new_fields/Doc"; +import { Doc, DocListCastAsync, Opt, WidthSym, HeightSym, DataSym, Field } from "../../../new_fields/Doc"; import { Copy, Id } from '../../../new_fields/FieldSymbols'; import { RichTextField } from "../../../new_fields/RichTextField"; import { RichTextUtils } from '../../../new_fields/RichTextUtils'; @@ -27,12 +27,10 @@ import { DictationManager } from '../../util/DictationManager'; import { DragManager } from "../../util/DragManager"; import buildKeymap from "../../util/ProsemirrorExampleTransfer"; import { inpRules } from "../../util/RichTextRules"; -import { DashDocCommentView, FootnoteView, ImageResizeView, DashDocView, OrderedListView, schema, SummaryView } from "../../util/RichTextSchema"; +import { DashDocCommentView, FootnoteView, ImageResizeView, DashDocView, OrderedListView, schema, SummaryView, DashFieldView } from "../../util/RichTextSchema"; import { SelectionManager } from "../../util/SelectionManager"; -import { TooltipLinkingMenu } from "../../util/TooltipLinkingMenu"; -import { TooltipTextMenu } from "../../util/TooltipTextMenu"; import { undoBatch, UndoManager } from "../../util/UndoManager"; -import { DocAnnotatableComponent } from "../DocComponent"; +import { DocAnnotatableComponent, DocAnnotatableProps } from "../DocComponent"; import { DocumentButtonBar } from '../DocumentButtonBar'; import { InkingControl } from "../InkingControl"; import { FieldView, FieldViewProps } from "./FieldView"; @@ -48,17 +46,12 @@ import { CollectionFreeFormView } from '../collections/collectionFreeForm/Collec import { InkTool } from '../../../new_fields/InkField'; import { TraceMobx } from '../../../new_fields/util'; import RichTextMenu from '../../util/RichTextMenu'; -import { DocumentDecorations } from '../DocumentDecorations'; library.add(faEdit); library.add(faSmile, faTextHeight, faUpload); export interface FormattedTextBoxProps { hideOnLeave?: boolean; - height?: string; - color?: string; - outer_div?: (domminus: HTMLElement) => void; - firstinstance?: boolean; } const richTextSchema = createSchema({ @@ -77,7 +70,6 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & public static LayoutString(fieldStr: string) { return FieldView.LayoutString(FormattedTextBox, fieldStr); } public static blankState = () => EditorState.create(FormattedTextBox.Instance.config); public static Instance: FormattedTextBox; - public static ToolTipTextMenu: TooltipTextMenu | undefined = undefined; public ProseRef?: HTMLDivElement; private _ref: React.RefObject<HTMLDivElement> = React.createRef(); private _scrollRef: React.RefObject<HTMLDivElement> = React.createRef(); @@ -92,16 +84,12 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & private _scrollToRegionReactionDisposer: Opt<IReactionDisposer>; private _reactionDisposer: Opt<IReactionDisposer>; private _heightReactionDisposer: Opt<IReactionDisposer>; - private _rulesReactionDisposer: Opt<IReactionDisposer>; private _proxyReactionDisposer: Opt<IReactionDisposer>; private _pullReactionDisposer: Opt<IReactionDisposer>; private _pushReactionDisposer: Opt<IReactionDisposer>; private _buttonBarReactionDisposer: Opt<IReactionDisposer>; private dropDisposer?: DragManager.DragDropDisposer; - @observable private _ruleFontSize = 0; - @observable private _ruleFontFamily = "Arial"; - @observable private _fontAlign = ""; @observable private _entered = false; public static FocusedBox: FormattedTextBox | undefined; @@ -127,10 +115,6 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & return ""; } - public static getToolTip(ev: EditorView) { - return this.ToolTipTextMenu ? this.ToolTipTextMenu : this.ToolTipTextMenu = new TooltipTextMenu(ev); - } - @undoBatch public setFontColor(color: string) { const view = this._editorView!; @@ -160,7 +144,7 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & const id = Utils.GenerateDeterministicGuid(this.dataDoc[Id] + key); DocServer.GetRefField(value).then(doc => { DocServer.GetRefField(id).then(linkDoc => { - this.dataDoc[key] = doc || Docs.Create.FreeformDocument([], { title: value, width: 500, height: 500 }, value); + this.dataDoc[key] = doc || Docs.Create.FreeformDocument([], { title: value, _width: 500, _height: 500 }, value); DocUtils.Publish(this.dataDoc[key] as Doc, value, this.props.addDocument, this.props.removeDocument); if (linkDoc) { (linkDoc as Doc).anchor2 = this.dataDoc[key] as Doc; } else DocUtils.MakeLink({ doc: this.dataDoc, ctx: this.props.ContainingCollectionDoc }, { doc: this.dataDoc[key] as Doc }, "Ref:" + value, "link to named target", id); @@ -201,9 +185,11 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & const tsel = this._editorView.state.selection.$from; tsel.marks().filter(m => m.type === this._editorView!.state.schema.marks.user_mark).map(m => AudioBox.SetScrubTime(Math.max(0, m.attrs.modified * 5000 - 1000))); this._applyingChange = true; - this.extensionDoc && !this.extensionDoc.lastModified && (this.extensionDoc.backgroundColor = "lightGray"); - this.extensionDoc && (this.extensionDoc.lastModified = new DateField(new Date(Date.now()))); - this.dataDoc[this.props.fieldKey] = new RichTextField(JSON.stringify(state.toJSON()), state.doc.textBetween(0, state.doc.content.size, "\n\n")); + if (!this.props.Document._textTemplate || Doc.GetProto(this.props.Document) === this.dataDoc) { + this.dataDoc[this.props.fieldKey + "-lastModified"] && (this.dataDoc[this.props.fieldKey + "-backgroundColor"] = "lightGray"); + this.dataDoc[this.props.fieldKey + "-lastModified"] = new DateField(new Date(Date.now())); + this.dataDoc[this.props.fieldKey] = new RichTextField(JSON.stringify(state.toJSON()), state.doc.textBetween(0, state.doc.content.size, "\n\n")); + } this._applyingChange = false; this.updateTitle(); this.tryUpdateHeight(); @@ -271,15 +257,15 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & newLayout = Doc.MakeDelegate(draggedDoc); newLayout.layout = StrCast(newLayout.layout).replace(/fieldKey={'[^']*'}/, `fieldKey={'${this.props.fieldKey}'}`); } - this.Document.layoutCustom = newLayout; - this.Document.layoutKey = "layoutCustom"; + this.Document.layout_custom = newLayout; + this.Document.layoutKey = "layout_custom"; e.stopPropagation(); // embed document when dragging with a userDropAction or an embedDoc flag set } else if (de.complete.docDragData.userDropAction || de.complete.docDragData.embedDoc) { const target = de.complete.docDragData.droppedDocuments[0]; // const link = DocUtils.MakeLink({ doc: this.dataDoc, ctx: this.props.ContainingCollectionDoc }, { doc: target }, "Embedded Doc:" + target.title); // if (link) { - target.fitToBox = true; + target._fitToBox = true; const node = schema.nodes.dashDoc.create({ width: target[WidthSym](), height: target[HeightSym](), title: "dashDoc", docid: target[Id], @@ -485,11 +471,10 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & schema, plugins: [ inputRules(inpRules), - this.tooltipTextMenuPlugin(), + this.richTextMenuPlugin(), history(), keymap(this._keymap), keymap(baseKeymap), - // this.tooltipLinkingMenuPlugin(), new Plugin({ props: { attributes: { class: "ProseMirror-example-setup-style" } @@ -513,7 +498,7 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & this._reactionDisposer = reaction( () => { - const field = this.dataDoc ? Cast(this.dataDoc[this.props.fieldKey], RichTextField) : undefined; + const field = Cast(this.props.Document._textTemplate || this.dataDoc[this.props.fieldKey], RichTextField); return field ? field.Data : RichTextUtils.Initialize(); }, incomingValue => { @@ -547,46 +532,16 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & ); this._heightReactionDisposer = reaction( - () => [this.layoutDoc[WidthSym](), this.layoutDoc.autoHeight], + () => [this.layoutDoc[WidthSym](), this.layoutDoc._autoHeight], () => this.tryUpdateHeight() ); - this.setupEditor(this.config, this.dataDoc, this.props.fieldKey); + this.setupEditor(this.config, this.props.fieldKey); this._searchReactionDisposer = reaction(() => this.layoutDoc.searchMatch, search => search ? this.highlightSearchTerms([Doc.SearchQuery()]) : this.unhighlightSearchTerms(), { fireImmediately: true }); - this._rulesReactionDisposer = reaction(() => { - const ruleProvider = this.props.ruleProvider; - const heading = NumCast(this.layoutDoc.heading); - if (ruleProvider instanceof Doc) { - return { - align: StrCast(ruleProvider["ruleAlign_" + heading], ""), - font: StrCast(ruleProvider["ruleFont_" + heading], "Arial"), - size: NumCast(ruleProvider["ruleSize_" + heading], 13) - }; - } - return undefined; - }, - action((rules: any) => { - this._ruleFontFamily = rules ? rules.font : "Arial"; - this._ruleFontSize = rules ? rules.size : 0; - rules && setTimeout(() => { - const view = this._editorView!; - if (this.ProseRef) { - const n = new NodeSelection(view.state.doc.resolve(0)); - if (this._editorView!.state.doc.textContent === "") { - view.dispatch(view.state.tr.setSelection(new TextSelection(view.state.doc.resolve(0), view.state.doc.resolve(2))). - replaceSelectionWith(this._editorView!.state.schema.nodes.paragraph.create({ align: rules.align }), true)); - } else if (n.node && n.node.type === view.state.schema.nodes.paragraph) { - view.dispatch(view.state.tr.setNodeMarkup(0, n.node.type, { ...n.node.attrs, align: rules.align })); - } - this.tryUpdateHeight(); - } - }, 0); - }), { fireImmediately: true } - ); this._scrollToRegionReactionDisposer = reaction( () => StrCast(this.layoutDoc.scrollToLinkID), async (scrollToLinkID) => { @@ -743,11 +698,9 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & DocServer.GetRefField(pdfRegionId).then(pdfRegion => { if ((pdfDoc instanceof Doc) && (pdfRegion instanceof Doc)) { setTimeout(async () => { - const extension = Doc.fieldExtensionDoc(pdfDoc, "data"); - if (extension) { - const targetAnnotations = await DocListCastAsync(extension.annotations);// bcz: NO... this assumes the pdf is using its 'data' field. need to have the PDF's view handle updating its own annotations - targetAnnotations && targetAnnotations.push(pdfRegion); - } + const targetField = Doc.LayoutFieldKey(pdfDoc); + const targetAnnotations = await DocListCastAsync(pdfDoc[DataSym][targetField + "-annotations"]);// bcz: better to have the PDF's view handle updating its own annotations + targetAnnotations?.push(pdfRegion); }); const link = DocUtils.MakeLink({ doc: this.props.Document, ctx: this.props.ContainingCollectionDoc }, { doc: pdfRegion, ctx: pdfDoc }, "note on " + pdfDoc.title, "pasted PDF link"); @@ -785,28 +738,18 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & } } - private setupEditor(config: any, doc: Doc, fieldKey: string) { - const field = doc ? Cast(doc[fieldKey], RichTextField) : undefined; - let startup = StrCast(doc.documentText); - startup = startup.startsWith("@@@") ? startup.replace("@@@", "") : ""; - if (!field && doc) { - const text = StrCast(doc[fieldKey]); - if (text) { - startup = text; - } else if (Cast(doc[fieldKey], "number")) { - startup = NumCast(doc[fieldKey], 99).toString(); - } - } + private setupEditor(config: any, fieldKey: string) { + const rtfField = Cast(this.props.Document._textTemplate || this.dataDoc[fieldKey], RichTextField); if (this.ProseRef) { const self = this; - this._editorView && this._editorView.destroy(); + this._editorView?.destroy(); this._editorView = new EditorView(this.ProseRef, { - state: field && field.Data ? EditorState.fromJSON(config, JSON.parse(field.Data)) : EditorState.create(config), + state: rtfField?.Data ? EditorState.fromJSON(config, JSON.parse(rtfField.Data)) : EditorState.create(config), handleScrollToSelection: (editorView) => { const ref = editorView.domAtPos(editorView.state.selection.from); let refNode = ref.node as any; while (refNode && !("getBoundingClientRect" in refNode)) refNode = refNode.parentElement; - const r1 = refNode && refNode.getBoundingClientRect(); + const r1 = refNode?.getBoundingClientRect(); const r3 = self._ref.current!.getBoundingClientRect(); if (r1.top < r3.top || r1.top > r3.bottom) { r1 && (self._scrollRef.current!.scrollTop += (r1.top - r3.top) * self.props.ScreenToLocalTransform().Scale); @@ -816,6 +759,7 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & dispatchTransaction: this.dispatchTransaction, nodeViews: { dashComment(node, view, getPos) { return new DashDocCommentView(node, view, getPos); }, + dashField(node, view, getPos) { return new DashFieldView(node, view, getPos, self); }, dashDoc(node, view, getPos) { return new DashDocView(node, view, getPos, self); }, image(node, view, getPos) { return new ImageResizeView(node, view, getPos, self.props.addDocTab); }, summary(node, view, getPos) { return new SummaryView(node, view, getPos); }, @@ -826,9 +770,9 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & handlePaste: this.handlePaste, }); this._editorView.state.schema.Document = this.props.Document; - if (startup && this._editorView) { - Doc.GetProto(doc).documentText = undefined; - this._editorView.dispatch(this._editorView.state.tr.insertText(startup)); + const startupText = !rtfField && this._editorView && Field.toString(this.dataDoc[fieldKey] as Field); + if (startupText) { + this._editorView.dispatch(this._editorView.state.tr.insertText(startupText)); } } @@ -837,8 +781,7 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & FormattedTextBox.SelectOnLoad = ""; this.props.select(false); } - const rtf = doc ? Cast(doc[fieldKey], RichTextField) : undefined; - (selectOnLoad || (rtf && !rtf.Text)) && this._editorView!.focus(); + (selectOnLoad /* || !rtfField?.Text*/) && this._editorView!.focus(); // add user mark for any first character that was typed since the user mark that gets set in KeyPress won't have been called yet. this._editorView!.state.storedMarks = [...(this._editorView!.state.storedMarks ? this._editorView!.state.storedMarks : []), schema.marks.user_mark.create({ userid: Doc.CurrentUserEmail, modified: Math.round(Date.now() / 1000 / 5) })]; } @@ -857,7 +800,6 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & componentWillUnmount() { this._scrollToRegionReactionDisposer && this._scrollToRegionReactionDisposer(); - this._rulesReactionDisposer && this._rulesReactionDisposer(); this._reactionDisposer && this._reactionDisposer(); this._proxyReactionDisposer && this._proxyReactionDisposer(); this._pushReactionDisposer && this._pushReactionDisposer(); @@ -1038,25 +980,16 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & } } - tooltipTextMenuPlugin() { + richTextMenuPlugin() { const self = FormattedTextBox; return new Plugin({ view(newView) { - // return self.ToolTipTextMenu = FormattedTextBox.getToolTip(newView); RichTextMenu.Instance.changeView(newView); return RichTextMenu.Instance; } }); } - tooltipLinkingMenuPlugin() { - const myprops = this.props; - return new Plugin({ - view(_editorView) { - return new TooltipLinkingMenu(_editorView, myprops); - } - }); - } onBlur = (e: any) => { //DictationManager.Controls.stop(false); if (this._undoTyping) { @@ -1111,26 +1044,26 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & @action tryUpdateHeight(limitHeight?: number) { let scrollHeight = this._ref.current?.scrollHeight; - if (!this.layoutDoc.animateToPos && this.layoutDoc.autoHeight && scrollHeight && + if (!this.layoutDoc.animateToPos && this.layoutDoc._autoHeight && scrollHeight && getComputedStyle(this._ref.current!.parentElement!).top === "0px") { // if top === 0, then the text box is growing upward (as the overlay caption) which doesn't contribute to the height computation if (limitHeight && scrollHeight > limitHeight) { scrollHeight = limitHeight; this.layoutDoc.limitHeight = undefined; - this.layoutDoc.autoHeight = false; + this.layoutDoc._autoHeight = false; } - const nh = this.Document.isTemplateField ? 0 : NumCast(this.dataDoc.nativeHeight, 0); - const dh = NumCast(this.layoutDoc.height, 0); + const nh = this.Document.isTemplateForField ? 0 : NumCast(this.dataDoc._nativeHeight, 0); + const dh = NumCast(this.layoutDoc._height, 0); const newHeight = Math.max(10, (nh ? dh / nh * scrollHeight : scrollHeight) + (this.props.ChromeHeight ? this.props.ChromeHeight() : 0)); if (Math.abs(newHeight - dh) > 1) { // bcz: Argh! without this, we get into a React crash if the same document is opened in a freeform view and in the treeview. no idea why, but after dragging the freeform document, selecting it, and selecting text, it will compute to 1 pixel higher than the treeview which causes a cycle - this.layoutDoc.height = newHeight; - this.dataDoc.nativeHeight = nh ? scrollHeight : undefined; + this.layoutDoc._height = newHeight; + this.dataDoc._nativeHeight = nh ? scrollHeight : undefined; } } } @computed get sidebarWidthPercent() { return StrCast(this.props.Document.sidebarWidthPercent, "0%"); } @computed get sidebarWidth() { return Number(this.sidebarWidthPercent.substring(0, this.sidebarWidthPercent.length - 1)) / 100 * this.props.PanelWidth(); } - @computed get annotationsKey() { return "annotations"; } + @computed get sidebarColor() { return StrCast(this.layoutDoc[this.props.fieldKey + "-backgroundColor"], StrCast(this.layoutDoc[this.props.fieldKey + "-backgroundColor"], "transparent")); } render() { TraceMobx(); const rounded = StrCast(this.layoutDoc.borderRounding) === "100%" ? "-rounded" : ""; @@ -1138,20 +1071,19 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & if (this.props.isSelected()) { // TODO: ftong --> update from dash in richtextmenu RichTextMenu.Instance.updateFromDash(this._editorView!, undefined, this.props); - // FormattedTextBox.ToolTipTextMenu!.updateFromDash(this._editorView!, undefined, this.props); } else if (FormattedTextBoxComment.textBox === this) { FormattedTextBoxComment.Hide(); } return ( <div className={`formattedTextBox-cont`} ref={this._ref} style={{ - height: this.layoutDoc.autoHeight ? "max-content" : this.props.height ? this.props.height : undefined, + height: this.layoutDoc._autoHeight ? "max-content" : undefined, background: this.props.hideOnLeave ? "rgba(0,0,0 ,0.4)" : undefined, opacity: this.props.hideOnLeave ? (this._entered ? 1 : 0.1) : 1, - color: this.props.color ? this.props.color : this.props.hideOnLeave ? "white" : "inherit", + color: this.props.hideOnLeave ? "white" : "inherit", pointerEvents: interactive ? "none" : "all", - fontSize: this._ruleFontSize ? this._ruleFontSize : NumCast(this.layoutDoc.fontSize, 13), - fontFamily: this._ruleFontFamily ? this._ruleFontFamily : StrCast(this.layoutDoc.fontFamily, "Crimson Text"), + fontSize: NumCast(this.layoutDoc.fontSize, 13), + fontFamily: StrCast(this.layoutDoc.fontFamily, "Crimson Text"), }} onContextMenu={this.specificContextMenu} onKeyDown={this.onKeyPress} @@ -1169,14 +1101,14 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & <div className={`formattedTextBox-outer`} style={{ width: `calc(100% - ${this.sidebarWidthPercent})`, }} ref={this._scrollRef}> <div className={`formattedTextBox-inner${rounded}`} style={{ whiteSpace: "pre-wrap", pointerEvents: ((this.Document.isButton || this.props.onClick) && !this.props.isSelected()) ? "none" : undefined }} ref={this.createDropTarget} /> </div> - {this.props.Document.hideSidebar ? (null) : this.sidebarWidthPercent === "0%" ? + {this.props.Document._hideSidebar ? (null) : this.sidebarWidthPercent === "0%" ? <div className="formattedTextBox-sidebar-handle" onPointerDown={this.sidebarDown} onClick={e => this.toggleSidebar()} /> : <div className={"formattedTextBox-sidebar" + (InkingControl.Instance.selectedTool !== InkTool.None ? "-inking" : "")} - style={{ width: `${this.sidebarWidthPercent}`, backgroundColor: `${StrCast(this.extensionDoc?.backgroundColor, "transparent")}` }}> + style={{ width: `${this.sidebarWidthPercent}`, backgroundColor: `${this.sidebarColor}` }}> <CollectionFreeFormView {...this.props} PanelHeight={this.props.PanelHeight} PanelWidth={() => this.sidebarWidth} - annotationsKey={this.annotationsKey} + annotationsKey={this.annotationKey} isAnnotationOverlay={false} focus={this.props.focus} isSelected={this.props.isSelected} @@ -1186,10 +1118,9 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps & whenActiveChanged={this.whenActiveChanged} removeDocument={this.removeDocument} moveDocument={this.moveDocument} - addDocument={(doc: Doc) => { doc.hideSidebar = true; return this.addDocument(doc); }} + addDocument={(doc: Doc) => { doc._hideSidebar = true; return this.addDocument(doc); }} CollectionView={undefined} ScreenToLocalTransform={() => this.props.ScreenToLocalTransform().translate(-(this.props.PanelWidth() - this.sidebarWidth), 0)} - ruleProvider={undefined} renderDepth={this.props.renderDepth + 1} ContainingCollectionDoc={this.props.ContainingCollectionDoc} chromeCollapsed={true}> diff --git a/src/client/views/nodes/FormattedTextBoxComment.tsx b/src/client/views/nodes/FormattedTextBoxComment.tsx index f7a530790..fda3e3285 100644 --- a/src/client/views/nodes/FormattedTextBoxComment.tsx +++ b/src/client/views/nodes/FormattedTextBoxComment.tsx @@ -86,7 +86,7 @@ export class FormattedTextBoxComment { DocumentManager.Instance.FollowLink(FormattedTextBoxComment.linkDoc, textBox.props.Document, (doc: Doc, maxLocation: string) => textBox.props.addDocTab(doc, undefined, e.ctrlKey ? "inTab" : "onRight")); } else if (textBox && (FormattedTextBoxComment.tooltipText as any).href) { - textBox.props.addDocTab(Docs.Create.WebDocument((FormattedTextBoxComment.tooltipText as any).href, { title: (FormattedTextBoxComment.tooltipText as any).href, width: 200, height: 400 }), undefined, "onRight"); + textBox.props.addDocTab(Docs.Create.WebDocument((FormattedTextBoxComment.tooltipText as any).href, { title: (FormattedTextBoxComment.tooltipText as any).href, _width: 200, _height: 400 }), undefined, "onRight"); } keep && textBox && FormattedTextBoxComment.start !== undefined && textBox.adoptAnnotation( FormattedTextBoxComment.start, FormattedTextBoxComment.end, FormattedTextBoxComment.mark); @@ -185,7 +185,6 @@ export class FormattedTextBoxComment { active={returnFalse} addDocument={returnFalse} removeDocument={returnFalse} - ruleProvider={undefined} addDocTab={returnFalse} pinToPres={returnFalse} dontRegisterView={true} diff --git a/src/client/views/nodes/IconBox.tsx b/src/client/views/nodes/IconBox.tsx index 9462ff024..172338eb6 100644 --- a/src/client/views/nodes/IconBox.tsx +++ b/src/client/views/nodes/IconBox.tsx @@ -79,7 +79,7 @@ export class IconBox extends React.Component<FieldViewProps> { <Measure offset onResize={(r) => runInAction(() => { if (r.offset!.width || this.props.Document.hideLabel) { this.props.Document.iconWidth = (r.offset!.width + Number(MINIMIZED_ICON_SIZE)); - if (this.props.Document.height === Number(MINIMIZED_ICON_SIZE)) this.props.Document.width = this.props.Document.iconWidth; + if (this.props.Document._height === Number(MINIMIZED_ICON_SIZE)) this.props.Document._width = this.props.Document.iconWidth; } })}> {({ measureRef }) => diff --git a/src/client/views/nodes/ImageBox.scss b/src/client/views/nodes/ImageBox.scss index cf5d999a7..43f4a0ba9 100644 --- a/src/client/views/nodes/ImageBox.scss +++ b/src/client/views/nodes/ImageBox.scss @@ -1,10 +1,12 @@ -.imageBox, .imageBox-dragging{ +.imageBox, +.imageBox-dragging { pointer-events: all; border-radius: inherit; - width:100%; - height:100%; + width: 100%; + height: 100%; position: absolute; transform-origin: top left; + .imageBox-fader { pointer-events: all; } @@ -16,6 +18,14 @@ } } +#upload-icon { + position: absolute; + bottom: 0; + right: 0; + width: 20px; + height: 20px; +} + .imageBox-cont { padding: 0vw; position: absolute; @@ -25,7 +35,8 @@ max-width: 100%; max-height: 100%; pointer-events: none; - background:transparent; + background: transparent; + img { height: auto; width: 100%; @@ -55,9 +66,10 @@ padding: 3px; background: white; cursor: pointer; - opacity:0.15; + opacity: 0.15; } -#google-photos:hover{ + +#google-photos:hover { opacity: 1; } diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx index 634555012..33c694c6e 100644 --- a/src/client/views/nodes/ImageBox.tsx +++ b/src/client/views/nodes/ImageBox.tsx @@ -4,11 +4,11 @@ import { faAsterisk, faFileAudio, faImage, faPaintBrush } from '@fortawesome/fre import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { action, computed, observable, runInAction, trace } from 'mobx'; import { observer } from "mobx-react"; -import { Doc, DocListCast, HeightSym, WidthSym } from '../../../new_fields/Doc'; +import { Doc, DocListCast, HeightSym, WidthSym, DataSym } from '../../../new_fields/Doc'; import { List } from '../../../new_fields/List'; import { createSchema, listSpec, makeInterface } from '../../../new_fields/Schema'; import { ComputedField } from '../../../new_fields/ScriptField'; -import { Cast, NumCast } from '../../../new_fields/Types'; +import { Cast, NumCast, StrCast } from '../../../new_fields/Types'; import { AudioField, ImageField } from '../../../new_fields/URLField'; import { Utils, returnOne, emptyFunction } from '../../../Utils'; import { CognitiveServices, Confidence, Service, Tag } from '../../cognitive_services/CognitiveServices'; @@ -24,9 +24,12 @@ import "./ImageBox.scss"; import React = require("react"); import { CollectionFreeFormView } from '../collections/collectionFreeForm/CollectionFreeFormView'; import { documentSchema } from '../../../new_fields/documentSchemas'; -import { Id } from '../../../new_fields/FieldSymbols'; +import { Id, Copy } from '../../../new_fields/FieldSymbols'; import { TraceMobx } from '../../../new_fields/util'; import { SelectionManager } from '../../util/SelectionManager'; +import { cache } from 'sharp'; +import { ObjectField } from '../../../new_fields/ObjectField'; +import { Networking } from '../../Network'; const requestImageSize = require('../../util/request-image-size'); const path = require('path'); const { Howl } = require('howler'); @@ -39,7 +42,6 @@ library.add(faFileAudio, faAsterisk); export const pageSchema = createSchema({ curPage: "number", fitWidth: "boolean", - rotation: "number", googlePhotosUrl: "string", googlePhotosTags: "string" }); @@ -56,6 +58,13 @@ declare class MediaRecorder { type ImageDocument = makeInterface<[typeof pageSchema, typeof documentSchema]>; const ImageDocument = makeInterface(pageSchema, documentSchema); +const uploadIcons = { + idle: "downarrow.png", + loading: "loading.gif", + success: "greencheck.png", + failure: "redx.png" +}; + @observer export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocument>(ImageDocument) { public static LayoutString(fieldKey: string) { return FieldView.LayoutString(ImageBox, fieldKey); } @@ -63,6 +72,7 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum private _dropDisposer?: DragManager.DragDropDisposer; @observable private _audioState = 0; @observable static _showControls: boolean; + @observable uploadIcon = uploadIcons.idle; protected createDropTarget = (ele: HTMLDivElement) => { this._dropDisposer && this._dropDisposer(); @@ -73,14 +83,21 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum @action drop = (e: Event, de: DragManager.DropEvent) => { if (de.complete.docDragData) { - if (de.altKey && de.complete.docDragData.draggedDocuments.length && de.complete.docDragData.draggedDocuments[0].data instanceof ImageField) { - Doc.GetProto(this.dataDoc)[this.props.fieldKey] = new ImageField(de.complete.docDragData.draggedDocuments[0].data.url); - e.stopPropagation(); + if (de.metaKey) { + de.complete.docDragData.droppedDocuments.forEach(action((drop: Doc) => { + Doc.AddDocToList(this.dataDoc, this.props.fieldKey + "-alternates", drop); + e.stopPropagation(); + })); + } else if (de.altKey || !this.dataDoc[this.props.fieldKey]) { + const layoutDoc = de.complete.docDragData?.draggedDocuments[0]; + const targetField = Doc.LayoutFieldKey(layoutDoc); + if (layoutDoc?.[DataSym][targetField] instanceof ImageField) { + this.dataDoc[this.props.fieldKey] = ObjectField.MakeCopy(layoutDoc[DataSym][targetField] as ImageField); + this.dataDoc[this.props.fieldKey + "-nativeWidth"] = NumCast(layoutDoc[DataSym][targetField + "-nativeWidth"]); + this.dataDoc[this.props.fieldKey + "-nativeHeight"] = NumCast(layoutDoc[DataSym][targetField + "-nativeHeight"]); + e.stopPropagation(); + } } - de.metaKey && de.complete.docDragData.droppedDocuments.forEach(action((drop: Doc) => { - this.extensionDoc && Doc.AddDocToList(Doc.GetProto(this.extensionDoc), "Alternates", drop); - e.stopPropagation(); - })); } } @@ -88,8 +105,7 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum let gumStream: any; let recorder: any; const self = this; - const extensionDoc = this.extensionDoc; - extensionDoc && navigator.mediaDevices.getUserMedia({ + navigator.mediaDevices.getUserMedia({ audio: true }).then(function (stream) { gumStream = stream; @@ -97,18 +113,18 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum recorder.ondataavailable = async function (e: any) { const formData = new FormData(); formData.append("file", e.data); - const res = await fetch(Utils.prepend("/upload"), { + const res = await fetch(Utils.prepend("/uploadFormData"), { method: 'POST', body: formData }); const files = await res.json(); const url = Utils.prepend(files[0].path); // upload to server with known URL - const audioDoc = Docs.Create.AudioDocument(url, { title: "audio test", width: 200, height: 32 }); + const audioDoc = Docs.Create.AudioDocument(url, { title: "audio test", _width: 200, _height: 32 }); audioDoc.treeViewExpandedView = "layout"; - const audioAnnos = Cast(extensionDoc.audioAnnotations, listSpec(Doc)); + const audioAnnos = Cast(this.dataDoc[this.props.fieldKey + "-audioAnnotations"], listSpec(Doc)); if (audioAnnos === undefined) { - extensionDoc.audioAnnotations = new List([audioDoc]); + this.dataDoc[this.props.fieldKey + "-audioAnnotations"] = new List([audioDoc]); } else { audioAnnos.push(audioDoc); } @@ -125,15 +141,15 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum @undoBatch rotate = action(() => { - const nw = this.Document.nativeWidth; - const nh = this.Document.nativeHeight; - const w = this.Document.width; - const h = this.Document.height; - this.Document.rotation = ((this.Document.rotation || 0) + 90) % 360; - this.Document.nativeWidth = nh; - this.Document.nativeHeight = nw; - this.Document.width = h; - this.Document.height = w; + const nw = NumCast(this.Document[this.props.fieldKey + "-nativeWidth"]); + const nh = NumCast(this.Document[this.props.fieldKey + "-nativeHeight"]); + const w = this.Document._width; + const h = this.Document._height; + this.dataDoc[this.props.fieldKey + "-rotation"] = (NumCast(this.dataDoc[this.props.fieldKey + "-rotation"]) + 90) % 360; + this.dataDoc[this.props.fieldKey + "-nativeWidth"] = nh; + this.dataDoc[this.props.fieldKey + "-nativeHeight"] = nw; + this.Document._width = h; + this.Document._height = w; }); specificContextMenu = (e: React.MouseEvent): void => { @@ -159,7 +175,7 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum results.reduce((face: CognitiveServices.Image.Face, faceDocs: List<Doc>) => faceDocs.push(Docs.Get.DocumentHierarchyFromJson(face, `Face: ${face.faceId}`)!), new List<Doc>()); return faceDocs; }; - this.url && this.extensionDoc && CognitiveServices.Image.Appliers.ProcessImage(this.extensionDoc, ["faces"], this.url, Service.Face, converter); + this.url && CognitiveServices.Image.Appliers.ProcessImage(this.dataDoc, [this.props.fieldKey + "-faces"], this.url, Service.Face, converter); } generateMetadata = (threshold: Confidence = Confidence.Excellent) => { @@ -171,12 +187,12 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum const sanitized = tag.name.replace(" ", "_"); tagDoc[sanitized] = ComputedField.MakeFunction(`(${tag.confidence} >= this.confidence) ? ${tag.confidence} : "${ComputedField.undefined}"`); }); - this.extensionDoc && (this.extensionDoc.generatedTags = tagsList); + this.dataDoc[this.props.fieldKey + "-generatedTags"] = tagsList; tagDoc.title = "Generated Tags Doc"; tagDoc.confidence = threshold; return tagDoc; }; - this.url && this.extensionDoc && CognitiveServices.Image.Appliers.ProcessImage(this.extensionDoc, ["generatedTagsDoc"], this.url, Service.ComputerVision, converter); + this.url && CognitiveServices.Image.Appliers.ProcessImage(this.dataDoc, [this.props.fieldKey + "-generatedTagsDoc"], this.url, Service.ComputerVision, converter); } @computed private get url() { @@ -206,39 +222,52 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum if (this._curSuffix === "_m") this._mediumRetryCount++; if (this._curSuffix === "_l") this._largeRetryCount++; } - @action onError = () => { + @action onError = (error: any) => { const timeout = this._curSuffix === "_s" ? this._smallRetryCount : this._curSuffix === "_m" ? this._mediumRetryCount : this._largeRetryCount; if (timeout < 10) { - setTimeout(this.retryPath, Math.min(10000, timeout * 5)); + // setTimeout(this.retryPath, 500); + } + const original = StrCast(this.dataDoc.originalUrl); + if (error.type === "error" && original) { + this.dataDoc[this.props.fieldKey] = new ImageField(original); } } _curSuffix = "_m"; - _resized = ""; resize = (imgPath: string) => { - requestImageSize(imgPath) - .then((size: any) => { - const rotation = NumCast(this.dataDoc.rotation) % 180; - const realsize = rotation === 90 || rotation === 270 ? { height: size.width, width: size.height } : size; - const aspect = realsize.height / realsize.width; - if (this.Document.width && (Math.abs(1 - NumCast(this.Document.height) / NumCast(this.Document.width) / (realsize.height / realsize.width)) > 0.1)) { - setTimeout(action(() => { - if (this.pathInfos.srcpath === imgPath && (!this.layoutDoc.isTemplateDoc || this.dataDoc !== this.layoutDoc)) { - this._resized = imgPath; - this.Document.height = this.Document[WidthSym]() * aspect; - this.Document.nativeHeight = realsize.height; - this.Document.nativeWidth = realsize.width; - } - }), 0); - } else this._resized = imgPath; + const cachedNativeSize = { + width: NumCast(this.dataDoc[this.props.fieldKey + "-nativeWidth"]), + height: NumCast(this.dataDoc[this.props.fieldKey + "-nativeHeight"]) + }; + const cachedImgPath = this.dataDoc[this.props.fieldKey + "-imgPath"]; + if (!cachedNativeSize.width || !cachedNativeSize.height || imgPath !== cachedImgPath) { + (!this.layoutDoc.isTemplateDoc || this.dataDoc !== this.layoutDoc) && requestImageSize(imgPath).then((inquiredSize: any) => { + const rotation = NumCast(this.dataDoc[this.props.fieldKey + "-rotation"]) % 180; + const rotatedNativeSize = rotation === 90 || rotation === 270 ? { height: inquiredSize.width, width: inquiredSize.height } : inquiredSize; + const rotatedAspect = rotatedNativeSize.height / rotatedNativeSize.width; + const docAspect = this.Document[HeightSym]() / this.Document[WidthSym](); + setTimeout(action(() => { + if (this.Document[WidthSym]() && (!cachedNativeSize.width || !cachedNativeSize.height || Math.abs(1 - docAspect / rotatedAspect) > 0.1)) { + this.Document._height = this.Document[WidthSym]() * rotatedAspect; + this.dataDoc[this.props.fieldKey + "-nativeWidth"] = this.Document._nativeWidth = rotatedNativeSize.width; + this.dataDoc[this.props.fieldKey + "-nativeHeight"] = this.Document._nativeHeight = rotatedNativeSize.height; + } + this.dataDoc[this.props.fieldKey + "-imgPath"] = imgPath; + }), 0); }) - .catch((err: any) => console.log(err)); + .catch((err: any) => console.log(err)); + } else if (this.Document._nativeHeight !== cachedNativeSize.width || this.Document._nativeWidth !== cachedNativeSize.height) { + !(this.Document[StrCast(this.props.Document.layoutKey)] instanceof Doc) && setTimeout(() => { + this.Document._nativeWidth = cachedNativeSize.width; + this.Document._nativeHeight = cachedNativeSize.height; + }, 0); + } } @action onPointerEnter = () => { const self = this; - const audioAnnos = this.extensionDoc && DocListCast(this.extensionDoc.audioAnnotations); + const audioAnnos = DocListCast(this.dataDoc[this.props.fieldKey + "-audioAnnotations"]); if (audioAnnos && audioAnnos.length && this._audioState === 0) { const anno = audioAnnos[Math.floor(Math.random() * audioAnnos.length)]; anno.data instanceof AudioField && new Howl({ @@ -271,45 +300,78 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum return !tags ? (null) : (<img id={"google-tags"} src={"/assets/google_tags.png"} />); } + @computed + private get considerDownloadIcon() { + const data = this.dataDoc[this.props.fieldKey]; + if (!(data instanceof ImageField)) { + return (null); + } + const primary = data.url.href; + if (primary.includes(window.location.origin)) { + return (null); + } + return ( + <img + id={"upload-icon"} + src={`/assets/${this.uploadIcon}`} + onClick={async () => { + const { dataDoc } = this; + const { success, failure, idle, loading } = uploadIcons; + runInAction(() => this.uploadIcon = loading); + const [{ clientAccessPath }] = await Networking.PostToServer("/uploadRemoteImage", { sources: [primary] }); + dataDoc.originalUrl = primary; + let succeeded = true; + let data: ImageField | undefined; + try { + data = new ImageField(Utils.prepend(clientAccessPath)); + } catch { + succeeded = false; + } + runInAction(() => this.uploadIcon = succeeded ? success : failure); + setTimeout(action(() => { + this.uploadIcon = idle; + if (data) { + dataDoc[this.props.fieldKey] = data; + } + }), 2000); + }} + /> + ); + } + @computed get nativeSize() { const pw = typeof this.props.PanelWidth === "function" ? this.props.PanelWidth() : typeof this.props.PanelWidth === "number" ? (this.props.PanelWidth as any) as number : 50; - const nativeWidth = (this.Document.nativeWidth || pw); - const nativeHeight = (this.Document.nativeHeight || 1); + const nativeWidth = NumCast(this.dataDoc[this.props.fieldKey + "-nativeWidth"], pw); + const nativeHeight = NumCast(this.dataDoc[this.props.fieldKey + "-nativeHeight"], 1); return { nativeWidth, nativeHeight }; } - @computed get pathInfos() { - const extensionDoc = this.extensionDoc!; - const { nativeWidth, nativeHeight } = this.nativeSize; - let paths = [[Utils.CorsProxy("http://www.cs.brown.edu/~bcz/noImage.png"), nativeWidth / nativeHeight]]; + @computed get paths() { + let paths = [Utils.CorsProxy("http://www.cs.brown.edu/~bcz/noImage.png")]; // this._curSuffix = ""; // if (w > 20) { - const alts = DocListCast(extensionDoc.Alternates); - const altpaths = alts.filter(doc => doc.data instanceof ImageField).map(doc => [this.choosePath((doc.data as ImageField).url), doc[WidthSym]() / doc[HeightSym]()]); + const alts = DocListCast(this.dataDoc[this.props.fieldKey + "-alternates"]); + const altpaths = alts.filter(doc => doc.data instanceof ImageField).map(doc => this.choosePath((doc.data as ImageField).url)); const field = this.dataDoc[this.props.fieldKey]; // if (w < 100 && this._smallRetryCount < 10) this._curSuffix = "_s"; // else if (w < 600 && this._mediumRetryCount < 10) this._curSuffix = "_m"; // else if (this._largeRetryCount < 10) this._curSuffix = "_l"; - if (field instanceof ImageField) paths = [[this.choosePath(field.url), nativeWidth / nativeHeight]]; + if (field instanceof ImageField) paths = [this.choosePath(field.url)]; paths.push(...altpaths); - const srcpath = paths[Math.min(paths.length - 1, (this.Document.curPage || 0))][0] as string; - const srcaspect = paths[Math.min(paths.length - 1, (this.Document.curPage || 0))][1] as number; - const fadepath = paths[Math.min(paths.length - 1, 1)][0] as string; - return { srcpath, srcaspect, fadepath }; + return paths; } @computed get content() { TraceMobx(); - const extensionDoc = this.extensionDoc; - if (!extensionDoc) return (null); - const { srcpath, srcaspect, fadepath } = this.pathInfos; + const srcpath = this.paths[NumCast(this.props.Document.curPage, 0)]; + const fadepath = this.paths[Math.min(1, this.paths.length - 1)]; const { nativeWidth, nativeHeight } = this.nativeSize; - const rotation = NumCast(this.Document.rotation, 0); + const rotation = NumCast(this.dataDoc[this.props.fieldKey + "-rotation"]); const aspect = (rotation % 180) ? this.Document[HeightSym]() / this.Document[WidthSym]() : 1; const shift = (rotation % 180) ? (nativeHeight - nativeWidth / aspect) / 2 : 0; - !this.Document.ignoreAspect && this._resized !== srcpath && this.resize(srcpath); + !this.Document.ignoreAspect && this.resize(srcpath); return <div className="imageBox-cont" key={this.props.Document[Id]} ref={this.createDropTarget} onContextMenu={this.specificContextMenu}> <div className="imageBox-fader" > @@ -319,7 +381,7 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum width={nativeWidth} ref={this._imgRef} onError={this.onError} /> - {fadepath === srcpath ? (null) : <div className="imageBox-fadeBlocker" style={{ width: nativeWidth, height: nativeWidth / srcaspect }}> + {fadepath === srcpath ? (null) : <div className="imageBox-fadeBlocker"> <img className="imageBox-fadeaway" key={"fadeaway" + this._smallRetryCount + (this._mediumRetryCount << 4) + (this._largeRetryCount << 8)} // force cache to update on retrys src={fadepath} @@ -334,10 +396,12 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum style={{ height: `calc(${.1 * nativeHeight / nativeWidth * 100}%)` }} > <FontAwesomeIcon className="imageBox-audioFont" - style={{ color: [DocListCast(extensionDoc.audioAnnotations).length ? "blue" : "gray", "green", "red"][this._audioState] }} icon={!DocListCast(extensionDoc.audioAnnotations).length ? "microphone" : faFileAudio} size="sm" /> + style={{ color: [DocListCast(this.dataDoc[this.props.fieldKey + "-audioAnnotations"]).length ? "blue" : "gray", "green", "red"][this._audioState] }} + icon={!DocListCast(this.dataDoc[this.props.fieldKey + "-audioAnnotations"]).length ? "microphone" : faFileAudio} size="sm" /> </div> + {this.considerDownloadIcon} {this.considerGooglePhotosLink()} - <FaceRectangles document={extensionDoc} color={"#0000FF"} backgroundColor={"#0000FF"} /> + <FaceRectangles document={this.dataDoc} color={"#0000FF"} backgroundColor={"#0000FF"} /> </div>; } @@ -354,7 +418,7 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum <CollectionFreeFormView {...this.props} PanelHeight={this.props.PanelHeight} PanelWidth={this.props.PanelWidth} - annotationsKey={this.annotationsKey} + annotationsKey={this.annotationKey} isAnnotationOverlay={true} focus={this.props.focus} isSelected={this.props.isSelected} @@ -367,7 +431,6 @@ export class ImageBox extends DocAnnotatableComponent<FieldViewProps, ImageDocum addDocument={this.addDocument} CollectionView={undefined} ScreenToLocalTransform={this.props.ScreenToLocalTransform} - ruleProvider={undefined} renderDepth={this.props.renderDepth + 1} ContainingCollectionDoc={this.props.ContainingCollectionDoc} chromeCollapsed={true}> diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx index 234a6a9d3..7aad6f90e 100644 --- a/src/client/views/nodes/KeyValueBox.tsx +++ b/src/client/views/nodes/KeyValueBox.tsx @@ -179,7 +179,7 @@ export class KeyValueBox extends React.Component<FieldViewProps> { } getTemplate = async () => { - const parent = Docs.Create.StackingDocument([], { width: 800, height: 800, title: "Template" }); + const parent = Docs.Create.StackingDocument([], { _width: 800, _height: 800, title: "Template" }); parent.singleColumn = false; parent.columnWidth = 100; for (const row of this.rows.filter(row => row.isChecked)) { @@ -200,17 +200,17 @@ export class KeyValueBox extends React.Component<FieldViewProps> { if (!fieldTemplate) { return; } - const previousViewType = fieldTemplate.viewType; + const previousViewType = fieldTemplate._viewType; Doc.MakeMetadataFieldTemplate(fieldTemplate, Doc.GetProto(parentStackingDoc)); - previousViewType && (fieldTemplate.viewType = previousViewType); + previousViewType && (fieldTemplate._viewType = previousViewType); Cast(parentStackingDoc.data, listSpec(Doc))!.push(fieldTemplate); } inferType = async (data: FieldResult, metaKey: string) => { - const options = { width: 300, height: 300, title: metaKey }; + const options = { _width: 300, _height: 300, title: metaKey }; if (data instanceof RichTextField || typeof data === "string" || typeof data === "number") { - return Docs.Create.TextDocument(options); + return Docs.Create.TextDocument("", options); } else if (data instanceof List) { if (data.length === 0) { return Docs.Create.StackingDocument([], options); diff --git a/src/client/views/nodes/KeyValuePair.tsx b/src/client/views/nodes/KeyValuePair.tsx index 91f8bb3b0..e6b512adf 100644 --- a/src/client/views/nodes/KeyValuePair.tsx +++ b/src/client/views/nodes/KeyValuePair.tsx @@ -46,7 +46,7 @@ export class KeyValuePair extends React.Component<KeyValuePairProps> { if (value instanceof Doc) { e.stopPropagation(); e.preventDefault(); - ContextMenu.Instance.addItem({ description: "Open Fields", event: () => this.props.addDocTab(Docs.Create.KVPDocument(value, { width: 300, height: 300 }), undefined, "onRight"), icon: "layer-group" }); + ContextMenu.Instance.addItem({ description: "Open Fields", event: () => this.props.addDocTab(Docs.Create.KVPDocument(value, { _width: 300, _height: 300 }), undefined, "onRight"), icon: "layer-group" }); ContextMenu.Instance.displayMenu(e.clientX, e.clientY); } } @@ -58,7 +58,6 @@ export class KeyValuePair extends React.Component<KeyValuePairProps> { LibraryPath: [], ContainingCollectionView: undefined, ContainingCollectionDoc: undefined, - ruleProvider: undefined, fieldKey: this.props.keyName, isSelected: returnFalse, select: emptyFunction, diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx index 8370df6ba..e1c5fd27f 100644 --- a/src/client/views/nodes/PDFBox.tsx +++ b/src/client/views/nodes/PDFBox.tsx @@ -50,9 +50,9 @@ export class PDFBox extends DocAnnotatableComponent<FieldViewProps, PdfDocument> constructor(props: any) { super(props); this._initialScale = this.props.ScreenToLocalTransform().Scale; - const nw = this.Document.nativeWidth = NumCast(this.extensionDocSync.nativeWidth, NumCast(this.Document.nativeWidth, 927)); - const nh = this.Document.nativeHeight = NumCast(this.extensionDocSync.nativeHeight, NumCast(this.Document.nativeHeight, 1200)); - !this.Document.fitWidth && !this.Document.ignoreAspect && (this.Document.height = this.Document[WidthSym]() * (nh / nw)); + const nw = this.Document._nativeWidth = NumCast(this.dataDoc[this.props.fieldKey + "-nativeWidth"], NumCast(this.Document._nativeWidth, 927)); + const nh = this.Document._nativeHeight = NumCast(this.dataDoc[this.props.fieldKey + "-nativeHeight"], NumCast(this.Document._nativeHeight, 1200)); + !this.Document._fitWidth && !this.Document.ignoreAspect && (this.Document._height = this.Document[WidthSym]() * (nh / nw)); const backup = "oldPath"; const { Document } = this.props; @@ -90,10 +90,10 @@ export class PDFBox extends DocAnnotatableComponent<FieldViewProps, PdfDocument> } loaded = (nw: number, nh: number, np: number) => { - this.extensionDocSync.numPages = np; - this.extensionDocSync.nativeWidth = this.Document.nativeWidth = nw * 96 / 72; - this.extensionDocSync.nativeHeight = this.Document.nativeHeight = nh * 96 / 72; - !this.Document.fitWidth && !this.Document.ignoreAspect && (this.Document.height = this.Document[WidthSym]() * (nh / nw)); + this.dataDoc[this.props.fieldKey + "-numPages"] = np; + this.dataDoc[this.props.fieldKey + "-nativeWidth"] = this.Document._nativeWidth = nw * 96 / 72; + this.dataDoc[this.props.fieldKey + "-nativeHeight"] = this.Document._nativeHeight = nh * 96 / 72; + !this.Document._fitWidth && !this.Document.ignoreAspect && (this.Document._height = this.Document[WidthSym]() * (nh / nw)); } public search(string: string, fwd: boolean) { this._pdfViewer && this._pdfViewer.search(string, fwd); } @@ -211,7 +211,7 @@ export class PDFBox extends DocAnnotatableComponent<FieldViewProps, PdfDocument> const pdfUrl = Cast(this.dataDoc[this.props.fieldKey], PdfField); const funcs: ContextMenuProps[] = []; pdfUrl && funcs.push({ description: "Copy path", event: () => Utils.CopyText(pdfUrl.url.pathname), icon: "expand-arrows-alt" }); - funcs.push({ description: "Toggle Fit Width " + (this.Document.fitWidth ? "Off" : "On"), event: () => this.Document.fitWidth = !this.Document.fitWidth, icon: "expand-arrows-alt" }); + funcs.push({ description: "Toggle Fit Width " + (this.Document._fitWidth ? "Off" : "On"), event: () => this.Document._fitWidth = !this.Document._fitWidth, icon: "expand-arrows-alt" }); ContextMenu.Instance.addItem({ description: "Pdf Funcs...", subitems: funcs, icon: "asterisk" }); } @@ -220,8 +220,8 @@ export class PDFBox extends DocAnnotatableComponent<FieldViewProps, PdfDocument> @computed get renderTitleBox() { const classname = "pdfBox" + (this.active() ? "-interactive" : ""); return <div className={classname} style={{ - width: !this.props.Document.fitWidth ? this.Document.nativeWidth || 0 : `${100 / this.contentScaling}%`, - height: !this.props.Document.fitWidth ? this.Document.nativeHeight || 0 : `${100 / this.contentScaling}%`, + width: !this.props.Document._fitWidth ? this.Document._nativeWidth || 0 : `${100 / this.contentScaling}%`, + height: !this.props.Document._fitWidth ? this.Document._nativeHeight || 0 : `${100 / this.contentScaling}%`, transform: `scale(${this.contentScaling})` }} > <div className="pdfBox-title-outer"> @@ -252,13 +252,15 @@ export class PDFBox extends DocAnnotatableComponent<FieldViewProps, PdfDocument> render() { const pdfUrl = Cast(this.dataDoc[this.props.fieldKey], PdfField, null); if (this.props.isSelected() || this.props.Document.scrollY !== undefined) this._everActive = true; - if (pdfUrl && this.extensionDoc && (this._everActive || (this.extensionDoc.nativeWidth && this.props.ScreenToLocalTransform().Scale < 2.5))) { + if (pdfUrl && (this._everActive || (this.dataDoc[this.props.fieldKey + "-nativeWidth"] && this.props.ScreenToLocalTransform().Scale < 2.5))) { if (pdfUrl instanceof PdfField && this._pdf) { return this.renderPdfView; } if (!this._pdfjsRequested) { this._pdfjsRequested = true; - Pdfjs.getDocument(pdfUrl.url.href).promise.then(pdf => runInAction(() => this._pdf = pdf)); + const promise = Pdfjs.getDocument(pdfUrl.url.href).promise; + promise.then(pdf => { runInAction(() => { this._pdf = pdf; console.log("promise"); }) }); + } } return this.renderTitleBox; diff --git a/src/client/views/nodes/PresBox.tsx b/src/client/views/nodes/PresBox.tsx index 1e6894f37..428e9aa7b 100644 --- a/src/client/views/nodes/PresBox.tsx +++ b/src/client/views/nodes/PresBox.tsx @@ -44,7 +44,7 @@ export class PresBox extends React.Component<FieldViewProps> { if (item instanceof Doc && item.type !== DocumentType.PRESELEMENT) { const pinDoc = Docs.Create.PresElementBoxDocument({ backgroundColor: "transparent" }); Doc.GetProto(pinDoc).presentationTargetDoc = item; - Doc.GetProto(pinDoc).title = ComputedField.MakeFunction('(this.presentationTargetDoc instanceof Doc) && this.presentationTargetDoc.title.toString()'); + Doc.GetProto(pinDoc).title = ComputedField.MakeFunction('this.presentationTargetDoc?.title?.toString()'); value.splice(i, 1, pinDoc); } }); @@ -336,13 +336,13 @@ export class PresBox extends React.Component<FieldViewProps> { */ @action initializeScaleViews = (docList: Doc[], viewtype: number) => { - this.props.Document.chromeStatus = "disabled"; + this.props.Document._chromeStatus = "disabled"; const hgt = (viewtype === CollectionViewType.Tree) ? 50 : 72; docList.forEach((doc: Doc) => { doc.presBox = this.props.Document; doc.presBoxKey = this.props.fieldKey; doc.collapsedHeight = hgt; - doc.height = ComputedField.MakeFunction("this.collapsedHeight + Number(this.embedOpen ? 100:0)"); + doc._height = ComputedField.MakeFunction("this.collapsedHeight + Number(this.embedOpen ? 100:0)"); const curScale = NumCast(doc.viewScale, null); if (curScale === undefined) { doc.viewScale = 1; @@ -360,7 +360,7 @@ export class PresBox extends React.Component<FieldViewProps> { return this.props.ScreenToLocalTransform().translate(-10, -50);// listBox padding-left and pres-box-cont minHeight } render() { - this.initializeScaleViews(this.childDocs, NumCast(this.props.Document.viewType)); + this.initializeScaleViews(this.childDocs, NumCast(this.props.Document._viewType)); return ( <div className="presBox-cont" onContextMenu={this.specificContextMenu}> <div className="presBox-buttons"> diff --git a/src/client/views/nodes/VideoBox.tsx b/src/client/views/nodes/VideoBox.tsx index 376d27380..d12a8d151 100644 --- a/src/client/views/nodes/VideoBox.tsx +++ b/src/client/views/nodes/VideoBox.tsx @@ -55,12 +55,12 @@ export class VideoBox extends DocAnnotatableComponent<FieldViewProps, VideoDocum videoLoad = () => { const aspect = this.player!.videoWidth / this.player!.videoHeight; - const nativeWidth = (this.Document.nativeWidth || 0); - const nativeHeight = (this.Document.nativeHeight || 0); + const nativeWidth = (this.Document._nativeWidth || 0); + const nativeHeight = (this.Document._nativeHeight || 0); if (!nativeWidth || !nativeHeight) { - if (!this.Document.nativeWidth) this.Document.nativeWidth = this.player!.videoWidth; - this.Document.nativeHeight = (this.Document.nativeWidth || 0) / aspect; - this.Document.height = (this.Document.width || 0) / aspect; + if (!this.Document._nativeWidth) this.Document._nativeWidth = this.player!.videoWidth; + this.Document._nativeHeight = (this.Document._nativeWidth || 0) / aspect; + this.Document._height = (this.Document._width || 0) / aspect; } if (!this.Document.duration) this.Document.duration = this.player!.duration; } @@ -101,11 +101,11 @@ export class VideoBox extends DocAnnotatableComponent<FieldViewProps, VideoDocum } @action public Snapshot() { - const width = this.Document.width || 0; - const height = this.Document.height || 0; + const width = this.Document._width || 0; + const height = this.Document._height || 0; const canvas = document.createElement('canvas'); canvas.width = 640; - canvas.height = 640 * (this.Document.nativeHeight || 0) / (this.Document.nativeWidth || 1); + canvas.height = 640 * (this.Document._nativeHeight || 0) / (this.Document._nativeWidth || 1); const ctx = canvas.getContext('2d');//draw image to canvas. scale to target dimensions if (ctx) { ctx.rect(0, 0, canvas.width, canvas.height); @@ -117,7 +117,7 @@ export class VideoBox extends DocAnnotatableComponent<FieldViewProps, VideoDocum if (!this._videoRef) { // can't find a way to take snapshots of videos const b = Docs.Create.ButtonDocument({ x: (this.Document.x || 0) + width, y: (this.Document.y || 0), - width: 150, height: 50, title: (this.Document.currentTimecode || 0).toString() + _width: 150, _height: 50, title: (this.Document.currentTimecode || 0).toString() }); b.onClick = ScriptField.MakeScript(`this.currentTimecode = ${(this.Document.currentTimecode || 0)}`); } else { @@ -130,7 +130,7 @@ export class VideoBox extends DocAnnotatableComponent<FieldViewProps, VideoDocum const url = this.choosePath(Utils.prepend(returnedFilename)); const imageSummary = Docs.Create.ImageDocument(url, { x: (this.Document.x || 0) + width, y: (this.Document.y || 0), - width: 150, height: height / width * 150, title: "--snapshot" + (this.Document.currentTimecode || 0) + " image-" + _width: 150, _height: height / width * 150, title: "--snapshot" + (this.Document.currentTimecode || 0) + " image-" }); imageSummary.isButton = true; this.props.addDocument && this.props.addDocument(imageSummary); @@ -151,12 +151,12 @@ export class VideoBox extends DocAnnotatableComponent<FieldViewProps, VideoDocum if (this.youtubeVideoId) { const youtubeaspect = 400 / 315; - const nativeWidth = (this.Document.nativeWidth || 0); - const nativeHeight = (this.Document.nativeHeight || 0); + const nativeWidth = (this.Document._nativeWidth || 0); + const nativeHeight = (this.Document._nativeHeight || 0); if (!nativeWidth || !nativeHeight) { - if (!this.Document.nativeWidth) this.Document.nativeWidth = 600; - this.Document.nativeHeight = (this.Document.nativeWidth || 0) / youtubeaspect; - this.Document.height = (this.Document.width || 0) / youtubeaspect; + if (!this.Document._nativeWidth) this.Document._nativeWidth = 600; + this.Document._nativeHeight = (this.Document._nativeWidth || 0) / youtubeaspect; + this.Document._height = (this.Document._width || 0) / youtubeaspect; } } } @@ -321,7 +321,7 @@ export class VideoBox extends DocAnnotatableComponent<FieldViewProps, VideoDocum const style = "videoBox-content-YouTube" + (this._fullScreen ? "-fullScreen" : ""); const start = untracked(() => Math.round(this.Document.currentTimecode || 0)); return <iframe key={this._youtubeIframeId} id={`${this.youtubeVideoId + this._youtubeIframeId}-player`} - onLoad={this.youtubeIframeLoaded} className={`${style}`} width={(this.Document.nativeWidth || 640)} height={(this.Document.nativeHeight || 390)} + onLoad={this.youtubeIframeLoaded} className={`${style}`} width={(this.Document._nativeWidth || 640)} height={(this.Document._nativeHeight || 390)} src={`https://www.youtube.com/embed/${this.youtubeVideoId}?enablejsapi=1&rel=0&showinfo=1&autoplay=1&mute=1&start=${start}&modestbranding=1&controls=${VideoBox._showControls ? 1 : 0}`} />; } @@ -340,7 +340,7 @@ export class VideoBox extends DocAnnotatableComponent<FieldViewProps, VideoDocum <CollectionFreeFormView {...this.props} PanelHeight={this.props.PanelHeight} PanelWidth={this.props.PanelWidth} - annotationsKey={this.annotationsKey} + annotationsKey={this.annotationKey} focus={this.props.focus} isSelected={this.props.isSelected} isAnnotationOverlay={true} @@ -353,7 +353,6 @@ export class VideoBox extends DocAnnotatableComponent<FieldViewProps, VideoDocum addDocument={this.addDocumentWithTimestamp} CollectionView={undefined} ScreenToLocalTransform={this.props.ScreenToLocalTransform} - ruleProvider={undefined} renderDepth={this.props.renderDepth + 1} ContainingCollectionDoc={this.props.ContainingCollectionDoc} chromeCollapsed={true}> diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx index b35ea0bb0..a48dc286e 100644 --- a/src/client/views/nodes/WebBox.tsx +++ b/src/client/views/nodes/WebBox.tsx @@ -34,17 +34,17 @@ export class WebBox extends DocAnnotatableComponent<FieldViewProps, WebDocument> @observable private collapsed: boolean = true; @observable private url: string = ""; - componentWillMount() { + componentDidMount() { const field = Cast(this.props.Document[this.props.fieldKey], WebField); if (field && field.url.href.indexOf("youtube") !== -1) { const youtubeaspect = 400 / 315; - const nativeWidth = NumCast(this.layoutDoc.nativeWidth); - const nativeHeight = NumCast(this.layoutDoc.nativeHeight); + const nativeWidth = NumCast(this.layoutDoc._nativeWidth); + const nativeHeight = NumCast(this.layoutDoc._nativeHeight); if (!nativeWidth || !nativeHeight || Math.abs(nativeWidth / nativeHeight - youtubeaspect) > 0.05) { - if (!nativeWidth) this.layoutDoc.nativeWidth = 600; - this.layoutDoc.nativeHeight = NumCast(this.layoutDoc.nativeWidth) / youtubeaspect; - this.layoutDoc.height = NumCast(this.layoutDoc.width) / youtubeaspect; + if (!nativeWidth) this.layoutDoc._nativeWidth = 600; + this.layoutDoc._nativeHeight = NumCast(this.layoutDoc._nativeWidth) / youtubeaspect; + this.layoutDoc._height = NumCast(this.layoutDoc._width) / youtubeaspect; } } @@ -83,13 +83,12 @@ export class WebBox extends DocAnnotatableComponent<FieldViewProps, WebDocument> const field = Cast(this.props.Document[this.props.fieldKey], WebField); if (field) url = field.url.href; - const newBox = Docs.Create.TextDocument({ + const newBox = Docs.Create.TextDocument(url, { x: NumCast(this.props.Document.x), y: NumCast(this.props.Document.y), title: url, - width: 200, - height: 70, - documentText: "@@@" + url + _width: 200, + _height: 70, }); SelectionManager.SelectedDocuments().map(dv => { @@ -198,7 +197,7 @@ export class WebBox extends DocAnnotatableComponent<FieldViewProps, WebDocument> <CollectionFreeFormView {...this.props} PanelHeight={this.props.PanelHeight} PanelWidth={this.props.PanelWidth} - annotationsKey={this.annotationsKey} + annotationsKey={this.annotationKey} focus={this.props.focus} isSelected={this.props.isSelected} isAnnotationOverlay={true} @@ -211,7 +210,6 @@ export class WebBox extends DocAnnotatableComponent<FieldViewProps, WebDocument> addDocument={this.addDocument} CollectionView={undefined} ScreenToLocalTransform={this.props.ScreenToLocalTransform} - ruleProvider={undefined} renderDepth={this.props.renderDepth + 1} ContainingCollectionDoc={this.props.ContainingCollectionDoc} chromeCollapsed={true}> diff --git a/src/client/views/pdf/Annotation.tsx b/src/client/views/pdf/Annotation.tsx index 6599c0e3c..d8b340db6 100644 --- a/src/client/views/pdf/Annotation.tsx +++ b/src/client/views/pdf/Annotation.tsx @@ -11,10 +11,11 @@ import "./Annotation.scss"; interface IAnnotationProps { anno: Doc; - extensionDoc: Doc; addDocTab: (document: Doc, dataDoc: Opt<Doc>, where: string) => boolean; pinToPres: (document: Doc) => void; focus: (doc: Doc) => void; + dataDoc: Doc; + fieldKey: string; } export default class Annotation extends React.Component<IAnnotationProps> { @@ -29,10 +30,11 @@ interface IRegionAnnotationProps { y: number; width: number; height: number; - extensionDoc: Doc; addDocTab: (document: Doc, dataDoc: Doc | undefined, where: string) => boolean; pinToPres: (document: Doc) => void; document: Doc; + dataDoc: Doc; + fieldKey: string; } @observer @@ -62,12 +64,12 @@ class RegionAnnotation extends React.Component<IRegionAnnotationProps> { } deleteAnnotation = () => { - const annotation = DocListCast(this.props.extensionDoc.annotations); + const annotation = DocListCast(this.props.dataDoc[this.props.fieldKey + "-annotations"]); const group = FieldValue(Cast(this.props.document.group, Doc)); if (group) { if (annotation.indexOf(group) !== -1) { const newAnnotations = annotation.filter(a => a !== FieldValue(Cast(this.props.document.group, Doc))); - this.props.extensionDoc.annotations = new List<Doc>(newAnnotations); + this.props.dataDoc[this.props.fieldKey + "-annotations"] = new List<Doc>(newAnnotations); } DocListCast(group.annotations).forEach(anno => anno.delete = true); diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index 62467ce4d..a7c1990e9 100644 --- a/src/client/views/pdf/PDFViewer.tsx +++ b/src/client/views/pdf/PDFViewer.tsx @@ -113,8 +113,8 @@ export class PDFViewer extends DocAnnotatableComponent<IViewerProps, PdfDocument private _coverPath: any; @computed get allAnnotations() { - return this.extensionDoc ? DocListCast(this.extensionDoc.annotations).filter( - anno => this._script.run({ this: anno }, console.log, true).result) : []; + return DocListCast(this.dataDoc[this.props.fieldKey + "-annotations"]).filter( + anno => this._script.run({ this: anno }, console.log, true).result); } @computed get nonDocAnnotations() { @@ -208,8 +208,8 @@ export class PDFViewer extends DocAnnotatableComponent<IViewerProps, PdfDocument await this.initialLoad(); this._annotationReactionDisposer = reaction( - () => this.extensionDoc && DocListCast(this.extensionDoc.annotations), - annotations => annotations && annotations.length && (this._annotations = annotations), + () => DocListCast(this.dataDoc[this.props.fieldKey + "-annotations"]), + annotations => annotations?.length && (this._annotations = annotations), { fireImmediately: true }); this._filterReactionDisposer = reaction( @@ -271,8 +271,8 @@ export class PDFViewer extends DocAnnotatableComponent<IViewerProps, PdfDocument const annoDoc = Docs.Create.FreeformDocument([], { backgroundColor: color, title: "Annotation on " + this.Document.title }); if (anno.style.left) annoDoc.x = parseInt(anno.style.left); if (anno.style.top) annoDoc.y = parseInt(anno.style.top); - if (anno.style.height) annoDoc.height = parseInt(anno.style.height); - if (anno.style.width) annoDoc.width = parseInt(anno.style.width); + if (anno.style.height) annoDoc._height = parseInt(anno.style.height); + if (anno.style.width) annoDoc._width = parseInt(anno.style.width); annoDoc.group = mainAnnoDoc; annoDoc.isButton = true; annoDocs.push(annoDoc); @@ -286,8 +286,8 @@ export class PDFViewer extends DocAnnotatableComponent<IViewerProps, PdfDocument const annoDoc = new Doc(); if (anno.style.left) annoDoc.x = parseInt(anno.style.left); if (anno.style.top) annoDoc.y = parseInt(anno.style.top); - if (anno.style.height) annoDoc.height = parseInt(anno.style.height); - if (anno.style.width) annoDoc.width = parseInt(anno.style.width); + if (anno.style.height) annoDoc._height = parseInt(anno.style.height); + if (anno.style.width) annoDoc._width = parseInt(anno.style.width); annoDoc.group = mainAnnoDoc; annoDoc.backgroundColor = color; annoDocs.push(annoDoc); @@ -558,7 +558,7 @@ export class PDFViewer extends DocAnnotatableComponent<IViewerProps, PdfDocument startDrag = (e: PointerEvent, ele: HTMLElement): void => { e.preventDefault(); e.stopPropagation(); - const targetDoc = Docs.Create.TextDocument({ width: 200, height: 200, title: "Note linked to " + this.props.Document.title }); + const targetDoc = Docs.Create.TextDocument("", { _width: 200, _height: 200, title: "Note linked to " + this.props.Document.title }); const annotationDoc = this.highlight("rgba(146, 245, 95, 0.467)"); // yellowish highlight color when dragging out a text selection if (annotationDoc) { DragManager.StartPdfAnnoDrag([ele], new DragManager.PdfAnnoDragData(this.props.Document, annotationDoc, targetDoc), e.pageX, e.pageY, { @@ -573,11 +573,11 @@ export class PDFViewer extends DocAnnotatableComponent<IViewerProps, PdfDocument const data = Doc.MakeDelegate(Doc.GetProto(this.props.Document)); data.title = StrCast(data.title) + "_snippet"; view.proto = data; - view.nativeHeight = marquee.height; - view.height = (this.Document[WidthSym]() / (this.Document.nativeWidth || 1)) * marquee.height; - view.nativeWidth = this.Document.nativeWidth; + view._nativeHeight = marquee.height; + view._height = (this.Document[WidthSym]() / (this.Document._nativeWidth || 1)) * marquee.height; + view._nativeWidth = this.Document._nativeWidth; view.startY = marquee.top; - view.width = this.Document[WidthSym](); + view._width = this.Document[WidthSym](); DragManager.StartDocumentDrag([], new DragManager.DocumentDragData([view]), 0, 0); } @@ -598,12 +598,12 @@ export class PDFViewer extends DocAnnotatableComponent<IViewerProps, PdfDocument getCoverImage = () => { if (!this.props.Document[HeightSym]() || !this.props.Document.nativeHeight) { setTimeout((() => { - this.Document.height = this.Document[WidthSym]() * this._coverPath.height / this._coverPath.width; - this.Document.nativeHeight = (this.Document.nativeWidth || 0) * this._coverPath.height / this._coverPath.width; + this.Document._height = this.Document[WidthSym]() * this._coverPath.height / this._coverPath.width; + this.Document._nativeHeight = (this.Document._nativeWidth || 0) * this._coverPath.height / this._coverPath.width; }).bind(this), 0); } - const nativeWidth = (this.Document.nativeWidth || 0); - const nativeHeight = (this.Document.nativeHeight || 0); + const nativeWidth = (this.Document._nativeWidth || 0); + const nativeHeight = (this.Document._nativeHeight || 0); const resolved = Utils.prepend(this._coverPath.path); return <img key={resolved} src={resolved} onError={action(() => this._coverPath.path = "http://www.cs.brown.edu/~bcz/face.gif")} onLoad={action(() => this._showWaiting = false)} style={{ position: "absolute", display: "inline-block", top: 0, left: 0, width: `${nativeWidth}px`, height: `${nativeHeight}px` }} />; @@ -621,19 +621,19 @@ export class PDFViewer extends DocAnnotatableComponent<IViewerProps, PdfDocument @computed get annotationLayer() { TraceMobx(); - return <div className="pdfViewer-annotationLayer" style={{ height: (this.Document.nativeHeight || 0), transform: `scale(${this._zoomed})` }} ref={this._annotationLayer}> + return <div className="pdfViewer-annotationLayer" style={{ height: NumCast(this.Document.nativeHeight), transform: `scale(${this._zoomed})` }} ref={this._annotationLayer}> {this.nonDocAnnotations.sort((a, b) => NumCast(a.y) - NumCast(b.y)).map((anno, index) => - <Annotation {...this.props} focus={this.props.focus} extensionDoc={this.extensionDoc!} anno={anno} key={`${anno[Id]}-annotation`} />)} + <Annotation {...this.props} focus={this.props.focus} dataDoc={this.dataDoc!} fieldKey={this.props.fieldKey} anno={anno} key={`${anno[Id]}-annotation`} />)} </div>; } overlayTransform = () => this.scrollXf().scale(1 / this._zoomed); - panelWidth = () => (this.Document.scrollHeight || this.Document.nativeHeight || 0); - panelHeight = () => this._pageSizes.length && this._pageSizes[0] ? this._pageSizes[0].width : (this.Document.nativeWidth || 0); + panelWidth = () => (this.Document.scrollHeight || this.Document._nativeHeight || 0); + panelHeight = () => this._pageSizes.length && this._pageSizes[0] ? this._pageSizes[0].width : (this.Document._nativeWidth || 0); @computed get overlayLayer() { return <div className={`pdfViewer-overlay${InkingControl.Instance.selectedTool !== InkTool.None ? "-inking" : ""}`} id="overlay" style={{ transform: `scale(${this._zoomed})` }}> <CollectionFreeFormView {...this.props} LibraryPath={this.props.ContainingCollectionView?.props.LibraryPath ?? []} - annotationsKey={this.annotationsKey} + annotationsKey={this.annotationKey} setPreviewCursor={this.setPreviewCursor} PanelHeight={this.panelWidth} PanelWidth={this.panelHeight} @@ -650,7 +650,6 @@ export class PDFViewer extends DocAnnotatableComponent<IViewerProps, PdfDocument addDocument={this.addDocument} CollectionView={undefined} ScreenToLocalTransform={this.overlayTransform} - ruleProvider={undefined} renderDepth={this.props.renderDepth + 1} ContainingCollectionDoc={this.props.ContainingCollectionView?.props.Document} chromeCollapsed={true}> @@ -676,20 +675,19 @@ export class PDFViewer extends DocAnnotatableComponent<IViewerProps, PdfDocument contentZoom = () => this._zoomed; render() { TraceMobx(); - return !this.extensionDoc ? (null) : - <div className={"pdfViewer" + (this._zoomed !== 1 ? "-zoomed" : "")} ref={this._mainCont} - onScroll={this.onScroll} onWheel={this.onZoomWheel} onPointerDown={this.onPointerDown} onClick={this.onClick} - style={{ - width: !this.props.Document.fitWidth ? NumCast(this.props.Document.nativeWidth) : `${100 / this.contentScaling}%`, - height: !this.props.Document.fitWidth ? NumCast(this.props.Document.nativeHeight) : `${100 / this.contentScaling}%`, - transform: `scale(${this.props.ContentScaling()})` - }} > - {this.pdfViewerDiv} - {this.overlayLayer} - {this.annotationLayer} - {this.standinViews} - <PdfViewerMarquee isMarqueeing={this.marqueeing} width={this.marqueeWidth} height={this.marqueeHeight} x={this.marqueeX} y={this.marqueeY} /> - </div >; + return <div className={"pdfViewer" + (this._zoomed !== 1 ? "-zoomed" : "")} ref={this._mainCont} + onScroll={this.onScroll} onWheel={this.onZoomWheel} onPointerDown={this.onPointerDown} onClick={this.onClick} + style={{ + width: !this.props.Document._fitWidth ? NumCast(this.props.Document._nativeWidth) : `${100 / this.contentScaling}%`, + height: !this.props.Document._fitWidth ? NumCast(this.props.Document._nativeHeight) : `${100 / this.contentScaling}%`, + transform: `scale(${this.props.ContentScaling()})` + }} > + {this.pdfViewerDiv} + {this.overlayLayer} + {this.annotationLayer} + {this.standinViews} + <PdfViewerMarquee isMarqueeing={this.marqueeing} width={this.marqueeWidth} height={this.marqueeHeight} x={this.marqueeX} y={this.marqueeY} /> + </div >; } } diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx index c02042380..dad55e1fd 100644 --- a/src/client/views/presentationview/PresElementBox.tsx +++ b/src/client/views/presentationview/PresElementBox.tsx @@ -161,12 +161,12 @@ export class PresElementBox extends DocComponent<FieldViewProps, PresDocument>(P return (null); } - const propDocWidth = NumCast(this.layoutDoc.nativeWidth); - const propDocHeight = NumCast(this.layoutDoc.nativeHeight); - const scale = () => 175 / NumCast(this.layoutDoc.nativeWidth, 175); + const propDocWidth = NumCast(this.layoutDoc._nativeWidth); + const propDocHeight = NumCast(this.layoutDoc._nativeHeight); + const scale = () => 175 / NumCast(this.layoutDoc._nativeWidth, 175); return ( <div className="presElementBox-embedded" style={{ - height: propDocHeight === 0 ? NumCast(this.layoutDoc.height) - NumCast(this.layoutDoc.collapsedHeight) : propDocHeight * scale(), + height: propDocHeight === 0 ? NumCast(this.layoutDoc._height) - NumCast(this.layoutDoc.collapsedHeight) : propDocHeight * scale(), width: propDocWidth === 0 ? "auto" : propDocWidth * scale(), }}> <ContentFittingDocumentView @@ -175,7 +175,6 @@ export class PresElementBox extends DocComponent<FieldViewProps, PresDocument>(P fitToBox={StrCast(this.targetDoc.type).indexOf(DocumentType.COL) !== -1} addDocument={returnFalse} removeDocument={returnFalse} - ruleProvider={undefined} addDocTab={returnFalse} pinToPres={returnFalse} PanelWidth={() => this.props.PanelWidth() - 20} @@ -193,7 +192,7 @@ export class PresElementBox extends DocComponent<FieldViewProps, PresDocument>(P } render() { - const treecontainer = this.props.ContainingCollectionDoc && this.props.ContainingCollectionDoc.viewType === CollectionViewType.Tree; + const treecontainer = this.props.ContainingCollectionDoc?._viewType === CollectionViewType.Tree; const className = "presElementBox-item" + (this.currentIndex === this.indexInPres ? " presElementBox-selected" : ""); const pbi = "presElementBox-interaction"; return ( diff --git a/src/client/views/search/SearchBox.scss b/src/client/views/search/SearchBox.scss index 0825580b7..f492ea773 100644 --- a/src/client/views/search/SearchBox.scss +++ b/src/client/views/search/SearchBox.scss @@ -9,6 +9,7 @@ position: absolute; font-size: 10px; line-height: 1; + overflow: hidden; } .searchBox-bar { height: 32px; diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx index dd1ac7421..be13dae03 100644 --- a/src/client/views/search/SearchBox.tsx +++ b/src/client/views/search/SearchBox.tsx @@ -217,16 +217,16 @@ export class SearchBox extends React.Component { doc.x = x; doc.y = y; const size = 200; - const aspect = NumCast(doc.nativeHeight) / NumCast(doc.nativeWidth, 1); + const aspect = NumCast(doc._nativeHeight) / NumCast(doc._nativeWidth, 1); if (aspect > 1) { - doc.height = size; - doc.width = size / aspect; + doc._height = size; + doc._width = size / aspect; } else if (aspect > 0) { - doc.width = size; - doc.height = size * aspect; + doc._width = size; + doc._height = size * aspect; } else { - doc.width = size; - doc.height = size; + doc._width = size; + doc._height = size; } x += 250; if (x > 1000) { @@ -234,7 +234,7 @@ export class SearchBox extends React.Component { y += 300; } } - return Docs.Create.TreeDocument(docs, { width: 200, height: 400, backgroundColor: "grey", title: `Search Docs: "${this._searchString}"` }); + return Docs.Create.TreeDocument(docs, { _width: 200, _height: 400, backgroundColor: "grey", title: `Search Docs: "${this._searchString}"` }); } @action.bound @@ -267,10 +267,11 @@ export class SearchBox extends React.Component { @action resultsScrolled = (e?: React.UIEvent<HTMLDivElement>) => { + if (!this.resultsRef.current) return; const scrollY = e ? e.currentTarget.scrollTop : this.resultsRef.current ? this.resultsRef.current.scrollTop : 0; const itemHght = 53; const startIndex = Math.floor(Math.max(0, scrollY / itemHght)); - const endIndex = Math.ceil(Math.min(this._numTotalResults - 1, startIndex + (this.resultsRef.current!.getBoundingClientRect().height / itemHght))); + const endIndex = Math.ceil(Math.min(this._numTotalResults - 1, startIndex + (this.resultsRef.current.getBoundingClientRect().height / itemHght))); this._endIndex = endIndex === -1 ? 12 : endIndex; diff --git a/src/client/views/search/SearchItem.tsx b/src/client/views/search/SearchItem.tsx index 88a4d4c50..8aea737f0 100644 --- a/src/client/views/search/SearchItem.tsx +++ b/src/client/views/search/SearchItem.tsx @@ -68,11 +68,11 @@ export class SelectorContextMenu extends React.Component<SearchItemProps> { getOnClick({ col, target }: { col: Doc, target: Doc }) { return () => { col = Doc.IsPrototype(col) ? Doc.MakeDelegate(col) : col; - if (NumCast(col.viewType, CollectionViewType.Invalid) === CollectionViewType.Freeform) { - const newPanX = NumCast(target.x) + NumCast(target.width) / 2; - const newPanY = NumCast(target.y) + NumCast(target.height) / 2; - col.panX = newPanX; - col.panY = newPanY; + if (NumCast(col._viewType, CollectionViewType.Invalid) === CollectionViewType.Freeform) { + const newPanX = NumCast(target.x) + NumCast(target._width) / 2; + const newPanY = NumCast(target.y) + NumCast(target._height) / 2; + col._panX = newPanX; + col._panY = newPanY; } CollectionDockingView.AddRightSplit(col, undefined); }; @@ -161,7 +161,6 @@ export class SearchItem extends React.Component<SearchItemProps> { fitToBox={StrCast(this.props.doc.type).indexOf(DocumentType.COL) !== -1} addDocument={returnFalse} removeDocument={returnFalse} - ruleProvider={undefined} addDocTab={returnFalse} pinToPres={returnFalse} getTransform={Transform.Identity} @@ -260,7 +259,6 @@ export class SearchItem extends React.Component<SearchItemProps> { onPointerMoved = (e: PointerEvent) => { if (Math.abs(e.clientX - this._downX) > Utils.DRAG_THRESHOLD || Math.abs(e.clientY - this._downY) > Utils.DRAG_THRESHOLD) { - console.log("DRAGGIGNG"); document.removeEventListener("pointermove", this.onPointerMoved); document.removeEventListener("pointerup", this.onPointerUp); const doc = Doc.IsPrototype(this.props.doc) ? Doc.MakeDelegate(this.props.doc) : this.props.doc; diff --git a/src/mobile/ImageUpload.tsx b/src/mobile/ImageUpload.tsx index 0b0280519..1583e3d5d 100644 --- a/src/mobile/ImageUpload.tsx +++ b/src/mobile/ImageUpload.tsx @@ -45,7 +45,7 @@ class Uploader extends React.Component { const formData = new FormData(); formData.append("file", files[0]); - const upload = window.location.origin + "/upload"; + const upload = window.location.origin + "/uploadFormData"; this.status = "uploading image"; const res = await fetch(upload, { method: 'POST', @@ -55,7 +55,7 @@ class Uploader extends React.Component { const json = await res.json(); json.map(async (file: any) => { const path = window.location.origin + file; - const doc = Docs.Create.ImageDocument(path, { nativeWidth: 200, width: 200, title: name }); + const doc = Docs.Create.ImageDocument(path, { _nativeWidth: 200, _width: 200, title: name }); this.status = "getting user document"; diff --git a/src/mobile/MobileInterface.tsx b/src/mobile/MobileInterface.tsx index ea2fc917f..b1eaeaa0a 100644 --- a/src/mobile/MobileInterface.tsx +++ b/src/mobile/MobileInterface.tsx @@ -38,7 +38,6 @@ export default class MobileInterface extends React.Component { addDocTab={returnFalse} pinToPres={emptyFunction} removeDocument={undefined} - ruleProvider={undefined} onClick={undefined} ScreenToLocalTransform={Transform.Identity} ContentScaling={returnOne} diff --git a/src/new_fields/CursorField.ts b/src/new_fields/CursorField.ts index fd86031a8..28467377b 100644 --- a/src/new_fields/CursorField.ts +++ b/src/new_fields/CursorField.ts @@ -2,7 +2,7 @@ import { ObjectField } from "./ObjectField"; import { observable } from "mobx"; import { Deserializable } from "../client/util/SerializationHelper"; import { serializable, createSimpleSchema, object, date } from "serializr"; -import { OnUpdate, ToScriptString, Copy } from "./FieldSymbols"; +import { OnUpdate, ToScriptString, ToString, Copy } from "./FieldSymbols"; export type CursorPosition = { x: number, @@ -60,4 +60,7 @@ export default class CursorField extends ObjectField { [ToScriptString]() { return "invalid"; } + [ToString]() { + return "invalid"; + } }
\ No newline at end of file diff --git a/src/new_fields/DateField.ts b/src/new_fields/DateField.ts index 4f999e5e8..a925148c2 100644 --- a/src/new_fields/DateField.ts +++ b/src/new_fields/DateField.ts @@ -1,7 +1,7 @@ import { Deserializable } from "../client/util/SerializationHelper"; import { serializable, date } from "serializr"; import { ObjectField } from "./ObjectField"; -import { Copy, ToScriptString } from "./FieldSymbols"; +import { Copy, ToScriptString, ToString } from "./FieldSymbols"; import { scriptingGlobal, Scripting } from "../client/util/Scripting"; @scriptingGlobal @@ -26,6 +26,9 @@ export class DateField extends ObjectField { [ToScriptString]() { return `new DateField(new Date(${this.date.toISOString()}))`; } + [ToString]() { + return this.date.toISOString(); + } } Scripting.addGlobal(function d(...dateArgs: any[]) { diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index e0ab5d97c..5f78636a9 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -1,21 +1,22 @@ -import { observable, ObservableMap, runInAction, action, untracked } from "mobx"; +import { observable, ObservableMap, runInAction } from "mobx"; import { alias, map, serializable } from "serializr"; import { DocServer } from "../client/DocServer"; import { DocumentType } from "../client/documents/DocumentTypes"; import { Scripting, scriptingGlobal } from "../client/util/Scripting"; import { afterDocDeserialize, autoObject, Deserializable, SerializationHelper } from "../client/util/SerializationHelper"; -import { Copy, HandleUpdate, Id, OnUpdate, Parent, Self, SelfProxy, ToScriptString, Update } from "./FieldSymbols"; +import { Copy, HandleUpdate, Id, OnUpdate, Parent, Self, SelfProxy, ToScriptString, ToString, Update } from "./FieldSymbols"; import { List } from "./List"; import { ObjectField } from "./ObjectField"; import { PrefetchProxy, ProxyField } from "./Proxy"; import { FieldId, RefField } from "./RefField"; import { listSpec } from "./Schema"; import { ComputedField, ScriptField } from "./ScriptField"; -import { BoolCast, Cast, FieldValue, NumCast, PromiseValue, StrCast, ToConstructor } from "./Types"; +import { BoolCast, Cast, FieldValue, NumCast, StrCast, ToConstructor } from "./Types"; import { deleteProperty, getField, getter, makeEditable, makeReadOnly, setter, updateFunction } from "./util"; import { intersectRect } from "../Utils"; import { UndoManager } from "../client/util/UndoManager"; import { computedFn } from "mobx-utils"; +import { RichTextField } from "./RichTextField"; export namespace Field { export function toKeyValueString(doc: Doc, key: string): string { @@ -36,6 +37,18 @@ export namespace Field { return field[ToScriptString](); } } + export function toString(field: Field): string { + if (typeof field === "string") { + return field; + } else if (typeof field === "number" || typeof field === "boolean") { + return String(field); + } else if (field instanceof ObjectField) { + return field[ToString](); + } else if (field instanceof RefField) { + return field[ToString](); + } + return "(null)"; + } export function IsField(field: any): field is Field; export function IsField(field: any, includeUndefined: true): field is Field | undefined; export function IsField(field: any, includeUndefined: boolean = false): field is Field | undefined { @@ -75,6 +88,7 @@ export function DocListCast(field: FieldResult): Doc[] { export const WidthSym = Symbol("Width"); export const HeightSym = Symbol("Height"); +export const DataSym = Symbol("Data"); export const UpdatingFromServer = Symbol("UpdatingFromServer"); const CachedUpdates = Symbol("Cached updates"); @@ -150,12 +164,16 @@ export class Doc extends RefField { private [Self] = this; private [SelfProxy]: any; - public [WidthSym] = () => NumCast(this[SelfProxy].width); - public [HeightSym] = () => NumCast(this[SelfProxy].height); + public [WidthSym] = () => NumCast(this[SelfProxy]._width); + public [HeightSym] = () => NumCast(this[SelfProxy]._height); + public get [DataSym]() { return Cast(this[SelfProxy].resolvedDataDoc, Doc, null) || this[SelfProxy]; } [ToScriptString]() { return "invalid"; } + [ToString]() { + return "Doc"; + } private [CachedUpdates]: { [key: string]: () => void | Promise<any> } = {}; public static CurrentUserEmail: string = ""; @@ -409,86 +427,70 @@ export namespace Doc { if (layout instanceof Doc && layout !== alias) { Doc.SetLayout(alias, Doc.MakeAlias(layout)); } - const aliasNumber = Doc.GetProto(doc).aliasNumber = NumCast(Doc.GetProto(doc).aliasNumber) + 1; - alias.title = ComputedField.MakeFunction(`renameAlias(this, ${aliasNumber})`); + alias.title = ComputedField.MakeFunction(`renameAlias(this, ${Doc.GetProto(doc).aliasNumber = NumCast(Doc.GetProto(doc).aliasNumber) + 1})`); return alias; } // // Determines whether the combination of the layoutDoc and dataDoc represents - // a template relationship. If so, the layoutDoc will be expanded into a new - // document that inherits the properties of the original layout while allowing - // for individual layout properties to be overridden in the expanded layout. + // a template relationship : there is a dataDoc and it doesn't match the layoutDoc an + // the lyouatDoc's layout is layout string (not a document) // export function WillExpandTemplateLayout(layoutDoc: Doc, dataDoc?: Doc) { - return BoolCast(layoutDoc.isTemplateField) && dataDoc && layoutDoc !== dataDoc && !(layoutDoc[StrCast(layoutDoc.layoutKey, "layout")] instanceof Doc); + return layoutDoc.isTemplateForField && dataDoc && layoutDoc !== dataDoc && !(Doc.LayoutField(layoutDoc) instanceof Doc); } // - // Returns an expanded template layout for a target data document. - // First it checks if an expanded layout already exists -- if so it will be stored on the dataDoc - // using the template layout doc's id as the field key. - // If it doesn't find the expanded layout, then it makes a delegate of the template layout and - // saves it on the data doc indexed by the template layout's id + // Returns an expanded template layout for a target data document if there is a template relationship + // between the two. If so, the layoutDoc is expanded into a new document that inherits the properties + // of the original layout while allowing for individual layout properties to be overridden in the expanded layout. // export function expandTemplateLayout(templateLayoutDoc: Doc, dataDoc?: Doc) { if (!WillExpandTemplateLayout(templateLayoutDoc, dataDoc) || !dataDoc) return templateLayoutDoc; - // if we have a data doc that doesn't match the layout, then we're rendering a template. - // ... which means we change the layout to be an expanded view of the template layout. - // This allows the view override the template's properties and be referenceable as its own document. - const expandedLayoutFieldKey = "Layout[" + templateLayoutDoc[Id] + "]"; - const expandedTemplateLayout = dataDoc[expandedLayoutFieldKey]; - if (expandedTemplateLayout instanceof Doc) { - return expandedTemplateLayout; - } + const templateField = StrCast(templateLayoutDoc.isTemplateForField); // the field that the template renders + // First it checks if an expanded layout already exists -- if so it will be stored on the dataDoc + // using the template layout doc's id as the field key. + // If it doesn't find the expanded layout, then it makes a delegate of the template layout and + // saves it on the data doc indexed by the template layout's id. + // + const expandedLayoutFieldKey = templateField + "-layout[" + templateLayoutDoc[Id] + "]"; + const expandedTemplateLayout = dataDoc?.[expandedLayoutFieldKey]; if (expandedTemplateLayout === undefined) { - setTimeout(() => dataDoc[expandedLayoutFieldKey] === undefined && - (dataDoc[expandedLayoutFieldKey] = Doc.MakeDelegate(templateLayoutDoc, undefined, "[" + templateLayoutDoc.title + "]")), 0); + setTimeout(() => { + if (!dataDoc[expandedLayoutFieldKey]) { + const newLayoutDoc = Doc.MakeDelegate(templateLayoutDoc, undefined, "[" + templateLayoutDoc.title + "]"); + dataDoc[expandedLayoutFieldKey] = newLayoutDoc; + newLayoutDoc.resolvedDataDoc = dataDoc; + if (dataDoc[templateField] === undefined && templateLayoutDoc[templateField] instanceof List && Cast(templateLayoutDoc[templateField], listSpec(Doc), []).length) { + dataDoc[templateField] = ComputedField.MakeFunction(`ObjectField.MakeCopy(templateLayoutDoc["${templateField}"] as List)`, { templateLayoutDoc: Doc.name }, { templateLayoutDoc: templateLayoutDoc }); + } + } + }, 0); } - return undefined; // use the templateLayout when it's not a template or the expandedTemplate is pending. + return expandedTemplateLayout instanceof Doc ? expandedTemplateLayout : undefined; // layout is undefined if the expandedTemplate is pending. } - export function GetLayoutDataDocPair(doc: Doc, dataDoc: Doc | undefined, fieldKey: string, childDocLayout: Doc) { - let layoutDoc: Doc | undefined = childDocLayout; - const resolvedDataDoc = !doc.isTemplateField && dataDoc !== doc && dataDoc ? Doc.GetDataDoc(dataDoc) : undefined; - if (resolvedDataDoc && Doc.WillExpandTemplateLayout(childDocLayout, resolvedDataDoc)) { - const extensionDoc = fieldExtensionDoc(resolvedDataDoc, StrCast(childDocLayout.templateField, StrCast(childDocLayout.title))); - layoutDoc = Doc.expandTemplateLayout(childDocLayout, extensionDoc !== resolvedDataDoc ? extensionDoc : undefined); - setTimeout(() => layoutDoc && (layoutDoc.resolvedDataDoc = resolvedDataDoc), 0); - } else layoutDoc = childDocLayout; - return { layout: layoutDoc, data: resolvedDataDoc }; + // if the childDoc is a template for a field, then this will return the expanded layout with its data doc. + // otherwise, it just returns the childDoc + export function GetLayoutDataDocPair(containerDoc: Doc, containerDataDoc: Opt<Doc>, childDoc: Doc) { + const resolvedDataDoc = containerDataDoc === containerDoc || !containerDataDoc ? undefined : Doc.GetDataDoc(containerDataDoc); + return { layout: Doc.expandTemplateLayout(childDoc, resolvedDataDoc), data: resolvedDataDoc }; } - - // - // Resolves a reference to a field by returning 'doc' if no field extension is specified, - // otherwise, it returns the extension document stored in doc.<fieldKey>_ext. - // This mechanism allows any fields to be extended with an extension document that can - // be used to capture field-specific metadata. For example, an image field can be extended - // to store annotations, ink, and other data. - // - export function fieldExtensionDoc(doc: Doc, fieldKey: string) { - const extension = doc[fieldKey + "_ext"]; - if (doc instanceof Doc && extension === undefined) { - setTimeout(() => CreateDocumentExtensionForField(doc, fieldKey), 0); - } - return extension ? extension as Doc : undefined; - } - export function fieldExtensionDocSync(doc: Doc, fieldKey: string) { - return (doc[fieldKey + "_ext"] as Doc) || CreateDocumentExtensionForField(doc, fieldKey); - } - export function CreateDocumentExtensionForField(doc: Doc, fieldKey: string) { - const docExtensionForField = new Doc(doc[Id] + fieldKey, true); - docExtensionForField.title = fieldKey + ".ext"; // courtesy field--- shouldn't be needed except maybe for debugging - docExtensionForField.extendsDoc = doc; // this is used by search to map field matches on the extension doc back to the document it extends. - docExtensionForField.extendsField = fieldKey; // this can be used by search to map matches on the extension doc back to the field that was extended. - docExtensionForField.type = DocumentType.EXTENSION; let proto: Doc | undefined = doc; while (proto && !Doc.IsPrototype(proto) && proto.proto) { proto = proto.proto; } - (proto ? proto : doc)[fieldKey + "_ext"] = new PrefetchProxy(docExtensionForField); + let docExtensionForField = ((proto || doc)[fieldKey + "_ext"] as Doc); + if (!docExtensionForField) { + docExtensionForField = new Doc(doc[Id] + fieldKey, true); + docExtensionForField.title = fieldKey + ".ext"; // courtesy field--- shouldn't be needed except maybe for debugging + docExtensionForField.extendsDoc = doc; // this is used by search to map field matches on the extension doc back to the document it extends. + docExtensionForField.extendsField = fieldKey; // this can be used by search to map matches on the extension doc back to the field that was extended. + docExtensionForField.type = DocumentType.EXTENSION; + (proto || doc)[fieldKey + "_ext"] = new PrefetchProxy(docExtensionForField); + } return docExtensionForField; } @@ -517,7 +519,9 @@ export namespace Doc { export function MakeCopy(doc: Doc, copyProto: boolean = false, copyProtoId?: string): Doc { const copy = new Doc(copyProtoId, true); + const exclude = Cast(doc.excludeFields, listSpec("string"), []); Object.keys(doc).forEach(key => { + if (exclude.includes(key)) return; const cfield = ComputedField.WithoutComputed(() => FieldValue(doc[key])); const field = ProxyField.WithoutProxy(() => doc[key]); if (key === "proto" && copyProto) { @@ -566,8 +570,8 @@ export namespace Doc { export function ApplyTemplateTo(templateDoc: Doc, target: Doc, targetKey: string, titleTarget: string | undefined = undefined) { if (!templateDoc) { target.layout = undefined; - target.nativeWidth = undefined; - target.nativeHeight = undefined; + target._nativeWidth = undefined; + target._nativeHeight = undefined; target.onClick = undefined; target.type = undefined; return; @@ -580,45 +584,50 @@ export namespace Doc { Doc.GetProto(target).type = DocumentType.TEMPLATE; target.onClick = templateDoc.onClick instanceof ObjectField && templateDoc.onClick[Copy](); - Doc.GetProto(target)[targetKey] = layoutCustomLayout; + Doc.GetProto(target)[targetKey] = new PrefetchProxy(layoutCustomLayout); } target.layoutKey = targetKey; return target; } - export function MakeMetadataFieldTemplate(fieldTemplate: Doc, templateDataDoc: Doc, suppressTitle: boolean = false): boolean { - // move data doc fields to layout doc as needed (nativeWidth/nativeHeight, data, ??) - const metadataFieldName = StrCast(fieldTemplate.title).replace(/^-/, ""); - let fieldLayoutDoc = fieldTemplate; - if (fieldTemplate.layout instanceof Doc) { - fieldLayoutDoc = Doc.MakeDelegate(fieldTemplate.layout); - } - - fieldTemplate.templateField = metadataFieldName; - fieldTemplate.title = metadataFieldName; - fieldTemplate.isTemplateField = true; - /* move certain layout properties from the original data doc to the template layout to avoid - inheriting them from the template's data doc which may also define these fields for its own use. - */ - fieldTemplate.ignoreAspect = fieldTemplate.ignoreAspect === undefined ? undefined : BoolCast(fieldTemplate.ignoreAspect); - fieldTemplate.singleColumn = BoolCast(fieldTemplate.singleColumn); - fieldTemplate.nativeWidth = Cast(fieldTemplate.nativeWidth, "number"); - fieldTemplate.nativeHeight = Cast(fieldTemplate.nativeHeight, "number"); - fieldTemplate.type = fieldTemplate.type; - fieldTemplate.panX = 0; - fieldTemplate.panY = 0; - fieldTemplate.scale = 1; - fieldTemplate.showTitle = suppressTitle ? undefined : "title"; - const data = fieldTemplate.data; - // setTimeout(action(() => { - !templateDataDoc[metadataFieldName] && data instanceof ObjectField && (Doc.GetProto(templateDataDoc)[metadataFieldName] = ObjectField.MakeCopy(data)); - const layout = StrCast(fieldLayoutDoc.layout).replace(/fieldKey={'[^']*'}/, `fieldKey={'${metadataFieldName}'}`); - const layoutDelegate = Doc.Layout(fieldTemplate); - layoutDelegate.layout = layout; - fieldTemplate.layout = layoutDelegate !== fieldTemplate ? layoutDelegate : layout; - if (fieldTemplate.backgroundColor !== templateDataDoc.defaultBackgroundColor) fieldTemplate.defaultBackgroundColor = fieldTemplate.backgroundColor; - fieldTemplate.proto = templateDataDoc; - // }), 0); + // + // This function converts a generic field layout display into a field layout that displays a specific + // metadata field indicated by the title of the template field (not the default field that it was rendering) + // + export function MakeMetadataFieldTemplate(templateField: Doc, templateDoc: Opt<Doc>): boolean { + + // find the metadata field key that this template field doc will display (indicated by its title) + const metadataFieldKey = StrCast(templateField.title).replace(/^-/, ""); + + // update the original template to mark it as a template + templateField.isTemplateForField = metadataFieldKey; + templateField.title = metadataFieldKey; + + // move any data that the template field had been rendering over to the template doc so that things will still be rendered + // when the template field is adjusted to point to the new metadatafield key. + // note 1: if the template field contained a list of documents, each of those documents will be converted to templates as well. + // note 2: this will not overwrite any field that already exists on the template doc at the field key + if (!templateDoc?.[metadataFieldKey] && templateField.data instanceof ObjectField) { + Cast(templateField.data, listSpec(Doc), [])?.map(d => d instanceof Doc && MakeMetadataFieldTemplate(d, templateDoc)); + (Doc.GetProto(templateField)[metadataFieldKey] = ObjectField.MakeCopy(templateField.data)); + } + if (templateField.data instanceof RichTextField && templateField.data.Text) { + templateField._textTemplate = ComputedField.MakeFunction(`copyField(this.${metadataFieldKey})`, { this: Doc.name }); + } + + // get the layout string that the template uses to specify its layout + const templateFieldLayoutString = StrCast(Doc.LayoutField(Doc.Layout(templateField))); + + // change itto render the target metadata field instead of what it was rendering before and assign it to the template field layout document. + Doc.Layout(templateField).layout = templateFieldLayoutString.replace(/fieldKey={'[^']*'}/, `fieldKey={'${metadataFieldKey}'}`); + + // assign the template field doc a delegate of any extension document that was previously used to render the template field (since extension doc's carry rendering informatino) + Doc.Layout(templateField)[metadataFieldKey + "_ext"] = Doc.MakeDelegate(templateField[templateFieldLayoutString?.split("'")[1] + "_ext"] as Doc); + + if (templateField.backgroundColor !== templateDoc?.defaultBackgroundColor) { + templateField.defaultBackgroundColor = templateField.backgroundColor; + } + return true; } @@ -627,12 +636,12 @@ export namespace Doc { const doc1Layout = Doc.Layout(doc1); const x2 = NumCast(doc2.x) - clusterDistance; const y2 = NumCast(doc2.y) - clusterDistance; - const w2 = NumCast(doc2Layout.width) + clusterDistance; - const h2 = NumCast(doc2Layout.height) + clusterDistance; + const w2 = NumCast(doc2Layout._width) + clusterDistance; + const h2 = NumCast(doc2Layout._height) + clusterDistance; const x = NumCast(doc1.x) - clusterDistance; const y = NumCast(doc1.y) - clusterDistance; - const w = NumCast(doc1Layout.width) + clusterDistance; - const h = NumCast(doc1Layout.height) + clusterDistance; + const w = NumCast(doc1Layout._width) + clusterDistance; + const h = NumCast(doc1Layout._height) + clusterDistance; return doc1.z === doc2.z && intersectRect({ left: x, top: y, width: w, height: h }, { left: x2, top: y2, width: w2, height: h2 }); } @@ -657,9 +666,10 @@ export namespace Doc { // the document containing the view layout information - will be the Document itself unless the Document has // a layout field. In that case, all layout information comes from there unless overriden by Document - export function Layout(doc: Doc) { return Doc.LayoutField(doc) instanceof Doc ? doc[StrCast(doc.layoutKey, "layout")] as Doc : doc; } + export function Layout(doc: Doc) { return Doc.LayoutField(doc) instanceof Doc ? Doc.LayoutField(doc) as Doc : doc; } export function SetLayout(doc: Doc, layout: Doc | string) { doc[StrCast(doc.layoutKey, "layout")] = layout; } export function LayoutField(doc: Doc) { return doc[StrCast(doc.layoutKey, "layout")]; } + export function LayoutFieldKey(doc: Doc) { return StrCast(Doc.Layout(doc).layout).split("'")[1]; } const manager = new DocData(); export function SearchQuery(): string { return manager._searchQuery; } export function SetSearchQuery(query: string) { runInAction(() => manager._searchQuery = query); } @@ -692,7 +702,7 @@ export namespace Doc { export function LinkOtherAnchor(linkDoc: Doc, anchorDoc: Doc) { return Doc.AreProtosEqual(anchorDoc, Cast(linkDoc.anchor1, Doc) as Doc) ? Cast(linkDoc.anchor2, Doc) as Doc : Cast(linkDoc.anchor1, Doc) as Doc; } - export function LinkEndpoint(linkDoc: Doc, anchorDoc: Doc) { return Doc.AreProtosEqual(anchorDoc, Cast(linkDoc.anchor1, Doc) as Doc) ? "layoutKey1" : "layoutKey2"; } + export function LinkEndpoint(linkDoc: Doc, anchorDoc: Doc) { return Doc.AreProtosEqual(anchorDoc, Cast(linkDoc.anchor1, Doc) as Doc) ? "layout_key1" : "layout_key2"; } export function linkFollowUnhighlight() { Doc.UnhighlightAll(); @@ -700,9 +710,9 @@ export namespace Doc { } let dt = 0; - export function linkFollowHighlight(destDoc: Doc) { + export function linkFollowHighlight(destDoc: Doc, dataAndDisplayDocs = true) { linkFollowUnhighlight(); - Doc.HighlightDoc(destDoc); + Doc.HighlightDoc(destDoc, dataAndDisplayDocs); document.removeEventListener("pointerdown", linkFollowUnhighlight); document.addEventListener("pointerdown", linkFollowUnhighlight); const x = dt = Date.now(); @@ -716,10 +726,10 @@ export namespace Doc { export function IsHighlighted(doc: Doc) { return highlightManager.HighlightedDoc.get(doc) || highlightManager.HighlightedDoc.get(Doc.GetDataDoc(doc)); } - export function HighlightDoc(doc: Doc) { + export function HighlightDoc(doc: Doc, dataAndDisplayDocs = true) { runInAction(() => { highlightManager.HighlightedDoc.set(doc, true); - highlightManager.HighlightedDoc.set(Doc.GetDataDoc(doc), true); + dataAndDisplayDocs && highlightManager.HighlightedDoc.set(Doc.GetDataDoc(doc), true); }); } export function UnHighlightDoc(doc: Doc) { @@ -746,23 +756,27 @@ export namespace Doc { source.dragFactory instanceof Doc && source.dragFactory.isTemplateDoc ? source.dragFactory : source && source.layout instanceof Doc && source.layout.isTemplateDoc ? source.layout : undefined; } + export function setChildDetailedLayout(target: Doc, source?: Doc) { + target.childDetailed = source && source.isTemplateDoc ? source : source && + source.dragFactory instanceof Doc && source.dragFactory.isTemplateDoc ? source.dragFactory : + source && source.layout instanceof Doc && source.layout.isTemplateDoc ? source.layout : undefined; + } - export function MakeDocFilter(docFilters: string[]) { - let docFilterText = ""; - for (let i = 0; i < docFilters.length; i += 3) { - const key = docFilters[i]; - const value = docFilters[i + 1]; - const modifiers = docFilters[i + 2]; - const scriptText = `${modifiers === "x" ? "!" : ""}matchFieldValue(doc, "${key}", "${value}")`; - docFilterText = docFilterText ? docFilterText + " || " + scriptText : scriptText; + export function matchFieldValue(doc: Doc, key: string, value: any): boolean { + const fieldVal = doc[key] ? doc[key] : doc[key + "_ext"]; + if (Cast(fieldVal, listSpec("string"), []).length) { + const vals = Cast(fieldVal, listSpec("string"), []); + return vals.some(v => v === value); } - return docFilterText ? "(" + docFilterText + ")" : ""; + const fieldStr = Field.toString(fieldVal as Field); + return fieldStr === value; } } Scripting.addGlobal(function renameAlias(doc: any, n: any) { return StrCast(Doc.GetProto(doc).title).replace(/\([0-9]*\)/, "") + `(${n})`; }); Scripting.addGlobal(function getProto(doc: any) { return Doc.GetProto(doc); }); Scripting.addGlobal(function setChildLayout(target: any, source: any) { Doc.setChildLayout(target, source); }); +Scripting.addGlobal(function setChildDetailedLayout(target: any, source: any) { Doc.setChildDetailedLayout(target, source); }); Scripting.addGlobal(function getAlias(doc: any) { return Doc.MakeAlias(doc); }); Scripting.addGlobal(function getCopy(doc: any, copyProto: any) { return doc.isTemplateDoc ? Doc.ApplyTemplate(doc) : Doc.MakeCopy(doc, copyProto); }); Scripting.addGlobal(function copyField(field: any) { return ObjectField.MakeCopy(field); }); @@ -776,31 +790,18 @@ Scripting.addGlobal(function selectedDocs(container: Doc, excludeCollections: bo const docs = DocListCast(Doc.UserDoc().SelectedDocs).filter(d => !Doc.AreProtosEqual(d, container) && !d.annotationOn && d.type !== DocumentType.DOCUMENT && d.type !== DocumentType.KVP && (!excludeCollections || !Cast(d.data, listSpec(Doc), null))); return docs.length ? new List(docs) : prevValue; }); -Scripting.addGlobal(function matchFieldValue(doc: Doc, key: string, value: any) { - const fieldVal = doc[key] ? doc[key] : doc[key + "_ext"]; - if (StrCast(fieldVal, null) !== undefined) return StrCast(fieldVal) === value; - if (NumCast(fieldVal, null) !== undefined) return NumCast(fieldVal) === value; - if (Cast(fieldVal, listSpec("string"), []).length) { - const vals = Cast(fieldVal, listSpec("string"), []); - return vals.some(v => v === value); - } - return false; -}); -Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: any, modifiers: string) { - const docFilters = Cast(container.docFilter, listSpec("string"), []); - let found = false; - for (let i = 0; i < docFilters.length && !found; i += 3) { +Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: any, modifiers?: string) { + const docFilters = Cast(container._docFilter, listSpec("string"), []); + for (let i = 0; i < docFilters.length; i += 3) { if (docFilters[i] === key && docFilters[i + 1] === value) { - found = true; docFilters.splice(i, 3); + break; } } - if (!found || modifiers !== "none") { + if (modifiers !== undefined) { docFilters.push(key); docFilters.push(value); docFilters.push(modifiers); - container.docFilter = new List<string>(docFilters); + container._docFilter = new List<string>(docFilters); } - const docFilterText = Doc.MakeDocFilter(docFilters); - container.viewSpecScript = docFilterText ? ScriptField.MakeFunction(docFilterText, { doc: Doc.name }) : undefined; });
\ No newline at end of file diff --git a/src/new_fields/FieldSymbols.ts b/src/new_fields/FieldSymbols.ts index b5b3aa588..4aadb81a2 100644 --- a/src/new_fields/FieldSymbols.ts +++ b/src/new_fields/FieldSymbols.ts @@ -7,4 +7,5 @@ export const Id = Symbol("Id"); export const OnUpdate = Symbol("OnUpdate"); export const Parent = Symbol("Parent"); export const Copy = Symbol("Copy"); -export const ToScriptString = Symbol("ToScriptString");
\ No newline at end of file +export const ToScriptString = Symbol("ToScriptString"); +export const ToString = Symbol("ToString");
\ No newline at end of file diff --git a/src/new_fields/HtmlField.ts b/src/new_fields/HtmlField.ts index f952acff9..6e8bba977 100644 --- a/src/new_fields/HtmlField.ts +++ b/src/new_fields/HtmlField.ts @@ -1,7 +1,7 @@ import { Deserializable } from "../client/util/SerializationHelper"; import { serializable, primitive } from "serializr"; import { ObjectField } from "./ObjectField"; -import { Copy, ToScriptString } from "./FieldSymbols"; +import { Copy, ToScriptString, ToString} from "./FieldSymbols"; @Deserializable("html") export class HtmlField extends ObjectField { @@ -20,4 +20,7 @@ export class HtmlField extends ObjectField { [ToScriptString]() { return "invalid"; } + [ToString]() { + return this.html; + } } diff --git a/src/new_fields/IconField.ts b/src/new_fields/IconField.ts index 62b2cd254..76c4ddf1b 100644 --- a/src/new_fields/IconField.ts +++ b/src/new_fields/IconField.ts @@ -1,7 +1,7 @@ import { Deserializable } from "../client/util/SerializationHelper"; import { serializable, primitive } from "serializr"; import { ObjectField } from "./ObjectField"; -import { Copy, ToScriptString } from "./FieldSymbols"; +import { Copy, ToScriptString, ToString } from "./FieldSymbols"; @Deserializable("icon") export class IconField extends ObjectField { @@ -20,4 +20,7 @@ export class IconField extends ObjectField { [ToScriptString]() { return "invalid"; } + [ToString]() { + return "ICONfield"; + } } diff --git a/src/new_fields/InkField.ts b/src/new_fields/InkField.ts index 01493bcc2..4a44b4f55 100644 --- a/src/new_fields/InkField.ts +++ b/src/new_fields/InkField.ts @@ -1,7 +1,7 @@ import { Deserializable } from "../client/util/SerializationHelper"; import { serializable, custom, createSimpleSchema, list, object, map } from "serializr"; import { ObjectField } from "./ObjectField"; -import { Copy, ToScriptString } from "./FieldSymbols"; +import { Copy, ToScriptString, ToString } from "./FieldSymbols"; export enum InkTool { None, @@ -45,4 +45,7 @@ export class InkField extends ObjectField { [ToScriptString]() { return "invalid"; } + [ToString]() { + return "InkField"; + } } diff --git a/src/new_fields/List.ts b/src/new_fields/List.ts index bb48b1bb3..a43f11e82 100644 --- a/src/new_fields/List.ts +++ b/src/new_fields/List.ts @@ -6,7 +6,7 @@ import { observable, action } from "mobx"; import { ObjectField } from "./ObjectField"; import { RefField } from "./RefField"; import { ProxyField } from "./Proxy"; -import { Self, Update, Parent, OnUpdate, SelfProxy, ToScriptString, Copy } from "./FieldSymbols"; +import { Self, Update, Parent, OnUpdate, SelfProxy, ToScriptString, ToString, Copy } from "./FieldSymbols"; import { Scripting } from "../client/util/Scripting"; const listHandlers: any = { @@ -292,6 +292,9 @@ class ListImpl<T extends Field> extends ObjectField { [ToScriptString]() { return `new List([${(this as any).map((field: any) => Field.toScriptString(field))}])`; } + [ToString]() { + return "List"; + } } export type List<T extends Field> = ListImpl<T> & (T | (T extends RefField ? Promise<T> : never))[]; export const List: { new <T extends Field>(fields?: T[]): List<T> } = ListImpl as any; diff --git a/src/new_fields/ObjectField.ts b/src/new_fields/ObjectField.ts index 65ada91c0..566104b40 100644 --- a/src/new_fields/ObjectField.ts +++ b/src/new_fields/ObjectField.ts @@ -1,6 +1,6 @@ import { Doc } from "./Doc"; import { RefField } from "./RefField"; -import { OnUpdate, Parent, Copy, ToScriptString } from "./FieldSymbols"; +import { OnUpdate, Parent, Copy, ToScriptString, ToString } from "./FieldSymbols"; import { Scripting } from "../client/util/Scripting"; export abstract class ObjectField { @@ -9,11 +9,12 @@ export abstract class ObjectField { abstract [Copy](): ObjectField; abstract [ToScriptString](): string; + abstract [ToString](): string; } export namespace ObjectField { export function MakeCopy<T extends ObjectField>(field: T) { - return field[Copy](); + return field?.[Copy](); } } diff --git a/src/new_fields/Proxy.ts b/src/new_fields/Proxy.ts index c6292e37c..d50c0f14e 100644 --- a/src/new_fields/Proxy.ts +++ b/src/new_fields/Proxy.ts @@ -5,7 +5,7 @@ import { observable, action } from "mobx"; import { DocServer } from "../client/DocServer"; import { RefField } from "./RefField"; import { ObjectField } from "./ObjectField"; -import { Id, Copy, ToScriptString } from "./FieldSymbols"; +import { Id, Copy, ToScriptString, ToString } from "./FieldSymbols"; import { scriptingGlobal } from "../client/util/Scripting"; import { Plugins } from "./util"; @@ -32,6 +32,9 @@ export class ProxyField<T extends RefField> extends ObjectField { [ToScriptString]() { return "invalid"; } + [ToString]() { + return "ProxyField"; + } @serializable(primitive()) readonly fieldId: string = ""; diff --git a/src/new_fields/RefField.ts b/src/new_fields/RefField.ts index f7bea8c94..b6ef69750 100644 --- a/src/new_fields/RefField.ts +++ b/src/new_fields/RefField.ts @@ -1,6 +1,6 @@ import { serializable, primitive, alias } from "serializr"; import { Utils } from "../Utils"; -import { Id, HandleUpdate, ToScriptString } from "./FieldSymbols"; +import { Id, HandleUpdate, ToScriptString, ToString } from "./FieldSymbols"; import { afterDocDeserialize } from "../client/util/SerializationHelper"; export type FieldId = string; @@ -17,4 +17,5 @@ export abstract class RefField { protected [HandleUpdate]?(diff: any): void | Promise<void>; abstract [ToScriptString](): string; + abstract [ToString](): string; } diff --git a/src/new_fields/RichTextField.ts b/src/new_fields/RichTextField.ts index fd5459876..a0f21f45e 100644 --- a/src/new_fields/RichTextField.ts +++ b/src/new_fields/RichTextField.ts @@ -1,7 +1,7 @@ import { ObjectField } from "./ObjectField"; import { serializable } from "serializr"; import { Deserializable } from "../client/util/SerializationHelper"; -import { Copy, ToScriptString } from "./FieldSymbols"; +import { Copy, ToScriptString, ToString } from "./FieldSymbols"; import { scriptingGlobal } from "../client/util/Scripting"; @scriptingGlobal @@ -26,5 +26,8 @@ export class RichTextField extends ObjectField { [ToScriptString]() { return `new RichTextField("${this.Data}", "${this.Text}")`; } + [ToString]() { + return this.Text; + } }
\ No newline at end of file diff --git a/src/new_fields/RichTextUtils.ts b/src/new_fields/RichTextUtils.ts index 682206aa2..c50f8cc48 100644 --- a/src/new_fields/RichTextUtils.ts +++ b/src/new_fields/RichTextUtils.ts @@ -273,8 +273,8 @@ export namespace RichTextUtils { const guid = Utils.GenerateDeterministicGuid(src); const backingDocId = StrCast(textNote[guid]); if (!backingDocId) { - const backingDoc = Docs.Create.ImageDocument(src, { width: 300, height: 300 }); - DocumentView.makeCustomViewClicked(backingDoc, undefined); + const backingDoc = Docs.Create.ImageDocument(src, { _width: 300, _height: 300 }); + DocumentView.makeCustomViewClicked(backingDoc, undefined, Docs.Create.FreeformDocument); docid = backingDoc[Id]; textNote[guid] = docid; } else { @@ -403,7 +403,7 @@ export namespace RichTextUtils { let exported = (await Cast(linkDoc.anchor2, Doc))!; if (!exported.customLayout) { exported = Doc.MakeAlias(exported); - DocumentView.makeCustomViewClicked(exported, undefined); + DocumentView.makeCustomViewClicked(exported, undefined, Docs.Create.FreeformDocument); linkDoc.anchor2 = exported; } url = Utils.shareUrl(exported[Id]); diff --git a/src/new_fields/SchemaHeaderField.ts b/src/new_fields/SchemaHeaderField.ts index 42a8485ac..07c90f5a2 100644 --- a/src/new_fields/SchemaHeaderField.ts +++ b/src/new_fields/SchemaHeaderField.ts @@ -1,7 +1,7 @@ import { Deserializable } from "../client/util/SerializationHelper"; import { serializable, primitive } from "serializr"; import { ObjectField } from "./ObjectField"; -import { Copy, ToScriptString, OnUpdate } from "./FieldSymbols"; +import { Copy, ToScriptString, ToString, OnUpdate } from "./FieldSymbols"; import { scriptingGlobal } from "../client/util/Scripting"; import { ColumnType } from "../client/views/collections/CollectionSchemaView"; @@ -116,4 +116,7 @@ export class SchemaHeaderField extends ObjectField { [ToScriptString]() { return `invalid`; } + [ToString]() { + return `SchemaHeaderField`; + } }
\ No newline at end of file diff --git a/src/new_fields/ScriptField.ts b/src/new_fields/ScriptField.ts index b5ad4a7f6..f8a8d1226 100644 --- a/src/new_fields/ScriptField.ts +++ b/src/new_fields/ScriptField.ts @@ -1,9 +1,9 @@ import { ObjectField } from "./ObjectField"; import { CompiledScript, CompileScript, scriptingGlobal, ScriptOptions } from "../client/util/Scripting"; -import { Copy, ToScriptString, Parent, SelfProxy } from "./FieldSymbols"; +import { Copy, ToScriptString, ToString, Parent, SelfProxy } from "./FieldSymbols"; import { serializable, createSimpleSchema, map, primitive, object, deserialize, PropSchema, custom, SKIP } from "serializr"; import { Deserializable, autoObject } from "../client/util/SerializationHelper"; -import { Doc } from "../new_fields/Doc"; +import { Doc, Field } from "../new_fields/Doc"; import { Plugins } from "./util"; import { computedFn } from "mobx-utils"; import { ProxyField } from "./Proxy"; @@ -101,12 +101,16 @@ export class ScriptField extends ObjectField { [ToScriptString]() { return "script field"; } - public static CompileScript(script: string, params: object = {}, addReturn = false) { + [ToString]() { + return "script field"; + } + public static CompileScript(script: string, params: object = {}, addReturn = false, capturedVariables?: { [name: string]: Field }) { const compiled = CompileScript(script, { params: { this: Doc.name, _last_: "any", ...params }, typecheck: false, editable: true, - addReturn: addReturn + addReturn: addReturn, + capturedVariables }); return compiled; } @@ -127,12 +131,12 @@ export class ComputedField extends ScriptField { _lastComputedResult: any; //TODO maybe add an observable cache based on what is passed in for doc, considering there shouldn't really be that many possible values for doc value = computedFn((doc: Doc) => this._lastComputedResult = this.script.run({ this: doc, _last_: this._lastComputedResult }, console.log).result); - public static MakeScript(script: string, params: object = {}, ) { + public static MakeScript(script: string, params: object = {}) { const compiled = ScriptField.CompileScript(script, params, false); return compiled.compiled ? new ComputedField(compiled) : undefined; } - public static MakeFunction(script: string, params: object = {}) { - const compiled = ScriptField.CompileScript(script, params, true); + public static MakeFunction(script: string, params: object = {}, capturedVariables?: { [name: string]: Field }) { + const compiled = ScriptField.CompileScript(script, params, true, capturedVariables); return compiled.compiled ? new ComputedField(compiled) : undefined; } } diff --git a/src/new_fields/URLField.ts b/src/new_fields/URLField.ts index 35ef6dd02..cfab36906 100644 --- a/src/new_fields/URLField.ts +++ b/src/new_fields/URLField.ts @@ -1,7 +1,7 @@ import { Deserializable } from "../client/util/SerializationHelper"; import { serializable, custom } from "serializr"; import { ObjectField } from "./ObjectField"; -import { ToScriptString, Copy } from "./FieldSymbols"; +import { ToScriptString, ToString, Copy } from "./FieldSymbols"; import { Scripting, scriptingGlobal } from "../client/util/Scripting"; function url() { @@ -32,6 +32,9 @@ export abstract class URLField extends ObjectField { [ToScriptString]() { return `new ${this.constructor.name}("${this.url.href}")`; } + [ToString]() { + return this.url.href; + } [Copy](): this { return new (this.constructor as any)(this.url); diff --git a/src/new_fields/documentSchemas.ts b/src/new_fields/documentSchemas.ts index d5c34e128..4a5c1fdb0 100644 --- a/src/new_fields/documentSchemas.ts +++ b/src/new_fields/documentSchemas.ts @@ -4,20 +4,22 @@ import { Doc } from "./Doc"; import { DateField } from "./DateField"; export const documentSchema = createSchema({ - layout: "string", // this is the native layout string for the document. templates can be added using other fields and setting layoutKey below (see layoutCustom as an example) + layout: "string", // this is the native layout string for the document. templates can be added using other fields and setting layoutKey below (see layout_custom as an example) layoutKey: "string", // holds the field key for the field that actually holds the current lyoat - layoutCustom: Doc, // used to hold a custom layout (there's nothing special about this field .. any field could hold a custom layout that can be selected by setting 'layoutKey') + layout_custom: Doc, // used to hold a custom layout (there's nothing special about this field .. any field could hold a custom layout that can be selected by setting 'layoutKey') title: "string", // document title (can be on either data document or layout) - nativeWidth: "number", // native width of document which determines how much document contents are scaled when the document's width is set - nativeHeight: "number", // " - width: "number", // width of document in its container's coordinate system - height: "number", // " + _dropAction: "string", // override specifying what should happen when this document is dropped (can be "alias" or "copy") + _nativeWidth: "number", // native width of document which determines how much document contents are scaled when the document's width is set + _nativeHeight: "number", // " + _width: "number", // width of document in its container's coordinate system + _height: "number", // " + _freeformLayoutEngine: "string",// the string ID for the layout engine to use to layout freeform view documents + _LODdisable: "boolean", // whether to disbale LOD switching for CollectionFreeFormViews color: "string", // foreground color of document backgroundColor: "string", // background color of document opacity: "number", // opacity of document creationDate: DateField, // when the document was created links: listSpec(Doc), // computed (readonly) list of links associated with this document - dropAction: "string", // override specifying what should happen when this document is dropped (can be "alias" or "copy") removeDropProperties: listSpec("string"), // properties that should be removed from the alias/copy/etc of this document when it is dropped onClick: ScriptField, // script to run when document is clicked (can be overriden by an onClick prop) onPointerDown: ScriptField, // script to run when document is clicked (can be overriden by an onClick prop) @@ -26,7 +28,7 @@ export const documentSchema = createSchema({ dragFactory: Doc, // the document that serves as the "template" for the onDragStart script. ie, to drag out copies of the dragFactory document. ignoreAspect: "boolean", // whether aspect ratio should be ignored when laying out or manipulating the document autoHeight: "boolean", // whether the height of the document should be computed automatically based on its contents - isTemplateField: "boolean", // whether this document acts as a template layout for describing how other documents should be displayed + isTemplateForField: "string",// when specifies a field key, then the containing document is a template that renders the specified field isBackground: "boolean", // whether document is a background element and ignores input events (can only selet with marquee) type: "string", // enumerated type of document treeViewOpen: "boolean", // flag denoting whether the documents sub-tree (contents) is visible or hidden @@ -56,7 +58,6 @@ export const documentSchema = createSchema({ xPadding: "number", // pixels of padding on left/right of collectionfreeformview contents when fitToBox is set yPadding: "number", // pixels of padding on left/right of collectionfreeformview contents when fitToBox is set LODarea: "number", // area (width*height) where CollectionFreeFormViews switch from a label to rendering contents - LODdisable: "boolean", // whether to disbale LOD switching for CollectionFreeFormViews letterSpacing: "string", textTransform: "string" }); @@ -68,6 +69,13 @@ export const positionSchema = createSchema({ z: "number", }); +export const collectionSchema = createSchema({ + childLayout: Doc, // layout template for children of a collecion + childDetailed: Doc, // layout template to apply to a child when its clicked on in a collection and opened (requires onChildClick or other script to use this field) + onChildClick: ScriptField, // script to run for each child when its clicked + onCheckedClick: ScriptField, // script to run when a checkbox is clicked next to a child in a tree view +}); + export type Document = makeInterface<[typeof documentSchema]>; export const Document = makeInterface(documentSchema); diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts index 4147be278..2cedda7a6 100644 --- a/src/new_fields/util.ts +++ b/src/new_fields/util.ts @@ -1,12 +1,13 @@ import { UndoManager } from "../client/util/UndoManager"; import { Doc, Field, FieldResult, UpdatingFromServer } from "./Doc"; import { SerializationHelper } from "../client/util/SerializationHelper"; -import { ProxyField } from "./Proxy"; +import { ProxyField, PrefetchProxy } from "./Proxy"; import { RefField } from "./RefField"; import { ObjectField } from "./ObjectField"; import { action, trace } from "mobx"; import { Parent, OnUpdate, Update, Id, SelfProxy, Self } from "./FieldSymbols"; import { DocServer } from "../client/DocServer"; +import { props } from "bluebird"; function _readOnlySetter(): never { throw new Error("Documents can't be modified in read-only mode"); @@ -35,6 +36,7 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number target[prop] = value; return true; } + if (typeof prop === "symbol") { target[prop] = value; return true; @@ -52,7 +54,7 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number value = new ProxyField(value); } if (value instanceof ObjectField) { - if (value[Parent] && value[Parent] !== receiver) { + if (value[Parent] && value[Parent] !== receiver && !(value instanceof PrefetchProxy)) { throw new Error("Can't put the same object in multiple documents at the same time"); } value[Parent] = receiver; @@ -98,11 +100,38 @@ export function makeEditable() { _setter = _setterImpl; } -export function setter(target: any, prop: string | symbol | number, value: any, receiver: any): boolean { +let layoutProps = ["panX", "panY", "width", "height", "nativeWidth", "nativeHeight", "fitWidth", "fitToBox", + "LODdisable", "dropAction", "chromeStatus", "viewType", "gridGap", "xMargin", "yMargin", "autoHeight"]; +export function setter(target: any, in_prop: string | symbol | number, value: any, receiver: any): boolean { + let prop = in_prop; + if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && + ((prop as string).startsWith("_") || layoutProps.includes(prop))) { + if (!prop.startsWith("_")) { + console.log(prop + " is deprecated - switch to _" + prop); + prop = "_" + prop; + } + const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver); + if (resolvedLayout instanceof Doc) { + resolvedLayout[prop] = value; + return true; + } + } return _setter(target, prop, value, receiver); } -export function getter(target: any, prop: string | symbol | number, receiver: any): any { +export function getter(target: any, in_prop: string | symbol | number, receiver: any): any { + let prop = in_prop; + if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && + ((prop as string).startsWith("_") || layoutProps.includes(prop))) { + if (!prop.startsWith("_")) { + console.log(prop + " is deprecated - switch to _" + prop); + prop = "_" + prop; + } + const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver); + if (resolvedLayout instanceof Doc) { + return resolvedLayout[prop]; + } + } if (prop === "then") {//If we're being awaited return undefined; } diff --git a/src/scraping/buxton/scraper.py b/src/scraping/buxton/scraper.py index 2d1a5ca32..ec9c3f72c 100644 --- a/src/scraping/buxton/scraper.py +++ b/src/scraping/buxton/scraper.py @@ -85,13 +85,14 @@ def write_collection(parse_results, display_fields, storage_key, viewType): "proto": protofy(data_doc["_id"]), "x": 10, "y": 10, - "width": 900, - "height": 600, - "panX": 0, - "panY": 0, + "_width": 900, + "_height": 600, + "_panX": 0, + "_panY": 0, "zIndex": 2, "libraryBrush": False, - "viewType": viewType + "_viewType": viewType, + "_LODdisable": True }, "__type": "Doc" } @@ -99,10 +100,7 @@ def write_collection(parse_results, display_fields, storage_key, viewType): fields["proto"] = protofy(common_proto_id) fields[storage_key] = listify(proxify_guids(view_guids)) fields["schemaColumns"] = listify(display_fields) - fields["backgroundColor"] = "white" - fields["viewType"] = 2 fields["author"] = "Bill Buxton" - fields["disableLOD"] = True fields["creationDate"] = { "date": datetime.datetime.utcnow().microsecond, "__type": "date" @@ -113,7 +111,6 @@ def write_collection(parse_results, display_fields, storage_key, viewType): "__type": "image" } fields["isPrototype"] = True - fields["page"] = -1 target_collection.insert_one(data_doc) target_collection.insert_one(view_doc) @@ -135,7 +132,7 @@ def write_text_doc(content): "proto": protofy(data_doc_guid), "x": 10, "y": 10, - "width": 400, + "_width": 400, "zIndex": 2 }, "__type": "Doc" @@ -150,17 +147,17 @@ def write_text_doc(content): "__type": "RichTextField" }, "title": content, - "nativeWidth": 200, + "_nativeWidth": 200, "author": "Bill Buxton", "creationDate": { "date": datetime.datetime.utcnow().microsecond, "__type": "date" }, "isPrototype": True, - "autoHeight": True, + "_autoHeight": True, "page": -1, - "nativeHeight": 200, - "height": 200, + "_nativeHeight": 200, + "_height": 200, "data_text": content }, "__type": "Doc" @@ -190,8 +187,10 @@ def write_image(folder, name): "proto": protofy(data_doc_guid), "x": 10, "y": 10, - "width": min(800, native_width), - "zIndex": 2 + "_width": min(800, native_width), + "zIndex": 2, + "widthUnit": "*", + "widthMagnitude": 1 }, "__type": "Doc" } @@ -205,7 +204,7 @@ def write_image(folder, name): "__type": "image" }, "title": name, - "nativeWidth": native_width, + "_nativeWidth": native_width, "author": "Bill Buxton", "creationDate": { "date": datetime.datetime.utcnow().microsecond, @@ -213,8 +212,8 @@ def write_image(folder, name): }, "isPrototype": True, "page": -1, - "nativeHeight": native_height, - "height": native_height + "_nativeHeight": native_height, + "_height": native_height }, "__type": "Doc" } @@ -366,7 +365,7 @@ def parse_document(file_name: str): def proxify_guids(guids): - return list(map(lambda guid: {"fieldId": guid, "__type": "proxy"}, guids)) + return list(map(lambda guid: {"fieldId": guid, "__type": "prefetch_proxy"}, guids)) def write_common_proto(): @@ -407,7 +406,7 @@ parent_guid = write_collection({ "__type": "Doc" }, "child_guids": schema_guids -}, ["title", "short_description", "original_price"], "data", 4) +}, ["title", "short_description", "original_price"], "data", 2) print("appending parent schema to main workspace...\n") target_collection.update_one( diff --git a/src/server/ApiManagers/UploadManager.ts b/src/server/ApiManagers/UploadManager.ts index 74f45ae62..a92b613b7 100644 --- a/src/server/ApiManagers/UploadManager.ts +++ b/src/server/ApiManagers/UploadManager.ts @@ -40,7 +40,7 @@ export default class UploadManager extends ApiManager { register({ method: Method.POST, - subscription: "/upload", + subscription: "/uploadFormData", secureHandler: async ({ req, res }) => { const form = new formidable.IncomingForm(); form.uploadDir = pathToDirectory(Directory.parsed_files); @@ -61,6 +61,18 @@ export default class UploadManager extends ApiManager { register({ method: Method.POST, + subscription: "/uploadRemoteImage", + secureHandler: async ({ req, res }) => { + const { sources } = req.body; + if (Array.isArray(sources)) { + return res.send(await Promise.all(sources.map(url => DashUploadUtils.UploadImage(url)))); + } + res.send(); + } + }); + + register({ + method: Method.POST, subscription: "/uploadDoc", secureHandler: ({ req, res }) => { const form = new formidable.IncomingForm(); @@ -169,8 +181,7 @@ export default class UploadManager extends ApiManager { secureHandler: async ({ req, res }) => { const { source } = req.body; if (typeof source === "string") { - const { serverAccessPaths } = await DashUploadUtils.UploadImage(source); - return res.send(await DashUploadUtils.InspectImage(serverAccessPaths[SizeSuffix.Original])); + return res.send(await DashUploadUtils.InspectImage(source)); } res.send({}); } diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts index d9d985ca5..cb7104757 100644 --- a/src/server/DashUploadUtils.ts +++ b/src/server/DashUploadUtils.ts @@ -1,4 +1,4 @@ -import * as fs from 'fs'; +import { unlinkSync, createWriteStream, readFileSync, rename } from 'fs'; import { Utils } from '../Utils'; import * as path from 'path'; import * as sharp from 'sharp'; @@ -12,8 +12,9 @@ import { basename } from "path"; import { createIfNotExists } from './ActionUtilities'; import { ParsedPDF } from "../server/PdfTypes"; const parse = require('pdf-parse'); -import { Directory, serverPathToFile, clientPathToFile } from './ApiManagers/UploadManager'; +import { Directory, serverPathToFile, clientPathToFile, pathToDirectory } from './ApiManagers/UploadManager'; import { red } from 'colors'; +const requestImageSize = require("../client/util/request-image-size"); export enum SizeSuffix { Small = "_s", @@ -27,6 +28,10 @@ export function InjectSize(filename: string, size: SizeSuffix) { return filename.substring(0, filename.length - extension.length) + size + extension; } +function isLocal() { + return /Dash-Web[\\\/]src[\\\/]server[\\\/]public[\\\/](.*)/; +} + export namespace DashUploadUtils { export interface Size { @@ -92,24 +97,18 @@ export namespace DashUploadUtils { } async function UploadPdf(absolutePath: string) { - const dataBuffer = fs.readFileSync(absolutePath); + const dataBuffer = readFileSync(absolutePath); const result: ParsedPDF = await parse(dataBuffer); const parsedName = basename(absolutePath); await new Promise<void>((resolve, reject) => { const textFilename = `${parsedName.substring(0, parsedName.length - 4)}.txt`; - const writeStream = fs.createWriteStream(serverPathToFile(Directory.text, textFilename)); + const writeStream = createWriteStream(serverPathToFile(Directory.text, textFilename)); writeStream.write(result.text, error => error ? reject(error) : resolve()); }); return MoveParsedFile(absolutePath, Directory.pdfs); } - const generate = (prefix: string, url: string) => `${prefix}upload_${Utils.GenerateGuid()}${sanitizeExtension(url)}`; - const sanitizeExtension = (source: string) => { - let extension = path.extname(source); - extension = extension.toLowerCase(); - extension = extension.split("?")[0]; - return extension; - }; + const generate = (prefix: string, extension: string) => `${prefix}upload_${Utils.GenerateGuid()}.${extension}`; /** * Uploads an image specified by the @param source to Dash's /public/files/ @@ -134,12 +133,13 @@ export namespace DashUploadUtils { }; export interface InspectionResults { - isLocal: boolean; - stream: any; - normalizedUrl: string; + source: string; + requestable: string; exifData: EnrichedExifData; - contentSize?: number; - contentType?: string; + contentSize: number; + contentType: string; + nativeWidth: number; + nativeHeight: number; } export interface EnrichedExifData { @@ -152,6 +152,12 @@ export namespace DashUploadUtils { return Promise.all(pending); } + export interface RequestedImageSize { + width: number; + height: number; + type: string; + } + /** * Based on the url's classification as local or remote, gleans * as much information as possible about the specified image @@ -159,24 +165,28 @@ export namespace DashUploadUtils { * @param source is the path or url to the image in question */ export const InspectImage = async (source: string): Promise<InspectionResults> => { - const { isLocal, stream, normalized: normalizedUrl } = classify(source); - const exifData = await parseExifData(source); + let resolvedUrl: string; + const matches = isLocal().exec(source); + if (matches === null) { + resolvedUrl = source; + } else { + resolvedUrl = `http://localhost:1050/${matches[1].split("\\").join("/")}`; + } + const exifData = await parseExifData(resolvedUrl); const results = { exifData, - isLocal, - stream, - normalizedUrl + requestable: resolvedUrl }; - // stop here if local, since request.head() can't handle local paths, only urls on the web - if (isLocal) { - return results; - } const { headers } = (await new Promise<any>((resolve, reject) => { - request.head(source, (error, res) => error ? reject(error) : resolve(res)); - })); + request.head(resolvedUrl, (error, res) => error ? reject(error) : resolve(res)); + }).catch(error => console.error(error))); + const { width: nativeWidth, height: nativeHeight }: RequestedImageSize = await requestImageSize(resolvedUrl); return { + source, contentSize: parseInt(headers[size]), contentType: headers[type], + nativeWidth, + nativeHeight, ...results }; }; @@ -185,22 +195,20 @@ export namespace DashUploadUtils { return new Promise<{ clientAccessPath: Opt<string> }>(resolve => { const filename = basename(absolutePath); const destinationPath = serverPathToFile(destination, filename); - fs.rename(absolutePath, destinationPath, error => { + rename(absolutePath, destinationPath, error => { resolve({ clientAccessPath: error ? undefined : clientPathToFile(destination, filename) }); }); }); } export const UploadInspectedImage = async (metadata: InspectionResults, filename?: string, format?: string, prefix = ""): Promise<ImageUploadInformation> => { - const { isLocal, stream, normalizedUrl, contentSize, contentType, exifData } = metadata; - const resolved = filename || generate(prefix, normalizedUrl); - const extension = format || sanitizeExtension(normalizedUrl || resolved); + const { requestable, source, ...remaining } = metadata; + const extension = remaining.contentType.toLowerCase().split("/")[1]; //format || sanitizeExtension(requestable || resolved); + const resolved = filename || generate(prefix, extension); const information: ImageUploadInformation = { clientAccessPath: clientPathToFile(Directory.images, resolved), serverAccessPaths: {}, - exifData, - contentSize, - contentType, + ...remaining }; const { pngs, jpgs } = AcceptibleMedia; return new Promise<ImageUploadInformation>(async (resolve, reject) => { @@ -220,32 +228,22 @@ export namespace DashUploadUtils { await new Promise<void>(resolve => { const filename = InjectSize(resolved, suffix); information.serverAccessPaths[suffix] = serverPathToFile(Directory.images, filename); - stream(normalizedUrl).pipe(resizer).pipe(fs.createWriteStream(serverPathToFile(Directory.images, filename))) + request(requestable).pipe(resizer).pipe(createWriteStream(serverPathToFile(Directory.images, filename))) .on('close', resolve) .on('error', reject); }); } - if (isLocal) { - await new Promise<boolean>(resolve => { - fs.unlink(normalizedUrl, error => resolve(error === null)); - }); + if (isLocal().test(source)) { + unlinkSync(source); } resolve(information); }); }; - const classify = (url: string) => { - const isLocal = /Dash-Web(\\|\/)src(\\|\/)server(\\|\/)public(\\|\/)files/g.test(url); - return { - isLocal, - stream: isLocal ? fs.createReadStream : request, - normalized: isLocal ? path.normalize(url) : url - }; - }; - const parseExifData = async (source: string): Promise<EnrichedExifData> => { + const image = await request.get(source, { encoding: null }); return new Promise<EnrichedExifData>(resolve => { - new ExifImage(source, (error, data) => { + new ExifImage({ image }, (error, data) => { let reason: Opt<string> = undefined; if (error) { reason = (error as any).code; diff --git a/src/server/RouteManager.ts b/src/server/RouteManager.ts index 6bc75ca21..63e957cd1 100644 --- a/src/server/RouteManager.ts +++ b/src/server/RouteManager.ts @@ -180,7 +180,7 @@ export const STATUS = { }; export function _error(res: Response, message: string, error?: any) { - console.error(message); + console.error(message, error); res.statusMessage = message; res.status(STATUS.EXECUTION_ERROR).send(error); } diff --git a/src/server/Websocket/Websocket.ts b/src/server/Websocket/Websocket.ts index 9e6ad1c72..a2fdc7c89 100644 --- a/src/server/Websocket/Websocket.ts +++ b/src/server/Websocket/Websocket.ts @@ -124,8 +124,6 @@ export namespace WebSocket { socket.broadcast.emit(MessageStore.SetField.Message, newValue)); if (newValue.type === Types.Text) { Search.updateDocument({ id: newValue.id, data: (newValue as any).data }); - console.log("set field"); - console.log("checking in"); } } diff --git a/src/server/authentication/models/current_user_utils.ts b/src/server/authentication/models/current_user_utils.ts index b383bc8b6..dbde351b3 100644 --- a/src/server/authentication/models/current_user_utils.ts +++ b/src/server/authentication/models/current_user_utils.ts @@ -14,6 +14,7 @@ import { Utils } from "../../../Utils"; import { nullAudio } from "../../../new_fields/URLField"; import { DragManager } from "../../../client/util/DragManager"; import { InkingControl } from "../../../client/views/InkingControl"; +import { CollectionViewType } from "../../../client/views/collections/CollectionView"; export class CurrentUserUtils { private static curr_id: string; @@ -33,29 +34,29 @@ export class CurrentUserUtils { // a default set of note types .. not being used yet... static setupNoteTypes(doc: Doc) { return [ - Docs.Create.TextDocument({ title: "Note", backgroundColor: "yellow", isTemplateDoc: true }), - Docs.Create.TextDocument({ title: "Idea", backgroundColor: "pink", isTemplateDoc: true }), - Docs.Create.TextDocument({ title: "Topic", backgroundColor: "lightBlue", isTemplateDoc: true }), - Docs.Create.TextDocument({ title: "Person", backgroundColor: "lightGreen", isTemplateDoc: true }), - Docs.Create.TextDocument({ title: "Todo", backgroundColor: "orange", isTemplateDoc: true }) + Docs.Create.TextDocument("", { title: "Note", backgroundColor: "yellow", isTemplateDoc: true }), + Docs.Create.TextDocument("", { title: "Idea", backgroundColor: "pink", isTemplateDoc: true }), + Docs.Create.TextDocument("", { title: "Topic", backgroundColor: "lightBlue", isTemplateDoc: true }), + Docs.Create.TextDocument("", { title: "Person", backgroundColor: "lightGreen", isTemplateDoc: true }), + Docs.Create.TextDocument("", { title: "Todo", backgroundColor: "orange", isTemplateDoc: true }) ]; } // setup the "creator" buttons for the sidebar-- eg. the default set of draggable document creation tools static setupCreatorButtons(doc: Doc, buttons?: string[]) { const notes = CurrentUserUtils.setupNoteTypes(doc); - doc.noteTypes = Docs.Create.TreeDocument(notes, { title: "Note Types", height: 75 }); + doc.noteTypes = Docs.Create.TreeDocument(notes, { title: "Note Types", _height: 75 }); doc.activePen = doc; const docProtoData: { title: string, icon: string, drag?: string, ignoreClick?: boolean, click?: string, ischecked?: string, activePen?: Doc, backgroundColor?: string, dragFactory?: Doc }[] = [ - { title: "collection", icon: "folder", ignoreClick: true, drag: 'Docs.Create.FreeformDocument([], { nativeWidth: undefined, nativeHeight: undefined, width: 150, height: 100, title: "freeform" })' }, - { title: "preview", icon: "expand", ignoreClick: true, drag: 'Docs.Create.DocumentDocument(ComputedField.MakeFunction("selectedDocs(this,true,[_last_])?.[0]"), { width: 250, height: 250, title: "container" })' }, + { title: "collection", icon: "folder", ignoreClick: true, drag: 'Docs.Create.FreeformDocument([], { _nativeWidth: undefined, _nativeHeight: undefined, _LODdisable: true, _width: 150, _height: 100, title: "freeform" })' }, + { title: "preview", icon: "expand", ignoreClick: true, drag: 'Docs.Create.DocumentDocument(ComputedField.MakeFunction("selectedDocs(this,true,[_last_])?.[0]"), { _width: 250, _height: 250, title: "container" })' }, { title: "todo item", icon: "check", ignoreClick: true, drag: 'getCopy(this.dragFactory, true)', dragFactory: notes[notes.length - 1] }, - { title: "web page", icon: "globe-asia", ignoreClick: true, drag: 'Docs.Create.WebDocument("https://en.wikipedia.org/wiki/Hedgehog", { width: 300, height: 300, title: "New Webpage" })' }, - { title: "cat image", icon: "cat", ignoreClick: true, drag: 'Docs.Create.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", { width: 200, title: "an image of a cat" })' }, - { title: "record", icon: "microphone", ignoreClick: true, drag: `Docs.Create.AudioDocument("${nullAudio}", { width: 200, title: "ready to record audio" })` }, - { title: "clickable button", icon: "bolt", ignoreClick: true, drag: 'Docs.Create.ButtonDocument({ width: 150, height: 50, title: "Button" })' }, - { title: "presentation", icon: "tv", ignoreClick: true, drag: 'Doc.UserDoc().curPresentation = Docs.Create.PresDocument(new List<Doc>(), { width: 200, height: 500, title: "a presentation trail" })' }, - { title: "import folder", icon: "cloud-upload-alt", ignoreClick: true, drag: 'Docs.Create.DirectoryImportDocument({ title: "Directory Import", width: 400, height: 400 })' }, + { title: "web page", icon: "globe-asia", ignoreClick: true, drag: 'Docs.Create.WebDocument("https://en.wikipedia.org/wiki/Hedgehog", {_width: 300, _height: 300, title: "New Webpage" })' }, + { title: "cat image", icon: "cat", ignoreClick: true, drag: 'Docs.Create.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", { _width: 200, title: "an image of a cat" })' }, + { title: "record", icon: "microphone", ignoreClick: true, drag: `Docs.Create.AudioDocument("${nullAudio}", { _width: 200, title: "ready to record audio" })` }, + { title: "clickable button", icon: "bolt", ignoreClick: true, drag: 'Docs.Create.ButtonDocument({ _width: 150, _height: 50, title: "Button" })' }, + { title: "presentation", icon: "tv", ignoreClick: true, drag: `Doc.UserDoc().curPresentation = Docs.Create.PresDocument(new List<Doc>(), { _width: 200, _height: 500, _viewType: ${CollectionViewType.Stacking}, title: "a presentation trail" })` }, + { title: "import folder", icon: "cloud-upload-alt", ignoreClick: true, drag: 'Docs.Create.DirectoryImportDocument({ title: "Directory Import", _width: 400, _height: 400 })' }, { title: "mobile view", icon: "phone", ignoreClick: true, drag: 'Doc.UserDoc().activeMobile' }, { title: "use pen", icon: "pen-nib", click: 'activatePen(this.activePen.pen = sameDocs(this.activePen.pen, this) ? undefined : this,2, this.backgroundColor)', backgroundColor: "blue", ischecked: `sameDocs(this.activePen.pen, this)`, activePen: doc }, { title: "use highlighter", icon: "highlighter", click: 'activateBrush(this.activePen.pen = sameDocs(this.activePen.pen, this) ? undefined : this,20,this.backgroundColor)', backgroundColor: "yellow", ischecked: `sameDocs(this.activePen.pen, this)`, activePen: doc }, @@ -65,7 +66,7 @@ export class CurrentUserUtils { { title: "use drag", icon: "mouse-pointer", click: 'deactivateInk();this.activePen.pen = this;', ischecked: `sameDocs(this.activePen.pen, this)`, backgroundColor: "white", activePen: doc }, ]; return docProtoData.filter(d => !buttons || !buttons.includes(d.title)).map(data => Docs.Create.FontIconDocument({ - nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, dropAction: data.click ? "copy" : undefined, title: data.title, icon: data.icon, ignoreClick: data.ignoreClick, + _nativeWidth: 100, _nativeHeight: 100, _width: 100, _height: 100, _dropAction: data.click ? "copy" : undefined, title: data.title, icon: data.icon, ignoreClick: data.ignoreClick, onDragStart: data.drag ? ScriptField.MakeFunction(data.drag) : undefined, onClick: data.click ? ScriptField.MakeScript(data.click) : undefined, ischecked: data.ischecked ? ComputedField.MakeFunction(data.ischecked) : undefined, activePen: data.activePen, backgroundColor: data.backgroundColor, removeDropProperties: new List<string>(["dropAction"]), dragFactory: data.dragFactory, @@ -103,7 +104,7 @@ export class CurrentUserUtils { { title: "use drag", icon: "mouse-pointer", click: 'deactivateInk();this.activePen.pen = this;', ischecked: `sameDocs(this.activePen.pen, this)`, backgroundColor: "white", activePen: doc }, ]; return docProtoData.filter(d => !buttons || !buttons.includes(d.title)).map(data => Docs.Create.FontIconDocument({ - nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, dropAction: data.click ? "copy" : undefined, title: data.title, icon: data.icon, ignoreClick: data.ignoreClick, + _nativeWidth: 100, _nativeHeight: 100, _width: 100, _height: 100, _dropAction: data.click ? "copy" : undefined, title: data.title, icon: data.icon, ignoreClick: data.ignoreClick, onDragStart: data.drag ? ScriptField.MakeFunction(data.drag) : undefined, onClick: data.click ? ScriptField.MakeScript(data.click) : undefined, ischecked: data.ischecked ? ComputedField.MakeFunction(data.ischecked) : undefined, activePen: data.activePen, backgroundColor: data.backgroundColor, removeDropProperties: new List<string>(["dropAction"]), dragFactory: data.dragFactory, @@ -114,12 +115,12 @@ export class CurrentUserUtils { const docProtoData: { title: string, icon: string, drag?: string, ignoreClick?: boolean, pointerDown?: string, pointerUp?: string, ischecked?: string, clipboard?: Doc, activePen?: Doc, backgroundColor?: string, dragFactory?: Doc }[] = [ { title: "use pen", icon: "pen-nib", pointerUp: "resetPen()", pointerDown: 'setPen(2, this.backgroundColor)', backgroundColor: "blue", ischecked: `sameDocs(this.activePen.pen, this)`, activePen: doc }, { title: "use highlighter", icon: "highlighter", pointerUp: "resetPen()", pointerDown: 'setPen(20, this.backgroundColor)', backgroundColor: "yellow", ischecked: `sameDocs(this.activePen.pen, this)`, activePen: doc }, - { title: "notepad", icon: "clipboard", pointerUp: "GestureOverlay.Instance.closeFloatingDoc()", pointerDown: 'GestureOverlay.Instance.openFloatingDoc(this.clipboard)', clipboard: Docs.Create.FreeformDocument([], { width: 300, height: 300 }), backgroundColor: "orange", ischecked: `sameDocs(this.activePen.pen, this)`, activePen: doc }, + { title: "notepad", icon: "clipboard", pointerUp: "GestureOverlay.Instance.closeFloatingDoc()", pointerDown: 'GestureOverlay.Instance.openFloatingDoc(this.clipboard)', clipboard: Docs.Create.FreeformDocument([], { _width: 300, _height: 300 }), backgroundColor: "orange", ischecked: `sameDocs(this.activePen.pen, this)`, activePen: doc }, { title: "interpret text", icon: "font", pointerUp: "setToolglass('none')", pointerDown: "setToolglass('inktotext')", backgroundColor: "orange", ischecked: `sameDocs(this.activePen.pen, this)`, activePen: doc }, { title: "ignore gestures", icon: "signature", pointerUp: "setToolglass('none')", pointerDown: "setToolglass('ignoregesture')", backgroundColor: "green", ischecked: `sameDocs(this.activePen.pen, this)`, activePen: doc }, ]; return docProtoData.map(data => Docs.Create.FontIconDocument({ - nativeWidth: 10, nativeHeight: 10, width: 10, height: 10, dropAction: data.pointerDown ? "copy" : undefined, title: data.title, icon: data.icon, ignoreClick: data.ignoreClick, + _nativeWidth: 10, _nativeHeight: 10, _width: 10, _height: 10, _dropAction: data.pointerDown ? "copy" : undefined, title: data.title, icon: data.icon, ignoreClick: data.ignoreClick, onDragStart: data.drag ? ScriptField.MakeFunction(data.drag) : undefined, clipboard: data.clipboard, onPointerUp: data.pointerUp ? ScriptField.MakeScript(data.pointerUp) : undefined, onPointerDown: data.pointerDown ? ScriptField.MakeScript(data.pointerDown) : undefined, @@ -131,7 +132,7 @@ export class CurrentUserUtils { static setupThumbDoc(userDoc: Doc) { if (!userDoc.thumbDoc) { userDoc.thumbDoc = Docs.Create.LinearDocument(CurrentUserUtils.setupThumbButtons(userDoc), { - width: 100, height: 50, ignoreClick: true, lockedPosition: true, chromeStatus: "disabled", title: "buttons", autoHeight: true, yMargin: 5, isExpanded: true, backgroundColor: "white" + _width: 100, _height: 50, ignoreClick: true, lockedPosition: true, _chromeStatus: "disabled", title: "buttons", _autoHeight: true, _yMargin: 5, isExpanded: true, backgroundColor: "white" }); } return userDoc.thumbDoc; @@ -139,7 +140,7 @@ export class CurrentUserUtils { static setupMobileDoc(userDoc: Doc) { return userDoc.activeMoble ?? Docs.Create.MasonryDocument(CurrentUserUtils.setupMobileButtons(userDoc), { - columnWidth: 100, ignoreClick: true, lockedPosition: true, chromeStatus: "disabled", title: "buttons", autoHeight: true, yMargin: 5 + columnWidth: 100, ignoreClick: true, lockedPosition: true, _chromeStatus: "disabled", title: "buttons", _autoHeight: true, _yMargin: 5 }); } @@ -147,19 +148,19 @@ export class CurrentUserUtils { static setupToolsPanel(sidebarContainer: Doc, doc: Doc) { // setup a masonry view of all he creators const dragCreators = Docs.Create.MasonryDocument(CurrentUserUtils.setupCreatorButtons(doc), { - width: 500, autoHeight: true, columnWidth: 35, ignoreClick: true, lockedPosition: true, chromeStatus: "disabled", title: "buttons", - dropConverter: ScriptField.MakeScript("convertToButtons(dragData)", { dragData: DragManager.DocumentDragData.name }), yMargin: 5 + _width: 500, _autoHeight: true, columnWidth: 35, ignoreClick: true, lockedPosition: true, _chromeStatus: "disabled", title: "buttons", + dropConverter: ScriptField.MakeScript("convertToButtons(dragData)", { dragData: DragManager.DocumentDragData.name }), _yMargin: 5 }); // setup a color picker const color = Docs.Create.ColorDocument({ - title: "color picker", width: 400, dropAction: "alias", forceActive: true, removeDropProperties: new List<string>(["dropAction", "forceActive"]) + title: "color picker", _width: 300, _dropAction: "alias", forceActive: true, removeDropProperties: new List<string>(["dropAction", "forceActive"]) }); return Docs.Create.ButtonDocument({ - width: 35, height: 25, backgroundColor: "lightgrey", color: "rgb(34, 34, 34)", title: "Tools", fontSize: 10, targetContainer: sidebarContainer, + _width: 35, _height: 25, backgroundColor: "lightgrey", color: "rgb(34, 34, 34)", title: "Tools", fontSize: 10, targetContainer: sidebarContainer, letterSpacing: "0px", textTransform: "unset", borderRounding: "5px 5px 0px 0px", boxShadow: "3px 3px 0px rgb(34, 34, 34)", sourcePanel: Docs.Create.StackingDocument([dragCreators, color], { - width: 500, height: 800, lockedPosition: true, chromeStatus: "disabled", title: "tools stack" + _width: 500, lockedPosition: true, _chromeStatus: "disabled", title: "tools stack" }), onClick: ScriptField.MakeScript("this.targetContainer.proto = this.sourcePanel"), }); @@ -169,23 +170,23 @@ export class CurrentUserUtils { static setupLibraryPanel(sidebarContainer: Doc, doc: Doc) { // setup workspaces library item doc.workspaces = Docs.Create.TreeDocument([], { - title: "WORKSPACES", height: 100, forceActive: true, boxShadow: "0 0", lockedPosition: true, backgroundColor: "#eeeeee" + title: "WORKSPACES", _height: 100, forceActive: true, boxShadow: "0 0", lockedPosition: true, backgroundColor: "#eeeeee" }); doc.documents = Docs.Create.TreeDocument([], { - title: "DOCUMENTS", height: 42, forceActive: true, boxShadow: "0 0", preventTreeViewOpen: true, lockedPosition: true, backgroundColor: "#eeeeee" + title: "DOCUMENTS", _height: 42, forceActive: true, boxShadow: "0 0", preventTreeViewOpen: true, lockedPosition: true, backgroundColor: "#eeeeee" }); // setup Recently Closed library item doc.recentlyClosed = Docs.Create.TreeDocument([], { - title: "RECENTLY CLOSED", height: 75, forceActive: true, boxShadow: "0 0", preventTreeViewOpen: true, lockedPosition: true, backgroundColor: "#eeeeee" + title: "RECENTLY CLOSED", _height: 75, forceActive: true, boxShadow: "0 0", preventTreeViewOpen: true, lockedPosition: true, backgroundColor: "#eeeeee" }); return Docs.Create.ButtonDocument({ - width: 50, height: 25, backgroundColor: "lightgrey", color: "rgb(34, 34, 34)", title: "Library", fontSize: 10, + _width: 50, _height: 25, backgroundColor: "lightgrey", color: "rgb(34, 34, 34)", title: "Library", fontSize: 10, letterSpacing: "0px", textTransform: "unset", borderRounding: "5px 5px 0px 0px", boxShadow: "3px 3px 0px rgb(34, 34, 34)", sourcePanel: Docs.Create.TreeDocument([doc.workspaces as Doc, doc.documents as Doc, doc.recentlyClosed as Doc], { - title: "Library", xMargin: 5, yMargin: 5, gridGap: 5, forceActive: true, dropAction: "alias", lockedPosition: true, boxShadow: "0 0", + title: "Library", _xMargin: 5, _yMargin: 5, _gridGap: 5, forceActive: true, _dropAction: "alias", lockedPosition: true, boxShadow: "0 0", }), targetContainer: sidebarContainer, onClick: ScriptField.MakeScript("this.targetContainer.proto = this.sourcePanel;") @@ -195,7 +196,7 @@ export class CurrentUserUtils { // setup the Search button which will display the search panel. static setupSearchPanel(sidebarContainer: Doc) { return Docs.Create.ButtonDocument({ - width: 50, height: 25, backgroundColor: "lightgrey", color: "rgb(34, 34, 34)", title: "Search", fontSize: 10, + _width: 50, _height: 25, backgroundColor: "lightgrey", color: "rgb(34, 34, 34)", title: "Search", fontSize: 10, letterSpacing: "0px", textTransform: "unset", borderRounding: "5px 5px 0px 0px", boxShadow: "3px 3px 0px rgb(34, 34, 34)", sourcePanel: Docs.Create.QueryDocument({ title: "search stack", ignoreClick: true @@ -209,7 +210,7 @@ export class CurrentUserUtils { // setup the list of sidebar mode buttons which determine what is displayed in the sidebar static setupSidebarButtons(doc: Doc) { doc.sidebarContainer = new Doc(); - (doc.sidebarContainer as Doc).chromeStatus = "disabled"; + (doc.sidebarContainer as Doc)._chromeStatus = "disabled"; (doc.sidebarContainer as Doc).onClick = ScriptField.MakeScript("freezeSidebar()"); doc.ToolsBtn = this.setupToolsPanel(doc.sidebarContainer as Doc, doc); @@ -218,21 +219,21 @@ export class CurrentUserUtils { // Finally, setup the list of buttons to display in the sidebar doc.sidebarButtons = Docs.Create.StackingDocument([doc.SearchBtn as Doc, doc.LibraryBtn as Doc, doc.ToolsBtn as Doc], { - width: 500, height: 80, boxShadow: "0 0", sectionFilter: "title", hideHeadings: true, ignoreClick: true, - backgroundColor: "rgb(100, 100, 100)", chromeStatus: "disabled", title: "library stack", - yMargin: 10, + _width: 500, _height: 80, boxShadow: "0 0", sectionFilter: "title", hideHeadings: true, ignoreClick: true, + backgroundColor: "rgb(100, 100, 100)", _chromeStatus: "disabled", title: "library stack", + _yMargin: 10, }); } /// sets up the default list of buttons to be shown in the expanding button menu at the bottom of the Dash window static setupExpandingButtons(doc: Doc) { doc.undoBtn = Docs.Create.FontIconDocument( - { nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, dropAction: "alias", onClick: ScriptField.MakeScript("undo()"), removeDropProperties: new List<string>(["dropAction"]), title: "undo button", icon: "undo-alt" }); + { _nativeWidth: 100, _nativeHeight: 100, _width: 100, _height: 100, _dropAction: "alias", onClick: ScriptField.MakeScript("undo()"), removeDropProperties: new List<string>(["dropAction"]), title: "undo button", icon: "undo-alt" }); doc.redoBtn = Docs.Create.FontIconDocument( - { nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, dropAction: "alias", onClick: ScriptField.MakeScript("redo()"), removeDropProperties: new List<string>(["dropAction"]), title: "redo button", icon: "redo-alt" }); + { _nativeWidth: 100, _nativeHeight: 100, _width: 100, _height: 100, _dropAction: "alias", onClick: ScriptField.MakeScript("redo()"), removeDropProperties: new List<string>(["dropAction"]), title: "redo button", icon: "redo-alt" }); doc.expandingButtons = Docs.Create.LinearDocument([doc.undoBtn as Doc, doc.redoBtn as Doc], { - title: "expanding buttons", gridGap: 5, xMargin: 5, yMargin: 5, height: 42, width: 100, boxShadow: "0 0", + title: "expanding buttons", _gridGap: 5, _xMargin: 5, _yMargin: 5, _height: 42, _width: 100, boxShadow: "0 0", backgroundColor: "black", preventTreeViewOpen: true, forceActive: true, lockedPosition: true, dropConverter: ScriptField.MakeScript("convertToButtons(dragData)", { dragData: DragManager.DocumentDragData.name }) }); @@ -241,13 +242,13 @@ export class CurrentUserUtils { // sets up the default set of documents to be shown in the Overlay layer static setupOverlays(doc: Doc) { doc.overlays = Docs.Create.FreeformDocument([], { title: "Overlays", backgroundColor: "#aca3a6" }); - doc.linkFollowBox = Docs.Create.LinkFollowBoxDocument({ x: 250, y: 20, width: 500, height: 370, title: "Link Follower" }); + doc.linkFollowBox = Docs.Create.LinkFollowBoxDocument({ x: 250, y: 20, _width: 500, _height: 370, title: "Link Follower" }); Doc.AddDocToList(doc.overlays as Doc, "data", doc.linkFollowBox as Doc); } // the initial presentation Doc to use static setupDefaultPresentation(doc: Doc) { - doc.curPresentation = Docs.Create.PresDocument(new List<Doc>(), { title: "Presentation", boxShadow: "0 0" }); + doc.curPresentation = Docs.Create.PresDocument(new List<Doc>(), { title: "Presentation", _viewType: CollectionViewType.Stacking, boxShadow: "0 0" }); } static setupMobileUploads(doc: Doc) { |