vimalk78's picture
feat(crossword): generated crosswords with clues
486eff6
import{r as m,a as T,R as _}from"./vendor-nf7bT_Uh.js";(function(){const a=document.createElement("link").relList;if(a&&a.supports&&a.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))l(t);new MutationObserver(t=>{for(const s of t)if(s.type==="childList")for(const i of s.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&l(i)}).observe(document,{childList:!0,subtree:!0});function o(t){const s={};return t.integrity&&(s.integrity=t.integrity),t.referrerPolicy&&(s.referrerPolicy=t.referrerPolicy),t.crossOrigin==="use-credentials"?s.credentials="include":t.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function l(t){if(t.ep)return;t.ep=!0;const s=o(t);fetch(t.href,s)}})();var P={exports:{}},b={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var $=m,O=Symbol.for("react.element"),L=Symbol.for("react.fragment"),A=Object.prototype.hasOwnProperty,F=$.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,D={key:!0,ref:!0,__self:!0,__source:!0};function k(n,a,o){var l,t={},s=null,i=null;o!==void 0&&(s=""+o),a.key!==void 0&&(s=""+a.key),a.ref!==void 0&&(i=a.ref);for(l in a)A.call(a,l)&&!D.hasOwnProperty(l)&&(t[l]=a[l]);if(n&&n.defaultProps)for(l in a=n.defaultProps,a)t[l]===void 0&&(t[l]=a[l]);return{$$typeof:O,type:n,key:s,ref:i,props:t,_owner:F.current}}b.Fragment=L;b.jsx=k;b.jsxs=k;P.exports=b;var e=P.exports,C={},S=T;C.createRoot=S.createRoot,C.hydrateRoot=S.hydrateRoot;const G=({onTopicsChange:n,availableTopics:a=[],selectedTopics:o=[],customSentence:l="",onSentenceChange:t,multiTheme:s=!0,onMultiThemeChange:i})=>{const g=c=>{const y=o.includes(c)?o.filter(p=>p!==c):[...o,c];n(y)};return e.jsxs("div",{className:"topic-selector",children:[e.jsx("h3",{children:"Select Topics"}),e.jsx("div",{className:"topic-buttons",children:a.map(c=>e.jsx("button",{className:`topic-btn ${o.includes(c.name)?"selected":""}`,onClick:()=>g(c.name),children:c.name},c.id))}),e.jsxs("div",{className:"sentence-input-container",children:[e.jsx("label",{htmlFor:"custom-sentence",className:"sentence-label",children:"Custom Sentence (optional)"}),e.jsx("textarea",{id:"custom-sentence",className:"sentence-input",value:l,onChange:c=>t&&t(c.target.value),placeholder:"Enter a sentence to influence word selection...",rows:"3",maxLength:"200"}),e.jsxs("div",{className:"sentence-info",children:[e.jsxs("span",{className:"char-count",children:[l.length,"/200 characters"]}),l&&e.jsx("button",{type:"button",className:"clear-sentence-btn",onClick:()=>t&&t(""),title:"Clear sentence",children:"Clear"})]})]}),e.jsxs("div",{className:"multi-theme-toggle-container",children:[e.jsxs("label",{className:"multi-theme-toggle",children:[e.jsx("input",{type:"checkbox",checked:s,onChange:c=>i&&i(c.target.checked),className:"multi-theme-checkbox"}),e.jsx("span",{className:"multi-theme-label",children:"🎯 Use Multi-Theme Processing"})]}),e.jsx("p",{className:"multi-theme-description",children:s?"AI will process each theme separately and balance results":"AI will blend all themes into a single concept"})]}),e.jsxs("p",{className:"selected-count",children:[o.length," topic",o.length!==1?"s":""," selected"]})]})},B=({grid:n,clues:a,showSolution:o,onCellChange:l})=>{const[t,s]=m.useState({}),i=(d,r,u)=>{const h=`${d}-${r}`,x={...t,[h]:u.toUpperCase()};s(x),l&&l(d,r,u)},g=(d,r)=>{if(o&&!c(d,r))return n[d][r];const u=`${d}-${r}`;return t[u]||""},c=(d,r)=>n[d][r]===".",y=(d,r)=>{if(!a)return null;const u=a.find(h=>h.position.row===d&&h.position.col===r);return u?u.number:null};if(!n||n.length===0)return e.jsx("div",{className:"puzzle-grid",children:"No puzzle loaded"});const p=n.length,f=n[0]?n[0].length:0;return e.jsx("div",{className:"puzzle-container",children:e.jsx("div",{className:"puzzle-grid",style:{gridTemplateColumns:`repeat(${f}, 35px)`,gridTemplateRows:`repeat(${p}, 35px)`},children:n.map((d,r)=>d.map((u,h)=>{const x=y(r,h);return c(r,h)?e.jsx("div",{className:"grid-cell empty-cell",style:{visibility:"hidden"}},`${r}-${h}`):e.jsxs("div",{className:"grid-cell white-cell",children:[x&&e.jsx("span",{className:"cell-number",children:x}),e.jsx("input",{type:"text",maxLength:"1",value:g(r,h),onChange:j=>i(r,h,j.target.value),className:`cell-input ${o?"solution-text":""}`,disabled:o})]},`${r}-${h}`)}))})})},M=({clues:n=[]})=>{const a=n.filter(t=>t.direction==="across"),o=n.filter(t=>t.direction==="down"),l=({title:t,clueList:s})=>e.jsxs("div",{className:"clue-section",children:[e.jsx("h4",{children:t}),e.jsx("ol",{children:s.map(i=>e.jsxs("li",{className:"clue-item",children:[e.jsx("span",{className:"clue-number",children:i.number}),e.jsx("span",{className:"clue-text",children:i.text})]},`${i.number}-${i.direction}`))})]});return e.jsxs("div",{className:"clue-list",children:[e.jsx(l,{title:"Across",clueList:a}),e.jsx(l,{title:"Down",clueList:o})]})},U=({message:n="Generating puzzle..."})=>e.jsxs("div",{className:"loading-spinner",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{className:"loading-message",children:n})]}),J=()=>{const[n,a]=m.useState(null),[o,l]=m.useState(!1),[t,s]=m.useState(null),[i,g]=m.useState([]),c="",y=m.useCallback(async()=>{try{l(!0);const r=await fetch(`${c}/api/topics`);if(!r.ok)throw new Error("Failed to fetch topics");const u=await r.json();g(u)}catch(r){s(r.message)}finally{l(!1)}},[c]),p=m.useCallback(async(r,u="medium",h=!1,x="",z=!0)=>{try{l(!0),s(null);const j=await fetch(`${c}/api/generate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({topics:r,difficulty:u,useAI:h,...x&&{customSentence:x},multiTheme:z})});if(!j.ok){const w=await j.json().catch(()=>({}));throw new Error(w.message||"Failed to generate puzzle")}const v=await j.json();return a(v),v}catch(j){return s(j.message),null}finally{l(!1)}},[c]),f=m.useCallback(async r=>{try{const u=await fetch(`${c}/api/validate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({puzzle:n,answers:r})});if(!u.ok)throw new Error("Failed to validate answers");return await u.json()}catch(u){return s(u.message),null}},[c,n]),d=m.useCallback(()=>{a(null),s(null)},[]);return{puzzle:n,loading:o,error:t,topics:i,fetchTopics:y,generatePuzzle:p,validateAnswers:f,resetPuzzle:d}};function q(){const[n,a]=m.useState([]),[o,l]=m.useState("medium"),[t,s]=m.useState(!1),[i,g]=m.useState(""),[c,y]=m.useState(!0),{puzzle:p,loading:f,error:d,topics:r,fetchTopics:u,generatePuzzle:h,resetPuzzle:x}=J();m.useEffect(()=>{u()},[u]);const z=async()=>{if(n.length===0){alert("Please select at least one topic");return}await h(n,o,!1,i,c)},j=N=>{a(N)},v=N=>{g(N)},w=N=>{y(N)},R=()=>{x(),a([]),s(!1),l("medium"),g(""),y(!0)},E=()=>{s(!0)};return e.jsxs("div",{className:"crossword-app",children:[e.jsxs("header",{className:"app-header",children:[e.jsx("h1",{className:"app-title",children:"Crossword Puzzle Generator"}),e.jsx("p",{children:"Select topics and generate your custom crossword puzzle!"})]}),e.jsx(G,{onTopicsChange:j,availableTopics:r,selectedTopics:n,customSentence:i,onSentenceChange:v,multiTheme:c,onMultiThemeChange:w}),e.jsxs("div",{className:"puzzle-controls",children:[e.jsxs("select",{value:o,onChange:N=>l(N.target.value),className:"control-btn",children:[e.jsx("option",{value:"easy",children:"Easy"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"hard",children:"Hard"})]}),e.jsx("button",{onClick:z,disabled:f||n.length===0,className:"control-btn generate-btn",children:f?"Generating...":"Generate Puzzle"}),e.jsx("button",{onClick:R,className:"control-btn reset-btn",children:"Reset"}),p&&!t&&e.jsx("button",{onClick:E,className:"control-btn reveal-btn",children:"Reveal Solution"})]}),d&&e.jsxs("div",{className:"error-message",children:["Error: ",d]}),f&&e.jsx(U,{}),p&&!f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"puzzle-info",children:e.jsxs("span",{className:"puzzle-stats",children:[p.metadata.wordCount," words • ",p.metadata.size,"×",p.metadata.size," grid"]})}),e.jsxs("div",{className:"puzzle-layout",children:[e.jsx(B,{grid:p.grid,clues:p.clues,showSolution:t}),e.jsx(M,{clues:p.clues})]})]}),!p&&!f&&!d&&e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"#7f8c8d"},children:'Select topics and click "Generate Puzzle" to start!'})]})}C.createRoot(document.getElementById("root")).render(e.jsx(_.StrictMode,{children:e.jsx(q,{})}));
//# sourceMappingURL=index-uK3VdD5a.js.map