Tweaks

From wolfenazz/YzPzCode · View interactive version

Tweaks is an AI agent skill from the GitHub repository wolfenazz/YzPzCode. Wrap any HTML artifact with a side panel of live, parameterized controls — accent color, type scale, density, motion, theme — that rewrite CSS custom properties in real time and persist to localStorage. Lets the user explore variants of a design without re-prompting the agent. Use when the brief ask

How to use this skill

Skill file

Tweaks Skill · 参数化变体面板

Wrap any HTML artifact with a side panel of live controls that rewrite

CSS custom properties in real time and persist to localStorage.

Inspired by the huashu-design tweak pattern.

What you produce

A single self-contained HTML file with two layers:

  1. Stage — the original artifact (landing page / deck / dashboard)

re-keyed so all visual decisions read from CSS custom properties:

--accent, --scale, --density, --mode, --motion.

  1. Panel — a fixed sidebar (or drawer on small viewports) with

form controls bound to those custom properties via a tiny

vanilla-JS bridge. Persists every change to localStorage keyed

by the artifact identifier.

The user can:

preferences (or sensible defaults).

watch the stage update instantly — no rerender.

reset to defaults.

When to use

in the last 20% themselves.

feel the variants live (instead of you re-running the agent).

want viewers to play.

When *not* to use

parameters don't help).

with carefully balanced data viz — knobs would degrade it).

The 5 standard knobs

Pick a subset that suits the artifact. Don't ship all 5 if only 2

matter — clutter is a regression.

1. `--accent` — Accent color

A select with 5–8 curated swatches (don't ship a free color picker —

the user will pick a bad color and blame you).

const ACCENT_PRESETS = [
  { id: 'rust',    val: '#c96442', label: 'Rust' },
  { id: 'cobalt',  val: '#2c4d8e', label: 'Cobalt' },
  { id: 'sage',    val: '#4a7a3f', label: 'Sage' },
  { id: 'plum',    val: '#7a3f6a', label: 'Plum' },
  { id: 'graphite',val: '#3a3a3a', label: 'Graphite' },
];

The artifact uses var(--accent) everywhere it had a hard-coded

accent before. Border / link / pull-quote rule / CTA all flip

together.

2. `--scale` — Type scale (0.85 / 1.0 / 1.15)

Three settings: Compact (0.85), Normal (1.0), Generous (1.15).

All font-size declarations multiply by var(--scale) via

calc(... * var(--scale)).

Don't go beyond ±15% — beyond that the layout breaks (column flow,

breakpoints, line counts).

3. `--density` — Layout density (Tight / Normal / Roomy)

Three settings that swap the spacing scale: Tight (0.75) /

Normal (1.0) / Roomy (1.4). All padding / gap / margin

declarations multiply by var(--density).

This is the highest-impact knob — it's also the most fragile, so

**every layout-critical container must declare its base spacing in

custom properties** before you wrap.

4. `--mode` — Light / Dark

A 2-state toggle. Sets data-mode="light" vs "dark" on the

<html> element and the artifact's :root selector responds with

two color sets.

If the artifact already has a media-query-based dark mode, replace

it with the data-attr version — the user's choice should win over

their OS.

5. `--motion` — Off / Subtle / Lively

Three settings. Maps to a CSS variable --motion-mult that scales

all transition-duration / animation-duration declarations:

Respect prefers-reduced-motion: default to Off if the user has

that set, regardless of stored preference.

Host integration contract (REQUIRED)

The Open Design viewer toolbar has a Tweaks toggle that drives panel

visibility from outside the iframe. For the toggle to bind to your panel,

your artifact must speak one of these two protocols (pick one; don't

mix). The toolbar enables itself the moment it sees either signal.

Protocol A — postMessage (recommended for agent-generated artifacts)

Use this when the panel mounts via JS (React, vanilla, anything dynamic).

Artifact → host:

window.parent. Tells the toolbar a panel exists; the optional visible

reports the panel's initial state so the toolbar toggle starts in sync.

