@leafer/miniapp-core 2.0.8 → 2.0.9

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.
Files changed (2) hide show
  1. package/package.json +6 -6
  2. package/src/index.ts +13 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/miniapp-core",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "description": "@leafer/miniapp-core",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -24,10 +24,10 @@
24
24
  "leaferjs"
25
25
  ],
26
26
  "dependencies": {
27
- "@leafer/core": "2.0.8",
28
- "@leafer/canvas-miniapp": "2.0.8",
29
- "@leafer/image-miniapp": "2.0.8",
30
- "@leafer/partner": "2.0.8",
31
- "@leafer/interface": "2.0.8"
27
+ "@leafer/core": "2.0.9",
28
+ "@leafer/canvas-miniapp": "2.0.9",
29
+ "@leafer/image-miniapp": "2.0.9",
30
+ "@leafer/partner": "2.0.9",
31
+ "@leafer/interface": "2.0.9"
32
32
  }
33
33
  }
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@ export * from '@leafer/core'
3
3
  export * from '@leafer/canvas-miniapp'
4
4
  export * from '@leafer/image-miniapp'
5
5
 
6
- import { ICanvasType, ICreator, IExportFileType, IExportImageType, IResponseType, IFunction, IObject, IMiniappSelect, IMiniappSizeView, IBoundsData, IImageCrossOrigin, ILeaferImage } from '@leafer/interface'
6
+ import { ICanvasType, ICreator, IExportFileType, ILeaferCanvas, IExportImageType, IResponseType, IFunction, IObject, IMiniappSelect, IMiniappSizeView, IBoundsData, IImageCrossOrigin, ILeaferImage } from '@leafer/interface'
7
7
  import { Platform, Creator, FileHelper, defineKey } from '@leafer/core'
8
8
 
9
9
  import { LeaferCanvas } from '@leafer/canvas-miniapp'
@@ -60,7 +60,7 @@ export function useCanvas(_canvasType: ICanvasType, app?: IObject): void {
60
60
  },
61
61
  loadImage(src: string, _crossOrigin?: IImageCrossOrigin, _leaferImage?: ILeaferImage): Promise<HTMLImageElement> {
62
62
  return new Promise((resolve, reject) => {
63
- const img = Platform.canvas.view.createImage()
63
+ const img = Platform.getCanvas().view.createImage() // 抖音小程序 Platform.canvas 图片无法加载,需使用 Platform.renderCanvas
64
64
  img.onload = () => { resolve(img) }
65
65
  img.onerror = (error: any) => { reject(error) }
66
66
  img.src = Platform.image.getRealURL(src)
@@ -140,11 +140,20 @@ export function useCanvas(_canvasType: ICanvasType, app?: IObject): void {
140
140
 
141
141
  Platform.canvas = Creator.canvas()
142
142
  Platform.conicGradientSupport = !!Platform.canvas.context.createConicGradient
143
+
144
+ defineKey(Platform, 'devicePixelRatio', { get() { return Math.max(1, app.getWindowInfo ? app.getWindowInfo().pixelRatio : app.getSystemInfoSync().pixelRatio) } })
143
145
  }
144
146
 
147
+
145
148
  Platform.name = 'miniapp'
149
+
150
+ Platform.getCanvas = function (): ILeaferCanvas {
151
+ const { renderCanvas } = Platform
152
+ return (renderCanvas && renderCanvas.view) ? renderCanvas : Platform.canvas
153
+ }
154
+
146
155
  Platform.requestRender = function (render: IFunction): void {
147
- const { view } = Platform.renderCanvas || Platform.canvas
156
+ const { view } = Platform.getCanvas()
148
157
  view.requestAnimationFrame ? view.requestAnimationFrame(render) : setTimeout(render, 16) // fix 抖音小程序
149
158
  }
150
- defineKey(Platform, 'devicePixelRatio', { get() { return Math.max(1, wx.getWindowInfo ? wx.getWindowInfo().pixelRatio : wx.getSystemInfoSync().pixelRatio) } })
159
+