core-jgi/org.adempiere.ui.zk/pdf.js/build/pdf.sandbox.js

309 lines
614 KiB
JavaScript
Raw Normal View History

/**
* @licstart The following is the entire license notice for the
* Javascript code in this page
*
* Copyright 2021 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @licend The above is the entire license notice for the
* Javascript code in this page
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("pdfjs-dist/build/pdf.sandbox", [], factory);
else if(typeof exports === 'object')
exports["pdfjs-dist/build/pdf.sandbox"] = factory();
else
root["pdfjs-dist/build/pdf.sandbox"] = root.pdfjsSandbox = factory();
})(this, function() {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ([
/* 0 */,
/* 1 */
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({value:true}));exports.default=void 0;var Module=function(){var _scriptDir=typeof document!=='undefined'&&document.currentScript?document.currentScript.src:undefined;return function(Module){Module=Module||{};var b;b||(b=typeof Module!=='undefined'?Module:{});var h,n;b.ready=new Promise(function(a,c){h=a;n=c;});var q={},r;for(r in b)b.hasOwnProperty(r)&&(q[r]=b[r]);var t="";"undefined"!==typeof document&&document.currentScript&&(t=document.currentScript.src);_scriptDir&&(t=_scriptDir);0!==t.indexOf("blob:")?t=t.substr(0,t.lastIndexOf("/")+1):t="";var aa=b.print||console.log.bind(console),u=b.printErr||console.warn.bind(console);for(r in q)q.hasOwnProperty(r)&&(b[r]=q[r]);q=null;var v;b.wasmBinary&&(v=b.wasmBinary);var noExitRuntime=b.noExitRuntime||!0;"object"!==typeof WebAssembly&&w("no native wasm support detected");var x,z=!1;function A(a){var c=b["_"+a];c||w("Assertion failed: Cannot call unknown function "+(a+", make sure it is exported"));return c;}function B(a,c,d,e){var f={string:function(l){var p=0;if(null!==l&&void 0!==l&&0!==l){var U=(l.length<<2)+1;p=C(U);D(l,E,p,U);}return p;},array:function(l){var p=C(l.length);F.set(l,p);return p;}},g=A(a),k=[];a=0;if(e)for(var m=0;m<e.length;m++){var y=f[d[m]];y?(0===a&&(a=G()),k[m]=y(e[m])):k[m]=e[m];}d=g.apply(null,k);d=function(l){return"string"===c?H(l):"boolean"===c?!!l:l;}(d);0!==a&&I(a);return d;}var J="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0;function K(a,c,d){var e=c+d;for(d=c;a[d]&&!(d>=e);)++d;if(16<d-c&&a.subarray&&J)return J.decode(a.subarray(c,d));for(e="";c<d;){var f=a[c++];if(f&128){var g=a[c++]&63;if(192==(f&224))e+=String.fromCharCode((f&31)<<6|g);else{var k=a[c++]&63;f=224==(f&240)?(f&15)<<12|g<<6|k:(f&7)<<18|g<<12|k<<6|a[c++]&63;65536>f?e+=String.fromCharCode(f):(f-=65536,e+=String.fromCharCode(55296|f>>10,56320|f&1023));}}else e+=String.fromCharCode(f);}return e;}function H(a){return a?K(E,a,void 0):"";}function D(a,c,d,e){if(0<e){e=d+e-1;for(var f=0;f<a.length;++f){var g=a.charCodeAt(f);if(55296<=g&&57343>=g){var k=a.charCodeAt(++f);g=65536+((g&1023)<<10)|k&1023;}if(127>=g){if(d>=e)break;c[d++]=g;}else{if(2047>=g){if(d+1>=e)break;c[d++]=192|g>>6;}else{if(65535>=g){if(d+2>=e)break;c[d++]=224|g>>12;}else{if(d+3>=e)break;c[d++]=240|g>>18;c[d++]=128|g>>12&63;}c[d++]=128|g>>6&63;}c[d++]=128|g&63;}}c[d]=0;}}function L(a){for(var c=0,d=0;d<a.length;++d){var e=a.charCodeAt(d);55296<=e&&57343>=e&&(e=65536+((e&1023)<<10)|a.charCodeAt(++d)&1023);127>=e?++c:c=2047>=e?c+2:65535>=e?c+3:c+4;}return c;}function ba(a){var c=L(a)+1,d=M(c);d&&D(a,F,d,c);return d;}var ca,F,E,N;function da(){var a=x.buffer;ca=a;b.HEAP8=F=new Int8Array(a);b.HEAP16=new Int16Array(a);b.HEAP32=N=new Int32Array(a);b.HEAPU8=E=new Uint8Array(a);b.HEAPU16=new Uint16Array(a);b.HEAPU32=new Uint32Array(a);b.HEAPF32=new Float32Array(a);b.HEAPF64=new Float64Array(a);}var O,ea=[],fa=[],ha=[],ia=[];function ja(){var a=b.preRun.shift();ea.unshift(a);}var P=0,Q=null,R=null;b.preloadedImages={};b.preloadedAudios={};function w(a){if(b.onAbort)b.onAbort(a);u(a);z=!0;a=new WebAssembly.RuntimeError("abort("+a+"). Build with -s ASSERTIONS=1 for more info.");n(a);throw a;}function S(a){return String.prototype.startsWith?a.startsWith("data:application/octet-stream;base64,"):0===a.indexOf("data:application/octet-stream;base64,");}var T="data:application/octet-stream;base64,AGFzbQEAAAABxQZsYAR/fn9/AX5gA39/fwF/YAJ/fwF/YAJ/fwBgAX8Bf2AFf35/f38BfmADf39/AGABfAF8YAF/AGACf34BfmACf34AYAR/f39/AX9gAn9/AX5gAn9+AX9gA39/fgF/YAN/fn8BfmABfgF/YAN/fn8AYAZ/fn9/f38BfmADf35/AX9gBX9/f39/AX9gBn9+fn9/fwF+YAN/fn4BfmAEf39+fwF/YAN/f38BfmAEf39/fwBgBn9/f39/fwF/YAR/f39/AX5gA39+fgF/YAF/AX5gBX9+fn5+AGABfgF+YAJ8fAF8YAABf2AFf35/fn8Bf2AHf35/fn5+fwF/YAV/fn5/fwF+YAAAYAV/f39/fwBgA39+fgBgBH9+fn8AYAd/f39/f39/AX9gBn9+f35+fwF/YAV/fn5+fwF/YAV/fn5/fwBgAn5/AGAJf39/f39/f39/AX9gBH9+f38Bf2AEf35+fwF/YAJ+fwF/YAZ/f39/f38BfmAHf35/f39/fwF+YAR/fn9+AX5gBH9+fn8BfmAHf39/f39/fwBgA39/fgBgBH9/fn8AYAR/fn9/AGAIf39/f39/f38Bf2AEf39/fgF/YAR/fn9+AX9gBH9+fn4Bf2AGf3x/f39/AX9gA35/fwF/YAR/fn5+AX5gAn5+AX5gAnx/AXxgA3
/***/ }),
/* 2 */
/***/ ((__unused_webpack_module, exports) => {
class SandboxSupportBase {
constructor(win) {
this.win = win;
this.timeoutIds = new Map();
this.commFun = null;
}
destroy() {
this.commFunc = null;
this.timeoutIds.forEach(([_, id]) => this.win.clearTimeout(id));
this.timeoutIds = null;
}
exportValueToSandbox(val) {
throw new Error("Not implemented");
}
importValueFromSandbox(val) {
throw new Error("Not implemented");
}
createErrorForSandbox(errorMessage) {
throw new Error("Not implemented");
}
callSandboxFunction(name, args) {
try {
args = this.exportValueToSandbox(args);
this.commFun(name, args);
} catch (e) {
this.win.console.error(e);
}
}
createSandboxExternals() {
const externals = {
setTimeout: (callbackId, nMilliseconds) => {
if (typeof callbackId !== "number" || typeof nMilliseconds !== "number") {
return;
}
const id = this.win.setTimeout(() => {
this.timeoutIds.delete(callbackId);
this.callSandboxFunction("timeoutCb", {
callbackId,
interval: false
});
}, nMilliseconds);
this.timeoutIds.set(callbackId, id);
},
clearTimeout: id => {
this.win.clearTimeout(this.timeoutIds.get(id));
this.timeoutIds.delete(id);
},
setInterval: (callbackId, nMilliseconds) => {
if (typeof callbackId !== "number" || typeof nMilliseconds !== "number") {
return;
}
const id = this.win.setInterval(() => {
this.callSandboxFunction("timeoutCb", {
callbackId,
interval: true
});
}, nMilliseconds);
this.timeoutIds.set(callbackId, id);
},
clearInterval: id => {
this.win.clearInterval(this.timeoutIds.get(id));
this.timeoutIds.delete(id);
},
alert: cMsg => {
if (typeof cMsg !== "string") {
return;
}
this.win.alert(cMsg);
},
confirm: cMsg => {
if (typeof cMsg !== "string") {
return false;
}
return this.win.confirm(cMsg);
},
prompt: (cQuestion, cDefault) => {
if (typeof cQuestion !== "string" || typeof cDefault !== "string") {
return null;
}
return this.win.prompt(cQuestion, cDefault);
},
parseURL: cUrl => {
const url = new this.win.URL(cUrl);
const props = ["hash", "host", "hostname", "href", "origin", "password", "pathname", "port", "protocol", "search", "searchParams", "username"];
return Object.fromEntries(props.map(name => [name, url[name].toString()]));
},
send: data => {
if (!data) {
return;
}
const event = new this.win.CustomEvent("updatefromsandbox", {
detail: this.importValueFromSandbox(data)
});
this.win.dispatchEvent(event);
}
};
Object.setPrototypeOf(externals, null);
return (name, args) => {
try {
const result = externals[name](...args);
return this.exportValueToSandbox(result);
} catch (error) {
throw this.createErrorForSandbox(error?.toString() ?? "");
}
};
}
}
{
exports.SandboxSupportBase = SandboxSupportBase;
}
/***/ })
/******/ ]);
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __w_pdfjs_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
var exports = __webpack_exports__;
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports.QuickJSSandbox = QuickJSSandbox;
var _quickjsEval = _interopRequireDefault(__w_pdfjs_require__(1));
var _pdfSandboxExternal = __w_pdfjs_require__(2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const pdfjsVersion = '2.9.359';
const pdfjsBuild = 'e667c8cbc';
class SandboxSupport extends _pdfSandboxExternal.SandboxSupportBase {
exportValueToSandbox(val) {
return JSON.stringify(val);
}
importValueFromSandbox(val) {
return val;
}
createErrorForSandbox(errorMessage) {
return new Error(errorMessage);
}
}
class Sandbox {
constructor(win, module) {
this.support = new SandboxSupport(win, this);
module.externalCall = this.support.createSandboxExternals();
this._module = module;
this._alertOnError = 0;
}
create(data) {
const code = ['(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === \'object\' && typeof module === \'object\')\n\t\tmodule.exports = factory();\n\telse if(typeof define === \'function\' && define.amd)\n\t\tdefine("pdfjs-dist/build/pdf.scripting", [], factory);\n\telse if(typeof exports === \'object\')\n\t\texports["pdfjs-dist/build/pdf.scripting"] = factory();\n\telse\n\t\troot.pdfjsScripting = factory();\n})(this, function() {\nreturn /******/ (() => { // webpackBootstrap\n/******/ \t"use strict";\n/******/ \tvar __webpack_modules__ = ([\n/* 0 */,\n/* 1 */\n/***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {\n\n\n\nObject.defineProperty(exports, "__esModule", ({\n value: true\n}));\nexports.initSandbox = initSandbox;\n\nvar _constants = __w_pdfjs_require__(2);\n\nvar _field = __w_pdfjs_require__(3);\n\nvar _aform = __w_pdfjs_require__(8);\n\nvar _app = __w_pdfjs_require__(9);\n\nvar _color = __w_pdfjs_require__(5);\n\nvar _console = __w_pdfjs_require__(13);\n\nvar _doc = __w_pdfjs_require__(14);\n\nvar _proxy = __w_pdfjs_require__(16);\n\nvar _util = __w_pdfjs_require__(17);\n\nfunction initSandbox(params) {\n delete globalThis.pdfjsScripting;\n const externalCall = globalThis.callExternalFunction;\n delete globalThis.callExternalFunction;\n\n const globalEval = code => globalThis.eval(code);\n\n const send = data => externalCall("send", [data]);\n\n const proxyHandler = new _proxy.ProxyHandler();\n const {\n data\n } = params;\n const doc = new _doc.Doc({\n send,\n globalEval,\n ...data.docInfo\n });\n const _document = {\n obj: doc,\n wrapped: new Proxy(doc, proxyHandler)\n };\n const app = new _app.App({\n send,\n globalEval,\n externalCall,\n _document,\n calculationOrder: data.calculationOrder,\n proxyHandler,\n ...data.appInfo\n });\n const util = new _util.Util({\n externalCall\n });\n const appObjects = app._objects;\n\n if (data.objects) {\n const annotations = [];\n\n for (const [name, objs] of Object.entries(data.objects)) {\n annotations.length = 0;\n let container = null;\n\n for (const obj of objs) {\n if (obj.type !== "") {\n annotations.push(obj);\n } else {\n container = obj;\n }\n }\n\n let obj = container;\n\n if (annotations.length > 0) {\n obj = annotations[0];\n obj.send = send;\n }\n\n obj.globalEval = globalEval;\n obj.doc = _document;\n obj.fieldPath = name;\n obj.appObjects = appObjects;\n let field;\n\n switch (obj.type) {\n case "radiobutton":\n {\n const otherButtons = annotations.slice(1);\n field = new _field.RadioButtonField(otherButtons, obj);\n break;\n }\n\n case "checkbox":\n {\n const otherButtons = annotations.slice(1);\n field = new _field.CheckboxField(otherButtons, obj);\n break;\n }\n\n case "text":\n if (annotations.length <= 1) {\n field = new _field.Field(obj);\n break;\n }\n\n obj.siblings = annotations.map(x => x.id).slice(1);\n field = new _field.Field(obj);\n break;\n\n default:\n field = new _field.Field(obj);\n }\n\n const wrapped = new Proxy(field, proxyHandler);\n\n doc._addField(name, wrapped);\n\n const _object = {\n obj: field,\n wrapped\n };\n\n for (const object of objs) {\n appObjects[object.id] = _object;\n }\n\n if (container) {\n appObjects[container.id] = _object;\n }\n }\n }\n\n const color = new _color.Color();\n globalThis.event = null;\n globalThis.global = Object.create(null);\n globalThis.app = new Proxy(app, proxyHandler);\n globalThis.color = new Proxy(color, proxyHandler);\n globalThis.console = new Proxy(new _console.Console({\n send\n }), proxyHandler);\n globalThis.util = new Proxy(util, proxyHandler);\n globalThis.border
code.push("delete dump;");
let success = false;
let buf = 0;
try {
const sandboxData = JSON.stringify(data);
code.push(`pdfjsScripting.initSandbox({ data: ${sandboxData} })`);
buf = this._module.stringToNewUTF8(code.join("\n"));
success = !!this._module.ccall("init", "number", ["number", "number"], [buf, this._alertOnError]);
} catch (error) {
console.error(error);
} finally {
if (buf) {
this._module.ccall("free", "number", ["number"], [buf]);
}
}
if (success) {
this.support.commFun = this._module.cwrap("commFun", null, ["string", "string"]);
} else {
this.nukeSandbox();
throw new Error("Cannot start sandbox");
}
}
dispatchEvent(event) {
this.support.callSandboxFunction("dispatchEvent", event);
}
dumpMemoryUse() {
if (this._module) {
this._module.ccall("dumpMemoryUse", null, []);
}
}
nukeSandbox() {
if (this._module !== null) {
this.support.destroy();
this.support = null;
this._module.ccall("nukeSandbox", null, []);
this._module = null;
}
}
evalForTesting(code, key) {
throw new Error("Not implemented: evalForTesting");
}
}
function QuickJSSandbox() {
return (0, _quickjsEval.default)().then(module => {
return new Sandbox(window, module);
});
}
})();
/******/ return __webpack_exports__;
/******/ })()
;
});
//# sourceMappingURL=pdf.sandbox.js.map