File size: 14,912 Bytes
3b88621
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
import{r as m,a as R,R as $}from"./vendor-nf7bT_Uh.js";(function(){const c=document.createElement("link").relList;if(c&&c.supports&&c.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))i(t);new MutationObserver(t=>{for(const r of t)if(r.type==="childList")for(const h of r.addedNodes)h.tagName==="LINK"&&h.rel==="modulepreload"&&i(h)}).observe(document,{childList:!0,subtree:!0});function u(t){const r={};return t.integrity&&(r.integrity=t.integrity),t.referrerPolicy&&(r.referrerPolicy=t.referrerPolicy),t.crossOrigin==="use-credentials"?r.credentials="include":t.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(t){if(t.ep)return;t.ep=!0;const r=u(t);fetch(t.href,r)}})();var C={exports:{}},_={};/**
 * @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 O=m,L=Symbol.for("react.element"),F=Symbol.for("react.fragment"),G=Object.prototype.hasOwnProperty,M=O.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,U={key:!0,ref:!0,__self:!0,__source:!0};function T(s,c,u){var i,t={},r=null,h=null;u!==void 0&&(r=""+u),c.key!==void 0&&(r=""+c.key),c.ref!==void 0&&(h=c.ref);for(i in c)G.call(c,i)&&!U.hasOwnProperty(i)&&(t[i]=c[i]);if(s&&s.defaultProps)for(i in c=s.defaultProps,c)t[i]===void 0&&(t[i]=c[i]);return{$$typeof:L,type:s,key:r,ref:h,props:t,_owner:M.current}}_.Fragment=F;_.jsx=T;_.jsxs=T;C.exports=_;var e=C.exports,z={},S=R;z.createRoot=S.createRoot,z.hydrateRoot=S.hydrateRoot;const W=({onTopicsChange:s,availableTopics:c=[],selectedTopics:u=[],customSentence:i="",onSentenceChange:t,multiTheme:r=!0,onMultiThemeChange:h})=>{const g=o=>{const f=u.includes(o)?u.filter(j=>j!==o):[...u,o];s(f)};return e.jsxs("div",{className:"topic-selector",children:[e.jsx("h3",{children:"Select Topics"}),e.jsx("div",{className:"topic-buttons",children:c.map(o=>e.jsx("button",{className:`topic-btn ${u.includes(o.name)?"selected":""}`,onClick:()=>g(o.name),children:o.name},o.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:i,onChange:o=>t&&t(o.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:[i.length,"/200 characters"]}),i&&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:r,onChange:o=>h&&h(o.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:r?"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:[u.length," topic",u.length!==1?"s":""," selected"]})]})},B=({grid:s,clues:c,showSolution:u,onCellChange:i})=>{const[t,r]=m.useState({});m.useEffect(()=>{r({})},[s]);const h=(l,n,a)=>{const p=`${l}-${n}`,x={...t,[p]:a.toUpperCase()};r(x),i&&i(l,n,a)},g=(l,n)=>{if(u&&!o(l,n))return s[l][n];const a=`${l}-${n}`;return t[a]||""},o=(l,n)=>s[l][n]===".",f=(l,n)=>{if(!c)return null;const a=c.find(p=>p.position.row===l&&p.position.col===n);return a?a.number:null};if(!s||s.length===0)return e.jsx("div",{className:"puzzle-grid",children:"No puzzle loaded"});const j=s.length,d=s[0]?s[0].length:0;return e.jsx("div",{className:"puzzle-container",children:e.jsx("div",{className:"puzzle-grid",style:{gridTemplateColumns:`repeat(${d}, 35px)`,gridTemplateRows:`repeat(${j}, 35px)`},children:s.map((l,n)=>l.map((a,p)=>{const x=f(n,p);return o(n,p)?e.jsx("div",{className:"grid-cell empty-cell",style:{visibility:"hidden"}},`${n}-${p}`):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(n,p),onChange:v=>h(n,p,v.target.value),className:`cell-input ${u?"solution-text":""}`,disabled:u})]},`${n}-${p}`)}))})})},q=({clues:s=[]})=>{const c=s.filter(t=>t.direction==="across"),u=s.filter(t=>t.direction==="down"),i=({title:t,clueList:r})=>e.jsxs("div",{className:"clue-section",children:[e.jsx("h4",{children:t}),e.jsx("ol",{children:r.map(h=>e.jsxs("li",{className:"clue-item",children:[e.jsx("span",{className:"clue-number",children:h.number}),e.jsx("span",{className:"clue-text",children:h.text})]},`${h.number}-${h.direction}`))})]});return e.jsxs("div",{className:"clue-list",children:[e.jsx(i,{title:"Across",clueList:c}),e.jsx(i,{title:"Down",clueList:u})]})},Y=({debugData:s})=>{const[c,u]=m.useState("overview");if(!s||!s.enabled)return e.jsx("div",{className:"debug-tab",children:e.jsx("p",{children:"Debug data not available. Set ENABLE_DEBUG_TAB=true on the backend."})});const i=[{id:"overview",label:"Overview"},{id:"thematic-pool",label:"Thematic Pool"},{id:"candidates",label:"Candidates"},{id:"selection",label:"Selection"},{id:"selected",label:"Selected Words"}],t=()=>{var d,l,n;return e.jsxs("div",{className:"debug-section",children:[e.jsx("h3",{children:"Generation Parameters"}),e.jsxs("div",{className:"debug-grid",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Topics:"})," ",s.generation_params.topics.join(", ")]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Difficulty:"})," ",s.generation_params.difficulty]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Requested Words:"})," ",s.generation_params.requested_words]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Thematic Pool Size:"})," ",s.generation_params.thematic_pool_size]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Min Similarity:"})," ",s.generation_params.min_similarity]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Multi-theme:"})," ",s.generation_params.multi_theme?"Yes":"No"]}),s.generation_params.custom_sentence&&e.jsxs("div",{children:[e.jsx("strong",{children:"Custom Sentence:"}),' "',s.generation_params.custom_sentence,'"']})]}),e.jsx("h3",{children:"Selection Algorithm"}),e.jsxs("div",{className:"debug-grid",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Method:"})," ",s.selection_method]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Temperature:"})," ",s.selection_params.similarity_temperature]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Difficulty Weight:"})," ",s.selection_params.difficulty_weight]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Use Softmax:"})," ",s.selection_params.use_softmax_selection?"Yes":"No"]})]}),e.jsx("h3",{children:"Results Summary"}),e.jsxs("div",{className:"debug-grid",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Thematic Pool:"})," ",((d=s.thematic_pool)==null?void 0:d.length)||0," words"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Candidates:"})," ",((l=s.candidate_words)==null?void 0:l.length)||0," words"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Selected:"})," ",((n=s.selected_words)==null?void 0:n.length)||0," words"]})]})]})},r=(d,l=!1,n=!1)=>e.jsx("div",{className:"word-table-container",children:e.jsxs("table",{className:"word-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Word"}),e.jsx("th",{children:"Similarity"}),e.jsx("th",{children:"Percentile"}),e.jsx("th",{children:"Tier"}),l&&e.jsx("th",{children:"Clue"}),n&&e.jsx("th",{children:"Semantic Neighbors"})]})}),e.jsx("tbody",{children:d.map((a,p)=>{var x;return e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("strong",{children:a.word})}),e.jsx("td",{children:a.similarity.toFixed(3)}),e.jsx("td",{children:a.percentile.toFixed(3)}),e.jsx("td",{title:a.tier_description||a.tier,children:a.tier.replace("tier_","").replace("_"," ")}),l&&e.jsx("td",{children:a.clue}),n&&e.jsx("td",{children:((x=a.semantic_neighbors)==null?void 0:x.slice(0,3).join(", "))||"N/A"})]},p)})})]})}),h=()=>{const d=[...s.thematic_pool||[]].sort((l,n)=>n.similarity-l.similarity);return e.jsxs("div",{className:"debug-section",children:[e.jsxs("h3",{children:["Thematic Pool (",d.length," words)"]}),e.jsx("p",{children:"All words generated thematically, sorted by similarity to theme."}),r(d)]})},g=()=>{const d=s.candidate_words||[];return e.jsxs("div",{className:"debug-section",children:[e.jsxs("h3",{children:["Candidate Words (",d.length," words)"]}),e.jsx("p",{children:"Words that passed filtering and got clues generated."}),r(d,!0,!0)]})},o=()=>e.jsxs("div",{className:"debug-section",children:[e.jsx("h3",{children:"Selection Process"}),e.jsxs("div",{className:"debug-grid",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Algorithm:"})," ",s.selection_method]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Temperature:"})," ",s.selection_params.similarity_temperature," (lower = more deterministic)"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Difficulty Weight:"})," ",s.selection_params.difficulty_weight," (balance between similarity and frequency)"]})]}),e.jsx("h4",{children:"How it works:"}),e.jsxs("ul",{children:[e.jsxs("li",{children:[e.jsx("strong",{children:"Composite Score"})," = (1 - difficulty_weight) × similarity + difficulty_weight × frequency_alignment"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Frequency Alignment"}),": Gaussian distribution favoring target percentiles by difficulty"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Softmax Selection"}),": Probabilistic selection based on composite scores with temperature control"]})]}),e.jsx("h4",{children:"Difficulty Targets:"}),e.jsxs("ul",{children:[e.jsxs("li",{children:[e.jsx("strong",{children:"Easy:"})," 90th percentile (common words like CAT, DOG)"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Medium:"})," 50th percentile (balanced selection)"]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Hard:"})," 20th percentile (rare words like QUETZAL, PLATYPUS)"]})]})]}),f=()=>{const d=s.selected_words||[];return e.jsxs("div",{className:"debug-section",children:[e.jsxs("h3",{children:["Selected Words (",d.length," words)"]}),e.jsx("p",{children:"Final words chosen for crossword generation."}),r(d,!0)]})},j=()=>{switch(c){case"overview":return t();case"thematic-pool":return h();case"candidates":return g();case"selection":return o();case"selected":return f();default:return t()}};return e.jsxs("div",{className:"debug-tab",children:[e.jsx("div",{className:"debug-nav",children:i.map(d=>e.jsx("button",{className:`debug-nav-btn ${c===d.id?"active":""}`,onClick:()=>u(d.id),children:d.label},d.id))}),e.jsx("div",{className:"debug-content",children:j()})]})},H=({message:s="Generating puzzle..."})=>e.jsxs("div",{className:"loading-spinner",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{className:"loading-message",children:s})]}),J=()=>{const[s,c]=m.useState(null),[u,i]=m.useState(!1),[t,r]=m.useState(null),[h,g]=m.useState([]),o="",f=m.useCallback(async()=>{try{i(!0);const n=await fetch(`${o}/api/topics`);if(!n.ok)throw new Error("Failed to fetch topics");const a=await n.json();g(a)}catch(n){r(n.message)}finally{i(!1)}},[o]),j=m.useCallback(async(n,a="medium",p=!1,x="",y=!0)=>{try{i(!0),r(null);const v=await fetch(`${o}/api/generate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({topics:n,difficulty:a,useAI:p,...x&&{customSentence:x},multiTheme:y})});if(!v.ok){const w=await v.json().catch(()=>({}));throw new Error(w.message||"Failed to generate puzzle")}const N=await v.json();return c(N),N}catch(v){return r(v.message),null}finally{i(!1)}},[o]),d=m.useCallback(async n=>{try{const a=await fetch(`${o}/api/validate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({puzzle:s,answers:n})});if(!a.ok)throw new Error("Failed to validate answers");return await a.json()}catch(a){return r(a.message),null}},[o,s]),l=m.useCallback(()=>{c(null),r(null)},[]);return{puzzle:s,loading:u,error:t,topics:h,fetchTopics:f,generatePuzzle:j,validateAnswers:d,resetPuzzle:l}};function K(){const[s,c]=m.useState([]),[u,i]=m.useState("medium"),[t,r]=m.useState(!1),[h,g]=m.useState(""),[o,f]=m.useState(!0),[j,d]=m.useState("puzzle"),{puzzle:l,loading:n,error:a,topics:p,fetchTopics:x,generatePuzzle:y,resetPuzzle:v}=J();m.useEffect(()=>{x()},[x]);const N=async()=>{if(s.length===0&&!h.trim()){alert("Please select at least one topic or provide a custom sentence");return}r(!1),await y(s,u,!1,h,o)},w=b=>{c(b)},P=b=>{g(b)},k=b=>{f(b)},E=()=>{v(),c([]),r(!1),i("medium"),g(""),f(!0),d("puzzle")},A=()=>{r(!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(W,{onTopicsChange:w,availableTopics:p,selectedTopics:s,customSentence:h,onSentenceChange:P,multiTheme:o,onMultiThemeChange:k}),e.jsxs("div",{className:"puzzle-controls",children:[e.jsxs("select",{value:u,onChange:b=>i(b.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:N,disabled:n||s.length===0&&!h.trim(),className:"control-btn generate-btn",children:n?"Generating...":"Generate Puzzle"}),e.jsx("button",{onClick:E,className:"control-btn reset-btn",children:"Reset"}),l&&!t&&e.jsx("button",{onClick:A,className:"control-btn reveal-btn",children:"Reveal Solution"})]}),a&&e.jsxs("div",{className:"error-message",children:["Error: ",a]}),n&&e.jsx(H,{}),l&&!n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"tab-nav",children:[e.jsx("button",{className:`tab-btn ${j==="puzzle"?"active":""}`,onClick:()=>d("puzzle"),children:"Puzzle"}),l.debug&&e.jsx("button",{className:`tab-btn ${j==="debug"?"active":""}`,onClick:()=>d("debug"),children:"Debug"})]}),j==="puzzle"&&e.jsxs("div",{className:"puzzle-layout",children:[e.jsx(B,{grid:l.grid,clues:l.clues,showSolution:t}),e.jsx(q,{clues:l.clues})]}),j==="debug"&&l.debug&&e.jsx(Y,{debugData:l.debug})]}),!l&&!n&&!a&&e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"#7f8c8d"},children:'Select topics and click "Generate Puzzle" to start!'})]})}z.createRoot(document.getElementById("root")).render(e.jsx($.StrictMode,{children:e.jsx(K,{})}));
//# sourceMappingURL=index-BjEV3Co3.js.map