pixuireactcomponents 1.3.76 → 1.3.77

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": "pixuireactcomponents",
3
- "version": "1.3.76",
3
+ "version": "1.3.77",
4
4
  "description": "pixui react components",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,7 +12,7 @@
12
12
  "dependencies": {
13
13
  "animate.css": "^3.7.2",
14
14
  "babel-plugin-transform-decorators-legacy": "^1.3.5",
15
- "cheerio": "^1.0.0-rc.12",
15
+ "cheerio": "1.0.0-rc.12",
16
16
  "cpx": "^1.5.0",
17
17
  "gamelet-pixui-frame": "0.4.9",
18
18
  "google-protobuf": "^3.8.0",
@@ -9,9 +9,5 @@ export declare namespace assetCache {
9
9
  * @returns 返回本地缓存文件路径
10
10
  */
11
11
  const cache: (url: string, force?: boolean, retryTimes?: number) => Promise<string>;
12
- /**
13
- * 返回url在本地的缓存文件路径,无缓存时返回空字符串
14
- */
15
- const getAssetPath: (url: string) => string;
16
12
  const download: (url: string, responseType: 'arraybuffer' | 'json' | 'text', retryTimes?: number) => Promise<string>;
17
13
  }
@@ -37,11 +37,36 @@ 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';
41
40
  var assetPrefix = 'cacheAsset';
42
41
  var isJssdkEnv = function () {
43
42
  return GameletAPI.getRuntimeEnv() == 'jssdk-appwindow' || GameletAPI.getRuntimeEnv() == 'jssdk-preprocessor';
44
43
  };
44
+ //动态导入lib_mgr
45
+ var getLibMgr = function () { return __awaiter(void 0, void 0, void 0, function () {
46
+ var LibMgr, module_1, error_1;
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0:
50
+ if (!window.require) {
51
+ console.error('env error');
52
+ return [2 /*return*/, null];
53
+ }
54
+ _a.label = 1;
55
+ case 1:
56
+ _a.trys.push([1, 3, , 4]);
57
+ return [4 /*yield*/, import('../../../lib/loadlib/lib_mgr')];
58
+ case 2:
59
+ module_1 = _a.sent();
60
+ LibMgr = module_1.LibMgr;
61
+ return [3 /*break*/, 4];
62
+ case 3:
63
+ error_1 = _a.sent();
64
+ console.error('need puerts env');
65
+ return [2 /*return*/, null];
66
+ case 4: return [2 /*return*/, LibMgr];
67
+ }
68
+ });
69
+ }); };
45
70
  /**
46
71
  * 缓存资源到本地,仅jssdk环境可用
47
72
  */
@@ -60,76 +85,77 @@ export var assetCache;
60
85
  var _this = this;
