mirror of
https://github.com/nexu-io/open-design.git
synced 2026-10-27 09:51:12 +01:00
* feat: general-purpose skills with @-mention composition and user import
Lift skills from "one mode-bound skill per project" to a generic capability
the user can compose per turn:
- Daemon: scan multiple skill roots (user-skills under runtime data, then
the bundled `skills/`); user-imported skills can shadow built-ins by id.
- New `POST /api/skills/import` and `DELETE /api/skills/:id` endpoints,
with CONFLICT/BAD_REQUEST/NOT_FOUND error codes and built-in delete
protection.
- ChatRequest gains `skillIds: string[]`; the chat run concatenates each
picked skill's body (and merges craftRequires) into the system prompt
for that turn only — the project's persistent `skillId` is untouched.
- Web composer: `@` popover now lists skills alongside project files;
picks render as removable chips above the textarea and ride along with
the request as `skillIds`.
- Settings → Library: import form (name/description/triggers/body),
per-card delete for user skills, "user" origin badge.
* chore(web): drop welcome pet teaser + add ds→prompt-template mapping util
- SettingsDialog: remove the inline pet adoption teaser from the welcome
panel so the first-run modal stays focused on configuration.
- New `inferPromptTemplateCategoriesForDs(ds)` helper that maps a design
system's authored metadata to prompt-template gallery categories.
Imported by the design-system gallery wiring on a sibling branch; no
callers in this branch yet.
* feat: split skills/design-templates and add finalize-design API
Phase 0 of the skills/design-templates refactor (specs/current/
skills-and-design-templates.md):
- Move ~104 rendering catalogue entries from skills/ to design-templates/
and keep skills/ for the small set of functional skills that *do work*
on user input (utilities, briefs, packagers).
- Add design-templates/AGENTS.md and skills/AGENTS.md describing the
contract, and a brand-agnostic craft/ surface for opt-in craft rules.
- Daemon: add DESIGN_TEMPLATES_DIR / USER_DESIGN_TEMPLATES_DIR roots and
an /api/design-templates surface mirroring /api/skills. Asset/example
routes still span both registries so existing srcdoc URLs keep
resolving across the rename.
- Web: split LibrarySection into SkillsSection + DesignSystemsSection,
rename the EntryView "Examples" tab to "Templates", and update locales
+ the New-project picker accordingly.
Adds the finalize-design endpoint:
- New apps/daemon/src/finalize-design.ts and packages/contracts/src/api/
finalize.ts — one-shot synthesis of a project's transcript + active
design system + current artifact into <projectDir>/DESIGN.md via the
Anthropic Messages API. Per-project .finalize.lock mirrors the
transcript-export hygiene from PR #493; provider credentials are not
persisted by the daemon.
Other supporting changes:
- README + AGENTS.md updates to document the new directory split and
craft/ surface, plus i18n strings across 13 locales.
- Test refactors and new coverage (finalize-design, runs, sidecar
server, plus refreshed daemon integration tests).
- .gitignore: scope the *.exe ignore to /OpenDesign.exe so legitimate
vendor binaries are no longer hidden.
* fix(merge): move clinical-case-report to design-templates/
Origin/main added the clinical-case-report skill under skills/ before
the skills/design-templates split landed. Its od.mode is prototype, so
per specs/current/skills-and-design-templates.md it is a design template
and belongs alongside the other rendering catalogue entries — not under
the slimmed-down functional skills/ root. Moving it keeps the EntryView
Templates tab consistent with origin/main's intent.
* feat(skills): curated design/creative catalogue + collapsible Settings rows
Seed ~100 curated design/creative skill stubs under skills/ sourced from
awesome-claude-skills (ComposioHQ) and awesome-agent-skills (VoltAgent).
Each stub carries an od.category tag so the new filter pill row in
Settings -> Skills can group them. The seed script
(scripts/seed-curated-design-skills.ts, pnpm seed:curated-design-skills)
is idempotent: it only creates folders that don't already exist, so
hand-edited stubs are never overwritten.
- Daemon: parse and surface od.category on SkillInfo with a strict slug
normaliser; mirror the field on SkillSummary in @open-design/contracts.
Category is purely a UI hint — system-prompt composition is unchanged.
- Web: rewrite SkillsSection from a left-list / right-detail grid into a
vertical stack of collapsible rows mirroring the External MCP panel
(header always visible with name + mode/source/category pills + per-row
enable toggle; SKILL.md preview, file tree and inline edit form expand
on demand). Add a Category filter row above the list. Reorder Settings
nav so Skills + External MCP sit above the Composio/MCP cluster. Update
composer placeholder/hint across 17 locales to advertise '@ files or
skills · / for commands'.
- Docs: extend skills/AGENTS.md with the curated catalogue rules
(idempotency, category vocabulary, no upstream vendoring).
Co-authored-by: Cursor <cursoragent@cursor.com>
* test(skills): teach localized-content + system-prompt tests about the skills/design-templates split
mrcfps blocking review on PR #955: the skills/design-templates split
(b5993385) moved ~110 SKILL.md entries out of `skills/` and into
`design-templates/`, but two repo-level tests still hard-coded the
single-root layout, so CI gates went red on the merged branch:
- `e2e/tests/localized-content.test.ts` only scanned `<repo>/skills`
while the locale `skillCopy` map keeps id-keyed entries spanning
both roots (ExamplesTab/Templates uses one lookup regardless of
origin). Teach the helper to read both `skills/` and
`design-templates/`, deduplicating ids so the union matches the
localized claim.
- `apps/daemon/tests/prompts/system.test.ts` read
`skills/live-artifact/SKILL.md`, which now lives under
`design-templates/live-artifact/`. Update the absolute path so
composeSystemPrompt's coverage of the live-artifact preamble is
exercised again.
Also enroll the curated design/creative catalogue (PR #955, ~91
stubs sourced from awesome-claude-skills / awesome-agent-skills) in
the DE / FR / RU `_SKILL_IDS_WITH_EN_FALLBACK` lists. The stubs are
English-only by design (frontmatter advertises an upstream URL); the
fallback list is exactly the place to acknowledge "we know this id
exists, English copy is fine here" so the localized-content coverage
gate passes without forcing a translation task per locale.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(skills): always quote frontmatter name so importUserSkill round-trips numeric / boolean ids
mrcfps PR #955 review: `buildSkillMarkdown` emitted `name:
${escapeYamlString(name)}` without quotes, so YAML coerced names
like `123`, `true`, `false`, or `null` into non-string scalars on
re-parse. listSkills() then read `data.name` as a number/boolean
and the import flow's follow-up `findSkillById(skills, result.id)`
missed it, falling into `/api/skills/import`'s "imported skill
could not be re-read" 500 path for those ids.
Switch the emitter to a quoted scalar (`name: "..."`) — the
double-escape already in `escapeYamlString` makes the quoted form
safe — and add a round-trip test covering `123`, `true`, `false`,
`null`, and `0` to lock in the contract.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(web): drop staged-skill chips when the matching @<id> token leaves the draft
mrcfps PR #955 review: `submit()` always forwarded every id in
`stagedSkills`, but that state was only mutated on picker click and
chip removal. Hand-deleting an `@<id>` token from the textarea left
the chip staged, so the request still carried `skillIds: [<id>]` and
the daemon composed a skill the prompt no longer referenced.
Sync the chips with the draft inside `handleChange()` by pruning
`stagedSkills` whenever the new value no longer contains the
`@<id>` token (using the same whitespace boundary as
`removeStagedSkill`'s strip regex). Comment explains why this
prune does not run for `staged` file attachments — users frequently
add files via the upload button without leaving an `@<path>` token,
so a symmetric prune there would erase legitimate uploads.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(daemon): stage @-composed skills' side files alongside the active skill
codex PR #955 review: composing a per-turn `@`-picked skill into the
system prompt appended its body (with the `withSkillRootPreamble`
guidance pointing at relative paths under `<cwd>/.od-skills/<folder>/`)
but never staged the actual folder. `startChatRun` only copied
`activeSkillDir`, so when the project's primary skill was different
(or absent) the composed skill's references/, examples/, and scripts/
files lived only at their absolute repo path — agents that honour
the cwd-relative form (or that don't get `--add-dir`, e.g. Codex with
allowlisted gpt-image projects) couldn't reach them.
Thread the composed skills' dirs out of `composeDaemonSystemPrompt`
as `extraSkillDirs` and stage each one through the same
`stageActiveSkill` API used for the primary skill. Dedupe by folder
basename so a project whose primary skill is also `@`-composed isn't
copied twice. Each preamble already advertises its own folder, so the
prompt and the staged tree stay aligned without further changes.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(web): respect the Library disable toggle in the project @-mention picker
codex PR #955 review: only `EntryView` received `enabledSkills`
(filtered against `config.disabledSkills`); active projects still
got `skills={skills}` raw, so a skill the user disabled in Settings
kept appearing in the project's `@`-mention popover and could ride
along to the daemon via `skillIds`. That broke the Library toggle
for any project opened on the post-split branch.
Compute a functional-skills-only enabled subset
(`enabledFunctionalSkills`) and pass it into `<ProjectView>` instead.
Templates stay separate — design-templates are filtered through their
own `enabledDesignTemplates` memo for the Templates gallery — so
ProjectView's chat composer still only sees skills, never templates,
matching the pre-split prop surface.
Co-authored-by: Cursor <cursoragent@cursor.com>
* test(e2e): mock /api/design-templates for example-use-prompt flow
The Templates tab in EntryView fetches from /api/design-templates after
the skills/design-templates split (specs/current/skills-and-design-templates.md).
The example-use-prompt Playwright scenario only mocked /api/skills, so the
gallery card never appeared and the test timed out waiting on
example-card-warm-utility-example. Serve the same fixture summary on both
endpoints so the templates gallery renders the card the test clicks.
Co-authored-by: Cursor <cursoragent@cursor.com>
* test(tools-pack): create design-templates fixture for resources test
The packaging resources copy now bundles the new design-templates tree
alongside skills (see resources.ts BUNDLED_RESOURCE_TREES). The
copyBundledResourceTrees fixture only created skills, design-systems,
craft, etc., so the recursive copy crashed with ENOENT on
design-templates before it could check the prompt-templates assertion.
Add the missing fixture directory so the test exercises the same set
of resource trees the packaged build does.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(skills): clone built-in side files into the shadow on first edit
mrcfps PR #955 review: editing a built-in skill wrote a USER_SKILLS_DIR
shadow folder that contained only a new SKILL.md. The next listSkills()
pass surfaced the shadow as the active dir, but every side-file resolver
(/api/skills/:id/files, /example, /assets/*, the system-prompt preamble,
and the per-turn cwd staging) reads through skill.dir. With nothing but
SKILL.md in the shadow, the bundled assets/, references/, scripts/, and
examples/ disappeared the moment the user hit save — a built-in like
last30days or live-artifact would break immediately after edit instead
of just having its body overridden.
Teach updateUserSkill() to take a `sourceDir` and clone every entry
except SKILL.md / dotfiles into the shadow on the very first edit. The
shadow stays self-contained, so all the resolvers keep working without
fallback bookkeeping. Subsequent edits detect the existing shadow and
skip the clone, so user tweaks under the side tree survive a re-save.
Wire `sourceDir: skill.dir` from server.ts's PUT /api/skills/:id handler
and add two regression tests:
- 'clones built-in side files into the shadow on the first edit' walks
the file tree after save and asserts assets/template.html, references/
notes.md, and scripts/helper.sh all round-trip from the built-in.
- 'preserves user-edited side files on subsequent edits' edits the
staged assets/template.html, re-saves, and confirms the user content
is still there.
Co-authored-by: Cursor <cursoragent@cursor.com>
* test(e2e): rename home tab from Examples to Templates
The Examples tab was renamed to Templates in EntryView (b5993385's
skills/design-templates split — entry.tabExamples became entry.tabTemplates
and the tab value moved from 'examples' to 'templates'), but
entry-chrome-flows still asserted the old label and testId. Update both.
* fix(skills+web): preserve template body in API mode and dir-based skill delete
Two follow-ups from PR #955 review:
1. ProjectView only received `enabledFunctionalSkills`, but
`composedSystemPrompt()` still resolved `project.skillId` through that
prop and `fetchSkill()`. Projects created from the new
`/api/design-templates` surface keep a template id in `project.skillId`,
so opening one in API mode dropped the template body from the system
prompt and the upstream request ran without the project's primary
template instructions. Now ProjectView takes a separate
`designTemplates` prop (the unfiltered template list, so a
later-disabled template still loads for projects already created from
it) and `composedSystemPrompt()` plus the metadata / `isDeck` lookups
fall back to that list, with `fetchDesignTemplate()` as the body-fetch
fallback to `fetchSkill()`. The chat composer's `@`-picker keeps
receiving only the enabled functional skills.
2. `DELETE /api/skills/:id` used `deleteUserSkill(USER_SKILLS_DIR, skill.id)`
which re-slugified the frontmatter id and removed
`<userSkillsDir>/<slug>/`. That matched the import shape but missed the
install shape — `installFromTarget` writes the folder at
`sanitizeRepoName(url)` (GitHub) or `path.basename(realpath)` (local
symlink), neither of which is guaranteed to equal the slugified
frontmatter `name`. A duplicate `app.delete('/api/skills/:id', ...)`
handler at the install routes never fired because Express resolved the
earlier registration first, leaving the install/uninstall path without
working teardown. The handler now removes `skill.dir` (the absolute
path listSkills already discovered) under a USER_SKILLS_DIR safety
check, using `lstat` + `unlinkSync` so symlinked local installs unlink
cleanly without recursing into the user's source tree. The dead
duplicate handler is removed; `deleteUserSkill` is dropped from the
server.ts import set (still exported and unit-tested in skills.ts).
Regression coverage in `apps/daemon/tests/skills-delete-route.test.ts`
pins both shapes plus the symlink-preserves-source case.
* test(daemon): point hyperframes system-prompt test at design-templates
The merge with main brought in a hyperframes system-prompt test that
reads `skills/hyperframes/SKILL.md`, but this branch's split moved
`hyperframes` into `design-templates/` (same migration as `live-artifact`
already handled above in this file). CI was failing with ENOENT on the
old path.
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
438 lines
14 KiB
HTML
438 lines
14 KiB
HTML
<!doctype html>
|
||
<html lang="en" data-mode="light">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
<title>[ARTIFACT TITLE] · Tweaks</title>
|
||
<style>
|
||
/* =========================================================
|
||
TWEAKS · WRAP TEMPLATE
|
||
=========================================================
|
||
This file is a skeleton. Workflow:
|
||
1. Replace [ARTIFACT TITLE] in <title>.
|
||
2. Update STORAGE_KEY in the script (tweaks-<artifact-slug>).
|
||
3. Decide which knobs apply (1-5 from KNOBS_LIBRARY).
|
||
4. Paste artifact CSS into the [ARTIFACT_STYLE] region.
|
||
5. Paste artifact body into the [ARTIFACT_BODY] region.
|
||
6. Lift hard-coded #hex / Npx / Nrem values to custom
|
||
properties so the knobs actually move.
|
||
========================================================= */
|
||
|
||
:root {
|
||
/* ---------- Knob defaults (overridden by JS bridge) ---------- */
|
||
--accent: #c96442;
|
||
--scale: 1;
|
||
--density: 1;
|
||
--motion-mult: 1;
|
||
|
||
/* ---------- Light theme tokens ---------- */
|
||
--bg: #f6f4ef;
|
||
--paper: #ffffff;
|
||
--ink: #1a1a1c;
|
||
--muted: #6b6964;
|
||
--rule: #e2dfd7;
|
||
}
|
||
[data-mode="dark"] {
|
||
--bg: #0e0d0c;
|
||
--paper: #181715;
|
||
--ink: #f4f1ea;
|
||
--muted: #8a857a;
|
||
--rule: #2a2723;
|
||
}
|
||
|
||
@media (prefers-reduced-motion: reduce) {
|
||
:root { --motion-mult: 0; }
|
||
}
|
||
|
||
* { box-sizing: border-box; }
|
||
html, body { margin: 0; padding: 0; min-height: 100%; }
|
||
body {
|
||
background: var(--bg);
|
||
color: var(--ink);
|
||
font-family: 'Inter', -apple-system, system-ui, sans-serif;
|
||
font-size: calc(16px * var(--scale));
|
||
line-height: 1.55;
|
||
transition: background calc(220ms * var(--motion-mult)) ease,
|
||
color calc(220ms * var(--motion-mult)) ease;
|
||
}
|
||
|
||
/* =========================================================
|
||
[ARTIFACT_STYLE] — paste artifact-specific CSS here
|
||
========================================================= */
|
||
|
||
/* =========================================================
|
||
PANEL · fixed sidebar with knobs
|
||
========================================================= */
|
||
.tw-panel {
|
||
position: fixed;
|
||
top: 16px;
|
||
right: 16px;
|
||
z-index: 100;
|
||
width: 280px;
|
||
max-width: calc(100vw - 32px);
|
||
background: var(--paper);
|
||
border: 1px solid var(--rule);
|
||
border-radius: 8px;
|
||
box-shadow: 0 8px 32px rgba(0,0,0,0.08);
|
||
font-family: 'Inter', system-ui, sans-serif;
|
||
transition: transform calc(220ms * var(--motion-mult)) cubic-bezier(.2,.8,.2,1),
|
||
opacity calc(220ms * var(--motion-mult)) ease;
|
||
}
|
||
[data-mode="dark"] .tw-panel { box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
|
||
.tw-panel.tw-hidden {
|
||
transform: translateX(calc(100% + 32px));
|
||
opacity: 0;
|
||
pointer-events: none;
|
||
}
|
||
.tw-head {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding: 14px 18px;
|
||
border-bottom: 1px solid var(--rule);
|
||
}
|
||
.tw-head .ttl {
|
||
font-family: 'IBM Plex Mono', ui-monospace, monospace;
|
||
font-size: 10px;
|
||
letter-spacing: 0.24em;
|
||
text-transform: uppercase;
|
||
color: var(--muted);
|
||
}
|
||
.tw-head .toggle {
|
||
background: transparent;
|
||
border: 1px solid var(--rule);
|
||
color: var(--muted);
|
||
width: 24px;
|
||
height: 24px;
|
||
border-radius: 4px;
|
||
cursor: pointer;
|
||
font-family: 'IBM Plex Mono', monospace;
|
||
font-size: 11px;
|
||
padding: 0;
|
||
}
|
||
.tw-head .toggle:hover { color: var(--ink); }
|
||
|
||
.tw-body { padding: 14px 18px 18px; }
|
||
|
||
.tw-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
|
||
.tw-row:last-child { margin-bottom: 0; }
|
||
.tw-row .lbl {
|
||
font-family: 'IBM Plex Mono', monospace;
|
||
font-size: 10px;
|
||
letter-spacing: 0.22em;
|
||
text-transform: uppercase;
|
||
color: var(--muted);
|
||
}
|
||
|
||
/* Segmented control */
|
||
.tw-seg {
|
||
display: flex;
|
||
border: 1px solid var(--rule);
|
||
border-radius: 5px;
|
||
overflow: hidden;
|
||
background: var(--bg);
|
||
}
|
||
.tw-seg button {
|
||
flex: 1;
|
||
padding: 7px 8px;
|
||
background: transparent;
|
||
border: 0;
|
||
border-left: 1px solid var(--rule);
|
||
cursor: pointer;
|
||
font-family: 'Inter', system-ui, sans-serif;
|
||
font-size: 12px;
|
||
font-weight: 500;
|
||
color: var(--muted);
|
||
transition: color calc(180ms * var(--motion-mult)) ease,
|
||
background calc(180ms * var(--motion-mult)) ease;
|
||
}
|
||
.tw-seg button:first-child { border-left: 0; }
|
||
.tw-seg button:hover { color: var(--ink); }
|
||
.tw-seg button[aria-pressed="true"] {
|
||
background: var(--paper);
|
||
color: var(--ink);
|
||
box-shadow: inset 0 -2px 0 var(--accent);
|
||
}
|
||
|
||
/* Swatch grid */
|
||
.tw-swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
|
||
.tw-swatch {
|
||
width: 100%;
|
||
aspect-ratio: 1;
|
||
border: 2px solid transparent;
|
||
border-radius: 5px;
|
||
cursor: pointer;
|
||
padding: 0;
|
||
transition: transform calc(160ms * var(--motion-mult)) ease,
|
||
border-color calc(160ms * var(--motion-mult)) ease;
|
||
}
|
||
.tw-swatch:hover { transform: scale(1.06); }
|
||
.tw-swatch[aria-pressed="true"] { border-color: var(--ink); }
|
||
|
||
/* Mini toolbar in panel footer */
|
||
.tw-foot {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding: 10px 18px;
|
||
border-top: 1px solid var(--rule);
|
||
font-family: 'IBM Plex Mono', monospace;
|
||
font-size: 10px;
|
||
letter-spacing: 0.18em;
|
||
text-transform: uppercase;
|
||
color: var(--muted);
|
||
}
|
||
.tw-foot button {
|
||
background: transparent;
|
||
border: 0;
|
||
color: var(--muted);
|
||
cursor: pointer;
|
||
padding: 0;
|
||
font-family: inherit;
|
||
font-size: inherit;
|
||
letter-spacing: inherit;
|
||
text-transform: inherit;
|
||
}
|
||
.tw-foot button:hover { color: var(--ink); }
|
||
kbd {
|
||
font-family: 'IBM Plex Mono', monospace;
|
||
font-size: 9px;
|
||
padding: 2px 5px;
|
||
border: 1px solid var(--rule);
|
||
border-radius: 3px;
|
||
color: var(--ink);
|
||
}
|
||
|
||
/* When panel is hidden, expose a "T" button at top-right */
|
||
.tw-restore {
|
||
position: fixed;
|
||
top: 16px;
|
||
right: 16px;
|
||
z-index: 100;
|
||
width: 36px;
|
||
height: 36px;
|
||
border-radius: 50%;
|
||
border: 1px solid var(--rule);
|
||
background: var(--paper);
|
||
color: var(--ink);
|
||
font-family: 'IBM Plex Mono', monospace;
|
||
font-size: 13px;
|
||
font-weight: 500;
|
||
cursor: pointer;
|
||
display: none;
|
||
align-items: center;
|
||
justify-content: center;
|
||
transition: transform calc(180ms * var(--motion-mult)) ease;
|
||
}
|
||
.tw-restore:hover { transform: scale(1.06); }
|
||
.tw-restore.tw-show { display: flex; }
|
||
|
||
@media (max-width: 720px) {
|
||
.tw-panel { left: 16px; right: 16px; width: auto; }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<!-- =========================================================
|
||
[ARTIFACT_BODY] — paste artifact-specific markup here
|
||
========================================================= -->
|
||
|
||
<!-- =========================================================
|
||
PANEL — knob controls (drop the rows you don't ship)
|
||
========================================================= -->
|
||
<aside class="tw-panel" id="tw-panel" aria-label="Tweak panel">
|
||
<header class="tw-head">
|
||
<span class="ttl">Tweaks</span>
|
||
<button class="toggle" id="tw-close" aria-label="Hide panel" title="Hide (T)">×</button>
|
||
</header>
|
||
<div class="tw-body">
|
||
|
||
<!-- Accent -->
|
||
<div class="tw-row">
|
||
<span class="lbl">Accent</span>
|
||
<div class="tw-swatches" id="tw-accent" role="radiogroup" aria-label="Accent color"></div>
|
||
</div>
|
||
|
||
<!-- Mode -->
|
||
<div class="tw-row">
|
||
<span class="lbl">Mode</span>
|
||
<div class="tw-seg" id="tw-mode" role="radiogroup" aria-label="Color mode">
|
||
<button data-val="light" aria-pressed="true">Light</button>
|
||
<button data-val="dark" aria-pressed="false">Dark</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Scale -->
|
||
<div class="tw-row">
|
||
<span class="lbl">Type scale</span>
|
||
<div class="tw-seg" id="tw-scale" role="radiogroup" aria-label="Type scale">
|
||
<button data-val="0.85" aria-pressed="false">Compact</button>
|
||
<button data-val="1" aria-pressed="true">Normal</button>
|
||
<button data-val="1.15" aria-pressed="false">Generous</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Density -->
|
||
<div class="tw-row">
|
||
<span class="lbl">Density</span>
|
||
<div class="tw-seg" id="tw-density" role="radiogroup" aria-label="Density">
|
||
<button data-val="0.75" aria-pressed="false">Tight</button>
|
||
<button data-val="1" aria-pressed="true">Normal</button>
|
||
<button data-val="1.4" aria-pressed="false">Roomy</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Motion -->
|
||
<div class="tw-row">
|
||
<span class="lbl">Motion</span>
|
||
<div class="tw-seg" id="tw-motion" role="radiogroup" aria-label="Motion">
|
||
<button data-val="0" aria-pressed="false">Off</button>
|
||
<button data-val="1" aria-pressed="true">Subtle</button>
|
||
<button data-val="1.6" aria-pressed="false">Lively</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<footer class="tw-foot">
|
||
<span><kbd>T</kbd> hide · <kbd>R</kbd> reset</span>
|
||
<button id="tw-reset" type="button">Reset</button>
|
||
</footer>
|
||
</aside>
|
||
|
||
<button class="tw-restore" id="tw-restore" aria-label="Show panel" title="Show panel (T)">T</button>
|
||
|
||
<script>
|
||
// =========================================================
|
||
// BRIDGE — binds knobs ↔ CSS custom props ↔ localStorage
|
||
// =========================================================
|
||
// CHANGE THIS to a unique slug per artifact you wrap.
|
||
const STORAGE_KEY = 'tweaks-default';
|
||
|
||
const ACCENT_PRESETS = [
|
||
{ id: 'rust', val: '#c96442' },
|
||
{ id: 'cobalt', val: '#2c4d8e' },
|
||
{ id: 'sage', val: '#4a7a3f' },
|
||
{ id: 'plum', val: '#7a3f6a' },
|
||
{ id: 'graphite', val: '#3a3a3a' },
|
||
];
|
||
|
||
const DEFAULTS = {
|
||
accent: ACCENT_PRESETS[0].val,
|
||
mode: 'light',
|
||
scale: 1,
|
||
density: 1,
|
||
motion: matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : 1,
|
||
};
|
||
|
||
function load() {
|
||
try {
|
||
const raw = localStorage.getItem(STORAGE_KEY);
|
||
if (!raw) return { ...DEFAULTS };
|
||
return { ...DEFAULTS, ...JSON.parse(raw) };
|
||
} catch { return { ...DEFAULTS }; }
|
||
}
|
||
function save(state) {
|
||
try { localStorage.setItem(STORAGE_KEY, JSON.stringify(state)); }
|
||
catch {}
|
||
}
|
||
|
||
function applyState(s) {
|
||
const root = document.documentElement;
|
||
root.style.setProperty('--accent', s.accent);
|
||
root.style.setProperty('--scale', s.scale);
|
||
root.style.setProperty('--density', s.density);
|
||
root.style.setProperty('--motion-mult', s.motion);
|
||
root.setAttribute('data-mode', s.mode);
|
||
// Reflect to UI
|
||
paintAccent(s.accent);
|
||
paintSeg('tw-mode', s.mode);
|
||
paintSeg('tw-scale', String(s.scale));
|
||
paintSeg('tw-density', String(s.density));
|
||
paintSeg('tw-motion', String(s.motion));
|
||
}
|
||
|
||
function paintAccent(val) {
|
||
const host = document.getElementById('tw-accent');
|
||
if (!host) return;
|
||
host.querySelectorAll('button').forEach((b) =>
|
||
b.setAttribute('aria-pressed', b.dataset.val === val ? 'true' : 'false'),
|
||
);
|
||
}
|
||
function paintSeg(id, val) {
|
||
const host = document.getElementById(id);
|
||
if (!host) return;
|
||
host.querySelectorAll('button').forEach((b) =>
|
||
b.setAttribute('aria-pressed', b.dataset.val === val ? 'true' : 'false'),
|
||
);
|
||
}
|
||
|
||
function buildAccent(state) {
|
||
const host = document.getElementById('tw-accent');
|
||
if (!host) return;
|
||
host.innerHTML = '';
|
||
for (const p of ACCENT_PRESETS) {
|
||
const b = document.createElement('button');
|
||
b.type = 'button';
|
||
b.className = 'tw-swatch';
|
||
b.dataset.val = p.val;
|
||
b.setAttribute('aria-label', p.id);
|
||
b.style.background = p.val;
|
||
b.addEventListener('click', () => {
|
||
state.accent = p.val;
|
||
save(state); applyState(state);
|
||
});
|
||
host.appendChild(b);
|
||
}
|
||
}
|
||
|
||
function bindSeg(id, key, parser) {
|
||
const host = document.getElementById(id);
|
||
if (!host) return;
|
||
host.addEventListener('click', (e) => {
|
||
const btn = e.target.closest('button[data-val]');
|
||
if (!btn) return;
|
||
state[key] = parser ? parser(btn.dataset.val) : btn.dataset.val;
|
||
save(state); applyState(state);
|
||
});
|
||
}
|
||
|
||
const state = load();
|
||
buildAccent(state);
|
||
bindSeg('tw-mode', 'mode');
|
||
bindSeg('tw-scale', 'scale', parseFloat);
|
||
bindSeg('tw-density', 'density', parseFloat);
|
||
bindSeg('tw-motion', 'motion', parseFloat);
|
||
applyState(state);
|
||
|
||
// ---- Panel show/hide ----
|
||
const panel = document.getElementById('tw-panel');
|
||
const restore = document.getElementById('tw-restore');
|
||
function setPanelVisible(v) {
|
||
panel.classList.toggle('tw-hidden', !v);
|
||
restore.classList.toggle('tw-show', !v);
|
||
}
|
||
document.getElementById('tw-close').addEventListener('click', () => setPanelVisible(false));
|
||
restore.addEventListener('click', () => setPanelVisible(true));
|
||
|
||
// ---- Reset ----
|
||
document.getElementById('tw-reset').addEventListener('click', () => {
|
||
Object.assign(state, DEFAULTS);
|
||
save(state); applyState(state);
|
||
});
|
||
|
||
// ---- Keyboard shortcuts ----
|
||
addEventListener('keydown', (e) => {
|
||
if (e.metaKey || e.ctrlKey || e.altKey) return;
|
||
if (e.target.matches('input, textarea, select, [contenteditable]')) return;
|
||
if (e.key === 't' || e.key === 'T') {
|
||
e.preventDefault();
|
||
setPanelVisible(panel.classList.contains('tw-hidden'));
|
||
} else if (e.key === 'r' || e.key === 'R') {
|
||
e.preventDefault();
|
||
Object.assign(state, DEFAULTS);
|
||
save(state); applyState(state);
|
||
}
|
||
});
|
||
</script>
|
||
</body>
|
||
</html>
|