From 879336d259b409647e9ff4849c17fe95562f2b8b Mon Sep 17 00:00:00 2001 From: nicholasyfu1 Date: Sat, 2 Nov 2024 15:50:50 -0400 Subject: [PATCH 01/19] Added blank crossword --- index.html | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/index.html b/index.html index 20b910d..75d155a 100644 --- a/index.html +++ b/index.html @@ -27,6 +27,8 @@

Enter a list of words below




+

+

View Source Code (MIT License)


Short Article @ ProjectBoard



@@ -63,6 +65,26 @@

View So } return tableArray.join(""); } + + /** + * Generates HTML table from layout.table as a 2D array. + */ + function generate_html_table(table) { + var htmlText = ''; + for (let i = 0; i < table.length; i++) { + htmlText += ''; + for (let j = 0; j < table[i].length; j++) { + if (table[i][j] !== '-') { // If letter, add a white cell + htmlText += ''; + } else { // If not letter, add a black cell + htmlText += ''; + } + } + htmlText += ''; + } + htmlText += '
'; + return htmlText; + } function button_clicked(){ // Input data @@ -82,8 +104,12 @@

View So var alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]; var word_search = create_word_search(alphabet, output_html); + // Generate crossword HTML + var crossword_html = generate_html_table(layout.table); + // Display result document.getElementById("content").innerHTML = "

Output JSON


" + JSON.stringify(output_json) + "

Output Html


" + output_html + "

Extra Output: Word Search


" + word_search + "
"; + document.getElementById("blank-html-crossword").innerHTML = "

Blank Crossword


" + crossword_html; } } From 021129b430958eebb11434906db4ff0af5a413d2 Mon Sep 17 00:00:00 2001 From: nicholasyfu1 Date: Sat, 2 Nov 2024 16:08:57 -0400 Subject: [PATCH 02/19] Added ability to enter clues --- index.html | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 75d155a..2cc2078 100644 --- a/index.html +++ b/index.html @@ -47,11 +47,12 @@

View So function convert_to_json(word_list){ var json_data = []; for(let i in word_list){ - if(word_list[i].length > 0){ - json_data[i] = {"answer": word_list[i].toLowerCase()}; + if(word_list[i].trim().length > 0){ + var parts = word_list[i].split(";"); + var clue = parts[1] ? parts[1].trim() : ''; + json_data[i] = {"answer": parts[0].trim().toLowerCase(), "clue": clue}; } } - return json_data; } @@ -88,7 +89,7 @@

View So function button_clicked(){ // Input data - var word_list = document.getElementById("words").value.replace(/[ \r\n,;:-]+/g, ",").split(","); + var word_list = document.getElementById("words").value.split('\n'); if(word_list[0] != ""){ var input_json = convert_to_json(word_list); @@ -109,7 +110,7 @@

View So // Display result document.getElementById("content").innerHTML = "

Output JSON


" + JSON.stringify(output_json) + "

Output Html


" + output_html + "

Extra Output: Word Search


" + word_search + "
"; - document.getElementById("blank-html-crossword").innerHTML = "

Blank Crossword


" + crossword_html; + document.getElementById("blank-html-crossword").innerHTML = "

Blank Crossword


" + crossword_html; } } From 2ffed6f72c3a52444cc2764ef71442f548798806 Mon Sep 17 00:00:00 2001 From: Mina Mandic Date: Wed, 6 Nov 2024 11:30:11 -0500 Subject: [PATCH 03/19] indexed into json to add position to layout --- index.html | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 2cc2078..23a36dc 100644 --- a/index.html +++ b/index.html @@ -70,13 +70,19 @@

View So /** * Generates HTML table from layout.table as a 2D array. */ - function generate_html_table(table) { + function generate_html_table(table, output_json) { var htmlText = ''; for (let i = 0; i < table.length; i++) { htmlText += ''; for (let j = 0; j < table[i].length; j++) { if (table[i][j] !== '-') { // If letter, add a white cell - htmlText += ''; + var wordPosition = output_json.find(word => word.startx === j + 1 && word.starty === i + 1); // Find word that starts here + if (wordPosition) { // If word starts here, White cell with number + htmlText += ``; + } else { // Blank white cell + htmlText += ''; + } } else { // If not letter, add a black cell htmlText += ''; } @@ -106,7 +112,7 @@

View So var word_search = create_word_search(alphabet, output_html); // Generate crossword HTML - var crossword_html = generate_html_table(layout.table); + var crossword_html = generate_html_table(layout.table, output_json); // Display result document.getElementById("content").innerHTML = "

Output JSON


" + JSON.stringify(output_json) + "

Output Html


" + output_html + "

Extra Output: Word Search


" + word_search + "
"; From 6e862f8e5271150d9c158bafa67e2d2154d3b6b8 Mon Sep 17 00:00:00 2001 From: Mina Mandic Date: Tue, 12 Nov 2024 15:22:13 -0500 Subject: [PATCH 04/19] added side panel to display clues --- index.html | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/index.html b/index.html index 23a36dc..8ecee86 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,16 @@ color: #444444; max-height: 99999999px; } + .side-panel { + position: absolute; + top: 100px; + right: 50px; + width: 300px; + border: 1px solid #444; + padding: 10px; + font-family: Arial, sans-serif; + background-color: #f9f9f9; + } @@ -43,6 +53,11 @@

View So +
+

Clues

+
    +
    + From 5f0d6a845359bf6c63b52a25387d3fd57f8f3080 Mon Sep 17 00:00:00 2001 From: Mina Mandic Date: Tue, 12 Nov 2024 15:23:55 -0500 Subject: [PATCH 05/19] instructions --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 8ecee86..a590865 100644 --- a/index.html +++ b/index.html @@ -30,7 +30,7 @@


    Crossword Layout Generator

    -

    Enter a list of words below



    +

    Enter a list of words below, separate words from their clues using a semicolon










    From 8e8683036ca55ecd715e0088f449577bb64dab94 Mon Sep 17 00:00:00 2001 From: Mina Mandic Date: Tue, 12 Nov 2024 15:26:59 -0500 Subject: [PATCH 06/19] formatting --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index a590865..e69e8bf 100644 --- a/index.html +++ b/index.html @@ -30,7 +30,7 @@


    Crossword Layout Generator

    -

    Enter a list of words below, separate words from their clues using a semicolon



    +

    Enter a list of words below, separate words and clues using ";"










    From 01cabc6e8740c93d5e760d50f0cba460aedf9ea6 Mon Sep 17 00:00:00 2001 From: aporsch1 <108027459+aporsch1@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:14:10 -0500 Subject: [PATCH 07/19] added filled in crossword --- index.html | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index e69e8bf..8f1f6ae 100644 --- a/index.html +++ b/index.html @@ -108,6 +108,31 @@

    Clues

    return htmlText; } + function generate_filled_crossword_table(table, output_json) { + var htmlText = '

    + ${wordPosition.position}
    '; + for (let i = 0; i < table.length; i++) { + htmlText += ''; + for (let j = 0; j < table[i].length; j++) { + if (table[i][j] !== '-') { // If letter, add a white cell and display the letter + var wordPosition = output_json.find(word => word.startx === j + 1 && word.starty === i + 1); // Find word that starts here + if (wordPosition) { // If word starts here, White cell with number and letter + htmlText += ``; + } else { // White cell with letter + htmlText += ``; + } + } else { // If not letter, add a black cell + htmlText += ''; + } + } + htmlText += ''; + } + htmlText += '
    + ${table[i][j]} + ${wordPosition.position} + ${table[i][j]}
    '; + return htmlText; + } + function display_clues(clues) { var cluesList = document.getElementById("clues-list"); cluesList.innerHTML = ""; @@ -141,9 +166,12 @@

    Clues

    // Generate crossword HTML var crossword_html = generate_html_table(layout.table, output_json); + var filled_crossword_html = generate_filled_crossword_table(layout.table, output_json); + // Display result document.getElementById("content").innerHTML = "

    Output JSON


    " + JSON.stringify(output_json) + "

    Output Html


    " + output_html + "

    Extra Output: Word Search


    " + word_search + "
    "; - document.getElementById("blank-html-crossword").innerHTML = "

    Blank Crossword


    " + crossword_html; + document.getElementById("blank-html-crossword").innerHTML = "

    Blank Crossword


    " + crossword_html; + document.getElementById("content").innerHTML = "

    Filled Crossword

    " + filled_crossword_html; display_clues(input_json) } } From a165d0795b80a336067c33fde9654451e0c177bd Mon Sep 17 00:00:00 2001 From: nicholasyfu1 Date: Wed, 13 Nov 2024 20:35:14 -0500 Subject: [PATCH 08/19] Fixed clues formatting --- index.html | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index 8f1f6ae..0452b1b 100644 --- a/index.html +++ b/index.html @@ -12,16 +12,6 @@ color: #444444; max-height: 99999999px; } - .side-panel { - position: absolute; - top: 100px; - right: 50px; - width: 300px; - border: 1px solid #444; - padding: 10px; - font-family: Arial, sans-serif; - background-color: #f9f9f9; - } @@ -32,13 +22,18 @@

    Crossword Layout Generator

    Enter a list of words below, separate words and clues using ";"



    -



    +



    +




    +
    + +

    +

    View Source Code (MIT License)


    Short Article @ ProjectBoard



    @@ -53,10 +48,7 @@

    View So -
    -

    Clues

    -
      -
      + From 61c0012327ca0bcc256f0f49a012a81f4a346eee Mon Sep 17 00:00:00 2001 From: Mina Mandic Date: Mon, 18 Nov 2024 10:47:03 -0500 Subject: [PATCH 09/19] feature to check if word is in crossword --- index.html | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 0452b1b..069e6a9 100644 --- a/index.html +++ b/index.html @@ -20,9 +20,14 @@


      Crossword Layout Generator

      -

      Enter a list of words below, separate words and clues using ";"



      +

      Enter a list of words below







      + +

      Check if a word is in the crossword

      + + +



      @@ -48,8 +53,6 @@

      View So

      - -

      From 3f1fc36c7fd3194da10c2b2311874da89f127406 Mon Sep 17 00:00:00 2001 From: aporsch1 <108027459+aporsch1@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:14:51 -0500 Subject: [PATCH 10/19] download pdfs --- index.html | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/index.html b/index.html index 069e6a9..17fdb7c 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,11 @@ + + + + + +
      +
      +
      +

      Generate your own crossword puzzle

      +

      Enter a list of words on seperate lines


      -
      + +

      -

      Crossword Layout Generator

      -

      Enter a list of words below



      - -



      -


      + + +

      -

      Check if a word is in the crossword

      - - -
      + -

      +

      -

      + -
      +

      -

      +
      + +

      -
      - - + -

      View Source Code (MIT License)


      - Short Article @ ProjectBoard



      +

      -
      + +

      +
      + + - -

      - + From f9a1624f48877992fdce999574a9f94424b8f549 Mon Sep 17 00:00:00 2001 From: nicholasyfu1 Date: Thu, 21 Nov 2024 23:13:46 -0500 Subject: [PATCH 15/19] fixed buttons --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index d966b6e..a593947 100644 --- a/index.html +++ b/index.html @@ -176,7 +176,7 @@

      Check if a word is in the crossword



      - @@ -285,7 +288,7 @@

      Word Search

      if (table[i][j] !== '-') { // If letter, add a white cell and display the letter var wordPosition = output_json.find(word => word.startx === j + 1 && word.starty === i + 1); // Find word that starts here if (wordPosition) { // If word starts here, White cell with number and letter - htmlText += ` + htmlText += ` ${table[i][j]} ${wordPosition.position}`; } else { // White cell with letter From 7ba194b9b30863bbcfbda9abf3d8e7c98d2e3036 Mon Sep 17 00:00:00 2001 From: nicholasyfu1 Date: Mon, 2 Dec 2024 19:30:02 -0500 Subject: [PATCH 17/19] Added max size limit --- index.html | 24 ++++++++++++++++++++++-- layout_generator.js | 12 ++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index af1b004..8530961 100644 --- a/index.html +++ b/index.html @@ -66,6 +66,10 @@ color: var(--nav-title); } + .form-group label { + color: var(--text-secondary); + } + .form-control { background-color: var(--background-secondary); color: var(--input-text); @@ -149,10 +153,23 @@

      Generate your own crossword puzzle

      Enter a list of words on seperate lines


      - +

      +
      + + +
      +

      +

      @@ -367,9 +384,12 @@

      Word Search

      var input_json = convert_to_json(word_list); await generate_missing_clues(input_json); + + var maxSizeInput = document.getElementById("maxSizeInput").value; + var maxSize = parseInt(maxSizeInput); // Output data - var layout = generateLayout(input_json); + var layout = generateLayout(input_json, maxSize); var rows = layout.rows; var cols = layout.cols; var table = layout.table; // table as two-dimensional array diff --git a/layout_generator.js b/layout_generator.js index 8585997..cefe3fa 100644 --- a/layout_generator.js +++ b/layout_generator.js @@ -96,7 +96,7 @@ function assignPositions(words){ } } -function computeDimension(words, factor){ +function computeDimension(words, factor, maxSize){ var temp = 0; for(let i = 0; i < words.length; i++){ if(temp < words[i].answer.length){ @@ -104,7 +104,7 @@ function computeDimension(words, factor){ } } - return temp * factor; + return Math.min(temp * factor, maxSize); } @@ -461,8 +461,8 @@ function tableToString(table, delim){ } } -function generateSimpleTable(words){ - var rows = computeDimension(words, 3); +function generateSimpleTable(words, maxSize){ + var rows = computeDimension(words, 3, maxSize); var cols = rows; var blankTable = initTable(rows, cols); var table = generateTable(blankTable, rows, cols, words, [0.7, 0.15, 0.1, 0.05]); @@ -472,8 +472,8 @@ function generateSimpleTable(words){ return finalTable; } -function generateLayout(words_json){ - var layout = generateSimpleTable(words_json); +function generateLayout(words_json, maxSize = 16){ + var layout = generateSimpleTable(words_json, maxSize); layout.table_string = tableToString(layout.table, "
      "); return layout; } From 14602c27e36543858d2d1e06c642530273ee4b34 Mon Sep 17 00:00:00 2001 From: nicholasyfu1 Date: Mon, 2 Dec 2024 19:45:16 -0500 Subject: [PATCH 18/19] Fixed bug with clues --- index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 8530961..40fae87 100644 --- a/index.html +++ b/index.html @@ -283,7 +283,7 @@

      Word Search

      var wordPosition = output_json.find(word => word.startx === j + 1 && word.starty === i + 1); // Find word that starts here if (wordPosition) { // If word starts here, White cell with number htmlText += ` - ${wordPosition.position}`; + ${wordPosition.position}`; } else { // Blank white cell htmlText += ''; } @@ -307,7 +307,7 @@

      Word Search

      if (wordPosition) { // If word starts here, White cell with number and letter htmlText += ` ${table[i][j]} - ${wordPosition.position}`; + ${wordPosition.position}`; } else { // White cell with letter htmlText += ` ${table[i][j]}`; @@ -325,11 +325,12 @@

      Word Search

      function generate_clues(clues) { var htmlText = `
        `; clues.forEach((item, index) => { - if (item.clue) { + console.log(item) + if (item.clue && item.orientation != "none") { const word = `word-${index}`; htmlText += `
      • - ${index + 1}. ${item.clue} + ${item.position}. ${item.clue}
      • `; @@ -406,7 +407,6 @@

        Word Search

        var filled_crossword_html = generate_filled_crossword_table(layout.table, output_json); var clues_html = generate_clues(input_json); - console.log(clues_html); // Display result document.getElementById("output-json").innerHTML = "
        " + JSON.stringify(output_json); From 4bec92a3bab7adfd755f3c4f50fe001ad6d68b92 Mon Sep 17 00:00:00 2001 From: nicholasyfu1 <62448453+nicholasyfu1@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:19:33 -0500 Subject: [PATCH 19/19] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index cc6ab1f..c48072f 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,13 @@ This crossword layout generator takes in a list of answers and outputs a crosswo ## Running the code locally **Step 1:** Navigate to the server directory: `cd server` + **Step 2:** Install project dependencies: `npm install` + **Step 3:** Create a file named `.env` in `server`. In the file, add your API key: `OPENAI_API_KEY=your_api_key` + **Step 4:** Start the server with `npm start` (default: port 3000) + **Step 5:** Go back to the main project directory and run the live server extension. ## Input and Output Format