graphic-pixi/lib/app/JlGraphicApp.d.ts

602 lines
16 KiB
TypeScript
Raw Normal View History

2023-12-12 17:31:07 +08:00
/// <reference types="node" />
import EventEmitter from 'eventemitter3';
import { Viewport } from 'pixi-viewport';
import { Application, Container, DisplayObject, Graphics, Point } from 'pixi.js';
import { GraphicQueryStore } from '../core/GraphicStore';
import { GraphicData, GraphicState, GraphicTemplate, GraphicTransform, JlGraphic } from '../core/JlGraphic';
import { AbsorbablePosition } from '../graphic';
import { AppWsMsgBroker, GraphicQuery, ICreateOnNotFound, type AppStateSubscription, type MessageCliOption } from '../message';
import { OperationRecord } from '../operation/JlOperation';
import { AnimationManager, IMouseToolOptions } from '../plugins';
import { GraphicCopyPlugin } from '../plugins/CopyPlugin';
import { AppDragEvent, InteractionPlugin } from '../plugins/InteractionPlugin';
import { JlGraphicAppKeyboardPlugin, KeyListener } from '../plugins/KeyboardPlugin';
import { ContextMenu, ContextMenuPlugin } from '../ui/ContextMenu';
import { MenuItemOptions } from '../ui/Menu';
export declare const AppConsts: {
viewportname: string;
canvasname: string;
AssistantAppendsName: string;
assistantElementColor: string;
};
/**
*
*/
export interface ICanvasProperties {
width: number;
height: number;
backgroundColor: string;
viewportTransform: GraphicTransform;
}
export declare class CanvasData implements ICanvasProperties {
width: number;
height: number;
backgroundColor: string;
viewportTransform: GraphicTransform;
constructor(properties?: ICanvasProperties);
copyFrom(properties: ICanvasProperties): boolean;
clone(): CanvasData;
}
export interface IJlCanvas extends Container {
/**
*
*/
get properties(): ICanvasProperties;
/**
*
*/
get scene(): IGraphicScene;
/**
*
* @param properties
*/
update(properties: ICanvasProperties): void;
/**
*
* @param appends
*/
addAssistantAppends(...appends: DisplayObject[]): void;
/**
*
* @param appends
*/
removeAssistantAppends(...appends: DisplayObject[]): void;
/**
*
*/
saveData(): ICanvasProperties;
}
export declare class JlCanvas extends Container implements IJlCanvas {
__JlCanvas: boolean;
type: string;
scene: IGraphicScene;
_properties: CanvasData;
bg: Graphics;
nonInteractiveContainer: Container;
assistantAppendContainer: Container;
constructor(scene: IGraphicScene, properties?: CanvasData);
/**
* /
*/
repaint(): void;
get width(): number;
get height(): number;
get backgroundColor(): string;
doRepaint(): void;
get properties(): CanvasData;
saveData(): CanvasData;
update(properties: ICanvasProperties): void;
addChild<U extends DisplayObject[]>(...children: U): U[0];
removeChild<U extends DisplayObject[]>(...children: U): U[0];
/**
* Child
*/
addNonInteractiveChild(...obj: DisplayObject[]): void;
removeGraphic(...obj: DisplayObject[]): void;
/**
* Child
*/
removeNonInteractiveChild(...obj: DisplayObject[]): void;
addAssistantAppends(...appends: DisplayObject[]): void;
removeAssistantAppends(...appends: DisplayObject[]): void;
/**
*
*/
pauseInteractiveChildren(): void;
/**
*
*/
resumeInteractiveChildren(): void;
}
/**
*
*/
export declare class SelectedChangeEvent {
graphic: JlGraphic;
select: boolean;
constructor(graphic: JlGraphic, select: boolean);
}
/**
*
*/
export interface GraphicAppEvents extends GlobalMixins.GraphicAppEvents {
graphicstored: [graphic: JlGraphic];
graphicdeleted: [graphic: JlGraphic];
postdataloaded: [];
loadfinish: [];
'interaction-plugin-resume': [plugin: InteractionPlugin];
'interaction-plugin-pause': [plugin: InteractionPlugin];
'options-update': [options: GraphicAppOptions];
graphicselectedchange: [graphic: JlGraphic, selected: boolean];
graphicchildselectedchange: [child: DisplayObject, selected: boolean];
graphicselected: [graphics: JlGraphic[]];
'viewport-scaled': [vp: Viewport];
drag_op_start: [event: AppDragEvent];
drag_op_move: [event: AppDragEvent];
drag_op_end: [event: AppDragEvent];
'pre-menu-handle': [menu: MenuItemOptions];
'post-menu-handle': [menu: MenuItemOptions];
'websocket-connect-state-change': [connected: boolean];
'websocket-error': [err: Error];
destroy: [app: IGraphicApp];
}
/**
*
*/
export interface IGraphicStorage {
/**
*
*/
canvasProperty?: ICanvasProperties;
/**
*
*/
datas: GraphicData[];
}
/**
* App构造参数
*/
export interface IGraphicAppConfig {
/**
*
* @returns
*/
dataLoader?: () => Promise<IGraphicStorage>;
/**
* 100
*/
maxOperationRecords?: number;
/**
*
*/
threshold?: number;
/**
*
*/
mouseToolOptions?: IMouseToolOptions;
/**
*
*/
absorbablePositions?: AbsorbablePosition[];
/**
* true
*/
cullable?: boolean;
/**
*
*/
isSupportDeletion?: (g: JlGraphic) => boolean;
/**
* ,
*/
assistantElementColor?: string;
}
/**
*
*/
export interface IInteractiveGraphicOptions {
/**
* Excludes同时只能存在一个
*/
interactiveGraphicTypeIncludes?: string[];
/**
* Includes同时只能存在一个
*/
interactiveGraphicTypeExcludes?: string[];
}
export type GraphicAppOptions = IGraphicAppConfig & IInteractiveGraphicOptions;
/**
*
*/
export interface IGraphicScene extends EventEmitter<GraphicAppEvents> {
/**
*
*/
get app(): GraphicApp;
/**
* pixijs应用对象
*/
get pixi(): Application;
/**
*
*/
get viewport(): Viewport;
/**
*
*/
get canvas(): IJlCanvas;
/**
* dom
*/
get dom(): HTMLElement | undefined;
/**
*
*/
get queryStore(): GraphicQueryStore;
/**
*
*/
get selectedGraphics(): JlGraphic[];
/**
*
*/
get animationManager(): AnimationManager;
/**
*
*/
get appOptions(): GraphicAppOptions;
/**
*
* @param options
*/
setOptions(options: GraphicAppOptions): void;
/**
*
* @param menu
*/
registerMenu(menu: ContextMenu): void;
/**
*
* @param p
*/
toCanvasCoordinates(p: Point): Point;
/**
* /()
*/
reload(): Promise<void>;
/**
*
*/
forceReload(): Promise<void>;
/**
* dom
* @param dom
*/
bindDom(dom: HTMLElement): void;
/**
* dom节点移除
*/
unbindDom(): void;
/**
*
* @param graphicTemplates
*/
registerGraphicTemplates(...graphicTemplates: GraphicTemplate[]): void;
/**
*
* @param graphicStates
*/
handleGraphicStates(graphicStates: GraphicState[], queryer?: GraphicQuery, createOnNotFound?: ICreateOnNotFound): void;
/**
*
* @param type
*/
getGraphicTemplatesByType<GT extends GraphicTemplate>(type: string): GT;
/**
*
* @param graphics
*/
addGraphics(...graphics: JlGraphic[]): void;
/**
*
* @param graphics
*/
deleteGraphics(...graphics: JlGraphic[]): JlGraphic[];
/**
*
*/
detectRelations(): void;
/**
*
* @param plugins
*/
registerInteractionPlugin(...plugins: InteractionPlugin[]): void;
/**
*
*/
pauseAppInteractionPlugins(): void;
/**
* name获取交互插件
* @param name
*/
interactionPlugin<P = InteractionPlugin>(name: string): P;
/**
*
* @param graphics
*/
updateSelected(...graphics: JlGraphic[]): void;
/**
*
*/
selectAllGraphics(): void;
/**
* 使
* @param group
*/
makeGraphicCenterShow(...group: JlGraphic[]): void;
/**
*
*/
destroy(): void;
/**
* websocket消息
*/
subscribe(sub: AppStateSubscription): void;
/**
* websocket订阅
*/
unsubscribe(destination: string): void;
}
declare abstract class GraphicSceneBase extends EventEmitter<GraphicAppEvents> implements IGraphicScene {
private graphicStore;
_options: GraphicAppOptions;
pixi: Application;
viewport: Viewport;
canvas: JlCanvas;
_loaded: boolean;
_dom?: HTMLElement;
_viewportResizer?: NodeJS.Timeout;
graphicTemplateMap: Map<string, GraphicTemplate>;
interactionPluginMap: Map<string, InteractionPlugin>;
graphicCopyPlugin: GraphicCopyPlugin;
animationManager: AnimationManager;
menuPlugin: ContextMenuPlugin;
private debounceEmitFunc;
wsMsgBroker: AppWsMsgBroker;
constructor(options: GraphicAppOptions);
get appOptions(): GraphicAppOptions;
abstract get app(): GraphicApp;
get dom(): HTMLElement | undefined;
get queryStore(): GraphicQueryStore;
get selectedGraphics(): JlGraphic[];
private load;
/**
*
*/
reload(): Promise<void>;
forceReload(): Promise<void>;
/**
*
* @param options
*/
setOptions(options: GraphicAppOptions): void;
toCanvasCoordinates(p: Point): Point;
/**
*
* @param menu
*/
registerMenu(menu: ContextMenu): void;
/**
*
* @param graphicTemplates
*/
registerGraphicTemplates(...graphicTemplates: GraphicTemplate[]): void;
getGraphicTemplatesByType<GT extends GraphicTemplate>(type: string): GT;
private updateViewport;
/**
*
*/
private pause;
/**
*
*/
private resume;
bindDom(dom: HTMLElement): void;
unbindDom(): void;
/**
* ,GraphicApp默认添加到无交互容器,DrawApp默认添加到交互容器,
* @param protos
* @param options /
*/
loadGraphic(protos: GraphicData[]): Promise<void>;
/**
*
* @param graphic
*/
beforeGraphicStore(graphic: JlGraphic): void;
/**
*
* @param graphic
*/
private doAddGraphics;
private doDeleteGraphics;
/**
*
* @param graphics
*/
addGraphics(...graphics: JlGraphic[]): void;
/**
*
* @param graphics
*/
deleteGraphics(...graphics: JlGraphic[]): JlGraphic[];
/**
*
*/
detectRelations(): void;
/**
*
*/
selectAllGraphics(filter?: (g: JlGraphic) => boolean): void;
/**
*
*/
updateSelected(...graphics: JlGraphic[]): void;
private doEmitAppGraphicSelected;
/**
*
* @param param
*/
updateCanvas(param: ICanvasProperties): void;
/**
* 使()
*/
makeGraphicCenterShow(...group: JlGraphic[]): void;
/**
* ,
*/
registerInteractionPlugin(...plugins: InteractionPlugin[]): void;
/**
*
* @param name
* @returns
*/
interactionPlugin<P = InteractionPlugin>(name: string): P;
/**
*
*/
pauseAppInteractionPlugins(): void;
private doPauseInteractionPlugin;
/**
*
*/
removeInteractionPlugin(plugin: InteractionPlugin): void;
private checkWsMsgCli;
/**
* websocket消息
*/
subscribe(sub: AppStateSubscription): void;
/**
* websocket订阅
*/
unsubscribe(destination: string): void;
/**
*
* @param graphicStates
*/
handleGraphicStates(graphicStates: GraphicState[], queryer?: GraphicQuery, createOnNotFound?: ICreateOnNotFound): void;
/**
*
*/
destroy(): void;
}
/**
*
*/
export interface IGraphicApp extends IGraphicScene {
get opRecord(): OperationRecord;
/**
*
* @param code
* @returns
*/
initScene(code: string, options: GraphicAppOptions): IGraphicScene;
/**
*
* @param code
* @returns
*/
getScene(code: string): IGraphicScene;
/**
*
* @param dom
*/
switchScene(code: string, dom: HTMLElement): void;
/**
* code场景
* @param code
*/
removeScene(code: string): void;
/**
*
* @param graphics
*/
addGraphicAndRecord(...graphics: JlGraphic[]): void;
/**
*
* @param graphics
*/
deleteGraphicAndRecord(...graphics: JlGraphic[]): void;
/**
* websocket消息客户端
*/
enableWsMassaging(options: MessageCliOption): void;
/**
* ,
* @param keyListeners
*/
addKeyboardListener(...keyListeners: KeyListener[]): void;
/**
*
* @param keyListeners
*/
removeKeyboardListener(...keyListeners: KeyListener[]): void;
}
/**
* app基类
*/
export declare class GraphicApp extends GraphicSceneBase implements IGraphicApp {
/**
*
*/
scenes: Map<string, JlScene>;
opRecord: OperationRecord;
keyboardPlugin: JlGraphicAppKeyboardPlugin;
constructor(options: GraphicAppOptions);
get app(): GraphicApp;
setOptions(options: GraphicAppOptions): void;
addGraphicAndRecord(...graphics: JlGraphic[]): void;
deleteGraphicAndRecord(...graphics: JlGraphic[]): void;
/**
*
* @param code
* @returns
*/
initScene(code: string, options: GraphicAppOptions): IGraphicScene;
/**
*
* @param code
* @returns
*/
getScene(code: string): IGraphicScene;
switchScene(code: string, dom: HTMLElement): void;
removeScene(code: string): void;
/**
* websocket消息客户端
*/
enableWsMassaging(options: MessageCliOption): void;
/**
* ,
* @param keyListeners
*/
addKeyboardListener(...keyListeners: KeyListener[]): void;
/**
*
* @param keyListeners
*/
removeKeyboardListener(...keyListeners: KeyListener[]): void;
/**
*
*/
destroy(): void;
}
/**
*
*/
export default class JlScene extends GraphicSceneBase {
code: string;
app: GraphicApp;
constructor(app: GraphicApp, code: string, options: GraphicAppOptions);
}
export {};