klecks
klecks copied to clipboard
Uncaught Error: Already created an embed
I'm trying to embed Kleki into the next Js project but getting this error
Uncaught Error: Already created an embed
code: ` if (typeof window !== "undefined" && typeof window.Klecks !== "undefined") { const klecks = new Klecks({ onSubmit: (onSuccess, onError) => { console.log(klecks.getPNG()) klecks.getPSD().then((blob) => { console.log(blob) });
setTimeout(() => {
onSuccess();
}, 500);
}
});
if (psdURL) {
console.log("in psdUrl")
fetch(new Request(psdURL)).then(response => {
return response.arrayBuffer();
}).then(buffer => {
return klecks.readPSD(buffer); // resolves to Klecks project
}).then(project => {
klecks.openProject(project);
}).catch(e => {
klecks.initError('failed to read image');
});
} else {
klecks.openProject({
width: 500,
height: 500,
layers: [{
name: 'Background',
opacity: 1,
mixModeStr: 'source-over',
image: (() => {
const canvas = document.createElement('canvas');
canvas.width = 500;
canvas.height = 500;
const ctx = canvas.getContext('2d');
ctx.save();
ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.restore();
return canvas;
})(),
}]
});
}
}
`
So far I've made no effort to support React/Next.js. I'd be surprised if it works out of the box. You need to be careful to not execute Kleck's initialization logic twice. Also Klecks has no destructor yet.
At some point I will look into this.