@leafer-ui/display 1.0.1 → 1.0.2

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.1",
3
+ "version": "1.0.2",
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.1",
26
- "@leafer-ui/data": "1.0.1",
27
- "@leafer-ui/display-module": "1.0.1",
28
- "@leafer-ui/decorator": "1.0.1",
29
- "@leafer-ui/external": "1.0.1"
25
+ "@leafer/core": "1.0.2",
26
+ "@leafer-ui/data": "1.0.2",
27
+ "@leafer-ui/display-module": "1.0.2",
28
+ "@leafer-ui/decorator": "1.0.2",
29
+ "@leafer-ui/external": "1.0.2"
30
30
  },
31
31
  "devDependencies": {
32
- "@leafer/interface": "1.0.1",
33
- "@leafer-ui/interface": "1.0.1"
32
+ "@leafer/interface": "1.0.2",
33
+ "@leafer-ui/interface": "1.0.2"
34
34
  }
35
35
  }
package/src/Box.ts CHANGED
@@ -10,7 +10,7 @@ import { Rect } from './Rect'
10
10
  const rect = Rect.prototype
11
11
  const group = Group.prototype
12
12
  const childrenRenderBounds = {} as IBoundsData
13
- const { copy, add, includes } = BoundsHelper
13
+ const { copy, add, includes, copyAndSpread } = BoundsHelper
14
14
 
15
15
  @rewriteAble()
16
16
  @registerUI()
