Skip to content

API: edit

@mosaicoo/svg-engine/edit is the headless editing layer that sits between core (the model) and ui (the Material widgets). It owns selection, the tool system, interactive gestures (move/resize/rotate/marquee/snap/align), the plugin system, and the capability registries (menus, shortcuts, effects, libraries, pages, animation). It is headless: no Angular Material/CDK.

It’s a large surface — this page is a practical map of what you actually wire up. Everything is signal-backed and per-editor scoped.

import {
provideSvgEngineEditorScope, provideSvgEngineEditorBuiltins,
SelectionService, ToolHostService,
} from '@mosaicoo/svg-engine/edit';
APIDescription
provideSvgEngineEditorScope()Registers the per-editor services (selection, transform, snap, marquee, alignment, layers, pages, animation, workspace, …) in a child injector. Provide it once per editor instance — this is what enables multi-editor isolation.
provideSvgEngineEditorBuiltins()One call that installs the full headless plugin set (tools, libraries, IO, optimizers, effects, keyboard, menus) instead of hand-registering ~two dozen plugins. Pair it with provideSvgeUiBuiltins() from ui for the Material tier.
provideSvgEnginePlugin(plugin)Bootstrap a single plugin at app config time.
provideSvgeHelpLinks(links)Configure the Help-menu URLs (docs, tutorials, plugin dev, report issue).
APIDescription
SelectionServiceThe selection state: signals selectedIds, focusId, hoverId, count, hasSelection, isSingleSelection; methods select, selectMany, addToSelection, removeFromSelection, toggle, clear, setHover, isSelected. Locked nodes are filtered out automatically.

The tool system routes pointer/keyboard events to whichever tool is active.

APIDescription
ToolRegistryRegistry of installed tools: register(tool) → Disposable, get(id), getByShortcut(key), tools signal.
ToolHostServiceActive-tool state + event router: activeId/activeTool signals; activate(id), deactivate(), and routePointerDown/Move/Up/Cancel, routeKeyDown. Forward your canvas events here.
ToolThe tool contract: id, label, optional icon/cursor/shortcut/optionsComponent, and optional lifecycle hooks (onActivate, onPointerDown, onKeyDown, …).
ToolContext / ToolPointerEventThe context (injector) handed to each hook, and the pointer wrapper (docPoint, screen coords, modifier flags).

The 15 built-in tools ship as plugins; each exposes an id constant:

ToolId constantPurpose
SelectSELECT_TOOL_IDSelect & transform (default).
Direct SelectDIRECT_SELECT_TOOL_IDEdit individual anchor points.
PenPEN_TOOL_IDDraw Bézier paths.
PencilPENCIL_TOOL_IDFreehand drawing.
Rectangle / Ellipse / PolygonRECTANGLE_TOOL_ID / ELLIPSE_TOOL_ID / POLYGON_TOOL_IDDraw shapes.
TextTEXT_TOOL_IDCreate & edit text.
EyedropperEYEDROPPER_TOOL_IDSample colors.
KnifeKNIFE_TOOL_IDCut paths.
SmoothSMOOTH_TOOL_IDSmooth paths.
GradientGRADIENT_TOOL_IDEdit gradients on-canvas.
WidthWIDTH_TOOL_IDVariable stroke-width profiles.
Symbol SprayerSYMBOL_SPRAYER_TOOL_IDSpray symbol instances.
PagePAGE_TOOL_IDCreate & edit pages/artboards.

These services hold transient gesture state and dispatch the matching undoable command on commit. You read bounding boxes and feed pointer deltas in.

APIDescription
TransformServiceMove/resize/rotate gestures with a live preview: startMove/startResize/startRotate, updateDragDelta/updateRotateAngle, endDragAndCommit, cancelDrag; dragState/showPreview signals.
MarqueeServiceDrag-to-select rubber band: start/update/end/cancel, rect/isActive signals. Pair with nodesInsideMarquee(rect, nodes, mode) (MarqueeHitMode, MarqueeMode).
SnapServiceSnap config + live guides: toggles for enabled, mode (grid/objects/both), snapToGuides, gridSize, thresholdPx; resolveForMove(rect, candidates, zoom) returns the snapped delta + guides.
AlignmentServiceAlign & distribute as one undo entry: align(items, axis), alignToReference, distribute, distributeSpacing. Types AlignAxis, DistributeAxis, NodeBBox.
KeyObjectServiceRemembers the “align to key object” target per editor.

Each has matching overlay components — SelectionOverlay, RotationPivot, Marquee, SnapGuides — that you can drop into the canvas.

APIDescription
WorkspaceServiceEditor presentation state: background, page, grid, guides, rulers, interaction signals with matching setters. Types BackgroundConfig, PageConfig, GridConfig, Guide, RulersConfig, InteractionConfig.
LayersServicePer-node visibility & lock (editor-only, not serialized): isVisible/isLocked, setVisible/toggleVisible, setLocked/toggleLocked, showAll/unlockAll.
IsolationServiceGroup isolation + breadcrumb navigation: enterIsolation, exitIsolation, toggleIsolation.
SvgeCanvasGesturesDirective for middle-mouse pan + wheel zoom, driving ViewportService.
Workspace file formatserializeWorkspace(state) / parseWorkspace(json) and the .svge/.svgez envelope types — persist the full editor state (config + viewport), not just the document.

