@leafer-ui/gradient 1.0.0-rc.23 → 1.0.0-rc.24
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 +5 -5
- package/src/conic.ts +6 -12
- package/src/linear.ts +18 -11
- package/src/radial.ts +6 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/gradient",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.24",
|
|
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.
|
|
26
|
-
"@leafer-ui/draw": "1.0.0-rc.
|
|
25
|
+
"@leafer/core": "1.0.0-rc.24",
|
|
26
|
+
"@leafer-ui/draw": "1.0.0-rc.24"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.0.0-rc.
|
|
30
|
-
"@leafer-ui/interface": "1.0.0-rc.
|
|
29
|
+
"@leafer/interface": "1.0.0-rc.24",
|
|
30
|
+
"@leafer-ui/interface": "1.0.0-rc.24"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/conic.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { IMatrixData, IPointData, IBoundsData } from '@leafer/interface'
|
|
2
|
-
import { Platform, PointHelper, MatrixHelper } from '@leafer/core'
|
|
2
|
+
import { Platform, PointHelper, MatrixHelper, AroundHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { IGradientPaint, ILeafPaint } from '@leafer-ui/interface'
|
|
5
5
|
|
|
6
6
|
import { applyStops } from './linear'
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const { getAngle, getDistance } = PointHelper
|
|
10
10
|
const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
const defaultTo = { x: 0.5, y: 1 }
|
|
14
|
-
|
|
12
|
+
const { toPoint } = AroundHelper
|
|
15
13
|
const realFrom = {} as IPointData
|
|
16
14
|
const realTo = {} as IPointData
|
|
17
15
|
|
|
@@ -19,14 +17,10 @@ export function conicGradient(paint: IGradientPaint, box: IBoundsData): ILeafPai
|
|
|
19
17
|
|
|
20
18
|
let { from, to, type, opacity, blendMode, stretch } = paint
|
|
21
19
|
|
|
22
|
-
from ||
|
|
23
|
-
to ||
|
|
24
|
-
|
|
25
|
-
const { x, y, width, height } = box
|
|
26
|
-
|
|
27
|
-
set(realFrom, x + from.x * width, y + from.y * height)
|
|
28
|
-
set(realTo, x + to.x * width, y + to.y * height)
|
|
20
|
+
toPoint(from || 'center', box, realFrom)
|
|
21
|
+
toPoint(to || 'bottom', box, realTo)
|
|
29
22
|
|
|
23
|
+
const { width, height } = box
|
|
30
24
|
const transform: IMatrixData = get()
|
|
31
25
|
const angle = getAngle(realFrom, realTo)
|
|
32
26
|
|
package/src/linear.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { IObject, IBoundsData } from '@leafer/interface'
|
|
2
|
-
import { Platform } from '@leafer/core'
|
|
1
|
+
import { IObject, IBoundsData, IPointData } from '@leafer/interface'
|
|
2
|
+
import { AroundHelper, Platform } from '@leafer/core'
|
|
3
3
|
|
|
4
|
-
import { IGradientPaint, ILeafPaint, IColorStop } from '@leafer-ui/interface'
|
|
4
|
+
import { IGradientPaint, ILeafPaint, IColorStop, IColorString } from '@leafer-ui/interface'
|
|
5
5
|
import { ColorConvert } from '@leafer-ui/draw'
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const { toPoint } = AroundHelper
|
|
9
|
+
const realFrom = {} as IPointData
|
|
10
|
+
const realTo = {} as IPointData
|
|
10
11
|
|
|
11
12
|
export function linearGradient(paint: IGradientPaint, box: IBoundsData): ILeafPaint {
|
|
12
13
|
|
|
13
14
|
let { from, to, type, blendMode, opacity } = paint
|
|
14
15
|
|
|
15
|
-
from ||
|
|
16
|
-
to ||
|
|
16
|
+
toPoint(from || 'top', box, realFrom)
|
|
17
|
+
toPoint(to || 'bottom', box, realTo)
|
|
17
18
|
|
|
18
|
-
const style = Platform.canvas.createLinearGradient(
|
|
19
|
+
const style = Platform.canvas.createLinearGradient(realFrom.x, realFrom.y, realTo.x, realTo.y)
|
|
19
20
|
applyStops(style, paint.stops, opacity)
|
|
20
21
|
|
|
21
22
|
const data: ILeafPaint = { type, style }
|
|
@@ -24,10 +25,16 @@ export function linearGradient(paint: IGradientPaint, box: IBoundsData): ILeafPa
|
|
|
24
25
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
export function applyStops(gradient: IObject, stops: IColorStop[], opacity: number): void {
|
|
28
|
-
|
|
28
|
+
export function applyStops(gradient: IObject, stops: IColorStop[] | IColorString[], opacity: number): void {
|
|
29
|
+
|
|
30
|
+
let stop: IColorStop | string
|
|
29
31
|
for (let i = 0, len = stops.length; i < len; i++) {
|
|
30
32
|
stop = stops[i]
|
|
31
|
-
|
|
33
|
+
if (typeof stop === 'string') {
|
|
34
|
+
gradient.addColorStop(i / (len - 1), ColorConvert.string(stop, opacity))
|
|
35
|
+
} else {
|
|
36
|
+
gradient.addColorStop(stop.offset, ColorConvert.string(stop.color, opacity))
|
|
37
|
+
}
|
|
32
38
|
}
|
|
39
|
+
|
|
33
40
|
}
|
package/src/radial.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { IBoundsData } from '@leafer/interface'
|
|
2
|
-
import { Platform, PointHelper, MatrixHelper } from '@leafer/core'
|
|
2
|
+
import { Platform, PointHelper, MatrixHelper, AroundHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { IGradientPaint, ILeafPaint, IMatrixData, IPointData } from '@leafer-ui/interface'
|
|
5
5
|
|
|
6
6
|
import { applyStops } from './linear'
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const { getAngle, getDistance } = PointHelper
|
|
10
10
|
const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
const defaultTo = { x: 0.5, y: 1 }
|
|
14
|
-
|
|
12
|
+
const { toPoint } = AroundHelper
|
|
15
13
|
const realFrom = {} as IPointData
|
|
16
14
|
const realTo = {} as IPointData
|
|
17
15
|
|
|
@@ -19,13 +17,10 @@ export function radialGradient(paint: IGradientPaint, box: IBoundsData): ILeafPa
|
|
|
19
17
|
|
|
20
18
|
let { from, to, type, opacity, blendMode, stretch } = paint
|
|
21
19
|
|
|
22
|
-
from ||
|
|
23
|
-
to ||
|
|
24
|
-
|
|
25
|
-
const { x, y, width, height } = box
|
|
26
|
-
set(realFrom, x + from.x * width, y + from.y * height)
|
|
27
|
-
set(realTo, x + to.x * width, y + to.y * height)
|
|
20
|
+
toPoint(from || 'center', box, realFrom)
|
|
21
|
+
toPoint(to || 'bottom', box, realTo)
|
|
28
22
|
|
|
23
|
+
const { width, height } = box
|
|
29
24
|
let transform: IMatrixData
|
|
30
25
|
|
|
31
26
|
if (width !== height || stretch) {
|