@visactor/vrender-core 0.18.14-alpha.0 → 0.18.14
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.
- package/cjs/graphic/config.js +1 -0
- package/cjs/graphic/config.js.map +1 -1
- package/cjs/graphic/richtext/frame.js +6 -6
- package/cjs/graphic/richtext/frame.js.map +1 -1
- package/cjs/graphic/richtext/line.d.ts +1 -1
- package/cjs/graphic/richtext/line.js +3 -2
- package/cjs/graphic/richtext/line.js.map +1 -1
- package/cjs/graphic/richtext/paragraph.d.ts +1 -0
- package/cjs/graphic/richtext/paragraph.js.map +1 -1
- package/cjs/graphic/richtext.js +11 -2
- package/cjs/graphic/richtext.js.map +1 -1
- package/cjs/interface/graphic/richText.d.ts +2 -1
- package/cjs/interface/graphic/richText.js.map +1 -1
- package/cjs/render/contributions/render/draw-contribution.js +2 -2
- package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
- package/es/graphic/config.js +1 -0
- package/es/graphic/config.js.map +1 -1
- package/es/graphic/richtext/frame.js +6 -6
- package/es/graphic/richtext/frame.js.map +1 -1
- package/es/graphic/richtext/line.d.ts +1 -1
- package/es/graphic/richtext/line.js +3 -2
- package/es/graphic/richtext/line.js.map +1 -1
- package/es/graphic/richtext/paragraph.d.ts +1 -0
- package/es/graphic/richtext/paragraph.js.map +1 -1
- package/es/graphic/richtext.js +11 -2
- package/es/graphic/richtext.js.map +1 -1
- package/es/interface/graphic/richText.d.ts +2 -1
- package/es/interface/graphic/richText.js.map +1 -1
- package/es/render/contributions/render/draw-contribution.js +2 -2
- package/es/render/contributions/render/draw-contribution.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/richtext/frame.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA8BxC,MAAM,CAAC,OAAO,OAAO,KAAK;IAwBxB,YACE,IAAY,EACZ,GAAW,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CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,WAAW,EAC5F;wBACA,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC;wBACrD,IAAI,SAAS,GAAG,UAAU,EAAE;4BAC1B,UAAU,GAAG,SAAS,CAAC;yBACxB;wBACD,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;qBACrC;yBAAM;wBACL,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,UAAU,EAAE;4BAC1C,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;yBACxC;wBACD,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;qBACrC;iBACF;aACF;SACF;QAED,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,eAAe,KAAK,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU;YACrE,MAAM,EAAE,IAAI,CAAC,eAAe,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW;SACvE,CAAC;IACJ,CAAC;CACF","file":"frame.js","sourcesContent":["// import { IContext2d } from '../../IContext';\nimport type { IContext2d, IRichTextIcon } from '../../interface';\nimport type Line from './line';\nimport { DIRECTION_KEY } 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/frame.js\nexport default class Frame {\n left: number;\n top: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n actualHeight: number;\n ellipsis: boolean | string;\n wordBreak: 'break-word' | 'break-all';\n verticalDirection: 'top' | 'middle' | 'bottom';\n lines: Line[];\n // ctx: IContext2d;\n globalAlign: 'left' | 'center' | 'right' | 'start' | 'end';\n globalBaseline: 'top' | 'middle' | 'bottom';\n layoutDirection: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string; left: string; top: string; bottom: string };\n isWidthMax: boolean;\n isHeightMax: boolean;\n\n singleLine: boolean;\n\n icons: Map<string, IRichTextIcon>;\n\n constructor(\n left: number,\n top: number,\n width: number,\n height: number,\n ellipsis: boolean | string,\n wordBreak: 'break-word' | 'break-all',\n verticalDirection: 'top' | 'middle' | 'bottom',\n // ctx: IContext2d,\n globalAlign: 'left' | 'center' | 'right' | 'start' | 'end',\n globalBaseline: 'top' | 'middle' | 'bottom',\n layoutDirection: 'horizontal' | 'vertical',\n isWidthMax: boolean,\n isHeightMax: boolean,\n singleLine: boolean,\n icons?: Map<string, IRichTextIcon>\n ) {\n this.left = left;\n this.top = top;\n this.width = width;\n this.height = height;\n this.actualHeight = 0;\n this.bottom = top + height;\n this.right = left + width;\n this.ellipsis = ellipsis;\n this.wordBreak = wordBreak;\n this.verticalDirection = verticalDirection;\n this.lines = [];\n // this.ctx = ctx;\n this.globalAlign = globalAlign;\n this.globalBaseline = globalBaseline;\n this.layoutDirection = layoutDirection;\n this.directionKey = DIRECTION_KEY[this.layoutDirection];\n\n this.isWidthMax = isWidthMax;\n this.isHeightMax = isHeightMax;\n\n this.singleLine = singleLine;\n\n if (icons) {\n icons.clear();\n this.icons = icons;\n } else {\n this.icons = new Map();\n }\n }\n\n draw(\n ctx: IContext2d,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) {\n const { width: actualWidth, height: actualHeight } = this.getActualSize();\n const width = this.isWidthMax ? Math.min(this.width, actualWidth) : this.width || actualWidth || 0;\n let height = this.isHeightMax ? Math.min(this.height, actualHeight) : this.height || actualHeight || 0;\n // 1. height 可能受 maxHeight 影响大于 actualHeight 计算出来的实际高度\n // 2. actualHeight 是不加省略内容的高度,可能会大于 height\n // 以上两种情况都可以通过 Math.min 解决\n height = Math.min(height, actualHeight);\n /**\n * 根据 align 和 baseline 进行偏移\n */\n let deltaY = 0;\n switch (this.globalBaseline) {\n case 'top':\n deltaY = 0;\n break;\n case 'middle':\n deltaY = -height / 2;\n break;\n case 'bottom':\n deltaY = -height;\n break;\n default:\n break;\n }\n\n let deltaX = 0;\n if (this.globalAlign === 'right' || this.globalAlign === 'end') {\n deltaX = -width;\n } else if (this.globalAlign === 'center') {\n deltaX = -width / 2;\n }\n\n let frameHeight = this[this.directionKey.height];\n if (this.singleLine) {\n frameHeight = this.lines[0].height + 1;\n }\n let lastLineTag = false;\n if (this.verticalDirection === 'middle') {\n if (this.actualHeight >= frameHeight && frameHeight !== 0) {\n for (let i = 0; i < this.lines.length; i++) {\n const { top, height } = this.lines[i];\n if (top + height < this[this.directionKey.top] || top + height > this[this.directionKey.top] + frameHeight) {\n return lastLineTag; // 不在展示范围内的line不绘制\n }\n // 判断需要显示省略号且是展示范围内的最后一行\n let lastLine = false;\n if (\n this.ellipsis &&\n this.lines[i + 1] &&\n this.lines[i + 1].top + this.lines[i + 1].height > this[this.directionKey.top] + frameHeight\n ) {\n lastLine = true;\n lastLineTag = true;\n }\n this.lines[i].draw(\n ctx,\n lastLine,\n this.lines[i][this.directionKey.left] + deltaX,\n this.lines[i][this.directionKey.top] + deltaY,\n drawIcon\n );\n }\n } else {\n const detalHeight = Math.floor((frameHeight - this.actualHeight) / 2);\n if (this.layoutDirection === 'vertical') {\n deltaX += detalHeight;\n } else {\n deltaY += detalHeight;\n }\n for (let i = 0; i < this.lines.length; i++) {\n this.lines[i].draw(\n ctx,\n false,\n this.lines[i][this.directionKey.left] + deltaX,\n this.lines[i][this.directionKey.top] + deltaY,\n drawIcon\n );\n }\n }\n\n // top = this.top + (this.height - this.actualHeight) / 2\n } else if (this.verticalDirection === 'bottom' && this.layoutDirection !== 'vertical') {\n for (let i = 0; i < this.lines.length; i++) {\n const { top, height } = this.lines[i];\n const y = frameHeight - this.lines[i].top - this.lines[i].height;\n // if (y + height < this.top || y + height > this.bottom) {\n if (frameHeight === 0) {\n this.lines[i].draw(ctx, false, deltaX, y + deltaY, drawIcon);\n } else if (y + height > this[this.directionKey.top] + frameHeight || y < this[this.directionKey.top]) {\n return lastLineTag; // 不在展示范围内的line不绘制\n } else {\n // 判断需要显示省略号且是展示范围内的最后一行\n let lastLine = false;\n if (this.ellipsis && this.lines[i + 1] && y - this.lines[i + 1].height < this[this.directionKey.top]) {\n lastLine = true;\n lastLineTag = true;\n }\n this.lines[i].draw(ctx, lastLine, deltaX, y + deltaY, drawIcon);\n }\n }\n } else {\n if (\n this.verticalDirection === 'bottom' &&\n this.layoutDirection === 'vertical' &&\n this.singleLine &&\n this.isWidthMax\n ) {\n deltaX += this.lines[0].height + 1;\n }\n for (let i = 0; i < this.lines.length; i++) {\n if (this.verticalDirection === 'bottom' && this.layoutDirection === 'vertical') {\n deltaX -= this.lines[i].height + this.lines[i].top;\n }\n const { top, height } = this.lines[i];\n if (frameHeight === 0) {\n this.lines[i].draw(\n ctx,\n false,\n this.lines[i][this.directionKey.left] + deltaX,\n this.lines[i][this.directionKey.top] + deltaY,\n drawIcon\n );\n } else if (\n top + height < this[this.directionKey.top] ||\n top + height > this[this.directionKey.top] + frameHeight\n ) {\n return lastLineTag; // 不在展示范围内的line不绘制\n } else {\n // 判断需要显示省略号且是展示范围内的最后一行\n let lastLine = false;\n if (\n this.ellipsis &&\n this.lines[i + 1] &&\n this.lines[i + 1].top + this.lines[i + 1].height > this[this.directionKey.top] + frameHeight\n ) {\n lastLine = true;\n lastLineTag = true;\n }\n this.lines[i].draw(\n ctx,\n lastLine,\n this.lines[i][this.directionKey.left] + deltaX,\n this.lines[i][this.directionKey.top] + deltaY,\n drawIcon\n );\n }\n }\n }\n\n return lastLineTag;\n }\n\n getActualSize(): { width: number; height: number } {\n if (this.ellipsis) {\n return this.getActualSizeWidthEllipsis();\n }\n\n return this.getRawActualSize();\n }\n\n getRawActualSize(): { width: number; height: number } {\n let width: number = 0;\n let height: number = 0;\n for (let i = 0; i < this.lines.length; i++) {\n const line = this.lines[i];\n if (line.actualWidth > width) {\n width = line.actualWidth;\n }\n height += line.height;\n }\n\n // return { width, height };\n return {\n width: this.layoutDirection === 'vertical' ? height : width,\n height: this.layoutDirection === 'vertical' ? width : height\n };\n }\n\n getActualSizeWidthEllipsis(): { width: number; height: number } {\n let widthBound: number = 0;\n let heightBound: number = 0;\n\n const { width: actualWidth, height: actualHeight } = this.getRawActualSize();\n const width = this.width || actualWidth || 0;\n let height = this.height || actualHeight || 0;\n // 1. height 可能受 maxHeight 影响大于 actualHeight 计算出来的实际高度\n // 2. actualHeight 是不加省略内容的高度,可能会大于 height\n // 以上两种情况都可以通过 Math.min 解决\n height = Math.min(height, actualHeight);\n /**\n * 根据 align 和 baseline 进行偏移\n */\n const deltaY = 0;\n\n let frameHeight = this[this.directionKey.height];\n if (this.singleLine) {\n frameHeight = this.lines[0].height + 1;\n }\n\n if (this.verticalDirection === 'middle') {\n if (this.actualHeight >= frameHeight && frameHeight !== 0) {\n for (let i = 0; i < this.lines.length; i++) {\n const { top, height } = this.lines[i];\n if (top + height < this[this.directionKey.top] || top + height > this[this.directionKey.top] + frameHeight) {\n // return; // 不在展示范围内的line不绘制\n } else {\n // 判断需要显示省略号且是展示范围内的最后一行\n if (\n this.ellipsis &&\n this.lines[i + 1] &&\n this.lines[i + 1].top + this.lines[i + 1].height > this[this.directionKey.top] + frameHeight\n ) {\n const lineWidth = this.lines[i].getWidthWithEllips();\n if (lineWidth > widthBound) {\n widthBound = lineWidth;\n }\n heightBound += this.lines[i].height;\n } else {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n }\n // this.lines[i].draw(ctx, lastLine, deltaX, this.lines[i].top + deltaY);\n }\n }\n } else {\n const detalHeight = Math.floor((frameHeight - this.actualHeight) / 2);\n for (let i = 0; i < this.lines.length; i++) {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n }\n }\n\n // top = this.top + (this.height - this.actualHeight) / 2\n } else if (this.verticalDirection === 'bottom') {\n for (let i = 0; i < this.lines.length; i++) {\n const { top, height } = this.lines[i];\n const y = frameHeight - this.lines[i].top - this.lines[i].height;\n // if (y + height < this.top || y + height > this.bottom) {\n if (frameHeight === 0) {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n } else if (y + height > this[this.directionKey.top] + frameHeight || y < this[this.directionKey.top]) {\n // return; // 不在展示范围内的line不绘制\n } else {\n // 判断需要显示省略号且是展示范围内的最后一行\n const lastLine = false;\n if (this.ellipsis && this.lines[i + 1] && y - this.lines[i + 1].height < this[this.directionKey.top]) {\n const lineWidth = this.lines[i].getWidthWithEllips();\n if (lineWidth > widthBound) {\n widthBound = lineWidth;\n }\n heightBound += this.lines[i].height;\n } else {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n }\n }\n }\n } else {\n for (let i = 0; i < this.lines.length; i++) {\n const { top, height } = this.lines[i];\n if (frameHeight === 0) {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n } else if (\n top + height < this[this.directionKey.top] ||\n top + height > this[this.directionKey.top] + frameHeight\n ) {\n // return; // 不在展示范围内的line不绘制\n } else {\n // 判断需要显示省略号且是展示范围内的最后一行\n const lastLine = false;\n if (\n this.ellipsis &&\n this.lines[i + 1] &&\n this.lines[i + 1].top + this.lines[i + 1].height > this[this.directionKey.top] + frameHeight\n ) {\n const lineWidth = this.lines[i].getWidthWithEllips();\n if (lineWidth > widthBound) {\n widthBound = lineWidth;\n }\n heightBound += this.lines[i].height;\n } else {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n }\n }\n }\n }\n\n return {\n width: this.layoutDirection === 'vertical' ? heightBound : widthBound,\n height: this.layoutDirection === 'vertical' ? widthBound : heightBound\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/graphic/richtext/frame.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA8BxC,MAAM,CAAC,OAAO,OAAO,KAAK;IAwBxB,YACE,IAAY,EACZ,GAAW,EACX,KAAa,EACb,MAAc,EACd,QAA0B,EAC1B,SAAqC,EACrC,iBAA8C,EAE9C,WAA0D,EAC1D,cAA2C,EAC3C,eAA0C,EAC1C,UAAmB,EACnB,WAAoB,EACpB,UAAmB,EACnB,KAAkC;QAElC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB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I,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC;wBACrD,IAAI,SAAS,GAAG,UAAU,EAAE;4BAC1B,UAAU,GAAG,SAAS,CAAC;yBACxB;wBACD,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;qBACrC;yBAAM;wBACL,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,UAAU,EAAE;4BAC1C,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;yBACxC;wBACD,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;qBACrC;iBACF;aACF;SACF;QAED,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,eAAe,KAAK,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU;YACrE,MAAM,EAAE,IAAI,CAAC,eAAe,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW;SACvE,CAAC;IACJ,CAAC;CACF","file":"frame.js","sourcesContent":["// import { IContext2d } from '../../IContext';\nimport type { IContext2d, IRichTextIcon } from '../../interface';\nimport type Line from './line';\nimport { DIRECTION_KEY } 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/frame.js\nexport default class Frame {\n left: number;\n top: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n actualHeight: number;\n ellipsis: boolean | string;\n wordBreak: 'break-word' | 'break-all';\n verticalDirection: 'top' | 'middle' | 'bottom';\n lines: Line[];\n // ctx: IContext2d;\n globalAlign: 'left' | 'center' | 'right' | 'start' | 'end';\n globalBaseline: 'top' | 'middle' | 'bottom';\n layoutDirection: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string; left: string; top: string; bottom: string };\n isWidthMax: boolean;\n isHeightMax: boolean;\n\n singleLine: boolean;\n\n icons: Map<string, IRichTextIcon>;\n\n constructor(\n left: number,\n top: number,\n width: number,\n height: number,\n ellipsis: boolean | string,\n wordBreak: 'break-word' | 'break-all',\n verticalDirection: 'top' | 'middle' | 'bottom',\n // ctx: IContext2d,\n globalAlign: 'left' | 'center' | 'right' | 'start' | 'end',\n globalBaseline: 'top' | 'middle' | 'bottom',\n layoutDirection: 'horizontal' | 'vertical',\n isWidthMax: boolean,\n isHeightMax: boolean,\n singleLine: boolean,\n icons?: Map<string, IRichTextIcon>\n ) {\n this.left = left;\n this.top = top;\n this.width = width;\n this.height = height;\n this.actualHeight = 0;\n this.bottom = top + height;\n this.right = left + width;\n this.ellipsis = ellipsis;\n this.wordBreak = wordBreak;\n this.verticalDirection = verticalDirection;\n this.lines = [];\n // this.ctx = ctx;\n this.globalAlign = globalAlign;\n this.globalBaseline = globalBaseline;\n this.layoutDirection = layoutDirection;\n this.directionKey = DIRECTION_KEY[this.layoutDirection];\n\n this.isWidthMax = isWidthMax;\n this.isHeightMax = isHeightMax;\n\n this.singleLine = singleLine;\n\n if (icons) {\n icons.clear();\n this.icons = icons;\n } else {\n this.icons = new Map();\n }\n }\n\n draw(\n ctx: IContext2d,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) {\n const { width: actualWidth, height: actualHeight } = this.getActualSize();\n const width = this.isWidthMax ? Math.min(this.width, actualWidth) : this.width || actualWidth || 0;\n let height = this.isHeightMax ? Math.min(this.height, actualHeight) : this.height || actualHeight || 0;\n // 1. height 可能受 maxHeight 影响大于 actualHeight 计算出来的实际高度\n // 2. actualHeight 是不加省略内容的高度,可能会大于 height\n // 以上两种情况都可以通过 Math.min 解决\n height = Math.min(height, actualHeight);\n /**\n * 根据 align 和 baseline 进行偏移\n */\n let deltaY = 0;\n switch (this.globalBaseline) {\n case 'top':\n deltaY = 0;\n break;\n case 'middle':\n deltaY = -height / 2;\n break;\n case 'bottom':\n deltaY = -height;\n break;\n default:\n break;\n }\n\n let deltaX = 0;\n if (this.globalAlign === 'right' || this.globalAlign === 'end') {\n deltaX = -width;\n } else if (this.globalAlign === 'center') {\n deltaX = -width / 2;\n }\n\n let frameHeight = this[this.directionKey.height];\n if (this.singleLine) {\n frameHeight = this.lines[0].height + 1;\n }\n let lastLineTag = false;\n if (this.verticalDirection === 'middle') {\n if (this.actualHeight >= frameHeight && frameHeight !== 0) {\n for (let i = 0; i < this.lines.length; i++) {\n const { top, height } = this.lines[i];\n if (top + height < this[this.directionKey.top] || top + height > this[this.directionKey.top] + frameHeight) {\n return lastLineTag; // 不在展示范围内的line不绘制\n }\n // 判断需要显示省略号且是展示范围内的最后一行\n let lastLine = false;\n if (\n this.ellipsis &&\n this.lines[i + 1] &&\n this.lines[i + 1].top + this.lines[i + 1].height > this[this.directionKey.top] + frameHeight\n ) {\n lastLine = true;\n lastLineTag = true;\n }\n this.lines[i].draw(\n ctx,\n lastLine,\n this.lines[i][this.directionKey.left] + deltaX,\n this.lines[i][this.directionKey.top] + deltaY,\n this.ellipsis,\n drawIcon\n );\n }\n } else {\n const detalHeight = Math.floor((frameHeight - this.actualHeight) / 2);\n if (this.layoutDirection === 'vertical') {\n deltaX += detalHeight;\n } else {\n deltaY += detalHeight;\n }\n for (let i = 0; i < this.lines.length; i++) {\n this.lines[i].draw(\n ctx,\n false,\n this.lines[i][this.directionKey.left] + deltaX,\n this.lines[i][this.directionKey.top] + deltaY,\n this.ellipsis,\n drawIcon\n );\n }\n }\n\n // top = this.top + (this.height - this.actualHeight) / 2\n } else if (this.verticalDirection === 'bottom' && this.layoutDirection !== 'vertical') {\n for (let i = 0; i < this.lines.length; i++) {\n const { top, height } = this.lines[i];\n const y = frameHeight - this.lines[i].top - this.lines[i].height;\n // if (y + height < this.top || y + height > this.bottom) {\n if (frameHeight === 0) {\n this.lines[i].draw(ctx, false, deltaX, y + deltaY, this.ellipsis, drawIcon);\n } else if (y + height > this[this.directionKey.top] + frameHeight || y < this[this.directionKey.top]) {\n return lastLineTag; // 不在展示范围内的line不绘制\n } else {\n // 判断需要显示省略号且是展示范围内的最后一行\n let lastLine = false;\n if (this.ellipsis && this.lines[i + 1] && y - this.lines[i + 1].height < this[this.directionKey.top]) {\n lastLine = true;\n lastLineTag = true;\n }\n this.lines[i].draw(ctx, lastLine, deltaX, y + deltaY, this.ellipsis, drawIcon);\n }\n }\n } else {\n if (\n this.verticalDirection === 'bottom' &&\n this.layoutDirection === 'vertical' &&\n this.singleLine &&\n this.isWidthMax\n ) {\n deltaX += this.lines[0].height + 1;\n }\n for (let i = 0; i < this.lines.length; i++) {\n if (this.verticalDirection === 'bottom' && this.layoutDirection === 'vertical') {\n deltaX -= this.lines[i].height + this.lines[i].top;\n }\n const { top, height } = this.lines[i];\n if (frameHeight === 0) {\n this.lines[i].draw(\n ctx,\n false,\n this.lines[i][this.directionKey.left] + deltaX,\n this.lines[i][this.directionKey.top] + deltaY,\n this.ellipsis,\n drawIcon\n );\n } else if (\n top + height < this[this.directionKey.top] ||\n top + height > this[this.directionKey.top] + frameHeight\n ) {\n return lastLineTag; // 不在展示范围内的line不绘制\n } else {\n // 判断需要显示省略号且是展示范围内的最后一行\n let lastLine = false;\n if (\n this.ellipsis &&\n this.lines[i + 1] &&\n this.lines[i + 1].top + this.lines[i + 1].height > this[this.directionKey.top] + frameHeight\n ) {\n lastLine = true;\n lastLineTag = true;\n }\n this.lines[i].draw(\n ctx,\n lastLine,\n this.lines[i][this.directionKey.left] + deltaX,\n this.lines[i][this.directionKey.top] + deltaY,\n this.ellipsis,\n drawIcon\n );\n }\n }\n }\n\n return lastLineTag;\n }\n\n getActualSize(): { width: number; height: number } {\n if (this.ellipsis) {\n return this.getActualSizeWidthEllipsis();\n }\n\n return this.getRawActualSize();\n }\n\n getRawActualSize(): { width: number; height: number } {\n let width: number = 0;\n let height: number = 0;\n for (let i = 0; i < this.lines.length; i++) {\n const line = this.lines[i];\n if (line.actualWidth > width) {\n width = line.actualWidth;\n }\n height += line.height;\n }\n\n // return { width, height };\n return {\n width: this.layoutDirection === 'vertical' ? height : width,\n height: this.layoutDirection === 'vertical' ? width : height\n };\n }\n\n getActualSizeWidthEllipsis(): { width: number; height: number } {\n let widthBound: number = 0;\n let heightBound: number = 0;\n\n const { width: actualWidth, height: actualHeight } = this.getRawActualSize();\n const width = this.width || actualWidth || 0;\n let height = this.height || actualHeight || 0;\n // 1. height 可能受 maxHeight 影响大于 actualHeight 计算出来的实际高度\n // 2. actualHeight 是不加省略内容的高度,可能会大于 height\n // 以上两种情况都可以通过 Math.min 解决\n height = Math.min(height, actualHeight);\n /**\n * 根据 align 和 baseline 进行偏移\n */\n const deltaY = 0;\n\n let frameHeight = this[this.directionKey.height];\n if (this.singleLine) {\n frameHeight = this.lines[0].height + 1;\n }\n\n if (this.verticalDirection === 'middle') {\n if (this.actualHeight >= frameHeight && frameHeight !== 0) {\n for (let i = 0; i < this.lines.length; i++) {\n const { top, height } = this.lines[i];\n if (top + height < this[this.directionKey.top] || top + height > this[this.directionKey.top] + frameHeight) {\n // return; // 不在展示范围内的line不绘制\n } else {\n // 判断需要显示省略号且是展示范围内的最后一行\n if (\n this.ellipsis &&\n this.lines[i + 1] &&\n this.lines[i + 1].top + this.lines[i + 1].height > this[this.directionKey.top] + frameHeight\n ) {\n const lineWidth = this.lines[i].getWidthWithEllips();\n if (lineWidth > widthBound) {\n widthBound = lineWidth;\n }\n heightBound += this.lines[i].height;\n } else {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n }\n // this.lines[i].draw(ctx, lastLine, deltaX, this.lines[i].top + deltaY);\n }\n }\n } else {\n const detalHeight = Math.floor((frameHeight - this.actualHeight) / 2);\n for (let i = 0; i < this.lines.length; i++) {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n }\n }\n\n // top = this.top + (this.height - this.actualHeight) / 2\n } else if (this.verticalDirection === 'bottom') {\n for (let i = 0; i < this.lines.length; i++) {\n const { top, height } = this.lines[i];\n const y = frameHeight - this.lines[i].top - this.lines[i].height;\n // if (y + height < this.top || y + height > this.bottom) {\n if (frameHeight === 0) {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n } else if (y + height > this[this.directionKey.top] + frameHeight || y < this[this.directionKey.top]) {\n // return; // 不在展示范围内的line不绘制\n } else {\n // 判断需要显示省略号且是展示范围内的最后一行\n const lastLine = false;\n if (this.ellipsis && this.lines[i + 1] && y - this.lines[i + 1].height < this[this.directionKey.top]) {\n const lineWidth = this.lines[i].getWidthWithEllips();\n if (lineWidth > widthBound) {\n widthBound = lineWidth;\n }\n heightBound += this.lines[i].height;\n } else {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n }\n }\n }\n } else {\n for (let i = 0; i < this.lines.length; i++) {\n const { top, height } = this.lines[i];\n if (frameHeight === 0) {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n } else if (\n top + height < this[this.directionKey.top] ||\n top + height > this[this.directionKey.top] + frameHeight\n ) {\n // return; // 不在展示范围内的line不绘制\n } else {\n // 判断需要显示省略号且是展示范围内的最后一行\n const lastLine = false;\n if (\n this.ellipsis &&\n this.lines[i + 1] &&\n this.lines[i + 1].top + this.lines[i + 1].height > this[this.directionKey.top] + frameHeight\n ) {\n const lineWidth = this.lines[i].getWidthWithEllips();\n if (lineWidth > widthBound) {\n widthBound = lineWidth;\n }\n heightBound += this.lines[i].height;\n } else {\n if (this.lines[i].actualWidth > widthBound) {\n widthBound = this.lines[i].actualWidth;\n }\n heightBound += this.lines[i].height;\n }\n }\n }\n }\n\n return {\n width: this.layoutDirection === 'vertical' ? heightBound : widthBound,\n height: this.layoutDirection === 'vertical' ? widthBound : heightBound\n };\n }\n}\n"]}
|
|
@@ -23,6 +23,6 @@ export default class Line {
|
|
|
23
23
|
};
|
|
24
24
|
constructor(left: number, width: number, baseline: number, ascent: number, descent: number, lineBuffer: (Paragraph | RichTextIcon)[], direction: 'horizontal' | 'vertical', isWidthMax: boolean);
|
|
25
25
|
calcOffset(width: number, isWidthMax: boolean): void;
|
|
26
|
-
draw(ctx: IContext2d, lastLine: boolean, x: number, y: number, drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void): void;
|
|
26
|
+
draw(ctx: IContext2d, lastLine: boolean, x: number, y: number, drawEllipsis: boolean | string, drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void): void;
|
|
27
27
|
getWidthWithEllips(): number;
|
|
28
28
|
}
|
|
@@ -31,11 +31,12 @@ export default class Line {
|
|
|
31
31
|
x += paragraph[directionKey.width] + spacing);
|
|
32
32
|
}));
|
|
33
33
|
}
|
|
34
|
-
draw(ctx, lastLine, x, y, drawIcon) {
|
|
35
|
-
if (lastLine) {
|
|
34
|
+
draw(ctx, lastLine, x, y, drawEllipsis, drawIcon) {
|
|
35
|
+
if (drawEllipsis && (lastLine || this.paragraphs.some((p => p.overflow)))) {
|
|
36
36
|
let otherParagraphWidth = 0;
|
|
37
37
|
for (let i = this.paragraphs.length - 1; i >= 0; i--) {
|
|
38
38
|
const paragraph = this.paragraphs[i];
|
|
39
|
+
if (paragraph.overflow) continue;
|
|
39
40
|
if (paragraph instanceof RichTextIcon) break;
|
|
40
41
|
if ("vertical" === this.direction && "vertical" !== paragraph.direction) {
|
|
41
42
|
paragraph.verticalEllipsis = !0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/richtext/line.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA8B1E,MAAM,CAAC,OAAO,OAAO,IAAI;IAevB,YACE,IAAY,EACZ,KAAa,EACb,QAAgB,EAChB,MAAc,EACd,OAAe,EACf,UAAwC,EACxC,SAAoC,EACpC,UAAmB;QAEnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,GAAG,GAAG,QAAQ,GAAG,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,CAAC,SAAS;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;IACf,CAAC;CACF","file":"line.js","sourcesContent":["// import { IContext2d } from '../../IContext';\nimport type { IContext2d, IRichTextIcon } from '../../interface';\nimport { RichTextIcon } from './icon';\nimport Paragraph from './paragraph';\nimport { DIRECTION_KEY, measureTextCanvas, regFirstSpace } from './utils';\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 行\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/line.js\nexport default class Line {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (Paragraph | RichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string; left: string; x: string; y: string };\n\n constructor(\n left: number,\n width: number,\n baseline: number,\n ascent: number,\n descent: number,\n lineBuffer: (Paragraph | RichTextIcon)[],\n direction: 'horizontal' | 'vertical',\n isWidthMax: boolean\n ) {\n this.left = left;\n this.width = width;\n this.baseline = baseline;\n this.ascent = ascent;\n this.descent = descent;\n // this.height = ascent + descent;\n this.top = baseline - ascent;\n this.paragraphs = lineBuffer.map(p => p);\n this.textAlign =\n (this.paragraphs[0] instanceof RichTextIcon\n ? this.paragraphs[0].attribute.textAlign\n : this.paragraphs[0].character.textAlign) || 'left'; // 对齐方式选择第一个paragraph属性\n this.direction = direction;\n this.directionKey = DIRECTION_KEY[this.direction];\n\n this.actualWidth = 0;\n let maxHeight = 0;\n this.paragraphs.forEach((word, index) => {\n // 每行中第一个字符不能是空格\n if (index === 0 && word instanceof Paragraph) {\n const result = regFirstSpace.exec(word.text);\n if (result?.index !== 0) {\n word.text = word.text.slice(result?.index);\n word.updateWidth();\n }\n }\n this.actualWidth += word[this.directionKey.width];\n maxHeight = Math.max(word[this.directionKey.height], maxHeight);\n });\n this.height = maxHeight;\n\n this.blankWidth = !isWidthMax ? this.width - this.actualWidth : 0;\n\n this.calcOffset(width, isWidthMax);\n }\n\n calcOffset(width: number, isWidthMax: boolean) {\n // 处理对齐方式,计算左侧偏移距离和字符之间间距\n const directionKey = this.directionKey;\n const maxHeight = this.height;\n let x = this.left;\n let spacing = 0;\n if (this.actualWidth < width && !isWidthMax) {\n if (this.textAlign === 'right' || this.textAlign === 'end') {\n x = width - this.actualWidth;\n } else if (this.textAlign === 'center') {\n x = (width - this.actualWidth) / 2;\n } else if (this.textAlign === 'justify') {\n if (this.paragraphs.length < 2) {\n // 只有一个paragraph两端对齐居中显示\n x = (width - this.actualWidth) / 2;\n } else {\n spacing = (width - this.actualWidth) / (this.paragraphs.length - 1);\n }\n }\n }\n\n this.paragraphs.map(function (paragraph) {\n if (paragraph instanceof RichTextIcon) {\n // paragraph.setAttribute(directionKey.x, x);\n paragraph['_' + directionKey.x] = x;\n x += paragraph[directionKey.width] + spacing;\n // 处理纵向对齐\n paragraph['_' + directionKey.y] =\n paragraph.attribute.textBaseline === 'top'\n ? 0\n : paragraph.attribute.textBaseline === 'bottom'\n ? maxHeight - paragraph.height\n : (maxHeight - paragraph.height) / 2;\n } else {\n paragraph[directionKey.left] = x;\n x += paragraph[directionKey.width] + spacing;\n }\n });\n }\n\n draw(\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) {\n if (lastLine) {\n // 处理省略号\n let otherParagraphWidth = 0;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n if (this.direction === 'vertical' && paragraph.direction !== 'vertical') {\n paragraph.verticalEllipsis = true;\n break;\n }\n // const { width } = measureText('...', paragraph.style);\n const { width } = measureTextCanvas('...', paragraph.character);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n paragraph.ellipsis = 'add';\n\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n }\n\n // 正常绘制\n this.paragraphs.map((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n // 更新icon位置\n paragraph.setAttributes({\n x: x + paragraph._x,\n y: y + paragraph._y\n });\n\n // 绘制icon\n drawIcon(paragraph, ctx, x + paragraph._x, y + paragraph._y, this.ascent);\n return;\n }\n paragraph.draw(ctx, y + this.ascent, x, index === 0, this.textAlign);\n });\n }\n\n getWidthWithEllips() {\n // 处理省略号\n let otherParagraphWidth = 0;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n\n const { width } = measureTextCanvas('...', paragraph.character);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n paragraph.ellipsis = 'add';\n paragraph.ellipsisWidth = ellipsisWidth;\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n\n let width = 0;\n // 正常绘制\n this.paragraphs.map((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n width += paragraph.width; // todo: 处理direction\n } else {\n width += paragraph.getWidthWithEllips(this.direction);\n }\n });\n\n return width;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/graphic/richtext/line.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA8B1E,MAAM,CAAC,OAAO,OAAO,IAAI;IAevB,YACE,IAAY,EACZ,KAAa,EACb,QAAgB,EAChB,MAAc,EACd,OAAe,EACf,UAAwC,EACxC,SAAoC,EACpC,UAAmB;QAEnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,G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S,CAAC,QAAQ,GAAG,MAAM,CAAC;gBAC5B,mBAAmB,IAAI,SAAS,CAAC,KAAK,CAAC;aACxC;SACF;QAED,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YACvC,IAAI,SAAS,YAAY,YAAY,EAAE;gBACrC,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC;aAC1B;iBAAM;gBACL,KAAK,IAAI,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACvD;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF","file":"line.js","sourcesContent":["// import { IContext2d } from '../../IContext';\nimport type { IContext2d, IRichTextIcon } from '../../interface';\nimport { RichTextIcon } from './icon';\nimport Paragraph from './paragraph';\nimport { DIRECTION_KEY, measureTextCanvas, regFirstSpace } from './utils';\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 行\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/line.js\nexport default class Line {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (Paragraph | RichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string; left: string; x: string; y: string };\n\n constructor(\n left: number,\n width: number,\n baseline: number,\n ascent: number,\n descent: number,\n lineBuffer: (Paragraph | RichTextIcon)[],\n direction: 'horizontal' | 'vertical',\n isWidthMax: boolean\n ) {\n this.left = left;\n this.width = width;\n this.baseline = baseline;\n this.ascent = ascent;\n this.descent = descent;\n // this.height = ascent + descent;\n this.top = baseline - ascent;\n this.paragraphs = lineBuffer.map(p => p);\n this.textAlign =\n (this.paragraphs[0] instanceof RichTextIcon\n ? this.paragraphs[0].attribute.textAlign\n : this.paragraphs[0].character.textAlign) || 'left'; // 对齐方式选择第一个paragraph属性\n this.direction = direction;\n this.directionKey = DIRECTION_KEY[this.direction];\n\n this.actualWidth = 0;\n let maxHeight = 0;\n this.paragraphs.forEach((word, index) => {\n // 每行中第一个字符不能是空格\n if (index === 0 && word instanceof Paragraph) {\n const result = regFirstSpace.exec(word.text);\n if (result?.index !== 0) {\n word.text = word.text.slice(result?.index);\n word.updateWidth();\n }\n }\n this.actualWidth += word[this.directionKey.width];\n maxHeight = Math.max(word[this.directionKey.height], maxHeight);\n });\n this.height = maxHeight;\n\n this.blankWidth = !isWidthMax ? this.width - this.actualWidth : 0;\n\n this.calcOffset(width, isWidthMax);\n }\n\n calcOffset(width: number, isWidthMax: boolean) {\n // 处理对齐方式,计算左侧偏移距离和字符之间间距\n const directionKey = this.directionKey;\n const maxHeight = this.height;\n let x = this.left;\n let spacing = 0;\n if (this.actualWidth < width && !isWidthMax) {\n if (this.textAlign === 'right' || this.textAlign === 'end') {\n x = width - this.actualWidth;\n } else if (this.textAlign === 'center') {\n x = (width - this.actualWidth) / 2;\n } else if (this.textAlign === 'justify') {\n if (this.paragraphs.length < 2) {\n // 只有一个paragraph两端对齐居中显示\n x = (width - this.actualWidth) / 2;\n } else {\n spacing = (width - this.actualWidth) / (this.paragraphs.length - 1);\n }\n }\n }\n\n this.paragraphs.map(function (paragraph) {\n if (paragraph instanceof RichTextIcon) {\n // paragraph.setAttribute(directionKey.x, x);\n paragraph['_' + directionKey.x] = x;\n x += paragraph[directionKey.width] + spacing;\n // 处理纵向对齐\n paragraph['_' + directionKey.y] =\n paragraph.attribute.textBaseline === 'top'\n ? 0\n : paragraph.attribute.textBaseline === 'bottom'\n ? maxHeight - paragraph.height\n : (maxHeight - paragraph.height) / 2;\n } else {\n paragraph[directionKey.left] = x;\n x += paragraph[directionKey.width] + spacing;\n }\n });\n }\n\n draw(\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawEllipsis: boolean | string,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) {\n if (drawEllipsis && (lastLine || this.paragraphs.some(p => (p as Paragraph).overflow))) {\n // 处理省略号\n let otherParagraphWidth = 0;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n continue;\n }\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n if (this.direction === 'vertical' && paragraph.direction !== 'vertical') {\n paragraph.verticalEllipsis = true;\n break;\n }\n // const { width } = measureText('...', paragraph.style);\n const { width } = measureTextCanvas('...', paragraph.character);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n paragraph.ellipsis = 'add';\n\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n }\n\n // 正常绘制\n this.paragraphs.map((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n // 更新icon位置\n paragraph.setAttributes({\n x: x + paragraph._x,\n y: y + paragraph._y\n });\n\n // 绘制icon\n drawIcon(paragraph, ctx, x + paragraph._x, y + paragraph._y, this.ascent);\n return;\n }\n paragraph.draw(ctx, y + this.ascent, x, index === 0, this.textAlign);\n });\n }\n\n getWidthWithEllips() {\n // 处理省略号\n let otherParagraphWidth = 0;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n\n const { width } = measureTextCanvas('...', paragraph.character);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n paragraph.ellipsis = 'add';\n paragraph.ellipsisWidth = ellipsisWidth;\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n\n let width = 0;\n // 正常绘制\n this.paragraphs.map((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n width += paragraph.width; // todo: 处理direction\n } else {\n width += paragraph.getWidthWithEllips(this.direction);\n }\n });\n\n return width;\n }\n}\n"]}
|
|
@@ -20,6 +20,7 @@ export default class Paragraph {
|
|
|
20
20
|
ellipsisWidth: number;
|
|
21
21
|
ellipsisOtherParagraphWidth: number;
|
|
22
22
|
verticalEllipsis?: boolean;
|
|
23
|
+
overflow?: boolean;
|
|
23
24
|
constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter);
|
|
24
25
|
updateWidth(): void;
|
|
25
26
|
draw(ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AA8BlG,MAAM,CAAC,OAAO,OAAO,SAAS;IAyB5B,YAAY,IAAY,EAAE,OAAgB,EAAE,SAAsC;QAEhF,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC,YAAY,IAAI,YAAY,CAAC;QAK3D,MAAM,UAAU,GAAG,mBAAmB,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5E,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,IAAI,CAAC,UAAU,GAAG,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;SAC3E;aAAM;YACL,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;SACnD;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;QAE9B,MAAM,EAAE,MAAM,EAAE,MAAM,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B,IAAI,IAAI,KAAK,CAAC;YAEd,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, applyFillStyle, applyStrokeStyle, 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 ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: 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 }\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 = '...';\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += '...';\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 += '...';\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.stroke) {\n applyStrokeStyle(ctx, this.character);\n ctx.strokeText(text, left, baseline);\n }\n\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, this.character);\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 += '...';\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,cAAc,EAAE,gBAAgB,EAAE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1C,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, applyFillStyle, applyStrokeStyle, 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 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 }\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 = '...';\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += '...';\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 += '...';\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.stroke) {\n applyStrokeStyle(ctx, this.character);\n ctx.strokeText(text, left, baseline);\n }\n\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, this.character);\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 += '...';\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"]}
|
package/es/graphic/richtext.js
CHANGED
|
@@ -133,7 +133,7 @@ export class RichText extends Graphic {
|
|
|
133
133
|
}
|
|
134
134
|
doUpdateFrameCache() {
|
|
135
135
|
var _a;
|
|
136
|
-
const {textConfig: textConfig = [], maxWidth: maxWidth, maxHeight: maxHeight, width: width, height: height, ellipsis: ellipsis, wordBreak: wordBreak, verticalDirection: verticalDirection, textAlign: textAlign, textBaseline: textBaseline, layoutDirection: layoutDirection, singleLine: singleLine} = this.attribute, paragraphs = [];
|
|
136
|
+
const {textConfig: textConfig = [], maxWidth: maxWidth, maxHeight: maxHeight, width: width, height: height, ellipsis: ellipsis, wordBreak: wordBreak, verticalDirection: verticalDirection, textAlign: textAlign, textBaseline: textBaseline, layoutDirection: layoutDirection, singleLine: singleLine, forceBreakLine: forceBreakLine} = this.attribute, paragraphs = [];
|
|
137
137
|
for (let i = 0; i < textConfig.length; i++) if ("image" in textConfig[i]) {
|
|
138
138
|
const config = this.combinedStyleToCharacter(textConfig[i]), iconCache = config.id && this._frameCache && this._frameCache.icons && this._frameCache.icons.get(config.id);
|
|
139
139
|
if (iconCache) paragraphs.push(iconCache); else {
|
|
@@ -152,7 +152,16 @@ export class RichText extends Graphic {
|
|
|
152
152
|
} else richTextConfig.text && paragraphs.push(new Paragraph(richTextConfig.text, !1, richTextConfig));
|
|
153
153
|
}
|
|
154
154
|
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);
|
|
155
|
-
|
|
155
|
+
if (forceBreakLine) {
|
|
156
|
+
let lineCount = 0, skip = !1;
|
|
157
|
+
for (let i = 0; i < paragraphs.length; i++) {
|
|
158
|
+
const p = paragraphs[i];
|
|
159
|
+
skip ? (p.overflow = !0, p.left = 1 / 0, p.top = 1 / 0, !p.newLine && frame.lines[frame.lines.length - 1].paragraphs.push(p)) : wrapper.deal(p),
|
|
160
|
+
frame.lines.length !== lineCount && (lineCount = frame.lines.length, wrapper.lineBuffer.length = 0,
|
|
161
|
+
p.overflow = !0, p.left = 1e3, p.top = 1e3, frame.lines[frame.lines.length - 1].paragraphs.push(p),
|
|
162
|
+
skip = !0), p.newLine && (skip = !1);
|
|
163
|
+
}
|
|
164
|
+
} else for (let i = 0; i < paragraphs.length; i++) wrapper.deal(paragraphs[i]);
|
|
156
165
|
wrapper.send();
|
|
157
166
|
if (!("horizontal" === frame.layoutDirection ? richTextWidthEnable : richTextHeightEnable)) {
|
|
158
167
|
const frameSize = frame.getActualSizeWidthEllipsis();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/richtext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmC,MAAM,kBAAkB,CAAC;AAgB7E,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAC7C,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,uBAAuB,GAAG;IAC9B,OAAO;IACP,QAAQ;IACR,UAAU;IACV,WAAW;IACX,mBAAmB;IACnB,WAAW;IACX,UAAU;IACV,WAAW;IACX,cAAc;IACd,YAAY;IACZ,iBAAiB;IACjB,GAAG,sBAAsB;CAC1B,CAAC;AAEF,MAAM,OAAO,QAAS,SAAQ,OAAkC;IAiB9D,YAAY,MAAkC;QAC5C,KAAK,CAAC,MAAM,CAAC,CAAC;QAjBhB,SAAI,GAAe,UAAU,CAAC;QAG9B,sBAAiB,GAAyB,IAAI,CAAC;QAe7C,IAAI,CAAC,UAAU,GAAG,oBAAoB,CAAC;IACzC,CAAC;IAED,IAAI,KAAK;;QACP,OAAO,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,mCAAI,wBAAwB,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O,QAAQ,CAAC;IAClB,CAAC;IAED,oBAAoB;QAClB,OAAO,QAAQ,CAAC,mBAAmB,CAAC;IACtC,CAAC;;AAnXM,4BAAmB,mBACxB,QAAQ,EAAE,CAAC,EACX,SAAS,EAAE,CAAC,EACZ,iBAAiB,EAAE,CAAC,EACpB,SAAS,EAAE,CAAC,EACZ,YAAY,EAAE,CAAC,EACf,UAAU,EAAE,CAAC,EACb,eAAe,EAAE,CAAC,IACf,mBAAmB,EACtB;AA6WJ,MAAM,UAAU,cAAc,CAAC,UAAqC;IAClE,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC","file":"richtext.js","sourcesContent":["import { isNumber, type AABBBounds, type OBBBounds } from '@visactor/vutils';\nimport type {\n IRichText,\n IRichTextCharacter,\n RichTextGlobalAlignType,\n RichTextGlobalBaselineType,\n RichTextVerticalDirection,\n RichTextWordBreak,\n IRichTextGraphicAttribute,\n IRichTextImageCharacter,\n IRichTextParagraphCharacter,\n IStage,\n ILayer,\n IRichTextIcon,\n EventPoint\n} from '../interface';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { DefaultRichTextAttribute } from './config';\nimport Frame from './richtext/frame';\nimport Paragraph from './richtext/paragraph';\nimport Wrapper from './richtext/wrapper';\nimport { getTheme } from './theme';\nimport { RichTextIcon } from './richtext/icon';\nimport type { FederatedMouseEvent } from '../event';\nimport { application } from '../application';\nimport { parsePadding } from '../common/utils';\nimport { RICHTEXT_NUMBER_TYPE } from './constants';\n\nconst RICHTEXT_UPDATE_TAG_KEY = [\n 'width',\n 'height',\n 'ellipsis',\n 'wordBreak',\n 'verticalDirection',\n 'maxHeight',\n 'maxWidth',\n 'textAlign',\n 'textBaseline',\n 'textConfig',\n 'layoutDirection',\n ...GRAPHIC_UPDATE_TAG_KEY\n];\n\nexport class RichText extends Graphic<IRichTextGraphicAttribute> implements IRichText {\n type: 'richtext' = 'richtext';\n\n _frameCache: Frame; // 富文本布局画布\n _currentHoverIcon: IRichTextIcon | null = null;\n\n static NOWORK_ANIMATE_ATTR = {\n ellipsis: 1,\n wordBreak: 1,\n verticalDirection: 1,\n textAlign: 1,\n textBaseline: 1,\n textConfig: 1,\n layoutDirection: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n constructor(params?: IRichTextGraphicAttribute) {\n super(params);\n this.numberType = RICHTEXT_NUMBER_TYPE;\n }\n\n get width(): number {\n return this.attribute.width ?? DefaultRichTextAttribute.width;\n }\n set width(w: number) {\n if (this.attribute.width === w) {\n return;\n }\n this.attribute.width = w;\n this.addUpdateShapeAndBoundsTag();\n }\n get height(): number {\n return this.attribute.height ?? DefaultRichTextAttribute.height;\n }\n set height(h: number) {\n if (this.attribute.height === h) {\n return;\n }\n this.attribute.height = h;\n this.addUpdateShapeAndBoundsTag();\n }\n get maxWidth(): number | undefined {\n return this.attribute.maxWidth;\n }\n set maxWidth(mw: number | undefined) {\n if (this.attribute.maxWidth === mw) {\n return;\n }\n this.attribute.maxWidth = mw;\n this.addUpdateShapeAndBoundsTag();\n }\n get maxHeight(): number | undefined {\n return this.attribute.maxHeight;\n }\n set maxHeight(mh: number | undefined) {\n if (this.attribute.maxHeight === mh) {\n return;\n }\n this.attribute.maxHeight = mh;\n this.addUpdateShapeAndBoundsTag();\n }\n get ellipsis(): boolean | string {\n return this.attribute.ellipsis ?? DefaultRichTextAttribute.ellipsis;\n }\n set ellipsis(e: boolean | string) {\n if (this.attribute.ellipsis === e) {\n return;\n }\n this.attribute.ellipsis = e;\n this.addUpdateShapeAndBoundsTag();\n }\n get wordBreak(): RichTextWordBreak {\n return this.attribute.wordBreak ?? DefaultRichTextAttribute.wordBreak;\n }\n set wordBreak(wb: RichTextWordBreak) {\n if (this.attribute.wordBreak === wb) {\n return;\n }\n this.attribute.wordBreak = wb;\n this.addUpdateShapeAndBoundsTag();\n }\n get verticalDirection(): RichTextVerticalDirection {\n return this.attribute.verticalDirection ?? DefaultRichTextAttribute.verticalDirection;\n }\n set verticalDirection(vd: RichTextVerticalDirection) {\n if (this.attribute.verticalDirection === vd) {\n return;\n }\n this.attribute.verticalDirection = vd;\n this.addUpdateShapeAndBoundsTag();\n }\n get textAlign(): RichTextGlobalAlignType {\n return this.attribute.textAlign ?? DefaultRichTextAttribute.textAlign;\n }\n set textAlign(align: RichTextGlobalAlignType) {\n if (this.attribute.textAlign === align) {\n return;\n }\n this.attribute.textAlign = align;\n this.addUpdateShapeAndBoundsTag();\n }\n get textBaseline(): RichTextGlobalBaselineType {\n return this.attribute.textBaseline ?? DefaultRichTextAttribute.textBaseline;\n }\n set textBaseline(baseline: RichTextGlobalBaselineType) {\n if (this.attribute.textBaseline === baseline) {\n return;\n }\n this.attribute.textBaseline = baseline;\n this.addUpdateShapeAndBoundsTag();\n }\n get textConfig(): IRichTextCharacter[] {\n return this.attribute.textConfig ?? DefaultRichTextAttribute.textConfig;\n }\n set textConfig(config: IRichTextCharacter[]) {\n this.attribute.textConfig = config;\n this.addUpdateShapeAndBoundsTag();\n }\n\n protected doUpdateAABBBounds(): AABBBounds {\n const richTextTheme = getTheme(this).richtext;\n this._AABBBounds.clear();\n const attribute = this.attribute;\n const bounds = application.graphicService.updateRichTextAABBBounds(\n attribute,\n getTheme(this).richtext,\n this._AABBBounds,\n this\n ) as AABBBounds;\n\n const { boundsPadding = richTextTheme.boundsPadding } = attribute;\n const paddingArray = parsePadding(boundsPadding);\n if (paddingArray) {\n bounds.expand(paddingArray);\n }\n\n this.clearUpdateBoundTag();\n return bounds;\n }\n\n protected tryUpdateOBBBounds(): OBBBounds {\n throw new Error('暂不支持');\n }\n\n getDefaultAttribute(name: string) {\n return DefaultRichTextAttribute[name];\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, RICHTEXT_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, RICHTEXT_UPDATE_TAG_KEY);\n }\n getFrameCache(): Frame {\n if (this.shouldUpdateShape()) {\n this.doUpdateFrameCache();\n this.clearUpdateShapeTag();\n }\n return this._frameCache;\n }\n combinedStyleToCharacter(config: IRichTextImageCharacter | IRichTextParagraphCharacter) {\n const { fill, stroke, fontSize, fontFamily, fontStyle, fontWeight, lineWidth } = this.attribute;\n return { fill, stroke, fontSize, fontFamily, fontStyle, fontWeight, lineWidth, ...config };\n }\n doUpdateFrameCache() {\n // 1. 测量,生成paragraph\n const {\n textConfig = [],\n maxWidth,\n maxHeight,\n width,\n height,\n ellipsis,\n wordBreak,\n verticalDirection,\n textAlign,\n textBaseline,\n layoutDirection,\n singleLine\n } = this.attribute;\n const paragraphs: (Paragraph | RichTextIcon)[] = [];\n\n for (let i = 0; i < textConfig.length; i++) {\n if ('image' in textConfig[i]) {\n const config = this.combinedStyleToCharacter(\n textConfig[i] as IRichTextImageCharacter\n ) as IRichTextImageCharacter;\n // 直接创建icon Mark\n const iconCache =\n config.id && this._frameCache && this._frameCache.icons && this._frameCache.icons.get(config.id);\n if (iconCache) {\n paragraphs.push(iconCache as RichTextIcon);\n } else {\n const icon = new RichTextIcon(config);\n icon.successCallback = () => {\n this.addUpdateBoundTag();\n this.stage?.renderNextFrame();\n };\n icon.richtextId = config.id;\n paragraphs.push(icon);\n }\n } else {\n const richTextConfig = this.combinedStyleToCharacter(\n textConfig[i] as IRichTextParagraphCharacter\n ) as IRichTextParagraphCharacter;\n if (isNumber(richTextConfig.text)) {\n richTextConfig.text = `${richTextConfig.text}`;\n }\n if (richTextConfig.text && richTextConfig.text.includes('\\n')) {\n // 如果有文字内有换行符,将该段文字切为多段,并在后一段加入newLine标记\n const textParts = richTextConfig.text.split('\\n');\n for (let j = 0; j < textParts.length; j++) {\n paragraphs.push(new Paragraph(textParts[j], j !== 0, richTextConfig));\n }\n } else if (richTextConfig.text) {\n paragraphs.push(new Paragraph(richTextConfig.text, false, richTextConfig));\n }\n }\n }\n\n // 2. 布局,生成frame\n // const frameHeight =\n // typeof maxHeight === 'number' && (!height || height > maxHeight) // height = 0或height>maxHeight,使用maxHeight布局\n // ? maxHeight\n // : height;\n // const frameWidth =\n // typeof maxWidth === 'number' && (!width || width > maxWidth) // height = 0或height>maxWidth,使用maxWidth布局\n // ? maxWidth\n // : width;\n\n const maxWidthFinite = typeof maxWidth === 'number' && Number.isFinite(maxWidth) && maxWidth > 0;\n const maxHeightFinite = typeof maxHeight === 'number' && Number.isFinite(maxHeight) && maxHeight > 0;\n\n const richTextWidthEnable =\n typeof width === 'number' &&\n Number.isFinite(width) &&\n width > 0 &&\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n (!maxWidthFinite || width <= maxWidth);\n const richTextHeightEnable =\n typeof height === 'number' &&\n Number.isFinite(height) &&\n height > 0 &&\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n (!maxHeightFinite || height <= maxHeight);\n\n const frameWidth = richTextWidthEnable ? width : maxWidthFinite ? maxWidth : 0;\n const frameHeight = richTextHeightEnable ? height : maxHeightFinite ? maxHeight : 0;\n\n const frame = new Frame(\n 0,\n 0,\n frameWidth || 0,\n frameHeight || 0,\n ellipsis,\n wordBreak,\n verticalDirection,\n textAlign,\n textBaseline,\n layoutDirection || 'horizontal',\n // typeof maxWidth === 'number' && (!width || width > maxWidth),\n // typeof maxHeight === 'number' && (!height || height > maxHeight),\n !richTextWidthEnable && maxWidthFinite,\n !richTextHeightEnable && maxHeightFinite,\n singleLine || false,\n this._frameCache?.icons\n );\n const wrapper = new Wrapper(frame);\n for (let i = 0; i < paragraphs.length; i++) {\n wrapper.deal(paragraphs[i]);\n }\n\n wrapper.send(); // 最后一行手动输出\n\n // 如果对应的配置宽度不可用,那么需要额外进行一次对齐\n const directionEnable = frame.layoutDirection === 'horizontal' ? richTextWidthEnable : richTextHeightEnable;\n if (!directionEnable) {\n // 使用实际宽度\n const frameSize = frame.getActualSizeWidthEllipsis();\n let offsetSize = frame.layoutDirection === 'horizontal' ? frameSize.width : frameSize.height;\n // 如果最大值可用\n if (frame.layoutDirection === 'horizontal' ? maxWidthFinite : maxHeightFinite) {\n // 取2者中的较小值\n offsetSize = Math.min(\n offsetSize,\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n frame.layoutDirection === 'horizontal' ? maxWidth : maxHeight\n );\n }\n\n frame.lines.forEach(function (l) {\n l.calcOffset(offsetSize, false);\n });\n }\n\n this._frameCache = frame;\n\n // this.bindIconEvent();\n }\n\n clone() {\n return new RichText({ ...this.attribute });\n }\n\n setStage(stage?: IStage, layer?: ILayer) {\n super.setStage(stage, layer);\n const frameCache = this.getFrameCache();\n // for (let i = 0; i < frameCache.icons.length; i++) {\n // const icon = frameCache.icons[i];\n // icon.setStage(stage, layer);\n // }\n frameCache.icons.forEach(icon => {\n icon.setStage(stage, layer);\n });\n }\n\n // richtext绑定icon交互事件,供外部调用\n bindIconEvent() {\n this.addEventListener('pointermove', (e: FederatedMouseEvent) => {\n const pickedIcon = this.pickIcon(e.global);\n if (pickedIcon && pickedIcon === this._currentHoverIcon) {\n // do nothing\n } else if (pickedIcon) {\n this._currentHoverIcon?.setHoverState(false);\n this._currentHoverIcon = pickedIcon;\n this._currentHoverIcon.setHoverState(true);\n this.stage?.setCursor(pickedIcon.attribute.cursor);\n this.stage?.renderNextFrame();\n } else if (!pickedIcon && this._currentHoverIcon) {\n this._currentHoverIcon.setHoverState(false);\n this._currentHoverIcon = null;\n this.stage?.setCursor();\n // console.log('setCursor()');\n\n this.stage?.renderNextFrame();\n }\n });\n\n this.addEventListener('pointerleave', (e: FederatedMouseEvent) => {\n if (this._currentHoverIcon) {\n this._currentHoverIcon.setHoverState(false);\n this._currentHoverIcon = null;\n this.stage?.setCursor();\n this.stage?.renderNextFrame();\n }\n });\n }\n\n pickIcon(point: EventPoint): IRichTextIcon | undefined {\n const frameCache = this.getFrameCache();\n const { e: x, f: y } = this.globalTransMatrix;\n // for (let i = 0; i < frameCache.icons.length; i++) {\n // const icon = frameCache.icons[i];\n // if (icon.containsPoint(point.x - x, point.y - y)) {\n // return icon;\n // }\n // }\n let pickIcon: IRichTextIcon | undefined;\n frameCache.icons.forEach(icon => {\n if (icon.AABBBounds.containsPoint({ x: point.x - x, y: point.y - y })) {\n pickIcon = icon;\n\n pickIcon.globalX = (pickIcon.attribute.x ?? 0) + x;\n pickIcon.globalY = (pickIcon.attribute.y ?? 0) + y;\n }\n });\n\n return pickIcon;\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return RichText.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createRichText(attributes: IRichTextGraphicAttribute): IRichText {\n return new RichText(attributes);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/graphic/richtext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmC,MAAM,kBAAkB,CAAC;AAgB7E,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAC7C,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,uBAAuB,GAAG;IAC9B,OAAO;IACP,QAAQ;IACR,UAAU;IACV,WAAW;IACX,mBAAmB;IACnB,WAAW;IACX,UAAU;IACV,WAAW;IACX,cAAc;IACd,YAAY;IACZ,iBAAiB;IACjB,GAAG,sBAAsB;CAC1B,CAAC;AAEF,MAAM,OAAO,QAAS,SAA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AAQ,CAAC,OAAO,GAAG,CAAC,MAAA,QAAQ,CAAC,SAAS,CAAC,CAAC,mCAAI,CAAC,CAAC,GAAG,CAAC,CAAC;gBACnD,QAAQ,CAAC,OAAO,GAAG,CAAC,MAAA,QAAQ,CAAC,SAAS,CAAC,CAAC,mCAAI,CAAC,CAAC,GAAG,CAAC,CAAC;aACpD;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,oBAAoB;QAClB,OAAO,QAAQ,CAAC,mBAAmB,CAAC;IACtC,CAAC;;AAjZM,4BAAmB,mBACxB,QAAQ,EAAE,CAAC,EACX,SAAS,EAAE,CAAC,EACZ,iBAAiB,EAAE,CAAC,EACpB,SAAS,EAAE,CAAC,EACZ,YAAY,EAAE,CAAC,EACf,UAAU,EAAE,CAAC,EACb,eAAe,EAAE,CAAC,IACf,mBAAmB,EACtB;AA2YJ,MAAM,UAAU,cAAc,CAAC,UAAqC;IAClE,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC","file":"richtext.js","sourcesContent":["import { isNumber, type AABBBounds, type OBBBounds } from '@visactor/vutils';\nimport type {\n IRichText,\n IRichTextCharacter,\n RichTextGlobalAlignType,\n RichTextGlobalBaselineType,\n RichTextVerticalDirection,\n RichTextWordBreak,\n IRichTextGraphicAttribute,\n IRichTextImageCharacter,\n IRichTextParagraphCharacter,\n IStage,\n ILayer,\n IRichTextIcon,\n EventPoint\n} from '../interface';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { DefaultRichTextAttribute } from './config';\nimport Frame from './richtext/frame';\nimport Paragraph from './richtext/paragraph';\nimport Wrapper from './richtext/wrapper';\nimport { getTheme } from './theme';\nimport { RichTextIcon } from './richtext/icon';\nimport type { FederatedMouseEvent } from '../event';\nimport { application } from '../application';\nimport { parsePadding } from '../common/utils';\nimport { RICHTEXT_NUMBER_TYPE } from './constants';\n\nconst RICHTEXT_UPDATE_TAG_KEY = [\n 'width',\n 'height',\n 'ellipsis',\n 'wordBreak',\n 'verticalDirection',\n 'maxHeight',\n 'maxWidth',\n 'textAlign',\n 'textBaseline',\n 'textConfig',\n 'layoutDirection',\n ...GRAPHIC_UPDATE_TAG_KEY\n];\n\nexport class RichText extends Graphic<IRichTextGraphicAttribute> implements IRichText {\n type: 'richtext' = 'richtext';\n\n _frameCache: Frame; // 富文本布局画布\n _currentHoverIcon: IRichTextIcon | null = null;\n\n static NOWORK_ANIMATE_ATTR = {\n ellipsis: 1,\n wordBreak: 1,\n verticalDirection: 1,\n textAlign: 1,\n textBaseline: 1,\n textConfig: 1,\n layoutDirection: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n constructor(params?: IRichTextGraphicAttribute) {\n super(params);\n this.numberType = RICHTEXT_NUMBER_TYPE;\n }\n\n get width(): number {\n return this.attribute.width ?? DefaultRichTextAttribute.width;\n }\n set width(w: number) {\n if (this.attribute.width === w) {\n return;\n }\n this.attribute.width = w;\n this.addUpdateShapeAndBoundsTag();\n }\n get height(): number {\n return this.attribute.height ?? DefaultRichTextAttribute.height;\n }\n set height(h: number) {\n if (this.attribute.height === h) {\n return;\n }\n this.attribute.height = h;\n this.addUpdateShapeAndBoundsTag();\n }\n get maxWidth(): number | undefined {\n return this.attribute.maxWidth;\n }\n set maxWidth(mw: number | undefined) {\n if (this.attribute.maxWidth === mw) {\n return;\n }\n this.attribute.maxWidth = mw;\n this.addUpdateShapeAndBoundsTag();\n }\n get maxHeight(): number | undefined {\n return this.attribute.maxHeight;\n }\n set maxHeight(mh: number | undefined) {\n if (this.attribute.maxHeight === mh) {\n return;\n }\n this.attribute.maxHeight = mh;\n this.addUpdateShapeAndBoundsTag();\n }\n get ellipsis(): boolean | string {\n return this.attribute.ellipsis ?? DefaultRichTextAttribute.ellipsis;\n }\n set ellipsis(e: boolean | string) {\n if (this.attribute.ellipsis === e) {\n return;\n }\n this.attribute.ellipsis = e;\n this.addUpdateShapeAndBoundsTag();\n }\n get wordBreak(): RichTextWordBreak {\n return this.attribute.wordBreak ?? DefaultRichTextAttribute.wordBreak;\n }\n set wordBreak(wb: RichTextWordBreak) {\n if (this.attribute.wordBreak === wb) {\n return;\n }\n this.attribute.wordBreak = wb;\n this.addUpdateShapeAndBoundsTag();\n }\n get verticalDirection(): RichTextVerticalDirection {\n return this.attribute.verticalDirection ?? DefaultRichTextAttribute.verticalDirection;\n }\n set verticalDirection(vd: RichTextVerticalDirection) {\n if (this.attribute.verticalDirection === vd) {\n return;\n }\n this.attribute.verticalDirection = vd;\n this.addUpdateShapeAndBoundsTag();\n }\n get textAlign(): RichTextGlobalAlignType {\n return this.attribute.textAlign ?? DefaultRichTextAttribute.textAlign;\n }\n set textAlign(align: RichTextGlobalAlignType) {\n if (this.attribute.textAlign === align) {\n return;\n }\n this.attribute.textAlign = align;\n this.addUpdateShapeAndBoundsTag();\n }\n get textBaseline(): RichTextGlobalBaselineType {\n return this.attribute.textBaseline ?? DefaultRichTextAttribute.textBaseline;\n }\n set textBaseline(baseline: RichTextGlobalBaselineType) {\n if (this.attribute.textBaseline === baseline) {\n return;\n }\n this.attribute.textBaseline = baseline;\n this.addUpdateShapeAndBoundsTag();\n }\n get textConfig(): IRichTextCharacter[] {\n return this.attribute.textConfig ?? DefaultRichTextAttribute.textConfig;\n }\n set textConfig(config: IRichTextCharacter[]) {\n this.attribute.textConfig = config;\n this.addUpdateShapeAndBoundsTag();\n }\n\n protected doUpdateAABBBounds(): AABBBounds {\n const richTextTheme = getTheme(this).richtext;\n this._AABBBounds.clear();\n const attribute = this.attribute;\n const bounds = application.graphicService.updateRichTextAABBBounds(\n attribute,\n getTheme(this).richtext,\n this._AABBBounds,\n this\n ) as AABBBounds;\n\n const { boundsPadding = richTextTheme.boundsPadding } = attribute;\n const paddingArray = parsePadding(boundsPadding);\n if (paddingArray) {\n bounds.expand(paddingArray);\n }\n\n this.clearUpdateBoundTag();\n return bounds;\n }\n\n protected tryUpdateOBBBounds(): OBBBounds {\n throw new Error('暂不支持');\n }\n\n getDefaultAttribute(name: string) {\n return DefaultRichTextAttribute[name];\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, RICHTEXT_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, RICHTEXT_UPDATE_TAG_KEY);\n }\n getFrameCache(): Frame {\n if (this.shouldUpdateShape()) {\n this.doUpdateFrameCache();\n this.clearUpdateShapeTag();\n }\n return this._frameCache;\n }\n combinedStyleToCharacter(config: IRichTextImageCharacter | IRichTextParagraphCharacter) {\n const { fill, stroke, fontSize, fontFamily, fontStyle, fontWeight, lineWidth } = this.attribute;\n return { fill, stroke, fontSize, fontFamily, fontStyle, fontWeight, lineWidth, ...config };\n }\n doUpdateFrameCache() {\n // 1. 测量,生成paragraph\n const {\n textConfig = [],\n maxWidth,\n maxHeight,\n width,\n height,\n ellipsis,\n wordBreak,\n verticalDirection,\n textAlign,\n textBaseline,\n layoutDirection,\n singleLine,\n forceBreakLine\n } = this.attribute;\n const paragraphs: (Paragraph | RichTextIcon)[] = [];\n\n for (let i = 0; i < textConfig.length; i++) {\n if ('image' in textConfig[i]) {\n const config = this.combinedStyleToCharacter(\n textConfig[i] as IRichTextImageCharacter\n ) as IRichTextImageCharacter;\n // 直接创建icon Mark\n const iconCache =\n config.id && this._frameCache && this._frameCache.icons && this._frameCache.icons.get(config.id);\n if (iconCache) {\n paragraphs.push(iconCache as RichTextIcon);\n } else {\n const icon = new RichTextIcon(config);\n icon.successCallback = () => {\n this.addUpdateBoundTag();\n this.stage?.renderNextFrame();\n };\n icon.richtextId = config.id;\n paragraphs.push(icon);\n }\n } else {\n const richTextConfig = this.combinedStyleToCharacter(\n textConfig[i] as IRichTextParagraphCharacter\n ) as IRichTextParagraphCharacter;\n if (isNumber(richTextConfig.text)) {\n richTextConfig.text = `${richTextConfig.text}`;\n }\n if (richTextConfig.text && richTextConfig.text.includes('\\n')) {\n // 如果有文字内有换行符,将该段文字切为多段,并在后一段加入newLine标记\n const textParts = richTextConfig.text.split('\\n');\n for (let j = 0; j < textParts.length; j++) {\n paragraphs.push(new Paragraph(textParts[j], j !== 0, richTextConfig));\n }\n } else if (richTextConfig.text) {\n paragraphs.push(new Paragraph(richTextConfig.text, false, richTextConfig));\n }\n }\n }\n\n // 2. 布局,生成frame\n // const frameHeight =\n // typeof maxHeight === 'number' && (!height || height > maxHeight) // height = 0或height>maxHeight,使用maxHeight布局\n // ? maxHeight\n // : height;\n // const frameWidth =\n // typeof maxWidth === 'number' && (!width || width > maxWidth) // height = 0或height>maxWidth,使用maxWidth布局\n // ? maxWidth\n // : width;\n\n const maxWidthFinite = typeof maxWidth === 'number' && Number.isFinite(maxWidth) && maxWidth > 0;\n const maxHeightFinite = typeof maxHeight === 'number' && Number.isFinite(maxHeight) && maxHeight > 0;\n\n const richTextWidthEnable =\n typeof width === 'number' &&\n Number.isFinite(width) &&\n width > 0 &&\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n (!maxWidthFinite || width <= maxWidth);\n const richTextHeightEnable =\n typeof height === 'number' &&\n Number.isFinite(height) &&\n height > 0 &&\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n (!maxHeightFinite || height <= maxHeight);\n\n const frameWidth = richTextWidthEnable ? width : maxWidthFinite ? maxWidth : 0;\n const frameHeight = richTextHeightEnable ? height : maxHeightFinite ? maxHeight : 0;\n\n const frame = new Frame(\n 0,\n 0,\n frameWidth || 0,\n frameHeight || 0,\n ellipsis,\n wordBreak,\n verticalDirection,\n textAlign,\n textBaseline,\n layoutDirection || 'horizontal',\n // typeof maxWidth === 'number' && (!width || width > maxWidth),\n // typeof maxHeight === 'number' && (!height || height > maxHeight),\n !richTextWidthEnable && maxWidthFinite,\n !richTextHeightEnable && maxHeightFinite,\n singleLine || false,\n this._frameCache?.icons\n );\n const wrapper = new Wrapper(frame);\n // debugger;\n if (forceBreakLine) {\n let lineCount = 0;\n let skip = false;\n for (let i = 0; i < paragraphs.length; i++) {\n const p = paragraphs[i];\n if (skip) {\n (p as Paragraph).overflow = true;\n (p as Paragraph).left = Infinity;\n (p as Paragraph).top = Infinity;\n !(p as Paragraph).newLine && frame.lines[frame.lines.length - 1].paragraphs.push(p);\n } else {\n wrapper.deal(p);\n }\n if (frame.lines.length !== lineCount) {\n lineCount = frame.lines.length;\n wrapper.lineBuffer.length = 0;\n (p as Paragraph).overflow = true;\n (p as Paragraph).left = 1000;\n (p as Paragraph).top = 1000;\n frame.lines[frame.lines.length - 1].paragraphs.push(p);\n skip = true;\n }\n if ((p as Paragraph).newLine) {\n skip = false;\n }\n }\n } else {\n for (let i = 0; i < paragraphs.length; i++) {\n wrapper.deal(paragraphs[i]);\n }\n }\n\n wrapper.send(); // 最后一行手动输出\n\n // 如果对应的配置宽度不可用,那么需要额外进行一次对齐\n const directionEnable = frame.layoutDirection === 'horizontal' ? richTextWidthEnable : richTextHeightEnable;\n if (!directionEnable) {\n // 使用实际宽度\n const frameSize = frame.getActualSizeWidthEllipsis();\n let offsetSize = frame.layoutDirection === 'horizontal' ? frameSize.width : frameSize.height;\n // 如果最大值可用\n if (frame.layoutDirection === 'horizontal' ? maxWidthFinite : maxHeightFinite) {\n // 取2者中的较小值\n offsetSize = Math.min(\n offsetSize,\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n frame.layoutDirection === 'horizontal' ? maxWidth : maxHeight\n );\n }\n\n frame.lines.forEach(function (l) {\n l.calcOffset(offsetSize, false);\n });\n }\n\n this._frameCache = frame;\n\n // this.bindIconEvent();\n }\n\n clone() {\n return new RichText({ ...this.attribute });\n }\n\n setStage(stage?: IStage, layer?: ILayer) {\n super.setStage(stage, layer);\n const frameCache = this.getFrameCache();\n // for (let i = 0; i < frameCache.icons.length; i++) {\n // const icon = frameCache.icons[i];\n // icon.setStage(stage, layer);\n // }\n frameCache.icons.forEach(icon => {\n icon.setStage(stage, layer);\n });\n }\n\n // richtext绑定icon交互事件,供外部调用\n bindIconEvent() {\n this.addEventListener('pointermove', (e: FederatedMouseEvent) => {\n const pickedIcon = this.pickIcon(e.global);\n if (pickedIcon && pickedIcon === this._currentHoverIcon) {\n // do nothing\n } else if (pickedIcon) {\n this._currentHoverIcon?.setHoverState(false);\n this._currentHoverIcon = pickedIcon;\n this._currentHoverIcon.setHoverState(true);\n this.stage?.setCursor(pickedIcon.attribute.cursor);\n this.stage?.renderNextFrame();\n } else if (!pickedIcon && this._currentHoverIcon) {\n this._currentHoverIcon.setHoverState(false);\n this._currentHoverIcon = null;\n this.stage?.setCursor();\n // console.log('setCursor()');\n\n this.stage?.renderNextFrame();\n }\n });\n\n this.addEventListener('pointerleave', (e: FederatedMouseEvent) => {\n if (this._currentHoverIcon) {\n this._currentHoverIcon.setHoverState(false);\n this._currentHoverIcon = null;\n this.stage?.setCursor();\n this.stage?.renderNextFrame();\n }\n });\n }\n\n pickIcon(point: EventPoint): IRichTextIcon | undefined {\n const frameCache = this.getFrameCache();\n const { e: x, f: y } = this.globalTransMatrix;\n // for (let i = 0; i < frameCache.icons.length; i++) {\n // const icon = frameCache.icons[i];\n // if (icon.containsPoint(point.x - x, point.y - y)) {\n // return icon;\n // }\n // }\n let pickIcon: IRichTextIcon | undefined;\n frameCache.icons.forEach(icon => {\n if (icon.AABBBounds.containsPoint({ x: point.x - x, y: point.y - y })) {\n pickIcon = icon;\n\n pickIcon.globalX = (pickIcon.attribute.x ?? 0) + x;\n pickIcon.globalY = (pickIcon.attribute.y ?? 0) + y;\n }\n });\n\n return pickIcon;\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return RichText.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createRichText(attributes: IRichTextGraphicAttribute): IRichText {\n return new RichText(attributes);\n}\n"]}
|
|
@@ -15,6 +15,7 @@ export type IRichTextAttribute = {
|
|
|
15
15
|
textBaseline: RichTextGlobalBaselineType;
|
|
16
16
|
layoutDirection: RichTextLayoutDirectionType;
|
|
17
17
|
textConfig: IRichTextCharacter[];
|
|
18
|
+
forceBreakLine: boolean;
|
|
18
19
|
singleLine: boolean;
|
|
19
20
|
};
|
|
20
21
|
export type IRichTextGraphicAttribute = Partial<IGraphicAttribute & ITextGraphicAttribute> & Partial<IRichTextAttribute>;
|
|
@@ -124,7 +125,7 @@ export interface IRichTextLine {
|
|
|
124
125
|
x: string;
|
|
125
126
|
y: string;
|
|
126
127
|
};
|
|
127
|
-
draw: (ctx: IContext2d, lastLine: boolean, x: number, y: number, drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void) => void;
|
|
128
|
+
draw: (ctx: IContext2d, lastLine: boolean, x: number, y: number, drawEllipsis: boolean | string, drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void) => void;
|
|
128
129
|
getWidthWithEllips: () => number;
|
|
129
130
|
}
|
|
130
131
|
export interface IRichTextFrame {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/richText.ts"],"names":[],"mappings":"","file":"richText.js","sourcesContent":["import type { IColor } from '../color';\nimport type { IContext2d } from '../context';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { IImage, IImageGraphicAttribute } from './image';\nimport type { ITextGraphicAttribute } from './text';\n\nexport type IRichTextAttribute = {\n width: number;\n height: number;\n ellipsis: boolean | string;\n wordBreak: RichTextWordBreak;\n verticalDirection: RichTextVerticalDirection;\n maxHeight: number;\n maxWidth: number;\n textAlign: RichTextGlobalAlignType;\n textBaseline: RichTextGlobalBaselineType;\n layoutDirection: RichTextLayoutDirectionType;\n textConfig: IRichTextCharacter[];\n singleLine: boolean;\n};\n\nexport type IRichTextGraphicAttribute = Partial<IGraphicAttribute & ITextGraphicAttribute> &\n Partial<IRichTextAttribute>;\n\nexport type RichTextWordBreak = 'break-word' | 'break-all';\nexport type RichTextVerticalDirection = 'top' | 'middle' | 'bottom';\nexport type RichTextGlobalAlignType = 'left' | 'right' | 'center';\nexport type RichTextGlobalBaselineType = 'top' | 'middle' | 'bottom';\nexport type RichTextLayoutDirectionType = 'horizontal' | 'vertical';\nexport type RichTextFontStyle = 'normal' | 'italic' | 'oblique';\nexport type RichTextTextDecoration = 'none' | 'underline' | 'line-through';\n// export type RichTextTextAlign = 'left' | 'right' | 'center';\nexport type RichTextScript = 'normal' | 'sub' | 'super';\n\nexport type IRichTextBasicCharacter = {\n lineHeight?: number | string;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextParagraphCharacter = IRichTextBasicCharacter & {\n text: string | number;\n fontSize?: number;\n fontFamily?: string;\n fill?: IColor | boolean;\n stroke?: IColor | boolean;\n fontWeight?: string;\n lineWidth?: number;\n // lineHeight?: number;\n fontStyle?: RichTextFontStyle; // normal, italic, oblique\n textDecoration?: RichTextTextDecoration; // none, underline, line-through\n // textAlign?: RichTextTextAlign; // left, right, center\n script?: RichTextScript; // normal, sub, super\n underline?: boolean;\n lineThrough?: boolean;\n // direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextImageCharacter = IRichTextBasicCharacter & {\n // 图片基础属性\n image: string | HTMLImageElement | HTMLCanvasElement;\n width: number;\n height: number;\n\n // hover相关属性\n // backgroundShow?: boolean; // 是否显示background\n backgroundShowMode?: 'always' | 'hover';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n // background size 同时控制了该icon的响应范围\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // 唯一标识符\n id?: string;\n\n // lineHeight?: number;\n // textAlign?: RichTextTextAlign; // left, right, center\n // direction?: RichTextLayoutDirectionType;\n margin?: number | number[];\n\n funcType?: string;\n hoverImage?: string | HTMLImageElement | HTMLCanvasElement;\n};\n\nexport type IRichTextCharacter = IRichTextParagraphCharacter | IRichTextImageCharacter;\n\nexport type IRichTextIconGraphicAttribute = IImageGraphicAttribute & {\n id?: string;\n backgroundShowMode?: 'always' | 'hover' | 'never';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // lineHeight?: number;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n\n margin?: number | number[];\n\n // backgroundShow?: boolean;\n};\n\nexport interface IRichTextParagraph {\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 direction?: 'horizontal' | 'vertical';\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n updateWidth: () => void;\n draw: (ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) => void;\n getWidthWithEllips: (direction: string) => number;\n}\n\nexport interface IRichTextLine {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (IRichTextParagraph | IRichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n x: string;\n y: string;\n };\n draw: (\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => void;\n getWidthWithEllips: () => number;\n}\n\nexport interface IRichTextFrame {\n left: number;\n top: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n actualHeight: number;\n ellipsis: boolean | string;\n wordBreak: 'break-word' | 'break-all';\n verticalDirection: 'top' | 'middle' | 'bottom';\n lines: IRichTextLine[];\n globalAlign: 'left' | 'center' | 'right' | 'start' | 'end';\n globalBaseline: 'top' | 'middle' | 'bottom';\n layoutDirection: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n top: string;\n bottom: string;\n };\n isWidthMax: boolean;\n isHeightMax: boolean;\n singleLine: boolean;\n icons: Map<string, IRichTextIcon>;\n draw: (\n ctx: IContext2d,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => boolean;\n getActualSize: () => {\n width: number;\n height: number;\n };\n getRawActualSize: () => {\n width: number;\n height: number;\n };\n getActualSizeWidthEllipsis: () => {\n width: number;\n height: number;\n };\n}\n\nexport interface IRichText extends IGraphic<IRichTextGraphicAttribute> {\n getFrameCache: () => IRichTextFrame;\n}\n\nexport interface IRichTextIcon extends IImage {\n attribute: IRichTextIconGraphicAttribute;\n richtextId?: string;\n globalX?: number;\n globalY?: number;\n\n _x: number;\n _y: number;\n _hovered: boolean;\n _marginArray: [number, number, number, number];\n\n setHoverState: (hovered: boolean) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/richText.ts"],"names":[],"mappings":"","file":"richText.js","sourcesContent":["import type { IColor } from '../color';\nimport type { IContext2d } from '../context';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { IImage, IImageGraphicAttribute } from './image';\nimport type { ITextGraphicAttribute } from './text';\n\nexport type IRichTextAttribute = {\n width: number;\n height: number;\n ellipsis: boolean | string;\n wordBreak: RichTextWordBreak;\n verticalDirection: RichTextVerticalDirection;\n maxHeight: number;\n maxWidth: number;\n textAlign: RichTextGlobalAlignType;\n textBaseline: RichTextGlobalBaselineType;\n layoutDirection: RichTextLayoutDirectionType;\n textConfig: IRichTextCharacter[];\n // 是否强制每行break\n forceBreakLine: boolean;\n singleLine: boolean;\n};\n\nexport type IRichTextGraphicAttribute = Partial<IGraphicAttribute & ITextGraphicAttribute> &\n Partial<IRichTextAttribute>;\n\nexport type RichTextWordBreak = 'break-word' | 'break-all';\nexport type RichTextVerticalDirection = 'top' | 'middle' | 'bottom';\nexport type RichTextGlobalAlignType = 'left' | 'right' | 'center';\nexport type RichTextGlobalBaselineType = 'top' | 'middle' | 'bottom';\nexport type RichTextLayoutDirectionType = 'horizontal' | 'vertical';\nexport type RichTextFontStyle = 'normal' | 'italic' | 'oblique';\nexport type RichTextTextDecoration = 'none' | 'underline' | 'line-through';\n// export type RichTextTextAlign = 'left' | 'right' | 'center';\nexport type RichTextScript = 'normal' | 'sub' | 'super';\n\nexport type IRichTextBasicCharacter = {\n lineHeight?: number | string;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextParagraphCharacter = IRichTextBasicCharacter & {\n text: string | number;\n fontSize?: number;\n fontFamily?: string;\n fill?: IColor | boolean;\n stroke?: IColor | boolean;\n fontWeight?: string;\n lineWidth?: number;\n // lineHeight?: number;\n fontStyle?: RichTextFontStyle; // normal, italic, oblique\n textDecoration?: RichTextTextDecoration; // none, underline, line-through\n // textAlign?: RichTextTextAlign; // left, right, center\n script?: RichTextScript; // normal, sub, super\n underline?: boolean;\n lineThrough?: boolean;\n // direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextImageCharacter = IRichTextBasicCharacter & {\n // 图片基础属性\n image: string | HTMLImageElement | HTMLCanvasElement;\n width: number;\n height: number;\n\n // hover相关属性\n // backgroundShow?: boolean; // 是否显示background\n backgroundShowMode?: 'always' | 'hover';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n // background size 同时控制了该icon的响应范围\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // 唯一标识符\n id?: string;\n\n // lineHeight?: number;\n // textAlign?: RichTextTextAlign; // left, right, center\n // direction?: RichTextLayoutDirectionType;\n margin?: number | number[];\n\n funcType?: string;\n hoverImage?: string | HTMLImageElement | HTMLCanvasElement;\n};\n\nexport type IRichTextCharacter = IRichTextParagraphCharacter | IRichTextImageCharacter;\n\nexport type IRichTextIconGraphicAttribute = IImageGraphicAttribute & {\n id?: string;\n backgroundShowMode?: 'always' | 'hover' | 'never';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // lineHeight?: number;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n\n margin?: number | number[];\n\n // backgroundShow?: boolean;\n};\n\nexport interface IRichTextParagraph {\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 direction?: 'horizontal' | 'vertical';\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n updateWidth: () => void;\n draw: (ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) => void;\n getWidthWithEllips: (direction: string) => number;\n}\n\nexport interface IRichTextLine {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (IRichTextParagraph | IRichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n x: string;\n y: string;\n };\n draw: (\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawEllipsis: boolean | string,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => void;\n getWidthWithEllips: () => number;\n}\n\nexport interface IRichTextFrame {\n left: number;\n top: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n actualHeight: number;\n ellipsis: boolean | string;\n wordBreak: 'break-word' | 'break-all';\n verticalDirection: 'top' | 'middle' | 'bottom';\n lines: IRichTextLine[];\n globalAlign: 'left' | 'center' | 'right' | 'start' | 'end';\n globalBaseline: 'top' | 'middle' | 'bottom';\n layoutDirection: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n top: string;\n bottom: string;\n };\n isWidthMax: boolean;\n isHeightMax: boolean;\n singleLine: boolean;\n icons: Map<string, IRichTextIcon>;\n draw: (\n ctx: IContext2d,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => boolean;\n getActualSize: () => {\n width: number;\n height: number;\n };\n getRawActualSize: () => {\n width: number;\n height: number;\n };\n getActualSizeWidthEllipsis: () => {\n width: number;\n height: number;\n };\n}\n\nexport interface IRichText extends IGraphic<IRichTextGraphicAttribute> {\n getFrameCache: () => IRichTextFrame;\n}\n\nexport interface IRichTextIcon extends IImage {\n attribute: IRichTextIconGraphicAttribute;\n richtextId?: string;\n globalX?: number;\n globalY?: number;\n\n _x: number;\n _y: number;\n _hovered: boolean;\n _marginArray: [number, number, number, number];\n\n setHoverState: (hovered: boolean) => void;\n}\n"]}
|
|
@@ -78,8 +78,8 @@ let DefaultDrawContribution = class {
|
|
|
78
78
|
return (null !== (_a = a.attribute.zIndex) && void 0 !== _a ? _a : DefaultAttribute.zIndex) - (null !== (_b = b.attribute.zIndex) && void 0 !== _b ? _b : DefaultAttribute.zIndex);
|
|
79
79
|
})).forEach((group => {
|
|
80
80
|
group.isContainer ? this.renderGroup(group, drawContext, matrixAllocate.allocate(1, 0, 0, 1, 0, 0)) : this.renderItem(group, drawContext);
|
|
81
|
-
})), context.restore(), context.
|
|
82
|
-
context.
|
|
81
|
+
})), context.restore(), context.setClearMatrix(1, 0, 0, 1, 0, 0), context.inuse = !1,
|
|
82
|
+
context.draw();
|
|
83
83
|
}
|
|
84
84
|
doRegister() {
|
|
85
85
|
throw new Error("暂不支持");
|