/*!
 * PSPDFKit for Web 2024.5.1 (https://pspdfkit.com/web)
 *
 * Copyright (c) 2016-2024 PSPDFKit GmbH. All rights reserved.
 *
 * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
 * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
 * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
 * This notice may not be removed from this file.
 *
 * PSPDFKit uses several open source third-party components: https://pspdfkit.com/acknowledgements/web/
 */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.PSPDFKit=e():t.PSPDFKit=e()}(globalThis,(()=>(()=>{"use strict";var t={r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e);const n=function t(e){let n;return n=e instanceof Error?e:new Error(e),Object.setPrototypeOf(n,t.prototype),n};n.prototype=Object.create(Error.prototype,{name:{value:"PSPDFKitError",enumerable:!1}});const o=n;function r(t,e){if(!t)throw new o(`Assertion failed: ${e||"Condition not met"}\n\nFor further assistance, please go to: https://pspdfkit.com/support/request`)}["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'].join(",");new WeakMap;async function a(t){const e=(await async function(t){try{const e=await fetch(t).catch((e=>{throw new o(`Error fetching dynamic fonts file ${t}. ${e}`)}));if(200!==e.status)throw new o(`Error fetching dynamic fonts file ${t}. Status code: ${e.status}`);return e}catch(t){throw t}}(t)).json().catch((e=>{throw new o(`Error parsing dynamic fonts file ${t}. ${e}`)}));return e}let i=function(t){return t[t.pdf_a_1a=0]="pdf_a_1a",t[t.pdf_a_1b=1]="pdf_a_1b",t[t.pdf_a_2a=2]="pdf_a_2a",t[t.pdf_a_2u=3]="pdf_a_2u",t[t.pdf_a_2b=4]="pdf_a_2b",t[t.pdf_a_3a=5]="pdf_a_3a",t[t.pdf_a_3u=6]="pdf_a_3u",t[t.pdf_a_3b=7]="pdf_a_3b",t[t.pdf_a_4=8]="pdf_a_4",t[t.pdf_a_4e=9]="pdf_a_4e",t[t.pdf_a_4f=10]="pdf_a_4f",t}({});const s="/create.pdf",f="/save.pdf",c="/create.docx",l="/save.docx",d="/templateData.json",u="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope;let p=null,y=null;function _(t){let e;r(y,"GdPicture WebAssembly is not loaded.");for(var n=arguments.length,o=new Array(n>1?n-1:0),a=1;a<n;a++)o[a-1]=arguments[a];for(const t of o)e=Object.assign(o[0],t);const i=JSON.stringify({type:t,...e}),s=JSON.parse(y.CommandHandler(i));if(!s.success)throw new Error(s.errorReason+": "+s.errorMessage+"\n"+s.error);return s}const b=new class{_mountCustomFonts(t,e){r(p,"WebAssembly module not loaded."),p.FS.mkdir(e);{const n=u?p.FS.filesystems.WORKERFS:p.FS.filesystems.MEMFS;p.FS.mount(n,{blobs:t},e)}}async loadModule(t,e,n,o,r,i,s){const{Assemblies:f,Module:c}=await async function(t,e){if("string"==typeof t){const n="pspdfkit-lib/",o=`${n}gdpicture-c88fa177/jit`,r=`${n}gdpicture-c88fa177/aot`;let a,i;e?(a=`${t}${r}/initDotnet.js`,i=`${t}${r}`):(a=`${t}${o}/initDotnet.js`,i=`${t}${o}`);const{initDotnet:s}=await import(a);return s(i)}throw new Error("GdPicture WASM loader not implemented")}(t,e);y=f.GdPictureWasm.API,p=c,_("gdpicture/setLicense",{origin:n},{licenseKey:o||"DEMO_PSPDFKIT_WEB"});const l=r?"/fonts":"";if(r&&!p.FS.analyzePath(l).exists&&(this._mountCustomFonts(r,l),_("gdpicture/setFonts",{fontPaths:[l]})),i){const t=await a(i);_("gdpicture/setDynamicFontLoading",{baseUrl:i.split("/").slice(0,-1).join("/"),allowedFonts:t.availableFonts,v:1})}s&&_("gdpicture/setFontSubstitutions",{fontSubstitutions:s})}toPdf(t,e){p.FS.writeFile(s,new Uint8Array(t));const n={file:f,format:"pdf"};e&&e in i&&(n.conformance=e);try{return _("gdpicture/process",{input:{file:s},output:n}),p.FS.readFile(f).buffer}finally{try{p.FS.unlink(f)}catch(t){}}}toOffice(t,e){p.FS.writeFile(s,new Uint8Array(t));const n=`/save.${e}`;try{return _("gdpicture/process",{input:{file:s},output:{file:n,format:e}}),p.FS.readFile(n).buffer}finally{try{p.FS.unlink(n)}catch(t){console.log(t.message)}}}async populateDocumentTemplate(t,e){let n;p.FS.writeFile(c,new Uint8Array(t));try{n=JSON.stringify(e,null,2)}catch(t){throw new Error("Invalid config data")}p.FS.writeFile(d,n);try{return _("gdpicture/process-office-template",{inputFile:c,modelAndConfigFile:d,outputFile:l}),p.FS.readFile(l).buffer}finally{try{p.FS.unlink(l),p.FS.unlink(d)}catch(t){console.log(t.message)}}}},m=self;return m.global=m,m.module={},m.onmessage=async t=>{let e,n,{data:o}=t;try{const t=await b[o.action](...o.args);if(e={id:o.id,result:t},Array.isArray(t)){const e=t.filter((t=>t instanceof ArrayBuffer));e.length>0&&(n=e)}t instanceof ArrayBuffer&&(n=[t])}catch(t){const r=[...o.args].filter((t=>t instanceof ArrayBuffer));r.length>0&&(n=r),e={id:o.id,error:t.message||t.toString(),callArgs:o.args}}m.postMessage(e,n)},e})()));