Skip to content

Evan715823/cheatsheet-generator-skill / skills/cheatsheet-generator

cheatsheet-generator

Verified

Generate LaTeX exam cheatsheets from course materials (PDF/PPTX/MD/images). Use when user says "generate cheatsheet", "make a cheat sheet", "create exam reference sheet", "condense notes", or has course materials to turn into a compact LaTeX review sheet for exams.

templates/editor_ui.html

View on GitHub
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cheatsheet Editor</title>
<style>
  :root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --border: #e5e5e5;
    --text: #1d1d1f;
    --text-sec: #86868b;
    --accent: #0071e3;
    --accent-hover: #0077ED;
    --accent-glow: rgba(0,113,227,0.25);
    --green: #34c759;
    --amber: #ff9f0a;
    --red: #ff3b30;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }

  body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
  }

  /* Custom scrollbars */
  ::-webkit-scrollbar { width: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 3px;
  }
  ::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

  /* Toolbar */
  .toolbar {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    background: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, rgba(248,248,250,0.9) 100%);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 0.5px solid var(--border);
    gap: 12px;
    flex-shrink: 0;
    z-index: 10;
    box-shadow: 0 1px 8px rgba(0,0,0,0.04);
  }

  .toolbar h1 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-right: auto;
    letter-spacing: -0.01em;
    background: linear-gradient(135deg, var(--text) 0%, #555 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .tb-btn {
    padding: 6px 16px;
    font-size: 0.78rem;
    font-weight: 500;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    background: var(--surface);
    color: var(--text);
  }

  .tb-btn:hover { border-color: #ccc; background: #fafafa; transform: translateY(-0.5px); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
  .tb-btn:active { transform: translateY(0); }

  .tb-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }

  .tb-btn.primary:hover { background: var(--accent-hover); box-shadow: 0 2px 12px var(--accent-glow); }

  /* Main */
  .main {
    display: grid;
    grid-template-columns: 1fr 380px;
    flex: 1;
    overflow: hidden;
  }

  /* Left: source */
  .panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .panel-header {
    padding: 10px 20px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-sec);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 0.5px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
  }

  #previewImg {
    max-width: 100%;
    max-height: 180px;
    object-fit: contain;
    background: #fff;
    display: none;
    flex-shrink: 0;
    border-bottom: 0.5px solid var(--border);
  }

  .source-wrap {
    flex: 1;
    overflow-y: auto;
    background: var(--surface);
  }

  /* Source code with line numbers */
  .source-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--mono);
    font-size: 0.72rem;
    line-height: 1.6;
  }

  .source-table td {
    vertical-align: top;
    padding: 0;
  }

  .line-number {
    width: 44px;
    min-width: 44px;
    text-align: right;
    padding: 0 12px 0 8px;
    color: #c7c7cc;
    user-select: none;
    -webkit-user-select: none;
    border-right: 1px solid #f0f0f2;
    font-size: 0.65rem;
    background: #fafafe;
  }

  .line-content {
    padding: 0 16px 0 12px;
    white-space: pre-wrap;
    word-break: break-all;
    tab-size: 2;
    color: #333;
  }

  .source-table tr:first-child .line-number,
  .source-table tr:first-child .line-content { padding-top: 14px; }
  .source-table tr:last-child .line-number,
  .source-table tr:last-child .line-content { padding-bottom: 14px; }

  /* Syntax highlighting - richer colors */
  .tex-cmd { color: #c239b3; font-weight: 500; }
  .tex-brace { color: #2d7ff9; }
  .tex-comment { color: #a3a3a8; font-style: italic; }
  .tex-math { color: #e8590c; }
  .tex-env { color: #7048e8; font-weight: 500; }

  /* Right: edit */
  .panel-right {
    border-left: 0.5px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg);
  }

  .edit-section {
    padding: 20px;
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 0.5px solid var(--border);
  }

  .textarea-wrap {
    position: relative;
  }

  .edit-section textarea {
    width: 100%;
    min-height: 100px;
    padding: 12px;
    font-size: 0.82rem;
    font-family: inherit;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    resize: vertical;
    outline: none;
    transition: border-color 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    line-height: 1.5;
  }

  .edit-section textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
  }
  .edit-section textarea:disabled { opacity: 0.5; }

  .textarea-hint {
    font-size: 0.68rem;
    color: var(--text-sec);
    margin-top: 5px;
    display: flex;
    justify-content: space-between;
    padding: 0 2px;
  }

  .textarea-hint .char-count { font-variant-numeric: tabular-nums; }

  /* Image upload */
  .upload-area {
    margin-top: 10px;
    padding: 10px;
    border: 1.5px dashed var(--border);
    border-radius: 10px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-sec);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    background: transparent;
  }

  .upload-area:hover, .upload-area.dragover {
    border-color: var(--accent);
    background: rgba(0,113,227,0.04);
    color: var(--accent);
    border-style: dashed;
    animation: dash-march 0.6s linear infinite;
  }

  @keyframes dash-march {
    to { border-dash-offset: 12px; }
  }

  /* Animated dashed border via SVG for hover */
  .upload-area::before {
    content: '';
    position: absolute;
    inset: -1.5px;
    border-radius: 11px;
    padding: 1.5px;
    background: linear-gradient(90deg, var(--accent), #7048e8, var(--accent));
    background-size: 200% 100%;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
  }

  .upload-area:hover::before, .upload-area.dragover::before {
    opacity: 1;
    animation: border-shimmer 2s linear infinite;
  }

  @keyframes border-shimmer {
    to { background-position: 200% 0; }
  }

  .upload-area input[type="file"] {
    display: none;
  }

  .upload-previews {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
  }

  .upload-thumb {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid var(--border);
  }

  .upload-file-icon {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    font-weight: 600;
    color: var(--text-sec);
    text-align: center;
    overflow: hidden;
    word-break: break-all;
    padding: 2px;
    line-height: 1.1;
  }

  .upload-thumb-wrap {
    position: relative;
    display: inline-block;
  }

  .upload-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--red);
    color: #fff;
    border: none;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: transform 0.15s;
  }

  .upload-remove:hover { transform: scale(1.15); }

  .edit-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
  }

  .edit-btn {
    padding: 8px 20px;
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    background: linear-gradient(135deg, #0077ED 0%, #005BBB 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    overflow: hidden;
  }

  .edit-btn:hover { background: linear-gradient(135deg, #0080FF 0%, #0066CC 100%); box-shadow: 0 4px 16px var(--accent-glow); transform: translateY(-0.5px); }
  .edit-btn:active { transform: translateY(0) scale(0.97); }
  .edit-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

  /* Ripple effect on click */
  .edit-btn .ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255,255,255,0.35);
    transform: scale(0);
    animation: ripple-anim 0.5s ease-out forwards;
    pointer-events: none;
  }

  @keyframes ripple-anim {
    to { transform: scale(3); opacity: 0; }
  }

  .status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-sec);
  }

  .status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    flex-shrink: 0;
    box-shadow: 0 0 0 0 rgba(52,199,89,0.4);
    transition: all 0.3s;
  }

  .status-dot.working {
    background: var(--amber);
    box-shadow: 0 0 0 0 rgba(255,159,10,0.4);
    animation: pulse-ring 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  }

  @keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(255,159,10,0.5); }
    50% { box-shadow: 0 0 0 6px rgba(255,159,10,0); }
    100% { box-shadow: 0 0 0 0 rgba(255,159,10,0); }
  }

  /* History */
  .history-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
  }

  .history-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-sec);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
  }

  .h-item {
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: 10px;
    font-size: 0.78rem;
    animation: slide-in-right 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    opacity: 0;
    transform: translateX(16px);
    transition: box-shadow 0.2s;
  }

  .h-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  }

  @keyframes slide-in-right {
    to { opacity: 1; transform: translateX(0); }
  }

  .h-req { color: var(--text-sec); margin-bottom: 4px; line-height: 1.4; }
  .h-res { color: var(--green); font-weight: 500; }

  /* Done overlay */
  .done-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(245,245,247,0.75);
    backdrop-filter: blur(40px) saturate(1.5);
    -webkit-backdrop-filter: blur(40px) saturate(1.5);
    z-index: 100;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  }

  .done-overlay.show { display: flex; animation: fade-in 0.4s forwards; }

  @keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  .done-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #34c759 0%, #28a745 100%);
    color: #fff;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(52,199,89,0.3);
    animation: done-bounce 0.5s 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

  @keyframes done-bounce {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
  }

  .done-overlay h2 { font-size: 1.3rem; font-weight: 600; }
  .done-overlay p { color: var(--text-sec); }

  /* Overleaf tutorial modal */
  .modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(8px);
    z-index: 200;
    justify-content: center;
    align-items: center;
    opacity: 0;
  }
  .modal-backdrop.show {
    display: flex;
    animation: modal-backdrop-in 0.3s forwards;
  }

  @keyframes modal-backdrop-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  .modal {
    background: var(--surface);
    border-radius: 16px;
    width: 520px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 24px 80px rgba(0,0,0,0.18);
    padding: 32px;
    position: relative;
    animation: modal-enter 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transform: scale(0.92) translateY(12px);
    opacity: 0;
  }

  @keyframes modal-enter {
    from { transform: scale(0.92) translateY(12px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
  }

  .modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--text-sec);
    transition: all 0.15s;
  }
  .modal-close:hover { background: #eee; color: var(--text); transform: rotate(90deg); }

  .modal h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .modal .subtitle {
    color: var(--text-sec);
    font-size: 0.82rem;
    margin-bottom: 20px;
  }

  .step-list {
    list-style: none;
    counter-reset: steps;
  }

  .step-list li {
    counter-increment: steps;
    position: relative;
    padding: 14px 16px 14px 50px;
    margin-bottom: 10px;
    background: var(--bg);
    border-radius: 10px;
    font-size: 0.84rem;
    line-height: 1.55;
  }

  .step-list li::before {
    content: counter(steps);
    position: absolute;
    left: 14px;
    top: 14px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .step-list li strong { color: var(--text); }
  .step-list li code {
    background: rgba(0,113,227,0.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--accent);
  }

  .modal-note {
    margin-top: 16px;
    padding: 12px 14px;
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 10px;
    font-size: 0.78rem;
    line-height: 1.5;
    color: #6d4c00;
  }

  .modal-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
  }

  .tb-btn.overleaf {
    background: #47a141;
    border-color: #47a141;
    color: #fff;
  }
  .tb-btn.overleaf:hover { background: #3d8c38; box-shadow: 0 2px 12px rgba(71,161,65,0.3); }

  .done-tutorial {
    margin-top: 20px;
    text-align: center;
  }
  .done-tutorial a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: color 0.15s;
  }
  .done-tutorial a:hover { text-decoration: underline; }
</style>
</head>
<body>

<div class="toolbar">
  <h1>Cheatsheet Editor</h1>
  <button class="tb-btn" onclick="copyTex()">Copy</button>
  <button class="tb-btn" onclick="downloadTex()">Download</button>
  <button class="tb-btn overleaf" onclick="showOverleafGuide()">Import to Overleaf</button>
  <button class="tb-btn primary" onclick="finish()">Done</button>
</div>

<div class="main">
  <div class="panel">
    <div class="panel-header">LaTeX Source</div>
    <img id="previewImg" alt="PDF Preview">
    <div class="source-wrap">
      <div class="source-code" id="sourceCode">Loading...</div>
    </div>
  </div>

  <div class="panel-right">
    <div class="edit-section">
      <div class="textarea-wrap">
        <textarea id="editInput" placeholder="Describe changes...&#10;&#10;e.g. Add more detail to the HTTP section"></textarea>
        <div class="textarea-hint">
          <span>Ctrl+Enter to submit</span>
          <span class="char-count" id="charCount">0 chars</span>
        </div>
      </div>
      <div class="upload-area" id="uploadArea" onclick="document.getElementById('fileInput').click()">
        Drop files here, click to upload, or paste (Ctrl+V)
        <input type="file" id="fileInput" multiple>
      </div>
      <div class="upload-previews" id="uploadPreviews"></div>
      <div class="edit-actions">
        <button class="edit-btn" id="editBtn" onclick="submitEdit()">Submit</button>
        <div class="status">
          <div class="status-dot" id="statusDot"></div>
          <span id="statusText">Ready</span>
        </div>
      </div>
    </div>
    <div class="history-wrap">
      <div class="history-label">History</div>
      <div id="historyList"></div>
    </div>
  </div>
</div>

<div class="done-overlay" id="doneOverlay">
  <div class="done-icon">&#10003;</div>
  <h2>Cheatsheet Saved</h2>
  <p>Your cheatsheet.tex is ready for Overleaf.</p>
  <div class="done-tutorial">
    <a onclick="document.getElementById('doneOverlay').classList.remove('show'); showOverleafGuide();">How to import to Overleaf &rarr;</a>
  </div>
</div>

<!-- Overleaf Import Tutorial Modal -->
<div class="modal-backdrop" id="overleafModal">
  <div class="modal">
    <button class="modal-close" onclick="closeOverleafGuide()">&times;</button>
    <h2><span style="font-size:1.3rem">&#127811;</span> Import to Overleaf</h2>
    <p class="subtitle">Follow these steps to compile your cheatsheet in Overleaf</p>

    <ol class="step-list">
      <li>Open <strong>Overleaf</strong> and click <strong>New Project</strong> &rarr; <strong>Blank Project</strong>. Give it any name.</li>
      <li>In the new project, click on <code>main.tex</code> in the file tree on the left. <strong>Select all</strong> existing content (Ctrl+A) and <strong>delete</strong> it.</li>
      <li>Click the <strong>Copy</strong> button in this editor's toolbar (or open the downloaded <code>.tex</code> file and copy its contents). Then <strong>paste</strong> into the empty <code>main.tex</code> on Overleaf.</li>
      <li>Click the <strong>Menu</strong> button (top-left corner in Overleaf). Under <strong>Settings</strong>, change the <strong>Compiler</strong> from <code>pdfLaTeX</code> to <code>XeLaTeX</code>.</li>
      <li>Click <strong>Recompile</strong> (or Ctrl+Enter). Your cheatsheet PDF will render on the right!</li>
    </ol>

    <div class="modal-note">
      <strong>&#9888; Important:</strong> You <em>must</em> switch the compiler to <strong>XeLaTeX</strong> (step 4). The default pdfLaTeX does not support the <code>fontspec</code> package used for custom fonts. If you see a compilation error about fontspec, this is the fix.
    </div>

    <div class="modal-actions">
      <button class="tb-btn overleaf" onclick="window.open('https://www.overleaf.com/project','_blank')">Open Overleaf</button>
      <button class="tb-btn" onclick="copyTex(); closeOverleafGuide();">Copy LaTeX &amp; Close</button>
    </div>
  </div>
</div>

<script>
  let currentTex = '';

  function highlightTex(src) {
    let h = src.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
    h = h.replace(/(%.*)$/gm, '<span class="tex-comment">$1</span>');
    h = h.replace(/(\$[^$]+?\$)/g, '<span class="tex-math">$1</span>');
    h = h.replace(/(\\(?:begin|end)\{[^}]+\})/g, '<span class="tex-env">$1</span>');
    h = h.replace(/(\\[a-zA-Z@]+)/g, '<span class="tex-cmd">$1</span>');
    h = h.replace(/([{}])/g, '<span class="tex-brace">$1</span>');
    return h;
  }

  function renderSourceWithLineNumbers(src) {
    const highlighted = highlightTex(src);
    const lines = highlighted.split('\n');
    let html = '<table class="source-table">';
    for (let i = 0; i < lines.length; i++) {
      html += '<tr><td class="line-number">' + (i + 1) + '</td><td class="line-content">' + (lines[i] || ' ') + '</td></tr>';
    }
    html += '</table>';
    return html;
  }

  async function loadTex() {
    try {
      const r = await fetch('/tex');
      currentTex = await r.text();
      document.getElementById('sourceCode').innerHTML = renderSourceWithLineNumbers(currentTex);
    } catch(e) {
      document.getElementById('sourceCode').textContent = '% Error loading source.';
    }
  }

  async function checkPreview() {
    try {
      const r = await fetch('/preview.png', {method:'HEAD'});
      if (r.ok) { const img = document.getElementById('previewImg'); img.src = '/preview.png?' + Date.now(); img.style.display = 'block'; }
    } catch(e) {}
  }

  async function submitEdit() {
    const input = document.getElementById('editInput');
    const text = input.value.trim();
    if (!text) return;
    const btn = document.getElementById('editBtn');
    const dot = document.getElementById('statusDot');
    const st = document.getElementById('statusText');
    btn.disabled = true; input.disabled = true;
    dot.classList.add('working'); st.textContent = 'Claude is editing...';
    const reqText = text; input.value = '';
    updateCharCount();
    try {
      const imagePaths = uploadedImages.map(i => i.path);
      const r = await fetch('/request', {method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({request:reqText, images:imagePaths})});
      const d = await r.json();
      if (d.tex) { currentTex = d.tex; document.getElementById('sourceCode').innerHTML = renderSourceWithLineNumbers(currentTex); }
      addHistory(reqText, d.summary || 'Done');
      checkPreview();
    } catch(e) { addHistory(reqText, 'Error: ' + e.message, true); }
    finally { btn.disabled = false; input.disabled = false; dot.classList.remove('working'); st.textContent = 'Ready'; input.focus(); uploadedImages = []; renderUploadPreviews(); }
  }

  function addHistory(req, res, isError) {
    const el = document.createElement('div');
    el.className = 'h-item';
    el.innerHTML = `<div class="h-req">${esc(req)}</div><div class="h-res" ${isError?'style="color:var(--red)"':''}>${esc(res)}</div>`;
    document.getElementById('historyList').prepend(el);
  }

  function esc(s) { return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }

  function copyTex() {
    navigator.clipboard.writeText(currentTex).then(() => {
      const b = event.target; const o = b.textContent; b.textContent = 'Copied'; setTimeout(() => b.textContent = o, 1200);
    });
  }

  function downloadTex() {
    const a = document.createElement('a');
    a.href = URL.createObjectURL(new Blob([currentTex], {type:'text/x-tex'}));
    a.download = 'cheatsheet.tex'; a.click(); URL.revokeObjectURL(a.href);
  }

  async function finish() {
    try { await fetch('/quit', {method:'POST'}); } catch(e) {}
    document.getElementById('doneOverlay').classList.add('show');
  }

  document.addEventListener('keydown', e => { if (e.ctrlKey && e.key === 'Enter') { e.preventDefault(); submitEdit(); } });

  // --- Character count ---
  function updateCharCount() {
    const len = document.getElementById('editInput').value.length;
    document.getElementById('charCount').textContent = len + ' char' + (len !== 1 ? 's' : '');
  }
  document.getElementById('editInput').addEventListener('input', updateCharCount);

  // --- Edit button ripple effect ---
  document.getElementById('editBtn').addEventListener('click', function(e) {
    const btn = this;
    const rect = btn.getBoundingClientRect();
    const ripple = document.createElement('span');
    ripple.className = 'ripple';
    const size = Math.max(rect.width, rect.height);
    ripple.style.width = ripple.style.height = size + 'px';
    ripple.style.left = (e.clientX - rect.left - size / 2) + 'px';
    ripple.style.top = (e.clientY - rect.top - size / 2) + 'px';
    btn.appendChild(ripple);
    ripple.addEventListener('animationend', () => ripple.remove());
  });

  // --- Image upload ---
  let uploadedImages = []; // array of {name, path} after upload

  const uploadArea = document.getElementById('uploadArea');
  const fileInput = document.getElementById('fileInput');
  const uploadPreviews = document.getElementById('uploadPreviews');

  // Drag and drop
  uploadArea.addEventListener('dragover', e => { e.preventDefault(); uploadArea.classList.add('dragover'); });
  uploadArea.addEventListener('dragleave', () => uploadArea.classList.remove('dragover'));
  uploadArea.addEventListener('drop', e => {
    e.preventDefault();
    uploadArea.classList.remove('dragover');
    handleFiles(e.dataTransfer.files);
  });

  fileInput.addEventListener('change', () => { handleFiles(fileInput.files); fileInput.value = ''; });

  async function handleFiles(files) {
    for (const file of files) {
      const formData = new FormData();
      formData.append('image', file);
      try {
        const r = await fetch('/upload_image', { method: 'POST', body: formData });
        const d = await r.json();
        if (d.path) {
          const isImage = file.type.startsWith('image/');
          uploadedImages.push({ name: d.name || file.name, path: d.path, isImage });
          renderUploadPreviews();
        }
      } catch(e) { console.error('Upload failed:', e); }
    }
  }

  function renderUploadPreviews() {
    uploadPreviews.innerHTML = '';
    uploadedImages.forEach((img, idx) => {
      const wrap = document.createElement('div');
      wrap.className = 'upload-thumb-wrap';
      if (img.isImage) {
        wrap.innerHTML = `<img class="upload-thumb" src="/uploaded/${encodeURIComponent(img.name)}" alt="${esc(img.name)}" title="${esc(img.name)}"><button class="upload-remove" onclick="removeUpload(${idx})">&times;</button>`;
      } else {
        const ext = img.name.split('.').pop().toUpperCase();
        wrap.innerHTML = `<div class="upload-file-icon" title="${esc(img.name)}">${esc(ext)}<br>${esc(img.name.substring(0,12))}</div><button class="upload-remove" onclick="removeUpload(${idx})">&times;</button>`;
      }
      uploadPreviews.appendChild(wrap);
    });
  }

  // Paste support (Ctrl+V screenshots or files)
  document.addEventListener('paste', e => {
    const items = e.clipboardData?.items;
    if (!items) return;
    const files = [];
    for (const item of items) {
      if (item.kind === 'file') {
        const file = item.getAsFile();
        if (file) files.push(file);
      }
    }
    if (files.length > 0) {
      e.preventDefault();
      handleFiles(files);
    }
  });

  function removeUpload(idx) {
    uploadedImages.splice(idx, 1);
    renderUploadPreviews();
  }

  function showOverleafGuide() {
    document.getElementById('overleafModal').classList.add('show');
  }

  function closeOverleafGuide() {
    document.getElementById('overleafModal').classList.remove('show');
  }

  // Close modal on backdrop click
  document.getElementById('overleafModal').addEventListener('click', e => {
    if (e.target === document.getElementById('overleafModal')) closeOverleafGuide();
  });

  // Close modal on Escape key
  document.addEventListener('keydown', e => {
    if (e.key === 'Escape') closeOverleafGuide();
  });

  loadTex(); checkPreview();
</script>
</body>
</html>
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall