Milsymbol does not write SVG strings or Canvas API calls directly inside its symbol logic. Instead, every visual element — frames, icons, text fields, modifier badges — is first described as a draw instruction: a plain JavaScript object with aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/spatialillusions/milsymbol/llms.txt
Use this file to discover all available pages before exploring further.
type field and geometry properties. Once all symbol parts have assembled their draw instructions into a flat array, milsymbol’s output layer translates that array into either an SVG string (via asSVG()) or Canvas 2D API calls (via asCanvas()). This separation of concerns is what makes milsymbol both extensible and output-agnostic.
Why Draw Instructions Matter for Extension Authors
When you callms.addSymbolPart() or ms.addIconParts(), you are writing functions that produce draw instructions. Milsymbol collects the pre and post arrays from every registered symbol part and merges them into a single ordered list before rendering. Understanding the draw instruction schema therefore lets you:
- Add entirely new graphical elements on top of any symbol
- Override or replace built-in icon parts
- Position and transform custom geometry in the same coordinate space as the standard icons
Coordinate System
All draw instructions share a single logical coordinate system:- Origin:
(100, 100)— the centre of the icon octagon - Icon octagon: 100 logical units wide and 100 logical units tall, spanning from
(50, 50)to(150, 150) - A reference SVG showing the octagon and its grid lines is available in the repository at
dev/octagon.svg
size option scales the entire output uniformly at render time, so your geometry is always authored at the canonical 100×100 scale.
Draw Instruction Types
Milsymbol recognises seven draw instruction types. All types are defined inindex.d.ts as a discriminated union (DrawInstruction).
path
Renders an SVG path. Use standard SVG d path syntax with coordinates in the 100×100 icon space.
circle
Renders a filled and/or stroked circle.
text
Renders a text label at a specific position.
svg
Embeds a complete SVG XML string verbatim. Useful for including pre-existing SVG artwork as part of a symbol without converting it to path instructions.
translate
Wraps one or more draw instructions and applies a translation (offset) before rendering them. The nested draw array is itself a DrawInstruction[].
rotate
Wraps draw instructions and applies a rotation around a given centre point.
scale
Wraps draw instructions and scales them by a uniform factor relative to the current transformation.
Arrays of Draw Instructions
ADrawInstruction can be either a single object or an array of objects. Milsymbol’s renderer handles both transparently, which means you can group related shapes into a sub-array and return that array from a symbol part without flattening it first.
Common Fields Reference
All primitive draw instruction types (path, circle, text) share the same set of optional visual styling fields:
| Field | Type | Required | Description |
|---|---|---|---|
fill | string | false | Yes | Fill color as a CSS color string, or false for no fill |
fillopacity | number | No | Fill opacity from 0 (transparent) to 1 (opaque) |
stroke | string | false | Yes | Stroke color as a CSS color string, or false for no stroke |
strokewidth | number | No | Width of the stroke in logical coordinate units |
strokedasharray | string | No | SVG stroke-dasharray value, e.g. "4,4" or "8,12" |
translate, rotate, scale) do not carry visual fields of their own — those belong to the nested draw instructions.
Using Draw Instructions in Symbol Extensions
Register a symbol part with ms.addSymbolPart()
A symbol part is a function called with
this bound to the current Symbol
instance. It must return an object with pre, post, and bbox.TypeScript Types
The full set of draw instruction types is exported frommilsymbol:
