Search by

particle-academy / fancy-cms

wishborn

Laravel host for fancy-cms — the PHP page renderer (node tree → HTML + compiled CSS + island placeholders), persistence, file API on any disk, and publish routing. The PHP half of the dual-emitter pair with @particle-academy/fancy-cms-ui.

Package info

github.com/Particle-Academy/fancy-cms

pkg:composer/particle-academy/fancy-cms

Statistics

Installs: 1 625

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 2

v0.9.1 2026-11-13 18:14 UTC

This package is auto-updated.

Last update: 2026-11-19 03:01:23 UTC


README

Native icon nodes are bounded leaves. Agent::describe()['elements']['icon'] describes their prop contract. Search Agent::icons(query,cursor) for up to 20 names per response (source, names, total, nextCursor); expose this as cms_icons to agents. The full Fancy Lucide 0.511.0 set has 1,803 names/aliases and 1,594 glyphs. Empty query lists names in pages; a name or ASCII words search matches all words, exact match first then lexical order. Set literal props name, decorative and, for a meaningful icon, a nonblank label (up to1024 UTF-8 bytes). Decorative labels are hidden. SVG, paths, extra props and bindings are rejected at storage and operation boundaries. Existing responsive style.fontSize sizes the one-em glyph; style.color accepts the existing theme tokens. PHP and React render the same generated catalogue and byte-identical SVG. The React package keeps react-fancy optional by emitting the compatible wrapper directly.

PHP reads no icon data at class load. Validation/search loads the closed name index; rendering loads only the selected per-glyph JSON files and caches them for reuse in the process. JavaScript hosts preload matching glyphs through the UI package's separate icon subpaths and pass the same icons map for SSR and hydration. Glyph data is never document input. Provenance/version/content SHA256 live in resources/icons/metadata.json; see NOTICE and licenses/LUCIDE-LICENSE. The UI twin's offline npm run icons:check verifies both packages and detects drift from the installed Fancy Lucide artifact.

For abstract artwork, frame and shape accept literal boolean props.decorative. True emits aria-hidden="true"; false/omitted stays visible. The entire subtree may contain only frames, shapes and decorative icons without actions. Storage and both operation reducers refuse meaningful descendants, including inserts, moves, prop and action edits that would hide a CTA, heading, image or meaningful icon. Malformed documents rendered directly fail visible. The decorative property is reserved for frames, shapes and icons; rename metadata using that key on other node types.

Fancified

⚠️ Early-release BETA. This package is young and moving fast — expect rough edges, gaps, and breaking changes between 0.x releases. If you hit anything odd (bugs, missing pieces, confusing docs), please report it at github.com/Particle-Academy/fancy-cms/issues — every discovery helps.

The Laravel host for fancy-cms — an extendable inline-WYSIWYG website + app-shell builder built on the Fancy Dev Kit. This package owns the PHP renderer (node tree → HTML + compiled CSS + island placeholders), and — in later phases — persistence, the file API on any disk, and publish routing.

Status: agent surface + document spine + static rendering. Ships the agent guide/catalogue, revision-aware page sessions, validated PageDocs and PageOps, the PHP reducer/inverses, semantic HTML and the PHP CSS emitter. Reducer and CSS parity are checked against @particle-academy/fancy-cms-ui 0.9. Storage, authorization, revision transactions and broadcasting belong to the host application.

Architecture & plan: .ai/plans/fancy-cms.md in the fancy.agi envelope.

For agents. This package is listed on the Fancy MCP catalog server at https://ui.particle.academy/mcp (streamable HTTP, no API key; MCP id fancy-ui), with install commands and docs, alongside the rest of the kit. How an agent installs and uses this package is in AGENTS.md.

Why two emitters

The editor (JS) and the published site (PHP) must produce identical CSS and native static HTML from the same document. The two renderers are kept honest by a cross-engine parity harness, the same discipline used for dark-slide / holy-sheet (PHP ≡ Node).

php bin/emit-css.php path/to/doc.json   # emit CSS for a Stages document

Agent contract

FancyCms\Agent ships an agent guide (Agent::guide()) and a compact operation/element catalogue (Agent::describe()) for host-registered tools such as cms_describe and cms_apply. How to wire them is in AGENTS.md.

Edit a page with two writers

use FancyCms\Document\PageDoc;
use FancyCms\PageSession;

// The host chooses the registry; an untrusted builder can exclude richtext.
$types = array_values(array_diff(PageDoc::NODE_TYPES, ['richtext']));
$session = new PageSession($doc, $types);
$read = $session->get(); // ['doc' => PageDoc, 'revision' => opaque string]

$result = $session->apply([
    ['t' => 'set_node_props', 'id' => 'hero', 'patch' => ['content' => 'Hello']],
], actor: 'agent', basedOn: $read['revision']);

$changes = $session->changesSince($read['revision']);
// ['revision' => '...', 'complete' => true, 'changes' => [
//   ['handle' => 'node:hero', 'change' => 'updated', 'actor' => 'agent'],
// ]]

$storedState = $session->toJson();
$restored = PageSession::fromJson($storedState, $types);

