import type { BaseCollectorReducerAction, INormalPushMsg, ISerializableStorageData } from "../collector/types";
import type { ETextEditorType, FontStyleType, FontWeightType, TextOptions } from "../component/textEditor/types";
import type { EmitEventType } from "../plugin/types";
import type { ECanvasContextType, ECanvasShowType, EDataType, EPostMessageType, ESVGType, EScaleType, EToolsKey, ElayerType, EventWorkState } from "./enum";
import type { BaseShapeOptions, BaseShapeTool, ShapeOptions } from "./tools";
import type { SelectorShape } from "./tools";
import type { Direction } from "re-resizable/lib/resizer";
import type { ShapeOptType } from "../displayer/types";
import type { AutoShapeResult } from "./autoShape/types";
export type PickOne<T> = {
    [P in keyof T]: Record<P, T[P]> & Partial<Record<Exclude<keyof T, P>, undefined>>;
}[keyof T];
export type IworkId = string | number;
export type IqueryTask = Partial<IWorkerMessage> | undefined;
export type ViewWorkerOptions = {
    offscreenCanvasOpt: IOffscreenCanvasOptionType;
    layerOpt: ILayerOptionType;
    dpr: number;
    originalPoint: [number, number];
    cameraOpt: ICameraOpt;
    transferOffscreenCanvas?: {
        bgCanvas: OffscreenCanvas;
        serviceCanvas: OffscreenCanvas;
        localCanvas: OffscreenCanvas;
    };
};
export interface ICanvasSceneType {
    /** canvas 上下文 */
    /** canvas 宽度 */
    width: number;
    /** canvas 高度 */
    height: number;
    /** canvas */
    canvas: HTMLCanvasElement;
}
export interface IOffscreenCanvasOptionType {
    /** offscreenCanvas 宽度 */
    width: number;
    /** offscreenCanvas 高度 */
    height: number;
    /** 上下文类型 */
    contextType?: ECanvasContextType;
    /** 是否自动渲染,默认自动渲染 */
    autoRender?: boolean;
    /** 缓冲区大小，默认1500 */
    bufferSize?: number;
    [key: string]: any;
}
export interface ILayerOptionType {
    canvas?: OffscreenCanvas;
    offscreen?: boolean;
    handleEvent?: boolean;
    depth?: boolean;
    width: number;
    height: number;
    bufferSize?: number;
    contextType?: ECanvasContextType;
    [key: string]: any;
}
export interface IUpdateNodeOpt {
    scale?: [number, number];
    box?: {
        x: number;
        y: number;
        w: number;
        h: number;
    };
    dir?: Direction;
    translate?: [number, number];
    selectorColor?: string;
    strokeColor?: string;
    fillColor?: string;
    fontColor?: string;
    fontBgColor?: string;
    isOpacity?: boolean;
    pos?: [number, number];
    workState?: EventWorkState;
    useAnimation?: boolean;
    zIndex?: number;
    zIndexForBackgroundSVG?: number;
    zIndexLayer?: ElayerType;
    originPos?: [number, number];
    ops?: string;
    angle?: number;
    centralPoint?: [number, number];
    selectScale?: number[];
    bold?: FontWeightType;
    italic?: FontStyleType;
    underline?: boolean;
    lineThrough?: boolean;
    fontSize?: number;
    pointMap?: Map<string, [number, number][]>;
    textInfos?: Map<string, Partial<TextOptions>>;
    isLocked?: boolean;
    toolsType?: EToolsKey;
    willRefresh?: boolean;
    /** 最新操作用户 */
    uid?: string;
    [key: string]: any;
}
export type IWorkerMessage = Omit<Partial<BaseCollectorReducerAction>, "op"> & {
    viewId: string;
    msgType: EPostMessageType;
    dataType: EDataType;
    scenePath?: string;
    workState?: EventWorkState;
    op?: number[];
    offscreenCanvasOpt?: IOffscreenCanvasOptionType;
    dpr?: number;
    vertex?: string;
    fragment?: string;
    workId?: IworkId;
    workOption?: BaseShapeOptions;
    toolsType?: EToolsKey;
    uid?: string;
    cameraOpt?: ICameraOpt;
    translate?: [number, number];
    scale?: number;
    currentToolsData?: IActiveToolsDataType;
    updateNodeOpt?: IUpdateNodeOpt;
    layerOpt?: ILayerOptionType;
    useAnimation?: boolean;
    willRefreshSelector?: boolean;
    willSyncService?: boolean;
    willRefresh?: boolean;
    isActiveZIndex?: boolean;
    selectStore?: Map<string, {
        ops?: string;
        opt?: BaseShapeOptions;
        updateNodeOpt?: IUpdateNodeOpt;
    }>;
    willSerializeData?: boolean;
    isRunSubWork?: boolean;
    scenes?: ISerializableStorageData;
    textType?: ETextEditorType;
    mainTasksqueueCount?: number;
    textUpdateForWoker?: boolean;
    tasksqueue?: Map<string, IWorkerMessage>;
    point?: [number, number];
    disableEraseImage?: boolean;
    disableEraseText?: boolean;
    maxCombineEraserTime?: number;
    /** 平滑同步 */
    smoothSync?: boolean;
    /** 是否使用单一worker模式 */
    isUseSimple?: boolean;
    /** 离屏canvas */
    offscreenCanvas?: {
        localCanvas: OffscreenCanvas;
        bgCanvas: OffscreenCanvas;
        serviceCanvas: OffscreenCanvas;
    };
    /** 字体库 */
    fontBuffers?: {
        fontFamily: string;
        buffer: ArrayBuffer;
    }[];
    isRunBackgroundThread?: boolean;
    /** 直接提交 FullWork 时，清理本地铅笔预览层 */
    clearPreviewLocalWork?: boolean;
    /** auto-shape 的识别结果，仅用于内部调试/日志 */
    autoShapeResult?: AutoShapeResult;
    [key: string]: any;
};
export interface IRectType {
    x: number;
    y: number;
    w: number;
    h: number;
}
export interface IMainMessage extends INormalPushMsg {
    type: EPostMessageType;
    dataType?: EDataType;
    imageBitmap?: ImageBitmap | OffscreenCanvas;
    rect?: IRectType;
    dpr?: number;
    translate?: [number, number];
    scale?: number;
    removeIds?: Array<string>;
    /** 是否是完整的一次任务 */
    isFullWork?: boolean;
    selectIds?: Array<string>;
    padding?: number;
    selectRect?: IRectType;
    selectorColor?: string;
    strokeColor?: string;
    fillColor?: string;
    isOpacity?: boolean;
    updateNodeOpts?: Map<string, IUpdateNodeOpt>;
    willSyncService?: boolean;
    newWorkDatas?: Map<string, {
        op: number[];
        opt: BaseShapeOptions;
        workId: IworkId;
        toolsType: EToolsKey;
    }>;
    scenePath?: string;
    canvasWidth?: number;
    canvasHeight?: number;
    workState?: EventWorkState;
    canTextEdit?: boolean;
    canRotate?: boolean;
    canLock?: boolean;
    scaleType?: EScaleType;
    textOpt?: TextOptions;
    viewId?: string;
    points?: [number, number][];
    isRefresh?: boolean;
    renderRect?: IRectType;
    isLocked?: boolean;
    shapeOpt?: ShapeOptType;
    toolsTypes?: EToolsKey[];
    isLockSentEventCursor?: boolean;
    nextTasks?: IMainMessage[];
    setFontFaceResult?: boolean;
    needUndoTicker?: number;
    clearPreviewLocalWork?: boolean;
    autoShapeResult?: AutoShapeResult;
    [key: string]: any;
}
export interface IMainMessageRenderData {
    viewId: string;
    rect?: IRectType;
    imageBitmap?: ImageBitmap;
    isDrawAll?: boolean;
    drawCanvas?: ECanvasShowType;
    isClear?: boolean;
    isClearAll?: boolean;
    clearCanvas?: ECanvasShowType;
    /** 是否需要销毁imageBitmap */
    isUnClose?: boolean;
    workerType?: EDataType.Local | EDataType.Service;
    offset?: {
        x: number;
        y: number;
    };
    translate?: [number, number];
    workId?: string;
}
export interface IBatchMainMessage {
    /** 绘制数据 */
    render?: Array<IMainMessageRenderData>;
    /** 同步服务端数据 */
    sp?: Array<IMainMessage>;
    workerTasksqueueCount?: number;
    workIds?: Set<string>;
    viewId?: string;
    consumeCount?: number;
    subWorkerDrawCount?: number;
    fullWorkerDrawCount?: number;
}
export interface ICameraOpt {
    centerX: number;
    centerY: number;
    scale: number;
    width: number;
    height: number;
}
export interface IUpdateSelectorPropsType {
    updateSelectorOpt: IUpdateNodeOpt;
    willRefreshSelector?: boolean;
    willSyncService?: boolean;
    willSerializeData?: boolean;
    emitEventType?: EmitEventType;
    isSync?: boolean;
    textUpdateForWoker?: boolean;
    /** 平滑同步 */
    smoothSync?: boolean;
    /** 记录撤销重做id */
    needUndoTicker?: number;
}
export interface IUpdateSelectorCallbackPropsType {
    res?: IMainMessage;
    param: IUpdateSelectorPropsType;
    postData: Pick<IBatchMainMessage, "sp" | "render">;
    workShapeNode: SelectorShape;
    newServiceStore: Map<string, {
        opt: BaseShapeOptions;
        toolsType: EToolsKey;
        ops?: string;
    }>;
    /** 平滑同步 */
    smoothSync?: boolean;
}
export interface IActiveToolsDataType {
    toolsType: EToolsKey;
    toolsOpt: ShapeOptions;
    combineUnitTime?: number;
    maxCombineEraserTime?: number;
}
export interface IActiveWorkDataType {
    workState: EventWorkState;
    toolsOpt?: ShapeOptions;
    viewId?: string;
    workId?: IworkId;
}
export type IServiceWorkItem = {
    toolsType: EToolsKey;
    animationWorkData?: number[];
    animationIndex?: number;
    type: EPostMessageType;
    node?: BaseShapeTool;
    updateNodeOpt?: IUpdateNodeOpt;
    ops?: string;
    isDel?: boolean;
    timer?: number;
    useAnimation?: boolean;
    bindSelector?: string;
    selectIds?: string[];
    oldRect?: IRectType;
    totalRect?: IRectType;
    isDiff?: boolean;
    imageBitmap?: ImageBitmap;
    isEnableCursor?: boolean;
};
export type ILocalWorkItem = {
    toolsType: EToolsKey;
    node: BaseShapeTool;
    data?: IWorkerMessage;
    result?: IMainMessage;
    totalRect?: IRectType;
    workState: EventWorkState;
    isDel?: boolean;
    willRefresh?: boolean;
};
export type BaseNodeMapItem = {
    name: string;
    rect: IRectType;
    op: number[];
    opt: BaseShapeOptions;
    centerPos: [number, number];
    toolsType: EToolsKey;
    canRotate: boolean;
    scaleType: EScaleType;
    /** 是否被框选中,框选中的元素不能被其它人操作 */
    isSelected: boolean;
    /** 是否是影子模型,影子模型不会被绘制 */
    isShadow?: boolean;
};
export type Size = {
    /**
     * 宽
     */
    width: number;
    /**
     * 高
     */
    height: number;
};
export type Rectangle = Size & {
    /**
     * 矩形的左上角 x 坐标
     */
    originX: number;
    /**
     * 矩形的左上角 y 坐标
     */
    originY: number;
};
export interface ISVGBaseOptions extends BaseShapeOptions {
    /** 图片的唯一识别符 */
    uuid: string;
    /** 图片中点在世界坐标系中的 x 坐标 */
    centerX: number;
    /** 图片中点在世界坐标系中的 y 坐标 */
    centerY: number;
    /** 图片中点在世界坐标系中的宽 */
    width: number;
    /** 图片中点在世界坐标系中的高 */
    height: number;
    /** 图片是否被锁定 */
    locked: boolean;
    /** 图片是否禁止非等比放缩 */
    uniformScale: boolean;
    /** 内部 状态数据 */
    state?: unknown;
}
export interface ISVGUrlOptions extends ISVGBaseOptions {
    type: ESVGType.url;
    /** svg 源 url, 必须为 http 或 https 协议 */
    src: string;
    /** 是否以跨域方式加载图片 */
    crossOrigin: boolean | string;
}
export interface ISVGMarkmapOptions extends ISVGBaseOptions {
    type: ESVGType.markmap;
    /** markdown 数据 tostring */
    data: string;
}
export type ISVGOptions = ISVGUrlOptions | ISVGMarkmapOptions;
