@visactor/vrender-core
Version:
```typescript import { xxx } from '@visactor/vrender-core'; ```
331 lines (330 loc) • 18.1 kB
TypeScript
import type { ICustomPath2D } from './../interface/path';
import { Matrix, Point, type Dict, type IAABBBounds, type IOBBBounds, type IPointLike } from '@visactor/vutils';
import type { GraphicType, IAnimateConfig, IGraphicAttribute, IGraphic, IGraphicJson, ISetAttributeContext, ISetStatesOptions, ITransform, GraphicReleaseStatus } from '../interface/graphic';
import { Node } from './node-tree';
import type { IAnimate, IAnimateTarget, IGlyphGraphicAttribute, ILayer, IPickerService, IShadowRoot, IStage, IStep, ISymbolClass } from '../interface';
import { IContainPointMode } from '../common/enums';
import { CustomSymbolClass } from './builtin-symbol';
import type { CompiledStateDefinition, StateDefinition, StateDefinitionsInput, StateMergeMode, StateTransitionResult } from './state/state-definition';
import { StateEngine } from './state/state-engine';
import { UpdateCategory } from './state/attribute-update-classifier';
import { StateTransitionOrchestrator } from './state/state-transition-orchestrator';
import { type SharedStateScope } from './state/shared-state-scope';
export declare const PURE_STYLE_KEY: string[];
export declare const GRAPHIC_UPDATE_TAG_KEY: string[];
type AttributeDelta = Map<string, {
prev: unknown;
next: unknown;
}>;
type GraphicStateTransition = {
changed: boolean;
states: string[];
effectiveStates?: string[];
};
type ResolvedGraphicStateTransition<T> = {
transition: GraphicStateTransition;
effectiveStates: string[];
resolvedStateAttrs: Partial<T>;
};
type ExcludedAttributeKeys = Record<string, true>;
export declare const NOWORK_ANIMATE_ATTR: {
strokeSeg: number;
boundsPadding: number;
pickMode: number;
boundsMode: number;
customPickShape: number;
pickable: number;
childrenPickable: number;
visible: number;
zIndex: number;
layout: number;
keepDirIn3d: number;
globalZIndex: number;
outerBorder: number;
innerBorder: number;
lineDash: number;
lineCap: number;
lineJoin: number;
miterLimit: number;
strokeBoundsBuffer: number;
scaleCenter: number;
anchor: number;
anchor3d: number;
postMatrix: number;
backgroundMode: number;
background: number;
texture: number;
cursor: number;
html: number;
};
declare abstract class GraphicImpl<T extends Partial<IGraphicAttribute> = Partial<IGraphicAttribute>> extends Node implements IGraphic<T>, IAnimateTarget {
static mixin(source: Dict<any>): void;
_events?: any;
context?: Record<string, any>;
private transientFromAttrsBeforePreventAnimate?;
private transientFromAttrsBeforePreventAnimateDiffAttrs?;
static userSymbolMap: Record<string, ISymbolClass>;
onBeforeAttributeUpdate?: (val: any, attributes: Partial<T>, key: null | string | string[], context?: ISetAttributeContext) => T | undefined;
parent: any;
resources?: Map<string | HTMLImageElement | HTMLCanvasElement, {
state: 'init' | 'loading' | 'success' | 'fail';
data?: HTMLImageElement | HTMLCanvasElement;
}>;
backgroundImg?: boolean;
type: GraphicType;
prefixed: string;
numberType: number;
isContainer?: boolean;
valid: boolean;
stage?: IStage;
layer?: ILayer;
incremental?: number;
glyphHost?: IGraphic<IGlyphGraphicAttribute>;
_onSetStage?: (g: IGraphic, stage: IStage, layer: ILayer) => void;
in3dMode?: boolean;
widthWithoutTransform?: number;
heightWithoutTransform?: number;
x1WithoutTransform?: number;
y1WithoutTransform?: number;
protected _AABBBounds: IAABBBounds;
get AABBBounds(): IAABBBounds;
protected _OBBBounds?: IOBBBounds;
get OBBBounds(): IOBBBounds;
protected _globalAABBBounds: IAABBBounds;
get globalAABBBounds(): IAABBBounds;
protected _transMatrix: Matrix;
get transMatrix(): Matrix;
protected _globalTransMatrix: Matrix;
get globalTransMatrix(): Matrix;
protected _updateTag: number;
stamp?: number;
attribute: T;
protected _baseAttributes?: Partial<T>;
get baseAttributes(): Partial<T>;
set baseAttributes(value: Partial<T>);
shadowRoot?: IShadowRoot;
releaseStatus?: GraphicReleaseStatus;
states?: StateDefinitionsInput<T>;
currentStates?: string[];
effectiveStates?: string[];
resolvedStatePatch?: Partial<T>;
boundSharedStateScope?: SharedStateScope<T>;
boundSharedStateRevision?: number;
sharedStateDirty?: boolean;
registeredActiveScopes?: Set<SharedStateScope<T>>;
stateAnimateConfig?: IAnimateConfig;
stateMergeMode?: StateMergeMode;
animates: Map<string | number, IAnimate>;
animate?: () => IAnimate;
pathProxy?: ICustomPath2D;
attachedThemeGraphic?: IGraphic;
protected updateAABBBoundsStamp: number;
protected updateOBBBoundsStamp?: number;
clipPathMap?: Map<string, ISymbolClass>;
textMeasureId?: string;
protected stateSort?: (stateA: string, stateB: string) => number;
protected compiledStateDefinitions?: Map<string, CompiledStateDefinition<T>>;
protected compiledStateDefinitionsCacheKey?: string;
protected stateEngine?: StateEngine<T>;
protected stateEngineCompiledDefinitions?: Map<string, CompiledStateDefinition<T>>;
protected stateEngineStateSort?: (stateA: string, stateB: string) => number;
protected stateEngineMergeMode?: StateMergeMode;
protected stateTransitionOrchestrator?: StateTransitionOrchestrator<T>;
protected localStateDefinitionsSource?: StateDefinitionsInput<T>;
protected localStateDefinitionsVersion?: number;
protected resolverEpoch?: number;
protected attributeMayContainTransientAttrs?: boolean;
constructor(params?: T);
get normalAttrs(): Partial<T> | undefined;
set normalAttrs(_value: Partial<T> | undefined);
protected getBaseAttributesStorage(): Partial<T>;
getGraphicService(): import("../interface").IGraphicService;
getAttributes(): T;
protected getStateTransitionOrchestrator(): StateTransitionOrchestrator<T>;
protected resolveBoundSharedStateScope(): SharedStateScope<T> | SharedStateScope<Record<string, any>> | undefined;
protected syncSharedStateScopeBindingFromTree(markDirty?: boolean): boolean;
protected syncSharedStateScopeBindingOnTreeChange(markDirty?: boolean): boolean;
protected syncSharedStateActiveRegistrations(): void;
protected clearSharedStateActiveRegistrations(): void;
protected markSharedStateDirty(): void;
onParentSharedStateTreeChanged(stage?: IStage, layer?: ILayer): void;
refreshSharedStateBeforeRender(): void;
protected getLocalStatesVersion(): number;
protected resolveEffectiveCompiledDefinitions(): {
compiledDefinitions?: Map<string, CompiledStateDefinition<T>>;
};
protected recomputeCurrentStatePatch(): void;
protected buildStaticAttributeSnapshot(): Partial<T>;
protected buildRemovedStateAnimationAttrs(targetStateAttrs: Partial<T>, previousResolvedStatePatch?: Partial<T>): Partial<T>;
protected syncObjectToSnapshot(target: Record<string, any>, snapshot: Record<string, any>, excludedKeys?: ExcludedAttributeKeys): AttributeDelta;
protected _syncAttribute(excludedKeys?: ExcludedAttributeKeys): AttributeDelta;
protected _syncFinalAttributeFromStaticTruth(excludedKeys?: ExcludedAttributeKeys): void;
protected mergeAttributeDeltaCategory(category: UpdateCategory, key: string, prev: unknown, next: unknown): number;
protected submitUpdateByCategory(category: UpdateCategory, forceUpdateTag?: boolean): void;
protected submitUpdateByDelta(delta: AttributeDelta, forceUpdateTag?: boolean): void;
protected submitTouchedKeyUpdate(keys: string[], forceUpdateTag?: boolean): void;
protected submitTouchedUpdate(needsShapeAndBounds: boolean): void;
protected commitBaseAttributeMutation(forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
protected canCommitBaseAttributesByTouchedKeys(): boolean;
protected detachAttributeFromBaseAttributes(): void;
protected commitInternalBaseAttributes(params: Partial<T>, context?: ISetAttributeContext): void;
protected commitBaseAttributesByTouchedKeys(params: Partial<T>, forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
protected commitBaseAttributeBySingleKey(key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
protected applyBaseAttributes(params: Partial<T>): void;
protected _commitAnimationStaticAttributes(params: Partial<T>, context?: ISetAttributeContext): void;
applyAnimationTransientAttributes(params: Partial<T>, forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
protected applyTransientAttributes(params: Partial<T>, forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
protected _restoreAttributeFromStaticTruth(context?: ISetAttributeContext, excludedKeys?: ExcludedAttributeKeys): void;
protected collectStatePatchDeltaKeys(previousPatch?: Partial<T>, nextPatch?: Partial<T>): string[];
protected getStaticTruthValueForStateKey(key: string, nextPatch?: Partial<T>): {
hasValue: boolean;
value: any;
};
protected syncStatePatchDeltaToTarget(target: Record<string, any>, keys: string[], nextPatch?: Partial<T>, collectCategory?: boolean): UpdateCategory;
protected restoreAttributeFromStatePatchDelta(previousPatch?: Partial<T>, nextPatch?: Partial<T>, context?: ISetAttributeContext): void;
setMode(mode: '2d' | '3d'): void;
set3dMode(): void;
set2dMode(): void;
getOffsetXY(attr?: ITransform, includeScroll?: boolean): Point;
onAnimateBind(animate: IAnimate): void;
protected visitTrackedAnimates(cb: (animate: IAnimate) => void): void;
protected hasAnyTrackedAnimate(): any;
protected mayHaveTrackedAnimates(): boolean;
protected tryUpdateAABBBounds(): IAABBBounds;
protected tryUpdateOBBBounds(): IOBBBounds;
protected combindShadowAABBBounds(bounds: IAABBBounds): void;
abstract getGraphicTheme(): T;
protected doUpdateOBBBounds(): IOBBBounds;
protected abstract updateAABBBounds(attribute: T, symbolTheme: Required<T>, aabbBounds: IAABBBounds, full?: boolean): IAABBBounds;
getClipPath(): ISymbolClass;
parsePath(symbolType: string): ISymbolClass | CustomSymbolClass;
protected doUpdateAABBBounds(full?: boolean, graphicTheme?: Required<T>): IAABBBounds;
updatePathProxyAABBBounds(aabbBounds: IAABBBounds): boolean;
protected tryUpdateGlobalAABBBounds(): IAABBBounds;
protected tryUpdateGlobalTransMatrix(clearTag?: boolean): Matrix;
shouldUpdateGlobalMatrix(): boolean;
protected tryUpdateLocalTransMatrix(clearTag?: boolean): Matrix;
shouldUpdateAABBBounds(): boolean;
shouldSelfChangeUpdateAABBBounds(): boolean;
protected shouldUpdateLocalMatrix(): boolean;
isValid(): boolean;
protected _validNumber(num?: number): boolean;
shouldUpdateShape(): boolean;
clearUpdateShapeTag(): void;
containsPoint(x: number, y: number, mode: IContainPointMode, picker?: IPickerService): boolean;
protected setWidthHeightWithoutTransform(aabbBounds: IAABBBounds): void;
setAttributesAndPreventAnimate(params: Partial<T>, forceUpdateTag?: boolean, context?: ISetAttributeContext, ignorePriority?: boolean): void;
protected syncFinalAttributesFromUpdateContext(context?: ISetAttributeContext): void;
protected captureTransientFromAttrsBeforePreventAnimate(params: Partial<T>, keys: string[], context?: ISetAttributeContext): void;
protected consumeTransientFromAttrsBeforePreventAnimate(diffAttrs: Record<string, any>): Record<string, any> | null;
setAttributes(params: Partial<T>, forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
_setAttributes(params: Partial<T>, forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
setAttribute(key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
protected needUpdateTags(keys: string[], k?: string[]): boolean;
protected needUpdateTag(key: string, k?: string[]): boolean;
initAttributes(params: T): void;
translate(x: number, y: number): this;
translateTo(x: number, y: number): this;
scale(scaleX: number, scaleY: number, scaleCenter?: IPointLike): this;
scaleTo(scaleX: number, scaleY: number): this;
rotate(angle: number, rotateCenter?: IPointLike): this;
rotateTo(angle: number): this;
skewTo(b: number, c: number): this;
onAttributeUpdate(context?: ISetAttributeContext): void;
update(d?: {
bounds: boolean;
trans: boolean;
}): void;
hasState(stateName?: string): boolean;
getState(stateName: string): Partial<T> | StateDefinition<T> | undefined;
protected getStateResolveBaseAttrs(): Partial<T>;
protected syncStateResolveContext(stateResolveBaseAttrs?: Partial<T>): Partial<T>;
protected ensureStateEngine(stateResolveBaseAttrs?: Partial<T>): StateEngine<T>;
protected toGraphicStateTransition(result: StateTransitionResult): GraphicStateTransition;
protected sortLocalStates(states: readonly string[]): string[];
protected resolveLocalUseStatesTransition(states: readonly string[]): GraphicStateTransition;
protected resolveLocalClearStatesTransition(): GraphicStateTransition;
protected resolveUseStatesTransition(states: string[], stateResolveBaseAttrs?: Partial<T>): GraphicStateTransition;
protected resolveClearStatesTransition(): GraphicStateTransition;
protected resolveAddStateTransition(stateName: string, keepCurrentStates?: boolean): GraphicStateTransition;
protected resolveRemoveStateTransition(stateName: string | string[]): GraphicStateTransition;
protected resolveToggleStateTransition(stateName: string): GraphicStateTransition;
protected resolveGraphicStateTransition(states: string[], forceResolverRefresh?: boolean): ResolvedGraphicStateTransition<T>;
protected normalizeSetStatesOptions(options?: boolean | ISetStatesOptions): {
hasAnimation?: boolean;
animateSameStatePatchChange: boolean;
shouldRefreshSameStatePatch: boolean;
};
protected sameStatePatches(left?: Partial<T>, right?: Partial<T>): boolean;
protected commitSameStatePatchRefresh(states: string[], hasAnimation?: boolean, animateSameStatePatchChange?: boolean): void;
protected resolveStateAnimateConfig(animateConfig?: IAnimateConfig): any;
applyStateAttrs(attrs: Partial<T>, stateNames: string[], hasAnimation?: boolean, isClear?: boolean, animateConfig?: IAnimateConfig, extraAnimateAttrs?: Partial<T>): void;
updateNormalAttrs(_stateAttrs: Partial<T>): void;
protected getStateTransitionDefaultAttribute(key: string, targetAttrs?: Partial<T>): any;
protected shouldSkipStateTransitionDefaultAttribute(_key: string, _targetAttrs?: Partial<T>): boolean;
protected stopStateAnimates(type?: 'start' | 'end'): void;
clearStates(hasAnimation?: boolean): void;
removeState(stateName: string | string[], hasAnimation?: boolean): void;
toggleState(stateName: string, hasAnimation?: boolean): void;
addState(stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean): void;
setStates(states?: string[] | null, hasAnimation?: boolean): void;
setStates(states?: string[] | null, options?: ISetStatesOptions): void;
useStates(states: string[], hasAnimation?: boolean): void;
invalidateResolver(): void;
private sameStateNames;
addUpdateBoundTag(): void;
addUpdatePaintTag(): void;
addUpdateShapeTag(): void;
addUpdateShapeAndBoundsTag(): void;
protected addBroadUpdateTag(): void;
protected updateShapeAndBoundsTagSetted(): boolean;
protected clearUpdateBoundTag(): void;
protected clearUpdatePaintTag(): void;
addUpdatePositionTag(): void;
addUpdateGlobalPositionTag(): void;
protected clearUpdateLocalPositionTag(): void;
protected clearUpdateGlobalPositionTag(): void;
addUpdateLayoutTag(): void;
protected clearUpdateLayoutTag(): void;
protected needUpdateLayout(): boolean;
protected getAnchor(anchor: [string | number, string | number], params: {
b?: IAABBBounds;
}, resetScale?: boolean): [number, number];
protected doUpdateLocalMatrix(): void;
protected doUpdateGlobalMatrix(): void;
setStage(stage?: IStage, layer?: ILayer): void;
detachStageForRelease(): void;
setStageToShadowRoot(stage?: IStage, layer?: ILayer): void;
onAddStep(step: IStep): void;
onStop(props?: Partial<T>): void;
getDefaultAttribute(name: string): any;
getComputedAttribute(name: string): any;
onSetStage(cb: (g: IGraphic, stage: IStage) => void, immediate?: boolean): void;
attachShadow(shadowRoot?: IShadowRoot): IShadowRoot;
detachShadow(): void;
toJson(): IGraphicJson;
createPathProxy(path?: string): ICustomPath2D;
loadImage(image: any, background?: boolean): void;
setShadowGraphic(graphic: IGraphic): void;
imageLoadSuccess(url: string, image: HTMLImageElement, cb?: () => void): void;
imageLoadFail(url: string, cb?: () => void): void;
private _stopAnimates;
stopAnimates(stopChildren?: boolean): void;
release(): void;
protected hasCustomEvent(type: string): boolean;
protected _dispatchCustomEvent(type: string, context?: any): any;
protected beforeStateUpdate(attrs: Partial<T>, prevStates: readonly string[], nextStates: readonly string[], hasAnimation?: boolean, isClear?: boolean): any;
protected emitStateUpdateEvent(): void;
protected _emitCustomEvent(type: string, context?: any): void;
abstract getNoWorkAnimateAttr(): Record<string, number>;
abstract clone(): IGraphic<any>;
toCustomPath(): ICustomPath2D;
}
export type Graphic<T extends Partial<IGraphicAttribute> = Partial<IGraphicAttribute>> = GraphicImpl<T>;
export declare const GRAPHIC_CLASS_SYMBOL: unique symbol;
export interface IGraphicClassState {
Graphic: typeof GraphicImpl;
}
export declare function getGraphicClassState(): IGraphicClassState;
export declare const Graphic: typeof GraphicImpl;
export {};