Moduł gier Tablicy matematycznej.
{
"format": "mw-games-1",
"version": 57,
"games": [
{
"id": "tictactoe",
"action": "mw-v33-tictactoe",
"title": "Kółko i krzyżyk",
"label": "Kółko i krzyżyk",
"icon": "<span class=\"solid-icon\"><svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.7\" stroke-linecap=\"round\"><path d=\"M8 3v18M16 3v18M3 8h18M3 16h18M4 4l3 3m0-3L4 7\"/><circle cx=\"12\" cy=\"12\" r=\"2.3\"/><path d=\"m17 17 3 3m0-3-3 3\"/></svg></span>",
"source": "<!doctype html><html lang=\"pl\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>\n*{box-sizing:border-box}html,body{margin:0;background:#000;color:#fff;font:600 16px Arial,sans-serif;color-scheme:dark}#game{height:100dvh;min-height:320px;display:flex;flex-direction:column;align-items:center;padding:clamp(8px,1.5vh,16px);gap:clamp(7px,1.4vh,16px);overflow:auto}h1{font-size:clamp(22px,3.8vh,38px);margin:0;text-align:center}button{font:inherit;cursor:pointer;touch-action:manipulation}button:focus-visible{outline:2px solid #fff;outline-offset:3px}.modes{display:flex;gap:8px;width:min(100%,760px)}.mode,.reset{background:#121212;color:#fff;border:1px solid #46414f;border-radius:10px;padding:10px 18px;font-size:clamp(13px,2.4vh,22px);font-weight:700}.mode{flex:1}.mode[aria-pressed=true]{background:#c5a6ff;color:#201331;border-color:#c5a6ff}.status{display:flex;justify-content:center;align-items:center;gap:10px;font-size:clamp(17px,3.1vh,32px);min-height:1.3em;text-align:center}.x{color:#69bdff}.o{color:#ffb8da}.status.won{color:#7be4a7}.board{display:grid;grid-template-columns:repeat(3,1fr);grid-template-rows:repeat(3,1fr);gap:clamp(6px,1.1vh,12px);width:min(94vw,calc(100dvh - 190px),720px);aspect-ratio:1;flex:none;min-width:170px}.cell{display:grid;place-items:center;min-width:0;min-height:0;background:#101014;border:2px solid #494050;border-radius:clamp(7px,1.5vh,16px);padding:0}.cell:not(:disabled):hover{background:#211b30;border-color:#c5a6ff}.cell:disabled{cursor:default}.cell svg{width:72%;height:72%;fill:none;stroke:currentColor;stroke-width:11;stroke-linecap:round}.cell.win{border-color:#7be4a7;background:#143222;color:#7be4a7}.reset{background:#1b1723;color:#c5a6ff;border-color:#665487}.reset:hover{background:#322844}.legend{display:flex;gap:24px;justify-content:center;font-size:clamp(12px,1.8vh,18px);color:#c4c0cd}.legend b{font-size:1.2em}@media(min-height:850px){.board{width:min(94vw,calc(100dvh - 245px),760px)}}@media(max-height:420px) and (min-width:650px){#game{display:grid;grid-template-columns:1fr 1fr;grid-template-rows:auto auto 1fr auto;align-content:center;justify-items:center;min-height:280px}.board{grid-column:2;grid-row:1/5;width:min(46vw,calc(100dvh - 20px));min-width:150px}.modes{flex-direction:column}.status{grid-column:1}.legend{grid-column:1;display:none}}\n\n#game{display:flex;flex-direction:column;align-items:center}.playfield{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,4fr) minmax(0,1fr);align-items:center;justify-items:center;gap:clamp(4px,1.3vw,20px);width:min(100%,1500px);flex:1;min-height:120px;container-type:size}.side{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;text-align:center;padding:clamp(4px,1vw,16px);width:100%;border:2px solid #34313a;border-radius:12px;background:#101014;font-size:clamp(11px,1.7vw,23px);overflow-wrap:anywhere}.side b{font-size:clamp(26px,5vw,70px);line-height:1}.side.left.active{border-color:#69bdff}.side.right.active{border-color:#ffb8da}.reset,.reset:hover{background:#c5a6ff;color:#201331;border:2px solid #e1ccff;font-weight:800;font-size:clamp(16px,2.6vh,26px);min-height:42px;width:min(100%,360px);padding:8px 20px}.footer{justify-content:center}.board{grid-column:auto;grid-row:auto;width:min(64vw,100cqh,780px);min-width:0}.board-area{width:100%;height:100%;min-height:0;container-type:normal}.board-area .board{width:min(64vw,100cqh,780px)}@media(max-width:500px){.playfield{grid-template-columns:minmax(0,1fr) minmax(0,4fr) minmax(0,1fr);gap:3px}.side{padding:3px;border-radius:6px;gap:4px}.side b{font-size:24px}.side span{font-size:10px}.modes{flex-direction:row}}@media(max-height:420px) and (min-width:650px){.modes{flex-direction:row}#game{min-height:320px}.playfield{min-height:120px}.board{width:min(64vw,100cqh,780px)}}\n.reset,.reset:hover{background:#292929;color:#fff;border:1px solid #555;box-shadow:none}\n\n.head{display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:8px;width:min(100%,760px)}.head h1{grid-column:2}.info{grid-column:3;justify-self:end;border:1px solid #fff;background:#fff;color:#000;min-height:36px;padding:6px 15px;border-radius:8px;font-weight:800}.info:hover{background:#e5e5e5}dialog{background:#101015;border:1px solid #665487;border-radius:14px;color:#fff;width:min(90%,560px);padding:22px;line-height:1.5}dialog::backdrop{background:#000b}dialog h2{margin:0;color:#c5a6ff}dialog ol{padding-left:22px}dialog button{display:block;margin-left:auto;background:#292929;color:#fff;border:1px solid #555;border-radius:8px;padding:8px 16px}@media(max-width:500px){.head{grid-template-columns:1fr auto}.head h1{grid-column:1;text-align:left;font-size:clamp(18px,5vw,25px)}.info{grid-column:2;min-height:28px;padding:4px 10px;font-size:13px}}\n\n/* v41: wspólne położenie zasad w grach */\n#game{padding-top:10px;padding-left:12px;padding-right:12px}\n#game > .head,#game > header{display:grid;grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);align-items:center;gap:8px;position:relative;width:100%;max-width:none;align-self:stretch;flex:0 0 44px;min-height:44px;}\n#game > .head h1,#game > header h1{grid-column:2;grid-row:1;margin:0;text-align:center;font-size:clamp(20px,3.8vh,36px);line-height:1.15;}\n#game #info{position:static;grid-column:3;grid-row:1;justify-self:end;align-self:center;white-space:nowrap;min-height:36px;height:36px;padding:6px 15px;border:1px solid #fff;background:#fff;color:#000;font:800 16px/1 Arial,sans-serif;border-radius:8px;box-shadow:none;}\n#game #info:hover{background:#e5e5e5;color:#000;}\n@media(max-width:520px){#game > .head,#game > header{grid-template-columns:minmax(0,1fr) auto;}#game > .head h1,#game > header h1{grid-column:1;text-align:left;font-size:clamp(18px,4.7vw,25px);}#game #info{grid-column:2;}}\n</style></head><body><main id=\"game\"><header class=\"head\"><h1>Kółko i krzyżyk</h1><button type=\"button\" class=\"info\" id=\"info\" aria-label=\"Zasady gry\">Zasady</button></header><div class=\"modes\" role=\"group\" aria-label=\"Tryb gry\"><button class=\"mode\" data-mode=\"two\" aria-pressed=\"true\">2 graczy</button><button class=\"mode\" data-mode=\"cpu\" aria-pressed=\"false\">1 gracz</button></div><div class=\"status\" id=\"status\" aria-live=\"polite\"></div><div class=\"playfield\"><div class=\"side left\" id=\"leftPlayer\"></div><div class=\"board\" id=\"board\" aria-label=\"Plansza\"></div><div class=\"side right\" id=\"rightPlayer\"></div></div><button class=\"reset\" id=\"reset\">Nowa gra</button></main><dialog id=\"rules\" aria-labelledby=\"rulesTitle\"><h2 id=\"rulesTitle\">Zasady gry</h2><ol><li>Wybierz tryb: 1 gracz lub 2 graczy.</li><li>Grę rozpoczyna gracz X. Gracze na zmianę wpisują X lub O w wolne pola planszy 3 × 3.</li><li>Wygrywa ten, kto pierwszy ułoży trzy swoje znaki w jednym wierszu, w jednej kolumnie lub po przekątnej.</li><li>Jeżeli wszystkie pola są zajęte i nikt nie wygrał, następuje remis.</li><li>W trybie dla jednego gracza grasz znakiem X.</li></ol><button type=\"button\" id=\"dismiss\">Wróć do gry</button></dialog><script>\n(()=>{'use strict';const q=s=>document.querySelector(s),lines=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]];const fresh=()=>Array(9).fill('');let mode='two',games={two:fresh(),cpu:fresh()},timer=null,visible=true;const get=()=>games[mode];function win(b){return lines.find(l=>b[l[0]]&&l.every(i=>b[i]===b[l[0]]))||null}function turn(b){return b.filter(v=>v==='X').length===b.filter(v=>v==='O').length?'X':'O'}function ended(b){return !!win(b)||b.every(Boolean)}function valid(b){if(!Array.isArray(b)||b.length!==9||!b.every(v=>['','X','O'].includes(v)))return false;const x=b.filter(v=>v==='X').length,o=b.filter(v=>v==='O').length;if(x<o||x>o+1)return false;const wins=lines.filter(l=>b[l[0]]&&l.every(i=>b[i]===b[l[0]])).map(l=>b[l[0]]);return !(wins.includes('X')&&wins.includes('O'))&&(!wins.includes('X')||x===o+1)&&(!wins.includes('O')||x===o)}function state(){return {mode,games:{two:[...games.two],cpu:[...games.cpu]}}}function send(){if(parent!==window)parent.postMessage({type:'mw-v33-game-state',state:state()},'*')}function stop(){if(timer!==null)clearTimeout(timer);timer=null}function restore(s){stop();if(s&&['two','cpu'].includes(s.mode)&&valid(s.games?.two)&&valid(s.games?.cpu)){mode=s.mode;games={two:[...s.games.two],cpu:[...s.games.cpu]}}render();schedule()}const symbol={X:'<svg viewBox=\"0 0 100 100\" aria-hidden=\"true\"><path d=\"M22 22 78 78 M78 22 22 78\"/></svg>',O:'<svg viewBox=\"0 0 100 100\" aria-hidden=\"true\"><circle cx=\"50\" cy=\"50\" r=\"32\"/></svg>'};function render(){const b=get(),w=win(b),t=turn(b),cpu=mode==='cpu';document.querySelectorAll('.mode').forEach(el=>el.setAttribute('aria-pressed',String(el.dataset.mode===mode)));const s=q('#status');s.className='status'+(w?' won':'');s.textContent=w?(cpu?(b[w[0]]==='X'?'Wygrywasz':'Wygrywa przeciwnik'):'Wygrywa '+b[w[0]]):b.every(Boolean)?'Remis':cpu&&t==='O'?'Ruch przeciwnika…':'Ruch: '+t;s.classList.toggle(t==='X'?'x':'o',!ended(b));q('#leftPlayer').innerHTML='<b class=\"x\">X</b><span>'+(cpu?'Gracz':'Gracz 1')+'</span>';q('#rightPlayer').innerHTML='<b class=\"o\">O</b><span>'+(cpu?'Przeciwnik':'Gracz 2')+'</span>';q('#leftPlayer').classList.toggle('active',!ended(b)&&t==='X');q('#rightPlayer').classList.toggle('active',!ended(b)&&t==='O');for(let i=0;i<9;i++){const el=q('#board').children[i];el.className='cell '+(b[i]||'').toLowerCase()+(w?.includes(i)?' win':'');el.innerHTML=symbol[b[i]]||'';el.disabled=!!b[i]||ended(b)||(cpu&&t==='O');el.setAttribute('aria-label',`Wiersz ${Math.floor(i/3)+1}, kolumna ${i%3+1}: ${b[i]||'puste pole'}`)}}function minimax(b,player,depth){const w=win(b);if(w)return b[w[0]]==='O'?10-depth:depth-10;if(b.every(Boolean))return 0;let best=player==='O'?-Infinity:Infinity;for(let i=0;i<9;i++)if(!b[i]){b[i]=player;const score=minimax(b,player==='O'?'X':'O',depth+1);b[i]='';best=player==='O'?Math.max(best,score):Math.min(best,score)}return best}function computer(b){let best=-Infinity,choices=[];for(let i=0;i<9;i++)if(!b[i]){b[i]='O';const score=minimax(b,'X',1);b[i]='';if(score>best){best=score;choices=[i]}else if(score===best)choices.push(i)}return choices[Math.floor(Math.random()*choices.length)]}function schedule(){stop();const b=get();if(!visible||q('#rules').open||mode!=='cpu'||ended(b)||turn(b)!=='O')return;timer=setTimeout(()=>{timer=null;if(!visible||mode!=='cpu'||get()!==b||ended(b)||turn(b)!=='O')return;const i=computer(b);if(i!==undefined){b[i]='O';render();send()}},450)}for(let i=0;i<9;i++){const el=document.createElement('button');el.type='button';el.addEventListener('click',()=>{const b=get(),t=turn(b);if(b[i]||ended(b)||(mode==='cpu'&&t==='O'))return;b[i]=t;render();send();schedule()});q('#board').append(el)}document.querySelectorAll('.mode').forEach(el=>el.addEventListener('click',()=>{stop();mode=el.dataset.mode;render();send();schedule()}));q('#reset').addEventListener('click',()=>{stop();games[mode]=fresh();render();send()});\nq('#info').addEventListener('click',()=>{stop();q('#rules').showModal()});q('#dismiss').addEventListener('click',()=>q('#rules').close());q('#rules').addEventListener('close',schedule);\nfunction snapshot(){const b=get(),w=win(b),c=document.createElement('canvas');c.width=1440;c.height=900;const x=c.getContext('2d');x.fillStyle='#000';x.fillRect(0,0,1440,900);x.textAlign='center';x.fillStyle='#fff';x.font='bold 44px Arial';x.fillText('Kółko i krzyżyk',720,62);x.font='bold 26px Arial';x.fillStyle='#c5a6ff';x.fillText(mode==='cpu'?'1 gracz':'2 graczy',720,102);x.fillStyle='#fff';x.fillText(q('#status').textContent,720,146);const size=212,gap=10,startX=(1440-size*3-gap*2)/2,startY=174;for(let i=0;i<9;i++){const px=startX+i%3*(size+gap),py=startY+Math.floor(i/3)*(size+gap),won=w?.includes(i);x.beginPath();x.roundRect(px,py,size,size,15);x.fillStyle=won?'#143222':'#101014';x.fill();x.strokeStyle=won?'#7be4a7':'#494050';x.lineWidth=3;x.stroke();x.strokeStyle=won?'#7be4a7':b[i]==='X'?'#69bdff':'#ffb8da';x.lineWidth=17;x.lineCap='round';x.beginPath();if(b[i]==='X'){x.moveTo(px+55,py+55);x.lineTo(px+157,py+157);x.moveTo(px+157,py+55);x.lineTo(px+55,py+157)}else if(b[i]==='O')x.arc(px+106,py+106,62,0,Math.PI*2);x.stroke()}x.font='bold 30px Arial';x.fillStyle='#69bdff';x.fillText('X',175,420);x.font='bold 23px Arial';x.fillText(mode==='cpu'?'Gracz':'Gracz 1',175,460);x.font='bold 30px Arial';x.fillStyle='#ffb8da';x.fillText('O',1265,420);x.font='bold 23px Arial';x.fillText(mode==='cpu'?'Przeciwnik':'Gracz 2',1265,460);return c.toDataURL('image/png')}\nwindow.addEventListener('message',e=>{if(e.source!==parent)return;const m=e.data;if(m?.type==='mw-v21-div-restore')restore(m.state);if(m?.type==='mw-v33-game-visibility'){visible=!!m.visible;visible?schedule():stop()}if(m?.type==='mw-v21-div-export'){visible=false;restore(m.state);try{parent.postMessage({type:'mw-v21-div-image',id:m.id,png:snapshot()},'*')}catch(err){parent.postMessage({type:'mw-v21-div-image',id:m.id,error:String(err)},'*')}}});render();})();\n</script></body></html>\n"
},
{
"id": "dots",
"action": "mw-v34-dots",
"title": "Kropki",
"label": "Kropki",
"icon": "<span class=\"solid-icon\"><svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M5 5L12 12 19 5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.7\"/><circle cx=\"5\" cy=\"5\" r=\"1.8\"/><circle cx=\"5\" cy=\"12\" r=\"1.8\"/><circle cx=\"5\" cy=\"19\" r=\"1.8\"/><circle cx=\"12\" cy=\"5\" r=\"1.8\"/><circle cx=\"12\" cy=\"12\" r=\"1.8\"/><circle cx=\"12\" cy=\"19\" r=\"1.8\"/><circle cx=\"19\" cy=\"5\" r=\"1.8\"/><circle cx=\"19\" cy=\"12\" r=\"1.8\"/><circle cx=\"19\" cy=\"19\" r=\"1.8\"/></svg></span>",
"source": "<!doctype html><html lang=\"pl\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>\n*{box-sizing:border-box}html,body{margin:0;background:#000;color:#fff;font:600 16px Arial,sans-serif;color-scheme:dark}#game{height:100dvh;min-height:320px;display:flex;flex-direction:column;align-items:center;padding:clamp(8px,1.3vh,16px);gap:clamp(6px,1.1vh,12px);overflow:auto}h1{font-size:clamp(22px,3.8vh,38px);margin:0}button{font:inherit;cursor:pointer;touch-action:manipulation;color:#fff;background:#121212;border:1px solid #494050;border-radius:9px;padding:8px 14px}button:focus-visible{outline:2px solid #fff;outline-offset:2px}button[aria-pressed=true]{background:#c5a6ff;color:#201331;border-color:#c5a6ff}.head,.modes,.sizes,.footer{display:flex;align-items:center;justify-content:center;gap:8px;width:min(100%,760px)}.head{position:relative}.info{position:absolute;right:0;border:1px solid #fff;background:#fff;color:#000;min-height:36px;padding:6px 15px;border-radius:8px;font-weight:800}.modes button{flex:1;font-size:clamp(13px,2.4vh,22px)}.sizes{gap:5px}.sizes button{flex:1;padding:6px 2px;font-size:clamp(12px,2vh,18px);white-space:nowrap}.status{font-size:clamp(17px,2.8vh,30px);text-align:center;min-height:1.2em}.blue{color:#69bdff}.pink{color:#ffb8da}.won{color:#7be4a7}.board-area{flex:1;min-height:120px;width:100%;display:grid;place-items:center;container-type:size}.board{position:relative;width:min(92vw,calc(100dvh - 220px),760px);width:min(100cqw,100cqh,780px);aspect-ratio:1;background:#0b0b0d;border:1px solid #39343e;border-radius:14px;overflow:hidden}.board svg{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}.node{position:absolute;transform:translate(-50%,-50%);border:0;border-radius:50%;background:transparent;padding:0;display:grid;place-items:center}.node::after{content:'';display:block;width:clamp(7px,2.1cqw,14px);height:clamp(7px,2.1cqw,14px);border-radius:50%;background:#9e9e9e;box-shadow:none}.node.legal::after{background:#fff}.node.legal:hover::after{background:#c5a6ff}.node.used::after{background:var(--dot)}.node.end::after{background:#fff;border:2px solid var(--dot);width:clamp(11px,2.8cqw,19px);height:clamp(11px,2.8cqw,19px)}.node:disabled{cursor:default}.footer{justify-content:space-between;font-size:clamp(12px,1.8vh,18px);flex-wrap:wrap}.legend{display:flex;gap:14px}.legend b{font-size:1.2em}.reset{color:#c5a6ff;background:#1b1723;border-color:#665487}dialog{background:#101015;border:1px solid #665487;border-radius:14px;color:#fff;width:min(90%,560px);padding:22px;line-height:1.5}dialog::backdrop{background:#000b}dialog h2{margin:0;color:#c5a6ff}dialog ol{padding-left:22px}dialog button{display:block;margin-left:auto;color:#c5a6ff}@media(max-height:460px){#game{gap:5px}.board-area{min-height:100px}.head h1{font-size:20px}.info{min-height:28px;padding:4px 10px;font-size:13px}.modes button,.sizes button,.reset{padding:4px 8px}.status{font-size:16px}}\n\n#game{display:flex;flex-direction:column;align-items:center}.playfield{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,4fr) minmax(0,1fr);align-items:center;justify-items:center;gap:clamp(4px,1.3vw,20px);width:min(100%,1500px);flex:1;min-height:120px;container-type:size}.side{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;text-align:center;padding:clamp(4px,1vw,16px);width:100%;border:2px solid #34313a;border-radius:12px;background:#101014;font-size:clamp(11px,1.7vw,23px);overflow-wrap:anywhere}.side b{font-size:clamp(26px,5vw,70px);line-height:1}.side.left.active{border-color:#69bdff}.side.right.active{border-color:#ffb8da}.reset,.reset:hover{background:#c5a6ff;color:#201331;border:2px solid #e1ccff;font-weight:800;font-size:clamp(16px,2.6vh,26px);min-height:42px;width:min(100%,360px);padding:8px 20px}.footer{justify-content:center}.board{grid-column:auto;grid-row:auto;width:min(64vw,100cqh,780px);min-width:0}.board-area{width:100%;height:100%;min-height:0;container-type:normal}.board-area .board{width:min(64vw,100cqh,780px)}@media(max-width:500px){.playfield{grid-template-columns:minmax(0,1fr) minmax(0,4fr) minmax(0,1fr);gap:3px}.side{padding:3px;border-radius:6px;gap:4px}.side b{font-size:24px}.side span{font-size:10px}.modes{flex-direction:row}}@media(max-height:420px) and (min-width:650px){.modes{flex-direction:row}#game{min-height:320px}.playfield{min-height:120px}.board{width:min(64vw,100cqh,780px)}}\n.reset,.reset:hover{background:#292929;color:#fff;border:1px solid #555;box-shadow:none}\n\n/* v41: wspólne położenie zasad w grach */\n#game{padding-top:10px;padding-left:12px;padding-right:12px}\n#game > .head,#game > header{display:grid;grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);align-items:center;gap:8px;position:relative;width:100%;max-width:none;align-self:stretch;flex:0 0 44px;min-height:44px;}\n#game > .head h1,#game > header h1{grid-column:2;grid-row:1;margin:0;text-align:center;font-size:clamp(20px,3.8vh,36px);line-height:1.15;}\n#game #info{position:static;grid-column:3;grid-row:1;justify-self:end;align-self:center;white-space:nowrap;min-height:36px;height:36px;padding:6px 15px;border:1px solid #fff;background:#fff;color:#000;font:800 16px/1 Arial,sans-serif;border-radius:8px;box-shadow:none;}\n#game #info:hover{background:#e5e5e5;color:#000;}\n@media(max-width:520px){#game > .head,#game > header{grid-template-columns:minmax(0,1fr) auto;}#game > .head h1,#game > header h1{grid-column:1;text-align:left;font-size:clamp(18px,4.7vw,25px);}#game #info{grid-column:2;}}\n</style></head><body><main id=\"game\"><div class=\"head\"><h1>Kropki</h1><button class=\"info\" id=\"info\" aria-label=\"Zasady gry\">Zasady</button></div><div class=\"modes\" role=\"group\" aria-label=\"Tryb gry\"><button data-mode=\"two\">2 graczy</button><button data-mode=\"cpu\">1 gracz</button></div><div class=\"sizes\" id=\"sizes\" role=\"group\" aria-label=\"Rozmiar planszy\"></div><div class=\"status\" id=\"status\" aria-live=\"polite\"></div><div class=\"playfield\"><div class=\"side left\" id=\"leftPlayer\"></div><div class=\"board-area\"><div class=\"board\" id=\"board\" aria-label=\"Plansza kropek\"><svg id=\"lines\" viewBox=\"0 0 1000 1000\" aria-hidden=\"true\"></svg><div id=\"nodes\"></div></div></div><div class=\"side right\" id=\"rightPlayer\"></div></div><div class=\"footer\"><button class=\"reset\" id=\"reset\">Nowa gra</button></div></main><dialog id=\"rules\"><h2>Zasady gry</h2><ol><li>Wybierz tryb i rozmiar planszy.</li><li>Gracz 1 wybiera kropkę początkową, a następnie łączy ją z sąsiednią kropką.</li><li>Na zmianę przedłużajcie ścieżkę od jej końca: w pionie, poziomie lub po przekątnej.</li><li>Nie wolno wracać do użytej kropki ani przecinać istniejących linii.</li><li>Przegrywa gracz, który nie ma już ruchu.</li></ol><button id=\"dismiss\">Wróć do gry</button></dialog><script>\n(()=>{'use strict';const q=s=>document.querySelector(s),colors=['#69bdff','#ffb8da'],fresh=(size=5)=>({size,path:[]});let mode='two',games={two:fresh(),cpu:fresh()},timer=null,visible=true;const get=()=>games[mode];const xy=(i,n)=>[i%n,Math.floor(i/n)];const orient=(a,b,c)=>(b[0]-a[0])*(c[1]-a[1])-(b[1]-a[1])*(c[0]-a[0]);function crosses(a,b,c,d){return orient(a,b,c)*orient(a,b,d)<0&&orient(c,d,a)*orient(c,d,b)<0}function legal(path,n){if(!path.length)return Array.from({length:n*n},(_,i)=>i);const last=path.at(-1),a=xy(last,n),used=new Set(path),out=[];for(let dy=-1;dy<=1;dy++)for(let dx=-1;dx<=1;dx++){if(!dx&&!dy)continue;const x=a[0]+dx,y=a[1]+dy;if(x<0||y<0||x>=n||y>=n)continue;const j=y*n+x;if(used.has(j))continue;const b=[x,y];let hit=false;if(dx&&dy){for(let k=1;k<path.length-1;k++){if(crosses(a,b,xy(path[k-1],n),xy(path[k],n))){hit=true;break}}}if(!hit)out.push(j)}return out}const turn=p=>Math.max(0,p.length-1)%2;function valid(g){if(!g||!Number.isInteger(g.size)||g.size<3||g.size>9||!Array.isArray(g.path)||g.path.length>g.size*g.size)return false;const p=[];for(const i of g.path){if(!Number.isInteger(i)||!legal(p,g.size).includes(i))return false;p.push(i)}return true}function state(){return {mode,games:{two:{size:games.two.size,path:[...games.two.path]},cpu:{size:games.cpu.size,path:[...games.cpu.path]}}}}function send(){if(parent!==window)parent.postMessage({type:'mw-v34-dots-state',state:state()},'*')}function stop(){if(timer!==null)clearTimeout(timer);timer=null}function restore(s){stop();if(s&&['two','cpu'].includes(s.mode)&&valid(s.games?.two)&&valid(s.games?.cpu)){mode=s.mode;games={two:{size:s.games.two.size,path:[...s.games.two.path]},cpu:{size:s.games.cpu.size,path:[...s.games.cpu.path]}}}render();schedule()}const coord=(i,n)=>xy(i,n).map(v=>85+830*v/(n-1));function label(t){return mode==='cpu'?(t?'Przeciwnik':'Gracz'):'Gracz '+(t+1)}function statusText(){const {size:n,path:p}=get(),t=turn(p),over=p.length>1&&!legal(p,n).length;return over?(mode==='cpu'?(t?'Wygrywasz':'Wygrywa przeciwnik'):'Wygrywa '+label(1-t)):!p.length?'Wybierz kropkę początkową':p.length===1?(mode==='cpu'?'Połącz pierwsze kropki':'Gracz 1: połącz pierwsze kropki'):mode==='cpu'&&t?'Ruch przeciwnika…':'Ruch: '+label(t)}function render(){const {size:n,path:p}=get(),t=turn(p),moves=legal(p,n),allowed=new Set(moves),over=p.length>1&&!moves.length,blocked=mode==='cpu'&&t===1;document.querySelectorAll('[data-mode]').forEach(el=>el.setAttribute('aria-pressed',String(el.dataset.mode===mode)));document.querySelectorAll('[data-size]').forEach(el=>el.setAttribute('aria-pressed',String(+el.dataset.size===n)));q('#status').textContent=statusText();q('#status').className='status '+(over?'won':t?'pink':'blue');q('#leftPlayer').innerHTML='<b class=\"blue\">●</b><span>'+label(0)+'</span>';q('#rightPlayer').innerHTML='<b class=\"pink\">●</b><span>'+label(1)+'</span>';q('#leftPlayer').classList.toggle('active',!over&&t===0);q('#rightPlayer').classList.toggle('active',!over&&t===1);let lines='';for(let j=1;j<p.length;j++){const [x1,y1]=coord(p[j-1],n),[x2,y2]=coord(p[j],n);lines+=`<line x1=\"${x1}\" y1=\"${y1}\" x2=\"${x2}\" y2=\"${y2}\" stroke=\"${colors[(j-1)%2]}\" stroke-width=\"${Math.min(14,48/(n-1))}\" stroke-linecap=\"round\"/>`}q('#lines').innerHTML=lines;const nodes=q('#nodes');if(nodes.children.length!==n*n){nodes.replaceChildren();for(let i=0;i<n*n;i++){const el=document.createElement('button');el.type='button';el.className='node';el.dataset.index=i;const [x,y]=coord(i,n);el.style.left=x/10+'%';el.style.top=y/10+'%';el.style.width=el.style.height=Math.min(19,70/(n-1))+'%';el.addEventListener('click',()=>play(i));nodes.append(el)}}for(let i=0;i<n*n;i++){const el=nodes.children[i],at=p.indexOf(i),isEnd=at>=0&&at===p.length-1;el.className='node'+(at>=0?' used':'')+(isEnd?' end':'')+(!blocked&&allowed.has(i)?' legal':'');el.style.setProperty('--dot',colors[Math.max(0,at-1)%2]);el.disabled=blocked||!allowed.has(i);el.setAttribute('aria-label',`Wiersz ${Math.floor(i/n)+1}, kolumna ${i%n+1}${at>=0?', zajęta':''}`)}}function play(i){const {size:n,path:p}=get();if(mode==='cpu'&&turn(p)||!legal(p,n).includes(i))return;p.push(i);render();send();schedule()}\nfunction score(p,n,depth){const options=legal(p,n);if(!options.length)return -1000-depth;if(depth===0)return options.length;let best=-Infinity;for(const i of options){p.push(i);const s=-score(p,n,depth-1);p.pop();best=Math.max(best,s);if(best>=1000)break}return best}function computer(p,n){let best=-Infinity,choices=[];for(const i of legal(p,n)){p.push(i);const s=-score(p,n,n===3?Math.max(0,n*n-p.length):3);p.pop();if(s>best){best=s;choices=[i]}else if(s===best)choices.push(i)}return choices[Math.floor(Math.random()*choices.length)]}function schedule(){stop();const g=get();if(!visible||q('#rules').open||mode!=='cpu'||turn(g.path)!==1||!legal(g.path,g.size).length)return;timer=setTimeout(()=>{timer=null;if(!visible||mode!=='cpu'||get()!==g||q('#rules').open||turn(g.path)!==1)return;const i=computer(g.path,g.size);if(i!==undefined){g.path.push(i);render();send()}},550)}\nfor(let n=3;n<=9;n++){const el=document.createElement('button');el.type='button';el.dataset.size=n;el.textContent=n+'×'+n;el.addEventListener('click',()=>{if(get().size===n)return;stop();games[mode]=fresh(n);render();send()});q('#sizes').append(el)}document.querySelectorAll('[data-mode]').forEach(el=>el.addEventListener('click',()=>{stop();mode=el.dataset.mode;render();send();schedule()}));q('#reset').addEventListener('click',()=>{stop();games[mode]=fresh(get().size);render();send()});q('#info').addEventListener('click',()=>{stop();q('#rules').showModal()});q('#dismiss').addEventListener('click',()=>q('#rules').close());q('#rules').addEventListener('close',schedule);\nfunction snapshot(){const {size:n,path:p}=get(),c=document.createElement('canvas');c.width=1440;c.height=900;const x=c.getContext('2d');x.fillStyle='#000';x.fillRect(0,0,1440,900);x.textAlign='center';x.fillStyle='#fff';x.font='bold 44px Arial';x.fillText('Kropki',720,58);x.font='bold 26px Arial';x.fillStyle='#c5a6ff';x.fillText((mode==='cpu'?'1 gracz':'2 graczy')+' · '+n+'×'+n,720,100);x.fillStyle='#fff';x.fillText(statusText(),720,140);const side=690,offsetX=(1440-side)/2,offsetY=165,point=i=>coord(i,n).map((v,k)=>(k?offsetY:offsetX)+v*side/1000);x.fillStyle='#0b0b0d';x.fillRect(offsetX,offsetY,side,side);x.lineCap='round';for(let j=1;j<p.length;j++){const a=point(p[j-1]),b=point(p[j]);x.beginPath();x.moveTo(...a);x.lineTo(...b);x.strokeStyle=colors[(j-1)%2];x.lineWidth=Math.min(14,48/(n-1))*side/1000;x.stroke()}for(let i=0;i<n*n;i++){const at=p.indexOf(i);x.beginPath();x.arc(...point(i),7,0,Math.PI*2);x.fillStyle=at<0?(legal(p,n).includes(i)?'#fff':'#9e9e9e'):at===p.length-1?'#fff':colors[Math.max(0,at-1)%2];x.fill()}x.font='bold 30px Arial';x.fillStyle='#69bdff';x.fillText('●',175,420);x.font='bold 23px Arial';x.fillText(mode==='cpu'?'Gracz':'Gracz 1',175,460);x.font='bold 30px Arial';x.fillStyle='#ffb8da';x.fillText('●',1265,420);x.font='bold 23px Arial';x.fillText(mode==='cpu'?'Przeciwnik':'Gracz 2',1265,460);return c.toDataURL('image/png')}\nwindow.addEventListener('message',e=>{if(e.source!==parent)return;const m=e.data;if(m?.type==='mw-v21-div-restore')restore(m.state);if(m?.type==='mw-v33-game-visibility'){visible=!!m.visible;visible?schedule():stop()}if(m?.type==='mw-v21-div-export'){visible=false;restore(m.state);try{parent.postMessage({type:'mw-v21-div-image',id:m.id,png:snapshot()},'*')}catch(err){parent.postMessage({type:'mw-v21-div-image',id:m.id,error:String(err)},'*')}}});render();})();\n</script></body></html>\n"
},
{
"id": "ships",
"action": "mw-v36-ships",
"title": "Statki",
"label": "Statki",
"icon": "<span class=\"solid-icon\"><svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.7\" stroke-linejoin=\"round\"><path d=\"M3 13h18l-3 6H6zM8 13V8h8v5M12 8V4h5M3 22q3-2 6 0 3-2 6 0 3-2 6 0\"/></svg></span>",
"source": "<!doctype html><html lang=\"pl\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>\n*{box-sizing:border-box}html,body{margin:0;background:#000;color:#fff;color-scheme:dark;font:600 16px Arial,sans-serif}#game{height:100dvh;min-height:320px;display:flex;flex-direction:column;align-items:center;gap:clamp(5px,1.3vh,14px);padding:10px;overflow:auto}h1,h2,p{margin:0}h1{font-size:clamp(22px,3.8vh,38px)}button{font:inherit;cursor:pointer;touch-action:manipulation;color:#fff;background:#151515;border:1px solid #494050;border-radius:9px;padding:8px 14px}button:focus-visible{outline:2px solid #fff;outline-offset:2px}button[aria-pressed=true],.reset,.primary{background:#c5a6ff;color:#201331;border-color:#c5a6ff;font-weight:800}.reset{font-size:clamp(17px,2.7vh,25px);min-height:42px;width:min(100%,360px)}.head,.modes,.controls{display:flex;align-items:center;justify-content:center;gap:8px;width:min(100%,850px)}.head{position:relative}.rules{position:absolute;right:0;background:#fff;color:#000;font-weight:800}.modes button{flex:1;font-size:clamp(14px,2.4vh,22px)}#status{font-size:clamp(17px,2.8vh,28px);text-align:center;min-height:1.2em}.boards{flex:1;min-height:200px;width:100%;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:clamp(10px,2vw,30px);justify-items:center;align-items:center;container-type:size}.fleet{width:min(47cqw,calc(100cqh - 48px),590px);min-width:145px;display:flex;flex-direction:column;gap:5px;text-align:center}.fleet h2{font-size:clamp(15px,2.3vh,24px)}.fleet p{font-size:clamp(11px,1.8vh,18px);color:#c4c0cd}.grid{width:100%;aspect-ratio:1;display:grid;grid-template-columns:repeat(11,1fr);grid-template-rows:repeat(11,1fr);gap:2px}.axis{display:grid;place-items:center;color:#bbb;font-size:clamp(9px,1.7vh,17px)}.cell{min-width:0;min-height:0;padding:0;border:1px solid #39343e;border-radius:3px;background:#101722;font-size:clamp(10px,2.4vh,24px);display:grid;place-items:center}.fleet.active-player h2{text-decoration:underline;text-underline-offset:5px}.fleet.target-player .grid{outline:2px solid #c5a6ff;outline-offset:3px;border-radius:4px}.cell.hit{background:#742c40;border-color:#ff8ca8;color:#fff}.cell.sunk{background:#4b202c;border-color:#ffb8da;color:#ffb8da}.cell.miss{background:#24252c;color:#ccc}.cell:not(:disabled):hover{background:#302442;border-color:#c5a6ff}.cell:disabled{cursor:default}.blue{color:#69bdff}.pink{color:#ffb8da}.green{color:#7be4a7}.controls{flex-wrap:wrap}.cover{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px;text-align:center;width:100%;padding:20px}.cover h2{font-size:clamp(23px,4vw,48px)}.cover p{color:#ccc}.cover button{font-size:22px;padding:14px 30px}[hidden]{display:none!important}dialog{background:#101015;border:1px solid #665487;border-radius:14px;color:#fff;width:min(90%,560px);padding:22px;line-height:1.5}dialog::backdrop{background:#000b}dialog h2{color:#c5a6ff}dialog button{display:block;margin-left:auto} @media(max-width:520px){.boards{grid-template-columns:1fr;min-height:0;container-type:normal;flex:none}.fleet{width:min(94vw,400px)}#game{height:100dvh}.rules{position:static}.head{justify-content:space-between}.grid{gap:1px}} \n.reset,.reset:hover{background:#292929;color:#fff;border:1px solid #555;box-shadow:none}\n\n/* v41: wspólne położenie zasad w grach */\n#game{padding-top:10px;padding-left:12px;padding-right:12px}\n#game > .head,#game > header{display:grid;grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);align-items:center;gap:8px;position:relative;width:100%;max-width:none;align-self:stretch;flex:0 0 44px;min-height:44px;}\n#game > .head h1,#game > header h1{grid-column:2;grid-row:1;margin:0;text-align:center;font-size:clamp(20px,3.8vh,36px);line-height:1.15;}\n#game #info{position:static;grid-column:3;grid-row:1;justify-self:end;align-self:center;white-space:nowrap;min-height:36px;height:36px;padding:6px 15px;border:1px solid #fff;background:#fff;color:#000;font:800 16px/1 Arial,sans-serif;border-radius:8px;box-shadow:none;}\n#game #info:hover{background:#e5e5e5;color:#000;}\n@media(max-width:520px){#game > .head,#game > header{grid-template-columns:minmax(0,1fr) auto;}#game > .head h1,#game > header h1{grid-column:1;text-align:left;font-size:clamp(18px,4.7vw,25px);}#game #info{grid-column:2;}}\n</style></head><body><main id=\"game\"><div class=\"head\"><h1>Statki</h1><button id=\"info\" class=\"rules\">Zasady</button></div><div class=\"modes\"><button data-mode=\"two\">2 graczy</button><button data-mode=\"cpu\">1 gracz</button></div><div id=\"status\" aria-live=\"polite\"></div><section class=\"boards\" id=\"boards\"><article class=\"fleet\"><h2 id=\"ownTitle\"></h2><p id=\"ownCount\"></p><div class=\"grid\" id=\"own\"></div></article><article class=\"fleet\"><h2 id=\"targetTitle\"></h2><p id=\"targetCount\"></p><div class=\"grid\" id=\"target\"></div></article></section><button id=\"reset\" class=\"reset\">Nowa gra</button></main><dialog id=\"rules\"><h2>Zasady gry</h2><ol><li>Każdy gracz ma 10 statków: jeden czteromasztowiec, dwa trójmasztowce, trzy dwumasztowce i cztery jednomasztowce.</li><li>Obie floty są losowane automatycznie i pozostają ukryte. Statki nie stykają się, nawet narożnikami.</li><li>Kliknij pole na planszy przeciwnika. Dopiero strzał odsłania pole: krzyżyk oznacza trafienie, kropka — pudło.</li><li>Po każdym strzale kolejka przechodzi na drugiego gracza.</li><li>Wygrywa ten, kto pierwszy zatopi całą flotę przeciwnika.</li></ol><button id=\"dismiss\">Wróć do gry</button></dialog><script>\n(()=>{'use strict';const q=s=>document.querySelector(s),lengths=[4,3,3,2,2,2,1,1,1,1],range=()=>Array.from({length:100},(_,i)=>i),xy=i=>[i%10,Math.floor(i/10)],neighbors=i=>{const [x,y]=xy(i);return range().filter(j=>{const [a,b]=xy(j);return Math.abs(a-x)<=1&&Math.abs(b-y)<=1})};function fleet(){for(let attempt=0;attempt<100;attempt++){const ships=[],blocked=new Set();for(const len of lengths){const options=[];for(let i=0;i<100;i++)for(const d of [1,10]){const [x,y]=xy(i);if((d===1?x:y)+len>10)continue;const cells=Array.from({length:len},(_,k)=>i+k*d);if(cells.every(c=>!blocked.has(c)))options.push(cells)}if(!options.length)break;const ship=options[Math.floor(Math.random()*options.length)];ships.push(ship);ship.forEach(c=>neighbors(c).forEach(j=>blocked.add(j)))}if(ships.length===10)return ships}throw Error('Nie udało się rozmieścić floty')}\nconst fresh=()=>({fleets:[fleet(),fleet()],shots:[[],[]],turn:0,phase:'play',cover:false});let mode='two',games={two:fresh(),cpu:fresh()},visible=true,timer=null;const get=()=>games[mode],enemy=g=>1-g.turn,at=(g,p,i)=>g.fleets[p].find(s=>s.includes(i)),hit=(g,p,i)=>g.shots[1-p].includes(i),sunk=(g,p,s)=>s.every(i=>hit(g,p,i)),remaining=(g,p)=>g.fleets[p].filter(s=>!sunk(g,p,s)).length;const label=p=>mode==='cpu'?(p?'Przeciwnik':'Gracz'):'Gracz '+(p+1);function stop(){if(timer!==null)clearTimeout(timer);timer=null}function send(){if(parent!==window)parent.postMessage({type:'mw-v36-ships-state',state:{mode,games}},'*')}\nfunction valid(g){if(!g||!['setup','play','end'].includes(g.phase)||![0,1].includes(g.turn)||typeof g.cover!=='boolean'||!Array.isArray(g.fleets)||g.fleets.length!==2||!Array.isArray(g.shots)||g.shots.length!==2)return false;return g.fleets.every(f=>Array.isArray(f)&&f.length===10&&f.every((s,k)=>Array.isArray(s)&&s.length===lengths[k]&&s.every(i=>Number.isInteger(i)&&i>=0&&i<100))&&new Set(f.flat()).size===20)&&g.shots.every(s=>Array.isArray(s)&&s.length<=100&&new Set(s).size===s.length&&s.every(i=>Number.isInteger(i)&&i>=0&&i<100))}function restore(s){stop();if(s&&['two','cpu'].includes(s.mode)&&valid(s.games?.two)&&valid(s.games?.cpu)){mode=s.mode;games=JSON.parse(JSON.stringify(s.games));for(const g of Object.values(games)){if(g.phase==='setup'){g.phase='play';g.turn=0;}g.cover=false;}}render();schedule()}\nfunction drawGrid(id,g,p){const grid=q(id);grid.replaceChildren();const canFire=p===enemy(g)&&g.phase==='play'&&!(mode==='cpu'&&g.turn===1);for(let y=-1;y<10;y++)for(let x=-1;x<10;x++){if(x===-1||y===-1){const el=document.createElement('span');el.className='axis';el.textContent=x===-1?(y===-1?'':y+1):String.fromCharCode(65+x);grid.append(el);continue}const i=y*10+x,shot=hit(g,p,i),s=shot?at(g,p,i):null,el=document.createElement('button');el.className='cell'+(shot?(s?(sunk(g,p,s)?' sunk':' hit'):' miss'):'');el.textContent=shot?(s?'×':'•'):'';el.disabled=!canFire||shot;el.setAttribute('aria-label',`${String.fromCharCode(65+x)}${y+1}${shot?(s?', trafiony':', pudło'):''}`);if(canFire&&!shot)el.addEventListener('click',()=>fire(i));grid.append(el)}}\nfunction statusText(){const g=get();if(g.phase==='end')return 'Wygrywa '+label(g.turn);return 'Ruch: '+label(g.turn)}\nfunction render(){const g=get();document.querySelectorAll('[data-mode]').forEach(e=>e.setAttribute('aria-pressed',String(e.dataset.mode===mode)));q('#status').textContent=statusText();q('#status').className=g.phase==='end'?'green':g.turn?'pink':'blue';for(const [p,id] of [[0,'own'],[1,'target']]){const title=q('#'+id+'Title'),count=q('#'+id+'Count');title.textContent=label(p);title.className=p?'pink':'blue';const active=g.phase==='play'&&g.turn===p;title.closest('.fleet').classList.toggle('active-player',active);title.closest('.fleet').classList.toggle('target-player',g.phase==='play'&&g.turn!==p&&!(mode==='cpu'&&g.turn===1));count.textContent='Statki: '+remaining(g,p)+' / 10';drawGrid('#'+id,g,p)}}\nfunction fire(i,cpu=false){const g=get();if(g.phase!=='play'||g.cover||(mode==='cpu'&&g.turn===1&&!cpu)||g.shots[g.turn].includes(i))return;g.shots[g.turn].push(i);if(!remaining(g,enemy(g)))g.phase='end';else{g.turn=enemy(g);g.cover=false}render();send();schedule()}\nfunction choose(g){const shots=g.shots[1],available=range().filter(i=>!shots.includes(i));const active=shots.filter(i=>{const s=at(g,0,i);return s&&!sunk(g,0,s)});let options=[];for(const i of active){const [x,y]=xy(i);options.push(...available.filter(j=>{const [a,b]=xy(j);return Math.abs(x-a)+Math.abs(y-b)===1}))}if(!options.length){const excluded=new Set();for(const s of g.fleets[0])if(sunk(g,0,s))s.forEach(i=>neighbors(i).forEach(j=>excluded.add(j)));options=available.filter(i=>!excluded.has(i));if(!options.length)options=available}return options[Math.floor(Math.random()*options.length)]}function schedule(){stop();const g=get();if(!visible||mode!=='cpu'||g.phase!=='play'||g.turn!==1||q('#rules').open)return;timer=setTimeout(()=>{timer=null;if(visible&&mode==='cpu'&&get()===g&&g.turn===1&&!q('#rules').open)fire(choose(g),true)},650)}\nq('#reset').onclick=()=>{stop();games[mode]=fresh();render();send()};document.querySelectorAll('[data-mode]').forEach(e=>e.onclick=()=>{stop();mode=e.dataset.mode;render();send();schedule()});q('#info').onclick=()=>{stop();q('#rules').showModal()};q('#dismiss').onclick=()=>q('#rules').close();q('#rules').addEventListener('close',schedule);\nfunction snapshot(){const g=get(),c=document.createElement('canvas');c.width=1440;c.height=900;const x=c.getContext('2d');x.fillStyle='#000';x.fillRect(0,0,1440,900);x.textAlign='center';x.fillStyle='#fff';x.font='bold 44px Arial';x.fillText('Statki',720,60);x.font='bold 26px Arial';x.fillText(statusText(),720,108);{for(let k=0;k<2;k++){const pl=k,left=100+k*710,top=195,step=48;x.fillStyle=pl?'#ffb8da':'#69bdff';x.fillText(label(pl),left+264,155);for(let i=0;i<100;i++){const s=at(g,pl,i),shot=hit(g,pl,i),xx=left+(i%10+1)*step,yy=top+Math.floor(i/10)*step;x.fillStyle=shot?(s?'#742c40':'#24252c'):'#101722';x.fillRect(xx,yy,step-2,step-2);if(shot){x.fillStyle='#fff';x.fillText(s?'×':'•',xx+step/2,yy+33)}}x.fillStyle='#bbb';x.font='18px Arial';for(let i=0;i<10;i++){x.fillText(String.fromCharCode(65+i),left+(i+1.5)*step,top-12);x.fillText(i+1,left+step/2,top+i*step+30)}x.font='bold 26px Arial'}}return c.toDataURL('image/png')}\nwindow.addEventListener('message',e=>{if(e.source!==parent)return;const m=e.data;if(m?.type==='mw-v21-div-restore')restore(m.state);if(m?.type==='mw-v33-game-visibility'){visible=!!m.visible;visible?schedule():stop()}if(m?.type==='mw-v21-div-export'){visible=false;restore(m.state);try{parent.postMessage({type:'mw-v21-div-image',id:m.id,png:snapshot()},'*')}catch(err){parent.postMessage({type:'mw-v21-div-image',id:m.id,error:String(err)},'*')}}});render();})();\n</script></body></html>\n"
},
{
"id": "tetrimino",
"action": "mw-v38-tetrimino",
"title": "Tetris",
"label": "Tetris",
"icon": "<span class=\"solid-icon\"><svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.6\"><rect x=\"3\" y=\"4\" width=\"6\" height=\"6\"/><rect x=\"9\" y=\"4\" width=\"6\" height=\"6\"/><rect x=\"9\" y=\"10\" width=\"6\" height=\"6\"/><rect x=\"15\" y=\"10\" width=\"6\" height=\"6\"/></svg></span>",
"source": "<!doctype html><html lang=\"pl\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>\n*{box-sizing:border-box}html,body{margin:0;background:#000;color:#fff;color-scheme:dark;font:600 16px Arial,sans-serif}#game{height:100dvh;min-height:320px;display:flex;flex-direction:column;align-items:center;gap:8px;padding:10px;overflow:auto}h1,h2,p{margin:0}h1{font-size:clamp(22px,3.8vh,38px)}button{font:inherit;cursor:pointer;touch-action:manipulation;color:#fff;background:#292929;border:1px solid #555;border-radius:9px;padding:9px 16px}button:hover{background:#363636}button:focus-visible{outline:2px solid #fff;outline-offset:2px}button:disabled{opacity:.42;cursor:default}.head{display:flex;align-items:center;justify-content:center;position:relative;width:min(100%,1000px)}.rules{position:absolute;right:0;background:#fff;color:#000;font-weight:800}.rules:hover{background:#ddd}.stage{flex:1;min-height:220px;width:min(100%,1200px);display:grid;grid-template-columns:minmax(0,1fr) minmax(0,2fr) minmax(0,1fr);align-items:center;gap:clamp(6px,1.8vw,25px);container-type:size}.boardwrap{height:100%;display:flex;justify-content:center;align-items:center;position:relative;min-width:0}.board{width:min(100%,calc(100cqh / 2),420px);aspect-ratio:1/2;display:block;border:1px solid #51515c;background:#0b0b0e}.overlay{position:absolute;inset:0;display:grid;place-items:center;pointer-events:none}.overlay span{background:#000e;border:1px solid #666;padding:12px 20px;border-radius:9px;text-align:center;font-size:clamp(16px,2.5vw,30px)}.side{display:flex;flex-direction:column;gap:10px;text-align:center}.stat{background:#111115;border:1px solid #39343e;border-radius:10px;padding:clamp(7px,1.2vw,16px)}.stat small{color:#bbb;display:block;font-size:clamp(11px,1.4vw,18px)}.stat strong{font-size:clamp(20px,3vw,42px);color:#c5a6ff;overflow-wrap:anywhere}.preview{display:block;width:min(100%,150px);aspect-ratio:1;margin:auto}.controls{display:flex;justify-content:center;gap:6px;flex-wrap:wrap;width:100%}.controls button{min-width:52px;font-size:clamp(17px,2.6vh,27px);min-height:45px;padding:6px 12px}.actions{display:flex;gap:8px;justify-content:center;width:min(100%,700px)}.actions button{flex:1;font-size:clamp(16px,2.5vh,23px);font-weight:800;min-height:42px}.play{background:#c5a6ff;border-color:#c5a6ff;color:#201331}.play:hover{background:#dac7ff}.reset,.reset:hover{background:#292929;color:#fff;border:1px solid #555;box-shadow:none}.hint{color:#aaa;font-size:clamp(11px,1.6vh,15px);text-align:center}dialog{background:#101015;border:1px solid #666;border-radius:12px;color:#fff;width:min(90%,560px);padding:22px;line-height:1.55}dialog::backdrop{background:#000c}dialog h2{color:#c5a6ff}dialog button{display:block;margin-left:auto}[hidden]{display:none!important}@media(max-width:550px){.stage{grid-template-columns:minmax(0,1fr) minmax(0,2fr) minmax(0,1fr);gap:4px}.stat{padding:5px}.side{gap:5px}.rules{position:static}.head{justify-content:space-between}.controls button{min-width:38px;padding:5px 8px;font-size:18px}.hint{display:none}}\n\n/* v41: wspólne położenie zasad w grach */\n#game{padding-top:10px;padding-left:12px;padding-right:12px}\n#game > .head,#game > header{display:grid;grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);align-items:center;gap:8px;position:relative;width:100%;max-width:none;align-self:stretch;flex:0 0 44px;min-height:44px;}\n#game > .head h1,#game > header h1{grid-column:2;grid-row:1;margin:0;text-align:center;font-size:clamp(20px,3.8vh,36px);line-height:1.15;}\n#game #info{position:static;grid-column:3;grid-row:1;justify-self:end;align-self:center;white-space:nowrap;min-height:36px;height:36px;padding:6px 15px;border:1px solid #fff;background:#fff;color:#000;font:800 16px/1 Arial,sans-serif;border-radius:8px;box-shadow:none;}\n#game #info:hover{background:#e5e5e5;color:#000;}\n@media(max-width:520px){#game > .head,#game > header{grid-template-columns:minmax(0,1fr) auto;}#game > .head h1,#game > header h1{grid-column:1;text-align:left;font-size:clamp(18px,4.7vw,25px);}#game #info{grid-column:2;}}\n\n/* v41: neutralny przycisk sterowania grą */\n#game #play,#game #play:hover,#game #play:active{background:#292929;color:#fff;border:1px solid #555;box-shadow:none;}\n</style></head><body><main id=\"game\"><header class=\"head\"><h1>Tetris</h1><button class=\"rules\" id=\"info\">Zasady</button></header><section class=\"stage\"><aside class=\"side\"><div class=\"stat\"><small>Punkty</small><strong id=\"score\">0</strong></div><div class=\"stat\"><small>Linie</small><strong id=\"lines\">0</strong></div><div class=\"stat\"><small>Poziom</small><strong id=\"level\">1</strong></div></aside><div class=\"boardwrap\"><canvas id=\"board\" class=\"board\" aria-label=\"Plansza Tetris 10 na 20\"></canvas><div class=\"overlay\" id=\"overlay\"><span>Rozpocznij grę</span></div></div><aside class=\"side\"><div class=\"stat\"><small>Następny klocek</small><canvas class=\"preview\" id=\"preview\"></canvas></div><div class=\"stat\"><small>Tryb</small><strong style=\"font-size:clamp(12px,1.9vw,24px);color:white\">1 gracz</strong></div></aside></section><div class=\"controls\"><button data-move=\"left\" aria-label=\"W lewo\">←</button><button data-move=\"rotate\" aria-label=\"Obróć\">↻</button><button data-move=\"right\" aria-label=\"W prawo\">→</button><button data-move=\"down\" aria-label=\"W dół\">↓</button><button data-move=\"drop\" aria-label=\"Natychmiast opuść\">⇊</button></div><div class=\"actions\"><button class=\"play\" id=\"play\">Rozpocznij</button><button class=\"reset\" id=\"reset\">Nowa gra</button></div><p class=\"hint\">← → przesuwanie · ↑ obrót · ↓ opuszczanie · Spacja – zrzut · P – pauza</p></main><dialog id=\"rules\"><h2>Zasady</h2><ol><li>Przesuwaj i obracaj spadające klocki. W grze występuje siedem jednostronnych tetromin: I, O, T, J, L, S i Z.</li><li>Wypełnij cały poziomy rząd, aby go usunąć i zdobyć punkty.</li><li>Co 10 usuniętych linii rośnie poziom i szybkość.</li><li>Gra kończy się, gdy kolejny klocek nie mieści się na planszy.</li></ol><button id=\"dismiss\">Wróć</button></dialog><script>\n(()=>{'use strict';const q=s=>document.querySelector(s),W=10,H=20,colors=['','#59c9ee','#f5d65f','#b18af4','#79d99a','#f18198','#6c93ef','#f3ac6e'],shapes=[null,[[0,0],[1,0],[2,0],[3,0]],[[0,0],[1,0],[0,1],[1,1]],[[0,0],[1,0],[2,0],[1,1]],[[1,0],[2,0],[0,1],[1,1]],[[0,0],[1,0],[1,1],[2,1]],[[0,0],[0,1],[1,1],[2,1]],[[2,0],[0,1],[1,1],[2,1]]];let g,active=false,visible=true,timer=0,started=false;\nconst blank=()=>Array.from({length:H},()=>Array(W).fill(0));function bag(){const a=[1,2,3,4,5,6,7];for(let i=6;i>0;i--){const j=Math.floor(Math.random()*(i+1));[a[i],a[j]]=[a[j],a[i]]}return a}function take(){if(!g.bag.length)g.bag=bag();return g.bag.pop()}\nfunction spawn(){const t=g.next;g.next=take();g.p={t,x:3,y:0,r:0};if(!fits(g.p))g.over=true}function reset(){stop();g={board:blank(),bag:bag(),next:1,p:null,score:0,lines:0,over:false,started:false};g.next=take();spawn();started=false;render();send()}\nfunction points(p){let a=shapes[p.t].map(v=>v.slice());if(p.t===2)return a;let k=p.t===1?3:2;for(let i=0;i<p.r;i++)a=a.map(([x,y])=>[k-y,x]);return a}function fits(p){return points(p).every(([x,y])=>{x+=p.x;y+=p.y;return x>=0&&x<W&&y>=0&&y<H&&!g.board[y][x]})}function move(dx,dy){const p={...g.p,x:g.p.x+dx,y:g.p.y+dy};if(!fits(p))return false;g.p=p;return true}function rotate(){for(const [dx,dy] of [[0,0],[-1,0],[1,0],[-2,0],[2,0],[0,-1],[0,-2]]){const p={...g.p,r:(g.p.r+1)%4,x:g.p.x+dx,y:g.p.y+dy};if(fits(p)){g.p=p;return}}}\nfunction level(){return 1+Math.floor(g.lines/10)}function lock(){for(const [x,y] of points(g.p))g.board[y+g.p.y][x+g.p.x]=g.p.t;let keep=g.board.filter(row=>!row.every(Boolean)),n=H-keep.length;if(n){g.score+=[0,100,300,500,800][n]*level();g.lines+=n;while(keep.length<H)keep.unshift(Array(W).fill(0));g.board=keep}spawn();if(g.over)stop()}\nfunction stop(){active=false;clearTimeout(timer);timer=0}function schedule(){clearTimeout(timer);if(active&&visible&&!g.over)timer=setTimeout(()=>{if(!move(0,1))lock();render();send();schedule()},Math.max(100,850*Math.pow(.82,level()-1)))}function toggle(){if(g.over)return;if(active){stop()}else if(visible){active=true;started=true;g.started=true;schedule()}render();send()}\nfunction action(a){if(!active||!visible||g.over)return;if(a==='left')move(-1,0);if(a==='right')move(1,0);if(a==='rotate')rotate();if(a==='down'){if(move(0,1))g.score++;else lock()}if(a==='drop'){let d=0;while(move(0,1))d++;g.score+=2*d;lock();schedule()}render();send()}\nfunction paint(c,rows,cols,fn){const x=c.getContext('2d'),w=c.width/cols,h=c.height/rows;x.fillStyle='#0b0b0e';x.fillRect(0,0,c.width,c.height);function cell(cx,cy,t,ghost=false){const X=cx*w,Y=cy*h;if(ghost){x.strokeStyle='#85858f';x.lineWidth=Math.max(1,w*.045);x.strokeRect(X+w*.15,Y+h*.15,w*.7,h*.7);return}x.fillStyle=colors[t];x.fillRect(X+1,Y+1,w-2,h-2);x.fillStyle='#ffffff28';x.fillRect(X+2,Y+2,w-4,Math.max(1,h*.08))}x.strokeStyle='#232329';x.lineWidth=1;for(let i=0;i<=cols;i++){x.beginPath();x.moveTo(i*w,0);x.lineTo(i*w,c.height);x.stroke()}for(let i=0;i<=rows;i++){x.beginPath();x.moveTo(0,i*h);x.lineTo(c.width,i*h);x.stroke()}fn(cell)}function board(c){paint(c,H,W,cell=>{g.board.forEach((row,y)=>row.forEach((t,x)=>{if(t)cell(x,y,t)}));if(!g.over){let p={...g.p};while(fits({...p,y:p.y+1}))p.y++;for(const [x,y] of points(p))cell(x+p.x,y+p.y,p.t,true);for(const [x,y] of points(g.p))cell(x+g.p.x,y+g.p.y,g.p.t)}})}function preview(c){paint(c,4,4,cell=>{for(const [x,y] of shapes[g.next])cell(x,y+1,g.next)})}function size(c,cols,rows){const d=Math.min(3,window.devicePixelRatio||1),w=Math.max(cols,Math.round(c.getBoundingClientRect().width*d));c.width=w;c.height=Math.round(w*rows/cols)}function render(){const c=q('#board'),p=q('#preview');size(c,W,H);size(p,4,4);board(c);preview(p);q('#score').textContent=g.score;q('#lines').textContent=g.lines;q('#level').textContent=level();q('#overlay').hidden=active&&!g.over;q('#overlay span').textContent=g.over?'Koniec gry':started?'Pauza':'Rozpocznij grę';q('#play').textContent=active?'Pauza':started?'Wznów':'Rozpocznij';q('#play').disabled=g.over;document.querySelectorAll('[data-move]').forEach(b=>b.disabled=!active||g.over)}\nfunction send(){if(parent!==window)parent.postMessage({type:'mw-v38-tetrimino-state',state:g},'*')}function valid(s){return s&&Array.isArray(s.board)&&s.board.length===H&&s.board.every(r=>Array.isArray(r)&&r.length===W&&r.every(t=>Number.isInteger(t)&&t>=0&&t<=7))&&Array.isArray(s.bag)&&s.bag.length<=7&&s.bag.every(t=>Number.isInteger(t)&&t>=1&&t<=7)&&Number.isInteger(s.next)&&s.next>=1&&s.next<=7&&s.p&&Number.isInteger(s.p.t)&&s.p.t>=1&&s.p.t<=7&&Number.isInteger(s.p.r)&&s.p.r>=0&&s.p.r<=3&&Number.isInteger(s.p.x)&&s.p.x>=-3&&s.p.x<=9&&Number.isInteger(s.p.y)&&s.p.y>=0&&s.p.y<20&&Number.isSafeInteger(s.score)&&s.score>=0&&Number.isSafeInteger(s.lines)&&s.lines>=0&&typeof s.over==='boolean'&&typeof s.started==='boolean'}function restore(s){stop();if(valid(s)){g=JSON.parse(JSON.stringify(s));started=g.started}else if(!g){reset()}render()}\nfunction snapshot(){const c=document.createElement('canvas');c.width=1440;c.height=900;const x=c.getContext('2d');x.fillStyle='#000';x.fillRect(0,0,1440,900);x.textAlign='center';x.fillStyle='#fff';x.font='bold 44px Arial';x.fillText('Tetris',720,55);const b=document.createElement('canvas');b.width=390;b.height=780;board(b);x.drawImage(b,525,90);const p=document.createElement('canvas');p.width=p.height=160;preview(p);x.drawImage(p,1040,230);x.font='bold 25px Arial';x.fillText('Następny klocek',1120,200);for(const [i,t] of ['Punkty: '+g.score,'Linie: '+g.lines,'Poziom: '+level()].entries())x.fillText(t,275,250+i*95);if(g.over)x.fillText('Koniec gry',1120,500);return c.toDataURL('image/png')}\nq('#play').onclick=toggle;q('#reset').onclick=reset;q('#info').onclick=()=>{stop();render();send();q('#rules').showModal()};q('#dismiss').onclick=()=>q('#rules').close();document.querySelectorAll('[data-move]').forEach(b=>b.onclick=()=>action(b.dataset.move));window.addEventListener('keydown',e=>{if(q('#rules').open)return;const a={ArrowLeft:'left',ArrowRight:'right',ArrowUp:'rotate',ArrowDown:'down',' ':'drop'}[e.key];if(a||e.key.toLowerCase()==='p'){e.preventDefault();if(e.key.toLowerCase()==='p'){if(!e.repeat)toggle()}else action(a)}});window.addEventListener('blur',()=>{if(active){stop();render();send()}});window.addEventListener('resize',()=>render());window.addEventListener('message',e=>{if(e.source!==parent)return;const m=e.data;if(m?.type==='mw-v21-div-restore')restore(m.state);if(m?.type==='mw-v33-game-visibility'){visible=!!m.visible;if(!visible){stop();send()}render()}if(m?.type==='mw-v21-div-export'){visible=false;restore(m.state);try{parent.postMessage({type:'mw-v21-div-image',id:m.id,png:snapshot()},'*')}catch(err){parent.postMessage({type:'mw-v21-div-image',id:m.id,error:String(err)},'*')}}});reset();})();\n</script></body></html>\n"
},
{
"id": "tetromino",
"action": "mw-v40-tetromino",
"title": "Tetromino – układanie prostokątów",
"label": "Tetromino",
"icon": "<span class=\"solid-icon\"><svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"><rect x=\"2\" y=\"4\" width=\"20\" height=\"16\" rx=\"1\"/><path d=\"M2 12h10V4m0 8h5v8M7 12v8m10-16v8h5\"/></svg></span>",
"source": "<!doctype html><html lang=\"pl\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>\n*{box-sizing:border-box}html,body{margin:0;background:#000;color:white;font:600 16px Arial,sans-serif;color-scheme:dark}main{min-height:100dvh;height:100dvh;display:flex;flex-direction:column;gap:10px;padding:12px;overflow:auto}h1,h2,p{margin:0}h1{font-size:clamp(23px,3vw,40px)}header{display:flex;align-items:center;justify-content:space-between}button{font:inherit;color:white;background:#292929;border:1px solid #555;border-radius:8px;padding:9px 14px;cursor:pointer;touch-action:manipulation}button:hover{background:#383838}button:focus-visible{outline:2px solid white;outline-offset:2px}button:disabled{opacity:.35;cursor:default}.rules{background:white;color:black}.rules:hover{background:#ddd}.tabs,.tools{display:flex;gap:7px;flex-wrap:wrap;justify-content:center}.tabs button[aria-pressed=true]{background:#c5a6ff;color:#201331;border-color:#c5a6ff}.stage{flex:1;min-height:250px;display:grid;grid-template-columns:minmax(0,2fr) minmax(210px,1fr);gap:12px}.boardcard,.pieces{background:#0b0b0e;border:1px solid #39343e;border-radius:12px;padding:10px;display:flex;flex-direction:column;gap:10px;min-width:0;min-height:0}.boardarea{flex:1;min-height:120px;display:flex;align-items:center;justify-content:center;container-type:size}.board{display:grid;gap:1px;background:#48434d;border:1px solid #666;width:min(100%,calc(100cqh * var(--ratio)));aspect-ratio:var(--ratio);touch-action:manipulation}.cell{border:0;border-radius:0;padding:0;min-width:0;min-height:0;background:#151519;position:relative}.cell:hover{background:#393442}.cell.filled{background:var(--c)}.cell.ghost{background:var(--c);opacity:.5}.cell.bad{background:#783844}.pieces h2{font-size:clamp(17px,2vw,25px);text-align:center}.tray{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:5px;flex:1;align-content:center;overflow:auto}.piece{display:flex;align-items:center;justify-content:center;gap:5px;min-height:42px;padding:4px;background:#151519}.piece[aria-pressed=true]{border:2px solid #c5a6ff;background:#272032}.piece svg{width:min(90%,92px);height:clamp(24px,5vh,48px);display:block}.piece.used{opacity:.25}.info{color:#c5a6ff;text-align:center;font-size:clamp(14px,1.8vw,22px)}.status{min-height:25px;text-align:center;color:#fff}.success{color:#7be4a7}.muted{color:#bcbac4;text-align:center;font-size:clamp(12px,1.5vw,17px)}.tools button{flex:1}.footer{display:flex;gap:8px;justify-content:center;flex-wrap:wrap}.footer button{min-width:120px}dialog{background:#101015;border:1px solid #666;border-radius:12px;color:#fff;width:min(90%,660px);padding:22px;line-height:1.55}dialog::backdrop{background:#000c}dialog h2{color:#c5a6ff}dialog button{display:block;margin-left:auto}@media(max-width:650px){main{height:auto;min-height:100dvh}.stage{grid-template-columns:1fr}.boardarea{height:45vh;flex:none}.tray{grid-template-columns:repeat(4,minmax(0,1fr))}.piece svg{height:28px}.tabs button{padding:7px 10px}.pieces{overflow:visible}}\n\n/* v41: wspólne położenie zasad w grach */\n#game{padding-top:10px;padding-left:12px;padding-right:12px}\n#game > .head,#game > header{display:grid;grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);align-items:center;gap:8px;position:relative;width:100%;max-width:none;align-self:stretch;flex:0 0 44px;min-height:44px;}\n#game > .head h1,#game > header h1{grid-column:2;grid-row:1;margin:0;text-align:center;font-size:clamp(20px,3.8vh,36px);line-height:1.15;}\n#game #info{position:static;grid-column:3;grid-row:1;justify-self:end;align-self:center;white-space:nowrap;min-height:36px;height:36px;padding:6px 15px;border:1px solid #fff;background:#fff;color:#000;font:800 16px/1 Arial,sans-serif;border-radius:8px;box-shadow:none;}\n#game #info:hover{background:#e5e5e5;color:#000;}\n@media(max-width:520px){#game > .head,#game > header{grid-template-columns:minmax(0,1fr) auto;}#game > .head h1,#game > header h1{grid-column:1;text-align:left;font-size:clamp(18px,4.7vw,25px);}#game #info{grid-column:2;}}\n</style></head><body><main id=\"game\"><header><h1>Tetromino</h1><button id=\"info\" class=\"rules\">Zasady</button></header><nav class=\"tabs\" id=\"tabs\"></nav><p class=\"info\" id=\"description\"></p><section class=\"stage\"><article class=\"boardcard\"><div class=\"boardarea\"><div id=\"board\" class=\"board\" aria-label=\"Plansza łamigłówki\"></div></div><p class=\"status\" id=\"status\" role=\"status\"></p><p class=\"muted\">Wybierz figurę, a następnie pole odpowiadające jej lewemu górnemu narożnikowi. Kliknij ułożoną figurę, aby ją wyjąć.</p></article><aside class=\"pieces\"><h2 id=\"count\"></h2><div class=\"tray\" id=\"tray\"></div><div class=\"tools\"><button id=\"rotate\">↻ Obróć</button><button id=\"flip\">↔ Odbij</button></div><p class=\"muted\" id=\"selection\"></p></aside></section><div class=\"footer\"><button id=\"undo\">Cofnij</button><button id=\"reset\">Nowa gra</button><button id=\"solution\">Pokaż rozwiązanie</button></div></main><dialog id=\"rules\"><h2>Zasady</h2><ol><li>Wypełnij cały prostokąt, wykorzystując dwa zestawy tetromin. Każda figura składa się z czterech kwadratów połączonych bokami.</li><li>Wybierz figurę, obróć ją w razie potrzeby i kliknij pole planszy. Figury nie mogą się nakładać ani wystawać poza prostokąt.</li><li>Wolne tetromina: 5 rodzajów (I, O, T, L, S), można je obracać i odbijać. Jednostronne: 7 rodzajów (I, O, T, J, L, S, Z), można je obracać, ale nie odbijać.</li><li>Stałe tetromina: 19 różnych orientacji, można je tylko przesuwać. Ten rodzaj nie jest używany w tej łamigłówce.</li><li>Kliknięcie ułożonej figury wyjmuje ją z planszy. Wygrywasz, gdy wszystkie pola zostaną wypełnione.</li></ol><button id=\"dismiss\">Wróć</button></dialog><script>\n(()=>{'use strict';const q=s=>document.querySelector(s),sh={I:[[0,0],[1,0],[2,0],[3,0]],O:[[0,0],[1,0],[0,1],[1,1]],T:[[0,0],[1,0],[2,0],[1,1]],J:[[0,0],[0,1],[1,1],[2,1]],L:[[2,0],[0,1],[1,1],[2,1]],S:[[1,0],[2,0],[0,1],[1,1]],Z:[[0,0],[1,0],[1,1],[2,1]]},colors={I:'#35c9eb',O:'#f8df42',T:'#bd65ed',J:'#5268ef',L:'#ff993c',S:'#6edc57',Z:'#f05b60'},configs={'8x5':[8,5,true],'10x4':[10,4,true],'8x7':[8,7,false],'14x4':[14,4,false]},solutions={\"8x5\": [[\"I\", [0, 1, 2, 3]], [\"I\", [4, 5, 6, 7]], [\"O\", [8, 16, 9, 17]], [\"O\", [24, 32, 25, 33]], [\"T\", [10, 11, 19, 12]], [\"L\", [18, 26, 34, 35]], [\"T\", [27, 28, 36, 29]], [\"S\", [20, 13, 21, 14]], [\"S\", [22, 30, 15, 23]], [\"L\", [37, 38, 31, 39]]], \"10x4\": [[\"I\", [0, 1, 2, 3]], [\"I\", [10, 11, 12, 13]], [\"O\", [20, 30, 21, 31]], [\"O\", [22, 32, 23, 33]], [\"T\", [4, 5, 15, 6]], [\"L\", [14, 24, 34, 35]], [\"T\", [25, 26, 36, 27]], [\"S\", [16, 7, 17, 8]], [\"S\", [18, 28, 9, 19]], [\"L\", [37, 38, 29, 39]]], \"8x7\": [[\"I\", [0, 1, 2, 3]], [\"I\", [4, 5, 6, 7]], [\"O\", [8, 16, 9, 17]], [\"O\", [14, 22, 15, 23]], [\"T\", [32, 40, 48, 41]], [\"Z\", [24, 25, 33, 34]], [\"S\", [49, 42, 50, 43]], [\"J\", [51, 36, 44, 52]], [\"T\", [26, 19, 27, 35]], [\"L\", [10, 18, 11, 12]], [\"Z\", [20, 28, 13, 21]], [\"J\", [29, 30, 31, 39]], [\"L\", [37, 45, 53, 54]], [\"S\", [38, 46, 47, 55]]], \"14x4\": [[\"I\", [0, 1, 2, 3]], [\"I\", [14, 15, 16, 17]], [\"O\", [28, 42, 29, 43]], [\"O\", [30, 44, 31, 45]], [\"T\", [4, 5, 19, 6]], [\"L\", [18, 32, 46, 47]], [\"T\", [33, 34, 48, 35]], [\"S\", [20, 7, 21, 8]], [\"J\", [49, 22, 36, 50]], [\"S\", [9, 23, 24, 38]], [\"J\", [37, 51, 52, 53]], [\"Z\", [10, 11, 25, 26]], [\"L\", [12, 13, 27, 41]], [\"Z\", [39, 40, 54, 55]]]};let key='8x5',games={},selected=null,orientation=null,history=[],hover=-1,message='';const copy=v=>JSON.parse(JSON.stringify(v));function cfg(){return configs[key]}function names(){return [...(cfg()[2]?'IOTLS':'IOTJLSZ')].flatMap(n=>[n,n])}function game(){return games[key]||(games[key]={placed:[],revealed:false})}function norm(a){const x=Math.min(...a.map(p=>p[0])),y=Math.min(...a.map(p=>p[1]));return a.map(p=>[p[0]-x,p[1]-y]).sort((a,b)=>a[1]-b[1]||a[0]-b[0])}function cells(){let a=Array(cfg()[0]*cfg()[1]).fill(-1);for(const p of game().placed)for(const i of p.cells)a[i]=p.id;return a}function choose(id){selected=id;orientation=copy(sh[names()[id]]);hover=-1;message='';render()}function footprint(i){if(selected===null||i<0)return null;let [w,h]=cfg(),x=i%w,y=Math.floor(i/w),r=orientation.map(([a,b])=>[x+a,y+b]);if(r.some(([a,b])=>a>=w||b>=h))return null;return r.map(([a,b])=>b*w+a)}function push(){history.push(copy(game()));if(history.length>100)history.shift()}function click(i){let a=cells(),old=a[i];if(old!==-1){push();game().placed=game().placed.filter(p=>p.id!==old);game().revealed=false;choose(old);send();return}if(selected===null){message='Najpierw wybierz figurę.';render();return}let r=footprint(i);if(!r||r.some(j=>a[j]!==-1)){message='Figura nie mieści się w tym miejscu.';render();return}push();game().placed.push({id:selected,cells:r});game().revealed=false;selected=null;orientation=null;hover=-1;message='';render();send()}\nfunction icon(p,c){let w=Math.max(...p.map(v=>v[0]))+1,h=Math.max(...p.map(v=>v[1]))+1;return `<svg viewBox=\"0 0 ${w*20} ${h*20}\" aria-hidden=\"true\">${p.map(([x,y])=>`<rect x=\"${x*20}\" y=\"${y*20}\" width=\"20\" height=\"20\" fill=\"${c}\" stroke=\"#111\" stroke-width=\"1\"/>`).join('')}</svg>`}function paintHover(){const a=cells(),r=footprint(hover),ok=r&&r.every(j=>a[j]===-1);q('#board').querySelectorAll('button').forEach((el,i)=>{el.classList.toggle('ghost',!!(ok&&r.includes(i)));el.classList.toggle('bad',!!(r&&!ok&&r.includes(i)&&a[i]===-1));if(a[i]===-1&&selected!==null)el.style.setProperty('--c',colors[names()[selected]])})}function render(){const [w,h,free]=cfg(),a=cells(),ns=names(),used=new Set(game().placed.map(p=>p.id));q('#description').textContent=(free?'Wolne tetromina · 2 × 5 figur · 40 pól':'Jednostronne tetromina · 2 × 7 figur · 56 pól');q('#tabs').innerHTML=Object.entries(configs).map(([k,[x,y,f]])=>`<button data-key=\"${k}\" aria-pressed=\"${k===key}\">${f?'Wolne':'Jednostronne'} ${y}×${x}</button>`).join('');const b=q('#board');b.style.gridTemplateColumns=`repeat(${w},minmax(0,1fr))`;b.style.gridTemplateRows=`repeat(${h},minmax(0,1fr))`;b.style.setProperty('--ratio',w/h);b.innerHTML=a.map((id,i)=>`<button class=\"cell ${id>=0?'filled':''}\" data-i=\"${i}\" style=\"--c:${id>=0?colors[ns[id]]:'#151519'}\" aria-label=\"Wiersz ${Math.floor(i/w)+1}, kolumna ${i%w+1}${id>=0?', figura '+ns[id]:''}\"></button>`).join('');q('#tray').innerHTML=ns.map((n,id)=>`<button class=\"piece ${used.has(id)?'used':''}\" data-id=\"${id}\" ${used.has(id)?'disabled':''} aria-pressed=\"${selected===id}\" aria-label=\"Figura ${n}, zestaw ${id%2+1}\"><span>${n}</span>${icon(selected===id?orientation:sh[n],colors[n])}</button>`).join('');q('#count').textContent=`Figury ${used.size} / ${ns.length}`;q('#selection').textContent=selected===null?'Wybierz figurę':'Wybrano '+ns[selected];q('#rotate').disabled=selected===null;q('#flip').disabled=selected===null||!free;q('#flip').hidden=!free;q('#undo').disabled=!history.length;const done=a.every(v=>v!==-1);q('#status').textContent=done?(game().revealed?'Przykładowe rozwiązanie':'Brawo! Prostokąt ułożony.'):message||`${a.filter(v=>v!==-1).length} / ${a.length} pól`;q('#status').classList.toggle('success',done);paintHover()}\nfunction send(){if(parent!==window)parent.postMessage({type:'mw-v40-tetromino-state',state:{key,games}},'*')}function restore(s){if(s&&configs[s.key]&&s.games&&typeof s.games==='object'){key=s.key;games={};for(const k of Object.keys(configs)){const [w,h,f]=configs[k],ns=[...(f?'IOTLS':'IOTJLSZ')].flatMap(n=>[n,n]),v=s.games[k];if(!v||!Array.isArray(v.placed))continue;let ids=new Set(),occupied=new Set();let ok=v.placed.every(p=>{if(!Number.isInteger(p.id)||p.id<0||p.id>=ns.length||ids.has(p.id)||!Array.isArray(p.cells)||p.cells.length!==4||new Set(p.cells).size!==4||p.cells.some(i=>!Number.isInteger(i)||i<0||i>=w*h||occupied.has(i)))return false;let target=JSON.stringify(norm(p.cells.map(i=>[i%w,Math.floor(i/w)]))),matches=false;for(let flip=0;flip<(f?2:1);flip++){let a=sh[ns[p.id]].map(([x,y])=>[flip?-x:x,y]);for(let r=0;r<4;r++){if(JSON.stringify(norm(a))===target)matches=true;a=a.map(([x,y])=>[-y,x])}}if(!matches)return false;ids.add(p.id);p.cells.forEach(i=>occupied.add(i));return true});if(ok)games[k]={placed:copy(v.placed),revealed:!!v.revealed}}}selected=null;orientation=null;history=[];hover=-1;message='';render()}\nq('#tabs').onclick=e=>{let b=e.target.closest('[data-key]');if(!b)return;key=b.dataset.key;selected=null;orientation=null;history=[];hover=-1;message='';render();send()};q('#tray').onclick=e=>{let b=e.target.closest('[data-id]');if(b&&!b.disabled)choose(+b.dataset.id)};q('#board').onclick=e=>{let b=e.target.closest('[data-i]');if(b)click(+b.dataset.i)};q('#board').addEventListener('pointerover',e=>{let b=e.target.closest('[data-i]');if(b){hover=+b.dataset.i;paintHover()}});q('#board').addEventListener('pointerleave',()=>{hover=-1;paintHover()});q('#rotate').onclick=()=>{if(selected!==null){orientation=norm(orientation.map(([x,y])=>[-y,x]));render()}};q('#flip').onclick=()=>{if(selected!==null&&cfg()[2]){orientation=norm(orientation.map(([x,y])=>[-x,y]));render()}};q('#undo').onclick=()=>{if(history.length){games[key]=history.pop();selected=null;orientation=null;hover=-1;message='';render();send()}};q('#reset').onclick=()=>{games[key]={placed:[],revealed:false};history=[];selected=null;orientation=null;hover=-1;message='';render();send()};q('#solution').onclick=()=>{push();let used=new Set();games[key]={placed:solutions[key].map(([n,cells])=>{let id=names().findIndex((v,i)=>v===n&&!used.has(i));used.add(id);return {id,cells}}),revealed:true};selected=null;orientation=null;hover=-1;message='';render();send()};q('#info').onclick=()=>q('#rules').showModal();q('#dismiss').onclick=()=>q('#rules').close();window.addEventListener('keydown',e=>{if(q('#rules').open)return;if(e.key.toLowerCase()==='r'){q('#rotate').click()}if(e.key.toLowerCase()==='f'){q('#flip').click()}});\nfunction snapshot(){let c=document.createElement('canvas');c.width=1440;c.height=900;let x=c.getContext('2d'),[w,h]=cfg(),a=cells(),ns=names(),s=Math.min(105,1000/w,650/h),ox=(1440-s*w)/2,oy=160+(650-h*s)/2;x.fillStyle='#000';x.fillRect(0,0,1440,900);x.fillStyle='#fff';x.textAlign='center';x.font='bold 44px Arial';x.fillText('Tetromino',720,58);x.font='bold 25px Arial';x.fillStyle='#c5a6ff';x.fillText(q('#description').textContent+' · '+h+'×'+w,720,105);for(let i=0;i<a.length;i++){x.fillStyle=a[i]===-1?'#151519':colors[ns[a[i]]];x.fillRect(ox+(i%w)*s,oy+Math.floor(i/w)*s,s-1,s-1)}x.fillStyle='#fff';x.fillText(q('#status').textContent,720,850);return c.toDataURL('image/png')}\nwindow.addEventListener('message',e=>{if(e.source!==parent)return;let m=e.data;if(m?.type==='mw-v21-div-restore')restore(m.state);if(m?.type==='mw-v21-div-export'){restore(m.state);try{parent.postMessage({type:'mw-v21-div-image',id:m.id,png:snapshot()},'*')}catch(err){parent.postMessage({type:'mw-v21-div-image',id:m.id,error:String(err)},'*')}}});render();})();\n</script></body></html>\n"
},
{
"id": "pentomino",
"action": "mw-v42-pentomino",
"title": "Pentomino",
"label": "Pentomino",
"icon": "<span>▦</span>",
"source": "<!doctype html><html lang=\"pl\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>\n*{box-sizing:border-box}html,body{margin:0;background:#000;color:white;font:600 16px Arial,sans-serif;color-scheme:dark}main{min-height:100dvh;height:100dvh;display:flex;flex-direction:column;gap:10px;padding:12px;overflow:auto}h1,h2,p{margin:0}h1{font-size:clamp(23px,3vw,40px)}header{display:flex;align-items:center;justify-content:space-between}button{font:inherit;color:white;background:#292929;border:1px solid #555;border-radius:8px;padding:9px 14px;cursor:pointer;touch-action:manipulation}button:hover{background:#383838}button:focus-visible{outline:2px solid white;outline-offset:2px}button:disabled{opacity:.35;cursor:default}.rules{background:white;color:black}.rules:hover{background:#ddd}.tabs,.tools{display:flex;gap:7px;flex-wrap:wrap;justify-content:center}.tabs button[aria-pressed=true]{background:#c5a6ff;color:#201331;border-color:#c5a6ff}.stage{flex:1;min-height:250px;display:grid;grid-template-columns:minmax(0,2fr) minmax(210px,1fr);gap:12px}.boardcard,.pieces{background:#0b0b0e;border:1px solid #39343e;border-radius:12px;padding:10px;display:flex;flex-direction:column;gap:10px;min-width:0;min-height:0}.boardarea{flex:1;min-height:120px;display:flex;align-items:center;justify-content:center;container-type:size}.board{display:grid;gap:1px;background:#48434d;border:1px solid #666;width:min(100%,calc(100cqh * var(--ratio)));aspect-ratio:var(--ratio);touch-action:manipulation}.cell{border:0;border-radius:0;padding:0;min-width:0;min-height:0;background:#151519;position:relative}.cell:hover{background:#393442}.cell.filled{background:var(--c)}.cell.ghost{background:var(--c);opacity:.5}.cell.bad{background:#783844}.pieces h2{font-size:clamp(17px,2vw,25px);text-align:center}.tray{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:5px;flex:1;align-content:center;overflow:auto}.piece{display:flex;align-items:center;justify-content:center;gap:5px;min-height:42px;padding:4px;background:#151519}.piece[aria-pressed=true]{border:2px solid #c5a6ff;background:#272032}.piece svg{width:min(90%,92px);height:clamp(24px,5vh,48px);display:block}.piece.used{opacity:.25}.info{color:#c5a6ff;text-align:center;font-size:clamp(14px,1.8vw,22px)}.status{min-height:25px;text-align:center;color:#fff}.success{color:#7be4a7}.muted{color:#bcbac4;text-align:center;font-size:clamp(12px,1.5vw,17px)}.tools button{flex:1}.footer{display:flex;gap:8px;justify-content:center;flex-wrap:wrap}.footer button{min-width:120px}dialog{background:#101015;border:1px solid #666;border-radius:12px;color:#fff;width:min(90%,660px);padding:22px;line-height:1.55}dialog::backdrop{background:#000c}dialog h2{color:#c5a6ff}dialog button{display:block;margin-left:auto}@media(max-width:650px){main{height:auto;min-height:100dvh}.stage{grid-template-columns:1fr}.boardarea{height:45vh;flex:none}.tray{grid-template-columns:repeat(4,minmax(0,1fr))}.piece svg{height:28px}.tabs button{padding:7px 10px}.pieces{overflow:visible}}\n\n/* v41: wspólne położenie zasad w grach */\n#game{padding-top:10px;padding-left:12px;padding-right:12px}\n#game > .head,#game > header{display:grid;grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);align-items:center;gap:8px;position:relative;width:100%;max-width:none;align-self:stretch;flex:0 0 44px;min-height:44px;}\n#game > .head h1,#game > header h1{grid-column:2;grid-row:1;margin:0;text-align:center;font-size:clamp(20px,3.8vh,36px);line-height:1.15;}\n#game #info{position:static;grid-column:3;grid-row:1;justify-self:end;align-self:center;white-space:nowrap;min-height:36px;height:36px;padding:6px 15px;border:1px solid #fff;background:#fff;color:#000;font:800 16px/1 Arial,sans-serif;border-radius:8px;box-shadow:none;}\n#game #info:hover{background:#e5e5e5;color:#000;}\n@media(max-width:520px){#game > .head,#game > header{grid-template-columns:minmax(0,1fr) auto;}#game > .head h1,#game > header h1{grid-column:1;text-align:left;font-size:clamp(18px,4.7vw,25px);}#game #info{grid-column:2;}}\n</style></head><body><main id=\"game\"><header><h1>Pentomino</h1><button id=\"info\" class=\"rules\">Zasady</button></header><nav class=\"tabs\" id=\"tabs\"></nav><p class=\"info\" id=\"description\"></p><section class=\"stage\"><article class=\"boardcard\"><div class=\"boardarea\"><div id=\"board\" class=\"board\" aria-label=\"Plansza łamigłówki\"></div></div><p class=\"status\" id=\"status\" role=\"status\"></p><p class=\"muted\">Wybierz figurę, a następnie pole odpowiadające jej lewemu górnemu narożnikowi. Kliknij ułożoną figurę, aby ją wyjąć.</p></article><aside class=\"pieces\"><h2 id=\"count\"></h2><div class=\"tray\" id=\"tray\"></div><div class=\"tools\"><button id=\"rotate\">↻ Obróć</button><button id=\"flip\">↔ Odbij</button></div><p class=\"muted\" id=\"selection\"></p></aside></section><div class=\"footer\"><button id=\"undo\">Cofnij</button><button id=\"reset\">Nowa gra</button><button id=\"solution\">Pokaż rozwiązanie</button></div></main><dialog id=\"rules\"><h2>Zasady</h2><ol><li>Wypełnij cały prostokąt, wykorzystując 12 różnych pentomin. Każda figura składa się z pięciu kwadratów połączonych bokami.</li><li>Wybierz figurę, obróć ją w razie potrzeby i kliknij pole planszy. Figury nie mogą się nakładać ani wystawać poza prostokąt.</li><li>Każdą figurę można obracać i odbijać lustrzanie.</li><li>Kliknięcie ułożonej figury wyjmuje ją z planszy. Wygrywasz, gdy wszystkie pola zostaną wypełnione.</li></ol><button id=\"dismiss\">Wróć</button></dialog><script>\n(()=>{'use strict';const q=s=>document.querySelector(s),sh={\"F\": [[1, 0], [2, 0], [0, 1], [1, 1], [1, 2]], \"I\": [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0]], \"L\": [[0, 0], [0, 1], [0, 2], [0, 3], [1, 3]], \"P\": [[0, 0], [1, 0], [0, 1], [1, 1], [0, 2]], \"N\": [[0, 0], [1, 0], [1, 1], [2, 1], [3, 1]], \"T\": [[0, 0], [1, 0], [2, 0], [1, 1], [1, 2]], \"U\": [[0, 0], [2, 0], [0, 1], [1, 1], [2, 1]], \"V\": [[0, 0], [0, 1], [0, 2], [1, 2], [2, 2]], \"W\": [[0, 0], [0, 1], [1, 1], [1, 2], [2, 2]], \"X\": [[1, 0], [0, 1], [1, 1], [2, 1], [1, 2]], \"Y\": [[1, 0], [0, 1], [1, 1], [1, 2], [1, 3]], \"Z\": [[0, 0], [1, 0], [1, 1], [1, 2], [2, 2]]},colors={\"F\": \"#ed7081\", \"I\": \"#34c8ed\", \"L\": \"#ff993c\", \"P\": \"#b96ceb\", \"N\": \"#72dd7d\", \"T\": \"#e9c94e\", \"U\": \"#6d92fb\", \"V\": \"#d8a1e4\", \"W\": \"#4bc4b2\", \"X\": \"#e67fce\", \"Y\": \"#a7d54b\", \"Z\": \"#f2a779\"},configs={\"10x6\": [10, 6, true], \"12x5\": [12, 5, true], \"15x4\": [15, 4, true], \"20x3\": [20, 3, true]},solutions={\"10x6\": [[\"X\", [30, 21, 31, 41, 32]], [\"U\", [40, 50, 51, 42, 52]], [\"V\", [0, 10, 20, 1, 2]], [\"F\", [11, 12, 22, 3, 13]], [\"W\", [43, 53, 34, 44, 35]], [\"Z\", [23, 33, 24, 15, 25]], [\"L\", [4, 14, 5, 6, 7]], [\"Y\", [54, 45, 55, 56, 57]], [\"I\", [9, 19, 29, 39, 49]], [\"N\", [46, 47, 48, 58, 59]], [\"T\", [16, 17, 8, 18, 28]], [\"P\", [26, 36, 27, 37, 38]]], \"12x5\": [[\"X\", [13, 2, 14, 26, 15]], [\"U\", [0, 12, 24, 1, 25]], [\"P\", [36, 48, 37, 49, 50]], [\"V\", [3, 4, 5, 17, 29]], [\"F\", [27, 16, 28, 40, 41]], [\"N\", [38, 39, 51, 52, 53]], [\"I\", [6, 7, 8, 9, 10]], [\"T\", [21, 22, 11, 23, 35]], [\"W\", [33, 34, 46, 47, 59]], [\"L\", [43, 55, 56, 57, 58]], [\"Y\", [18, 30, 42, 54, 31]], [\"Z\", [19, 20, 32, 44, 45]]], \"15x4\": [[\"X\", [16, 2, 17, 32, 18]], [\"U\", [0, 15, 30, 1, 31]], [\"I\", [45, 46, 47, 48, 49]], [\"Y\", [3, 4, 5, 20, 6]], [\"F\", [33, 19, 34, 35, 50]], [\"Z\", [36, 51, 37, 23, 38]], [\"N\", [21, 7, 22, 8, 9]], [\"L\", [52, 53, 54, 40, 55]], [\"W\", [24, 39, 10, 25, 11]], [\"V\", [12, 13, 14, 29, 44]], [\"T\", [57, 28, 43, 58, 59]], [\"P\", [26, 41, 56, 27, 42]]], \"20x3\": [[\"X\", [36, 17, 37, 57, 38]], [\"U\", [18, 58, 19, 39, 59]], [\"P\", [14, 34, 15, 35, 16]], [\"I\", [52, 53, 54, 55, 56]], [\"Z\", [31, 51, 32, 13, 33]], [\"Y\", [9, 10, 30, 11, 12]], [\"W\", [8, 28, 29, 49, 50]], [\"T\", [46, 7, 27, 47, 48]], [\"F\", [24, 25, 45, 6, 26]], [\"N\", [22, 3, 23, 4, 5]], [\"V\", [0, 20, 40, 1, 2]], [\"L\", [21, 41, 42, 43, 44]]]};let key='10x6',games={},selected=null,orientation=null,history=[],hover=-1,message='';const copy=v=>JSON.parse(JSON.stringify(v));function cfg(){return configs[key]}function names(){return Object.keys(sh)}function game(){return games[key]||(games[key]={placed:[],revealed:false})}function norm(a){const x=Math.min(...a.map(p=>p[0])),y=Math.min(...a.map(p=>p[1]));return a.map(p=>[p[0]-x,p[1]-y]).sort((a,b)=>a[1]-b[1]||a[0]-b[0])}function cells(){let a=Array(cfg()[0]*cfg()[1]).fill(-1);for(const p of game().placed)for(const i of p.cells)a[i]=p.id;return a}function choose(id){selected=id;orientation=copy(sh[names()[id]]);hover=-1;message='';render()}function footprint(i){if(selected===null||i<0)return null;let [w,h]=cfg(),x=i%w,y=Math.floor(i/w),r=orientation.map(([a,b])=>[x+a,y+b]);if(r.some(([a,b])=>a>=w||b>=h))return null;return r.map(([a,b])=>b*w+a)}function push(){history.push(copy(game()));if(history.length>100)history.shift()}function click(i){let a=cells(),old=a[i];if(old!==-1){push();game().placed=game().placed.filter(p=>p.id!==old);game().revealed=false;choose(old);send();return}if(selected===null){message='Najpierw wybierz figurę.';render();return}let r=footprint(i);if(!r||r.some(j=>a[j]!==-1)){message='Figura nie mieści się w tym miejscu.';render();return}push();game().placed.push({id:selected,cells:r});game().revealed=false;selected=null;orientation=null;hover=-1;message='';render();send()}\nfunction icon(p,c){let w=Math.max(...p.map(v=>v[0]))+1,h=Math.max(...p.map(v=>v[1]))+1;return `<svg viewBox=\"0 0 ${w*20} ${h*20}\" aria-hidden=\"true\">${p.map(([x,y])=>`<rect x=\"${x*20}\" y=\"${y*20}\" width=\"20\" height=\"20\" fill=\"${c}\" stroke=\"#111\" stroke-width=\"1\"/>`).join('')}</svg>`}function paintHover(){const a=cells(),r=footprint(hover),ok=r&&r.every(j=>a[j]===-1);q('#board').querySelectorAll('button').forEach((el,i)=>{el.classList.toggle('ghost',!!(ok&&r.includes(i)));el.classList.toggle('bad',!!(r&&!ok&&r.includes(i)&&a[i]===-1));if(a[i]===-1&&selected!==null)el.style.setProperty('--c',colors[names()[selected]])})}function render(){const [w,h,free]=cfg(),a=cells(),ns=names(),used=new Set(game().placed.map(p=>p.id));q('#description').textContent='12 figur · 60 pól';q('#tabs').innerHTML=Object.entries(configs).map(([k,[x,y,f]])=>`<button data-key=\"${k}\" aria-pressed=\"${k===key}\">${y}×${x}</button>`).join('');const b=q('#board');b.style.gridTemplateColumns=`repeat(${w},minmax(0,1fr))`;b.style.gridTemplateRows=`repeat(${h},minmax(0,1fr))`;b.style.setProperty('--ratio',w/h);b.innerHTML=a.map((id,i)=>`<button class=\"cell ${id>=0?'filled':''}\" data-i=\"${i}\" style=\"--c:${id>=0?colors[ns[id]]:'#151519'}\" aria-label=\"Wiersz ${Math.floor(i/w)+1}, kolumna ${i%w+1}${id>=0?', figura '+ns[id]:''}\"></button>`).join('');q('#tray').innerHTML=ns.map((n,id)=>`<button class=\"piece ${used.has(id)?'used':''}\" data-id=\"${id}\" ${used.has(id)?'disabled':''} aria-pressed=\"${selected===id}\" aria-label=\"Figura ${n}, \"><span>${n}</span>${icon(selected===id?orientation:sh[n],colors[n])}</button>`).join('');q('#count').textContent=`Figury ${used.size} / ${ns.length}`;q('#selection').textContent=selected===null?'Wybierz figurę':'Wybrano '+ns[selected];q('#rotate').disabled=selected===null;q('#flip').disabled=selected===null||!free;q('#flip').hidden=!free;q('#undo').disabled=!history.length;const done=a.every(v=>v!==-1);q('#status').textContent=done?(game().revealed?'Przykładowe rozwiązanie':'Brawo! Prostokąt ułożony.'):message||`${a.filter(v=>v!==-1).length} / ${a.length} pól`;q('#status').classList.toggle('success',done);paintHover()}\nfunction send(){if(parent!==window)parent.postMessage({type:'mw-v42-pentomino-state',state:{key,games}},'*')}function restore(s){if(s&&configs[s.key]&&s.games&&typeof s.games==='object'){key=s.key;games={};for(const k of Object.keys(configs)){const [w,h,f]=configs[k],ns=Object.keys(sh),v=s.games[k];if(!v||!Array.isArray(v.placed))continue;let ids=new Set(),occupied=new Set();let ok=v.placed.every(p=>{if(!Number.isInteger(p.id)||p.id<0||p.id>=ns.length||ids.has(p.id)||!Array.isArray(p.cells)||p.cells.length!==5||new Set(p.cells).size!==5||p.cells.some(i=>!Number.isInteger(i)||i<0||i>=w*h||occupied.has(i)))return false;let target=JSON.stringify(norm(p.cells.map(i=>[i%w,Math.floor(i/w)]))),matches=false;for(let flip=0;flip<(f?2:1);flip++){let a=sh[ns[p.id]].map(([x,y])=>[flip?-x:x,y]);for(let r=0;r<4;r++){if(JSON.stringify(norm(a))===target)matches=true;a=a.map(([x,y])=>[-y,x])}}if(!matches)return false;ids.add(p.id);p.cells.forEach(i=>occupied.add(i));return true});if(ok)games[k]={placed:copy(v.placed),revealed:!!v.revealed}}}selected=null;orientation=null;history=[];hover=-1;message='';render()}\nq('#tabs').onclick=e=>{let b=e.target.closest('[data-key]');if(!b)return;key=b.dataset.key;selected=null;orientation=null;history=[];hover=-1;message='';render();send()};q('#tray').onclick=e=>{let b=e.target.closest('[data-id]');if(b&&!b.disabled)choose(+b.dataset.id)};q('#board').onclick=e=>{let b=e.target.closest('[data-i]');if(b)click(+b.dataset.i)};q('#board').addEventListener('pointerover',e=>{let b=e.target.closest('[data-i]');if(b){hover=+b.dataset.i;paintHover()}});q('#board').addEventListener('pointerleave',()=>{hover=-1;paintHover()});q('#rotate').onclick=()=>{if(selected!==null){orientation=norm(orientation.map(([x,y])=>[-y,x]));render()}};q('#flip').onclick=()=>{if(selected!==null&&cfg()[2]){orientation=norm(orientation.map(([x,y])=>[-x,y]));render()}};q('#undo').onclick=()=>{if(history.length){games[key]=history.pop();selected=null;orientation=null;hover=-1;message='';render();send()}};q('#reset').onclick=()=>{games[key]={placed:[],revealed:false};history=[];selected=null;orientation=null;hover=-1;message='';render();send()};q('#solution').onclick=()=>{push();let used=new Set();games[key]={placed:solutions[key].map(([n,cells])=>{let id=names().findIndex((v,i)=>v===n&&!used.has(i));used.add(id);return {id,cells}}),revealed:true};selected=null;orientation=null;hover=-1;message='';render();send()};q('#info').onclick=()=>q('#rules').showModal();q('#dismiss').onclick=()=>q('#rules').close();window.addEventListener('keydown',e=>{if(q('#rules').open)return;if(e.key.toLowerCase()==='r'){q('#rotate').click()}if(e.key.toLowerCase()==='f'){q('#flip').click()}});\nfunction snapshot(){let c=document.createElement('canvas');c.width=1440;c.height=900;let x=c.getContext('2d'),[w,h]=cfg(),a=cells(),ns=names(),s=Math.min(105,1000/w,650/h),ox=(1440-s*w)/2,oy=160+(650-h*s)/2;x.fillStyle='#000';x.fillRect(0,0,1440,900);x.fillStyle='#fff';x.textAlign='center';x.font='bold 44px Arial';x.fillText('Pentomino',720,58);x.font='bold 25px Arial';x.fillStyle='#c5a6ff';x.fillText(q('#description').textContent+' · '+h+'×'+w,720,105);for(let i=0;i<a.length;i++){x.fillStyle=a[i]===-1?'#151519':colors[ns[a[i]]];x.fillRect(ox+(i%w)*s,oy+Math.floor(i/w)*s,s-1,s-1)}x.fillStyle='#fff';x.fillText(q('#status').textContent,720,850);return c.toDataURL('image/png')}\nwindow.addEventListener('message',e=>{if(e.source!==parent)return;let m=e.data;if(m?.type==='mw-v21-div-restore')restore(m.state);if(m?.type==='mw-v21-div-export'){restore(m.state);try{parent.postMessage({type:'mw-v21-div-image',id:m.id,png:snapshot()},'*')}catch(err){parent.postMessage({type:'mw-v21-div-image',id:m.id,error:String(err)},'*')}}});render();})();\n</script></body></html>\n"
},
{
"id": "2048",
"action": "mw-v42-2048",
"title": "2048",
"label": "2048",
"icon": "<span>2ⁿ</span>",
"source": "<!doctype html><html lang=\"pl\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>*{box-sizing:border-box}html,body{margin:0;background:#000;color:white;font:600 16px Arial,sans-serif;color-scheme:dark}main{height:100dvh;min-height:100dvh;padding:10px 12px;display:flex;flex-direction:column;gap:12px;overflow:auto}header{display:grid;grid-template-columns:1fr auto 1fr;align-items:center;min-height:44px;gap:8px}h1{grid-column:2;margin:0;text-align:center;font-size:clamp(20px,3.8vh,36px)}button{background:#292929;color:white;border:1px solid #555;border-radius:8px;padding:9px 14px;font:inherit;cursor:pointer;touch-action:manipulation}button:disabled{opacity:.4}button:hover{background:#383838}button:focus-visible{outline:2px solid white;outline-offset:2px}#info{grid-column:3;justify-self:end;background:white;color:black;border:1px solid white;height:36px;padding:6px 15px;font:800 16px/1 Arial,sans-serif}nav,.tools,.footer{display:flex;gap:8px;justify-content:center;flex-wrap:wrap}button[aria-pressed=true]{background:#c5a6ff;color:#201331}.area{flex:1;min-height:200px;display:flex;align-items:center;justify-content:center;container-type:size}.board{display:grid;grid-auto-rows:1fr;width:min(100%,100cqh,620px);aspect-ratio:1;gap:4px;padding:4px;border:1px solid #555;border-radius:10px;background:#151515;touch-action:none}.cell{min-width:0;min-height:0;padding:0;border-radius:5px;border:1px solid #474747;display:flex;align-items:center;justify-content:center;font-size:clamp(18px,4.4vh,40px);font-weight:800;line-height:1}.status{text-align:center;color:#ddd;margin:0}dialog{background:#101015;border:1px solid #666;border-radius:12px;color:#fff;width:min(90%,660px);padding:22px;line-height:1.55}dialog::backdrop{background:#000c}dialog h2{color:#c5a6ff}dialog button{display:block;margin-left:auto}.stats{display:flex;gap:12px;justify-content:center}.stats div{padding:9px 20px;background:#171717;border:1px solid #444;border-radius:8px;text-align:center}.stats b{display:block;font-size:26px}.win{color:#7be4a7}.bad{outline:3px solid #ff6767;outline-offset:-3px}@media(max-width:520px){header{grid-template-columns:1fr auto}h1{grid-column:1;text-align:left}#info{grid-column:2}.board{width:min(100%,100cqh)}}</style></head><body><main id=\"game\"><header><h1>2048</h1><button id=\"info\">Zasady</button></header><div class=\"stats\"><div>Punkty<b id=\"score\">0</b></div><div>Rekord<b id=\"best\">0</b></div></div><div class=\"area\"><div class=\"board\" id=\"board\"></div></div><p id=\"status\" class=\"status\"></p><div class=\"tools\"><button data-dir=\"left\">←</button><button data-dir=\"up\">↑</button><button data-dir=\"down\">↓</button><button data-dir=\"right\">→</button></div><div class=\"footer\"><button id=\"undo\">Cofnij</button><button id=\"reset\">Nowa gra</button></div></main><dialog id=\"rules\"><h2>Zasady</h2><p>Przesuwaj wszystkie kafelki strzałkami, przyciskami lub gestem. Dwie jednakowe liczby łączą się w ich sumę, najwyżej raz podczas ruchu. Po ruchu pojawia się 2 lub 4. Dąż do 2048; gra kończy się, gdy nie można wykonać żadnego ruchu.</p><button id=\"dismiss\">Wróć</button></dialog><script>(()=>{\"use strict\";const q=s=>document.querySelector(s);q(\"#info\").onclick=()=>q(\"#rules\").showModal();q(\"#dismiss\").onclick=()=>q(\"#rules\").close();const MODE='2048';let a=Array(16).fill(0),score=0,best=0,previous=null;const colors=['#212126','#eee4da','#ede0c8','#f2b179','#f59563','#f67c5f','#f65e3b','#edcf72','#edcc61','#edc850','#edc53f','#edc22e'];function spawn(){let free=a.map((v,i)=>v?null:i).filter(v=>v!==null);if(free.length)a[free[Math.floor(Math.random()*free.length)]]=Math.random()<.9?2:4}function reset(){a=Array(16).fill(0);score=0;previous=null;spawn();spawn();render();send()}function lines(dir){return Array.from({length:4},(_,r)=>Array.from({length:4},(_,c)=>dir==='left'?r*4+c:dir==='right'?r*4+3-c:dir==='up'?c*4+r:(3-c)*4+r))}function move(dir){if(q('#rules').open)return;let old=a.slice(),oldscore=score;for(let ids of lines(dir)){let v=ids.map(i=>a[i]).filter(Boolean),out=[];for(let i=0;i<v.length;i++){if(v[i]===v[i+1]){out.push(v[i]*2);score+=v[i]*2;i++}else out.push(v[i])}ids.forEach((k,i)=>a[k]=out[i]||0)}if(a.some((v,i)=>v!==old[i])){previous={a:old,score:oldscore};spawn();best=Math.max(best,score);render();send()}}function can(){return a.includes(0)||a.some((v,i)=>(i%4<3&&a[i+1]===v)||(i<12&&a[i+4]===v))}function render(){q('#board').style.gridTemplateColumns='repeat(4,1fr)';q('#board').innerHTML=a.map(v=>`<div class=\"cell\" style=\"background:${colors[Math.min(11,Math.log2(v)||0)]||colors[0]};color:${v&&v<=4?'#302820':'#fff'}\">${v||''}</div>`).join('');q('#score').textContent=score;q('#best').textContent=best;q('#status').textContent=!can()?'Koniec gry':a.some(v=>v>=2048)?'2048 osiągnięte! Możesz grać dalej.':'Łącz jednakowe liczby';q('#undo').disabled=!previous}function state(){return {a,score,best,previous}}function restore(s){if(s&&Array.isArray(s.a)&&s.a.length===16&&s.a.every(v=>Number.isSafeInteger(v)&&v>=0&&(v===0||Number.isInteger(Math.log2(v))))){a=s.a.slice();score=Number(s.score)||0;best=Math.max(score,Number(s.best)||0);previous=null;render()}else{a=Array(16).fill(0);score=0;previous=null;spawn();spawn();render()}}q('#reset').onclick=reset;q('#undo').onclick=()=>{if(previous){a=previous.a;score=previous.score;previous=null;render();send()}};q('.tools').onclick=e=>{let b=e.target.closest('[data-dir]');if(b)move(b.dataset.dir)};window.addEventListener('keydown',e=>{let d={ArrowLeft:'left',ArrowRight:'right',ArrowUp:'up',ArrowDown:'down'}[e.key];if(d&&!q('#rules').open){e.preventDefault();move(d)}});let p=null;q('#board').addEventListener('pointerdown',e=>{p=[e.clientX,e.clientY];q('#board').setPointerCapture(e.pointerId)});q('#board').addEventListener('pointerup',e=>{if(!p)return;let dx=e.clientX-p[0],dy=e.clientY-p[1];p=null;if(Math.max(Math.abs(dx),Math.abs(dy))>15)move(Math.abs(dx)>Math.abs(dy)?dx>0?'right':'left':dy>0?'down':'up')});restore(null);function send(){if(parent!==window)parent.postMessage({type:'mw-v42-game-state',mode:MODE,state:state()},'*')}window.addEventListener('message',e=>{if(e.source!==parent)return;let m=e.data;if(m?.type==='mw-v21-div-restore')restore(m.state);if(m?.type==='mw-v21-div-export'){restore(m.state);try{const c=document.createElement('canvas');c.width=900;c.height=1000;const x=c.getContext('2d');x.fillStyle='#000';x.fillRect(0,0,900,1000);x.font='bold 44px Arial';x.textAlign='center';x.fillStyle='#fff';x.fillText(q('h1').textContent,450,65);let a=[...q('#board').children],n=Math.sqrt(a.length),d=760/n;a.forEach((b,i)=>{x.fillStyle=getComputedStyle(b).backgroundColor;x.fillRect(70+i%n*d,120+Math.floor(i/n)*d,d-3,d-3);x.fillStyle=getComputedStyle(b).color;x.font='bold '+Math.min(60,d*.48)+'px Arial';x.textBaseline='middle';x.fillText(b.textContent,70+(i%n+.5)*d,120+(Math.floor(i/n)+.5)*d)});x.fillStyle='#fff';x.font='24px Arial';x.fillText(q('#status').textContent,450,940);parent.postMessage({type:'mw-v21-div-image',id:m.id,png:c.toDataURL('image/png')},'*')}catch(err){parent.postMessage({type:'mw-v21-div-image',id:m.id,error:String(err)},'*')}}});})();</script></body></html>"
},
{
"id": "catoku",
"action": "mw-v42-catoku",
"title": "Catoku",
"label": "Catoku",
"icon": "<span class=\"solid-icon\"><svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><path fill-rule=\"evenodd\" d=\"M3 3L9 7Q12 6 15 7L21 3L22 12Q23 19 18 21Q12 24 6 21Q1 19 2 12Z M6 13a1.6 1.6 0 1 0 3.2 0a1.6 1.6 0 1 0 -3.2 0Z M14.8 13a1.6 1.6 0 1 0 3.2 0a1.6 1.6 0 1 0 -3.2 0Z M10 17h4l-2 2Z\"/></svg></span>",
"source": "<!doctype html><html lang=\"pl\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>*{box-sizing:border-box}html,body{margin:0;background:#000;color:white;font:600 16px Arial,sans-serif;color-scheme:dark}main{height:100dvh;min-height:100dvh;padding:10px 12px;display:flex;flex-direction:column;gap:12px;overflow:auto}header{display:grid;grid-template-columns:1fr auto 1fr;align-items:center;min-height:44px;gap:8px}h1{grid-column:2;margin:0;text-align:center;font-size:clamp(20px,3.8vh,36px)}button{background:#292929;color:white;border:1px solid #555;border-radius:8px;padding:9px 14px;font:inherit;cursor:pointer;touch-action:manipulation}button:disabled{opacity:.4}button:hover{background:#383838}button:focus-visible{outline:2px solid white;outline-offset:2px}#info{grid-column:3;justify-self:end;background:white;color:black;border:1px solid white;height:36px;padding:6px 15px;font:800 16px/1 Arial,sans-serif}nav,.tools,.footer{display:flex;gap:8px;justify-content:center;flex-wrap:wrap}button[aria-pressed=true]{background:#c5a6ff;color:#201331}.area{flex:1;min-height:200px;display:flex;align-items:center;justify-content:center;container-type:size}.board{display:grid;grid-auto-rows:1fr;width:min(100%,100cqh,620px);aspect-ratio:1;gap:4px;padding:4px;border:1px solid #555;border-radius:10px;background:#151515;touch-action:none}.cell{min-width:0;min-height:0;padding:0;border-radius:5px;border:1px solid #474747;display:flex;align-items:center;justify-content:center;font-size:clamp(18px,4.4vh,40px);font-weight:800;line-height:1}.status{text-align:center;color:#ddd;margin:0}dialog{background:#101015;border:1px solid #666;border-radius:12px;color:#fff;width:min(90%,660px);padding:22px;line-height:1.55}dialog::backdrop{background:#000c}dialog h2{color:#c5a6ff}dialog button{display:block;margin-left:auto}.stats{display:flex;gap:12px;justify-content:center}.stats div{padding:9px 20px;background:#171717;border:1px solid #444;border-radius:8px;text-align:center}.stats b{display:block;font-size:26px}.win{color:#7be4a7}.bad{outline:3px solid #ff6767;outline-offset:-3px}@media(max-width:520px){header{grid-template-columns:1fr auto}h1{grid-column:1;text-align:left}#info{grid-column:2}.board{width:min(100%,100cqh)}}.cell svg{display:block;width:82%;height:82%;max-width:100%;max-height:100%;flex:none;pointer-events:none}#cat svg{width:24px;height:24px;vertical-align:middle;margin-right:5px}</style></head><body><main id=\"game\"><header><h1>Catoku</h1><button id=\"info\">Zasady</button></header><nav id=\"sizes\"></nav><p class=\"status\">Jeden kot w każdym wierszu, kolumnie i kolorowym obszarze</p><div class=\"area\"><div class=\"board\" id=\"board\"></div></div><p id=\"status\" class=\"status\"></p><div class=\"tools\"><button id=\"cat\"><svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><path fill-rule=\"evenodd\" d=\"M3 3L9 7Q12 6 15 7L21 3L22 12Q23 19 18 21Q12 24 6 21Q1 19 2 12Z M6 13a1.6 1.6 0 1 0 3.2 0a1.6 1.6 0 1 0 -3.2 0Z M14.8 13a1.6 1.6 0 1 0 3.2 0a1.6 1.6 0 1 0 -3.2 0Z M10 17h4l-2 2Z\"/></svg> Kot</button><button id=\"cross\">× Wyklucz</button></div><div class=\"footer\"><button id=\"hint\">Podpowiedź</button><button id=\"clear\">Wyczyść</button><button id=\"reset\">Nowa gra</button></div></main><dialog id=\"rules\"><h2>Zasady</h2><ol><li>Umieść po jednym kocie w każdym wierszu, kolumnie i kolorowym obszarze.</li><li>Koty nie mogą się stykać, również po przekątnej.</li><li>Wybierz kota lub znak ×, a następnie kliknij pole. Ponowne kliknięcie usuwa oznaczenie.</li><li>Każda plansza ma jedno rozwiązanie.</li></ol><button id=\"dismiss\">Wróć</button></dialog><script>(()=>{\"use strict\";const q=s=>document.querySelector(s);q(\"#info\").onclick=()=>q(\"#rules\").showModal();q(\"#dismiss\").onclick=()=>q(\"#rules\").close();const MODE='catoku',puzzles={\"4\": [{\"g\": [0, 0, 1, 1, 0, 1, 1, 1, 2, 2, 3, 3, 2, 3, 3, 3], \"s\": [1, 7, 8, 14]}, {\"g\": [1, 1, 0, 0, 1, 1, 0, 0, 3, 3, 3, 2, 3, 3, 3, 2], \"s\": [2, 4, 11, 13]}, {\"g\": [1, 0, 0, 0, 1, 1, 0, 2, 3, 3, 2, 2, 3, 3, 2, 2], \"s\": [2, 4, 11, 13]}, {\"g\": [0, 0, 0, 1, 2, 2, 0, 1, 2, 2, 2, 1, 2, 2, 3, 3], \"s\": [1, 7, 8, 14]}, {\"g\": [1, 1, 0, 0, 1, 2, 2, 2, 1, 2, 2, 2, 3, 3, 3, 2], \"s\": [2, 4, 11, 13]}], \"5\": [{\"g\": [1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 3, 2, 4, 0, 3, 3, 3, 4, 3, 3, 3, 3, 4], \"s\": [2, 5, 13, 16, 24]}, {\"g\": [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 1, 3, 3, 4, 4, 1, 3, 3, 4, 4], \"s\": [2, 5, 14, 16, 23]}, {\"g\": [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 3, 0, 2, 1, 1, 3, 3, 4, 4, 4, 3, 4, 4, 4, 4], \"s\": [1, 9, 12, 15, 23]}, {\"g\": [0, 0, 0, 1, 1, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 3, 1, 1, 2, 2, 2, 2, 4], \"s\": [1, 8, 10, 17, 24]}, {\"g\": [2, 1, 1, 3, 0, 2, 1, 1, 3, 3, 2, 1, 1, 3, 3, 2, 3, 3, 3, 3, 4, 4, 3, 3, 3], \"s\": [4, 7, 10, 18, 21]}], \"6\": [{\"g\": [1, 0, 0, 0, 2, 2, 1, 1, 1, 2, 2, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3, 4, 4, 4, 3, 3, 4, 4, 4, 5], \"s\": [2, 6, 16, 19, 27, 35]}, {\"g\": [1, 1, 0, 0, 0, 2, 1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 4, 4, 4, 3, 2, 2, 4, 4, 5, 5, 5, 2, 4, 4, 5, 5, 2, 2], \"s\": [4, 7, 17, 21, 24, 32]}, {\"g\": [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 2, 2, 2, 1, 1, 3, 3, 3, 3, 3, 1, 5, 5, 3, 3, 3, 4, 5, 5, 3, 3, 3, 3], \"s\": [2, 10, 13, 21, 29, 30]}, {\"g\": [0, 0, 0, 0, 0, 1, 0, 2, 0, 1, 1, 1, 3, 2, 2, 2, 2, 1, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 5], \"s\": [2, 10, 13, 21, 24, 35]}, {\"g\": [0, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 3, 2, 2, 4, 4, 1, 3, 5, 5, 4, 4, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5], \"s\": [0, 8, 17, 21, 25, 34]}], \"7\": [{\"g\": [1, 1, 0, 2, 2, 2, 2, 1, 0, 0, 2, 2, 2, 2, 4, 4, 2, 2, 2, 2, 2, 4, 4, 2, 2, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 3, 5, 5, 5, 4, 4, 4, 3, 5, 5, 6], \"s\": [2, 7, 17, 26, 29, 39, 48]}, {\"g\": [1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 2, 2, 2, 4, 1, 1, 1, 2, 2, 2, 4, 4, 3, 1, 5, 2, 2, 4, 4, 4, 1, 5, 2, 2, 4, 4, 4, 4, 5, 5, 5, 4, 6, 6, 4, 5, 5, 5], \"s\": [6, 10, 19, 23, 28, 39, 43]}, {\"g\": [0, 0, 0, 0, 0, 1, 1, 3, 0, 0, 0, 0, 1, 1, 3, 3, 2, 4, 1, 1, 1, 3, 3, 3, 4, 4, 4, 1, 5, 5, 5, 4, 4, 4, 1, 5, 5, 5, 5, 5, 4, 4, 5, 5, 5, 5, 5, 5, 6], \"s\": [3, 12, 16, 21, 32, 36, 48]}, {\"g\": [5, 5, 5, 1, 1, 0, 0, 5, 5, 5, 1, 1, 1, 4, 2, 5, 1, 1, 1, 4, 4, 5, 5, 3, 1, 1, 4, 4, 5, 5, 3, 1, 1, 4, 4, 5, 5, 5, 4, 4, 4, 4, 5, 5, 5, 6, 4, 4, 4], \"s\": [6, 11, 14, 23, 33, 36, 45]}, {\"g\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 3, 3, 3, 3, 1, 2, 2, 2, 3, 3, 3, 5, 5, 5, 3, 3, 3, 3, 5, 5, 5, 5, 5, 4, 4, 5, 5, 5, 5, 5, 4, 4, 5, 5, 5, 5, 5, 6, 6], \"s\": [3, 7, 16, 25, 34, 36, 47]}], \"8\": [{\"g\": [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 1, 1, 1, 2, 4, 3, 3, 3, 1, 6, 6, 2, 4, 3, 3, 3, 6, 6, 6, 2, 6, 3, 3, 5, 6, 6, 6, 6, 6, 3, 3, 3, 7, 7, 6, 6, 6, 6, 3, 3], \"s\": [5, 9, 19, 30, 36, 47, 50, 56]}, {\"g\": [2, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 2, 0, 1, 1, 6, 2, 2, 2, 2, 2, 2, 2, 6, 3, 3, 4, 2, 2, 2, 2, 6, 6, 6, 4, 2, 2, 2, 2, 6, 6, 6, 4, 2, 2, 5, 2, 6, 6, 6, 6, 2, 2, 2, 2, 7, 6, 6, 6, 6, 2, 2, 2], \"s\": [5, 15, 20, 25, 35, 46, 50, 56]}, {\"g\": [0, 1, 1, 3, 3, 2, 2, 2, 1, 1, 1, 3, 3, 2, 2, 2, 1, 1, 3, 3, 3, 2, 2, 2, 4, 3, 3, 3, 3, 5, 5, 5, 4, 4, 3, 3, 3, 5, 5, 5, 4, 3, 3, 6, 6, 6, 5, 5, 3, 3, 3, 3, 6, 6, 6, 6, 3, 3, 3, 3, 6, 6, 6, 7], \"s\": [0, 10, 21, 27, 33, 46, 52, 63]}, {\"g\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 2, 2, 1, 1, 0, 2, 2, 2, 2, 2, 1, 1, 4, 3, 2, 2, 2, 2, 4, 4, 4, 3, 3, 2, 2, 2, 4, 4, 4, 3, 6, 5, 5, 5, 4, 4, 4, 4, 6, 5, 5, 5, 4, 4, 4, 4, 6, 6, 6, 7], \"s\": [2, 8, 21, 27, 33, 46, 52, 63]}, {\"g\": [0, 0, 0, 0, 4, 1, 1, 1, 0, 0, 0, 0, 4, 1, 1, 1, 0, 0, 0, 2, 4, 4, 1, 1, 3, 0, 4, 2, 4, 4, 4, 4, 3, 5, 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 6, 4, 7, 5, 5, 4, 4, 4, 4, 7, 7], \"s\": [2, 14, 19, 24, 36, 41, 53, 63]}]},colors=['#c5a6ff','#82c8f2','#f7a8be','#f5d477','#8ddda5','#ffb17a','#a5d9d4','#d6b49b'];let n=5,k=0,a=[],tool=1;function pu(){return puzzles[n][k]}function start(size=n,index=0){n=size;k=index;a=Array(n*n).fill(0);render();send()}function conflicts(){let cats=a.map((v,i)=>v===1?i:-1).filter(i=>i>=0),bad=new Set();for(let i of cats)for(let j of cats)if(i!==j){let r=Math.floor(i/n),s=Math.floor(j/n),c=i%n,d=j%n;if(r===s||c===d||pu().g[i]===pu().g[j]||(Math.abs(r-s)<=1&&Math.abs(c-d)<=1)){bad.add(i);bad.add(j)}}return bad}function render(){q('#sizes').innerHTML=Object.keys(puzzles).map(v=>`<button data-size=\"${v}\" aria-pressed=\"${+v===n}\">${v}×${v}</button>`).join('');q('#board').style.gridTemplateColumns=`repeat(${n},1fr)`;let bad=conflicts();q('#board').innerHTML=a.map((v,i)=>`<button data-i=\"${i}\" class=\"cell ${bad.has(i)?'bad':''}\" style=\"background:${colors[pu().g[i]]};color:#202027\" aria-label=\"Wiersz ${Math.floor(i/n)+1}, kolumna ${i%n+1}, ${v===1?'kot':v===2?'wykluczone':'puste'}\">${v===1?'<svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><path fill-rule=\"evenodd\" d=\"M3 3L9 7Q12 6 15 7L21 3L22 12Q23 19 18 21Q12 24 6 21Q1 19 2 12Z M6 13a1.6 1.6 0 1 0 3.2 0a1.6 1.6 0 1 0 -3.2 0Z M14.8 13a1.6 1.6 0 1 0 3.2 0a1.6 1.6 0 1 0 -3.2 0Z M10 17h4l-2 2Z\"/></svg>':v===2?'×':''}</button>`).join('');let count=a.filter(v=>v===1).length;q('#status').textContent=bad.size?'Koty naruszają zasady':count===n?'Brawo! Łamigłówka rozwiązana.':`Koty: ${count} / ${n} · Plansza ${k+1} / ${puzzles[n].length}`;q('#status').classList.toggle('win',count===n&&!bad.size);q('#cat').setAttribute('aria-pressed',String(tool===1));q('#cross').setAttribute('aria-pressed',String(tool===2))}function state(){return {n,k,a,tool}}function restore(s){if(s&&puzzles[s.n]?.[s.k]&&Array.isArray(s.a)&&s.a.length===s.n*s.n&&s.a.every(v=>[0,1,2].includes(v))){n=s.n;k=s.k;a=s.a.slice();tool=s.tool===2?2:1}else a=Array(n*n).fill(0);render()}q('#sizes').onclick=e=>{let b=e.target.closest('[data-size]');if(b)start(+b.dataset.size,0)};q('#board').onclick=e=>{let b=e.target.closest('[data-i]');if(b){let i=+b.dataset.i;a[i]=a[i]===tool?0:tool;render();send()}};q('#cat').onclick=()=>{tool=1;render();send()};q('#cross').onclick=()=>{tool=2;render();send()};q('#reset').onclick=()=>start(n,(k+1)%puzzles[n].length);q('#clear').onclick=()=>start(n,k);q('#hint').onclick=()=>{let target=pu().s.find(i=>a[i]!==1);if(target!==undefined){a[target]=1;render();send()}};restore(null);function send(){if(parent!==window)parent.postMessage({type:'mw-v42-game-state',mode:MODE,state:state()},'*')}window.addEventListener('message',e=>{if(e.source!==parent)return;let m=e.data;if(m?.type==='mw-v21-div-restore')restore(m.state);if(m?.type==='mw-v21-div-export'){restore(m.state);try{const c=document.createElement('canvas');c.width=900;c.height=1000;const x=c.getContext('2d');x.fillStyle='#000';x.fillRect(0,0,900,1000);x.font='bold 44px Arial';x.textAlign='center';x.fillStyle='#fff';x.fillText(q('h1').textContent,450,65);let a=[...q('#board').children],n=Math.sqrt(a.length),d=760/n;a.forEach((b,i)=>{x.fillStyle=getComputedStyle(b).backgroundColor;x.fillRect(70+i%n*d,120+Math.floor(i/n)*d,d-3,d-3);x.fillStyle=getComputedStyle(b).color;x.font='bold '+Math.min(60,d*.48)+'px Arial';x.textBaseline='middle';if(b.querySelector('svg')){x.save();x.translate(70+i%n*d+d*.09,120+Math.floor(i/n)*d+d*.09);x.scale(d*.82/24,d*.82/24);x.fill(new Path2D('M3 3L9 7Q12 6 15 7L21 3L22 12Q23 19 18 21Q12 24 6 21Q1 19 2 12Z M6 13a1.6 1.6 0 1 0 3.2 0a1.6 1.6 0 1 0 -3.2 0Z M14.8 13a1.6 1.6 0 1 0 3.2 0a1.6 1.6 0 1 0 -3.2 0Z M10 17h4l-2 2Z'),'evenodd');x.restore()}else x.fillText(b.textContent,70+(i%n+.5)*d,120+(Math.floor(i/n)+.5)*d)});x.fillStyle='#fff';x.font='24px Arial';x.fillText(q('#status').textContent,450,940);parent.postMessage({type:'mw-v21-div-image',id:m.id,png:c.toDataURL('image/png')},'*')}catch(err){parent.postMessage({type:'mw-v21-div-image',id:m.id,error:String(err)},'*')}}});})();</script></body></html>"
},
{
"id": "reverse-times",
"action": "mw-v43-reverse-times",
"title": "Odwrócona tabliczka mnożenia",
"label": "Odwrócona tabliczka",
"icon": "<span class=\"solid-icon\"><svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.7\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\"/><path d=\"M3 8.5h18M8.5 3v18\"/><path d=\"M11.8 11.8l2.8 2.8M14.6 11.8l-2.8 2.8\"/><path d=\"M16.9 17.2h2.2M18 16.1v2.2\"/></svg></span>",
"source": "<!doctype html><html lang=\"pl\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>\n*{box-sizing:border-box}html,body{margin:0;background:#000;color:#fff;font:600 16px Arial,sans-serif;color-scheme:dark}main{height:100dvh;min-height:100dvh;display:flex;flex-direction:column;gap:8px;padding:10px 12px;overflow:auto}header{display:grid;grid-template-columns:1fr auto 1fr;align-items:center;min-height:44px;gap:8px}h1{grid-column:2;margin:0;text-align:center;font-size:clamp(20px,3.8vh,36px)}button{background:#292929;color:white;border:1px solid #555;border-radius:8px;padding:9px 14px;font:inherit;cursor:pointer;touch-action:manipulation}button:disabled{opacity:.4;cursor:default}button:hover:not(:disabled){background:#383838}button:focus-visible{outline:2px solid white;outline-offset:2px}#info{grid-column:3;justify-self:end;background:white;color:black;border:1px solid white;height:36px;padding:6px 15px;font:800 16px/1 Arial,sans-serif}.challenge{display:flex;align-items:center;justify-content:center;gap:clamp(10px,4vw,60px)}.prompt{text-align:center}.prompt small,.stat small{display:block;color:#b8b8b8;font-size:14px}.prompt b{display:block;font-size:clamp(42px,8vh,80px);line-height:1;color:#c5a6ff}.stat{text-align:center;min-width:70px}.stat b{font-size:clamp(22px,4vh,36px);display:block}.area{flex:1;min-height:270px;display:flex;justify-content:center;align-items:center;container-type:size}.board{display:grid;grid-template-columns:repeat(11,minmax(0,1fr));grid-template-rows:repeat(11,minmax(0,1fr));width:min(100%,160cqh,1050px);height:min(100%,70vw);min-height:260px;gap:3px;container-type:inline-size}.cell,.axis{min-height:0;min-width:0;display:grid;place-items:center;line-height:1;padding:0;border-radius:5px;font-size:clamp(10px,2.1cqw,25px);font-weight:750}.axis{background:#26212e;color:#c5a6ff}.cell{border:1px solid #49424f;background:#17171b;color:white;white-space:nowrap}.cell:hover:not(:disabled){border-color:#c5a6ff;background:#282331}.cell:disabled{opacity:1;cursor:default}.cell.wrong{background:#32151c;border-color:#ff758b;color:#ff758b}.cell.correct{background:#142c1e;color:#7be4a7;border:2px solid #7be4a7}.status{margin:0;min-height:23px;text-align:center;font-size:clamp(14px,2.8vh,23px);color:#ddd}.footer{display:flex;justify-content:center;gap:10px;flex-wrap:wrap}.footer button{min-width:120px}.footer #next:not(:disabled){border-color:#aaa}dialog{background:#101015;border:1px solid #666;border-radius:12px;color:#fff;width:min(90%,660px);padding:22px;line-height:1.55}dialog::backdrop{background:#000c}dialog h2{color:#c5a6ff}dialog button{display:block;margin-left:auto}@media(max-width:520px){header{grid-template-columns:1fr auto}h1{grid-column:1;text-align:left}#info{grid-column:2}.board{gap:2px;height:min(100%,92vw)}.cell,.axis{font-size:clamp(8px,2.25cqw,16px)}.challenge{gap:12px}}\n</style></head><body><main id=\"game\"><header><h1>Odwrócona tabliczka</h1><button id=\"info\">Zasady</button></header><div class=\"challenge\"><div class=\"stat\"><small>Uzupełnione pola</small><b id=\"score\">0 / 100</b></div><div class=\"prompt\"><small>Znajdź iloczyn</small><b id=\"target\"></b></div><div class=\"stat\"><small>Błędy</small><b id=\"errors\">0</b></div></div><div class=\"area\"><div class=\"board\" id=\"board\" aria-label=\"Tabliczka mnożenia od 1 do 10\"></div></div><p class=\"status\" id=\"status\" role=\"status\" aria-live=\"polite\"></p><div class=\"footer\"><button id=\"correct\" disabled>Popraw</button><button id=\"reset\">Nowa gra</button></div></main><dialog id=\"rules\"><h2>Zasady</h2><ol><li>Na górze pojawia się wynik mnożenia.</li><li>Wybierz puste pole na przecięciu wiersza i kolumny, których iloczyn daje podany wynik.</li><li>Po kliknięciu pole pokaże iloczyn: zielony, jeśli odpowiedź jest poprawna, lub czerwony, jeśli jest błędna. Każde pole musisz odkryć samodzielnie. Zielone pola pozostają na planszy.</li><li>Jeśli się pomylisz, wybierz inne pole lub naciśnij „Popraw”, aby ukryć błędne odpowiedzi. Możesz też kliknąć ponownie czerwone pole. Licznik błędów pozostaje bez zmian. Ten sam wynik jest zadawany ponownie, aż odkryjesz wszystkie pola z tym iloczynem. Następnie pojawia się nowy wynik. Gra kończy się po uzupełnieniu wszystkich 100 pól.</li></ol><button id=\"dismiss\">Wróć</button></dialog><script>\n(()=>{'use strict';const q=s=>document.querySelector(s),MODE='reverse-times',products=[...new Set(Array.from({length:100},(_,i)=>(Math.floor(i/10)+1)*(i%10+1)))];let target=35,score=0,errors=0,solved=new Set(),wrong=[];\nfunction pair(i){return [Math.floor(i/10)+1,i%10+1]}\nfunction value(i){const [a,b]=pair(i);return a*b}\nfunction remaining(v){return Array.from({length:100},(_,i)=>i).some(i=>!solved.has(i)&&value(i)===v)}\nfunction nextTarget(){const pool=products.filter(remaining);target=pool.length?pool[Math.floor(Math.random()*pool.length)]:null;wrong=[]}\nfunction render(message=''){score=solved.size;q('#target').textContent=target===null?'✓':target;q('#score').textContent=score+' / 100';q('#errors').textContent=errors;let out='';for(let r=0;r<=10;r++)for(let c=0;c<=10;c++){if(!r||!c)out+=`<div class=\"axis\">${r||c||'×'}</div>`;else{let i=(r-1)*10+c-1,cls=solved.has(i)?'correct':wrong.includes(i)?'wrong':'';out+=`<button class=\"cell ${cls}\" data-i=\"${i}\" aria-label=\"${r} razy ${c}${cls?', wynik '+value(i):''}\" ${solved.has(i)||target===null?'disabled':''}>${cls?value(i):''}</button>`}}q('#board').innerHTML=out;q('#correct').disabled=target===null||!wrong.length;q('#status').textContent=target===null?'Brawo! Wszystkie 100 pól uzupełnione.':message|| (wrong.length?'Spróbuj ponownie':'Wybierz pasujące, puste pole')}\nfunction state(){return {target,score:solved.size,errors,solved:[...solved],wrong}}\nfunction send(){if(parent!==window)parent.postMessage({type:'mw-v42-game-state',mode:MODE,state:state()},'*')}\nfunction restore(s){if(s&&typeof s==='object'){const valid=i=>Number.isInteger(i)&&i>=0&&i<100;solved=new Set(Array.isArray(s.solved)?s.solved.filter(valid):valid(s.selected)&&value(s.selected)===s.target?[s.selected]:[]);errors=Math.max(0,Number(s.errors)||0);target=products.includes(s.target)?s.target:35;if(!remaining(target))nextTarget();wrong=Array.isArray(s.wrong)&&target!==null?s.wrong.filter(i=>valid(i)&&!solved.has(i)&&value(i)!==target):[]}render()}\nq('#board').onclick=e=>{const b=e.target.closest('[data-i]');if(!b||target===null)return;const i=+b.dataset.i;if(solved.has(i))return;if(value(i)===target){solved.add(i);wrong=[];if(remaining(target)){render('Dobrze! Znajdź kolejne pole z tym wynikiem.')}else{nextTarget();render('Dobrze! Znajdź nowy wynik.')}}else if(wrong.includes(i)){wrong=wrong.filter(j=>j!==i);render()}else{wrong.push(i);errors++;render('Spróbuj ponownie')}send()};q('#correct').onclick=()=>{wrong=[];render();send()};q('#reset').onclick=()=>{solved.clear();score=errors=0;nextTarget();render();send()};q('#info').onclick=()=>q('#rules').showModal();q('#dismiss').onclick=()=>q('#rules').close();window.addEventListener('message',e=>{if(e.source!==parent)return;const m=e.data;if(m?.type==='mw-v21-div-restore')restore(m.state);if(m?.type==='mw-v21-div-export'){restore(m.state);try{const c=document.createElement('canvas');c.width=1320;c.height=1000;const x=c.getContext('2d');x.fillStyle='#000';x.fillRect(0,0,c.width,c.height);x.textAlign='center';x.textBaseline='middle';x.fillStyle='#fff';x.font='bold 38px Arial';x.fillText('Odwrócona tabliczka',660,40);x.fillStyle='#c5a6ff';x.font='bold 64px Arial';x.fillText(target===null?\"✓\":target,660,110);const cells=[...q('#board').children];cells.forEach((b,i)=>{const a=80+i%11*105,y=175+Math.floor(i/11)*65;x.fillStyle=getComputedStyle(b).backgroundColor;x.fillRect(a,y,102,62);x.fillStyle=getComputedStyle(b).color;x.font='bold 26px Arial';x.fillText(b.textContent,a+51,y+31)});x.fillStyle='#fff';x.font='24px Arial';x.fillText(q('#status').textContent,660,920);x.fillText(`Uzupełnione pola: ${score} / 100 · Błędy: ${errors}`,660,960);parent.postMessage({type:'mw-v21-div-image',id:m.id,png:c.toDataURL('image/png')},'*')}catch(err){parent.postMessage({type:'mw-v21-div-image',id:m.id,error:String(err)},'*')}}});render()})();</script></body></html>\n"
},
{
"id": "prime-snake",
"action": "mw-v50-prime-snake",
"title": "Snake – liczby pierwsze",
"label": "Snake",
"icon": "<span class=\"solid-icon\"><svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M4 20v-6h8V5h7v7\"/><circle cx=\"19\" cy=\"4\" r=\"2\" fill=\"currentColor\"/><circle cx=\"5\" cy=\"5\" r=\"1.5\"/></svg></span>",
"source": "<!doctype html><html lang=\"pl\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>*{box-sizing:border-box}html,body{margin:0;background:#000;color:#fff;color-scheme:dark;font:16px Arial,sans-serif}main{height:100dvh;min-height:360px;display:flex;flex-direction:column;gap:12px;padding:clamp(8px,1.3vw,20px);overflow:auto}header{display:grid;grid-template-columns:100px 1fr 100px;align-items:center;gap:8px}h1{grid-column:2;text-align:center;margin:0;font-size:clamp(22px,3vw,38px)}button{font:700 clamp(14px,1.5vw,20px) Arial;border:1px solid #555;border-radius:8px;background:#292929;color:white;padding:10px 15px;cursor:pointer;touch-action:manipulation}button:disabled{opacity:.42;cursor:default}button:focus-visible{outline:2px solid #c5a6ff;outline-offset:2px}#info{grid-column:3;background:white;color:black;border-color:white;padding:9px 10px}button:hover:not(:disabled){border-color:#ddd}.bar,.controls{display:flex;align-items:center;justify-content:center;gap:10px;flex-wrap:wrap}.stat{background:#121216;border:1px solid #38343e;padding:8px 18px;border-radius:9px;text-align:center;min-width:100px}.stat small{color:#bbb;display:block}.stat b{font-size:clamp(20px,3vh,32px);font-variant-numeric:tabular-nums}.status{text-align:center;min-height:24px;margin:0;font-size:clamp(15px,2.4vh,24px)}.status.good{color:#7be4a7}.status.bad{color:#ff758b}dialog{background:#101015;border:1px solid #666;color:white;border-radius:12px;width:min(90%,650px);padding:22px;line-height:1.55}dialog::backdrop{background:#000c}dialog h2{color:#c5a6ff}dialog button{display:block;margin-left:auto}@media(max-width:550px){header{grid-template-columns:1fr auto}h1{grid-column:1;text-align:left}#info{grid-column:2}.stat{min-width:75px;padding:6px 10px}main{gap:7px}}.area{flex:1;min-height:150px;display:flex;justify-content:center;align-items:center;container-type:size}canvas{display:block;width:min(100%,133.333cqh);height:auto;max-height:100%;aspect-ratio:4/3;border:1px solid #444;border-radius:8px;touch-action:none}select{font:inherit;background:#292929;color:white;border:1px solid #555;padding:8px;border-radius:7px}.controls button[data-dir]{min-width:52px;font-size:26px;padding:5px 15px}</style></head><body><main id=\"game\"><header><h1>Snake – liczby pierwsze</h1><button id=\"info\">Zasady</button></header><div class=\"bar\"><div class=\"stat\"><small>Punkty</small><b id=\"score\">0</b></div><div class=\"stat\"><small>Życia</small><b id=\"lives\">3</b></div><div class=\"stat\"><small>Rekord</small><b id=\"best\">0</b></div><label>Tempo <select id=\"speed\"><option value=\"650\">Wolne</option><option value=\"430\" selected>Normalne</option><option value=\"260\">Szybkie</option></select></label></div><div class=\"area\"><canvas id=\"board\" width=\"960\" height=\"720\" aria-label=\"Plansza Snake\"></canvas></div><p id=\"status\" class=\"status\" role=\"status\">Zbieraj liczby pierwsze.</p><div class=\"controls\"><button id=\"start\">Rozpocznij</button><button data-dir=\"left\" aria-label=\"W lewo\">←</button><button data-dir=\"up\" aria-label=\"W górę\">↑</button><button data-dir=\"down\" aria-label=\"W dół\">↓</button><button data-dir=\"right\" aria-label=\"W prawo\">→</button><button id=\"reset\">Nowa gra</button></div></main><dialog id=\"rules\"><h2>Zasady</h2><ol><li>Steruj wężem strzałkami, przyciskami lub gestami na planszy.</li><li>Zbieraj wyłącznie liczby pierwsze. Każda daje punkt i wydłuża węża.</li><li>Zebranie liczby złożonej lub 1 kosztuje jedno życie. Gra podaje wyjaśnienie.</li><li>Zderzenie ze ścianą lub własnym ciałem kończy grę.</li></ol><button id=\"dismiss\">Wróć</button></dialog><script>(()=>{'use strict';const q=s=>document.querySelector(s),W=16,H=12,C=60,MODE='prime-snake',dirs={left:[-1,0],right:[1,0],up:[0,-1],down:[0,1]},primes=Array.from({length:99},(_,i)=>i+2).filter(isPrime),other=Array.from({length:100},(_,i)=>i+1).filter(n=>!isPrime(n));let g,best=0,running=false,timer=null,queued=null,visible=true;const canvas=q('#board'),ctx=canvas.getContext('2d');function isPrime(n){if(n<2)return false;for(let i=2;i*i<=n;i++)if(n%i===0)return false;return true}function rand(a){return a[Math.floor(Math.random()*a.length)]}function fill(){let empty=[];for(let i=0;i<W*H;i++)if(!g.snake.includes(i)&&!g.food.some(f=>f.i===i))empty.push(i);while(g.food.length<6&&empty.length){let i=rand(empty);empty=empty.filter(x=>x!==i);const need=g.food.filter(f=>isPrime(f.n)).length<3, pool=need?primes:other;g.food.push({i,n:rand(pool)})}}function fresh(){pause();g={snake:[6*W+7,6*W+6,6*W+5],dir:'right',food:[],score:0,lives:3,over:false,won:false,speed:+q('#speed').value,started:false};queued=null;fill();render('Zbieraj liczby pierwsze.');send()}function state(){return {...g,best}}function send(){if(parent!==window)parent.postMessage({type:'mw-v42-game-state',mode:MODE,state:state()},'*')}function pause(){running=false;clearInterval(timer);timer=null;if(g)q('#start').textContent=g.started?'Wznów':'Rozpocznij'}function start(){if(!visible||g.over||running)return;g.started=true;running=true;q('#start').textContent='Pauza';timer=setInterval(tick,g.speed);render('Zbieraj liczby pierwsze.');send()}function direction(d){if(!dirs[d]||g.over)return;const [dx,dy]=dirs[g.dir],[nx,ny]=dirs[d];if(dx+nx===0&&dy+ny===0)return;queued=d;if(!running)start()}function tick(){if(!running)return;if(queued){g.dir=queued;queued=null}const [dx,dy]=dirs[g.dir],head=g.snake[0],x=head%W+dx,y=Math.floor(head/W)+dy;if(x<0||x>=W||y<0||y>=H)return end('Koniec gry — ściana.');const i=y*W+x,f=g.food.find(a=>a.i===i),grow=f&&isPrime(f.n);if((grow?g.snake:g.snake.slice(0,-1)).includes(i))return end('Koniec gry — zderzenie z wężem.');g.snake.unshift(i);if(!grow)g.snake.pop();let msg='Zbieraj liczby pierwsze.',cls='';if(f){g.food=g.food.filter(a=>a!==f);if(grow){g.score++;best=Math.max(best,g.score);msg=f.n+' — liczba pierwsza';cls='good'}else{g.lives--;let d=2;while(d*d<=f.n&&f.n%d)d++;msg=f.n===1?'1 nie jest liczbą pierwszą.':f.n+' = '+d+' · '+(f.n/d)+' — liczba złożona';cls='bad';if(!g.lives){end(msg+' · Koniec gry');return}}fill()}if(g.snake.length===W*H){g.won=true;return end('Brawo! Cała plansza uzupełniona.')}render(msg,cls);send()}function end(msg){g.over=true;pause();render(msg,g.won?'good':'bad');send()}function render(msg,cls=''){ctx.fillStyle='#080809';ctx.fillRect(0,0,960,720);ctx.strokeStyle='#24242a';ctx.lineWidth=1;for(let i=0;i<=W;i++){ctx.beginPath();ctx.moveTo(i*C+.5,0);ctx.lineTo(i*C+.5,720);ctx.stroke()}for(let i=0;i<=H;i++){ctx.beginPath();ctx.moveTo(0,i*C+.5);ctx.lineTo(960,i*C+.5);ctx.stroke()}for(const f of g.food){let x=f.i%W*C,y=Math.floor(f.i/W)*C;ctx.fillStyle='#28232f';ctx.fillRect(x+4,y+4,52,52);ctx.strokeStyle='#8c78ad';ctx.strokeRect(x+4,y+4,52,52);ctx.fillStyle='#fff';ctx.textAlign='center';ctx.textBaseline='middle';ctx.font='bold 30px Arial';ctx.fillText(f.n,x+30,y+31)}g.snake.forEach((i,k)=>{let x=i%W*C,y=Math.floor(i/W)*C;ctx.fillStyle=k?'#38885c':'#7be4a7';ctx.fillRect(x+3,y+3,54,54);if(!k){const [dx,dy]=dirs[g.dir];ctx.fillStyle='#10231a';ctx.beginPath();ctx.arc(x+30+dx*15-dy*9,y+30+dy*15+dx*9,4,0,Math.PI*2);ctx.arc(x+30+dx*15+dy*9,y+30+dy*15-dx*9,4,0,Math.PI*2);ctx.fill()}});q('#score').textContent=g.score;q('#lives').textContent=g.lives;q('#best').textContent=best;q('#start').disabled=g.over;if(msg!==undefined){q('#status').textContent=msg;q('#status').className='status '+cls}}function restore(s){pause();queued=null;if(s&&Array.isArray(s.snake)&&s.snake.length>=3&&new Set(s.snake).size===s.snake.length&&s.snake.every(i=>Number.isInteger(i)&&i>=0&&i<W*H)&&dirs[s.dir]&&Array.isArray(s.food)&&s.food.every(f=>Number.isInteger(f.i)&&f.i>=0&&f.i<W*H&&Number.isInteger(f.n)&&f.n>=1&&f.n<=100)){g={...s,speed:[650,430,260].includes(s.speed)?s.speed:430};best=Math.max(0,+s.best||0);q('#speed').value=g.speed;pause();render(g.over?'Koniec gry':'Gra zatrzymana. Wznów, aby grać dalej.')}else fresh()}q('#start').onclick=()=>{if(running){pause();render('Pauza');send()}else start()};q('#reset').onclick=fresh;q('#speed').onchange=()=>{const was=running;pause();g.speed=+q('#speed').value;if(was)start();send()};document.querySelectorAll('[data-dir]').forEach(b=>b.onclick=()=>direction(b.dataset.dir));window.addEventListener('keydown',e=>{if(q('#rules').open||e.target.tagName==='SELECT')return;const d={ArrowLeft:'left',ArrowRight:'right',ArrowUp:'up',ArrowDown:'down',a:'left',d:'right',w:'up',s:'down'}[e.key];if(d){e.preventDefault();direction(d)}else if(e.code==='Space'){e.preventDefault();q('#start').click()}});let pt=null;canvas.addEventListener('pointerdown',e=>{pt=[e.clientX,e.clientY];canvas.setPointerCapture(e.pointerId)});canvas.addEventListener('pointerup',e=>{if(!pt)return;let dx=e.clientX-pt[0],dy=e.clientY-pt[1];pt=null;if(Math.max(Math.abs(dx),Math.abs(dy))>12)direction(Math.abs(dx)>Math.abs(dy)?dx>0?'right':'left':dy>0?'down':'up')});q('#info').onclick=()=>{pause();render('Pauza');send();q('#rules').showModal()};q('#dismiss').onclick=()=>q('#rules').close();window.addEventListener('message',e=>{if(e.source!==parent)return;const m=e.data;if(m?.type==='mw-v21-div-restore')restore(m.state);if(m?.type==='mw-v33-game-visibility'){visible=m.visible;if(!visible){pause();render('Pauza');send()}}if(m?.type==='mw-v21-div-export'){restore(m.state);try{const c=document.createElement('canvas');c.width=1100;c.height=880;const x=c.getContext('2d');x.fillStyle='#000';x.fillRect(0,0,1100,880);x.fillStyle='#fff';x.textAlign='center';x.font='bold 36px Arial';x.fillText('Snake – liczby pierwsze',550,48);x.drawImage(canvas,70,80);x.font='24px Arial';x.fillText('Punkty: '+g.score+' · Życia: '+g.lives,550,850);parent.postMessage({type:'mw-v21-div-image',id:m.id,png:c.toDataURL()},'*')}catch(err){parent.postMessage({type:'mw-v21-div-image',id:m.id,error:String(err)},'*')}}});document.addEventListener('visibilitychange',()=>{if(document.hidden){pause();send()}});fresh()})();</script></body></html>"
},
{
"id": "matches",
"action": "mw-v50-matches",
"title": "Zapałki",
"label": "Zapałki",
"icon": "<span class=\"solid-icon\"><svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\"><path d=\"M5 19L16 8M9 21L20 10M3 12L11 4\"/><circle cx=\"17\" cy=\"7\" r=\"2\" fill=\"currentColor\"/><circle cx=\"21\" cy=\"9\" r=\"1.5\" fill=\"currentColor\"/><circle cx=\"12\" cy=\"3\" r=\"1.5\" fill=\"currentColor\"/></svg></span>",
"source": "<!doctype html><html lang=\"pl\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><style>*{box-sizing:border-box}html,body{margin:0;background:#000;color:#fff;color-scheme:dark;font:16px Arial,sans-serif}main{height:100dvh;min-height:360px;display:flex;flex-direction:column;gap:12px;padding:clamp(8px,1.3vw,20px);overflow:auto}header{display:grid;grid-template-columns:100px 1fr 100px;align-items:center;gap:8px}h1{grid-column:2;text-align:center;margin:0;font-size:clamp(22px,3vw,38px)}button{font:700 clamp(14px,1.5vw,20px) Arial;border:1px solid #555;border-radius:8px;background:#292929;color:white;padding:10px 15px;cursor:pointer;touch-action:manipulation}button:disabled{opacity:.42;cursor:default}button:focus-visible{outline:2px solid #c5a6ff;outline-offset:2px}#info{grid-column:3;background:white;color:black;border-color:white;padding:9px 10px}button:hover:not(:disabled){border-color:#ddd}.bar,.controls{display:flex;align-items:center;justify-content:center;gap:10px;flex-wrap:wrap}.stat{background:#121216;border:1px solid #38343e;padding:8px 18px;border-radius:9px;text-align:center;min-width:100px}.stat small{color:#bbb;display:block}.stat b{font-size:clamp(20px,3vh,32px);font-variant-numeric:tabular-nums}.status{text-align:center;min-height:24px;margin:0;font-size:clamp(15px,2.4vh,24px)}.status.good{color:#7be4a7}.status.bad{color:#ff758b}dialog{background:#101015;border:1px solid #666;color:white;border-radius:12px;width:min(90%,650px);padding:22px;line-height:1.55}dialog::backdrop{background:#000c}dialog h2{color:#c5a6ff}dialog button{display:block;margin-left:auto}@media(max-width:550px){header{grid-template-columns:1fr auto}h1{grid-column:1;text-align:left}#info{grid-column:2}.stat{min-width:75px;padding:6px 10px}main{gap:7px}}.area{flex:1;min-height:160px;display:grid;place-items:center;container-type:size}#board{width:min(100%,320cqh,1350px);max-height:100%;height:auto;overflow:visible}.slot{cursor:pointer;outline:none}.slot .hit{stroke:transparent;stroke-width:25}.slot:focus-visible .hit{stroke:#c5a6ff55}.slot .wood{stroke:#e6c18d;stroke-width:9;stroke-linecap:round}.slot .head{fill:#e36a62}.slot.empty .wood{stroke:#36333b;stroke-width:3;stroke-dasharray:3 7}.slot.empty .head{display:none}.slot.selected .wood{stroke:#7be4a7}.slot.selected .head{fill:#7be4a7}.slot.hint .wood{stroke:#c5a6ff;stroke-width:12}.slot.empty.hint .wood{stroke:#c5a6ff;stroke-width:5}.equal{stroke:#fff;stroke-width:8;stroke-linecap:round}</style></head><body><main id=\"game\"><header><h1>Zapałki</h1><button id=\"info\">Zasady</button></header><div class=\"bar\"><div class=\"stat\"><small>Zadanie</small><b id=\"index\"></b></div><div class=\"stat\"><small>Rozwiązane</small><b id=\"score\"></b></div><div class=\"stat\"><small>Przenieś</small><b>1 zapałkę</b></div></div><div class=\"area\"><svg id=\"board\" viewBox=\"0 0 640 200\" role=\"group\" aria-label=\"Równanie z zapałek\"></svg></div><p class=\"status\" id=\"status\" role=\"status\"></p><div class=\"controls\"><button id=\"undo\">Cofnij</button><button id=\"hint\">Podpowiedź</button><button id=\"solution\">Pokaż rozwiązanie</button><button id=\"next\">Następne</button><button id=\"reset\">Nowa gra</button></div></main><dialog id=\"rules\"><h2>Zasady</h2><ol><li>Wybierz jedną zapałkę, a następnie wolne miejsce.</li><li>Przenieś dokładnie jedną zapałkę, aby otrzymać poprawne równanie. Znak równości pozostaje nieruchomy.</li><li>Po błędzie użyj Cofnij. Możesz skorzystać z podpowiedzi lub zobaczyć rozwiązanie.</li><li>Rozwiązanie pokazane przez grę nie zalicza zadania.</li></ol><button id=\"dismiss\">Wróć</button></dialog><script>(()=>{'use strict';const q=s=>document.querySelector(s),MODE='matches',D=[63, 6, 91, 79, 102, 109, 125, 7, 127, 111],P=[[[102, 1, 102, 125], [102, 1, 102, 63]], [[63, 1, 102, 91], [125, 1, 102, 91]], [[111, 1, 6, 102], [79, 3, 6, 102]], [[109, 1, 127, 7], [111, 1, 127, 6]], [[6, 3, 91, 127], [7, 3, 91, 111]], [[102, 1, 127, 102], [102, 3, 63, 102]], [[7, 3, 63, 6], [7, 1, 63, 7]], [[7, 3, 127, 109], [6, 3, 127, 111]], [[127, 1, 6, 91], [111, 1, 7, 91]], [[63, 1, 6, 127], [111, 1, 6, 127]], [[79, 3, 102, 109], [111, 1, 102, 109]], [[111, 1, 111, 125], [111, 1, 111, 63]], [[6, 3, 111, 109], [6, 3, 109, 125]], [[91, 3, 6, 127], [91, 3, 7, 111]], [[63, 1, 109, 6], [125, 1, 109, 6]], [[111, 1, 102, 91], [125, 1, 102, 91]], [[79, 1, 127, 63], [111, 1, 111, 63]], [[127, 3, 79, 109], [125, 3, 79, 111]], [[79, 1, 111, 102], [111, 1, 109, 102]], [[79, 3, 7, 91], [111, 1, 7, 91]], [[7, 3, 6, 109], [7, 1, 6, 125]], [[7, 1, 6, 127], [7, 1, 7, 63]], [[63, 1, 102, 109], [111, 1, 102, 109]], [[7, 1, 91, 102], [7, 1, 79, 102]], [[111, 3, 7, 6], [127, 1, 7, 6]], [[111, 3, 125, 6], [111, 1, 127, 6]], [[102, 3, 111, 102], [102, 3, 63, 102]], [[111, 3, 63, 79], [111, 1, 63, 111]], [[125, 1, 127, 109], [125, 1, 63, 125]], [[63, 3, 127, 79], [63, 3, 111, 111]], [[102, 1, 6, 111], [102, 3, 6, 109]], [[125, 3, 6, 127], [127, 3, 6, 111]], [[127, 1, 111, 111], [63, 3, 111, 111]], [[125, 1, 109, 102], [111, 1, 109, 102]], [[127, 3, 79, 111], [63, 3, 111, 111]], [[91, 3, 7, 63], [91, 3, 7, 111]], [[127, 1, 79, 111], [125, 3, 79, 111]], [[63, 3, 91, 125], [127, 1, 91, 125]], [[109, 1, 125, 102], [111, 1, 109, 102]], [[109, 3, 102, 7], [79, 3, 102, 7]]],N=P.length,SEG=[[16,16,76,16],[82,24,82,85],[82,103,82,164],[16,172,76,172],[10,103,10,164],[10,24,10,85],[16,94,76,94]],OP=[[12,94,70,94],[41,65,41,123]],OFF=[32,170,290,510];let idx=0,solved=[],masks=P[0][0].slice(),selected=null,used=false,revealed=false,hint=false;function equation(m){const [a,o,b,c]=m;return D.includes(a)&&D.includes(b)&&D.includes(c)&&(o===1||o===3)&&(o===3?D.indexOf(a)+D.indexOf(b):D.indexOf(a)-D.indexOf(b))===D.indexOf(c)}function draw(msg,cls=''){q('#index').textContent=(idx+1)+' / '+N;q('#score').textContent=solved.length+' / '+N;let out='<line class=\"equal\" x1=\"426\" y1=\"82\" x2=\"478\" y2=\"82\"/><line class=\"equal\" x1=\"426\" y1=\"106\" x2=\"478\" y2=\"106\"/>';for(let i=0;i<4;i++){const segments=i===1?OP:SEG;segments.forEach(([a,b,c,d],j)=>{a+=OFF[i];c+=OFF[i];const active=!!(masks[i]&(1<<j)),sel=selected?.[0]===i&&selected?.[1]===j,hi=hint&&((P[idx][0][i]^P[idx][1][i])&(1<<j));out+=`<g class=\"slot ${active?'':'empty'} ${sel?'selected':''} ${hi?'hint':''}\" data-i=\"${i}\" data-j=\"${j}\" tabindex=\"${used?-1:0}\" role=\"button\" aria-label=\"${active?'Zapałka':'Wolne miejsce'} ${i+1}, ${j+1}\"><line class=\"hit\" x1=\"${a}\" y1=\"${b}\" x2=\"${c}\" y2=\"${d}\"/><line class=\"wood\" x1=\"${a}\" y1=\"${b}\" x2=\"${c}\" y2=\"${d}\"/><circle class=\"head\" cx=\"${a}\" cy=\"${b}\" r=\"5.4\"/></g>`})}q('#board').innerHTML=out;q('#undo').disabled=!used&&!selected;q('#hint').disabled=used;q('#solution').disabled=used;if(msg!==undefined){q('#status').textContent=msg;q('#status').className='status '+cls}}function click(i,j){if(used)return;const active=masks[i]&(1<<j);if(active){selected=selected?.[0]===i&&selected?.[1]===j?null:[i,j];draw(selected?'Wybierz wolne miejsce dla zapałki.':'Wybierz zapałkę.');return}if(!selected){draw('Najpierw wybierz zapałkę.');return}const [a,b]=selected;masks[a]^=1<<b;masks[i]|=1<<j;selected=null;used=true;hint=false;if(equation(masks)){if(!solved.includes(idx))solved.push(idx);draw('Poprawne równanie!','good')}else draw('Równanie jest niepoprawne. Cofnij i spróbuj ponownie.','bad');send()}function load(i){idx=(i+N)%N;masks=P[idx][0].slice();selected=null;used=false;revealed=false;hint=false;draw('Przenieś jedną zapałkę, aby równanie było prawdziwe.');send()}function state(){return{idx,solved,masks,used,revealed}}function send(){if(parent!==window)parent.postMessage({type:'mw-v42-game-state',mode:MODE,state:state()},'*')}function restore(s){if(s&&Number.isInteger(s.idx)&&s.idx>=0&&s.idx<N&&Array.isArray(s.masks)&&s.masks.length===4&&s.masks.every((v,i)=>Number.isInteger(v)&&v>=0&&v<=(i===1?3:127))){idx=s.idx;masks=s.masks.slice();solved=Array.isArray(s.solved)?[...new Set(s.solved.filter(i=>Number.isInteger(i)&&i>=0&&i<N))]:[];used=!!s.used;revealed=!!s.revealed;selected=null;hint=false;draw(used?(revealed?'Rozwiązanie':equation(masks)?'Poprawne równanie!':'Cofnij i spróbuj ponownie.'):'Przenieś jedną zapałkę.',used?(equation(masks)?'good':'bad'):'')}else load(0)}q('#board').addEventListener('click',e=>{const el=e.target.closest('[data-i]');if(el)click(+el.dataset.i,+el.dataset.j)});q('#board').addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();const el=e.target.closest('[data-i]');if(el)click(+el.dataset.i,+el.dataset.j)}});q('#undo').onclick=()=>{masks=P[idx][0].slice();used=false;selected=null;revealed=false;hint=false;draw('Spróbuj ponownie.');send()};q('#hint').onclick=()=>{hint=!hint;draw(hint?'Fioletowe oznaczenie pokazuje miejsce przeniesienia.':'Przenieś jedną zapałkę.')};q('#solution').onclick=()=>{masks=P[idx][1].slice();used=true;revealed=true;selected=null;hint=false;draw('Rozwiązanie — zadanie nie jest zaliczone.','good');send()};q('#next').onclick=()=>load(idx+1);q('#reset').onclick=()=>{solved=[];load(0)};q('#info').onclick=()=>q('#rules').showModal();q('#dismiss').onclick=()=>q('#rules').close();window.addEventListener('message',e=>{if(e.source!==parent)return;const m=e.data;if(m?.type==='mw-v21-div-restore')restore(m.state);if(m?.type==='mw-v21-div-export'){restore(m.state);try{const c=document.createElement('canvas');c.width=1280;c.height=650;const x=c.getContext('2d');x.fillStyle='#000';x.fillRect(0,0,c.width,c.height);x.fillStyle='#fff';x.textAlign='center';x.font='bold 40px Arial';x.fillText('Zapałki',640,65);x.save();x.translate(0,130);x.scale(2,2);x.lineCap='round';for(let i=0;i<4;i++)(i===1?OP:SEG).forEach(([a,b,c,d],j)=>{if(!(masks[i]&(1<<j)))return;x.strokeStyle='#e6c18d';x.lineWidth=9;x.beginPath();x.moveTo(a+OFF[i],b);x.lineTo(c+OFF[i],d);x.stroke();x.fillStyle='#e36a62';x.beginPath();x.arc(a+OFF[i],b,5.4,0,Math.PI*2);x.fill()});x.strokeStyle='#fff';x.lineWidth=8;for(let y of [82,106]){x.beginPath();x.moveTo(426,y);x.lineTo(478,y);x.stroke()}x.restore();x.fillStyle='#fff';x.font='25px Arial';x.fillText(q('#status').textContent,640,600);parent.postMessage({type:'mw-v21-div-image',id:m.id,png:c.toDataURL()},'*')}catch(err){parent.postMessage({type:'mw-v21-div-image',id:m.id,error:String(err)},'*')}}});load(0)})();</script></body></html>"
}
]
}
Brak komentarzy:
Prześlij komentarz