Create a HTML JavaScript editor which uses konva.js (https://konvajs.org/),…
- User
Create a HTML JavaScript editor which uses konva.js (https://konvajs.org/), pickr(https://github.com/Simonwep/pickr) and font-awesome (https://github.com/FortAwesome/Font-Awesome). Also you need to use FontFaceObserver if you need to use none standard fonts. (https://fontfaceobserver.com/)
- Assistant
Below you find a complete, self-contained “mini-editor” that stitches together
• Konva.js – canvas / node editing
• Pickr – live color picker
• Font-Awesome – toolbar icons
• FontFaceObserver – lazy loading of non-system fontsDrop the snippet into index.html and open it – no build tools required 🚀
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"/> <title>Konva + Pickr Mini Editor</title> <!-- ----------------- 3rd-party styles ------------------ --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/> <link rel="stylesheet" href="https://unpkg.com/@simonwep/pickr/dist/themes/classic.min.css"/> <!-- ----------------- lay-out tweaks -------------------- --> <style> *{box-sizing:border-box;font-family:Arial,Helvetica,sans-serif} body{margin:0;display:flex;flex-direction:column;height:100vh} #toolbar{ display:flex;align-items:center;gap:.5rem; background:#222;color:#fff;padding:.4rem .8rem; } #toolbar button, #toolbar select{ background:#444;border:none;color:#fff;padding:.35rem .6rem; cursor:pointer;border-radius:4px;font-size:1rem } #toolbar button:hover{background:#666} #canvas-wrapper{flex:1;position:relative} #container{width:100%;height:100%} /* konva mount */ /* Pickr host */ .color-picker{width:1.8rem;height:1.8rem;border-radius:4px;border:1px solid #999} </style> </head> <body> <!-- Toolbar --> <div id="toolbar"> <button id="add-rect" title="Rectangle"><i class="fa-solid fa-square"></i></button> <button id="add-circle" title="Circle"><i class="fa-solid fa-circle"></i></button> <button id="add-text" title="Text"><i class="fa-solid fa-font"></i></button> <button id="delete" title="Delete"><i class="fa-solid fa-trash"></i></button> <div id="picker" class="color-picker"></div> <label for="font-select" style="margin-left:.8rem">Font:</label> <select id="font-select"> <option value="Arial">Arial</option> <option value="Indie Flower">Indie Flower</option> <option value="Lobster">Lobster</option> <option value="Pacifico">Pacifico</option> </select> </div> <!-- Konva mount --> <div id="canvas-wrapper"> <div id="container"></div> </div> <!-- ----------------- scripts ------------------ --> <script src="https://unpkg.com/konva@9/konva.min.js"></script> <script src="https://unpkg.com/@simonwep/pickr"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/fontfaceobserver/2.1.0/fontfaceobserver.standalone.js"></script> <script> /* ---------- 1. stage + layer ---------------- */ const stage = new Konva.Stage({ container: 'container', width: window.innerWidth, height: window.innerHeight - document.getElementById('toolbar').offsetHeight }); const layer = new Konva.Layer(); stage.add(layer); const tr = new Konva.Transformer({ignoreStroke:true,rotateEnabled:true}); layer.add(tr); layer.draw(); /* ---------- 2. util helpers ----------------- */ let activeNode = null; function select(node){ activeNode = node; tr.nodes(node ? [node] : []); layer.draw(); if(node && node.fill) pickr.setColor(node.fill()); } /* ---------- 3. color picker ----------------- */ const pickr = Pickr.create({ el: '#picker', theme: 'classic', default: '#3498db', components: { preview:true,opacity:true,hue:true, interaction:{hex:true,rgba:true,input:true,save:true} } }); pickr.on('change', (_, instance) => { if(activeNode && activeNode.fill){ activeNode.fill(instance.toHEXA().toString()); layer.batchDraw(); } }); /* ---------- 4. shape factories -------------- */ function basicEvents(shape){ shape.draggable(true); shape.on('click', e => select(e.target)); shape.on('dragstart', e => select(e.target)); } function addRect(){ const rect = new Konva.Rect({ x: 50, y: 50, width:120, height:80, fill: pickr.getColor().toHEXA().toString(), stroke:'#000',strokeWidth:2 }); basicEvents(rect); layer.add(rect); select(rect); } function addCircle(){ const circle = new Konva.Circle({ x:120, y:120, radius:50, fill: pickr.getColor().toHEXA().toString(), stroke:'#000',strokeWidth:2 }); basicEvents(circle); layer.add(circle); select(circle); } function addText(){ const txt = new Konva.Text({ x:150, y:150, text:'Edit me', fontSize:30, fontFamily:document.getElementById('font-select').value, fill: pickr.getColor().toHEXA().toString() }); basicEvents(txt); txt.on('dblclick', () => { const newTxt = prompt('Text:', txt.text()); if(newTxt !== null) txt.text(newTxt); layer.draw(); }); layer.add(txt); select(txt); } /* ---------- 5. toolbar bindings ------------- */ document.getElementById('add-rect').onclick = addRect; document.getElementById('add-circle').onclick = addCircle; document.getElementById('add-text').onclick = addText; document.getElementById('delete').onclick = () => { if(activeNode){ activeNode.destroy(); select(null); layer.draw(); } }; /* ---------- 6. font handling ---------------- */ const fontSelect = document.getElementById('font-select'); const loadedFonts = new Set(); fontSelect.onchange = () => { if(!activeNode || activeNode.getClassName() !== 'Text') return; const fam = fontSelect.value; const apply = () => { activeNode.fontFamily(fam); layer.draw(); }; if(loadedFonts.has(fam)){ apply(); return;} // Lazy load via Google fonts then observe const link = document.createElement('link'); link.rel = 'stylesheet'; link.href = `https://fonts.googleapis.com/css2?family=${fam.replace(/ /g,'+')}&display=swap`; document.head.appendChild(link); new FontFaceObserver(fam).load().then(()=>{ loadedFonts.add(fam); apply(); }).catch(()=>{console.warn('Font load failed'); apply();}); }; /* ---------- 7. deselect on empty click ------ */ stage.on('click', e => { if(e.target === stage) select(null);}); /* ---------- 8. responsive ------------------- */ window.addEventListener('resize', ()=>{ stage.width(window.innerWidth); stage.height(window.innerHeight - document.getElementById('toolbar').offsetHeight); }); </script> </body> </html>What you get out-of-the-box
🏗️ Add / drag / transform Rectangles, Circles and Text nodes.
🎨 Click any node – Pickr instantly shows its fill, change it live.
🔤 Change a selected text’s font with lazy-loaded Google fonts (FontFaceObserver guarantees the render only after the font is ready).
🗑️ Delete with the trash icon.
🖱️ Double-click text objects to edit their string.Feel free to extend: stroke color / width controls, export to PNG / JSON, multi-select, etc.—Konva’s API will happily scale with you. Happy hacking!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.