{
item.setContainerRef(node);
this.attachObserver(node);
}}
className={containerClassName}
style={containerStyle}
>
{
this.filler = node;
}}
className={styles.filler}
style={{ width: "100%", marginTop: item.fillerHeight }}
/>
{
item.setImageRef(ref);
this.imageRef.current = ref;
}}
usedValue={item.usedValue}
imageEntity={item.currentImageEntity}
imageTransform={item.imageTransform}
updateImageSize={item.updateImageSize}
size={item.canvasSize}
overlay={}
/>
{/* @todo this is dirty hack; rewrite to proper async waiting for data to load */}
{stageLoading || !toolsReady ? (
) : imageIsLoaded ? (
{
if (this.crosshairRef.current) {
this.crosshairRef.current.updateVisibility(true);
}
}}
onMouseLeave={(e) => {
if (this.crosshairRef.current) {
this.crosshairRef.current.updateVisibility(false);
}
const { width: stageWidth, height: stageHeight } = item.canvasSize;
const { offsetX: mouseposX, offsetY: mouseposY } = e.evt;
const newEvent = { ...e };
if (mouseposX <= 0) {
e.offsetX = 0;
} else if (mouseposX >= stageWidth) {
e.offsetX = stageWidth;
}
if (mouseposY <= 0) {
e.offsetY = 0;
} else if (mouseposY >= stageHeight) {
e.offsetY = stageHeight;
}
this.handleMouseMove(newEvent);
}}
onDragMove={this.updateCrosshair}
onMouseDown={this.handleMouseDown}
onMouseMove={this.handleMouseMove}
onMouseUp={this.handleMouseUp}
onWheel={item.zoom ? this.handleZoom : () => {}}
/>
) : null}
{toolsReady && imageIsLoaded && this.renderTools()}
{item.images.length > 1 && (
{item.images.map((src, i) => (

item.setCurrentImage(i)}
/>
))}
)}
);
}
},
);
const EntireStage = observer(
({
item,
imagePositionClassnames,
state,
onClick,
onMouseEnter,
onMouseLeave,
onDragMove,
onMouseDown,
onMouseMove,
onMouseUp,
onWheel,
crosshairRef,
}) => {
const { store } = item;
let size;
let position;
if (isFF(FF_ZOOM_OPTIM)) {
size = {
width: item.containerWidth,
height: item.containerHeight,
};
position = {
x: item.zoomingPositionX + item.alignmentOffset.x,
y: item.zoomingPositionY + item.alignmentOffset.y,
};
} else {
size = { ...item.canvasSize };
position = {
x: item.zoomingPositionX,
y: item.zoomingPositionY,
};
}
return (
{
item.setStageRef(ref);
}}
className={[styles["image-element"], ...imagePositionClassnames].join(" ")}
width={size.width}
height={size.height}
scaleX={item.zoomScale}
scaleY={item.zoomScale}
x={position.x}
y={position.y}
offsetX={item.stageTranslate.x}
offsetY={item.stageTranslate.y}
rotation={item.rotation}
onClick={onClick}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onDragMove={onDragMove}
onMouseDown={onMouseDown}
onMouseMove={onMouseMove}
onMouseUp={onMouseUp}
onWheel={onWheel}
>
);
},
);
const ImageLayer = observer(({ item }) => {
const imageEntity = item.currentImageEntity;
const konvaImageRef = useRef();
const currentSrc = imageEntity?.currentSrc;
const [loadedImage, setLoadedImage] = useState(null);
useEffect(() => {
if (!imageEntity?.downloaded || !currentSrc) {
setLoadedImage(null);
return;
}
let cancelled = false;
const img = new window.Image();
if (item.imageCrossOrigin) img.crossOrigin = item.imageCrossOrigin;
img.onload = () => {
if (!cancelled) setLoadedImage(img);
};
img.onerror = () => {
if (!cancelled) setLoadedImage(null);
};
img.src = currentSrc;
return () => {
cancelled = true;
img.src = ""; // Defensively immediately clear source to abandon decode and trigger GC
};
}, [imageEntity?.downloaded, currentSrc, item.imageCrossOrigin]);
const { width, height } = useMemo(() => {
return {
width: imageEntity.naturalWidth,
height: imageEntity.naturalHeight,
};
}, [imageEntity.naturalWidth, imageEntity.naturalHeight, item.stageWidth, item.stageHeight]);
const brightness = mapKonvaBrightness(imageEntity.brightnessGrade);
const contrast = imageEntity.contrastGrade - 100;
useEffect(() => {
const node = konvaImageRef.current;
if (node && loadedImage) {
try {
// Force Konva cache reset and redraw when source/filters change.
node.clearCache();
node.cache({ pixelRatio: 1 });
node.filters([Konva.Filters.Brighten, Konva.Filters.Contrast]);
node.brightness(brightness);
node.contrast(contrast);
} catch {
// Fallback to plain image draw if cache/filter pipeline fails.
node.clearCache();
node.filters([]);
}
node.getLayer()?.batchDraw();
}
}, [loadedImage, brightness, contrast, currentSrc]);
return loadedImage ? (
) : null;
});
const CursorLayer = observer(({ item, tool }) => {
const [[x, y], setCursorPosition] = useState([0, 0]);
const [visible, setVisible] = useState(false);
useEffect(() => {
if (!item.stageRef) return;
const stage = item.stageRef;
const onMouseMove = (e) => {
const { x, y } = stage.getPointerPosition();
const { x: deltaX, y: deltaY } = stage.position();
const { x: scaleX, y: scaleY } = stage.scale();
setCursorPosition([(x - deltaX) / scaleX, (y - deltaY) / scaleY]);
};
const onMouseEnter = () => {
setVisible(true);
};
const onMouseLeave = () => {
setVisible(false);
};
stage.on("mousemove", onMouseMove);
stage.on("mouseenter", onMouseEnter);
stage.on("mouseleave", onMouseLeave);
return () => {
stage.off("mousemove", onMouseMove);
stage.off("mouseenter", onMouseEnter);
stage.off("mouseleave", onMouseLeave);
};
}, [item.stageRef]);
const size = useMemo(() => {
return tool.strokeWidth * item.stageZoom;
}, [tool.strokeWidth, item.stageZoom]);
return visible ? (
{tool.strokeWidth <= 2 ? (
<>
>
) : (
<>
>
)}
) : null;
});
const StageContent = observer(({ item, store, state, crosshairRef }) => {
if (!isAlive(item)) return null;
if (!store.task || !item.currentSrc) return null;
// Keep selected or highlighted region on top
const regions = [...item.regs].sort((r) => (r.highlighted || r.selected ? 1 : -1));
const paginationEnabled = !!item.isMultiItem;
const wrapperClasses = [styles.wrapperComponent, item.images.length > 1 ? styles.withGallery : styles.wrapper];
const tool = item.getToolsManager().findSelectedTool();
if (paginationEnabled) wrapperClasses.push(styles.withPagination);
const { brushRegions, shapeRegions, bitmaskRegions } = splitRegions(regions);
const {
brushRegions: suggestedBrushRegions,
shapeRegions: suggestedShapeRegions,
bitmaskRegions: suggestedBitmaskRegions,
} = splitRegions(item.suggestions);
const renderableRegions = Object.entries({
brush: brushRegions,
shape: shapeRegions,
bitmask: bitmaskRegions,
suggestedBrush: suggestedBrushRegions,
suggestedBismask: suggestedBitmaskRegions,
suggestedShape: suggestedShapeRegions,
});
return (
<>
{item.grid && item.sizeUpdated &&
}
{isFF(FF_LSDV_4930) ?
: null}
{renderableRegions.map(([groupName, list]) => {
const useLayers = true;
const isSuggestion = groupName.match("suggested") !== null;
return list.length > 0 ? (
) : (
);
})}
{item.smoothingEnabled === false &&
}
{item.crosshair && (
)}
{tool && tool.toolName?.match(/bitmask/i) &&
}
>
);
});