@visactor/vrender-core 0.17.7-alpha.1 → 0.17.7-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/core/graphic-utils.d.ts +2 -1
- package/cjs/core/graphic-utils.js +29 -1
- package/cjs/core/graphic-utils.js.map +1 -1
- package/cjs/interface/core.d.ts +2 -1
- package/cjs/interface/core.js.map +1 -1
- package/cjs/modules.d.ts +0 -1
- package/cjs/modules.js +5 -11
- package/cjs/modules.js.map +1 -1
- package/cjs/picker/pick-modules.js +2 -3
- package/cjs/picker/pick-modules.js.map +1 -1
- package/cjs/render/contributions/render/draw-contribution.js +2 -2
- package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
- package/dist/index.js +171 -141
- package/dist/index.min.js +1 -1
- package/es/core/graphic-utils.d.ts +2 -1
- package/es/core/graphic-utils.js +32 -0
- package/es/core/graphic-utils.js.map +1 -1
- package/es/interface/core.d.ts +2 -1
- package/es/interface/core.js.map +1 -1
- package/es/modules.d.ts +0 -1
- package/es/modules.js +3 -9
- package/es/modules.js.map +1 -1
- package/es/picker/pick-modules.js +4 -4
- package/es/picker/pick-modules.js.map +1 -1
- package/es/render/contributions/render/draw-contribution.js +2 -2
- package/es/render/contributions/render/draw-contribution.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ICanvas, IContext2d, EnvType, IGlobal, ITextAttribute, IContributionProvider } from '../interface';
|
|
1
|
+
import type { ICanvas, IContext2d, EnvType, IGlobal, ITextAttribute, IContributionProvider, IGraphic, IGraphicAttribute, IStage } from '../interface';
|
|
2
2
|
import type { ITextMeasure, TextOptionsType } from '../interface/text';
|
|
3
3
|
import type { IMatrix, IPointLike, ITextMeasureOption } from '@visactor/vutils';
|
|
4
4
|
import { TextMeasure } from '@visactor/vutils';
|
|
@@ -22,6 +22,7 @@ export declare class DefaultGraphicUtil implements IGraphicUtil {
|
|
|
22
22
|
height: number;
|
|
23
23
|
};
|
|
24
24
|
createTextMeasureInstance(textSpec?: Partial<ITextAttribute>, option?: Partial<ITextMeasureOption>, getCanvasForMeasure?: () => any): TextMeasure<ITextAttribute>;
|
|
25
|
+
drawGraphicToCanvas(graphic: IGraphic<Partial<IGraphicAttribute>>, stage: IStage, canvas?: HTMLCanvasElement): HTMLCanvasElement | null | Promise<HTMLCanvasElement>;
|
|
25
26
|
}
|
|
26
27
|
export declare class DefaultTransformUtil implements ITransformUtil {
|
|
27
28
|
private matrix;
|
package/es/core/graphic-utils.js
CHANGED
|
@@ -24,6 +24,10 @@ import { canvasAllocate } from "../allocator/canvas-allocate";
|
|
|
24
24
|
|
|
25
25
|
import { application } from "../application";
|
|
26
26
|
|
|
27
|
+
import { container } from "../container";
|
|
28
|
+
|
|
29
|
+
import { VWindow } from "./window";
|
|
30
|
+
|
|
27
31
|
let DefaultGraphicUtil = class {
|
|
28
32
|
get canvas() {
|
|
29
33
|
return this.tryInitCanvas(), this._canvas;
|
|
@@ -76,6 +80,34 @@ let DefaultGraphicUtil = class {
|
|
|
76
80
|
specialCharSet: "-/: .,@%'\"~" + TextMeasure.ALPHABET_CHAR_SET + TextMeasure.ALPHABET_CHAR_SET.toUpperCase()
|
|
77
81
|
}, null != option ? option : {}), textSpec);
|
|
78
82
|
}
|
|
83
|
+
drawGraphicToCanvas(graphic, stage, canvas) {
|
|
84
|
+
if (!stage.defaultLayer) return null;
|
|
85
|
+
const window = container.get(VWindow), bounds = graphic.AABBBounds, width = bounds.width(), height = bounds.height();
|
|
86
|
+
window.create({
|
|
87
|
+
width: width,
|
|
88
|
+
height: height,
|
|
89
|
+
canvas: canvas,
|
|
90
|
+
dpr: stage.window.dpr,
|
|
91
|
+
canvasControled: !0,
|
|
92
|
+
offscreen: !0,
|
|
93
|
+
title: ""
|
|
94
|
+
});
|
|
95
|
+
const x = -bounds.x1, y = -bounds.y1, disableCheckGraphicWidthOutRange = stage.params.optimize.disableCheckGraphicWidthOutRange;
|
|
96
|
+
stage.params.optimize.disableCheckGraphicWidthOutRange = !0, stage.defaultLayer.getNativeHandler().drawTo(window, [ graphic ], {
|
|
97
|
+
x: x,
|
|
98
|
+
y: y,
|
|
99
|
+
width: width,
|
|
100
|
+
height: height,
|
|
101
|
+
stage: stage,
|
|
102
|
+
layer: stage.defaultLayer,
|
|
103
|
+
renderService: stage.renderService,
|
|
104
|
+
background: "transparent",
|
|
105
|
+
clear: !0,
|
|
106
|
+
updateBounds: !1
|
|
107
|
+
}), stage.params.optimize.disableCheckGraphicWidthOutRange = disableCheckGraphicWidthOutRange;
|
|
108
|
+
const c = window.getNativeHandler();
|
|
109
|
+
return c.nativeCanvas ? c.nativeCanvas : null;
|
|
110
|
+
}
|
|
79
111
|
};
|
|
80
112
|
|
|
81
113
|
DefaultGraphicUtil = __decorate([ injectable(), __param(0, inject(ContributionProvider)), __param(0, named(TextMeasureContribution)), __metadata("design:paramtypes", [ Object ]) ], DefaultGraphicUtil);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/graphic-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sDAAsD,CAAC;AAE/F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGtC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B,IAAI,MAAM;QACR,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC;IACt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EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAChG,OAAO,IAAI,CAAC;IACd,CAAC;IACD,SAAS,CAAC,EAAU,EAAE,EAAU;QAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,MAAM,EAAE;YACtC,OAAO,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IASD,QAAQ,CAAC,MAAqB;QAC5B,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,MAAM,EAAE;YACtC,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACO,cAAc,CAAC,MAAqB;QAkB1C,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA3IY,oBAAoB;IADhC,UAAU,EAAE;;GACA,oBAAoB,CA2IhC;SA3IY,oBAAoB","file":"graphic-utils.js","sourcesContent":["import { injectable, inject, named } from '../common/inversify-lite';\nimport type { ICanvas, IContext2d, EnvType, IGlobal, ITextAttribute, IContributionProvider } from '../interface';\nimport type { ITextMeasure, TextOptionsType } from '../interface/text';\nimport { TextMeasureContribution } from './contributions/textMeasure/textMeasure-contribution';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../common/contribution-provider';\nimport { DefaultTextStyle } from '../graphic/config';\nimport type { IMatrix, IPointLike, ITextMeasureOption } from '@visactor/vutils';\nimport { Matrix, TextMeasure } from '@visactor/vutils';\nimport type { IGraphicUtil, ITransformUtil, TransformType } from '../interface/core';\nimport { canvasAllocate } from '../allocator/canvas-allocate';\nimport { application } from '../application';\n\n@injectable()\nexport class DefaultGraphicUtil implements IGraphicUtil {\n get canvas(): ICanvas {\n this.tryInitCanvas();\n return this._canvas;\n }\n get context(): IContext2d | null {\n this.tryInitCanvas();\n return this._context;\n }\n _canvas?: ICanvas;\n _context?: IContext2d | null;\n _textMeasure: ITextMeasure;\n configured: boolean;\n global: IGlobal;\n\n constructor(\n @inject(ContributionProvider)\n @named(TextMeasureContribution)\n protected readonly contributions: IContributionProvider<ITextMeasure>\n ) {\n this.configured = false;\n this.global = application.global;\n this.global.hooks.onSetEnv.tap('graphic-util', (lastEnv, env, global) => {\n this.configured = false;\n this.configure(global, env);\n });\n }\n\n get textMeasure(): ITextMeasure {\n if (!this._textMeasure) {\n this.configure(this.global, this.global.env);\n }\n return this._textMeasure;\n }\n\n configure(global: IGlobal, env: EnvType) {\n if (this.configured) {\n return;\n }\n this.contributions.getContributions().forEach(contribution => {\n contribution.configure(this, env);\n });\n this.configured = true;\n }\n\n tryInitCanvas() {\n if (!this._canvas) {\n const canvas = canvasAllocate.shareCanvas();\n this._canvas = canvas;\n this._context = canvas.getContext('2d');\n }\n }\n\n bindTextMeasure(tm: ITextMeasure) {\n this._textMeasure = tm;\n }\n\n measureText(\n text: string,\n tc: TextOptionsType,\n method: 'native' | 'simple' | 'quick' = 'native'\n ): { width: number; height: number } {\n this.configure(this.global, this.global.env);\n const m = this.global.measureTextMethod;\n this.global.measureTextMethod = method;\n const data = {\n width: this._textMeasure.measureTextWidth(text, tc),\n height: tc.fontSize ?? DefaultTextStyle.fontSize\n };\n this.global.measureTextMethod = m;\n return data;\n }\n\n createTextMeasureInstance(\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) {\n this.configure(this.global, this.global.env);\n return new TextMeasure<ITextAttribute>(\n {\n defaultFontParams: {\n fontFamily: DefaultTextStyle.fontFamily,\n fontSize: DefaultTextStyle.fontSize\n },\n getCanvasForMeasure: getCanvasForMeasure || (() => this.canvas),\n getTextBounds: undefined,\n specialCharSet: '-/: .,@%\\'\"~' + TextMeasure.ALPHABET_CHAR_SET + TextMeasure.ALPHABET_CHAR_SET.toUpperCase(),\n ...(option ?? {})\n },\n textSpec\n );\n }\n}\n\nenum TransformMode {\n transform = 0,\n matrix = 1\n}\n\nconst _matrix = new Matrix();\n\n@injectable()\nexport class DefaultTransformUtil implements ITransformUtil {\n private matrix: IMatrix;\n private originTransform: TransformType;\n\n private outSourceMatrix: IMatrix;\n private outTargetMatrix: IMatrix;\n\n private mode: TransformMode;\n constructor() {\n this.matrix = new Matrix();\n }\n init(origin: TransformType): this {\n this.mode = TransformMode.transform;\n this.originTransform = origin;\n this.matrix.reset();\n return this;\n }\n fromMatrix(source: IMatrix, target: IMatrix): this {\n this.mode = TransformMode.matrix;\n this.outSourceMatrix = source;\n this.outTargetMatrix = target;\n return this;\n }\n\n // translate: (x: number, y: number) => Transform;\n // translateTo: (x: number, y: number) => Transform;\n private scaleMatrix(sx: number, sy: number, center?: IPointLike): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.scale(sx, sy);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.scale(sx, sy);\n }\n\n // _matrix.reset();\n // if (center) {\n // const { x, y } = center;\n // _matrix.translate(x, y);\n // _matrix.scale(sx, sy);\n // _matrix.translate(-x, -y);\n // } else {\n // _matrix.scale(sx, sy);\n // }\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n\n private rotateMatrix(angle: number, center?: IPointLike): this {\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.rotate(angle);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.rotate(angle);\n }\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n scale(sx: number, sy: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.scaleMatrix(sx, sy, center);\n }\n return this;\n }\n rotate(angle: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.rotateMatrix(angle, center);\n }\n return this;\n }\n private translateMatrix(dx: number, dy: number): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n this.outTargetMatrix.translate(dx, dy);\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n translate(dx: number, dy: number): this {\n if (this.mode === TransformMode.matrix) {\n return this.translateMatrix(dx, dy);\n }\n return this;\n }\n // scaleTo: (sx: number, sy: number, center: IPointLike) => Transform;\n // rotate: (rx: number, ry: number, center: IPointLike) => Transform;\n // rotateTo: (rx: number, ry: number, center: IPointLike) => Transform;\n // 语法糖\n // interactive: (dx: number, dy: number, dsx: number, dsy: number, drx: number, dry: number) => Transform;\n // // 扩展padding像素,用于外描边,内描边\n // extend: (origin: TransformType, padding: number) => Transform;\n // 将所有的transform生成为一次的transform\n simplify(target: TransformType): this {\n if (this.mode === TransformMode.matrix) {\n return this.simplifyMatrix(target);\n }\n return this;\n }\n private simplifyMatrix(target: TransformType): this {\n // let { a, b, c, d, e, f } = this.outTargetMatrix;\n // if (a === 0 || d === 0) return this;\n // const { dx=0, dy=0 } = target;\n // // 不处理dx和dy\n // e -= dx;\n // f -= dy;\n // const tanTheta = b / a;\n // const angle = Math.atan(tanTheta);\n // const cosTheta = cos(angle);\n // const sinTheta = sin(angle);\n // const sx = cosTheta !== 0 ? (a / cosTheta) : (b / sinTheta);\n // const sy = sinTheta !== 0 ? (-c / sinTheta) : (d / cosTheta);\n // const x = e;\n // const y = f;\n // target.x = x;\n // target.y = y;\n // target.dx = dx;\n return this;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/graphic-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAcrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sDAAsD,CAAC;AAE/F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAI5B,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B,IAAI,MAAM;QACR,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,IAAI,OAAO;QACT,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAOD,YAGqB,aAAkD;QAAlD,kBAAa,GAAb,aAAa,CAAqC;QAErE,IAA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AC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAChG,OAAO,IAAI,CAAC;IACd,CAAC;IACD,SAAS,CAAC,EAAU,EAAE,EAAU;QAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,MAAM,EAAE;YACtC,OAAO,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IASD,QAAQ,CAAC,MAAqB;QAC5B,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,MAAM,EAAE;YACtC,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACO,cAAc,CAAC,MAAqB;QAkB1C,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA3IY,oBAAoB;IADhC,UAAU,EAAE;;GACA,oBAAoB,CA2IhC;SA3IY,oBAAoB","file":"graphic-utils.js","sourcesContent":["import { injectable, inject, named } from '../common/inversify-lite';\nimport type {\n ICanvas,\n IContext2d,\n EnvType,\n IGlobal,\n ITextAttribute,\n IContributionProvider,\n IGraphic,\n IGraphicAttribute,\n IStage,\n IWindow\n} from '../interface';\nimport type { ITextMeasure, TextOptionsType } from '../interface/text';\nimport { TextMeasureContribution } from './contributions/textMeasure/textMeasure-contribution';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../common/contribution-provider';\nimport { DefaultTextStyle } from '../graphic/config';\nimport type { IMatrix, IPointLike, ITextMeasureOption } from '@visactor/vutils';\nimport { Matrix, TextMeasure } from '@visactor/vutils';\nimport type { IGraphicUtil, ITransformUtil, TransformType } from '../interface/core';\nimport { canvasAllocate } from '../allocator/canvas-allocate';\nimport { application } from '../application';\nimport { container } from '../container';\nimport { VWindow } from './window';\nimport { graphicCreator } from '../graphic';\n\n@injectable()\nexport class DefaultGraphicUtil implements IGraphicUtil {\n get canvas(): ICanvas {\n this.tryInitCanvas();\n return this._canvas;\n }\n get context(): IContext2d | null {\n this.tryInitCanvas();\n return this._context;\n }\n _canvas?: ICanvas;\n _context?: IContext2d | null;\n _textMeasure: ITextMeasure;\n configured: boolean;\n global: IGlobal;\n\n constructor(\n @inject(ContributionProvider)\n @named(TextMeasureContribution)\n protected readonly contributions: IContributionProvider<ITextMeasure>\n ) {\n this.configured = false;\n this.global = application.global;\n this.global.hooks.onSetEnv.tap('graphic-util', (lastEnv, env, global) => {\n this.configured = false;\n this.configure(global, env);\n });\n }\n\n get textMeasure(): ITextMeasure {\n if (!this._textMeasure) {\n this.configure(this.global, this.global.env);\n }\n return this._textMeasure;\n }\n\n configure(global: IGlobal, env: EnvType) {\n if (this.configured) {\n return;\n }\n this.contributions.getContributions().forEach(contribution => {\n contribution.configure(this, env);\n });\n this.configured = true;\n }\n\n tryInitCanvas() {\n if (!this._canvas) {\n const canvas = canvasAllocate.shareCanvas();\n this._canvas = canvas;\n this._context = canvas.getContext('2d');\n }\n }\n\n bindTextMeasure(tm: ITextMeasure) {\n this._textMeasure = tm;\n }\n\n measureText(\n text: string,\n tc: TextOptionsType,\n method: 'native' | 'simple' | 'quick' = 'native'\n ): { width: number; height: number } {\n this.configure(this.global, this.global.env);\n const m = this.global.measureTextMethod;\n this.global.measureTextMethod = method;\n const data = {\n width: this._textMeasure.measureTextWidth(text, tc),\n height: tc.fontSize ?? DefaultTextStyle.fontSize\n };\n this.global.measureTextMethod = m;\n return data;\n }\n\n createTextMeasureInstance(\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) {\n this.configure(this.global, this.global.env);\n return new TextMeasure<ITextAttribute>(\n {\n defaultFontParams: {\n fontFamily: DefaultTextStyle.fontFamily,\n fontSize: DefaultTextStyle.fontSize\n },\n getCanvasForMeasure: getCanvasForMeasure || (() => this.canvas),\n getTextBounds: undefined,\n specialCharSet: '-/: .,@%\\'\"~' + TextMeasure.ALPHABET_CHAR_SET + TextMeasure.ALPHABET_CHAR_SET.toUpperCase(),\n ...(option ?? {})\n },\n textSpec\n );\n }\n\n drawGraphicToCanvas(\n graphic: IGraphic<Partial<IGraphicAttribute>>,\n stage: IStage,\n canvas?: HTMLCanvasElement\n ): HTMLCanvasElement | null | Promise<HTMLCanvasElement> {\n if (!stage.defaultLayer) {\n return null;\n }\n const window = container.get<IWindow>(VWindow);\n const bounds = graphic.AABBBounds;\n const width = bounds.width();\n const height = bounds.height();\n window.create({\n width,\n height,\n canvas,\n dpr: stage.window.dpr,\n canvasControled: true,\n offscreen: true,\n title: ''\n });\n\n const x = -bounds.x1;\n const y = -bounds.y1;\n const disableCheckGraphicWidthOutRange = stage.params.optimize.disableCheckGraphicWidthOutRange;\n // 关掉dirtyBounds检测\n stage.params.optimize.disableCheckGraphicWidthOutRange = true;\n stage.defaultLayer.getNativeHandler().drawTo(window, [graphic as any], {\n x,\n y,\n width,\n height,\n stage,\n layer: stage.defaultLayer,\n renderService: stage.renderService,\n background: 'transparent',\n clear: true, // 第一个layer需要clear\n updateBounds: false\n });\n stage.params.optimize.disableCheckGraphicWidthOutRange = disableCheckGraphicWidthOutRange;\n\n const c = window.getNativeHandler();\n if (c.nativeCanvas) {\n return c.nativeCanvas;\n }\n return null;\n }\n}\n\nenum TransformMode {\n transform = 0,\n matrix = 1\n}\n\nconst _matrix = new Matrix();\n\n@injectable()\nexport class DefaultTransformUtil implements ITransformUtil {\n private matrix: IMatrix;\n private originTransform: TransformType;\n\n private outSourceMatrix: IMatrix;\n private outTargetMatrix: IMatrix;\n\n private mode: TransformMode;\n constructor() {\n this.matrix = new Matrix();\n }\n init(origin: TransformType): this {\n this.mode = TransformMode.transform;\n this.originTransform = origin;\n this.matrix.reset();\n return this;\n }\n fromMatrix(source: IMatrix, target: IMatrix): this {\n this.mode = TransformMode.matrix;\n this.outSourceMatrix = source;\n this.outTargetMatrix = target;\n return this;\n }\n\n // translate: (x: number, y: number) => Transform;\n // translateTo: (x: number, y: number) => Transform;\n private scaleMatrix(sx: number, sy: number, center?: IPointLike): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.scale(sx, sy);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.scale(sx, sy);\n }\n\n // _matrix.reset();\n // if (center) {\n // const { x, y } = center;\n // _matrix.translate(x, y);\n // _matrix.scale(sx, sy);\n // _matrix.translate(-x, -y);\n // } else {\n // _matrix.scale(sx, sy);\n // }\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n\n private rotateMatrix(angle: number, center?: IPointLike): this {\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.rotate(angle);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.rotate(angle);\n }\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n scale(sx: number, sy: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.scaleMatrix(sx, sy, center);\n }\n return this;\n }\n rotate(angle: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.rotateMatrix(angle, center);\n }\n return this;\n }\n private translateMatrix(dx: number, dy: number): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n this.outTargetMatrix.translate(dx, dy);\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n translate(dx: number, dy: number): this {\n if (this.mode === TransformMode.matrix) {\n return this.translateMatrix(dx, dy);\n }\n return this;\n }\n // scaleTo: (sx: number, sy: number, center: IPointLike) => Transform;\n // rotate: (rx: number, ry: number, center: IPointLike) => Transform;\n // rotateTo: (rx: number, ry: number, center: IPointLike) => Transform;\n // 语法糖\n // interactive: (dx: number, dy: number, dsx: number, dsy: number, drx: number, dry: number) => Transform;\n // // 扩展padding像素,用于外描边,内描边\n // extend: (origin: TransformType, padding: number) => Transform;\n // 将所有的transform生成为一次的transform\n simplify(target: TransformType): this {\n if (this.mode === TransformMode.matrix) {\n return this.simplifyMatrix(target);\n }\n return this;\n }\n private simplifyMatrix(target: TransformType): this {\n // let { a, b, c, d, e, f } = this.outTargetMatrix;\n // if (a === 0 || d === 0) return this;\n // const { dx=0, dy=0 } = target;\n // // 不处理dx和dy\n // e -= dx;\n // f -= dy;\n // const tanTheta = b / a;\n // const angle = Math.atan(tanTheta);\n // const cosTheta = cos(angle);\n // const sinTheta = sin(angle);\n // const sx = cosTheta !== 0 ? (a / cosTheta) : (b / sinTheta);\n // const sy = sinTheta !== 0 ? (-c / sinTheta) : (d / cosTheta);\n // const x = e;\n // const y = f;\n // target.x = x;\n // target.y = y;\n // target.dx = dx;\n return this;\n }\n}\n"]}
|
package/es/interface/core.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ICanvas } from './canvas';
|
|
2
2
|
import type { IContext2d } from './context';
|
|
3
|
-
import type { IGraphicAttribute } from './graphic';
|
|
3
|
+
import type { IGraphic, IGraphicAttribute } from './graphic';
|
|
4
4
|
import type { ITextAttribute } from './graphic/text';
|
|
5
5
|
import type { ILayer, ILayerParams } from './layer';
|
|
6
6
|
import type { IStage } from './stage';
|
|
@@ -16,6 +16,7 @@ export interface IGraphicUtil {
|
|
|
16
16
|
};
|
|
17
17
|
bindTextMeasure: (tm: ITextMeasure) => void;
|
|
18
18
|
createTextMeasureInstance: (textSpec?: Partial<ITextAttribute>, option?: Partial<ITextMeasureOption>, getCanvasForMeasure?: () => any) => TextMeasure<ITextAttribute>;
|
|
19
|
+
drawGraphicToCanvas: (graphic: IGraphic, stage: IStage) => HTMLCanvasElement | null | Promise<HTMLCanvasElement | null>;
|
|
19
20
|
}
|
|
20
21
|
export type TransformType = Pick<IGraphicAttribute, 'x' | 'y' | 'scaleX' | 'scaleY' | 'angle' | 'dx' | 'dy'> & {
|
|
21
22
|
anchor?: IGraphicAttribute['anchor'];
|
package/es/interface/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/core.ts"],"names":[],"mappings":"","file":"core.js","sourcesContent":["import type { ICanvas } from './canvas';\nimport type { IContext2d } from './context';\nimport type { IGraphicAttribute } from './graphic';\nimport type { ITextAttribute } from './graphic/text';\nimport type { ILayer, ILayerParams } from './layer';\nimport type { IStage } from './stage';\nimport type { ITextMeasure, TextOptionsType } from './text';\nimport type { IMatrix, IPointLike, ITextMeasureOption, TextMeasure } from '@visactor/vutils';\n\nexport interface IGraphicUtil {\n canvas?: ICanvas;\n context?: IContext2d | null;\n textMeasure: ITextMeasure;\n measureText: (text: string, tc: TextOptionsType) => { width: number; height: number };\n bindTextMeasure: (tm: ITextMeasure) => void;\n createTextMeasureInstance: (\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) => TextMeasure<ITextAttribute>;\n}\n\nexport type TransformType = Pick<IGraphicAttribute, 'x' | 'y' | 'scaleX' | 'scaleY' | 'angle' | 'dx' | 'dy'> & {\n anchor?: IGraphicAttribute['anchor'];\n};\nexport interface ITransformUtil {\n init: (origin: TransformType) => ITransformUtil;\n fromMatrix: (source: IMatrix, target: IMatrix) => ITransformUtil;\n scale: (sx: number, sy: number, center?: IPointLike) => ITransformUtil;\n rotate: (angle: number, center?: IPointLike) => ITransformUtil;\n translate: (dx: number, dy: number) => ITransformUtil;\n}\n\nexport interface ILayerService {\n createLayer: (stage: IStage, options?: Partial<ILayerParams>) => ILayer;\n // stage绘制前调用\n prepareStageLayer: (stage: IStage) => void;\n releaseLayer: (stage: IStage, layer: ILayer) => void;\n restLayerCount: (stage: IStage) => number;\n getStageLayer: (stage: IStage) => ILayer[];\n layerCount: (stage: IStage) => number;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/interface/core.ts"],"names":[],"mappings":"","file":"core.js","sourcesContent":["import type { ICanvas } from './canvas';\nimport type { IContext2d } from './context';\nimport type { IGraphic, IGraphicAttribute } from './graphic';\nimport type { ITextAttribute } from './graphic/text';\nimport type { ILayer, ILayerParams } from './layer';\nimport type { IStage } from './stage';\nimport type { ITextMeasure, TextOptionsType } from './text';\nimport type { IMatrix, IPointLike, ITextMeasureOption, TextMeasure } from '@visactor/vutils';\n\nexport interface IGraphicUtil {\n canvas?: ICanvas;\n context?: IContext2d | null;\n textMeasure: ITextMeasure;\n measureText: (text: string, tc: TextOptionsType) => { width: number; height: number };\n bindTextMeasure: (tm: ITextMeasure) => void;\n createTextMeasureInstance: (\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) => TextMeasure<ITextAttribute>;\n drawGraphicToCanvas: (\n graphic: IGraphic,\n stage: IStage\n ) => HTMLCanvasElement | null | Promise<HTMLCanvasElement | null>;\n}\n\nexport type TransformType = Pick<IGraphicAttribute, 'x' | 'y' | 'scaleX' | 'scaleY' | 'angle' | 'dx' | 'dy'> & {\n anchor?: IGraphicAttribute['anchor'];\n};\nexport interface ITransformUtil {\n init: (origin: TransformType) => ITransformUtil;\n fromMatrix: (source: IMatrix, target: IMatrix) => ITransformUtil;\n scale: (sx: number, sy: number, center?: IPointLike) => ITransformUtil;\n rotate: (angle: number, center?: IPointLike) => ITransformUtil;\n translate: (dx: number, dy: number) => ITransformUtil;\n}\n\nexport interface ILayerService {\n createLayer: (stage: IStage, options?: Partial<ILayerParams>) => ILayer;\n // stage绘制前调用\n prepareStageLayer: (stage: IStage) => void;\n releaseLayer: (stage: IStage, layer: ILayer) => void;\n restLayerCount: (stage: IStage) => number;\n getStageLayer: (stage: IStage) => ILayer[];\n layerCount: (stage: IStage) => number;\n}\n"]}
|
package/es/modules.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { IGlobal, IGraphicService } from './interface';
|
|
2
2
|
import type { IGraphicUtil, ILayerService, ITransformUtil } from './interface/core';
|
|
3
|
-
export declare function preLoadAllModule(): void;
|
|
4
3
|
export declare const vglobal: IGlobal;
|
|
5
4
|
export declare const graphicUtil: IGraphicUtil;
|
|
6
5
|
export declare const transformUtil: ITransformUtil;
|
package/es/modules.js
CHANGED
|
@@ -24,15 +24,9 @@ import { container } from "./container";
|
|
|
24
24
|
|
|
25
25
|
import { VGlobal } from "./constants";
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
loaded || (loaded = !0, container.load(coreModule), container.load(graphicModule),
|
|
31
|
-
container.load(renderModule), container.load(pickModule), container.load(pluginModule),
|
|
32
|
-
loadBuiltinContributions(container), loadRenderContributions(container));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
preLoadAllModule();
|
|
27
|
+
container.load(coreModule), container.load(graphicModule), container.load(renderModule),
|
|
28
|
+
container.load(pickModule), container.load(pluginModule), loadBuiltinContributions(container),
|
|
29
|
+
loadRenderContributions(container);
|
|
36
30
|
|
|
37
31
|
export const vglobal = container.get(VGlobal);
|
|
38
32
|
|
package/es/modules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/modules.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,YAAY,MAAM,yBAAyB,CAAC;AACnD,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAE/C,OAAO,aAAa,MAAM,0CAA0C,CAAC;AACrE,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,wBAAwB,MAAM,8BAA8B,CAAC;AACpE,OAAO,uBAAuB,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIhD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,
|
|
1
|
+
{"version":3,"sources":["../src/modules.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,YAAY,MAAM,yBAAyB,CAAC;AACnD,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAE/C,OAAO,aAAa,MAAM,0CAA0C,CAAC;AACrE,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,wBAAwB,MAAM,8BAA8B,CAAC;AACpE,OAAO,uBAAuB,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIhD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC3B,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AAC9B,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAC7B,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAE3B,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAC7B,wBAAwB,CAAC,SAAS,CAAC,CAAC;AACpC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAKnC,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAU,OAAO,CAAC,CAAC;AACvD,WAAW,CAAC,MAAM,GAAG,OAAO,CAAC;AAC7B,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,CAAe,WAAW,CAAC,CAAC;AACpE,WAAW,CAAC,WAAW,GAAG,WAAW,CAAC;AACtC,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,CAAiB,aAAa,CAAC,CAAC;AAC1E,WAAW,CAAC,aAAa,GAAG,aAAa,CAAC;AAC1C,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC,GAAG,CAAkB,cAAc,CAAC,CAAC;AAC7E,WAAW,CAAC,cAAc,GAAG,cAAc,CAAC;AAa5C,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAgB,YAAY,CAAC,CAAC;AACvE,WAAW,CAAC,YAAY,GAAG,YAAY,CAAC","file":"modules.js","sourcesContent":["import coreModule from './core/core-modules';\nimport renderModule from './render/render-modules';\nimport pickModule from './picker/pick-modules';\n// import allocatorModule from './allocator/allocator-modules';\nimport graphicModule from './graphic/graphic-service/graphic-module';\nimport pluginModule from './plugins/plugin-modules';\nimport loadBuiltinContributions from './core/contributions/modules';\nimport loadRenderContributions from './render/contributions/modules';\n// import loadPickContributions from './picker/contributions/modules';\n// import loadCanvasContributions from './canvas/contributions/modules';\nimport { LayerService } from './core/constants';\n// import { IMat4Allocate, IMatrixAllocate, Mat4Allocate, MatrixAllocate } from './allocator/matrix-allocate';\n// import { GlobalPickerService } from './picker/constants';\nimport type { IGlobal, IGraphicService, IPickerService } from './interface';\nimport { application } from './application';\nimport type { IGraphicUtil, ILayerService, ITransformUtil } from './interface/core';\nimport { GraphicService } from './graphic/constants';\nimport { GraphicUtil, TransformUtil } from './core/constants';\nimport { container } from './container';\nimport { VGlobal } from './constants';\n\ncontainer.load(coreModule);\ncontainer.load(graphicModule);\ncontainer.load(renderModule);\ncontainer.load(pickModule);\n// container.load(allocatorModule);\ncontainer.load(pluginModule);\nloadBuiltinContributions(container);\nloadRenderContributions(container);\n// loadPickContributions(container);\n// loadCanvasContributions(container);\n\n// 全局变量\nexport const vglobal = container.get<IGlobal>(VGlobal);\napplication.global = vglobal;\nexport const graphicUtil = container.get<IGraphicUtil>(GraphicUtil);\napplication.graphicUtil = graphicUtil;\nexport const transformUtil = container.get<ITransformUtil>(TransformUtil);\napplication.transformUtil = transformUtil;\nexport const graphicService = container.get<IGraphicService>(GraphicService);\napplication.graphicService = graphicService;\n// export const matrixAllocate = container.get<IMatrixAllocate>(MatrixAllocate);\n// export const mat4Allocate = container.get<IMat4Allocate>(Mat4Allocate);\n// export const canvasAllocate = container.get<ICanvasAllocate>(CanvasAllocate);\n// export const arcAllocate = container.get<IArcAllocate>(ArcAllocate);\n// export const areaAllocate = container.get<IAreaAllocate>(AreaAllocate);\n// export const circleAllocate = container.get<ICircleAllocate>(CircleAllocate);\n// export const lineAllocate = container.get<ILineAllocate>(LineAllocate);\n// export const pathAllocate = container.get<IPathAllocate>(PathAllocate);\n// export const rectAllocate = container.get<IRectAllocate>(RectAllocate);\n// export const symbolAllocate = container.get<ISymbolAllocate>(SymbolAllocate);\n// export const textAllocate = container.get<ITextAllocate>(TextAllocate);\n// export const pickerService = container.get<IPickerService>(GlobalPickerService);\nexport const layerService = container.get<ILayerService>(LayerService);\napplication.layerService = layerService;\n"]}
|
|
@@ -6,10 +6,10 @@ import { Canvas3DPickItemInterceptor, InteractivePickItemInterceptorContribution
|
|
|
6
6
|
|
|
7
7
|
import { bindContributionProvider } from "../common/contribution-provider";
|
|
8
8
|
|
|
9
|
-
export default new ContainerModule((
|
|
10
|
-
|
|
11
|
-
bind(
|
|
12
|
-
bind(
|
|
9
|
+
export default new ContainerModule((bind => {
|
|
10
|
+
bind(PickerService).toService(GlobalPickerService), bind(Canvas3DPickItemInterceptor).toSelf().inSingletonScope(),
|
|
11
|
+
bind(PickItemInterceptor).toService(Canvas3DPickItemInterceptor), bind(ShadowRootPickItemInterceptorContribution).toSelf().inSingletonScope(),
|
|
12
|
+
bind(PickItemInterceptor).toService(ShadowRootPickItemInterceptorContribution),
|
|
13
13
|
bind(InteractivePickItemInterceptorContribution).toSelf().inSingletonScope(), bind(PickItemInterceptor).toService(InteractivePickItemInterceptorContribution),
|
|
14
14
|
bindContributionProvider(bind, PickItemInterceptor);
|
|
15
15
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/picker/pick-modules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAIjE,OAAO,EACL,2BAA2B,EAC3B,0CAA0C,EAC1C,mBAAmB,EACnB,yCAAyC,EAC1C,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAE3E,eAAe,IAAI,eAAe,CAAC,
|
|
1
|
+
{"version":3,"sources":["../src/picker/pick-modules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAIjE,OAAO,EACL,2BAA2B,EAC3B,0CAA0C,EAC1C,mBAAmB,EACnB,yCAAyC,EAC1C,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAE3E,eAAe,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;IACxC,IAAI,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAMnD,IAAI,CAAC,2BAA2B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC9D,IAAI,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;IAGjE,IAAI,CAAC,yCAAyC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC5E,IAAI,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,yCAAyC,CAAC,CAAC;IAG/E,IAAI,CAAC,0CAA0C,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC7E,IAAI,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,0CAA0C,CAAC,CAAC;IAChF,wBAAwB,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC","file":"pick-modules.js","sourcesContent":["import { ContainerModule } from '../common/inversify-lite';\nimport { PickerService, GlobalPickerService } from './constants';\nimport { DefaultGlobalPickerService } from './global-picker-service';\n// import { DefaultCanvasPickerService } from './canvas-picker-service';\n// import { DefaultMathPickerService } from './math-picker-service';\nimport {\n Canvas3DPickItemInterceptor,\n InteractivePickItemInterceptorContribution,\n PickItemInterceptor,\n ShadowRootPickItemInterceptorContribution\n} from './pick-interceptor';\nimport { bindContributionProvider } from '../common/contribution-provider';\n\nexport default new ContainerModule(bind => {\n bind(PickerService).toService(GlobalPickerService);\n\n // bind(DefaultGlobalPickerService).toSelf().inSingletonScope();\n // bind(GlobalPickerService).toService(DefaultGlobalPickerService);\n\n // interceptor\n bind(Canvas3DPickItemInterceptor).toSelf().inSingletonScope();\n bind(PickItemInterceptor).toService(Canvas3DPickItemInterceptor);\n\n // shadow root\n bind(ShadowRootPickItemInterceptorContribution).toSelf().inSingletonScope();\n bind(PickItemInterceptor).toService(ShadowRootPickItemInterceptorContribution);\n\n // interactive\n bind(InteractivePickItemInterceptorContribution).toSelf().inSingletonScope();\n bind(PickItemInterceptor).toService(InteractivePickItemInterceptorContribution);\n bindContributionProvider(bind, PickItemInterceptor);\n});\n"]}
|
|
@@ -69,7 +69,7 @@ let DefaultDrawContribution = class {
|
|
|
69
69
|
dirtyBounds.y1 = Math.floor(dirtyBounds.y1 * context.dpr) / context.dpr, dirtyBounds.x2 = Math.ceil(dirtyBounds.x2 * context.dpr) / context.dpr,
|
|
70
70
|
dirtyBounds.y2 = Math.ceil(dirtyBounds.y2 * context.dpr) / context.dpr), this.backupDirtyBounds.copy(dirtyBounds),
|
|
71
71
|
context.inuse = !0, context.clearMatrix(), context.setTransformForCurrent(!0);
|
|
72
|
-
const drawInArea = dirtyBounds.width() * context.dpr
|
|
72
|
+
const drawInArea = dirtyBounds.width() * context.dpr < context.canvas.width || dirtyBounds.height() * context.dpr < context.canvas.height;
|
|
73
73
|
context.save(), context.translate(x, y, !0), drawInArea && (context.beginPath(),
|
|
74
74
|
context.rect(dirtyBounds.x1, dirtyBounds.y1, dirtyBounds.width(), dirtyBounds.height()),
|
|
75
75
|
context.clip()), stage.camera && (this.dirtyBounds.setValue(-1 / 0, -1 / 0, 1 / 0, 1 / 0),
|
|
@@ -78,7 +78,7 @@ let DefaultDrawContribution = class {
|
|
|
78
78
|
var _a, _b;
|
|
79
79
|
return (null !== (_a = a.attribute.zIndex) && void 0 !== _a ? _a : DefaultAttribute.zIndex) - (null !== (_b = b.attribute.zIndex) && void 0 !== _b ? _b : DefaultAttribute.zIndex);
|
|
80
80
|
})).forEach((group => {
|
|
81
|
-
this.renderGroup(group, drawContext, matrixAllocate.allocate(1, 0, 0, 1, 0, 0));
|
|
81
|
+
group.isContainer ? this.renderGroup(group, drawContext, matrixAllocate.allocate(1, 0, 0, 1, 0, 0)) : this.renderItem(group, drawContext);
|
|
82
82
|
})), context.restore(), context.restore(), context.draw(), context.inuse = !1;
|
|
83
83
|
}
|
|
84
84
|
doRegister() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/render/contributions/render/draw-contribution.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAgBxF,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,eAAe,EAAQ,MAAM,kBAAkB,CAAC;AAE3F,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAkB,MAAM,UAAU,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAM5C,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAclC,YAIiD,aAA+B,EAK3D,gCAAyF;QAL7D,kBAAa,GAAb,aAAa,CAAkB;QAK3D,qCAAgC,GAAhC,gCAAg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SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAChD,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,EAAE;oBAC9C,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;iBAClD;aACF;iBAAM;gBACL,OAAO,CAAC,SAAS,GAAG,WAAW,CAC7B,OAAO,EACP,KAAK,EACL;oBACE,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,EAAE;iBAC5D,EACD,CAAC,EACD,CAAC,CACF,CAAC;gBACF,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;aACvC;SACF;IACH,CAAC;IAED,SAAS,CAAC,aAA6B,EAAE,UAAwB;QAC/D,OAAO;IACT,CAAC;CACF,CAAA;AAjZY,uBAAuB;IADnC,UAAU,EAAE;IAmBR,WAAA,WAAW,CAAC,aAAa,CAAC,CAAA;IAG1B,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAC5B,WAAA,KAAK,CAAC,mBAAmB,CAAC,CAAA;;GAtBlB,uBAAuB,CAiZnC;SAjZY,uBAAuB","file":"draw-contribution.js","sourcesContent":["import { injectable, inject, named, multiInject } from '../../../common/inversify-lite';\nimport type {\n IContext2d,\n MaybePromise,\n IGraphic,\n IGroup,\n IDrawContext,\n IRenderService,\n IGraphicRender,\n IGraphicRenderDrawParams,\n IContributionProvider,\n IDrawItemInterceptorContribution,\n IDrawContribution,\n IRenderSelector,\n IGlobal\n} from '../../../interface';\nimport { findNextGraphic, foreach } from '../../../common/sort';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../../../common/contribution-provider';\nimport { DefaultAttribute } from '../../../graphic';\nimport type { IAABBBounds, IBounds, IBoundsLike, IMatrix, IMatrixLike } from '@visactor/vutils';\nimport { Bounds, Logger, getRectIntersect, isRectIntersect, last } from '@visactor/vutils';\nimport { LayerService } from '../../../core/constants';\nimport { container } from '../../../container';\nimport { GraphicRender, IncrementalDrawContribution, RenderSelector } from './symbol';\nimport { DrawItemInterceptor } from './draw-interceptor';\nimport { createColor } from '../../../common/canvas-utils';\nimport type { ILayerService } from '../../../interface/core';\nimport { boundsAllocate } from '../../../allocator/bounds-allocate';\nimport { matrixAllocate } from '../../../allocator/matrix-allocate';\nimport { application } from '../../../application';\n\n/**\n * 默认的渲染contribution,基于树状结构针对图元的渲染\n */\n@injectable()\nexport class DefaultDrawContribution implements IDrawContribution {\n declare currentRenderMap: Map<number, IGraphicRender>;\n declare defaultRenderMap: Map<number, IGraphicRender>;\n declare styleRenderMap: Map<string, Map<number, IGraphicRender>>;\n declare dirtyBounds: IBounds;\n declare backupDirtyBounds: IBounds;\n // 是否使用dirtyBounds\n declare useDirtyBounds: boolean;\n declare currentRenderService: IRenderService;\n declare InterceptorContributions: IDrawItemInterceptorContribution[];\n\n declare global: IGlobal;\n declare layerService: ILayerService;\n\n constructor(\n // @inject(ContributionProvider)\n // @named(GraphicRender)\n // protected readonly contributions: ContributionProvider<IGraphicRender>,\n @multiInject(GraphicRender) protected readonly contributions: IGraphicRender[],\n // @inject(RenderSelector) protected readonly renderSelector: IRenderSelector, // 根据图元类型选择对应的renderItem进行渲染\n // 拦截器\n @inject(ContributionProvider)\n @named(DrawItemInterceptor)\n protected readonly drawItemInterceptorContributions: IContributionProvider<IDrawItemInterceptorContribution>\n ) {\n this.currentRenderMap = new Map();\n this.defaultRenderMap = new Map();\n this.styleRenderMap = new Map();\n this.dirtyBounds = new Bounds();\n this.backupDirtyBounds = new Bounds();\n this.global = application.global;\n this.layerService = application.layerService;\n this.init();\n }\n\n init() {\n this.contributions.forEach(item => {\n if (item.style) {\n const map = this.styleRenderMap.get(item.style) || new Map();\n map.set(item.numberType, item);\n this.styleRenderMap.set(item.style, map);\n } else {\n this.defaultRenderMap.set(item.numberType, item);\n }\n });\n this.InterceptorContributions = this.drawItemInterceptorContributions\n .getContributions()\n .sort((a, b) => a.order - b.order);\n }\n\n prepareForDraw(renderService: IRenderService, drawContext: IDrawContext) {\n // 有dirtyBounds用dirtyBounds\n if (drawContext.updateBounds) {\n this.useDirtyBounds = true;\n } else {\n // 没有的话,看看是否需要跳过outRange的渲染\n this.useDirtyBounds = !drawContext.stage.params.optimize.disableCheckGraphicWidthOutRange;\n }\n }\n\n draw(renderService: IRenderService, drawContext: IDrawContext): MaybePromise<void> {\n this.prepareForDraw(renderService, drawContext);\n drawContext.drawContribution = this;\n this.currentRenderMap = this.styleRenderMap.get(drawContext.renderStyle) || this.defaultRenderMap;\n // this.startAtId = drawParams.startAtId;\n this.currentRenderService = renderService;\n // this.drawParams = drawParams;\n const { context, stage, x = 0, y = 0, width, height } = drawContext;\n\n if (!context) {\n return;\n }\n // if (context.drawPromise) {\n // return;\n // }\n const dirtyBounds: IBounds | undefined = this.dirtyBounds.setValue(0, 0, width, height);\n if (stage.dirtyBounds && !stage.dirtyBounds.empty()) {\n const b = getRectIntersect(dirtyBounds, stage.dirtyBounds, false);\n dirtyBounds.x1 = Math.floor(b.x1);\n dirtyBounds.y1 = Math.floor(b.y1);\n dirtyBounds.x2 = Math.ceil(b.x2);\n dirtyBounds.y2 = Math.ceil(b.y2);\n }\n // 如果dpr不是整数或者.5的小数,需要格式化dirtyBounds\n const d = context.dpr % 1;\n if (d || d !== 0.5) {\n dirtyBounds.x1 = Math.floor(dirtyBounds.x1 * context.dpr) / context.dpr;\n dirtyBounds.y1 = Math.floor(dirtyBounds.y1 * context.dpr) / context.dpr;\n dirtyBounds.x2 = Math.ceil(dirtyBounds.x2 * context.dpr) / context.dpr;\n dirtyBounds.y2 = Math.ceil(dirtyBounds.y2 * context.dpr) / context.dpr;\n }\n this.backupDirtyBounds.copy(dirtyBounds);\n context.inuse = true;\n // 初始化context\n context.clearMatrix();\n context.setTransformForCurrent(true);\n\n const drawInArea =\n dirtyBounds.width() * context.dpr !== context.canvas.width ||\n dirtyBounds.height() * context.dpr !== context.canvas.height;\n context.save();\n\n // 设置translate\n context.translate(x, y, true);\n if (drawInArea) {\n context.beginPath();\n context.rect(dirtyBounds.x1, dirtyBounds.y1, dirtyBounds.width(), dirtyBounds.height());\n context.clip();\n }\n\n // 如果存在3d视角,那么不使用dirtyBounds\n if (stage.camera) {\n this.dirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n this.backupDirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n }\n\n this.clearScreen(renderService, context, drawContext);\n // // 渲染的时候图元的起始位置就是x,y\n // this.backupDirtyBounds.translate(-x, -y);\n // this.dirtyBounds.translate(-x, -y);\n\n // // 设置translate\n // context.translate(x, y, true);\n\n context.save();\n renderService.renderTreeRoots\n .sort((a, b) => {\n return (a.attribute.zIndex ?? DefaultAttribute.zIndex) - (b.attribute.zIndex ?? DefaultAttribute.zIndex);\n })\n .forEach(group => {\n this.renderGroup(group as IGroup, drawContext, matrixAllocate.allocate(1, 0, 0, 1, 0, 0));\n });\n\n context.restore();\n context.restore();\n context.draw();\n // this.break = false;\n context.inuse = false;\n }\n\n doRegister() {\n throw new Error('暂不支持');\n }\n\n // 找到下一个graphic\n protected _findNextGraphic(group: IGroup): IGraphic | null {\n let parent = group.parent;\n let id = group._uid;\n while (parent) {\n const g = findNextGraphic(parent, id, DefaultAttribute.zIndex);\n if (g) {\n return g;\n }\n id = parent._uid;\n parent = parent.parent;\n }\n return null;\n }\n\n renderGroup(group: IGroup, drawContext: IDrawContext, parentMatrix: IMatrix, skipSort?: boolean) {\n if (drawContext.break || group.attribute.visibleAll === false) {\n return;\n }\n if (group.incremental && (drawContext.startAtId == null || drawContext.startAtId === group._uid)) {\n drawContext.break = true;\n this._increaseRender(group, drawContext);\n return;\n }\n\n if (this.useDirtyBounds && !isRectIntersect(group.AABBBounds, this.dirtyBounds, false)) {\n return;\n }\n\n let nextM: IMatrix = parentMatrix;\n let tempBounds: IBounds;\n\n if (this.useDirtyBounds) {\n tempBounds = boundsAllocate.allocateByObj(this.dirtyBounds);\n // 变换dirtyBounds\n const gm = group.transMatrix;\n nextM = matrixAllocate.allocateByObj(parentMatrix).multiply(gm.a, gm.b, gm.c, gm.d, gm.e, gm.f);\n // const m = group.globalTransMatrix.getInverse();\n this.dirtyBounds.copy(this.backupDirtyBounds).transformWithMatrix(nextM.getInverse());\n }\n\n this.renderItem(group, drawContext, {\n drawingCb: () => {\n skipSort\n ? group.forEachChildren((item: IGraphic) => {\n if (drawContext.break) {\n return;\n }\n if (item.isContainer) {\n this.renderGroup(item as IGroup, drawContext, nextM);\n } else {\n this.renderItem(item, drawContext);\n }\n })\n : foreach(\n group,\n DefaultAttribute.zIndex,\n (item: IGraphic) => {\n if (drawContext.break) {\n return;\n }\n if (item.isContainer) {\n this.renderGroup(item as IGroup, drawContext, nextM);\n } else {\n this.renderItem(item, drawContext);\n }\n },\n false,\n !!drawContext.context?.camera\n );\n }\n });\n\n if (this.useDirtyBounds) {\n this.dirtyBounds.copy(tempBounds);\n boundsAllocate.free(tempBounds);\n matrixAllocate.free(nextM);\n }\n }\n\n protected _increaseRender(group: IGroup, drawContext: IDrawContext) {\n const { layer, stage } = drawContext;\n const { subLayers } = layer;\n // 获取渐进渲染层\n let incrementalLayer = subLayers.get(group._uid);\n if (!incrementalLayer) {\n incrementalLayer = {\n layer: this.layerService.createLayer(stage),\n zIndex: subLayers.size,\n group\n };\n subLayers.set(group._uid, incrementalLayer);\n }\n // 渲染\n const incrementalContext = incrementalLayer.layer.getNativeHandler().getContext();\n const idc = incrementalLayer.drawContribution || container.get(IncrementalDrawContribution);\n idc.dirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n idc.backupDirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n (idc as any).draw(this.currentRenderService, {\n ...drawContext,\n drawContribution: idc,\n clear: 'transparent',\n layer: incrementalLayer.layer,\n context: incrementalContext,\n startAtId: group._uid,\n break: false\n });\n incrementalLayer.drawContribution = idc;\n // this.draw(this.currentRenderService, {...this.drawParams, startAtId: group._uid})\n // this.draw(this.currentRenderService, {...this.drawParams, clear: 'transparent', layer: incrementalContext.layer, context: incrementalContext, startAtId: group._uid})\n const nextGraphic = this._findNextGraphic(group);\n if (nextGraphic) {\n // 如果是下一个渐进渲染层,那就再来一次\n if (nextGraphic.isContainer && nextGraphic.incremental) {\n this._increaseRender(nextGraphic as IGroup, drawContext);\n } else {\n // 如果不是渐进渲染层,那就默认图层渲染\n let afterLayer = subLayers.get(nextGraphic._uid);\n if (!afterLayer) {\n afterLayer = {\n layer: this.layerService.createLayer(stage),\n zIndex: subLayers.size\n };\n subLayers.set(nextGraphic._uid, afterLayer);\n }\n const afterContext = afterLayer.layer.getNativeHandler().getContext();\n this.draw(this.currentRenderService, {\n ...drawContext,\n drawContribution: idc,\n clear: 'transparent',\n layer: afterLayer.layer,\n context: afterContext,\n startAtId: nextGraphic._uid,\n break: false\n });\n }\n }\n }\n\n getRenderContribution(graphic: IGraphic): IGraphicRender | null {\n // let renderer = this.renderSelector.selector(graphic);\n let renderer;\n if (!renderer) {\n renderer = this.selectRenderByNumberType(graphic.numberType);\n }\n if (!renderer) {\n renderer = this.selectRenderByType(graphic.type);\n }\n return renderer;\n }\n\n renderItem(graphic: IGraphic, drawContext: IDrawContext, params?: IGraphicRenderDrawParams) {\n // 添加拦截器\n if (this.InterceptorContributions.length) {\n for (let i = 0; i < this.InterceptorContributions.length; i++) {\n const drawContribution = this.InterceptorContributions[i];\n if (\n drawContribution.beforeDrawItem &&\n drawContribution.beforeDrawItem(graphic, this.currentRenderService, drawContext, this, params)\n ) {\n return;\n }\n }\n }\n\n const renderer = this.getRenderContribution(graphic);\n if (!renderer) {\n return;\n }\n\n let retrans: boolean = false;\n let tempBounds: IAABBBounds;\n\n if (graphic.parent) {\n const { scrollX = 0, scrollY = 0 } = graphic.parent.attribute;\n retrans = !!(scrollX || scrollY);\n if (retrans) {\n tempBounds = this.dirtyBounds.clone();\n // 变换dirtyBounds\n const m = graphic.globalTransMatrix.getInverse();\n this.dirtyBounds.copy(this.backupDirtyBounds).transformWithMatrix(m);\n this.dirtyBounds.translate(-scrollX, -scrollY);\n }\n }\n\n if (this.useDirtyBounds && !(graphic.isContainer || isRectIntersect(graphic.AABBBounds, this.dirtyBounds, false))) {\n retrans && this.dirtyBounds.copy(tempBounds);\n return;\n }\n\n const skipDraw = drawContext.startAtId != null && graphic._uid !== drawContext.startAtId;\n if (graphic._uid === drawContext.startAtId) {\n drawContext.startAtId = null;\n }\n params && (params.skipDraw = skipDraw);\n if (skipDraw) {\n graphic.isContainer && renderer.draw(graphic, this.currentRenderService, drawContext, params);\n } else {\n renderer.draw(graphic, this.currentRenderService, drawContext, params);\n }\n\n retrans && this.dirtyBounds.copy(tempBounds);\n\n // 添加拦截器\n if (this.InterceptorContributions.length) {\n for (let i = 0; i < this.InterceptorContributions.length; i++) {\n const drawContribution = this.InterceptorContributions[i];\n if (drawContribution.afterDrawItem) {\n if (drawContribution.afterDrawItem(graphic, this.currentRenderService, drawContext, this)) {\n return;\n }\n }\n }\n }\n }\n // 根据type选择对应的render\n protected selectRenderByType(type?: string): IGraphicRender | null {\n Logger.getInstance().warn('未知错误,不应该走到这里');\n return null;\n }\n // 根据type选择对应的render\n protected selectRenderByNumberType(type?: number): IGraphicRender | null {\n return this.currentRenderMap.get(type) || this.defaultRenderMap.get(type);\n }\n\n protected clearScreen(renderService: IRenderService, context: IContext2d, drawContext: IDrawContext) {\n const { clear } = drawContext;\n if (clear) {\n const canvas = context.getCanvas();\n const { width = canvas.width, height = canvas.height } = drawContext;\n const x = 0;\n const y = 0;\n context.clearRect(x, y, width, height);\n const stage = renderService.drawParams?.stage;\n if (stage && (stage as any).backgroundImg && (stage as any).resources) {\n const res = (stage as any).resources.get(clear);\n if (res && res.state === 'success' && res.data) {\n context.drawImage(res.data, x, y, width, height);\n }\n } else {\n context.fillStyle = createColor(\n context,\n clear,\n {\n AABBBounds: { x1: x, y1: y, x2: x + width, y2: y + height }\n },\n 0,\n 0\n );\n context.fillRect(x, y, width, height);\n }\n }\n }\n\n afterDraw(renderService: IRenderService, drawParams: IDrawContext) {\n return;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/render/contributions/render/draw-contribution.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAgBxF,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,eAAe,EAAQ,MAAM,kBAAkB,CAAC;AAE3F,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAkB,MAAM,UAAU,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAM5C,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAclC,YAIiD,aAA+B,EAK3D,gCAAyF;QAL7D,kBAAa,GAAb,aAAa,CAAkB;QAK3D,qCAAgC,GAAhC,gCAAgC,CAAyD;QAE5G,IAAI,CAAC,gBAAgB,GAAG,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AAa,CAAC,SAAS,EAAE;gBACrE,MAAM,GAAG,GAAI,KAAa,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAChD,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,EAAE;oBAC9C,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;iBAClD;aACF;iBAAM;gBACL,OAAO,CAAC,SAAS,GAAG,WAAW,CAC7B,OAAO,EACP,KAAK,EACL;oBACE,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,EAAE;iBAC5D,EACD,CAAC,EACD,CAAC,CACF,CAAC;gBACF,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;aACvC;SACF;IACH,CAAC;IAED,SAAS,CAAC,aAA6B,EAAE,UAAwB;QAC/D,OAAO;IACT,CAAC;CACF,CAAA;AAnZY,uBAAuB;IADnC,UAAU,EAAE;IAmBR,WAAA,WAAW,CAAC,aAAa,CAAC,CAAA;IAG1B,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAC5B,WAAA,KAAK,CAAC,mBAAmB,CAAC,CAAA;;GAtBlB,uBAAuB,CAmZnC;SAnZY,uBAAuB","file":"draw-contribution.js","sourcesContent":["import { injectable, inject, named, multiInject } from '../../../common/inversify-lite';\nimport type {\n IContext2d,\n MaybePromise,\n IGraphic,\n IGroup,\n IDrawContext,\n IRenderService,\n IGraphicRender,\n IGraphicRenderDrawParams,\n IContributionProvider,\n IDrawItemInterceptorContribution,\n IDrawContribution,\n IRenderSelector,\n IGlobal\n} from '../../../interface';\nimport { findNextGraphic, foreach } from '../../../common/sort';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../../../common/contribution-provider';\nimport { DefaultAttribute } from '../../../graphic';\nimport type { IAABBBounds, IBounds, IBoundsLike, IMatrix, IMatrixLike } from '@visactor/vutils';\nimport { Bounds, Logger, getRectIntersect, isRectIntersect, last } from '@visactor/vutils';\nimport { LayerService } from '../../../core/constants';\nimport { container } from '../../../container';\nimport { GraphicRender, IncrementalDrawContribution, RenderSelector } from './symbol';\nimport { DrawItemInterceptor } from './draw-interceptor';\nimport { createColor } from '../../../common/canvas-utils';\nimport type { ILayerService } from '../../../interface/core';\nimport { boundsAllocate } from '../../../allocator/bounds-allocate';\nimport { matrixAllocate } from '../../../allocator/matrix-allocate';\nimport { application } from '../../../application';\n\n/**\n * 默认的渲染contribution,基于树状结构针对图元的渲染\n */\n@injectable()\nexport class DefaultDrawContribution implements IDrawContribution {\n declare currentRenderMap: Map<number, IGraphicRender>;\n declare defaultRenderMap: Map<number, IGraphicRender>;\n declare styleRenderMap: Map<string, Map<number, IGraphicRender>>;\n declare dirtyBounds: IBounds;\n declare backupDirtyBounds: IBounds;\n // 是否使用dirtyBounds\n declare useDirtyBounds: boolean;\n declare currentRenderService: IRenderService;\n declare InterceptorContributions: IDrawItemInterceptorContribution[];\n\n declare global: IGlobal;\n declare layerService: ILayerService;\n\n constructor(\n // @inject(ContributionProvider)\n // @named(GraphicRender)\n // protected readonly contributions: ContributionProvider<IGraphicRender>,\n @multiInject(GraphicRender) protected readonly contributions: IGraphicRender[],\n // @inject(RenderSelector) protected readonly renderSelector: IRenderSelector, // 根据图元类型选择对应的renderItem进行渲染\n // 拦截器\n @inject(ContributionProvider)\n @named(DrawItemInterceptor)\n protected readonly drawItemInterceptorContributions: IContributionProvider<IDrawItemInterceptorContribution>\n ) {\n this.currentRenderMap = new Map();\n this.defaultRenderMap = new Map();\n this.styleRenderMap = new Map();\n this.dirtyBounds = new Bounds();\n this.backupDirtyBounds = new Bounds();\n this.global = application.global;\n this.layerService = application.layerService;\n this.init();\n }\n\n init() {\n this.contributions.forEach(item => {\n if (item.style) {\n const map = this.styleRenderMap.get(item.style) || new Map();\n map.set(item.numberType, item);\n this.styleRenderMap.set(item.style, map);\n } else {\n this.defaultRenderMap.set(item.numberType, item);\n }\n });\n this.InterceptorContributions = this.drawItemInterceptorContributions\n .getContributions()\n .sort((a, b) => a.order - b.order);\n }\n\n prepareForDraw(renderService: IRenderService, drawContext: IDrawContext) {\n // 有dirtyBounds用dirtyBounds\n if (drawContext.updateBounds) {\n this.useDirtyBounds = true;\n } else {\n // 没有的话,看看是否需要跳过outRange的渲染\n this.useDirtyBounds = !drawContext.stage.params.optimize.disableCheckGraphicWidthOutRange;\n }\n }\n\n draw(renderService: IRenderService, drawContext: IDrawContext): MaybePromise<void> {\n this.prepareForDraw(renderService, drawContext);\n drawContext.drawContribution = this;\n this.currentRenderMap = this.styleRenderMap.get(drawContext.renderStyle) || this.defaultRenderMap;\n // this.startAtId = drawParams.startAtId;\n this.currentRenderService = renderService;\n // this.drawParams = drawParams;\n const { context, stage, x = 0, y = 0, width, height } = drawContext;\n\n if (!context) {\n return;\n }\n // if (context.drawPromise) {\n // return;\n // }\n const dirtyBounds: IBounds | undefined = this.dirtyBounds.setValue(0, 0, width, height);\n if (stage.dirtyBounds && !stage.dirtyBounds.empty()) {\n const b = getRectIntersect(dirtyBounds, stage.dirtyBounds, false);\n dirtyBounds.x1 = Math.floor(b.x1);\n dirtyBounds.y1 = Math.floor(b.y1);\n dirtyBounds.x2 = Math.ceil(b.x2);\n dirtyBounds.y2 = Math.ceil(b.y2);\n }\n // 如果dpr不是整数或者.5的小数,需要格式化dirtyBounds\n const d = context.dpr % 1;\n if (d || d !== 0.5) {\n dirtyBounds.x1 = Math.floor(dirtyBounds.x1 * context.dpr) / context.dpr;\n dirtyBounds.y1 = Math.floor(dirtyBounds.y1 * context.dpr) / context.dpr;\n dirtyBounds.x2 = Math.ceil(dirtyBounds.x2 * context.dpr) / context.dpr;\n dirtyBounds.y2 = Math.ceil(dirtyBounds.y2 * context.dpr) / context.dpr;\n }\n this.backupDirtyBounds.copy(dirtyBounds);\n context.inuse = true;\n // 初始化context\n context.clearMatrix();\n context.setTransformForCurrent(true);\n\n const drawInArea =\n dirtyBounds.width() * context.dpr < context.canvas.width ||\n dirtyBounds.height() * context.dpr < context.canvas.height;\n context.save();\n\n // 设置translate\n context.translate(x, y, true);\n if (drawInArea) {\n context.beginPath();\n context.rect(dirtyBounds.x1, dirtyBounds.y1, dirtyBounds.width(), dirtyBounds.height());\n context.clip();\n }\n\n // 如果存在3d视角,那么不使用dirtyBounds\n if (stage.camera) {\n this.dirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n this.backupDirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n }\n\n this.clearScreen(renderService, context, drawContext);\n // // 渲染的时候图元的起始位置就是x,y\n // this.backupDirtyBounds.translate(-x, -y);\n // this.dirtyBounds.translate(-x, -y);\n\n // // 设置translate\n // context.translate(x, y, true);\n\n context.save();\n renderService.renderTreeRoots\n .sort((a, b) => {\n return (a.attribute.zIndex ?? DefaultAttribute.zIndex) - (b.attribute.zIndex ?? DefaultAttribute.zIndex);\n })\n .forEach(group => {\n group.isContainer\n ? this.renderGroup(group as IGroup, drawContext, matrixAllocate.allocate(1, 0, 0, 1, 0, 0))\n : this.renderItem(group as IGraphic, drawContext);\n });\n\n context.restore();\n context.restore();\n context.draw();\n // this.break = false;\n context.inuse = false;\n }\n\n doRegister() {\n throw new Error('暂不支持');\n }\n\n // 找到下一个graphic\n protected _findNextGraphic(group: IGroup): IGraphic | null {\n let parent = group.parent;\n let id = group._uid;\n while (parent) {\n const g = findNextGraphic(parent, id, DefaultAttribute.zIndex);\n if (g) {\n return g;\n }\n id = parent._uid;\n parent = parent.parent;\n }\n return null;\n }\n\n renderGroup(group: IGroup, drawContext: IDrawContext, parentMatrix: IMatrix, skipSort?: boolean) {\n if (drawContext.break || group.attribute.visibleAll === false) {\n return;\n }\n if (group.incremental && (drawContext.startAtId == null || drawContext.startAtId === group._uid)) {\n drawContext.break = true;\n this._increaseRender(group, drawContext);\n return;\n }\n\n if (this.useDirtyBounds && !isRectIntersect(group.AABBBounds, this.dirtyBounds, false)) {\n return;\n }\n\n let nextM: IMatrix = parentMatrix;\n let tempBounds: IBounds;\n\n if (this.useDirtyBounds) {\n tempBounds = boundsAllocate.allocateByObj(this.dirtyBounds);\n // 变换dirtyBounds\n const gm = group.transMatrix;\n nextM = matrixAllocate.allocateByObj(parentMatrix).multiply(gm.a, gm.b, gm.c, gm.d, gm.e, gm.f);\n // const m = group.globalTransMatrix.getInverse();\n this.dirtyBounds.copy(this.backupDirtyBounds).transformWithMatrix(nextM.getInverse());\n }\n\n this.renderItem(group, drawContext, {\n drawingCb: () => {\n skipSort\n ? group.forEachChildren((item: IGraphic) => {\n if (drawContext.break) {\n return;\n }\n if (item.isContainer) {\n this.renderGroup(item as IGroup, drawContext, nextM);\n } else {\n this.renderItem(item, drawContext);\n }\n })\n : foreach(\n group,\n DefaultAttribute.zIndex,\n (item: IGraphic) => {\n if (drawContext.break) {\n return;\n }\n if (item.isContainer) {\n this.renderGroup(item as IGroup, drawContext, nextM);\n } else {\n this.renderItem(item, drawContext);\n }\n },\n false,\n !!drawContext.context?.camera\n );\n }\n });\n\n if (this.useDirtyBounds) {\n this.dirtyBounds.copy(tempBounds);\n boundsAllocate.free(tempBounds);\n matrixAllocate.free(nextM);\n }\n }\n\n protected _increaseRender(group: IGroup, drawContext: IDrawContext) {\n const { layer, stage } = drawContext;\n const { subLayers } = layer;\n // 获取渐进渲染层\n let incrementalLayer = subLayers.get(group._uid);\n if (!incrementalLayer) {\n incrementalLayer = {\n layer: this.layerService.createLayer(stage),\n zIndex: subLayers.size,\n group\n };\n subLayers.set(group._uid, incrementalLayer);\n }\n // 渲染\n const incrementalContext = incrementalLayer.layer.getNativeHandler().getContext();\n const idc = incrementalLayer.drawContribution || container.get(IncrementalDrawContribution);\n idc.dirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n idc.backupDirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n (idc as any).draw(this.currentRenderService, {\n ...drawContext,\n drawContribution: idc,\n clear: 'transparent',\n layer: incrementalLayer.layer,\n context: incrementalContext,\n startAtId: group._uid,\n break: false\n });\n incrementalLayer.drawContribution = idc;\n // this.draw(this.currentRenderService, {...this.drawParams, startAtId: group._uid})\n // this.draw(this.currentRenderService, {...this.drawParams, clear: 'transparent', layer: incrementalContext.layer, context: incrementalContext, startAtId: group._uid})\n const nextGraphic = this._findNextGraphic(group);\n if (nextGraphic) {\n // 如果是下一个渐进渲染层,那就再来一次\n if (nextGraphic.isContainer && nextGraphic.incremental) {\n this._increaseRender(nextGraphic as IGroup, drawContext);\n } else {\n // 如果不是渐进渲染层,那就默认图层渲染\n let afterLayer = subLayers.get(nextGraphic._uid);\n if (!afterLayer) {\n afterLayer = {\n layer: this.layerService.createLayer(stage),\n zIndex: subLayers.size\n };\n subLayers.set(nextGraphic._uid, afterLayer);\n }\n const afterContext = afterLayer.layer.getNativeHandler().getContext();\n this.draw(this.currentRenderService, {\n ...drawContext,\n drawContribution: idc,\n clear: 'transparent',\n layer: afterLayer.layer,\n context: afterContext,\n startAtId: nextGraphic._uid,\n break: false\n });\n }\n }\n }\n\n getRenderContribution(graphic: IGraphic): IGraphicRender | null {\n // let renderer = this.renderSelector.selector(graphic);\n let renderer;\n if (!renderer) {\n renderer = this.selectRenderByNumberType(graphic.numberType);\n }\n if (!renderer) {\n renderer = this.selectRenderByType(graphic.type);\n }\n return renderer;\n }\n\n renderItem(graphic: IGraphic, drawContext: IDrawContext, params?: IGraphicRenderDrawParams) {\n // 添加拦截器\n if (this.InterceptorContributions.length) {\n for (let i = 0; i < this.InterceptorContributions.length; i++) {\n const drawContribution = this.InterceptorContributions[i];\n if (\n drawContribution.beforeDrawItem &&\n drawContribution.beforeDrawItem(graphic, this.currentRenderService, drawContext, this, params)\n ) {\n return;\n }\n }\n }\n\n const renderer = this.getRenderContribution(graphic);\n if (!renderer) {\n return;\n }\n\n let retrans: boolean = false;\n let tempBounds: IAABBBounds;\n\n if (graphic.parent) {\n const { scrollX = 0, scrollY = 0 } = graphic.parent.attribute;\n retrans = !!(scrollX || scrollY);\n if (retrans) {\n tempBounds = this.dirtyBounds.clone();\n // 变换dirtyBounds\n const m = graphic.globalTransMatrix.getInverse();\n this.dirtyBounds.copy(this.backupDirtyBounds).transformWithMatrix(m);\n this.dirtyBounds.translate(-scrollX, -scrollY);\n }\n }\n\n if (this.useDirtyBounds && !(graphic.isContainer || isRectIntersect(graphic.AABBBounds, this.dirtyBounds, false))) {\n retrans && this.dirtyBounds.copy(tempBounds);\n return;\n }\n\n const skipDraw = drawContext.startAtId != null && graphic._uid !== drawContext.startAtId;\n if (graphic._uid === drawContext.startAtId) {\n drawContext.startAtId = null;\n }\n params && (params.skipDraw = skipDraw);\n if (skipDraw) {\n graphic.isContainer && renderer.draw(graphic, this.currentRenderService, drawContext, params);\n } else {\n renderer.draw(graphic, this.currentRenderService, drawContext, params);\n }\n\n retrans && this.dirtyBounds.copy(tempBounds);\n\n // 添加拦截器\n if (this.InterceptorContributions.length) {\n for (let i = 0; i < this.InterceptorContributions.length; i++) {\n const drawContribution = this.InterceptorContributions[i];\n if (drawContribution.afterDrawItem) {\n if (drawContribution.afterDrawItem(graphic, this.currentRenderService, drawContext, this)) {\n return;\n }\n }\n }\n }\n }\n // 根据type选择对应的render\n protected selectRenderByType(type?: string): IGraphicRender | null {\n Logger.getInstance().warn('未知错误,不应该走到这里');\n return null;\n }\n // 根据type选择对应的render\n protected selectRenderByNumberType(type?: number): IGraphicRender | null {\n return this.currentRenderMap.get(type) || this.defaultRenderMap.get(type);\n }\n\n protected clearScreen(renderService: IRenderService, context: IContext2d, drawContext: IDrawContext) {\n const { clear } = drawContext;\n if (clear) {\n const canvas = context.getCanvas();\n const { width = canvas.width, height = canvas.height } = drawContext;\n const x = 0;\n const y = 0;\n context.clearRect(x, y, width, height);\n const stage = renderService.drawParams?.stage;\n if (stage && (stage as any).backgroundImg && (stage as any).resources) {\n const res = (stage as any).resources.get(clear);\n if (res && res.state === 'success' && res.data) {\n context.drawImage(res.data, x, y, width, height);\n }\n } else {\n context.fillStyle = createColor(\n context,\n clear,\n {\n AABBBounds: { x1: x, y1: y, x2: x + width, y2: y + height }\n },\n 0,\n 0\n );\n context.fillRect(x, y, width, height);\n }\n }\n }\n\n afterDraw(renderService: IRenderService, drawParams: IDrawContext) {\n return;\n }\n}\n"]}
|