Loading…

Online coloring
'; document.body.appendChild(frame); }catch(e){if(frame)frame.remove();activePrintFrame=null;status(text.print_error)} }; window.addEventListener('pagehide',persist);document.addEventListener('visibilitychange',()=>{if(document.visibilityState==='hidden')persist()}); window.addEventListener('beforeunload',e=>{if(changed){persist();e.preventDefault();e.returnValue=''}}); function loadImage(src){return new Promise((resolve,reject)=>{const image=new Image();image.onload=()=>resolve(image);image.onerror=reject;image.src=src})} const img=new Image(); img.onload=()=>{ try{ const scale=Math.min(1,1600/Math.max(img.naturalWidth,img.naturalHeight)); base.width=ink.width=layer.width=Math.max(1,Math.round(img.naturalWidth*scale)); base.height=ink.height=layer.height=Math.max(1,Math.round(img.naturalHeight*scale)); baseCtx.fillStyle='#fff';baseCtx.fillRect(0,0,base.width,base.height);baseCtx.drawImage(img,0,0,base.width,base.height); // Eerst zichtbaar en bruikbaar maken. Opslag mag het tekenvlak nooit blokkeren. render();ready=true;$('stack').hidden=false;fit();status(text.ready); restoreSavedDrawing(); }catch(e){status(text.load_error)} }; async function restoreSavedDrawing(){ const initialRevision=revision; try{ const saved=await withTimeout(readSaved()); if(revision!==initialRevision||drawing)return; if(saved&&saved.version===1&&saved.sourceWidth===img.naturalWidth&&saved.sourceHeight===img.naturalHeight&&Number.isInteger(saved.rotation)&&saved.rotation>=0&&saved.rotation<4){ const picture=await withTimeout(loadImage(saved.png)); // Beginnen met kleuren heeft voorrang op een vertraagde oude tekening. if(revision!==initialRevision||drawing)return; const expectedW=saved.rotation%2?base.height:base.width,expectedH=saved.rotation%2?base.width:base.height; if(picture.naturalWidth===expectedW&&picture.naturalHeight===expectedH){ rotation=saved.rotation;for(let i=0;istatus(text.load_error);img.src=imageUrl; })();