@@ -50,18 +50,26 @@ export class Box extends Group implements IBox {
50
50
  @rewrite(rect.__updateBoxBounds)
51
51
  public __updateRectBoxBounds(): void { }
52
52
 
53
- public __updateBoxBounds(): void {
53
+ public __updateBoxBounds(secondLayout?: boolean): void {
54
54
  const data = this.__
55
55
 
56
56
  if (this.children.length) {
57
57
  if (data.__autoSide) {
58
+
58
59
  if (this.leafer && this.leafer.ready) this.leafer.layouter.addExtra(this)
59
60
  super.__updateBoxBounds()
61
+
62
+ const { boxBounds } = this.__layout
63
+
60
64
  if (!data.__autoSize) {
61
- const b = this.__layout.boxBounds
62
- if (!data.__autoWidth) b.height += b.y, b.width = data.width, b.x = b.y = 0
63
- if (!data.__autoHeight) b.width += b.x, b.height = data.height, b.y = b.x = 0
65
+ if (data.__autoWidth) boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0
66
+ else boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0
64
67
  }
68
+
69
+ if (secondLayout && data.flow && data.padding) copyAndSpread(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'))
70
+
71
+ this.__updateNaturalSize()
72
+
65
73
  } else {
66
74
  this.__updateRectBoxBounds()
67
75
  }
@@ -85,13 +93,13 @@ export class Box extends Group implements IBox {
85
93
  copy(childrenRenderBounds, renderBounds)
86
94
  this.__updateRectRenderBounds()
87
95
 
88
- isOverflow = !includes(renderBounds, childrenRenderBounds) || undefined
96
+ isOverflow = !includes(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius // 路径与圆角直接当溢出处理
89
97
  } else {
90
98
  this.__updateRectRenderBounds()
91
99
  }
92
100
 
93
101
  this.isOverflow !== isOverflow && (this.isOverflow = isOverflow)
94
- if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide')) add(renderBounds, childrenRenderBounds)
102
+ if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow) add(renderBounds, childrenRenderBounds)
95
103
  }
96
104
 
97
105
  @rewrite(rect.__updateRenderBounds)
package/src/Canvas.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeaferCanvas, ILeaferCanvasConfig, INumber, IRenderOptions, IPointData, ICanvasContext2D, ICanvasContext2DSettings, IScreenSizeData, ISizeData } from '@leafer/interface'
2
- import { Creator, Matrix, Platform, dataProcessor, registerUI } from '@leafer/core'
2
+ import { Creator, ImageEvent, LeaferImage, Matrix, dataProcessor, registerUI } from '@leafer/core'
3
3
 
4
4
  import { ICanvas, ICanvasData, ICanvasInputData, IUI } from '@leafer-ui/interface'
5
5
  import { CanvasData } from '@leafer-ui/data'
@@ -22,7 +22,7 @@ export class Canvas extends Rect implements ICanvas {
22
22
  @resizeType(100)
23
23
  declare public height?: INumber
24
24
 
25
- @resizeType(Platform.devicePixelRatio)
25
+ @resizeType(1)
26
26
  declare public pixelRatio?: INumber
27
27
 
28
28
  @resizeType(true)
@@ -35,11 +35,25 @@ export class Canvas extends Rect implements ICanvas {
35
35
 
36
36
  public context?: ICanvasContext2D
37
37
 
38
+ public get ready(): boolean { return !this.url }
39
+
40
+ protected url?: string // 用于临时加载canvas的base64数据,完成后会置空
41
+
38
42
  constructor(data?: ICanvasInputData) {
39
43
  super(data)
40
44
  this.canvas = Creator.canvas(this.__ as ILeaferCanvasConfig)
41
45
  this.context = this.canvas.context
42
46
  this.__.__isCanvas = this.__.__drawAfterFill = true
47
+ if (data && data.url) this.drawImage(data.url)
48
+ }
49
+
50
+ public drawImage(url: string): void {
51
+ new LeaferImage({ url }).load((image: LeaferImage) => {
52
+ this.context.drawImage(image.view, 0, 0)
53
+ this.url = undefined
54
+ this.paint()
55
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }))
56
+ })
43
57
  }
44
58
 
45
59
  public draw(ui: IUI, offset?: IPointData, scale?: number | IPointData, rotation?: number): void {
package/src/Image.ts CHANGED
@@ -34,4 +34,6 @@ export class Image extends Rect implements IImage {
34
34
  super.destroy()
35
35
  }
36
36
 
37
- }
37
+ }
38
+
39
+ export const MyImage = Image
package/src/Leafer.ts CHANGED
@@ -375,6 +375,7 @@ export class Leafer extends Group implements ILeafer {
375
375
  return debug.error('need @leafer-in/view') as undefined
376
376
  }
377
377
 
378
+
378
379
  // interaction window rewrite
379
380
  public getValidMove(moveX: number, moveY: number): IPointData { return { x: moveX, y: moveY } }
380
381
  public getValidScale(changeScale: number): number { return changeScale }
@@ -384,6 +385,18 @@ export class Leafer extends Group implements ILeafer {
384
385
  return this.interaction && this.interaction.getLocal(clientPoint, updateClient)
385
386
  }
386
387
 
388
+ public getPagePointByClient(clientPoint: IClientPointData, updateClient?: boolean): IPointData {
389
+ return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient))
390
+ }
391
+
392
+ public updateClientBounds(): void {
393
+ this.canvas && this.canvas.updateClientBounds()
394
+ }
395
+
396
+ // miniapp rewrite
397
+ public receiveEvent(_event: any): void { }
398
+
399
+
387
400
  protected __checkUpdateLayout(): void {
388
401
  this.__layout.update()
389
402
  }
package/src/Pen.ts CHANGED
@@ -6,8 +6,7 @@ import { PenData } from '@leafer-ui/data'
6
6
  import { Group } from './Group'
7
7
  import { Path } from './Path'
8
8
 
9
-
10
- @useModule(PathCreator, ['set', 'beginPath', 'path'])
9
+ @useModule(PathCreator, ['set', 'beginPath', 'path', 'paint'])
11
10
  @registerUI()
