@leafer-ui/image 1.0.0-rc.17 → 1.0.0-rc.18

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/image",
3
- "version": "1.0.0-rc.17",
3
+ "version": "1.0.0-rc.18",
4
4
  "description": "@leafer-ui/image",
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.17",
26
- "@leafer/draw": "1.0.0-rc.17"
25
+ "@leafer/core": "1.0.0-rc.18",
26
+ "@leafer/draw": "1.0.0-rc.18"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.0.0-rc.17",
30
- "@leafer-ui/interface": "1.0.0-rc.17"
29
+ "@leafer/interface": "1.0.0-rc.18",
30
+ "@leafer-ui/interface": "1.0.0-rc.18"
31
31
  }
32
32
  }
package/src/check.ts CHANGED
@@ -10,7 +10,7 @@ import { createPattern } from './pattern'
10
10
  const { abs } = Math
11
11
 
12
12
  export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, allowPaint?: boolean): boolean {
13
- const { scaleX, scaleY } = ui.__world
13
+ const { scaleX, scaleY } = ui.__nowWorld
14
14
 
15
15
  if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
16
16
  return false
@@ -49,7 +49,7 @@ export function checkImage(ui: IUI, canvas: ILeaferCanvas, paint: ILeafPaint, al
49
49
  if (!paint.patternTask) {
50
50
  paint.patternTask = ImageManager.patternTasker.add(async () => {
51
51
  paint.patternTask = null
52
- if (canvas.bounds.hit(ui.__world)) createPattern(ui, paint, canvas.pixelRatio)
52
+ if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, canvas.pixelRatio)
53
53
  ui.forceUpdate('surface')
54
54
  }, 300)
55
55
  }
package/src/data.ts CHANGED
@@ -30,10 +30,6 @@ export function createData(leafPaint: ILeafPaint, image: ILeaferImage, paint: II
30
30
  switch (mode) {
31
31
  case 'strench':
32
32
  if (!sameBox) width = box.width, height = box.height
33
- if (box.x || box.y) {
34
- data.transform = get()
35
- translate(data.transform, box.x, box.y)
36
- }
37
33
  break
38
34
  case 'clip':
39
35
  if (offset || scaleX || rotation) clipMode(data, box, x, y, scaleX, scaleY, rotation)
@@ -48,6 +44,13 @@ export function createData(leafPaint: ILeafPaint, image: ILeaferImage, paint: II
48
44
  if (!sameBox || rotation) fillOrFitMode(data, mode, box, width, height, rotation)
49
45
  }
50
46
 
47
+ if (!data.transform) {
48
+ if (box.x || box.y) {
49
+ data.transform = get()
50
+ translate(data.transform, box.x, box.y)
51
+ }
52
+ }
53
+
51
54
  data.width = width
52
55
  data.height = height
53
56
  if (opacity) data.opacity = opacity
package/src/image.ts CHANGED
@@ -22,8 +22,7 @@ export function image(ui: IUI, attrName: string, paint: IImagePaint, boxBounds:
22
22
  if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
23
23
  leafPaint = cache.leafPaint
24
24
  } else {
25
- leafPaint = { type: paint.type }
26
- leafPaint.image = image
25
+ leafPaint = { type: paint.type, image }
27
26
 
28
27
  cache = image.use > 1 ? { leafPaint, paint, boxBounds: box.set(boxBounds) } : null
29
28
  }
@@ -45,10 +44,13 @@ export function image(ui: IUI, attrName: string, paint: IImagePaint, boxBounds:
45
44
 
46
45
  } else { // need load
47
46
 
47
+ ignoreRender(ui, true) // wait loaded
48
+
48
49
  if (firstUse) onLoad(ui, event)
49
50
 
50
51
  leafPaint.loadId = image.load(
51
52
  () => {
53
+ ignoreRender(ui, false)
52
54
  if (!ui.destroyed) {
53
55
  if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) ui.forceUpdate('surface')
54
56
  onLoadSuccess(ui, event)
@@ -56,6 +58,7 @@ export function image(ui: IUI, attrName: string, paint: IImagePaint, boxBounds:
56
58
  leafPaint.loadId = null
57
59
  },
58
60
  (error) => {
61
+ ignoreRender(ui, false)
59
62
  onLoadError(ui, event, error)
60
63
  leafPaint.loadId = null
61
64
  }
@@ -107,4 +110,9 @@ function onLoadError(ui: IUI, event: IImageEvent, error: string | IObject,): voi
107
110
 
108
111
  function emit(ui: IUI, type: string, data: IImageEvent): void {
109
112
  if (ui.hasEvent(type)) ui.emitEvent(new ImageEvent(type, data))
113
+ }
114
+
115
+ function ignoreRender(ui: IUI, value: boolean): void {
116
+ const { leafer } = ui
117
+ if (leafer && leafer.viewReady) leafer.renderer.ignore = value // prevent blink on hover
110
118
  }
package/src/pattern.ts CHANGED
@@ -8,7 +8,7 @@ const { ceil, abs } = Math
8
8
 
9
9
  export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): boolean {
10
10
 
11
- let { scaleX, scaleY } = ui.__world
11
+ let { scaleX, scaleY } = ui.__nowWorld
12
12
 
13
13
  const id = scaleX + '-' + scaleY
14
14