apply() validates every operation and resulting document through PageDoc::apply. A batch commits together: any failure preserves the document, op log and revision. Each accepted op gets an opaque revision and a trusted host-supplied agent or human actor; do not let model arguments choose their own actor. opLog() returns detached {op, actor, revision} rows. An empty batch leaves the revision unchanged. Supplying a stale basedOn refuses the whole batch with surface_changed_under_you; omitting it is an unconditional write, so agent tool adapters should require the revision they observed.

PageSessionException::getErrorCode() returns the string refusal code, getErrors() returns rows with index (zero-based op index, or null), path, expected, got and hint, and getRevision() returns the current revision. Codes are invalid_request, invalid_operation, surface_changed_under_you, unknown_revision, invalid_state, history_limit and state_limit.

The change feed uses the shape consumed by prism-human-plus. It retains every event in order, including removed descendants and transient changes, without coalescing away a human's edit. Handles are node:<id> for nodes and page:<doc.id> for metadata/theme; id components are URL-encoded with rawurlencode so whitespace, colons and Unicode survive consumer parsing. Decode the component with rawurldecode when constructing an op; these handles are not raw node ids. Changes are created, updated, deleted or moved. A known current cursor returns a complete empty feed. An unknown cursor raises unknown_revision, never a misleading empty answer. An agent must read and respect the human-attributed events after a conflict.

The host still owns persistence concurrency. Lock the stored session or use a compare-and-swap transaction across load → apply → save. Two separate instances loaded from the same saved state cannot see each other's writes without that host transaction. Authentication, actor provenance, authorization, storage and broadcasts remain host responsibilities. This class makes no network calls and cannot authenticate stored history.

State format version 1 stores the initial document and each operation as JSON strings inside its JSON envelope, preserving object/list/numeric-map tags. Restore validates and replays the complete history; cursors and actors survive. It accepts at most 1,000 ops per batch, 10,000 retained ops and 32 MiB of encoded state. Over-limit writes fail atomically. History is never silently pruned; starting a new session invalidates old cursors. Keep state in trusted storage.

Apply an edit on the server

use FancyCms\Document\PageDoc;
use FancyCms\Document\PageJson;

$doc = PageJson::decodeDocument($storedJson);
$op = PageJson::decodeOp($operationJson);
$next = PageDoc::apply($doc, $op);
$storedJson = PageJson::encodeDocument($next);

PageDoc::apply validates the input document and operation, rejects an edit that cannot apply, then validates the resulting document before returning it. SchemaException::getErrors() returns errors with path, expected, got and hint; messages identify the first path. The host persists/broadcasts the result within its own revision transaction. seq counts applied edits; the host checks the revision on which an incoming edit was based.

The vocabulary is exactly PageOp::TYPES: insert_node, remove_node, move_node, set_node_props, set_layout, set_style, set_constraints, set_animation, remove_animation, set_action, set_meta, set_theme, and reorder_roots. set_style and set_constraints carry a breakpoint. Omit layout from set_layout to clear it. Merge patches are shallow and preserve null values; null is not a deletion instruction.

For replay of already-shaped data, Reducer::reduce($doc, $op) and Reducer::reduceAll($doc, $ops) mirror JavaScript: missing targets, duplicate inserts, cycle-producing moves and invalid root permutations leave the document and seq unchanged. An optional third argument accepts an onInvalid callback receiving the operation and reason. Inputs are not mutated. Use PageDoc::apply at the server storage boundary for strict refusal.

Reducer::invert($preOpDoc, $op) returns the same serialized JSON-wire inverses as JavaScript. Missing prior patch fields disappear during JavaScript serialization, so merge inverses cannot remove newly introduced keys over the wire. Constraints, animations and actions currently have no JavaScript inverse and return an empty list in PHP too. Ordering::keyBetween($a, $b) ports fancy-doc-commons' base-62 ordering strings without numeric fractions.

Validate documents and preserve JSON shapes

PageDoc::validate and PageOp::validate return path errors; their assert methods throw SchemaException. Documents require a registered node type, matching node-map id, existing parent and acyclic parent chain. Built-ins include list; a host registry supplies an explicit type list:

$types = [...PageDoc::NODE_TYPES, 'store-card'];
$next = PageDoc::apply($doc, $op, $types);

Known emitted lengths, keywords, numbers, animation and action shapes are checked before storage. Validation allows at most 10,000 nodes, 64 levels of JSON and 100,000 JSON values; structural string fields allow 65,536 bytes. Tree cycle validation is iterative, including very deep parent chains.

Use PageJson for wire input/output. PHP's associative JSON decoder loses the difference between an empty object and an empty list. This codec keeps known record fields as arrays in PHP and emits them as JSON objects, including numeric node/property keys. Opaque JSON object values remain plain stdClass; arrays remain lists. A PHP array at a schema-defined record position means a record, so the codec checks the actual object/list tag before converting it. Objects with serialization callbacks are refused before encoding.

Static rendering

