@drovp/encode
Version:
Encode video, audio, and images into common formats.
1,268 lines (1,252 loc) • 359 kB
JavaScript
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
// node_modules/@drovp/utils/dist/modal-window.js
var require_modal_window = __commonJS({
"node_modules/@drovp/utils/dist/modal-window.js"(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.openContextMenu = exports2.showSaveDialog = exports2.showOpenDialog = exports2.resolve = exports2.getPayload = void 0;
var { ipcRenderer: ipcRenderer2, shell, clipboard } = require("electron");
function getPayload2() {
return ipcRenderer2.invoke("get-modal-window-payload");
}
exports2.getPayload = getPayload2;
function resolve2(payload) {
ipcRenderer2.invoke("resolve-modal-window", payload);
}
exports2.resolve = resolve2;
function showOpenDialog(options) {
return ipcRenderer2.invoke("show-open-dialog", options);
}
exports2.showOpenDialog = showOpenDialog;
function showSaveDialog2(options) {
return ipcRenderer2.invoke("show-save-dialog", options);
}
exports2.showSaveDialog = showSaveDialog2;
async function openContextMenu3(items) {
const serializableItems = items ? JSON.parse(JSON.stringify(items)) : void 0;
const path = await ipcRenderer2.invoke("open-context-menu", serializableItems);
if (!Array.isArray(path))
return;
let walker = items;
for (let i3 = 0; i3 < path.length; i3++) {
const index = path[i3];
if (Array.isArray(walker)) {
const item = walker[index];
if (item)
walker = i3 < path.length - 1 ? item.submenu : item.click;
} else {
walker = void 0;
}
}
if (typeof walker === "function") {
walker();
} else {
throw new Error(`Invalid context menu item click handler.`);
}
}
exports2.openContextMenu = openContextMenu3;
window.addEventListener("contextmenu", (event) => {
var _a2;
if (event.defaultPrevented)
return;
event.preventDefault();
event.stopPropagation();
if (!((event === null || event === void 0 ? void 0 : event.target) instanceof HTMLElement))
return;
const selection = (_a2 = window.getSelection()) === null || _a2 === void 0 ? void 0 : _a2.toString();
if (selection && selection.length > 0) {
openContextMenu3([{ role: "copy" }, { type: "separator" }, { role: "selectAll" }]);
return;
}
if (event.target.closest("select")) {
openContextMenu3();
return;
}
const editableInput = event.target.closest("input:not([read-only]),textarea:not([read-only])");
if (editableInput) {
openContextMenu3([
{ role: "undo" },
{ role: "redo" },
{ type: "separator" },
{ role: "cut" },
{ role: "copy" },
{ role: "paste" },
{ type: "separator" },
{ role: "selectAll" }
]);
return;
}
const anchor = event.target.closest("a[href]");
if (anchor) {
const href = anchor.href;
if (href) {
openContextMenu3([
{ label: "Open", click: () => shell.openExternal(href) },
{ label: "Copy", click: () => clipboard.writeText(href) }
]);
}
return;
}
openContextMenu3();
});
}
});
// node_modules/platform-paths/dist/index.js
var require_dist = __commonJS({
"node_modules/platform-paths/dist/index.js"(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.isPlatformPathIdentifier = exports2.clearCache = exports2.platformPaths = exports2.getDesktopPath = exports2.getVideosPath = exports2.getMusicPath = exports2.getPicturesPath = exports2.getDocumentsPath = exports2.getDownloadsPath = exports2.getHomePath = exports2.getTmpPath = exports2.getPlatformPath = void 0;
var OS2 = require("os");
var CP = require("child_process");
var fs_1 = require("fs");
var util_1 = require("util");
var exec = (0, util_1.promisify)(CP.exec);
var cachedPaths = /* @__PURE__ */ new Map();
var getters = {
tmp: async () => OS2.tmpdir(),
home: async () => OS2.homedir(),
downloads: () => getPath("Downloads", "Downloads", "DOWNLOAD", "Downloads", "/tmp/"),
documents: () => getPath("Personal", "Documents", "DOCUMENTS", "Documents"),
pictures: () => getPath("My Pictures", "Pictures", "PICTURES", "Pictures"),
music: () => getPath("My Music", "Music", "MUSIC", "Music"),
videos: () => getPath("My Video", "Videos", "VIDEOS", "Videos"),
desktop: () => getPath("Desktop", "Desktop", "DESKTOP", "Desktop")
};
async function getPlatformPath(name, { maxAge = 0 } = {}) {
if (!isPlatformPathIdentifier(name))
throw new Error(`Unknown platform path identifier "${name}".`);
const cached = cachedPaths.get(name);
if (cached && Date.now() - cached.createdAt < maxAge)
return cached.value;
const value = await getters[name]();
cachedPaths.set(name, { value, createdAt: Date.now() });
return value;
}
exports2.getPlatformPath = getPlatformPath;
var getTmpPath = (options) => getPlatformPath("tmp", options);
exports2.getTmpPath = getTmpPath;
var getHomePath = (options) => getPlatformPath("home", options);
exports2.getHomePath = getHomePath;
var getDownloadsPath = (options) => getPlatformPath("downloads", options);
exports2.getDownloadsPath = getDownloadsPath;
var getDocumentsPath = (options) => getPlatformPath("documents", options);
exports2.getDocumentsPath = getDocumentsPath;
var getPicturesPath = (options) => getPlatformPath("pictures", options);
exports2.getPicturesPath = getPicturesPath;
var getMusicPath = (options) => getPlatformPath("music", options);
exports2.getMusicPath = getMusicPath;
var getVideosPath = (options) => getPlatformPath("videos", options);
exports2.getVideosPath = getVideosPath;
var getDesktopPath = (options) => getPlatformPath("desktop", options);
exports2.getDesktopPath = getDesktopPath;
exports2.platformPaths = {
tmp: exports2.getTmpPath,
home: exports2.getHomePath,
downloads: exports2.getDownloadsPath,
documents: exports2.getDocumentsPath,
pictures: exports2.getPicturesPath,
music: exports2.getMusicPath,
videos: exports2.getVideosPath,
desktop: exports2.getDesktopPath
};
function clearCache() {
cachedPaths.clear();
}
exports2.clearCache = clearCache;
function isPlatformPathIdentifier(name) {
return getters.hasOwnProperty(name);
}
exports2.isPlatformPathIdentifier = isPlatformPathIdentifier;
async function getPath(winName, darwinName, xdgName, linuxName, linuxBackup) {
switch (OS2.platform()) {
case "win32":
return getWinRegistryPath(winName);
case "darwin":
return `${OS2.homedir()}/${darwinName}`;
case "linux":
return getLinuxPath(xdgName, linuxName, linuxBackup);
}
throw new Error(`Unsupported platform.`);
}
async function getLinuxPath(xdgName, folderName, fallback) {
const homeDir = OS2.homedir();
try {
let path = (await exec(`xdg-user-dir ${xdgName}`, { encoding: "utf8" })).stdout.trim();
if (path && path !== homeDir)
return path;
} catch (_a2) {
}
try {
const path = `${homeDir}/${folderName}`;
if ((await fs_1.promises.stat(path)).isDirectory())
return path;
} catch (_b) {
}
if (fallback)
return fallback;
throw new Error(`Couldn't resolve Documents directory.`);
}
async function getWinRegistryPath(name) {
const key = name === "Downloads" ? "{374DE290-123F-4565-9164-39C4925E467B}" : name;
const homeDir = OS2.homedir();
const { stdout, stderr } = await exec(`reg query "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders"`);
if (stderr)
throw new Error(stderr);
let value;
for (const line of stdout.split("\r\n").map((line2) => line2.trim())) {
if (!line.startsWith(key))
continue;
const parts = line.split(/ +REG_EXPAND_SZ +/);
if (parts.length === 2) {
value = parts[1];
break;
} else {
throw new Error(`Unexpected registry output:
${line}`);
}
}
if (!value) {
if (name === "Downloads")
return `${homeDir}\\Downloads`;
throw new Error(`No registry match for "${name}". stdout:
${stdout}`);
}
return value.replace("%USERPROFILE%", homeDir);
}
}
});
// node_modules/dayjs/dayjs.min.js
var require_dayjs_min = __commonJS({
"node_modules/dayjs/dayjs.min.js"(exports2, module2) {
!function(t3, e3) {
"object" == typeof exports2 && "undefined" != typeof module2 ? module2.exports = e3() : "function" == typeof define && define.amd ? define(e3) : (t3 = "undefined" != typeof globalThis ? globalThis : t3 || self).dayjs = e3();
}(exports2, function() {
"use strict";
var t3 = 1e3, e3 = 6e4, n2 = 36e5, r3 = "millisecond", i3 = "second", s3 = "minute", u3 = "hour", a3 = "day", o3 = "week", c3 = "month", f3 = "quarter", h3 = "year", d3 = "date", l3 = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y3 = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M2 = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(t4) {
var e4 = ["th", "st", "nd", "rd"], n3 = t4 % 100;
return "[" + t4 + (e4[(n3 - 20) % 10] || e4[n3] || e4[0]) + "]";
} }, m3 = function(t4, e4, n3) {
var r4 = String(t4);
return !r4 || r4.length >= e4 ? t4 : "" + Array(e4 + 1 - r4.length).join(n3) + t4;
}, v3 = { s: m3, z: function(t4) {
var e4 = -t4.utcOffset(), n3 = Math.abs(e4), r4 = Math.floor(n3 / 60), i4 = n3 % 60;
return (e4 <= 0 ? "+" : "-") + m3(r4, 2, "0") + ":" + m3(i4, 2, "0");
}, m: function t4(e4, n3) {
if (e4.date() < n3.date()) return -t4(n3, e4);
var r4 = 12 * (n3.year() - e4.year()) + (n3.month() - e4.month()), i4 = e4.clone().add(r4, c3), s4 = n3 - i4 < 0, u4 = e4.clone().add(r4 + (s4 ? -1 : 1), c3);
return +(-(r4 + (n3 - i4) / (s4 ? i4 - u4 : u4 - i4)) || 0);
}, a: function(t4) {
return t4 < 0 ? Math.ceil(t4) || 0 : Math.floor(t4);
}, p: function(t4) {
return { M: c3, y: h3, w: o3, d: a3, D: d3, h: u3, m: s3, s: i3, ms: r3, Q: f3 }[t4] || String(t4 || "").toLowerCase().replace(/s$/, "");
}, u: function(t4) {
return void 0 === t4;
} }, g3 = "en", D2 = {};
D2[g3] = M2;
var p3 = "$isDayjsObject", S2 = function(t4) {
return t4 instanceof _2 || !(!t4 || !t4[p3]);
}, w3 = function t4(e4, n3, r4) {
var i4;
if (!e4) return g3;
if ("string" == typeof e4) {
var s4 = e4.toLowerCase();
D2[s4] && (i4 = s4), n3 && (D2[s4] = n3, i4 = s4);
var u4 = e4.split("-");
if (!i4 && u4.length > 1) return t4(u4[0]);
} else {
var a4 = e4.name;
D2[a4] = e4, i4 = a4;
}
return !r4 && i4 && (g3 = i4), i4 || !r4 && g3;
}, O2 = function(t4, e4) {
if (S2(t4)) return t4.clone();
var n3 = "object" == typeof e4 ? e4 : {};
return n3.date = t4, n3.args = arguments, new _2(n3);
}, b3 = v3;
b3.l = w3, b3.i = S2, b3.w = function(t4, e4) {
return O2(t4, { locale: e4.$L, utc: e4.$u, x: e4.$x, $offset: e4.$offset });
};
var _2 = function() {
function M3(t4) {
this.$L = w3(t4.locale, null, true), this.parse(t4), this.$x = this.$x || t4.x || {}, this[p3] = true;
}
var m4 = M3.prototype;
return m4.parse = function(t4) {
this.$d = function(t5) {
var e4 = t5.date, n3 = t5.utc;
if (null === e4) return /* @__PURE__ */ new Date(NaN);
if (b3.u(e4)) return /* @__PURE__ */ new Date();
if (e4 instanceof Date) return new Date(e4);
if ("string" == typeof e4 && !/Z$/i.test(e4)) {
var r4 = e4.match($);
if (r4) {
var i4 = r4[2] - 1 || 0, s4 = (r4[7] || "0").substring(0, 3);
return n3 ? new Date(Date.UTC(r4[1], i4, r4[3] || 1, r4[4] || 0, r4[5] || 0, r4[6] || 0, s4)) : new Date(r4[1], i4, r4[3] || 1, r4[4] || 0, r4[5] || 0, r4[6] || 0, s4);
}
}
return new Date(e4);
}(t4), this.init();
}, m4.init = function() {
var t4 = this.$d;
this.$y = t4.getFullYear(), this.$M = t4.getMonth(), this.$D = t4.getDate(), this.$W = t4.getDay(), this.$H = t4.getHours(), this.$m = t4.getMinutes(), this.$s = t4.getSeconds(), this.$ms = t4.getMilliseconds();
}, m4.$utils = function() {
return b3;
}, m4.isValid = function() {
return !(this.$d.toString() === l3);
}, m4.isSame = function(t4, e4) {
var n3 = O2(t4);
return this.startOf(e4) <= n3 && n3 <= this.endOf(e4);
}, m4.isAfter = function(t4, e4) {
return O2(t4) < this.startOf(e4);
}, m4.isBefore = function(t4, e4) {
return this.endOf(e4) < O2(t4);
}, m4.$g = function(t4, e4, n3) {
return b3.u(t4) ? this[e4] : this.set(n3, t4);
}, m4.unix = function() {
return Math.floor(this.valueOf() / 1e3);
}, m4.valueOf = function() {
return this.$d.getTime();
}, m4.startOf = function(t4, e4) {
var n3 = this, r4 = !!b3.u(e4) || e4, f4 = b3.p(t4), l4 = function(t5, e5) {
var i4 = b3.w(n3.$u ? Date.UTC(n3.$y, e5, t5) : new Date(n3.$y, e5, t5), n3);
return r4 ? i4 : i4.endOf(a3);
}, $2 = function(t5, e5) {
return b3.w(n3.toDate()[t5].apply(n3.toDate("s"), (r4 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e5)), n3);
}, y4 = this.$W, M4 = this.$M, m5 = this.$D, v4 = "set" + (this.$u ? "UTC" : "");
switch (f4) {
case h3:
return r4 ? l4(1, 0) : l4(31, 11);
case c3:
return r4 ? l4(1, M4) : l4(0, M4 + 1);
case o3:
var g4 = this.$locale().weekStart || 0, D3 = (y4 < g4 ? y4 + 7 : y4) - g4;
return l4(r4 ? m5 - D3 : m5 + (6 - D3), M4);
case a3:
case d3:
return $2(v4 + "Hours", 0);
case u3:
return $2(v4 + "Minutes", 1);
case s3:
return $2(v4 + "Seconds", 2);
case i3:
return $2(v4 + "Milliseconds", 3);
default:
return this.clone();
}
}, m4.endOf = function(t4) {
return this.startOf(t4, false);
}, m4.$set = function(t4, e4) {
var n3, o4 = b3.p(t4), f4 = "set" + (this.$u ? "UTC" : ""), l4 = (n3 = {}, n3[a3] = f4 + "Date", n3[d3] = f4 + "Date", n3[c3] = f4 + "Month", n3[h3] = f4 + "FullYear", n3[u3] = f4 + "Hours", n3[s3] = f4 + "Minutes", n3[i3] = f4 + "Seconds", n3[r3] = f4 + "Milliseconds", n3)[o4], $2 = o4 === a3 ? this.$D + (e4 - this.$W) : e4;
if (o4 === c3 || o4 === h3) {
var y4 = this.clone().set(d3, 1);
y4.$d[l4]($2), y4.init(), this.$d = y4.set(d3, Math.min(this.$D, y4.daysInMonth())).$d;
} else l4 && this.$d[l4]($2);
return this.init(), this;
}, m4.set = function(t4, e4) {
return this.clone().$set(t4, e4);
}, m4.get = function(t4) {
return this[b3.p(t4)]();
}, m4.add = function(r4, f4) {
var d4, l4 = this;
r4 = Number(r4);
var $2 = b3.p(f4), y4 = function(t4) {
var e4 = O2(l4);
return b3.w(e4.date(e4.date() + Math.round(t4 * r4)), l4);
};
if ($2 === c3) return this.set(c3, this.$M + r4);
if ($2 === h3) return this.set(h3, this.$y + r4);
if ($2 === a3) return y4(1);
if ($2 === o3) return y4(7);
var M4 = (d4 = {}, d4[s3] = e3, d4[u3] = n2, d4[i3] = t3, d4)[$2] || 1, m5 = this.$d.getTime() + r4 * M4;
return b3.w(m5, this);
}, m4.subtract = function(t4, e4) {
return this.add(-1 * t4, e4);
}, m4.format = function(t4) {
var e4 = this, n3 = this.$locale();
if (!this.isValid()) return n3.invalidDate || l3;
var r4 = t4 || "YYYY-MM-DDTHH:mm:ssZ", i4 = b3.z(this), s4 = this.$H, u4 = this.$m, a4 = this.$M, o4 = n3.weekdays, c4 = n3.months, f4 = n3.meridiem, h4 = function(t5, n4, i5, s5) {
return t5 && (t5[n4] || t5(e4, r4)) || i5[n4].slice(0, s5);
}, d4 = function(t5) {
return b3.s(s4 % 12 || 12, t5, "0");
}, $2 = f4 || function(t5, e5, n4) {
var r5 = t5 < 12 ? "AM" : "PM";
return n4 ? r5.toLowerCase() : r5;
};
return r4.replace(y3, function(t5, r5) {
return r5 || function(t6) {
switch (t6) {
case "YY":
return String(e4.$y).slice(-2);
case "YYYY":
return b3.s(e4.$y, 4, "0");
case "M":
return a4 + 1;
case "MM":
return b3.s(a4 + 1, 2, "0");
case "MMM":
return h4(n3.monthsShort, a4, c4, 3);
case "MMMM":
return h4(c4, a4);
case "D":
return e4.$D;
case "DD":
return b3.s(e4.$D, 2, "0");
case "d":
return String(e4.$W);
case "dd":
return h4(n3.weekdaysMin, e4.$W, o4, 2);
case "ddd":
return h4(n3.weekdaysShort, e4.$W, o4, 3);
case "dddd":
return o4[e4.$W];
case "H":
return String(s4);
case "HH":
return b3.s(s4, 2, "0");
case "h":
return d4(1);
case "hh":
return d4(2);
case "a":
return $2(s4, u4, true);
case "A":
return $2(s4, u4, false);
case "m":
return String(u4);
case "mm":
return b3.s(u4, 2, "0");
case "s":
return String(e4.$s);
case "ss":
return b3.s(e4.$s, 2, "0");
case "SSS":
return b3.s(e4.$ms, 3, "0");
case "Z":
return i4;
}
return null;
}(t5) || i4.replace(":", "");
});
}, m4.utcOffset = function() {
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
}, m4.diff = function(r4, d4, l4) {
var $2, y4 = this, M4 = b3.p(d4), m5 = O2(r4), v4 = (m5.utcOffset() - this.utcOffset()) * e3, g4 = this - m5, D3 = function() {
return b3.m(y4, m5);
};
switch (M4) {
case h3:
$2 = D3() / 12;
break;
case c3:
$2 = D3();
break;
case f3:
$2 = D3() / 3;
break;
case o3:
$2 = (g4 - v4) / 6048e5;
break;
case a3:
$2 = (g4 - v4) / 864e5;
break;
case u3:
$2 = g4 / n2;
break;
case s3:
$2 = g4 / e3;
break;
case i3:
$2 = g4 / t3;
break;
default:
$2 = g4;
}
return l4 ? $2 : b3.a($2);
}, m4.daysInMonth = function() {
return this.endOf(c3).$D;
}, m4.$locale = function() {
return D2[this.$L];
}, m4.locale = function(t4, e4) {
if (!t4) return this.$L;
var n3 = this.clone(), r4 = w3(t4, e4, true);
return r4 && (n3.$L = r4), n3;
}, m4.clone = function() {
return b3.w(this.$d, this);
}, m4.toDate = function() {
return new Date(this.valueOf());
}, m4.toJSON = function() {
return this.isValid() ? this.toISOString() : null;
}, m4.toISOString = function() {
return this.$d.toISOString();
}, m4.toString = function() {
return this.$d.toUTCString();
}, M3;
}(), k3 = _2.prototype;
return O2.prototype = k3, [["$ms", r3], ["$s", i3], ["$m", s3], ["$H", u3], ["$W", a3], ["$M", c3], ["$y", h3], ["$D", d3]].forEach(function(t4) {
k3[t4[1]] = function(e4) {
return this.$g(e4, t4[0], t4[1]);
};
}), O2.extend = function(t4, e4) {
return t4.$i || (t4(e4, _2, O2), t4.$i = true), O2;
}, O2.locale = w3, O2.isDayjs = S2, O2.unix = function(t4) {
return O2(1e3 * t4);
}, O2.en = D2[g3], O2.Ls = D2, O2.p = {}, O2;
});
}
});
// node_modules/expand-template-literal/dist/index.js
var require_dist2 = __commonJS({
"node_modules/expand-template-literal/dist/index.js"(exports, module) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.expandTemplateLiteral = exports.TemplateError = void 0;
var TemplateError = class extends Error {
};
exports.TemplateError = TemplateError;
function expandTemplateLiteral(template, variables = {}) {
var _a;
try {
return eval(`(() => {
${Object.keys(variables).map((name) => `const ${name} = variables['${name}'];`).join("")}
return \`${template}\`;
})()`);
} catch (error) {
throw new TemplateError((_a = error) === null || _a === void 0 ? void 0 : _a.message);
}
}
exports.expandTemplateLiteral = expandTemplateLiteral;
}
});
// node_modules/@drovp/save-as-path/dist/utils.js
var require_utils = __commonJS({
"node_modules/@drovp/save-as-path/dist/utils.js"(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.escapeStringRegexp = exports2.formatDestinationSelection = exports2.uid = exports2.isSamePath = exports2.expandTemplate = exports2.pathIsFree = void 0;
var Path7 = require("path");
var fs_1 = require("fs");
var dayjs = require_dayjs_min();
var expand_template_literal_1 = require_dist2();
var IS_WINDOWS = process.platform === "win32";
async function pathIsFree(path) {
try {
await fs_1.promises.access(path);
} catch (error) {
if ((error === null || error === void 0 ? void 0 : error.code) === "ENOENT")
return true;
}
return false;
}
exports2.pathIsFree = pathIsFree;
function expandTemplate(inputPath, outputExtension, { destination = "${basename}", extraVariables }) {
const dirname2 = Path7.dirname(inputPath);
const srcextname = Path7.extname(inputPath);
const srcbasename = Path7.basename(inputPath);
const filename = Path7.basename(srcbasename, srcextname);
const ext = outputExtension || "";
const extname4 = outputExtension ? `.${outputExtension}` : "";
const basename3 = `${filename}${extname4}`;
const variables2 = {
path: Path7.join(dirname2, basename3),
srcextname,
srcext: srcextname[0] === "." ? srcextname.slice(1) : srcextname,
srcbasename,
filename,
dirname: dirname2,
ext,
extname: extname4,
basename: basename3,
dirbasename: Path7.basename(dirname2),
Time: dayjs,
uid: exports2.uid,
...extraVariables
};
return (0, expand_template_literal_1.expandTemplateLiteral)(destination, variables2);
}
exports2.expandTemplate = expandTemplate;
function normalizePath(path) {
return Path7.normalize(path.trim().replace(/[\\\/]+$/, ""));
}
function isSamePath(pathA, pathB) {
if (IS_WINDOWS) {
pathA = pathA.toLowerCase();
pathB = pathB.toLowerCase();
}
return normalizePath(pathA) === normalizePath(pathB);
}
exports2.isSamePath = isSamePath;
var uid2 = (size = 10) => Array(size).fill(0).map(() => Math.floor(Math.random() * 36).toString(36)).join("");
exports2.uid = uid2;
function formatDestinationSelection(path, oldPath) {
const oldPathParts = (oldPath || "").split(/\\|\//);
const lastOldPathPart = oldPathParts[oldPathParts.length - 1];
return Path7.posix.join(path.replaceAll("\\", "/"), lastOldPathPart);
}
exports2.formatDestinationSelection = formatDestinationSelection;
function escapeStringRegexp(string) {
if (typeof string !== "string") {
throw new TypeError("Expected a string");
}
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
}
exports2.escapeStringRegexp = escapeStringRegexp;
}
});
// node_modules/@drovp/save-as-path/dist/unusedFilename.js
var require_unusedFilename = __commonJS({
"node_modules/@drovp/save-as-path/dist/unusedFilename.js"(exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.unusedFilename = exports2.makeSeparatorIncrementer = exports2.MaxTryError = void 0;
var Path7 = require("path");
var utils_1 = require_utils();
var MaxTryError = class extends Error {
constructor(originalPath, lastTriedPath) {
super("Max tries reached.");
this.originalPath = originalPath;
this.lastTriedPath = lastTriedPath;
}
};
exports2.MaxTryError = MaxTryError;
var parenthesesIncrementer = (inputFilename, extension) => {
const match = inputFilename.match(/^(?<filename>.*)\((?<index>\d+)\)$/);
let { filename, index } = match ? match.groups : { filename: inputFilename, index: "0" };
let indexNum = parseInt(index, 10);
filename = filename.trim();
return [`${filename}${extension}`, `${filename} (${++indexNum})${extension}`];
};
var makeSeparatorIncrementer = (separator) => {
const escapedSeparator = (0, utils_1.escapeStringRegexp)(separator);
return (inputFilename, extension) => {
const match = new RegExp(`^(?<filename>.*)${escapedSeparator}(?<index>\\d+)$`).exec(inputFilename);
let { filename, index } = match ? match.groups : { filename: inputFilename, index: "0" };
let indexNum = parseInt(index, 10);
return [`${filename}${extension}`, `${filename.trim()}${separator}${++indexNum}${extension}`];
};
};
exports2.makeSeparatorIncrementer = makeSeparatorIncrementer;
var incrementPath = (filePath, incrementer) => {
const ext = Path7.extname(filePath);
const dirname2 = Path7.dirname(filePath);
const [originalFilename, incrementedFilename] = incrementer(Path7.basename(filePath, ext), ext);
return [Path7.join(dirname2, originalFilename), Path7.join(dirname2, incrementedFilename)];
};
async function unusedFilename(filePath, { incrementer = parenthesesIncrementer, maxTries = Number.POSITIVE_INFINITY, decider = utils_1.pathIsFree } = {}) {
let tries = 0;
let [originalPath] = incrementPath(filePath, incrementer);
let unusedPath = filePath;
while (true) {
if (await decider(unusedPath))
return unusedPath;
if (++tries > maxTries)
throw new MaxTryError(originalPath, unusedPath);
[originalPath, unusedPath] = incrementPath(unusedPath, incrementer);
}
}
exports2.unusedFilename = unusedFilename;
}
});
// node_modules/readable-stream/lib/internal/streams/stream-browser.js
var require_stream_browser = __commonJS({
"node_modules/readable-stream/lib/internal/streams/stream-browser.js"(exports2, module2) {
module2.exports = require("events").EventEmitter;
}
});
// node_modules/readable-stream/lib/internal/streams/buffer_list.js
var require_buffer_list = __commonJS({
"node_modules/readable-stream/lib/internal/streams/buffer_list.js"(exports2, module2) {
"use strict";
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread(target) {
for (var i3 = 1; i3 < arguments.length; i3++) {
var source = null != arguments[i3] ? arguments[i3] : {};
i3 % 2 ? ownKeys(Object(source), true).forEach(function(key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}
return obj;
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i3 = 0; i3 < props.length; i3++) {
var descriptor = props[i3];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", { writable: false });
return Constructor;
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== void 0) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
var _require = require("buffer");
var Buffer2 = _require.Buffer;
var _require2 = require("util");
var inspect = _require2.inspect;
var custom = inspect && inspect.custom || "inspect";
function copyBuffer(src, target, offset) {
Buffer2.prototype.copy.call(src, target, offset);
}
module2.exports = /* @__PURE__ */ function() {
function BufferList() {
_classCallCheck(this, BufferList);
this.head = null;
this.tail = null;
this.length = 0;
}
_createClass(BufferList, [{
key: "push",
value: function push(v3) {
var entry = {
data: v3,
next: null
};
if (this.length > 0) this.tail.next = entry;
else this.head = entry;
this.tail = entry;
++this.length;
}
}, {
key: "unshift",
value: function unshift(v3) {
var entry = {
data: v3,
next: this.head
};
if (this.length === 0) this.tail = entry;
this.head = entry;
++this.length;
}
}, {
key: "shift",
value: function shift() {
if (this.length === 0) return;
var ret = this.head.data;
if (this.length === 1) this.head = this.tail = null;
else this.head = this.head.next;
--this.length;
return ret;
}
}, {
key: "clear",
value: function clear() {
this.head = this.tail = null;
this.length = 0;
}
}, {
key: "join",
value: function join5(s3) {
if (this.length === 0) return "";
var p3 = this.head;
var ret = "" + p3.data;
while (p3 = p3.next) ret += s3 + p3.data;
return ret;
}
}, {
key: "concat",
value: function concat(n2) {
if (this.length === 0) return Buffer2.alloc(0);
var ret = Buffer2.allocUnsafe(n2 >>> 0);
var p3 = this.head;
var i3 = 0;
while (p3) {
copyBuffer(p3.data, ret, i3);
i3 += p3.data.length;
p3 = p3.next;
}
return ret;
}
// Consumes a specified amount of bytes or characters from the buffered data.
}, {
key: "consume",
value: function consume(n2, hasStrings) {
var ret;
if (n2 < this.head.data.length) {
ret = this.head.data.slice(0, n2);
this.head.data = this.head.data.slice(n2);
} else if (n2 === this.head.data.length) {
ret = this.shift();
} else {
ret = hasStrings ? this._getString(n2) : this._getBuffer(n2);
}
return ret;
}
}, {
key: "first",
value: function first() {
return this.head.data;
}
// Consumes a specified amount of characters from the buffered data.
}, {
key: "_getString",
value: function _getString(n2) {
var p3 = this.head;
var c3 = 1;
var ret = p3.data;
n2 -= ret.length;
while (p3 = p3.next) {
var str = p3.data;
var nb = n2 > str.length ? str.length : n2;
if (nb === str.length) ret += str;
else ret += str.slice(0, n2);
n2 -= nb;
if (n2 === 0) {
if (nb === str.length) {
++c3;
if (p3.next) this.head = p3.next;
else this.head = this.tail = null;
} else {
this.head = p3;
p3.data = str.slice(nb);
}
break;
}
++c3;
}
this.length -= c3;
return ret;
}
// Consumes a specified amount of bytes from the buffered data.
}, {
key: "_getBuffer",
value: function _getBuffer(n2) {
var ret = Buffer2.allocUnsafe(n2);
var p3 = this.head;
var c3 = 1;
p3.data.copy(ret);
n2 -= p3.data.length;
while (p3 = p3.next) {
var buf = p3.data;
var nb = n2 > buf.length ? buf.length : n2;
buf.copy(ret, ret.length - n2, 0, nb);
n2 -= nb;
if (n2 === 0) {
if (nb === buf.length) {
++c3;
if (p3.next) this.head = p3.next;
else this.head = this.tail = null;
} else {
this.head = p3;
p3.data = buf.slice(nb);
}
break;
}
++c3;
}
this.length -= c3;
return ret;
}
// Make sure the linked list only shows the minimal necessary information.
}, {
key: custom,
value: function value(_2, options) {
return inspect(this, _objectSpread(_objectSpread({}, options), {}, {
// Only inspect one level.
depth: 0,
// It should not recurse.
customInspect: false
}));
}
}]);
return BufferList;
}();
}
});
// node_modules/readable-stream/lib/internal/streams/destroy.js
var require_destroy = __commonJS({
"node_modules/readable-stream/lib/internal/streams/destroy.js"(exports2, module2) {
"use strict";
function destroy(err, cb) {
var _this = this;
var readableDestroyed = this._readableState && this._readableState.destroyed;
var writableDestroyed = this._writableState && this._writableState.destroyed;
if (readableDestroyed || writableDestroyed) {
if (cb) {
cb(err);
} else if (err) {
if (!this._writableState) {
process.nextTick(emitErrorNT, this, err);
} else if (!this._writableState.errorEmitted) {
this._writableState.errorEmitted = true;
process.nextTick(emitErrorNT, this, err);
}
}
return this;
}
if (this._readableState) {
this._readableState.destroyed = true;
}
if (this._writableState) {
this._writableState.destroyed = true;
}
this._destroy(err || null, function(err2) {
if (!cb && err2) {
if (!_this._writableState) {
process.nextTick(emitErrorAndCloseNT, _this, err2);
} else if (!_this._writableState.errorEmitted) {
_this._writableState.errorEmitted = true;
process.nextTick(emitErrorAndCloseNT, _this, err2);
} else {
process.nextTick(emitCloseNT, _this);
}
} else if (cb) {
process.nextTick(emitCloseNT, _this);
cb(err2);
} else {
process.nextTick(emitCloseNT, _this);
}
});
return this;
}
function emitErrorAndCloseNT(self2, err) {
emitErrorNT(self2, err);
emitCloseNT(self2);
}
function emitCloseNT(self2) {
if (self2._writableState && !self2._writableState.emitClose) return;
if (self2._readableState && !self2._readableState.emitClose) return;
self2.emit("close");
}
function undestroy() {
if (this._readableState) {
this._readableState.destroyed = false;
this._readableState.reading = false;
this._readableState.ended = false;
this._readableState.endEmitted = false;
}
if (this._writableState) {
this._writableState.destroyed = false;
this._writableState.ended = false;
this._writableState.ending = false;
this._writableState.finalCalled = false;
this._writableState.prefinished = false;
this._writableState.finished = false;
this._writableState.errorEmitted = false;
}
}
function emitErrorNT(self2, err) {
self2.emit("error", err);
}
function errorOrDestroy(stream, err) {
var rState = stream._readableState;
var wState = stream._writableState;
if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);
else stream.emit("error", err);
}
module2.exports = {
destroy,
undestroy,
errorOrDestroy
};
}
});
// node_modules/readable-stream/errors-browser.js
var require_errors_browser = __commonJS({
"node_modules/readable-stream/errors-browser.js"(exports2, module2) {
"use strict";
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var codes = {};
function createErrorType(code, message, Base) {
if (!Base) {
Base = Error;
}
function getMessage(arg1, arg2, arg3) {
if (typeof message === "string") {
return message;
} else {
return message(arg1, arg2, arg3);
}
}
var NodeError = /* @__PURE__ */ function(_Base) {
_inheritsLoose(NodeError2, _Base);
function NodeError2(arg1, arg2, arg3) {
return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
}
return NodeError2;
}(Base);
NodeError.prototype.name = Base.name;
NodeError.prototype.code = code;
codes[code] = NodeError;
}
function oneOf(expected, thing) {
if (Array.isArray(expected)) {
var len = expected.length;
expected = expected.map(function(i3) {
return String(i3);
});
if (len > 2) {
return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(", "), ", or ") + expected[len - 1];
} else if (len === 2) {
return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
} else {
return "of ".concat(thing, " ").concat(expected[0]);
}
} else {
return "of ".concat(thing, " ").concat(String(expected));
}
}
function startsWith(str, search, pos) {
return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
}
function endsWith(str, search, this_len) {
if (this_len === void 0 || this_len > str.length) {
this_len = str.length;
}
return str.substring(this_len - search.length, this_len) === search;
}
function includes(str, search, start) {
if (typeof start !== "number") {
start = 0;
}
if (start + search.length > str.length) {
return false;
} else {
return str.indexOf(search, start) !== -1;
}
}
createErrorType("ERR_INVALID_OPT_VALUE", function(name, value) {
return 'The value "' + value + '" is invalid for option "' + name + '"';
}, TypeError);
createErrorType("ERR_INVALID_ARG_TYPE", function(name, expected, actual) {
var determiner;
if (typeof expected === "string" && startsWith(expected, "not ")) {
determiner = "must not be";
expected = expected.replace(/^not /, "");
} else {
determiner = "must be";
}
var msg;
if (endsWith(name, " argument")) {
msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, "type"));
} else {
var type = includes(name, ".") ? "property" : "argument";
msg = 'The "'.concat(name, '" ').concat(type, " ").concat(determiner, " ").concat(oneOf(expected, "type"));
}
msg += ". Received type ".concat(typeof actual);
return msg;
}, TypeError);
createErrorType("ERR_STREAM_PUSH_AFTER_EOF", "stream.push() after EOF");
createErrorType("ERR_METHOD_NOT_IMPLEMENTED", function(name) {
return "The " + name + " method is not implemented";
});
createErrorType("ERR_STREAM_PREMATURE_CLOSE", "Premature close");
createErrorType("ERR_STREAM_DESTROYED", function(name) {
return "Cannot call " + name + " after a stream was destroyed";
});
createErrorType("ERR_MULTIPLE_CALLBACK", "Callback called multiple times");
createErrorType("ERR_STREAM_CANNOT_PIPE", "Cannot pipe, not readable");
createErrorType("ERR_STREAM_WRITE_AFTER_END", "write after end");
createErrorType("ERR_STREAM_NULL_VALUES", "May not write null values to stream", TypeError);
createErrorType("ERR_UNKNOWN_ENCODING", function(arg) {
return "Unknown encoding: " + arg;
}, TypeError);
createErrorType("ERR_STREAM_UNSHIFT_AFTER_END_EVENT", "stream.unshift() after end event");
module2.exports.codes = codes;
}
});
// node_modules/readable-stream/lib/internal/streams/state.js
var require_state = __commonJS({
"node_modules/readable-stream/lib/internal/streams/state.js"(exports2, module2) {
"use strict";
var ERR_INVALID_OPT_VALUE = require_errors_browser().codes.ERR_INVALID_OPT_VALUE;
function highWaterMarkFrom(options, isDuplex, duplexKey) {
return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
}
function getHighWaterMark(state, options, duplexKey, isDuplex) {
var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
if (hwm != null) {
if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
var name = isDuplex ? duplexKey : "highWaterMark";
throw new ERR_INVALID_OPT_VALUE(name, hwm);
}
return Math.floor(hwm);
}
return state.objectMode ? 16 : 16 * 1024;
}
module2.exports = {
getHighWaterMark
};
}
});
// node_modules/inherits/inherits_browser.js
var require_inherits_browser = __commonJS({
"node_modules/inherits/inherits_browser.js"(exports2, module2) {
if (typeof Object.create === "function") {
module2.exports = function inherits(ctor, superCtor) {
if (superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
}
};
} else {
module2.exports = function inherits(ctor, superCtor) {
if (superCtor) {
ctor.super_ = superCtor;
var TempCtor = function() {
};
TempCtor.prototype = superCtor.prototype;
ctor.prototype = new TempCtor();
ctor.prototype.constructor = ctor;
}
};
}
}
});
// node_modules/util-deprecate/browser.js
var require_browser = __commonJS({
"node_modules/util-deprecate/browser.js"(exports2, module2) {
module2.exports = deprecate;
function deprecate(fn, msg) {
if (config("noDeprecation")) {
return fn;
}
var warned = false;
function deprecated() {
if (!warned) {
if (config("throwDeprecation")) {
throw new Error(msg);
} else if (config("traceDeprecation")) {
console.trace(msg);
} else {
console.warn(msg);
}
warned = true;
}
return fn.apply(this, arguments);
}
return deprecated;
}
function config(name) {
try {
if (!global.localStorage) return false;
} catch (_2) {
return false;
}
var val = global.localStorage[name];
if (null == val) return false;
return String(val).toLowerCase() === "true";
}
}
});
// node_modules/readable-stream/lib/_stream_writable.js
var require_stream_writable = __commonJS({
"node_modules/readable-stream/lib/_stream_writable.js"(exports2, module2) {
"use strict";
module2.exports = Writable;
function CorkedRequest(state) {
var _this = this;
this.next = null;
this.entry = null;
this.finish = function() {
onCorkedFinish(_this, state);
};
}
var Duplex;
Writable.WritableState = WritableState;
var internalUtil = {
deprecate: require_browser()
};
var Stream = require_stream_browser();
var Buffer2 = require("buffer").Buffer;
var OurUint8Array = (typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function() {
};
function _uint8ArrayToBuffer(chunk) {
return Buffer2.from(chunk);
}
function _isUint8Array(obj) {
return Buffer2.isBuffer(obj) || obj instanceof OurUint8Array;
}
var destroyImpl = require_destroy();
var _require = require_state();
var getHighWaterMark = _require.getHighWaterMark;
var _require$codes = require_errors_browser().codes;
var ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE;
var ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED;
var ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK;
var ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE;
var ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
var ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES;
var ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END;
var ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
var errorOrDestroy = destroyImpl.errorOrDestroy;
require_inherits_browser()(Writable, Stream);
function nop() {
}