@skillpet/circuit
Version:
Circuit diagram library — render electrical schematics from JSON, with interactive SVG, themes, and Vue/React components
114 lines (113 loc) • 4.6 kB
TypeScript
/**
* Base element — subset aligned with Python `elements/elements.py` · `Element`.
*/
import type { BBox, Linestyle } from "./types.js";
import { Point, type XY } from "./geometry/point.js";
import { Transform } from "./geometry/transform.js";
import { type ElementLabelSpec } from "./element-label.js";
import type { LabelHint } from "./label-hint.js";
import type { SegmentLike } from "./segment.js";
/** Cardinal and default anchor names considered by Python `Element.__getattr__`. */
export declare const ELEMENT_GETATTR_ANCHOR_NAMES: readonly string[];
export declare class Element {
readonly userParams: Record<string, unknown>;
readonly elmParams: Record<string, unknown>;
dwgParams: Record<string, unknown>;
defaults: Record<string, unknown>;
segments: SegmentLike[];
anchors: Record<string, XY>;
absanchors: Record<string, Point>;
transform: Transform;
absdrop: {
point: Point;
theta: number;
};
_positioned: boolean;
_localshift: Point;
bbox: BBox;
/** User labels from {@link label} (Python `_userlabels`). */
protected userLabels: ElementLabelSpec[];
/** Default label placement when `loc` matches an anchor (Python `_labelhints`). */
protected _labelhints: Record<string, LabelHint>;
/** Geometry segment count before {@link placeElementLabels} runs (re-_place idempotence). */
private _segmentCountBeforeLabels;
constructor(userParams?: Record<string, unknown>);
get params(): Record<string, unknown>;
/** Absolute anchor after placement (Python `element[name]` / `absanchors`). */
getAbsAnchor(name: string): Point | undefined;
/**
* Names that trigger Python `Element.__getattr__` / `drawing_stack.push_element(self)`
* when `absanchors[name]` is not yet set (base: {@link ELEMENT_GETATTR_ANCHOR_NAMES} + `anchors` keys).
*/
getAnchorNamesForGetattr(): string[];
/**
* Python `Element.__getattr__` side effect: access to a known anchor name before placement
* calls `push_element(self)` (may implicitly `drawing.add(this)`).
*/
touchAnchorAccess(name: string): void;
/**
* Python `element[name]` after implicit placement: {@link touchAnchorAccess} then {@link getAbsAnchor}.
*/
resolveAnchor(name: string): Point | undefined;
protected _position(): void;
/** Python `Element._flipreverse` — mutate segments and anchors when flip/reverse set. */
protected _flipreverse(): void;
up(): this;
down(): this;
left(): this;
right(): this;
theta(angle: number): this;
drop(drop: string | XY): this;
at(xy: XY | readonly [Element, string], dx?: number, dy?: number): this;
scale(scale?: number): this;
scalex(scale?: number): this;
scaley(scale?: number): this;
flip(): this;
reverse(): this;
anchor(name: string): this;
color(color: string): this;
linestyle(ls: Linestyle | string): this;
linewidth(lw: number): this;
fill(color?: boolean | string): this;
zorder(z: number): this;
hold(): this;
/** Python `Element.style` — apply several style keys at once. */
style(opts: {
color?: string;
fill?: string | boolean;
ls?: Linestyle | string;
lw?: number;
}): this;
fontsize(n: number): this;
font(f: string): this;
mathfont(f: string): this;
/**
* Python `gradient_fill` — SVG linear gradient (see `Drawing.toSvgString` + `SegmentPoly`/`SegmentCircle` fill).
*/
gradientFill(color1: string, color2: string, vertical?: boolean): this;
/**
* Add a text label (Python `Element.label` subset; see `element-label.ts`).
* Merged with `label` / `toplabel` / … from params during `_place`.
*/
label(text: string | readonly string[], opts?: {
loc?: string | null;
ofst?: number | XY;
halign?: "left" | "center" | "right";
valign?: "top" | "center" | "bottom" | "base";
rotate?: boolean | number;
fontsize?: number;
font?: string;
mathfont?: string;
color?: string;
href?: string | null;
decoration?: string | null;
}): this;
/** Python `_labelhints[loc]` — merged in `placeElementLabels` when `ignore_hints` is not set. */
getLabelHint(loc: string): LabelHint | undefined;
_place(dwgxy: XY, dwgtheta: number, dwgparams: Record<string, unknown>): {
point: Point;
theta: number;
};
getBBox(transform: boolean, includetext?: boolean): BBox;
_draw(fig: import("./svg/figure.js").SvgFigure): void;
}