@loaders.gl/video 3.3.0-alpha.5 → 3.3.0-alpha.7

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.
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var utils = {
8
9
  URL: globalThis.URL || globalThis.webkitURL || globalThis.mozURL || globalThis.msURL,
9
10
  getUserMedia: function () {
@@ -15,21 +16,17 @@ var utils = {
15
16
  requestTimeout: function requestTimeout(callback, delay) {
16
17
  callback = callback || utils.noop;
17
18
  delay = delay || 0;
18
-
19
19
  if (!utils.requestAnimFrame) {
20
20
  return setTimeout(callback, delay);
21
21
  }
22
-
23
22
  var start = new Date().getTime();
24
23
  var handle = new Object();
25
24
  var requestAnimFrame = utils.requestAnimFrame;
26
-
27
25
  var loop = function loop() {
28
26
  var current = new Date().getTime();
29
27
  var delta = current - start;
30
28
  delta >= delay ? callback.call() : handle.value = requestAnimFrame(loop);
31
29
  };
32
-
33
30
  handle.value = requestAnimFrame(loop);
34
31
  return handle;
35
32
  },
@@ -47,7 +44,6 @@ var utils = {
47
44
  var enc2 = void 0;
48
45
  var enc3 = void 0;
49
46
  var enc4 = void 0;
50
-
51
47
  while (i < l) {
52
48
  chr1 = input.charCodeAt(i++);
53
49
  chr2 = input.charCodeAt(i++);
@@ -56,19 +52,15 @@ var utils = {
56
52
  enc2 = (chr1 & 3) << 4 | chr2 >> 4;
57
53
  enc3 = (chr2 & 15) << 2 | chr3 >> 6;
58
54
  enc4 = chr3 & 63;
59
-
60
55
  if (isNaN(chr2)) {
61
56
  enc3 = enc4 = 64;
62
57
  } else if (isNaN(chr3)) {
63
58
  enc4 = 64;
64
59
  }
65
-
66
60
  output = output + key.charAt(enc1) + key.charAt(enc2) + key.charAt(enc3) + key.charAt(enc4);
67
61
  }
68
-
69
62
  return output;
70
63
  };
71
-
72
64
  return btoa ? btoa.bind(globalThis) : utils.noop;
73
65
  }(),
74
66
  isObject: function isObject(obj) {
@@ -115,7 +107,6 @@ var utils = {
115
107
  ogg: false,
116
108
  webm: false
117
109
  };
118
-
119
110
  try {
120
111
  if (testEl && testEl.canPlayType) {
121
112
  supportObj.mp4 = testEl.canPlayType('video/mp4; codecs="mp4v.20.8"') !== '';
@@ -125,7 +116,6 @@ var utils = {
125
116
  supportObj.webm = testEl.canPlayType('video/webm; codecs="vp8, vorbis"') !== -1;
126
117
  }
127
118
  } catch (e) {}
128
-
129
119
  return supportObj;
130
120
  }()
131
121
  },
@@ -133,11 +123,9 @@ var utils = {
133
123
  each: function each(collection, callback) {
134
124
  var x = void 0;
135
125
  var len = void 0;
136
-
137
126
  if (utils.isArray(collection)) {
138
127
  x = -1;
139
128
  len = collection.length;
140
-
141
129
  while (++x < len) {
142
130
  if (callback(x, collection[x]) === false) {
143
131
  break;
@@ -157,14 +145,12 @@ var utils = {
157
145
  if (!utils.isObject(defaultOptions) || !utils.isObject(userOptions) || !Object.keys) {
158
146
  return;
159
147
  }
160
-
161
148
  var newObj = {};
162
149
  utils.each(defaultOptions, function (key, val) {
163
150
  newObj[key] = defaultOptions[key];
164
151
  });
165
152
  utils.each(userOptions, function (key, val) {
166
153
  var currentUserOption = userOptions[key];
167
-
168
154
  if (!utils.isObject(currentUserOption)) {
169
155
  newObj[key] = currentUserOption;
170
156
  } else if (!defaultOptions[key]) {
@@ -179,7 +165,6 @@ var utils = {
179
165
  if (!utils.isElement(elem)) {
180
166
  return;
181
167
  }
182
-
183
168
  if (utils.isString(attr) && utils.isString(val)) {
184
169
  elem.style[attr] = val;
185
170
  } else if (utils.isObject(attr)) {
@@ -192,7 +177,6 @@ var utils = {
192
177
  if (!utils.isElement(node)) {
193
178
  return;
194
179
  }
195
-
196
180
  if (node.parentNode) {
197
181
  node.parentNode.removeChild(node);
198
182
  }
@@ -201,7 +185,6 @@ var utils = {
201
185
  if (!utils.isString(content)) {
202
186
  return {};
203
187
  }
204
-
205
188
  try {
206
189
  var blob = new utils.Blob([content], {
207
190
  type: 'text/javascript'
@@ -221,11 +204,9 @@ var utils = {
221
204
  },
222
205
  getFontSize: function getFontSize() {
223
206
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
224
-
225
207
  if (!document.body || options.resizeFont === false) {
226
208
  return options.fontSize;
227
209
  }
228
-
229
210
  var text = options.text;
230
211
  var containerWidth = options.gifWidth;
231
212
  var fontSize = parseInt(options.fontSize, 10);
@@ -239,11 +220,9 @@ var utils = {
239
220
  span.style.textIndent = '-9999px';
240
221
  span.style.visibility = 'hidden';
241
222
  document.body.appendChild(span);
242
-
243
223
  while (span.offsetWidth > containerWidth && fontSize >= minFontSize) {
244
224
  span.style.fontSize = "".concat(--fontSize, "px");
245
225
  }
246
-
247
226
  document.body.removeChild(span);
248
227
  return "".concat(fontSize, "px");
249
228
  },
@@ -258,7 +237,6 @@ var error = {
258
237
  var errorObj = {};
259
238
  utils.each(error.validators, function (indece, currentValidator) {
260
239
  var errorCode = currentValidator.errorCode;
261
-
262
240
  if (!skipObj[errorCode] && !currentValidator.condition) {
263
241
  errorObj = currentValidator;
264
242
  errorObj.error = true;
@@ -312,9 +290,7 @@ var error = {
312
290
  var error$2 = Object.freeze({
313
291
  default: error
314
292
  });
315
-
316
293
  var noop = function noop() {};
317
-
318
294
  var defaultOptions = {
319
295
  sampleInterval: 10,
320
296
  numWorkers: 2,
@@ -349,32 +325,26 @@ var defaultOptions = {
349
325
  var defaultOptions$2 = Object.freeze({
350
326
  default: defaultOptions
351
327
  });
352
-
353
328
  function isSupported() {
354
329
  return error.isValid();
355
330
  }
356
-
357
331
  function isWebCamGIFSupported() {
358
332
  return error.isValid();
359
333
  }
360
-
361
334
  function isSupported$1() {
362
335
  var options = {
363
336
  getUserMedia: true
364
337
  };
365
338
  return error.isValid(options);
366
339
  }
367
-
368
340
  function isExistingVideoGIFSupported(codecs) {
369
341
  var hasValidCodec = false;
370
-
371
342
  if (utils.isArray(codecs) && codecs.length) {
372
343
  utils.each(codecs, function (indece, currentCodec) {
373
344
  if (utils.isSupported.videoCodecs[currentCodec]) {
374
345
  hasValidCodec = true;
375
346
  }
376
347
  });
377
-
378
348
  if (!hasValidCodec) {
379
349
  return false;
380
350
  }
@@ -383,12 +353,10 @@ function isExistingVideoGIFSupported(codecs) {
383
353
  return false;
384
354
  }
385
355
  }
386
-
387
356
  return error.isValid({
388
357
  getUserMedia: true
389
358
  });
390
359
  }
391
-
392
360
  function NeuQuant() {
393
361
  var netsize = 256;
394
362
  var prime1 = 499;
@@ -426,7 +394,6 @@ function NeuQuant() {
426
394
  var bias = [];
427
395
  var freq = [];
428
396
  var radpower = [];
429
-
430
397
  function NeuQuantConstructor(thepic, len, sample) {
431
398
  var i;
432
399
  var p;
@@ -434,7 +401,6 @@ function NeuQuant() {
434
401
  lengthcount = len;
435
402
  samplefac = sample;
436
403
  network = new Array(netsize);
437
-
438
404
  for (i = 0; i < netsize; i++) {
439
405
  network[i] = new Array(4);
440
406
  p = network[i];
@@ -443,27 +409,21 @@ function NeuQuant() {
443
409
  bias[i] = 0;
444
410
  }
445
411
  }
446
-
447
412
  function colorMap() {
448
413
  var map = [];
449
414
  var index = new Array(netsize);
450
-
451
415
  for (var i = 0; i < netsize; i++) {
452
416
  index[network[i][3]] = i;
453
417
  }
454
-
455
418
  var k = 0;
456
-
457
419
  for (var l = 0; l < netsize; l++) {
458
420
  var j = index[l];
459
421
  map[k++] = network[j][0];
460
422
  map[k++] = network[j][1];
461
423
  map[k++] = network[j][2];
462
424
  }
463
-
464
425
  return map;
465
426
  }
466
-
467
427
  function inxbuild() {
468
428
  var i;
469
429
  var j;
@@ -475,15 +435,12 @@ function NeuQuant() {
475
435
  var startpos;
476
436
  previouscol = 0;
477
437
  startpos = 0;
478
-
479
438
  for (i = 0; i < netsize; i++) {
480
439
  p = network[i];
481
440
  smallpos = i;
482
441
  smallval = p[1];
483
-
484
442
  for (j = i + 1; j < netsize; j++) {
485
443
  q = network[j];
486
-
487
444
  if (q[1] < smallval) {
488
445
  smallpos = j;
489
446
  smallval = q[1];
@@ -491,7 +448,6 @@ function NeuQuant() {
491
448
  }
492
449
 
493
450
  q = network[smallpos];
494
-
495
451
  if (i != smallpos) {
496
452
  j = q[0];
497
453
  q[0] = p[0];
@@ -506,26 +462,20 @@ function NeuQuant() {
506
462
  q[3] = p[3];
507
463
  p[3] = j;
508
464
  }
509
-
510
465
  if (smallval != previouscol) {
511
466
  netindex[previouscol] = startpos + i >> 1;
512
-
513
467
  for (j = previouscol + 1; j < smallval; j++) {
514
468
  netindex[j] = i;
515
469
  }
516
-
517
470
  previouscol = smallval;
518
471
  startpos = i;
519
472
  }
520
473
  }
521
-
522
474
  netindex[previouscol] = startpos + maxnetpos >> 1;
523
-
524
475
  for (j = previouscol + 1; j < 256; j++) {
525
476
  netindex[j] = maxnetpos;
526
477
  }
527
478
  }
528
-
529
479
  function learn() {
530
480
  var i;
531
481
  var j;
@@ -541,11 +491,9 @@ function NeuQuant() {
541
491
  var p;
542
492
  var pix;
543
493
  var lim;
544
-
545
494
  if (lengthcount < minpicturebytes) {
546
495
  samplefac = 1;
547
496
  }
548
-
549
497
  alphadec = 30 + (samplefac - 1) / 3;
550
498
  p = thepicture;
551
499
  pix = 0;
@@ -555,15 +503,12 @@ function NeuQuant() {
555
503
  alpha = initalpha;
556
504
  radius = initradius;
557
505
  rad = radius >> radiusbiasshift;
558
-
559
506
  if (rad <= 1) {
560
507
  rad = 0;
561
508
  }
562
-
563
509
  for (i = 0; i < rad; i++) {
564
510
  radpower[i] = alpha * ((rad * rad - i * i) * radbias / (rad * rad));
565
511
  }
566
-
567
512
  if (lengthcount < minpicturebytes) {
568
513
  step = 3;
569
514
  } else if (lengthcount % prime1 !== 0) {
@@ -575,48 +520,37 @@ function NeuQuant() {
575
520
  } else {
576
521
  step = 3 * prime4;
577
522
  }
578
-
579
523
  i = 0;
580
-
581
524
  while (i < samplepixels) {
582
525
  b = (p[pix + 0] & 0xff) << netbiasshift;
583
526
  g = (p[pix + 1] & 0xff) << netbiasshift;
584
527
  r = (p[pix + 2] & 0xff) << netbiasshift;
585
528
  j = contest(b, g, r);
586
529
  altersingle(alpha, j, b, g, r);
587
-
588
530
  if (rad !== 0) {
589
531
  alterneigh(rad, j, b, g, r);
590
532
  }
591
-
592
533
  pix += step;
593
-
594
534
  if (pix >= lim) {
595
535
  pix -= lengthcount;
596
536
  }
597
-
598
537
  i++;
599
-
600
538
  if (delta === 0) {
601
539
  delta = 1;
602
540
  }
603
-
604
541
  if (i % delta === 0) {
605
542
  alpha -= alpha / alphadec;
606
543
  radius -= radius / radiusdec;
607
544
  rad = radius >> radiusbiasshift;
608
-
609
545
  if (rad <= 1) {
610
546
  rad = 0;
611
547
  }
612
-
613
548
  for (j = 0; j < rad; j++) {
614
549
  radpower[j] = alpha * ((rad * rad - j * j) * radbias / (rad * rad));
615
550
  }
616
551
  }
617
552
  }
618
553
  }
619
-
620
554
  function map(b, g, r) {
621
555
  var i;
622
556
  var j;
@@ -629,38 +563,28 @@ function NeuQuant() {
629
563
  best = -1;
630
564
  i = netindex[g];
631
565
  j = i - 1;
632
-
633
566
  while (i < netsize || j >= 0) {
634
567
  if (i < netsize) {
635
568
  p = network[i];
636
569
  dist = p[1] - g;
637
-
638
570
  if (dist >= bestd) {
639
571
  i = netsize;
640
572
  } else {
641
573
  i++;
642
-
643
574
  if (dist < 0) {
644
575
  dist = -dist;
645
576
  }
646
-
647
577
  a = p[0] - b;
648
-
649
578
  if (a < 0) {
650
579
  a = -a;
651
580
  }
652
-
653
581
  dist += a;
654
-
655
582
  if (dist < bestd) {
656
583
  a = p[2] - r;
657
-
658
584
  if (a < 0) {
659
585
  a = -a;
660
586
  }
661
-
662
587
  dist += a;
663
-
664
588
  if (dist < bestd) {
665
589
  bestd = dist;
666
590
  best = p[3];
@@ -668,37 +592,27 @@ function NeuQuant() {
668
592
  }
669
593
  }
670
594
  }
671
-
672
595
  if (j >= 0) {
673
596
  p = network[j];
674
597
  dist = g - p[1];
675
-
676
598
  if (dist >= bestd) {
677
599
  j = -1;
678
600
  } else {
679
601
  j--;
680
-
681
602
  if (dist < 0) {
682
603
  dist = -dist;
683
604
  }
684
-
685
605
  a = p[0] - b;
686
-
687
606
  if (a < 0) {
688
607
  a = -a;
689
608
  }
690
-
691
609
  dist += a;
692
-
693
610
  if (dist < bestd) {
694
611
  a = p[2] - r;
695
-
696
612
  if (a < 0) {
697
613
  a = -a;
698
614
  }
699
-
700
615
  dist += a;
701
-
702
616
  if (dist < bestd) {
703
617
  bestd = dist;
704
618
  best = p[3];
@@ -707,21 +621,17 @@ function NeuQuant() {
707
621
  }
708
622
  }
709
623
  }
710
-
711
624
  return best;
712
625
  }
713
-
714
626
  function process() {
715
627
  learn();
716
628
  unbiasnet();
717
629
  inxbuild();
718
630
  return colorMap();
719
631
  }
720
-
721
632
  function unbiasnet() {
722
633
  var i;
723
634
  var j;
724
-
725
635
  for (i = 0; i < netsize; i++) {
726
636
  network[i][0] >>= netbiasshift;
727
637
  network[i][1] >>= netbiasshift;
@@ -729,7 +639,6 @@ function NeuQuant() {
729
639
  network[i][3] = i;
730
640
  }
731
641
  }
732
-
733
642
  function alterneigh(rad, i, b, g, r) {
734
643
  var j;
735
644
  var k;
@@ -739,37 +648,28 @@ function NeuQuant() {
739
648
  var m;
740
649
  var p;
741
650
  lo = i - rad;
742
-
743
651
  if (lo < -1) {
744
652
  lo = -1;
745
653
  }
746
-
747
654
  hi = i + rad;
748
-
749
655
  if (hi > netsize) {
750
656
  hi = netsize;
751
657
  }
752
-
753
658
  j = i + 1;
754
659
  k = i - 1;
755
660
  m = 1;
756
-
757
661
  while (j < hi || k > lo) {
758
662
  a = radpower[m++];
759
-
760
663
  if (j < hi) {
761
664
  p = network[j++];
762
-
763
665
  try {
764
666
  p[0] -= a * (p[0] - b) / alpharadbias | 0;
765
667
  p[1] -= a * (p[1] - g) / alpharadbias | 0;
766
668
  p[2] -= a * (p[2] - r) / alpharadbias | 0;
767
669
  } catch (e) {}
768
670
  }
769
-
770
671
  if (k > lo) {
771
672
  p = network[k--];
772
-
773
673
  try {
774
674
  p[0] -= a * (p[0] - b) / alpharadbias | 0;
775
675
  p[1] -= a * (p[1] - g) / alpharadbias | 0;
@@ -778,7 +678,6 @@ function NeuQuant() {
778
678
  }
779
679
  }
780
680
  }
781
-
782
681
  function altersingle(alpha, i, b, g, r) {
783
682
  var n = network[i];
784
683
  var alphaMult = alpha / initalpha;
@@ -786,7 +685,6 @@ function NeuQuant() {
786
685
  n[1] -= alphaMult * (n[1] - g) | 0;
787
686
  n[2] -= alphaMult * (n[2] - r) | 0;
788
687
  }
789
-
790
688
  function contest(b, g, r) {
791
689
  var i;
792
690
  var dist;
@@ -802,80 +700,62 @@ function NeuQuant() {
802
700
  bestbiasd = bestd;
803
701
  bestpos = -1;
804
702
  bestbiaspos = bestpos;
805
-
806
703
  for (i = 0; i < netsize; i++) {
807
704
  n = network[i];
808
705
  dist = n[0] - b;
809
-
810
706
  if (dist < 0) {
811
707
  dist = -dist;
812
708
  }
813
-
814
709
  a = n[1] - g;
815
-
816
710
  if (a < 0) {
817
711
  a = -a;
818
712
  }
819
-
820
713
  dist += a;
821
714
  a = n[2] - r;
822
-
823
715
  if (a < 0) {
824
716
  a = -a;
825
717
  }
826
-
827
718
  dist += a;
828
-
829
719
  if (dist < bestd) {
830
720
  bestd = dist;
831
721
  bestpos = i;
832
722
  }
833
-
834
723
  biasdist = dist - (bias[i] >> intbiasshift - netbiasshift);
835
-
836
724
  if (biasdist < bestbiasd) {
837
725
  bestbiasd = biasdist;
838
726
  bestbiaspos = i;
839
727
  }
840
-
841
728
  betafreq = freq[i] >> betashift;
842
729
  freq[i] -= betafreq;
843
730
  bias[i] += betafreq << gammashift;
844
731
  }
845
-
846
732
  freq[bestpos] += beta;
847
733
  bias[bestpos] -= betagamma;
848
734
  return bestbiaspos;
849
735
  }
850
-
851
736
  NeuQuantConstructor.apply(this, arguments);
852
737
  var exports = {};
853
738
  exports.map = map;
854
739
  exports.process = process;
855
740
  return exports;
856
741
  }
857
-
858
742
  function workerCode() {
859
743
  var self = this;
860
-
861
744
  try {
862
745
  globalThis.onmessage = function (ev) {
863
746
  var data = ev.data || {};
864
747
  var response;
865
-
866
748
  if (data.gifshot) {
867
749
  response = workerMethods.run(data);
868
750
  postMessage(response);
869
751
  }
870
752
  };
871
753
  } catch (e) {}
872
-
873
754
  var workerMethods = {
874
755
  dataToRGB: function dataToRGB(data, width, height) {
875
756
  var length = width * height * 4;
876
757
  var i = 0;
877
758
  var rgb = [];
878
-
879
759
  while (i < length) {
880
760
  rgb.push(data[i++]);
881
761
  rgb.push(data[i++]);
@@ -888,14 +768,12 @@ function workerCode() {
888
768
  componentizedPaletteToArray: function componentizedPaletteToArray(paletteRGB) {
889
769
  paletteRGB = paletteRGB || [];
890
770
  var paletteArray = [];
891
-
892
771
  for (var i = 0; i < paletteRGB.length; i += 3) {
893
772
  var r = paletteRGB[i];
894
773
  var g = paletteRGB[i + 1];
895
774
  var b = paletteRGB[i + 2];
896
775
  paletteArray.push(r << 16 | g << 8 | b);
897
776
  }
898
-
899
777
  return paletteArray;
900
778
  },
901
779
  processFrameWithQuantizer: function processFrameWithQuantizer(imageData, width, height, sampleInterval) {
@@ -906,14 +784,12 @@ function workerCode() {
906
784
  var numberPixels = width * height;
907
785
  var indexedPixels = new Uint8Array(numberPixels);
908
786
  var k = 0;
909
-
910
787
  for (var i = 0; i < numberPixels; i++) {
911
788
  var r = rgbComponents[k++];
912
789
  var g = rgbComponents[k++];
913
790
  var b = rgbComponents[k++];
914
791
  indexedPixels[i] = nq.map(r, g, b);
915
792
  }
916
-
917
793
  return {
918
794
  pixels: indexedPixels,
919
795
  palette: paletteArray
@@ -932,20 +808,17 @@ function workerCode() {
932
808
  };
933
809
  return workerMethods;
934
810
  }
935
-
936
811
  function gifWriter(buf, width, height, gopts) {
937
812
  var p = 0;
938
813
  gopts = gopts === undefined ? {} : gopts;
939
814
  var loop_count = gopts.loop === undefined ? null : gopts.loop;
940
815
  var global_palette = gopts.palette === undefined ? null : gopts.palette;
941
816
  if (width <= 0 || height <= 0 || width > 65535 || height > 65535) throw 'Width/Height invalid.';
942
-
943
817
  function check_palette_and_num_colors(palette) {
944
818
  var num_colors = palette.length;
945
819
  if (num_colors < 2 || num_colors > 256 || num_colors & num_colors - 1) throw 'Invalid code/color length, must be power of 2 and 2 .. 256.';
946
820
  return num_colors;
947
821
  }
948
-
949
822
  buf[p++] = 0x47;
950
823
  buf[p++] = 0x49;
951
824
  buf[p++] = 0x46;
@@ -958,10 +831,10 @@ function gifWriter(buf, width, height, gopts) {
958
831
  buf[p++] = width >> 8 & 0xff;
959
832
  buf[p++] = height & 0xff;
960
833
  buf[p++] = height >> 8 & 0xff;
961
- buf[p++] = (global_palette !== null ? 0x80 : 0) | gp_num_colors_pow2;
834
+ buf[p++] = (global_palette !== null ? 0x80 : 0) |
835
+ gp_num_colors_pow2;
962
836
  buf[p++] = background;
963
837
  buf[p++] = 0;
964
-
965
838
  if (loop_count !== null) {
966
839
  if (loop_count < 0 || loop_count > 65535) throw 'Loop count invalid.';
967
840
  buf[p++] = 0x21;
@@ -986,46 +859,39 @@ function gifWriter(buf, width, height, gopts) {
986
859
  }
987
860
 
988
861
  var ended = false;
989
-
990
862
  this.addFrame = function (x, y, w, h, indexed_pixels, opts) {
991
863
  if (ended === true) {
992
864
  --p;
993
865
  ended = false;
994
866
  }
995
-
996
867
  opts = opts === undefined ? {} : opts;
997
868
  if (x < 0 || y < 0 || x > 65535 || y > 65535) throw 'x/y invalid.';
998
869
  if (w <= 0 || h <= 0 || w > 65535 || h > 65535) throw 'Width/Height invalid.';
999
870
  if (indexed_pixels.length < w * h) throw 'Not enough pixels for the frame size.';
1000
871
  var using_local_palette = true;
1001
872
  var palette = opts.palette;
1002
-
1003
873
  if (palette === undefined || palette === null) {
1004
874
  using_local_palette = false;
1005
875
  palette = global_palette;
1006
876
  }
1007
-
1008
877
  if (palette === undefined || palette === null) throw 'Must supply either a local or global palette.';
1009
878
  var num_colors = check_palette_and_num_colors(palette);
1010
879
  var min_code_size = 0;
1011
-
1012
880
  while (num_colors >>= 1) {
1013
881
  ++min_code_size;
1014
882
  }
1015
-
1016
883
  num_colors = 1 << min_code_size;
1017
884
  var delay = opts.delay === undefined ? 0 : opts.delay;
1018
885
  var disposal = opts.disposal === undefined ? 0 : opts.disposal;
1019
- if (disposal < 0 || disposal > 3) throw 'Disposal out of range.';
886
+ if (disposal < 0 || disposal > 3)
887
+ throw 'Disposal out of range.';
1020
888
  var use_transparency = false;
1021
889
  var transparent_index = 0;
1022
-
1023
890
  if (opts.transparent !== undefined && opts.transparent !== null) {
1024
891
  use_transparency = true;
1025
892
  transparent_index = opts.transparent;
1026
893
  if (transparent_index < 0 || transparent_index >= num_colors) throw 'Transparent color index.';
1027
894
  }
1028
-
1029
895
  if (disposal !== 0 || use_transparency || delay !== 0) {
1030
896
  buf[p++] = 0x21;
1031
897
  buf[p++] = 0xf9;
@@ -1036,7 +902,6 @@ function gifWriter(buf, width, height, gopts) {
1036
902
  buf[p++] = transparent_index;
1037
903
  buf[p++] = 0;
1038
904
  }
1039
-
1040
905
  buf[p++] = 0x2c;
1041
906
  buf[p++] = x & 0xff;
1042
907
  buf[p++] = x >> 8 & 0xff;
@@ -1047,7 +912,6 @@ function gifWriter(buf, width, height, gopts) {
1047
912
  buf[p++] = h & 0xff;
1048
913
  buf[p++] = h >> 8 & 0xff;
1049
914
  buf[p++] = using_local_palette === true ? 0x80 | min_code_size - 1 : 0;
1050
-
1051
915
  if (using_local_palette === true) {
1052
916
  for (var i = 0, il = palette.length; i < il; ++i) {
1053
917
  var rgb = palette[i];
@@ -1056,19 +920,15 @@ function gifWriter(buf, width, height, gopts) {
1056
920
  buf[p++] = rgb & 0xff;
1057
921
  }
1058
922
  }
1059
-
1060
923
  p = GifWriterOutputLZWCodeStream(buf, p, min_code_size < 2 ? 2 : min_code_size, indexed_pixels);
1061
924
  };
1062
-
1063
925
  this.end = function () {
1064
926
  if (ended === false) {
1065
927
  buf[p++] = 0x3b;
1066
928
  ended = true;
1067
929
  }
1068
-
1069
930
  return p;
1070
931
  };
1071
-
1072
932
  function GifWriterOutputLZWCodeStream(buf, p, min_code_size, index_stream) {
1073
933
  buf[p++] = min_code_size;
1074
934
  var cur_subblock = p++;
@@ -1079,50 +939,41 @@ function gifWriter(buf, width, height, gopts) {
1079
939
  var cur_code_size = min_code_size + 1;
1080
940
  var cur_shift = 0;
1081
941
  var cur = 0;
1082
-
1083
942
  function emit_bytes_to_buffer(bit_block_size) {
1084
943
  while (cur_shift >= bit_block_size) {
1085
944
  buf[p++] = cur & 0xff;
1086
945
  cur >>= 8;
1087
946
  cur_shift -= 8;
1088
-
1089
947
  if (p === cur_subblock + 256) {
1090
948
  buf[cur_subblock] = 255;
1091
949
  cur_subblock = p++;
1092
950
  }
1093
951
  }
1094
952
  }
1095
-
1096
953
  function emit_code(c) {
1097
954
  cur |= c << cur_shift;
1098
955
  cur_shift += cur_code_size;
1099
956
  emit_bytes_to_buffer(8);
1100
957
  }
1101
-
1102
958
  var ib_code = index_stream[0] & code_mask;
1103
959
  var code_table = {};
1104
960
  emit_code(clear_code);
1105
-
1106
961
  for (var i = 1, il = index_stream.length; i < il; ++i) {
1107
962
  var k = index_stream[i] & code_mask;
1108
963
  var cur_key = ib_code << 8 | k;
1109
964
  var cur_code = code_table[cur_key];
1110
-
1111
965
  if (cur_code === undefined) {
1112
966
  cur |= ib_code << cur_shift;
1113
967
  cur_shift += cur_code_size;
1114
-
1115
968
  while (cur_shift >= 8) {
1116
969
  buf[p++] = cur & 0xff;
1117
970
  cur >>= 8;
1118
971
  cur_shift -= 8;
1119
-
1120
972
  if (p === cur_subblock + 256) {
1121
973
  buf[cur_subblock] = 255;
1122
974
  cur_subblock = p++;
1123
975
  }
1124
976
  }
1125
-
1126
977
  if (next_code === 4096) {
1127
978
  emit_code(clear_code);
1128
979
  next_code = eoi_code + 1;
@@ -1142,20 +993,16 @@ function gifWriter(buf, width, height, gopts) {
1142
993
  emit_code(ib_code);
1143
994
  emit_code(eoi_code);
1144
995
  emit_bytes_to_buffer(1);
1145
-
1146
996
  if (cur_subblock + 1 === p) {
1147
997
  buf[cur_subblock] = 0;
1148
998
  } else {
1149
999
  buf[cur_subblock] = p - cur_subblock - 1;
1150
1000
  buf[p++] = 0;
1151
1001
  }
1152
-
1153
1002
  return p;
1154
1003
  }
1155
1004
  }
1156
-
1157
1005
  var noop$2 = function noop() {};
1158
-
1159
1006
  var AnimatedGIF = function AnimatedGIF(options) {
1160
1007
  this.canvas = null;
1161
1008
  this.ctx = null;
@@ -1170,7 +1017,6 @@ var AnimatedGIF = function AnimatedGIF(options) {
1170
1017
  this.options = options;
1171
1018
  this.initializeWebWorkers(options);
1172
1019
  };
1173
-
1174
1020
  AnimatedGIF.prototype = {
1175
1021
  workerMethods: workerCode(),
1176
1022
  initializeWebWorkers: function initializeWebWorkers(options) {
@@ -1183,10 +1029,8 @@ AnimatedGIF.prototype = {
1183
1029
  var x = -1;
1184
1030
  var workerError = '';
1185
1031
  numWorkers = options.numWorkers;
1186
-
1187
1032
  while (++x < numWorkers) {
1188
1033
  webWorkerObj = utils.createWebWorker(processFrameWorkerCode);
1189
-
1190
1034
  if (utils.isObject(webWorkerObj)) {
1191
1035
  objectUrl = webWorkerObj.objectUrl;
1192
1036
  webWorker = webWorkerObj.worker;
@@ -1200,7 +1044,6 @@ AnimatedGIF.prototype = {
1200
1044
  utils.webWorkerError = Boolean(webWorkerObj);
1201
1045
  }
1202
1046
  }
1203
-
1204
1047
  this.workerError = workerError;
1205
1048
  this.canvas = document.createElement('canvas');
1206
1049
  this.canvas.width = options.gifWidth;
@@ -1216,22 +1059,18 @@ AnimatedGIF.prototype = {
1216
1059
  },
1217
1060
  byteMap: function () {
1218
1061
  var byteMap = [];
1219
-
1220
1062
  for (var i = 0; i < 256; i++) {
1221
1063
  byteMap[i] = String.fromCharCode(i);
1222
1064
  }
1223
-
1224
1065
  return byteMap;
1225
1066
  }(),
1226
1067
  bufferToString: function bufferToString(buffer) {
1227
1068
  var numberValues = buffer.length;
1228
1069
  var str = '';
1229
1070
  var x = -1;
1230
-
1231
1071
  while (++x < numberValues) {
1232
1072
  str += this.byteMap[buffer[x]];
1233
1073
  }
1234
-
1235
1074
  return str;
1236
1075
  },
1237
1076
  onFrameFinished: function onFrameFinished(progressCallback) {
@@ -1243,13 +1082,10 @@ AnimatedGIF.prototype = {
1243
1082
  return !frame.beingProcessed && frame.done;
1244
1083
  });
1245
1084
  self.numRenderedFrames++;
1246
-
1247
1085
  if (hasExistingImages) {
1248
1086
  progressCallback(self.numRenderedFrames / frames.length);
1249
1087
  }
1250
-
1251
1088
  self.onRenderProgressCallback(self.numRenderedFrames * 0.75 / frames.length);
1252
-
1253
1089
  if (allDone) {
1254
1090
  if (!self.generatingGIF) {
1255
1091
  self.generateGIF(frames, self.onRenderCompleteCallback);
@@ -1269,7 +1105,6 @@ AnimatedGIF.prototype = {
1269
1105
  var frames = this.frames;
1270
1106
  var frame = void 0;
1271
1107
  var worker = void 0;
1272
-
1273
1108
  var done = function done() {
1274
1109
  var ev = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1275
1110
  var data = ev.data;
@@ -1281,19 +1116,15 @@ AnimatedGIF.prototype = {
1281
1116
  AnimatedGifContext.freeWorker(worker);
1282
1117
  AnimatedGifContext.onFrameFinished(progressCallback);
1283
1118
  };
1284
-
1285
1119
  frame = frames[position];
1286
-
1287
1120
  if (frame.beingProcessed || frame.done) {
1288
1121
  this.onFrameFinished();
1289
1122
  return;
1290
1123
  }
1291
-
1292
1124
  frame.sampleInterval = sampleInterval;
1293
1125
  frame.beingProcessed = true;
1294
1126
  frame.gifshot = true;
1295
1127
  worker = this.getWorker();
1296
-
1297
1128
  if (worker) {
1298
1129
  worker.onmessage = done;
1299
1130
  worker.postMessage(frame);
@@ -1305,23 +1136,19 @@ AnimatedGIF.prototype = {
1305
1136
  },
1306
1137
  startRendering: function startRendering(completeCallback) {
1307
1138
  this.onRenderCompleteCallback = completeCallback;
1308
-
1309
1139
  for (var i = 0; i < this.options.numWorkers && i < this.frames.length; i++) {
1310
1140
  this.processFrame(i);
1311
1141
  }
1312
1142
  },
1313
1143
  processNextFrame: function processNextFrame() {
1314
1144
  var position = -1;
1315
-
1316
1145
  for (var i = 0; i < this.frames.length; i++) {
1317
1146
  var frame = this.frames[i];
1318
-
1319
1147
  if (!frame.done && !frame.beingProcessed) {
1320
1148
  position = i;
1321
1149
  break;
1322
1150
  }
1323
1151
  }
1324
-
1325
1152
  if (position >= 0) {
1326
1153
  this.processFrame(position);
1327
1154
  }
@@ -1347,7 +1174,6 @@ AnimatedGIF.prototype = {
1347
1174
  utils.each(frames, function (iterator, frame) {
1348
1175
  var framePalette = frame.palette;
1349
1176
  onRenderProgressCallback(0.75 + 0.25 * frame.position * 1.0 / frames.length);
1350
-
1351
1177
  for (var i = 0; i < frameDuration; i++) {
1352
1178
  gifWriter$$1.addFrame(0, 0, width, height, frame.pixels, {
1353
1179
  palette: framePalette,
@@ -1359,7 +1185,6 @@ AnimatedGIF.prototype = {
1359
1185
  onRenderProgressCallback(1.0);
1360
1186
  this.frames = [];
1361
1187
  this.generatingGIF = false;
1362
-
1363
1188
  if (utils.isFunction(callback)) {
1364
1189
  bufferToString = this.bufferToString(buffer);
1365
1190
  gif = "data:image/gif;base64,".concat(utils.btoa(bufferToString));
@@ -1391,11 +1216,9 @@ AnimatedGIF.prototype = {
1391
1216
  var textYCoordinate = gifshotOptions.textYCoordinate ? gifshotOptions.textYCoordinate : textBaseline === 'top' ? 1 : textBaseline === 'center' ? height / 2 : height;
1392
1217
  var font = "".concat(fontWeight, " ").concat(fontSize, " ").concat(fontFamily);
1393
1218
  var imageData = void 0;
1394
-
1395
1219
  try {
1396
1220
  ctx.filter = filter;
1397
1221
  ctx.drawImage(element, 0, 0, width, height);
1398
-
1399
1222
  if (text) {
1400
1223
  ctx.font = font;
1401
1224
  ctx.fillStyle = fontColor;
@@ -1403,7 +1226,6 @@ AnimatedGIF.prototype = {
1403
1226
  ctx.textBaseline = textBaseline;
1404
1227
  ctx.fillText(text, textXCoordinate, textYCoordinate);
1405
1228
  }
1406
-
1407
1229
  imageData = ctx.getImageData(0, 0, width, height);
1408
1230
  self.addFrameImageData(imageData);
1409
1231
  } catch (e) {
@@ -1433,21 +1255,18 @@ AnimatedGIF.prototype = {
1433
1255
  },
1434
1256
  getBase64GIF: function getBase64GIF(completeCallback) {
1435
1257
  var self = this;
1436
-
1437
1258
  var onRenderComplete = function onRenderComplete(gif) {
1438
1259
  self.destroyWorkers();
1439
1260
  utils.requestTimeout(function () {
1440
1261
  completeCallback(gif);
1441
1262
  }, 0);
1442
1263
  };
1443
-
1444
1264
  self.startRendering(onRenderComplete);
1445
1265
  },
1446
1266
  destroyWorkers: function destroyWorkers() {
1447
1267
  if (this.workerError) {
1448
1268
  return;
1449
1269
  }
1450
-
1451
1270
  var workers = this.workers;
1452
1271
  utils.each(workers, function (iterator, workerObj) {
1453
1272
  var worker = workerObj.worker;
@@ -1457,7 +1276,6 @@ AnimatedGIF.prototype = {
1457
1276
  });
1458
1277
  }
1459
1278
  };
1460
-
1461
1279
  function getBase64GIF(animatedGifInstance, callback) {
1462
1280
  animatedGifInstance.getBase64GIF(function (image) {
1463
1281
  callback({
@@ -1468,7 +1286,6 @@ function getBase64GIF(animatedGifInstance, callback) {
1468
1286
  });
1469
1287
  });
1470
1288
  }
1471
-
1472
1289
  function existingImages() {
1473
1290
  var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1474
1291
  var self = this;
@@ -1485,49 +1302,39 @@ function existingImages() {
1485
1302
  var loadedImagesLength = 0;
1486
1303
  var tempImage = void 0;
1487
1304
  var ag = void 0;
1488
-
1489
1305
  if (errorObj.error) {
1490
1306
  return callback(errorObj);
1491
1307
  }
1492
-
1493
1308
  ag = new AnimatedGIF(options);
1494
1309
  utils.each(images, function (index, image) {
1495
1310
  var currentImage = image;
1496
-
1497
1311
  if (utils.isElement(currentImage)) {
1498
1312
  if (options.crossOrigin) {
1499
1313
  currentImage.crossOrigin = options.crossOrigin;
1500
1314
  }
1501
-
1502
1315
  loadedImages[index] = currentImage;
1503
1316
  loadedImagesLength += 1;
1504
-
1505
1317
  if (loadedImagesLength === imagesLength) {
1506
1318
  addLoadedImagesToGif();
1507
1319
  }
1508
1320
  } else if (utils.isString(currentImage)) {
1509
1321
  tempImage = new Image();
1510
-
1511
1322
  if (options.crossOrigin) {
1512
1323
  tempImage.crossOrigin = options.crossOrigin;
1513
1324
  }
1514
-
1515
1325
  (function (tempImage) {
1516
1326
  if (image.text) {
1517
1327
  tempImage.text = image.text;
1518
1328
  }
1519
-
1520
1329
  tempImage.onerror = function (e) {
1521
1330
  var obj = void 0;
1522
1331
  --imagesLength;
1523
-
1524
1332
  if (imagesLength === 0) {
1525
1333
  obj = {};
1526
1334
  obj.error = 'None of the requested images was capable of being retrieved';
1527
1335
  return callback(obj);
1528
1336
  }
1529
1337
  };
1530
-
1531
1338
  tempImage.onload = function (e) {
1532
1339
  if (image.text) {
1533
1340
  loadedImages[index] = {
@@ -1537,19 +1344,14 @@ function existingImages() {
1537
1344
  } else {
1538
1345
  loadedImages[index] = tempImage;
1539
1346
  }
1540
-
1541
1347
  loadedImagesLength += 1;
1542
-
1543
1348
  if (loadedImagesLength === imagesLength) {
1544
1349
  addLoadedImagesToGif();
1545
1350
  }
1546
-
1547
1351
  utils.removeElement(tempImage);
1548
1352
  };
1549
-
1550
1353
  tempImage.src = currentImage;
1551
1354
  })(tempImage);
1552
-
1553
1355
  utils.setCSSAttr(tempImage, {
1554
1356
  position: 'fixed',
1555
1357
  opacity: '0'
@@ -1557,7 +1359,6 @@ function existingImages() {
1557
1359
  document.body.appendChild(tempImage);
1558
1360
  }
1559
1361
  });
1560
-
1561
1362
  function addLoadedImagesToGif() {
1562
1363
  utils.each(loadedImages, function (index, loadedImage) {
1563
1364
  if (loadedImage) {
@@ -1571,9 +1372,7 @@ function existingImages() {
1571
1372
  getBase64GIF(ag, callback);
1572
1373
  }
1573
1374
  }
1574
-
1575
1375
  var noop$3 = function noop() {};
1576
-
1577
1376
  var screenShot = {
1578
1377
  getGIF: function getGIF() {
1579
1378
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -1618,35 +1417,28 @@ var screenShot = {
1618
1417
  var sourceWidth = crop ? videoWidth - crop.scaledWidth : 0;
1619
1418
  var sourceY = crop ? Math.floor(crop.scaledHeight / 2) : 0;
1620
1419
  var sourceHeight = crop ? videoHeight - crop.scaledHeight : 0;
1621
-
1622
1420
  var captureFrames = function captureSingleFrame() {
1623
1421
  var framesLeft = pendingFrames - 1;
1624
-
1625
1422
  if (savedRenderingContexts.length) {
1626
1423
  context.putImageData(savedRenderingContexts[numFrames - pendingFrames], 0, 0);
1627
1424
  finishCapture();
1628
1425
  } else {
1629
1426
  drawVideo();
1630
1427
  }
1631
-
1632
1428
  function drawVideo() {
1633
1429
  try {
1634
1430
  if (sourceWidth > videoWidth) {
1635
1431
  sourceWidth = videoWidth;
1636
1432
  }
1637
-
1638
1433
  if (sourceHeight > videoHeight) {
1639
1434
  sourceHeight = videoHeight;
1640
1435
  }
1641
-
1642
1436
  if (sourceX < 0) {
1643
1437
  sourceX = 0;
1644
1438
  }
1645
-
1646
1439
  if (sourceY < 0) {
1647
1440
  sourceY = 0;
1648
1441
  }
1649
-
1650
1442
  context.filter = filter;
1651
1443
  context.drawImage(videoElement, sourceX, sourceY, sourceWidth, sourceHeight, 0, 0, gifWidth, gifHeight);
1652
1444
  finishCapture();
@@ -1658,14 +1450,11 @@ var screenShot = {
1658
1450
  }
1659
1451
  }
1660
1452
  }
1661
-
1662
1453
  function finishCapture() {
1663
1454
  var imageData = void 0;
1664
-
1665
1455
  if (saveRenderingContexts) {
1666
1456
  renderingContextsToSave.push(context.getImageData(0, 0, gifWidth, gifHeight));
1667
1457
  }
1668
-
1669
1458
  if (text) {
1670
1459
  context.font = font;
1671
1460
  context.fillStyle = fontColor;
@@ -1673,16 +1462,13 @@ var screenShot = {
1673
1462
  context.textBaseline = textBaseline;
1674
1463
  context.fillText(text, textXCoordinate, textYCoordinate);
1675
1464
  }
1676
-
1677
1465
  imageData = context.getImageData(0, 0, gifWidth, gifHeight);
1678
1466
  ag.addFrameImageData(imageData);
1679
1467
  pendingFrames = framesLeft;
1680
1468
  progressCallback((numFrames - pendingFrames) / numFrames);
1681
-
1682
1469
  if (framesLeft > 0) {
1683
1470
  utils.requestTimeout(captureSingleFrame, waitBetweenFrames);
1684
1471
  }
1685
-
1686
1472
  if (!pendingFrames) {
1687
1473
  ag.getBase64GIF(function (image) {
1688
1474
  callback({
@@ -1700,19 +1486,16 @@ var screenShot = {
1700
1486
  }
1701
1487
  }
1702
1488
  };
1703
-
1704
1489
  numFrames = numFrames !== undefined ? numFrames : 10;
1705
1490
  interval = interval !== undefined ? interval : 0.1;
1706
1491
  canvas.width = gifWidth;
1707
1492
  canvas.height = gifHeight;
1708
1493
  context = canvas.getContext('2d');
1709
-
1710
1494
  (function capture() {
1711
1495
  if (!savedRenderingContexts.length && videoElement.currentTime === 0) {
1712
1496
  utils.requestTimeout(capture, 100);
1713
1497
  return;
1714
1498
  }
1715
-
1716
1499
  captureFrames();
1717
1500
  })();
1718
1501
  },
@@ -1728,7 +1511,6 @@ var screenShot = {
1728
1511
  scaledWidth: 0,
1729
1512
  scaledHeight: 0
1730
1513
  };
1731
-
1732
1514
  if (width > height) {
1733
1515
  result.width = Math.round(width * (gifHeight / height)) - gifWidth;
1734
1516
  result.scaledWidth = Math.round(result.width * (height / gifHeight));
@@ -1736,7 +1518,6 @@ var screenShot = {
1736
1518
  result.height = Math.round(height * (gifWidth / width)) - gifHeight;
1737
1519
  result.scaledHeight = Math.round(result.height * (width / gifWidth));
1738
1520
  }
1739
-
1740
1521
  return result;
1741
1522
  }
1742
1523
  };
@@ -1751,11 +1532,9 @@ var videoStream = {
1751
1532
  var cameraStream = obj.cameraStream;
1752
1533
  var completedCallback = obj.completedCallback;
1753
1534
  var videoElement = obj.videoElement;
1754
-
1755
1535
  if (!videoElement) {
1756
1536
  return;
1757
1537
  }
1758
-
1759
1538
  if (videoElement.videoWidth > 0 && videoElement.videoHeight > 0) {
1760
1539
  videoElement.removeEventListener('loadeddata', videoStream.findVideoSize);
1761
1540
  completedCallback({
@@ -1795,11 +1574,9 @@ var videoStream = {
1795
1574
  var completedCallback = obj.completedCallback;
1796
1575
  var streamedCallback = obj.streamedCallback;
1797
1576
  var videoElement = obj.videoElement;
1798
-
1799
1577
  if (utils.isFunction(streamedCallback)) {
1800
1578
  streamedCallback();
1801
1579
  }
1802
-
1803
1580
  if (existingVideo) {
1804
1581
  if (utils.isString(existingVideo)) {
1805
1582
  videoElement.src = existingVideo;
@@ -1808,7 +1585,6 @@ var videoStream = {
1808
1585
  try {
1809
1586
  videoElement.src = utils.URL.createObjectURL(existingVideo);
1810
1587
  } catch (e) {}
1811
-
1812
1588
  videoElement.innerHTML = "<source src=\"".concat(existingVideo, "\" type=\"").concat(existingVideo.type, "\" />");
1813
1589
  }
1814
1590
  } else if (videoElement.mozSrcObject) {
@@ -1821,11 +1597,9 @@ var videoStream = {
1821
1597
  videoElement.srcObject = cameraStream;
1822
1598
  }
1823
1599
  }
1824
-
1825
1600
  videoElement.play();
1826
1601
  utils.requestTimeout(function checkLoadedData() {
1827
1602
  checkLoadedData.count = checkLoadedData.count || 0;
1828
-
1829
1603
  if (videoStream.loadedData === true) {
1830
1604
  videoStream.findVideoSize({
1831
1605
  videoElement: videoElement,
@@ -1835,7 +1609,6 @@ var videoStream = {
1835
1609
  videoStream.loadedData = false;
1836
1610
  } else {
1837
1611
  checkLoadedData.count += 1;
1838
-
1839
1612
  if (checkLoadedData.count > 10) {
1840
1613
  videoStream.findVideoSize({
1841
1614
  videoElement: videoElement,
@@ -1859,22 +1632,18 @@ var videoStream = {
1859
1632
  var webcamVideoElement = obj.webcamVideoElement;
1860
1633
  var videoElement = utils.isElement(existingVideo) ? existingVideo : webcamVideoElement ? webcamVideoElement : document.createElement('video');
1861
1634
  var cameraStream = void 0;
1862
-
1863
1635
  if (crossOrigin) {
1864
1636
  videoElement.crossOrigin = options.crossOrigin;
1865
1637
  }
1866
-
1867
1638
  videoElement.autoplay = true;
1868
1639
  videoElement.loop = true;
1869
1640
  videoElement.muted = true;
1870
1641
  videoElement.addEventListener('loadeddata', function (event) {
1871
1642
  videoStream.loadedData = true;
1872
-
1873
1643
  if (options.offset) {
1874
1644
  videoElement.currentTime = options.offset;
1875
1645
  }
1876
1646
  });
1877
-
1878
1647
  if (existingVideo) {
1879
1648
  videoStream.stream({
1880
1649
  videoElement: videoElement,
@@ -1907,13 +1676,11 @@ var videoStream = {
1907
1676
  var originalCallback = options.callback;
1908
1677
  var webcamVideoElement = options.webcamVideoElement;
1909
1678
  var noGetUserMediaSupportTimeout = void 0;
1910
-
1911
1679
  if (timeoutLength > 0) {
1912
1680
  noGetUserMediaSupportTimeout = utils.requestTimeout(function () {
1913
1681
  videoStream.onStreamingTimeout(originalCallback);
1914
1682
  }, 10000);
1915
1683
  }
1916
-
1917
1684
  videoStream.startStreaming({
1918
1685
  error: function error() {
1919
1686
  originalCallback({
@@ -1956,32 +1723,26 @@ var videoStream = {
1956
1723
  var cameraStreamTracks = cameraStream.getTracks ? cameraStream.getTracks() || [] : [];
1957
1724
  var hasCameraStreamTracks = Boolean(cameraStreamTracks.length);
1958
1725
  var firstCameraStreamTrack = cameraStreamTracks[0];
1959
-
1960
1726
  if (!keepCameraOn && hasCameraStreamTracks) {
1961
1727
  if (utils.isFunction(firstCameraStreamTrack.stop)) {
1962
1728
  firstCameraStreamTrack.stop();
1963
1729
  }
1964
1730
  }
1965
-
1966
1731
  if (utils.isElement(videoElement) && !webcamVideoElement) {
1967
1732
  videoElement.pause();
1968
-
1969
1733
  if (utils.isFunction(utils.URL.revokeObjectURL) && !utils.webWorkerError) {
1970
1734
  if (videoElement.src) {
1971
1735
  utils.URL.revokeObjectURL(videoElement.src);
1972
1736
  }
1973
1737
  }
1974
-
1975
1738
  utils.removeElement(videoElement);
1976
1739
  }
1977
1740
  }
1978
1741
  };
1979
-
1980
1742
  function stopVideoStreaming(options) {
1981
1743
  options = utils.isObject(options) ? options : {};
1982
1744
  videoStream.stopVideoStreaming(options);
1983
1745
  }
1984
-
1985
1746
  function createAndGetGIF(obj, callback) {
1986
1747
  var options = obj.options || {};
1987
1748
  var images = options.images;
@@ -2005,14 +1766,11 @@ function createAndGetGIF(obj, callback) {
2005
1766
  options.videoWidth = videoWidth;
2006
1767
  options.videoHeight = videoHeight;
2007
1768
  options.cameraStream = cameraStream;
2008
-
2009
1769
  if (!utils.isElement(videoElement)) {
2010
1770
  return;
2011
1771
  }
2012
-
2013
1772
  videoElement.width = gifWidth + cropDimensions.width;
2014
1773
  videoElement.height = gifHeight + cropDimensions.height;
2015
-
2016
1774
  if (!options.webcamVideoElement) {
2017
1775
  utils.setCSSAttr(videoElement, {
2018
1776
  position: 'fixed',
@@ -2020,17 +1778,14 @@ function createAndGetGIF(obj, callback) {
2020
1778
  });
2021
1779
  document.body.appendChild(videoElement);
2022
1780
  }
2023
-
2024
1781
  videoElement.play();
2025
1782
  screenShot.getGIF(options, function (obj) {
2026
1783
  if ((!images || !images.length) && (!video || !video.length)) {
2027
1784
  stopVideoStreaming(obj);
2028
1785
  }
2029
-
2030
1786
  completeCallback(obj);
2031
1787
  });
2032
1788
  }
2033
-
2034
1789
  function existingVideo() {
2035
1790
  var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2036
1791
  var callback = obj.callback;
@@ -2046,15 +1801,12 @@ function existingVideo() {
2046
1801
  var videoSrc = void 0;
2047
1802
  var tempImage = void 0;
2048
1803
  var ag = void 0;
2049
-
2050
1804
  if (errorObj.error) {
2051
1805
  return callback(errorObj);
2052
1806
  }
2053
-
2054
1807
  if (utils.isElement(existingVideo) && existingVideo.src) {
2055
1808
  videoSrc = existingVideo.src;
2056
1809
  videoType = utils.getExtension(videoSrc);
2057
-
2058
1810
  if (!utils.isSupported.videoCodecs[videoType]) {
2059
1811
  return callback(error.messages.videoCodecs);
2060
1812
  }
@@ -2065,14 +1817,12 @@ function existingVideo() {
2065
1817
  } else {
2066
1818
  videoType = videoSrc.substr(videoSrc.lastIndexOf('.') + 1, videoSrc.length);
2067
1819
  }
2068
-
2069
1820
  if (utils.isSupported.videoCodecs[videoType]) {
2070
1821
  existingVideo = videoSrc;
2071
1822
  return false;
2072
1823
  }
2073
1824
  });
2074
1825
  }
2075
-
2076
1826
  videoStream.startStreaming({
2077
1827
  completed: function completed(obj) {
2078
1828
  obj.options = options || {};
@@ -2083,25 +1833,21 @@ function existingVideo() {
2083
1833
  options: options
2084
1834
  });
2085
1835
  }
2086
-
2087
1836
  function existingWebcam() {
2088
1837
  var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2089
1838
  var callback = obj.callback;
2090
1839
  var lastCameraStream = obj.lastCameraStream;
2091
1840
  var options = obj.options;
2092
1841
  var webcamVideoElement = obj.webcamVideoElement;
2093
-
2094
1842
  if (!isWebCamGIFSupported()) {
2095
1843
  return callback(error.validate());
2096
1844
  }
2097
-
2098
1845
  if (options.savedRenderingContexts.length) {
2099
1846
  screenShot.getGIF(options, function (obj) {
2100
1847
  callback(obj);
2101
1848
  });
2102
1849
  return;
2103
1850
  }
2104
-
2105
1851
  videoStream.startVideoStreaming(function () {
2106
1852
  var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2107
1853
  obj.options = options || {};
@@ -2113,15 +1859,12 @@ function existingWebcam() {
2113
1859
  crossOrigin: options.crossOrigin
2114
1860
  });
2115
1861
  }
2116
-
2117
1862
  function createGIF(userOptions, callback) {
2118
1863
  callback = utils.isFunction(userOptions) ? userOptions : callback;
2119
1864
  userOptions = utils.isObject(userOptions) ? userOptions : {};
2120
-
2121
1865
  if (!utils.isFunction(callback)) {
2122
1866
  return;
2123
1867
  }
2124
-
2125
1868
  var options = utils.normalizeOptions(defaultOptions, userOptions) || {};
2126
1869
  var lastCameraStream = userOptions.cameraStream;
2127
1870
  var images = options.images;
@@ -2132,7 +1875,6 @@ function createGIF(userOptions, callback) {
2132
1875
  gifWidth: Math.floor(options.gifWidth),
2133
1876
  gifHeight: Math.floor(options.gifHeight)
2134
1877
  });
2135
-
2136
1878
  if (imagesLength) {
2137
1879
  existingImages({
2138
1880
  images: images,
@@ -2155,15 +1897,12 @@ function createGIF(userOptions, callback) {
2155
1897
  });
2156
1898
  }
2157
1899
  }
2158
-
2159
1900
  function takeSnapShot(userOptions, callback) {
2160
1901
  callback = utils.isFunction(userOptions) ? userOptions : callback;
2161
1902
  userOptions = utils.isObject(userOptions) ? userOptions : {};
2162
-
2163
1903
  if (!utils.isFunction(callback)) {
2164
1904
  return;
2165
1905
  }
2166
-
2167
1906
  var mergedOptions = utils.normalizeOptions(defaultOptions, userOptions);
2168
1907
  var options = utils.normalizeOptions(mergedOptions, {
2169
1908
  interval: 0.1,
@@ -2173,7 +1912,6 @@ function takeSnapShot(userOptions, callback) {
2173
1912
  });
2174
1913
  createGIF(options, callback);
2175
1914
  }
2176
-
2177
1915
  var API = {
2178
1916
  utils: utils$2,
2179
1917
  error: error$2,