fix(build): align TypeScript and test imports with NodeNext builds and safely copy Uint8Array inputs in browser processing
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartpreview',
|
||||
version: '1.1.1',
|
||||
description: 'A library for generating efficient JPEG previews from PDFs with support for Node.js and browser environments'
|
||||
}
|
||||
@@ -146,7 +146,7 @@ export class WebPdfProcessor implements IWebPdfProcessor {
|
||||
}
|
||||
|
||||
if (input instanceof Uint8Array) {
|
||||
return input.buffer.slice(input.byteOffset, input.byteOffset + input.byteLength);
|
||||
return this.uint8ArrayToArrayBuffer(input);
|
||||
}
|
||||
|
||||
if (input instanceof File || input instanceof Blob) {
|
||||
@@ -420,4 +420,10 @@ export class WebPdfProcessor implements IWebPdfProcessor {
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private uint8ArrayToArrayBuffer(input: Uint8Array): ArrayBuffer {
|
||||
const arrayBuffer = new ArrayBuffer(input.byteLength);
|
||||
new Uint8Array(arrayBuffer).set(input);
|
||||
return arrayBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ export class SmartPreview {
|
||||
if (input instanceof ArrayBuffer) {
|
||||
buffer = input;
|
||||
} else if (input instanceof Uint8Array) {
|
||||
buffer = input.buffer.slice(input.byteOffset, input.byteOffset + input.byteLength);
|
||||
buffer = this.uint8ArrayToArrayBuffer(input);
|
||||
} else if (input instanceof File || input instanceof Blob) {
|
||||
// Read first few bytes to detect format
|
||||
const headerBlob = input.slice(0, 8);
|
||||
@@ -299,4 +299,10 @@ export class SmartPreview {
|
||||
await instance.init();
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
private uint8ArrayToArrayBuffer(input: Uint8Array): ArrayBuffer {
|
||||
const arrayBuffer = new ArrayBuffer(input.byteLength);
|
||||
new Uint8Array(arrayBuffer).set(input);
|
||||
return arrayBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user