aboutsummaryrefslogtreecommitdiffhomepage
path: root/styleguide.js
blob: 0a7050a3e5694ef6fd585c2b3c22a0fec80b56df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const PW_TOKENS = {
  "version": "1.0.0",
  "brand": {
    "carbon": "#171715",
    "graphite": "#2E2E2A",
    "pewter": "#B8B5AB",
    "porcelain": "#F2EFE9",
    "signal": "#C12735",
    "signal-bright": "#D32939",
    "signal-deep": "#861E28",
    "amber": "#DAB16B",
    "jade": "#50B39A",
    "copper": "#C79A80"
  },
  "light": {
    "canvas": "#F2EFE9",
    "surface": "#FFFCF7",
    "raised": "#E1DED5",
    "inset": "#F8F5EF",
    "text": "#272620",
    "muted": "#615F56",
    "border": "#CBC7BD",
    "control-border": "#817D72",
    "focus": "#A52C36",
    "link": "#A52C36",
    "primary": "#C12735",
    "on-primary": "#FFFFFF",
    "primary-hover": "#A51F2C",
    "primary-active": "#861E28",
    "firefly": "#8A5D20",
    "on-firefly": "#FFFFFF",
    "firefly-hover": "#704A17",
    "firefly-active": "#593B13",
    "success": "#186950",
    "success-bg": "#DFEDE6",
    "warning": "#785018",
    "warning-bg": "#EEE5D3",
    "danger": "#A52C36",
    "danger-bg": "#F2DDDD",
    "info": "#615F56",
    "info-bg": "#E7E4DC",
    "inactive": "#615F56",
    "selection": "#EFD8D7",
    "on-selection": "#272620",
    "hover": "#EEEAE1",
    "disabled": "#77736A",
    "disabled-bg": "#E7E3DA"
  },
  "dark": {
    "canvas": "#171715",
    "surface": "#22221F",
    "raised": "#2E2E2A",
    "inset": "#141412",
    "text": "#E8E6DF",
    "muted": "#ADA99F",
    "border": "#484840",
    "control-border": "#7A7971",
    "focus": "#DAB16B",
    "link": "#D8D4C9",
    "primary": "#C12735",
    "on-primary": "#FFFFFF",
    "primary-hover": "#D32939",
    "primary-active": "#A82330",
    "firefly": "#DAB16B",
    "on-firefly": "#171715",
    "firefly-hover": "#E6C28A",
    "firefly-active": "#C39955",
    "success": "#50B39A",
    "success-bg": "#1C332D",
    "warning": "#DAB16B",
    "warning-bg": "#352C1D",
    "danger": "#F1989C",
    "danger-bg": "#3C2225",
    "info": "#B8B5AB",
    "info-bg": "#30302C",
    "inactive": "#ADA99F",
    "selection": "#48272A",
    "on-selection": "#E8E6DF",
    "hover": "#30302C",
    "disabled": "#918E85",
    "disabled-bg": "#30302C"
  }
};
'use strict';
const root=document.documentElement, $=s=>document.querySelector(s), $$=s=>Array.from(document.querySelectorAll(s));
const titleCase=s=>s.replace(/-/g,' ').replace(/\b\w/g,c=>c.toUpperCase());
let toastTimeout;
function notify(msg){const t=$('#toast');t.textContent=msg;t.hidden=false;clearTimeout(toastTimeout);toastTimeout=setTimeout(()=>t.hidden=true,3000)}
async function copy(value){try{await navigator.clipboard.writeText(value);notify('Copied to clipboard');}catch{try{const e=document.createElement('textarea');e.value=value;e.style.position='fixed';e.style.opacity='0';document.body.append(e);e.select();const ok=document.execCommand('copy');e.remove();if(!ok)throw Error();notify('Copied to clipboard');}catch{notify('Copy unavailable. Select the text manually.')}}}
const stored=(()=>{try{return localStorage.getItem('pw-styleguide-mode')}catch{return null}})();
const mode=['light','dark','auto'].includes(stored)?stored:'dark';
function setMode(value){root.dataset.pwTheme=value;$$('[data-mode]').forEach(b=>b.setAttribute('aria-pressed',String(b.dataset.mode===value)));try{localStorage.setItem('pw-styleguide-mode',value)}catch{}}
setMode(mode);
function renderLogoLibrary(){
  const host=$('#logo-library'),library=window.PW_LOGO_LIBRARY;
  if(!host)return;
  if(!library?.assets?.length){host.innerHTML='<p class="pw-alert pw-danger">The local logo manifest could not be loaded.</p>';return}
  const products=[...new Map(library.assets.map(asset=>[asset.productSlug,asset.product])).entries()];
  host.innerHTML=products.map(([slug,name])=>{
    const assets=library.assets.filter(asset=>asset.productSlug===slug);
    const cards=assets.map(asset=>{
      const rows=library.sizes.map(size=>{
        const files=asset.raster[String(size)];
        return '<div class="logo-download-row"><span>'+size+'px</span><a href="'+files.png+'" target="_blank" rel="noopener" aria-label="Open '+asset.product+' '+asset.variantLabel+' '+size+' by '+size+' PNG in a new tab">PNG</a><a href="'+files.webp+'" target="_blank" rel="noopener" aria-label="Open '+asset.product+' '+asset.variantLabel+' '+size+' by '+size+' WebP in a new tab">WebP</a></div>';
      }).join('');
      return '<article class="logo-asset-card '+asset.preview+'-spec"><div class="logo-asset-preview"><img src="'+asset.svg+'" alt="'+asset.product+' '+asset.variantLabel+' logo"></div><div class="logo-asset-meta"><h4>'+asset.variantLabel+'</h4><code>'+asset.slug+'</code><div class="logo-primary-download"><a href="'+asset.svg+'" download>SVG</a><span aria-hidden="true">·</span><span>'+library.sizes.length*2+' raster files</span></div><details><summary>PNG &amp; WebP sizes</summary><div class="logo-downloads">'+rows+'</div></details></div></article>';
    }).join('');
    return '<section class="logo-product-group" aria-labelledby="logo-group-'+slug+'"><div class="logo-group-heading"><h3 id="logo-group-'+slug+'">'+name+'</h3><span class="mono muted small">'+assets.length+' approved treatments</span></div><div class="logo-asset-grid">'+cards+'</div></section>';
  }).join('');
}
renderLogoLibrary();
$$('[data-mode]').forEach(b=>b.addEventListener('click',()=>setMode(b.dataset.mode)));
$('#nav-toggle').addEventListener('click',()=>{const open=$('#side-nav').classList.toggle('open');$('#nav-toggle').setAttribute('aria-expanded',String(open))});
const navLinks=$$('.nav-group a');
navLinks.forEach(a=>a.addEventListener('click',()=>{$('#side-nav').classList.remove('open');$('#nav-toggle').setAttribute('aria-expanded','false')}));
$('#nav-search').addEventListener('input',e=>{const q=e.target.value.trim().toLowerCase();let visible=0;for(const a of navLinks){const match=!q||a.textContent.toLowerCase().includes(q)||($(a.hash)?.textContent.toLowerCase().includes(q));a.hidden=!match;if(match)visible++}$$('.nav-group').forEach(g=>g.hidden=Array.from(g.querySelectorAll('a')).every(a=>a.hidden));$('#nav-count').hidden=!q;$('#nav-count').textContent=visible+' matching sections'});
let activeId='';
function updateNav(){const sections=$$('main section[id]');let current=sections[0].id;for(const s of sections)if(s.getBoundingClientRect().top<160)current=s.id;if(activeId!==current){activeId=current;navLinks.forEach(a=>{const active=a.hash==='#'+current;a.classList.toggle('active',active);if(active)a.setAttribute('aria-current','location');else a.removeAttribute('aria-current')})}}
let scheduled=false;addEventListener('scroll',()=>{if(!scheduled){scheduled=true;requestAnimationFrame(()=>{updateNav();scheduled=false})}},{passive:true});addEventListener('resize',updateNav);updateNav();
const descriptions={canvas:'Page foundation',surface:'Panels and cards',raised:'Title bars and elevated areas',inset:'Recessed fields and code',text:'Main text',muted:'Secondary text',border:'Decorative separators','control-border':'Interactive control boundaries',focus:'Keyboard focus',link:'Ordinary links',primary:'Master primary action','on-primary':'Primary action text','primary-hover':'Primary hover','primary-active':'Primary pressed',firefly:'Firefly product action','on-firefly':'Amber action text','firefly-hover':'Firefly hover','firefly-active':'Firefly pressed',success:'Connected / success','success-bg':'Positive callout background',warning:'Attention / pending','warning-bg':'Warning callout background',danger:'Error / destructive','danger-bg':'Error callout background',info:'Information','info-bg':'Informational callout',inactive:'Idle / offline',selection:'Selected surface','on-selection':'Selected text',hover:'Hover surface',disabled:'Disabled text','disabled-bg':'Disabled surface'};
function makeCopy(hex){return '<button type="button" class="token-copy" data-hex="'+hex+'" aria-label="Copy '+hex+'"><span style="background:'+hex+'"></span>'+hex+'</button>'}
$('#brand-swatches').innerHTML=Object.entries(PW_TOKENS.brand).map(([n,c])=>'<button class="swatch" type="button" data-hex="'+c+'" aria-label="Copy '+titleCase(n)+' '+c+'"><span class="swatch-color" style="background:'+c+'"></span><span class="swatch-info"><strong>'+titleCase(n)+'</strong><code>'+c+'</code></span></button>').join('');
function tokens(q=''){const items=Object.entries(PW_TOKENS.light).filter(([k,v])=>[k,v,PW_TOKENS.dark[k],descriptions[k]].join(' ').toLowerCase().includes(q.toLowerCase()));$('#token-rows').innerHTML=items.map(([k,v])=>'<tr><td>--pw-'+k+'</td><td>'+descriptions[k]+'</td><td>'+makeCopy(v)+'</td><td>'+makeCopy(PW_TOKENS.dark[k])+'</td></tr>').join('');$('#token-count').textContent=items.length+' of '+Object.keys(PW_TOKENS.light).length+' functional tokens'}
tokens();$('#token-filter').addEventListener('input',e=>tokens(e.target.value));
$('#space-demo').innerHTML=[4,8,12,16,24,32].map(n=>'<div><span>'+n+'px</span><b style="width:'+n*3+'px"></b></div>').join('');
document.addEventListener('click',e=>{const c=e.target.closest('[data-hex],[data-copy-target]');if(!c)return;if(c.dataset.hex)copy(c.dataset.hex);else copy(document.getElementById(c.dataset.copyTarget).textContent.trim())});
$$('[data-product]').forEach(b=>b.addEventListener('click',()=>{$('#component-sandbox').dataset.pwProduct=b.dataset.product;$$('[data-product]').forEach(x=>x.setAttribute('aria-pressed',String(x===b)))}));
$$('[data-demo]').forEach(b=>b.addEventListener('click',()=>$('#button-result').textContent=b.dataset.demo+' selected. No real action performed.'));
$('#form-demo').addEventListener('submit',e=>{e.preventDefault();$('#form-state').textContent='✓ Sample saved: '+$('#samplecall').value.toUpperCase()+' / '+$('#samplemode').value+'. No live submission.';$('#form-state').style.color='var(--pw-success)'});
const rows={Users:[['N8EI','A','DMR','success','On air','18:42:07'],['W8WKY','B','D-Star','inactive','Idle','18:40:12']],Nodes:[['K8OH','A','YSF','success','Connected','18:41:00'],['W1AW','B','DMR','inactive','Idle','18:35:20']],Peers:[['XLX720','A','XLX','success','Connected','18:42:12'],['XLX123','C','XLX','warning','Pending','18:37:05']]};
$$('[data-tab]').forEach(b=>b.addEventListener('click',()=>{$$('[data-tab]').forEach(x=>{x.classList.toggle('active',x===b);x.setAttribute('aria-pressed',String(x===b))});$('#sample-table-heading').textContent='Recently heard '+b.dataset.tab.toLowerCase();$('#sample-table-body').innerHTML=rows[b.dataset.tab].map(([call,mod,protocol,state,status,t])=>'<tr><td class="mono">'+call+'</td><td>'+mod+'</td><td>'+protocol+'</td><td><span class="pw-status pw-'+state+'">'+status+'</span></td><td class="mono">'+t+'</td></tr>').join('')}));