@visactor/vrender-core 0.22.0 → 0.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/cjs/canvas/contributions/base-canvas.d.ts +1 -0
  2. package/cjs/canvas/contributions/base-canvas.js +3 -0
  3. package/cjs/canvas/contributions/base-canvas.js.map +1 -1
  4. package/cjs/common/custom-path2d.js +8 -6
  5. package/cjs/common/custom-path2d.js.map +1 -1
  6. package/cjs/graphic/config.js +7 -3
  7. package/cjs/graphic/config.js.map +1 -1
  8. package/cjs/graphic/graphic.d.ts +8 -3
  9. package/cjs/graphic/graphic.js +52 -10
  10. package/cjs/graphic/graphic.js.map +1 -1
  11. package/cjs/graphic/group.d.ts +1 -0
  12. package/cjs/graphic/group.js +5 -0
  13. package/cjs/graphic/group.js.map +1 -1
  14. package/cjs/graphic/image.d.ts +3 -2
  15. package/cjs/graphic/image.js +23 -13
  16. package/cjs/graphic/image.js.map +1 -1
  17. package/cjs/graphic/richtext/line.js +11 -1
  18. package/cjs/graphic/richtext/line.js.map +1 -1
  19. package/cjs/graphic/richtext/paragraph.d.ts +8 -1
  20. package/cjs/graphic/richtext/paragraph.js +5 -16
  21. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  22. package/cjs/graphic/richtext.js +11 -7
  23. package/cjs/graphic/richtext.js.map +1 -1
  24. package/cjs/graphic/symbol.d.ts +1 -1
  25. package/cjs/graphic/symbol.js +20 -37
  26. package/cjs/graphic/symbol.js.map +1 -1
  27. package/cjs/graphic/text.d.ts +1 -0
  28. package/cjs/graphic/text.js +3 -0
  29. package/cjs/graphic/text.js.map +1 -1
  30. package/cjs/interface/graphic/arc.js.map +1 -1
  31. package/cjs/interface/graphic/area.js.map +1 -1
  32. package/cjs/interface/graphic/circle.js.map +1 -1
  33. package/cjs/interface/graphic/group.d.ts +1 -0
  34. package/cjs/interface/graphic/group.js.map +1 -1
  35. package/cjs/interface/graphic/image.d.ts +2 -0
  36. package/cjs/interface/graphic/image.js.map +1 -1
  37. package/cjs/interface/graphic/line.js.map +1 -1
  38. package/cjs/interface/graphic/polygon.js.map +1 -1
  39. package/cjs/interface/graphic/rect.js.map +1 -1
  40. package/cjs/interface/graphic/richText.d.ts +4 -0
  41. package/cjs/interface/graphic/richText.js.map +1 -1
  42. package/cjs/interface/graphic/symbol.d.ts +1 -0
  43. package/cjs/interface/graphic/symbol.js.map +1 -1
  44. package/cjs/interface/graphic/text.js.map +1 -1
  45. package/cjs/interface/graphic.d.ts +5 -0
  46. package/cjs/interface/graphic.js.map +1 -1
  47. package/cjs/plugins/builtin-plugin/auto-refresh-plugin.d.ts +1 -0
  48. package/cjs/plugins/builtin-plugin/auto-refresh-plugin.js +9 -3
  49. package/cjs/plugins/builtin-plugin/auto-refresh-plugin.js.map +1 -1
  50. package/cjs/plugins/builtin-plugin/edit-module.js +3 -2
  51. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  52. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +6 -3
  53. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +49 -31
  54. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  55. package/cjs/render/contributions/render/base-render.js +5 -2
  56. package/cjs/render/contributions/render/base-render.js.map +1 -1
  57. package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +14 -0
  58. package/cjs/render/contributions/render/contributions/base-contribution-render.js +36 -1
  59. package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  60. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.d.ts +2 -1
  61. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js +20 -3
  62. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  63. package/cjs/render/contributions/render/group-render.js +26 -4
  64. package/cjs/render/contributions/render/group-render.js.map +1 -1
  65. package/cjs/render/contributions/render/image-render.js +5 -3
  66. package/cjs/render/contributions/render/image-render.js.map +1 -1
  67. package/dist/index.es.js +4946 -4648
  68. package/es/canvas/contributions/base-canvas.d.ts +1 -0
  69. package/es/canvas/contributions/base-canvas.js +3 -0
  70. package/es/canvas/contributions/base-canvas.js.map +1 -1
  71. package/es/common/custom-path2d.js +8 -6
  72. package/es/common/custom-path2d.js.map +1 -1
  73. package/es/graphic/config.js +7 -3
  74. package/es/graphic/config.js.map +1 -1
  75. package/es/graphic/graphic.d.ts +8 -3
  76. package/es/graphic/graphic.js +58 -12
  77. package/es/graphic/graphic.js.map +1 -1
  78. package/es/graphic/group.d.ts +1 -0
  79. package/es/graphic/group.js +5 -0
  80. package/es/graphic/group.js.map +1 -1
  81. package/es/graphic/image.d.ts +3 -2
  82. package/es/graphic/image.js +23 -13
  83. package/es/graphic/image.js.map +1 -1
  84. package/es/graphic/richtext/line.js +11 -1
  85. package/es/graphic/richtext/line.js.map +1 -1
  86. package/es/graphic/richtext/paragraph.d.ts +8 -1
  87. package/es/graphic/richtext/paragraph.js +5 -16
  88. package/es/graphic/richtext/paragraph.js.map +1 -1
  89. package/es/graphic/richtext.js +11 -7
  90. package/es/graphic/richtext.js.map +1 -1
  91. package/es/graphic/symbol.d.ts +1 -1
  92. package/es/graphic/symbol.js +19 -42
  93. package/es/graphic/symbol.js.map +1 -1
  94. package/es/graphic/text.d.ts +1 -0
  95. package/es/graphic/text.js +3 -0
  96. package/es/graphic/text.js.map +1 -1
  97. package/es/interface/graphic/arc.js.map +1 -1
  98. package/es/interface/graphic/area.js.map +1 -1
  99. package/es/interface/graphic/circle.js.map +1 -1
  100. package/es/interface/graphic/group.d.ts +1 -0
  101. package/es/interface/graphic/group.js.map +1 -1
  102. package/es/interface/graphic/image.d.ts +2 -0
  103. package/es/interface/graphic/image.js.map +1 -1
  104. package/es/interface/graphic/line.js.map +1 -1
  105. package/es/interface/graphic/polygon.js.map +1 -1
  106. package/es/interface/graphic/rect.js.map +1 -1
  107. package/es/interface/graphic/richText.d.ts +4 -0
  108. package/es/interface/graphic/richText.js.map +1 -1
  109. package/es/interface/graphic/symbol.d.ts +1 -0
  110. package/es/interface/graphic/symbol.js.map +1 -1
  111. package/es/interface/graphic/text.js.map +1 -1
  112. package/es/interface/graphic.d.ts +5 -0
  113. package/es/interface/graphic.js.map +1 -1
  114. package/es/plugins/builtin-plugin/auto-refresh-plugin.d.ts +1 -0
  115. package/es/plugins/builtin-plugin/auto-refresh-plugin.js +9 -3
  116. package/es/plugins/builtin-plugin/auto-refresh-plugin.js.map +1 -1
  117. package/es/plugins/builtin-plugin/edit-module.js +3 -2
  118. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  119. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +6 -3
  120. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +49 -31
  121. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  122. package/es/render/contributions/render/base-render.js +5 -1
  123. package/es/render/contributions/render/base-render.js.map +1 -1
  124. package/es/render/contributions/render/contributions/base-contribution-render.d.ts +14 -0
  125. package/es/render/contributions/render/contributions/base-contribution-render.js +31 -0
  126. package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  127. package/es/render/contributions/render/contributions/base-texture-contribution-render.d.ts +2 -1
  128. package/es/render/contributions/render/contributions/base-texture-contribution-render.js +22 -2
  129. package/es/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  130. package/es/render/contributions/render/group-render.js +27 -3
  131. package/es/render/contributions/render/group-render.js.map +1 -1
  132. package/es/render/contributions/render/image-render.js +4 -3
  133. package/es/render/contributions/render/image-render.js.map +1 -1
  134. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/group.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAY7C,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACzD,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,UAAkC;IAC5D,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC","file":"group.js","sourcesContent":["import type { IAABBBounds, Matrix } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { Point } from '@visactor/vutils';\nimport { application } from '../application';\nimport type {\n IStage,\n GraphicAttributeMap,\n INode,\n IGraphic,\n ITheme,\n IThemeSpec,\n ILayer,\n GraphicType\n} from '../interface';\nimport type { IGroup, IGroupGraphicAttribute } from '../interface/graphic/group';\nimport { Graphic, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme, Theme } from './theme';\nimport { UpdateTag, IContainPointMode } from '../common/enums';\nimport { GROUP_NUMBER_TYPE } from './constants';\nimport { DefaultTransform } from './config';\n\n// Group更新AABBBounds的策略\nexport enum GroupUpdateAABBBoundsMode {\n // Group较少的情况,不会批量设置所有父层的tag,而是每次都查找\n LESS_GROUP = 0,\n // Group较多的情况,每次都会设置tag到最顶层\n MORE_GROUP = 1\n}\n\nexport class Group extends Graphic<IGroupGraphicAttribute> implements IGroup {\n type: GraphicType = 'group';\n parent: any = null;\n isContainer: boolean = true;\n // 子元素的更新标记\n declare _childUpdateTag: number;\n\n declare theme?: ITheme;\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IGroupGraphicAttribute) {\n super(params);\n this.numberType = GROUP_NUMBER_TYPE;\n this._childUpdateTag = UpdateTag.UPDATE_BOUNDS;\n // this.theme = new Theme();\n }\n\n setMode(mode: '2d' | '3d') {\n mode === '3d' ? this.set3dMode() : this.set2dMode();\n }\n\n set3dMode() {\n this.in3dMode = true;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('3d');\n // });\n }\n set2dMode() {\n this.in3dMode = false;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('2d');\n // });\n }\n\n setTheme(t: IThemeSpec) {\n if (!this.theme) {\n this.theme = new Theme();\n }\n return this.theme.setTheme(t, this);\n }\n\n createTheme() {\n if (!this.theme) {\n this.theme = new Theme();\n }\n }\n\n visibleAll(visible: boolean) {\n this.setAttribute('visible', visible);\n this.forEachChildren((item: IGraphic) => {\n if (item.isContainer && (item as any).visibleAll) {\n (item as any).visibleAll(visible);\n } else {\n item.setAttribute('visible', visible);\n }\n });\n }\n\n hideAll() {\n this.visibleAll(false);\n }\n\n showAll() {\n this.visibleAll(true);\n }\n\n /**\n * 是否包含某个点(点需要是全局坐标系)\n * group containsPoint 只需要判断bounds\n * TODO: group的shape判断\n * @param x\n * @param y\n * @param mode\n * @returns\n */\n containsPoint(x: number, y: number, mode: IContainPointMode): boolean {\n if (mode === IContainPointMode.GLOBAL) {\n // 转换x,y更精准\n const point = new Point(x, y);\n if (this.parent) {\n this.parent.globalTransMatrix.transformPoint(point, point);\n }\n return this.AABBBounds.contains(point.x, point.y);\n }\n return this.AABBBounds.contains(x, y);\n }\n\n shouldUpdateAABBBounds(): boolean {\n // 检索自己是否需要更新\n if (super.shouldUpdateAABBBounds()) {\n return true;\n }\n // 检索叶子节点是否有更新(如果children是叶子节点的话)\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return true;\n }\n return false;\n // // 检索是否子group需要更新\n // let needUpdate = false;\n // this.forEachChildren((node: IGraphic) => {\n // // 只查找group层级\n // if (node.isContainer && (node as Group).shouldUpdateAABBBounds()) {\n // needUpdate = true;\n // return true;\n // }\n // return false;\n // });\n // return needUpdate;\n }\n\n protected tryUpdateAABBBounds(): IAABBBounds {\n if (!this.shouldUpdateAABBBounds()) {\n return this._AABBBounds;\n }\n application.graphicService.beforeUpdateAABBBounds(this, this.stage, true, this._AABBBounds);\n const selfChange = this.shouldSelfChangeUpdateAABBBounds();\n const bounds = this.doUpdateAABBBounds();\n this.addUpdateLayoutTag();\n application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange);\n // 直接返回空Bounds,但是前面的流程还是要走\n if (this.attribute.boundsMode === 'empty') {\n bounds.clear();\n }\n return bounds;\n }\n\n /**\n * 大部分group不需要更新matrix,这里特殊优化一下\n * 更新局部matrix的具体函数\n */\n protected doUpdateLocalMatrix() {\n const {\n x = DefaultTransform.x,\n y = DefaultTransform.y,\n dx = DefaultTransform.dx,\n dy = DefaultTransform.dy,\n scaleX = DefaultTransform.scaleX,\n scaleY = DefaultTransform.scaleY,\n angle = DefaultTransform.angle,\n postMatrix\n } = this.attribute;\n if (x === 0 && y === 0 && dx === 0 && dy === 0 && scaleX === 1 && scaleY === 1 && angle === 0 && !postMatrix) {\n this._transMatrix.reset();\n return;\n }\n return super.doUpdateLocalMatrix();\n }\n\n getGraphicTheme(): Required<IGroupGraphicAttribute> {\n return getTheme(this).group;\n }\n\n protected updateAABBBounds(\n attribute: IGroupGraphicAttribute,\n groupTheme: Required<IGroupGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n const originalAABBBounds = aabbBounds; // fix aabbbounds update error in flex layout\n aabbBounds = aabbBounds.clone();\n\n const { width, height, path, clip = groupTheme.clip } = attribute;\n // 添加自身的fill或者clip\n if (path && path.length) {\n path.forEach(g => {\n aabbBounds.union(g.AABBBounds);\n });\n } else if (width != null && height != null) {\n aabbBounds.set(0, 0, Math.max(0, width), Math.max(0, height)); // fix bounds set when auto size in vtable\n }\n if (!clip) {\n // 添加子节点\n this.forEachChildren((node: IGraphic) => {\n aabbBounds.union(node.AABBBounds);\n });\n // 如果没有clip的话,还需要加一下scroll\n const { scrollX = 0, scrollY = 0 } = attribute;\n aabbBounds.translate(scrollX, scrollY);\n }\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, groupTheme, false, this);\n\n originalAABBBounds.copy(aabbBounds);\n return originalAABBBounds;\n }\n\n protected doUpdateAABBBounds(): IAABBBounds {\n this.updateAABBBoundsStamp++;\n const bounds = super.doUpdateAABBBounds();\n\n // 更新bounds之后需要设置父节点,否则tag丢失\n this.parent && this.parent.addChildUpdateBoundTag();\n this._emitCustomEvent('AAABBBoundsChange');\n\n return bounds;\n }\n\n protected clearUpdateBoundTag() {\n this._updateTag &= UpdateTag.CLEAR_BOUNDS;\n this._childUpdateTag &= UpdateTag.CLEAR_BOUNDS;\n }\n\n addUpdateBoundTag() {\n this._updateTag |= UpdateTag.UPDATE_BOUNDS; // for bounds\n if (this.parent) {\n this.parent.addChildUpdateBoundTag();\n }\n }\n\n addChildUpdateBoundTag() {\n // 如果已经设置过updateTag,那就不需要设置了\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return;\n }\n // 如果没有设置过,那么继续向上设置\n this._childUpdateTag |= UpdateTag.UPDATE_BOUNDS;\n this.parent && this.parent.addChildUpdateBoundTag();\n }\n\n getTheme() {\n return this.theme.getTheme(this);\n }\n\n /* 场景树结构 */\n incrementalAppendChild(node: INode): INode | null {\n const data = super.appendChild(node);\n if (this.stage && data) {\n (data as unknown as this).stage = this.stage;\n (data as unknown as this).layer = this.layer;\n }\n this.addUpdateBoundTag();\n application.graphicService.onAddIncremental(node as unknown as IGraphic, this, this.stage);\n return data;\n }\n incrementalClearChild(): void {\n super.removeAllChild();\n this.addUpdateBoundTag();\n application.graphicService.onClearIncremental(this, this.stage);\n return;\n }\n\n protected _updateChildToStage(child: IGraphic) {\n if (this.stage && child) {\n child.setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return child;\n }\n // TODO 代码优化\n appendChild(node: INode, addStage: boolean = true): INode | null {\n const data = super.appendChild(node);\n if (addStage && this.stage && data) {\n (data as unknown as this).setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return data;\n }\n insertBefore(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertBefore(newNode, referenceNode) as undefined as IGraphic);\n }\n insertAfter(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertAfter(newNode, referenceNode) as undefined as IGraphic);\n }\n insertInto(newNode: INode, idx: number): INode | null {\n return this._updateChildToStage(super.insertInto(newNode, idx) as undefined as IGraphic);\n }\n\n removeChild(child: IGraphic): IGraphic {\n const data = super.removeChild(child);\n child.stage = null;\n application.graphicService.onRemove(child);\n this.addUpdateBoundTag();\n return data as IGraphic;\n }\n\n removeAllChild(deep: boolean = false): void {\n this.forEachChildren((child: IGraphic) => {\n application.graphicService.onRemove(child);\n if (deep && child.isContainer) {\n child.removeAllChild(deep);\n }\n });\n super.removeAllChild();\n this.addUpdateBoundTag();\n }\n\n setStage(stage?: IStage, layer?: ILayer) {\n if (this.stage !== stage) {\n this.stage = stage;\n this.layer = layer;\n this.setStageToShadowRoot(stage, layer);\n this._onSetStage && this._onSetStage(this, stage, layer);\n application.graphicService.onSetStage(this, stage);\n this.forEachChildren(item => {\n (item as any).setStage(stage, this.layer);\n });\n }\n }\n /**\n * 更新位置tag,包括全局tag和局部tag\n */\n addUpdatePositionTag() {\n super.addUpdatePositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * 更新全局位置tag\n */\n addUpdateGlobalPositionTag() {\n super.addUpdateGlobalPositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * group更新全局的transMatrix\n * @param clearTag\n * @returns\n */\n protected tryUpdateGlobalTransMatrix(clearTag: boolean = true): Matrix {\n if (this.shouldUpdateGlobalMatrix()) {\n if (!this._globalTransMatrix) {\n this._globalTransMatrix = this.parent\n ? (this.parent as IGroup).globalTransMatrix.clone()\n : this.transMatrix.clone();\n } else if (this.parent) {\n const m = (this.parent as IGroup).globalTransMatrix;\n this._globalTransMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n }\n this.doUpdateGlobalMatrix();\n clearTag && this.clearUpdateGlobalPositionTag();\n }\n return this._globalTransMatrix;\n }\n /**\n * 查找自身更新global的tag,如果存在,就更新\n * @returns\n */\n shouldUpdateGlobalMatrix(): boolean {\n const shouldUpdate = !!(this._updateTag & UpdateTag.UPDATE_GLOBAL_MATRIX);\n return shouldUpdate;\n }\n\n private _getChildByName<T extends INode = INode>(name: string, deep?: boolean): T | null {\n return this.find(node => node.name === name, deep);\n }\n\n /**\n * if graphic exist then update attributes, otherwise create a new instance\n * @param graphicName the name of graphic\n * @param attributes the attributes of graphic\n * @param graphicType the type of graphic\n * @returns the graphic instance\n */\n createOrUpdateChild<T extends keyof GraphicAttributeMap>(\n graphicName: string,\n attributes: GraphicAttributeMap[T],\n graphicType: T\n ): INode {\n let graphic = this._getChildByName(graphicName) as IGraphic;\n if (graphic) {\n graphic.setAttributes(attributes);\n } else {\n graphic = application.graphicService.creator[graphicType](attributes as any);\n graphic.name = graphicName;\n this.add(graphic);\n }\n\n return graphic;\n }\n\n clone() {\n return new Group({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Group.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createGroup(attributes: IGroupGraphicAttribute): IGroup {\n return new Group(attributes);\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/group.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAY7C,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C,MAAM,CAAN,IAAY,yBAKX;AALD,WAAY,yBAAyB;IAEnC,qFAAc,CAAA;IAEd,qFAAc,CAAA;AAChB,CAAC,EALW,yBAAyB,KAAzB,yBA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eslint-disable-next-line no-duplicate-imports\nimport { Point } from '@visactor/vutils';\nimport { application } from '../application';\nimport type {\n IStage,\n GraphicAttributeMap,\n INode,\n IGraphic,\n ITheme,\n IThemeSpec,\n ILayer,\n GraphicType\n} from '../interface';\nimport type { IGroup, IGroupGraphicAttribute } from '../interface/graphic/group';\nimport { Graphic, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme, Theme } from './theme';\nimport { UpdateTag, IContainPointMode } from '../common/enums';\nimport { GROUP_NUMBER_TYPE } from './constants';\nimport { DefaultTransform } from './config';\n\n// Group更新AABBBounds的策略\nexport enum GroupUpdateAABBBoundsMode {\n // Group较少的情况,不会批量设置所有父层的tag,而是每次都查找\n LESS_GROUP = 0,\n // Group较多的情况,每次都会设置tag到最顶层\n MORE_GROUP = 1\n}\n\nexport class Group extends Graphic<IGroupGraphicAttribute> implements IGroup {\n type: GraphicType = 'group';\n parent: any = null;\n isContainer: boolean = true;\n // 子元素的更新标记\n declare _childUpdateTag: number;\n\n declare theme?: ITheme;\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IGroupGraphicAttribute) {\n super(params);\n this.numberType = GROUP_NUMBER_TYPE;\n this._childUpdateTag = UpdateTag.UPDATE_BOUNDS;\n // this.theme = new Theme();\n }\n\n setMode(mode: '2d' | '3d') {\n mode === '3d' ? this.set3dMode() : this.set2dMode();\n }\n\n set3dMode() {\n this.in3dMode = true;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('3d');\n // });\n }\n set2dMode() {\n this.in3dMode = false;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('2d');\n // });\n }\n\n setTheme(t: IThemeSpec) {\n if (!this.theme) {\n this.theme = new Theme();\n }\n return this.theme.setTheme(t, this);\n }\n\n createTheme() {\n if (!this.theme) {\n this.theme = new Theme();\n }\n }\n\n visibleAll(visible: boolean) {\n this.setAttribute('visible', visible);\n this.forEachChildren((item: IGraphic) => {\n if (item.isContainer && (item as any).visibleAll) {\n (item as any).visibleAll(visible);\n } else {\n item.setAttribute('visible', visible);\n }\n });\n }\n\n hideAll() {\n this.visibleAll(false);\n }\n\n showAll() {\n this.visibleAll(true);\n }\n\n /**\n * 是否包含某个点(点需要是全局坐标系)\n * group containsPoint 只需要判断bounds\n * TODO: group的shape判断\n * @param x\n * @param y\n * @param mode\n * @returns\n */\n containsPoint(x: number, y: number, mode: IContainPointMode): boolean {\n if (mode === IContainPointMode.GLOBAL) {\n // 转换x,y更精准\n const point = new Point(x, y);\n if (this.parent) {\n this.parent.globalTransMatrix.transformPoint(point, point);\n }\n return this.AABBBounds.contains(point.x, point.y);\n }\n return this.AABBBounds.contains(x, y);\n }\n\n shouldUpdateAABBBounds(): boolean {\n // 检索自己是否需要更新\n if (super.shouldUpdateAABBBounds()) {\n return true;\n }\n // 检索叶子节点是否有更新(如果children是叶子节点的话)\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return true;\n }\n return false;\n // // 检索是否子group需要更新\n // let needUpdate = false;\n // this.forEachChildren((node: IGraphic) => {\n // // 只查找group层级\n // if (node.isContainer && (node as Group).shouldUpdateAABBBounds()) {\n // needUpdate = true;\n // return true;\n // }\n // return false;\n // });\n // return needUpdate;\n }\n\n protected tryUpdateAABBBounds(): IAABBBounds {\n if (!this.shouldUpdateAABBBounds()) {\n return this._AABBBounds;\n }\n application.graphicService.beforeUpdateAABBBounds(this, this.stage, true, this._AABBBounds);\n const selfChange = this.shouldSelfChangeUpdateAABBBounds();\n const bounds = this.doUpdateAABBBounds();\n this.addUpdateLayoutTag();\n application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange);\n // 直接返回空Bounds,但是前面的流程还是要走\n if (this.attribute.boundsMode === 'empty') {\n bounds.clear();\n }\n return bounds;\n }\n\n /**\n * 大部分group不需要更新matrix,这里特殊优化一下\n * 更新局部matrix的具体函数\n */\n protected doUpdateLocalMatrix() {\n const {\n x = DefaultTransform.x,\n y = DefaultTransform.y,\n dx = DefaultTransform.dx,\n dy = DefaultTransform.dy,\n scaleX = DefaultTransform.scaleX,\n scaleY = DefaultTransform.scaleY,\n angle = DefaultTransform.angle,\n postMatrix\n } = this.attribute;\n if (x === 0 && y === 0 && dx === 0 && dy === 0 && scaleX === 1 && scaleY === 1 && angle === 0 && !postMatrix) {\n this._transMatrix.reset();\n return;\n }\n return super.doUpdateLocalMatrix();\n }\n\n getGraphicTheme(): Required<IGroupGraphicAttribute> {\n return getTheme(this).group;\n }\n\n protected updateAABBBounds(\n attribute: IGroupGraphicAttribute,\n groupTheme: Required<IGroupGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n const originalAABBBounds = aabbBounds; // fix aabbbounds update error in flex layout\n aabbBounds = aabbBounds.clone();\n\n const { width, height, path, clip = groupTheme.clip } = attribute;\n // 添加自身的fill或者clip\n if (path && path.length) {\n path.forEach(g => {\n aabbBounds.union(g.AABBBounds);\n });\n } else if (width != null && height != null) {\n aabbBounds.set(0, 0, Math.max(0, width), Math.max(0, height)); // fix bounds set when auto size in vtable\n }\n if (!clip) {\n // 添加子节点\n this.forEachChildren((node: IGraphic) => {\n aabbBounds.union(node.AABBBounds);\n });\n // 如果没有clip的话,还需要加一下scroll\n const { scrollX = 0, scrollY = 0 } = attribute;\n aabbBounds.translate(scrollX, scrollY);\n }\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, groupTheme, false, this);\n\n originalAABBBounds.copy(aabbBounds);\n return originalAABBBounds;\n }\n\n protected doUpdateAABBBounds(): IAABBBounds {\n this.updateAABBBoundsStamp++;\n const bounds = super.doUpdateAABBBounds();\n\n // 更新bounds之后需要设置父节点,否则tag丢失\n this.parent && this.parent.addChildUpdateBoundTag();\n this._emitCustomEvent('AAABBBoundsChange');\n\n return bounds;\n }\n\n protected clearUpdateBoundTag() {\n this._updateTag &= UpdateTag.CLEAR_BOUNDS;\n this._childUpdateTag &= UpdateTag.CLEAR_BOUNDS;\n }\n\n addUpdateBoundTag() {\n this._updateTag |= UpdateTag.UPDATE_BOUNDS; // for bounds\n if (this.parent) {\n this.parent.addChildUpdateBoundTag();\n }\n }\n\n addChildUpdateBoundTag() {\n // 如果已经设置过updateTag,那就不需要设置了\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return;\n }\n // 如果没有设置过,那么继续向上设置\n this._childUpdateTag |= UpdateTag.UPDATE_BOUNDS;\n this.parent && this.parent.addChildUpdateBoundTag();\n }\n\n getTheme() {\n return this.theme.getTheme(this);\n }\n\n /* 场景树结构 */\n incrementalAppendChild(node: INode): INode | null {\n const data = super.appendChild(node);\n if (this.stage && data) {\n (data as unknown as this).stage = this.stage;\n (data as unknown as this).layer = this.layer;\n }\n this.addUpdateBoundTag();\n application.graphicService.onAddIncremental(node as unknown as IGraphic, this, this.stage);\n return data;\n }\n incrementalClearChild(): void {\n super.removeAllChild();\n this.addUpdateBoundTag();\n application.graphicService.onClearIncremental(this, this.stage);\n return;\n }\n\n protected _updateChildToStage(child: IGraphic) {\n if (this.stage && child) {\n child.setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return child;\n }\n // TODO 代码优化\n appendChild(node: INode, addStage: boolean = true): INode | null {\n const data = super.appendChild(node);\n if (addStage && this.stage && data) {\n (data as unknown as this).setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return data;\n }\n insertBefore(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertBefore(newNode, referenceNode) as undefined as IGraphic);\n }\n insertAfter(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertAfter(newNode, referenceNode) as undefined as IGraphic);\n }\n insertInto(newNode: INode, idx: number): INode | null {\n return this._updateChildToStage(super.insertInto(newNode, idx) as undefined as IGraphic);\n }\n\n removeChild(child: IGraphic): IGraphic {\n const data = super.removeChild(child);\n child.stage = null;\n application.graphicService.onRemove(child);\n this.addUpdateBoundTag();\n return data as IGraphic;\n }\n\n removeAllChild(deep: boolean = false): void {\n this.forEachChildren((child: IGraphic) => {\n application.graphicService.onRemove(child);\n if (deep && child.isContainer) {\n child.removeAllChild(deep);\n }\n });\n super.removeAllChild();\n this.addUpdateBoundTag();\n }\n\n setStage(stage?: IStage, layer?: ILayer) {\n if (this.stage !== stage) {\n this.stage = stage;\n this.layer = layer;\n this.setStageToShadowRoot(stage, layer);\n this._onSetStage && this._onSetStage(this, stage, layer);\n application.graphicService.onSetStage(this, stage);\n this.forEachChildren(item => {\n (item as any).setStage(stage, this.layer);\n });\n }\n }\n /**\n * 更新位置tag,包括全局tag和局部tag\n */\n addUpdatePositionTag() {\n super.addUpdatePositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * 更新全局位置tag\n */\n addUpdateGlobalPositionTag() {\n super.addUpdateGlobalPositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * group更新全局的transMatrix\n * @param clearTag\n * @returns\n */\n protected tryUpdateGlobalTransMatrix(clearTag: boolean = true): Matrix {\n if (this.shouldUpdateGlobalMatrix()) {\n if (!this._globalTransMatrix) {\n this._globalTransMatrix = this.parent\n ? (this.parent as IGroup).globalTransMatrix.clone()\n : this.transMatrix.clone();\n } else if (this.parent) {\n const m = (this.parent as IGroup).globalTransMatrix;\n this._globalTransMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n }\n this.doUpdateGlobalMatrix();\n clearTag && this.clearUpdateGlobalPositionTag();\n }\n return this._globalTransMatrix;\n }\n /**\n * 查找自身更新global的tag,如果存在,就更新\n * @returns\n */\n shouldUpdateGlobalMatrix(): boolean {\n const shouldUpdate = !!(this._updateTag & UpdateTag.UPDATE_GLOBAL_MATRIX);\n return shouldUpdate;\n }\n\n private _getChildByName<T extends INode = INode>(name: string, deep?: boolean): T | null {\n return this.find(node => node.name === name, deep);\n }\n\n /**\n * if graphic exist then update attributes, otherwise create a new instance\n * @param graphicName the name of graphic\n * @param attributes the attributes of graphic\n * @param graphicType the type of graphic\n * @returns the graphic instance\n */\n createOrUpdateChild<T extends keyof GraphicAttributeMap>(\n graphicName: string,\n attributes: GraphicAttributeMap[T],\n graphicType: T\n ): INode {\n let graphic = this._getChildByName(graphicName) as IGraphic;\n if (graphic) {\n graphic.setAttributes(attributes);\n } else {\n graphic = application.graphicService.creator[graphicType](attributes as any);\n graphic.name = graphicName;\n this.add(graphic);\n }\n\n return graphic;\n }\n\n clone() {\n return new Group({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Group.NOWORK_ANIMATE_ATTR;\n }\n\n release(all?: boolean) {\n if (all) {\n this.forEachChildren((g: IGraphic) => {\n g.release(all);\n });\n }\n super.release();\n }\n}\n\nexport function createGroup(attributes: IGroupGraphicAttribute): IGroup {\n return new Group(attributes);\n}\n"]}
