@leafer/miniapp 1.5.2 → 1.6.0

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,11 +1,19 @@
1
1
  {
2
2
  "name": "@leafer/miniapp",
3
- "version": "1.5.2",
3
+ "version": "1.6.0",
4
4
  "description": "@leafer/miniapp",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
- "main": "src/index.ts",
7
+ "type": "module",
8
+ "main": "dist/miniapp.esm.min.js",
9
+ "exports": {
10
+ "import": "./dist/miniapp.esm.min.js",
11
+ "require": "./dist/miniapp.min.cjs",
12
+ "types": "./types/index.d.ts"
13
+ },
8
14
  "types": "types/index.d.ts",
15
+ "unpkg": "dist/miniapp.esm.min.js",
16
+ "jsdelivr": "dist/miniapp.esm.min.js",
9
17
  "files": [
10
18
  "src",
11
19
  "types",
@@ -22,11 +30,22 @@
22
30
  "leaferjs"
23
31
  ],
24
32
  "dependencies": {
25
- "@leafer/core": "1.5.2",
26
- "@leafer/canvas-miniapp": "1.5.2",
27
- "@leafer/image-miniapp": "1.5.2"
28
- },
29
- "devDependencies": {
30
- "@leafer/interface": "1.5.2"
33
+ "@leafer-ui/miniapp": "1.6.0",
34
+ "@leafer-in/editor": "1.6.0",
35
+ "@leafer-in/viewport": "1.6.0",
36
+ "@leafer-in/view": "1.6.0",
37
+ "@leafer-in/scroll": "1.6.0",
38
+ "@leafer-in/arrow": "1.6.0",
39
+ "@leafer-in/flow": "1.6.0",
40
+ "@leafer-in/animate": "1.6.0",
41
+ "@leafer-in/motion-path": "1.6.0",
42
+ "@leafer-in/state": "1.6.0",
43
+ "@leafer-in/robot": "1.6.0",
44
+ "@leafer-in/find": "1.6.0",
45
+ "@leafer-in/export": "1.6.0",
46
+ "@leafer-in/filter": "1.6.0",
47
+ "@leafer-in/color": "1.6.0",
48
+ "@leafer-in/resize": "1.6.0",
49
+ "@leafer-in/interface": "1.6.0"
31
50
  }
32
51
  }
package/src/index.ts CHANGED
@@ -1,143 +1,24 @@
1
- export * from '@leafer/core'
1
+ export * from '@leafer-ui/miniapp'
2
2
 
3
- export * from '@leafer/canvas-miniapp'
4
- export * from '@leafer/image-miniapp'
3
+ export * from '@leafer-in/editor'
4
+ export * from '@leafer-in/viewport'
5
+ export * from '@leafer-in/view'
6
+ export * from '@leafer-in/scroll'
5
7
 
6
- import { ICanvasType, ICreator, IExportFileType, IExportImageType, IFunction, IObject, IMiniappSelect, IMiniappSizeView, IBoundsData } from '@leafer/interface'
7
- import { Platform, Creator, FileHelper, defineKey } from '@leafer/core'
8
+ export * from '@leafer-in/arrow'
9
+ export * from '@leafer-in/flow'
8
10
 
9
- import { LeaferCanvas } from '@leafer/canvas-miniapp'
10
- import { LeaferImage } from '@leafer/image-miniapp'
11
+ export * from '@leafer-in/animate'
12
+ export * from '@leafer-in/motion-path'
13
+ export * from '@leafer-in/state'
14
+ export * from '@leafer-in/robot'
11
15
 
16
+ export * from '@leafer-in/find'
17
+ export * from '@leafer-in/export'
12
18
 
13
- const { mineType, fileType } = FileHelper
19
+ export * from '@leafer-in/filter'
14
20
 
21
+ export * from '@leafer-in/color'
22
+ export * from '@leafer-in/resize'
15
23
 
