{
const canvas = () => {
const w = 600,
h = 400;
const c = html`<canvas draggable=true width=${w} height=${h}>`.getContext(
'2d'
);
c.canvas.ondragstart = e => {
const t = e.dataTransfer;
t.setData('text/foo', 'bar');
t.setData('text/uri-list', c.canvas.toDataURL());
};
const g = c.createLinearGradient(0, 0, w, h);
g.addColorStop(0, '#c00');
g.addColorStop(1, '#fe0');
c.fillStyle = g;
c.fillRect(0, 0, w, h);
return c.canvas;
};
const d = document.querySelector('#' + id);
d.textContent = '';
Array.from({ length: 20 }, (v, i) => i).map(n => {
const div = html`<figure>
<canvas width='100' height='100' id='canvas-${n}'></canvas>
<figurecaption><input/>Canvas ${n}</figurecaption>
</figure>`;
const ctx = div.children[0].getContext('2d');
ctx.canvas.onmousemove = ctx.canvas.ontouchmove = evt =>
ctx.fillRect(evt.layerX, evt.layerY, 10, 10);
d.appendChild(div);
});
return d;
}