@leafer-ui/gradient 1.0.0-rc.25 → 1.0.0-rc.27

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/gradient",
3
- "version": "1.0.0-rc.25",
3
+ "version": "1.0.0-rc.27",
4
4
  "description": "@leafer-ui/gradient",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.0-rc.25",
26
- "@leafer-ui/draw": "1.0.0-rc.25"
25
+ "@leafer/core": "1.0.0-rc.27",
26
+ "@leafer-ui/draw": "1.0.0-rc.27"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-rc.25",
30
- "@leafer-ui/interface": "1.0.0-rc.25"
29
+ "@leafer/interface": "1.0.0-rc.27",
30
+ "@leafer-ui/interface": "1.0.0-rc.27"
31
31
  }
32
32
  }
package/src/conic.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { IMatrixData, IPointData, IBoundsData } from '@leafer/interface'
2
- import { Platform, PointHelper, MatrixHelper, AroundHelper } from '@leafer/core'
1
+ import { IPointData, IBoundsData } from '@leafer/interface'
2
+ import { Platform, PointHelper, AroundHelper } from '@leafer/core'
3
3
 
4
4
  import { IGradientPaint, ILeafPaint } from '@leafer-ui/interface'
5
5
 
6
6
  import { applyStops } from './linear'
7
+ import { getTransform } from './radial'
7
8
 
8
9
 
9
- const { getAngle, getDistance } = PointHelper
10
- const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper
10
+ const { getDistance } = PointHelper
11
11
 
12
12
  const { toPoint } = AroundHelper
13
13
  const realFrom = {} as IPointData
@@ -20,23 +20,14 @@ export function conicGradient(paint: IGradientPaint, box: IBoundsData): ILeafPai
20
20
  toPoint(from || 'center', box, realFrom)
21
21
  toPoint(to || 'bottom', box, realTo)
22
22
 
23
- const { width, height } = box
24
- const transform: IMatrixData = get()
25
- const angle = getAngle(realFrom, realTo)
26
-
27
- if (Platform.conicGradientRotate90) {
28
- scaleOfOuter(transform, realFrom, width / height * (stretch || 1), 1)
29
- rotateOfOuter(transform, realFrom, angle + 90)
30
- } else {
31
- scaleOfOuter(transform, realFrom, 1, width / height * (stretch || 1))
32
- rotateOfOuter(transform, realFrom, angle)
33
- }
34
-
35
23
  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))
36
24
  applyStops(style, paint.stops, opacity)
37
25
 
38
- const data: ILeafPaint = { type, style, transform }
26
+ const data: ILeafPaint = { type, style }
27
+ const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90)
28
+ if (transform) data.transform = transform
39
29
  if (blendMode) data.blendMode = blendMode
30
+
40
31
  return data
41
32
 
42
33
  }
package/src/index.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { IPaintGradientModule } from '@leafer-ui/interface'
2
2
 
3
3
  import { linearGradient } from './linear'
4
- import { radialGradient } from './radial'
4
+ import { radialGradient, getTransform } from './radial'
5
5
  import { conicGradient } from './conic'
6
6
 
7
7
 
8
8
  export const PaintGradientModule: IPaintGradientModule = {
9
9
  linearGradient,
10
10
  radialGradient,
11
- conicGradient
11
+ conicGradient,
12
+ getTransform
12
13
  }
package/src/radial.ts CHANGED
@@ -20,20 +20,33 @@ export function radialGradient(paint: IGradientPaint, box: IBoundsData): ILeafPa
20
20
  toPoint(from || 'center', box, realFrom)
21
21
  toPoint(to || 'bottom', box, realTo)
22
22
 
23
- const { width, height } = box
24
- let transform: IMatrixData
25
-
26
- if (width !== height || stretch) {
27
- transform = get()
28
- scaleOfOuter(transform, realFrom, width / height * (stretch || 1), 1)
29
- rotateOfOuter(transform, realFrom, getAngle(realFrom, realTo) + 90)
30
- }
31
-
32
23
  const style = Platform.canvas.createRadialGradient(realFrom.x, realFrom.y, 0, realFrom.x, realFrom.y, getDistance(realFrom, realTo))
33
24
  applyStops(style, paint.stops, opacity)
34
25
 
35
- const data: ILeafPaint = { type, style, transform }
26
+ const data: ILeafPaint = { type, style }
27
+ const transform = getTransform(box, realFrom, realTo, stretch, true)
28
+ if (transform) data.transform = transform
36
29
  if (blendMode) data.blendMode = blendMode
30
+
37
31
  return data
38
32
 
33
+ }
34
+
35
+ export function getTransform(box: IBoundsData, from: IPointData, to: IPointData, stretch: number, rotate90: boolean): IMatrixData {
36
+ let transform: IMatrixData
37
+ const { width, height } = box
38
+
39
+ if (width !== height || stretch) {
40
+ const angle = getAngle(from, to)
41
+ transform = get()
42
+ if (rotate90) {
43
+ scaleOfOuter(transform, from, width / height * (stretch || 1), 1)
44
+ rotateOfOuter(transform, from, angle + 90)
45
+ } else {
46
+ scaleOfOuter(transform, from, 1, width / height * (stretch || 1))
47
+ rotateOfOuter(transform, from, angle)
48
+ }
49
+ }
50
+
51
+ return transform
39
52
  }