@loaders.gl/video 4.4.5 → 5.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +14 -3
  2. package/dist/bundled.d.ts +3 -0
  3. package/dist/bundled.d.ts.map +1 -0
  4. package/dist/bundled.js +5 -0
  5. package/dist/bundled.js.map +1 -0
  6. package/dist/dist.dev.js +154 -80
  7. package/dist/dist.min.js +1 -1
  8. package/dist/gif-builder.d.ts +1 -1
  9. package/dist/gif-builder.js +2 -2
  10. package/dist/gif-builder.js.map +1 -1
  11. package/dist/index.cjs +140 -65
  12. package/dist/index.cjs.map +3 -4
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/lib/gifshot/gifshot.d.ts.map +1 -1
  18. package/dist/lib/gifshot/gifshot.js +40 -28
  19. package/dist/lib/gifshot/gifshot.js.map +1 -1
  20. package/dist/lib/parsers/parse-video.d.ts +2 -0
  21. package/dist/lib/parsers/parse-video.d.ts.map +1 -1
  22. package/dist/lib/parsers/parse-video.js +6 -6
  23. package/dist/lib/parsers/parse-video.js.map +1 -1
  24. package/dist/unbundled.d.ts +3 -0
  25. package/dist/unbundled.d.ts.map +1 -0
  26. package/dist/unbundled.js +5 -0
  27. package/dist/unbundled.js.map +1 -0
  28. package/dist/video-format.d.ts +13 -0
  29. package/dist/video-format.d.ts.map +1 -0
  30. package/dist/video-format.js +16 -0
  31. package/dist/video-format.js.map +1 -0
  32. package/dist/video-loader-with-parser.d.ts +28 -0
  33. package/dist/video-loader-with-parser.d.ts.map +1 -0
  34. package/dist/video-loader-with-parser.js +15 -0
  35. package/dist/video-loader-with-parser.js.map +1 -0
  36. package/dist/video-loader.d.ts +31 -9
  37. package/dist/video-loader.d.ts.map +1 -1
  38. package/dist/video-loader.js +10 -11
  39. package/dist/video-loader.js.map +1 -1
  40. package/package.json +13 -5
  41. package/src/bundled.ts +6 -0
  42. package/src/gif-builder.ts +2 -2
  43. package/src/index.ts +2 -0
  44. package/src/lib/gifshot/gifshot.ts +39 -28
  45. package/src/lib/parsers/parse-video.ts +7 -6
  46. package/src/unbundled.ts +6 -0
  47. package/src/video-format.ts +18 -0
  48. package/src/video-loader-with-parser.ts +22 -0
  49. package/src/video-loader.ts +12 -12
