@visactor/vrender-core 0.17.18-alpha.1 → 0.17.18

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 (111) hide show
  1. package/cjs/graphic/arc.js +1 -1
  2. package/cjs/graphic/arc.js.map +1 -1
  3. package/cjs/graphic/arc3d.js +1 -1
  4. package/cjs/graphic/arc3d.js.map +1 -1
  5. package/cjs/graphic/area.js +1 -1
  6. package/cjs/graphic/area.js.map +1 -1
  7. package/cjs/graphic/circle.js +1 -1
  8. package/cjs/graphic/circle.js.map +1 -1
  9. package/cjs/graphic/config.js +1 -0
  10. package/cjs/graphic/config.js.map +1 -1
  11. package/cjs/graphic/glyph.js +1 -1
  12. package/cjs/graphic/glyph.js.map +1 -1
  13. package/cjs/graphic/graphic-service/graphic-service.js +13 -11
  14. package/cjs/graphic/graphic-service/graphic-service.js.map +1 -1
  15. package/cjs/graphic/graphic.js +2 -2
  16. package/cjs/graphic/graphic.js.map +1 -1
  17. package/cjs/graphic/group.js +1 -1
  18. package/cjs/graphic/group.js.map +1 -1
  19. package/cjs/graphic/image.js +1 -1
  20. package/cjs/graphic/image.js.map +1 -1
  21. package/cjs/graphic/line.js +1 -1
  22. package/cjs/graphic/line.js.map +1 -1
  23. package/cjs/graphic/node-tree.js +1 -4
  24. package/cjs/graphic/node-tree.js.map +1 -1
  25. package/cjs/graphic/path.js +1 -1
  26. package/cjs/graphic/path.js.map +1 -1
  27. package/cjs/graphic/polygon.js +1 -1
  28. package/cjs/graphic/polygon.js.map +1 -1
  29. package/cjs/graphic/pyramid3d.js +1 -1
  30. package/cjs/graphic/pyramid3d.js.map +1 -1
  31. package/cjs/graphic/rect.js +1 -1
  32. package/cjs/graphic/rect.js.map +1 -1
  33. package/cjs/graphic/richtext.d.ts +1 -1
  34. package/cjs/graphic/richtext.js +10 -6
  35. package/cjs/graphic/richtext.js.map +1 -1
  36. package/cjs/graphic/symbol.js +1 -1
  37. package/cjs/graphic/symbol.js.map +1 -1
  38. package/cjs/graphic/text.js +2 -2
  39. package/cjs/graphic/text.js.map +1 -1
  40. package/cjs/interface/graphic/richText.d.ts +1 -1
  41. package/cjs/interface/graphic/richText.js.map +1 -1
  42. package/cjs/interface/graphic.d.ts +1 -0
  43. package/cjs/interface/graphic.js.map +1 -1
  44. package/cjs/render/contributions/render/contributions/text-contribution-render.js +7 -4
  45. package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  46. package/cjs/render/contributions/render/draw-contribution.js +3 -5
  47. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  48. package/cjs/render/contributions/render/image-render.js +2 -4
  49. package/cjs/render/contributions/render/image-render.js.map +1 -1
  50. package/cjs/render/contributions/render/index.d.ts +0 -1
  51. package/cjs/render/contributions/render/index.js +1 -2
  52. package/cjs/render/contributions/render/index.js.map +1 -1
  53. package/cjs/resource-loader/loader.d.ts +0 -5
  54. package/cjs/resource-loader/loader.js +15 -56
  55. package/cjs/resource-loader/loader.js.map +1 -1
  56. package/es/graphic/arc.js +1 -1
  57. package/es/graphic/arc.js.map +1 -1
  58. package/es/graphic/arc3d.js +1 -1
  59. package/es/graphic/arc3d.js.map +1 -1
  60. package/es/graphic/area.js +1 -1
  61. package/es/graphic/area.js.map +1 -1
  62. package/es/graphic/circle.js +1 -1
  63. package/es/graphic/circle.js.map +1 -1
  64. package/es/graphic/config.js +1 -0
  65. package/es/graphic/config.js.map +1 -1
  66. package/es/graphic/glyph.js +1 -1
  67. package/es/graphic/glyph.js.map +1 -1
  68. package/es/graphic/graphic-service/graphic-service.js +13 -11
  69. package/es/graphic/graphic-service/graphic-service.js.map +1 -1
  70. package/es/graphic/graphic.js +3 -3
  71. package/es/graphic/graphic.js.map +1 -1
  72. package/es/graphic/group.js +1 -1
  73. package/es/graphic/group.js.map +1 -1
  74. package/es/graphic/image.js +1 -1
  75. package/es/graphic/image.js.map +1 -1
  76. package/es/graphic/line.js +1 -1
  77. package/es/graphic/line.js.map +1 -1
  78. package/es/graphic/node-tree.js +1 -4
  79. package/es/graphic/node-tree.js.map +1 -1
  80. package/es/graphic/path.js +1 -1
  81. package/es/graphic/path.js.map +1 -1
  82. package/es/graphic/polygon.js +1 -1
  83. package/es/graphic/polygon.js.map +1 -1
  84. package/es/graphic/pyramid3d.js +1 -1
  85. package/es/graphic/pyramid3d.js.map +1 -1
  86. package/es/graphic/rect.js +1 -1
  87. package/es/graphic/rect.js.map +1 -1
  88. package/es/graphic/richtext.d.ts +1 -1
  89. package/es/graphic/richtext.js +11 -5
  90. package/es/graphic/richtext.js.map +1 -1
  91. package/es/graphic/symbol.js +1 -1
  92. package/es/graphic/symbol.js.map +1 -1
  93. package/es/graphic/text.js +2 -2
  94. package/es/graphic/text.js.map +1 -1
  95. package/es/interface/graphic/richText.d.ts +1 -1
  96. package/es/interface/graphic/richText.js.map +1 -1
  97. package/es/interface/graphic.d.ts +1 -0
  98. package/es/interface/graphic.js.map +1 -1
  99. package/es/render/contributions/render/contributions/text-contribution-render.js +8 -3
  100. package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  101. package/es/render/contributions/render/draw-contribution.js +3 -5
  102. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  103. package/es/render/contributions/render/image-render.js +2 -6
  104. package/es/render/contributions/render/image-render.js.map +1 -1
  105. package/es/render/contributions/render/index.d.ts +0 -1
  106. package/es/render/contributions/render/index.js +0 -2
  107. package/es/render/contributions/render/index.js.map +1 -1
  108. package/es/resource-loader/loader.d.ts +0 -5
  109. package/es/resource-loader/loader.js +14 -56
  110. package/es/resource-loader/loader.js.map +1 -1
  111. package/package.json +1 -1
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.defaultTextBackgroundRenderContribution = exports.DefaultTextBackgroundRenderContribution = void 0;
6
6
 
7
- const vutils_1 = require("@visactor/vutils"), enums_1 = require("../../../../common/enums"), base_contribution_render_1 = require("./base-contribution-render"), bounds_allocate_1 = require("../../../../allocator/bounds-allocate");
7
+ const vutils_1 = require("@visactor/vutils"), enums_1 = require("../../../../common/enums"), base_contribution_render_1 = require("./base-contribution-render"), bounds_allocate_1 = require("../../../../allocator/bounds-allocate"), rect_1 = require("../../../../common/shape/rect");
8
8
 
9
9
  class DefaultTextBackgroundRenderContribution extends base_contribution_render_1.DefaultBaseBackgroundRenderContribution {
10
10
  constructor() {
@@ -30,9 +30,12 @@ class DefaultTextBackgroundRenderContribution extends base_contribution_render_1
30
30
  context.highPerformanceSave(), onlyTranslate && context.setTransformFromMatrix(graphic.parent.globalTransMatrix, !0),
31
31
  context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute), this.doDrawImage(context, res.data, b, backgroundMode, backgroundFit),
32
32
  context.highPerformanceRestore(), context.setTransformForCurrent();
33
- } else context.highPerformanceSave(), context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute),
34
- context.fillStyle = background, context.fillRect(b.x1, b.y1, b.width(), b.height()),
35
- context.highPerformanceRestore();
33
+ } else {
34
+ const {backgroundCornerRadius: backgroundCornerRadius} = graphic.attribute;
35
+ context.highPerformanceSave(), context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute),
36
+ context.fillStyle = background, backgroundCornerRadius ? ((0, rect_1.createRectPath)(context, b.x1, b.y1, b.width(), b.height(), backgroundCornerRadius),
37
+ context.fill()) : context.fillRect(b.x1, b.y1, b.width(), b.height()), context.highPerformanceRestore();
38
+ }
36
39
  shouldReCalBounds && bounds_allocate_1.boundsAllocate.free(b);
37
40
  }
