lazy-widgets
Version:
Typescript retained mode GUI for the HTML canvas API
97 lines (96 loc) • 4.93 kB
TypeScript
import { BaseXMLUIParser } from './BaseXMLUIParser.js';
import type { Widget } from '../widgets/Widget.js';
import type { XMLUIParserContext } from './XMLUIParserContext.js';
import type { LayerInit } from '../core/LayerInit.js';
/**
* A layer parameter for a {@link WidgetXMLInputConfig}.
*
* @category XML
*/
export interface WidgetXMLInputConfigLayerParameter {
mode: 'layer';
name: string;
optional?: boolean;
list?: boolean;
validator?: <W extends Widget>(value: LayerInit<Widget>) => LayerInit<W>;
}
/**
* Deserializes an XML <layer> element, as a {@link LayerInit} value.
*
* @param parser - The parser that is calling this deserializer
* @param context - The current parser context, shared with all other initializations
* @param elem - The element to deserialize
* @returns Returns a new LayerInit instance, to be used as a parameter
*
* @category XML
*/
export declare function deserializeLayerElement(parser: BaseXMLUIParser, context: XMLUIParserContext, elem: Element): LayerInit<Widget>;
/**
* Deserializes an attribute with an options prefix. The value will be added as
* a field in an options object, or completely replace the options object.
*
* @param parser - The parser that is calling this deserializer
* @param context - The current parser context, shared with all other initializations
* @param instantiationContext - The current parser context, only available to this instantiation
* @param attribute - The attribute to deserialize - the attribute name decides the options object field, but `_` replaces the options object
*
* @category XML
*/
export declare function deserializeOptionsAttribute(parser: BaseXMLUIParser, context: XMLUIParserContext, instantiationContext: Record<string, unknown>, attribute: Attr): void;
/**
* Deserializes an attribute with an event on/once prefix. The attribute will
* decide which event listener to add to the instance post-initialization. The
* listeners will be added to the instantiation context for later use.
*
* @param once - Should `once` be set to true in {@link Widget#on}?
* @param parser - The parser that is calling this deserializer
* @param context - The current parser context, shared with all other initializations
* @param instantiationContext - The current parser context, only available to this instantiation
* @param attribute - The attribute to deserialize - the attribute name decides the event type to listen to
*
* @category XML
*/
export declare function deserializeEventAttribute(once: boolean, parser: BaseXMLUIParser, context: XMLUIParserContext, instantiationContext: Record<string, unknown>, attribute: Attr): void;
/**
* Adds an options object to the end of an argument list.
*
* @param _parser - The parser that is calling this deserializer (unused)
* @param _context - The current parser context, shared with all other initializations (unused)
* @param instantiationContext - The current parser context, only available to this instantiation
* @param args - The argument list that will be modified
*
* @category XML
*/
export declare function addOptionsObjectToArguments(_parser: BaseXMLUIParser, _context: XMLUIParserContext, instantiationContext: Record<string, unknown>, args: Array<unknown>): void;
/**
* Adds a list of event listeners to a widget instance. The event listeners will
* be retrieved from the instantiation context.
*
* @param _parser - The parser that is calling this deserializer (unused)
* @param _context - The current parser context, shared with all other initializations (unused)
* @param instantiationContext - The current parser context, only available to this instantiation
* @param instance - The widget instance for which the event listeners will be added to
*
* @category XML
*/
export declare function addEventListenersToWidget(_parser: BaseXMLUIParser, _context: XMLUIParserContext, instantiationContext: Record<string, unknown>, instance: Widget): void;
/**
* An XML UI parser.
*
* Unlike {@link BaseXMLUIParser}:
*
* - All default widgets are pre-registered
* - `<layer>` elements are treated as LayerInit parameters ("layer" parameter mode)
* - Attribute values starting with a backslash are always treated as strings, with the backslash removed
* - Attribute values starting with a dollar sign are always treated as variables
* - Attribute values starting with an at sign are always treated as JSON-encoded values
* - Attributes with the `lazy-widgets:options` namespace will be added to an options object and passed to a widget factory
* - Attributes with the `lazy-widgets:on` namespace will add event listeners to a widget
* - Similarly, attributes with the `lazy-widgets:once` namespace will add event listeners to a widget, but with `once` set to true
* - A lot of built-in validators are pre-registered
*
* @category XML
*/
export declare class XMLUIParser extends BaseXMLUIParser {
constructor();
}