@leafer-ui/paint 1.0.0-beta.6 → 1.0.0-beta.8

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/paint",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.8",
4
4
  "description": "@leafer-ui/paint",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,11 +19,11 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "dependencies": {
22
- "@leafer/core": "1.0.0-beta.6",
23
- "@leafer-ui/color": "1.0.0-beta.6"
22
+ "@leafer/core": "1.0.0-beta.8",
23
+ "@leafer-ui/color": "1.0.0-beta.8"
24
24
  },
25
25
  "devDependencies": {
26
- "@leafer/interface": "1.0.0-beta.6",
27
- "@leafer-ui/interface": "1.0.0-beta.6"
26
+ "@leafer/interface": "1.0.0-beta.8",
27
+ "@leafer-ui/interface": "1.0.0-beta.8"
28
28
  }
29
29
  }
package/src/Fill.ts CHANGED
@@ -7,7 +7,7 @@ import { drawText } from './FillText'
7
7
 
8
8
  export function fill(ui: IUI, canvas: ILeaferCanvas, fill: string | object): void {
9
9
  canvas.fillStyle = fill
10
- ui.__.__font ? drawText(ui, canvas) : canvas.fill(ui.__.windingRule)
10
+ ui.__.__font ? drawText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill())
11
11
  }
12
12
 
13
13
  export function fills(ui: IUI, canvas: ILeaferCanvas, fills: ILeafPaint[]): void {
@@ -25,21 +25,22 @@ export function fills(ui: IUI, canvas: ILeaferCanvas, fills: ILeafPaint[]): void
25
25
 
26
26
  if (item.blendMode) canvas.blendMode = item.blendMode
27
27
 
28
- __font ? drawText(ui, canvas) : canvas.fill(windingRule)
28
+ __font ? drawText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill())
29
29
 
30
30
  canvas.restore()
31
31
  } else {
32
32
  if (item.blendMode) {
33
33
  canvas.saveBlendMode(item.blendMode)
34
34
 
35
- __font ? drawText(ui, canvas) : canvas.fill(windingRule)
35
+ __font ? drawText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill())
36
36
 
37
37
  canvas.restoreBlendMode()
38
38
  } else {
39
39
 
40
- __font ? drawText(ui, canvas) : canvas.fill(windingRule)
40
+ __font ? drawText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill())
41
41
 
42
42
  }
43
43
  }
44
+
44
45
  }
45
46
  }
package/src/Shape.ts CHANGED
@@ -37,7 +37,14 @@ export function shape(ui: IUI, current: ILeaferCanvas, options: IRenderOptions):
37
37
 
38
38
  } else {
39
39
 
40
- bounds = shapeBounds = __world
40
+ if (options.matrix) {
41
+ scaleX *= options.matrix.a
42
+ scaleY *= options.matrix.d
43
+ bounds = shapeBounds = getOuterOf(__world, options.matrix)
44
+ } else {
45
+ bounds = shapeBounds = __world
46
+ }
47
+
41
48
  worldCanvas = canvas
42
49
  }
43
50
 
