@visactor/vrender-core 0.22.7-alpha.8 → 0.22.7

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 (188) hide show
  1. package/cjs/canvas/util.js +1 -2
  2. package/cjs/color-string/store.js +2 -1
  3. package/cjs/common/canvas-utils.js +5 -2
  4. package/cjs/common/canvas-utils.js.map +1 -1
  5. package/cjs/event/federated-event/base-event.js +1 -1
  6. package/cjs/event/federated-event/base-event.js.map +1 -1
  7. package/cjs/graphic/arc.js +1 -1
  8. package/cjs/graphic/arc.js.map +1 -1
  9. package/cjs/graphic/area.js +1 -1
  10. package/cjs/graphic/area.js.map +1 -1
  11. package/cjs/graphic/circle.js +2 -1
  12. package/cjs/graphic/circle.js.map +1 -1
  13. package/cjs/graphic/config.d.ts +2 -1
  14. package/cjs/graphic/config.js +8 -2
  15. package/cjs/graphic/config.js.map +1 -1
  16. package/cjs/graphic/constants.d.ts +1 -0
  17. package/cjs/graphic/constants.js +4 -3
  18. package/cjs/graphic/constants.js.map +1 -1
  19. package/cjs/graphic/graphic.d.ts +3 -0
  20. package/cjs/graphic/graphic.js +9 -6
  21. package/cjs/graphic/graphic.js.map +1 -1
  22. package/cjs/graphic/image.js +2 -1
  23. package/cjs/graphic/image.js.map +1 -1
  24. package/cjs/graphic/index.d.ts +1 -0
  25. package/cjs/graphic/index.js +8 -8
  26. package/cjs/graphic/index.js.map +1 -1
  27. package/cjs/graphic/line.js +2 -1
  28. package/cjs/graphic/line.js.map +1 -1
  29. package/cjs/graphic/path.js +2 -1
  30. package/cjs/graphic/path.js.map +1 -1
  31. package/cjs/graphic/polygon.js +2 -1
  32. package/cjs/graphic/polygon.js.map +1 -1
  33. package/cjs/graphic/rect.js +2 -1
  34. package/cjs/graphic/rect.js.map +1 -1
  35. package/cjs/graphic/richtext/paragraph.d.ts +3 -0
  36. package/cjs/graphic/richtext/paragraph.js +14 -10
  37. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  38. package/cjs/graphic/richtext/utils.js +12 -2
  39. package/cjs/graphic/richtext/utils.js.map +1 -1
  40. package/cjs/graphic/richtext.d.ts +3 -0
  41. package/cjs/graphic/richtext.js +3 -2
  42. package/cjs/graphic/richtext.js.map +1 -1
  43. package/cjs/graphic/star.d.ts +53 -0
  44. package/cjs/graphic/star.js +76 -0
  45. package/cjs/graphic/star.js.map +1 -0
  46. package/cjs/graphic/symbol.js +2 -1
  47. package/cjs/graphic/symbol.js.map +1 -1
  48. package/cjs/graphic/text.js +1 -0
  49. package/cjs/graphic/text.js.map +1 -1
  50. package/cjs/graphic/theme.js +2 -0
  51. package/cjs/graphic/theme.js.map +1 -1
  52. package/cjs/index.d.ts +2 -0
  53. package/cjs/index.js +7 -6
  54. package/cjs/index.js.map +1 -1
  55. package/cjs/interface/contribution.d.ts +2 -0
  56. package/cjs/interface/contribution.js.map +1 -1
  57. package/cjs/interface/graphic/index.d.ts +1 -0
  58. package/cjs/interface/graphic/index.js +3 -2
  59. package/cjs/interface/graphic/index.js.map +1 -1
  60. package/cjs/interface/graphic/richText.d.ts +3 -0
  61. package/cjs/interface/graphic/richText.js.map +1 -1
  62. package/cjs/interface/graphic/star.d.ts +12 -0
  63. package/cjs/interface/graphic/star.js +6 -0
  64. package/cjs/interface/graphic/star.js.map +1 -0
  65. package/cjs/interface/graphic/theme.d.ts +3 -0
  66. package/cjs/interface/graphic/theme.js.map +1 -1
  67. package/cjs/interface/graphic.d.ts +5 -0
  68. package/cjs/interface/graphic.js.map +1 -1
  69. package/cjs/plugins/builtin-plugin/edit-module.js +11 -8
  70. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  71. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +1 -1
  72. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  73. package/cjs/register/register-star.d.ts +1 -0
  74. package/cjs/register/register-star.js +14 -0
  75. package/cjs/register/register-star.js.map +1 -0
  76. package/cjs/render/contributions/render/contributions/constants.d.ts +1 -0
  77. package/cjs/render/contributions/render/contributions/constants.js +3 -2
  78. package/cjs/render/contributions/render/contributions/constants.js.map +1 -1
  79. package/cjs/render/contributions/render/contributions/index.d.ts +1 -0
  80. package/cjs/render/contributions/render/contributions/index.js +2 -2
  81. package/cjs/render/contributions/render/contributions/index.js.map +1 -1
  82. package/cjs/render/contributions/render/contributions/star-contribution-render.d.ts +2 -0
  83. package/cjs/render/contributions/render/contributions/star-contribution-render.js +11 -0
  84. package/cjs/render/contributions/render/contributions/star-contribution-render.js.map +1 -0
  85. package/cjs/render/contributions/render/star-module.d.ts +2 -0
  86. package/cjs/render/contributions/render/star-module.js +15 -0
  87. package/cjs/render/contributions/render/star-module.js.map +1 -0
  88. package/cjs/render/contributions/render/star-render.d.ts +10 -0
  89. package/cjs/render/contributions/render/star-render.js +54 -0
  90. package/cjs/render/contributions/render/star-render.js.map +1 -0
  91. package/cjs/render/contributions/render/symbol.d.ts +1 -0
  92. package/cjs/render/contributions/render/symbol.js +2 -2
  93. package/cjs/render/contributions/render/symbol.js.map +1 -1
  94. package/dist/index.es.js +282 -21
  95. package/es/canvas/util.js +1 -2
  96. package/es/color-string/store.js +2 -1
  97. package/es/common/canvas-utils.js +5 -2
  98. package/es/common/canvas-utils.js.map +1 -1
  99. package/es/event/federated-event/base-event.js +1 -1
  100. package/es/event/federated-event/base-event.js.map +1 -1
  101. package/es/graphic/arc.js +1 -1
  102. package/es/graphic/arc.js.map +1 -1
  103. package/es/graphic/area.js +1 -1
  104. package/es/graphic/area.js.map +1 -1
  105. package/es/graphic/circle.js +2 -1
  106. package/es/graphic/circle.js.map +1 -1
  107. package/es/graphic/config.d.ts +2 -1
  108. package/es/graphic/config.js +9 -1
  109. package/es/graphic/config.js.map +1 -1
  110. package/es/graphic/constants.d.ts +1 -0
  111. package/es/graphic/constants.js +2 -0
  112. package/es/graphic/constants.js.map +1 -1
  113. package/es/graphic/graphic.d.ts +3 -0
  114. package/es/graphic/graphic.js +9 -6
  115. package/es/graphic/graphic.js.map +1 -1
  116. package/es/graphic/image.js +2 -1
  117. package/es/graphic/image.js.map +1 -1
  118. package/es/graphic/index.d.ts +1 -0
  119. package/es/graphic/index.js +2 -0
  120. package/es/graphic/index.js.map +1 -1
  121. package/es/graphic/line.js +2 -1
  122. package/es/graphic/line.js.map +1 -1
  123. package/es/graphic/path.js +2 -1
  124. package/es/graphic/path.js.map +1 -1
  125. package/es/graphic/polygon.js +2 -1
  126. package/es/graphic/polygon.js.map +1 -1
  127. package/es/graphic/rect.js +2 -1
  128. package/es/graphic/rect.js.map +1 -1
  129. package/es/graphic/richtext/paragraph.d.ts +3 -0
  130. package/es/graphic/richtext/paragraph.js +14 -10
  131. package/es/graphic/richtext/paragraph.js.map +1 -1
  132. package/es/graphic/richtext/utils.js +12 -2
  133. package/es/graphic/richtext/utils.js.map +1 -1
  134. package/es/graphic/richtext.d.ts +3 -0
  135. package/es/graphic/richtext.js +3 -2
  136. package/es/graphic/richtext.js.map +1 -1
  137. package/es/graphic/star.d.ts +53 -0
  138. package/es/graphic/star.js +80 -0
  139. package/es/graphic/star.js.map +1 -0
  140. package/es/graphic/symbol.js +2 -1
  141. package/es/graphic/symbol.js.map +1 -1
  142. package/es/graphic/text.js +1 -0
  143. package/es/graphic/text.js.map +1 -1
  144. package/es/graphic/theme.js +3 -1
  145. package/es/graphic/theme.js.map +1 -1
  146. package/es/index.d.ts +2 -0
  147. package/es/index.js +4 -0
  148. package/es/index.js.map +1 -1
  149. package/es/interface/contribution.d.ts +2 -0
  150. package/es/interface/contribution.js.map +1 -1
  151. package/es/interface/graphic/index.d.ts +1 -0
  152. package/es/interface/graphic/index.js +2 -0
  153. package/es/interface/graphic/index.js.map +1 -1
  154. package/es/interface/graphic/richText.d.ts +3 -0
  155. package/es/interface/graphic/richText.js.map +1 -1
  156. package/es/interface/graphic/star.d.ts +12 -0
  157. package/es/interface/graphic/star.js +2 -0
  158. package/es/interface/graphic/star.js.map +1 -0
  159. package/es/interface/graphic/theme.d.ts +3 -0
  160. package/es/interface/graphic/theme.js.map +1 -1
  161. package/es/interface/graphic.d.ts +5 -0
  162. package/es/interface/graphic.js.map +1 -1
  163. package/es/plugins/builtin-plugin/edit-module.js +11 -8
  164. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  165. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +1 -1
  166. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  167. package/es/register/register-star.d.ts +1 -0
  168. package/es/register/register-star.js +8 -0
  169. package/es/register/register-star.js.map +1 -0
  170. package/es/render/contributions/render/contributions/constants.d.ts +1 -0
  171. package/es/render/contributions/render/contributions/constants.js +2 -0
  172. package/es/render/contributions/render/contributions/constants.js.map +1 -1
  173. package/es/render/contributions/render/contributions/index.d.ts +1 -0
  174. package/es/render/contributions/render/contributions/index.js +2 -0
  175. package/es/render/contributions/render/contributions/index.js.map +1 -1
  176. package/es/render/contributions/render/contributions/star-contribution-render.d.ts +2 -0
  177. package/es/render/contributions/render/contributions/star-contribution-render.js +8 -0
  178. package/es/render/contributions/render/contributions/star-contribution-render.js.map +1 -0
  179. package/es/render/contributions/render/star-module.d.ts +2 -0
  180. package/es/render/contributions/render/star-module.js +13 -0
  181. package/es/render/contributions/render/star-module.js.map +1 -0
  182. package/es/render/contributions/render/star-render.d.ts +10 -0
  183. package/es/render/contributions/render/star-render.js +59 -0
  184. package/es/render/contributions/render/star-render.js.map +1 -0
  185. package/es/render/contributions/render/symbol.d.ts +1 -0
  186. package/es/render/contributions/render/symbol.js +2 -0
  187. package/es/render/contributions/render/symbol.js.map +1 -1
  188. package/package.json +2 -2
