@visactor/vrender-core 0.22.0 → 0.22.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/allocator/bounds-allocate.js +1 -1
- package/cjs/allocator/canvas-allocate.js +1 -1
- package/cjs/allocator/constants.js +1 -1
- package/cjs/allocator/graphic-allocate.js +1 -1
- package/cjs/allocator/matrix-allocate.js +1 -1
- package/cjs/animate/custom-animate.js +2 -1
- package/cjs/animate/index.js +1 -2
- package/cjs/color-string/store.js +2 -1
- package/cjs/common/custom-path2d.js +8 -6
- package/cjs/common/custom-path2d.js.map +1 -1
- package/cjs/common/enums.js +1 -2
- package/cjs/common/render-area.js +1 -0
- package/cjs/common/store.js +1 -1
- package/cjs/common/text.js +1 -2
- package/cjs/common/utils.js +1 -1
- package/cjs/core/application.js +1 -1
- package/cjs/core/camera.js +1 -1
- package/cjs/graphic/config.js +2 -1
- package/cjs/graphic/config.js.map +1 -1
- package/cjs/graphic/graphic.d.ts +1 -1
- package/cjs/graphic/graphic.js +7 -7
- package/cjs/graphic/graphic.js.map +1 -1
- package/cjs/graphic/group.d.ts +1 -0
- package/cjs/graphic/group.js +5 -0
- package/cjs/graphic/group.js.map +1 -1
- package/cjs/graphic/richtext/line.js +11 -1
- package/cjs/graphic/richtext/line.js.map +1 -1
- package/cjs/graphic/richtext/paragraph.d.ts +8 -1
- package/cjs/graphic/richtext/paragraph.js +5 -16
- package/cjs/graphic/richtext/paragraph.js.map +1 -1
- package/cjs/graphic/richtext.js +11 -7
- package/cjs/graphic/richtext.js.map +1 -1
- package/cjs/graphic/symbol.d.ts +1 -0
- package/cjs/graphic/symbol.js +11 -0
- package/cjs/graphic/symbol.js.map +1 -1
- package/cjs/interface/graphic/arc.js.map +1 -1
- package/cjs/interface/graphic/area.js.map +1 -1
- package/cjs/interface/graphic/circle.js.map +1 -1
- package/cjs/interface/graphic/group.js.map +1 -1
- package/cjs/interface/graphic/image.js.map +1 -1
- package/cjs/interface/graphic/line.js.map +1 -1
- package/cjs/interface/graphic/polygon.js.map +1 -1
- package/cjs/interface/graphic/rect.js.map +1 -1
- package/cjs/interface/graphic/richText.d.ts +4 -0
- package/cjs/interface/graphic/richText.js.map +1 -1
- package/cjs/interface/graphic/symbol.d.ts +1 -0
- package/cjs/interface/graphic/symbol.js.map +1 -1
- package/cjs/interface/graphic/text.js.map +1 -1
- package/cjs/plugins/builtin-plugin/edit-module.js +3 -2
- package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +6 -3
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +49 -31
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/cjs/render/contributions/render/contributions/base-texture-contribution-render.d.ts +2 -1
- package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js +20 -3
- package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
- package/dist/index.es.js +208 -85
- package/es/allocator/bounds-allocate.js +1 -1
- package/es/allocator/canvas-allocate.js +1 -1
- package/es/allocator/constants.js +1 -1
- package/es/allocator/graphic-allocate.js +1 -1
- package/es/allocator/matrix-allocate.js +1 -1
- package/es/animate/custom-animate.js +2 -1
- package/es/animate/index.js +1 -2
- package/es/color-string/store.js +2 -1
- package/es/common/custom-path2d.js +8 -6
- package/es/common/custom-path2d.js.map +1 -1
- package/es/common/enums.js +1 -2
- package/es/common/render-area.js +2 -1
- package/es/common/store.js +1 -1
- package/es/common/text.js +1 -2
- package/es/common/utils.js +1 -1
- package/es/core/application.js +1 -1
- package/es/core/camera.js +1 -1
- package/es/graphic/config.js +2 -1
- package/es/graphic/config.js.map +1 -1
- package/es/graphic/graphic.d.ts +1 -1
- package/es/graphic/graphic.js +9 -9
- package/es/graphic/graphic.js.map +1 -1
- package/es/graphic/group.d.ts +1 -0
- package/es/graphic/group.js +5 -0
- package/es/graphic/group.js.map +1 -1
- package/es/graphic/richtext/line.js +11 -1
- package/es/graphic/richtext/line.js.map +1 -1
- package/es/graphic/richtext/paragraph.d.ts +8 -1
- package/es/graphic/richtext/paragraph.js +5 -16
- package/es/graphic/richtext/paragraph.js.map +1 -1
- package/es/graphic/richtext.js +11 -7
- package/es/graphic/richtext.js.map +1 -1
- package/es/graphic/symbol.d.ts +1 -0
- package/es/graphic/symbol.js +11 -0
- package/es/graphic/symbol.js.map +1 -1
- package/es/interface/graphic/arc.js.map +1 -1
- package/es/interface/graphic/area.js.map +1 -1
- package/es/interface/graphic/circle.js.map +1 -1
- package/es/interface/graphic/group.js.map +1 -1
- package/es/interface/graphic/image.js.map +1 -1
- package/es/interface/graphic/line.js.map +1 -1
- package/es/interface/graphic/polygon.js.map +1 -1
- package/es/interface/graphic/rect.js.map +1 -1
- package/es/interface/graphic/richText.d.ts +4 -0
- package/es/interface/graphic/richText.js.map +1 -1
- package/es/interface/graphic/symbol.d.ts +1 -0
- package/es/interface/graphic/symbol.js.map +1 -1
- package/es/interface/graphic/text.js.map +1 -1
- package/es/plugins/builtin-plugin/edit-module.js +3 -2
- package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +6 -3
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js +49 -31
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/es/render/contributions/render/contributions/base-texture-contribution-render.d.ts +2 -1
- package/es/render/contributions/render/contributions/base-texture-contribution-render.js +22 -2
- package/es/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
- package/package.json +1 -1
package/es/graphic/symbol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/graphic/symbol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,iBAA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@visactor/vutils';\nimport { AABBBounds } from '@visactor/vutils';\nimport { isArray, max } from '@visactor/vutils';\nimport type { ISymbol, ISymbolClass, ISymbolGraphicAttribute } from '../interface';\nimport { builtinSymbolsMap, builtInSymbolStrMap, CustomSymbolClass } from './builtin-symbol';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { SVG_PARSE_ATTRIBUTE_MAP, SVG_PARSE_ATTRIBUTE_MAP_KEYS, SYMBOL_NUMBER_TYPE } from './constants';\nimport { XMLParser } from '../common/xml';\nimport { isSvg } from '../common/xml/parser';\nimport { updateBoundsOfSymbolOuterBorder } from './graphic-service/symbol-outer-border-bounds';\n\nconst _tempBounds = new AABBBounds();\n\nconst SYMBOL_UPDATE_TAG_KEY = ['symbolType', 'size', ...GRAPHIC_UPDATE_TAG_KEY];\n\n/**\n * symbol\n */\nexport class Symbol extends Graphic<ISymbolGraphicAttribute> implements ISymbol {\n type: 'symbol' = 'symbol';\n\n static userSymbolMap: Record<string, ISymbolClass> = {};\n\n static NOWORK_ANIMATE_ATTR = {\n symbolType: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n constructor(params: ISymbolGraphicAttribute = { symbolType: 'circle' }) {\n super(params);\n this.numberType = SYMBOL_NUMBER_TYPE;\n }\n\n protected _parsedPath?: ISymbolClass;\n\n getParsedPath(): ISymbolClass {\n if (this.shouldUpdateShape()) {\n this.doUpdateParsedPath();\n this.clearUpdateShapeTag();\n }\n return this._parsedPath as ISymbolClass;\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n const { size } = this.attribute;\n return isArray(size) ? size.length === 2 && size.every(this._validNumber) : this._validNumber(size);\n }\n\n protected doUpdateParsedPath(): ISymbolClass {\n const symbolTheme = this.getGraphicTheme();\n // 查找内置symbol\n let { symbolType = symbolTheme.symbolType } = this.attribute;\n let path = builtinSymbolsMap[symbolType];\n if (path) {\n this._parsedPath = path;\n return path;\n }\n path = Symbol.userSymbolMap[symbolType];\n if (path) {\n this._parsedPath = path;\n return path;\n }\n\n const _symbolType = builtInSymbolStrMap[symbolType];\n symbolType = _symbolType || symbolType;\n // 判断是否是svg\n const valid = isSvg(symbolType);\n if (valid === true) {\n const parser = new XMLParser();\n const { svg } = parser.parse(symbolType);\n if (!svg) {\n return null;\n }\n const path = isArray(svg.path) ? svg.path : [svg.path];\n _tempBounds.clear();\n const cacheList: { path: CustomPath2D; attribute: Record<string, any> }[] = [];\n path.forEach((item: any) => {\n const cache = new CustomPath2D().fromString(item.d);\n const attribute: any = {};\n SVG_PARSE_ATTRIBUTE_MAP_KEYS.forEach(k => {\n if (item[k]) {\n (attribute as any)[(SVG_PARSE_ATTRIBUTE_MAP as any)[k]] = item[k];\n }\n });\n // 查找\n cacheList.push({\n path: cache,\n attribute\n });\n _tempBounds.union(cache.bounds);\n });\n const width = _tempBounds.width();\n const height = _tempBounds.height();\n // 规范化到1\n const maxWH = max(width, height);\n const scale = 1 / maxWH;\n cacheList.forEach(cache => cache.path.transform(0, 0, scale, scale));\n\n this._parsedPath = new CustomSymbolClass(symbolType, cacheList, true);\n Symbol.userSymbolMap[symbolType] = this._parsedPath;\n return this._parsedPath;\n }\n\n const cache = new CustomPath2D().fromString(symbolType);\n const width = cache.bounds.width();\n const height = cache.bounds.height();\n // 规范化到1\n const maxWH = max(width, height);\n const scale = 1 / maxWH;\n cache.transform(0, 0, scale, scale);\n this._parsedPath = new CustomSymbolClass(symbolType, cache);\n Symbol.userSymbolMap[symbolType] = this._parsedPath;\n return this._parsedPath;\n }\n\n getGraphicTheme(): Required<ISymbolGraphicAttribute> {\n return getTheme(this).symbol;\n }\n\n protected updateAABBBounds(\n attribute: ISymbolGraphicAttribute,\n symbolTheme: Required<ISymbolGraphicAttribute>,\n aabbBounds: IAABBBounds,\n full?: boolean\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n full\n ? this.updateSymbolAABBBoundsImprecise(attribute, symbolTheme, aabbBounds)\n : this.updateSymbolAABBBoundsAccurate(attribute, symbolTheme, aabbBounds);\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfSymbolOuterBorder(attribute, symbolTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n\n const { lineJoin = symbolTheme.lineJoin } = attribute;\n application.graphicService.transformAABBBounds(attribute, aabbBounds, symbolTheme, lineJoin === 'miter', this);\n return aabbBounds;\n }\n\n protected updateSymbolAABBBoundsImprecise(\n attribute: ISymbolGraphicAttribute,\n symbolTheme: Required<ISymbolGraphicAttribute>,\n aabbBounds: IAABBBounds\n ): IAABBBounds {\n // 当做正方形计算\n const { size = symbolTheme.size } = attribute;\n\n if (isArray(size)) {\n aabbBounds.set(-size[0] / 2, -size[1] / 2, size[0] / 2, size[1] / 2);\n } else {\n const halfWH = size / 2;\n\n aabbBounds.set(-halfWH, -halfWH, halfWH, halfWH);\n }\n\n return aabbBounds;\n }\n\n protected updateSymbolAABBBoundsAccurate(\n attribute: ISymbolGraphicAttribute,\n symbolTheme: Required<ISymbolGraphicAttribute>,\n aabbBounds: IAABBBounds\n ): IAABBBounds {\n const { size = symbolTheme.size } = attribute;\n\n const symbolClass = this.getParsedPath();\n symbolClass.bounds(size, aabbBounds);\n\n return aabbBounds;\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, SYMBOL_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, SYMBOL_UPDATE_TAG_KEY);\n }\n\n toCustomPath() {\n const symbolInstance = this.getParsedPath();\n const size = this.attribute.size;\n const x = 0;\n const y = 0;\n const formattedSize = isArray(size) ? size : [size, size];\n\n return symbolInstance.path\n ? new CustomPath2D().fromCustomPath2D(symbolInstance.path, x, y, formattedSize[0], formattedSize[1])\n : new CustomPath2D().fromString(symbolInstance.pathStr, x, y, formattedSize[0], formattedSize[1]);\n }\n\n clone() {\n return new Symbol({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Symbol.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createSymbol(attributes: ISymbolGraphicAttribute): ISymbol {\n return new Symbol(attributes);\n}\n\n// addAttributeToPrototype(DefaultSymbolStyle, Symbol, PURE_STYLE_KEY);\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/graphic/symbol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,8CAA8C,CAAC;AAE/F,MAAM,WAAW,GAAG,IAAI,UAAU,EAAE,CAAC;AAErC,MAAM,qBAAqB,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,sBAAsB,CAAC,CAAC;AAKhF,MAAM,OAAO,MAAO,SAAQ,OAAgC;IAU1D,YAAY,SAAkC,EAAE,UAAU,EAA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AAC,GAAG,CAAC,CAAC;QACZ,MAAM,CAAC,GAAG,CAAC,CAAC;QACZ,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAE1D,OAAO,cAAc,CAAC,IAAI;YACxB,CAAC,CAAC,IAAI,YAAY,EAAE,CAAC,gBAAgB,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;YACpG,CAAC,CAAC,IAAI,YAAY,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IACtG,CAAC;IAED,KAAK;QACH,OAAO,IAAI,MAAM,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IAC3C,CAAC;IAED,oBAAoB;QAClB,OAAO,MAAM,CAAC,mBAAmB,CAAC;IACpC,CAAC;;AAnMM,oBAAa,GAAiC,EAAE,CAAC;AAEjD,0BAAmB,mBACxB,UAAU,EAAE,CAAC,IACV,mBAAmB,EACtB;AAiMJ,MAAM,UAAU,YAAY,CAAC,UAAmC;IAC9D,OAAO,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;AAChC,CAAC","file":"symbol.js","sourcesContent":["import type { IAABBBounds } from '@visactor/vutils';\nimport { AABBBounds } from '@visactor/vutils';\nimport { isArray, max } from '@visactor/vutils';\nimport type { ISymbol, ISymbolClass, ISymbolGraphicAttribute } from '../interface';\nimport { builtinSymbolsMap, builtInSymbolStrMap, CustomSymbolClass } from './builtin-symbol';\nimport { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme } from './theme';\nimport { application } from '../application';\nimport { CustomPath2D } from '../common/custom-path2d';\nimport { SVG_PARSE_ATTRIBUTE_MAP, SVG_PARSE_ATTRIBUTE_MAP_KEYS, SYMBOL_NUMBER_TYPE } from './constants';\nimport { XMLParser } from '../common/xml';\nimport { isSvg } from '../common/xml/parser';\nimport { updateBoundsOfSymbolOuterBorder } from './graphic-service/symbol-outer-border-bounds';\n\nconst _tempBounds = new AABBBounds();\n\nconst SYMBOL_UPDATE_TAG_KEY = ['symbolType', 'size', ...GRAPHIC_UPDATE_TAG_KEY];\n\n/**\n * symbol\n */\nexport class Symbol extends Graphic<ISymbolGraphicAttribute> implements ISymbol {\n type: 'symbol' = 'symbol';\n\n static userSymbolMap: Record<string, ISymbolClass> = {};\n\n static NOWORK_ANIMATE_ATTR = {\n symbolType: 1,\n ...NOWORK_ANIMATE_ATTR\n };\n\n constructor(params: ISymbolGraphicAttribute = { symbolType: 'circle' }) {\n super(params);\n this.numberType = SYMBOL_NUMBER_TYPE;\n }\n\n protected _parsedPath?: ISymbolClass;\n\n getParsedPath(): ISymbolClass {\n if (this.shouldUpdateShape()) {\n this.doUpdateParsedPath();\n this.clearUpdateShapeTag();\n }\n return this._parsedPath as ISymbolClass;\n }\n\n getParsedPath2D(x = 0, y = 0, size = 1): Path2D | null {\n let path: Path2D | null = null;\n try {\n path = new Path2D();\n } catch (err) {\n return null;\n }\n const parsedPath = this.getParsedPath();\n if (!parsedPath) {\n return null;\n }\n parsedPath.draw(path, size, x, y);\n }\n\n isValid(): boolean {\n return super.isValid() && this._isValid();\n }\n private _isValid(): boolean {\n const { size } = this.attribute;\n return isArray(size) ? size.length === 2 && size.every(this._validNumber) : this._validNumber(size);\n }\n\n protected doUpdateParsedPath(): ISymbolClass {\n const symbolTheme = this.getGraphicTheme();\n // 查找内置symbol\n let { symbolType = symbolTheme.symbolType } = this.attribute;\n let path = builtinSymbolsMap[symbolType];\n if (path) {\n this._parsedPath = path;\n return path;\n }\n path = Symbol.userSymbolMap[symbolType];\n if (path) {\n this._parsedPath = path;\n return path;\n }\n\n const _symbolType = builtInSymbolStrMap[symbolType];\n symbolType = _symbolType || symbolType;\n // 判断是否是svg\n const valid = isSvg(symbolType);\n if (valid === true) {\n const parser = new XMLParser();\n const { svg } = parser.parse(symbolType);\n if (!svg) {\n return null;\n }\n const path = isArray(svg.path) ? svg.path : [svg.path];\n _tempBounds.clear();\n const cacheList: { path: CustomPath2D; attribute: Record<string, any> }[] = [];\n path.forEach((item: any) => {\n const cache = new CustomPath2D().fromString(item.d);\n const attribute: any = {};\n SVG_PARSE_ATTRIBUTE_MAP_KEYS.forEach(k => {\n if (item[k]) {\n (attribute as any)[(SVG_PARSE_ATTRIBUTE_MAP as any)[k]] = item[k];\n }\n });\n // 查找\n cacheList.push({\n path: cache,\n attribute\n });\n _tempBounds.union(cache.bounds);\n });\n const width = _tempBounds.width();\n const height = _tempBounds.height();\n // 规范化到1\n const maxWH = max(width, height);\n const scale = 1 / maxWH;\n cacheList.forEach(cache => cache.path.transform(0, 0, scale, scale));\n\n this._parsedPath = new CustomSymbolClass(symbolType, cacheList, true);\n Symbol.userSymbolMap[symbolType] = this._parsedPath;\n return this._parsedPath;\n }\n\n const cache = new CustomPath2D().fromString(symbolType);\n const width = cache.bounds.width();\n const height = cache.bounds.height();\n // 规范化到1\n const maxWH = max(width, height);\n const scale = 1 / maxWH;\n cache.transform(0, 0, scale, scale);\n this._parsedPath = new CustomSymbolClass(symbolType, cache);\n Symbol.userSymbolMap[symbolType] = this._parsedPath;\n return this._parsedPath;\n }\n\n getGraphicTheme(): Required<ISymbolGraphicAttribute> {\n return getTheme(this).symbol;\n }\n\n protected updateAABBBounds(\n attribute: ISymbolGraphicAttribute,\n symbolTheme: Required<ISymbolGraphicAttribute>,\n aabbBounds: IAABBBounds,\n full?: boolean\n ) {\n if (!this.updatePathProxyAABBBounds(aabbBounds)) {\n full\n ? this.updateSymbolAABBBoundsImprecise(attribute, symbolTheme, aabbBounds)\n : this.updateSymbolAABBBoundsAccurate(attribute, symbolTheme, aabbBounds);\n }\n\n const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds);\n\n updateBoundsOfSymbolOuterBorder(attribute, symbolTheme, tb1);\n aabbBounds.union(tb1);\n tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);\n\n const { lineJoin = symbolTheme.lineJoin } = attribute;\n application.graphicService.transformAABBBounds(attribute, aabbBounds, symbolTheme, lineJoin === 'miter', this);\n return aabbBounds;\n }\n\n protected updateSymbolAABBBoundsImprecise(\n attribute: ISymbolGraphicAttribute,\n symbolTheme: Required<ISymbolGraphicAttribute>,\n aabbBounds: IAABBBounds\n ): IAABBBounds {\n // 当做正方形计算\n const { size = symbolTheme.size } = attribute;\n\n if (isArray(size)) {\n aabbBounds.set(-size[0] / 2, -size[1] / 2, size[0] / 2, size[1] / 2);\n } else {\n const halfWH = size / 2;\n\n aabbBounds.set(-halfWH, -halfWH, halfWH, halfWH);\n }\n\n return aabbBounds;\n }\n\n protected updateSymbolAABBBoundsAccurate(\n attribute: ISymbolGraphicAttribute,\n symbolTheme: Required<ISymbolGraphicAttribute>,\n aabbBounds: IAABBBounds\n ): IAABBBounds {\n const { size = symbolTheme.size } = attribute;\n\n const symbolClass = this.getParsedPath();\n symbolClass.bounds(size, aabbBounds);\n\n return aabbBounds;\n }\n\n protected needUpdateTags(keys: string[]): boolean {\n return super.needUpdateTags(keys, SYMBOL_UPDATE_TAG_KEY);\n }\n protected needUpdateTag(key: string): boolean {\n return super.needUpdateTag(key, SYMBOL_UPDATE_TAG_KEY);\n }\n\n toCustomPath() {\n const symbolInstance = this.getParsedPath();\n const size = this.attribute.size;\n const x = 0;\n const y = 0;\n const formattedSize = isArray(size) ? size : [size, size];\n\n return symbolInstance.path\n ? new CustomPath2D().fromCustomPath2D(symbolInstance.path, x, y, formattedSize[0], formattedSize[1])\n : new CustomPath2D().fromString(symbolInstance.pathStr, x, y, formattedSize[0], formattedSize[1]);\n }\n\n clone() {\n return new Symbol({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Symbol.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createSymbol(attributes: ISymbolGraphicAttribute): ISymbol {\n return new Symbol(attributes);\n}\n\n// addAttributeToPrototype(DefaultSymbolStyle, Symbol, PURE_STYLE_KEY);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/arc.ts"],"names":[],"mappings":"","file":"arc.js","sourcesContent":["import type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { ICustomPath2D } from '../path';\n\n/**\n * 扇区属性\n */\nexport type IArcAttribute = {\n
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/arc.ts"],"names":[],"mappings":"","file":"arc.js","sourcesContent":["import type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { ICustomPath2D } from '../path';\n\n/**\n * 扇区属性\n */\nexport type IArcAttribute = {\n /**\n * 内半径\n */\n innerRadius: number;\n /**\n * 外半径\n */\n outerRadius: number;\n /**\n * 内边距\n */\n innerPadding: number;\n /**\n * 外边距\n */\n outerPadding: number;\n /**\n * 起始角度;\n * 以弧度的形式指定,0 表示 12 点钟方向并且顺时针方向为正。\n * 如果 |endAngle - startAngle| ≥ τ 则会绘制一个完整的扇形或圆环\n */\n startAngle: number;\n /**\n * 终止角度;\n * 以弧度的形式指定,0 表示 12 点钟方向并且顺时针方向为正。\n * 如果 |endAngle - startAngle| ≥ τ 则会绘制一个完整的扇形或圆环\n */\n endAngle: number;\n /**\n * 用于指定扇形区块的内外圆角半径,支持设置固定数值 或者 相对于扇形区块的半径差(| outerRadius - innerRadius |)的百分比值\n * 支持分别配置从外到内顺时针方向四个角的圆角半径,百分比值为相对于内外扇形的半径差。\n * 其中\n *\n * cornerRadius: 10:表示内圆角半径和外圆角半径都是 10px。\n * cornerRadius: '20%':表示内圆角半径和外圆角半径都是扇形区块半径的 20%。\n * cornerRadius: [10, 20]:表示为环形图时,外圆角半径是 10px、内圆角半径是 20px。\n * cornerRadius: ['20%', '50%']:表示为环形图时,外圆角半径是内外圆半径差的 20%、内圆角半径是内外圆半径差的 50%。\n * cornerRadius: [5, 10, 15, 20]:表示外圆角半径分别为 5px 和 10px,内圆角半径分别为 15px 和 20px。\n *\n * 也支持如下形式的配置:\n * cornerRadius: [5, '10%', '20%', 10]\n * TODO: 暂不支持\n */\n cornerRadius: number | string | Array<number | string>;\n /**\n * 间隙角度;间隔角度会转换为一个在两个相邻的弧之间的确定的线性距离,定义为 padRadius * | padAngle |\n * 这个距离在弧的开始和结束处都是相等的;\n * 间隔角度通常只应用于环形扇区(即当内半径大于 0)\n */\n padAngle: number;\n /**\n * 间隙半径\n */\n padRadius: number;\n\n /**\n * 对应了线段的 lineCap 属性,lineCap 表示的是线段末端如何绘制\n * cap: true 表示在弧线的起始位置都增加一个角度,角度是 | outerRadius - innerRadius | / outerRadius\n */\n cap: boolean | [boolean, boolean];\n /**\n * 当cap = true 并且 使用了渐变填充的时候,自动实现conical渐变,也就是环形的渐变\n */\n forceShowCap: boolean;\n};\n/**\n * 内部缓存,用于存储一些内部变量\n */\nexport type IArcCache = {\n /** 解析后的圆角配置 */\n cornerRadius?: [number, number, number, number];\n startAngle?: number;\n endAngle?: number;\n};\n\nexport type IArcGraphicAttribute = Partial<IGraphicAttribute> & Partial<IArcAttribute>;\n\nexport interface IArc extends IGraphic<IArcGraphicAttribute> {\n cache?: ICustomPath2D;\n\n getParsedCornerRadius: () => number | number[];\n getParsedAngle: () => { startAngle: number; endAngle: number; sc?: number; ec?: number };\n getParsePadAngle: (\n startAngle: number,\n endAngle: number\n ) => {\n outerStartAngle: number;\n outerEndAngle: number;\n innerStartAngle: number;\n innerEndAngle: number;\n\n outerDeltaAngle: number;\n innerDeltaAngle: number;\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/area.ts"],"names":[],"mappings":"","file":"area.js","sourcesContent":["import type { IPointLike } from '@visactor/vutils';\nimport type { ISegPath2D } from '../curve';\nimport type { IConnectedStyle, IGraphic, IGraphicAttribute } from '../graphic';\nimport type { ICurveType } from '../common';\n\nexport type IAreaAttribute = {\n segments: IAreaSegment[]
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/area.ts"],"names":[],"mappings":"","file":"area.js","sourcesContent":["import type { IPointLike } from '@visactor/vutils';\nimport type { ISegPath2D } from '../curve';\nimport type { IConnectedStyle, IGraphic, IGraphicAttribute } from '../graphic';\nimport type { ICurveType } from '../common';\n\nexport type IAreaAttribute = {\n /**\n * 分段设置point和样式\n */\n segments: IAreaSegment[];\n /**\n * 所有的点坐标\n */\n points: IPointLike[];\n /**\n * 曲线的类型,默认为linear\n */\n curveType: ICurveType;\n /**\n * 线段的裁切比例/显示长度占总长度的比例\n */\n clipRange: number;\n /**\n * 是否是闭合曲线\n */\n closePath: boolean;\n /**\n * 曲线类型为catmullRom时,对应的张力参数\n */\n curveTension: number;\n};\n\nexport type IAreaCacheItem = {\n top: ISegPath2D;\n bottom: ISegPath2D;\n};\n\nexport type IAreaGraphicAttribute = Partial<IGraphicAttribute> & Partial<IAreaAttribute> & Partial<IConnectedStyle>;\n\nexport interface IArea extends IGraphic<IAreaGraphicAttribute> {\n cacheArea?: IAreaCacheItem | IAreaCacheItem[];\n}\n\ntype ISegmentStyle = Pick<\n IGraphicAttribute,\n 'fill' | 'fillOpacity' | 'background' | 'texture' | 'textureColor' | 'textureSize' | 'texturePadding'\n>;\n\nexport interface IAreaSegment extends Partial<ISegmentStyle>, Partial<IConnectedStyle> {\n points: IPointLike[];\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/circle.ts"],"names":[],"mappings":"","file":"circle.js","sourcesContent":["import type { IGraphicAttribute, IGraphic } from '../graphic';\n\nexport type ICircleAttribute = {\n radius: number;\n startAngle: number;\n endAngle: number;\n};\n\nexport type ICircleGraphicAttribute = Partial<IGraphicAttribute> & Partial<ICircleAttribute>;\n\nexport type ICircle = IGraphic<ICircleGraphicAttribute>;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/circle.ts"],"names":[],"mappings":"","file":"circle.js","sourcesContent":["import type { IGraphicAttribute, IGraphic } from '../graphic';\n\nexport type ICircleAttribute = {\n /**\n * 半径\n */\n radius: number;\n /**\n * 起始角度,单位为弧度\n */\n startAngle: number;\n /**\n * 终止角度,单位为弧度\n */\n endAngle: number;\n};\n\nexport type ICircleGraphicAttribute = Partial<IGraphicAttribute> & Partial<ICircleAttribute>;\n\nexport type ICircle = IGraphic<ICircleGraphicAttribute>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/group.ts"],"names":[],"mappings":"","file":"group.js","sourcesContent":["import type { ITheme, IThemeSpec } from './theme';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { INode } from '../node-tree';\nimport type { GraphicAttributeMap } from './creator';\n\nexport type IGroupAttribute = {\n path: IGraphic[];\n width: number;\n height: number;\n cornerRadius: number | number[];\n cornerType: 'round' | 'bevel';\n clip: boolean;\n visibleAll: boolean;\n display?: 'relative' | 'inner-block' | 'flex';\n flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse';\n flexWrap?: 'nowrap' | 'wrap';\n justifyContent?: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';\n alignItems?: 'flex-start' | 'flex-end' | 'center';\n alignContent?: 'flex-start' | 'center' | 'space-between' | 'space-around';\n
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/group.ts"],"names":[],"mappings":"","file":"group.js","sourcesContent":["import type { ITheme, IThemeSpec } from './theme';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { INode } from '../node-tree';\nimport type { GraphicAttributeMap } from './creator';\n\nexport type IGroupAttribute = {\n /**\n * 路径,用于绘制路径图形或者设置裁剪图形\n */\n path: IGraphic[];\n /**\n * 宽度\n */\n width: number;\n /**\n * 高度\n */\n height: number;\n /**\n * 圆角半径\n */\n cornerRadius: number | number[];\n /**\n * 圆角类型,\n * 'round' - 圆弧\n * 'bevel' - 斜角\n */\n cornerType: 'round' | 'bevel';\n /**\n * 是否剪裁\n */\n clip: boolean;\n /**\n * 所有的子节点是否可见\n */\n visibleAll: boolean;\n /**\n * 布局方式\n */\n display?: 'relative' | 'inner-block' | 'flex';\n /**\n * flex布局的方向\n */\n flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse';\n /**\n * flex布局的换行\n */\n flexWrap?: 'nowrap' | 'wrap';\n /**\n * flex布局中,子元素在主轴上的对齐方式\n */\n justifyContent?: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around';\n /**\n * flex布局中,子元素在交叉轴上的对齐方式\n */\n alignItems?: 'flex-start' | 'flex-end' | 'center';\n /**\n * flex布局中,多行内容的垂直对齐方式\n */\n alignContent?: 'flex-start' | 'center' | 'space-between' | 'space-around';\n /**\n * 基准的透明度,用于控制group下面整体图元的透明度\n */\n baseOpacity?: number;\n};\n\nexport type IGroupGraphicAttribute = Partial<IGraphicAttribute> & Partial<IGroupAttribute>;\n\nexport interface IGroup extends IGraphic<IGroupGraphicAttribute> {\n childrenPickable?: boolean; // 子元素是否可以被pick\n\n theme?: ITheme;\n\n createTheme: () => void;\n hideAll: () => void;\n showAll: () => void;\n\n setTheme: (t: IThemeSpec) => void;\n\n incrementalAppendChild: (node: INode, highPerformance?: boolean) => INode | null;\n incrementalClearChild: () => void;\n\n createOrUpdateChild: <T extends keyof GraphicAttributeMap>(\n graphicName: string,\n attributes: GraphicAttributeMap[T],\n graphicType: T\n ) => INode;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/image.ts"],"names":[],"mappings":"","file":"image.js","sourcesContent":["import type { IGraphicAttribute, IGraphic } from '../graphic';\n\nexport type IRepeatType = 'no-repeat' | 'repeat';\n\nexport type IImageAttribute = {\n width: number;\n height: number;\n repeatX: IRepeatType;\n repeatY: IRepeatType;\n image: string | HTMLImageElement | HTMLCanvasElement;\n cornerRadius: number | number[];\n cornerType: 'round' | 'bevel';\n};\n\nexport type IImageGraphicAttribute = Partial<IGraphicAttribute> & Partial<IImageAttribute>;\n\nexport interface IImage extends IGraphic<IImageGraphicAttribute> {\n successCallback?: () => void;\n failCallback?: () => void;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/image.ts"],"names":[],"mappings":"","file":"image.js","sourcesContent":["import type { IGraphicAttribute, IGraphic } from '../graphic';\n\nexport type IRepeatType = 'no-repeat' | 'repeat';\n\nexport type IImageAttribute = {\n /**\n * 宽度\n */\n width: number;\n /**\n * 高度\n */\n height: number;\n /**\n * x方向的重复方式\n */\n repeatX: IRepeatType;\n /**\n * y方向的重复方式\n */\n repeatY: IRepeatType;\n /**\n * 图像url或者内容\n */\n image: string | HTMLImageElement | HTMLCanvasElement;\n /**\n * 圆角半径\n */\n cornerRadius: number | number[];\n /**\n * 圆角类型,\n * 'round' - 圆弧\n * 'bevel' - 斜角\n */\n cornerType: 'round' | 'bevel';\n};\n\nexport type IImageGraphicAttribute = Partial<IGraphicAttribute> & Partial<IImageAttribute>;\n\nexport interface IImage extends IGraphic<IImageGraphicAttribute> {\n successCallback?: () => void;\n failCallback?: () => void;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/line.ts"],"names":[],"mappings":"","file":"line.js","sourcesContent":["import type { IPointLike } from '@visactor/vutils';\nimport type { IGraphicAttribute, IGraphic, IConnectedStyle } from '../graphic';\nimport type { ICurveType } from '../common';\nimport type { ISegPath2D } from '../curve';\n\n// 依据x纬度做clipRange\n// 依据y纬度做clipRange\n// 依据线段自动匹配纬度做clipRange\n// 依据线长纬度做clipRange\nexport type IClipRangeByDimensionType = 'x' | 'y' | 'auto' | 'default';\n\nexport type ILineAttribute = {\n segments: ISegment[]
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/line.ts"],"names":[],"mappings":"","file":"line.js","sourcesContent":["import type { IPointLike } from '@visactor/vutils';\nimport type { IGraphicAttribute, IGraphic, IConnectedStyle } from '../graphic';\nimport type { ICurveType } from '../common';\nimport type { ISegPath2D } from '../curve';\n\n// 依据x纬度做clipRange\n// 依据y纬度做clipRange\n// 依据线段自动匹配纬度做clipRange\n// 依据线长纬度做clipRange\nexport type IClipRangeByDimensionType = 'x' | 'y' | 'auto' | 'default';\n\nexport type ILineAttribute = {\n /**\n * 分段设置point和样式\n */\n segments: ISegment[];\n /**\n * 所有点的坐标,segments 和 points 不能同时生效\n */\n points: IPointLike[];\n /**\n * 曲线的类型,默认为linear\n */\n curveType: ICurveType;\n /**\n * 线段的裁切比例/显示长度占总长度的比例\n */\n clipRange: number;\n /**\n * 裁剪的维度\n */\n clipRangeByDimension: IClipRangeByDimensionType;\n /**\n * 是否封闭路径\n */\n closePath: boolean;\n /**\n * 曲线类型为catmullRom时,对应的张力参数\n */\n curveTension: number;\n};\n\nexport type ILineGraphicAttribute = Partial<IGraphicAttribute> & Partial<ILineAttribute> & Partial<IConnectedStyle>;\n\nexport interface ILine extends IGraphic<ILineGraphicAttribute> {\n cache?: ISegPath2D | ISegPath2D[];\n}\n\ntype ISegmentStyle = Pick<\n IGraphicAttribute,\n 'stroke' | 'strokeOpacity' | 'lineDash' | 'lineDashOffset' | 'lineCap' | 'lineJoin' | 'lineWidth' | 'miterLimit'\n>;\n\nexport interface ISegment extends Partial<ISegmentStyle>, Partial<IConnectedStyle> {\n points: IPointLike[];\n simplify?: boolean;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/polygon.ts"],"names":[],"mappings":"","file":"polygon.js","sourcesContent":["import type { IPointLike } from '@visactor/vutils';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\n\nexport type IPolygonAttribute = {\n
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/polygon.ts"],"names":[],"mappings":"","file":"polygon.js","sourcesContent":["import type { IPointLike } from '@visactor/vutils';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\n\nexport type IPolygonAttribute = {\n /**\n * 多边形的顶点坐标\n */\n points: IPointLike[];\n /**\n * 圆角半径\n */\n cornerRadius?: number | number[];\n /**\n * 是否闭合多边形\n */\n closePath?: boolean;\n};\n\nexport type IPolygonGraphicAttribute = Partial<IGraphicAttribute> & Partial<IPolygonAttribute>;\n\nexport type IPolygon = IGraphic<IPolygonGraphicAttribute>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/rect.ts"],"names":[],"mappings":"","file":"rect.js","sourcesContent":["import type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { ICustomPath2D } from '../path';\n\nexport type IRectAttribute = {\n width: number;\n height: number;\n x1: number;\n y1: number;\n cornerRadius: number | number[];\n cornerType: 'round' | 'bevel';\n};\n\nexport type IRectGraphicAttribute = Partial<IGraphicAttribute> & Partial<IRectAttribute>;\n\nexport interface IRect extends IGraphic<IRectGraphicAttribute> {\n cache?: ICustomPath2D;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/rect.ts"],"names":[],"mappings":"","file":"rect.js","sourcesContent":["import type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { ICustomPath2D } from '../path';\n\nexport type IRectAttribute = {\n width: number;\n height: number;\n x1: number;\n y1: number;\n /**\n * 圆角半径\n */\n cornerRadius: number | number[];\n /**\n * 圆角类型,\n * 'round' - 圆弧\n * 'bevel' - 斜角\n */\n cornerType: 'round' | 'bevel';\n};\n\nexport type IRectGraphicAttribute = Partial<IGraphicAttribute> & Partial<IRectAttribute>;\n\nexport interface IRect extends IGraphic<IRectGraphicAttribute> {\n cache?: ICustomPath2D;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/richText.ts"],"names":[],"mappings":"","file":"richText.js","sourcesContent":["import type { IColor } from '../color';\nimport type { IContext2d } from '../context';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { IImage, IImageGraphicAttribute } from './image';\nimport type { ITextGraphicAttribute } from './text';\n\nexport type IRichTextEditOptionsType = {\n placeholder?: string;\n placeholderColor?: string;\n placeholderFontSize?: number;\n placeholderFontFamily?: string;\n // 是否将placeholder同步到textConfig中\n syncPlaceholderToTextConfig?: boolean;\n // 即使是空文本,是否也保持高度\n keepHeightWhileEmpty?: boolean;\n // 是否在输入的时候展示包围框,不传默认是false,可以传入颜色\n boundsStrokeWhenInput?: string;\n stopPropagation?: boolean;\n};\n\nexport type IRichTextAttribute = {\n /**\n * 富文本的总宽度\n */\n width: number;\n /**\n * 富文本的总高度\n */\n height: number;\n /**\n * 是否可编辑\n */\n editable: boolean;\n /**\n * 测量ascent和descent的模式,预览的时候actual比较合适,而如果需要编辑的话,font比较合适\n */\n ascentDescentMode?: 'actual' | 'font';\n /**\n * 富文本的编辑配置\n */\n editOptions: IRichTextEditOptionsType | null;\n /**\n * 文本超长的时候是否显示省略字符串\n * 1. boolean类型,true 表示将截断后的省略字符串设置为..., false 表示不显示省略字符串\n * 2. string类型,表示显示省略字符串,并将省略字符串设置为指定的值\n */\n ellipsis: boolean | string;\n /**\n * 文字换行类型\n */\n wordBreak: RichTextWordBreak;\n /**\n * 文字垂直方向\n */\n verticalDirection: RichTextVerticalDirection;\n /**\n * 富文本的最大高度,超过这个高度根据ellipsis的配置展示省略字符串或者直接截断\n */\n maxHeight: number;\n /**\n * 富文本的最大宽度,超过这个宽度根据ellipsis的配置展示省略字符串或者直接截断\n */\n maxWidth: number;\n /**\n * 文字对齐方式\n */\n textAlign: RichTextGlobalAlignType;\n /**\n * 文字基线\n */\n textBaseline: RichTextGlobalBaselineType;\n /**\n * 富文本的布局方向\n */\n layoutDirection: RichTextLayoutDirectionType;\n /**\n * 富文本的内容配置\n */\n textConfig: IRichTextCharacter[];\n /**\n * 不自动换行,仅当用户设置了换行符的时候才换行\n */\n disableAutoWrapLine: boolean;\n /**\n * 是否强制单行显示\n */\n singleLine: boolean;\n};\n\nexport type IRichTextGraphicAttribute = Partial<IGraphicAttribute & ITextGraphicAttribute> &\n Partial<IRichTextAttribute>;\n\nexport type RichTextWordBreak = 'break-word' | 'break-all';\nexport type RichTextVerticalDirection = 'top' | 'middle' | 'bottom';\nexport type RichTextGlobalAlignType = 'left' | 'right' | 'center';\nexport type RichTextGlobalBaselineType = 'top' | 'middle' | 'bottom';\nexport type RichTextLayoutDirectionType = 'horizontal' | 'vertical';\nexport type RichTextFontStyle = 'normal' | 'italic' | 'oblique';\nexport type RichTextTextDecoration = 'none' | 'underline' | 'line-through';\n// export type RichTextTextAlign = 'left' | 'right' | 'center';\nexport type RichTextScript = 'normal' | 'sub' | 'super';\n\nexport type IRichTextBasicCharacter = {\n /**\n * 行高\n */\n lineHeight?: number | string;\n /**\n * 文字对齐方式\n * left, right, center\n */\n textAlign?: CanvasTextAlign;\n /**\n * 文字基线\n */\n textBaseline?: CanvasTextBaseline;\n /**\n * 文字方向\n */\n direction?: RichTextLayoutDirectionType;\n};\n\n/**\n * 富文本段落为文本类型时候的配置\n */\nexport type IRichTextParagraphCharacter = IRichTextBasicCharacter & {\n /**\n * 文本内容\n */\n text: string | number;\n /**\n * 富文本片段的字体大小\n */\n fontSize?: number;\n /**\n * 富文本片段的字体类型\n */\n fontFamily?: string;\n /**\n * 富文本片段的文字颜色\n */\n fill?: IColor | boolean;\n /**\n * 富文本片段的文字描边颜色\n */\n stroke?: IColor | boolean;\n /**\n * 富文本片段的文字字重\n */\n fontWeight?: string;\n /**\n * 富文本片段的文字描边宽度\n */\n lineWidth?: number;\n // lineHeight?: number;\n /**\n * 富文本片段的文字斜体设置,支持以下属性\n * normal, italic, oblique\n */\n fontStyle?: RichTextFontStyle;\n /**\n * 富文本片段的文字中划线设置,支持以下属性\n * none, underline, line-through\n */\n textDecoration?: RichTextTextDecoration;\n // textAlign?: RichTextTextAlign; // left, right, center\n script?: RichTextScript; // normal, sub, super\n /**\n * 富文本片段的文字下划线设置,是否显示下划线\n */\n underline?: boolean;\n /**\n * 富文本片段的文字中划线设置,是否显示中划线\n */\n lineThrough?: boolean;\n /**\n * 富文本片段的透明度\n */\n opacity?: number;\n /**\n * 富文本片段的文字填充透明度\n */\n fillOpacity?: number;\n /**\n * 富文本片段的文字描边透明度\n */\n strokeOpacity?: number;\n // 仅支持纯色背景\n background?: string;\n // 背景透明度\n backgroundOpacity?: number;\n // direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextImageCharacter = IRichTextBasicCharacter & {\n /**\n * 设置图片的内容,\n * 支持三种格式:\n * 1. 图片的url\n * 2. 图片的Image对象\n * 3. 图片的Canvas对象\n */\n image: string | HTMLImageElement | HTMLCanvasElement;\n /**\n * 图片的宽度\n */\n width: number;\n /**\n * 图片的高度\n */\n height: number;\n\n // hover相关属性\n // backgroundShow?: boolean; // 是否显示background\n /**\n * 背景的展示模式,支持以下属性\n * always: 一直显示\n * hover: 鼠标hover时显示\n */\n backgroundShowMode?: 'always' | 'hover';\n /**\n * 背景矩形填充颜色\n */\n backgroundFill?: boolean | IColor;\n /**\n * 背景矩形填充透明度\n */\n backgroundFillOpacity?: number;\n /**\n * 背景矩形边框颜色\n */\n backgroundStroke?: boolean | IColor;\n /**\n * 背景矩形边框透明度\n */\n backgroundStrokeOpacity?: number;\n /**\n * 背景矩形圆角\n */\n backgroundRadius?: number;\n // background size 同时控制了该icon的响应范围\n /**\n * 背景矩形的宽度\n */\n backgroundWidth?: number;\n /**\n * 背景矩形的高度\n */\n backgroundHeight?: number;\n\n /**\n * 唯一标识符\n */\n id?: string;\n\n // lineHeight?: number;\n // textAlign?: RichTextTextAlign; // left, right, center\n // direction?: RichTextLayoutDirectionType;\n /**\n * 图片与相邻节点的间距\n */\n margin?: number | number[];\n\n funcType?: string;\n hoverImage?: string | HTMLImageElement | HTMLCanvasElement;\n};\n/**\n * 富文本的字符类型\n */\nexport type IRichTextCharacter = IRichTextParagraphCharacter | IRichTextImageCharacter;\n\nexport type IRichTextIconGraphicAttribute = IImageGraphicAttribute & {\n /**\n * 唯一id\n */\n id?: string;\n /**\n * 背景的展示模式,支持以下属性\n * always: 一直显示\n * hover: 鼠标hover时显示\n * never: 不显示\n */\n backgroundShowMode?: 'always' | 'hover' | 'never';\n /**\n * 背景矩形填充颜色\n */\n backgroundFill?: boolean | IColor;\n /**\n * 背景矩形填充透明度\n */\n backgroundFillOpacity?: number;\n /**\n * 背景矩形边框颜色\n */\n backgroundStroke?: boolean | IColor;\n /**\n * 背景矩形边框透明度\n */\n backgroundStrokeOpacity?: number;\n /**\n * 背景矩形圆角\n */\n backgroundRadius?: number;\n /**\n * 背景矩形的宽度\n */\n backgroundWidth?: number;\n /**\n * 背景矩形的高度\n */\n backgroundHeight?: number;\n\n // lineHeight?: number;\n /**\n * 文字对齐方式\n * left, right, center\n */\n textAlign?: CanvasTextAlign;\n /**\n * 文字基线\n * top, middle, bottom\n */\n textBaseline?: CanvasTextBaseline;\n /**\n * 文字方向\n * horizontal, vertical\n */\n direction?: RichTextLayoutDirectionType;\n /**\n * 图片与相邻节点的间距\n */\n margin?: number | number[];\n\n // backgroundShow?: boolean;\n};\n\nexport interface IRichTextParagraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n direction?: 'horizontal' | 'vertical';\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n updateWidth: () => void;\n draw: (ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) => void;\n getWidthWithEllips: (direction: string) => number;\n}\n\nexport interface IRichTextLine {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (IRichTextParagraph | IRichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n x: string;\n y: string;\n };\n draw: (\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawEllipsis: boolean | string,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => void;\n getWidthWithEllips: (ellipsis: string) => number;\n}\n\nexport interface IRichTextFrame {\n left: number;\n top: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n actualHeight: number;\n ellipsis: boolean | string;\n wordBreak: 'break-word' | 'break-all';\n verticalDirection: 'top' | 'middle' | 'bottom';\n lines: IRichTextLine[];\n globalAlign: 'left' | 'center' | 'right' | 'start' | 'end';\n globalBaseline: 'top' | 'middle' | 'bottom';\n layoutDirection: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n top: string;\n bottom: string;\n };\n isWidthMax: boolean;\n isHeightMax: boolean;\n singleLine: boolean;\n icons: Map<string, IRichTextIcon>;\n draw: (\n ctx: IContext2d,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => boolean;\n getActualSize: () => {\n width: number;\n height: number;\n };\n getRawActualSize: () => {\n width: number;\n height: number;\n };\n getActualSizeWidthEllipsis: () => {\n width: number;\n height: number;\n };\n}\n\nexport interface IRichText extends IGraphic<IRichTextGraphicAttribute> {\n getFrameCache: () => IRichTextFrame;\n cliped?: boolean;\n}\n\nexport interface IRichTextIcon extends IImage {\n attribute: IRichTextIconGraphicAttribute;\n richtextId?: string;\n globalX?: number;\n globalY?: number;\n\n _x: number;\n _y: number;\n _hovered: boolean;\n _marginArray: [number, number, number, number];\n\n setHoverState: (hovered: boolean) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/richText.ts"],"names":[],"mappings":"","file":"richText.js","sourcesContent":["import type { IColor } from '../color';\nimport type { IContext2d } from '../context';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { IImage, IImageGraphicAttribute } from './image';\nimport type { ITextGraphicAttribute } from './text';\n\nexport type IRichTextEditOptionsType = {\n placeholder?: string;\n placeholderColor?: string;\n placeholderFontSize?: number;\n placeholderFontFamily?: string;\n // 是否将placeholder同步到textConfig中\n syncPlaceholderToTextConfig?: boolean;\n // 即使是空文本,是否也保持高度\n keepHeightWhileEmpty?: boolean;\n // 是否在输入的时候展示包围框,不传默认是false,可以传入颜色\n boundsStrokeWhenInput?: string;\n stopPropagation?: boolean;\n};\n\nexport type IRichTextAttribute = {\n /**\n * @since 0.22.1\n * 升级后避免break change,通过开关来控制\n */\n upgradeAttrs: {\n lineHeight: true;\n multiBreakLine: true;\n } | null;\n /**\n * 富文本的总宽度\n */\n width: number;\n /**\n * 富文本的总高度\n */\n height: number;\n /**\n * 是否可编辑\n */\n editable: boolean;\n /**\n * 测量ascent和descent的模式,预览的时候actual比较合适,而如果需要编辑的话,font比较合适\n */\n ascentDescentMode?: 'actual' | 'font';\n /**\n * 富文本的编辑配置\n */\n editOptions: IRichTextEditOptionsType | null;\n /**\n * 文本超长的时候是否显示省略字符串\n * 1. boolean类型,true 表示将截断后的省略字符串设置为..., false 表示不显示省略字符串\n * 2. string类型,表示显示省略字符串,并将省略字符串设置为指定的值\n */\n ellipsis: boolean | string;\n /**\n * 文字换行类型\n */\n wordBreak: RichTextWordBreak;\n /**\n * 文字垂直方向\n */\n verticalDirection: RichTextVerticalDirection;\n /**\n * 富文本的最大高度,超过这个高度根据ellipsis的配置展示省略字符串或者直接截断\n */\n maxHeight: number;\n /**\n * 富文本的最大宽度,超过这个宽度根据ellipsis的配置展示省略字符串或者直接截断\n */\n maxWidth: number;\n /**\n * 文字对齐方式\n */\n textAlign: RichTextGlobalAlignType;\n /**\n * 文字基线\n */\n textBaseline: RichTextGlobalBaselineType;\n /**\n * 富文本的布局方向\n */\n layoutDirection: RichTextLayoutDirectionType;\n /**\n * 富文本的内容配置\n */\n textConfig: IRichTextCharacter[];\n /**\n * 不自动换行,仅当用户设置了换行符的时候才换行\n */\n disableAutoWrapLine: boolean;\n /**\n * 是否强制单行显示\n */\n singleLine: boolean;\n};\n\nexport type IRichTextGraphicAttribute = Partial<IGraphicAttribute & ITextGraphicAttribute> &\n Partial<IRichTextAttribute>;\n\nexport type RichTextWordBreak = 'break-word' | 'break-all';\nexport type RichTextVerticalDirection = 'top' | 'middle' | 'bottom';\nexport type RichTextGlobalAlignType = 'left' | 'right' | 'center';\nexport type RichTextGlobalBaselineType = 'top' | 'middle' | 'bottom';\nexport type RichTextLayoutDirectionType = 'horizontal' | 'vertical';\nexport type RichTextFontStyle = 'normal' | 'italic' | 'oblique';\nexport type RichTextTextDecoration = 'none' | 'underline' | 'line-through';\n// export type RichTextTextAlign = 'left' | 'right' | 'center';\nexport type RichTextScript = 'normal' | 'sub' | 'super';\n\nexport type IRichTextBasicCharacter = {\n /**\n * 行高\n */\n lineHeight?: number | string;\n /**\n * 文字对齐方式\n * left, right, center\n */\n textAlign?: CanvasTextAlign;\n /**\n * 文字基线\n */\n textBaseline?: CanvasTextBaseline;\n /**\n * 文字方向\n */\n direction?: RichTextLayoutDirectionType;\n};\n\n/**\n * 富文本段落为文本类型时候的配置\n */\nexport type IRichTextParagraphCharacter = IRichTextBasicCharacter & {\n /**\n * 文本内容\n */\n text: string | number;\n /**\n * 富文本片段的字体大小\n */\n fontSize?: number;\n /**\n * 富文本片段的字体类型\n */\n fontFamily?: string;\n /**\n * 富文本片段的文字颜色\n */\n fill?: IColor | boolean;\n /**\n * 富文本片段的文字描边颜色\n */\n stroke?: IColor | boolean;\n /**\n * 富文本片段的文字字重\n */\n fontWeight?: string;\n /**\n * 富文本片段的文字描边宽度\n */\n lineWidth?: number;\n // lineHeight?: number;\n /**\n * 富文本片段的文字斜体设置,支持以下属性\n * normal, italic, oblique\n */\n fontStyle?: RichTextFontStyle;\n /**\n * 富文本片段的文字中划线设置,支持以下属性\n * none, underline, line-through\n */\n textDecoration?: RichTextTextDecoration;\n // textAlign?: RichTextTextAlign; // left, right, center\n script?: RichTextScript; // normal, sub, super\n /**\n * 富文本片段的文字下划线设置,是否显示下划线\n */\n underline?: boolean;\n /**\n * 富文本片段的文字中划线设置,是否显示中划线\n */\n lineThrough?: boolean;\n /**\n * 富文本片段的透明度\n */\n opacity?: number;\n /**\n * 富文本片段的文字填充透明度\n */\n fillOpacity?: number;\n /**\n * 富文本片段的文字描边透明度\n */\n strokeOpacity?: number;\n // 仅支持纯色背景\n background?: string;\n // 背景透明度\n backgroundOpacity?: number;\n // direction?: RichTextLayoutDirectionType;\n};\n\nexport type IRichTextImageCharacter = IRichTextBasicCharacter & {\n /**\n * 设置图片的内容,\n * 支持三种格式:\n * 1. 图片的url\n * 2. 图片的Image对象\n * 3. 图片的Canvas对象\n */\n image: string | HTMLImageElement | HTMLCanvasElement;\n /**\n * 图片的宽度\n */\n width: number;\n /**\n * 图片的高度\n */\n height: number;\n\n // hover相关属性\n // backgroundShow?: boolean; // 是否显示background\n /**\n * 背景的展示模式,支持以下属性\n * always: 一直显示\n * hover: 鼠标hover时显示\n */\n backgroundShowMode?: 'always' | 'hover';\n /**\n * 背景矩形填充颜色\n */\n backgroundFill?: boolean | IColor;\n /**\n * 背景矩形填充透明度\n */\n backgroundFillOpacity?: number;\n /**\n * 背景矩形边框颜色\n */\n backgroundStroke?: boolean | IColor;\n /**\n * 背景矩形边框透明度\n */\n backgroundStrokeOpacity?: number;\n /**\n * 背景矩形圆角\n */\n backgroundRadius?: number;\n // background size 同时控制了该icon的响应范围\n /**\n * 背景矩形的宽度\n */\n backgroundWidth?: number;\n /**\n * 背景矩形的高度\n */\n backgroundHeight?: number;\n\n /**\n * 唯一标识符\n */\n id?: string;\n\n // lineHeight?: number;\n // textAlign?: RichTextTextAlign; // left, right, center\n // direction?: RichTextLayoutDirectionType;\n /**\n * 图片与相邻节点的间距\n */\n margin?: number | number[];\n\n funcType?: string;\n hoverImage?: string | HTMLImageElement | HTMLCanvasElement;\n};\n/**\n * 富文本的字符类型\n */\nexport type IRichTextCharacter = IRichTextParagraphCharacter | IRichTextImageCharacter;\n\nexport type IRichTextIconGraphicAttribute = IImageGraphicAttribute & {\n /**\n * 唯一id\n */\n id?: string;\n /**\n * 背景的展示模式,支持以下属性\n * always: 一直显示\n * hover: 鼠标hover时显示\n * never: 不显示\n */\n backgroundShowMode?: 'always' | 'hover' | 'never';\n /**\n * 背景矩形填充颜色\n */\n backgroundFill?: boolean | IColor;\n /**\n * 背景矩形填充透明度\n */\n backgroundFillOpacity?: number;\n /**\n * 背景矩形边框颜色\n */\n backgroundStroke?: boolean | IColor;\n /**\n * 背景矩形边框透明度\n */\n backgroundStrokeOpacity?: number;\n /**\n * 背景矩形圆角\n */\n backgroundRadius?: number;\n /**\n * 背景矩形的宽度\n */\n backgroundWidth?: number;\n /**\n * 背景矩形的高度\n */\n backgroundHeight?: number;\n\n // lineHeight?: number;\n /**\n * 文字对齐方式\n * left, right, center\n */\n textAlign?: CanvasTextAlign;\n /**\n * 文字基线\n * top, middle, bottom\n */\n textBaseline?: CanvasTextBaseline;\n /**\n * 文字方向\n * horizontal, vertical\n */\n direction?: RichTextLayoutDirectionType;\n /**\n * 图片与相邻节点的间距\n */\n margin?: number | number[];\n\n // backgroundShow?: boolean;\n};\n\nexport interface IRichTextParagraph {\n text: string;\n ascent: number;\n descent: number;\n width: number;\n height: number;\n lineHeight: number;\n fontSize: number;\n length: number;\n newLine: boolean;\n character: IRichTextParagraphCharacter;\n left: number;\n top: number;\n direction?: 'horizontal' | 'vertical';\n widthOrigin?: number;\n heightOrigin?: number;\n textBaseline?: CanvasTextBaseline;\n ellipsis: 'normal' | 'add' | 'replace' | 'hide';\n ellipsisWidth: number;\n ellipsisOtherParagraphWidth: number;\n verticalEllipsis?: boolean;\n updateWidth: () => void;\n draw: (ctx: IContext2d, baseline: number, deltaLeft: number, isLineFirst: boolean, textAlign: string) => void;\n getWidthWithEllips: (direction: string) => number;\n}\n\nexport interface IRichTextLine {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (IRichTextParagraph | IRichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n x: string;\n y: string;\n };\n draw: (\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawEllipsis: boolean | string,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => void;\n getWidthWithEllips: (ellipsis: string) => number;\n}\n\nexport interface IRichTextFrame {\n left: number;\n top: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n actualHeight: number;\n ellipsis: boolean | string;\n wordBreak: 'break-word' | 'break-all';\n verticalDirection: 'top' | 'middle' | 'bottom';\n lines: IRichTextLine[];\n globalAlign: 'left' | 'center' | 'right' | 'start' | 'end';\n globalBaseline: 'top' | 'middle' | 'bottom';\n layoutDirection: 'horizontal' | 'vertical';\n directionKey: {\n width: string;\n height: string;\n left: string;\n top: string;\n bottom: string;\n };\n isWidthMax: boolean;\n isHeightMax: boolean;\n singleLine: boolean;\n icons: Map<string, IRichTextIcon>;\n draw: (\n ctx: IContext2d,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) => boolean;\n getActualSize: () => {\n width: number;\n height: number;\n };\n getRawActualSize: () => {\n width: number;\n height: number;\n };\n getActualSizeWidthEllipsis: () => {\n width: number;\n height: number;\n };\n}\n\nexport interface IRichText extends IGraphic<IRichTextGraphicAttribute> {\n getFrameCache: () => IRichTextFrame;\n cliped?: boolean;\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"]}
|
|
@@ -9,6 +9,7 @@ export type ISymbolAttribute = {
|
|
|
9
9
|
export type ISymbolGraphicAttribute = Partial<IGraphicAttribute> & Partial<ISymbolAttribute>;
|
|
10
10
|
export interface ISymbol extends IGraphic<ISymbolGraphicAttribute> {
|
|
11
11
|
getParsedPath: () => ISymbolClass;
|
|
12
|
+
getParsedPath2D: (x?: number, y?: number, size?: number) => Path2D | null;
|
|
12
13
|
}
|
|
13
14
|
export type SymbolType = 'circle' | 'cross' | 'diamond' | 'square' | 'arrow' | 'arrowLeft' | 'arrowRight' | 'arrow2Left' | 'arrow2Right' | 'wedge' | 'thinTriangle' | 'triangle' | 'triangleUp' | 'triangleDown' | 'triangleRight' | 'triangleLeft' | 'stroke' | 'star' | 'wye' | 'rect' | 'rectRound' | 'roundLine' | string;
|
|
14
15
|
export interface ISymbolClass {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/symbol.ts"],"names":[],"mappings":"","file":"symbol.js","sourcesContent":["import type { IBounds } from '@visactor/vutils';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { ICustomPath2D, IPath2D } from '../path';\n\nexport type ISymbolAttribute = {\n symbolType: SymbolType;\n size: number | [number, number];\n clipRange: number;\n};\n\nexport type ISymbolGraphicAttribute = Partial<IGraphicAttribute> & Partial<ISymbolAttribute>;\n\nexport interface ISymbol extends IGraphic<ISymbolGraphicAttribute> {\n getParsedPath: () => ISymbolClass;\n}\n\nexport type SymbolType =\n | 'circle'\n | 'cross'\n | 'diamond'\n | 'square'\n | 'arrow'\n | 'arrowLeft'\n | 'arrowRight'\n | 'arrow2Left'\n | 'arrow2Right'\n | 'wedge'\n | 'thinTriangle'\n | 'triangle'\n | 'triangleUp'\n | 'triangleDown'\n | 'triangleRight'\n | 'triangleLeft'\n | 'stroke'\n | 'star'\n | 'wye'\n | 'rect'\n | 'rectRound'\n | 'roundLine'\n | string;\n\nexport interface ISymbolClass {\n type: SymbolType | string;\n path?: ICustomPath2D;\n pathStr: string;\n isSvg?: boolean;\n\n // 返回true表示内部已经调用closePath,返回false表示没有调用closePath,外部需要调用closePath\n draw: (\n ctx: IPath2D,\n size: number | [number, number],\n x: number,\n y: number,\n z?: number,\n cb?: (p: ICustomPath2D, a: any) => void\n ) => boolean;\n drawWithClipRange?: (\n ctx: IPath2D,\n size: number | [number, number],\n x: number,\n y: number,\n clipRange: number,\n z?: number,\n cb?: (p: ICustomPath2D, a: any) => void\n ) => boolean;\n drawOffset: (\n ctx: IPath2D,\n size: number | [number, number],\n x: number,\n y: number,\n offset: number,\n z?: number,\n cb?: (p: ICustomPath2D, a: any) => void\n ) => boolean;\n\n drawToSvgPath?: (size: number | [number, number], x: number, y: number, z?: number) => string;\n\n bounds: (size: number | [number, number], bounds: IBounds) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/symbol.ts"],"names":[],"mappings":"","file":"symbol.js","sourcesContent":["import type { IBounds } from '@visactor/vutils';\nimport type { IGraphicAttribute, IGraphic } from '../graphic';\nimport type { ICustomPath2D, IPath2D } from '../path';\n\nexport type ISymbolAttribute = {\n symbolType: SymbolType;\n size: number | [number, number];\n clipRange: number;\n};\n\nexport type ISymbolGraphicAttribute = Partial<IGraphicAttribute> & Partial<ISymbolAttribute>;\n\nexport interface ISymbol extends IGraphic<ISymbolGraphicAttribute> {\n getParsedPath: () => ISymbolClass;\n getParsedPath2D: (x?: number, y?: number, size?: number) => Path2D | null;\n}\n\nexport type SymbolType =\n | 'circle'\n | 'cross'\n | 'diamond'\n | 'square'\n | 'arrow'\n | 'arrowLeft'\n | 'arrowRight'\n | 'arrow2Left'\n | 'arrow2Right'\n | 'wedge'\n | 'thinTriangle'\n | 'triangle'\n | 'triangleUp'\n | 'triangleDown'\n | 'triangleRight'\n | 'triangleLeft'\n | 'stroke'\n | 'star'\n | 'wye'\n | 'rect'\n | 'rectRound'\n | 'roundLine'\n | string;\n\nexport interface ISymbolClass {\n type: SymbolType | string;\n path?: ICustomPath2D;\n pathStr: string;\n isSvg?: boolean;\n\n // 返回true表示内部已经调用closePath,返回false表示没有调用closePath,外部需要调用closePath\n draw: (\n ctx: IPath2D,\n size: number | [number, number],\n x: number,\n y: number,\n z?: number,\n cb?: (p: ICustomPath2D, a: any) => void\n ) => boolean;\n drawWithClipRange?: (\n ctx: IPath2D,\n size: number | [number, number],\n x: number,\n y: number,\n clipRange: number,\n z?: number,\n cb?: (p: ICustomPath2D, a: any) => void\n ) => boolean;\n drawOffset: (\n ctx: IPath2D,\n size: number | [number, number],\n x: number,\n y: number,\n offset: number,\n z?: number,\n cb?: (p: ICustomPath2D, a: any) => void\n ) => boolean;\n\n drawToSvgPath?: (size: number | [number, number], x: number, y: number, z?: number) => string;\n\n bounds: (size: number | [number, number], bounds: IBounds) => void;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/graphic/text.ts"],"names":[],"mappings":"AAkCA,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,6DAAY,CAAA;IACZ,yEAAkB,CAAA;IAClB,qEAAgB,CAAA;AAClB,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B","file":"text.js","sourcesContent":["import type { IGraphicAttribute, IGraphic } from '../graphic';\n\nexport interface TextLayoutBBox {\n width: number; // 包围盒的宽度\n height: number; // 包围盒的高度\n xOffset: number;\n yOffset: number;\n}\n\nexport interface LayoutItemType {\n str: string; // 这行的字符串\n leftOffset?: number; // 该行距离左侧的偏移\n topOffset?: number; // 该行距离右侧的偏移\n width: number;\n ascent: number;\n descent: number;\n keepCenterInLine: boolean;\n}\n\nexport interface SimplifyLayoutType {\n lines: LayoutItemType[];\n}\n\nexport interface LayoutType {\n bbox: TextLayoutBBox;\n lines: LayoutItemType[];\n fontFamily: string;\n fontSize: number;\n fontWeight?: string | number;\n lineHeight: number;\n textAlign: TextAlignType;\n textBaseline: TextBaselineType;\n}\n\nexport enum MeasureModeEnum {\n estimate = 0,\n actualBounding = 1,\n fontBounding = 2\n}\n\nexport type ITextAttribute = {\n text: string | number | string[] | number[];\n maxLineWidth: number;\n maxWidth: number;\n textAlign: TextAlignType;\n textBaseline: TextBaselineType;\n fontSize: number;\n fontFamily: string;\n fontWeight: string | number;\n ellipsis: boolean | string;\n fontVariant: string;\n fontStyle: string;\n lineHeight: number | string;\n underline: number;\n lineThrough: number;\n scaleIn3d: boolean;\n direction: 'horizontal' | 'vertical';\n
|
|
1
|
+
{"version":3,"sources":["../src/interface/graphic/text.ts"],"names":[],"mappings":"AAkCA,MAAM,CAAN,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,6DAAY,CAAA;IACZ,yEAAkB,CAAA;IAClB,qEAAgB,CAAA;AAClB,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B","file":"text.js","sourcesContent":["import type { IGraphicAttribute, IGraphic } from '../graphic';\n\nexport interface TextLayoutBBox {\n width: number; // 包围盒的宽度\n height: number; // 包围盒的高度\n xOffset: number;\n yOffset: number;\n}\n\nexport interface LayoutItemType {\n str: string; // 这行的字符串\n leftOffset?: number; // 该行距离左侧的偏移\n topOffset?: number; // 该行距离右侧的偏移\n width: number;\n ascent: number;\n descent: number;\n keepCenterInLine: boolean;\n}\n\nexport interface SimplifyLayoutType {\n lines: LayoutItemType[];\n}\n\nexport interface LayoutType {\n bbox: TextLayoutBBox;\n lines: LayoutItemType[];\n fontFamily: string;\n fontSize: number;\n fontWeight?: string | number;\n lineHeight: number;\n textAlign: TextAlignType;\n textBaseline: TextBaselineType;\n}\n\nexport enum MeasureModeEnum {\n estimate = 0,\n actualBounding = 1,\n fontBounding = 2\n}\n\nexport type ITextAttribute = {\n /**\n * 文字内容\n */\n text: string | number | string[] | number[];\n /**\n * 单行的的最大长度,当超出这个长度,可以展示省略符或者换行、截断等\n * 后续可能去除\n */\n maxLineWidth: number;\n /**\n * 单行的的最大长度,当超出这个长度,可以展示省略符或者换行、截断等\n * 同 maxLineWidth\n */\n maxWidth: number;\n /**\n * 文字对齐方式\n */\n textAlign: TextAlignType;\n /**\n * 文字竖直方向的对齐方式\n */\n textBaseline: TextBaselineType;\n /**\n * 字号\n */\n fontSize: number;\n /**\n * 字体\n */\n fontFamily: string;\n /**\n * 字重\n */\n fontWeight: string | number;\n /**\n * 文字超出后的省略符\n */\n ellipsis: boolean | string;\n /**\n * 控制文本的小型大写字母(small-caps)显示\n */\n fontVariant: string;\n /**\n * 字体样式,是否为斜体等\n */\n fontStyle: string;\n /**\n * 行高(字符串类型表示比例值,如\"150%\")\n */\n lineHeight: number | string;\n /**\n * 是否显示下划线\n */\n underline: number;\n /**\n * 是否显示中划线\n */\n lineThrough: number;\n /**\n * 在3d场景下是否根据z坐标缩放\n */\n scaleIn3d: boolean;\n /**\n * 文本的排布方向,如果需要文本纵向排布,可以配置为 'vertical'\n */\n direction: 'horizontal' | 'vertical';\n /**\n * 垂直布局的模式,0代表默认(横向textAlign,纵向textBaseline),1代表特殊(横向textBaseline,纵向textAlign)\n */\n verticalMode: number;\n /*\n * 单词断行\n */\n wordBreak: 'break-word' | 'break-all' | 'keep-all';\n /**\n * 内部配置,是否忽略一些bounds的buffer\n */\n ignoreBuf: boolean;\n /**\n * 高度限制控制显示内容及省略号\n */\n heightLimit: number;\n /**\n * 按照行数限制显示内容及省略号\n */\n lineClamp: number;\n /**\n * 同 whiteSpace: 'normal'\n * 后续可能删除\n */\n wrap: boolean;\n /**\n * 设置如何处理空白字符\n */\n whiteSpace: 'normal' | 'no-wrap';\n /**\n * 省略号的位置,默认为'end'\n */\n suffixPosition: 'start' | 'end' | 'middle';\n /**\n * 下划线的虚线样式\n */\n underlineDash: number[];\n /**\n * 下划线的虚线偏移量\n */\n underlineOffset: number;\n /**\n * 关闭poptip\n */\n disableAutoClipedPoptip?: boolean;\n /**\n * @since 0.21.0\n * 测量模式,默认使用actualBounding\n */\n measureMode?: MeasureModeEnum;\n\n /**\n * @since 0.21.0\n * 保持在行中间的位置\n */\n keepCenterInLine?: boolean;\n};\nexport type ITextCache = {\n // 单行文本的时候缓存(多行文本没有)\n clipedText?: string;\n clipedWidth?: number;\n // 文本的布局缓存(单行文本也有)\n layoutData?: LayoutType;\n // 垂直布局的列表\n verticalList?: { text: string; width?: number; direction: number }[][];\n};\n\nexport type ITextGraphicAttribute = Partial<IGraphicAttribute> & Partial<ITextAttribute>;\n\nexport type IWrapTextGraphicAttribute = ITextGraphicAttribute & {\n heightLimit?: number;\n lineClamp?: number;\n};\n\nexport interface IText extends IGraphic<ITextGraphicAttribute> {\n // 判断是否被ellipisised\n clipedText?: string;\n clipedWidth?: number;\n cliped?: boolean;\n multilineLayout?: LayoutType;\n font?: string;\n isMultiLine: boolean;\n cache?: ITextCache;\n\n getBaselineMapAlign: () => Record<string, string>;\n getAlignMapBaseline: () => Record<string, string>;\n}\n\nexport type TextAlignType = 'left' | 'right' | 'center' | 'start' | 'end';\nexport type TextBaselineType = 'top' | 'middle' | 'bottom' | 'alphabetic';\n"]}
|
|
@@ -11,14 +11,15 @@ var __rest = this && this.__rest || function(s, e) {
|
|
|
11
11
|
import { application } from "../../application";
|
|
12
12
|
|
|
13
13
|
export function getDefaultCharacterConfig(attribute) {
|
|
14
|
-
const {fill: fill = "black", stroke: stroke = !1, fontWeight: fontWeight = "normal", fontFamily: fontFamily = "Arial"} = attribute;
|
|
14
|
+
const {fill: fill = "black", stroke: stroke = !1, fontWeight: fontWeight = "normal", lineHeight: lineHeight, fontFamily: fontFamily = "Arial"} = attribute;
|
|
15
15
|
let {fontSize: fontSize = 12} = attribute;
|
|
16
16
|
return isFinite(fontSize) || (fontSize = 12), {
|
|
17
17
|
fill: fill,
|
|
18
18
|
stroke: stroke,
|
|
19
19
|
fontSize: fontSize,
|
|
20
20
|
fontWeight: fontWeight,
|
|
21
|
-
fontFamily: fontFamily
|
|
21
|
+
fontFamily: fontFamily,
|
|
22
|
+
lineHeight: lineHeight
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
|
|
@@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C,mBAAmB,CAAC,kBAAkB,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtF,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAClF,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAClE,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QACnE,WAAW,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACxE,CAAC;CACF","file":"edit-module.js","sourcesContent":["import { application } from '../../application';\nimport type {\n IRichText,\n IRichTextCharacter,\n IRichTextGraphicAttribute,\n IRichTextParagraphCharacter\n} from '../../interface';\n\n// function getMaxConfigIndexIgnoreLinebreak(textConfig: IRichTextCharacter[]) {\n// let idx = 0;\n// for (let i = 0; i < textConfig.length; i++) {\n// const c = textConfig[i] as IRichTextParagraphCharacter;\n// if (c.text !== '\\n') {\n// idx++;\n// }\n// }\n// return Math.max(idx - 1, 0);\n// }\n\nexport function getDefaultCharacterConfig(attribute: IRichTextGraphicAttribute) {\n const { fill = 'black', stroke = false, fontWeight = 'normal', fontFamily = 'Arial' } = attribute;\n let { fontSize = 12 } = attribute;\n if (!isFinite(fontSize)) {\n fontSize = 12;\n }\n return {\n fill,\n stroke,\n fontSize,\n fontWeight,\n fontFamily\n } as any;\n}\n\n/**\n * 找到cursorIndex所在的textConfig的位置,给出的index就是要插入的准确位置\n * @param textConfig\n * @param cursorIndex\n * @returns\n */\nexport function findConfigIndexByCursorIdx(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n if (cursorIndex < 0) {\n return 0;\n }\n\n // 排序找到对应的元素\n const intCursorIndex = Math.round(cursorIndex);\n let tempCursorIndex = intCursorIndex;\n // 跳过连续换行符中的第一个换行符\n let lineBreak = false;\n let configIdx = 0;\n for (configIdx = 0; configIdx < textConfig.length && tempCursorIndex >= 0; configIdx++) {\n const c = textConfig[configIdx] as IRichTextParagraphCharacter;\n if (c.text === '\\n') {\n tempCursorIndex -= Number(lineBreak);\n lineBreak = true;\n } else {\n tempCursorIndex--;\n lineBreak = false;\n }\n }\n // 说明过限了\n if (tempCursorIndex >= 0) {\n return textConfig.length;\n }\n configIdx -= 1;\n\n // 如果有换行,一定在换行符左边写\n if (cursorIndex > intCursorIndex && !lineBreak) {\n configIdx += 1;\n }\n return configIdx;\n}\n\n/**\n * 根据configIndex找到cursorIndex的位置,忽略单个换行符,连续换行符的时候只忽略第一个\n * @param textConfig\n * @param configIndex\n * @returns\n */\nexport function findCursorIdxByConfigIndex(textConfig: IRichTextCharacter[], configIndex: number): number {\n let cursorIndex = 0;\n if (configIndex < 0) {\n return -0.1;\n }\n // 仅有一个\\n,那不算\n // 如果有连续的\\n,那就少算一个\n let lastLineBreak = false;\n\n for (let i = 0; i <= configIndex && i < textConfig.length; i++) {\n const c = textConfig[i] as IRichTextParagraphCharacter;\n if (c.text === '\\n') {\n cursorIndex += Number(lastLineBreak);\n lastLineBreak = true;\n } else {\n cursorIndex++;\n lastLineBreak = false;\n }\n }\n cursorIndex = Math.max(cursorIndex - 1, 0);\n\n // 超出区间了直接设置到尾部,configIndex超过区间,cursorIndex不会超过\n if (configIndex > textConfig.length - 1) {\n // 如果最后一行是一个换行符,那么就得是xx.9否则就是xx.1\n if ((textConfig[textConfig.length - 1] as any)?.text === '\\n') {\n return cursorIndex + 0.9;\n }\n return cursorIndex + 0.1;\n }\n\n // 如果是这个configIdx对应到的是单个换行的话,那么算到下一个字符上\n const lineBreak = (textConfig[configIndex] as any)?.text === '\\n';\n if (configIndex >= textConfig.length - 1 && lineBreak) {\n return cursorIndex + 1 - 0.1;\n }\n const singleLineBreak = lineBreak && (textConfig[configIndex - 1] as any)?.text !== '\\n';\n\n // 光标往左放\n cursorIndex -= 0.1;\n\n // 如果是单行,那么这一个换行符没有算字符,光标要往右放\n if (singleLineBreak) {\n cursorIndex += 0.2;\n }\n return cursorIndex;\n}\n\nexport class EditModule {\n container: HTMLElement;\n textAreaDom: HTMLTextAreaElement;\n currRt: IRichText;\n isComposing: boolean;\n composingConfigIdx: number;\n cursorIndex: number;\n selectionStartCursorIdx: number;\n // 输入的回调(composing的时候每次也会触发)\n onInputCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n // change的回调(composing确认才会触发)\n onChangeCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n onFocusInList: Array<() => void>;\n onFocusOutList: Array<() => void>;\n focusOutTimer: number;\n\n constructor(container?: HTMLElement) {\n this.container = container ?? document.body;\n\n const textAreaDom = document.createElement('textarea');\n textAreaDom.autocomplete = 'off';\n textAreaDom.innerText = '';\n this.applyStyle(textAreaDom);\n this.container.append(textAreaDom);\n this.textAreaDom = textAreaDom;\n this.isComposing = false;\n this.composingConfigIdx = -1;\n this.onInputCbList = [];\n this.onChangeCbList = [];\n this.onFocusInList = [];\n this.onFocusOutList = [];\n }\n\n onInput(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onInputCbList.push(cb);\n }\n\n onChange(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onChangeCbList.push(cb);\n }\n\n onFocusIn(cb: () => void) {\n this.onFocusInList.push(cb);\n }\n\n onFocusOut(cb: () => void) {\n this.onFocusOutList.push(cb);\n }\n\n applyStyle(textAreaDom: HTMLTextAreaElement) {\n textAreaDom.setAttribute(\n 'style',\n `width: 100px; height: 30px; left: 0; top: 0; position: absolute; z-index: -1; outline: none; resize: none; border: none; overflow: hidden; color: transparent; user-select: none; caret-color: transparent;background-color: transparent;`\n );\n\n textAreaDom.addEventListener('input', this.handleInput);\n textAreaDom.addEventListener('compositionstart', this.handleCompositionStart);\n textAreaDom.addEventListener('compositionend', this.handleCompositionEnd);\n // 监听焦点\n textAreaDom.addEventListener('focusin', this.handleFocusIn);\n textAreaDom.addEventListener('focusout', this.handleFocusOut);\n application.global.addEventListener('keydown', this.handleKeyDown);\n }\n\n handleFocusIn = () => {\n // this.focusOutTimer && clearTimeout(this.focusOutTimer);\n // this.focusOutTimer = 0;\n // this.onFocusInList && this.onFocusInList.forEach(cb => cb());\n };\n handleFocusOut = () => {\n // 暂时注释,会导致非期待情况下的误关闭\n // // 延时触发,避免误关闭\n // this.focusOutTimer = setTimeout(() => {\n // this.onFocusOutList && this.onFocusOutList.forEach(cb => cb());\n // }, 100);\n };\n\n handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Delete' || e.key === 'Backspace') {\n this.handleInput({ data: null, type: 'Backspace' });\n }\n };\n\n handleCompositionStart = () => {\n this.isComposing = true;\n const { textConfig = [] } = this.currRt.attribute;\n this.composingConfigIdx = this.cursorIndex < 0 ? 0 : findConfigIndexByCursorIdx(textConfig, this.cursorIndex);\n if (this.cursorIndex < 0) {\n const config = textConfig[0];\n textConfig.unshift({ fill: 'black', ...getDefaultCharacterConfig(this.currRt.attribute), ...config, text: '' });\n } else {\n const configIdx = this.composingConfigIdx;\n const lastConfig = textConfig[configIdx] || textConfig[configIdx - 1];\n textConfig.splice(configIdx, 0, { fill: 'black', ...lastConfig, text: '' });\n }\n };\n handleCompositionEnd = () => {\n this.isComposing = false;\n\n const text = this.parseCompositionStr(this.composingConfigIdx);\n // 拆分上一次的内容\n // const { textConfig = [] } = this.currRt.attribute;\n // const configIdx = this.composingConfigIdx;\n\n // const lastConfig = textConfig[configIdx];\n // textConfig.splice(configIdx, 1);\n // const text = (lastConfig as any).text;\n // const textList: string[] = text ? Array.from(text.toString()) : [];\n // for (let i = 0; i < textList.length; i++) {\n // textConfig.splice(i + configIdx, 0, { ...lastConfig, isComposing: false, text: textList[i] } as any);\n // }\n // this.currRt.setAttributes({ textConfig });\n // const nextConfigIdx = configIdx + textList.length;\n // this.cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n this.composingConfigIdx = -1;\n\n this.onChangeCbList.forEach(cb => {\n cb(\n text,\n this.isComposing,\n // TODO 当换行后刚开始输入会有问题,后续看这里具体Cursor变换逻辑\n this.cursorIndex,\n this.currRt\n );\n });\n };\n\n /**\n * 复合输入以及粘贴,都会复制出一大段内容,这时候需要重新处理textConfig和cursorIndex\n * 1. 拆分text到textConfig\n * 2. 计算新的cursorIndex\n * @param configIdx\n */\n parseCompositionStr(configIdx: number) {\n const { textConfig = [] } = this.currRt.attribute;\n\n const lastConfig = textConfig[configIdx] ?? {};\n textConfig.splice(configIdx, 1);\n const text = (lastConfig as any).text;\n const textList: string[] = text ? Array.from(text.toString()) : [];\n for (let i = 0; i < textList.length; i++) {\n textConfig.splice(i + configIdx, 0, {\n fill: 'black',\n ...lastConfig,\n isComposing: false,\n text: textList[i]\n } as any);\n }\n this.currRt.setAttributes({ textConfig });\n const nextConfigIdx = configIdx + textList.length;\n this.cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n return text;\n }\n\n handleInput = (ev: any) => {\n if (!this.currRt) {\n return;\n }\n if (ev.inputType === 'historyUndo') {\n return;\n }\n const { textConfig = [], ...rest } = this.currRt.attribute;\n // 删完了,直接返回\n if (ev.type === 'Backspace' && !textConfig.length) {\n return;\n }\n\n let str = (ev as any).data;\n if (!this.isComposing && ev.type !== 'Backspace' && !str) {\n str = '\\n';\n }\n\n // 处理正反选\n if (this.selectionStartCursorIdx > this.cursorIndex) {\n [this.cursorIndex, this.selectionStartCursorIdx] = [this.selectionStartCursorIdx, this.cursorIndex];\n }\n\n const startIdx = findConfigIndexByCursorIdx(textConfig, this.selectionStartCursorIdx);\n const endIdx = findConfigIndexByCursorIdx(textConfig, this.cursorIndex);\n\n // composing的话会插入一个字符,所以往右加一个\n const lastConfigIdx = this.isComposing ? this.composingConfigIdx : Math.max(startIdx - 1, 0);\n // 算一个默认属性\n let lastConfig: any = textConfig[lastConfigIdx];\n if (!lastConfig) {\n lastConfig = getDefaultCharacterConfig(rest);\n }\n let nextConfig = lastConfig;\n\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx, endIdx - startIdx);\n if (this.isComposing) {\n this.composingConfigIdx = startIdx;\n }\n }\n\n let nextConfigIdx = startIdx;\n\n // 删除键\n if (ev.type === 'Backspace' && !this.isComposing) {\n if (startIdx === endIdx) {\n if (startIdx <= 0) {\n return;\n }\n // 删除\n textConfig.splice(startIdx - 1, 1);\n nextConfigIdx = Math.max(startIdx - 1, 0);\n } else {\n // 不插入内容\n }\n } else {\n // 插入\n if (!this.isComposing) {\n nextConfig = { fill: 'black', ...lastConfig, text: '' };\n textConfig.splice(startIdx, 0, nextConfig);\n nextConfigIdx++;\n }\n // 插入\n nextConfig.text = str;\n // 标记isComposing,用来判定是否应该拆分成单个字符\n nextConfig.isComposing = this.isComposing;\n }\n\n this.currRt.setAttributes({ textConfig });\n // 重新计算cursorIdx\n // nextConfigIdx = Math.min(nextConfigIdx, textConfig.length - 1);\n\n let cursorIndex = this.cursorIndex;\n if (str && str.length > 1 && !this.isComposing) {\n // 如果字符长度大于1且不是composing,那说明是粘贴\n // 拆分\n this.parseCompositionStr(nextConfigIdx - 1);\n cursorIndex = this.cursorIndex;\n } else {\n // composing的时候不偏移,只有完整输入后才偏移\n cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n if (!this.isComposing) {\n this.cursorIndex = cursorIndex;\n } else {\n this.cursorIndex = this.selectionStartCursorIdx;\n }\n }\n\n if (!this.isComposing) {\n this.onChangeCbList.forEach(cb => {\n cb(str, this.isComposing, cursorIndex, this.currRt);\n });\n } else {\n this.onInputCbList.forEach(cb => {\n cb(str, this.isComposing, cursorIndex, this.currRt);\n });\n }\n };\n\n moveTo(x: number, y: number, rt: IRichText, cursorIndex: number, selectionStartCursorIdx: number) {\n this.textAreaDom.style.left = `${x}px`;\n this.textAreaDom.style.top = `${y}px`;\n setTimeout(() => {\n this.textAreaDom.focus();\n this.textAreaDom.setSelectionRange(0, 0);\n });\n this.currRt = rt;\n\n this.cursorIndex = cursorIndex;\n this.selectionStartCursorIdx = selectionStartCursorIdx;\n }\n\n release() {\n this.textAreaDom.removeEventListener('input', this.handleInput);\n this.textAreaDom.removeEventListener('compositionstart', this.handleCompositionStart);\n this.textAreaDom.removeEventListener('compositionend', this.handleCompositionEnd);\n this.textAreaDom.addEventListener('focusin', this.handleFocusOut);\n this.textAreaDom.addEventListener('focusout', this.handleFocusOut);\n application.global.removeEventListener('keydown', this.handleKeyDown);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/plugins/builtin-plugin/edit-module.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAmBhD,MAAM,UAAU,yBAAyB,CAAC,SAAoC;IAC5E,MAAM,EAAE,IAAI,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,UAAU,GAAG,QAAQ,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,EAAE,GAAG,SAAS,CAAC;IAC9G,IAAI,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,SAAS,CAAC;IAClC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACvB,QAAQ,GAAG,EAAE,CAAC;KACf;IACD,OAAO;QACL,IAAI;QACJ,MAAM;QACN,QAAQ;QACR,UAAU;QACV,UAAU;QACV,UAAU;KACJ,CAAC;AACX,CAAC;AAQD,MAAM,UAAU,0BAA0B,CAAC,UAAgC,EAAE,WAAmB;IAC9F,IAAI,WAAW,GAAG,CAAC,EAAE;QACnB,OAAO,CAAC,CAAC;KACV;IAGD,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/C,IAAI,eAAe,GAAG,cAAc,CAAC;IAErC,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,KAAK,SAAS,GAAG,CAAC,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AW,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QAEjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;IACzD,CAAC;IAED,OAAO;QACL,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAChE,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtF,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAClF,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAClE,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QACnE,WAAW,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACxE,CAAC;CACF","file":"edit-module.js","sourcesContent":["import { application } from '../../application';\nimport type {\n IRichText,\n IRichTextCharacter,\n IRichTextGraphicAttribute,\n IRichTextParagraphCharacter\n} from '../../interface';\n\n// function getMaxConfigIndexIgnoreLinebreak(textConfig: IRichTextCharacter[]) {\n// let idx = 0;\n// for (let i = 0; i < textConfig.length; i++) {\n// const c = textConfig[i] as IRichTextParagraphCharacter;\n// if (c.text !== '\\n') {\n// idx++;\n// }\n// }\n// return Math.max(idx - 1, 0);\n// }\n\nexport function getDefaultCharacterConfig(attribute: IRichTextGraphicAttribute) {\n const { fill = 'black', stroke = false, fontWeight = 'normal', lineHeight, fontFamily = 'Arial' } = attribute;\n let { fontSize = 12 } = attribute;\n if (!isFinite(fontSize)) {\n fontSize = 12;\n }\n return {\n fill,\n stroke,\n fontSize,\n fontWeight,\n fontFamily,\n lineHeight\n } as any;\n}\n\n/**\n * 找到cursorIndex所在的textConfig的位置,给出的index就是要插入的准确位置\n * @param textConfig\n * @param cursorIndex\n * @returns\n */\nexport function findConfigIndexByCursorIdx(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n if (cursorIndex < 0) {\n return 0;\n }\n\n // 排序找到对应的元素\n const intCursorIndex = Math.round(cursorIndex);\n let tempCursorIndex = intCursorIndex;\n // 跳过连续换行符中的第一个换行符\n let lineBreak = false;\n let configIdx = 0;\n for (configIdx = 0; configIdx < textConfig.length && tempCursorIndex >= 0; configIdx++) {\n const c = textConfig[configIdx] as IRichTextParagraphCharacter;\n if (c.text === '\\n') {\n tempCursorIndex -= Number(lineBreak);\n lineBreak = true;\n } else {\n tempCursorIndex--;\n lineBreak = false;\n }\n }\n // 说明过限了\n if (tempCursorIndex >= 0) {\n return textConfig.length;\n }\n configIdx -= 1;\n\n // 如果有换行,一定在换行符左边写\n if (cursorIndex > intCursorIndex && !lineBreak) {\n configIdx += 1;\n }\n return configIdx;\n}\n\n/**\n * 根据configIndex找到cursorIndex的位置,忽略单个换行符,连续换行符的时候只忽略第一个\n * @param textConfig\n * @param configIndex\n * @returns\n */\nexport function findCursorIdxByConfigIndex(textConfig: IRichTextCharacter[], configIndex: number): number {\n let cursorIndex = 0;\n if (configIndex < 0) {\n return -0.1;\n }\n // 仅有一个\\n,那不算\n // 如果有连续的\\n,那就少算一个\n let lastLineBreak = false;\n\n for (let i = 0; i <= configIndex && i < textConfig.length; i++) {\n const c = textConfig[i] as IRichTextParagraphCharacter;\n if (c.text === '\\n') {\n cursorIndex += Number(lastLineBreak);\n lastLineBreak = true;\n } else {\n cursorIndex++;\n lastLineBreak = false;\n }\n }\n cursorIndex = Math.max(cursorIndex - 1, 0);\n\n // 超出区间了直接设置到尾部,configIndex超过区间,cursorIndex不会超过\n if (configIndex > textConfig.length - 1) {\n // 如果最后一行是一个换行符,那么就得是xx.9否则就是xx.1\n if ((textConfig[textConfig.length - 1] as any)?.text === '\\n') {\n return cursorIndex + 0.9;\n }\n return cursorIndex + 0.1;\n }\n\n // 如果是这个configIdx对应到的是单个换行的话,那么算到下一个字符上\n const lineBreak = (textConfig[configIndex] as any)?.text === '\\n';\n if (configIndex >= textConfig.length - 1 && lineBreak) {\n return cursorIndex + 1 - 0.1;\n }\n const singleLineBreak = lineBreak && (textConfig[configIndex - 1] as any)?.text !== '\\n';\n\n // 光标往左放\n cursorIndex -= 0.1;\n\n // 如果是单行,那么这一个换行符没有算字符,光标要往右放\n if (singleLineBreak) {\n cursorIndex += 0.2;\n }\n return cursorIndex;\n}\n\nexport class EditModule {\n container: HTMLElement;\n textAreaDom: HTMLTextAreaElement;\n currRt: IRichText;\n isComposing: boolean;\n composingConfigIdx: number;\n cursorIndex: number;\n selectionStartCursorIdx: number;\n // 输入的回调(composing的时候每次也会触发)\n onInputCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n // change的回调(composing确认才会触发)\n onChangeCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n onFocusInList: Array<() => void>;\n onFocusOutList: Array<() => void>;\n focusOutTimer: number;\n\n constructor(container?: HTMLElement) {\n this.container = container ?? document.body;\n\n const textAreaDom = document.createElement('textarea');\n textAreaDom.autocomplete = 'off';\n textAreaDom.innerText = '';\n this.applyStyle(textAreaDom);\n this.container.append(textAreaDom);\n this.textAreaDom = textAreaDom;\n this.isComposing = false;\n this.composingConfigIdx = -1;\n this.onInputCbList = [];\n this.onChangeCbList = [];\n this.onFocusInList = [];\n this.onFocusOutList = [];\n }\n\n onInput(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onInputCbList.push(cb);\n }\n\n onChange(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onChangeCbList.push(cb);\n }\n\n onFocusIn(cb: () => void) {\n this.onFocusInList.push(cb);\n }\n\n onFocusOut(cb: () => void) {\n this.onFocusOutList.push(cb);\n }\n\n applyStyle(textAreaDom: HTMLTextAreaElement) {\n textAreaDom.setAttribute(\n 'style',\n `width: 100px; height: 30px; left: 0; top: 0; position: absolute; z-index: -1; outline: none; resize: none; border: none; overflow: hidden; color: transparent; user-select: none; caret-color: transparent;background-color: transparent;`\n );\n\n textAreaDom.addEventListener('input', this.handleInput);\n textAreaDom.addEventListener('compositionstart', this.handleCompositionStart);\n textAreaDom.addEventListener('compositionend', this.handleCompositionEnd);\n // 监听焦点\n textAreaDom.addEventListener('focusin', this.handleFocusIn);\n textAreaDom.addEventListener('focusout', this.handleFocusOut);\n application.global.addEventListener('keydown', this.handleKeyDown);\n }\n\n handleFocusIn = () => {\n // this.focusOutTimer && clearTimeout(this.focusOutTimer);\n // this.focusOutTimer = 0;\n // this.onFocusInList && this.onFocusInList.forEach(cb => cb());\n };\n handleFocusOut = () => {\n // 暂时注释,会导致非期待情况下的误关闭\n // // 延时触发,避免误关闭\n // this.focusOutTimer = setTimeout(() => {\n // this.onFocusOutList && this.onFocusOutList.forEach(cb => cb());\n // }, 100);\n };\n\n handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Delete' || e.key === 'Backspace') {\n this.handleInput({ data: null, type: 'Backspace' });\n }\n };\n\n handleCompositionStart = () => {\n this.isComposing = true;\n const { textConfig = [] } = this.currRt.attribute;\n this.composingConfigIdx = this.cursorIndex < 0 ? 0 : findConfigIndexByCursorIdx(textConfig, this.cursorIndex);\n if (this.cursorIndex < 0) {\n const config = textConfig[0];\n textConfig.unshift({ fill: 'black', ...getDefaultCharacterConfig(this.currRt.attribute), ...config, text: '' });\n } else {\n const configIdx = this.composingConfigIdx;\n const lastConfig = textConfig[configIdx] || textConfig[configIdx - 1];\n textConfig.splice(configIdx, 0, { fill: 'black', ...lastConfig, text: '' });\n }\n };\n handleCompositionEnd = () => {\n this.isComposing = false;\n\n const text = this.parseCompositionStr(this.composingConfigIdx);\n // 拆分上一次的内容\n // const { textConfig = [] } = this.currRt.attribute;\n // const configIdx = this.composingConfigIdx;\n\n // const lastConfig = textConfig[configIdx];\n // textConfig.splice(configIdx, 1);\n // const text = (lastConfig as any).text;\n // const textList: string[] = text ? Array.from(text.toString()) : [];\n // for (let i = 0; i < textList.length; i++) {\n // textConfig.splice(i + configIdx, 0, { ...lastConfig, isComposing: false, text: textList[i] } as any);\n // }\n // this.currRt.setAttributes({ textConfig });\n // const nextConfigIdx = configIdx + textList.length;\n // this.cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n this.composingConfigIdx = -1;\n\n this.onChangeCbList.forEach(cb => {\n cb(\n text,\n this.isComposing,\n // TODO 当换行后刚开始输入会有问题,后续看这里具体Cursor变换逻辑\n this.cursorIndex,\n this.currRt\n );\n });\n };\n\n /**\n * 复合输入以及粘贴,都会复制出一大段内容,这时候需要重新处理textConfig和cursorIndex\n * 1. 拆分text到textConfig\n * 2. 计算新的cursorIndex\n * @param configIdx\n */\n parseCompositionStr(configIdx: number) {\n const { textConfig = [] } = this.currRt.attribute;\n\n const lastConfig = textConfig[configIdx] ?? {};\n textConfig.splice(configIdx, 1);\n const text = (lastConfig as any).text;\n const textList: string[] = text ? Array.from(text.toString()) : [];\n for (let i = 0; i < textList.length; i++) {\n textConfig.splice(i + configIdx, 0, {\n fill: 'black',\n ...lastConfig,\n isComposing: false,\n text: textList[i]\n } as any);\n }\n this.currRt.setAttributes({ textConfig });\n const nextConfigIdx = configIdx + textList.length;\n this.cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n return text;\n }\n\n handleInput = (ev: any) => {\n if (!this.currRt) {\n return;\n }\n if (ev.inputType === 'historyUndo') {\n return;\n }\n const { textConfig = [], ...rest } = this.currRt.attribute;\n // 删完了,直接返回\n if (ev.type === 'Backspace' && !textConfig.length) {\n return;\n }\n\n let str = (ev as any).data;\n if (!this.isComposing && ev.type !== 'Backspace' && !str) {\n str = '\\n';\n }\n\n // 处理正反选\n if (this.selectionStartCursorIdx > this.cursorIndex) {\n [this.cursorIndex, this.selectionStartCursorIdx] = [this.selectionStartCursorIdx, this.cursorIndex];\n }\n\n const startIdx = findConfigIndexByCursorIdx(textConfig, this.selectionStartCursorIdx);\n const endIdx = findConfigIndexByCursorIdx(textConfig, this.cursorIndex);\n\n // composing的话会插入一个字符,所以往右加一个\n const lastConfigIdx = this.isComposing ? this.composingConfigIdx : Math.max(startIdx - 1, 0);\n // 算一个默认属性\n let lastConfig: any = textConfig[lastConfigIdx];\n if (!lastConfig) {\n lastConfig = getDefaultCharacterConfig(rest);\n }\n let nextConfig = lastConfig;\n\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx, endIdx - startIdx);\n if (this.isComposing) {\n this.composingConfigIdx = startIdx;\n }\n }\n\n let nextConfigIdx = startIdx;\n\n // 删除键\n if (ev.type === 'Backspace' && !this.isComposing) {\n if (startIdx === endIdx) {\n if (startIdx <= 0) {\n return;\n }\n // 删除\n textConfig.splice(startIdx - 1, 1);\n nextConfigIdx = Math.max(startIdx - 1, 0);\n } else {\n // 不插入内容\n }\n } else {\n // 插入\n if (!this.isComposing) {\n nextConfig = { fill: 'black', ...lastConfig, text: '' };\n textConfig.splice(startIdx, 0, nextConfig);\n nextConfigIdx++;\n }\n // 插入\n nextConfig.text = str;\n // 标记isComposing,用来判定是否应该拆分成单个字符\n nextConfig.isComposing = this.isComposing;\n }\n\n this.currRt.setAttributes({ textConfig });\n // 重新计算cursorIdx\n // nextConfigIdx = Math.min(nextConfigIdx, textConfig.length - 1);\n\n let cursorIndex = this.cursorIndex;\n if (str && str.length > 1 && !this.isComposing) {\n // 如果字符长度大于1且不是composing,那说明是粘贴\n // 拆分\n this.parseCompositionStr(nextConfigIdx - 1);\n cursorIndex = this.cursorIndex;\n } else {\n // composing的时候不偏移,只有完整输入后才偏移\n cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n if (!this.isComposing) {\n this.cursorIndex = cursorIndex;\n } else {\n this.cursorIndex = this.selectionStartCursorIdx;\n }\n }\n\n if (!this.isComposing) {\n this.onChangeCbList.forEach(cb => {\n cb(str, this.isComposing, cursorIndex, this.currRt);\n });\n } else {\n this.onInputCbList.forEach(cb => {\n cb(str, this.isComposing, cursorIndex, this.currRt);\n });\n }\n };\n\n moveTo(x: number, y: number, rt: IRichText, cursorIndex: number, selectionStartCursorIdx: number) {\n this.textAreaDom.style.left = `${x}px`;\n this.textAreaDom.style.top = `${y}px`;\n setTimeout(() => {\n this.textAreaDom.focus();\n this.textAreaDom.setSelectionRange(0, 0);\n });\n this.currRt = rt;\n\n this.cursorIndex = cursorIndex;\n this.selectionStartCursorIdx = selectionStartCursorIdx;\n }\n\n release() {\n this.textAreaDom.removeEventListener('input', this.handleInput);\n this.textAreaDom.removeEventListener('compositionstart', this.handleCompositionStart);\n this.textAreaDom.removeEventListener('compositionend', this.handleCompositionEnd);\n this.textAreaDom.addEventListener('focusin', this.handleFocusOut);\n this.textAreaDom.addEventListener('focusout', this.handleFocusOut);\n application.global.removeEventListener('keydown', this.handleKeyDown);\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IPointLike } from '@visactor/vutils';
|
|
2
|
-
import type { IGroup, ILine, IPlugin, IPluginService, IRect, IRichText, IRichTextCharacter, IRichTextFrame, IRichTextIcon, IRichTextLine, IRichTextParagraph, ITicker, ITimeline } from '../../interface';
|
|
2
|
+
import type { IGraphic, IGroup, ILine, IPlugin, IPluginService, IRect, IRichText, IRichTextCharacter, IRichTextFrame, IRichTextIcon, IRichTextLine, IRichTextParagraph, ITicker, ITimeline } from '../../interface';
|
|
3
3
|
import { EditModule } from './edit-module';
|
|
4
4
|
type UpdateType = 'input' | 'change' | 'onfocus' | 'beforeOnfocus' | 'defocus' | 'beforeDefocus' | 'selection' | 'dispatch';
|
|
5
5
|
declare class Selection {
|
|
@@ -70,12 +70,14 @@ export declare class RichTextEditPlugin implements IPlugin {
|
|
|
70
70
|
handleFocusOut: () => never;
|
|
71
71
|
deactivate(context: IPluginService): void;
|
|
72
72
|
handleMove: (e: PointerEvent) => void;
|
|
73
|
-
handleEnter: (
|
|
74
|
-
handleLeave: (
|
|
73
|
+
handleEnter: () => void;
|
|
74
|
+
handleLeave: () => void;
|
|
75
75
|
handlePointerDown: (e: PointerEvent) => void;
|
|
76
76
|
handlePointerUp: (e: PointerEvent) => void;
|
|
77
77
|
handleDBLClick: (e: PointerEvent) => void;
|
|
78
78
|
protected stopPropagation(e: Event): void;
|
|
79
|
+
addEditLineOrBgOrBounds(graphic: IGraphic, shadowRoot: IGroup): void;
|
|
80
|
+
removeEditLineOrBgOrBounds(graphic: IGraphic, shadowRoot: IGroup): void;
|
|
79
81
|
onFocus(e: PointerEvent, data?: any): void;
|
|
80
82
|
offsetShadowRoot(rt?: IRichText): void;
|
|
81
83
|
protected offsetLineBgAndShadowBounds(): void;
|
|
@@ -96,6 +98,7 @@ export declare class RichTextEditPlugin implements IPlugin {
|
|
|
96
98
|
};
|
|
97
99
|
protected getColumnIndex(cache: IRichTextFrame, cInfo: IRichTextParagraph | IRichTextIcon): number;
|
|
98
100
|
protected isRichtext(e: PointerEvent): boolean;
|
|
101
|
+
protected isEditableRichtext(e: PointerEvent): boolean;
|
|
99
102
|
protected triggerRender(): void;
|
|
100
103
|
protected computeGlobalDelta(cache: IRichTextFrame): void;
|
|
101
104
|
protected getEventPosition(e: PointerEvent): IPointLike;
|