@leafer-ui/display 1.6.1 → 1.6.3

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.6.1",
3
+ "version": "1.6.3",
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.6.1",
26
- "@leafer-ui/data": "1.6.1",
27
- "@leafer-ui/display-module": "1.6.1",
28
- "@leafer-ui/decorator": "1.6.1",
29
- "@leafer-ui/external": "1.6.1"
25
+ "@leafer/core": "1.6.3",
26
+ "@leafer-ui/data": "1.6.3",
27
+ "@leafer-ui/display-module": "1.6.3",
28
+ "@leafer-ui/decorator": "1.6.3",
29
+ "@leafer-ui/external": "1.6.3"
30
30
  },
31
31
  "devDependencies": {
32
- "@leafer/interface": "1.6.1",
33
- "@leafer-ui/interface": "1.6.1"
32
+ "@leafer/interface": "1.6.3",
33
+ "@leafer-ui/interface": "1.6.3"
34
34
  }
35
35
  }
package/src/Box.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeaferCanvas, IRenderOptions, IBoundsData, IBoolean, INumber } from '@leafer/interface'
2
- import { rewrite, rewriteAble, registerUI, BoundsHelper, dataProcessor, affectRenderBoundsType, dataType, boundsType } from '@leafer/core'
2
+ import { rewrite, rewriteAble, registerUI, BoundsHelper, dataProcessor, affectRenderBoundsType, dataType, boundsType, DataHelper } from '@leafer/core'
3
3
 
4
4
  import { IBox, IBoxData, IBoxInputData, IOverflow } from '@leafer-ui/interface'
5
5
  import { BoxData } from '@leafer-ui/data'
@@ -102,11 +102,11 @@ export class Box extends Group implements IBox {
102
102
  copy(childrenRenderBounds, renderBounds)
103
103
  this.__updateRectRenderBounds()
104
104
 
105
- isOverflow = !includes(renderBounds, childrenRenderBounds) || undefined
105
+ isOverflow = !includes(renderBounds, childrenRenderBounds)
106
106
  if (isOverflow && this.__.overflow !== 'hide') add(renderBounds, childrenRenderBounds)
107
107
  } else this.__updateRectRenderBounds()
108
108
 
109
- this.isOverflow !== isOverflow && (this.isOverflow = isOverflow) // 节省赋值
109
+ DataHelper.stintSet(this, 'isOverflow', isOverflow)
110
110
  }
111
111
 
112
112
  @rewrite(rect.__updateRenderBounds)
package/src/Canvas.ts CHANGED
@@ -36,7 +36,7 @@ export class Canvas extends Rect implements ICanvas {
36
36
 
37
37
  public canvas?: ILeaferCanvas
38
38
 
39
- public context?: ICanvasContext2D
39
+ public get context(): ICanvasContext2D { return this.canvas.context }
40
40
 
41
41
  public get ready(): boolean { return !this.url }
42
42
 
@@ -45,7 +45,6 @@ export class Canvas extends Rect implements ICanvas {
45
45
  constructor(data?: ICanvasInputData) {
46
46
  super(data)
47
47
  this.canvas = Creator.canvas(this.__ as ILeaferCanvasConfig)
48
- this.context = this.canvas.context
49
48
  if (data && data.url) this.drawImage(data.url)
50
49
  }
51
50
 
@@ -93,7 +92,7 @@ export class Canvas extends Rect implements ICanvas {
93
92
  public destroy(): void {
94
93
  if (this.canvas) {
95
94
  this.canvas.destroy()
96
- this.canvas = this.context = null
95
+ this.canvas = null
97
96
  }
98
97
  super.destroy()
99
98
  }
package/src/Image.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeaferImage, IString } from '@leafer/interface'
2
- import { ImageEvent, boundsType, dataProcessor, registerUI } from '@leafer/core'
2
+ import { boundsType, dataProcessor, registerUI } from '@leafer/core'
3
3
 
4
4
  import { IImage, IImageInputData, IImageData } from '@leafer-ui/interface'
5
5
  import { ImageData } from '@leafer-ui/data'
@@ -18,20 +18,12 @@ export class Image extends Rect implements IImage {
18
18
  @boundsType('')
19
19
  public url: IString
20
20
 
21
- public get ready(): boolean { return this.image ? this.image.ready : false }
21
+ public get ready(): boolean { const { image } = this; return image && image.ready }
22
22
 
23
- public image?: ILeaferImage
23
+ public get image(): ILeaferImage { const { fill } = this.__; return fill instanceof Array && fill[0].image }
24
24
 
25
25
  constructor(data?: IImageInputData) {
26
26
  super(data)
27
- this.on(ImageEvent.LOADED, (e: ImageEvent) => {
28
- if (e.attrName === 'fill' && e.attrValue.url === this.url) this.image = e.image
29
- })
30
- }
31
-
32
- public destroy(): void {
33
- this.image = null
34
- super.destroy()
35
27
  }
36
28
 
37
29
  }
package/src/Leafer.ts CHANGED
@@ -421,20 +421,23 @@ export class Leafer extends Group implements ILeafer {
421
421
 
422
422
  protected __listenEvents(): void {
423
423
  const runId = Run.start('FirstCreate ' + this.innerName)
424
- this.once(LeaferEvent.START, () => Run.end(runId))
425
- this.once(LayoutEvent.START, () => this.updateLazyBounds())
426
- this.once(RenderEvent.START, () => this.__onCreated())
427
- this.once(RenderEvent.END, () => this.__onViewReady())
424
+ this.once([
425
+ [LeaferEvent.START, () => Run.end(runId)],
426
+ [LayoutEvent.START, this.updateLazyBounds, this],
427
+ [RenderEvent.START, this.__onCreated, this],
428
+ [RenderEvent.END, this.__onViewReady, this]
429
+ ])
428
430
  this.__eventIds.push(
429
- this.on_(WatchEvent.DATA, this.__onWatchData, this),
430
- this.on_(LayoutEvent.END, this.__onLayoutEnd, this),
431
- this.on_(RenderEvent.NEXT, this.__onNextRender, this),
431
+ this.on_([
432
+ [WatchEvent.DATA, this.__onWatchData, this],
433
+ [LayoutEvent.END, this.__onLayoutEnd, this],
434
+ [RenderEvent.NEXT, this.__onNextRender, this]
435
+ ])
432
436
  )
433
437
  }
434
438
 
435
439
  protected __removeListenEvents(): void {
436
440
  this.off_(this.__eventIds)
437
- this.__eventIds.length = 0
438
441
  }
439
442
 
440
443
  override destroy(sync?: boolean): void {
package/src/Text.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeaferCanvas, IBoolean, INumber, IString, IBoundsData, IUnitData, IRenderOptions } from '@leafer/interface'
2
- import { BoundsHelper, boundsType, surfaceType, dataProcessor, registerUI, affectStrokeBoundsType, dataType, hitType, MathHelper } from '@leafer/core'
2
+ import { BoundsHelper, boundsType, surfaceType, dataProcessor, registerUI, affectStrokeBoundsType, dataType, hitType, MathHelper, DataHelper } from '@leafer/core'
3
3
 
4
4
  import { IFill, IText, IFontWeight, ITextCase, ITextDecoration, ITextData, ITextInputData, ITextAlign, IVerticalAlign, ITextDrawData, IOverflow, IStrokeAlign, IHitType, ITextWrap, IWritingMode, IBackgroundBoxStyle } from '@leafer-ui/interface'
5
5
  import { TextData } from '@leafer-ui/data'
@@ -44,6 +44,9 @@ export class Text extends UI implements IText {
44
44
  @boundsType('')
45
45
  public text?: IString | INumber
46
46
 
47
+ @boundsType('')
48
+ public placeholder?: IString
49
+
47
50
  @boundsType('caption')
48
51
  public fontFamily?: IString
49
52
 
@@ -115,7 +118,7 @@ export class Text extends UI implements IText {
115
118
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`
116
119
  data.__clipText = textOverflow !== 'show' && !data.__autoSize
117
120
 
118
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__)
121
+ data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === '') ? data.placeholder : data.text, this.__)
119
122
  }
120
123
 
121
124
  override __updateBoxBounds(): void {
@@ -149,11 +152,10 @@ export class Text extends UI implements IText {
149
152
 
150
153
  if (italic) b.width += fontSize * 0.16 // 倾斜会导致文本的bounds增大
151
154
 
152
- const isOverflow = !includes(b, contentBounds) || undefined
153
- if (isOverflow) setList(data.__textBoxBounds = {} as IBoundsData, [b, contentBounds]), layout.renderChanged = true
154
- else data.__textBoxBounds = b
155
+ DataHelper.stintSet(this, 'isOverflow', !includes(b, contentBounds))
155
156
 
156
- this.isOverflow !== isOverflow && (this.isOverflow = isOverflow) // 节省赋值
157
+ if (this.isOverflow) setList(data.__textBoxBounds = {} as IBoundsData, [b, contentBounds]), layout.renderChanged = true
158
+ else data.__textBoxBounds = b
157
159
  }
158
160
 
159
161
  override __onUpdateSize(): void {
package/src/UI.ts CHANGED
@@ -1,13 +1,13 @@
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, IScaleData, IUnitData, IPathCommandObject, ITransition, IFilter } from '@leafer/interface'
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, IScaleData, IUnitData, IPathCommandObject, ITransition, IFilter, ILeaferImage } from '@leafer/interface'
2
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, MathHelper, Plugin, DataHelper } 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, IArrowType, IFindUIMethod, ILeafer, IEditorConfig, IEditorConfigFunction, IEditToolFunction, IKeyframe, IAnimation, IAnimate, IStates, IStateName, IAnimateType, IStateStyle } from '@leafer-ui/interface'
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, IKeyframe, IAnimation, IAnimate, IStates, IStateName, IAnimateType, IStateStyle, IColorString } from '@leafer-ui/interface'
5
5
  import { effectType, 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'
9
9
 
10
- import { Export, PathArrow } from '@leafer-ui/external'
10
+ import { Export, Paint, PathArrow } from '@leafer-ui/external'
11
11
 
12
12
 
13
13
  @useModule(UIBounds)
@@ -346,12 +346,28 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
346
346
 
347
347
  public disabledStyle?: IStateStyle
348
348
 
349
+
349
350
  public placeholderStyle?: IStateStyle
350
351
 
352
+ @surfaceType()
353
+ public placeholderColor?: IColorString
354
+
355
+ @dataType(100)
356
+ public placeholderDelay?: INumber
357
+
351
358
 
352
359
  public button?: IBoolean
353
360
 
354
361
 
362
+ // @leafer-in/editor rewrite
363
+
364
+ public editConfig: IEditorConfig
365
+
366
+ public editOuter: string
367
+
368
+ public editInner: string
369
+
370
+
355
371
  // 预留给用户使用的数据对象
356
372
  @dataType({})
357
373
  public data: IObject
@@ -360,6 +376,8 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
360
376
  public set scale(value: INumber | IPointData) { MathHelper.assignScale(this as IScaleData, value) }
361
377
  public get scale(): INumber | IPointData { return this.__.scale }
362
378
 
379
+ public useFastShadow?: boolean // 将忽略 stroke 产生的阴影,只对单个 fill 有效
380
+
363
381
  public __box?: IUI // 背景box, 一般用于文本背景框
364
382
  public __animate?: IAnimate
365
383
 
@@ -371,15 +389,6 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
371
389
  }
372
390
 
373
391
 
374
- // @leafer-in/editor rewrite
375
-
376
- public editConfig: IEditorConfig
377
-
378
- public editOuter: string
379
-
380
- public editInner: string
381
-
382
-
383
392
  constructor(data?: IUIInputData) {
384
393
  super(data)
385
394
  }
@@ -476,6 +485,10 @@ export class UI extends Leaf implements IUI { // tip: rewrited Box
476
485
  } else drawer.rect(x, y, width, height)
477
486
  }
478
487
 
488
+ public drawImagePlaceholder(canvas: ILeaferCanvas, _image?: ILeaferImage): void {
489
+ Paint.fill(this.__.placeholderColor, this, canvas) // 图片占位符
490
+ }
491
+
479
492
  // @leafer-in/animate rewrite
480
493
 
481
494
  public animate(_keyframe?: IUIInputData | IKeyframe[] | IAnimation | IAnimation[], _options?: ITransition, _type?: IAnimateType, _isTemp?: boolean): IAnimate {
package/types/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { IString, INumber, IBoolean, IMaskType, IEraserType, IAlign, IUnitPointData, IPathCommandData, IPathCommandObject, IPathString, IWindingRule, IFlowType, IFourNumber, IGap, IPointGap, IFlowAlign, IFlowAxisAlign, IFlowWrap, IFlowBoxType, IAutoSize, IAutoBoxData, IConstraint, IRangeSize, IAxis, IBoundsData, IHitType, ICursorType, IFilter, ITransition, IUnitData, IObject, IPointData, IPathCreator, IValue, IFindCondition, ILeaferCanvas, IPathDrawer, IExportFileType, IJSONOptions, IPickOptions, IPickResult, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaferConfig, IAutoBounds, IBounds, IEventListenerId, ITimer, IControl, ILeaferType, IScreenSizeData, IResizeEvent, IZoomType, IClientPointData, IRenderOptions, ILeaferImage, ICanvasContext2DSettings, ICanvasContext2D } from '@leafer/interface';
1
+ import { IString, INumber, IBoolean, IMaskType, IEraserType, IAlign, IUnitPointData, IPathCommandData, IPathCommandObject, IPathString, IWindingRule, IFlowType, IFourNumber, IGap, IPointGap, IFlowAlign, IFlowAxisAlign, IFlowWrap, IFlowBoxType, IAutoSize, IAutoBoxData, IConstraint, IRangeSize, IAxis, IBoundsData, IHitType, ICursorType, IFilter, ITransition, IUnitData, IObject, IPointData, IPathCreator, IValue, IFindCondition, ILeaferCanvas, IPathDrawer, ILeaferImage, IExportFileType, IJSONOptions, IPickOptions, IPickResult, IRenderer, IWatcher, ILayouter, ISelector, IInteraction, ICanvasManager, IHitCanvasManager, ILeaferConfig, IAutoBounds, IBounds, IEventListenerId, ITimer, IControl, ILeaferType, IScreenSizeData, IResizeEvent, IZoomType, IClientPointData, IRenderOptions, ICanvasContext2DSettings, ICanvasContext2D } from '@leafer/interface';
2
2
  import { Leaf, LeafList } from '@leafer/core';
3
- import { IUI, IUIData, IUIInputData, ILeafer, IGroup, IBlendMode, IFill, IStroke, IStrokeAlign, IStrokeWidthString, IStrokeCap, IStrokeJoin, IDashPatternString, IArrowType, ICornerRadiusString, IShadowEffect, IShadowString, IBlurEffect, IGrayscaleEffect, IAnimation, IStates, IStateName, IStateStyle, IAnimate, IEditorConfig, IFindUIMethod, IKeyframe, IAnimateType, IExportOptions, IExportResult, IEditorConfigFunction, IEditToolFunction, IGroupData, IGroupInputData, IUIJSONData, IFindCondition as IFindCondition$1, 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, IBackgroundBoxStyle, IHitType as IHitType$1, IFontWeight, ITextCase, ITextDecoration, IWritingMode, ITextAlign, IVerticalAlign, ITextWrap, ITextDrawData, ITextInputData, IPath, IPathData, IPathInputData, IPen, IPenData, IPathCommandData as IPathCommandData$1, IPenInputData, IPointData as IPointData$1 } from '@leafer-ui/interface';
3
+ import { IUI, IUIData, IUIInputData, ILeafer, IGroup, IBlendMode, IFill, IStroke, IStrokeAlign, IStrokeWidthString, IStrokeCap, IStrokeJoin, IDashPatternString, IArrowType, ICornerRadiusString, IShadowEffect, IShadowString, IBlurEffect, IGrayscaleEffect, IAnimation, IStates, IStateName, IStateStyle, IColorString, IEditorConfig, IAnimate, IFindUIMethod, IKeyframe, IAnimateType, IExportOptions, IExportResult, IEditorConfigFunction, IEditToolFunction, IGroupData, IGroupInputData, IUIJSONData, IFindCondition as IFindCondition$1, 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, IBackgroundBoxStyle, IHitType as IHitType$1, IFontWeight, ITextCase, ITextDecoration, IWritingMode, ITextAlign, IVerticalAlign, ITextWrap, ITextDrawData, ITextInputData, IPath, IPathData, IPathInputData, IPen, IPenData, IPathCommandData as IPathCommandData$1, IPenInputData, IPointData as IPointData$1 } from '@leafer-ui/interface';
4
4
 
5
5
  declare class UI extends Leaf implements IUI {
6
6
  __: IUIData;
@@ -107,16 +107,19 @@ declare class UI extends Leaf implements IUI {
107
107
  selectedStyle?: IStateStyle;
108
108
  disabledStyle?: IStateStyle;
109
109
  placeholderStyle?: IStateStyle;
110
+ placeholderColor?: IColorString;
111
+ placeholderDelay?: INumber;
110
112
  button?: IBoolean;
113
+ editConfig: IEditorConfig;
114
+ editOuter: string;
115
+ editInner: string;
111
116
  data: IObject;
112
117
  set scale(value: INumber | IPointData);
113
118
  get scale(): INumber | IPointData;
119
+ useFastShadow?: boolean;
114
120
  __box?: IUI;
115
121
  __animate?: IAnimate;
116
122
  get pen(): IPathCreator;
117
- editConfig: IEditorConfig;
118
- editOuter: string;
119
- editInner: string;
120
123
  constructor(data?: IUIInputData);
121
124
  reset(_data?: IUIInputData): void;
122
125
  set(data: IUIInputData, transition?: ITransition | 'temp'): void;
@@ -135,6 +138,7 @@ declare class UI extends Leaf implements IUI {
135
138
  __drawPath(canvas: ILeaferCanvas): void;
136
139
  __drawPathByData(drawer: IPathDrawer, data: IPathCommandData): void;
137
140
  __drawPathByBox(drawer: IPathDrawer): void;
141
+ drawImagePlaceholder(canvas: ILeaferCanvas, _image?: ILeaferImage): void;
138
142
  animate(_keyframe?: IUIInputData | IKeyframe[] | IAnimation | IAnimation[], _options?: ITransition, _type?: IAnimateType, _isTemp?: boolean): IAnimate;
139
143
  killAnimate(_type?: IAnimateType, _nextStyle?: IUIInputData): void;
140
144
  export(_filename: IExportFileType | string, _options?: IExportOptions | number | boolean): Promise<IExportResult>;
@@ -360,9 +364,8 @@ declare class Image extends Rect implements IImage {
360
364
  __: IImageData;
361
365
  url: IString;
362
366
  get ready(): boolean;
363
- image?: ILeaferImage;
367
+ get image(): ILeaferImage;
364
368
  constructor(data?: IImageInputData);
365
- destroy(): void;
366
369
  }
367
370
  declare const MyImage: typeof Image;
368
371
 
@@ -376,7 +379,7 @@ declare class Canvas extends Rect implements ICanvas {
376
379
  safeResize?: boolean;
377
380
  contextSettings?: ICanvasContext2DSettings;
378
381
  canvas?: ILeaferCanvas;
379
- context?: ICanvasContext2D;
382
+ get context(): ICanvasContext2D;
380
383
  get ready(): boolean;
381
384
  url?: string;
382
385
  constructor(data?: ICanvasInputData);
@@ -399,6 +402,7 @@ declare class Text extends UI implements IText {
399
402
  strokeAlign?: IStrokeAlign;
400
403
  hitFill?: IHitType$1;
401
404
  text?: IString | INumber;
405
+ placeholder?: IString;
402
406
  fontFamily?: IString;
403
407
  fontSize?: INumber;
404
408
  fontWeight?: IFontWeight;