import { Component } from './component.js'; import { TrackBuilder, PCB } from './pcb/pcb.js'; import { Pin } from './pin.js'; export type PassiveFactory = { Resistor: new (options?: { value?: string; [key: string]: unknown; }) => Component; Capacitor: new (options?: { value?: string; [key: string]: unknown; }) => Component; Inductor: new (options?: { value?: string; [key: string]: unknown; }) => Component; Diode: new (options?: { value?: string; [key: string]: unknown; }) => Component; LED: new (options?: { value?: string; [key: string]: unknown; }) => Component; Fuse: new (options?: { value?: string; [key: string]: unknown; }) => Component; }; /** * Base options required by every Package. * User-defined option interfaces extend this. */ export interface PackageOptions { pcb: PCB; x: number; y: number; reference?: string; /** Name used for the PCB group. Defaults to the class name. */ name?: string; passives?: PassiveFactory; } /** * ### Package * * Abstract base class for TypeCAD hardware packages. * * A Package is a self-contained module that wraps one or more components, * manages their passive components, connects power, peripherals, and routing, * and groups them on the PCB. * * #### Usage * ```typescript * export class rd_isl9120ir extends Package<{ inputPower?: Power }> { * regulator: ISL9120IRTNZ; * inputCap: Component; * * build(options) { * this.regulator = new ISL9120IRTNZ(this.reference); * this.regulator.pcb = { x: 150.6, y: 97.725, rotation: 0 }; * * this.inputCap = new this.passives.Capacitor({ value: '22 uF' }); * this.inputCap.pcb = { x: 153.67, y: 99.047, rotation: -90 }; * * this.net(this.regulator.VIN_1, this.inputCap.pin(2)); * } * } * ``` * * All `Component` properties set on `this` inside `build()` are automatically * collected — no `this.components.push(...)` required. * * For tracks, use `this.add(this.track().from(...).to(...))` since track chains * are not stored as named properties. */ export declare abstract class Package { /** The PCB instance this package is placed on. */ protected readonly pcb: PCB; /** The passive component factory (default: 0603). */ protected readonly passives: PassiveFactory; /** Optional reference designator prefix for the main IC (e.g. 'U2'). */ protected readonly reference: string | undefined; /** * All PCB elements belonging to this package (components + track builders). * Populated automatically after `build()` via property reflection. * Use `this.add()` for tracks or any element not stored as a named property. */ readonly components: (Component | TrackBuilder)[]; constructor(options: PackageOptions & TOptions); /** * Implement all component creation, net connections, and routing here. * All Component properties assigned to `this` are automatically collected. */ protected abstract build(options: PackageOptions & TOptions): void; /** * Connect one or more pins to the same net. * Shorthand for `this.pcb.net(...)`. */ protected net(...pins: Pin[]): void; /** * Place a PCB via and automatically register it in `components`. */ protected via(at: { x: number; y: number; }, size?: 0.6, drill?: 0.3): Component; /** * Start a track chain. Use `this.add()` to register the completed track. * * Example: * ```typescript * this.add(this.track().from({ x: 152.05, y: 96.87 }).to({ x: 152.4, y: 96.52, layer: 'F.Cu', width: 0.2 })); * ``` */ protected track(): TrackBuilder; /** * Manually register one or more components or track builders. * Use this for tracks (which are not stored as named properties) * or for components inside arrays. */ protected add(...items: (Component | TrackBuilder)[]): void; /** * Called when no passives factory is provided. * @typecad/passives is an ecosystem package — install it separately and * pass it via the `passives` option. */ private _defaultPassives; /** * After `build()` runs, walk all own enumerable properties of the subclass * instance. Any value that is a `Component` or `TrackBuilder` and has not * already been manually pushed to `this.components` is collected automatically. */ private _autoCollect; /** * Apply the current PCB offset to all collected components' `.pcb` positions. * Tracks and vias already had offsets applied at creation time via PCB methods, * so only regular Components need adjustment. */ private _applyOffset; } //# sourceMappingURL=package.d.ts.map