@lijuhong1981/jsgif 1.0.4 → 1.0.6
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 +25 -2
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Check from "@lijuhong1981/jscheck";
|
|
2
|
+
import { Destroyable, destroyHTMLElement, destroyObject } from "@lijuhong1981/jsdestroy";
|
|
2
3
|
import { fetchArrayBuffer } from "@lijuhong1981/jsload";
|
|
3
4
|
|
|
4
5
|
// 转流数组
|
|
@@ -17,8 +18,9 @@ function bitsToNum(ba) {
|
|
|
17
18
|
}, 0);
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
class Stream {
|
|
21
|
+
class Stream extends Destroyable {
|
|
21
22
|
constructor(data) {
|
|
23
|
+
super();
|
|
22
24
|
this.data = data;
|
|
23
25
|
this.len = data.length;
|
|
24
26
|
this.pos = 0;
|
|
@@ -151,6 +153,7 @@ function GifPlayer(options = {}) {
|
|
|
151
153
|
LAST_DISPOSA_METHOD = null;
|
|
152
154
|
CURRENT_FRAME_INDEX = -1;
|
|
153
155
|
TRANSPARENCY = null;
|
|
156
|
+
STREAM && STREAM.destroy();
|
|
154
157
|
};
|
|
155
158
|
|
|
156
159
|
function readSubBlocks() {
|
|
@@ -461,6 +464,9 @@ function GifPlayer(options = {}) {
|
|
|
461
464
|
function doCurrentFrame() {
|
|
462
465
|
const frame = FRAME_LIST[currentFrameIndex];
|
|
463
466
|
drawFrame(frame);
|
|
467
|
+
if (typeof options.onFrameChanged === 'function') {
|
|
468
|
+
options.onFrameChanged(currentFrameIndex, frame);
|
|
469
|
+
}
|
|
464
470
|
setTimeout(function () {
|
|
465
471
|
if (!isPlaying)
|
|
466
472
|
return;
|
|
@@ -502,8 +508,8 @@ function GifPlayer(options = {}) {
|
|
|
502
508
|
try {
|
|
503
509
|
if (data instanceof ArrayBuffer)
|
|
504
510
|
data = new Uint8Array(data);
|
|
505
|
-
STREAM = new Stream(data);
|
|
506
511
|
reset();
|
|
512
|
+
STREAM = new Stream(data);
|
|
507
513
|
parseHeader();
|
|
508
514
|
parseBlock();
|
|
509
515
|
drawAtlasImage();
|
|
@@ -528,6 +534,15 @@ function GifPlayer(options = {}) {
|
|
|
528
534
|
});
|
|
529
535
|
}
|
|
530
536
|
|
|
537
|
+
function destroyGif() {
|
|
538
|
+
stopGif();
|
|
539
|
+
destroyHTMLElement(CANVAS);
|
|
540
|
+
destroyHTMLElement(TEMP_CANVAS);
|
|
541
|
+
destroyHTMLElement(ATLAS_CANVAS);
|
|
542
|
+
reset();
|
|
543
|
+
destroyObject(player);
|
|
544
|
+
}
|
|
545
|
+
|
|
531
546
|
Object.defineProperties(player, {
|
|
532
547
|
loadData: {
|
|
533
548
|
value: loadData,
|
|
@@ -610,6 +625,14 @@ function GifPlayer(options = {}) {
|
|
|
610
625
|
return options.onFrameChanged;
|
|
611
626
|
}
|
|
612
627
|
},
|
|
628
|
+
isDestroyed: {
|
|
629
|
+
value: function () {
|
|
630
|
+
return false;
|
|
631
|
+
},
|
|
632
|
+
},
|
|
633
|
+
destroy: {
|
|
634
|
+
value: destroyGif,
|
|
635
|
+
},
|
|
613
636
|
});
|
|
614
637
|
|
|
615
638
|
return player;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lijuhong1981/jsgif",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "lijuhong1981",
|
|
6
6
|
"homepage": "https://github.com/lijuhong1981/jslibs#readme",
|
|
@@ -17,5 +17,6 @@
|
|
|
17
17
|
},
|
|
18
18
|
"bugs": {
|
|
19
19
|
"url": "https://github.com/lijuhong1981/jslibs/issues"
|
|
20
|
-
}
|
|
20
|
+
},
|
|
21
|
+
"gitHead": "0cd088b384359010fbe891a8242f16bcecc481ab"
|
|
21
22
|
}
|