@visactor/vrender-core 0.22.0-vstory.6 → 0.22.0-vstory.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/animate/custom-animate.js +2 -1
- package/cjs/animate/index.js +1 -2
- package/cjs/graphic/group.js +1 -1
- package/cjs/graphic/group.js.map +1 -1
- package/cjs/graphic/richtext/paragraph.js +4 -5
- package/cjs/graphic/richtext/paragraph.js.map +1 -1
- package/cjs/graphic/richtext.d.ts +2 -1
- package/cjs/graphic/richtext.js +6 -0
- package/cjs/graphic/richtext.js.map +1 -1
- package/cjs/interface/graphic/richText.d.ts +1 -0
- package/cjs/interface/graphic/richText.js.map +1 -1
- package/cjs/plugins/builtin-plugin/edit-module.js +2 -2
- package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +3 -2
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +87 -73
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/cjs/render/contributions/render/draw-contribution.js +1 -1
- package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
- package/dist/index.es.js +55 -21
- package/es/animate/custom-animate.js +2 -1
- package/es/animate/index.js +1 -2
- package/es/graphic/group.js +1 -1
- package/es/graphic/group.js.map +1 -1
- package/es/graphic/richtext/paragraph.js +4 -5
- package/es/graphic/richtext/paragraph.js.map +1 -1
- package/es/graphic/richtext.d.ts +2 -1
- package/es/graphic/richtext.js +6 -0
- package/es/graphic/richtext.js.map +1 -1
- package/es/interface/graphic/richText.d.ts +1 -0
- package/es/interface/graphic/richText.js.map +1 -1
- package/es/plugins/builtin-plugin/edit-module.js +2 -2
- package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +3 -2
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js +85 -73
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/es/render/contributions/render/draw-contribution.js +1 -1
- package/es/render/contributions/render/draw-contribution.js.map +1 -1
- package/package.json +3 -3
package/dist/index.es.js
CHANGED
|
@@ -13587,6 +13587,9 @@ class Group extends Graphic {
|
|
|
13587
13587
|
const bounds = this.doUpdateAABBBounds();
|
|
13588
13588
|
this.addUpdateLayoutTag();
|
|
13589
13589
|
application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange);
|
|
13590
|
+
if (this.attribute.boundsMode === 'empty') {
|
|
13591
|
+
bounds.clear();
|
|
13592
|
+
}
|
|
13590
13593
|
return bounds;
|
|
13591
13594
|
}
|
|
13592
13595
|
doUpdateLocalMatrix() {
|
|
@@ -17841,15 +17844,11 @@ function getFixedLRTB(left, right, top, bottom) {
|
|
|
17841
17844
|
const topInt = Math.round(top);
|
|
17842
17845
|
const rightInt = Math.round(right);
|
|
17843
17846
|
const bottomInt = Math.round(bottom);
|
|
17844
|
-
const _left = left > leftInt ? leftInt : leftInt - 0.5;
|
|
17845
|
-
const _top = top > topInt ? topInt : topInt - 0.5;
|
|
17846
|
-
const _right = rightInt > right ? rightInt : rightInt + 0.5;
|
|
17847
|
-
const _bottom = bottomInt > bottom ? bottomInt : bottomInt + 0.5;
|
|
17848
17847
|
return {
|
|
17849
|
-
left:
|
|
17850
|
-
top:
|
|
17851
|
-
right:
|
|
17852
|
-
bottom:
|
|
17848
|
+
left: leftInt,
|
|
17849
|
+
top: topInt,
|
|
17850
|
+
right: rightInt,
|
|
17851
|
+
bottom: bottomInt
|
|
17853
17852
|
};
|
|
17854
17853
|
}
|
|
17855
17854
|
class Paragraph {
|
|
@@ -18758,7 +18757,16 @@ class RichText extends Graphic {
|
|
|
18758
18757
|
return tc.every(item => item.isComposing ||
|
|
18759
18758
|
!(item.text && isString(item.text) && RichText.splitText(item.text).length > 1));
|
|
18760
18759
|
}
|
|
18760
|
+
static splitEmoji(text) {
|
|
18761
|
+
return [...new Intl.Segmenter().segment(text)].map(x => x.segment);
|
|
18762
|
+
}
|
|
18761
18763
|
static splitText(text) {
|
|
18764
|
+
try {
|
|
18765
|
+
const arr = this.splitEmoji(text);
|
|
18766
|
+
return arr;
|
|
18767
|
+
}
|
|
18768
|
+
catch (e) {
|
|
18769
|
+
}
|
|
18762
18770
|
return Array.from(text);
|
|
18763
18771
|
}
|
|
18764
18772
|
static TransformTextConfig2SingleCharacter(textConfig) {
|
|
@@ -24414,7 +24422,9 @@ let DefaultDrawContribution = class DefaultDrawContribution {
|
|
|
24414
24422
|
this._increaseRender(group, drawContext);
|
|
24415
24423
|
return;
|
|
24416
24424
|
}
|
|
24417
|
-
if (this.useDirtyBounds &&
|
|
24425
|
+
if (this.useDirtyBounds &&
|
|
24426
|
+
!isRectIntersect(group.AABBBounds, this.dirtyBounds, false) &&
|
|
24427
|
+
group.attribute.boundsMode !== 'empty') {
|
|
24418
24428
|
return;
|
|
24419
24429
|
}
|
|
24420
24430
|
let nextM = parentMatrix;
|
|
@@ -27258,7 +27268,7 @@ class EditModule {
|
|
|
27258
27268
|
const text = lastConfig.text;
|
|
27259
27269
|
const textList = text ? Array.from(text.toString()) : [];
|
|
27260
27270
|
for (let i = 0; i < textList.length; i++) {
|
|
27261
|
-
textConfig.splice(i + configIdx, 0, Object.assign(Object.assign({ fill: 'black' }, lastConfig), { isComposing: false, text: textList[i] }));
|
|
27271
|
+
textConfig.splice(i + configIdx, 0, Object.assign(Object.assign(Object.assign(Object.assign({}, getDefaultCharacterConfig(this.currRt.attribute)), { fill: 'black' }), lastConfig), { isComposing: false, text: textList[i] }));
|
|
27262
27272
|
}
|
|
27263
27273
|
this.currRt.setAttributes({ textConfig });
|
|
27264
27274
|
const nextConfigIdx = configIdx + textList.length;
|
|
@@ -27604,6 +27614,12 @@ class RichTextEditPlugin {
|
|
|
27604
27614
|
return;
|
|
27605
27615
|
}
|
|
27606
27616
|
const { lines } = cache;
|
|
27617
|
+
if (lines.length === 0) {
|
|
27618
|
+
return;
|
|
27619
|
+
}
|
|
27620
|
+
if (!lines[0].paragraphs || lines[0].paragraphs.length === 0) {
|
|
27621
|
+
return;
|
|
27622
|
+
}
|
|
27607
27623
|
const totalCursorCount = lines.reduce((total, line) => total + line.paragraphs.length, 0) - 1;
|
|
27608
27624
|
this.selectionRange(-0.1, totalCursorCount + 0.1);
|
|
27609
27625
|
e.preventDefault();
|
|
@@ -27717,10 +27733,18 @@ class RichTextEditPlugin {
|
|
|
27717
27733
|
return;
|
|
27718
27734
|
}
|
|
27719
27735
|
const { placeholder, placeholderColor = 'rgba(0, 0, 0, 0.6)', placeholderFontFamily, placeholderFontSize } = editOptions;
|
|
27720
|
-
const shadow = this.
|
|
27721
|
-
|
|
27722
|
-
|
|
27723
|
-
|
|
27736
|
+
const shadow = this.getShadow(this.currRt);
|
|
27737
|
+
const textConfigItem = Object.assign(Object.assign({}, getDefaultCharacterConfig(this.currRt.attribute)), { text: placeholder });
|
|
27738
|
+
if (placeholderColor) {
|
|
27739
|
+
textConfigItem.fill = placeholderColor;
|
|
27740
|
+
}
|
|
27741
|
+
if (placeholderFontFamily) {
|
|
27742
|
+
textConfigItem.fontFamily = placeholderFontFamily;
|
|
27743
|
+
}
|
|
27744
|
+
if (placeholderFontSize) {
|
|
27745
|
+
textConfigItem.fontSize = placeholderFontSize;
|
|
27746
|
+
}
|
|
27747
|
+
this.shadowPlaceHolder = createRichText(Object.assign(Object.assign({}, this.currRt.attribute), { x: 0, y: 0, pickable: false, editable: false, editOptions: null, angle: 0, _debug_bounds: false, textConfig: [textConfigItem] }));
|
|
27724
27748
|
shadow.add(this.shadowPlaceHolder);
|
|
27725
27749
|
}
|
|
27726
27750
|
tryShowInputBounds() {
|
|
@@ -27733,11 +27757,12 @@ class RichTextEditPlugin {
|
|
|
27733
27757
|
return;
|
|
27734
27758
|
}
|
|
27735
27759
|
const { attribute } = this.currRt;
|
|
27736
|
-
|
|
27760
|
+
let b = this.currRt.AABBBounds;
|
|
27737
27761
|
let h = b.height();
|
|
27738
27762
|
if (!attribute.textConfig.length && this.editLine) {
|
|
27739
27763
|
const { points } = this.editLine.attribute;
|
|
27740
27764
|
h = points[1].y - points[0].y;
|
|
27765
|
+
b = getRichTextBounds(Object.assign({}, this.shadowPlaceHolder.attribute));
|
|
27741
27766
|
}
|
|
27742
27767
|
this.shadowBounds = this.shadowBounds || createRect({});
|
|
27743
27768
|
this.shadowBounds.setAttributes({
|
|
@@ -27748,10 +27773,9 @@ class RichTextEditPlugin {
|
|
|
27748
27773
|
fill: false,
|
|
27749
27774
|
stroke: boundsStrokeWhenInput,
|
|
27750
27775
|
lineWidth: 1,
|
|
27751
|
-
boundsMode: 'empty',
|
|
27752
27776
|
zIndex: -1
|
|
27753
27777
|
});
|
|
27754
|
-
const shadow = this.
|
|
27778
|
+
const shadow = this.getShadow(this.currRt);
|
|
27755
27779
|
shadow.add(this.shadowBounds);
|
|
27756
27780
|
this.offsetLineBgAndShadowBounds();
|
|
27757
27781
|
}
|
|
@@ -27763,7 +27787,7 @@ class RichTextEditPlugin {
|
|
|
27763
27787
|
if (textConfig && textConfig.length) {
|
|
27764
27788
|
return;
|
|
27765
27789
|
}
|
|
27766
|
-
if (!(editOptions && editOptions.placeholder)) {
|
|
27790
|
+
if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceHolderToTextConfig)) {
|
|
27767
27791
|
return;
|
|
27768
27792
|
}
|
|
27769
27793
|
const { placeholder } = editOptions;
|
|
@@ -27782,6 +27806,7 @@ class RichTextEditPlugin {
|
|
|
27782
27806
|
application.global.addEventListener('keydown', this.handleKeyDown);
|
|
27783
27807
|
}
|
|
27784
27808
|
onFocus(e, data) {
|
|
27809
|
+
this.updateCbs && this.updateCbs.forEach(cb => cb('beforeOnfocus', this));
|
|
27785
27810
|
this.deFocus(false);
|
|
27786
27811
|
this.focusing = true;
|
|
27787
27812
|
const target = e.target;
|
|
@@ -27790,7 +27815,7 @@ class RichTextEditPlugin {
|
|
|
27790
27815
|
}
|
|
27791
27816
|
this.currRt = target;
|
|
27792
27817
|
RichTextEditPlugin.tryUpdateRichtext(target);
|
|
27793
|
-
const shadowRoot =
|
|
27818
|
+
const shadowRoot = this.getShadow(target);
|
|
27794
27819
|
const cache = target.getFrameCache();
|
|
27795
27820
|
if (!cache) {
|
|
27796
27821
|
return;
|
|
@@ -27798,11 +27823,11 @@ class RichTextEditPlugin {
|
|
|
27798
27823
|
this.computeGlobalDelta(cache);
|
|
27799
27824
|
shadowRoot.setAttributes({ shadowRootIdx: 1, pickable: false, x: this.deltaX, y: this.deltaY });
|
|
27800
27825
|
if (!this.editLine) {
|
|
27801
|
-
const line = createLine({ x: 0, y: 0, lineWidth: 1, stroke: 'black'
|
|
27826
|
+
const line = createLine({ x: 0, y: 0, lineWidth: 1, stroke: 'black' });
|
|
27802
27827
|
this.addAnimateToLine(line);
|
|
27803
27828
|
this.editLine = line;
|
|
27804
27829
|
this.ticker.start(true);
|
|
27805
|
-
const g = createGroup({ x: 0, y: 0, width: 0, height: 0
|
|
27830
|
+
const g = createGroup({ x: 0, y: 0, width: 0, height: 0 });
|
|
27806
27831
|
this.editBg = g;
|
|
27807
27832
|
shadowRoot.add(this.editLine);
|
|
27808
27833
|
shadowRoot.add(this.editBg);
|
|
@@ -27857,6 +27882,7 @@ class RichTextEditPlugin {
|
|
|
27857
27882
|
if (!target) {
|
|
27858
27883
|
return;
|
|
27859
27884
|
}
|
|
27885
|
+
this.updateCbs && this.updateCbs.forEach(cb => cb('beforeDefocus', this, { trulyDeFocus }));
|
|
27860
27886
|
if (trulyDeFocus) {
|
|
27861
27887
|
this.trySyncPlaceholderToTextConfig();
|
|
27862
27888
|
target.detachShadow();
|
|
@@ -27953,6 +27979,9 @@ class RichTextEditPlugin {
|
|
|
27953
27979
|
};
|
|
27954
27980
|
let line0Info = this.getLineByPoint(cache, startCursorPos);
|
|
27955
27981
|
let line1Info = this.getLineByPoint(cache, endCursorPos);
|
|
27982
|
+
if (!line0Info || !line1Info) {
|
|
27983
|
+
return;
|
|
27984
|
+
}
|
|
27956
27985
|
if (startCursorPos.y > endCursorPos.y ||
|
|
27957
27986
|
(startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x)) {
|
|
27958
27987
|
[startCursorPos, endCursorPos] = [endCursorPos, startCursorPos];
|
|
@@ -28023,6 +28052,11 @@ class RichTextEditPlugin {
|
|
|
28023
28052
|
this.editBg.setAttributes({ fill: 'transparent' });
|
|
28024
28053
|
}
|
|
28025
28054
|
}
|
|
28055
|
+
getShadow(rt) {
|
|
28056
|
+
const sr = rt.shadowRoot || rt.attachShadow();
|
|
28057
|
+
sr.setAttributes({ boundsMode: 'empty' });
|
|
28058
|
+
return sr;
|
|
28059
|
+
}
|
|
28026
28060
|
getLineByPoint(cache, p1) {
|
|
28027
28061
|
let lineInfo = cache.lines[0];
|
|
28028
28062
|
for (let i = 0; i < cache.lines.length; i++) {
|
package/es/animate/index.js
CHANGED
package/es/graphic/group.js
CHANGED
|
@@ -66,7 +66,7 @@ export class Group extends Graphic {
|
|
|
66
66
|
application.graphicService.beforeUpdateAABBBounds(this, this.stage, !0, this._AABBBounds);
|
|
67
67
|
const selfChange = this.shouldSelfChangeUpdateAABBBounds(), bounds = this.doUpdateAABBBounds();
|
|
68
68
|
return this.addUpdateLayoutTag(), application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange),
|
|
69
|
-
bounds;
|
|
69
|
+
"empty" === this.attribute.boundsMode && bounds.clear(), bounds;
|
|
70
70
|
}
|
|
71
71
|
doUpdateLocalMatrix() {
|
|
72
72
|
const {x: x = DefaultTransform.x, y: y = DefaultTransform.y, dx: dx = DefaultTransform.dx, dy: dy = DefaultTransform.dy, scaleX: scaleX = DefaultTransform.scaleX, scaleY: scaleY = DefaultTransform.scaleY, angle: angle = DefaultTransform.angle, postMatrix: postMatrix} = this.attribute;
|
package/es/graphic/group.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/group.ts"],"names":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nC,CAAC;;AArXM,yBAAmB,GAAG,mBAAmB,CAAC;AAwXnD,MAAM,UAAU,WAAW,CAAC,UAAkC;IAC5D,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC","file":"group.js","sourcesContent":["import type { IAABBBounds, Matrix } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { Point } from '@visactor/vutils';\nimport { application } from '../application';\nimport type {\n IStage,\n GraphicAttributeMap,\n INode,\n IGraphic,\n ITheme,\n IThemeSpec,\n ILayer,\n GraphicType\n} from '../interface';\nimport type { IGroup, IGroupGraphicAttribute } from '../interface/graphic/group';\nimport { Graphic, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme, Theme } from './theme';\nimport { UpdateTag, IContainPointMode } from '../common/enums';\nimport { GROUP_NUMBER_TYPE } from './constants';\nimport { DefaultTransform } from './config';\n\n// Group更新AABBBounds的策略\nexport enum GroupUpdateAABBBoundsMode {\n // Group较少的情况,不会批量设置所有父层的tag,而是每次都查找\n LESS_GROUP = 0,\n // Group较多的情况,每次都会设置tag到最顶层\n MORE_GROUP = 1\n}\n\nexport class Group extends Graphic<IGroupGraphicAttribute> implements IGroup {\n type: GraphicType = 'group';\n parent: any = null;\n isContainer: boolean = true;\n // 子元素的更新标记\n declare _childUpdateTag: number;\n\n declare theme?: ITheme;\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IGroupGraphicAttribute) {\n super(params);\n this.numberType = GROUP_NUMBER_TYPE;\n this._childUpdateTag = UpdateTag.UPDATE_BOUNDS;\n // this.theme = new Theme();\n }\n\n setMode(mode: '2d' | '3d') {\n mode === '3d' ? this.set3dMode() : this.set2dMode();\n }\n\n set3dMode() {\n this.in3dMode = true;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('3d');\n // });\n }\n set2dMode() {\n this.in3dMode = false;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('2d');\n // });\n }\n\n setTheme(t: IThemeSpec) {\n if (!this.theme) {\n this.theme = new Theme();\n }\n return this.theme.setTheme(t, this);\n }\n\n createTheme() {\n if (!this.theme) {\n this.theme = new Theme();\n }\n }\n\n visibleAll(visible: boolean) {\n this.setAttribute('visible', visible);\n this.forEachChildren((item: IGraphic) => {\n if (item.isContainer && (item as any).visibleAll) {\n (item as any).visibleAll(visible);\n } else {\n item.setAttribute('visible', visible);\n }\n });\n }\n\n hideAll() {\n this.visibleAll(false);\n }\n\n showAll() {\n this.visibleAll(true);\n }\n\n /**\n * 是否包含某个点(点需要是全局坐标系)\n * group containsPoint 只需要判断bounds\n * TODO: group的shape判断\n * @param x\n * @param y\n * @param mode\n * @returns\n */\n containsPoint(x: number, y: number, mode: IContainPointMode): boolean {\n if (mode === IContainPointMode.GLOBAL) {\n // 转换x,y更精准\n const point = new Point(x, y);\n if (this.parent) {\n this.parent.globalTransMatrix.transformPoint(point, point);\n }\n return this.AABBBounds.contains(point.x, point.y);\n }\n return this.AABBBounds.contains(x, y);\n }\n\n shouldUpdateAABBBounds(): boolean {\n // 检索自己是否需要更新\n if (super.shouldUpdateAABBBounds()) {\n return true;\n }\n // 检索叶子节点是否有更新(如果children是叶子节点的话)\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return true;\n }\n return false;\n // // 检索是否子group需要更新\n // let needUpdate = false;\n // this.forEachChildren((node: IGraphic) => {\n // // 只查找group层级\n // if (node.isContainer && (node as Group).shouldUpdateAABBBounds()) {\n // needUpdate = true;\n // return true;\n // }\n // return false;\n // });\n // return needUpdate;\n }\n\n protected tryUpdateAABBBounds(): IAABBBounds {\n if (!this.shouldUpdateAABBBounds()) {\n return this._AABBBounds;\n }\n application.graphicService.beforeUpdateAABBBounds(this, this.stage, true, this._AABBBounds);\n const selfChange = this.shouldSelfChangeUpdateAABBBounds();\n const bounds = this.doUpdateAABBBounds();\n this.addUpdateLayoutTag();\n application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange);\n return bounds;\n }\n\n /**\n * 大部分group不需要更新matrix,这里特殊优化一下\n * 更新局部matrix的具体函数\n */\n protected doUpdateLocalMatrix() {\n const {\n x = DefaultTransform.x,\n y = DefaultTransform.y,\n dx = DefaultTransform.dx,\n dy = DefaultTransform.dy,\n scaleX = DefaultTransform.scaleX,\n scaleY = DefaultTransform.scaleY,\n angle = DefaultTransform.angle,\n postMatrix\n } = this.attribute;\n if (x === 0 && y === 0 && dx === 0 && dy === 0 && scaleX === 1 && scaleY === 1 && angle === 0 && !postMatrix) {\n this._transMatrix.reset();\n return;\n }\n return super.doUpdateLocalMatrix();\n }\n\n getGraphicTheme(): Required<IGroupGraphicAttribute> {\n return getTheme(this).group;\n }\n\n protected updateAABBBounds(\n attribute: IGroupGraphicAttribute,\n groupTheme: Required<IGroupGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n const originalAABBBounds = aabbBounds; // fix aabbbounds update error in flex layout\n aabbBounds = aabbBounds.clone();\n\n const { width, height, path, clip = groupTheme.clip } = attribute;\n // 添加自身的fill或者clip\n if (path && path.length) {\n path.forEach(g => {\n aabbBounds.union(g.AABBBounds);\n });\n } else if (width != null && height != null) {\n aabbBounds.set(0, 0, Math.max(0, width), Math.max(0, height)); // fix bounds set when auto size in vtable\n }\n if (!clip) {\n // 添加子节点\n this.forEachChildren((node: IGraphic) => {\n aabbBounds.union(node.AABBBounds);\n });\n // 如果没有clip的话,还需要加一下scroll\n const { scrollX = 0, scrollY = 0 } = attribute;\n aabbBounds.translate(scrollX, scrollY);\n }\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, groupTheme, false, this);\n\n originalAABBBounds.copy(aabbBounds);\n return originalAABBBounds;\n }\n\n protected doUpdateAABBBounds(): IAABBBounds {\n this.updateAABBBoundsStamp++;\n const bounds = super.doUpdateAABBBounds();\n\n // 更新bounds之后需要设置父节点,否则tag丢失\n this.parent && this.parent.addChildUpdateBoundTag();\n this._emitCustomEvent('AAABBBoundsChange');\n\n return bounds;\n }\n\n protected clearUpdateBoundTag() {\n this._updateTag &= UpdateTag.CLEAR_BOUNDS;\n this._childUpdateTag &= UpdateTag.CLEAR_BOUNDS;\n }\n\n addUpdateBoundTag() {\n this._updateTag |= UpdateTag.UPDATE_BOUNDS; // for bounds\n if (this.parent) {\n this.parent.addChildUpdateBoundTag();\n }\n }\n\n addChildUpdateBoundTag() {\n // 如果已经设置过updateTag,那就不需要设置了\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return;\n }\n // 如果没有设置过,那么继续向上设置\n this._childUpdateTag |= UpdateTag.UPDATE_BOUNDS;\n this.parent && this.parent.addChildUpdateBoundTag();\n }\n\n getTheme() {\n return this.theme.getTheme(this);\n }\n\n /* 场景树结构 */\n incrementalAppendChild(node: INode): INode | null {\n const data = super.appendChild(node);\n if (this.stage && data) {\n (data as unknown as this).stage = this.stage;\n (data as unknown as this).layer = this.layer;\n }\n this.addUpdateBoundTag();\n application.graphicService.onAddIncremental(node as unknown as IGraphic, this, this.stage);\n return data;\n }\n incrementalClearChild(): void {\n super.removeAllChild();\n this.addUpdateBoundTag();\n application.graphicService.onClearIncremental(this, this.stage);\n return;\n }\n\n protected _updateChildToStage(child: IGraphic) {\n if (this.stage && child) {\n child.setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return child;\n }\n // TODO 代码优化\n appendChild(node: INode, addStage: boolean = true): INode | null {\n const data = super.appendChild(node);\n if (addStage && this.stage && data) {\n (data as unknown as this).setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return data;\n }\n insertBefore(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertBefore(newNode, referenceNode) as undefined as IGraphic);\n }\n insertAfter(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertAfter(newNode, referenceNode) as undefined as IGraphic);\n }\n insertInto(newNode: INode, idx: number): INode | null {\n return this._updateChildToStage(super.insertInto(newNode, idx) as undefined as IGraphic);\n }\n\n removeChild(child: IGraphic): IGraphic {\n const data = super.removeChild(child);\n child.stage = null;\n application.graphicService.onRemove(child);\n this.addUpdateBoundTag();\n return data as IGraphic;\n }\n\n removeAllChild(deep: boolean = false): void {\n this.forEachChildren((child: IGraphic) => {\n application.graphicService.onRemove(child);\n if (deep && child.isContainer) {\n child.removeAllChild(deep);\n }\n });\n super.removeAllChild();\n this.addUpdateBoundTag();\n }\n\n setStage(stage?: IStage, layer?: ILayer) {\n if (this.stage !== stage) {\n this.stage = stage;\n this.layer = layer;\n this.setStageToShadowRoot(stage, layer);\n this._onSetStage && this._onSetStage(this, stage, layer);\n application.graphicService.onSetStage(this, stage);\n this.forEachChildren(item => {\n (item as any).setStage(stage, this.layer);\n });\n }\n }\n /**\n * 更新位置tag,包括全局tag和局部tag\n */\n addUpdatePositionTag() {\n super.addUpdatePositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * 更新全局位置tag\n */\n addUpdateGlobalPositionTag() {\n super.addUpdateGlobalPositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * group更新全局的transMatrix\n * @param clearTag\n * @returns\n */\n protected tryUpdateGlobalTransMatrix(clearTag: boolean = true): Matrix {\n if (this.shouldUpdateGlobalMatrix()) {\n if (!this._globalTransMatrix) {\n this._globalTransMatrix = this.parent\n ? (this.parent as IGroup).globalTransMatrix.clone()\n : this.transMatrix.clone();\n } else if (this.parent) {\n const m = (this.parent as IGroup).globalTransMatrix;\n this._globalTransMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n }\n this.doUpdateGlobalMatrix();\n clearTag && this.clearUpdateGlobalPositionTag();\n }\n return this._globalTransMatrix;\n }\n /**\n * 查找自身更新global的tag,如果存在,就更新\n * @returns\n */\n shouldUpdateGlobalMatrix(): boolean {\n const shouldUpdate = !!(this._updateTag & UpdateTag.UPDATE_GLOBAL_MATRIX);\n return shouldUpdate;\n }\n\n private _getChildByName<T extends INode = INode>(name: string, deep?: boolean): T | null {\n return this.find(node => node.name === name, deep);\n }\n\n /**\n * if graphic exist then update attributes, otherwise create a new instance\n * @param graphicName the name of graphic\n * @param attributes the attributes of graphic\n * @param graphicType the type of graphic\n * @returns the graphic instance\n */\n createOrUpdateChild<T extends keyof GraphicAttributeMap>(\n graphicName: string,\n attributes: GraphicAttributeMap[T],\n graphicType: T\n ): INode {\n let graphic = this._getChildByName(graphicName) as IGraphic;\n if (graphic) {\n graphic.setAttributes(attributes);\n } else {\n graphic = application.graphicService.creator[graphicType](attributes as any);\n graphic.name = graphicName;\n this.add(graphic);\n }\n\n return graphic;\n }\n\n clone() {\n return new Group({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Group.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createGroup(attributes: IGroupGraphicAttribute): IGroup {\n return new Group(attributes);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/graphic/group.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAY7C,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C,MAAM,CAAN,IAAY,yBAKX;AALD,WAAY,yBAAyB;IAEnC,qFAAc,CAAA;IAEd,qFAAc,CAAA;AAChB,CAAC,EALW,yBAAy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AAC,UAAU,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAC;QAC1E,OAAO,YAAY,CAAC;IACtB,CAAC;IAEO,eAAe,CAA0B,IAAY,EAAE,IAAc;QAC3E,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC;IASD,mBAAmB,CACjB,WAAmB,EACnB,UAAkC,EAClC,WAAc;QAEd,IAAI,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAa,CAAC;QAC5D,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;SACnC;aAAM;YACL,OAAO,GAAG,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,UAAiB,CAAC,CAAC;YAC7E,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC;YAC3B,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SACnB;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,KAAK,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IAC1C,CAAC;IAED,oBAAoB;QAClB,OAAO,KAAK,CAAC,mBAAmB,CAAC;IACnC,CAAC;;AAzXM,yBAAmB,GAAG,mBAAmB,CAAC;AA4XnD,MAAM,UAAU,WAAW,CAAC,UAAkC;IAC5D,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC","file":"group.js","sourcesContent":["import type { IAABBBounds, Matrix } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { Point } from '@visactor/vutils';\nimport { application } from '../application';\nimport type {\n IStage,\n GraphicAttributeMap,\n INode,\n IGraphic,\n ITheme,\n IThemeSpec,\n ILayer,\n GraphicType\n} from '../interface';\nimport type { IGroup, IGroupGraphicAttribute } from '../interface/graphic/group';\nimport { Graphic, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme, Theme } from './theme';\nimport { UpdateTag, IContainPointMode } from '../common/enums';\nimport { GROUP_NUMBER_TYPE } from './constants';\nimport { DefaultTransform } from './config';\n\n// Group更新AABBBounds的策略\nexport enum GroupUpdateAABBBoundsMode {\n // Group较少的情况,不会批量设置所有父层的tag,而是每次都查找\n LESS_GROUP = 0,\n // Group较多的情况,每次都会设置tag到最顶层\n MORE_GROUP = 1\n}\n\nexport class Group extends Graphic<IGroupGraphicAttribute> implements IGroup {\n type: GraphicType = 'group';\n parent: any = null;\n isContainer: boolean = true;\n // 子元素的更新标记\n declare _childUpdateTag: number;\n\n declare theme?: ITheme;\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IGroupGraphicAttribute) {\n super(params);\n this.numberType = GROUP_NUMBER_TYPE;\n this._childUpdateTag = UpdateTag.UPDATE_BOUNDS;\n // this.theme = new Theme();\n }\n\n setMode(mode: '2d' | '3d') {\n mode === '3d' ? this.set3dMode() : this.set2dMode();\n }\n\n set3dMode() {\n this.in3dMode = true;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('3d');\n // });\n }\n set2dMode() {\n this.in3dMode = false;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('2d');\n // });\n }\n\n setTheme(t: IThemeSpec) {\n if (!this.theme) {\n this.theme = new Theme();\n }\n return this.theme.setTheme(t, this);\n }\n\n createTheme() {\n if (!this.theme) {\n this.theme = new Theme();\n }\n }\n\n visibleAll(visible: boolean) {\n this.setAttribute('visible', visible);\n this.forEachChildren((item: IGraphic) => {\n if (item.isContainer && (item as any).visibleAll) {\n (item as any).visibleAll(visible);\n } else {\n item.setAttribute('visible', visible);\n }\n });\n }\n\n hideAll() {\n this.visibleAll(false);\n }\n\n showAll() {\n this.visibleAll(true);\n }\n\n /**\n * 是否包含某个点(点需要是全局坐标系)\n * group containsPoint 只需要判断bounds\n * TODO: group的shape判断\n * @param x\n * @param y\n * @param mode\n * @returns\n */\n containsPoint(x: number, y: number, mode: IContainPointMode): boolean {\n if (mode === IContainPointMode.GLOBAL) {\n // 转换x,y更精准\n const point = new Point(x, y);\n if (this.parent) {\n this.parent.globalTransMatrix.transformPoint(point, point);\n }\n return this.AABBBounds.contains(point.x, point.y);\n }\n return this.AABBBounds.contains(x, y);\n }\n\n shouldUpdateAABBBounds(): boolean {\n // 检索自己是否需要更新\n if (super.shouldUpdateAABBBounds()) {\n return true;\n }\n // 检索叶子节点是否有更新(如果children是叶子节点的话)\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return true;\n }\n return false;\n // // 检索是否子group需要更新\n // let needUpdate = false;\n // this.forEachChildren((node: IGraphic) => {\n // // 只查找group层级\n // if (node.isContainer && (node as Group).shouldUpdateAABBBounds()) {\n // needUpdate = true;\n // return true;\n // }\n // return false;\n // });\n // return needUpdate;\n }\n\n protected tryUpdateAABBBounds(): IAABBBounds {\n if (!this.shouldUpdateAABBBounds()) {\n return this._AABBBounds;\n }\n application.graphicService.beforeUpdateAABBBounds(this, this.stage, true, this._AABBBounds);\n const selfChange = this.shouldSelfChangeUpdateAABBBounds();\n const bounds = this.doUpdateAABBBounds();\n this.addUpdateLayoutTag();\n application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange);\n // 直接返回空Bounds,但是前面的流程还是要走\n if (this.attribute.boundsMode === 'empty') {\n bounds.clear();\n }\n return bounds;\n }\n\n /**\n * 大部分group不需要更新matrix,这里特殊优化一下\n * 更新局部matrix的具体函数\n */\n protected doUpdateLocalMatrix() {\n const {\n x = DefaultTransform.x,\n y = DefaultTransform.y,\n dx = DefaultTransform.dx,\n dy = DefaultTransform.dy,\n scaleX = DefaultTransform.scaleX,\n scaleY = DefaultTransform.scaleY,\n angle = DefaultTransform.angle,\n postMatrix\n } = this.attribute;\n if (x === 0 && y === 0 && dx === 0 && dy === 0 && scaleX === 1 && scaleY === 1 && angle === 0 && !postMatrix) {\n this._transMatrix.reset();\n return;\n }\n return super.doUpdateLocalMatrix();\n }\n\n getGraphicTheme(): Required<IGroupGraphicAttribute> {\n return getTheme(this).group;\n }\n\n protected updateAABBBounds(\n attribute: IGroupGraphicAttribute,\n groupTheme: Required<IGroupGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n const originalAABBBounds = aabbBounds; // fix aabbbounds update error in flex layout\n aabbBounds = aabbBounds.clone();\n\n const { width, height, path, clip = groupTheme.clip } = attribute;\n // 添加自身的fill或者clip\n if (path && path.length) {\n path.forEach(g => {\n aabbBounds.union(g.AABBBounds);\n });\n } else if (width != null && height != null) {\n aabbBounds.set(0, 0, Math.max(0, width), Math.max(0, height)); // fix bounds set when auto size in vtable\n }\n if (!clip) {\n // 添加子节点\n this.forEachChildren((node: IGraphic) => {\n aabbBounds.union(node.AABBBounds);\n });\n // 如果没有clip的话,还需要加一下scroll\n const { scrollX = 0, scrollY = 0 } = attribute;\n aabbBounds.translate(scrollX, scrollY);\n }\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, groupTheme, false, this);\n\n originalAABBBounds.copy(aabbBounds);\n return originalAABBBounds;\n }\n\n protected doUpdateAABBBounds(): IAABBBounds {\n this.updateAABBBoundsStamp++;\n const bounds = super.doUpdateAABBBounds();\n\n // 更新bounds之后需要设置父节点,否则tag丢失\n this.parent && this.parent.addChildUpdateBoundTag();\n this._emitCustomEvent('AAABBBoundsChange');\n\n return bounds;\n }\n\n protected clearUpdateBoundTag() {\n this._updateTag &= UpdateTag.CLEAR_BOUNDS;\n this._childUpdateTag &= UpdateTag.CLEAR_BOUNDS;\n }\n\n addUpdateBoundTag() {\n this._updateTag |= UpdateTag.UPDATE_BOUNDS; // for bounds\n if (this.parent) {\n this.parent.addChildUpdateBoundTag();\n }\n }\n\n addChildUpdateBoundTag() {\n // 如果已经设置过updateTag,那就不需要设置了\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return;\n }\n // 如果没有设置过,那么继续向上设置\n this._childUpdateTag |= UpdateTag.UPDATE_BOUNDS;\n this.parent && this.parent.addChildUpdateBoundTag();\n }\n\n getTheme() {\n return this.theme.getTheme(this);\n }\n\n /* 场景树结构 */\n incrementalAppendChild(node: INode): INode | null {\n const data = super.appendChild(node);\n if (this.stage && data) {\n (data as unknown as this).stage = this.stage;\n (data as unknown as this).layer = this.layer;\n }\n this.addUpdateBoundTag();\n application.graphicService.onAddIncremental(node as unknown as IGraphic, this, this.stage);\n return data;\n }\n incrementalClearChild(): void {\n super.removeAllChild();\n this.addUpdateBoundTag();\n application.graphicService.onClearIncremental(this, this.stage);\n return;\n }\n\n protected _updateChildToStage(child: IGraphic) {\n if (this.stage && child) {\n child.setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return child;\n }\n // TODO 代码优化\n appendChild(node: INode, addStage: boolean = true): INode | null {\n const data = super.appendChild(node);\n if (addStage && this.stage && data) {\n (data as unknown as this).setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return data;\n }\n insertBefore(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertBefore(newNode, referenceNode) as undefined as IGraphic);\n }\n insertAfter(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertAfter(newNode, referenceNode) as undefined as IGraphic);\n }\n insertInto(newNode: INode, idx: number): INode | null {\n return this._updateChildToStage(super.insertInto(newNode, idx) as undefined as IGraphic);\n }\n\n removeChild(child: IGraphic): IGraphic {\n const data = super.removeChild(child);\n child.stage = null;\n application.graphicService.onRemove(child);\n this.addUpdateBoundTag();\n return data as IGraphic;\n }\n\n removeAllChild(deep: boolean = false): void {\n this.forEachChildren((child: IGraphic) => {\n application.graphicService.onRemove(child);\n if (deep && child.isContainer) {\n child.removeAllChild(deep);\n }\n });\n super.removeAllChild();\n this.addUpdateBoundTag();\n }\n\n setStage(stage?: IStage, layer?: ILayer) {\n if (this.stage !== stage) {\n this.stage = stage;\n this.layer = layer;\n this.setStageToShadowRoot(stage, layer);\n this._onSetStage && this._onSetStage(this, stage, layer);\n application.graphicService.onSetStage(this, stage);\n this.forEachChildren(item => {\n (item as any).setStage(stage, this.layer);\n });\n }\n }\n /**\n * 更新位置tag,包括全局tag和局部tag\n */\n addUpdatePositionTag() {\n super.addUpdatePositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * 更新全局位置tag\n */\n addUpdateGlobalPositionTag() {\n super.addUpdateGlobalPositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * group更新全局的transMatrix\n * @param clearTag\n * @returns\n */\n protected tryUpdateGlobalTransMatrix(clearTag: boolean = true): Matrix {\n if (this.shouldUpdateGlobalMatrix()) {\n if (!this._globalTransMatrix) {\n this._globalTransMatrix = this.parent\n ? (this.parent as IGroup).globalTransMatrix.clone()\n : this.transMatrix.clone();\n } else if (this.parent) {\n const m = (this.parent as IGroup).globalTransMatrix;\n this._globalTransMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n }\n this.doUpdateGlobalMatrix();\n clearTag && this.clearUpdateGlobalPositionTag();\n }\n return this._globalTransMatrix;\n }\n /**\n * 查找自身更新global的tag,如果存在,就更新\n * @returns\n */\n shouldUpdateGlobalMatrix(): boolean {\n const shouldUpdate = !!(this._updateTag & UpdateTag.UPDATE_GLOBAL_MATRIX);\n return shouldUpdate;\n }\n\n private _getChildByName<T extends INode = INode>(name: string, deep?: boolean): T | null {\n return this.find(node => node.name === name, deep);\n }\n\n /**\n * if graphic exist then update attributes, otherwise create a new instance\n * @param graphicName the name of graphic\n * @param attributes the attributes of graphic\n * @param graphicType the type of graphic\n * @returns the graphic instance\n */\n createOrUpdateChild<T extends keyof GraphicAttributeMap>(\n graphicName: string,\n attributes: GraphicAttributeMap[T],\n graphicType: T\n ): INode {\n let graphic = this._getChildByName(graphicName) as IGraphic;\n if (graphic) {\n graphic.setAttributes(attributes);\n } else {\n graphic = application.graphicService.creator[graphicType](attributes as any);\n graphic.name = graphicName;\n this.add(graphic);\n }\n\n return graphic;\n }\n\n clone() {\n return new Group({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Group.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createGroup(attributes: IGroupGraphicAttribute): IGroup {\n return new Group(attributes);\n}\n"]}
|
|
@@ -3,12 +3,11 @@ import { calculateLineHeight } from "../../common/utils";
|
|
|
3
3
|
import { measureTextCanvas, getStrByWithCanvas } from "./utils";
|
|
4
4
|
|
|
5
5
|
function getFixedLRTB(left, right, top, bottom) {
|
|
6
|
-
const leftInt = Math.round(left), topInt = Math.round(top), rightInt = Math.round(right), bottomInt = Math.round(bottom);
|
|
7
6
|
return {
|
|
8
|
-
left: left
|
|
9
|
-
top: top
|
|
10
|
-
right:
|
|
11
|
-
bottom:
|
|
7
|
+
left: Math.round(left),
|
|
8
|
+
top: Math.round(top),
|
|
9
|
+
right: Math.round(right),
|
|
10
|
+
bottom: Math.round(bottom)
|
|
12
11
|
};
|
|
13
12
|
}
|
|
14
13
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEhE,SAAS,YAAY,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW,EAAE,MAAc;IAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAA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YAAY,EAAE,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YAC1F,OAAO,KAAK,GAAG,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;SAClD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAAC,SAAoB,EAAE,KAAa;IACnE,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACxE,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAE3D,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC","file":"paragraph.js","sourcesContent":["import { calculateLineHeight } from '../../common/utils';\nimport type { IContext2d, IRichTextParagraphCharacter } from '../../interface';\nimport { measureTextCanvas, getStrByWithCanvas } from './utils';\n\nfunction getFixedLRTB(left: number, right: number, top: number, bottom: number) {\n const leftInt = Math.round(left);\n const topInt = Math.round(top);\n const rightInt = Math.round(right);\n const bottomInt = Math.round(bottom);\n const _left = left > leftInt ? leftInt : leftInt - 0.5;\n const _top = top > topInt ? topInt : topInt - 0.5;\n const _right = rightInt > right ? rightInt : rightInt + 0.5;\n const _bottom = bottomInt > bottom ? bottomInt : bottomInt + 0.5;\n return {\n left: _left,\n top: _top,\n right: _right,\n bottom: _bottom\n };\n}\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 文字段\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/text.js\nexport default class Paragraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n // rotate?: number;\n direction?: 'horizontal' | 'vertical';\n // bounds?: Bounds;\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisStr: string;\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n overflow?: boolean;\n\n constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\n\n // 处理行高:\n // lineHeight为数字时,大于fontSize取lineHeight,小于fontSize时取fontSize\n // lineHeight不为数字时,统一认为lineHeight为'normal',值取1.2 * fontSize\n const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);\n if (typeof lineHeight === 'number') {\n this.lineHeight = lineHeight > this.fontSize ? lineHeight : this.fontSize;\n } else {\n this.lineHeight = Math.floor(1.2 * this.fontSize);\n }\n\n this.height = this.lineHeight;\n\n const { ascent, height, descent, width } = measureTextCanvas(text, character);\n\n let halfDetaHeight = 0;\n let deltaAscent = 0;\n let deltaDescent = 0;\n if (this.height > height) {\n // measureTextCanvas测量出的是纯文字高度,this.height是考虑行高后的高度\n // 如果this.height > height,将超过的高度平均分配到ascent和descent上\n halfDetaHeight = (this.height - height) / 2;\n deltaAscent = Math.ceil(halfDetaHeight);\n deltaDescent = Math.floor(halfDetaHeight);\n }\n\n if (this.textBaseline === 'top') {\n this.ascent = halfDetaHeight;\n this.descent = height - halfDetaHeight;\n } else if (this.textBaseline === 'bottom') {\n this.ascent = height - halfDetaHeight;\n this.descent = halfDetaHeight;\n } else if (this.textBaseline === 'middle') {\n this.ascent = this.height / 2;\n this.descent = this.height / 2;\n } else {\n this.ascent = ascent + deltaAscent;\n this.descent = descent + deltaDescent;\n }\n\n this.length = text.length;\n this.width = width || 0;\n this.text = text || '';\n this.newLine = newLine || false;\n this.character = character;\n\n this.left = 0;\n this.top = 0;\n\n this.ellipsis = 'normal';\n this.ellipsisWidth = 0;\n this.ellipsisOtherParagraphWidth = 0;\n\n // 处理旋转\n if (character.direction === 'vertical') {\n this.direction = character.direction;\n this.widthOrigin = this.width;\n this.heightOrigin = this.height;\n // const bounds = new Bounds();\n // bounds.set(0, 0, this.width, this.height);\n // bounds.rotate(Math.PI / 2, this.width / 2, this.height / 2);\n // this.bounds = bounds;\n // this.width = bounds.width();\n // this.height = bounds.height();\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n this.lineHeight = this.height;\n }\n this.ellipsisStr = '...';\n }\n\n updateWidth() {\n const { width } = measureTextCanvas(this.text, this.character);\n this.width = width;\n if (this.direction === 'vertical') {\n this.widthOrigin = this.width;\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n }\n }\n\n drawBackground(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n if (!(this.character.background && (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0))) {\n return;\n }\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n const fillStyle = ctx.fillStyle;\n const globalAlpha = ctx.globalAlpha;\n ctx.fillStyle = this.character.background;\n if (this.character.backgroundOpacity !== void 0) {\n ctx.globalAlpha = this.character.backgroundOpacity;\n }\n // 背景稍微扩充一些buf,否则会出现白线\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + lineHeight;\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n ctx.fillStyle = fillStyle;\n ctx.globalAlpha = globalAlpha;\n }\n\n draw(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // if (isLineFirst) {\n // const result = regFirstSpace.exec(text);\n // if (result?.index !== 0) {\n // text = text.slice(result?.index);\n // }\n // }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n // if (this.character.fill) {\n // if (this.character.background && (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0)) {\n // const fillStyle = ctx.fillStyle;\n // const globalAlpha = ctx.globalAlpha;\n // ctx.fillStyle = this.character.background;\n // if (this.character.backgroundOpacity !== void 0) {\n // ctx.globalAlpha = this.character.backgroundOpacity;\n // }\n // // 背景稍微扩充一些buf,否则会出现白线\n // const right = left + (this.widthOrigin || this.width);\n // const bottom = top + lineHeight;\n // const lrtb = getFixedLRTB(left, right, top, bottom);\n // ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n // ctx.fillStyle = fillStyle;\n // ctx.globalAlpha = globalAlpha;\n // }\n // }\n\n const { lineWidth = 1 } = this.character;\n if (this.character.stroke && lineWidth) {\n ctx.strokeText(text, left, baseline);\n }\n\n if (this.character.fill) {\n ctx.fillText(text, left, baseline);\n }\n\n if (this.character.fill) {\n if (this.character.lineThrough || this.character.underline) {\n if (this.character.underline) {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n }\n if (this.character.lineThrough) {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n }\n } else if (this.character.textDecoration === 'underline') {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n } else if (this.character.textDecoration === 'line-through') {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n }\n }\n\n if (direction === 'vertical') {\n ctx.restore();\n }\n }\n\n getWidthWithEllips(direction: string): number {\n let text = this.text;\n // const direction = this.direction;\n const width = direction === 'vertical' ? this.height : this.width;\n // const height = direction === 'vertical' ? this.width: this.height;\n\n if (this.ellipsis === 'hide') {\n return width;\n } else if (this.ellipsis === 'add') {\n return width + this.ellipsisWidth;\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n const { width: measureWidth } = measureTextCanvas(this.text.slice(index), this.character);\n return width + this.ellipsisWidth - measureWidth;\n }\n return width;\n }\n}\n\nexport function seperateParagraph(paragraph: Paragraph, index: number) {\n const text1 = paragraph.text.slice(0, index);\n const text2 = paragraph.text.slice(index);\n const p1 = new Paragraph(text1, paragraph.newLine, paragraph.character);\n const p2 = new Paragraph(text2, true, paragraph.character);\n\n return [p1, p2];\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/graphic/richtext/paragraph.ts"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AI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YAC1F,OAAO,KAAK,GAAG,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;SAClD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAAC,SAAoB,EAAE,KAAa;IACnE,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACxE,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAE3D,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC","file":"paragraph.js","sourcesContent":["import { calculateLineHeight } from '../../common/utils';\nimport type { IContext2d, IRichTextParagraphCharacter } from '../../interface';\nimport { measureTextCanvas, getStrByWithCanvas } from './utils';\n\nfunction getFixedLRTB(left: number, right: number, top: number, bottom: number) {\n const leftInt = Math.round(left);\n const topInt = Math.round(top);\n const rightInt = Math.round(right);\n const bottomInt = Math.round(bottom);\n // 会导致背景色重叠\n // const _left = left > leftInt ? leftInt : leftInt - 0.5;\n // const _top = top > topInt ? topInt : topInt - 0.5;\n // const _right = rightInt > right ? rightInt : rightInt + 0.5;\n // const _bottom = bottomInt > bottom ? bottomInt : bottomInt + 0.5;\n return {\n left: leftInt,\n top: topInt,\n right: rightInt,\n bottom: bottomInt\n };\n}\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 文字段\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/text.js\nexport default class Paragraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n // rotate?: number;\n direction?: 'horizontal' | 'vertical';\n // bounds?: Bounds;\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisStr: string;\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n overflow?: boolean;\n\n constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\n\n // 处理行高:\n // lineHeight为数字时,大于fontSize取lineHeight,小于fontSize时取fontSize\n // lineHeight不为数字时,统一认为lineHeight为'normal',值取1.2 * fontSize\n const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);\n if (typeof lineHeight === 'number') {\n this.lineHeight = lineHeight > this.fontSize ? lineHeight : this.fontSize;\n } else {\n this.lineHeight = Math.floor(1.2 * this.fontSize);\n }\n\n this.height = this.lineHeight;\n\n const { ascent, height, descent, width } = measureTextCanvas(text, character);\n\n let halfDetaHeight = 0;\n let deltaAscent = 0;\n let deltaDescent = 0;\n if (this.height > height) {\n // measureTextCanvas测量出的是纯文字高度,this.height是考虑行高后的高度\n // 如果this.height > height,将超过的高度平均分配到ascent和descent上\n halfDetaHeight = (this.height - height) / 2;\n deltaAscent = Math.ceil(halfDetaHeight);\n deltaDescent = Math.floor(halfDetaHeight);\n }\n\n if (this.textBaseline === 'top') {\n this.ascent = halfDetaHeight;\n this.descent = height - halfDetaHeight;\n } else if (this.textBaseline === 'bottom') {\n this.ascent = height - halfDetaHeight;\n this.descent = halfDetaHeight;\n } else if (this.textBaseline === 'middle') {\n this.ascent = this.height / 2;\n this.descent = this.height / 2;\n } else {\n this.ascent = ascent + deltaAscent;\n this.descent = descent + deltaDescent;\n }\n\n this.length = text.length;\n this.width = width || 0;\n this.text = text || '';\n this.newLine = newLine || false;\n this.character = character;\n\n this.left = 0;\n this.top = 0;\n\n this.ellipsis = 'normal';\n this.ellipsisWidth = 0;\n this.ellipsisOtherParagraphWidth = 0;\n\n // 处理旋转\n if (character.direction === 'vertical') {\n this.direction = character.direction;\n this.widthOrigin = this.width;\n this.heightOrigin = this.height;\n // const bounds = new Bounds();\n // bounds.set(0, 0, this.width, this.height);\n // bounds.rotate(Math.PI / 2, this.width / 2, this.height / 2);\n // this.bounds = bounds;\n // this.width = bounds.width();\n // this.height = bounds.height();\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n this.lineHeight = this.height;\n }\n this.ellipsisStr = '...';\n }\n\n updateWidth() {\n const { width } = measureTextCanvas(this.text, this.character);\n this.width = width;\n if (this.direction === 'vertical') {\n this.widthOrigin = this.width;\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n }\n }\n\n drawBackground(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n if (!(this.character.background && (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0))) {\n return;\n }\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n const fillStyle = ctx.fillStyle;\n const globalAlpha = ctx.globalAlpha;\n ctx.fillStyle = this.character.background;\n if (this.character.backgroundOpacity !== void 0) {\n ctx.globalAlpha = this.character.backgroundOpacity;\n }\n // 背景稍微扩充一些buf,否则会出现白线\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + lineHeight;\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n ctx.fillStyle = fillStyle;\n ctx.globalAlpha = globalAlpha;\n }\n\n draw(\n ctx: IContext2d,\n top: number,\n ascent: number,\n deltaLeft: number,\n isLineFirst: boolean,\n textAlign: string,\n lineHeight: number\n ) {\n let baseline = top + ascent;\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = this.ellipsisStr;\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n left -= this.ellipsisWidth;\n }\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, this.width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n (direction === 'vertical' ? this.height : this.width) - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n if (textAlign === 'right' || textAlign === 'end') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // if (isLineFirst) {\n // const result = regFirstSpace.exec(text);\n // if (result?.index !== 0) {\n // text = text.slice(result?.index);\n // }\n // }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n // if (this.character.fill) {\n // if (this.character.background && (!this.character.backgroundOpacity || this.character.backgroundOpacity > 0)) {\n // const fillStyle = ctx.fillStyle;\n // const globalAlpha = ctx.globalAlpha;\n // ctx.fillStyle = this.character.background;\n // if (this.character.backgroundOpacity !== void 0) {\n // ctx.globalAlpha = this.character.backgroundOpacity;\n // }\n // // 背景稍微扩充一些buf,否则会出现白线\n // const right = left + (this.widthOrigin || this.width);\n // const bottom = top + lineHeight;\n // const lrtb = getFixedLRTB(left, right, top, bottom);\n // ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n // ctx.fillStyle = fillStyle;\n // ctx.globalAlpha = globalAlpha;\n // }\n // }\n\n const { lineWidth = 1 } = this.character;\n if (this.character.stroke && lineWidth) {\n ctx.strokeText(text, left, baseline);\n }\n\n if (this.character.fill) {\n ctx.fillText(text, left, baseline);\n }\n\n if (this.character.fill) {\n if (this.character.lineThrough || this.character.underline) {\n if (this.character.underline) {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n }\n if (this.character.lineThrough) {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n }\n } else if (this.character.textDecoration === 'underline') {\n const top = 1 + baseline;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n } else if (this.character.textDecoration === 'line-through') {\n const top = 1 + baseline - this.ascent / 2;\n const right = left + (this.widthOrigin || this.width);\n const bottom = top + (this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1);\n const lrtb = getFixedLRTB(left, right, top, bottom);\n ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);\n }\n }\n\n if (direction === 'vertical') {\n ctx.restore();\n }\n }\n\n getWidthWithEllips(direction: string): number {\n let text = this.text;\n // const direction = this.direction;\n const width = direction === 'vertical' ? this.height : this.width;\n // const height = direction === 'vertical' ? this.width: this.height;\n\n if (this.ellipsis === 'hide') {\n return width;\n } else if (this.ellipsis === 'add') {\n return width + this.ellipsisWidth;\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += this.ellipsisStr;\n\n const { width: measureWidth } = measureTextCanvas(this.text.slice(index), this.character);\n return width + this.ellipsisWidth - measureWidth;\n }\n return width;\n }\n}\n\nexport function seperateParagraph(paragraph: Paragraph, index: number) {\n const text1 = paragraph.text.slice(0, index);\n const text2 = paragraph.text.slice(index);\n const p1 = new Paragraph(text1, paragraph.newLine, paragraph.character);\n const p2 = new Paragraph(text2, true, paragraph.character);\n\n return [p1, p2];\n}\n"]}
|
package/es/graphic/richtext.d.ts
CHANGED
|
@@ -66,7 +66,8 @@ export declare class RichText extends Graphic<IRichTextGraphicAttribute> impleme
|
|
|
66
66
|
set textConfig(config: IRichTextCharacter[]);
|
|
67
67
|
getGraphicTheme(): Required<IRichTextGraphicAttribute>;
|
|
68
68
|
static AllSingleCharacter(cache: IRichTextFrame | IRichTextGraphicAttribute['textConfig']): boolean;
|
|
69
|
-
static
|
|
69
|
+
static splitEmoji(text: string): any[];
|
|
70
|
+
static splitText(text: string): any[];
|
|
70
71
|
static TransformTextConfig2SingleCharacter(textConfig: IRichTextGraphicAttribute['textConfig']): IRichTextCharacter[];
|
|
71
72
|
protected updateAABBBounds(attribute: IRichTextGraphicAttribute, richtextTheme: Required<IRichTextGraphicAttribute>, aabbBounds: IAABBBounds): import("@visactor/vutils").IBounds;
|
|
72
73
|
protected needUpdateTags(keys: string[]): boolean;
|
package/es/graphic/richtext.js
CHANGED
|
@@ -110,7 +110,13 @@ export class RichText extends Graphic {
|
|
|
110
110
|
}
|
|
111
111
|
return cache.every((item => item.isComposing || !(item.text && isString(item.text) && RichText.splitText(item.text).length > 1)));
|
|
112
112
|
}
|
|
113
|
+
static splitEmoji(text) {
|
|
114
|
+
return [ ...(new Intl.Segmenter).segment(text) ].map((x => x.segment));
|
|
115
|
+
}
|
|
113
116
|
static splitText(text) {
|
|
117
|
+
try {
|
|
118
|
+
return this.splitEmoji(text);
|
|
119
|
+
} catch (e) {}
|
|
114
120
|
return Array.from(text);
|
|
115
121
|
}
|
|
116
122
|
static TransformTextConfig2SingleCharacter(textConfig) {
|