Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@socaity/media-toolkit

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@socaity/media-toolkit - npm Package Compare versions

Comparing version
0.0.3
to
0.0.5
+260
-202
dist/media-toolkit.es.js

@@ -1,11 +0,11 @@

var M = Object.defineProperty;
var T = (r, e, t) => e in r ? M(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
var p = (r, e, t) => T(r, typeof e != "symbol" ? e + "" : e, t);
function E(r) {
return r && typeof r == "object" && "file_name" in r && "content_type" in r && "content" in r;
var B = Object.defineProperty;
var x = (o, e, t) => e in o ? B(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
var b = (o, e, t) => x(o, typeof e != "symbol" ? e + "" : e, t);
function _(o) {
return o && typeof o == "object" && "file_name" in o && "content_type" in o && "content" in o;
}
const h = typeof window > "u";
function b(r) {
const d = typeof window > "u";
function E(o) {
try {
const e = new URL(r);
const e = new URL(o);
return e.protocol === "http:" || e.protocol === "https:";

@@ -16,13 +16,13 @@ } catch {

}
function I(r) {
return r.startsWith("data:") || B(r);
function L(o) {
return o.startsWith("data:") || F(o);
}
function B(r) {
return /^[A-Za-z0-9+/=]+$/.test(r) && r.length % 4 === 0;
function F(o) {
return /^[A-Za-z0-9+/=]+$/.test(o) && o.length % 4 === 0;
}
async function x(r) {
if (!h)
async function C(o) {
if (!d)
return !1;
try {
return (await (await import("fs/promises")).stat(r)).isFile();
return (await (await import("fs/promises")).stat(o)).isFile();
} catch {

@@ -32,21 +32,21 @@ return !1;

}
function A(r) {
return r && typeof r == "object" && typeof r.data == "string" && typeof r.type == "string" && typeof r.name == "string";
function A(o) {
return o && typeof o == "object" && typeof o.data == "string" && typeof o.type == "string" && typeof o.name == "string";
}
async function U(r) {
if (r == null)
async function T(o) {
if (o == null)
return null;
if (Array.isArray(r)) {
const e = r.map((t) => U(t));
if (Array.isArray(o)) {
const e = o.map((t) => T(t));
return Promise.all(e);
}
if (E(r))
if (_(o))
try {
return await new m().fromDict(r);
return await new f().fromDict(o);
} catch {
return r;
return o;
}
return r;
return o;
}
class y {
class g {
/**

@@ -62,5 +62,5 @@ * Create a MediaFile or specialized subclass from any supported data type.

throw new Error("Cannot create MediaFile from null or undefined data");
const t = await y._detectContentType(e);
let n = d.default;
return t && t.startsWith("image/") ? n = d.image : t && t.startsWith("audio/") ? n = d.audio : t && t.startsWith("video/") && (n = d.video), new n().fromAny(e);
const t = await g._detectContentType(e);
let n = h.default;
return t && t.startsWith("image/") ? n = h.image : t && t.startsWith("audio/") ? n = h.audio : t && t.startsWith("video/") && (n = h.video), new n().fromAny(e);
}

@@ -76,12 +76,12 @@ /**

var t;
if (e instanceof m)
if (e instanceof f)
return e.getContentType();
if (E(e))
if (_(e))
return e.content_type;
if (A(e))
return e.type;
if (typeof e == "string" && b(e)) {
const o = (t = new URL(e).pathname.split(".").pop()) == null ? void 0 : t.toLowerCase();
if (o) {
const s = y._getMimeTypeFromExtension(o);
if (typeof e == "string" && E(e)) {
const r = (t = new URL(e).pathname.split(".").pop()) == null ? void 0 : t.toLowerCase();
if (r) {
const s = g._getMimeTypeFromExtension(r);
if (s) return s;

@@ -110,5 +110,5 @@ }

await n.access(e);
const o = i.extname(e).slice(1).toLowerCase();
if (o) {
const s = y._getMimeTypeFromExtension(o);
const r = i.extname(e).slice(1).toLowerCase();
if (r) {
const s = g._getMimeTypeFromExtension(r);
if (s) return s;

@@ -168,3 +168,3 @@ }

}
class m {
class f {
/**

@@ -177,5 +177,5 @@ * Creates a new MediaFile instance.

constructor(e = "file", t = "application/octet-stream") {
p(this, "content_type");
p(this, "file_name");
p(this, "_content", null);
b(this, "content_type");
b(this, "file_name");
b(this, "_content", null);
this.content_type = t, this.file_name = e;

@@ -192,3 +192,3 @@ }

static async create(e) {
return y.create(e);
return g.create(e);
}

@@ -205,3 +205,3 @@ /**

throw new Error("Cannot create MediaFile from null or undefined data");
if (e instanceof m)
if (e instanceof f)
return e;

@@ -213,4 +213,9 @@ if (A(e)) {

}
if (h && this._isBuffer(e))
if (d && this._isBuffer(e))
return this.fromBytes(e);
if (typeof File < "u" && e instanceof File) {
this.file_name = e.name, this.content_type = e.type || "application/octet-stream";
const t = await e.arrayBuffer();
return this.fromBytes(t);
}
if (typeof Blob < "u" && e instanceof Blob) {

@@ -223,11 +228,11 @@ const t = await e.arrayBuffer();

if (typeof e == "string") {
if (b(e))
if (E(e))
return await this.fromUrl(e);
if (I(e))
if (L(e))
return this.fromBase64(e);
if (await x(e))
if (await C(e))
return await this.fromFile(e);
throw typeof e == "string" ? new Error("Invalid data type for MediaFile " + e) : new Error("Invalid data type for MediaFile");
}
return E(e) ? await this.fromDict(e) : this;
return _(e) ? await this.fromDict(e) : this;
}

@@ -241,3 +246,3 @@ /**

async fromFile(e) {
if (!h)
if (!d)
throw new Error("Loading from file path is only supported in Node.js environment");

@@ -259,4 +264,4 @@ try {

async fromUrl(e, t) {
const n = async (i, o) => await fetch(i, {
headers: o || {
const n = async (i, r) => await fetch(i, {
headers: r || {
"User-Agent": "MediaFile/1.0.0"

@@ -276,10 +281,10 @@ }

this.content_type = i.headers.get("content-type") || "application/octet-stream";
const o = i.headers.get("content-disposition");
if (o) {
const s = o.match(/filename=(?:['"]?)([^'";\n]+)/i);
const r = i.headers.get("content-disposition");
if (r) {
const s = r.match(/filename=(?:['"]?)([^'";\n]+)/i);
s && s[1] && (this.file_name = s[1]);
}
if (!this.file_name || this.file_name === "file") {
const a = new URL(e).pathname.split("/"), u = a[a.length - 1];
u && u.trim() !== "" ? this.file_name = decodeURIComponent(u) : this.file_name = "downloaded_file";
const a = new URL(e).pathname.split("/"), m = a[a.length - 1];
m && m.trim() !== "" ? this.file_name = decodeURIComponent(m) : this.file_name = "downloaded_file";
}

@@ -301,3 +306,3 @@ return this._content = await i.arrayBuffer(), this;

try {
return this._content = h ? this._decodeBase64NodeJs(t) : this._decodeBase64Browser(t), this;
return this._content = d ? this._decodeBase64NodeJs(t) : this._decodeBase64Browser(t), this;
} catch (i) {

@@ -324,3 +329,3 @@ throw new Error(`Failed to decode base64 data: ${i.message}`);

this._content = e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength);
else if (h && Buffer.isBuffer(e))
else if (d && Buffer.isBuffer(e))
if (typeof SharedArrayBuffer < "u" && e.buffer instanceof SharedArrayBuffer) {

@@ -378,3 +383,3 @@ const t = new Uint8Array(e);

toBuffer() {
if (this._ensureContent(), !h)
if (this._ensureContent(), !d)
throw new Error("Buffer is only available in Node.js environment");

@@ -392,3 +397,3 @@ return Buffer.from(this._content);

let t;
if (h)
if (d)
t = Buffer.from(this._content).toString("base64");

@@ -398,5 +403,5 @@ else {

let i = "";
const o = 10240;
for (let s = 0; s < n.length; s += o) {
const a = n.subarray(s, Math.min(s + o, n.length));
const r = 10240;
for (let s = 0; s < n.length; s += r) {
const a = n.subarray(s, Math.min(s + r, n.length));
i += String.fromCharCode.apply(null, Array.from(a));

@@ -429,3 +434,3 @@ }

const t = e || this.file_name;
if (h)
if (d)
try {

@@ -435,4 +440,4 @@ const n = await import("fs/promises").then((s) => s.default || s), i = await import("path").then((s) => s.default || s);

throw new Error("Failed to load 'path' module.");
const o = i.dirname(t);
o !== "." && await n.mkdir(o, { recursive: !0 }).catch(() => {
const r = i.dirname(t);
r !== "." && await n.mkdir(r, { recursive: !0 }).catch(() => {
}), await n.writeFile(t, Buffer.from(this._content));

@@ -443,5 +448,5 @@ } catch (n) {

else {
const n = this.toBlob(), i = URL.createObjectURL(n), o = document.createElement("a");
o.href = i, o.download = t, document.body.appendChild(o), o.click(), setTimeout(() => {
document.body.removeChild(o), URL.revokeObjectURL(i);
const n = this.toBlob(), i = URL.createObjectURL(n), r = document.createElement("a");
r.href = i, r.download = t, document.body.appendChild(r), r.click(), setTimeout(() => {
document.body.removeChild(r), URL.revokeObjectURL(i);
}, 100);

@@ -498,3 +503,3 @@ }

return t[this.content_type];
if (h)
if (d)
try {

@@ -572,7 +577,7 @@ const i = require("mime-types").extension(this.content_type);

if (!e) return;
if (h)
if (d)
try {
const o = require("mime-types").lookup(this.file_name);
if (o) {
this.content_type = o;
const r = require("mime-types").lookup(this.file_name);
if (r) {
this.content_type = r;
return;

@@ -615,4 +620,4 @@ }

if (e.startsWith("data:")) {
const [t, n] = e.split(",", 2), i = t.match(/^data:([^;,]+)/), o = i ? i[1] : null;
return { data: n, mediaType: o };
const [t, n] = e.split(",", 2), i = t.match(/^data:([^;,]+)/), r = i ? i[1] : null;
return { data: n, mediaType: r };
}

@@ -638,3 +643,3 @@ return { data: e, mediaType: null };

_isBuffer(e) {
return h && Buffer.isBuffer(e);
return d && Buffer.isBuffer(e);
}

@@ -680,3 +685,90 @@ /**

}
const c = class c extends m {
const l = {
mp3: "audio/mpeg",
wav: "audio/wav",
ogg: "audio/ogg",
aac: "audio/aac",
flac: "audio/flac",
m4a: "audio/mp4",
webm: "audio/webm"
}, c = {
mp4: "video/mp4",
mov: "video/quicktime",
avi: "video/x-msvideo",
mkv: "video/x-matroska",
wmv: "video/x-ms-wmv",
webm: "video/webm",
"3gp": "video/3gpp",
flv: "video/x-flv"
}, u = {
jpg: "image/jpeg",
jpeg: "image/jpeg",
png: "image/png",
gif: "image/gif",
webp: "image/webp",
svg: "image/svg+xml",
bmp: "image/bmp",
ico: "image/x-icon",
tiff: "image/tiff",
tif: "image/tiff",
avif: "image/avif"
}, $ = {
...l,
...c,
...u
};
function U(o) {
const e = [];
switch (o) {
case "audio":
e.push(...Object.values(l)), e.push(...Object.keys(l).map((t) => `.${t}`));
break;
case "video":
e.push(...Object.values(c)), e.push(...Object.keys(c).map((t) => `.${t}`));
break;
case "image":
e.push(...Object.values(u)), e.push(...Object.keys(u).map((t) => `.${t}`));
break;
case "file":
default:
return ["*/*"];
}
return e;
}
function k(o) {
if (o.includes("file"))
return ["*/*"];
const e = [];
return o.forEach((t) => {
e.push(...U(t));
}), [...new Set(e)];
}
function M(o) {
return {
audio: "Audio",
video: "Video",
image: "Images",
file: "Files"
}[o] || o;
}
function j(o) {
switch (o) {
case "audio":
return Object.keys(l);
case "video":
return Object.keys(c);
case "image":
return Object.keys(u);
default:
return [];
}
}
function I(o, e) {
const t = o.startsWith(".") ? o.substring(1) : o;
return j(e).includes(t.toLowerCase());
}
function R(o) {
return Object.values(l).includes(o) ? "audio" : Object.values(c).includes(o) ? "video" : Object.values(u).includes(o) ? "image" : null;
}
class p extends f {
/**

@@ -700,3 +792,3 @@ * Creates a new ImageFile instance.

throw new Error("Cannot create ImageFile from null or undefined data");
return new c().fromAny(e);
return new p().fromAny(e);
}

@@ -710,5 +802,5 @@ /**

async fromAny(e) {
if (e instanceof c)
if (e instanceof p)
return e;
if (e instanceof m && !(e instanceof c)) {
if (e instanceof f && !(e instanceof p)) {
if (e.isEmpty())

@@ -731,4 +823,4 @@ throw new Error("Cannot create ImageFile from empty MediaFile");

this._ensureContent();
const t = this.toBase64(), { width: n, height: i, alt: o = "", className: s = "" } = e, a = n ? ` width="${n}"` : "", u = i ? ` height="${i}"` : "", v = s ? ` class="${s}"` : "";
return `<img src="${t}" alt="${o}"${a}${u}${v}>`;
const t = this.toBase64(), { width: n, height: i, alt: r = "", className: s = "" } = e, a = n ? ` width="${n}"` : "", m = i ? ` height="${i}"` : "", v = s ? ` class="${s}"` : "";
return `<img src="${t}" alt="${r}"${a}${m}${v}>`;
}

@@ -765,5 +857,5 @@ /**

};
const i = this.toBlob(), o = URL.createObjectURL(i);
n.src = o, n.addEventListener("load", () => {
URL.revokeObjectURL(o);
const i = this.toBlob(), r = URL.createObjectURL(i);
n.src = r, n.addEventListener("load", () => {
URL.revokeObjectURL(r);
}, { once: !0 });

@@ -783,4 +875,4 @@ });

const e = (t = this.extension) == null ? void 0 : t.toLowerCase();
if (e && e in c.IMAGE_MIME_TYPES) {
this.content_type = c.IMAGE_MIME_TYPES[e];
if (e && e in u) {
this.content_type = u[e];
return;

@@ -799,42 +891,25 @@ }

if (e[0] === 255 && e[1] === 216 && e[2] === 255) {
this.content_type = c.IMAGE_MIME_TYPES.jpeg;
this.content_type = u.jpeg;
return;
}
if (e[0] === 137 && e[1] === 80 && e[2] === 78 && e[3] === 71 && e[4] === 13 && e[5] === 10 && e[6] === 26 && e[7] === 10) {
this.content_type = c.IMAGE_MIME_TYPES.png;
this.content_type = u.png;
return;
}
if (e[0] === 71 && e[1] === 73 && e[2] === 70 && e[3] === 56 && (e[4] === 55 || e[4] === 57) && e[5] === 97) {
this.content_type = c.IMAGE_MIME_TYPES.gif;
this.content_type = u.gif;
return;
}
if (e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70 && e[8] === 87 && e[9] === 69 && e[10] === 66 && e[11] === 80) {
this.content_type = c.IMAGE_MIME_TYPES.webp;
this.content_type = u.webp;
return;
}
if (this._content.byteLength > 100 && new TextDecoder().decode(new Uint8Array(this._content.slice(0, 100))).indexOf("<svg") !== -1) {
this.content_type = c.IMAGE_MIME_TYPES.svg;
this.content_type = u.svg;
return;
}
this.content_type = c.IMAGE_MIME_TYPES.png;
this.content_type = u.png;
}
};
/**
* Common image MIME types
*/
p(c, "IMAGE_MIME_TYPES", {
jpg: "image/jpeg",
jpeg: "image/jpeg",
png: "image/png",
gif: "image/gif",
webp: "image/webp",
svg: "image/svg+xml",
bmp: "image/bmp",
ico: "image/x-icon",
tiff: "image/tiff",
tif: "image/tiff",
avif: "image/avif"
});
let w = c;
const l = class l extends m {
}
class y extends f {
/**

@@ -858,3 +933,3 @@ * Creates a new AudioFile instance.

throw new Error("Cannot create AudioFile from null or undefined data");
return new l().fromAny(e);
return new y().fromAny(e);
}

@@ -868,5 +943,5 @@ /**

async fromAny(e) {
if (e instanceof l)
if (e instanceof y)
return e;
if (e instanceof m && !(e instanceof l)) {
if (e instanceof f && !(e instanceof y)) {
if (e.isEmpty())

@@ -931,4 +1006,4 @@ throw new Error("Cannot create AudioFile from empty MediaFile");

*/
toHtmlPlayer(e = {}) {
const t = this.toBase64(), { controls: n = !0, autoplay: i = !1, loop: o = !1 } = e;
toHTMLPlayer(e = {}) {
const t = this.toBase64(), { controls: n = !0, autoplay: i = !1, loop: r = !1 } = e;
return `<audio

@@ -938,3 +1013,3 @@ src="${t}"

${i ? "autoplay" : ""}
${o ? "loop" : ""}>
${r ? "loop" : ""}>
Your browser does not support the audio element.

@@ -954,4 +1029,4 @@ </audio>`;

const e = (t = this.extension) == null ? void 0 : t.toLowerCase();
if (e && e in l.AUDIO_MIME_TYPES) {
this.content_type = l.AUDIO_MIME_TYPES[e];
if (e && e in l) {
this.content_type = l[e];
return;

@@ -970,38 +1045,25 @@ }

if (e[0] === 73 && e[1] === 68 && e[2] === 51) {
this.content_type = l.AUDIO_MIME_TYPES.mp3;
this.content_type = l.mp3;
return;
}
if (e[0] === 255 && (e[1] & 224) === 224) {
this.content_type = l.AUDIO_MIME_TYPES.mp3;
this.content_type = l.mp3;
return;
}
if (e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70 && e[8] === 87 && e[9] === 65 && e[10] === 86 && e[11] === 69) {
this.content_type = l.AUDIO_MIME_TYPES.wav;
this.content_type = l.wav;
return;
}
if (e[0] === 79 && e[1] === 103 && e[2] === 103 && e[3] === 83) {
this.content_type = l.AUDIO_MIME_TYPES.ogg;
this.content_type = l.ogg;
return;
}
if (e[0] === 102 && e[1] === 76 && e[2] === 97 && e[3] === 67) {
this.content_type = l.AUDIO_MIME_TYPES.flac;
this.content_type = l.flac;
return;
}
this.content_type = l.AUDIO_MIME_TYPES.mp3;
this.content_type = l.mp3;
}
};
/**
* Common audio MIME types
*/
p(l, "AUDIO_MIME_TYPES", {
mp3: "audio/mpeg",
wav: "audio/wav",
ogg: "audio/ogg",
aac: "audio/aac",
flac: "audio/flac",
m4a: "audio/mp4",
webm: "audio/webm"
});
let g = l;
const f = class f extends m {
}
class w extends f {
/**

@@ -1025,3 +1087,3 @@ * Creates a new VideoFile instance.

throw new Error("Cannot create VideoFile from null or undefined data");
return new f().fromAny(e);
return new w().fromAny(e);
}

@@ -1035,5 +1097,5 @@ /**

async fromAny(e) {
if (e instanceof f)
if (e instanceof w)
return e;
if (e instanceof m && !(e instanceof f)) {
if (e instanceof f && !(e instanceof w)) {
if (e.isEmpty())

@@ -1125,20 +1187,20 @@ throw new Error("Cannot create VideoFile from empty MediaFile");

t.currentTime = e, await new Promise((a) => {
const u = () => {
t.removeEventListener("seeked", u), a();
const m = () => {
t.removeEventListener("seeked", m), a();
};
t.addEventListener("seeked", u);
t.addEventListener("seeked", m);
});
const o = document.createElement("canvas");
o.width = t.videoWidth, o.height = t.videoHeight;
const s = o.getContext("2d");
const r = document.createElement("canvas");
r.width = t.videoWidth, r.height = t.videoHeight;
const s = r.getContext("2d");
if (!s)
throw new Error("Failed to get canvas context");
s.drawImage(t, 0, 0, o.width, o.height), o.toBlob((a) => {
s.drawImage(t, 0, 0, r.width, r.height), r.toBlob((a) => {
a ? n(a) : i(new Error("Failed to create thumbnail blob"));
}, "image/jpeg", 0.95);
} catch (o) {
i(o);
} catch (r) {
i(r);
}
}), t.addEventListener("error", (o) => {
i(new Error(`Video loading error: ${o}`));
}), t.addEventListener("error", (r) => {
i(new Error(`Video loading error: ${r}`));
});

@@ -1157,6 +1219,6 @@ });

autoplay: i = !1,
loop: o = !1,
loop: r = !1,
muted: s = !1,
width: a,
height: u,
height: m,
poster: v

@@ -1168,6 +1230,6 @@ } = e;

${i ? "autoplay" : ""}
${o ? "loop" : ""}
${r ? "loop" : ""}
${s ? "muted" : ""}
${a ? `width="${a}"` : ""}
${u ? `height="${u}"` : ""}
${m ? `height="${m}"` : ""}
${v ? `poster="${v}"` : ""}>

@@ -1188,4 +1250,4 @@ Your browser does not support the video element.

const e = (t = this.extension) == null ? void 0 : t.toLowerCase();
if (e && e in f.VIDEO_MIME_TYPES) {
this.content_type = f.VIDEO_MIME_TYPES[e];
if (e && e in c) {
this.content_type = c[e];
return;

@@ -1204,62 +1266,58 @@ }

if (e[4] === 102 && e[5] === 116 && e[6] === 121 && e[7] === 112) {
this.content_type = f.VIDEO_MIME_TYPES.mp4;
this.content_type = c.mp4;
return;
}
if (e[4] === 119 && e[5] === 105 && e[6] === 100 && e[7] === 101 || e[4] === 109 && e[5] === 100 && e[6] === 97 && e[7] === 116 || e[4] === 102 && e[5] === 114 && e[6] === 101 && e[7] === 101 || e[4] === 112 && e[5] === 110 && e[6] === 111 && e[7] === 116 || e[4] === 115 && e[5] === 107 && e[6] === 105 && e[7] === 112 || e[4] === 109 && e[5] === 111 && e[6] === 111 && e[7] === 118) {
this.content_type = f.VIDEO_MIME_TYPES.mov;
this.content_type = c.mov;
return;
}
if (e[0] === 26 && e[1] === 69 && e[2] === 223 && e[3] === 163) {
this.content_type = f.VIDEO_MIME_TYPES.webm;
this.content_type = c.webm;
return;
}
if (e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70 && e[8] === 65 && e[9] === 86 && e[10] === 73 && e[11] === 32) {
this.content_type = f.VIDEO_MIME_TYPES.avi;
this.content_type = c.avi;
return;
}
if (e[0] === 70 && e[1] === 76 && e[2] === 86) {
this.content_type = f.VIDEO_MIME_TYPES.flv;
this.content_type = c.flv;
return;
}
if (e[4] === 102 && e[5] === 116 && e[6] === 121 && e[7] === 112 && e[8] === 51 && e[9] === 103 && e[10] === 112) {
this.content_type = f.VIDEO_MIME_TYPES["3gp"];
this.content_type = c["3gp"];
return;
}
this.content_type = f.VIDEO_MIME_TYPES.mp4;
this.content_type = c.mp4;
}
};
/**
* Common video MIME types
*/
p(f, "VIDEO_MIME_TYPES", {
mp4: "video/mp4",
mov: "video/quicktime",
avi: "video/x-msvideo",
mkv: "video/x-matroska",
wmv: "video/x-ms-wmv",
webm: "video/webm",
"3gp": "video/3gpp",
flv: "video/x-flv"
});
let _ = f;
const d = {};
d.default = m;
d.image = w;
d.audio = g;
d.video = _;
d.media = m;
typeof window < "u" && (window.MediaFile = m, window.ImageFile = w, window.AudioFile = g, window.AudioFile = _);
typeof module < "u" && typeof module.exports < "u" && (module.exports = { MediaFile: m, ImageFile: w, AudioFile: g, VideoFile: _, MediaFileFactory: y });
}
const h = {};
h.default = f;
h.image = p;
h.audio = y;
h.video = w;
h.media = f;
typeof window < "u" && (window.MediaFile = f, window.ImageFile = p, window.AudioFile = y, window.AudioFile = w);
typeof module < "u" && typeof module.exports < "u" && (module.exports = { MediaFile: f, ImageFile: p, AudioFile: y, VideoFile: w, MediaFileFactory: g });
export {
g as AudioFile,
w as ImageFile,
m as MediaFile,
y as MediaFileFactory,
_ as VideoFile,
$ as ALL_MIME_TYPES,
l as AUDIO_MIME_TYPES,
y as AudioFile,
u as IMAGE_MIME_TYPES,
p as ImageFile,
f as MediaFile,
g as MediaFileFactory,
c as VIDEO_MIME_TYPES,
w as VideoFile,
R as detectCategoryFromMimeType,
U as getAcceptedTypes,
k as getAcceptedTypesForCategories,
M as getCategoryDisplayName,
j as getFileExtensions,
I as isExtensionSupported,
A as isFileReaderObject,
E as isFileResult,
b as isUrl,
x as isValidFilePath,
U as parseSocaityAPIJobResult
_ as isFileResult,
E as isUrl,
C as isValidFilePath,
T as parseSocaityAPIJobResult
};
//# sourceMappingURL=media-toolkit.es.js.map

@@ -1,18 +0,18 @@

(function(a,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(a=typeof globalThis<"u"?globalThis:a||self,c(a["media-toolkit"]={}))})(this,function(a){"use strict";var U=Object.defineProperty;var L=(a,c,l)=>c in a?U(a,c,{enumerable:!0,configurable:!0,writable:!0,value:l}):a[c]=l;var g=(a,c,l)=>L(a,typeof c!="symbol"?c+"":c,l);function c(s){return s&&typeof s=="object"&&"file_name"in s&&"content_type"in s&&"content"in s}const l=typeof window>"u";function A(s){try{const e=new URL(s);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}}function B(s){return s.startsWith("data:")||F(s)}function F(s){return/^[A-Za-z0-9+/=]+$/.test(s)&&s.length%4===0}async function T(s){if(!l)return!1;try{return(await(await import("fs/promises")).stat(s)).isFile()}catch{return!1}}function M(s){return s&&typeof s=="object"&&typeof s.data=="string"&&typeof s.type=="string"&&typeof s.name=="string"}async function I(s){if(s==null)return null;if(Array.isArray(s)){const e=s.map(t=>I(t));return Promise.all(e)}if(c(s))try{return await new m().fromDict(s)}catch{return s}return s}class w{static async create(e){if(e==null)throw new Error("Cannot create MediaFile from null or undefined data");const t=await w._detectContentType(e);let n=y.default;return t&&t.startsWith("image/")?n=y.image:t&&t.startsWith("audio/")?n=y.audio:t&&t.startsWith("video/")&&(n=y.video),new n().fromAny(e)}static async _detectContentType(e){var t;if(e instanceof m)return e.getContentType();if(c(e))return e.content_type;if(M(e))return e.type;if(typeof e=="string"&&A(e)){const o=(t=new URL(e).pathname.split(".").pop())==null?void 0:t.toLowerCase();if(o){const r=w._getMimeTypeFromExtension(o);if(r)return r}try{const r=await fetch(e,{method:"HEAD",headers:{"User-Agent":"MediaFile/1.0.0"}});if(r.ok){const f=r.headers.get("content-type");if(f)return f}}catch{}}if(typeof e=="string"&&e.startsWith("data:")){const n=e.match(/^data:([^;,]+)/);if(n&&n[1])return n[1]}if(typeof e=="string"&&typeof window>"u")try{const n=await import("fs/promises"),i=await import("path");await n.access(e);const o=i.extname(e).slice(1).toLowerCase();if(o){const r=w._getMimeTypeFromExtension(o);if(r)return r}}catch{}return typeof Blob<"u"&&e instanceof Blob?e.type:null}static _getMimeTypeFromExtension(e){const t={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",aac:"audio/aac",flac:"audio/flac",m4a:"audio/mp4",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",mp4:"video/mp4",mov:"video/quicktime",avi:"video/x-msvideo",mkv:"video/x-matroska",wmv:"video/x-ms-wmv",webm:"video/webm","3gp":"video/3gpp",flv:"video/x-flv",pdf:"application/pdf",txt:"text/plain",html:"text/html",htm:"text/html",json:"application/json",js:"application/javascript",css:"text/css",xml:"application/xml",zip:"application/zip"};return e in t?t[e]:null}}class m{constructor(e="file",t="application/octet-stream"){g(this,"content_type");g(this,"file_name");g(this,"_content",null);this.content_type=t,this.file_name=e}static async create(e){return w.create(e)}async fromAny(e){if(e==null)throw new Error("Cannot create MediaFile from null or undefined data");if(e instanceof m)return e;if(M(e)){if(this.file_name=e.name||"file",this.content_type=e.type,typeof e.data=="string")return this.fromBase64(e.data);throw new Error("Invalid data format in FileReader object")}if(l&&this._isBuffer(e))return this.fromBytes(e);if(typeof Blob<"u"&&e instanceof Blob){const t=await e.arrayBuffer();return this.fromBytes(t)}if(e instanceof ArrayBuffer||e instanceof Uint8Array)return this.fromBytes(e);if(typeof e=="string"){if(A(e))return await this.fromUrl(e);if(B(e))return this.fromBase64(e);if(await T(e))return await this.fromFile(e);throw typeof e=="string"?new Error("Invalid data type for MediaFile "+e):new Error("Invalid data type for MediaFile")}return c(e)?await this.fromDict(e):this}async fromFile(e){if(!l)throw new Error("Loading from file path is only supported in Node.js environment");try{const n=await(await import("fs/promises")).readFile(e),i=await import("path");return this.file_name=i.basename(e),this._content=this._bufferToArrayBuffer(n),this._setContentTypeFromFileName(),this}catch(t){throw new Error(`Failed to load file from path: ${e}. ${t.message}`)}}async fromUrl(e,t){const n=async(i,o)=>await fetch(i,{headers:o||{"User-Agent":"MediaFile/1.0.0"}});try{let i=await n(e,t);if(!i.ok){if(i.status===401||i.status===403){const r=new URL(e);r.search="",i=await n(r.toString(),t)}if(!i.ok)throw new Error(`HTTP error! Status: ${i.status}`)}this.content_type=i.headers.get("content-type")||"application/octet-stream";const o=i.headers.get("content-disposition");if(o){const r=o.match(/filename=(?:['"]?)([^'";\n]+)/i);r&&r[1]&&(this.file_name=r[1])}if(!this.file_name||this.file_name==="file"){const f=new URL(e).pathname.split("/"),p=f[f.length-1];p&&p.trim()!==""?this.file_name=decodeURIComponent(p):this.file_name="downloaded_file"}return this._content=await i.arrayBuffer(),this}catch(i){throw new Error(`Failed to load file from URL: ${e}. ${i.message}`)}}fromBase64(e){const{data:t,mediaType:n}=this._parseBase64Uri(e);n&&(this.content_type=n);try{return this._content=l?this._decodeBase64NodeJs(t):this._decodeBase64Browser(t),this}catch(i){throw new Error(`Failed to decode base64 data: ${i.message}`)}}fromBytes(e){if(typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer){const t=new Uint8Array(e),n=new ArrayBuffer(t.byteLength);return new Uint8Array(n).set(t),this._content=n,this}if(e instanceof Uint8Array)if(typeof SharedArrayBuffer<"u"&&e.buffer instanceof SharedArrayBuffer){const t=new Uint8Array(e);this._content=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}else this._content=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);else if(l&&Buffer.isBuffer(e))if(typeof SharedArrayBuffer<"u"&&e.buffer instanceof SharedArrayBuffer){const t=new Uint8Array(e);this._content=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}else this._content=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);else this._content=new Uint8Array(e).buffer;return this}async fromDict(e){if(!e.content)throw new Error("Invalid FileResult object: missing content");return this.file_name=e.file_name,this.content_type=e.content_type,await this.fromAny(e.content)}toBlob(){if(this._ensureContent(),typeof Blob>"u")throw new Error("Blob is not available in this environment");return new Blob([new Uint8Array(this._content)],{type:this.content_type})}toArrayBuffer(){return this._ensureContent(),typeof SharedArrayBuffer<"u"&&this._content instanceof SharedArrayBuffer?this._content.slice(0):this._content}toUint8Array(){return this._ensureContent(),new Uint8Array(this._content)}toBuffer(){if(this._ensureContent(),!l)throw new Error("Buffer is only available in Node.js environment");return Buffer.from(this._content)}toBase64(e=!0){this._ensureContent();let t;if(l)t=Buffer.from(this._content).toString("base64");else{const n=new Uint8Array(this._content);let i="";const o=10240;for(let r=0;r<n.length;r+=o){const f=n.subarray(r,Math.min(r+o,n.length));i+=String.fromCharCode.apply(null,Array.from(f))}t=btoa(i)}return e?`data:${this.content_type};base64,${t}`:t}toJson(){return{file_name:this.file_name,content_type:this.content_type,content:this.toBase64()}}async save(e){this._ensureContent();const t=e||this.file_name;if(l)try{const n=await import("fs/promises").then(r=>r.default||r),i=await import("path").then(r=>r.default||r);if(!i||typeof i.dirname!="function")throw new Error("Failed to load 'path' module.");const o=i.dirname(t);o!=="."&&await n.mkdir(o,{recursive:!0}).catch(()=>{}),await n.writeFile(t,Buffer.from(this._content))}catch(n){throw new Error(`Failed to save file: ${n.message}`)}else{const n=this.toBlob(),i=URL.createObjectURL(n),o=document.createElement("a");o.href=i,o.download=t,document.body.appendChild(o),o.click(),setTimeout(()=>{document.body.removeChild(o),URL.revokeObjectURL(i)},100)}}fileSize(e="bytes"){if(!this._content)return 0;const t=this._content.byteLength;switch(e){case"kb":return t/1024;case"mb":return t/(1024*1024);case"gb":return t/(1024*1024*1024);default:return t}}get extension(){var e;if(this.content_type&&this.content_type!=="application/octet-stream"){const t={"image/jpeg":"jpg","image/png":"png","image/gif":"gif","image/webp":"webp","image/svg+xml":"svg","audio/mpeg":"mp3","audio/wav":"wav","audio/ogg":"ogg","video/mp4":"mp4","video/quicktime":"mov","application/pdf":"pdf","text/plain":"txt","text/html":"html","application/json":"json",npz:"npz"};if(this.content_type in t)return t[this.content_type];if(l)try{const i=require("mime-types").extension(this.content_type);if(i)return i}catch{}}return this.file_name&&this.file_name.includes(".")&&((e=this.file_name.split(".").pop())==null?void 0:e.toLowerCase())||null}getFileName(){return this.file_name}setFileName(e){this.file_name=e}getContentType(){return this.content_type}setContentType(e){this.content_type=e}read(){return this._ensureContent(),this._content}isEmpty(){return!this._content||this._content.byteLength===0}getInfo(){return{fileName:this.file_name,contentType:this.content_type,size:this.fileSize(),extension:this.extension}}_setContentTypeFromFileName(){var n;if(!this.file_name)return;const e=(n=this.file_name.split(".").pop())==null?void 0:n.toLowerCase();if(!e)return;if(l)try{const o=require("mime-types").lookup(this.file_name);if(o){this.content_type=o;return}}catch{}const t={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",mp4:"video/mp4",mov:"video/quicktime",pdf:"application/pdf",txt:"text/plain",html:"text/html",htm:"text/html",json:"application/json",js:"application/javascript",css:"text/css",xml:"application/xml",zip:"application/zip"};e in t&&(this.content_type=t[e])}_parseBase64Uri(e){if(e.startsWith("data:")){const[t,n]=e.split(",",2),i=t.match(/^data:([^;,]+)/),o=i?i[1]:null;return{data:n,mediaType:o}}return{data:e,mediaType:null}}_ensureContent(){if(!this._content)throw new Error("No content available. Load content first using fromFile, fromUrl, etc.")}_isBuffer(e){return l&&Buffer.isBuffer(e)}_decodeBase64NodeJs(e){const t=Buffer.from(e,"base64");return this._bufferToArrayBuffer(t)}_decodeBase64Browser(e){const t=atob(e),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n.buffer}_bufferToArrayBuffer(e){if(typeof SharedArrayBuffer<"u"&&e.buffer instanceof SharedArrayBuffer){const t=new ArrayBuffer(e.byteLength);return new Uint8Array(t).set(new Uint8Array(e)),t}else return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}}const d=class d extends m{constructor(e="image",t="image/png"){super(e,t)}static async create(e){if(e==null)throw new Error("Cannot create ImageFile from null or undefined data");return new d().fromAny(e)}async fromAny(e){if(e instanceof d)return e;if(e instanceof m&&!(e instanceof d)){if(e.isEmpty())throw new Error("Cannot create ImageFile from empty MediaFile");return this.file_name=e.getFileName()||"image",this.content_type=e.getContentType(),this._content=e.read(),this._validateImageContentType(),this}const t=await super.fromAny(e);return t.file_name=t.file_name||"image",t._validateImageContentType(),t}toImageElement(e={}){if(typeof window>"u")throw new Error("Image elements are only available in browser environments");this._ensureContent();const t=this.toBase64(),{width:n,height:i,alt:o="",className:r=""}=e,f=n?` width="${n}"`:"",p=i?` height="${i}"`:"",E=r?` class="${r}"`:"";return`<img src="${t}" alt="${o}"${f}${p}${E}>`}toDOMImageElement(e={}){if(typeof window>"u")throw new Error("DOM Image elements are only available in browser environments");this._ensureContent();const t=this.toBlob(),n=URL.createObjectURL(t),i=new Image;return e.width&&(i.width=e.width),e.height&&(i.height=e.height),e.alt&&(i.alt=e.alt),e.className&&(i.className=e.className),i.src=n,i.addEventListener("load",()=>{setTimeout(()=>URL.revokeObjectURL(n),1e3)}),i}async getDimensions(){if(typeof window>"u")throw new Error("Getting image dimensions is only available in browser environments");return new Promise((e,t)=>{const n=new Image;n.onload=()=>{e({width:n.naturalWidth,height:n.naturalHeight})},n.onerror=()=>{t(new Error("Failed to load image for dimension calculation"))};const i=this.toBlob(),o=URL.createObjectURL(i);n.src=o,n.addEventListener("load",()=>{URL.revokeObjectURL(o)},{once:!0})})}_validateImageContentType(){var t;if(this.content_type.startsWith("image/"))return;const e=(t=this.extension)==null?void 0:t.toLowerCase();if(e&&e in d.IMAGE_MIME_TYPES){this.content_type=d.IMAGE_MIME_TYPES[e];return}this._content&&this._detectImageFormat()}_detectImageFormat(){const e=new Uint8Array(this._content).slice(0,12);if(e[0]===255&&e[1]===216&&e[2]===255){this.content_type=d.IMAGE_MIME_TYPES.jpeg;return}if(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e[4]===13&&e[5]===10&&e[6]===26&&e[7]===10){this.content_type=d.IMAGE_MIME_TYPES.png;return}if(e[0]===71&&e[1]===73&&e[2]===70&&e[3]===56&&(e[4]===55||e[4]===57)&&e[5]===97){this.content_type=d.IMAGE_MIME_TYPES.gif;return}if(e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80){this.content_type=d.IMAGE_MIME_TYPES.webp;return}if(this._content.byteLength>100&&new TextDecoder().decode(new Uint8Array(this._content.slice(0,100))).indexOf("<svg")!==-1){this.content_type=d.IMAGE_MIME_TYPES.svg;return}this.content_type=d.IMAGE_MIME_TYPES.png}};g(d,"IMAGE_MIME_TYPES",{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",tiff:"image/tiff",tif:"image/tiff",avif:"image/avif"});let _=d;const h=class h extends m{constructor(e="audio",t="audio/wav"){super(e,t)}static async create(e){if(e==null)throw new Error("Cannot create AudioFile from null or undefined data");return new h().fromAny(e)}async fromAny(e){if(e instanceof h)return e;if(e instanceof m&&!(e instanceof h)){if(e.isEmpty())throw new Error("Cannot create AudioFile from empty MediaFile");return this.file_name=e.getFileName()||"audio",this.content_type=e.getContentType(),this._content=e.read(),this._validateAudioContentType(),this}const t=await super.fromAny(e);return t.file_name=t.file_name||"audio",t._validateAudioContentType(),t}toAudioElement(){if(typeof window>"u")throw new Error("Audio elements are only available in browser environments");this._ensureContent();const e=this.toBlob(),t=URL.createObjectURL(e),n=new Audio(t);return n.addEventListener("canplaythrough",()=>{setTimeout(()=>URL.revokeObjectURL(t),1e3)}),n}async play(){if(typeof window>"u")throw new Error("Audio playback is only available in browser environments");const e=this.toAudioElement();return new Promise((t,n)=>{e.addEventListener("play",()=>t()),e.addEventListener("error",i=>n(new Error(`Audio playback error: ${i}`))),e.play().catch(n)})}async getDuration(){if(typeof window>"u")throw new Error("Getting audio duration is only available in browser environments");const e=this.toAudioElement();return new Promise(t=>{if(e.duration&&!isNaN(e.duration)){t(e.duration);return}e.addEventListener("loadedmetadata",()=>{t(e.duration)})})}toHtmlPlayer(e={}){const t=this.toBase64(),{controls:n=!0,autoplay:i=!1,loop:o=!1}=e;return`<audio
(function(a,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(a=typeof globalThis<"u"?globalThis:a||self,f(a["media-toolkit"]={}))})(this,function(a){"use strict";var I=Object.defineProperty;var S=(a,f,l)=>f in a?I(a,f,{enumerable:!0,configurable:!0,writable:!0,value:l}):a[f]=l;var E=(a,f,l)=>S(a,typeof f!="symbol"?f+"":f,l);function f(o){return o&&typeof o=="object"&&"file_name"in o&&"content_type"in o&&"content"in o}const l=typeof window>"u";function A(o){try{const e=new URL(o);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}}function U(o){return o.startsWith("data:")||j(o)}function j(o){return/^[A-Za-z0-9+/=]+$/.test(o)&&o.length%4===0}async function F(o){if(!l)return!1;try{return(await(await import("fs/promises")).stat(o)).isFile()}catch{return!1}}function B(o){return o&&typeof o=="object"&&typeof o.data=="string"&&typeof o.type=="string"&&typeof o.name=="string"}async function T(o){if(o==null)return null;if(Array.isArray(o)){const e=o.map(t=>T(t));return Promise.all(e)}if(f(o))try{return await new u().fromDict(o)}catch{return o}return o}class _{static async create(e){if(e==null)throw new Error("Cannot create MediaFile from null or undefined data");const t=await _._detectContentType(e);let n=y.default;return t&&t.startsWith("image/")?n=y.image:t&&t.startsWith("audio/")?n=y.audio:t&&t.startsWith("video/")&&(n=y.video),new n().fromAny(e)}static async _detectContentType(e){var t;if(e instanceof u)return e.getContentType();if(f(e))return e.content_type;if(B(e))return e.type;if(typeof e=="string"&&A(e)){const r=(t=new URL(e).pathname.split(".").pop())==null?void 0:t.toLowerCase();if(r){const s=_._getMimeTypeFromExtension(r);if(s)return s}try{const s=await fetch(e,{method:"HEAD",headers:{"User-Agent":"MediaFile/1.0.0"}});if(s.ok){const c=s.headers.get("content-type");if(c)return c}}catch{}}if(typeof e=="string"&&e.startsWith("data:")){const n=e.match(/^data:([^;,]+)/);if(n&&n[1])return n[1]}if(typeof e=="string"&&typeof window>"u")try{const n=await import("fs/promises"),i=await import("path");await n.access(e);const r=i.extname(e).slice(1).toLowerCase();if(r){const s=_._getMimeTypeFromExtension(r);if(s)return s}}catch{}return typeof Blob<"u"&&e instanceof Blob?e.type:null}static _getMimeTypeFromExtension(e){const t={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",aac:"audio/aac",flac:"audio/flac",m4a:"audio/mp4",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",mp4:"video/mp4",mov:"video/quicktime",avi:"video/x-msvideo",mkv:"video/x-matroska",wmv:"video/x-ms-wmv",webm:"video/webm","3gp":"video/3gpp",flv:"video/x-flv",pdf:"application/pdf",txt:"text/plain",html:"text/html",htm:"text/html",json:"application/json",js:"application/javascript",css:"text/css",xml:"application/xml",zip:"application/zip"};return e in t?t[e]:null}}class u{constructor(e="file",t="application/octet-stream"){E(this,"content_type");E(this,"file_name");E(this,"_content",null);this.content_type=t,this.file_name=e}static async create(e){return _.create(e)}async fromAny(e){if(e==null)throw new Error("Cannot create MediaFile from null or undefined data");if(e instanceof u)return e;if(B(e)){if(this.file_name=e.name||"file",this.content_type=e.type,typeof e.data=="string")return this.fromBase64(e.data);throw new Error("Invalid data format in FileReader object")}if(l&&this._isBuffer(e))return this.fromBytes(e);if(typeof File<"u"&&e instanceof File){this.file_name=e.name,this.content_type=e.type||"application/octet-stream";const t=await e.arrayBuffer();return this.fromBytes(t)}if(typeof Blob<"u"&&e instanceof Blob){const t=await e.arrayBuffer();return this.fromBytes(t)}if(e instanceof ArrayBuffer||e instanceof Uint8Array)return this.fromBytes(e);if(typeof e=="string"){if(A(e))return await this.fromUrl(e);if(U(e))return this.fromBase64(e);if(await F(e))return await this.fromFile(e);throw typeof e=="string"?new Error("Invalid data type for MediaFile "+e):new Error("Invalid data type for MediaFile")}return f(e)?await this.fromDict(e):this}async fromFile(e){if(!l)throw new Error("Loading from file path is only supported in Node.js environment");try{const n=await(await import("fs/promises")).readFile(e),i=await import("path");return this.file_name=i.basename(e),this._content=this._bufferToArrayBuffer(n),this._setContentTypeFromFileName(),this}catch(t){throw new Error(`Failed to load file from path: ${e}. ${t.message}`)}}async fromUrl(e,t){const n=async(i,r)=>await fetch(i,{headers:r||{"User-Agent":"MediaFile/1.0.0"}});try{let i=await n(e,t);if(!i.ok){if(i.status===401||i.status===403){const s=new URL(e);s.search="",i=await n(s.toString(),t)}if(!i.ok)throw new Error(`HTTP error! Status: ${i.status}`)}this.content_type=i.headers.get("content-type")||"application/octet-stream";const r=i.headers.get("content-disposition");if(r){const s=r.match(/filename=(?:['"]?)([^'";\n]+)/i);s&&s[1]&&(this.file_name=s[1])}if(!this.file_name||this.file_name==="file"){const c=new URL(e).pathname.split("/"),p=c[c.length-1];p&&p.trim()!==""?this.file_name=decodeURIComponent(p):this.file_name="downloaded_file"}return this._content=await i.arrayBuffer(),this}catch(i){throw new Error(`Failed to load file from URL: ${e}. ${i.message}`)}}fromBase64(e){const{data:t,mediaType:n}=this._parseBase64Uri(e);n&&(this.content_type=n);try{return this._content=l?this._decodeBase64NodeJs(t):this._decodeBase64Browser(t),this}catch(i){throw new Error(`Failed to decode base64 data: ${i.message}`)}}fromBytes(e){if(typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer){const t=new Uint8Array(e),n=new ArrayBuffer(t.byteLength);return new Uint8Array(n).set(t),this._content=n,this}if(e instanceof Uint8Array)if(typeof SharedArrayBuffer<"u"&&e.buffer instanceof SharedArrayBuffer){const t=new Uint8Array(e);this._content=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}else this._content=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);else if(l&&Buffer.isBuffer(e))if(typeof SharedArrayBuffer<"u"&&e.buffer instanceof SharedArrayBuffer){const t=new Uint8Array(e);this._content=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}else this._content=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);else this._content=new Uint8Array(e).buffer;return this}async fromDict(e){if(!e.content)throw new Error("Invalid FileResult object: missing content");return this.file_name=e.file_name,this.content_type=e.content_type,await this.fromAny(e.content)}toBlob(){if(this._ensureContent(),typeof Blob>"u")throw new Error("Blob is not available in this environment");return new Blob([new Uint8Array(this._content)],{type:this.content_type})}toArrayBuffer(){return this._ensureContent(),typeof SharedArrayBuffer<"u"&&this._content instanceof SharedArrayBuffer?this._content.slice(0):this._content}toUint8Array(){return this._ensureContent(),new Uint8Array(this._content)}toBuffer(){if(this._ensureContent(),!l)throw new Error("Buffer is only available in Node.js environment");return Buffer.from(this._content)}toBase64(e=!0){this._ensureContent();let t;if(l)t=Buffer.from(this._content).toString("base64");else{const n=new Uint8Array(this._content);let i="";const r=10240;for(let s=0;s<n.length;s+=r){const c=n.subarray(s,Math.min(s+r,n.length));i+=String.fromCharCode.apply(null,Array.from(c))}t=btoa(i)}return e?`data:${this.content_type};base64,${t}`:t}toJson(){return{file_name:this.file_name,content_type:this.content_type,content:this.toBase64()}}async save(e){this._ensureContent();const t=e||this.file_name;if(l)try{const n=await import("fs/promises").then(s=>s.default||s),i=await import("path").then(s=>s.default||s);if(!i||typeof i.dirname!="function")throw new Error("Failed to load 'path' module.");const r=i.dirname(t);r!=="."&&await n.mkdir(r,{recursive:!0}).catch(()=>{}),await n.writeFile(t,Buffer.from(this._content))}catch(n){throw new Error(`Failed to save file: ${n.message}`)}else{const n=this.toBlob(),i=URL.createObjectURL(n),r=document.createElement("a");r.href=i,r.download=t,document.body.appendChild(r),r.click(),setTimeout(()=>{document.body.removeChild(r),URL.revokeObjectURL(i)},100)}}fileSize(e="bytes"){if(!this._content)return 0;const t=this._content.byteLength;switch(e){case"kb":return t/1024;case"mb":return t/(1024*1024);case"gb":return t/(1024*1024*1024);default:return t}}get extension(){var e;if(this.content_type&&this.content_type!=="application/octet-stream"){const t={"image/jpeg":"jpg","image/png":"png","image/gif":"gif","image/webp":"webp","image/svg+xml":"svg","audio/mpeg":"mp3","audio/wav":"wav","audio/ogg":"ogg","video/mp4":"mp4","video/quicktime":"mov","application/pdf":"pdf","text/plain":"txt","text/html":"html","application/json":"json",npz:"npz"};if(this.content_type in t)return t[this.content_type];if(l)try{const i=require("mime-types").extension(this.content_type);if(i)return i}catch{}}return this.file_name&&this.file_name.includes(".")&&((e=this.file_name.split(".").pop())==null?void 0:e.toLowerCase())||null}getFileName(){return this.file_name}setFileName(e){this.file_name=e}getContentType(){return this.content_type}setContentType(e){this.content_type=e}read(){return this._ensureContent(),this._content}isEmpty(){return!this._content||this._content.byteLength===0}getInfo(){return{fileName:this.file_name,contentType:this.content_type,size:this.fileSize(),extension:this.extension}}_setContentTypeFromFileName(){var n;if(!this.file_name)return;const e=(n=this.file_name.split(".").pop())==null?void 0:n.toLowerCase();if(!e)return;if(l)try{const r=require("mime-types").lookup(this.file_name);if(r){this.content_type=r;return}}catch{}const t={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",mp4:"video/mp4",mov:"video/quicktime",pdf:"application/pdf",txt:"text/plain",html:"text/html",htm:"text/html",json:"application/json",js:"application/javascript",css:"text/css",xml:"application/xml",zip:"application/zip"};e in t&&(this.content_type=t[e])}_parseBase64Uri(e){if(e.startsWith("data:")){const[t,n]=e.split(",",2),i=t.match(/^data:([^;,]+)/),r=i?i[1]:null;return{data:n,mediaType:r}}return{data:e,mediaType:null}}_ensureContent(){if(!this._content)throw new Error("No content available. Load content first using fromFile, fromUrl, etc.")}_isBuffer(e){return l&&Buffer.isBuffer(e)}_decodeBase64NodeJs(e){const t=Buffer.from(e,"base64");return this._bufferToArrayBuffer(t)}_decodeBase64Browser(e){const t=atob(e),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n.buffer}_bufferToArrayBuffer(e){if(typeof SharedArrayBuffer<"u"&&e.buffer instanceof SharedArrayBuffer){const t=new ArrayBuffer(e.byteLength);return new Uint8Array(t).set(new Uint8Array(e)),t}else return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}}const d={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",aac:"audio/aac",flac:"audio/flac",m4a:"audio/mp4",webm:"audio/webm"},m={mp4:"video/mp4",mov:"video/quicktime",avi:"video/x-msvideo",mkv:"video/x-matroska",wmv:"video/x-ms-wmv",webm:"video/webm","3gp":"video/3gpp",flv:"video/x-flv"},h={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",tiff:"image/tiff",tif:"image/tiff",avif:"image/avif"},x={...d,...m,...h};function L(o){const e=[];switch(o){case"audio":e.push(...Object.values(d)),e.push(...Object.keys(d).map(t=>`.${t}`));break;case"video":e.push(...Object.values(m)),e.push(...Object.keys(m).map(t=>`.${t}`));break;case"image":e.push(...Object.values(h)),e.push(...Object.keys(h).map(t=>`.${t}`));break;case"file":default:return["*/*"]}return e}function M(o){if(o.includes("file"))return["*/*"];const e=[];return o.forEach(t=>{e.push(...L(t))}),[...new Set(e)]}function O(o){return{audio:"Audio",video:"Video",image:"Images",file:"Files"}[o]||o}function C(o){switch(o){case"audio":return Object.keys(d);case"video":return Object.keys(m);case"image":return Object.keys(h);default:return[]}}function k(o,e){const t=o.startsWith(".")?o.substring(1):o;return C(e).includes(t.toLowerCase())}function $(o){return Object.values(d).includes(o)?"audio":Object.values(m).includes(o)?"video":Object.values(h).includes(o)?"image":null}class w extends u{constructor(e="image",t="image/png"){super(e,t)}static async create(e){if(e==null)throw new Error("Cannot create ImageFile from null or undefined data");return new w().fromAny(e)}async fromAny(e){if(e instanceof w)return e;if(e instanceof u&&!(e instanceof w)){if(e.isEmpty())throw new Error("Cannot create ImageFile from empty MediaFile");return this.file_name=e.getFileName()||"image",this.content_type=e.getContentType(),this._content=e.read(),this._validateImageContentType(),this}const t=await super.fromAny(e);return t.file_name=t.file_name||"image",t._validateImageContentType(),t}toImageElement(e={}){if(typeof window>"u")throw new Error("Image elements are only available in browser environments");this._ensureContent();const t=this.toBase64(),{width:n,height:i,alt:r="",className:s=""}=e,c=n?` width="${n}"`:"",p=i?` height="${i}"`:"",b=s?` class="${s}"`:"";return`<img src="${t}" alt="${r}"${c}${p}${b}>`}toDOMImageElement(e={}){if(typeof window>"u")throw new Error("DOM Image elements are only available in browser environments");this._ensureContent();const t=this.toBlob(),n=URL.createObjectURL(t),i=new Image;return e.width&&(i.width=e.width),e.height&&(i.height=e.height),e.alt&&(i.alt=e.alt),e.className&&(i.className=e.className),i.src=n,i.addEventListener("load",()=>{setTimeout(()=>URL.revokeObjectURL(n),1e3)}),i}async getDimensions(){if(typeof window>"u")throw new Error("Getting image dimensions is only available in browser environments");return new Promise((e,t)=>{const n=new Image;n.onload=()=>{e({width:n.naturalWidth,height:n.naturalHeight})},n.onerror=()=>{t(new Error("Failed to load image for dimension calculation"))};const i=this.toBlob(),r=URL.createObjectURL(i);n.src=r,n.addEventListener("load",()=>{URL.revokeObjectURL(r)},{once:!0})})}_validateImageContentType(){var t;if(this.content_type.startsWith("image/"))return;const e=(t=this.extension)==null?void 0:t.toLowerCase();if(e&&e in h){this.content_type=h[e];return}this._content&&this._detectImageFormat()}_detectImageFormat(){const e=new Uint8Array(this._content).slice(0,12);if(e[0]===255&&e[1]===216&&e[2]===255){this.content_type=h.jpeg;return}if(e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71&&e[4]===13&&e[5]===10&&e[6]===26&&e[7]===10){this.content_type=h.png;return}if(e[0]===71&&e[1]===73&&e[2]===70&&e[3]===56&&(e[4]===55||e[4]===57)&&e[5]===97){this.content_type=h.gif;return}if(e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80){this.content_type=h.webp;return}if(this._content.byteLength>100&&new TextDecoder().decode(new Uint8Array(this._content.slice(0,100))).indexOf("<svg")!==-1){this.content_type=h.svg;return}this.content_type=h.png}}class g extends u{constructor(e="audio",t="audio/wav"){super(e,t)}static async create(e){if(e==null)throw new Error("Cannot create AudioFile from null or undefined data");return new g().fromAny(e)}async fromAny(e){if(e instanceof g)return e;if(e instanceof u&&!(e instanceof g)){if(e.isEmpty())throw new Error("Cannot create AudioFile from empty MediaFile");return this.file_name=e.getFileName()||"audio",this.content_type=e.getContentType(),this._content=e.read(),this._validateAudioContentType(),this}const t=await super.fromAny(e);return t.file_name=t.file_name||"audio",t._validateAudioContentType(),t}toAudioElement(){if(typeof window>"u")throw new Error("Audio elements are only available in browser environments");this._ensureContent();const e=this.toBlob(),t=URL.createObjectURL(e),n=new Audio(t);return n.addEventListener("canplaythrough",()=>{setTimeout(()=>URL.revokeObjectURL(t),1e3)}),n}async play(){if(typeof window>"u")throw new Error("Audio playback is only available in browser environments");const e=this.toAudioElement();return new Promise((t,n)=>{e.addEventListener("play",()=>t()),e.addEventListener("error",i=>n(new Error(`Audio playback error: ${i}`))),e.play().catch(n)})}async getDuration(){if(typeof window>"u")throw new Error("Getting audio duration is only available in browser environments");const e=this.toAudioElement();return new Promise(t=>{if(e.duration&&!isNaN(e.duration)){t(e.duration);return}e.addEventListener("loadedmetadata",()=>{t(e.duration)})})}toHTMLPlayer(e={}){const t=this.toBase64(),{controls:n=!0,autoplay:i=!1,loop:r=!1}=e;return`<audio
src="${t}"
${n?"controls":""}
${i?"autoplay":""}
${o?"loop":""}>
${r?"loop":""}>
Your browser does not support the audio element.
</audio>`}_validateAudioContentType(){var t;if(this.content_type.startsWith("audio/"))return;const e=(t=this.extension)==null?void 0:t.toLowerCase();if(e&&e in h.AUDIO_MIME_TYPES){this.content_type=h.AUDIO_MIME_TYPES[e];return}this._content&&this._detectAudioFormat()}_detectAudioFormat(){const e=new Uint8Array(this._content).slice(0,12);if(e[0]===73&&e[1]===68&&e[2]===51){this.content_type=h.AUDIO_MIME_TYPES.mp3;return}if(e[0]===255&&(e[1]&224)===224){this.content_type=h.AUDIO_MIME_TYPES.mp3;return}if(e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===65&&e[10]===86&&e[11]===69){this.content_type=h.AUDIO_MIME_TYPES.wav;return}if(e[0]===79&&e[1]===103&&e[2]===103&&e[3]===83){this.content_type=h.AUDIO_MIME_TYPES.ogg;return}if(e[0]===102&&e[1]===76&&e[2]===97&&e[3]===67){this.content_type=h.AUDIO_MIME_TYPES.flac;return}this.content_type=h.AUDIO_MIME_TYPES.mp3}};g(h,"AUDIO_MIME_TYPES",{mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",aac:"audio/aac",flac:"audio/flac",m4a:"audio/mp4",webm:"audio/webm"});let v=h;const u=class u extends m{constructor(e="video",t="video/mp4"){super(e,t)}static async create(e){if(e==null)throw new Error("Cannot create VideoFile from null or undefined data");return new u().fromAny(e)}async fromAny(e){if(e instanceof u)return e;if(e instanceof m&&!(e instanceof u)){if(e.isEmpty())throw new Error("Cannot create VideoFile from empty MediaFile");return this.file_name=e.getFileName()||"video",this.content_type=e.getContentType(),this._content=e.read(),this._validateVideoContentType(),this}const t=await super.fromAny(e);return t.file_name=t.file_name||"video",t._validateVideoContentType(),t}toVideoElement(){if(typeof window>"u")throw new Error("Video elements are only available in browser environments");this._ensureContent();const e=this.toBlob(),t=URL.createObjectURL(e),n=document.createElement("video");return n.src=t,n.addEventListener("loadedmetadata",()=>{setTimeout(()=>URL.revokeObjectURL(t),1e3)}),n}async play(){if(typeof window>"u")throw new Error("Video playback is only available in browser environments");const e=this.toVideoElement();return new Promise((t,n)=>{e.addEventListener("play",()=>t()),e.addEventListener("error",i=>n(new Error(`Video playback error: ${i}`))),e.play().catch(n)})}async getDuration(){if(typeof window>"u")throw new Error("Getting video duration is only available in browser environments");const e=this.toVideoElement();return new Promise(t=>{if(e.duration&&!isNaN(e.duration)){t(e.duration);return}e.addEventListener("loadedmetadata",()=>{t(e.duration)})})}async getDimensions(){if(typeof window>"u")throw new Error("Getting video dimensions is only available in browser environments");const e=this.toVideoElement();return new Promise(t=>{if(e.videoWidth&&e.videoHeight){t({width:e.videoWidth,height:e.videoHeight});return}e.addEventListener("loadedmetadata",()=>{t({width:e.videoWidth,height:e.videoHeight})})})}async createThumbnail(e=0){if(typeof window>"u")throw new Error("Creating thumbnails is only available in browser environments");const t=this.toVideoElement();return new Promise((n,i)=>{t.addEventListener("loadedmetadata",async()=>{try{t.currentTime=e,await new Promise(f=>{const p=()=>{t.removeEventListener("seeked",p),f()};t.addEventListener("seeked",p)});const o=document.createElement("canvas");o.width=t.videoWidth,o.height=t.videoHeight;const r=o.getContext("2d");if(!r)throw new Error("Failed to get canvas context");r.drawImage(t,0,0,o.width,o.height),o.toBlob(f=>{f?n(f):i(new Error("Failed to create thumbnail blob"))},"image/jpeg",.95)}catch(o){i(o)}}),t.addEventListener("error",o=>{i(new Error(`Video loading error: ${o}`))})})}toHtmlPlayer(e={}){const t=this.toBase64(),{controls:n=!0,autoplay:i=!1,loop:o=!1,muted:r=!1,width:f,height:p,poster:E}=e;return`<video
</audio>`}_validateAudioContentType(){var t;if(this.content_type.startsWith("audio/"))return;const e=(t=this.extension)==null?void 0:t.toLowerCase();if(e&&e in d){this.content_type=d[e];return}this._content&&this._detectAudioFormat()}_detectAudioFormat(){const e=new Uint8Array(this._content).slice(0,12);if(e[0]===73&&e[1]===68&&e[2]===51){this.content_type=d.mp3;return}if(e[0]===255&&(e[1]&224)===224){this.content_type=d.mp3;return}if(e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===65&&e[10]===86&&e[11]===69){this.content_type=d.wav;return}if(e[0]===79&&e[1]===103&&e[2]===103&&e[3]===83){this.content_type=d.ogg;return}if(e[0]===102&&e[1]===76&&e[2]===97&&e[3]===67){this.content_type=d.flac;return}this.content_type=d.mp3}}class v extends u{constructor(e="video",t="video/mp4"){super(e,t)}static async create(e){if(e==null)throw new Error("Cannot create VideoFile from null or undefined data");return new v().fromAny(e)}async fromAny(e){if(e instanceof v)return e;if(e instanceof u&&!(e instanceof v)){if(e.isEmpty())throw new Error("Cannot create VideoFile from empty MediaFile");return this.file_name=e.getFileName()||"video",this.content_type=e.getContentType(),this._content=e.read(),this._validateVideoContentType(),this}const t=await super.fromAny(e);return t.file_name=t.file_name||"video",t._validateVideoContentType(),t}toVideoElement(){if(typeof window>"u")throw new Error("Video elements are only available in browser environments");this._ensureContent();const e=this.toBlob(),t=URL.createObjectURL(e),n=document.createElement("video");return n.src=t,n.addEventListener("loadedmetadata",()=>{setTimeout(()=>URL.revokeObjectURL(t),1e3)}),n}async play(){if(typeof window>"u")throw new Error("Video playback is only available in browser environments");const e=this.toVideoElement();return new Promise((t,n)=>{e.addEventListener("play",()=>t()),e.addEventListener("error",i=>n(new Error(`Video playback error: ${i}`))),e.play().catch(n)})}async getDuration(){if(typeof window>"u")throw new Error("Getting video duration is only available in browser environments");const e=this.toVideoElement();return new Promise(t=>{if(e.duration&&!isNaN(e.duration)){t(e.duration);return}e.addEventListener("loadedmetadata",()=>{t(e.duration)})})}async getDimensions(){if(typeof window>"u")throw new Error("Getting video dimensions is only available in browser environments");const e=this.toVideoElement();return new Promise(t=>{if(e.videoWidth&&e.videoHeight){t({width:e.videoWidth,height:e.videoHeight});return}e.addEventListener("loadedmetadata",()=>{t({width:e.videoWidth,height:e.videoHeight})})})}async createThumbnail(e=0){if(typeof window>"u")throw new Error("Creating thumbnails is only available in browser environments");const t=this.toVideoElement();return new Promise((n,i)=>{t.addEventListener("loadedmetadata",async()=>{try{t.currentTime=e,await new Promise(c=>{const p=()=>{t.removeEventListener("seeked",p),c()};t.addEventListener("seeked",p)});const r=document.createElement("canvas");r.width=t.videoWidth,r.height=t.videoHeight;const s=r.getContext("2d");if(!s)throw new Error("Failed to get canvas context");s.drawImage(t,0,0,r.width,r.height),r.toBlob(c=>{c?n(c):i(new Error("Failed to create thumbnail blob"))},"image/jpeg",.95)}catch(r){i(r)}}),t.addEventListener("error",r=>{i(new Error(`Video loading error: ${r}`))})})}toHtmlPlayer(e={}){const t=this.toBase64(),{controls:n=!0,autoplay:i=!1,loop:r=!1,muted:s=!1,width:c,height:p,poster:b}=e;return`<video
src="${t}"
${n?"controls":""}
${i?"autoplay":""}
${o?"loop":""}
${r?"muted":""}
${f?`width="${f}"`:""}
${r?"loop":""}
${s?"muted":""}
${c?`width="${c}"`:""}
${p?`height="${p}"`:""}
${E?`poster="${E}"`:""}>
${b?`poster="${b}"`:""}>
Your browser does not support the video element.
</video>`}_validateVideoContentType(){var t;if(this.content_type.startsWith("video/"))return;const e=(t=this.extension)==null?void 0:t.toLowerCase();if(e&&e in u.VIDEO_MIME_TYPES){this.content_type=u.VIDEO_MIME_TYPES[e];return}this._content&&this._detectVideoFormat()}_detectVideoFormat(){const e=new Uint8Array(this._content).slice(0,16);if(e[4]===102&&e[5]===116&&e[6]===121&&e[7]===112){this.content_type=u.VIDEO_MIME_TYPES.mp4;return}if(e[4]===119&&e[5]===105&&e[6]===100&&e[7]===101||e[4]===109&&e[5]===100&&e[6]===97&&e[7]===116||e[4]===102&&e[5]===114&&e[6]===101&&e[7]===101||e[4]===112&&e[5]===110&&e[6]===111&&e[7]===116||e[4]===115&&e[5]===107&&e[6]===105&&e[7]===112||e[4]===109&&e[5]===111&&e[6]===111&&e[7]===118){this.content_type=u.VIDEO_MIME_TYPES.mov;return}if(e[0]===26&&e[1]===69&&e[2]===223&&e[3]===163){this.content_type=u.VIDEO_MIME_TYPES.webm;return}if(e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===65&&e[9]===86&&e[10]===73&&e[11]===32){this.content_type=u.VIDEO_MIME_TYPES.avi;return}if(e[0]===70&&e[1]===76&&e[2]===86){this.content_type=u.VIDEO_MIME_TYPES.flv;return}if(e[4]===102&&e[5]===116&&e[6]===121&&e[7]===112&&e[8]===51&&e[9]===103&&e[10]===112){this.content_type=u.VIDEO_MIME_TYPES["3gp"];return}this.content_type=u.VIDEO_MIME_TYPES.mp4}};g(u,"VIDEO_MIME_TYPES",{mp4:"video/mp4",mov:"video/quicktime",avi:"video/x-msvideo",mkv:"video/x-matroska",wmv:"video/x-ms-wmv",webm:"video/webm","3gp":"video/3gpp",flv:"video/x-flv"});let b=u;const y={};y.default=m,y.image=_,y.audio=v,y.video=b,y.media=m,typeof window<"u"&&(window.MediaFile=m,window.ImageFile=_,window.AudioFile=v,window.AudioFile=b),typeof module<"u"&&typeof module.exports<"u"&&(module.exports={MediaFile:m,ImageFile:_,AudioFile:v,VideoFile:b,MediaFileFactory:w}),a.AudioFile=v,a.ImageFile=_,a.MediaFile=m,a.MediaFileFactory=w,a.VideoFile=b,a.isFileReaderObject=M,a.isFileResult=c,a.isUrl=A,a.isValidFilePath=T,a.parseSocaityAPIJobResult=I,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
</video>`}_validateVideoContentType(){var t;if(this.content_type.startsWith("video/"))return;const e=(t=this.extension)==null?void 0:t.toLowerCase();if(e&&e in m){this.content_type=m[e];return}this._content&&this._detectVideoFormat()}_detectVideoFormat(){const e=new Uint8Array(this._content).slice(0,16);if(e[4]===102&&e[5]===116&&e[6]===121&&e[7]===112){this.content_type=m.mp4;return}if(e[4]===119&&e[5]===105&&e[6]===100&&e[7]===101||e[4]===109&&e[5]===100&&e[6]===97&&e[7]===116||e[4]===102&&e[5]===114&&e[6]===101&&e[7]===101||e[4]===112&&e[5]===110&&e[6]===111&&e[7]===116||e[4]===115&&e[5]===107&&e[6]===105&&e[7]===112||e[4]===109&&e[5]===111&&e[6]===111&&e[7]===118){this.content_type=m.mov;return}if(e[0]===26&&e[1]===69&&e[2]===223&&e[3]===163){this.content_type=m.webm;return}if(e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===65&&e[9]===86&&e[10]===73&&e[11]===32){this.content_type=m.avi;return}if(e[0]===70&&e[1]===76&&e[2]===86){this.content_type=m.flv;return}if(e[4]===102&&e[5]===116&&e[6]===121&&e[7]===112&&e[8]===51&&e[9]===103&&e[10]===112){this.content_type=m["3gp"];return}this.content_type=m.mp4}}const y={};y.default=u,y.image=w,y.audio=g,y.video=v,y.media=u,typeof window<"u"&&(window.MediaFile=u,window.ImageFile=w,window.AudioFile=g,window.AudioFile=v),typeof module<"u"&&typeof module.exports<"u"&&(module.exports={MediaFile:u,ImageFile:w,AudioFile:g,VideoFile:v,MediaFileFactory:_}),a.ALL_MIME_TYPES=x,a.AUDIO_MIME_TYPES=d,a.AudioFile=g,a.IMAGE_MIME_TYPES=h,a.ImageFile=w,a.MediaFile=u,a.MediaFileFactory=_,a.VIDEO_MIME_TYPES=m,a.VideoFile=v,a.detectCategoryFromMimeType=$,a.getAcceptedTypes=L,a.getAcceptedTypesForCategories=M,a.getCategoryDisplayName=O,a.getFileExtensions=C,a.isExtensionSupported=k,a.isFileReaderObject=B,a.isFileResult=f,a.isUrl=A,a.isValidFilePath=F,a.parseSocaityAPIJobResult=T,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=media-toolkit.umd.js.map
{
"name": "@socaity/media-toolkit",
"version": "0.0.3",
"version": "0.0.5",
"type": "module",

@@ -5,0 +5,0 @@ "description": "Web-ready standardized file processing and serialization. Read, write, convert and send files. Including image, audio, video and any other file. Easily convert between base64, bytes, numpy and more. Create browser elements or use in node.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display