@@ -32,7 +32,8 @@ export class Line extends Graphic {
32
32
  }
33
33
  updateAABBBounds(attribute, lineTheme, aabbBounds) {
34
34
  this.updatePathProxyAABBBounds(aabbBounds) || (attribute.segments ? this.updateLineAABBBoundsBySegments(attribute, lineTheme, aabbBounds) : this.updateLineAABBBoundsByPoints(attribute, lineTheme, aabbBounds)),
35
- application.graphicService.updateTempAABBBounds(aabbBounds);
35
+ application.graphicService.updateTempAABBBounds(aabbBounds), this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1,
36
+ this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1;
36
37
  const {lineJoin: lineJoin = lineTheme.lineJoin} = attribute;
37
38
  return application.graphicService.transformAABBBounds(attribute, aabbBounds, lineTheme, "miter" === lineJoin, this),
38
39
  aabbBounds;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/line.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,mBAAmB,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,sBAAsB,CAAC,CAAC;AAE3G,MAAM,OAAO,IAAK,SAAQ,OAA8B;IAGtD,YAAY,SAAgC,EAAE;QAC5C,KAAK,CAAC,MAAM,CAAC,CAAC;QAHhB,SAAI,GAAW,MAAM,CAAC;QAIpB,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC;IACrC,CAAC;IAQD,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;IACO,QAAQ;QACd,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,OAAO,IAAI,CAAC;SACb;QACD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5C,IAAI,QA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,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC","file":"line.js","sourcesContent":["import type { IAABBBounds, IPointLike } from '@visactor/vutils';\nimport type { ILine, ILineGraphicAttribute } from '../interface';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { pointsInterpolation } from '../common/utils';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { LINE_NUMBER_TYPE } from './constants';\n\nconst LINE_UPDATE_TAG_KEY = ['segments', 'points', 'curveType', 'curveTension', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Line extends Graphic<ILineGraphicAttribute> implements ILine {\n type: 'line' = 'line';\n\n constructor(params: ILineGraphicAttribute = {}) {\n super(params);\n this.numberType = LINE_NUMBER_TYPE;\n }\n\n static NOWORK_ANIMATE_ATTR = {\n segments: 1,\n curveType: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n if (this.pathProxy) {\n return true;\n }\n const { points, segments } = this.attribute;\n if (segments) {\n if (segments.length === 0) {\n return false;\n }\n return true;\n } else if (points) {\n if (points.length <= 1) {\n return false;\n }\n return true;\n }\n return false;\n }\n\n protected _interpolate(key: string, ratio: number, lastStepVal: any, nextStepVal: any, nextAttributes: any): void {\n if (key === 'points') {\n (nextAttributes as any).points = pointsInterpolation(lastStepVal, nextStepVal, ratio);\n }\n }\n\n getGraphicTheme(): Required<ILineGraphicAttribute> {\n return getTheme(this).line;\n }\n\n protected updateAABBBounds(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n attribute.segments\n ? this.updateLineAABBBoundsBySegments(attribute, lineTheme, aabbBounds)\n : this.updateLineAABBBoundsByPoints(attribute, lineTheme, aabbBounds);\n }\n\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n const { lineJoin = lineTheme.lineJoin } = attribute;\n application.graphicService.transformAABBBounds(attribute, aabbBounds, lineTheme, lineJoin === 'miter', this);\n return aabbBounds;\n }\n\n protected updateLineAABBBoundsByPoints(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: ILine\n ): IAABBBounds {\n const { points = lineTheme.points, connectedType } = attribute;\n const b = aabbBounds;\n points.forEach(p => {\n if (p.defined !== false || connectedType === 'connect') {\n b.add(p.x, p.y);\n }\n });\n return b;\n }\n protected updateLineAABBBoundsBySegments(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: ILine\n ): IAABBBounds {\n const { segments = lineTheme.segments, connectedType } = attribute;\n const b = aabbBounds;\n segments.forEach(s => {\n s.points.forEach(p => {\n if (p.defined !== false || connectedType === 'connect') {\n b.add(p.x, p.y);\n }\n });\n });\n return b;\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, LINE_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, LINE_UPDATE_TAG_KEY);\n }\n\n toCustomPath() {\n const attribute = this.attribute;\n const path = new CustomPath2D();\n const segments = attribute.segments;\n\n const parsePoints = (points: IPointLike[]) => {\n if (points && points.length) {\n let isFirst = true;\n points.forEach(point => {\n if (point.defined === false) {\n return;\n }\n if (isFirst) {\n path.moveTo(point.x, point.y);\n } else {\n path.lineTo(point.x, point.y);\n }\n\n isFirst = false;\n });\n }\n };\n\n if (segments && segments.length) {\n segments.forEach(seg => {\n parsePoints(seg.points);\n });\n } else if (attribute.points) {\n parsePoints(attribute.points);\n }\n\n return path;\n }\n\n clone() {\n return new Line({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Line.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createLine(attributes: ILineGraphicAttribute): ILine {\n return new Line(attributes);\n}\n\n// addAttributeToPrototype(DefaultLineStyle, Line, PURE_STYLE_KEY);\n"]}
1
+ {"version":3,"sources":["../src/graphic/line.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,mBAAmB,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,sBAAsB,CAAC,CAAC;AAE3G,MAAM,OAAO,IAAK,SAAQ,OAA8B;IAGtD,YAAY,SAAgC,EAAE;QAC5C,KAAK,CAAC,MAAM,CAAC,CAAC;QAHhB,SAAI,GAAW,MAAM,CAAC;QAIpB,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC;IACrC,CAAC;IAQD,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;IACO,QAAQ;QACd,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,OAAO,IAAI,CAAC;SACb;QACD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5C,IAAI,QAAQ,EAAE;YACZ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;gBACzB,OAAO,KAAK,CAAC;aACd;YACD,OAAO,IAAI,CAAC;SACb;aAAM,IAAI,MAAM,EAAE;YACjB,IAAI,MAAM,CAAC,MAAM,IAAI,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AAI,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC","file":"line.js","sourcesContent":["import type { IAABBBounds, IPointLike } from '@visactor/vutils';\nimport type { ILine, ILineGraphicAttribute } from '../interface';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { pointsInterpolation } from '../common/utils';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { LINE_NUMBER_TYPE } from './constants';\n\nconst LINE_UPDATE_TAG_KEY = ['segments', 'points', 'curveType', 'curveTension', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Line extends Graphic<ILineGraphicAttribute> implements ILine {\n type: 'line' = 'line';\n\n constructor(params: ILineGraphicAttribute = {}) {\n super(params);\n this.numberType = LINE_NUMBER_TYPE;\n }\n\n static NOWORK_ANIMATE_ATTR = {\n segments: 1,\n curveType: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n if (this.pathProxy) {\n return true;\n }\n const { points, segments } = this.attribute;\n if (segments) {\n if (segments.length === 0) {\n return false;\n }\n return true;\n } else if (points) {\n if (points.length <= 1) {\n return false;\n }\n return true;\n }\n return false;\n }\n\n protected _interpolate(key: string, ratio: number, lastStepVal: any, nextStepVal: any, nextAttributes: any): void {\n if (key === 'points') {\n (nextAttributes as any).points = pointsInterpolation(lastStepVal, nextStepVal, ratio);\n }\n }\n\n getGraphicTheme(): Required<ILineGraphicAttribute> {\n return getTheme(this).line;\n }\n\n protected updateAABBBounds(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n attribute.segments\n ? this.updateLineAABBBoundsBySegments(attribute, lineTheme, aabbBounds)\n : this.updateLineAABBBoundsByPoints(attribute, lineTheme, aabbBounds);\n }\n\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1;\n this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1;\n\n const { lineJoin = lineTheme.lineJoin } = attribute;\n application.graphicService.transformAABBBounds(attribute, aabbBounds, lineTheme, lineJoin === 'miter', this);\n return aabbBounds;\n }\n\n protected updateLineAABBBoundsByPoints(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: ILine\n ): IAABBBounds {\n const { points = lineTheme.points, connectedType } = attribute;\n const b = aabbBounds;\n points.forEach(p => {\n if (p.defined !== false || connectedType === 'connect') {\n b.add(p.x, p.y);\n }\n });\n return b;\n }\n protected updateLineAABBBoundsBySegments(\n attribute: ILineGraphicAttribute,\n lineTheme: Required<ILineGraphicAttribute>,\n aabbBounds: IAABBBounds,\n graphic?: ILine\n ): IAABBBounds {\n const { segments = lineTheme.segments, connectedType } = attribute;\n const b = aabbBounds;\n segments.forEach(s => {\n s.points.forEach(p => {\n if (p.defined !== false || connectedType === 'connect') {\n b.add(p.x, p.y);\n }\n });\n });\n return b;\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, LINE_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, LINE_UPDATE_TAG_KEY);\n }\n\n toCustomPath() {\n const attribute = this.attribute;\n const path = new CustomPath2D();\n const segments = attribute.segments;\n\n const parsePoints = (points: IPointLike[]) => {\n if (points && points.length) {\n let isFirst = true;\n points.forEach(point => {\n if (point.defined === false) {\n return;\n }\n if (isFirst) {\n path.moveTo(point.x, point.y);\n } else {\n path.lineTo(point.x, point.y);\n }\n\n isFirst = false;\n });\n }\n };\n\n if (segments && segments.length) {\n segments.forEach(seg => {\n parsePoints(seg.points);\n });\n } else if (attribute.points) {\n parsePoints(attribute.points);\n }\n\n return path;\n }\n\n clone() {\n return new Line({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Line.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createLine(attributes: ILineGraphicAttribute): ILine {\n return new Line(attributes);\n}\n\n// addAttributeToPrototype(DefaultLineStyle, Line, PURE_STYLE_KEY);\n"]}
@@ -45,7 +45,8 @@ export class Path extends Graphic {
45
45
  }
46
46
  const {tb1: tb1, tb2: tb2} = application.graphicService.updateTempAABBBounds(aabbBounds);
47
47
  updateBoundsOfCommonOuterBorder(attribute, pathTheme, tb1), aabbBounds.union(tb1),
48
- tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);
48
+ tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2), this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1,
49
+ this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1;
49
50
  const {lineJoin: lineJoin = pathTheme.lineJoin} = attribute;
50
51
  return application.graphicService.transformAABBBounds(attribute, aabbBounds, pathTheme, "miter" === lineJoin, this),
51
52
  aabbBounds;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/path.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAE9F,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,sBAAsB,CAAC,CAAC;AAE9E,MAAM,OAAO,IAAK,SAAQ,OAA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AC;SACxC;IACH,CAAC;IAES,cAAc,CAAC,IAAc;QACrC,OAAO,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IACzD,CAAC;IACS,aAAa,CAAC,GAAW;QACjC,OAAO,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IACvD,CAAC;IAED,YAAY;QACV,MAAM,CAAC,GAAG,CAAC,CAAC;QACZ,MAAM,CAAC,GAAG,CAAC,CAAC;QAEZ,OAAO,IAAI,YAAY,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK;QACH,OAAO,IAAI,IAAI,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IACzC,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AAvGM,wBAAmB,mBACxB,IAAI,EAAE,CAAC,EACP,UAAU,EAAE,CAAC,IACV,mBAAmB,EACtB;AAsGJ,MAAM,UAAU,UAAU,CAAC,UAAiC;IAC1D,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC","file":"path.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport { isString, isNil } from '@visactor/vutils';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport type { ICustomPath2D, IPath, IPathGraphicAttribute } from '../interface';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { PATH_NUMBER_TYPE } from './constants';\nimport { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds';\n\nconst PATH_UPDATE_TAG_KEY = ['path', 'customPath', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Path extends Graphic<IPathGraphicAttribute> implements IPath {\n type: 'path' = 'path';\n cache?: ICustomPath2D;\n\n static NOWORK_ANIMATE_ATTR = {\n path: 1,\n customPath: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n constructor(params: IPathGraphicAttribute) {\n super(params);\n this.numberType = PATH_NUMBER_TYPE;\n }\n\n get pathShape(): ICustomPath2D {\n this.tryUpdateAABBBounds();\n return this.getParsedPathShape();\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n const { path } = this.attribute;\n return path != null && path !== '';\n }\n\n getParsedPathShape(): CustomPath2D {\n const pathTheme = this.getGraphicTheme();\n if (!this.valid) {\n return pathTheme.path as CustomPath2D;\n }\n const attribute = this.attribute;\n if (attribute.path instanceof CustomPath2D) {\n return attribute.path;\n }\n\n if (isNil(this.cache)) {\n this.doUpdatePathShape();\n }\n\n if (this.cache instanceof CustomPath2D) {\n return this.cache;\n }\n return pathTheme.path as CustomPath2D;\n }\n\n getGraphicTheme(): Required<IPathGraphicAttribute> {\n return getTheme(this).path;\n }\n\n protected updateAABBBounds(\n attribute: IPathGraphicAttribute,\n pathTheme: Required<IPathGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n const pathShape = this.getParsedPathShape();\n aabbBounds.union(pathShape.getBounds());\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfCommonOuterBorder(attribute, pathTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n const { lineJoin = pathTheme.lineJoin } = attribute;\n application.graphicService.transformAABBBounds(attribute, aabbBounds, pathTheme, lineJoin === 'miter', this);\n return aabbBounds;\n }\n\n protected doUpdateAABBBounds(full?: boolean) {\n this.doUpdatePathShape();\n return super.doUpdateAABBBounds(full);\n }\n\n protected doUpdatePathShape() {\n const attribute = this.attribute;\n if (isString(attribute.path, true)) {\n this.cache = new CustomPath2D().fromString(attribute.path as string);\n } else if (attribute.customPath) {\n this.cache = new CustomPath2D();\n attribute.customPath(this.cache, this);\n }\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, PATH_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, PATH_UPDATE_TAG_KEY);\n }\n\n toCustomPath() {\n const x = 0;\n const y = 0;\n\n return new CustomPath2D().fromCustomPath2D(this.getParsedPathShape(), x, y);\n }\n\n clone() {\n return new Path({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Path.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createPath(attributes: IPathGraphicAttribute): IPath {\n return new Path(attributes);\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/path.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAE9F,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,sBAAsB,CAAC,CAAC;AAE9E,MAAM,OAAO,IAAK,SAAQ,OAA8B;IAUtD,YAAY,MAA6B;QACvC,KAAK,CAAC,MAAM,CAAC,CAAC;QAVhB,SAAI,GAAW,MAAM,CAAC;QAWpB,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC;IACrC,CAAC;IAED,IAAI,SAAS;QACX,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,OAAO,IAA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AAK,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IACzD,CAAC;IACS,aAAa,CAAC,GAAW;QACjC,OAAO,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IACvD,CAAC;IAED,YAAY;QACV,MAAM,CAAC,GAAG,CAAC,CAAC;QACZ,MAAM,CAAC,GAAG,CAAC,CAAC;QAEZ,OAAO,IAAI,YAAY,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK;QACH,OAAO,IAAI,IAAI,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IACzC,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AA3GM,wBAAmB,mBACxB,IAAI,EAAE,CAAC,EACP,UAAU,EAAE,CAAC,IACV,mBAAmB,EACtB;AA0GJ,MAAM,UAAU,UAAU,CAAC,UAAiC;IAC1D,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC","file":"path.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport { isString, isNil } from '@visactor/vutils';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport type { ICustomPath2D, IPath, IPathGraphicAttribute } from '../interface';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { PATH_NUMBER_TYPE } from './constants';\nimport { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds';\n\nconst PATH_UPDATE_TAG_KEY = ['path', 'customPath', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Path extends Graphic<IPathGraphicAttribute> implements IPath {\n type: 'path' = 'path';\n cache?: ICustomPath2D;\n\n static NOWORK_ANIMATE_ATTR = {\n path: 1,\n customPath: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n constructor(params: IPathGraphicAttribute) {\n super(params);\n this.numberType = PATH_NUMBER_TYPE;\n }\n\n get pathShape(): ICustomPath2D {\n this.tryUpdateAABBBounds();\n return this.getParsedPathShape();\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n const { path } = this.attribute;\n return path != null && path !== '';\n }\n\n getParsedPathShape(): CustomPath2D {\n const pathTheme = this.getGraphicTheme();\n if (!this.valid) {\n return pathTheme.path as CustomPath2D;\n }\n const attribute = this.attribute;\n if (attribute.path instanceof CustomPath2D) {\n return attribute.path;\n }\n\n if (isNil(this.cache)) {\n this.doUpdatePathShape();\n }\n\n if (this.cache instanceof CustomPath2D) {\n return this.cache;\n }\n return pathTheme.path as CustomPath2D;\n }\n\n getGraphicTheme(): Required<IPathGraphicAttribute> {\n return getTheme(this).path;\n }\n\n protected updateAABBBounds(\n attribute: IPathGraphicAttribute,\n pathTheme: Required<IPathGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n const pathShape = this.getParsedPathShape();\n aabbBounds.union(pathShape.getBounds());\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfCommonOuterBorder(attribute, pathTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n\n this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1;\n this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1;\n\n const { lineJoin = pathTheme.lineJoin } = attribute;\n application.graphicService.transformAABBBounds(attribute, aabbBounds, pathTheme, lineJoin === 'miter', this);\n return aabbBounds;\n }\n\n protected doUpdateAABBBounds(full?: boolean) {\n this.doUpdatePathShape();\n return super.doUpdateAABBBounds(full);\n }\n\n protected doUpdatePathShape() {\n const attribute = this.attribute;\n if (isString(attribute.path, true)) {\n this.cache = new CustomPath2D().fromString(attribute.path as string);\n } else if (attribute.customPath) {\n this.cache = new CustomPath2D();\n attribute.customPath(this.cache, this);\n }\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, PATH_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, PATH_UPDATE_TAG_KEY);\n }\n\n toCustomPath() {\n const x = 0;\n const y = 0;\n\n return new CustomPath2D().fromCustomPath2D(this.getParsedPathShape(), x, y);\n }\n\n clone() {\n return new Path({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Path.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createPath(attributes: IPathGraphicAttribute): IPath {\n return new Path(attributes);\n}\n"]}
@@ -28,7 +28,8 @@ export class Polygon extends Graphic {
28
28
  }
29
29
  updateAABBBounds(attribute, polygonTheme, aabbBounds) {
30
30
  this.updatePathProxyAABBBounds(aabbBounds) || this.updatePolygonAABBBoundsImprecise(attribute, polygonTheme, aabbBounds),
31
- application.graphicService.updateTempAABBBounds(aabbBounds);
31
+ application.graphicService.updateTempAABBBounds(aabbBounds), this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1,
32
+ this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1;
32
33
  const {lineJoin: lineJoin = polygonTheme.lineJoin} = attribute;
33
34
  return application.graphicService.transformAABBBounds(attribute, aabbBounds, polygonTheme, "miter" === lineJoin, this),
34
35
  aabbBounds;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/polygon.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAA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mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IAC5C,CAAC;IAED,oBAAoB;QAClB,OAAO,OAAO,CAAC,mBAAmB,CAAC;IACrC,CAAC;;AAlFM,2BAAmB,GAAG,mBAAmB,CAAC;AAqFnD,MAAM,UAAU,aAAa,CAAC,UAAoC;IAChE,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;AACjC,CAAC","file":"polygon.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport type { IPolygon, IPolygonGraphicAttribute } from '../interface/graphic/polygon';\nimport { getTheme } from './theme';\nimport { pointsInterpolation } from '../common/utils';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { application } from '../application';\nimport type { GraphicType } from '../interface';\nimport { POLYGON_NUMBER_TYPE } from './constants';\n\nconst POLYGON_UPDATE_TAG_KEY = ['points', 'cornerRadius', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Polygon extends Graphic<IPolygonGraphicAttribute> implements IPolygon {\n type: GraphicType = 'polygon';\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IPolygonGraphicAttribute) {\n super(params);\n this.numberType = POLYGON_NUMBER_TYPE;\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n protected _isValid(): boolean {\n const { points } = this.attribute;\n return points && points.length >= 2;\n }\n\n getGraphicTheme(): Required<IPolygonGraphicAttribute> {\n return getTheme(this).polygon;\n }\n\n protected updateAABBBounds(\n attribute: IPolygonGraphicAttribute,\n polygonTheme: Required<IPolygonGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n this.updatePolygonAABBBoundsImprecise(attribute, polygonTheme, aabbBounds);\n }\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n const { lineJoin = polygonTheme.lineJoin } = attribute;\n application.graphicService.transformAABBBounds(attribute, aabbBounds, polygonTheme, lineJoin === 'miter', this);\n return aabbBounds;\n }\n\n protected updatePolygonAABBBoundsImprecise(\n attribute: IPolygonGraphicAttribute,\n polygonTheme: Required<IPolygonGraphicAttribute>,\n aabbBounds: IAABBBounds\n ): IAABBBounds {\n const { points = polygonTheme.points } = attribute;\n points.forEach(p => {\n aabbBounds.add(p.x, p.y);\n });\n\n return aabbBounds;\n }\n\n protected _interpolate(key: string, ratio: number, lastStepVal: any, nextStepVal: any, nextAttributes: any): void {\n if (key === 'points') {\n (nextAttributes as any).points = pointsInterpolation(lastStepVal, nextStepVal, ratio);\n }\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, POLYGON_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, POLYGON_UPDATE_TAG_KEY);\n }\n\n toCustomPath() {\n const points = this.attribute.points;\n const path = new CustomPath2D();\n\n points.forEach((point, index) => {\n if (index === 0) {\n path.moveTo(point.x, point.y);\n } else {\n path.lineTo(point.x, point.y);\n }\n });\n path.closePath();\n\n return path;\n }\n\n clone() {\n return new Polygon({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Polygon.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createPolygon(attributes: IPolygonGraphicAttribute): IPolygon {\n return new Polygon(attributes);\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/polygon.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,mBAA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AAI,CAAC,SAAS,EAAE,CAAC;QAEjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,OAAO,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IAC5C,CAAC;IAED,oBAAoB;QAClB,OAAO,OAAO,CAAC,mBAAmB,CAAC;IACrC,CAAC;;AArFM,2BAAmB,GAAG,mBAAmB,CAAC;AAwFnD,MAAM,UAAU,aAAa,CAAC,UAAoC;IAChE,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;AACjC,CAAC","file":"polygon.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport type { IPolygon, IPolygonGraphicAttribute } from '../interface/graphic/polygon';\nimport { getTheme } from './theme';\nimport { pointsInterpolation } from '../common/utils';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { application } from '../application';\nimport type { GraphicType } from '../interface';\nimport { POLYGON_NUMBER_TYPE } from './constants';\n\nconst POLYGON_UPDATE_TAG_KEY = ['points', 'cornerRadius', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Polygon extends Graphic<IPolygonGraphicAttribute> implements IPolygon {\n type: GraphicType = 'polygon';\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IPolygonGraphicAttribute) {\n super(params);\n this.numberType = POLYGON_NUMBER_TYPE;\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n protected _isValid(): boolean {\n const { points } = this.attribute;\n return points && points.length >= 2;\n }\n\n getGraphicTheme(): Required<IPolygonGraphicAttribute> {\n return getTheme(this).polygon;\n }\n\n protected updateAABBBounds(\n attribute: IPolygonGraphicAttribute,\n polygonTheme: Required<IPolygonGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n this.updatePolygonAABBBoundsImprecise(attribute, polygonTheme, aabbBounds);\n }\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1;\n this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1;\n\n const { lineJoin = polygonTheme.lineJoin } = attribute;\n application.graphicService.transformAABBBounds(attribute, aabbBounds, polygonTheme, lineJoin === 'miter', this);\n return aabbBounds;\n }\n\n protected updatePolygonAABBBoundsImprecise(\n attribute: IPolygonGraphicAttribute,\n polygonTheme: Required<IPolygonGraphicAttribute>,\n aabbBounds: IAABBBounds\n ): IAABBBounds {\n const { points = polygonTheme.points } = attribute;\n points.forEach(p => {\n aabbBounds.add(p.x, p.y);\n });\n\n return aabbBounds;\n }\n\n protected _interpolate(key: string, ratio: number, lastStepVal: any, nextStepVal: any, nextAttributes: any): void {\n if (key === 'points') {\n (nextAttributes as any).points = pointsInterpolation(lastStepVal, nextStepVal, ratio);\n }\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, POLYGON_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, POLYGON_UPDATE_TAG_KEY);\n }\n\n toCustomPath() {\n const points = this.attribute.points;\n const path = new CustomPath2D();\n\n points.forEach((point, index) => {\n if (index === 0) {\n path.moveTo(point.x, point.y);\n } else {\n path.lineTo(point.x, point.y);\n }\n });\n path.closePath();\n\n return path;\n }\n\n clone() {\n return new Polygon({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Polygon.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createPolygon(attributes: IPolygonGraphicAttribute): IPolygon {\n return new Polygon(attributes);\n}\n"]}
@@ -36,7 +36,8 @@ export class Rect extends Graphic {
36
36
  }
37
37
  const {tb1: tb1, tb2: tb2} = application.graphicService.updateTempAABBBounds(aabbBounds);
38
38
  return updateBoundsOfCommonOuterBorder(attribute, rectTheme, tb1), aabbBounds.union(tb1),
39
- tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2), application.graphicService.transformAABBBounds(attribute, aabbBounds, rectTheme, !1, this),
39
+ tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2), this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1,
40
+ this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1, application.graphicService.transformAABBBounds(attribute, aabbBounds, rectTheme, !1, this),
40
41
  aabbBounds;
41
42
  }
42
43
  needUpdateTags(keys) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/rect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAE9F,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,sBAAsB,CAAC,CAAC;AAEvG,MAAM,OAAO,IAAK,SAAQ,OAA8B;IAKtD,YAAY,MAA6B;QACvC,KAAK,CAAC,MAAM,CAAC,CAAC;QALhB,SAAI,GAAgB,MAAM,CAAC;QAMzB,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC;IACrC,CAAC;IAED,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;IACO,QAAQ;QACd,OAAO,IAAI,CAAC;IAId,CAAC;IAED,eAAe;QACb,OA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,CAAC;IAES,cAAc,CAAC,IAAc;QACrC,OAAO,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IACzD,CAAC;IACS,aAAa,CAAC,GAAW;QACjC,OAAO,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IACvD,CAAC;IAED,YAAY;QAEV,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAEnE,MAAM,IAAI,GAAG,IAAI,YAAY,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAE/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,IAAI,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IACzC,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AAvEM,wBAAmB,GAAG,mBAAmB,CAAC;AA0EnD,MAAM,UAAU,UAAU,CAAC,UAAiC;IAC1D,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC","file":"rect.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport type { GraphicType, ICustomPath2D, IRect, IRectGraphicAttribute } from '../interface';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { RECT_NUMBER_TYPE } from './constants';\nimport { normalizeRectAttributes } from '../common/rect-utils';\nimport { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds';\n\nconst RECT_UPDATE_TAG_KEY = ['width', 'x1', 'y1', 'height', 'cornerRadius', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Rect extends Graphic<IRectGraphicAttribute> implements IRect {\n type: GraphicType = 'rect';\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IRectGraphicAttribute) {\n super(params);\n this.numberType = RECT_NUMBER_TYPE;\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n return true;\n // 暂时不判断,理论上认为都是合法的,节省性能耗时\n // const { width, x1, y1, height } = this.attribute;\n // return (this._validNumber(width) || this._validNumber(x1)) && (this._validNumber(height) || this._validNumber(y1));\n }\n\n getGraphicTheme(): Required<IRectGraphicAttribute> {\n return getTheme(this).rect;\n }\n\n protected updateAABBBounds(\n attribute: IRectGraphicAttribute,\n rectTheme: Required<IRectGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n let { width, height } = attribute;\n const { x1, y1, x, y } = attribute;\n width = width ?? x1 - x;\n height = height ?? y1 - y;\n if (isFinite(width) || isFinite(height) || isFinite(x) || isFinite(y)) {\n aabbBounds.set(0, 0, width || 0, height || 0);\n }\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfCommonOuterBorder(attribute, rectTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, rectTheme, false, this);\n return aabbBounds;\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, RECT_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, RECT_UPDATE_TAG_KEY);\n }\n\n toCustomPath(): ICustomPath2D {\n // throw new Error('暂不支持');\n const attribute = this.attribute;\n const { x, y, width, height } = normalizeRectAttributes(attribute);\n\n const path = new CustomPath2D();\n path.moveTo(x, y);\n path.rect(x, y, width, height);\n\n return path;\n }\n\n clone() {\n return new Rect({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Rect.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createRect(attributes: IRectGraphicAttribute): IRect {\n return new Rect(attributes);\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/rect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAE9F,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,sBAAsB,CAAC,CAAC;AAEvG,MAAM,OAAO,IAAK,SAAQ,OAA8B;IAKtD,YAAY,MAA6B;QACvC,KAAK,CAAC,MAAM,CAAC,CAAC;QALhB,SAAI,GAAgB,MAAM,CAAC;QAMzB,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC;IACrC,CAAC;IAED,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;IACO,QAAQ;QACd,OAAO,IAAI,CAAC;IAId,CAAC;IAED,eAAe;QACb,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;IAC7B,CAAC;IAES,gBAAgB,CACxB,SA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AU,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAC9F,OAAO,UAAU,CAAC;IACpB,CAAC;IAES,cAAc,CAAC,IAAc;QACrC,OAAO,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IACzD,CAAC;IACS,aAAa,CAAC,GAAW;QACjC,OAAO,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IACvD,CAAC;IAED,YAAY;QAEV,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAEnE,MAAM,IAAI,GAAG,IAAI,YAAY,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAE/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,IAAI,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IACzC,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AA1EM,wBAAmB,GAAG,mBAAmB,CAAC;AA6EnD,MAAM,UAAU,UAAU,CAAC,UAAiC;IAC1D,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC","file":"rect.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport type { GraphicType, ICustomPath2D, IRect, IRectGraphicAttribute } from '../interface';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { RECT_NUMBER_TYPE } from './constants';\nimport { normalizeRectAttributes } from '../common/rect-utils';\nimport { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds';\n\nconst RECT_UPDATE_TAG_KEY = ['width', 'x1', 'y1', 'height', 'cornerRadius', ...GRAPHIC_UPDATE_TAG_KEY];\n\nexport class Rect extends Graphic<IRectGraphicAttribute> implements IRect {\n type: GraphicType = 'rect';\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IRectGraphicAttribute) {\n super(params);\n this.numberType = RECT_NUMBER_TYPE;\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n return true;\n // 暂时不判断,理论上认为都是合法的,节省性能耗时\n // const { width, x1, y1, height } = this.attribute;\n // return (this._validNumber(width) || this._validNumber(x1)) && (this._validNumber(height) || this._validNumber(y1));\n }\n\n getGraphicTheme(): Required<IRectGraphicAttribute> {\n return getTheme(this).rect;\n }\n\n protected updateAABBBounds(\n attribute: IRectGraphicAttribute,\n rectTheme: Required<IRectGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n let { width, height } = attribute;\n const { x1, y1, x, y } = attribute;\n width = width ?? x1 - x;\n height = height ?? y1 - y;\n if (isFinite(width) || isFinite(height) || isFinite(x) || isFinite(y)) {\n aabbBounds.set(0, 0, width || 0, height || 0);\n }\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfCommonOuterBorder(attribute, rectTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n\n this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1;\n this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1;\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, rectTheme, false, this);\n return aabbBounds;\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, RECT_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, RECT_UPDATE_TAG_KEY);\n }\n\n toCustomPath(): ICustomPath2D {\n // throw new Error('暂不支持');\n const attribute = this.attribute;\n const { x, y, width, height } = normalizeRectAttributes(attribute);\n\n const path = new CustomPath2D();\n path.moveTo(x, y);\n path.rect(x, y, width, height);\n\n return path;\n }\n\n clone() {\n return new Rect({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Rect.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createRect(attributes: IRectGraphicAttribute): IRect {\n return new Rect(attributes);\n}\n"]}
@@ -23,6 +23,9 @@ export default class Paragraph {
23
23
  ellipsisOtherParagraphWidth: number;
24
24
  verticalEllipsis?: boolean;
25
25
  overflow?: boolean;
26
+ space?: number;
27
+ dx?: number;
28
+ dy?: number;
26
29
  constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter, ascentDescentMode?: 'actual' | 'font');
27
30
  updateWidth(): void;
28
31
  drawBackground(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): {
@@ -14,6 +14,7 @@ function getFixedLRTB(left, right, top, bottom) {
14
14
 
15
15
  export default class Paragraph {
16
16
  constructor(text, newLine, character, ascentDescentMode) {
17
+ var _a, _b;
17
18
  this.fontSize = character.fontSize || 16, this.textBaseline = character.textBaseline || "alphabetic",
18
19
  this.ascentDescentMode = ascentDescentMode;
19
20
  const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);
@@ -28,9 +29,11 @@ export default class Paragraph {
28
29
  this.descent = this.height / 2) : (this.ascent = ascent + deltaAscent, this.descent = descent + deltaDescent),
29
30
  this.length = text.length, this.width = width || 0, this.text = text || "", this.newLine = newLine || !1,
30
31
  this.character = character, this.left = 0, this.top = 0, this.ellipsis = "normal",
31
- this.ellipsisWidth = 0, this.ellipsisOtherParagraphWidth = 0, "vertical" === character.direction && (this.direction = character.direction,
32
- this.widthOrigin = this.width, this.heightOrigin = this.height, this.width = this.heightOrigin,
33
- this.height = this.widthOrigin, this.lineHeight = this.height), this.ellipsisStr = "...";
32
+ this.ellipsisWidth = 0, this.ellipsisOtherParagraphWidth = 0, this.space = character.space,
33
+ this.dx = null !== (_a = character.dx) && void 0 !== _a ? _a : 0, this.dy = null !== (_b = character.dy) && void 0 !== _b ? _b : 0,
34
+ "vertical" === character.direction && (this.direction = character.direction, this.widthOrigin = this.width,
35
+ this.heightOrigin = this.height, this.width = this.heightOrigin, this.height = this.widthOrigin,
36
+ this.lineHeight = this.height), this.ellipsisStr = "...";
34
37
  }
35
38
  updateWidth() {
36
39
  const {width: width} = measureTextCanvas(this.text, this.character, this.ascentDescentMode);
@@ -46,9 +49,9 @@ export default class Paragraph {
46
49
  if ("hide" === this.ellipsis) return;
47
50
  if ("add" === this.ellipsis) text += this.ellipsisStr, "right" !== textAlign && "end" !== textAlign || (left -= this.ellipsisWidth); else if ("replace" === this.ellipsis) {
48
51
  const index = getStrByWithCanvas(text, ("vertical" === direction ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.character, text.length - 1);
49
- if (text = text.slice(0, index), text += this.ellipsisStr, "right" === textAlign || "end" === textAlign) {
52
+ if (text = text.slice(0, index), text += this.ellipsisStr, "right" === textAlign || "end" === textAlign) if ("vertical" === direction) ; else {
50
53
  const {width: width} = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);
51
- "vertical" === direction || (left -= this.ellipsisWidth - width);
54
+ left -= this.ellipsisWidth - width;
52
55
  }
53
56
  }
54
57
  }
@@ -59,16 +62,17 @@ export default class Paragraph {
59
62
  });
60
63
  }
61
64
  draw(ctx, top, ascent, deltaLeft, isLineFirst, textAlign, lineHeight) {
62
- let baseline = top + ascent, text = this.text, left = this.left + deltaLeft;
65
+ var _a;
66
+ let baseline = top + ascent, text = this.text, left = this.left + deltaLeft + (null !== (_a = this.space) && void 0 !== _a ? _a : 0) / 2;
63
67
  baseline += this.top;
64
68
  let direction = this.direction;
65
69
  if (this.verticalEllipsis) text = this.ellipsisStr, direction = "vertical", baseline -= this.ellipsisWidth / 2; else {
66
70
  if ("hide" === this.ellipsis) return;
67
71
  if ("add" === this.ellipsis) text += this.ellipsisStr, "right" !== textAlign && "end" !== textAlign || (left -= this.ellipsisWidth); else if ("replace" === this.ellipsis) {
68
72
  const index = getStrByWithCanvas(text, ("vertical" === direction ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.character, text.length - 1);
69
- if (text = text.slice(0, index), text += this.ellipsisStr, "right" === textAlign || "end" === textAlign) {
73
+ if (text = text.slice(0, index), text += this.ellipsisStr, "right" === textAlign || "end" === textAlign) if ("vertical" === direction) ; else {
70
74
  const {width: width} = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);
71
- "vertical" === direction || (left -= this.ellipsisWidth - width);
75
+ left -= this.ellipsisWidth - width;
72
76
  }
73
77
  }
74
78
  }
@@ -84,8 +88,8 @@ export default class Paragraph {
84
88
  ctx.translate(-this.heightOrigin || -this.lineHeight / 2, -this.descent / 2), ctx.translate(left, baseline),
85
89
  left = 0, baseline = 0);
86
90
  const {lineWidth: lineWidth = 1} = this.character;
87
- if (this.character.stroke && lineWidth && ctx.strokeText(text, left, baseline),
88
- this.character.fill && ctx.fillText(text, left, baseline), this.character.fill) if (this.character.lineThrough || this.character.underline) {
91
+ if (this.character.stroke && lineWidth && ctx.strokeText(text, left, baseline + this.dy),
92
+ this.character.fill && ctx.fillText(text, left, baseline + this.dy), this.character.fill) if (this.character.lineThrough || this.character.underline) {
89
93
  if (this.character.underline) {
90
94
  const top = 1 + baseline, lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1));
91
95
  ctx.fillRect(lrtb.left, 1 + baseline, lrtb.right - lrtb.left, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)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AAC,MAAM,GAAG,CAAC,CAChB,CAAC;YACF,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAC5B,IAAI,IAAI,IAAI,CAAC,WAAW,CAAC;YAEzB,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,SAAS,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"]}
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,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC;IAClD,MAAM,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,GAAG,CAAC;IAC5D,MAAM,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC;IACjE,OAAO;QACL,IAAI,EAAE,KAAK;QACX,GAAG,EAAE,IAAI;QACT,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,OAAO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AE,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 space?: number;\n dx?: number;\n dy?: number;\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 this.space = character.space;\n this.dx = character.dx ?? 0;\n this.dy = character.dy ?? 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 if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n const { width } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\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 + (this.space ?? 0) / 2;\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 if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n const { width } = measureTextCanvas(this.text.slice(index), this.character, this.ascentDescentMode);\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 + this.dy);\n }\n\n if (this.character.fill) {\n ctx.fillText(text, left, baseline + this.dy);\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"]}
@@ -103,6 +103,7 @@ export function getStrByWithDom(desc, width, style, guessIndex, needTestLetter)
103
103
  }
104
104
 
105
105
  export function getStrByWithCanvas(desc, width, character, guessIndex, needTestLetter) {
106
+ if (desc.length <= 1) return 0;
106
107
  if (!width || width <= 0) return 0;
107
108
  const textMeasure = application.graphicUtil.textMeasure;
108
109
  let index = guessIndex, temp = desc.slice(0, index), tempWidth = Math.floor(textMeasure.measureText(temp, character).width), tempNext = desc.slice(0, index + 1), tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character).width);
@@ -171,16 +172,25 @@ export function measureTextDom(text, style) {
171
172
  }
172
173
 
173
174
  export function measureTextCanvas(text, character, mode = "actual") {
175
+ var _a;
176
+ if ("" === text) return {
177
+ ascent: 0,
178
+ height: 0,
179
+ descent: 0,
180
+ width: 0
181
+ };
174
182
  const measurement = application.graphicUtil.textMeasure.measureText(text, character), result = {
175
183
  ascent: 0,
176
184
  height: 0,
177
185
  descent: 0,
178
186
  width: 0
179
187
  }, ascent = "actual" === mode ? measurement.actualBoundingBoxAscent : measurement.fontBoundingBoxAscent, descent = "actual" === mode ? measurement.actualBoundingBoxDescent : measurement.fontBoundingBoxDescent;
180
- return "number" != typeof ascent || "number" != typeof descent ? (result.width = Math.floor(measurement.width),
188
+ "number" != typeof ascent || "number" != typeof descent ? (result.width = Math.floor(measurement.width),
181
189
  result.height = character.fontSize || 0, result.ascent = result.height, result.descent = 0) : (result.width = Math.floor(measurement.width),
182
190
  result.height = Math.floor(ascent + descent), result.ascent = Math.floor(ascent),
183
- result.descent = result.height - result.ascent), result;
191
+ result.descent = result.height - result.ascent);
192
+ const space = null !== (_a = character.space) && void 0 !== _a ? _a : 0;
193
+ return result.width += space, result;
184
194
  }
185
195
 
186
196
  export function getFontString(character, ctx) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/richtext/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,UAAU,EAAE;QACV,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,CAAC,EAAE,GAAG;QACN,CAAC,EAAE,GAAG;QACN,MAAM,EAAE,QAAQ;KACjB;IACD,QAAQ,EAAE;QACR,KAAK,EAAE,QAAQ;QACf,MAAM,EAAE,OAAO;QACf,IAAI,EAAE,KAAK;QACX,GAAG,EAAE,MAAM;QACX,CAAC,EAAE,GAAG;QACN,CAAC,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C;QAC3C,GAAG;QACH,CAAC,QAAQ,IAAI,EAAE,CAAC;QAChB,KAAK;QACL,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,iBAAiB,CAAC,UAAU,CAAC,CACtE,CAAC;AACJ,CAAC","file":"utils.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { application } from '../../application';\nimport { createColor } from '../../common/canvas-utils';\nimport type { IContext2d, ITextStyleParams, IRichTextParagraphCharacter } from '../../interface';\nimport { DEFAULT_TEXT_FONT_FAMILY } from '../../constants';\n\nexport const DIRECTION_KEY = {\n horizontal: {\n width: 'width',\n height: 'height',\n left: 'left',\n top: 'top',\n x: 'x',\n y: 'y',\n bottom: 'bottom'\n },\n vertical: {\n width: 'height',\n height: 'width',\n left: 'top',\n top: 'left',\n x: 'y',\n y: 'x',\n bottom: 'right'\n }\n};\n\nconst defaultFormatting = {\n fontSize: 16,\n fontFamily: DEFAULT_TEXT_FONT_FAMILY,\n fill: true,\n stroke: false,\n fontWeight: 'normal',\n lineHeight: 'normal',\n fontStyle: 'normal', // normal, italic, oblique\n textDecoration: 'none', // none, underline, line-through\n textAlign: 'left', // left, right, center\n script: 'normal' // normal, sub, super\n};\nconst nbsp = String.fromCharCode(160);\n\nexport const regLetter = /\\w|\\(|\\)|-/;\nconst regPunctuation = /[.?!,;:/,。?!、;:]/;\nexport const regFirstSpace = /\\S/;\n\nconst setTextStyle = (ctx: IContext2d, character: IRichTextParagraphCharacter) => {\n let fontSize = character.fontSize || 16;\n switch (character.script) {\n case 'super':\n case 'sub':\n fontSize *= 0.8;\n break;\n }\n\n ctx.setTextStyle({\n textAlign: 'left',\n textBaseline: character.textBaseline || 'alphabetic',\n fontStyle: character.fontStyle || '',\n fontWeight: character.fontWeight || '',\n fontSize,\n fontFamily: character.fontFamily\n } as ITextStyleParams);\n};\n\n// Applies the style of a run to the canvas context\nexport function applyFillStyle(ctx: IContext2d, character: IRichTextParagraphCharacter, b?: IBoundsLike) {\n const fillStyle = (character && (character.fill as string)) || defaultFormatting.fill;\n if (!fillStyle) {\n ctx.globalAlpha = 0;\n return;\n }\n\n const { fillOpacity = 1, opacity = 1 } = character;\n\n ctx.globalAlpha = fillOpacity * opacity;\n ctx.fillStyle = b ? createColor(ctx, fillStyle, { AABBBounds: b }) : (fillStyle as string);\n\n setTextStyle(ctx, character);\n}\n\nexport function applyStrokeStyle(ctx: IContext2d, character: IRichTextParagraphCharacter) {\n const strokeStyle = (character && (character.stroke as string)) || (defaultFormatting.stroke as any);\n if (!strokeStyle) {\n ctx.globalAlpha = 0;\n return;\n }\n\n const { strokeOpacity = 1, opacity = 1 } = character;\n\n ctx.globalAlpha = strokeOpacity * opacity;\n ctx.lineWidth = character && typeof character.lineWidth === 'number' ? character.lineWidth : 1;\n ctx.strokeStyle = strokeStyle as string;\n\n setTextStyle(ctx, character);\n}\n\nexport function prepareContext(ctx: IContext2d) {\n ctx.setTextStyle({\n textAlign: 'left',\n textBaseline: 'bottom'\n });\n}\n\n// 确认达到availableWidth的字符串截取index\nexport function getStrByWithDom(\n desc: string,\n width: number,\n style: string,\n guessIndex: number,\n needTestLetter?: boolean\n): number {\n desc = desc.replace(/\\s/g, nbsp);\n\n // 测量用DOM\n const span = document.createElement('span');\n span.setAttribute('style', style);\n span.style.visibility = 'hidden';\n span.style.whiteSpace = 'nowrap';\n document.body.appendChild(span);\n\n // 测量从头到当前位置宽度以及从头到下一个字符位置宽度\n let index = guessIndex;\n let temp = desc.slice(0, index);\n span.innerText = temp;\n let tempWidth = span.offsetWidth;\n\n let tempNext = desc.slice(0, index + 1);\n span.innerText = tempNext;\n let tempWidthNext = span.offsetWidth;\n\n // 到当前位置宽度 < width && 到下一个字符位置宽度 > width时,认为找到准确阶段位置\n while (tempWidth > width || tempWidthNext <= width) {\n if (tempWidth > width) {\n index--;\n } else {\n index++;\n }\n\n temp = desc.slice(0, index);\n span.innerText = temp;\n tempWidth = span.offsetWidth;\n\n tempNext = desc.slice(0, index + 1);\n span.innerText = tempNext;\n tempWidthNext = span.offsetWidth;\n }\n\n // 处理特殊情况\n if (needTestLetter) {\n index = testLetter(desc, index);\n }\n\n document.body.removeChild(span);\n return index;\n}\nexport function getStrByWithCanvas(\n desc: string,\n width: number,\n character: IRichTextParagraphCharacter,\n // ctx: IContext2d,\n guessIndex: number,\n needTestLetter?: boolean\n): number {\n if (!width || width <= 0) {\n return 0;\n }\n const textMeasure = application.graphicUtil.textMeasure;\n // const measurement = textMeasure.measureText(text, character);\n\n // 测量从头到当前位置宽度以及从头到下一个字符位置宽度\n let index = guessIndex;\n let temp = desc.slice(0, index);\n let tempWidth = Math.floor(textMeasure.measureText(temp, character as any).width);\n\n let tempNext = desc.slice(0, index + 1);\n let tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character as any).width);\n\n // 到当前位置宽度 < width && 到下一个字符位置宽度 > width时,认为找到准确阶段位置\n while (tempWidth > width || tempWidthNext <= width) {\n if (tempWidth > width) {\n index--;\n } else {\n index++;\n }\n\n if (index > desc.length) {\n index = desc.length;\n break;\n } else if (index < 0) {\n index = 0;\n break;\n }\n\n temp = desc.slice(0, index);\n tempWidth = Math.floor(textMeasure.measureText(temp, character as any).width);\n\n tempNext = desc.slice(0, index + 1);\n tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character as any).width);\n }\n\n // 处理特殊情况\n if (needTestLetter) {\n index = testLetter(desc, index);\n }\n\n return index;\n}\n\nexport function getWordStartEndIdx(string: string, index: number) {\n let startIdx = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[startIdx - 1]) && regLetter.test(string[startIdx])) ||\n // 行首标点符号处理\n regPunctuation.test(string[startIdx])\n ) {\n startIdx--;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (startIdx <= 0) {\n break;\n }\n }\n\n let endIdx = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[endIdx + 1]) && regLetter.test(string[endIdx])) ||\n // 行首标点符号处理\n regPunctuation.test(string[endIdx])\n ) {\n endIdx++;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (endIdx >= string.length) {\n break;\n }\n }\n endIdx = Math.min(endIdx + 1, string.length);\n\n return {\n startIdx,\n endIdx\n };\n}\n\n/**\n * 向前找到单词结尾处换行\n * @param string\n * @param index\n * @param negativeWrongMatch 如果为true,那么如果无法匹配就会向后找到单词的结尾,否则就直接返回index\n * @returns\n */\nexport function testLetter(string: string, index: number, negativeWrongMatch: boolean = false): number {\n let i = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[i - 1]) && regLetter.test(string[i])) ||\n // 行首标点符号处理\n regPunctuation.test(string[i])\n ) {\n i--;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (i <= 0) {\n return negativeWrongMatch ? testLetter2(string, index) : index;\n }\n }\n return i;\n}\n\n/**\n * 向后找到单词结尾处换行\n * @param string\n * @param index\n * @returns\n */\nexport function testLetter2(string: string, index: number) {\n let i = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[i + 1]) && regLetter.test(string[i])) ||\n // 行首标点符号处理\n regPunctuation.test(string[i])\n ) {\n i++;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (i >= string.length) {\n return i;\n }\n }\n return i + 1;\n}\n\n// 测量文字详细信息\nexport function measureTextDom(\n text: string,\n style: string\n): { ascent?: number; height?: number; descent?: number; width?: number } {\n let div;\n\n const span = document.createElement('span');\n const block = document.createElement('div');\n div = document.createElement('div');\n\n block.style.display = 'inline-block';\n block.style.width = '1px';\n block.style.height = '0';\n\n div.style.visibility = 'hidden';\n div.style.position = 'absolute';\n div.style.top = '0';\n div.style.left = '0';\n div.style.width = '500px';\n div.style.height = '200px';\n div.style.whiteSpace = 'nowrap';\n\n div.appendChild(span);\n div.appendChild(block);\n document.body.appendChild(div);\n\n const result: { ascent?: number; height?: number; descent?: number; width?: number } = {};\n try {\n span.setAttribute('style', style);\n span.style.whiteSpace = 'nowrap';\n span.style.display = 'inline-block';\n\n span.innerHTML = '';\n span.appendChild(document.createTextNode(text.replace(/\\s/g, nbsp)));\n\n block.style.verticalAlign = 'baseline';\n result.ascent = block.offsetTop - span.offsetTop;\n block.style.verticalAlign = 'bottom';\n result.height = block.offsetTop - span.offsetTop;\n result.descent = result.height - result.ascent;\n result.width = span.offsetWidth;\n } finally {\n div.parentNode?.removeChild(div);\n div = null;\n }\n return result;\n}\n\n// 测量文字详细信息\nexport function measureTextCanvas(\n text: string,\n character: IRichTextParagraphCharacter,\n mode: 'actual' | 'font' = 'actual'\n): { ascent: number; height: number; descent: number; width: number } {\n const textMeasure = application.graphicUtil.textMeasure;\n const measurement = textMeasure.measureText(text, character as any) as TextMetrics;\n const result: { ascent: number; height: number; descent: number; width: number } = {\n ascent: 0,\n height: 0,\n descent: 0,\n width: 0\n };\n const ascent = mode === 'actual' ? measurement.actualBoundingBoxAscent : measurement.fontBoundingBoxAscent;\n const descent = mode === 'actual' ? measurement.actualBoundingBoxDescent : measurement.fontBoundingBoxDescent;\n if (typeof ascent !== 'number' || typeof descent !== 'number') {\n result.width = Math.floor(measurement.width);\n result.height = character.fontSize || 0;\n result.ascent = result.height;\n result.descent = 0;\n } else {\n result.width = Math.floor(measurement.width);\n result.height = Math.floor(ascent + descent);\n result.ascent = Math.floor(ascent);\n result.descent = result.height - result.ascent;\n }\n return result;\n}\n\nexport function getFontString(character: IRichTextParagraphCharacter, ctx: IContext2d | null) {\n let fontSize = (character && character.fontSize) || defaultFormatting.fontSize;\n\n if (character) {\n switch (character.script) {\n case 'super':\n case 'sub':\n fontSize *= 0.8;\n break;\n }\n }\n\n return (\n ((character && character.fontStyle) || '') +\n ' ' +\n ((character && character.fontWeight) || '') +\n ' ' +\n (fontSize || 12) +\n 'px ' +\n ((character && character.fontFamily) || defaultFormatting.fontFamily)\n );\n}\n"]}
1
+ {"version":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AAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACnC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;KAChD;IACD,MAAM,KAAK,GAAG,MAAA,SAAS,CAAC,KAAK,mCAAI,CAAC,CAAC;IACnC,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;IACtB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,SAAsC,EAAE,GAAsB;IAC1F,IAAI,QAAQ,GAAG,CAAC,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,iBAAiB,CAAC,QAAQ,CAAC;IAE/E,IAAI,SAAS,EAAE;QACb,QAAQ,SAAS,CAAC,MAAM,EAAE;YACxB,KAAK,OAAO,CAAC;YACb,KAAK,KAAK;gBACR,QAAQ,IAAI,GAAG,CAAC;gBAChB,MAAM;SACT;KACF;IAED,OAAO,CACL,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QAC1C,GAAG;QACH,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC3C,GAAG;QACH,CAAC,QAAQ,IAAI,EAAE,CAAC;QAChB,KAAK;QACL,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,iBAAiB,CAAC,UAAU,CAAC,CACtE,CAAC;AACJ,CAAC","file":"utils.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { application } from '../../application';\nimport { createColor } from '../../common/canvas-utils';\nimport type { IContext2d, ITextStyleParams, IRichTextParagraphCharacter } from '../../interface';\nimport { DEFAULT_TEXT_FONT_FAMILY } from '../../constants';\n\nexport const DIRECTION_KEY = {\n horizontal: {\n width: 'width',\n height: 'height',\n left: 'left',\n top: 'top',\n x: 'x',\n y: 'y',\n bottom: 'bottom'\n },\n vertical: {\n width: 'height',\n height: 'width',\n left: 'top',\n top: 'left',\n x: 'y',\n y: 'x',\n bottom: 'right'\n }\n};\n\nconst defaultFormatting = {\n fontSize: 16,\n fontFamily: DEFAULT_TEXT_FONT_FAMILY,\n fill: true,\n stroke: false,\n fontWeight: 'normal',\n lineHeight: 'normal',\n fontStyle: 'normal', // normal, italic, oblique\n textDecoration: 'none', // none, underline, line-through\n textAlign: 'left', // left, right, center\n script: 'normal' // normal, sub, super\n};\nconst nbsp = String.fromCharCode(160);\n\nexport const regLetter = /\\w|\\(|\\)|-/;\nconst regPunctuation = /[.?!,;:/,。?!、;:]/;\nexport const regFirstSpace = /\\S/;\n\nconst setTextStyle = (ctx: IContext2d, character: IRichTextParagraphCharacter) => {\n let fontSize = character.fontSize || 16;\n switch (character.script) {\n case 'super':\n case 'sub':\n fontSize *= 0.8;\n break;\n }\n\n ctx.setTextStyle({\n textAlign: 'left',\n textBaseline: character.textBaseline || 'alphabetic',\n fontStyle: character.fontStyle || '',\n fontWeight: character.fontWeight || '',\n fontSize,\n fontFamily: character.fontFamily\n } as ITextStyleParams);\n};\n\n// Applies the style of a run to the canvas context\nexport function applyFillStyle(ctx: IContext2d, character: IRichTextParagraphCharacter, b?: IBoundsLike) {\n const fillStyle = (character && (character.fill as string)) || defaultFormatting.fill;\n if (!fillStyle) {\n ctx.globalAlpha = 0;\n return;\n }\n\n const { fillOpacity = 1, opacity = 1 } = character;\n\n ctx.globalAlpha = fillOpacity * opacity;\n ctx.fillStyle = b ? createColor(ctx, fillStyle, { AABBBounds: b }) : (fillStyle as string);\n\n setTextStyle(ctx, character);\n}\n\nexport function applyStrokeStyle(ctx: IContext2d, character: IRichTextParagraphCharacter) {\n const strokeStyle = (character && (character.stroke as string)) || (defaultFormatting.stroke as any);\n if (!strokeStyle) {\n ctx.globalAlpha = 0;\n return;\n }\n\n const { strokeOpacity = 1, opacity = 1 } = character;\n\n ctx.globalAlpha = strokeOpacity * opacity;\n ctx.lineWidth = character && typeof character.lineWidth === 'number' ? character.lineWidth : 1;\n ctx.strokeStyle = strokeStyle as string;\n\n setTextStyle(ctx, character);\n}\n\nexport function prepareContext(ctx: IContext2d) {\n ctx.setTextStyle({\n textAlign: 'left',\n textBaseline: 'bottom'\n });\n}\n\n// 确认达到availableWidth的字符串截取index\nexport function getStrByWithDom(\n desc: string,\n width: number,\n style: string,\n guessIndex: number,\n needTestLetter?: boolean\n): number {\n desc = desc.replace(/\\s/g, nbsp);\n\n // 测量用DOM\n const span = document.createElement('span');\n span.setAttribute('style', style);\n span.style.visibility = 'hidden';\n span.style.whiteSpace = 'nowrap';\n document.body.appendChild(span);\n\n // 测量从头到当前位置宽度以及从头到下一个字符位置宽度\n let index = guessIndex;\n let temp = desc.slice(0, index);\n span.innerText = temp;\n let tempWidth = span.offsetWidth;\n\n let tempNext = desc.slice(0, index + 1);\n span.innerText = tempNext;\n let tempWidthNext = span.offsetWidth;\n\n // 到当前位置宽度 < width && 到下一个字符位置宽度 > width时,认为找到准确阶段位置\n while (tempWidth > width || tempWidthNext <= width) {\n if (tempWidth > width) {\n index--;\n } else {\n index++;\n }\n\n temp = desc.slice(0, index);\n span.innerText = temp;\n tempWidth = span.offsetWidth;\n\n tempNext = desc.slice(0, index + 1);\n span.innerText = tempNext;\n tempWidthNext = span.offsetWidth;\n }\n\n // 处理特殊情况\n if (needTestLetter) {\n index = testLetter(desc, index);\n }\n\n document.body.removeChild(span);\n return index;\n}\nexport function getStrByWithCanvas(\n desc: string,\n width: number,\n character: IRichTextParagraphCharacter,\n // ctx: IContext2d,\n guessIndex: number,\n needTestLetter?: boolean\n): number {\n if (desc.length <= 1) {\n return 0;\n }\n if (!width || width <= 0) {\n return 0;\n }\n const textMeasure = application.graphicUtil.textMeasure;\n // const measurement = textMeasure.measureText(text, character);\n\n // 测量从头到当前位置宽度以及从头到下一个字符位置宽度\n let index = guessIndex;\n let temp = desc.slice(0, index);\n let tempWidth = Math.floor(textMeasure.measureText(temp, character as any).width);\n\n let tempNext = desc.slice(0, index + 1);\n let tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character as any).width);\n\n // 到当前位置宽度 < width && 到下一个字符位置宽度 > width时,认为找到准确阶段位置\n while (tempWidth > width || tempWidthNext <= width) {\n if (tempWidth > width) {\n index--;\n } else {\n index++;\n }\n\n if (index > desc.length) {\n index = desc.length;\n break;\n } else if (index < 0) {\n index = 0;\n break;\n }\n\n temp = desc.slice(0, index);\n tempWidth = Math.floor(textMeasure.measureText(temp, character as any).width);\n\n tempNext = desc.slice(0, index + 1);\n tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character as any).width);\n }\n\n // 处理特殊情况\n if (needTestLetter) {\n index = testLetter(desc, index);\n }\n\n return index;\n}\n\nexport function getWordStartEndIdx(string: string, index: number) {\n let startIdx = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[startIdx - 1]) && regLetter.test(string[startIdx])) ||\n // 行首标点符号处理\n regPunctuation.test(string[startIdx])\n ) {\n startIdx--;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (startIdx <= 0) {\n break;\n }\n }\n\n let endIdx = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[endIdx + 1]) && regLetter.test(string[endIdx])) ||\n // 行首标点符号处理\n regPunctuation.test(string[endIdx])\n ) {\n endIdx++;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (endIdx >= string.length) {\n break;\n }\n }\n endIdx = Math.min(endIdx + 1, string.length);\n\n return {\n startIdx,\n endIdx\n };\n}\n\n/**\n * 向前找到单词结尾处换行\n * @param string\n * @param index\n * @param negativeWrongMatch 如果为true,那么如果无法匹配就会向后找到单词的结尾,否则就直接返回index\n * @returns\n */\nexport function testLetter(string: string, index: number, negativeWrongMatch: boolean = false): number {\n let i = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[i - 1]) && regLetter.test(string[i])) ||\n // 行首标点符号处理\n regPunctuation.test(string[i])\n ) {\n i--;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (i <= 0) {\n return negativeWrongMatch ? testLetter2(string, index) : index;\n }\n }\n return i;\n}\n\n/**\n * 向后找到单词结尾处换行\n * @param string\n * @param index\n * @returns\n */\nexport function testLetter2(string: string, index: number) {\n let i = index;\n // 切分前后都是英文字母数字下划线,向前找到非英文字母处换行\n while (\n (regLetter.test(string[i + 1]) && regLetter.test(string[i])) ||\n // 行首标点符号处理\n regPunctuation.test(string[i])\n ) {\n i++;\n // 无法满足所有条件,放弃匹配,直接截断,避免陷入死循环\n if (i >= string.length) {\n return i;\n }\n }\n return i + 1;\n}\n\n// 测量文字详细信息\nexport function measureTextDom(\n text: string,\n style: string\n): { ascent?: number; height?: number; descent?: number; width?: number } {\n let div;\n\n const span = document.createElement('span');\n const block = document.createElement('div');\n div = document.createElement('div');\n\n block.style.display = 'inline-block';\n block.style.width = '1px';\n block.style.height = '0';\n\n div.style.visibility = 'hidden';\n div.style.position = 'absolute';\n div.style.top = '0';\n div.style.left = '0';\n div.style.width = '500px';\n div.style.height = '200px';\n div.style.whiteSpace = 'nowrap';\n\n div.appendChild(span);\n div.appendChild(block);\n document.body.appendChild(div);\n\n const result: { ascent?: number; height?: number; descent?: number; width?: number } = {};\n try {\n span.setAttribute('style', style);\n span.style.whiteSpace = 'nowrap';\n span.style.display = 'inline-block';\n\n span.innerHTML = '';\n span.appendChild(document.createTextNode(text.replace(/\\s/g, nbsp)));\n\n block.style.verticalAlign = 'baseline';\n result.ascent = block.offsetTop - span.offsetTop;\n block.style.verticalAlign = 'bottom';\n result.height = block.offsetTop - span.offsetTop;\n result.descent = result.height - result.ascent;\n result.width = span.offsetWidth;\n } finally {\n div.parentNode?.removeChild(div);\n div = null;\n }\n return result;\n}\n\n// 测量文字详细信息\nexport function measureTextCanvas(\n text: string,\n character: IRichTextParagraphCharacter,\n mode: 'actual' | 'font' = 'actual'\n): { ascent: number; height: number; descent: number; width: number } {\n if (text === '') {\n return {\n ascent: 0,\n height: 0,\n descent: 0,\n width: 0\n };\n }\n const textMeasure = application.graphicUtil.textMeasure;\n const measurement = textMeasure.measureText(text, character as any) as TextMetrics;\n const result: { ascent: number; height: number; descent: number; width: number } = {\n ascent: 0,\n height: 0,\n descent: 0,\n width: 0\n };\n const ascent = mode === 'actual' ? measurement.actualBoundingBoxAscent : measurement.fontBoundingBoxAscent;\n const descent = mode === 'actual' ? measurement.actualBoundingBoxDescent : measurement.fontBoundingBoxDescent;\n if (typeof ascent !== 'number' || typeof descent !== 'number') {\n result.width = Math.floor(measurement.width);\n result.height = character.fontSize || 0;\n result.ascent = result.height;\n result.descent = 0;\n } else {\n result.width = Math.floor(measurement.width);\n result.height = Math.floor(ascent + descent);\n result.ascent = Math.floor(ascent);\n result.descent = result.height - result.ascent;\n }\n const space = character.space ?? 0;\n result.width += space;\n return result;\n}\n\nexport function getFontString(character: IRichTextParagraphCharacter, ctx: IContext2d | null) {\n let fontSize = (character && character.fontSize) || defaultFormatting.fontSize;\n\n if (character) {\n switch (character.script) {\n case 'super':\n case 'sub':\n fontSize *= 0.8;\n break;\n }\n }\n\n return (\n ((character && character.fontStyle) || '') +\n ' ' +\n ((character && character.fontWeight) || '') +\n ' ' +\n (fontSize || 12) +\n 'px ' +\n ((character && character.fontFamily) || defaultFormatting.fontFamily)\n );\n}\n"]}
@@ -95,6 +95,9 @@ export declare class RichText extends Graphic<IRichTextGraphicAttribute> impleme
95
95
  strokeOpacity: number;
96
96
  background?: string;
97
97
  backgroundOpacity?: number;
98
+ space?: number;
99
+ dx?: number;
100
+ dy?: number;
98
101
  } | {
99
102
  lineHeight?: string | number;
100
103
  textAlign?: CanvasTextAlign;