@vvfx/sdk 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: TODO
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 赤芍,何即,不择,意绮
6
- * Version: v0.2.0
6
+ * Version: v0.2.1
7
7
  */
8
8
 
9
9
  'use strict';
@@ -11,7 +11,6 @@
11
11
  var EFFECTS = require('@galacean/effects');
12
12
  var url$1 = require('url');
13
13
 
14
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
15
14
  function _interopNamespaceDefault(e) {
16
15
  var n = Object.create(null);
17
16
  if (e) {
@@ -59546,11 +59545,11 @@ function loadFFmpegHelper(options) {
59546
59545
  return [
59547
59546
  4,
59548
59547
  Promise.all([
59549
- Promise.resolve().then(function () { return index$1; }).catch(function(err) {
59548
+ import('@ffmpeg/ffmpeg').catch(function(err) {
59550
59549
  var message = _instanceof(err, Error) ? err.message : 'Unknown error';
59551
59550
  throw new Error("Failed to load @ffmpeg/ffmpeg: " + message);
59552
59551
  }),
59553
- Promise.resolve().then(function () { return index; }).catch(function(err) {
59552
+ import('@ffmpeg/util').catch(function(err) {
59554
59553
  var message = _instanceof(err, Error) ? err.message : 'Unknown error';
59555
59554
  throw new Error("Failed to load @ffmpeg/util: " + message);
59556
59555
  })
@@ -95872,783 +95871,6 @@ SDK.config = BaseConfig;
95872
95871
  return _instanceof(obj, CardItem);
95873
95872
  }
95874
95873
 
95875
- var FFMessageType;
95876
- (function(FFMessageType) {
95877
- FFMessageType["LOAD"] = "LOAD";
95878
- FFMessageType["EXEC"] = "EXEC";
95879
- FFMessageType["FFPROBE"] = "FFPROBE";
95880
- FFMessageType["WRITE_FILE"] = "WRITE_FILE";
95881
- FFMessageType["READ_FILE"] = "READ_FILE";
95882
- FFMessageType["DELETE_FILE"] = "DELETE_FILE";
95883
- FFMessageType["RENAME"] = "RENAME";
95884
- FFMessageType["CREATE_DIR"] = "CREATE_DIR";
95885
- FFMessageType["LIST_DIR"] = "LIST_DIR";
95886
- FFMessageType["DELETE_DIR"] = "DELETE_DIR";
95887
- FFMessageType["ERROR"] = "ERROR";
95888
- FFMessageType["DOWNLOAD"] = "DOWNLOAD";
95889
- FFMessageType["PROGRESS"] = "PROGRESS";
95890
- FFMessageType["LOG"] = "LOG";
95891
- FFMessageType["MOUNT"] = "MOUNT";
95892
- FFMessageType["UNMOUNT"] = "UNMOUNT";
95893
- })(FFMessageType || (FFMessageType = {}));
95894
-
95895
- /**
95896
- * Generate an unique message ID.
95897
- */ var getMessageID = function() {
95898
- var messageID = 0;
95899
- return function() {
95900
- return messageID++;
95901
- };
95902
- }();
95903
-
95904
- var ERROR_NOT_LOADED = new Error("ffmpeg is not loaded, call `await ffmpeg.load()` first");
95905
- var ERROR_TERMINATED = new Error("called FFmpeg.terminate()");
95906
-
95907
- var _worker = /*#__PURE__*/ _class_private_field_loose_key("_worker"), /**
95908
- * #resolves and #rejects tracks Promise resolves and rejects to
95909
- * be called when we receive message from web worker.
95910
- */ _resolves = /*#__PURE__*/ _class_private_field_loose_key("_resolves"), _rejects = /*#__PURE__*/ _class_private_field_loose_key("_rejects"), _logEventCallbacks = /*#__PURE__*/ _class_private_field_loose_key("_logEventCallbacks"), _progressEventCallbacks = /*#__PURE__*/ _class_private_field_loose_key("_progressEventCallbacks"), /**
95911
- * register worker message event handlers.
95912
- */ _registerHandlers = /*#__PURE__*/ _class_private_field_loose_key("_registerHandlers"), /**
95913
- * Generic function to send messages to web worker.
95914
- */ _send = /*#__PURE__*/ _class_private_field_loose_key("_send");
95915
- /**
95916
- * Provides APIs to interact with ffmpeg web worker.
95917
- *
95918
- * @example
95919
- * ```ts
95920
- * const ffmpeg = new FFmpeg();
95921
- * ```
95922
- */ var FFmpeg = /*#__PURE__*/ function() {
95923
- function FFmpeg() {
95924
- var _this = this;
95925
- Object.defineProperty(this, _worker, {
95926
- writable: true,
95927
- value: void 0
95928
- });
95929
- Object.defineProperty(this, _resolves, {
95930
- writable: true,
95931
- value: void 0
95932
- });
95933
- Object.defineProperty(this, _rejects, {
95934
- writable: true,
95935
- value: void 0
95936
- });
95937
- Object.defineProperty(this, _logEventCallbacks, {
95938
- writable: true,
95939
- value: void 0
95940
- });
95941
- Object.defineProperty(this, _progressEventCallbacks, {
95942
- writable: true,
95943
- value: void 0
95944
- });
95945
- Object.defineProperty(this, _registerHandlers, {
95946
- writable: true,
95947
- value: void 0
95948
- });
95949
- Object.defineProperty(this, _send, {
95950
- writable: true,
95951
- value: void 0
95952
- });
95953
- _class_private_field_loose_base(this, _worker)[_worker] = null;
95954
- _class_private_field_loose_base(this, _resolves)[_resolves] = {};
95955
- _class_private_field_loose_base(this, _rejects)[_rejects] = {};
95956
- _class_private_field_loose_base(this, _logEventCallbacks)[_logEventCallbacks] = [];
95957
- _class_private_field_loose_base(this, _progressEventCallbacks)[_progressEventCallbacks] = [];
95958
- this.loaded = false;
95959
- _class_private_field_loose_base(this, _registerHandlers)[_registerHandlers] = function() {
95960
- if (_class_private_field_loose_base(_this, _worker)[_worker]) {
95961
- _class_private_field_loose_base(_this, _worker)[_worker].onmessage = function(param) {
95962
- var _param_data = param.data, id = _param_data.id, type = _param_data.type, data = _param_data.data;
95963
- switch(type){
95964
- case FFMessageType.LOAD:
95965
- _this.loaded = true;
95966
- _class_private_field_loose_base(_this, _resolves)[_resolves][id](data);
95967
- break;
95968
- case FFMessageType.MOUNT:
95969
- case FFMessageType.UNMOUNT:
95970
- case FFMessageType.EXEC:
95971
- case FFMessageType.FFPROBE:
95972
- case FFMessageType.WRITE_FILE:
95973
- case FFMessageType.READ_FILE:
95974
- case FFMessageType.DELETE_FILE:
95975
- case FFMessageType.RENAME:
95976
- case FFMessageType.CREATE_DIR:
95977
- case FFMessageType.LIST_DIR:
95978
- case FFMessageType.DELETE_DIR:
95979
- _class_private_field_loose_base(_this, _resolves)[_resolves][id](data);
95980
- break;
95981
- case FFMessageType.LOG:
95982
- _class_private_field_loose_base(_this, _logEventCallbacks)[_logEventCallbacks].forEach(function(f) {
95983
- return f(data);
95984
- });
95985
- break;
95986
- case FFMessageType.PROGRESS:
95987
- _class_private_field_loose_base(_this, _progressEventCallbacks)[_progressEventCallbacks].forEach(function(f) {
95988
- return f(data);
95989
- });
95990
- break;
95991
- case FFMessageType.ERROR:
95992
- _class_private_field_loose_base(_this, _rejects)[_rejects][id](data);
95993
- break;
95994
- }
95995
- delete _class_private_field_loose_base(_this, _resolves)[_resolves][id];
95996
- delete _class_private_field_loose_base(_this, _rejects)[_rejects][id];
95997
- };
95998
- }
95999
- };
96000
- _class_private_field_loose_base(this, _send)[_send] = function(param, trans, signal) {
96001
- var type = param.type, data = param.data;
96002
- if (trans === void 0) trans = [];
96003
- if (!_class_private_field_loose_base(_this, _worker)[_worker]) {
96004
- return Promise.reject(ERROR_NOT_LOADED);
96005
- }
96006
- return new Promise(function(resolve, reject) {
96007
- var id = getMessageID();
96008
- _class_private_field_loose_base(_this, _worker)[_worker] && _class_private_field_loose_base(_this, _worker)[_worker].postMessage({
96009
- id: id,
96010
- type: type,
96011
- data: data
96012
- }, trans);
96013
- _class_private_field_loose_base(_this, _resolves)[_resolves][id] = resolve;
96014
- _class_private_field_loose_base(_this, _rejects)[_rejects][id] = reject;
96015
- signal == null ? void 0 : signal.addEventListener("abort", function() {
96016
- reject(new DOMException("Message # " + id + " was aborted", "AbortError"));
96017
- }, {
96018
- once: true
96019
- });
96020
- });
96021
- };
96022
- /**
96023
- * Loads ffmpeg-core inside web worker. It is required to call this method first
96024
- * as it initializes WebAssembly and other essential variables.
96025
- *
96026
- * @category FFmpeg
96027
- * @returns `true` if ffmpeg core is loaded for the first time.
96028
- */ this.load = function(_0, _1) {
96029
- if (_0 === void 0) _0 = void 0;
96030
- if (_1 === void 0) _1 = void 0;
96031
- var _ref = [
96032
- _0,
96033
- _1
96034
- ], tmp = _ref[0], _ref1 = tmp === void 0 ? {} : tmp, _rest = _ref.slice(1), classWorkerURL = _ref1.classWorkerURL, config = _object_without_properties_loose(_ref1, [
96035
- "classWorkerURL"
96036
- ]), tmp1 = _rest[0], signal = (tmp1 === void 0 ? {} : tmp1).signal;
96037
- if (!_class_private_field_loose_base(_this, _worker)[_worker]) {
96038
- _class_private_field_loose_base(_this, _worker)[_worker] = classWorkerURL ? new Worker(new URL(classWorkerURL, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.mjs', document.baseURI).href))), {
96039
- type: "module"
96040
- }) : // We need to duplicated the code here to enable webpack
96041
- // to bundle worekr.js here.
96042
- new Worker(new URL("./worker.js", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.mjs', document.baseURI).href))), {
96043
- type: "module"
96044
- });
96045
- _class_private_field_loose_base(_this, _registerHandlers)[_registerHandlers]();
96046
- }
96047
- return _class_private_field_loose_base(_this, _send)[_send]({
96048
- type: FFMessageType.LOAD,
96049
- data: config
96050
- }, undefined, signal);
96051
- };
96052
- /**
96053
- * Execute ffmpeg command.
96054
- *
96055
- * @remarks
96056
- * To avoid common I/O issues, ["-nostdin", "-y"] are prepended to the args
96057
- * by default.
96058
- *
96059
- * @example
96060
- * ```ts
96061
- * const ffmpeg = new FFmpeg();
96062
- * await ffmpeg.load();
96063
- * await ffmpeg.writeFile("video.avi", ...);
96064
- * // ffmpeg -i video.avi video.mp4
96065
- * await ffmpeg.exec(["-i", "video.avi", "video.mp4"]);
96066
- * const data = ffmpeg.readFile("video.mp4");
96067
- * ```
96068
- *
96069
- * @returns `0` if no error, `!= 0` if timeout (1) or error.
96070
- * @category FFmpeg
96071
- */ this.exec = function(/** ffmpeg command line args */ args, /**
96072
- * milliseconds to wait before stopping the command execution.
96073
- *
96074
- * @defaultValue -1
96075
- */ timeout, param) {
96076
- if (timeout === void 0) timeout = -1;
96077
- var signal = (param === void 0 ? {} : param).signal;
96078
- return _class_private_field_loose_base(_this, _send)[_send]({
96079
- type: FFMessageType.EXEC,
96080
- data: {
96081
- args: args,
96082
- timeout: timeout
96083
- }
96084
- }, undefined, signal);
96085
- };
96086
- /**
96087
- * Execute ffprobe command.
96088
- *
96089
- * @example
96090
- * ```ts
96091
- * const ffmpeg = new FFmpeg();
96092
- * await ffmpeg.load();
96093
- * await ffmpeg.writeFile("video.avi", ...);
96094
- * // Getting duration of a video in seconds: ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 video.avi -o output.txt
96095
- * await ffmpeg.ffprobe(["-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", "video.avi", "-o", "output.txt"]);
96096
- * const data = ffmpeg.readFile("output.txt");
96097
- * ```
96098
- *
96099
- * @returns `0` if no error, `!= 0` if timeout (1) or error.
96100
- * @category FFmpeg
96101
- */ this.ffprobe = function(/** ffprobe command line args */ args, /**
96102
- * milliseconds to wait before stopping the command execution.
96103
- *
96104
- * @defaultValue -1
96105
- */ timeout, param) {
96106
- if (timeout === void 0) timeout = -1;
96107
- var signal = (param === void 0 ? {} : param).signal;
96108
- return _class_private_field_loose_base(_this, _send)[_send]({
96109
- type: FFMessageType.FFPROBE,
96110
- data: {
96111
- args: args,
96112
- timeout: timeout
96113
- }
96114
- }, undefined, signal);
96115
- };
96116
- /**
96117
- * Terminate all ongoing API calls and terminate web worker.
96118
- * `FFmpeg.load()` must be called again before calling any other APIs.
96119
- *
96120
- * @category FFmpeg
96121
- */ this.terminate = function() {
96122
- var ids = Object.keys(_class_private_field_loose_base(_this, _rejects)[_rejects]);
96123
- // rejects all incomplete Promises.
96124
- for(var _iterator = _create_for_of_iterator_helper_loose(ids), _step; !(_step = _iterator()).done;){
96125
- var id = _step.value;
96126
- _class_private_field_loose_base(_this, _rejects)[_rejects][id](ERROR_TERMINATED);
96127
- delete _class_private_field_loose_base(_this, _rejects)[_rejects][id];
96128
- delete _class_private_field_loose_base(_this, _resolves)[_resolves][id];
96129
- }
96130
- if (_class_private_field_loose_base(_this, _worker)[_worker]) {
96131
- _class_private_field_loose_base(_this, _worker)[_worker].terminate();
96132
- _class_private_field_loose_base(_this, _worker)[_worker] = null;
96133
- _this.loaded = false;
96134
- }
96135
- };
96136
- /**
96137
- * Write data to ffmpeg.wasm.
96138
- *
96139
- * @example
96140
- * ```ts
96141
- * const ffmpeg = new FFmpeg();
96142
- * await ffmpeg.load();
96143
- * await ffmpeg.writeFile("video.avi", await fetchFile("../video.avi"));
96144
- * await ffmpeg.writeFile("text.txt", "hello world");
96145
- * ```
96146
- *
96147
- * @category File System
96148
- */ this.writeFile = function(path, data, param) {
96149
- var signal = (param === void 0 ? {} : param).signal;
96150
- var trans = [];
96151
- if (_instanceof(data, Uint8Array)) {
96152
- trans.push(data.buffer);
96153
- }
96154
- return _class_private_field_loose_base(_this, _send)[_send]({
96155
- type: FFMessageType.WRITE_FILE,
96156
- data: {
96157
- path: path,
96158
- data: data
96159
- }
96160
- }, trans, signal);
96161
- };
96162
- this.mount = function(fsType, options, mountPoint) {
96163
- var trans = [];
96164
- return _class_private_field_loose_base(_this, _send)[_send]({
96165
- type: FFMessageType.MOUNT,
96166
- data: {
96167
- fsType: fsType,
96168
- options: options,
96169
- mountPoint: mountPoint
96170
- }
96171
- }, trans);
96172
- };
96173
- this.unmount = function(mountPoint) {
96174
- var trans = [];
96175
- return _class_private_field_loose_base(_this, _send)[_send]({
96176
- type: FFMessageType.UNMOUNT,
96177
- data: {
96178
- mountPoint: mountPoint
96179
- }
96180
- }, trans);
96181
- };
96182
- /**
96183
- * Read data from ffmpeg.wasm.
96184
- *
96185
- * @example
96186
- * ```ts
96187
- * const ffmpeg = new FFmpeg();
96188
- * await ffmpeg.load();
96189
- * const data = await ffmpeg.readFile("video.mp4");
96190
- * ```
96191
- *
96192
- * @category File System
96193
- */ this.readFile = function(path, /**
96194
- * File content encoding, supports two encodings:
96195
- * - utf8: read file as text file, return data in string type.
96196
- * - binary: read file as binary file, return data in Uint8Array type.
96197
- *
96198
- * @defaultValue binary
96199
- */ encoding, param) {
96200
- if (encoding === void 0) encoding = "binary";
96201
- var signal = (param === void 0 ? {} : param).signal;
96202
- return _class_private_field_loose_base(_this, _send)[_send]({
96203
- type: FFMessageType.READ_FILE,
96204
- data: {
96205
- path: path,
96206
- encoding: encoding
96207
- }
96208
- }, undefined, signal);
96209
- };
96210
- /**
96211
- * Delete a file.
96212
- *
96213
- * @category File System
96214
- */ this.deleteFile = function(path, param) {
96215
- var signal = (param === void 0 ? {} : param).signal;
96216
- return _class_private_field_loose_base(_this, _send)[_send]({
96217
- type: FFMessageType.DELETE_FILE,
96218
- data: {
96219
- path: path
96220
- }
96221
- }, undefined, signal);
96222
- };
96223
- /**
96224
- * Rename a file or directory.
96225
- *
96226
- * @category File System
96227
- */ this.rename = function(oldPath, newPath, param) {
96228
- var signal = (param === void 0 ? {} : param).signal;
96229
- return _class_private_field_loose_base(_this, _send)[_send]({
96230
- type: FFMessageType.RENAME,
96231
- data: {
96232
- oldPath: oldPath,
96233
- newPath: newPath
96234
- }
96235
- }, undefined, signal);
96236
- };
96237
- /**
96238
- * Create a directory.
96239
- *
96240
- * @category File System
96241
- */ this.createDir = function(path, param) {
96242
- var signal = (param === void 0 ? {} : param).signal;
96243
- return _class_private_field_loose_base(_this, _send)[_send]({
96244
- type: FFMessageType.CREATE_DIR,
96245
- data: {
96246
- path: path
96247
- }
96248
- }, undefined, signal);
96249
- };
96250
- /**
96251
- * List directory contents.
96252
- *
96253
- * @category File System
96254
- */ this.listDir = function(path, param) {
96255
- var signal = (param === void 0 ? {} : param).signal;
96256
- return _class_private_field_loose_base(_this, _send)[_send]({
96257
- type: FFMessageType.LIST_DIR,
96258
- data: {
96259
- path: path
96260
- }
96261
- }, undefined, signal);
96262
- };
96263
- /**
96264
- * Delete an empty directory.
96265
- *
96266
- * @category File System
96267
- */ this.deleteDir = function(path, param) {
96268
- var signal = (param === void 0 ? {} : param).signal;
96269
- return _class_private_field_loose_base(_this, _send)[_send]({
96270
- type: FFMessageType.DELETE_DIR,
96271
- data: {
96272
- path: path
96273
- }
96274
- }, undefined, signal);
96275
- };
96276
- }
96277
- var _proto = FFmpeg.prototype;
96278
- _proto.on = function on(event, callback) {
96279
- if (event === "log") {
96280
- _class_private_field_loose_base(this, _logEventCallbacks)[_logEventCallbacks].push(callback);
96281
- } else if (event === "progress") {
96282
- _class_private_field_loose_base(this, _progressEventCallbacks)[_progressEventCallbacks].push(callback);
96283
- }
96284
- };
96285
- _proto.off = function off(event, callback) {
96286
- if (event === "log") {
96287
- _class_private_field_loose_base(this, _logEventCallbacks)[_logEventCallbacks] = _class_private_field_loose_base(this, _logEventCallbacks)[_logEventCallbacks].filter(function(f) {
96288
- return f !== callback;
96289
- });
96290
- } else if (event === "progress") {
96291
- _class_private_field_loose_base(this, _progressEventCallbacks)[_progressEventCallbacks] = _class_private_field_loose_base(this, _progressEventCallbacks)[_progressEventCallbacks].filter(function(f) {
96292
- return f !== callback;
96293
- });
96294
- }
96295
- };
96296
- return FFmpeg;
96297
- }();
96298
-
96299
- var FFFSType;
96300
- (function(FFFSType) {
96301
- FFFSType["MEMFS"] = "MEMFS";
96302
- FFFSType["NODEFS"] = "NODEFS";
96303
- FFFSType["NODERAWFS"] = "NODERAWFS";
96304
- FFFSType["IDBFS"] = "IDBFS";
96305
- FFFSType["WORKERFS"] = "WORKERFS";
96306
- FFFSType["PROXYFS"] = "PROXYFS";
96307
- })(FFFSType || (FFFSType = {}));
96308
-
96309
- var index$1 = /*#__PURE__*/Object.freeze({
96310
- __proto__: null,
96311
- get FFFSType () { return FFFSType; },
96312
- FFmpeg: FFmpeg
96313
- });
96314
-
96315
- var ERROR_RESPONSE_BODY_READER = new Error("failed to get response body reader");
96316
- var ERROR_INCOMPLETED_DOWNLOAD = new Error("failed to complete download");
96317
-
96318
- var HeaderContentLength = "Content-Length";
96319
-
96320
- var readFromBlobOrFile = function readFromBlobOrFile(blob) {
96321
- return new Promise(function(resolve, reject) {
96322
- var fileReader = new FileReader();
96323
- fileReader.onload = function() {
96324
- var result = fileReader.result;
96325
- if (_instanceof(result, ArrayBuffer)) {
96326
- resolve(new Uint8Array(result));
96327
- } else {
96328
- resolve(new Uint8Array());
96329
- }
96330
- };
96331
- fileReader.onerror = function(event) {
96332
- var _event_target_error, _event_target;
96333
- reject(Error("File could not be read! Code=" + ((event == null ? void 0 : (_event_target = event.target) == null ? void 0 : (_event_target_error = _event_target.error) == null ? void 0 : _event_target_error.code) || -1)));
96334
- };
96335
- fileReader.readAsArrayBuffer(blob);
96336
- });
96337
- };
96338
- /**
96339
- * An util function to fetch data from url string, base64, URL, File or Blob format.
96340
- *
96341
- * Examples:
96342
- * ```ts
96343
- * // URL
96344
- * await fetchFile("http://localhost:3000/video.mp4");
96345
- * // base64
96346
- * await fetchFile("data:<type>;base64,wL2dvYWwgbW9yZ...");
96347
- * // URL
96348
- * await fetchFile(new URL("video.mp4", import.meta.url));
96349
- * // File
96350
- * fileInput.addEventListener('change', (e) => {
96351
- * await fetchFile(e.target.files[0]);
96352
- * });
96353
- * // Blob
96354
- * const blob = new Blob(...);
96355
- * await fetchFile(blob);
96356
- * ```
96357
- */ var fetchFile = function fetchFile(file) {
96358
- return _async_to_generator(function() {
96359
- var data;
96360
- return _ts_generator(this, function(_state) {
96361
- switch(_state.label){
96362
- case 0:
96363
- if (!(typeof file === "string")) return [
96364
- 3,
96365
- 5
96366
- ];
96367
- if (!/data:_data\/([a-zA-Z]*);base64,([^"]*)/.test(file)) return [
96368
- 3,
96369
- 1
96370
- ];
96371
- data = atob(file.split(",")[1]).split("").map(function(c) {
96372
- return c.charCodeAt(0);
96373
- });
96374
- return [
96375
- 3,
96376
- 4
96377
- ];
96378
- case 1:
96379
- return [
96380
- 4,
96381
- fetch(file)
96382
- ];
96383
- case 2:
96384
- return [
96385
- 4,
96386
- _state.sent().arrayBuffer()
96387
- ];
96388
- case 3:
96389
- data = _state.sent();
96390
- _state.label = 4;
96391
- case 4:
96392
- return [
96393
- 3,
96394
- 11
96395
- ];
96396
- case 5:
96397
- if (!_instanceof(file, URL)) return [
96398
- 3,
96399
- 8
96400
- ];
96401
- return [
96402
- 4,
96403
- fetch(file)
96404
- ];
96405
- case 6:
96406
- return [
96407
- 4,
96408
- _state.sent().arrayBuffer()
96409
- ];
96410
- case 7:
96411
- data = _state.sent();
96412
- return [
96413
- 3,
96414
- 11
96415
- ];
96416
- case 8:
96417
- if (!(_instanceof(file, File) || _instanceof(file, Blob))) return [
96418
- 3,
96419
- 10
96420
- ];
96421
- return [
96422
- 4,
96423
- readFromBlobOrFile(file)
96424
- ];
96425
- case 9:
96426
- data = _state.sent();
96427
- return [
96428
- 3,
96429
- 11
96430
- ];
96431
- case 10:
96432
- return [
96433
- 2,
96434
- new Uint8Array()
96435
- ];
96436
- case 11:
96437
- return [
96438
- 2,
96439
- new Uint8Array(data)
96440
- ];
96441
- }
96442
- });
96443
- })();
96444
- };
96445
- /**
96446
- * importScript dynamically import a script, useful when you
96447
- * want to use different versions of ffmpeg.wasm based on environment.
96448
- *
96449
- * Example:
96450
- *
96451
- * ```ts
96452
- * await importScript("http://localhost:3000/ffmpeg.js");
96453
- * ```
96454
- */ var importScript = function importScript(url) {
96455
- return _async_to_generator(function() {
96456
- return _ts_generator(this, function(_state) {
96457
- return [
96458
- 2,
96459
- new Promise(function(resolve) {
96460
- var script = document.createElement("script");
96461
- var eventHandler = function eventHandler1() {
96462
- script.removeEventListener("load", eventHandler);
96463
- resolve();
96464
- };
96465
- script.src = url;
96466
- script.type = "text/javascript";
96467
- script.addEventListener("load", eventHandler);
96468
- document.getElementsByTagName("head")[0].appendChild(script);
96469
- })
96470
- ];
96471
- });
96472
- })();
96473
- };
96474
- /**
96475
- * Download content of a URL with progress.
96476
- *
96477
- * Progress only works when Content-Length is provided by the server.
96478
- *
96479
- */ var downloadWithProgress = function downloadWithProgress(url, cb) {
96480
- return _async_to_generator(function() {
96481
- var resp, buf, _resp_body, total, reader, chunks, received, _ref, done, value, delta, data, position, _iterator, _step, chunk, e;
96482
- return _ts_generator(this, function(_state) {
96483
- switch(_state.label){
96484
- case 0:
96485
- return [
96486
- 4,
96487
- fetch(url)
96488
- ];
96489
- case 1:
96490
- resp = _state.sent();
96491
- _state.label = 2;
96492
- case 2:
96493
- _state.trys.push([
96494
- 2,
96495
- 7,
96496
- ,
96497
- 9
96498
- ]);
96499
- // Set total to -1 to indicate that there is not Content-Type Header.
96500
- total = parseInt(resp.headers.get(HeaderContentLength) || "-1");
96501
- reader = (_resp_body = resp.body) == null ? void 0 : _resp_body.getReader();
96502
- if (!reader) throw ERROR_RESPONSE_BODY_READER;
96503
- chunks = [];
96504
- received = 0;
96505
- _state.label = 3;
96506
- case 3:
96507
- return [
96508
- 4,
96509
- reader.read()
96510
- ];
96511
- case 4:
96512
- _ref = _state.sent(), done = _ref.done, value = _ref.value;
96513
- delta = value ? value.length : 0;
96514
- if (done) {
96515
- if (total != -1 && total !== received) throw ERROR_INCOMPLETED_DOWNLOAD;
96516
- cb && cb({
96517
- url: url,
96518
- total: total,
96519
- received: received,
96520
- delta: delta,
96521
- done: done
96522
- });
96523
- return [
96524
- 3,
96525
- 6
96526
- ];
96527
- }
96528
- chunks.push(value);
96529
- received += delta;
96530
- cb && cb({
96531
- url: url,
96532
- total: total,
96533
- received: received,
96534
- delta: delta,
96535
- done: done
96536
- });
96537
- _state.label = 5;
96538
- case 5:
96539
- return [
96540
- 3,
96541
- 3
96542
- ];
96543
- case 6:
96544
- data = new Uint8Array(received);
96545
- position = 0;
96546
- for(_iterator = _create_for_of_iterator_helper_loose(chunks); !(_step = _iterator()).done;){
96547
- chunk = _step.value;
96548
- data.set(chunk, position);
96549
- position += chunk.length;
96550
- }
96551
- buf = data.buffer;
96552
- return [
96553
- 3,
96554
- 9
96555
- ];
96556
- case 7:
96557
- e = _state.sent();
96558
- console.log("failed to send download progress event: ", e);
96559
- return [
96560
- 4,
96561
- resp.arrayBuffer()
96562
- ];
96563
- case 8:
96564
- // Fetch arrayBuffer directly when it is not possible to get progress.
96565
- buf = _state.sent();
96566
- cb && cb({
96567
- url: url,
96568
- total: buf.byteLength,
96569
- received: buf.byteLength,
96570
- delta: 0,
96571
- done: true
96572
- });
96573
- return [
96574
- 3,
96575
- 9
96576
- ];
96577
- case 9:
96578
- return [
96579
- 2,
96580
- buf
96581
- ];
96582
- }
96583
- });
96584
- })();
96585
- };
96586
- /**
96587
- * toBlobURL fetches data from an URL and return a blob URL.
96588
- *
96589
- * Example:
96590
- *
96591
- * ```ts
96592
- * await toBlobURL("http://localhost:3000/ffmpeg.js", "text/javascript");
96593
- * ```
96594
- */ var toBlobURL = function toBlobURL(url, mimeType, progress, cb) {
96595
- if (progress === void 0) progress = false;
96596
- return _async_to_generator(function() {
96597
- var buf, _tmp, blob;
96598
- return _ts_generator(this, function(_state) {
96599
- switch(_state.label){
96600
- case 0:
96601
- if (!progress) return [
96602
- 3,
96603
- 2
96604
- ];
96605
- return [
96606
- 4,
96607
- downloadWithProgress(url, cb)
96608
- ];
96609
- case 1:
96610
- _tmp = _state.sent();
96611
- return [
96612
- 3,
96613
- 5
96614
- ];
96615
- case 2:
96616
- return [
96617
- 4,
96618
- fetch(url)
96619
- ];
96620
- case 3:
96621
- return [
96622
- 4,
96623
- _state.sent().arrayBuffer()
96624
- ];
96625
- case 4:
96626
- _tmp = _state.sent();
96627
- _state.label = 5;
96628
- case 5:
96629
- buf = _tmp;
96630
- blob = new Blob([
96631
- buf
96632
- ], {
96633
- type: mimeType
96634
- });
96635
- return [
96636
- 2,
96637
- URL.createObjectURL(blob)
96638
- ];
96639
- }
96640
- });
96641
- })();
96642
- };
96643
-
96644
- var index = /*#__PURE__*/Object.freeze({
96645
- __proto__: null,
96646
- downloadWithProgress: downloadWithProgress,
96647
- fetchFile: fetchFile,
96648
- importScript: importScript,
96649
- toBlobURL: toBlobURL
96650
- });
96651
-
96652
95874
  Object.defineProperty(exports, "generateGUID", {
96653
95875
  enumerable: true,
96654
95876
  get: function () { return EFFECTS.generateGUID; }