16
- Object.assign(Creator, {
17
- canvas: (options?, manager?) => new LeaferCanvas(options, manager),
18
- image: (options) => new LeaferImage(options)
19
- } as ICreator)
20
-
21
-
22
- export function useCanvas(_canvasType: ICanvasType, app?: IObject): void {
23
- Platform.origin = {
24
- createCanvas: (width: number, height: number, _format?: string) => {
25
- const data = { type: '2d', width, height }
26
- return app.createOffscreenCanvas ? app.createOffscreenCanvas(data) : app.createOffScreenCanvas(data) // fix: 微信小游戏居然使用的是Screen大写的 wx.createOffScreenCanvas() [踩坑]
27
- },
28
- canvasToDataURL: (canvas: IObject, type?: IExportImageType, quality?: number) => canvas.toDataURL(mineType(type), quality),
29
- canvasToBolb: (canvas: IObject, type?: IExportFileType, quality?: number) => canvas.toBuffer(type, { quality }),
30
- canvasSaveAs: (canvas: IObject, filePath: string, quality?: any) => {
31
- let data: string = canvas.toDataURL(mineType(fileType(filePath)), quality)
32
- data = data.substring(data.indexOf('64,') + 3)
33
- return Platform.origin.download(data, filePath)
34
- },
35
- download(data: string, filePath: string): Promise<void> {
36
- return new Promise((resolve, reject) => {
37
- let toAlbum: boolean
38
- if (!filePath.includes('/')) {
39
- filePath = `${app.env.USER_DATA_PATH}/` + filePath
40
- toAlbum = true
41
- }
42
- const fs = app.getFileSystemManager()
43
- fs.writeFile({
44
- filePath,
45
- data,
46
- encoding: 'base64',
47
- success() {
48
- if (toAlbum) {
49
- Platform.miniapp.saveToAlbum(filePath).then(() => {
50
- fs.unlink({ filePath })
51
- resolve()
52
- })
53
- } else {
54
- resolve()
55
- }
56
-
57
- },
58
- fail(error: any) {
59
- reject(error)
60
- }
61
- })
62
- })
63
- },
64
- loadImage(src: string): Promise<HTMLImageElement> {
65
- return new Promise((resolve, reject) => {
66
- const img = Platform.canvas.view.createImage()
67
- img.onload = () => { resolve(img) }
68
- img.onerror = (error: any) => { reject(error) }
69
- img.src = Platform.image.getRealURL(src)
70
- })
71
- },
72
- noRepeat: 'repeat-x' // fix: 微信小程序 createPattern 直接使用 no-repeat 有bug,导致无法显示
73
- }
74
-
75
- Platform.miniapp = {
76
- select(name: string): IMiniappSelect {
77
- return app.createSelectorQuery().select(name)
78
- },
79
- getBounds(select: IMiniappSelect): Promise<IBoundsData> {
80
- return new Promise((resolve) => {
81
- select.boundingClientRect().exec((res: any) => {
82
- const rect = res[1]
83
- resolve({ x: rect.top, y: rect.left, width: rect.width, height: rect.height })
84
- })
85
- })
86
- },
87
- getSizeView(select: IMiniappSelect): Promise<IMiniappSizeView> {
88
- return new Promise((resolve) => {
89
- select.fields({ node: true, size: true }).exec((res: any) => {
90
- const data = res[0]
91
- resolve({ view: data.node, width: data.width, height: data.height })
92
- })
93
- })
94
- },
95
- saveToAlbum(path: string): Promise<any> {
96
- return new Promise((resolve) => {
97
- app.getSetting({
98
- success: (res: any) => {
99
- if (res.authSetting['scope.writePhotosAlbum']) {
100
- app.saveImageToPhotosAlbum({
101
- filePath: path,
102
- success() { resolve(true) }
103
- })
104
- } else {
105
- app.authorize({
106
- scope: 'scope.writePhotosAlbum',
107
- success: () => {
108
- app.saveImageToPhotosAlbum({
109
- filePath: path,
110
- success() { resolve(true) }
111
- })
112
- },
113
- fail: () => { }
114
- })
115
- }
116
- }
117
- })
118
- })
119
- },
120
- onWindowResize(fun: IFunction): void {
121
- app.onWindowResize(fun)
122
- },
123
- offWindowResize(fun: IFunction): void {
124
- app.offWindowResize(fun)
125
- }
126
- }
127
-
128
- Platform.event = {
129
- stopDefault(_origin: IObject): void { },
130
- stopNow(_origin: IObject): void { },
131
- stop(_origin: IObject): void { }
132
- }
133
-
134
- Platform.canvas = Creator.canvas()
135
- Platform.conicGradientSupport = !!Platform.canvas.context.createConicGradient
136
- }
137
-
138
- Platform.name = 'miniapp'
139
- Platform.requestRender = function (render: IFunction): void {
140
- const { view } = Platform.renderCanvas || Platform.canvas
141
- view.requestAnimationFrame ? view.requestAnimationFrame(render) : setTimeout(render, 16) // fix 抖音小程序
142
- }
143
- defineKey(Platform, 'devicePixelRatio', { get() { return Math.max(1, wx.getSystemInfoSync().pixelRatio) } })
24
+ export * from '@leafer-in/interface'
package/types/index.d.ts CHANGED
@@ -1,8 +1,17 @@
1
- export * from '@leafer/core';
2
- export * from '@leafer/canvas-miniapp';
3
- export * from '@leafer/image-miniapp';
4
- import { ICanvasType, IObject } from '@leafer/interface';
5
-
6
- declare function useCanvas(_canvasType: ICanvasType, app?: IObject): void;
7
-
8
- export { useCanvas };
1
+ export * from '@leafer-ui/miniapp';
2
+ export * from '@leafer-in/editor';
3
+ export * from '@leafer-in/viewport';
4
+ export * from '@leafer-in/view';
5
+ export * from '@leafer-in/scroll';
6
+ export * from '@leafer-in/arrow';
7
+ export * from '@leafer-in/flow';
8
+ export * from '@leafer-in/animate';
9
+ export * from '@leafer-in/motion-path';
10
+ export * from '@leafer-in/state';
11
+ export * from '@leafer-in/robot';
12
+ export * from '@leafer-in/find';
13
+ export * from '@leafer-in/export';
14
+ export * from '@leafer-in/filter';
15
+ export * from '@leafer-in/color';
16
+ export * from '@leafer-in/resize';
17
+ export * from '@leafer-in/interface';