pixuireactcomponents 1.3.89 → 1.3.91

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
3
  // make it callable from typescript
4
- if (globalThis.oplatSDKRunningTestRoutine) {
4
+ if (globalThis.oplatSDKRunningTestRoutine || typeof addlibpath === 'undefined') {
5
5
  exports.addlibpath = function (path) { };
6
6
  exports.clearlibpath = function (path) { };
7
7
  exports.loadlib = function (libname) { return undefined; };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.3.89",
3
+ "version": "1.3.91",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,2 @@
1
+ import { h } from 'preact';
2
+ export declare const PreloadImg: (props: h.JSX.HTMLAttributes<HTMLImageElement>) => h.JSX.Element;
@@ -0,0 +1,36 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { useEffect, useState } from 'preact/hooks';
13
+ import { h } from 'preact';
14
+ import { GameletAPI } from 'gamelet-pixui-frame';
15
+ import { assetCache } from 'src/components/tools/assetCache';
16
+ export var PreloadImg = function (props) {
17
+ var src = props.src;
18
+ var _a = useState(''), realSrc = _a[0], setRealSrc = _a[1];
19
+ useEffect(function () {
20
+ if (src) {
21
+ if (isJssdkEnv()) {
22
+ assetCache.cache(src).then(function (localSrc) {
23
+ setRealSrc(localSrc);
24
+ console.log('使用预加载图片', src, ' -> ', localSrc);
25
+ });
26
+ }
27
+ else {
28
+ setRealSrc(src);
29
+ }
30
+ }
31
+ }, [src]);
32
+ return h("img", __assign({}, props, { src: realSrc }));
33
+ };
34
+ var isJssdkEnv = function () {
35
+ return GameletAPI.getRuntimeEnv() == 'jssdk-appwindow' || GameletAPI.getRuntimeEnv() == 'jssdk-preprocessor';
36
+ };
@@ -16,5 +16,5 @@ export declare namespace assetCache {
16
16
  * @param retryTimes 重试次数
17
17
  * @returns 下载成功是,返回xhr.response,否则返回空字符串
18
18
  */
19
- const download: (url: string, responseType: 'arraybuffer' | 'json' | 'text', retryTimes?: number) => Promise<string>;
19
+ const request: (url: string, responseType: 'arraybuffer' | 'json' | 'text', retryTimes?: number) => Promise<string>;
20
20
  }
@@ -37,30 +37,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  import { GameletAPI } from 'gamelet-pixui-frame';
38
38
  import path from 'path';
39
39
  import { tools } from './tools';
40
- // import { LibMgr } from '../../../lib/loadlib/lib_mgr';
40
+ import { LibMgr } from '../../../lib/loadlib/lib_mgr';
41
41
  var assetPrefix = 'cacheAsset';
42
- var isJssdkEnv = function () {
43
- return GameletAPI.getRuntimeEnv() == 'jssdk-appwindow' || GameletAPI.getRuntimeEnv() == 'jssdk-preprocessor';
44
- };
45
- //动态导入lib_mgr
46
- var getLibMgr = function () { return __awaiter(void 0, void 0, void 0, function () {
47
- var module_1, error_1;
48
- return __generator(this, function (_a) {
49
- switch (_a.label) {
50
- case 0:
51
- _a.trys.push([0, 2, , 3]);
52
- return [4 /*yield*/, import('../../../lib/loadlib/lib_mgr')];
53
- case 1:
54
- module_1 = _a.sent();
55
- return [2 /*return*/, module_1.LibMgr];
56
- case 2:
57
- error_1 = _a.sent();
58
- console.error('need puerts env', error_1);
59
- return [2 /*return*/, null];
60
- case 3: return [2 /*return*/];
61
- }
62
- });
63
- }); };
42
+ var isJssdkEnv = GameletAPI.getRuntimeEnv() == 'jssdk-appwindow' || GameletAPI.getRuntimeEnv() == 'jssdk-preprocessor';
43
+ var OPLib = LibMgr.getInstance().getMainLib();
44
+ console.log('new lib test');
64
45
  /**
65
46
  * 缓存资源到本地,仅jssdk环境可用
66
47
  */
@@ -80,27 +61,18 @@ export var assetCache;
80
61
  return __generator(this, function (_a) {
81
62
  console.log('cacheAsset---', url);
82
63
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
83
- var urlWithoutParams, LibMgr, lib, localPath, xhr;
64
+ var urlWithoutParams, localPath, xhr;
84
65
  var _this = this;
85
66
  return __generator(this, function (_a) {
86
67
  switch (_a.label) {
87
68
  case 0:
88
- if (!isJssdkEnv()) {
69
+ if (!isJssdkEnv) {
89
70
  console.log('非jssdk环境');
90
71
  reject(url);
91
72
  }
92
73
  urlWithoutParams = url.split('?')[0];
93
- return [4 /*yield*/, getLibMgr()];
94
- case 1:
95
- LibMgr = _a.sent();
96
- if (!LibMgr) {
97
- console.log('getLibMgr failed');
98
- reject();
99
- return [2 /*return*/];
100
- }
101
- lib = LibMgr.getInstance().getMainLib();
102
74
  return [4 /*yield*/, getLocalPath(urlWithoutParams)];
103
- case 2:
75
+ case 1:
104
76
  localPath = _a.sent();
105
77
  if (!localPath) {
106
78
  console.log('getLocalPath failed');
@@ -109,7 +81,7 @@ export var assetCache;
109
81
  }
110
82
  console.log('cacheAsset getlocalPath', localPath);
111
83
  if (!force) {
112
- if (lib.fileExists(localPath)) {
84
+ if (OPLib.fileExists(localPath)) {
113
85
  console.log('cacheAsset file exist', localPath);
114
86
  resolve(localPath);
115
87
  }
@@ -124,7 +96,7 @@ export var assetCache;
124
96
  console.log('cacheAsset xhr statue=200', url, localPath);
125
97
  // let buf = Buffer.from(xhr.response, 'binary').buffer;
126
98
  if (localPath) {
127
- lib.saveToFile(localPath, xhr.response);
99
+ OPLib.saveToFile(localPath, xhr.response);
128
100
  resolve(localPath);
129
101
  }
130
102
  else {
@@ -169,9 +141,9 @@ export var assetCache;
169
141
  * @param retryTimes 重试次数
170
142
  * @returns 下载成功是,返回xhr.response,否则返回空字符串
171
143
  */
172
- assetCache.download = function (url, responseType, retryTimes) {
144
+ assetCache.request = function (url, responseType, retryTimes) {
173
145
  if (retryTimes === void 0) { retryTimes = 3; }
174
- console.log('download---', url);
146
+ console.log('request---', url);
175
147
  return new Promise(function (resolve, reject) {
176
148
  var xhr = new XMLHttpRequest();
177
149
  xhr.open('GET', url, true);
@@ -185,7 +157,7 @@ export var assetCache;
185
157
  console.warn('cacheAsset xhr statue!=200', xhr.status);
186
158
  if (retryTimes > 0) {
187
159
  console.log('retry cacheAsset', retryTimes);
188
- assetCache.download(url, responseType, retryTimes - 1).then(resolve, reject);
160
+ assetCache.request(url, responseType, retryTimes - 1).then(resolve, reject);
189
161
  }
190
162
  else {
191
163
  reject('');
@@ -198,7 +170,7 @@ export var assetCache;
198
170
  console.warn('cacheAsset XHR error', xhr.status);
199
171
  if (retryTimes > 0) {
200
172
  console.log('retry cacheAsset', retryTimes);
201
- assetCache.download(url, responseType, retryTimes - 1).then(resolve, reject);
173
+ assetCache.request(url, responseType, retryTimes - 1).then(resolve, reject);
202
174
  }
203
175
  else {
204
176
  reject('');
@@ -208,27 +180,16 @@ export var assetCache;
208
180
  });
209
181
  };
210
182
  var getLocalPath = function (url) { return __awaiter(_this, void 0, void 0, function () {
211
- var LibMgr, lib, filePath, fileName;
183
+ var filePath, fileName;
212
184
  return __generator(this, function (_a) {
213
- switch (_a.label) {
214
- case 0:
215
- console.log('getLocalPath', url);
216
- return [4 /*yield*/, getLibMgr()];
217
- case 1:
218
- LibMgr = _a.sent();
219
- if (!LibMgr) {
220
- console.log('getLibMgr failed');
221
- return [2 /*return*/];
222
- }
223
- lib = LibMgr.getInstance().getMainLib();
224
- filePath = path.join(lib.getCachePath(), 'assetcache');
225
- //检查assetcache文件夹
226
- if (!lib.dirExists(filePath)) {
227
- lib.makeDir(filePath);
228
- }
229
- fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
230
- return [2 /*return*/, path.join(filePath, fileName)];
185
+ console.log('getLocalPath', url);
186
+ filePath = path.join(OPLib.getCachePath(), 'assetcache');
187
+ //检查assetcache文件夹
188
+ if (!OPLib.dirExists(filePath)) {
189
+ OPLib.makeDir(filePath);
231
190
  }
191
+ fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
192
+ return [2 /*return*/, path.join(filePath, fileName)];
232
193
  });
233
194
  }); };
234
195
  })(assetCache || (assetCache = {}));