package/dist/index.cjs CHANGED
@@ -3,6 +3,14 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __esm = (fn, res, err) => function __init() {
7
+ if (err) throw err[0];
8
+ try {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ } catch (e) {
11
+ throw err = [e], e;
12
+ }
13
+ };
6
14
  var __export = (target, all) => {
7
15
  for (var name in all)
8
16
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,39 +25,95 @@ var __copyProps = (to, from, except, desc) => {
17
25
  };
18
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
27
 
20
- // dist/index.js
21
- var dist_exports = {};
22
- __export(dist_exports, {
23
- GIFBuilder: () => GIFBuilder,
24
- VideoLoader: () => VideoLoader
28
+ // dist/video-format.js
29
+ var VideoFormat;
30
+ var init_video_format = __esm({
31
+ "dist/video-format.js"() {
32
+ "use strict";
33
+ VideoFormat = {
34
+ name: "Video",
35
+ id: "video",
36
+ module: "video",
37
+ encoding: "video",
38
+ format: "video",
39
+ extensions: ["mp4"],
40
+ mimeTypes: ["video/mp4"],
41
+ category: "video",
42
+ binary: true
43
+ };
44
+ }
25
45
  });
26
- module.exports = __toCommonJS(dist_exports);
27
46
 
28
47
  // dist/lib/parsers/parse-video.js
29
- async function parseVideo(arrayBuffer) {
30
- const blob2 = new Blob([arrayBuffer]);
48
+ async function parseVideoBlob(blob2) {
31
49
  const video = document.createElement("video");
32
50
  video.src = URL.createObjectURL(blob2);
33
51
  return video;
34
52
  }
53
+ async function parseVideo(arrayBuffer) {
54
+ return await parseVideoBlob(new Blob([arrayBuffer]));
55
+ }
56
+ var init_parse_video = __esm({
57
+ "dist/lib/parsers/parse-video.js"() {
58
+ "use strict";
59
+ }
60
+ });
61
+
62
+ // dist/video-loader-with-parser.js
63
+ var video_loader_with_parser_exports = {};
64
+ __export(video_loader_with_parser_exports, {
65
+ VideoLoaderWithParser: () => VideoLoaderWithParser
66
+ });
67
+ var _VideoLoaderPreload, VideoLoaderMetadataWithoutPreload, VideoLoaderWithParser;
68
+ var init_video_loader_with_parser = __esm({
69
+ "dist/video-loader-with-parser.js"() {
70
+ "use strict";
71
+ init_parse_video();
72
+ init_video_loader();
73
+ ({ preload: _VideoLoaderPreload, ...VideoLoaderMetadataWithoutPreload } = VideoLoader);
74
+ VideoLoaderWithParser = {
75
+ ...VideoLoaderMetadataWithoutPreload,
76
+ parse: parseVideo,
77
+ parseBlob: parseVideoBlob
78
+ };
79
+ }
80
+ });
35
81
 
36
82
  // dist/video-loader.js
37
- var VERSION = true ? "4.4.5" : "latest";
38
- var VideoLoader = {
39
- dataType: null,
40
- batchType: null,
41
- name: "Video",
42
- id: "video",
43
- module: "video",
44
- version: VERSION,
45
- extensions: ["mp4"],
46
- mimeTypes: ["video/mp4"],
47
- // tests: arrayBuffer => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer))),
48
- options: {
49
- video: {}
50
- },
51
- parse: parseVideo
52
- };
83
+ async function preload() {
84
+ const { VideoLoaderWithParser: VideoLoaderWithParser2 } = await Promise.resolve().then(() => (init_video_loader_with_parser(), video_loader_with_parser_exports));
85
+ return VideoLoaderWithParser2;
86
+ }
87
+ var VERSION, VideoLoader;
88
+ var init_video_loader = __esm({
89
+ "dist/video-loader.js"() {
90
+ "use strict";
91
+ init_video_format();
92
+ VERSION = true ? "5.0.0-alpha.2" : "latest";
93
+ VideoLoader = {
94
+ dataType: null,
95
+ batchType: null,
96
+ ...VideoFormat,
97
+ version: VERSION,
98
+ // tests: arrayBuffer => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer))),
99
+ options: {
100
+ video: {}
101
+ },
102
+ preload
103
+ };
104
+ }
105
+ });
106
+
107
+ // dist/index.js
108
+ var index_exports = {};
109
+ __export(index_exports, {
110
+ GIFBuilder: () => GIFBuilder,
111
+ VideoFormat: () => VideoFormat,
112
+ VideoLoader: () => VideoLoader
113
+ });
114
+ module.exports = __toCommonJS(index_exports);
115
+ init_video_format();
116
+ init_video_loader();
53
117
 
54
118
  // dist/lib/utils/assert.js
55
119
  function assert(condition, message) {
@@ -62,12 +126,12 @@ function assert(condition, message) {
62
126
  var document2 = globalThis.document || {};
63
127
  var utils = {
64
128
  URL: globalThis.URL || globalThis.webkitURL || globalThis.mozURL || globalThis.msURL,
65
- getUserMedia: function() {
129
+ getUserMedia: (function() {
66
130
  if (!globalThis.navigator)
67
131
  return globalThis.navigator;
68
132
  const getUserMedia = globalThis.navigator.getUserMedia || globalThis.navigator.webkitGetUserMedia || globalThis.navigator.mozGetUserMedia || globalThis.navigator.msGetUserMedia;
69
133
  return getUserMedia ? getUserMedia.bind(globalThis.navigator) : getUserMedia;
70
- }(),
134
+ })(),
71
135
  requestAnimFrame: globalThis.requestAnimationFrame || globalThis.webkitRequestAnimationFrame || globalThis.mozRequestAnimationFrame || globalThis.oRequestAnimationFrame || globalThis.msRequestAnimationFrame,
72
136
  requestTimeout: function requestTimeout(callback, delay) {
73
137
  callback = callback || utils.noop;
@@ -75,19 +139,23 @@ var utils = {
75
139
  if (!utils.requestAnimFrame) {
76
140
  return setTimeout(callback, delay);
77
141
  }
78
- const start = new Date().getTime();
142
+ const start = (/* @__PURE__ */ new Date()).getTime();
79
143
  const handle = new Object();
80
144
  const requestAnimFrame = utils.requestAnimFrame;
81
145
  const loop = function loop2() {
82
- const current = new Date().getTime();
146
+ const current = (/* @__PURE__ */ new Date()).getTime();
83
147
  const delta = current - start;
84
- delta >= delay ? callback.call() : handle.value = requestAnimFrame(loop2);
148
+ if (delta >= delay) {
149
+ callback.call();
150
+ } else {
151
+ handle.value = requestAnimFrame(loop2);
152
+ }
85
153
  };
86
154
  handle.value = requestAnimFrame(loop);
87
155
  return handle;
88
156
  },
89
157
  Blob: globalThis.Blob || globalThis.BlobBuilder || globalThis.WebKitBlobBuilder || globalThis.MozBlobBuilder || globalThis.MSBlobBuilder,
90
- btoa: function() {
158
+ btoa: (function() {
91
159
  const btoa = globalThis.btoa || function(input) {
92
160
  let output = "";
93
161
  let i = 0;
@@ -108,9 +176,9 @@ var utils = {
108
176
  enc2 = (chr1 & 3) << 4 | chr2 >> 4;
109
177
  enc3 = (chr2 & 15) << 2 | chr3 >> 6;
110
178
  enc4 = chr3 & 63;
111
- if (isNaN(chr2)) {
179
+ if (Number.isNaN(chr2)) {
112
180
  enc3 = enc4 = 64;
113
- } else if (isNaN(chr3)) {
181
+ } else if (Number.isNaN(chr3)) {
114
182
  enc4 = 64;
115
183
  }
116
184
  output = output + key.charAt(enc1) + key.charAt(enc2) + key.charAt(enc3) + key.charAt(enc4);
@@ -118,7 +186,7 @@ var utils = {
118
186
  return output;
119
187
  };
120
188
  return btoa ? btoa.bind(globalThis) : utils.noop;
121
- }(),
189
+ })(),
122
190
  isObject: function isObject(obj) {
123
191
  return obj && Object.prototype.toString.call(obj) === "[object Object]";
124
192
  },
@@ -134,6 +202,12 @@ var utils = {
134
202
  isElement: function isElement(elem) {
135
203
  return elem && elem.nodeType === 1;
136
204
  },
205
+ isImageBitmap: function isImageBitmap(image) {
206
+ return typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
207
+ },
208
+ isDrawable: function isDrawable(image) {
209
+ return utils.isElement(image) || utils.isImageBitmap(image);
210
+ },
137
211
  isString: function isString(value) {
138
212
  return typeof value === "string" || Object.prototype.toString.call(value) === "[object String]";
139
213
  },
@@ -154,7 +228,7 @@ var utils = {
154
228
  Uint32Array: function Uint32Array2() {
155
229
  return globalThis.Uint32Array;
156
230
  },
157
- videoCodecs: function() {
231
+ videoCodecs: (function() {
158
232
  const testEl = document2.createElement("video");
159
233
  const supportObj = {
160
234
  mp4: false,
@@ -171,10 +245,10 @@ var utils = {
171
245
  supportObj.ogg = testEl.canPlayType('video/ogg; codecs="theora"') !== "";
172
246
  supportObj.webm = testEl.canPlayType('video/webm; codecs="vp8, vorbis"') !== -1;
173
247
  }
174
- } catch (e) {
248
+ } catch (_e) {
175
249
  }
176
250
  return supportObj;
177
- }()
251
+ })()
178
252
  },
179
253
  noop: function noop() {
180
254
  },
@@ -437,7 +511,7 @@ function NeuQuant() {
437
511
  const intbiasshift = 16;
438
512
  const intbias = 1 << intbiasshift;
439
513
  const gammashift = 10;
440
- const gamma = 1 << gammashift;
514
+ const _gamma = 1 << gammashift;
441
515
  const betashift = 10;
442
516
  const beta = intbias >> betashift;
443
517
  const betagamma = intbias << gammashift - betashift;
@@ -514,7 +588,7 @@ function NeuQuant() {
514
588
  }
515
589
  }
516
590
  q = network[smallpos];
517
- if (i != smallpos) {
591
+ if (i !== smallpos) {
518
592
  j = q[0];
519
593
  q[0] = p[0];
520
594
  p[0] = j;
@@ -528,7 +602,7 @@ function NeuQuant() {
528
602
  q[3] = p[3];
529
603
  p[3] = j;
530
604
  }
531
- if (smallval != previouscol) {
605
+ if (smallval !== previouscol) {
532
606
  netindex[previouscol] = startpos + i >> 1;
533
607
  for (j = previouscol + 1; j < smallval; j++) {
534
608
  netindex[j] = i;
@@ -697,7 +771,7 @@ function NeuQuant() {
697
771
  }
698
772
  function unbiasnet() {
699
773
  let i;
700
- let j;
774
+ let _j;
701
775
  for (i = 0; i < netsize; i++) {
702
776
  network[i][0] >>= netbiasshift;
703
777
  network[i][1] >>= netbiasshift;
@@ -732,7 +806,7 @@ function NeuQuant() {
732
806
  p[0] -= a * (p[0] - b) / alpharadbias | 0;
733
807
  p[1] -= a * (p[1] - g) / alpharadbias | 0;
734
808
  p[2] -= a * (p[2] - r) / alpharadbias | 0;
735
- } catch (e) {
809
+ } catch (_e) {
736
810
  }
737
811
  }
738
812
  if (k > lo) {
@@ -741,7 +815,7 @@ function NeuQuant() {
741
815
  p[0] -= a * (p[0] - b) / alpharadbias | 0;
742
816
  p[1] -= a * (p[1] - g) / alpharadbias | 0;
743
817
  p[2] -= a * (p[2] - r) / alpharadbias | 0;
744
- } catch (e) {
818
+ } catch (_e) {
745
819
  }
746
820
  }
747
821
  }
@@ -808,7 +882,7 @@ function NeuQuant() {
808
882
  return exports;
809
883
  }
810
884
  function workerCode() {
811
- const self = this;
885
+ const _self = this;
812
886
  try {
813
887
  globalThis.onmessage = function(ev) {
814
888
  const data = ev.data || {};
@@ -818,7 +892,7 @@ function workerCode() {
818
892
  postMessage(response);
819
893
  }
820
894
  };
821
- } catch (e) {
895
+ } catch (_e) {
822
896
  }
823
897
  var workerMethods = {
824
898
  dataToRGB: function dataToRGB(data, width, height) {
@@ -868,7 +942,7 @@ function workerCode() {
868
942
  frame = frame || {};
869
943
  const _frame = frame;
870
944
  const height = _frame.height;
871
- const palette = _frame.palette;
945
+ const _palette = _frame.palette;
872
946
  const sampleInterval = _frame.sampleInterval;
873
947
  const width = _frame.width;
874
948
  const imageData = frame.data;
@@ -952,8 +1026,10 @@ function gifWriter(buf, width, height, gopts) {
952
1026
  throw "Must supply either a local or global palette.";
953
1027
  let num_colors = check_palette_and_num_colors(palette);
954
1028
  let min_code_size = 0;
955
- while (num_colors >>= 1) {
1029
+ num_colors >>= 1;
1030
+ while (num_colors) {
956
1031
  ++min_code_size;
1032
+ num_colors >>= 1;
957
1033
  }
958
1034
  num_colors = 1 << min_code_size;
959
1035
  const delay = opts.delay === void 0 ? 0 : opts.delay;
@@ -1135,13 +1211,13 @@ AnimatedGIF.prototype = {
1135
1211
  freeWorker: function freeWorker(worker) {
1136
1212
  this.availableWorkers.push(worker);
1137
1213
  },
1138
- byteMap: function() {
1214
+ byteMap: (function() {
1139
1215
  const byteMap = [];
1140
1216
  for (let i = 0; i < 256; i++) {
1141
1217
  byteMap[i] = String.fromCharCode(i);
1142
1218
  }
1143
1219
  return byteMap;
1144
- }(),
1220
+ })(),
1145
1221
  bufferToString: function bufferToString(buffer) {
1146
1222
  const numberValues = buffer.length;
1147
1223
  let str = "";
@@ -1176,7 +1252,6 @@ AnimatedGIF.prototype = {
1176
1252
  },
1177
1253
  processFrame: function processFrame(position) {
1178
1254
  const AnimatedGifContext = this;
1179
- const options = this.options;
1180
1255
  const _options = this.options;
1181
1256
  const progressCallback = _options.progressCallback;
1182
1257
  const sampleInterval = _options.sampleInterval;
@@ -1288,8 +1363,8 @@ AnimatedGIF.prototype = {
1288
1363
  const fontColor = _gifshotOptions.fontColor;
1289
1364
  const fontFamily = _gifshotOptions.fontFamily;
1290
1365
  const fontWeight = _gifshotOptions.fontWeight;
1291
- const gifHeight = _gifshotOptions.gifHeight;
1292
- const gifWidth = _gifshotOptions.gifWidth;
1366
+ const _gifHeight = _gifshotOptions.gifHeight;
1367
+ const _gifWidth = _gifshotOptions.gifWidth;
1293
1368
  const text = _gifshotOptions.text;
1294
1369
  const textAlign = _gifshotOptions.textAlign;
1295
1370
  const textBaseline = _gifshotOptions.textBaseline;
@@ -1369,7 +1444,7 @@ function getBase64GIF2(animatedGifInstance, callback) {
1369
1444
  }
1370
1445
  function existingImages() {
1371
1446
  const obj = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1372
- const self = this;
1447
+ const _self = this;
1373
1448
  const callback = obj.callback;
1374
1449
  const images = obj.images;
1375
1450
  const options = obj.options;
@@ -1389,7 +1464,7 @@ function existingImages() {
1389
1464
  ag = new AnimatedGIF(options);
1390
1465
  utils.each(images, function(index, image) {
1391
1466
  const currentImage = image;
1392
- if (utils.isElement(currentImage)) {
1467
+ if (utils.isDrawable(currentImage)) {
1393
1468
  if (options.crossOrigin) {
1394
1469
  currentImage.crossOrigin = options.crossOrigin;
1395
1470
  }
@@ -1471,7 +1546,7 @@ var screenShot = {
1471
1546
  const fontFamily = options.fontFamily;
1472
1547
  const fontWeight = options.fontWeight;
1473
1548
  const keepCameraOn = options.keepCameraOn;
1474
- const numWorkers = options.numWorkers;
1549
+ const _numWorkers = options.numWorkers;
1475
1550
  const progressCallback = options.progressCallback;
1476
1551
  const saveRenderingContexts = options.saveRenderingContexts;
1477
1552
  const savedRenderingContexts = options.savedRenderingContexts;
@@ -1485,7 +1560,7 @@ var screenShot = {
1485
1560
  const gifWidth = Number(options.gifWidth);
1486
1561
  const gifHeight = Number(options.gifHeight);
1487
1562
  let interval = Number(options.interval);
1488
- const sampleInterval = Number(options.sampleInterval);
1563
+ const _sampleInterval = Number(options.sampleInterval);
1489
1564
  const waitBetweenFrames = hasExistingImages ? 0 : interval * 1e3;
1490
1565
  const renderingContextsToSave = [];
1491
1566
  let numFrames = savedRenderingContexts.length ? savedRenderingContexts.length : options.numFrames;
@@ -1666,7 +1741,7 @@ var videoStream = {
1666
1741
  } else if (existingVideo2 instanceof Blob) {
1667
1742
  try {
1668
1743
  videoElement.src = utils.URL.createObjectURL(existingVideo2);
1669
- } catch (e) {
1744
+ } catch (_e) {
1670
1745
  }
1671
1746
  videoElement.innerHTML = `<source src="${existingVideo2}" type="${existingVideo2.type}" />`;
1672
1747
  }
@@ -1676,7 +1751,7 @@ var videoStream = {
1676
1751
  try {
1677
1752
  videoElement.srcObject = cameraStream;
1678
1753
  videoElement.src = utils.URL.createObjectURL(cameraStream);
1679
- } catch (e) {
1754
+ } catch (_e) {
1680
1755
  videoElement.srcObject = cameraStream;
1681
1756
  }
1682
1757
  }
@@ -1714,7 +1789,7 @@ var videoStream = {
1714
1789
  const options = obj.options;
1715
1790
  const webcamVideoElement = obj.webcamVideoElement;
1716
1791
  const videoElement = utils.isElement(existingVideo2) ? existingVideo2 : webcamVideoElement ? webcamVideoElement : document2.createElement("video");
1717
- const cameraStream = void 0;
1792
+ const _cameraStream = void 0;
1718
1793
  if (crossOrigin) {
1719
1794
  videoElement.crossOrigin = options.crossOrigin;
1720
1795
  }
@@ -1832,7 +1907,7 @@ function createAndGetGIF(obj, callback) {
1832
1907
  const video = options.video;
1833
1908
  const gifWidth = Number(options.gifWidth);
1834
1909
  const gifHeight = Number(options.gifHeight);
1835
- const numFrames = Number(options.numFrames);
1910
+ const _numFrames = Number(options.numFrames);
1836
1911
  const cameraStream = obj.cameraStream;
1837
1912
  const videoElement = obj.videoElement;
1838
1913
  const videoWidth = obj.videoWidth;
@@ -1879,11 +1954,11 @@ function existingVideo() {
1879
1954
  "globalThis.URL": true
1880
1955
  };
1881
1956
  const errorObj = error.validate(skipObj);
1882
- const loadedImages = 0;
1957
+ const _loadedImages = 0;
1883
1958
  let videoType = void 0;
1884
1959
  let videoSrc = void 0;
1885
- const tempImage = void 0;
1886
- const ag = void 0;
1960
+ const _tempImage = void 0;
1961
+ const _ag = void 0;
1887
1962
  if (errorObj.error) {
1888
1963
  return callback(errorObj);
1889
1964
  }
@@ -2020,7 +2095,7 @@ var GIF_BUILDER_OPTIONS = {
2020
2095
  crossOrigin: "Anonymous",
2021
2096
  // Options are 'Anonymous', 'use-credentials', or a falsy value to not set a CORS attribute.
2022
2097
  // CALLBACKS
2023
- progressCallback: (captureProgress) => {
2098
+ progressCallback: (_captureProgress) => {
2024
2099
  },
2025
2100
  // Callback that provides the current progress of the current image
2026
2101
  completeCallback: () => {
@@ -2092,14 +2167,14 @@ var GIF_BUILDER_OPTIONS = {
2092
2167
  savedRenderingContexts: []
2093
2168
  // Array of canvas image data
2094
2169
  };
2095
- var GIFBuilder = class {
2170
+ var GIFBuilder = class _GIFBuilder {
2096
2171
  static get properties() {
2097
2172
  return {
2098
2173
  id: "gif",
2099
2174
  name: "GIF",
2100
2175
  extensions: ["gif"],
2101
2176
  mimeTypes: ["image/gif"],
2102
- builder: GIFBuilder,
2177
+ builder: _GIFBuilder,
2103
2178
  options: GIF_BUILDER_OPTIONS
2104
2179
  };
2105
2180
  }