Overlay/filter components: WorkspaceBackground, GridOverlay, GuidesOverlay, PageOverlay, LayersFilter, IsolationFilter, AnchorOverlay.

Everything optional in the editor is a plugin. Build your own to add tools, libraries, menus, shortcuts, effects or formats.

APIDescription
EditorPluginThe plugin contract: id, version, name, apiVersion, optional dependencies/category, and install(ctx) / optional uninstall(ctx).
PluginContextHanded to install: pluginId, injector, and track(disposable) so every contribution is auto-removed on uninstall.
PluginRegistryInstall/uninstall lifecycle: install, uninstall, has, get, list, installed signal.
PLUGIN_API_VERSION / PluginCategory / InstalledPluginThe current API version, the category union, and the installed-record type.

For managing and loading plugins: PluginManagerService + PluginCatalog + PluginStateStore back the plugin-manager UI; PluginLoader + providePluginLoader(config) + validateExternalPluginManifest() load external third-party plugins behind an allowlist + API-version gate (SVGE_PLUGIN_TRUSTED_ORIGINS, SVGE_PLUGIN_MODULE_LOADER).

APIDescription
MenuContributionRegistryExtensible menu/toolbar/context-menu registry: register(contribution) → Disposable, bySlot(slot). Types MenuContribution, MenuSlot, MenuContributionContext. Slots: MENU_SLOT, TOOLBAR_SLOT, CONTEXT_MENU_SLOT.
ShortcutRegistry / ShortcutServiceRegister shortcuts (register → Disposable, findMatch(event)) and dispatch them on keydown. Shortcut carries combo, label, optional when guard, handler.
KeybindingsServiceRuntime customization: listShortcuts, setOverride(id, combo), clearOverride, exportAsJson.
Combo helpersparseCombo, comboMatches, formatCombo, comboFromEvent, validateCombo.

Built-in contribution plugins: builtinMenuContributionsPlugin, builtinInsertMenuPlugin, builtinAdvancedEditMenuPlugin, builtinEditorShortcutsPlugin.

A uniform LibraryRegistry<T> (register → Disposable, get, update, items signal) backs every asset library. Each ships a built-in plugin.

ServiceHolds
ShapeLibraryServiceReusable shapes.
SymbolLibraryServiceSymbols (master/instance via SymbolUseNode).
TemplateLibraryServiceDocument templates.
BrushLibraryServiceBrushes (width profiles for the Pencil).
PatternLibraryService / GradientLibraryServicePatterns and gradients.
GraphicStyleLibraryServiceReusable graphic styles.
PaletteRegistryColor palettes (Palette = { id, name, colors }).
ClipPathLibraryService / MaskLibraryServiceClip paths and masks.

Supporting services: AssetManagerService (file → data URI) and ActiveDefsService / ActiveSymbolsService (compose the used defs/symbols into <defs> for export).

APIDescription
PagesServiceDerived view of the document’s pages: pages/count/hasPages signals, byId, nameOf, viewBoxOf.
ActivePageServiceWhich page is being edited: activePageId/activePage/effectiveDrawTargetId signals, setActivePageId.
AnimationServiceEdit the page animation via undoable commands: addKeyframe, removeKeyframe, moveKeyframe, setKeyframeEasing, setDuration, setAnimatableProperty, sample(playhead); tracks/duration/hasAnimation signals.
PlaybackServiceDrives the playhead with requestAnimationFrame: play/pause/seek/step/setSpeed/setLoop; playhead/isPlaying signals.
APIDescription
EffectRegistryRegistry of SVG-filter effects: register → Disposable, get, byCategory, effects signal.
Effect / EffectParamThe effect contract (buildFilterMarkup()) and its typed parameters (EffectNumberParam, EffectColorParam, EffectSelectParam, EffectBooleanParam).
Param helperseffectDefaults, resolveEffectParams, nonDefaultParams, isNumberParam.
ParametricEffectRegistry / ChainFilterRegistryParametric (re-editable) effects and effect chaining, with id encode/parse helpers.
builtinEffectsPluginRegisters the built-in filter presets (blur, drop shadow, glow, bevel/emboss, color adjustments, …).
APIDescription
ClipboardServiceIn-memory copy/cut/paste decoupled from the browser clipboard: copy, cut, paste, canPaste.
FindReplaceService / SelectSameServiceFind & replace across node text/properties (find, replace, replaceAll; FindCriteria/FindMatch), and “select same” (fill/stroke/font/…).
AutoSaveServicePeriodic localStorage autosave with recovery.
RecentFilesServiceMRU list behind “Open Recent”.
SnapshotsPersistenceServicePersist editor snapshots to localStorage.
AssetExportRegistry / AssetExportRunnerBatch export: register slots (target + format + scale + filename) and run them with unique-name disambiguation.
FullscreenServiceNative fullscreen wrapper.
ImportSettingsService / ImportPlacementServiceSVG-import placement preference and the interactive drag-to-place gesture (SvgeImportPlacementOverlay).
TraceImageServiceRaster-to-vector tracing: traceImageToPaths(imageData, options) + the undoable TraceImageCommand.
SmartObjectActionsService”Replace contents” / rasterize actions for smart objects.