@leafer-ui/display 1.0.0-rc.9 → 1.0.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.0.0-rc.9",
3
+ "version": "1.0.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.0.0-rc.9",
26
- "@leafer-ui/data": "1.0.0-rc.9",
27
- "@leafer-ui/display-module": "1.0.0-rc.9",
28
- "@leafer-ui/decorator": "1.0.0-rc.9",
29
- "@leafer-ui/external": "1.0.0-rc.9"
25
+ "@leafer/core": "1.0.0",
26
+ "@leafer-ui/data": "1.0.0",
27
+ "@leafer-ui/display-module": "1.0.0",
28
+ "@leafer-ui/decorator": "1.0.0",
29
+ "@leafer-ui/external": "1.0.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@leafer/interface": "1.0.0-rc.9",
33
- "@leafer-ui/interface": "1.0.0-rc.9"
32
+ "@leafer/interface": "1.0.0",
33
+ "@leafer-ui/interface": "1.0.0"
34
34
  }
35
35
  }
package/src/Box.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ILeaferCanvas, IRenderOptions, IPathDrawer, IBoundsData, IPathCommandData } from '@leafer/interface'
2
- import { rewrite, rewriteAble, registerUI, BoundsHelper, dataProcessor, affectRenderBoundsType } from '@leafer/core'
1
+ import { ILeaferCanvas, IRenderOptions, IBoundsData, IBoolean } from '@leafer/interface'
2
+ import { rewrite, rewriteAble, registerUI, BoundsHelper, dataProcessor, affectRenderBoundsType, dataType } from '@leafer/core'
3
3
 
4
4
  import { IBox, IBoxData, IBoxInputData, IOverflow } from '@leafer-ui/interface'
5
5
  import { BoxData } from '@leafer-ui/data'
