@visactor/vrender-core 0.21.11 → 0.22.0-vstory.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (376) hide show
  1. package/cjs/animate/Ticker/default-ticker.d.ts +2 -0
  2. package/cjs/animate/Ticker/default-ticker.js +7 -1
  3. package/cjs/animate/Ticker/default-ticker.js.map +1 -1
  4. package/cjs/animate/animate.js +2 -2
  5. package/cjs/animate/animate.js.map +1 -1
  6. package/cjs/animate/custom-animate.js +14 -25
  7. package/cjs/animate/custom-animate.js.map +1 -1
  8. package/cjs/animate/easing-func.d.ts +1 -0
  9. package/cjs/animate/easing-func.js +16 -0
  10. package/cjs/animate/easing-func.js.map +1 -0
  11. package/cjs/animate/easing.d.ts +4 -0
  12. package/cjs/animate/easing.js +24 -1
  13. package/cjs/animate/easing.js.map +1 -1
  14. package/cjs/animate/index.d.ts +1 -0
  15. package/cjs/animate/index.js +1 -1
  16. package/cjs/animate/index.js.map +1 -1
  17. package/cjs/color-string/store.js +1 -2
  18. package/cjs/common/3d-interceptor.js +2 -1
  19. package/cjs/common/bezier-utils.d.ts +3 -0
  20. package/cjs/common/bezier-utils.js +17 -2
  21. package/cjs/common/bezier-utils.js.map +1 -1
  22. package/cjs/common/custom-path2d.d.ts +4 -0
  23. package/cjs/common/custom-path2d.js +43 -11
  24. package/cjs/common/custom-path2d.js.map +1 -1
  25. package/cjs/common/render-area.d.ts +4 -0
  26. package/cjs/common/render-area.js +76 -17
  27. package/cjs/common/render-area.js.map +1 -1
  28. package/cjs/common/render-command-list.js +2 -1
  29. package/cjs/common/render-curve.d.ts +1 -1
  30. package/cjs/common/render-curve.js.map +1 -1
  31. package/cjs/common/segment/curve/arc.d.ts +4 -1
  32. package/cjs/common/segment/curve/arc.js +10 -1
  33. package/cjs/common/segment/curve/arc.js.map +1 -1
  34. package/cjs/common/segment/curve/base.d.ts +4 -1
  35. package/cjs/common/segment/curve/base.js.map +1 -1
  36. package/cjs/common/segment/curve/cubic-bezier.d.ts +5 -1
  37. package/cjs/common/segment/curve/cubic-bezier.js +24 -3
  38. package/cjs/common/segment/curve/cubic-bezier.js.map +1 -1
  39. package/cjs/common/segment/curve/curve-context.js +5 -4
  40. package/cjs/common/segment/curve/curve-context.js.map +1 -1
  41. package/cjs/common/segment/curve/ellipse.d.ts +4 -1
  42. package/cjs/common/segment/curve/ellipse.js +9 -0
  43. package/cjs/common/segment/curve/ellipse.js.map +1 -1
  44. package/cjs/common/segment/curve/line.d.ts +4 -1
  45. package/cjs/common/segment/curve/line.js +18 -0
  46. package/cjs/common/segment/curve/line.js.map +1 -1
  47. package/cjs/common/segment/curve/move.d.ts +4 -1
  48. package/cjs/common/segment/curve/move.js +9 -0
  49. package/cjs/common/segment/curve/move.js.map +1 -1
  50. package/cjs/common/segment/curve/path.d.ts +2 -1
  51. package/cjs/common/segment/curve/path.js +5 -2
  52. package/cjs/common/segment/curve/path.js.map +1 -1
  53. package/cjs/common/segment/curve/quadratic-bezier.d.ts +6 -2
  54. package/cjs/common/segment/curve/quadratic-bezier.js +23 -5
  55. package/cjs/common/segment/curve/quadratic-bezier.js.map +1 -1
  56. package/cjs/common/segment/step.js +1 -1
  57. package/cjs/common/segment/step.js.map +1 -1
  58. package/cjs/common/shape/rect.d.ts +1 -1
  59. package/cjs/common/shape/rect.js +30 -25
  60. package/cjs/common/shape/rect.js.map +1 -1
  61. package/cjs/common/store.js +1 -1
  62. package/cjs/core/contributions/env/base-contribution.d.ts +2 -0
  63. package/cjs/core/contributions/env/base-contribution.js +6 -0
  64. package/cjs/core/contributions/env/base-contribution.js.map +1 -1
  65. package/cjs/core/global.d.ts +2 -3
  66. package/cjs/core/global.js +7 -7
  67. package/cjs/core/global.js.map +1 -1
  68. package/cjs/graphic/builtin-symbol/rect.d.ts +2 -1
  69. package/cjs/graphic/builtin-symbol/rect.js +28 -0
  70. package/cjs/graphic/builtin-symbol/rect.js.map +1 -1
  71. package/cjs/graphic/builtin-symbol/utils.d.ts +2 -1
  72. package/cjs/graphic/builtin-symbol/utils.js +5 -0
  73. package/cjs/graphic/builtin-symbol/utils.js.map +1 -1
  74. package/cjs/graphic/config.js +20 -5
  75. package/cjs/graphic/config.js.map +1 -1
  76. package/cjs/graphic/graphic.d.ts +1 -1
  77. package/cjs/graphic/graphic.js +20 -6
  78. package/cjs/graphic/graphic.js.map +1 -1
  79. package/cjs/graphic/line.js +2 -2
  80. package/cjs/graphic/line.js.map +1 -1
  81. package/cjs/graphic/richtext/line.js +1 -1
  82. package/cjs/graphic/richtext/line.js.map +1 -1
  83. package/cjs/graphic/richtext/paragraph.d.ts +1 -1
  84. package/cjs/graphic/richtext/paragraph.js +37 -7
  85. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  86. package/cjs/graphic/richtext/utils.d.ts +4 -0
  87. package/cjs/graphic/richtext/utils.js +19 -6
  88. package/cjs/graphic/richtext/utils.js.map +1 -1
  89. package/cjs/graphic/richtext/wrapper.d.ts +1 -0
  90. package/cjs/graphic/richtext/wrapper.js +1 -1
  91. package/cjs/graphic/richtext/wrapper.js.map +1 -1
  92. package/cjs/graphic/richtext.d.ts +7 -2
  93. package/cjs/graphic/richtext.js +37 -4
  94. package/cjs/graphic/richtext.js.map +1 -1
  95. package/cjs/index.d.ts +2 -0
  96. package/cjs/index.js +2 -1
  97. package/cjs/index.js.map +1 -1
  98. package/cjs/interface/animate.d.ts +5 -39
  99. package/cjs/interface/animate.js.map +1 -1
  100. package/cjs/interface/color.js.map +1 -1
  101. package/cjs/interface/context.d.ts +1 -0
  102. package/cjs/interface/context.js.map +1 -1
  103. package/cjs/interface/global.d.ts +4 -1
  104. package/cjs/interface/global.js.map +1 -1
  105. package/cjs/interface/graphic/group.d.ts +1 -0
  106. package/cjs/interface/graphic/group.js.map +1 -1
  107. package/cjs/interface/graphic/image.d.ts +1 -0
  108. package/cjs/interface/graphic/image.js.map +1 -1
  109. package/cjs/interface/graphic/path.d.ts +1 -0
  110. package/cjs/interface/graphic/path.js.map +1 -1
  111. package/cjs/interface/graphic/rect.d.ts +1 -0
  112. package/cjs/interface/graphic/rect.js.map +1 -1
  113. package/cjs/interface/graphic/richText.d.ts +12 -0
  114. package/cjs/interface/graphic/richText.js.map +1 -1
  115. package/cjs/interface/graphic/symbol.d.ts +2 -0
  116. package/cjs/interface/graphic/symbol.js.map +1 -1
  117. package/cjs/interface/graphic.d.ts +12 -3
  118. package/cjs/interface/graphic.js.map +1 -1
  119. package/cjs/interface/path.d.ts +5 -0
  120. package/cjs/interface/path.js.map +1 -1
  121. package/cjs/interface/picker.d.ts +13 -0
  122. package/cjs/interface/picker.js.map +1 -1
  123. package/cjs/picker/constants.d.ts +2 -0
  124. package/cjs/picker/constants.js +3 -2
  125. package/cjs/picker/constants.js.map +1 -1
  126. package/cjs/picker/pick-interceptor.d.ts +7 -2
  127. package/cjs/picker/pick-interceptor.js +19 -2
  128. package/cjs/picker/pick-interceptor.js.map +1 -1
  129. package/cjs/picker/pick-modules.js +7 -4
  130. package/cjs/picker/pick-modules.js.map +1 -1
  131. package/cjs/picker/picker-service.d.ts +4 -2
  132. package/cjs/picker/picker-service.js +13 -12
  133. package/cjs/picker/picker-service.js.map +1 -1
  134. package/cjs/plugins/builtin-plugin/edit-module.d.ts +17 -6
  135. package/cjs/plugins/builtin-plugin/edit-module.js +128 -42
  136. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  137. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
  138. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
  139. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
  140. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +88 -31
  141. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +537 -229
  142. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  143. package/cjs/render/contributions/render/arc3d-render.js.map +1 -1
  144. package/cjs/render/contributions/render/area-render.d.ts +1 -1
  145. package/cjs/render/contributions/render/area-render.js +36 -16
  146. package/cjs/render/contributions/render/area-render.js.map +1 -1
  147. package/cjs/render/contributions/render/base-render.d.ts +1 -0
  148. package/cjs/render/contributions/render/base-render.js +20 -2
  149. package/cjs/render/contributions/render/base-render.js.map +1 -1
  150. package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +7 -1
  151. package/cjs/render/contributions/render/contributions/base-contribution-render.js +16 -8
  152. package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  153. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
  154. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  155. package/cjs/render/contributions/render/contributions/group-contribution-render.js +8 -3
  156. package/cjs/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  157. package/cjs/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  158. package/cjs/render/contributions/render/contributions/image-contribution-render.js +2 -2
  159. package/cjs/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  160. package/cjs/render/contributions/render/contributions/rect-contribution-render.js +4 -4
  161. package/cjs/render/contributions/render/contributions/rect-contribution-render.js.map +1 -1
  162. package/cjs/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
  163. package/cjs/render/contributions/render/contributions/symbol-contribution-render.js +30 -2
  164. package/cjs/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
  165. package/cjs/render/contributions/render/contributions/text-contribution-render.js +5 -3
  166. package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  167. package/cjs/render/contributions/render/draw-contribution.js +2 -1
  168. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  169. package/cjs/render/contributions/render/group-render.js +2 -2
  170. package/cjs/render/contributions/render/group-render.js.map +1 -1
  171. package/cjs/render/contributions/render/image-render.js +3 -3
  172. package/cjs/render/contributions/render/image-render.js.map +1 -1
  173. package/cjs/render/contributions/render/line-render.js +31 -9
  174. package/cjs/render/contributions/render/line-render.js.map +1 -1
  175. package/cjs/render/contributions/render/path-render.js.map +1 -1
  176. package/cjs/render/contributions/render/polygon-render.js.map +1 -1
  177. package/cjs/render/contributions/render/rect-render.js +2 -2
  178. package/cjs/render/contributions/render/rect-render.js.map +1 -1
  179. package/cjs/render/contributions/render/richtext-render.js +1 -1
  180. package/cjs/render/contributions/render/richtext-render.js.map +1 -1
  181. package/cjs/render/contributions/render/symbol-render.js +15 -13
  182. package/cjs/render/contributions/render/symbol-render.js.map +1 -1
  183. package/cjs/render/contributions/render/utils.d.ts +1 -2
  184. package/cjs/render/contributions/render/utils.js +4 -20
  185. package/cjs/render/contributions/render/utils.js.map +1 -1
  186. package/cjs/resource-loader/loader.js +1 -1
  187. package/cjs/resource-loader/loader.js.map +1 -1
  188. package/dist/index.es.js +8962 -7480
  189. package/es/animate/Ticker/default-ticker.d.ts +2 -0
  190. package/es/animate/Ticker/default-ticker.js +7 -1
  191. package/es/animate/Ticker/default-ticker.js.map +1 -1
  192. package/es/animate/animate.js +4 -5
  193. package/es/animate/animate.js.map +1 -1
  194. package/es/animate/custom-animate.js +14 -25
  195. package/es/animate/custom-animate.js.map +1 -1
  196. package/es/animate/easing-func.d.ts +1 -0
  197. package/es/animate/easing-func.js +10 -0
  198. package/es/animate/easing-func.js.map +1 -0
  199. package/es/animate/easing.d.ts +4 -0
  200. package/es/animate/easing.js +24 -1
  201. package/es/animate/easing.js.map +1 -1
  202. package/es/animate/index.d.ts +1 -0
  203. package/es/animate/index.js +2 -0
  204. package/es/animate/index.js.map +1 -1
  205. package/es/color-string/store.js +1 -2
  206. package/es/common/3d-interceptor.js +2 -1
  207. package/es/common/bezier-utils.d.ts +3 -0
  208. package/es/common/bezier-utils.js +14 -0
  209. package/es/common/bezier-utils.js.map +1 -1
  210. package/es/common/custom-path2d.d.ts +4 -0
  211. package/es/common/custom-path2d.js +44 -12
  212. package/es/common/custom-path2d.js.map +1 -1
  213. package/es/common/render-area.d.ts +4 -0
  214. package/es/common/render-area.js +77 -18
  215. package/es/common/render-area.js.map +1 -1
  216. package/es/common/render-command-list.js +2 -1
  217. package/es/common/render-curve.d.ts +1 -1
  218. package/es/common/render-curve.js.map +1 -1
  219. package/es/common/segment/curve/arc.d.ts +4 -1
  220. package/es/common/segment/curve/arc.js +10 -1
  221. package/es/common/segment/curve/arc.js.map +1 -1
  222. package/es/common/segment/curve/base.d.ts +4 -1
  223. package/es/common/segment/curve/base.js.map +1 -1
  224. package/es/common/segment/curve/cubic-bezier.d.ts +5 -1
  225. package/es/common/segment/curve/cubic-bezier.js +22 -1
  226. package/es/common/segment/curve/cubic-bezier.js.map +1 -1
  227. package/es/common/segment/curve/curve-context.js +6 -3
  228. package/es/common/segment/curve/curve-context.js.map +1 -1
  229. package/es/common/segment/curve/ellipse.d.ts +4 -1
  230. package/es/common/segment/curve/ellipse.js +9 -0
  231. package/es/common/segment/curve/ellipse.js.map +1 -1
  232. package/es/common/segment/curve/line.d.ts +4 -1
  233. package/es/common/segment/curve/line.js +18 -0
  234. package/es/common/segment/curve/line.js.map +1 -1
  235. package/es/common/segment/curve/move.d.ts +4 -1
  236. package/es/common/segment/curve/move.js +9 -0
  237. package/es/common/segment/curve/move.js.map +1 -1
  238. package/es/common/segment/curve/path.d.ts +2 -1
  239. package/es/common/segment/curve/path.js +5 -2
  240. package/es/common/segment/curve/path.js.map +1 -1
  241. package/es/common/segment/curve/quadratic-bezier.d.ts +6 -2
  242. package/es/common/segment/curve/quadratic-bezier.js +28 -5
  243. package/es/common/segment/curve/quadratic-bezier.js.map +1 -1
  244. package/es/common/segment/step.js +1 -1
  245. package/es/common/segment/step.js.map +1 -1
  246. package/es/common/shape/rect.d.ts +1 -1
  247. package/es/common/shape/rect.js +30 -25
  248. package/es/common/shape/rect.js.map +1 -1
  249. package/es/common/store.js +1 -1
  250. package/es/core/contributions/env/base-contribution.d.ts +2 -0
  251. package/es/core/contributions/env/base-contribution.js +6 -0
  252. package/es/core/contributions/env/base-contribution.js.map +1 -1
  253. package/es/core/global.d.ts +2 -3
  254. package/es/core/global.js +7 -8
  255. package/es/core/global.js.map +1 -1
  256. package/es/graphic/builtin-symbol/rect.d.ts +2 -1
  257. package/es/graphic/builtin-symbol/rect.js +28 -0
  258. package/es/graphic/builtin-symbol/rect.js.map +1 -1
  259. package/es/graphic/builtin-symbol/utils.d.ts +2 -1
  260. package/es/graphic/builtin-symbol/utils.js +5 -0
  261. package/es/graphic/builtin-symbol/utils.js.map +1 -1
  262. package/es/graphic/config.js +20 -5
  263. package/es/graphic/config.js.map +1 -1
  264. package/es/graphic/graphic.d.ts +1 -1
  265. package/es/graphic/graphic.js +20 -6
  266. package/es/graphic/graphic.js.map +1 -1
  267. package/es/graphic/line.js +2 -2
  268. package/es/graphic/line.js.map +1 -1
  269. package/es/graphic/richtext/line.js +1 -1
  270. package/es/graphic/richtext/line.js.map +1 -1
  271. package/es/graphic/richtext/paragraph.d.ts +1 -1
  272. package/es/graphic/richtext/paragraph.js +37 -7
  273. package/es/graphic/richtext/paragraph.js.map +1 -1
  274. package/es/graphic/richtext/utils.d.ts +4 -0
  275. package/es/graphic/richtext/utils.js +15 -2
  276. package/es/graphic/richtext/utils.js.map +1 -1
  277. package/es/graphic/richtext/wrapper.d.ts +1 -0
  278. package/es/graphic/richtext/wrapper.js +1 -1
  279. package/es/graphic/richtext/wrapper.js.map +1 -1
  280. package/es/graphic/richtext.d.ts +7 -2
  281. package/es/graphic/richtext.js +37 -5
  282. package/es/graphic/richtext.js.map +1 -1
  283. package/es/index.d.ts +2 -0
  284. package/es/index.js +4 -0
  285. package/es/index.js.map +1 -1
  286. package/es/interface/animate.d.ts +5 -39
  287. package/es/interface/animate.js.map +1 -1
  288. package/es/interface/color.js.map +1 -1
  289. package/es/interface/context.d.ts +1 -0
  290. package/es/interface/context.js.map +1 -1
  291. package/es/interface/global.d.ts +4 -1
  292. package/es/interface/global.js.map +1 -1
  293. package/es/interface/graphic/group.d.ts +1 -0
  294. package/es/interface/graphic/group.js.map +1 -1
  295. package/es/interface/graphic/image.d.ts +1 -0
  296. package/es/interface/graphic/image.js.map +1 -1
  297. package/es/interface/graphic/path.d.ts +1 -0
  298. package/es/interface/graphic/path.js.map +1 -1
  299. package/es/interface/graphic/rect.d.ts +1 -0
  300. package/es/interface/graphic/rect.js.map +1 -1
  301. package/es/interface/graphic/richText.d.ts +12 -0
  302. package/es/interface/graphic/richText.js.map +1 -1
  303. package/es/interface/graphic/symbol.d.ts +2 -0
  304. package/es/interface/graphic/symbol.js.map +1 -1
  305. package/es/interface/graphic.d.ts +12 -3
  306. package/es/interface/graphic.js.map +1 -1
  307. package/es/interface/path.d.ts +5 -0
  308. package/es/interface/path.js.map +1 -1
  309. package/es/interface/picker.d.ts +13 -0
  310. package/es/interface/picker.js.map +1 -1
  311. package/es/picker/constants.d.ts +2 -0
  312. package/es/picker/constants.js +4 -0
  313. package/es/picker/constants.js.map +1 -1
  314. package/es/picker/pick-interceptor.d.ts +7 -2
  315. package/es/picker/pick-interceptor.js +19 -1
  316. package/es/picker/pick-interceptor.js.map +1 -1
  317. package/es/picker/pick-modules.js +5 -3
  318. package/es/picker/pick-modules.js.map +1 -1
  319. package/es/picker/picker-service.d.ts +4 -2
  320. package/es/picker/picker-service.js +13 -13
  321. package/es/picker/picker-service.js.map +1 -1
  322. package/es/plugins/builtin-plugin/edit-module.d.ts +17 -6
  323. package/es/plugins/builtin-plugin/edit-module.js +123 -40
  324. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  325. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
  326. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
  327. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
  328. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +88 -31
  329. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +538 -225
  330. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  331. package/es/render/contributions/render/arc3d-render.js.map +1 -1
  332. package/es/render/contributions/render/area-render.d.ts +1 -1
  333. package/es/render/contributions/render/area-render.js +36 -16
  334. package/es/render/contributions/render/area-render.js.map +1 -1
  335. package/es/render/contributions/render/base-render.d.ts +1 -0
  336. package/es/render/contributions/render/base-render.js +21 -2
  337. package/es/render/contributions/render/base-render.js.map +1 -1
  338. package/es/render/contributions/render/contributions/base-contribution-render.d.ts +7 -1
  339. package/es/render/contributions/render/contributions/base-contribution-render.js +16 -8
  340. package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  341. package/es/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
  342. package/es/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  343. package/es/render/contributions/render/contributions/group-contribution-render.js +8 -3
  344. package/es/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  345. package/es/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  346. package/es/render/contributions/render/contributions/image-contribution-render.js +2 -2
  347. package/es/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  348. package/es/render/contributions/render/contributions/rect-contribution-render.js +4 -4
  349. package/es/render/contributions/render/contributions/rect-contribution-render.js.map +1 -1
  350. package/es/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
  351. package/es/render/contributions/render/contributions/symbol-contribution-render.js +26 -0
  352. package/es/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
  353. package/es/render/contributions/render/contributions/text-contribution-render.js +5 -3
  354. package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  355. package/es/render/contributions/render/draw-contribution.js +1 -1
  356. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  357. package/es/render/contributions/render/group-render.js +2 -2
  358. package/es/render/contributions/render/group-render.js.map +1 -1
  359. package/es/render/contributions/render/image-render.js +3 -2
  360. package/es/render/contributions/render/image-render.js.map +1 -1
  361. package/es/render/contributions/render/line-render.js +31 -9
  362. package/es/render/contributions/render/line-render.js.map +1 -1
  363. package/es/render/contributions/render/path-render.js.map +1 -1
  364. package/es/render/contributions/render/polygon-render.js.map +1 -1
  365. package/es/render/contributions/render/rect-render.js +2 -2
  366. package/es/render/contributions/render/rect-render.js.map +1 -1
  367. package/es/render/contributions/render/richtext-render.js +1 -1
  368. package/es/render/contributions/render/richtext-render.js.map +1 -1
  369. package/es/render/contributions/render/symbol-render.js +16 -14
  370. package/es/render/contributions/render/symbol-render.js.map +1 -1
  371. package/es/render/contributions/render/utils.d.ts +1 -2
  372. package/es/render/contributions/render/utils.js +0 -18
  373. package/es/render/contributions/render/utils.js.map +1 -1
  374. package/es/resource-loader/loader.js +1 -1
  375. package/es/resource-loader/loader.js.map +1 -1
  376. package/package.json +1 -1
