@visactor/vrender-core 1.0.44 → 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.
Files changed (120) hide show
  1. package/cjs/canvas/constants.js +2 -1
  2. package/cjs/color-string/index.js +1 -2
  3. package/cjs/common/diff.js +2 -1
  4. package/cjs/common/event-transformer.js +1 -2
  5. package/cjs/common/render-area.js +1 -1
  6. package/cjs/common/render-command-list.js +1 -1
  7. package/cjs/common/render-curve.js +1 -1
  8. package/cjs/common/render-utils.js +1 -1
  9. package/cjs/common/seg-context.js +1 -1
  10. package/cjs/common/simplify.js +2 -1
  11. package/cjs/common/sort.js +1 -1
  12. package/cjs/common/split-path.js +1 -1
  13. package/cjs/common/store.js +1 -1
  14. package/cjs/common/text.js +1 -1
  15. package/cjs/common/utils.js +1 -1
  16. package/cjs/core/constants.js +1 -1
  17. package/cjs/core/core-modules.js +1 -1
  18. package/cjs/core/global-module.js +0 -2
  19. package/cjs/core/global.js +1 -1
  20. package/cjs/core/graphic-utils.js +1 -1
  21. package/cjs/core/index.js +1 -1
  22. package/cjs/core/layer-service.js +1 -2
  23. package/cjs/core/layer.d.ts +1 -1
  24. package/cjs/core/layer.js +1 -1
  25. package/cjs/core/layer.js.map +1 -1
  26. package/cjs/core/light.js +1 -1
  27. package/cjs/core/stage.d.ts +5 -3
  28. package/cjs/core/stage.js +17 -5
  29. package/cjs/core/stage.js.map +1 -1
  30. package/cjs/core/window.js +1 -1
  31. package/cjs/graphic/config.js +7 -1
  32. package/cjs/graphic/config.js.map +1 -1
  33. package/cjs/graphic/graphic.js +5 -2
  34. package/cjs/graphic/graphic.js.map +1 -1
  35. package/cjs/graphic/image.d.ts +1 -0
  36. package/cjs/graphic/image.js +2 -1
  37. package/cjs/graphic/image.js.map +1 -1
  38. package/cjs/interface/graphic/image.d.ts +7 -1
  39. package/cjs/interface/graphic/image.js.map +1 -1
  40. package/cjs/interface/graphic.d.ts +14 -2
  41. package/cjs/interface/graphic.js.map +1 -1
  42. package/cjs/interface/layer.d.ts +3 -2
  43. package/cjs/interface/layer.js.map +1 -1
  44. package/cjs/interface/render.d.ts +1 -1
  45. package/cjs/interface/render.js.map +1 -1
  46. package/cjs/interface/stage.d.ts +3 -2
  47. package/cjs/interface/stage.js.map +1 -1
  48. package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +27 -9
  49. package/cjs/render/contributions/render/contributions/base-contribution-render.js +147 -34
  50. package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  51. package/cjs/render/contributions/render/contributions/group-contribution-render.js +8 -6
  52. package/cjs/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  53. package/cjs/render/contributions/render/contributions/text-contribution-render.js +20 -17
  54. package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  55. package/cjs/render/contributions/render/draw-contribution.js +16 -5
  56. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  57. package/cjs/render/contributions/render/image-render.d.ts +14 -1
  58. package/cjs/render/contributions/render/image-render.js +99 -20
  59. package/cjs/render/contributions/render/image-render.js.map +1 -1
  60. package/dist/index.es.js +414 -114
  61. package/es/canvas/constants.js +2 -1
  62. package/es/color-string/index.js +1 -2
  63. package/es/common/diff.js +2 -1
  64. package/es/common/event-transformer.js +1 -2
  65. package/es/common/render-area.js +1 -1
  66. package/es/common/render-command-list.js +1 -1
  67. package/es/common/render-curve.js +1 -1
  68. package/es/common/render-utils.js +1 -1
  69. package/es/common/seg-context.js +1 -1
  70. package/es/common/simplify.js +2 -1
  71. package/es/common/sort.js +1 -1
  72. package/es/common/split-path.js +1 -1
  73. package/es/common/store.js +1 -1
  74. package/es/common/text.js +1 -1
  75. package/es/common/utils.js +1 -1
  76. package/es/core/constants.js +1 -1
  77. package/es/core/core-modules.js +1 -1
  78. package/es/core/global-module.js +0 -2
  79. package/es/core/global.js +1 -1
  80. package/es/core/graphic-utils.js +1 -1
  81. package/es/core/index.js +1 -1
  82. package/es/core/layer-service.js +1 -2
  83. package/es/core/layer.d.ts +1 -1
  84. package/es/core/layer.js +1 -1
  85. package/es/core/layer.js.map +1 -1
  86. package/es/core/light.js +1 -1
  87. package/es/core/stage.d.ts +5 -3
  88. package/es/core/stage.js +17 -6
  89. package/es/core/stage.js.map +1 -1
  90. package/es/core/window.js +1 -1
  91. package/es/graphic/config.js +7 -1
  92. package/es/graphic/config.js.map +1 -1
  93. package/es/graphic/graphic.js +4 -2
  94. package/es/graphic/graphic.js.map +1 -1
  95. package/es/graphic/image.d.ts +1 -0
  96. package/es/graphic/image.js +2 -1
  97. package/es/graphic/image.js.map +1 -1
  98. package/es/interface/graphic/image.d.ts +7 -1
  99. package/es/interface/graphic/image.js.map +1 -1
  100. package/es/interface/graphic.d.ts +14 -2
  101. package/es/interface/graphic.js.map +1 -1
  102. package/es/interface/layer.d.ts +3 -2
  103. package/es/interface/layer.js.map +1 -1
  104. package/es/interface/render.d.ts +1 -1
  105. package/es/interface/render.js.map +1 -1
  106. package/es/interface/stage.d.ts +3 -2
  107. package/es/interface/stage.js.map +1 -1
  108. package/es/render/contributions/render/contributions/base-contribution-render.d.ts +27 -9
  109. package/es/render/contributions/render/contributions/base-contribution-render.js +140 -33
  110. package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  111. package/es/render/contributions/render/contributions/group-contribution-render.js +9 -7
  112. package/es/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  113. package/es/render/contributions/render/contributions/text-contribution-render.js +20 -16
  114. package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  115. package/es/render/contributions/render/draw-contribution.js +17 -4
  116. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  117. package/es/render/contributions/render/image-render.d.ts +14 -1
  118. package/es/render/contributions/render/image-render.js +93 -18
  119. package/es/render/contributions/render/image-render.js.map +1 -1
  120. package/package.json +2 -2
