@leafer-ui/paint 1.0.0-rc.8 → 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.8",
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.8"
25
+ "@leafer/core": "1.0.0-rc.9"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.8",
29
- "@leafer-ui/interface": "1.0.0-rc.8"
28
+ "@leafer/interface": "1.0.0-rc.9",
29
+ "@leafer-ui/interface": "1.0.0-rc.9"
30
30
  }
31
31
  }
@@ -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, repeat } = 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,10 @@ 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)
33
44
  if (!repeat) data.repeat = 'repeat'
34
45
  break
35
46
  case 'fit':
@@ -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
  }