feat(icons): add the FA5 catalog, REST endpoint and unified icon helpers
Mirror the reference theme's universal picker on FA5: a generated full catalog of the bundled FA5 Free 5.15.4 fonts (src/Icons/fa5-icons.php, generated from the shipped CSS + SVG fonts), a zibsvg group parsed from the runtime sprite so it cannot drift, and GET /aksrt/v1/icons/catalog. Shared admin pieces: aksrt_icon_markup()/aksrt_sanitize_icon_value() with an SVG allowlist, the picker field/modal assets, and one canonical aksrt-font-awesome handle registered through aksrt_enqueue_fontawesome().
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* One-shot generator for src/Icons/fa5-icons.php.
|
||||
*
|
||||
* Sources (shipped with the theme):
|
||||
* - assets/fontawesome5/css/all.min.css → glyph class names + codepoints
|
||||
* - assets/fontawesome5/webfonts/fa-*.svg → per-style glyph codepoints
|
||||
*
|
||||
* Usage: php tools/generate-fa5-icons.php
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || define('ABSPATH', __DIR__ . '/');
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
$css_path = $root . '/assets/fontawesome5/css/all.min.css';
|
||||
$fonts_path = $root . '/assets/fontawesome5/webfonts';
|
||||
$out_path = $root . '/src/Icons/fa5-icons.php';
|
||||
|
||||
$css = (string) file_get_contents($css_path);
|
||||
|
||||
// class name → codepoint (e.g. 'home' => 0xf015)
|
||||
$name_to_code = [];
|
||||
if (!preg_match_all('/\.fa-([a-z0-9-]+):before\{content:"\\\\([0-9a-f]{4})"\}/i', $css, $m, PREG_SET_ORDER)) {
|
||||
fwrite(STDERR, "No glyph rules matched in all.min.css\n");
|
||||
exit(1);
|
||||
}
|
||||
foreach ($m as $hit) {
|
||||
$name_to_code[$hit[1]] = hexdec($hit[2]);
|
||||
}
|
||||
|
||||
// style → set of codepoints, parsed from the SVG font files
|
||||
$code_to_style = ['fas' => [], 'far' => [], 'fab' => []];
|
||||
foreach (array_keys($code_to_style) as $style) {
|
||||
$file = $fonts_path . '/fa-' . ($style === 'fab' ? 'brands-400' : ($style === 'far' ? 'regular-400' : 'solid-900')) . '.svg';
|
||||
$src = (string) file_get_contents($file);
|
||||
if (!preg_match_all('/<glyph[^>]*unicode="&#x([0-9a-f]+);"/i', $src, $g, PREG_SET_ORDER)) {
|
||||
fwrite(STDERR, "No glyphs matched in {$file}\n");
|
||||
exit(1);
|
||||
}
|
||||
foreach ($g as $hit) {
|
||||
$code_to_style[$style][hexdec($hit[1])] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$groups = ['fas' => [], 'far' => [], 'fab' => []];
|
||||
foreach ($name_to_code as $name => $code) {
|
||||
foreach ($groups as $style => $unused) {
|
||||
if (!empty($code_to_style[$style][$code])) {
|
||||
$groups[$style][] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($groups as $style => $names) {
|
||||
sort($groups[$style], SORT_NATURAL | SORT_FLAG_CASE);
|
||||
}
|
||||
|
||||
$export = var_export($groups, true);
|
||||
|
||||
$php = <<<PHP
|
||||
<?php
|
||||
/**
|
||||
* Font Awesome 5 Free (5.15.4) icon catalog, grouped by style.
|
||||
*
|
||||
* Generated by tools/generate-fa5-icons.php — do not edit by hand.
|
||||
* Bare glyph names; the picker composes "fa {fas|far|fab} fa-{name}".
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
return {$export}
|
||||
PHP;
|
||||
|
||||
file_put_contents($out_path, $php . ";\n");
|
||||
|
||||
printf(
|
||||
"fas=%d far=%d fab=%d (css glyph classes=%d)\nWrote %s\n",
|
||||
count($groups['fas']),
|
||||
count($groups['far']),
|
||||
count($groups['fab']),
|
||||
count($name_to_code),
|
||||
$out_path
|
||||
);
|
||||
Reference in New Issue
Block a user