@meonode/canvas 1.6.0-beta.1 → 1.6.0-beta.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,6 +1,11 @@
1
1
  import type { BaseProps, ImageProps, NodeDescriptor } from '../canvas/canvas.type.js';
2
- import { type CanvasRenderingContext2D } from 'skia-canvas';
2
+ import { type CanvasRenderingContext2D, Image as CanvasImage } from 'skia-canvas';
3
3
  import { BoxNode } from '../canvas/layout.canvas.util.js';
4
+ /**
5
+ * Per-render image cache — keyed by `src|color` for string sources.
6
+ * Scoped to a single RootNode.render() call; discarded after rendering.
7
+ */
8
+ export type RenderImageCache = Map<string, Promise<CanvasImage>>;
4
9
  /**
5
10
  * Renders images with configurable sizing, positioning, and effects.
6
11
  * Supports object-fit modes, positioning, border radius, and saturation filters.
@@ -12,12 +17,15 @@ export declare class ImageNode extends BoxNode {
12
17
  private naturalHeight;
13
18
  private loadingPromise;
14
19
  constructor(props: ImageProps);
15
- load(): Promise<void>;
20
+ load(cache?: RenderImageCache): Promise<void>;
21
+ /**
22
+ * Fetches and processes the image source into a CanvasImage.
23
+ * Does not touch node state — pure fetch logic.
24
+ */
25
+ private _fetchCanvasImage;
16
26
  /**
17
- * Loads and processes an image from various sources (URL, file path, or Buffer).
18
- * Handles SVG color modifications and sets natural dimensions with an aspect ratio.
19
- * @returns Promise that resolves when image loading completes
20
- * @throws Error if image loading fails
27
+ * Loads and processes an image, using the render-scoped cache to avoid
28
+ * re-fetching the same source within a single render pass.
21
29
  */
22
30
  private _loadImage;
23
31
  getLoadingPromise(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"image.canvas.util.d.ts","sourceRoot":"","sources":["../../../src/canvas/image.canvas.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACpF,OAAO,EAAE,KAAK,wBAAwB,EAAmC,MAAM,aA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,OAAO,CAAC,aAAa,CAAI;IACzB,OAAO,CAAC,cAAc,CAA6B;gBAEvC,KAAK,EAAE,UAAU;IAYtB,IAAI,CAAC,KAAK,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpD;;;OAGG;YACW,iBAAiB;IAmE/B;;;OAGG;IACH,OAAO,CAAC,UAAU;IAgDX,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzC;;;OAGG;cACgB,cAAc,CAAC,GAAG,EAAE,wBAAwB,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAoJrH;AAED;;GAEG;AACH,eAAO,MAAM,KAAK,GAAI,OAAO,UAAU,KAAG,cAGxC,CAAA"}
@@ -41,23 +41,82 @@ class ImageNode extends layout_canvas_util.BoxNode {
41
41
  ...props,
42
42
  };
43
43
  }
