var __defProp = Object.defineProperty; var __defNormalProp = (_0x41471d, _0x1e1100, _0x28c88f) => _0x1e1100 in _0x41471d ? __defProp(_0x41471d, _0x1e1100, { enumerable: true, configurable: true, writable: true, value: _0x28c88f, }) : (_0x41471d[_0x1e1100] = _0x28c88f); var __name = (_0x2cc3f2, _0x2cbd13) => __defProp(_0x2cc3f2, "name", { value: _0x2cbd13, configurable: true, }); var __publicField = (_0x1d9f24, _0x1bb1c5, _0x151e39) => __defNormalProp( _0x1d9f24, typeof _0x1bb1c5 !== "symbol" ? _0x1bb1c5 + "" : _0x1bb1c5, _0x151e39 ); import { j as _0x288a9b, _ as _0x5c4fdf, b as _0x27c34c, c as _0x44b372, l as _0x4b0578, d as _0x39aa0d, p as _0x4d9c6f, } from "./vendor.mjs"; import { m as _0x119297, s as _0x499903, u as _0x69751b, g as _0x33a514, t as _0x549107, M as _0x177173, a as _0x47bd8f, } from "./FoundryGui.mjs"; const _ModuleImporter = class _ModuleImporter { constructor(_0x201ad8) { __publicField(this, "additionalMessages", ""); __publicField(this, "sceneSort", 0); __publicField(this, "adventure"); __publicField(this, "npcActors", new Map()); __publicField(this, "createdFolders", []); this.adventure = _0x201ad8; } async fetchJson(_0x5daf33) { const _0x44882b = await fetch("/modules/pdftofoundry/" + _0x5daf33); return await _0x44882b.json(); } async fromUuid(_0x2b073f) { const _0x3aefec = await fromUuid(_0x2b073f); if (!_0x3aefec) { return null; } return game.actors.fromCompendium(_0x3aefec); } async ensureFolderExists(_0x1e5d43) { if (this.createdFolders.includes(_0x1e5d43)) { return; } const _0xf4481d = _0x1e5d43.split("/"); if (_0xf4481d.length > 1) { await this.ensureFolderExists( _0xf4481d.slice(0, _0xf4481d.length - 1).join("/") ); } try { await _0x119297(_0x1e5d43); } catch {} await _0x499903(500); this.createdFolders.push(_0x1e5d43); } async emitFile(_0x329632, _0x4bf299, _0x1d3cf7) { const _0x5e78d8 = game.settings.get("pdftofoundry", "basePath"); const _0x115a13 = _0x288a9b(_0x5e78d8, this.adventure.prefix, _0x329632); await this.ensureFolderExists(_0x115a13); await _0x69751b(_0x1d3cf7, _0x115a13, _0x4bf299); return _0x288a9b(_0x115a13, _0x4bf299); } async emitImage(_0x33f4d7, _0x53eabe, _0x46d6d8) { if (_0x46d6d8.toBlob === undefined) { return await this.emitFile( _0x33f4d7, _0x53eabe, await _0x46d6d8.toBuffer() ); } const _0x4ea853 = await new Promise((_0x5bce14) => _0x46d6d8.toBlob((_0x2cbf77) => _0x5bce14(_0x2cbf77), "image/webp") ); return await this.emitFile(_0x33f4d7, _0x53eabe, _0x4ea853); } getCanonicalArtForToken(_0x4a9600) { const _0x453a44 = _0x33a514() .filter((_0x30f0c4) => _0x30f0c4.prefix !== this.adventure.prefix) .flatMap((_0x220801) => _0x220801.npcs .filter((_0x40d020) => _0x4a9600.shouldBeReplacedByArt(_0x40d020)) .map((_0x12f759) => _0x549107.getTokenArt(_0x220801, _0x12f759)) .filter((_0x2cf234) => _0x2cf234 !== undefined) ); if (_0x453a44 == null) { return undefined; } else { return _0x453a44[0]; } } async finalize() { _0x549107.uploadTokenArt(); ui.notifications.queue = []; } fixupJournal(_0x416647, _0x3d92f0) { _0x416647.text.content = _0x416647.text.content.replace( /

([^<>]+)<\/h4>/g, (_0x209bf9, _0x6c074d, _0x13d257) => { if (_0x3d92f0.has(_0x6c074d)) { return "@Actor[" + _0x3d92f0.get(_0x6c074d) + "]{" + _0x13d257 + "}"; } console.log( "PDFToFoundry | Couldn't find actor for " + _0x6c074d + " : " + _0x13d257 ); return _0x209bf9; } ); } getCanonicalSceneMapping() { const _0x5fedd7 = game.settings.get("pdftofoundry", "basePath"); const _0x22d98d = _0x33a514().flatMap((_0x4cd3bb) => _0x4cd3bb.scenes.map((_0x370c45) => { var _0x4d9c6e; var _0xa165fd; return { path: _0x288a9b( _0x5fedd7, _0x4cd3bb.prefix, _0x370c45.name + ".webp" ), name: (_0x4d9c6e = _0x370c45.canonical) == null ? undefined : _0x4d9c6e.name, priority: (_0xa165fd = _0x370c45.canonical) == null ? undefined : _0xa165fd.priority, }; }) ); return _0x22d98d; } async createScene(_0x124656, _0x309d88, _0x178cb7, _0x379612) { if (_0x309d88) { const _0x49b3ea = this.getCanonicalSceneMapping(); for (const _0xffae0c of game.scenes.contents) { const _0x15cde2 = _0x49b3ea .filter((_0x579885) => _0x579885.name === _0x309d88) .find((_0x42f0f5) => _0x42f0f5.path === _0xffae0c.background.src); if (_0x15cde2 && _0x178cb7 > _0x15cde2.priority) { await _0xffae0c.update({ img: _0x124656.background.src, width: _0x124656.width, height: _0x124656.height, "background.offsetX": _0x124656.background.offsetX, "background.offsetY": _0x124656.background.offsetY, }); const _0x1e7c6a = await _0xffae0c.createThumbnail(); _0xffae0c.update( { thumb: _0x1e7c6a.thumb, }, { diff: false, } ); if (!game.settings.get("pdftofoundry", "alwaysCreateScenes")) { return; } } else if (_0x15cde2 && _0x178cb7 < _0x15cde2.priority) { _0x124656.background.src = _0xffae0c.background.src; _0x124656.width = _0xffae0c.width; _0x124656.height = _0xffae0c.height; _0x124656.background.offsetX = _0xffae0c.background.offsetX; _0x124656.background.offsetY = _0xffae0c.background.offSetY; _0x178cb7 = _0x15cde2.priority; } } } const [_0x5f3b5e] = await Scene.createDocuments([_0x124656]); _0x124656._id = _0x5f3b5e.id; const _0x23de64 = []; for (const _0x29c729 of _0x379612) { const _0x5cfdbf = this.npcActors[_0x29c729.id]; if (!_0x5cfdbf) { continue; } const _0x2368cb = await _0x5cfdbf.getTokenDocument({ x: _0x29c729.x, y: _0x29c729.y, hidden: true, }); _0x23de64.push(_0x2368cb.toObject()); } _0x5f3b5e.createEmbeddedDocuments("Token", _0x23de64); const _0x1f09c5 = game.scenes.get(_0x5f3b5e.id); if (_0x1f09c5) { const _0x1078c9 = await _0x1f09c5.createThumbnail(); await _0x1f09c5.update( { thumb: _0x1078c9.thumb, }, { diff: false, } ); } return _0x1f09c5; } async importActor(_0x4952b6, _0x35f7fc) { const _0x4db2b0 = this.getCanonicalArtForToken(_0x35f7fc.npc); const _0x3e9576 = await this.fromUuid(_0x4952b6); if (!_0x3e9576) { return null; } _0x3e9576.img = _0x4db2b0 !== undefined ? _0x4db2b0.actor : _0x35f7fc.img; _0x3e9576.prototypeToken.texture.src = _0x4db2b0 !== undefined ? _0x4db2b0.token : _0x35f7fc.token; _0x3e9576.folder = _0x35f7fc.folder; if (_0x35f7fc.name) { _0x3e9576.name = _0x35f7fc.name; _0x3e9576.prototypeToken.name = _0x35f7fc.name; } if (_0x35f7fc.elite) { _0x3e9576.system.traits.value.push("elite"); } if (_0x35f7fc.weak) { _0x3e9576.system.traits.value.push("weak"); } _0x3e9576.flags.pdftofoundry = { module: this.adventure.prefix, id: _0x35f7fc.id, }; const _0x5aedd8 = game.settings.get( "pdftofoundry", "alwaysUseImportedIcons" ); if (!_0x5aedd8) { const _0x329777 = game.compendiumArt.get(_0x35f7fc.npc.uniqueKey); if (_0x329777 !== undefined) { _0x3e9576.img = _0x329777.actor; foundry.utils.mergeObject(_0x3e9576.prototypeToken, _0x329777.token, { inplace: true, recursive: true, }); } } let _0x2eff27 = null; if (!this.adventure.noImport) { const _0x5eabcb = CONFIG.Actor.documentClass; const _0x46106a = await _0x5eabcb.createDocuments([_0x3e9576], { fromCompendium: true, }); _0x2eff27 = _0x46106a[0]; this.npcActors[_0x35f7fc.id] = _0x46106a[0]; } if (_0x4db2b0 === undefined && !_0x35f7fc.npc.isPlaceholderArt()) { _0x549107.setTokenArt(this.adventure, _0x35f7fc, { actor: _0x35f7fc.img, token: _0x35f7fc.token, }); } return _0x2eff27; } async import(_0x33b8e3, _0x4f3a13) { var _0x1e99b0; var _0x1ea252; const _0x5d005e = new _0x177173(); this.adventure.progressFn = _0x4f3a13; this.adventure.preprocess(_0x33b8e3.textDetails); await this.adventure.extractImageJournals(_0x33b8e3, _0x5d005e, this); const _0x37d873 = {}; for (const [_0x14317d, _0x570d62] of this.adventure.pages.entries()) { _0x4f3a13( "Extracting page " + _0x14317d, _0x14317d / this.adventure.pages.length ); _0x570d62(_0x33b8e3, (_0x5f5919, _0x546344) => { if (_0x37d873[_0x5f5919] === undefined) { _0x37d873[_0x5f5919] = []; } _0x37d873[_0x5f5919].push(_0x546344); }); } for (let _0x1eda14 in _0x37d873) { const _0x53ccf3 = this.adventure.extractDetails( _0x37d873[_0x1eda14], _0x5d005e, _0x1eda14 ); for (const _0x44ebe4 of _0x53ccf3) { _0x5d005e.journalEntries.push(_0x44ebe4); if (_0x1eda14.startsWith("sidebar")) { _0x1eda14 = "Sidebars"; } } } this.adventure.finalize(_0x5d005e); _0x549107.eagerLoad(); const _0x379219 = __name((_0x47ca53, _0x3531cd = "m") => { let _0x3de05e = undefined; return async () => (_0x3de05e ||= ( await Folder.createDocuments([ { name: this.adventure.fullName, type: _0x47ca53, parent: null, sorting: _0x3531cd, }, ]) )[0]); }, "lazyFolder"); const _0x287d1a = _0x379219("Scene"); const _0x267e82 = _0x379219("JournalEntry"); const _0x4e0d0e = _0x379219("Actor", "a"); for (const _0x1d2f7f of this.adventure.combines) { this.adventure.appendJournal(_0x5d005e, _0x1d2f7f.source, _0x1d2f7f.dest); } const _0x1651d5 = new Map(); for (const [_0x5f4f98, _0x123bae] of this.adventure.npcs.entries()) { _0x4f3a13( "Extracting npc " + _0x5f4f98, _0x5f4f98 / this.adventure.npcs.length ); const _0x20825f = await _0x123bae.generate(_0x33b8e3, this); if (_0x20825f === undefined) { console.error( "PDFToFoundry | There wasn't an npc to import for " + _0x123bae.id ); continue; } if (!this.adventure.noImport); const [_0x5ce8bc, _0x35cd79] = _0x20825f; const _0x48e8cd = await this.importActor(_0x5ce8bc, { ..._0x35cd79, folder: (await _0x4e0d0e()).id, }); if (!_0x48e8cd) { if (_0x48e8cd === undefined) { this.additionalMessages += "
Failed importing " + _0x123bae.id; } continue; } for (const _0x149550 of _0x123bae.forIds ?? []) { _0x1651d5.set(_0x149550, _0x48e8cd.id); } } for (const _0x4dd10e of _0x5d005e.journalEntries) { this.fixupJournal(_0x4dd10e, _0x1651d5); } let _0x571e55 = 0; let _0x1cfba7 = [..._0x5d005e.journalEntries]; const _0x1ce87e = []; for (const _0x3f348e of this.adventure.journalPages) { const _0x2520a4 = _0x3f348e.pages .map((_0xd8e762) => { const _0x183269 = _0x1cfba7.find( (_0x3dcf91) => _0x3dcf91.flags.pdftofoundry.id === _0xd8e762.id ); if (_0x183269 !== undefined && _0xd8e762.name) { _0x183269.name = _0x33b8e3.decodeEncodedString(_0xd8e762.name); } return _0x183269; }) .filter((_0x11a9f0) => _0x11a9f0); _0x1cfba7 = _0x1cfba7.filter( (_0xbc5b3b) => !_0x2520a4.some( (_0x165b78) => _0x165b78.flags.pdftofoundry.id === _0xbc5b3b.flags.pdftofoundry.id ) ); if (_0x2520a4.length > 0) { _0x1ce87e.push({ name: _0x33b8e3.decodeEncodedString(_0x3f348e.name), pages: _0x2520a4, }); } } if (_0x1cfba7.length > 0) { _0x1ce87e.push({ pages: _0x1cfba7, name: this.adventure.fullName, }); } for (const { pages: _0x21c0d2, name: _0x1c7400 } of _0x1ce87e) { _0x571e55 += 100; const _0x3233a1 = { name: _0x1c7400, folder: (await _0x267e82()).id, sort: _0x571e55, permission: { default: 0, }, pages: _0x21c0d2.map((_0x3eb743) => ({ ..._0x3eb743, })), }; const _0x2b60a8 = await JournalEntry.createDocuments([_0x3233a1]); for (let _0x387fc9 = 0; _0x387fc9 < _0x21c0d2.length; _0x387fc9++) { _0x21c0d2[_0x387fc9].journalId = _0x2b60a8[0].id; _0x21c0d2[_0x387fc9].journalPageId = _0x2b60a8[0].pages.contents[_0x387fc9].id; } } let _0x13c5cc = 0; let _0x2128e9 = undefined; for (const [_0x1ecc24, _0xedee92] of this.adventure.scenes.entries()) { _0x4f3a13( "Extracting scene " + _0x1ecc24, _0x1ecc24 / this.adventure.scenes.length ); try { const _0x461656 = await _0xedee92.generate(_0x33b8e3, _0x5d005e, this); if (_0x461656 === undefined) { continue; } _0x13c5cc += 100; const _0x4cc403 = await this.createScene( { ..._0x461656, sort: _0x13c5cc, folder: (await _0x287d1a()).id, }, (_0x1e99b0 = _0xedee92.canonical) == null ? undefined : _0x1e99b0.name, (_0x1ea252 = _0xedee92.canonical) == null ? undefined : _0x1ea252.priority, _0xedee92.tokens ); _0x2128e9 = _0x2128e9 ?? _0x4cc403; } catch (_0x56b968) { console.error(_0x56b968); } } this.finalize(); if (_0x2128e9 !== undefined) { await _0x2128e9.activate(); } _0x4f3a13("Complete. Enjoy!", 1); } }; __name(_ModuleImporter, "ModuleImporter"); let ModuleImporter = _ModuleImporter; const _PdfData = class _PdfData { constructor(_0x3d07d1) { __publicField(this, "imageDetails"); __publicField(this, "textDetails"); Object.assign(this, _0x3d07d1); } createEncodedStringFromText(_0x2af7a7) { let _0x4af552 = ""; let _0x43a6ba = _0x2af7a7; while (_0x43a6ba.length > 0) { let _0x563f9b = false; for (let _0xf2884e = _0x43a6ba.length; _0xf2884e > 0; _0xf2884e--) { const _0x12c7d9 = _0x43a6ba.substring(0, _0xf2884e); let _0x28d3ca = undefined; if (_0xf2884e === 1) { _0x28d3ca = _0x12c7d9; } for (const _0x4075f0 of this.textDetails) { const _0x4025f1 = _0x4075f0.text .toLocaleLowerCase() .indexOf(_0x12c7d9.toLocaleLowerCase()); if (_0x4025f1 !== -1) { const _0x8d6a01 = _0x4075f0.text.substring( _0x4025f1, _0x4025f1 + _0xf2884e ); let _0x237827 = undefined; if (_0x8d6a01 === _0x12c7d9) { _0x237827 = "{" + _0x4075f0.id + ":" + _0x4025f1 + ":" + (_0x4025f1 + _0xf2884e) + "}"; } else if (this.sentenceCase(_0x8d6a01) === _0x12c7d9) { _0x237827 = "{" + _0x4075f0.id + ":" + _0x4025f1 + ":" + (_0x4025f1 + _0xf2884e) + ":S}"; } else if (_0x8d6a01.toLocaleUpperCase() === _0x12c7d9) { _0x237827 = "{" + _0x4075f0.id + ":" + _0x4025f1 + ":" + (_0x4025f1 + _0xf2884e) + ":U}"; } else if (_0x8d6a01.toLocaleLowerCase() === _0x12c7d9) { _0x237827 = "{" + _0x4075f0.id + ":" + _0x4025f1 + ":" + (_0x4025f1 + _0xf2884e) + ":L}"; } else { const _0x494a06 = [...Array(_0x12c7d9.length).keys()].filter( (_0x431cd8) => _0x12c7d9[_0x431cd8] === _0x12c7d9[_0x431cd8].toLocaleUpperCase() ); _0x237827 = "{" + _0x4075f0.id + ":" + _0x4025f1 + ":" + (_0x4025f1 + _0xf2884e) + ":" + _0x494a06.join(",") + "}"; } if ( _0x28d3ca === undefined || _0x237827.length < _0x28d3ca.length ) { _0x28d3ca = _0x237827; } } } if (_0x28d3ca) { _0x4af552 += _0x28d3ca; _0x43a6ba = _0x43a6ba.substring(_0xf2884e); _0x563f9b = true; break; } } if (!_0x563f9b) { break; } } return _0x4af552; } decodeEncodedString(_0x4e3b28) { return _0x4e3b28.replace( /\{([^}]*):([^}]*):([^}]*)(:([^}]*))?\}/g, (_0xed3863) => { const _0x37b413 = _0xed3863 .substring(1, _0xed3863.length - 1) .split(":"); const _0x1a45ee = this.textDetails.find( (_0x37c57d) => _0x37c57d.id === _0x37b413[0] ); if (!_0x1a45ee) { return ""; } let _0x28b859 = _0x1a45ee.text.substring( Number(_0x37b413[1]), Number(_0x37b413[2]) ); if (_0x37b413.length >= 4 && _0x37b413[3] === "L") { _0x28b859 = _0x28b859.toLocaleLowerCase(); } else if (_0x37b413.length >= 4 && _0x37b413[3] === "U") { _0x28b859 = _0x28b859.toLocaleUpperCase(); } else if (_0x37b413.length >= 4 && _0x37b413[3] === "S") { _0x28b859 = this.sentenceCase(_0x28b859); } else if (_0x37b413.length >= 4) { const _0x37f938 = _0x37b413[3].split(","); _0x28b859 = [...Array(_0x28b859.length).keys()] .map((_0x5878a3) => _0x37f938.find((_0x2989d0) => _0x2989d0 === "" + _0x5878a3) ? _0x28b859[_0x5878a3].toLocaleUpperCase() : _0x28b859[_0x5878a3] ) .join(""); } return _0x28b859; } ); } sentenceCase(_0x10efce) { return _0x10efce .split(" ") .map((_0x704cc) => _0x704cc.length > 1 ? _0x704cc[0].toUpperCase() + _0x704cc.substr(1).toLowerCase() : _0x704cc ) .join(" ") .trim(); } getText(_0x25dc31) { const _0xc8a098 = this.textDetails.find( (_0x42f834) => _0x42f834.page === _0x25dc31.page && Math.abs(_0x42f834.x - _0x25dc31.x) < 1 && Math.abs(_0x42f834.y - _0x25dc31.y) < 1 ); if (!_0xc8a098) { return ""; } let _0x46d80b = _0xc8a098.text; if (_0x25dc31.substring !== undefined) { _0x46d80b = _0x46d80b.substring( _0x25dc31.substring.start, _0x25dc31.substring.end ); } if ( _0x25dc31.sentenceCase === undefined || _0x25dc31.sentenceCase === true ) { _0x46d80b = this.sentenceCase(_0x46d80b); } return _0x46d80b; } getTextById(_0xd41d59) { const _0x5c844b = this.textDetails.find( (_0x570364) => _0x570364.id === _0xd41d59 ); if (!_0x5c844b) { return ""; } return _0x5c844b.text; } }; __name(_PdfData, "PdfData"); let PdfData = _PdfData; function log(_0x2af440) {} __name(log, "log"); async function parsePdf(_0x3e4a48, _0x376800, _0x2a6a09) { const _0xaced8 = _0x5c4fdf(_0x3e4a48); const _0x48d8b9 = await _0xaced8.promise; const _0x4837fd = []; const _0x1ad58f = []; const _0x198638 = new Set(); let _0x562860 = 1; const _0xe67a5d = Array(_0x48d8b9.numPages) .fill(1) .map((_0x42e0a5, _0x56880b) => _0x42e0a5 + _0x56880b); for (let _0x4ec28c = 0; _0x4ec28c < _0xe67a5d.length; _0x4ec28c++) { const _0x2a0d7b = _0xe67a5d[_0x4ec28c]; _0x376800("Fetching page " + _0x2a0d7b, _0x4ec28c / _0xe67a5d.length); const _0x379152 = await _0x48d8b9.getPage(_0x2a0d7b); const _0x451685 = await _0x379152.getOperatorList({ intent: "any", }); const _0x2a33c0 = _0x562860; let _0x8975ab = false; const _0x37bdf5 = []; const _0x45714f = __name((_0x1b2409) => { let _0x21bbdd = _0x1b2409; let _0x582d6f = [1, 0, 0, 1, 0, 0]; try { const _0x59a23d = _0x379152.commonObjs.get(_0x1b2409); _0x21bbdd = _0x59a23d.name; if (_0x59a23d.fontMatrix) { _0x582d6f = _0x59a23d.fontMatrix; } } catch {} const _0x51cd5e = _0x1b2409.indexOf("+"); if (_0x51cd5e !== -1) { _0x21bbdd = _0x1b2409.substring(_0x51cd5e + 1); } return [_0x21bbdd, _0x582d6f]; }, "getFontDetails"); const _0x2e99fe = Object.entries(_0x27c34c).reduce( (_0x59bcbb, _0x535250) => { const [_0x38ee1e, _0x1ea908] = _0x535250; _0x59bcbb[_0x1ea908] = _0x38ee1e; return _0x59bcbb; }, {} ); const _0x326258 = { fontName: "", baseFontSize: 1, currentTextMatrix: [1, 0, 0, 1, 0, 0], currentTextLineMatrix: [1, 0, 0, 1, 0, 0], fillRGBColor: "", strokeRGBColor: "", lineWidth: 0, leading: 0, charSpacing: 0, wordSpacing: 0, gstate: {}, transform: [1, 0, 0, 1, 0, 0], path: [], clip: [], fontMatrix: [1, 0, 0, 1, 0, 0], textContinuation: false, }; const _0x305d54 = []; let _0x482ed6 = _0x326258; const _0x143dd9 = __name((_0x34392a, _0x46f028) => { _0x482ed6.currentTextLineMatrix[4] += _0x34392a * _0x482ed6.currentTextLineMatrix[0]; _0x482ed6.currentTextLineMatrix[5] += _0x46f028 * _0x482ed6.currentTextLineMatrix[3]; _0x482ed6.currentTextMatrix = [..._0x482ed6.currentTextLineMatrix]; _0x482ed6.textContinuation = false; }, "moveText"); for (let _0x132a45 = 0; _0x132a45 < _0x451685.fnArray.length; _0x132a45++) { const _0x3d94d9 = _0x451685.argsArray[_0x132a45]; const _0x6760d9 = _0x2e99fe[_0x451685.fnArray[_0x132a45]]; switch (_0x451685.fnArray[_0x132a45]) { case _0x27c34c.setTextMatrix: log(" setTextMatrix " + JSON.stringify(_0x3d94d9)); _0x482ed6.currentTextLineMatrix = _0x3d94d9; _0x482ed6.currentTextMatrix = [..._0x482ed6.currentTextLineMatrix]; break; case _0x27c34c.setFont: [_0x482ed6.fontName, _0x482ed6.baseFontSize] = _0x3d94d9; [_0x482ed6.fontName, _0x482ed6.fontMatrix] = _0x45714f( _0x482ed6.fontName ); _0x482ed6.fontName = _0x482ed6.fontName.replace(/[^+]+\+/, ""); break; case _0x27c34c.showText: { const _0x359d61 = _0x3d94d9[0] .map((_0x5a5f3d) => _0x5a5f3d.unicode) .join(""); const _0x4df8e0 = _0x3d94d9[0] .map((_0x331cad) => _0x331cad.width ?? 0) .reduce((_0x1f5b37, _0x10f24b) => _0x1f5b37 + _0x10f24b, 0); const _0x15382c = _0x3d94d9[0] .map((_0x11fda8) => _0x11fda8.isSpace ?? 0) .reduce((_0x9f5fc5, _0x541d49) => _0x9f5fc5 + _0x541d49, 0); const _0x2803b7 = _0x482ed6.currentTextMatrix[2]; const _0x2cc691 = _0x482ed6.currentTextMatrix[3]; const _0x31399c = Math.sqrt( _0x2803b7 * _0x2803b7 + _0x2cc691 * _0x2cc691 ); const _0x284037 = _0x482ed6.baseFontSize * _0x31399c; const _0x463402 = _0x482ed6.fontName + ":" + _0x284037; const _0x3efa92 = _0x482ed6.currentTextMatrix[4]; const _0x49f853 = _0x482ed6.currentTextMatrix[5]; log( "([" + _0x3efa92 + ", " + _0x49f853 + "], " + _0x482ed6.fontName + ":" + _0x284037 + " - " + _0x482ed6.fillRGBColor + "/" + _0x482ed6.strokeRGBColor + "/" + _0x482ed6.lineWidth + " [" + _0x482ed6.charSpacing + " / " + _0x482ed6.wordSpacing + "]) " + _0x4df8e0 + "/" + _0x15382c + ' - "' + _0x359d61 + '"' ); const _0x412eab = ensureId( _0x198638, (_0x461ccd) => _0x2a33c0 + ":" + Math.round(_0x3efa92) + ":" + Math.round(_0x49f853) + (_0x461ccd > 0 ? ":" + _0x461ccd : "") ); if (_0x49f853 === 2) { _0x8975ab = true; } const _0x15c6be = _0x4837fd.length > 0 && _0x4837fd[_0x4837fd.length - 1].text === _0x359d61; if (!_0x15c6be && _0x284037 > 4) { if ( _0x482ed6.textContinuation && _0x359d61.trim() === "" && _0x463402 === _0x4837fd[_0x4837fd.length - 1].fontId ) { _0x4837fd[_0x4837fd.length - 1].text = _0x4837fd[_0x4837fd.length - 1].text.trimEnd() + _0x359d61; } else if (_0x359d61.trim() !== "") { _0x4837fd.push({ text: _0x359d61, fontId: _0x463402, fontName: _0x482ed6.fontName, fontSize: _0x284037, color: _0x482ed6.fillRGBColor, isLeftAligned: false, isIndented: false, page: _0x2a33c0, x: _0x3efa92, y: _0x49f853, id: btoa(_0x412eab).replace(/=/g, ""), }); } } _0x482ed6.currentTextMatrix[4] += (_0x4df8e0 * _0x482ed6.fontMatrix[0] + _0x359d61.length * _0x482ed6.charSpacing + _0x15382c * _0x482ed6.wordSpacing) * _0x482ed6.currentTextMatrix[0]; _0x482ed6.textContinuation = true; break; } case _0x27c34c.beginText: break; case _0x27c34c.endText: break; case _0x27c34c.moveText: _0x143dd9(_0x3d94d9[0], _0x3d94d9[1]); break; case _0x27c34c.setCharSpacing: _0x482ed6.charSpacing = _0x3d94d9[0]; break; case _0x27c34c.setWordSpacing: _0x482ed6.wordSpacing = _0x3d94d9[0]; break; case _0x27c34c.setLeadingMoveText: log(" setLeadingMoveText " + JSON.stringify(_0x3d94d9)); _0x482ed6.leading = -_0x3d94d9[1]; _0x143dd9(_0x3d94d9[0], _0x3d94d9[1]); break; case _0x27c34c.nextLine: _0x143dd9(0, -_0x482ed6.leading); break; case _0x27c34c.save: log(" save - " + JSON.stringify(_0x482ed6)); _0x305d54.push(JSON.parse(JSON.stringify(_0x482ed6))); break; case _0x27c34c.restore: _0x482ed6 = _0x305d54.pop(); log(" restore - " + JSON.stringify(_0x482ed6)); break; case _0x27c34c.paintJpegXObject: case _0x27c34c.paintImageXObject: log(" " + _0x6760d9 + " - " + JSON.stringify(_0x3d94d9)); _0x37bdf5.push({ image: _0x3d94d9[0], gstate: _0x482ed6.gstate, transform: _0x482ed6.transform, clip: _0x482ed6.clip, }); break; case _0x27c34c.setFillRGBColor: _0x482ed6.fillRGBColor = "#" + Array.from(_0x3d94d9) .map((_0x31d9d2) => _0x31d9d2.toString(16).padStart(2, "0")) .join(""); log(" setFillRGBColor - " + JSON.stringify(_0x3d94d9)); break; case _0x27c34c.setStrokeRGBColor: _0x482ed6.strokeRGBColor = "#" + Array.from(_0x3d94d9) .map((_0x41389d) => _0x41389d.toString(16).padStart(2, "0")) .join(""); log(" setStrokeRGBColor - " + JSON.stringify(_0x3d94d9)); break; case _0x27c34c.setLineWidth: _0x482ed6.lineWidth = _0x3d94d9[0]; break; case _0x27c34c.setGState: log(" setGState - " + JSON.stringify(_0x482ed6.gstate)); break; case _0x27c34c.beginGroup: log(" beginGroup - " + JSON.stringify(_0x3d94d9[0])); _0x482ed6.gstate = _0x3d94d9[0]; break; case _0x27c34c.endGroup: log(" endGroup - " + JSON.stringify(_0x3d94d9[0])); _0x482ed6.gstate = {}; break; case _0x27c34c.transform: log(" transform - " + JSON.stringify(_0x3d94d9)); _0x482ed6.transform = _0x3d94d9; break; case _0x27c34c.constructPath: log(" constructPath - " + JSON.stringify(_0x3d94d9)); _0x482ed6.path = _0x3d94d9; break; case _0x27c34c.clip: _0x482ed6.clip.push(_0x482ed6.path); break; default: log(" ?" + _0x6760d9 + " - " + JSON.stringify(_0x3d94d9)); break; } } if (_0x8975ab || _0x2a33c0 + 3 < 11) { _0x562860 += 1; } for (const _0x23cf19 of _0x37bdf5) { const _0x47c34a = _0x23cf19.image; const _0x5d95a7 = _0x47c34a.startsWith("g_") ? _0x379152.commonObjs : _0x379152.objs; const _0x57ac3f = new Promise((_0x4b445a) => _0x5d95a7.get(_0x47c34a, (_0x4e3dd5) => _0x4b445a(_0x4e3dd5)) ); const _0x5816dc = await _0x57ac3f; let _0x3475c9 = __name(async (_0x2f0c95) => {}, "renderToCanvasFn"); if (_0x5816dc.src !== undefined) { _0x3475c9 = __name(async (_0x32d7ff) => { const _0x2fd524 = await _0x4b0578(_0x5816dc.src); _0x32d7ff.drawImage( _0x2fd524, 0, 0, _0x5816dc.width, _0x5816dc.height ); }, "renderToCanvasFn"); } else if (_0x5816dc.kind === 3) { _0x3475c9 = __name(async (_0x4f16fe) => { const _0x3450cd = _0x4f16fe.createImageData( _0x5816dc.width, _0x5816dc.height ); const _0x534496 = _0x3450cd.data; _0x534496.set(_0x5816dc.data, 0); _0x4f16fe.putImageData(_0x3450cd, 0, 0); }, "renderToCanvasFn"); } else if (_0x5816dc.kind === 2) { _0x3475c9 = __name(async (_0x4c76b1) => { const _0x50d661 = _0x4c76b1.createImageData( _0x5816dc.width, _0x5816dc.height ); const _0xf3e903 = _0x50d661.data; for ( let _0x296ae3 = 0, _0x2c4939 = 0; _0x296ae3 < _0x5816dc.data.length; _0x296ae3 += 3, _0x2c4939 += 4 ) { _0xf3e903[_0x2c4939] = _0x5816dc.data[_0x296ae3]; _0xf3e903[_0x2c4939 + 1] = _0x5816dc.data[_0x296ae3 + 1]; _0xf3e903[_0x2c4939 + 2] = _0x5816dc.data[_0x296ae3 + 2]; _0xf3e903[_0x2c4939 + 3] = 255; } _0x4c76b1.putImageData(_0x50d661, 0, 0); }, "renderToCanvasFn"); } else if (_0x5816dc.bitmap !== undefined) { _0x3475c9 = __name(async (_0x48306f) => { _0x48306f.drawImage( _0x5816dc.bitmap, 0, 0, _0x5816dc.width, _0x5816dc.height ); }, "renderToCanvasFn"); } else { console.error("unknown kind of image :( :( :("); } const _0x2a2f41 = __name( async ( _0x49327a, _0x47b689, _0x4beb2a, _0x445674, _0xed1541, _0x5ed590, _0x1b919e ) => { let _0x34ecf5 = _0x44b372(_0x5816dc.width, _0x5816dc.height); const _0x2dea93 = _0x34ecf5.getContext("2d"); await _0x3475c9(_0x2dea93); if ( _0x4beb2a !== undefined && _0x445674 !== undefined && _0xed1541 !== undefined && _0x5ed590 !== undefined ) { const _0x32a3a0 = _0xed1541 - _0x4beb2a; const _0x10f678 = _0x5ed590 - _0x445674; const _0x15c7e6 = _0x44b372(_0x32a3a0, _0x10f678); const _0x367b68 = _0x15c7e6.getContext("2d"); _0x367b68.fillStyle = "white"; _0x367b68.fillRect(0, 0, _0x15c7e6.width, _0x15c7e6.height); _0x367b68.drawImage( _0x34ecf5, _0x4beb2a, _0x445674, _0x32a3a0, _0x10f678, 0, 0, _0x32a3a0, _0x10f678 ); _0x34ecf5 = _0x15c7e6; } if (_0x1b919e !== undefined && _0x1b919e !== 0) { let _0x4bbecb = _0x34ecf5.width; let _0x34ae16 = _0x34ecf5.height; if (_0x1b919e % 2 !== 0) { [_0x4bbecb, _0x34ae16] = [_0x34ae16, _0x4bbecb]; } const _0x2104e1 = _0x44b372(_0x4bbecb, _0x34ae16); const _0x48b25f = _0x2104e1.getContext("2d"); _0x48b25f.fillStyle = "white"; _0x48b25f.fillRect(0, 0, _0x2104e1.width, _0x2104e1.height); _0x48b25f.save(); _0x48b25f.translate(_0x4bbecb / 2, _0x34ae16 / 2); _0x48b25f.rotate((_0x1b919e * Math.PI) / 2); _0x48b25f.drawImage( _0x34ecf5, -_0x34ecf5.width / 2, -_0x34ecf5.height / 2 ); _0x48b25f.restore(); _0x34ecf5 = _0x2104e1; } if ( _0x49327a !== undefined && _0x47b689 !== undefined && _0x49327a !== _0x5816dc.width && _0x47b689 !== _0x5816dc.height ) { const _0x38b10d = _0x44b372(_0x49327a, _0x47b689); const _0x574eb1 = _0x38b10d.getContext("2d"); _0x574eb1.fillStyle = "white"; _0x574eb1.fillRect(0, 0, _0x38b10d.width, _0x38b10d.height); _0x574eb1.drawImage( _0x34ecf5, 0, 0, _0x38b10d.width, _0x38b10d.height ); _0x34ecf5 = _0x38b10d; } return _0x34ecf5; }, "getImageCanvas" ); const _0x362bd2 = ensureId( _0x198638, (_0x3e5345) => _0x2a33c0 + ":" + JSON.stringify(_0x23cf19.transform) + (_0x3e5345 > 0 ? ":" + _0x3e5345 : "") ); _0x1ad58f.push({ id: btoa(_0x362bd2).replace(/=/g, ""), page: _0x2a33c0, width: _0x5816dc.width, height: _0x5816dc.height, transform: _0x23cf19.transform, gstate: _0x23cf19.gstate, clip: _0x23cf19.clip, getImageCanvas: _0x2a2f41, }); } } { for (const _0x23ba8c of _0x4837fd) { log( _0x23ba8c.fontId + " (" + _0x23ba8c.x + ", " + _0x23ba8c.y + ') "' + _0x23ba8c.text + '"' ); } } return new PdfData({ textDetails: _0x4837fd, imageDetails: _0x1ad58f, }); } __name(parsePdf, "parsePdf"); function ensureId(_0xf2cca, _0x465614) { let _0x336e6d = 0; let _0x48a307; while (true) { _0x48a307 = _0x465614(_0x336e6d); if (!_0xf2cca.has(_0x48a307)) { break; } _0x336e6d += 1; } _0xf2cca.add(_0x48a307); return _0x48a307; } __name(ensureId, "ensureId"); _0x39aa0d.workerSrc = _0x4d9c6f; const readUploadedFileAsBinary = __name((_0x1d9f8c) => { const _0x234455 = new FileReader(); return new Promise((_0x250ca3, _0x66b911) => { _0x234455.onerror = () => { _0x234455.abort(); _0x66b911(new DOMException("Problem parsing input file.")); }; _0x234455.onload = () => { _0x250ca3(_0x234455.result); }; _0x234455.readAsArrayBuffer(_0x1d9f8c); }); }, "readUploadedFileAsBinary"); const readUploadedFileAsText = __name((_0xb22c4c) => { const _0x4f26e4 = new FileReader(); return new Promise((_0x3f237d, _0x470efc) => { _0x4f26e4.onerror = () => { _0x4f26e4.abort(); _0x470efc(new DOMException("Problem parsing input file.")); }; _0x4f26e4.onload = () => { _0x3f237d(_0x4f26e4.result); }; _0x4f26e4.readAsText(_0xb22c4c); }); }, "readUploadedFileAsText"); function progressFn(_0x5a2b2e, _0x180328) { const _0x3b85cc = document.getElementById("loading"); const _0x6cec05 = Math.clamp(_0x180328 * 100, 0, 100); _0x3b85cc.querySelector("#context").textContent = _0x5a2b2e; _0x3b85cc.querySelector("#loading-bar").style.width = _0x6cec05 + "%"; _0x3b85cc.querySelector("#progress").textContent = ""; _0x3b85cc.style.display = "block"; if (_0x180328 === 1 && !_0x3b85cc.hidden) { $(_0x3b85cc).fadeOut(5000); } } __name(progressFn, "progressFn"); async function generateData(_0x4d785c) { let _0x21250c; if (_0x4d785c.type === "application/json") { const _0x311f4d = await readUploadedFileAsText(_0x4d785c); _0x21250c = { textDetails: JSON.parse(_0x311f4d), imageDetails: [], }; } else { const _0x4f5334 = await readUploadedFileAsBinary(_0x4d785c); const _0x249de0 = new Uint8Array(_0x4f5334); _0x21250c = await parsePdf(_0x249de0, progressFn); } const _0x3903f3 = _0x47bd8f(_0x21250c); if (_0x3903f3 === undefined) { progressFn("failed to detect pdf. cannot proceed.", 1); postChatMessage( "Could not detect PDF to import. PDF to Foundry only supports importing adventures that it has been programmed to support. For a list of supported adventures, please see the import dialog." ); return; } try { const _0xddc06c = new ModuleImporter(_0x3903f3); await _0xddc06c.import(_0x21250c, progressFn); const _0x19462c = "Your import of " + _0x3903f3.fullName + " is complete" + _0xddc06c.additionalMessages; postChatMessage(_0x19462c); } catch (_0x27931f) { progressFn(_0x27931f.message, 1); if ( _0x27931f.message === "Couldn't detect watermark :(. Please no pirate." ) { postChatMessage( "Couldn't detect watermark. PDF to Foundry will only import officially licensed adventures." ); } else { postChatMessage("Error: " + _0x27931f.message); } } } __name(generateData, "generateData"); function postChatMessage(_0x2dd0ab) { const _0x15d840 = { whisper: [game.userId], content: _0x2dd0ab, type: 0, blind: true, speaker: { alias: "PDF to Foundry", }, }; ChatMessage.create(_0x15d840, {}); } __name(postChatMessage, "postChatMessage"); export { generateData };