export { Graphviz } from '@hpcc-js/wasm'; import EventEmitter from 'eventemitter3'; import RBush from 'rbush'; import { vec2, vec3, mat4, quat, mat3 } from 'gl-matrix'; export { isPlainObject } from '@antv/util'; declare enum UnitType { kUnknown = 0, kNumber = 1, kPercentage = 2, kEms = 3, kPixels = 4, kRems = 5, kDegrees = 6, kRadians = 7, kGradians = 8, kTurns = 9, kMilliseconds = 10, kSeconds = 11, kInteger = 12 } declare enum Nested { kYes = 0, kNo = 1 } declare enum ParenLess { kYes = 0, kNo = 1 } declare enum CSSStyleValueType { kUnknownType = 0, kUnparsedType = 1, kKeywordType = 2, kUnitType = 3, kSumType = 4, kProductType = 5, kNegateType = 6, kInvertType = 7, kMinType = 8, kMaxType = 9, kClampType = 10, kTransformType = 11, kPositionType = 12, kURLImageType = 13, kColorType = 14, kUnsupportedColorType = 15 } /** * CSSStyleValue is the base class for all CSS values accessible from Typed OM. * Values that are not yet supported as specific types are also returned as base CSSStyleValues. * * Spec @see https://drafts.css-houdini.org/css-typed-om/#stylevalue-objects * Docs @see https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleValue */ declare abstract class CSSStyleValue { static isAngle(unit: UnitType): boolean; static isLength(type: UnitType): boolean; static isRelativeUnit(type: UnitType): boolean; static isTime(unit: UnitType): boolean; protected abstract getType(): CSSStyleValueType; abstract buildCSSText(n: Nested, p: ParenLess, result: string): string; abstract clone(): CSSStyleValue; toString(): string; isNumericValue(): boolean; } /** * CSSNumericValue is the base class for numeric and length typed CSS Values. * @see https://drafts.css-houdini.org/css-typed-om/#numeric-objects * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_numeric_value.idl */ /** * Represents numeric values that can be expressed as a single number plus a * unit (or a naked number or percentage). * @see https://drafts.css-houdini.org/css-typed-om/#cssunitvalue */ declare class CSSUnitValue extends CSSStyleValue { unit: UnitType; value: number; constructor(value: number, unitOrName?: UnitType | string); clone(): CSSUnitValue; equals(other: CSSUnitValue): boolean; getType(): CSSStyleValueType; convertTo(target_unit: UnitType): CSSUnitValue; buildCSSText(n: Nested, p: ParenLess, result: string): string; } /** * canvas.customElements * * @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry */ declare class CustomElementRegistry { private registry; constructor(); define(name: string, constructor: new (...args: any[]) => T): void; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/get */ get(name: string): new (...args: any[]) => T; } interface PointLike { x: number; y: number; } declare class Point { x: number; y: number; constructor(x?: number, y?: number); clone(): Point; copyFrom(p: Point): void; } /** * An DOM-compatible synthetic event implementation that is "forwarded" on behalf of an original * FederatedEvent or native {@link https://dom.spec.whatwg.org/#event Event}. */ declare class FederatedEvent { /** * The type of event, supports the following: * * pointerdown * * touchstart * * mousedown * * rightdown * * ... */ type: string; /** * @deprecated */ get name(): string; /** * The propagation phase. * @see https://developer.mozilla.org/en-US/docs/Web/API/Event/eventPhase */ eventPhase: number; /** * can be used to implement event delegation * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/target */ target: IEventTarget | null; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/bubbles */ bubbles: boolean; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/cancelBubble */ cancelBubble: boolean; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable */ readonly cancelable = false; /** the event target when listeners binded */ currentTarget: IEventTarget | null; /** Flags whether the default response of the user agent was prevent through this event. */ defaultPrevented: boolean; /** * timestamp when the event created * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/timeStamp */ timeStamp: number; /** * the original event. */ nativeEvent: N; /** The original event that caused this event, if any. */ originalEvent: FederatedEvent; /** Flags whether propagation was stopped. */ propagationStopped: boolean; /** Flags whether propagation was immediately stopped. */ propagationImmediatelyStopped: boolean; manager: EventService | null; /** Event-specific detail */ detail: T; /** * The coordinates of the evnet relative to the nearest DOM layer. * This is a non-standard property. */ layer: Point; get layerX(): number; get layerY(): number; /** * The coordinates of the event relative to the DOM document. * This is a non-standard property. * relative to the DOM document. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/pageX */ page: Point; get pageX(): number; get pageY(): number; /** * relative to Canvas, origin is left-top */ canvas: Point; get x(): number; get y(): number; get canvasX(): number; get canvasY(): number; /** * relative to Viewport, account for Camera */ viewport: Point; get viewportX(): number; get viewportY(): number; /** * The event boundary which manages this event. Propagation can only occur * within the boundary's jurisdiction. */ constructor(manager: EventService | null); path: IEventTarget[]; /** * The propagation path for this event * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/composedPath * * So composedPath()[0] represents the original target. * @see https://polymer-library.polymer-project.org/3.0/docs/devguide/events#retargeting */ composedPath(): IEventTarget[]; /** * @deprecated */ get propagationPath(): IEventTarget[]; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/preventDefault */ preventDefault(): void; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/stopImmediatePropagation */ stopImmediatePropagation(): void; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Event/stopPropagation */ stopPropagation(): void; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/view */ view: any; /** * added for compatibility with DOM Event, * deprecated props and methods */ initEvent(): void; initUIEvent(): void; which: number; returnValue: boolean; srcElement: IEventTarget; readonly composed = false; isTrusted: boolean; clone(): void; NONE: number; CAPTURING_PHASE: number; AT_TARGET: number; BUBBLING_PHASE: number; } interface RendererPlugin { name: string; context: CanvasContext; init: (runtime: GlobalRuntime) => void; destroy: (runtime: GlobalRuntime) => void; } interface IRenderer { getConfig: () => RendererConfig; /** * register plugin at runtime */ registerPlugin: (plugin: RendererPlugin) => void; /** * unregister plugin at runtime */ unregisterPlugin: (plugin: RendererPlugin) => void; /** * get plugin by name */ getPlugin: (name: string) => RendererPlugin; /** * return all registered plugins */ getPlugins: () => RendererPlugin[]; } interface RectStyleProps extends BaseStyleProps { x?: number | string; y?: number | string; width: number | string; height: number | string; /** * top-left, top-right, bottom-right, bottom-left */ radius?: number | string | number[]; } interface ParsedRectStyleProps extends ParsedBaseStyleProps { x?: number; y?: number; width: number; height: number; radius?: [number, number, number, number]; } declare class Rect extends DisplayObject { constructor({ style, ...rest }?: DisplayObjectConfig); } /** * @see https://drafts.css-houdini.org/css-typed-om-1/#dom-csscolorvalue-colorspace */ declare type ColorSpace = 'rgb' | 'hsl' | 'hwb' | 'lch' | 'lab'; declare type CSSColorRGBComp = CSSNumberish | 'none'; declare type CSSColorPercent = CSSNumberish | 'none'; /** * CSSColorValue is the base class used for the various CSS color interfaces. * * @see https://drafts.css-houdini.org/css-typed-om-1/#colorvalue-objects */ declare abstract class CSSColorValue extends CSSStyleValue { colorSpace: ColorSpace; constructor(colorSpace: ColorSpace); getType(): CSSStyleValueType; /** * @see https://drafts.css-houdini.org/css-typed-om-1/#dom-csscolorvalue-to */ to(colorSpace: ColorSpace): CSSColorValue; } /** * CSSKeywordValue represents CSS Values that are specified as keywords * eg. 'initial' * @see https://developer.mozilla.org/en-US/docs/Web/API/CSSKeywordValue * @see https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/blink/renderer/core/css/cssom/css_keyword_value.idl */ declare class CSSKeywordValue extends CSSStyleValue { value: string; constructor(value: string); clone(): CSSKeywordValue; getType(): CSSStyleValueType; buildCSSText(n: Nested, p: ParenLess, result: string): string; } interface LinearColorStop { offset: CSSUnitValue; color: string; } interface LinearGradient { angle: CSSUnitValue; steps: LinearColorStop[]; } interface RadialGradient { cx: CSSUnitValue; cy: CSSUnitValue; size?: CSSUnitValue | CSSKeywordValue; steps: LinearColorStop[]; } declare enum GradientType { Constant = 0, LinearGradient = 1, RadialGradient = 2 } declare class CSSGradientValue extends CSSStyleValue { type: GradientType; value: LinearGradient | RadialGradient; constructor(type: GradientType, value: LinearGradient | RadialGradient); clone(): CSSGradientValue; buildCSSText(n: Nested, p: ParenLess, result: string): string; getType(): CSSStyleValueType; } /** * The CSSRGB class represents the CSS rgb()/rgba() functions. * * @see https://drafts.css-houdini.org/css-typed-om-1/#cssrgb */ declare class CSSRGB extends CSSColorValue { r: CSSColorRGBComp; g: CSSColorRGBComp; b: CSSColorRGBComp; alpha: CSSColorPercent; /** * 'transparent' & 'none' has the same rgba data */ isNone: boolean; constructor(r: CSSColorRGBComp, g: CSSColorRGBComp, b: CSSColorRGBComp, alpha?: CSSColorPercent, /** * 'transparent' & 'none' has the same rgba data */ isNone?: boolean); clone(): CSSRGB; buildCSSText(n: Nested, p: ParenLess, result: string): string; } /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern */ interface Pattern { image: string | CanvasImageSource | Rect; repetition: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat'; transform: string; } interface ParsedFilterStyleProperty { name: string; params: CSSUnitValue[]; } declare type MCommand = 'M'; declare type mCommand = 'm'; declare type LCommand = 'L'; declare type lCommand = 'l'; declare type VCommand = 'V'; declare type vCommand = 'v'; declare type HCommand = 'H'; declare type hCommand = 'h'; declare type ZCommand = 'Z'; declare type zCommand = 'z'; declare type CCommand = 'C'; declare type cCommand = 'c'; declare type SCommand = 'S'; declare type sCommand = 's'; declare type QCommand = 'Q'; declare type qCommand = 'q'; declare type TCommand = 'T'; declare type tCommand = 't'; declare type ACommand = 'A'; declare type aCommand = 'a'; declare type MSegment = [MCommand, number, number]; declare type mSegment = [mCommand, number, number]; declare type MoveSegment = MSegment | mSegment; declare type LSegment = [LCommand, number, number]; declare type lSegment = [lCommand, number, number]; declare type LineSegment = LSegment | lSegment; declare type VSegment = [VCommand, number]; declare type vSegment = [vCommand, number]; declare type VertLineSegment = vSegment | VSegment; declare type HSegment = [HCommand, number]; declare type hSegment = [hCommand, number]; declare type HorLineSegment = HSegment | hSegment; declare type ZSegment = [ZCommand]; declare type zSegment = [zCommand]; declare type CloseSegment = ZSegment | zSegment; declare type CSegment = [CCommand, number, number, number, number, number, number]; declare type cSegment = [cCommand, number, number, number, number, number, number]; declare type CubicSegment = CSegment | cSegment; declare type SSegment = [SCommand, number, number, number, number]; declare type sSegment = [sCommand, number, number, number, number]; declare type ShortCubicSegment = SSegment | sSegment; declare type QSegment = [QCommand, number, number, number, number]; declare type qSegment = [qCommand, number, number, number, number]; declare type QuadSegment = QSegment | qSegment; declare type TSegment = [TCommand, number, number]; declare type tSegment = [tCommand, number, number]; declare type ShortQuadSegment = TSegment | tSegment; declare type ASegment = [ACommand, number, number, number, number, number, number, number]; declare type aSegment = [aCommand, number, number, number, number, number, number, number]; declare type ArcSegment = ASegment | aSegment; declare type PathSegment$1 = MoveSegment | LineSegment | VertLineSegment | HorLineSegment | CloseSegment | CubicSegment | ShortCubicSegment | QuadSegment | ShortQuadSegment | ArcSegment; declare type AbsoluteSegment = MSegment | LSegment | VSegment | HSegment | CSegment | SSegment | QSegment | TSegment | ASegment | ZSegment; declare type PathArray = [MSegment | mSegment, ...PathSegment$1[]]; declare type AbsoluteArray = [MSegment, ...AbsoluteSegment[]]; declare type CurveArray = [MSegment, ...CSegment[]]; interface ParsedTransform { t: string; d: CSSUnitValue[]; } declare enum Shape$1 { GROUP = "g", CIRCLE = "circle", ELLIPSE = "ellipse", IMAGE = "image", RECT = "rect", LINE = "line", POLYLINE = "polyline", POLYGON = "polygon", TEXT = "text", PATH = "path", HTML = "html", MESH = "mesh" } declare type ColorType = string | null; interface EventPosition { clientX: number; clientY: number; viewportX: number; viewportY: number; x: number; y: number; } declare type TextTransform = 'capitalize' | 'uppercase' | 'lowercase' | 'none'; declare type TextOverflow = 'clip' | 'ellipsis' | string; declare type TextDecorationLine = string | 'none'; declare type TextDecorationStyle = 'solid' | 'double' | 'dotted' | 'dashed' | 'wavy'; interface BaseStyleProps { class?: string; /** * @see https://developer.mozilla.org/en-US/docs/Web/CSS/transform */ transform?: string; /** * @see https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin */ transformOrigin?: string; /** * how do we define the 'position' of a shape? * eg. the default anchor of a Rect is top-left, we can change it to its' center [0.5, 0.5]. */ anchor?: vec2 | vec3 | string; /** * @see https://developer.mozilla.org/en-US/docs/Web/CSS/visibility */ visibility?: 'visible' | 'hidden' | CSSGlobalKeywords; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/pointer-events */ pointerEvents?: 'none' | 'auto' | 'stroke' | 'fill' | 'painted' | 'visible' | 'visiblestroke' | 'visiblefill' | 'visiblepainted' | 'all' | CSSGlobalKeywords; /** * z-index in CSS */ zIndex?: number; /** * the cursor style when the target is active */ cursor?: Cursor; /** * clip path * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/clip-path */ clipPath?: DisplayObject | null; /** * offset path * @see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Motion_Path */ offsetPath?: DisplayObject | null; offsetDistance?: number; stroke?: ColorType | Pattern; /** 描边透明度 */ strokeOpacity?: number | string; /** 填充颜色 */ fill?: ColorType | Pattern; /** 填充透明度 */ fillOpacity?: number | string; /** * The fill-rule attribute is a presentation attribute defining the algorithm to use to determine the inside part of a shape. * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/fill-rule */ fillRule?: 'nonzero' | 'evenodd'; /** 整体透明度 */ opacity?: number | string; /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-width */ strokeWidth?: string | number; /** * alias if strokeWidth * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineWidth */ lineWidth?: string | number; /** * increased line width when hitting test */ increasedLineWidthForHitTesting?: string | number; /** * 交互区域 */ hitArea?: DisplayObject | null; /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linecap */ strokeLinecap?: CanvasLineCap; /** * alias of strokeLinecap * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineCap */ lineCap?: CanvasLineCap; /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linejoin */ strokeLinejoin?: CanvasLineJoin; /** * alias of strokeLinejoin * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin */ lineJoin?: CanvasLineJoin; /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray */ strokeDasharray?: string | (string | number)[]; /** * alias of strokeDasharray * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getLineDash */ lineDash?: number | string | (string | number)[]; /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dashoffset */ strokeDashoffset?: number; /** * alias of strokeDashoffset * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset */ lineDashOffset?: number; shadowType?: 'inner' | 'outer' | 'both'; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/shadowBlur */ shadowBlur?: number; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/shadowColor */ shadowColor?: ColorType; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/shadowOffsetX */ shadowOffsetX?: number; /** * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/shadowOffsetY */ shadowOffsetY?: number; /** * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter */ filter?: string; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/text-transform */ textTransform?: TextTransform | ''; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/miterLimit */ miterLimit?: number | string; display?: string; /** * @see https://g-next.antv.vision/zh/docs/plugins/dragndrop#drag */ draggable?: boolean; /** * @see https://g-next.antv.vision/zh/docs/plugins/dragndrop#drop */ droppable?: boolean; } interface ParsedBaseStyleProps extends Omit { opacity?: number; fillOpacity?: number; strokeOpacity?: number; fill?: CSSRGB | CSSGradientValue[] | Pattern; stroke?: CSSRGB | CSSGradientValue[] | Pattern; lineDash?: [number, number]; anchor?: [number, number, number]; transform: ParsedTransform[]; transformOrigin?: [CSSUnitValue, CSSUnitValue, CSSUnitValue]; lineWidth?: number; increasedLineWidthForHitTesting?: number; /** * x according to definition, eg. Line's x1/x2, Polyline's points */ defX?: number; defY?: number; /** * offset relative to initial definition */ offsetX?: number; offsetY?: number; shadowColor?: CSSRGB; miterLimit?: number; filter?: ParsedFilterStyleProperty[]; } declare type Cursor = 'auto' | 'default' | 'none' | 'context-menu' | 'help' | 'pointer' | 'progress' | 'wait' | 'cell' | 'crosshair' | 'text' | 'vertical-text' | 'alias' | 'copy' | 'move' | 'no-drop' | 'not-allowed' | 'grab' | 'grabbing' | 'all-scroll' | 'col-resize' | 'row-resize' | 'n-resize' | 'e-resize' | 's-resize' | 'w-resize' | 'ne-resize' | 'nw-resize' | 'se-resize' | 'sw-resize' | 'ew-resize' | 'ns-resize' | 'nesw-resize' | 'nwse-resize' | 'zoom-in' | 'zoom-out'; interface RendererConfig { /** * enable dirty check for displayobject */ enableDirtyCheck: boolean; /** * enable culling */ enableCulling: boolean; /** * enable dirty rectangle rendering */ enableDirtyRectangleRendering: boolean; /** * enable debugging dirty rectangle, Canvas will trigger CanvasEvent.DIRTY_RECTANGLE */ enableDirtyRectangleRenderingDebug: boolean; /** * enable auto rendering */ enableAutoRendering: boolean; } /** * eg. NodeCanvas, OffscreenCanvas, HTMLCanvasElement */ interface CanvasLike extends IEventTarget { width: number; height: number; getContext: ((contextId: '2d', contextAttributes?: CanvasRenderingContext2DSettings) => CanvasRenderingContext2D | null) & ((contextId: 'webgl', contextAttributes?: WebGLContextAttributes) => WebGLRenderingContext | null) & ((contextId: 'webgl2', contextAttributes?: WebGLContextAttributes) => WebGL2RenderingContext | null); addEventListener: ((type: K, listener: (this: HTMLCanvasElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions) => void) & ((type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void); removeEventListener: ((type: K, listener: (this: HTMLCanvasElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions) => void) & ((type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void); } interface CanvasConfig { /** * Renderer */ renderer: IRenderer; /** * document.getElementById(container); */ container?: string | HTMLElement; /** * support OffscreenCanvas */ canvas?: CanvasLike; /** * used in JSDOM */ document?: Document; /** * used in text measurement & texture generation */ offscreenCanvas?: CanvasLike; /** * window.devicePixelRatio */ devicePixelRatio?: number; /** * rAF */ requestAnimationFrame?: (callback: FrameRequestCallback) => number; cancelAnimationFrame?: (id: number) => void; /** * replace `new window.Image()` */ createImage?: (src: string) => HTMLImageElement; /** * limits query */ supportsPointerEvents?: boolean; supportsTouchEvents?: boolean; isTouchEvent?: (event: InteractivePointerEvent) => event is TouchEvent; isMouseEvent?: (event: InteractivePointerEvent) => event is MouseEvent; /** * Listen to native click event instead of mocking with pointerup & down events. */ useNativeClickEvent?: boolean; /** * Should we account for CSS Transform applied on container? */ supportsCSSTransform?: boolean; /** * 画布宽度 */ width?: number; /** * 画布高度 */ height?: number; /** * 画布背景色 */ background?: ColorType; /** * 画布的 cursor 样式 */ cursor?: Cursor; [key: string]: any; } /** * The format to use when defining custom easing functions */ declare type TypeEasingFunction = (t: number, params?: (string | number)[], duration?: number) => number; declare type InteractivePointerEvent = PointerEvent | TouchEvent | MouseEvent | WheelEvent; declare type Tuple3 = [T, T, T]; declare type Tuple3Number = Tuple3; /** * Objects that can receive events and may have listeners for them. * eg. Element, Canvas, DisplayObject * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget */ declare class EventTarget implements IEventTarget { /** * event emitter */ emitter: EventEmitter; /** * @deprecated * @alias addEventListener */ on(type: string, listener: EventListenerOrEventListenerObject | ((...args: any[]) => void), options?: boolean | AddEventListenerOptions): this; /** * support `capture` & `once` in options * @see https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget/addEventListener */ addEventListener(type: string, listener: EventListenerOrEventListenerObject | ((...args: any[]) => void), options?: boolean | AddEventListenerOptions): this; /** * @deprecated * @alias removeEventListener */ off(type: string, listener: EventListenerOrEventListenerObject | ((...args: any[]) => void), options?: boolean | AddEventListenerOptions): this; removeAllEventListeners(): void; removeEventListener(type: string, listener?: EventListenerOrEventListenerObject | ((...args: any[]) => void), options?: boolean | AddEventListenerOptions): this; /** * @deprecated * @alias dispatchEvent */ emit(eventName: string, object: object): void; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent */ dispatchEvent(e: T, skipPropagate?: boolean): boolean; } /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Node */ declare abstract class Node$1 extends EventTarget implements INode$1 { /** * Both nodes are in different documents or different trees in the same document. */ static DOCUMENT_POSITION_DISCONNECTED: number; /** * otherNode precedes the node in either a pre-order depth-first traversal * of a tree containing both (e.g., as an ancestor or previous sibling or a descendant of a previous sibling or previous sibling of an ancestor) or (if they are disconnected) in an arbitrary but consistent ordering. */ static DOCUMENT_POSITION_PRECEDING: number; /** * otherNode follows the node in either a pre-order depth-first traversal of a tree containing both (e.g., as a descendant or following sibling or a descendant of a following sibling or following sibling of an ancestor) or (if they are disconnected) in an arbitrary but consistent ordering. */ static DOCUMENT_POSITION_FOLLOWING: number; /** * otherNode is an ancestor of the node. */ static DOCUMENT_POSITION_CONTAINS: number; /** * otherNode is a descendant of the node. */ static DOCUMENT_POSITION_CONTAINED_BY: number; /** * The result relies upon arbitrary and/or implementation-specific behavior and is not guaranteed to be portable. */ static DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: number; static isNode(target: IEventTarget | INode$1): target is INode$1; shadow: boolean; /** * points to canvas.document * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/ownerDocument */ ownerDocument: IDocument | null; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/isConnected * @example circle.isConnected; // false canvas.appendChild(circle); circle.isConnected; // true */ isConnected: boolean; /** * Returns node's node document's document base URL. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node */ readonly baseURI: string; /** * Returns the children. * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes */ childNodes: IChildNode[]; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/nodeType */ nodeType: number; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/nodeName */ nodeName: string; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/nodeValue */ nodeValue: string | null; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/textContent */ get textContent(): string; set textContent(content: string); /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/getRootNode */ getRootNode(opts?: { composed?: boolean; }): INode$1; hasChildNodes(): boolean; isDefaultNamespace(namespace: string | null): boolean; lookupNamespaceURI(prefix: string | null): string | null; lookupPrefix(namespace: string | null): string | null; normalize(): void; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/isEqualNode */ isEqualNode(otherNode: INode$1 | null): boolean; isSameNode(otherNode: INode$1 | null): boolean; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/ParentNode */ parentNode: (INode$1 & IParentNode) | null; /** * @deprecated * @alias parentNode */ get parent(): INode$1 | null; get parentElement(): IElement | null; get nextSibling(): IChildNode | null; get previousSibling(): IChildNode | null; get firstChild(): IChildNode | null; get lastChild(): IChildNode | null; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition * @see https://github.com/b-fuze/deno-dom/blob/master/src/dom/node.ts#L338 */ compareDocumentPosition(other: INode$1): number; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode */ abstract cloneNode(deep?: boolean): this; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild */ abstract appendChild(newChild: T, index?: number): T; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore */ abstract insertBefore(newChild: T, refChild: INode$1 | null): T; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild */ abstract removeChild(child: T): T; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/replaceChild */ abstract replaceChild(newChild: INode$1, oldChild: T): T; abstract destroy(): void; /** * @deprecated * @alias contains */ contain(other: T | null): boolean; contains(other: T | null): boolean; getAncestor(n: number): INode$1 | null; forEach(callback: (o: INode$1) => void | boolean, assigned?: boolean): void; } /** * the entry of DOM tree * Document -> Node -> EventTarget * @see https://developer.mozilla.org/en-US/docs/Web/API/Document */ declare class Document$1 extends Node$1 implements IDocument { constructor(); get children(): IElement[]; get childElementCount(): number; get firstElementChild(): IElement | null; get lastElementChild(): IElement | null; /** * only document has defaultView, points to canvas, * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/defaultView */ defaultView: ICanvas | null; /** * the root element of document, eg. * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement */ readonly documentElement: Group; /** * document.timeline in WAAPI */ readonly timeline: IAnimationTimeline; readonly ownerDocument: null; /** * @example const circle = document.createElement('circle', { style: { r: 10 } }); */ createElement, StyleProps extends BaseStyleProps>(tagName: string, options: DisplayObjectConfig): T; createElementNS, StyleProps extends BaseStyleProps>(namespaceURI: string, tagName: string, options: DisplayObjectConfig): T; cloneNode(deep?: boolean): this; destroy(): void; /** * Picking 2D graphics with RBush based on BBox, fast but inaccurate. */ elementsFromBBox(minX: number, minY: number, maxX: number, maxY: number): DisplayObject[]; elementFromPointSync(x: number, y: number): DisplayObject; /** * Do picking with API instead of triggering interactive events. * * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementFromPoint */ elementFromPoint(x: number, y: number): Promise; elementsFromPointSync(x: number, y: number): DisplayObject[]; /** * Do picking with API instead of triggering interactive events. * * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementsFromPoint */ elementsFromPoint(x: number, y: number): Promise; /** * eg. Uncaught DOMException: Failed to execute 'appendChild' on 'Node': Only one element on document allowed. */ appendChild(newChild: T, index?: number): T; insertBefore(newChild: T, refChild: INode$1 | null): T; removeChild(oldChild: T, destroy?: boolean): T; replaceChild(newChild: INode$1, oldChild: T, destroy?: boolean): T; append(...nodes: INode$1[]): void; prepend(...nodes: INode$1[]): void; /** * Execute query on documentElement. */ getElementById(id: string): E | null; getElementsByName(name: string): E[]; getElementsByTagName(tagName: string): E[]; getElementsByClassName(className: string): E[]; querySelector(selectors: string): E | null; querySelectorAll(selectors: string): E[]; find(filter: (node: E) => boolean): E | null; findAll(filter: (node: E) => boolean): E[]; } /** * @see https://doc.babylonjs.com/how_to/optimizing_your_scene#changing-mesh-culling-strategy */ declare enum Strategy { Standard = 0 } interface Cullable { strategy: Strategy; visibilityPlaneMask: number; visible: boolean; enable: boolean; } declare class Plane { distance: number; normal: vec3; /** * lookup table for p-vertex & n-vertex when doing frustum culling */ pnVertexFlag: number; constructor(distance?: number, normal?: vec3); updatePNVertexFlag(): void; distanceToPoint(point: vec3): number; normalize(): void; intersectsLine(start: vec3, end: vec3, point?: vec3): boolean; } /** * Axis-Aligned Bounding Box * 为了便于后续 Frustum Culling,通过查找表定义 p-vertex 和 n-vertex * @see https://github.com/antvis/GWebGPUEngine/issues/3 */ declare class AABB { static isEmpty(aabb: AABB): boolean; center: Tuple3Number; halfExtents: Tuple3Number; min: Tuple3Number; max: Tuple3Number; update(center: Tuple3Number, halfExtents: Tuple3Number): void; setMinMax(min: Tuple3Number, max: Tuple3Number): void; getMin(): Tuple3Number; getMax(): Tuple3Number; add(aabb: AABB): void; setFromTransformedAABB(aabb: AABB, m: mat4): void; intersects(aabb: AABB): boolean; intersection(aabb: AABB): AABB | null; /** * get n-vertex * @param plane plane of CullingVolume */ getNegativeFarPoint(plane: Plane): Tuple3Number; /** * get p-vertex * @param plane plane of CullingVolume */ getPositiveFarPoint(plane: Plane): Tuple3Number; } declare class Frustum { planes: Plane[]; constructor(planes?: Plane[]); /** * extract 6 planes from projectionMatrix * @see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf */ extractFromVPMatrix(projectionMatrix: mat4): void; } declare class Rectangle implements DOMRect { x: number; y: number; width: number; height: number; left: number; right: number; top: number; bottom: number; constructor(x: number, y: number, width: number, height: number); toJSON(): void; } interface Geometry { /** * excluding all children */ contentBounds: AABB | undefined; /** * including extra rendering effects, eg. shadowBlur filters(drop-shadow, blur) */ renderBounds: AABB | undefined; } interface RBushNodeAABB { displayObject: DisplayObject; minX: number; minY: number; maxX: number; maxY: number; } interface RBushNode { aabb?: RBushNodeAABB; } interface Renderable { /** * aabb 应该存在 Renderable 而非 Geometry 中,原因包括: * 1. 包围盒会受 transform 影响。例如每次 transform 之后应该重新计算包围盒(center 发生偏移)。 * 2. 多个 Mesh 可以共享一个 Geometry,但可以各自拥有不同的 aabb */ bounds: AABB | undefined; boundsDirty: boolean; /** * account for hierarchy, also including extra rendering effects */ renderBounds: AABB | undefined; renderBoundsDirty: boolean; /** * dirty render bounds in last render frame */ dirtyRenderBounds: AABB; /** * dirty rectangle flag */ dirty: boolean; /** * Rendering with other renderers, eg. simple Path/Polyline should be treated as instanced Line. */ proxyNodeName: string; } interface Sortable { /** * need to re-sort */ dirty: boolean; /** * sorted child entities */ sorted: INode$1[]; /** * index in parent's children */ lastSortedIndex: number; /** * render order in whole scenegraph */ renderOrder: number; } /** * do RTS transformation for 2D/3D */ interface Transform { dirtyFlag: boolean; localDirtyFlag: boolean; frozen: boolean; /** * local space RTS */ localPosition: vec3; localRotation: quat; localScale: vec3; localTransform: mat4; /** * @see https://www.w3.org/TR/css-transforms-1/#SkewDefined */ localSkew: vec2; /** * world space RTS */ position: vec3; rotation: quat; scaling: vec3; worldTransform: mat4; /** * the origin of scaling and rotation */ origin: vec3; } /** * Has following capabilities: * * Node insert/remove, eg. appendChild, removeChild, remove... * * Query eg. querySelector getElementById... * * Animation */ declare class Element extends Node$1 implements IElement { static isElement(target: IEventTarget | INode$1 | IElement): target is IElement; /** * Unique id. */ entity: number; renderable: Renderable; cullable: Cullable; transformable: Transform; sortable: Sortable; geometry: Geometry; rBushNode: RBushNode; /** * used with `getElementById()` * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/id */ id: string; /** * used in `getElementsByClassName` * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName */ get className(): string; set className(className: string); /** * used in `getElementsByName` * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByName */ name: string; /** * https://developer.mozilla.org/zh-CN/docs/Web/API/Element/namespaceURI */ namespaceURI: string; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/classList */ get classList(): string[]; scrollLeft: number; scrollTop: number; /** * We don't support border now * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/clientTop */ clientTop: number; clientLeft: number; get tagName(): string; get children(): IElement[]; get childElementCount(): number; get firstElementChild(): IElement | null; get lastElementChild(): IElement | null; get parentElement(): IElement | null; get nextSibling(): IElement | null; get previousSibling(): IElement | null; cloneNode(deep?: boolean): this; appendChild(child: T, index?: number): T; insertBefore(newChild: T, refChild: INode$1 | null): T; replaceChild(newChild: INode$1, oldChild: T): T; removeChild(child: T): T; /** * Remove all children which can be appended to its original parent later again. */ removeChildren(): void; /** * Recursively destroy all children which can not be appended to its original parent later again. */ destroyChildren(): void; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/matches */ matches(selector: string): boolean; getElementById(id: string): E | null; getElementsByName(name: string): E[]; getElementsByClassName(className: string): E[]; getElementsByTagName(tagName: string): E[]; querySelector(selectors: string): E | null; querySelectorAll(selectors: string): E[]; /** * should traverses the element and its parents (heading toward the document root) * until it finds a node that matches the specified CSS selector. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/closest * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#polyfill */ closest(selectors: string): E | null; /** * search in scene group, but should not include itself */ find(filter: (node: E) => boolean): E | null; findAll(filter: (node: E) => boolean): E[]; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/after */ after(...nodes: INode$1[]): void; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/before */ before(...nodes: INode$1[]): void; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/replaceWith */ replaceWith(...nodes: INode$1[]): void; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/append */ append(...nodes: INode$1[]): void; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/prepend */ prepend(...nodes: INode$1[]): void; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/replaceChildren */ replaceChildren(...nodes: INode$1[]): void; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/remove */ remove(): this; /** * is destroyed or not */ destroyed: boolean; destroy(): void; getGeometryBounds(): AABB; getRenderBounds(): AABB; /** * get bounds in world space, account for children */ getBounds(): AABB; /** * get bounds in local space, account for children */ getLocalBounds(): AABB; /** * account for context's bounds in client space, * but not accounting for children * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect */ getBoundingClientRect(): Rectangle; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getClientRects */ getClientRects(): Rectangle[]; /** * compatible with `style` * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style */ style: StyleProps & ICSSStyleDeclaration; computedStyle: any; /** * Renderers will use these used values. */ parsedStyle: ParsedStyleProps; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/computedStyleMap * eg. circle.computedStyleMap().get('fill'); */ computedStyleMap(): Map; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes */ readonly attributes: StyleProps; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttributeNames */ getAttributeNames(): string[]; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute */ getAttribute(name: keyof StyleProps): StyleProps[keyof StyleProps] | null | undefined; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute */ hasAttribute(qualifiedName: string): boolean; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttributes */ hasAttributes(): boolean; /** * should use removeAttribute() instead of setting the attribute value to null either directly or using setAttribute(). Many attributes will not behave as expected if you set them to null. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute */ removeAttribute(attributeName: keyof StyleProps): void; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute */ setAttribute(attributeName: Key, value: StyleProps[Key], force?: boolean): void; getAttributeNS(namespace: string, localName: string): string; getAttributeNode(qualifiedName: string): Attr; getAttributeNodeNS(namespace: string, localName: string): Attr; hasAttributeNS(namespace: string, localName: string): boolean; removeAttributeNS(namespace: string, localName: string): void; removeAttributeNode(attr: Attr): Attr; setAttributeNS(namespace: string, qualifiedName: string, value: string): void; setAttributeNode(attr: Attr): Attr; setAttributeNodeNS(attr: Attr): Attr; toggleAttribute(qualifiedName: string, force?: boolean): boolean; } declare class FederatedMouseEvent extends FederatedEvent implements MouseEvent { /** Whether the "alt" key was pressed when this mouse event occurred. */ altKey: boolean; /** The specific button that was pressed in this mouse event. */ button: number; /** The button depressed when this event occurred. */ buttons: number; /** Whether the "control" key was pressed when this mouse event occurred. */ ctrlKey: boolean; /** Whether the "meta" key was pressed when this mouse event occurred. */ metaKey: boolean; /** This is currently not implemented in the Federated Events API. */ relatedTarget: DisplayObject | null; /** Whether the "shift" key was pressed when this mouse event occurred. */ shiftKey: boolean; /** * The coordinates of the mouse event relative to the canvas. */ client: Point; get clientX(): number; get clientY(): number; /** * The movement in this pointer relative to the last `mousemove` event. */ movement: Point; get movementX(): number; get movementY(): number; /** * The offset of the pointer coordinates w.r.t. target DisplayObject in world space. This is * not supported at the moment. */ offset: Point; get offsetX(): number; get offsetY(): number; /** * The pointer coordinates in world space. */ global: Point; get globalX(): number; get globalY(): number; /** * The pointer coordinates in sceen space. */ screen: Point; get screenX(): number; get screenY(): number; getModifierState(key: string): boolean; initMouseEvent(): void; } declare class FederatedPointerEvent extends FederatedMouseEvent implements PointerEvent { /** * The unique identifier of the pointer. * * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerId */ pointerId: number; /** * The width of the pointer's contact along the x-axis, measured in CSS pixels. * radiusX of TouchEvents will be represented by this value. * * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/width */ width: number; /** * The height of the pointer's contact along the y-axis, measured in CSS pixels. * radiusY of TouchEvents will be represented by this value. * * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/height */ height: number; /** * Indicates whether or not the pointer device that created the event is the primary pointer. * * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/isPrimary */ isPrimary: boolean; /** * The type of pointer that triggered the event. * * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType */ pointerType: string; /** * Pressure applied by the pointing device during the event. *s * A Touch's force property will be represented by this value. * * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pressure */ pressure: number; /** * Barrel pressure on a stylus pointer. * * @see https://w3c.github.io/pointerevents/#pointerevent-interface */ tangentialPressure: number; /** * The angle, in degrees, between the pointer device and the screen. * * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltX */ tiltX: number; /** * The angle, in degrees, between the pointer device and the screen. * * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltY */ tiltY: number; /** * Twist of a stylus pointer. * * @see https://w3c.github.io/pointerevents/#pointerevent-interface */ twist: number; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/getCoalescedEvents */ getCoalescedEvents(): PointerEvent[]; /** * @see https://chromestatus.com/feature/5765569655603200 */ getPredictedEvents(): PointerEvent[]; /** * @see https://github.com/antvis/G/issues/1115 * We currently reuses event objects in the event system, * avoiding the creation of a large number of event objects. * Reused objects are only used to carry different data, * such as coordinate information, native event objects, * and therefore the lifecycle is limited to the event handler, * which can lead to unintended consequences if an attempt is made to cache the entire event object. * * Therefore, while keeping the above performance considerations in mind, it is possible to provide a clone method that creates a new object when the user really wants to cache it, e.g. */ clone(): FederatedPointerEvent; } declare class FederatedWheelEvent extends FederatedMouseEvent implements WheelEvent { /** * The units of `deltaX`, `deltaY`, and `deltaZ`. This is one of `DOM_DELTA_LINE`, * `DOM_DELTA_PAGE`, `DOM_DELTA_PIXEL`. */ deltaMode: number; /** Horizontal scroll amount */ deltaX: number; /** Vertical scroll amount */ deltaY: number; /** z-axis scroll amount. */ deltaZ: number; /** Units specified in lines. */ DOM_DELTA_LINE: number; /** Units specified in pages. */ DOM_DELTA_PAGE: number; /** Units specified in pixels. */ DOM_DELTA_PIXEL: number; clone(): FederatedWheelEvent; } /** * prototype chains: DisplayObject -> Element -> Node -> EventTarget * * mixins: Animatable, Transformable, Visible * @see https://github.com/tannerntannern/ts-mixer/blob/master/README.md#mixing-generic-classes * * Provide abilities in scene graph, such as: * * transform `translate/rotate/scale` * * add/remove child * * visibility and z-index * * Those abilities are implemented with those components: `Transform/Sortable/Visible`. * * Emit following events: * * init * * destroy * * attributeChanged */ declare class DisplayObject extends Element { /** * contains style props in constructor's params, eg. fill, stroke... */ config: DisplayObjectConfig; isCustomElement: boolean; isMutationObserved: boolean; /** * push to active animations after calling `animate()` */ private activeAnimations; /** * Use data-* attribute. * @see https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes * @example * group.dataset.prop1 = 1; * group.getAttribute('data-prop1'); // 1 */ dataset: any; constructor(config: DisplayObjectConfig); destroy(): void; cloneNode(deep?: boolean, customCloneFunc?: (name: string, attribute: any) => any): this; private initAttributes; setAttribute(name: Key, value: StyleProps[Key], force?: boolean): void; /** * called when attributes get changed or initialized */ internalSetAttribute(name: Key, value: StyleProps[Key], parseOptions?: Partial): void; /** * returns different values than getBoundingClientRect(), as the latter returns value relative to the viewport * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox * * FIXME: It is worth noting that getBBox responds to original untransformed values of a drawn object. * @see https://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html#getBBox */ getBBox(): DOMRect; setOrigin(position: vec3 | vec2 | number, y?: number, z?: number): this; getOrigin(): vec3; /** * set position in world space */ setPosition(position: vec3 | vec2 | number, y?: number, z?: number): this; /** * set position in local space */ setLocalPosition(position: vec3 | vec2 | number, y?: number, z?: number): this; /** * translate in world space */ translate(position: vec3 | vec2 | number, y?: number, z?: number): this; /** * translate in local space */ translateLocal(position: vec3 | vec2 | number, y?: number, z?: number): this; getPosition(): vec3; getLocalPosition(): vec3; /** * compatible with G 3.0 * * scaling in local space * scale(10) = scale(10, 10, 10) * * we can't set scale in world space */ scale(scaling: vec3 | vec2 | number, y?: number, z?: number): this; scaleLocal(scaling: vec3 | vec2 | number, y?: number, z?: number): this; /** * set scaling in local space */ setLocalScale(scaling: vec3 | vec2 | number, y?: number, z?: number): this; /** * get scaling in local space */ getLocalScale(): vec3; /** * get scaling in world space */ getScale(): vec3; /** * only return degrees of Z axis in world space */ getEulerAngles(): number; /** * only return degrees of Z axis in local space */ getLocalEulerAngles(): number; /** * set euler angles(degrees) in world space */ setEulerAngles(z: number): this; /** * set euler angles(degrees) in local space */ setLocalEulerAngles(z: number): this; rotateLocal(x: number, y?: number, z?: number): this; rotate(x: number, y?: number, z?: number): this; setRotation(rotation: quat | number, y?: number, z?: number, w?: number): this; setLocalRotation(rotation: quat | number, y?: number, z?: number, w?: number): this; setLocalSkew(skew: vec2 | number, y?: number): this; getRotation(): quat; getLocalRotation(): quat; getLocalSkew(): vec2; getLocalTransform(): mat4; getWorldTransform(): mat4; setLocalTransform(transform: mat4): this; resetLocalTransform(): void; /** * returns an array of all Animation objects affecting this element * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAnimations */ getAnimations(): IAnimation[]; /** * create an animation with WAAPI * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/animate */ animate(keyframes: Keyframe[] | PropertyIndexedKeyframes | null, options?: number | KeyframeAnimationOptions | undefined): IAnimation | null; /** * shortcut for Used value of `visibility` */ isVisible(): boolean; get interactive(): boolean; set interactive(b: boolean); isInteractive(): boolean; isCulled(): boolean; /** * bring to front in current group */ toFront(): this; /** * send to back in current group */ toBack(): this; /** * compatible with G 3.0 * @alias object.config * @deprecated */ getConfig(): DisplayObjectConfig; /** * @alias style * @example * circle.style.r = 10; * const r = circle.style; * @deprecated */ attr(): StyleProps; attr(name: Partial): DisplayObject; attr(name: Key): StyleProps[Key]; attr(name: Key, value: StyleProps[Key]): DisplayObject; /** * return 3x3 matrix in world space * @deprecated */ getMatrix(transformMat4?: mat4): mat3; /** * return 3x3 matrix in local space * @deprecated */ getLocalMatrix(): mat3; /** * set 3x3 matrix in world space * @deprecated */ setMatrix(mat: mat3): void; /** * set 3x3 matrix in local space * @deprecated */ setLocalMatrix(mat: mat3): void; /** * Use `visibility: visible` instead. * @deprecated */ show(): void; /** * Use `visibility: hidden` instead. * @deprecated */ hide(): void; /** * Use `childElementCount` instead. * @deprecated */ getCount(): number; /** * Use `parentElement` instead. * @deprecated */ getParent(): DisplayObject | null; /** * Use `children` instead. * @deprecated */ getChildren(): DisplayObject[]; /** * Use `firstElementChild` instead. * @deprecated */ getFirst(): DisplayObject | null; /** * Use `lastElementChild` instead. * @deprecated */ getLast(): DisplayObject | null; /** * Use `this.children[index]` instead. * @deprecated */ getChildByIndex(index: number): DisplayObject | null; /** * Use `appendChild` instead. * @deprecated */ add(child: T, index?: number): T; /** * Use `this.style.clipPath` instead. * @deprecated */ setClip(clipPath: DisplayObject | null): void; /** * Use `this.style.clipPath` instead. * @deprecated */ getClip: () => any; /** * @deprecated */ set>(name: Key, value: DisplayObjectConfig[Key]): void; /** * @deprecated */ get(name: keyof DisplayObjectConfig): any; /** * Use `setPosition` instead. * @deprecated */ moveTo(position: vec3 | vec2 | number, y?: number, z?: number): this; /** * Use `setPosition` instead. * @deprecated */ move(position: vec3 | vec2 | number, y?: number, z?: number): this; /** * Use `this.style.zIndex` instead. * @deprecated */ setZIndex(zIndex: number): this; } interface GeometryAABBUpdater { update: (parsedStyle: T, object: DisplayObject) => { width: number; height: number; depth?: number; offsetX?: number; offsetY?: number; offsetZ?: number; }; } interface LineStyleProps extends BaseStyleProps { x1: number; y1: number; x2: number; y2: number; z1?: number; z2?: number; isBillboard?: boolean; /** * marker will be positioned at x1/y1 */ markerStart?: DisplayObject; /** * marker will be positioned at x2/y2 */ markerEnd?: DisplayObject; /** * offset relative to original position */ markerStartOffset?: number; /** * offset relative to original position */ markerEndOffset?: number; } interface ParsedLineStyleProps extends ParsedBaseStyleProps { x1: number; y1: number; x2: number; y2: number; z1?: number; z2?: number; defX: number; defY: number; isBillboard?: boolean; markerStart?: DisplayObject; markerEnd?: DisplayObject; markerStartOffset?: number; markerEndOffset?: number; } /** * Create a line connecting two points. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/line * * Also support for using marker. */ declare class Line extends DisplayObject { private markerStartAngle; private markerEndAngle; constructor({ style, ...rest }?: DisplayObjectConfig); attributeChangedCallback(attrName: Key, oldValue: LineStyleProps[Key], newValue: LineStyleProps[Key], prevParsedValue: ParsedLineStyleProps[Key], newParsedValue: ParsedLineStyleProps[Key]): void; private transformMarker; getPoint(ratio: number, inWorldSpace?: boolean): Point; getPointAtLength(distance: number, inWorldSpace?: boolean): Point; getTotalLength(): number; } interface TextMetrics { font: string; width: number; height: number; lines: string[]; lineWidths: number[]; lineHeight: number; maxLineWidth: number; fontProperties: IFontMetrics; lineMetrics: Rectangle[]; } interface IFontMetrics { ascent: number; descent: number; fontSize: number; } declare type DataURLType = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/bmp'; /** * The created image data will have a resolution of 96dpi. * @see https://developer.mozilla.org/zh-CN/docs/Web/API/HTMLCanvasElement/toDataURL#%E5%8F%82%E6%95%B0 */ interface DataURLOptions { /** * The default type is image/png. */ type: DataURLType; /** * The image quality between 0 and 1 for image/jpeg and image/webp. */ encoderOptions: number; } interface ContextService { init: () => Promise; destroy: () => void; getContext: () => Context | null; getDomElement: () => CanvasLike | null; getDPR: () => number; getBoundingClientRect: () => DOMRect | undefined; resize: (width: number, height: number) => void; applyCursorStyle: (cursor: string) => void; toDataURL: (options: Partial) => Promise; } declare type Picker = (position: EventPosition) => IEventTarget | null; declare class EventService { private globalRuntime; private context; constructor(globalRuntime: GlobalRuntime, context: CanvasContext); private rootTarget; private emitter; cursor: Cursor | null; private mappingTable; private mappingState; private eventPool; private pickHandler; private tmpMatrix; private tmpVec3; init(): void; destroy(): void; client2Viewport(client: PointLike): PointLike; viewport2Client(canvas: PointLike): PointLike; viewport2Canvas({ x, y }: PointLike): PointLike; canvas2Viewport(canvasP: PointLike): PointLike; setPickHandler(pickHandler: Picker): void; addEventMapping(type: string, fn: (e: FederatedEvent) => void): void; mapEvent(e: FederatedEvent): void; onPointerDown: (from: FederatedPointerEvent) => void; onPointerUp: (from: FederatedPointerEvent) => void; onPointerMove: (from: FederatedPointerEvent) => void; onPointerOut: (from: FederatedPointerEvent) => void; onPointerOver: (from: FederatedPointerEvent) => void; onPointerUpOutside: (from: FederatedPointerEvent) => void; onWheel: (from: FederatedWheelEvent) => void; onClick: (from: FederatedPointerEvent) => void; onPointerCancel: (from: FederatedPointerEvent) => void; dispatchEvent(e: FederatedEvent, type?: string, skipPropagate?: boolean): void; propagate(e: FederatedEvent, type?: string): void; propagationPath(target: IEventTarget): IEventTarget[]; hitTest(position: EventPosition): IEventTarget | null; /** * whether the native event trigger came from Canvas, * should account for HTML shape */ private isNativeEventFromCanvas; /** * Find HTML from composed path in native UI event. */ private getExistedHTML; private pickTarget; private createPointerEvent; private createWheelEvent; private trackingData; cloneWheelEvent(from: FederatedWheelEvent): FederatedWheelEvent; clonePointerEvent(from: FederatedPointerEvent, type?: string): FederatedPointerEvent; private copyPointerData; private copyMouseData; private copyWheelData; private copyData; private allocateEvent; private freeEvent; private notifyTarget; private notifyListeners; /** * some detached nodes may exist in propagation path, need to skip them */ private findMountedTarget; private getCursor; } /** * why we need re-render */ declare enum RenderReason { CAMERA_CHANGED = 0, DISPLAY_OBJECT_CHANGED = 1, NONE = 2 } interface RenderingContext { /** * root of scenegraph */ root: Group; /** * force rendering at next frame */ force: boolean; /** * reason of re-render, reset after every renderred frame */ renderReasons: Set; renderListCurrentFrame: DisplayObject[]; unculledEntities: number[]; dirty: boolean; } declare type Measure = T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ? T : never; declare type Append = { 0: [U]; 1: [T[0], U]; 2: [T[0], T[1], U]; 3: [T[0], T[1], T[2], U]; 4: [T[0], T[1], T[2], T[3], U]; 5: [T[0], T[1], T[2], T[3], T[4], U]; 6: [T[0], T[1], T[2], T[3], T[4], T[5], U]; 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], U]; 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], U]; }[Measure]; declare type AsArray = T extends any[] ? T : [T]; declare class UnsetAdditionalOptions { _UnsetAdditionalOptions: true; } declare type IfSet = X extends UnsetAdditionalOptions ? Record : X; declare type Callback = (error: E | null, result?: T) => void; declare type InnerCallback = (error?: E | null | false, result?: T) => void; declare type FullTap = Tap & { type: 'sync' | 'async' | 'promise'; fn: () => any; }; declare type Tap = TapOptions & { name: string; }; declare type TapOptions = { before?: string; stage?: number; }; declare class Hook { name: string | undefined; taps: FullTap[]; callAsync(...args: Append, Callback>): void; promise: (...args: AsArray) => Promise; call(...args: AsArray): R; private _promise; constructor(args?: never[], name?: undefined); compile(options: any): void; _createCall(type: any): void; _tap(type: string, options: string | (Tap & IfSet), fn: (...args: AsArray) => R): void; tap(options: string | (Tap & IfSet), fn: (...args: AsArray) => R): void; tapAsync(options: string | (Tap & IfSet), fn: (...args: Append, InnerCallback>) => void): void; tapPromise(options: string | (Tap & IfSet), fn: (...args: AsArray) => Promise): void; _runRegisterInterceptors(options: any): any; withOptions(options: TapOptions & IfSet): Omit; isUsed(): boolean; _resetCompilation(): void; _insert(item: any): void; } declare class AsyncParallelHook extends Hook { constructor(args?: never[], name?: undefined); } declare class AsyncSeriesWaterfallHook extends Hook[0], AdditionalOptions> { constructor(args?: never[], name?: undefined); } declare class SyncHook extends Hook { constructor(args?: never[], name?: undefined); } declare class SyncWaterfallHook extends SyncHook[0], AdditionalOptions> { constructor(args?: never[], name?: undefined); } interface PathStyleProps extends BaseStyleProps { path?: string | PathArray; d?: string | PathArray; /** * marker will be positioned at the first point */ markerStart?: DisplayObject; /** * marker will be positioned at the last point */ markerEnd?: DisplayObject; markerMid?: DisplayObject; /** * offset relative to original position */ markerStartOffset?: number; /** * offset relative to original position */ markerEndOffset?: number; } interface PathSegmentBBox { x: number; y: number; width: number; height: number; } interface PathSegment { command: 'M' | 'L' | 'V' | 'H' | 'C' | 'S' | 'Q' | 'T' | 'A' | 'Z'; currentPoint: [number, number]; prePoint: [number, number]; nextPoint: [number, number]; startTangent: [number, number]; endTangent: [number, number]; params: AbsoluteSegment; arcParams: PathArcParams; /** * Used for hit test. */ box: PathSegmentBBox; /** * Convert A to C. */ cubicParams: [number, number, number, number, number, number]; } interface PathArcParams { cx: number; cy: number; rx: number; ry: number; startAngle: number; endAngle: number; xRotation: number; arcFlag: number; sweepFlag: number; } interface ParsedPathStyleProps extends ParsedBaseStyleProps { path: { absolutePath: AbsoluteArray; hasArc: boolean; segments: PathSegment[]; polygons: [number, number][][]; polylines: [number, number][][]; curve: CurveArray; totalLength: number; rect: Rectangle; }; d?: { absolutePath: AbsoluteArray; hasArc: boolean; segments: PathSegment[]; polygons: [number, number][][]; polylines: [number, number][][]; curve: CurveArray; totalLength: number; rect: Rectangle; }; markerStart?: DisplayObject; markerMid?: DisplayObject; markerEnd?: DisplayObject; markerStartOffset?: number; markerEndOffset?: number; } declare class Path extends DisplayObject { private markerStartAngle; private markerEndAngle; /** * markers placed at the mid */ private markerMidList; constructor({ style, ...rest }?: DisplayObjectConfig); attributeChangedCallback(attrName: Key, oldValue: PathStyleProps[Key], newValue: PathStyleProps[Key], prevParsedValue: ParsedPathStyleProps[Key], newParsedValue: ParsedPathStyleProps[Key]): void; private transformMarker; private placeMarkerMid; /** * Returns the total length of the path. * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getTotalLength */ getTotalLength(): number; /** * Returns the point at a given distance along the path. * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getPointAtLength */ getPointAtLength(distance: number, inWorldSpace?: boolean): Point; /** * Returns the point at a given ratio of the total length in path. */ getPoint(ratio: number, inWorldSpace?: boolean): Point; /** * Get start tangent vector */ getStartTangent(): number[][]; /** * Get end tangent vector */ getEndTangent(): number[][]; } interface TextStyleProps extends BaseStyleProps { x?: number | string; y?: number | string; text: number | string; /** * The text-align property sets the horizontal alignment of the inline-level content. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-align */ textAlign?: CSSGlobalKeywords | 'start' | 'center' | 'middle' | 'end' | 'left' | 'right'; /** * It specifies the current text baseline used when drawing text. * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline */ textBaseline?: CSSGlobalKeywords | 'top' | 'hanging' | 'middle' | 'alphabetic' | 'ideographic' | 'bottom'; /** * The text-overflow property sets how hidden overflow content is signaled to users. * It can be clipped, display an ellipsis ('…'), or display a custom string. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow#values */ textOverflow?: TextOverflow | string; /** * Borrow from CanvasKit ParagraphStyle. */ maxLines?: number; /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/textPath */ textPath?: Path; /** * The side attribute determines the side of a path the text is placed on (relative to the path direction). * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/side */ textPathSide?: 'left' | 'right'; /** * The startOffset attribute defines an offset from the start of the path for the initial current text position along the path after converting the path to the \ element's coordinate system. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/startOffset */ textPathStartOffset?: number | string; /** * @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration-line */ textDecorationLine?: TextDecorationLine; /** * @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration-color */ textDecorationColor?: string; /** * @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration-style */ textDecorationStyle?: TextDecorationStyle; /** * The font-style property sets whether a font should be styled with a normal, italic, or oblique face from its font-family. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/font-style */ fontStyle?: CSSGlobalKeywords | 'normal' | 'italic' | 'oblique'; /** * The font-size property sets the size of the font. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/font-size */ fontSize?: number | string; /** * The font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/font-family */ fontFamily?: string; /** * The font-weight property sets the weight (or boldness) of the font. The weights available depend on the font-family that is currently set. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight */ fontWeight?: CSSGlobalKeywords | 'normal' | 'bold' | 'bolder' | 'lighter' | number; /** * The font-variant shorthand property allows you to set all the font variants for a font. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant */ fontVariant?: CSSGlobalKeywords | 'normal' | 'small-caps' | string; /** * The line-height property sets the height of a line box. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/line-height */ lineHeight?: number | string; /** * It specifies the spacing between letters when drawing text. * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/letterSpacing */ letterSpacing?: number | string; /** * The white-space property sets how white space inside an element is handled. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/white-space */ /** * There is no "CSS leading" property * @see https://css-tricks.com/how-to-tame-line-height-in-css/ */ leading?: number; /** * The overflow-wrap CSS property applies to inline elements, * setting whether the browser should insert line breaks within an otherwise unbreakable string to prevent text from overflowing its line box. * * The overflow-wrap property acts in the same way as the non-standard property word-wrap. * The word-wrap property is now treated by browsers as an alias of the standard property. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap */ wordWrap?: boolean; /** * Max width of overflowing box. */ wordWrapWidth?: number; /** * The dx attribute indicates a shift along the x-axis on the position of an element or its content. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/dx */ dx?: number | string; /** * The dy attribute indicates a shift along the y-axis on the position of an element or its content. * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/dy */ dy?: number | string; } interface ParsedTextStyleProps extends ParsedBaseStyleProps { x: number; y: number; text: string; textAlign?: 'start' | 'center' | 'middle' | 'end' | 'left' | 'right'; textBaseline?: 'top' | 'hanging' | 'middle' | 'alphabetic' | 'ideographic' | 'bottom'; fontStyle?: 'normal' | 'italic' | 'oblique'; fontSize?: number; fontFamily?: string; fontWeight?: 'normal' | 'bold' | 'bolder' | 'lighter' | number; fontVariant?: 'normal' | 'small-caps' | string; lineHeight?: number; letterSpacing?: number; leading?: number; wordWrap?: boolean; wordWrapWidth?: number; maxLines?: number; textOverflow?: TextOverflow | string; isOverflowing?: boolean; textPath?: Path; textDecorationLine?: TextDecorationLine; textDecorationColor?: CSSRGB; textDecorationStyle?: TextDecorationStyle | string; textPathSide?: 'left' | 'right'; textPathStartOffset?: number; metrics?: TextMetrics; dx?: number; dy?: number; } /** * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextElement */ declare class Text extends DisplayObject { /** * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement#constants */ constructor({ style, ...rest }?: DisplayObjectConfig); /** * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement */ getComputedTextLength(): number; getLineBoundingRects(): Rectangle[]; isOverflowing(): boolean; } declare type RenderingPluginContext = CanvasContext & GlobalRuntime; interface RenderingPlugin { apply: (context: RenderingPluginContext, runtime: GlobalRuntime) => void; } interface PickingResult { /** * position in canvas coordinate */ position: EventPosition; picked: DisplayObject[]; /** * only return the topmost object if there are multiple objects overlapped */ topmost?: boolean; } /** * Use frame renderer implemented by `g-canvas/svg/webgl`, in every frame we do followings: * * update & merge dirty rectangles * * begin frame * * filter by visible * * sort by z-index in scene graph * * culling with strategies registered in `g-canvas/webgl` * * end frame */ declare class RenderingService { private globalRuntime; private context; constructor(globalRuntime: GlobalRuntime, context: CanvasContext); private inited; private stats; private zIndexCounter; /** * avoid re-creating too many custom events */ private renderOrderChangedEvent; hooks: { /** * called before any frame rendered */ init: AsyncParallelHook<[], UnsetAdditionalOptions>; /** * only dirty object which has sth changed will be rendered */ dirtycheck: SyncWaterfallHook<[DisplayObject | null], UnsetAdditionalOptions>; /** * do culling */ cull: SyncWaterfallHook<[DisplayObject | null, ICamera], UnsetAdditionalOptions>; /** * called at beginning of each frame, won't get called if nothing to re-render */ beginFrame: SyncHook<[], void, UnsetAdditionalOptions>; /** * called before every dirty object get rendered */ beforeRender: SyncHook<[DisplayObject], void, UnsetAdditionalOptions>; /** * called when every dirty object rendering even it's culled */ render: SyncHook<[DisplayObject], void, UnsetAdditionalOptions>; /** * called after every dirty object get rendered */ afterRender: SyncHook<[DisplayObject], void, UnsetAdditionalOptions>; endFrame: SyncHook<[], void, UnsetAdditionalOptions>; destroy: SyncHook<[], void, UnsetAdditionalOptions>; /** * use async but faster method such as GPU-based picking in `g-plugin-device-renderer` */ pick: AsyncSeriesWaterfallHook<[PickingResult], PickingResult>; /** * Unsafe but sync version of pick. */ pickSync: SyncWaterfallHook<[PickingResult], PickingResult>; /** * used in event system */ pointerDown: SyncHook<[InteractivePointerEvent], void, UnsetAdditionalOptions>; pointerUp: SyncHook<[InteractivePointerEvent], void, UnsetAdditionalOptions>; pointerMove: SyncHook<[InteractivePointerEvent], void, UnsetAdditionalOptions>; pointerOut: SyncHook<[InteractivePointerEvent], void, UnsetAdditionalOptions>; pointerOver: SyncHook<[InteractivePointerEvent], void, UnsetAdditionalOptions>; pointerWheel: SyncHook<[InteractivePointerEvent], void, UnsetAdditionalOptions>; pointerCancel: SyncHook<[InteractivePointerEvent], void, UnsetAdditionalOptions>; click: SyncHook<[InteractivePointerEvent], void, UnsetAdditionalOptions>; }; init(): Promise; getStats(): { /** * total display objects in scenegraph */ total: number; /** * number of display objects need to render in current frame */ rendered: number; }; /** * Meet the following conditions: * * disable DirtyRectangleRendering * * camera changed */ disableDirtyRectangleRendering(): boolean; render(canvasConfig: Partial, rerenderCallback: () => void): void; private renderDisplayObject; destroy(): void; dirtify(): void; } /** * can be treated like Window in DOM * provide some extra methods like `window`, such as: * * `window.requestAnimationFrame` * * `window.devicePixelRatio` * * prototype chains: Canvas(Window) -> EventTarget */ declare class Canvas extends EventTarget implements ICanvas { /** * window.document */ document: Document$1; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry */ customElements: CustomElementRegistry; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame */ requestAnimationFrame: (callback: FrameRequestCallback) => number; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame */ cancelAnimationFrame: (handle: number) => void; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio */ devicePixelRatio: number; /** * whether the runtime supports PointerEvent? * if not, the event system won't trigger pointer events like `pointerdown` */ supportsPointerEvents: boolean; /** * whether the runtime supports TouchEvent? * if not, the event system won't trigger touch events like `touchstart` */ supportsTouchEvents: boolean; /** * is this native event a TouchEvent? */ isTouchEvent: (event: InteractivePointerEvent) => event is TouchEvent; /** * is this native event a MouseEvent? */ isMouseEvent: (event: InteractivePointerEvent) => event is MouseEvent; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element */ Element: typeof DisplayObject; /** * rAF in auto rendering */ private frameId?; private inited; private readyPromise; private resolveReadyPromise; context: CanvasContext; constructor(config: CanvasConfig); private initRenderingContext; private initDefaultCamera; getConfig(): Partial; /** * get the root displayObject in scenegraph * @alias this.document.documentElement */ getRoot(): Group; /** * get the camera of canvas */ getCamera(): ICamera; getContextService(): ContextService; getEventService(): EventService; getRenderingService(): RenderingService; getRenderingContext(): RenderingContext; getStats(): { total: number; rendered: number; }; get ready(): Promise; /** * `cleanUp` means clean all the internal services of Canvas which happens when calling `canvas.destroy()`. */ destroy(cleanUp?: boolean, skipTriggerEvent?: boolean): void; /** * compatible with G 3.0 * @deprecated * @alias resize */ changeSize(width: number, height: number): void; resize(width: number, height: number): void; appendChild(child: T, index?: number): T; insertBefore(newChild: T, refChild: N | null): T; removeChild(child: T): T; /** * Remove all children which can be appended to its original parent later again. */ removeChildren(): void; /** * Recursively destroy all children which can not be appended to its original parent later again. * But the canvas remains running which means display objects can be appended later. */ destroyChildren(): void; render(): void; private run; private initRenderer; private loadRendererContainerModule; setRenderer(renderer: IRenderer): Promise; setCursor(cursor: Cursor): void; unmountChildren(parent: DisplayObject): void; mountChildren(parent: DisplayObject): void; client2Viewport(client: PointLike): PointLike; viewport2Client(canvas: PointLike): PointLike; viewport2Canvas(viewport: PointLike): PointLike; canvas2Viewport(canvas: PointLike): PointLike; /** * @deprecated * @alias client2Viewport */ getPointByClient(clientX: number, clientY: number): PointLike; /** * @deprecated * @alias viewport2Client */ getClientByPoint(x: number, y: number): PointLike; } /** * 保存相机状态,便于后续在多个 Landmark 间移动 */ interface Landmark { name: string; matrix: mat4; right: vec3; up: vec3; forward: vec3; position: vec3; focalPoint: vec3; distanceVector: vec3; distance: number; dollyingStep: number; azimuth: number; elevation: number; roll: number; relAzimuth: number; relElevation: number; relRoll: number; zoom: number; } /** * Different type of cameras, eg. simple camera used in 2D scene or * advanced camera which can do actions & switch between landmarks. */ declare enum CameraType { /** * Performs all the rotational operations with the focal point instead of the camera position. * This type of camera is useful in applications(like CAD) where 3D objects are being designed or explored. * Camera cannot orbits over the north & south poles. * @see http://voxelent.com/tutorial-cameras/ * * In Three.js it's used in OrbitControls. * @see https://threejs.org/docs/#examples/zh/controls/OrbitControls */ ORBITING = 0, /** * It's similar to the ORBITING camera, but it allows the camera to orbit over the north or south poles. * * In Three.js it's used in OrbitControls. * @see https://threejs.org/docs/#examples/en/controls/TrackballControls */ EXPLORING = 1, /** * Performs all the rotational operations with the camera position. * It's useful in first person shooting games. * Camera cannot orbits over the north & south poles. * * In Three.js it's used in FirstPersonControls. * @see https://threejs.org/docs/#examples/en/controls/FirstPersonControls */ TRACKING = 2 } /** * CameraType must be TRACKING */ declare enum CameraTrackingMode { DEFAULT = 0, ROTATIONAL = 1, TRANSLATIONAL = 2, CINEMATIC = 3 } declare enum CameraProjectionMode { ORTHOGRAPHIC = 0, PERSPECTIVE = 1 } interface ICamera { canvas: ICanvas; eventEmitter: EventEmitter; isOrtho: () => boolean; getProjectionMode: () => CameraProjectionMode; getPerspective: () => mat4; getPerspectiveInverse: () => mat4; getFrustum: () => Frustum; getPosition: () => vec3; getFocalPoint: () => vec3; getDollyingStep: () => number; getNear: () => number; getFar: () => number; getZoom: () => number; getOrthoMatrix: () => mat4; getView: () => { enabled: boolean; fullWidth: number; fullHeight: number; offsetX: number; offsetY: number; width: number; height: number; }; setEnableUpdate: (enabled: boolean) => void; setType: (type: CameraType, trackingMode?: CameraTrackingMode) => this; setProjectionMode: (projectionMode: CameraProjectionMode) => this; setTrackingMode: (trackingMode: CameraTrackingMode) => this; /** * If flag is true, it reverses the azimuth and elevation angles. * Subsequent calls to rotate, setAzimuth, setElevation, * changeAzimuth or changeElevation will cause the inverted effect. * setRoll or changeRoll is not affected by this method. * * This inversion is useful when one wants to simulate that the world * is moving, instead of the camera. * * By default the camera angles are not reversed. * @param {Boolean} flag the boolean flag to reverse the angles. */ setWorldRotation: (flag: boolean) => this; /** * 计算 MV 矩阵,为相机矩阵的逆矩阵 */ getViewTransform: () => mat4; getWorldTransform: () => mat4; jitterProjectionMatrix: (x: number, y: number) => void; clearJitterProjectionMatrix: () => void; /** * 设置相机矩阵 */ setMatrix: (matrix: mat4) => this; setFov: (fov: number) => this; setAspect: (aspect: number) => this; setNear: (near: number) => this; setFar: (far: number) => this; /** * Sets an offset in a larger frustum, used in PixelPicking */ setViewOffset: (fullWidth: number, fullHeight: number, x: number, y: number, width: number, height: number) => this; clearViewOffset: () => this; setZoom: (zoom: number) => this; setZoomByViewportPoint: (zoom: number, viewportPoint: vec2) => this; setPerspective: (near: number, far: number, fov: number, aspect: number) => this; setOrthographic: (l: number, r: number, t: number, b: number, near: number, far: number) => this; /** * Move the camera in world coordinates. * It will keep looking at the current focal point. * * support scalars or vectors. * @example * setPosition(1, 2, 3); * setPosition([1, 2, 3]); */ setPosition: (x: number | vec2 | vec3, y?: number, z?: number) => this; /** * Sets the focal point of this camera in world coordinates. * * support scalars or vectors. * @example * setFocalPoint(1, 2, 3); * setFocalPoint([1, 2, 3]); */ setFocalPoint: (x: number | vec2 | vec3, y?: number, z?: number) => this; getDistance: () => number; getDistanceVector: () => vec3; /** * Moves the camera towards/from the focal point. */ setDistance: (d: number) => this; setMaxDistance: (d: number) => this; setMinDistance: (d: number) => this; /** * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置 * the azimuth in degrees */ setAzimuth: (az: number) => this; getAzimuth: () => number; /** * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置 */ setElevation: (el: number) => this; getElevation: () => number; /** * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置 */ setRoll: (angle: number) => this; getRoll: () => number; /** * Changes the azimuth and elevation with respect to the current camera axes * @param {Number} azimuth the relative azimuth * @param {Number} elevation the relative elevation * @param {Number} roll the relative roll */ rotate: (azimuth: number, elevation: number, roll: number) => this; /** * 沿水平(right) & 垂直(up)平移相机 */ pan: (tx: number, ty: number) => this; /** * 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢 */ dolly: (value: number) => this; createLandmark: (name: string, params?: Partial<{ position: vec3 | vec2; focalPoint: vec3 | vec2; zoom: number; roll: number; }>) => Landmark; gotoLandmark: (name: string | Landmark, options?: number | Partial<{ easing: string; easingFunction: TypeEasingFunction; duration: number; onfinish: () => void; }>) => void; /** * Stop camera animation immediately. */ cancelLandmarkAnimation: () => void; } /** * 参考「WebGL Insights - 23.Designing Cameras for WebGL Applications」,基于 Responsible Camera 思路设计 * @see https://github.com/d13g0/nucleo.js/blob/master/source/camera/Camera.js * * 保存相机参数,定义相机动作: * 1. dolly 沿 n 轴移动 * 2. pan 沿 u v 轴移动 * 3. rotate 以方位角旋转 * 4. 移动到 Landmark,具有平滑的动画效果,其间禁止其他用户交互 */ declare class Camera implements ICamera { canvas: Canvas; eventEmitter: EventEmitter; /** * 相机矩阵 */ protected matrix: mat4; /** * u 轴 * @see http://learnwebgl.brown37.net/07_cameras/camera_introduction.html#a-camera-definition */ protected right: vec3; /** * v 轴 +Y is down */ protected up: vec3; /** * n 轴 +Z is inside */ protected forward: vec3; /** * 相机位置 */ protected position: vec3; /** * 视点位置 */ protected focalPoint: vec3; /** * 视点到相机位置的向量 * focalPoint - position */ protected distanceVector: vec3; /** * 相机位置到视点距离 * length(focalPoint - position) */ protected distance: number; /** * @see https://en.wikipedia.org/wiki/Azimuth */ protected azimuth: number; protected elevation: number; protected roll: number; protected relAzimuth: number; protected relElevation: number; protected relRoll: number; /** * 沿 n 轴移动时,保证移动速度从快到慢 */ protected dollyingStep: number; protected maxDistance: number; protected minDistance: number; /** * zoom factor of the camera, default is 1 * eg. https://threejs.org/docs/#api/en/cameras/OrthographicCamera.zoom */ protected zoom: number; /** * invert the horizontal coordinate system HCS */ protected rotateWorld: boolean; /** * 投影矩阵参数 */ /** * field of view [0-360] * @see http://en.wikipedia.org/wiki/Angle_of_view */ protected fov: number; protected near: number; protected far: number; protected aspect: number; protected left: number; protected rright: number; protected top: number; protected bottom: number; protected projectionMatrix: mat4; protected projectionMatrixInverse: mat4; protected jitteredProjectionMatrix: mat4 | undefined; protected view: { enabled: boolean; fullWidth: number; fullHeight: number; offsetX: number; offsetY: number; width: number; height: number; } | undefined; protected enableUpdate: boolean; protected type: CameraType; protected trackingMode: CameraTrackingMode; protected projectionMode: CameraProjectionMode; /** * for culling use */ protected frustum: Frustum; /** * ortho matrix for Canvas2D & SVG */ protected orthoMatrix: mat4; isOrtho(): boolean; getProjectionMode(): CameraProjectionMode; getPerspective(): mat4; getPerspectiveInverse(): mat4; getFrustum(): Frustum; getPosition(): vec3; getFocalPoint(): vec3; getDollyingStep(): number; getNear(): number; getFar(): number; getZoom(): number; getOrthoMatrix(): mat4; getView(): { enabled: boolean; fullWidth: number; fullHeight: number; offsetX: number; offsetY: number; width: number; height: number; } | undefined; setEnableUpdate(enabled: boolean): void; setType(type: CameraType, trackingMode?: CameraTrackingMode): this; setProjectionMode(projectionMode: CameraProjectionMode): this; setTrackingMode(trackingMode: CameraTrackingMode): this; /** * If flag is true, it reverses the azimuth and elevation angles. * Subsequent calls to rotate, setAzimuth, setElevation, * changeAzimuth or changeElevation will cause the inverted effect. * setRoll or changeRoll is not affected by this method. * * This inversion is useful when one wants to simulate that the world * is moving, instead of the camera. * * By default the camera angles are not reversed. * @param {Boolean} flag the boolean flag to reverse the angles. */ setWorldRotation(flag: boolean): this; /** * 计算 MV 矩阵,为相机矩阵的逆矩阵 */ getViewTransform(): mat4; getWorldTransform(): mat4; jitterProjectionMatrix(x: number, y: number): void; clearJitterProjectionMatrix(): void; /** * 设置相机矩阵 */ setMatrix(matrix: mat4): this; setFov(fov: number): this; setAspect(aspect: number): this; setNear(near: number): this; setFar(far: number): this; /** * Sets an offset in a larger frustum, used in PixelPicking */ setViewOffset(fullWidth: number, fullHeight: number, x: number, y: number, width: number, height: number): this; clearViewOffset(): this; setZoom(zoom: number): this; /** * Zoom by specified point in viewport coordinates. */ setZoomByViewportPoint(zoom: number, viewportPoint: vec2): this; setPerspective(near: number, far: number, fov: number, aspect: number): this; setOrthographic(l: number, r: number, t: number, b: number, near: number, far: number): this; /** * Move the camera in world coordinates. * It will keep looking at the current focal point. * * support scalars or vectors. * @example * setPosition(1, 2, 3); * setPosition([1, 2, 3]); */ setPosition(x: number | vec2 | vec3, y?: number, z?: number): this; /** * Sets the focal point of this camera in world coordinates. * * support scalars or vectors. * @example * setFocalPoint(1, 2, 3); * setFocalPoint([1, 2, 3]); */ setFocalPoint(x: number | vec2 | vec3, y?: number, z?: number): this; getDistance(): number; getDistanceVector(): vec3; /** * Moves the camera towards/from the focal point. */ setDistance(d: number): this; setMaxDistance(d: number): this; setMinDistance(d: number): this; /** * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置 * the azimuth in degrees */ setAzimuth(az: number): this; getAzimuth(): number; /** * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置 */ setElevation(el: number): this; getElevation(): number; /** * 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置 */ setRoll(angle: number): this; getRoll(): number; /** * 根据相机矩阵重新计算各种相机参数 */ protected _update(): void; /** * 计算相机矩阵 */ protected computeMatrix(): void; /** * Sets the camera position in the camera matrix */ protected _setPosition(x: number | vec3, y?: number, z?: number): void; /** * Recalculates axes based on the current matrix */ protected _getAxes(): void; /** * Recalculates euler angles based on the current state */ protected _getAngles(): void; /** * 重新计算相机位置,只有 ORBITING 模式相机位置才会发生变化 */ protected _getPosition(): void; /** * 重新计算视点,只有 TRACKING 模式视点才会发生变化 */ protected _getFocalPoint(): void; /** * 重新计算视距 */ protected _getDistance(): void; protected _getOrthoMatrix(): void; protected triggerUpdate(): void; rotate(azimuth: number, elevation: number, roll: number): this; pan(tx: number, ty: number): this; dolly(value: number): this; createLandmark(name: string, params?: Partial<{ position: [number, number, number] | Float32Array | [number, number]; focalPoint: [number, number, number] | Float32Array | [number, number]; zoom: number; roll: number; }>): Landmark; gotoLandmark(name: string | Landmark, options?: number | Partial<{ easing: string; easingFunction: TypeEasingFunction; duration: number; onfinish: () => void; }>): void; cancelLandmarkAnimation(): void; } interface IEventTarget { addEventListener: (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void; removeEventListener: (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void; dispatchEvent: (e: T, skipPropagate?: boolean) => boolean; } interface INode$1 extends IEventTarget { shadow: boolean; /** * Returns node's node document's document base URL. */ readonly baseURI: string; /** * Returns the children. */ readonly childNodes: IChildNode[]; /** * Returns the first child. */ readonly firstChild: IChildNode | null; /** * Returns true if node is connected and false otherwise. */ isConnected: boolean; /** * Returns the last child. */ readonly lastChild: IChildNode | null; /** * Returns the next sibling. */ readonly nextSibling: IChildNode | null; /** * Returns a string appropriate for the type of node. */ readonly nodeName: string; /** * Returns the type of node. */ readonly nodeType: number; nodeValue: string | null; /** * Returns the node document. Returns null for documents. */ ownerDocument: IDocument | null; /** * Returns the parent element. */ readonly parentElement: IElement | null; /** * Returns the parent. */ parentNode: (INode$1 & IParentNode) | null; /** * Returns the previous sibling. */ readonly previousSibling: IChildNode | null; textContent: string | null; appendChild: (newChild: T, index?: number) => T; /** * Returns a copy of node. If deep is true, the copy also includes the node's descendants. */ cloneNode: (deep?: boolean) => INode$1; /** * Returns a bitmask indicating the position of other relative to node. */ compareDocumentPosition: (other: INode$1) => number; /** * Returns true if other is an inclusive descendant of node, and false otherwise. */ contains: (other: INode$1 | null) => boolean; /** * Returns node's root. */ getRootNode: (options?: GetRootNodeOptions) => INode$1; /** * Returns node's ancestor. */ getAncestor: (n: number) => INode$1 | null; /** * Traverse in sub tree. */ forEach: (callback: (o: INode$1) => void | boolean, assigned?: boolean) => void; /** * Returns whether node has children. */ hasChildNodes: () => boolean; insertBefore: (newChild: T, refChild: INode$1 | null) => T; isDefaultNamespace: (namespace: string | null) => boolean; /** * Returns whether node and otherNode have the same properties. */ isEqualNode: (otherNode: INode$1 | null) => boolean; isSameNode: (otherNode: INode$1 | null) => boolean; lookupNamespaceURI: (prefix: string | null) => string | null; lookupPrefix: (namespace: string | null) => string | null; /** * Removes empty exclusive Text nodes and concatenates the data * of remaining contiguous exclusive Text nodes into the first of their nodes. */ normalize: () => void; removeChild: (oldChild: T) => T; replaceChild: (newChild: INode$1, oldChild: T) => T; /** * Destroy itself. */ destroy: () => void; } interface IParentNode { readonly childElementCount: number; /** * Returns the child elements. */ readonly children: IElement[]; /** * Returns the first child that is an element, and null otherwise. */ readonly firstElementChild: IElement | null; /** * Returns the last child that is an element, and null otherwise. */ readonly lastElementChild: IElement | null; /** * Inserts nodes after the last child of node, * while replacing strings in nodes with equivalent Text nodes. * * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ append: (...nodes: INode$1[]) => void; /** * Inserts nodes before the first child of node, * while replacing strings in nodes with equivalent Text nodes. * * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ prepend: (...nodes: INode$1[]) => void; /** * Returns the first element that is a descendant of node that matches selectors. */ querySelector: (selectors: string) => E | null; /** * Returns all element descendants of node that match selectors. */ querySelectorAll: (selectors: string) => E[]; /** * Similar to querySelector, use custom filter instead of selectors. */ find: (filter: (node: E) => boolean) => E | null; /** * Similar to querySelectorAll, use custom filter instead of selectors. */ findAll: (filter: (node: E) => boolean) => E[]; } interface IChildNode extends INode$1 { /** * Inserts nodes just after node, while replacing strings in nodes with equivalent Text nodes. * * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ after: (...nodes: INode$1[]) => void; /** * Inserts nodes just before node, while replacing strings in nodes with equivalent Text nodes. * * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ before: (...nodes: INode$1[]) => void; /** * Removes node. */ remove: () => void; /** * Replaces node with nodes, while replacing strings in nodes with equivalent Text nodes. * * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ replaceWith: (...nodes: INode$1[]) => void; } interface DisplayObjectConfig { /** * element's identifier, must be unique in a document. * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/id */ id?: string; name?: string; /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/className */ class?: string; className?: string; /** * all styles properties, not read-only * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style */ style?: StyleProps; initialParsedStyle?: any; /** * compatible with G 3.0 * @alias style * @deprecated */ attrs?: StyleProps; type?: Shape$1 | string; /** * @deprecated use `style.zIndex` instead */ zIndex?: number; /** * @deprecated use `style.visibility = 'visible'` instead */ visible?: boolean; /** * compatible with G 3.0 * @alias interactive * @deprecated */ capture?: boolean; /** * enable interaction events for the DisplayObject * @deprecated use `style.pointerEvents = 'auto'` instead */ interactive?: boolean; } interface IElement extends INode$1, IChildNode, IParentNode { /** * Returns the value of element's id content attribute. Can be set to change it. */ id: string; /** * Returns the qualified name. */ tagName: string; name: string; /** * Returns the value of element's class content attribute. Can be set to change it. */ className: string; classList: string[]; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes */ attributes: StyleProps; /** * compatible with `style` * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style */ style: StyleProps & ICSSStyleDeclaration; parsedStyle: ParsedStyleProps; getElementById: (id: string) => E | null; getElementsByName: (name: string) => E[]; getElementsByClassName: (className: string) => E[]; getElementsByTagName: (tagName: string) => E[]; scrollLeft: number; scrollTop: number; clientLeft: number; clientTop: number; getGeometryBounds(): AABB; getRenderBounds(): AABB; getBounds(): AABB; getLocalBounds(): AABB; getBoundingClientRect(): Rectangle; getClientRects(): Rectangle[]; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute */ setAttribute: (attributeName: Key, value: StyleProps[Key], force?: boolean) => void; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute */ getAttribute: (attributeName: keyof StyleProps) => StyleProps[keyof StyleProps] | undefined; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute */ removeAttribute: (attributeName: keyof StyleProps) => void; hasAttribute: (qualifiedName: string) => boolean; } interface IAnimationTimeline { currentTime: number | null; destroy: () => void; play: (target: IElement, keyframes: Keyframe[] | PropertyIndexedKeyframes | null, options?: number | KeyframeAnimationOptions | undefined) => IAnimation; restart: () => boolean; getAnimations: () => IAnimation[]; } interface IAnimation { effect: IKeyframeEffect; timeline: IAnimationTimeline; id: string; pending: boolean; playState: AnimationPlayState; ready: Promise; finished: Promise; onfinish: ((this: this, ev: AnimationPlaybackEvent) => any) | null; oncancel: ((this: this, ev: AnimationPlaybackEvent) => any) | null; onframe: ((this: this, ev: AnimationPlaybackEvent) => any) | null; currentTime: number; startTime: number; playbackRate: number; totalDuration: number; play: () => void; pause: () => void; finish: () => void; cancel: () => void; reverse: () => void; updatePlaybackRate: (playbackRate: number) => void; tick: (timelineTime: number, isAnimationFrame: boolean) => void; } interface IAnimationEffectTiming extends EffectTiming { easingFunction: TypeEasingFunction; } interface IKeyframeEffect { composite: CompositeOperation; iterationComposite: IterationCompositeOperation; target: IElement | null; animation: IAnimation | null; timing: IAnimationEffectTiming; normalizedKeyframes: ComputedKeyframe[]; applyInterpolations: () => void; update: (localTime: number | null) => boolean; getKeyframes: () => ComputedKeyframe[]; setKeyframes: (keyframes: Keyframe[] | PropertyIndexedKeyframes | null) => void; getComputedTiming: () => ComputedEffectTiming; getTiming: () => EffectTiming; updateTiming: (timing?: OptionalEffectTiming) => void; } interface IDocument extends INode$1, IParentNode { /** * Returns the Window object of the active document. */ readonly defaultView: ICanvas | null; /** * Gets a reference to the root node of the document. */ readonly documentElement: IElement; readonly ownerDocument: null; readonly timeline: IAnimationTimeline; /** * Creates an instance of the element for the specified tag. */ createElement: , StyleProps extends BaseStyleProps>(tagName: string, options: DisplayObjectConfig) => T; elementFromPoint: (x: number, y: number) => Promise; elementsFromPoint: (x: number, y: number) => Promise; elementsFromBBox: (minX: number, minY: number, maxX: number, maxY: number) => DisplayObject[]; } /** * @see https://developer.mozilla.org/zh-CN/docs/Web/API/CSSStyleDeclaration */ interface ICSSStyleDeclaration { setProperty: (propertyName: Key, value: StyleProps[Key], priority?: string) => void; getPropertyValue: (propertyName: keyof StyleProps) => StyleProps[keyof StyleProps] | undefined; removeProperty: (propertyName: keyof StyleProps) => void; item: (index: number) => string; } interface CanvasContext { config: Partial; camera: ICamera; /** * ContextServiceContribution */ ContextService: new (context: GlobalRuntime & CanvasContext) => ContextService; contextService: ContextService; renderingService: RenderingService; eventService: EventService; rBushRoot: RBush; renderingContext: RenderingContext; renderingPlugins: RenderingPlugin[]; } interface ICanvas extends IEventTarget { document: IDocument; customElements: CustomElementRegistry; devicePixelRatio: number; requestAnimationFrame: (callback: FrameRequestCallback) => number; cancelAnimationFrame: (handle: number) => void; supportsTouchEvents: boolean; supportsPointerEvents: boolean; isTouchEvent: (event: InteractivePointerEvent) => event is TouchEvent; isMouseEvent: (event: InteractivePointerEvent) => event is MouseEvent; render: () => void; destroy: (destroyScenegraph?: boolean) => void; resize: (width: number, height: number) => void; context: CanvasContext; mountChildren: (parent: INode$1) => void; unmountChildren: (parent: INode$1) => void; getConfig: () => Partial; getCamera: () => ICamera; getContextService: () => ContextService; getRenderingService: () => RenderingService; getEventService: () => EventService; client2Viewport: (client: PointLike) => PointLike; viewport2Client: (viewport: PointLike) => PointLike; canvas2Viewport: (canvas: PointLike) => PointLike; viewport2Canvas: (viewport: PointLike) => PointLike; } interface CircleStyleProps extends BaseStyleProps { cx?: number | string | null; cy?: number | string | null; r: number | string | null; } interface ParsedCircleStyleProps extends ParsedBaseStyleProps { cx: number; cy: number; r: number; } declare class Circle extends DisplayObject { constructor({ style, ...rest }?: DisplayObjectConfig); } interface GroupStyleProps extends BaseStyleProps { x?: number | string; y?: number | string; width?: number | string; height?: number | string; } /** * its attributes are inherited by its children. * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/g * @example * */ declare class Group extends DisplayObject { constructor({ style, ...rest }?: DisplayObjectConfig); } interface HTMLStyleProps extends BaseStyleProps { x?: number | string; y?: number | string; innerHTML: string | HTMLElement; width?: number | string; height?: number | string; } interface ParsedHTMLStyleProps extends ParsedBaseStyleProps { x: CSSUnitValue; y: CSSUnitValue; $el: HTMLElement; innerHTML: string | HTMLElement; width: CSSUnitValue; height: CSSUnitValue; } /** * HTML container * @see https://github.com/pmndrs/drei#html */ declare class HTML extends DisplayObject { constructor({ style, ...rest }?: DisplayObjectConfig); /** * return wrapper HTMLElement * *
in g-webgl/canvas * * in g-svg */ getDomElement(): HTMLElement; /** * override with $el.getBoundingClientRect * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect */ getBoundingClientRect(): DOMRect; getClientRects(): DOMRect[]; getBounds(): AABB | null; getLocalBounds(): AABB | null; } interface ImageStyleProps extends BaseStyleProps { x?: number | string; y?: number | string; z?: number; img?: string | HTMLImageElement; src?: string | HTMLImageElement; width?: number | string; height?: number | string; isBillboard?: boolean; } interface ParsedImageStyleProps extends ParsedBaseStyleProps { x: number; y: number; z?: number; img?: string | HTMLImageElement; src?: string | HTMLImageElement; width?: number; height?: number; isBillboard?: boolean; } declare class Image extends DisplayObject { constructor({ style, ...rest }?: DisplayObjectConfig); } interface PolygonStyleProps extends BaseStyleProps { points: [number, number][]; /** * marker will be positioned at the first point */ markerStart?: DisplayObject; /** * marker will be positioned at the last point */ markerEnd?: DisplayObject; markerMid?: DisplayObject; /** * offset relative to original position */ markerStartOffset?: number; /** * offset relative to original position */ markerEndOffset?: number; isClosed?: boolean; } interface PolylineStyleProps extends BaseStyleProps { points: [number, number][]; /** * marker will be positioned at the first point */ markerStart?: DisplayObject; /** * marker will be positioned at the last point */ markerEnd?: DisplayObject; markerMid?: DisplayObject; /** * offset relative to original position */ markerStartOffset?: number; /** * offset relative to original position */ markerEndOffset?: number; } interface AllShapeStyle extends BaseStyleProps, LineStyleProps, PathStyleProps, PolygonStyleProps, PolylineStyleProps { cx?: number | string | null; cy?: number | string | null; r: number | string | null; rx: number | string | null; ry: number | string | null; x?: number | string; y?: number | string; width?: number | string; height?: number | string; innerHTML: string | HTMLElement; z?: number; img?: string | HTMLImageElement; src?: string | HTMLImageElement; isBillboard?: boolean; /** * top-left, top-right, bottom-right, bottom-left */ radius?: number | string | number[]; } declare type Interpolatable = number | boolean | number[] | boolean[]; declare type CSSPropertyMixer = (left: Parsed, right: Parsed, displayObject: IElement | null) => [T, T, (i: T) => string | any] | undefined; declare type CSSPropertyParser = (value: string | any, object: DisplayObject) => Parsed; declare type CSSPropertyCalculator = (name: string, oldParsed: Parsed, parsed: Parsed, object: IElement, registry: StyleValueRegistry) => Used; /** * 1. parser: raw CSS string -> Computed Value * 2. calculator: Computed Value -> Used Value * 3. mixer(in animation system): Used Value -> new Used Value * 4. post processor */ interface CSSProperty { /** * parse CSS string to CSSStyleValue * * @example * '10' -> CSS.number(10) * '10px' -> CSS.px(10) * '180deg' -> CSS.deg(180) */ parser: CSSPropertyParser; parserWithCSSDisabled: CSSPropertyParser; /** * convert parsed value to used value. * eg. in `lineWidth`, convert [CSSUnitValue] to [CSSUnitValue, CSSUnitValue] * * in Blink, it convert a CSSValue to an appropriate platform value */ calculator: CSSPropertyCalculator; /** * used with interpolation in animation system */ mixer: CSSPropertyMixer; preProcessor: (object: IElement) => void; /** * eg. update local position after x/y/z caculated */ postProcessor: (object: IElement, attributes: string[]) => void; } /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type */ declare enum PropertySyntax { /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#coordinate */ COORDINATE = "", /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#color */ COLOR = "", /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#paint */ PAINT = "", /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number */ NUMBER = "", /** * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/angle */ ANGLE = "", /** * with range 0..1 * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#opacity_value */ OPACITY_VALUE = "", /** * with range 0..Infinity */ SHADOW_BLUR = "", /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#length */ LENGTH = "", /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage */ PERCENTAGE = "", LENGTH_PERCENTAGE = " | ", LENGTH_PERCENTAGE_12 = "[ | ]{1,2}", /** * @see https://developer.mozilla.org/en-US/docs/Web/CSS/margin#formal_syntax */ LENGTH_PERCENTAGE_14 = "[ | ]{1,4}", /** * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#list-of-ts */ LIST_OF_POINTS = "", PATH = "", /** * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter#formal_syntax */ FILTER = "", Z_INDEX = "", OFFSET_DISTANCE = "", DEFINED_PATH = "", MARKER = "", TRANSFORM = "", TRANSFORM_ORIGIN = "", TEXT = "", TEXT_TRANSFORM = "" } interface PropertyMetadata { n: string; /** * The interpolable flag indicates whether a property can be animated smoothly. * Default to `false`. */ int?: boolean; /** * The property will inherit by default if no value is specified. * Default to `false`. */ inh?: boolean; /** * This property affects only one field on ComputedStyle, and can be set * directly during inheritance instead of forcing a recalc. */ ind?: boolean; /** * This specifies the default value for this field. * - for keyword fields, this is the initial keyword * - for other fields, this is a string containg the C++ expression that is used to initialise the field. */ d?: string | ((nodeName: string) => string); /** * The resolved value used for getComputedStyle() depends on layout for this * property, which means we may need to update layout to return the correct * value from getComputedStyle(). */ l?: boolean; /** * This specifies all valid keyword values for the property. */ k?: string[]; /** * eg. strokeWidth is an alias of lineWidth */ a?: string[]; /** * sort before init attributes according to this priority */ p?: number; /** * eg. */ syntax?: string; } interface PropertyParseOptions { skipUpdateAttribute: boolean; skipParse: boolean; forceUpdateGeometry: boolean; usedAttributes: string[]; } interface StyleValueRegistry { recalc: (displayObject: DisplayObject) => void; registerMetadata: (metadata: PropertyMetadata) => void; unregisterMetadata: (name: string) => void; getPropertySyntax: (syntax: string) => CSSProperty; addUnresolveProperty: (object: DisplayObject, name: string) => void; processProperties: (object: DisplayObject, attributes: BaseStyleProps, options?: Partial) => void; parseProperty: (name: string, value: any, object: DisplayObject) => CSSStyleValue; computeProperty: (name: string, computed: CSSStyleValue, object: DisplayObject) => any; } interface LayoutRegistry { registerLayout: (name: string, ctor: any) => void; hasLayout: (name: string) => boolean; getLayout: (name: string) => any; } declare type CSSGlobalKeywords = 'unset' | 'initial' | 'inherit' | ''; interface GlobalRuntime { CameraContribution: new () => Camera; AnimationTimeline: any; EasingFunction: (...args: any[]) => (t: number) => number; geometryUpdaterFactory: Record>; styleValueRegistry: StyleValueRegistry; layoutRegistry: LayoutRegistry; CSSPropertySyntaxFactory: Record>>; globalThis: any; enableCSSParsing: boolean; nativeHTMLMap: WeakMap; } interface IPoint { x: number; y: number; anchorIndex?: number; [key: string]: number | undefined; } interface IItemBase { destroyed: boolean; /** * 节点类型 * @return {string} 节点的类型 */ getType: () => ITEM_TYPE; /** * 获取 Item 的ID */ getID: () => string; /** * 获取当前元素的所有状态 * @return {Array} 元素的所有状态 */ getStates: () => string[]; /** * 当前元素是否处于某状态 * @param {String} state 状态名 * @return {Boolean} 是否处于某状态 */ hasState: (state: string) => boolean; /** * 更改元素状态, visible 不属于这个范畴 * @internal 仅提供内部类 graph 使用 * @param {String} state 状态名 * @param {Boolean} value 节点状态值 */ setState: (state: string, value: string | boolean) => void; clearStates: (states?: string | string[]) => void; /** * 将更新应用到 model 上,刷新属性 * @internal 仅提供给 Graph 使用,外部直接调用 graph.update 接口 * @param {Object} cfg 配置项,可以是增量信息 * @param {boolean} updateType 更新的类型,'move' 代表仅移动 */ update: (cfg: ModelConfig, updateType?: UpdateType) => void; /** * 显示元素 */ show: () => void; /** * 隐藏元素 */ hide: () => void; get: (key: string) => T; set: (key: string, value: T) => void; } interface IEdge extends IItemBase { setSource: (source: INode) => void; setTarget: (target: INode) => void; getSource: () => INode; getTarget: () => INode; } interface INode extends IItemBase { /** * 获取从节点关联的所有边 * @return {Array} 边的集合 */ getEdges: () => IEdge[]; /** * 添加边 * @param {Edge} edge 边 */ addEdge: (edge: IEdge) => void; /** * 移除边 * @param {Edge} edge 边 */ removeEdge: (edge: IEdge) => void; /** * 获取节点所有的邻居节点 * * @returns {INode[]} * @memberof INode */ getNeighbors: (type?: 'source' | 'target' | undefined) => INode[]; /** * 获取连接点 * @param {Object} point 节点外面的一个点,用于计算交点、最近的锚点 * @return {Object} 连接点 {x,y} */ getLinkPoint: (point: IPoint) => IPoint | null; /** * 获取节点中心点 * @returns */ getPosition: () => IPoint; } declare type IItem = INode | IEdge; interface States { [key: string]: IItem[]; } interface ItemMap { [key: string]: IItem; } interface ArrowConfig { lineWidth?: number; path?: string; stroke?: string; fill?: string; lineDash?: number[]; strokeOpacity?: number; opacity?: number; fillOpacity?: number; /** * 偏移量,见:https://g-next.antv.vision/api/basic/line#markerend * markerStartOffset 和 markerEndOffset */ endOffset?: number; } declare type ShapeStyle = Partial; declare type ModelStyle = Partial<{ [key: string]: unknown; style: ShapeStyle; }>; interface ModelConfig extends ModelStyle { id?: string; type?: string; nodeType?: string; x?: number; y?: number; size?: number | number[]; color?: string; anchorPoints?: number[][]; startPoint?: { x: number; y: number; }; endPoint?: { x: number; y: number; }; visible?: boolean; endArrow?: boolean | ArrowConfig; /** * 节点指标数据 * */ metrics?: MetricInfo[]; /** * 是否显示指标名 * */ showMetricName?: boolean; /** * 是否展示lael名 */ showLabel?: boolean; } interface MetricInfo { name: string; value: number; min?: number; max?: number; baseColor?: string; strokeColor?: string; } interface NodeConfig extends ModelConfig { id: string; } interface EdgeConfig extends ModelConfig { id?: string; source?: string; target?: string; sourceNode?: Node; targetNode?: Node; } declare type UpdateType = 'move' | 'bbox' | 'style' | 'bbox|label' | 'style|label' | undefined; declare type ShapeOptions = Partial<{ options: ModelConfig; /** * 形状的类型,例如 circle,ellipse,polyline... */ type: string; itemType: string; shapeType: string; [key: string]: any; /** * 绘制 */ draw: (cfg: ModelConfig, group: Group, item: IItem) => DisplayObject; drawShape: (cfg?: ModelConfig, group?: Group) => DisplayObject; /** * 绘制完成后的操作,便于用户继承现有的节点、边 */ afterDraw: (cfg: ModelConfig, group: Group, item: IItem, rst?: DisplayObject) => void; /** * 仅更新为位置信息 */ updatePosition: (cfg: ModelConfig, group: Group, item: IItem) => DisplayObject; /** * 绘制完成后的操作,便于用户继承现有的节点、边 */ afterUpdatePosition: (cfg: ModelConfig, group: Group, item: IItem, rst?: DisplayObject) => void; setState: (name: string, value: string | boolean, item: IItem) => void; }>; declare class ItemController { private graph; destroyed: boolean; private edgeToBeUpdateMap; constructor(graph: IGraph); /** * 增加 Item 实例 * * @param {ITEM_TYPE} type 实例类型,node 或 edge * @param {(NodeConfig & EdgeConfig)} model 数据模型 * @returns {(IItem)} * @memberof ItemController */ addItem(type: ITEM_TYPE, model: ModelConfig): IItem | boolean; /** * 更新节点或边 * * @param {IItem} item ID 或 实例 * @param {(EdgeConfig | Partial)} cfg 数据模型 * @returns * @memberof ItemController */ updateItem(item: IItem | string, cfg: EdgeConfig | Partial, updateType?: UpdateType): void; /** * 更新 item 状态 * * @param {IItem} item Item 实例 * @param {string} state 状态名称 * @param {boolean} value 是否启用状态或状态值 * @returns {void} * @memberof ItemController */ setItemState(item: IItem, state: string, value: string | boolean): void; /** * 清除所有指定的状态 * * @param {IItem} item Item 实例 * @param {string[]} states 状态名称集合 * @memberof ItemController */ clearItemStates(item: IItem | string, states?: string | string[]): void; /** * 更新边限流,同时可以防止相同的边频繁重复更新 * */ private throttleRefresh; } declare class LayoutController { graph: IGraph; destroyed: boolean; protected layoutCfg: LayoutConfig; protected layoutType: string | string[]; constructor(graph: IGraph); protected initLayout(): void; layout(): void; } declare class StateController { private graph; destroyed: boolean; constructor(graph: IGraph); /** * 更新 Item 的状态 * * @param {IItem} item Item实例 * @param {string} state 状态名称 * @param {boolean} enabled 状态是否可用 * @memberof State */ updateState(item: IItem, state: string, enabled: string | boolean): void; /** * 批量更新 states,兼容 updateState,支持更新一个 state * * @param {IItem} item * @param {(string | string[])} states * @param {boolean} enabled * @memberof State */ updateStates(item: IItem, states: string | string[], enabled: string | boolean): void; destroy(): void; } declare class ViewController { private graph; destroyed: boolean; constructor(graph: IGraph); private getViewCenter; } declare class EventController { private graph; private canvasDragListener; private canvasWheelZoomListener; private preHoverItem; destroyed: boolean; constructor(graph: IGraph); init(): void; destory(): void; /** * 处理画布拖动,TODO: 拖动需要限制范围 * @param draggable asdf */ setCanvasDraggable(draggable: boolean): void; /** * 处理画布缩放 * @param zoomable */ setCanvasWheelZoom(zoomable: boolean): void; private initCanvasEvent; private handleCanvasEvent; private handlePointerMove; private isItemGroup; private getItem; } interface GEventCommon { item: IItem | null; } interface GMouseEvent extends GEventCommon, FederatedMouseEvent { } interface GPointerEvent extends GEventCommon, FederatedPointerEvent { } interface GWheelEvent extends GEventCommon, FederatedWheelEvent { } declare type GEvent = GMouseEvent | GPointerEvent | GWheelEvent; declare type GEventNameKey = 'canvas' | 'node' | 'edge'; declare type GEventNameValue = 'click' | 'mouseenter' | 'mouseleave'; declare type GEventNameCommon = `${GEventNameKey}:${GEventNameValue}`; declare type GEventName = GEventNameCommon | string; interface BehaviorConfig { cfg?: Record; type: string; } declare type ITEM_TYPE = 'node' | 'edge'; interface GraphData { nodes?: NodeConfig[]; edges?: EdgeConfig[]; [key: string]: any; } interface IGraph { get: (key: K) => NonNullable; set: (key: K | Partial, value?: T[K]) => IGraph; /** * 设置视图初始化数据 * @param {GraphData} data 初始化数据 */ data: (data?: GraphData) => void; /** * 获取当前图中所有节点的item实例 */ getNodes: () => any[]; /** * 获取当前图中所有边的item实例 */ getEdges: () => any[]; /** * 改变画布大小 * @param {number} width 画布宽度 * @param {number} height 画布高度 * @return {Graph} this */ changeSize: (width: number, height: number) => IGraph; /** * 获取当前视口伸缩比例 * @return {number} 比例 */ getZoom: () => number; /** * 监听函数 */ on: (eventName: GEventName, callback: (e: T) => void, once?: boolean) => this; /** * 移除指定的监听函数 */ off: (eventName: GEventName, callback: (e: T) => void, once?: boolean) => this; emit: (evt: string, ...args: any[]) => this; findById: (id: string) => IItem; /** * 根据data接口的数据渲染视图 */ render: () => void; /** * 新增元素 * @param {string} type 元素类型(node | edge) * @param {ModelConfig} model 元素数据模型 * @return {IItem | boolean} 元素实例 */ addItem: (type: ITEM_TYPE, model: ModelConfig, stack?: boolean, sortCombo?: boolean) => IItem | boolean; /** * Adds multiple items with a single operation * @param {{type: ITEM_TYPE, model: ModelConfig}[]} items Items to be added to the graph * @return {(IItem | boolean)[]} Instance of the added items or a boolean set to false to signal that the input node was not added */ addItems: (items: { type: ITEM_TYPE; model: ModelConfig; }[]) => (IItem | boolean)[]; /** * 设置元素状态 * @param {IItem} item 元素id或元素实例 * @param {string} state 状态名称 * @param {boolean} value 是否启用状态或状态值 */ setItemState: (item: IItem | string, state: string, value: string | boolean) => void; /** * 清理元素多个状态 * @param {string|IItem} item 元素id或元素实例 * @param {string | string[]} states 状态 */ clearItemStates: (item: IItem | string, states?: string | string[]) => void; /** * 更新元素 * @param {IItem} item 元素id或元素实例 * @param {EdgeConfig | NodeConfig} cfg 需要更新的数据 */ updateItem: (item: IItem | string, cfg: Partial | EdgeConfig, updateType?: UpdateType) => void; /** * 自动重绘 */ autoPaint: () => void; /** * 仅画布重新绘制 */ paint: () => void; /** * 设置是否在更新/刷新后自动重绘 * @param {boolean} auto 自动重绘 */ setAutoPaint: (auto: boolean) => void; /** * 清除画布元素 */ clear: (avoidEmit?: boolean) => IGraph; /** * 销毁画布 */ destroy: () => void; translate: (dx: number, dy: number) => void; zoom: (zoom: number, center?: IPoint, min?: number, max?: number) => void; fitCenter: () => void; fitView: () => void; setCanvasDraggable: (draggable: boolean) => void; setCanvasWheelZoom: (zoomable: boolean) => void; } interface LayoutConfig { type?: string; [key: string]: unknown; } interface IGroupOptions { /** * 图的 DOM 容器,可以传入该 DOM 的 id 或者直接传入容器的 HTML 节点对象 */ container: string | HTMLElement; layout?: LayoutConfig; data?: GraphData; /** * 指定画布宽度,单位为 'px',可选,默认为容器宽度 */ width?: number; /** * 指定画布高度,单位为 'px',可选,默认为容器宽度 */ height?: number; fitView?: boolean; fitCenter?: boolean; /** * 当图中元素更新,或视口变换时,是否自动重绘。建议在批量操作节点时关闭,以提高性能,完成批量操作后再打开,参见后面的 setAutoPaint() 方法。 * 默认值:true */ autoPaint?: boolean; /** * 默认状态下节点的配置,比如 type, size, color。会被写入的 data 覆盖。 */ defaultNode?: Partial<{ type: string; size: number | number[]; color: string; }> & ModelStyle; /** * 默认状态下边的配置,比如 type, size, color。会被写入的 data 覆盖。 */ defaultEdge?: Partial<{ type: string; size: number | number[]; color: string; }> & ModelStyle; /** * 最小缩放比例 * 默认值 0.2 */ minZoom?: number; /** * 最大缩放比例 * 默认值 10 */ maxZoom?: number; /** * 画布是否支持拖拽,默认false */ canvasDraggable?: boolean; /** * 画布是否支持鼠标滚轮缩放 */ canvasWheelZoom?: boolean; /** * 行为模式 */ behaviors?: BehaviorConfig[]; } interface IPriveteGroupOptions extends IGroupOptions { canvas: Canvas; emitter: EventEmitter; states: States; viewController: ViewController; itemController: ItemController; stateController: StateController; layoutController: LayoutController; eventController: EventController; group: Group; itemMap: ItemMap; nodes: INode[]; edges: IEdge[]; destroyed: boolean; zoom: number; } declare class Graph implements IGraph { protected cfg: IGroupOptions & { [key: string]: any; }; constructor(cfg: IGroupOptions); protected init(): void; protected initGroup(): void; protected initCanvas(): null; on(eventName: GEventName, callback: (e: T) => void, once?: boolean | undefined): this; off(eventName: GEventName, callback: (e: T) => void, once?: boolean | undefined): this; emit(evt: string, ...args: any[]): this; /** * 获取当前图中所有节点的item实例 * @return {INode} item数组 */ getNodes(): INode[]; /** * 获取当前图中所有边的item实例 * @return {IEdge} item数组 */ getEdges(): IEdge[]; /** * 设置视图初始化数据 * @param {GraphData} data 初始化数据 */ data(data?: GraphData): void; render(): void; addItem: (type: ITEM_TYPE, model: ModelConfig) => IItem | boolean; addItems(items: { type: ITEM_TYPE; model: ModelConfig; }[]): (IItem | boolean)[]; /** * 获取 this.cfg 中的值 * @param key 键 */ get(key: string): any; /** * 将值设置到 this.cfg 变量上面 * @param key 键 或 对象值 * @param val 值 */ set(key: string | object, val?: T): Graph; /** * 设置元素状态 * @param {IItem} item 元素id或元素实例 * @param {string} state 状态名称 * @param {string | boolean} value 是否启用状态 或 状态值 */ setItemState(item: IItem | string, state: string, value: string | boolean): void; /** * 清理元素多个状态 * @param {string|IItem} item 元素id或元素实例 * @param {string[]} states 状态 */ clearItemStates(item: IItem | string, states?: string[] | string): void; /** * 更新元素 * @param {IItem} item 元素id或元素实例 * @param {Partial | EdgeConfig} cfg 需要更新的数据 */ updateItem(item: IItem | string, cfg: Partial | EdgeConfig, updateType?: UpdateType): void; /** * 自动重绘 * @internal 仅供内部更新机制调用,外部根据需求调用 render 或 paint 接口 */ autoPaint(): void; /** * 设置是否在更新/刷新后自动重绘 * @param {boolean} auto 自动重绘 */ setAutoPaint(auto: boolean): void; /** * 仅画布重新绘制 */ paint(): void; getDefaultCfg(): Partial; /** * 根据 ID 查询图元素实例 * @param id 图元素 ID */ findById(id: string): IItem; /** * 伸缩窗口 * @param zoom * @param center 以center的x, y坐标为中心缩放 */ zoom(zoom: number, center?: IPoint, min?: number, max?: number): void; /** * 平移画布 * @param dx 水平方向位移 * @param dy 垂直方向位移 */ translate(dx: number, dy: number): void; /** * Move the graph to destination under viewport coordinates. * @param destination destination under viewport coordinates. * @param effectTiming animation configurations */ translateTo(dx: number, dy: number): Promise; changeSize(width: number, height: number): this; getZoom(): any; /** * Fit the graph center to the view center. */ fitCenter(): Promise; /** * Fit the graph content to the view. */ fitView(): void; /** * 销毁画布 */ destroy(): void; /** * 清除画布元素 * @return {object} this */ clear(avoidEmit?: boolean): IGraph; getViewportCenter(): IPoint; setCanvasDraggable(draggable: boolean): void; setCanvasWheelZoom(zoomable: boolean): void; private innerAddItem; } declare const Arrow: { triangle: (width?: number, length?: number, d?: number) => string; }; declare class Shape { static Node: any; static Edge: any; static Combo: any; static registerFactory(factoryType: string, cfg: object): object; static getFactory(factoryType: string): any; static registerNode(shapeType: string, nodeDefinition: ShapeOptions, extendShapeType?: string): any; static registerEdge(shapeType: string, edgeDefinition: ShapeOptions, extendShapeType?: string): any; } declare const GLOBAL: { defaultNode: { type: string; size: number; style: { lineWidth: number; stroke: string; fill: string; color: string; rx: number; ry: number; }; }; defaultEdge: { type: string; style: { lineWidth: number; stroke: string; lineAppendWidth: number; color: string; }; }; defaultArrow: { markerEndOffset: number; markerStartOffset: number; style: { path: string; stroke: string; fill: string; anchor: string; transformOrigin: string; }; }; }; declare type Engine = 'circo' | 'dot' | 'fdp' | 'sfdp' | 'neato' | 'osage' | 'patchwork' | 'twopi'; export { Arrow, Circle, DisplayObject, EdgeConfig, Engine, GLOBAL, Graph, Group, IAnimation, IEdge, INode, Image, Line, ModelConfig, NodeConfig, Path, Rect, Shape, ShapeOptions, Text };