@leafer-ui/display 1.0.0-rc.3 → 1.0.0-rc.30

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,123 +1,237 @@
1
- import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType, __Number, __Boolean, __String, IPathString, IExportFileType, IPointData, ICursorType, IAround } 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 } 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, IPaint, IStrokeAlign, IStrokeJoin, IStrokeCap, IBlendMode, IPaintString, IDashPatternString, IShadowString, IGrayscaleEffect, IUIData, IGroup, IStrokeWidthString, ICornerRadiusString, IUIInputData, IUIBaseInputData, IExportOptions, IExportResult } 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
 
21
+ declare public proxyData?: IUIInputData // need rewrite getter
22
+ declare public __proxyData?: IUIInputData
23
+
24
+ public get app(): ILeafer { return this.leafer && this.leafer.app }
25
+
26
+ declare public leafer?: ILeafer
22
27
  declare public parent?: IGroup
23
28
 
29
+ @zoomLayerType()
30
+ public zoomLayer: IGroup
31
+
32
+ public get isFrame(): boolean { return false }
33
+
34
+ declare public children?: IUI[]
35
+
24
36
  // ---
25
37
 
26
38
  // id
27
39
  @dataType('')
28
- public id: __String
40
+ public id?: IString
29
41
 
30
42
  @dataType('')
31
- public name: __String
43
+ public name?: IString
32
44
 
33
45
  @dataType('')
34
- public className: __String
46
+ public className?: IString
35
47
 
36
48
 
37
49
  // layer
38
50
  @surfaceType('pass-through')
39
- public blendMode: IBlendMode
51
+ public blendMode?: IBlendMode
40
52
 
41
53
  @opacityType(1)
42
- public opacity: __Number
54
+ public opacity?: INumber
43
55
 
44
- @opacityType(true)
45
- public visible: __Boolean
56
+ @visibleType(true)
57
+ public visible?: IBoolean | 0
46
58
 
47
- @maskType(false)
48
- public isMask: __Boolean
49
59
 
50
- @eraserType(false)
51
- public isEraser?: __Boolean
60
+ @stateType(false)
61
+ public selected?: IBoolean
62
+
63
+ @stateType(false)
64
+ public disabled?: IBoolean
65
+
66
+ @surfaceType(false)
67
+ public locked?: IBoolean
68
+
52
69
 
53
70
  @sortType(0)
54
- public zIndex: __Number
71
+ public zIndex?: INumber
55
72
 
56
- @dataType()
57
- public locked: __Boolean
73
+
74
+ @maskType(false)
75
+ public mask?: IBoolean | IMaskType
76
+
77
+ @eraserType(false)
78
+ public eraser?: IBoolean | IEraserType
58
79
 
59
80
 
60
81
  // position
61
- @positionType(0)
62
- public x: __Number
82
+ @positionType(0, true)
83
+ public x?: INumber
63
84
 
64
- @positionType(0)
65
- public y: __Number
85
+ @positionType(0, true)
86
+ public y?: INumber
66
87
 
67
88
  // size
68
- @boundsType(100)
69
- public width: __Number
89
+ @boundsType(100, true)
90
+ public width?: INumber
70
91
 
71
- @boundsType(100)
72
- public height: __Number
92
+ @boundsType(100, true)
93
+ public height?: INumber
73
94
 
74
95
  // scale
75
- @scaleType(1)
76
- public scaleX: __Number
96
+ @scaleType(1, true)
97
+ public scaleX?: INumber
77
98
 
78
- @scaleType(1)
79
- public scaleY: __Number
99
+ @scaleType(1, true)
100
+ public scaleY?: INumber
80
101
 
81
102
  // rotate
82
- @rotationType(0)
83
- public rotation: __Number
103
+ @rotationType(0, true)
104
+ public rotation?: INumber
84
105
 
85
106
  // skew
86
- @rotationType(0)
87
- public skewX: __Number
107
+ @rotationType(0, true)
108
+ public skewX?: INumber
88
109
 
89
- @rotationType(0)
90
- public skewY: __Number
110
+ @rotationType(0, true)
111
+ public skewY?: INumber
91
112
 
92
113
 
93
- @positionType()
94
- public around: IAround
114
+ // offset
115
+ @positionType(0, true)
116
+ public offsetX?: INumber
95
117
 
118
+ @positionType(0, true)
119
+ public offsetY?: INumber
96
120
 
121
+ // scroll
122
+ @positionType(0, true)
123
+ public scrollX?: INumber
124
+
125
+ @positionType(0, true)
126
+ public scrollY?: INumber
127
+
128
+
129
+ // center
130
+ @autoLayoutType()
131
+ public origin?: IAlign | IUnitPointData
132
+
133
+ @autoLayoutType()
134
+ public around?: IAlign | IUnitPointData
135
+
136
+
137
+ // image
97
138
  @dataType(false)