12
11
  export class Pen extends Group implements IPen {
13
12
 
@@ -79,10 +78,9 @@ export class Pen extends Group implements IPen {
79
78
  public clearPath(): Pen { return this }
80
79
 
81
80
  public paint(): void {
82
- this.pathElement.forceUpdate('path')
81
+ if (!this.pathElement.__layout.boxChanged) this.pathElement.forceUpdate('path')
83
82
  }
84
83
 
85
-
86
84
  }
87
85
 
88
86
  function penPathType() {
package/src/Text.ts CHANGED
@@ -96,14 +96,14 @@ export class Text extends UI implements IText {
96
96
  }
97
97
 
98
98
  public __drawHitPath(canvas: ILeaferCanvas): void {
99
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__
99
+ const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__
100
100
 
101
101
  canvas.beginPath()
102
102
 
103
103
  if (this.__.__letterSpacing < 0) {
104
104
  this.__drawPathByData(canvas)
105
105
  } else {
106
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight))
106
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight))
107
107
  }
108
108
  }
109
109
 
package/src/index.ts CHANGED
@@ -11,7 +11,7 @@ export { Polygon } from './Polygon'
11
11
  export { Star } from './Star'
12
12
  export { Line } from './Line'
13
13
 
14
- export { Image } from './Image'
14
+ export { Image, MyImage } from './Image'
15
15
  export { Canvas } from './Canvas'
16
16
 
17
17
  export { Text } from './Text'
package/types/index.d.ts CHANGED
@@ -231,6 +231,9 @@ declare class Leafer extends Group implements ILeafer {
231
231
  getValidMove(moveX: number, moveY: number): IPointData;
232
232
  getValidScale(changeScale: number): number;
233
233
  getWorldPointByClient(clientPoint: IClientPointData, updateClient?: boolean): IPointData;
234
+ getPagePointByClient(clientPoint: IClientPointData, updateClient?: boolean): IPointData;
235
+ updateClientBounds(): void;
236
+ receiveEvent(_event: any): void;
234
237
  protected __checkUpdateLayout(): void;
235
238
  protected emitLeafer(type: string): void;
236
239
  protected __listenEvents(): void;
@@ -250,7 +253,7 @@ declare class Box extends Group implements IBox {
250
253
  __updateRectRenderSpread(): number;
251
254
  __updateRenderSpread(): number;
252
255
  __updateRectBoxBounds(): void;
253
- __updateBoxBounds(): void;
256
+ __updateBoxBounds(secondLayout?: boolean): void;
254
257
  __updateStrokeBounds(): void;
255
258
  __updateRenderBounds(): void;
256
259
  __updateRectRenderBounds(): void;
@@ -333,6 +336,7 @@ declare class Image extends Rect implements IImage {
333
336
  constructor(data?: IImageInputData);
334
337
  destroy(): void;
335
338
  }
339
+ declare const MyImage: typeof Image;
336
340
 
337
341
  declare class Canvas extends Rect implements ICanvas {
338
342
  get __tag(): string;
@@ -344,7 +348,10 @@ declare class Canvas extends Rect implements ICanvas {
344
348
  contextSettings?: ICanvasContext2DSettings;
345
349
  canvas?: ILeaferCanvas;
346
350
  context?: ICanvasContext2D;
351
+ get ready(): boolean;
352
+ protected url?: string;
347
353
  constructor(data?: ICanvasInputData);
354
+ drawImage(url: string): void;
348
355
  draw(ui: IUI, offset?: IPointData, scale?: number | IPointData, rotation?: number): void;
349
356
  paint(): void;
350
357
  __drawAfterFill(canvas: ILeaferCanvas, _options: IRenderOptions): void;
@@ -422,4 +429,4 @@ declare class Pen extends Group implements IPen {
422
429
  paint(): void;
423
430
  }
424
431
 
425
- export { Box, Canvas, Ellipse, Frame, Group, Image, Leafer, Line, Path, Pen, Polygon, Rect, Star, Text, UI };
432
+ export { Box, Canvas, Ellipse, Frame, Group, Image, Leafer, Line, MyImage, Path, Pen, Polygon, Rect, Star, Text, UI };