canvu-react 0.4.67 → 0.4.69

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,5 +1,5 @@
1
1
  import { V as VectorSceneItem } from './types-fJNwEnHf.cjs';
2
- import { a as VectorViewportAssetStore } from './asset-store-35ysK28r.cjs';
2
+ import { a as VectorViewportAssetStore } from './raster-image-canvas-nK9kM9UJ.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 './asset-store-D_FjW_CN.js';
2
+ import { a as VectorViewportAssetStore } from './raster-image-canvas-CCOmB4NY.js';
3
3
 
4
4
  declare class IndexedDbImageStore {
5
5
  private dbPromise;
@@ -1,10 +1,10 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { c as CanvasPlugin } from './types-D5d-3dvz.cjs';
2
+ import { c as CanvasPlugin } from './types-D402X18k.cjs';
3
3
  import 'react';
4
4
  import './types-fJNwEnHf.cjs';
5
5
  import './shape-builders-DzhCOuzo.cjs';
6
+ import './raster-image-canvas-nK9kM9UJ.cjs';
6
7
  import './link-item-BMV3VUCr.cjs';
7
- import './asset-store-35ysK28r.cjs';
8
8
  import './types-DqsqQQVf.cjs';
9
9
 
10
10
  type ChatbotPluginPanelProps = {
package/dist/chatbot.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { c as CanvasPlugin } from './types-B-Jdh-n6.js';
2
+ import { c as CanvasPlugin } from './types-CMuEaiM7.js';
3
3
  import 'react';
4
4
  import './types-fJNwEnHf.js';
5
5
  import './shape-builders-xG3A66sv.js';
6
+ import './raster-image-canvas-CCOmB4NY.js';
6
7
  import './link-item-COoNNvCu.js';
7
- import './asset-store-D_FjW_CN.js';
8
8
  import './types-BXa2CIrc.js';
9
9
 
10
10
  type ChatbotPluginPanelProps = {
package/dist/index.cjs CHANGED
@@ -2577,6 +2577,176 @@ function cullItemsByViewport(items, visibleWorld) {
2577
2577
  return cullItemsByViewportSpatial(items, visibleWorld, SPATIAL_CELL_SIZE);
2578
2578
  }
2579
2579
 
2580
+ // src/renderer/raster-image-canvas.ts
2581
+ var DEFAULT_PIXEL_HEADROOM = 1.5;
2582
+ var DEFAULT_MAX_PIXEL_COUNT = 12e6;
2583
+ var DEFAULT_MAX_DIMENSION = 4096;
2584
+ var DEFAULT_UPSCALE_REDRAW_RATIO = 1.15;
2585
+ function resolveRasterImageCanvasRenderingOptions(options) {
2586
+ if (!options) return null;
2587
+ const fallbackDevicePixelRatio = typeof window === "undefined" ? 1 : window.devicePixelRatio;
2588
+ return {
2589
+ resolveSourceSize: options.resolveSourceSize,
2590
+ resolveRenderTarget: options.resolveRenderTarget,
2591
+ devicePixelRatio: toPositiveFiniteNumber(
2592
+ options.devicePixelRatio,
2593
+ fallbackDevicePixelRatio
2594
+ ),
2595
+ pixelHeadroom: toPositiveFiniteNumber(
2596
+ options.pixelHeadroom,
2597
+ DEFAULT_PIXEL_HEADROOM
2598
+ ),
2599
+ maxPixelCount: toPositiveFiniteNumber(
2600
+ options.maxPixelCount,
2601
+ DEFAULT_MAX_PIXEL_COUNT
2602
+ ),
2603
+ maxDimension: toPositiveFiniteNumber(
2604
+ options.maxDimension,
2605
+ DEFAULT_MAX_DIMENSION
2606
+ ),
2607
+ upscaleRedrawRatio: toPositiveFiniteNumber(
2608
+ options.upscaleRedrawRatio,
2609
+ DEFAULT_UPSCALE_REDRAW_RATIO
2610
+ )
2611
+ };
2612
+ }
2613
+ function getRasterImageContentRect(item) {
2614
+ if (item.toolKind !== "image" || !item.imageIntrinsicSize) return null;
2615
+ const bounds = normalizeRect(item.bounds);
2616
+ const intrinsicWidth = Math.max(1e-6, item.imageIntrinsicSize.width);
2617
+ const intrinsicHeight = Math.max(1e-6, item.imageIntrinsicSize.height);
2618
+ const boundsAspectRatio = bounds.width / Math.max(1e-9, bounds.height);
2619
+ const imageAspectRatio = intrinsicWidth / intrinsicHeight;
2620
+ if (Math.abs(boundsAspectRatio - imageAspectRatio) < 1e-3) {
2621
+ return { x: 0, y: 0, width: bounds.width, height: bounds.height };
2622
+ }
2623
+ if (boundsAspectRatio > imageAspectRatio) {
2624
+ const height2 = bounds.height;
2625
+ const width2 = height2 * imageAspectRatio;
2626
+ return { x: (bounds.width - width2) / 2, y: 0, width: width2, height: height2 };
2627
+ }
2628
+ const width = bounds.width;
2629
+ const height = width / imageAspectRatio;
2630
+ return { x: 0, y: (bounds.height - height) / 2, width, height };
2631
+ }
2632
+ function resolveRasterImageCanvasSourceSize({
2633
+ item,
2634
+ href,
2635
+ intrinsicSize,
2636
+ contentRect,
2637
+ viewportSize,
2638
+ cameraZoom,
2639
+ options
2640
+ }) {
2641
+ const resolved = options.resolveSourceSize?.({
2642
+ item,
2643
+ href,
2644
+ intrinsicSize,
2645
+ contentRect,
2646
+ viewportSize,
2647
+ cameraZoom,
2648
+ devicePixelRatio: options.devicePixelRatio
2649
+ });
2650
+ const width = toPositiveFiniteNumber(resolved?.width, intrinsicSize.width);
2651
+ const height = toPositiveFiniteNumber(resolved?.height, intrinsicSize.height);
2652
+ return { width, height };
2653
+ }
2654
+ function getRasterImageCanvasTargetSize({
2655
+ intrinsicSize,
2656
+ contentRect,
2657
+ cameraZoom,
2658
+ devicePixelRatio,
2659
+ pixelHeadroom,
2660
+ maxPixelCount,
2661
+ maxDimension
2662
+ }) {
2663
+ const intrinsicWidth = Math.max(1, Math.round(intrinsicSize.width));
2664
+ const intrinsicHeight = Math.max(1, Math.round(intrinsicSize.height));
2665
+ const targetCssWidth = Math.max(1, contentRect.width * cameraZoom);
2666
+ const targetCssHeight = Math.max(1, contentRect.height * cameraZoom);
2667
+ const desiredWidth = targetCssWidth * toPositiveFiniteNumber(devicePixelRatio, 1) * pixelHeadroom;
2668
+ const desiredHeight = targetCssHeight * toPositiveFiniteNumber(devicePixelRatio, 1) * pixelHeadroom;
2669
+ const dimensionScale = Math.min(
2670
+ 1,
2671
+ toPositiveFiniteNumber(maxDimension, intrinsicWidth) / Math.max(intrinsicWidth, intrinsicHeight)
2672
+ );
2673
+ const pixelScale = Math.min(
2674
+ 1,
2675
+ Math.sqrt(
2676
+ toPositiveFiniteNumber(maxPixelCount, intrinsicWidth * intrinsicHeight) / (intrinsicWidth * intrinsicHeight)
2677
+ )
2678
+ );
2679
+ const viewportScale = Math.min(
2680
+ 1,
2681
+ desiredWidth / intrinsicWidth,
2682
+ desiredHeight / intrinsicHeight
2683
+ );
2684
+ const scale = Math.min(dimensionScale, pixelScale, viewportScale);
2685
+ const width = Math.max(1, Math.round(intrinsicWidth * scale));
2686
+ const height = Math.max(1, Math.round(width * (intrinsicHeight / intrinsicWidth)));
2687
+ return { width, height };
2688
+ }
2689
+ function resolveRasterImageCanvasRenderTarget({
2690
+ item,
2691
+ href,
2692
+ intrinsicSize,
2693
+ sourceSize,
2694
+ contentRect,
2695
+ targetSize,
2696
+ viewportSize,
2697
+ cameraZoom,
2698
+ options
2699
+ }) {
2700
+ const request = {
2701
+ item,
2702
+ href,
2703
+ intrinsicSize,
2704
+ sourceSize,
2705
+ contentRect,
2706
+ targetSize,
2707
+ viewportSize,
2708
+ cameraZoom,
2709
+ devicePixelRatio: options.devicePixelRatio
2710
+ };
2711
+ const resolved = options.resolveRenderTarget?.(request);
2712
+ if (typeof resolved === "string") {
2713
+ return { href: resolved, sourceKey: resolved, targetSize, contentRect };
2714
+ }
2715
+ if (resolved?.href) {
2716
+ return {
2717
+ href: resolved.href,
2718
+ sourceKey: resolved.sourceKey ?? resolved.href,
2719
+ targetSize,
2720
+ contentRect
2721
+ };
2722
+ }
2723
+ return { href, sourceKey: href, targetSize, contentRect };
2724
+ }
2725
+ function shouldRedrawRasterImageCanvas({
2726
+ currentSourceKey,
2727
+ currentWidth,
2728
+ currentHeight,
2729
+ nextSourceKey,
2730
+ nextWidth,
2731
+ nextHeight,
2732
+ upscaleRedrawRatio
2733
+ }) {
2734
+ const safeCurrentWidth = Math.max(0, Math.round(currentWidth));
2735
+ const safeCurrentHeight = Math.max(0, Math.round(currentHeight));
2736
+ const safeNextWidth = Math.max(1, Math.round(nextWidth));
2737
+ const safeNextHeight = Math.max(1, Math.round(nextHeight));
2738
+ if (!currentSourceKey || safeCurrentWidth <= 1 || safeCurrentHeight <= 1) {
2739
+ return true;
2740
+ }
2741
+ if (currentSourceKey !== nextSourceKey && safeCurrentWidth === safeNextWidth && safeCurrentHeight === safeNextHeight) {
2742
+ return true;
2743
+ }
2744
+ return safeNextWidth > safeCurrentWidth * upscaleRedrawRatio || safeNextHeight > safeCurrentHeight * upscaleRedrawRatio;
2745
+ }
2746
+ function toPositiveFiniteNumber(value, fallback) {
2747
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
2748
+ }
2749
+
2580
2750
  // src/renderer/svg-vector-renderer.ts
2581
2751
  function formatCameraTransform(camera) {
2582
2752
  const z = camera.zoom;
@@ -2601,6 +2771,87 @@ function itemClassName(item) {
2601
2771
  }
2602
2772
  return classes.join(" ");
2603
2773
  }
2774
+ async function decodeRasterImage(href, width, height, signal) {
2775
+ if (typeof createImageBitmap === "function") {
2776
+ try {
2777
+ const response = await fetch(href, { signal, credentials: "same-origin" });
2778
+ if (!response.ok) {
2779
+ throw new Error(`Failed to fetch raster image: ${response.status}`);
2780
+ }
2781
+ const blob = await response.blob();
2782
+ if (signal.aborted) throw new DOMException("Aborted", "AbortError");
2783
+ const bitmap = await createImageBitmap(blob, {
2784
+ resizeWidth: width,
2785
+ resizeHeight: height,
2786
+ resizeQuality: "high"
2787
+ });
2788
+ return {
2789
+ width: bitmap.width,
2790
+ height: bitmap.height,
2791
+ draw: (context) => {
2792
+ context.drawImage(bitmap, 0, 0, bitmap.width, bitmap.height);
2793
+ },
2794
+ close: () => bitmap.close()
2795
+ };
2796
+ } catch (error) {
2797
+ if (signal.aborted) throw error;
2798
+ }
2799
+ }
2800
+ const image = await loadImageElement(href, signal);
2801
+ return {
2802
+ width,
2803
+ height,
2804
+ draw: (context) => {
2805
+ context.drawImage(image, 0, 0, width, height);
2806
+ },
2807
+ close: () => {
2808
+ }
2809
+ };
2810
+ }
2811
+ function loadImageElement(href, signal) {
2812
+ return new Promise((resolve, reject) => {
2813
+ if (signal.aborted) {
2814
+ reject(new DOMException("Aborted", "AbortError"));
2815
+ return;
2816
+ }
2817
+ const image = new Image();
2818
+ const cleanup = () => {
2819
+ signal.removeEventListener("abort", abort);
2820
+ image.onload = null;
2821
+ image.onerror = null;
2822
+ };
2823
+ const abort = () => {
2824
+ cleanup();
2825
+ image.removeAttribute("src");
2826
+ reject(new DOMException("Aborted", "AbortError"));
2827
+ };
2828
+ image.decoding = "async";
2829
+ image.onload = () => {
2830
+ const decodePromise = image.decode?.();
2831
+ if (!decodePromise) {
2832
+ cleanup();
2833
+ resolve(image);
2834
+ return;
2835
+ }
2836
+ decodePromise.then(
2837
+ () => {
2838
+ cleanup();
2839
+ resolve(image);
2840
+ },
2841
+ () => {
2842
+ cleanup();
2843
+ resolve(image);
2844
+ }
2845
+ );
2846
+ };
2847
+ image.onerror = () => {
2848
+ cleanup();
2849
+ reject(new Error("Failed to load raster image"));
2850
+ };
2851
+ signal.addEventListener("abort", abort, { once: true });
2852
+ image.src = href;
2853
+ });
2854
+ }
2604
2855
  var SvgVectorRenderer = class {
2605
2856
  container;
2606
2857
  scene;
@@ -2612,10 +2863,14 @@ var SvgVectorRenderer = class {
2612
2863
  hoveredItemId = null;
2613
2864
  liveOverlay = null;
2614
2865
  resizeObserver;
2866
+ rasterImageCanvasRendering;
2615
2867
  constructor(options) {
2616
2868
  this.container = options.container;
2617
2869
  this.scene = options.scene;
2618
2870
  this.camera = options.camera;
2871
+ this.rasterImageCanvasRendering = resolveRasterImageCanvasRenderingOptions(
2872
+ options.rasterImageCanvas
2873
+ );
2619
2874
  this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
2620
2875
  this.svg.setAttribute("width", "100%");
2621
2876
  this.svg.setAttribute("height", "100%");
@@ -2644,6 +2899,15 @@ var SvgVectorRenderer = class {
2644
2899
  this.applyInteractionAttributes(cached.g, id);
2645
2900
  }
2646
2901
  }
2902
+ setRasterImageCanvasRendering(options) {
2903
+ this.rasterImageCanvasRendering = resolveRasterImageCanvasRenderingOptions(options);
2904
+ if (!this.rasterImageCanvasRendering) {
2905
+ for (const cached of this.itemNodeCache.values()) {
2906
+ this.releaseRasterImageCanvas(cached);
2907
+ }
2908
+ }
2909
+ this.render();
2910
+ }
2647
2911
  /**
2648
2912
  * Reads container size, culls items, and updates the SVG (incrementally when possible).
2649
2913
  */
@@ -2717,6 +2981,7 @@ var SvgVectorRenderer = class {
2717
2981
  }
2718
2982
  for (const [id, cached] of this.itemNodeCache) {
2719
2983
  if (!visibleIds.has(id)) {
2984
+ this.releaseRasterImageCanvas(cached);
2720
2985
  cached.g.remove();
2721
2986
  }
2722
2987
  }
@@ -2749,6 +3014,7 @@ var SvgVectorRenderer = class {
2749
3014
  g.innerHTML = item.childrenSvg;
2750
3015
  cached.lastChildrenSvg = item.childrenSvg;
2751
3016
  }
3017
+ this.syncRasterImageCanvas(cached, item);
2752
3018
  const expectedPosition = previousNode ? previousNode.nextSibling : this.rootG.firstChild;
2753
3019
  if (expectedPosition !== g) {
2754
3020
  this.rootG.insertBefore(g, expectedPosition);
@@ -2756,6 +3022,238 @@ var SvgVectorRenderer = class {
2756
3022
  previousNode = g;
2757
3023
  }
2758
3024
  }
3025
+ syncRasterImageCanvas(cached, item) {
3026
+ const options = this.rasterImageCanvasRendering;
3027
+ if (!options || item.toolKind !== "image" || !item.imageRasterHref || !item.imageIntrinsicSize) {
3028
+ this.releaseRasterImageCanvas(cached);
3029
+ return;
3030
+ }
3031
+ const contentRect = getRasterImageContentRect(item);
3032
+ const viewportSize = {
3033
+ width: this.container.clientWidth,
3034
+ height: this.container.clientHeight
3035
+ };
3036
+ if (!contentRect || viewportSize.width <= 0 || viewportSize.height <= 0) {
3037
+ this.releaseRasterImageCanvas(cached);
3038
+ return;
3039
+ }
3040
+ const sourceSize = resolveRasterImageCanvasSourceSize({
3041
+ item,
3042
+ href: item.imageRasterHref,
3043
+ intrinsicSize: item.imageIntrinsicSize,
3044
+ contentRect,
3045
+ viewportSize,
3046
+ cameraZoom: this.camera.zoom,
3047
+ options
3048
+ });
3049
+ const targetSize = getRasterImageCanvasTargetSize({
3050
+ intrinsicSize: sourceSize,
3051
+ contentRect,
3052
+ cameraZoom: this.camera.zoom,
3053
+ devicePixelRatio: options.devicePixelRatio,
3054
+ pixelHeadroom: options.pixelHeadroom,
3055
+ maxPixelCount: options.maxPixelCount,
3056
+ maxDimension: options.maxDimension
3057
+ });
3058
+ const target = resolveRasterImageCanvasRenderTarget({
3059
+ item,
3060
+ href: item.imageRasterHref,
3061
+ intrinsicSize: item.imageIntrinsicSize,
3062
+ sourceSize,
3063
+ contentRect,
3064
+ targetSize,
3065
+ viewportSize,
3066
+ cameraZoom: this.camera.zoom,
3067
+ options
3068
+ });
3069
+ const rasterCanvas = this.ensureRasterImageCanvas(cached);
3070
+ this.positionRasterImageCanvas(rasterCanvas, target.contentRect);
3071
+ if (rasterCanvas.itemHref !== null && rasterCanvas.itemHref !== item.imageRasterHref) {
3072
+ this.clearRasterImageCanvasBitmap(rasterCanvas);
3073
+ }
3074
+ if (!shouldRedrawRasterImageCanvas({
3075
+ currentSourceKey: rasterCanvas.sourceKey,
3076
+ currentWidth: rasterCanvas.width,
3077
+ currentHeight: rasterCanvas.height,
3078
+ nextSourceKey: target.sourceKey,
3079
+ nextWidth: target.targetSize.width,
3080
+ nextHeight: target.targetSize.height,
3081
+ upscaleRedrawRatio: options.upscaleRedrawRatio
3082
+ })) {
3083
+ return;
3084
+ }
3085
+ const request = {
3086
+ itemHref: item.imageRasterHref,
3087
+ target
3088
+ };
3089
+ if (rasterCanvas.abortController) {
3090
+ if (rasterCanvas.loadingItemHref !== item.imageRasterHref) {
3091
+ rasterCanvas.abortController.abort();
3092
+ rasterCanvas.abortController = null;
3093
+ rasterCanvas.loadingItemHref = null;
3094
+ rasterCanvas.loadingSourceKey = null;
3095
+ rasterCanvas.loadingWidth = 0;
3096
+ rasterCanvas.loadingHeight = 0;
3097
+ rasterCanvas.queuedTarget = null;
3098
+ this.drawRasterImageCanvas(rasterCanvas, request);
3099
+ return;
3100
+ }
3101
+ if (rasterCanvas.loadingSourceKey === target.sourceKey && rasterCanvas.loadingWidth === target.targetSize.width && rasterCanvas.loadingHeight === target.targetSize.height) {
3102
+ return;
3103
+ }
3104
+ if (shouldRedrawRasterImageCanvas({
3105
+ currentSourceKey: rasterCanvas.loadingSourceKey,
3106
+ currentWidth: rasterCanvas.loadingWidth,
3107
+ currentHeight: rasterCanvas.loadingHeight,
3108
+ nextSourceKey: target.sourceKey,
3109
+ nextWidth: target.targetSize.width,
3110
+ nextHeight: target.targetSize.height,
3111
+ upscaleRedrawRatio: options.upscaleRedrawRatio
3112
+ })) {
3113
+ rasterCanvas.queuedTarget = request;
3114
+ }
3115
+ return;
3116
+ }
3117
+ this.drawRasterImageCanvas(rasterCanvas, request);
3118
+ }
3119
+ ensureRasterImageCanvas(cached) {
3120
+ if (cached.rasterCanvas) {
3121
+ if (!cached.rasterCanvas.foreignObject.isConnected) {
3122
+ cached.g.appendChild(cached.rasterCanvas.foreignObject);
3123
+ }
3124
+ return cached.rasterCanvas;
3125
+ }
3126
+ const foreignObject = document.createElementNS(
3127
+ "http://www.w3.org/2000/svg",
3128
+ "foreignObject"
3129
+ );
3130
+ foreignObject.setAttribute("data-canvu-raster-canvas", "true");
3131
+ foreignObject.style.pointerEvents = "none";
3132
+ const canvas = document.createElement("canvas");
3133
+ canvas.width = 1;
3134
+ canvas.height = 1;
3135
+ canvas.style.display = "block";
3136
+ canvas.style.width = "100%";
3137
+ canvas.style.height = "100%";
3138
+ foreignObject.appendChild(canvas);
3139
+ cached.g.appendChild(foreignObject);
3140
+ cached.rasterCanvas = {
3141
+ foreignObject,
3142
+ canvas,
3143
+ itemHref: null,
3144
+ sourceKey: null,
3145
+ width: 0,
3146
+ height: 0,
3147
+ loadSequence: 0,
3148
+ abortController: null,
3149
+ loadingItemHref: null,
3150
+ loadingSourceKey: null,
3151
+ loadingWidth: 0,
3152
+ loadingHeight: 0,
3153
+ queuedTarget: null
3154
+ };
3155
+ return cached.rasterCanvas;
3156
+ }
3157
+ positionRasterImageCanvas(rasterCanvas, contentRect) {
3158
+ rasterCanvas.foreignObject.setAttribute("x", String(contentRect.x));
3159
+ rasterCanvas.foreignObject.setAttribute("y", String(contentRect.y));
3160
+ rasterCanvas.foreignObject.setAttribute("width", String(contentRect.width));
3161
+ rasterCanvas.foreignObject.setAttribute("height", String(contentRect.height));
3162
+ }
3163
+ drawRasterImageCanvas(rasterCanvas, request) {
3164
+ const { target } = request;
3165
+ const width = Math.max(1, Math.round(target.targetSize.width));
3166
+ const height = Math.max(1, Math.round(target.targetSize.height));
3167
+ const sequence = rasterCanvas.loadSequence + 1;
3168
+ rasterCanvas.loadSequence = sequence;
3169
+ rasterCanvas.abortController?.abort();
3170
+ const abortController = new AbortController();
3171
+ rasterCanvas.abortController = abortController;
3172
+ rasterCanvas.loadingItemHref = request.itemHref;
3173
+ rasterCanvas.loadingSourceKey = target.sourceKey;
3174
+ rasterCanvas.loadingWidth = width;
3175
+ rasterCanvas.loadingHeight = height;
3176
+ rasterCanvas.queuedTarget = null;
3177
+ decodeRasterImage(target.href, width, height, abortController.signal).then((decoded) => {
3178
+ if (abortController.signal.aborted || rasterCanvas.loadSequence !== sequence) {
3179
+ decoded.close();
3180
+ return;
3181
+ }
3182
+ const context = rasterCanvas.canvas.getContext("2d");
3183
+ if (!context) {
3184
+ decoded.close();
3185
+ rasterCanvas.abortController = null;
3186
+ rasterCanvas.loadingItemHref = null;
3187
+ rasterCanvas.loadingSourceKey = null;
3188
+ rasterCanvas.loadingWidth = 0;
3189
+ rasterCanvas.loadingHeight = 0;
3190
+ this.drawQueuedRasterImageCanvasTarget(rasterCanvas);
3191
+ return;
3192
+ }
3193
+ rasterCanvas.canvas.width = decoded.width;
3194
+ rasterCanvas.canvas.height = decoded.height;
3195
+ context.clearRect(0, 0, decoded.width, decoded.height);
3196
+ decoded.draw(context);
3197
+ decoded.close();
3198
+ rasterCanvas.itemHref = request.itemHref;
3199
+ rasterCanvas.sourceKey = target.sourceKey;
3200
+ rasterCanvas.width = decoded.width;
3201
+ rasterCanvas.height = decoded.height;
3202
+ rasterCanvas.abortController = null;
3203
+ rasterCanvas.loadingItemHref = null;
3204
+ rasterCanvas.loadingSourceKey = null;
3205
+ rasterCanvas.loadingWidth = 0;
3206
+ rasterCanvas.loadingHeight = 0;
3207
+ this.drawQueuedRasterImageCanvasTarget(rasterCanvas);
3208
+ }).catch((error) => {
3209
+ if (abortController.signal.aborted) return;
3210
+ if (error instanceof Error && error.name === "AbortError") return;
3211
+ if (rasterCanvas.loadSequence === sequence) {
3212
+ rasterCanvas.abortController = null;
3213
+ rasterCanvas.loadingItemHref = null;
3214
+ rasterCanvas.loadingSourceKey = null;
3215
+ rasterCanvas.loadingWidth = 0;
3216
+ rasterCanvas.loadingHeight = 0;
3217
+ this.drawQueuedRasterImageCanvasTarget(rasterCanvas);
3218
+ }
3219
+ });
3220
+ }
3221
+ drawQueuedRasterImageCanvasTarget(rasterCanvas) {
3222
+ const queuedTarget = rasterCanvas.queuedTarget;
3223
+ if (!queuedTarget) return;
3224
+ rasterCanvas.queuedTarget = null;
3225
+ if (!shouldRedrawRasterImageCanvas({
3226
+ currentSourceKey: rasterCanvas.sourceKey,
3227
+ currentWidth: rasterCanvas.width,
3228
+ currentHeight: rasterCanvas.height,
3229
+ nextSourceKey: queuedTarget.target.sourceKey,
3230
+ nextWidth: queuedTarget.target.targetSize.width,
3231
+ nextHeight: queuedTarget.target.targetSize.height,
3232
+ upscaleRedrawRatio: this.rasterImageCanvasRendering?.upscaleRedrawRatio ?? 1
3233
+ })) {
3234
+ return;
3235
+ }
3236
+ this.drawRasterImageCanvas(rasterCanvas, queuedTarget);
3237
+ }
3238
+ clearRasterImageCanvasBitmap(rasterCanvas) {
3239
+ const context = rasterCanvas.canvas.getContext("2d");
3240
+ context?.clearRect(0, 0, rasterCanvas.canvas.width, rasterCanvas.canvas.height);
3241
+ rasterCanvas.canvas.width = 1;
3242
+ rasterCanvas.canvas.height = 1;
3243
+ rasterCanvas.itemHref = null;
3244
+ rasterCanvas.sourceKey = null;
3245
+ rasterCanvas.width = 0;
3246
+ rasterCanvas.height = 0;
3247
+ }
3248
+ releaseRasterImageCanvas(cached) {
3249
+ const rasterCanvas = cached.rasterCanvas;
3250
+ if (!rasterCanvas) return;
3251
+ rasterCanvas.abortController?.abort();
3252
+ rasterCanvas.loadSequence += 1;
3253
+ rasterCanvas.queuedTarget = null;
3254
+ rasterCanvas.foreignObject.remove();
3255
+ cached.rasterCanvas = void 0;
3256
+ }
2759
3257
  applyInteractionAttributes(g, itemId) {
2760
3258
  g.setAttribute(
2761
3259
  "data-canvu-selected",
@@ -2768,6 +3266,9 @@ var SvgVectorRenderer = class {
2768
3266
  }
2769
3267
  destroy() {
2770
3268
  this.resizeObserver.disconnect();
3269
+ for (const cached of this.itemNodeCache.values()) {
3270
+ this.releaseRasterImageCanvas(cached);
3271
+ }
2771
3272
  this.itemNodeCache.clear();
2772
3273
  this.liveOverlay = null;
2773
3274
  this.svg.remove();