@skillpet/circuit
Version:
Circuit diagram library — render electrical schematics from JSON, with interactive SVG, themes, and Vue/React components
157 lines (156 loc) • 5.34 kB
TypeScript
/**
* SVG figure — aligned with Python `backends/svg.py` · `Figure` (subset).
*/
import type { Arcdirection, BBox, Capstyle, Halign, Joinstyle, Linestyle, RotationMode, Valign } from "../types.js";
import { type SvgStyleOpts } from "./svg-style.js";
export type SvgElement = {
z: number;
xml: string;
};
/**
* Estimate text dimensions using per-character width lookup (aligned with
* Python `svgtext.text_approx_size`). Returns width and height in points.
*/
export declare function textSize(text: string, fontsize: number, font?: string): {
width: number;
height: number;
};
export declare class SvgFigure {
static totalClips: number;
bbox: BBox;
readonly scale: number;
pxwidth: number;
pxheight: number;
private readonly elements;
private backgroundColor?;
readonly showbbox: boolean;
private readonly extraDefs;
private readonly svgDefs;
private readonly clips;
private readonly _groupStack;
private _hasGroups;
constructor(bbox: BBox, opts?: {
inchesPerUnit?: number;
margin?: number;
showbbox?: boolean;
/** Raw inner XML for `<defs>` (e.g. gradients, symbols). */
extraDefs?: string;
});
setBbox(bbox: BBox): void;
/** User coords → SVG px (y-up → y-down). */
xform(x: number, y: number): [number, number];
bgcolor(color: string): void;
/** Create an SVG hatch `<pattern>` def, returning the pattern id for `fill="url(#id)"`. */
hatchpattern(name?: string, color?: string, linewidth?: number): string;
/** Create an SVG `<clipPath>` def from raw path data. */
addclip(clipId: string, pathData: string): void;
/** Attach a clip-path to an element by BBox (aligned with Python `Figure.addclip`). */
addclipBbox(bboxClip: BBox): string | undefined;
plot(xs: number[], ys: number[], style?: SvgStyleOpts & {
zorder?: number;
clip?: BBox;
}): void;
circle(cx: number, cy: number, radius: number, style?: SvgStyleOpts & {
zorder?: number;
}): void;
/** Arrowhead at user-space `xy`, `thetaDeg` is line direction in degrees (see Python `Figure.arrow`). */
arrow(xy: [number, number], thetaDeg: number, opts?: {
arrowwidth?: number;
arrowlength?: number;
color?: string;
lw?: number;
zorder?: number;
}): void;
text(s: string, x: number, y: number, opts?: {
color?: string;
fontsize?: number;
fontfamily?: string;
rotation?: number;
halign?: Halign;
valign?: Valign;
rotation_mode?: RotationMode;
zorder?: number;
/** Wraps `<text>` in `<a href="...">` (e.g. Python `IcPin.href`). */
href?: string;
/** CSS `text-decoration` for pin name styling (`underline` / `overline`). */
textDecoration?: "underline" | "overline";
}): void;
/** Polygon / polyline — aligned with Python `Figure.poly`. */
poly(verts: readonly {
x: number;
y: number;
}[], opts?: {
closed?: boolean;
color?: string;
fill?: string;
lw?: number;
ls?: Linestyle;
hatch?: boolean;
capstyle?: Capstyle;
joinstyle?: Joinstyle;
zorder?: number;
}): void;
/** Cubic (4 points) or quadratic (3 points) Bézier — aligned with Python `Figure.bezier`. */
bezier(pts: readonly {
x: number;
y: number;
}[], opts?: {
color?: string;
lw?: number;
ls?: Linestyle;
capstyle?: Capstyle;
zorder?: number;
arrow?: string;
arrowlength?: number;
arrowwidth?: number;
}): void;
/** Elliptical arc — aligned with Python `Figure.arc` (subset: no arrow on arc). */
arc(center: [number, number], width: number, height: number, opts?: {
theta1?: number;
theta2?: number;
angle?: number;
color?: string;
lw?: number;
ls?: Linestyle;
fill?: string | null;
zorder?: number;
arrow?: Arcdirection | null;
arrowwidth?: number;
arrowlength?: number;
}): void;
/** Raw SVG path `d` fragments — aligned with Python `Figure.path`. */
path(parts: readonly (string | {
x: number;
y: number;
})[], opts?: {
color?: string;
lw?: number;
ls?: Linestyle;
capstyle?: Capstyle;
joinstyle?: Joinstyle;
fill?: string;
zorder?: number;
}): void;
image(imageData: string, xy: [number, number], width: number, height: number, opts?: {
rotate?: number;
zorder?: number;
imgfmt?: string;
}): void;
mathText(html: string, x: number, y: number, opts: {
width: number;
height: number;
color?: string;
fontsize?: number;
halign?: Halign;
valign?: Valign;
zorder?: number;
rotation?: number;
}): void;
/** Begin an SVG `<g>` group; elements added after this call will be wrapped on `endGroup()`. */
beginGroup(attrs: Record<string, string>, title?: string): void;
/** End the most recent `<g>` group opened by `beginGroup()`. */
endGroup(): void;
/** Sorted SVG children inner XML. */
toSvgInnerXml(): string;
toSvgString(): string;
}