@leafer-ui/display 1.0.0-rc.8 → 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/src/UI.ts CHANGED
@@ -1,25 +1,24 @@
1
- import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType, INumber, IBoolean, IString, IPathString, IExportFileType, IPointData, ICursorType, IAround, IFindMethod } from '@leafer/interface'
2
- import { Leaf, PathDrawer, surfaceType, dataType, positionType, boundsType, pathType, scaleType, rotationType, opacityType, sortType, maskType, dataProcessor, useModule, rewrite, rewriteAble, UICreator, PathCorner, hitType, strokeType, PathConvert, eraserType, cursorType, autoLayoutType } 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 } 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 } 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, IFindUIMethod, IEditSize, ILeafer } from '@leafer-ui/interface'
5
- import { effectType } from '@leafer-ui/decorator'
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
+ import { arrowType, effectType, stateType, zoomLayerType } from '@leafer-ui/decorator'
6
6
 
7
7
  import { UIData } from '@leafer-ui/data'
8
- import { UIBounds, UIHit, UIRender } from '@leafer-ui/display-module'
8
+ import { UIBounds, UIRender } from '@leafer-ui/display-module'
9
9
 
10
- import { Export, Paint } from '@leafer-ui/external'
10
+ import { Export, PathArrow } from '@leafer-ui/external'
11
11
 
12
12
 
13
13
  @useModule(UIBounds)
14
- @useModule(UIHit)
15
14
  @useModule(UIRender)
16
15
  @rewriteAble()
