@lijuhong1981/jsgif 1.0.5 → 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.
Files changed (2) hide show
  1. package/index.js +22 -2
  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() {
@@ -505,8 +508,8 @@ function GifPlayer(options = {}) {
505
508
  try {
506
509
  if (data instanceof ArrayBuffer)
507
510
  data = new Uint8Array(data);
508
- STREAM = new Stream(data);
509
511
  reset();
512
+ STREAM = new Stream(data);
510
513
  parseHeader();
511
514
  parseBlock();
512
515
  drawAtlasImage();
@@ -531,6 +534,15 @@ function GifPlayer(options = {}) {
531
534
  });
532
535
  }
533
536
 
537
+ function destroyGif() {
538
+ stopGif();
539
+ destroyHTMLElement(CANVAS);
540
+ destroyHTMLElement(TEMP_CANVAS);
541
+ destroyHTMLElement(ATLAS_CANVAS);
542
+ reset();
543
+ destroyObject(player);
544
+ }
545
+
534
546
  Object.defineProperties(player, {
535
547
  loadData: {
536
548
  value: loadData,
@@ -613,6 +625,14 @@ function GifPlayer(options = {}) {
613
625
  return options.onFrameChanged;
614
626
  }
615
627
  },
628
+ isDestroyed: {
629
+ value: function () {
630
+ return false;
631
+ },
632
+ },
633
+ destroy: {
634
+ value: destroyGif,
635
+ },
616
636
  });
617
637
 
618
638
  return player;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lijuhong1981/jsgif",
3
- "version": "1.0.5",
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
  }