@lijuhong1981/jsgif 1.2.10 → 1.2.12
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/index.js +7 -2
- package/package.json +4 -3
- package/src/GIFImageLoader.js +3 -13
- package/src/GIFPlayer.js +4 -4
- package/src/loadGIFImage.js +34 -0
package/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import GIFPlayer from "./src/GIFPlayer.js";
|
|
2
|
-
import
|
|
2
|
+
import loadGIFImage from "./src/loadGIFImage.js";
|
|
3
|
+
import GIFImageLoader from "./src/GIFImageLoader.js";
|
|
3
4
|
|
|
4
5
|
export default GIFPlayer;
|
|
5
|
-
export {
|
|
6
|
+
export {
|
|
7
|
+
GIFPlayer,
|
|
8
|
+
loadGIFImage,
|
|
9
|
+
GIFImageLoader,
|
|
10
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lijuhong1981/jsgif",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.12",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "lijuhong1981 <lijuhong@hotmail.com>",
|
|
6
6
|
"homepage": "https://github.com/lijuhong1981/jslibs#readme",
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
"bugs": {
|
|
19
19
|
"url": "https://github.com/lijuhong1981/jslibs/issues"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "a1eac84f5720dadfac32210e20bff644508d4b3a",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@lijuhong1981/jscheck": "^1.0.10",
|
|
24
24
|
"@lijuhong1981/jsdestroy": "^1.1.11",
|
|
25
25
|
"@lijuhong1981/jsevents": "^1.1.10",
|
|
26
|
-
"@lijuhong1981/jsload": "^1.2.
|
|
26
|
+
"@lijuhong1981/jsload": "^1.2.9",
|
|
27
|
+
"@lijuhong1981/jstask": "^1.1.6"
|
|
27
28
|
}
|
|
28
29
|
}
|
package/src/GIFImageLoader.js
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
import ImageLoader from "@lijuhong1981/jsload/src/ImageLoader.js";
|
|
2
|
-
import
|
|
2
|
+
import loadGIFImage from "./loadGIFImage.js";
|
|
3
3
|
|
|
4
4
|
class GIFImageLoader extends ImageLoader {
|
|
5
|
-
// constructor(options) {
|
|
6
|
-
// super(options);
|
|
7
|
-
// }
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* 重写图片加载函数,生成canvas以绘制gif动画
|
|
11
8
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
player.loadUrl(options.url, options.requestOptions, function () {
|
|
15
|
-
onLoad(player.canvas);
|
|
16
|
-
}, function (error) {
|
|
17
|
-
onError(error);
|
|
18
|
-
});
|
|
19
|
-
player.canvas.gifPlayer = player;
|
|
20
|
-
return player.canvas;
|
|
9
|
+
onLoad(url, options) {
|
|
10
|
+
return loadGIFImage(url, options);
|
|
21
11
|
}
|
|
22
12
|
};
|
|
23
13
|
|
package/src/GIFPlayer.js
CHANGED
|
@@ -136,11 +136,11 @@ const defaultOptions = {
|
|
|
136
136
|
function GIFPlayer(options = {}) {
|
|
137
137
|
options = Object.assign({}, defaultOptions, options);
|
|
138
138
|
console.log('options:', options);
|
|
139
|
-
const CANVAS = document.createElement("canvas");
|
|
139
|
+
const CANVAS = options.canvas || document.createElement("canvas");
|
|
140
140
|
const CANVAS_CTX = CANVAS.getContext('2d');
|
|
141
|
-
const TEMP_CANVAS = document.createElement("canvas");//用来拿 imageData
|
|
142
|
-
const TEMP_CANVAS_CTX = TEMP_CANVAS.getContext('2d', { willReadFrequently: true, });
|
|
143
|
-
const ATLAS_CANVAS = document.createElement("canvas");
|
|
141
|
+
const TEMP_CANVAS = document.createElement("canvas");//用来拿 imageData 的缓存canvas
|
|
142
|
+
const TEMP_CANVAS_CTX = TEMP_CANVAS.getContext('2d', { willReadFrequently: true, });
|
|
143
|
+
const ATLAS_CANVAS = options.atlasCanvas || document.createElement("canvas");
|
|
144
144
|
const FRAME_LIST = []; // 存放每一帧数据以及对应的延时
|
|
145
145
|
let GIF_INFO = {}; // GIF 的一些信息
|
|
146
146
|
let STREAM = null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import defer from "@lijuhong1981/jstask/src/defer.js";
|
|
2
|
+
import GIFPlayer from "./GIFPlayer.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 加载APNG图片
|
|
6
|
+
* @param {string} url 图片url
|
|
7
|
+
* @param {object} options 加载配置项
|
|
8
|
+
* @param {object} options.requestOptions 请求配置项,可选项
|
|
9
|
+
* @param {Function} options.onLoad 可选,加载成功回调函数
|
|
10
|
+
* @param {Function} options.onError 可选,加载出错回调函数
|
|
11
|
+
* @param {HTMLCanvasElement} result 输出的Canvas对象,可不填
|
|
12
|
+
* @returns {HTMLCanvasElement} 返回Canvas对象
|
|
13
|
+
*/
|
|
14
|
+
function loadGIFImage(url, options = {}, result = document.createElement('canvas')) {
|
|
15
|
+
const readyPromise = defer();
|
|
16
|
+
result.readyPromise = readyPromise.promise;
|
|
17
|
+
|
|
18
|
+
const player = new GIFPlayer({
|
|
19
|
+
canvas: result,
|
|
20
|
+
});
|
|
21
|
+
player.loadUrl(url, options.requestOptions, function () {
|
|
22
|
+
if (typeof options.onLoad === 'function')
|
|
23
|
+
options.onLoad(result);
|
|
24
|
+
readyPromise.resolve(result);
|
|
25
|
+
}, function (error) {
|
|
26
|
+
if (typeof options.onError === 'function')
|
|
27
|
+
options.onError(error);
|
|
28
|
+
readyPromise.reject(error);
|
|
29
|
+
});
|
|
30
|
+
result.gifPlayer = player;
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default loadGIFImage;
|