@leafer-ui/paint 1.8.0 → 1.9.1

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.8.0",
3
+ "version": "1.9.1",
4
4
  "description": "@leafer-ui/paint",
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.8.0",
26
- "@leafer-ui/draw": "1.8.0"
25
+ "@leafer/core": "1.9.1",
26
+ "@leafer-ui/draw": "1.9.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.8.0",
30
- "@leafer-ui/interface": "1.8.0"
29
+ "@leafer/interface": "1.9.1",
30
+ "@leafer-ui/interface": "1.9.1"
31
31
  }
32
32
  }
package/src/Compute.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DataHelper } from '@leafer/core'
1
+ import { DataHelper, isArray, isObject, isString, isUndefined } from '@leafer/core'
2
2
 
3
3
  import { IUI, IPaint, ILeafPaint, IRGB, IBooleanMap, IObject, IPaintAttr, IStrokeComputedStyle } from '@leafer-ui/interface'
4
4
  import { ColorConvert, PaintImage, PaintGradient } from '@leafer-ui/draw'
@@ -11,7 +11,7 @@ export function compute(attrName: IPaintAttr, ui: IUI): void {
11
11
  const data = ui.__, leafPaints: ILeafPaint[] = []
12
12
 
13
13
  let paints: IPaint[] = data.__input[attrName], isAlphaPixel: boolean, isTransparent: boolean
14
- if (!(paints instanceof Array)) paints = [paints]
14
+ if (!isArray(paints)) paints = [paints]
15
15
 
16
16
  recycleMap = PaintImage.recycleImage(attrName, data)
17
17
 
@@ -50,7 +50,7 @@ export function compute(attrName: IPaintAttr, ui: IUI): void {
50
50
 
51
51
 
52
52
  function getLeafPaint(attrName: string, paint: IPaint, ui: IUI): ILeafPaint {
53
- if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0) return undefined
53
+ if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined
54
54
 
55
55
  let data: ILeafPaint
56
56
  const { boxBounds } = ui.__layout
@@ -73,15 +73,18 @@ function getLeafPaint(attrName: string, paint: IPaint, ui: IUI): ILeafPaint {
73
73
  data = { type, style: ColorConvert.string(color, opacity) }
74
74
  break
75
75
  default:
76
- if ((paint as IRGB).r !== undefined) data = { type: 'solid', style: ColorConvert.string(paint) }
76
+ if (!isUndefined((paint as IRGB).r)) data = { type: 'solid', style: ColorConvert.string(paint) }
77
77
  }
78
78
 
79
79
  if (data) {
80
- if (typeof data.style === 'string' && hasTransparent(data.style)) data.isTransparent = true
80
+ // 描边样式
81
+ if (isString(data.style) && hasTransparent(data.style)) data.isTransparent = true
81
82
  if (paint.style) {
82
83
  if (paint.style.strokeWidth === 0) return undefined
83
84
  data.strokeStyle = paint.style as IStrokeComputedStyle
84
85
  }
86
+
87
+ if (paint.editing) data.editing = paint.editing
85
88
  if (paint.blendMode) data.blendMode = paint.blendMode
86
89
  }
87
90
 
package/src/Fill.ts CHANGED
@@ -36,7 +36,7 @@ export function fills(fills: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void
36
36
  if (item.transform) canvas.transform(item.transform)
37
37
  if (item.scaleFixed) {
38
38
  const { scaleX, scaleY } = ui.getRenderScaleData(true)
39
- canvas.scale(1 / scaleX, 1 / scaleY)
39
+ if (item.scaleFixed === true || (item.scaleFixed === 'zoom-in' && scaleX > 1 && scaleY > 1)) canvas.scale(1 / scaleX, 1 / scaleY)
40
40
  }
41
41
  if (item.blendMode) canvas.blendMode = item.blendMode
42
42
  fillPathOrText(ui, canvas)
package/src/Shape.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IBoundsData, ILeaferCanvas, IRenderOptions, IMatrix } from '@leafer/interface'
2
- import { BoundsHelper } from '@leafer/core'
2
+ import { BoundsHelper, Matrix, Platform } from '@leafer/core'
3
3
 
4
4
  import { IUI, ICachedShape } from '@leafer-ui/interface'
5
5
 
@@ -8,15 +8,13 @@ const { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper
8
8
 
9
9
  export function shape(ui: IUI, current: ILeaferCanvas, options: IRenderOptions): ICachedShape {
10
10
  const canvas = current.getSameCanvas()
11
- const nowWorld = ui.__nowWorld
11
+ const nowWorld = ui.__nowWorld, currentBounds = current.bounds
12
12
 
13
- let bounds: IBoundsData, fitMatrix: IMatrix, shapeBounds: IBoundsData, worldCanvas: ILeaferCanvas
13
+ let bounds: IBoundsData, matrix: IMatrix, fitMatrix: IMatrix, shapeBounds: IBoundsData, worldCanvas: ILeaferCanvas
14
14
 
15
- let { scaleX, scaleY } = nowWorld
16
- if (scaleX < 0) scaleX = -scaleX
17
- if (scaleY < 0) scaleY = -scaleY
15
+ let { scaleX, scaleY } = ui.getRenderScaleData(true)
18
16
 
19
- if (current.bounds.includes(nowWorld)) {
17
+ if (currentBounds.includes(nowWorld)) {
20
18
 
21
19
  worldCanvas = canvas
22
20
  bounds = shapeBounds = nowWorld
@@ -24,8 +22,17 @@ export function shape(ui: IUI, current: ILeaferCanvas, options: IRenderOptions):
24
22
  } else {
25
23
 
26
24
  const { renderShapeSpread: spread } = ui.__layout
27
- const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [spread * scaleY, spread * scaleX]) : current.bounds, nowWorld)
28
- fitMatrix = current.bounds.getFitMatrix(worldClipBounds)
25
+
26
+ let worldClipBounds: IBoundsData // 作为绘制阴影的裁剪形状
27
+
28
+ if (Platform.fullImageShadow) { // fix: iOS Safari 18.5 以上, 只裁剪部分区域渲染阴影会有问题
29
+ worldClipBounds = nowWorld
30
+ } else {
31
+ const spreadBounds = spread ? getSpread(currentBounds, scaleX === scaleY ? spread * scaleX : [spread * scaleY, spread * scaleX]) : currentBounds
32
+ worldClipBounds = getIntersectData(spreadBounds, nowWorld)
33
+ }
34
+
35
+ fitMatrix = currentBounds.getFitMatrix(worldClipBounds)
29
36
  let { a: fitScaleX, d: fitScaleY } = fitMatrix
30
37
 
31
38
  if (fitMatrix.a < 1) {
@@ -39,21 +46,22 @@ export function shape(ui: IUI, current: ILeaferCanvas, options: IRenderOptions):
39
46
  shapeBounds = getOuterOf(nowWorld, fitMatrix)
40
47
  bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f)
41
48
 
42
- if (options.matrix) {
43
- const { matrix } = options
44
- fitMatrix.multiply(matrix)
45
- fitScaleX *= matrix.scaleX
46
- fitScaleY *= matrix.scaleY
47
- }
48
-
49
- options = { ...options, matrix: fitMatrix.withScale(fitScaleX, fitScaleY) }
49
+ const userMatrix = options.matrix
50
+ if (userMatrix) {
51
+ matrix = new Matrix(fitMatrix) // 仅用于渲染
52
+ matrix.multiply(userMatrix)
53
+ fitScaleX *= userMatrix.scaleX
54
+ fitScaleY *= userMatrix.scaleY
55
+ } else matrix = fitMatrix
50
56
 
57
+ matrix.withScale(fitScaleX, fitScaleY)
58
+ options = { ...options, matrix }
51
59
  }
52
60
 
53
61
  ui.__renderShape(canvas, options)
54
62
 
55
63
  return {
56
- canvas, matrix: fitMatrix, bounds,
64
+ canvas, matrix, fitMatrix, bounds,
57
65
  worldCanvas, shapeBounds, scaleX, scaleY
58
66
  }
59
67
  }
package/src/Stroke.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeaferCanvas } from '@leafer/interface'
2
- import { LeafHelper } from "@leafer/core"
2
+ import { LeafHelper, isObject } from "@leafer/core"
3
3
 
4
4
  import { IUI, ILeafPaint } from '@leafer-ui/interface'
5
5
  import { Paint } from '@leafer-ui/draw'
@@ -40,7 +40,7 @@ export function strokes(strokes: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas):
40
40
 
41
41
  function drawCenter(stroke: string | ILeafPaint[], strokeWidthScale: number, ui: IUI, canvas: ILeaferCanvas) {
42
42
  const data = ui.__
43
- if (typeof stroke === 'object') {
43
+ if (isObject(stroke)) {
44
44
  drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas)
45
45
  } else {
46
46
  canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data)
package/src/StrokeText.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeaferCanvas } from '@leafer/interface'
2
- import { LeafHelper } from "@leafer/core"
2
+ import { LeafHelper, isObject } from "@leafer/core"
3
3
 
4
4
  import { IUI, ITextRowData, ILeafPaint, IStrokeAlign, ILeafStrokePaint } from '@leafer-ui/interface'
5
5
  import { PaintImage } from "@leafer-ui/draw"
@@ -23,7 +23,7 @@ export function strokeText(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaf
23
23
 
24
24
  function drawCenter(stroke: string | ILeafPaint[], strokeWidthScale: number, ui: IUI, canvas: ILeaferCanvas): void {
25
25
  const data = ui.__
26
- if (typeof stroke === 'object') {
26
+ if (isObject(stroke)) {
27
27
  drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas)
28
28
  } else {
29
29
  canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data)