mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
chore(ui): clean up unused files/packages
This commit is contained in:
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copies an image to the clipboard by drawing it to a canvas and then
|
||||
* calling toBlob() on the canvas.
|
||||
*/
|
||||
const copyImage = (url: string, width: number, height: number) => {
|
||||
const imageElement = document.createElement('img');
|
||||
|
||||
imageElement.addEventListener('load', () => {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
const context = canvas.getContext('2d');
|
||||
|
||||
if (!context) return;
|
||||
|
||||
context.drawImage(imageElement, 0, 0);
|
||||
|
||||
canvas.toBlob((blob) => {
|
||||
blob &&
|
||||
navigator.clipboard.write([
|
||||
new ClipboardItem({
|
||||
[blob.type]: blob,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
canvas.remove();
|
||||
imageElement.remove();
|
||||
});
|
||||
|
||||
imageElement.src = url;
|
||||
};
|
||||
|
||||
export default copyImage;
|
@ -1,14 +0,0 @@
|
||||
/**
|
||||
* Downloads a file, given its URL.
|
||||
*/
|
||||
const downloadFile = (url: string) => {
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = '';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
a.remove();
|
||||
};
|
||||
|
||||
export default downloadFile;
|
@ -1,53 +0,0 @@
|
||||
import Konva from 'konva';
|
||||
import { IRect, Vector2d } from 'konva/lib/types';
|
||||
|
||||
const layerToDataURL = (
|
||||
layer: Konva.Layer,
|
||||
stageScale: number,
|
||||
stageCoordinates: Vector2d,
|
||||
boundingBox?: IRect
|
||||
) => {
|
||||
const tempScale = layer.scale();
|
||||
|
||||
const relativeClientRect = layer.getClientRect({
|
||||
relativeTo: layer.getParent(),
|
||||
});
|
||||
|
||||
// Scale the canvas before getting it as a Blob
|
||||
layer.scale({
|
||||
x: 1 / stageScale,
|
||||
y: 1 / stageScale,
|
||||
});
|
||||
|
||||
const { x, y, width, height } = layer.getClientRect();
|
||||
const dataURLBoundingBox = boundingBox
|
||||
? {
|
||||
x: boundingBox.x + stageCoordinates.x,
|
||||
y: boundingBox.y + stageCoordinates.y,
|
||||
width: boundingBox.width,
|
||||
height: boundingBox.height,
|
||||
}
|
||||
: {
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height,
|
||||
};
|
||||
|
||||
const dataURL = layer.toDataURL(dataURLBoundingBox);
|
||||
|
||||
// Unscale the canvas
|
||||
layer.scale(tempScale);
|
||||
|
||||
return {
|
||||
dataURL,
|
||||
boundingBox: {
|
||||
x: relativeClientRect.x,
|
||||
y: relativeClientRect.y,
|
||||
width: width,
|
||||
height: height,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default layerToDataURL;
|
Reference in New Issue
Block a user