← All libraries

CandySprinkles

✨ CandySprinkles

Declarative styling + layout

port of lipgloss styling layout borders tables trees

Style, Border, Table, List, Tree, Layout::join, Place, multi-layer Canvas, and Theme — the canonical colour palette for all SugarCraft libs. Pure rendering — no I/O — so you can render frames inside a unit test.

Install

composer require sugarcraft/candy-sprinkles

Quickstart

use SugarCraft\Sprinkles\{Style, Border, Layout, Position};
use SugarCraft\Sprinkles\Table\Table;
use SugarCraft\Core\Util\Color;

$banner = Style::new()
    ->bold()
    ->foreground(Color::hex('#ff5f87'))
    ->padding(0, 2)
    ->render('hello, candy world');

$table = Table::new()
    ->headers('Name', 'Age')
    ->row('Alice', '30')
    ->row('Bob', '25')
    ->border(Border::rounded())
    ->render();

echo Layout::joinVertical(Position::LEFT, $banner, $table);

What's in the box

StyleForeground / background, bold / italic / underline, padding, margin, width, alignment. Immutable with*() chain.
BorderSix built-in styles + custom. Border::rounded(), thick(), double(), hidden(), normal(), ascii().
TableHeaders, rows, per-cell styleFunc. ANSI-aware width calc with grapheme cluster support.
List + TreeBulleted lists and ASCII trees with custom enumerators.
LayoutjoinHorizontal, joinVertical, place, placeOverlay for popovers.
CanvasMulti-layer compositor. Z-ordered overlays, alpha-aware merge, ideal for modals + tooltips.
ThemeSSOT colour palette. 10 named factories (dark/light/dracula/tokyoNight/oneDark/githubDark/solarized*/ansi/adaptive). 13 colour slots (foreground/background/primary/secondary/accent/muted/error/warning/success/info/border/separator/cursor). All with*() setters return a new Theme.

Source & demos

Try the quickstart →

API

ClassMethodDescription
Themedark() / light() / dracula() / tokyoNight() / oneDark() / githubDark() / solarizedDark() / solarizedLight() / ansi() / adaptive()Named theme factories
ThemewithPrimary($c) / withForeground($c) / withBackground($c) / withError($c) / …13 colour slot setters — all return a new Theme
Stylenew()Create a new style
Styleforeground(color)Set foreground color
Stylebackground(color)Set background color
Stylebold(), italic(), underline(), blink(), rapidBlink()Text effects (blink = SGR 5, rapidBlink = SGR 6)
Stylepatch($other)Incremental merge — only props set in $other are applied
BorderGradientBlendfromColors(Color ...$colors)1-5 colors → 4 interpolated border-side colors
Stylepadding(top, right, bottom, left)Add padding
Stylerender(content)Render styled content
Borderrounded(), thick(), double(), hidden()Border style presets
Tablenew()Create a table
Tableheaders(...), row(...)Add table content
LayoutjoinVertical(), joinHorizontal()Join layouts
Canvasnew()Create multi-layer canvas

Demos.

VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.

Style

Style

Foreground / background, bold, italic — chained Style builders.
Border

Border

All six built-in border styles.
Table

Table

Per-cell styleFunc with header highlighting.
List

List

Bulleted list with custom enumerator.
Tree

Tree

Indented tree with branch glyphs.
Dashboard

Dashboard

Multi-panel layout joined horizontally + vertically.
Canvas

Canvas

Multi-layer compositor with z-ordered overlays.