@@ -2,6 +2,16 @@ import { calculateLineHeight } from "../../common/utils";
2
2
 
3
3
  import { measureTextCanvas, getStrByWithCanvas } from "./utils";
4
4
 
5
+ function getFixedLRTB(left, right, top, bottom) {
6
+ const leftInt = Math.round(left), topInt = Math.round(top), rightInt = Math.round(right), bottomInt = Math.round(bottom);
7
+ return {
8
+ left: left > leftInt ? leftInt : leftInt - .5,
9
+ top: top > topInt ? topInt : topInt - .5,
10
+ right: rightInt > right ? rightInt : rightInt + .5,
11
+ bottom: bottomInt > bottom ? bottomInt : bottomInt + .5
12
+ };
13
+ }
14
+
5
15
  export default class Paragraph {
6
16
  constructor(text, newLine, character) {
7
17
  this.fontSize = character.fontSize || 16, this.textBaseline = character.textBaseline || "alphabetic";
@@ -26,8 +36,8 @@ export default class Paragraph {
26
36
  this.width = width, "vertical" === this.direction && (this.widthOrigin = this.width,
27
37
  this.width = this.heightOrigin, this.height = this.widthOrigin);
28
38
  }
29
- draw(ctx, baseline, deltaLeft, isLineFirst, textAlign) {
30
- let text = this.text, left = this.left + deltaLeft;
39
+ draw(ctx, top, ascent, deltaLeft, isLineFirst, textAlign, lineHeight) {
40
+ let baseline = top + ascent, text = this.text, left = this.left + deltaLeft;
31
41
  baseline += this.top;
32
42
  let direction = this.direction;
33
43
  if (this.verticalEllipsis) text = this.ellipsisStr, direction = "vertical", baseline -= this.ellipsisWidth / 2; else {
@@ -48,13 +58,33 @@ export default class Paragraph {
48
58
  case "sub":
49
59
  baseline += this.descent / 2;
50
60
  }
51
- "vertical" === direction && (ctx.save(), ctx.rotateAbout(Math.PI / 2, left, baseline),
61
+ if ("vertical" === direction && (ctx.save(), ctx.rotateAbout(Math.PI / 2, left, baseline),
52
62
  ctx.translate(-this.heightOrigin || -this.lineHeight / 2, -this.descent / 2), ctx.translate(left, baseline),
53
- left = 0, baseline = 0);
63
+ left = 0, baseline = 0), this.character.fill && this.character.background && (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0)) {
64
+ const fillStyle = ctx.fillStyle, globalAlpha = ctx.globalAlpha;
65
+ ctx.fillStyle = this.character.background, void 0 !== this.character.backgroundOpacity && (ctx.globalAlpha = this.character.backgroundOpacity);
66
+ const lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + lineHeight);
67
+ ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top),
68
+ ctx.fillStyle = fillStyle, ctx.globalAlpha = globalAlpha;
69
+ }
54
70
  const {lineWidth: lineWidth = 1} = this.character;
55
- this.character.stroke && lineWidth && ctx.strokeText(text, left, baseline), this.character.fill && ctx.fillText(text, left, baseline),
56
- this.character.fill && ("boolean" == typeof this.character.lineThrough || "boolean" == typeof this.character.underline ? (this.character.underline && ctx.fillRect(left, 1 + baseline, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1),
57
- this.character.lineThrough && ctx.fillRect(left, 1 + baseline - this.ascent / 2, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1)) : "underline" === this.character.textDecoration ? ctx.fillRect(left, 1 + baseline, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1) : "line-through" === this.character.textDecoration && ctx.fillRect(left, 1 + baseline - this.ascent / 2, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1)),
71
+ if (this.character.stroke && lineWidth && ctx.strokeText(text, left, baseline),
72
+ this.character.fill && ctx.fillText(text, left, baseline), this.character.fill) if (this.character.lineThrough || this.character.underline) {
73
+ if (this.character.underline) {
74
+ 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));
75
+ ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);
76
+ }
77
+ if (this.character.lineThrough) {
78
+ const top = 1 + baseline - this.ascent / 2, lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1));
79
+ ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);
80
+ }
81
+ } else if ("underline" === this.character.textDecoration) {
82
+ 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));
83
+ ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);
84
+ } else if ("line-through" === this.character.textDecoration) {
85
+ const top = 1 + baseline - this.ascent / 2, lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1));
86
+ ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);
87
+ }
58
88
  "vertical" === direction && ctx.restore();
