Examples
Quick recipes for the most common ways to integrate svg-engine. For a guided walkthrough, see Getting started.
Read-only viewer
Section titled “Read-only viewer”Render an SVG document with no editing services and no Material:
import { Component } from '@angular/core';import { SvgeRenderer } from '@mosaicoo/svg-engine/render';import { createRect, createGroup, type SvgDocument } from '@mosaicoo/svg-engine/core';
@Component({ standalone: true, imports: [SvgeRenderer], template: `<svge-renderer [tree]="doc.root" [viewBox]="doc.viewBox" />`,})export class MyViewer { protected readonly doc: SvgDocument = { id: 'demo' as never, viewBox: { x: 0, y: 0, width: 200, height: 100 }, root: createGroup([ createRect({ x: 10, y: 10, width: 80, height: 60 }, { style: { fill: '#90caf9' } }), ]), };}Load an SVG file
Section titled “Load an SVG file”Add the IO plugin and import a file (sanitized automatically):
import { provideSvgEnginePlugin, builtinIoPlugin } from '@mosaicoo/svg-engine/edit';providers: [provideSvgEnginePlugin(builtinIoPlugin)];
// any componentprivate readonly importers = inject(ImporterRegistry); // from @mosaicoo/svg-engine/ioasync loadFile(file: File) { const importer = this.importers.byMediaType('image/svg+xml'); const result = importer?.import(await file.text()); if (result?.ok) this.state.resetDocument(result.document);}Full editor shell
Section titled “Full editor shell”Drop in the Material-styled editor:
import { SvgeEditor } from '@mosaicoo/svg-engine/ui';<svge-editor [title]="'My drawing'"> <svg:g svgeSelectionOverlay></svg:g> <svg:g svgeRotationPivot></svg:g> <svg:g svgeMarquee></svg:g> <svg:g svgeSnapGuides></svg:g></svge-editor>