@loaders.gl/video 3.4.14 → 3.4.15

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.
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = void 0;
8
- var _readOnlyError2 = _interopRequireDefault(require("@babel/runtime/helpers/readOnlyError"));
9
7
  var utils = {
10
8
  URL: globalThis.URL || globalThis.webkitURL || globalThis.mozURL || globalThis.msURL,
11
9
  getUserMedia: function () {
12
10
  if (!globalThis.navigator) return globalThis.navigator;
13
- var getUserMedia = globalThis.navigator.getUserMedia || globalThis.navigator.webkitGetUserMedia || globalThis.navigator.mozGetUserMedia || globalThis.navigator.msGetUserMedia;
11
+ const getUserMedia = globalThis.navigator.getUserMedia || globalThis.navigator.webkitGetUserMedia || globalThis.navigator.mozGetUserMedia || globalThis.navigator.msGetUserMedia;
14
12
  return getUserMedia ? getUserMedia.bind(globalThis.navigator) : getUserMedia;
15
13
  }(),
16
14
  requestAnimFrame: globalThis.requestAnimationFrame || globalThis.webkitRequestAnimationFrame || globalThis.mozRequestAnimationFrame || globalThis.oRequestAnimationFrame || globalThis.msRequestAnimationFrame,
@@ -20,12 +18,12 @@ var utils = {
20
18
  if (!utils.requestAnimFrame) {
21
19
  return setTimeout(callback, delay);
22
20
  }
23
- var start = new Date().getTime();
24
- var handle = new Object();
25
- var requestAnimFrame = utils.requestAnimFrame;
26
- var loop = function loop() {
27
- var current = new Date().getTime();
28
- var delta = current - start;
21
+ const start = new Date().getTime();
22
+ const handle = new Object();
23
+ const requestAnimFrame = utils.requestAnimFrame;
24
+ const loop = function loop() {
25
+ const current = new Date().getTime();
26
+ const delta = current - start;
29
27
  delta >= delay ? callback.call() : handle.value = requestAnimFrame(loop);
30
28
  };
31
29
  handle.value = requestAnimFrame(loop);
@@ -33,18 +31,18 @@ var utils = {
33
31
  },
34
32
  Blob: globalThis.Blob || globalThis.BlobBuilder || globalThis.WebKitBlobBuilder || globalThis.MozBlobBuilder || globalThis.MSBlobBuilder,
35
33
  btoa: function () {
36
- var btoa = globalThis.btoa || function (input) {
37
- var output = '';
38
- var i = 0;
39
- var l = input.length;
40
- var key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
41
- var chr1 = void 0;
42
- var chr2 = void 0;
43
- var chr3 = void 0;
44
- var enc1 = void 0;
45
- var enc2 = void 0;
46
- var enc3 = void 0;
47
- var enc4 = void 0;
34
+ const btoa = globalThis.btoa || function (input) {
35
+ let output = '';
36
+ let i = 0;
37
+ const l = input.length;
38
+ const key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
39
+ let chr1 = void 0;
40
+ let chr2 = void 0;
41
+ let chr3 = void 0;
42
+ let enc1 = void 0;
43
+ let enc2 = void 0;
44
+ let enc3 = void 0;
45
+ let enc4 = void 0;
48
46
  while (i < l) {
49
47
  chr1 = input.charCodeAt(i++);
50
48
  chr2 = input.charCodeAt(i++);
@@ -84,7 +82,7 @@ var utils = {
84
82
  },
85
83
  isSupported: {
86
84
  canvas: function canvas() {
87
- var el = document.createElement('canvas');
85
+ const el = document.createElement('canvas');
88
86
  return el && el.getContext && el.getContext('2d');
89
87
  },
90
88
  webworkers: function webworkers() {
@@ -100,8 +98,8 @@ var utils = {
100
98
  return globalThis.Uint32Array;
101
99
  },
102
100
  videoCodecs: function () {
103
- var testEl = document.createElement('video');
104
- var supportObj = {
101
+ const testEl = document.createElement('video');
102
+ const supportObj = {
105
103
  mp4: false,
106
104
  h264: false,
107
105
  ogv: false,
@@ -122,8 +120,8 @@ var utils = {
122
120
  },
123
121
  noop: function noop() {},
124
122
  each: function each(collection, callback) {
125
- var x = void 0;
126
- var len = void 0;
123
+ let x = void 0;
124
+ let len = void 0;
127
125
  if (utils.isArray(collection)) {
128
126
  x = -1;
129
127
  len = collection.length;
@@ -146,12 +144,12 @@ var utils = {
146
144
  if (!utils.isObject(defaultOptions) || !utils.isObject(userOptions) || !Object.keys) {
147
145
  return;
148
146
  }
149
- var newObj = {};
147
+ const newObj = {};
150
148
  utils.each(defaultOptions, function (key, val) {
151
149
  newObj[key] = defaultOptions[key];
152
150
  });
153
151
  utils.each(userOptions, function (key, val) {
154
- var currentUserOption = userOptions[key];
152
+ const currentUserOption = userOptions[key];
155
153
  if (!utils.isObject(currentUserOption)) {
156
154
  newObj[key] = currentUserOption;
157
155
  } else if (!defaultOptions[key]) {
@@ -187,14 +185,14 @@ var utils = {
187
185
  return {};
188
186
  }
189
187
  try {
190
- var blob = new utils.Blob([content], {
188
+ const blob = new utils.Blob([content], {
191
189
  type: 'text/javascript'
192
190
  });
193
- var objectUrl = utils.URL.createObjectURL(blob);
194
- var worker = new Worker(objectUrl);
191
+ const objectUrl = utils.URL.createObjectURL(blob);
192
+ const worker = new Worker(objectUrl);
195
193
  return {
196
- objectUrl: objectUrl,
197
- worker: worker
194
+ objectUrl,
195
+ worker
198
196
  };
199
197
  } catch (e) {
200
198
  return "".concat(e);
@@ -204,16 +202,16 @@ var utils = {
204
202
  return src.substr(src.lastIndexOf('.') + 1, src.length);
205
203
  },
206
204
  getFontSize: function getFontSize() {
207
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
205
+ const options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
208
206
  if (!document.body || options.resizeFont === false) {
209
207
  return options.fontSize;
210
208
  }
211
- var text = options.text;
212
- var containerWidth = options.gifWidth;
213
- var fontSize = parseInt(options.fontSize, 10);
214
- var minFontSize = parseInt(options.minFontSize, 10);
215
- var div = document.createElement('div');
216
- var span = document.createElement('span');
209
+ const text = options.text;
210
+ const containerWidth = options.gifWidth;
211
+ let fontSize = parseInt(options.fontSize, 10);
212
+ const minFontSize = parseInt(options.minFontSize, 10);
213
+ const div = document.createElement('div');
214
+ const span = document.createElement('span');
217
215
  div.setAttribute('width', containerWidth);
218
216
  div.appendChild(span);
219
217
  span.innerHTML = text;
@@ -229,15 +227,15 @@ var utils = {
229
227
  },
230
228
  webWorkerError: false
231
229
  };
232
- var utils$2 = Object.freeze({
230
+ const utils$2 = Object.freeze({
233
231
  default: utils
234
232
  });
235
233
  var error = {
236
234
  validate: function validate(skipObj) {
237
235
  skipObj = utils.isObject(skipObj) ? skipObj : {};
238
- var errorObj = {};
236
+ let errorObj = {};
239
237
  utils.each(error.validators, function (indece, currentValidator) {
240
- var errorCode = currentValidator.errorCode;
238
+ const errorCode = currentValidator.errorCode;
241
239
  if (!skipObj[errorCode] && !currentValidator.condition) {
242
240
  errorObj = currentValidator;
243
241
  errorObj.error = true;
@@ -248,8 +246,8 @@ var error = {
248
246
  return errorObj;
249
247
  },
250
248
  isValid: function isValid(skipObj) {
251
- var errorObj = error.validate(skipObj);
252
- var isValid = errorObj.error !== true;
249
+ const errorObj = error.validate(skipObj);
250
+ const isValid = errorObj.error !== true;
253
251
  return isValid;
254
252
  },
255
253
  validators: [{
@@ -288,11 +286,11 @@ var error = {
288
286
  }
289
287
  }
290
288
  };
291
- var error$2 = Object.freeze({
289
+ const error$2 = Object.freeze({
292
290
  default: error
293
291
  });
294
- var noop = function noop() {};
295
- var defaultOptions = {
292
+ const noop = function noop() {};
293
+ const defaultOptions = {
296
294
  sampleInterval: 10,
297
295
  numWorkers: 2,
298
296
  filter: '',
@@ -323,7 +321,7 @@ var defaultOptions = {
323
321
  savedRenderingContexts: [],
324
322
  crossOrigin: 'Anonymous'
325
323
  };
326
- var defaultOptions$2 = Object.freeze({
324
+ const defaultOptions$2 = Object.freeze({
327
325
  default: defaultOptions
328
326
  });
329
327
  function isSupported() {
@@ -333,13 +331,13 @@ function isWebCamGIFSupported() {
333
331
  return error.isValid();
334
332
  }
335
333
  function isSupported$1() {
336
- var options = {
334
+ const options = {
337
335
  getUserMedia: true
338
336
  };
339
337
  return error.isValid(options);
340
338
  }
341
339
  function isExistingVideoGIFSupported(codecs) {
342
- var hasValidCodec = false;
340
+ let hasValidCodec = false;
343
341
  if (utils.isArray(codecs) && codecs.length) {
344
342
  utils.each(codecs, function (indece, currentCodec) {
345
343
  if (utils.isSupported.videoCodecs[currentCodec]) {
@@ -359,45 +357,45 @@ function isExistingVideoGIFSupported(codecs) {
359
357
  });
360
358
  }
361
359
  function NeuQuant() {
362
- var netsize = 256;
363
- var prime1 = 499;
364
- var prime2 = 491;
365
- var prime3 = 487;
366
- var prime4 = 503;
367
- var minpicturebytes = 3 * prime4;
368
- var maxnetpos = netsize - 1;
369
- var netbiasshift = 4;
370
- var ncycles = 100;
371
- var intbiasshift = 16;
372
- var intbias = 1 << intbiasshift;
373
- var gammashift = 10;
374
- var gamma = 1 << gammashift;
375
- var betashift = 10;
376
- var beta = intbias >> betashift;
377
- var betagamma = intbias << gammashift - betashift;
378
- var initrad = netsize >> 3;
379
- var radiusbiasshift = 6;
380
- var radiusbias = 1 << radiusbiasshift;
381
- var initradius = initrad * radiusbias;
382
- var radiusdec = 30;
383
- var alphabiasshift = 10;
384
- var initalpha = 1 << alphabiasshift;
385
- var alphadec;
386
- var radbiasshift = 8;
387
- var radbias = 1 << radbiasshift;
388
- var alpharadbshift = alphabiasshift + radbiasshift;
389
- var alpharadbias = 1 << alpharadbshift;
390
- var thepicture;
391
- var lengthcount;
392
- var samplefac;
393
- var network;
394
- var netindex = [];
395
- var bias = [];
396
- var freq = [];
397
- var radpower = [];
360
+ const netsize = 256;
361
+ const prime1 = 499;
362
+ const prime2 = 491;
363
+ const prime3 = 487;
364
+ const prime4 = 503;
365
+ const minpicturebytes = 3 * prime4;
366
+ const maxnetpos = netsize - 1;
367
+ const netbiasshift = 4;
368
+ const ncycles = 100;
369
+ const intbiasshift = 16;
370
+ const intbias = 1 << intbiasshift;
371
+ const gammashift = 10;
372
+ const gamma = 1 << gammashift;
373
+ const betashift = 10;
374
+ const beta = intbias >> betashift;
375
+ const betagamma = intbias << gammashift - betashift;
376
+ const initrad = netsize >> 3;
377
+ const radiusbiasshift = 6;
378
+ const radiusbias = 1 << radiusbiasshift;
379
+ const initradius = initrad * radiusbias;
380
+ const radiusdec = 30;
381
+ const alphabiasshift = 10;
382
+ const initalpha = 1 << alphabiasshift;
383
+ let alphadec;
384
+ const radbiasshift = 8;
385
+ const radbias = 1 << radbiasshift;
386
+ const alpharadbshift = alphabiasshift + radbiasshift;
387
+ const alpharadbias = 1 << alpharadbshift;
388
+ let thepicture;
389
+ let lengthcount;
390
+ let samplefac;
391
+ let network;
392
+ const netindex = [];
393
+ const bias = [];
394
+ const freq = [];
395
+ const radpower = [];
398
396
  function NeuQuantConstructor(thepic, len, sample) {
399
- var i;
400
- var p;
397
+ let i;
398
+ let p;
401
399
  thepicture = thepic;
402
400
  lengthcount = len;
403
401
  samplefac = sample;
@@ -411,14 +409,14 @@ function NeuQuant() {
411
409
  }
412
410
  }
413
411
  function colorMap() {
414
- var map = [];
415
- var index = new Array(netsize);
416
- for (var i = 0; i < netsize; i++) {
412
+ const map = [];
413
+ const index = new Array(netsize);
414
+ for (let i = 0; i < netsize; i++) {
417
415
  index[network[i][3]] = i;
418
416
  }
419
- var k = 0;
420
- for (var l = 0; l < netsize; l++) {
421
- var j = index[l];
417
+ let k = 0;
418
+ for (let l = 0; l < netsize; l++) {
419
+ const j = index[l];
422
420
  map[k++] = network[j][0];
423
421
  map[k++] = network[j][1];
424
422
  map[k++] = network[j][2];
@@ -426,14 +424,14 @@ function NeuQuant() {
426
424
  return map;
427
425
  }
428
426
  function inxbuild() {
429
- var i;
430
- var j;
431
- var smallpos;
432
- var smallval;
433
- var p;
434
- var q;
435
- var previouscol;
436
- var startpos;
427
+ let i;
428
+ let j;
429
+ let smallpos;
430
+ let smallval;
431
+ let p;
432
+ let q;
433
+ let previouscol;
434
+ let startpos;
437
435
  previouscol = 0;
438
436
  startpos = 0;
439
437
  for (i = 0; i < netsize; i++) {
@@ -477,20 +475,20 @@ function NeuQuant() {
477
475
  }
478
476
  }
479
477
  function learn() {
480
- var i;
481
- var j;
482
- var b;
483
- var g;
484
- var r;
485
- var radius;
486
- var rad;
487
- var alpha;
488
- var step;
489
- var delta;
490
- var samplepixels;
491
- var p;
492
- var pix;
493
- var lim;
478
+ let i;
479
+ let j;
480
+ let b;
481
+ let g;
482
+ let r;
483
+ let radius;
484
+ let rad;
485
+ let alpha;
486
+ let step;
487
+ let delta;
488
+ let samplepixels;
489
+ let p;
490
+ let pix;
491
+ let lim;
494
492
  if (lengthcount < minpicturebytes) {
495
493
  samplefac = 1;
496
494
  }
@@ -552,13 +550,13 @@ function NeuQuant() {
552
550
  }
553
551
  }
554
552
  function map(b, g, r) {
555
- var i;
556
- var j;
557
- var dist;
558
- var a;
559
- var bestd;
560
- var p;
561
- var best;
553
+ let i;
554
+ let j;
555
+ let dist;
556
+ let a;
557
+ let bestd;
558
+ let p;
559
+ let best;
562
560
  bestd = 1000;
563
561
  best = -1;
564
562
  i = netindex[g];
@@ -630,8 +628,8 @@ function NeuQuant() {
630
628
  return colorMap();
631
629
  }
632
630
  function unbiasnet() {
633
- var i;
634
- var j;
631
+ let i;
632
+ let j;
635
633
  for (i = 0; i < netsize; i++) {
636
634
  network[i][0] >>= netbiasshift;
637
635
  network[i][1] >>= netbiasshift;
@@ -640,13 +638,13 @@ function NeuQuant() {
640
638
  }
641
639
  }
642
640
  function alterneigh(rad, i, b, g, r) {
643
- var j;
644
- var k;
645
- var lo;
646
- var hi;
647
- var a;
648
- var m;
649
- var p;
641
+ let j;
642
+ let k;
643
+ let lo;
644
+ let hi;
645
+ let a;
646
+ let m;
647
+ let p;
650
648
  lo = i - rad;
651
649
  if (lo < -1) {
652
650
  lo = -1;
@@ -679,23 +677,23 @@ function NeuQuant() {
679
677
  }
680
678
  }
681
679
  function altersingle(alpha, i, b, g, r) {
682
- var n = network[i];
683
- var alphaMult = alpha / initalpha;
680
+ const n = network[i];
681
+ const alphaMult = alpha / initalpha;
684
682
  n[0] -= alphaMult * (n[0] - b) | 0;
685
683
  n[1] -= alphaMult * (n[1] - g) | 0;
686
684
  n[2] -= alphaMult * (n[2] - r) | 0;
687
685
  }
688
686
  function contest(b, g, r) {
689
- var i;
690
- var dist;
691
- var a;
692
- var biasdist;
693
- var betafreq;
694
- var bestpos;
695
- var bestbiaspos;
696
- var bestd;
697
- var bestbiasd;
698
- var n;
687
+ let i;
688
+ let dist;
689
+ let a;
690
+ let biasdist;
691
+ let betafreq;
692
+ let bestpos;
693
+ let bestbiaspos;
694
+ let bestd;
695
+ let bestbiasd;
696
+ let n;
699
697
  bestd = ~(1 << 31);
700
698
  bestbiasd = bestd;
701
699
  bestpos = -1;
@@ -734,17 +732,17 @@ function NeuQuant() {
734
732
  return bestbiaspos;
735
733
  }
736
734
  NeuQuantConstructor.apply(this, arguments);
737
- var exports = {};
735
+ const exports = {};
738
736
  exports.map = map;
739
737
  exports.process = process;
740
738
  return exports;
741
739
  }
742
740
  function workerCode() {
743
- var self = this;
741
+ const self = this;
744
742
  try {
745
743
  globalThis.onmessage = function (ev) {
746
- var data = ev.data || {};
747
- var response;
744
+ const data = ev.data || {};
745
+ let response;
748
746
  if (data.gifshot) {
749
747
  response = workerMethods.run(data);
750
748
  postMessage(response);
@@ -753,9 +751,9 @@ function workerCode() {
753
751
  } catch (e) {}
754
752
  var workerMethods = {
755
753
  dataToRGB: function dataToRGB(data, width, height) {
756
- var length = width * height * 4;
757
- var i = 0;
758
- var rgb = [];
754
+ const length = width * height * 4;
755
+ let i = 0;
756
+ const rgb = [];
759
757
  while (i < length) {
760
758
  rgb.push(data[i++]);
761
759
  rgb.push(data[i++]);
@@ -766,27 +764,27 @@ function workerCode() {
766
764
  },
767
765
  componentizedPaletteToArray: function componentizedPaletteToArray(paletteRGB) {
768
766
  paletteRGB = paletteRGB || [];
769
- var paletteArray = [];
770
- for (var i = 0; i < paletteRGB.length; i += 3) {
771
- var r = paletteRGB[i];
772
- var g = paletteRGB[i + 1];
773
- var b = paletteRGB[i + 2];
767
+ const paletteArray = [];
768
+ for (let i = 0; i < paletteRGB.length; i += 3) {
769
+ const r = paletteRGB[i];
770
+ const g = paletteRGB[i + 1];
771
+ const b = paletteRGB[i + 2];
774
772
  paletteArray.push(r << 16 | g << 8 | b);
775
773
  }
776
774
  return paletteArray;
777
775
  },
778
776
  processFrameWithQuantizer: function processFrameWithQuantizer(imageData, width, height, sampleInterval) {
779
- var rgbComponents = this.dataToRGB(imageData, width, height);
780
- var nq = new NeuQuant(rgbComponents, rgbComponents.length, sampleInterval);
781
- var paletteRGB = nq.process();
782
- var paletteArray = new Uint32Array(this.componentizedPaletteToArray(paletteRGB));
783
- var numberPixels = width * height;
784
- var indexedPixels = new Uint8Array(numberPixels);
785
- var k = 0;
786
- for (var i = 0; i < numberPixels; i++) {
787
- var r = rgbComponents[k++];
788
- var g = rgbComponents[k++];
789
- var b = rgbComponents[k++];
777
+ const rgbComponents = this.dataToRGB(imageData, width, height);
778
+ const nq = new NeuQuant(rgbComponents, rgbComponents.length, sampleInterval);
779
+ const paletteRGB = nq.process();
780
+ const paletteArray = new Uint32Array(this.componentizedPaletteToArray(paletteRGB));
781
+ const numberPixels = width * height;
782
+ const indexedPixels = new Uint8Array(numberPixels);
783
+ let k = 0;
784
+ for (let i = 0; i < numberPixels; i++) {
785
+ const r = rgbComponents[k++];
786
+ const g = rgbComponents[k++];
787
+ const b = rgbComponents[k++];
790
788
  indexedPixels[i] = nq.map(r, g, b);
791
789
  }
792
790
  return {
@@ -796,25 +794,25 @@ function workerCode() {
796
794
  },
797
795
  run: function run(frame) {
798
796
  frame = frame || {};
799
- var _frame = frame;
800
- var height = _frame.height;
801
- var palette = _frame.palette;
802
- var sampleInterval = _frame.sampleInterval;
803
- var width = _frame.width;
804
- var imageData = frame.data;
797
+ const _frame = frame;
798
+ const height = _frame.height;
799
+ const palette = _frame.palette;
800
+ const sampleInterval = _frame.sampleInterval;
801
+ const width = _frame.width;
802
+ const imageData = frame.data;
805
803
  return this.processFrameWithQuantizer(imageData, width, height, sampleInterval);
806
804
  }
807
805
  };
808
806
  return workerMethods;
809
807
  }
810
808
  function gifWriter(buf, width, height, gopts) {
811
- var p = 0;
809
+ let p = 0;
812
810
  gopts = gopts === undefined ? {} : gopts;
813
- var loop_count = gopts.loop === undefined ? null : gopts.loop;
814
- var global_palette = gopts.palette === undefined ? null : gopts.palette;
811
+ const loop_count = gopts.loop === undefined ? null : gopts.loop;
812
+ const global_palette = gopts.palette === undefined ? null : gopts.palette;
815
813
  if (width <= 0 || height <= 0 || width > 65535 || height > 65535) throw 'Width/Height invalid.';
816
814
  function check_palette_and_num_colors(palette) {
817
- var num_colors = palette.length;
815
+ const num_colors = palette.length;
818
816
  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.';
819
817
  return num_colors;
820
818
  }
@@ -824,8 +822,8 @@ function gifWriter(buf, width, height, gopts) {
824
822
  buf[p++] = 0x38;
825
823
  buf[p++] = 0x39;
826
824
  buf[p++] = 0x61;
827
- var gp_num_colors_pow2 = 0;
828
- var background = 0;
825
+ const gp_num_colors_pow2 = 0;
826
+ const background = 0;
829
827
  buf[p++] = width & 0xff;
830
828
  buf[p++] = width >> 8 & 0xff;
831
829
  buf[p++] = height & 0xff;
@@ -855,7 +853,7 @@ function gifWriter(buf, width, height, gopts) {
855
853
  buf[p++] = loop_count >> 8 & 0xff;
856
854
  buf[p++] = 0x00;
857
855
  }
858
- var ended = false;
856
+ let ended = false;
859
857
  this.addFrame = function (x, y, w, h, indexed_pixels, opts) {
860
858
  if (ended === true) {
861
859
  --p;
@@ -865,24 +863,24 @@ function gifWriter(buf, width, height, gopts) {
865
863
  if (x < 0 || y < 0 || x > 65535 || y > 65535) throw 'x/y invalid.';
866
864
  if (w <= 0 || h <= 0 || w > 65535 || h > 65535) throw 'Width/Height invalid.';
867
865
  if (indexed_pixels.length < w * h) throw 'Not enough pixels for the frame size.';
868
- var using_local_palette = true;
869
- var palette = opts.palette;
866
+ let using_local_palette = true;
867
+ let palette = opts.palette;
870
868
  if (palette === undefined || palette === null) {
871
869
  using_local_palette = false;
872
870
  palette = global_palette;
873
871
  }
874
872
  if (palette === undefined || palette === null) throw 'Must supply either a local or global palette.';
875
- var num_colors = check_palette_and_num_colors(palette);
876
- var min_code_size = 0;
873
+ let num_colors = check_palette_and_num_colors(palette);
874
+ let min_code_size = 0;
877
875
  while (num_colors >>= 1) {
878
876
  ++min_code_size;
879
877
  }
880
878
  num_colors = 1 << min_code_size;
881
- var delay = opts.delay === undefined ? 0 : opts.delay;
882
- var disposal = opts.disposal === undefined ? 0 : opts.disposal;
879
+ const delay = opts.delay === undefined ? 0 : opts.delay;
880
+ const disposal = opts.disposal === undefined ? 0 : opts.disposal;
883
881
  if (disposal < 0 || disposal > 3) throw 'Disposal out of range.';
884
- var use_transparency = false;
885
- var transparent_index = 0;
882
+ let use_transparency = false;
883
+ let transparent_index = 0;
886
884
  if (opts.transparent !== undefined && opts.transparent !== null) {
887
885
  use_transparency = true;
888
886
  transparent_index = opts.transparent;
@@ -909,8 +907,8 @@ function gifWriter(buf, width, height, gopts) {
909
907
  buf[p++] = h >> 8 & 0xff;
910
908
  buf[p++] = using_local_palette === true ? 0x80 | min_code_size - 1 : 0;
911
909
  if (using_local_palette === true) {
912
- for (var i = 0, il = palette.length; i < il; ++i) {
913
- var rgb = palette[i];
910
+ for (let i = 0, il = palette.length; i < il; ++i) {
911
+ const rgb = palette[i];
914
912
  buf[p++] = rgb >> 16 & 0xff;
915
913
  buf[p++] = rgb >> 8 & 0xff;
916
914
  buf[p++] = rgb & 0xff;
@@ -927,14 +925,14 @@ function gifWriter(buf, width, height, gopts) {
927
925
  };
928
926
  function GifWriterOutputLZWCodeStream(buf, p, min_code_size, index_stream) {
929
927
  buf[p++] = min_code_size;
930
- var cur_subblock = p++;
931
- var clear_code = 1 << min_code_size;
932
- var code_mask = clear_code - 1;
933
- var eoi_code = clear_code + 1;
934
- var next_code = eoi_code + 1;
935
- var cur_code_size = min_code_size + 1;
936
- var cur_shift = 0;
937
- var cur = 0;
928
+ let cur_subblock = p++;
929
+ const clear_code = 1 << min_code_size;
930
+ const code_mask = clear_code - 1;
931
+ const eoi_code = clear_code + 1;
932
+ let next_code = eoi_code + 1;
933
+ let cur_code_size = min_code_size + 1;
934
+ let cur_shift = 0;
935
+ let cur = 0;
938
936
  function emit_bytes_to_buffer(bit_block_size) {
939
937
  while (cur_shift >= bit_block_size) {
940
938
  buf[p++] = cur & 0xff;
@@ -951,13 +949,13 @@ function gifWriter(buf, width, height, gopts) {
951
949
  cur_shift += cur_code_size;
952
950
  emit_bytes_to_buffer(8);
953
951
  }
954
- var ib_code = index_stream[0] & code_mask;
955
- var code_table = {};
952
+ let ib_code = index_stream[0] & code_mask;
953
+ let code_table = {};
956
954
  emit_code(clear_code);
957
- for (var i = 1, il = index_stream.length; i < il; ++i) {
958
- var k = index_stream[i] & code_mask;
959
- var cur_key = ib_code << 8 | k;
960
- var cur_code = code_table[cur_key];
955
+ for (let i = 1, il = index_stream.length; i < il; ++i) {
956
+ const k = index_stream[i] & code_mask;
957
+ const cur_key = ib_code << 8 | k;
958
+ const cur_code = code_table[cur_key];
961
959
  if (cur_code === undefined) {
962
960
  cur |= ib_code << cur_shift;
963
961
  cur_shift += cur_code_size;
@@ -996,8 +994,8 @@ function gifWriter(buf, width, height, gopts) {
996
994
  return p;
997
995
  }
998
996
  }
999
- var noop$2 = function noop() {};
1000
- var AnimatedGIF = function AnimatedGIF(options) {
997
+ const noop$2 = function noop() {};
998
+ const AnimatedGIF = function AnimatedGIF(options) {
1001
999
  this.canvas = null;
1002
1000
  this.ctx = null;
1003
1001
  this.repeat = 0;
@@ -1014,14 +1012,14 @@ var AnimatedGIF = function AnimatedGIF(options) {
1014
1012
  AnimatedGIF.prototype = {
1015
1013
  workerMethods: workerCode(),
1016
1014
  initializeWebWorkers: function initializeWebWorkers(options) {
1017
- var self = this;
1018
- var processFrameWorkerCode = "".concat(NeuQuant.toString(), "(").concat(workerCode.toString(), "());");
1019
- var webWorkerObj = void 0;
1020
- var objectUrl = void 0;
1021
- var webWorker = void 0;
1022
- var numWorkers = void 0;
1023
- var x = -1;
1024
- var workerError = '';
1015
+ const self = this;
1016
+ const processFrameWorkerCode = "".concat(NeuQuant.toString(), "(").concat(workerCode.toString(), "());");
1017
+ let webWorkerObj = void 0;
1018
+ let objectUrl = void 0;
1019
+ let webWorker = void 0;
1020
+ let numWorkers = void 0;
1021
+ let x = -1;
1022
+ let workerError = '';
1025
1023
  numWorkers = options.numWorkers;
1026
1024
  while (++x < numWorkers) {
1027
1025
  webWorkerObj = utils.createWebWorker(processFrameWorkerCode);
@@ -1030,7 +1028,7 @@ AnimatedGIF.prototype = {
1030
1028
  webWorker = webWorkerObj.worker;
1031
1029
  self.workers.push({
1032
1030
  worker: webWorker,
1033
- objectUrl: objectUrl
1031
+ objectUrl
1034
1032
  });
1035
1033
  self.availableWorkers.push(webWorker);
1036
1034
  } else {
@@ -1052,27 +1050,27 @@ AnimatedGIF.prototype = {
1052
1050
  this.availableWorkers.push(worker);
1053
1051
  },
1054
1052
  byteMap: function () {
1055
- var byteMap = [];
1056
- for (var i = 0; i < 256; i++) {
1053
+ const byteMap = [];
1054
+ for (let i = 0; i < 256; i++) {
1057
1055
  byteMap[i] = String.fromCharCode(i);
1058
1056
  }
1059
1057
  return byteMap;
1060
1058
  }(),
1061
1059
  bufferToString: function bufferToString(buffer) {
1062
- var numberValues = buffer.length;
1063
- var str = '';
1064
- var x = -1;
1060
+ const numberValues = buffer.length;
1061
+ let str = '';
1062
+ let x = -1;
1065
1063
  while (++x < numberValues) {
1066
1064
  str += this.byteMap[buffer[x]];
1067
1065
  }
1068
1066
  return str;
1069
1067
  },
1070
1068
  onFrameFinished: function onFrameFinished(progressCallback) {
1071
- var self = this;
1072
- var frames = self.frames;
1073
- var options = self.options;
1074
- var hasExistingImages = Boolean((options.images || []).length);
1075
- var allDone = frames.every(function (frame) {
1069
+ const self = this;
1070
+ const frames = self.frames;
1071
+ const options = self.options;
1072
+ const hasExistingImages = Boolean((options.images || []).length);
1073
+ const allDone = frames.every(function (frame) {
1076
1074
  return !frame.beingProcessed && frame.done;
1077
1075
  });
1078
1076
  self.numRenderedFrames++;
@@ -1091,17 +1089,17 @@ AnimatedGIF.prototype = {
1091
1089
  }
1092
1090
  },
1093
1091
  processFrame: function processFrame(position) {
1094
- var AnimatedGifContext = this;
1095
- var options = this.options;
1096
- var _options = this.options;
1097
- var progressCallback = _options.progressCallback;
1098
- var sampleInterval = _options.sampleInterval;
1099
- var frames = this.frames;
1100
- var frame = void 0;
1101
- var worker = void 0;
1102
- var done = function done() {
1103
- var ev = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1104
- var data = ev.data;
1092
+ const AnimatedGifContext = this;
1093
+ const options = this.options;
1094
+ const _options = this.options;
1095
+ const progressCallback = _options.progressCallback;
1096
+ const sampleInterval = _options.sampleInterval;
1097
+ const frames = this.frames;
1098
+ let frame = void 0;
1099
+ let worker = void 0;
1100
+ const done = function done() {
1101
+ const ev = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1102
+ const data = ev.data;
1105
1103
  delete frame.data;
1106
1104
  frame.pixels = Array.prototype.slice.call(data.pixels);
1107
1105
  frame.palette = Array.prototype.slice.call(data.palette);
@@ -1130,14 +1128,14 @@ AnimatedGIF.prototype = {
1130
1128
  },
1131
1129
  startRendering: function startRendering(completeCallback) {
1132
1130
  this.onRenderCompleteCallback = completeCallback;
1133
- for (var i = 0; i < this.options.numWorkers && i < this.frames.length; i++) {
1131
+ for (let i = 0; i < this.options.numWorkers && i < this.frames.length; i++) {
1134
1132
  this.processFrame(i);
1135
1133
  }
1136
1134
  },
1137
1135
  processNextFrame: function processNextFrame() {
1138
- var position = -1;
1139
- for (var i = 0; i < this.frames.length; i++) {
1140
- var frame = this.frames[i];
1136
+ let position = -1;
1137
+ for (let i = 0; i < this.frames.length; i++) {
1138
+ const frame = this.frames[i];
1141
1139
  if (!frame.done && !frame.beingProcessed) {
1142
1140
  position = i;
1143
1141
  break;
@@ -1148,30 +1146,30 @@ AnimatedGIF.prototype = {
1148
1146
  }
1149
1147
  },
1150
1148
  generateGIF: function generateGIF(frames, callback) {
1151
- var buffer = [];
1152
- var gifOptions = {
1149
+ const buffer = [];
1150
+ const gifOptions = {
1153
1151
  loop: this.repeat
1154
1152
  };
1155
- var options = this.options;
1156
- var interval = options.interval;
1157
- var frameDuration = options.frameDuration;
1158
- var existingImages = options.images;
1159
- var hasExistingImages = Boolean(existingImages.length);
1160
- var height = options.gifHeight;
1161
- var width = options.gifWidth;
1162
- var gifWriter$$1 = new gifWriter(buffer, width, height, gifOptions);
1163
- var onRenderProgressCallback = this.onRenderProgressCallback;
1164
- var delay = hasExistingImages ? interval * 100 : 0;
1165
- var bufferToString = void 0;
1166
- var gif = void 0;
1153
+ const options = this.options;
1154
+ const interval = options.interval;
1155
+ const frameDuration = options.frameDuration;
1156
+ const existingImages = options.images;
1157
+ const hasExistingImages = Boolean(existingImages.length);
1158
+ const height = options.gifHeight;
1159
+ const width = options.gifWidth;
1160
+ const gifWriter$$1 = new gifWriter(buffer, width, height, gifOptions);
1161
+ const onRenderProgressCallback = this.onRenderProgressCallback;
1162
+ const delay = hasExistingImages ? interval * 100 : 0;
1163
+ let bufferToString = void 0;
1164
+ let gif = void 0;
1167
1165
  this.generatingGIF = true;
1168
1166
  utils.each(frames, function (iterator, frame) {
1169
- var framePalette = frame.palette;
1167
+ const framePalette = frame.palette;
1170
1168
  onRenderProgressCallback(0.75 + 0.25 * frame.position * 1.0 / frames.length);
1171
- for (var i = 0; i < frameDuration; i++) {
1169
+ for (let i = 0; i < frameDuration; i++) {
1172
1170
  gifWriter$$1.addFrame(0, 0, width, height, frame.pixels, {
1173
1171
  palette: framePalette,
1174
- delay: delay
1172
+ delay
1175
1173
  });
1176
1174
  }
1177
1175
  });
@@ -1190,26 +1188,26 @@ AnimatedGIF.prototype = {
1190
1188
  },
1191
1189
  addFrame: function addFrame(element, gifshotOptions) {
1192
1190
  gifshotOptions = utils.isObject(gifshotOptions) ? gifshotOptions : {};
1193
- var self = this;
1194
- var ctx = self.ctx;
1195
- var options = self.options;
1196
- var width = options.gifWidth;
1197
- var height = options.gifHeight;
1198
- var fontSize = utils.getFontSize(gifshotOptions);
1199
- var _gifshotOptions = gifshotOptions;
1200
- var filter = _gifshotOptions.filter;
1201
- var fontColor = _gifshotOptions.fontColor;
1202
- var fontFamily = _gifshotOptions.fontFamily;
1203
- var fontWeight = _gifshotOptions.fontWeight;
1204
- var gifHeight = _gifshotOptions.gifHeight;
1205
- var gifWidth = _gifshotOptions.gifWidth;
1206
- var text = _gifshotOptions.text;
1207
- var textAlign = _gifshotOptions.textAlign;
1208
- var textBaseline = _gifshotOptions.textBaseline;
1209
- var textXCoordinate = gifshotOptions.textXCoordinate ? gifshotOptions.textXCoordinate : textAlign === 'left' ? 1 : textAlign === 'right' ? width : width / 2;
1210
- var textYCoordinate = gifshotOptions.textYCoordinate ? gifshotOptions.textYCoordinate : textBaseline === 'top' ? 1 : textBaseline === 'center' ? height / 2 : height;
1211
- var font = "".concat(fontWeight, " ").concat(fontSize, " ").concat(fontFamily);
1212
- var imageData = void 0;
1191
+ const self = this;
1192
+ const ctx = self.ctx;
1193
+ const options = self.options;
1194
+ const width = options.gifWidth;
1195
+ const height = options.gifHeight;
1196
+ const fontSize = utils.getFontSize(gifshotOptions);
1197
+ const _gifshotOptions = gifshotOptions;
1198
+ const filter = _gifshotOptions.filter;
1199
+ const fontColor = _gifshotOptions.fontColor;
1200
+ const fontFamily = _gifshotOptions.fontFamily;
1201
+ const fontWeight = _gifshotOptions.fontWeight;
1202
+ const gifHeight = _gifshotOptions.gifHeight;
1203
+ const gifWidth = _gifshotOptions.gifWidth;
1204
+ const text = _gifshotOptions.text;
1205
+ const textAlign = _gifshotOptions.textAlign;
1206
+ const textBaseline = _gifshotOptions.textBaseline;
1207
+ const textXCoordinate = gifshotOptions.textXCoordinate ? gifshotOptions.textXCoordinate : textAlign === 'left' ? 1 : textAlign === 'right' ? width : width / 2;
1208
+ const textYCoordinate = gifshotOptions.textYCoordinate ? gifshotOptions.textYCoordinate : textBaseline === 'top' ? 1 : textBaseline === 'center' ? height / 2 : height;
1209
+ const font = "".concat(fontWeight, " ").concat(fontSize, " ").concat(fontFamily);
1210
+ let imageData = void 0;
1213
1211
  try {
1214
1212
  ctx.filter = filter;
1215
1213
  ctx.drawImage(element, 0, 0, width, height);
@@ -1227,9 +1225,9 @@ AnimatedGIF.prototype = {
1227
1225
  }
1228
1226
  },
1229
1227
  addFrameImageData: function addFrameImageData() {
1230
- var imageData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1231
- var frames = this.frames;
1232
- var imageDataArray = imageData.data;
1228
+ const imageData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1229
+ const frames = this.frames;
1230
+ const imageDataArray = imageData.data;
1233
1231
  this.frames.push({
1234
1232
  data: imageDataArray,
1235
1233
  width: imageData.width,
@@ -1248,8 +1246,8 @@ AnimatedGIF.prototype = {
1248
1246
  return this.generatingGIF;
1249
1247
  },
1250
1248
  getBase64GIF: function getBase64GIF(completeCallback) {
1251
- var self = this;
1252
- var onRenderComplete = function onRenderComplete(gif) {
1249
+ const self = this;
1250
+ const onRenderComplete = function onRenderComplete(gif) {
1253
1251
  self.destroyWorkers();
1254
1252
  utils.requestTimeout(function () {
1255
1253
  completeCallback(gif);
@@ -1261,10 +1259,10 @@ AnimatedGIF.prototype = {
1261
1259
  if (this.workerError) {
1262
1260
  return;
1263
1261
  }
1264
- var workers = this.workers;
1262
+ const workers = this.workers;
1265
1263
  utils.each(workers, function (iterator, workerObj) {
1266
- var worker = workerObj.worker;
1267
- var objectUrl = workerObj.objectUrl;
1264
+ const worker = workerObj.worker;
1265
+ const objectUrl = workerObj.objectUrl;
1268
1266
  worker.terminate();
1269
1267
  utils.URL.revokeObjectURL(objectUrl);
1270
1268
  });
@@ -1276,32 +1274,32 @@ function getBase64GIF(animatedGifInstance, callback) {
1276
1274
  error: false,
1277
1275
  errorCode: '',
1278
1276
  errorMsg: '',
1279
- image: image
1277
+ image
1280
1278
  });
1281
1279
  });
1282
1280
  }
1283
1281
  function existingImages() {
1284
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1285
- var self = this;
1286
- var callback = obj.callback;
1287
- var images = obj.images;
1288
- var options = obj.options;
1289
- var imagesLength = obj.imagesLength;
1290
- var skipObj = {
1282
+ const obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1283
+ const self = this;
1284
+ const callback = obj.callback;
1285
+ const images = obj.images;
1286
+ const options = obj.options;
1287
+ let imagesLength = obj.imagesLength;
1288
+ const skipObj = {
1291
1289
  getUserMedia: true,
1292
1290
  'globalThis.URL': true
1293
1291
  };
1294
- var errorObj = error.validate(skipObj);
1295
- var loadedImages = [];
1296
- var loadedImagesLength = 0;
1297
- var tempImage = void 0;
1298
- var ag = void 0;
1292
+ const errorObj = error.validate(skipObj);
1293
+ const loadedImages = [];
1294
+ let loadedImagesLength = 0;
1295
+ let tempImage = void 0;
1296
+ let ag = void 0;
1299
1297
  if (errorObj.error) {
1300
1298
  return callback(errorObj);
1301
1299
  }
1302
1300
  ag = new AnimatedGIF(options);
1303
1301
  utils.each(images, function (index, image) {
1304
- var currentImage = image;
1302
+ const currentImage = image;
1305
1303
  if (utils.isElement(currentImage)) {
1306
1304
  if (options.crossOrigin) {
1307
1305
  currentImage.crossOrigin = options.crossOrigin;
@@ -1321,7 +1319,7 @@ function existingImages() {
1321
1319
  tempImage.text = image.text;
1322
1320
  }
1323
1321
  tempImage.onerror = function (e) {
1324
- var obj = void 0;
1322
+ let obj = void 0;
1325
1323
  --imagesLength;
1326
1324
  if (imagesLength === 0) {
1327
1325
  obj = {};
@@ -1366,53 +1364,53 @@ function existingImages() {
1366
1364
  getBase64GIF(ag, callback);
1367
1365
  }
1368
1366
  }
1369
- var noop$3 = function noop() {};
1370
- var screenShot = {
1367
+ const noop$3 = function noop() {};
1368
+ const screenShot = {
1371
1369
  getGIF: function getGIF() {
1372
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1373
- var callback = arguments[1];
1370
+ const options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1371
+ let callback = arguments[1];
1374
1372
  callback = utils.isFunction(callback) ? callback : noop$3;
1375
- var canvas = document.createElement('canvas');
1376
- var context = void 0;
1377
- var existingImages = options.images;
1378
- var hasExistingImages = Boolean(existingImages.length);
1379
- var cameraStream = options.cameraStream;
1380
- var crop = options.crop;
1381
- var filter = options.filter;
1382
- var fontColor = options.fontColor;
1383
- var fontFamily = options.fontFamily;
1384
- var fontWeight = options.fontWeight;
1385
- var keepCameraOn = options.keepCameraOn;
1386
- var numWorkers = options.numWorkers;
1387
- var progressCallback = options.progressCallback;
1388
- var saveRenderingContexts = options.saveRenderingContexts;
1389
- var savedRenderingContexts = options.savedRenderingContexts;
1390
- var text = options.text;
1391
- var textAlign = options.textAlign;
1392
- var textBaseline = options.textBaseline;
1393
- var videoElement = options.videoElement;
1394
- var videoHeight = options.videoHeight;
1395
- var videoWidth = options.videoWidth;
1396
- var webcamVideoElement = options.webcamVideoElement;
1397
- var gifWidth = Number(options.gifWidth);
1398
- var gifHeight = Number(options.gifHeight);
1399
- var interval = Number(options.interval);
1400
- var sampleInterval = Number(options.sampleInterval);
1401
- var waitBetweenFrames = hasExistingImages ? 0 : interval * 1000;
1402
- var renderingContextsToSave = [];
1403
- var numFrames = savedRenderingContexts.length ? savedRenderingContexts.length : options.numFrames;
1404
- var pendingFrames = numFrames;
1405
- var ag = new AnimatedGIF(options);
1406
- var fontSize = utils.getFontSize(options);
1407
- var textXCoordinate = options.textXCoordinate ? options.textXCoordinate : textAlign === 'left' ? 1 : textAlign === 'right' ? gifWidth : gifWidth / 2;
1408
- var textYCoordinate = options.textYCoordinate ? options.textYCoordinate : textBaseline === 'top' ? 1 : textBaseline === 'center' ? gifHeight / 2 : gifHeight;
1409
- var font = "".concat(fontWeight, " ").concat(fontSize, " ").concat(fontFamily);
1410
- var sourceX = crop ? Math.floor(crop.scaledWidth / 2) : 0;
1411
- var sourceWidth = crop ? videoWidth - crop.scaledWidth : 0;
1412
- var sourceY = crop ? Math.floor(crop.scaledHeight / 2) : 0;
1413
- var sourceHeight = crop ? videoHeight - crop.scaledHeight : 0;
1414
- var captureFrames = function captureSingleFrame() {
1415
- var framesLeft = pendingFrames - 1;
1373
+ const canvas = document.createElement('canvas');
1374
+ let context = void 0;
1375
+ const existingImages = options.images;
1376
+ const hasExistingImages = Boolean(existingImages.length);
1377
+ const cameraStream = options.cameraStream;
1378
+ const crop = options.crop;
1379
+ const filter = options.filter;
1380
+ const fontColor = options.fontColor;
1381
+ const fontFamily = options.fontFamily;
1382
+ const fontWeight = options.fontWeight;
1383
+ const keepCameraOn = options.keepCameraOn;
1384
+ const numWorkers = options.numWorkers;
1385
+ const progressCallback = options.progressCallback;
1386
+ const saveRenderingContexts = options.saveRenderingContexts;
1387
+ const savedRenderingContexts = options.savedRenderingContexts;
1388
+ const text = options.text;
1389
+ const textAlign = options.textAlign;
1390
+ const textBaseline = options.textBaseline;
1391
+ const videoElement = options.videoElement;
1392
+ const videoHeight = options.videoHeight;
1393
+ const videoWidth = options.videoWidth;
1394
+ const webcamVideoElement = options.webcamVideoElement;
1395
+ const gifWidth = Number(options.gifWidth);
1396
+ const gifHeight = Number(options.gifHeight);
1397
+ let interval = Number(options.interval);
1398
+ const sampleInterval = Number(options.sampleInterval);
1399
+ const waitBetweenFrames = hasExistingImages ? 0 : interval * 1000;
1400
+ const renderingContextsToSave = [];
1401
+ let numFrames = savedRenderingContexts.length ? savedRenderingContexts.length : options.numFrames;
1402
+ let pendingFrames = numFrames;
1403
+ const ag = new AnimatedGIF(options);
1404
+ const fontSize = utils.getFontSize(options);
1405
+ const textXCoordinate = options.textXCoordinate ? options.textXCoordinate : textAlign === 'left' ? 1 : textAlign === 'right' ? gifWidth : gifWidth / 2;
1406
+ const textYCoordinate = options.textYCoordinate ? options.textYCoordinate : textBaseline === 'top' ? 1 : textBaseline === 'center' ? gifHeight / 2 : gifHeight;
1407
+ const font = "".concat(fontWeight, " ").concat(fontSize, " ").concat(fontFamily);
1408
+ let sourceX = crop ? Math.floor(crop.scaledWidth / 2) : 0;
1409
+ let sourceWidth = crop ? videoWidth - crop.scaledWidth : 0;
1410
+ let sourceY = crop ? Math.floor(crop.scaledHeight / 2) : 0;
1411
+ let sourceHeight = crop ? videoHeight - crop.scaledHeight : 0;
1412
+ const captureFrames = function captureSingleFrame() {
1413
+ const framesLeft = pendingFrames - 1;
1416
1414
  if (savedRenderingContexts.length) {
1417
1415
  context.putImageData(savedRenderingContexts[numFrames - pendingFrames], 0, 0);
1418
1416
  finishCapture();
@@ -1445,7 +1443,7 @@ var screenShot = {
1445
1443
  }
1446
1444
  }
1447
1445
  function finishCapture() {
1448
- var imageData = void 0;
1446
+ let imageData = void 0;
1449
1447
  if (saveRenderingContexts) {
1450
1448
  renderingContextsToSave.push(context.getImageData(0, 0, gifWidth, gifHeight));
1451
1449
  }
@@ -1469,12 +1467,12 @@ var screenShot = {
1469
1467
  error: false,
1470
1468
  errorCode: '',
1471
1469
  errorMsg: '',
1472
- image: image,
1473
- cameraStream: cameraStream,
1474
- videoElement: videoElement,
1475
- webcamVideoElement: webcamVideoElement,
1470
+ image,
1471
+ cameraStream,
1472
+ videoElement,
1473
+ webcamVideoElement,
1476
1474
  savedRenderingContexts: renderingContextsToSave,
1477
- keepCameraOn: keepCameraOn
1475
+ keepCameraOn
1478
1476
  });
1479
1477
  });
1480
1478
  }
@@ -1494,12 +1492,12 @@ var screenShot = {
1494
1492
  })();
1495
1493
  },
1496
1494
  getCropDimensions: function getCropDimensions() {
1497
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1498
- var width = obj.videoWidth;
1499
- var height = obj.videoHeight;
1500
- var gifWidth = obj.gifWidth;
1501
- var gifHeight = obj.gifHeight;
1502
- var result = {
1495
+ const obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1496
+ const width = obj.videoWidth;
1497
+ const height = obj.videoHeight;
1498
+ const gifWidth = obj.gifWidth;
1499
+ const gifHeight = obj.gifHeight;
1500
+ const result = {
1503
1501
  width: 0,
1504
1502
  height: 0,
1505
1503
  scaledWidth: 0,
@@ -1523,17 +1521,17 @@ var videoStream = {
1523
1521
  },
1524
1522
  findVideoSize: function findVideoSizeMethod(obj) {
1525
1523
  findVideoSizeMethod.attempts = findVideoSizeMethod.attempts || 0;
1526
- var cameraStream = obj.cameraStream;
1527
- var completedCallback = obj.completedCallback;
1528
- var videoElement = obj.videoElement;
1524
+ const cameraStream = obj.cameraStream;
1525
+ const completedCallback = obj.completedCallback;
1526
+ const videoElement = obj.videoElement;
1529
1527
  if (!videoElement) {
1530
1528
  return;
1531
1529
  }
1532
1530
  if (videoElement.videoWidth > 0 && videoElement.videoHeight > 0) {
1533
1531
  videoElement.removeEventListener('loadeddata', videoStream.findVideoSize);
1534
1532
  completedCallback({
1535
- videoElement: videoElement,
1536
- cameraStream: cameraStream,
1533
+ videoElement,
1534
+ cameraStream,
1537
1535
  videoWidth: videoElement.videoWidth,
1538
1536
  videoHeight: videoElement.videoHeight
1539
1537
  });
@@ -1544,8 +1542,8 @@ var videoStream = {
1544
1542
  }, 400);
1545
1543
  } else {
1546
1544
  completedCallback({
1547
- videoElement: videoElement,
1548
- cameraStream: cameraStream,
1545
+ videoElement,
1546
+ cameraStream,
1549
1547
  videoWidth: videoStream.defaultVideoDimensions.width,
1550
1548
  videoHeight: videoStream.defaultVideoDimensions.height
1551
1549
  });
@@ -1563,11 +1561,11 @@ var videoStream = {
1563
1561
  }
1564
1562
  },
1565
1563
  stream: function stream(obj) {
1566
- var existingVideo = utils.isArray(obj.existingVideo) ? obj.existingVideo[0] : obj.existingVideo;
1567
- var cameraStream = obj.cameraStream;
1568
- var completedCallback = obj.completedCallback;
1569
- var streamedCallback = obj.streamedCallback;
1570
- var videoElement = obj.videoElement;
1564
+ const existingVideo = utils.isArray(obj.existingVideo) ? obj.existingVideo[0] : obj.existingVideo;
1565
+ const cameraStream = obj.cameraStream;
1566
+ const completedCallback = obj.completedCallback;
1567
+ const streamedCallback = obj.streamedCallback;
1568
+ const videoElement = obj.videoElement;
1571
1569
  if (utils.isFunction(streamedCallback)) {
1572
1570
  streamedCallback();
1573
1571
  }
@@ -1596,18 +1594,18 @@ var videoStream = {
1596
1594
  checkLoadedData.count = checkLoadedData.count || 0;
1597
1595
  if (videoStream.loadedData === true) {
1598
1596
  videoStream.findVideoSize({
1599
- videoElement: videoElement,
1600
- cameraStream: cameraStream,
1601
- completedCallback: completedCallback
1597
+ videoElement,
1598
+ cameraStream,
1599
+ completedCallback
1602
1600
  });
1603
1601
  videoStream.loadedData = false;
1604
1602
  } else {
1605
1603
  checkLoadedData.count += 1;
1606
1604
  if (checkLoadedData.count > 10) {
1607
1605
  videoStream.findVideoSize({
1608
- videoElement: videoElement,
1609
- cameraStream: cameraStream,
1610
- completedCallback: completedCallback
1606
+ videoElement,
1607
+ cameraStream,
1608
+ completedCallback
1611
1609
  });
1612
1610
  } else {
1613
1611
  checkLoadedData();
@@ -1616,16 +1614,16 @@ var videoStream = {
1616
1614
  }, 0);
1617
1615
  },
1618
1616
  startStreaming: function startStreaming(obj) {
1619
- var errorCallback = utils.isFunction(obj.error) ? obj.error : utils.noop;
1620
- var streamedCallback = utils.isFunction(obj.streamed) ? obj.streamed : utils.noop;
1621
- var completedCallback = utils.isFunction(obj.completed) ? obj.completed : utils.noop;
1622
- var crossOrigin = obj.crossOrigin;
1623
- var existingVideo = obj.existingVideo;
1624
- var lastCameraStream = obj.lastCameraStream;
1625
- var options = obj.options;
1626
- var webcamVideoElement = obj.webcamVideoElement;
1627
- var videoElement = utils.isElement(existingVideo) ? existingVideo : webcamVideoElement ? webcamVideoElement : document.createElement('video');
1628
- var cameraStream = void 0;
1617
+ const errorCallback = utils.isFunction(obj.error) ? obj.error : utils.noop;
1618
+ const streamedCallback = utils.isFunction(obj.streamed) ? obj.streamed : utils.noop;
1619
+ const completedCallback = utils.isFunction(obj.completed) ? obj.completed : utils.noop;
1620
+ const crossOrigin = obj.crossOrigin;
1621
+ const existingVideo = obj.existingVideo;
1622
+ const lastCameraStream = obj.lastCameraStream;
1623
+ const options = obj.options;
1624
+ const webcamVideoElement = obj.webcamVideoElement;
1625
+ const videoElement = utils.isElement(existingVideo) ? existingVideo : webcamVideoElement ? webcamVideoElement : document.createElement('video');
1626
+ const cameraStream = void 0;
1629
1627
  if (crossOrigin) {
1630
1628
  videoElement.crossOrigin = options.crossOrigin;
1631
1629
  }
@@ -1640,36 +1638,36 @@ var videoStream = {
1640
1638
  });
1641
1639
  if (existingVideo) {
1642
1640
  videoStream.stream({
1643
- videoElement: videoElement,
1644
- existingVideo: existingVideo,
1645
- completedCallback: completedCallback
1641
+ videoElement,
1642
+ existingVideo,
1643
+ completedCallback
1646
1644
  });
1647
1645
  } else if (lastCameraStream) {
1648
1646
  videoStream.stream({
1649
- videoElement: videoElement,
1647
+ videoElement,
1650
1648
  cameraStream: lastCameraStream,
1651
- streamedCallback: streamedCallback,
1652
- completedCallback: completedCallback
1649
+ streamedCallback,
1650
+ completedCallback
1653
1651
  });
1654
1652
  } else {
1655
1653
  utils.getUserMedia({
1656
1654
  video: true
1657
1655
  }, function (stream) {
1658
1656
  videoStream.stream({
1659
- videoElement: videoElement,
1657
+ videoElement,
1660
1658
  cameraStream: stream,
1661
- streamedCallback: streamedCallback,
1662
- completedCallback: completedCallback
1659
+ streamedCallback,
1660
+ completedCallback
1663
1661
  });
1664
1662
  }, errorCallback);
1665
1663
  }
1666
1664
  },
1667
1665
  startVideoStreaming: function startVideoStreaming(callback) {
1668
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1669
- var timeoutLength = options.timeout !== undefined ? options.timeout : 0;
1670
- var originalCallback = options.callback;
1671
- var webcamVideoElement = options.webcamVideoElement;
1672
- var noGetUserMediaSupportTimeout = void 0;
1666
+ const options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1667
+ const timeoutLength = options.timeout !== undefined ? options.timeout : 0;
1668
+ const originalCallback = options.callback;
1669
+ const webcamVideoElement = options.webcamVideoElement;
1670
+ let noGetUserMediaSupportTimeout = void 0;
1673
1671
  if (timeoutLength > 0) {
1674
1672
  noGetUserMediaSupportTimeout = utils.requestTimeout(function () {
1675
1673
  videoStream.onStreamingTimeout(originalCallback);
@@ -1689,34 +1687,34 @@ var videoStream = {
1689
1687
  clearTimeout(noGetUserMediaSupportTimeout);
1690
1688
  },
1691
1689
  completed: function completed() {
1692
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1693
- var cameraStream = obj.cameraStream;
1694
- var videoElement = obj.videoElement;
1695
- var videoHeight = obj.videoHeight;
1696
- var videoWidth = obj.videoWidth;
1690
+ const obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1691
+ const cameraStream = obj.cameraStream;
1692
+ const videoElement = obj.videoElement;
1693
+ const videoHeight = obj.videoHeight;
1694
+ const videoWidth = obj.videoWidth;
1697
1695
  callback({
1698
- cameraStream: cameraStream,
1699
- videoElement: videoElement,
1700
- videoHeight: videoHeight,
1701
- videoWidth: videoWidth
1696
+ cameraStream,
1697
+ videoElement,
1698
+ videoHeight,
1699
+ videoWidth
1702
1700
  });
1703
1701
  },
1704
1702
  lastCameraStream: options.lastCameraStream,
1705
- webcamVideoElement: webcamVideoElement,
1703
+ webcamVideoElement,
1706
1704
  crossOrigin: options.crossOrigin,
1707
- options: options
1705
+ options
1708
1706
  });
1709
1707
  },
1710
1708
  stopVideoStreaming: function stopVideoStreaming(obj) {
1711
1709
  obj = utils.isObject(obj) ? obj : {};
1712
- var _obj = obj;
1713
- var keepCameraOn = _obj.keepCameraOn;
1714
- var videoElement = _obj.videoElement;
1715
- var webcamVideoElement = _obj.webcamVideoElement;
1716
- var cameraStream = obj.cameraStream || {};
1717
- var cameraStreamTracks = cameraStream.getTracks ? cameraStream.getTracks() || [] : [];
1718
- var hasCameraStreamTracks = Boolean(cameraStreamTracks.length);
1719
- var firstCameraStreamTrack = cameraStreamTracks[0];
1710
+ const _obj = obj;
1711
+ const keepCameraOn = _obj.keepCameraOn;
1712
+ const videoElement = _obj.videoElement;
1713
+ const webcamVideoElement = _obj.webcamVideoElement;
1714
+ const cameraStream = obj.cameraStream || {};
1715
+ const cameraStreamTracks = cameraStream.getTracks ? cameraStream.getTracks() || [] : [];
1716
+ const hasCameraStreamTracks = Boolean(cameraStreamTracks.length);
1717
+ const firstCameraStreamTrack = cameraStreamTracks[0];
1720
1718
  if (!keepCameraOn && hasCameraStreamTracks) {
1721
1719
  if (utils.isFunction(firstCameraStreamTrack.stop)) {
1722
1720
  firstCameraStreamTrack.stop();
@@ -1738,23 +1736,23 @@ function stopVideoStreaming(options) {
1738
1736
  videoStream.stopVideoStreaming(options);
1739
1737
  }
1740
1738
  function createAndGetGIF(obj, callback) {
1741
- var options = obj.options || {};
1742
- var images = options.images;
1743
- var video = options.video;
1744
- var gifWidth = Number(options.gifWidth);
1745
- var gifHeight = Number(options.gifHeight);
1746
- var numFrames = Number(options.numFrames);
1747
- var cameraStream = obj.cameraStream;
1748
- var videoElement = obj.videoElement;
1749
- var videoWidth = obj.videoWidth;
1750
- var videoHeight = obj.videoHeight;
1751
- var cropDimensions = screenShot.getCropDimensions({
1752
- videoWidth: videoWidth,
1753
- videoHeight: videoHeight,
1754
- gifHeight: gifHeight,
1755
- gifWidth: gifWidth
1739
+ const options = obj.options || {};
1740
+ const images = options.images;
1741
+ const video = options.video;
1742
+ const gifWidth = Number(options.gifWidth);
1743
+ const gifHeight = Number(options.gifHeight);
1744
+ const numFrames = Number(options.numFrames);
1745
+ const cameraStream = obj.cameraStream;
1746
+ const videoElement = obj.videoElement;
1747
+ const videoWidth = obj.videoWidth;
1748
+ const videoHeight = obj.videoHeight;
1749
+ const cropDimensions = screenShot.getCropDimensions({
1750
+ videoWidth,
1751
+ videoHeight,
1752
+ gifHeight,
1753
+ gifWidth
1756
1754
  });
1757
- var completeCallback = callback;
1755
+ const completeCallback = callback;
1758
1756
  options.crop = cropDimensions;
1759
1757
  options.videoElement = videoElement;
1760
1758
  options.videoWidth = videoWidth;
@@ -1781,20 +1779,20 @@ function createAndGetGIF(obj, callback) {
1781
1779
  });
1782
1780
  }
1783
1781
  function existingVideo() {
1784
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1785
- var callback = obj.callback;
1786
- var existingVideo = obj.existingVideo;
1787
- var options = obj.options;
1788
- var skipObj = {
1782
+ const obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1783
+ const callback = obj.callback;
1784
+ let existingVideo = obj.existingVideo;
1785
+ const options = obj.options;
1786
+ const skipObj = {
1789
1787
  getUserMedia: true,
1790
1788
  'globalThis.URL': true
1791
1789
  };
1792
- var errorObj = error.validate(skipObj);
1793
- var loadedImages = 0;
1794
- var videoType = void 0;
1795
- var videoSrc = void 0;
1796
- var tempImage = void 0;
1797
- var ag = void 0;
1790
+ const errorObj = error.validate(skipObj);
1791
+ const loadedImages = 0;
1792
+ let videoType = void 0;
1793
+ let videoSrc = void 0;
1794
+ const tempImage = void 0;
1795
+ const ag = void 0;
1798
1796
  if (errorObj.error) {
1799
1797
  return callback(errorObj);
1800
1798
  }
@@ -1822,17 +1820,17 @@ function existingVideo() {
1822
1820
  obj.options = options || {};
1823
1821
  createAndGetGIF(obj, callback);
1824
1822
  },
1825
- existingVideo: existingVideo,
1823
+ existingVideo,
1826
1824
  crossOrigin: options.crossOrigin,
1827
- options: options
1825
+ options
1828
1826
  });
1829
1827
  }
1830
1828
  function existingWebcam() {
1831
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1832
- var callback = obj.callback;
1833
- var lastCameraStream = obj.lastCameraStream;
1834
- var options = obj.options;
1835
- var webcamVideoElement = obj.webcamVideoElement;
1829
+ const obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1830
+ const callback = obj.callback;
1831
+ const lastCameraStream = obj.lastCameraStream;
1832
+ const options = obj.options;
1833
+ const webcamVideoElement = obj.webcamVideoElement;
1836
1834
  if (!isWebCamGIFSupported()) {
1837
1835
  return callback(error.validate());
1838
1836
  }
@@ -1843,13 +1841,13 @@ function existingWebcam() {
1843
1841
  return;
1844
1842
  }
1845
1843
  videoStream.startVideoStreaming(function () {
1846
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1844
+ const obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1847
1845
  obj.options = options || {};
1848
1846
  createAndGetGIF(obj, callback);
1849
1847
  }, {
1850
- lastCameraStream: lastCameraStream,
1851
- callback: callback,
1852
- webcamVideoElement: webcamVideoElement,
1848
+ lastCameraStream,
1849
+ callback,
1850
+ webcamVideoElement,
1853
1851
  crossOrigin: options.crossOrigin
1854
1852
  });
1855
1853
  }
@@ -1859,35 +1857,35 @@ function createGIF(userOptions, callback) {
1859
1857
  if (!utils.isFunction(callback)) {
1860
1858
  return;
1861
1859
  }
1862
- var options = utils.normalizeOptions(defaultOptions, userOptions) || {};
1863
- var lastCameraStream = userOptions.cameraStream;
1864
- var images = options.images;
1865
- var imagesLength = images ? images.length : 0;
1866
- var video = options.video;
1867
- var webcamVideoElement = options.webcamVideoElement;
1860
+ let options = utils.normalizeOptions(defaultOptions, userOptions) || {};
1861
+ const lastCameraStream = userOptions.cameraStream;
1862
+ const images = options.images;
1863
+ const imagesLength = images ? images.length : 0;
1864
+ const video = options.video;
1865
+ const webcamVideoElement = options.webcamVideoElement;
1868
1866
  options = utils.normalizeOptions(options, {
1869
1867
  gifWidth: Math.floor(options.gifWidth),
1870
1868
  gifHeight: Math.floor(options.gifHeight)
1871
1869
  });
1872
1870
  if (imagesLength) {
1873
1871
  existingImages({
1874
- images: images,
1875
- imagesLength: imagesLength,
1876
- callback: callback,
1877
- options: options
1872
+ images,
1873
+ imagesLength,
1874
+ callback,
1875
+ options
1878
1876
  });
1879
1877
  } else if (video) {
1880
1878
  existingVideo({
1881
1879
  existingVideo: video,
1882
- callback: callback,
1883
- options: options
1880
+ callback,
1881
+ options
1884
1882
  });
1885
1883
  } else {
1886
1884
  existingWebcam({
1887
- lastCameraStream: lastCameraStream,
1888
- callback: callback,
1889
- webcamVideoElement: webcamVideoElement,
1890
- options: options
1885
+ lastCameraStream,
1886
+ callback,
1887
+ webcamVideoElement,
1888
+ options
1891
1889
  });
1892
1890
  }
1893
1891
  }
@@ -1897,8 +1895,8 @@ function takeSnapShot(userOptions, callback) {
1897
1895
  if (!utils.isFunction(callback)) {
1898
1896
  return;
1899
1897
  }
1900
- var mergedOptions = utils.normalizeOptions(defaultOptions, userOptions);
1901
- var options = utils.normalizeOptions(mergedOptions, {
1898
+ const mergedOptions = utils.normalizeOptions(defaultOptions, userOptions);
1899
+ const options = utils.normalizeOptions(mergedOptions, {
1902
1900
  interval: 0.1,
1903
1901
  numFrames: 1,
1904
1902
  gifWidth: Math.floor(mergedOptions.gifWidth),
@@ -1906,16 +1904,16 @@ function takeSnapShot(userOptions, callback) {
1906
1904
  });
1907
1905
  createGIF(options, callback);
1908
1906
  }
1909
- var API = {
1907
+ const API = {
1910
1908
  utils: utils$2,
1911
1909
  error: error$2,
1912
1910
  defaultOptions: defaultOptions$2,
1913
- createGIF: createGIF,
1914
- takeSnapShot: takeSnapShot,
1915
- stopVideoStreaming: stopVideoStreaming,
1916
- isSupported: isSupported,
1917
- isWebCamGIFSupported: isWebCamGIFSupported,
1918
- isExistingVideoGIFSupported: isExistingVideoGIFSupported,
1911
+ createGIF,
1912
+ takeSnapShot,
1913
+ stopVideoStreaming,
1914
+ isSupported,
1915
+ isWebCamGIFSupported,
1916
+ isExistingVideoGIFSupported,
1919
1917
  isExistingImagesGIFSupported: isSupported$1,
1920
1918
  VERSION: '0.4.5'
1921
1919
  };