@imgly/plugin-print-ready-pdfs-web 1.1.2 → 1.68.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,38 +0,0 @@
1
- var j=Object.defineProperty;var b=(r,t)=>()=>(r&&(t=r(r=0)),t);var B=(r,t)=>{for(var e in t)j(r,e,{get:t[e],enumerable:!0})};function A(r){let t=r.endsWith("/")?r:r+"/";return t.startsWith("http://")||t.startsWith("https://")?t:(typeof document<"u"&&document.location?.origin||"")+t}var S=b(()=>{"use strict"});var v={};B(v,{BrowserAssetLoader:()=>g});var g,h=b(()=>{"use strict";S();g=class{baseUrl;constructor(t){this.baseUrl=A(t)}async loadGhostscriptModule(){let e=await import(new URL("gs.js",this.baseUrl).href);return e.default||e}getWasmPath(){return new URL("gs.wasm",this.baseUrl).href}async loadICCProfile(t){let e=new URL(t,this.baseUrl).href,o=await fetch(e);if(!o.ok)throw new Error(`Failed to load ICC profile ${t}: ${o.status} ${o.statusText}`);return o.blob()}}});var T={};B(T,{NodeAssetLoader:()=>E});var E,O=b(()=>{E=class{constructor(){throw new Error("NodeAssetLoader cannot be used in browser environments. Please provide the `assetPath` or `assetLoader` option to convertToPDFX3().")}async loadGhostscriptModule(){throw new Error("Not available in browser")}getWasmPath(){throw new Error("Not available in browser")}async loadICCProfile(){throw new Error("Not available in browser")}}});var c=class r{constructor(t){this.component=t}static globalLogLevel="warn";static logs=[];static maxLogs=1e3;static setLogLevel(t){r.globalLogLevel=t}static getLogs(){return[...r.logs]}static clearLogs(){r.logs=[]}debug(t,e){this.log("debug",t,e)}info(t,e){this.log("info",t,e)}warn(t,e){this.log("warn",t,e)}error(t,e){this.log("error",t,e)}log(t,e,o){let i={debug:0,info:1,warn:2,error:3};if(i[t]<i[r.globalLogLevel])return;let a={timestamp:Date.now(),level:t,component:this.component,message:e,data:o};r.logs.push(a),r.logs.length>r.maxLogs&&(r.logs=r.logs.slice(-r.maxLogs));let s=`[${new Date().toISOString()}] [${t.toUpperCase()}] [${this.component}]`,n=o?`${e} ${JSON.stringify(o)}`:e;switch(t){case"debug":console.debug(s,n);break;case"info":console.info(s,n);break;case"warn":console.warn(s,n);break;case"error":console.error(s,n);break;default:break}}};var d=class{supportsWebAssembly(){try{return typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function"}catch{return!1}}};async function F(r){let{silent:t=!0,assetLoader:e}=r,o=await e.loadGhostscriptModule(),i=e.getWasmPath(),a={locateFile:n=>n==="gs.wasm"?i:n};return t&&(a.print=()=>{},a.printErr=()=>{}),await o(a)}var f=class{static instance=null;static TIMEOUT_MS=3e4;static async load(t){return this.instance?this.instance:(this.instance=this.loadInternal(t),this.instance)}static async loadInternal(t){let e=new c("GhostscriptLoader");if(!new d().supportsWebAssembly())throw new Error("WebAssembly not supported in this browser");let i=t.timeout||this.TIMEOUT_MS;try{return e.info("Loading bundled Ghostscript (AGPL-3.0 licensed)"),e.info("Source available at: https://github.com/imgly/plugins"),await this.loadWithTimeout(()=>this.loadFromBundle(t.assetLoader),i)}catch(a){throw e.error("Ghostscript loading failed",{error:a.message}),new Error(`Failed to load Ghostscript: ${a.message}`)}}static async loadFromBundle(t){let e=new c("GhostscriptInit");try{e.info("Initializing Ghostscript module");let o=await F({assetLoader:t});return e.info("Ghostscript module initialized successfully",{version:o.version||"unknown",hasFS:!!o.FS,hasCallMain:!!o.callMain}),o}catch(o){throw e.error("Ghostscript initialization failed",{error:o}),new Error(`Ghostscript initialization failed: ${o.message}`)}}static async loadWithTimeout(t,e){return Promise.race([t(),new Promise((o,i)=>{setTimeout(()=>i(new Error(`Loading timeout after ${e}ms`)),e)})])}static reset(){this.instance=null}};var u=class{static async toUint8Array(t){if(t.arrayBuffer){let e=await t.arrayBuffer();return new Uint8Array(e)}return new Promise((e,o)=>{let i=new FileReader;i.onload=()=>{i.result instanceof ArrayBuffer?e(new Uint8Array(i.result)):o(new Error("Failed to read blob as ArrayBuffer"))},i.onerror=()=>o(i.error),i.readAsArrayBuffer(t)})}static async validatePDF(t){try{let e=await this.toUint8Array(t),o=new Uint8Array([37,80,68,70]);if(e.length<4)return!1;for(let i=0;i<4;i++)if(e[i]!==o[i])return!1;return!0}catch{return!1}}};var m=class{constructor(t,e="/tmp/pdfx"){this.module=t;this.fs=t.FS,this.logger=new c("VirtualFileSystem"),this.workingDir=e,this.initialize()}fs;logger;managedFiles=new Set;workingDir;initialize(){try{this.createDirIfNotExists(this.workingDir),this.createDirIfNotExists(`${this.workingDir}/input`),this.createDirIfNotExists(`${this.workingDir}/output`),this.createDirIfNotExists(`${this.workingDir}/profiles`),this.createDirIfNotExists(`${this.workingDir}/temp`),this.logger.info("Virtual filesystem initialized",{workingDir:this.workingDir})}catch(t){throw this.logger.error("Failed to initialize virtual filesystem",{error:t}),new Error(`VFS initialization failed: ${t}`)}}createDirIfNotExists(t){try{this.fs.mkdir(t)}catch(e){if(e.code!=="EEXIST")throw e}}async writeBlob(t,e,o=!0){try{let i=await u.toUint8Array(e);this.fs.writeFile(t,i),o&&this.managedFiles.add(t),this.logger.debug("File written",{path:t,size:i.length})}catch(i){throw this.logger.error("Failed to write blob",{path:t,error:i}),new Error(`Failed to write file ${t}: ${i}`)}}writeText(t,e,o=!0){try{this.fs.writeFile(t,e),o&&this.managedFiles.add(t),this.logger.debug("Text file written",{path:t,length:e.length})}catch(i){throw this.logger.error("Failed to write text",{path:t,error:i}),new Error(`Failed to write text file ${t}: ${i}`)}}readFile(t){try{let e=this.fs.readFile(t);return this.logger.debug("File read",{path:t,size:e.length}),e}catch(e){throw this.logger.error("Failed to read file",{path:t,error:e}),new Error(`Failed to read file ${t}: ${e}`)}}exists(t){try{return this.fs.stat(t),!0}catch{return!1}}cleanup(){let t=0;for(let e of this.managedFiles)try{this.fs.unlink(e),t++}catch(o){this.logger.warn("Failed to cleanup file",{path:e,error:o})}this.managedFiles.clear(),this.logger.info("Filesystem cleanup completed",{cleanedCount:t})}};function V(){try{let r=import.meta.url;if(!r||r.startsWith("file://"))return null;let t=r.lastIndexOf("/");return t===-1?null:r.substring(0,t+1)}catch{return null}}async function K(r){if(r.assetLoader)return r.assetLoader;if(r.assetPath){let{BrowserAssetLoader:o}=await Promise.resolve().then(()=>(h(),v));return new o(r.assetPath)}if(typeof window<"u"||typeof document<"u"){let o=V();if(o){let{BrowserAssetLoader:i}=await Promise.resolve().then(()=>(h(),v));return new i(o)}throw new Error(`In browser environments with Webpack 5 or Angular, you must provide the \`assetPath\` option.
2
-
3
- Example:
4
- convertToPDFX3(blob, {
5
- outputProfile: 'fogra39',
6
- assetPath: '/assets/print-ready-pdfs/'
7
- });
8
-
9
- See: https://github.com/imgly/plugins/tree/main/packages/plugin-print-ready-pdfs-web#bundler-setup-webpack-5--angular`)}let{NodeAssetLoader:e}=await Promise.resolve().then(()=>(O(),T));return new e}async function Y(r,t){if(Array.isArray(r)){if(r.length===0)return[];let e=[];for(let o=0;o<r.length;o++)try{let i=await k(r[o],t);e.push(i)}catch(i){throw new Error(`Failed to convert PDF ${o+1} of ${r.length}: ${i instanceof Error?i.message:String(i)}`)}return e}return k(r,t)}async function k(r,t){if(!(r instanceof Blob))throw new Error("Input must be a Blob");if(r.size===0)throw new Error("Input PDF is empty");if(r.size>100*1024*1024)throw new Error(`Input PDF too large (${r.size} bytes). Maximum: 100MB`);if(!t.outputProfile)throw new Error('outputProfile is required. Must be one of: "gracol", "fogra39", "srgb", "custom"');let e=["gracol","fogra39","srgb","custom"];if(!e.includes(t.outputProfile))throw new Error(`Invalid outputProfile "${t.outputProfile}". Must be one of: ${e.join(", ")}`);if(t.outputProfile==="custom"&&!t.customProfile)throw new Error('customProfile Blob is required when outputProfile is "custom"');if(t.customProfile&&!(t.customProfile instanceof Blob))throw new Error("customProfile must be a Blob");if(!await u.validatePDF(r))throw new Error("Invalid PDF format");let i=await K(t),a=await f.load({assetLoader:i}),s=new m(a);try{let n="/tmp/input.pdf",L="/tmp/output.pdf",C="/tmp/pdfx_def.ps",D="/tmp/custom.icc";if(await s.writeBlob(n,r),t.outputProfile==="custom"&&t.customProfile)await s.writeBlob(D,t.customProfile);else if(t.outputProfile!=="custom"){let l=M[t.outputProfile],N=`/tmp/${l.file}`,_=await i.loadICCProfile(l.file);await s.writeBlob(N,_)}let w,y,P;if(t.outputProfile==="custom")w=D,y=t.outputConditionIdentifier||"Custom Profile",P=t.outputCondition||"Custom ICC Profile";else{let l=M[t.outputProfile];w=`/tmp/${l.file}`,y=t.outputConditionIdentifier||l.identifier,P=t.outputCondition||l.info}let x=s.readFile(w),G=Array.from(x).map(l=>l.toString(16).padStart(2,"0")).join(""),$=x.slice(16,20),U=String.fromCharCode(...$).trim()==="CMYK",X=q(t,G,y,P);s.writeText(C,X);let p=["-dBATCH","-dNOPAUSE","-sDEVICE=pdfwrite","-dCompatibilityLevel=1.4","-dWriteObjStms=false","-dWriteXRefStm=false","-dPDFSETTINGS=/prepress","-dSetPageSize=false","-dAutoRotatePages=/None"];t.flattenTransparency!==!1&&p.push("-dHaveTransparency=false"),U?p.push("-sColorConversionStrategy=CMYK","-dProcessColorModel=/DeviceCMYK","-dConvertCMYKImagesToRGB=false"):p.push("-sColorConversionStrategy=RGB"),p.push(`-sOutputFile=${L}`,C,n);let I=await a.callMain(p);if(I!==0)throw new Error(`Ghostscript conversion failed with exit code ${I}`);let R=s.readFile(L),W=new Uint8Array(R),z=new Blob([W],{type:"application/pdf"});return s.cleanup(),z}catch(n){throw s.cleanup(),n}}var M={gracol:{file:"GRACoL2013_CRPC6.icc",identifier:"CGATS 21.2",info:"GRACoL 2013 CRPC6"},fogra39:{file:"ISOcoated_v2_eci.icc",identifier:"FOGRA39",info:"ISO Coated v2 (ECI)"},srgb:{file:"sRGB_IEC61966-2-1.icc",identifier:"sRGB IEC61966-2.1",info:"sRGB IEC61966-2.1"}};function q(r,t,e,o){return`%!
10
- % PDF/X-3 Definition File
11
- [ /Title (${r.title||"Untitled"}) /DOCINFO pdfmark
12
- [ /Trapped /False /DOCINFO pdfmark
13
-
14
- % Set PDF/X-3 conformance
15
- [ /GTS_PDFXVersion (PDF/X-3:2003) /GTS_PDFXConformance (PDF/X-3:2003) /DOCINFO pdfmark
16
-
17
- % Set TrimBox to match MediaBox for all pages (required for PDF/X)
18
- [/TrimBox [0 0 0 0] /PAGE pdfmark
19
-
20
- % Embed ICC profile as hex stream
21
- [/_objdef {icc_PDFX} /type /stream /OBJ pdfmark
22
- [{icc_PDFX} <</N 4>> /PUT pdfmark
23
- [{icc_PDFX} <${t}> /PUT pdfmark
24
-
25
- % Define OutputIntent with embedded ICC profile
26
- [/_objdef {OutputIntent_PDFX} /type /dict /OBJ pdfmark
27
- [{OutputIntent_PDFX} <<
28
- /Type /OutputIntent
29
- /S /GTS_PDFX
30
- /OutputCondition (${o})
31
- /OutputConditionIdentifier (${e})
32
- /RegistryName (http://www.color.org)
33
- /DestOutputProfile {icc_PDFX}
34
- >> /PUT pdfmark
35
-
36
- % Add OutputIntent to Catalog
37
- [{Catalog} <</OutputIntents [{OutputIntent_PDFX}]>> /PUT pdfmark`}h();export{g as BrowserAssetLoader,c as Logger,Y as convertToPDFX3};
38
- //# sourceMappingURL=index.browser.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/utils/asset-path.ts", "../src/loaders/browser-loader.ts", "../src/loaders/node-loader.browser.ts", "../src/utils/logger.ts", "../src/utils/browser-detection.ts", "../src/wasm/ghostscript-module.ts", "../src/core/ghostscript-loader.ts", "../src/utils/blob-utils.ts", "../src/core/virtual-filesystem.ts", "../src/pdfx.ts", "../src/index.browser.ts"],
4
- "sourcesContent": ["/**\n * Asset path utilities for resolving plugin assets in different environments.\n * Handles the Webpack 5 / Angular CLI issue where import.meta.url is transformed\n * to a file:// URL that doesn't work in browsers.\n */\n\n/**\n * Normalizes an asset path to ensure it has a trailing slash and is a valid URL.\n * Converts relative paths (e.g., '/assets/wasm/') to absolute URLs using the current origin.\n */\nexport function normalizeAssetPath(path: string): string {\n const normalizedPath = path.endsWith('/') ? path : path + '/';\n\n // If it's already an absolute URL, return as-is\n if (\n normalizedPath.startsWith('http://') ||\n normalizedPath.startsWith('https://')\n ) {\n return normalizedPath;\n }\n\n // Convert relative path to absolute URL using document.location.origin\n const origin =\n typeof document !== 'undefined' ? document.location?.origin || '' : '';\n\n return origin + normalizedPath;\n}\n\n/**\n * Resolves the base URL for loading plugin assets in browser environments.\n * Throws a helpful error if assetPath is required but not provided.\n *\n * @param assetPath - Explicit asset path provided by the user\n * @param currentModuleUrl - The import.meta.url of the calling module\n */\nexport function resolveAssetBasePath(\n assetPath: string | undefined,\n currentModuleUrl: string\n): string {\n // 1. Explicit assetPath always wins\n if (assetPath) {\n return normalizeAssetPath(assetPath);\n }\n\n // 2. Try import.meta.url (works in Vite, native ESM)\n if (!currentModuleUrl.startsWith('file://')) {\n // Valid browser URL - use it directly\n return new URL('./', currentModuleUrl).href;\n }\n\n // 3. Bundled environment (Webpack 5 transforms to file://)\n // assetPath is required - throw helpful error\n throw new Error(\n `Could not locate plugin assets. The assetPath option is required.\\n\\n` +\n `This typically happens when using a bundler (like Webpack 5 or Angular CLI) ` +\n `that transforms import.meta.url to a file:// URL.\\n\\n` +\n `To fix this, copy the plugin assets to your public folder and provide the assetPath option:\\n\\n` +\n `Option A: Configure your bundler to copy assets automatically\\n\\n` +\n ` Angular CLI - add to angular.json \"assets\" array:\\n` +\n ` { \"glob\": \"{gs.js,gs.wasm,*.icc}\", \"input\": \"node_modules/@imgly/plugin-print-ready-pdfs-web/dist\", \"output\": \"/assets/\" }\\n\\n` +\n ` Webpack - use copy-webpack-plugin:\\n` +\n ` new CopyPlugin({ patterns: [{ from: \"node_modules/@imgly/plugin-print-ready-pdfs-web/dist/*.{js,wasm,icc}\", to: \"assets/[name][ext]\" }] })\\n\\n` +\n `Option B: Copy manually\\n\\n` +\n ` cp node_modules/@imgly/plugin-print-ready-pdfs-web/dist/{gs.js,gs.wasm,*.icc} public/assets/\\n\\n` +\n `Then pass the assetPath option:\\n\\n` +\n ` convertToPDFX3(blob, {\\n` +\n ` outputProfile: 'fogra39',\\n` +\n ` assetPath: '/assets/' // adjust to match your output path\\n` +\n ` });\\n\\n` +\n `See: https://github.com/imgly/plugins/tree/main/packages/plugin-print-ready-pdfs-web#bundler-setup-webpack-5--angular`\n );\n}\n", "import type { AssetLoader } from '../types/asset-loader';\nimport type { GhostscriptModuleFactory } from '../types/ghostscript';\nimport { normalizeAssetPath } from '../utils/asset-path';\n\n/**\n * Browser-specific asset loader implementation.\n * Loads assets via HTTP fetch and dynamic import.\n *\n * @example\n * ```typescript\n * const loader = new BrowserAssetLoader('/assets/print-ready-pdfs/');\n * const result = await convertToPDFX3(pdfBlob, {\n * outputProfile: 'fogra39',\n * assetLoader: loader\n * });\n * ```\n */\nexport class BrowserAssetLoader implements AssetLoader {\n private baseUrl: string;\n\n /**\n * Create a new BrowserAssetLoader.\n * @param assetPath - Base URL path where plugin assets are served from.\n * Must be an absolute path (e.g., '/assets/') or full URL.\n */\n constructor(assetPath: string) {\n this.baseUrl = normalizeAssetPath(assetPath);\n }\n\n async loadGhostscriptModule(): Promise<GhostscriptModuleFactory> {\n const moduleUrl = new URL('gs.js', this.baseUrl).href;\n // webpackIgnore comment prevents Webpack from trying to bundle this dynamic import\n // The URL is determined at runtime based on assetPath configuration\n const module = await import(/* webpackIgnore: true */ moduleUrl);\n return module.default || module;\n }\n\n getWasmPath(): string {\n return new URL('gs.wasm', this.baseUrl).href;\n }\n\n async loadICCProfile(profileName: string): Promise<Blob> {\n const profileUrl = new URL(profileName, this.baseUrl).href;\n const response = await fetch(profileUrl);\n if (!response.ok) {\n throw new Error(\n `Failed to load ICC profile ${profileName}: ${response.status} ${response.statusText}`\n );\n }\n return response.blob();\n }\n}\n", "/**\n * Browser stub for NodeAssetLoader.\n * This file is only used by the browser bundle and should never be called at runtime.\n * If it is called, it means the user didn't provide assetPath or assetLoader option.\n */\n\n// This error will never actually be thrown because the browser entry point\n// throws before reaching the NodeAssetLoader import. But Webpack needs to\n// be able to resolve this import, so we provide a stub.\nexport class NodeAssetLoader {\n constructor() {\n throw new Error(\n 'NodeAssetLoader cannot be used in browser environments. ' +\n 'Please provide the `assetPath` or `assetLoader` option to convertToPDFX3().'\n );\n }\n\n async loadGhostscriptModule(): Promise<never> {\n throw new Error('Not available in browser');\n }\n\n getWasmPath(): string {\n throw new Error('Not available in browser');\n }\n\n async loadICCProfile(): Promise<never> {\n throw new Error('Not available in browser');\n }\n}\n", "/* eslint-disable no-console */\nexport type LogLevel = 'debug' | 'info' | 'warn' | 'error';\n\nexport interface LogEntry {\n timestamp: number;\n level: LogLevel;\n component: string;\n message: string;\n data?: any;\n}\n\nexport class Logger {\n private static globalLogLevel: LogLevel = 'warn';\n\n private static logs: LogEntry[] = [];\n\n private static maxLogs = 1000;\n\n constructor(private component: string) {}\n\n static setLogLevel(level: LogLevel): void {\n Logger.globalLogLevel = level;\n }\n\n static getLogs(): LogEntry[] {\n return [...Logger.logs];\n }\n\n static clearLogs(): void {\n Logger.logs = [];\n }\n\n debug(message: string, data?: any): void {\n this.log('debug', message, data);\n }\n\n info(message: string, data?: any): void {\n this.log('info', message, data);\n }\n\n warn(message: string, data?: any): void {\n this.log('warn', message, data);\n }\n\n error(message: string, data?: any): void {\n this.log('error', message, data);\n }\n\n private log(level: LogLevel, message: string, data?: any): void {\n const levelOrder: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n };\n\n if (levelOrder[level] < levelOrder[Logger.globalLogLevel]) {\n return;\n }\n\n const entry: LogEntry = {\n timestamp: Date.now(),\n level,\n component: this.component,\n message,\n data,\n };\n\n Logger.logs.push(entry);\n\n // Keep logs under the limit\n if (Logger.logs.length > Logger.maxLogs) {\n Logger.logs = Logger.logs.slice(-Logger.maxLogs);\n }\n\n // Console output\n const prefix = `[${new Date().toISOString()}] [${level.toUpperCase()}] [${\n this.component\n }]`;\n const logMessage = data ? `${message} ${JSON.stringify(data)}` : message;\n\n switch (level) {\n case 'debug':\n console.debug(prefix, logMessage);\n break;\n case 'info':\n console.info(prefix, logMessage);\n break;\n case 'warn':\n console.warn(prefix, logMessage);\n break;\n case 'error':\n console.error(prefix, logMessage);\n break;\n default:\n // All log levels handled above\n break;\n }\n }\n}\n", "export class BrowserDetection {\n supportsWebAssembly(): boolean {\n try {\n return (\n typeof WebAssembly === 'object' &&\n typeof WebAssembly.instantiate === 'function'\n );\n } catch {\n return false;\n }\n }\n}\n", "// Wrapper for the Ghostscript WASM module to ensure proper loading\nimport type {\n EmscriptenModule,\n GhostscriptModuleFactory,\n} from '../types/ghostscript';\nimport type { AssetLoader } from '../types/asset-loader';\n\nexport interface GhostscriptModuleOptions {\n /**\n * Whether to suppress Ghostscript's stdout/stderr output.\n * Default: true (silent mode)\n */\n silent?: boolean;\n\n /**\n * Asset loader for loading gs.js and gs.wasm.\n * Required - use BrowserAssetLoader or NodeAssetLoader.\n */\n assetLoader: AssetLoader;\n}\n\nexport default async function createGhostscriptModule(\n options: GhostscriptModuleOptions\n): Promise<EmscriptenModule> {\n const { silent = true, assetLoader } = options;\n\n // Load the Ghostscript module using the provided loader\n const factory = await assetLoader.loadGhostscriptModule();\n const wasmPath = assetLoader.getWasmPath();\n\n // Configure the module to load WASM from the specified location\n const moduleConfig: Record<string, unknown> = {\n locateFile: (filename: string) => {\n if (filename === 'gs.wasm') {\n return wasmPath;\n }\n return filename;\n },\n };\n\n // Suppress Ghostscript stdout/stderr output in silent mode\n if (silent) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n moduleConfig.print = () => {};\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n moduleConfig.printErr = () => {};\n }\n\n const module = await factory(moduleConfig);\n\n return module;\n}\n", "import type { EmscriptenModule } from '../types/ghostscript';\nimport type { AssetLoader } from '../types/asset-loader';\nimport { Logger } from '../utils/logger';\nimport { BrowserDetection } from '../utils/browser-detection';\nimport createGhostscriptModule from '../wasm/ghostscript-module';\n\nexport interface LoaderOptions {\n timeout?: number;\n /**\n * Asset loader for loading plugin assets.\n * Required - use BrowserAssetLoader or NodeAssetLoader.\n */\n assetLoader: AssetLoader;\n}\n\nexport class GhostscriptLoader {\n private static instance: Promise<EmscriptenModule> | null = null;\n\n private static readonly TIMEOUT_MS = 30000;\n\n static async load(options: LoaderOptions): Promise<EmscriptenModule> {\n // If already loaded, return the cached instance\n // (the WASM module is a singleton and assetLoader should be consistent within an app)\n if (this.instance) {\n return this.instance;\n }\n\n this.instance = this.loadInternal(options);\n return this.instance;\n }\n\n private static async loadInternal(\n options: LoaderOptions\n ): Promise<EmscriptenModule> {\n const logger = new Logger('GhostscriptLoader');\n const browser = new BrowserDetection();\n\n // Check browser compatibility\n if (!browser.supportsWebAssembly()) {\n throw new Error('WebAssembly not supported in this browser');\n }\n\n const timeout = options.timeout || this.TIMEOUT_MS;\n\n try {\n logger.info('Loading bundled Ghostscript (AGPL-3.0 licensed)');\n logger.info('Source available at: https://github.com/imgly/plugins');\n return await this.loadWithTimeout(\n () => this.loadFromBundle(options.assetLoader),\n timeout\n );\n } catch (error) {\n logger.error('Ghostscript loading failed', {\n error: (error as Error).message,\n });\n throw new Error(\n `Failed to load Ghostscript: ${(error as Error).message}`\n );\n }\n }\n\n private static async loadFromBundle(\n assetLoader: AssetLoader\n ): Promise<EmscriptenModule> {\n // Use the bundled WASM module with proper configuration\n const logger = new Logger('GhostscriptInit');\n\n try {\n logger.info('Initializing Ghostscript module');\n\n const module = await createGhostscriptModule({ assetLoader });\n\n logger.info('Ghostscript module initialized successfully', {\n version: module.version || 'unknown',\n hasFS: !!module.FS,\n hasCallMain: !!module.callMain,\n });\n\n return module;\n } catch (error) {\n logger.error('Ghostscript initialization failed', { error });\n throw new Error(\n `Ghostscript initialization failed: ${(error as Error).message}`\n );\n }\n }\n\n private static async loadWithTimeout<T>(\n operation: () => Promise<T>,\n timeoutMs: number\n ): Promise<T> {\n return Promise.race([\n operation(),\n new Promise<never>((_, reject) => {\n setTimeout(\n () => reject(new Error(`Loading timeout after ${timeoutMs}ms`)),\n timeoutMs\n );\n }),\n ]);\n }\n\n static reset(): void {\n this.instance = null;\n }\n}\n", "export class BlobUtils {\n static async toUint8Array(blob: Blob): Promise<Uint8Array> {\n if (blob.arrayBuffer) {\n const buffer = await blob.arrayBuffer();\n return new Uint8Array(buffer);\n }\n\n // Fallback for older browsers\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = () => {\n if (reader.result instanceof ArrayBuffer) {\n resolve(new Uint8Array(reader.result));\n } else {\n reject(new Error('Failed to read blob as ArrayBuffer'));\n }\n };\n reader.onerror = () => reject(reader.error);\n reader.readAsArrayBuffer(blob);\n });\n }\n\n static async validatePDF(blob: Blob): Promise<boolean> {\n try {\n const data = await this.toUint8Array(blob);\n\n // Check PDF magic number\n const pdfHeader = new Uint8Array([0x25, 0x50, 0x44, 0x46]); // %PDF\n\n if (data.length < 4) {\n return false;\n }\n\n for (let i = 0; i < 4; i++) {\n if (data[i] !== pdfHeader[i]) {\n return false;\n }\n }\n\n return true;\n } catch {\n return false;\n }\n }\n}\n", "import type { EmscriptenModule, EmscriptenFS } from '../types/ghostscript';\nimport { Logger } from '../utils/logger';\nimport { BlobUtils } from '../utils/blob-utils';\n\nexport interface FileEntry {\n path: string;\n data: Uint8Array;\n cleanup: boolean;\n}\n\nexport class VirtualFileSystem {\n private readonly fs: EmscriptenFS;\n\n private readonly logger: Logger;\n\n private readonly managedFiles: Set<string> = new Set();\n\n private readonly workingDir: string;\n\n constructor(\n private readonly module: EmscriptenModule,\n workingDir = '/tmp/pdfx'\n ) {\n this.fs = module.FS;\n this.logger = new Logger('VirtualFileSystem');\n this.workingDir = workingDir;\n this.initialize();\n }\n\n private initialize(): void {\n try {\n // Create working directory structure (handle existing directories gracefully)\n this.createDirIfNotExists(this.workingDir);\n this.createDirIfNotExists(`${this.workingDir}/input`);\n this.createDirIfNotExists(`${this.workingDir}/output`);\n this.createDirIfNotExists(`${this.workingDir}/profiles`);\n this.createDirIfNotExists(`${this.workingDir}/temp`);\n\n this.logger.info('Virtual filesystem initialized', {\n workingDir: this.workingDir,\n });\n } catch (error) {\n this.logger.error('Failed to initialize virtual filesystem', { error });\n throw new Error(`VFS initialization failed: ${error}`);\n }\n }\n\n private createDirIfNotExists(path: string): void {\n try {\n this.fs.mkdir(path);\n } catch (error: any) {\n // Ignore \"File exists\" errors, re-throw others\n if (error.code !== 'EEXIST') {\n throw error;\n }\n }\n }\n\n async writeBlob(path: string, blob: Blob, managed = true): Promise<void> {\n try {\n const data = await BlobUtils.toUint8Array(blob);\n this.fs.writeFile(path, data);\n\n if (managed) {\n this.managedFiles.add(path);\n }\n\n this.logger.debug('File written', { path, size: data.length });\n } catch (error) {\n this.logger.error('Failed to write blob', { path, error });\n throw new Error(`Failed to write file ${path}: ${error}`);\n }\n }\n\n writeText(path: string, content: string, managed = true): void {\n try {\n this.fs.writeFile(path, content);\n\n if (managed) {\n this.managedFiles.add(path);\n }\n\n this.logger.debug('Text file written', { path, length: content.length });\n } catch (error) {\n this.logger.error('Failed to write text', { path, error });\n throw new Error(`Failed to write text file ${path}: ${error}`);\n }\n }\n\n readFile(path: string): Uint8Array {\n try {\n const data = this.fs.readFile(path) as Uint8Array;\n this.logger.debug('File read', { path, size: data.length });\n return data;\n } catch (error) {\n this.logger.error('Failed to read file', { path, error });\n throw new Error(`Failed to read file ${path}: ${error}`);\n }\n }\n\n exists(path: string): boolean {\n try {\n this.fs.stat(path);\n return true;\n } catch {\n return false;\n }\n }\n\n cleanup(): void {\n let cleanedCount = 0;\n\n for (const path of this.managedFiles) {\n try {\n this.fs.unlink(path);\n cleanedCount++;\n } catch (error) {\n this.logger.warn('Failed to cleanup file', { path, error });\n }\n }\n\n this.managedFiles.clear();\n this.logger.info('Filesystem cleanup completed', { cleanedCount });\n }\n}\n", "import type { PDFX3Options, AssetLoader } from './types';\nimport { GhostscriptLoader } from './core/ghostscript-loader';\nimport { VirtualFileSystem } from './core/virtual-filesystem';\nimport { BlobUtils } from './utils/blob-utils';\n\n/**\n * Try to get a usable base URL from import.meta.url.\n * Returns null if the URL is not usable (e.g., file:// protocol in browser).\n */\nfunction tryGetBaseUrlFromImportMeta(): string | null {\n try {\n // import.meta.url points to the bundled JS file location\n // In Vite: \"http://localhost:5173/node_modules/.vite/deps/...\"\n // In Webpack 5: \"file:///path/to/dist/index.mjs\" (not usable in browser)\n const url = import.meta.url;\n if (!url) return null;\n\n // file:// URLs don't work for dynamic imports in browsers\n if (url.startsWith('file://')) return null;\n\n // Extract the directory from the URL\n const lastSlash = url.lastIndexOf('/');\n if (lastSlash === -1) return null;\n\n return url.substring(0, lastSlash + 1);\n } catch {\n return null;\n }\n}\n\n/**\n * Get the appropriate AssetLoader based on options and environment.\n */\nasync function getAssetLoader(options: PDFX3Options): Promise<AssetLoader> {\n // 1. Explicit loader takes precedence\n if (options.assetLoader) {\n return options.assetLoader;\n }\n\n // 2. assetPath creates a BrowserAssetLoader\n if (options.assetPath) {\n const { BrowserAssetLoader } = await import('./loaders/browser-loader');\n return new BrowserAssetLoader(options.assetPath);\n }\n\n // 3. Auto-detect environment\n const isBrowser =\n typeof window !== 'undefined' || typeof document !== 'undefined';\n\n if (isBrowser) {\n // Try to auto-detect base URL from import.meta.url (works in Vite)\n const autoBaseUrl = tryGetBaseUrlFromImportMeta();\n if (autoBaseUrl) {\n const { BrowserAssetLoader } = await import('./loaders/browser-loader');\n return new BrowserAssetLoader(autoBaseUrl);\n }\n\n // Can't auto-detect - require explicit configuration (Webpack 5, Angular, etc.)\n throw new Error(\n 'In browser environments with Webpack 5 or Angular, you must provide the `assetPath` option.\\n\\n' +\n 'Example:\\n' +\n ' convertToPDFX3(blob, {\\n' +\n \" outputProfile: 'fogra39',\\n\" +\n \" assetPath: '/assets/print-ready-pdfs/'\\n\" +\n ' });\\n\\n' +\n 'See: https://github.com/imgly/plugins/tree/main/packages/plugin-print-ready-pdfs-web#bundler-setup-webpack-5--angular'\n );\n }\n\n // Node.js - use NodeAssetLoader\n const { NodeAssetLoader } = await import('./loaders/node-loader');\n return new NodeAssetLoader();\n}\n\n/**\n * PDF/X-3 conversion function\n * Converts RGB PDF(s) to PDF/X-3 format using specified output profile\n *\n * @overload\n * @param inputPDF Single PDF blob to convert\n * @param options Conversion configuration\n * @returns Promise resolving to converted PDF blob\n *\n * @overload\n * @param inputPDFs Array of PDF blobs to convert\n * @param options Conversion configuration\n * @returns Promise resolving to array of converted PDF blobs\n */\nexport function convertToPDFX3(\n inputPDF: Blob,\n options: PDFX3Options\n): Promise<Blob>;\nexport function convertToPDFX3(\n inputPDFs: Blob[],\n options: PDFX3Options\n): Promise<Blob[]>;\nexport async function convertToPDFX3(\n input: Blob | Blob[],\n options: PDFX3Options\n): Promise<Blob | Blob[]> {\n // Handle array input (batch processing)\n if (Array.isArray(input)) {\n if (input.length === 0) {\n return [];\n }\n\n // Process each blob sequentially to avoid overwhelming the WASM module\n const results: Blob[] = [];\n for (let i = 0; i < input.length; i++) {\n try {\n // eslint-disable-next-line no-await-in-loop\n const converted = await convertToPDFX3Single(input[i], options);\n results.push(converted);\n } catch (error) {\n throw new Error(\n `Failed to convert PDF ${i + 1} of ${input.length}: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n }\n return results;\n }\n\n // Handle single blob input\n return convertToPDFX3Single(input, options);\n}\n\n/**\n * Internal function to convert a single PDF\n */\nasync function convertToPDFX3Single(\n inputPDF: Blob,\n options: PDFX3Options\n): Promise<Blob> {\n // Validate inputs\n if (!(inputPDF instanceof Blob)) {\n throw new Error('Input must be a Blob');\n }\n\n if (inputPDF.size === 0) {\n throw new Error('Input PDF is empty');\n }\n\n if (inputPDF.size > 100 * 1024 * 1024) {\n throw new Error(\n `Input PDF too large (${inputPDF.size} bytes). Maximum: 100MB`\n );\n }\n\n // Validate output profile is provided\n if (!options.outputProfile) {\n throw new Error(\n 'outputProfile is required. Must be one of: \"gracol\", \"fogra39\", \"srgb\", \"custom\"'\n );\n }\n\n // Validate output profile value\n const validProfiles = ['gracol', 'fogra39', 'srgb', 'custom'];\n if (!validProfiles.includes(options.outputProfile)) {\n throw new Error(\n `Invalid outputProfile \"${\n options.outputProfile\n }\". Must be one of: ${validProfiles.join(', ')}`\n );\n }\n\n // Validate custom profile requirement\n if (options.outputProfile === 'custom' && !options.customProfile) {\n throw new Error(\n 'customProfile Blob is required when outputProfile is \"custom\"'\n );\n }\n\n // Validate custom profile if provided\n if (options.customProfile && !(options.customProfile instanceof Blob)) {\n throw new Error('customProfile must be a Blob');\n }\n\n // Validate PDF format\n const isValidPDF = await BlobUtils.validatePDF(inputPDF);\n if (!isValidPDF) {\n throw new Error('Invalid PDF format');\n }\n\n // Get the asset loader for this conversion\n const assetLoader = await getAssetLoader(options);\n\n // Load Ghostscript with the asset loader\n const module = await GhostscriptLoader.load({ assetLoader });\n const vfs = new VirtualFileSystem(module);\n\n try {\n // Setup file paths\n const inputPath = '/tmp/input.pdf';\n const outputPath = '/tmp/output.pdf';\n const pdfxDefPath = '/tmp/pdfx_def.ps';\n const customProfilePath = '/tmp/custom.icc';\n\n // Write input PDF to virtual filesystem\n await vfs.writeBlob(inputPath, inputPDF);\n\n // Write ICC profiles to virtual filesystem\n if (options.outputProfile === 'custom' && options.customProfile) {\n await vfs.writeBlob(customProfilePath, options.customProfile);\n } else if (options.outputProfile !== 'custom') {\n // Load the bundled ICC profile using the asset loader\n const profileInfo =\n PROFILE_PRESETS[options.outputProfile as keyof typeof PROFILE_PRESETS];\n const profilePath = `/tmp/${profileInfo.file}`;\n\n const profileBlob = await assetLoader.loadICCProfile(profileInfo.file);\n await vfs.writeBlob(profilePath, profileBlob);\n }\n\n // Determine ICC profile path and metadata for Ghostscript\n let iccProfilePath: string;\n let outputConditionIdentifier: string;\n let outputCondition: string;\n\n if (options.outputProfile === 'custom') {\n iccProfilePath = customProfilePath;\n // Use custom values or defaults\n outputConditionIdentifier =\n options.outputConditionIdentifier || 'Custom Profile';\n outputCondition = options.outputCondition || 'Custom ICC Profile';\n } else {\n const preset =\n PROFILE_PRESETS[options.outputProfile as keyof typeof PROFILE_PRESETS];\n iccProfilePath = `/tmp/${preset.file}`;\n // Allow overriding preset values\n outputConditionIdentifier =\n options.outputConditionIdentifier || preset.identifier;\n outputCondition = options.outputCondition || preset.info;\n }\n\n // Read ICC profile data and convert to hex for embedding\n // WASM doesn't support (file) (r) file syntax, so we embed directly\n const iccData = vfs.readFile(iccProfilePath);\n const iccHex = Array.from(iccData)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n\n // Determine color conversion strategy based on profile type\n // ICC profile color space is at bytes 16-19\n // 'RGB ' = 0x52474220, 'CMYK' = 0x434D594B\n const colorSpaceBytes = iccData.slice(16, 20);\n const colorSpaceStr = String.fromCharCode(...colorSpaceBytes);\n const isCMYKProfile = colorSpaceStr.trim() === 'CMYK';\n\n // Generate PDF/X-3 definition with ICC profile hex data\n const pdfxDefinition = generatePDFXDef(\n options,\n iccHex,\n outputConditionIdentifier,\n outputCondition\n );\n vfs.writeText(pdfxDefPath, pdfxDefinition);\n\n // Execute Ghostscript conversion\n // For CMYK profiles, convert all colors to CMYK using the ICC profile\n // Note: Transparency flattening will rasterize transparent content\n const gsArgs = [\n '-dBATCH',\n '-dNOPAUSE',\n '-sDEVICE=pdfwrite',\n '-dCompatibilityLevel=1.4',\n // Disable PDF 1.5+ features to avoid warnings with PDF 1.4 compatibility\n '-dWriteObjStms=false',\n '-dWriteXRefStm=false',\n // PDF/X-3 settings\n '-dPDFSETTINGS=/prepress',\n '-dSetPageSize=false',\n '-dAutoRotatePages=/None',\n ];\n\n // Flatten transparency for PDF/X-3 compliance (default: true)\n // HaveTransparency=false tells Ghostscript the target viewer cannot handle\n // PDF 1.4 transparency, so pages with transparency are converted to bitmaps\n const shouldFlattenTransparency = options.flattenTransparency !== false;\n if (shouldFlattenTransparency) {\n gsArgs.push('-dHaveTransparency=false');\n }\n\n // Add color conversion for CMYK profiles\n if (isCMYKProfile) {\n gsArgs.push(\n '-sColorConversionStrategy=CMYK',\n '-dProcessColorModel=/DeviceCMYK',\n '-dConvertCMYKImagesToRGB=false'\n );\n } else {\n // For RGB profiles, we still need a color conversion strategy\n gsArgs.push('-sColorConversionStrategy=RGB');\n }\n\n // Add output file and input files\n gsArgs.push(`-sOutputFile=${outputPath}`, pdfxDefPath, inputPath);\n\n const exitCode = await module.callMain(gsArgs);\n if (exitCode !== 0) {\n throw new Error(\n `Ghostscript conversion failed with exit code ${exitCode}`\n );\n }\n\n // Read output\n const outputData = vfs.readFile(outputPath);\n // Create a copy of the data to ensure it's an ArrayBuffer, not SharedArrayBuffer\n const outputBuffer = new Uint8Array(outputData);\n const outputPDF = new Blob([outputBuffer], { type: 'application/pdf' });\n\n // Cleanup\n vfs.cleanup();\n\n return outputPDF;\n } catch (error) {\n vfs.cleanup();\n throw error;\n }\n}\n\n// Profile presets from the spec\nconst PROFILE_PRESETS = {\n gracol: {\n file: 'GRACoL2013_CRPC6.icc',\n identifier: 'CGATS 21.2',\n info: 'GRACoL 2013 CRPC6',\n },\n fogra39: {\n file: 'ISOcoated_v2_eci.icc',\n identifier: 'FOGRA39',\n info: 'ISO Coated v2 (ECI)',\n },\n srgb: {\n file: 'sRGB_IEC61966-2-1.icc',\n identifier: 'sRGB IEC61966-2.1',\n info: 'sRGB IEC61966-2.1',\n },\n};\n\nfunction generatePDFXDef(\n options: PDFX3Options,\n iccProfileHex: string,\n outputConditionIdentifier: string,\n outputCondition: string\n): string {\n return `%!\n% PDF/X-3 Definition File\n[ /Title (${options.title || 'Untitled'}) /DOCINFO pdfmark\n[ /Trapped /False /DOCINFO pdfmark\n\n% Set PDF/X-3 conformance\n[ /GTS_PDFXVersion (PDF/X-3:2003) /GTS_PDFXConformance (PDF/X-3:2003) /DOCINFO pdfmark\n\n% Set TrimBox to match MediaBox for all pages (required for PDF/X)\n[/TrimBox [0 0 0 0] /PAGE pdfmark\n\n% Embed ICC profile as hex stream\n[/_objdef {icc_PDFX} /type /stream /OBJ pdfmark\n[{icc_PDFX} <</N 4>> /PUT pdfmark\n[{icc_PDFX} <${iccProfileHex}> /PUT pdfmark\n\n% Define OutputIntent with embedded ICC profile\n[/_objdef {OutputIntent_PDFX} /type /dict /OBJ pdfmark\n[{OutputIntent_PDFX} <<\n /Type /OutputIntent\n /S /GTS_PDFX\n /OutputCondition (${outputCondition})\n /OutputConditionIdentifier (${outputConditionIdentifier})\n /RegistryName (http://www.color.org)\n /DestOutputProfile {icc_PDFX}\n>> /PUT pdfmark\n\n% Add OutputIntent to Catalog\n[{Catalog} <</OutputIntents [{OutputIntent_PDFX}]>> /PUT pdfmark`;\n}\n", "/**\n * @imgly/plugin-pdfx-web - Print-Ready PDF conversion for CE.SDK\n * Browser-specific entry point\n *\n * This entry point is optimized for browser environments:\n * - No Node.js-specific code included\n * - CSP-safe (no new Function() or eval())\n * - Uses standard dynamic import() for loading gs.js\n *\n * IMPORTANT: This package includes Ghostscript WASM binaries licensed under AGPL-3.0.\n * Commercial users must ensure license compliance. See README.md for details.\n */\n\n// Export the main conversion function\nexport { convertToPDFX3 } from './pdfx';\n\n// Export BrowserAssetLoader for browser environments\nexport { BrowserAssetLoader } from './loaders/browser-loader';\n\n// Export Logger for controlling log verbosity\nexport { Logger } from './utils/logger';\n\n// Export types for TypeScript users\nexport type { PDFX3Options, AssetLoader } from './types';\nexport type { LogLevel } from './utils/logger';\n"],
5
- "mappings": "6HAUO,SAASA,EAAmBC,EAAsB,CACvD,IAAMC,EAAiBD,EAAK,SAAS,GAAG,EAAIA,EAAOA,EAAO,IAG1D,OACEC,EAAe,WAAW,SAAS,GACnCA,EAAe,WAAW,UAAU,EAE7BA,GAKP,OAAO,SAAa,KAAc,SAAS,UAAU,QAAU,IAEjDA,CAClB,CA1BA,IAAAC,EAAAC,EAAA,oBCAA,IAAAC,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,IAAA,IAiBaA,EAjBbC,EAAAC,EAAA,kBAEAC,IAeaH,EAAN,KAAgD,CAC7C,QAOR,YAAYI,EAAmB,CAC7B,KAAK,QAAUC,EAA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rC,EACA2C,EACAf,EACAC,EACQ,CACR,MAAO;AAAA;AAAA,YAEG7B,EAAQ,OAAS,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAYxB2C,CAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAONd,CAAe;AAAA,gCACLD,CAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iEAOzD,CCvWAgB",
6
- "names": ["normalizeAssetPath", "path", "normalizedPath", "init_asset_path", "__esmMin", "browser_loader_exports", "__export", "BrowserAssetLoader", "init_browser_loader", "__esmMin", "init_asset_path", "assetPath", "normalizeAssetPath", "module", "profileName", "profileUrl", "response", "node_loader_browser_exports", "__export", "NodeAssetLoader", "init_node_loader_browser", "__esmMin", "Logger", "_Logger", "component", "level", "message", "data", "levelOrder", "entry", "prefix", "logMessage", "BrowserDetection", "createGhostscriptModule", "options", "silent", "assetLoader", "factory", "wasmPath", "moduleConfig", "filename", "GhostscriptLoader", "options", "logger", "Logger", "BrowserDetection", "timeout", "error", "assetLoader", "module", "createGhostscriptModule", "operation", "timeoutMs", "_", "reject", "BlobUtils", "blob", "buffer", "resolve", "reject", "reader", "data", "pdfHeader", "VirtualFileSystem", "module", "workingDir", "Logger", "error", "path", "blob", "managed", "data", "BlobUtils", "content", "cleanedCount", "tryGetBaseUrlFromImportMeta", "url", "lastSlash", "getAssetLoader", "options", "BrowserAssetLoader", "autoBaseUrl", "NodeAssetLoader", "convertToPDFX3", "input", "results", "i", "converted", "convertToPDFX3Single", "error", "inputPDF", "validProfiles", "BlobUtils", "assetLoader", "module", "GhostscriptLoader", "vfs", "VirtualFileSystem", "inputPath", "outputPath", "pdfxDefPath", "customProfilePath", "profileInfo", "PROFILE_PRESETS", "profilePath", "profileBlob", "iccProfilePath", "outputConditionIdentifier", "outputCondition", "preset", "iccData", "iccHex", "b", "colorSpaceBytes", "isCMYKProfile", "pdfxDefinition", "generatePDFXDef", "gsArgs", "exitCode", "outputData", "outputBuffer", "outputPDF", "iccProfileHex", "init_browser_loader"]
7
- }
@@ -1,38 +0,0 @@
1
- var j=Object.defineProperty;var P=(r,t)=>()=>(r&&(t=r(r=0)),t);var B=(r,t)=>{for(var e in t)j(r,e,{get:t[e],enumerable:!0})};function S(r){let t=r.endsWith("/")?r:r+"/";return t.startsWith("http://")||t.startsWith("https://")?t:(typeof document<"u"&&document.location?.origin||"")+t}var T=P(()=>{"use strict"});var v={};B(v,{BrowserAssetLoader:()=>F});var F,L=P(()=>{"use strict";T();F=class{baseUrl;constructor(t){this.baseUrl=S(t)}async loadGhostscriptModule(){let e=await import(new URL("gs.js",this.baseUrl).href);return e.default||e}getWasmPath(){return new URL("gs.wasm",this.baseUrl).href}async loadICCProfile(t){let e=new URL(t,this.baseUrl).href,o=await fetch(e);if(!o.ok)throw new Error(`Failed to load ICC profile ${t}: ${o.status} ${o.statusText}`);return o.blob()}}});var O={};B(O,{NodeAssetLoader:()=>g});var g,E=P(()=>{"use strict";g=class{moduleDir=null;gsPath=null;initPromise=null;constructor(){this.initPromise=this.initialize()}async initialize(){let t=await import("module"),e=await import("path"),i=(t.createRequire||t.default?.createRequire)(import.meta.url);this.gsPath=i.resolve("./gs.js");let n=e.dirname||e.default?.dirname;this.moduleDir=n(this.gsPath)}async ensureInitialized(){this.initPromise&&(await this.initPromise,this.initPromise=null)}async loadGhostscriptModule(){await this.ensureInitialized();let t=await import(this.gsPath);return t.default||t}getWasmPath(){if(!this.moduleDir)throw new Error("NodeAssetLoader not initialized. Call loadGhostscriptModule() first and await its completion.");return`${this.moduleDir}/gs.wasm`}async loadICCProfile(t){await this.ensureInitialized();let e=await import("fs"),o=await import("path"),i=o.join||o.default?.join,n=e.readFileSync||e.default?.readFileSync,s=i(this.moduleDir,t),a=n(s);return new Blob([a],{type:"application/vnd.iccprofile"})}}});var c=class r{constructor(t){this.component=t}static globalLogLevel="warn";static logs=[];static maxLogs=1e3;static setLogLevel(t){r.globalLogLevel=t}static getLogs(){return[...r.logs]}static clearLogs(){r.logs=[]}debug(t,e){this.log("debug",t,e)}info(t,e){this.log("info",t,e)}warn(t,e){this.log("warn",t,e)}error(t,e){this.log("error",t,e)}log(t,e,o){let i={debug:0,info:1,warn:2,error:3};if(i[t]<i[r.globalLogLevel])return;let n={timestamp:Date.now(),level:t,component:this.component,message:e,data:o};r.logs.push(n),r.logs.length>r.maxLogs&&(r.logs=r.logs.slice(-r.maxLogs));let s=`[${new Date().toISOString()}] [${t.toUpperCase()}] [${this.component}]`,a=o?`${e} ${JSON.stringify(o)}`:e;switch(t){case"debug":console.debug(s,a);break;case"info":console.info(s,a);break;case"warn":console.warn(s,a);break;case"error":console.error(s,a);break;default:break}}};var p=class{supportsWebAssembly(){try{return typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function"}catch{return!1}}};async function b(r){let{silent:t=!0,assetLoader:e}=r,o=await e.loadGhostscriptModule(),i=e.getWasmPath(),n={locateFile:a=>a==="gs.wasm"?i:a};return t&&(n.print=()=>{},n.printErr=()=>{}),await o(n)}var f=class{static instance=null;static TIMEOUT_MS=3e4;static async load(t){return this.instance?this.instance:(this.instance=this.loadInternal(t),this.instance)}static async loadInternal(t){let e=new c("GhostscriptLoader");if(!new p().supportsWebAssembly())throw new Error("WebAssembly not supported in this browser");let i=t.timeout||this.TIMEOUT_MS;try{return e.info("Loading bundled Ghostscript (AGPL-3.0 licensed)"),e.info("Source available at: https://github.com/imgly/plugins"),await this.loadWithTimeout(()=>this.loadFromBundle(t.assetLoader),i)}catch(n){throw e.error("Ghostscript loading failed",{error:n.message}),new Error(`Failed to load Ghostscript: ${n.message}`)}}static async loadFromBundle(t){let e=new c("GhostscriptInit");try{e.info("Initializing Ghostscript module");let o=await b({assetLoader:t});return e.info("Ghostscript module initialized successfully",{version:o.version||"unknown",hasFS:!!o.FS,hasCallMain:!!o.callMain}),o}catch(o){throw e.error("Ghostscript initialization failed",{error:o}),new Error(`Ghostscript initialization failed: ${o.message}`)}}static async loadWithTimeout(t,e){return Promise.race([t(),new Promise((o,i)=>{setTimeout(()=>i(new Error(`Loading timeout after ${e}ms`)),e)})])}static reset(){this.instance=null}};var u=class{static async toUint8Array(t){if(t.arrayBuffer){let e=await t.arrayBuffer();return new Uint8Array(e)}return new Promise((e,o)=>{let i=new FileReader;i.onload=()=>{i.result instanceof ArrayBuffer?e(new Uint8Array(i.result)):o(new Error("Failed to read blob as ArrayBuffer"))},i.onerror=()=>o(i.error),i.readAsArrayBuffer(t)})}static async validatePDF(t){try{let e=await this.toUint8Array(t),o=new Uint8Array([37,80,68,70]);if(e.length<4)return!1;for(let i=0;i<4;i++)if(e[i]!==o[i])return!1;return!0}catch{return!1}}};var m=class{constructor(t,e="/tmp/pdfx"){this.module=t;this.fs=t.FS,this.logger=new c("VirtualFileSystem"),this.workingDir=e,this.initialize()}fs;logger;managedFiles=new Set;workingDir;initialize(){try{this.createDirIfNotExists(this.workingDir),this.createDirIfNotExists(`${this.workingDir}/input`),this.createDirIfNotExists(`${this.workingDir}/output`),this.createDirIfNotExists(`${this.workingDir}/profiles`),this.createDirIfNotExists(`${this.workingDir}/temp`),this.logger.info("Virtual filesystem initialized",{workingDir:this.workingDir})}catch(t){throw this.logger.error("Failed to initialize virtual filesystem",{error:t}),new Error(`VFS initialization failed: ${t}`)}}createDirIfNotExists(t){try{this.fs.mkdir(t)}catch(e){if(e.code!=="EEXIST")throw e}}async writeBlob(t,e,o=!0){try{let i=await u.toUint8Array(e);this.fs.writeFile(t,i),o&&this.managedFiles.add(t),this.logger.debug("File written",{path:t,size:i.length})}catch(i){throw this.logger.error("Failed to write blob",{path:t,error:i}),new Error(`Failed to write file ${t}: ${i}`)}}writeText(t,e,o=!0){try{this.fs.writeFile(t,e),o&&this.managedFiles.add(t),this.logger.debug("Text file written",{path:t,length:e.length})}catch(i){throw this.logger.error("Failed to write text",{path:t,error:i}),new Error(`Failed to write text file ${t}: ${i}`)}}readFile(t){try{let e=this.fs.readFile(t);return this.logger.debug("File read",{path:t,size:e.length}),e}catch(e){throw this.logger.error("Failed to read file",{path:t,error:e}),new Error(`Failed to read file ${t}: ${e}`)}}exists(t){try{return this.fs.stat(t),!0}catch{return!1}}cleanup(){let t=0;for(let e of this.managedFiles)try{this.fs.unlink(e),t++}catch(o){this.logger.warn("Failed to cleanup file",{path:e,error:o})}this.managedFiles.clear(),this.logger.info("Filesystem cleanup completed",{cleanedCount:t})}};function q(){try{let r=import.meta.url;if(!r||r.startsWith("file://"))return null;let t=r.lastIndexOf("/");return t===-1?null:r.substring(0,t+1)}catch{return null}}async function V(r){if(r.assetLoader)return r.assetLoader;if(r.assetPath){let{BrowserAssetLoader:o}=await Promise.resolve().then(()=>(L(),v));return new o(r.assetPath)}if(typeof window<"u"||typeof document<"u"){let o=q();if(o){let{BrowserAssetLoader:i}=await Promise.resolve().then(()=>(L(),v));return new i(o)}throw new Error(`In browser environments with Webpack 5 or Angular, you must provide the \`assetPath\` option.
2
-
3
- Example:
4
- convertToPDFX3(blob, {
5
- outputProfile: 'fogra39',
6
- assetPath: '/assets/print-ready-pdfs/'
7
- });
8
-
9
- See: https://github.com/imgly/plugins/tree/main/packages/plugin-print-ready-pdfs-web#bundler-setup-webpack-5--angular`)}let{NodeAssetLoader:e}=await Promise.resolve().then(()=>(E(),O));return new e}async function K(r,t){if(Array.isArray(r)){if(r.length===0)return[];let e=[];for(let o=0;o<r.length;o++)try{let i=await M(r[o],t);e.push(i)}catch(i){throw new Error(`Failed to convert PDF ${o+1} of ${r.length}: ${i instanceof Error?i.message:String(i)}`)}return e}return M(r,t)}async function M(r,t){if(!(r instanceof Blob))throw new Error("Input must be a Blob");if(r.size===0)throw new Error("Input PDF is empty");if(r.size>100*1024*1024)throw new Error(`Input PDF too large (${r.size} bytes). Maximum: 100MB`);if(!t.outputProfile)throw new Error('outputProfile is required. Must be one of: "gracol", "fogra39", "srgb", "custom"');let e=["gracol","fogra39","srgb","custom"];if(!e.includes(t.outputProfile))throw new Error(`Invalid outputProfile "${t.outputProfile}". Must be one of: ${e.join(", ")}`);if(t.outputProfile==="custom"&&!t.customProfile)throw new Error('customProfile Blob is required when outputProfile is "custom"');if(t.customProfile&&!(t.customProfile instanceof Blob))throw new Error("customProfile must be a Blob");if(!await u.validatePDF(r))throw new Error("Invalid PDF format");let i=await V(t),n=await f.load({assetLoader:i}),s=new m(n);try{let a="/tmp/input.pdf",D="/tmp/output.pdf",C="/tmp/pdfx_def.ps",I="/tmp/custom.icc";if(await s.writeBlob(a,r),t.outputProfile==="custom"&&t.customProfile)await s.writeBlob(I,t.customProfile);else if(t.outputProfile!=="custom"){let l=k[t.outputProfile],N=`/tmp/${l.file}`,_=await i.loadICCProfile(l.file);await s.writeBlob(N,_)}let h,y,w;if(t.outputProfile==="custom")h=I,y=t.outputConditionIdentifier||"Custom Profile",w=t.outputCondition||"Custom ICC Profile";else{let l=k[t.outputProfile];h=`/tmp/${l.file}`,y=t.outputConditionIdentifier||l.identifier,w=t.outputCondition||l.info}let x=s.readFile(h),G=Array.from(x).map(l=>l.toString(16).padStart(2,"0")).join(""),$=x.slice(16,20),U=String.fromCharCode(...$).trim()==="CMYK",X=Y(t,G,y,w);s.writeText(C,X);let d=["-dBATCH","-dNOPAUSE","-sDEVICE=pdfwrite","-dCompatibilityLevel=1.4","-dWriteObjStms=false","-dWriteXRefStm=false","-dPDFSETTINGS=/prepress","-dSetPageSize=false","-dAutoRotatePages=/None"];t.flattenTransparency!==!1&&d.push("-dHaveTransparency=false"),U?d.push("-sColorConversionStrategy=CMYK","-dProcessColorModel=/DeviceCMYK","-dConvertCMYKImagesToRGB=false"):d.push("-sColorConversionStrategy=RGB"),d.push(`-sOutputFile=${D}`,C,a);let A=await n.callMain(d);if(A!==0)throw new Error(`Ghostscript conversion failed with exit code ${A}`);let R=s.readFile(D),z=new Uint8Array(R),W=new Blob([z],{type:"application/pdf"});return s.cleanup(),W}catch(a){throw s.cleanup(),a}}var k={gracol:{file:"GRACoL2013_CRPC6.icc",identifier:"CGATS 21.2",info:"GRACoL 2013 CRPC6"},fogra39:{file:"ISOcoated_v2_eci.icc",identifier:"FOGRA39",info:"ISO Coated v2 (ECI)"},srgb:{file:"sRGB_IEC61966-2-1.icc",identifier:"sRGB IEC61966-2.1",info:"sRGB IEC61966-2.1"}};function Y(r,t,e,o){return`%!
10
- % PDF/X-3 Definition File
11
- [ /Title (${r.title||"Untitled"}) /DOCINFO pdfmark
12
- [ /Trapped /False /DOCINFO pdfmark
13
-
14
- % Set PDF/X-3 conformance
15
- [ /GTS_PDFXVersion (PDF/X-3:2003) /GTS_PDFXConformance (PDF/X-3:2003) /DOCINFO pdfmark
16
-
17
- % Set TrimBox to match MediaBox for all pages (required for PDF/X)
18
- [/TrimBox [0 0 0 0] /PAGE pdfmark
19
-
20
- % Embed ICC profile as hex stream
21
- [/_objdef {icc_PDFX} /type /stream /OBJ pdfmark
22
- [{icc_PDFX} <</N 4>> /PUT pdfmark
23
- [{icc_PDFX} <${t}> /PUT pdfmark
24
-
25
- % Define OutputIntent with embedded ICC profile
26
- [/_objdef {OutputIntent_PDFX} /type /dict /OBJ pdfmark
27
- [{OutputIntent_PDFX} <<
28
- /Type /OutputIntent
29
- /S /GTS_PDFX
30
- /OutputCondition (${o})
31
- /OutputConditionIdentifier (${e})
32
- /RegistryName (http://www.color.org)
33
- /DestOutputProfile {icc_PDFX}
34
- >> /PUT pdfmark
35
-
36
- % Add OutputIntent to Catalog
37
- [{Catalog} <</OutputIntents [{OutputIntent_PDFX}]>> /PUT pdfmark`}E();export{c as Logger,g as NodeAssetLoader,K as convertToPDFX3};
38
- //# sourceMappingURL=index.node.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/utils/asset-path.ts", "../src/loaders/browser-loader.ts", "../src/loaders/node-loader.ts", "../src/utils/logger.ts", "../src/utils/browser-detection.ts", "../src/wasm/ghostscript-module.ts", "../src/core/ghostscript-loader.ts", "../src/utils/blob-utils.ts", "../src/core/virtual-filesystem.ts", "../src/pdfx.ts", "../src/index.node.ts"],
4
- "sourcesContent": ["/**\n * Asset path utilities for resolving plugin assets in different environments.\n * Handles the Webpack 5 / Angular CLI issue where import.meta.url is transformed\n * to a file:// URL that doesn't work in browsers.\n */\n\n/**\n * Normalizes an asset path to ensure it has a trailing slash and is a valid URL.\n * Converts relative paths (e.g., '/assets/wasm/') to absolute URLs using the current origin.\n */\nexport function normalizeAssetPath(path: string): string {\n const normalizedPath = path.endsWith('/') ? path : path + '/';\n\n // If it's already an absolute URL, return as-is\n if (\n normalizedPath.startsWith('http://') ||\n normalizedPath.startsWith('https://')\n ) {\n return normalizedPath;\n }\n\n // Convert relative path to absolute URL using document.location.origin\n const origin =\n typeof document !== 'undefined' ? document.location?.origin || '' : '';\n\n return origin + normalizedPath;\n}\n\n/**\n * Resolves the base URL for loading plugin assets in browser environments.\n * Throws a helpful error if assetPath is required but not provided.\n *\n * @param assetPath - Explicit asset path provided by the user\n * @param currentModuleUrl - The import.meta.url of the calling module\n */\nexport function resolveAssetBasePath(\n assetPath: string | undefined,\n currentModuleUrl: string\n): string {\n // 1. Explicit assetPath always wins\n if (assetPath) {\n return normalizeAssetPath(assetPath);\n }\n\n // 2. Try import.meta.url (works in Vite, native ESM)\n if (!currentModuleUrl.startsWith('file://')) {\n // Valid browser URL - use it directly\n return new URL('./', currentModuleUrl).href;\n }\n\n // 3. Bundled environment (Webpack 5 transforms to file://)\n // assetPath is required - throw helpful error\n throw new Error(\n `Could not locate plugin assets. The assetPath option is required.\\n\\n` +\n `This typically happens when using a bundler (like Webpack 5 or Angular CLI) ` +\n `that transforms import.meta.url to a file:// URL.\\n\\n` +\n `To fix this, copy the plugin assets to your public folder and provide the assetPath option:\\n\\n` +\n `Option A: Configure your bundler to copy assets automatically\\n\\n` +\n ` Angular CLI - add to angular.json \"assets\" array:\\n` +\n ` { \"glob\": \"{gs.js,gs.wasm,*.icc}\", \"input\": \"node_modules/@imgly/plugin-print-ready-pdfs-web/dist\", \"output\": \"/assets/\" }\\n\\n` +\n ` Webpack - use copy-webpack-plugin:\\n` +\n ` new CopyPlugin({ patterns: [{ from: \"node_modules/@imgly/plugin-print-ready-pdfs-web/dist/*.{js,wasm,icc}\", to: \"assets/[name][ext]\" }] })\\n\\n` +\n `Option B: Copy manually\\n\\n` +\n ` cp node_modules/@imgly/plugin-print-ready-pdfs-web/dist/{gs.js,gs.wasm,*.icc} public/assets/\\n\\n` +\n `Then pass the assetPath option:\\n\\n` +\n ` convertToPDFX3(blob, {\\n` +\n ` outputProfile: 'fogra39',\\n` +\n ` assetPath: '/assets/' // adjust to match your output path\\n` +\n ` });\\n\\n` +\n `See: https://github.com/imgly/plugins/tree/main/packages/plugin-print-ready-pdfs-web#bundler-setup-webpack-5--angular`\n );\n}\n", "import type { AssetLoader } from '../types/asset-loader';\nimport type { GhostscriptModuleFactory } from '../types/ghostscript';\nimport { normalizeAssetPath } from '../utils/asset-path';\n\n/**\n * Browser-specific asset loader implementation.\n * Loads assets via HTTP fetch and dynamic import.\n *\n * @example\n * ```typescript\n * const loader = new BrowserAssetLoader('/assets/print-ready-pdfs/');\n * const result = await convertToPDFX3(pdfBlob, {\n * outputProfile: 'fogra39',\n * assetLoader: loader\n * });\n * ```\n */\nexport class BrowserAssetLoader implements AssetLoader {\n private baseUrl: string;\n\n /**\n * Create a new BrowserAssetLoader.\n * @param assetPath - Base URL path where plugin assets are served from.\n * Must be an absolute path (e.g., '/assets/') or full URL.\n */\n constructor(assetPath: string) {\n this.baseUrl = normalizeAssetPath(assetPath);\n }\n\n async loadGhostscriptModule(): Promise<GhostscriptModuleFactory> {\n const moduleUrl = new URL('gs.js', this.baseUrl).href;\n // webpackIgnore comment prevents Webpack from trying to bundle this dynamic import\n // The URL is determined at runtime based on assetPath configuration\n const module = await import(/* webpackIgnore: true */ moduleUrl);\n return module.default || module;\n }\n\n getWasmPath(): string {\n return new URL('gs.wasm', this.baseUrl).href;\n }\n\n async loadICCProfile(profileName: string): Promise<Blob> {\n const profileUrl = new URL(profileName, this.baseUrl).href;\n const response = await fetch(profileUrl);\n if (!response.ok) {\n throw new Error(\n `Failed to load ICC profile ${profileName}: ${response.status} ${response.statusText}`\n );\n }\n return response.blob();\n }\n}\n", "import type { AssetLoader } from '../types/asset-loader';\nimport type { GhostscriptModuleFactory } from '../types/ghostscript';\n\n/**\n * Node.js-specific asset loader implementation.\n * Loads assets from the filesystem relative to the module's location.\n *\n * This loader automatically finds assets relative to the built module,\n * so no configuration is needed in Node.js environments.\n *\n * @example\n * ```typescript\n * // In Node.js, the loader is used automatically when no assetPath is provided\n * const result = await convertToPDFX3(pdfBlob, {\n * outputProfile: 'fogra39'\n * });\n *\n * // Or explicitly:\n * const loader = new NodeAssetLoader();\n * const result = await convertToPDFX3(pdfBlob, {\n * outputProfile: 'fogra39',\n * assetLoader: loader\n * });\n * ```\n */\nexport class NodeAssetLoader implements AssetLoader {\n private moduleDir: string | null = null;\n private gsPath: string | null = null;\n private initPromise: Promise<void> | null = null;\n\n constructor() {\n // Initialization is deferred to first use because we need async imports\n this.initPromise = this.initialize();\n }\n\n private async initialize(): Promise<void> {\n // Dynamic imports for Node.js built-in modules\n // These use /* webpackIgnore: true */ comments to prevent bundlers from processing them\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const moduleLib: any = await import(/* webpackIgnore: true */ 'module');\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const pathLib: any = await import(/* webpackIgnore: true */ 'path');\n\n const createRequire = moduleLib.createRequire || moduleLib.default?.createRequire;\n const requireForESM = createRequire(import.meta.url);\n // gs.js is copied to dist/ alongside the bundle\n this.gsPath = requireForESM.resolve('./gs.js');\n\n const dirname = pathLib.dirname || pathLib.default?.dirname;\n this.moduleDir = dirname(this.gsPath);\n }\n\n private async ensureInitialized(): Promise<void> {\n if (this.initPromise) {\n await this.initPromise;\n this.initPromise = null;\n }\n }\n\n async loadGhostscriptModule(): Promise<GhostscriptModuleFactory> {\n await this.ensureInitialized();\n // Dynamic import for ESM compatibility\n const module = await import(this.gsPath!);\n return module.default || module;\n }\n\n /**\n * Get the path to the WASM file.\n *\n * **Important:** This method must be called after `loadGhostscriptModule()` has completed,\n * as initialization happens lazily during that call. The library's internal usage\n * guarantees this ordering, but if you're using `NodeAssetLoader` directly, ensure\n * you call `loadGhostscriptModule()` first.\n *\n * @throws Error if called before initialization completes\n */\n getWasmPath(): string {\n if (!this.moduleDir) {\n throw new Error(\n 'NodeAssetLoader not initialized. Call loadGhostscriptModule() first and await its completion.'\n );\n }\n return `${this.moduleDir}/gs.wasm`;\n }\n\n async loadICCProfile(profileName: string): Promise<Blob> {\n await this.ensureInitialized();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const fsLib: any = await import(/* webpackIgnore: true */ 'fs');\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const pathLib: any = await import(/* webpackIgnore: true */ 'path');\n\n const join = pathLib.join || pathLib.default?.join;\n const readFileSync = fsLib.readFileSync || fsLib.default?.readFileSync;\n\n const profilePath = join(this.moduleDir!, profileName);\n const data = readFileSync(profilePath);\n return new Blob([data], { type: 'application/vnd.iccprofile' });\n }\n}\n", "/* eslint-disable no-console */\nexport type LogLevel = 'debug' | 'info' | 'warn' | 'error';\n\nexport interface LogEntry {\n timestamp: number;\n level: LogLevel;\n component: string;\n message: string;\n data?: any;\n}\n\nexport class Logger {\n private static globalLogLevel: LogLevel = 'warn';\n\n private static logs: LogEntry[] = [];\n\n private static maxLogs = 1000;\n\n constructor(private component: string) {}\n\n static setLogLevel(level: LogLevel): void {\n Logger.globalLogLevel = level;\n }\n\n static getLogs(): LogEntry[] {\n return [...Logger.logs];\n }\n\n static clearLogs(): void {\n Logger.logs = [];\n }\n\n debug(message: string, data?: any): void {\n this.log('debug', message, data);\n }\n\n info(message: string, data?: any): void {\n this.log('info', message, data);\n }\n\n warn(message: string, data?: any): void {\n this.log('warn', message, data);\n }\n\n error(message: string, data?: any): void {\n this.log('error', message, data);\n }\n\n private log(level: LogLevel, message: string, data?: any): void {\n const levelOrder: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n };\n\n if (levelOrder[level] < levelOrder[Logger.globalLogLevel]) {\n return;\n }\n\n const entry: LogEntry = {\n timestamp: Date.now(),\n level,\n component: this.component,\n message,\n data,\n };\n\n Logger.logs.push(entry);\n\n // Keep logs under the limit\n if (Logger.logs.length > Logger.maxLogs) {\n Logger.logs = Logger.logs.slice(-Logger.maxLogs);\n }\n\n // Console output\n const prefix = `[${new Date().toISOString()}] [${level.toUpperCase()}] [${\n this.component\n }]`;\n const logMessage = data ? `${message} ${JSON.stringify(data)}` : message;\n\n switch (level) {\n case 'debug':\n console.debug(prefix, logMessage);\n break;\n case 'info':\n console.info(prefix, logMessage);\n break;\n case 'warn':\n console.warn(prefix, logMessage);\n break;\n case 'error':\n console.error(prefix, logMessage);\n break;\n default:\n // All log levels handled above\n break;\n }\n }\n}\n", "export class BrowserDetection {\n supportsWebAssembly(): boolean {\n try {\n return (\n typeof WebAssembly === 'object' &&\n typeof WebAssembly.instantiate === 'function'\n );\n } catch {\n return false;\n }\n }\n}\n", "// Wrapper for the Ghostscript WASM module to ensure proper loading\nimport type {\n EmscriptenModule,\n GhostscriptModuleFactory,\n} from '../types/ghostscript';\nimport type { AssetLoader } from '../types/asset-loader';\n\nexport interface GhostscriptModuleOptions {\n /**\n * Whether to suppress Ghostscript's stdout/stderr output.\n * Default: true (silent mode)\n */\n silent?: boolean;\n\n /**\n * Asset loader for loading gs.js and gs.wasm.\n * Required - use BrowserAssetLoader or NodeAssetLoader.\n */\n assetLoader: AssetLoader;\n}\n\nexport default async function createGhostscriptModule(\n options: GhostscriptModuleOptions\n): Promise<EmscriptenModule> {\n const { silent = true, assetLoader } = options;\n\n // Load the Ghostscript module using the provided loader\n const factory = await assetLoader.loadGhostscriptModule();\n const wasmPath = assetLoader.getWasmPath();\n\n // Configure the module to load WASM from the specified location\n const moduleConfig: Record<string, unknown> = {\n locateFile: (filename: string) => {\n if (filename === 'gs.wasm') {\n return wasmPath;\n }\n return filename;\n },\n };\n\n // Suppress Ghostscript stdout/stderr output in silent mode\n if (silent) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n moduleConfig.print = () => {};\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n moduleConfig.printErr = () => {};\n }\n\n const module = await factory(moduleConfig);\n\n return module;\n}\n", "import type { EmscriptenModule } from '../types/ghostscript';\nimport type { AssetLoader } from '../types/asset-loader';\nimport { Logger } from '../utils/logger';\nimport { BrowserDetection } from '../utils/browser-detection';\nimport createGhostscriptModule from '../wasm/ghostscript-module';\n\nexport interface LoaderOptions {\n timeout?: number;\n /**\n * Asset loader for loading plugin assets.\n * Required - use BrowserAssetLoader or NodeAssetLoader.\n */\n assetLoader: AssetLoader;\n}\n\nexport class GhostscriptLoader {\n private static instance: Promise<EmscriptenModule> | null = null;\n\n private static readonly TIMEOUT_MS = 30000;\n\n static async load(options: LoaderOptions): Promise<EmscriptenModule> {\n // If already loaded, return the cached instance\n // (the WASM module is a singleton and assetLoader should be consistent within an app)\n if (this.instance) {\n return this.instance;\n }\n\n this.instance = this.loadInternal(options);\n return this.instance;\n }\n\n private static async loadInternal(\n options: LoaderOptions\n ): Promise<EmscriptenModule> {\n const logger = new Logger('GhostscriptLoader');\n const browser = new BrowserDetection();\n\n // Check browser compatibility\n if (!browser.supportsWebAssembly()) {\n throw new Error('WebAssembly not supported in this browser');\n }\n\n const timeout = options.timeout || this.TIMEOUT_MS;\n\n try {\n logger.info('Loading bundled Ghostscript (AGPL-3.0 licensed)');\n logger.info('Source available at: https://github.com/imgly/plugins');\n return await this.loadWithTimeout(\n () => this.loadFromBundle(options.assetLoader),\n timeout\n );\n } catch (error) {\n logger.error('Ghostscript loading failed', {\n error: (error as Error).message,\n });\n throw new Error(\n `Failed to load Ghostscript: ${(error as Error).message}`\n );\n }\n }\n\n private static async loadFromBundle(\n assetLoader: AssetLoader\n ): Promise<EmscriptenModule> {\n // Use the bundled WASM module with proper configuration\n const logger = new Logger('GhostscriptInit');\n\n try {\n logger.info('Initializing Ghostscript module');\n\n const module = await createGhostscriptModule({ assetLoader });\n\n logger.info('Ghostscript module initialized successfully', {\n version: module.version || 'unknown',\n hasFS: !!module.FS,\n hasCallMain: !!module.callMain,\n });\n\n return module;\n } catch (error) {\n logger.error('Ghostscript initialization failed', { error });\n throw new Error(\n `Ghostscript initialization failed: ${(error as Error).message}`\n );\n }\n }\n\n private static async loadWithTimeout<T>(\n operation: () => Promise<T>,\n timeoutMs: number\n ): Promise<T> {\n return Promise.race([\n operation(),\n new Promise<never>((_, reject) => {\n setTimeout(\n () => reject(new Error(`Loading timeout after ${timeoutMs}ms`)),\n timeoutMs\n );\n }),\n ]);\n }\n\n static reset(): void {\n this.instance = null;\n }\n}\n", "export class BlobUtils {\n static async toUint8Array(blob: Blob): Promise<Uint8Array> {\n if (blob.arrayBuffer) {\n const buffer = await blob.arrayBuffer();\n return new Uint8Array(buffer);\n }\n\n // Fallback for older browsers\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = () => {\n if (reader.result instanceof ArrayBuffer) {\n resolve(new Uint8Array(reader.result));\n } else {\n reject(new Error('Failed to read blob as ArrayBuffer'));\n }\n };\n reader.onerror = () => reject(reader.error);\n reader.readAsArrayBuffer(blob);\n });\n }\n\n static async validatePDF(blob: Blob): Promise<boolean> {\n try {\n const data = await this.toUint8Array(blob);\n\n // Check PDF magic number\n const pdfHeader = new Uint8Array([0x25, 0x50, 0x44, 0x46]); // %PDF\n\n if (data.length < 4) {\n return false;\n }\n\n for (let i = 0; i < 4; i++) {\n if (data[i] !== pdfHeader[i]) {\n return false;\n }\n }\n\n return true;\n } catch {\n return false;\n }\n }\n}\n", "import type { EmscriptenModule, EmscriptenFS } from '../types/ghostscript';\nimport { Logger } from '../utils/logger';\nimport { BlobUtils } from '../utils/blob-utils';\n\nexport interface FileEntry {\n path: string;\n data: Uint8Array;\n cleanup: boolean;\n}\n\nexport class VirtualFileSystem {\n private readonly fs: EmscriptenFS;\n\n private readonly logger: Logger;\n\n private readonly managedFiles: Set<string> = new Set();\n\n private readonly workingDir: string;\n\n constructor(\n private readonly module: EmscriptenModule,\n workingDir = '/tmp/pdfx'\n ) {\n this.fs = module.FS;\n this.logger = new Logger('VirtualFileSystem');\n this.workingDir = workingDir;\n this.initialize();\n }\n\n private initialize(): void {\n try {\n // Create working directory structure (handle existing directories gracefully)\n this.createDirIfNotExists(this.workingDir);\n this.createDirIfNotExists(`${this.workingDir}/input`);\n this.createDirIfNotExists(`${this.workingDir}/output`);\n this.createDirIfNotExists(`${this.workingDir}/profiles`);\n this.createDirIfNotExists(`${this.workingDir}/temp`);\n\n this.logger.info('Virtual filesystem initialized', {\n workingDir: this.workingDir,\n });\n } catch (error) {\n this.logger.error('Failed to initialize virtual filesystem', { error });\n throw new Error(`VFS initialization failed: ${error}`);\n }\n }\n\n private createDirIfNotExists(path: string): void {\n try {\n this.fs.mkdir(path);\n } catch (error: any) {\n // Ignore \"File exists\" errors, re-throw others\n if (error.code !== 'EEXIST') {\n throw error;\n }\n }\n }\n\n async writeBlob(path: string, blob: Blob, managed = true): Promise<void> {\n try {\n const data = await BlobUtils.toUint8Array(blob);\n this.fs.writeFile(path, data);\n\n if (managed) {\n this.managedFiles.add(path);\n }\n\n this.logger.debug('File written', { path, size: data.length });\n } catch (error) {\n this.logger.error('Failed to write blob', { path, error });\n throw new Error(`Failed to write file ${path}: ${error}`);\n }\n }\n\n writeText(path: string, content: string, managed = true): void {\n try {\n this.fs.writeFile(path, content);\n\n if (managed) {\n this.managedFiles.add(path);\n }\n\n this.logger.debug('Text file written', { path, length: content.length });\n } catch (error) {\n this.logger.error('Failed to write text', { path, error });\n throw new Error(`Failed to write text file ${path}: ${error}`);\n }\n }\n\n readFile(path: string): Uint8Array {\n try {\n const data = this.fs.readFile(path) as Uint8Array;\n this.logger.debug('File read', { path, size: data.length });\n return data;\n } catch (error) {\n this.logger.error('Failed to read file', { path, error });\n throw new Error(`Failed to read file ${path}: ${error}`);\n }\n }\n\n exists(path: string): boolean {\n try {\n this.fs.stat(path);\n return true;\n } catch {\n return false;\n }\n }\n\n cleanup(): void {\n let cleanedCount = 0;\n\n for (const path of this.managedFiles) {\n try {\n this.fs.unlink(path);\n cleanedCount++;\n } catch (error) {\n this.logger.warn('Failed to cleanup file', { path, error });\n }\n }\n\n this.managedFiles.clear();\n this.logger.info('Filesystem cleanup completed', { cleanedCount });\n }\n}\n", "import type { PDFX3Options, AssetLoader } from './types';\nimport { GhostscriptLoader } from './core/ghostscript-loader';\nimport { VirtualFileSystem } from './core/virtual-filesystem';\nimport { BlobUtils } from './utils/blob-utils';\n\n/**\n * Try to get a usable base URL from import.meta.url.\n * Returns null if the URL is not usable (e.g., file:// protocol in browser).\n */\nfunction tryGetBaseUrlFromImportMeta(): string | null {\n try {\n // import.meta.url points to the bundled JS file location\n // In Vite: \"http://localhost:5173/node_modules/.vite/deps/...\"\n // In Webpack 5: \"file:///path/to/dist/index.mjs\" (not usable in browser)\n const url = import.meta.url;\n if (!url) return null;\n\n // file:// URLs don't work for dynamic imports in browsers\n if (url.startsWith('file://')) return null;\n\n // Extract the directory from the URL\n const lastSlash = url.lastIndexOf('/');\n if (lastSlash === -1) return null;\n\n return url.substring(0, lastSlash + 1);\n } catch {\n return null;\n }\n}\n\n/**\n * Get the appropriate AssetLoader based on options and environment.\n */\nasync function getAssetLoader(options: PDFX3Options): Promise<AssetLoader> {\n // 1. Explicit loader takes precedence\n if (options.assetLoader) {\n return options.assetLoader;\n }\n\n // 2. assetPath creates a BrowserAssetLoader\n if (options.assetPath) {\n const { BrowserAssetLoader } = await import('./loaders/browser-loader');\n return new BrowserAssetLoader(options.assetPath);\n }\n\n // 3. Auto-detect environment\n const isBrowser =\n typeof window !== 'undefined' || typeof document !== 'undefined';\n\n if (isBrowser) {\n // Try to auto-detect base URL from import.meta.url (works in Vite)\n const autoBaseUrl = tryGetBaseUrlFromImportMeta();\n if (autoBaseUrl) {\n const { BrowserAssetLoader } = await import('./loaders/browser-loader');\n return new BrowserAssetLoader(autoBaseUrl);\n }\n\n // Can't auto-detect - require explicit configuration (Webpack 5, Angular, etc.)\n throw new Error(\n 'In browser environments with Webpack 5 or Angular, you must provide the `assetPath` option.\\n\\n' +\n 'Example:\\n' +\n ' convertToPDFX3(blob, {\\n' +\n \" outputProfile: 'fogra39',\\n\" +\n \" assetPath: '/assets/print-ready-pdfs/'\\n\" +\n ' });\\n\\n' +\n 'See: https://github.com/imgly/plugins/tree/main/packages/plugin-print-ready-pdfs-web#bundler-setup-webpack-5--angular'\n );\n }\n\n // Node.js - use NodeAssetLoader\n const { NodeAssetLoader } = await import('./loaders/node-loader');\n return new NodeAssetLoader();\n}\n\n/**\n * PDF/X-3 conversion function\n * Converts RGB PDF(s) to PDF/X-3 format using specified output profile\n *\n * @overload\n * @param inputPDF Single PDF blob to convert\n * @param options Conversion configuration\n * @returns Promise resolving to converted PDF blob\n *\n * @overload\n * @param inputPDFs Array of PDF blobs to convert\n * @param options Conversion configuration\n * @returns Promise resolving to array of converted PDF blobs\n */\nexport function convertToPDFX3(\n inputPDF: Blob,\n options: PDFX3Options\n): Promise<Blob>;\nexport function convertToPDFX3(\n inputPDFs: Blob[],\n options: PDFX3Options\n): Promise<Blob[]>;\nexport async function convertToPDFX3(\n input: Blob | Blob[],\n options: PDFX3Options\n): Promise<Blob | Blob[]> {\n // Handle array input (batch processing)\n if (Array.isArray(input)) {\n if (input.length === 0) {\n return [];\n }\n\n // Process each blob sequentially to avoid overwhelming the WASM module\n const results: Blob[] = [];\n for (let i = 0; i < input.length; i++) {\n try {\n // eslint-disable-next-line no-await-in-loop\n const converted = await convertToPDFX3Single(input[i], options);\n results.push(converted);\n } catch (error) {\n throw new Error(\n `Failed to convert PDF ${i + 1} of ${input.length}: ${\n error instanceof Error ? error.message : String(error)\n }`\n );\n }\n }\n return results;\n }\n\n // Handle single blob input\n return convertToPDFX3Single(input, options);\n}\n\n/**\n * Internal function to convert a single PDF\n */\nasync function convertToPDFX3Single(\n inputPDF: Blob,\n options: PDFX3Options\n): Promise<Blob> {\n // Validate inputs\n if (!(inputPDF instanceof Blob)) {\n throw new Error('Input must be a Blob');\n }\n\n if (inputPDF.size === 0) {\n throw new Error('Input PDF is empty');\n }\n\n if (inputPDF.size > 100 * 1024 * 1024) {\n throw new Error(\n `Input PDF too large (${inputPDF.size} bytes). Maximum: 100MB`\n );\n }\n\n // Validate output profile is provided\n if (!options.outputProfile) {\n throw new Error(\n 'outputProfile is required. Must be one of: \"gracol\", \"fogra39\", \"srgb\", \"custom\"'\n );\n }\n\n // Validate output profile value\n const validProfiles = ['gracol', 'fogra39', 'srgb', 'custom'];\n if (!validProfiles.includes(options.outputProfile)) {\n throw new Error(\n `Invalid outputProfile \"${\n options.outputProfile\n }\". Must be one of: ${validProfiles.join(', ')}`\n );\n }\n\n // Validate custom profile requirement\n if (options.outputProfile === 'custom' && !options.customProfile) {\n throw new Error(\n 'customProfile Blob is required when outputProfile is \"custom\"'\n );\n }\n\n // Validate custom profile if provided\n if (options.customProfile && !(options.customProfile instanceof Blob)) {\n throw new Error('customProfile must be a Blob');\n }\n\n // Validate PDF format\n const isValidPDF = await BlobUtils.validatePDF(inputPDF);\n if (!isValidPDF) {\n throw new Error('Invalid PDF format');\n }\n\n // Get the asset loader for this conversion\n const assetLoader = await getAssetLoader(options);\n\n // Load Ghostscript with the asset loader\n const module = await GhostscriptLoader.load({ assetLoader });\n const vfs = new VirtualFileSystem(module);\n\n try {\n // Setup file paths\n const inputPath = '/tmp/input.pdf';\n const outputPath = '/tmp/output.pdf';\n const pdfxDefPath = '/tmp/pdfx_def.ps';\n const customProfilePath = '/tmp/custom.icc';\n\n // Write input PDF to virtual filesystem\n await vfs.writeBlob(inputPath, inputPDF);\n\n // Write ICC profiles to virtual filesystem\n if (options.outputProfile === 'custom' && options.customProfile) {\n await vfs.writeBlob(customProfilePath, options.customProfile);\n } else if (options.outputProfile !== 'custom') {\n // Load the bundled ICC profile using the asset loader\n const profileInfo =\n PROFILE_PRESETS[options.outputProfile as keyof typeof PROFILE_PRESETS];\n const profilePath = `/tmp/${profileInfo.file}`;\n\n const profileBlob = await assetLoader.loadICCProfile(profileInfo.file);\n await vfs.writeBlob(profilePath, profileBlob);\n }\n\n // Determine ICC profile path and metadata for Ghostscript\n let iccProfilePath: string;\n let outputConditionIdentifier: string;\n let outputCondition: string;\n\n if (options.outputProfile === 'custom') {\n iccProfilePath = customProfilePath;\n // Use custom values or defaults\n outputConditionIdentifier =\n options.outputConditionIdentifier || 'Custom Profile';\n outputCondition = options.outputCondition || 'Custom ICC Profile';\n } else {\n const preset =\n PROFILE_PRESETS[options.outputProfile as keyof typeof PROFILE_PRESETS];\n iccProfilePath = `/tmp/${preset.file}`;\n // Allow overriding preset values\n outputConditionIdentifier =\n options.outputConditionIdentifier || preset.identifier;\n outputCondition = options.outputCondition || preset.info;\n }\n\n // Read ICC profile data and convert to hex for embedding\n // WASM doesn't support (file) (r) file syntax, so we embed directly\n const iccData = vfs.readFile(iccProfilePath);\n const iccHex = Array.from(iccData)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n\n // Determine color conversion strategy based on profile type\n // ICC profile color space is at bytes 16-19\n // 'RGB ' = 0x52474220, 'CMYK' = 0x434D594B\n const colorSpaceBytes = iccData.slice(16, 20);\n const colorSpaceStr = String.fromCharCode(...colorSpaceBytes);\n const isCMYKProfile = colorSpaceStr.trim() === 'CMYK';\n\n // Generate PDF/X-3 definition with ICC profile hex data\n const pdfxDefinition = generatePDFXDef(\n options,\n iccHex,\n outputConditionIdentifier,\n outputCondition\n );\n vfs.writeText(pdfxDefPath, pdfxDefinition);\n\n // Execute Ghostscript conversion\n // For CMYK profiles, convert all colors to CMYK using the ICC profile\n // Note: Transparency flattening will rasterize transparent content\n const gsArgs = [\n '-dBATCH',\n '-dNOPAUSE',\n '-sDEVICE=pdfwrite',\n '-dCompatibilityLevel=1.4',\n // Disable PDF 1.5+ features to avoid warnings with PDF 1.4 compatibility\n '-dWriteObjStms=false',\n '-dWriteXRefStm=false',\n // PDF/X-3 settings\n '-dPDFSETTINGS=/prepress',\n '-dSetPageSize=false',\n '-dAutoRotatePages=/None',\n ];\n\n // Flatten transparency for PDF/X-3 compliance (default: true)\n // HaveTransparency=false tells Ghostscript the target viewer cannot handle\n // PDF 1.4 transparency, so pages with transparency are converted to bitmaps\n const shouldFlattenTransparency = options.flattenTransparency !== false;\n if (shouldFlattenTransparency) {\n gsArgs.push('-dHaveTransparency=false');\n }\n\n // Add color conversion for CMYK profiles\n if (isCMYKProfile) {\n gsArgs.push(\n '-sColorConversionStrategy=CMYK',\n '-dProcessColorModel=/DeviceCMYK',\n '-dConvertCMYKImagesToRGB=false'\n );\n } else {\n // For RGB profiles, we still need a color conversion strategy\n gsArgs.push('-sColorConversionStrategy=RGB');\n }\n\n // Add output file and input files\n gsArgs.push(`-sOutputFile=${outputPath}`, pdfxDefPath, inputPath);\n\n const exitCode = await module.callMain(gsArgs);\n if (exitCode !== 0) {\n throw new Error(\n `Ghostscript conversion failed with exit code ${exitCode}`\n );\n }\n\n // Read output\n const outputData = vfs.readFile(outputPath);\n // Create a copy of the data to ensure it's an ArrayBuffer, not SharedArrayBuffer\n const outputBuffer = new Uint8Array(outputData);\n const outputPDF = new Blob([outputBuffer], { type: 'application/pdf' });\n\n // Cleanup\n vfs.cleanup();\n\n return outputPDF;\n } catch (error) {\n vfs.cleanup();\n throw error;\n }\n}\n\n// Profile presets from the spec\nconst PROFILE_PRESETS = {\n gracol: {\n file: 'GRACoL2013_CRPC6.icc',\n identifier: 'CGATS 21.2',\n info: 'GRACoL 2013 CRPC6',\n },\n fogra39: {\n file: 'ISOcoated_v2_eci.icc',\n identifier: 'FOGRA39',\n info: 'ISO Coated v2 (ECI)',\n },\n srgb: {\n file: 'sRGB_IEC61966-2-1.icc',\n identifier: 'sRGB IEC61966-2.1',\n info: 'sRGB IEC61966-2.1',\n },\n};\n\nfunction generatePDFXDef(\n options: PDFX3Options,\n iccProfileHex: string,\n outputConditionIdentifier: string,\n outputCondition: string\n): string {\n return `%!\n% PDF/X-3 Definition File\n[ /Title (${options.title || 'Untitled'}) /DOCINFO pdfmark\n[ /Trapped /False /DOCINFO pdfmark\n\n% Set PDF/X-3 conformance\n[ /GTS_PDFXVersion (PDF/X-3:2003) /GTS_PDFXConformance (PDF/X-3:2003) /DOCINFO pdfmark\n\n% Set TrimBox to match MediaBox for all pages (required for PDF/X)\n[/TrimBox [0 0 0 0] /PAGE pdfmark\n\n% Embed ICC profile as hex stream\n[/_objdef {icc_PDFX} /type /stream /OBJ pdfmark\n[{icc_PDFX} <</N 4>> /PUT pdfmark\n[{icc_PDFX} <${iccProfileHex}> /PUT pdfmark\n\n% Define OutputIntent with embedded ICC profile\n[/_objdef {OutputIntent_PDFX} /type /dict /OBJ pdfmark\n[{OutputIntent_PDFX} <<\n /Type /OutputIntent\n /S /GTS_PDFX\n /OutputCondition (${outputCondition})\n /OutputConditionIdentifier (${outputConditionIdentifier})\n /RegistryName (http://www.color.org)\n /DestOutputProfile {icc_PDFX}\n>> /PUT pdfmark\n\n% Add OutputIntent to Catalog\n[{Catalog} <</OutputIntents [{OutputIntent_PDFX}]>> /PUT pdfmark`;\n}\n", "/**\n * @imgly/plugin-pdfx-web - Print-Ready PDF conversion for CE.SDK\n * Node.js-specific entry point\n *\n * This entry point is optimized for Node.js environments:\n * - Uses filesystem APIs to load assets\n * - No browser-specific code included\n * - Assets are resolved relative to the module location\n *\n * IMPORTANT: This package includes Ghostscript WASM binaries licensed under AGPL-3.0.\n * Commercial users must ensure license compliance. See README.md for details.\n */\n\n// Export the main conversion function\nexport { convertToPDFX3 } from './pdfx';\n\n// Export NodeAssetLoader for Node.js environments\nexport { NodeAssetLoader } from './loaders/node-loader';\n\n// Export Logger for controlling log verbosity\nexport { Logger } from './utils/logger';\n\n// Export types for TypeScript users\nexport type { PDFX3Options, AssetLoader } from './types';\nexport type { LogLevel } from './utils/logger';\n"],
5
- "m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2C,EACAf,EACAC,EACQ,CACR,MAAO;AAAA;AAAA,YAEG7B,EAAQ,OAAS,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAYxB2C,CAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAONd,CAAe;AAAA,gCACLD,CAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iEAOzD,CCvWAgB",
6
- "names": ["normalizeAssetPath", "path", "normalizedPath", "init_asset_path", "__esmMin", "browser_loader_exports", "__export", "BrowserAssetLoader", "init_browser_loader", "__esmMin", "init_asset_path", "assetPath", "normalizeAssetPath", "module", "profileName", "profileUrl", "response", "node_loader_exports", "__export", "NodeAssetLoader", "init_node_loader", "__esmMin", "moduleLib", "pathLib", "requireForESM", "dirname", "module", "profileName", "fsLib", "join", "readFileSync", "profilePath", "data", "Logger", "_Logger", "component", "level", "message", "data", "levelOrder", "entry", "prefix", "logMessage", "BrowserDetection", "createGhostscriptModule", "options", "silent", "assetLoader", "factory", "wasmPath", "moduleConfig", "filename", "GhostscriptLoader", "options", "logger", "Logger", "BrowserDetection", "timeout", "error", "assetLoader", "module", "createGhostscriptModule", "operation", "timeoutMs", "_", "reject", "BlobUtils", "blob", "buffer", "resolve", "reject", "reader", "data", "pdfHeader", "VirtualFileSystem", "module", "workingDir", "Logger", "error", "path", "blob", "managed", "data", "BlobUtils", "content", "cleanedCount", "tryGetBaseUrlFromImportMeta", "url", "lastSlash", "getAssetLoader", "options", "BrowserAssetLoader", "autoBaseUrl", "NodeAssetLoader", "convertToPDFX3", "input", "results", "i", "converted", "convertToPDFX3Single", "error", "inputPDF", "validProfiles", "BlobUtils", "assetLoader", "module", "GhostscriptLoader", "vfs", "VirtualFileSystem", "inputPath", "outputPath", "pdfxDefPath", "customProfilePath", "profileInfo", "PROFILE_PRESETS", "profilePath", "profileBlob", "iccProfilePath", "outputConditionIdentifier", "outputCondition", "preset", "iccData", "iccHex", "b", "colorSpaceBytes", "isCMYKProfile", "pdfxDefinition", "generatePDFXDef", "gsArgs", "exitCode", "outputData", "outputBuffer", "outputPDF", "iccProfileHex", "init_node_loader"]
7
- }
@@ -1,56 +0,0 @@
1
- import type { GhostscriptModuleFactory } from './ghostscript';
2
-
3
- /**
4
- * Interface for loading plugin assets (gs.js, gs.wasm, ICC profiles).
5
- * Implement this interface to customize how assets are loaded in your environment.
6
- *
7
- * Built-in implementations:
8
- * - `BrowserAssetLoader`: For browser environments, loads assets via HTTP
9
- * - `NodeAssetLoader`: For Node.js environments, loads assets from the filesystem
10
- *
11
- * @example Custom loader for CDN
12
- * ```typescript
13
- * class CDNAssetLoader implements AssetLoader {
14
- * private cdnBase = 'https://cdn.example.com/pdf-plugin/v1.1.2/';
15
- *
16
- * async loadGhostscriptModule() {
17
- * const module = await import(this.cdnBase + 'gs.js');
18
- * return module.default;
19
- * }
20
- *
21
- * getWasmPath() {
22
- * return this.cdnBase + 'gs.wasm';
23
- * }
24
- *
25
- * async loadICCProfile(name: string) {
26
- * const response = await fetch(this.cdnBase + name);
27
- * return response.blob();
28
- * }
29
- * }
30
- * ```
31
- */
32
- export interface AssetLoader {
33
- /**
34
- * Load the Ghostscript JavaScript module.
35
- * @returns The Ghostscript module factory function
36
- */
37
- loadGhostscriptModule(): Promise<GhostscriptModuleFactory>;
38
-
39
- /**
40
- * Get the URL/path to the WASM file for Emscripten's locateFile callback.
41
- *
42
- * **Note:** This method is called synchronously by Emscripten after `loadGhostscriptModule()`
43
- * completes. Implementations should ensure any required initialization happens in
44
- * `loadGhostscriptModule()` so that `getWasmPath()` can return immediately.
45
- *
46
- * @returns URL or path to gs.wasm
47
- */
48
- getWasmPath(): string;
49
-
50
- /**
51
- * Load an ICC profile by name.
52
- * @param profileName - e.g., 'GRACoL2013_CRPC6.icc'
53
- * @returns The ICC profile as a Blob
54
- */
55
- loadICCProfile(profileName: string): Promise<Blob>;
56
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * Type definitions for the Ghostscript WASM module.
3
- * Based on Emscripten module types with Ghostscript-specific extensions.
4
- */
5
-
6
- /**
7
- * Emscripten filesystem interface for file operations.
8
- */
9
- export interface EmscriptenFS {
10
- mkdir(path: string): void;
11
- writeFile(path: string, data: string | Uint8Array): void;
12
- readFile(path: string): Uint8Array;
13
- stat(path: string): { size: number };
14
- unlink(path: string): void;
15
- }
16
-
17
- /**
18
- * Ghostscript WASM module interface.
19
- * Extends Emscripten module with Ghostscript-specific methods.
20
- */
21
- export interface EmscriptenModule {
22
- /** Emscripten virtual filesystem */
23
- FS: EmscriptenFS;
24
-
25
- /** Call the main() function with arguments */
26
- callMain(args: string[]): Promise<number>;
27
-
28
- /** Optional version string */
29
- version?: string;
30
-
31
- /** Print function for stdout */
32
- print?: (text: string) => void;
33
-
34
- /** Print function for stderr */
35
- printErr?: (text: string) => void;
36
-
37
- /** Custom locateFile function for WASM loading */
38
- locateFile?: (filename: string) => string;
39
- }
40
-
41
- /**
42
- * Factory function returned by the Ghostscript JavaScript module.
43
- * Creates an initialized EmscriptenModule instance.
44
- */
45
- export type GhostscriptModuleFactory = (
46
- config?: Record<string, unknown>
47
- ) => Promise<EmscriptenModule>;
@@ -1,3 +0,0 @@
1
- export * from './ghostscript';
2
- export * from './pdfx';
3
- export * from './asset-loader';
@@ -1,46 +0,0 @@
1
- import type { AssetLoader } from './asset-loader';
2
-
3
- export interface PDFX3Options {
4
- // Required
5
- outputProfile: 'gracol' | 'fogra39' | 'srgb' | 'custom';
6
- customProfile?: Blob; // Only if outputProfile is 'custom'
7
-
8
- // Optional (with sensible defaults)
9
- title?: string; // Document title (default: use existing)
10
- outputConditionIdentifier?: string; // OutputIntent identifier (e.g., "FOGRA39")
11
- outputCondition?: string; // Human-readable condition description
12
- flattenTransparency?: boolean; // Force transparency flattening (default: true for PDF/X-3 compliance)
13
-
14
- /**
15
- * Asset loader instance for loading plugin assets.
16
- *
17
- * If not provided:
18
- * - Browser: Must provide `assetPath` instead
19
- * - Node.js: Uses NodeAssetLoader automatically
20
- *
21
- * Provide a custom AssetLoader implementation for advanced scenarios
22
- * like loading assets from a CDN, custom storage, or service worker cache.
23
- *
24
- * @example
25
- * ```typescript
26
- * const loader = new BrowserAssetLoader('/assets/');
27
- * const result = await convertToPDFX3(blob, {
28
- * outputProfile: 'fogra39',
29
- * assetLoader: loader
30
- * });
31
- * ```
32
- */
33
- assetLoader?: AssetLoader;
34
-
35
- /**
36
- * Base URL path where plugin assets (gs.js, gs.wasm, *.icc) are served from.
37
- * Shorthand for creating a BrowserAssetLoader.
38
- *
39
- * Required in browser environments unless `assetLoader` is provided.
40
- * Ignored in Node.js environments.
41
- *
42
- * @example '/assets/print-ready-pdfs/'
43
- * @example 'https://cdn.example.com/libs/print-ready-pdfs/'
44
- */
45
- assetPath?: string;
46
- }