From 45501bf74257232a06c94b69396672b1d1529548 Mon Sep 17 00:00:00 2001 From: leaferjs Date: Sun, 20 Oct 2024 20:26:07 +0800 Subject: [PATCH] path support command object --- packages/display-module/data/src/BoxData.ts | 2 +- packages/display-module/data/src/EllipseData.ts | 2 +- packages/display-module/data/src/RectData.ts | 2 +- packages/display-module/data/src/UIData.ts | 13 +++++++------ packages/display/src/UI.ts | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/display-module/data/src/BoxData.ts b/packages/display-module/data/src/BoxData.ts index 981662c0..c75d6645 100644 --- a/packages/display-module/data/src/BoxData.ts +++ b/packages/display-module/data/src/BoxData.ts @@ -5,7 +5,7 @@ import { GroupData } from "./GroupData" export class BoxData extends GroupData implements IBoxData { - public get __boxStroke(): boolean { return !this.__pathInputed } + public get __boxStroke(): boolean { return !(this as IBoxData).__pathInputed } // 路径与圆角直接当溢出处理 public get __drawAfterFill(): boolean { return (this as IBoxData).overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length as unknown as boolean } diff --git a/packages/display-module/data/src/EllipseData.ts b/packages/display-module/data/src/EllipseData.ts index 591189b8..a0a944e3 100644 --- a/packages/display-module/data/src/EllipseData.ts +++ b/packages/display-module/data/src/EllipseData.ts @@ -4,5 +4,5 @@ import { UIData } from "./UIData" export class EllipseData extends UIData implements IEllipseData { - get __boxStroke(): boolean { return !this.__pathInputed } + get __boxStroke(): boolean { return !(this as IEllipseData).__pathInputed } } \ No newline at end of file diff --git a/packages/display-module/data/src/RectData.ts b/packages/display-module/data/src/RectData.ts index 114cae0f..43596388 100644 --- a/packages/display-module/data/src/RectData.ts +++ b/packages/display-module/data/src/RectData.ts @@ -4,5 +4,5 @@ import { UIData } from "./UIData" export class RectData extends UIData implements IRectData { - get __boxStroke(): boolean { return !this.__pathInputed } + get __boxStroke(): boolean { return !(this as IRectData).__pathInputed } } \ No newline at end of file diff --git a/packages/display-module/data/src/UIData.ts b/packages/display-module/data/src/UIData.ts index 5560e352..f997fd0b 100644 --- a/packages/display-module/data/src/UIData.ts +++ b/packages/display-module/data/src/UIData.ts @@ -1,11 +1,11 @@ -import { INumber, IValue, IBoolean, IPathCommandData, IPathString, IPointData } from '@leafer/interface' +import { INumber, IValue, IBoolean, IPathCommandData, IPathString, IPointData, IPathCommandObject } from '@leafer/interface' import { PathConvert, LeafData, Debug } from '@leafer/core' import { IShadowEffect, IUI, IUIData, ILeafPaint } from '@leafer-ui/interface' import { Paint, PaintImage } from '@leafer-ui/external' -const { parse } = PathConvert +const { parse, objectToCanvasData } = PathConvert const emptyPaint: ILeafPaint = {} const debug = Debug.get('UIData') export class UIData extends LeafData implements IUIData { @@ -117,13 +117,14 @@ export class UIData extends LeafData implements IUIData { } - protected setPath(value: IPathCommandData | IPathString) { - if (typeof value === 'string') { + protected setPath(value: IPathCommandData | IPathCommandObject[] | IPathString) { + const isString = typeof value === 'string' + if (isString || (value && typeof value[0] === 'object')) { this.__setInput('path', value) - this._path = parse(value) + this._path = isString ? parse(value) : objectToCanvasData(value as IPathCommandObject[]) } else { if (this.__input) this.__removeInput('path') - this._path = value + this._path = value as IPathCommandData } } diff --git a/packages/display/src/UI.ts b/packages/display/src/UI.ts index 82c5e43e..a4554e2e 100644 --- a/packages/display/src/UI.ts +++ b/packages/display/src/UI.ts @@ -1,4 +1,4 @@ -import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType, INumber, IBoolean, IString, IPathString, IExportFileType, IPointData, ICursorType, IMaskType, IEraserType, IValue, IWindingRule, IPathCreator, IFourNumber, IBoundsData, IFlowType, IGap, IFlowWrap, IAxis, IConstraint, IAutoBoxData, IFlowBoxType, IPointGap, IFlowAlign, IFlowAxisAlign, IFindCondition, IAutoSize, IRangeSize, IAlign, IUnitPointData, IObject, IScaleData, IUnitData } from '@leafer/interface' +import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType, INumber, IBoolean, IString, IPathString, IExportFileType, IPointData, ICursorType, IMaskType, IEraserType, IValue, IWindingRule, IPathCreator, IFourNumber, IBoundsData, IFlowType, IGap, IFlowWrap, IAxis, IConstraint, IAutoBoxData, IFlowBoxType, IPointGap, IFlowAlign, IFlowAxisAlign, IFindCondition, IAutoSize, IRangeSize, IAlign, IUnitPointData, IObject, IScaleData, IUnitData, IPathCommandObject } from '@leafer/interface' import { Leaf, PathDrawer, surfaceType, dataType, positionType, boundsType, pathType, scaleType, rotationType, opacityType, visibleType, sortType, maskType, dataProcessor, registerUI, useModule, rewrite, rewriteAble, UICreator, PathCorner, hitType, strokeType, PathConvert, eraserType, cursorType, autoLayoutType, pen, naturalBoundsType, pathInputType, MathHelper, needPlugin } from '@leafer/core' import { IUI, IShadowEffect, IBlurEffect, IStrokeAlign, IStrokeJoin, IStrokeCap, IBlendMode, IDashPatternString, IShadowString, IGrayscaleEffect, IUIData, IGroup, IStrokeWidthString, ICornerRadiusString, IUIInputData, IExportOptions, IExportResult, IFill, IStroke, IArrowType, IFindUIMethod, ILeafer, IEditorConfig, IEditorConfigFunction, IEditToolFunction, IKeyframe, IAnimation, IAnimate, IStates, IStateName, ITransition, IAnimateType } from '@leafer-ui/interface' @@ -138,7 +138,7 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box // path @pathInputType() - public path?: IPathCommandData | IPathString + public path?: IPathCommandData | IPathCommandObject[] | IPathString @pathType() public windingRule?: IWindingRule