package/src/Stroke.ts CHANGED
@@ -8,6 +8,7 @@ import { strokeText, strokesText } from './StrokeText'
8
8
  export function stroke(ui: IUI, canvas: ILeaferCanvas, stroke: string | object): void {
9
9
  const options = ui.__
10
10
  const { strokeWidth, strokeAlign, __font } = options
11
+ if (!strokeWidth) return
11
12
 
12
13
  if (__font) {
13
14
 
@@ -58,6 +59,7 @@ export function stroke(ui: IUI, canvas: ILeaferCanvas, stroke: string | object):
58
59
  export function strokes(ui: IUI, canvas: ILeaferCanvas, strokes: ILeafPaint[]): void {
59
60
  const options = ui.__
60
61
  const { strokeWidth, strokeAlign, __font } = options
62
+ if (!strokeWidth) return
61
63
 
62
64
  if (__font) {
63
65
 
@@ -41,11 +41,8 @@ export function conicGradient(paint: IGradientPaint, box: IBoundsData): ILeafPai
41
41
  const style = Platform.conicGradientSupport ? Platform.canvas.createConicGradient(0, realFrom.x, realFrom.y) : Platform.canvas.createRadialGradient(realFrom.x, realFrom.y, 0, realFrom.x, realFrom.y, getDistance(realFrom, realTo))
42
42
  applyStops(style, paint.stops, opacity)
43
43
 
44
- return {
45
- type,
46
- blendMode,
47
- style,
48
- transform
49
- }
44
+ const data: ILeafPaint = { type, style, transform }
45
+ if (blendMode) data.blendMode = blendMode
46
+ return data
50
47
 
51
48
  }
@@ -1,4 +1,4 @@
1
- import { IBoundsData } from '@leafer/interface'
1
+ import { IBoundsData, ISizeData } from '@leafer/interface'
2
2
  import { Platform, MatrixHelper, ImageEvent } from '@leafer/core'
3
3
 
4
4
  import { IUI, IImagePaint, ILeafPaint, IMatrixData, IImagePaintMode, IPointData } from '@leafer-ui/interface'
@@ -7,53 +7,54 @@ import { IUI, IImagePaint, ILeafPaint, IMatrixData, IImagePaintMode, IPointData
7
7
  const { get, rotateOfOuter, translate, scaleOfOuter, scale: scaleHelper, rotate } = MatrixHelper
8
8
 
9
9
  export function image(ui: IUI, attrName: string, paint: IImagePaint, box: IBoundsData): ILeafPaint {
10
- let { type, blendMode } = paint
11
- let leaferPaint: ILeafPaint = {
12
- type,
13
- blendMode,
14
- style: 'rgba(255,255,255,0)'
15
- }
10
+ const { type, blendMode } = paint
11
+ let leaferPaint: ILeafPaint = { type, style: 'rgba(255,255,255,0)' }
12
+ if (blendMode) leaferPaint.blendMode = blendMode
16
13
 
17
14
  const { imageManager } = ui.leafer
18
15
  const image = imageManager.get(paint)
19
16
 
20
17
  if (image.ready) {
21
18
 
22
- let transform: IMatrixData
23
- let { opacity, mode, offset, scale, rotation } = paint
24
- let { width, height } = image
25
- const sameBox = box.width === width && box.height === height
26
-
27
- switch (mode) {
28
- case 'strench':
29
- if (!sameBox) width = box.width, height = box.height
30
- if (box.x || box.y) {
31
- transform = get()
32
- translate(transform, box.x, box.y)
33
- }
34
- break
35
- case 'clip':
36
- if (offset || scale || rotation) transform = getClipTransform(box, offset, scale, rotation)
37
- break
38
- case 'repeat':
39
- if (!sameBox || scale || rotation) transform = getRepeatTransform(box, width, height, scale as number, rotation)
40
- break
41
- case 'fit':
42
- case 'cover':
43
- default:
44
- if (!sameBox || rotation) transform = getFillOrFitTransform(mode, box, width, height, rotation)
45
- }
19
+ if (hasSize(ui, attrName, image)) {
20
+
21
+ let transform: IMatrixData
22
+ let { opacity, mode, offset, scale, rotation } = paint
23
+ let { width, height } = image
24
+ const sameBox = box.width === width && box.height === height
25
+
26
+ switch (mode) {
27
+ case 'strench':
28
+ if (!sameBox) width = box.width, height = box.height
29
+ if (box.x || box.y) {
30
+ transform = get()
31
+ translate(transform, box.x, box.y)
32
+ }
33
+ break
34
+ case 'clip':
35
+ if (offset || scale || rotation) transform = getClipTransform(box, offset, scale, rotation)
36
+ break
37
+ case 'repeat':
38
+ if (!sameBox || scale || rotation) transform = getRepeatTransform(box, width, height, scale as number, rotation)
39
+ break
40
+ case 'fit':
41
+ case 'cover':
42
+ default:
43
+ if (!sameBox || rotation) transform = getFillOrFitTransform(mode, box, width, height, rotation)
44
+ }
46
45
 
47
- leaferPaint.style = createPattern(image.getCanvas(width, height, opacity), transform, mode === 'repeat')
46
+ leaferPaint.style = createPattern(image.getCanvas(width, height, opacity), transform, mode === 'repeat')
47
+
48
+ }
48
49
 
49
50
  } else {
50
51
 
51
52
  imageManager.load(image,
52
53
  () => {
53
- if (!ui.__.__getInput('width')) ui.width = image.width
54
- if (!ui.__.__getInput('height')) ui.height = image.height
55
- ui.forceUpdate('width')
56
- ui.emitEvent(new ImageEvent(ImageEvent.LOADED, ui, image, attrName, paint))
54
+ if (ui.leafer) {
55
+ if (hasSize(ui, attrName, image)) ui.forceUpdate('width')
56
+ ui.emitEvent(new ImageEvent(ImageEvent.LOADED, ui, image, attrName, paint))
57
+ }
57
58
  },
58
59
  (error) => {
59
60
  ui.emitEvent(new ImageEvent(ImageEvent.ERROR, ui, image, attrName, paint, error))
@@ -65,6 +66,23 @@ export function image(ui: IUI, attrName: string, paint: IImagePaint, box: IBound
65
66
  return leaferPaint
66
67
  }
67
68
 
69
+ function hasSize(ui: IUI, attrName: string, image: ISizeData): boolean {
70
+ const { __: data } = ui
71
+
72
+ if (attrName === 'fill' && data) {
73
+ if (!data.__naturalWidth || !data.__naturalHeight) {
74
+ data.__naturalWidth = image.width
75
+ data.__naturalHeight = image.height
76
+ if (!data.__getInput('width') || !data.__getInput('height')) {
77
+ ui.forceUpdate('width')
78
+ return false
79
+ }
80
+ }
81
+ }
82
+
83
+ return true
84
+ }
85
+
68
86
  function getFillOrFitTransform(mode: IImagePaintMode, box: IBoundsData, width: number, height: number, rotation: number): IMatrixData {
69
87
  const transform: IMatrixData = get()
70
88
  const swap = rotation && rotation !== 180
@@ -18,11 +18,9 @@ export function linearGradient(paint: IGradientPaint, box: IBoundsData): ILeafPa
18
18
  const style = Platform.canvas.createLinearGradient(box.x + from.x * box.width, box.y + from.y * box.height, box.x + to.x * box.width, box.y + to.y * box.height)
19
19
  applyStops(style, paint.stops, opacity)
20
20
 
21
- return {
22
- type,
23
- blendMode,
24
- style
25
- }
21
+ const data: ILeafPaint = { type, style }
22
+ if (blendMode) data.blendMode = blendMode
23
+ return data
26
24
 
27
25
  }
28
26
 
@@ -37,11 +37,8 @@ export function radialGradient(paint: IGradientPaint, box: IBoundsData): ILeafPa
37
37
  const style = Platform.canvas.createRadialGradient(realFrom.x, realFrom.y, 0, realFrom.x, realFrom.y, getDistance(realFrom, realTo))
38
38
  applyStops(style, paint.stops, opacity)
39
39
 
40
- return {
41
- type,
42
- blendMode,
43
- style,
44
- transform
45
- }
40
+ const data: ILeafPaint = { type, style, transform }
41
+ if (blendMode) data.blendMode = blendMode
42
+ return data
46
43
 
47
44
  }