@leafer-ui/display 1.0.0-rc.23 → 1.0.0-rc.24

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.0.0-rc.23",
3
+ "version": "1.0.0-rc.24",
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.0.0-rc.23",
26
- "@leafer-ui/data": "1.0.0-rc.23",
27
- "@leafer-ui/display-module": "1.0.0-rc.23",
28
- "@leafer-ui/decorator": "1.0.0-rc.23",
29
- "@leafer-ui/external": "1.0.0-rc.23"
25
+ "@leafer/core": "1.0.0-rc.24",
26
+ "@leafer-ui/data": "1.0.0-rc.24",
27
+ "@leafer-ui/display-module": "1.0.0-rc.24",
28
+ "@leafer-ui/decorator": "1.0.0-rc.24",
29
+ "@leafer-ui/external": "1.0.0-rc.24"
30
30
  },
31
31
  "devDependencies": {
32
- "@leafer/interface": "1.0.0-rc.23",
33
- "@leafer-ui/interface": "1.0.0-rc.23"
32
+ "@leafer/interface": "1.0.0-rc.24",
33
+ "@leafer-ui/interface": "1.0.0-rc.24"
34
34
  }
35
35
  }
package/src/Box.ts CHANGED
@@ -9,8 +9,8 @@ import { Rect } from './Rect'
9
9
 
10
10
  const rect = Rect.prototype
11
11
  const group = Group.prototype
12
- const bounds = {} as IBoundsData
13
- const { copy, add } = BoundsHelper
12
+ const childrenRenderBounds = {} as IBoundsData
13
+ const { copy, add, includes } = BoundsHelper
14
14
 
15
15
  @rewriteAble()
16
16
  @registerUI()
