canvu-react 0.4.70 → 0.4.72
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-D2xaUoAT.d.cts → asset-hydration-6swZ6ciN.d.cts} +1 -1
- package/dist/{asset-hydration-D9eThWse.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 +139 -8
- 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 +139 -8
- package/dist/index.js.map +1 -1
- package/dist/{raster-image-canvas-nK9kM9UJ.d.cts → raster-image-canvas-ByaCKEVw.d.cts} +35 -1
- package/dist/{raster-image-canvas-CCOmB4NY.d.ts → raster-image-canvas-D3ZrySjr.d.ts} +35 -1
- package/dist/react.cjs +178 -15
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +13 -6
- package/dist/react.d.ts +13 -6
- package/dist/react.js +178 -15
- package/dist/react.js.map +1 -1
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/realtime.js.map +1 -1
- package/dist/{types-CMuEaiM7.d.ts → types-C5wxwquF.d.ts} +1 -1
- package/dist/{types-D402X18k.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
|
|
|
@@ -2588,6 +2669,7 @@ function resolveRasterImageCanvasRenderingOptions(options) {
|
|
|
2588
2669
|
return {
|
|
2589
2670
|
resolveSourceSize: options.resolveSourceSize,
|
|
2590
2671
|
resolveRenderTarget: options.resolveRenderTarget,
|
|
2672
|
+
resolveCanvasSource: options.resolveCanvasSource,
|
|
2591
2673
|
devicePixelRatio: toPositiveFiniteNumber(
|
|
2592
2674
|
options.devicePixelRatio,
|
|
2593
2675
|
fallbackDevicePixelRatio
|
|
@@ -2852,6 +2934,36 @@ function loadImageElement(href, signal) {
|
|
|
2852
2934
|
image.src = href;
|
|
2853
2935
|
});
|
|
2854
2936
|
}
|
|
2937
|
+
function normalizeDecodedRasterImageSource(source) {
|
|
2938
|
+
if (!source) return null;
|
|
2939
|
+
const width = Math.max(1, Math.round(source.width));
|
|
2940
|
+
const height = Math.max(1, Math.round(source.height));
|
|
2941
|
+
if (!Number.isFinite(width) || !Number.isFinite(height)) return null;
|
|
2942
|
+
return {
|
|
2943
|
+
width,
|
|
2944
|
+
height,
|
|
2945
|
+
draw: source.draw,
|
|
2946
|
+
close: source.close ?? (() => {
|
|
2947
|
+
})
|
|
2948
|
+
};
|
|
2949
|
+
}
|
|
2950
|
+
async function resolveDecodedRasterImageSource({
|
|
2951
|
+
options,
|
|
2952
|
+
request,
|
|
2953
|
+
width,
|
|
2954
|
+
height,
|
|
2955
|
+
signal
|
|
2956
|
+
}) {
|
|
2957
|
+
if (options?.resolveCanvasSource) {
|
|
2958
|
+
const source = await options.resolveCanvasSource({
|
|
2959
|
+
...request,
|
|
2960
|
+
signal
|
|
2961
|
+
});
|
|
2962
|
+
const decoded = normalizeDecodedRasterImageSource(source);
|
|
2963
|
+
if (decoded) return decoded;
|
|
2964
|
+
}
|
|
2965
|
+
return decodeRasterImage(request.targetHref, width, height, signal);
|
|
2966
|
+
}
|
|
2855
2967
|
var SvgVectorRenderer = class {
|
|
2856
2968
|
container;
|
|
2857
2969
|
scene;
|
|
@@ -3084,7 +3196,20 @@ var SvgVectorRenderer = class {
|
|
|
3084
3196
|
}
|
|
3085
3197
|
const request = {
|
|
3086
3198
|
itemHref: item.imageRasterHref,
|
|
3087
|
-
target
|
|
3199
|
+
target,
|
|
3200
|
+
sourceRequest: {
|
|
3201
|
+
item,
|
|
3202
|
+
href: item.imageRasterHref,
|
|
3203
|
+
intrinsicSize: item.imageIntrinsicSize,
|
|
3204
|
+
sourceSize,
|
|
3205
|
+
contentRect: target.contentRect,
|
|
3206
|
+
targetSize: target.targetSize,
|
|
3207
|
+
viewportSize,
|
|
3208
|
+
cameraZoom: this.camera.zoom,
|
|
3209
|
+
devicePixelRatio: options.devicePixelRatio,
|
|
3210
|
+
targetHref: target.href,
|
|
3211
|
+
sourceKey: target.sourceKey
|
|
3212
|
+
}
|
|
3088
3213
|
};
|
|
3089
3214
|
if (rasterCanvas.abortController) {
|
|
3090
3215
|
if (rasterCanvas.loadingItemHref !== item.imageRasterHref) {
|
|
@@ -3174,7 +3299,13 @@ var SvgVectorRenderer = class {
|
|
|
3174
3299
|
rasterCanvas.loadingWidth = width;
|
|
3175
3300
|
rasterCanvas.loadingHeight = height;
|
|
3176
3301
|
rasterCanvas.queuedTarget = null;
|
|
3177
|
-
|
|
3302
|
+
resolveDecodedRasterImageSource({
|
|
3303
|
+
options: this.rasterImageCanvasRendering,
|
|
3304
|
+
request: request.sourceRequest,
|
|
3305
|
+
width,
|
|
3306
|
+
height,
|
|
3307
|
+
signal: abortController.signal
|
|
3308
|
+
}).then((decoded) => {
|
|
3178
3309
|
if (abortController.signal.aborted || rasterCanvas.loadSequence !== sequence) {
|
|
3179
3310
|
decoded.close();
|
|
3180
3311
|
return;
|