canvu-react 0.4.71 → 0.4.73
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.
- package/dist/{asset-hydration-BeWWxiBq.d.cts → asset-hydration-6swZ6ciN.d.cts} +1 -1
- package/dist/{asset-hydration-CLoDkZDh.d.ts → asset-hydration-P0M5hn-p.d.ts} +1 -1
- package/dist/chatbot.d.cts +2 -2
- package/dist/chatbot.d.ts +2 -2
- package/dist/index.cjs +87 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +87 -6
- package/dist/index.js.map +1 -1
- package/dist/{raster-image-canvas-Byq087t9.d.cts → raster-image-canvas-ByaCKEVw.d.cts} +2 -0
- package/dist/{raster-image-canvas-BqBgE8C-.d.ts → raster-image-canvas-D3ZrySjr.d.ts} +2 -0
- package/dist/react.cjs +182 -33
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +35 -8
- package/dist/react.d.ts +35 -8
- package/dist/react.js +182 -33
- package/dist/react.js.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/{types-D_cQxUug.d.ts → types-C5wxwquF.d.ts} +1 -1
- package/dist/{types-f8d-2-6N.d.cts → types-DOUBapS4.d.cts} +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { V as VectorSceneItem } from './types-fJNwEnHf.cjs';
|
|
2
|
-
import { a as VectorViewportAssetStore } from './raster-image-canvas-
|
|
2
|
+
import { a as VectorViewportAssetStore } from './raster-image-canvas-ByaCKEVw.cjs';
|
|
3
3
|
|
|
4
4
|
declare class IndexedDbImageStore {
|
|
5
5
|
private dbPromise;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { V as VectorSceneItem } from './types-fJNwEnHf.js';
|
|
2
|
-
import { a as VectorViewportAssetStore } from './raster-image-canvas-
|
|
2
|
+
import { a as VectorViewportAssetStore } from './raster-image-canvas-D3ZrySjr.js';
|
|
3
3
|
|
|
4
4
|
declare class IndexedDbImageStore {
|
|
5
5
|
private dbPromise;
|
package/dist/chatbot.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { c as CanvasPlugin } from './types-
|
|
2
|
+
import { c as CanvasPlugin } from './types-DOUBapS4.cjs';
|
|
3
3
|
import 'react';
|
|
4
4
|
import './types-fJNwEnHf.cjs';
|
|
5
5
|
import './shape-builders-DzhCOuzo.cjs';
|
|
6
|
-
import './raster-image-canvas-
|
|
6
|
+
import './raster-image-canvas-ByaCKEVw.cjs';
|
|
7
7
|
import './link-item-BMV3VUCr.cjs';
|
|
8
8
|
import './types-DqsqQQVf.cjs';
|
|
9
9
|
|
package/dist/chatbot.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { c as CanvasPlugin } from './types-
|
|
2
|
+
import { c as CanvasPlugin } from './types-C5wxwquF.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
import './types-fJNwEnHf.js';
|
|
5
5
|
import './shape-builders-xG3A66sv.js';
|
|
6
|
-
import './raster-image-canvas-
|
|
6
|
+
import './raster-image-canvas-D3ZrySjr.js';
|
|
7
7
|
import './link-item-COoNNvCu.js';
|
|
8
8
|
import './types-BXa2CIrc.js';
|
|
9
9
|
|
package/dist/index.cjs
CHANGED
|
@@ -225,7 +225,8 @@ function getPdfJs() {
|
|
|
225
225
|
}
|
|
226
226
|
return pdfjsPromise;
|
|
227
227
|
}
|
|
228
|
-
async function renderPageToCanvas(page, scale) {
|
|
228
|
+
async function renderPageToCanvas(page, scale, signal) {
|
|
229
|
+
throwIfAborted(signal);
|
|
229
230
|
const raw = page.getViewport({ scale: 1 });
|
|
230
231
|
const adjustedScale = Math.round(raw.width * scale) / raw.width;
|
|
231
232
|
const viewport = page.getViewport({ scale: adjustedScale });
|
|
@@ -238,22 +239,48 @@ async function renderPageToCanvas(page, scale) {
|
|
|
238
239
|
if (!ctx) throw new Error("Canvas 2D context unavailable");
|
|
239
240
|
ctx.imageSmoothingEnabled = true;
|
|
240
241
|
ctx.imageSmoothingQuality = "high";
|
|
241
|
-
|
|
242
|
+
const renderTask = page.render({ canvas, viewport });
|
|
243
|
+
if (signal) {
|
|
244
|
+
const abortRender = () => {
|
|
245
|
+
renderTask.cancel();
|
|
246
|
+
};
|
|
247
|
+
signal.addEventListener("abort", abortRender, { once: true });
|
|
248
|
+
try {
|
|
249
|
+
await renderTask.promise;
|
|
250
|
+
} catch (error) {
|
|
251
|
+
if (signal.aborted) throw createAbortError();
|
|
252
|
+
throw error;
|
|
253
|
+
} finally {
|
|
254
|
+
signal.removeEventListener("abort", abortRender);
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
await renderTask.promise;
|
|
258
|
+
}
|
|
259
|
+
throwIfAborted(signal);
|
|
242
260
|
return { canvas, width: w, height: h };
|
|
243
261
|
}
|
|
262
|
+
function createAbortError() {
|
|
263
|
+
return new DOMException("Aborted", "AbortError");
|
|
264
|
+
}
|
|
265
|
+
function throwIfAborted(signal) {
|
|
266
|
+
if (signal?.aborted) {
|
|
267
|
+
throw createAbortError();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
244
270
|
function normalizePdfPageNumbers(pageNumbers, pageCount) {
|
|
245
271
|
if (!pageNumbers || pageNumbers.length === 0) {
|
|
246
272
|
return Array.from({ length: pageCount }, (_, index) => index + 1);
|
|
247
273
|
}
|
|
248
274
|
return [...new Set(pageNumbers)].filter((pageNumber) => pageNumber >= 1 && pageNumber <= pageCount).sort((left, right) => left - right);
|
|
249
275
|
}
|
|
250
|
-
async function runWithConcurrency(items, concurrency, execute) {
|
|
276
|
+
async function runWithConcurrency(items, concurrency, execute, signal) {
|
|
251
277
|
const results = new Array(items.length);
|
|
252
278
|
let nextIndex = 0;
|
|
253
279
|
const workerCount = Math.max(1, Math.min(concurrency, items.length));
|
|
254
280
|
await Promise.all(
|
|
255
281
|
Array.from({ length: workerCount }, async () => {
|
|
256
282
|
while (nextIndex < items.length) {
|
|
283
|
+
throwIfAborted(signal);
|
|
257
284
|
const currentIndex = nextIndex;
|
|
258
285
|
nextIndex += 1;
|
|
259
286
|
const item = items[currentIndex];
|
|
@@ -261,6 +288,7 @@ async function runWithConcurrency(items, concurrency, execute) {
|
|
|
261
288
|
continue;
|
|
262
289
|
}
|
|
263
290
|
results[currentIndex] = await execute(item);
|
|
291
|
+
throwIfAborted(signal);
|
|
264
292
|
}
|
|
265
293
|
})
|
|
266
294
|
);
|
|
@@ -270,9 +298,49 @@ async function loadPdfToStore(file, store, options) {
|
|
|
270
298
|
const scale = options?.scale ?? 1.5;
|
|
271
299
|
const pageConcurrency = options?.pageConcurrency ?? 2;
|
|
272
300
|
const storeThumbnails = options?.storeThumbnails ?? false;
|
|
301
|
+
const signal = options?.signal;
|
|
302
|
+
throwIfAborted(signal);
|
|
273
303
|
const pdfjs = await getPdfJs();
|
|
304
|
+
throwIfAborted(signal);
|
|
274
305
|
const arrayBuffer = await file.arrayBuffer();
|
|
275
|
-
|
|
306
|
+
throwIfAborted(signal);
|
|
307
|
+
const loadingTask = pdfjs.getDocument({ data: arrayBuffer });
|
|
308
|
+
if (signal) {
|
|
309
|
+
const abortLoading = () => {
|
|
310
|
+
void loadingTask.destroy();
|
|
311
|
+
};
|
|
312
|
+
signal.addEventListener("abort", abortLoading, { once: true });
|
|
313
|
+
try {
|
|
314
|
+
const pdf2 = await loadingTask.promise;
|
|
315
|
+
signal.removeEventListener("abort", abortLoading);
|
|
316
|
+
return await loadPdfDocumentToStore(pdf2, store, {
|
|
317
|
+
scale,
|
|
318
|
+
pageNumbers: options?.pageNumbers,
|
|
319
|
+
pageConcurrency,
|
|
320
|
+
storeThumbnails,
|
|
321
|
+
signal,
|
|
322
|
+
onPageStored: options?.onPageStored
|
|
323
|
+
});
|
|
324
|
+
} catch (error) {
|
|
325
|
+
if (signal.aborted) throw createAbortError();
|
|
326
|
+
throw error;
|
|
327
|
+
} finally {
|
|
328
|
+
signal.removeEventListener("abort", abortLoading);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const pdf = await loadingTask.promise;
|
|
332
|
+
return await loadPdfDocumentToStore(pdf, store, {
|
|
333
|
+
scale,
|
|
334
|
+
pageNumbers: options?.pageNumbers,
|
|
335
|
+
pageConcurrency,
|
|
336
|
+
storeThumbnails,
|
|
337
|
+
onPageStored: options?.onPageStored
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
async function loadPdfDocumentToStore(pdf, store, options) {
|
|
341
|
+
const { pageConcurrency, scale, signal } = options;
|
|
342
|
+
const storeThumbnails = options.storeThumbnails ?? false;
|
|
343
|
+
throwIfAborted(signal);
|
|
276
344
|
const pageNumbers = normalizePdfPageNumbers(options?.pageNumbers, pdf.numPages);
|
|
277
345
|
const bufferedResults = /* @__PURE__ */ new Map();
|
|
278
346
|
let nextEmitIndex = 0;
|
|
@@ -287,7 +355,9 @@ async function loadPdfToStore(file, store, options) {
|
|
|
287
355
|
if (!bufferedResult) break;
|
|
288
356
|
bufferedResults.delete(nextPageNumber);
|
|
289
357
|
nextEmitIndex += 1;
|
|
358
|
+
throwIfAborted(signal);
|
|
290
359
|
await options?.onPageStored?.(bufferedResult);
|
|
360
|
+
throwIfAborted(signal);
|
|
291
361
|
}
|
|
292
362
|
};
|
|
293
363
|
const nextChain = emitChain.then(run, run);
|
|
@@ -299,11 +369,20 @@ async function loadPdfToStore(file, store, options) {
|
|
|
299
369
|
pageNumbers,
|
|
300
370
|
pageConcurrency,
|
|
301
371
|
async (pageNumber) => {
|
|
372
|
+
throwIfAborted(signal);
|
|
302
373
|
const page = await pdf.getPage(pageNumber);
|
|
303
|
-
|
|
374
|
+
throwIfAborted(signal);
|
|
375
|
+
const { canvas, width, height } = await renderPageToCanvas(
|
|
376
|
+
page,
|
|
377
|
+
scale,
|
|
378
|
+
signal
|
|
379
|
+
);
|
|
380
|
+
throwIfAborted(signal);
|
|
304
381
|
const mime = "image/png";
|
|
305
382
|
const pageBlob = await encodeCanvasToBlob(canvas, { mimeType: mime });
|
|
383
|
+
throwIfAborted(signal);
|
|
306
384
|
const blobId = await store.storeOriginal(pageBlob);
|
|
385
|
+
throwIfAborted(signal);
|
|
307
386
|
const thumbnailBlobId = storeThumbnails ? await (async () => {
|
|
308
387
|
const thumbScale = Math.min(1, 256 / Math.max(width, height));
|
|
309
388
|
const tw = Math.max(1, Math.round(width * thumbScale));
|
|
@@ -320,6 +399,7 @@ async function loadPdfToStore(file, store, options) {
|
|
|
320
399
|
const thumbBlob = await encodeCanvasToBlob(thumbCanvas, {
|
|
321
400
|
mimeType: mime
|
|
322
401
|
});
|
|
402
|
+
throwIfAborted(signal);
|
|
323
403
|
return await store.storeThumbnail(thumbBlob);
|
|
324
404
|
})() : "";
|
|
325
405
|
const pageResult = {
|
|
@@ -331,7 +411,8 @@ async function loadPdfToStore(file, store, options) {
|
|
|
331
411
|
};
|
|
332
412
|
await queuePageEmission(pageResult);
|
|
333
413
|
return pageResult;
|
|
334
|
-
}
|
|
414
|
+
},
|
|
415
|
+
signal
|
|
335
416
|
);
|
|
336
417
|
}
|
|
337
418
|
|