@leafer-ui/display 1.7.0 → 1.9.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/display",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "@leafer-ui/display",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,14 +22,14 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.7.0",
26
- "@leafer-ui/data": "1.7.0",
27
- "@leafer-ui/display-module": "1.7.0",
28
- "@leafer-ui/decorator": "1.7.0",
29
- "@leafer-ui/external": "1.7.0"
25
+ "@leafer/core": "1.9.0",
26
+ "@leafer-ui/data": "1.9.0",
27
+ "@leafer-ui/display-module": "1.9.0",
28
+ "@leafer-ui/decorator": "1.9.0",
29
+ "@leafer-ui/external": "1.9.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@leafer/interface": "1.7.0",
33
- "@leafer-ui/interface": "1.7.0"
32
+ "@leafer/interface": "1.9.0",
33
+ "@leafer-ui/interface": "1.9.0"
34
34
  }
35
35
  }
package/src/Box.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ILeaferCanvas, IRenderOptions, IBoundsData, IBoolean, INumber } from '@leafer/interface'
2
2
  import { rewrite, rewriteAble, registerUI, BoundsHelper, dataProcessor, affectRenderBoundsType, dataType, boundsType, DataHelper } from '@leafer/core'
3
3
 
4
- import { IBox, IBoxData, IBoxInputData, IOverflow } from '@leafer-ui/interface'
4
+ import { IBox, IBoxData, IBoxInputData, IGroup, IOverflow } from '@leafer-ui/interface'
5
5
  import { BoxData } from '@leafer-ui/data'
6
6
 
7
7
  import { Group } from './Group'
