here2share

Flexible Card Studio

Nov 14th, 2026
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 14.59 KB | None | 0 0
  1. <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Flexible Card Studio</title><style>
  2. *{box-sizing:border-box}body{margin:0;background:#101114;color:#ddd;font:14px Arial}button,select,input,textarea{background:#303239;color:#eee;border:1px solid #575b66;border-radius:5px;padding:8px;font:14px Arial}button{cursor:pointer}.tools{position:sticky;top:0;z-index:9;background:#24262c;padding:12px;display:flex;gap:8px;align-items:center;flex-wrap:wrap}.tools label{display:flex;align-items:center;gap:5px}.tools input[type=number]{width:80px}.tools input[type=color]{width:40px;height:34px;padding:3px}.help{padding:12px 22px;color:#b2b5be;line-height:1.6}#viewport{overflow:auto;padding:20px}#page{--bg:#161719;--fg:#e4e4e7;--card:#202125;--accent:#a7c7ff;--line:#383b43;width:1080px;min-height:400px;margin:auto;padding:45px 70px;background:var(--bg);color:var(--fg)}.block{position:relative;margin:0 0 25px}.card{background:var(--card);border-radius:22px;padding:22px;width:80%;margin-left:auto;font:21px/1.5 Arial}.text{font:23px/1.5 Georgia,serif}.edit{min-height:30px;overflow-wrap:anywhere}.edit:focus{outline:1px dashed var(--accent);outline-offset:7px}.edit p{margin:0 0 18px}.edit p:last-child{margin-bottom:0}.edit h2{font-size:1.16em;margin:24px 0 14px}.edit blockquote{border-left:4px solid var(--line);margin:20px 0;padding-left:20px}.edit li{margin-bottom:12px}.edit table{width:100%;table-layout:fixed;border-collapse:collapse;background:var(--card);font:18px/1.4 Arial;margin:20px 0}.edit th,.edit td{border:1px solid var(--line);padding:12px;text-align:left;vertical-align:top;overflow-wrap:anywhere}.edit th{background:var(--line)}.edit a{color:var(--accent)}.edit pre{white-space:pre-wrap}dialog{background:#22252b;color:#ddd;border:1px solid #616875;border-radius:10px;width:min(800px,95vw)}dialog textarea{width:100%;height:220px;margin:12px 0}.row{display:flex;gap:10px;flex-wrap:wrap;align-items:center}#status{color:#bbd3bc}#preview{max-height:300px;overflow:auto}#preview table{border-collapse:collapse;width:100%}#preview td,#preview th{border:1px solid #666;padding:8px}.swatches{display:flex;gap:4px}.swatch{width:24px;height:27px;padding:0;border:1px solid #777}details{padding:5px}summary{cursor:pointer}
  3. </style></head><body><div class="tools">
  4. <button id="addCard">+ Card</button><button id="addText">+ Text</button><button id="paste">Paste text</button><button id="table">Table</button>
  5. <select id="blockStyle" aria-label="Active block layout"><option value="">Block layout…</option><option value="card">Card</option><option value="text">Plain text</option></select><button id="up">Move up</button><button id="down">Move down</button><button id="remove">Delete block</button>
  6. <select id="format" aria-label="Text format"><option value="">Text format…</option><option value="p">Paragraph</option><option value="h2">Heading</option><option value="h3">Subheading</option><option value="blockquote">Quote</option><option value="pre">Code</option></select><button data-cmd="bold">Bold</button><button data-cmd="italic">Italic</button><button data-cmd="insertUnorderedList">Bullets</button><button data-cmd="removeFormat">Clear formatting</button>
  7. <label>Text FG <input type="color" id="fg" value="#e4e4e7"></label><button id="applyFg">Apply FG</button><label>Text BG <input type="color" id="bg" value="#36445c"></label><button id="applyBg">Apply BG</button><button id="clearBg">Clear text BG</button>
  8. <label>Palette targets <select id="target"><option value="fg">Text FG</option><option value="bg">Text BG</option></select></label><div id="swatches" class="swatches"></div>
  9. </div><div class="tools" style="position:static">
  10. <label>Theme <select id="theme"><option value="charcoal">Charcoal</option><option value="slate">Slate</option><option value="midnight">Midnight</option><option value="forest">Forest</option><option value="light">Light</option></select></label>
  11. <label>Page <input type="color" id="pageBg" value="#161719"></label><label>Default text <input type="color" id="pageFg" value="#e4e4e7"></label><label>Cards <input type="color" id="cardBg" value="#202125"></label>
  12. <label>Width <input id="width" type="number" min="400" max="2400" value="1080"></label><label>Padding <input id="padding" type="number" min="10" max="200" value="60"></label><label>Card width % <input id="cardWidth" type="number" min="20" max="100" value="80"></label><label>Card alignment <select id="align"><option value="right">Right</option><option value="left">Left</option><option value="center">Centre</option></select></label>
  13. <label>Font <select id="font"><option value="Georgia,serif">Serif</option><option value="Arial,sans-serif">Sans-serif</option><option value="monospace">Monospace</option></select></label><label>Size <input id="size" type="number" min="10" max="80" value="23"></label><label>PNG scale <select id="scale"><option>1</option><option selected>2</option><option>3</option></select></label><button id="png">Export PNG</button><button id="save">Save HTML</button><span id="status" role="status"></span>
  14. </div><div class="help">Generic, editable blocks: click a card or text block to make it active. Select text, then choose its foreground (FG) or background (BG) colour. Palette swatches apply immediately to the selected text; custom colour pickers use the Apply buttons. Block layout, font, size and card alignment affect the active block. Page colours affect the whole document. Paste formatted text directly, or use Paste text. Export excludes the editor controls. PNG export needs internet to load html2canvas; your document is rendered locally.</div>
  15. <div id="viewport"><main id="page"><section class="block card"><div class="edit" contenteditable="true"><p>Your card text goes here.</p></div></section><section class="block text"><div class="edit" contenteditable="true"><h2>Your heading</h2><p>Paste or write any content here. Select a passage to change its text colour or background highlight. Add, remove, reorder and restyle blocks as needed.</p></div></section></main></div>
  16. <dialog id="pasteDialog"><h2>Paste text into active block</h2><textarea id="pasteValue"></textarea><label><input type="checkbox" id="replace"> Replace entire block (otherwise insert at cursor)</label><p><button id="pasteApply">Insert text</button> <button onclick="this.closest('dialog').close()">Cancel</button></p></dialog>
  17. <dialog id="tableDialog"><h2>Paste table data</h2><textarea id="tableValue" placeholder="Paste spreadsheet cells, CSV or a Markdown table"></textarea><div class="row"><select id="delimiter"><option value="auto">Auto separator</option><option value="tab">Tabs</option><option value="pipe">Pipes |</option><option value="comma">CSV (commas)</option></select><label><input type="checkbox" id="transpose"> Swap rows / columns</label><label><input type="checkbox" id="header" checked> Header row</label></div><div id="preview"></div><p><button id="insertTable">Insert</button> <button onclick="this.closest('dialog').close()">Cancel</button></p></dialog>
  18. <script>
  19. const $=id=>document.getElementById(id),page=$('page');let active=page.querySelector('.edit'),range=null;const esc=s=>s.replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));function block(){return active.closest('.block')}function remember(){let s=getSelection();if(s.rangeCount&&page.contains(s.anchorNode)){let el=s.anchorNode.nodeType===1?s.anchorNode:s.anchorNode.parentElement;let edit=el.closest('.edit');if(edit){active=edit;range=s.getRangeAt(0).cloneRange()}}}document.addEventListener('selectionchange',remember);page.addEventListener('focusin',e=>{let x=e.target.closest('.edit');if(x)active=x});
  20. function restore(){active.focus();let s=getSelection();s.removeAllRanges();if(range&&active.contains(range.commonAncestorContainer))s.addRange(range);else{let r=document.createRange();r.selectNodeContents(active);r.collapse(false);s.addRange(r)}}function cmd(c,v){restore();document.execCommand('styleWithCSS',false,true);document.execCommand(c,false,v);remember()}
  21. document.querySelectorAll('button[data-cmd]').forEach(b=>{b.onmousedown=e=>e.preventDefault();b.onclick=()=>cmd(b.dataset.cmd)});$('format').onchange=e=>{if(e.target.value)cmd('formatBlock',e.target.value);e.target.value=''};
  22. function colour(type,value){if(!range||range.collapsed){$('status').textContent='Select text in a block first.';return}cmd(type==='fg'?'foreColor':'hiliteColor',value);$('status').textContent='Selection colour updated.'}['fg','bg'].forEach(k=>$('apply'+(k==='fg'?'Fg':'Bg')).onclick=()=>colour(k,$(k).value));$('clearBg').onclick=()=>colour('bg','transparent');
  23. const palette=['#f4f4f5','#c7cbd4','#939baa','#161719','#23262e','#39404e','#a7c7ff','#a6e3c0','#f5d38b','#ffaaa5','#d4b7f5','#79d5dc'];palette.forEach(c=>{let b=document.createElement('button');b.className='swatch';b.style.background=c;b.title=c;b.setAttribute('aria-label','Apply '+c);b.onmousedown=e=>e.preventDefault();b.onclick=()=>{let t=$('target').value;$(t).value=c;colour(t,c)};$('swatches').append(b)});
  24. function add(type){let b=document.createElement('section');b.className='block '+type;b.innerHTML='<div class="edit" contenteditable="true"><p>Your text…</p></div>';block().after(b);active=b.firstElementChild;range=null;active.focus()}
  25. $('addCard').onclick=()=>add('card');$('addText').onclick=()=>add('text');$('blockStyle').onchange=e=>{if(e.target.value)block().className='block '+e.target.value;e.target.value=''};$('up').onclick=()=>{let b=block();if(b.previousElementSibling)b.previousElementSibling.before(b)};$('down').onclick=()=>{let b=block();if(b.nextElementSibling)b.nextElementSibling.after(b)};$('remove').onclick=()=>{if(page.children.length===1){active.innerHTML='<p><br></p>';return}let b=block();active=(b.nextElementSibling||b.previousElementSibling).querySelector('.edit');b.remove();range=null};
  26. $('font').onchange=e=>block().style.fontFamily=e.target.value;$('size').oninput=e=>block().style.fontSize=e.target.value+'px';$('cardWidth').oninput=e=>block().style.width=e.target.value+'%';$('align').onchange=e=>{let b=block();b.style.marginLeft=e.target.value==='left'?'0':'auto';b.style.marginRight=e.target.value==='right'?'0':'auto'};
  27. const vars={pageBg:'--bg',pageFg:'--fg',cardBg:'--card'};Object.entries(vars).forEach(([id,v])=>$(id).oninput=e=>page.style.setProperty(v,e.target.value));$('width').oninput=e=>page.style.width=e.target.value+'px';$('padding').oninput=e=>page.style.padding=e.target.value+'px';
  28. const themes={charcoal:['#161719','#e4e4e7','#202125','#a7c7ff','#383b43'],slate:['#17212d','#e5edf5','#243344','#9ecbff','#3e5266'],midnight:['#101429','#ecebff','#1d2440','#b5b7ff','#394366'],forest:['#131e19','#e1eee5','#21332a','#a6e3c0','#395446'],light:['#f6f6f5','#202124','#e7e8eb','#245fa3','#c6c9ce']};$('theme').onchange=e=>{let a=themes[e.target.value];['--bg','--fg','--card','--accent','--line'].forEach((v,i)=>page.style.setProperty(v,a[i]));['pageBg','pageFg','cardBg'].forEach((v,i)=>$(v).value=a[i])};
  29. function insert(html){restore();document.execCommand('insertHTML',false,html);remember()}$('paste').onclick=()=>$('pasteDialog').showModal();$('pasteApply').onclick=()=>{let h=$('pasteValue').value.split(/\n\s*\n/).map(x=>'<p>'+esc(x).replace(/\n/g,'<br>')+'</p>').join('');$('pasteDialog').close();if($('replace').checked){active.innerHTML=h;range=null}else insert(h)};
  30. page.addEventListener('paste',e=>{if(!e.target.closest('.edit'))return;let h=e.clipboardData.getData('text/html');if(!h)return;e.preventDefault();let doc=new DOMParser().parseFromString(h,'text/html');doc.querySelectorAll('script,style,iframe,object,embed,img,svg,link,meta').forEach(n=>n.remove());doc.body.querySelectorAll('*').forEach(n=>[...n.attributes].forEach(a=>n.removeAttribute(a.name)));insert(doc.body.innerHTML)});
  31. function csv(l){let a=[],v='',q=false;for(let i=0;i<l.length;i++){let c=l[i];if(c==='"'){if(q&&l[i+1]==='"'){v+='"';i++}else q=!q}else if(c===','&&!q){a.push(v);v=''}else v+=c}return [...a,v]}
  32. function table(){let t=$('tableValue').value.trim();if(!t)return '';let sep=$('delimiter').value;if(sep==='auto')sep=t.includes('\t')?'tab':t.includes('|')?'pipe':'comma';let r=t.split(/\r?\n/).filter(x=>x.trim()).map(l=>sep==='comma'?csv(l):sep==='tab'?l.split('\t'):l.trim().replace(/^\||\|$/g,'').split('|')).filter(r=>!r.every(c=>/^\s*:?-{3,}:?\s*$/.test(c)));let n=Math.max(0,...r.map(x=>x.length));r=r.map(x=>Array.from({length:n},(_,i)=>(x[i]||'').trim()));if($('transpose').checked)r=Array.from({length:n},(_,i)=>r.map(x=>x[i]));return '<table><tbody>'+r.map((row,i)=>'<tr>'+row.map(c=>{let tag=i===0&&$('header').checked?'th':'td';return '<'+tag+'>'+esc(c)+'</'+tag+'>'}).join('')+'</tr>').join('')+'</tbody></table><p><br></p>'}
  33. $('table').onclick=()=>{$('tableDialog').showModal();$('preview').innerHTML=table()};['tableValue','delimiter','transpose','header'].forEach(id=>$(id).oninput=()=>$('preview').innerHTML=table());$('insertTable').onclick=()=>{let h=table();$('tableDialog').close();if(h)insert(h)};
  34. function download(blob,name){let a=document.createElement('a'),u=URL.createObjectURL(blob);a.href=u;a.download=name;a.click();setTimeout(()=>URL.revokeObjectURL(u),5000)}
  35. $('save').onclick=()=>{let doc=document.documentElement.cloneNode(true);doc.querySelectorAll('input,select,textarea').forEach((el,i)=>{let src=document.querySelectorAll('input,select,textarea')[i];if(el.tagName==='SELECT')[...el.options].forEach(o=>o.toggleAttribute('selected',o.value===src.value));else if(el.tagName==='TEXTAREA')el.textContent=src.value;else{el.setAttribute('value',src.value);el.toggleAttribute('checked',src.checked)}});doc.querySelector('#status').textContent='';doc.querySelectorAll('[disabled]').forEach(e=>e.removeAttribute('disabled'));download(new Blob(['<!doctype html>\n'+doc.outerHTML],{type:'text/html'}),'flexible-card-studio.html');$('status').textContent='Editable HTML saved.'};
  36. async function load(){if(window.html2canvas)return;await new Promise((resolve,reject)=>{let s=document.createElement('script');s.src='https://cdn.jsdelivr.net/npm/[email protected]/dist/html2canvas.min.js';s.onload=resolve;s.onerror=reject;document.head.append(s)})}
  37. $('png').onclick=async()=>{$('png').disabled=true;$('status').textContent='Rendering…';try{await load();await document.fonts.ready;getSelection().removeAllRanges();document.activeElement.blur();let canvas=await html2canvas(page,{scale:Number($('scale').value),backgroundColor:null,logging:false,windowWidth:Math.max(1400,page.offsetWidth+100)});let blob=await new Promise(resolve=>canvas.toBlob(resolve,'image/png'));if(!blob)throw Error();download(blob,'composition.png');$('status').textContent='PNG saved.'}catch(e){$('status').textContent='Export failed. Check internet access or try a smaller PNG scale.'}finally{$('png').disabled=false}};
  38. </script></body></html>
Advertisement
Add Comment
Please, Sign In to add comment