38
41
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/render/contributions/render/contributions/text-contribution-render.ts"],"names":[],"mappings":";;;AACA,6CAA4C;AAC5C,oDAAsE;AAStE,yEAAqF;AACrF,2EAAuE;AAGvE,MAAa,uCACX,SAAQ,kEAAuC;IADjD;;QAIE,SAAI,GAA+B,kCAA0B,CAAC,gBAAgB,CAAC;IAkFjF,CAAC;IAhFC,SAAS,CACP,OAAc,EACd,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,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;YACtE,OAAO,CAAC,sBAAsB,EAAE,CAAC;YACjC,OAAO,CAAC,sBAAsB,EAAE,CAAC;SAClC;aAAM;YACL,OAAO,CAAC,mBAAmB,EAAE,CAAC;YAC9B,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC;YAC3E,OAAO,CAAC,SAAS,GAAG,UAAoB,CAAC;YACzC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;YACpD,OAAO,CAAC,sBAAsB,EAAE,CAAC;SAClC;QAED,IAAI,iBAAiB,EAAE;YACrB,gCAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACxB;IACH,CAAC;CACF;AAtFD,0FAsFC;AAEY,QAAA,uCAAuC,GAAG,IAAI,uCAAuC,EAAE,CAAC","file":"text-contribution-render.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport { isObject } from '@visactor/vutils';\nimport { BaseRenderContributionTime } from '../../../../common/enums';\nimport type {\n IContext2d,\n IDrawContext,\n IGraphicAttribute,\n IText,\n ITextRenderContribution,\n IThemeAttribute\n} from '../../../../interface';\nimport { DefaultBaseBackgroundRenderContribution } from './base-contribution-render';\nimport { boundsAllocate } from '../../../../allocator/bounds-allocate';\nimport { getTextBounds } from '../../../../graphic';\n\nexport class DefaultTextBackgroundRenderContribution\n extends DefaultBaseBackgroundRenderContribution\n implements ITextRenderContribution\n{\n time: BaseRenderContributionTime = BaseRenderContributionTime.beforeFillStroke;\n\n drawShape(\n graphic: IText,\n context: IContext2d,\n x: number,\n y: number,\n doFill: boolean,\n doStroke: boolean,\n fVisible: boolean,\n sVisible: boolean,\n graphicAttribute: Required<IGraphicAttribute>,\n drawContext: IDrawContext,\n fillCb?: (ctx: IContext2d, markAttribute: Partial<IGraphicAttribute>, themeAttribute: IThemeAttribute) => boolean,\n strokeCb?: (ctx: IContext2d, markAttribute: Partial<IGraphicAttribute>, themeAttribute: IThemeAttribute) => boolean\n ) {\n const { backgroundMode = graphicAttribute.backgroundMode, backgroundFit = graphicAttribute.backgroundFit } =\n graphic.attribute;\n let { background } = graphic.attribute;\n if (!background) {\n return;\n }\n let b: IAABBBounds;\n const shouldReCalBounds = isObject(background) && (background as any).background;\n const onlyTranslate = graphic.transMatrix.onlyTranslate();\n if (shouldReCalBounds) {\n const _b = graphic.AABBBounds;\n const x = ((background as any).x ?? _b.x1) + ((background as any).dx ?? 0);\n const y = ((background as any).y ?? _b.y1) + ((background as any).dy ?? 0);\n const w = (background as any).width ?? _b.width();\n const h = (background as any).height ?? _b.height();\n b = boundsAllocate.allocate(x, y, x + w, y + h);\n background = (background as any).background;\n if (!onlyTranslate) {\n const w = b.width();\n const h = b.height();\n b.set(\n ((background as any).x ?? 0) + ((background as any).dx ?? 0),\n ((background as any).y ?? 0) + ((background as any).dy ?? 0),\n w,\n h\n );\n }\n } else {\n b = graphic.AABBBounds;\n if (!onlyTranslate) {\n b.set(0, 0, b.width(), b.height());\n }\n }\n\n if (graphic.backgroundImg && graphic.resources) {\n const res = graphic.resources.get(background as any);\n if (res.state !== 'success' || !res.data) {\n return;\n }\n\n context.highPerformanceSave();\n // 默认应用旋转\n if (!onlyTranslate) {\n // TODO 性能优化\n // const _b = getTextBounds({ ...graphic.attribute, angle: 0, scaleX: 1, scaleY: 1, x: 0, y: 0, dx: 0, dy: 0 });\n // b.copy(_b);\n } else {\n context.setTransformFromMatrix(graphic.parent.globalTransMatrix, true);\n }\n\n context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute);\n this.doDrawImage(context, res.data, b, backgroundMode, backgroundFit);\n context.highPerformanceRestore();\n context.setTransformForCurrent();\n } else {\n context.highPerformanceSave();\n context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute);\n context.fillStyle = background as string;\n context.fillRect(b.x1, b.y1, b.width(), b.height());\n context.highPerformanceRestore();\n }\n\n if (shouldReCalBounds) {\n boundsAllocate.free(b);\n }\n }\n}\n\nexport const defaultTextBackgroundRenderContribution = new DefaultTextBackgroundRenderContribution();\n\n// @injectable()\n// export class DefaultTextPopTipRenderContribution\n// extends DefaultBasePopTipRenderContribution\n// implements ITextRenderContribution\n// {\n// time: BaseRenderContributionTime = BaseRenderContributionTime.afterFillStroke;\n// }\n"]}
1
+ {"version":3,"sources":["../src/render/contributions/render/contributions/text-contribution-render.ts"],"names":[],"mappings":";;;AACA,6CAA4C;AAC5C,oDAAsE;AAStE,yEAAqF;AACrF,2EAAuE;AAEvE,wDAA+D;AAE/D,MAAa,uCACX,SAAQ,kEAAuC;IADjD;;QAIE,SAAI,GAA+B,kCAA0B,CAAC,gBAAgB,CAAC;IAyFjF,CAAC;IAvFC,SAAS,CACP,OAAc,EACd,OAAmB,EACnB,CAAS,EACT,CAAS,EACT,MAAe,EACf,QAAiB,EACjB,QAAiB,EACjB,QAAiB,EACjB,gBAA6C,EAC7C,WAAyB,EACzB,MAAiH,EACjH,QAAmH;;QAEnH,MAAM,EAAE,cAAc,GAAG,gBAAgB,CAAC,cAAc,EAAE,aAAa,GAAG,gBAAgB,CAAC,aAAa,EAAE,GACxG,OAAO,CAAC,SAAS,CAAC;QACpB,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC;QACvC,IAAI,CAAC,UAAU,EAAE;YACf,OAAO;SACR;QACD,IAAI,CAAc,CAAC;QACnB,MAAM,iBAAiB,GAAG,IAAA,iBAAQ,EAAC,UAAU,CAAC,IAAK,UAAkB,CAAC,UAAU,CAAC;QACjF,MAAM,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC;QAC1D,IAAI,iBAAiB,EAAE;YACrB,MA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AM,EAAE,EAAE,sBAAsB,CAAC,CAAC;gBACnF,OAAO,CAAC,IAAI,EAAE,CAAC;aAChB;iBAAM;gBACL,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;aACrD;YACD,OAAO,CAAC,sBAAsB,EAAE,CAAC;SAClC;QAED,IAAI,iBAAiB,EAAE;YACrB,gCAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACxB;IACH,CAAC;CACF;AA7FD,0FA6FC;AAEY,QAAA,uCAAuC,GAAG,IAAI,uCAAuC,EAAE,CAAC","file":"text-contribution-render.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport { isObject } from '@visactor/vutils';\nimport { BaseRenderContributionTime } from '../../../../common/enums';\nimport type {\n IContext2d,\n IDrawContext,\n IGraphicAttribute,\n IText,\n ITextRenderContribution,\n IThemeAttribute\n} from '../../../../interface';\nimport { DefaultBaseBackgroundRenderContribution } from './base-contribution-render';\nimport { boundsAllocate } from '../../../../allocator/bounds-allocate';\nimport { getTextBounds } from '../../../../graphic';\nimport { createRectPath } from '../../../../common/shape/rect';\n\nexport class DefaultTextBackgroundRenderContribution\n extends DefaultBaseBackgroundRenderContribution\n implements ITextRenderContribution\n{\n time: BaseRenderContributionTime = BaseRenderContributionTime.beforeFillStroke;\n\n drawShape(\n graphic: IText,\n context: IContext2d,\n x: number,\n y: number,\n doFill: boolean,\n doStroke: boolean,\n fVisible: boolean,\n sVisible: boolean,\n graphicAttribute: Required<IGraphicAttribute>,\n drawContext: IDrawContext,\n fillCb?: (ctx: IContext2d, markAttribute: Partial<IGraphicAttribute>, themeAttribute: IThemeAttribute) => boolean,\n strokeCb?: (ctx: IContext2d, markAttribute: Partial<IGraphicAttribute>, themeAttribute: IThemeAttribute) => boolean\n ) {\n const { backgroundMode = graphicAttribute.backgroundMode, backgroundFit = graphicAttribute.backgroundFit } =\n graphic.attribute;\n let { background } = graphic.attribute;\n if (!background) {\n return;\n }\n let b: IAABBBounds;\n const shouldReCalBounds = isObject(background) && (background as any).background;\n const onlyTranslate = graphic.transMatrix.onlyTranslate();\n if (shouldReCalBounds) {\n const _b = graphic.AABBBounds;\n const x = ((background as any).x ?? _b.x1) + ((background as any).dx ?? 0);\n const y = ((background as any).y ?? _b.y1) + ((background as any).dy ?? 0);\n const w = (background as any).width ?? _b.width();\n const h = (background as any).height ?? _b.height();\n b = boundsAllocate.allocate(x, y, x + w, y + h);\n background = (background as any).background;\n if (!onlyTranslate) {\n const w = b.width();\n const h = b.height();\n b.set(\n ((background as any).x ?? 0) + ((background as any).dx ?? 0),\n ((background as any).y ?? 0) + ((background as any).dy ?? 0),\n w,\n h\n );\n }\n } else {\n b = graphic.AABBBounds;\n if (!onlyTranslate) {\n b.set(0, 0, b.width(), b.height());\n }\n }\n\n if (graphic.backgroundImg && graphic.resources) {\n const res = graphic.resources.get(background as any);\n if (res.state !== 'success' || !res.data) {\n return;\n }\n\n context.highPerformanceSave();\n // 默认应用旋转\n if (!onlyTranslate) {\n // TODO 性能优化\n // const _b = getTextBounds({ ...graphic.attribute, angle: 0, scaleX: 1, scaleY: 1, x: 0, y: 0, dx: 0, dy: 0 });\n // b.copy(_b);\n } else {\n context.setTransformFromMatrix(graphic.parent.globalTransMatrix, true);\n }\n\n context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute);\n this.doDrawImage(context, res.data, b, backgroundMode, backgroundFit);\n context.highPerformanceRestore();\n context.setTransformForCurrent();\n } else {\n const { backgroundCornerRadius } = graphic.attribute;\n context.highPerformanceSave();\n context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute);\n context.fillStyle = background as string;\n if (backgroundCornerRadius) {\n // 测试后,cache对于重绘性能提升不大,但是在首屏有一定性能损耗,因此rect不再使用cache\n createRectPath(context, b.x1, b.y1, b.width(), b.height(), backgroundCornerRadius);\n context.fill();\n } else {\n context.fillRect(b.x1, b.y1, b.width(), b.height());\n }\n context.highPerformanceRestore();\n }\n\n if (shouldReCalBounds) {\n boundsAllocate.free(b);\n }\n }\n}\n\nexport const defaultTextBackgroundRenderContribution = new DefaultTextBackgroundRenderContribution();\n\n// @injectable()\n// export class DefaultTextPopTipRenderContribution\n// extends DefaultBasePopTipRenderContribution\n// implements ITextRenderContribution\n// {\n// time: BaseRenderContributionTime = BaseRenderContributionTime.afterFillStroke;\n// }\n"]}
@@ -57,9 +57,8 @@ let DefaultDrawContribution = class {
57
57
  const drawInArea = dirtyBounds.width() * context.dpr < context.canvas.width || dirtyBounds.height() * context.dpr < context.canvas.height;
58
58
  context.save(), context.translate(x, y, !0), drawInArea && (context.beginPath(),
59
59
  context.rect(dirtyBounds.x1, dirtyBounds.y1, dirtyBounds.width(), dirtyBounds.height()),
60
- context.clip()), stage.camera && (this.dirtyBounds.setValue(-1 / 0, -1 / 0, 1 / 0, 1 / 0),
61
- this.backupDirtyBounds.setValue(-1 / 0, -1 / 0, 1 / 0, 1 / 0)), this.clearScreen(renderService, context, drawContext),
62
- context.save(), renderService.renderTreeRoots.sort(((a, b) => {
60
+ context.clip()), stage.camera && (this.dirtyBounds.clear(), this.backupDirtyBounds.clear()),
61
+ this.clearScreen(renderService, context, drawContext), context.save(), renderService.renderTreeRoots.sort(((a, b) => {
63
62
  var _a, _b;
64
63
  return (null !== (_a = a.attribute.zIndex) && void 0 !== _a ? _a : graphic_1.DefaultAttribute.zIndex) - (null !== (_b = b.attribute.zIndex) && void 0 !== _b ? _b : graphic_1.DefaultAttribute.zIndex);
65
64
  })).forEach((group => {
@@ -111,8 +110,7 @@ let DefaultDrawContribution = class {
111
110
  group: group
112
111
  }, subLayers.set(group._uid, incrementalLayer));
113
112
  const incrementalContext = incrementalLayer.layer.getNativeHandler().getContext(), idc = incrementalLayer.drawContribution || container_1.container.get(symbol_1.IncrementalDrawContribution);
114
- idc.dirtyBounds.setValue(-1 / 0, -1 / 0, 1 / 0, 1 / 0), idc.backupDirtyBounds.setValue(-1 / 0, -1 / 0, 1 / 0, 1 / 0),
115
- idc.draw(this.currentRenderService, Object.assign(Object.assign({}, drawContext), {
113
+ idc.dirtyBounds.clear(), idc.backupDirtyBounds.clear(), idc.draw(this.currentRenderService, Object.assign(Object.assign({}, drawContext), {
116
114
  drawContribution: idc,
117
115
  clear: "transparent",
118
116
  layer: incrementalLayer.layer,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/render/contributions/render/draw-contribution.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAAwF;AAgBxF,+CAAgE;AAEhE,iFAA6E;AAC7E,8CAAoD;AAEpD,6CAA2F;AAE3F,kDAA+C;AAC/C,qCAAsF;AACtF,yDAAyD;AACzD,+DAA2D;AAE3D,wEAAoE;AACpE,wEAAoE;AACpE,sDAAmD;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,IAAI,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,IAAI,eAAM,EAAE,CAAC;QAChC,IAAI,CAAC,iBAAiB,GAAG,IAAI,eAAM,EAAE,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,yBAAW,CAAC,MAAM,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,yBAAW,CAAC,YAAY,CAAC;QAC7C,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAED,IAAI;QACF,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAChC,IAAI,IAAI,CAAC,KAAK,EAAE;g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W,EAC7B,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;AApZY,uBAAuB;IADnC,IAAA,2BAAU,GAAE;IAmBR,WAAA,IAAA,4BAAW,EAAC,sBAAa,CAAC,CAAA;IAG1B,WAAA,IAAA,uBAAM,EAAC,4CAAoB,CAAC,CAAA;IAC5B,WAAA,IAAA,sBAAK,EAAC,sCAAmB,CAAC,CAAA;;GAtBlB,uBAAuB,CAoZnC;AApZY,0DAAuB","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 stage && (context.globalAlpha = (stage as any).attribute.opacity ?? 1);\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,mEAAwF;AAgBxF,+CAAgE;AAEhE,iFAA6E;AAC7E,8CAAoD;AAEpD,6CAA2F;AAE3F,kDAA+C;AAC/C,qCAAsF;AACtF,yDAAyD;AACzD,+DAA2D;AAE3D,wEAAoE;AACpE,wEAAoE;AACpE,sDAAmD;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,IAAI,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,IAAI,eAAM,EAAE,CAAC;QAChC,IAAI,CAAC,iBAAiB,GAAG,IAAI,eAAM,EAAE,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,yBAAW,CAAC,MAAM,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,yBAAW,CAAC,YAAY,CAAC;QAC7C,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAED,IAAI;QACF,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAChC,IAAI,IAAI,CAAC,KAAK,EAAE;gBACd,MAAM,GAAG,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;gBAC7D,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;gBAC/B,IAAI,CAAC,cAAc,CAAC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AA;IAG1B,WAAA,IAAA,uBAAM,EAAC,4CAAoB,CAAC,CAAA;IAC5B,WAAA,IAAA,sBAAK,EAAC,sCAAmB,CAAC,CAAA;;GAtBlB,uBAAuB,CAoZnC;AApZY,0DAAuB","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.clear();\n this.backupDirtyBounds.clear();\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.clear();\n idc.backupDirtyBounds.clear();\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 stage && (context.globalAlpha = (stage as any).attribute.opacity ?? 1);\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"]}
@@ -16,7 +16,7 @@ Object.defineProperty(exports, "__esModule", {
16
16
  value: !0
17
17
  }), exports.DefaultCanvasImageRender = 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"), repeatStr = [ "", "repeat-x", "repeat-y", "repeat" ];
20
20
 
21
21
  let DefaultCanvasImageRender = class extends base_render_1.BaseRender {
22
22
  constructor(imageRenderContribitions) {
@@ -52,9 +52,7 @@ let DefaultCanvasImageRender = class extends base_render_1.BaseRender {
52
52
  draw(image, renderService, drawContext) {
53
53
  const {image: url} = image.attribute;
54
54
  if (!url || !image.resources) return;
55
- const res = image.resources.get(url);
56
- if ("loading" === res.state && (0, vutils_1.isString)(url)) return void loader_1.ResourceLoader.improveImageLoading(url);
57
- if ("success" !== res.state) return;
55
+ if ("success" !== image.resources.get(url).state) return;
58
56
  const {context: context} = renderService.drawParams;
59
57
  if (!context) return;
60
58
  const imageAttribute = (0, theme_1.getTheme)(image).image;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/render/contributions/render/image-render.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA2E;AAE3E,iFAA6E;AAC7E,kDAAkD;AAclD,yDAAoE;AAEpE,0DAA+D;AAE/D,6CAAqD;AACrD,qDAA4D;AAC5D,+CAA2C;AAC3C,mDAA2E;AAC3E,4DAAiE;AAEjE,MAAM,SAAS,GAAG,CAAC,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAGlD,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,wBAAkB;IAI9D,YAGqB,wBAAyE;QAE5F,KAAK,EAAE,CAAC;QAFW,6BAAwB,GAAxB,wBAAwB,CAAiD;QAL9F,eAAU,GAAW,6BAAiB,CAAC;QAQrC,IAAI,CAAC,oBAAoB,GAAG,CAAC,wDAAwC,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACtC,CAAC;IAED,SAAS,CACP,KAAa,EACb,OAAmB,EACnB,CAAS,EACT,CAAS,EACT,WAAyB,EACzB,MAAiC,EACjC,MAIY;QA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uB,CAAC,CAAA;;GANtB,wBAAwB,CA8HpC;AA9HY,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 } 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 imageRenderContribitions: IContributionProvider<IImageRenderContribution>\n ) {\n super();\n this.builtinContributions = [defaultImageBackgroundRenderContribution];\n this.init(imageRenderContribitions);\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 ) {\n // const imageAttribute = graphicService.themeService.getCurrentTheme().imageAttribute;\n const imageAttribute = getTheme(image).image;\n const {\n width = imageAttribute.width,\n height = imageAttribute.height,\n repeatX = imageAttribute.repeatX,\n repeatY = imageAttribute.repeatY,\n cornerRadius = imageAttribute.cornerRadius,\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 // shadow\n context.setShadowBlendStyle && context.setShadowBlendStyle(image, imageAttribute);\n\n this.beforeRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);\n\n // context.beginPath();\n // context.image(x, y, width, height);\n\n if (doFill) {\n if (fillCb) {\n fillCb(context, image.attribute, imageAttribute);\n } else if (fVisible) {\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 // deal with cornerRadius\n let needRestore = false;\n if (cornerRadius === 0 || (isArray(cornerRadius) && (<number[]>cornerRadius).every(num => num === 0))) {\n // 不需要处理圆角\n } else {\n context.beginPath();\n createRectPath(context, x, y, width, height, cornerRadius);\n context.save();\n context.clip();\n needRestore = true;\n }\n\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 if (needRestore) {\n context.restore();\n }\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 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;AAclD,yDAAoE;AAEpE,0DAA+D;AAE/D,6CAA2C;AAC3C,qDAA4D;AAC5D,+CAA2C;AAC3C,mDAA2E;AAE3E,MAAM,SAAS,GAAG,CAAC,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAGlD,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,wBAAkB;IAI9D,YAGqB,wBAAyE;QAE5F,KAAK,EAAE,CAAC;QAFW,6BAAwB,GAAxB,wBAAwB,CAAiD;QAL9F,eAAU,GAAW,6BAAiB,CAAC;QAQrC,IAAI,CAAC,oBAAoB,GAAG,CAAC,wDAAwC,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACtC,CAAC;IAED,SAAS,CACP,KAAa,EACb,OAAmB,EACnB,CAAS,EACT,CAAS,EACT,WAAyB,EACzB,MAAiC,EACjC,MAIY;QAGZ,MAAM,cAAc,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC,KAAK,CAAC;QAC7C,MAAM,EACJ,KAAK,GAAG,cAAc,CAAC,KAAK,EAC5B,MAAM,GAAG,cAAc,CAAC,MAAM,EAC9B,OAAO,GAAG,cAAc,CAAC,OAAO,EAChC,OAAO,GAAG,cAAc,CAAC,OAAO,EAChC,YAAY,GAAG,cAAc,CAAC,YAAY,EAC1C,KAAK,EAAE,GAAG,EACX,GAAG,KAAK,CAAC,SAAS,CAAC;QAEpB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;QACvD,IAAI,CAAC,IAAI,EAAE;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C,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;YAC5B,OAAO;SACR;QACD,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE;YAC3B,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;AAxHY,wBAAwB;IADpC,IAAA,2BAAU,GAAE;IAMR,WAAA,IAAA,uBAAM,EAAC,4CAAoB,CAAC,CAAA;IAC5B,WAAA,IAAA,sBAAK,EAAC,mCAAuB,CAAC,CAAA;;GANtB,wBAAwB,CAwHpC;AAxHY,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 } from '@visactor/vutils';\nimport { createRectPath } from '../../../common/shape/rect';\nimport { BaseRender } from './base-render';\nimport { defaultImageBackgroundRenderContribution } from './contributions';\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 imageRenderContribitions: IContributionProvider<IImageRenderContribution>\n ) {\n super();\n this.builtinContributions = [defaultImageBackgroundRenderContribution];\n this.init(imageRenderContribitions);\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 ) {\n // const imageAttribute = graphicService.themeService.getCurrentTheme().imageAttribute;\n const imageAttribute = getTheme(image).image;\n const {\n width = imageAttribute.width,\n height = imageAttribute.height,\n repeatX = imageAttribute.repeatX,\n repeatY = imageAttribute.repeatY,\n cornerRadius = imageAttribute.cornerRadius,\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 // shadow\n context.setShadowBlendStyle && context.setShadowBlendStyle(image, imageAttribute);\n\n this.beforeRenderStep(image, context, x, y, doFill, false, fVisible, false, imageAttribute, drawContext, fillCb);\n\n // context.beginPath();\n // context.image(x, y, width, height);\n\n if (doFill) {\n if (fillCb) {\n fillCb(context, image.attribute, imageAttribute);\n } else if (fVisible) {\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 // deal with cornerRadius\n let needRestore = false;\n if (cornerRadius === 0 || (isArray(cornerRadius) && (<number[]>cornerRadius).every(num => num === 0))) {\n // 不需要处理圆角\n } else {\n context.beginPath();\n createRectPath(context, x, y, width, height, cornerRadius);\n context.save();\n context.clip();\n needRestore = true;\n }\n\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 if (needRestore) {\n context.restore();\n }\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 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 { 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"]}
@@ -12,4 +12,3 @@ export * from './image-render';
12
12
  export * from './symbol';
13
13
  export * from './contributions';
14
14
  export * from './utils';
15
- export * from './draw-interceptor';
@@ -23,6 +23,5 @@ __exportStar(require("./path-render"), exports), __exportStar(require("./rect-re
23
23
  __exportStar(require("./symbol-render"), exports), __exportStar(require("./text-render"), exports),
24
24
  __exportStar(require("./graphic-render"), exports), __exportStar(require("./polygon-render"), exports),
25
25
  __exportStar(require("./image-render"), exports), __exportStar(require("./symbol"), exports),
26
- __exportStar(require("./contributions"), exports), __exportStar(require("./utils"), exports),
27
- __exportStar(require("./draw-interceptor"), exports);
26
+ __exportStar(require("./contributions"), exports), __exportStar(require("./utils"), exports);
28
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/render/contributions/render/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,kDAAgC;AAChC,gDAA8B;AAC9B,gDAA8B;AAC9B,gDAA8B;AAC9B,gDAA8B;AAC9B,kDAAgC;AAChC,gDAA8B;AAC9B,mDAAiC;AACjC,mDAAiC;AACjC,iDAA+B;AAC/B,2CAAyB;AACzB,kDAAgC;AAChC,0CAAwB;AACxB,qDAAmC","file":"index.js","sourcesContent":["export * from './arc-render';\nexport * from './circle-render';\nexport * from './line-render';\nexport * from './area-render';\nexport * from './path-render';\nexport * from './rect-render';\nexport * from './symbol-render';\nexport * from './text-render';\nexport * from './graphic-render';\nexport * from './polygon-render';\nexport * from './image-render';\nexport * from './symbol';\nexport * from './contributions';\nexport * from './utils';\nexport * from './draw-interceptor';\n"]}
1
+ {"version":3,"sources":["../src/render/contributions/render/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,kDAAgC;AAChC,gDAA8B;AAC9B,gDAA8B;AAC9B,gDAA8B;AAC9B,gDAA8B;AAC9B,kDAAgC;AAChC,gDAA8B;AAC9B,mDAAiC;AACjC,mDAAiC;AACjC,iDAA+B;AAC/B,2CAAyB;AACzB,kDAAgC;AAChC,0CAAwB","file":"index.js","sourcesContent":["export * from './arc-render';\nexport * from './circle-render';\nexport * from './line-render';\nexport * from './area-render';\nexport * from './path-render';\nexport * from './rect-render';\nexport * from './symbol-render';\nexport * from './text-render';\nexport * from './graphic-render';\nexport * from './polygon-render';\nexport * from './image-render';\nexport * from './symbol';\nexport * from './contributions';\nexport * from './utils';\n"]}
@@ -1,14 +1,9 @@
1
1
  import type { IImage, ImagePayload } from '../interface';
2
2
  export declare class ResourceLoader {
3
3
  private static cache;
4
- private static isLoading;
5
- private static toLoadAueue;
6
4
  static GetImage(url: string, mark: ImagePayload): void;
7
5
  static GetSvg(svgStr: string, mark: IImage): void;
8
6
  static GetFile(url: string, type: 'json' | 'arrayBuffer' | 'blob'): Promise<HTMLImageElement | ImageData | ArrayBuffer | Blob | ImageBitmap | OffscreenCanvas | {
9
7
  [id: string]: any;
10
8
  }>;
11
- static loading(): void;
12
- static loadImage(url: string, mark: ImagePayload): void;
13
- static improveImageLoading(url: string): void;
14
9
  }
@@ -4,15 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.ResourceLoader = void 0;
6
6
 
7
- const application_1 = require("../application"), PARALLEL_NUMBER = 10;
7
+ const application_1 = require("../application");
8
8
 
9
9
  class ResourceLoader {
10
10
  static GetImage(url, mark) {
11
11
  var _a;
12
- const data = ResourceLoader.cache.get(url);
12
+ let data = ResourceLoader.cache.get(url);
13
13
  data ? "fail" === data.loadState ? application_1.application.global.getRequestAnimationFrame()((() => {
14
14
  mark.imageLoadFail(url);
15
- })) : "init" === data.loadState || "loading" === data.loadState ? null === (_a = data.waitingMark) || void 0 === _a || _a.push(mark) : mark && mark.imageLoadSuccess(url, data.data) : ResourceLoader.loadImage(url, mark);
15
+ })) : "init" === data.loadState || "loading" === data.loadState ? null === (_a = data.waitingMark) || void 0 === _a || _a.push(mark) : mark && mark.imageLoadSuccess(url, data.data) : (data = {
16
+ type: "image",
17
+ loadState: "init"
18
+ }, ResourceLoader.cache.set(url, data), data.dataPromise = application_1.application.global.loadImage(url),
19
+ data.dataPromise ? (data.waitingMark = [ mark ], data.dataPromise.then((res => {
20
+ var _a;
21
+ data.loadState = (null == res ? void 0 : res.data) ? "success" : "fail", data.data = null == res ? void 0 : res.data,
22
+ null === (_a = data.waitingMark) || void 0 === _a || _a.map(((mark, index) => {
23
+ (null == res ? void 0 : res.data) ? (data.loadState = "success", data.data = res.data,
24
+ mark.imageLoadSuccess(url, res.data)) : (data.loadState = "fail", mark.imageLoadFail(url));
25
+ }));
26
+ }))) : (data.loadState = "fail", mark.imageLoadFail(url)));
16
27
  }
17
28
  static GetSvg(svgStr, mark) {
18
29
  var _a;
@@ -42,59 +53,7 @@ class ResourceLoader {
42
53
  }, ResourceLoader.cache.set(url, data), "arrayBuffer" === type ? data.dataPromise = application_1.application.global.loadArrayBuffer(url) : "blob" === type ? data.dataPromise = application_1.application.global.loadBlob(url) : "json" === type && (data.dataPromise = application_1.application.global.loadJson(url)),
43
54
  data.dataPromise.then((data => data.data)));
44
55
  }
45
- static loading() {
46
- setTimeout((() => {
47
- if (!ResourceLoader.isLoading && ResourceLoader.toLoadAueue.length) {
48
- ResourceLoader.isLoading = !0;
49
- const tasks = ResourceLoader.toLoadAueue.splice(0, 10), promises = [];
50
- tasks.forEach((task => {
51
- const {url: url, marks: marks} = task, data = {
52
- type: "image",
53
- loadState: "init"
54
- };
55
- if (ResourceLoader.cache.set(url, data), data.dataPromise = application_1.application.global.loadImage(url),
56
- data.dataPromise) {
57
- data.waitingMark = marks;
58
- const end = data.dataPromise.then((res => {
59
- var _a;
60
- data.loadState = (null == res ? void 0 : res.data) ? "success" : "fail", data.data = null == res ? void 0 : res.data,
61
- null === (_a = data.waitingMark) || void 0 === _a || _a.map(((mark, index) => {
62
- (null == res ? void 0 : res.data) ? (data.loadState = "success", data.data = res.data,
63
- mark.imageLoadSuccess(url, res.data)) : (data.loadState = "fail", mark.imageLoadFail(url));
64
- }));
65
- }));
66
- promises.push(end);
67
- } else data.loadState = "fail", marks.forEach((mark => mark.imageLoadFail(url)));
68
- })), Promise.all(promises).then((() => {
69
- ResourceLoader.isLoading = !1, ResourceLoader.loading();
70
- })).catch((error => {
71
- console.error(error), ResourceLoader.isLoading = !1, ResourceLoader.loading();
72
- }));
73
- }
74
- }), 0);
75
- }
76
- static loadImage(url, mark) {
77
- const index = getIndex(url, ResourceLoader.toLoadAueue);
78
- if (-1 !== index) return ResourceLoader.toLoadAueue[index].marks.push(mark), void ResourceLoader.loading();
79
- ResourceLoader.toLoadAueue.push({
80
- url: url,
81
- marks: [ mark ]
82
- }), ResourceLoader.loading();
83
- }
84
- static improveImageLoading(url) {
85
- const index = getIndex(url, ResourceLoader.toLoadAueue);
86
- if (-1 !== index) {
87
- const elememt = ResourceLoader.toLoadAueue.splice(index, 1);
88
- ResourceLoader.toLoadAueue.unshift(elememt[0]);
89
- }
90
- }
91
- }
92
-
93
- function getIndex(url, arr) {
94
- for (let i = 0; i < arr.length; i++) if (arr[i].url === url) return i;
95
- return -1;
96
56
  }
97
57
 
98
- exports.ResourceLoader = ResourceLoader, ResourceLoader.cache = new Map, ResourceLoader.isLoading = !1,
99
- ResourceLoader.toLoadAueue = [];
58
+ exports.ResourceLoader = ResourceLoader, ResourceLoader.cache = new Map;
100
59
  //# sourceMappingURL=loader.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/resource-loader/loader.ts"],"names":[],"mappings":";;;AACA,gDAA6C;AAE7C,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAa,cAAc;IAKzB,MAAM,CAAC,QAAQ,CAAC,GAAW,EAAE,IAAkB;;QAC7C,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,IAAI,EAAE;YAER,IAAI,IAAI,CAAC,SAAS,KAAK,MAAM,EAAE;gBAE7B,yBAAW,CAAC,MAAM,CAAC,wBAAwB,EAAE,CAAC,GAAG,EAAE;oBACjD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;gBAC1B,CAAC,CAAC,CAAC;aACJ;iBAAM,IAAI,IAAI,CAAC,SAAS,KAAK,MAAM,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE;gBAEpE,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,CAAC,IAAI,CAAC,CAAC;aAC9B;iBAAM,IAAI,IAAI,EAAE;gBACf,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,IAAwB,CAAC,CAAC;aAC3D;SACF;aAAM;YACL,cAAc,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;SA6BrC;IACH,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,IAAY;;QACxC,IAAI,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,IAAI,EAAE;YAER,IAAI,IAAI,C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AG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,EAAE;YACtB,OAAO,CAAC,CAAC;SACV;KACF;IACD,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC","file":"loader.js","sourcesContent":["import type { IImage, ImagePayload, ResourceData } from '../interface';\nimport { application } from '../application';\n\nconst PARALLEL_NUMBER = 10;\nexport class ResourceLoader {\n private static cache: Map<string, ResourceData> = new Map();\n private static isLoading: boolean = false;\n private static toLoadAueue: { url: string; marks: ImagePayload[] }[] = [];\n\n static GetImage(url: string, mark: ImagePayload) {\n const data = ResourceLoader.cache.get(url);\n if (data) {\n // 存在缓存\n if (data.loadState === 'fail') {\n // 资源请求失败,修改mark状态\n application.global.getRequestAnimationFrame()(() => {\n mark.imageLoadFail(url);\n });\n } else if (data.loadState === 'init' || data.loadState === 'loading') {\n // 资源padding队列加入mark信息\n data.waitingMark?.push(mark);\n } else if (mark) {\n mark.imageLoadSuccess(url, data.data as HTMLImageElement);\n }\n } else {\n ResourceLoader.loadImage(url, mark);\n // data = { type: 'image', loadState: 'init' };\n // ResourceLoader.cache.set(url, data);\n\n // data.dataPromise = application.global.loadImage(url);\n // if (!data.dataPromise) {\n // // 无法获取资源,修改缓存和mark状态\n // data.loadState = 'fail';\n // mark.imageLoadFail(url);\n // } else {\n // // 资源padding队列加入mark信息\n // data.waitingMark = [mark];\n\n // data.dataPromise.then(res => {\n // data.loadState = res?.data ? 'success' : 'fail';\n // data.data = res?.data;\n // // 遍历资源padding队列,更新mark信息\n // data.waitingMark?.map((mark: IImage, index) => {\n // if (res?.data) {\n // data.loadState = 'success';\n // data.data = res.data;\n // mark.imageLoadSuccess(url, res.data as HTMLImageElement);\n // } else {\n // data.loadState = 'fail';\n // mark.imageLoadFail(url);\n // }\n // });\n // });\n // }\n }\n }\n\n static GetSvg(svgStr: string, mark: IImage) {\n let data = ResourceLoader.cache.get(svgStr);\n if (data) {\n // 存在缓存\n if (data.loadState === 'fail') {\n // 资源请求失败,修改mark状态\n application.global.getRequestAnimationFrame()(() => {\n mark.imageLoadFail(svgStr);\n });\n } else if (data.loadState === 'init' || data.loadState === 'loading') {\n // 资源padding队列加入mark信息\n data.waitingMark?.push(mark);\n } else if (mark) {\n application.global.getRequestAnimationFrame()(() => {\n mark.imageLoadSuccess(svgStr, data.data as HTMLImageElement);\n });\n }\n } else {\n data = { type: 'image', loadState: 'init' };\n ResourceLoader.cache.set(svgStr, data);\n\n data.dataPromise = application.global.loadSvg(svgStr);\n if (!data.dataPromise) {\n // 无法获取资源,修改缓存和mark状态\n data.loadState = 'fail';\n mark.imageLoadFail(svgStr);\n } else {\n // 资源padding队列加入mark信息\n data.waitingMark = [mark];\n\n data.dataPromise.then(res => {\n data.loadState = res?.data ? 'success' : 'fail';\n data.data = res?.data;\n // 遍历资源padding队列,更新mark信息\n data.waitingMark?.map((mark: IImage, index) => {\n if (res?.data) {\n data.loadState = 'success';\n data.data = res.data;\n mark.imageLoadSuccess(svgStr, res.data as HTMLImageElement);\n } else {\n data.loadState = 'fail';\n mark.imageLoadFail(svgStr);\n }\n });\n });\n }\n }\n }\n\n static GetFile(url: string, type: 'json' | 'arrayBuffer' | 'blob') {\n let data = ResourceLoader.cache.get(url);\n if (data) {\n // 存在缓存\n if (data.loadState === 'init' || data.loadState === 'fail') {\n return Promise.reject();\n } else if (data.loadState === 'loading') {\n return data.dataPromise.then(data => data.data);\n }\n return Promise.resolve(data.data);\n }\n data = { type, loadState: 'init' };\n ResourceLoader.cache.set(url, data);\n\n if (type === 'arrayBuffer') {\n data.dataPromise = application.global.loadArrayBuffer(url);\n } else if (type === 'blob') {\n data.dataPromise = application.global.loadBlob(url);\n } else if (type === 'json') {\n data.dataPromise = application.global.loadJson(url);\n }\n\n return data.dataPromise.then(data => data.data);\n }\n\n static loading() {\n setTimeout(() => {\n if (!ResourceLoader.isLoading && ResourceLoader.toLoadAueue.length) {\n ResourceLoader.isLoading = true;\n const tasks = ResourceLoader.toLoadAueue.splice(0, PARALLEL_NUMBER);\n const promises: Promise<void>[] = [];\n tasks.forEach(task => {\n const { url, marks } = task;\n const data: ResourceData = { type: 'image', loadState: 'init' };\n ResourceLoader.cache.set(url, data);\n\n data.dataPromise = application.global.loadImage(url);\n if (!data.dataPromise) {\n // 无法获取资源,修改缓存和mark状态\n data.loadState = 'fail';\n // mark.imageLoadFail(url);\n marks.forEach(mark => mark.imageLoadFail(url));\n } else {\n // 资源padding队列加入mark信息\n // data.waitingMark = [mark];\n data.waitingMark = marks;\n\n const end = data.dataPromise.then(res => {\n data.loadState = res?.data ? 'success' : 'fail';\n data.data = res?.data;\n // 遍历资源padding队列,更新mark信息\n data.waitingMark?.map((mark: IImage, index) => {\n if (res?.data) {\n data.loadState = 'success';\n data.data = res.data;\n // console.log(mark.attribute.y)\n mark.imageLoadSuccess(url, res.data as HTMLImageElement);\n } else {\n data.loadState = 'fail';\n mark.imageLoadFail(url);\n }\n });\n });\n\n promises.push(end);\n }\n });\n\n Promise.all(promises)\n .then(() => {\n ResourceLoader.isLoading = false;\n ResourceLoader.loading();\n })\n .catch(error => {\n console.error(error);\n ResourceLoader.isLoading = false;\n ResourceLoader.loading();\n });\n }\n }, 0);\n }\n\n static loadImage(url: string, mark: ImagePayload) {\n // find url in toLoadAueue\n const index = getIndex(url, ResourceLoader.toLoadAueue);\n if (index !== -1) {\n // add mark to aueue\n ResourceLoader.toLoadAueue[index].marks.push(mark);\n ResourceLoader.loading();\n return;\n }\n\n // add task to aueue\n ResourceLoader.toLoadAueue.push({ url, marks: [mark] });\n ResourceLoader.loading();\n }\n\n static improveImageLoading(url: string) {\n const index = getIndex(url, ResourceLoader.toLoadAueue);\n if (index !== -1) {\n const elememt = ResourceLoader.toLoadAueue.splice(index, 1);\n ResourceLoader.toLoadAueue.unshift(elememt[0]);\n }\n }\n}\n\nfunction getIndex(url: string, arr: { url: string; marks: ImagePayload[] }[]) {\n for (let i = 0; i < arr.length; i++) {\n if (arr[i].url === url) {\n return i;\n }\n }\n return -1;\n}\n"]}
1
+ {"version":3,"sources":["../src/resource-loader/loader.ts"],"names":[],"mappings":";;;AACA,gDAA6C;AAE7C,MAAa,cAAc;IAGzB,MAAM,CAAC,QAAQ,CAAC,GAAW,EAAE,IAAkB;;QAC7C,IAAI,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,IAAI,EAAE;YAER,IAAI,IAAI,CAAC,SAAS,KAAK,MAAM,EAAE;gBAE7B,yBAAW,CAAC,MAAM,CAAC,wBAAwB,EAAE,CAAC,GAAG,EAAE;oBACjD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;gBAC1B,CAAC,CAAC,CAAC;aACJ;iBAAM,IAAI,IAAI,CAAC,SAAS,KAAK,MAAM,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE;gBAEpE,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,CAAC,IAAI,CAAC,CAAC;aAC9B;iBAAM,IAAI,IAAI,EAAE;gBACf,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,IAAwB,CAAC,CAAC;aAC3D;SACF;aAAM;YACL,IAAI,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;YAC5C,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAEpC,IAAI,CAAC,WAAW,GAAG,yBAAW,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACrD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;gBAErB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;gBACxB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;aACzB;iBAAM;gBAEL,IAAI,CAAC,WAAW,GAAG,CAAC,IAAI,CAA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EAAE;YAC1B,IAAI,CAAC,WAAW,GAAG,yBAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SACrD;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;;AA1HH,wCA2HC;AA1HgB,oBAAK,GAA8B,IAAI,GAAG,EAAE,CAAC","file":"loader.js","sourcesContent":["import type { IImage, ImagePayload, ResourceData } from '../interface';\nimport { application } from '../application';\n\nexport class ResourceLoader {\n private static cache: Map<string, ResourceData> = new Map();\n\n static GetImage(url: string, mark: ImagePayload) {\n let data = ResourceLoader.cache.get(url);\n if (data) {\n // 存在缓存\n if (data.loadState === 'fail') {\n // 资源请求失败,修改mark状态\n application.global.getRequestAnimationFrame()(() => {\n mark.imageLoadFail(url);\n });\n } else if (data.loadState === 'init' || data.loadState === 'loading') {\n // 资源padding队列加入mark信息\n data.waitingMark?.push(mark);\n } else if (mark) {\n mark.imageLoadSuccess(url, data.data as HTMLImageElement);\n }\n } else {\n data = { type: 'image', loadState: 'init' };\n ResourceLoader.cache.set(url, data);\n\n data.dataPromise = application.global.loadImage(url);\n if (!data.dataPromise) {\n // 无法获取资源,修改缓存和mark状态\n data.loadState = 'fail';\n mark.imageLoadFail(url);\n } else {\n // 资源padding队列加入mark信息\n data.waitingMark = [mark];\n\n data.dataPromise.then(res => {\n data.loadState = res?.data ? 'success' : 'fail';\n data.data = res?.data;\n // 遍历资源padding队列,更新mark信息\n data.waitingMark?.map((mark: IImage, index) => {\n if (res?.data) {\n data.loadState = 'success';\n data.data = res.data;\n mark.imageLoadSuccess(url, res.data as HTMLImageElement);\n } else {\n data.loadState = 'fail';\n mark.imageLoadFail(url);\n }\n });\n });\n }\n }\n }\n\n static GetSvg(svgStr: string, mark: IImage) {\n let data = ResourceLoader.cache.get(svgStr);\n if (data) {\n // 存在缓存\n if (data.loadState === 'fail') {\n // 资源请求失败,修改mark状态\n application.global.getRequestAnimationFrame()(() => {\n mark.imageLoadFail(svgStr);\n });\n } else if (data.loadState === 'init' || data.loadState === 'loading') {\n // 资源padding队列加入mark信息\n data.waitingMark?.push(mark);\n } else if (mark) {\n application.global.getRequestAnimationFrame()(() => {\n mark.imageLoadSuccess(svgStr, data.data as HTMLImageElement);\n });\n }\n } else {\n data = { type: 'image', loadState: 'init' };\n ResourceLoader.cache.set(svgStr, data);\n\n data.dataPromise = application.global.loadSvg(svgStr);\n if (!data.dataPromise) {\n // 无法获取资源,修改缓存和mark状态\n data.loadState = 'fail';\n mark.imageLoadFail(svgStr);\n } else {\n // 资源padding队列加入mark信息\n data.waitingMark = [mark];\n\n data.dataPromise.then(res => {\n data.loadState = res?.data ? 'success' : 'fail';\n data.data = res?.data;\n // 遍历资源padding队列,更新mark信息\n data.waitingMark?.map((mark: IImage, index) => {\n if (res?.data) {\n data.loadState = 'success';\n data.data = res.data;\n mark.imageLoadSuccess(svgStr, res.data as HTMLImageElement);\n } else {\n data.loadState = 'fail';\n mark.imageLoadFail(svgStr);\n }\n });\n });\n }\n }\n }\n\n static GetFile(url: string, type: 'json' | 'arrayBuffer' | 'blob') {\n let data = ResourceLoader.cache.get(url);\n if (data) {\n // 存在缓存\n if (data.loadState === 'init' || data.loadState === 'fail') {\n return Promise.reject();\n } else if (data.loadState === 'loading') {\n return data.dataPromise.then(data => data.data);\n }\n return Promise.resolve(data.data);\n }\n data = { type, loadState: 'init' };\n ResourceLoader.cache.set(url, data);\n\n if (type === 'arrayBuffer') {\n data.dataPromise = application.global.loadArrayBuffer(url);\n } else if (type === 'blob') {\n data.dataPromise = application.global.loadBlob(url);\n } else if (type === 'json') {\n data.dataPromise = application.global.loadJson(url);\n }\n\n return data.dataPromise.then(data => data.data);\n }\n}\n"]}
package/es/graphic/arc.js CHANGED
@@ -83,7 +83,7 @@ export class Arc extends Graphic {
83
83
  }
84
84
  doUpdateAABBBounds(full) {
85
85
  const arcTheme = getTheme(this).arc;
86
- this._AABBBounds.setValue(1 / 0, 1 / 0, -1 / 0, -1 / 0);
86
+ this._AABBBounds.clear();
87
87
  const attribute = this.attribute, bounds = application.graphicService.updateArcAABBBounds(attribute, getTheme(this).arc, this._AABBBounds, full, this), {boundsPadding: boundsPadding = arcTheme.boundsPadding} = attribute, paddingArray = parsePadding(boundsPadding);
88
88
  return paddingArray && bounds.expand(paddingArray), this.clearUpdateBoundTag(),
89
89
  bounds;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/arc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEzG,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmB9C,MAAM,kBAAkB,GAAG;IACzB,aAAa;IACb,aAAa;IACb,YAAY;IACZ,UAAU;IACV,cAAc;IACd,UAAU;IACV,WAAW;IACX,KAAK;IACL,GAAG,sBAAsB;CAC1B,CAAC;AAMF,MAAM,OAAO,GAAI,SAAQ,OAA6B;IA8CpD,YAAY,MAA4B;QACtC,KAAK,CAAC,MAAM,CAAC,CAAC;QA9ChB,SAAI,GAAgB,KAAK,CAAC;QA+CxB,IAAI,CAAC,UAAU,GAAG,eAAe,CAAC;IACpC,CAAC;IAED,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE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W,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,SAAS,CAAC,CAAC;YAC9D,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YAChC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;YAC7D,IAAI,CAAC,SAAS,EAAE,CAAC;SAClB;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,GAAG,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IACxC,CAAC;IAED,oBAAoB;QAClB,OAAO,GAAG,CAAC,mBAAmB,CAAC;IACjC,CAAC;;AAhRM,uBAAmB,mBACxB,GAAG,EAAE,CAAC,IACH,mBAAmB,EACtB;AAgRJ,MAAM,UAAU,SAAS,CAAC,UAAgC;IACxD,OAAO,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;AAC7B,CAAC","file":"arc.js","sourcesContent":["import type { AABBBounds, OBBBounds } from '@visactor/vutils';\nimport { pi2, sin, epsilon, abs, asin, clampAngleByRadian, isNumber, cos, sqrt } from '@visactor/vutils';\nimport type { IArc, IArcGraphicAttribute } from '../interface/graphic/arc';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { parsePadding } from '../common/utils';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport type { GraphicType } from '../interface';\nimport { ARC_NUMBER_TYPE } from './constants';\n\n/**\n * 部分代码参考 https://github.com/d3/d3-shape/\n * Copyright 2010-2022 Mike Bostock\n\n Permission to use, copy, modify, and/or distribute this software for any purpose\n with or without fee is hereby granted, provided that the above copyright notice\n and this permission notice appear in all copies.\n\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n THIS SOFTWARE.\n */\n\nconst ARC_UPDATE_TAG_KEY = [\n 'innerRadius',\n 'outerRadius',\n 'startAngle',\n 'endAngle',\n 'cornerRadius',\n 'padAngle',\n 'padRadius',\n 'cap',\n ...GRAPHIC_UPDATE_TAG_KEY\n];\n\n/**\n * 圆形图元\n * 默认顺时针绘制\n */\nexport class Arc extends Graphic<IArcGraphicAttribute> implements IArc {\n type: GraphicType = 'arc';\n\n static NOWORK_ANIMATE_ATTR = {\n cap: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n // static parseCornerRadius(r: IArcGraphicAttribute['cornerRadius']) {\n // if (isArray(r)) {\n // if ((r as any[]).length === 1) {\n // const value = r[0];\n // return [value, value, value, value];\n // }\n\n // if ((r as any[]).length === 2) {\n // return [r[0], r[0], r[1], r[1]];\n // }\n\n // if ((r as any[]).length === 3) {\n // return [r[0], r[1], r[2], 0];\n // }\n\n // return (r as any[]).slice(0, 4);\n // }\n\n // return [r as string | number, r as string | number, r as string | number, r as string | number];\n // }\n\n // static isCornerRadiusEqual(oldR: IArcGraphicAttribute['cornerRadius'], newR: IArcGraphicAttribute['cornerRadius']) {\n // throw new Error('暂不支持');\n // if (oldR === newR) {\n // return true;\n // }\n\n // if (isArray(oldR) && !isArray(newR)) {\n // return (oldR as (string | number)[]).every(r => r === newR);\n // }\n\n // if (!isArray(oldR) && isArray(newR)) {\n // return (newR as (string | number)[]).every(r => r === oldR);\n // }\n\n // return arrayEqual(oldR as (string | number)[], newR as (string | number)[]);\n // }\n\n constructor(params: IArcGraphicAttribute) {\n super(params);\n this.numberType = ARC_NUMBER_TYPE;\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n const { startAngle, endAngle, outerRadius, innerRadius } = this.attribute;\n return (\n this._validNumber(startAngle) &&\n this._validNumber(endAngle) &&\n this._validNumber(outerRadius) &&\n this._validNumber(innerRadius)\n );\n }\n\n getParsedCornerRadius() {\n const arcTheme = getTheme(this).arc;\n const {\n cornerRadius = arcTheme.cornerRadius,\n outerRadius = arcTheme.outerRadius,\n innerRadius = arcTheme.innerRadius\n } = this.attribute;\n if (cornerRadius === 0 || cornerRadius === '0%') {\n return 0;\n }\n const deltaRadius = Math.abs(outerRadius - innerRadius);\n return Math.min(\n isNumber(cornerRadius, true)\n ? (cornerRadius as number)\n : (deltaRadius * parseFloat(cornerRadius as string)) / 100,\n deltaRadius / 2\n );\n }\n\n getParsedAngle() {\n const arcTheme = getTheme(this).arc;\n let { startAngle = arcTheme.startAngle, endAngle = arcTheme.endAngle } = this.attribute;\n const { cap = arcTheme.cap } = this.attribute;\n\n const sign = endAngle - startAngle >= 0 ? 1 : -1;\n const deltaAngle = endAngle - startAngle;\n\n startAngle = clampAngleByRadian(startAngle);\n endAngle = startAngle + deltaAngle;\n\n if (cap && abs(deltaAngle) < pi2 - epsilon) {\n let startCap = 1;\n let endCap = 1;\n if ((cap as boolean[]).length) {\n startCap = Number(cap[0]);\n endCap = Number(cap[1]);\n }\n const { outerRadius = arcTheme.outerRadius, innerRadius = arcTheme.innerRadius } = this.attribute;\n const capWidth = Math.abs(outerRadius - innerRadius) / 2;\n // 以外边界长度为准\n const capAngle = capWidth / outerRadius;\n\n if (capWidth > epsilon && outerRadius > epsilon) {\n return {\n startAngle: startAngle - sign * capAngle * startCap,\n endAngle: endAngle + sign * capAngle * endCap,\n sc: sign * capAngle * startCap,\n ec: sign * capAngle * endCap\n };\n }\n }\n\n return {\n startAngle: startAngle,\n endAngle: endAngle\n };\n }\n\n // 参考 https://github.com/d3/d3-shape/blob/main/src/arc.js\n getParsePadAngle(startAngle: number, endAngle: number) {\n const arcTheme = getTheme(this).arc;\n const {\n outerRadius = arcTheme.outerRadius,\n innerRadius = arcTheme.innerRadius,\n padAngle = arcTheme.padAngle\n } = this.attribute;\n\n const { padRadius = sqrt(outerRadius * outerRadius + innerRadius * innerRadius) } = this.attribute;\n const deltaAngle = abs(endAngle - startAngle);\n\n // Or is it a circular or annular sector?\n let outerStartAngle = startAngle;\n let outerEndAngle = endAngle;\n let innerStartAngle = startAngle;\n let innerEndAngle = endAngle;\n const halfPadAngle = padAngle / 2;\n let innerDeltaAngle = deltaAngle;\n let outerDeltaAngle = deltaAngle;\n\n // Apply padding? Note that since r1 ≥ r0, outerDeltaAngle ≥ innerDeltaAngle.\n if (halfPadAngle > epsilon && padRadius > epsilon) {\n const sign = endAngle > startAngle ? 1 : -1;\n\n let p0 = asin((Number(padRadius) / innerRadius) * sin(halfPadAngle));\n let p1 = asin((Number(padRadius) / outerRadius) * sin(halfPadAngle));\n if ((innerDeltaAngle -= p0 * 2) > epsilon) {\n p0 *= sign;\n innerStartAngle += p0;\n innerEndAngle -= p0;\n } else {\n innerDeltaAngle = 0;\n innerStartAngle = innerEndAngle = (startAngle + endAngle) / 2;\n }\n if ((outerDeltaAngle -= p1 * 2) > epsilon) {\n p1 *= sign;\n outerStartAngle += p1;\n outerEndAngle -= p1;\n } else {\n outerDeltaAngle = 0;\n outerStartAngle = outerEndAngle = (startAngle + endAngle) / 2;\n }\n\n return {\n outerStartAngle,\n outerEndAngle,\n innerStartAngle,\n innerEndAngle,\n innerDeltaAngle,\n outerDeltaAngle\n };\n }\n\n return {\n outerStartAngle,\n outerEndAngle,\n innerStartAngle,\n innerEndAngle,\n innerDeltaAngle,\n outerDeltaAngle\n };\n }\n\n protected doUpdateAABBBounds(full?: boolean): AABBBounds {\n const arcTheme = getTheme(this).arc;\n this._AABBBounds.setValue(Infinity, Infinity, -Infinity, -Infinity);\n const attribute = this.attribute;\n const bounds = application.graphicService.updateArcAABBBounds(\n attribute,\n getTheme(this).arc,\n this._AABBBounds,\n full,\n this\n ) as AABBBounds;\n\n const { boundsPadding = arcTheme.boundsPadding } = attribute;\n const paddingArray = parsePadding(boundsPadding);\n if (paddingArray) {\n bounds.expand(paddingArray);\n }\n this.clearUpdateBoundTag();\n return bounds;\n }\n\n protected tryUpdateOBBBounds(): OBBBounds {\n throw new Error('暂不支持');\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, ARC_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, ARC_UPDATE_TAG_KEY);\n }\n\n getDefaultAttribute(name: string) {\n const arcTheme = getTheme(this).arc;\n return arcTheme[name];\n }\n\n toCustomPath() {\n const x = 0;\n const y = 0;\n\n const attribute = this.attribute;\n const { startAngle, endAngle } = this.getParsedAngle();\n let innerRadius = attribute.innerRadius;\n let outerRadius = attribute.outerRadius;\n const deltaAngle = abs(endAngle - startAngle);\n const clockwise: boolean = endAngle > startAngle;\n\n if (outerRadius < innerRadius) {\n const temp = outerRadius;\n outerRadius = innerRadius;\n innerRadius = temp;\n }\n\n const path = new CustomPath2D();\n\n if (outerRadius <= epsilon) {\n path.moveTo(x, y);\n } else if (deltaAngle >= pi2 - epsilon) {\n // 是个完整的圆环\n // Or is it a circle or annulus?\n path.moveTo(x + outerRadius * cos(startAngle), y + outerRadius * sin(startAngle));\n path.arc(x, y, outerRadius, startAngle, endAngle, !clockwise);\n if (innerRadius > epsilon) {\n path.moveTo(x + innerRadius * cos(endAngle), y + innerRadius * sin(endAngle));\n path.arc(x, y, innerRadius, endAngle, startAngle, clockwise);\n }\n } else {\n const xors = outerRadius * cos(startAngle);\n const yors = outerRadius * sin(startAngle);\n const xire = innerRadius * cos(endAngle);\n const yire = innerRadius * sin(endAngle);\n\n path.moveTo(x + xors, y + yors);\n path.arc(x, y, outerRadius, startAngle, endAngle, !clockwise);\n path.lineTo(x + xire, y + yire);\n path.arc(x, y, innerRadius, endAngle, startAngle, clockwise);\n path.closePath();\n }\n\n return path;\n }\n\n clone() {\n return new Arc({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Arc.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createArc(attributes: IArcGraphicAttribute): IArc {\n return new Arc(attributes);\n}\n\n// addAttributeToPrototype(DefaultCircleStyle, Circle, PURE_STYLE_KEY);\n"]}
1
+ {"version":3,"sources":["../src/graphic/arc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEzG,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmB9C,MAAM,kBAAkB,GAAG;IACzB,aAAa;IACb,aAAa;IACb,YAAY;IACZ,UAAU;IACV,cAAc;IACd,UAAU;IACV,WAAW;IACX,KAAK;IACL,GAAG,sBAAsB;CAC1B,CAAC;AAMF,MAAM,OAAO,GAAI,SAAQ,OAA6B;IA8CpD,YAAY,MAA4B;QACtC,KAAK,CAAC,MAAM,CAAC,CAAC;QA9ChB,SAAI,GAAgB,KAAK,CAAC;QA+CxB,IAAI,CAAC,UAAU,GAAG,eAAe,CAAC;IACpC,CAAC;IAED,OAAO;QACL,OAAO,KAAK,CAAC,OA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,EAAE,CAAC,SAAS,CAAC,CAAC;YAC9D,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YAChC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;YAC7D,IAAI,CAAC,SAAS,EAAE,CAAC;SAClB;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,GAAG,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IACxC,CAAC;IAED,oBAAoB;QAClB,OAAO,GAAG,CAAC,mBAAmB,CAAC;IACjC,CAAC;;AAhRM,uBAAmB,mBACxB,GAAG,EAAE,CAAC,IACH,mBAAmB,EACtB;AAgRJ,MAAM,UAAU,SAAS,CAAC,UAAgC;IACxD,OAAO,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;AAC7B,CAAC","file":"arc.js","sourcesContent":["import type { AABBBounds, OBBBounds } from '@visactor/vutils';\nimport { pi2, sin, epsilon, abs, asin, clampAngleByRadian, isNumber, cos, sqrt } from '@visactor/vutils';\nimport type { IArc, IArcGraphicAttribute } from '../interface/graphic/arc';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { parsePadding } from '../common/utils';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport type { GraphicType } from '../interface';\nimport { ARC_NUMBER_TYPE } from './constants';\n\n/**\n * 部分代码参考 https://github.com/d3/d3-shape/\n * Copyright 2010-2022 Mike Bostock\n\n Permission to use, copy, modify, and/or distribute this software for any purpose\n with or without fee is hereby granted, provided that the above copyright notice\n and this permission notice appear in all copies.\n\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n THIS SOFTWARE.\n */\n\nconst ARC_UPDATE_TAG_KEY = [\n 'innerRadius',\n 'outerRadius',\n 'startAngle',\n 'endAngle',\n 'cornerRadius',\n 'padAngle',\n 'padRadius',\n 'cap',\n ...GRAPHIC_UPDATE_TAG_KEY\n];\n\n/**\n * 圆形图元\n * 默认顺时针绘制\n */\nexport class Arc extends Graphic<IArcGraphicAttribute> implements IArc {\n type: GraphicType = 'arc';\n\n static NOWORK_ANIMATE_ATTR = {\n cap: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n // static parseCornerRadius(r: IArcGraphicAttribute['cornerRadius']) {\n // if (isArray(r)) {\n // if ((r as any[]).length === 1) {\n // const value = r[0];\n // return [value, value, value, value];\n // }\n\n // if ((r as any[]).length === 2) {\n // return [r[0], r[0], r[1], r[1]];\n // }\n\n // if ((r as any[]).length === 3) {\n // return [r[0], r[1], r[2], 0];\n // }\n\n // return (r as any[]).slice(0, 4);\n // }\n\n // return [r as string | number, r as string | number, r as string | number, r as string | number];\n // }\n\n // static isCornerRadiusEqual(oldR: IArcGraphicAttribute['cornerRadius'], newR: IArcGraphicAttribute['cornerRadius']) {\n // throw new Error('暂不支持');\n // if (oldR === newR) {\n // return true;\n // }\n\n // if (isArray(oldR) && !isArray(newR)) {\n // return (oldR as (string | number)[]).every(r => r === newR);\n // }\n\n // if (!isArray(oldR) && isArray(newR)) {\n // return (newR as (string | number)[]).every(r => r === oldR);\n // }\n\n // return arrayEqual(oldR as (string | number)[], newR as (string | number)[]);\n // }\n\n constructor(params: IArcGraphicAttribute) {\n super(params);\n this.numberType = ARC_NUMBER_TYPE;\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n const { startAngle, endAngle, outerRadius, innerRadius } = this.attribute;\n return (\n this._validNumber(startAngle) &&\n this._validNumber(endAngle) &&\n this._validNumber(outerRadius) &&\n this._validNumber(innerRadius)\n );\n }\n\n getParsedCornerRadius() {\n const arcTheme = getTheme(this).arc;\n const {\n cornerRadius = arcTheme.cornerRadius,\n outerRadius = arcTheme.outerRadius,\n innerRadius = arcTheme.innerRadius\n } = this.attribute;\n if (cornerRadius === 0 || cornerRadius === '0%') {\n return 0;\n }\n const deltaRadius = Math.abs(outerRadius - innerRadius);\n return Math.min(\n isNumber(cornerRadius, true)\n ? (cornerRadius as number)\n : (deltaRadius * parseFloat(cornerRadius as string)) / 100,\n deltaRadius / 2\n );\n }\n\n getParsedAngle() {\n const arcTheme = getTheme(this).arc;\n let { startAngle = arcTheme.startAngle, endAngle = arcTheme.endAngle } = this.attribute;\n const { cap = arcTheme.cap } = this.attribute;\n\n const sign = endAngle - startAngle >= 0 ? 1 : -1;\n const deltaAngle = endAngle - startAngle;\n\n startAngle = clampAngleByRadian(startAngle);\n endAngle = startAngle + deltaAngle;\n\n if (cap && abs(deltaAngle) < pi2 - epsilon) {\n let startCap = 1;\n let endCap = 1;\n if ((cap as boolean[]).length) {\n startCap = Number(cap[0]);\n endCap = Number(cap[1]);\n }\n const { outerRadius = arcTheme.outerRadius, innerRadius = arcTheme.innerRadius } = this.attribute;\n const capWidth = Math.abs(outerRadius - innerRadius) / 2;\n // 以外边界长度为准\n const capAngle = capWidth / outerRadius;\n\n if (capWidth > epsilon && outerRadius > epsilon) {\n return {\n startAngle: startAngle - sign * capAngle * startCap,\n endAngle: endAngle + sign * capAngle * endCap,\n sc: sign * capAngle * startCap,\n ec: sign * capAngle * endCap\n };\n }\n }\n\n return {\n startAngle: startAngle,\n endAngle: endAngle\n };\n }\n\n // 参考 https://github.com/d3/d3-shape/blob/main/src/arc.js\n getParsePadAngle(startAngle: number, endAngle: number) {\n const arcTheme = getTheme(this).arc;\n const {\n outerRadius = arcTheme.outerRadius,\n innerRadius = arcTheme.innerRadius,\n padAngle = arcTheme.padAngle\n } = this.attribute;\n\n const { padRadius = sqrt(outerRadius * outerRadius + innerRadius * innerRadius) } = this.attribute;\n const deltaAngle = abs(endAngle - startAngle);\n\n // Or is it a circular or annular sector?\n let outerStartAngle = startAngle;\n let outerEndAngle = endAngle;\n let innerStartAngle = startAngle;\n let innerEndAngle = endAngle;\n const halfPadAngle = padAngle / 2;\n let innerDeltaAngle = deltaAngle;\n let outerDeltaAngle = deltaAngle;\n\n // Apply padding? Note that since r1 ≥ r0, outerDeltaAngle ≥ innerDeltaAngle.\n if (halfPadAngle > epsilon && padRadius > epsilon) {\n const sign = endAngle > startAngle ? 1 : -1;\n\n let p0 = asin((Number(padRadius) / innerRadius) * sin(halfPadAngle));\n let p1 = asin((Number(padRadius) / outerRadius) * sin(halfPadAngle));\n if ((innerDeltaAngle -= p0 * 2) > epsilon) {\n p0 *= sign;\n innerStartAngle += p0;\n innerEndAngle -= p0;\n } else {\n innerDeltaAngle = 0;\n innerStartAngle = innerEndAngle = (startAngle + endAngle) / 2;\n }\n if ((outerDeltaAngle -= p1 * 2) > epsilon) {\n p1 *= sign;\n outerStartAngle += p1;\n outerEndAngle -= p1;\n } else {\n outerDeltaAngle = 0;\n outerStartAngle = outerEndAngle = (startAngle + endAngle) / 2;\n }\n\n return {\n outerStartAngle,\n outerEndAngle,\n innerStartAngle,\n innerEndAngle,\n innerDeltaAngle,\n outerDeltaAngle\n };\n }\n\n return {\n outerStartAngle,\n outerEndAngle,\n innerStartAngle,\n innerEndAngle,\n innerDeltaAngle,\n outerDeltaAngle\n };\n }\n\n protected doUpdateAABBBounds(full?: boolean): AABBBounds {\n const arcTheme = getTheme(this).arc;\n this._AABBBounds.clear();\n const attribute = this.attribute;\n const bounds = application.graphicService.updateArcAABBBounds(\n attribute,\n getTheme(this).arc,\n this._AABBBounds,\n full,\n this\n ) as AABBBounds;\n\n const { boundsPadding = arcTheme.boundsPadding } = attribute;\n const paddingArray = parsePadding(boundsPadding);\n if (paddingArray) {\n bounds.expand(paddingArray);\n }\n this.clearUpdateBoundTag();\n return bounds;\n }\n\n protected tryUpdateOBBBounds(): OBBBounds {\n throw new Error('暂不支持');\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, ARC_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, ARC_UPDATE_TAG_KEY);\n }\n\n getDefaultAttribute(name: string) {\n const arcTheme = getTheme(this).arc;\n return arcTheme[name];\n }\n\n toCustomPath() {\n const x = 0;\n const y = 0;\n\n const attribute = this.attribute;\n const { startAngle, endAngle } = this.getParsedAngle();\n let innerRadius = attribute.innerRadius;\n let outerRadius = attribute.outerRadius;\n const deltaAngle = abs(endAngle - startAngle);\n const clockwise: boolean = endAngle > startAngle;\n\n if (outerRadius < innerRadius) {\n const temp = outerRadius;\n outerRadius = innerRadius;\n innerRadius = temp;\n }\n\n const path = new CustomPath2D();\n\n if (outerRadius <= epsilon) {\n path.moveTo(x, y);\n } else if (deltaAngle >= pi2 - epsilon) {\n // 是个完整的圆环\n // Or is it a circle or annulus?\n path.moveTo(x + outerRadius * cos(startAngle), y + outerRadius * sin(startAngle));\n path.arc(x, y, outerRadius, startAngle, endAngle, !clockwise);\n if (innerRadius > epsilon) {\n path.moveTo(x + innerRadius * cos(endAngle), y + innerRadius * sin(endAngle));\n path.arc(x, y, innerRadius, endAngle, startAngle, clockwise);\n }\n } else {\n const xors = outerRadius * cos(startAngle);\n const yors = outerRadius * sin(startAngle);\n const xire = innerRadius * cos(endAngle);\n const yire = innerRadius * sin(endAngle);\n\n path.moveTo(x + xors, y + yors);\n path.arc(x, y, outerRadius, startAngle, endAngle, !clockwise);\n path.lineTo(x + xire, y + yire);\n path.arc(x, y, innerRadius, endAngle, startAngle, clockwise);\n path.closePath();\n }\n\n return path;\n }\n\n clone() {\n return new Arc({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Arc.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createArc(attributes: IArcGraphicAttribute): IArc {\n return new Arc(attributes);\n}\n\n// addAttributeToPrototype(DefaultCircleStyle, Circle, PURE_STYLE_KEY);\n"]}