@leafer-ui/gradient 1.6.2 → 1.6.4

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.6.2",
3
+ "version": "1.6.4",
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.6.2",
26
- "@leafer-ui/draw": "1.6.2"
25
+ "@leafer/core": "1.6.4",
26
+ "@leafer-ui/draw": "1.6.4"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.6.2",
30
- "@leafer-ui/interface": "1.6.2"
29
+ "@leafer/interface": "1.6.4",
30
+ "@leafer-ui/interface": "1.6.4"
31
31
  }
32
32
  }
package/src/conic.ts CHANGED
@@ -15,18 +15,18 @@ const realTo = {} as IPointData
15
15
 
16
16
  export function conicGradient(paint: IGradientPaint, box: IBoundsData): ILeafPaint {
17
17
 
18
- let { from, to, type, opacity, blendMode, stretch } = paint
18
+ let { from, to, type, opacity, stretch } = paint
19
19
 
20
20
  toPoint(from || 'center', box, realFrom)
21
21
  toPoint(to || 'bottom', box, realTo)
22
22
 
23
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))
24
- applyStops(style, paint.stops, opacity)
25
-
26
24
  const data: ILeafPaint = { type, style }
25
+
26
+ applyStops(data, style, paint.stops, opacity)
27
+
27
28
  const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90)
28
29
  if (transform) data.transform = transform
29
- if (blendMode) data.blendMode = blendMode
30
30
 
31
31
  return data
32
32
 
package/src/linear.ts CHANGED
@@ -5,36 +5,36 @@ import { IGradientPaint, ILeafPaint, IColorStop, IColorString } from '@leafer-ui
5
5
  import { ColorConvert } from '@leafer-ui/draw'
6
6
 
7
7
 
8
- const { toPoint } = AroundHelper
8
+ const { toPoint } = AroundHelper, { hasTransparent } = ColorConvert
9
9
  const realFrom = {} as IPointData
10
10
  const realTo = {} as IPointData
11
11
 
12
12
  export function linearGradient(paint: IGradientPaint, box: IBoundsData): ILeafPaint {
13
13
 
14
- let { from, to, type, blendMode, opacity } = paint
14
+ let { from, to, type, opacity } = paint
15
15
 
16
16
  toPoint(from || 'top', box, realFrom)
17
17
  toPoint(to || 'bottom', box, realTo)
18
18
 
19
19
  const style = Platform.canvas.createLinearGradient(realFrom.x, realFrom.y, realTo.x, realTo.y)
20
- applyStops(style, paint.stops, opacity)
21
-
22
20
  const data: ILeafPaint = { type, style }
23
- if (blendMode) data.blendMode = blendMode
21
+
22
+ applyStops(data, style, paint.stops, opacity)
23
+
24
24
  return data
25
25
 
26
26
  }
27
27
 
28
- export function applyStops(gradient: IObject, stops: IColorStop[] | IColorString[], opacity: number): void {
28
+ export function applyStops(data: ILeafPaint, gradient: IObject, stops: IColorStop[] | IColorString[], opacity: number): void {
29
29
  if (stops) {
30
- let stop: IColorStop | string
30
+ let stop: IColorStop | string, color: string, offset: number, isTransparent: boolean
31
31
  for (let i = 0, len = stops.length; i < len; i++) {
32
32
  stop = stops[i]
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
- }
33
+ if (typeof stop === 'string') offset = i / (len - 1), color = ColorConvert.string(stop, opacity)
34
+ else offset = stop.offset, color = ColorConvert.string(stop.color, opacity)
35
+ gradient.addColorStop(offset, color)
36
+ if (!isTransparent && hasTransparent(color)) isTransparent = true
38
37
  }
38
+ if (isTransparent) data.isTransparent = true
39
39
  }
40
40
  }
package/src/radial.ts CHANGED
@@ -15,18 +15,18 @@ const realTo = {} as IPointData
15
15
 
16
16
  export function radialGradient(paint: IGradientPaint, box: IBoundsData): ILeafPaint {
17
17
 
18
- let { from, to, type, opacity, blendMode, stretch } = paint
18
+ let { from, to, type, opacity, stretch } = paint
19
19
 
20
20
  toPoint(from || 'center', box, realFrom)
21
21
  toPoint(to || 'bottom', box, realTo)
22
22
 
23
23
  const style = Platform.canvas.createRadialGradient(realFrom.x, realFrom.y, 0, realFrom.x, realFrom.y, getDistance(realFrom, realTo))
24
- applyStops(style, paint.stops, opacity)
25
-
26
24
  const data: ILeafPaint = { type, style }
25
+
26
+ applyStops(data, style, paint.stops, opacity)
27
+
27
28
  const transform = getTransform(box, realFrom, realTo, stretch, true)
28
29
  if (transform) data.transform = transform
29
- if (blendMode) data.blendMode = blendMode
30
30
 
31
31
  return data
32
32