59
89
  }
60
90
  getWidthWithEllips(direction) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE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C,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,CAAC,CAAC;IACxE,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAE3D,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\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\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisStr: string;\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n overflow?: boolean;\n\n constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\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);\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);\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 draw(ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) {\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);\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 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 (typeof this.character.lineThrough === 'boolean' || typeof this.character.underline === 'boolean') {\n if (this.character.underline) {\n ctx.fillRect(\n left,\n 1 + baseline,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n if (this.character.lineThrough) {\n ctx.fillRect(\n left,\n 1 + baseline - this.ascent / 2,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n } else if (this.character.textDecoration === 'underline') {\n ctx.fillRect(\n left,\n 1 + baseline,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n } else if (this.character.textDecoration === 'line-through') {\n ctx.fillRect(\n left,\n 1 + baseline - this.ascent / 2,\n this.widthOrigin || this.width,\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);\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);\n const p2 = new Paragraph(text2, true, paragraph.character);\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,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C,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,CAAC,CAAC;YAC1F,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,CAAC,CAAC;IACxE,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAE3D,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\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisStr: string;\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n overflow?: boolean;\n\n constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\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);\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);\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 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);\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(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\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(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\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(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\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(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\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);\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);\n const p2 = new Paragraph(text2, true, paragraph.character);\n\n return [p1, p2];\n}\n"]}
@@ -27,6 +27,10 @@ export declare function applyStrokeStyle(ctx: IContext2d, character: IRichTextPa
27
27
  export declare function prepareContext(ctx: IContext2d): void;
28
28
  export declare function getStrByWithDom(desc: string, width: number, style: string, guessIndex: number, needTestLetter?: boolean): number;
29
29
  export declare function getStrByWithCanvas(desc: string, width: number, character: IRichTextParagraphCharacter, guessIndex: number, needTestLetter?: boolean): number;
30
+ export declare function getWordStartEndIdx(string: string, index: number): {
31
+ startIdx: number;
32
+ endIdx: number;
33
+ };
30
34
  export declare function testLetter(string: string, index: number, negativeWrongMatch?: boolean): number;
31
35
  export declare function testLetter2(string: string, index: number): number;
32
36
  export declare function measureTextDom(text: string, style: string): {
@@ -121,6 +121,19 @@ export function getStrByWithCanvas(desc, width, character, guessIndex, needTestL
121
121
  return needTestLetter && (index = testLetter(desc, index)), index;
122
122
  }
123
123
 
124
+ export function getWordStartEndIdx(string, index) {
125
+ let startIdx = index;
126
+ for (;(regLetter.test(string[startIdx - 1]) && regLetter.test(string[startIdx]) || regPunctuation.test(string[startIdx])) && (startIdx--,
127
+ !(startIdx <= 0)); ) ;
128
+ let endIdx = index;
129
+ for (;(regLetter.test(string[endIdx + 1]) && regLetter.test(string[endIdx]) || regPunctuation.test(string[endIdx])) && (endIdx++,
130
+ !(endIdx >= string.length)); ) ;
131
+ return endIdx = Math.min(endIdx + 1, string.length), {
132
+ startIdx: startIdx,
133
+ endIdx: endIdx
134
+ };
135
+ }
136
+
124
137
  export function testLetter(string, index, negativeWrongMatch = !1) {
125
138
  let i = index;
126
139
  for (;regLetter.test(string[i - 1]) && regLetter.test(string[i]) || regPunctuation.test(string[i]); ) if (i--,
@@ -130,9 +143,9 @@ export function testLetter(string, index, negativeWrongMatch = !1) {
130
143
 
131
144
  export function testLetter2(string, index) {
132
145
  let i = index;
133
- for (;regLetter.test(string[i - 1]) && regLetter.test(string[i]) || regPunctuation.test(string[i]); ) if (i++,
146
+ for (;regLetter.test(string[i + 1]) && regLetter.test(string[i]) || regPunctuation.test(string[i]); ) if (i++,
134
147
  i >= string.length) return i;
135
- return i;
148
+ return i + 1;
136
149
  }
137
150
 
138
151
  export function measureTextDom(text, style) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/richtext/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,M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AAC,uBAAuB,CAAC,CAAC;QAChE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;KAChD;IACD,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 (!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\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;\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): { 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 if (\n typeof measurement.actualBoundingBoxAscent !== 'number' ||\n typeof measurement.actualBoundingBoxDescent !== 'number'\n ) {\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(measurement.actualBoundingBoxAscent + measurement.actualBoundingBoxDescent);\n result.ascent = Math.floor(measurement.actualBoundingBoxAscent);\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}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AAS,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 (!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): { 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 if (\n typeof measurement.actualBoundingBoxAscent !== 'number' ||\n typeof measurement.actualBoundingBoxDescent !== 'number'\n ) {\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(measurement.actualBoundingBoxAscent + measurement.actualBoundingBoxDescent);\n result.ascent = Math.floor(measurement.actualBoundingBoxAscent);\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"]}
@@ -17,6 +17,7 @@ export default class Wrapper {
17
17
  width: string;
18
18
  height: string;
19
19
  };
20
+ newLine: boolean;
20
21
  constructor(frame: Frame);
21
22
  store(paragraph: Paragraph | RichTextIcon): void;
22
23
  send(): void;
@@ -34,7 +34,7 @@ export default class Wrapper {
34
34
  deal(paragraph, singleLine = !1) {
35
35
  paragraph instanceof RichTextIcon ? "horizontal" === this.direction && 0 === this.width || "vertical" === this.direction && 0 === this.height || this.lineWidth + paragraph[this.directionKey.width] <= this[this.directionKey.width] ? this.store(paragraph) : 0 === this.lineBuffer.length ? (this.store(paragraph),
36
36
  this.send()) : (this.send(), this.deal(paragraph)) : "number" != typeof this.width || this.width < 0 || (paragraph.newLine && this.send(),
37
- 0 !== paragraph.text.length && ("horizontal" === this.direction && 0 === this.width || "vertical" === this.direction && 0 === this.height || this.lineWidth + paragraph[this.directionKey.width] <= this[this.directionKey.width] ? this.store(paragraph) : this.lineWidth === this[this.directionKey.width] ? (this.send(),
37
+ (0 !== paragraph.text.length || this.newLine) && ("horizontal" === this.direction && 0 === this.width || "vertical" === this.direction && 0 === this.height || this.lineWidth + paragraph[this.directionKey.width] <= this[this.directionKey.width] ? this.store(paragraph) : this.lineWidth === this[this.directionKey.width] ? (this.send(),
38
38
  this.deal(paragraph)) : this.cut(paragraph, singleLine)));
39
39
  }
40
40
  cut(paragraph, singleLine) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/richtext/wrapper.ts"],"names":[],"mappings":"AAAA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U,EAAE;gBACd,IAAI,CAAC,IAAI,EAAE,CAAC;aACb;iBAAM;gBACL,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACf;SACF;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YAEvC,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SACtB;IAEH,CAAC;CACF","file":"wrapper.js","sourcesContent":["import Line from './line';\nimport type Frame from './frame';\nimport type Paragraph from './paragraph';\nimport { seperateParagraph } from './paragraph';\nimport { DIRECTION_KEY, getStrByWithCanvas } from './utils';\nimport { RichTextIcon } from './icon';\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/wrap.js\nexport default class Wrapper {\n frame: Frame;\n\n lineWidth: number;\n width: number;\n height: number;\n y: number;\n maxAscent: number;\n maxDescent: number;\n maxAscentForBlank: number;\n maxDescentForBlank: number;\n lineBuffer: (Paragraph | RichTextIcon)[];\n direction: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string };\n\n constructor(frame: Frame) {\n this.frame = frame;\n this.width = this.frame.width;\n this.height = this.frame.height;\n\n this.lineWidth = 0;\n this.y = this.frame.top;\n this.maxAscent = 0;\n this.maxDescent = 0;\n // 空字符串测量出的Ascent和Descent和文字不一致(空字符串测量结果ascent和descent一半一半),需要特殊处理\n this.maxAscentForBlank = 0;\n this.maxDescentForBlank = 0;\n this.lineBuffer = [];\n\n this.direction = frame.layoutDirection;\n this.directionKey = DIRECTION_KEY[this.direction];\n }\n\n // 不满一行,存储\n store(paragraph: Paragraph | RichTextIcon) {\n if (paragraph instanceof RichTextIcon) {\n this.frame.icons.set(paragraph.richtextId, paragraph);\n this.lineBuffer.push(paragraph);\n this.lineWidth += paragraph[this.directionKey.width];\n\n // 处理icon textBaseline ascent descent\n let iconAscent = 0;\n let iconDescent = 0;\n if (paragraph.attribute.textBaseline === 'top') {\n iconAscent = 0;\n iconDescent = paragraph.height;\n } else if (paragraph.attribute.textBaseline === 'bottom') {\n iconAscent = paragraph.height;\n iconDescent = 0;\n } else {\n iconAscent = paragraph.height / 2;\n iconDescent = paragraph.height / 2;\n }\n this.maxAscent = Math.max(this.maxAscent, iconAscent);\n this.maxDescent = Math.max(this.maxDescent, iconDescent);\n } else {\n this.lineBuffer.push(paragraph);\n if (paragraph.text.length !== 0) {\n this.lineWidth += paragraph[this.directionKey.width];\n this.maxAscent = Math.max(this.maxAscent, paragraph.ascent);\n this.maxDescent = Math.max(this.maxDescent, paragraph.descent);\n } else {\n this.maxAscentForBlank = Math.max(this.maxAscentForBlank, paragraph.ascent);\n this.maxDescentForBlank = Math.max(this.maxDescentForBlank, paragraph.descent);\n }\n }\n }\n\n // 满一行,生成line\n send() {\n if (this.lineBuffer.length === 0) {\n return;\n }\n // 当一行中有文字和空白时,不考虑空白的ascent和descent;如果只有空白(\\n引起的空行),取空白部分的ascent和descent\n const maxAscent = this.maxAscent === 0 ? this.maxAscentForBlank : this.maxAscent;\n const maxDescent = this.maxDescent === 0 ? this.maxDescentForBlank : this.maxDescent;\n const line = new Line(\n this.frame.left,\n this[this.directionKey.width],\n this.y + maxAscent,\n maxAscent,\n maxDescent,\n this.lineBuffer,\n this.direction,\n this.direction === 'horizontal' ? this.frame.isWidthMax : this.frame.isHeightMax\n );\n this.frame.lines.push(line);\n this.frame.actualHeight += line.height;\n\n // this.y += maxAscent + maxDescent;\n this.y += line.height;\n\n this.lineBuffer.length = 0;\n this.lineWidth = this.maxAscent = this.maxDescent = this.maxAscentForBlank = this.maxDescentForBlank = 0;\n }\n\n // 处理paragraph\n // singleLine表示是否将这个作为单行处理,也就是不拆多行了\n deal(paragraph: Paragraph | RichTextIcon, singleLine: boolean = false) {\n if (paragraph instanceof RichTextIcon) {\n if (\n (this.direction === 'horizontal' && this.width === 0) ||\n (this.direction === 'vertical' && this.height === 0)\n ) {\n // width为0时,宽度不设限制,不主动换行\n this.store(paragraph);\n } else {\n if (this.lineWidth + paragraph[this.directionKey.width] <= this[this.directionKey.width]) {\n this.store(paragraph);\n } else if (this.lineBuffer.length === 0) {\n this.store(paragraph);\n this.send();\n } else {\n this.send();\n this.deal(paragraph);\n }\n }\n\n return;\n }\n\n // 可能会出现宽度为负的情况,此时不处理数据\n if (typeof this.width !== 'number' || this.width < 0) {\n return;\n }\n\n if (paragraph.newLine) {\n // 需要换行前,先完成上一行绘制\n this.send();\n }\n\n if (paragraph.text.length === 0) {\n return;\n } // 换行符分割出的Paragraph不进入line\n\n if ((this.direction === 'horizontal' && this.width === 0) || (this.direction === 'vertical' && this.height === 0)) {\n // width为0时,宽度不设限制,不主动换行\n this.store(paragraph);\n } else {\n // // width为有效值时,按照宽度限制,主动换行\n // if (this.lineWidth + paragraph.width <= this.width) {\n // this.store(paragraph);\n // } else if (this.lineWidth === this.width) {\n // this.send();\n // // this.store(paragraph);\n // this.deal(paragraph);\n // } else {\n // this.cut(paragraph);\n // }\n if (this.lineWidth + paragraph[this.directionKey.width] <= this[this.directionKey.width]) {\n this.store(paragraph);\n } else if (this.lineWidth === this[this.directionKey.width]) {\n this.send();\n this.deal(paragraph);\n } else {\n this.cut(paragraph, singleLine);\n }\n }\n }\n\n // 文字超长,按需截断\n // 如果singleLine的话,最多就拆两行\n cut(paragraph: Paragraph, singleLine?: boolean) {\n // if (this.direction === 'vertical' && this.lineBuffer.length) {\n // // 纵排不做paragraph内截断\n // this.send();\n // this.deal(paragraph);\n // return;\n // } else if (this.direction === 'vertical') {\n // // 超长不处理?\n // this.store(paragraph);\n // this.send();\n // return;\n // }\n const availableWidth = this[this.directionKey.width] - this.lineWidth || 0;\n const guessIndex = Math.ceil((availableWidth / paragraph[this.directionKey.width]) * paragraph.length) || 0;\n // const index = getStrByWith(paragraph.text, availableWidth, paragraph.style, guessIndex, true);\n const index = getStrByWithCanvas(\n paragraph.text,\n availableWidth,\n paragraph.character,\n guessIndex,\n this.frame.wordBreak === 'break-word'\n );\n if (index !== 0) {\n const [p1, p2] = seperateParagraph(paragraph, index);\n this.store(p1);\n if (singleLine) {\n this.send();\n } else {\n this.deal(p2);\n }\n } else if (this.lineBuffer.length !== 0) {\n // 当前行无法容纳,转下一行处理\n this.send();\n this.deal(paragraph);\n }\n // 宽度过低,无法截断(容不下第一个字符的宽度),不处理\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/richtext/wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAG1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AA8BtC,MAAM,CAAC,OAAO,OAAO,OAAO;IAgB1B,YAAY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AAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SACtB;IAEH,CAAC;CACF","file":"wrapper.js","sourcesContent":["import Line from './line';\nimport type Frame from './frame';\nimport type Paragraph from './paragraph';\nimport { seperateParagraph } from './paragraph';\nimport { DIRECTION_KEY, getStrByWithCanvas } from './utils';\nimport { RichTextIcon } from './icon';\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/wrap.js\nexport default class Wrapper {\n frame: Frame;\n\n lineWidth: number;\n width: number;\n height: number;\n y: number;\n maxAscent: number;\n maxDescent: number;\n maxAscentForBlank: number;\n maxDescentForBlank: number;\n lineBuffer: (Paragraph | RichTextIcon)[];\n direction: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string };\n newLine: boolean; // 空换行符是否新增一行\n\n constructor(frame: Frame) {\n this.frame = frame;\n this.width = this.frame.width;\n this.height = this.frame.height;\n\n this.lineWidth = 0;\n this.y = this.frame.top;\n this.maxAscent = 0;\n this.maxDescent = 0;\n // 空字符串测量出的Ascent和Descent和文字不一致(空字符串测量结果ascent和descent一半一半),需要特殊处理\n this.maxAscentForBlank = 0;\n this.maxDescentForBlank = 0;\n this.lineBuffer = [];\n\n this.direction = frame.layoutDirection;\n this.directionKey = DIRECTION_KEY[this.direction];\n }\n\n // 不满一行,存储\n store(paragraph: Paragraph | RichTextIcon) {\n if (paragraph instanceof RichTextIcon) {\n this.frame.icons.set(paragraph.richtextId, paragraph);\n this.lineBuffer.push(paragraph);\n this.lineWidth += paragraph[this.directionKey.width];\n\n // 处理icon textBaseline ascent descent\n let iconAscent = 0;\n let iconDescent = 0;\n if (paragraph.attribute.textBaseline === 'top') {\n iconAscent = 0;\n iconDescent = paragraph.height;\n } else if (paragraph.attribute.textBaseline === 'bottom') {\n iconAscent = paragraph.height;\n iconDescent = 0;\n } else {\n iconAscent = paragraph.height / 2;\n iconDescent = paragraph.height / 2;\n }\n this.maxAscent = Math.max(this.maxAscent, iconAscent);\n this.maxDescent = Math.max(this.maxDescent, iconDescent);\n } else {\n this.lineBuffer.push(paragraph);\n if (paragraph.text.length !== 0) {\n this.lineWidth += paragraph[this.directionKey.width];\n this.maxAscent = Math.max(this.maxAscent, paragraph.ascent);\n this.maxDescent = Math.max(this.maxDescent, paragraph.descent);\n } else {\n this.maxAscentForBlank = Math.max(this.maxAscentForBlank, paragraph.ascent);\n this.maxDescentForBlank = Math.max(this.maxDescentForBlank, paragraph.descent);\n }\n }\n }\n\n // 满一行,生成line\n send() {\n if (this.lineBuffer.length === 0) {\n return;\n }\n // 当一行中有文字和空白时,不考虑空白的ascent和descent;如果只有空白(\\n引起的空行),取空白部分的ascent和descent\n const maxAscent = this.maxAscent === 0 ? this.maxAscentForBlank : this.maxAscent;\n const maxDescent = this.maxDescent === 0 ? this.maxDescentForBlank : this.maxDescent;\n const line = new Line(\n this.frame.left,\n this[this.directionKey.width],\n this.y + maxAscent,\n maxAscent,\n maxDescent,\n this.lineBuffer,\n this.direction,\n this.direction === 'horizontal' ? this.frame.isWidthMax : this.frame.isHeightMax\n );\n this.frame.lines.push(line);\n this.frame.actualHeight += line.height;\n\n // this.y += maxAscent + maxDescent;\n this.y += line.height;\n\n this.lineBuffer.length = 0;\n this.lineWidth = this.maxAscent = this.maxDescent = this.maxAscentForBlank = this.maxDescentForBlank = 0;\n }\n\n // 处理paragraph\n // singleLine表示是否将这个作为单行处理,也就是不拆多行了\n deal(paragraph: Paragraph | RichTextIcon, singleLine: boolean = false) {\n if (paragraph instanceof RichTextIcon) {\n if (\n (this.direction === 'horizontal' && this.width === 0) ||\n (this.direction === 'vertical' && this.height === 0)\n ) {\n // width为0时,宽度不设限制,不主动换行\n this.store(paragraph);\n } else {\n if (this.lineWidth + paragraph[this.directionKey.width] <= this[this.directionKey.width]) {\n this.store(paragraph);\n } else if (this.lineBuffer.length === 0) {\n this.store(paragraph);\n this.send();\n } else {\n this.send();\n this.deal(paragraph);\n }\n }\n\n return;\n }\n\n // 可能会出现宽度为负的情况,此时不处理数据\n if (typeof this.width !== 'number' || this.width < 0) {\n return;\n }\n\n if (paragraph.newLine) {\n // 需要换行前,先完成上一行绘制\n this.send();\n }\n\n if (paragraph.text.length === 0 && !this.newLine) {\n return;\n } // 换行符分割出的Paragraph不进入line\n\n if ((this.direction === 'horizontal' && this.width === 0) || (this.direction === 'vertical' && this.height === 0)) {\n // width为0时,宽度不设限制,不主动换行\n this.store(paragraph);\n } else {\n // // width为有效值时,按照宽度限制,主动换行\n // if (this.lineWidth + paragraph.width <= this.width) {\n // this.store(paragraph);\n // } else if (this.lineWidth === this.width) {\n // this.send();\n // // this.store(paragraph);\n // this.deal(paragraph);\n // } else {\n // this.cut(paragraph);\n // }\n if (this.lineWidth + paragraph[this.directionKey.width] <= this[this.directionKey.width]) {\n this.store(paragraph);\n } else if (this.lineWidth === this[this.directionKey.width]) {\n this.send();\n this.deal(paragraph);\n } else {\n this.cut(paragraph, singleLine);\n }\n }\n }\n\n // 文字超长,按需截断\n // 如果singleLine的话,最多就拆两行\n cut(paragraph: Paragraph, singleLine?: boolean) {\n // if (this.direction === 'vertical' && this.lineBuffer.length) {\n // // 纵排不做paragraph内截断\n // this.send();\n // this.deal(paragraph);\n // return;\n // } else if (this.direction === 'vertical') {\n // // 超长不处理?\n // this.store(paragraph);\n // this.send();\n // return;\n // }\n const availableWidth = this[this.directionKey.width] - this.lineWidth || 0;\n const guessIndex = Math.ceil((availableWidth / paragraph[this.directionKey.width]) * paragraph.length) || 0;\n // const index = getStrByWith(paragraph.text, availableWidth, paragraph.style, guessIndex, true);\n const index = getStrByWithCanvas(\n paragraph.text,\n availableWidth,\n paragraph.character,\n guessIndex,\n this.frame.wordBreak === 'break-word'\n );\n if (index !== 0) {\n const [p1, p2] = seperateParagraph(paragraph, index);\n this.store(p1);\n if (singleLine) {\n this.send();\n } else {\n this.deal(p2);\n }\n } else if (this.lineBuffer.length !== 0) {\n // 当前行无法容纳,转下一行处理\n this.send();\n this.deal(paragraph);\n }\n // 宽度过低,无法截断(容不下第一个字符的宽度),不处理\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { IAABBBounds } from '@visactor/vutils';
2
- import type { IRichText, IRichTextCharacter, RichTextGlobalAlignType, RichTextGlobalBaselineType, RichTextVerticalDirection, RichTextWordBreak, IRichTextGraphicAttribute, IRichTextImageCharacter, IRichTextParagraphCharacter, IStage, ILayer, IRichTextIcon, EventPoint } from '../interface';
2
+ import type { IRichText, IRichTextCharacter, RichTextGlobalAlignType, RichTextGlobalBaselineType, RichTextVerticalDirection, RichTextWordBreak, IRichTextGraphicAttribute, IRichTextImageCharacter, IRichTextParagraphCharacter, IStage, ILayer, IRichTextIcon, EventPoint, IRichTextFrame } from '../interface';
3
3
  import { Graphic } from './graphic';
4
4
  import Frame from './richtext/frame';
5
5
  export declare class RichText extends Graphic<IRichTextGraphicAttribute> implements IRichText {
@@ -65,10 +65,13 @@ export declare class RichText extends Graphic<IRichTextGraphicAttribute> impleme
65
65
  get textConfig(): IRichTextCharacter[];
66
66
  set textConfig(config: IRichTextCharacter[]);
67
67
  getGraphicTheme(): Required<IRichTextGraphicAttribute>;
68
+ static AllSingleCharacter(cache: IRichTextFrame | IRichTextGraphicAttribute['textConfig']): boolean;
69
+ static splitText(text: string): string[];
70
+ static TransformTextConfig2SingleCharacter(textConfig: IRichTextGraphicAttribute['textConfig']): IRichTextCharacter[];
68
71
  protected updateAABBBounds(attribute: IRichTextGraphicAttribute, richtextTheme: Required<IRichTextGraphicAttribute>, aabbBounds: IAABBBounds): import("@visactor/vutils").IBounds;
69
72
  protected needUpdateTags(keys: string[]): boolean;
70
73
  protected needUpdateTag(key: string): boolean;
71
- getFrameCache(): Frame;
74
+ getFrameCache(): IRichTextFrame;
72
75
  get cliped(): boolean;
73
76
  combinedStyleToCharacter(config: IRichTextImageCharacter | IRichTextParagraphCharacter): {
74
77
  lineHeight?: string | number;
@@ -90,6 +93,8 @@ export declare class RichText extends Graphic<IRichTextGraphicAttribute> impleme
90
93
  opacity: number;
91
94
  fillOpacity: number;
92
95
  strokeOpacity: number;
96
+ background?: string;
97
+ backgroundOpacity?: number;
93
98
  } | {
94
99
  lineHeight?: string | number;
95
100
  textAlign?: CanvasTextAlign;
@@ -1,4 +1,4 @@
1
- import { isNumber } from "@visactor/vutils";
1
+ import { isNumber, isString } from "@visactor/vutils";
2
2
 
3
3
  import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from "./graphic";
4
4
 
@@ -104,8 +104,30 @@ export class RichText extends Graphic {
104
104
  getGraphicTheme() {
105
105
  return getTheme(this).richtext;
106
106
  }
107
+ static AllSingleCharacter(cache) {
108
+ if (cache.lines) {
109
+ return cache.lines.every((line => line.paragraphs.every((item => !(item.text && isString(item.text) && RichText.splitText(item.text).length > 1)))));
110
+ }
111
+ return cache.every((item => item.isComposing || !(item.text && isString(item.text) && RichText.splitText(item.text).length > 1)));
112
+ }
113
+ static splitText(text) {
114
+ return Array.from(text);
115
+ }
116
+ static TransformTextConfig2SingleCharacter(textConfig) {
117
+ const tc = [];
118
+ return textConfig.forEach((item => {
119
+ const textList = RichText.splitText(item.text.toString());
120
+ if (isString(item.text) && textList.length > 1) for (let i = 0; i < textList.length; i++) {
121
+ const t = textList[i];
122
+ tc.push(Object.assign(Object.assign({}, item), {
123
+ text: t
124
+ }));
125
+ } else tc.push(item);
126
+ })), tc;
127
+ }
107
128
  updateAABBBounds(attribute, richtextTheme, aabbBounds) {
108
- const {width: width = richtextTheme.width, height: height = richtextTheme.height, maxWidth: maxWidth = richtextTheme.maxWidth, maxHeight: maxHeight = richtextTheme.maxHeight, textAlign: textAlign = richtextTheme.textAlign, textBaseline: textBaseline = richtextTheme.textBaseline} = attribute;
129
+ var _a, _b;
130
+ const {width: width = richtextTheme.width, height: height = richtextTheme.height, maxWidth: maxWidth = richtextTheme.maxWidth, maxHeight: maxHeight = richtextTheme.maxHeight, textAlign: textAlign = richtextTheme.textAlign, textBaseline: textBaseline = richtextTheme.textBaseline, editOptions: editOptions} = attribute;
109
131
  if (width > 0 && height > 0) aabbBounds.set(0, 0, width, height); else {
110
132
  const frameCache = this.getFrameCache(), {width: actualWidth, height: actualHeight} = frameCache.getActualSize();
111
133
  let contentWidth = width || actualWidth || 0, contentHeight = height || actualHeight || 0;
@@ -113,6 +135,8 @@ export class RichText extends Graphic {
113
135
  contentWidth = "number" == typeof maxWidth && contentWidth > maxWidth ? maxWidth : contentWidth || 0,
114
136
  aabbBounds.set(0, 0, contentWidth, contentHeight);
115
137
  }
138
+ editOptions && editOptions.keepHeightWhileEmpty && !aabbBounds.height() && !(null === (_a = attribute.textConfig) || void 0 === _a ? void 0 : _a.length) && (aabbBounds.y2 = aabbBounds.y1 + (null !== (_b = attribute.fontSize) && void 0 !== _b ? _b : 12),
139
+ aabbBounds.x2 = aabbBounds.x1 + 2);
116
140
  let deltaY = 0;
117
141
  switch (textBaseline) {
118
142
  case "top":
@@ -184,7 +208,11 @@ export class RichText extends Graphic {
184
208
  }
185
209
  doUpdateFrameCache(tc) {
186
210
  var _a;
187
- const {textConfig: _tc = [], maxWidth: maxWidth, maxHeight: maxHeight, width: width, height: height, ellipsis: ellipsis, wordBreak: wordBreak, verticalDirection: verticalDirection, textAlign: textAlign, textBaseline: textBaseline, layoutDirection: layoutDirection, singleLine: singleLine, disableAutoWrapLine: disableAutoWrapLine} = this.attribute, paragraphs = [], textConfig = null != tc ? tc : _tc;
211
+ const {maxWidth: maxWidth, maxHeight: maxHeight, width: width, height: height, ellipsis: ellipsis, wordBreak: wordBreak, verticalDirection: verticalDirection, textAlign: textAlign, textBaseline: textBaseline, layoutDirection: layoutDirection, singleLine: singleLine, disableAutoWrapLine: disableAutoWrapLine, editable: editable} = this.attribute;
212
+ let {textConfig: _tc = []} = this.attribute;
213
+ editable && _tc.length > 0 && !RichText.AllSingleCharacter(_tc) && (_tc = RichText.TransformTextConfig2SingleCharacter(_tc),
214
+ this.attribute.textConfig = _tc);
215
+ const paragraphs = [], textConfig = null != tc ? tc : _tc;
188
216
  for (let i = 0; i < textConfig.length; i++) if ("image" in textConfig[i]) {
189
217
  const config = this.combinedStyleToCharacter(textConfig[i]);
190
218
  config.lineWidth = void 0;
@@ -205,7 +233,7 @@ export class RichText extends Graphic {
205
233
  } else richTextConfig.text && paragraphs.push(new Paragraph(richTextConfig.text, !1, richTextConfig));
206
234
  }
207
235
  const maxWidthFinite = "number" == typeof maxWidth && Number.isFinite(maxWidth) && maxWidth > 0, maxHeightFinite = "number" == typeof maxHeight && Number.isFinite(maxHeight) && maxHeight > 0, richTextWidthEnable = "number" == typeof width && Number.isFinite(width) && width > 0 && (!maxWidthFinite || width <= maxWidth), richTextHeightEnable = "number" == typeof height && Number.isFinite(height) && height > 0 && (!maxHeightFinite || height <= maxHeight), frame = new Frame(0, 0, (richTextWidthEnable ? width : maxWidthFinite ? maxWidth : 0) || 0, (richTextHeightEnable ? height : maxHeightFinite ? maxHeight : 0) || 0, ellipsis, wordBreak, verticalDirection, textAlign, textBaseline, layoutDirection || "horizontal", !richTextWidthEnable && maxWidthFinite, !richTextHeightEnable && maxHeightFinite, singleLine || !1, null === (_a = this._frameCache) || void 0 === _a ? void 0 : _a.icons), wrapper = new Wrapper(frame);
208
- if (disableAutoWrapLine) {
236
+ if (wrapper.newLine = editable, disableAutoWrapLine) {
209
237
  let lineCount = 0, skip = !1;
210
238
  for (let i = 0; i < paragraphs.length; i++) {
211
239
  const p = paragraphs[i];
@@ -224,7 +252,11 @@ export class RichText extends Graphic {
224
252
  l.calcOffset(offsetSize, !1);
225
253
  }));
226
254
  }
227
- this._frameCache = frame;
255
+ editable && frame.lines.forEach((item => {
256
+ const lastParagraphs = item.paragraphs;
257
+ item.paragraphs = item.paragraphs.filter((p => "" !== p.text)), 0 === item.paragraphs.length && lastParagraphs.length && (lastParagraphs[0].text = "\n",
258
+ item.paragraphs.push(lastParagraphs[0]));
259
+ })), this._frameCache = frame;
228
260
  }
229
261
  clone() {
230
262
  return new RichText(Object.assign({}, this.attribute));