Skip to content

M3: swatch libraries — library panel, generated libraries, save and load, gradient libraries (M3.56–M3.58) - #27

Merged
bflatastic merged 3 commits into
mainfrom
pr/m3-swatch-libraries
Oct 4, 2026
Merged

bflatastic merged 3 commits into
mainfrom
pr/m3-swatch-libraries

Conversation

@bflatastic

Copy link
Copy Markdown
Member

Part of M3 (Paint & appearance). Swatch libraries: a library panel with our own code-generated libraries, saving and loading libraries, and gradient libraries. Nothing is taken from Illustrator's bundled libraries; every palette is computed and named by us.

  • M3.56: library panel and generated libraries.
    • Opening it: Window ▸ Swatch Libraries and the Swatches panel's library button open a floating, read-only library panel with thumbnail and list views, a find field, a libraries menu, previous/next arrows and Add to Swatches.
    • Using it: clicking a swatch adds it and applies it to the active proxy (Alt: the other proxy) in one undo step.
    • Default Swatches restores the defaults.
    • Libraries: nine, computed from OKLCH colours: Web Safe 216, Grays and Neutrals, Earth Tones, Skin Tone Ramps, Pastels, Brights, Metallic Gradients, Perceptual Scales, Harmony Sets.
    • Commands: swatch.library.list, swatch.library.get {library}, swatch.library.add {library, names?, apply?, focus?} (skips swatches the document already has), swatch.resetDefaults {replace?}. UI command window.swatchLibrary {library}.
    • Shared panel: panels/library_panel.rs is generic (LibraryKind), so graphic style libraries can reuse it.
  • M3.57: saving and loading libraries.
    • Formats (color/src/palette_io.rs): .vcswatches (lossless JSON: models, global, spot, groups); .gpl palettes (RGB, # Group: headers, other tools' comments and headers read); CSS custom properties (escaped, write-only).
    • Commands: swatch.library.save {path?, format?, names?, name?, user?} returns {data} without a path. swatch.library.load {path?|data?|dataBase64?, name?} also loads another document's swatches.
    • User libraries: saved to <prefs dir>/Swatches, they appear under User Defined.
    • Opening files: a .vcswatches or .gpl file opens in the library panel, and the open dialogs gain a "Swatch libraries" filter.
  • M3.58: gradient libraries and gradient swatch options.
    • Five generated gradient libraries.
    • Swatch Options on a gradient swatch shows the name and the gradient, and OK renames it.
    • swatch.edit {paint?} replaces a swatch's paint with one of the same kind, and Alt-dropping a paint on a matching swatch uses it.

docs/mcp.md and docs/control-protocol.md cover the commands and the saveSwatchLibrary dialog.

Known limits:

  • One library panel at a time.
  • Library swatches can't be dragged straight onto art.
  • Renaming a gradient swatch doesn't update gradient links in art.

Checks

Rebased onto 1ea13b5 (#26). cargo xtask ci passes all 7 steps on this tree: 1,530 tests, 0 failed.

New tests:

  • every library is deterministic, unique and in gamut;
  • Web Safe has 216 colours;
  • add skips duplicates in one undo step;
  • the submenu lists every library;
  • .vcswatches round-trips CMYK, spot and groups;
  • .gpl headers and comments;
  • CSS escaping;
  • every generated gradient has two or more sorted stops;
  • rename.

🤖 Generated with Claude Code

bflatastic and others added 3 commits October 5, 2026 00:59
Window > Swatch Libraries and the Swatches panel's library button open a
read-only, floating library panel (thumbnail and list views, find field,
libraries menu, previous/next arrows). Clicking a swatch adds it to the
document and applies it as one undo step; Shift/Cmd-clicks select swatches
and groups for Add to Swatches. Default Swatches restores missing defaults.

Libraries are computed in code (OKLCH, rounded to 8-bit sRGB): Web Safe 216,
Grays and Neutrals, Earth Tones, Skin Tone Ramps, Pastels, Brights,
Metallic Gradients, Perceptual Scales, Harmony Sets.

Commands: swatch.library.list, swatch.library.get, swatch.library.add
{library, names?, apply?, focus?}, swatch.resetDefaults {replace?};
UI command window.swatchLibrary {library}.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m back

Save Swatch Library… (Swatches panel menu, libraries menu, Window menu)
opens a dialog: name, format and destination. .vcswatches is lossless JSON
(colour models, global, spot, gradients, groups), .gpl an RGB palette with
groups as comment headers, CSS custom properties with escaped names.
Libraries saved to the user library folder show under User Defined.
Other Library… (and opening a .vcswatches/.gpl file) loads a library or
another document's swatches into the library panel.

Commands: swatch.library.save {path?, format?, names?, name?, user?}
(no path returns {data}), swatch.library.load {path?|data?|dataBase64?,
name?}; UI: window.swatchLibrary.other, ui.saveSwatchLibrary (dialog
saveSwatchLibrary), window.userSwatchLibrary1..10.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Alt-drop replaces a swatch

Window > Swatch Libraries > Gradients lists five generated gradient
libraries (Spectrum, Sky, Neutral incl. fades to transparent, Duotone,
Radial Glows); the library panel's menu lists them too.
Swatch Options on a gradient swatch shows its name and the gradient; OK
renames it. Alt-dropping an edited gradient (or a colour) on a swatch of its
kind in the Swatches panel replaces it, via swatch.edit {paint}.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant