@leafer-ui/display 1.0.0-rc.17 → 1.0.0-rc.18

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.17",
3
+ "version": "1.0.0-rc.18",
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.17",
26
- "@leafer-ui/data": "1.0.0-rc.17",
27
- "@leafer-ui/display-module": "1.0.0-rc.17",
28
- "@leafer-ui/decorator": "1.0.0-rc.17",
29
- "@leafer-ui/external": "1.0.0-rc.17"
25
+ "@leafer/core": "1.0.0-rc.18",
26
+ "@leafer-ui/data": "1.0.0-rc.18",
27
+ "@leafer-ui/display-module": "1.0.0-rc.18",
28
+ "@leafer-ui/decorator": "1.0.0-rc.18",
29
+ "@leafer-ui/external": "1.0.0-rc.18"
30
30
  },
31
31
  "devDependencies": {
32
- "@leafer/interface": "1.0.0-rc.17",
33
- "@leafer-ui/interface": "1.0.0-rc.17"
32
+ "@leafer/interface": "1.0.0-rc.18",
33
+ "@leafer-ui/interface": "1.0.0-rc.18"
34
34
  }
35
35
  }
package/src/Group.ts CHANGED
@@ -51,7 +51,7 @@ export class Group extends UI implements IGroup {
51
51
 
52
52
  let child: IUI
53
53
  children.forEach(childData => {
54
- child = UICreator.get(childData.tag, childData) as IUI
54
+ child = (childData as IUI).__ ? childData as IUI : UICreator.get(childData.tag, childData) as IUI
55
55
  this.add(child)
56
56
  })
57
57
 
package/src/Leafer.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { ILeaferCanvas, IRenderer, ILayouter, ISelector, IWatcher, IInteraction, ILeaferConfig, ICanvasManager, IHitCanvasManager, IAutoBounds, IScreenSizeData, IResizeEvent, ILeaf, IEventListenerId, ITimer, IValue, IObject, IControl, IPointData, ILeaferType, ICursorType, IBoundsData, INumber } 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 } from '@leafer/interface'
2
2
  import { AutoBounds, LayoutEvent, ResizeEvent, LeaferEvent, CanvasManager, ImageManager, DataHelper, Creator, Run, Debug, RenderEvent, registerUI, boundsType, canvasSizeAttrs, dataProcessor, WaitHelper, WatchEvent, Bounds } from '@leafer/core'
3
3
 
4
- import { ILeaferInputData, ILeaferData, IFunction, IUIInputData, ILeafer, IGroup, IApp, IEditorBase } from '@leafer-ui/interface'
4
+ import { ILeaferInputData, ILeaferData, IFunction, IUIInputData, ILeafer, IApp, IEditorBase } from '@leafer-ui/interface'
5
5
  import { LeaferData } from '@leafer-ui/data'
6
6
  import { Group } from './Group'
7
7
 
