import type { Component } from './component.js'; import type { PCB } from './pcb/pcb.js'; /** * A deferred placement value that is resolved by the Component constructor * using the component's own footprint bounds. This enables edge-to-edge * spacing without manually specifying the target footprint. * * You typically don't construct this directly — it is returned by placement * functions like {@link below}, {@link above}, {@link rightOf}, {@link leftOf}, * and {@link BoardBounds.fromLeft}. */ export declare class PlacementValue { private readonly _resolve; constructor(resolve: (targetBounds: { width: number; height: number; } | null) => number); /** @internal */ resolveWithFootprint(footprint: string): number; } /** * Returns `true` if the value is a {@link PlacementValue} instance. * * @param value - Any value to check. */ export declare function isPlacementValue(value: unknown): value is PlacementValue; /** A number or a deferred {@link PlacementValue} that resolves to a number. */ export type PlacementNumber = number | PlacementValue; /** * Returned by directional placement functions ({@link below}, {@link above}, * {@link rightOf}, {@link leftOf}). Call `.by()` to specify the gap. * * @example * ```ts * const r2 = new Resistor({ pcb: { x: 10, y: below(r1).by(3) } }); * ``` */ export interface PlacementBuilder { /** * Specify the gap in millimeters from the source component's edge to the * target component's edge (edge-to-edge). Returns a number or a * {@link PlacementValue} that the Component constructor resolves * automatically. * * When no `target` is provided, a {@link PlacementValue} is returned that * resolves using the new component's own footprint — so the gap is * edge-to-edge with no extra work. * * When a `target` is provided (a {@link Component} or footprint string * like `"Capacitor_SMD:C_0603_1608Metric"`), a plain number is returned * immediately. * * @param gap - Edge-to-edge gap in mm. Defaults to `2`. * @param target - Optional target component or footprint string for explicit bounds lookup. * * @example * ```ts * // Automatic — resolves using the new component's own footprint * new Capacitor({ pcb: { y: below(r1).by(3) } }); * * // Explicit target component * new Capacitor({ pcb: { y: below(r1).by(3, someOtherCap) } }); * * // Default 2mm gap * new Capacitor({ pcb: { y: below(r1).by() } }); * ``` */ by(gap?: number, target?: Component | string): PlacementNumber; } /** * Board boundary dimensions derived from `pcb.outline()` calls. * Returned by {@link board}. * * All coordinates are in millimeters. `top`/`bottom` follow KiCad's * coordinate system where Y increases downward. */ export interface BoardBounds { /** Center point of the board outline. */ readonly center: { x: number; y: number; }; /** Minimum Y of the board edge (top edge). */ readonly top: number; /** Maximum Y of the board edge (bottom edge). */ readonly bottom: number; /** Minimum X of the board edge (left edge). */ readonly left: number; /** Maximum X of the board edge (right edge). */ readonly right: number; /** Board width in mm (right − left). */ readonly width: number; /** Board height in mm (bottom − top). */ readonly height: number; /** Top-left corner coordinates. */ readonly topLeft: { x: number; y: number; }; /** Top-right corner coordinates. */ readonly topRight: { x: number; y: number; }; /** Bottom-left corner coordinates. */ readonly bottomLeft: { x: number; y: number; }; /** Bottom-right corner coordinates. */ readonly bottomRight: { x: number; y: number; }; /** * Returns a placement value for the X coordinate that positions a * component's courtyard `margin` mm from the left board edge (edge-to-edge). * * @param margin - Gap from board edge to component courtyard in mm. Defaults to `2`. * * @example * ```ts * const b = board(pcb); * const j1 = new Component({ footprint: '...', pcb: { * x: b.fromLeft(5), * y: b.center.y, * }}); * ``` */ fromLeft(margin?: number): PlacementValue; /** * Returns a placement value for the X coordinate that positions a * component's courtyard `margin` mm from the right board edge (edge-to-edge). * * @param margin - Gap from board edge to component courtyard in mm. Defaults to `2`. * * @example * ```ts * const b = board(pcb); * const tp = new Component({ footprint: '...', pcb: { * x: b.fromRight(1), * y: b.fromTop(1), * }}); * ``` */ fromRight(margin?: number): PlacementValue; /** * Returns a placement value for the Y coordinate that positions a * component's courtyard `margin` mm from the top board edge (edge-to-edge). * * @param margin - Gap from board edge to component courtyard in mm. Defaults to `2`. */ fromTop(margin?: number): PlacementValue; /** * Returns a placement value for the Y coordinate that positions a * component's courtyard `margin` mm from the bottom board edge (edge-to-edge). * * @param margin - Gap from board edge to component courtyard in mm. Defaults to `2`. */ fromBottom(margin?: number): PlacementValue; } /** * Returned by {@link sameAs}. Provides live access to a component's * X and Y PCB coordinates. * * @example * ```ts * const pos = sameAs(r1); * new Capacitor({ pcb: { x: pos.x, y: below(r1).by(3) } }); * ``` */ export interface SameAsResult { /** The component's current PCB X coordinate (live). */ readonly x: number; /** The component's current PCB Y coordinate (live). */ readonly y: number; } /** * Places a component below the given source component. Returns a * {@link PlacementBuilder} — call `.by(gap)` to specify the edge-to-edge * gap in mm. * * The gap is measured from the **bottom edge** of the source component's * bounding box to the **top edge** of the target component's bounding box. * * @param component - The reference component to place below. * @returns A builder with a `.by()` method. * * @example * ```ts * const r1 = new Resistor({ pcb: { x: 10, y: 10 } }); * * // 3mm edge-to-edge gap, resolved automatically * const c1 = new Capacitor({ pcb: { * x: sameAs(r1).x, * y: below(r1).by(3), * }}); * ``` */ export declare function below(component: Component): PlacementBuilder; /** * Places a component above the given source component. Returns a * {@link PlacementBuilder} — call `.by(gap)` to specify the edge-to-edge * gap in mm. * * The gap is measured from the **top edge** of the source component's * bounding box to the **bottom edge** of the target component's bounding box. * * @param component - The reference component to place above. * @returns A builder with a `.by()` method. * * @example * ```ts * const led = new LED({ pcb: { * x: sameAs(mcu).x, * y: above(mcu).by(8), * }}); * ``` */ export declare function above(component: Component): PlacementBuilder; /** * Places a component to the right of the given source component. Returns a * {@link PlacementBuilder} — call `.by(gap)` to specify the edge-to-edge * gap in mm. * * The gap is measured from the **right edge** of the source component's * bounding box to the **left edge** of the target component's bounding box. * * @param component - The reference component to place to the right of. * @returns A builder with a `.by()` method. * * @example * ```ts * const r1 = new Resistor({ pcb: { * x: rightOf(c1).by(3), * y: sameAs(c1).y, * }}); * ``` */ export declare function rightOf(component: Component): PlacementBuilder; /** * Places a component to the left of the given source component. Returns a * {@link PlacementBuilder} — call `.by(gap)` to specify the edge-to-edge * gap in mm. * * The gap is measured from the **left edge** of the source component's * bounding box to the **right edge** of the target component's bounding box. * * @param component - The reference component to place to the left of. * @returns A builder with a `.by()` method. * * @example * ```ts * const r2 = new Resistor({ pcb: { * x: leftOf(led1).by(4), * y: sameAs(led1).y, * }}); * ``` */ export declare function leftOf(component: Component): PlacementBuilder; /** * Returns the X and Y PCB coordinates of a component for alignment. * The returned object is live — if the component moves, the values update. * * @param component - The component whose position to mirror. * @returns An object with `.x` and `.y` properties. * * @example * ```ts * // Place c1 directly below r1, aligned in X * const c1 = new Capacitor({ pcb: { * x: sameAs(r1).x, * y: below(r1).by(3), * }}); * ``` */ export declare function sameAs(component: Component): SameAsResult; /** * Returns the board boundary dimensions derived from the PCB's outline * (Edge.Cuts layer). Use this to place components relative to the board edges. * * If no outline has been defined, all properties return `0`. * * @param pcb - The PCB instance (must have had `pcb.outline()` called). * @returns A {@link BoardBounds} object with center, edges, corners, and `from*` methods. * * @example * ```ts * const typecad = new PCB('myboard'); * typecad.outline(0, 0, 60, 45); * * const b = board(typecad); * * // Place MCU at board center * mcu.pcb = { x: b.center.x, y: b.center.y }; * * // Place connector 5mm from left edge (edge-to-edge) * const j1 = new Component({ footprint: '...', pcb: { * x: b.fromLeft(5), * y: b.center.y, * }}); * * // Place test point 1mm from top-right corner (edge-to-edge) * const tp = new Component({ footprint: '...', pcb: { * x: b.fromRight(1), * y: b.fromTop(1), * }}); * ``` */ export declare function board(pcb: PCB): BoardBounds; //# sourceMappingURL=placement.d.ts.map