@nutrient-sdk/viewer
Version:
View and annotate PDF files in your web app. Full support for mobile and desktop. Runs in the browser using WASM.
13 lines • 25.9 kB
JavaScript
/*!
* Nutrient Web SDK 1.15.1 (https://www.nutrient.io/sdk/web)
*
* Copyright (c) 2016-2026 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://www.nutrient.io/legal/acknowledgements/web-acknowledgements/
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.NutrientViewer=e():t.NutrientViewer=e()}(globalThis,()=>(()=>{"use strict";var t,e,r,n={},i={};function o(t){var e=i[t];if(void 0!==e)return e.exports;var r=i[t]={exports:{}};return n[t](r,r.exports,o),r.exports}o.m=n,o.d=(t,e)=>{for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.f={},o.e=t=>Promise.all(Object.keys(o.f).reduce((e,r)=>(o.f[r](t,e),e),[])),o.u=t=>"nutrient-viewer-lib/chunk-"+t+"-"+{340:"50b6be80417dd76e",567:"a70463edeb45ddad"}[t]+".js",o.miniCssF=t=>{},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),t={},e="NutrientViewer:",o.l=(r,n,i,a)=>{if(t[r])t[r].push(n);else{var s,u;if(void 0!==i)for(var f=document.getElementsByTagName("script"),c=0;c<f.length;c++){var l=f[c];if(l.getAttribute("src")==r||l.getAttribute("data-webpack")==e+i){s=l;break}}s||(u=!0,(s=document.createElement("script")).charset="utf-8",o.nc&&s.setAttribute("nonce",o.nc),s.setAttribute("data-webpack",e+i),s.src=o.tu(r)),t[r]=[n];var d=(e,n)=>{s.onerror=s.onload=null,clearTimeout(p);var i=t[r];if(delete t[r],s.parentNode&&s.parentNode.removeChild(s),i&&i.forEach(t=>t(n)),e)return e(n)},p=setTimeout(d.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=d.bind(null,s.onerror),s.onload=d.bind(null,s.onload),u&&document.head.appendChild(s)}},o.tt=()=>(void 0===r&&(r={createScriptURL:t=>t},"undefined"!=typeof trustedTypes&&trustedTypes.createPolicy&&(r=trustedTypes.createPolicy("nutrient-web-sdk#webpack",r))),r),o.tu=t=>o.tt().createScriptURL(t),o.p="",(()=>{var t={374:0};o.f.j=(e,r)=>{var n=o.o(t,e)?t[e]:void 0;if(0!==n)if(n)r.push(n[2]);else{var i=new Promise((r,i)=>n=t[e]=[r,i]);r.push(n[2]=i);var a=o.p+o.u(e),s=new Error;o.l(a,r=>{if(o.o(t,e)&&(0!==(n=t[e])&&(t[e]=void 0),n)){var i=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;s.message="Loading chunk "+e+" failed.\n("+i+": "+a+")",s.name="ChunkLoadError",s.type=i,s.request=a,n[1](s)}},"chunk-"+e,e)}};var e=(e,r)=>{var n,i,[a,s,u]=r,f=0;if(a.some(e=>0!==t[e])){for(n in s)o.o(s,n)&&(o.m[n]=s[n]);if(u)u(o)}for(e&&e(r);f<a.length;f++)i=a[f],o.o(t,i)&&t[i]&&t[i][0](),t[i]=0},r=globalThis.webpackChunkNutrientViewer=globalThis.webpackChunkNutrientViewer||[];r.forEach(e.bind(null,0)),r.push=e.bind(null,r.push.bind(r))})();const a=function t(e){let r;return r=e instanceof Error?e:new Error(e),Object.setPrototypeOf(r,t.prototype),r};a.prototype=Object.create(Error.prototype,{name:{value:"PSPDFKitError",enumerable:!1}});const s=a;function u(t,e){if(!t)throw new s(`Assertion failed: ${e||"Condition not met"}\n\nFor further assistance, please go to: https://www.nutrient.io/support/request`)}function f(t){return"[object Object]"===Object.prototype.toString.call(t)}function c(){console.warn(...arguments)}["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'].join(",");function l(t){return l="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},l(t)}function d(t){var e=function(t,e){if("object"!=l(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=l(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==l(e)?e:e+""}function p(t,e,r){return(e=d(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}new WeakMap;Symbol.for("nutrient.web.trustedTypesPolicy");async function m(t){const e=(await async function(t){try{const e=await fetch(t).catch(e=>{throw new s(`Error fetching dynamic fonts file ${t}. ${e}`)});if(200!==e.status)throw new s(`Error fetching dynamic fonts file ${t}. Status code: ${e.status}`);return e}catch(t){throw t}}(t)).json().catch(e=>{throw new s(`Error parsing dynamic fonts file ${t}. ${e}`)});return e}let h=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 g=/^data:([^;,]+)?;base64,(.*)$/i,w=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}(?:==)?|[A-Za-z0-9+/]{3}=?)?$/,b=new Set(["original","fixed","fit-width","fit-height","fit-max"]),y=new Set(["png","jpg","gif","bmp","tif"]),v={"image/png":"png","image/jpeg":"jpg","image/jpg":"jpg","image/gif":"gif","image/bmp":"bmp","image/tiff":"tif","image/x-tiff":"tif"};async function S(t){const e={urlImageReferences:[]},r=E(t.model,"$.model",e);if(e.urlImageReferences.length>0){const t=await async function(t){const e=Array.from(new Set(t.map(t=>t.normalizedUrl))),r=new Map;for(const e of t){if(!e.preferredFormat)continue;const t=r.get(e.normalizedUrl);if(t){if(t.format!==e.preferredFormat)throw new Error(`Conflicting image formats for URL "${e.normalizedUrl}" between ${t.path} and ${e.path}.`)}else r.set(e.normalizedUrl,{format:e.preferredFormat,path:e.path})}const n=await Promise.all(e.map(t=>async function(t,e){let r;try{r=await fetch(t)}catch(e){throw new Error(`Failed to fetch ${t}. This can happen when the URL is cross-origin without CORS headers. Configure CORS or pass base64/data URL instead.`)}if(!r.ok)throw new Error(`Failed to fetch ${t}: ${r.status} ${r.statusText}.`);const n=new Uint8Array(await r.arrayBuffer()),i=r.headers.get("content-type");if(i?.toLowerCase().includes("image/svg+xml"))throw new Error("svg format is not supported in this release.");const o=function(t){if(!t)return;const e=t.toLowerCase().split(";")[0].trim();return v[e]}(i),a=function(t){try{const e=new URL(t).pathname,r=e.split(".").pop()?.toLowerCase();if(!r)return;return A(r)??void 0}catch(t){return}}(t),s=e??o??a;if(!s)throw new Error(`Failed to infer image format for ${t}. Provide "format" in the image object.`);return{normalizedUrl:t,base64Data:$(n),format:s}}(t,r.get(t)?.format)));return new Map(n.map(t=>[t.normalizedUrl,t]))}(e.urlImageReferences);!function(t,e){for(const r of t){const t=e.get(r.normalizedUrl);r.image.source="base64",r.image.data=t.base64Data,null==r.image.format&&t.format&&(r.image.format=t.format),delete r.image.url,delete r.image.path}}(e.urlImageReferences,t)}const n=function(t){if(null==t)return{delimiter:{start:"{",end:"}"}};if(!f(t))throw new Error("$.config must be a valid object.");const e={...t},r=e.delimiter;return e.delimiter=function(t){if(null==t)return{start:"{",end:"}"};if(!f(t))throw new Error("$.config.delimiter must be a valid object.");const e={...t},{start:r,end:n,objectDelimiter:i}=e;if(null!=r&&"string"!=typeof r)throw new Error("$.config.delimiter.start must be a string.");if(null!=n&&"string"!=typeof n)throw new Error("$.config.delimiter.end must be a string.");if(null!=i&&"string"!=typeof i)throw new Error("$.config.delimiter.objectDelimiter must be a string.");return e.start="string"==typeof r?r:"{",e.end="string"==typeof n?n:"}",e}(r),e}(t.config);return{serializedData:JSON.stringify({config:n,model:r},null,2)}}function E(t,e,r){if(Array.isArray(t))return t.map((t,n)=>E(t,`${e}[${n}]`,r));if(!f(t))return t;if(function(t){return f(t)&&"image"===t._type}(t))return function(t,e,r){const n={...t},i=function(t,e){if("string"!=typeof t)throw new Error(`${e}.source must be a string.`);if("dataUrl"===t)return"base64";if("base64"===t||"url"===t)return t;if("file"===t)throw new Error(`${e}.source "file" is not supported in public APIs. Use "base64" (or "dataUrl") or "url".`);throw new Error(`${e}.source must be one of "base64", "dataUrl", or "url". Received "${t}".`)}(n.source,e);n.source=i,function(t,e){if(void 0===t.sizing)return;if(!b.has(t.sizing))throw new Error(`${e}.sizing must be one of "original", "fixed", "fit-width", "fit-height", "fit-max".`);switch(t.sizing){case"fixed":case"fit-max":U(t.width,`${e}.width`),U(t.height,`${e}.height`);break;case"fit-width":U(t.width,`${e}.width`);break;case"fit-height":U(t.height,`${e}.height`)}}(n,e),function(t,e){if(void 0===t.pageNumber)return;if(!Number.isInteger(t.pageNumber)||t.pageNumber<=0)throw new Error(`${e}.pageNumber must be a positive integer.`)}(n,e);const o=function(t,e){if(void 0===t)return;if("string"!=typeof t)throw new Error(`${e}.format must be a string.`);if("svg"===t.toLowerCase().trim())throw new Error(`${e}.format svg is not supported in this release.`);const r=A(t);if(!r)throw new Error(`${e}.format must be one of "png", "jpg"/"jpeg", "gif", "bmp", "tif"/"tiff".`);return r}(n.format,e);o&&(n.format=o);switch(i){case"base64":{const t=n.data;if("string"!=typeof t||""===t.trim())throw new Error(`${e}.data must be a non-empty string.`);const r=function(t,e){const r=g.exec(t.trim());if(r){const t=(r[1]||"").toLowerCase(),n=r[2];if(!n)throw new Error(`${e} must contain non-empty base64 data.`);if("image/svg+xml"===t)throw new Error(`${e} does not support svg images in this release.`);return _(n,e),{isDataUrl:!0}}return _(t.trim(),e),{isDataUrl:!1}}(t,`${e}.data`);if(!r.isDataUrl&&!n.format)throw new Error(`${e}.format must be supplied when source is raw base64 data.`);break}case"url":{const t="string"==typeof n.url&&""!==n.url.trim()?n.url.trim():"string"==typeof n.path&&""!==n.path.trim()?n.path.trim():null;if(!t)throw new Error(`${e}.url must be supplied when source is "url".`);const i=function(t,e){let r;try{r=new URL(t.trim())}catch(t){throw new Error(`${e} must be a valid absolute URL.`)}if(!["http:","https:"].includes(r.protocol))throw new Error(`${e} must use http or https.`);return r.toString()}(t,`${e}.url`);n.url=i,r.urlImageReferences.push({path:e,image:n,normalizedUrl:i,preferredFormat:n.format});break}}return n}(t,e,r);const n={};for(const[i,o]of Object.entries(t))n[i]=E(o,`${e}${F(i)}`,r);return n}function $(t){if("undefined"!=typeof Buffer)return Buffer.from(t).toString("base64");let e="";for(let r=0;r<t.length;r+=32768){const n=t.subarray(r,r+32768);e+=String.fromCharCode(...n)}return btoa(e)}function _(t,e){const r=t.replace(/\s+/g,"");if(""===r||!w.test(r))throw new Error(`${e} must be valid base64 data.`)}function U(t,e){if("number"!=typeof t||!Number.isFinite(t)||t<=0)throw new Error(`${e} must be a positive number.`)}function A(t){const e=t.toLowerCase().trim();return"jpeg"===e?"jpg":"tiff"===e?"tif":y.has(e)?e:null}function F(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)?`.${t}`:`[${JSON.stringify(t)}]`}const j=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;const k=function(t){return"string"==typeof t&&j.test(t)};const x=function(t){if(!k(t))throw TypeError("Invalid UUID");let e;return Uint8Array.of((e=parseInt(t.slice(0,8),16))>>>24,e>>>16&255,e>>>8&255,255&e,(e=parseInt(t.slice(9,13),16))>>>8,255&e,(e=parseInt(t.slice(14,18),16))>>>8,255&e,(e=parseInt(t.slice(19,23),16))>>>8,255&e,(e=parseInt(t.slice(24,36),16))/1099511627776&255,e/4294967296&255,e>>>24&255,e>>>16&255,e>>>8&255,255&e)};const I=[];for(let t=0;t<256;++t)I.push((t+256).toString(16).slice(1));function C(t,e=0){return(I[t[e+0]]+I[t[e+1]]+I[t[e+2]]+I[t[e+3]]+"-"+I[t[e+4]]+I[t[e+5]]+"-"+I[t[e+6]]+I[t[e+7]]+"-"+I[t[e+8]]+I[t[e+9]]+"-"+I[t[e+10]]+I[t[e+11]]+I[t[e+12]]+I[t[e+13]]+I[t[e+14]]+I[t[e+15]]).toLowerCase()}let M;const T=new Uint8Array(16);function P(t){return 14+(t+64>>>9<<4)+1}function D(t,e){const r=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(r>>16)<<16|65535&r}function L(t,e,r,n,i,o){return D((a=D(D(e,t),D(n,o)))<<(s=i)|a>>>32-s,r);var a,s}function O(t,e,r,n,i,o,a){return L(e&r|~e&n,t,e,i,o,a)}function R(t,e,r,n,i,o,a){return L(e&n|r&~n,t,e,i,o,a)}function z(t,e,r,n,i,o,a){return L(e^r^n,t,e,i,o,a)}function N(t,e,r,n,i,o,a){return L(r^(e|~n),t,e,i,o,a)}const B=function(t){return function(t){const e=new Uint8Array(4*t.length);for(let r=0;r<4*t.length;r++)e[r]=t[r>>2]>>>r%4*8&255;return e}(function(t,e){const r=new Uint32Array(P(e)).fill(0);r.set(t),r[e>>5]|=128<<e%32,r[r.length-1]=e,t=r;let n=1732584193,i=-271733879,o=-1732584194,a=271733878;for(let e=0;e<t.length;e+=16){const r=n,s=i,u=o,f=a;n=O(n,i,o,a,t[e],7,-680876936),a=O(a,n,i,o,t[e+1],12,-389564586),o=O(o,a,n,i,t[e+2],17,606105819),i=O(i,o,a,n,t[e+3],22,-1044525330),n=O(n,i,o,a,t[e+4],7,-176418897),a=O(a,n,i,o,t[e+5],12,1200080426),o=O(o,a,n,i,t[e+6],17,-1473231341),i=O(i,o,a,n,t[e+7],22,-45705983),n=O(n,i,o,a,t[e+8],7,1770035416),a=O(a,n,i,o,t[e+9],12,-1958414417),o=O(o,a,n,i,t[e+10],17,-42063),i=O(i,o,a,n,t[e+11],22,-1990404162),n=O(n,i,o,a,t[e+12],7,1804603682),a=O(a,n,i,o,t[e+13],12,-40341101),o=O(o,a,n,i,t[e+14],17,-1502002290),i=O(i,o,a,n,t[e+15],22,1236535329),n=R(n,i,o,a,t[e+1],5,-165796510),a=R(a,n,i,o,t[e+6],9,-1069501632),o=R(o,a,n,i,t[e+11],14,643717713),i=R(i,o,a,n,t[e],20,-373897302),n=R(n,i,o,a,t[e+5],5,-701558691),a=R(a,n,i,o,t[e+10],9,38016083),o=R(o,a,n,i,t[e+15],14,-660478335),i=R(i,o,a,n,t[e+4],20,-405537848),n=R(n,i,o,a,t[e+9],5,568446438),a=R(a,n,i,o,t[e+14],9,-1019803690),o=R(o,a,n,i,t[e+3],14,-187363961),i=R(i,o,a,n,t[e+8],20,1163531501),n=R(n,i,o,a,t[e+13],5,-1444681467),a=R(a,n,i,o,t[e+2],9,-51403784),o=R(o,a,n,i,t[e+7],14,1735328473),i=R(i,o,a,n,t[e+12],20,-1926607734),n=z(n,i,o,a,t[e+5],4,-378558),a=z(a,n,i,o,t[e+8],11,-2022574463),o=z(o,a,n,i,t[e+11],16,1839030562),i=z(i,o,a,n,t[e+14],23,-35309556),n=z(n,i,o,a,t[e+1],4,-1530992060),a=z(a,n,i,o,t[e+4],11,1272893353),o=z(o,a,n,i,t[e+7],16,-155497632),i=z(i,o,a,n,t[e+10],23,-1094730640),n=z(n,i,o,a,t[e+13],4,681279174),a=z(a,n,i,o,t[e],11,-358537222),o=z(o,a,n,i,t[e+3],16,-722521979),i=z(i,o,a,n,t[e+6],23,76029189),n=z(n,i,o,a,t[e+9],4,-640364487),a=z(a,n,i,o,t[e+12],11,-421815835),o=z(o,a,n,i,t[e+15],16,530742520),i=z(i,o,a,n,t[e+2],23,-995338651),n=N(n,i,o,a,t[e],6,-198630844),a=N(a,n,i,o,t[e+7],10,1126891415),o=N(o,a,n,i,t[e+14],15,-1416354905),i=N(i,o,a,n,t[e+5],21,-57434055),n=N(n,i,o,a,t[e+12],6,1700485571),a=N(a,n,i,o,t[e+3],10,-1894986606),o=N(o,a,n,i,t[e+10],15,-1051523),i=N(i,o,a,n,t[e+1],21,-2054922799),n=N(n,i,o,a,t[e+8],6,1873313359),a=N(a,n,i,o,t[e+15],10,-30611744),o=N(o,a,n,i,t[e+6],15,-1560198380),i=N(i,o,a,n,t[e+13],21,1309151649),n=N(n,i,o,a,t[e+4],6,-145523070),a=N(a,n,i,o,t[e+11],10,-1120210379),o=N(o,a,n,i,t[e+2],15,718787259),i=N(i,o,a,n,t[e+9],21,-343485551),n=D(n,r),i=D(i,s),o=D(o,u),a=D(a,f)}return Uint32Array.of(n,i,o,a)}(function(t){if(0===t.length)return new Uint32Array;const e=new Uint32Array(P(8*t.length)).fill(0);for(let r=0;r<t.length;r++)e[r>>2]|=(255&t[r])<<r%4*8;return e}(t),8*t.length))};const q="6ba7b810-9dad-11d1-80b4-00c04fd430c8",H="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function V(t,e,r,n,i,o){const a="string"==typeof r?function(t){t=unescape(encodeURIComponent(t));const e=new Uint8Array(t.length);for(let r=0;r<t.length;++r)e[r]=t.charCodeAt(r);return e}(r):r,s="string"==typeof n?x(n):n;if("string"==typeof n&&(n=x(n)),16!==n?.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let u=new Uint8Array(16+a.length);if(u.set(s),u.set(a,s.length),u=e(u),u[6]=15&u[6]|t,u[8]=63&u[8]|128,i){o=o||0;for(let t=0;t<16;++t)i[o+t]=u[t];return i}return C(u)}function W(t,e,r,n){return V(48,B,t,e,r,n)}W.DNS=q,W.URL=H;const K={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};const G=function(t,e,r){if(K.randomUUID&&!e&&!t)return K.randomUUID();const n=(t=t||{}).random??t.rng?.()??function(){if(!M){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");M=crypto.getRandomValues.bind(crypto)}return M(T)}();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){if((r=r||0)<0||r+16>e.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let t=0;t<16;++t)e[r+t]=n[t];return e}return C(n)};function Q(t,e,r,n){switch(t){case 0:return e&r^~e&n;case 1:case 3:return e^r^n;case 2:return e&r^e&n^r&n}}function Z(t,e){return t<<e|t>>>32-e}const J=function(t){const e=[1518500249,1859775393,2400959708,3395469782],r=[1732584193,4023233417,2562383102,271733878,3285377520],n=new Uint8Array(t.length+1);n.set(t),n[t.length]=128;const i=(t=n).length/4+2,o=Math.ceil(i/16),a=new Array(o);for(let e=0;e<o;++e){const r=new Uint32Array(16);for(let n=0;n<16;++n)r[n]=t[64*e+4*n]<<24|t[64*e+4*n+1]<<16|t[64*e+4*n+2]<<8|t[64*e+4*n+3];a[e]=r}a[o-1][14]=8*(t.length-1)/Math.pow(2,32),a[o-1][14]=Math.floor(a[o-1][14]),a[o-1][15]=8*(t.length-1)&4294967295;for(let t=0;t<o;++t){const n=new Uint32Array(80);for(let e=0;e<16;++e)n[e]=a[t][e];for(let t=16;t<80;++t)n[t]=Z(n[t-3]^n[t-8]^n[t-14]^n[t-16],1);let i=r[0],o=r[1],s=r[2],u=r[3],f=r[4];for(let t=0;t<80;++t){const r=Math.floor(t/20),a=Z(i,5)+Q(r,o,s,u)+f+e[r]+n[t]>>>0;f=u,u=s,s=Z(o,30)>>>0,o=i,i=a}r[0]=r[0]+i>>>0,r[1]=r[1]+o>>>0,r[2]=r[2]+s>>>0,r[3]=r[3]+u>>>0,r[4]=r[4]+f>>>0}return Uint8Array.of(r[0]>>24,r[0]>>16,r[0]>>8,r[0],r[1]>>24,r[1]>>16,r[1]>>8,r[1],r[2]>>24,r[2]>>16,r[2]>>8,r[2],r[3]>>24,r[3]>>16,r[3]>>8,r[3],r[4]>>24,r[4]>>16,r[4]>>8,r[4])};function Y(t,e,r,n){return V(80,J,t,e,r,n)}Y.DNS=q,Y.URL=H;function X(){const t="nutrient-analytics-user-id";if(!window||!window.localStorage)return null;try{if(window.localStorage.getItem(t))return window.localStorage.getItem(t);const e=G();return window.localStorage.setItem(t,e),e}catch{return null}}class tt{constructor(){p(this,"maxQueueSize",1e3),p(this,"flushTimer",null),p(this,"visibilityChangeHandler",null),p(this,"isFlushing",!1),p(this,"queue",[]),p(this,"allEvents",[])}static getInstance(){return tt.instance||(tt.instance=new tt),tt.instance}emit(t){this.collect(t)}configure(t){const{hmacSecret:e,endpoint:r,flushInterval:n,maxQueueSize:i,clientInfo:o}=t;this.clientInfo=o,this.hmacSecret=this.hexStringToHmacSecret(e),this.endpoint=r,void 0!==i&&(this.maxQueueSize=i),this.isE2E()||(this.flushTimer=setInterval(()=>this.flush(),n||3e3),this.visibilityChangeHandler=()=>{"hidden"===document.visibilityState&&this.queue.length>0&&this.flush()},document.addEventListener("visibilitychange",this.visibilityChangeHandler))}cleanup(){null!==this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),null!==this.visibilityChangeHandler&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null)}static cleanup(){tt.instance&&(tt.instance.cleanup(),tt.instance=void 0)}shouldBeIgnored(t){switch(t.name){case"content|editor|save":return!!this.allEvents.find(e=>e.name===t.name&&Math.abs(e.timestamp-t.timestamp)<1e3);case"form|creator|field|add":return!this.allEvents.find(t=>"form|creator|enter"===t.name);case"annotation|edit":return!!this.allEvents.find(e=>e.name===t.name&&Math.abs(e.timestamp-t.timestamp)<100);default:return!1}}collect(t){if(this.isE2E()){const e=window;if(e.__PSPDFKIT_ANALYTICS_EVENTS__??=[],this.shouldBeIgnored(t))return;return this.allEvents.push(t),void e.__PSPDFKIT_ANALYTICS_EVENTS__.push(t)}this.shouldBeIgnored(t)||(this.allEvents.push(t),this.queue.length>=this.maxQueueSize&&this.queue.shift(),this.queue.push(t))}async flush(){if(this.isFlushing||this.isE2E()||0===this.queue.length)return;this.isFlushing=!0;const t=this.queue.splice(0,this.queue.length);try{const e=await this.uploadBatch(t);this.requeue(e)}finally{this.isFlushing=!1}}async uploadBatch(t){try{const e=await this.prepareUpload(t);if(!e)return t;const r=`${this.endpoint}/proto/metrics`,n=await fetch(r,{method:"POST",headers:e.headers,body:e.body,keepalive:!0});return n.ok?[]:413===n.status?this.splitAndRetryBatch(t):t}catch(e){return t}}async splitAndRetryBatch(t){if(t.length<=1)return c("Dropping one analytics event: metrics endpoint rejected a single-event payload as too large (HTTP 413)."),[];const e=Math.floor(t.length/2),r=t.slice(0,e),n=t.slice(e);return[...await this.uploadBatch(r),...await this.uploadBatch(n)]}async prepareUpload(t){const{prepareUpload:e}=await Promise.all([o.e(340),o.e(567)]).then(o.bind(o,23948));return e({clientInfo:{...this.clientInfo,tag:X()??void 0},hmacSecret:this.hmacSecret},this.buildMetrics(t))}buildMetrics(t){return t.map(t=>({type:"counter",name:t.name,attributes:Object.fromEntries(Object.entries(t.attributes).map(t=>{let[e,r]=t;return[e,String(r)]})),timestamp:t.timestamp}))}requeue(t){const e=this.maxQueueSize-this.queue.length;if(e<=0)return;const r=t.slice(0,e);this.queue.unshift(...r)}isE2E(){return"undefined"!=typeof window&&Boolean(window.__E2E_TEST__)}hexStringToHmacSecret(t){if(128!==t.length)throw new Error(`Invalid hex string length: expected 128 characters, got ${t.length}`);return new Uint8Array(Array.from(t,t=>t.charCodeAt(0)))}}function et(t){var e,r;e="convert|from|office",r={feature:"office_conversion",mimeType:t},tt.getInstance().emit({name:e,attributes:r??{},timestamp:Date.now()})}p(tt,"instance",void 0);const rt="/create.pdf",nt="/save.pdf",it="/create.docx",ot="/save.docx",at="/templateData.json",st="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope;let ut=null,ft=null;function ct(t){let e;u(ft,"GdPicture WebAssembly is not loaded.");for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];for(const t of n)e=Object.assign(n[0],t);const o=JSON.stringify({type:t,...e}),a=JSON.parse(ft.CommandHandler(o));if(!a.success)throw new Error(a.errorReason+": "+a.errorMessage+"\n"+a.error);return a}const lt={allMarkup:0,simpleMarkup:1,noMarkup:2,original:3},dt=lt.noMarkup,pt={documentMarkupMode:dt};function mt(t){if(!t)return pt;if(!t.documentMarkupMode)return{...t,documentMarkupMode:dt};if(!(t.documentMarkupMode in lt))throw new Error(`Invalid documentMarkupMode value: ${t.documentMarkupMode}. Allowed values are: ${Object.keys(lt).join(", ")}`);return{...t,documentMarkupMode:lt[t.documentMarkupMode]}}const ht={"application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","text/plain":"txt"},gt=new class{_mountCustomFonts(t,e){u(ut,"WebAssembly module not loaded."),ut.FS.mkdir(e);{const r=st?ut.FS.filesystems.WORKERFS:ut.FS.filesystems.MEMFS;ut.FS.mount(r,{blobs:t},e)}}async loadModule(t,e,r,n,i,o,a){const{Assemblies:s,Module:u}=await async function(t,e){if("string"==typeof t){const r="nutrient-viewer-lib/",n=`${r}gdpicture-dd1aca24/jit`,i=`${r}gdpicture-dd1aca24/aot`;let o,a;e?(o=`${t}${i}/initDotnet.js`,a=`${t}${i}`):(o=`${t}${n}/initDotnet.js`,a=`${t}${n}`);const{initDotnet:s}=await import(o);return s(a,(t,e,r,n,i)=>"blazor.boot.json"===e?fetch(r,{credentials:"same-origin"}):null)}throw new Error("GdPicture WASM loader not implemented")}(t,e);ft=s.GdPictureWasm.API,ut=u,ct("gdpicture/setLicense",{origin:r},{licenseKey:n||"DEMO_PSPDFKIT_WEB"});const f=i?"/fonts":"";if(i&&!ut.FS.analyzePath(f).exists&&(this._mountCustomFonts(i,f),ct("gdpicture/setFonts",{fontPaths:[f]})),o){const t=await m(o);ct("gdpicture/setDynamicFontLoading",{baseUrl:o.split("/").slice(0,-1).join("/"),allowedFonts:t.availableFonts,v:1})}a&&ct("gdpicture/setFontSubstitutions",{fontSubstitutions:a})}toPdf(t,e,r,n,i){let o=rt;if(i&&"pdf"!==i&&Object.values(ht).includes(i)){et(Object.keys(ht).find(t=>ht[t].toLowerCase()===i.toLowerCase()).toLowerCase()),o+=`.${i}`}else if(n&&"application/pdf"!==n){const t=n.toLowerCase();et(t);const e=ht.hasOwnProperty(t)&&ht[t];e&&(o+=`.${e}`)}ut.FS.writeFile(o,new Uint8Array(t),{canOwn:!0});const a={file:nt,format:"pdf",conformance:e&&e in h?e:void 0,officeConversionSettings:mt(r)};try{return ct("gdpicture/process",{input:{file:o},output:a}),ut.FS.readFile(nt).buffer}finally{try{ut.FS.unlink(nt),ut.FS.unlink(o)}catch(t){}}}toOffice(t,e){ut.FS.writeFile(rt,new Uint8Array(t));const r=`/save.${e}`;try{return ct("gdpicture/process",{input:{file:rt},output:{file:r,format:e}}),ut.FS.readFile(r).buffer}finally{try{ut.FS.unlink(r),ut.FS.unlink(rt)}catch(t){console.log(t.message)}}}async populateDocumentTemplate(t,e){ut.FS.writeFile(it,new Uint8Array(t));const{serializedData:r}=await S(e);ut.FS.writeFile(at,r);try{return ct("gdpicture/process-office-template",{inputFile:it,modelAndConfigFile:at,outputFile:ot}),ut.FS.readFile(ot).buffer}finally{try{ut.FS.unlink(ot),ut.FS.unlink(at),ut.FS.unlink(it)}catch(t){console.log(t.message)}}}},wt=self;return wt.global=wt,wt.module={},wt.addEventListener("message",async t=>{let e,r,{data:n}=t;try{const t=await gt[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 i=[...n.args].filter(t=>t instanceof ArrayBuffer);i.length>0&&(r=i),e={id:n.id,error:t.message||t.toString(),callArgs:n.args}}wt.postMessage(e,r)}),{}})());