import { AcEdBaseView } from '../../view'; import { AcEdInputModifiers } from '../AcEdInputModifiers'; import { AcEdInputToggles } from '../AcEdInputToggles'; import { AcEdPromptAngleOptions, AcEdPromptBoxOptions, AcEdPromptBoxResult, AcEdPromptDistanceOptions, AcEdPromptDoubleOptions, AcEdPromptDoubleResult, AcEdPromptEntityOptions, AcEdPromptEntityResult, AcEdPromptIntegerOptions, AcEdPromptIntegerResult, AcEdPromptKeywordOptions, AcEdPromptPointOptions, AcEdPromptPointResult, AcEdPromptResult, AcEdPromptSelectionOptions, AcEdPromptSelectionResult, AcEdPromptStringOptions } from '../prompt'; import { AcEdMessageType } from './AcEdMessageType'; /** * A fully type-safe TypeScript class providing CAD-style interactive user input * using floating HTML input boxes and mouse events. Supports collecting points, * distances, angles, numbers, strings, and selecting a 2-point rectangular box * using an HTML overlay rectangle (suitable when the main canvas is a THREE.js * WebGL canvas). */ export declare class AcEdInputManager { /** Inject styles only once */ private static stylesInjected; /** The view associated with this input operation */ protected view: AcEdBaseView; /** Stores last confirmed point from getPoint() or getBox() */ private lastPoint; /** Command line UI component */ private _commandLine; /** Buffered command-line style inputs (each item is one Enter-confirmed value). */ private _scriptInputs; /** Current modifier key state during input sessions. */ private _modifierState; /** Toggle-style Ctrl flip state (press Ctrl once to flip arc direction). */ private _ctrlArcFlip; /** * The flag to indicate whether it is currently in an “input acquisition” mode (e.g., point * selection, distance/angle prompt, string prompt, etc.), */ private active; /** * True only when the current input session explicitly expects entity selection * (getEntity/getSelection). Used to gate view-level selection behavior. */ private entitySelectionActive; /** * Construct the manager and attach mousemove listener used for floating input * positioning and live preview updates. * * @param view - The view associated with the input manager */ constructor(view: AcEdBaseView); /** * The flag to indicate whether it is currently in an “input acquisition” mode (e.g., point * selection, distance/angle prompt, string prompt, etc.), */ get isActive(): boolean; /** * Whether current input session allows entity selection in the view. */ get isEntitySelectionActive(): boolean; /** * Current modifier key state (Ctrl/Shift/Alt/Meta) during input sessions. */ get modifiers(): AcEdInputModifiers; /** * Toggle-style input states (press once to flip, persists after keyup). */ get toggles(): AcEdInputToggles; /** Reset toggle-style inputs to their default state. */ resetToggles(): void; /** * Queue scripted inputs for subsequent getXXX calls. * One array item equals one Enter-confirmed value. */ enqueueScriptInputs(inputs: string[]): void; /** Clears any pending scripted inputs. */ clearScriptInputs(): void; /** * Displays a typed message in the command-line message panel. * * @param message - Message text to render * @param type - Message severity controlling the rendered style * @param msgKey - Optional localization key associated with the message */ showMessage(message: string, type?: AcEdMessageType, msgKey?: string): void; /** * Returns the next scripted token without consuming it. * * @returns Next queued scripted token, or `undefined` when empty. */ peekScriptInput(): string; /** * Consumes and returns the next scripted token. * * @returns Next queued scripted token, or `undefined` when empty. */ consumeScriptInput(): string | undefined; /** * Injects minimal CSS required for the floating input and preview rectangle. * Useful when you do not have a separate CSS file. */ private injectCSS; /** * Format a number for display in input box. * Default: 3 decimal places for points/distance, 2 decimal places for angles. * @param value The numeric value * @param type Optional type: 'point' | 'distance' | 'angle' */ private formatNumber; /** * Returns whether the supplied prompt defines any keywords. * * Keyword-aware prompts need extra command-line wiring so textual input can * be interpreted as keyword picks instead of free-form values. This helper * centralizes the check and gracefully handles prompts that expose no keyword * collection. * * @param options - Prompt options to inspect * @returns `true` when at least one keyword is registered on the prompt */ private hasKeywords; /** * Builds a keyword-only prompt options object from a general prompt. * * Several input flows support optional keywords in parallel with their main * acquisition mode. Rather than duplicating keyword definitions manually, the * original prompt's keyword metadata is cloned into a dedicated * `AcEdPromptKeywordOptions` instance that can be passed to the command-line * keyword session. * * @typeParam T - Value type produced by the source prompt * @param options - Source prompt whose keyword definitions should be copied * @returns A keyword prompt configured with the same message and keyword set */ private buildKeywordOptions; /** * Copies keyword definitions from one prompt options object to another. * * This is primarily used by composite prompts such as `getBox()`, which break * a higher-level workflow into multiple sub-prompts while preserving the same * keyword vocabulary and default keyword behavior across each stage. * * @param source - Prompt options providing the keyword definitions * @param target - Prompt options receiving the cloned keyword definitions */ private copyKeywords; /** * Resolves a picked object id back to its database entity instance. * * View-level picking only returns lightweight hit-test data such as object * ids and bounding information. Prompt validation, however, needs access to * the backing `AcDbEntity` so it can inspect runtime metadata like the entity * type and layer. * * @param objectId - Object id returned by the spatial pick query * @returns The matching database entity, or `undefined` if it can no longer be found */ private getEntityById; /** * Returns whether the specified entity belongs to a locked layer. * * The entity itself only stores its layer name, so this helper resolves the * layer record from the current drawing database and inspects its lock state. * Missing layer records are treated as unlocked to avoid rejecting input due * to incomplete metadata. * * @param entity - Entity being evaluated for prompt selection * @returns `true` if the entity's layer exists and is locked; otherwise `false` */ private isEntityOnLockedLayer; /** * Checks whether a picked entity satisfies the prompt's allowed-class filter. * * Different parts of the stack expose the entity type in slightly different * forms. The data-model layer provides a short CAD type name through * `entity.type` (for example `Line`), while runtime inspection exposes the * TypeScript constructor name (for example `AcDbLine`). To maximize * compatibility with existing caller expectations, both forms are tested * against the prompt's allow-list. * * @param entity - Picked entity being validated * @param options - Prompt options containing the configured allowed classes * @returns `true` when the entity matches at least one allowed class, or when * no class restriction has been configured */ private isEntityClassAllowed; /** * Starts a command-line keyword session for the given prompt when needed. * * Many interactive prompts accept both mouse-driven input and typed keywords * at the same time. This helper lazily creates the command-line keyword * session only when keywords are actually configured, and returns a small * control object that lets callers await or cancel that session. * * @param options - Prompt options that may define keywords * @param allowTyping - Whether arbitrary typing is allowed alongside keyword completion * @returns An object containing the keyword promise and cancel callback, or * `undefined` when the prompt has no keywords */ private startKeywordSession; /** * Narrows an unknown error value to the internal keyword control-flow error. * * Prompt implementations use {@link AcEdKeywordInputError} as a private * mechanism for bubbling a keyword pick out of deeply nested async UI flows. * This type guard keeps the outer prompt wrappers readable while preserving * strong typing for the extracted keyword token. * * @param error - Unknown error value thrown from an input workflow * @returns `true` if the error represents a keyword selection */ private isPromptKeyword; /** * Converts internal prompt control-flow errors to typed prompt results. * * @typeParam T - Prompt result type to construct * @param error - Unknown error thrown from prompt workflow * @param handlers - Result factories for mapped prompt statuses * @returns Mapped prompt result when recognized; otherwise `undefined` */ private mapPromptError; /** * Attaches keyword text to a prompt result and returns it. */ private withKeywordResult; /** * Maps internal control-flow errors to prompt results by status constructor. * * @typeParam T - Prompt result type * @param error - Unknown error thrown from prompt workflow * @param create - Factory creating a result from target status * @param options - Toggles for supported mapped statuses */ private mapPromptErrorToResult; /** * Executes prompt workflow with centralized try/catch mapping. * * @typeParam T - Raw successful value from prompt workflow * @typeParam R - Prompt result type * @param run - Async prompt workflow that may throw control-flow errors * @param onOk - Maps successful workflow value to result object * @param create - Creates a result object from mapped prompt status * @param options - Toggles for supported mapped statuses */ private executePrompt; /** * Extracts default-value behavior from prompt options when supported. */ private resolvePromptDefaultValue; /** * Prompts the user to specify a point. * * The point may be supplied by clicking in the view, typing coordinates into * the floating input, or consuming a queued scripted input token. Keywords are * also supported when configured on the prompt options. * * @param options - Point prompt options controlling messaging, base-point * behavior, jig integration, and keywords * @returns A prompt result containing the picked point, cancel status, or keyword */ getPoint(options: AcEdPromptPointOptions): Promise; /** * Prompts the user for a purely typed numeric value through floating input. * * This helper is shared by distance, angle, double, and integer prompts when * no mouse-driven geometric reference is needed. Validation is delegated to * the supplied handler so the floating UI can mark invalid values and keep * the prompt alive until the user enters an acceptable number. * * @param options - Numeric prompt options describing the message and keyword set * @param handler - Parser/validator responsible for converting raw text into a number * @returns A promise that resolves to the parsed numeric value */ private getNumberTyped; /** * Prompts the user to specify a distance value. * * When a base point is available, the floating input previews the live * distance from that reference point to the current cursor. Otherwise, the * method falls back to typed numeric entry only. Scripted inputs and keywords * are supported as well. * * @param options - Distance prompt options controlling base-point behavior and messaging * @returns A prompt result containing the resolved distance, cancel status, or keyword */ getDistance(options: AcEdPromptDistanceOptions): Promise; /** * Prompts the user to specify an angle in degrees. * * If a base point is available, the cursor position is converted into a live * angular preview relative to that point and the optional prompt base angle. * Without a geometric reference, the method accepts typed numeric input only. * * @param options - Angle prompt options controlling base point, base angle, and messaging * @returns A prompt result containing the resolved angle, cancel status, or keyword */ getAngle(options: AcEdPromptAngleOptions): Promise; /** * Prompts the user for a floating-point number. * * This is the generic free-form numeric entry path used when no geometric * interpretation such as distance or angle is required. * * @param options - Double prompt options controlling validation and messaging * @returns A prompt result containing the parsed number, cancel status, or keyword */ getDouble(options: AcEdPromptDoubleOptions): Promise; /** * Prompts the user for an integer value. * * The supplied integer handler enforces integer-only parsing for both typed * input and scripted command input. * * @param options - Integer prompt options controlling validation and messaging * @returns A prompt result containing the parsed integer, cancel status, or keyword */ getInteger(options: AcEdPromptIntegerOptions): Promise; /** * Prompts the user to type an arbitrary string. * * The value is collected through the shared floating-input pipeline so it can * participate in the same cancellation, keyword, and scripted-input behavior * as the other prompt types. * * @param options - String prompt options controlling the prompt message and keywords * @returns A prompt result containing the entered string, cancel status, or keyword */ getString(options: AcEdPromptStringOptions): Promise; /** * Prompts the user to enter one of the configured keywords. * * Unlike the mixed-mode keyword sessions used by other prompt types, this * method runs a dedicated keyword prompt and returns the chosen keyword as the * result value. * * @param options - Keyword prompt options describing the allowed keywords * @returns A prompt result containing the chosen keyword or cancel status */ getKeywords(options: AcEdPromptKeywordOptions): Promise; /** * Prompts the user to select one or more entities by mouse interaction. * * This method supports two selection modes: * * - **Click selection**: Clicking on an entity selects the entity under the cursor. * - **Box selection**: * - left-to-right drag: window selection (entities fully inside the box) * - right-to-left drag: crossing selection (entities intersecting the box) * * The selection operation behaves similarly to AutoCAD's * `Editor.GetSelection()` API: * * - Press **Enter** to accept the current selection set. * - Press **Escape** to cancel the operation. * - If {@link AcEdPromptSelectionOptions.singleOnly} is `true`, the selection * completes immediately after the first entity is selected. * * This method does not use floating input boxes. Instead, it relies entirely on * mouse gestures and keyboard input. A floating prompt message and command line * prompt are displayed during the operation. * * @param options - Selection prompt options that control user messaging and * whether only a single entity may be selected. * @returns A promise that resolves to an array of selected entity IDs. * The array is empty if no entities are selected and the user presses Enter. * The promise is rejected if the operation is cancelled. */ getSelection(options: AcEdPromptSelectionOptions): Promise; /** * Prompts the user to select a single entity. * * Selection is performed by clicking in the view and validating the first * hit-tested entity under the cursor. The picked entity may be rejected when * it belongs to a locked layer or does not satisfy the prompt's allowed-class * filter, in which case the rejection message is shown and the prompt remains * active. Keywords and `AllowNone` behavior are also supported. * * @param options - Entity prompt options controlling filtering, messaging, and keywords * @returns A prompt result containing the selected entity id, picked point, * cancel status, or keyword */ getEntity(options: AcEdPromptEntityOptions): Promise; /** * Prompt the user to specify a rectangular box by selecting two corners. * Each corner may be specified by clicking on the canvas or typing "x,y". * A live HTML overlay rectangle previews the box as the user moves the mouse. * * The box prompt is implemented as two chained point prompts. Keywords from * the original box prompt are copied into each corner prompt so the caller * sees a consistent interaction model across both stages. * * @param options - Box prompt options controlling corner messages, preview behavior, and keywords * @returns A prompt result containing the final 2D box, cancel status, or keyword */ getBox(options: AcEdPromptBoxOptions): Promise; /** * Shared point input logic used by getPoint() and getBox(). Accepts "x,y" * typed input OR mouse click. * * This helper optionally wires extra cleanup and preview callbacks so * higher-level workflows can overlay additional temporary graphics while * reusing the same point acquisition behavior. * * @param options - Point prompt options controlling the interaction * @param cleanup - Optional callback invoked when the point prompt ends * @param drawPreview - Optional callback invoked as the cursor moves for live preview rendering * @returns A promise that resolves to the chosen point */ private getPointInternal; /** * Attempts to consume one scripted input and parse it as a point. * Supported forms: "x,y", "x,y,z", or "x y". * * Successful scripted points also update `lastPoint` so subsequent prompts * that rely on prior geometric context behave the same way as with manual * point picking. * * @param options - Point prompt options used to validate the scripted coordinates * @returns Parsed point value, or `undefined` when no scripted token is queued * @throws Error if a queued scripted token cannot be parsed as a valid point */ private tryGetScriptedPoint; /** * Attempts to consume one scripted input and parse it with the supplied handler. * * Scripted input is used to emulate command-line entry in automated or * replayed workflows. This helper keeps the parsing path consistent with * interactive input by delegating to the same handler implementation used by * the floating-input UI. * * @typeParam T - Parsed value type * @param handler - Input handler used to parse the queued token * @returns Parsed value, or `undefined` when no scripted token is available * @throws Error if a queued token exists but fails validation */ private tryGetScriptedValue; /** * Attempts to consume one scripted numeric token. * * This is a thin specialization of {@link tryGetScriptedValue} that narrows * the accepted handler types to those used by numeric-style prompts. * * @param handler - Numeric handler used to parse the queued token * @returns Parsed numeric value, or `undefined` when no scripted token is queued */ private tryGetScriptedNumber; /** * Removes and returns the next queued scripted input token. * * @returns The next scripted token, or `undefined` when the queue is empty */ private dequeueScriptInput; /** * Splits a scripted point token into x/y coordinate components. * * The accepted formats intentionally mirror common CAD command-line point * entry conventions, including comma-separated coordinates and whitespace- * separated coordinates. An optional third `z` component is tolerated for * compatibility, but only the `x` and `y` values are used by 2D prompts. * * @param token - Raw scripted point token * @returns Extracted x/y string pair, or `undefined` if the token is malformed */ private splitScriptedPoint; /** * Returns whether an unknown error value represents prompt cancellation. * * Prompt flows normalize cancellation to a regular `Error` with the message * `'cancelled'`. This helper keeps the outer result-conversion code concise * and consistent across prompt types. * * @param error - Unknown error value thrown from an input workflow * @returns `true` if the error represents prompt cancellation */ private isPromptCancelled; /** * Returns whether an unknown error value represents PromptStatus.None. * * @param error - Unknown error value thrown from an input workflow * @returns `true` if the error represents "no input" confirmation */ private isPromptNone; /** * Reads SHORTCUTMENU value from current working database. * * @returns Normalized 0..3 shortcut-menu mode */ private getShortcutMenuMode; /** * Resolves right-click behavior for current prompt session. * * SHORTCUTMENU: * 0 => always Enter * 1 => Enter in command, menu when idle * 2 => menu in command * 3 => always menu */ private shouldUseRightClickEnter; /** * Synchronizes the stored modifier-key snapshot with a DOM keyboard event. * * Floating preview rendering depends on modifier state for behaviors such as * temporary mode switches. This helper updates the cached modifier snapshot * and reports whether anything actually changed so callers can avoid * unnecessary preview refreshes. * * @param e - Keyboard-like event carrying modifier-key flags * @returns `true` if any modifier flag changed; otherwise `false` */ private updateModifierStateFromEvent; /** * Handles the sticky Ctrl toggle used by certain jig interactions. * * Instead of tracking Ctrl as a purely held modifier, some commands treat a * Ctrl key press as a persistent toggle. This helper flips that toggle on the * first non-repeating keydown event for the Control key. * * @param e - Keyboard event to inspect * @returns `true` if the toggle state changed and previews should refresh */ private handleCtrlToggleKey; /** * Extracts cross-prompt defaults from a prompt options object. * * Not every prompt type exposes the same optional properties, but the * floating-input pipeline needs a normalized shape for values such as base * point, dashed-baseline behavior, jig, and base angle. This helper performs * those property-existence checks in one place. * * @typeParam T - Value type produced by the prompt * @param options - Prompt options to normalize * @returns A normalized object containing only the floating-input defaults it understands */ private resolvePromptDefaults; /** * Runs a floating-input prompt and resolves it to a parsed value. * * This is the core interaction primitive used by most non-selection prompts. * It wires together command-line keyword handling, floating input creation, * validation, preview refreshes, jig updates, cancellation handling, and * cleanup. The method guarantees that temporary UI and event listeners are * torn down no matter how the prompt completes. * * @typeParam T - Value type produced by the prompt * @param options - Configuration describing how the floating prompt should parse, * validate, preview, and commit its value * @returns A promise that resolves with the committed value or rejects on cancel/keyword */ private makeFloatingInputPromise; } //# sourceMappingURL=AcEdInputManager.d.ts.map