@lijuhong1981/jsgif 1.0.10 → 1.1.0
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 +24 -20
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Check from "@lijuhong1981/jscheck";
|
|
2
|
-
import { Destroyable, destroyHTMLElement, destroyObject } from "@lijuhong1981/jsdestroy";
|
|
2
|
+
import { defineDestroyProperties, Destroyable, destroyHTMLElement, destroyObject } from "@lijuhong1981/jsdestroy";
|
|
3
|
+
import { EventRaiser } from "@lijuhong1981/events";
|
|
3
4
|
import { fetchArrayBuffer } from "@lijuhong1981/jsload";
|
|
4
5
|
|
|
5
6
|
// 转流数组
|
|
@@ -145,6 +146,7 @@ function GifPlayer(options = {}) {
|
|
|
145
146
|
let TRANSPARENCY = null;
|
|
146
147
|
let isPlaying = false;
|
|
147
148
|
let currentFrameIndex = 0;
|
|
149
|
+
const frameChanged = new EventRaiser();
|
|
148
150
|
const player = {};
|
|
149
151
|
|
|
150
152
|
function reset() {
|
|
@@ -464,9 +466,7 @@ function GifPlayer(options = {}) {
|
|
|
464
466
|
function drawCurrentFrame() {
|
|
465
467
|
const frame = FRAME_LIST[currentFrameIndex];
|
|
466
468
|
drawFrame(frame);
|
|
467
|
-
|
|
468
|
-
options.onFrameChanged(currentFrameIndex, frame);
|
|
469
|
-
}
|
|
469
|
+
frameChanged.raiseEvent(currentFrameIndex, frame);
|
|
470
470
|
return frame;
|
|
471
471
|
}
|
|
472
472
|
|
|
@@ -507,7 +507,7 @@ function GifPlayer(options = {}) {
|
|
|
507
507
|
return player;
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
-
function loadData(data) {
|
|
510
|
+
function loadData(data, onLoad, onError) {
|
|
511
511
|
Check.defined('data', data);
|
|
512
512
|
|
|
513
513
|
return new Promise(function (resolve, reject) {
|
|
@@ -522,25 +522,37 @@ function GifPlayer(options = {}) {
|
|
|
522
522
|
stopGif();
|
|
523
523
|
if (options.autoPlay)
|
|
524
524
|
playGif();
|
|
525
|
+
if (typeof onLoad === 'function')
|
|
526
|
+
onLoad(player);
|
|
525
527
|
resolve(player);
|
|
526
528
|
} catch (error) {
|
|
529
|
+
if (typeof onError === 'function')
|
|
530
|
+
onError(error);
|
|
527
531
|
reject(error);
|
|
528
532
|
}
|
|
529
533
|
});
|
|
530
534
|
}
|
|
531
535
|
|
|
532
536
|
// 用xhr请求本地文件
|
|
533
|
-
function loadUrl(url, requestOptions) {
|
|
537
|
+
function loadUrl(url, requestOptions, onLoad, onError) {
|
|
534
538
|
Check.typeOf.string('url', url);
|
|
535
539
|
|
|
536
540
|
return new Promise(function (resolve, reject) {
|
|
541
|
+
|
|
542
|
+
function rejectError() {
|
|
543
|
+
if (typeof onError === 'function')
|
|
544
|
+
onError(error);
|
|
545
|
+
reject(error);
|
|
546
|
+
}
|
|
547
|
+
|
|
537
548
|
fetchArrayBuffer(url, requestOptions).then(function (arraybuffer) {
|
|
538
|
-
loadData(arraybuffer).then(resolve).catch(
|
|
539
|
-
}).catch(
|
|
549
|
+
loadData(arraybuffer, onLoad, onError).then(resolve).catch(rejectError);
|
|
550
|
+
}).catch(rejectError);
|
|
540
551
|
});
|
|
541
552
|
}
|
|
542
553
|
|
|
543
554
|
function destroyGif() {
|
|
555
|
+
frameChanged.clear();
|
|
544
556
|
stopGif();
|
|
545
557
|
destroyHTMLElement(CANVAS);
|
|
546
558
|
destroyHTMLElement(TEMP_CANVAS);
|
|
@@ -623,22 +635,14 @@ function GifPlayer(options = {}) {
|
|
|
623
635
|
return options.timeScale;
|
|
624
636
|
}
|
|
625
637
|
},
|
|
626
|
-
|
|
627
|
-
set: function (value) {
|
|
628
|
-
options.onFrameChanged = value;
|
|
629
|
-
},
|
|
638
|
+
frameChanged: {
|
|
630
639
|
get: function () {
|
|
631
|
-
return
|
|
640
|
+
return frameChanged;
|
|
632
641
|
}
|
|
633
|
-
}
|
|
634
|
-
destroy: {
|
|
635
|
-
value: destroyGif,
|
|
636
|
-
},
|
|
642
|
+
}
|
|
637
643
|
});
|
|
638
644
|
|
|
639
|
-
player
|
|
640
|
-
return false;
|
|
641
|
-
};
|
|
645
|
+
defineDestroyProperties(player, destroyGif);
|
|
642
646
|
|
|
643
647
|
return player;
|
|
644
648
|
};
|