pdfjs-dist
Version:
Generic build of Mozilla's PDF.js library.
187 lines (184 loc) • 120 kB
JavaScript
/**
* @licstart The following is the entire license notice for the
* JavaScript code in this page
*
* Copyright 2024 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
*/
/**
* pdfjsVersion = 5.7.284
* pdfjsBuild = 7e5b36c2d
*/
/******/ // 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))
/******/ })();
/******/
/************************************************************************/
;// ./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) {
if (!this.commFun) {
return;
}
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() ?? "");
}
};
}
}
;// ./src/pdf.sandbox.js
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 = ["\n;// ./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}(\\\\.|[- ])?\\\\d{4}\", \"\\\\d{3}(\\\\.|[- ])?\\\\d{3}(\\\\.|[- ])?\\\\d{4}\", \"\\\\(\\\\d{3}\\\\)(\\\\.|[- ])?\\\\d{3}(\\\\.|[- ])?\\\\d{4}\", \"011(\\\\.|[- \\\\d])*\"],\n RE_SSN_ENTRY: [\"\\\\d{0,3}(\\\\.|[- ])?\\\\d{0,2}(\\\\.|[- ])?\\\\d{0,4}\"],\n RE_SSN_COMMIT: [\"\\\\d{3}(\\\\.|[- ])?\\\\d{2}(\\\\.|[- ])?\\\\d{4}\"]\n});\n\n;// ./src/scripting_api/common.js\nconst FieldType = {\n none: 0,\n number: 1,\n percent: 2,\n date: 3,\n time: 4\n};\nfunction createActionsMap(actions) {\n return new Map(actions ? Object.entries(actions) : null);\n}\nfunction getFieldType(actions) {\n let format = actions.get(\"Format\");\n if (!format) {\n return FieldType.none;\n }\n format = format[0];\n format = format.trim();\n if (format.startsWith(\"AFNumber_\")) {\n return FieldType.number;\n }\n if (format.startsWith(\"AFPercent_\")) {\n return FieldType.percent;\n }\n if (format.startsWith(\"AFDate_\")) {\n return FieldType.date;\n }\n if (format.startsWith(\"AFTime_\")) {\n return FieldType.time;\n }\n return FieldType.none;\n}\n\n;// ./src/shared/math_clamp.js\nfunction MathClamp(v, min, max) {\n return Math.min(Math.max(v, min), max);\n}\n\n;// ./src/shared/scripting_utils.js\n\nfunction makeColorComp(n) {\n return Math.floor(MathClamp(n, 0, 1) * 255).toString(16).padStart(2, \"0\");\n}\nfunction scaleAndClamp(x) {\n return MathClamp(x, 0, 1) * 255;\n}\nclass ColorConverters {\n static CMYK_G([c, y, m, k]) {\n return [\"G\", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];\n }\n static G_CMYK([g]) {\n return [\"CMYK\", 0, 0, 0, 1 - g];\n }\n static G_RGB([g]) {\n return [\"RGB\", g, g, g];\n }\n static G_rgb([g]) {\n g = scaleAndClamp(g);\n return [g, g, g];\n }\n static G_HTML([g]) {\n const G = makeColorComp(g);\n return `#${G}${G}${G}`;\n }\n static RGB_G([r, g, b]) {\n return [\"G\", 0.3 * r + 0.59 * g + 0.11 * b];\n }\n static RGB_rgb(color) {\n return color.map(scaleAndClamp);\n }\n static RGB_HTML(color) {\n return `#${color.map(makeColorComp).join(\"\")}`;\n }\n static T_HTML() {\n return \"#00000000\";\n }\n static T_rgb() {\n return [null];\n }\n static CMYK_RGB([c, y, m, k]) {\n return [\"RGB\", 1 - Math.min(1, c + k), 1 - Math.min(1, m + k), 1 - Math.min(1, y + k)];\n }\n static CMYK_rgb([c, y, m, k]) {\n return [scaleAndClamp(1 - Math.min(1, c + k)), scaleAndClamp(1 - Math.min(1, m + k)), scaleAndClamp(1 - Math.min(1, y + k))];\n }\n static CMYK_HTML(components) {\n const rgb = this.CMYK_RGB(components).slice(1);\n return this.RGB_HTML(rgb);\n }\n static RGB_CMYK([r, g, b]) {\n const c = 1 - r;\n const m = 1 - g;\n const y = 1 - b;\n const k = Math.min(c, m, y);\n return [\"CMYK\", c, m, y, k];\n }\n}\nconst DateFormats = [\"m/d\", \"m/d/yy\", \"mm/dd/yy\", \"mm/yy\", \"d-mmm\", \"d-mmm-yy\", \"dd-mmm-yy\", \"yy-mm-dd\", \"mmm-yy\", \"mmmm-yy\", \"mmm d, yyyy\", \"mmmm d, yyyy\", \"m/d/yy h:MM tt\", \"m/d/yy HH:MM\"];\nconst TimeFormats = [\"HH:MM\", \"h:MM tt\", \"HH:MM:ss\", \"h:MM:ss tt\"];\n\n;// ./src/scripting_api/pdf_object.js\nclass PDFObject {\n constructor(data) {\n this._expandos = Object.create(null);\n this._send = data.send || null;\n this._id = data.id || null;\n }\n}\n\n;// ./src/scripting_api/color.js\n\n\nclass Color extends PDFObject {\n transparent = [\"T\"];\n black = [\"G\", 0];\n white = [\"G\", 1];\n red = [\"RGB\", 1, 0, 0];\n green = [\"RGB\", 0, 1, 0];\n blue = [\"RGB\", 0, 0, 1];\n cyan = [\"CMYK\", 1, 0, 0, 0];\n magenta = [\"CMYK\", 0, 1, 0, 0];\n yellow = [\"CMYK\", 0, 0, 1, 0];\n dkGray = [\"G\", 0.25];\n gray = [\"G\", 0.5];\n ltGray = [\"G\", 0.75];\n constructor() {\n super({});\n }\n static _isValidSpace(cColorSpace) {\n return typeof cColorSpace === \"string\" && (cColorSpace === \"T\" || cColorSpace === \"G\" || cColorSpace === \"RGB\" || cColorSpace === \"CMYK\");\n }\n static _isValidColor(colorArray) {\n if (!Array.isArray(colorArray) || colorArray.length === 0) {\n return false;\n }\n const space = colorArray[0];\n if (!Color._isValidSpace(space)) {\n return false;\n }\n switch (space) {\n case \"T\":\n if (colorArray.length !== 1) {\n return false;\n }\n break;\n case \"G\":\n if (colorArray.length !== 2) {\n return false;\n }\n break;\n case \"RGB\":\n if (colorArray.length !== 4) {\n return false;\n }\n break;\n case \"CMYK\":\n if (colorArray.length !== 5) {\n return false;\n }\n break;\n default:\n return false;\n }\n return colorArray.slice(1).every(c => typeof c === \"number\" && c >= 0 && c <= 1);\n }\n static _getCorrectColor(colorArray) {\n return Color._isValidColor(colorArray) ? colorArray : [\"G\", 0];\n }\n convert(colorArray, cColorSpace) {\n if (!Color._isValidSpace(cColorSpace)) {\n return this.black;\n }\n if (cColorSpace === \"T\") {\n return [\"T\"];\n }\n colorArray = Color._getCorrectColor(colorArray);\n if (colorArray[0] === cColorSpace) {\n return colorArray;\n }\n if (colorArray[0] === \"T\") {\n return this.convert(this.black, cColorSpace);\n }\n return ColorConverters[`${colorArray[0]}_${cColorSpace}`](colorArray.slice(1));\n }\n equal(colorArray1, colorArray2) {\n colorArray1 = Color._getCorrectColor(colorArray1);\n colorArray2 = Color._getCorrectColor(colorArray2);\n if (colorArray1[0] === \"T\" || colorArray2[0] === \"T\") {\n return colorArray1[0] === \"T\" && colorArray2[0] === \"T\";\n }\n if (colorArray1[0] !== colorArray2[0]) {\n colorArray2 = this.convert(colorArray2, colorArray1[0]);\n }\n return colorArray1.slice(1).every((c, i) => c === colorArray2[i + 1]);\n }\n}\n\n;// ./src/scripting_api/app_utils.js\nconst VIEWER_TYPE = \"PDF.js\";\nconst VIEWER_VARIATION = \"Full\";\nconst VIEWER_VERSION = 21.00720099;\nconst FORMS_VERSION = 21.00720099;\nconst USERACTIVATION_CALLBACKID = 0;\nconst USERACTIVATION_MAXTIME_VALIDITY = 5000;\nfunction serializeError(error) {\n const value = `${error.toString()}\\n${error.stack}`;\n return {\n command: \"error\",\n value\n };\n}\nconst makeArr = () => [];\nconst makeMap = () => new Map();\n{\n if (typeof Math.sumPrecise !== \"function\") {\n Math.sumPrecise = function (numbers) {\n return numbers.reduce((a, b) => a + b, 0);\n };\n }\n if (typeof Map.prototype.getOrInsertComputed !== \"function\") {\n Map.prototype.getOrInsertComputed = function (key, callbackFn) {\n if (!this.has(key)) {\n this.set(key, callbackFn(key));\n }\n return this.get(key);\n };\n }\n}\n\n;// ./src/scripting_api/field.js\n\n\n\n\nclass Field extends PDFObject {\n constructor(data) {\n super(data);\n this.alignment = data.alignment || \"left\";\n this.borderStyle = data.borderStyle || \"\";\n this.buttonAlignX = data.buttonAlignX || 50;\n this.buttonAlignY = data.buttonAlignY || 50;\n this.buttonFitBounds = data.buttonFitBounds;\n this.buttonPosition = data.buttonPosition;\n this.buttonScaleHow = data.buttonScaleHow;\n this.ButtonScaleWhen = data.buttonScaleWhen;\n this.calcOrderIndex = data.calcOrderIndex;\n this.comb = data.comb;\n this.commitOnSelChange = data.commitOnSelChange;\n this.currentValueIndices = data.currentValueIndices;\n this.defaultStyle = data.defaultStyle;\n this.defaultValue = data.defaultValue;\n this.doNotScroll = data.doNotScroll;\n this.doNotSpellCheck = data.doNotSpellCheck;\n this.delay = data.delay;\n this.display = data.display;\n this.doc = data.doc.wrapped;\n this.editable = data.editable;\n this.exportValues = data.exportValues;\n this.fileSelect = data.fileSelect;\n this.hidden = data.hidden;\n this.highlight = data.highlight;\n this.lineWidth = data.lineWidth;\n this.multiline = data.multiline;\n this.multipleSelection = !!data.multipleSelection;\n this.name = data.name;\n this.password = data.password;\n this.print = data.print;\n this.radiosInUnison = data.radiosInUnison;\n this.readonly = data.readonly;\n this.rect = data.rect;\n this.required = data.required;\n this.richText = data.richText;\n this.richValue = data.richValue;\n this.style = data.style;\n this.submitName = data.submitName;\n this.textFont = data.textFont;\n this.textSize = data.textSize;\n this.type = data.type;\n this.userName = data.userName;\n this._actions = createActionsMap(data.actions);\n this._browseForFileToSubmit = data.browseForFileToSubmit || null;\n this._buttonCaption = null;\n this._buttonIcon = null;\n this._charLimit = data.charLimit;\n this._children = null;\n this._currentValueIndices = data.currentValueIndices || 0;\n this._document = data.doc;\n this._fieldPath = data.fieldPath;\n this._fillColor = data.fillColor || [\"T\"];\n this._isChoice = Array.isArray(data.items);\n this._items = data.items || [];\n this._hasValue = Object.hasOwn(data, \"value\");\n this._page = data.page || 0;\n this._strokeColor = data.strokeColor || [\"G\", 0];\n this._textColor = data.textColor || [\"G\", 0];\n this._value = null;\n this._kidIds = data.kidIds || null;\n this._fieldType = getFieldType(this._actions);\n this._siblings = data.siblings || null;\n this._rotation = data.rotation || 0;\n this._datetimeFormat = data.datetimeFormat || null;\n this._hasDateOrTime = !!data.hasDatetimeHTML;\n this._util = data.util;\n this._globalEval = data.globalEval;\n this._appObjects = data.appObjects;\n this.value = data.value || \"\";\n }\n get currentValueIndices() {\n if (!this._isChoice) {\n return 0;\n }\n return this._currentValueIndices;\n }\n set currentValueIndices(indices) {\n if (!this._isChoice) {\n return;\n }\n if (!Array.isArray(indices)) {\n indices = [indices];\n }\n if (!indices.every(i => typeof i === \"number\" && Number.isInteger(i) && i >= 0 && i < this.numItems)) {\n return;\n }\n indices.sort();\n if (this.multipleSelection) {\n this._currentValueIndices = indices;\n this._value = [];\n indices.forEach(i => {\n this._value.push(this._items[i].displayValue);\n });\n } else if (indices.length > 0) {\n indices = indices.splice(1, indices.length - 1);\n this._currentValueIndices = indices[0];\n this._value = this._items[this._currentValueIndices];\n }\n this._send({\n id: this._id,\n indices\n });\n }\n get fillColor() {\n return this._fillColor;\n }\n set fillColor(color) {\n if (Color._isValidColor(color)) {\n this._fillColor = color;\n }\n }\n get bgColor() {\n return this.fillColor;\n }\n set bgColor(color) {\n this.fillColor = color;\n }\n get charLimit() {\n return this._charLimit;\n }\n set charLimit(limit) {\n if (typeof limit !== \"number\") {\n throw new Error(\"Invalid argument value\");\n }\n this._charLimit = Math.max(0, Math.floor(limit));\n }\n get numItems() {\n if (!this._isChoice) {\n throw new Error(\"Not a choice widget\");\n }\n return this._items.length;\n }\n set numItems(_) {\n throw new Error(\"field.numItems is read-only\");\n }\n get strokeColor() {\n return this._strokeColor;\n }\n set strokeColor(color) {\n if (Color._isValidColor(color)) {\n this._strokeColor = color;\n }\n }\n get borderColor() {\n return this.strokeColor;\n }\n set borderColor(color) {\n this.strokeColor = color;\n }\n get page() {\n return this._page;\n }\n set page(_) {\n throw new Error(\"field.page is read-only\");\n }\n get rotation() {\n return this._rotation;\n }\n set rotation(angle) {\n angle = Math.floor(angle);\n if (angle % 90 !== 0) {\n throw new Error(\"Invalid rotation: must be a multiple of 90\");\n }\n angle %= 360;\n if (angle < 0) {\n angle += 360;\n }\n this._rotation = angle;\n }\n get textColor() {\n return this._textColor;\n }\n set textColor(color) {\n if (Color._isValidColor(color)) {\n this._textColor = color;\n }\n }\n get fgColor() {\n return this.textColor;\n }\n set fgColor(color) {\n this.textColor = color;\n }\n get value() {\n return this._value;\n }\n set value(value) {\n if (this._isChoice) {\n this._setChoiceValue(value);\n return;\n }\n if (this._hasDateOrTime && value) {\n const date = this._util.scand(this._datetimeFormat, value);\n if (date) {\n this._originalValue = date.valueOf();\n value = this._util.printd(this._datetimeFormat, date);\n this._value = !isNaN(value) ? parseFloat(value) : value;\n return;\n }\n }\n if (value === \"\" || typeof value !== \"string\" || this._fieldType >= FieldType.date) {\n this._originalValue = undefined;\n this._value = value;\n return;\n }\n this._originalValue = value;\n const _value = value.trim().replace(\",\", \".\");\n this._value = !isNaN(_value) ? parseFloat(_value) : value;\n }\n get _initialValue() {\n return this._hasDateOrTime && this._originalValue || null;\n }\n _getValue() {\n return this._originalValue ?? this.value;\n }\n _setChoiceValue(value) {\n if (this.multipleSelection) {\n if (!Array.isArray(value)) {\n value = [value];\n }\n const values = new Set(value);\n if (Array.isArray(this._currentValueIndices)) {\n this._currentValueIndices.length = 0;\n this._value.length = 0;\n } else {\n this._currentValueIndices = [];\n this._value = [];\n }\n this._items.forEach((item, i) => {\n if (values.has(item.exportValue)) {\n this._currentValueIndices.push(i);\n this._value.push(item.exportValue);\n }\n });\n } else {\n if (Array.isArray(value)) {\n value = value[0];\n }\n const index = this._items.findIndex(({\n exportValue\n }) => value === exportValue);\n if (index !== -1) {\n this._currentValueIndices = index;\n this._value = this._items[index].exportValue;\n }\n }\n }\n get valueAsString() {\n return (this._value ?? \"\").toString();\n }\n set valueAsString(_) {}\n browseForFileToSubmit() {\n if (this._browseForFileToSubmit) {\n this._browseForFileToSubmit();\n }\n }\n buttonGetCaption(nFace = 0) {\n if (this._buttonCaption) {\n return this._buttonCaption[nFace];\n }\n return \"\";\n }\n buttonGetIcon(nFace = 0) {\n if (this._buttonIcon) {\n return this._buttonIcon[nFace];\n }\n return null;\n }\n buttonImportIcon(cPath = null, nPave = 0) {}\n buttonSetCaption(cCaption, nFace = 0) {\n if (!this._buttonCaption) {\n this._buttonCaption = [\"\", \"\", \"\"];\n }\n this._buttonCaption[nFace] = cCaption;\n }\n buttonSetIcon(oIcon, nFace = 0) {\n if (!this._buttonIcon) {\n this._buttonIcon = [null, null, null];\n }\n this._buttonIcon[nFace] = oIcon;\n }\n checkThisBox(nWidget, bCheckIt = true) {}\n clearItems() {\n if (!this._isChoice) {\n throw new Error(\"Not a choice widget\");\n }\n this._items = [];\n this._send({\n id: this._id,\n clear: null\n });\n }\n deleteItemAt(nIdx = null) {\n if (!this._isChoice) {\n throw new Error(\"Not a choice widget\");\n }\n if (!this.numItems) {\n return;\n }\n if (nIdx === null) {\n nIdx = Array.isArray(this._currentValueIndices) ? this._currentValueIndices[0] : this._currentValueIndices;\n nIdx ||= 0;\n }\n if (nIdx < 0 || nIdx >= this.numItems) {\n nIdx = this.numItems - 1;\n }\n this._items.splice(nIdx, 1);\n if (Array.isArray(this._currentValueIndices)) {\n let index = this._currentValueIndices.findIndex(i => i >= nIdx);\n if (index !== -1) {\n if (this._currentValueIndices[index] === nIdx) {\n this._currentValueIndices.splice(index, 1);\n }\n for (const ii = this._currentValueIndices.length; index < ii; index++) {\n --this._currentValueIndices[index];\n }\n }\n } else if (this._currentValueIndices === nIdx) {\n this._currentValueIndices = this.numItems > 0 ? 0 : -1;\n } else if (this._currentValueIndices > nIdx) {\n --this._currentValueIndices;\n }\n this._send({\n id: this._id,\n remove: nIdx\n });\n }\n getItemAt(nIdx = -1, bExportValue = false) {\n if (!this._isChoice) {\n throw new Error(\"Not a choice widget\");\n }\n if (nIdx < 0 || nIdx >= this.numItems) {\n nIdx = this.numItems - 1;\n }\n const item = this._items[nIdx];\n return bExportValue ? item.exportValue : item.displayValue;\n }\n getArray() {\n if (this._kidIds) {\n const array = [];\n const fillArrayWithKids = kidIds => {\n for (const id of kidIds) {\n const obj = this._appObjects[id];\n if (!obj) {\n continue;\n }\n if (obj.obj._hasValue) {\n array.push(obj.wrapped);\n }\n if (obj.obj._kidIds) {\n fillArrayWithKids(obj.obj._kidIds);\n }\n }\n };\n fillArrayWithKids(this._kidIds);\n return array;\n }\n return this._children ??= this._document.obj._getTerminalChildren(this._fieldPath);\n }\n getLock() {\n return undefined;\n }\n isBoxChecked(nWidget) {\n return false;\n }\n isDefaultChecked(nWidget) {\n return false;\n }\n insertItemAt(cName, cExport = undefined, nIdx = 0) {\n if (!this._isChoice) {\n throw new Error(\"Not a choice widget\");\n }\n if (!cName) {\n return;\n }\n if (nIdx < 0 || nIdx > this.numItems) {\n nIdx = this.numItems;\n }\n if (this._items.some(({\n displayValue\n }) => displayValue === cName)) {\n return;\n }\n if (cExport === undefined) {\n cExport = cName;\n }\n const data = {\n displayValue: cName,\n exportValue: cExport\n };\n this._items.splice(nIdx, 0, data);\n if (Array.isArray(this._currentValueIndices)) {\n let index = this._currentValueIndices.findIndex(i => i >= nIdx);\n if (index !== -1) {\n for (const ii = this._currentValueIndices.length; index < ii; index++) {\n ++this._currentValueIndices[index];\n }\n }\n } else if (this._currentValueIndices >= nIdx) {\n ++this._currentValueIndices;\n }\n this._send({\n id: this._id,\n insert: {\n index: nIdx,\n ...data\n }\n });\n }\n setAction(cTrigger, cScript) {\n if (typeof cTrigger !== \"string\" || typeof cScript !== \"string\") {\n return;\n }\n if (!(cTrigger in this._actions)) {\n this._actions[cTrigger] = [];\n }\n this._actions[cTrigger].push(cScript);\n }\n setFocus() {\n this._send({\n id: this._id,\n focus: true\n });\n }\n setItems(oArray) {\n if (!this._isChoice) {\n throw new Error(\"Not a choice widget\");\n }\n this._items.length = 0;\n for (const element of oArray) {\n let displayValue, exportValue;\n if (Array.isArray(element)) {\n displayValue = element[0]?.toString() || \"\";\n exportValue = element[1]?.toString() || \"\";\n } else {\n displayValue = exportValue = element?.toString() || \"\";\n }\n this._items.push({\n displayValue,\n exportValue\n });\n }\n this._currentValueIndices = 0;\n this._send({\n id: this._id,\n items: this._items\n });\n }\n setLock() {}\n signatureGetModifications() {}\n signatureGetSeedValue() {}\n signatureInfo() {}\n signatureSetSeedValue() {}\n signatureSign() {}\n signatureValidate() {}\n _isButton() {\n return false;\n }\n _reset() {\n this.value = this.defaultValue;\n }\n _runActions(event) {\n const eventName = event.name;\n if (!this._actions.has(eventName)) {\n return false;\n }\n const actions = this._actions.get(eventName);\n for (const action of actions) {\n try {\n this._globalEval(action);\n } catch (error) {\n const serializedError = serializeError(error);\n serializedError.value = `Error when executing \"${eventName}\" for field \"${this._id}\"\\n${serializedError.value}`;\n this._send(serializedError);\n }\n }\n return true;\n }\n}\nclass RadioButtonField extends Field {\n constructor(otherButtons, data) {\n super(data);\n this.exportValues = [this.exportValues];\n this._radioIds = [this._id];\n this._radioActions = [this._actions];\n for (const radioData of otherButtons) {\n this.exportValues.push(radioData.exportValues);\n this._radioIds.push(radioData.id);\n this._radioActions.push(createActionsMap(radioData.actions));\n if (this._value === radioData.exportValues) {\n this._id = radioData.id;\n }\n }\n this._hasBeenInitialized = true;\n this._value = data.value || \"\";\n }\n get _siblings() {\n return this._radioIds.filter(id => id !== this._id);\n }\n set _siblings(_) {}\n get value() {\n return this._value;\n }\n set value(value) {\n if (!this._hasBeenInitialized) {\n return;\n }\n if (value === null || value === undefined) {\n this._value = \"\";\n }\n const i = this.exportValues.indexOf(value);\n if (0 <= i && i < this._radioIds.length) {\n this._id = this._radioIds[i];\n this._value = value;\n } else if (value === \"Off\" && this._radioIds.length === 2) {\n const nextI = (1 + this._radioIds.indexOf(this._id)) % 2;\n this._id = this._radioIds[nextI];\n this._value = this.exportValues[nextI];\n }\n }\n checkThisBox(nWidget, bCheckIt = true) {\n if (nWidget < 0 || nWidget >= this._radioIds.length || !bCheckIt) {\n return;\n }\n this._id = this._radioIds[nWidget];\n this._value = this.exportValues[nWidget];\n this._send({\n id: this._id,\n value: this._value\n });\n }\n isBoxChecked(nWidget) {\n return nWidget >= 0 && nWidget < this._radioIds.length && this._id === this._radioIds[nWidget];\n }\n isDefaultChecked(nWidget) {\n return nWidget >= 0 && nWidget < this.exportValues.length && this.defaultValue === this.exportValues[nWidget];\n }\n _getExportValue(state) {\n const i = this._radioIds.indexOf(this._id);\n return this.exportValues[i];\n }\n _runActions(event) {\n const i = this._radioIds.indexOf(this._id);\n this._actions = this._radioActions[i];\n return super._runActions(event);\n }\n _isButton() {\n return true;\n }\n}\nclass CheckboxField extends RadioButtonField {\n get value() {\n return this._value;\n }\n set value(value) {\n if (!value || value === \"Off\") {\n this._value = \"Off\";\n } else {\n super.value = value;\n }\n }\n _getExportValue(state) {\n return state ? super._getExportValue(state) : \"Off\";\n }\n isBoxChecked(nWidget) {\n if (this._value === \"Off\") {\n return false;\n }\n return super.isBoxChecked(nWidget);\n }\n isDefaultChecked(nWidget) {\n if (this.defaultValue === \"Off\") {\n return this._value === \"Off\";\n }\n return super.isDefaultChecked(nWidget);\n }\n checkThisBox(nWidget, bCheckIt = true) {\n if (nWidget < 0 || nWidget >= this._radioIds.length) {\n return;\n }\n this._id = this._radioIds[nWidget];\n this._value = bCheckIt ? this.exportValues[nWidget] : \"Off\";\n this._send({\n id: this._id,\n value: this._value\n });\n }\n}\n\n;// ./src/scripting_api/aform.js\n\n\n\nclass AForm {\n constructor(document, app, util, color) {\n this._document = document;\n this._app = app;\n this._util = util;\n this._color = color;\n this._emailRegex = new RegExp(\"^[a-zA-Z0-9.!#$%&'*+\\\\/=?^_`{|}~-]+\" + \"@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\" + \"(?:\\\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$\");\n }\n _mkTargetName(event) {\n return event.target ? `[ ${event.target.name} ]` : \"\";\n }\n _parseDate(cFormat, cDate) {\n let date = null;\n try {\n date = this._util._scand(cFormat, cDate, false);\n } catch {}\n if (date) {\n return date;\n }\n date = Date.parse(cDate);\n return isNaN(date) ? null : new Date(date);\n }\n AFMergeChange(event = globalThis.event) {\n if (event.willCommit) {\n return event.value.toString();\n }\n return this._app._eventDispatcher.mergeChange(event);\n }\n AFParseDateEx(cString, cOrder) {\n return this._parseDate(cOrder, cString);\n }\n AFExtractNums(str) {\n if (typeof str === \"number\") {\n return [str];\n }\n if (!str || typeof str !== \"string\") {\n return null;\n }\n const first = str.charAt(0);\n if (first === \".\" || first === \",\") {\n str = `0${str}`;\n }\n const numbers = str.match(/(\\d+)/g);\n if (numbers.length === 0) {\n return null;\n }\n return numbers;\n }\n AFMakeNumber(str) {\n if (typeof str === \"number\") {\n return str;\n }\n if (typeof str !== \"string\") {\n return null;\n }\n str = str.trim().replace(\",\", \".\");\n const number = parseFloat(str);\n if (isNaN(number) || !isFinite(number)) {\n return null;\n }\n return number;\n }\n AFMakeArrayFromList(string) {\n if (typeof string === \"string\") {\n return string.split(/, ?/g);\n }\n return string;\n }\n AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend) {\n const event = globalThis.event;\n let value = this.AFMakeNumber(event.value);\n if (value === null) {\n event.value = \"\";\n return;\n }\n const sign = Math.sign(value);\n const buf = [];\n let hasParen = false;\n if (sign === -1 && bCurrencyPrepend && negStyle === 0) {\n buf.push(\"-\");\n }\n if ((negStyle === 2 || negStyle === 3) && sign === -1) {\n buf.push(\"(\");\n hasParen = true;\n }\n if (bCurrencyPrepend) {\n buf.push(strCurrency);\n }\n sepStyle = MathClamp(Math.floor(sepStyle), 0, 4);\n buf.push(\"%,\", sepStyle, \".\", nDec.toString(), \"f\");\n if (!bCurrencyPrepend) {\n buf.push(strCurrency);\n }\n if (hasParen) {\n buf.push(\")\");\n }\n if (negStyle === 1 || negStyle === 3) {\n event.target.textColor = sign === 1 ? this._color.black : this._color.red;\n }\n if ((negStyle !== 0 || bCurrencyPrepend) && sign === -1) {\n value = -value;\n }\n const formatStr = buf.join(\"\");\n event.value = this._util.printf(formatStr, value);\n }\n AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend) {\n const event = globalThis.event;\n let value = this.AFMergeChange(event);\n if (!value) {\n return;\n }\n value = value.trim();\n let pattern;\n if (sepStyle > 1) {\n pattern = event.willCommit ? /^[+-]?(\\d+(,\\d*)?|,\\d+)$/ : /^[+-]?\\d*,?\\d*$/;\n } else {\n pattern = event.willCommit ? /^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)$/ : /^[+-]?\\d*\\.?\\d*$/;\n }\n if (!pattern.test(value)) {\n if (event.willCommit) {\n const err = `${GlobalConstants.IDS_INVALID_VALUE} ${this._mkTargetName(event)}`;\n this._app.alert(err);\n }\n event.rc = false;\n }\n if (event.willCommit && sepStyle > 1) {\n event.value = parseFloat(value.replace(\",\", \".\"));\n }\n }\n AFPercent_Format(nDec, sepStyle, percentPrepend = false) {\n if (typeof nDec !== \"number\") {\n return;\n }\n if (typeof sepStyle !== \"number\") {\n return;\n }\n if (nDec < 0) {\n throw new Error(\"Invalid nDec value in AFPercent_Format\");\n }\n const event = globalThis.event;\n if (nDec > 512) {\n event.value = \"%\";\n return;\n }\n nDec = Math.floor(nDec);\n sepStyle = MathClamp(Math.floor(sepStyle), 0, 4);\n let value = this.AFMakeNumber(event.value);\n if (value === null) {\n event.value = \"%\";\n return;\n }\n const formatStr = `%,${sepStyle}.${nDec}f`;\n value = this._util.printf(formatStr, value * 100);\n event.value = percentPrepend ? `%${value}` : `${value}%`;\n }\n AFPercent_Keystroke(nDec, sepStyle) {\n this.AFNumber_Keystroke(nDec, sepStyle, 0, 0, \"\", true);\n }\n AFDate_FormatEx(cFormat) {\n const event = globalThis.event;\n const value = event.value;\n if (!value) {\n return;\n }\n const date = this._parseDate(cFormat, value);\n if (date !== null) {\n event.value = this._util.printd(cFormat, date);\n }\n }\n AFDate_Format(pdf) {\n this.AFDate_FormatEx(DateFormats[pdf] ?? pdf);\n }\n AFDate_KeystrokeEx(cFormat) {\n const event = globalThis.event;\n if (!event.willCommit) {\n return;\n }\n const value = this.AFMergeChange(event);\n if (!value) {\n return;\n }\n if (this._parseDate(cFormat, value) === null) {\n const invalid = GlobalConstants.IDS_INVALID_DATE;\n const invalid2 = GlobalConstants.IDS_INVALID_DATE2;\n const err = `${invalid} ${this._mkTargetName(event)}${invalid2}${cFormat}`;\n this._app.alert(err);\n event.rc = false;\n }\n }\n AFDate_Keystroke(pdf) {\n if (pdf >= 0 && pdf < DateFormats.length) {\n this.AFDate_KeystrokeEx(DateFormats[pdf]);\n }\n }\n AFRange_Validate(bGreaterThan, nGreaterThan, bLessThan, nLessThan) {\n const event = globalThis.event;\n if (!event.value) {\n return;\n }\n const value = this.AFMakeNumber(event.value);\n if (value === null) {\n return;\n }\n bGreaterThan = !!bGreaterThan;\n bLessThan = !!bLessThan;\n if (bGreaterThan) {\n nGreaterThan = this.AFMakeNumber(nGreaterThan);\n if (nGreaterThan === null) {\n return;\n }\n }\n if (bLessThan) {\n nLessThan = this.AFMakeNumber(nLessThan);\n if (nLessThan === null) {\n return;\n }\n }\n let err = \"\";\n if (bGreaterThan && bLessThan) {\n if (value < nGreaterThan || value > nLessThan) {\n err = this._util.printf(GlobalConstants.IDS_GT_AND_LT, nGreaterThan, nLessThan);\n }\n } else if (bGreaterThan) {\n if (value < nGreaterThan) {\n err = this._util.printf(GlobalConstants.IDS_GREATER_THAN, nGreaterThan);\n }\n } else if (value > nLessThan) {\n err = this._util.printf(GlobalConstants.IDS_LESS_THAN, nLessThan);\n }\n if (err) {\n this._app.alert(err);\n event.rc = false;\n }\n }\n AFSimple(cFunction, nValue1, nValue2) {\n const value1 = this.AFMakeNumber(nValue1);\n if (value1 === null) {\n throw new Error(\"Invalid nValue1 in AFSimple\");\n }\n const value2 = this.AFMakeNumber(nValue2);\n if (value2 === null) {\n throw new Error(\"Invalid nValue2 in AFSimple\");\n }\n switch (cFunction) {\n case \"AVG\":\n return (value1 + value2) / 2;\n case \"SUM\":\n return value1 + value2;\n case \"PRD\":\n return value1 * value2;\n case \"MIN\":\n return Math.min(value1, value2);\n case \"MAX\":\n return Math.max(value1, value2);\n }\n throw new Error(\"Invalid cFunction in AFSimple\");\n }\n AFSimple_Calculate(cFunction, cFields) {\n const actions = {\n AVG: args => Math.sumPrecise(args) / args.length,\n SUM: args => Math.sumPrecise(args),\n PRD: args => args.reduce((acc, value) => acc * value, 1),\n MIN: args => Math.min(...args),\n MAX: args => Math.max(...args)\n };\n if (!(cFunction in actions)) {\n throw new TypeError(\"Invalid function in AFSimple_Calculate\");\n }\n const event = globalThis.event;\n const values = [];\n cFields = this.AFMakeArrayFromList(cFields);\n for (const cField of cFields) {\n const field = this._document.getField(cField);\n if (!field) {\n continue;\n }\n for (const child of field.getArray()) {\n const number = this.AFMakeNumber(child.value);\n values.push(number ?? 0);\n }\n }\n if (values.length === 0) {\n event.value = 0;\n return;\n }\n const res = actions[cFunction](values);\n event.value = Math.round(1e6 * res) / 1e6;\n }\n AFSpecial_Format(psf) {\n const event = globalThis.event;\n if (!event.value) {\n return;\n }\n psf = this.AFMakeNumber(psf);\n let formatStr;\n switch (psf) {\n case 0:\n formatStr = \"99999\";\n break;\n case 1:\n formatStr = \"99999-9999\";\n break;\n case 2:\n formatStr = this._util.printx(\"9999999999\", event.value).length >= 10 ? \"(999) 999-9999\" : \"999-9999\";\n break;\n case 3:\n formatStr = \"999-99-9999\";\n break;\n default:\n throw new Error(\"Invalid psf in AFSpecial_Format\");\n }\n event.value = this._util.printx(formatStr, event.value);\n }\n AFSpecial_KeystrokeEx(cMask) {\n const event = globalThis.event;\n const simplifiedFormatStr = cMask.replaceAll(/[^9AOX]/g, \"\");\n this.#AFSpecial_KeystrokeEx_helper(simplifiedFormatStr, null, false);\n if (event.rc) {\n return;\n }\n event.rc = true;\n this.#AFSpecial_KeystrokeEx_helper(cMask, null, true);\n }\n #AFSpecial_KeystrokeEx_helper(cMask, value, warn) {\n if (!cMask) {\n return;\n }\n const event = globalThis.event;\n value ||= this.AFMergeChange(event);\n if (!value) {\n return;\n }\n const checkers = new Map([[\"9\", char => char >= \"0\" && char <= \"9\"], [\"A\", char => \"a\" <= char && char <= \"z\" || \"A\" <= char && char <= \"Z\"], [\"O\", char => \"a\" <= char && char <= \"z\" || \"A\" <= char && char <= \"Z\" || \"0\" <= char && char <= \"9\"], [\"X\", char => true]]);\n function _checkValidity(_value, _cMask) {\n for (let i = 0, ii = _value.length; i < ii; i++) {\n const mask = _cMask.charAt(i);\n const char = _value.charAt(i);\n const checker = checkers.get(mask);\n if (checker) {\n if (!checker(char)) {\n return false;\n }\n } else if (mask !== char) {\n return false;\n }\n }\n return true;\n }\n const err = `${GlobalConstants.IDS_INVALID_VALUE} = \"${cMask}\"`;\n if (value.length > cMask.length) {\n if (warn) {\n this._app.alert(err);\n }\n event.rc = false;\n return;\n }\n if (event.willCommit) {\n if (value.length < cMask.length) {\n if (warn) {\n this._app.alert(err);\n }\n event.rc = false;\n return;\n }\n if (!_checkValidity(value, cMask)) {\n if (warn) {\n this._app.alert(err);\n }\n event.rc = false;\n return;\n }\n event.value += cMask.substring(value.length);\n return;\n }\n if (value.length < cMask.length) {\n cMask = cMask.substring(0, value.length);\n }\n if (!_checkValidity(value, cMask)) {\n if (warn) {\n this._app.alert(err);\n }\n event.rc = false;\n }\n }\n AFSpecial_Keystroke(psf) {\n const event = globalThis.event;\n psf = this.AFMakeNumber(psf);\n let value = this.AFMergeChange(event);\n let formatStr, secondFormatStr;\n switch (psf) {\n case 0:\n formatStr = \"99999\";\n break;\n case 1:\n formatStr = \"99999-9999\";\n break;\n case 2:\n formatStr = \"999-9999\";\n secondFormatStr = \"(999) 999-9999\";\n break;\n case 3:\n formatStr = \"999-99-9999\";\n break;\n default:\n throw new Error(\"Invalid psf in AFSpecial_Keystroke\");\n }\n const formats = secondFormatStr ? [formatStr, secondFormatStr] : [formatStr];\n for (const format of formats) {\n this.#AFSpecial_KeystrokeEx_helper(format, value, false);\n if (event.rc) {\n return;\n }\n event.rc = true;\n }\n const re = /([-()]|\\s)+/g;\n value = value.replaceAll(re, \"\");\n for (const format of formats) {\n this.#AFSpecial_KeystrokeEx_helper(format.replaceAll(re, \"\"), value, false);\n if (event.rc) {\n return;\n }\n event.rc = true;\n }\n this.AFSpecial_KeystrokeEx((secondFormatStr && value.match(/\\d/g) || []).length > 7 ? secondFormatStr : formatStr);\n }\n AFTime_FormatEx(cFormat) {\n this.AFDate_FormatEx(cFormat);\n }\n AFTime_Format(pdf) {\n this.AFDate_FormatEx(TimeFormats[pdf] ?? pdf);\n }\n AFTime_KeystrokeEx(cFormat) {\n this.AFDate_KeystrokeEx(cFormat);\n }\n AFTime_Keystroke(pdf) {\n if (pdf >= 0 && pdf < TimeFormats.length) {\n this.AFDate_KeystrokeEx(TimeFormats[pdf]);\n }\n }\n eMailValidate(str) {\n return this._emailRegex.test(str);\n }\n AFExactMatch(rePatterns, str) {\n if (rePatterns instanceof RegExp) {\n return str.match(rePatterns)?.[0] === str || 0;\n }\n return rePatterns.findIndex(re => str.match(re)?.[0] === str) + 1;\n }\n}\n\n;// ./src/scripting_api/event.js\n\nclass Event {\n constructor(data) {\n this.change = data.change || \"\";\n this.changeEx = data.changeEx || null;\n this.commitKey = data.commitKey || 0;\n this.fieldFull = data.fieldFull || false;\n this.keyDown = data.keyDown || false;\n this.modifier = data.modifier || false;\n this.name = data.name;\n this.rc = true;\n this.richChange = data.richChange || [];\n this.richChangeEx = data.richChangeEx || [];\n this.richValue = data.richValue || [];\n this.selEnd = data.selEnd ?? -1;\n this.selStart = data.selStart ?? -1;\n this.shift = data.shift || false;\n this.source = data.source || null;\n this.target = data.target || null;\n this.targetName = \"\";\n this.type = \"Field\";\n this.value = data.value || \"\";\n this.willCommit = data.willCommit || false;\n }\n}\nclass EventDispatcher {\n constructor(document, calculationOrder, objects, externalCall) {\n this._document = document;\n this._calculationOrder = calculationOrder;\n this._objects = objects;\n this._externalCall = externalCall;\n this._document.obj._eventDispatcher = this;\n this._isCalculating = false;\n }\n mergeChange(event) {\n let value = event.value;\n if (Array.isArray(value)) {\n return value;\n }\n if (typeof value !== \"string\") {\n value = value.toString();\n }\n const prefix = event.selStart >= 0 ? value.substring(0, event.selStart) : \"\";\n const postfix = event.selEnd >= 0 && event.selEnd <= value.length ? value.substring(event.selEnd) : \"\";\n return `${prefix}${event.change}${postfix}`;\n }\n userActivation() {\n this._document.obj._userActivation = true;\n this._externalCall(\"setTimeout\", [USERACTIVATION_CALLBACKID, USERACTIVATION_MAXTIME_VALIDITY]);\n }\n dispatch(baseEvent) {\n const id = baseEvent.id;\n if (!(id in this._objects)) {\n let event;\n if (id === \"doc\" || id === \"page\") {\n event = globalThis.event = new Event(baseEvent);\n event.source = event.target = this._document.wrapped;\n event.name = baseEvent.name;\n }\n if (id === \"doc\") {\n const eventName = event.name;\n if (eventName === \"Open\") {\n this.userActivation();\n this._document.obj._initActions();\n this.formatAll();\n }\n if (![\"DidPrint\", \"DidSave\", \"WillPrint\", \"WillSave\"].includes(eventName)) {\n this.userActivation();\n }\n this._document.obj._dispatchDocEvent(event.name);\n } else if (id === \"page\") {\n this.userActivation();\n this._document.obj._dispatchPageEvent(event.name, baseEvent.actions, baseEvent.pageNumber);\n } else if (id === \"app\" && b