pixuireactcomponents 1.3.90 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixuireactcomponents",
3
- "version": "1.3.90",
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
  }
@@ -141,9 +141,9 @@ export var assetCache;
141
141
  * @param retryTimes 重试次数
142
142
  * @returns 下载成功是,返回xhr.response,否则返回空字符串
143
143
  */
144
- assetCache.download = function (url, responseType, retryTimes) {
144
+ assetCache.request = function (url, responseType, retryTimes) {
145
145
  if (retryTimes === void 0) { retryTimes = 3; }
146
- console.log('download---', url);
146
+ console.log('request---', url);
147
147
  return new Promise(function (resolve, reject) {
148
148
  var xhr = new XMLHttpRequest();
149
149
  xhr.open('GET', url, true);
@@ -157,7 +157,7 @@ export var assetCache;
157
157
  console.warn('cacheAsset xhr statue!=200', xhr.status);
158
158
  if (retryTimes > 0) {
159
159
  console.log('retry cacheAsset', retryTimes);
160
- assetCache.download(url, responseType, retryTimes - 1).then(resolve, reject);
160
+ assetCache.request(url, responseType, retryTimes - 1).then(resolve, reject);
161
161
  }
162
162
  else {
163
163
  reject('');
@@ -170,7 +170,7 @@ export var assetCache;
170
170
  console.warn('cacheAsset XHR error', xhr.status);
171
171
  if (retryTimes > 0) {
172
172
  console.log('retry cacheAsset', retryTimes);
173
- assetCache.download(url, responseType, retryTimes - 1).then(resolve, reject);
173
+ assetCache.request(url, responseType, retryTimes - 1).then(resolve, reject);
174
174
  }
175
175
  else {
176
176
  reject('');