@@ -5,6 +5,8 @@ export declare class Image extends Graphic<IImageGraphicAttribute> implements II
5
5
  type: 'image';
6
6
  successCallback?: () => void;
7
7
  failCallback?: () => void;
8
+ _actualWidth?: number;
9
+ _actualHeight?: number;
8
10
  static NOWORK_ANIMATE_ATTR: {
9
11
  strokeSeg: number;
10
12
  boundsPadding: number;
@@ -39,10 +41,9 @@ export declare class Image extends Graphic<IImageGraphicAttribute> implements II
39
41
  repeatY: number;
40
42
  };
41
43
  constructor(params: IImageGraphicAttribute);
44
+ getImageElement(): HTMLImageElement | HTMLCanvasElement | null;
42
45
  get width(): number;
43
- set width(width: number);
44
46
  get height(): number;
45
- set height(height: number);
46
47
  get repeatX(): IRepeatType;
47
48
  set repeatX(repeatX: IRepeatType);
48
49
  get repeatY(): IRepeatType;
@@ -16,19 +16,17 @@ export class Image extends Graphic {
16
16
  constructor(params) {
17
17
  super(params), this.type = "image", this.numberType = IMAGE_NUMBER_TYPE, this.loadImage(this.attribute.image);
18
18
  }
19
- get width() {
20
- var _a;
21
- return null !== (_a = this.attribute.width) && void 0 !== _a ? _a : 0;
19
+ getImageElement() {
20
+ const {image: image} = this.attribute;
21
+ if (!image || !this.resources) return null;
22
+ const res = this.resources.get(image);
23
+ return "success" !== res.state ? null : res.data;
22
24
  }
23
- set width(width) {
24
- this.attribute.width === width && (this.attribute.width = width, this.addUpdateShapeAndBoundsTag());
25
+ get width() {
26
+ return this.tryUpdateAABBBounds(), this._actualWidth;
25
27
  }
26
28
  get height() {
27
- var _a;
28
- return null !== (_a = this.attribute.height) && void 0 !== _a ? _a : 0;
29
- }
30
- set height(height) {
31
- this.attribute.height === height && (this.attribute.height = height, this.addUpdateShapeAndBoundsTag());
29
+ return this.tryUpdateAABBBounds(), this._actualHeight;
32
30
  }
33
31
  get repeatX() {
34
32
  var _a;
@@ -53,7 +51,7 @@ export class Image extends Graphic {
53
51
  imageLoadSuccess(url, image, cb) {
54
52
  super.imageLoadSuccess(url, image, (() => {
55
53
  this.successCallback && this.successCallback();
56
- }));
54
+ })), this.addUpdateBoundTag();
57
55
  }
58
56
  imageLoadFail(url, cb) {
59
57
  super.imageLoadFail(url, (() => {
@@ -71,8 +69,20 @@ export class Image extends Graphic {
71
69
  }
72
70
  updateAABBBounds(attribute, imageTheme, aabbBounds) {
73
71
  if (!this.updatePathProxyAABBBounds(aabbBounds)) {
74
- const {width: width = imageTheme.width, height: height = imageTheme.height} = attribute;
75
- aabbBounds.set(0, 0, width, height);
72
+ const {maxWidth: maxWidth = imageTheme.maxWidth, maxHeight: maxHeight = imageTheme.maxHeight} = attribute;
73
+ let {width: width, height: height} = attribute;
74
+ if (null == width || null == height) {
75
+ const imageElement = this.getImageElement();
76
+ if (imageElement) {
77
+ const imageWidth = imageElement.width, imageHeight = imageElement.height;
78
+ if (null != width) height = width * (imageHeight / imageWidth); else if (null != height) width = height * (imageWidth / imageHeight); else {
79
+ const imageRatio = imageWidth / imageHeight;
80
+ imageRatio > maxWidth / maxHeight ? (width = maxWidth, height = maxWidth / imageRatio) : (height = maxHeight,
81
+ width = maxHeight * imageRatio);
82
+ }
83
+ } else width = maxWidth, height = maxHeight;
84
+ }
85
+ this._actualWidth = width, this._actualHeight = height, aabbBounds.set(0, 0, width, height);
76
86
  }
77
87
  const {tb1: tb1, tb2: tb2} = application.graphicService.updateTempAABBBounds(aabbBounds);
78
88
  return updateBoundsOfCommonOuterBorder(attribute, imageTheme, tb1), aabbBounds.union(tb1),
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/image.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAE9F,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,sBAAsB,CAAC,CAAC;AAMrF,MAAM,OAAO,KAAM,SAAQ,OAA+B;IAaxD,YAAY,MAA8B;QACxC,KAAK,CAAC,MAAM,CAAC,CAAC;QAbhB,SAAI,GAAY,OAAO,CAAC;QActB,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC;QAEpC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,KAAK;;QACP,OAAO,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,mCAAI,CAAC,CAAC;IACnC,CAAC;IACD,IAAI,KAAK,CAAC,KAAa;QACrB,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,KAAK,KAAK,EAAE;YAClC,IAAI,CAAC,SAAS,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","file":"image.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport type { IImage, IImageGraphicAttribute, IRepeatType, ISetAttributeContext } from '../interface';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { DefaultImageAttribute } from './config';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { IMAGE_NUMBER_TYPE } from './constants';\nimport { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds';\n\nconst IMAGE_UPDATE_TAG_KEY = ['width', 'height', 'image', ...GRAPHIC_UPDATE_TAG_KEY];\n\n/**\n * TODO image 需要考虑加载问题 等load模块\n * 同时需要在Graphic增加 图片填充 or 图片按形状clip功能\n */\nexport class Image extends Graphic<IImageGraphicAttribute> implements IImage {\n type: 'image' = 'image';\n // 资源加载完成后回调,外部通过回调获取图片资源尺寸\n successCallback?: () => void;\n failCallback?: () => void;\n\n static NOWORK_ANIMATE_ATTR = {\n image: 1,\n repeatX: 1,\n repeatY: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n constructor(params: IImageGraphicAttribute) {\n super(params);\n this.numberType = IMAGE_NUMBER_TYPE;\n\n this.loadImage(this.attribute.image);\n }\n\n get width(): number {\n return this.attribute.width ?? 0;\n }\n set width(width: number) {\n if (this.attribute.width === width) {\n this.attribute.width = width;\n this.addUpdateShapeAndBoundsTag();\n }\n }\n\n get height(): number {\n return this.attribute.height ?? 0;\n }\n set height(height: number) {\n if (this.attribute.height === height) {\n this.attribute.height = height;\n this.addUpdateShapeAndBoundsTag();\n }\n }\n get repeatX(): IRepeatType {\n return this.attribute.repeatX ?? 'no-repeat';\n }\n set repeatX(repeatX: IRepeatType) {\n if (this.attribute.repeatX === repeatX) {\n this.attribute.repeatX = repeatX;\n }\n }\n get repeatY(): IRepeatType {\n return this.attribute.repeatY ?? 'no-repeat';\n }\n set repeatY(repeatY: IRepeatType) {\n if (this.attribute.repeatY === repeatY) {\n this.attribute.repeatY = repeatY;\n }\n }\n get image(): string | HTMLImageElement | HTMLCanvasElement {\n return this.attribute.image;\n }\n set image(image: string | HTMLImageElement | HTMLCanvasElement) {\n if (image !== this.attribute.image) {\n this.attribute.image = image;\n this.loadImage(this.attribute.image);\n // this.addUpdateShapeAndBoundsTag();\n }\n }\n\n imageLoadSuccess(url: string, image: HTMLImageElement, cb?: () => void): void {\n super.imageLoadSuccess(url, image, () => {\n if (this.successCallback) {\n this.successCallback();\n }\n });\n }\n\n imageLoadFail(url: string, cb?: () => void): void {\n super.imageLoadFail(url, () => {\n if (this.failCallback) {\n this.failCallback();\n }\n });\n }\n\n setAttributes(\n params: Partial<IImageGraphicAttribute>,\n forceUpdateTag?: boolean,\n context?: ISetAttributeContext\n ): void {\n if (params.image) {\n this.loadImage(params.image);\n }\n return super.setAttributes(params, forceUpdateTag, context);\n }\n\n setAttribute(key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext): void {\n if (key === 'image') {\n this.loadImage(value);\n }\n return super.setAttribute(key, value, forceUpdateTag, context);\n }\n\n getGraphicTheme(): Required<IImageGraphicAttribute> {\n return getTheme(this).image;\n }\n\n protected updateAABBBounds(\n attribute: IImageGraphicAttribute,\n imageTheme: Required<IImageGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n const { width = imageTheme.width, height = imageTheme.height } = attribute;\n aabbBounds.set(0, 0, width, height);\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfCommonOuterBorder(attribute, imageTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, imageTheme, false, this);\n return aabbBounds;\n }\n\n getDefaultAttribute(name: string) {\n return (DefaultImageAttribute as any)[name];\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, IMAGE_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, IMAGE_UPDATE_TAG_KEY);\n }\n\n clone() {\n return new Image({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Image.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createImage(attributes: IImageGraphicAttribute): IImage {\n return new Image(attributes);\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/image.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAE9F,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,sBAAsB,CAAC,CAAC;AAMrF,MAAM,OAAO,KAAM,SAAQ,OAA+B;IAexD,YAAY,MAA8B;QACxC,KAAK,CAAC,MAAM,CAAC,CAAC;QAfhB,SAAI,GAAY,OAAO,CAAC;QAgBtB,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC;QAEpC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,eAAe;QACb,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YAC7B,OAAO,IAAI,CAAC;SACb;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,GAA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EAAE,GAAG,CAAC,CAAC;QAC5D,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACtB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAE7C,WAAW,CAAC,cAAc,CAAC,mBAAmB,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAC/F,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,mBAAmB,CAAC,IAAY;QAC9B,OAAQ,qBAA6B,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAES,cAAc,CAAC,IAAc;QACrC,OAAO,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;IAC1D,CAAC;IACS,aAAa,CAAC,GAAW;QACjC,OAAO,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;IACxD,CAAC;IAED,KAAK;QACH,OAAO,IAAI,KAAK,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IAC1C,CAAC;IAED,oBAAoB;QAClB,OAAO,KAAK,CAAC,mBAAmB,CAAC;IACnC,CAAC;;AApLM,yBAAmB,mBACxB,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,CAAC,IACP,mBAAmB,EACtB;AAkLJ,MAAM,UAAU,WAAW,CAAC,UAAkC;IAC5D,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC","file":"image.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport type { IImage, IImageGraphicAttribute, IRepeatType, ISetAttributeContext } from '../interface';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { DefaultImageAttribute } from './config';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { IMAGE_NUMBER_TYPE } from './constants';\nimport { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds';\n\nconst IMAGE_UPDATE_TAG_KEY = ['width', 'height', 'image', ...GRAPHIC_UPDATE_TAG_KEY];\n\n/**\n * TODO image 需要考虑加载问题 等load模块\n * 同时需要在Graphic增加 图片填充 or 图片按形状clip功能\n */\nexport class Image extends Graphic<IImageGraphicAttribute> implements IImage {\n type: 'image' = 'image';\n // 资源加载完成后回调,外部通过回调获取图片资源尺寸\n successCallback?: () => void;\n failCallback?: () => void;\n declare _actualWidth?: number;\n declare _actualHeight?: number;\n\n static NOWORK_ANIMATE_ATTR = {\n image: 1,\n repeatX: 1,\n repeatY: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n constructor(params: IImageGraphicAttribute) {\n super(params);\n this.numberType = IMAGE_NUMBER_TYPE;\n\n this.loadImage(this.attribute.image);\n }\n\n getImageElement(): HTMLImageElement | HTMLCanvasElement | null {\n const { image } = this.attribute;\n if (!image || !this.resources) {\n return null;\n }\n const res = this.resources.get(image);\n if (res.state !== 'success') {\n return null;\n }\n return res.data;\n }\n\n get width(): number {\n this.tryUpdateAABBBounds();\n return this._actualWidth;\n }\n // set width(width: number) {\n // if (this.attribute.width === width) {\n // this.attribute.width = width;\n // this.addUpdateShapeAndBoundsTag();\n // }\n // }\n\n get height(): number {\n this.tryUpdateAABBBounds();\n return this._actualHeight;\n }\n // set height(height: number) {\n // if (this.attribute.height === height) {\n // this.attribute.height = height;\n // this.addUpdateShapeAndBoundsTag();\n // }\n // }\n get repeatX(): IRepeatType {\n return this.attribute.repeatX ?? 'no-repeat';\n }\n set repeatX(repeatX: IRepeatType) {\n if (this.attribute.repeatX === repeatX) {\n this.attribute.repeatX = repeatX;\n }\n }\n get repeatY(): IRepeatType {\n return this.attribute.repeatY ?? 'no-repeat';\n }\n set repeatY(repeatY: IRepeatType) {\n if (this.attribute.repeatY === repeatY) {\n this.attribute.repeatY = repeatY;\n }\n }\n get image(): string | HTMLImageElement | HTMLCanvasElement {\n return this.attribute.image;\n }\n set image(image: string | HTMLImageElement | HTMLCanvasElement) {\n if (image !== this.attribute.image) {\n this.attribute.image = image;\n this.loadImage(this.attribute.image);\n // this.addUpdateShapeAndBoundsTag();\n }\n }\n\n imageLoadSuccess(url: string, image: HTMLImageElement, cb?: () => void): void {\n super.imageLoadSuccess(url, image, () => {\n if (this.successCallback) {\n this.successCallback();\n }\n });\n this.addUpdateBoundTag();\n }\n\n imageLoadFail(url: string, cb?: () => void): void {\n super.imageLoadFail(url, () => {\n if (this.failCallback) {\n this.failCallback();\n }\n });\n }\n\n setAttributes(\n params: Partial<IImageGraphicAttribute>,\n forceUpdateTag?: boolean,\n context?: ISetAttributeContext\n ): void {\n if (params.image) {\n this.loadImage(params.image);\n }\n return super.setAttributes(params, forceUpdateTag, context);\n }\n\n setAttribute(key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext): void {\n if (key === 'image') {\n this.loadImage(value);\n }\n return super.setAttribute(key, value, forceUpdateTag, context);\n }\n\n getGraphicTheme(): Required<IImageGraphicAttribute> {\n return getTheme(this).image;\n }\n\n protected updateAABBBounds(\n attribute: IImageGraphicAttribute,\n imageTheme: Required<IImageGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n const { maxWidth = imageTheme.maxWidth, maxHeight = imageTheme.maxHeight } = attribute;\n let { width, height } = attribute;\n if (width == null || height == null) {\n const imageElement = this.getImageElement();\n if (imageElement) {\n // 如果给了width或者height,那就使用已给的width或者height来按比例缩放,否则就在maxWidth和maxHeight之间按比例缩放\n const imageWidth = imageElement.width;\n const imageHeight = imageElement.height;\n if (width != null) {\n height = width * (imageHeight / imageWidth);\n } else if (height != null) {\n width = height * (imageWidth / imageHeight);\n } else {\n // 如果width和height都没有给,那就使用maxWidth和maxHeight来按比例缩放\n const imageRatio = imageWidth / imageHeight;\n const maxWHRatio = maxWidth / maxHeight;\n if (imageRatio > maxWHRatio) {\n width = maxWidth;\n height = maxWidth / imageRatio;\n } else {\n height = maxHeight;\n width = maxHeight * imageRatio;\n }\n }\n } else {\n width = maxWidth;\n height = maxHeight;\n }\n }\n this._actualWidth = width;\n this._actualHeight = height;\n aabbBounds.set(0, 0, width, height);\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfCommonOuterBorder(attribute, imageTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, imageTheme, false, this);\n return aabbBounds;\n }\n\n getDefaultAttribute(name: string) {\n return (DefaultImageAttribute as any)[name];\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, IMAGE_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, IMAGE_UPDATE_TAG_KEY);\n }\n\n clone() {\n return new Image({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Image.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createImage(attributes: IImageGraphicAttribute): IImage {\n return new Image(attributes);\n}\n"]}
@@ -67,8 +67,18 @@ export default class Line {
67
67
  paragraph.ellipsis = "hide", otherParagraphWidth += paragraph.width;
68
68
  }
69
69
  }
70
+ let fillStyle = "", globalAlpha = -1, currBgList = [];
71
+ const bgList = [ currBgList ];
70
72
  this.paragraphs.forEach(((paragraph, index) => {
71
- paragraph instanceof RichTextIcon || paragraph.drawBackground(ctx, y, this.ascent, x, 0 === index, this.textAlign, this.height);
73
+ if (paragraph instanceof RichTextIcon) return;
74
+ const data = paragraph.drawBackground(ctx, y, this.ascent, x, 0 === index, this.textAlign, this.height);
75
+ data && (fillStyle === data.fillStyle && globalAlpha === data.globalAlpha || (currBgList = [],
76
+ bgList.push(currBgList), fillStyle = data.fillStyle, globalAlpha = data.globalAlpha),
77
+ currBgList.push(data));
78
+ })), bgList.forEach((bg => {
79
+ if (0 === bg.length) return;
80
+ const data = bg[0], end = bg[bg.length - 1];
81
+ ctx.fillStyle = data.fillStyle, ctx.globalAlpha = data.globalAlpha, ctx.fillRect(data.left, data.top, end.right - data.left, end.bottom - data.top);
72
82
  })), this.paragraphs.forEach(((paragraph, index) => {
73
83
  if (paragraph instanceof RichTextIcon) return paragraph.setAttributes({
74
84
  x: x + paragraph._x,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/richtext/line.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA8B5G,MAAM,CAAC,OAAO,OAAO,IAAI;IAevB,YACE,IAAY,EACZ,KAAa,EACb,QAAgB,EAChB,MAAc,EACd,OAAe,EACf,UAAwC,EACxC,SAAoC,EACpC,UAAmB;QAEnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,GAAG,GAAG,QAAQ,GAAG,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,CAAC,SAAS;YACZ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,YAAY;gBACzC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS;gBACxC,CAAC,CAAC,IAAI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F;QAED,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YAC3C,IAAI,SAAS,YAAY,YAAY,EAAE;gBACrC,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC;aAC1B;iBAAM;gBACL,KAAK,IAAI,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACvD;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF","file":"line.js","sourcesContent":["// import { IContext2d } from '../../IContext';\nimport type { IContext2d, IRichTextIcon } from '../../interface';\nimport { RichTextIcon } from './icon';\nimport Paragraph from './paragraph';\nimport { applyFillStyle, applyStrokeStyle, DIRECTION_KEY, measureTextCanvas, regFirstSpace } from './utils';\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 行\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/line.js\nexport default class Line {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (Paragraph | RichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string; left: string; x: string; y: string };\n\n constructor(\n left: number,\n width: number,\n baseline: number,\n ascent: number,\n descent: number,\n lineBuffer: (Paragraph | RichTextIcon)[],\n direction: 'horizontal' | 'vertical',\n isWidthMax: boolean\n ) {\n this.left = left;\n this.width = width;\n this.baseline = baseline;\n this.ascent = ascent;\n this.descent = descent;\n // this.height = ascent + descent;\n this.top = baseline - ascent;\n this.paragraphs = lineBuffer.map(p => p);\n this.textAlign =\n (this.paragraphs[0] instanceof RichTextIcon\n ? this.paragraphs[0].attribute.textAlign\n : this.paragraphs[0].character.textAlign) || 'left'; // 对齐方式选择第一个paragraph属性\n this.direction = direction;\n this.directionKey = DIRECTION_KEY[this.direction];\n\n this.actualWidth = 0;\n let maxHeight = 0;\n this.paragraphs.forEach((word, index) => {\n // 每行中第一个字符不能是空格\n if (index === 0 && word instanceof Paragraph) {\n const result = regFirstSpace.exec(word.text);\n if (result?.index !== 0) {\n word.text = word.text.slice(result?.index);\n word.updateWidth();\n }\n }\n this.actualWidth += word[this.directionKey.width];\n maxHeight = Math.max(word[this.directionKey.height], maxHeight);\n });\n this.height = maxHeight;\n\n this.blankWidth = !isWidthMax ? this.width - this.actualWidth : 0;\n\n this.calcOffset(width, isWidthMax);\n }\n\n calcOffset(width: number, isWidthMax: boolean) {\n // 处理对齐方式,计算左侧偏移距离和字符之间间距\n const directionKey = this.directionKey;\n const maxHeight = this.height;\n let x = this.left;\n let spacing = 0;\n if (this.actualWidth < width && !isWidthMax) {\n if (this.textAlign === 'right' || this.textAlign === 'end') {\n x = width - this.actualWidth;\n } else if (this.textAlign === 'center') {\n x = (width - this.actualWidth) / 2;\n } else if (this.textAlign === 'justify') {\n if (this.paragraphs.length < 2) {\n // 只有一个paragraph两端对齐居中显示\n x = (width - this.actualWidth) / 2;\n } else {\n spacing = (width - this.actualWidth) / (this.paragraphs.length - 1);\n }\n }\n }\n\n this.paragraphs.map(function (paragraph) {\n if (paragraph instanceof RichTextIcon) {\n // paragraph.setAttribute(directionKey.x, x);\n paragraph['_' + directionKey.x] = x;\n x += paragraph[directionKey.width] + spacing;\n // 处理纵向对齐\n paragraph['_' + directionKey.y] =\n paragraph.attribute.textBaseline === 'top'\n ? 0\n : paragraph.attribute.textBaseline === 'bottom'\n ? maxHeight - paragraph.height\n : (maxHeight - paragraph.height) / 2;\n } else {\n paragraph[directionKey.left] = x;\n x += paragraph[directionKey.width] + spacing;\n }\n });\n }\n\n draw(\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawEllipsis: boolean | string,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) {\n if (drawEllipsis && (lastLine || this.paragraphs.some(p => (p as Paragraph).overflow))) {\n // 检测是否需要省略号,因为会有多行同时省略的情况\n let emptyOverflow = true;\n let skipEllipsis = false;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n emptyOverflow = emptyOverflow && (paragraph as Paragraph).text === '';\n } else {\n if (emptyOverflow) {\n skipEllipsis = true;\n break;\n }\n }\n }\n\n // 处理省略号\n let otherParagraphWidth = 0;\n if (!skipEllipsis) {\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n if ((paragraph as Paragraph).text === '') {\n break;\n }\n continue;\n }\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n if (this.direction === 'vertical' && paragraph.direction !== 'vertical') {\n paragraph.verticalEllipsis = true;\n break;\n }\n const ellipsis = drawEllipsis === true ? '...' : drawEllipsis || '';\n paragraph.ellipsisStr = ellipsis;\n // const { width } = measureText('...', paragraph.style);\n const { width } = measureTextCanvas(ellipsis, paragraph.character, paragraph.ascentDescentMode);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n lastLine && (paragraph.ellipsis = 'add');\n\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n }\n }\n\n // 绘制背景\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n return;\n }\n paragraph.drawBackground(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n });\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n // 更新icon位置\n paragraph.setAttributes({\n x: x + paragraph._x,\n y: y + paragraph._y\n });\n\n // 绘制icon\n drawIcon(paragraph, ctx, x + paragraph._x, y + paragraph._y, this.ascent);\n return;\n }\n const b = {\n x1: this.left,\n y1: this.top,\n x2: this.left + this.actualWidth,\n y2: this.top + this.height\n };\n applyStrokeStyle(ctx, paragraph.character);\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, paragraph.character, b);\n paragraph.draw(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n });\n }\n\n getWidthWithEllips(ellipsis: string) {\n // 处理省略号\n let otherParagraphWidth = 0;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n\n const { width } = measureTextCanvas(ellipsis, paragraph.character, paragraph.ascentDescentMode);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n paragraph.ellipsis = 'add';\n paragraph.ellipsisWidth = ellipsisWidth;\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n\n let width = 0;\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n width += paragraph.width; // todo: 处理direction\n } else {\n width += paragraph.getWidthWithEllips(this.direction);\n }\n });\n\n return width;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/richtext/line.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA8B5G,MAAM,CAAC,OAAO,OAAO,IAAI;IAevB,YACE,IAAY,EACZ,KAAa,EACb,QAAgB,EAChB,MAAc,EACd,OAAe,EACf,UAAwC,EACxC,SAAoC,EACpC,UAAmB;QAEnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG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AS,CAAC,aAAa,GAAG,aAAa,CAAC;gBACxC,SAAS,CAAC,2BAA2B,GAAG,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC;gBAE9E,MAAM;aACP;iBAAM;gBAEL,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;gBAC5B,mBAAmB,IAAI,SAAS,CAAC,KAAK,CAAC;aACxC;SACF;QAED,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YAC3C,IAAI,SAAS,YAAY,YAAY,EAAE;gBACrC,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC;aAC1B;iBAAM;gBACL,KAAK,IAAI,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACvD;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF","file":"line.js","sourcesContent":["// import { IContext2d } from '../../IContext';\nimport type { IContext2d, IRichTextIcon } from '../../interface';\nimport { RichTextIcon } from './icon';\nimport Paragraph from './paragraph';\nimport { applyFillStyle, applyStrokeStyle, DIRECTION_KEY, measureTextCanvas, regFirstSpace } from './utils';\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 行\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/line.js\nexport default class Line {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (Paragraph | RichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string; left: string; x: string; y: string };\n\n constructor(\n left: number,\n width: number,\n baseline: number,\n ascent: number,\n descent: number,\n lineBuffer: (Paragraph | RichTextIcon)[],\n direction: 'horizontal' | 'vertical',\n isWidthMax: boolean\n ) {\n this.left = left;\n this.width = width;\n this.baseline = baseline;\n this.ascent = ascent;\n this.descent = descent;\n // this.height = ascent + descent;\n this.top = baseline - ascent;\n this.paragraphs = lineBuffer.map(p => p);\n this.textAlign =\n (this.paragraphs[0] instanceof RichTextIcon\n ? this.paragraphs[0].attribute.textAlign\n : this.paragraphs[0].character.textAlign) || 'left'; // 对齐方式选择第一个paragraph属性\n this.direction = direction;\n this.directionKey = DIRECTION_KEY[this.direction];\n\n this.actualWidth = 0;\n let maxHeight = 0;\n this.paragraphs.forEach((word, index) => {\n // 每行中第一个字符不能是空格\n if (index === 0 && word instanceof Paragraph) {\n const result = regFirstSpace.exec(word.text);\n if (result?.index !== 0) {\n word.text = word.text.slice(result?.index);\n word.updateWidth();\n }\n }\n this.actualWidth += word[this.directionKey.width];\n maxHeight = Math.max(word[this.directionKey.height], maxHeight);\n });\n this.height = maxHeight;\n\n this.blankWidth = !isWidthMax ? this.width - this.actualWidth : 0;\n\n this.calcOffset(width, isWidthMax);\n }\n\n calcOffset(width: number, isWidthMax: boolean) {\n // 处理对齐方式,计算左侧偏移距离和字符之间间距\n const directionKey = this.directionKey;\n const maxHeight = this.height;\n let x = this.left;\n let spacing = 0;\n if (this.actualWidth < width && !isWidthMax) {\n if (this.textAlign === 'right' || this.textAlign === 'end') {\n x = width - this.actualWidth;\n } else if (this.textAlign === 'center') {\n x = (width - this.actualWidth) / 2;\n } else if (this.textAlign === 'justify') {\n if (this.paragraphs.length < 2) {\n // 只有一个paragraph两端对齐居中显示\n x = (width - this.actualWidth) / 2;\n } else {\n spacing = (width - this.actualWidth) / (this.paragraphs.length - 1);\n }\n }\n }\n\n this.paragraphs.map(function (paragraph) {\n if (paragraph instanceof RichTextIcon) {\n // paragraph.setAttribute(directionKey.x, x);\n paragraph['_' + directionKey.x] = x;\n x += paragraph[directionKey.width] + spacing;\n // 处理纵向对齐\n paragraph['_' + directionKey.y] =\n paragraph.attribute.textBaseline === 'top'\n ? 0\n : paragraph.attribute.textBaseline === 'bottom'\n ? maxHeight - paragraph.height\n : (maxHeight - paragraph.height) / 2;\n } else {\n paragraph[directionKey.left] = x;\n x += paragraph[directionKey.width] + spacing;\n }\n });\n }\n\n draw(\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawEllipsis: boolean | string,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) {\n if (drawEllipsis && (lastLine || this.paragraphs.some(p => (p as Paragraph).overflow))) {\n // 检测是否需要省略号,因为会有多行同时省略的情况\n let emptyOverflow = true;\n let skipEllipsis = false;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n emptyOverflow = emptyOverflow && (paragraph as Paragraph).text === '';\n } else {\n if (emptyOverflow) {\n skipEllipsis = true;\n break;\n }\n }\n }\n\n // 处理省略号\n let otherParagraphWidth = 0;\n if (!skipEllipsis) {\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n if ((paragraph as Paragraph).text === '') {\n break;\n }\n continue;\n }\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n if (this.direction === 'vertical' && paragraph.direction !== 'vertical') {\n paragraph.verticalEllipsis = true;\n break;\n }\n const ellipsis = drawEllipsis === true ? '...' : drawEllipsis || '';\n paragraph.ellipsisStr = ellipsis;\n // const { width } = measureText('...', paragraph.style);\n const { width } = measureTextCanvas(ellipsis, paragraph.character, paragraph.ascentDescentMode);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n lastLine && (paragraph.ellipsis = 'add');\n\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n }\n }\n\n // 绘制背景\n // 属性相同的背景,合并绘制\n let fillStyle = '';\n let globalAlpha = -1;\n let currBgList: {\n fillStyle: string;\n globalAlpha: number;\n left: number;\n top: number;\n right: number;\n bottom: number;\n }[] = [];\n const bgList = [currBgList];\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n return;\n }\n const data = paragraph.drawBackground(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n if (!data) {\n return;\n }\n if (!(fillStyle === data.fillStyle && globalAlpha === data.globalAlpha)) {\n currBgList = [];\n bgList.push(currBgList);\n fillStyle = data.fillStyle;\n globalAlpha = data.globalAlpha;\n }\n currBgList.push(data);\n });\n // 绘制背景\n bgList.forEach(bg => {\n if (bg.length === 0) {\n return;\n }\n const data = bg[0];\n const end = bg[bg.length - 1];\n ctx.fillStyle = data.fillStyle;\n ctx.globalAlpha = data.globalAlpha;\n ctx.fillRect(data.left, data.top, end.right - data.left, end.bottom - data.top);\n });\n\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n // 更新icon位置\n paragraph.setAttributes({\n x: x + paragraph._x,\n y: y + paragraph._y\n });\n\n // 绘制icon\n drawIcon(paragraph, ctx, x + paragraph._x, y + paragraph._y, this.ascent);\n return;\n }\n const b = {\n x1: this.left,\n y1: this.top,\n x2: this.left + this.actualWidth,\n y2: this.top + this.height\n };\n applyStrokeStyle(ctx, paragraph.character);\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, paragraph.character, b);\n paragraph.draw(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n });\n }\n\n getWidthWithEllips(ellipsis: string) {\n // 处理省略号\n let otherParagraphWidth = 0;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n\n const { width } = measureTextCanvas(ellipsis, paragraph.character, paragraph.ascentDescentMode);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n paragraph.ellipsis = 'add';\n paragraph.ellipsisWidth = ellipsisWidth;\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n\n let width = 0;\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n width += paragraph.width; // todo: 处理direction\n } else {\n width += paragraph.getWidthWithEllips(this.direction);\n }\n });\n\n return width;\n }\n}\n"]}
@@ -25,7 +25,14 @@ export default class Paragraph {
25
25
  overflow?: boolean;
26
26
  constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter, ascentDescentMode?: 'actual' | 'font');
27
27
  updateWidth(): void;
28
- drawBackground(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): void;
28
+ drawBackground(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): {
29
+ fillStyle: string;
30
+ globalAlpha: number;
31
+ left: number;
32
+ top: number;
33
+ right: number;
34
+ bottom: number;
35
+ };
29
36
  draw(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): void;
30
37
  getWidthWithEllips(direction: string): number;
31
38
  }
@@ -38,7 +38,7 @@ export default class Paragraph {
38
38
  this.width = this.heightOrigin, this.height = this.widthOrigin);
39
39
  }
40
40
  drawBackground(ctx, top, ascent, deltaLeft, isLineFirst, textAlign, lineHeight) {
41
- if (!this.character.background || this.character.backgroundOpacity && !(this.character.backgroundOpacity > 0)) return;
41
+ if ("" === this.text || "\n" === this.text || !this.character.background || this.character.backgroundOpacity && !(this.character.backgroundOpacity > 0)) return;
42
42
  let baseline = top + ascent, text = this.text, left = this.left + deltaLeft;
43
43
  baseline += this.top;
44
44
  let direction = this.direction;
@@ -52,22 +52,11 @@ export default class Paragraph {
52
52
  }
53
53
  }
54
54
  }
55
- switch (this.character.script) {
56
- case "super":
57
- baseline -= this.ascent * (1 / 3);
58
- break;
59
-
60
- case "sub":
61
- baseline += this.descent / 2;
62
- }
63
- "vertical" === direction && (ctx.save(), ctx.rotateAbout(Math.PI / 2, left, baseline),
64
- ctx.translate(-this.heightOrigin || -this.lineHeight / 2, -this.descent / 2), ctx.translate(left, baseline),
65
- left = 0, baseline = 0);
66
- const fillStyle = ctx.fillStyle, globalAlpha = ctx.globalAlpha;
67
- ctx.fillStyle = this.character.background, void 0 !== this.character.backgroundOpacity && (ctx.globalAlpha = this.character.backgroundOpacity);
68
55
  const lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + lineHeight);
69
- ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top),
70
- ctx.fillStyle = fillStyle, ctx.globalAlpha = globalAlpha;
56
+ return Object.assign(Object.assign({}, lrtb), {
57
+ fillStyle: this.character.background,
58
+ globalAlpha: this.character.backgroundOpacity
59
+ });
71
60
  }
72
61
  draw(ctx, top, ascent, deltaLeft, isLineFirst, textAlign, lineHeight) {
73
62
  let baseline = top + ascent, text = this.text, left = this.left + deltaLeft;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEhE,SAAS,YAAY,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW,EAAE,MAAc;IAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC;IACvD,MAAM,IAAI,GAAG,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM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SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,iBAAiB,CAAC,CAAC;IAExF,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC","file":"paragraph.js","sourcesContent":["import { calculateLineHeight } from '../../common/utils';\nimport type { IContext2d, IRichTextParagraphCharacter } from '../../interface';\nimport { measureTextCanvas, getStrByWithCanvas } from './utils';\n\nfunction getFixedLRTB(left: number, right: number, top: number, bottom: number) {\n const leftInt = Math.round(left);\n const topInt = Math.round(top);\n const rightInt = Math.round(right);\n const bottomInt = Math.round(bottom);\n const _left = left > leftInt ? leftInt : leftInt - 0.5;\n const _top = top > topInt ? topInt : topInt - 0.5;\n const _right = rightInt > right ? rightInt : rightInt + 0.5;\n const _bottom = bottomInt > bottom ? bottomInt : bottomInt + 0.5;\n return {\n left: _left,\n top: _top,\n right: _right,\n bottom: _bottom\n };\n}\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 文字段\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/text.js\nexport default class Paragraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n // rotate?: number;\n direction?: 'horizontal' | 'vertical';\n // bounds?: Bounds;\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ascentDescentMode?: 'actual' | 'font';\n\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisStr: string;\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n overflow?: boolean;\n\n constructor(\n text: string,\n newLine: boolean,\n character: IRichTextParagraphCharacter,\n ascentDescentMode?: 'actual' | 'font'\n ) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\n this.ascentDescentMode = ascentDescentMode;\n\n // 处理行高:\n // lineHeight为数字时,大于fontSize取lineHeight,小于fontSize时取fontSize\n // lineHeight不为数字时,统一认为lineHeight为'normal',值取1.2 * fontSize\n const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);\n if (typeof lineHeight === 'number') {\n this.lineHeight = lineHeight > this.fontSize ? lineHeight : this.fontSize;\n } else {\n this.lineHeight = Math.floor(1.2 * this.fontSize);\n }\n\n this.height = this.lineHeight;\n\n const { ascent, height, descent, width } = measureTextCanvas(text, character, this.ascentDescentMode);\n\n let halfDetaHeight = 0;\n let deltaAscent = 0;\n let deltaDescent = 0;\n if (this.height > height) {\n // measureTextCanvas测量出的是纯文字高度,this.height是考虑行高后的高度\n // 如果this.height > height,将超过的高度平均分配到ascent和descent上\n halfDetaHeight = (this.height - height) / 2;\n deltaAscent = Math.ceil(halfDetaHeight);\n deltaDescent = Math.floor(halfDetaHeight);\n }\n\n if (this.textBaseline === 'top') {\n this.ascent = halfDetaHeight;\n this.descent = height - halfDetaHeight;\n } else if (this.textBaseline === 'bottom') {\n this.ascent = height - halfDetaHeight;\n this.descent = halfDetaHeight;\n } else if (this.textBaseline === 'middle') {\n this.ascent = this.height / 2;\n this.descent = this.height / 2;\n } else {\n this.ascent = ascent + deltaAscent;\n this.descent = descent + deltaDescent;\n }\n\n this.length = text.length;\n this.width = width || 0;\n this.text = text || '';\n this.newLine = newLine || false;\n this.character = character;\n\n this.left = 0;\n this.top = 0;\n\n this.ellipsis = 'normal';\n this.ellipsisWidth = 0;\n this.ellipsisOtherParagraphWidth = 0;\n\n // 处理旋转\n if (character.direction === 'vertical') {\n this.direction = character.direction;\n this.widthOrigin = this.width;\n this.heightOrigin = this.height;\n // const bounds = new Bounds();\n // bounds.set(0, 0, this.width, this.height);\n // bounds.rotate(Math.PI / 2, this.width / 2, this.height / 2);\n // this.bounds = bounds;\n // this.width = bounds.width();\n // this.height = bounds.height();\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n this.lineHeight = this.height;\n }\n this.ellipsisStr = '...';\n }\n\n updateWidth() {\n const { width } = measureTextCanvas(this.text, this.character, this.ascentDescentMode);\n this.width = width;\n if (this.direction === 'vertical') {\n this.widthOrigin = this.width;\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n }\n }\n\n drawBackground(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n if (!(this.character.background && (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0))) {\n return;\n }\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n const fillStyle = ctx.fillStyle;\n const globalAlpha = ctx.globalAlpha;\n ctx.fillStyle = this.character.background;\n if (this.character.backgroundOpacity !== void 0) {\n ctx.globalAlpha = this.character.backgroundOpacity;\n }\n // 背景稍微扩充一些buf,否则会出现白线\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + lineHeight;\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n ctx.fillStyle = fillStyle;\n ctx.globalAlpha = globalAlpha;\n }\n\n draw(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // if (isLineFirst) {\n // const result = regFirstSpace.exec(text);\n // if (result?.index !== 0) {\n // text = text.slice(result?.index);\n // }\n // }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n // if (this.character.fill) {\n // if (this.character.background && (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0)) {\n // const fillStyle = ctx.fillStyle;\n // const globalAlpha = ctx.globalAlpha;\n // ctx.fillStyle = this.character.background;\n // if (this.character.backgroundOpacity !== void 0) {\n // ctx.globalAlpha = this.character.backgroundOpacity;\n // }\n // // 背景稍微扩充一些buf,否则会出现白线\n // const right = left + (this.widthOrigin || this.width);\n // const bottom = top + lineHeight;\n // const lrtb = getFixedLRTB(left, right, top, bottom);\n // ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n // ctx.fillStyle = fillStyle;\n // ctx.globalAlpha = globalAlpha;\n // }\n // }\n\n const { lineWidth = 1 } = this.character;\n if (this.character.stroke && lineWidth) {\n ctx.strokeText(text, left, baseline);\n }\n\n if (this.character.fill) {\n ctx.fillText(text, left, baseline);\n }\n\n if (this.character.fill) {\n if (this.character.lineThrough || this.character.underline) {\n if (this.character.underline) {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n if (this.character.lineThrough) {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline - this.ascent / 2,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n } else if (this.character.textDecoration === 'underline') {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n } else if (this.character.textDecoration === 'line-through') {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline - this.ascent / 2,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n }\n\n if (direction === 'vertical') {\n ctx.restore();\n }\n }\n\n getWidthWithEllips(direction: string): number {\n let text = this.text;\n // const direction = this.direction;\n const width = direction === 'vertical' ? this.height : this.width;\n // const height = direction === 'vertical' ? this.width: this.height;\n\n if (this.ellipsis === 'hide') {\n return width;\n } else if (this.ellipsis === 'add') {\n return width + this.ellipsisWidth;\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n const { width: measureWidth } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n return width + this.ellipsisWidth - measureWidth;\n }\n return width;\n }\n}\n\nexport function seperateParagraph(paragraph: Paragraph, index: number) {\n const text1 = paragraph.text.slice(0, index);\n const text2 = paragraph.text.slice(index);\n const p1 = new Paragraph(text1, paragraph.newLine, paragraph.character, paragraph.ascentDescentMode);\n const p2 = new Paragraph(text2, true, paragraph.character, paragraph.ascentDescentMode);\n\n return [p1, p2];\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEhE,SAAS,YAAY,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW,EAAE,MAAc;IAC5E,MAAM,OAAO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AAS,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAClH,OAAO,KAAK,GAAG,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;SAClD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAAC,SAAoB,EAAE,KAAa;IACnE,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,iBAAiB,CAAC,CAAC;IACrG,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,iBAAiB,CAAC,CAAC;IAExF,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC","file":"paragraph.js","sourcesContent":["import { calculateLineHeight } from '../../common/utils';\nimport type { IContext2d, IRichTextParagraphCharacter } from '../../interface';\nimport { measureTextCanvas, getStrByWithCanvas } from './utils';\n\nfunction getFixedLRTB(left: number, right: number, top: number, bottom: number) {\n const leftInt = Math.round(left);\n const topInt = Math.round(top);\n const rightInt = Math.round(right);\n const bottomInt = Math.round(bottom);\n const _left = left > leftInt ? leftInt : leftInt - 0.5;\n const _top = top > topInt ? topInt : topInt - 0.5;\n const _right = rightInt > right ? rightInt : rightInt + 0.5;\n const _bottom = bottomInt > bottom ? bottomInt : bottomInt + 0.5;\n return {\n left: _left,\n top: _top,\n right: _right,\n bottom: _bottom\n };\n}\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 文字段\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/text.js\nexport default class Paragraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n // rotate?: number;\n direction?: 'horizontal' | 'vertical';\n // bounds?: Bounds;\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ascentDescentMode?: 'actual' | 'font';\n\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisStr: string;\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n overflow?: boolean;\n\n constructor(\n text: string,\n newLine: boolean,\n character: IRichTextParagraphCharacter,\n ascentDescentMode?: 'actual' | 'font'\n ) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\n this.ascentDescentMode = ascentDescentMode;\n\n // 处理行高:\n // lineHeight为数字时,大于fontSize取lineHeight,小于fontSize时取fontSize\n // lineHeight不为数字时,统一认为lineHeight为'normal',值取1.2 * fontSize\n const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);\n if (typeof lineHeight === 'number') {\n this.lineHeight = lineHeight > this.fontSize ? lineHeight : this.fontSize;\n } else {\n this.lineHeight = Math.floor(1.2 * this.fontSize);\n }\n\n this.height = this.lineHeight;\n\n const { ascent, height, descent, width } = measureTextCanvas(text, character, this.ascentDescentMode);\n\n let halfDetaHeight = 0;\n let deltaAscent = 0;\n let deltaDescent = 0;\n if (this.height > height) {\n // measureTextCanvas测量出的是纯文字高度,this.height是考虑行高后的高度\n // 如果this.height > height,将超过的高度平均分配到ascent和descent上\n halfDetaHeight = (this.height - height) / 2;\n deltaAscent = Math.ceil(halfDetaHeight);\n deltaDescent = Math.floor(halfDetaHeight);\n }\n\n if (this.textBaseline === 'top') {\n this.ascent = halfDetaHeight;\n this.descent = height - halfDetaHeight;\n } else if (this.textBaseline === 'bottom') {\n this.ascent = height - halfDetaHeight;\n this.descent = halfDetaHeight;\n } else if (this.textBaseline === 'middle') {\n this.ascent = this.height / 2;\n this.descent = this.height / 2;\n } else {\n this.ascent = ascent + deltaAscent;\n this.descent = descent + deltaDescent;\n }\n\n this.length = text.length;\n this.width = width || 0;\n this.text = text || '';\n this.newLine = newLine || false;\n this.character = character;\n\n this.left = 0;\n this.top = 0;\n\n this.ellipsis = 'normal';\n this.ellipsisWidth = 0;\n this.ellipsisOtherParagraphWidth = 0;\n\n // 处理旋转\n if (character.direction === 'vertical') {\n this.direction = character.direction;\n this.widthOrigin = this.width;\n this.heightOrigin = this.height;\n // const bounds = new Bounds();\n // bounds.set(0, 0, this.width, this.height);\n // bounds.rotate(Math.PI / 2, this.width / 2, this.height / 2);\n // this.bounds = bounds;\n // this.width = bounds.width();\n // this.height = bounds.height();\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n this.lineHeight = this.height;\n }\n this.ellipsisStr = '...';\n }\n\n updateWidth() {\n const { width } = measureTextCanvas(this.text, this.character, this.ascentDescentMode);\n this.width = width;\n if (this.direction === 'vertical') {\n this.widthOrigin = this.width;\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n }\n }\n\n drawBackground(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n if (\n !(\n this.text !== '' &&\n this.text !== '\\n' &&\n this.character.background &&\n (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0)\n )\n ) {\n return;\n }\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n // 背景稍微扩充一些buf,否则会出现白线\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + lineHeight;\n const lrtb = getFixedLRTB(left, right, top, bottom);\n\n return {\n ...lrtb,\n fillStyle: this.character.background,\n globalAlpha: this.character.backgroundOpacity\n };\n }\n\n draw(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // if (isLineFirst) {\n // const result = regFirstSpace.exec(text);\n // if (result?.index !== 0) {\n // text = text.slice(result?.index);\n // }\n // }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n // if (this.character.fill) {\n // if (this.character.background && (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0)) {\n // const fillStyle = ctx.fillStyle;\n // const globalAlpha = ctx.globalAlpha;\n // ctx.fillStyle = this.character.background;\n // if (this.character.backgroundOpacity !== void 0) {\n // ctx.globalAlpha = this.character.backgroundOpacity;\n // }\n // // 背景稍微扩充一些buf,否则会出现白线\n // const right = left + (this.widthOrigin || this.width);\n // const bottom = top + lineHeight;\n // const lrtb = getFixedLRTB(left, right, top, bottom);\n // ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n // ctx.fillStyle = fillStyle;\n // ctx.globalAlpha = globalAlpha;\n // }\n // }\n\n const { lineWidth = 1 } = this.character;\n if (this.character.stroke && lineWidth) {\n ctx.strokeText(text, left, baseline);\n }\n\n if (this.character.fill) {\n ctx.fillText(text, left, baseline);\n }\n\n if (this.character.fill) {\n if (this.character.lineThrough || this.character.underline) {\n if (this.character.underline) {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n if (this.character.lineThrough) {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline - this.ascent / 2,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n } else if (this.character.textDecoration === 'underline') {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n } else if (this.character.textDecoration === 'line-through') {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(\n lrtb.left,\n 1 + baseline - this.ascent / 2,\n lrtb.right - lrtb.left,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n }\n\n if (direction === 'vertical') {\n ctx.restore();\n }\n }\n\n getWidthWithEllips(direction: string): number {\n let text = this.text;\n // const direction = this.direction;\n const width = direction === 'vertical' ? this.height : this.width;\n // const height = direction === 'vertical' ? this.width: this.height;\n\n if (this.ellipsis === 'hide') {\n return width;\n } else if (this.ellipsis === 'add') {\n return width + this.ellipsisWidth;\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n const { width: measureWidth } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\n return width + this.ellipsisWidth - measureWidth;\n }\n return width;\n }\n}\n\nexport function seperateParagraph(paragraph: Paragraph, index: number) {\n const text1 = paragraph.text.slice(0, index);\n const text2 = paragraph.text.slice(index);\n const p1 = new Paragraph(text1, paragraph.newLine, paragraph.character, paragraph.ascentDescentMode);\n const p2 = new Paragraph(text2, true, paragraph.character, paragraph.ascentDescentMode);\n\n return [p1, p2];\n}\n"]}