web/control-panel-inventory/inventory-preview.html
2026-11-27 23:43:05 +00:00

46 lines
No EOL
19 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>DuneRealms account inventory — layout preview</title><style>body{margin:0;background:#0a1516;color:#f2eee3;font:15px system-ui;padding:clamp(14px,3vw,36px)}main{max-width:1060px;margin:auto}.preview-brand{letter-spacing:.14em;font-size:13px;color:#e4bb72}.preview-note{color:#b1c3ba;font-size:13px}</style><style>.dr-inventory{--bg:#101f20;--line:#35514b;--gold:#e4bb72;--muted:#b1c3ba;--text:#f2eee3;background:var(--bg);color:var(--text);border:1px solid var(--line);border-radius:20px;padding:clamp(16px,3vw,30px);font:15px/1.5 system-ui,sans-serif;margin:24px 0;box-sizing:border-box}.dr-inventory *{box-sizing:border-box}.dr-inventory [hidden]{display:none!important}.dr-inventory h2{font:500 clamp(25px,4vw,36px)/1.15 Georgia,serif;margin:4px 0 10px}.dr-inventory h3{font-size:16px;margin:0 0 12px}.dr-inventory p{margin:0 0 12px}.dr-inventory .kit-eyebrow{color:var(--gold);letter-spacing:.16em;font-size:11px;font-weight:700}.dr-inventory .kit-muted{color:var(--muted);font-size:13px}.dr-inventory .kit-heading{display:flex;justify-content:space-between;align-items:center;gap:16px;flex-wrap:wrap;margin-bottom:22px}.dr-inventory button{font:inherit;color:inherit;background:#233c36;border:1px solid #48665a;border-radius:8px;padding:9px 14px;cursor:pointer}.dr-inventory button:hover{background:#315246}.dr-inventory button:focus-visible{outline:3px solid var(--gold);outline-offset:3px}.dr-inventory button:disabled{opacity:.55;cursor:wait}.dr-inventory .kit-layout{display:grid;grid-template-columns:minmax(240px,.8fr) minmax(0,1.6fr);gap:22px}.dr-inventory .kit-equipment{background:linear-gradient(160deg,#213c36,#142a28 70%);border:1px solid var(--line);border-radius:14px;padding:20px;min-width:0}.dr-inventory .kit-person{display:grid;grid-template-columns:46px minmax(90px,1fr) 46px;gap:8px;align-items:center;min-height:240px}.dr-inventory .kit-armor-slots{display:grid;gap:10px}.dr-inventory .kit-mannequin{display:block;width:100%;max-width:170px;margin:auto;filter:drop-shadow(0 16px 12px #071b1880);image-rendering:pixelated}.dr-inventory .kit-avatar-label{text-align:center;margin:6px 0 18px;color:var(--muted);font-size:12px}.dr-inventory .kit-xp{display:flex;justify-content:space-between;gap:8px;color:#b7d58b;font-size:13px;margin:12px 0 7px}.dr-inventory .kit-xp-track{height:5px;background:#0a1916;border-radius:8px;overflow:hidden}.dr-inventory .kit-xp-fill{height:100%;background:#afd178}.dr-inventory .kit-tabs{display:flex;gap:5px;flex-wrap:wrap;margin-bottom:20px;border-bottom:1px solid var(--line);padding-bottom:12px}.dr-inventory .kit-tabs button{border:0;background:transparent;padding:8px 10px;color:var(--muted);font-size:13px}.dr-inventory .kit-tabs button[aria-selected=true]{background:#364b38;color:#f4d49b}.dr-inventory .kit-grid{display:grid;grid-template-columns:repeat(9,minmax(0,1fr));gap:6px}.dr-inventory button.kit-slot{position:relative;border-radius:6px;aspect-ratio:1;padding:5px;width:100%;min-width:0;background:linear-gradient(135deg,#253b36,#1a302c);border:1px solid #43574b;display:grid;place-items:center;box-shadow:inset 2px 2px #ffffff08,inset -2px -2px #00000025}.dr-inventory button.kit-slot[data-equipped=true]{border-color:#d3af70;background:#3d4735}.dr-inventory button.kit-slot[aria-pressed=true]{outline:2px solid var(--gold);outline-offset:1px}.dr-inventory .kit-slot svg{width:100%;height:100%;max-width:42px;image-rendering:pixelated;filter:drop-shadow(2px 3px 0 #0005)}.dr-inventory .kit-count{position:absolute;right:4px;bottom:0;font-size:12px;color:#fff;text-shadow:1px 1px #000}.dr-inventory .kit-empty{color:#72867a;font-size:19px}.dr-inventory .kit-hotbar{margin-top:10px;border-top:1px solid var(--line);padding-top:10px}.dr-inventory .kit-grid-title{display:flex;justify-content:space-between;margin:0 0 8px;font-size:12px;color:var(--muted)}.dr-inventory .kit-detail{background:#1c302c;border:1px solid var(--line);border-radius:10px;padding:14px 16px;margin-top:18px;min-height:76px}.dr-inventory .kit-detail strong{display:block;color:#f1d19b;margin-bottom:3px}.dr-inventory .kit-detail p{margin:0;color:var(--muted);font-size:13px;overflow-wrap:anywhere}.dr-inventory .kit-notice{color:var(--muted);padding:14px 0}.dr-inventory .kit-footer{font-size:12px;color:var(--muted);margin-top:20px;border-top:1px solid var(--line);padding-top:12px}.dr-inventory .kit-sale{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px 16px;padding:13px 0;border-bottom:1px solid var(--line)}.dr-inventory .kit-sale small{display:block;color:var(--muted);font-size:12px}.dr-inventory .kit-sale strong{color:#f1d19b;font-size:14px;overflow-wrap:anywhere}.dr-inventory .kit-money{text-align:right;white-space:nowrap;color:#c6da96;font-size:14px}.dr-inventory .kit-older{margin-top:14px}.dr-inventory .kit-hand span{font-size:10px;color:var(--muted)}@media(max-width:760px){.dr-inventory .kit-layout{grid-template-columns:1fr}.dr-inventory .kit-equipment{display:grid;grid-template-columns:1fr 1fr;gap:0 18px}.dr-inventory .kit-equipment h3{grid-column:1/-1}.dr-inventory .kit-person{grid-row:2/5;min-height:220px}.dr-inventory .kit-avatar-label{align-self:end}.dr-inventory .kit-xp{align-self:end}.dr-inventory .kit-mannequin{max-width:140px}.dr-inventory .kit-grid{gap:5px}}@media(max-width:380px){.dr-inventory .kit-equipment{display:block}.dr-inventory .kit-person{max-width:240px;margin:auto}.dr-inventory .kit-tabs button{padding:7px}.dr-inventory .kit-slot svg{max-width:24px}.dr-inventory .kit-count{font-size:10px}.dr-inventory .kit-grid{gap:3px}}
</style><main><p class="preview-brand">DUNEREALMS.COM / YOUR ACCOUNT</p><p class="preview-note">Layout preview with fictional inventory and sales. No account or server connection.</p><section id="preview"></section></main><script>const armorKeys=['helmet','chestplate','leggings','boots'];
const node=(tag,text,cls)=>{const e=document.createElement(tag);if(text!==undefined)e.textContent=text;if(cls)e.className=cls;return e;};
const money=value=>new Intl.NumberFormat(undefined,{maximumFractionDigits:2,minimumFractionDigits:2}).format(Number(value));
const colors={NETHERITE:'#69616f',DIAMOND:'#62d6cc',IRON:'#d5d6c7',GOLDEN:'#e7bc57',CHAINMAIL:'#9da9a6',LEATHER:'#9b7050'};
function armorColor(item){if(!item)return null;if(/^#[0-9a-f]{6}$/i.test(item.color||''))return item.color;return Object.entries(colors).find(([key])=>item.material?.startsWith(key))?.[1]||'#a9b4a8';}
function rect(svg,x,y,w,h,fill){const e=document.createElementNS('http://www.w3.org/2000/svg','rect');for(const [k,v]of Object.entries({x,y,width:w,height:h,fill}))e.setAttribute(k,v);svg.append(e);}
function svgBox(box){const s=document.createElementNS('http://www.w3.org/2000/svg','svg');s.setAttribute('viewBox',box);s.setAttribute('aria-hidden','true');s.setAttribute('shape-rendering','crispEdges');return s;}
function mannequin(armor){const s=svgBox('0 0 80 144');s.classList.add('kit-mannequin');
rect(s,18,136,44,3,'#0a1f1a');rect(s,28,6,24,24,'#bd906d');rect(s,28,6,24,7,'#3c3026');rect(s,28,13,4,8,'#3c3026');rect(s,33,17,4,3,'#cfe6df');rect(s,43,17,4,3,'#cfe6df');rect(s,35,18,2,2,'#396e8b');rect(s,43,18,2,2,'#396e8b');rect(s,37,24,8,2,'#805d48');
rect(s,16,32,12,38,'#aa8164');rect(s,52,32,12,38,'#aa8164');rect(s,16,32,12,18,'#457d78');rect(s,52,32,12,18,'#376862');rect(s,28,32,24,39,'#457d78');rect(s,28,32,5,39,'#56938a');rect(s,28,71,11,53,'#2e414d');rect(s,41,71,11,53,'#253946');rect(s,28,119,11,9,'#463b33');rect(s,41,119,11,9,'#392f29');
const color=Object.fromEntries(armorKeys.map(k=>[k,armorColor(armor?.[k])]));
if(color.helmet){rect(s,26,3,28,11,color.helmet);rect(s,26,14,4,15,color.helmet);rect(s,50,14,4,15,color.helmet);rect(s,29,5,22,2,'#ffffff40');}
if(color.chestplate){rect(s,27,32,26,39,color.chestplate);rect(s,14,32,14,15,color.chestplate);rect(s,52,32,14,15,color.chestplate);rect(s,30,35,4,32,'#ffffff25');rect(s,46,35,5,32,'#00000025');rect(s,35,34,10,7,'#142a2855');}
if(color.leggings){rect(s,27,71,26,10,color.leggings);rect(s,27,81,12,30,color.leggings);rect(s,41,81,12,30,color.leggings);rect(s,29,83,3,24,'#ffffff20');rect(s,49,83,3,24,'#00000025');}
if(color.boots){rect(s,26,111,13,18,color.boots);rect(s,41,111,13,18,color.boots);rect(s,26,125,13,4,'#00000035');rect(s,41,125,13,4,'#00000035');}return s;}
function itemIcon(item){const s=svgBox('0 0 24 24'),m=item?.material||'',c=armorColor(item)||'#c7b67f';
if(/HELMET/.test(m)){rect(s,4,4,16,8,c);rect(s,4,12,4,7,c);rect(s,16,12,4,7,c);rect(s,7,5,10,2,'#ffffff55');}
else if(/CHESTPLATE/.test(m)){rect(s,6,5,12,15,c);rect(s,2,4,5,7,c);rect(s,17,4,5,7,c);rect(s,9,4,6,4,'#263b37');rect(s,8,10,2,8,'#ffffff35');}
else if(/LEGGINGS/.test(m)){rect(s,5,4,14,5,c);rect(s,5,9,5,12,c);rect(s,14,9,5,12,c);}
else if(/BOOTS/.test(m)){rect(s,4,5,6,14,c);rect(s,14,5,6,14,c);rect(s,2,16,8,4,c);rect(s,14,16,8,4,c);}
else if(/SWORD|SHOVEL|PICKAXE|AXE/.test(m)){rect(s,7,14,3,7,'#9b7750');rect(s,10,5,4,11,c);rect(s,6,13,12,3,c);if(/PICKAXE|AXE/.test(m))rect(s,4,4,15,5,c);}
else if(/DYE|SPICE/.test(m)){rect(s,7,5,10,3,'#c97732');rect(s,4,9,16,9,'#df9447');rect(s,7,18,10,3,'#b85c29');rect(s,7,10,6,3,'#ffd18b');}
else if(/SHIELD/.test(m)){rect(s,5,3,14,14,'#a4aaa1');rect(s,8,5,8,13,'#8b7054');rect(s,8,17,8,4,'#a4aaa1');}
else if(/DIAMOND|EMERALD/.test(m)){const f=m.includes('DIAMOND')?'#64d8d0':'#61be87';rect(s,7,4,10,4,f);rect(s,4,8,16,8,f);rect(s,7,16,10,4,f);rect(s,7,7,4,4,'#d3fff2');}
else if(/INGOT/.test(m)){rect(s,4,8,16,9,m.includes('GOLD')?'#e9c367':'#c6cbc3');rect(s,7,5,13,5,m.includes('GOLD')?'#ffe29a':'#eef0e5');rect(s,4,17,16,3,'#7f8371');}
else if(/BREAD|FOOD|CARROT/.test(m)){rect(s,3,9,17,9,'#c5954c');rect(s,6,6,11,4,'#e0b168');rect(s,7,8,2,7,'#f1cf89');rect(s,13,8,2,7,'#f1cf89');}
else{rect(s,4,5,15,14,'#8e9a7b');rect(s,4,5,15,4,'#b4bc92');rect(s,15,9,4,10,'#6e7a60');rect(s,6,11,3,3,'#c4bc8a');}return s;}
function mountInventory(root,{request=async path=>{const r=await fetch(path,{credentials:'same-origin',cache:'no-store'});const data=await r.json();if(!r.ok)throw Error(data.message||'Please try again later.');return data;},demo=false}={}){
root.classList.add('dr-inventory');root.replaceChildren();const heading=node('header',undefined,'kit-heading'),titles=node('div');titles.append(node('div',demo?'ACCOUNT / INVENTORY PREVIEW':'ACCOUNT / PLANETARY INVENTORY','kit-eyebrow'),node('h2','Your expedition kit'),node('p','Everything you carry, across the five worlds.','kit-muted'));const refresh=node('button','Refresh');refresh.type='button';heading.append(titles,refresh);root.append(heading);
const status=node('p','Loading your saved inventory…','kit-notice');status.setAttribute('role','status');root.append(status);const layout=node('div',undefined,'kit-layout');layout.hidden=true;root.append(layout);
const equipment=node('section',undefined,'kit-equipment');equipment.append(node('h3','Equipped armor'));const person=node('div',undefined,'kit-person'),armorSlots=node('div',undefined,'kit-armor-slots'),avatar=node('div'),hand=node('div',undefined,'kit-hand');person.append(armorSlots,avatar,hand);equipment.append(person,node('p','Equipment mannequin · dummy skin','kit-avatar-label'));const xp=node('div',undefined,'kit-xp'),track=node('div',undefined,'kit-xp-track'),fill=node('div',undefined,'kit-xp-fill');track.setAttribute('role','progressbar');track.setAttribute('aria-label','Progress to next experience level');track.setAttribute('aria-valuemin','0');track.setAttribute('aria-valuemax','100');track.append(fill);equipment.append(xp,track);layout.append(equipment);
const content=node('section'),tabs=node('div',undefined,'kit-tabs');tabs.setAttribute('role','tablist');tabs.setAttribute('aria-label','Account inventory sections');content.append(tabs);layout.append(content);const panel=node('div');panel.id='kit-panel-'+Math.random().toString(36).slice(2);panel.setAttribute('role','tabpanel');content.append(panel);const detail=node('div',undefined,'kit-detail');detail.setAttribute('aria-live','polite');content.append(detail);const footer=node('p',undefined,'kit-footer');root.append(footer);
let data=null,active='inventory',generation=0,historyGeneration=0,historyRows=[],cursor=null;
function select(item,label){detail.replaceChildren(node('strong',item?.name||label||'Empty slot'));if(item)detail.append(node('p',`${item.amount} × ${item.material.replaceAll('_',' ').toLowerCase()}${item.enchanted?' · Enchanted':''}${item.maxDurability?` · Durability ${item.durability} / ${item.maxDurability}`:''}`));else detail.append(node('p','Select an item to inspect its saved details.'));}
function slot(item,label,equipped=false){const b=node('button',undefined,'kit-slot');b.type='button';b.setAttribute('aria-label',label+': '+(item?`${item.name}, quantity ${item.amount}`:'empty'));b.dataset.equipped=String(equipped);if(item){b.append(itemIcon(item));if(item.amount>1)b.append(node('span',String(item.amount),'kit-count'));}else b.append(node('span','·','kit-empty'));b.onclick=()=>{root.querySelectorAll('.kit-slot[aria-pressed]').forEach(e=>e.removeAttribute('aria-pressed'));b.setAttribute('aria-pressed','true');select(item,label);};return b;}
function grid(items,count,label,hot=false){const wrap=node('div',undefined,hot?'kit-hotbar':''),title=node('div',undefined,'kit-grid-title');title.append(node('span',label),node('span',`${(items||[]).filter(Boolean).length} / ${count} slots`));wrap.append(title);const g=node('div',undefined,'kit-grid');for(let i=0;i<count;i++)g.append(slot(items?.[i],`${label} slot ${i+1}`,hot&&data?.snapshot?.selectedSlot===i));wrap.append(g);return wrap;}
const tabButtons={};for(const [key,title]of [['inventory','Inventory'],['history','History of sales']]){const b=node('button',title);b.type='button';b.id=panel.id+'-'+key;b.setAttribute('role','tab');b.setAttribute('aria-controls',panel.id);b.setAttribute('aria-selected',String(key===active));b.onclick=()=>{active=key;renderPanel();};tabs.append(b);tabButtons[key]=b;}
function renderPanel(){for(const [k,b]of Object.entries(tabButtons))b.setAttribute('aria-selected',String(k===active));panel.setAttribute('aria-labelledby',tabButtons[active].id);panel.replaceChildren();detail.hidden=active==='history';historyGeneration++;
if(active==='history'){historyRows=[];cursor=null;loadSales(false);return;}const s=data?.snapshot;if(!s){panel.append(node('p','No saved items yet.','kit-muted'));return;}panel.append(grid(s.inventory,27,'Backpack'),grid(s.hotbar,9,'Hotbar',true));}
async function loadSales(older){const token=++historyGeneration;panel.replaceChildren(node('p','Loading sales…','kit-muted'));try{const r=await request('/api/exchange/sales-history'+(older&&cursor?'?before='+encodeURIComponent(cursor):''));if(token!==historyGeneration)return;historyRows=older?[...historyRows,...(r.sales||[])]:r.sales||[];cursor=r.nextCursor;panel.replaceChildren(node('h3','History of sales'));if(!historyRows.length)panel.append(node('p',r.status==='unlinked'?'Link your Minecraft account to view your sales.':'No completed sales yet. Sales made after this update appear here.','kit-muted'));for(const sale of historyRows){const row=node('article',undefined,'kit-sale'),left=node('div');left.append(node('strong',sale.display_name||sale.material.replaceAll('_',' ')),node('small',`${sale.quantity} item${sale.quantity===1?'':'s'} · ${sale.origin.replaceAll('_',' ')} · Buyer: ${sale.buyer_name}`),node('small',new Date(sale.sold_at).toLocaleString()));const right=node('div',undefined,'kit-money');right.append(node('div','+'+money(sale.total_price)),node('small','Solari'));row.append(left,right);panel.append(row);}if(cursor){const more=node('button','Load older sales','kit-older');more.type='button';more.onclick=()=>loadSales(true);panel.append(more);}}catch(error){if(token===historyGeneration)panel.replaceChildren(node('p',error.message,'kit-notice'));}}
async function refreshData(){const token=++generation;refresh.disabled=true;status.textContent='Loading your saved inventory…';status.hidden=false;layout.hidden=true;historyGeneration++;try{const r=await request('/api/inventory');if(token!==generation)return;data=r;layout.hidden=false;status.hidden=r.status==='ready';status.textContent=r.message||'';const s=r.snapshot||{};armorSlots.replaceChildren(...armorKeys.map(k=>slot(s.armor?.[k],k)));avatar.replaceChildren(mannequin(s.armor));hand.replaceChildren(slot(s.offhand,'Offhand'),node('span','Offhand'));xp.replaceChildren(node('span','Level '+(s.level||0)),node('span',s.playerName||'Minecraft account'));const progress=Math.max(0,Math.min(100,Number(s.experienceProgress||0)*100));fill.style.width=progress+'%';track.setAttribute('aria-valuenow',String(Math.round(progress)));select(null);footer.textContent=demo?'DEMO DATA · Layout preview only. Lobby and ender chests remain separate.':r.status==='ready'?`Saved ${new Date(r.updatedAt||s.capturedAt).toLocaleString()} · ${r.sessionOpen?'Active or unclean session; showing last saved items.':'Last completed save.'} Read only. Lobby and ender chests remain separate.`:'Planetary servers only. Lobby and ender chests remain separate.';renderPanel();}catch(error){if(token!==generation)return;data=null;layout.hidden=true;status.hidden=false;status.textContent=error.message;footer.textContent='Inventory could not be loaded.';}finally{if(token===generation)refresh.disabled=false;}}
refresh.onclick=refreshData;refreshData();return{refresh:refreshData,clear(){generation++;historyGeneration++;data=null;historyRows=[];root.replaceChildren();}};
}
const inventoryFixture={"status": "ready", "sessionOpen": false, "updatedAt": "2026-10-27T11:00:00Z", "snapshot": {"version": 1, "playerName": "DesertTraveller", "capturedAt": "2026-10-27T11:00:00Z", "level": 23, "experienceProgress": 0.62, "selectedSlot": 0, "armor": {"helmet": {"material": "LEATHER_HELMET", "name": "Fremen helmet", "amount": 1, "color": "#c18c48", "enchanted": true}, "chestplate": {"material": "LEATHER_CHESTPLATE", "name": "Fremen chestplate", "amount": 1, "color": "#c18c48", "enchanted": true}, "leggings": {"material": "LEATHER_LEGGINGS", "name": "Fremen leggings", "amount": 1, "color": "#c18c48", "enchanted": true}, "boots": {"material": "LEATHER_BOOTS", "name": "Fremen boots", "amount": 1, "color": "#c18c48", "enchanted": true}}, "offhand": {"material": "SHIELD", "name": "Caravan shield", "amount": 1}, "inventory": [{"material": "ORANGE_DYE", "name": "Melange Spice", "amount": 64}, {"material": "ORANGE_DYE", "name": "Melange Spice", "amount": 32}, {"material": "IRON_INGOT", "name": "Iron ingot", "amount": 24}, {"material": "GOLD_INGOT", "name": "Gold ingot", "amount": 8}, {"material": "DIAMOND", "name": "Diamond", "amount": 5}, {"material": "BREAD", "name": "Bread", "amount": 16}, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null], "hotbar": [{"material": "NETHERITE_SHOVEL", "name": "Spice Harvest Shovel", "amount": 1, "durability": 1885, "maxDurability": 2031}, {"material": "IRON_SWORD", "name": "Desert blade", "amount": 1, "enchanted": true}, null, {"material": "BREAD", "name": "Bread", "amount": 12}, null, null, null, null, null]}};const salesFixture={"status": "ready", "sales": [{"id": "3", "display_name": "Melange Spice", "material": "ORANGE_DYE", "quantity": 1, "total_price": "150.00", "origin": "arrakis", "buyer_name": "CaravanTrader", "sold_at": "2026-10-27T10:45:00Z"}, {"id": "2", "display_name": "Gold ingot", "material": "GOLD_INGOT", "quantity": 1, "total_price": "85.00", "origin": "kaitain", "buyer_name": "GuildMerchant", "sold_at": "2026-10-27T09:30:00Z"}], "nextCursor": null};mountInventory(document.getElementById('preview'),{demo:true,request:async path=>structuredClone(path.startsWith('/api/exchange')?salesFixture:inventoryFixture)});</script></html>