Subir ajustes de acordeon y SEO
This commit is contained in:
Vendored
+72
-43
@@ -194,7 +194,8 @@ var wp;
|
||||
maxConcurrentUploads: DEFAULT_MAX_CONCURRENT_UPLOADS,
|
||||
maxConcurrentImageProcessing: DEFAULT_MAX_CONCURRENT_IMAGE_PROCESSING,
|
||||
retry: { ...DEFAULT_RETRY_SETTINGS }
|
||||
}
|
||||
},
|
||||
failureCount: 0
|
||||
};
|
||||
function reducer(state = DEFAULT_STATE, action = { type: Type.Unknown }) {
|
||||
switch (action.type) {
|
||||
@@ -235,9 +236,13 @@ var wp;
|
||||
...state,
|
||||
queue: [...state.queue, action.item]
|
||||
};
|
||||
case Type.Cancel:
|
||||
case Type.Cancel: {
|
||||
const cancelled = state.queue.find(
|
||||
(item) => item.id === action.id
|
||||
);
|
||||
return {
|
||||
...state,
|
||||
failureCount: cancelled && !cancelled.parentId ? state.failureCount + 1 : state.failureCount,
|
||||
queue: state.queue.map(
|
||||
(item) => item.id === action.id ? {
|
||||
...item,
|
||||
@@ -245,6 +250,7 @@ var wp;
|
||||
} : item
|
||||
)
|
||||
};
|
||||
}
|
||||
case Type.RetryItem:
|
||||
return {
|
||||
...state,
|
||||
@@ -421,6 +427,7 @@ var wp;
|
||||
getAllItems: () => getAllItems,
|
||||
getBlobUrls: () => getBlobUrls,
|
||||
getFailedItems: () => getFailedItems,
|
||||
getFailureCount: () => getFailureCount,
|
||||
getItem: () => getItem,
|
||||
getItemProgress: () => getItemProgress,
|
||||
getPendingImageProcessing: () => getPendingImageProcessing,
|
||||
@@ -433,6 +440,9 @@ var wp;
|
||||
function getAllItems(state) {
|
||||
return state.queue;
|
||||
}
|
||||
function getFailureCount(state) {
|
||||
return state.failureCount;
|
||||
}
|
||||
function getItem(state, id) {
|
||||
return state.queue.find((item) => item.id === id);
|
||||
}
|
||||
@@ -1569,6 +1579,13 @@ var wp;
|
||||
}
|
||||
function readItemData(buffer, loc, idatOffset) {
|
||||
const baseOffset = loc.constructionMethod === 1 ? idatOffset : 0;
|
||||
for (const ext of loc.extents) {
|
||||
if (baseOffset + ext.offset + ext.length > buffer.byteLength) {
|
||||
throw new Error(
|
||||
"HEIC item data extends past the end of the file"
|
||||
);
|
||||
}
|
||||
}
|
||||
if (loc.extents.length === 1) {
|
||||
const ext = loc.extents[0];
|
||||
const start = baseOffset + ext.offset;
|
||||
@@ -2057,6 +2074,8 @@ var wp;
|
||||
}
|
||||
|
||||
// packages/upload-media/build-module/canvas-utils.mjs
|
||||
var HeicUnsupportedError = class extends Error {
|
||||
};
|
||||
async function canvasConvertToJpeg(file, quality = 0.82) {
|
||||
const baseName = getFileBasename(file.name);
|
||||
try {
|
||||
@@ -2114,51 +2133,57 @@ var wp;
|
||||
}
|
||||
}
|
||||
}
|
||||
let heicData;
|
||||
try {
|
||||
heicData = parseHeic(await file.arrayBuffer());
|
||||
} catch (error) {
|
||||
throw new Error("The HEIC file could not be parsed", {
|
||||
cause: error
|
||||
});
|
||||
}
|
||||
if (typeof VideoDecoder !== "undefined") {
|
||||
let supported = false;
|
||||
try {
|
||||
const heicData = parseHeic(await file.arrayBuffer());
|
||||
const support = await VideoDecoder.isConfigSupported({
|
||||
codec: heicData.codecString
|
||||
});
|
||||
if (support.supported) {
|
||||
const canvas = new OffscreenCanvas(
|
||||
heicData.outputWidth,
|
||||
heicData.outputHeight
|
||||
);
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) {
|
||||
throw new Error("Could not get canvas 2d context");
|
||||
}
|
||||
for (const tile of heicData.tiles) {
|
||||
const frame = await decodeHevcFrame(
|
||||
heicData.codecString,
|
||||
heicData.description,
|
||||
heicData.tileWidth,
|
||||
heicData.tileHeight,
|
||||
tile.data
|
||||
);
|
||||
try {
|
||||
ctx.drawImage(frame, tile.x, tile.y);
|
||||
} finally {
|
||||
frame.close();
|
||||
}
|
||||
}
|
||||
const outputCanvas = heicData.rotation !== 0 ? applyRotation(canvas, heicData.rotation) : applyExifOrientation(
|
||||
canvas,
|
||||
heicData.exifOrientation
|
||||
);
|
||||
const jpegBlob = await outputCanvas.convertToBlob({
|
||||
type: "image/jpeg",
|
||||
quality
|
||||
});
|
||||
return new File([jpegBlob], `${baseName}.jpg`, {
|
||||
type: "image/jpeg"
|
||||
});
|
||||
}
|
||||
supported = support.supported === true;
|
||||
} catch {
|
||||
}
|
||||
if (supported) {
|
||||
const canvas = new OffscreenCanvas(
|
||||
heicData.outputWidth,
|
||||
heicData.outputHeight
|
||||
);
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) {
|
||||
throw new Error("Could not get canvas 2d context");
|
||||
}
|
||||
for (const tile of heicData.tiles) {
|
||||
const frame = await decodeHevcFrame(
|
||||
heicData.codecString,
|
||||
heicData.description,
|
||||
heicData.tileWidth,
|
||||
heicData.tileHeight,
|
||||
tile.data
|
||||
);
|
||||
try {
|
||||
ctx.drawImage(frame, tile.x, tile.y);
|
||||
} finally {
|
||||
frame.close();
|
||||
}
|
||||
}
|
||||
const outputCanvas = heicData.rotation !== 0 ? applyRotation(canvas, heicData.rotation) : applyExifOrientation(canvas, heicData.exifOrientation);
|
||||
const jpegBlob = await outputCanvas.convertToBlob({
|
||||
type: "image/jpeg",
|
||||
quality
|
||||
});
|
||||
return new File([jpegBlob], `${baseName}.jpg`, {
|
||||
type: "image/jpeg"
|
||||
});
|
||||
}
|
||||
}
|
||||
throw new Error(getHeicUnsupportedMessage());
|
||||
throw new HeicUnsupportedError(getHeicUnsupportedMessage());
|
||||
}
|
||||
function applyRotation(source, rotation) {
|
||||
if (rotation === 0) {
|
||||
@@ -2836,13 +2861,17 @@ var wp;
|
||||
file,
|
||||
settings.imageQuality ?? DEFAULT_OUTPUT_QUALITY
|
||||
);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
const unsupported = error instanceof HeicUnsupportedError;
|
||||
dispatch.cancelItem(
|
||||
id,
|
||||
new UploadError({
|
||||
code: ErrorCode.HEIC_DECODE_ERROR,
|
||||
message: getHeicUnsupportedMessage(),
|
||||
file
|
||||
code: unsupported ? ErrorCode.HEIC_DECODE_ERROR : ErrorCode.IMAGE_TRANSCODING_ERROR,
|
||||
message: unsupported ? getHeicUnsupportedMessage() : (0, import_i18n7.__)(
|
||||
"This HEIC image could not be converted. Try converting it to JPEG before uploading."
|
||||
),
|
||||
file,
|
||||
cause: error instanceof Error ? error : void 0
|
||||
})
|
||||
);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user