From f798e54f0e4f435d200002c742d9e1418c46e33c Mon Sep 17 00:00:00 2001 From: Graham van der Wielen <13894957+grayum@users.noreply.github.com> Date: Mon, 19 Oct 2026 18:07:35 +0200 Subject: [PATCH 1/3] feat: add cue icon palette and audited filled artwork --- dist/icon-colours.js | 12 ++++++++++++ dist/icon-fills.js | 31 +++++++++++++++++++++++++++++++ dist/icons.js | 2 +- tests/icon-artwork.test.mjs | 15 +++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 dist/icon-colours.js create mode 100644 dist/icon-fills.js create mode 100644 tests/icon-artwork.test.mjs diff --git a/dist/icon-colours.js b/dist/icon-colours.js new file mode 100644 index 0000000..be6759c --- /dev/null +++ b/dist/icon-colours.js @@ -0,0 +1,12 @@ +// Fixed audited palette: the same sRGB values on screen and paper. Never use data as CSS. +export const ICON_COLOURS=Object.freeze([ + {id:'default',name:'Default / monochrome',value:null}, + {id:'blue',name:'Blue',value:'#2676c9'}, + {id:'orange',name:'Orange',value:'#b96a13'}, + {id:'green',name:'Green',value:'#278548'}, + {id:'red',name:'Red',value:'#c54040'}, + {id:'purple',name:'Purple',value:'#8b57b5'} +].map(Object.freeze)); +export function validateIconColour(id){if(!ICON_COLOURS.some(c=>c.id===id))throw Error('Invalid cue icon colour. Choose a named palette colour.');return id;} +export const iconColour=id=>ICON_COLOURS.find(c=>c.id===(id??'default'))||ICON_COLOURS[0]; +export function setIconColour(row,id){validateIconColour(id);if((row.iconColour??'default')===id)return false;if(id==='default')delete row.iconColour;else row.iconColour=id;return true;} diff --git a/dist/icon-fills.js b/dist/icon-fills.js new file mode 100644 index 0000000..82d02de --- /dev/null +++ b/dist/icon-fills.js @@ -0,0 +1,31 @@ +import {ICONS} from './icons.js'; + +// Audited interior layers, beneath the unchanged outlines. Open detail strokes are +// never implicitly filled. These local silhouettes describe actual enclosed parts. +const path=(d,transform)=>['path',{d,...(transform?{transform}:{})}]; +const copy=(name,index)=>ICONS[name][index]; +const INTERIORS={ + banana:[copy('banana',1)], // Fruit/peel body; the open peel detail stays on top. + bottle:[path('M10 4V2h4v2Z'),copy('bottle',1),path('M8 7c0 1-2 1.8-2 3 0 1 1.3 1.6 1.3 2.6S6 14 6 15v5q0 2 2 2h8q2 0 2-2v-5c0-1-1.3-1.4-1.3-2.4S18 11 18 10c0-1.2-2-2-2-3Z')], + bar:[path('M8 11V3.5Q8 2 9.5 2h5Q16 2 16 3.5V11Z'),path('M8 13.5V21q0 1 1 1h6q1 0 1-1v-5.5L14 14H8Z'),copy('bar',2)], + gel:[copy('gel',0)], + smile:[copy('smile',0)], + mountain:[copy('mountain',0)], + flag:[path('M4 4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528Z')], + coffee:[path('M4 8h12a1 1 0 0 1 1 1v8a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1Z')], // Handle and steam stay open. + warning:[path(ICONS.warning[0][1].d+'Z')], + cobbles:ICONS.cobbles.slice(1), // Separate stones, never the open road edges/gaps. + ricecake:[copy('ricecake',0)], + can:[path('M5 4v16c0 2.7 14 2.7 14 0V4Z'),copy('can',0)], + neutral:[path('M4 3c5-3 10 3 16 0v12c-6 3-11-3-16 0Z')], + litter:[path('M5 6h14v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2Z')] +}; +export const STROKE_ONLY_CUES=Object.freeze(['feed']); // Open utensils have no useful enclosed body. +export const COLOURED_OUTLINE='#202426'; +export function iconArtwork(name,coloured=false){ + const base=ICONS[name]||[]; + if(!coloured||!INTERIORS[name])return base; + const fills=INTERIORS[name].map(([tag,attrs])=>[tag,{...attrs,fill:'currentColor',stroke:'none','data-icon-fill':''}]); + const outlines=base.map(([tag,attrs])=>[tag,{...attrs,stroke:attrs.stroke==='none'?'none':COLOURED_OUTLINE,...(attrs.fill==='currentColor'?{fill:COLOURED_OUTLINE}:{} )}]); + return [...fills,...outlines]; +} diff --git a/dist/icons.js b/dist/icons.js index 60e90f0..49a4808 100644 --- a/dist/icons.js +++ b/dist/icons.js @@ -1,2 +1,2 @@ // Lucide 1.8.0 subset (assets/LUCIDE-LICENSE). Bar, bottle, gel, cobbles, ricecake, can, neutral: original StemTape artwork. -export const ICONS = {"banana":[["path",{"d":"M4 13c3.5-2 8-2 10 2a5.5 5.5 0 0 1 8 5"}],["path",{"d":"M5.15 17.89c5.52-1.52 8.65-6.89 7-12C11.55 4 11.5 2 13 2c3.22 0 5 5.5 5 8 0 6.5-4.2 12-10.49 12C5.11 22 2 22 2 20c0-1.5 1.14-1.55 3.15-2.11Z"}]],"bottle":[["path",{"transform":"rotate(45 12 12)","d":"M10 4V2h4v2"}],["path",{"transform":"rotate(45 12 12)","d":"M8 4h8q1 0 1 1v2H7V5q0-1 1-1Z"}],["path",{"transform":"rotate(45 12 12)","d":"M8 7c0 1-2 1.8-2 3 0 1 1.3 1.6 1.3 2.6S6 14 6 15v5q0 2 2 2h8q2 0 2-2v-5c0-1-1.3-1.4-1.3-2.4S18 11 18 10c0-1.2-2-2-2-3"}]],"bar":[["path",{"d":"M8 11V3.5Q8 2 9.5 2h5Q16 2 16 3.5V11","transform":"rotate(38 12 12)"}],["path",{"d":"M8 13.5V21q0 1 1 1h6q1 0 1-1v-5.5","transform":"rotate(38 12 12)"}],["path",{"d":"M7.5 11h9v4.5L14 14H7.5Z","transform":"rotate(38 12 12)"}],["circle",{"cx":10.4,"cy":5.2,"r":0.65,"fill":"currentColor","stroke":"none","transform":"rotate(38 12 12)"}],["circle",{"cx":13.6,"cy":5.2,"r":0.65,"fill":"currentColor","stroke":"none","transform":"rotate(38 12 12)"}],["path",{"d":"M10.4 7.4q1.6 1.9 3.2 0","transform":"rotate(38 12 12)"}]],"gel":[["path",{"d":"M9 2h6v2.3l-1 .5 1 .5V6l1 1.5V21q0 1-1 1H9q-1 0-1-1V7.5L9 6V5a1 1 0 0 0 0-2Z","transform":"rotate(38 12 12)"}],["path",{"d":"M8 19.5h8","transform":"rotate(38 12 12)"}]],"smile":[["circle",{"cx":"12","cy":"12","r":"10"}],["path",{"d":"M8 14s1.5 2 4 2 4-2 4-2"}],["line",{"x1":"9","x2":"9.01","y1":"9","y2":"9"}],["line",{"x1":"15","x2":"15.01","y1":"9","y2":"9"}]],"mountain":[["path",{"d":"m8 3 4 8 5-5 5 15H2L8 3z"}]],"feed":[["path",{"d":"M3 2v7c0 1.1.9 2 2 2h4a2 2 0 0 0 2-2V2"}],["path",{"d":"M7 2v20"}],["path",{"d":"M21 15V2a5 5 0 0 0-5 5v6c0 1.1.9 2 2 2h3Zm0 0v7"}]],"flag":[["path",{"d":"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528"}]],"coffee":[["path",{"d":"M10 2v2"}],["path",{"d":"M14 2v2"}],["path",{"d":"M16 8a1 1 0 0 1 1 1v8a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1h14a4 4 0 1 1 0 8h-1"}],["path",{"d":"M6 2v2"}]],"warning":[["path",{"d":"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}],["path",{"d":"M12 9v4"}],["path",{"d":"M12 17h.01"}]],"plus":[["path",{"d":"M5 12h14"}],["path",{"d":"M12 5v14"}]],"print":[["path",{"d":"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}],["path",{"d":"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6"}],["rect",{"x":"6","y":"14","width":"12","height":"8","rx":"1"}]],"download":[["path",{"d":"M12 15V3"}],["path",{"d":"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}],["path",{"d":"m7 10 5 5 5-5"}]],"upload":[["path",{"d":"M12 3v12"}],["path",{"d":"m17 8-5-5-5 5"}],["path",{"d":"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}]],"trash":[["path",{"d":"M10 11v6"}],["path",{"d":"M14 11v6"}],["path",{"d":"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}],["path",{"d":"M3 6h18"}],["path",{"d":"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}]],"copy":[["rect",{"width":"14","height":"14","x":"8","y":"8","rx":"2","ry":"2"}],["path",{"d":"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"}]],"up":[["path",{"d":"m18 15-6-6-6 6"}]],"down":[["path",{"d":"m6 9 6 6 6-6"}]],"settings":[["path",{"d":"M10 5H3"}],["path",{"d":"M12 19H3"}],["path",{"d":"M14 3v4"}],["path",{"d":"M16 17v4"}],["path",{"d":"M21 12h-9"}],["path",{"d":"M21 19h-5"}],["path",{"d":"M21 5h-7"}],["path",{"d":"M8 10v4"}],["path",{"d":"M8 12H3"}]],"check":[["path",{"d":"M20 6 9 17l-5-5"}]],"sun":[["circle",{"cx":"12","cy":"12","r":"4"}],["path",{"d":"M12 2v2"}],["path",{"d":"M12 20v2"}],["path",{"d":"m4.93 4.93 1.41 1.41"}],["path",{"d":"m17.66 17.66 1.41 1.41"}],["path",{"d":"M2 12h2"}],["path",{"d":"M20 12h2"}],["path",{"d":"m6.34 17.66-1.41 1.41"}],["path",{"d":"m19.07 4.93-1.41 1.41"}]],"moon":[["path",{"d":"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401"}]],"monitor":[["rect",{"width":"20","height":"14","x":"2","y":"3","rx":"2"}],["line",{"x1":"8","x2":"16","y1":"21","y2":"21"}],["line",{"x1":"12","x2":"12","y1":"17","y2":"21"}]],"close":[["path",{"d":"M18 6 6 18"}],["path",{"d":"m6 6 12 12"}]],"columns":[["rect",{"width":"18","height":"18","x":"3","y":"3","rx":"2"}],["path",{"d":"M9 3v18"}],["path",{"d":"M15 3v18"}]],"sort":[["path",{"d":"m3 16 4 4 4-4"}],["path",{"d":"M7 20V4"}],["path",{"d":"M11 4h10"}],["path",{"d":"M11 8h7"}],["path",{"d":"M11 12h4"}]],"save":[["path",{"d":"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"}],["path",{"d":"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7"}],["path",{"d":"M7 3v4a1 1 0 0 0 1 1h7"}]],"help":[["circle",{"cx":"12","cy":"12","r":"10"}],["path",{"d":"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}],["path",{"d":"M12 17h.01"}]],"grip":[["circle",{"cx":"9","cy":"12","r":"1"}],["circle",{"cx":"9","cy":"5","r":"1"}],["circle",{"cx":"9","cy":"19","r":"1"}],["circle",{"cx":"15","cy":"12","r":"1"}],["circle",{"cx":"15","cy":"5","r":"1"}],["circle",{"cx":"15","cy":"19","r":"1"}]],"litter":[["path",{"d":"M10 11v6"}],["path",{"d":"M14 11v6"}],["path",{"d":"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}],["path",{"d":"M3 6h18"}],["path",{"d":"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}]],"cobbles":[["path",{"d":"M6.5 3 1 21M17.5 3 23 21"}],["path",{"d":"M9 3.8h1.8q.6 0 .6.6v1.7q0 .6-.6.6H8.4q-.7 0-.4-.7l.5-1.5q.1-.7.5-.7Z","stroke-width":1.15}],["path",{"d":"M13.2 3.8H15q.4 0 .5.7L16 6q.3.7-.4.7h-2.4q-.6 0-.6-.6V4.4q0-.6.6-.6Z","stroke-width":1.15}],["path",{"d":"M7.5 8.6h1.3q.7 0 .5.7l-.5 3q-.1.7-.8.7H6q-.8 0-.5-.8l1.1-2.8q.2-.8.9-.8Z","stroke-width":1.15}],["path",{"d":"M11.4 8.6h1.2q.6 0 .7.7l.5 3q.1.7-.6.7h-2.4q-.7 0-.6-.7l.5-3q.1-.7.7-.7Z","stroke-width":1.15}],["path",{"d":"M15.2 8.6h1.3q.7 0 .9.8l1.1 2.8q.3.8-.5.8h-2q-.7 0-.8-.7l-.5-3q-.2-.7.5-.7Z","stroke-width":1.15}],["path",{"d":"M5.8 15h1.8q.8 0 .6.8l-.7 3.9q-.2 1-1 1H4.2q-1 0-.7-1l1.4-3.8q.2-.9.9-.9Z","stroke-width":1.15}],["path",{"d":"M10.6 15h2.8q.7 0 .8.8l.7 3.9q.2 1-.8 1H9.9q-1 0-.8-1l.7-3.9q.1-.8.8-.8Z","stroke-width":1.15}],["path",{"d":"M16.4 15h1.8q.7 0 .9.9l1.4 3.8q.3 1-.7 1h-2.3q-.8 0-1-1l-.7-3.9q-.2-.8.6-.8Z","stroke-width":1.15}]],"ricecake":[["rect",{"x":4,"y":3,"width":16,"height":18,"rx":3}],["path",{"d":"M4 15h16M8 7l1 1m5-2 1 1m-7 4 1 1m6-2 1 1M8 18h8"}]],"can":[["ellipse",{"cx":12,"cy":4,"rx":7,"ry":2}],["path",{"d":"M5 4v16c0 2.7 14 2.7 14 0V4M5 9h14M5 17h14M10 4h4"}]],"neutral":[["path",{"d":"M4 22V3c5-3 10 3 16 0v12c-6 3-11-3-16 0M9 12V6l6 6V6"}]]}; +export const ICONS = {"banana":[["path",{"d":"M4 13c3.5-2 8-2 10 2a5.5 5.5 0 0 1 8 5"}],["path",{"d":"M5.15 17.89c5.52-1.52 8.65-6.89 7-12C11.55 4 11.5 2 13 2c3.22 0 5 5.5 5 8 0 6.5-4.2 12-10.49 12C5.11 22 2 22 2 20c0-1.5 1.14-1.55 3.15-2.11Z"}]],"bottle":[["path",{"d":"M10 4V2h4v2"}],["path",{"d":"M8 4h8q1 0 1 1v2H7V5q0-1 1-1Z"}],["path",{"d":"M8 7c0 1-2 1.8-2 3 0 1 1.3 1.6 1.3 2.6S6 14 6 15v5q0 2 2 2h8q2 0 2-2v-5c0-1-1.3-1.4-1.3-2.4S18 11 18 10c0-1.2-2-2-2-3"}]],"bar":[["path",{"d":"M8 11V3.5Q8 2 9.5 2h5Q16 2 16 3.5V11"}],["path",{"d":"M8 13.5V21q0 1 1 1h6q1 0 1-1v-5.5"}],["path",{"d":"M7.5 11h9v4.5L14 14H7.5Z"}],["circle",{"cx":10.4,"cy":5.2,"r":0.65,"fill":"currentColor","stroke":"none"}],["circle",{"cx":13.6,"cy":5.2,"r":0.65,"fill":"currentColor","stroke":"none"}],["path",{"d":"M10.4 7.4q1.6 1.9 3.2 0"}]],"gel":[["path",{"d":"M9 2h6v2.3l-1 .5 1 .5V6l1 1.5V21q0 1-1 1H9q-1 0-1-1V7.5L9 6V5a1 1 0 0 0 0-2Z"}],["path",{"d":"M8 19.5h8"}]],"smile":[["circle",{"cx":"12","cy":"12","r":"10"}],["path",{"d":"M8 14s1.5 2 4 2 4-2 4-2"}],["line",{"x1":"9","x2":"9.01","y1":"9","y2":"9"}],["line",{"x1":"15","x2":"15.01","y1":"9","y2":"9"}]],"mountain":[["path",{"d":"m8 3 4 8 5-5 5 15H2L8 3z"}]],"feed":[["path",{"d":"M3 2v7c0 1.1.9 2 2 2h4a2 2 0 0 0 2-2V2"}],["path",{"d":"M7 2v20"}],["path",{"d":"M21 15V2a5 5 0 0 0-5 5v6c0 1.1.9 2 2 2h3Zm0 0v7"}]],"flag":[["path",{"d":"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528"}]],"coffee":[["path",{"d":"M10 2v2"}],["path",{"d":"M14 2v2"}],["path",{"d":"M16 8a1 1 0 0 1 1 1v8a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1h14a4 4 0 1 1 0 8h-1"}],["path",{"d":"M6 2v2"}]],"warning":[["path",{"d":"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}],["path",{"d":"M12 9v4"}],["path",{"d":"M12 17h.01"}]],"plus":[["path",{"d":"M5 12h14"}],["path",{"d":"M12 5v14"}]],"print":[["path",{"d":"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}],["path",{"d":"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6"}],["rect",{"x":"6","y":"14","width":"12","height":"8","rx":"1"}]],"download":[["path",{"d":"M12 15V3"}],["path",{"d":"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}],["path",{"d":"m7 10 5 5 5-5"}]],"upload":[["path",{"d":"M12 3v12"}],["path",{"d":"m17 8-5-5-5 5"}],["path",{"d":"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}]],"trash":[["path",{"d":"M10 11v6"}],["path",{"d":"M14 11v6"}],["path",{"d":"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}],["path",{"d":"M3 6h18"}],["path",{"d":"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}]],"copy":[["rect",{"width":"14","height":"14","x":"8","y":"8","rx":"2","ry":"2"}],["path",{"d":"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"}]],"up":[["path",{"d":"m18 15-6-6-6 6"}]],"down":[["path",{"d":"m6 9 6 6 6-6"}]],"settings":[["path",{"d":"M10 5H3"}],["path",{"d":"M12 19H3"}],["path",{"d":"M14 3v4"}],["path",{"d":"M16 17v4"}],["path",{"d":"M21 12h-9"}],["path",{"d":"M21 19h-5"}],["path",{"d":"M21 5h-7"}],["path",{"d":"M8 10v4"}],["path",{"d":"M8 12H3"}]],"check":[["path",{"d":"M20 6 9 17l-5-5"}]],"sun":[["circle",{"cx":"12","cy":"12","r":"4"}],["path",{"d":"M12 2v2"}],["path",{"d":"M12 20v2"}],["path",{"d":"m4.93 4.93 1.41 1.41"}],["path",{"d":"m17.66 17.66 1.41 1.41"}],["path",{"d":"M2 12h2"}],["path",{"d":"M20 12h2"}],["path",{"d":"m6.34 17.66-1.41 1.41"}],["path",{"d":"m19.07 4.93-1.41 1.41"}]],"moon":[["path",{"d":"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401"}]],"monitor":[["rect",{"width":"20","height":"14","x":"2","y":"3","rx":"2"}],["line",{"x1":"8","x2":"16","y1":"21","y2":"21"}],["line",{"x1":"12","x2":"12","y1":"17","y2":"21"}]],"close":[["path",{"d":"M18 6 6 18"}],["path",{"d":"m6 6 12 12"}]],"columns":[["rect",{"width":"18","height":"18","x":"3","y":"3","rx":"2"}],["path",{"d":"M9 3v18"}],["path",{"d":"M15 3v18"}]],"sort":[["path",{"d":"m3 16 4 4 4-4"}],["path",{"d":"M7 20V4"}],["path",{"d":"M11 4h10"}],["path",{"d":"M11 8h7"}],["path",{"d":"M11 12h4"}]],"save":[["path",{"d":"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"}],["path",{"d":"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7"}],["path",{"d":"M7 3v4a1 1 0 0 0 1 1h7"}]],"help":[["circle",{"cx":"12","cy":"12","r":"10"}],["path",{"d":"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}],["path",{"d":"M12 17h.01"}]],"grip":[["circle",{"cx":"9","cy":"12","r":"1"}],["circle",{"cx":"9","cy":"5","r":"1"}],["circle",{"cx":"9","cy":"19","r":"1"}],["circle",{"cx":"15","cy":"12","r":"1"}],["circle",{"cx":"15","cy":"5","r":"1"}],["circle",{"cx":"15","cy":"19","r":"1"}]],"litter":[["path",{"d":"M10 11v6"}],["path",{"d":"M14 11v6"}],["path",{"d":"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}],["path",{"d":"M3 6h18"}],["path",{"d":"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}]],"cobbles":[["path",{"d":"M6.5 3 1 21M17.5 3 23 21"}],["path",{"d":"M9 3.8h1.8q.6 0 .6.6v1.7q0 .6-.6.6H8.4q-.7 0-.4-.7l.5-1.5q.1-.7.5-.7Z","stroke-width":1.15}],["path",{"d":"M13.2 3.8H15q.4 0 .5.7L16 6q.3.7-.4.7h-2.4q-.6 0-.6-.6V4.4q0-.6.6-.6Z","stroke-width":1.15}],["path",{"d":"M7.5 8.6h1.3q.7 0 .5.7l-.5 3q-.1.7-.8.7H6q-.8 0-.5-.8l1.1-2.8q.2-.8.9-.8Z","stroke-width":1.15}],["path",{"d":"M11.4 8.6h1.2q.6 0 .7.7l.5 3q.1.7-.6.7h-2.4q-.7 0-.6-.7l.5-3q.1-.7.7-.7Z","stroke-width":1.15}],["path",{"d":"M15.2 8.6h1.3q.7 0 .9.8l1.1 2.8q.3.8-.5.8h-2q-.7 0-.8-.7l-.5-3q-.2-.7.5-.7Z","stroke-width":1.15}],["path",{"d":"M5.8 15h1.8q.8 0 .6.8l-.7 3.9q-.2 1-1 1H4.2q-1 0-.7-1l1.4-3.8q.2-.9.9-.9Z","stroke-width":1.15}],["path",{"d":"M10.6 15h2.8q.7 0 .8.8l.7 3.9q.2 1-.8 1H9.9q-1 0-.8-1l.7-3.9q.1-.8.8-.8Z","stroke-width":1.15}],["path",{"d":"M16.4 15h1.8q.7 0 .9.9l1.4 3.8q.3 1-.7 1h-2.3q-.8 0-1-1l-.7-3.9q-.2-.8.6-.8Z","stroke-width":1.15}]],"ricecake":[["rect",{"x":4,"y":3,"width":16,"height":18,"rx":3}],["path",{"d":"M4 15h16M8 7l1 1m5-2 1 1m-7 4 1 1m6-2 1 1M8 18h8"}]],"can":[["ellipse",{"cx":12,"cy":4,"rx":7,"ry":2}],["path",{"d":"M5 4v16c0 2.7 14 2.7 14 0V4M5 9h14M5 17h14M10 4h4"}]],"neutral":[["path",{"d":"M4 22V3c5-3 10 3 16 0v12c-6 3-11-3-16 0M9 12V6l6 6V6"}]]}; diff --git a/tests/icon-artwork.test.mjs b/tests/icon-artwork.test.mjs new file mode 100644 index 0000000..8e9f877 --- /dev/null +++ b/tests/icon-artwork.test.mjs @@ -0,0 +1,15 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +test('audited colour interiors preserve original geometry and open-symbol exceptions',async()=>{ + const {iconArtwork,STROKE_ONLY_CUES,COLOURED_OUTLINE}=await import('../dist/icon-fills.js');const {ICONS}=await import('../dist/icons.js');const {SYMBOLS}=await import('../dist/core.js'); + const original=JSON.stringify(ICONS); + assert.deepEqual(STROKE_ONLY_CUES,['feed']); + for(const key of SYMBOLS.filter(Boolean)){ + assert.deepEqual(iconArtwork(key),ICONS[key]);const coloured=iconArtwork(key,true),fills=coloured.filter(([,a])=>Object.hasOwn(a,'data-icon-fill')); + if(key==='feed'){assert.deepEqual(coloured,ICONS.feed);continue;} + assert.ok(fills.length,key);assert.ok(fills.every(([tag,a])=>['path','rect','circle','ellipse'].includes(tag)&&a.fill==='currentColor'&&a.stroke==='none'),key); + const outlines=coloured.slice(fills.length);assert.equal(outlines.length,ICONS[key].length); + outlines.forEach(([tag,a],i)=>{assert.equal(tag,ICONS[key][i][0]);for(const [attr,v]of Object.entries(ICONS[key][i][1]))if(!['fill','stroke'].includes(attr))assert.equal(a[attr],v,`${key} ${attr}`);assert.ok(a.stroke==='none'||a.stroke===COLOURED_OUTLINE);}); + } + assert.equal(JSON.stringify(ICONS),original);assert.ok(iconArtwork('bottle',true).every(([,a])=>!Object.hasOwn(a,'transform')));for(const key of ['bar','gel'])for(const coloured of [false,true])assert.ok(iconArtwork(key,coloured).every(([,a])=>!Object.hasOwn(a,'transform')));assert.equal(iconArtwork('coffee',true).filter(([,a])=>Object.hasOwn(a,'data-icon-fill')).length,1);assert.equal(iconArtwork('cobbles',true).filter(([,a])=>Object.hasOwn(a,'data-icon-fill')).length,8); +}); From 5017b2c6ed8d55d21755d712cad2d3ef1fce1cb0 Mon Sep 17 00:00:00 2001 From: Graham van der Wielen <13894957+grayum@users.noreply.github.com> Date: Mon, 19 Oct 2026 18:07:47 +0200 Subject: [PATCH 2/3] feat: add validated grid modes and shared cell geometry --- dist/core.js | 3 +++ dist/grid.js | 14 ++++++++++++++ tests/grid.test.mjs | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 dist/grid.js create mode 100644 tests/grid.test.mjs diff --git a/dist/core.js b/dist/core.js index 86b80fb..0ac8105 100644 --- a/dist/core.js +++ b/dist/core.js @@ -1,3 +1,4 @@ +import {validateGrid} from './grid.js'; import {BUILTIN_CUES,FLANDERS_CUES} from './presets.js'; // Pure data model: canonical metres and elapsed minutes; no HTML or network access. export const VERSION = 1; @@ -60,6 +61,8 @@ export function validateEvent(e){ if(new Set(out.rows[mode].map(r=>r.id)).size!==out.rows[mode].length)throw Error('Duplicate row IDs.'); } const l=e.layout||{};out.layout={width:finite(l.width,20,180,'width (20–180 mm)'),length:finite(l.length,30,260,'length (30–260 mm)'),font:finite(l.font,8,24,'font size (8–24 pt)'),padding:finite(l.padding,1,8,'padding'),gap:finite(l.gap,0.5,6,'row spacing'),rotation:choice(l.rotation,[0,90,180,270],'rotation'),header:boolean(l.header,'header'),paper:choice(l.paper,['A4','Letter'],'paper'),copies:finite(l.copies,1,4,'copies')}; + if(Object.hasOwn(l,'grid'))out.layout.grid=validateGrid(l.grid); + if(Object.hasOwn(l,'lines'))out.layout.lines=boolean(l.lines,'legacy row lines'); if(!Number.isInteger(l.copies))throw Error('Copies must be a whole number.'); // Absent footer fields mean disabled/empty. Do not inflate old exact-budget plans on load. if(Object.hasOwn(l,'footerEnabled'))out.layout.footerEnabled=boolean(l.footerEnabled,'footer visibility'); diff --git a/dist/grid.js b/dist/grid.js new file mode 100644 index 0000000..eb324de --- /dev/null +++ b/dist/grid.js @@ -0,0 +1,14 @@ +// Millimetres, like the shared SVG layout. Boundaries are drawn once, not per cell. +export const GRID_MODES=['none','rows','full']; +export const GRID_STROKE=.15; +// Shared left/right inset inside each configured column, in every grid mode. +export const CELL_PADDING=.8; +export function validateGrid(mode){if(!GRID_MODES.includes(mode))throw Error('Invalid grid mode. Choose None, Row lines or Full grid.');return mode;} +export const gridMode=layout=>layout.grid??(layout.lines===false?'none':'rows'); +export function setGridMode(layout,mode){validateGrid(mode);if(gridMode(layout)===mode)return false;layout.grid=mode;return true;} +export function gridGeometry({left,right,top,bottom,widths,rowEnds}){ + const inset=GRID_STROKE/2,l=left+inset,r=right-inset; + const horizontal=[top+inset,...rowEnds],vertical=[l];let x=left; + for(const width of widths.slice(0,-1)){x+=width;vertical.push(x);}vertical.push(r); + return {path:[...horizontal.map(y=>`M${l} ${y}H${r}`),...vertical.map(x=>`M${x} ${top+inset}V${bottom}`)].join(' '),inkBottom:bottom+inset}; +} diff --git a/tests/grid.test.mjs b/tests/grid.test.mjs new file mode 100644 index 0000000..12a01ce --- /dev/null +++ b/tests/grid.test.mjs @@ -0,0 +1,18 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {createEvent,validateEvent} from '../dist/core.js'; +import {GRID_STROKE,gridMode,setGridMode,gridGeometry} from '../dist/grid.js'; +test('default/legacy grid mapping and allowlisted overrides preserve old dimensions',()=>{ + const e=createEvent(),l=structuredClone(e.layout);assert.equal(gridMode(l),'rows');for(const [lines,mode] of [[false,'none'],[true,'rows']]){e.layout.lines=lines;assert.equal(gridMode(validateEvent(e).layout),mode);} + for(const mode of ['none','rows','full']){e.layout.grid=mode;assert.equal(gridMode(validateEvent(e).layout),mode);assert.equal(e.layout.width,l.width);} + for(const bad of ['all','Full grid',true,null,1]){e.layout.grid=bad;assert.throws(()=>validateEvent(e),/Invalid grid mode/);} + delete e.layout.grid;e.layout.lines='false';assert.throws(()=>validateEvent(e),/legacy row lines/); +}); +test('grid choices are atomic/no-op aware and preserve legacy preference as history baseline',()=>{ + const l={lines:false};assert.equal(setGridMode(l,'none'),false);assert.equal(setGridMode(l,'full'),true);assert.equal(setGridMode(l,'full'),false);assert.equal(l.lines,false);assert.equal(setGridMode(l,'rows'),true);assert.throws(()=>setGridMode(l,'arbitrary'),/Invalid grid/); +}); +test('shared grid draws each boundary once, inside padding, with bottom ink budget',()=>{ + const g=gridGeometry({left:2,right:30,top:2,bottom:25,widths:[8,10,10],rowEnds:[9,17,25]}); + const moves=g.path.match(/M[^M]+/g).map(x=>x.trim());assert.equal(moves.length,8);assert.equal(new Set(moves).size,8);assert.ok(g.path.includes('M10 2.075V25'));assert.ok(g.path.includes('M20 2.075V25'));assert.equal(g.inkBottom,25+GRID_STROKE/2); + const hidden=gridGeometry({left:2,right:30,top:2,bottom:10,widths:[14,14],rowEnds:[10]});assert.equal(hidden.path.split(' ').filter(x=>x.startsWith('M')).length,5);assert.match(hidden.path,/M16 /); +}); From db8373ec6936bccbb39bff5e07995bcc11ecd78f Mon Sep 17 00:00:00 2001 From: Graham van der Wielen <13894957+grayum@users.noreply.github.com> Date: Mon, 19 Oct 2026 18:08:02 +0200 Subject: [PATCH 3/3] feat: integrate cue colours and full-grid printing for v0.9.0 --- .env.example | 2 +- .github/workflows/checks.yml | 4 +- CHANGELOG.md | 21 ++++ README.md | 24 +++- UPGRADE.md | 42 +++++++ deploy/.env.vps.example | 2 +- dist/app.js | 34 ++++-- dist/core.js | 11 +- dist/index.html | 4 +- dist/styles.css | 8 +- docker-compose.example.yaml | 2 +- docs/ARCHITECTURE.md | 33 +++++- docs/LOCAL-DEVELOPMENT.md | 36 +++++- docs/REVIEW-v0.9.0.md | 172 +++++++++++++++++++++++++++ docs/ROADMAP.md | 6 +- docs/VALIDATION.md | 223 +++++++++++++++++++++++++++++++++++ package.json | 6 +- scripts/container-smoke.sh | 2 +- tests/browser.mjs | 4 + tests/colours.test.mjs | 40 +++++++ tests/v060-browser.mjs | 5 +- tests/v062-browser.mjs | 6 +- tests/v090-browser.mjs | 48 ++++++++ tests/v090-orientation.mjs | 32 +++++ tests/v090-refinements.mjs | 49 ++++++++ tests/v090-zoom.mjs | 28 +++++ 26 files changed, 806 insertions(+), 38 deletions(-) create mode 100644 docs/REVIEW-v0.9.0.md create mode 100644 tests/colours.test.mjs create mode 100644 tests/v090-browser.mjs create mode 100644 tests/v090-orientation.mjs create mode 100644 tests/v090-refinements.mjs create mode 100644 tests/v090-zoom.mjs diff --git a/.env.example b/.env.example index ec63f3f..1d11de5 100644 --- a/.env.example +++ b/.env.example @@ -4,7 +4,7 @@ NGINX_IMAGE=nginx:1.30.5-alpine # Local image built by Compose; use a release digest when promoting to production. -STEMTAPE_IMAGE=stemtape:0.8.0 +STEMTAPE_IMAGE=stemtape:0.9.0 # Only used when you enable the commented Traefik sections: STEMTAPE_DOMAIN=stemtape.example.com diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index f014fe4..1422bdf 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -49,5 +49,5 @@ jobs: run: | docker pull nginx:stable-alpine base_image=$(docker image inspect --format '{{index .RepoDigests 0}}' nginx:stable-alpine) - docker build --build-arg NGINX_IMAGE="$base_image" -t stemtape:0.8.0 . - sh scripts/container-smoke.sh stemtape:0.8.0 + docker build --build-arg NGINX_IMAGE="$base_image" -t stemtape:0.9.0 . + sh scripts/container-smoke.sh stemtape:0.9.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c09ca2..8e20ad3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## 0.9.0 — review candidate (2026-10-19) + +- Add independent per-cue primary-icon colours from a fixed named palette, + with labelled picker choices, selected state and focus restoration. Keep + transparent areas, existing solid details and cue identities. + Fill audited interiors beneath dark detail outlines; Feed zone keeps coloured + strokes. Remove Banana's special yellow default. +- Set Bar, Bottle/Bidon and Gel upright at 0°, removing their artwork rotations + from filled interiors and detail outlines together. Retain bounds and padding. +- Add None / Row lines / Full grid through the shared preview/print renderer; + draw boundaries once, reserve outer stroke space and keep the footer outside. + Use a shared 0.8 mm horizontal inset per cell side across grid modes. +- Preserve colours/grid across history, duplicates, JSON and preset revisions. + Validate optional v1 styling without inflating legacy load-time byte budgets. +- Extend coloured CSVs with a versioned icon-colour metadata column that older + importers reject. Preserve monochrome CSV and all role/value alignment. +- Add data, native-browser, geometry and PDF checks. Final user-reported manual + acceptance dated **2026-10-19** includes Bar, Bottle/Bidon and Gel at 0°. + Physical printing remains unverified and is not a release gate at the user's + request. No deployment or infrastructure changes. + ## 0.8.0 — review candidate (2026-10-18) Final user-reported manual preview acceptance: 2026-10-18, including the final diff --git a/README.md b/README.md index 04365e5..ee91b20 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,28 @@ Open **http://127.0.0.1:8080**. Use this local server rather than opening `index Custom Unicode emojis use the user's system font. The outlined symbols combine **Lucide** with original StemTape symbols, including the approved Bar, Bottle, Gel and Cobbles replacements, not Font Awesome. Lucide 1.8.0 and DejaVu font notices are bundled in `dist/assets/`. No CDN assets or analytics. +## v0.9.0 changes (review candidate) + +- Open a cue's icon picker to choose Default / monochrome, Blue, Orange, Green, + Red or Purple. Colour belongs to the row, survives icon changes/None, and affects + primary icon artwork only. Both Bidon rows can have different colours. +- Layout & print settings → Appearance → Grid: None, Row lines (existing default), + or Full grid. Visible Note/custom columns participate; footer stays outside. +- Colours and grid are undoable and retained in complete JSON, duplicates, personal + presets and their recovery revisions. Old plans remain monochrome with row lines. +- Coloured CSVs add versioned metadata requiring v0.9.0; monochrome CSVs stay in the + previous format. CSV omits grid settings. Older apps lose new styling on JSON save. +- Same selected icon colour on screen, preview and print; audited interior fills + and dark outlines retain gaps/details. Feed zone keeps coloured utensil strokes. + Default Banana is monochrome like every cue. Shared 0.8 mm cell insets keep + artwork/text away from grid borders within configured widths. Browser/printer + settings and greyscale printers can affect colour. Verify an actual-size physical print before use. + +See [design, compatibility and review checklist](docs/REVIEW-v0.9.0.md). +Final user-reported manual preview acceptance: **2026-10-19**, including upright +Bar, Gel and Bottle/Bidon at 0°. Physical printing remains unverified and is not a +release gate at the user's request; production verification is not claimed. + ## v0.8.0 changes (review candidate) - New preset names and renames must be unique after trimming and ignoring case, @@ -203,7 +225,7 @@ npm run test:browser This creates screenshots and an actual PDF in ignored `artifacts/`. Review all screenshots and verify PDF dimensions; passing assertions alone is not visual QA. ```sh -sh scripts/container-smoke.sh stemtape:0.8.0 +sh scripts/container-smoke.sh stemtape:0.9.0 ``` **v0.6.1 validation:** the complete native Chromium suite against the local Docker app, real-browser screenshot/200% zoom review, 69 Node tests, syntax and container checks passed. The owner also reports a passing manual Docker-preview check on 2026-10-09. Physical printing, screen-reader/device testing and production verification are not inferred; remaining gates are recorded in [current validation](docs/VALIDATION.md). diff --git a/UPGRADE.md b/UPGRADE.md index 529fd45..741c931 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,45 @@ +# Upgrade to 0.9.0 (review candidate) + +Preserve complete JSON originals before upgrading. Schema version/key remain v1 +and `stemtape.v1`. Optional row `iconColour` accepts only default/blue/orange/green/ +red/purple; absent means monochrome. Optional layout `grid` accepts only none/rows/ +full. Absent grid uses the old row-line appearance; a legacy boolean `lines` maps +true to rows and false to none. This base had unconditional row separators and no +saved line control. Load does not add styling bytes to legacy exact-budget data. +Unknown styling values reject import/storage validation with useful errors, keeping +original data protected; there is no silent normalization to another colour. + +Colours/grid are included in complete JSON, duplicates, personal templates and the +one previous revision, and the unchanged atomic save/UTF-8 budget path. They are +plan Undo/Redo actions; preset recovery itself stays outside history. Remembered +bike dimensions do not acquire styling preferences. + +Coloured CSVs add the reserved header `stemtape:column:["icon-colour",1]` immediately +after icon, with a stable palette ID per row. All visible user-column data stays +aligned after it. Old CSVs import as monochrome; entirely monochrome exports omit +the new column. Grid remains JSON/preset layout metadata, absent from CSV. + +**Tested rollback limitation:** the actual v0.8.0 validator drops new colour/grid +fields when re-saving JSON, and its CSV importer rejects the new metadata tuple. +Older applications must not be used to edit the only copy of styled plans. +Export complete JSON and retain originals; test older code only on copies in an +isolated profile. No automatic downgrade or lossless older-version round trip is +claimed. Earlier preset/association rollback limitations still apply. + +The visual follow-up adds audited fill layers for selected colours, keeps Feed +zone as coloured strokes and removes the default Banana yellow treatment. +Shared 0.8 mm cell insets replace uneven offsets across grid modes; unusually +tight existing columns may wrap differently or need explicit adjustment. +Dimensions/fonts are never silently changed and overflow still blocks printing. +No additional persisted fields or format changes are needed for these refinements. + +Printing remains client-side, with exact-colour CSS hints already present in the +print stylesheet. Browser/printer options, ink and greyscale output can alter +colours. Shapes/text remain independent identifiers; check physical dimensions +and the printed 50 mm scale. Final user-reported manual preview acceptance on +**2026-10-19** includes Bar/Gel/Bottle upright at 0°. Physical printing remains +unverified and is not a release gate at the user's request. + # Upgrade to 0.8.0 (review candidate) Export complete JSON and preserve originals before updating. Schema v1 and key diff --git a/deploy/.env.vps.example b/deploy/.env.vps.example index 2ce958c..fc23fd0 100644 --- a/deploy/.env.vps.example +++ b/deploy/.env.vps.example @@ -2,5 +2,5 @@ # Put these settings in the project-root .env used by --env-file .env. NGINX_IMAGE=nginx@sha256:REPLACE_WITH_VERIFIED_ALPINE_DIGEST CADDY_IMAGE=caddy@sha256:REPLACE_WITH_VERIFIED_ALPINE_DIGEST -STEMTAPE_IMAGE=stemtape:0.8.0 +STEMTAPE_IMAGE=stemtape:0.9.0 STEMTAPE_DOMAIN=stemtape.example.com diff --git a/dist/app.js b/dist/app.js index 2f32b29..0936f41 100644 --- a/dist/app.js +++ b/dist/app.js @@ -1,3 +1,5 @@ +import {ICON_COLOURS,iconColour,setIconColour} from './icon-colours.js'; +import {gridMode,setGridMode,gridGeometry,GRID_STROKE,CELL_PADDING} from './grid.js'; import {KEY,LIMITS,SYMBOLS,uid,clone,column,createEvent,initialState,validateEvent,displayDistance,toMetres,formatTime,parseTime,cueHeader,cellText,exportCSV,importCSV,moveCue,sortCuesByPosition,serializeState,parseState,restoreObject,totalDistanceMaximum,validatedTotal} from './core.js'; import {BUILTIN_PRESET_NAMES} from './presets.js'; import {presetChange,personalPresetLabel} from './preset-actions.js'; @@ -5,7 +7,7 @@ import {assertEventName,uniqueEventName,eventDisplayLabel} from './names.js'; import {PlanHistory} from './history.js'; import {SaveSession,formatSaveTime} from './save-status.js'; import {footerGeometry} from './footer.js'; -import {ICONS} from './icons.js'; +import {iconArtwork} from './icon-fills.js'; import {cueColumnId,moveColumn,canRemoveColumn,removeColumn} from './columns.js'; import {noteColumn,showNoteColumn} from './note-column.js'; import {columnControls} from './column-controls.js'; @@ -13,7 +15,7 @@ const $=id=>document.getElementById(id),NS='http://www.w3.org/2000/svg'; const names={'':'None',banana:'Banana',bottle:'Bottle',bar:'Bar',gel:'Gel',smile:'Smile',mountain:'Climb',feed:'Feed zone',flag:'Finish',coffee:'Coffee',warning:'Caution',cobbles:'Cobbles / pavé',ricecake:'Rice cake',can:'Softdrink',neutral:'Neutral zone',litter:'Litter zone'}; const el=(tag,a={},text)=>{const n=document.createElement(tag);for(const[k,v]of Object.entries(a))n.setAttribute(k,v);if(text!==undefined)n.textContent=text;return n;}; const svg=(tag,a={},text)=>{const n=document.createElementNS(NS,tag);for(const[k,v]of Object.entries(a))n.setAttribute(k,v);if(text!==undefined)n.textContent=text;return n;}; -function icon(name){const n=svg('svg',{viewBox:'0 0 24 24',fill:'none',stroke:'currentColor','stroke-width':1.8,'stroke-linecap':'round','stroke-linejoin':'round','aria-hidden':'true',class:'icon'});for(const[tag,a]of ICONS[name]||[])n.append(svg(tag,a));return n;} +function icon(name,coloured=false){const n=svg('svg',{viewBox:'0 0 24 24',fill:'none',stroke:'currentColor','stroke-width':1.8,'stroke-linecap':'round','stroke-linejoin':'round','aria-hidden':'true',class:'icon'});for(const[tag,a]of iconArtwork(name,coloured))n.append(svg(tag,a));return n;} function button(text,action,cls='',name){const b=el('button',{type:'button',class:cls},text);if(name)b.prepend(icon(name));b.addEventListener('click',action);return b;} function labelled(text,input){const l=el('label',{},text);l.append(input);return l;} function select(options,value,action){const s=el('select');for(const[v,t]of options)s.append(el('option',{value:v},t));s.value=value;s.dataset.acceptedValue=value;s.onchange=()=>{action(s.value);if(!hasInvalidEdits())s.dataset.acceptedValue=s.value;};return s;} @@ -216,11 +218,11 @@ function updateEvents(){const s=$('event-select');s.replaceChildren(...state.eve function render(force=false){if(!force&&hasInvalidEdits())return;applyTheme();const e=event();updateEvents();$('event-name').value=e.name;clearEventNameError(); $('preset').replaceChildren(el('option',{value:'nutrition'},BUILTIN_PRESET_NAMES.nutrition),el('option',{value:'route'},BUILTIN_PRESET_NAMES.route),el('option',{value:'custom'},BUILTIN_PRESET_NAMES.custom),el('option',{value:'flanders'},BUILTIN_PRESET_NAMES.flanders+' · example'),...state.presets.map((p,i)=>el('option',{value:`saved:${i}`},personalPresetLabel(state.presets,p))));$('preset').value=e.preset; const associated=state.presets.find(p=>p.id&&p.id===e.presetId);$('preset-association').textContent=associated?`Based on preset: ${personalPresetLabel(state.presets,associated)}`:'Custom plan';$('update-preset').hidden=!associated;$('update-preset').title=associated?`Replace ${personalPresetLabel(state.presets,associated)}`:''; -$('unit').value=e.unit;$('mode-distance').setAttribute('aria-pressed',e.mode==='distance');$('mode-time').setAttribute('aria-pressed',e.mode==='time');$('mode-time').disabled=e.preset!=='nutrition';$('unit').disabled=e.mode==='time';$('dimension-unit').value=e.dimensionUnit; +$('grid').value=gridMode(e.layout);$('unit').value=e.unit;$('mode-distance').setAttribute('aria-pressed',e.mode==='distance');$('mode-time').setAttribute('aria-pressed',e.mode==='time');$('mode-time').disabled=e.preset!=='nutrition';$('unit').disabled=e.mode==='time';$('dimension-unit').value=e.dimensionUnit; const factor=e.dimensionUnit==='in'?25.4:1;for(const[id,min,max]of [['width',20,180],['length',30,260]]){const n=$(id);n.min=min/factor;n.max=max/factor;n.step='any';n.value=e.layout[id]/factor;} for(const id of ['font','padding','gap','rotation','paper','copies'])$(id).value=e.layout[id];$('header').checked=e.layout.header;$('footer-enabled').checked=e.layout.footerEnabled??false;$('footer-text').value=e.layout.footerText??'';$('footer-text').disabled=!e.layout.footerEnabled;$('total').max=totalDistanceMaximum(e.unit);$('total').step='any';$('total').value=Math.min(displayDistance(e.totalM,e.unit),totalDistanceMaximum(e.unit));$('remaining').checked=e.remaining;$('remaining').disabled=e.mode==='time';$('mode-note').textContent=e.mode==='time'?'Elapsed time since the start. Enter hours:minutes.':'Distances are entered from the start. Display units can be changed.';renderRows(force);renderPreview();renderColumnSettings();rememberSelects();if(fieldHistory&&!fieldHistory.input.isConnected)finishHistoryField();refreshHistory();} function renderRows(force=false){if(!force&&hasInvalidEdits())return;rowRefreshPending=false;clearTimeout(rowRefreshTimer);const e=event(),rows=e.rows[e.mode];$('row-count').textContent=`${rows.length} ${rows.length===1?'cue':'cues'}`;const head=el('tr');head.append(el('th',{},'#'));e.columns.forEach((c,i)=>{if(i===1)head.append(el('th',{},'Icon'));const th=el('th',{'data-column-id':c.id},i===0?(e.mode==='time'?'h:mm':e.unit):c.label);th.hidden=i>0&&!c.visible;head.append(th);});head.append(el('th',{},''));$('editor-head').replaceChildren(head);const body=$('editor-rows');body.replaceChildren(); -rows.forEach((r,index)=>{const tr=el('tr',{'data-row-id':r.id});const order=el('td',{class:'row-order'}),grip=button('',()=>{},'drag-handle','grip');grip.setAttribute('aria-label',`Reorder row ${index+1}`);grip.setAttribute('aria-describedby','drag-help');grip.title='Drag to reorder · Arrow Up / Down';attachRowDrag(grip,tr,r.id);order.append(grip,el('span',{class:'row-number'},String(index+1)));tr.append(order);e.columns.forEach((c,i)=>{if(i===1){const td=el('td',{class:'symbol-cell'}),b=button('',()=>symbolPicker(r),'symbol-button');b.dataset.symbol=r.symbol;b.setAttribute('aria-label',`Choose icon for row ${index+1}`);b.title=names[r.symbol];b.append(icon(r.symbol||'plus'));td.append(b);tr.append(td);} +rows.forEach((r,index)=>{const tr=el('tr',{'data-row-id':r.id});const order=el('td',{class:'row-order'}),grip=button('',()=>{},'drag-handle','grip');grip.setAttribute('aria-label',`Reorder row ${index+1}`);grip.setAttribute('aria-describedby','drag-help');grip.title='Drag to reorder · Arrow Up / Down';attachRowDrag(grip,tr,r.id);order.append(grip,el('span',{class:'row-number'},String(index+1)));tr.append(order);e.columns.forEach((c,i)=>{if(i===1){const td=el('td',{class:'symbol-cell'}),b=button('',()=>symbolPicker(r),'symbol-button');b.dataset.symbol=r.symbol;b.setAttribute('aria-label',`Choose icon for row ${index+1}`);b.title=`${names[r.symbol]} · ${iconColour(r.iconColour).name}`;b.setAttribute('aria-description',`Icon colour: ${iconColour(r.iconColour).name}`);const artwork=icon(r.symbol||'plus',Boolean(r.symbol&&iconColour(r.iconColour).value));if(r.symbol&&iconColour(r.iconColour).value)artwork.setAttribute('color',iconColour(r.iconColour).value);b.append(artwork);td.append(b);tr.append(td);} const td=el('td',{class:i===0?'distance-cell':''}),isTime=i===0&&e.mode==='time',input=el('input',{'aria-label':`${i===0?(isTime?'Time':e.unit):c.label}, row ${index+1}`});if(isTime){input.type='text';input.placeholder='1:30';input.pattern='[0-9]{1,3}:[0-5][0-9]';input.value=formatTime(r.cells[c.id]);}else if(c.type==='distance'||c.type==='number'){input.type='number';input.min='0';input.max=c.type==='distance'?String(10_000_000/(e.unit==='mi'?1609.344:1000)):'10000000';input.step='any';input.value=c.type==='distance'?displayDistance(r.cells[c.id],e.unit):r.cells[c.id];}else{input.type='text';input.maxLength=LIMITS.text;input.value=r.cells[c.id];} td.dataset.columnId=c.id;td.hidden=i>0&&!c.visible;input.dataset.columnId=c.id; const key=r.id+c.id;input.oninput=()=>{input.setCustomValidity('');try{if(!input.checkValidity()||(input.type==='number'&&input.value===''))throw Error('Enter a valid non-negative number.');const v=isTime?parseTime(input.value):c.type==='distance'?toMetres(input.value,e.unit):c.type==='number'?Number(input.value):input.value;r.cells[c.id]=v;invalidCells.delete(key);if(!commit(false,input))invalidCells.add(key);else if(rowRefreshPending)scheduleRowRefresh();}catch(err){invalidCells.add(key);input.setCustomValidity(err.message);renderPreview();}};let originalValue=r.cells[c.id]; @@ -233,14 +235,21 @@ input.onblur=()=>{ }; if(i===0)input.onkeydown=ev=>{if(ev.key==='Enter'){ev.preventDefault();input.blur();}};td.append(input);tr.append(td);}); const td=el('td'),actions=el('div',{class:'row-actions'});for(const[label,name,action]of [['Move row up','up',()=>{const at=rows.findIndex(row=>row.id===r.id);if(moveCue(rows,r.id,at-1)){commit(true,null,'row reorder');announceMove(r.id,'up');}}],['Move row down','down',()=>{const at=rows.findIndex(row=>row.id===r.id);if(moveCue(rows,r.id,at+1)){commit(true,null,'row reorder');announceMove(r.id,'down');}}],['Delete row','trash',()=>{const at=rows.findIndex(row=>row.id===r.id);if(at>=0)rows.splice(at,1);commit(true,null,'delete row');}]] ){const b=button('',action,'',name);b.setAttribute('aria-label',`${label} ${index+1}`);b.dataset.move=name;if(name!=='trash')b.setAttribute('aria-disabled',String(name==='up'&&index===0||name==='down'&&index===rows.length-1));actions.append(b);}td.append(actions);tr.append(td);body.append(tr);});} -function symbolPicker(row){const d=openDialog('Choose a cue symbol');d.append(el('p',{},'These outline icons print consistently. You can also paste emojis directly into any text field.'));const g=el('div',{class:'option-grid'});for(const name of ['',...SYMBOLS.filter(Boolean).sort((a,b)=>names[a].localeCompare(names[b],'en',{sensitivity:'base'}))]){const b=button(names[name],()=>{row.symbol=name;$('dialog').close();commit(true,null,'change icon');});if(name)b.prepend(icon(name));g.append(b);}d.append(g);} +function symbolPicker(row){ + const d=openDialog('Choose a cue symbol');d.append(el('p',{},'Choose an icon or its colour. Colour belongs to this cue, survives icon changes and is kept when None hides the icon. Text and custom symbol columns keep their existing appearance.')); + const finish=(label)=>{$('dialog').close();commit(true,null,label);Array.from($('editor-rows').children).find(tr=>tr.dataset.rowId===row.id)?.querySelector('.symbol-button')?.focus({preventScroll:true});}; + const palette=el('fieldset',{class:'cue-colours'});palette.append(el('legend',{},'Icon colour')); + for(const colour of ICON_COLOURS){const b=button(colour.name,()=>{if(setIconColour(row,colour.id))finish('change icon colour');else $('dialog').close();},'secondary-button');b.setAttribute('aria-pressed',String((row.iconColour??'default')===colour.id));const sample=icon(row.symbol||'bottle',Boolean(colour.value));if(colour.value)sample.setAttribute('color',colour.value);b.prepend(sample);palette.append(b);}d.append(palette); + const g=el('div',{class:'option-grid'});for(const name of ['',...SYMBOLS.filter(Boolean).sort((a,b)=>names[a].localeCompare(names[b],'en',{sensitivity:'base'}))]){const b=button(names[name],()=>{row.symbol=name;finish('change icon');});if(name){const artwork=icon(name,Boolean(iconColour(row.iconColour).value));if(iconColour(row.iconColour).value)artwork.setAttribute('color',iconColour(row.iconColour).value);b.prepend(artwork);}g.append(b);}d.append(g); +} const ctx=document.createElement('canvas').getContext('2d'); function wrap(text,width,font,bold){ctx.font=`${bold?'700':'400'} ${font}px StemSans`;const lines=[];let line='';for(const ch of Array.from(new Intl.Segmenter(undefined,{granularity:'grapheme'}).segment(text),s=>s.segment)){if(ch==='\n'){lines.push(line);line='';continue;}if(line&&ctx.measureText(line+ch).width>width){const p=line.lastIndexOf(' ');if(p>0){lines.push(line.slice(0,p));line=line.slice(p+1)+ch;}else{lines.push(line);line=ch;}}else line+=ch;}lines.push(line);return lines;} function makeSheet(){const e=event(),l=e.layout,rotated=l.rotation===90||l.rotation===270,w=rotated?l.length:l.width,h=rotated?l.width:l.length;const root=svg('svg',{xmlns:NS,viewBox:`0 0 ${l.width} ${l.length}`,width:`${l.width}mm`,height:`${l.length}mm`,role:'img','aria-label':'Printable cue sheet'});root.append(svg('rect',{width:l.width,height:l.length,fill:'white'}));const g=svg('g');if(l.rotation===90)g.setAttribute('transform',`translate(${l.width} 0) rotate(90)`);if(l.rotation===180)g.setAttribute('transform',`translate(${l.width} ${l.length}) rotate(180)`);if(l.rotation===270)g.setAttribute('transform',`translate(0 ${l.length}) rotate(270)`);root.append(g); -const cols=e.columns.filter(c=>c.visible),sum=cols.reduce((s,c)=>s+c.width,0),inner=w-2*l.padding,widths=cols.map(c=>inner*c.width/sum),font=l.font*25.4/72,lineHeight=font*1.25;let y=l.padding;const warnings=[]; -const draw=(cells,header,row,index)=>{let x=l.padding;const all=cols.map((c,i)=>{const symbol=!header&&row.symbol&&c.id===cueColumnId(e)?row.symbol:null,reserve=symbol?font+1:0,available=widths[i]-1.5-reserve,lines=wrap(cells[i],Math.max(available,1),font,header||c.bold);if(availablectx.measureText(line).width>available+.01))warnings.push(`Column “${c.label}” is too narrow.`);return{lines,symbol,reserve};});const height=Math.max(...all.map(a=>a.lines.length))*lineHeight+l.gap; -all.forEach((a,i)=>{const c=cols[i];if(a.symbol){const ic=icon(a.symbol);for(const[k,v]of Object.entries({x,y:y+.4,width:font,height:font,color:'#111'}))ic.setAttribute(k,v);ic.removeAttribute('class');g.append(ic);}let tx=x+.5+a.reserve,anchor='start';if(c.align==='right'){tx=x+widths[i]-.8;anchor='end';}else if(c.align==='center'){tx=x+widths[i]/2+a.reserve/2;anchor='middle';}a.lines.forEach((line,j)=>g.append(svg('text',{x:tx,y:y+font+j*lineHeight,'font-family':'StemSans','font-size':font,'font-weight':header||c.bold?700:400,'text-anchor':anchor,fill:'#111'},line)));x+=widths[i];});y+=height;g.append(svg('line',{x1:l.padding,y1:y-.4,x2:w-l.padding,y2:y-.4,stroke:header?'#222':'#b9b9b9','stroke-width':header?.3:.15}));if(y>h-l.padding)warnings.push(header?'Headers do not fit.':`Row ${index+1} exceeds the strip length.`);}; +const mode=gridMode(l),full=mode==='full',rowEnds=[];const cols=e.columns.filter(c=>c.visible),sum=cols.reduce((s,c)=>s+c.width,0),inner=w-2*l.padding,widths=cols.map(c=>inner*c.width/sum),font=l.font*25.4/72,lineHeight=font*1.25;let y=l.padding+(full?GRID_STROKE:0);const warnings=[]; +const draw=(cells,header,row,index)=>{let x=l.padding;const all=cols.map((c,i)=>{const symbol=!header&&row.symbol&&c.id===cueColumnId(e)?row.symbol:null,reserve=symbol?font+1:0,available=widths[i]-2*CELL_PADDING-reserve,lines=wrap(cells[i],Math.max(available,1),font,header||c.bold);if(availablectx.measureText(line).width>available+.01))warnings.push(`Column “${c.label}” is too narrow.`);return{lines,symbol,reserve};});const height=Math.max(...all.map(a=>a.lines.length))*lineHeight+l.gap; +all.forEach((a,i)=>{const c=cols[i];if(a.symbol){const ic=icon(a.symbol,Boolean(iconColour(row.iconColour).value));for(const[k,v]of Object.entries({x:x+CELL_PADDING,y:y+.4,width:font,height:font,color:iconColour(row.iconColour).value??'#111','data-cue-icon':row.id}))ic.setAttribute(k,v);ic.removeAttribute('class');g.append(ic);}let tx=x+CELL_PADDING+a.reserve,anchor='start';if(c.align==='right'){tx=x+widths[i]-CELL_PADDING;anchor='end';}else if(c.align==='center'){tx=x+widths[i]/2+a.reserve/2;anchor='middle';}a.lines.forEach((line,j)=>g.append(svg('text',{x:tx,y:y+font+j*lineHeight,'font-family':'StemSans','font-size':font,'font-weight':header||c.bold?700:400,'text-anchor':anchor,fill:'#111'},line)));x+=widths[i];});y+=height;rowEnds.push(y);if(mode==='rows')g.append(svg('line',{x1:l.padding,y1:y-.4,x2:w-l.padding,y2:y-.4,stroke:header?'#222':'#b9b9b9','stroke-width':header?.3:.15}));if(y+(full?GRID_STROKE/2:0)>h-l.padding)warnings.push(header?'Headers do not fit.':`Row ${index+1} exceeds the strip length.`);}; if(l.header)draw(cols.map(c=>cueHeader(e,c)),true,null,0);e.rows[e.mode].forEach((r,i)=>draw(cols.map(c=>cellText(e,c,r.cells[c.id])),false,r,i));if(!e.rows[e.mode].length)warnings.push('Add at least one cue before printing.');if(e.remaining&&e.mode==='distance'&&e.rows.distance.some(r=>r.cells[e.columns[0].id]>e.totalM))warnings.push('A cue is beyond the total ride distance.'); +if(full&&rowEnds.length){const geometry=gridGeometry({left:l.padding,right:w-l.padding,top:l.padding,bottom:y,widths,rowEnds});g.append(svg('path',{d:geometry.path,fill:'none',stroke:'#777','stroke-width':GRID_STROKE,'data-grid':'full'}));y=geometry.inkBottom;} // Footer shares the rotated table coordinate system, never the outer page/calibration area. if(l.footerEnabled&&l.footerText?.trim()){ ctx.font=`400 ${font}px StemSans`; @@ -272,6 +281,7 @@ for(const mode of ['distance','time'])$(`mode-${mode}`).onclick=()=>{if(mode===' for(const id of ['width','length','font','padding','gap','rotation','copies','paper'])$(id).onchange=()=>{const input=$(id);if(!input.checkValidity()||input.value==='')return input.reportValidity();const e=event(),candidate=clone(e);candidate.layout[id]=id==='paper'?input.value:Number(input.value)*(id==='width'||id==='length'?(e.dimensionUnit==='in'?25.4:1):1);try{e.layout=validateEvent(candidate).layout;commit(false,input);}catch(err){input.setCustomValidity(err.message);toast(err.message);renderPreview();}}; $('footer-enabled').onchange=()=>{event().layout.footerEnabled=$('footer-enabled').checked;if(commit(false,null,'toggle footer'))$('footer-text').disabled=!event().layout.footerEnabled;}; $('footer-text').oninput=()=>{const input=$('footer-text');event().layout.footerText=input.value;commit(false,input);}; +$('grid').onchange=()=>{if(setGridMode(event().layout,$('grid').value))commit(true,null,'change grid');}; $('header').onchange=()=>{event().layout.header=$('header').checked;commit(false,null,'toggle headers');};$('remaining').onchange=()=>{event().remaining=$('remaining').checked;commit(false,null,'toggle distance remaining');};$('total').onchange=()=>{const input=$('total');input.setCustomValidity('');try{const metres=validatedTotal(input.value,event().unit);if(!input.checkValidity())throw Error('Enter a valid total distance.');event().totalM=metres;commit(false,input);}catch(err){input.setCustomValidity(err.message);renderPreview();}};$('save-bike').onclick=()=>{try{const{width,length,padding,rotation}=event().layout;state.bike={width,length,padding,rotation};if(save())toast(storageOK&&!recoveryBlocked?'Bike dimensions saved for new plans.':'Bike dimensions changed in memory — not saved.');}catch{toast('Could not save bike dimensions.');}}; $('add-row').onclick=()=>{const e=event(),rows=e.rows[e.mode];if(rows.length>=LIMITS.rows)return toast('Maximum 200 cues per mode.');const r={id:uid(),symbol:'',cells:{}};e.columns.forEach((c,i)=>r.cells[c.id]=c.type==='number'||c.type==='distance'?i===0?(rows.at(-1)?.cells[c.id]||0):0:'');rows.push(r);commit(true,null,'insert row');$('editor-rows').lastElementChild?.querySelector('input')?.focus();};$('sort').onclick=()=>{const e=event();sortCuesByPosition(e.rows[e.mode],e.columns[0].id);commit(true,null,'sort rows');}; // Successful preset writes alone expose replacement/recovery and association changes. @@ -298,7 +308,7 @@ function confirmPreset(title,text,action){confirmAction(title,text,action);$('di $('update-preset').onclick=()=>{ const p=state.presets.find(p=>p.id&&p.id===event().presetId);if(!p)return; const d=openDialog('Update preset?');d.append(el('p',{},`Replace “${p.name}” (personal preset ${state.presets.indexOf(p)+1}) with this plan? The preset name stays “${p.name}”. Existing ride plans stay unchanged. One previous version is retained; preset actions are outside plan Undo/Redo.`)); - d.append(el('p',{},'Captures the event name, both distance/time cue lists and their manual order, icons and all cell contents (including hidden Note text); column labels, types, widths, order, visibility, alignment and bold; planning mode, units, total/remaining distance; and all sheet/print settings: dimensions, font, padding, row spacing, rotation, header, footer, paper and copies. It does not capture theme, remembered bike dimensions or session Undo/Redo history. New plans use the captured event name with a unique suffix if needed.')); + d.append(el('p',{},'Captures the event name, both distance/time cue lists and their manual order, icons, cue icon colours and all cell contents (including hidden Note text); column labels, types, widths, order, visibility, alignment and bold; planning mode, units, total/remaining distance; and all sheet/print settings: dimensions, font, padding, row spacing, grid mode, rotation, header, footer, paper and copies. It does not capture theme, remembered bike dimensions or session Undo/Redo history. New plans use the captured event name with a unique suffix if needed.')); const a=el('div',{class:'dialog-actions'});a.append(button('Cancel',()=>$('dialog').close()),button('Update preset',()=>{if(persistPreset('update',{id:p.id}))$('dialog').close();},'primary'),button('Rename preset…',()=>renamePreset(p),'secondary-button')); if(p.previous)a.append(button('Restore previous version',()=>confirmPreset('Restore previous preset version?',`Restore “${p.previous.name}” for ${personalPresetLabel(state.presets,p)}? Existing plans stay unchanged. The current version becomes the one recovery revision.`,()=>{if(persistPreset('recover',{id:p.id}))toast('Previous preset version restored.');}),'secondary-button')); a.append(button('Delete personal preset',()=>confirmPreset('Delete personal preset?',`Delete “${p.name}” (personal preset ${state.presets.indexOf(p)+1}) and its recovery version? Associated plans are kept and unlinked. Export JSON first.`,()=>{if(persistPreset('delete',{id:p.id})){toast('Personal preset deleted; plans kept.');$('save-preset').focus({preventScroll:true});}}),'danger-button'));d.append(a);a.querySelector('button').focus(); @@ -359,19 +369,19 @@ function columnsDialog(){ $('column-settings').onclick=columnsDialog;$('column-details').onclick=columnsDialog; function download(content,type,name){const url=URL.createObjectURL(new Blob([content],{type})),a=el('a',{href:url,download:name});document.body.append(a);a.click();a.remove();setTimeout(()=>URL.revokeObjectURL(url),1500);} function filename(){return event().name.replace(/[^a-zA-Z0-9_-]/g,'-').replace(/-+/g,'-').slice(0,60)||'stemtape';} -$('export').onclick=()=>{const d=openDialog('Export your plan');if(recoveryBlocked)offerOriginal(d);d.append(el('p',{},'CSV contains the current mode’s visible data columns, plus position and icon. JSON backs up hidden content, all events, both modes, presets and preferences.'));d.append(button('CSV · current cue table',()=>{download(exportCSV(event()),'text/csv;charset=utf-8',`${filename()}-${event().mode}.csv`);$('dialog').close();},'export-option','download'),button('JSON · complete backup',()=>{download(serializeState(state),'application/json','stemtape-backup.json');$('dialog').close();},'export-option','save'));d.append(el('p',{},'CSV protects formula-like text for spreadsheets. Use JSON for exact preservation of custom types, formatting and text.'));}; +$('export').onclick=()=>{const d=openDialog('Export your plan');if(recoveryBlocked)offerOriginal(d);d.append(el('p',{},'CSV contains the current mode’s visible data columns, plus position and icon. Coloured cues add versioned metadata requiring v0.9.0 or later; grid settings require JSON. JSON backs up hidden content, all events, both modes, presets and preferences.'));d.append(button('CSV · current cue table',()=>{download(exportCSV(event()),'text/csv;charset=utf-8',`${filename()}-${event().mode}.csv`);$('dialog').close();},'export-option','download'),button('JSON · complete backup',()=>{download(serializeState(state),'application/json','stemtape-backup.json');$('dialog').close();},'export-option','save'));d.append(el('p',{},'CSV protects formula-like text for spreadsheets. Use JSON for exact preservation of custom types, formatting and text.'));}; $('import').onclick=()=>{ const d=openDialog('Import from your device');d.append(el('p',{},'Files and pasted tables stay on this device.')); const options=el('div',{class:'import-options'}); const file=el('section',{class:'import-card','aria-labelledby':'import-file-title'}); - file.append(el('h3',{id:'import-file-title'},'CSV or JSON file'),el('p',{},'CSV creates a new event. The first column must be distance_km, distance_mi or time (h:mm), optionally followed by icon, then your cue columns.'),el('p',{},'JSON backups are validated before you choose whether to restore. Maximum file and complete-state size: 2,000,000 UTF-8 bytes.'),button('Choose CSV or JSON',()=>$('file-input').click(),'primary','upload')); + file.append(el('h3',{id:'import-file-title'},'CSV or JSON file'),el('p',{},'CSV creates a new event. The first column must be distance_km, distance_mi or time (h:mm), optionally followed by icon, versioned icon-colour metadata when exported by v0.9.0, then your cue columns.'),el('p',{},'JSON backups are validated before you choose whether to restore. Maximum file and complete-state size: 2,000,000 UTF-8 bytes.'),button('Choose CSV or JSON',()=>$('file-input').click(),'primary','upload')); const paste=el('section',{class:'import-card','aria-labelledby':'import-paste-title'}); paste.append(el('h3',{id:'import-paste-title'},'Spreadsheet table'),el('p',{},'Copy a range including headers from your spreadsheet, then paste it to create a new event.'),button('Paste spreadsheet table',pasteTable)); options.append(file,paste);d.append(options); }; $('file-input').onchange=async()=>{const f=$('file-input').files[0];$('file-input').value='';if(!f)return;try{if(f.size>LIMITS.bytes)throw Error('File exceeds 2,000,000 UTF-8 bytes. Keep this original file for recovery; it has not been changed.');const text=await f.text();/* Reading yields: recheck drafts created while the file was loading. */if(hasInvalidEdits())throw Error('Correct or cancel unaccepted edits before importing.');if(f.name.toLowerCase().endsWith('.csv')){const e=importCSV(text);$('dialog').close();if(addEvent(e))toast('CSV imported as a new event.');}else if(f.name.toLowerCase().endsWith('.json')){const candidate=parseState(text),d=openDialog('Restore backup?');d.append(el('p',{},`This replaces your ${state.events.length} current event(s) with ${candidate.events.length} event(s) from the backup, including preferences and presets.`));if(recoveryBlocked)offerOriginal(d);const a=el('div',{class:'dialog-actions'});a.append(button(recoveryBlocked?'Back up temporary in-memory plan':'Back up current data',()=>download(serializeState(state),'application/json','stemtape-before-restore.json')),button('Restore backup',()=>{$('dialog').close();if(replaceLibrary(candidate))toast('Backup restored.');},'primary'));d.append(a);}else throw Error('Choose a .csv or .json file.');}catch(err){const d=openDialog('Import could not be completed');d.append(el('p',{},`${err.message} Your existing plans have not been changed.`));}}; function offerOriginal(d){d.append(el('p',{class:'warning'},'The original saved data is protected. The visible plan is temporary fallback data, not your original. Replacement will overwrite the original; export it first.'),button('Export original recovery data',()=>download(recoveryOriginal??'','application/json','stemtape-recovery.json')));} -function help(){const d=openDialog('Your plan. Your device.');const guidance=el('p',{},'Create your cues, choose a usable stem or top-tube width and length, then print at ');guidance.append(el('strong',{},'Scale 100% / Actual size.'),document.createTextNode(' Fit to page can change physical dimensions. Disable browser print headers and footers. Check the printed 50 mm scale with a ruler.'));d.append(guidance);for(const text of ['Undo and Redo keep up to 20 completed actions per plan in this tab, within an 8 MiB shared snapshot budget (large plans may keep fewer actions). Switching plans keeps separate histories; reloading clears them. History is never saved or exported. Plan creation/deletion, presets, library restore, theme and remembered bike dimensions are excluded. New or duplicated plans start empty; successful library replacement clears history. Correct or explicitly cancel invalid drafts before Undo/Redo. Valid restored changes stay in memory if saving fails; export a backup when Not saved is shown.', +function help(){const d=openDialog('Your plan. Your device.');const guidance=el('p',{},'Create your cues, choose a usable stem or top-tube width and length, then print at ');guidance.append(el('strong',{},'Scale 100% / Actual size.'),document.createTextNode(' Fit to page can change physical dimensions. Disable browser print headers and footers. Check the printed 50 mm scale with a ruler.'));d.append(guidance);for(const text of ['Icon colour applies only to the primary cue artwork: fixed named colours fill audited interior regions with dark detail outlines, preserving transparent gaps. Feed zone uses coloured strokes for its open utensils. Default keeps theme-aware screen and monochrome print appearance. Colour stays with each row when its icon changes or is hidden by None. Grid options are None, Row lines (the default), and Full grid, including visible columns and an outer border; the footer stays outside the grid. Both settings are undoable and included in JSON and personal preset revisions. Coloured CSVs use an optional versioned stemtape:column: metadata column for icon-colour v1; older versions reject these coloured CSVs. Monochrome CSVs stay compatible. Grid is not included in CSV. Keep a complete JSON backup before rollback: older apps discard these styling fields. Browser/printer settings and greyscale printers can change or omit colours; always verify an actual-size physical print and its 50 mm scale. Colour is an aid, not the only cue identifier.','Undo and Redo keep up to 20 completed actions per plan in this tab, within an 8 MiB shared snapshot budget (large plans may keep fewer actions). Switching plans keeps separate histories; reloading clears them. History is never saved or exported. Plan creation/deletion, presets, library restore, theme and remembered bike dimensions are excluded. New or duplicated plans start empty; successful library replacement clears history. Correct or explicitly cancel invalid drafts before Undo/Redo. Valid restored changes stay in memory if saving fails; export a backup when Not saved is shown.', 'Event name names this ride plan, not its preset. Event names are unique among saved ride plans; preset names are unique among personal and built-in presets. Both checks trim whitespace and ignore case, preserving chosen capitalization. An event and a preset may share a name. New, duplicated, CSV/spreadsheet-imported and preset-created plans get a unique event name, adding (2), (3), etc. Existing duplicate names and complete JSON restores stay intact and have distinguishable numbered labels. Renaming requires a unique name. A conflicting event-name draft stays visible without changing the last accepted name; correct it or press Escape to cancel. If Undo/Redo would restore a name another plan has taken, the action is blocked with history intact: rename the other plan, then retry.', 'Save as new preset associates this plan with a personal copy. New preset names and preset renames must be unique after trimming and ignoring case, including built-in names. Existing duplicate names and JSON imports are preserved; numbered personal-preset labels distinguish entries without showing IDs. Content updates with an unchanged name and recovery remain available for existing duplicates. Update preset preserves its preset name and captures the current event name, both cue lists, columns, units and all plan layout/print settings. Rename preset is a separate action that leaves saved template contents and existing event names unchanged. Update preset replaces only the associated identity, after confirmation, never another same-name preset or a bundled example. Duplicates retain their association; plan renames do not rename presets. Deleting a personal preset keeps and unlinks its plans. Updating keeps one previous version; Restore previous version swaps it with the current version. These operations require successful storage and are outside plan Undo/Redo. Complete JSON retains identities, associations and recovery; CSV does not. Older versions may discard new metadata or reject new example plans: export JSON before rollback.', 'Tour of Flanders is a supplied example ride plan with no edition/year or official-route verification. Its Location Note is visible. Adjust the sheet if its 19 cues overflow; printing remains blocked until everything fits.', diff --git a/dist/core.js b/dist/core.js index 0ac8105..96d1feb 100644 --- a/dist/core.js +++ b/dist/core.js @@ -1,3 +1,4 @@ +import {validateIconColour} from './icon-colours.js'; import {validateGrid} from './grid.js'; import {BUILTIN_CUES,FLANDERS_CUES} from './presets.js'; // Pure data model: canonical metres and elapsed minutes; no HTML or network access. @@ -55,6 +56,7 @@ export function validateEvent(e){ if(!Array.isArray(e.rows?.[mode])||e.rows[mode].length>LIMITS.rows)throw Error('Too many rows (maximum 200 per mode).'); out.rows[mode]=e.rows[mode].map(r=>{ const row={id:str(r.id,64,'row ID'),symbol:choice(r.symbol,SYMBOLS,'symbol'),cells:{}}; + if(Object.hasOwn(r,'iconColour'))row.iconColour=validateIconColour(r.iconColour); for(const [i,c] of cols.entries()){const value=r.cells?.[c.id];row.cells[c.id]=c.type==='distance'||c.type==='number'?finite(value,0,i===0&&mode==='time'?59999:10_000_000,'cell value'):str(value,LIMITS.text,'cell text');if(i===0&&mode==='time'&&!Number.isInteger(value))throw Error('Elapsed time must use whole minutes.');} return row; }); @@ -118,14 +120,15 @@ export function parseCSV(text){ // Spreadsheet-safe CSV is not a lossless backup; JSON preserves exact strings. export function safeCSVCell(v){let s=String(v??'');if(/^[\s]*[=+\-@\t\r\n]/.test(s))s="'"+s;return '"'+s.replaceAll('"','""')+'"';} export function exportCSV(e){ - const cols=e.columns.slice(1).filter(c=>c.visible),head=[e.mode==='time'?'time':`distance_${e.unit}`,'icon',...cols.map(c=>csvHeader(c,e.unit,e))]; - return '\uFEFF'+[head,...e.rows[e.mode].map(r=>[e.mode==='time'?formatTime(r.cells[e.columns[0].id]):displayDistance(r.cells[e.columns[0].id],e.unit),r.symbol,...cols.map(c=>c.type==='distance'?displayDistance(r.cells[c.id],e.unit):r.cells[c.id])])].map(r=>r.map(safeCSVCell).join(',')).join('\r\n'); + const cols=e.columns.slice(1).filter(c=>c.visible),coloured=e.rows[e.mode].some(r=>r.iconColour&&r.iconColour!=='default'),head=[e.mode==='time'?'time':`distance_${e.unit}`,'icon',...(coloured?[CSV_COLOUR_HEADER]:[]),...cols.map(c=>csvHeader(c,e.unit,e))]; + return '\uFEFF'+[head,...e.rows[e.mode].map(r=>[e.mode==='time'?formatTime(r.cells[e.columns[0].id]):displayDistance(r.cells[e.columns[0].id],e.unit),r.symbol,...(coloured?[r.iconColour??'default']:[]),...cols.map(c=>c.type==='distance'?displayDistance(r.cells[c.id],e.unit):r.cells[c.id])])].map(r=>r.map(safeCSVCell).join(',')).join('\r\n'); } export function importCSV(text){ const data=parseCSV(text);if(data.length<2)throw Error('CSV needs a header and at least one row.'); const h=data.shift().map(v=>v.trim()),first=h[0]?.toLowerCase(),mode=['time','h:mm'].includes(first)?'time':'distance'; if(!['time','h:mm','distance_km','km','distance_mi','mi'].includes(first))throw Error('First CSV column must be distance_km, distance_mi or time (h:mm).'); - const iconIndex=h[1]?.toLowerCase()==='icon'?1:-1,start=iconIndex===1?2:1; + const iconIndex=h[1]?.toLowerCase()==='icon'?1:-1,colourIndex=iconIndex===1&&h[2]===CSV_COLOUR_HEADER?2:-1,start=colourIndex===2?3:iconIndex===1?2:1; + if(h.some((v,i)=>v.startsWith('stemtape:column:["icon-colour"')&&i!==colourIndex))throw Error('Unsupported or misplaced CSV cue-colour metadata. Use v0.9.0 or later and preserve its header.'); if((h.length-start<1&&iconIndex!==1)||h.length-start>7)throw Error('CSV needs 1–7 cue columns, or position and icon only.'); const meta=h.slice(start).map(parseCSVHeader); if(['cue','note'].some(role=>meta.filter(c=>c.role===role).length>1))throw Error('Duplicate CSV column role.'); @@ -140,6 +143,7 @@ export function importCSV(text){ const raw=values[0].trim();if(!raw)throw Error('Every row needs a distance or time.'); const n=mode==='time'?parseTime(raw):toMetres(raw,e.unit);if(!Number.isFinite(n)||n<0)throw Error('Distances must be positive numbers.'); const r={id:uid(),symbol:iconIndex===1?values[1]:'',cells:{[e.columns[0].id]:n}}; + if(colourIndex===2){const colour=validateIconColour(values[colourIndex]);if(colour!=='default')r.iconColour=colour;} e.columns.slice(1).forEach((c,i)=>{ if(!meta[i]){r.cells[c.id]='';return;} const value=values[start+i];if(c.type==='distance'&&!value.trim())throw Error('Every distance cell needs a number.'); @@ -193,6 +197,7 @@ export function restoreObject(target,source) { // Explicit metadata avoids confusing literal labels such as "Water [km]" with units. const CSV_COLUMN_PREFIX='stemtape:column:'; +const CSV_COLOUR_HEADER='stemtape:column:["icon-colour",1]'; function csvHeader(c,unit,e) { const role=c.id===e.noteColumnId?'note':c.id===e.cueColumnId?'cue':null; const meta=[c.type==='distance'?'distance':'text',c.label,c.type==='distance'?unit:null]; diff --git a/dist/index.html b/dist/index.html index 4557485..f510bc3 100644 --- a/dist/index.html +++ b/dist/index.html @@ -20,7 +20,7 @@

Appearance

-
+

Columns

Distance/time stays first. Drag a handle, use Move left/right, or press arrow keys, Home or End on a handle.

    @@ -30,7 +30,7 @@