Command Palette

Search for a command to run...

Назад к скиллам
скилл № 95948

lc-algo-demo

Add or edit an algorithm visualizer under algo_demo/ against the shared contract the other 36 pages already obey — colours read from the VIZ palette and never…

БесплатноБез исполняемых скриптов
yennanliuот yennanliu★ 141 звезда на GitHub

Установить lc-algo-demo в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Add an algorithm visualizer

Write a page into algo_demo/ that behaves like the other 36.

Invocation: /lc-algo-demo <algorithm> — e.g. /lc-algo-demo trie.

Why the contract matters here specifically

algo_demo/ is 36 hand-written pages plus common.js and style.css, with no generator. site/build.sh copies the directory wholesale. So nothing compiles these pages, nothing templates them, and every shared behaviour is held together by convention alone — which means a page that reimplements one of them looks fine in isolation and is wrong the moment the theme changes, the window resizes, or someone repaints the palette.

Anything that should look or behave the same on all 37 pages belongs in common.js or style.css, never copy-pasted into a page's inline <script>.

site/test/algo-demo.test.js evaluates the shipped common.js in jsdom and asserts against it, so a change to the shared files is testable. A change copy-pasted into a page is not.

Prime directives

  1. Never hardcode a colour. Canvases read from VIZ — the --viz-* tokens — so both themes and any repaint stay in one place. A literal #3b82f6 is invisible in review and wrong in the other theme.
  2. Do not reimplement what getContext('2d') already gives you. It is wrapped once, for every page: the backing store is scaled to devicePixelRatio behind width/height accessors (a page still writes and reads CSS pixels), and the font setter rewrites the generic families to the site's face. Both fixes therefore reach pages written before either existed. Re-doing the scaling double-scales it.
  3. draw = VIZ.repaintable(draw) for any draw() that takes arguments, plus window.addEventListener('resize', draw.repaint). Handing draw straight to addEventListener passes it the resize Event as its first drawing argument, and calling it with reset arguments throws the highlight away. A theme switch fires a resize, so either way the picture reverts mid-run.
  4. The trace lives in .viz-trace, below the canvas, full width. It was once in the 300px control column, where L=4 R=24 sum=28 wrapped three times and four steps filled the box. Put it back there and the trace stops being readable.
  5. Write the trace in the shapes the logger understands — otherwise it renders as a flat run of divs, which is what it was before.

The step trace's three shapes

createLogger(id)'s contract is still clear() and log(html, cls). What it does with the message depends on its shape:

Written Rendered as
logger.log('L=4 R=24 sum=28') a numbered step
logger.log('&nbsp;&nbsp;sum > target → move R') the reason, indented and tucked under the step above it
logger.log('--- Iteration 2 ---') a phase heading
logger.log('<span class="highlight">Found!</span>') the run's outcome
logger.log('') ignored — rows are already spaced

The leading &nbsp; does most of the work: it turns a step and the decision it led to from two equal-weight lines into one row.

The outcome test is the message being entirely one highlight span. Pages also use that span mid-sentence to pick out a value — Process node <span class="highlight">1</span> dist=7 — and treating those as outcomes flags nine rows in ten, which marks nothing. Use the whole-message form once per run, for the result.

The logger also auto-decorates name=value pairs and → ← ⇒ arrows inside a step, so write them plainly rather than marking them up.

The steps

1. Read a neighbour, and common.js

ls algo_demo/

Open a page that visualizes the same shape of thing — an array walk (kadane.html, sliding-window.html, two-pointers.html), a grid (bfs.html, multi-source-bfs.html), a tree (binary-tree-traversal.html, lca.html), a graph (dijkstra.html, topological-sort.html) — and match it. Then read common.js's header comment, which names the three things you get for free.

2. Check the helper does not already exist

Before writing a drawing helper, look for it. VIZ already provides bar, axis, pointer, region, readout, on(bg), alpha(color, a), font(px, weight) and categorical, plus sleep, shuffle and randomArray. A page-local re-implementation of any of them is a divergence waiting to happen.

3. Write algo_demo/<name>.html

Match the page skeleton exactly — it is what the navbar, breadcrumbs and trace panel hang off:

<script src="../nav.js"></script>          <!-- before common.js, always -->
<script src="common.js"></script>
...
<div id="site-nav" data-page="visualizer" data-base="../"></div>
<script>CSNav.mount();</script>
<main class="container">
  <div class="breadcrumbs">…<span class="current">Your Algorithm</span></div>
  <div class="page-header">…</div>
  <div class="viz-wrapper">
    <div class="viz-canvas-area"><canvas id="canvas"></canvas></div>
    <d
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

  1. 01Read
  2. 02Glob
  3. 03Grep
  4. 04Bash
  5. 05Write
  6. 06Edit

FAQ

Что делает скилл lc-algo-demo?

Add or edit an algorithm visualizer under algo_demo/ against the shared contract the other 36 pages already obey — colours read from the VIZ palette and never hardcoded, no re-implementation of the devicePixelRatio canvas wrapper, the step trace written in the three shapes createLogger renders as structure, the trace in its own full-width panel below the canvas, and `draw = VIZ.repaintable(draw)` for any draw() that takes arguments. Use when asked to add a visualizer, animate an algorithm, build a demo page, or change something that should look the same on every visualizer. Triggers - "add a visualizer for Dijkstra", "/lc-algo-demo trie", "animate the sliding window", "the trace is unreadable on the segment tree page".

Как установить скилл lc-algo-demo?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл lc-algo-demo запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить lc-algo-demo с