17
- export class UI extends Leaf implements IUI {
16
+ export class UI extends Leaf implements IUI { // tip: rewrited Box
18
17
 
19
18
  @dataProcessor(UIData)
20
19
  declare public __: IUIData
21
20
 
22
- declare public proxyData: IUIInputData // need rewrite getter
21
+ declare public proxyData?: IUIInputData // need rewrite getter
23
22
  declare public __proxyData?: IUIInputData
24
23
 
25
24
  public get app(): ILeafer { return this.leafer && this.leafer.app }
@@ -27,7 +26,10 @@ export class UI extends Leaf implements IUI {
27
26
  declare public leafer?: ILeafer
28
27
  declare public parent?: IGroup
29
28
 
30
- public isFrame?: boolean
29
+ @zoomLayerType()
30
+ public zoomLayer: IGroup
31
+
32
+ public get isFrame(): boolean { return false }
31
33
 
32
34
  declare public children?: IUI[]
33
35
 
@@ -35,110 +37,201 @@ export class UI extends Leaf implements IUI {
35
37
 
36
38
  // id
37
39
  @dataType('')
38
- public id: IString
40
+ public id?: IString
39
41
 
40
42
  @dataType('')
41
- public name: IString
43
+ public name?: IString
42
44
 
43
45
  @dataType('')
44
- public className: IString
46
+ public className?: IString
45
47
 
46
48
 
47
49
  // layer
48
50
  @surfaceType('pass-through')
49
- public blendMode: IBlendMode
51
+ public blendMode?: IBlendMode
50
52
 
51
53
  @opacityType(1)
52
- public opacity: INumber
54
+ public opacity?: INumber
53
55
 
54
- @opacityType(true)
55
- public visible: IBoolean
56
+ @visibleType(true)
57
+ public visible?: IBoolean | 0
56
58
 
57
- @maskType(false)
58
- public isMask: IBoolean
59
59
 
60
- @eraserType(false)
61
- public isEraser?: IBoolean
60
+ @stateType(false)
61
+ public selected?: IBoolean
62
+
63
+ @stateType(false)
64
+ public disabled?: IBoolean
65
+
66
+ @surfaceType(false)
67
+ public locked?: IBoolean
62
68
 
63
- @dataType(false)
64
- public locked: IBoolean
65
69
 
66
70
  @sortType(0)
67
- public zIndex: INumber
71
+ public zIndex?: INumber
72
+
73
+
74
+ @maskType(false)
75
+ public mask?: IBoolean | IMaskType
76
+
77
+ @eraserType(false)
78
+ public eraser?: IBoolean | IEraserType
68
79
 
69
80
 
70
81
  // position
71
- @positionType(0)
72
- public x: INumber
82
+ @positionType(0, true)
83
+ public x?: INumber
73
84
 
74
- @positionType(0)
75
- public y: INumber
85
+ @positionType(0, true)
86
+ public y?: INumber
76
87
 
77
88
  // size
78
- @boundsType(100)
79
- public width: INumber
89
+ @boundsType(100, true)
90
+ public width?: INumber
80
91
 
81
- @boundsType(100)
82
- public height: INumber
92
+ @boundsType(100, true)
93
+ public height?: INumber
83
94
 
84
95
  // scale
85
- @scaleType(1)
86
- public scaleX: INumber
96
+ @scaleType(1, true)
97
+ public scaleX?: INumber
87
98
 
88
- @scaleType(1)
89
- public scaleY: INumber
99
+ @scaleType(1, true)
100
+ public scaleY?: INumber
90
101
 
91
102
  // rotate
92
- @rotationType(0)
93
- public rotation: INumber
103
+ @rotationType(0, true)
104
+ public rotation?: INumber
94
105
 
95
106
  // skew
96
- @rotationType(0)
97
- public skewX: INumber
107
+ @rotationType(0, true)
108
+ public skewX?: INumber
98
109
 
99
- @rotationType(0)
100
- public skewY: INumber
110
+ @rotationType(0, true)
111
+ public skewY?: INumber
101
112
 
102
113
 
114
+ // offset
115
+ @positionType(0, true)
116
+ public offsetX?: INumber
117
+
118
+ @positionType(0, true)
119
+ public offsetY?: INumber
120
+
121
+ // scroll
122
+ @positionType(0, true)
123
+ public scrollX?: INumber
124
+
125
+ @positionType(0, true)
126
+ public scrollY?: INumber
127
+
128
+
129
+ // center
103
130
  @autoLayoutType()
104
- public around: IAround
131
+ public origin?: IAlign | IUnitPointData
105
132
 
133
+ @autoLayoutType()
134
+ public around?: IAlign | IUnitPointData
106
135
 
136
+
137
+ // image
107
138
  @dataType(false)
108
- public draggable: IBoolean
139
+ public lazy?: IBoolean // load image / compute paint
140
+
141
+ @naturalBoundsType(1)
142
+ public pixelRatio?: INumber
109
143
 
110
144
 
145
+ // path
146
+ @pathInputType()
147
+ public path?: IPathCommandData | IPathString
148
+
149
+ @pathType()
150
+ public windingRule?: IWindingRule
151
+
152
+ @pathType(true)
153
+ public closed?: boolean
154
+
155
+
156
+ // auto layout
157
+ @autoLayoutType(false)
158
+ public flow?: IFlowType
159
+
160
+ @boundsType(0)
161
+ public padding?: IFourNumber
162
+
163
+ @boundsType(0)
164
+ public gap?: IGap | IPointGap
165
+
166
+ @boundsType('top-left')
167
+ public flowAlign?: IFlowAlign | IFlowAxisAlign
168
+
169
+ @boundsType(false)
170
+ public flowWrap?: IFlowWrap
171
+
172
+ @boundsType('box')
173
+ public itemBox?: IFlowBoxType
174
+
175
+
176
+ @boundsType(true)
177
+ public inFlow?: IBoolean
178
+
179
+ @boundsType() // rewrite in flow
180
+ public autoWidth?: IAutoSize
181
+
182
+ @boundsType() // rewrite in flow
183
+ public autoHeight?: IAutoSize
184
+
185
+ @boundsType()
186
+ public lockRatio?: IBoolean
187
+
188
+ @boundsType()
189
+ public autoBox?: IAutoBoxData | IConstraint
190
+
191
+
192
+ @boundsType()
193
+ public widthRange?: IRangeSize
194
+
195
+ @boundsType()
196
+ public heightRange?: IRangeSize
197
+
198
+
199
+ // drag
111
200
  @dataType(false)
112
- public editable: IBoolean
201
+ public draggable?: IBoolean | IAxis
113
202
 
114
- @dataType('size')
115
- public editSize?: IEditSize
203
+ @dataType()
204
+ public dragBounds?: IBoundsData | 'parent'
205
+
206
+
207
+ @dataType(false)
208
+ public editable?: IBoolean
116
209
 
117
210
 
118
211
  // hit
119
212
  @hitType(true)
120
- public hittable: IBoolean
213
+ public hittable?: IBoolean
121
214
 
122
215
  @hitType('path')
123
- public hitFill: IHitType
216
+ public hitFill?: IHitType
124
217
 
125
218
  @strokeType('path')
126
- public hitStroke: IHitType
219
+ public hitStroke?: IHitType
127
220
 
128
221
  @hitType(false)
129
- public hitBox: IBoolean
222
+ public hitBox?: IBoolean
130
223
 
131
224
  @hitType(true)
132
- public hitChildren: IBoolean
225
+ public hitChildren?: IBoolean
133
226
 
134
227
  @hitType(true)
135
- public hitSelf: IBoolean
228
+ public hitSelf?: IBoolean
136
229
 
137
230
  @hitType()
138
- public hitRadius: INumber
231
+ public hitRadius?: INumber
139
232
 
140
233
  @cursorType('')
141
- public cursor: ICursorType | ICursorType[]
234
+ public cursor?: ICursorType | ICursorType[]
142
235
 
143
236
  // ---
144
237
 
@@ -146,59 +239,96 @@ export class UI extends Leaf implements IUI {
146
239
  // fill
147
240
 
148
241
  @surfaceType()
149
- public fill: IFill
242
+ public fill?: IFill
150
243
 
151
244
  // stroke
152
245
 
153
246
  @strokeType()
154
- public stroke: IStroke
247
+ public stroke?: IStroke
155
248
 
156
249
  @strokeType('inside')
157
- public strokeAlign: IStrokeAlign
250
+ public strokeAlign?: IStrokeAlign
158
251
 
159
252
  @strokeType(1)
160
- public strokeWidth: number | number[] | IStrokeWidthString
253
+ public strokeWidth?: IFourNumber | IStrokeWidthString
254
+
255
+ @strokeType(false)
256
+ public strokeWidthFixed?: IBoolean
161
257
 
162
258
  @strokeType('none')
163
- public strokeCap: IStrokeCap
259
+ public strokeCap?: IStrokeCap
164
260
 
165
261
  @strokeType('miter')
166
- public strokeJoin: IStrokeJoin
262
+ public strokeJoin?: IStrokeJoin
167
263
 
168
264
  @strokeType()
169
- public dashPattern: INumber[] | IDashPatternString
265
+ public dashPattern?: INumber[] | IDashPatternString
170
266
 
171
267
  @strokeType()
172
- public dashOffset: INumber
268
+ public dashOffset?: INumber
173
269
 
174
270
  @strokeType(10)
175
- public miterLimit: INumber
271
+ public miterLimit?: INumber
272
+
176
273
 
274
+ // arrow
275
+
276
+ @arrowType('none')
277
+ public startArrow?: IArrowType
278
+
279
+ @arrowType('none')
280
+ public endArrow?: IArrowType
177
281
 
178
282
  // corner
179
283
 
180
284
  @pathType(0)
181
- public cornerRadius: number | number[] | ICornerRadiusString
285
+ public cornerRadius?: IFourNumber | ICornerRadiusString
182
286
 
183
287
  @pathType()
184
- public cornerSmoothing: INumber
288
+ public cornerSmoothing?: INumber
185
289
 
186
290
  // effect
187
291
 
188
292
  @effectType()
189
- public shadow: IShadowEffect | IShadowEffect[] | IShadowString
293
+ public shadow?: IShadowEffect | IShadowEffect[] | IShadowString
190
294
 
191
295
  @effectType()
192
- public innerShadow: IShadowEffect | IShadowEffect[] | IShadowString
296
+ public innerShadow?: IShadowEffect | IShadowEffect[] | IShadowString
193
297
 
194
298
  @effectType()
195
- public blur: INumber | IBlurEffect
299
+ public blur?: INumber | IBlurEffect
196
300
 
197
301
  @effectType()
198
- public backgroundBlur: INumber | IBlurEffect
302
+ public backgroundBlur?: INumber | IBlurEffect
199
303
 
200
304
  @effectType()
201
- public grayscale: INumber | IGrayscaleEffect
305
+ public grayscale?: INumber | IGrayscaleEffect
306
+
307
+
308
+ // states
309
+
310
+ @dataType()
311
+ public normalStyle?: IUIInputData // auto restore hover / press / focus / selected / disabled style
312
+
313
+ @dataType()
314
+ public hoverStyle?: IUIInputData
315
+
316
+ @dataType()
317
+ public pressStyle?: IUIInputData
318
+
319
+ @dataType()
320
+ public focusStyle?: IUIInputData
321
+
322
+ @dataType()
323
+ public selectedStyle?: IUIInputData
324
+
325
+ @dataType()
326
+ public disabledStyle?: IUIInputData
327
+
328
+
329
+ // 预留给用户使用的数据对象
330
+ @dataType({})
331
+ public data: IObject
202
332
 
203
333
 
204
334
  public set scale(value: INumber | IPointData) {
@@ -215,6 +345,22 @@ export class UI extends Leaf implements IUI {
215
345
  return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX
216
346
  }
217
347
 
348
+ public get pen(): IPathCreator {
349
+ const { path } = this.__
350
+ pen.set(this.path = path || [])
351
+ if (!path) this.__drawPathByBox(pen)
352
+ return pen
353
+ }
354
+
355
+
356
+ // editor
357
+
358
+ public get editConfig(): IEditorConfig { return undefined }
359
+
360
+ public get editOuter(): string { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool' }
361
+
362
+ public get editInner(): string { return 'PathEditor' }
363
+
218
364
 
219
365
  constructor(data?: IUIInputData) {
220
366
  super(data)
@@ -231,49 +377,54 @@ export class UI extends Leaf implements IUI {
231
377
  Object.assign(this, data)
232
378
  }
233
379
 
234
- public get(): IUIInputData {
235
- return this.__.__getInputData()
380
+ public get(name?: string | string[] | IUIInputData): IUIInputData | IValue {
381
+ return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name)
236
382
  }
237
383
 
238
384
  public createProxyData(): IUIInputData { return undefined }
239
385
 
240
386
 
241
- // find
387
+ // hit rewrite
242
388
 
243
- public find(condition: number | string | IFindUIMethod, options?: any): IUI[] {
244
- return this.leafer ? this.leafer.selector.getBy(condition as IFindMethod, this, false, options) as IUI[] : []
245
- }
389
+ public find(_condition: number | string | IFindCondition | IFindUIMethod, _options?: any): IUI[] { return undefined }
246
390
 
247
- public findOne(condition: number | string | IFindUIMethod, options?: any): IUI {
248
- return this.leafer ? this.leafer.selector.getBy(condition as IFindMethod, this, true, options) as IUI : null
249
- }
391
+ public findTag(tag: string | string[]): IUI[] { return this.find({ tag }) }
392
+
393
+ public findOne(_condition: number | string | IFindCondition | IFindUIMethod, _options?: any): IUI | undefined { return undefined }
394
+
395
+ public findId(id: number | string): IUI | undefined { return this.findOne({ id }) }
250
396
 
251
397
 
252
398
  // path
253
399
 
254
- public getPath(curve?: boolean): IPathCommandData {
255
- const { path } = this.__
256
- if (!path) return []
400
+ public getPath(curve?: boolean, pathForRender?: boolean): IPathCommandData {
401
+ this.__layout.update()
402
+ let path = pathForRender ? this.__.__pathForRender : this.__.path
403
+ if (!path) pen.set(path = []), this.__drawPathByBox(pen)
257
404
  return curve ? PathConvert.toCanvasData(path, true) : path
258
405
  }
259
406
 
260
- public getPathString(curve?: boolean): IPathString {
261
- return PathConvert.stringify(this.getPath(curve))
407
+ public getPathString(curve?: boolean, pathForRender?: boolean): IPathString {
408
+ return PathConvert.stringify(this.getPath(curve, pathForRender))
262
409
  }
263
410
 
264
411
 
412
+ public load(): void {
413
+ this.__.__computePaint() // 手动加载图片
414
+ }
415
+
265
416
  public __onUpdateSize(): void {
266
417
  if (this.__.__input) {
267
- const { fill, stroke } = this.__.__input
268
- if (fill) Paint.compute('fill', this)
269
- if (stroke) Paint.compute('stroke', this)
418
+ const data = this.__;
419
+ (data.lazy && !this.__inLazyBounds && !Export.running) ? data.__needComputePaint = true : data.__computePaint()
270
420
  }
271
421
  }
272
422
 
273
423
  public __updateRenderPath(): void {
274
424
  if (this.__.path) {
275
- const { __: data } = this
425
+ const data = this.__
276
426
  data.__pathForRender = data.cornerRadius ? PathCorner.smooth(data.path, data.cornerRadius, data.cornerSmoothing) : data.path
427
+ if (data.__useArrow) PathArrow.addArrows(this, !data.cornerRadius)
277
428
  }
278
429
  }
279
430
 
@@ -287,13 +438,19 @@ export class UI extends Leaf implements IUI {
287
438
  this.__drawPathByData(canvas, this.__.path)
288
439
  }
289
440
 
290
- @rewrite(PathDrawer.drawPathByData)
291
- public __drawPathByData(_drawer: IPathDrawer, _data: IPathCommandData): void { }
441
+ public __drawPathByData(drawer: IPathDrawer, data: IPathCommandData): void {
442
+ if (data) {
443
+ PathDrawer.drawPathByData(drawer, data)
444
+ } else {
445
+ this.__drawPathByBox(drawer)
446
+ }
447
+ }
292
448
 
293
449
  public __drawPathByBox(drawer: IPathDrawer): void {
294
450
  const { x, y, width, height } = this.__layout.boxBounds
295
451
  if (this.__.cornerRadius) {
296
- drawer.roundRect(x, y, width, height, this.__.cornerRadius)
452
+ const { cornerRadius } = this.__
453
+ drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius) // 修复微信浏览器bug, 后续需进一步优化
297
454
  } else {
298
455
  drawer.rect(x, y, width, height)
299
456
  }
@@ -314,6 +471,23 @@ export class UI extends Leaf implements IUI {
314
471
  return UICreator.get(data.tag || this.prototype.__tag, data, x, y, width, height) as IUI
315
472
  }
316
473
 
474
+ static registerUI(): void {
475
+ registerUI()(this)
476
+ }
477
+
478
+ static registerData(data: IUIData): void {
479
+ dataProcessor(data)(this.prototype)
480
+ }
481
+
482
+
483
+ // @leafer-in/editor rewrite
484
+
485
+ static setEditConfig(_config: IEditorConfig | IEditorConfigFunction): void { }
486
+
487
+ static setEditOuter(_toolName: string | IEditToolFunction): void { }
488
+
489
+ static setEditInner(_editorName: string | IEditToolFunction): void { }
490
+
317
491
 
318
492
  public destroy(): void {
319
493
  this.fill = this.stroke = null
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { UI } from './UI'
2
2
 
3
+ export { Leafer } from './Leafer'
3
4
  export { Group } from './Group'
4
5
  export { Box } from './Box'
5
6
  export { Frame } from './Frame'