bitbof / klecks

Community funded painting tool powering Kleki.com
https://klecks.org
MIT License
220 stars 69 forks source link

Uncaught Error: Already created an embed #62

Open yuvrajchaudhari03 opened 1 year ago

yuvrajchaudhari03 commented 1 year ago

I'm trying to embed Kleki into the next Js project but getting this error

Uncaught Error: Already created an embed

Screenshot 2023-01-30 at 10 26 16 AM

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;
                })(),
            }]
        });
    }
}

`

bitbof commented 1 year ago

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.