Omit visible for the common "panel is already on screen" case (the host

treats a missing field as true so the legacy zero-arg message keeps

working). Pass visible: false to declare a default-closed panel.

{ type: '__edit_mode_dismissed' }. Toolbar flips to "off".

Host → artifact:

Minimal listener:

window.addEventListener('message', (e) => {
  const t = e?.data?.type;
  if (t === '__activate_edit_mode') setOpen(true);
  else if (t === '__deactivate_edit_mode') setOpen(false);
});
// Or, for a default-closed panel:
//   window.parent.postMessage({ type: '__edit_mode_available', visible: open }, '*');
window.parent.postMessage({ type: '__edit_mode_available' }, '*');
// in your close handler:
const dismiss = () => {
  setOpen(false);
  window.parent.postMessage({ type: '__edit_mode_dismissed' }, '*');
};

Panel may default to open or closed — the host syncs its toggle to

whichever state the artifact reports.

Protocol B — class-based (used by `assets/wrap.html`)

Use this only when you wrap the template verbatim. The artifact ships a

.tw-panel element and toggles a .tw-hidden class for visibility. The

viewer's iframe bridge (in apps/web/src/runtime/srcdoc.ts) hides the

panel on initial paint, watches the class via MutationObserver, and

relays state both directions. No JS required in the artifact beyond what

the template already includes.

Selectors are fixed: .tw-panel (the panel root) and .tw-hidden (the

hidden state). If you rename either, the bridge can't find it.

Anti-pattern

Don't invent a third protocol or rename either set of identifiers. The

toolbar toggle only binds to A or B. Custom panels with custom classes

and no postMessage will leave the toolbar greyed out.

Implementation primitives

Read assets/wrap.html — it ships the panel + bridge as an

inert template. Your job is to:

  1. Take the user's existing artifact HTML.
  2. Lift its accent / mode / spacing / scale into custom properties

(search for hard-coded #hex / Npx / Nrem and convert).

  1. Paste the contents into the marked region of wrap.html.
  2. Edit assets/wrap.html's KNOBS array to keep only the knobs

you decided are relevant to this artifact. Don't ship 5 if 2

matter.

  1. Patch the STORAGE_KEY to a unique slug (tweaks-<artifact-slug>).

The bridge in wrap.html:

Workflow

Step 1 — Acquire the artifact

Same options as the critique skill:

  1. Project file (index.html in the project folder).
  2. Pasted HTML in the chat.
  3. Generated by you in this turn.

Step 2 — Decide which knobs apply

Read the artifact's CSS first. For each knob, decide yes / no:

pricing page).

rhythm (deck, dashboard, landing). No for runbooks (already dense).

you're willing to derive them.

worth scaling. No for static reports / critique reports.

Default: 3 knobs is the sweet spot. Five is too busy, one is

not worth a panel.

Step 3 — Lift hard-coded values into custom properties

Open assets/wrap.html's <style> block — copy its custom-property

naming scheme (--accent, --scale, etc.). In the user's artifact,

find every place those concerns live and rewrite:

If the artifact uses clamp() or vw already, multiply the

outer value by the custom property — don't tear apart clamp(...).

Step 4 — Paste into the wrap

Copy the artifact's <style> and <body> into the marked regions

of wrap.html. Keep the panel + bridge intact.

Step 5 — Test the loop

Open the result, click each knob at least once, refresh the page,

confirm the choice persists. If a knob breaks the layout —

remove it, don't ship it.

Output contract

<artifact identifier="tweaks-<artifact-slug>" type="text/html" title="<Artifact Title> · Tweaks">
<!doctype html>
<html>...</html>
</artifact>

One sentence before the artifact ("Wrapped X with a 3-knob tweak

panel — accent / scale / mode."). Stop after </artifact>.

Hard rules

pick bad colors when given freedom; saving them from that is the

whole point.

key. Two artifacts open in two tabs must not share state.

if the user has that set, override only on explicit click.

existing imports. Inline the panel + bridge.

via a "T" button at top-right.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.