@@ -26,6 +26,8 @@ export class Box extends Group implements IBox {
26
26
  @affectRenderBoundsType('show')
27
27
  declare public overflow: IOverflow
28
28
 
29
+ public isOverflow: boolean
30
+
29
31
  constructor(data?: IBoxInputData) {
30
32
  super(data)
31
33
  this.__layout.renderChanged || this.__layout.renderChange()
@@ -38,9 +40,7 @@ export class Box extends Group implements IBox {
38
40
  public __updateRectRenderSpread(): number { return 0 }
39
41
 
40
42
  public __updateRenderSpread(): number {
41
- const width = this.__updateRectRenderSpread()
42
- const hide = this.__.__drawAfterFill = this.__.overflow === 'hide'
43
- return (width || hide) ? width : -1
43
+ return this.__updateRectRenderSpread() || -1
44
44
  }
45
45
 
46
46
 
@@ -50,32 +50,45 @@ export class Box extends Group implements IBox {
50
50
  public __updateBoxBounds(): void {
51
51
  const data = this.__
52
52
 
53
- if (data.__autoSide && this.children.length) {
54
- if (this.leafer) this.leafer.layouter.addExtra(this)
55
- super.__updateBoxBounds()
56
- if (!data.__autoSize) {
57
- const b = this.__layout.boxBounds
58
- if (!data.__autoWidth) b.x = 0, b.width = data.width
59
- if (!data.__autoHeight) b.y = 0, b.height = data.height
53
+ if (this.children.length) {
54
+ if (data.__autoSide) {
55
+ if (this.leafer && this.leafer.ready) this.leafer.layouter.addExtra(this)
56
+ super.__updateBoxBounds()
57
+ if (!data.__autoSize) {
58
+ const b = this.__layout.boxBounds
59
+ if (!data.__autoWidth) b.x = 0, b.width = data.width
60
+ if (!data.__autoHeight) b.y = 0, b.height = data.height
61
+ }
62
+ } else {
63
+ this.__updateRectBoxBounds()
60
64
  }
65
+
66
+ if (data.flow) this.__updateContentBounds()
67
+
61
68
  } else {
62
69
  this.__updateRectBoxBounds()
63
70
  }
64
-
65
- if (data.flow) this.__updateContentBounds()
66
71
  }
67
72
 
68
73
  @rewrite(rect.__updateStrokeBounds)
69
74
  public __updateStrokeBounds(): void { }
70
75
 
71
76
  public __updateRenderBounds(): void {
72
- this.__updateRectRenderBounds()
73
- if (!this.__.__drawAfterFill) {
74
- const { renderBounds } = this.__layout
75
- copy(bounds, renderBounds)
77
+ let isOverflow: boolean
78
+ const { renderBounds } = this.__layout
79
+
80
+ if (this.children.length) {
76
81
  super.__updateRenderBounds()
77
- add(renderBounds, bounds)
82
+ copy(childrenRenderBounds, renderBounds)
83
+ this.__updateRectRenderBounds()
84
+
85
+ isOverflow = !includes(renderBounds, childrenRenderBounds) || undefined
86
+ } else {
87
+ this.__updateRectRenderBounds()
78
88
  }
89
+
90
+ this.isOverflow !== isOverflow && (this.isOverflow = isOverflow)
91
+ if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide')) add(renderBounds, childrenRenderBounds)
79
92
  }
80
93
 
81
94
  @rewrite(rect.__updateRenderBounds)
@@ -102,16 +115,25 @@ export class Box extends Group implements IBox {
102
115
  this.__renderRect(canvas, options)
103
116
  } else {
104
117
  this.__renderRect(canvas, options)
105
- this.__renderGroup(canvas, options)
118
+ if (this.children.length) this.__renderGroup(canvas, options)
106
119
  }
107
120
  }
108
121
 
109
122
  public __drawAfterFill(canvas: ILeaferCanvas, options: IRenderOptions): void {
110
- canvas.save()
111
- canvas.clip()
112
- this.__renderGroup(canvas, options)
113
- canvas.restore()
114
- if (this.__.stroke) this.__drawRenderPath(canvas)
123
+ const { length } = this.children
124
+ if (this.isOverflow) {
125
+ canvas.save()
126
+ canvas.clip()
127
+ if (length) this.__renderGroup(canvas, options)
128
+ canvas.restore()
129
+ } else {
130
+ if (length) this.__renderGroup(canvas, options)
131
+ }
132
+
133
+ if (this.__.stroke && length) {
134
+ canvas.setWorld(this.__nowWorld)
135
+ this.__drawRenderPath(canvas)
136
+ }
115
137
  }
116
138
 
117
139
  }
package/src/Leafer.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaferCanvas, IRenderer, ILayouter, ISelector, IWatcher, IInteraction, ILeaferConfig, ICanvasManager, IHitCanvasManager, IAutoBounds, IScreenSizeData, IResizeEvent, IEventListenerId, ITimer, IValue, IObject, IControl, IPointData, ILeaferType, ICursorType, IBoundsData, INumber, IZoomType, IFourNumber, IBounds } from '@leafer/interface'
1
+ import { ILeaferCanvas, IRenderer, ILayouter, ISelector, IWatcher, IInteraction, ILeaferConfig, ICanvasManager, IHitCanvasManager, IAutoBounds, IScreenSizeData, IResizeEvent, IEventListenerId, ITimer, IValue, IObject, IControl, IPointData, ILeaferType, ICursorType, IBoundsData, INumber, IZoomType, IFourNumber, IBounds, IClientPointData } from '@leafer/interface'
2
2
  import { AutoBounds, LayoutEvent, ResizeEvent, LeaferEvent, CanvasManager, ImageManager, DataHelper, Creator, Run, Debug, RenderEvent, registerUI, boundsType, canvasSizeAttrs, dataProcessor, WaitHelper, WatchEvent, Bounds, LeafList } from '@leafer/core'
3
3
 
4
4
  import { ILeaferInputData, ILeaferData, IFunction, IUIInputData, ILeafer, IApp, IEditorBase } from '@leafer-ui/interface'
@@ -80,6 +80,7 @@ export class Leafer extends Group implements ILeafer {
80
80
 
81
81
  public get FPS(): number { return this.renderer ? this.renderer.FPS : 60 }
82
82
  public get cursorPoint(): IPointData { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 } }
83
+ public get clientBounds(): IBoundsData { return this.canvas && this.canvas.getClientBounds() }
83
84
  public leafs = 0
84
85
 
85
86
  public __eventIds: IEventListenerId[] = []
@@ -253,7 +254,7 @@ export class Leafer extends Group implements ILeafer {
253
254
  } else if (attrName === 'fill') {
254
255
  this.__changeFill(newValue as string)
255
256
  } else if (attrName === 'hittable') {
256
- this.canvas.hittable = newValue as boolean
257
+ if (!this.parent) this.canvas.hittable = newValue as boolean
257
258
  }
258
259
  }
259
260
  return super.__setAttr(attrName, newValue)
@@ -371,6 +372,11 @@ export class Leafer extends Group implements ILeafer {
371
372
  public getValidMove(moveX: number, moveY: number): IPointData { return { x: moveX, y: moveY } }
372
373
  public getValidScale(changeScale: number): number { return changeScale }
373
374
 
375
+
376
+ public getWorldPointByClient(clientPoint: IClientPointData, updateClient?: boolean): IPointData {
377
+ return this.interaction && this.interaction.getLocal(clientPoint, updateClient)
378
+ }
379
+
374
380
  protected __checkUpdateLayout(): void {
375
381
  this.__layout.update()
376
382
  }
package/src/Line.ts CHANGED
@@ -59,11 +59,12 @@ export class Line extends UI implements ILine { // tip: rewrited Polygon
59
59
 
60
60
  public __updatePath(): void {
61
61
 
62
- const path: number[] = this.__.path = []
62
+ const data = this.__
63
+ const path: number[] = data.path = []
63
64
 
64
- if (this.__.points) {
65
+ if (data.points) {
65
66
 
66
- drawPoints(path, this.__.points, this.__.closed)
67
+ drawPoints(path, data.points, false, data.closed)
67
68
 
68
69
  } else {
69
70
 
package/src/Text.ts CHANGED
@@ -59,7 +59,7 @@ export class Text extends UI implements IText {
59
59
  @boundsType(0)
60
60
  public letterSpacing: INumber | IUnitData
61
61
 
62
- @boundsType({ type: 'percent', value: 150 } as IUnitData)
62
+ @boundsType({ type: 'percent', value: 1.5 } as IUnitData)
63
63
  public lineHeight: INumber | IUnitData
64
64
 
65
65
  @boundsType(0)
package/src/UI.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType, INumber, IBoolean, IString, IPathString, IExportFileType, IPointData, ICursorType, IMaskType, IEraserType, IValue, IWindingRule, IPathCreator, IFourNumber, IBoundsData, IFlowType, IGap, IWrap, IAxis, IConstraint, IAutoBoxData, IFlowBoxType, IPointGap, IFlowAlign, IFlowAxisAlign, IFindCondition, IAutoSize, IRangeSize, IAlign, IUnitPointData } from '@leafer/interface'
2
- import { Leaf, PathDrawer, surfaceType, dataType, positionType, boundsType, pathType, scaleType, rotationType, opacityType, sortType, maskType, dataProcessor, registerUI, useModule, rewrite, rewriteAble, UICreator, PathCorner, hitType, strokeType, PathConvert, eraserType, cursorType, autoLayoutType, pen, naturalBoundsType, pathInputType } from '@leafer/core'
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 } from '@leafer/core'
3
3
 
4
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 } from '@leafer-ui/interface'
5
5
  import { arrowType, effectType, stateType, zoomLayerType } from '@leafer-ui/decorator'
@@ -53,8 +53,8 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
53
53
  @opacityType(1)
54
54
  public opacity: INumber
55
55
 
56
- @opacityType(true)
57
- public visible: IBoolean
56
+ @visibleType(true)
57
+ public visible: IBoolean | 0
58
58
 
59
59
 
60
60
  @stateType(false)
@@ -72,13 +72,10 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
72
72
 
73
73
 
74
74
  @maskType(false)
75
- public mask: IMaskType
76
-
77
- @surfaceType('pixel') // will remove
78
- public maskType: IMaskType
75
+ public mask: IBoolean | IMaskType
79
76
 
80
77
  @eraserType(false)
81
- public eraser: IEraserType
78
+ public eraser: IBoolean | IEraserType
82
79
 
83
80
 
84
81
  // position
@@ -341,7 +338,9 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
341
338
  }
342
339
 
343
340
  public get pen(): IPathCreator {
344
- pen.set(this.path = this.__.path || [])
341
+ const { path } = this.__
342
+ pen.set(this.path = path || [])
343
+ if (!path) this.__drawPathByBox(pen)
345
344
  return pen
346
345
  }
347
346
 
@@ -350,7 +349,7 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
350
349
 
351
350
  public get editConfig(): IEditorConfig { return undefined }
352
351
 
353
- public get editOuter(): string { return 'EditTool' }
352
+ public get editOuter(): string { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool' }
354
353
 
355
354
  public get editInner(): string { return 'PathEditor' }
356
355
 
@@ -393,13 +392,7 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
393
392
  public getPath(curve?: boolean, pathForRender?: boolean): IPathCommandData {
394
393
  this.__layout.update()
395
394
  let path = pathForRender ? this.__.__pathForRender : this.__.path
396
- if (!path) {
397
- const { width, height } = this.boxBounds
398
- if (width || height) {
399
- pen.set(path = [])
400
- this.__drawPathByBox(pen)
401
- }
402
- }
395
+ if (!path) pen.set(path = []), this.__drawPathByBox(pen)
403
396
  return curve ? PathConvert.toCanvasData(path, true) : path
404
397
  }
405
398
 
@@ -408,6 +401,10 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
408
401
  }
409
402
 
410
403
 
404
+ public load(): void {
405
+ this.__.__computePaint() // 手动加载图片
406
+ }
407
+
411
408
  public __onUpdateSize(): void {
412
409
  if (this.__.__input) {
413
410
  const data = this.__;
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IString, INumber, IBoolean, IMaskType, IEraserType, IAlign, IUnitPointData, IPathCommandData, IPathString, IWindingRule, IFlowType, IFourNumber, IGap, IPointGap, IFlowAlign, IFlowAxisAlign, IWrap, IFlowBoxType, IAutoSize, IAutoBoxData, IConstraint, IRangeSize, IAxis, IBoundsData, IHitType, ICursorType, IPointData, IPathCreator, IValue, IFindCondition, ILeaferCanvas, IPathDrawer, IExportFileType, IPickOptions, IPickResult, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaferConfig, IAutoBounds, IBounds, IEventListenerId, ITimer, IControl, ILeaferType, IScreenSizeData, IResizeEvent, IObject, IZoomType, IRenderOptions, ILeaferImage, ICanvasContext2DSettings, ICanvasContext2D, IUnitData } from '@leafer/interface';
1
+ import { IString, INumber, IBoolean, IMaskType, IEraserType, IAlign, IUnitPointData, IPathCommandData, IPathString, IWindingRule, IFlowType, IFourNumber, IGap, IPointGap, IFlowAlign, IFlowAxisAlign, IWrap, IFlowBoxType, IAutoSize, IAutoBoxData, IConstraint, IRangeSize, IAxis, IBoundsData, IHitType, ICursorType, IPointData, IPathCreator, IValue, IFindCondition, ILeaferCanvas, IPathDrawer, IExportFileType, IPickOptions, IPickResult, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaferConfig, IAutoBounds, IBounds, IEventListenerId, ITimer, IControl, ILeaferType, IScreenSizeData, IResizeEvent, IObject, IZoomType, IClientPointData, IRenderOptions, ILeaferImage, ICanvasContext2DSettings, ICanvasContext2D, IUnitData } from '@leafer/interface';
2
2
  import { Leaf, LeafList } from '@leafer/core';
3
3
  import { IUI, IUIData, IUIInputData, ILeafer, IGroup, IBlendMode, IFill, IStroke, IStrokeAlign, IStrokeWidthString, IStrokeCap, IStrokeJoin, IDashPatternString, IArrowType, ICornerRadiusString, IShadowEffect, IShadowString, IBlurEffect, IGrayscaleEffect, IEditorConfig, IFindUIMethod, IExportOptions, IExportResult, IEditorConfigFunction, IEditToolFunction, IGroupData, IGroupInputData, 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, IHitType as IHitType$1, IFontWeight, ITextCase, ITextDecoration, ITextAlign, IVerticalAlign, ITextWrap, ITextDrawData, ITextInputData, IPath, IPathData, IPathInputData, IPen, IPenData, IPathCommandData as IPathCommandData$1, IPenInputData } from '@leafer-ui/interface';
4
4
 
@@ -17,14 +17,13 @@ declare class UI extends Leaf implements IUI {
17
17
  className: IString;
18
18
  blendMode: IBlendMode;
19
19
  opacity: INumber;
20
- visible: IBoolean;
20
+ visible: IBoolean | 0;
21
21
  selected: IBoolean;
22
22
  disabled: IBoolean;
23
23
  locked: IBoolean;
24
24
  zIndex: INumber;
25
- mask: IMaskType;
26
- maskType: IMaskType;
27
- eraser: IEraserType;
25
+ mask: IBoolean | IMaskType;
26
+ eraser: IBoolean | IEraserType;
28
27
  x: INumber;
29
28
  y: INumber;
30
29
  width: INumber;
@@ -110,6 +109,7 @@ declare class UI extends Leaf implements IUI {
110
109
  findId(id: number | string): IUI;
111
110
  getPath(curve?: boolean, pathForRender?: boolean): IPathCommandData;
112
111
  getPathString(curve?: boolean, pathForRender?: boolean): IPathString;
112
+ load(): void;
113
113
  __onUpdateSize(): void;
114
114
  __updateRenderPath(): void;
115
115
  __drawRenderPath(canvas: ILeaferCanvas): void;
@@ -181,6 +181,7 @@ declare class Leafer extends Group implements ILeafer {
181
181
  lazyBounds: IBounds;
182
182
  get FPS(): number;
183
183
  get cursorPoint(): IPointData;
184
+ get clientBounds(): IBoundsData;
184
185
  leafs: number;
185
186
  __eventIds: IEventListenerId[];
186
187
  protected __startTimer: ITimer;
@@ -227,6 +228,7 @@ declare class Leafer extends Group implements ILeafer {
227
228
  zoom(_zoomType: IZoomType, _padding?: IFourNumber, _fixedScale?: boolean): IBoundsData;
228
229
  getValidMove(moveX: number, moveY: number): IPointData;
229
230
  getValidScale(changeScale: number): number;
231
+ getWorldPointByClient(clientPoint: IClientPointData, updateClient?: boolean): IPointData;
230
232
  protected __checkUpdateLayout(): void;
231
233
  protected emitLeafer(type: string): void;
232
234
  protected __listenEvents(): void;
@@ -239,6 +241,7 @@ declare class Box extends Group implements IBox {
239
241
  get isBranchLeaf(): boolean;
240
242
  __: IBoxData;
241
243
  overflow: IOverflow;
244
+ isOverflow: boolean;
242
245
  constructor(data?: IBoxInputData);
243
246
  __updateStrokeSpread(): number;
244
247
  __updateRectRenderSpread(): number;