(() => { 'use strict'; const root = document.getElementById('rj-ui-demo'); if (!root) return; const $ = id => root.querySelector('#' + id); let items = [ {id:1,title:'Review checkout labels',status:'active',description:'Check that the visible label and accessible name agree. This is a fictional example, not a live project.'}, {id:2,title:'Test keyboard navigation',status:'active',description:'Move through the complete flow without a pointer; verify focus order and dialog return focus.'}, {id:3,title:'Document offline recovery',status:'done',description:'Name the difference between queued locally and saved to the service. This record is fictional.'} ]; let selected = 1, nextId = 4, searchTimer; const announce = text => { $('u-announcement').textContent = text; }; function render() { const query=$('u-search').value.trim().toLocaleLowerCase(); const filter=root.querySelector('input[name="u-filter"]:checked').value; const visible=items.filter(item=>(filter==='all'||item.status===filter)&&item.title.toLocaleLowerCase().includes(query)); $('u-results').replaceChildren(); $('u-selection-note').hidden=visible.some(item=>item.id===selected); visible.forEach(item=>{ const b=document.createElement('button'); b.type='button';b.className='u-record';b.setAttribute('aria-pressed',String(item.id===selected)); const label=document.createElement('span');label.textContent=item.title;const sub=document.createElement('small');sub.textContent=(item.status==='done'?'Done':'Active')+(item.id===selected?' / Selected':''); b.append(label,sub);b.addEventListener('click',()=>{selected=item.id;renderDetail();root.querySelectorAll('.u-record').forEach(el=>el.setAttribute('aria-pressed',String(el===b)));render();const replacement=Array.from(root.querySelectorAll('.u-record')).find(el=>el.getAttribute('aria-pressed')==='true');if(replacement)replacement.focus();announce('Selected '+item.title);}); $('u-results').append(b); }); if(!visible.length){const p=document.createElement('p');p.textContent='No matching tasks. Clear search or choose All.';$('u-results').append(p);} $('u-count').textContent=visible.length+' of '+items.length+' fictional tasks'; renderDetail(); } function renderDetail(){const item=items.find(i=>i.id===selected);$('u-detail-title').textContent=item.title;$('u-detail-description').textContent=item.description;$('u-detail-status').textContent=item.status==='done'?'Done':'Active';$('u-complete').textContent=item.status==='done'?'Reopen task':'Mark complete';} $('u-theme').addEventListener('click',()=>{const dark=root.dataset.theme!=='dark';root.dataset.theme=dark?'dark':'light';$('u-theme').setAttribute('aria-pressed',String(dark));$('u-theme').textContent=dark?'Light appearance':'Dark appearance';announce((dark?'Dark':'Light')+' appearance. Not saved.');}); const adapters={web:'DOM + semantic HTML. Preserve browser links, Back and keyboard behaviour.',hybrid:'Web UI in a native host. Adapt safe areas, keyboard, Back and narrow plugin permissions.',ios:'SwiftUI / UIKit controls. Preserve Dynamic Type, VoiceOver, native navigation and system sheets.',android:'Kotlin / Compose controls. Preserve 48 dp targets, TalkBack, insets and system Back.',windows:'WinUI 3 / XAML controls. Preserve keyboard accelerators, UI Automation and window behaviour.',mac:'SwiftUI / AppKit controls. Preserve menus, Cmd shortcuts, VoiceOver and native windows.',shared:'React Native or Flutter is a renderer choice. Map semantic tokens; verify each platform independently.'}; $('u-platform').addEventListener('change',()=>{$('u-platform-note').textContent=adapters[$('u-platform').value];announce('Adapter guidance updated. The specimen remains browser-rendered.');}); $('u-search').addEventListener('input',()=>{render();clearTimeout(searchTimer);searchTimer=setTimeout(()=>announce($('u-count').textContent),300);}); root.querySelectorAll('input[name="u-filter"]').forEach(el=>el.addEventListener('change',()=>{render();announce($('u-count').textContent);})); $('u-complete').addEventListener('click',()=>{const item=items.find(i=>i.id===selected);item.status=item.status==='done'?'active':'done';render();announce(item.title+': '+(item.status==='done'?'complete':'reopened')+'. Demo only.');}); const states={ready:'Ready: the example workspace is available.',loading:'Loading: keep the task label and avoid duplicate requests. This is a state specimen, not a network request.',empty:'Empty: no records yet. Offer one clear create action.',error:'Service error: keep entered data and offer a safe retry. This is simulated.',offline:'Offline: distinguish queued locally from synced to the service. No local storage is used in this specimen.'}; $('u-state').addEventListener('change',()=>{$('u-state-message').textContent=states[$('u-state').value];announce(states[$('u-state').value]);}); $('u-feedback').addEventListener('click',()=>announce('Example action complete. No data was sent or stored.')); const dialog=$('u-dialog'); function close(){dialog.close();$('u-new').focus();} $('u-new').addEventListener('click',()=>{if(typeof dialog.showModal!=='function'){announce('This browser needs a dialog fallback before using this feature.');return;}$('u-form').reset();$('u-error').hidden=true;$('u-title').removeAttribute('aria-invalid');dialog.showModal();$('u-title').focus();}); $('u-cancel').addEventListener('click',close); dialog.addEventListener('cancel',()=>{setTimeout(()=>$('u-new').focus(),0);}); $('u-form').addEventListener('submit',event=>{event.preventDefault();const title=$('u-title').value.trim();if(!title){$('u-error').hidden=false;$('u-title').setAttribute('aria-invalid','true');$('u-title').focus();announce('Enter a title before creating a task.');return;}items.push({id:nextId,title,status:'active',description:'New fictional task. In-memory demo only.'});selected=nextId++;$('u-search').value='';root.querySelector('input[name="u-filter"][value="all"]').checked=true;render();close();announce('Created '+title+'. In-memory demo only.');}); render(); })();