61
86
  return __generator(this, function (_a) {
62
87
  console.log('cacheAsset---', url);
63
- return [2 /*return*/, new Promise(function (resolve, reject) {
64
- if (!isJssdkEnv()) {
65
- console.log('非jssdk环境');
66
- reject();
67
- return;
68
- }
69
- var lib = LibMgr.getInstance().getMainLib();
70
- var localPath = getLocalPath(url);
71
- if (!force) {
72
- if (lib.fileExists(localPath)) {
73
- console.log('cacheAsset file exist', localPath);
74
- resolve(localPath);
75
- return;
76
- }
77
- }
78
- var xhr = new XMLHttpRequest();
79
- xhr.open('GET', url, true);
80
- xhr.responseType = 'arraybuffer';
81
- xhr.onload = function () { return __awaiter(_this, void 0, void 0, function () {
82
- var buf;
83
- return __generator(this, function (_a) {
84
- if (xhr.status === 200) {
85
- buf = Buffer.from(xhr.response, 'binary').buffer;
86
- lib.saveToFile(localPath, buf);
87
- resolve(localPath);
88
- }
89
- else {
90
- console.warn('cacheAsset xhr statue!=200', xhr.status);
91
- if (retryTimes > 0) {
92
- console.log('retry cacheAsset', retryTimes);
93
- assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
88
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
89
+ var mgr, lib, localPath, xhr;
90
+ var _this = this;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0:
94
+ if (!isJssdkEnv()) {
95
+ console.log('非jssdk环境');
96
+ reject();
97
+ return [2 /*return*/];
94
98
  }
95
- else {
99
+ return [4 /*yield*/, getLibMgr()];
100
+ case 1:
101
+ mgr = _a.sent();
102
+ if (!mgr) {
96
103
  reject();
104
+ return [2 /*return*/];
97
105
  }
98
- }
99
- return [2 /*return*/];
100
- });
101
- }); };
102
- xhr.onerror = function () {
103
- console.warn('cacheAsset XHR error', xhr.status);
104
- if (retryTimes > 0) {
105
- console.log('retry cacheAsset', retryTimes);
106
- assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
107
- }
108
- else {
109
- reject();
106
+ lib = mgr.getInstance().getMainLib();
107
+ return [4 /*yield*/, getLocalPath(url)];
108
+ case 2:
109
+ localPath = _a.sent();
110
+ if (!force) {
111
+ if (lib.fileExists(localPath)) {
112
+ console.log('cacheAsset file exist', localPath);
113
+ resolve(localPath);
114
+ return [2 /*return*/];
115
+ }
116
+ }
117
+ xhr = new XMLHttpRequest();
118
+ xhr.open('GET', url, true);
119
+ xhr.responseType = 'arraybuffer';
120
+ xhr.onload = function () { return __awaiter(_this, void 0, void 0, function () {
121
+ var buf;
122
+ return __generator(this, function (_a) {
123
+ if (xhr.status === 200) {
124
+ buf = Buffer.from(xhr.response, 'binary').buffer;
125
+ lib.saveToFile(localPath, buf);
126
+ resolve(localPath);
127
+ }
128
+ else {
129
+ console.warn('cacheAsset xhr statue!=200', xhr.status);
130
+ if (retryTimes > 0) {
131
+ console.log('retry cacheAsset', retryTimes);
132
+ assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
133
+ }
134
+ else {
135
+ reject();
136
+ }
137
+ }
138
+ return [2 /*return*/];
139
+ });
140
+ }); };
141
+ xhr.onerror = function () {
142
+ console.warn('cacheAsset XHR error', xhr.status);
143
+ if (retryTimes > 0) {
144
+ console.log('retry cacheAsset', retryTimes);
145
+ assetCache.cache(url, force, retryTimes - 1).then(resolve, reject);
146
+ }
147
+ else {
148
+ reject();
149
+ }
150
+ };
151
+ xhr.send();
152
+ return [2 /*return*/];
110
153
  }
111
- };
112
- xhr.send();
113
- })];
154
+ });
155
+ }); })];
114
156
  });
115
157
  });
116
158
  };
117
- /**
118
- * 返回url在本地的缓存文件路径,无缓存时返回空字符串
119
- */
120
- assetCache.getAssetPath = function (url) {
121
- if (!isJssdkEnv()) {
122
- console.log('非jssdk环境');
123
- return '';
124
- }
125
- var lib = LibMgr.getInstance().getMainLib();
126
- var localPath = getLocalPath(url);
127
- if (!lib.fileExists(localPath)) {
128
- console.log('getAssetPath file not exist', localPath);
129
- return '';
130
- }
131
- return localPath;
132
- };
133
159
  assetCache.download = function (url, responseType, retryTimes) {
134
160
  if (retryTimes === void 0) { retryTimes = 3; }
135
161
  console.log('download---', url);
@@ -168,15 +194,27 @@ export var assetCache;
168
194
  xhr.send();
169
195
  });
170
196
  };
171
- var getLocalPath = function (url) {
172
- console.log('getLocalPath', url);
173
- var lib = LibMgr.getInstance().getMainLib();
174
- var filePath = path.join(lib.getCachePath(), 'assetcache');
175
- //检查assetcache文件夹
176
- if (!lib.dirExists(filePath)) {
177
- lib.makeDir(filePath);
178
- }
179
- var fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
180
- return path.join(filePath, fileName);
181
- };
197
+ var getLocalPath = function (url) { return __awaiter(_this, void 0, void 0, function () {
198
+ var mgr, lib, filePath, fileName;
199
+ return __generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0:
202
+ console.log('getLocalPath', url);
203
+ return [4 /*yield*/, getLibMgr()];
204
+ case 1:
205
+ mgr = _a.sent();
206
+ if (!mgr) {
207
+ return [2 /*return*/, ''];
208
+ }
209
+ lib = mgr.getInstance().getMainLib();
210
+ filePath = path.join(lib.getCachePath(), 'assetcache');
211
+ //检查assetcache文件夹
212
+ if (!lib.dirExists(filePath)) {
213
+ lib.makeDir(filePath);
214
+ }
215
+ fileName = tools.getHashStr(assetPrefix + url) + path.extname(url);
216
+ return [2 /*return*/, path.join(filePath, fileName)];
217
+ }
218
+ });
219
+ }); };
182
220
  })(assetCache || (assetCache = {}));