@@ -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()
@@ -18,27 +18,24 @@ export class Box extends Group implements IBox {
18
18
 
19
19
  public get __tag() { return 'Box' }
20
20
 
21
+ public get isBranchLeaf(): boolean { return true }
22
+
21
23
  @dataProcessor(BoxData)
22
24
  declare public __: IBoxData
23
25
 
26
+ @dataType(false)
27
+ public resizeChildren?: IBoolean
28
+
24
29
  @affectRenderBoundsType('show')
25
- declare public overflow: IOverflow
30
+ declare public overflow?: IOverflow
31
+
32
+ public isOverflow: boolean
26
33
 
27
34
  constructor(data?: IBoxInputData) {
28
35
  super(data)
29
- this.isBranchLeaf = true
30
36
  this.__layout.renderChanged || this.__layout.renderChange()
31
37
  }
32
38
 
33
- public __scaleResize(scaleX: number, scaleY: number): void {
34
- if (this.__.__autoBounds && this.children.length) {
35
- super.__scaleResize(scaleX, scaleY)
36
- } else {
37
- this.width *= scaleX
38
- this.height *= scaleY
39
- }
40
- }
41
-
42
39
  @rewrite(rect.__updateStrokeSpread)
43
40
  public __updateStrokeSpread(): number { return 0 }
44
41
 
@@ -46,10 +43,7 @@ export class Box extends Group implements IBox {
46
43
  public __updateRectRenderSpread(): number { return 0 }
47
44
 
48
45
  public __updateRenderSpread(): number {
49
- let width = this.__updateRectRenderSpread() || super.__updateRenderSpread()
50
- this.__.__drawAfterFill = this.__.overflow === 'hide'
51
- if (!width) width = this.__.__drawAfterFill ? 0 : 1
52
- return width
46
+ return this.__updateRectRenderSpread() || -1
53
47
  }
54
48
 
55
49
 
@@ -57,8 +51,23 @@ export class Box extends Group implements IBox {
57
51
  public __updateRectBoxBounds(): void { }
58
52
 
59
53
  public __updateBoxBounds(): void {
60
- if (this.__.__autoBounds && this.children.length) {
61
- super.__updateBoxBounds()
54
+ const data = this.__
55
+
56
+ if (this.children.length) {
57
+ if (data.__autoSide) {
58
+ if (this.leafer && this.leafer.ready) this.leafer.layouter.addExtra(this)
59
+ super.__updateBoxBounds()
60
+ if (!data.__autoSize) {
61
+ const b = this.__layout.boxBounds
62
+ if (!data.__autoWidth) b.height += b.y, b.width = data.width, b.x = b.y = 0
63
+ if (!data.__autoHeight) b.width += b.x, b.height = data.height, b.y = b.x = 0
64
+ }
65
+ } else {
66
+ this.__updateRectBoxBounds()
67
+ }
68
+
69
+ if (data.flow) this.__updateContentBounds()
70
+
62
71
  } else {
63
72
  this.__updateRectBoxBounds()
64
73
  }
@@ -68,15 +77,22 @@ export class Box extends Group implements IBox {
68
77
  public __updateStrokeBounds(): void { }
69
78
 
70
79
  public __updateRenderBounds(): void {
71
- this.__updateRectRenderBounds()
72
- if (!this.__.__drawAfterFill) {
73
- const { renderBounds } = this.__layout
74
- copy(bounds, renderBounds)
80
+ let isOverflow: boolean
81
+ const { renderBounds } = this.__layout
82
+
83
+ if (this.children.length) {
75
84
  super.__updateRenderBounds()
76
- add(renderBounds, bounds)
85
+ copy(childrenRenderBounds, renderBounds)
86
+ this.__updateRectRenderBounds()
87
+
88
+ isOverflow = !includes(renderBounds, childrenRenderBounds) || undefined
89
+ } else {
90
+ this.__updateRectRenderBounds()
77
91
  }
78
- }
79
92
 
93
+ this.isOverflow !== isOverflow && (this.isOverflow = isOverflow)
94
+ if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide')) add(renderBounds, childrenRenderBounds)
95
+ }
80
96
 
81
97
  @rewrite(rect.__updateRenderBounds)
82
98
  public __updateRectRenderBounds(): void { }
@@ -90,10 +106,6 @@ export class Box extends Group implements IBox {
90
106
  }
91
107
 
92
108
 
93
- @rewrite(rect.__drawPathByData)
94
- public __drawPathByData(_drawer: IPathDrawer, _data: IPathCommandData): void { }
95
-
96
-
97
109
  @rewrite(rect.__render)
98
110
  public __renderRect(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
99
111
 
@@ -106,16 +118,25 @@ export class Box extends Group implements IBox {
106
118
  this.__renderRect(canvas, options)
107
119
  } else {
108
120
  this.__renderRect(canvas, options)
109
- this.__renderGroup(canvas, options)
121
+ if (this.children.length) this.__renderGroup(canvas, options)
110
122
  }
111
123
  }
112
124
 
113
125
  public __drawAfterFill(canvas: ILeaferCanvas, options: IRenderOptions): void {
114
- canvas.save()
115
- canvas.clip()
116
- this.__renderGroup(canvas, options)
117
- canvas.restore()
118
- if (this.__.stroke) this.__drawRenderPath(canvas)
126
+ const { length } = this.children
127
+ if (this.isOverflow) {
128
+ canvas.save()
129
+ canvas.clip()
130
+ if (length) this.__renderGroup(canvas, options)
131
+ canvas.restore()
132
+ } else {
133
+ if (length) this.__renderGroup(canvas, options)
134
+ }
135
+
136
+ if (this.__.stroke && length) {
137
+ canvas.setWorld(this.__nowWorld)
138
+ this.__drawRenderPath(canvas)
139
+ }
119
140
  }
120
141
 
121
142
  }
package/src/Canvas.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { ILeaferCanvas, ILeaferCanvasConfig, INumber, IRenderOptions, IPointData, ICanvasContext2D, IScreenSizeData, ISizeData, IHitType } from '@leafer/interface'
2
- import { Creator, Matrix, Platform, dataProcessor, registerUI, hitType } from '@leafer/core'
1
+ import { ILeaferCanvas, ILeaferCanvasConfig, INumber, IRenderOptions, IPointData, ICanvasContext2D, ICanvasContext2DSettings, IScreenSizeData, ISizeData } from '@leafer/interface'
2
+ import { Creator, Matrix, Platform, dataProcessor, registerUI } from '@leafer/core'
3
3
 
4
4
  import { ICanvas, ICanvasData, ICanvasInputData, IUI } from '@leafer-ui/interface'
5
- import { ImageData } from '@leafer-ui/data'
5
+ import { CanvasData } from '@leafer-ui/data'
6
+ import { resizeType } from '@leafer-ui/decorator'
6
7
 
7
8
  import { Rect } from './Rect'
8
- import { resizeType } from '@leafer-ui/decorator'
9
9
 
10
10
 
11
11
  @registerUI()
@@ -13,40 +13,39 @@ export class Canvas extends Rect implements ICanvas {
13
13
 
14
14
  public get __tag() { return 'Canvas' }
15
15
 
16
- @dataProcessor(ImageData)
16
+ @dataProcessor(CanvasData)
17
17
  declare public __: ICanvasData
18
18
 
19
19
  @resizeType(100)
20
- declare public width: INumber
20
+ declare public width?: INumber
21
21
 
22
22
  @resizeType(100)
23
- declare public height: INumber
23
+ declare public height?: INumber
24
24
 
25
25
  @resizeType(Platform.devicePixelRatio)
26
- public pixelRatio: INumber
26
+ declare public pixelRatio?: INumber
27
27
 
28
28
  @resizeType(true)
29
- public smooth: boolean
29
+ public smooth?: boolean
30
30
 
31
- @hitType('all')
32
- declare public hitFill: IHitType
31
+ @resizeType()
32
+ public contextSettings?: ICanvasContext2DSettings
33
33
 
34
- public canvas: ILeaferCanvas
34
+ public canvas?: ILeaferCanvas
35
35
 
36
- public context: ICanvasContext2D
36
+ public context?: ICanvasContext2D
37
37
 
38
38
  constructor(data?: ICanvasInputData) {
39
39
  super(data)
40
40
  this.canvas = Creator.canvas(this.__ as ILeaferCanvasConfig)
41
41
  this.context = this.canvas.context
42
- this.__.__drawAfterFill = true
42
+ this.__.__isCanvas = this.__.__drawAfterFill = true
43
43
  }
44
44
 
45
45
  public draw(ui: IUI, offset?: IPointData, scale?: number | IPointData, rotation?: number): void {
46
46
  ui.__layout.update()
47
47
 
48
- const matrix = new Matrix(ui.__world)
49
- matrix.invert()
48
+ const matrix = new Matrix(ui.__world).invert()
50
49
 
51
50
  const m = new Matrix()
52
51
  if (offset) m.translate(offset.x, offset.y)
@@ -54,7 +53,7 @@ export class Canvas extends Rect implements ICanvas {
54
53
  if (rotation) m.rotate(rotation)
55
54
  matrix.multiplyParent(m)
56
55
 
57
- ui.__render(this.canvas, { matrix })
56
+ ui.__render(this.canvas, { matrix: matrix.withScale() })
58
57
  this.paint()
59
58
  }
60
59
 
@@ -65,7 +64,7 @@ export class Canvas extends Rect implements ICanvas {
65
64
  public __drawAfterFill(canvas: ILeaferCanvas, _options: IRenderOptions): void {
66
65
  const origin = this.canvas.view as ISizeData
67
66
  const { width, height } = this
68
- if (this.__.cornerRadius) {
67
+ if (this.__.cornerRadius || this.pathInputed) {
69
68
  canvas.save()
70
69
  canvas.clip()
71
70
  canvas.drawImage(this.canvas.view as any, 0, 0, origin.width, origin.height, 0, 0, width, height)
package/src/Ellipse.ts CHANGED
@@ -18,13 +18,13 @@ export class Ellipse extends UI implements IEllipse {
18
18
  declare public __: IEllipseData
19
19
 
20
20
  @pathType(0)
21
- public innerRadius: INumber
21
+ public innerRadius?: INumber
22
22
 
23
23
  @pathType(0)
24
- public startAngle: INumber
24
+ public startAngle?: INumber
25
25
 
26
26
  @pathType(0)
27
- public endAngle: INumber
27
+ public endAngle?: INumber
28
28
 
29
29
  constructor(data?: IEllipseInputData) {
30
30
  super(data)
package/src/Frame.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { dataProcessor, registerUI, affectRenderBoundsType } from '@leafer/core'
1
+ import { dataProcessor, registerUI, affectRenderBoundsType, surfaceType } from '@leafer/core'
2
2
 
3
- import { IFrame, IFrameData, IFrameInputData, IOverflow } from '@leafer-ui/interface'
3
+ import { IFrame, IFrameData, IFrameInputData, IFill, IOverflow } from '@leafer-ui/interface'
4
4
  import { FrameData } from '@leafer-ui/data'
5
5
 
6
6
  import { Box } from './Box'
@@ -11,15 +11,18 @@ export class Frame extends Box implements IFrame {
11
11
 
12
12
  public get __tag() { return 'Frame' }
13
13
 
14
+ public get isFrame(): boolean { return true }
15
+
14
16
  @dataProcessor(FrameData)
15
17
  declare public __: IFrameData
16
18
 
19
+ @surfaceType('#FFFFFF')
20
+ declare public fill?: IFill
21
+
17
22
  @affectRenderBoundsType('hide')
18
- declare public overflow: IOverflow
23
+ declare public overflow?: IOverflow
19
24
 
20
25
  constructor(data?: IFrameInputData) {
21
26
  super(data)
22
- this.isFrame = true
23
- if (!this.__.fill) this.__.fill = '#FFFFFF'
24
27
  }
25
28
  }
package/src/Group.ts CHANGED
@@ -1,45 +1,39 @@
1
- import { Branch, useModule, dataProcessor, registerUI, UICreator, MatrixHelper } from '@leafer/core'
1
+ import { IJSONOptions, IPickOptions, IPickResult, IPointData } from '@leafer/interface'
2
+ import { Branch, useModule, dataProcessor, registerUI, UICreator } from '@leafer/core'
2
3
 
3
- import { IGroup, IGroupData, IGroupInputData, IUI, IUIInputData } from '@leafer-ui/interface'
4
+ import { IGroup, IGroupData, IGroupInputData, IUI, IUIInputData, IUIJSONData } from '@leafer-ui/interface'
4
5
  import { GroupData } from '@leafer-ui/data'
5
6
 
6
7
  import { UI } from './UI'
7
8
 
8
9
 
9
- const matrix = MatrixHelper.get()
10
-
11
10
  @useModule(Branch)
12
11
  @registerUI()
13
- export class Group extends UI implements IGroup {
12
+ export class Group extends UI implements IGroup { // tip: rewrited Box
14
13
 
15
14
  public get __tag() { return 'Group' }
16
15
 
16
+ public get isBranch(): boolean { return true }
17
+
17
18
  @dataProcessor(GroupData)
18
19
  declare public __: IGroupData
19
20
 
20
21
  declare public children: IUI[]
21
22
 
22
- public set mask(child: IUI) {
23
- if (this.__hasMask) this.__removeMask()
24
- if (child) {
25
- child.isMask = true
26
- this.addAt(child, 0)
27
- }
28
- }
29
- public get mask(): IUI {
30
- return this.children.find(item => item.isMask)
31
- }
32
-
33
23
  constructor(data?: IGroupInputData) {
34
24
  super(data)
25
+ }
26
+
27
+ public reset(data?: IGroupInputData): void {
35
28
  this.__setBranch()
29
+ super.reset(data)
36
30
  }
37
31
 
38
32
  public __setBranch(): void {
39
- this.isBranch = true
40
33
  if (!this.children) this.children = []
41
34
  }
42
35
 
36
+
43
37
  // data
44
38
 
45
39
  public set(data: IUIInputData): void {
@@ -50,14 +44,14 @@ export class Group extends UI implements IGroup {
50
44
  if (!this.children) {
51
45
  this.__setBranch()
52
46
  } else {
53
- this.removeAll(true)
47
+ this.clear()
54
48
  }
55
49
 
56
50
  super.set(data)
57
51
 
58
52
  let child: IUI
59
53
  children.forEach(childData => {
60
- child = UICreator.get(childData.tag, childData) as IUI
54
+ child = (childData as IUI).__ ? childData as IUI : UICreator.get(childData.tag, childData) as IUI
61
55
  this.add(child)
62
56
  })
63
57
 
@@ -68,20 +62,17 @@ export class Group extends UI implements IGroup {
68
62
  }
69
63
  }
70
64
 
71
- public toJSON(): IUIInputData {
72
- const data = super.toJSON()
73
- data.children = this.children.map(child => child.toJSON())
65
+ public toJSON(options?: IJSONOptions): IUIJSONData {
66
+ const data = super.toJSON(options)
67
+ data.children = this.children.map(child => child.toJSON(options))
74
68
  return data
75
69
  }
76
70
 
77
- public __scaleResize(scaleX: number, scaleY: number): void {
78
- const { children } = this
79
- for (let i = 0; i < children.length; i++) {
80
- matrix.a = scaleX // must update
81
- matrix.d = scaleY
82
- children[i].transform(matrix, true)
83
- }
84
- }
71
+
72
+ // hit rewrite
73
+
74
+ public pick(_hitPoint: IPointData, _options?: IPickOptions): IPickResult { return undefined }
75
+
85
76
 
86
77
  // add
87
78
 
@@ -93,7 +84,7 @@ export class Group extends UI implements IGroup {
93
84
  this.add(child, this.children.indexOf(after) + 1)
94
85
  }
95
86
 
96
- public addBefore(child: UI, before: IUI): void {
87
+ public addBefore(child: IUI, before: IUI): void {
97
88
  this.add(child, this.children.indexOf(before))
98
89
  }
99
90
 
@@ -107,4 +98,6 @@ export class Group extends UI implements IGroup {
107
98
 
108
99
  public removeAll(_destroy?: boolean): void { }
109
100
 
101
+ public clear(): void { }
102
+
110
103
  }
package/src/Image.ts CHANGED
@@ -20,7 +20,7 @@ export class Image extends Rect implements IImage {
20
20
 
21
21
  public get ready(): boolean { return this.image ? this.image.ready : false }
22
22
 
23
- public image: ILeaferImage
23
+ public image?: ILeaferImage
24
24
 
25
25
  constructor(data?: IImageInputData) {
26
26
  super(data)