44
- load() {
44
+ load(cache) {
45
45
  if (!this.loadingPromise) {
46
- this.loadingPromise = this._loadImage();
46
+ this.loadingPromise = this._loadImage(cache);
47
47
  }
48
48
  return this.loadingPromise;
49
49
  }
50
50
  /**
51
- * Loads and processes an image from various sources (URL, file path, or Buffer).
52
- * Handles SVG color modifications and sets natural dimensions with an aspect ratio.
53
- * @returns Promise that resolves when image loading completes
54
- * @throws Error if image loading fails
51
+ * Fetches and processes the image source into a CanvasImage.
52
+ * Does not touch node state pure fetch logic.
55
53
  */
56
- _loadImage() {
57
- if (this.loadingPromise)
58
- return this.loadingPromise;
59
- if (this.loadedImage)
60
- return Promise.resolve();
54
+ async _fetchCanvasImage() {
55
+ const { fileTypeFromBuffer, fileTypeFromFile } = await import('file-type');
56
+ let finalSource = this.props.src;
57
+ let isSvg = false;
58
+ let contentBuffer = null;
59
+ let detectedMime;
60
+ if (typeof this.props.src === 'string') {
61
+ if (this.props.src.startsWith('http')) {
62
+ const response = await fetch(this.props.src);
63
+ if (!response.ok) {
64
+ throw new Error(`HTTP error ${response.status} fetching image: ${this.props.src}`);
65
+ }
66
+ const imageArrayBuffer = await response.arrayBuffer();
67
+ contentBuffer = Buffer.from(imageArrayBuffer);
68
+ finalSource = contentBuffer;
69
+ const fileTypeResult = await fileTypeFromBuffer(contentBuffer);
70
+ detectedMime = fileTypeResult?.mime;
71
+ isSvg = detectedMime === 'image/svg+xml';
72
+ if ((!detectedMime || detectedMime === 'application/xml') && contentBuffer.toString('utf-8').includes('<svg')) {
73
+ isSvg = true;
74
+ }
75
+ }
76
+ else {
77
+ finalSource = this.props.src;
78
+ const filePath = this.props.src;
79
+ try {
80
+ const fileTypeResult = await fileTypeFromFile(filePath);
81
+ detectedMime = fileTypeResult?.mime;
82
+ isSvg = detectedMime === 'image/svg+xml';
83
+ if ((!detectedMime || detectedMime === 'application/xml') && filePath.toLowerCase().endsWith('.svg')) {
84
+ isSvg = true;
85
+ }
86
+ }
87
+ catch {
88
+ isSvg = filePath.toLowerCase().endsWith('.svg');
89
+ }
90
+ if (isSvg && this.props.color) {
91
+ try {
92
+ contentBuffer = await fs.promises.readFile(filePath);
93
+ }
94
+ catch {
95
+ isSvg = false;
96
+ contentBuffer = null;
97
+ }
98
+ }
99
+ }
100
+ }
101
+ else {
102
+ contentBuffer = this.props.src;
103
+ finalSource = contentBuffer;
104
+ const fileTypeResult = await fileTypeFromBuffer(contentBuffer);
105
+ detectedMime = fileTypeResult?.mime;
106
+ isSvg = detectedMime === 'image/svg+xml';
107
+ }
108
+ if (isSvg && this.props.color && contentBuffer) {
109
+ const svgString = contentBuffer.toString('utf-8');
110
+ const modifiedSvgString = svgString.replace(/fill="[^"]*"/g, `fill="${this.props.color}"`);
111
+ finalSource = modifiedSvgString !== svgString ? Buffer.from(modifiedSvgString) : contentBuffer;
112
+ }
113
+ return skiaCanvas.loadImage(finalSource);
114
+ }
115
+ /**
116
+ * Loads and processes an image, using the render-scoped cache to avoid
117
+ * re-fetching the same source within a single render pass.
118
+ */
119
+ _loadImage(cache) {
61
120
  if (!this.props.src) {
62
121
  const aspectRatioFromProps = typeof this.props.aspectRatio === 'number' && this.props.aspectRatio > 0 ? this.props.aspectRatio : undefined;
63
122
  this.node.setAspectRatio(aspectRatioFromProps);
@@ -67,71 +126,19 @@ class ImageNode extends layout_canvas_util.BoxNode {
67
126
  }
68
127
  return new Promise(resolve => {
69
128
  const load = async () => {
70
- const { fileTypeFromBuffer, fileTypeFromFile } = await import('file-type');
71
- let finalSource = this.props.src;
72
- let isSvg = false;
73
- let contentBuffer = null;
74
- let detectedMime;
75
129
  try {
76
- if (typeof this.props.src === 'string') {
77
- if (this.props.src.startsWith('http')) {
78
- const response = await fetch(this.props.src);
79
- if (!response.ok) {
80
- throw new Error(`HTTP error ${response.status} fetching image: ${this.props.src}`);
81
- }
82
- const imageArrayBuffer = await response.arrayBuffer();
83
- contentBuffer = Buffer.from(imageArrayBuffer);
84
- finalSource = contentBuffer;
85
- const fileTypeResult = await fileTypeFromBuffer(contentBuffer);
86
- detectedMime = fileTypeResult?.mime;
87
- isSvg = detectedMime === 'image/svg+xml';
88
- if ((!detectedMime || detectedMime === 'application/xml') && contentBuffer.toString('utf-8').includes('<svg')) {
89
- isSvg = true;
90
- }
91
- }
92
- else {
93
- finalSource = this.props.src;
94
- const filePath = this.props.src;
95
- try {
96
- const fileTypeResult = await fileTypeFromFile(filePath);
97
- detectedMime = fileTypeResult?.mime;
98
- isSvg = detectedMime === 'image/svg+xml';
99
- if ((!detectedMime || detectedMime === 'application/xml') && filePath.toLowerCase().endsWith('.svg')) {
100
- isSvg = true;
101
- }
102
- }
103
- catch {
104
- isSvg = filePath.toLowerCase().endsWith('.svg');
105
- }
106
- if (isSvg && this.props.color) {
107
- try {
108
- contentBuffer = await fs.promises.readFile(filePath);
109
- }
110
- catch {
111
- isSvg = false;
112
- contentBuffer = null;
113
- }
114
- }
130
+ let imagePromise;
131
+ if (cache && typeof this.props.src === 'string') {
132
+ const cacheKey = this.props.color ? `${this.props.src}|${this.props.color}` : this.props.src;
133
+ if (!cache.has(cacheKey)) {
134
+ cache.set(cacheKey, this._fetchCanvasImage());
115
135
  }
136
+ imagePromise = cache.get(cacheKey);
116
137
  }
117
138
  else {
118
- contentBuffer = this.props.src;
119
- finalSource = contentBuffer;
120
- const fileTypeResult = await fileTypeFromBuffer(contentBuffer);
121
- detectedMime = fileTypeResult?.mime;
122
- isSvg = detectedMime === 'image/svg+xml';
123
- }
124
- if (isSvg && this.props.color && contentBuffer) {
125
- const svgString = contentBuffer.toString('utf-8');
126
- const modifiedSvgString = svgString.replace(/fill="[^"]*"/g, `fill="${this.props.color}"`);
127
- if (modifiedSvgString !== svgString) {
128
- finalSource = Buffer.from(modifiedSvgString);
129
- }
130
- else {
131
- finalSource = contentBuffer;
132
- }
139
+ imagePromise = this._fetchCanvasImage();
133
140
  }
134
- const img = await skiaCanvas.loadImage(finalSource);
141
+ const img = await imagePromise;
135
142
  this.loadedImage = img;
136
143
  this.naturalWidth = img.width;
137
144
  this.naturalHeight = img.height;
@@ -1 +1 @@
1
- {"version":3,"file":"image.canvas.util.js","sources":["../../../../src/canvas/image.canvas.util.ts"],"sourcesContent":["import type { BaseProps, ImageProps, NodeDescriptor } from '@/canvas/canvas.type.js'\nimport { type CanvasRenderingContext2D, Image as CanvasImage, loadImage } from 'skia-canvas'\nimport { BoxNode } from '@/canvas/layout.canvas.util.js'\nimport { drawRoundedRectPath, parseBorderRadius } from '@/canvas/canvas.helper.js'\nimport { promises as fs } from 'fs'\nimport { Style } from '@/constant/common.const.js'\n\n/**\n * Calculates pixel offset for image positioning based on percentage or pixel values.\n * This handles centering, edge alignment, and percentage-based positioning.\n */\nfunction calculateOffsetFromValue(positionValue: number | `${number}%` | undefined, availableSpace: number): number {\n const value = positionValue ?? '50%'\n if (typeof value === 'number') {\n return value\n }\n if (typeof value === 'string' && value.endsWith('%')) {\n const percentage = parseFloat(value) / 100\n return availableSpace * percentage\n }\n console.warn(`[ImageNode] Invalid objectPosition value format: ${value}. Defaulting to 50%.`)\n return availableSpace * 0.5\n}\n\n/**\n * Renders images with configurable sizing, positioning, and effects.\n * Supports object-fit modes, positioning, border radius, and saturation filters.\n */\nexport class ImageNode extends BoxNode {\n declare props: ImageProps & BaseProps\n private loadedImage: CanvasImage | null = null\n private naturalWidth = 0\n private naturalHeight = 0\n private loadingPromise: Promise<void> | null = null\n\n constructor(props: ImageProps) {\n super({ name: 'Image', ...props, children: undefined })\n\n this.props = {\n objectFit: 'fill',\n overflow: Style.Overflow.Hidden,\n saturate: 1,\n objectPosition: { Left: '50%', Top: '50%' },\n ...props,\n }\n }\n\n public load(): Promise<void> {\n if (!this.loadingPromise) {\n this.loadingPromise = this._loadImage()\n }\n return this.loadingPromise\n }\n\n /**\n * Loads and processes an image from various sources (URL, file path, or Buffer).\n * Handles SVG color modifications and sets natural dimensions with an aspect ratio.\n * @returns Promise that resolves when image loading completes\n * @throws Error if image loading fails\n */\n private _loadImage(): Promise<void> {\n if (this.loadingPromise) return this.loadingPromise\n if (this.loadedImage) return Promise.resolve()\n\n if (!this.props.src) {\n const aspectRatioFromProps = typeof this.props.aspectRatio === 'number' && this.props.aspectRatio > 0 ? this.props.aspectRatio : undefined\n this.node.setAspectRatio(aspectRatioFromProps)\n this.naturalWidth = 0\n this.naturalHeight = 0\n\n return Promise.resolve()\n }\n\n return new Promise(resolve => {\n const load = async () => {\n const { fileTypeFromBuffer, fileTypeFromFile } = await import('file-type')\n let finalSource: string | Buffer = this.props.src\n let isSvg = false\n let contentBuffer: Buffer | null = null\n let detectedMime: string | undefined\n\n try {\n if (typeof this.props.src === 'string') {\n if (this.props.src.startsWith('http')) {\n const response = await fetch(this.props.src)\n if (!response.ok) {\n throw new Error(`HTTP error ${response.status} fetching image: ${this.props.src}`)\n }\n const imageArrayBuffer = await response.arrayBuffer()\n contentBuffer = Buffer.from(imageArrayBuffer)\n finalSource = contentBuffer\n\n const fileTypeResult = await fileTypeFromBuffer(contentBuffer)\n detectedMime = fileTypeResult?.mime\n isSvg = detectedMime === 'image/svg+xml'\n\n if ((!detectedMime || detectedMime === 'application/xml') && contentBuffer.toString('utf-8').includes('<svg')) {\n isSvg = true\n }\n } else {\n finalSource = this.props.src\n const filePath = this.props.src\n\n try {\n const fileTypeResult = await fileTypeFromFile(filePath)\n detectedMime = fileTypeResult?.mime\n isSvg = detectedMime === 'image/svg+xml'\n\n if ((!detectedMime || detectedMime === 'application/xml') && filePath.toLowerCase().endsWith('.svg')) {\n isSvg = true\n }\n } catch {\n isSvg = filePath.toLowerCase().endsWith('.svg')\n }\n\n if (isSvg && this.props.color) {\n try {\n contentBuffer = await fs.readFile(filePath)\n } catch {\n isSvg = false\n contentBuffer = null\n }\n }\n }\n } else {\n contentBuffer = this.props.src\n finalSource = contentBuffer\n\n const fileTypeResult = await fileTypeFromBuffer(contentBuffer)\n detectedMime = fileTypeResult?.mime\n isSvg = detectedMime === 'image/svg+xml'\n }\n\n if (isSvg && this.props.color && contentBuffer) {\n const svgString = contentBuffer.toString('utf-8')\n const modifiedSvgString = svgString.replace(/fill=\"[^\"]*\"/g, `fill=\"${this.props.color}\"`)\n\n if (modifiedSvgString !== svgString) {\n finalSource = Buffer.from(modifiedSvgString)\n } else {\n finalSource = contentBuffer\n }\n }\n\n const img = await loadImage(finalSource as never)\n this.loadedImage = img\n this.naturalWidth = img.width\n this.naturalHeight = img.height\n\n const calculatedAspectRatio = this.naturalWidth > 0 && this.naturalHeight > 0 ? this.naturalWidth / this.naturalHeight : undefined\n\n const finalAspectRatio = typeof this.props.aspectRatio === 'number' && this.props.aspectRatio > 0 ? this.props.aspectRatio : calculatedAspectRatio\n\n this.node.setAspectRatio(finalAspectRatio)\n\n this.props.onLoad?.()\n resolve()\n } catch (error: any) {\n this.naturalWidth = 0\n this.naturalHeight = 0\n const finalAspectRatioOnError = typeof this.props.aspectRatio === 'number' && this.props.aspectRatio > 0 ? this.props.aspectRatio : undefined\n this.node.setAspectRatio(finalAspectRatioOnError)\n this.props.onError?.(error)\n resolve()\n }\n }\n load()\n })\n }\n\n public getLoadingPromise(): Promise<void> {\n return this.loadingPromise ?? this.load()\n }\n\n /**\n * Renders the image with correct sizing, clipping, and positioning.\n * Handles object-fit, object-position, and visual effects like saturation.\n */\n protected override _renderContent(ctx: CanvasRenderingContext2D, x: number, y: number, width: number, height: number) {\n super._renderContent(ctx, x, y, width, height)\n\n if (!this.loadedImage || width <= 0 || height <= 0) return\n const img = this.loadedImage\n const imgW = this.naturalWidth\n const imgH = this.naturalHeight\n if (imgW <= 0 || imgH <= 0) return\n\n // Calculate content box accounting for padding and borders\n const paddingLeft = this.node.getComputedPadding(Style.Edge.Left)\n const paddingTop = this.node.getComputedPadding(Style.Edge.Top)\n const paddingRight = this.node.getComputedPadding(Style.Edge.Right)\n const paddingBottom = this.node.getComputedPadding(Style.Edge.Bottom)\n const borderLeft = this.node.getComputedBorder(Style.Edge.Left)\n const borderTop = this.node.getComputedBorder(Style.Edge.Top)\n const borderRight = this.node.getComputedBorder(Style.Edge.Right)\n const borderBottom = this.node.getComputedBorder(Style.Edge.Bottom)\n const contentX = x + borderLeft + paddingLeft\n const contentY = y + borderTop + paddingTop\n const contentWidth = Math.max(0, width - borderLeft - paddingLeft - borderRight - paddingRight)\n const contentHeight = Math.max(0, height - borderTop - paddingTop - borderBottom - paddingBottom)\n\n if (contentWidth <= 0 || contentHeight <= 0) return\n\n // Apply clipping for border radius\n ctx.save()\n const outerRadii = parseBorderRadius(this.props.borderRadius)\n const innerBorderRadii = {\n TopLeft: Math.max(0, outerRadii.TopLeft - borderTop),\n TopRight: Math.max(0, outerRadii.TopRight - borderTop),\n BottomRight: Math.max(0, outerRadii.BottomRight - borderBottom),\n BottomLeft: Math.max(0, outerRadii.BottomLeft - borderBottom),\n }\n const contentRadii = {\n TopLeft: Math.max(0, innerBorderRadii.TopLeft - Math.max(paddingLeft, paddingTop)),\n TopRight: Math.max(0, innerBorderRadii.TopRight - Math.max(paddingRight, paddingTop)),\n BottomRight: Math.max(0, innerBorderRadii.BottomRight - Math.max(paddingRight, paddingBottom)),\n BottomLeft: Math.max(0, innerBorderRadii.BottomLeft - Math.max(paddingLeft, paddingBottom)),\n }\n drawRoundedRectPath(ctx, contentX, contentY, contentWidth, contentHeight, contentRadii)\n ctx.clip()\n\n // Calculate image dimensions based on object-fit\n const nodeRatio = contentWidth / contentHeight\n const imgRatio = imgW / imgH\n const objectFit = this.props.objectFit\n let dw = contentWidth\n let dh = contentHeight\n\n if (objectFit === 'contain') {\n if (imgRatio > nodeRatio) {\n dw = contentWidth\n dh = contentWidth / imgRatio\n } else {\n dh = contentHeight\n dw = contentHeight * imgRatio\n }\n } else if (objectFit === 'cover') {\n if (imgRatio > nodeRatio) {\n dh = contentHeight\n dw = contentHeight * imgRatio\n } else {\n dw = contentWidth\n dh = contentWidth / imgRatio\n }\n } else if (objectFit === 'none') {\n dw = imgW\n dh = imgH\n } else if (objectFit === 'scale-down') {\n if (imgW <= contentWidth && imgH <= contentHeight) {\n dw = imgW\n dh = imgH\n } else {\n if (imgRatio > nodeRatio) {\n dw = contentWidth\n dh = contentWidth / imgRatio\n } else {\n dh = contentHeight\n dw = contentHeight * imgRatio\n }\n }\n }\n\n // Calculate image position based on object-position\n const sx = 0\n const sy = 0\n const sw = imgW\n const sh = imgH\n\n const availableWidth = contentWidth - dw\n const availableHeight = contentHeight - dh\n const posProps = this.props.objectPosition || {}\n const horizontalValue = posProps.Left !== undefined ? posProps.Left : posProps.Right !== undefined ? posProps.Right : '50%'\n const verticalValue = posProps.Top !== undefined ? posProps.Top : posProps.Bottom !== undefined ? posProps.Bottom : '50%'\n\n let offsetX = calculateOffsetFromValue(horizontalValue, availableWidth)\n let offsetY = calculateOffsetFromValue(verticalValue, availableHeight)\n\n if (posProps.Left === undefined && posProps.Right !== undefined) {\n offsetX = availableWidth - offsetX\n }\n if (posProps.Top === undefined && posProps.Bottom !== undefined) {\n offsetY = availableHeight - offsetY\n }\n\n const dx = contentX + offsetX\n const dy = contentY + offsetY\n\n // Draw image with filters\n ctx.save()\n try {\n if (this.props.dropShadow) {\n const shadow = this.props.dropShadow\n const shadowBlur = Math.max(shadow.offsetX ?? 0, shadow.offsetY ?? 0)\n ctx.shadowOffsetX = shadow.offsetX ?? 0\n ctx.shadowOffsetY = shadow.offsetY ?? 0\n ctx.shadowBlur = Math.max(0, shadow.blur ?? shadowBlur)\n ctx.shadowColor = shadow.color ?? 'black'\n }\n\n const saturateValue = this.props.saturate ?? 1\n let filterString = ''\n if (saturateValue !== 1) {\n filterString += `saturate(${saturateValue * 100}%) `\n }\n\n if (filterString) {\n const currentFilter = ctx.filter && ctx.filter !== 'none' ? ctx.filter + ' ' : ''\n ctx.filter = currentFilter + filterString.trim()\n }\n\n const finalDX = Math.floor(dx)\n const finalDY = Math.floor(dy)\n const finalDW = Math.ceil(dw + (dx - finalDX))\n const finalDH = Math.ceil(dh + (dy - finalDY))\n\n if (finalDW > 0 && finalDH > 0) {\n ctx.drawImage(img, sx, sy, sw, sh, finalDX, finalDY, finalDW, finalDH)\n }\n } catch (drawError) {\n console.error('[ImageNode] Error drawing image:', drawError)\n } finally {\n ctx.restore()\n }\n\n ctx.restore()\n }\n}\n\n/**\n * Factory function to create ImageNode instances\n */\nexport const Image = (props: ImageProps): NodeDescriptor => ({\n __type: 'Image',\n props: props as Omit<ImageProps, 'onLoad' | 'onError'>,\n})\n"],"names":["BoxNode","Style","fs","loadImage","parseBorderRadius","drawRoundedRectPath"],"mappings":";;;;;;;;AAOA;;;AAGG;AACH,SAAS,wBAAwB,CAAC,aAAgD,EAAE,cAAsB,EAAA;AACxG,IAAA,MAAM,KAAK,GAAG,aAAa,IAAI,KAAK;AACpC,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC7B,QAAA,OAAO,KAAK;IACd;AACA,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACpD,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,GAAG;QAC1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AAE;gBAC9B,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;YACxE;QACF;QAAE,OAAO,SAAS,EAAE;AAClB,YAAA,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,SAAS,CAAC;QAC9D;gBAAU;YACR,GAAG,CAAC,OAAO,EAAE;QACf;QAEA,GAAG,CAAC,OAAO,EAAE;IACf;AACD;AAED;;AAEG;MACU,KAAK,GAAG,CAAC,KAAiB,MAAsB;AAC3D,IAAA,MAAM,EAAE,OAAO;AACf,IAAA,KAAK,EAAE,KAA+C;AACvD,CAAA;;;;;"}
1
+ {"version":3,"file":"image.canvas.util.js","sources":["../../../../src/canvas/image.canvas.util.ts"],"sourcesContent":["import type { BaseProps, ImageProps, NodeDescriptor } from '@/canvas/canvas.type.js'\nimport { type CanvasRenderingContext2D, Image as CanvasImage, loadImage } from 'skia-canvas'\nimport { BoxNode } from '@/canvas/layout.canvas.util.js'\nimport { drawRoundedRectPath, parseBorderRadius } from '@/canvas/canvas.helper.js'\nimport { promises as fs } from 'fs'\nimport { Style } from '@/constant/common.const.js'\n\n/**\n * Calculates pixel offset for image positioning based on percentage or pixel values.\n * This handles centering, edge alignment, and percentage-based positioning.\n */\nfunction calculateOffsetFromValue(positionValue: number | `${number}%` | undefined, availableSpace: number): number {\n const value = positionValue ?? '50%'\n if (typeof value === 'number') {\n return value\n }\n if (typeof value === 'string' && value.endsWith('%')) {\n const percentage = parseFloat(value) / 100\n return availableSpace * percentage\n }\n console.warn(`[ImageNode] Invalid objectPosition value format: ${value}. Defaulting to 50%.`)\n return availableSpace * 0.5\n}\n\n/**\n * Per-render image cache — keyed by `src|color` for string sources.\n * Scoped to a single RootNode.render() call; discarded after rendering.\n */\nexport type RenderImageCache = Map<string, Promise<CanvasImage>>\n\n/**\n * Renders images with configurable sizing, positioning, and effects.\n * Supports object-fit modes, positioning, border radius, and saturation filters.\n */\nexport class ImageNode extends BoxNode {\n declare props: ImageProps & BaseProps\n private loadedImage: CanvasImage | null = null\n private naturalWidth = 0\n private naturalHeight = 0\n private loadingPromise: Promise<void> | null = null\n\n constructor(props: ImageProps) {\n super({ name: 'Image', ...props, children: undefined })\n\n this.props = {\n objectFit: 'fill',\n overflow: Style.Overflow.Hidden,\n saturate: 1,\n objectPosition: { Left: '50%', Top: '50%' },\n ...props,\n }\n }\n\n public load(cache?: RenderImageCache): Promise<void> {\n if (!this.loadingPromise) {\n this.loadingPromise = this._loadImage(cache)\n }\n return this.loadingPromise\n }\n\n /**\n * Fetches and processes the image source into a CanvasImage.\n * Does not touch node state — pure fetch logic.\n */\n private async _fetchCanvasImage(): Promise<CanvasImage> {\n const { fileTypeFromBuffer, fileTypeFromFile } = await import('file-type')\n let finalSource: string | Buffer = this.props.src\n let isSvg = false\n let contentBuffer: Buffer | null = null\n let detectedMime: string | undefined\n\n if (typeof this.props.src === 'string') {\n if (this.props.src.startsWith('http')) {\n const response = await fetch(this.props.src)\n if (!response.ok) {\n throw new Error(`HTTP error ${response.status} fetching image: ${this.props.src}`)\n }\n const imageArrayBuffer = await response.arrayBuffer()\n contentBuffer = Buffer.from(imageArrayBuffer)\n finalSource = contentBuffer\n\n const fileTypeResult = await fileTypeFromBuffer(contentBuffer)\n detectedMime = fileTypeResult?.mime\n isSvg = detectedMime === 'image/svg+xml'\n\n if ((!detectedMime || detectedMime === 'application/xml') && contentBuffer.toString('utf-8').includes('<svg')) {\n isSvg = true\n }\n } else {\n finalSource = this.props.src\n const filePath = this.props.src\n\n try {\n const fileTypeResult = await fileTypeFromFile(filePath)\n detectedMime = fileTypeResult?.mime\n isSvg = detectedMime === 'image/svg+xml'\n\n if ((!detectedMime || detectedMime === 'application/xml') && filePath.toLowerCase().endsWith('.svg')) {\n isSvg = true\n }\n } catch {\n isSvg = filePath.toLowerCase().endsWith('.svg')\n }\n\n if (isSvg && this.props.color) {\n try {\n contentBuffer = await fs.readFile(filePath)\n } catch {\n isSvg = false\n contentBuffer = null\n }\n }\n }\n } else {\n contentBuffer = this.props.src\n finalSource = contentBuffer\n\n const fileTypeResult = await fileTypeFromBuffer(contentBuffer)\n detectedMime = fileTypeResult?.mime\n isSvg = detectedMime === 'image/svg+xml'\n }\n\n if (isSvg && this.props.color && contentBuffer) {\n const svgString = contentBuffer.toString('utf-8')\n const modifiedSvgString = svgString.replace(/fill=\"[^\"]*\"/g, `fill=\"${this.props.color}\"`)\n finalSource = modifiedSvgString !== svgString ? Buffer.from(modifiedSvgString) : contentBuffer\n }\n\n return loadImage(finalSource as never)\n }\n\n /**\n * Loads and processes an image, using the render-scoped cache to avoid\n * re-fetching the same source within a single render pass.\n */\n private _loadImage(cache?: RenderImageCache): Promise<void> {\n if (!this.props.src) {\n const aspectRatioFromProps = typeof this.props.aspectRatio === 'number' && this.props.aspectRatio > 0 ? this.props.aspectRatio : undefined\n this.node.setAspectRatio(aspectRatioFromProps)\n this.naturalWidth = 0\n this.naturalHeight = 0\n return Promise.resolve()\n }\n\n return new Promise(resolve => {\n const load = async () => {\n try {\n let imagePromise: Promise<CanvasImage>\n\n if (cache && typeof this.props.src === 'string') {\n const cacheKey = this.props.color ? `${this.props.src}|${this.props.color}` : this.props.src\n if (!cache.has(cacheKey)) {\n cache.set(cacheKey, this._fetchCanvasImage())\n }\n imagePromise = cache.get(cacheKey)!\n } else {\n imagePromise = this._fetchCanvasImage()\n }\n\n const img = await imagePromise\n this.loadedImage = img\n this.naturalWidth = img.width\n this.naturalHeight = img.height\n\n const calculatedAspectRatio = this.naturalWidth > 0 && this.naturalHeight > 0 ? this.naturalWidth / this.naturalHeight : undefined\n const finalAspectRatio = typeof this.props.aspectRatio === 'number' && this.props.aspectRatio > 0 ? this.props.aspectRatio : calculatedAspectRatio\n\n this.node.setAspectRatio(finalAspectRatio)\n this.props.onLoad?.()\n resolve()\n } catch (error: any) {\n this.naturalWidth = 0\n this.naturalHeight = 0\n const finalAspectRatioOnError = typeof this.props.aspectRatio === 'number' && this.props.aspectRatio > 0 ? this.props.aspectRatio : undefined\n this.node.setAspectRatio(finalAspectRatioOnError)\n this.props.onError?.(error)\n resolve()\n }\n }\n load()\n })\n }\n\n public getLoadingPromise(): Promise<void> {\n return this.loadingPromise ?? this.load()\n }\n\n /**\n * Renders the image with correct sizing, clipping, and positioning.\n * Handles object-fit, object-position, and visual effects like saturation.\n */\n protected override _renderContent(ctx: CanvasRenderingContext2D, x: number, y: number, width: number, height: number) {\n super._renderContent(ctx, x, y, width, height)\n\n if (!this.loadedImage || width <= 0 || height <= 0) return\n const img = this.loadedImage\n const imgW = this.naturalWidth\n const imgH = this.naturalHeight\n if (imgW <= 0 || imgH <= 0) return\n\n // Calculate content box accounting for padding and borders\n const paddingLeft = this.node.getComputedPadding(Style.Edge.Left)\n const paddingTop = this.node.getComputedPadding(Style.Edge.Top)\n const paddingRight = this.node.getComputedPadding(Style.Edge.Right)\n const paddingBottom = this.node.getComputedPadding(Style.Edge.Bottom)\n const borderLeft = this.node.getComputedBorder(Style.Edge.Left)\n const borderTop = this.node.getComputedBorder(Style.Edge.Top)\n const borderRight = this.node.getComputedBorder(Style.Edge.Right)\n const borderBottom = this.node.getComputedBorder(Style.Edge.Bottom)\n const contentX = x + borderLeft + paddingLeft\n const contentY = y + borderTop + paddingTop\n const contentWidth = Math.max(0, width - borderLeft - paddingLeft - borderRight - paddingRight)\n const contentHeight = Math.max(0, height - borderTop - paddingTop - borderBottom - paddingBottom)\n\n if (contentWidth <= 0 || contentHeight <= 0) return\n\n // Apply clipping for border radius\n ctx.save()\n const outerRadii = parseBorderRadius(this.props.borderRadius)\n const innerBorderRadii = {\n TopLeft: Math.max(0, outerRadii.TopLeft - borderTop),\n TopRight: Math.max(0, outerRadii.TopRight - borderTop),\n BottomRight: Math.max(0, outerRadii.BottomRight - borderBottom),\n BottomLeft: Math.max(0, outerRadii.BottomLeft - borderBottom),\n }\n const contentRadii = {\n TopLeft: Math.max(0, innerBorderRadii.TopLeft - Math.max(paddingLeft, paddingTop)),\n TopRight: Math.max(0, innerBorderRadii.TopRight - Math.max(paddingRight, paddingTop)),\n BottomRight: Math.max(0, innerBorderRadii.BottomRight - Math.max(paddingRight, paddingBottom)),\n BottomLeft: Math.max(0, innerBorderRadii.BottomLeft - Math.max(paddingLeft, paddingBottom)),\n }\n drawRoundedRectPath(ctx, contentX, contentY, contentWidth, contentHeight, contentRadii)\n ctx.clip()\n\n // Calculate image dimensions based on object-fit\n const nodeRatio = contentWidth / contentHeight\n const imgRatio = imgW / imgH\n const objectFit = this.props.objectFit\n let dw = contentWidth\n let dh = contentHeight\n\n if (objectFit === 'contain') {\n if (imgRatio > nodeRatio) {\n dw = contentWidth\n dh = contentWidth / imgRatio\n } else {\n dh = contentHeight\n dw = contentHeight * imgRatio\n }\n } else if (objectFit === 'cover') {\n if (imgRatio > nodeRatio) {\n dh = contentHeight\n dw = contentHeight * imgRatio\n } else {\n dw = contentWidth\n dh = contentWidth / imgRatio\n }\n } else if (objectFit === 'none') {\n dw = imgW\n dh = imgH\n } else if (objectFit === 'scale-down') {\n if (imgW <= contentWidth && imgH <= contentHeight) {\n dw = imgW\n dh = imgH\n } else {\n if (imgRatio > nodeRatio) {\n dw = contentWidth\n dh = contentWidth / imgRatio\n } else {\n dh = contentHeight\n dw = contentHeight * imgRatio\n }\n }\n }\n\n // Calculate image position based on object-position\n const sx = 0\n const sy = 0\n const sw = imgW\n const sh = imgH\n\n const availableWidth = contentWidth - dw\n const availableHeight = contentHeight - dh\n const posProps = this.props.objectPosition || {}\n const horizontalValue = posProps.Left !== undefined ? posProps.Left : posProps.Right !== undefined ? posProps.Right : '50%'\n const verticalValue = posProps.Top !== undefined ? posProps.Top : posProps.Bottom !== undefined ? posProps.Bottom : '50%'\n\n let offsetX = calculateOffsetFromValue(horizontalValue, availableWidth)\n let offsetY = calculateOffsetFromValue(verticalValue, availableHeight)\n\n if (posProps.Left === undefined && posProps.Right !== undefined) {\n offsetX = availableWidth - offsetX\n }\n if (posProps.Top === undefined && posProps.Bottom !== undefined) {\n offsetY = availableHeight - offsetY\n }\n\n const dx = contentX + offsetX\n const dy = contentY + offsetY\n\n // Draw image with filters\n ctx.save()\n try {\n if (this.props.dropShadow) {\n const shadow = this.props.dropShadow\n const shadowBlur = Math.max(shadow.offsetX ?? 0, shadow.offsetY ?? 0)\n ctx.shadowOffsetX = shadow.offsetX ?? 0\n ctx.shadowOffsetY = shadow.offsetY ?? 0\n ctx.shadowBlur = Math.max(0, shadow.blur ?? shadowBlur)\n ctx.shadowColor = shadow.color ?? 'black'\n }\n\n const saturateValue = this.props.saturate ?? 1\n let filterString = ''\n if (saturateValue !== 1) {\n filterString += `saturate(${saturateValue * 100}%) `\n }\n\n if (filterString) {\n const currentFilter = ctx.filter && ctx.filter !== 'none' ? ctx.filter + ' ' : ''\n ctx.filter = currentFilter + filterString.trim()\n }\n\n const finalDX = Math.floor(dx)\n const finalDY = Math.floor(dy)\n const finalDW = Math.ceil(dw + (dx - finalDX))\n const finalDH = Math.ceil(dh + (dy - finalDY))\n\n if (finalDW > 0 && finalDH > 0) {\n ctx.drawImage(img, sx, sy, sw, sh, finalDX, finalDY, finalDW, finalDH)\n }\n } catch (drawError) {\n console.error('[ImageNode] Error drawing image:', drawError)\n } finally {\n ctx.restore()\n }\n\n ctx.restore()\n }\n}\n\n/**\n * Factory function to create ImageNode instances\n */\nexport const Image = (props: ImageProps): NodeDescriptor => ({\n __type: 'Image',\n props: props as Omit<ImageProps, 'onLoad' | 'onError'>,\n})\n"],"names":["BoxNode","Style","fs","loadImage","parseBorderRadius","drawRoundedRectPath"],"mappings":";;;;;;;;AAOA;;;AAGG;AACH,SAAS,wBAAwB,CAAC,aAAgD,EAAE,cAAsB,EAAA;AACxG,IAAA,MAAM,KAAK,GAAG,aAAa,IAAI,KAAK;AACpC,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC7B,QAAA,OAAO,KAAK;IACd;AACA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EAAE,UAAU,EAAE,OAAO,EAAW,MAAM,gCAAgC,CAAA;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAiBnF,eAAO,MAAM,qBAAqB,YAEjC,CAAA;AAOD,MAAM,WAAW,kBAAkB;IACjC,uFAAuF;IACvF,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,kBAAkB,QAMpD;AA2LD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO,CAmB7D;AAED;;;GAGG;AACH,qBAAa,QAAS,SAAQ,UAAU;IACtC,6CAA6C;IAC7C,OAAO,CAAC,MAAM,CAAoB;IAClC,8CAA8C;IAC9C,OAAO,CAAC,GAAG,CAAwC;IACnD,4CAA4C;IAC5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,6CAA6C;IAC7C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAQ;IACrC,4DAA4D;IAC5D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAE9B;;;;OAIG;gBACS,KAAK,EAAE,SAAS,GAAG,SAAS;IAoDxC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAazB;;;;OAIG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;CA6ChC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,GAAU,OAAO,SAAS,KAAG,OAAO,CAAC,MAAM,CAS3D,CAAA"}
@@ -54,22 +54,77 @@ function configure(options) {
54
54
  }
55
55
  }
56
56
  /**
57
- * Minimal Canvas-compatible wrapper returned when rendering in worker mode.
58
- * Exposes toBuffer / toBufferSync so callers can use the result identically.
57
+ * Proxies all skia-canvas Canvas APIs to a Canvas instance living inside a worker thread.
58
+ * Sync methods (toBufferSync, toURLSync) return from a pre-encoded PNG buffer.
59
+ * Async methods (toBuffer, toURL, toFile, getters) delegate to the worker.
59
60
  */
60
61
  class WorkerCanvas {
61
- _buffer;
62
- constructor(_buffer) {
63
- this._buffer = _buffer;
62
+ width;
63
+ height;
64
+ _buffer; // pre-encoded PNG for sync use
65
+ _pool;
66
+ _workerIdx;
67
+ _canvasId;
68
+ constructor(opts) {
69
+ this._buffer = opts.buffer;
70
+ this.width = opts.width;
71
+ this.height = opts.height;
72
+ this._pool = opts.pool;
73
+ this._workerIdx = opts.workerIdx;
74
+ this._canvasId = opts.canvasId;
64
75
  }
65
- toBufferSync(_format) {
76
+ _call(method, ...args) {
77
+ return this._pool.callOnCanvas(this._workerIdx, this._canvasId, method, args);
78
+ }
79
+ // --- Sync methods: return from pre-encoded PNG buffer ---
80
+ toBufferSync(_format, _options) {
66
81
  return this._buffer;
67
82
  }
68
- toBuffer(_format) {
69
- return Promise.resolve(this._buffer);
83
+ toURLSync(_format, _options) {
84
+ return `data:image/png;base64,${this._buffer.toString('base64')}`;
85
+ }
86
+ // --- Async methods: delegate to worker ---
87
+ toBuffer(format, options) {
88
+ return this._call('toBuffer', format, options);
89
+ }
90
+ toURL(format, options) {
91
+ return this._call('toURL', format, options);
92
+ }
93
+ toFile(filename, options) {
94
+ return this._call('toFile', filename, options);
95
+ }
96
+ /** Returns a Buffer (Sharp instance cannot be transferred across threads) */
97
+ toSharp(options) {
98
+ return this._call('toSharp', options);
99
+ }
100
+ toSharpSync(_options) {
101
+ throw new Error('[canvas] toSharpSync() is not available in worker mode — use toSharp() instead');
102
+ }
103
+ // --- Async convenience getters ---
104
+ get png() {
105
+ return this._call('toBuffer', 'png');
106
+ }
107
+ get webp() {
108
+ return this._call('toBuffer', 'webp');
109
+ }
110
+ get jpg() {
111
+ return this._call('toBuffer', 'jpg');
112
+ }
113
+ get svg() {
114
+ return this._call('toBuffer', 'svg');
115
+ }
116
+ get pdf() {
117
+ return this._call('toBuffer', 'pdf');
118
+ }
119
+ get raw() {
120
+ return this._call('toBuffer', 'raw');
121
+ }
122
+ /** Release the Canvas from worker memory. Call when done with this object. */
123
+ release() {
124
+ this._pool.releaseCanvas(this._workerIdx, this._canvasId);
70
125
  }
71
126
  }
72
- /** Lazy-instantiated worker pool singleton */
127
+ /** Worker thread pool routes render and canvas-call messages */
73
128
  class WorkerPool {
74
129
  workers = [];
75
130
  idle = [];
@@ -79,22 +134,30 @@ class WorkerPool {
79
134
  constructor(size) {
80
135
  this.init(size);
81
136
  }
82
- async init(size) {
137
+ init(size) {
83
138
  const workerFile = path__namespace.join(path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('canvas/root.canvas.util.js', document.baseURI).href)))), '../render.worker.js');
84
139
  for (let i = 0; i < size; i++) {
140
+ const workerIdx = i;
85
141
  const worker = new node_worker_threads.Worker(workerFile);
86
- worker.on('message', ({ id, buffer, error }) => {
87
- const task = this.pending.get(id);
142
+ worker.on('message', (msg) => {
143
+ const task = this.pending.get(msg.taskId);
88
144
  if (!task)
89
145
  return;
90
- this.pending.delete(id);
91
- this.idle.push(worker);
92
- this.drain();
93
- if (error) {
94
- task.reject(new Error(error));
146
+ this.pending.delete(msg.taskId);
147
+ if ('error' in msg) {
148
+ task.reject(new Error(msg.error));
149
+ return;
150
+ }
151
+ if ('canvasId' in msg) {
152
+ // Render complete — put worker back to idle
153
+ this.idle.push(worker);
154
+ this.drain();
155
+ const result = { buffer: msg.buffer, canvasId: msg.canvasId, workerIdx, width: msg.width, height: msg.height };
156
+ task.resolve(result);
95
157
  }
96
158
  else {
97
- task.resolve(buffer);
159
+ // Canvas method call complete
160
+ task.resolve(msg.result);
98
161
  }
99
162
  });
100
163
  this.workers.push(worker);
@@ -105,22 +168,36 @@ class WorkerPool {
105
168
  while (this.queue.length > 0 && this.idle.length > 0) {
106
169
  const task = this.queue.shift();
107
170
  const worker = this.idle.pop();
108
- worker.postMessage({ id: task.id, props: task.props });
171
+ const request = { type: 'render', taskId: task.id, props: task.props };
172
+ worker.postMessage(request);
109
173
  }
110
174
  }
111
175
  render(props) {
112
176
  return new Promise((resolve, reject) => {
113
177
  const id = this.nextId++;
114
- this.pending.set(id, { resolve, reject });
178
+ this.pending.set(id, { resolve: resolve, reject });
115
179
  if (this.idle.length > 0) {
116
180
  const worker = this.idle.pop();
117
- worker.postMessage({ id, props });
181
+ const request = { type: 'render', taskId: id, props };
182
+ worker.postMessage(request);
118
183
  }
119
184
  else {
120
185
  this.queue.push({ id, props });
121
186
  }
122
187
  });
123
188
  }
189
+ callOnCanvas(workerIdx, canvasId, method, args) {
190
+ return new Promise((resolve, reject) => {
191
+ const id = this.nextId++;
192
+ this.pending.set(id, { resolve: resolve, reject });
193
+ const request = { type: 'call', taskId: id, canvasId, method, args };
194
+ this.workers[workerIdx].postMessage(request);
195
+ });
196
+ }
197
+ releaseCanvas(workerIdx, canvasId) {
198
+ const request = { type: 'release', canvasId };
199
+ this.workers[workerIdx]?.postMessage(request);
200
+ }
124
201
  terminate() {
125
202
  this.workers.forEach(w => w.terminate());
126
203
  }
@@ -234,15 +311,17 @@ class RootNode extends layout_canvas_util.ColumnNode {
234
311
  * @returns Promise resolving to the rendered Canvas instance
235
312
  */
236
313
  async render() {
237
- // Step 1: Load all images with a concurrency limit to avoid overwhelming remote sources
314
+ // Step 1: Load all images with a concurrency limit to avoid overwhelming remote sources.
315
+ // A per-render cache deduplicates identical src+color combinations within this render pass.
238
316
  const imageNodes = this.findAllImageNodes();
239
317
  if (imageNodes.length > 0) {
318
+ const imageCache = new Map();
240
319
  const CONCURRENCY = 5;
241
320
  const queue = [...imageNodes];
242
321
  const workers = Array.from({ length: Math.min(CONCURRENCY, queue.length) }, async () => {
243
322
  while (queue.length > 0) {
244
323
  const node = queue.shift();
245
- await node.load();
324
+ await node.load(imageCache);
246
325
  }
247
326
  });
248
327
  await Promise.allSettled(workers);
@@ -282,8 +361,8 @@ const Root = async (props) => {
282
361
  if (!_workerPool) {
283
362
  _workerPool = new WorkerPool(_workerPoolSize);
284
363
  }
285
- const buffer = await _workerPool.render(props);
286
- return new WorkerCanvas(buffer);
364
+ const result = await _workerPool.render(props);
365
+ return new WorkerCanvas({ ...result, pool: _workerPool });
287
366
  }
288
367
  return new RootNode(props).render();
289
368
  };