@skillpet/circuit
Version:
Circuit diagram library — render electrical schematics from JSON, with interactive SVG, themes, and Vue/React components
267 lines (266 loc) • 8.44 kB
TypeScript
/**
* Drawing segments — subset aligned with Python `segments.py`.
*/
import type { Arcdirection, BBox, Capstyle, Joinstyle, Linestyle } from "./types.js";
import { type XY } from "./geometry/point.js";
import { Transform } from "./geometry/transform.js";
import { type SvgFigure } from "./svg/figure.js";
export declare const GAP: [number, number];
export type SegmentPathPoint = XY | typeof GAP;
export declare class Segment {
path: [number, number][];
color?: string;
lw?: number;
ls?: Linestyle;
capstyle?: Capstyle;
joinstyle?: Joinstyle;
fill?: string | boolean;
arrow?: string;
arrowwidth: number;
arrowlength: number;
zorder?: number;
visible: boolean;
clip?: BBox;
role?: 'lead1' | 'lead2' | 'body';
gradientStrokeId?: string;
constructor(path: SegmentPathPoint[], opts?: {
color?: string;
lw?: number;
ls?: Linestyle;
capstyle?: Capstyle;
joinstyle?: Joinstyle;
fill?: string | boolean;
arrow?: string;
arrowwidth?: number;
arrowlength?: number;
zorder?: number;
visible?: boolean;
clip?: BBox;
});
xform(transform: Transform, style: Record<string, unknown>): Segment;
getBBox(): BBox;
/** Python `Segment.doreverse` — mirror path after reversing point order. */
doreverse(centerx: number): void;
/** Python `Segment.doflip` — vertical flip of path points. */
doflip(): void;
draw(fig: SvgFigure, transform: Transform, style: Record<string, unknown>): void;
}
export declare class SegmentCircle {
center: [number, number];
radius: number;
color?: string;
lw?: number;
ls?: string;
fill?: string | boolean;
zorder?: number;
visible: boolean;
constructor(center: [number, number], radius: number, opts?: {
color?: string;
lw?: number;
ls?: string;
fill?: string | boolean;
zorder?: number;
});
xform(transform: Transform, style: Record<string, unknown>): SegmentCircle;
getBBox(): BBox;
doreverse(centerx: number): void;
doflip(): void;
draw(fig: SvgFigure, transform: Transform, style: Record<string, unknown>): void;
}
/** Text label in element-local coordinates — aligned with Python `SegmentText` (subset). */
export declare class SegmentText {
xy: [number, number];
readonly text: string;
color?: string;
fontsize?: number;
fontfamily?: string;
/** Math font (Python `SegmentText.mathfont`); used when text contains `$…$` (no Ziamath — SVG font-family only). */
mathfont?: string;
zorder?: number;
visible: boolean;
halign?: "left" | "center" | "right";
valign?: "top" | "center" | "bottom" | "base";
/** Hyperlink on label (Python `IcPin.href`). */
href?: string;
/** `"underline"` / `"overline"` (Python `IcPin.decoration`). */
decoration?: string | null;
/**
* Extra rotation in degrees (local), added to the element transform (Python `IcPin` name labels).
* If omitted, text is not rotated with the element (legacy behavior for unlabeled segments).
*/
rotation?: number;
constructor(xy: XY, text: string, opts?: {
color?: string;
fontsize?: number;
fontfamily?: string;
mathfont?: string;
zorder?: number;
visible?: boolean;
align?: readonly [string | undefined, string | undefined];
halign?: "left" | "center" | "right";
valign?: "top" | "center" | "bottom" | "base";
href?: string | null;
decoration?: string | null;
rotation?: number;
});
xform(transform: Transform, style: Record<string, unknown>): SegmentText;
getBBox(): BBox;
doreverse(centerx: number): void;
doflip(): void;
draw(fig: SvgFigure, transform: Transform, style: Record<string, unknown>): void;
}
export declare class SegmentPoly {
verts: [number, number][];
closed: boolean;
cornerradius: number;
color?: string;
fill?: string | boolean;
lw?: number;
ls?: Linestyle;
hatch?: boolean;
joinstyle?: Joinstyle;
capstyle?: Capstyle;
zorder?: number;
visible: boolean;
clip?: BBox;
constructor(verts: [number, number][], opts?: {
closed?: boolean;
cornerradius?: number;
color?: string;
fill?: string | boolean;
lw?: number;
ls?: Linestyle;
hatch?: boolean;
joinstyle?: Joinstyle;
capstyle?: Capstyle;
zorder?: number;
visible?: boolean;
clip?: BBox;
});
xform(transform: Transform, style: Record<string, unknown>): SegmentPoly;
getBBox(): BBox;
doreverse(centerx: number): void;
doflip(): void;
draw(fig: SvgFigure, transform: Transform, style: Record<string, unknown>): void;
}
export declare class SegmentArc {
center: [number, number];
width: number;
height: number;
theta1: number;
theta2: number;
arrow?: Arcdirection | null;
arrowwidth: number;
arrowlength: number;
angle: number;
color?: string;
lw?: number;
ls?: Linestyle;
fill?: string;
zorder?: number;
visible: boolean;
clip?: BBox;
constructor(center: [number, number], width: number, height: number, opts?: {
theta1?: number;
theta2?: number;
arrow?: Arcdirection | null;
arrowwidth?: number;
arrowlength?: number;
angle?: number;
color?: string;
lw?: number;
ls?: Linestyle;
fill?: string;
zorder?: number;
visible?: boolean;
clip?: BBox;
});
xform(transform: Transform, style: Record<string, unknown>): SegmentArc;
getBBox(): BBox;
doreverse(centerx: number): void;
doflip(): void;
draw(fig: SvgFigure, transform: Transform, style: Record<string, unknown>): void;
}
export declare class SegmentBezier {
p: [number, number][];
color?: string;
lw?: number;
ls?: Linestyle;
capstyle?: Capstyle;
arrow?: string;
arrowlength: number;
arrowwidth: number;
zorder?: number;
visible: boolean;
clip?: BBox;
constructor(pts: [number, number][], opts?: {
color?: string;
lw?: number;
ls?: Linestyle;
capstyle?: Capstyle;
arrow?: string;
arrowlength?: number;
arrowwidth?: number;
zorder?: number;
visible?: boolean;
clip?: BBox;
});
xform(transform: Transform, style: Record<string, unknown>): SegmentBezier;
getBBox(): BBox;
doreverse(centerx: number): void;
doflip(): void;
draw(fig: SvgFigure, transform: Transform, style: Record<string, unknown>): void;
}
export declare class SegmentPath {
path: readonly (string | [number, number])[];
color?: string;
lw?: number;
ls?: Linestyle;
capstyle?: Capstyle;
joinstyle?: Joinstyle;
fill?: string | boolean;
zorder?: number;
visible: boolean;
clip?: BBox;
constructor(path: readonly (string | [number, number])[], opts?: {
color?: string;
lw?: number;
ls?: Linestyle;
capstyle?: Capstyle;
joinstyle?: Joinstyle;
fill?: string | boolean;
zorder?: number;
visible?: boolean;
clip?: BBox;
});
xform(transform: Transform, style: Record<string, unknown>): SegmentPath;
getBBox(): BBox;
/** SVG path commands are not transformed; matches Python stub. */
doreverse(_centerx: number): void;
doflip(): void;
draw(fig: SvgFigure, transform: Transform, style: Record<string, unknown>): void;
}
export declare class SegmentImage {
image: string;
xy: [number, number];
width: number;
height: number;
rotate: number;
imgfmt?: string;
zorder?: number;
visible: boolean;
constructor(image: string, opts?: {
xy?: [number, number];
width?: number;
height?: number;
rotate?: number;
imgfmt?: string;
zorder?: number;
});
getBBox(): BBox;
xform(transform: Transform, style: Record<string, unknown>): SegmentImage;
doreverse(_centerx: number): void;
doflip(): void;
draw(fig: SvgFigure, transform: Transform, style: Record<string, unknown>): void;
}
export type SegmentLike = Segment | SegmentCircle | SegmentText | SegmentPoly | SegmentArc | SegmentBezier | SegmentPath | SegmentImage;