/** * Pointing at anything on a page, as Lovable's picker does: hover outlines * the element under the pointer, a click picks it, and the assistant is told * which. * * ANY element, not only what Val marks. The assistant changes code, and the * thing a person wants changed is as often a wrapper, a gap or a button as a * field -- so a field's path is extra information when there is one * (`valPath`), never the condition for picking. * * Picking is on while a MODIFIER is held, so the page stays a page: links * follow, menus open, and nothing has to be switched back off. `active` * turns it on without one, for a Select button or a touch screen. * * Plain DOM, nothing of React's or the Studio's, and in `shared` because * both halves need it: the canvas bridge (`@valbuild/next`, * `@valbuild/tanstack`) runs it inside the page, the only place the page's * elements can be reached; the Studio's stories run it on a page of their own. Only the * `PickedElement` crosses the frame (`valCanvasProtocol.ts`). */ export type PickedElement = { /** `h2`, `section`, `button`… */ tag: string; /** The words in it, shortened: what a person recognises it by. */ text: string; /** Its own classes, as written. */ classes: string[]; /** * Where it is, from the root down, short enough to read: * `section:nth-of-type(2) > h2`. An `id` ends the walk, since it is * already unique. */ selector: string; /** The Val field it shows, or is inside of; absent when it shows none. */ valPath?: string; }; export type PickModifier = "alt" | "meta" | "shift" | "ctrl"; export declare function describeElement(element: Element, root: Element): PickedElement; /** What a person is told to hold, on their own keyboard. */ export declare function modifierLabel(modifier: PickModifier, mac: boolean): string; export type ElementPickerOptions = { modifier: PickModifier; /** On without the modifier: a Select button, or a touch screen. */ active: () => boolean; /** * Only what shows a Val field can be picked: the field's element is taken * for anything inside it, and nothing outside one is. The Studio's * assistant outside code mode, where what can be changed is content. */ fieldsOnly?: () => boolean; /** The element under the pointer while picking; `null` when not picking. */ onHover: (element: Element | null) => void; onPick: (element: Element) => void; }; /** * Listens on `root` (capturing, so the page's own handlers never see a pick) * and returns what stops it. */ export declare function attachElementPicker(root: HTMLElement, options: ElementPickerOptions): () => void; /** * The outlines over the page while picking: the element under the pointer, * named, and the one picked. * * Boxes `position: fixed` on top of everything, with `pointer-events: none`, * appended to the page's body -- not outlines on the elements themselves. * The canvas's field outlines are a stylesheet so they cannot disturb the * page's layout (`ValCanvasBridge`); a fixed box is out of the flow, so it * cannot either, and it is the one way to put a NAME beside any element, which * a selector cannot reach. * * In a shadow root of one host element: the bridge re-measures the page on * every `style` change under `body`, and a box that follows the pointer * changes its style every frame. Inside a shadow root those changes are not * the page's, so the host's one insertion is all the bridge sees. */ export type PickerOverlay = { show: (kind: "hover" | "picked", element: Element | null) => void; setColor: (color: string) => void; destroy: () => void; }; export declare function createPickerOverlay(doc: Document, initialColor: string): PickerOverlay; /** `h2.mb-6.text-2xl`: what the hover box is named. */ export declare function elementLabel(element: Element): string; export type ElementPicking = { /** Take the picked outline down, when the Studio no longer holds the pick. */ clearPicked: () => void; setColor: (color: string) => void; stop: () => void; }; /** * Picking on a page, whole: the listeners, the outlines, and Esc to stop * picking without the modifier. What a canvas bridge mounts. */ export declare function startElementPicking(root: HTMLElement, options: { modifier: PickModifier; active: () => boolean; /** See `ElementPickerOptions.fieldsOnly`. */ fieldsOnly?: () => boolean; color: string; onPick: (picked: PickedElement) => void; /** Esc while `active`: the Studio turns Select off. */ onStop: () => void; }): ElementPicking;