98
- public draggable: __Boolean
139
+ public lazy?: IBoolean // load image / compute paint
140
+
141
+ @naturalBoundsType(1)
142
+ public pixelRatio?: INumber
143
+
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
200
+ @dataType(false)
201
+ public draggable?: IBoolean | IAxis
202
+
203
+ @dataType()
204
+ public dragBounds?: IBoundsData | 'parent'
205
+
206
+
207
+ @dataType(false)
208
+ public editable?: IBoolean
209
+
99
210
 
100
211
  // hit
101
212
  @hitType(true)
102
- public hittable: __Boolean
213
+ public hittable?: IBoolean
103
214
 
104
215
  @hitType('path')
105
- public hitFill: IHitType
216
+ public hitFill?: IHitType
106
217
 
107
218
  @strokeType('path')
108
- public hitStroke: IHitType
219
+ public hitStroke?: IHitType
220
+
221
+ @hitType(false)
222
+ public hitBox?: IBoolean
109
223
 
110
224
  @hitType(true)
111
- public hitChildren: __Boolean
225
+ public hitChildren?: IBoolean
112
226
 
113
227
  @hitType(true)
114
- public hitSelf: __Boolean
228
+ public hitSelf?: IBoolean
115
229
 
116
230
  @hitType()
117
- public hitRadius: __Number
231
+ public hitRadius?: INumber
118
232
 
119
- @cursorType('default')
120
- public cursor: ICursorType | ICursorType[]
233
+ @cursorType('')
234
+ public cursor?: ICursorType | ICursorType[]
121
235
 
122
236
  // ---
123
237
 
