@scaleflex/dam-core 0.3.2 → 0.4.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.js CHANGED
@@ -1,13 +1,13 @@
1
1
  const N = "https://api.filerobot.com";
2
- function B(s) {
3
- return s === 404 || s === 408 || s === 429 || s >= 500;
2
+ function B(t) {
3
+ return t === 404 || t === 408 || t === 429 || t >= 500;
4
4
  }
5
- const G = (s) => new Promise((e) => setTimeout(e, s));
6
- function M(s, e) {
7
- return `${(e || N).replace(/\/+$/, "")}/${s}`;
5
+ const G = (t) => new Promise((e) => setTimeout(e, t));
6
+ function M(t, e) {
7
+ return `${(e || N).replace(/\/+$/, "")}/${t}`;
8
8
  }
9
- async function W(s, e, t, i = {}) {
10
- const r = `${M(s, t)}/key/${encodeURIComponent(e)}`, o = i.retries ?? 2, l = i.retryDelayMs ?? 400;
9
+ async function W(t, e, s, i = {}) {
10
+ const r = `${M(t, s)}/key/${encodeURIComponent(e)}`, o = i.retries ?? 2, l = i.retryDelayMs ?? 400;
11
11
  let a = new Error("SASS key exchange failed");
12
12
  for (let c = 0; c <= o; c++) {
13
13
  c > 0 && await G(l * c);
@@ -34,71 +34,71 @@ async function W(s, e, t, i = {}) {
34
34
  }
35
35
  throw a;
36
36
  }
37
- function T(s, e) {
38
- const t = {};
39
- switch (s.mode) {
37
+ function T(t, e) {
38
+ const s = {};
39
+ switch (t.mode) {
40
40
  case "security-template":
41
41
  if (!e)
42
42
  throw new Error(
43
43
  "[dam-core] Cannot build auth headers for security-template mode: SASS key exchange has not been performed. Call resolveAuth() first, or use sass-key mode."
44
44
  );
45
- t["X-Filerobot-Key"] = e;
45
+ s["X-Filerobot-Key"] = e;
46
46
  break;
47
47
  case "sass-key":
48
- t["X-Filerobot-Key"] = s.sassKey;
48
+ s["X-Filerobot-Key"] = t.sassKey;
49
49
  break;
50
50
  }
51
- return s.airboxPuid && (t["X-Filerobot-Airbox-Puid"] = s.airboxPuid), t;
51
+ return t.airboxPuid && (s["X-Filerobot-Airbox-Puid"] = t.airboxPuid), s;
52
52
  }
53
- function X(s) {
54
- return s.mode === "securityTemplate" || s.mode === "sassKey";
53
+ function X(t) {
54
+ return t.mode === "securityTemplate" || t.mode === "sassKey";
55
55
  }
56
- function V(s) {
57
- return X(s) ? s.mode === "securityTemplate" ? {
56
+ function V(t) {
57
+ return X(t) ? t.mode === "securityTemplate" ? {
58
58
  mode: "security-template",
59
- container: s.projectToken,
60
- securityTemplateId: s.securityTemplateKey,
61
- airboxPuid: s.airboxPuid
59
+ container: t.projectToken,
60
+ securityTemplateId: t.securityTemplateKey,
61
+ airboxPuid: t.airboxPuid
62
62
  } : {
63
63
  mode: "sass-key",
64
- container: s.projectToken,
65
- sassKey: s.sassKey,
66
- airboxPuid: s.airboxPuid
67
- } : s;
64
+ container: t.projectToken,
65
+ sassKey: t.sassKey,
66
+ airboxPuid: t.airboxPuid
67
+ } : t;
68
68
  }
69
- async function I(s, e) {
70
- const t = V(s), i = M(t.container, e);
71
- if (t.mode === "security-template") {
72
- const r = await W(t.container, t.securityTemplateId, e);
73
- return { apiBase: i, headers: T(t, r), sassKey: r };
69
+ async function I(t, e) {
70
+ const s = V(t), i = M(s.container, e);
71
+ if (s.mode === "security-template") {
72
+ const r = await W(s.container, s.securityTemplateId, e);
73
+ return { apiBase: i, headers: T(s, r), sassKey: r };
74
74
  }
75
- return { apiBase: i, headers: T(t) };
75
+ return { apiBase: i, headers: T(s) };
76
76
  }
77
77
  const H = 3e4;
78
- class O {
79
- constructor(e, t, i) {
80
- this.baseUrl = `${e.apiBase}/v5`, this.headers = e.headers, this.auth = t, this.apiDomain = i;
78
+ class R {
79
+ constructor(e, s, i) {
80
+ this.baseUrl = `${e.apiBase}/v5`, this.headers = e.headers, this.auth = s, this.apiDomain = i;
81
81
  }
82
82
  /** Resolve an AuthConfig (performing key exchange if needed) and build a client. */
83
- static async create(e, t) {
84
- const i = await I(e, t);
85
- return new O(i, e, t);
83
+ static async create(e, s) {
84
+ const i = await I(e, s);
85
+ return new R(i, e, s);
86
86
  }
87
- get(e, t) {
87
+ get(e, s) {
88
88
  const i = new URL(`${this.baseUrl}${e}`);
89
- if (t)
90
- for (const [r, o] of Object.entries(t))
89
+ if (s)
90
+ for (const [r, o] of Object.entries(s))
91
91
  o != null && i.searchParams.set(r, Array.isArray(o) ? o.join(",") : String(o));
92
92
  return this.send(i, { method: "GET" });
93
93
  }
94
- post(e, t) {
95
- return this.sendJson("POST", e, t);
94
+ post(e, s) {
95
+ return this.sendJson("POST", e, s);
96
96
  }
97
- put(e, t) {
98
- return this.sendJson("PUT", e, t);
97
+ put(e, s) {
98
+ return this.sendJson("PUT", e, s);
99
99
  }
100
- delete(e, t) {
101
- return this.sendJson("DELETE", e, t);
100
+ delete(e, s) {
101
+ return this.sendJson("DELETE", e, s);
102
102
  }
103
103
  /**
104
104
  * Absolute REST URL (incl. the `/v5` base) for a path — for building direct
@@ -111,25 +111,25 @@ class O {
111
111
  get authKey() {
112
112
  return this.headers["X-Filerobot-Key"];
113
113
  }
114
- sendJson(e, t, i) {
115
- return this.send(new URL(`${this.baseUrl}${t}`), {
114
+ sendJson(e, s, i) {
115
+ return this.send(new URL(`${this.baseUrl}${s}`), {
116
116
  method: e,
117
117
  headers: { "Content-Type": "application/json" },
118
118
  body: i === void 0 ? void 0 : JSON.stringify(i)
119
119
  });
120
120
  }
121
- async send(e, t, i = !1) {
121
+ async send(e, s, i = !1) {
122
122
  var l;
123
123
  const r = new AbortController(), o = setTimeout(() => r.abort(), H);
124
124
  try {
125
125
  const a = await fetch(e.toString(), {
126
- ...t,
127
- headers: { ...this.headers, ...t.headers },
126
+ ...s,
127
+ headers: { ...this.headers, ...s.headers },
128
128
  signal: r.signal
129
129
  });
130
130
  if (clearTimeout(o), a.status === 401 && !i && ((l = this.auth) == null ? void 0 : l.mode) === "security-template") {
131
131
  const h = await I(this.auth, this.apiDomain);
132
- return this.headers = h.headers, this.send(e, t, !0);
132
+ return this.headers = h.headers, this.send(e, s, !0);
133
133
  }
134
134
  if (!a.ok) {
135
135
  let h = `API error: ${a.status} ${a.statusText}`;
@@ -152,50 +152,50 @@ class O {
152
152
  }
153
153
  }
154
154
  }
155
- function J(s) {
156
- const e = s.path ?? s.name, t = e.replace(/\/[^/]*$/, "") || "/";
155
+ function J(t) {
156
+ const e = t.path ?? t.name, s = e.replace(/\/[^/]*$/, "") || "/";
157
157
  return {
158
- uuid: s.uuid,
159
- name: s.name.split("/").pop() || s.name,
158
+ uuid: t.uuid,
159
+ name: t.name.split("/").pop() || t.name,
160
160
  path: e,
161
- parentPath: t,
162
- createdAt: s.created_at,
163
- modifiedAt: s.modified_at
161
+ parentPath: s,
162
+ createdAt: t.created_at,
163
+ modifiedAt: t.modified_at
164
164
  };
165
165
  }
166
- async function b(s, e = {}) {
167
- const t = e.sortBy ?? "name", i = e.sortDirection ?? "asc";
168
- return ((await s.get("/folders", {
166
+ async function b(t, e = {}) {
167
+ const s = e.sortBy ?? "name", i = e.sortDirection ?? "asc";
168
+ return ((await t.get("/folders", {
169
169
  folder: e.folderPath ?? "/",
170
170
  recursive: e.recursive ?? 0,
171
171
  limit: e.limit ?? 1e3,
172
172
  offset: e.offset ?? 0,
173
173
  q: e.q,
174
- sort: `${t}:${i}`
174
+ sort: `${s}:${i}`
175
175
  })).folders ?? []).map(J);
176
176
  }
177
- async function K(s, e, t) {
178
- const i = t.replace(/\/+$/, ""), r = i ? `${i}/${e}` : `/${e}`, o = await s.post("/folders", { name: r });
177
+ async function K(t, e, s) {
178
+ const i = s.replace(/\/+$/, ""), r = i ? `${i}/${e}` : `/${e}`, o = await t.post("/folders", { name: r });
179
179
  if (o.status !== "success") throw new Error(o.msg || "Failed to create folder");
180
180
  }
181
- async function Y(s, e, t) {
182
- const i = await s.put(`/folder/${encodeURIComponent(e)}/name`, {
183
- name: t
181
+ async function Y(t, e, s) {
182
+ const i = await t.put(`/folder/${encodeURIComponent(e)}/name`, {
183
+ name: s
184
184
  });
185
185
  if ((i == null ? void 0 : i.status) === "error") throw new Error(i.msg || "Failed to rename folder");
186
186
  }
187
- async function Z(s, e) {
188
- const t = await s.delete("/folders", { folders_uuids: e });
189
- if ((t == null ? void 0 : t.status) === "error") throw new Error(t.msg || "Failed to delete folders");
187
+ async function Z(t, e) {
188
+ const s = await t.delete("/folders", { folders_uuids: e });
189
+ if ((s == null ? void 0 : s.status) === "error") throw new Error(s.msg || "Failed to delete folders");
190
190
  }
191
- async function Q(s, e, t) {
192
- const i = await s.post("/folders", {
191
+ async function Q(t, e, s) {
192
+ const i = await t.post("/folders", {
193
193
  folders_uuids: e,
194
- new_folder_name: t
194
+ new_folder_name: s
195
195
  });
196
196
  if ((i == null ? void 0 : i.status) === "error") throw new Error(i.msg || "Failed to move folders");
197
197
  }
198
- const R = {
198
+ const O = {
199
199
  small: [null, 1048576],
200
200
  // < 1 MB
201
201
  medium: [1048576, 10485760],
@@ -210,67 +210,72 @@ const R = {
210
210
  month: 30,
211
211
  year: 365
212
212
  };
213
- function y(s, e) {
214
- const t = new Date(e);
215
- return t.setUTCHours(0, 0, 0, 0), t.setUTCDate(t.getUTCDate() - ee[s]), t;
213
+ function y(t, e) {
214
+ const s = new Date(e);
215
+ return s.setUTCHours(0, 0, 0, 0), s.setUTCDate(s.getUTCDate() - ee[t]), s;
216
216
  }
217
- const L = ["cdn_permalink"], F = {}, m = (s, e) => e.split(" ").forEach((t) => F[t] = s);
217
+ const L = ["cdn_permalink"], F = {}, m = (t, e) => e.split(" ").forEach((s) => F[s] = t);
218
218
  m("image", "jpg jpeg png gif webp svg avif bmp tif tiff heic ico");
219
219
  m("video", "mp4 webm mov m4v avi mkv ogv");
220
220
  m("audio", "mp3 wav ogg oga m4a aac flac");
221
221
  m("document", "pdf doc docx xls xlsx ppt pptx txt csv rtf md");
222
222
  m("model", "glb gltf obj fbx stl usdz ply 3ds dae");
223
- function te(s) {
224
- const e = (s.name.split(".").pop() || "").toLowerCase();
223
+ function te(t) {
224
+ const e = (t.name.split(".").pop() || "").toLowerCase();
225
225
  if (F[e] === "model") return "model";
226
- const t = (s.file_type || s.type || "").toLowerCase();
227
- return t.startsWith("image") ? "image" : t.startsWith("video") ? "video" : t.startsWith("audio") ? "audio" : t.includes("pdf") || t.includes("document") || t.includes("text") ? "document" : F[e] ?? "other";
226
+ const s = (t.file_type || t.type || "").toLowerCase();
227
+ return s.startsWith("image") ? "image" : s.startsWith("video") ? "video" : s.startsWith("audio") ? "audio" : s.includes("pdf") || s.includes("document") || s.includes("text") ? "document" : F[e] ?? "other";
228
228
  }
229
- function z(s) {
230
- var e, t, i, r, o;
229
+ function z(t) {
230
+ var e, s, i, r, o, l, a;
231
231
  return {
232
- uuid: s.uuid,
233
- name: s.name,
234
- folder: s.folder ?? "/",
235
- type: te(s),
236
- fileType: s.file_type ?? s.type,
237
- cdnUrl: s.cdn_permalink ?? s.cdn_url,
238
- thumbnailUrl: ((e = s.info) == null ? void 0 : e.video_thumbnail) ?? ((t = s.info) == null ? void 0 : t.image_thumbnail) ?? ((i = s.info) == null ? void 0 : i.thumbnail) ?? ((r = s.info) == null ? void 0 : r.preview),
232
+ uuid: t.uuid,
233
+ name: t.name,
234
+ folder: t.folder ?? "/",
235
+ type: te(t),
236
+ fileType: t.file_type ?? t.type,
237
+ cdnUrl: t.cdn_permalink ?? t.cdn_url,
238
+ thumbnailUrl: ((e = t.info) == null ? void 0 : e.video_thumbnail) ?? ((s = t.info) == null ? void 0 : s.image_thumbnail) ?? ((i = t.info) == null ? void 0 : i.thumbnail) ?? ((r = t.info) == null ? void 0 : r.preview),
239
239
  // Live API returns `size: { bytes, pretty }`; tolerate a plain number too.
240
- size: typeof s.size == "object" ? (o = s.size) == null ? void 0 : o.bytes : s.size,
241
- width: s.width,
242
- height: s.height,
243
- createdAt: s.created_at,
244
- modifiedAt: s.modified_at
240
+ size: typeof t.size == "object" ? (o = t.size) == null ? void 0 : o.bytes : t.size,
241
+ duration: ((l = t.info) == null ? void 0 : l.video_duration) ?? ((a = t.info) == null ? void 0 : a.duration),
242
+ width: t.width,
243
+ height: t.height,
244
+ createdAt: t.created_at,
245
+ modifiedAt: t.modified_at
245
246
  };
246
247
  }
247
- function se(s) {
248
+ function se(t) {
248
249
  var l;
249
- const e = s.fields ?? L, t = s.sortBy ?? "created_at", i = s.sortDirection ?? "desc", r = [];
250
- if (s.search && r.push(s.search), s.q && r.push(s.q), (l = s.types) != null && l.length && r.push(`type:${s.types.map((a) => `"${a}"`).join(",")}`), s.sizeBucket) {
251
- const [a, c] = R[s.sizeBucket];
250
+ const e = t.fields ?? L, s = t.sortBy ?? "created_at", i = t.sortDirection ?? "desc", r = [];
251
+ if (t.search && r.push(t.search), t.q && r.push(t.q), (l = t.types) != null && l.length && r.push(`type:${t.types.map((a) => `"${a}"`).join(",")}`), t.sizeBucket) {
252
+ const [a, c] = O[t.sizeBucket];
252
253
  r.push(`size:"${a ?? ""}..${c ?? ""}"`);
253
254
  }
255
+ if (t.durationRange) {
256
+ const { min: a, max: c } = t.durationRange;
257
+ (a != null || c != null) && r.push(`video_duration:"${a ?? ""}..${c ?? ""}"`);
258
+ }
254
259
  const o = Date.now();
255
- return s.createdWithin && r.push(`created>"${y(s.createdWithin, o).toISOString()}"`), s.updatedWithin && r.push(`updated>"${y(s.updatedWithin, o).toISOString()}"`), {
256
- offset: s.offset ?? 0,
257
- limit: s.limit ?? 100,
260
+ return t.createdWithin && r.push(`created>"${y(t.createdWithin, o).toISOString()}"`), t.updatedWithin && r.push(`updated>"${y(t.updatedWithin, o).toISOString()}"`), {
261
+ offset: t.offset ?? 0,
262
+ limit: t.limit ?? 100,
258
263
  format: "json,regvar:api,select:internal",
259
264
  preview: 2301,
260
265
  // Filerobot preview-size preset for thumbnails
261
- recursive: s.recursive ?? 1,
266
+ recursive: t.recursive ?? 1,
262
267
  fields: e.length ? e : void 0,
263
- sort: `${t}:${i}`,
264
- folder: s.folder,
268
+ sort: `${s}:${i}`,
269
+ folder: t.folder,
265
270
  q: r.length ? r.join(" ") : void 0
266
271
  };
267
272
  }
268
- async function w(s, e = {}) {
269
- const t = se(e), i = await s.get("/files", t), r = (i.files ?? []).map(z), o = typeof i.total == "number" ? i.total : i.count ?? r.length;
273
+ async function w(t, e = {}) {
274
+ const s = se(e), i = await t.get("/files", s), r = (i.files ?? []).map(z), o = typeof i.total == "number" ? i.total : i.count ?? r.length;
270
275
  return { assets: r, total: o };
271
276
  }
272
- async function $e(s, e = {}) {
273
- return (await w(s, e)).assets;
277
+ async function $e(t, e = {}) {
278
+ return (await w(t, e)).assets;
274
279
  }
275
280
  const ie = {
276
281
  image: "image",
@@ -283,17 +288,21 @@ const ie = {
283
288
  font: "other",
284
289
  other: "other"
285
290
  };
286
- function re(s, e, t) {
291
+ function re(t, e, s) {
287
292
  var i;
288
- if ((i = e.types) != null && i.length && !e.types.includes(ie[s.type])) return !1;
293
+ if ((i = e.types) != null && i.length && !e.types.includes(ie[t.type])) return !1;
289
294
  if (e.sizeBucket) {
290
- const [r, o] = R[e.sizeBucket];
291
- if (s.size == null || r != null && s.size < r || o != null && s.size >= o) return !1;
295
+ const [r, o] = O[e.sizeBucket];
296
+ if (t.size == null || r != null && t.size < r || o != null && t.size >= o) return !1;
297
+ }
298
+ if (e.durationRange) {
299
+ const { min: r, max: o } = e.durationRange;
300
+ if (t.duration == null || r != null && t.duration < r || o != null && t.duration > o) return !1;
292
301
  }
293
- return !(e.createdWithin && !((s.createdAt ? Date.parse(s.createdAt) : NaN) >= y(e.createdWithin, t).getTime()) || e.updatedWithin && !((s.modifiedAt ? Date.parse(s.modifiedAt) : NaN) >= y(e.updatedWithin, t).getTime()));
302
+ return !(e.createdWithin && !((t.createdAt ? Date.parse(t.createdAt) : NaN) >= y(e.createdWithin, s).getTime()) || e.updatedWithin && !((t.modifiedAt ? Date.parse(t.modifiedAt) : NaN) >= y(e.updatedWithin, s).getTime()));
294
303
  }
295
- function ne(s, e, t) {
296
- const i = t === "asc" ? 1 : -1, r = (o) => {
304
+ function ne(t, e, s) {
305
+ const i = s === "asc" ? 1 : -1, r = (o) => {
297
306
  var l;
298
307
  switch (e) {
299
308
  case "name":
@@ -308,19 +317,19 @@ function ne(s, e, t) {
308
317
  return o.createdAt ? Date.parse(o.createdAt) : 0;
309
318
  }
310
319
  };
311
- return [...s].sort((o, l) => {
320
+ return [...t].sort((o, l) => {
312
321
  const a = r(o), c = r(l);
313
322
  return a < c ? -i : a > c ? i : 0;
314
323
  });
315
324
  }
316
- async function oe(s, e, t = {}) {
317
- const i = t.fields ?? L, r = new Array(e.length);
325
+ async function oe(t, e, s = {}) {
326
+ const i = s.fields ?? L, r = new Array(e.length);
318
327
  let o = 0;
319
328
  const l = async () => {
320
329
  for (; o < e.length; ) {
321
330
  const c = o++;
322
331
  try {
323
- const f = await s.get(`/file/${encodeURIComponent(e[c])}`, {
332
+ const f = await t.get(`/file/${encodeURIComponent(e[c])}`, {
324
333
  format: "json,regvar:api,select:internal",
325
334
  preview: 2301,
326
335
  fields: i.length ? i : void 0
@@ -329,152 +338,152 @@ async function oe(s, e, t = {}) {
329
338
  } catch {
330
339
  }
331
340
  }
332
- }, a = Math.min(t.concurrency ?? 8, e.length);
341
+ }, a = Math.min(s.concurrency ?? 8, e.length);
333
342
  return await Promise.all(Array.from({ length: a }, l)), r.filter((c) => c !== void 0);
334
343
  }
335
- async function ae(s, e, t) {
336
- const i = await s.put(`/file/${encodeURIComponent(e)}/name`, {
337
- name: t
344
+ async function ae(t, e, s) {
345
+ const i = await t.put(`/file/${encodeURIComponent(e)}/name`, {
346
+ name: s
338
347
  });
339
348
  if ((i == null ? void 0 : i.status) === "error") throw new Error(i.msg || "Failed to rename file");
340
349
  }
341
- async function ce(s, e) {
342
- const t = await s.delete("/files", { files_uuids: e });
343
- if ((t == null ? void 0 : t.status) === "error") throw new Error(t.msg || "Failed to delete files");
350
+ async function ce(t, e) {
351
+ const s = await t.delete("/files", { files_uuids: e });
352
+ if ((s == null ? void 0 : s.status) === "error") throw new Error(s.msg || "Failed to delete files");
344
353
  }
345
- async function le(s, e, t) {
346
- const i = await s.post("/files", {
354
+ async function le(t, e, s) {
355
+ const i = await t.post("/files", {
347
356
  files_uuids: e,
348
- new_folder_name: t
357
+ new_folder_name: s
349
358
  });
350
359
  if ((i == null ? void 0 : i.status) === "error") throw new Error(i.msg || "Failed to move files");
351
360
  }
352
- async function de(s) {
353
- return (await s.get("/labels")).labels ?? [];
361
+ async function de(t) {
362
+ return (await t.get("/labels")).labels ?? [];
354
363
  }
355
- function he(s) {
356
- if (s.sid)
357
- return `labels:${s.sid.replace(/^#/, "")}`;
364
+ function he(t) {
365
+ if (t.sid)
366
+ return `labels:${t.sid.replace(/^#/, "")}`;
358
367
  }
359
- function $(s, e) {
368
+ function $(t, e) {
360
369
  try {
361
- const t = new URL(s);
362
- return t.searchParams.set("p", e), t.toString();
370
+ const s = new URL(t);
371
+ return s.searchParams.set("p", e), s.toString();
363
372
  } catch {
364
- return s;
373
+ return t;
365
374
  }
366
375
  }
367
- function x(s) {
368
- var e, t, i, r, o;
376
+ function x(t) {
377
+ var e, s, i, r, o;
369
378
  return {
370
- uuid: s.uuid,
371
- name: s.name,
372
- url: s.url,
373
- previewUrl: s.preview ?? s.url,
374
- width: (e = s.info) == null ? void 0 : e.img_w,
375
- height: (t = s.info) == null ? void 0 : t.img_h,
376
- size: (i = s.info) == null ? void 0 : i.size,
377
- format: (r = s.info) == null ? void 0 : r.img_type,
379
+ uuid: t.uuid,
380
+ name: t.name,
381
+ url: t.url,
382
+ previewUrl: t.preview ?? t.url,
383
+ width: (e = t.info) == null ? void 0 : e.img_w,
384
+ height: (s = t.info) == null ? void 0 : s.img_h,
385
+ size: (i = t.info) == null ? void 0 : i.size,
386
+ format: (r = t.info) == null ? void 0 : r.img_type,
378
387
  isOriginal: !1,
379
388
  isPreset: !1,
380
- bgRemoved: ((o = s.info) == null ? void 0 : o.remove_background) === !0
389
+ bgRemoved: ((o = t.info) == null ? void 0 : o.remove_background) === !0
381
390
  };
382
391
  }
383
- function fe(s) {
392
+ function fe(t) {
384
393
  return {
385
- uuid: s.uuid,
386
- name: s.name,
387
- url: s.cdnUrl ?? "",
388
- previewUrl: s.thumbnailUrl ?? s.cdnUrl,
389
- width: s.width,
390
- height: s.height,
391
- size: s.size,
392
- format: s.fileType,
394
+ uuid: t.uuid,
395
+ name: t.name,
396
+ url: t.cdnUrl ?? "",
397
+ previewUrl: t.thumbnailUrl ?? t.cdnUrl,
398
+ width: t.width,
399
+ height: t.height,
400
+ size: t.size,
401
+ format: t.fileType,
393
402
  isOriginal: !0,
394
403
  isPreset: !1,
395
404
  bgRemoved: !1
396
405
  };
397
406
  }
398
- function ue(s, e) {
399
- const t = s.cdnUrl ?? "";
407
+ function ue(t, e) {
408
+ const s = t.cdnUrl ?? "";
400
409
  return {
401
410
  uuid: `preset-${e.name}`,
402
411
  name: e.name,
403
- url: $(t, e.name),
404
- previewUrl: $(s.thumbnailUrl ?? t, e.name),
412
+ url: $(s, e.name),
413
+ previewUrl: $(t.thumbnailUrl ?? s, e.name),
405
414
  isOriginal: !1,
406
415
  isPreset: !0,
407
416
  bgRemoved: !1
408
417
  };
409
418
  }
410
419
  function ve({
411
- asset: s,
420
+ asset: t,
412
421
  variants: e = [],
413
- presets: t = []
422
+ presets: s = []
414
423
  }) {
415
- const i = new Set(t.map((a) => a.name)), r = e.filter((a) => {
424
+ const i = new Set(s.map((a) => a.name)), r = e.filter((a) => {
416
425
  var c;
417
426
  return !i.has(a.name) && ((c = a.info) == null ? void 0 : c.remove_background) !== !0;
418
427
  }).map(x), o = e.filter((a) => {
419
428
  var c;
420
429
  return ((c = a.info) == null ? void 0 : c.remove_background) === !0 && !i.has(a.name);
421
- }).map(x), l = t.map((a) => ue(s, a));
422
- return [fe(s), ...r, ...o, ...l];
430
+ }).map(x), l = s.map((a) => ue(t, a));
431
+ return [fe(t), ...r, ...o, ...l];
423
432
  }
424
- async function ge(s, e) {
425
- const t = await s.get(
433
+ async function ge(t, e) {
434
+ const s = await t.get(
426
435
  `/file/${encodeURIComponent(e)}/variants`
427
436
  );
428
- return (t == null ? void 0 : t.variants) ?? [];
437
+ return (s == null ? void 0 : s.variants) ?? [];
429
438
  }
430
- function me(s) {
431
- return Array.isArray(s) ? s.map(
439
+ function me(t) {
440
+ return Array.isArray(t) ? t.map(
432
441
  (e) => typeof e == "string" ? { name: e } : e && typeof e.name == "string" ? { name: e.name, desc: e.desc } : null
433
442
  ).filter((e) => e !== null) : [];
434
443
  }
435
- async function pe(s) {
444
+ async function pe(t) {
436
445
  var i, r, o;
437
- const e = await s.get("/settings"), t = (e == null ? void 0 : e.presets) ?? ((i = e == null ? void 0 : e.cloudimg) == null ? void 0 : i.presets) ?? ((o = (r = e == null ? void 0 : e.settings) == null ? void 0 : r.cloudimg) == null ? void 0 : o.presets) ?? void 0;
438
- return me(t);
446
+ const e = await t.get("/settings"), s = (e == null ? void 0 : e.presets) ?? ((i = e == null ? void 0 : e.cloudimg) == null ? void 0 : i.presets) ?? ((o = (r = e == null ? void 0 : e.settings) == null ? void 0 : r.cloudimg) == null ? void 0 : o.presets) ?? void 0;
447
+ return me(s);
439
448
  }
440
- async function xe(s, e) {
441
- const [t, i] = await Promise.all([
442
- ge(s, e.uuid),
443
- pe(s)
449
+ async function xe(t, e) {
450
+ const [s, i] = await Promise.all([
451
+ ge(t, e.uuid),
452
+ pe(t)
444
453
  ]);
445
- return ve({ asset: e, variants: t, presets: i });
454
+ return ve({ asset: e, variants: s, presets: i });
446
455
  }
447
- async function we(s, e) {
448
- const t = await s.post("/file-archive", {
456
+ async function we(t, e) {
457
+ const s = await t.post("/file-archive", {
449
458
  files_uuids: e.filesUuids ?? [],
450
459
  folders_uuids: e.foldersUuids ?? [],
451
460
  urls: e.urls ?? []
452
461
  });
453
- if (!(t != null && t.task_id)) throw new Error("Archive task was not created");
454
- return t.task_id;
462
+ if (!(s != null && s.task_id)) throw new Error("Archive task was not created");
463
+ return s.task_id;
455
464
  }
456
- function ye(s, e) {
457
- return s.get(`/file-archive/${encodeURIComponent(e)}`, {
465
+ function ye(t, e) {
466
+ return t.get(`/file-archive/${encodeURIComponent(e)}`, {
458
467
  status_only: 1
459
468
  });
460
469
  }
461
470
  const Se = /* @__PURE__ */ new Set(["PENDING", "RUNNING", "PROCESSING", ""]);
462
- function be(s) {
463
- const e = ((s == null ? void 0 : s.task_status) ?? "").toUpperCase(), t = typeof (s == null ? void 0 : s.task_percent) == "number" ? s.task_percent : 0;
471
+ function be(t) {
472
+ const e = ((t == null ? void 0 : t.task_status) ?? "").toUpperCase(), s = typeof (t == null ? void 0 : t.task_percent) == "number" ? t.task_percent : 0;
464
473
  if (e === "DONE") return { done: !0, progress: 100 };
465
- if (Se.has(e)) return { done: !1, progress: t };
466
- throw new Error(`Archive job failed: ${(s == null ? void 0 : s.task_status) ?? "unknown status"}`);
474
+ if (Se.has(e)) return { done: !1, progress: s };
475
+ throw new Error(`Archive job failed: ${(t == null ? void 0 : t.task_status) ?? "unknown status"}`);
467
476
  }
468
- async function _e(s, e, t = {}) {
477
+ async function _e(t, e, s = {}) {
469
478
  var h, d;
470
- const i = t.intervalMs ?? 1500, r = t.timeoutMs ?? 12e4, o = t.maxRetries ?? 5, l = t.sleep ?? ((u) => new Promise((g) => setTimeout(g, u))), a = t.now ?? Date.now, c = a() + r;
479
+ const i = s.intervalMs ?? 1500, r = s.timeoutMs ?? 12e4, o = s.maxRetries ?? 5, l = s.sleep ?? ((u) => new Promise((g) => setTimeout(g, u))), a = s.now ?? Date.now, c = a() + r;
471
480
  let f = 0;
472
481
  for (; ; ) {
473
- if ((h = t.signal) != null && h.aborted) throw new Error("Archive polling aborted");
482
+ if ((h = s.signal) != null && h.aborted) throw new Error("Archive polling aborted");
474
483
  if (a() > c) throw new Error("Archive polling timed out");
475
484
  let u;
476
485
  try {
477
- u = await ye(s, e);
486
+ u = await ye(t, e);
478
487
  } catch (S) {
479
488
  if (f++ < o) {
480
489
  await l(i);
@@ -483,19 +492,19 @@ async function _e(s, e, t = {}) {
483
492
  throw S;
484
493
  }
485
494
  const { done: g, progress: p } = be(u);
486
- if ((d = t.onProgress) == null || d.call(t, p), g) return;
495
+ if ((d = s.onProgress) == null || d.call(s, p), g) return;
487
496
  await l(i);
488
497
  }
489
498
  }
490
- function Ae(s, e) {
491
- const t = s.absoluteUrl(`/file-archive/${encodeURIComponent(e)}`), i = s.authKey;
492
- if (!i) return t;
493
- const r = t.includes("?") ? "&" : "?";
494
- return `${t}${r}secret_key=${encodeURIComponent(i)}`;
499
+ function Ae(t, e) {
500
+ const s = t.absoluteUrl(`/file-archive/${encodeURIComponent(e)}`), i = t.authKey;
501
+ if (!i) return s;
502
+ const r = s.includes("?") ? "&" : "?";
503
+ return `${s}${r}secret_key=${encodeURIComponent(i)}`;
495
504
  }
496
- async function Ce(s, e, t = {}) {
497
- const i = await we(s, e);
498
- return await _e(s, i, t), Ae(s, i);
505
+ async function Ce(t, e, s = {}) {
506
+ const i = await we(t, e);
507
+ return await _e(t, i, s), Ae(t, i);
499
508
  }
500
509
  const Fe = ["cdn_permalink"], q = {
501
510
  created_at: "created_at",
@@ -504,56 +513,62 @@ const Fe = ["cdn_permalink"], q = {
504
513
  size: "size",
505
514
  type: "type"
506
515
  };
507
- function Ee(s) {
508
- let e = s.fields ?? Fe;
509
- s.permalinksEnabled || (e = e.filter((l) => l !== "cdn_permalink"));
510
- const t = {
511
- offset: s.offset ?? 0,
512
- limit: s.limit ?? 100,
516
+ function Ee(t) {
517
+ let e = t.fields ?? Fe;
518
+ t.permalinksEnabled || (e = e.filter((l) => l !== "cdn_permalink"));
519
+ const s = {
520
+ offset: t.offset ?? 0,
521
+ limit: t.limit ?? 100,
513
522
  format: "json,regvar:api,select:internal",
514
523
  preview: 2301,
515
- recursive: s.recursive ?? 1
524
+ recursive: t.recursive ?? 1
516
525
  };
517
- e.length > 0 && (t.fields = e);
518
- const i = s.sort_by ?? "created_at", r = s.sort_direction ?? "desc";
519
- t.sort = `${q[i] || i}:${r}`, s.folder && (t.folder = s.folder);
526
+ e.length > 0 && (s.fields = e);
527
+ const i = t.sort_by ?? "created_at", r = t.sort_direction ?? "desc";
528
+ s.sort = `${q[i] || i}:${r}`, t.folder && (s.folder = t.folder);
520
529
  const o = [];
521
- return s.search && !s.with_ai && o.push(s.search), s.q && o.push(s.q), o.length > 0 && (t.q = o.join(" ")), s.with_ai && (t.with_ai = !0, s.ai_query && (t.ai_query = s.ai_query), s.ai_lang && (t.ai_lang = s.ai_lang)), s.collection_uuid && (t.collection_uuid = s.collection_uuid), s.f64 && (t.f64 = s.f64), t;
530
+ return t.search && !t.with_ai && o.push(t.search), t.q && o.push(t.q), o.length > 0 && (s.q = o.join(" ")), t.with_ai && (s.with_ai = !0, t.ai_query && (s.ai_query = t.ai_query), t.ai_lang && (s.ai_lang = t.ai_lang)), t.collection_uuid && (s.collection_uuid = t.collection_uuid), t.f64 && (s.f64 = t.f64), s;
522
531
  }
523
- function Ue(s, e) {
524
- return s.get("/files", Ee(e));
532
+ function Ue(t, e) {
533
+ return t.get("/files", Ee(e));
525
534
  }
526
- function De(s, e) {
527
- const t = { recursive: e.recursive ?? 1 };
528
- e.folder && (t.folder = e.folder);
535
+ function De(t, e) {
536
+ const s = { recursive: e.recursive ?? 1 };
537
+ e.folder && (s.folder = e.folder);
529
538
  const i = [];
530
- return e.search && !e.with_ai && i.push(e.search), e.q && i.push(e.q), i.length > 0 && (t.q = i.join(" ")), e.with_ai && (t.with_ai = !0, e.ai_query && (t.ai_query = e.ai_query), e.ai_lang && (t.ai_lang = e.ai_lang)), e.collection_uuid && (t.collection_uuid = e.collection_uuid), e.f64 && (t.f64 = e.f64), s.get("/files/stats", t);
539
+ return e.search && !e.with_ai && i.push(e.search), e.q && i.push(e.q), i.length > 0 && (s.q = i.join(" ")), e.with_ai && (s.with_ai = !0, e.ai_query && (s.ai_query = e.ai_query), e.ai_lang && (s.ai_lang = e.ai_lang)), e.collection_uuid && (s.collection_uuid = e.collection_uuid), e.f64 && (s.f64 = e.f64), t.get("/files/stats", s);
531
540
  }
532
- function ke(s, e = {}) {
533
- const t = {
541
+ function ke(t, e = {}) {
542
+ const s = {
534
543
  recursive: e.recursive ?? 0,
535
544
  folder: e.folderPath ?? "/",
536
545
  limit: e.limit ?? 1e3,
537
546
  offset: e.offset ?? 0
538
547
  };
539
- e.q && (t.q = e.q);
548
+ e.q && (s.q = e.q);
540
549
  const i = e.sort_by ?? "created_at", r = e.sort_direction ?? "asc";
541
- return t.sort = `${q[i] || i}:${r}`, s.get("/folders", t);
550
+ return s.sort = `${q[i] || i}:${r}`, t.get("/folders", s);
542
551
  }
543
- async function Me(s, e) {
544
- return e.length === 0 ? {} : (await s.post("/folders/previews", {
552
+ async function Me(t, e) {
553
+ return e.length === 0 ? {} : (await t.post("/folders/previews", {
545
554
  folders: e
546
555
  })).folders || {};
547
556
  }
548
- const C = 100, U = 1e3, D = { types: [], size: null, created: null, updated: null };
557
+ const C = 100, U = 1e3, D = {
558
+ types: [],
559
+ size: null,
560
+ duration: null,
561
+ created: null,
562
+ updated: null
563
+ };
549
564
  class E {
550
- constructor(e, t = {}) {
551
- this.client = e, this.listeners = /* @__PURE__ */ new Set(), this.loadSeq = 0, this.treeSeq = 0, this.fetchedCount = 0, this.selectionAnchor = null, this.favAdapter = t.favourites, this.onScopeChange = t.onScopeChange, this.state = {
552
- scope: { type: "folder", value: t.rootFolder ?? "/" },
553
- viewMode: t.viewMode ?? "grid",
554
- gridSize: t.gridSize ?? "m",
555
- sortBy: t.sortBy ?? "created_at",
556
- sortDirection: t.sortDirection ?? "desc",
565
+ constructor(e, s = {}) {
566
+ this.client = e, this.listeners = /* @__PURE__ */ new Set(), this.loadSeq = 0, this.treeSeq = 0, this.fetchedCount = 0, this.selectionAnchor = null, this.favAdapter = s.favourites, this.onScopeChange = s.onScopeChange, this.state = {
567
+ scope: { type: "folder", value: s.rootFolder ?? "/" },
568
+ viewMode: s.viewMode ?? "grid",
569
+ gridSize: s.gridSize ?? "m",
570
+ sortBy: s.sortBy ?? "created_at",
571
+ sortDirection: s.sortDirection ?? "desc",
557
572
  searchQuery: "",
558
573
  filters: { ...D },
559
574
  folders: [],
@@ -580,15 +595,15 @@ class E {
580
595
  async loadFolderChildren(e) {
581
596
  if (!this.state.treeChildren[e])
582
597
  try {
583
- const t = await b(this.client, { folderPath: e });
584
- this.set({ treeChildren: { ...this.state.treeChildren, [e]: t } });
598
+ const s = await b(this.client, { folderPath: e });
599
+ this.set({ treeChildren: { ...this.state.treeChildren, [e]: s } });
585
600
  } catch {
586
601
  }
587
602
  }
588
603
  /** Expand/collapse a folder node, lazy-loading its children on first expand. */
589
604
  async toggleFolder(e) {
590
- const t = new Set(this.state.expandedFolders);
591
- t.has(e) ? (t.delete(e), this.set({ expandedFolders: t })) : (await this.loadFolderChildren(e), t.add(e), this.set({ expandedFolders: t }));
605
+ const s = new Set(this.state.expandedFolders);
606
+ s.has(e) ? (s.delete(e), this.set({ expandedFolders: s })) : (await this.loadFolderChildren(e), s.add(e), this.set({ expandedFolders: s }));
592
607
  }
593
608
  async loadLabels() {
594
609
  try {
@@ -605,13 +620,13 @@ class E {
605
620
  }
606
621
  /** Toggle an asset's favourite status (per-user, via the adapter). */
607
622
  async toggleFavourite(e) {
608
- const t = this.state.favourites.has(e), i = new Set(this.state.favourites);
609
- t ? i.delete(e) : i.add(e), this.set({ favourites: i });
623
+ const s = this.state.favourites.has(e), i = new Set(this.state.favourites);
624
+ s ? i.delete(e) : i.add(e), this.set({ favourites: i });
610
625
  try {
611
- this.favAdapter && (t ? await this.favAdapter.remove(e) : await this.favAdapter.add(e));
626
+ this.favAdapter && (s ? await this.favAdapter.remove(e) : await this.favAdapter.add(e));
612
627
  } catch {
613
628
  const r = new Set(this.state.favourites);
614
- t ? r.add(e) : r.delete(e), this.set({ favourites: r });
629
+ s ? r.add(e) : r.delete(e), this.set({ favourites: r });
615
630
  return;
616
631
  }
617
632
  this.state.scope.type === "favourites" && this.load();
@@ -624,12 +639,12 @@ class E {
624
639
  }
625
640
  set(e) {
626
641
  this.state = { ...this.state, ...e };
627
- for (const t of this.listeners) t(this.state);
642
+ for (const s of this.listeners) s(this.state);
628
643
  }
629
644
  // ── navigation / scope ─────────────────────────────────────────────────────
630
645
  setScope(e) {
631
- var t;
632
- this.selectionAnchor = null, this.set({ scope: e, selection: /* @__PURE__ */ new Set() }), (t = this.onScopeChange) == null || t.call(this, e), this.load();
646
+ var s;
647
+ this.selectionAnchor = null, this.set({ scope: e, selection: /* @__PURE__ */ new Set() }), (s = this.onScopeChange) == null || s.call(this, e), this.load();
633
648
  }
634
649
  openFolder(e) {
635
650
  this.setScope({ type: "folder", value: e });
@@ -647,8 +662,8 @@ class E {
647
662
  setGridSize(e) {
648
663
  this.set({ gridSize: e });
649
664
  }
650
- setSort(e, t) {
651
- this.set({ sortBy: e, sortDirection: t }), this.load();
665
+ setSort(e, s) {
666
+ this.set({ sortBy: e, sortDirection: s }), this.load();
652
667
  }
653
668
  setSearch(e) {
654
669
  this.set({ searchQuery: e }), this.load();
@@ -659,23 +674,23 @@ class E {
659
674
  }
660
675
  /** Toggle one file-type in the type facet. Reloads from page 1. */
661
676
  toggleType(e) {
662
- const t = this.state.filters.types;
677
+ const s = this.state.filters.types;
663
678
  this.setFilters({
664
- types: t.includes(e) ? t.filter((i) => i !== e) : [...t, e]
679
+ types: s.includes(e) ? s.filter((i) => i !== e) : [...s, e]
665
680
  });
666
681
  }
667
682
  /** Number of active facets across all groups (for the toolbar badge). */
668
683
  get activeFilterCount() {
669
- const { types: e, size: t, created: i, updated: r } = this.state.filters;
670
- return e.length + (t ? 1 : 0) + (i ? 1 : 0) + (r ? 1 : 0);
684
+ const { types: e, size: s, duration: i, created: r, updated: o } = this.state.filters;
685
+ return e.length + (s ? 1 : 0) + (i ? 1 : 0) + (r ? 1 : 0) + (o ? 1 : 0);
671
686
  }
672
687
  /** Clear every facet in one update, then reload. No-op if nothing is active. */
673
688
  clearFilters() {
674
689
  this.activeFilterCount && (this.set({ filters: { ...D } }), this.load());
675
690
  }
676
691
  // ── selection ──────────────────────────────────────────────────────────────
677
- toggleSelect(e, t = !1) {
678
- const i = new Set(t ? this.state.selection : []), r = !i.has(e);
692
+ toggleSelect(e, s = !1) {
693
+ const i = new Set(s ? this.state.selection : []), r = !i.has(e);
679
694
  r ? i.add(e) : i.delete(e), r && (this.selectionAnchor = e), this.set({ selection: i });
680
695
  }
681
696
  /**
@@ -686,23 +701,23 @@ class E {
686
701
  * anchor yet, behaves like a plain multi-select toggle.
687
702
  */
688
703
  selectRange(e) {
689
- const t = this.state.assets, i = t.findIndex((c) => c.uuid === e);
704
+ const s = this.state.assets, i = s.findIndex((c) => c.uuid === e);
690
705
  if (i < 0) return;
691
- const r = this.selectionAnchor != null ? t.findIndex((c) => c.uuid === this.selectionAnchor) : -1;
706
+ const r = this.selectionAnchor != null ? s.findIndex((c) => c.uuid === this.selectionAnchor) : -1;
692
707
  if (r < 0) {
693
708
  this.toggleSelect(e, !0);
694
709
  return;
695
710
  }
696
711
  const [o, l] = r <= i ? [r, i] : [i, r], a = new Set(this.state.selection);
697
- for (let c = o; c <= l; c++) a.add(t[c].uuid);
712
+ for (let c = o; c <= l; c++) a.add(s[c].uuid);
698
713
  this.set({ selection: a });
699
714
  }
700
715
  /** Replace the whole selection in one update (e.g. "select all", marquee drag). */
701
716
  setSelection(e) {
702
- const t = new Set(e);
717
+ const s = new Set(e);
703
718
  let i = null;
704
- for (const r of t) i = r;
705
- this.selectionAnchor = i, this.set({ selection: t });
719
+ for (const r of s) i = r;
720
+ this.selectionAnchor = i, this.set({ selection: s });
706
721
  }
707
722
  clearSelection() {
708
723
  this.selectionAnchor = null, this.set({ selection: /* @__PURE__ */ new Set() });
@@ -721,9 +736,9 @@ class E {
721
736
  * `treeSeq` guard discards a superseded refresh.
722
737
  */
723
738
  async refreshTree() {
724
- const e = ++this.treeSeq, t = /* @__PURE__ */ new Set(["/", this.currentFolderPath, ...this.state.expandedFolders]), i = {};
739
+ const e = ++this.treeSeq, s = /* @__PURE__ */ new Set(["/", this.currentFolderPath, ...this.state.expandedFolders]), i = {};
725
740
  await Promise.all(
726
- [...t].map(async (r) => {
741
+ [...s].map(async (r) => {
727
742
  try {
728
743
  i[r] = await b(this.client, { folderPath: r });
729
744
  } catch {
@@ -740,8 +755,8 @@ class E {
740
755
  }
741
756
  /** Find a cached folder's path by uuid (across the tree cache + current list). */
742
757
  folderPath(e) {
743
- for (const t of [this.state.folders, ...Object.values(this.state.treeChildren)]) {
744
- const i = t.find((r) => r.uuid === e);
758
+ for (const s of [this.state.folders, ...Object.values(this.state.treeChildren)]) {
759
+ const i = s.find((r) => r.uuid === e);
745
760
  if (i) return i.path;
746
761
  }
747
762
  }
@@ -751,49 +766,50 @@ class E {
751
766
  * scope to its new path (or the parent on delete). Returns true if it redirected
752
767
  * (which itself triggers a reload), so the caller can skip its own load().
753
768
  */
754
- redirectScope(e, t) {
769
+ redirectScope(e, s) {
755
770
  const { scope: i } = this.state;
756
771
  if (i.type !== "folder" || !i.value) return !1;
757
772
  const r = i.value;
758
- return r !== e && !r.startsWith(e + "/") ? !1 : (t === null ? this.openFolder(E.parentOf(e)) : this.openFolder(r === e ? t : t + r.slice(e.length)), !0);
773
+ return r !== e && !r.startsWith(e + "/") ? !1 : (s === null ? this.openFolder(E.parentOf(e)) : this.openFolder(r === e ? s : s + r.slice(e.length)), !0);
759
774
  }
760
775
  async createFolder(e) {
761
776
  await K(this.client, e, this.currentFolderPath), await this.refreshTree(), await this.load();
762
777
  }
763
- async renameFolderById(e, t) {
778
+ async renameFolderById(e, s) {
764
779
  const i = this.folderPath(e);
765
- await Y(this.client, e, t), await this.refreshTree();
766
- const r = i ? `${E.parentOf(i).replace(/\/$/, "")}/${t}` : null;
780
+ await Y(this.client, e, s), await this.refreshTree();
781
+ const r = i ? `${E.parentOf(i).replace(/\/$/, "")}/${s}` : null;
767
782
  i && r && this.redirectScope(i, r) || await this.load();
768
783
  }
769
784
  async deleteFolderById(e) {
770
- const t = this.folderPath(e);
771
- await Z(this.client, [e]), await this.refreshTree(), t && this.redirectScope(t, null) || await this.load();
785
+ const s = this.folderPath(e);
786
+ await Z(this.client, [e]), await this.refreshTree(), s && this.redirectScope(s, null) || await this.load();
772
787
  }
773
- async moveFolderById(e, t) {
788
+ async moveFolderById(e, s) {
774
789
  const i = this.folderPath(e);
775
- await Q(this.client, [e], t), await this.refreshTree();
776
- const r = (i == null ? void 0 : i.split("/").pop()) ?? "", o = i ? `${t.replace(/\/$/, "")}/${r}` : null;
790
+ await Q(this.client, [e], s), await this.refreshTree();
791
+ const r = (i == null ? void 0 : i.split("/").pop()) ?? "", o = i ? `${s.replace(/\/$/, "")}/${r}` : null;
777
792
  i && o && this.redirectScope(i, o) || await this.load();
778
793
  }
779
- async renameAsset(e, t) {
780
- await ae(this.client, e, t), await this.load();
794
+ async renameAsset(e, s) {
795
+ await ae(this.client, e, s), await this.load();
781
796
  }
782
797
  async deleteAssets(e) {
783
798
  await ce(this.client, e), this.clearSelection(), await this.load();
784
799
  }
785
- async moveAssets(e, t) {
786
- await le(this.client, e, t), this.clearSelection(), await this.load();
800
+ async moveAssets(e, s) {
801
+ await le(this.client, e, s), this.clearSelection(), await this.load();
787
802
  }
788
803
  // ── data loading ───────────────────────────────────────────────────────────
789
804
  /** Translate the active filter facets into the api query shape (undefined = off). */
790
805
  facetParams() {
791
- const { types: e, size: t, created: i, updated: r } = this.state.filters;
806
+ const { types: e, size: s, duration: i, created: r, updated: o } = this.state.filters;
792
807
  return {
793
808
  types: e.length ? e : void 0,
794
- sizeBucket: t ?? void 0,
795
- createdWithin: i ?? void 0,
796
- updatedWithin: r ?? void 0
809
+ sizeBucket: s ?? void 0,
810
+ durationRange: i ?? void 0,
811
+ createdWithin: r ?? void 0,
812
+ updatedWithin: o ?? void 0
797
813
  };
798
814
  }
799
815
  /**
@@ -808,8 +824,8 @@ class E {
808
824
  * the caller advances its offset cursor correctly even when dedupe drops items.
809
825
  */
810
826
  async fetchAssetsPage(e) {
811
- const { scope: t, sortBy: i, sortDirection: r } = this.state, o = this.state.searchQuery || void 0, l = this.facetParams();
812
- if (t.type === "favourites") {
827
+ const { scope: s, sortBy: i, sortDirection: r } = this.state, o = this.state.searchQuery || void 0, l = this.facetParams();
828
+ if (s.type === "favourites") {
813
829
  const h = [...this.state.favourites], d = await oe(this.client, h.slice(0, U)), u = Date.now(), g = d.filter((S) => re(S, l, u)), p = ne(g, i, r);
814
830
  return {
815
831
  assets: p,
@@ -821,11 +837,11 @@ class E {
821
837
  }
822
838
  const a = { sortBy: i, sortDirection: r, search: o, ...l, offset: e, limit: C };
823
839
  let c;
824
- if (t.type === "folder") {
840
+ if (s.type === "folder") {
825
841
  const h = this.state.searchQuery.trim() ? 1 : 0;
826
- c = await w(this.client, { ...a, folder: t.value ?? "/", recursive: h });
827
- } else if (t.type === "label") {
828
- const h = this.state.labels.find((u) => u.uuid === t.value), d = h ? he(h) : void 0;
842
+ c = await w(this.client, { ...a, folder: s.value ?? "/", recursive: h });
843
+ } else if (s.type === "label") {
844
+ const h = this.state.labels.find((u) => u.uuid === s.value), d = h ? he(h) : void 0;
829
845
  c = await w(this.client, { ...a, recursive: 1, q: d });
830
846
  } else
831
847
  c = await w(this.client, { ...a, recursive: 1 });
@@ -843,7 +859,7 @@ class E {
843
859
  const e = ++this.loadSeq;
844
860
  this.set({ loading: !0, loadingMore: !1, error: null });
845
861
  try {
846
- const t = b(this.client, { folderPath: this.currentFolderPath }), i = this.fetchAssetsPage(0), [r, o] = await Promise.all([t, i]);
862
+ const s = b(this.client, { folderPath: this.currentFolderPath }), i = this.fetchAssetsPage(0), [r, o] = await Promise.all([s, i]);
847
863
  if (e !== this.loadSeq) return;
848
864
  this.fetchedCount = o.fetched, this.set({
849
865
  folders: r,
@@ -855,9 +871,9 @@ class E {
855
871
  // keep the tree cache warm for the folder we just listed
856
872
  treeChildren: { ...this.state.treeChildren, [this.currentFolderPath]: r }
857
873
  });
858
- } catch (t) {
874
+ } catch (s) {
859
875
  if (e !== this.loadSeq) return;
860
- this.set({ error: t instanceof Error ? t.message : String(t), loading: !1 });
876
+ this.set({ error: s instanceof Error ? s.message : String(s), loading: !1 });
861
877
  }
862
878
  }
863
879
  /**
@@ -874,25 +890,25 @@ class E {
874
890
  const e = this.loadSeq;
875
891
  this.set({ loadingMore: !0 });
876
892
  try {
877
- const t = await this.fetchAssetsPage(this.fetchedCount);
893
+ const s = await this.fetchAssetsPage(this.fetchedCount);
878
894
  if (e !== this.loadSeq) return;
879
- this.fetchedCount += t.fetched;
880
- const i = new Set(this.state.assets.map((o) => o.uuid)), r = t.assets.filter((o) => !i.has(o.uuid));
895
+ this.fetchedCount += s.fetched;
896
+ const i = new Set(this.state.assets.map((o) => o.uuid)), r = s.assets.filter((o) => !i.has(o.uuid));
881
897
  this.set({
882
898
  assets: [...this.state.assets, ...r],
883
- total: t.total,
884
- hasMore: t.hasMore,
899
+ total: s.total,
900
+ hasMore: s.hasMore,
885
901
  loadingMore: !1,
886
902
  error: null
887
903
  // a recovered page clears any prior load-more failure
888
904
  });
889
- } catch (t) {
905
+ } catch (s) {
890
906
  if (e !== this.loadSeq) return;
891
- this.set({ error: t instanceof Error ? t.message : String(t), loadingMore: !1 });
907
+ this.set({ error: s instanceof Error ? s.message : String(s), loadingMore: !1 });
892
908
  }
893
909
  }
894
910
  }
895
- class Oe {
911
+ class Re {
896
912
  constructor(e = "sfx-light-dam:favourites") {
897
913
  this.key = e;
898
914
  }
@@ -917,73 +933,73 @@ class Oe {
917
933
  return this.read().has(e);
918
934
  }
919
935
  add(e) {
920
- const t = this.read();
921
- t.add(e), this.write(t);
936
+ const s = this.read();
937
+ s.add(e), this.write(s);
922
938
  }
923
939
  remove(e) {
924
- const t = this.read();
925
- t.delete(e), this.write(t);
940
+ const s = this.read();
941
+ s.delete(e), this.write(s);
926
942
  }
927
943
  }
928
- function Re(s, e) {
929
- const t = new URL(s);
930
- return e.width && t.searchParams.set("w", String(e.width)), e.height && t.searchParams.set("h", String(e.height)), e.quality !== void 0 && t.searchParams.set("q", String(e.quality)), t.toString();
944
+ function Oe(t, e) {
945
+ const s = new URL(t);
946
+ return e.width && s.searchParams.set("w", String(e.width)), e.height && s.searchParams.set("h", String(e.height)), e.quality !== void 0 && s.searchParams.set("q", String(e.quality)), s.toString();
931
947
  }
932
948
  const Le = { excellent: 90, good: 75, fair: 60 }, ze = { fullhd: 1920, large: 1200, medium: 600, small: 300 }, Pe = {
933
949
  webp: "awebp,webp",
934
950
  gif: "agif,gif"
935
951
  };
936
- function j(s, e) {
937
- s.searchParams.delete("download"), e.width && s.searchParams.set("w", String(e.width)), e.height && s.searchParams.set("h", String(e.height)), e.quality != null && s.searchParams.set("q", String(e.quality)), e.format && s.searchParams.set("force_format", Pe[e.format] ?? e.format), e.strictSizes !== void 0 && (e.width || e.height) && s.searchParams.set("func", e.strictSizes ? "bound" : "cover");
952
+ function j(t, e) {
953
+ t.searchParams.delete("download"), e.width && t.searchParams.set("w", String(e.width)), e.height && t.searchParams.set("h", String(e.height)), e.quality != null && t.searchParams.set("q", String(e.quality)), e.format && t.searchParams.set("force_format", Pe[e.format] ?? e.format), e.strictSizes !== void 0 && (e.width || e.height) && t.searchParams.set("func", e.strictSizes ? "bound" : "cover");
938
954
  }
939
- function Te(s, e) {
940
- if (!e) return s;
941
- const t = e === "jpeg" ? "jpg" : e;
942
- return `${s.replace(/\.[^./\\]+$/, "") || s}.${t}`;
955
+ function Te(t, e) {
956
+ if (!e) return t;
957
+ const s = e === "jpeg" ? "jpg" : e;
958
+ return `${t.replace(/\.[^./\\]+$/, "") || t}.${s}`;
943
959
  }
944
- function qe(s, e, t = {}) {
945
- const i = new URL(s);
946
- return j(i, t), i.searchParams.set("force_download", Te(e, t.format)), i.toString();
960
+ function qe(t, e, s = {}) {
961
+ const i = new URL(t);
962
+ return j(i, s), i.searchParams.set("force_download", Te(e, s.format)), i.toString();
947
963
  }
948
- function je(s, e = {}) {
949
- const t = new URL(s);
950
- return j(t, e), t.toString();
964
+ function je(t, e = {}) {
965
+ const s = new URL(t);
966
+ return j(s, e), s.toString();
951
967
  }
952
968
  const k = /^(https:\/\/)([a-z0-9_-]+)\.filerobot\.com\/(?:v\d+\/)?/i;
953
- function _(s) {
954
- if (!s) return "";
969
+ function _(t) {
970
+ if (!t) return "";
955
971
  const e = (i) => i.replace(/(\.filerobot\.com\/[a-z0-9_-]+)\/v\d+\//i, "$1/");
956
- if (s.includes("assets.filerobot.com")) return e(s);
957
- const t = s.match(k);
958
- return t ? e(s.replace(k, `$1assets.filerobot.com/${t[2]}/`)) : s;
972
+ if (t.includes("assets.filerobot.com")) return e(t);
973
+ const s = t.match(k);
974
+ return s ? e(t.replace(k, `$1assets.filerobot.com/${s[2]}/`)) : t;
959
975
  }
960
- function A(s, e) {
976
+ function A(t, e) {
961
977
  try {
962
- const t = new URL(s);
963
- for (const [i, r] of Object.entries(e)) t.searchParams.set(i, r);
964
- return t.toString();
978
+ const s = new URL(t);
979
+ for (const [i, r] of Object.entries(e)) s.searchParams.set(i, r);
980
+ return s.toString();
965
981
  } catch {
966
- return s;
982
+ return t;
967
983
  }
968
984
  }
969
- function Ne(s, e = 240) {
970
- const t = String(e);
971
- if (s.type === "video")
972
- return s.thumbnailUrl ? A(_(s.thumbnailUrl), { w: t, force_format: "webp,jpeg" }) : "";
973
- if (s.type === "document" && /\.pdf$/i.test(s.name)) {
974
- const i = _(s.cdnUrl ?? "");
985
+ function Ne(t, e = 240) {
986
+ const s = String(e);
987
+ if (t.type === "video")
988
+ return t.thumbnailUrl ? A(_(t.thumbnailUrl), { w: s, force_format: "webp,jpeg" }) : "";
989
+ if (t.type === "document" && /\.pdf$/i.test(t.name)) {
990
+ const i = _(t.cdnUrl ?? "");
975
991
  if (!i) return "";
976
992
  const r = i.replace(/([?&])func=proxy&?/, "$1").replace(/[?&]$/, "");
977
993
  return A(r, {
978
- w: t,
994
+ w: s,
979
995
  force_format: "webp,jpeg",
980
996
  doc_page: "1",
981
997
  bypass_process_proxy: "1"
982
998
  });
983
999
  }
984
- if (s.type === "image" || s.thumbnailUrl) {
985
- const i = s.thumbnailUrl ?? s.cdnUrl;
986
- return i ? A(_(i), { w: t, func: "bound" }) : "";
1000
+ if (t.type === "image" || t.thumbnailUrl) {
1001
+ const i = t.thumbnailUrl ?? t.cdnUrl;
1002
+ return i ? A(_(i), { w: s, func: "bound" }) : "";
987
1003
  }
988
1004
  return "";
989
1005
  }
@@ -1099,47 +1115,47 @@ const n = "https://scaleflex.cloudimg.io/v7/assets/file-types/v3/", Ie = '<svg x
1099
1115
  function Be() {
1100
1116
  return P._default;
1101
1117
  }
1102
- function Ge(s) {
1103
- const e = (s.split(".").pop() || "").toLowerCase();
1118
+ function Ge(t) {
1119
+ const e = (t.split(".").pop() || "").toLowerCase();
1104
1120
  return P[e] || P._default;
1105
1121
  }
1106
- function We(s) {
1107
- if (s == null || !Number.isFinite(s) || s < 0) return "—";
1122
+ function We(t) {
1123
+ if (t == null || !Number.isFinite(t) || t < 0) return "—";
1108
1124
  const e = ["B", "KB", "MB", "GB", "TB"];
1109
- let t = s, i = 0;
1110
- for (; t >= 1024 && i < e.length - 1; )
1111
- t /= 1024, i++;
1125
+ let s = t, i = 0;
1126
+ for (; s >= 1024 && i < e.length - 1; )
1127
+ s /= 1024, i++;
1112
1128
  const r = (a, c) => {
1113
1129
  const f = c > 0 && Math.round(a * 10) / 10 < 10 ? 1 : 0, h = a.toFixed(f);
1114
1130
  return { str: h, rounded: Number(h) };
1115
- }, o = r(t, i);
1131
+ }, o = r(s, i);
1116
1132
  let l = o.str;
1117
- return o.rounded >= 1024 && i < e.length - 1 && (t /= 1024, i++, l = r(t, i).str), `${l} ${e[i]}`;
1133
+ return o.rounded >= 1024 && i < e.length - 1 && (s /= 1024, i++, l = r(s, i).str), `${l} ${e[i]}`;
1118
1134
  }
1119
- function Xe(s) {
1120
- if (!s) return "—";
1121
- const e = new Date(s);
1122
- return Number.isNaN(e.getTime()) ? s : e.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
1135
+ function Xe(t) {
1136
+ if (!t) return "—";
1137
+ const e = new Date(t);
1138
+ return Number.isNaN(e.getTime()) ? t : e.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
1123
1139
  }
1124
- function Ve(s, e) {
1125
- return s && e ? `${s} × ${e}` : "—";
1140
+ function Ve(t, e) {
1141
+ return t && e ? `${t} × ${e}` : "—";
1126
1142
  }
1127
- function He(s, e) {
1128
- let t;
1143
+ function He(t, e) {
1144
+ let s;
1129
1145
  const i = ((...r) => {
1130
- clearTimeout(t), t = setTimeout(() => s(...r), e);
1146
+ clearTimeout(s), s = setTimeout(() => t(...r), e);
1131
1147
  });
1132
- return i.cancel = () => clearTimeout(t), i;
1148
+ return i.cancel = () => clearTimeout(s), i;
1133
1149
  }
1134
1150
  export {
1135
1151
  E as BrowseStore,
1136
- O as DamClient,
1137
- Oe as LocalFavouritesAdapter,
1152
+ R as DamClient,
1153
+ Re as LocalFavouritesAdapter,
1138
1154
  U as MAX_FAVOURITES,
1139
1155
  C as PAGE_SIZE,
1140
1156
  Le as QUALITY_LEVELS,
1141
1157
  ze as RESIZE_PRESETS,
1142
- Re as addCdnParams,
1158
+ Oe as addCdnParams,
1143
1159
  Ae as archiveDownloadUrl,
1144
1160
  be as archiveStatusOutcome,
1145
1161
  ve as assembleVariations,