@@ -41,6 +41,8 @@ export class Box extends Group implements IBox {
41
41
 
42
42
  public isOverflow: boolean
43
43
 
44
+ public scrollBar?: IGroup
45
+
44
46
  constructor(data?: IBoxInputData) {
45
47
  super(data)
46
48
  this.__layout.renderChanged || this.__layout.renderChange()
@@ -61,10 +63,10 @@ export class Box extends Group implements IBox {
61
63
 
62
64
  // @leafer-in/flow will rewrite
63
65
  public __updateBoxBounds(_secondLayout?: boolean): void {
64
- const data = this.__
65
-
66
66
  if (this.children.length && !this.pathInputed) {
67
67
 
68
+ const data = this.__
69
+
68
70
  if (data.__autoSide) {
69
71
 
70
72
  if (data.__hasSurface) this.__extraUpdate() // Box自身存在样式,需要额外更新
@@ -95,23 +97,36 @@ export class Box extends Group implements IBox {
95
97
 
96
98
  public __updateRenderBounds(): void {
97
99
  let isOverflow: boolean
98
- const { renderBounds } = this.__layout
99
100
 
100
101
  if (this.children.length) {
102
+ const data = this.__, { renderBounds, boxBounds } = this.__layout
103
+
101
104
  super.__updateRenderBounds()
102
105
  copy(childrenRenderBounds, renderBounds)
103
106
  this.__updateRectRenderBounds()
104
107
 
105
- isOverflow = !includes(renderBounds, childrenRenderBounds)
106
- if (isOverflow && this.__.overflow !== 'hide') add(renderBounds, childrenRenderBounds)
108
+ // 增加滚动逻辑
109
+ if (data.scrollY || data.scrollX) {
110
+ childrenRenderBounds.x += data.scrollX
111
+ childrenRenderBounds.y += data.scrollY
112
+ }
113
+
114
+ isOverflow = !includes(boxBounds, childrenRenderBounds)
115
+ if (isOverflow && data.overflow !== 'hide') add(renderBounds, childrenRenderBounds)
107
116
  } else this.__updateRectRenderBounds()
108
117
 
109
118
  DataHelper.stintSet(this, 'isOverflow', isOverflow)
119
+
120
+ this.__updateScrollBar()
110
121
  }
111
122
 
112
123
  @rewrite(rect.__updateRenderBounds)
113
124
  public __updateRectRenderBounds(): void { }
114
125
 
126
+ // need rewrite
127
+ public __updateScrollBar(): void { }
128
+
129
+
115
130
  @rewrite(rect.__updateChange)
116
131
  public __updateRectChange(): void { }
117
132
 
@@ -135,13 +150,14 @@ export class Box extends Group implements IBox {
135
150
  this.__renderRect(canvas, options)
136
151
  if (this.children.length) this.__renderGroup(canvas, options)
137
152
  }
153
+ if (this.scrollBar) this.scrollBar.__render(canvas, options)
138
154
  }
139
155
 
140
156
  // in __drawAfterFill()
141
157
  public __drawContent(canvas: ILeaferCanvas, options: IRenderOptions): void {
142
158
  this.__renderGroup(canvas, options)
143
159
 
144
- if (this.__.__useStroke) { // 还原绘制路径
160
+ if (this.__.__useStroke || this.__.__useEffect) { // 还原绘制路径
145
161
  canvas.setWorld(this.__nowWorld)
146
162
  this.__drawRenderPath(canvas)
147
163
  }
package/src/Canvas.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeaferCanvas, ILeaferCanvasConfig, INumber, IRenderOptions, IPointData, ICanvasContext2D, ICanvasContext2DSettings, IScreenSizeData } from '@leafer/interface'
2
- import { Creator, ImageEvent, LeaferImage, Matrix, dataProcessor, dataType, registerUI } from '@leafer/core'
2
+ import { Creator, ImageEvent, LeaferImage, Matrix, dataProcessor, dataType, registerUI, isNumber } from '@leafer/core'
3
3
 
4
4
  import { ICanvas, ICanvasData, ICanvasInputData, IUI } from '@leafer-ui/interface'
5
5
  import { CanvasData } from '@leafer-ui/data'
@@ -62,7 +62,7 @@ export class Canvas extends Rect implements ICanvas {
62
62
 
63
63
  const m = new Matrix()
64
64
  if (offset) m.translate(offset.x, offset.y)
65
- if (scale) typeof scale === 'number' ? m.scale(scale) : m.scale(scale.x, scale.y)
65
+ if (scale) isNumber(scale) ? m.scale(scale) : m.scale(scale.x, scale.y)
66
66
  if (rotation) m.rotate(rotation)
67
67
  matrix.multiplyParent(m)
68
68
 
package/src/Group.ts CHANGED
@@ -27,6 +27,8 @@ export class Group extends UI implements IGroup { // tip: rewrited Box
27
27
 
28
28
  declare public children: IUI[]
29
29
 
30
+ public childlessJSON?: boolean
31
+
30
32
  constructor(data?: IGroupInputData) {
31
33
  super(data)
32
34
  }
@@ -43,7 +45,7 @@ export class Group extends UI implements IGroup { // tip: rewrited Box
43
45
 
44
46
  // data
45
47
 
46
- public set(data: IUIInputData, transition?: ITransition | 'temp'): void {
48
+ override set(data: IUIInputData, transition?: ITransition | 'temp'): void {
47
49
  if (data) {
48
50
  if (data.children) {
49
51
  const { children } = data
@@ -60,9 +62,9 @@ export class Group extends UI implements IGroup { // tip: rewrited Box
60
62
  }
61
63
  }
62
64
 
63
- public toJSON(options?: IJSONOptions): IUIJSONData {
65
+ override toJSON(options?: IJSONOptions): IUIJSONData {
64
66
  const data = super.toJSON(options)
65
- data.children = this.children.map(child => child.toJSON(options))
67
+ if (!this.childlessJSON) data.children = this.children.map(child => child.toJSON(options))
66
68
  return data
67
69
  }
68
70
 
package/src/Image.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeaferImage, IString } from '@leafer/interface'
2
- import { boundsType, dataProcessor, registerUI } from '@leafer/core'
2
+ import { boundsType, dataProcessor, registerUI, isArray } from '@leafer/core'
3
3
 
4
4
  import { IImage, IImageInputData, IImageData } from '@leafer-ui/interface'
5
5
  import { ImageData } from '@leafer-ui/data'
@@ -20,7 +20,7 @@ export class Image extends Rect implements IImage {
20
20
 
21
21
  public get ready(): boolean { const { image } = this; return image && image.ready }
22
22
 
23
- public get image(): ILeaferImage { const { fill } = this.__; return fill instanceof Array && fill[0].image }
23
+ public get image(): ILeaferImage { const { fill } = this.__; return isArray(fill) && fill[0].image }
24
24
 
25
25
  constructor(data?: IImageInputData) {
26
26
  super(data)
package/src/UI.ts CHANGED
@@ -1,7 +1,7 @@
1
- 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, ITransition, IFilter, ILeaferImage } from '@leafer/interface'
2
- 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, Plugin, DataHelper } from '@leafer/core'
1
+ 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, ITransition, IFilter, ILeaferImage, IScaleFixed } from '@leafer/interface'
2
+ 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, Plugin, DataHelper, affectRenderBoundsType, isString, isNumber } from '@leafer/core'
3
3
 
4
- 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, IAnimateType, IStateStyle, IColorString } from '@leafer-ui/interface'
4
+ 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, IAnimateType, IStateStyle, IColorString, IAnimateList } from '@leafer-ui/interface'
5
5
  import { effectType, zoomLayerType } from '@leafer-ui/decorator'
6
6
 
7
7
  import { UIData } from '@leafer-ui/data'
@@ -143,6 +143,10 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
143
143
  public pixelRatio?: INumber
144
144
 
145
145
 
146
+ @affectRenderBoundsType(0)
147
+ public renderSpread?: INumber // 强行扩大渲染边界
148
+
149
+
146
150
  // path
147
151
  @pathInputType()
148
152
  public path?: IPathCommandData | IPathCommandObject[] | IPathString
@@ -245,7 +249,7 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
245
249
  public strokeWidth?: IFourNumber | IStrokeWidthString
246
250
 
247
251
  @strokeType(false)
248
- public strokeWidthFixed?: IBoolean
252
+ public strokeWidthFixed?: IScaleFixed
249
253
 
250
254
  @strokeType('none')
251
255
  public strokeCap?: IStrokeCap
@@ -376,10 +380,13 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
376
380
  public set scale(value: INumber | IPointData) { MathHelper.assignScale(this as IScaleData, value) }
377
381
  public get scale(): INumber | IPointData { return this.__.scale }
378
382
 
383
+ public get isAutoWidth(): boolean { const t = this.__; return t.__autoWidth || t.autoWidth as boolean }
384
+ public get isAutoHeight(): boolean { const t = this.__; return t.__autoHeight || t.autoHeight as boolean }
385
+
379
386
  public useFastShadow?: boolean // 将忽略 stroke 产生的阴影,只对单个 fill 有效
380
387
 
381
388
  public __box?: IUI // 背景box, 一般用于文本背景框
382
- public __animate?: IAnimate
389
+ public __animate?: IAnimate | IAnimateList
383
390
 
384
391
  public get pen(): IPathCreator {
385
392
  const { path } = this.__
@@ -413,7 +420,7 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
413
420
  }
414
421
 
415
422
  public get(name?: string | string[] | IUIInputData): IUIInputData | IValue {
416
- return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name)
423
+ return isString(name) ? this.__.__getInput(name) : this.__.__getInputData(name)
417
424
  }
418
425
 
419
426
  public createProxyData(): IUIInputData { return undefined }
@@ -481,7 +488,7 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
481
488
  const { x, y, width, height } = this.__layout.boxBounds
482
489
  if (this.__.cornerRadius) {
483
490
  const { cornerRadius } = this.__
484
- drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius) // 修复微信浏览器bug, 后续需进一步优化
491
+ drawer.roundRect(x, y, width, height, isNumber(cornerRadius) ? [cornerRadius] : cornerRadius) // 修复微信浏览器bug, 后续需进一步优化
485
492
  } else drawer.rect(x, y, width, height)
486
493
  }
487
494
 
package/types/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { IString, INumber, IBoolean, IMaskType, IEraserType, IAlign, IUnitPointData, IPathCommandData, IPathCommandObject, IPathString, IWindingRule, IFlowType, IFourNumber, IGap, IPointGap, IFlowAlign, IFlowAxisAlign, IFlowWrap, IFlowBoxType, IAutoSize, IAutoBoxData, IConstraint, IRangeSize, IAxis, IBoundsData, IHitType, ICursorType, IFilter, ITransition, IUnitData, IObject, IPointData, IPathCreator, IValue, IFindCondition, ILeaferCanvas, IPathDrawer, ILeaferImage, IExportFileType, IJSONOptions, IPickOptions, IPickResult, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaferConfig, IAutoBounds, IBounds, IEventListenerId, ITimer, IControl, ILeaferType, IScreenSizeData, IResizeEvent, IZoomType, IZoomOptions, IClientPointData, IRenderOptions, ICanvasContext2DSettings, ICanvasContext2D } from '@leafer/interface';
1
+ import { IString, INumber, IBoolean, IMaskType, IEraserType, IAlign, IUnitPointData, IPathCommandData, IPathCommandObject, IPathString, IWindingRule, IFlowType, IFourNumber, IGap, IPointGap, IFlowAlign, IFlowAxisAlign, IFlowWrap, IFlowBoxType, IAutoSize, IAutoBoxData, IConstraint, IRangeSize, IAxis, IBoundsData, IHitType, ICursorType, IScaleFixed, IFilter, ITransition, IUnitData, IObject, IPointData, IPathCreator, IValue, IFindCondition, ILeaferCanvas, IPathDrawer, ILeaferImage, IExportFileType, IJSONOptions, IPickOptions, IPickResult, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaferConfig, IAutoBounds, IBounds, IEventListenerId, ITimer, IControl, ILeaferType, IScreenSizeData, IResizeEvent, IZoomType, IZoomOptions, IClientPointData, IRenderOptions, ICanvasContext2DSettings, ICanvasContext2D } from '@leafer/interface';
2
2
  import { Leaf, LeafList } from '@leafer/core';
3
- import { IUI, IUIData, IUIInputData, ILeafer, IGroup, IBlendMode, IFill, IStroke, IStrokeAlign, IStrokeWidthString, IStrokeCap, IStrokeJoin, IDashPatternString, IArrowType, ICornerRadiusString, IShadowEffect, IShadowString, IBlurEffect, IGrayscaleEffect, IAnimation, IStates, IStateName, IStateStyle, IColorString, IEditorConfig, IAnimate, IFindUIMethod, IKeyframe, IAnimateType, IExportOptions, IExportResult, IEditorConfigFunction, IEditToolFunction, IGroupData, IGroupInputData, IUIJSONData, IFindCondition as IFindCondition$1, ILeaferData, IApp, IEditorBase, IFunction, ILeaferInputData, IBox, IBoxData, IOverflow, IBoxInputData, IFrame, IFrameData, IFrameInputData, IRect, IRectData, IRectInputData, IEllipse, IEllipseData, IEllipseInputData, IPolygon, IPolygonData, IPolygonInputData, IStar, IStarData, IStarInputData, ILine, ILineData, ILineInputData, IImage, IImageData, IImageInputData, ICanvas, ICanvasData, ICanvasInputData, IText, ITextData, IBackgroundBoxStyle, IHitType as IHitType$1, IFontWeight, ITextCase, ITextDecoration, IWritingMode, ITextAlign, IVerticalAlign, ITextWrap, ITextDrawData, ITextInputData, IPath, IPathData, IPathInputData, IPen, IPenData, IPathCommandData as IPathCommandData$1, IPenInputData, IPointData as IPointData$1 } from '@leafer-ui/interface';
3
+ import { IUI, IUIData, IUIInputData, ILeafer, IGroup, IBlendMode, IFill, IStroke, IStrokeAlign, IStrokeWidthString, IStrokeCap, IStrokeJoin, IDashPatternString, IArrowType, ICornerRadiusString, IShadowEffect, IShadowString, IBlurEffect, IGrayscaleEffect, IAnimation, IStates, IStateName, IStateStyle, IColorString, IEditorConfig, IAnimate, IAnimateList, IFindUIMethod, IKeyframe, IAnimateType, IExportOptions, IExportResult, IEditorConfigFunction, IEditToolFunction, IGroupData, IGroupInputData, IUIJSONData, IFindCondition as IFindCondition$1, ILeaferData, IApp, IEditorBase, IFunction, ILeaferInputData, IBox, IBoxData, IOverflow, IBoxInputData, IFrame, IFrameData, IFrameInputData, IRect, IRectData, IRectInputData, IEllipse, IEllipseData, IEllipseInputData, IPolygon, IPolygonData, IPolygonInputData, IStar, IStarData, IStarInputData, ILine, ILineData, ILineInputData, IImage, IImageData, IImageInputData, ICanvas, ICanvasData, ICanvasInputData, IText, ITextData, IBackgroundBoxStyle, IHitType as IHitType$1, IFontWeight, ITextCase, ITextDecoration, IWritingMode, ITextAlign, IVerticalAlign, ITextWrap, ITextDrawData, ITextInputData, IPath, IPathData, IPathInputData, IPen, IPenData, IPathCommandData as IPathCommandData$1, IPenInputData, IPointData as IPointData$1 } from '@leafer-ui/interface';
4
4
 
5
5
  declare class UI extends Leaf implements IUI {
6
6
  __: IUIData;
@@ -41,6 +41,7 @@ declare class UI extends Leaf implements IUI {
41
41
  around?: IAlign | IUnitPointData;
42
42
  lazy?: IBoolean;
43
43
  pixelRatio?: INumber;
44
+ renderSpread?: INumber;
44
45
  path?: IPathCommandData | IPathCommandObject[] | IPathString;
45
46
  windingRule?: IWindingRule;
46
47
  closed?: boolean;
@@ -72,7 +73,7 @@ declare class UI extends Leaf implements IUI {
72
73
  stroke?: IStroke;
73
74
  strokeAlign?: IStrokeAlign;
74
75
  strokeWidth?: IFourNumber | IStrokeWidthString;
75
- strokeWidthFixed?: IBoolean;
76
+ strokeWidthFixed?: IScaleFixed;
76
77
  strokeCap?: IStrokeCap;
77
78
  strokeJoin?: IStrokeJoin;
78
79
  dashPattern?: INumber[] | IDashPatternString;
@@ -116,9 +117,11 @@ declare class UI extends Leaf implements IUI {
116
117
  data: IObject;
117
118
  set scale(value: INumber | IPointData);
118
119
  get scale(): INumber | IPointData;
120
+ get isAutoWidth(): boolean;
121
+ get isAutoHeight(): boolean;
119
122
  useFastShadow?: boolean;
120
123
  __box?: IUI;
121
- __animate?: IAnimate;
124
+ __animate?: IAnimate | IAnimateList;
122
125
  get pen(): IPathCreator;
123
126
  constructor(data?: IUIInputData);
124
127
  reset(_data?: IUIInputData): void;
@@ -160,6 +163,7 @@ declare class Group extends UI implements IGroup {
160
163
  width?: INumber;
161
164
  height?: INumber;
162
165
  children: IUI[];
166
+ childlessJSON?: boolean;
163
167
  constructor(data?: IGroupInputData);
164
168
  reset(data?: IGroupInputData): void;
165
169
  __setBranch(): void;
@@ -280,6 +284,7 @@ declare class Box extends Group implements IBox {
280
284
  textBox?: IBoolean;
281
285
  overflow?: IOverflow;
282
286
  isOverflow: boolean;
287
+ scrollBar?: IGroup;
283
288
  constructor(data?: IBoxInputData);
284
289
  __updateStrokeSpread(): number;
285
290
  __updateRectRenderSpread(): number;
@@ -289,6 +294,7 @@ declare class Box extends Group implements IBox {
289
294
  __updateStrokeBounds(): void;
290
295
  __updateRenderBounds(): void;
291
296
  __updateRectRenderBounds(): void;
297
+ __updateScrollBar(): void;
292
298
  __updateRectChange(): void;
293
299
  __updateChange(): void;
294
300
  __renderRect(_canvas: ILeaferCanvas, _options: IRenderOptions): void;