diff --git a/CHANGELOG.md b/CHANGELOG.md index ffd0d86..15ebd1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog ## Unreleased +- **The text toolbar offers at most eight colours.** The swatch row listed every colour on any row in the deck, so a template-heavy deck showed more than forty, chart fills and run backgrounds among them. It now holds the role colours first, then the text colours rows use most, capped at eight. Colours already on rows keep rendering. Gate: test/editor.test.mjs. - **Two windows no longer lose an edit in the store.** When window B was typing as window A saved, B saved its words on top of A's model, but A's older save could reach localStorage after B's. Both windows looked right and the store held A's model without B's words, so a reload lost them. A CI probe caught this on Firefox in 12 of 180 runs under load and 0 of 60 alone. A window now watches the `storage` event: when the store holds a model it already built on, it writes its newer model back, and it writes the log back when entries are missing. This was the Firefox two-window failure on `main`. - **`validate --suggest`: the layouts and templates that fit a slide's content (#207).** `node bin/validate.mjs --suggest "three or four numbers with movement"` prints the top five of the 32 library layouts and 115 templates with kind, density and slot or fill keys. `lib/suggest.mjs` scores each by idf-weighted word overlap with its name, its `use` or `note`, and the SKILL.md routing table, which it reads at run time so the two cannot disagree. SKILL.md START HERE names it. Gate: test/suggest.test.mjs (every routing-table row finds its layout in the top three, a template is found by its note, unknown words still answer five, the CLI prints the ranking). diff --git a/README.md b/README.md index 94e3045..6acc7e5 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ node bin/assets.mjs logo "Xometry" --out assets/ # a logo fil - **Single file.** Model + renderer + editor in one `.html`; nothing is fetched at runtime. - **Zero network.** No webfonts, CDNs or remote images; images are data: URIs. The gate greps for it. -- **Editable.** Drag, ⌘-multi-select, marquee select (drag a window on empty canvas), double-click to retype, corner-nib resize, point nibs on connectors, floating role/mark/colour toolbar (B/I/U/S, sub/sup, the deck's own swatches; ⌘B/⌘I/⌘U), undo that survives reload, contact sheet with grab-and-drag reordering. +- **Editable.** Drag, ⌘-multi-select, marquee select (drag a window on empty canvas), double-click to retype, corner-nib resize, point nibs on connectors, floating role/mark/colour toolbar (B/I/U/S, sub/sup, up to eight swatches from the deck's own text colours; ⌘B/⌘I/⌘U), undo that survives reload, contact sheet with grab-and-drag reordering. - **Human edits are never lost.** Every edit autosaves in the browser — localStorage, IndexedDB where that is refused, memory as the last resort — on a desktop, a phone or inside an iframe, and every window of the same browser showing the deck picks it up live. Every edit lands in the in-file log and, once the deck file is linked (⌘S or the dot, Chrome/Edge, asked once), is written into the file by itself. `create --from` replays the log onto the next version, human wins, conflicts flagged. `bin/edits.mjs` prints the log for an agent. Version history is not decklet's job: it moved to weave (0.9.0). - **Motion, honestly.** Four entrance anims — `rise`, `fade`, `pop`, `wipe` — staggered 120 ms on slide *entry* only. `prefers-reduced-motion` turns them off, and print, the contact sheet, the PDF and `verify` all draw the settled frame, so motion can never change what is measured or exported. - **Brand-true.** Eight text roles (Title, Supertitle, H1, H2, Body, Caption, Label, Stat) are the only source of font/size/leading; rows cannot override them. Chrome is one deck-wide master layer on a `margin` token. Tokens re-theme every deck. diff --git a/deck.html b/deck.html index 732664a..d395843 100644 --- a/deck.html +++ b/deck.html @@ -1139,9 +1139,18 @@ } // ── floating mini toolbar (roles + inline marks + Apply to all slides) ── const tb=$('tb'); -// color swatches = the text colors ALREADY in the deck (roles first, then first appearance in rows/runs). No picker, no hex input. -// dedupe on the RESOLVED value (#23262C and rgb(35, 38, 44) are one swatch); the first literal spelling is kept -const deckColors=()=>{const seen=new Map();for(const c of [...Object.values(deck.styles&&deck.styles.roles||{}).map(r=>r.color),...[...(deck.master||[]),...deck.slides.flatMap(s=>s.els||[])].flatMap(e=>[e.color,...[...(e.html||'').matchAll(/color:\s*([^;"']+)/g)].map(m=>m[1].trim())])].filter(Boolean)){canvas.style.color=c;const k=getComputedStyle(canvas).color;if(!seen.has(k))seen.set(k,c)}canvas.style.color='';return [...seen.values()]}; +const SWATCH_MAX=8; +const deckColors=()=>{ + const key=c=>{canvas.style.color=c;return getComputedStyle(canvas).color}; + const roles=Object.values(deck.styles&&deck.styles.roles||{}).map(r=>r.color).filter(Boolean); + const rows=[...(deck.master||[]),...deck.slides.flatMap(s=>s.els||[])].filter(e=>e.text||e.html); + const used=rows.flatMap(e=>[e.color,...[...(e.html||'').matchAll(/(?m[1].trim())]).filter(Boolean); + const spelled=new Map(),uses=new Map(); + for(const c of used){const k=key(c);if(!spelled.has(k))spelled.set(k,c);uses.set(k,(uses.get(k)||0)+1)} + const out=new Map(roles.map(c=>[key(c),c])); + for(const k of [...uses.keys()].sort((a,b)=>uses.get(b)-uses.get(a)))if(!out.has(k))out.set(k,spelled.get(k)); + canvas.style.color='';return [...out.values()].slice(0,SWATCH_MAX); +}; const runSpan=(sr,node)=>{const a=sr.rangeCount&&sr.anchorNode,el=a&&(a.nodeType===1?a:a.parentElement).closest('[style*="color"]');return el&&node.contains(el)&&el!==node?el:null}; // a row whose resolved weight is already bold (any role the style sets to 600+): B would only write font-weight:normal, so it stays off const heavy=r=>!!r&&(/^bold/.test(r.weight)||+r.weight>=600); diff --git a/library.html b/library.html index ae5b984..a455d4f 100644 --- a/library.html +++ b/library.html @@ -1138,9 +1138,18 @@ } // ── floating mini toolbar (roles + inline marks + Apply to all slides) ── const tb=$('tb'); -// color swatches = the text colors ALREADY in the deck (roles first, then first appearance in rows/runs). No picker, no hex input. -// dedupe on the RESOLVED value (#23262C and rgb(35, 38, 44) are one swatch); the first literal spelling is kept -const deckColors=()=>{const seen=new Map();for(const c of [...Object.values(deck.styles&&deck.styles.roles||{}).map(r=>r.color),...[...(deck.master||[]),...deck.slides.flatMap(s=>s.els||[])].flatMap(e=>[e.color,...[...(e.html||'').matchAll(/color:\s*([^;"']+)/g)].map(m=>m[1].trim())])].filter(Boolean)){canvas.style.color=c;const k=getComputedStyle(canvas).color;if(!seen.has(k))seen.set(k,c)}canvas.style.color='';return [...seen.values()]}; +const SWATCH_MAX=8; +const deckColors=()=>{ + const key=c=>{canvas.style.color=c;return getComputedStyle(canvas).color}; + const roles=Object.values(deck.styles&&deck.styles.roles||{}).map(r=>r.color).filter(Boolean); + const rows=[...(deck.master||[]),...deck.slides.flatMap(s=>s.els||[])].filter(e=>e.text||e.html); + const used=rows.flatMap(e=>[e.color,...[...(e.html||'').matchAll(/(?m[1].trim())]).filter(Boolean); + const spelled=new Map(),uses=new Map(); + for(const c of used){const k=key(c);if(!spelled.has(k))spelled.set(k,c);uses.set(k,(uses.get(k)||0)+1)} + const out=new Map(roles.map(c=>[key(c),c])); + for(const k of [...uses.keys()].sort((a,b)=>uses.get(b)-uses.get(a)))if(!out.has(k))out.set(k,spelled.get(k)); + canvas.style.color='';return [...out.values()].slice(0,SWATCH_MAX); +}; const runSpan=(sr,node)=>{const a=sr.rangeCount&&sr.anchorNode,el=a&&(a.nodeType===1?a:a.parentElement).closest('[style*="color"]');return el&&node.contains(el)&&el!==node?el:null}; // a row whose resolved weight is already bold (any role the style sets to 600+): B would only write font-weight:normal, so it stays off const heavy=r=>!!r&&(/^bold/.test(r.weight)||+r.weight>=600); diff --git a/template.html b/template.html index 9b4cd70..009f084 100644 --- a/template.html +++ b/template.html @@ -1138,9 +1138,18 @@ } // ── floating mini toolbar (roles + inline marks + Apply to all slides) ── const tb=$('tb'); -// color swatches = the text colors ALREADY in the deck (roles first, then first appearance in rows/runs). No picker, no hex input. -// dedupe on the RESOLVED value (#23262C and rgb(35, 38, 44) are one swatch); the first literal spelling is kept -const deckColors=()=>{const seen=new Map();for(const c of [...Object.values(deck.styles&&deck.styles.roles||{}).map(r=>r.color),...[...(deck.master||[]),...deck.slides.flatMap(s=>s.els||[])].flatMap(e=>[e.color,...[...(e.html||'').matchAll(/color:\s*([^;"']+)/g)].map(m=>m[1].trim())])].filter(Boolean)){canvas.style.color=c;const k=getComputedStyle(canvas).color;if(!seen.has(k))seen.set(k,c)}canvas.style.color='';return [...seen.values()]}; +const SWATCH_MAX=8; +const deckColors=()=>{ + const key=c=>{canvas.style.color=c;return getComputedStyle(canvas).color}; + const roles=Object.values(deck.styles&&deck.styles.roles||{}).map(r=>r.color).filter(Boolean); + const rows=[...(deck.master||[]),...deck.slides.flatMap(s=>s.els||[])].filter(e=>e.text||e.html); + const used=rows.flatMap(e=>[e.color,...[...(e.html||'').matchAll(/(?m[1].trim())]).filter(Boolean); + const spelled=new Map(),uses=new Map(); + for(const c of used){const k=key(c);if(!spelled.has(k))spelled.set(k,c);uses.set(k,(uses.get(k)||0)+1)} + const out=new Map(roles.map(c=>[key(c),c])); + for(const k of [...uses.keys()].sort((a,b)=>uses.get(b)-uses.get(a)))if(!out.has(k))out.set(k,spelled.get(k)); + canvas.style.color='';return [...out.values()].slice(0,SWATCH_MAX); +}; const runSpan=(sr,node)=>{const a=sr.rangeCount&&sr.anchorNode,el=a&&(a.nodeType===1?a:a.parentElement).closest('[style*="color"]');return el&&node.contains(el)&&el!==node?el:null}; // a row whose resolved weight is already bold (any role the style sets to 600+): B would only write font-weight:normal, so it stays off const heavy=r=>!!r&&(/^bold/.test(r.weight)||+r.weight>=600); diff --git a/test/editor.test.mjs b/test/editor.test.mjs index 7569977..02c38ec 100644 --- a/test/editor.test.mjs +++ b/test/editor.test.mjs @@ -44,6 +44,27 @@ live('the mini toolbar opens on a text edit inside a multi-row selection: the ed assert.deepEqual(p.errs, []); await b.close(); }); +live('the toolbar offers at most eight colours: roles first, then the text colours used most, never a chart fill', async () => { + const hex = i => `#${(0x102030 + i * 0x010305).toString(16).padStart(6, '0')}`; + const once = Array.from({length: 30}, (_, i) => ({x: 60, y: 300, w: 200, role: 'Body', color: hex(i), text: `once ${i}`})); + const twice = [0, 1, 2].map(() => ({x: 60, y: 340, w: 200, role: 'Body', color: '#ff00aa', text: 'pink'})); + const m = model({slides: [{els: [ + {x: 60, y: 80, w: 800, role: 'H1', text: 'Palette'}, + {x: 60, y: 200, w: 100, h: 20, bar: 1, color: '#00ff01'}, + {x: 60, y: 240, w: 400, role: 'Body', html: 'marked'}, + ...once, ...twice]}]}); + const b = await pw.chromium.launch(); try { + const p = await fresh(b, write('swatches.html', create(m).html)); + await p.evaluate(() => { sel.clear(); sel.add(0); render(); }); + const shown = await p.evaluate(() => [...document.querySelectorAll('#tb-colors .sw')].map(s => s.dataset.color)); + const roleColours = await p.evaluate(() => [...new Set(Object.values(deck.styles.roles).map(r => r.color))]); + assert.ok(shown.length <= 8, `at most eight swatches, got ${shown.length}`); + assert.deepEqual(shown.slice(0, roleColours.length), roleColours, 'the role colours come first'); + assert.ok(shown.includes('#ff00aa'), 'the most used row colour stays'); + assert.ok(!shown.includes('#00ff01'), 'a bar fill is not a text colour'); + assert.ok(!shown.includes('#00ff02'), 'a run background is not a text colour'); + assert.deepEqual(p.errs, []); } finally { await b.close(); } +}); live('an inline mark on a multi-line row keeps its line breaks: italic, a colour run, a reload, a deck already carrying html with a newline', async () => { // any mark moves a row from text to html, and the newline travels into html as a literal \n. text rows pre-wrap on a \n // and html rows did not, so the committed row collapsed onto one line. The fault sits on the shared text → html path.