@@ -54,8 +54,6 @@ export class Leafer extends Group implements ILeafer {
54
54
  // plugin
55
55
  public editor: IEditorBase
56
56
 
57
- public zoomLayer: IGroup = this
58
-
59
57
  public userConfig: ILeaferConfig
60
58
  public config: ILeaferConfig = {
61
59
  type: 'design',
@@ -69,7 +67,6 @@ export class Leafer extends Group implements ILeafer {
69
67
  move: {
70
68
  holdSpaceKey: true,
71
69
  holdMiddleKey: true,
72
- dragOut: true,
73
70
  autoDistance: 2
74
71
  }
75
72
  }
@@ -236,10 +233,6 @@ export class Leafer extends Group implements ILeafer {
236
233
  this.__level = 1
237
234
  }
238
235
 
239
- public setZoomLayer(zoomLayer: ILeaf): void {
240
- this.zoomLayer = zoomLayer as IGroup
241
- }
242
-
243
236
  protected __checkAutoLayout(config: ILeaferConfig): void {
244
237
  if (!config.width || !config.height) {
245
238
  this.autoLayout = new AutoBounds(config)
@@ -327,15 +320,18 @@ export class Leafer extends Group implements ILeafer {
327
320
  }
328
321
  }
329
322
 
330
- public waitReady(item: IFunction): void {
323
+ public waitReady(item: IFunction, bind?: IObject): void {
324
+ if (bind) item = item.bind(bind)
331
325
  this.ready ? item() : this.__readyWait.push(item)
332
326
  }
333
327
 
334
- public waitViewReady(item: IFunction): void {
328
+ public waitViewReady(item: IFunction, bind?: IObject): void {
329
+ if (bind) item = item.bind(bind)
335
330
  this.viewReady ? item() : this.__viewReadyWait.push(item)
336
331
  }
337
332
 
338
- public waitViewCompleted(item: IFunction): void {
333
+ public waitViewCompleted(item: IFunction, bind?: IObject): void {
334
+ if (bind) item = item.bind(bind)
339
335
  this.__viewCompletedWait.push(item)
340
336
  if (this.viewCompleted) {
341
337
  this.__checkViewCompleted(false)
@@ -344,7 +340,8 @@ export class Leafer extends Group implements ILeafer {
344
340
  }
345
341
  }
346
342
 
347
- public nextRender(item: IFunction, off?: 'off'): void {
343
+ public nextRender(item: IFunction, bind?: IObject, off?: 'off'): void {
344
+ if (bind) item = item.bind(bind)
348
345
  const list = this.__nextRenderWait
349
346
  if (off) {
350
347
  for (let i = 0; i < list.length; i++) {
@@ -355,6 +352,16 @@ export class Leafer extends Group implements ILeafer {
355
352
  }
356
353
  }
357
354
 
355
+ // need view plugin
356
+ public zoom(_zoomType: IZoomType, _padding?: IFourNumber, _fixedScale?: boolean): IBoundsData { return undefined }
357
+
358
+ public validScale(changeScale: number): number {
359
+ const { scaleX } = this.zoomLayer.__, { min, max } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale)
360
+ if (absScale < min) changeScale = min / scaleX
361
+ else if (absScale > max) changeScale = max / scaleX
362
+ return changeScale
363
+ }
364
+
358
365
  protected __checkUpdateLayout(): void {
359
366
  this.__layout.update()
360
367
  }
package/src/UI.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType, INumber, IBoolean, IString, IPathString, IExportFileType, IPointData, ICursorType, IMaskType, IAround, IValue, IWindingRule } 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, PathCreator, naturalBoundsType, pathInputType } from '@leafer/core'
1
+ import { ILeaferCanvas, IPathDrawer, IPathCommandData, IHitType, INumber, IBoolean, IString, IPathString, IExportFileType, IPointData, ICursorType, IMaskType, IAround, IValue, IWindingRule, IPathCreator } 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'
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, IEditSize, ILeafer } from '@leafer-ui/interface'
5
- import { arrowType, effectType } from '@leafer-ui/decorator'
5
+ import { arrowType, effectType, stateType, zoomLayerType } from '@leafer-ui/decorator'
6
6
 
7
7
  import { UIData } from '@leafer-ui/data'
8
8
  import { UIBounds, UIRender } from '@leafer-ui/display-module'
@@ -10,6 +10,8 @@ import { UIBounds, UIRender } from '@leafer-ui/display-module'
10
10
  import { Export, PathArrow } from '@leafer-ui/external'
11
11
 
12
12
 
13
+
14
+
13
15
  @useModule(UIBounds)
14
16
  @useModule(UIRender)
15
17
  @rewriteAble()
@@ -26,6 +28,9 @@ export class UI extends Leaf implements IUI {
26
28
  declare public leafer?: ILeafer
27
29
  declare public parent?: IGroup
28
30
 
31
+ @zoomLayerType()
32
+ public zoomLayer: IGroup
33
+
29
34
  public get isFrame(): boolean { return false }
30
35
 
31
36
  declare public children?: IUI[]
@@ -53,9 +58,17 @@ export class UI extends Leaf implements IUI {
53
58
  @opacityType(true)
54
59
  public visible: IBoolean
55
60
 
61
+
62
+ @stateType(false)
63
+ public selected: IBoolean
64
+
65
+ @stateType(false)
66
+ public disabled: IBoolean
67
+
56
68
  @dataType(false)
57
69
  public locked: IBoolean
58
70
 
71
+
59
72
  @sortType(0)
60
73
  public zIndex: INumber
61
74
 
@@ -231,6 +244,27 @@ export class UI extends Leaf implements IUI {
231
244
  public grayscale: INumber | IGrayscaleEffect
232
245
 
233
246
 
247
+ // states
248
+
249
+ @dataType()
250
+ public normalStyle: IUIInputData // auto restore hover / press / focus / selected / disabled style
251
+
252
+ @dataType()
253
+ public hoverStyle: IUIInputData
254
+
255
+ @dataType()
256
+ public pressStyle: IUIInputData
257
+
258
+ @dataType()
259
+ public focusStyle: IUIInputData
260
+
261
+ @dataType()
262
+ public selectedStyle: IUIInputData
263
+
264
+ @dataType()
265
+ public disabledStyle: IUIInputData
266
+
267
+
234
268
  public set scale(value: INumber | IPointData) {
235
269
  if (typeof value === 'number') {
236
270
  this.scaleX = this.scaleY = value
@@ -246,6 +280,12 @@ export class UI extends Leaf implements IUI {
246
280
  }
247
281
 
248
282
 
283
+ public get pen(): IPathCreator {
284
+ pen.set(this.path = this.__.path || [])
285
+ return pen
286
+ }
287
+
288
+
249
289
  constructor(data?: IUIInputData) {
250
290
  super(data)
251
291
  }
@@ -261,8 +301,8 @@ export class UI extends Leaf implements IUI {
261
301
  Object.assign(this, data)
262
302
  }
263
303
 
264
- public get(name?: string): IUIInputData | IValue {
265
- return name ? this.__.__getInput(name) : this.__.__getInputData()
304
+ public get(name?: string | string[] | IUIInputData): IUIInputData | IValue {
305
+ return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name)
266
306
  }
267
307
 
268
308
  public createProxyData(): IUIInputData { return undefined }
@@ -281,9 +321,11 @@ export class UI extends Leaf implements IUI {
281
321
  this.__layout.update()
282
322
  let path = pathForRender ? this.__.__pathForRender : this.__.path
283
323
  if (!path) {
284
- path = []
285
324
  const { width, height } = this.boxBounds
286
- if (width || height) this.__drawPathByBox(new PathCreator(path))
325
+ if (width || height) {
326
+ pen.set(path = [])
327
+ this.__drawPathByBox(pen)
328
+ }
287
329
  }
288
330
  return curve ? PathConvert.toCanvasData(path, true) : path
289
331
  }
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IString, INumber, IBoolean, IMaskType, IAround, IHitType, ICursorType, IPathCommandData, IPathString, IWindingRule, IPointData, IValue, ILeaferCanvas, IPathDrawer, IExportFileType, IPickOptions, IPickResult, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaferConfig, IAutoBounds, IEventListenerId, ITimer, IControl, ILeaferType, IScreenSizeData, IBoundsData, IResizeEvent, ILeaf, IRenderOptions, ILeaferImage, ICanvasContext2D } from '@leafer/interface';
1
+ import { IString, INumber, IBoolean, IMaskType, IAround, IHitType, ICursorType, IPathCommandData, IPathString, IWindingRule, IPointData, IPathCreator, IValue, ILeaferCanvas, IPathDrawer, IExportFileType, IPickOptions, IPickResult, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaferConfig, IAutoBounds, IEventListenerId, ITimer, IControl, ILeaferType, IScreenSizeData, IBoundsData, IResizeEvent, IObject, IZoomType, IFourNumber, IRenderOptions, ILeaferImage, ICanvasContext2D } from '@leafer/interface';
2
2
  import { Leaf } from '@leafer/core';
3
3
  import { IUI, IUIData, IUIInputData, ILeafer, IGroup, IBlendMode, IEditSize, IFill, IStroke, IStrokeAlign, IStrokeWidthString, IStrokeCap, IStrokeJoin, IDashPatternString, IArrowType, ICornerRadiusString, IShadowEffect, IShadowString, IBlurEffect, IGrayscaleEffect, IFindUIMethod, IExportOptions, IExportResult, 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, IUnitData, ITextAlign, IVerticalAlign, ITextWrap, ITextDrawData, ITextInputData, IPath, IPathData, IPathInputData, IPen, IPenData, IPathCommandData as IPathCommandData$1, IPenInputData } from '@leafer-ui/interface';
4
4
 
@@ -9,6 +9,7 @@ declare class UI extends Leaf implements IUI {
9
9
  get app(): ILeafer;
10
10
  leafer?: ILeafer;
11
11
  parent?: IGroup;
12
+ zoomLayer: IGroup;
12
13
  get isFrame(): boolean;
13
14
  children?: IUI[];
14
15
  id: IString;
@@ -17,6 +18,8 @@ declare class UI extends Leaf implements IUI {
17
18
  blendMode: IBlendMode;
18
19
  opacity: INumber;
19
20
  visible: IBoolean;
21
+ selected: IBoolean;
22
+ disabled: IBoolean;
20
23
  locked: IBoolean;
21
24
  zIndex: INumber;
22
25
  mask: IBoolean;
@@ -66,12 +69,19 @@ declare class UI extends Leaf implements IUI {
66
69
  blur: INumber | IBlurEffect;
67
70
  backgroundBlur: INumber | IBlurEffect;
68
71
  grayscale: INumber | IGrayscaleEffect;
72
+ normalStyle: IUIInputData;
73
+ hoverStyle: IUIInputData;
74
+ pressStyle: IUIInputData;
75
+ focusStyle: IUIInputData;
76
+ selectedStyle: IUIInputData;
77
+ disabledStyle: IUIInputData;
69
78
  set scale(value: INumber | IPointData);
70
79
  get scale(): INumber | IPointData;
80
+ get pen(): IPathCreator;
71
81
  constructor(data?: IUIInputData);
72
82
  reset(_data?: IUIInputData): void;
73
83
  set(data: IUIInputData): void;
74
- get(name?: string): IUIInputData | IValue;
84
+ get(name?: string | string[] | IUIInputData): IUIInputData | IValue;
75
85
  createProxyData(): IUIInputData;
76
86
  find(_condition: number | string | IFindUIMethod, _options?: any): IUI[];
77
87
  findOne(_condition: number | string | IFindUIMethod, _options?: any): IUI;
@@ -138,7 +148,6 @@ declare class Leafer extends Group implements ILeafer {
138
148
  canvasManager: ICanvasManager;
139
149
  hitCanvasManager?: IHitCanvasManager;
140
150
  editor: IEditorBase;
141
- zoomLayer: IGroup;
142
151
  userConfig: ILeaferConfig;
143
152
  config: ILeaferConfig;
144
153
  autoLayout?: IAutoBounds;
@@ -169,7 +178,6 @@ declare class Leafer extends Group implements ILeafer {
169
178
  protected __setApp(): void;
170
179
  protected __bindApp(app: IApp): void;
171
180
  __setLeafer(leafer: ILeafer): void;
172
- setZoomLayer(zoomLayer: ILeaf): void;
173
181
  protected __checkAutoLayout(config: ILeaferConfig): void;
174
182
  __setAttr(attrName: string, newValue: IValue): void;
175
183
  __getAttr(attrName: string): IValue;
@@ -181,10 +189,12 @@ declare class Leafer extends Group implements ILeafer {
181
189
  protected __onNextRender(): void;
182
190
  protected __checkViewCompleted(emit?: boolean): void;
183
191
  protected __onWatchData(): void;
184
- waitReady(item: IFunction): void;
185
- waitViewReady(item: IFunction): void;
186
- waitViewCompleted(item: IFunction): void;
187
- nextRender(item: IFunction, off?: 'off'): void;
192
+ waitReady(item: IFunction, bind?: IObject): void;
193
+ waitViewReady(item: IFunction, bind?: IObject): void;
194
+ waitViewCompleted(item: IFunction, bind?: IObject): void;
195
+ nextRender(item: IFunction, bind?: IObject, off?: 'off'): void;
196
+ zoom(_zoomType: IZoomType, _padding?: IFourNumber, _fixedScale?: boolean): IBoundsData;
197
+ validScale(changeScale: number): number;
188
198
  protected __checkUpdateLayout(): void;
189
199
  protected emitLeafer(type: string): void;
190
200
  protected __listenEvents(): void;