@@ -30,8 +30,76 @@ import { defaultImageBackgroundRenderContribution, defaultImageRenderContributio
30
30
 
31
31
  import { ResourceLoader } from "../../../resource-loader/loader";
32
32
 
33
+ import { drawBackgroundImage } from "./contributions/base-contribution-render";
34
+
33
35
  const repeatStr = [ "", "repeat-x", "repeat-y", "repeat" ];
34
36
 
37
+ export function resolveImageMode({repeatX: repeatX = "no-repeat", repeatY: repeatY = "no-repeat", imageMode: imageMode}) {
38
+ const repeatMode = resolveImageRepeatMode(repeatX, repeatY);
39
+ return {
40
+ repeatMode: repeatMode,
41
+ sizingMode: "no-repeat" === repeatMode && null != imageMode ? imageMode : "fill"
42
+ };
43
+ }
44
+
45
+ const IMAGE_MODE_TO_BACKGROUND_MODE = {
46
+ cover: "no-repeat-cover",
47
+ contain: "no-repeat-contain",
48
+ fill: "no-repeat-fill",
49
+ auto: "no-repeat-auto"
50
+ };
51
+
52
+ export function resolveBackgroundParamsByImageSizing(sizingMode) {
53
+ return {
54
+ backgroundMode: IMAGE_MODE_TO_BACKGROUND_MODE[sizingMode],
55
+ backgroundFit: !1,
56
+ backgroundKeepAspectRatio: !1
57
+ };
58
+ }
59
+
60
+ export function resolveImageRepeatMode(repeatX, repeatY) {
61
+ let repeat = 0;
62
+ return "repeat" === repeatX && (repeat |= 1), "repeat" === repeatY && (repeat |= 2),
63
+ repeat ? repeatStr[repeat] : "no-repeat";
64
+ }
65
+
66
+ export 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"}) {
67
+ const {repeatMode: repeatMode, sizingMode: sizingMode} = resolveImageMode({
68
+ repeatX: repeatX,
69
+ repeatY: repeatY,
70
+ imageMode: imageMode
71
+ });
72
+ return "no-repeat" === repeatMode && ("cover" === sizingMode || "auto" === sizingMode || 1 !== imageScale || 0 !== imageOffsetX || 0 !== imageOffsetY);
73
+ }
74
+
75
+ export 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"}) {
76
+ const {repeatMode: repeatMode, sizingMode: sizingMode} = resolveImageMode({
77
+ repeatX: repeatX,
78
+ repeatY: repeatY,
79
+ imageMode: imageMode
80
+ }), imageBackgroundParams = "no-repeat" === repeatMode ? resolveBackgroundParamsByImageSizing(sizingMode) : {
81
+ backgroundMode: repeatMode,
82
+ backgroundFit: !1,
83
+ backgroundKeepAspectRatio: !1
84
+ };
85
+ drawBackgroundImage(context, data, {
86
+ x1: x,
87
+ y1: y,
88
+ x2: x + width,
89
+ y2: y + height,
90
+ width: () => width,
91
+ height: () => height
92
+ }, {
93
+ backgroundMode: imageBackgroundParams.backgroundMode,
94
+ backgroundFit: imageBackgroundParams.backgroundFit,
95
+ backgroundKeepAspectRatio: imageBackgroundParams.backgroundKeepAspectRatio,
96
+ backgroundScale: imageScale,
97
+ backgroundOffsetX: imageOffsetX,
98
+ backgroundOffsetY: imageOffsetY,
99
+ backgroundPosition: imagePosition
100
+ });
101
+ }
102
+
35
103
  let DefaultCanvasImageRender = class extends BaseRender {
36
104
  constructor(graphicRenderContributions) {
37
105
  super(), this.graphicRenderContributions = graphicRenderContributions, this.numberType = IMAGE_NUMBER_TYPE,
@@ -39,7 +107,7 @@ let DefaultCanvasImageRender = class extends BaseRender {
39
107
  this.init(graphicRenderContributions);
40
108
  }
41
109
  drawShape(image, context, x, y, drawContext, params, fillCb, strokeCb) {
42
- const imageAttribute = 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);
110
+ const imageAttribute = 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);
43
111
  if (!data) return;
44
112
  const {fVisible: fVisible, sVisible: sVisible, doFill: doFill, doStroke: doStroke} = data;
45
113
  if (!url || !image.resources) return;
@@ -47,29 +115,36 @@ let DefaultCanvasImageRender = class extends BaseRender {
47
115
  if ("success" !== res.state) return;
48
116
  const width = image.width, height = image.height;
49
117
  context.beginPath();
50
- let needRestore = !1;
118
+ let needCornerClip = !1;
51
119
  0 === cornerRadius || isArray(cornerRadius) && cornerRadius.every((num => 0 === num)) ? context.rect(x, y, width, height) : (createRectPath(context, x, y, width, height, cornerRadius, "bevel" !== cornerType),
52
- needRestore = !0), context.setShadowBlendStyle && context.setShadowBlendStyle(image, image.attribute, imageAttribute);
120
+ needCornerClip = !0), context.setShadowBlendStyle && context.setShadowBlendStyle(image, image.attribute, imageAttribute);
53
121
  const _runFill = () => {
54
- if (doFill) if (fillCb) fillCb(context, image.attribute, imageAttribute); else if (fVisible) {
55
- context.setCommonStyle(image, image.attribute, x, y, imageAttribute);
56
- let repeat = 0;
57
- if ("repeat" === repeatX && (repeat |= 1), "repeat" === repeatY && (repeat |= 2),
58
- repeat) {
59
- const pattern = context.createPattern(res.data, repeatStr[repeat]);
60
- context.fillStyle = pattern, context.translate(x, y, !0), context.fillRect(0, 0, width, height),
61
- context.translate(-x, -y, !0);
62
- } else context.drawImage(res.data, x, y, width, height);
63
- }
122
+ doFill && (fillCb ? fillCb(context, image.attribute, imageAttribute) : fVisible && (context.setCommonStyle(image, image.attribute, x, y, imageAttribute),
123
+ drawImageWithLayout(context, res.data, x, y, width, height, {
124
+ repeatX: repeatX,
125
+ repeatY: repeatY,
126
+ imageMode: imageMode,
127
+ imageScale: imageScale,
128
+ imageOffsetX: imageOffsetX,
129
+ imageOffsetY: imageOffsetY,
130
+ imagePosition: imagePosition
131
+ })));
64
132
  }, _runStroke = () => {
65
133
  doStroke && (strokeCb ? strokeCb(context, image.attribute, imageAttribute) : sVisible && (context.setStrokeStyle(image, image.attribute, originX - x, originY - y, imageAttribute),
66
134
  context.stroke()));
67
- };
68
- fillStrokeOrder ? (_runStroke(), needRestore && (context.save(), context.clip()),
135
+ }, needLayoutClip = shouldClipImageByLayout({
136
+ repeatX: repeatX,
137
+ repeatY: repeatY,
138
+ imageMode: imageMode,
139
+ imageScale: imageScale,
140
+ imageOffsetX: imageOffsetX,
141
+ imageOffsetY: imageOffsetY,
142
+ imagePosition: imagePosition
143
+ }), needClip = needCornerClip || needLayoutClip;
144
+ fillStrokeOrder ? (_runStroke(), needClip && (context.save(), context.clip()), this.beforeRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb),
145
+ _runFill(), needClip && context.restore()) : (needClip && (context.save(), context.clip()),
69
146
  this.beforeRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb),
