import MolangParser from "molangjs"; import tinycolor from "tinycolor2"; import { RaycastResult } from "../preview/preview"; import { MenuItem } from "./menu"; export declare const BarItems: any; type SubKeybind = { name: string; keybind?: Keybind; default_keybind?: Keybind; trigger: (event: Event) => void; }; export interface KeybindItemOptions { id?: string; name?: string; description?: string; category?: string; keybind?: Keybind; variations?: { [key: string]: { name: string; description?: string; }; }; } export interface BarItemOptions extends KeybindItemOptions { name?: string; description?: string; icon?: IconString | (() => IconString); color?: string; condition?: ConditionResolvable; category?: string; keybind?: Keybind; /** * If set to true, the item can only be used in private context and does not appear in keybindings, action control, or toolbar customization */ private?: true; /** * The plugin that this was added by */ plugin?: string; work_in_dialog?: boolean; variations?: { [key: string]: { name: string; description?: string; }; }; } /** * BarItem, the base abstract class for anything that can be added to a toolbar */ export declare abstract class BarItem extends EventSystem { static constructing: BarItem | undefined; id: string; name: string; description: string; icon?: IconString | ((context?: any) => IconString); category?: string; color?: string; condition: ConditionResolvable; type: string; node: HTMLElement; nodes: HTMLElement[]; uniqueNode?: boolean; toolbars: Toolbar[]; keybind: Keybind; default_keybind?: Keybind; /** * The plugin that this was added by */ plugin?: string; /** * @private How often the action was used */ uses?: number; work_in_dialog?: boolean; variations?: BarItemOptions['variations']; /** * Anything that can go into a toolbar, including actions, tools, toggles, widgets etc. */ constructor(id: string, data: BarItemOptions); conditionMet(): boolean; /** * Adds a label to the HTML element of the bar item * @param in_bar Set to true to generate an in-bar label, as opposed to a regular on-hover label * @param action Provide the action to generate the label. This defaults to self and is only needed in special cases */ addLabel(in_bar?: boolean, action?: any): void; /** * Gets a copy of the elements HTML node that is not yet in use. */ getNode(ignore_disconnected?: boolean): HTMLElement; /** * Appends the bar item to a HTML element */ toElement(destination: HTMLElement | string): this; pushToolbar(bar: Toolbar, index?: number): void; sub_keybinds?: Record; addSubKeybind(id: string, name: string, default_keybind: Keybind, trigger: any): void; delete(): void; } export declare class KeybindItem { id: string; type: string; name: string; description: string; category?: string; keybind: Keybind; default_keybind?: Keybind; condition?: ConditionResolvable; variations?: { [key: string]: { name: string; description?: string; }; }; constructor(id: string, data: KeybindItemOptions); delete(): void; } export interface ActionOptions extends BarItemOptions { /** * Function to run when user uses the action successfully */ click?: (event?: Event) => void; /** * Icon color. Can be a CSS color string, or an axis letter to use an axis color. */ color?: string; children?: MenuItem[] | ((context: any) => MenuItem[]); searchable?: boolean; /** * Show the full label in toolbars */ label?: boolean; /** * Provide a menu that belongs to the action, and gets displayed as a small arrow next to it in toolbars. */ side_menu?: Menu | ToolConfig | Dialog; /** * Provide a window with additional configutation related to the action */ tool_config?: ToolConfig; } export interface ActionSpecificOptions extends ActionOptions { click: (event?: Event) => void; } /** * Actions can be triggered to run something, they can be added to menus, toolbars, assigned a keybinding, or run via Action Control */ export declare class Action extends BarItem { menu_node: HTMLElement; icon_node: HTMLElement; /** * Provide a menu that belongs to the action, and gets displayed as a small arrow next to it in toolbars. */ side_menu?: ActionOptions['side_menu']; side_menu_anchor?: HTMLElement; menus: { menu: Menu; path: string; }[]; /** * Provide a window with additional configutation related to the action */ tool_config?: ToolConfig; onClick: any; children?: ActionOptions['children']; searchable?: boolean; click: ActionOptions['click']; constructor(id: string, data: ActionSpecificOptions); setupSideMenuButton(open_node: HTMLElement, tool_node: HTMLElement): void; /** * Trigger to run or select the action. This is the equivalent of clicking or using a keybind to trigger it. Also checks if the condition is met. */ trigger(event?: Event): boolean; updateKeybindingLabel(): this; getNode(ignore_disconnected: any): HTMLElement; /** Change the icon of the action */ setIcon(icon: IconString): void; /** * Change the name of the action */ setName(name: string): void; delete(): void; } type RGBAColor = { r: number; g: number; b: number; a: number; }; type ViewMode = 'textured' | 'solid' | 'wireframe' | 'uv' | 'normal'; type PaintContext = { /** * Brush color, set by the Blockbench color panel */ color: string; /** * Opacity, as set by the Opacity slider */ opacity: number; /** * 2D Canvas context of the texture that is being edited */ ctx: CanvasRenderingContext2D; /**X Coordinate of the position of the brush stroke */ x: number; /**Y Coordinate of the position of the brush stroke */ y: number; /** * Brush size, as set by the Brush Size slider */ size: number; /** * Brush softness, as set by the Brush Softness slider */ softness: number; /** * Blockbench texture that is being edited */ texture: Texture; /** * Javascript pointer event that the brush stroke originated from */ event: PointerEvent; }; export interface BrushOptions { /** * Enable the input for blend modes when this tool is selected */ blend_modes: boolean; /** * Enable the input for shapes when this tool is selected */ shapes: boolean; /** * Enable the input for brush size when this tool is selected */ size: boolean; /** * Enable the input for softness when this tool is selected */ softness: boolean; /** * Enable the input for opacity when this tool is selected */ opacity: boolean; /** * Enable the toggle for screen space when this tool is selected */ screen_space: boolean; /** * When the brush size is an even number, offset the snapping by half a pixel so that even size brush strokes can be correctly centered */ offset_even_radius: boolean; /** * Set whether the brush coordinates get floored to snap to the nearest pixel. */ floor_coordinates: boolean | (() => boolean); /** * Function that runs per pixel when the brush is used. Mutually exclusive with draw(). * @param pixel_x Local X coordinate relative to the brush center * @param pixel_y Local Y coordinate relative to the brush center * @param pixel_color Current color of the pixel on the texture * @param local_opacity Local opacity of the current pixel on the brush, between 0 and 1. Opacity falls of to the sides of the brush if the brush is set to smooth. Opacity from the Opacity slider is not factored in yet. * @param PaintContext Additional context to the paint stroke */ changePixel(pixel_x: number, pixel_y: number, pixel_color: RGBAColor, local_opacity: number, PaintContext: PaintContext): RGBAColor; /** * Function that runs when a new brush stroke starts. Return false to cancel the brush stroke * @param context */ onStrokeStart(context: { texture: Texture; x: number; y: number; uv?: any; event: PointerEvent; raycast_data: RaycastResult; }): boolean; /** * Function that runs when a new brush stroke starts. Return false to cancel the brush stroke * @param context */ onStrokeMove(context: { texture: Texture; x: number; y: number; uv?: any; event: PointerEvent; raycast_data: RaycastResult; }): boolean; /** * Function that runs when a new brush stroke starts. * @param context */ onStrokeEnd(context: { texture: Texture; x: number; y: number; uv?: any; raycast_data: RaycastResult; }): void; /** * Alternative way to create a custom brush, mutually exclusive with the changePixel() function. Draw runs once every time the brush starts or moves, and also along the bath on lines. * @param context */ draw(context: { ctx: CanvasRenderingContext2D; x: number; y: number; size: number; softness: number; texture: Texture; event: PointerEvent; }): void; } interface ToolSpecificOptions { selectFace?: boolean; selectElements?: boolean; click_locked_elements?: boolean; transformerMode?: 'translate' | 'scale' | 'rotate' | 'stretch' | 'hidden' | ''; cursor?: string; animation_channel?: string; toolbar?: string; transform_toolbar?: string; alt_tool?: string; modes?: string[]; allowed_view_modes?: ViewMode; paintTool?: boolean; brush?: BrushOptions; raycast_options?: { edges?: boolean; vertices?: boolean; }; onCanvasClick?(raycast_data: RaycastResult): void; onSelect?(): void; onUnselect?(): void; onCanvasMouseMove?(raycast_data: RaycastResult | false): any; onCanvasRightClick?(raycast_data: RaycastResult): any; onTextureEditorClick?(raycast_data: RaycastResult): any; } export type ToolOptions = ActionOptions & ToolSpecificOptions; export interface Tool extends ToolSpecificOptions { } /** * A tool, such as move tool, vertex snap tool, or paint brush */ export declare class Tool extends Action implements ToolSpecificOptions { tool_settings: Record; constructor(id: string, data: ToolOptions); select(): this; trigger(event: Event): boolean; switchModeAndSelect(): boolean; delete(): void; static all: Tool[]; static selected: Tool | null; } export interface ToggleOptions extends Omit { /** * Default value of the toggle */ default?: boolean; /** * If true, remember the value between restarts */ save_on_restart?: boolean; /** * ID of a setting that the toggle is linked to */ linked_setting?: string; /** * Method that gets called when the user changes the value of the toggle */ onChange?(value: boolean): void; icon: IconString | (() => IconString); } /** * A toggle is a type of action that can be on or off. The state is not persistent between restarts by default. */ export declare class Toggle extends Action { /** * ID of a setting that the toggle is linked to */ linked_setting?: string; value: boolean; onChange?: (value: boolean) => void; menu_icon_node: HTMLElement; constructor(id: string, data: ToggleOptions); set(value: boolean): this; setIcon(icon: IconString): this; /** * Updates the state of the toggle in the UI */ updateEnabledState(): this; } interface WidgetOptions extends BarItemOptions { id?: string; } export declare abstract class Widget extends BarItem { constructor(id: string, data: WidgetOptions); } export type NumSliderOptions = WidgetOptions & { private?: boolean; settings?: { default?: number; min?: number; max?: number; interval?: number | (() => number); step?: number; show_bar?: boolean; limit?: boolean; }; sensitivity?: number; invert_scroll_direction?: boolean; /** * Define a tool setting key under which the value of the slider is saved on the selected tool */ tool_setting?: string; uv?: boolean; sub_keybinds?: { increase: Keybind; decrease: Keybind; }; getInterval?(event: Event): number; change?(value: (n: number) => number): void; get?(): number; onChange?: (value: number, event?: Event) => void; onBefore?(): void; onAfter?: (difference?: number) => void; }; export declare class NumSlider extends Widget { value: number | string; width: number; sensitivity: number; invert_scroll_direction: boolean; pre?: number; private last_value; private sliding; private sliding_start_pos; settings: NumSliderOptions['settings']; interval: number | ((event: Event) => number); onBefore?: () => void; onChange?: (value: number, event?: Event) => void; onAfter?: (difference?: number) => void; uv?: boolean; /** * @private */ jq_outer: JQuery; /** * @private */ jq_inner: JQuery; /** * Define a tool setting key under which the value of the slider is saved on the selected tool */ tool_setting?: string; /** * All sliders that form the vector input that this slider is a part of */ slider_vector?: NumSlider[]; constructor(id: string, data: NumSliderOptions); startInput(): void; setWidth(width: number): this; getInterval(e?: Event): number; slide(clientX: number, event: MouseEvent | PointerEvent): void; input(): void; stopInput(): void; arrow(difference: any, event: any): void; trigger(event: Event): boolean; setValue(value: number | string, trim?: boolean): this; change(modify: (old_value: number) => number, event?: Event): void; get(): any; update(): void; static MolangParser: MolangParser; } interface BarSliderOptions extends WidgetOptions { value?: number; min?: number; max?: number; step?: number; circular?: boolean; width?: number; onChange?: (event: Event) => void; onBefore?: (event: Event) => void; onAfter?: (event: Event) => void; sub_keybinds?: { increase: Keybind; decrease: Keybind; }; } export declare class BarSlider extends Widget { value: number; settings: { min: number; max: number; step: number; circular?: boolean; }; onChange?: (event: Event) => void; onBefore?: (event: Event) => void; onAfter?: (event: Event) => void; constructor(id: string, data: BarSliderOptions); change(value: number, event?: Event): void; set(value: number): void; get(): number; } type BarSelectPropertyFormat = string | boolean | { name: string | true; condition?: ConditionResolvable; icon?: IconString; }; interface BarSelectOptions extends WidgetOptions { value?: string; icon_mode?: boolean; options: Record; onChange?(self: BarSelect, event?: Event): void; width?: number; min_width?: number; sub_keybinds?: { [key: string]: Keybind; }; } export declare class BarSelect extends Widget { icon_mode: boolean; value: string; values: string[]; options: Record; onChange?(self: BarSelect, event?: Event): void; constructor(id: string, data: BarSelectOptions); getNode(ignore_disconnected?: boolean): HTMLElement; open(event: Event): this; trigger(event: MouseEvent | TouchEvent | KeyboardEvent | WheelEvent): boolean | undefined; change(value: string, event?: Event): this; getNameFor(key: string): string; set(key: string): this; get(): string; } interface BarTextOptions extends WidgetOptions { text: string; onUpdate: () => void; click?: () => void; } export declare class BarText extends Widget { text: string; onUpdate: () => void; click: () => void; constructor(id: string, data: BarTextOptions); set(text: string): this; update(): this; trigger(event: Event): boolean; } export interface ColorPickerOptions extends WidgetOptions { value?: string; palette?: boolean; onChange?: (color: tinycolor.Instance) => void; } export declare class ColorPicker extends Widget { value: tinycolor.Instance; jq: JQuery; onChange?: (color: tinycolor.Instance) => void; constructor(options: ColorPickerOptions); constructor(id: string, data: ColorPickerOptions); change(color: tinycolor.Instance): void; hide(): void; delete(): void; confirm(): void; set(color: tinycolor.ColorInput): this; get(): tinycolor.Instance; } declare const global: { BarItem: typeof import("./actions").BarItem; KeybindItem: typeof import("./actions").KeybindItem; Action: typeof import("./actions").Action; Tool: typeof import("./actions").Tool; Toggle: typeof import("./actions").Toggle; Widget: typeof import("./actions").Widget; NumSlider: typeof import("./actions").NumSlider; BarSlider: typeof import("./actions").BarSlider; BarSelect: typeof import("./actions").BarSelect; BarText: typeof import("./actions").BarText; ColorPicker: typeof import("./actions").ColorPicker; Keybinds: { actions: any[]; stored: {}; extra: {}; structure: {}; save(): void; }; BarItems: any; }; declare global { type BarItem = import('./actions').BarItem; const BarItem: typeof global.BarItem; type KeybindItem = import('./actions').KeybindItem; const KeybindItem: typeof global.KeybindItem; type Action = import('./actions').Action; const Action: typeof global.Action; type Tool = import('./actions').Tool; const Tool: typeof global.Tool; type Toggle = import('./actions').Toggle; const Toggle: typeof global.Toggle; type Widget = import('./actions').Widget; const Widget: typeof global.Widget; type NumSlider = import('./actions').NumSlider; const NumSlider: typeof global.NumSlider; type BarSlider = import('./actions').BarSlider; const BarSlider: typeof global.BarSlider; type BarSelect = import('./actions').BarSelect; const BarSelect: typeof global.BarSelect; type BarText = import('./actions').BarText; const BarText: typeof global.BarText; type ColorPicker = import('./actions').ColorPicker; const ColorPicker: typeof global.ColorPicker; const BarItems: BarItemRegistry; interface BarItemRegistry { [key: string]: BarItem; undo: Action; redo: Action; } } export {};