@leafer/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 +10 -10
- package/src/Branch.ts +12 -11
- package/src/Leaf.ts +183 -68
- package/types/index.d.ts +66 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/display",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "@leafer/display",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/math": "1.0.0
|
|
26
|
-
"@leafer/data": "1.0.0
|
|
27
|
-
"@leafer/layout": "1.0.0
|
|
28
|
-
"@leafer/display-module": "1.0.0
|
|
29
|
-
"@leafer/event": "1.0.0
|
|
30
|
-
"@leafer/decorator": "1.0.0
|
|
31
|
-
"@leafer/helper": "1.0.0
|
|
32
|
-
"@leafer/platform": "1.0.0
|
|
25
|
+
"@leafer/math": "1.0.0",
|
|
26
|
+
"@leafer/data": "1.0.0",
|
|
27
|
+
"@leafer/layout": "1.0.0",
|
|
28
|
+
"@leafer/display-module": "1.0.0",
|
|
29
|
+
"@leafer/event": "1.0.0",
|
|
30
|
+
"@leafer/decorator": "1.0.0",
|
|
31
|
+
"@leafer/helper": "1.0.0",
|
|
32
|
+
"@leafer/platform": "1.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@leafer/interface": "1.0.0
|
|
35
|
+
"@leafer/interface": "1.0.0"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/src/Branch.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ChildEvent } from '@leafer/event'
|
|
|
3
3
|
import { BoundsHelper } from '@leafer/math'
|
|
4
4
|
import { BranchHelper, LeafBoundsHelper, WaitHelper } from '@leafer/helper'
|
|
5
5
|
import { useModule } from '@leafer/decorator'
|
|
6
|
-
import { BranchRender
|
|
6
|
+
import { BranchRender } from '@leafer/display-module'
|
|
7
7
|
|
|
8
8
|
import { Leaf } from './Leaf'
|
|
9
9
|
|
|
@@ -14,14 +14,7 @@ const { localBoxBounds, localStrokeBounds, localRenderBounds, maskLocalBoxBounds
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
@useModule(BranchRender)
|
|
17
|
-
|
|
18
|
-
export class Branch extends Leaf {
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
super()
|
|
22
|
-
this.isBranch = true
|
|
23
|
-
this.children = []
|
|
24
|
-
}
|
|
17
|
+
export class Branch extends Leaf { // tip: rewrited Group
|
|
25
18
|
|
|
26
19
|
// overwrite
|
|
27
20
|
|
|
@@ -70,12 +63,16 @@ export class Branch extends Leaf {
|
|
|
70
63
|
}
|
|
71
64
|
|
|
72
65
|
public add(child: ILeaf, index?: number): void {
|
|
66
|
+
if (child === this) return
|
|
67
|
+
|
|
73
68
|
if (child.parent) child.parent.remove(child)
|
|
74
69
|
child.parent = this
|
|
75
70
|
|
|
76
71
|
index === undefined ? this.children.push(child) : this.children.splice(index, 0, child)
|
|
77
72
|
if (child.isBranch) this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1
|
|
78
|
-
|
|
73
|
+
|
|
74
|
+
child.__layout.boxChanged || child.__layout.boxChange() // layouted(removed), need update
|
|
75
|
+
child.__layout.matrixChanged || child.__layout.matrixChange() // layouted(removed), need update
|
|
79
76
|
|
|
80
77
|
if (child.__parentWait) WaitHelper.run(child.__parentWait)
|
|
81
78
|
|
|
@@ -91,7 +88,7 @@ export class Branch extends Leaf {
|
|
|
91
88
|
children.forEach(child => this.add(child))
|
|
92
89
|
}
|
|
93
90
|
|
|
94
|
-
public remove(child?:
|
|
91
|
+
public remove(child?: ILeaf, destroy?: boolean): void {
|
|
95
92
|
if (child) {
|
|
96
93
|
const index = this.children.indexOf(child)
|
|
97
94
|
if (index > -1) {
|
|
@@ -119,6 +116,10 @@ export class Branch extends Leaf {
|
|
|
119
116
|
}
|
|
120
117
|
}
|
|
121
118
|
|
|
119
|
+
public clear(): void {
|
|
120
|
+
this.removeAll(true)
|
|
121
|
+
}
|
|
122
|
+
|
|
122
123
|
protected __preRemove(): void {
|
|
123
124
|
if (this.__hasMask) this.__updateMask()
|
|
124
125
|
if (this.__hasEraser) this.__updateEraser()
|
package/src/Leaf.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { ILeaferBase, ILeaf, ILeafInputData, ILeafData, ILeaferCanvas, IRenderOptions, IBoundsType, ILocationType, IMatrixWithBoundsData, ILayoutBoundsData, IValue, ILeafLayout, InnerId, IHitCanvas, IRadiusPointData, IEventListenerMap, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IObject, IFunction, IPointData, IBoundsData, IBranch,
|
|
2
|
-
import { IncrementId, MatrixHelper, PointHelper } from '@leafer/math'
|
|
1
|
+
import { ILeaferBase, ILeaf, ILeafInputData, ILeafData, ILeaferCanvas, IRenderOptions, IBoundsType, ILocationType, IMatrixWithBoundsData, ILayoutBoundsData, IValue, ILeafLayout, InnerId, IHitCanvas, IRadiusPointData, IEventListenerMap, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IObject, IFunction, IPointData, IBoundsData, IBranch, IFindMethod, IMatrixData, IAttrDecorator, IMatrixWithBoundsScaleData, IMatrixWithScaleData, IAlign, IJSONOptions } from '@leafer/interface'
|
|
2
|
+
import { BoundsHelper, IncrementId, MatrixHelper, PointHelper } from '@leafer/math'
|
|
3
3
|
import { LeafData } from '@leafer/data'
|
|
4
4
|
import { LeafLayout } from '@leafer/layout'
|
|
5
|
-
import { LeafDataProxy, LeafMatrix, LeafBounds,
|
|
5
|
+
import { LeafDataProxy, LeafMatrix, LeafBounds, LeafEventer, LeafRender } from '@leafer/display-module'
|
|
6
6
|
import { boundsType, useModule, defineDataProcessor } from '@leafer/decorator'
|
|
7
7
|
import { LeafHelper, WaitHelper } from '@leafer/helper'
|
|
8
|
+
import { ChildEvent } from '@leafer/event'
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
const { LEAF, create } = IncrementId
|
|
11
|
-
const { toInnerPoint, toOuterPoint } = MatrixHelper
|
|
12
|
-
const {
|
|
13
|
-
const {
|
|
12
|
+
const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper
|
|
13
|
+
const { toOuterOf } = BoundsHelper
|
|
14
|
+
const { copy } = PointHelper
|
|
15
|
+
const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getLocalOrigin, getRelativeWorld, drop } = LeafHelper
|
|
14
16
|
|
|
15
17
|
@useModule(LeafDataProxy)
|
|
16
18
|
@useModule(LeafMatrix)
|
|
17
19
|
@useModule(LeafBounds)
|
|
18
|
-
@useModule(LeafHit)
|
|
19
20
|
@useModule(LeafEventer)
|
|
20
21
|
@useModule(LeafRender)
|
|
21
22
|
export class Leaf implements ILeaf {
|
|
@@ -34,27 +35,31 @@ export class Leaf implements ILeaf {
|
|
|
34
35
|
public leafer?: ILeaferBase
|
|
35
36
|
public parent?: ILeaf
|
|
36
37
|
|
|
37
|
-
public isLeafer: boolean
|
|
38
|
-
public isBranch: boolean
|
|
39
|
-
public isBranchLeaf: boolean
|
|
38
|
+
public get isLeafer(): boolean { return false }
|
|
39
|
+
public get isBranch(): boolean { return false }
|
|
40
|
+
public get isBranchLeaf(): boolean { return false }
|
|
40
41
|
|
|
41
42
|
public __: ILeafData
|
|
42
43
|
public __layout: ILeafLayout
|
|
43
44
|
|
|
44
|
-
public __world:
|
|
45
|
+
public __world: IMatrixWithBoundsScaleData
|
|
45
46
|
public __local?: IMatrixWithBoundsData // and localStrokeBounds? localRenderBounds?
|
|
46
47
|
|
|
48
|
+
public __nowWorld?: IMatrixWithBoundsScaleData // use __world or __cameraWorld render
|
|
49
|
+
public __cameraWorld?: IMatrixWithBoundsScaleData // use camera matrix render
|
|
50
|
+
|
|
47
51
|
public get __localMatrix(): IMatrixData { return this.__local || this.__layout }
|
|
48
|
-
public get
|
|
52
|
+
public get __localBoxBounds(): IBoundsData { return this.__local || this.__layout }
|
|
49
53
|
|
|
50
54
|
public __worldOpacity: number
|
|
51
55
|
|
|
52
56
|
// now transform
|
|
53
|
-
public get worldTransform():
|
|
54
|
-
public get localTransform():
|
|
57
|
+
public get worldTransform(): IMatrixWithScaleData { return this.__layout.getTransform('world') as IMatrixWithScaleData }
|
|
58
|
+
public get localTransform(): IMatrixData { return this.__layout.getTransform('local') }
|
|
55
59
|
|
|
56
60
|
// now bounds
|
|
57
61
|
public get boxBounds(): IBoundsData { return this.getBounds('box', 'inner') }
|
|
62
|
+
public get renderBounds(): IBoundsData { return this.getBounds('render', 'inner') }
|
|
58
63
|
public get worldBoxBounds(): IBoundsData { return this.getBounds('box') }
|
|
59
64
|
public get worldStrokeBounds(): IBoundsData { return this.getBounds('stroke') }
|
|
60
65
|
public get worldRenderBounds(): IBoundsData { return this.getBounds('render') }
|
|
@@ -74,6 +79,9 @@ export class Leaf implements ILeaf {
|
|
|
74
79
|
|
|
75
80
|
public get __onlyHitMask(): boolean { return this.__hasMask && !this.__.hitChildren }
|
|
76
81
|
public get __ignoreHitWorld(): boolean { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren }
|
|
82
|
+
public get __inLazyBounds(): boolean { const { leafer } = this; return leafer && leafer.created && leafer.lazyBounds.hit(this.__world) }
|
|
83
|
+
|
|
84
|
+
public get pathInputed(): boolean { return this.__.__pathInputed as unknown as boolean }
|
|
77
85
|
|
|
78
86
|
// event
|
|
79
87
|
public __captureMap?: IEventListenerMap
|
|
@@ -99,7 +107,7 @@ export class Leaf implements ILeaf {
|
|
|
99
107
|
|
|
100
108
|
public reset(data?: ILeafInputData): void {
|
|
101
109
|
|
|
102
|
-
this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1
|
|
110
|
+
this.__world = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1 }
|
|
103
111
|
if (data !== null) this.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 }
|
|
104
112
|
|
|
105
113
|
this.__worldOpacity = 1
|
|
@@ -108,7 +116,10 @@ export class Leaf implements ILeaf {
|
|
|
108
116
|
this.__layout = new this.__LayoutProcessor(this)
|
|
109
117
|
|
|
110
118
|
if (this.__level) this.resetCustom()
|
|
111
|
-
if (data)
|
|
119
|
+
if (data) {
|
|
120
|
+
if ((data as ILeaf).__) data = (data as ILeaf).toJSON()
|
|
121
|
+
data.children ? this.set(data) : Object.assign(this, data)
|
|
122
|
+
}
|
|
112
123
|
}
|
|
113
124
|
|
|
114
125
|
public resetCustom(): void {
|
|
@@ -117,16 +128,22 @@ export class Leaf implements ILeaf {
|
|
|
117
128
|
}
|
|
118
129
|
|
|
119
130
|
|
|
120
|
-
public waitParent(item: IFunction): void {
|
|
131
|
+
public waitParent(item: IFunction, bind?: IObject): void {
|
|
132
|
+
if (bind) item = item.bind(bind)
|
|
121
133
|
this.parent ? item() : (this.__parentWait ? this.__parentWait.push(item) : this.__parentWait = [item])
|
|
122
134
|
}
|
|
123
135
|
|
|
124
|
-
public waitLeafer(item: IFunction): void {
|
|
136
|
+
public waitLeafer(item: IFunction, bind?: IObject): void {
|
|
137
|
+
if (bind) item = item.bind(bind)
|
|
125
138
|
this.leafer ? item() : (this.__leaferWait ? this.__leaferWait.push(item) : this.__leaferWait = [item])
|
|
126
139
|
}
|
|
127
140
|
|
|
128
|
-
public nextRender(item: IFunction): void {
|
|
129
|
-
this.leafer ? this.leafer.nextRender(item) : this.waitLeafer(() => this.leafer.nextRender(item))
|
|
141
|
+
public nextRender(item: IFunction, bind?: IObject, off?: 'off'): void {
|
|
142
|
+
this.leafer ? this.leafer.nextRender(item, bind, off) : this.waitLeafer(() => this.leafer.nextRender(item, bind, off))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public removeNextRender(item: IFunction): void {
|
|
146
|
+
this.nextRender(item, null, 'off')
|
|
130
147
|
}
|
|
131
148
|
|
|
132
149
|
public __bindLeafer(leafer: ILeaferBase | null): void {
|
|
@@ -155,19 +172,31 @@ export class Leaf implements ILeaf {
|
|
|
155
172
|
// data
|
|
156
173
|
|
|
157
174
|
public set(_data: IObject): void { }
|
|
158
|
-
public get(): ILeafInputData { return undefined }
|
|
175
|
+
public get(_name?: string): ILeafInputData | IValue { return undefined }
|
|
159
176
|
|
|
160
|
-
public
|
|
161
|
-
|
|
177
|
+
public setAttr(name: string, value: any): void { (this as IObject)[name] = value }
|
|
178
|
+
public getAttr(name: string): any { return (this as IObject)[name] }
|
|
179
|
+
|
|
180
|
+
public getComputedAttr(name: string): any { return (this.__ as IObject)[name] }
|
|
181
|
+
|
|
182
|
+
public toJSON(options?: IJSONOptions): IObject {
|
|
183
|
+
if (options) this.__layout.update()
|
|
184
|
+
return this.__.__getInputData(null, options)
|
|
162
185
|
}
|
|
163
186
|
|
|
164
|
-
public toString(): string {
|
|
165
|
-
return JSON.stringify(this.toJSON())
|
|
187
|
+
public toString(options?: IJSONOptions): string {
|
|
188
|
+
return JSON.stringify(this.toJSON(options))
|
|
166
189
|
}
|
|
167
190
|
|
|
191
|
+
public toSVG(): string { return undefined }
|
|
192
|
+
|
|
193
|
+
public __SVG(_data: IObject): void { }
|
|
194
|
+
|
|
195
|
+
public toHTML(): string { return undefined }
|
|
196
|
+
|
|
168
197
|
// LeafDataProxy rewrite
|
|
169
198
|
|
|
170
|
-
public __setAttr(_attrName: string, _newValue: IValue):
|
|
199
|
+
public __setAttr(_attrName: string, _newValue: IValue): boolean { return true }
|
|
171
200
|
|
|
172
201
|
public __getAttr(_attrName: string): IValue { return undefined }
|
|
173
202
|
|
|
@@ -182,10 +211,25 @@ export class Leaf implements ILeaf {
|
|
|
182
211
|
|
|
183
212
|
public find(_condition: number | string | IFindMethod, _options?: any): ILeaf[] { return undefined }
|
|
184
213
|
|
|
185
|
-
public
|
|
214
|
+
public findTag(_tag: string | string[]): ILeaf[] { return undefined }
|
|
215
|
+
|
|
216
|
+
public findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf | undefined { return undefined }
|
|
217
|
+
|
|
218
|
+
public findId(_id: number | string): ILeaf | undefined { return undefined }
|
|
219
|
+
|
|
220
|
+
// ---
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
// state
|
|
224
|
+
|
|
225
|
+
public focus(_value?: boolean): void { }
|
|
186
226
|
|
|
187
227
|
// ---
|
|
188
228
|
|
|
229
|
+
public updateLayout(): void {
|
|
230
|
+
this.__layout.update()
|
|
231
|
+
}
|
|
232
|
+
|
|
189
233
|
public forceUpdate(attrName?: string): void {
|
|
190
234
|
if (attrName === undefined) attrName = 'width'
|
|
191
235
|
else if (attrName === 'surface') attrName = 'blendMode'
|
|
@@ -194,11 +238,10 @@ export class Leaf implements ILeaf {
|
|
|
194
238
|
(this as any)[attrName] = value
|
|
195
239
|
}
|
|
196
240
|
|
|
197
|
-
public
|
|
198
|
-
this.
|
|
241
|
+
public forceRender(_bounds?: IBoundsData): void {
|
|
242
|
+
this.forceUpdate('surface')
|
|
199
243
|
}
|
|
200
244
|
|
|
201
|
-
|
|
202
245
|
// LeafMatrix rewrite
|
|
203
246
|
|
|
204
247
|
public __updateWorldMatrix(): void { }
|
|
@@ -224,12 +267,17 @@ export class Leaf implements ILeaf {
|
|
|
224
267
|
|
|
225
268
|
public __updateBoxBounds(): void { }
|
|
226
269
|
|
|
270
|
+
public __updateContentBounds(): void { }
|
|
271
|
+
|
|
227
272
|
public __updateStrokeBounds(): void { }
|
|
228
273
|
|
|
229
274
|
public __updateRenderBounds(): void { }
|
|
230
275
|
|
|
231
276
|
|
|
232
277
|
public __updateAutoLayout(): void { }
|
|
278
|
+
|
|
279
|
+
public __updateFlowLayout(): void { }
|
|
280
|
+
|
|
233
281
|
public __updateNaturalSize(): void { }
|
|
234
282
|
|
|
235
283
|
|
|
@@ -242,28 +290,49 @@ export class Leaf implements ILeaf {
|
|
|
242
290
|
// ---
|
|
243
291
|
|
|
244
292
|
|
|
245
|
-
|
|
293
|
+
public __updateEraser(value?: boolean): void {
|
|
294
|
+
this.__hasEraser = value ? true : this.children.some(item => item.__.eraser)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
public __renderEraser(canvas: ILeaferCanvas, options: IRenderOptions): void { // path eraser
|
|
298
|
+
canvas.save()
|
|
299
|
+
this.__clip(canvas, options)
|
|
300
|
+
const { renderBounds: r } = this.__layout
|
|
301
|
+
canvas.clearRect(r.x, r.y, r.width, r.height)
|
|
302
|
+
canvas.restore()
|
|
303
|
+
}
|
|
246
304
|
|
|
247
|
-
public
|
|
305
|
+
public __updateMask(value?: boolean): void {
|
|
306
|
+
this.__hasMask = value ? true : this.children.some(item => item.__.mask)
|
|
307
|
+
}
|
|
248
308
|
|
|
249
|
-
|
|
309
|
+
// LeafMask rewrite
|
|
250
310
|
|
|
251
|
-
public __renderMask(_canvas: ILeaferCanvas,
|
|
311
|
+
public __renderMask(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
|
|
252
312
|
|
|
253
|
-
public __removeMask(_child?: ILeaf): void { }
|
|
254
313
|
|
|
255
314
|
// ---
|
|
256
315
|
|
|
257
316
|
|
|
258
317
|
// convert
|
|
259
318
|
|
|
260
|
-
public
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
319
|
+
public __getNowWorld(options: IRenderOptions): IMatrixWithBoundsScaleData {
|
|
320
|
+
if (options.matrix) {
|
|
321
|
+
if (!this.__cameraWorld) this.__cameraWorld = {} as IMatrixWithBoundsScaleData
|
|
322
|
+
const cameraWorld = this.__cameraWorld
|
|
323
|
+
multiplyParent(this.__world, options.matrix, cameraWorld, undefined, this.__world)
|
|
324
|
+
toOuterOf(this.__layout.renderBounds, cameraWorld, cameraWorld)
|
|
325
|
+
return cameraWorld
|
|
326
|
+
} else {
|
|
327
|
+
return this.__world
|
|
328
|
+
}
|
|
265
329
|
}
|
|
266
330
|
|
|
331
|
+
public getTransform(relative?: ILocationType | ILeaf): IMatrixData {
|
|
332
|
+
return this.__layout.getTransform(relative || 'local')
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
|
|
267
336
|
public getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData {
|
|
268
337
|
return this.__layout.getBounds(type, relative)
|
|
269
338
|
}
|
|
@@ -277,6 +346,14 @@ export class Leaf implements ILeaf {
|
|
|
277
346
|
}
|
|
278
347
|
|
|
279
348
|
|
|
349
|
+
public getWorldBounds(inner: IBoundsData, relative?: ILeaf, change?: boolean): IBoundsData {
|
|
350
|
+
const matrix = relative ? getRelativeWorld(this, relative) : this.worldTransform
|
|
351
|
+
const to = change ? inner : {} as IBoundsData
|
|
352
|
+
toOuterOf(inner, matrix, to)
|
|
353
|
+
return to
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
|
|
280
357
|
public worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void {
|
|
281
358
|
if (this.parent) {
|
|
282
359
|
this.parent.worldToInner(world, to, distance, relative)
|
|
@@ -340,8 +417,18 @@ export class Leaf implements ILeaf {
|
|
|
340
417
|
return point
|
|
341
418
|
}
|
|
342
419
|
|
|
420
|
+
public getPagePoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
|
|
421
|
+
const layer = this.leafer ? this.leafer.zoomLayer : this
|
|
422
|
+
return layer.getInnerPoint(world, relative, distance, change)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
public getWorldPointByPage(page: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData {
|
|
426
|
+
const layer = this.leafer ? this.leafer.zoomLayer : this
|
|
427
|
+
return layer.getWorldPoint(page, relative, distance, change)
|
|
428
|
+
}
|
|
343
429
|
|
|
344
|
-
|
|
430
|
+
|
|
431
|
+
// transform
|
|
345
432
|
|
|
346
433
|
public setTransform(matrix: IMatrixData, resize?: boolean): void {
|
|
347
434
|
setTransform(this, matrix, resize)
|
|
@@ -351,47 +438,70 @@ export class Leaf implements ILeaf {
|
|
|
351
438
|
transform(this, matrix, resize)
|
|
352
439
|
}
|
|
353
440
|
|
|
354
|
-
|
|
355
|
-
public move(x: number, y?: number): void {
|
|
441
|
+
public move(x: number | IPointData, y?: number): void {
|
|
356
442
|
moveLocal(this, x, y)
|
|
357
443
|
}
|
|
358
444
|
|
|
359
|
-
public scaleOf(origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
|
|
360
|
-
zoomOfLocal(this,
|
|
445
|
+
public scaleOf(origin: IPointData | IAlign, scaleX: number, scaleY?: number, resize?: boolean): void {
|
|
446
|
+
zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize)
|
|
361
447
|
}
|
|
362
448
|
|
|
363
|
-
public rotateOf(origin: IPointData, rotation: number): void {
|
|
364
|
-
rotateOfLocal(this,
|
|
449
|
+
public rotateOf(origin: IPointData | IAlign, rotation: number): void {
|
|
450
|
+
rotateOfLocal(this, getLocalOrigin(this, origin), rotation)
|
|
365
451
|
}
|
|
366
452
|
|
|
367
|
-
public skewOf(origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
|
|
368
|
-
skewOfLocal(this,
|
|
453
|
+
public skewOf(origin: IPointData | IAlign, skewX: number, skewY?: number, resize?: boolean): void {
|
|
454
|
+
skewOfLocal(this, getLocalOrigin(this, origin), skewX, skewY, resize)
|
|
369
455
|
}
|
|
370
456
|
|
|
457
|
+
public transformWorld(worldTransform?: IMatrixData, resize?: boolean): void {
|
|
458
|
+
transformWorld(this, worldTransform, resize)
|
|
459
|
+
}
|
|
371
460
|
|
|
372
|
-
public
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
461
|
+
public moveWorld(x: number | IPointData, y?: number): void {
|
|
462
|
+
moveWorld(this, x, y)
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
public scaleOfWorld(worldOrigin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void {
|
|
466
|
+
zoomOfWorld(this, worldOrigin, scaleX, scaleY, resize)
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
public rotateOfWorld(worldOrigin: IPointData, rotation: number): void {
|
|
470
|
+
rotateOfWorld(this, worldOrigin, rotation)
|
|
382
471
|
}
|
|
383
472
|
|
|
384
|
-
public
|
|
385
|
-
|
|
386
|
-
if (scaleY !== 1) (this as ILeaf).height *= scaleY // Text auto height
|
|
473
|
+
public skewOfWorld(worldOrigin: IPointData, skewX: number, skewY?: number, resize?: boolean): void {
|
|
474
|
+
skewOfWorld(this, worldOrigin, skewX, skewY, resize)
|
|
387
475
|
}
|
|
388
476
|
|
|
389
|
-
|
|
477
|
+
|
|
478
|
+
// @leafer-in/resize rewrite
|
|
479
|
+
|
|
480
|
+
public scaleResize(scaleX: number, scaleY = scaleX, _noResize?: boolean): void {
|
|
481
|
+
(this as ILeaf).scaleX *= scaleX;
|
|
482
|
+
(this as ILeaf).scaleY *= scaleY
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
public __scaleResize(_scaleX: number, _scaleY: number): void { }
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
public resizeWidth(_width: number): void { }
|
|
489
|
+
|
|
490
|
+
public resizeHeight(_height: number): void { }
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
// @leafer-ui/hit LeafHit rewrite
|
|
390
494
|
|
|
391
495
|
public __hitWorld(_point: IRadiusPointData): boolean { return true }
|
|
392
496
|
|
|
393
497
|
public __hit(_local: IRadiusPointData): boolean { return true }
|
|
394
498
|
|
|
499
|
+
public __hitFill(_inner: IRadiusPointData): boolean { return true }
|
|
500
|
+
|
|
501
|
+
public __hitStroke(_inner: IRadiusPointData, _strokeWidth: number): boolean { return true }
|
|
502
|
+
|
|
503
|
+
public __hitPixel(_inner: IRadiusPointData): boolean { return true }
|
|
504
|
+
|
|
395
505
|
public __drawHitPath(_canvas: ILeaferCanvas): void { }
|
|
396
506
|
|
|
397
507
|
public __updateHitCanvas(): void { }
|
|
@@ -407,7 +517,10 @@ export class Leaf implements ILeaf {
|
|
|
407
517
|
|
|
408
518
|
public __draw(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
|
|
409
519
|
|
|
410
|
-
|
|
520
|
+
|
|
521
|
+
public __clip(_canvas: ILeaferCanvas, _options: IRenderOptions): void { }
|
|
522
|
+
|
|
523
|
+
public __renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions, _ignoreFill?: boolean, _ignoreStroke?: boolean): void { }
|
|
411
524
|
|
|
412
525
|
|
|
413
526
|
public __updateWorldOpacity(): void { }
|
|
@@ -449,7 +562,7 @@ export class Leaf implements ILeaf {
|
|
|
449
562
|
|
|
450
563
|
public on(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void { }
|
|
451
564
|
|
|
452
|
-
public off(_type
|
|
565
|
+
public off(_type?: string | string[], _listener?: IEventListener, _options?: IEventListenerOptions | boolean): void { }
|
|
453
566
|
|
|
454
567
|
public on_(_type: string | string[], _listener: IEventListener, _bind?: IObject, _options?: IEventListenerOptions | boolean): IEventListenerId { return undefined }
|
|
455
568
|
|
|
@@ -465,8 +578,8 @@ export class Leaf implements ILeaf {
|
|
|
465
578
|
|
|
466
579
|
// ---
|
|
467
580
|
|
|
468
|
-
static changeAttr(attrName: string, defaultValue: IValue): void {
|
|
469
|
-
defineDataProcessor(this.prototype, attrName, defaultValue)
|
|
581
|
+
static changeAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void {
|
|
582
|
+
fn ? this.addAttr(attrName, defaultValue, fn) : defineDataProcessor(this.prototype, attrName, defaultValue)
|
|
470
583
|
}
|
|
471
584
|
|
|
472
585
|
static addAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void {
|
|
@@ -477,8 +590,10 @@ export class Leaf implements ILeaf {
|
|
|
477
590
|
|
|
478
591
|
public destroy(): void {
|
|
479
592
|
if (!this.destroyed) {
|
|
480
|
-
|
|
593
|
+
const { parent } = this
|
|
594
|
+
if (parent) this.remove()
|
|
481
595
|
if (this.children) (this as unknown as IBranch).removeAll(true)
|
|
596
|
+
if (this.hasEvent(ChildEvent.DESTROY)) this.emitEvent(new ChildEvent(ChildEvent.DESTROY, this, parent))
|
|
482
597
|
|
|
483
598
|
this.__.destroy()
|
|
484
599
|
this.__layout.destroy()
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaf, InnerId, ILeaferBase, ILeafData, ILeafLayout,
|
|
1
|
+
import { ILeaf, InnerId, ILeaferBase, ILeafData, ILeafLayout, IMatrixWithBoundsScaleData, IMatrixWithBoundsData, IMatrixData, IBoundsData, IMatrixWithScaleData, IHitCanvas, IEventListenerMap, IFunction, ILeafInputData, IObject, IValue, IJSONOptions, IFindMethod, ILeaferCanvas, IRenderOptions, ILocationType, IBoundsType, ILayoutBoundsData, IPointData, IAlign, IRadiusPointData, IEventListener, IEventListenerOptions, IEventListenerId, IEvent, IAttrDecorator } from '@leafer/interface';
|
|
2
2
|
import { LeafData } from '@leafer/data';
|
|
3
3
|
import { LeafLayout } from '@leafer/layout';
|
|
4
4
|
|
|
@@ -12,19 +12,22 @@ declare class Leaf implements ILeaf {
|
|
|
12
12
|
get __LayoutProcessor(): typeof LeafLayout;
|
|
13
13
|
leafer?: ILeaferBase;
|
|
14
14
|
parent?: ILeaf;
|
|
15
|
-
isLeafer: boolean;
|
|
16
|
-
isBranch: boolean;
|
|
17
|
-
isBranchLeaf: boolean;
|
|
15
|
+
get isLeafer(): boolean;
|
|
16
|
+
get isBranch(): boolean;
|
|
17
|
+
get isBranchLeaf(): boolean;
|
|
18
18
|
__: ILeafData;
|
|
19
19
|
__layout: ILeafLayout;
|
|
20
|
-
__world:
|
|
20
|
+
__world: IMatrixWithBoundsScaleData;
|
|
21
21
|
__local?: IMatrixWithBoundsData;
|
|
22
|
+
__nowWorld?: IMatrixWithBoundsScaleData;
|
|
23
|
+
__cameraWorld?: IMatrixWithBoundsScaleData;
|
|
22
24
|
get __localMatrix(): IMatrixData;
|
|
23
|
-
get
|
|
25
|
+
get __localBoxBounds(): IBoundsData;
|
|
24
26
|
__worldOpacity: number;
|
|
25
|
-
get worldTransform():
|
|
26
|
-
get localTransform():
|
|
27
|
+
get worldTransform(): IMatrixWithScaleData;
|
|
28
|
+
get localTransform(): IMatrixData;
|
|
27
29
|
get boxBounds(): IBoundsData;
|
|
30
|
+
get renderBounds(): IBoundsData;
|
|
28
31
|
get worldBoxBounds(): IBoundsData;
|
|
29
32
|
get worldStrokeBounds(): IBoundsData;
|
|
30
33
|
get worldRenderBounds(): IBoundsData;
|
|
@@ -38,6 +41,8 @@ declare class Leaf implements ILeaf {
|
|
|
38
41
|
__hitCanvas?: IHitCanvas;
|
|
39
42
|
get __onlyHitMask(): boolean;
|
|
40
43
|
get __ignoreHitWorld(): boolean;
|
|
44
|
+
get __inLazyBounds(): boolean;
|
|
45
|
+
get pathInputed(): boolean;
|
|
41
46
|
__captureMap?: IEventListenerMap;
|
|
42
47
|
__bubbleMap?: IEventListenerMap;
|
|
43
48
|
__parentWait?: IFunction[];
|
|
@@ -48,22 +53,33 @@ declare class Leaf implements ILeaf {
|
|
|
48
53
|
constructor(data?: ILeafInputData);
|
|
49
54
|
reset(data?: ILeafInputData): void;
|
|
50
55
|
resetCustom(): void;
|
|
51
|
-
waitParent(item: IFunction): void;
|
|
52
|
-
waitLeafer(item: IFunction): void;
|
|
53
|
-
nextRender(item: IFunction): void;
|
|
56
|
+
waitParent(item: IFunction, bind?: IObject): void;
|
|
57
|
+
waitLeafer(item: IFunction, bind?: IObject): void;
|
|
58
|
+
nextRender(item: IFunction, bind?: IObject, off?: 'off'): void;
|
|
59
|
+
removeNextRender(item: IFunction): void;
|
|
54
60
|
__bindLeafer(leafer: ILeaferBase | null): void;
|
|
55
61
|
set(_data: IObject): void;
|
|
56
|
-
get(): ILeafInputData;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
get(_name?: string): ILeafInputData | IValue;
|
|
63
|
+
setAttr(name: string, value: any): void;
|
|
64
|
+
getAttr(name: string): any;
|
|
65
|
+
getComputedAttr(name: string): any;
|
|
66
|
+
toJSON(options?: IJSONOptions): IObject;
|
|
67
|
+
toString(options?: IJSONOptions): string;
|
|
68
|
+
toSVG(): string;
|
|
69
|
+
__SVG(_data: IObject): void;
|
|
70
|
+
toHTML(): string;
|
|
71
|
+
__setAttr(_attrName: string, _newValue: IValue): boolean;
|
|
60
72
|
__getAttr(_attrName: string): IValue;
|
|
61
73
|
setProxyAttr(_attrName: string, _newValue: IValue): void;
|
|
62
74
|
getProxyAttr(_attrName: string): IValue;
|
|
63
75
|
find(_condition: number | string | IFindMethod, _options?: any): ILeaf[];
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
findTag(_tag: string | string[]): ILeaf[];
|
|
77
|
+
findOne(_condition: number | string | IFindMethod, _options?: any): ILeaf | undefined;
|
|
78
|
+
findId(_id: number | string): ILeaf | undefined;
|
|
79
|
+
focus(_value?: boolean): void;
|
|
66
80
|
updateLayout(): void;
|
|
81
|
+
forceUpdate(attrName?: string): void;
|
|
82
|
+
forceRender(_bounds?: IBoundsData): void;
|
|
67
83
|
__updateWorldMatrix(): void;
|
|
68
84
|
__updateLocalMatrix(): void;
|
|
69
85
|
__updateWorldBounds(): void;
|
|
@@ -72,21 +88,25 @@ declare class Leaf implements ILeaf {
|
|
|
72
88
|
__updateLocalStrokeBounds(): void;
|
|
73
89
|
__updateLocalRenderBounds(): void;
|
|
74
90
|
__updateBoxBounds(): void;
|
|
91
|
+
__updateContentBounds(): void;
|
|
75
92
|
__updateStrokeBounds(): void;
|
|
76
93
|
__updateRenderBounds(): void;
|
|
77
94
|
__updateAutoLayout(): void;
|
|
95
|
+
__updateFlowLayout(): void;
|
|
78
96
|
__updateNaturalSize(): void;
|
|
79
97
|
__updateStrokeSpread(): number;
|
|
80
98
|
__updateRenderSpread(): number;
|
|
81
99
|
__onUpdateSize(): void;
|
|
82
|
-
__updateEraser(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
100
|
+
__updateEraser(value?: boolean): void;
|
|
101
|
+
__renderEraser(canvas: ILeaferCanvas, options: IRenderOptions): void;
|
|
102
|
+
__updateMask(value?: boolean): void;
|
|
103
|
+
__renderMask(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
|
|
104
|
+
__getNowWorld(options: IRenderOptions): IMatrixWithBoundsScaleData;
|
|
105
|
+
getTransform(relative?: ILocationType | ILeaf): IMatrixData;
|
|
87
106
|
getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData;
|
|
88
107
|
getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData;
|
|
89
108
|
getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[];
|
|
109
|
+
getWorldBounds(inner: IBoundsData, relative?: ILeaf, change?: boolean): IBoundsData;
|
|
90
110
|
worldToLocal(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
|
|
91
111
|
localToWorld(local: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
|
|
92
112
|
worldToInner(world: IPointData, to?: IPointData, distance?: boolean, relative?: ILeaf): void;
|
|
@@ -97,22 +117,35 @@ declare class Leaf implements ILeaf {
|
|
|
97
117
|
getLocalPointByInner(inner: IPointData, _relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
|
|
98
118
|
getWorldPoint(inner: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
|
|
99
119
|
getWorldPointByLocal(local: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
|
|
120
|
+
getPagePoint(world: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
|
|
121
|
+
getWorldPointByPage(page: IPointData, relative?: ILeaf, distance?: boolean, change?: boolean): IPointData;
|
|
100
122
|
setTransform(matrix: IMatrixData, resize?: boolean): void;
|
|
101
123
|
transform(matrix: IMatrixData, resize?: boolean): void;
|
|
102
|
-
move(x: number, y?: number): void;
|
|
103
|
-
scaleOf(origin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
|
|
104
|
-
rotateOf(origin: IPointData, rotation: number): void;
|
|
105
|
-
skewOf(origin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
|
|
106
|
-
|
|
107
|
-
|
|
124
|
+
move(x: number | IPointData, y?: number): void;
|
|
125
|
+
scaleOf(origin: IPointData | IAlign, scaleX: number, scaleY?: number, resize?: boolean): void;
|
|
126
|
+
rotateOf(origin: IPointData | IAlign, rotation: number): void;
|
|
127
|
+
skewOf(origin: IPointData | IAlign, skewX: number, skewY?: number, resize?: boolean): void;
|
|
128
|
+
transformWorld(worldTransform?: IMatrixData, resize?: boolean): void;
|
|
129
|
+
moveWorld(x: number | IPointData, y?: number): void;
|
|
130
|
+
scaleOfWorld(worldOrigin: IPointData, scaleX: number, scaleY?: number, resize?: boolean): void;
|
|
131
|
+
rotateOfWorld(worldOrigin: IPointData, rotation: number): void;
|
|
132
|
+
skewOfWorld(worldOrigin: IPointData, skewX: number, skewY?: number, resize?: boolean): void;
|
|
133
|
+
scaleResize(scaleX: number, scaleY?: number, _noResize?: boolean): void;
|
|
134
|
+
__scaleResize(_scaleX: number, _scaleY: number): void;
|
|
135
|
+
resizeWidth(_width: number): void;
|
|
136
|
+
resizeHeight(_height: number): void;
|
|
108
137
|
__hitWorld(_point: IRadiusPointData): boolean;
|
|
109
138
|
__hit(_local: IRadiusPointData): boolean;
|
|
139
|
+
__hitFill(_inner: IRadiusPointData): boolean;
|
|
140
|
+
__hitStroke(_inner: IRadiusPointData, _strokeWidth: number): boolean;
|
|
141
|
+
__hitPixel(_inner: IRadiusPointData): boolean;
|
|
110
142
|
__drawHitPath(_canvas: ILeaferCanvas): void;
|
|
111
143
|
__updateHitCanvas(): void;
|
|
112
144
|
__render(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
|
|
113
145
|
__drawFast(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
|
|
114
146
|
__draw(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
|
|
115
|
-
|
|
147
|
+
__clip(_canvas: ILeaferCanvas, _options: IRenderOptions): void;
|
|
148
|
+
__renderShape(_canvas: ILeaferCanvas, _options: IRenderOptions, _ignoreFill?: boolean, _ignoreStroke?: boolean): void;
|
|
116
149
|
__updateWorldOpacity(): void;
|
|
117
150
|
__updateChange(): void;
|
|
118
151
|
__drawPath(_canvas: ILeaferCanvas): void;
|
|
@@ -124,20 +157,19 @@ declare class Leaf implements ILeaf {
|
|
|
124
157
|
remove(_child?: ILeaf, destroy?: boolean): void;
|
|
125
158
|
dropTo(parent: ILeaf, index?: number, resize?: boolean): void;
|
|
126
159
|
on(_type: string | string[], _listener: IEventListener, _options?: IEventListenerOptions | boolean): void;
|
|
127
|
-
off(_type
|
|
160
|
+
off(_type?: string | string[], _listener?: IEventListener, _options?: IEventListenerOptions | boolean): void;
|
|
128
161
|
on_(_type: string | string[], _listener: IEventListener, _bind?: IObject, _options?: IEventListenerOptions | boolean): IEventListenerId;
|
|
129
162
|
off_(_id: IEventListenerId | IEventListenerId[]): void;
|
|
130
163
|
once(_type: string | string[], _listener: IEventListener, _capture?: boolean): void;
|
|
131
164
|
emit(_type: string, _event?: IEvent | IObject, _capture?: boolean): void;
|
|
132
165
|
emitEvent(_event?: IEvent, _capture?: boolean): void;
|
|
133
166
|
hasEvent(_type: string, _capture?: boolean): boolean;
|
|
134
|
-
static changeAttr(attrName: string, defaultValue: IValue): void;
|
|
167
|
+
static changeAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void;
|
|
135
168
|
static addAttr(attrName: string, defaultValue: IValue, fn?: IAttrDecorator): void;
|
|
136
169
|
destroy(): void;
|
|
137
170
|
}
|
|
138
171
|
|
|
139
172
|
declare class Branch extends Leaf {
|
|
140
|
-
constructor();
|
|
141
173
|
__updateStrokeSpread(): number;
|
|
142
174
|
__updateRenderSpread(): number;
|
|
143
175
|
__updateBoxBounds(): void;
|
|
@@ -146,8 +178,9 @@ declare class Branch extends Leaf {
|
|
|
146
178
|
__updateSortChildren(): void;
|
|
147
179
|
add(child: ILeaf, index?: number): void;
|
|
148
180
|
addMany(...children: ILeaf[]): void;
|
|
149
|
-
remove(child?:
|
|
181
|
+
remove(child?: ILeaf, destroy?: boolean): void;
|
|
150
182
|
removeAll(destroy?: boolean): void;
|
|
183
|
+
clear(): void;
|
|
151
184
|
protected __preRemove(): void;
|
|
152
185
|
protected __realRemoveChild(child: ILeaf): void;
|
|
153
186
|
protected __emitChildEvent(type: string, child: ILeaf): void;
|