AiSvg
AI SVG visual asset generation β prompt builder + SVG security sanitizer.
Statusβ
| Key | Value |
|---|---|
| Layer | composite |
| Tier | L1 |
| Status | wip |
| Version | 0.9.0 |
| Price | Free (free) |
| Category | Content |
Overviewβ
Overviewβ
AiSvg is a Composite Plugin for generating and validating AI-created SVG visual assets. It provides a standard prompt builder and SVG sanitizer for content documents, landing pages, help pages, reports, and other web content.
LLM calls are delegated to project AI adapters such as AiRelay. AiSvg owns the Pure boundary for prompt composition + result validation.
Core Componentsβ
Enumsβ
| Enum | Cases |
|---|---|
SvgVisualKind | CARTOON / PHOTO / DIAGRAM / ICON |
StylePreset | FLAT / CARTOON / LINE / HAND_DRAWN |
Each has visualHint() / styleHint() for prompt construction.
PromptBuilder (Pure)β
Extracted from academy.how's IllustrationGenerator::buildPrompt and generalized. Inputs: caption + kind + style + locale. Auto-includes viewBox, locale title language, audience, security constraints, and size limits.
SvgSanitizer (Pure)β
Validates LLM-generated SVG safety + format.
- Auto-strips Markdown code fence
- Validates
<svg>start +</svg>end - Blocks dangerous tags (script / foreignObject / iframe / object / embed)
- Blocks event handlers (onclick / onload / etc)
- Blocks unsafe URL schemes in href/xlink:href/style url(): http, https, data, javascript
- Size limits (8KB / 60 lines)
Result: { ok, svg, issues, size_bytes, line_count }. Issue codes are i18n-able.
Configurationβ
return [
'enabled' => env('PLG_AI_SVG_ENABLED', true),
'audience' => 'general web content readers',
'svg' => ['max_size_bytes' => 8192, 'max_lines' => 60, 'view_box' => '0 0 480 320'],
'forbidden' => [
'tags' => ['script', 'foreignObject', 'iframe', 'object', 'embed'],
'event_handlers' => ['onclick', 'onload', 'onmouseover', 'onerror'],
'block_external_images' => true,
'forbidden_url_schemes' => ['http:', 'https:', 'data:', 'javascript:'],
],
];
Usageβ
$prompt = PromptBuilder::fromConfig(config('ai-svg'))->build(
caption: 'an apple in sunlight',
kind: SvgVisualKind::CARTOON,
style: StylePreset::FLAT,
locale: app()->getLocale(),
);
$result = $aiClient->complete($prompt);
$sanitized = SvgSanitizer::fromConfig(config('ai-svg'))->sanitize($result['text']);
if ($sanitized['ok']) {
$visualAsset->svg_content = $sanitized['svg'];
}
Originβ
Extracted from academy.how's IllustrationGenerator (320 LOC). LLM call / Eloquent save / AiRun tracking are project or AiRelay/AiTracking responsibilities.
Dependenciesβ
- DocumentProcessor β embed SVG in Document
- AiRelay (optional) β LLM call adapter
- AiTracking (optional) β generation history
Roadmapβ
- Standard
AiSvgAssetModel + Migration - Filament Resource for preview, approval, regeneration, and rollback
- Refine prompt (user instructions + attachment images)
- Caption β SVG caching
Licenseβ
MIT