PageRenderer::render($doc, $data, $imageResolver) returns HTML and CSS. The optional third argument is a synchronous host asset lookup. Stable data-cms handles sit on the semantic element: headings use h1–h6, text uses paragraphs, links/buttons use safe anchors, lists use ul/ol, and containers accept the allowlisted landmark in props.as. Labels and list items are escaped. Images carry alt text, object-fit and lazy/eager loading. Bindings resolve only the supplied data context. Browser runtimes handle motion, actions and repeaters. PHP does not emit richtext HTML; the agent catalogue excludes it.

The 0.9 base stylesheet emits first, before tokens and per-node rules. It resets semantic-element margins and supplies scoped button/callout/code/image styles. Include the returned CSS when serving the HTML. Button/callout variant and image-fit attributes use allowlists; native leaves use the same markup and escaping as React's static renderer. Valid props.anchor slugs become id. Eager images add a deduplicated SSR preload hint; lazy and data images do not. Missing legacy props/style.base fields get empty rendering defaults; strict document validation still requires the authored document shape.

Host-resolved responsive images

Set an image node's props.asset to a literal catalogue handle. The optional resolver returns only host-owned metadata; an unknown handle, absent resolver or invalid metadata emits no image source and never falls back to props.src. Alt, fit and loading remain document properties.

// A regular shop can use its approved CDN; no flabs storage or database required.
$assets = [
    'campaign/hero' => [
        'src' => 'https://images.shop.example/campaign-1536.jpg', 'width' => 1536, 'height' => 1024,
        'variants' => [
            ['src' => 'https://images.shop.example/campaign-480.jpg', 'width' => 480, 'height' => 320],
            ['src' => 'https://images.shop.example/campaign-960.jpg', 'width' => 960, 'height' => 640],
        ],
        'sizes' => '(max-width: 640px) 100vw, 640px',
    ],
];
$imageResolver = static fn (string $handle): ?array => $assets[$handle] ?? null;
$rendered = \FancyCms\Render\PageRenderer::render($doc, [], $imageResolver);

Intrinsic width/height come only from measured host metadata, not authored props. Variants declare source, width and height; widths and URLs must be distinct. They are copied/sorted into srcSet; a nonempty host sizes is required when variants exist. Single sources emit dimensions without invented srcset/sizes. Dimensions are positive integers up to 1,000,000; at most 16 variants. Sources are root-relative or HTTP(S), with no protocol-relative URL, backslash, controls, spaces or raw comma (percent-encode it). Invalid metadata refuses the whole asset. Eager preload hints match React19's responsive deduplication rules.

Use the same immutable manifest in the PHP host and React SSR/hydration/editor surfaces. The resolver is a synchronous closed lookup: never fetch a model's URL or pass an unknown handle through as a URL. The host owns authorization, catalogue membership, measured dimensions, serving/integrity and CSP. Existing images without asset keep their legacy src behavior, so a closed-asset host must validate documents to require allowed asset handles. The package has no asset discovery/generation endpoint, network fetch or storage dependency.

The CSS emitter mirrors responsive stack/grid behavior, visibility, theme tokens and 0.8 style properties. It escapes ids for quoted selectors and inline styles, validates every emitted length/keyword/number, and drops free-form values that can escape a declaration. Theme token collisions use JavaScript's object-entry order; numeric formatting is independent of PHP's serialization precision. Legacy sections[] ordering remains readable.

Infographics and the island catalogue

chart, kpi, table and leaderboard are native node types. The page carries the shape and binds its numbers with $bind; you pass the data:

$out = PageRenderer::render($doc, ['metrics' => ['revenue' => 12345.6, 'change' => 0.12]]);

A chart renders as an accessible data table (the browser upgrades it to a lazily loaded canvas); missing or malformed data renders an empty state. DataRequests::of($doc) lists every bound path a page reads, with the shape each prop expects.

The island catalogue describes every component type a host renders, each with a JSON Schema for its props. Build it once at boot and use it everywhere:

use FancyCms\Islands\IslandCatalogue;

$islands = IslandCatalogue::builtin()
    ->register('kit:Tabs', ['description' => 'Tabbed panels', 'props' => $tabsSchema, 'example' => ['tabs' => []]])
    // or the catalogue your JS host exported with islandCatalogue(islands):
    ->merge(file_get_contents(resource_path('js/islands.json')));

Agent::describe($islands);                            // cms_describe: types, schemas, examples
new PageSession($doc, $islands->nodeTypes());         // documents may hold those types
PageRenderer::render($doc, $data, islands: $islands); // registered types render as islands

Parity checks

The PHP and JavaScript reducers, CSS and HTML emitters are checked byte for byte against each other; how to run the harnesses is in CONTRIBUTING.md.

Principles

Fonts: see host-resolved fonts for structured font references, same-origin resolution and the opt-in Inter 4.1 bundle.

Running a site: see the webmaster guide for the render route, recommended CSP, image and font resolvers, accessibility and responsive checks, the CLIs and pre-publish verification. The authoring side is covered by the matching guide in @particle-academy/fancy-cms-ui.

  • Guest, not host — adopted per-surface; respects host auth/layout/data.
  • Human+ is opt-in — core works with no websockets or agents.

MIT © Particle Academy

⭐ Star Fancy Dev Kit

If this package is useful to you, a quick ⭐ on the repo really helps us build a better kit. Thank you!