@visactor/vrender-core 0.18.14-alpha.0 → 0.18.15-beta.1
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
package/cjs/graphic/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/config.ts"],"names":[],"mappings":";;;AACA,6CAAuD;AACvD,2DAAuD;AAiC1C,QAAA,aAAa,GAAY;IACpC,SAAS,EAAE,MAAM;CAClB,CAAC;A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AC,EAClB,gBAAgB,EAAE,CAAC,EACnB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,QAAQ,EACtB,SAAS,EAAE,YAAY,EACvB,MAAM,EAAE,CAAC,EACT,EAAE,EAAE,EAAE,EAEN,KAAK,EAAE,EAAE,EACT,MAAM,EAAE,EAAE,EACV,cAAc,EAAE,0BAA0B,EAC1C,qBAAqB,EAAE,CAAC,EACxB,gBAAgB,EAAE,KAAK,EACvB,uBAAuB,EAAE,CAAC,EAC1B,gBAAgB,EAAE,CAAC,EACnB,OAAO,EAAE,CAAC,IACV","file":"config.js","sourcesContent":["// 存放公共属性\nimport { Logger, Matrix, pi2 } from '@visactor/vutils';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport type {\n IArcGraphicAttribute,\n IAreaGraphicAttribute,\n IGraphicAttribute,\n ICircleGraphicAttribute,\n IFillStyle,\n IGlyphGraphicAttribute,\n IGroupGraphicAttribute,\n IImageGraphicAttribute,\n ILineGraphicAttribute,\n IPathGraphicAttribute,\n IPolygonGraphicAttribute,\n IRect3dGraphicAttribute,\n IRectGraphicAttribute,\n IStrokeStyle,\n IGraphicStyle,\n ISymbolGraphicAttribute,\n ITextAttribute,\n ITextGraphicAttribute,\n IRichTextGraphicAttribute,\n ITransform,\n RichTextWordBreak,\n RichTextVerticalDirection,\n RichTextGlobalAlignType,\n RichTextGlobalBaselineType,\n IRichTextIconGraphicAttribute,\n IConnectedStyle,\n ILayout,\n IDebugType,\n IPickStyle\n} from '../interface';\n\nexport const DefaultLayout: ILayout = {\n alignSelf: 'auto'\n};\n\nexport const DefaultTransform: ITransform = {\n x: 0,\n y: 0,\n z: 0,\n dx: 0,\n dy: 0,\n dz: 0,\n scrollX: 0,\n scrollY: 0,\n scaleX: 1,\n scaleY: 1,\n scaleZ: 1,\n angle: 0,\n alpha: 0,\n beta: 0,\n scaleCenter: [0, 0],\n anchor: [0, 0],\n anchor3d: [0, 0],\n postMatrix: new Matrix()\n};\n\nexport const DefaultFillStyle: IFillStyle = {\n fillOpacity: 1,\n fill: false,\n shadowBlur: 0,\n shadowColor: 'black',\n shadowOffsetX: 0,\n shadowOffsetY: 0\n};\n\nconst commonStroke: Omit<IStrokeStyle, 'outerBorder' | 'innerBorder'> = {\n strokeOpacity: 1,\n lineDash: [],\n lineDashOffset: 0,\n lineWidth: 1,\n lineCap: 'butt',\n lineJoin: 'miter',\n miterLimit: 10,\n strokeBoundsBuffer: 2,\n stroke: false\n};\n\nexport const DefaultStrokeStyle: IStrokeStyle = {\n outerBorder: { ...commonStroke, distance: 0 },\n innerBorder: { ...commonStroke, distance: 0 },\n ...commonStroke\n};\n\nexport const DefaultTextStyle: Required<ITextAttribute> = {\n text: '',\n maxLineWidth: Infinity,\n textAlign: 'left',\n textBaseline: 'alphabetic',\n fontSize: 16,\n // @ts-ignore\n fontFamily: `PingFang SC,Microsoft Yahei,system-ui,-apple-system,segoe ui,\n Roboto,Helvetica,Arial,sans-serif, apple color emoji,segoe ui emoji,segoe ui symbol`,\n fontWeight: '',\n ellipsis: '…',\n fontVariant: '',\n fontStyle: '',\n lineHeight: undefined,\n underline: 0,\n lineThrough: 0,\n scaleIn3d: false,\n direction: 'horizontal',\n wordBreak: 'break-all',\n ignoreBuf: false,\n verticalMode: 0,\n wrap: false,\n whiteSpace: 'no-wrap',\n heightLimit: Infinity,\n lineClamp: Infinity,\n suffixPosition: 'end',\n underlineDash: [],\n underlineOffset: 0,\n disableAutoClipedPoptip: undefined\n};\n\nexport const DefaultPickStyle: IPickStyle = {\n pickStrokeBuffer: 0\n};\n\nexport const DefaultStyle: IGraphicStyle = {\n opacity: 1,\n background: null,\n backgroundOpacity: 1,\n backgroundCornerRadius: 0,\n texture: null,\n textureColor: 'black',\n textureSize: 10,\n texturePadding: 2,\n backgroundMode: 'no-repeat',\n backgroundFit: true,\n blur: 0,\n cursor: null,\n html: null,\n react: null,\n ...DefaultFillStyle,\n ...DefaultStrokeStyle,\n ...DefaultLayout,\n ...DefaultPickStyle\n};\n\nexport const DefaultConnectAttribute: Required<IConnectedStyle> = {\n connectedType: 'none',\n // connectedStyle: {\n // stroke: DefaultStrokeStyle.stroke,\n // strokeOpacity: DefaultStrokeStyle.strokeOpacity,\n // lineDash: DefaultStrokeStyle.lineDash,\n // lineDashOffset: DefaultStrokeStyle.lineDashOffset,\n // lineCap: DefaultStrokeStyle.lineCap,\n // lineJoin: DefaultStrokeStyle.lineJoin,\n // lineWidth: DefaultStrokeStyle.lineWidth,\n // fill: DefaultFillStyle.fill,\n // fillOpacity: DefaultFillStyle.fillOpacity\n // },\n connectedStyle: {}, // 默认全都继承父属性\n connectedX: NaN,\n connectedY: NaN\n} as IConnectedStyle;\n\nexport const DefaultDebugAttribute: Required<IDebugType> = {\n _debug_bounds: false\n};\n\nexport const DefaultAttribute: Required<IGraphicAttribute> = {\n strokeSeg: null,\n pickable: true,\n childrenPickable: true,\n fillPickable: true,\n strokePickable: true,\n visible: true,\n zIndex: 0,\n layout: null,\n boundsPadding: 0,\n renderStyle: 'default',\n pickMode: 'accurate',\n customPickShape: null,\n boundsMode: 'accurate',\n keepDirIn3d: true,\n shadowRootIdx: 1,\n globalZIndex: 1,\n globalCompositeOperation: '',\n overflow: 'hidden',\n ...DefaultDebugAttribute,\n ...DefaultStyle,\n ...DefaultTransform\n};\n\nexport function addAttributeToPrototype(obj: Record<string, any>, c: any, keys: string[]) {\n keys.forEach(key => {\n c.prototype[key] = obj[key];\n });\n}\nexport function rewriteProto(obj: Record<string, any>, c: Record<string, any>) {\n Object.setPrototypeOf(obj, c);\n}\n\nexport const DefaultArcAttribute: Required<IArcGraphicAttribute> = {\n ...DefaultAttribute,\n startAngle: 0,\n endAngle: pi2,\n innerRadius: 0,\n outerRadius: 1,\n innerPadding: 0,\n outerPadding: 0,\n cornerRadius: 0,\n padRadius: 0,\n padAngle: 0,\n cap: false,\n forceShowCap: false\n};\n\nexport const DefaultAreaAttribute: Required<IAreaGraphicAttribute> = {\n ...DefaultAttribute,\n ...DefaultConnectAttribute,\n points: [],\n segments: [],\n curveType: 'linear',\n clipRange: 1,\n closePath: false\n};\n\nexport const DefaultCircleAttribute: Required<ICircleGraphicAttribute> = {\n ...DefaultAttribute,\n radius: 1,\n startAngle: 0,\n endAngle: pi2\n};\n\nexport const DefaultGroupAttribute: Required<IGroupGraphicAttribute> = {\n ...DefaultAttribute,\n width: 0,\n height: 0,\n cornerRadius: 0,\n path: [],\n clip: false,\n visibleAll: true,\n display: 'relative',\n flexDirection: 'row',\n flexWrap: 'wrap',\n justifyContent: 'flex-start',\n alignItems: 'flex-start',\n alignContent: 'flex-start'\n};\n\nexport const DefaultGlyphAttribute: Required<IGlyphGraphicAttribute> = {\n ...DefaultAttribute,\n path: '',\n width: 0,\n height: 0,\n cornerRadius: 0,\n clip: false\n};\n\nexport const DefaultLineAttribute: Required<ILineGraphicAttribute> = {\n ...DefaultAttribute,\n ...DefaultConnectAttribute,\n points: [],\n segments: [],\n curveType: 'linear',\n clipRange: 1,\n clipRangeByDimension: 'default',\n closePath: false\n};\n\nexport const DefaultPathAttribute: Required<IPathGraphicAttribute> = {\n ...DefaultAttribute,\n path: new CustomPath2D(),\n customPath: () => {\n Logger.getInstance().warn('空函数');\n }\n};\n\nexport const DefaultPolygonAttribute: Required<IPolygonGraphicAttribute> = {\n ...DefaultAttribute,\n points: [],\n cornerRadius: 0,\n closePath: true\n};\n\nexport const DefaultRectAttribute: Required<IRectGraphicAttribute> = {\n ...DefaultAttribute,\n width: 0,\n height: 0,\n x1: 0,\n y1: 0,\n strokeBoundsBuffer: 0,\n cornerRadius: 0\n};\n\nexport const DefaultRect3dAttribute: Required<IRect3dGraphicAttribute> = {\n ...DefaultAttribute,\n width: 0,\n height: 0,\n x1: 0,\n y1: 0,\n cornerRadius: 0,\n length: 0\n};\n\nexport const DefaultSymbolAttribute: Required<ISymbolGraphicAttribute> = {\n ...DefaultAttribute,\n symbolType: 'circle',\n size: 10, // 外接**正方形**的边长\n keepDirIn3d: true\n};\n\nexport const DefaultTextAttribute: Required<ITextGraphicAttribute> = {\n ...DefaultAttribute,\n ...DefaultTextStyle,\n strokeBoundsBuffer: 0,\n keepDirIn3d: true\n};\n\nexport const DefaultRichTextAttribute: Required<IRichTextGraphicAttribute> = {\n ...DefaultAttribute,\n ...DefaultTextStyle,\n width: 300,\n height: 300,\n ellipsis: true,\n wordBreak: 'break-word' as RichTextWordBreak,\n verticalDirection: 'top' as RichTextVerticalDirection,\n textAlign: 'left' as RichTextGlobalAlignType,\n textBaseline: 'top' as RichTextGlobalBaselineType,\n layoutDirection: 'horizontal',\n textConfig: [],\n maxHeight: undefined,\n maxWidth: undefined,\n singleLine: false\n};\n\nexport const DefaultImageAttribute: Required<IImageGraphicAttribute> = {\n repeatX: 'no-repeat',\n repeatY: 'no-repeat',\n image: '',\n width: 0,\n height: 0,\n ...DefaultAttribute,\n fill: true,\n cornerRadius: 0\n};\n\nexport const DefaultRichTextIconAttribute: Required<IRichTextIconGraphicAttribute> = {\n ...DefaultImageAttribute,\n backgroundShowMode: 'never',\n backgroundWidth: 0,\n backgroundHeight: 0,\n textAlign: 'left',\n textBaseline: 'middle',\n direction: 'horizontal',\n margin: 0,\n id: '',\n\n width: 20,\n height: 20,\n backgroundFill: 'rgba(101, 117, 168, 0.1)',\n backgroundFillOpacity: 1,\n backgroundStroke: false,\n backgroundStrokeOpacity: 1,\n backgroundRadius: 4,\n opacity: 1\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/graphic/config.ts"],"names":[],"mappings":";;;AACA,6CAAuD;AACvD,2DAAuD;AAiC1C,QAAA,aAAa,GAAY;IACpC,SAAS,EAAE,MAAM;CAClB,CAAC;AAEW,QAAA,gBAAgB,GAAe;IAC1C,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;IACV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AE,EACV,cAAc,EAAE,0BAA0B,EAC1C,qBAAqB,EAAE,CAAC,EACxB,gBAAgB,EAAE,KAAK,EACvB,uBAAuB,EAAE,CAAC,EAC1B,gBAAgB,EAAE,CAAC,EACnB,OAAO,EAAE,CAAC,IACV","file":"config.js","sourcesContent":["// 存放公共属性\nimport { Logger, Matrix, pi2 } from '@visactor/vutils';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport type {\n IArcGraphicAttribute,\n IAreaGraphicAttribute,\n IGraphicAttribute,\n ICircleGraphicAttribute,\n IFillStyle,\n IGlyphGraphicAttribute,\n IGroupGraphicAttribute,\n IImageGraphicAttribute,\n ILineGraphicAttribute,\n IPathGraphicAttribute,\n IPolygonGraphicAttribute,\n IRect3dGraphicAttribute,\n IRectGraphicAttribute,\n IStrokeStyle,\n IGraphicStyle,\n ISymbolGraphicAttribute,\n ITextAttribute,\n ITextGraphicAttribute,\n IRichTextGraphicAttribute,\n ITransform,\n RichTextWordBreak,\n RichTextVerticalDirection,\n RichTextGlobalAlignType,\n RichTextGlobalBaselineType,\n IRichTextIconGraphicAttribute,\n IConnectedStyle,\n ILayout,\n IDebugType,\n IPickStyle\n} from '../interface';\n\nexport const DefaultLayout: ILayout = {\n alignSelf: 'auto'\n};\n\nexport const DefaultTransform: ITransform = {\n x: 0,\n y: 0,\n z: 0,\n dx: 0,\n dy: 0,\n dz: 0,\n scrollX: 0,\n scrollY: 0,\n scaleX: 1,\n scaleY: 1,\n scaleZ: 1,\n angle: 0,\n alpha: 0,\n beta: 0,\n scaleCenter: [0, 0],\n anchor: [0, 0],\n anchor3d: [0, 0],\n postMatrix: new Matrix()\n};\n\nexport const DefaultFillStyle: IFillStyle = {\n fillOpacity: 1,\n fill: false,\n shadowBlur: 0,\n shadowColor: 'black',\n shadowOffsetX: 0,\n shadowOffsetY: 0\n};\n\nconst commonStroke: Omit<IStrokeStyle, 'outerBorder' | 'innerBorder'> = {\n strokeOpacity: 1,\n lineDash: [],\n lineDashOffset: 0,\n lineWidth: 1,\n lineCap: 'butt',\n lineJoin: 'miter',\n miterLimit: 10,\n strokeBoundsBuffer: 2,\n stroke: false\n};\n\nexport const DefaultStrokeStyle: IStrokeStyle = {\n outerBorder: { ...commonStroke, distance: 0 },\n innerBorder: { ...commonStroke, distance: 0 },\n ...commonStroke\n};\n\nexport const DefaultTextStyle: Required<ITextAttribute> = {\n text: '',\n maxLineWidth: Infinity,\n textAlign: 'left',\n textBaseline: 'alphabetic',\n fontSize: 16,\n // @ts-ignore\n fontFamily: `PingFang SC,Microsoft Yahei,system-ui,-apple-system,segoe ui,\n Roboto,Helvetica,Arial,sans-serif, apple color emoji,segoe ui emoji,segoe ui symbol`,\n fontWeight: '',\n ellipsis: '…',\n fontVariant: '',\n fontStyle: '',\n lineHeight: undefined,\n underline: 0,\n lineThrough: 0,\n scaleIn3d: false,\n direction: 'horizontal',\n wordBreak: 'break-all',\n ignoreBuf: false,\n verticalMode: 0,\n wrap: false,\n whiteSpace: 'no-wrap',\n heightLimit: Infinity,\n lineClamp: Infinity,\n suffixPosition: 'end',\n underlineDash: [],\n underlineOffset: 0,\n disableAutoClipedPoptip: undefined\n};\n\nexport const DefaultPickStyle: IPickStyle = {\n pickStrokeBuffer: 0\n};\n\nexport const DefaultStyle: IGraphicStyle = {\n opacity: 1,\n background: null,\n backgroundOpacity: 1,\n backgroundCornerRadius: 0,\n texture: null,\n textureColor: 'black',\n textureSize: 10,\n texturePadding: 2,\n backgroundMode: 'no-repeat',\n backgroundFit: true,\n blur: 0,\n cursor: null,\n html: null,\n react: null,\n ...DefaultFillStyle,\n ...DefaultStrokeStyle,\n ...DefaultLayout,\n ...DefaultPickStyle\n};\n\nexport const DefaultConnectAttribute: Required<IConnectedStyle> = {\n connectedType: 'none',\n // connectedStyle: {\n // stroke: DefaultStrokeStyle.stroke,\n // strokeOpacity: DefaultStrokeStyle.strokeOpacity,\n // lineDash: DefaultStrokeStyle.lineDash,\n // lineDashOffset: DefaultStrokeStyle.lineDashOffset,\n // lineCap: DefaultStrokeStyle.lineCap,\n // lineJoin: DefaultStrokeStyle.lineJoin,\n // lineWidth: DefaultStrokeStyle.lineWidth,\n // fill: DefaultFillStyle.fill,\n // fillOpacity: DefaultFillStyle.fillOpacity\n // },\n connectedStyle: {}, // 默认全都继承父属性\n connectedX: NaN,\n connectedY: NaN\n} as IConnectedStyle;\n\nexport const DefaultDebugAttribute: Required<IDebugType> = {\n _debug_bounds: false\n};\n\nexport const DefaultAttribute: Required<IGraphicAttribute> = {\n strokeSeg: null,\n pickable: true,\n childrenPickable: true,\n fillPickable: true,\n strokePickable: true,\n visible: true,\n zIndex: 0,\n layout: null,\n boundsPadding: 0,\n renderStyle: 'default',\n pickMode: 'accurate',\n customPickShape: null,\n boundsMode: 'accurate',\n keepDirIn3d: true,\n shadowRootIdx: 1,\n globalZIndex: 1,\n globalCompositeOperation: '',\n overflow: 'hidden',\n ...DefaultDebugAttribute,\n ...DefaultStyle,\n ...DefaultTransform\n};\n\nexport function addAttributeToPrototype(obj: Record<string, any>, c: any, keys: string[]) {\n keys.forEach(key => {\n c.prototype[key] = obj[key];\n });\n}\nexport function rewriteProto(obj: Record<string, any>, c: Record<string, any>) {\n Object.setPrototypeOf(obj, c);\n}\n\nexport const DefaultArcAttribute: Required<IArcGraphicAttribute> = {\n ...DefaultAttribute,\n startAngle: 0,\n endAngle: pi2,\n innerRadius: 0,\n outerRadius: 1,\n innerPadding: 0,\n outerPadding: 0,\n cornerRadius: 0,\n padRadius: 0,\n padAngle: 0,\n cap: false,\n forceShowCap: false\n};\n\nexport const DefaultAreaAttribute: Required<IAreaGraphicAttribute> = {\n ...DefaultAttribute,\n ...DefaultConnectAttribute,\n points: [],\n segments: [],\n curveType: 'linear',\n clipRange: 1,\n closePath: false\n};\n\nexport const DefaultCircleAttribute: Required<ICircleGraphicAttribute> = {\n ...DefaultAttribute,\n radius: 1,\n startAngle: 0,\n endAngle: pi2\n};\n\nexport const DefaultGroupAttribute: Required<IGroupGraphicAttribute> = {\n ...DefaultAttribute,\n width: 0,\n height: 0,\n cornerRadius: 0,\n path: [],\n clip: false,\n visibleAll: true,\n display: 'relative',\n flexDirection: 'row',\n flexWrap: 'wrap',\n justifyContent: 'flex-start',\n alignItems: 'flex-start',\n alignContent: 'flex-start'\n};\n\nexport const DefaultGlyphAttribute: Required<IGlyphGraphicAttribute> = {\n ...DefaultAttribute,\n path: '',\n width: 0,\n height: 0,\n cornerRadius: 0,\n clip: false\n};\n\nexport const DefaultLineAttribute: Required<ILineGraphicAttribute> = {\n ...DefaultAttribute,\n ...DefaultConnectAttribute,\n points: [],\n segments: [],\n curveType: 'linear',\n clipRange: 1,\n clipRangeByDimension: 'default',\n closePath: false\n};\n\nexport const DefaultPathAttribute: Required<IPathGraphicAttribute> = {\n ...DefaultAttribute,\n path: new CustomPath2D(),\n customPath: () => {\n Logger.getInstance().warn('空函数');\n }\n};\n\nexport const DefaultPolygonAttribute: Required<IPolygonGraphicAttribute> = {\n ...DefaultAttribute,\n points: [],\n cornerRadius: 0,\n closePath: true\n};\n\nexport const DefaultRectAttribute: Required<IRectGraphicAttribute> = {\n ...DefaultAttribute,\n width: 0,\n height: 0,\n x1: 0,\n y1: 0,\n strokeBoundsBuffer: 0,\n cornerRadius: 0\n};\n\nexport const DefaultRect3dAttribute: Required<IRect3dGraphicAttribute> = {\n ...DefaultAttribute,\n width: 0,\n height: 0,\n x1: 0,\n y1: 0,\n cornerRadius: 0,\n length: 0\n};\n\nexport const DefaultSymbolAttribute: Required<ISymbolGraphicAttribute> = {\n ...DefaultAttribute,\n symbolType: 'circle',\n size: 10, // 外接**正方形**的边长\n keepDirIn3d: true\n};\n\nexport const DefaultTextAttribute: Required<ITextGraphicAttribute> = {\n ...DefaultAttribute,\n ...DefaultTextStyle,\n strokeBoundsBuffer: 0,\n keepDirIn3d: true\n};\n\nexport const DefaultRichTextAttribute: Required<IRichTextGraphicAttribute> = {\n ...DefaultAttribute,\n ...DefaultTextStyle,\n width: 300,\n height: 300,\n ellipsis: true,\n wordBreak: 'break-word' as RichTextWordBreak,\n verticalDirection: 'top' as RichTextVerticalDirection,\n textAlign: 'left' as RichTextGlobalAlignType,\n textBaseline: 'top' as RichTextGlobalBaselineType,\n layoutDirection: 'horizontal',\n textConfig: [],\n forceBreakLine: false,\n maxHeight: undefined,\n maxWidth: undefined,\n singleLine: false\n};\n\nexport const DefaultImageAttribute: Required<IImageGraphicAttribute> = {\n repeatX: 'no-repeat',\n repeatY: 'no-repeat',\n image: '',\n width: 0,\n height: 0,\n ...DefaultAttribute,\n fill: true,\n cornerRadius: 0\n};\n\nexport const DefaultRichTextIconAttribute: Required<IRichTextIconGraphicAttribute> = {\n ...DefaultImageAttribute,\n backgroundShowMode: 'never',\n backgroundWidth: 0,\n backgroundHeight: 0,\n textAlign: 'left',\n textBaseline: 'middle',\n direction: 'horizontal',\n margin: 0,\n id: '',\n\n width: 20,\n height: 20,\n backgroundFill: 'rgba(101, 117, 168, 0.1)',\n backgroundFillOpacity: 1,\n backgroundStroke: false,\n backgroundStrokeOpacity: 1,\n backgroundRadius: 4,\n opacity: 1\n};\n"]}
|
|
@@ -43,19 +43,19 @@ class Frame {
|
|
|
43
43
|
if (top + height < this[this.directionKey.top] || top + height > this[this.directionKey.top] + frameHeight) return lastLineTag;
|
|
44
44
|
let lastLine = !1;
|
|
45
45
|
this.ellipsis && this.lines[i + 1] && this.lines[i + 1].top + this.lines[i + 1].height > this[this.directionKey.top] + frameHeight && (lastLine = !0,
|
|
46
|
-
lastLineTag = !0), this.lines[i].draw(ctx, lastLine, this.lines[i][this.directionKey.left] + deltaX, this.lines[i][this.directionKey.top] + deltaY, drawIcon);
|
|
46
|
+
lastLineTag = !0), this.lines[i].draw(ctx, lastLine, this.lines[i][this.directionKey.left] + deltaX, this.lines[i][this.directionKey.top] + deltaY, this.ellipsis, drawIcon);
|
|
47
47
|
} else {
|
|
48
48
|
const detalHeight = Math.floor((frameHeight - this.actualHeight) / 2);
|
|
49
49
|
"vertical" === this.layoutDirection ? deltaX += detalHeight : deltaY += detalHeight;
|
|
50
|
-
for (let i = 0; i < this.lines.length; i++) this.lines[i].draw(ctx, !1, this.lines[i][this.directionKey.left] + deltaX, this.lines[i][this.directionKey.top] + deltaY, drawIcon);
|
|
50
|
+
for (let i = 0; i < this.lines.length; i++) this.lines[i].draw(ctx, !1, this.lines[i][this.directionKey.left] + deltaX, this.lines[i][this.directionKey.top] + deltaY, this.ellipsis, drawIcon);
|
|
51
51
|
} else if ("bottom" === this.verticalDirection && "vertical" !== this.layoutDirection) for (let i = 0; i < this.lines.length; i++) {
|
|
52
52
|
const {top: top, height: height} = this.lines[i], y = frameHeight - this.lines[i].top - this.lines[i].height;
|
|
53
|
-
if (0 === frameHeight) this.lines[i].draw(ctx, !1, deltaX, y + deltaY, drawIcon); else {
|
|
53
|
+
if (0 === frameHeight) this.lines[i].draw(ctx, !1, deltaX, y + deltaY, this.ellipsis, drawIcon); else {
|
|
54
54
|
if (y + height > this[this.directionKey.top] + frameHeight || y < this[this.directionKey.top]) return lastLineTag;
|
|
55
55
|
{
|
|
56
56
|
let lastLine = !1;
|
|
57
57
|
this.ellipsis && this.lines[i + 1] && y - this.lines[i + 1].height < this[this.directionKey.top] && (lastLine = !0,
|
|
58
|
-
lastLineTag = !0), this.lines[i].draw(ctx, lastLine, deltaX, y + deltaY, drawIcon);
|
|
58
|
+
lastLineTag = !0), this.lines[i].draw(ctx, lastLine, deltaX, y + deltaY, this.ellipsis, drawIcon);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
} else {
|
|
@@ -63,12 +63,12 @@ class Frame {
|
|
|
63
63
|
for (let i = 0; i < this.lines.length; i++) {
|
|
64
64
|
"bottom" === this.verticalDirection && "vertical" === this.layoutDirection && (deltaX -= this.lines[i].height + this.lines[i].top);
|
|
65
65
|
const {top: top, height: height} = this.lines[i];
|
|
66
|
-
if (0 === frameHeight) this.lines[i].draw(ctx, !1, this.lines[i][this.directionKey.left] + deltaX, this.lines[i][this.directionKey.top] + deltaY, drawIcon); else {
|
|
66
|
+
if (0 === frameHeight) this.lines[i].draw(ctx, !1, this.lines[i][this.directionKey.left] + deltaX, this.lines[i][this.directionKey.top] + deltaY, this.ellipsis, drawIcon); else {
|
|
67
67
|
if (top + height < this[this.directionKey.top] || top + height > this[this.directionKey.top] + frameHeight) return lastLineTag;
|
|
68
68
|
{
|
|
69
69
|
let lastLine = !1;
|
|
70
70
|
this.ellipsis && this.lines[i + 1] && this.lines[i + 1].top + this.lines[i + 1].height > this[this.directionKey.top] + frameHeight && (lastLine = !0,
|
|
71
|
-
lastLineTag = !0), this.lines[i].draw(ctx, lastLine, this.lines[i][this.directionKey.left] + deltaX, this.lines[i][this.directionKey.top] + deltaY, drawIcon);
|
|
71
|
+
lastLineTag = !0), this.lines[i].draw(ctx, lastLine, this.lines[i][this.directionKey.left] + deltaX, this.lines[i][this.directionKey.top] + deltaY, this.ellipsis, drawIcon);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/richtext/frame.ts"],"names":[],"mappings":";;AAGA,mCAAwC;AA8BxC,MAAqB,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,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,IAAI,GAA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,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;AA9XD,wBA8XC","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,mCAAwC;AA8BxC,MAAqB,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,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAEhB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;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AK,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;AAlYD,wBAkYC","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
|
}
|
|
@@ -40,11 +40,12 @@ class Line {
|
|
|
40
40
|
x += paragraph[directionKey.width] + spacing);
|
|
41
41
|
}));
|
|
42
42
|
}
|
|
43
|
-
draw(ctx, lastLine, x, y, drawIcon) {
|
|
44
|
-
if (lastLine) {
|
|
43
|
+
draw(ctx, lastLine, x, y, drawEllipsis, drawIcon) {
|
|
44
|
+
if (drawEllipsis && (lastLine || this.paragraphs.some((p => p.overflow)))) {
|
|
45
45
|
let otherParagraphWidth = 0;
|
|
46
46
|
for (let i = this.paragraphs.length - 1; i >= 0; i--) {
|
|
47
47
|
const paragraph = this.paragraphs[i];
|
|
48
|
+
if (paragraph.overflow) continue;
|
|
48
49
|
if (paragraph instanceof icon_1.RichTextIcon) break;
|
|
49
50
|
if ("vertical" === this.direction && "vertical" !== paragraph.direction) {
|
|
50
51
|
paragraph.verticalEllipsis = !0;
|
|
@@ -1 +1 @@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SAAS,CAAC,KAAK,EAAE;gBAEnF,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC;gBAC/B,SAAS,CAAC,aAAa,GAAG,aAAa,CAAC;gBACxC,SAAS,CAAC,2BAA2B,GAAG,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC;gBAE9E,MAAM;aACP;iBAAM;gBAEL,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;gBAC5B,mBAAmB,IAAI,SAAS,CAAC,KAAK,CAAC;aACxC;SACF;QAED,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YACvC,IAAI,SAAS,YAAY,mBAAY,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;AA1MD,uBA0MC","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,iCAAsC;AACtC,4DAAoC;AACpC,mCAA0E;AA8B1E,MAAqB,IAAI;IAevB,YACE,IAAY,EACZ,KAAa,EACb,QAAgB,EAChB,MAAc,EACd,OAAe,EACf,UAAwC,EACxC,SAAoC,EACpC,UAAmB;QAEnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,GAAG,GAAG,QAAQ,GAAG,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,CAAC,SAAS;YACZ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,mBAAY;gBACzC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS;gBACxC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC;QACxD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,qBAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAElD,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,U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iB,EAAC,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;YAChE,MAAM,aAAa,GAAG,KAAK,IAAI,CAAC,CAAC;YACjC,IAAI,aAAa,IAAI,IAAI,CAAC,UAAU,GAAG,mBAAmB,EAAE;gBAE1D,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;gBAC3B,SAAS,CAAC,aAAa,GAAG,aAAa,CAAC;gBACxC,MAAM;aACP;iBAAM,IAAI,aAAa,IAAI,IAAI,CAAC,UAAU,GAAG,mBAAmB,GAAG,SAAS,CAAC,KAAK,EAAE;gBAEnF,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC;gBAC/B,SAAS,CAAC,aAAa,GAAG,aAAa,CAAC;gBACxC,SAAS,CAAC,2BAA2B,GAAG,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC;gBAE9E,MAAM;aACP;iBAAM;gBAEL,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;gBAC5B,mBAAmB,IAAI,SAAS,CAAC,KAAK,CAAC;aACxC;SACF;QAED,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YACvC,IAAI,SAAS,YAAY,mBAAY,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;AA9MD,uBA8MC","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,8CAAyD;AAEzD,mCAAkG;AA8BlG,MAAqB,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,IAA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AC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC;AAPD,8CAOC","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,8CAAyD;AAEzD,mCAAkG;AA8BlG,MAAqB,SAAS;IA0B5B,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,IAAA,2BAAmB,EAAC,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,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAA,yBAAiB,EAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAE9E,IAAI,cA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AY,EAAE,GAAG,IAAA,yBAAiB,EAAC,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;AAhQD,4BAgQC;AAED,SAAgB,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;AAPD,8CAOC","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/cjs/graphic/richtext.js
CHANGED
|
@@ -125,7 +125,7 @@ class RichText extends graphic_1.Graphic {
|
|
|
125
125
|
}
|
|
126
126
|
doUpdateFrameCache() {
|
|
127
127
|
var _a;
|
|
128
|
-
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 = [];
|
|
128
|
+
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 = [];
|
|
129
129
|
for (let i = 0; i < textConfig.length; i++) if ("image" in textConfig[i]) {
|
|
130
130
|
const config = this.combinedStyleToCharacter(textConfig[i]), iconCache = config.id && this._frameCache && this._frameCache.icons && this._frameCache.icons.get(config.id);
|
|
131
131
|
if (iconCache) paragraphs.push(iconCache); else {
|
|
@@ -144,7 +144,16 @@ class RichText extends graphic_1.Graphic {
|
|
|
144
144
|
} else richTextConfig.text && paragraphs.push(new paragraph_1.default(richTextConfig.text, !1, richTextConfig));
|
|
145
145
|
}
|
|
146
146
|
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), frameWidth = richTextWidthEnable ? width : maxWidthFinite ? maxWidth : 0, frameHeight = richTextHeightEnable ? height : maxHeightFinite ? maxHeight : 0, frame = new frame_1.default(0, 0, frameWidth || 0, frameHeight || 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_1.default(frame);
|
|
147
|
-
|
|
147
|
+
if (forceBreakLine) {
|
|
148
|
+
let lineCount = 0, skip = !1;
|
|
149
|
+
for (let i = 0; i < paragraphs.length; i++) {
|
|
150
|
+
const p = paragraphs[i];
|
|
151
|
+
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),
|
|
152
|
+
frame.lines.length !== lineCount && (lineCount = frame.lines.length, wrapper.lineBuffer.length = 0,
|
|
153
|
+
p.overflow = !0, p.left = 1e3, p.top = 1e3, frame.lines[frame.lines.length - 1].paragraphs.push(p),
|
|
154
|
+
skip = !0), p.newLine && (skip = !1);
|
|
155
|
+
}
|
|
156
|
+
} else for (let i = 0; i < paragraphs.length; i++) wrapper.deal(paragraphs[i]);
|
|
148
157
|
wrapper.send();
|
|
149
158
|
if (!("horizontal" === frame.layoutDirection ? richTextWidthEnable : richTextHeightEnable)) {
|
|
150
159
|
const frameSize = frame.getActualSizeWidthEllipsis();
|