13 lines
12 KiB
JavaScript

/*!
* PSPDFKit for Web 2023.5.2 (https://pspdfkit.com/web)
*
* Copyright (c) 2016-2023 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/
*/
(self.webpackChunkPSPDFKit=self.webpackChunkPSPDFKit||[]).push([[9859],{49859:(t,e,r)=>{"use strict";r.r(e),r.d(e,{Conformance:()=>i,GdPicture:()=>g,GdPictureClientNative:()=>h,GdPictureWorker:()=>w,getBrowserSpawner:()=>F});var n=r(84121),o=r(47347),s=r(72852);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}({});function a(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function l(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?a(Object(r),!0).forEach((function(e){(0,n.Z)(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}const c="/create.pdf",u="/save.pdf",d="/create.docx",f="/save.docx",p="/templateData.json",m="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope;let b=null,y=null;function _(t){let e;(0,o.kG)(y,"GdPicture WebAssembly is not loaded.");for(var r=arguments.length,n=new Array(r>1?r-1:0),s=1;s<r;s++)n[s-1]=arguments[s];for(const t of n)e=Object.assign(n[0],t);const i=JSON.stringify(l({type:t},e)),a=JSON.parse(y.CommandHandler(i));if(!a.success)throw new Error(a.errorReason+": "+a.errorMessage+"\n"+a.error);return a}class g{_mountCustomFonts(t,e){(0,o.kG)(b,"WebAssembly module not loaded."),b.FS.mkdir(e);{const r=m?b.FS.filesystems.WORKERFS:b.FS.filesystems.MEMFS;b.FS.mount(r,{blobs:t},e)}}async loadModule(t,e,r,n,o,i,a){const{Assemblies:l,Module:c}=await async function(t,e){if("string"==typeof t){const r="pspdfkit-lib/",n=`${r}gdpicture-e184469a/jit`,o=`${r}gdpicture-e184469a/aot`;let s,i;e?(s=`${t}${o}/initDotnet.js`,i=`${t}${o}`):(s=`${t}${n}/initDotnet.js`,i=`${t}${n}`);const{initDotnet:a}=await import(s);return a(i)}throw new Error("GdPicture WASM loader not implemented")}(t,e);y=l.GdPictureWasm.API,b=c,_("gdpicture/setLicense",{origin:r},{licenseKey:n||"DEMO_PSPDFKIT_WEB"});const u=o?"/fonts":"";if(o&&!b.FS.analyzePath(u).exists&&(this._mountCustomFonts(o,u),_("gdpicture/setFonts",{fontPaths:[u]})),i){const t=await(0,s.S)(i);_("gdpicture/setDynamicFontLoading",{baseUrl:i.split("/").slice(0,-1).join("/"),allowedFonts:t.availableFonts,v:1})}a&&_("gdpicture/setFontSubstitutions",{fontSubstitutions:a})}toPdf(t,e){b.FS.writeFile(c,new Uint8Array(t));const r={file:u,format:"pdf"};e&&e in i&&(r.conformance=e);try{return _("gdpicture/process",{input:{file:c},output:r}),b.FS.readFile(u).buffer}finally{try{b.FS.unlink(u)}catch(t){}}}async populateDocumentTemplate(t,e){let r;b.FS.writeFile(d,new Uint8Array(t));try{r=JSON.stringify(e,null,2)}catch(t){throw new Error("Invalid config data")}b.FS.writeFile(p,r);try{return _("gdpicture/process-office-template",{inputFile:d,modelAndConfigFile:p,outputFile:f}),b.FS.readFile(f).buffer}finally{try{b.FS.unlink(f),b.FS.unlink(p)}catch(t){}}}}const w=class{constructor(t){let{baseUrl:e,aot:r,mainThreadOrigin:s,licenseKey:i,customFonts:a,dynamicFonts:l,fontSubstitutions:c,workerSpawner:u,wasmLoaderPath:d}=t;(0,n.Z)(this,"requests",new Map),(0,n.Z)(this,"nextRequestId",1),(0,n.Z)(this,"handleMessage",(t=>{const e=t.data,r=this.requests.get(e.id);(0,o.kG)(r,`No request was made for id ${e.id}.`);const{resolve:n,reject:s}=r;if(this.requests.delete(e.id),e.error){const t=new o.p2(e.error);t.callArgs=e.callArgs,s(t)}else n(e.result)})),this.workerSpawner=u,this.workerSpawner.setMessageHandler(this.handleMessage),this.moduleLoadPromise=this.sendRequest("loadModule",[d?{baseUrl:e,wasmLoaderPath:d}:e,r,s,i,a,l,c])}toPdf(t,e){let r;return e&&(r=e.replace("pdf","pdf_").replaceAll("-","_")),this.sendRequest("toPdf",[t,r])}async populateDocumentTemplate(t,e){return this.sendRequest("populateDocumentTemplate",[t,e])}destroy(){var t;null===(t=this.workerSpawner)||void 0===t||t.terminate(),this.workerSpawner=null}async sendRequest(t,e){(0,o.kG)(this.workerSpawner,"GdPictureClient has been destroyed"),this.moduleLoadPromise&&await this.moduleLoadPromise;const r=this.workerSpawner;return new Promise(((n,o)=>{const s=this.assignId(),i=[...e].filter((t=>t instanceof ArrayBuffer));r.postMessage({id:s,action:t,args:e},i),this.requests=this.requests.set(s,{resolve:n,reject:o})}))}assignId(){const t=this.nextRequestId;return this.nextRequestId=this.nextRequestId+1,t}};const h=class{constructor(t){let{baseUrl:e,aot:r,mainThreadOrigin:n,licenseKey:o,customFonts:s,dynamicFonts:i,fontSubstitutions:a}=t;this.gdPicture=new g,this.moduleLoadPromise=this.gdPicture.loadModule(e,r,n,o,s,i,a)}async toPdf(t,e){let r;return this.moduleLoadPromise&&await this.moduleLoadPromise,e&&(r=e.replace("pdf","pdf_").replaceAll("-","_")),this.gdPicture.toPdf(t,r)}async populateDocumentTemplate(t,e){return this.moduleLoadPromise&&await this.moduleLoadPromise,this.gdPicture.populateDocumentTemplate(t,e)}destroy(){}};var S=r(59817),P=r.n(S);const F=async function(){let t=new(P());return{setMessageHandler(e){(0,o.kG)(t,"Worker is null"),t.onmessage=e},postMessage(e,r){var n;null===(n=t)||void 0===n||n.postMessage(e,r)},terminate(){var e;null===(e=t)||void 0===e||e.terminate(),t=null}}}},59817:(t,e,r)=>{t.exports=function(){return r(69855)('/*!\n * PSPDFKit for Web 2023.5.2 (https://pspdfkit.com/web)\n *\n * Copyright (c) 2016-2023 PSPDFKit GmbH. All rights reserved.\n *\n * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW\n * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.\n * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.\n * This notice may not be removed from this file.\n *\n * PSPDFKit uses several open source third-party components: https://pspdfkit.com/acknowledgements/web/\n */(()=>{"use strict";const t=function t(e){let r;return r=e instanceof Error?e:new Error(e),Object.setPrototypeOf(r,t.prototype),r};t.prototype=Object.create(Error.prototype,{name:{value:"PSPDFKitError",enumerable:!1}});const e=t;function r(t,r){if(!t)throw new e(`Assertion failed: ${r||"Condition not met"}\\n\\nFor further assistance, please go to: https://pspdfkit.com/support/request`)}function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t){var e=function(t,e){if("object"!==n(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===n(e)?e:String(e)}function i(t,e,r){return(e=o(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}["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;let a=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}({});function s(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function c(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?s(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}const f="/create.pdf",l="/save.pdf",u="/create.docx",p="/save.docx",d="/templateData.json",y="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope;let b=null,m=null;function _(t){let e;r(m,"GdPicture WebAssembly is not loaded.");for(var n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];for(const t of o)e=Object.assign(o[0],t);const a=JSON.stringify(c({type:t},e)),s=JSON.parse(m.CommandHandler(a));if(!s.success)throw new Error(s.errorReason+": "+s.errorMessage+"\\n"+s.error);return s}const g=new class{_mountCustomFonts(t,e){r(b,"WebAssembly module not loaded."),b.FS.mkdir(e);{const r=y?b.FS.filesystems.WORKERFS:b.FS.filesystems.MEMFS;b.FS.mount(r,{blobs:t},e)}}async loadModule(t,r,n,o,i,a,s){const{Assemblies:c,Module:f}=await async function(t,e){if("string"==typeof t){const r="pspdfkit-lib/",n=`${r}gdpicture-e184469a/jit`,o=`${r}gdpicture-e184469a/aot`;let i,a;e?(i=`${t}${o}/initDotnet.js`,a=`${t}${o}`):(i=`${t}${n}/initDotnet.js`,a=`${t}${n}`);const{initDotnet:s}=await import(i);return s(a)}throw new Error("GdPicture WASM loader not implemented")}(t,r);m=c.GdPictureWasm.API,b=f,_("gdpicture/setLicense",{origin:n},{licenseKey:o||"DEMO_PSPDFKIT_WEB"});const l=i?"/fonts":"";if(i&&!b.FS.analyzePath(l).exists&&(this._mountCustomFonts(i,l),_("gdpicture/setFonts",{fontPaths:[l]})),a){const t=await async function(t){try{const r=await fetch(t).catch((r=>{throw new e(`Error fetching dynamic fonts file ${t}. ${r}`)}));if(200!==r.status)throw new e(`Error fetching dynamic fonts file ${t}. Status code: ${r.status}`);const n=await r.json().catch((r=>{throw new e(`Error parsing dynamic fonts file ${t}. ${r}`)}));return n}catch(t){throw t}}(a);_("gdpicture/setDynamicFontLoading",{baseUrl:a.split("/").slice(0,-1).join("/"),allowedFonts:t.availableFonts,v:1})}s&&_("gdpicture/setFontSubstitutions",{fontSubstitutions:s})}toPdf(t,e){b.FS.writeFile(f,new Uint8Array(t));const r={file:l,format:"pdf"};e&&e in a&&(r.conformance=e);try{return _("gdpicture/process",{input:{file:f},output:r}),b.FS.readFile(l).buffer}finally{try{b.FS.unlink(l)}catch(t){}}}async populateDocumentTemplate(t,e){let r;b.FS.writeFile(u,new Uint8Array(t));try{r=JSON.stringify(e,null,2)}catch(t){throw new Error("Invalid config data")}b.FS.writeFile(d,r);try{return _("gdpicture/process-office-template",{inputFile:u,modelAndConfigFile:d,outputFile:p}),b.FS.readFile(p).buffer}finally{try{b.FS.unlink(p),b.FS.unlink(d)}catch(t){}}}},w=self;w.global=w,w.module={},w.onmessage=async t=>{let e,r,{data:n}=t;try{const t=await g[n.action](...n.args);if(e={id:n.id,result:t},Array.isArray(t)){const e=t.filter((t=>t instanceof ArrayBuffer));e.length>0&&(r=e)}t instanceof ArrayBuffer&&(r=[t])}catch(t){const o=[...n.args].filter((t=>t instanceof ArrayBuffer));o.length>0&&(r=o),e={id:n.id,error:t.message||t.toString(),callArgs:n.args}}w.postMessage(e,r)}})();',null)}}}]);