70
- _runFill(), needRestore && context.restore()) : (needRestore && (context.save(),
71
- context.clip()), this.beforeRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb),
72
- _runFill(), needRestore && context.restore(), _runStroke()), this.afterRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb);
147
+ _runFill(), needClip && context.restore(), _runStroke()), this.afterRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb);
73
148
  }
74
149
  draw(image, renderService, drawContext) {
75
150
  const {image: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, 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,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAiBlD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,wCAAwC,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAC3G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AE;YAC5C,cAAc,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,QAAQ,CAAC,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,UAAU,EAAE;IAMR,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAC5B,WAAA,KAAK,CAAC,uBAAuB,CAAC,CAAA;;GANtB,wBAAwB,CAgLpC;SAhLY,wBAAwB","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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/vrender-core",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "description": "",
5
5
  "sideEffects": [
6
6
  "./src/modules.ts",
@@ -73,7 +73,7 @@
73
73
  "build-umd": "cross-env DEBUG='Bundler*' bundle --clean -f umd",
74
74
  "dev": "cross-env DEBUG='Bundler*' bundle --clean -f es -w",
75
75
  "start": "vite ./__tests__/browser",
76
- "test": "jest",
76
+ "test": "jest 2>&1",
77
77
  "test-live": "npm run test-watch __tests__/unit/theme/line.test.ts",
78
78
  "test-watch": "cross-env DEBUG_MODE=1 jest --watch",
79
79
  "test-cov": "jest -w 16 --coverage",