@@ -125,62 +239,99 @@ export class UI extends Leaf implements IUI {
125
239
  // fill
126
240
 
127
241
  @surfaceType()
128
- public fill: IPaint | IPaint[] | IPaintString
242
+ public fill?: IFill
129
243
 
130
244
  // stroke
131
245
 
132
246
  @strokeType()
133
- public stroke: IPaint | IPaint[] | IPaintString
247
+ public stroke?: IStroke
134
248
 
135
249
  @strokeType('inside')
136
- public strokeAlign: IStrokeAlign
250
+ public strokeAlign?: IStrokeAlign
137
251
 
138
252
  @strokeType(1)
139
- public strokeWidth: number | number[] | IStrokeWidthString
253
+ public strokeWidth?: IFourNumber | IStrokeWidthString
254
+
255
+ @strokeType(false)
256
+ public strokeWidthFixed?: IBoolean
140
257
 
141
258
  @strokeType('none')
142
- public strokeCap: IStrokeCap
259
+ public strokeCap?: IStrokeCap
143
260
 
144
261
  @strokeType('miter')
145
- public strokeJoin: IStrokeJoin
262
+ public strokeJoin?: IStrokeJoin
146
263
 
147
264
  @strokeType()
148
- public dashPattern: __Number[] | IDashPatternString
265
+ public dashPattern?: INumber[] | IDashPatternString
149
266
 
150
267
  @strokeType()
151
- public dashOffset: __Number
268
+ public dashOffset?: INumber
152
269
 
153
270
  @strokeType(10)
154
- public miterLimit: __Number
271
+ public miterLimit?: INumber
272
+
273
+
274
+ // arrow
275
+
276
+ @arrowType('none')
277
+ public startArrow?: IArrowType
155
278
 
279
+ @arrowType('none')
280
+ public endArrow?: IArrowType
156
281
 
157
282
  // corner
158
283
 
159
- @pathType()
160
- public cornerRadius: number | number[] | ICornerRadiusString
284
+ @pathType(0)
285
+ public cornerRadius?: IFourNumber | ICornerRadiusString
161
286
 
162
287
  @pathType()
163
- public cornerSmoothing: __Number
288
+ public cornerSmoothing?: INumber
164
289
 
165
290
  // effect
166
291
 
167
292
  @effectType()
168
- public shadow: IShadowEffect | IShadowEffect[] | IShadowString
293
+ public shadow?: IShadowEffect | IShadowEffect[] | IShadowString
169
294
 
170
295
  @effectType()
171
- public innerShadow: IShadowEffect | IShadowEffect[] | IShadowString
296
+ public innerShadow?: IShadowEffect | IShadowEffect[] | IShadowString
172
297
 
173
298
  @effectType()
174
- public blur: __Number | IBlurEffect
299
+ public blur?: INumber | IBlurEffect
175
300
 
176
301
  @effectType()
177
- public backgroundBlur: __Number | IBlurEffect
302
+ public backgroundBlur?: INumber | IBlurEffect
178
303
 
179
304
  @effectType()
180
- public grayscale: __Number | 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
+
181
328
 
329
+ // 预留给用户使用的数据对象
330
+ @dataType({})
331
+ public data: IObject
182
332
 
183
- public set scale(value: __Number | IPointData) {
333
+
334
+ public set scale(value: INumber | IPointData) {
184
335
  if (typeof value === 'number') {
185
336
  this.scaleX = this.scaleY = value
186
337
  } else {
@@ -189,49 +340,91 @@ export class UI extends Leaf implements IUI {
189
340
  }
190
341
  }
191
342
 
192
- public get scale(): __Number | IPointData {
343
+ public get scale(): INumber | IPointData {
193
344
  const { scaleX, scaleY } = this
194
345
  return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX
195
346
  }
196
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 }
197
359
 
198
- constructor(data?: IUIBaseInputData) {
360
+ public get editOuter(): string { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool' }
361
+
362
+ public get editInner(): string { return 'PathEditor' }
363
+
364
+
365
+ constructor(data?: IUIInputData) {
199
366
  super(data)
200
367
  }
201
368
 
202
369
 
370
+ // data
371
+
372
+ @rewrite(Leaf.prototype.reset)
373
+ public reset(_data?: IUIInputData): void { }
374
+
375
+
203
376
  public set(data: IUIInputData): void {
204
377
  Object.assign(this, data)
205
378
  }
206
379
 
207
- public get(): IUIInputData {
208
- return this.__.__getInputData()
380
+ public get(name?: string | string[] | IUIInputData): IUIInputData | IValue {
381
+ return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name)
209
382
  }
210
383
 
384
+ public createProxyData(): IUIInputData { return undefined }
385
+
211
386
 
212
- public getPath(curve?: boolean): IPathCommandData {
213
- const path = this.__.path
214
- if (!path) return []
387
+ // hit rewrite
388
+
389
+ public find(_condition: number | string | IFindCondition | IFindUIMethod, _options?: any): IUI[] { return undefined }
390
+
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 }) }
396
+
397
+
398
+ // path
399
+
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)
215
404
  return curve ? PathConvert.toCanvasData(path, true) : path
216
405
  }
217
406
 
218
- public getPathString(curve?: boolean): IPathString {
219
- return PathConvert.stringify(this.getPath(curve))
407
+ public getPathString(curve?: boolean, pathForRender?: boolean): IPathString {
408
+ return PathConvert.stringify(this.getPath(curve, pathForRender))
220
409
  }
221
410
 
222
411
 
412
+ public load(): void {
413
+ this.__.__computePaint() // 手动加载图片
414
+ }
415
+
223
416
  public __onUpdateSize(): void {
224
417
  if (this.__.__input) {
225
- const { fill, stroke } = this.__.__input
226
- if (fill) Paint.compute(this, 'fill')
227
- if (stroke) Paint.compute(this, 'stroke')
418
+ const data = this.__;
419
+ (data.lazy && !this.__inLazyBounds && !Export.running) ? data.__needComputePaint = true : data.__computePaint()
228
420
  }
229
421
  }
230
422
 
231
423
  public __updateRenderPath(): void {
232
424
  if (this.__.path) {
233
- const { __: data } = this
425
+ const data = this.__
234
426
  data.__pathForRender = data.cornerRadius ? PathCorner.smooth(data.path, data.cornerRadius, data.cornerSmoothing) : data.path
427
+ if (data.__useArrow) PathArrow.addArrows(this, !data.cornerRadius)
235
428
  }
236
429
  }
237
430
 
@@ -245,8 +438,26 @@ export class UI extends Leaf implements IUI {
245
438
  this.__drawPathByData(canvas, this.__.path)
246
439
  }
247
440
 
248
- @rewrite(PathDrawer.drawPathByData)
249
- 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
+ }
448
+
449
+ public __drawPathByBox(drawer: IPathDrawer): void {
450
+ const { x, y, width, height } = this.__layout.boxBounds
451
+ if (this.__.cornerRadius) {
452
+ const { cornerRadius } = this.__
453
+ drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius) // 修复微信浏览器bug, 后续需进一步优化
454
+ } else {
455
+ drawer.rect(x, y, width, height)
456
+ }
457
+ }
458
+
459
+
460
+ // create
250
461
 
251
462
  public export(filename: IExportFileType | string, options?: IExportOptions | number | boolean): Promise<IExportResult> {
252
463
  return Export.export(this, filename, options)
@@ -260,6 +471,24 @@ export class UI extends Leaf implements IUI {
260
471
  return UICreator.get(data.tag || this.prototype.__tag, data, x, y, width, height) as IUI
261
472
  }
262
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
+
491
+
263
492
  public destroy(): void {
264
493
  this.fill = this.stroke = null
265
494
  super.destroy()
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'