UNPKG

@nutrient-sdk/node

Version:

Convert documents in your Node.js apps.

13 lines 2.09 kB
/*! * Nutrient for Node.js 1.1.0 (https://www.nutrient.io/nodejs) * * Copyright © 2024-2025 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. * * Nutrient uses several open source third-party components: https://www.nutrient.io/legal/acknowledgements/nodejs-acknowledgements/ */ let e,t;let r="string"==typeof globalThis.process?.versions?.node,o="object"==typeof window&&"Deno"in window||"object"==typeof self&&"Deno"in self;export async function initialize(){if(r){let{createRequire:t}=await import("module");e=t(import.meta.url)}else if(o){let e=new URL("./resources/list.json",import.meta.url),r=await globalThis.fetch(e).then(e=>e.json());t=(await Promise.all(r.map(e=>globalThis.fetch(new URL(`./resources/${e}`,import.meta.url)).then(async e=>{if(e.ok)return e.arrayBuffer()}).then(t=>({buffer:t,filename:e})).catch(()=>({buffer:void 0,filename:e}))))).reduce((e,{filename:t,buffer:r})=>(e[`${globalThis.gdPicture.baseUrl}/resources/${decodeURI(t)}`]=r,e),{})}}export function fetchResource(e,t){fetch(`${globalThis.gdPicture.baseUrl}/resources/${e}`,t)}export function fetch(i,l){try{if(r){let t=e("node:fs"),r=e("node:path"),o=t.readFileSync(r.normalize(i));globalThis.gdPicture.module.FS.writeFile(l,new Uint8Array(o))}else if(o)globalThis.gdPicture.module.FS.writeFile(l,new Uint8Array(t[i]));else{let e=new XMLHttpRequest;e.open("GET",i,!1),e.overrideMimeType("text/plain; charset=x-user-defined"),e.send(),200===e.status?globalThis.gdPicture.module.FS.writeFile(l,function(e){let t=new Uint8Array(new ArrayBuffer(e.length));for(let r=0,o=e.length;r<o;r++)t[r]=e.charCodeAt(r);return t}(e.response)):console.error(`Could not retrieve resource. Status: ${e.status}`)}}catch(e){console.error(`Could not retrieve resource. Exception: ${e.message}`)}}