@visactor/vrender-core 1.0.43 → 1.0.45
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/canvas/constants.js +2 -1
- package/cjs/color-string/index.js +1 -2
- package/cjs/common/event-transformer.js +1 -2
- package/cjs/common/generator.js +2 -1
- package/cjs/common/render-area.js +1 -1
- package/cjs/common/render-command-list.js +1 -1
- package/cjs/common/render-curve.js +1 -1
- package/cjs/common/render-utils.js +1 -1
- package/cjs/common/seg-context.js +1 -1
- package/cjs/common/simplify.js +1 -1
- package/cjs/common/sort.js +1 -1
- package/cjs/common/split-path.js +1 -1
- package/cjs/common/store.js +1 -1
- package/cjs/common/text.js +2 -1
- package/cjs/common/utils.js +1 -1
- package/cjs/core/constants.js +1 -1
- package/cjs/core/core-modules.js +1 -1
- package/cjs/core/global-module.js +0 -2
- package/cjs/core/global.js +1 -1
- package/cjs/core/graphic-utils.js +1 -1
- package/cjs/core/index.js +1 -1
- package/cjs/core/layer-service.js +1 -2
- package/cjs/core/layer.d.ts +1 -1
- package/cjs/core/layer.js +1 -1
- package/cjs/core/layer.js.map +1 -1
- package/cjs/core/light.js +1 -1
- package/cjs/core/stage.d.ts +5 -3
- package/cjs/core/stage.js +17 -5
- package/cjs/core/stage.js.map +1 -1
- package/cjs/core/window.js +1 -1
- package/cjs/graphic/config.js +7 -1
- package/cjs/graphic/config.js.map +1 -1
- package/cjs/graphic/graphic.js +5 -2
- package/cjs/graphic/graphic.js.map +1 -1
- package/cjs/graphic/image.d.ts +1 -0
- package/cjs/graphic/image.js +2 -1
- package/cjs/graphic/image.js.map +1 -1
- package/cjs/interface/graphic/image.d.ts +7 -1
- package/cjs/interface/graphic/image.js.map +1 -1
- package/cjs/interface/graphic.d.ts +14 -2
- package/cjs/interface/graphic.js.map +1 -1
- package/cjs/interface/layer.d.ts +3 -2
- package/cjs/interface/layer.js.map +1 -1
- package/cjs/interface/render.d.ts +1 -1
- package/cjs/interface/render.js.map +1 -1
- package/cjs/interface/stage.d.ts +3 -2
- package/cjs/interface/stage.js.map +1 -1
- package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +27 -9
- package/cjs/render/contributions/render/contributions/base-contribution-render.js +147 -34
- package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/group-contribution-render.js +8 -6
- package/cjs/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/text-contribution-render.js +20 -17
- package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/draw-contribution.js +16 -5
- package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
- package/cjs/render/contributions/render/image-render.d.ts +14 -1
- package/cjs/render/contributions/render/image-render.js +99 -20
- package/cjs/render/contributions/render/image-render.js.map +1 -1
- package/dist/index.es.js +414 -114
- package/es/canvas/constants.js +2 -1
- package/es/color-string/index.js +1 -2
- package/es/common/event-transformer.js +1 -2
- package/es/common/generator.js +2 -1
- package/es/common/render-area.js +1 -1
- package/es/common/render-command-list.js +1 -1
- package/es/common/render-curve.js +1 -1
- package/es/common/render-utils.js +1 -1
- package/es/common/seg-context.js +1 -1
- package/es/common/simplify.js +1 -1
- package/es/common/sort.js +1 -1
- package/es/common/split-path.js +1 -1
- package/es/common/store.js +1 -1
- package/es/common/text.js +2 -1
- package/es/common/utils.js +1 -1
- package/es/core/constants.js +1 -1
- package/es/core/core-modules.js +1 -1
- package/es/core/global-module.js +0 -2
- package/es/core/global.js +1 -1
- package/es/core/graphic-utils.js +1 -1
- package/es/core/index.js +1 -1
- package/es/core/layer-service.js +1 -2
- package/es/core/layer.d.ts +1 -1
- package/es/core/layer.js +1 -1
- package/es/core/layer.js.map +1 -1
- package/es/core/light.js +1 -1
- package/es/core/stage.d.ts +5 -3
- package/es/core/stage.js +17 -6
- package/es/core/stage.js.map +1 -1
- package/es/core/window.js +1 -1
- package/es/graphic/config.js +7 -1
- package/es/graphic/config.js.map +1 -1
- package/es/graphic/graphic.js +4 -2
- package/es/graphic/graphic.js.map +1 -1
- package/es/graphic/image.d.ts +1 -0
- package/es/graphic/image.js +2 -1
- package/es/graphic/image.js.map +1 -1
- package/es/interface/graphic/image.d.ts +7 -1
- package/es/interface/graphic/image.js.map +1 -1
- package/es/interface/graphic.d.ts +14 -2
- package/es/interface/graphic.js.map +1 -1
- package/es/interface/layer.d.ts +3 -2
- package/es/interface/layer.js.map +1 -1
- package/es/interface/render.d.ts +1 -1
- package/es/interface/render.js.map +1 -1
- package/es/interface/stage.d.ts +3 -2
- package/es/interface/stage.js.map +1 -1
- package/es/render/contributions/render/contributions/base-contribution-render.d.ts +27 -9
- package/es/render/contributions/render/contributions/base-contribution-render.js +140 -33
- package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/group-contribution-render.js +9 -7
- package/es/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/text-contribution-render.js +20 -16
- package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
- package/es/render/contributions/render/draw-contribution.js +17 -4
- package/es/render/contributions/render/draw-contribution.js.map +1 -1
- package/es/render/contributions/render/image-render.d.ts +14 -1
- package/es/render/contributions/render/image-render.js +93 -18
- package/es/render/contributions/render/image-render.js.map +1 -1
- package/package.json +2 -2
|
@@ -14,9 +14,81 @@ var __decorate = this && this.__decorate || function(decorators, target, key, de
|
|
|
14
14
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", {
|
|
16
16
|
value: !0
|
|
17
|
-
}), exports.DefaultCanvasImageRender = void 0;
|
|
17
|
+
}), exports.DefaultCanvasImageRender = exports.drawImageWithLayout = exports.shouldClipImageByLayout = exports.resolveImageRepeatMode = exports.resolveBackgroundParamsByImageSizing = exports.resolveImageMode = void 0;
|
|
18
18
|
|
|
19
|
-
const inversify_lite_1 = require("../../../common/inversify-lite"), contribution_provider_1 = require("../../../common/contribution-provider"), theme_1 = require("../../../graphic/theme"), constants_1 = require("./contributions/constants"), constants_2 = require("../../../graphic/constants"), vutils_1 = require("@visactor/vutils"), rect_1 = require("../../../common/shape/rect"), base_render_1 = require("./base-render"), contributions_1 = require("./contributions"), loader_1 = require("../../../resource-loader/loader"), repeatStr = [ "", "repeat-x", "repeat-y", "repeat" ];
|
|
19
|
+
const inversify_lite_1 = require("../../../common/inversify-lite"), contribution_provider_1 = require("../../../common/contribution-provider"), theme_1 = require("../../../graphic/theme"), constants_1 = require("./contributions/constants"), constants_2 = require("../../../graphic/constants"), vutils_1 = require("@visactor/vutils"), rect_1 = require("../../../common/shape/rect"), base_render_1 = require("./base-render"), contributions_1 = require("./contributions"), loader_1 = require("../../../resource-loader/loader"), base_contribution_render_1 = require("./contributions/base-contribution-render"), repeatStr = [ "", "repeat-x", "repeat-y", "repeat" ];
|
|
20
|
+
|
|
21
|
+
function resolveImageMode({repeatX: repeatX = "no-repeat", repeatY: repeatY = "no-repeat", imageMode: imageMode}) {
|
|
22
|
+
const repeatMode = resolveImageRepeatMode(repeatX, repeatY);
|
|
23
|
+
return {
|
|
24
|
+
repeatMode: repeatMode,
|
|
25
|
+
sizingMode: "no-repeat" === repeatMode && null != imageMode ? imageMode : "fill"
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.resolveImageMode = resolveImageMode;
|
|
30
|
+
|
|
31
|
+
const IMAGE_MODE_TO_BACKGROUND_MODE = {
|
|
32
|
+
cover: "no-repeat-cover",
|
|
33
|
+
contain: "no-repeat-contain",
|
|
34
|
+
fill: "no-repeat-fill",
|
|
35
|
+
auto: "no-repeat-auto"
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function resolveBackgroundParamsByImageSizing(sizingMode) {
|
|
39
|
+
return {
|
|
40
|
+
backgroundMode: IMAGE_MODE_TO_BACKGROUND_MODE[sizingMode],
|
|
41
|
+
backgroundFit: !1,
|
|
42
|
+
backgroundKeepAspectRatio: !1
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function resolveImageRepeatMode(repeatX, repeatY) {
|
|
47
|
+
let repeat = 0;
|
|
48
|
+
return "repeat" === repeatX && (repeat |= 1), "repeat" === repeatY && (repeat |= 2),
|
|
49
|
+
repeat ? repeatStr[repeat] : "no-repeat";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function shouldClipImageByLayout({repeatX: repeatX = "no-repeat", repeatY: repeatY = "no-repeat", imageMode: imageMode, imageScale: imageScale = 1, imageOffsetX: imageOffsetX = 0, imageOffsetY: imageOffsetY = 0, imagePosition: imagePosition = "top-left"}) {
|
|
53
|
+
const {repeatMode: repeatMode, sizingMode: sizingMode} = resolveImageMode({
|
|
54
|
+
repeatX: repeatX,
|
|
55
|
+
repeatY: repeatY,
|
|
56
|
+
imageMode: imageMode
|
|
57
|
+
});
|
|
58
|
+
return "no-repeat" === repeatMode && ("cover" === sizingMode || "auto" === sizingMode || 1 !== imageScale || 0 !== imageOffsetX || 0 !== imageOffsetY);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function drawImageWithLayout(context, data, x, y, width, height, {repeatX: repeatX = "no-repeat", repeatY: repeatY = "no-repeat", imageMode: imageMode, imageScale: imageScale = 1, imageOffsetX: imageOffsetX = 0, imageOffsetY: imageOffsetY = 0, imagePosition: imagePosition = "top-left"}) {
|
|
62
|
+
const {repeatMode: repeatMode, sizingMode: sizingMode} = resolveImageMode({
|
|
63
|
+
repeatX: repeatX,
|
|
64
|
+
repeatY: repeatY,
|
|
65
|
+
imageMode: imageMode
|
|
66
|
+
}), imageBackgroundParams = "no-repeat" === repeatMode ? resolveBackgroundParamsByImageSizing(sizingMode) : {
|
|
67
|
+
backgroundMode: repeatMode,
|
|
68
|
+
backgroundFit: !1,
|
|
69
|
+
backgroundKeepAspectRatio: !1
|
|
70
|
+
};
|
|
71
|
+
(0, base_contribution_render_1.drawBackgroundImage)(context, data, {
|
|
72
|
+
x1: x,
|
|
73
|
+
y1: y,
|
|
74
|
+
x2: x + width,
|
|
75
|
+
y2: y + height,
|
|
76
|
+
width: () => width,
|
|
77
|
+
height: () => height
|
|
78
|
+
}, {
|
|
79
|
+
backgroundMode: imageBackgroundParams.backgroundMode,
|
|
80
|
+
backgroundFit: imageBackgroundParams.backgroundFit,
|
|
81
|
+
backgroundKeepAspectRatio: imageBackgroundParams.backgroundKeepAspectRatio,
|
|
82
|
+
backgroundScale: imageScale,
|
|
83
|
+
backgroundOffsetX: imageOffsetX,
|
|
84
|
+
backgroundOffsetY: imageOffsetY,
|
|
85
|
+
backgroundPosition: imagePosition
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exports.resolveBackgroundParamsByImageSizing = resolveBackgroundParamsByImageSizing,
|
|
90
|
+
exports.resolveImageRepeatMode = resolveImageRepeatMode, exports.shouldClipImageByLayout = shouldClipImageByLayout,
|
|
91
|
+
exports.drawImageWithLayout = drawImageWithLayout;
|
|
20
92
|
|
|
21
93
|
let DefaultCanvasImageRender = class extends base_render_1.BaseRender {
|
|
22
94
|
constructor(graphicRenderContributions) {
|
|
@@ -25,7 +97,7 @@ let DefaultCanvasImageRender = class extends base_render_1.BaseRender {
|
|
|
25
97
|
this.init(graphicRenderContributions);
|
|
26
98
|
}
|
|
27
99
|
drawShape(image, context, x, y, drawContext, params, fillCb, strokeCb) {
|
|
28
|
-
const imageAttribute = (0, theme_1.getTheme)(image).image, {repeatX: repeatX = imageAttribute.repeatX, repeatY: repeatY = imageAttribute.repeatY, x: originX = imageAttribute.x, y: originY = imageAttribute.y, cornerRadius: cornerRadius = imageAttribute.cornerRadius, fillStrokeOrder: fillStrokeOrder = imageAttribute.fillStrokeOrder, cornerType: cornerType = imageAttribute.cornerType, image: url} = image.attribute, data = this.valid(image, imageAttribute, fillCb);
|
|
100
|
+
const imageAttribute = (0, theme_1.getTheme)(image).image, {repeatX: repeatX = imageAttribute.repeatX, repeatY: repeatY = imageAttribute.repeatY, x: originX = imageAttribute.x, y: originY = imageAttribute.y, cornerRadius: cornerRadius = imageAttribute.cornerRadius, fillStrokeOrder: fillStrokeOrder = imageAttribute.fillStrokeOrder, cornerType: cornerType = imageAttribute.cornerType, imageMode: imageMode = imageAttribute.imageMode, imageScale: imageScale = imageAttribute.imageScale, imageOffsetX: imageOffsetX = imageAttribute.imageOffsetX, imageOffsetY: imageOffsetY = imageAttribute.imageOffsetY, imagePosition: imagePosition = imageAttribute.imagePosition, image: url} = image.attribute, data = this.valid(image, imageAttribute, fillCb);
|
|
29
101
|
if (!data) return;
|
|
30
102
|
const {fVisible: fVisible, sVisible: sVisible, doFill: doFill, doStroke: doStroke} = data;
|
|
31
103
|
if (!url || !image.resources) return;
|
|
@@ -33,30 +105,37 @@ let DefaultCanvasImageRender = class extends base_render_1.BaseRender {
|
|
|
33
105
|
if ("success" !== res.state) return;
|
|
34
106
|
const width = image.width, height = image.height;
|
|
35
107
|
context.beginPath();
|
|
36
|
-
let
|
|
108
|
+
let needCornerClip = !1;
|
|
37
109
|
0 === cornerRadius || (0, vutils_1.isArray)(cornerRadius) && cornerRadius.every((num => 0 === num)) ? context.rect(x, y, width, height) : ((0,
|
|
38
110
|
rect_1.createRectPath)(context, x, y, width, height, cornerRadius, "bevel" !== cornerType),
|
|
39
|
-
|
|
111
|
+
needCornerClip = !0), context.setShadowBlendStyle && context.setShadowBlendStyle(image, image.attribute, imageAttribute);
|
|
40
112
|
const _runFill = () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
113
|
+
doFill && (fillCb ? fillCb(context, image.attribute, imageAttribute) : fVisible && (context.setCommonStyle(image, image.attribute, x, y, imageAttribute),
|
|
114
|
+
drawImageWithLayout(context, res.data, x, y, width, height, {
|
|
115
|
+
repeatX: repeatX,
|
|
116
|
+
repeatY: repeatY,
|
|
117
|
+
imageMode: imageMode,
|
|
118
|
+
imageScale: imageScale,
|
|
119
|
+
imageOffsetX: imageOffsetX,
|
|
120
|
+
imageOffsetY: imageOffsetY,
|
|
121
|
+
imagePosition: imagePosition
|
|
122
|
+
})));
|
|
51
123
|
}, _runStroke = () => {
|
|
52
124
|
doStroke && (strokeCb ? strokeCb(context, image.attribute, imageAttribute) : sVisible && (context.setStrokeStyle(image, image.attribute, originX - x, originY - y, imageAttribute),
|
|
53
125
|
context.stroke()));
|
|
54
|
-
}
|
|
55
|
-
|
|
126
|
+
}, needLayoutClip = shouldClipImageByLayout({
|
|
127
|
+
repeatX: repeatX,
|
|
128
|
+
repeatY: repeatY,
|
|
129
|
+
imageMode: imageMode,
|
|
130
|
+
imageScale: imageScale,
|
|
131
|
+
imageOffsetX: imageOffsetX,
|
|
132
|
+
imageOffsetY: imageOffsetY,
|
|
133
|
+
imagePosition: imagePosition
|
|
134
|
+
}), needClip = needCornerClip || needLayoutClip;
|
|
135
|
+
fillStrokeOrder ? (_runStroke(), needClip && (context.save(), context.clip()), this.beforeRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb),
|
|
136
|
+
_runFill(), needClip && context.restore()) : (needClip && (context.save(), context.clip()),
|
|
56
137
|
this.beforeRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb),
|
|
57
|
-
_runFill(),
|
|
58
|
-
context.clip()), this.beforeRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb),
|
|
59
|
-
_runFill(), needRestore && context.restore(), _runStroke()), this.afterRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb);
|
|
138
|
+
_runFill(), needClip && context.restore(), _runStroke()), this.afterRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb);
|
|
60
139
|
}
|
|
61
140
|
draw(image, renderService, drawContext) {
|
|
62
141
|
const {image: url} = image.attribute;
|
|
@@ -1 +1 @@
|
|
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,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;YAC5B,OAAO;SACR;QACD,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAIrC,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,IAAA,iBAAQ,EAAC,GAAG,CAAC,EAAE;YAC5C,uBAAc,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;YACxC,OAAO;SACR;aAAM,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE;YAClC,OAAO;SACR;QAED,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,UAAU,CAAC;QAC7C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO;SACR;QACD,MAAM,cAAc,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC,KAAK,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IACxD,CAAC;CACF,CAAA;AAvKY,wBAAwB;IADpC,IAAA,2BAAU,GAAE;IAMR,WAAA,IAAA,uBAAM,EAAC,4CAAoB,CAAC,CAAA;IAC5B,WAAA,IAAA,sBAAK,EAAC,mCAAuB,CAAC,CAAA;;GANtB,wBAAwB,CAuKpC;AAvKY,4DAAwB","file":"image-render.js","sourcesContent":["import { inject, injectable, named } from '../../../common/inversify-lite';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../../../common/contribution-provider';\nimport { getTheme } from '../../../graphic/theme';\nimport type {\n IGraphicAttribute,\n IContext2d,\n IMarkAttribute,\n IImage,\n IThemeAttribute,\n IGraphicRender,\n IImageRenderContribution,\n IContributionProvider,\n IDrawContext,\n IGraphicRenderDrawParams,\n IRenderService\n} from '../../../interface';\nimport { ImageRenderContribution } from './contributions/constants';\nimport { fillVisible, runFill } from './utils';\nimport { IMAGE_NUMBER_TYPE } from '../../../graphic/constants';\nimport { BaseRenderContributionTime } from '../../../common/enums';\nimport { isArray, isString } from '@visactor/vutils';\nimport { createRectPath } from '../../../common/shape/rect';\nimport { BaseRender } from './base-render';\nimport { defaultImageBackgroundRenderContribution, defaultImageRenderContribution } from './contributions';\nimport { ResourceLoader } from '../../../resource-loader/loader';\n\nconst repeatStr = ['', 'repeat-x', 'repeat-y', 'repeat'];\n\n@injectable()\nexport class DefaultCanvasImageRender extends BaseRender<IImage> implements IGraphicRender {\n type: 'image';\n numberType: number = IMAGE_NUMBER_TYPE;\n\n constructor(\n @inject(ContributionProvider)\n @named(ImageRenderContribution)\n protected readonly graphicRenderContributions: IContributionProvider<IImageRenderContribution>\n ) {\n super();\n this.builtinContributions = [defaultImageRenderContribution, defaultImageBackgroundRenderContribution];\n this.init(graphicRenderContributions);\n }\n\n drawShape(\n image: IImage,\n context: IContext2d,\n x: number,\n y: number,\n drawContext: IDrawContext,\n params?: IGraphicRenderDrawParams,\n fillCb?: (\n ctx: IContext2d,\n markAttribute: Partial<IMarkAttribute & IGraphicAttribute>,\n themeAttribute: IThemeAttribute\n ) => boolean,\n strokeCb?: (\n ctx: IContext2d,\n markAttribute: Partial<IMarkAttribute & IGraphicAttribute>,\n themeAttribute: IThemeAttribute\n ) => boolean\n ) {\n // const imageAttribute = graphicService.themeService.getCurrentTheme().imageAttribute;\n const imageAttribute = getTheme(image).image;\n const {\n repeatX = imageAttribute.repeatX,\n repeatY = imageAttribute.repeatY,\n x: originX = imageAttribute.x,\n y: originY = imageAttribute.y,\n cornerRadius = imageAttribute.cornerRadius,\n fillStrokeOrder = imageAttribute.fillStrokeOrder,\n cornerType = imageAttribute.cornerType,\n image: url\n } = image.attribute;\n\n const data = this.valid(image, imageAttribute, fillCb);\n if (!data) {\n return;\n }\n const { fVisible, sVisible, doFill, doStroke } = data;\n\n if (!url || !image.resources) {\n return;\n }\n const res = image.resources.get(url);\n if (res.state !== 'success') {\n return;\n }\n\n const width = image.width;\n const height = image.height;\n context.beginPath();\n\n // deal with cornerRadius\n let needRestore = false;\n if (cornerRadius === 0 || (isArray(cornerRadius) && (<number[]>cornerRadius).every(num => num === 0))) {\n // 不需要处理圆角\n context.rect(x, y, width, height);\n } else {\n // context.beginPath();\n createRectPath(context, x, y, width, height, cornerRadius, cornerType !== 'bevel');\n needRestore = true;\n }\n\n // shadow\n context.setShadowBlendStyle && context.setShadowBlendStyle(image, image.attribute, imageAttribute);\n // context.beginPath();\n // context.image(x, y, width, height);\n\n const _runFill = () => {\n if (doFill) {\n if (fillCb) {\n fillCb(context, image.attribute, imageAttribute);\n } else if (fVisible) {\n context.setCommonStyle(image, image.attribute, x, y, imageAttribute);\n let repeat = 0;\n if (repeatX === 'repeat') {\n repeat |= 0b0001;\n }\n if (repeatY === 'repeat') {\n repeat |= 0b0010;\n }\n if (repeat) {\n const pattern = context.createPattern(res.data, repeatStr[repeat]);\n context.fillStyle = pattern;\n context.translate(x, y, true);\n context.fillRect(0, 0, width, height);\n context.translate(-x, -y, true);\n } else {\n context.drawImage(res.data, x, y, width, height);\n }\n }\n }\n };\n\n const _runStroke = () => {\n if (doStroke) {\n if (strokeCb) {\n strokeCb(context, image.attribute, imageAttribute);\n } else if (sVisible) {\n context.setStrokeStyle(image, image.attribute, originX - x, originY - y, imageAttribute);\n context.stroke();\n }\n }\n };\n\n if (!fillStrokeOrder) {\n if (needRestore) {\n context.save();\n context.clip();\n }\n this.beforeRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);\n _runFill();\n if (needRestore) {\n context.restore();\n }\n _runStroke();\n } else {\n _runStroke();\n if (needRestore) {\n context.save();\n context.clip();\n }\n this.beforeRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);\n _runFill();\n if (needRestore) {\n context.restore();\n }\n }\n\n this.afterRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);\n }\n\n draw(image: IImage, renderService: IRenderService, drawContext: IDrawContext) {\n const { image: url } = image.attribute;\n\n if (!url || !image.resources) {\n return;\n }\n const res = image.resources.get(url);\n // if (res.state !== 'success') {\n // return;\n // }\n if (res.state === 'loading' && isString(url)) {\n ResourceLoader.improveImageLoading(url);\n return;\n } else if (res.state !== 'success') {\n return;\n }\n\n const { context } = renderService.drawParams;\n if (!context) {\n return;\n }\n const imageAttribute = getTheme(image).image;\n this._draw(image, imageAttribute, false, drawContext);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/render/contributions/render/image-render.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA2E;AAE3E,iFAA6E;AAC7E,kDAAkD;AAiBlD,yDAAoE;AACpE,0DAA+D;AAC/D,6CAAqD;AACrD,qDAA4D;AAC5D,+CAA2C;AAC3C,mDAA2G;AAC3G,4DAAiE;AACjE,uFAA+E;AAE/E,MAAM,SAAS,GAAG,CAAC,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAOzD,SAAgB,gBAAgB,CAAC,EAC/B,OAAO,GAAG,WAAW,EACrB,OAAO,GAAG,WAAW,EACrB,SAAS,EACyD;IAIlE,MAAM,UAAU,GAAG,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE5D,OAAO;QACL,UAAU;QACV,UAAU,EAAE,UAAU,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,MAAM,CAAC,CAAC,CAAC,MAAM;KACtE,CAAC;AACJ,CAAC;AAdD,4CAcC;AAED,MAAM,6BAA6B,GAA6C;IAC9E,KAAK,EAAE,iBAAiB;IACxB,OAAO,EAAE,mBAAmB;IAC5B,IAAI,EAAE,gBAAgB;IACtB,IAAI,EAAE,gBAAgB;CACvB,CAAC;AAEF,SAAgB,oCAAoC,CAAC,UAA4B;IAK/E,OAAO;QACL,cAAc,EAAE,6BAA6B,CAAC,UAAU,CAAC;QACzD,aAAa,EAAE,KAAK;QACpB,yBAAyB,EAAE,KAAK;KACjC,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AC,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IAClH,CAAC;IAED,IAAI,CAAC,KAAa,EAAE,aAA6B,EAAE,WAAyB;QAC1E,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC;QAEvC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;YAC5B,OAAO;SACR;QACD,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAIrC,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,IAAA,iBAAQ,EAAC,GAAG,CAAC,EAAE;YAC5C,uBAAc,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;YACxC,OAAO;SACR;aAAM,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE;YAClC,OAAO;SACR;QAED,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,UAAU,CAAC;QAC7C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO;SACR;QACD,MAAM,cAAc,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC,KAAK,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IACxD,CAAC;CACF,CAAA;AAhLY,wBAAwB;IADpC,IAAA,2BAAU,GAAE;IAMR,WAAA,IAAA,uBAAM,EAAC,4CAAoB,CAAC,CAAA;IAC5B,WAAA,IAAA,sBAAK,EAAC,mCAAuB,CAAC,CAAA;;GANtB,wBAAwB,CAgLpC;AAhLY,4DAAwB","file":"image-render.js","sourcesContent":["import { inject, injectable, named } from '../../../common/inversify-lite';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../../../common/contribution-provider';\nimport { getTheme } from '../../../graphic/theme';\nimport type {\n IGraphicAttribute,\n IContext2d,\n IMarkAttribute,\n BackgroundSizing,\n BackgroundMode,\n IImage,\n IImageGraphicAttribute,\n IThemeAttribute,\n IGraphicRender,\n IImageRenderContribution,\n IContributionProvider,\n IDrawContext,\n IGraphicRenderDrawParams,\n IRenderService\n} from '../../../interface';\nimport { ImageRenderContribution } from './contributions/constants';\nimport { IMAGE_NUMBER_TYPE } from '../../../graphic/constants';\nimport { isArray, isString } from '@visactor/vutils';\nimport { createRectPath } from '../../../common/shape/rect';\nimport { BaseRender } from './base-render';\nimport { defaultImageBackgroundRenderContribution, defaultImageRenderContribution } from './contributions';\nimport { ResourceLoader } from '../../../resource-loader/loader';\nimport { drawBackgroundImage } from './contributions/base-contribution-render';\n\nconst repeatStr = ['', 'repeat-x', 'repeat-y', 'repeat'];\n\nexport type IImageLayoutDrawParams = Pick<\n IImageGraphicAttribute,\n 'repeatX' | 'repeatY' | 'imageMode' | 'imageScale' | 'imageOffsetX' | 'imageOffsetY' | 'imagePosition'\n>;\n\nexport function resolveImageMode({\n repeatX = 'no-repeat',\n repeatY = 'no-repeat',\n imageMode\n}: Pick<IImageLayoutDrawParams, 'repeatX' | 'repeatY' | 'imageMode'>): {\n repeatMode: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat';\n sizingMode: BackgroundSizing;\n} {\n const repeatMode = resolveImageRepeatMode(repeatX, repeatY);\n\n return {\n repeatMode,\n sizingMode: repeatMode === 'no-repeat' ? imageMode ?? 'fill' : 'fill'\n };\n}\n\nconst IMAGE_MODE_TO_BACKGROUND_MODE: Record<BackgroundSizing, BackgroundMode> = {\n cover: 'no-repeat-cover',\n contain: 'no-repeat-contain',\n fill: 'no-repeat-fill',\n auto: 'no-repeat-auto'\n};\n\nexport function resolveBackgroundParamsByImageSizing(sizingMode: BackgroundSizing): {\n backgroundMode: BackgroundMode;\n backgroundFit: boolean;\n backgroundKeepAspectRatio: boolean;\n} {\n return {\n backgroundMode: IMAGE_MODE_TO_BACKGROUND_MODE[sizingMode],\n backgroundFit: false,\n backgroundKeepAspectRatio: false\n };\n}\n\nexport function resolveImageRepeatMode(\n repeatX: IImageGraphicAttribute['repeatX'],\n repeatY: IImageGraphicAttribute['repeatY']\n): 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' {\n let repeat = 0;\n if (repeatX === 'repeat') {\n repeat |= 0b0001;\n }\n if (repeatY === 'repeat') {\n repeat |= 0b0010;\n }\n return repeat ? (repeatStr[repeat] as 'repeat' | 'repeat-x' | 'repeat-y') : 'no-repeat';\n}\n\nexport function shouldClipImageByLayout({\n repeatX = 'no-repeat',\n repeatY = 'no-repeat',\n imageMode,\n imageScale = 1,\n imageOffsetX = 0,\n imageOffsetY = 0,\n imagePosition = 'top-left'\n}: IImageLayoutDrawParams): boolean {\n const { repeatMode, sizingMode } = resolveImageMode({\n repeatX,\n repeatY,\n imageMode\n });\n return (\n repeatMode === 'no-repeat' &&\n (sizingMode === 'cover' || sizingMode === 'auto' || imageScale !== 1 || imageOffsetX !== 0 || imageOffsetY !== 0)\n );\n}\n\nexport function drawImageWithLayout(\n context: IContext2d,\n data: any,\n x: number,\n y: number,\n width: number,\n height: number,\n {\n repeatX = 'no-repeat',\n repeatY = 'no-repeat',\n imageMode,\n imageScale = 1,\n imageOffsetX = 0,\n imageOffsetY = 0,\n imagePosition = 'top-left'\n }: IImageLayoutDrawParams\n) {\n const { repeatMode, sizingMode } = resolveImageMode({\n repeatX,\n repeatY,\n imageMode\n });\n const imageBackgroundParams =\n repeatMode === 'no-repeat'\n ? resolveBackgroundParamsByImageSizing(sizingMode)\n : {\n backgroundMode: repeatMode,\n backgroundFit: false,\n backgroundKeepAspectRatio: false\n };\n drawBackgroundImage(\n context,\n data,\n {\n x1: x,\n y1: y,\n x2: x + width,\n y2: y + height,\n width: () => width,\n height: () => height\n } as any,\n {\n backgroundMode: imageBackgroundParams.backgroundMode,\n backgroundFit: imageBackgroundParams.backgroundFit,\n backgroundKeepAspectRatio: imageBackgroundParams.backgroundKeepAspectRatio,\n backgroundScale: imageScale,\n backgroundOffsetX: imageOffsetX,\n backgroundOffsetY: imageOffsetY,\n backgroundPosition: imagePosition\n }\n );\n}\n\n@injectable()\nexport class DefaultCanvasImageRender extends BaseRender<IImage> implements IGraphicRender {\n type: 'image';\n numberType: number = IMAGE_NUMBER_TYPE;\n\n constructor(\n @inject(ContributionProvider)\n @named(ImageRenderContribution)\n protected readonly graphicRenderContributions: IContributionProvider<IImageRenderContribution>\n ) {\n super();\n this.builtinContributions = [defaultImageRenderContribution, defaultImageBackgroundRenderContribution];\n this.init(graphicRenderContributions);\n }\n\n drawShape(\n image: IImage,\n context: IContext2d,\n x: number,\n y: number,\n drawContext: IDrawContext,\n params?: IGraphicRenderDrawParams,\n fillCb?: (\n ctx: IContext2d,\n markAttribute: Partial<IMarkAttribute & IGraphicAttribute>,\n themeAttribute: IThemeAttribute\n ) => boolean,\n strokeCb?: (\n ctx: IContext2d,\n markAttribute: Partial<IMarkAttribute & IGraphicAttribute>,\n themeAttribute: IThemeAttribute\n ) => boolean\n ) {\n // const imageAttribute = graphicService.themeService.getCurrentTheme().imageAttribute;\n const imageAttribute = getTheme(image).image;\n const {\n repeatX = imageAttribute.repeatX,\n repeatY = imageAttribute.repeatY,\n x: originX = imageAttribute.x,\n y: originY = imageAttribute.y,\n cornerRadius = imageAttribute.cornerRadius,\n fillStrokeOrder = imageAttribute.fillStrokeOrder,\n cornerType = imageAttribute.cornerType,\n imageMode = imageAttribute.imageMode,\n imageScale = imageAttribute.imageScale,\n imageOffsetX = imageAttribute.imageOffsetX,\n imageOffsetY = imageAttribute.imageOffsetY,\n imagePosition = imageAttribute.imagePosition,\n image: url\n } = image.attribute;\n\n const data = this.valid(image, imageAttribute, fillCb);\n if (!data) {\n return;\n }\n const { fVisible, sVisible, doFill, doStroke } = data;\n\n if (!url || !image.resources) {\n return;\n }\n const res = image.resources.get(url);\n if (res.state !== 'success') {\n return;\n }\n\n const width = image.width;\n const height = image.height;\n context.beginPath();\n\n // deal with cornerRadius\n let needCornerClip = false;\n if (cornerRadius === 0 || (isArray(cornerRadius) && (<number[]>cornerRadius).every(num => num === 0))) {\n // 不需要处理圆角\n context.rect(x, y, width, height);\n } else {\n // context.beginPath();\n createRectPath(context, x, y, width, height, cornerRadius, cornerType !== 'bevel');\n needCornerClip = true;\n }\n\n // shadow\n context.setShadowBlendStyle && context.setShadowBlendStyle(image, image.attribute, imageAttribute);\n // context.beginPath();\n // context.image(x, y, width, height);\n\n const _runFill = () => {\n if (doFill) {\n if (fillCb) {\n fillCb(context, image.attribute, imageAttribute);\n } else if (fVisible) {\n context.setCommonStyle(image, image.attribute, x, y, imageAttribute);\n drawImageWithLayout(context, res.data, x, y, width, height, {\n repeatX,\n repeatY,\n imageMode,\n imageScale,\n imageOffsetX,\n imageOffsetY,\n imagePosition\n });\n }\n }\n };\n\n const _runStroke = () => {\n if (doStroke) {\n if (strokeCb) {\n strokeCb(context, image.attribute, imageAttribute);\n } else if (sVisible) {\n context.setStrokeStyle(image, image.attribute, originX - x, originY - y, imageAttribute);\n context.stroke();\n }\n }\n };\n\n const needLayoutClip = shouldClipImageByLayout({\n repeatX,\n repeatY,\n imageMode,\n imageScale,\n imageOffsetX,\n imageOffsetY,\n imagePosition\n });\n const needClip = needCornerClip || needLayoutClip;\n\n if (!fillStrokeOrder) {\n if (needClip) {\n context.save();\n context.clip();\n }\n this.beforeRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);\n _runFill();\n if (needClip) {\n context.restore();\n }\n _runStroke();\n } else {\n _runStroke();\n if (needClip) {\n context.save();\n context.clip();\n }\n this.beforeRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);\n _runFill();\n if (needClip) {\n context.restore();\n }\n }\n\n this.afterRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);\n }\n\n draw(image: IImage, renderService: IRenderService, drawContext: IDrawContext) {\n const { image: url } = image.attribute;\n\n if (!url || !image.resources) {\n return;\n }\n const res = image.resources.get(url);\n // if (res.state !== 'success') {\n // return;\n // }\n if (res.state === 'loading' && isString(url)) {\n ResourceLoader.improveImageLoading(url);\n return;\n } else if (res.state !== 'success') {\n return;\n }\n\n const { context } = renderService.drawParams;\n if (!context) {\n return;\n }\n const imageAttribute = getTheme(image).image;\n this._draw(image, imageAttribute, false, drawContext);\n }\n}\n"]}
|