webx-ui / module-icons
The site's own icons for the WebX UI admin panel: SVG kept in the database, cleaned by a white list and served as one sprite beside the theme's, with no query on a page.
Requires
- php: ^8.4
- illuminate/console: ^13.0
- illuminate/contracts: ^13.0
- illuminate/database: ^13.0
- illuminate/filesystem: ^13.0
- illuminate/support: ^13.0
- webx-ui/cache: ^0.103.0
- webx-ui/mcp: ^0.103.0
- webx-ui/module-admin: ^0.103.0
- webx-ui/module-auth: ^0.103.0
- webx-ui/themes: ^0.103.0
Requires (Dev)
- orchestra/testbench: ^11.0
- phpunit/phpunit: ^12.0 || ^13.0
- webx-ui/module-blocks: ^0.103.0
- webx-ui/module-settings: ^0.103.0
Suggests
- webx-ui/module-blocks: Where an icon stands: the fields and templates of the blocks — a used icon is then neither renamed nor deleted without saying where.
- webx-ui/module-settings: Where an icon stands: an icon picker a project puts on the settings screen.
Provides
None
Conflicts
None
Replaces
None
README
The site's own icons for the WebX UI admin panel: SVG kept in
the database, cleaned by a white list and drawn by <x-theme::icon name="…"> next to the icons of
the theme — added without editing the theme, without a build and without a deploy.
A page asks the database nothing about them. The rows are built into one sprite on the public disk
and a manifest in bootstrap/cache; a page reads the manifest from opcache.
Requirements
- PHP 8.4+, Laravel 13
webx-ui/themes(the tag and the white list),webx-ui/module-admin,webx-ui/module-auth
Install
composer require webx-ui/module-icons
php artisan migrate
php artisan storage:link # once per site, if public/storage is not there yet
A site without the module, or with an empty table, draws exactly what it drew before.
How a name is drawn
<x-theme::icon name="deck">:
- an icon of the theme (
icons/deck.svgof a layer) — the theme's sprite, as before; - otherwise an icon of the site —
/storage/webx-icons/<hash>.svg#deck; - otherwise an empty
<svg>; withAPP_DEBUGa comment says where the name was looked for.
The theme comes first, so a template of the theme never changes its look because the site took the same name.
Adding an icon
An icon of the site is content. In the panel, «Icons» → «New icon»: a name, the markup pasted or
an .svg file uploaded, and a preview of what the server's cleaning keeps — on a light and a dark
ground, at 16, 24 and 48 pixels — before anything is saved. The icon is then in every field
wx-icon-picker with source: "theme", under «Site». An agent does the same over MCP: read
icons://rules, then icons_create with the name and the markup — dry_run: true first shows
what the white list keeps. A name the theme has is refused; an icon that stands somewhere (a block's
field, a header, a template, a setting, a field of a module's form) is not renamed, nor deleted without force — icons_usage says
where. Permissions: icons.view reads, icons.manage writes; editor and developer manage,
seo reads.
The sprite
php artisan webx:icons:build [--force] reads the table (one query) and writes:
storage/app/public/webx-icons/<hash12>.svg— every icon as a<symbol>with its own viewBox, named by the hash of the content, so a browser caches it forever. The current file and three earlier ones are kept: a page cached before a build still links to its sprite.bootstrap/cache/webx-icons.php— the names, the sprite's address and a fingerprint of the table; written beside its place and renamed over it.
Nothing is written when the files already say what the table says, so it runs anywhere, any number of times:
- on every save and delete of an icon, in the same request;
- on the boot of a container (
webx:boot, afterwebx:theme:sync); - after
webx:snapshot:restore— the rows travel as content, the files never do; - on the first page that finds the manifest lost, under a lock (one query, once);
- by hand, and
php artisan webx:doctorsays when it is needed.
A new sprite moves the cache groups theme and icons: its address is in cached HTML.
With the skeleton's nginx, /storage/webx-icons/ answers with Cache-Control: immutable; on
another server the hash in the name does the same job, only with a revalidation now and then.
Taking icons over from the theme
An icon a layer of the theme carries in icons/ needs a release to change. To make it content:
php artisan webx:icons:import theme-default phone mail # or the whole layer; --dry-run first
Each file goes through the same white list and limits as any other icon (--keep-colors keeps a
multicoloured one), with source theme:<layer> and the licence of the layer's package. The name
stays the same, so nothing on a page changes; while the layer still has the file the theme's icon
is drawn and the site's is shadowed. webx:theme:check notes each shadowed icon (not a
finding), webx:doctor warns, icons_list marks it. Drop the files from the layer in its next
release, and the site's icons take over.
Config
php artisan vendor:publish --tag=webx-icons-config — limits of an icon (64 KB sent, 32 KB and
2000 elements kept), the number of icons a site keeps (500), the folder of the sprite and the place
of the manifest.
License
MIT