use-ffmpeg
Version:
A React hook for browser-based media processing using FFmpeg WASM - handles video and other file formats conversion with ease
2,938 lines • 107 kB
JavaScript
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
var react = {exports: {}};
var react_production = {};
/**
* @license React
* react.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var hasRequiredReact_production;
function requireReact_production () {
if (hasRequiredReact_production) return react_production;
hasRequiredReact_production = 1;
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
REACT_PROFILER_TYPE = Symbol.for("react.profiler"),
REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
REACT_CONTEXT_TYPE = Symbol.for("react.context"),
REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"),
REACT_MEMO_TYPE = Symbol.for("react.memo"),
REACT_LAZY_TYPE = Symbol.for("react.lazy"),
MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
function getIteratorFn(maybeIterable) {
if (null === maybeIterable || "object" !== typeof maybeIterable) return null;
maybeIterable =
(MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) ||
maybeIterable["@@iterator"];
return "function" === typeof maybeIterable ? maybeIterable : null;
}
var ReactNoopUpdateQueue = {
isMounted: function () {
return false;
},
enqueueForceUpdate: function () {},
enqueueReplaceState: function () {},
enqueueSetState: function () {}
},
assign = Object.assign,
emptyObject = {};
function Component(props, context, updater) {
this.props = props;
this.context = context;
this.refs = emptyObject;
this.updater = updater || ReactNoopUpdateQueue;
}
Component.prototype.isReactComponent = {};
Component.prototype.setState = function (partialState, callback) {
if (
"object" !== typeof partialState &&
"function" !== typeof partialState &&
null != partialState
)
throw Error(
"takes an object of state variables to update or a function which returns an object of state variables."
);
this.updater.enqueueSetState(this, partialState, callback, "setState");
};
Component.prototype.forceUpdate = function (callback) {
this.updater.enqueueForceUpdate(this, callback, "forceUpdate");
};
function ComponentDummy() {}
ComponentDummy.prototype = Component.prototype;
function PureComponent(props, context, updater) {
this.props = props;
this.context = context;
this.refs = emptyObject;
this.updater = updater || ReactNoopUpdateQueue;
}
var pureComponentPrototype = (PureComponent.prototype = new ComponentDummy());
pureComponentPrototype.constructor = PureComponent;
assign(pureComponentPrototype, Component.prototype);
pureComponentPrototype.isPureReactComponent = true;
var isArrayImpl = Array.isArray,
ReactSharedInternals = { H: null, A: null, T: null, S: null },
hasOwnProperty = Object.prototype.hasOwnProperty;
function ReactElement(type, key, self, source, owner, props) {
self = props.ref;
return {
$$typeof: REACT_ELEMENT_TYPE,
type: type,
key: key,
ref: undefined !== self ? self : null,
props: props
};
}
function cloneAndReplaceKey(oldElement, newKey) {
return ReactElement(
oldElement.type,
newKey,
undefined,
undefined,
undefined,
oldElement.props
);
}
function isValidElement(object) {
return (
"object" === typeof object &&
null !== object &&
object.$$typeof === REACT_ELEMENT_TYPE
);
}
function escape(key) {
var escaperLookup = { "=": "=0", ":": "=2" };
return (
"$" +
key.replace(/[=:]/g, function (match) {
return escaperLookup[match];
})
);
}
var userProvidedKeyEscapeRegex = /\/+/g;
function getElementKey(element, index) {
return "object" === typeof element && null !== element && null != element.key
? escape("" + element.key)
: index.toString(36);
}
function noop$1() {}
function resolveThenable(thenable) {
switch (thenable.status) {
case "fulfilled":
return thenable.value;
case "rejected":
throw thenable.reason;
default:
switch (
("string" === typeof thenable.status
? thenable.then(noop$1, noop$1)
: ((thenable.status = "pending"),
thenable.then(
function (fulfilledValue) {
"pending" === thenable.status &&
((thenable.status = "fulfilled"),
(thenable.value = fulfilledValue));
},
function (error) {
"pending" === thenable.status &&
((thenable.status = "rejected"), (thenable.reason = error));
}
)),
thenable.status)
) {
case "fulfilled":
return thenable.value;
case "rejected":
throw thenable.reason;
}
}
throw thenable;
}
function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
var type = typeof children;
if ("undefined" === type || "boolean" === type) children = null;
var invokeCallback = false;
if (null === children) invokeCallback = true;
else
switch (type) {
case "bigint":
case "string":
case "number":
invokeCallback = true;
break;
case "object":
switch (children.$$typeof) {
case REACT_ELEMENT_TYPE:
case REACT_PORTAL_TYPE:
invokeCallback = true;
break;
case REACT_LAZY_TYPE:
return (
(invokeCallback = children._init),
mapIntoArray(
invokeCallback(children._payload),
array,
escapedPrefix,
nameSoFar,
callback
)
);
}
}
if (invokeCallback)
return (
(callback = callback(children)),
(invokeCallback =
"" === nameSoFar ? "." + getElementKey(children, 0) : nameSoFar),
isArrayImpl(callback)
? ((escapedPrefix = ""),
null != invokeCallback &&
(escapedPrefix =
invokeCallback.replace(userProvidedKeyEscapeRegex, "$&/") + "/"),
mapIntoArray(callback, array, escapedPrefix, "", function (c) {
return c;
}))
: null != callback &&
(isValidElement(callback) &&
(callback = cloneAndReplaceKey(
callback,
escapedPrefix +
(null == callback.key ||
(children && children.key === callback.key)
? ""
: ("" + callback.key).replace(
userProvidedKeyEscapeRegex,
"$&/"
) + "/") +
invokeCallback
)),
array.push(callback)),
1
);
invokeCallback = 0;
var nextNamePrefix = "" === nameSoFar ? "." : nameSoFar + ":";
if (isArrayImpl(children))
for (var i = 0; i < children.length; i++)
(nameSoFar = children[i]),
(type = nextNamePrefix + getElementKey(nameSoFar, i)),
(invokeCallback += mapIntoArray(
nameSoFar,
array,
escapedPrefix,
type,
callback
));
else if (((i = getIteratorFn(children)), "function" === typeof i))
for (
children = i.call(children), i = 0;
!(nameSoFar = children.next()).done;
)
(nameSoFar = nameSoFar.value),
(type = nextNamePrefix + getElementKey(nameSoFar, i++)),
(invokeCallback += mapIntoArray(
nameSoFar,
array,
escapedPrefix,
type,
callback
));
else if ("object" === type) {
if ("function" === typeof children.then)
return mapIntoArray(
resolveThenable(children),
array,
escapedPrefix,
nameSoFar,
callback
);
array = String(children);
throw Error(
"Objects are not valid as a React child (found: " +
("[object Object]" === array
? "object with keys {" + Object.keys(children).join(", ") + "}"
: array) +
"). If you meant to render a collection of children, use an array instead."
);
}
return invokeCallback;
}
function mapChildren(children, func, context) {
if (null == children) return children;
var result = [],
count = 0;
mapIntoArray(children, result, "", "", function (child) {
return func.call(context, child, count++);
});
return result;
}
function lazyInitializer(payload) {
if (-1 === payload._status) {
var ctor = payload._result;
ctor = ctor();
ctor.then(
function (moduleObject) {
if (0 === payload._status || -1 === payload._status)
(payload._status = 1), (payload._result = moduleObject);
},
function (error) {
if (0 === payload._status || -1 === payload._status)
(payload._status = 2), (payload._result = error);
}
);
-1 === payload._status && ((payload._status = 0), (payload._result = ctor));
}
if (1 === payload._status) return payload._result.default;
throw payload._result;
}
var reportGlobalError =
"function" === typeof reportError
? reportError
: function (error) {
if (
"object" === typeof window &&
"function" === typeof window.ErrorEvent
) {
var event = new window.ErrorEvent("error", {
bubbles: true,
cancelable: true,
message:
"object" === typeof error &&
null !== error &&
"string" === typeof error.message
? String(error.message)
: String(error),
error: error
});
if (!window.dispatchEvent(event)) return;
} else if (
"object" === typeof process &&
"function" === typeof process.emit
) {
process.emit("uncaughtException", error);
return;
}
console.error(error);
};
function noop() {}
react_production.Children = {
map: mapChildren,
forEach: function (children, forEachFunc, forEachContext) {
mapChildren(
children,
function () {
forEachFunc.apply(this, arguments);
},
forEachContext
);
},
count: function (children) {
var n = 0;
mapChildren(children, function () {
n++;
});
return n;
},
toArray: function (children) {
return (
mapChildren(children, function (child) {
return child;
}) || []
);
},
only: function (children) {
if (!isValidElement(children))
throw Error(
"React.Children.only expected to receive a single React element child."
);
return children;
}
};
react_production.Component = Component;
react_production.Fragment = REACT_FRAGMENT_TYPE;
react_production.Profiler = REACT_PROFILER_TYPE;
react_production.PureComponent = PureComponent;
react_production.StrictMode = REACT_STRICT_MODE_TYPE;
react_production.Suspense = REACT_SUSPENSE_TYPE;
react_production.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE =
ReactSharedInternals;
react_production.act = function () {
throw Error("act(...) is not supported in production builds of React.");
};
react_production.cache = function (fn) {
return function () {
return fn.apply(null, arguments);
};
};
react_production.cloneElement = function (element, config, children) {
if (null === element || undefined === element)
throw Error(
"The argument must be a React element, but you passed " + element + "."
);
var props = assign({}, element.props),
key = element.key,
owner = undefined;
if (null != config)
for (propName in (undefined !== config.ref && (owner = undefined),
undefined !== config.key && (key = "" + config.key),
config))
!hasOwnProperty.call(config, propName) ||
"key" === propName ||
"__self" === propName ||
"__source" === propName ||
("ref" === propName && undefined === config.ref) ||
(props[propName] = config[propName]);
var propName = arguments.length - 2;
if (1 === propName) props.children = children;
else if (1 < propName) {
for (var childArray = Array(propName), i = 0; i < propName; i++)
childArray[i] = arguments[i + 2];
props.children = childArray;
}
return ReactElement(element.type, key, undefined, undefined, owner, props);
};
react_production.createContext = function (defaultValue) {
defaultValue = {
$$typeof: REACT_CONTEXT_TYPE,
_currentValue: defaultValue,
_currentValue2: defaultValue,
_threadCount: 0,
Provider: null,
Consumer: null
};
defaultValue.Provider = defaultValue;
defaultValue.Consumer = {
$$typeof: REACT_CONSUMER_TYPE,
_context: defaultValue
};
return defaultValue;
};
react_production.createElement = function (type, config, children) {
var propName,
props = {},
key = null;
if (null != config)
for (propName in (undefined !== config.key && (key = "" + config.key), config))
hasOwnProperty.call(config, propName) &&
"key" !== propName &&
"__self" !== propName &&
"__source" !== propName &&
(props[propName] = config[propName]);
var childrenLength = arguments.length - 2;
if (1 === childrenLength) props.children = children;
else if (1 < childrenLength) {
for (var childArray = Array(childrenLength), i = 0; i < childrenLength; i++)
childArray[i] = arguments[i + 2];
props.children = childArray;
}
if (type && type.defaultProps)
for (propName in ((childrenLength = type.defaultProps), childrenLength))
undefined === props[propName] &&
(props[propName] = childrenLength[propName]);
return ReactElement(type, key, undefined, undefined, null, props);
};
react_production.createRef = function () {
return { current: null };
};
react_production.forwardRef = function (render) {
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
};
react_production.isValidElement = isValidElement;
react_production.lazy = function (ctor) {
return {
$$typeof: REACT_LAZY_TYPE,
_payload: { _status: -1, _result: ctor },
_init: lazyInitializer
};
};
react_production.memo = function (type, compare) {
return {
$$typeof: REACT_MEMO_TYPE,
type: type,
compare: undefined === compare ? null : compare
};
};
react_production.startTransition = function (scope) {
var prevTransition = ReactSharedInternals.T,
currentTransition = {};
ReactSharedInternals.T = currentTransition;
try {
var returnValue = scope(),
onStartTransitionFinish = ReactSharedInternals.S;
null !== onStartTransitionFinish &&
onStartTransitionFinish(currentTransition, returnValue);
"object" === typeof returnValue &&
null !== returnValue &&
"function" === typeof returnValue.then &&
returnValue.then(noop, reportGlobalError);
} catch (error) {
reportGlobalError(error);
} finally {
ReactSharedInternals.T = prevTransition;
}
};
react_production.unstable_useCacheRefresh = function () {
return ReactSharedInternals.H.useCacheRefresh();
};
react_production.use = function (usable) {
return ReactSharedInternals.H.use(usable);
};
react_production.useActionState = function (action, initialState, permalink) {
return ReactSharedInternals.H.useActionState(action, initialState, permalink);
};
react_production.useCallback = function (callback, deps) {
return ReactSharedInternals.H.useCallback(callback, deps);
};
react_production.useContext = function (Context) {
return ReactSharedInternals.H.useContext(Context);
};
react_production.useDebugValue = function () {};
react_production.useDeferredValue = function (value, initialValue) {
return ReactSharedInternals.H.useDeferredValue(value, initialValue);
};
react_production.useEffect = function (create, deps) {
return ReactSharedInternals.H.useEffect(create, deps);
};
react_production.useId = function () {
return ReactSharedInternals.H.useId();
};
react_production.useImperativeHandle = function (ref, create, deps) {
return ReactSharedInternals.H.useImperativeHandle(ref, create, deps);
};
react_production.useInsertionEffect = function (create, deps) {
return ReactSharedInternals.H.useInsertionEffect(create, deps);
};
react_production.useLayoutEffect = function (create, deps) {
return ReactSharedInternals.H.useLayoutEffect(create, deps);
};
react_production.useMemo = function (create, deps) {
return ReactSharedInternals.H.useMemo(create, deps);
};
react_production.useOptimistic = function (passthrough, reducer) {
return ReactSharedInternals.H.useOptimistic(passthrough, reducer);
};
react_production.useReducer = function (reducer, initialArg, init) {
return ReactSharedInternals.H.useReducer(reducer, initialArg, init);
};
react_production.useRef = function (initialValue) {
return ReactSharedInternals.H.useRef(initialValue);
};
react_production.useState = function (initialState) {
return ReactSharedInternals.H.useState(initialState);
};
react_production.useSyncExternalStore = function (
subscribe,
getSnapshot,
getServerSnapshot
) {
return ReactSharedInternals.H.useSyncExternalStore(
subscribe,
getSnapshot,
getServerSnapshot
);
};
react_production.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
react_production.version = "19.0.0";
return react_production;
}
var react_development = {exports: {}};
/**
* @license React
* react.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
react_development.exports;
var hasRequiredReact_development;
function requireReact_development () {
if (hasRequiredReact_development) return react_development.exports;
hasRequiredReact_development = 1;
(function (module, exports) {
"production" !== process.env.NODE_ENV &&
(function () {
function defineDeprecationWarning(methodName, info) {
Object.defineProperty(Component.prototype, methodName, {
get: function () {
console.warn(
"%s(...) is deprecated in plain JavaScript React classes. %s",
info[0],
info[1]
);
}
});
}
function getIteratorFn(maybeIterable) {
if (null === maybeIterable || "object" !== typeof maybeIterable)
return null;
maybeIterable =
(MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) ||
maybeIterable["@@iterator"];
return "function" === typeof maybeIterable ? maybeIterable : null;
}
function warnNoop(publicInstance, callerName) {
publicInstance =
((publicInstance = publicInstance.constructor) &&
(publicInstance.displayName || publicInstance.name)) ||
"ReactClass";
var warningKey = publicInstance + "." + callerName;
didWarnStateUpdateForUnmountedComponent[warningKey] ||
(console.error(
"Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.",
callerName,
publicInstance
),
(didWarnStateUpdateForUnmountedComponent[warningKey] = true));
}
function Component(props, context, updater) {
this.props = props;
this.context = context;
this.refs = emptyObject;
this.updater = updater || ReactNoopUpdateQueue;
}
function ComponentDummy() {}
function PureComponent(props, context, updater) {
this.props = props;
this.context = context;
this.refs = emptyObject;
this.updater = updater || ReactNoopUpdateQueue;
}
function testStringCoercion(value) {
return "" + value;
}
function checkKeyStringCoercion(value) {
try {
testStringCoercion(value);
var JSCompiler_inline_result = !1;
} catch (e) {
JSCompiler_inline_result = true;
}
if (JSCompiler_inline_result) {
JSCompiler_inline_result = console;
var JSCompiler_temp_const = JSCompiler_inline_result.error;
var JSCompiler_inline_result$jscomp$0 =
("function" === typeof Symbol &&
Symbol.toStringTag &&
value[Symbol.toStringTag]) ||
value.constructor.name ||
"Object";
JSCompiler_temp_const.call(
JSCompiler_inline_result,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
JSCompiler_inline_result$jscomp$0
);
return testStringCoercion(value);
}
}
function getComponentNameFromType(type) {
if (null == type) return null;
if ("function" === typeof type)
return type.$$typeof === REACT_CLIENT_REFERENCE$2
? null
: type.displayName || type.name || null;
if ("string" === typeof type) return type;
switch (type) {
case REACT_FRAGMENT_TYPE:
return "Fragment";
case REACT_PORTAL_TYPE:
return "Portal";
case REACT_PROFILER_TYPE:
return "Profiler";
case REACT_STRICT_MODE_TYPE:
return "StrictMode";
case REACT_SUSPENSE_TYPE:
return "Suspense";
case REACT_SUSPENSE_LIST_TYPE:
return "SuspenseList";
}
if ("object" === typeof type)
switch (
("number" === typeof type.tag &&
console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
),
type.$$typeof)
) {
case REACT_CONTEXT_TYPE:
return (type.displayName || "Context") + ".Provider";
case REACT_CONSUMER_TYPE:
return (type._context.displayName || "Context") + ".Consumer";
case REACT_FORWARD_REF_TYPE:
var innerType = type.render;
type = type.displayName;
type ||
((type = innerType.displayName || innerType.name || ""),
(type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef"));
return type;
case REACT_MEMO_TYPE:
return (
(innerType = type.displayName || null),
null !== innerType
? innerType
: getComponentNameFromType(type.type) || "Memo"
);
case REACT_LAZY_TYPE:
innerType = type._payload;
type = type._init;
try {
return getComponentNameFromType(type(innerType));
} catch (x) {}
}
return null;
}
function isValidElementType(type) {
return "string" === typeof type ||
"function" === typeof type ||
type === REACT_FRAGMENT_TYPE ||
type === REACT_PROFILER_TYPE ||
type === REACT_STRICT_MODE_TYPE ||
type === REACT_SUSPENSE_TYPE ||
type === REACT_SUSPENSE_LIST_TYPE ||
type === REACT_OFFSCREEN_TYPE ||
("object" === typeof type &&
null !== type &&
(type.$$typeof === REACT_LAZY_TYPE ||
type.$$typeof === REACT_MEMO_TYPE ||
type.$$typeof === REACT_CONTEXT_TYPE ||
type.$$typeof === REACT_CONSUMER_TYPE ||
type.$$typeof === REACT_FORWARD_REF_TYPE ||
type.$$typeof === REACT_CLIENT_REFERENCE$1 ||
undefined !== type.getModuleId))
? true
: false;
}
function disabledLog() {}
function disableLogs() {
if (0 === disabledDepth) {
prevLog = console.log;
prevInfo = console.info;
prevWarn = console.warn;
prevError = console.error;
prevGroup = console.group;
prevGroupCollapsed = console.groupCollapsed;
prevGroupEnd = console.groupEnd;
var props = {
configurable: true,
enumerable: true,
value: disabledLog,
writable: true
};
Object.defineProperties(console, {
info: props,
log: props,
warn: props,
error: props,
group: props,
groupCollapsed: props,
groupEnd: props
});
}
disabledDepth++;
}
function reenableLogs() {
disabledDepth--;
if (0 === disabledDepth) {
var props = { configurable: true, enumerable: true, writable: true };
Object.defineProperties(console, {
log: assign({}, props, { value: prevLog }),
info: assign({}, props, { value: prevInfo }),
warn: assign({}, props, { value: prevWarn }),
error: assign({}, props, { value: prevError }),
group: assign({}, props, { value: prevGroup }),
groupCollapsed: assign({}, props, { value: prevGroupCollapsed }),
groupEnd: assign({}, props, { value: prevGroupEnd })
});
}
0 > disabledDepth &&
console.error(
"disabledDepth fell below zero. This is a bug in React. Please file an issue."
);
}
function describeBuiltInComponentFrame(name) {
if (undefined === prefix)
try {
throw Error();
} catch (x) {
var match = x.stack.trim().match(/\n( *(at )?)/);
prefix = (match && match[1]) || "";
suffix =
-1 < x.stack.indexOf("\n at")
? " (<anonymous>)"
: -1 < x.stack.indexOf("@")
? "@unknown:0:0"
: "";
}
return "\n" + prefix + name + suffix;
}
function describeNativeComponentFrame(fn, construct) {
if (!fn || reentry) return "";
var frame = componentFrameCache.get(fn);
if (undefined !== frame) return frame;
reentry = true;
frame = Error.prepareStackTrace;
Error.prepareStackTrace = undefined;
var previousDispatcher = null;
previousDispatcher = ReactSharedInternals.H;
ReactSharedInternals.H = null;
disableLogs();
try {
var RunInRootFrame = {
DetermineComponentFrameRoot: function () {
try {
if (construct) {
var Fake = function () {
throw Error();
};
Object.defineProperty(Fake.prototype, "props", {
set: function () {
throw Error();
}
});
if ("object" === typeof Reflect && Reflect.construct) {
try {
Reflect.construct(Fake, []);
} catch (x) {
var control = x;
}
Reflect.construct(fn, [], Fake);
} else {
try {
Fake.call();
} catch (x$0) {
control = x$0;
}
fn.call(Fake.prototype);
}
} else {
try {
throw Error();
} catch (x$1) {
control = x$1;
}
(Fake = fn()) &&
"function" === typeof Fake.catch &&
Fake.catch(function () {});
}
} catch (sample) {
if (sample && control && "string" === typeof sample.stack)
return [sample.stack, control.stack];
}
return [null, null];
}
};
RunInRootFrame.DetermineComponentFrameRoot.displayName =
"DetermineComponentFrameRoot";
var namePropDescriptor = Object.getOwnPropertyDescriptor(
RunInRootFrame.DetermineComponentFrameRoot,
"name"
);
namePropDescriptor &&
namePropDescriptor.configurable &&
Object.defineProperty(
RunInRootFrame.DetermineComponentFrameRoot,
"name",
{ value: "DetermineComponentFrameRoot" }
);
var _RunInRootFrame$Deter =
RunInRootFrame.DetermineComponentFrameRoot(),
sampleStack = _RunInRootFrame$Deter[0],
controlStack = _RunInRootFrame$Deter[1];
if (sampleStack && controlStack) {
var sampleLines = sampleStack.split("\n"),
controlLines = controlStack.split("\n");
for (
_RunInRootFrame$Deter = namePropDescriptor = 0;
namePropDescriptor < sampleLines.length &&
!sampleLines[namePropDescriptor].includes(
"DetermineComponentFrameRoot"
);
)
namePropDescriptor++;
for (
;
_RunInRootFrame$Deter < controlLines.length &&
!controlLines[_RunInRootFrame$Deter].includes(
"DetermineComponentFrameRoot"
);
)
_RunInRootFrame$Deter++;
if (
namePropDescriptor === sampleLines.length ||
_RunInRootFrame$Deter === controlLines.length
)
for (
namePropDescriptor = sampleLines.length - 1,
_RunInRootFrame$Deter = controlLines.length - 1;
1 <= namePropDescriptor &&
0 <= _RunInRootFrame$Deter &&
sampleLines[namePropDescriptor] !==
controlLines[_RunInRootFrame$Deter];
)
_RunInRootFrame$Deter--;
for (
;
1 <= namePropDescriptor && 0 <= _RunInRootFrame$Deter;
namePropDescriptor--, _RunInRootFrame$Deter--
)
if (
sampleLines[namePropDescriptor] !==
controlLines[_RunInRootFrame$Deter]
) {
if (1 !== namePropDescriptor || 1 !== _RunInRootFrame$Deter) {
do
if (
(namePropDescriptor--,
_RunInRootFrame$Deter--,
0 > _RunInRootFrame$Deter ||
sampleLines[namePropDescriptor] !==
controlLines[_RunInRootFrame$Deter])
) {
var _frame =
"\n" +
sampleLines[namePropDescriptor].replace(
" at new ",
" at "
);
fn.displayName &&
_frame.includes("<anonymous>") &&
(_frame = _frame.replace("<anonymous>", fn.displayName));
"function" === typeof fn &&
componentFrameCache.set(fn, _frame);
return _frame;
}
while (1 <= namePropDescriptor && 0 <= _RunInRootFrame$Deter);
}
break;
}
}
} finally {
(reentry = false),
(ReactSharedInternals.H = previousDispatcher),
reenableLogs(),
(Error.prepareStackTrace = frame);
}
sampleLines = (sampleLines = fn ? fn.displayName || fn.name : "")
? describeBuiltInComponentFrame(sampleLines)
: "";
"function" === typeof fn && componentFrameCache.set(fn, sampleLines);
return sampleLines;
}
function describeUnknownElementTypeFrameInDEV(type) {
if (null == type) return "";
if ("function" === typeof type) {
var prototype = type.prototype;
return describeNativeComponentFrame(
type,
!(!prototype || !prototype.isReactComponent)
);
}
if ("string" === typeof type) return describeBuiltInComponentFrame(type);
switch (type) {
case REACT_SUSPENSE_TYPE:
return describeBuiltInComponentFrame("Suspense");
case REACT_SUSPENSE_LIST_TYPE:
return describeBuiltInComponentFrame("SuspenseList");
}
if ("object" === typeof type)
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE:
return (type = describeNativeComponentFrame(type.render, false)), type;
case REACT_MEMO_TYPE:
return describeUnknownElementTypeFrameInDEV(type.type);
case REACT_LAZY_TYPE:
prototype = type._payload;
type = type._init;
try {
return describeUnknownElementTypeFrameInDEV(type(prototype));
} catch (x) {}
}
return "";
}
function getOwner() {
var dispatcher = ReactSharedInternals.A;
return null === dispatcher ? null : dispatcher.getOwner();
}
function hasValidKey(config) {
if (hasOwnProperty.call(config, "key")) {
var getter = Object.getOwnPropertyDescriptor(config, "key").get;
if (getter && getter.isReactWarning) return false;
}
return undefined !== config.key;
}
function defineKeyPropWarningGetter(props, displayName) {
function warnAboutAccessingKey() {
specialPropKeyWarningShown ||
((specialPropKeyWarningShown = true),
console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
displayName
));
}
warnAboutAccessingKey.isReactWarning = true;
Object.defineProperty(props, "key", {
get: warnAboutAccessingKey,
configurable: true
});
}
function elementRefGetterWithDeprecationWarning() {
var componentName = getComponentNameFromType(this.type);
didWarnAboutElementRef[componentName] ||
((didWarnAboutElementRef[componentName] = true),
console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
));
componentName = this.props.ref;
return undefined !== componentName ? componentName : null;
}
function ReactElement(type, key, self, source, owner, props) {
self = props.ref;
type = {
$$typeof: REACT_ELEMENT_TYPE,
type: type,
key: key,
props: props,
_owner: owner
};
null !== (undefined !== self ? self : null)
? Object.defineProperty(type, "ref", {
enumerable: false,
get: elementRefGetterWithDeprecationWarning
})
: Object.defineProperty(type, "ref", { enumerable: false, value: null });
type._store = {};
Object.defineProperty(type._store, "validated", {
configurable: false,
enumerable: false,
writable: true,
value: 0
});
Object.defineProperty(type, "_debugInfo", {
configurable: false,
enumerable: false,
writable: true,
value: null
});
Object.freeze && (Object.freeze(type.props), Object.freeze(type));
return type;
}
function cloneAndReplaceKey(oldElement, newKey) {
newKey = ReactElement(
oldElement.type,
newKey,
undefined,
undefined,
oldElement._owner,
oldElement.props
);
newKey._store.validated = oldElement._store.validated;
return newKey;
}
function validateChildKeys(node, parentType) {
if (
"object" === typeof node &&
node &&
node.$$typeof !== REACT_CLIENT_REFERENCE
)
if (isArrayImpl(node))
for (var i = 0; i < node.length; i++) {
var child = node[i];
isValidElement(child) && validateExplicitKey(child, parentType);
}
else if (isValidElement(node))
node._store && (node._store.validated = 1);
else if (
((i = getIteratorFn(node)),
"function" === typeof i &&
i !== node.entries &&
((i = i.call(node)), i !== node))
)
for (; !(node = i.next()).done; )
isValidElement(node.value) &&
validateExplicitKey(node.value, parentType);
}
function isValidElement(object) {
return (
"object" === typeof object &&
null !== object &&
object.$$typeof === REACT_ELEMENT_TYPE
);
}
function validateExplicitKey(element, parentType) {
if (
element._store &&
!element._store.validated &&
null == element.key &&
((element._store.validated = 1),
(parentType = getCurrentComponentErrorInfo(parentType)),
!ownerHasKeyUseWarning[parentType])
) {
ownerHasKeyUseWarning[parentType] = true;
var childOwner = "";
element &&
null != element._owner &&
element._owner !== getOwner() &&
((childOwner = null),
"number" === typeof element._owner.tag
? (childOwner = getComponentNameFromType(element._owner.type))
: "string" === typeof element._owner.name &&
(childOwner = element._owner.name),
(childOwner = " It was passed a child from " + childOwner + "."));
var prevGetCurrentStack = ReactSharedInternals.getCurrentStack;
ReactSharedInternals.getCurrentStack = function () {
var stack = describeUnknownElementTypeFrameInDEV(element.type);
prevGetCurrentStack && (stack += prevGetCurrentStack() || "");
return stack;
};
console.error(
'Each child in a list should have a unique "key" prop.%s%s See https://react.dev/link/warning-keys for more information.',
parentType,
childOwner
);
ReactSharedInternals.getCurrentStack = prevGetCurrentStack;
}
}
function getCurrentComponentErrorInfo(parentType) {
var info = "",
owner = getOwner();
owner &&
(owner = getComponentNameFromType(owner.type)) &&
(info = "\n\nCheck the render method of `" + owner + "`.");
info ||
((parentType = getComponentNameFromType(parentType)) &&
(info =
"\n\nCheck the top-level render call using <" + parentType + ">."));
return info;
}
function escape(key) {
var escaperLookup = { "=": "=0", ":": "=2" };
return (
"$" +
key.replace(/[=:]/g, function (match) {
return escaperLookup[match];
})
);
}
function getElementKey(element, index) {
return "object" === typeof element &&
null !== element &&
null != element.key
? (checkKeyStringCoercion(element.key), escape("" + element.key))
: index.toString(36);
}
function noop$1() {}
function resolveThenable(thenable) {
switch (thenable.status) {
case "fulfilled":
return thenable.value;
case "rejected":
throw thenable.reason;
default:
switch (
("string" === typeof thenable.status
? thenable.then(noop$1, noop$1)
: ((thenable.status = "pending"),
thenable.then(
function (fulfilledValue) {
"pending" === thenable.status &&
((thenable.status = "fulfilled"),
(thenable.value = fulfilledValue));
},
function (error) {
"pending" === thenable.status &&
((thenable.status = "rejected"),
(thenable.reason = error));
}
)),
thenable.status)
) {
case "fulfilled":
return thenable.value;
case "rejected":
throw thenable.reason;
}
}
throw thenable;
}
function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
var type = typeof children;
if ("undefined" === type || "boolean" === type) children = null;
var invokeCallback = false;
if (null === children) invokeCallback = true;
else
switch (type) {
case "bigint":
case "string":
case "number":
invokeCallback = true;
break;
case "object":
switch (children.$$typeof) {
case REACT_ELEMENT_TYPE:
case REACT_PORTAL_TYPE:
invokeCallback = true;
break;
case REACT_LAZY_TYPE:
return (
(invokeCallback = children._init),
mapIntoArray(
invokeCallback(children._payload),
array,
escapedPrefix,
nameSoFar,
callback
)
);
}
}
if (invokeCallback) {
invokeCallback = children;
callback = callback(invokeCallback);
var childKey =
"" === nameSoFar ? "." + getElementKey(invokeCallback, 0) : nameSoFar;
isArrayImpl(callback)
? ((escapedPrefix = ""),
null != childKey &&
(escapedPrefix =
childKey.replace(userProvidedKeyEscapeRegex, "$&/") + "/"),
mapIntoArray(callback, array, escapedPrefix, "", function (c) {
return c;
}))
: null != callback &&
(isValidElement(callback) &&
(null != callback.key &&
((invokeCallback && invokeCallback.key === callback.key) ||
checkKeyStringCoercion(callback.key)),
(escapedPrefix = cloneAndReplaceKey(
callback,
escapedPrefix +
(null == callback.key ||
(invokeCallback && invokeCallback.key === callback.key)
? ""
: ("" + callback.key).replace(
userProvidedKeyEscapeRegex,
"$&/"
) + "/") +
childKey
)),
"" !== nameSoFar &&
null != invokeCallback &&
isValidElement(invokeCallback) &&
null == invokeCallback.key &&
invokeCallback._store &&
!invokeCallback._store.validated &&
(escapedPrefix._store.validated = 2),
(callback = escapedPrefix)),
array.push(callback));
return 1;
}
invokeCallback = 0;
childKey = "" === nameSoFar ? "." : nameSoFar + ":";
if (isArrayImpl(children))
for (var i = 0; i < children.length; i++)
(nameSoFar = children[i]),
(type = childKey + getElementKey(nameSoFar, i)),
(invokeCallback += mapIntoArray(
nameSoFar,
array,
escapedPrefix,
type,
callback
));
else if (((i = getIteratorFn(children)), "function" === typeof i))
for (
i === children.entries &&
(didWarnAboutMaps ||
console.warn(
"Using Maps as children is not supported. Use an array of keyed ReactElements instead."
),
(didWarnAboutMaps = true)),
children = i.call(children),
i = 0;
!(nameSoFar = children.next()).done;
)
(nameSoFar = nameSoFar.value),
(type = childKey + getElementKey(nameSoFar, i++)),
(invokeCallback += mapIntoArray(
nameSoFar,
array,
escapedPrefix,
type,
callback
));
else if ("object" === type) {
if ("function" === typeof children.then)
return mapIntoArray(
resolveThenable(children),
array,
escapedPrefix,
nameSoFar,
callback
);
array = String(children);
throw Error(
"Objects are not valid as a React child (found: " +
("[object Object]" === array
? "object with keys {" + Object.keys(children).join(", ") + "}"
: array) +
"). If you meant to render a collection of children, use an array instead."
);
}
return invokeCallback;
}
function mapChildren(children, func, context) {
if (null == children) return children;
var result = [],
count = 0;
mapIntoArray(children, result, "", "", function (child) {
return func.call(context, child, count++);
});
return result;
}
function lazyInitializer(payload) {
if (-1 === payload._status) {
var ctor = payload._result;
ctor = ctor();
ctor.then(
function (moduleObject) {
if (0 === payload._status || -1 === payload._status)
(payload._status = 1), (payload._result = moduleObject);
},
function (error) {
if (0 === payload._status || -1 === payload._status)
(payload._status = 2), (payload._result = error);
}
);
-1 === payload._status &&
((payload._status = 0), (payload._result = ctor));
}
if (1 === payload._status)
return (
(ctor = payload._result),
undefined === ctor &&
console.error(
"lazy: Expected the result of a dynamic import() call. Instead received: %s\n\nYour code should look like: \n const MyComponent = lazy(() => import('./MyComponent'))\n\nDid you accidentally put curly braces around the import?",
ctor
),
"default" in ctor ||
console.error(
"lazy: Expected the result of a dynamic import() call. Instead received: %s\n\nYour code should look like: \n const MyComponent = lazy(() => import('./MyComponent'))",
ctor
),
ctor.default
);
throw payload._result;
}
function resolveDispatcher() {
var dispatcher = ReactSharedInternals.H;
null === dispatcher &&
console.error(
"Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem."
);
return dispatcher;
}
function noop() {}
function enqueueTask(task) {
if (null === enqueueTaskImpl)
try {
var requireString = ("require" + Math.random()).slice(0, 7);
enqueueTaskImpl = (module && module[requireString]).call(
module,
"timers"
).setImmediate;
} catch (_err) {
enqueueTaskImpl = function (callback) {
false === didWarnAboutMessageChannel &&
((didWarnAboutMessageChannel = true),
"undefined" === typeof MessageChannel &&
console.error(
"This browser does not have a MessageChannel implementation, so enqueuing tasks via await act(async () => ...) will fail. Please file an issue at https://github.com/facebook/react/issues if you encounter this warning."
));
var channel = new MessageChannel();
channel.port1.onmessage = callback;
channel.port2.postMessage(undefined);
};
}
return enqueueTaskImpl(task);
}
function aggregateErrors(errors) {
return 1 < errors.length && "function" === typeof AggregateError
? new AggregateError(errors)
: errors[0];
}
function popActScope(prevActQueue, prevActScopeDepth) {
prevActScopeDepth !== actScopeDepth - 1 &&
console.error(
"You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one. "
);
actScopeDepth = prevActScopeDepth;
}
function recursivelyFlushAsyncActWork(returnValue, resolve, reject) {
var queue = ReactSharedInternals.actQueue;
if (null !== queue)
if (0 !== queue.length)
try {
flushActQueue(queue);
enqueueTask(function () {
return recursivelyFlushAsyncActWork(returnValue, resolve, reject);
});
return;
} catch (error) {
ReactSharedInternals.thrownErrors.push(error);
}
else ReactSharedInternals.actQueue = null;
0 < ReactSharedInternals.thrownErrors.length
? ((queue = aggregateErrors(ReactSharedInternals.thrownErrors)),
(ReactSharedInternals.thrownErrors.length = 0),
reject(queue))
: resolve(returnValue);
}
function flushActQueue(queue) {
if (!isFlushing) {
isFlushing = true;
var i = 0;
try {
for (; i < queue.length; i++) {
var callback = queue[i];
do {
ReactSharedInternals.didUsePromise = !1;
var continuation = callback(!1);
if (null !== continuation) {
if (ReactSharedInternals.didUsePromise) {
queue[i] = callback;
queue.splice(0, i);
return;
}
callback = continuation;
} else break;
} while (1);
}
queue.length = 0;
} catch (error) {
queue.splice(0, i + 1), ReactSharedInternals.thrownErrors.push(error);
} finally {
isFlushing = false;
}
}
}
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
REACT_PROFILER_TYPE = Symbol.for("react.profiler");
var REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
REACT_CONTEXT_TYPE = Symbol.for("react.context"),
REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"),
REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"),
REACT_MEMO_TYPE = Symbol.for("react.memo"),
REACT_LAZY_TYPE = Symbol.for("react.lazy"),
REACT_OFFSCREEN_TYPE = Symbol.for("react.offscreen"),
MAYBE_ITERATOR_SYMBOL = Symbol.iterator,
didWarnStateUpdateForUnmountedComponent = {},
ReactNoopUpdateQueue = {
isMounted: function () {
return false;
},
enqueueForceUpdate: function (publicInstance) {
warnNoop(publicInstance, "forceUpdate");
},
enqueueReplaceState: function (publicInstance) {
warnNoop(publicInstance, "replaceState");
},
enqueueSetState: function (publicInstance) {
warnNoop(publicInstance, "setState");
}
},
assign = Object.assign,
emptyObject = {};
Object.freeze(emptyObject);
Component.prototype.isReactComponent = {};
Component.prototype.setState = function (partialState, callback) {
if (
"object" !== typeof partialState &&
"function" !== typeof partialState &&
null != partialState
)
throw Error(
"takes an object of state variables to update or a function which returns an object of state variables."
);
this.updater.enqueueSetState(this, partialState, callback, "setState");
};
Component.prototype.forceUpdate = function (callback) {
this.updater.enqueueForceUpdate(this, callback, "forceUpdate");
};
var deprecatedAPIs = {
isMounted: [
"isMounted",
"Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."
],
replaceState: [
"replaceState",
"Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."
]
},
fnName;
for (fnName in deprecatedAPIs)
deprecatedAPIs.hasOwnProperty(fnName) &&
defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
ComponentDummy.prototype = Component.prototype;
deprecatedAPIs = PureComponent.prototype = new ComponentDummy();
deprecatedAPIs.constructor = PureComponent;
assign(deprecatedAPIs, Component.prototype);
deprecatedAPIs.isPureReactComponent = true;
var isArrayImpl = Array.isArray,
REACT_CLIENT_REFERENCE$2 = Symbol.for("react.client.reference"),
ReactSharedInternals = {
H: null,
A: null,
T: null,
S: null,
actQueue: null,
isBatchingLegacy: false,
didScheduleLegacyUpdate: false,
didUsePromise: false,
thrownErrors: [],
getCurrentStack: null
},
hasOwnProperty = Object.prototype.hasOwnProperty,
REACT_CLIENT_REFERENCE$1 = Symbol.for("react.client.reference"),
disabledDepth = 0,
prevLog,
prevInfo,
prevWarn,
prevError,
prevGroup,
prevGroupCollapsed,
prevGroupEnd;
disabledLog.__reactDisabledLog = true;
var prefix,
suffix,
reentry = false;
var componentFrameCache = new (
"function" === typeof WeakMap ? WeakMap : Map
)();
var REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
specialPropKeyWarningShown,
didWarnAboutOldJSXRuntime;
var didWarnAboutElementRef = {};
var ownerHasKeyUseWarning = {},
didWarnAboutMaps = false,
userProvidedKeyEscapeRegex = /\/+/g,
reportGlobalError =
"function" === typeof reportError
? reportError
: function (error) {
if (
"object" === typeof window &&
"function" === typeof window.ErrorEvent
) {
var event = new window.ErrorEvent("error", {
bubbles: true,
cancelable: true,
message:
"object" === typeof error &&
null !== error &&
"string" === typeof error.message
? String(error.message)
: String(error),
error: error
});
if (!window.dispatchEvent(event)) return;
} else if (
"object" === typeof process &&
"function" === typeof process.emit
) {
process.emit("uncaughtException", error);
return;
}
console.error(error);
},
didWarnAboutMessageChannel = false,
enqueueTaskImpl = null,
actScopeDepth = 0,
didWarnNoAwaitAct = false,
isFlushing = false,
queueSeveralMicrotasks =
"function" === typeof queueMicrotask
? function (callback) {
queueMicrotask(function () {
return queueMicrotask(callback);
});
}
: enqueueTask;
exports.Children = {
map: mapChildren,
forEach: function (children, forEachFunc, forEachContext) {
mapChildren(
children,
function () {
forEachFunc.apply(this, arguments);
},
forEachContext
);
},
count: function (children) {
var n = 0;
mapChildren(children, function () {
n++;
});
return n;
},
toArray: function (children) {
return (
mapChildren(children, function (child) {
return child;
}) || []
);
},
only: function (children) {
if (!isValidElement(children))
throw Error(
"React.Children.only expected to receive a single React element child."
);
return children;
}
};
exports.Component = Component;
exports.Fragment = REACT_FRAGMENT_TYPE;
exports.Profiler = REACT_PROFILER_TYPE;
exports.PureComponent = PureComponent;
exports.StrictMode = REACT_STRICT_MODE_TYPE;
exports.Suspense = REACT_SUSPENSE_TYPE;
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE =
ReactSharedInternals;
exports.act = function (callback) {
var prevActQueue = ReactSharedInternals.actQueue,
prevActScopeDepth = actScopeDepth;
actScopeDepth++;
var queue = (ReactSharedInternals.actQueue =
null !== prevActQueue ? prevActQueue : []),
didAwaitActCall = false;
try {
var result = callback();
} catch (error) {
ReactSharedInternals.thrownErrors.push(error);
}
if (0 < ReactSharedInternals.thrownErrors.length)
throw (
(popActScope(prevActQueue, prevActScopeDepth),
(callback = aggregateErrors(ReactSharedInternals.thrownErrors)),
(ReactSharedInternals.thrownErrors.length = 0),
callback)
);
if (
null !== result &&
"object" === typeof result &&
"function" === typeof result.then
) {
var thenable = result;
queueSeveralMicrotasks(function () {
didAwaitActCall ||
didWarnNoAwaitAct ||
((didWarnNoAwaitAct = true),
console.error(
"You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);"
));
});
return {
then: function (resolve, reject) {
didAwaitActCall = true;
thenable.then(
function (returnValue) {
popActScope(prevActQueue, prevActScopeDepth);
if (0 === prevActScopeDepth) {
try {
flushActQueue(queue),
enqueueTask(function () {
return recursivelyFlushAsyncActWork(
returnValue,
resolve,
reject
);
});
} catch (error$2) {
ReactSharedInternals.thrownErrors.push(error$2);
}
if (0 < ReactSharedInternals.thrownErrors.length) {
var _thrownError = aggregateErrors(
ReactSharedInternals.thrownErrors
);
ReactSharedInternals.thrownErrors.length = 0;
reject(_thrownError);
}
} else resolve(returnValue);
},
function (error) {
popActScope(prevActQueue, prevActScopeDepth);
0 < ReactSharedInternals.thrownErrors.length
? ((error = aggregateErrors(
ReactSharedInternals.thrownErrors
)),
(ReactSharedInternals.thrownErrors.length = 0),
reject(error))
: reject(error);
}
);
}
};
}
var returnValue$jscomp$0 = result;
popActScope(prevActQueue, prevActScopeDepth);
0 === prevActScopeDepth &&
(flushActQueue(queue),
0 !== queue.length &&
queueSeveralMicrotasks(function () {
didAwaitActCall ||
didWarnNoAwaitAct ||
((didWarnNoAwaitAct = true),
console.error(
"A component suspended inside an `act` scope, but the `act` call was not awaited. When testing React components that depend on asynchronous data, you must await the result:\n\nawait act(() => ...)"
));
}),
(ReactSharedInternals.actQueue = null));
if (0 < ReactSharedInternals.thrownErrors.length)
throw (
((callback = aggregateErrors(ReactSharedInternals.thrownErrors)),
(ReactSharedInternals.thrownErrors.length = 0),
callback)
);
return {
then: function (resolve, reject) {
didAwaitActCall = true;
0 === prevActScopeDepth
? ((ReactSharedInternals.actQueue = queue),
enqueueTask(function () {
return recursivelyFlushAsyncActWork(
returnValue$jscomp$0,
resolve,
reject
);
}))
: resolve(returnValue$jscomp$0);
}
};
};
exports.cache = function (fn) {
return function () {
return fn.apply(null, arguments);
};
};
exports.cloneElement = function (element, config, children) {
if (null === element || undefined === element)
throw Error(
"The argument must be a React element, but you passed " +
element +
"."
);
var props = assign({}, element.props),
key = element.key,
owner = element._owner;
if (null != config) {
var JSCompiler_inline_result;
a: {
if (
hasOwnProperty.call(config, "ref") &&
(JSCompiler_inline_result = Object.getOwnPropertyDescriptor(
config,
"ref"
).get) &&
JSCompiler_inline_result.isReactWarning
) {
JSCompiler_inline_result = false;
break a;
}
JSCompiler_inline_result = undefined !== config.ref;
}
JSCompiler_inline_result && (owner = getOwner());
hasValidKey(config) &&
(checkKeyStringCoercion(config.key), (key = "" + config.key));
for (propName in config)
!hasOwnProperty.call(config, propName) ||
"key" === propName ||
"__self" === propName ||
"__source" === propName ||
("ref" === propName && undefined === config.ref) ||
(props[propName] = config[propName]);
}
var propName = arguments.length - 2;
if (1 === propName) props.children = children;
else if (1 < propName) {
JSCompiler_inline_result = Array(propName);
for (var i = 0; i < propName; i++)
JSCompiler_inline_result[i] = arguments[i + 2];
props.children = JSCompiler_inline_result;
}
props = ReactElement(element.type, key, undefined, undefined, owner, props);
for (key = 2; key < arguments.length; key++)
validateChildKeys(arguments[key], props.type);
return props;
};
exports.createContext = function (defaultValue) {
defaultValue = {
$$typeof: REACT_CONTEXT_TYPE,
_currentValue: defaultValue,
_currentValue2: defaultValue,
_threadCount: 0,
Provider: null,
Consumer: null
};
defaultValue.Provider = defaultValue;
defaultValue.Consumer = {
$$typeof: REACT_CONSUMER_TYPE,
_context: defaultValue
};
defaultValue._currentRenderer = null;
defaultValue._currentRenderer2 = null;
return defaultValue;
};
exports.createElement = function (type, config, children) {
if (isValidElementType(type))
for (var i = 2; i < arguments.length; i++)
validateChildKeys(arguments[i], type);
else {
i = "";
if (
undefined === type ||
("object" === typeof type &&
null !== type &&
0 === Object.keys(type).length)
)
i +=
" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.";
if (null === type) var typeString = "null";
else
isArrayImpl(type)
? (typeString = "array")
: undefined !== type && type.$$typeof === REACT_ELEMENT_TYPE
? ((typeString =
"<" +
(getComponentNameFromType(type.type) || "Unknown") +
" />"),
(i =
" Did you accidentally export a JSX literal instead of a component?"))
: (typeString = typeof type);
console.error(
"React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",
typeString,
i
);
}
var propName;
i = {};
typeString = null;
if (null != config)
for (propName in (didWarnAboutOldJSXRuntime ||
!("__self" in config) ||
"key" in config ||
((didWarnAboutOldJSXRuntime = true),
console.warn(
"Your app (or one of its dependencies) is using an outdated JSX transform. Update to the modern JSX transform for faster performance: https://react.dev/link/new-jsx-transform"
)),
hasValidKey(config) &&
(checkKeyStringCoercion(config.key), (typeString = "" + config.key)),
config))
hasOwnProperty.call(config, propName) &&
"key" !== propName &&
"__self" !== propName &&
"__source" !== propName &&
(i[propName] = config[propName]);
var childrenLength = arguments.length - 2;
if (1 === childrenLength) i.children = children;
else if (1 < childrenLength) {
for (
var childArray = Array(childrenLength), _i = 0;
_i < childrenLength;
_i++
)
childArray[_i] = arguments[_i + 2];
Object.freeze && Object.freeze(childArray);
i.children = childArray;
}
if (type && type.defaultProps)
for (propName in ((childrenLength = type.defaultProps), childrenLength))
undefined === i[propName] && (i[propName] = childrenLength[propName]);
typeString &&
defineKeyPropWarningGetter(
i,
"function" === typeof type
? type.displayName || type.name || "Unknown"
: type
);
return ReactElement(type, typeString, undefined, undefined, getOwner(), i);
};
exports.createRef = function () {
var refObject = { current: null };
Object.seal(refObject);
return refObject;
};
exports.forwardRef = function (render) {
null != render && render.$$typeof === REACT_MEMO_TYPE
? console.error(
"forwardRef requires a render function but received a `memo` component. Instead of forwardRef(memo(...)), use memo(forwardRef(...))."
)
: "function" !== typeof render
? console.error(
"forwardRef requires a render function but was given %s.",
null === render ? "null" : typeof render
)
: 0 !== render.length &&
2 !== render.length &&
console.error(
"forwardRef render functions accept exactly two parameters: props and ref. %s",
1 === render.length
? "Did you forget to use the ref parameter?"
: "Any additional parameter will be undefined."
);
null != render &&
null != render.defaultProps &&
console.error(
"forwardRef render functions do not support defaultProps. Did you accidentally pass a React component?"
);
var elementType = { $$typeof: REACT_FORWARD_REF_TYPE, render: render },
ownName;
Object.defineProperty(elementType, "displayName", {
enumerable: false,
configurable: true,
get: function () {
return ownName;
},
set: function (name) {
ownName = name;
render.name ||
render.displayName ||
(Object.defineProperty(render, "name", { value: name }),
(render.displayName = name));
}
});
return elementType;
};
exports.isValidElement = isValidElement;
exports.lazy = function (ctor) {
return {
$$typeof: REACT_LAZY_TYPE,
_payload: { _status: -1, _result: ctor },
_init: lazyInitializer
};
};
exports.memo = function (type, compare) {
isValidElementType(type) ||
console.error(
"memo: The first argument must be a component. Instead received: %s",
null === type ? "null" : typeof type
);
compare = {
$$typeof: REACT_MEMO_TYPE,
type: type,
compare: undefined === compare ? null : compare
};
var ownName;
Object.defineProperty(compare, "displayName", {
enumerable: false,
configurable: true,
get: function () {
return ownName;
},
set: function (name) {
ownName = name;
type.name ||
type.displayName ||
(Object.defineProperty(type, "name", { value: name }),
(type.displayName = name));
}
});
return compare;
};
exports.startTransition = function (scope) {
var prevTransition = ReactSharedInternals.T,
currentTransition = {};
ReactSharedInternals.T = currentTransition;
currentTransition._updatedFibers = new Set();
try {
var returnValue = scope(),
onStartTransitionFinish = ReactSharedInternals.S;
null !== onStartTransitionFinish &&
onStartTransitionFinish(currentTransition, returnValue);
"object" === typeof returnValue &&
null !== returnValue &&
"function" === typeof returnValue.then &&
returnValue.then(noop, reportGlobalError);
} catch (error) {
reportGlobalError(error);
} finally {
null === prevTransition &&
currentTransition._updatedFibers &&
((scope = currentTransition._updatedFibers.size),
currentTransition._updatedFibers.clear(),
10 < scope &&
console.warn(
"Detected a large number of updates inside startTransition. If this is due to a subscription please re-write it to use React provided hooks. Otherwise concurrent mode guarantees are off the table."
)),
(ReactSharedInternals.T = prevTransition);
}
};
exports.unstable_useCacheRefresh = function () {
return resolveDispatcher().useCacheRefresh();
};
exports.use = function (usable) {
return resolveDispatcher().use(usable);
};
exports.useActionState = function (action, initialState, permalink) {
return resolveDispatcher().useActionState(
action,
initialState,
permalink
);
};
exports.useCallback = function (callback, deps) {
return resolveDispatcher().useCallback(callback, deps);
};
exports.useContext = function (Context) {
var dispatcher = resolveDispatcher();
Context.$$typeof === REACT_CONSUMER_TYPE &&
console.error(
"Calling useContext(Context.Consumer) is not supported and will cause bugs. Did you mean to call useContext(Context) instead?"
);
return dispatcher.useContext(Context);
};
exports.useDebugValue = function (value, formatterFn) {
return resolveDispatcher().useDebugValue(value, formatterFn);
};
exports.useDeferredValue = function (value, initialValue) {
return resolveDispatcher().useDeferredValue(value, initialValue);
};
exports.useEffect = function (create, deps) {
return resolveDispatcher().useEffect(create, deps);
};
exports.useId = function () {
return resolveDispatcher().useId();
};
exports.useImperativeHandle = function (ref, create, deps) {
return resolveDispatcher().useImperativeHandle(ref, create, deps);
};
exports.useInsertionEffect = function (create, deps) {
return resolveDispatcher().useInsertionEffect(create, deps);
};
exports.useLayoutEffect = function (create, deps) {
return resolveDispatcher().useLayoutEffect(create, deps);
};
exports.useMemo = function (create, deps) {
return resolveDispatcher().useMemo(create, deps);
};
exports.useOptimistic = function (passthrough, reducer) {
return resolveDispatcher().useOptimistic(passthrough, reducer);
};
exports.useReducer = function (reducer, initialArg, init) {
return resolveDispatcher().useReducer(reducer, initialArg, init);
};
exports.useRef = function (initialValue) {
return resolveDispatcher().useRef(initialValue);
};
exports.useState = function (initialState) {
return resolveDispatcher().useState(initialState);
};
exports.useSyncExternalStore = function (
subscribe,
getSnapshot,
getServerSnapshot
) {
return resolveDispatcher().useSyncExternalStore(
subscribe,
getSnapshot,
getServerSnapshot
);
};
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
})();
} (react_development, react_development.exports));
return react_development.exports;
}
var hasRequiredReact;
function requireReact () {
if (hasRequiredReact) return react.exports;
hasRequiredReact = 1;
if (process.env.NODE_ENV === 'production') {
react.exports = requireReact_production();
} else {
react.exports = requireReact_development();
}
return react.exports;
}
var reactExports = requireReact();
var React = /*@__PURE__*/getDefaultExportFromCjs(reactExports);
var FFMessageType;
(function (FFMessageType) {
FFMessageType["LOAD"] = "LOAD";
FFMessageType["EXEC"] = "EXEC";
FFMessageType["FFPROBE"] = "FFPROBE";
FFMessageType["WRITE_FILE"] = "WRITE_FILE";
FFMessageType["READ_FILE"] = "READ_FILE";
FFMessageType["DELETE_FILE"] = "DELETE_FILE";
FFMessageType["RENAME"] = "RENAME";
FFMessageType["CREATE_DIR"] = "CREATE_DIR";
FFMessageType["LIST_DIR"] = "LIST_DIR";
FFMessageType["DELETE_DIR"] = "DELETE_DIR";
FFMessageType["ERROR"] = "ERROR";
FFMessageType["DOWNLOAD"] = "DOWNLOAD";
FFMessageType["PROGRESS"] = "PROGRESS";
FFMessageType["LOG"] = "LOG";
FFMessageType["MOUNT"] = "MOUNT";
FFMessageType["UNMOUNT"] = "UNMOUNT";
})(FFMessageType || (FFMessageType = {}));
/**
* Generate an unique message ID.
*/
const getMessageID = (() => {
let messageID = 0;
return () => messageID++;
})();
const ERROR_NOT_LOADED = new Error("ffmpeg is not loaded, call `await ffmpeg.load()` first");
const ERROR_TERMINATED = new Error("called FFmpeg.terminate()");
/**
* Provides APIs to interact with ffmpeg web worker.
*
* @example
* ```ts
* const ffmpeg = new FFmpeg();
* ```
*/
class FFmpeg {
#worker = null;
/**
* #resolves and #rejects tracks Promise resolves and rejects to
* be called when we receive message from web worker.
*/
#resolves = {};
#rejects = {};
#logEventCallbacks = [];
#progressEventCallbacks = [];
loaded = false;
/**
* register worker message event handlers.
*/
#registerHandlers = () => {
if (this.#worker) {
this.#worker.onmessage = ({ data: { id, type, data }, }) => {
switch (type) {
case FFMessageType.LOAD:
this.loaded = true;
this.#resolves[id](data);
break;
case FFMessageType.MOUNT:
case FFMessageType.UNMOUNT:
case FFMessageType.EXEC:
case FFMessageType.FFPROBE:
case FFMessageType.WRITE_FILE:
case FFMessageType.READ_FILE:
case FFMessageType.DELETE_FILE:
case FFMessageType.RENAME:
case FFMessageType.CREATE_DIR:
case FFMessageType.LIST_DIR:
case FFMessageType.DELETE_DIR:
this.#resolves[id](data);
break;
case FFMessageType.LOG:
this.#logEventCallbacks.forEach((f) => f(data));
break;
case FFMessageType.PROGRESS:
this.#progressEventCallbacks.forEach((f) => f(data));
break;
case FFMessageType.ERROR:
this.#rejects[id](data);
break;
}
delete this.#resolves[id];
delete this.#rejects[id];
};
}
};
/**
* Generic function to send messages to web worker.
*/
#send = ({ type, data }, trans = [], signal) => {
if (!this.#worker) {
return Promise.reject(ERROR_NOT_LOADED);
}
return new Promise((resolve, reject) => {
const id = getMessageID();
this.#worker && this.#worker.postMessage({ id, type, data }, trans);
this.#resolves[id] = resolve;
this.#rejects[id] = reject;
signal?.addEventListener("abort", () => {
reject(new DOMException(`Message # ${id} was aborted`, "AbortError"));
}, { once: true });
});
};
on(event, callback) {
if (event === "log") {
this.#logEventCallbacks.push(callback);
}
else if (event === "progress") {
this.#progressEventCallbacks.push(callback);
}
}
off(event, callback) {
if (event === "log") {
this.#logEventCallbacks = this.#logEventCallbacks.filter((f) => f !== callback);
}
else if (event === "progress") {
this.#progressEventCallbacks = this.#progressEventCallbacks.filter((f) => f !== callback);
}
}
/**
* Loads ffmpeg-core inside web worker. It is required to call this method first
* as it initializes WebAssembly and other essential variables.
*
* @category FFmpeg
* @returns `true` if ffmpeg core is loaded for the first time.
*/
load = ({ classWorkerURL, ...config } = {}, { signal } = {}) => {
if (!this.#worker) {
this.#worker = classWorkerURL ?
new Worker(new URL(classWorkerURL, import.meta.url), {
type: "module",
}) :
// We need to duplicated the code here to enable webpack
// to bundle worekr.js here.
new Worker(new URL("./worker.js", import.meta.url), {
type: "module",
});
this.#registerHandlers();
}
return this.#send({
type: FFMessageType.LOAD,
data: config,
}, undefined, signal);
};
/**
* Execute ffmpeg command.
*
* @remarks
* To avoid common I/O issues, ["-nostdin", "-y"] are prepended to the args
* by default.
*
* @example
* ```ts
* const ffmpeg = new FFmpeg();
* await ffmpeg.load();
* await ffmpeg.writeFile("video.avi", ...);
* // ffmpeg -i video.avi video.mp4
* await ffmpeg.exec(["-i", "video.avi", "video.mp4"]);
* const data = ffmpeg.readFile("video.mp4");
* ```
*
* @returns `0` if no error, `!= 0` if timeout (1) or error.
* @category FFmpeg
*/
exec = (
/** ffmpeg command line args */
args,
/**
* milliseconds to wait before stopping the command execution.
*
* @defaultValue -1
*/
timeout = -1, { signal } = {}) => this.#send({
type: FFMessageType.EXEC,
data: { args, timeout },
}, undefined, signal);
/**
* Execute ffprobe command.
*
* @example
* ```ts
* const ffmpeg = new FFmpeg();
* await ffmpeg.load();
* await ffmpeg.writeFile("video.avi", ...);
* // 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
* await ffmpeg.ffprobe(["-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", "video.avi", "-o", "output.txt"]);
* const data = ffmpeg.readFile("output.txt");
* ```
*
* @returns `0` if no error, `!= 0` if timeout (1) or error.
* @category FFmpeg
*/
ffprobe = (
/** ffprobe command line args */
args,
/**
* milliseconds to wait before stopping the command execution.
*
* @defaultValue -1
*/
timeout = -1, { signal } = {}) => this.#send({
type: FFMessageType.FFPROBE,
data: { args, timeout },
}, undefined, signal);
/**
* Terminate all ongoing API calls and terminate web worker.
* `FFmpeg.load()` must be called again before calling any other APIs.
*
* @category FFmpeg
*/
terminate = () => {
const ids = Object.keys(this.#rejects);
// rejects all incomplete Promises.
for (const id of ids) {
this.#rejects[id](ERROR_TERMINATED);
delete this.#rejects[id];
delete this.#resolves[id];
}
if (this.#worker) {
this.#worker.terminate();
this.#worker = null;
this.loaded = false;
}
};
/**
* Write data to ffmpeg.wasm.
*
* @example
* ```ts
* const ffmpeg = new FFmpeg();
* await ffmpeg.load();
* await ffmpeg.writeFile("video.avi", await fetchFile("../video.avi"));
* await ffmpeg.writeFile("text.txt", "hello world");
* ```
*
* @category File System
*/
writeFile = (path, data, { signal } = {}) => {
const trans = [];
if (data instanceof Uint8Array) {
trans.push(data.buffer);
}
return this.#send({
type: FFMessageType.WRITE_FILE,
data: { path, data },
}, trans, signal);
};
mount = (fsType, options, mountPoint) => {
const trans = [];
return this.#send({
type: FFMessageType.MOUNT,
data: { fsType, options, mountPoint },
}, trans);
};
unmount = (mountPoint) => {
const trans = [];
return this.#send({
type: FFMessageType.UNMOUNT,
data: { mountPoint },
}, trans);
};
/**
* Read data from ffmpeg.wasm.
*
* @example
* ```ts
* const ffmpeg = new FFmpeg();
* await ffmpeg.load();
* const data = await ffmpeg.readFile("video.mp4");
* ```
*
* @category File System
*/
readFile = (path,
/**
* File content encoding, supports two encodings:
* - utf8: read file as text file, return data in string type.
* - binary: read file as binary file, return data in Uint8Array type.
*
* @defaultValue binary
*/
encoding = "binary", { signal } = {}) => this.#send({
type: FFMessageType.READ_FILE,
data: { path, encoding },
}, undefined, signal);
/**
* Delete a file.
*
* @category File System
*/
deleteFile = (path, { signal } = {}) => this.#send({
type: FFMessageType.DELETE_FILE,
data: { path },
}, undefined, signal);
/**
* Rename a file or directory.
*
* @category File System
*/
rename = (oldPath, newPath, { signal } = {}) => this.#send({
type: FFMessageType.RENAME,
data: { oldPath, newPath },
}, undefined, signal);
/**
* Create a directory.
*
* @category File System
*/
createDir = (path, { signal } = {}) => this.#send({
type: FFMessageType.CREATE_DIR,
data: { path },
}, undefined, signal);
/**
* List directory contents.
*
* @category File System
*/
listDir = (path, { signal } = {}) => this.#send({
type: FFMessageType.LIST_DIR,
data: { path },
}, undefined, signal);
/**
* Delete an empty directory.
*
* @category File System
*/
deleteDir = (path, { signal } = {}) => this.#send({
type: FFMessageType.DELETE_DIR,
data: { path },
}, undefined, signal);
}
var FFFSType;
(function (FFFSType) {
FFFSType["MEMFS"] = "MEMFS";
FFFSType["NODEFS"] = "NODEFS";
FFFSType["NODERAWFS"] = "NODERAWFS";
FFFSType["IDBFS"] = "IDBFS";
FFFSType["WORKERFS"] = "WORKERFS";
FFFSType["PROXYFS"] = "PROXYFS";
})(FFFSType || (FFFSType = {}));
const ERROR_RESPONSE_BODY_READER = new Error("failed to get response body reader");
const ERROR_INCOMPLETED_DOWNLOAD = new Error("failed to complete download");
const HeaderContentLength = "Content-Length";
const readFromBlobOrFile = (blob) => new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.onload = () => {
const { result } = fileReader;
if (result instanceof ArrayBuffer) {
resolve(new Uint8Array(result));
}
else {
resolve(new Uint8Array());
}
};
fileReader.onerror = (event) => {
reject(Error(`File could not be read! Code=${event?.target?.error?.code || -1}`));
};
fileReader.readAsArrayBuffer(blob);
});
/**
* An util function to fetch data from url string, base64, URL, File or Blob format.
*
* Examples:
* ```ts
* // URL
* await fetchFile("http://localhost:3000/video.mp4");
* // base64
* await fetchFile("data:<type>;base64,wL2dvYWwgbW9yZ...");
* // URL
* await fetchFile(new URL("video.mp4", import.meta.url));
* // File
* fileInput.addEventListener('change', (e) => {
* await fetchFile(e.target.files[0]);
* });
* // Blob
* const blob = new Blob(...);
* await fetchFile(blob);
* ```
*/
const fetchFile = async (file) => {
let data;
if (typeof file === "string") {
/* From base64 format */
if (/data:_data\/([a-zA-Z]*);base64,([^"]*)/.test(file)) {
data = atob(file.split(",")[1])
.split("")
.map((c) => c.charCodeAt(0));
/* From remote server/URL */
}
else {
data = await (await fetch(file)).arrayBuffer();
}
}
else if (file instanceof URL) {
data = await (await fetch(file)).arrayBuffer();
}
else if (file instanceof File || file instanceof Blob) {
data = await readFromBlobOrFile(file);
}
else {
return new Uint8Array();
}
return new Uint8Array(data);
};
/**
* Download content of a URL with progress.
*
* Progress only works when Content-Length is provided by the server.
*
*/
const downloadWithProgress = async (url, cb) => {
const resp = await fetch(url);
let buf;
try {
// Set total to -1 to indicate that there is not Content-Type Header.
const total = parseInt(resp.headers.get(HeaderContentLength) || "-1");
const reader = resp.body?.getReader();
if (!reader)
throw ERROR_RESPONSE_BODY_READER;
const chunks = [];
let received = 0;
for (;;) {
const { done, value } = await reader.read();
const delta = value ? value.length : 0;
if (done) {
if (total != -1 && total !== received)
throw ERROR_INCOMPLETED_DOWNLOAD;
cb && cb({ url, total, received, delta, done });
break;
}
chunks.push(value);
received += delta;
cb && cb({ url, total, received, delta, done });
}
const data = new Uint8Array(received);
let position = 0;
for (const chunk of chunks) {
data.set(chunk, position);
position += chunk.length;
}
buf = data.buffer;
}
catch (e) {
console.log(`failed to send download progress event: `, e);
// Fetch arrayBuffer directly when it is not possible to get progress.
buf = await resp.arrayBuffer();
}
return buf;
};
/**
* toBlobURL fetches data from an URL and return a blob URL.
*
* Example:
*
* ```ts
* await toBlobURL("http://localhost:3000/ffmpeg.js", "text/javascript");
* ```
*/
const toBlobURL = async (url, mimeType, progress = false, cb) => {
const buf = progress
? await downloadWithProgress(url, cb)
: await (await fetch(url)).arrayBuffer();
const blob = new Blob([buf], { type: mimeType });
return URL.createObjectURL(blob);
};
/**
* Loads the FFmpeg library with optional multi-threading support.
*
* This function initializes a new instance of FFmpeg, sets up event listeners for logging,
* and loads the necessary core and WASM files from a given URL. If multi-threading is enabled,
* it will load an additional worker script. If multi-threading (`mt`) is set to true, a base URL must
* be provided for the FFmpeg core and worker scripts.
*
* @param {string} [baseUrl="https://unpkg.com/@ffmpeg/core@0.12.10/dist/esm"] - The base URL to load the FFmpeg core and WASM files from.
* @param {boolean} [mt=false] - A flag to indicate if multi-threading should be enabled. If true, a worker script will be loaded. If multi-threading is enabled, `baseUrl` must be provided.
*
* @returns {Promise<FFmpeg>} - A Promise that resolves to the initialized FFmpeg instance.
*
* @throws {Error} - Throws an error if the FFmpeg core or WASM files fail to load or if an error occurs during FFmpeg operations.
*
* @example
* const ffmpeg = await load()
* // By default, the base URL is provided for single-threaded transcoding. To use multi-threading, a base URL MUST be provided and `mt` should be set to true.
* // You can now use the `ffmpeg` instance for transcoding tasks.
*/
const load = async (baseUrl = "https://unpkg.com/@ffmpeg/core@0.12.10/dist/esm", mt = false) => {
// inittialize a new ffmpeg instance
const ffmpeg = new FFmpeg();
const singleThred = {
coreURL: await toBlobURL(`${baseUrl}/ffmpeg-core.js`, "text/javascript"),
wasmURL: await toBlobURL(`${baseUrl}/ffmpeg-core.wasm`, "application/wasm"),
};
try {
if (mt) {
await ffmpeg.load({
...singleThred,
workerURL: await toBlobURL(`${baseUrl}/ffmpeg-core.worker.js`, "text/javascript"),
});
}
else {
await ffmpeg.load(singleThred);
}
}
catch (error) {
throw new Error(`Error loading FFmpeg core and WASM files from ${baseUrl}`);
}
return ffmpeg;
};
/**
* Handles an error by creating an error message and throwing a new Error.
*
* This function accepts an error and context string, constructs a descriptive error message,
* and throws an error with that message. If the provided error is an instance of `Error`,
* its message is included; otherwise, a generic message indicating an unknown error is used.
*
* @param {unknown} error - The error to handle. It can be any type, but if it's an instance of `Error`, its message will be used.
* @param {string} context - A string that provides context about where the error occurred, helping to identify the source of the issue.
* @returns {never} - This function always throws an error and does not return a value.
*
* @throws {Error} Throws a new error with a formatted message containing the provided context and the error message (if available).
*
* @example
* try {
* // Some code that may throw an error
* } catch (error) {
* handleError(error, "Error processing the file");
* }
*/
const errorHandler = (error, context) => {
let errorMessage = `${context}: `;
if (error instanceof Error) {
errorMessage += error.message;
}
else {
errorMessage += "Unknown error occurred.";
}
throw new Error(errorMessage);
};
const mimeTypes = {
video: {
mp4: "video/mp4",
webm: "video/webm",
mkv: "video/x-matroska",
mov: "video/quicktime",
avi: "video/x-msvideo",
flv: "video/x-flv",
ts: "video/MP2T",
ogv: "video/ogg",
asf: "video/x-ms-asf",
"3gp": "video/3gpp",
rm: "application/vnd.rn-realmedia",
},
audio: {
mp3: "audio/mpeg",
wav: "audio/x-wav",
aac: "audio/aac",
flac: "audio/flac",
ogg: "audio/ogg",
m4a: "audio/mp4",
wma: "audio/x-ms-wma",
amr: "audio/amr",
opus: "audio/opus",
},
image: {
png: "image/png",
jpeg: "image/jpeg",
jpg: "image/jpeg",
gif: "image/gif",
svg: "image/svg+xml",
webp: "image/webp",
bmp: "image/bmp",
tiff: "image/tiff",
ico: "image/x-icon",
},
};
const mimeTypesObject = {
...mimeTypes.audio,
...mimeTypes.image,
...mimeTypes.video,
};
/**
* Extracts the MIME type from a file name or path based on its extension.
*
* This function takes a file name or file path as input, extracts its extension,
* and looks up the corresponding MIME type from a predefined object. If the
* extension is not found or unsupported, it throws an error.
*
* @param {string} file - The file name or path to extract the MIME type from.
* @returns {{ mimeType: string }} An object containing the MIME type of the file.
* @throws {error} Throws an error if the file has no extension or the extension is unsupported.
*
* @example
* import { extractMimeType } from "./utils";
*
* // Example 1: Extracting MIME type for a supported file
* const file1 = "example.pdf";
* console.log(extractMimeType(file1)); // { mimeType: "application/pdf" }
*
* // Example 2: Extracting MIME type for an unsupported file
* const file2 = "example.unknown";
* try {
* extractMimeType(file2);
* } catch (err) {
* console.error(err.message); // "Unsupported file extension"
* }
*
* // Example 3: File with no extension
* const file3 = "example";
* try {
* extractMimeType(file3);
* } catch (err) {
* console.error(err.message); // "No extension found in file"
* }
*/
const extractMimeType = (file) => {
const splitFile = file.split(".");
if (splitFile.length < 2) {
throw new Error("No extension found in file");
}
const extension = splitFile[splitFile.length - 1].toLowerCase();
// look up for the MIM type of the extension
const mimeType = mimeTypesObject[extension];
if (!mimeType) {
throw new Error("Unsupported file extension");
}
return { mimeType };
};
/**
* converts a file size in bytes to human-readable format
*
* This function takes the size of a file in bytes and formats it into a more
* readable string representation using units such as KB, MB, GB, or TB.
* If the size is `undefined`, it returns "unknown size".
*
* @param {number | undefined} size - The size of the file in bytes. If `undefined`, the size is unknown
* @returns {string} The formated file size, or "unknown size" if the input is `undefined`
*
* @example
* // Example 1: Formatting a small size
* formatFileSize(1024); // Returns "1.00 KB"
*
* // Example 2: Formatting a larger size
* formatFileSize(1048576); // Returns "1.00 MB"
*
* // Example 3: Handling undefined input
* formatFileSize(undefined); // Returns "unknown size"
*/
const formatFileSize = (size) => {
if (size === undefined) {
return "unknown size";
}
const units = ["bytes", "KB", "MB", "GB", "TB"];
let k = 0;
let newSize = size;
while (newSize >= 1024 && k < units.length - 1) {
newSize /= 1024;
k++;
}
return `${newSize.toFixed(2)} ${units[k]}`;
};
/**
* Transcodes a file using FFmpeg and returns the output as a downloadable URL and its human-readable size.
*
* This function handles the file conversion process using FFmpeg, including writing the file to FFmpeg's virtual file system,
* executing the FFmpeg command, and cleaning up temporary files after the conversion.
*
* @param {FFmpeg | null} ffmpeg - The initialized FFmpeg instance.
* @param {File} file - The input file to be transcoded.
* @param {string} outputFileFullName - The name of the output file, including its extension.
* @param {string[]} [cmdOptions] - Optional array of additional FFmpeg command-line options.
* @returns {Promise<{ url: string; fileSize: string }>} A promise resolving to an object containing:
* - `url` (string): A downloadable URL for the transcoded file.
* - `fileSize` (string): The size of the transcoded file in a human-readable format.
* @throws {Error} If FFmpeg is not loaded, or if any error occurs during the transcoding process.
*/
const transcode = async (ffmpeg, file, outputFileFullName, cmdOptions) => {
const inputFileFullName = file.name;
if (!ffmpeg) {
return errorHandler(new Error("FFmpeg not loaded"), "Error converting file");
}
try {
// Write the file to FFmpeg's virtual file system
await ffmpeg.writeFile(inputFileFullName, await fetchFile(file));
const { mimeType } = extractMimeType(outputFileFullName);
// Ensure cmdOptions is an array or defaults to empty array
const safeCmdOptions = Array.isArray(cmdOptions) ? cmdOptions : [];
// FFmpeg command setup
const ffmpegCmd = [
"-i",
inputFileFullName,
outputFileFullName,
...safeCmdOptions,
];
// Execute FFmpeg command
await ffmpeg.exec(ffmpegCmd);
// Read the output file
const data = await ffmpeg.readFile(outputFileFullName);
// Create a Blob from the data and generate a URL
const blob = new Blob([data], { type: mimeType });
// blobsize
const size = blob.size;
//convert blob size to human-readable form
const humanReadableSize = formatFileSize(size);
// creates a URL to reference the blob
const url = URL.createObjectURL(blob);
// Clean FFmpeg virtual file system by deleting temporary files
await Promise.all([
ffmpeg.deleteFile(inputFileFullName),
ffmpeg.deleteFile(outputFileFullName),
]);
return { url, fileSize: humanReadableSize };
}
catch (error) {
return errorHandler(error, "Error converting file");
}
};
/**
* Custom React hook for loading FFmpeg and performing file transcoding operations.
*
* Provides methods for initializing FFmpeg and transcoding files using FFmpeg once it is loaded.
*
* @returns {UseFFmpeg} An object containing:
* - `loaded` (boolean): Indicates whether FFmpeg is loaded and ready to use.
* - `loadFFmpeg(baseUrl?: string, mt?: boolean): Promise<void>`: A function to load FFmpeg.
* - `transcode(file: File, outputFileFullName: string, cmdOptions?: string[]): Promise<Buffer>`: A function to transcode files using FFmpeg.
*/
const useFFmpeg$1 = () => {
const [loaded, SetLoaded] = reactExports.useState(false);
const ffmpegRef = reactExports.useRef(null);
/**
* Loads the FFmpeg library and sets it up for use.
*
* This function sets the `loaded` state to `false` while loading, and to `true` once the process completes successfully.
*
* @param {string} [baseUrl] - The optional base URL to load FFmpeg from.
* @param {boolean} [mt] - Optional flag for enabling multithreading in FFmpeg.
* @returns {Promise<void>} Resolves when FFmpeg is successfully loaded.
* @throws {Error} If FFmpeg fails to load, the error is passed to `errorHandler`.
*/
const loadFFmpeg = reactExports.useCallback(async (baseUrl, mt) => {
try {
const ffmpegResponse = await load(baseUrl, mt);
ffmpegRef.current = ffmpegResponse;
SetLoaded(true);
}
catch (error) {
errorHandler(error, "Error loading FFmpeg");
SetLoaded(false);
}
}, []);
/**
* Transcodes a file using the loaded FFmpeg instance.
*
* This function processes the given input file and generates an output file with the specified name.
* Additional FFmpeg command-line options can be provided for customization.
*
* @param {File} file - The input file to transcode.
* @param {string} outputFileFullName - The full name of the transcoded output file.
* @param {string[]} [cmdOptions] - Optional array of FFmpeg command-line options.
* @returns {Promise<Buffer>} Resolves with the transcoded file data as a buffer.
* @throws {Error} If FFmpeg is not loaded or if an error occurs during transcoding.
*/
const handleTranscode = reactExports.useCallback(async (file, outputFileFullName, cmdOptions) => {
if (!loaded) {
throw new Error("FFmpeg is not loaded");
}
return await transcode(ffmpegRef.current, file, outputFileFullName, cmdOptions);
}, [loaded]);
return {
loadFFmpeg,
loaded,
transcode: handleTranscode,
};
};
/**
* Context to provide the FFmpeg hook to the application.
* @private
*/
const FFmpegContext = reactExports.createContext(null);
/**
* FFmpegContextProvider is a React component that wraps the application and provides
* the FFmpeg hook using context. This provider must be placed higher in the component tree
* where the `useFFmpeg` hook needs access to FFmpeg functionality.
*
* @param {React.PropsWithChildren} props - The props to be passed to the children components.
* @returns {React.ReactNode} - The wrapped children components with the FFmpeg context provided.
*
* @example
* <FFmpegContextProvider>
* <YourComponent />
* </FFmpegContextProvider>
*/
const FFmpegContextProvider = (props) => {
const ffmpeg = useFFmpeg$1();
return (React.createElement(FFmpegContext.Provider, { value: ffmpeg }, props.children));
};
/**
* Custom hook to access the FFmpeg context value.
* If the context is not available (i.e., the hook is called outside the provider),
* it will fallback to using the base `useFFmpeg` hook directly.
*
* @returns {UseFFmpeg} - The FFmpeg hook, providing FFmpeg functionality and methods.
*
* @throws {Error} - Throws an error if the hook is used outside of the FFmpegContextProvider
* and the fallback logic is not invoked (since the base hook will be used in that case).
*
* @example
* const ffmpeg = useFFmpeg();
* ffmpeg.load(); // Example usage
*/
const useFFmpeg = () => {
const contextValue = reactExports.useContext(FFmpegContext);
if (contextValue) {
return contextValue;
}
return useFFmpeg$1();
};
export { FFmpegContextProvider, mimeTypes, useFFmpeg };
//# sourceMappingURL=index.esm.js.map