@visactor/vrender-core 0.16.14-alpha.3 → 0.16.14-alpha.5
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/core/graphic-utils.d.ts +1 -3
- package/cjs/core/graphic-utils.js +2 -4
- package/cjs/core/graphic-utils.js.map +1 -1
- package/cjs/graphic/richtext/paragraph.js +12 -11
- package/cjs/graphic/richtext/paragraph.js.map +1 -1
- package/cjs/interface/core.d.ts +1 -3
- package/cjs/interface/core.js.map +1 -1
- package/cjs/interface/graphic/richText.d.ts +1 -1
- package/cjs/interface/graphic/richText.js.map +1 -1
- package/dist/index.js +245 -244
- package/dist/index.min.js +1 -1
- package/es/core/graphic-utils.d.ts +1 -3
- package/es/core/graphic-utils.js +1 -5
- package/es/core/graphic-utils.js.map +1 -1
- package/es/graphic/richtext/paragraph.js +5 -2
- package/es/graphic/richtext/paragraph.js.map +1 -1
- package/es/interface/core.d.ts +1 -3
- package/es/interface/core.js.map +1 -1
- package/es/interface/graphic/richText.d.ts +1 -1
- package/es/interface/graphic/richText.js.map +1 -1
- package/package.json +2 -2
|
@@ -18,9 +18,7 @@ export declare class DefaultGraphicUtil implements IGraphicUtil {
|
|
|
18
18
|
width: number;
|
|
19
19
|
height: number;
|
|
20
20
|
};
|
|
21
|
-
createTextMeasureInstance(textSpec?: Partial<ITextAttribute>, option?: Partial<ITextMeasureOption>, getCanvasForMeasure?: () => any): TextMeasure<
|
|
22
|
-
lineHeight?: number;
|
|
23
|
-
}>;
|
|
21
|
+
createTextMeasureInstance(textSpec?: Partial<ITextAttribute>, option?: Partial<ITextMeasureOption>, getCanvasForMeasure?: () => any): TextMeasure<ITextAttribute>;
|
|
24
22
|
}
|
|
25
23
|
export declare class DefaultTransformUtil implements ITransformUtil {
|
|
26
24
|
private matrix;
|
package/es/core/graphic-utils.js
CHANGED
|
@@ -24,8 +24,6 @@ import { Matrix, TextMeasure } from "@visactor/vutils";
|
|
|
24
24
|
|
|
25
25
|
import { VGlobal } from "../constants";
|
|
26
26
|
|
|
27
|
-
import { calculateLineHeight } from "../common/utils";
|
|
28
|
-
|
|
29
27
|
let DefaultGraphicUtil = class {
|
|
30
28
|
constructor(contributions, global) {
|
|
31
29
|
this.contributions = contributions, this.global = global, this.configured = !1,
|
|
@@ -71,9 +69,7 @@ let DefaultGraphicUtil = class {
|
|
|
71
69
|
getCanvasForMeasure: getCanvasForMeasure || (() => this.canvas),
|
|
72
70
|
getTextBounds: void 0,
|
|
73
71
|
specialCharSet: "-/: .,@%'\"~" + TextMeasure.ALPHABET_CHAR_SET + TextMeasure.ALPHABET_CHAR_SET.toUpperCase()
|
|
74
|
-
}, null != option ? option : {}),
|
|
75
|
-
lineHeight: calculateLineHeight(null == textSpec ? void 0 : textSpec.lineHeight, null == textSpec ? void 0 : textSpec.fontSize)
|
|
76
|
-
}));
|
|
72
|
+
}, null != option ? option : {}), textSpec);
|
|
77
73
|
}
|
|
78
74
|
};
|
|
79
75
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/graphic-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sDAAsD,CAAC;AAE/F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG/C,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAM7B,YAGqB,aAAkD,EACpC,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,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAChG,OAAO,IAAI,CAAC;IACd,CAAC;IACD,SAAS,CAAC,EAAU,EAAE,EAAU;QAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,MAAM,EAAE;YACtC,OAAO,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IASD,QAAQ,CAAC,MAAqB;QAC5B,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,MAAM,EAAE;YACtC,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACO,cAAc,CAAC,MAAqB;QAkB1C,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA3IY,oBAAoB;IADhC,UAAU,EAAE;;GACA,oBAAoB,CA2IhC;SA3IY,oBAAoB","file":"graphic-utils.js","sourcesContent":["import { injectable, inject, named } from '../common/inversify-lite';\nimport type { ICanvas, IContext2d, EnvType, IGlobal, ITextAttribute, IContributionProvider } from '../interface';\nimport type { ITextMeasure, TextOptionsType } from '../interface/text';\nimport { TextMeasureContribution } from './contributions/textMeasure/textMeasure-contribution';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../common/contribution-provider';\nimport { wrapCanvas } from '../canvas/util';\nimport { DefaultTextStyle } from '../graphic/config';\nimport type { IMatrix, IPointLike, ITextMeasureOption } from '@visactor/vutils';\nimport { Matrix, TextMeasure } from '@visactor/vutils';\nimport type { IGraphicUtil, ITransformUtil, TransformType } from '../interface/core';\nimport { VGlobal } from '../constants';\nimport { calculateLineHeight } from '../common/utils';\n\n@injectable()\nexport class DefaultGraphicUtil implements IGraphicUtil {\n canvas?: ICanvas;\n context?: IContext2d | null;\n _textMeasure: ITextMeasure;\n configured: boolean;\n\n constructor(\n @inject(ContributionProvider)\n @named(TextMeasureContribution)\n protected readonly contributions: IContributionProvider<ITextMeasure>,\n @inject(VGlobal) public readonly global: IGlobal\n ) {\n this.configured = false;\n this.global.hooks.onSetEnv.tap('graphic-util', (lastEnv, env, global) => {\n this.configured = false;\n this.configure(global, env);\n });\n }\n\n get textMeasure(): ITextMeasure {\n if (!this._textMeasure) {\n this.configure(this.global, this.global.env);\n }\n return this._textMeasure;\n }\n\n configure(global: IGlobal, env: EnvType) {\n if (this.configured) {\n return;\n }\n const canvas = wrapCanvas({\n nativeCanvas: global.createCanvas({ width: 100, height: 100 })\n });\n this.canvas = canvas;\n this.context = canvas.getContext('2d');\n this.contributions.getContributions().forEach(contribution => {\n contribution.configure(this, env);\n });\n this.configured = true;\n }\n\n bindTextMeasure(tm: ITextMeasure) {\n this._textMeasure = tm;\n }\n\n measureText(\n text: string,\n tc: TextOptionsType,\n method: 'native' | 'simple' | 'quick' = 'native'\n ): { width: number; height: number } {\n this.configure(this.global, this.global.env);\n const m = this.global.measureTextMethod;\n this.global.measureTextMethod = method;\n const data = {\n width: this._textMeasure.measureTextWidth(text, tc),\n height: tc.fontSize ?? DefaultTextStyle.fontSize\n };\n this.global.measureTextMethod = m;\n return data;\n }\n\n createTextMeasureInstance(\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) {\n this.configure(this.global, this.global.env);\n return new TextMeasure<Omit<ITextAttribute, 'lineHeight'> & { lineHeight?: number }>(\n {\n defaultFontParams: {\n fontFamily: DefaultTextStyle.fontFamily,\n fontSize: DefaultTextStyle.fontSize\n },\n getCanvasForMeasure: getCanvasForMeasure || (() => this.canvas),\n getTextBounds: undefined,\n specialCharSet: '-/: .,@%\\'\"~' + TextMeasure.ALPHABET_CHAR_SET + TextMeasure.ALPHABET_CHAR_SET.toUpperCase(),\n ...(option ?? {})\n },\n {\n ...textSpec,\n lineHeight: calculateLineHeight(textSpec?.lineHeight, textSpec?.fontSize)\n }\n );\n }\n}\n\nenum TransformMode {\n transform = 0,\n matrix = 1\n}\n\nconst _matrix = new Matrix();\n\n@injectable()\nexport class DefaultTransformUtil implements ITransformUtil {\n private matrix: IMatrix;\n private originTransform: TransformType;\n\n private outSourceMatrix: IMatrix;\n private outTargetMatrix: IMatrix;\n\n private mode: TransformMode;\n constructor() {\n this.matrix = new Matrix();\n }\n init(origin: TransformType): this {\n this.mode = TransformMode.transform;\n this.originTransform = origin;\n this.matrix.reset();\n return this;\n }\n fromMatrix(source: IMatrix, target: IMatrix): this {\n this.mode = TransformMode.matrix;\n this.outSourceMatrix = source;\n this.outTargetMatrix = target;\n return this;\n }\n\n // translate: (x: number, y: number) => Transform;\n // translateTo: (x: number, y: number) => Transform;\n private scaleMatrix(sx: number, sy: number, center?: IPointLike): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.scale(sx, sy);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.scale(sx, sy);\n }\n\n // _matrix.reset();\n // if (center) {\n // const { x, y } = center;\n // _matrix.translate(x, y);\n // _matrix.scale(sx, sy);\n // _matrix.translate(-x, -y);\n // } else {\n // _matrix.scale(sx, sy);\n // }\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n\n private rotateMatrix(angle: number, center?: IPointLike): this {\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.rotate(angle);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.rotate(angle);\n }\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n scale(sx: number, sy: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.scaleMatrix(sx, sy, center);\n }\n return this;\n }\n rotate(angle: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.rotateMatrix(angle, center);\n }\n return this;\n }\n private translateMatrix(dx: number, dy: number): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n this.outTargetMatrix.translate(dx, dy);\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n translate(dx: number, dy: number): this {\n if (this.mode === TransformMode.matrix) {\n return this.translateMatrix(dx, dy);\n }\n return this;\n }\n // scaleTo: (sx: number, sy: number, center: IPointLike) => Transform;\n // rotate: (rx: number, ry: number, center: IPointLike) => Transform;\n // rotateTo: (rx: number, ry: number, center: IPointLike) => Transform;\n // 语法糖\n // interactive: (dx: number, dy: number, dsx: number, dsy: number, drx: number, dry: number) => Transform;\n // // 扩展padding像素,用于外描边,内描边\n // extend: (origin: TransformType, padding: number) => Transform;\n // 将所有的transform生成为一次的transform\n simplify(target: TransformType): this {\n if (this.mode === TransformMode.matrix) {\n return this.simplifyMatrix(target);\n }\n return this;\n }\n private simplifyMatrix(target: TransformType): this {\n // let { a, b, c, d, e, f } = this.outTargetMatrix;\n // if (a === 0 || d === 0) return this;\n // const { dx=0, dy=0 } = target;\n // // 不处理dx和dy\n // e -= dx;\n // f -= dy;\n // const tanTheta = b / a;\n // const angle = Math.atan(tanTheta);\n // const cosTheta = cos(angle);\n // const sinTheta = sin(angle);\n // const sx = cosTheta !== 0 ? (a / cosTheta) : (b / sinTheta);\n // const sy = sinTheta !== 0 ? (-c / sinTheta) : (d / cosTheta);\n // const x = e;\n // const y = f;\n // target.x = x;\n // target.y = y;\n // target.dx = dx;\n return this;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/graphic-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAGrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sDAAsD,CAAC;AAE/F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGhC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAM7B,YAGqB,aAAkD,EACpC,MAAe;QAD7B,kBAAa,GAAb,aAAa,CAAqC;QACpC,WAAM,GAAN,MAAM,CAAS;QAEhD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;YACtE,IAAI,CAAC,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IACd,CAAC;IASD,QAAQ,CAAC,MAAqB;QAC5B,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,MAAM,EAAE;YACtC,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACO,cAAc,CAAC,MAAqB;QAkB1C,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA3IY,oBAAoB;IADhC,UAAU,EAAE;;GACA,oBAAoB,CA2IhC;SA3IY,oBAAoB","file":"graphic-utils.js","sourcesContent":["import { injectable, inject, named } from '../common/inversify-lite';\nimport type { ICanvas, IContext2d, EnvType, IGlobal, ITextAttribute, IContributionProvider } from '../interface';\nimport type { ITextMeasure, TextOptionsType } from '../interface/text';\nimport { TextMeasureContribution } from './contributions/textMeasure/textMeasure-contribution';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../common/contribution-provider';\nimport { wrapCanvas } from '../canvas/util';\nimport { DefaultTextStyle } from '../graphic/config';\nimport type { IMatrix, IPointLike, ITextMeasureOption } from '@visactor/vutils';\nimport { Matrix, TextMeasure } from '@visactor/vutils';\nimport type { IGraphicUtil, ITransformUtil, TransformType } from '../interface/core';\nimport { VGlobal } from '../constants';\n\n@injectable()\nexport class DefaultGraphicUtil implements IGraphicUtil {\n canvas?: ICanvas;\n context?: IContext2d | null;\n _textMeasure: ITextMeasure;\n configured: boolean;\n\n constructor(\n @inject(ContributionProvider)\n @named(TextMeasureContribution)\n protected readonly contributions: IContributionProvider<ITextMeasure>,\n @inject(VGlobal) public readonly global: IGlobal\n ) {\n this.configured = false;\n this.global.hooks.onSetEnv.tap('graphic-util', (lastEnv, env, global) => {\n this.configured = false;\n this.configure(global, env);\n });\n }\n\n get textMeasure(): ITextMeasure {\n if (!this._textMeasure) {\n this.configure(this.global, this.global.env);\n }\n return this._textMeasure;\n }\n\n configure(global: IGlobal, env: EnvType) {\n if (this.configured) {\n return;\n }\n const canvas = wrapCanvas({\n nativeCanvas: global.createCanvas({ width: 100, height: 100 })\n });\n this.canvas = canvas;\n this.context = canvas.getContext('2d');\n this.contributions.getContributions().forEach(contribution => {\n contribution.configure(this, env);\n });\n this.configured = true;\n }\n\n bindTextMeasure(tm: ITextMeasure) {\n this._textMeasure = tm;\n }\n\n measureText(\n text: string,\n tc: TextOptionsType,\n method: 'native' | 'simple' | 'quick' = 'native'\n ): { width: number; height: number } {\n this.configure(this.global, this.global.env);\n const m = this.global.measureTextMethod;\n this.global.measureTextMethod = method;\n const data = {\n width: this._textMeasure.measureTextWidth(text, tc),\n height: tc.fontSize ?? DefaultTextStyle.fontSize\n };\n this.global.measureTextMethod = m;\n return data;\n }\n\n createTextMeasureInstance(\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) {\n this.configure(this.global, this.global.env);\n return new TextMeasure<ITextAttribute>(\n {\n defaultFontParams: {\n fontFamily: DefaultTextStyle.fontFamily,\n fontSize: DefaultTextStyle.fontSize\n },\n getCanvasForMeasure: getCanvasForMeasure || (() => this.canvas),\n getTextBounds: undefined,\n specialCharSet: '-/: .,@%\\'\"~' + TextMeasure.ALPHABET_CHAR_SET + TextMeasure.ALPHABET_CHAR_SET.toUpperCase(),\n ...(option ?? {})\n },\n textSpec\n );\n }\n}\n\nenum TransformMode {\n transform = 0,\n matrix = 1\n}\n\nconst _matrix = new Matrix();\n\n@injectable()\nexport class DefaultTransformUtil implements ITransformUtil {\n private matrix: IMatrix;\n private originTransform: TransformType;\n\n private outSourceMatrix: IMatrix;\n private outTargetMatrix: IMatrix;\n\n private mode: TransformMode;\n constructor() {\n this.matrix = new Matrix();\n }\n init(origin: TransformType): this {\n this.mode = TransformMode.transform;\n this.originTransform = origin;\n this.matrix.reset();\n return this;\n }\n fromMatrix(source: IMatrix, target: IMatrix): this {\n this.mode = TransformMode.matrix;\n this.outSourceMatrix = source;\n this.outTargetMatrix = target;\n return this;\n }\n\n // translate: (x: number, y: number) => Transform;\n // translateTo: (x: number, y: number) => Transform;\n private scaleMatrix(sx: number, sy: number, center?: IPointLike): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.scale(sx, sy);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.scale(sx, sy);\n }\n\n // _matrix.reset();\n // if (center) {\n // const { x, y } = center;\n // _matrix.translate(x, y);\n // _matrix.scale(sx, sy);\n // _matrix.translate(-x, -y);\n // } else {\n // _matrix.scale(sx, sy);\n // }\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n\n private rotateMatrix(angle: number, center?: IPointLike): this {\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n if (center) {\n const { x, y } = center;\n this.outTargetMatrix.translate(x, y);\n this.outTargetMatrix.rotate(angle);\n this.outTargetMatrix.translate(-x, -y);\n } else {\n this.outTargetMatrix.rotate(angle);\n }\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n scale(sx: number, sy: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.scaleMatrix(sx, sy, center);\n }\n return this;\n }\n rotate(angle: number, center?: IPointLike): this {\n if (this.mode === TransformMode.matrix) {\n return this.rotateMatrix(angle, center);\n }\n return this;\n }\n private translateMatrix(dx: number, dy: number): this {\n // if (this.outSourceMatrix !== this.outTargetMatrix) {\n // // copy\n // const m = this.outSourceMatrix;\n // this.outTargetMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n // }\n const sMatrix = this.outSourceMatrix;\n _matrix.setValue(sMatrix.a, sMatrix.b, sMatrix.c, sMatrix.d, sMatrix.e, sMatrix.f);\n this.outTargetMatrix.reset();\n this.outTargetMatrix.translate(dx, dy);\n\n this.outTargetMatrix.multiply(_matrix.a, _matrix.b, _matrix.c, _matrix.d, _matrix.e, _matrix.f);\n return this;\n }\n translate(dx: number, dy: number): this {\n if (this.mode === TransformMode.matrix) {\n return this.translateMatrix(dx, dy);\n }\n return this;\n }\n // scaleTo: (sx: number, sy: number, center: IPointLike) => Transform;\n // rotate: (rx: number, ry: number, center: IPointLike) => Transform;\n // rotateTo: (rx: number, ry: number, center: IPointLike) => Transform;\n // 语法糖\n // interactive: (dx: number, dy: number, dsx: number, dsy: number, drx: number, dry: number) => Transform;\n // // 扩展padding像素,用于外描边,内描边\n // extend: (origin: TransformType, padding: number) => Transform;\n // 将所有的transform生成为一次的transform\n simplify(target: TransformType): this {\n if (this.mode === TransformMode.matrix) {\n return this.simplifyMatrix(target);\n }\n return this;\n }\n private simplifyMatrix(target: TransformType): this {\n // let { a, b, c, d, e, f } = this.outTargetMatrix;\n // if (a === 0 || d === 0) return this;\n // const { dx=0, dy=0 } = target;\n // // 不处理dx和dy\n // e -= dx;\n // f -= dy;\n // const tanTheta = b / a;\n // const angle = Math.atan(tanTheta);\n // const cosTheta = cos(angle);\n // const sinTheta = sin(angle);\n // const sx = cosTheta !== 0 ? (a / cosTheta) : (b / sinTheta);\n // const sy = sinTheta !== 0 ? (-c / sinTheta) : (d / cosTheta);\n // const x = e;\n // const y = f;\n // target.x = x;\n // target.y = y;\n // target.dx = dx;\n return this;\n }\n}\n"]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { calculateLineHeight } from "../../common/utils";
|
|
2
|
+
|
|
1
3
|
import { measureTextCanvas, applyFillStyle, applyStrokeStyle, getStrByWithCanvas } from "./utils";
|
|
2
4
|
|
|
3
5
|
export default class Paragraph {
|
|
4
6
|
constructor(text, newLine, character) {
|
|
5
|
-
this.fontSize = character.fontSize || 16, this.textBaseline = character.textBaseline || "alphabetic"
|
|
6
|
-
|
|
7
|
+
this.fontSize = character.fontSize || 16, this.textBaseline = character.textBaseline || "alphabetic";
|
|
8
|
+
const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);
|
|
9
|
+
this.lineHeight = "number" == typeof lineHeight ? lineHeight > this.fontSize ? lineHeight : this.fontSize : Math.floor(1.2 * this.fontSize),
|
|
7
10
|
this.height = this.lineHeight;
|
|
8
11
|
const {ascent: ascent, height: height, descent: descent, width: width} = measureTextCanvas(text, character);
|
|
9
12
|
let halfDetaHeight = 0, deltaAscent = 0, deltaDescent = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AA8BlG,MAAM,CAAC,OAAO,OAAO,SAAS;IAyB5B,YAAY,IAAY,EAAE,OAAgB,EAAE,SAAsC;QAEhF,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC,YAAY,IAAI,YAAY,CAAC;QAK3D,IAAI,OAAO,SAAS,CAAC,UAAU,KAAK,QAAQ,EAAE;YAC5C,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;SAC/F;aAAM;YACL,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,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AC;YACF,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAC5B,IAAI,IAAI,KAAK,CAAC;YAEd,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YAC1F,OAAO,KAAK,GAAG,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;SAClD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAAC,SAAoB,EAAE,KAAa;IACnE,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACxE,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAE3D,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC","file":"paragraph.js","sourcesContent":["import 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 if (typeof character.lineHeight === 'number') {\n this.lineHeight = character.lineHeight > this.fontSize ? character.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') {\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') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // if (isLineFirst) {\n // const result = regFirstSpace.exec(text);\n // if (result?.index !== 0) {\n // text = text.slice(result?.index);\n // }\n // }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n if (this.character.stroke) {\n applyStrokeStyle(ctx, this.character);\n ctx.strokeText(text, left, baseline);\n }\n\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, this.character);\n\n if (this.character.fill) {\n ctx.fillText(text, left, baseline);\n }\n\n if (this.character.fill) {\n if (typeof this.character.lineThrough === 'boolean' || typeof this.character.underline === 'boolean') {\n if (this.character.underline) {\n ctx.fillRect(\n left,\n 1 + baseline,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n if (this.character.lineThrough) {\n ctx.fillRect(\n left,\n 1 + baseline - this.ascent / 2,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n } else if (this.character.textDecoration === 'underline') {\n ctx.fillRect(\n left,\n 1 + baseline,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n } else if (this.character.textDecoration === 'line-through') {\n ctx.fillRect(\n left,\n 1 + baseline - this.ascent / 2,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n }\n\n if (direction === 'vertical') {\n ctx.restore();\n }\n }\n\n getWidthWithEllips(direction: string): number {\n let text = this.text;\n // const direction = this.direction;\n const width = direction === 'vertical' ? this.height : this.width;\n // const height = direction === 'vertical' ? this.width: this.height;\n\n if (this.ellipsis === 'hide') {\n return width;\n } else if (this.ellipsis === 'add') {\n return width + this.ellipsisWidth;\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += '...';\n\n const { width: measureWidth } = measureTextCanvas(this.text.slice(index), this.character);\n return width + this.ellipsisWidth - measureWidth;\n }\n return width;\n }\n}\n\nexport function seperateParagraph(paragraph: Paragraph, index: number) {\n const text1 = paragraph.text.slice(0, index);\n const text2 = paragraph.text.slice(index);\n const p1 = new Paragraph(text1, paragraph.newLine, paragraph.character);\n const p2 = new Paragraph(text2, true, paragraph.character);\n\n return [p1, p2];\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/graphic/richtext/paragraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBA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AAS,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACxE,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAE3D,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClB,CAAC","file":"paragraph.js","sourcesContent":["import { calculateLineHeight } from '../../common/utils';\nimport type { IContext2d, IRichTextParagraphCharacter } from '../../interface';\nimport { measureTextCanvas, applyFillStyle, applyStrokeStyle, getStrByWithCanvas } from './utils';\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 文字段\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/text.js\nexport default class Paragraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n // rotate?: number;\n direction?: 'horizontal' | 'vertical';\n // bounds?: Bounds;\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n\n constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter) {\n // 测量文字\n this.fontSize = character.fontSize || 16;\n this.textBaseline = character.textBaseline || 'alphabetic';\n\n // 处理行高:\n // lineHeight为数字时,大于fontSize取lineHeight,小于fontSize时取fontSize\n // lineHeight不为数字时,统一认为lineHeight为'normal',值取1.2 * fontSize\n const lineHeight = calculateLineHeight(character.lineHeight, this.fontSize);\n if (typeof lineHeight === 'number') {\n this.lineHeight = lineHeight > this.fontSize ? lineHeight : this.fontSize;\n } else {\n this.lineHeight = Math.floor(1.2 * this.fontSize);\n }\n\n this.height = this.lineHeight;\n\n const { ascent, height, descent, width } = measureTextCanvas(text, character);\n\n let halfDetaHeight = 0;\n let deltaAscent = 0;\n let deltaDescent = 0;\n if (this.height > height) {\n // measureTextCanvas测量出的是纯文字高度,this.height是考虑行高后的高度\n // 如果this.height > height,将超过的高度平均分配到ascent和descent上\n halfDetaHeight = (this.height - height) / 2;\n deltaAscent = Math.ceil(halfDetaHeight);\n deltaDescent = Math.floor(halfDetaHeight);\n }\n\n if (this.textBaseline === 'top') {\n this.ascent = halfDetaHeight;\n this.descent = height - halfDetaHeight;\n } else if (this.textBaseline === 'bottom') {\n this.ascent = height - halfDetaHeight;\n this.descent = halfDetaHeight;\n } else if (this.textBaseline === 'middle') {\n this.ascent = this.height / 2;\n this.descent = this.height / 2;\n } else {\n this.ascent = ascent + deltaAscent;\n this.descent = descent + deltaDescent;\n }\n\n this.length = text.length;\n this.width = width || 0;\n this.text = text || '';\n this.newLine = newLine || false;\n this.character = character;\n\n this.left = 0;\n this.top = 0;\n\n this.ellipsis = 'normal';\n this.ellipsisWidth = 0;\n this.ellipsisOtherParagraphWidth = 0;\n\n // 处理旋转\n if (character.direction === 'vertical') {\n this.direction = character.direction;\n this.widthOrigin = this.width;\n this.heightOrigin = this.height;\n // const bounds = new Bounds();\n // bounds.set(0, 0, this.width, this.height);\n // bounds.rotate(Math.PI / 2, this.width / 2, this.height / 2);\n // this.bounds = bounds;\n // this.width = bounds.width();\n // this.height = bounds.height();\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n this.lineHeight = this.height;\n }\n }\n\n updateWidth() {\n const { width } = measureTextCanvas(this.text, this.character);\n this.width = width;\n if (this.direction === 'vertical') {\n this.widthOrigin = this.width;\n this.width = this.heightOrigin;\n this.height = this.widthOrigin;\n }\n }\n\n draw(ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) {\n let text = this.text;\n let left = this.left + deltaLeft;\n baseline += this.top;\n let direction = this.direction;\n\n if (this.verticalEllipsis) {\n text = '...';\n direction = 'vertical';\n baseline -= this.ellipsisWidth / 2;\n } else if (this.ellipsis === 'hide') {\n return;\n } else if (this.ellipsis === 'add') {\n text += '...';\n\n if (textAlign === 'right') {\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') {\n const { width } = measureTextCanvas(this.text.slice(index), this.character);\n if (direction === 'vertical') {\n // baseline -= this.ellipsisWidth - width;\n } else {\n left -= this.ellipsisWidth - width;\n }\n }\n }\n\n // prepareContext(ctx);\n switch (this.character.script) {\n case 'super':\n baseline -= this.ascent * (1 / 3);\n break;\n case 'sub':\n baseline += this.descent / 2;\n break;\n }\n\n // if (isLineFirst) {\n // const result = regFirstSpace.exec(text);\n // if (result?.index !== 0) {\n // text = text.slice(result?.index);\n // }\n // }\n\n // 处理旋转\n if (direction === 'vertical') {\n ctx.save();\n ctx.rotateAbout(Math.PI / 2, left, baseline);\n ctx.translate(-(this.heightOrigin as number) || -this.lineHeight / 2, -this.descent / 2);\n ctx.translate(left, baseline);\n left = 0;\n baseline = 0;\n }\n\n if (this.character.stroke) {\n applyStrokeStyle(ctx, this.character);\n ctx.strokeText(text, left, baseline);\n }\n\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, this.character);\n\n if (this.character.fill) {\n ctx.fillText(text, left, baseline);\n }\n\n if (this.character.fill) {\n if (typeof this.character.lineThrough === 'boolean' || typeof this.character.underline === 'boolean') {\n if (this.character.underline) {\n ctx.fillRect(\n left,\n 1 + baseline,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n if (this.character.lineThrough) {\n ctx.fillRect(\n left,\n 1 + baseline - this.ascent / 2,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n } else if (this.character.textDecoration === 'underline') {\n ctx.fillRect(\n left,\n 1 + baseline,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n } else if (this.character.textDecoration === 'line-through') {\n ctx.fillRect(\n left,\n 1 + baseline - this.ascent / 2,\n this.widthOrigin || this.width,\n this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1\n );\n }\n }\n\n if (direction === 'vertical') {\n ctx.restore();\n }\n }\n\n getWidthWithEllips(direction: string): number {\n let text = this.text;\n // const direction = this.direction;\n const width = direction === 'vertical' ? this.height : this.width;\n // const height = direction === 'vertical' ? this.width: this.height;\n\n if (this.ellipsis === 'hide') {\n return width;\n } else if (this.ellipsis === 'add') {\n return width + this.ellipsisWidth;\n } else if (this.ellipsis === 'replace') {\n // 找到需要截断的字符长度\n // const index = getStrByWith(text, width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth, this.style, text.length - 1);\n const index = getStrByWithCanvas(\n text,\n width - this.ellipsisWidth + this.ellipsisOtherParagraphWidth,\n this.character,\n text.length - 1\n );\n text = text.slice(0, index);\n text += '...';\n\n const { width: measureWidth } = measureTextCanvas(this.text.slice(index), this.character);\n return width + this.ellipsisWidth - measureWidth;\n }\n return width;\n }\n}\n\nexport function seperateParagraph(paragraph: Paragraph, index: number) {\n const text1 = paragraph.text.slice(0, index);\n const text2 = paragraph.text.slice(index);\n const p1 = new Paragraph(text1, paragraph.newLine, paragraph.character);\n const p2 = new Paragraph(text2, true, paragraph.character);\n\n return [p1, p2];\n}\n"]}
|
package/es/interface/core.d.ts
CHANGED
|
@@ -15,9 +15,7 @@ export interface IGraphicUtil {
|
|
|
15
15
|
height: number;
|
|
16
16
|
};
|
|
17
17
|
bindTextMeasure: (tm: ITextMeasure) => void;
|
|
18
|
-
createTextMeasureInstance: (textSpec?: Partial<ITextAttribute>, option?: Partial<ITextMeasureOption>, getCanvasForMeasure?: () => any) => TextMeasure<
|
|
19
|
-
lineHeight?: number;
|
|
20
|
-
}>;
|
|
18
|
+
createTextMeasureInstance: (textSpec?: Partial<ITextAttribute>, option?: Partial<ITextMeasureOption>, getCanvasForMeasure?: () => any) => TextMeasure<ITextAttribute>;
|
|
21
19
|
}
|
|
22
20
|
export type TransformType = Pick<IGraphicAttribute, 'x' | 'y' | 'scaleX' | 'scaleY' | 'angle' | 'dx' | 'dy'> & {
|
|
23
21
|
anchor?: IGraphicAttribute['anchor'];
|
package/es/interface/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/core.ts"],"names":[],"mappings":"","file":"core.js","sourcesContent":["import type { ICanvas } from './canvas';\nimport type { IContext2d } from './context';\nimport type { IGraphicAttribute } from './graphic';\nimport type { ITextAttribute } from './graphic/text';\nimport type { ILayer, ILayerParams } from './layer';\nimport type { IStage } from './stage';\nimport type { ITextMeasure, TextOptionsType } from './text';\nimport type { IMatrix, IPointLike, ITextMeasureOption, TextMeasure } from '@visactor/vutils';\n\nexport interface IGraphicUtil {\n canvas?: ICanvas;\n context?: IContext2d | null;\n textMeasure: ITextMeasure;\n measureText: (text: string, tc: TextOptionsType) => { width: number; height: number };\n bindTextMeasure: (tm: ITextMeasure) => void;\n createTextMeasureInstance: (\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) => TextMeasure<
|
|
1
|
+
{"version":3,"sources":["../src/interface/core.ts"],"names":[],"mappings":"","file":"core.js","sourcesContent":["import type { ICanvas } from './canvas';\nimport type { IContext2d } from './context';\nimport type { IGraphicAttribute } from './graphic';\nimport type { ITextAttribute } from './graphic/text';\nimport type { ILayer, ILayerParams } from './layer';\nimport type { IStage } from './stage';\nimport type { ITextMeasure, TextOptionsType } from './text';\nimport type { IMatrix, IPointLike, ITextMeasureOption, TextMeasure } from '@visactor/vutils';\n\nexport interface IGraphicUtil {\n canvas?: ICanvas;\n context?: IContext2d | null;\n textMeasure: ITextMeasure;\n measureText: (text: string, tc: TextOptionsType) => { width: number; height: number };\n bindTextMeasure: (tm: ITextMeasure) => void;\n createTextMeasureInstance: (\n textSpec?: Partial<ITextAttribute>,\n option?: Partial<ITextMeasureOption>,\n getCanvasForMeasure?: () => any\n ) => TextMeasure<ITextAttribute>;\n}\n\nexport type TransformType = Pick<IGraphicAttribute, 'x' | 'y' | 'scaleX' | 'scaleY' | 'angle' | 'dx' | 'dy'> & {\n anchor?: IGraphicAttribute['anchor'];\n};\nexport interface ITransformUtil {\n init: (origin: TransformType) => ITransformUtil;\n fromMatrix: (source: IMatrix, target: IMatrix) => ITransformUtil;\n scale: (sx: number, sy: number, center?: IPointLike) => ITransformUtil;\n rotate: (angle: number, center?: IPointLike) => ITransformUtil;\n translate: (dx: number, dy: number) => ITransformUtil;\n}\n\nexport interface ILayerService {\n createLayer: (stage: IStage, options?: Partial<ILayerParams>) => ILayer;\n // stage绘制前调用\n prepareStageLayer: (stage: IStage) => void;\n releaseLayer: (stage: IStage, layer: ILayer) => void;\n restLayerCount: (stage: IStage) => number;\n getStageLayer: (stage: IStage) => ILayer[];\n layerCount: (stage: IStage) => number;\n}\n"]}
|
|
@@ -26,7 +26,7 @@ export type RichTextFontStyle = 'normal' | 'italic' | 'oblique';
|
|
|
26
26
|
export type RichTextTextDecoration = 'none' | 'underline' | 'line-through';
|
|
27
27
|
export type RichTextScript = 'normal' | 'sub' | 'super';
|
|
28
28
|
export type IRichTextBasicCharacter = {
|
|
29
|
-
lineHeight?: number;
|
|
29
|
+
lineHeight?: number | string;
|
|
30
30
|
textAlign?: CanvasTextAlign;
|
|
31
31
|
textBaseline?: CanvasTextBaseline;
|
|
32
32
|
direction?: RichTextLayoutDirectionType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/richText.ts"],"names":[],"mappings":"","file":"richText.js","sourcesContent":["import type { IColor } from '../color';\nimport type { IContext2d } from '../context';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { IImage, IImageGraphicAttribute } from './image';\n\nexport type IRichTextAttribute = {\n width: number;\n height: number;\n ellipsis: boolean | string;\n wordBreak: RichTextWordBreak;\n verticalDirection: RichTextVerticalDirection;\n maxHeight: number;\n maxWidth: number;\n textAlign: RichTextGlobalAlignType;\n textBaseline: RichTextGlobalBaselineType;\n layoutDirection: RichTextLayoutDirectionType;\n textConfig: IRichTextCharacter[];\n singleLine: boolean;\n};\n\nexport type IRichTextGraphicAttribute = Partial<IGraphicAttribute> & Partial<IRichTextAttribute>;\n\nexport type RichTextWordBreak = 'break-word' | 'break-all';\nexport type RichTextVerticalDirection = 'top' | 'middle' | 'bottom';\nexport type RichTextGlobalAlignType = 'left' | 'right' | 'center';\nexport type RichTextGlobalBaselineType = 'top' | 'middle' | 'bottom';\nexport type RichTextLayoutDirectionType = 'horizontal' | 'vertical';\nexport type RichTextFontStyle = 'normal' | 'italic' | 'oblique';\nexport type RichTextTextDecoration = 'none' | 'underline' | 'line-through';\n// export type RichTextTextAlign = 'left' | 'right' | 'center';\nexport type RichTextScript = 'normal' | 'sub' | 'super';\n\nexport type IRichTextBasicCharacter = {\n lineHeight?: number;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextParagraphCharacter = IRichTextBasicCharacter & {\n text: string;\n fontSize?: number;\n fontFamily?: string;\n fill?: IColor | boolean;\n stroke?: IColor | boolean;\n fontWeight?: string;\n // lineHeight?: number;\n fontStyle?: RichTextFontStyle; // normal, italic, oblique\n textDecoration?: RichTextTextDecoration; // none, underline, line-through\n // textAlign?: RichTextTextAlign; // left, right, center\n script?: RichTextScript; // normal, sub, super\n underline?: boolean;\n lineThrough?: boolean;\n // direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextImageCharacter = IRichTextBasicCharacter & {\n // 图片基础属性\n image: string | HTMLImageElement | HTMLCanvasElement;\n width: number;\n height: number;\n\n // hover相关属性\n // backgroundShow?: boolean; // 是否显示background\n backgroundShowMode?: 'always' | 'hover';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n // background size 同时控制了该icon的响应范围\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // 唯一标识符\n id?: string;\n\n // lineHeight?: number;\n // textAlign?: RichTextTextAlign; // left, right, center\n // direction?: RichTextLayoutDirectionType;\n margin?: number | number[];\n\n funcType?: string;\n hoverImage?: string | HTMLImageElement | HTMLCanvasElement;\n};\n\nexport type IRichTextCharacter = IRichTextParagraphCharacter | IRichTextImageCharacter;\n\nexport type IRichTextIconGraphicAttribute = IImageGraphicAttribute & {\n id?: string;\n backgroundShowMode?: 'always' | 'hover' | 'never';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // lineHeight?: number;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n\n margin?: number | number[];\n\n // backgroundShow?: boolean;\n};\n\nexport interface IRichTextParagraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n direction?: 'horizontal' | 'vertical';\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n updateWidth: () => void;\n draw: (ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) => void;\n getWidthWithEllips: (direction: string) => number;\n}\n\nexport interface IRichTextLine {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (IRichTextParagraph | IRichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n x: string;\n y: string;\n };\n draw: (\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => void;\n getWidthWithEllips: () => number;\n}\n\nexport interface IRichTextFrame {\n left: number;\n top: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n actualHeight: number;\n ellipsis: boolean | string;\n wordBreak: 'break-word' | 'break-all';\n verticalDirection: 'top' | 'middle' | 'bottom';\n lines: IRichTextLine[];\n globalAlign: 'left' | 'center' | 'right';\n globalBaseline: 'top' | 'middle' | 'bottom';\n layoutDirection: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n top: string;\n bottom: string;\n };\n isWidthMax: boolean;\n isHeightMax: boolean;\n singleLine: boolean;\n icons: Map<string, IRichTextIcon>;\n draw: (\n ctx: IContext2d,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => boolean;\n getActualSize: () => {\n width: number;\n height: number;\n };\n getRawActualSize: () => {\n width: number;\n height: number;\n };\n getActualSizeWidthEllipsis: () => {\n width: number;\n height: number;\n };\n}\n\nexport interface IRichText extends IGraphic<IRichTextGraphicAttribute> {\n getFrameCache: () => IRichTextFrame;\n}\n\nexport interface IRichTextIcon extends IImage {\n attribute: IRichTextIconGraphicAttribute;\n richtextId?: string;\n globalX?: number;\n globalY?: number;\n\n _x: number;\n _y: number;\n _hovered: boolean;\n _marginArray: [number, number, number, number];\n\n setHoverState: (hovered: boolean) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/richText.ts"],"names":[],"mappings":"","file":"richText.js","sourcesContent":["import type { IColor } from '../color';\nimport type { IContext2d } from '../context';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { IImage, IImageGraphicAttribute } from './image';\n\nexport type IRichTextAttribute = {\n width: number;\n height: number;\n ellipsis: boolean | string;\n wordBreak: RichTextWordBreak;\n verticalDirection: RichTextVerticalDirection;\n maxHeight: number;\n maxWidth: number;\n textAlign: RichTextGlobalAlignType;\n textBaseline: RichTextGlobalBaselineType;\n layoutDirection: RichTextLayoutDirectionType;\n textConfig: IRichTextCharacter[];\n singleLine: boolean;\n};\n\nexport type IRichTextGraphicAttribute = Partial<IGraphicAttribute> & Partial<IRichTextAttribute>;\n\nexport type RichTextWordBreak = 'break-word' | 'break-all';\nexport type RichTextVerticalDirection = 'top' | 'middle' | 'bottom';\nexport type RichTextGlobalAlignType = 'left' | 'right' | 'center';\nexport type RichTextGlobalBaselineType = 'top' | 'middle' | 'bottom';\nexport type RichTextLayoutDirectionType = 'horizontal' | 'vertical';\nexport type RichTextFontStyle = 'normal' | 'italic' | 'oblique';\nexport type RichTextTextDecoration = 'none' | 'underline' | 'line-through';\n// export type RichTextTextAlign = 'left' | 'right' | 'center';\nexport type RichTextScript = 'normal' | 'sub' | 'super';\n\nexport type IRichTextBasicCharacter = {\n lineHeight?: number | string;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextParagraphCharacter = IRichTextBasicCharacter & {\n text: string;\n fontSize?: number;\n fontFamily?: string;\n fill?: IColor | boolean;\n stroke?: IColor | boolean;\n fontWeight?: string;\n // lineHeight?: number;\n fontStyle?: RichTextFontStyle; // normal, italic, oblique\n textDecoration?: RichTextTextDecoration; // none, underline, line-through\n // textAlign?: RichTextTextAlign; // left, right, center\n script?: RichTextScript; // normal, sub, super\n underline?: boolean;\n lineThrough?: boolean;\n // direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextImageCharacter = IRichTextBasicCharacter & {\n // 图片基础属性\n image: string | HTMLImageElement | HTMLCanvasElement;\n width: number;\n height: number;\n\n // hover相关属性\n // backgroundShow?: boolean; // 是否显示background\n backgroundShowMode?: 'always' | 'hover';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n // background size 同时控制了该icon的响应范围\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // 唯一标识符\n id?: string;\n\n // lineHeight?: number;\n // textAlign?: RichTextTextAlign; // left, right, center\n // direction?: RichTextLayoutDirectionType;\n margin?: number | number[];\n\n funcType?: string;\n hoverImage?: string | HTMLImageElement | HTMLCanvasElement;\n};\n\nexport type IRichTextCharacter = IRichTextParagraphCharacter | IRichTextImageCharacter;\n\nexport type IRichTextIconGraphicAttribute = IImageGraphicAttribute & {\n id?: string;\n backgroundShowMode?: 'always' | 'hover' | 'never';\n backgroundFill?: boolean | IColor; // 背景矩形填充颜色\n backgroundFillOpacity?: number; // 背景矩形填充透明度\n backgroundStroke?: boolean | IColor; // 背景矩形边框颜色\n backgroundStrokeOpacity?: number; // 背景矩形边框透明度\n backgroundRadius?: number; // 背景矩形圆角\n backgroundWidth?: number;\n backgroundHeight?: number;\n\n // lineHeight?: number;\n textAlign?: CanvasTextAlign; // left, right, center\n textBaseline?: CanvasTextBaseline;\n direction?: RichTextLayoutDirectionType;\n\n margin?: number | number[];\n\n // backgroundShow?: boolean;\n};\n\nexport interface IRichTextParagraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n direction?: 'horizontal' | 'vertical';\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n updateWidth: () => void;\n draw: (ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) => void;\n getWidthWithEllips: (direction: string) => number;\n}\n\nexport interface IRichTextLine {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (IRichTextParagraph | IRichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n x: string;\n y: string;\n };\n draw: (\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => void;\n getWidthWithEllips: () => number;\n}\n\nexport interface IRichTextFrame {\n left: number;\n top: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n actualHeight: number;\n ellipsis: boolean | string;\n wordBreak: 'break-word' | 'break-all';\n verticalDirection: 'top' | 'middle' | 'bottom';\n lines: IRichTextLine[];\n globalAlign: 'left' | 'center' | 'right';\n globalBaseline: 'top' | 'middle' | 'bottom';\n layoutDirection: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n top: string;\n bottom: string;\n };\n isWidthMax: boolean;\n isHeightMax: boolean;\n singleLine: boolean;\n icons: Map<string, IRichTextIcon>;\n draw: (\n ctx: IContext2d,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => boolean;\n getActualSize: () => {\n width: number;\n height: number;\n };\n getRawActualSize: () => {\n width: number;\n height: number;\n };\n getActualSizeWidthEllipsis: () => {\n width: number;\n height: number;\n };\n}\n\nexport interface IRichText extends IGraphic<IRichTextGraphicAttribute> {\n getFrameCache: () => IRichTextFrame;\n}\n\nexport interface IRichTextIcon extends IImage {\n attribute: IRichTextIconGraphicAttribute;\n richtextId?: string;\n globalX?: number;\n globalY?: number;\n\n _x: number;\n _y: number;\n _hovered: boolean;\n _marginArray: [number, number, number, number];\n\n setHoverState: (hovered: boolean) => void;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/vrender-core",
|
|
3
|
-
"version": "0.16.14-alpha.
|
|
3
|
+
"version": "0.16.14-alpha.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"sideEffects": true,
|
|
6
6
|
"main": "cjs/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"color-convert": "2.0.1",
|
|
16
|
-
"@visactor/vutils": "
|
|
16
|
+
"@visactor/vutils": "0.16.8-alpha.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@rushstack/eslint-patch": "~1.1.4",
|