dvorak321 / gbfr-parser

6 stars 3 forks source link

What about a copy to clipboard button? #5

Open brunolm opened 8 months ago

brunolm commented 8 months ago

yarn add html2canvas

  let mainDiv: HTMLElement;
  async function capture() {
    const canvas = await html2canvas(mainDiv);
    const blob = await new Promise(resolve => canvas.toBlob(resolve, 'image/png'));

    try {
        await navigator.clipboard.write([
            new ClipboardItem({
              'image/png': blob
            } as any)
        ]);
        console.log('Image copied to clipboard');
    } catch (err) {
        console.error(err);
    }
  }

    <button id="capture" on:click={capture}>
      Copy
    </button>