@livo-tv/blocks 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +46 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +46 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4695,6 +4695,24 @@ function partRanges(fileSize, partSize) {
|
|
|
4695
4695
|
};
|
|
4696
4696
|
});
|
|
4697
4697
|
}
|
|
4698
|
+
var BYTE_UNITS = ["B", "KB", "MB", "GB", "TB"];
|
|
4699
|
+
function formatUploadBytes(bytes) {
|
|
4700
|
+
if (!Number.isFinite(bytes) || bytes <= 0) {
|
|
4701
|
+
return "0 B";
|
|
4702
|
+
}
|
|
4703
|
+
let value = bytes;
|
|
4704
|
+
let unit = 0;
|
|
4705
|
+
while (value >= 1024 && unit < BYTE_UNITS.length - 1) {
|
|
4706
|
+
value /= 1024;
|
|
4707
|
+
unit += 1;
|
|
4708
|
+
}
|
|
4709
|
+
if (unit === 0 || value >= 10) {
|
|
4710
|
+
return `${Math.round(value)} ${BYTE_UNITS[unit]}`;
|
|
4711
|
+
}
|
|
4712
|
+
const tenths = Math.round(value * 10) / 10;
|
|
4713
|
+
const label = Number.isInteger(tenths) ? String(tenths) : tenths.toFixed(1);
|
|
4714
|
+
return `${label} ${BYTE_UNITS[unit]}`;
|
|
4715
|
+
}
|
|
4698
4716
|
function progressFromBytes(loaded, total) {
|
|
4699
4717
|
const safeTotal = Math.max(0, total);
|
|
4700
4718
|
const safeLoaded = Math.min(Math.max(0, loaded), safeTotal);
|
|
@@ -4883,6 +4901,9 @@ function statusLabel(status, labels) {
|
|
|
4883
4901
|
}
|
|
4884
4902
|
}
|
|
4885
4903
|
}
|
|
4904
|
+
function progressLabel(job) {
|
|
4905
|
+
return `${job.percent}% \xB7 ${formatUploadBytes(job.loaded)} / ${formatUploadBytes(job.total)}`;
|
|
4906
|
+
}
|
|
4886
4907
|
function FileUploadTray({
|
|
4887
4908
|
jobs,
|
|
4888
4909
|
labels: labelOverrides,
|
|
@@ -4905,16 +4926,18 @@ function FileUploadTray({
|
|
|
4905
4926
|
const canResume = job.status === "paused";
|
|
4906
4927
|
const canCancel = job.status === "uploading" || job.status === "paused" || job.status === "error";
|
|
4907
4928
|
return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "grid min-w-0 gap-1.5", children: [
|
|
4929
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4930
|
+
"p",
|
|
4931
|
+
{
|
|
4932
|
+
className: "h-[3lh] min-w-0 line-clamp-3 text-sm leading-5 font-medium break-all",
|
|
4933
|
+
title: job.name,
|
|
4934
|
+
children: job.name
|
|
4935
|
+
}
|
|
4936
|
+
),
|
|
4908
4937
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [
|
|
4909
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4910
|
-
"p",
|
|
4911
|
-
{
|
|
4912
|
-
className: "min-w-0 flex-1 truncate text-sm font-medium",
|
|
4913
|
-
title: job.name,
|
|
4914
|
-
children: job.name
|
|
4915
|
-
}
|
|
4916
|
-
),
|
|
4917
4938
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground shrink-0 text-xs", children: statusLabel(job.status, labels) }),
|
|
4939
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground shrink-0 text-xs tabular-nums", children: progressLabel(job) }),
|
|
4940
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "min-w-0 flex-1" }),
|
|
4918
4941
|
canPause ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4919
4942
|
Button,
|
|
4920
4943
|
{
|
|
@@ -5125,10 +5148,19 @@ function createMultipartUploadController(options) {
|
|
|
5125
5148
|
const ranges = partRanges(options.file.size, options.partSize);
|
|
5126
5149
|
const sleep = options.sleep ?? defaultSleep;
|
|
5127
5150
|
const state = { status: "idle" };
|
|
5128
|
-
const
|
|
5151
|
+
const seeded = /* @__PURE__ */ new Map();
|
|
5152
|
+
for (const part of options.completedParts ?? []) {
|
|
5153
|
+
if (part.partNumber < 1 || part.partNumber > ranges.length) continue;
|
|
5154
|
+
seeded.set(part.partNumber, part);
|
|
5155
|
+
}
|
|
5156
|
+
const completed = [...seeded.values()].sort(
|
|
5157
|
+
(left, right) => left.partNumber - right.partNumber
|
|
5158
|
+
);
|
|
5159
|
+
const done = new Set(completed.map((part) => part.partNumber));
|
|
5129
5160
|
let currentXhr = null;
|
|
5130
5161
|
let run = null;
|
|
5131
|
-
let resumeIndex =
|
|
5162
|
+
let resumeIndex = ranges.findIndex((range) => !done.has(range.partNumber));
|
|
5163
|
+
if (resumeIndex < 0) resumeIndex = ranges.length;
|
|
5132
5164
|
function currentStatus() {
|
|
5133
5165
|
return state.status;
|
|
5134
5166
|
}
|
|
@@ -5186,11 +5218,13 @@ function createMultipartUploadController(options) {
|
|
|
5186
5218
|
resumeIndex = index;
|
|
5187
5219
|
const range = ranges[index];
|
|
5188
5220
|
if (!range) continue;
|
|
5221
|
+
if (done.has(range.partNumber)) continue;
|
|
5189
5222
|
const body = options.file.slice(range.start, range.end);
|
|
5190
5223
|
try {
|
|
5191
5224
|
const etag = await putPartWithRetry(range.partNumber, body);
|
|
5192
5225
|
if (state.status !== "uploading") return;
|
|
5193
5226
|
completed.push({ partNumber: range.partNumber, etag });
|
|
5227
|
+
done.add(range.partNumber);
|
|
5194
5228
|
emitProgress(0);
|
|
5195
5229
|
} catch (error) {
|
|
5196
5230
|
currentXhr = null;
|
|
@@ -5207,7 +5241,8 @@ function createMultipartUploadController(options) {
|
|
|
5207
5241
|
}
|
|
5208
5242
|
async function start() {
|
|
5209
5243
|
if (run) return run;
|
|
5210
|
-
|
|
5244
|
+
emitProgress(0);
|
|
5245
|
+
run = uploadFrom(resumeIndex).catch((error) => {
|
|
5211
5246
|
if (isStopped()) return;
|
|
5212
5247
|
state.status = "error";
|
|
5213
5248
|
throw error;
|