@leafer-ui/paint 1.0.0-rc.7 → 1.0.0-rc.9

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-rc.7",
3
+ "version": "1.0.0-rc.9",
4
4
  "description": "@leafer-ui/paint",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,10 +22,10 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.0-rc.7"
25
+ "@leafer/core": "1.0.0-rc.9"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.7",
29
- "@leafer-ui/interface": "1.0.0-rc.7"
28
+ "@leafer/interface": "1.0.0-rc.9",
29
+ "@leafer-ui/interface": "1.0.0-rc.9"
30
30
  }
31
31
  }
@@ -19,7 +19,7 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
19
19
  const { data } = paint
20
20
 
21
21
  if (allowPaint) {
22
- if (data.mode !== 'repeat') {
22
+ if (!data.repeat) {
23
23
  let { width, height } = data
24
24
  width *= abs(scaleX) * canvas.pixelRatio
25
25
  height *= abs(scaleY) * canvas.pixelRatio
@@ -11,12 +11,23 @@ const { get, translate } = MatrixHelper
11
11
  export function createData(leafPaint: ILeafPaint, image: ILeaferImage, paint: IImagePaint, box: IBoundsData): void {
12
12
  let { width, height } = image
13
13
 
14
- const { opacity, mode, offset, scale, rotation, blendMode } = paint
14
+
15
+ const { opacity, mode, offset, scale, size, rotation, blendMode, repeat } = paint
15
16
  const sameBox = box.width === width && box.height === height
16
17
  if (blendMode) leafPaint.blendMode = blendMode
17
18
 
18
19
  const data: ILeafPaintPatternData = leafPaint.data = { mode }
19
20
 
21
+ let x: number, y: number, scaleX: number, scaleY: number
22
+ if (offset) x = offset.x, y = offset.y
23
+ if (size) {
24
+ scaleX = (typeof size === 'number' ? size : size.width) / width
25
+ scaleY = (typeof size === 'number' ? size : size.height) / height
26
+ } else if (scale) {
27
+ scaleX = typeof scale === 'number' ? scale : scale.x
28
+ scaleY = typeof scale === 'number' ? scale : scale.y
29
+ }
30
+
20
31
  switch (mode) {
21
32
  case 'strench':
22
33
  if (!sameBox) width = box.width, height = box.height
@@ -26,10 +37,11 @@ export function createData(leafPaint: ILeafPaint, image: ILeaferImage, paint: II
26
37
  }
27
38
  break
28
39
  case 'clip':
29
- if (offset || scale || rotation) clipMode(data, box, offset, scale, rotation)
40
+ if (offset || scaleX || rotation) clipMode(data, box, x, y, scaleX, scaleY, rotation)
30
41
  break
31
42
  case 'repeat':
32
- if (!sameBox || scale || rotation) repeatMode(data, box, width, height, scale as number, rotation)
43
+ if (!sameBox || scaleX || rotation) repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation)
44
+ if (!repeat) data.repeat = 'repeat'
33
45
  break
34
46
  case 'fit':
35
47
  case 'cover':
@@ -40,4 +52,5 @@ export function createData(leafPaint: ILeafPaint, image: ILeaferImage, paint: II
40
52
  data.width = width
41
53
  data.height = height
42
54
  if (opacity) data.opacity = opacity
55
+ if (repeat) data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat'
43
56
  }
@@ -64,11 +64,11 @@ function hasNaturalSize(ui: IUI, attrName: string, image: ISizeData): boolean {
64
64
  d.__naturalWidth = image.width
65
65
  d.__naturalHeight = image.height
66
66
  if (!d.__getInput('width') || !d.__getInput('height')) {
67
+ ui.forceUpdate('width')
67
68
  if (ui.__proxyData) {
68
69
  ui.setProxyAttr('width', ui.__.width)
69
70
  ui.setProxyAttr('height', ui.__.height)
70
71
  }
71
- ui.forceUpdate('width')
72
72
  return false
73
73
  }
74
74
  }
@@ -1,9 +1,10 @@
1
- import { IBoundsData } from '@leafer/interface'
1
+ import { IBoundsData, IPointData, IMatrixData, } from '@leafer/interface'
2
2
  import { MatrixHelper } from '@leafer/core'
3
3
 
4
- import { IMatrixData, IImagePaintMode, IPointData, ILeafPaintPatternData } from '@leafer-ui/interface'
4
+ import { IImagePaintMode, ILeafPaintPatternData } from '@leafer-ui/interface'
5
5
 
6
6
 
7
+ let origin = {} as IPointData
7
8
  const { get, rotateOfOuter, translate, scaleOfOuter, scale: scaleHelper, rotate } = MatrixHelper
8
9
 
9
10
  export function fillOrFitMode(data: ILeafPaintPatternData, mode: IImagePaintMode, box: IBoundsData, width: number, height: number, rotation: number): void {
@@ -22,12 +23,12 @@ export function fillOrFitMode(data: ILeafPaintPatternData, mode: IImagePaintMode
22
23
  }
23
24
 
24
25
 
25
- export function clipMode(data: ILeafPaintPatternData, box: IBoundsData, offset: IPointData, scale: number | IPointData, rotation: number): void {
26
+ export function clipMode(data: ILeafPaintPatternData, box: IBoundsData, x: number, y: number, scaleX: number, scaleY: number, rotation: number): void {
26
27
  const transform: IMatrixData = get()
27
28
  translate(transform, box.x, box.y)
28
- if (offset) translate(transform, offset.x, offset.y)
29
- if (scale) {
30
- typeof scale === 'number' ? scaleHelper(transform, scale) : scaleHelper(transform, scale.x, scale.y)
29
+ if (x || y) translate(transform, x, y)
30
+ if (scaleX) {
31
+ scaleHelper(transform, scaleX, scaleY)
31
32
  data.scaleX = transform.a
32
33
  data.scaleY = transform.d
33
34
  }
@@ -36,9 +37,8 @@ export function clipMode(data: ILeafPaintPatternData, box: IBoundsData, offset:
36
37
  }
37
38
 
38
39
 
39
- export function repeatMode(data: ILeafPaintPatternData, box: IBoundsData, width: number, height: number, scale: number, rotation: number): void {
40
+ export function repeatMode(data: ILeafPaintPatternData, box: IBoundsData, width: number, height: number, x: number, y: number, scaleX: number, scaleY: number, rotation: number): void {
40
41
  const transform = get()
41
-
42
42
  if (rotation) {
43
43
  rotate(transform, rotation)
44
44
  switch (rotation) {
@@ -53,10 +53,14 @@ export function repeatMode(data: ILeafPaintPatternData, box: IBoundsData, width:
53
53
  break
54
54
  }
55
55
  }
56
- translate(transform, box.x, box.y)
57
- if (scale) {
58
- scaleOfOuter(transform, box, scale)
59
- data.scaleX = data.scaleY = scale
56
+ origin.x = box.x
57
+ origin.y = box.y
58
+ if (x || y) origin.x += x, origin.y += y
59
+ translate(transform, origin.x, origin.y)
60
+ if (scaleX) {
61
+ scaleOfOuter(transform, origin, scaleX, scaleY)
62
+ data.scaleX = scaleX
63
+ data.scaleY = scaleY
60
64
  }
61
65
  data.transform = transform
62
66
  }
@@ -17,7 +17,7 @@ export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): b
17
17
  scaleY = Math.abs(scaleY)
18
18
 
19
19
  const { image, data } = paint
20
- let imageScale: number, imageMatrix: IMatrixData, { width, height, scaleX: sx, scaleY: sy, opacity, transform, mode } = data
20
+ let imageScale: number, imageMatrix: IMatrixData, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data
21
21
 
22
22
  if (sx) {
23
23
  imageMatrix = get()
@@ -34,7 +34,7 @@ export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): b
34
34
 
35
35
  const size = width * height
36
36
 
37
- if (paint.data.mode !== 'repeat') {
37
+ if (!repeat) {
38
38
  if (size > Platform.image.maxCacheSize) return false // same as check()
39
39
  }
40
40
 
@@ -67,7 +67,7 @@ export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): b
67
67
  scale(imageMatrix, 1 / scaleX, 1 / scaleY)
68
68
  }
69
69
 
70
- const pattern = Platform.canvas.createPattern(image.getCanvas(width < 1 ? 1 : width, height < 1 ? 1 : height, opacity) as any, mode === 'repeat' ? 'repeat' : (Platform.origin.noRepeat || 'no-repeat'))
70
+ const pattern = Platform.canvas.createPattern(image.getCanvas(width < 1 ? 1 : width, height < 1 ? 1 : height, opacity) as any, repeat || (Platform.origin.noRepeat || 'no-repeat'))
71
71
 
72
72
  try {
73
73
  if (paint.transform) paint.transform = null