Enhance canvas functionality with new node types and validation
- Added support for new canvas node types: curves, color-adjust, light-adjust, detail-adjust, and render. - Implemented validation for adjustment nodes to restrict incoming edges to one. - Updated canvas connection validation to improve user feedback on invalid connections. - Enhanced node creation and rendering logic to accommodate new node types and their properties. - Refactored related components and utilities for better maintainability and performance.
This commit is contained in:
35
lib/image-pipeline/source-loader.ts
Normal file
35
lib/image-pipeline/source-loader.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
const imageBitmapCache = new Map<string, Promise<ImageBitmap>>();
|
||||
|
||||
export async function loadSourceBitmap(sourceUrl: string): Promise<ImageBitmap> {
|
||||
if (!sourceUrl || sourceUrl.trim().length === 0) {
|
||||
throw new Error("Render sourceUrl is required.");
|
||||
}
|
||||
|
||||
if (typeof createImageBitmap !== "function") {
|
||||
throw new Error("ImageBitmap is not available in this environment.");
|
||||
}
|
||||
|
||||
const cached = imageBitmapCache.get(sourceUrl);
|
||||
if (cached) {
|
||||
return await cached;
|
||||
}
|
||||
|
||||
const promise = (async () => {
|
||||
const response = await fetch(sourceUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Render source failed: ${response.status}`);
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
return await createImageBitmap(blob);
|
||||
})();
|
||||
|
||||
imageBitmapCache.set(sourceUrl, promise);
|
||||
|
||||
try {
|
||||
return await promise;
|
||||
} catch (error) {
|
||||
imageBitmapCache.delete(sourceUrl);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user