OpenXE/www/js/production/generic/build/pdf.sandbox.mjs

239 lines
708 KiB
JavaScript
Raw Normal View History

/**
* @licstart The following is the entire license notice for the
* JavaScript code in this page
*
* Copyright 2023 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
*/
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/************************************************************************/
var __webpack_exports__ = globalThis.pdfjsSandbox = {};
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
QuickJSSandbox: () => (/* binding */ QuickJSSandbox)
});
;// CONCATENATED MODULE: ./external/quickjs/quickjs-eval.js
var Module=(()=>{var _scriptDir=typeof document!=='undefined'&&document.currentScript?document.currentScript.src:undefined;return function(moduleArg={}){var d=moduleArg,k,n;d.ready=new Promise((a,b)=>{k=a;n=b;});var p=Object.assign({},d),q="";"undefined"!=typeof document&&document.currentScript&&(q=document.currentScript.src);_scriptDir&&(q=_scriptDir);q.startsWith("blob:")?q="":q=q.substr(0,q.replace(/[?#].*/,"").lastIndexOf("/")+1);var aa=d.print||console.log.bind(console),u=d.printErr||console.error.bind(console);Object.assign(d,p);p=null;var v;d.wasmBinary&&(v=d.wasmBinary);"object"!=typeof WebAssembly&&w("no native wasm support detected");var x,y=!1,z,A,B,C;function D(){var a=x.buffer;d.HEAP8=z=new Int8Array(a);d.HEAP16=new Int16Array(a);d.HEAPU8=A=new Uint8Array(a);d.HEAPU16=new Uint16Array(a);d.HEAP32=B=new Int32Array(a);d.HEAPU32=C=new Uint32Array(a);d.HEAPF32=new Float32Array(a);d.HEAPF64=new Float64Array(a);}var E=[],F=[],G=[];function ba(){var a=d.preRun.shift();E.unshift(a);}var H=0,I=null,J=null;function w(a){d.onAbort?.(a);a="Aborted("+a+")";u(a);y=!0;a=new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");n(a);throw a;}var K=a=>a.startsWith("data:application/octet-stream;base64,"),L;L="data:application/octet-stream;base64,AGFzbQEAAAABzgZtYAJ/fwBgA39/fwF/YAR/fn9/AX5gAn9/AX9gBX9+f39/AX5gAX8Bf2ADf39/AGAEf39/fwF/YAJ/fgF+YAF/AGABfAF8YAV/f39/fwF/YAJ/fgBgAn9+AX9gAn9/AX5gA39/fgF/YAN/fn8BfmAGf35/f39/AX5gA39+fwBgA39+fwF/YAZ/f39/f38Bf2AEf39/fwBgBn9+fn9/fwF+YAR/f35/AX9gA39+fgF+YAN/f38BfmADf35+AX9gBH9/f38BfmAFf35+fn4AYAJ8fAF8YAF/AX5gBH9/f34Bf2AFf35+f38BfmAFf39/f38AYAd/fn9+fn5/AX9gBX9/f35+AX9gB39/f39/f38Bf2AAAGAFf35/fn8Bf2AEf35+fwBgBH9+fn8BfmAFf35+fn8Bf2AFf39/f38BfmAEf39+fgF/YAF+AX9gBH9+f34BfmAEf35/fwBgBH9+fn8Bf2AJf39/f39/f39/AX9gCH9/f39/f39/AX9gA39+fgBgBH9+f38Bf2AGf35/fn5/AX9gBX9+fn9/AGABfgF+YAd/fn9/f39/AX5gAX8BfGADf39+AGAEf35/fgF/YAV/f35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goKIwoKCgodKwoKCgoKARYWFgIABAcBcAGnA
;// CONCATENATED MODULE: ./src/pdf.sandbox.external.js
class SandboxSupportBase {
constructor(win) {
this.win = win;
this.timeoutIds = new Map();
this.commFun = null;
}
destroy() {
this.commFun = null;
for (const id of this.timeoutIds.values()) {
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;
}
if (callbackId === 0) {
this.win.clearTimeout(this.timeoutIds.get(callbackId));
}
const id = this.win.setTimeout(() => {
this.timeoutIds.delete(callbackId);
this.callSandboxFunction("timeoutCb", {
callbackId,
interval: false
});
}, nMilliseconds);
this.timeoutIds.set(callbackId, id);
},
clearTimeout: callbackId => {
this.win.clearTimeout(this.timeoutIds.get(callbackId));
this.timeoutIds.delete(callbackId);
},
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: callbackId => {
this.win.clearInterval(this.timeoutIds.get(callbackId));
this.timeoutIds.delete(callbackId);
},
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() ?? "");
}
};
}
}
;// CONCATENATED MODULE: ./src/pdf.sandbox.js
const pdfjsVersion = "4.2.67";
const pdfjsBuild = "49b388101";
class SandboxSupport extends 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 = ["var __webpack_exports__ = globalThis.pdfjsSandbox = {};\n\n;// CONCATENATED MODULE: ./src/scripting_api/constants.js\nconst Border = Object.freeze({\n s: \"solid\",\n d: \"dashed\",\n b: \"beveled\",\n i: \"inset\",\n u: \"underline\"\n});\nconst Cursor = Object.freeze({\n visible: 0,\n hidden: 1,\n delay: 2\n});\nconst Display = Object.freeze({\n visible: 0,\n hidden: 1,\n noPrint: 2,\n noView: 3\n});\nconst Font = Object.freeze({\n Times: \"Times-Roman\",\n TimesB: \"Times-Bold\",\n TimesI: \"Times-Italic\",\n TimesBI: \"Times-BoldItalic\",\n Helv: \"Helvetica\",\n HelvB: \"Helvetica-Bold\",\n HelvI: \"Helvetica-Oblique\",\n HelvBI: \"Helvetica-BoldOblique\",\n Cour: \"Courier\",\n CourB: \"Courier-Bold\",\n CourI: \"Courier-Oblique\",\n CourBI: \"Courier-BoldOblique\",\n Symbol: \"Symbol\",\n ZapfD: \"ZapfDingbats\",\n KaGo: \"HeiseiKakuGo-W5-UniJIS-UCS2-H\",\n KaMi: \"HeiseiMin-W3-UniJIS-UCS2-H\"\n});\nconst Highlight = Object.freeze({\n n: \"none\",\n i: \"invert\",\n p: \"push\",\n o: \"outline\"\n});\nconst Position = Object.freeze({\n textOnly: 0,\n iconOnly: 1,\n iconTextV: 2,\n textIconV: 3,\n iconTextH: 4,\n textIconH: 5,\n overlay: 6\n});\nconst ScaleHow = Object.freeze({\n proportional: 0,\n anamorphic: 1\n});\nconst ScaleWhen = Object.freeze({\n always: 0,\n never: 1,\n tooBig: 2,\n tooSmall: 3\n});\nconst Style = Object.freeze({\n ch: \"check\",\n cr: \"cross\",\n di: \"diamond\",\n ci: \"circle\",\n st: \"star\",\n sq: \"square\"\n});\nconst Trans = Object.freeze({\n blindsH: \"BlindsHorizontal\",\n blindsV: \"BlindsVertical\",\n boxI: \"BoxIn\",\n boxO: \"BoxOut\",\n dissolve: \"Dissolve\",\n glitterD: \"GlitterDown\",\n glitterR: \"GlitterRight\",\n glitterRD: \"GlitterRightDown\",\n random: \"Random\",\n replace: \"Replace\",\n splitHI: \"SplitHorizontalIn\",\n splitHO: \"SplitHorizontalOut\",\n splitVI: \"SplitVerticalIn\",\n splitVO: \"SplitVerticalOut\",\n wipeD: \"WipeDown\",\n wipeL: \"WipeLeft\",\n wipeR: \"WipeRight\",\n wipeU: \"WipeUp\"\n});\nconst ZoomType = Object.freeze({\n none: \"NoVary\",\n fitP: \"FitPage\",\n fitW: \"FitWidth\",\n fitH: \"FitHeight\",\n fitV: \"FitVisibleWidth\",\n pref: \"Preferred\",\n refW: \"ReflowWidth\"\n});\nconst GlobalConstants = Object.freeze({\n IDS_GREATER_THAN: \"Invalid value: must be greater than or equal to % s.\",\n IDS_GT_AND_LT: \"Invalid value: must be greater than or equal to % s \" + \"and less than or equal to % s.\",\n IDS_LESS_THAN: \"Invalid value: must be less than or equal to % s.\",\n IDS_INVALID_MONTH: \"** Invalid **\",\n IDS_INVALID_DATE: \"Invalid date / time: please ensure that the date / time exists. Field\",\n IDS_INVALID_DATE2: \" should match format \",\n IDS_INVALID_VALUE: \"The value entered does not match the format of the field\",\n IDS_AM: \"am\",\n IDS_PM: \"pm\",\n IDS_MONTH_INFO: \"January[1] February[2] March[3] April[4] May[5] \" + \"June[6] July[7] August[8] September[9] October[10] \" + \"November[11] December[12] Sept[9] Jan[1] Feb[2] Mar[3] \" + \"Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov[11] Dec[12]\",\n IDS_STARTUP_CONSOLE_MSG: \"** ^ _ ^ **\",\n RE_NUMBER_ENTRY_DOT_SEP: [\"[+-]?\\\\d*\\\\.?\\\\d*\"],\n RE_NUMBER_COMMIT_DOT_SEP: [\"[+-]?\\\\d+(\\\\.\\\\d+)?\", \"[+-]?\\\\.\\\\d+\", \"[+-]?\\\\d+\\\\.\"],\n RE_NUMBER_ENTRY_COMMA_SEP: [\"[+-]?\\\\d*,?\\\\d*\"],\n RE_NUMBER_COMMIT_COMMA_SEP: [\"[+-]?\\\\d+([.,]\\\\d+)?\", \"[+-]?[.,]\\\\d+\", \"[+-]?\\\\d+[.,]\"],\n RE_ZIP_ENTRY: [\"\\\\d{0,5}\"],\n RE_ZIP_COMMIT: [\"\\\\d{5}\"],\n RE_ZIP4_ENTRY: [\"\\\\d{0,5}(\\\\.|[- ])?\\\\d{0,4}\"],\n RE_ZIP4_COMMIT: [\"\\\\d{5}(\\\\.|[- ])?\\\\d{4}\"],\n RE_PHONE_ENTRY: [\"\\\\d{0,3}(\\\\.|[- ])?\\\\d{0,3}(\\\\.|[- ])?\\\\d{0,4}\", \"\\\\(\\\\d{0,3}\", \"\\\\(\\\\d{0,3}\\\\)(\\\\.|[- ])?\\\\d{0,3}(\\\\.|[- ])?\\\\d{0,4}\", \"\\\\(\\\\d{0,3}(\\\\.|[- ])?\\\\d{0,3}(\\\\.|[- ])?\\\\d{0,4}\", \"\\\\d{0,3}\\\\)(\\\\.|[- ])?\\\\d{0,3}(\\\\.|[- ])?\\\\d{0,4}\", \"011(\\\\.|[- \\\\d])*\"],\n RE_PHONE_COMMIT: [\"\\\\d{3
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() {
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 quickjs_eval().then(module => new Sandbox(window, module));
}
var __webpack_exports__QuickJSSandbox = __webpack_exports__.QuickJSSandbox;
export { __webpack_exports__QuickJSSandbox as QuickJSSandbox };
//# sourceMappingURL=pdf.sandbox.mjs.map