Plugin Directory


Ignore:
Timestamp:
10/12/2025 06:39:44 PM (3 months ago)
Author:
bfintal
Message:

version 1.1.1

Location:
cimo-image-optimizer
Files:
4 edited
22 copied

Legend:

Unmodified
Added
Removed
  • cimo-image-optimizer/tags/1.1.1/build/admin/index.asset.php

    r3377045 r3377061  
    1 <?php return array('dependencies' => array(), 'version' => '13dc3f1388f240b87b32');
     1<?php return array('dependencies' => array(), 'version' => 'a88466c89bcf670568ac');
  • cimo-image-optimizer/tags/1.1.1/build/admin/index.js

    r3377045 r3377061  
    1 (()=>{"use strict";function e(e){"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",e):e())}const t=[{value:"webp",mimeType:"image/webp"},{value:"jpg",mimeType:"image/jpeg"},{value:"png",mimeType:"image/png"}],a={webp:{quality:.8,width:"auto",height:"auto"},jpg:{quality:.8,width:"auto",height:"auto"},png:{quality:.8,width:"auto",height:"auto"}};async function i(e,i){const n=null!==(i=i||{}).format?i.format:"webp";if(!e||"object"!=typeof e||"string"!=typeof e.name||"number"!=typeof e.size||"string"!=typeof e.type||"function"!=typeof e.slice)return{file:e,metadata:null};if(!e.type||!e.type.startsWith("image/"))return{file:e,metadata:null};const o=t.find(e=>e.value===n);if(o&&e.type===o.mimeType)return{file:e,metadata:null};const r=document.createElement("canvas");if(o&&!r.toDataURL(o.mimeType).startsWith(`data:${o.mimeType}`))return console.error("[Cimo] "+n+" is not supported by the browser, please use another modern browser"),{file:e,metadata:null};if("image/gif"===e.type){const t=await e.slice(0,51200).arrayBuffer(),a=new Uint8Array(t);let i=0;for(let t=0;t<a.length-2;t++)if(33===a[t]&&249===a[t+1]&&4===a[t+2]&&(i++,i>1))return{file:e,metadata:null}}const s={file:e};try{const r=performance.now(),c=await(async(e,i="webp",n={})=>{let o=(n=n||{}).quality?n.quality:.8,r=n.maxDimension?n.maxDimension:0;return"string"==typeof o&&(o=parseFloat(o)/100,o||(o=.8)),"string"==typeof r&&(r=parseFloat(r)),new Promise((n,s)=>{const c=new Image;let l=null;c.onload=async function(){const e=document.createElement("canvas"),m=a[i],{width:d,height:p}=function(e,t,a){const i=(a=a||{}).scale?a.scale:1,n=a.width?a.width:"auto",o=a.height?a.height:"auto",r=a.aspectRatio?a.aspectRatio:"auto",s=a.maxDimension?a.maxDimension:0;let c=e*i,l=t*i;if(s&&"number"==typeof s&&s>0){const e=Math.max(c,l);if(e>s){const t=s/e;c*=t,l*=t}}if("auto"!==n&&"number"==typeof n&&(c=n,"auto"===o&&(l=t/e*c)),"auto"!==o&&"number"==typeof o&&(l=o,"auto"===n&&(c=e/t*l)),"auto"!==r){if("custom"===r)return{width:c,height:l};const[e,t]=r.split(":").map(Number),a=e/t,i=c/l;if(Math.abs(i-a)>.01)if(i>a)c=l*a;else{const e=c;c=e,l=e/a}}return{width:Math.round(c),height:Math.round(l)}}(c.width,c.height,{...m,maxDimension:r});e.width=d,e.height=p;const u=e.getContext("2d"),f=c.width/c.height,g=d/p;let h=c.height,w=c.width,y=0,v=0;Math.abs(f-g)>.01&&(f>g?(w=c.height*g,y=(c.width-w)/2):(h=c.width/g,v=(c.height-h)/2)),u.drawImage(c,y,v,w,h,0,0,d,p);const b=t.find(e=>e.value===i),_="webp"===i||"jpg"===i?o:void 0;e.toBlob(function(t){URL.revokeObjectURL(l),l=null,u.clearRect(0,0,e.width,e.height),e.width=0,e.height=0,t?n(t):s(new Error("Failed to convert image"))},b.mimeType,_)},c.onerror=()=>{l&&(URL.revokeObjectURL(l),l=null),s(new Error("Failed to load image"))},l=URL.createObjectURL(e.file),c.src=l})})(s,n,{quality:i.quality,maxDimension:i.maxDimension}),l=performance.now(),m="jpeg"===n?"jpg":n,d=e.name.replace(/\.[^/.]+$/,"")+"."+m,p={filename:d,originalFormat:e.type,originalFilesize:e.size,convertedFormat:o.mimeType,convertedFilesize:c.size,conversionTime:l-r,compressionSavings:e.size>0?c.size/e.size:null};return{file:new(0,e.constructor)([c],d,{type:o.mimeType,lastModified:Date.now()}),metadata:p}}catch(e){throw new Error(`Failed to convert image: ${e.message}`)}}function n(e){return("string"!=typeof e?String(e):e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/`/g,"&#96;")}function o(e,t="editor-canvas"){const a=()=>{const a=document.querySelector(`iframe[name="${t}"]`);if(a&&a.contentDocument){const t=()=>{a.contentDocument.body?e(a.contentDocument):setTimeout(t,50)};"loading"===a.contentDocument.readyState?a.addEventListener("load",()=>{t()}):t()}};a();let i=0;const n=setInterval(()=>{i>=10?clearInterval(n):(i++,a())},1e3),o=new MutationObserver(e=>{e.forEach(e=>{e.addedNodes.forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&("IFRAME"===e.tagName&&e.name===t||e.querySelector&&e.querySelector(`iframe[name="${t}"]`))&&a()})})});return o.observe(document.body,{childList:!0,subtree:!0}),o}const r=e=>Array.isArray(e)&&0!==e.length?e.every(e=>c(e.filename))?Promise.resolve():(e.forEach(e=>{e.filename&&s(e.filename,e)}),new Promise((t,a)=>{fetch(`${window.cimoSettings?.restUrl||"/wp-json/cimo/v1/"}metadata`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","X-WP-Nonce":window.cimoSettings?.nonce||window.wpApiSettings?.nonce},body:JSON.stringify({metadata:e}),credentials:"same-origin"}).then(e=>e.ok?e.json():e.json().then(t=>{throw new Error(t.message||e.statusText)})).then(e=>{t(e)}).catch(t=>{console.error(`Failed to save metadata for filenames: [${e.map(e=>e.filename).join(", ")}]:`,t),a(new Error(`Failed to save metadata: ${t.message}`))})})):Promise.resolve(),s=(e,t)=>{window.cimoMetadataCache||(window.cimoMetadataCache={}),window.cimoMetadataCache[e.replaceAll(/\s+/g,"-")]={...t}},c=e=>window.cimoMetadataCache?.[e?.replaceAll(/\s+/g,"-")]||null;async function l(e){try{return await i(e,{format:"webp",quality:window.cimoSettings?.webpQuality||.8,maxDimension:window.cimoSettings?.maxImageDimension||0})}catch(t){return console.error(t),{file:e,metadata:null}}}const m=["image/jpg","image/jpeg","image/png","image/gif"];function d(e){if(!e)return;if(!e.body)return;e.body.__cimo_dropzone_listener_attached||(e.body.addEventListener("drop",async t=>{if(t.__cimo_converted)return;if(!Array.from(t.dataTransfer.files).some(e=>m.includes(e.type)))return;if(!(t.target.closest(".media-frame-uploader")||t.target.closest(".media-upload-form")||t.target.closest(".editor-post-featured-image")||t.target.closest(".editor-styles-wrapper")||t.target.closest(".uploader-window")))return;let a;for(t.preventDefault(),t.stopPropagation();a=document.querySelector('.uploader-window[style*="display: block"]');)a.style.display="none";const i=Array.from(t.dataTransfer.files);if(!i.length)return;const n=await Promise.all(i.map(l)),o=n.map(e=>e.file),s=n.map(e=>e.metadata),c=new DataTransfer;if(o.forEach(e=>{c.items.add(e)}),await r(s),t.target?.classList.contains("components-drop-zone")){const a=e!==document,i=new Event("drop",{bubbles:!a});Object.defineProperty(i,"dataTransfer",{value:c,writable:!1}),i.__cimo_converted=!0,t.target.dispatchEvent(i)}else{const a=document.querySelector('.media-modal input[type="file"]')||document.querySelector('.media-upload-form input[type="file"]')||document.querySelector('input[type="file"]');if(a){a.files=c.files;const t=e!==document,i=new Event("change",{bubbles:!t});i.__cimo_converted=!0,a.dispatchEvent(i)}else{const e=new Event("drop",{bubbles:!0});Object.defineProperty(e,"dataTransfer",{value:c,writable:!1}),e.__cimo_converted=!0,t.target.dispatchEvent(e)}}},!0),e.body.__cimo_dropzone_listener_attached=!0)}async function p(e){try{return await i(e,{format:"webp",quality:window.cimoSettings?.webpQuality||.8,maxDimension:window.cimoSettings?.maxImageDimension||0})}catch(t){return console.error(t),{file:e,metadata:null}}}e(()=>{d(document),o(e=>{d(e)})});const u=["image/jpg","image/jpeg","image/png","image/gif"];function f(e){if(!window.wp&&!e)return;if(!e.body)return;e.body.__cimo_selectfiles_listener_attached||(e.body.addEventListener("change",async e=>{if("file"!==e.target.type)return;if(e.__cimo_converted)return;if(!Array.from(e.target.files).some(e=>u.includes(e.type)))return;if(!(e.target.closest(".components-form-file-upload")||e.target.closest(".media-frame")||e.target.closest(".media-upload-form")||e.target.closest(".moxie-shim")))return;e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();const t=Array.from(e.target.files),a=await Promise.all(t.map(p)),i=a.map(e=>e.file),n=a.map(e=>e.metadata),o=new DataTransfer;i.forEach(e=>{o.items.add(e)}),await r(n),e.target.files=o.files;const s=new Event("change",{bubbles:!0});s.__cimo_converted=!0,e.target.dispatchEvent(s)},!0),e.body.__cimo_selectfiles_listener_attached=!0)}function g(e,t=2,a=!1){if(0===e)return"0 Bytes";const i=t<0?0:t,n=Math.abs(e),o=Math.floor(Math.log(n)/Math.log(1024));let r=e<0?"-":"";return a&&(r="-"===r?"":"-"),r+parseFloat((n/Math.pow(1024,o)).toFixed(i))+" "+["Bytes","KB","MB","GB"][o]}e(()=>{f(document),o(e=>{f(e)})}),e(()=>{"undefined"!=typeof wp&&wp.media&&wp.media.view&&wp.media.view.Attachment&&wp.media.view.Attachment.Details&&(wp.media.view.Attachment.Details=wp.media.view.Attachment.Details.extend({template:function(e){const t=wp.media.template("attachment-details")(e),a=document.createElement("div");a.innerHTML=t;let i=e.model.get("cimo")||null;i&&0!==Object.keys(i).length||(i=c(e.model.get("originalImageName")||e.model.get("filename")));const o=a.querySelector(".attachment-info");if(i&&o){const e=document.createElement("div");e.className="cimo-media-manager-metadata";let t='<div class="cimo-media-manager-metadata-title-container">\n\t\t\t\t<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 672 672" height="20" width="20"><path d="M132.5 132.5C182.4 82.5 253 56 336 56C419 56 489.6 82.5 539.5 132.5C589.4 182.5 616 253 616 336C616 419 589.5 489.6 539.5 539.5C489.5 589.4 419 616 336 616C253 616 182.4 589.5 132.5 539.5C82.6 489.5 56 419 56 336C56 253 82.5 182.4 132.5 132.5zM465.5 273.9C477.6 264.2 479.5 246.6 469.9 234.5C460.3 222.4 442.6 220.5 430.5 230.1C378 272.1 330.3 341.9 306.7 379.4C291.4 359.3 267.2 331.1 239.5 312.6C226.6 304 209.2 307.5 200.7 320.4C192.2 333.3 195.6 350.7 208.5 359.2C237.4 378.5 264.1 415.1 274.1 429.9C281.5 440.9 294 447.9 307.9 447.9C322.3 447.9 335.5 440.3 342.8 428C357.2 403.5 410 318.3 465.6 273.8z"/></svg>\n\t\t\t\t<h3 class="cimo-media-manager-metadata-title">Image Optimized by Cimo</h3>\n\t\t\t\t</div>\n\t\t\t\t<ul>';const a=i.compressionSavings?(100-100*i.compressionSavings).toFixed(2):null,r=g(i.originalFilesize-i.convertedFilesize,1,!0);t+=`<li class="cimo-compression-savings ${n(a>0?"cimo-optimization-savings-up":"cimo-optimization-savings-down")}">Saved ${n(a)}% <span class="cimo-compression-savings-bytes">(${n(r)})</span></li>`;const s=g(parseInt(i.originalFilesize)||0),c=g(parseInt(i.convertedFilesize)||0);t+=`<li class="cimo-filesize-original">Original: <span class="cimo-value">${n(s)}</span></li>`,t+=`<li class="cimo-filesize-optimized">Optimized: <span class="cimo-value">${n(c)}</span></li>`,t+=`<li class="cimo-converted">🏞️ Converted to <span class="cimo-value">${n(function(e){const t=e.split("/")[1];return"webp"===t?"WebP":t.charAt(0).toUpperCase()+t.slice(1)}(i.convertedFormat))}</span></li>`;let l="N/A";if(i.conversionTime){const e=parseFloat(i.conversionTime);l=e<1e3?`${e.toFixed(0)} ms`:e<6e4?`${(e/1e3).toFixed(1)} sec`:`${(e/6e4).toFixed(1)} min`}t+=`<li class="cimo-time">⚡️ Done in <span class="cimo-value">${n(l)}</span></li>`,e.innerHTML=t,o.appendChild(e)}return a.innerHTML}}))})})();
     1(()=>{"use strict";function e(e){"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",e):e())}const t=[{value:"webp",mimeType:"image/webp"},{value:"jpg",mimeType:"image/jpeg"},{value:"png",mimeType:"image/png"}],a={webp:{quality:.8,width:"auto",height:"auto"},jpg:{quality:.8,width:"auto",height:"auto"},png:{quality:.8,width:"auto",height:"auto"}};async function i(e,i){const n=null!==(i=i||{}).format?i.format:"webp";if(!e||"object"!=typeof e||"string"!=typeof e.name||"number"!=typeof e.size||"string"!=typeof e.type||"function"!=typeof e.slice)return{file:e,metadata:null};if(!e.type||!e.type.startsWith("image/"))return{file:e,metadata:null};const o=t.find(e=>e.value===n);if(o&&e.type===o.mimeType)return{file:e,metadata:null};const r=document.createElement("canvas");if(o&&!r.toDataURL(o.mimeType).startsWith(`data:${o.mimeType}`))return console.error("[Cimo] "+n+" is not supported by the browser, please use another modern browser"),{file:e,metadata:null};if("image/gif"===e.type){const t=await e.slice(0,51200).arrayBuffer(),a=new Uint8Array(t);let i=0;for(let t=0;t<a.length-2;t++)if(33===a[t]&&249===a[t+1]&&4===a[t+2]&&(i++,i>1))return{file:e,metadata:null}}const s={file:e};try{const r=performance.now(),c=await(async(e,i="webp",n={})=>{let o=(n=n||{}).quality?n.quality:.8,r=n.maxDimension?n.maxDimension:0;return"string"==typeof o&&(o=parseFloat(o)/100,o||(o=.8)),"string"==typeof r&&(r=parseFloat(r)),new Promise((n,s)=>{const c=new Image;let l=null;c.onload=async function(){const e=document.createElement("canvas"),m=a[i],{width:d,height:p}=function(e,t,a){const i=(a=a||{}).scale?a.scale:1,n=a.width?a.width:"auto",o=a.height?a.height:"auto",r=a.aspectRatio?a.aspectRatio:"auto",s=a.maxDimension?a.maxDimension:0;let c=e*i,l=t*i;if(s&&"number"==typeof s&&s>0){const e=Math.max(c,l);if(e>s){const t=s/e;c*=t,l*=t}}if("auto"!==n&&"number"==typeof n&&(c=n,"auto"===o&&(l=t/e*c)),"auto"!==o&&"number"==typeof o&&(l=o,"auto"===n&&(c=e/t*l)),"auto"!==r){if("custom"===r)return{width:c,height:l};const[e,t]=r.split(":").map(Number),a=e/t,i=c/l;if(Math.abs(i-a)>.01)if(i>a)c=l*a;else{const e=c;c=e,l=e/a}}return{width:Math.round(c),height:Math.round(l)}}(c.width,c.height,{...m,maxDimension:r});e.width=d,e.height=p;const u=e.getContext("2d"),f=c.width/c.height,g=d/p;let h=c.height,w=c.width,y=0,v=0;Math.abs(f-g)>.01&&(f>g?(w=c.height*g,y=(c.width-w)/2):(h=c.width/g,v=(c.height-h)/2)),u.drawImage(c,y,v,w,h,0,0,d,p);const b=t.find(e=>e.value===i),_="webp"===i||"jpg"===i?o:void 0;e.toBlob(function(t){URL.revokeObjectURL(l),l=null,u.clearRect(0,0,e.width,e.height),e.width=0,e.height=0,t?n(t):s(new Error("Failed to convert image"))},b.mimeType,_)},c.onerror=()=>{l&&(URL.revokeObjectURL(l),l=null),s(new Error("Failed to load image"))},l=URL.createObjectURL(e.file),c.src=l})})(s,n,{quality:i.quality,maxDimension:i.maxDimension}),l=performance.now(),m="jpeg"===n?"jpg":n,d=e.name.replace(/\.[^/.]+$/,"")+"."+m,p={filename:d,originalFormat:e.type,originalFilesize:e.size,convertedFormat:o.mimeType,convertedFilesize:c.size,conversionTime:l-r,compressionSavings:e.size>0?c.size/e.size:null};return{file:new(0,e.constructor)([c],d,{type:o.mimeType,lastModified:Date.now()}),metadata:p}}catch(e){throw new Error(`Failed to convert image: ${e.message}`)}}function n(e){return("string"!=typeof e?String(e):e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/`/g,"&#96;")}function o(e,t="editor-canvas"){const a=()=>{const a=document.querySelector(`iframe[name="${t}"]`);if(a&&a.contentDocument){const t=()=>{a.contentDocument.body?e(a.contentDocument):setTimeout(t,50)};"loading"===a.contentDocument.readyState?a.addEventListener("load",()=>{t()}):t()}};a();let i=0;const n=setInterval(()=>{i>=10?clearInterval(n):(i++,a())},1e3),o=new MutationObserver(e=>{e.forEach(e=>{e.addedNodes.forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&("IFRAME"===e.tagName&&e.name===t||e.querySelector&&e.querySelector(`iframe[name="${t}"]`))&&a()})})});return o.observe(document.body,{childList:!0,subtree:!0}),o}const r=e=>Array.isArray(e)&&0!==e.length?e.every(e=>c(e.filename))?Promise.resolve():(e.forEach(e=>{e.filename&&s(e.filename,e)}),new Promise((t,a)=>{fetch(`${window.cimoSettings?.restUrl||"/wp-json/cimo/v1/"}metadata`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","X-WP-Nonce":window.cimoSettings?.nonce||window.wpApiSettings?.nonce},body:JSON.stringify({metadata:e}),credentials:"same-origin"}).then(e=>e.ok?e.json():e.json().then(t=>{throw new Error(t.message||e.statusText)})).then(e=>{t(e)}).catch(t=>{console.error(`Failed to save metadata for filenames: [${e.map(e=>e.filename).join(", ")}]:`,t),a(new Error(`Failed to save metadata: ${t.message}`))})})):Promise.resolve(),s=(e,t)=>{window.cimoMetadataCache||(window.cimoMetadataCache={}),window.cimoMetadataCache[e.replaceAll(/\s+/g,"-")]={...t}},c=e=>window.cimoMetadataCache?.[e?.replaceAll(/\s+/g,"-")]||null;async function l(e){try{return await i(e,{format:"webp",quality:window.cimoSettings?.webpQuality||.8,maxDimension:window.cimoSettings?.maxImageDimension||0})}catch(t){return console.error(t),{file:e,metadata:null}}}const m=["image/jpg","image/jpeg","image/png","image/gif"];function d(e){if(!e)return;if(!e.body)return;e.body.__cimo_dropzone_listener_attached||(e.body.addEventListener("drop",async t=>{if(t.__cimo_converted)return;if(!Array.from(t.dataTransfer.files).some(e=>m.includes(e.type)))return;if(!(t.target.closest(".media-frame-uploader")||t.target.closest(".media-upload-form")||t.target.closest(".editor-post-featured-image")||t.target.closest(".editor-styles-wrapper")||t.target.closest(".uploader-window")))return;let a;for(;a=document.querySelector('.uploader-window[style*="display: block"]');)a.style.display="none";const i=Array.from(t.dataTransfer.files);if(!i.length)return;const n=await Promise.all(i.map(l));if(n.some(e=>null===e.metadata))return;t.preventDefault(),t.stopPropagation();const o=n.map(e=>e.file),s=n.map(e=>e.metadata),c=new DataTransfer;if(o.forEach(e=>{c.items.add(e)}),await r(s),t.target?.classList.contains("components-drop-zone")){const a=e!==document,i=new Event("drop",{bubbles:!a});Object.defineProperty(i,"dataTransfer",{value:c,writable:!1}),i.__cimo_converted=!0,t.target.dispatchEvent(i)}else{const a=document.querySelector('.media-modal input[type="file"]')||document.querySelector('.media-upload-form input[type="file"]')||document.querySelector('input[type="file"]');if(a){a.files=c.files;const t=e!==document,i=new Event("change",{bubbles:!t});i.__cimo_converted=!0,a.dispatchEvent(i)}else{const e=new Event("drop",{bubbles:!0});Object.defineProperty(e,"dataTransfer",{value:c,writable:!1}),e.__cimo_converted=!0,t.target.dispatchEvent(e)}}},!0),e.body.__cimo_dropzone_listener_attached=!0)}async function p(e){try{return await i(e,{format:"webp",quality:window.cimoSettings?.webpQuality||.8,maxDimension:window.cimoSettings?.maxImageDimension||0})}catch(t){return console.error(t),{file:e,metadata:null}}}e(()=>{d(document),o(e=>{d(e)})});const u=["image/jpg","image/jpeg","image/png","image/gif"];function f(e){if(!window.wp&&!e)return;if(!e.body)return;e.body.__cimo_selectfiles_listener_attached||(e.body.addEventListener("change",async e=>{if("file"!==e.target.type)return;if(e.__cimo_converted)return;if(!Array.from(e.target.files).some(e=>u.includes(e.type)))return;if(!(e.target.closest(".components-form-file-upload")||e.target.closest(".media-frame")||e.target.closest(".media-upload-form")||e.target.closest(".moxie-shim")))return;const t=Array.from(e.target.files),a=await Promise.all(t.map(p));if(a.some(e=>null===e.metadata))return;e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();const i=a.map(e=>e.file),n=a.map(e=>e.metadata),o=new DataTransfer;i.forEach(e=>{o.items.add(e)}),await r(n),e.target.files=o.files;const s=new Event("change",{bubbles:!0});s.__cimo_converted=!0,e.target.dispatchEvent(s)},!0),e.body.__cimo_selectfiles_listener_attached=!0)}function g(e,t=2,a=!1){if(0===e)return"0 Bytes";const i=t<0?0:t,n=Math.abs(e),o=Math.floor(Math.log(n)/Math.log(1024));let r=e<0?"-":"";return a&&(r="-"===r?"":"-"),r+parseFloat((n/Math.pow(1024,o)).toFixed(i))+" "+["Bytes","KB","MB","GB"][o]}e(()=>{f(document),o(e=>{f(e)})}),e(()=>{"undefined"!=typeof wp&&wp.media&&wp.media.view&&wp.media.view.Attachment&&wp.media.view.Attachment.Details&&(wp.media.view.Attachment.Details=wp.media.view.Attachment.Details.extend({template:function(e){const t=wp.media.template("attachment-details")(e),a=document.createElement("div");a.innerHTML=t;let i=e.model.get("cimo")||null;i&&0!==Object.keys(i).length||(i=c(e.model.get("originalImageName")||e.model.get("filename")));const o=a.querySelector(".attachment-info");if(i&&o){const e=document.createElement("div");e.className="cimo-media-manager-metadata";let t='<div class="cimo-media-manager-metadata-title-container">\n\t\t\t\t<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 672 672" height="20" width="20"><path d="M132.5 132.5C182.4 82.5 253 56 336 56C419 56 489.6 82.5 539.5 132.5C589.4 182.5 616 253 616 336C616 419 589.5 489.6 539.5 539.5C489.5 589.4 419 616 336 616C253 616 182.4 589.5 132.5 539.5C82.6 489.5 56 419 56 336C56 253 82.5 182.4 132.5 132.5zM465.5 273.9C477.6 264.2 479.5 246.6 469.9 234.5C460.3 222.4 442.6 220.5 430.5 230.1C378 272.1 330.3 341.9 306.7 379.4C291.4 359.3 267.2 331.1 239.5 312.6C226.6 304 209.2 307.5 200.7 320.4C192.2 333.3 195.6 350.7 208.5 359.2C237.4 378.5 264.1 415.1 274.1 429.9C281.5 440.9 294 447.9 307.9 447.9C322.3 447.9 335.5 440.3 342.8 428C357.2 403.5 410 318.3 465.6 273.8z"/></svg>\n\t\t\t\t<h3 class="cimo-media-manager-metadata-title">Image Optimized by Cimo</h3>\n\t\t\t\t</div>\n\t\t\t\t<ul>';const a=i.compressionSavings?(100-100*i.compressionSavings).toFixed(2):null,r=g(i.originalFilesize-i.convertedFilesize,1,!0);t+=`<li class="cimo-compression-savings ${n(a>0?"cimo-optimization-savings-up":"cimo-optimization-savings-down")}">Saved ${n(a)}% <span class="cimo-compression-savings-bytes">(${n(r)})</span></li>`;const s=g(parseInt(i.originalFilesize)||0),c=g(parseInt(i.convertedFilesize)||0);t+=`<li class="cimo-filesize-original">Original: <span class="cimo-value">${n(s)}</span></li>`,t+=`<li class="cimo-filesize-optimized">Optimized: <span class="cimo-value">${n(c)}</span></li>`,t+=`<li class="cimo-converted">🏞️ Converted to <span class="cimo-value">${n(function(e){const t=e.split("/")[1];return"webp"===t?"WebP":t.charAt(0).toUpperCase()+t.slice(1)}(i.convertedFormat))}</span></li>`;let l="N/A";if(i.conversionTime){const e=parseFloat(i.conversionTime);l=e<1e3?`${e.toFixed(0)} ms`:e<6e4?`${(e/1e3).toFixed(1)} sec`:`${(e/6e4).toFixed(1)} min`}t+=`<li class="cimo-time">⚡️ Done in <span class="cimo-value">${n(l)}</span></li>`,e.innerHTML=t,o.appendChild(e)}return a.innerHTML}}))})})();
  • cimo-image-optimizer/tags/1.1.1/cimo.php

    r3377045 r3377061  
    88 * License: GPLv2 or later
    99 * Text Domain: cimo-image-optimizer
    10  * Version: 1.1.0
     10 * Version: 1.1.1
    1111 *
    1212 * @fs_premium_only /freemius.php, /freemius/
  • cimo-image-optimizer/tags/1.1.1/readme.txt

    r3377045 r3377061  
    55Tested up to: 6.8.3
    66Requires PHP: 8.0
    7 Stable tag: 1.1.0
     7Stable tag: 1.1.1
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    189189== Changelog ==
    190190
     191= 1.1.1 =
     192
     193* Fixed: When uploading images using Safari, images will just upload as they normally would.
     194
    191195= 1.1.0 =
    192196
  • cimo-image-optimizer/trunk/build/admin/index.asset.php

    r3377045 r3377061  
    1 <?php return array('dependencies' => array(), 'version' => '13dc3f1388f240b87b32');
     1<?php return array('dependencies' => array(), 'version' => 'a88466c89bcf670568ac');
  • cimo-image-optimizer/trunk/build/admin/index.js

    r3377045 r3377061  
    1 (()=>{"use strict";function e(e){"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",e):e())}const t=[{value:"webp",mimeType:"image/webp"},{value:"jpg",mimeType:"image/jpeg"},{value:"png",mimeType:"image/png"}],a={webp:{quality:.8,width:"auto",height:"auto"},jpg:{quality:.8,width:"auto",height:"auto"},png:{quality:.8,width:"auto",height:"auto"}};async function i(e,i){const n=null!==(i=i||{}).format?i.format:"webp";if(!e||"object"!=typeof e||"string"!=typeof e.name||"number"!=typeof e.size||"string"!=typeof e.type||"function"!=typeof e.slice)return{file:e,metadata:null};if(!e.type||!e.type.startsWith("image/"))return{file:e,metadata:null};const o=t.find(e=>e.value===n);if(o&&e.type===o.mimeType)return{file:e,metadata:null};const r=document.createElement("canvas");if(o&&!r.toDataURL(o.mimeType).startsWith(`data:${o.mimeType}`))return console.error("[Cimo] "+n+" is not supported by the browser, please use another modern browser"),{file:e,metadata:null};if("image/gif"===e.type){const t=await e.slice(0,51200).arrayBuffer(),a=new Uint8Array(t);let i=0;for(let t=0;t<a.length-2;t++)if(33===a[t]&&249===a[t+1]&&4===a[t+2]&&(i++,i>1))return{file:e,metadata:null}}const s={file:e};try{const r=performance.now(),c=await(async(e,i="webp",n={})=>{let o=(n=n||{}).quality?n.quality:.8,r=n.maxDimension?n.maxDimension:0;return"string"==typeof o&&(o=parseFloat(o)/100,o||(o=.8)),"string"==typeof r&&(r=parseFloat(r)),new Promise((n,s)=>{const c=new Image;let l=null;c.onload=async function(){const e=document.createElement("canvas"),m=a[i],{width:d,height:p}=function(e,t,a){const i=(a=a||{}).scale?a.scale:1,n=a.width?a.width:"auto",o=a.height?a.height:"auto",r=a.aspectRatio?a.aspectRatio:"auto",s=a.maxDimension?a.maxDimension:0;let c=e*i,l=t*i;if(s&&"number"==typeof s&&s>0){const e=Math.max(c,l);if(e>s){const t=s/e;c*=t,l*=t}}if("auto"!==n&&"number"==typeof n&&(c=n,"auto"===o&&(l=t/e*c)),"auto"!==o&&"number"==typeof o&&(l=o,"auto"===n&&(c=e/t*l)),"auto"!==r){if("custom"===r)return{width:c,height:l};const[e,t]=r.split(":").map(Number),a=e/t,i=c/l;if(Math.abs(i-a)>.01)if(i>a)c=l*a;else{const e=c;c=e,l=e/a}}return{width:Math.round(c),height:Math.round(l)}}(c.width,c.height,{...m,maxDimension:r});e.width=d,e.height=p;const u=e.getContext("2d"),f=c.width/c.height,g=d/p;let h=c.height,w=c.width,y=0,v=0;Math.abs(f-g)>.01&&(f>g?(w=c.height*g,y=(c.width-w)/2):(h=c.width/g,v=(c.height-h)/2)),u.drawImage(c,y,v,w,h,0,0,d,p);const b=t.find(e=>e.value===i),_="webp"===i||"jpg"===i?o:void 0;e.toBlob(function(t){URL.revokeObjectURL(l),l=null,u.clearRect(0,0,e.width,e.height),e.width=0,e.height=0,t?n(t):s(new Error("Failed to convert image"))},b.mimeType,_)},c.onerror=()=>{l&&(URL.revokeObjectURL(l),l=null),s(new Error("Failed to load image"))},l=URL.createObjectURL(e.file),c.src=l})})(s,n,{quality:i.quality,maxDimension:i.maxDimension}),l=performance.now(),m="jpeg"===n?"jpg":n,d=e.name.replace(/\.[^/.]+$/,"")+"."+m,p={filename:d,originalFormat:e.type,originalFilesize:e.size,convertedFormat:o.mimeType,convertedFilesize:c.size,conversionTime:l-r,compressionSavings:e.size>0?c.size/e.size:null};return{file:new(0,e.constructor)([c],d,{type:o.mimeType,lastModified:Date.now()}),metadata:p}}catch(e){throw new Error(`Failed to convert image: ${e.message}`)}}function n(e){return("string"!=typeof e?String(e):e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/`/g,"&#96;")}function o(e,t="editor-canvas"){const a=()=>{const a=document.querySelector(`iframe[name="${t}"]`);if(a&&a.contentDocument){const t=()=>{a.contentDocument.body?e(a.contentDocument):setTimeout(t,50)};"loading"===a.contentDocument.readyState?a.addEventListener("load",()=>{t()}):t()}};a();let i=0;const n=setInterval(()=>{i>=10?clearInterval(n):(i++,a())},1e3),o=new MutationObserver(e=>{e.forEach(e=>{e.addedNodes.forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&("IFRAME"===e.tagName&&e.name===t||e.querySelector&&e.querySelector(`iframe[name="${t}"]`))&&a()})})});return o.observe(document.body,{childList:!0,subtree:!0}),o}const r=e=>Array.isArray(e)&&0!==e.length?e.every(e=>c(e.filename))?Promise.resolve():(e.forEach(e=>{e.filename&&s(e.filename,e)}),new Promise((t,a)=>{fetch(`${window.cimoSettings?.restUrl||"/wp-json/cimo/v1/"}metadata`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","X-WP-Nonce":window.cimoSettings?.nonce||window.wpApiSettings?.nonce},body:JSON.stringify({metadata:e}),credentials:"same-origin"}).then(e=>e.ok?e.json():e.json().then(t=>{throw new Error(t.message||e.statusText)})).then(e=>{t(e)}).catch(t=>{console.error(`Failed to save metadata for filenames: [${e.map(e=>e.filename).join(", ")}]:`,t),a(new Error(`Failed to save metadata: ${t.message}`))})})):Promise.resolve(),s=(e,t)=>{window.cimoMetadataCache||(window.cimoMetadataCache={}),window.cimoMetadataCache[e.replaceAll(/\s+/g,"-")]={...t}},c=e=>window.cimoMetadataCache?.[e?.replaceAll(/\s+/g,"-")]||null;async function l(e){try{return await i(e,{format:"webp",quality:window.cimoSettings?.webpQuality||.8,maxDimension:window.cimoSettings?.maxImageDimension||0})}catch(t){return console.error(t),{file:e,metadata:null}}}const m=["image/jpg","image/jpeg","image/png","image/gif"];function d(e){if(!e)return;if(!e.body)return;e.body.__cimo_dropzone_listener_attached||(e.body.addEventListener("drop",async t=>{if(t.__cimo_converted)return;if(!Array.from(t.dataTransfer.files).some(e=>m.includes(e.type)))return;if(!(t.target.closest(".media-frame-uploader")||t.target.closest(".media-upload-form")||t.target.closest(".editor-post-featured-image")||t.target.closest(".editor-styles-wrapper")||t.target.closest(".uploader-window")))return;let a;for(t.preventDefault(),t.stopPropagation();a=document.querySelector('.uploader-window[style*="display: block"]');)a.style.display="none";const i=Array.from(t.dataTransfer.files);if(!i.length)return;const n=await Promise.all(i.map(l)),o=n.map(e=>e.file),s=n.map(e=>e.metadata),c=new DataTransfer;if(o.forEach(e=>{c.items.add(e)}),await r(s),t.target?.classList.contains("components-drop-zone")){const a=e!==document,i=new Event("drop",{bubbles:!a});Object.defineProperty(i,"dataTransfer",{value:c,writable:!1}),i.__cimo_converted=!0,t.target.dispatchEvent(i)}else{const a=document.querySelector('.media-modal input[type="file"]')||document.querySelector('.media-upload-form input[type="file"]')||document.querySelector('input[type="file"]');if(a){a.files=c.files;const t=e!==document,i=new Event("change",{bubbles:!t});i.__cimo_converted=!0,a.dispatchEvent(i)}else{const e=new Event("drop",{bubbles:!0});Object.defineProperty(e,"dataTransfer",{value:c,writable:!1}),e.__cimo_converted=!0,t.target.dispatchEvent(e)}}},!0),e.body.__cimo_dropzone_listener_attached=!0)}async function p(e){try{return await i(e,{format:"webp",quality:window.cimoSettings?.webpQuality||.8,maxDimension:window.cimoSettings?.maxImageDimension||0})}catch(t){return console.error(t),{file:e,metadata:null}}}e(()=>{d(document),o(e=>{d(e)})});const u=["image/jpg","image/jpeg","image/png","image/gif"];function f(e){if(!window.wp&&!e)return;if(!e.body)return;e.body.__cimo_selectfiles_listener_attached||(e.body.addEventListener("change",async e=>{if("file"!==e.target.type)return;if(e.__cimo_converted)return;if(!Array.from(e.target.files).some(e=>u.includes(e.type)))return;if(!(e.target.closest(".components-form-file-upload")||e.target.closest(".media-frame")||e.target.closest(".media-upload-form")||e.target.closest(".moxie-shim")))return;e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();const t=Array.from(e.target.files),a=await Promise.all(t.map(p)),i=a.map(e=>e.file),n=a.map(e=>e.metadata),o=new DataTransfer;i.forEach(e=>{o.items.add(e)}),await r(n),e.target.files=o.files;const s=new Event("change",{bubbles:!0});s.__cimo_converted=!0,e.target.dispatchEvent(s)},!0),e.body.__cimo_selectfiles_listener_attached=!0)}function g(e,t=2,a=!1){if(0===e)return"0 Bytes";const i=t<0?0:t,n=Math.abs(e),o=Math.floor(Math.log(n)/Math.log(1024));let r=e<0?"-":"";return a&&(r="-"===r?"":"-"),r+parseFloat((n/Math.pow(1024,o)).toFixed(i))+" "+["Bytes","KB","MB","GB"][o]}e(()=>{f(document),o(e=>{f(e)})}),e(()=>{"undefined"!=typeof wp&&wp.media&&wp.media.view&&wp.media.view.Attachment&&wp.media.view.Attachment.Details&&(wp.media.view.Attachment.Details=wp.media.view.Attachment.Details.extend({template:function(e){const t=wp.media.template("attachment-details")(e),a=document.createElement("div");a.innerHTML=t;let i=e.model.get("cimo")||null;i&&0!==Object.keys(i).length||(i=c(e.model.get("originalImageName")||e.model.get("filename")));const o=a.querySelector(".attachment-info");if(i&&o){const e=document.createElement("div");e.className="cimo-media-manager-metadata";let t='<div class="cimo-media-manager-metadata-title-container">\n\t\t\t\t<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 672 672" height="20" width="20"><path d="M132.5 132.5C182.4 82.5 253 56 336 56C419 56 489.6 82.5 539.5 132.5C589.4 182.5 616 253 616 336C616 419 589.5 489.6 539.5 539.5C489.5 589.4 419 616 336 616C253 616 182.4 589.5 132.5 539.5C82.6 489.5 56 419 56 336C56 253 82.5 182.4 132.5 132.5zM465.5 273.9C477.6 264.2 479.5 246.6 469.9 234.5C460.3 222.4 442.6 220.5 430.5 230.1C378 272.1 330.3 341.9 306.7 379.4C291.4 359.3 267.2 331.1 239.5 312.6C226.6 304 209.2 307.5 200.7 320.4C192.2 333.3 195.6 350.7 208.5 359.2C237.4 378.5 264.1 415.1 274.1 429.9C281.5 440.9 294 447.9 307.9 447.9C322.3 447.9 335.5 440.3 342.8 428C357.2 403.5 410 318.3 465.6 273.8z"/></svg>\n\t\t\t\t<h3 class="cimo-media-manager-metadata-title">Image Optimized by Cimo</h3>\n\t\t\t\t</div>\n\t\t\t\t<ul>';const a=i.compressionSavings?(100-100*i.compressionSavings).toFixed(2):null,r=g(i.originalFilesize-i.convertedFilesize,1,!0);t+=`<li class="cimo-compression-savings ${n(a>0?"cimo-optimization-savings-up":"cimo-optimization-savings-down")}">Saved ${n(a)}% <span class="cimo-compression-savings-bytes">(${n(r)})</span></li>`;const s=g(parseInt(i.originalFilesize)||0),c=g(parseInt(i.convertedFilesize)||0);t+=`<li class="cimo-filesize-original">Original: <span class="cimo-value">${n(s)}</span></li>`,t+=`<li class="cimo-filesize-optimized">Optimized: <span class="cimo-value">${n(c)}</span></li>`,t+=`<li class="cimo-converted">🏞️ Converted to <span class="cimo-value">${n(function(e){const t=e.split("/")[1];return"webp"===t?"WebP":t.charAt(0).toUpperCase()+t.slice(1)}(i.convertedFormat))}</span></li>`;let l="N/A";if(i.conversionTime){const e=parseFloat(i.conversionTime);l=e<1e3?`${e.toFixed(0)} ms`:e<6e4?`${(e/1e3).toFixed(1)} sec`:`${(e/6e4).toFixed(1)} min`}t+=`<li class="cimo-time">⚡️ Done in <span class="cimo-value">${n(l)}</span></li>`,e.innerHTML=t,o.appendChild(e)}return a.innerHTML}}))})})();
     1(()=>{"use strict";function e(e){"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",e):e())}const t=[{value:"webp",mimeType:"image/webp"},{value:"jpg",mimeType:"image/jpeg"},{value:"png",mimeType:"image/png"}],a={webp:{quality:.8,width:"auto",height:"auto"},jpg:{quality:.8,width:"auto",height:"auto"},png:{quality:.8,width:"auto",height:"auto"}};async function i(e,i){const n=null!==(i=i||{}).format?i.format:"webp";if(!e||"object"!=typeof e||"string"!=typeof e.name||"number"!=typeof e.size||"string"!=typeof e.type||"function"!=typeof e.slice)return{file:e,metadata:null};if(!e.type||!e.type.startsWith("image/"))return{file:e,metadata:null};const o=t.find(e=>e.value===n);if(o&&e.type===o.mimeType)return{file:e,metadata:null};const r=document.createElement("canvas");if(o&&!r.toDataURL(o.mimeType).startsWith(`data:${o.mimeType}`))return console.error("[Cimo] "+n+" is not supported by the browser, please use another modern browser"),{file:e,metadata:null};if("image/gif"===e.type){const t=await e.slice(0,51200).arrayBuffer(),a=new Uint8Array(t);let i=0;for(let t=0;t<a.length-2;t++)if(33===a[t]&&249===a[t+1]&&4===a[t+2]&&(i++,i>1))return{file:e,metadata:null}}const s={file:e};try{const r=performance.now(),c=await(async(e,i="webp",n={})=>{let o=(n=n||{}).quality?n.quality:.8,r=n.maxDimension?n.maxDimension:0;return"string"==typeof o&&(o=parseFloat(o)/100,o||(o=.8)),"string"==typeof r&&(r=parseFloat(r)),new Promise((n,s)=>{const c=new Image;let l=null;c.onload=async function(){const e=document.createElement("canvas"),m=a[i],{width:d,height:p}=function(e,t,a){const i=(a=a||{}).scale?a.scale:1,n=a.width?a.width:"auto",o=a.height?a.height:"auto",r=a.aspectRatio?a.aspectRatio:"auto",s=a.maxDimension?a.maxDimension:0;let c=e*i,l=t*i;if(s&&"number"==typeof s&&s>0){const e=Math.max(c,l);if(e>s){const t=s/e;c*=t,l*=t}}if("auto"!==n&&"number"==typeof n&&(c=n,"auto"===o&&(l=t/e*c)),"auto"!==o&&"number"==typeof o&&(l=o,"auto"===n&&(c=e/t*l)),"auto"!==r){if("custom"===r)return{width:c,height:l};const[e,t]=r.split(":").map(Number),a=e/t,i=c/l;if(Math.abs(i-a)>.01)if(i>a)c=l*a;else{const e=c;c=e,l=e/a}}return{width:Math.round(c),height:Math.round(l)}}(c.width,c.height,{...m,maxDimension:r});e.width=d,e.height=p;const u=e.getContext("2d"),f=c.width/c.height,g=d/p;let h=c.height,w=c.width,y=0,v=0;Math.abs(f-g)>.01&&(f>g?(w=c.height*g,y=(c.width-w)/2):(h=c.width/g,v=(c.height-h)/2)),u.drawImage(c,y,v,w,h,0,0,d,p);const b=t.find(e=>e.value===i),_="webp"===i||"jpg"===i?o:void 0;e.toBlob(function(t){URL.revokeObjectURL(l),l=null,u.clearRect(0,0,e.width,e.height),e.width=0,e.height=0,t?n(t):s(new Error("Failed to convert image"))},b.mimeType,_)},c.onerror=()=>{l&&(URL.revokeObjectURL(l),l=null),s(new Error("Failed to load image"))},l=URL.createObjectURL(e.file),c.src=l})})(s,n,{quality:i.quality,maxDimension:i.maxDimension}),l=performance.now(),m="jpeg"===n?"jpg":n,d=e.name.replace(/\.[^/.]+$/,"")+"."+m,p={filename:d,originalFormat:e.type,originalFilesize:e.size,convertedFormat:o.mimeType,convertedFilesize:c.size,conversionTime:l-r,compressionSavings:e.size>0?c.size/e.size:null};return{file:new(0,e.constructor)([c],d,{type:o.mimeType,lastModified:Date.now()}),metadata:p}}catch(e){throw new Error(`Failed to convert image: ${e.message}`)}}function n(e){return("string"!=typeof e?String(e):e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/`/g,"&#96;")}function o(e,t="editor-canvas"){const a=()=>{const a=document.querySelector(`iframe[name="${t}"]`);if(a&&a.contentDocument){const t=()=>{a.contentDocument.body?e(a.contentDocument):setTimeout(t,50)};"loading"===a.contentDocument.readyState?a.addEventListener("load",()=>{t()}):t()}};a();let i=0;const n=setInterval(()=>{i>=10?clearInterval(n):(i++,a())},1e3),o=new MutationObserver(e=>{e.forEach(e=>{e.addedNodes.forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&("IFRAME"===e.tagName&&e.name===t||e.querySelector&&e.querySelector(`iframe[name="${t}"]`))&&a()})})});return o.observe(document.body,{childList:!0,subtree:!0}),o}const r=e=>Array.isArray(e)&&0!==e.length?e.every(e=>c(e.filename))?Promise.resolve():(e.forEach(e=>{e.filename&&s(e.filename,e)}),new Promise((t,a)=>{fetch(`${window.cimoSettings?.restUrl||"/wp-json/cimo/v1/"}metadata`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","X-WP-Nonce":window.cimoSettings?.nonce||window.wpApiSettings?.nonce},body:JSON.stringify({metadata:e}),credentials:"same-origin"}).then(e=>e.ok?e.json():e.json().then(t=>{throw new Error(t.message||e.statusText)})).then(e=>{t(e)}).catch(t=>{console.error(`Failed to save metadata for filenames: [${e.map(e=>e.filename).join(", ")}]:`,t),a(new Error(`Failed to save metadata: ${t.message}`))})})):Promise.resolve(),s=(e,t)=>{window.cimoMetadataCache||(window.cimoMetadataCache={}),window.cimoMetadataCache[e.replaceAll(/\s+/g,"-")]={...t}},c=e=>window.cimoMetadataCache?.[e?.replaceAll(/\s+/g,"-")]||null;async function l(e){try{return await i(e,{format:"webp",quality:window.cimoSettings?.webpQuality||.8,maxDimension:window.cimoSettings?.maxImageDimension||0})}catch(t){return console.error(t),{file:e,metadata:null}}}const m=["image/jpg","image/jpeg","image/png","image/gif"];function d(e){if(!e)return;if(!e.body)return;e.body.__cimo_dropzone_listener_attached||(e.body.addEventListener("drop",async t=>{if(t.__cimo_converted)return;if(!Array.from(t.dataTransfer.files).some(e=>m.includes(e.type)))return;if(!(t.target.closest(".media-frame-uploader")||t.target.closest(".media-upload-form")||t.target.closest(".editor-post-featured-image")||t.target.closest(".editor-styles-wrapper")||t.target.closest(".uploader-window")))return;let a;for(;a=document.querySelector('.uploader-window[style*="display: block"]');)a.style.display="none";const i=Array.from(t.dataTransfer.files);if(!i.length)return;const n=await Promise.all(i.map(l));if(n.some(e=>null===e.metadata))return;t.preventDefault(),t.stopPropagation();const o=n.map(e=>e.file),s=n.map(e=>e.metadata),c=new DataTransfer;if(o.forEach(e=>{c.items.add(e)}),await r(s),t.target?.classList.contains("components-drop-zone")){const a=e!==document,i=new Event("drop",{bubbles:!a});Object.defineProperty(i,"dataTransfer",{value:c,writable:!1}),i.__cimo_converted=!0,t.target.dispatchEvent(i)}else{const a=document.querySelector('.media-modal input[type="file"]')||document.querySelector('.media-upload-form input[type="file"]')||document.querySelector('input[type="file"]');if(a){a.files=c.files;const t=e!==document,i=new Event("change",{bubbles:!t});i.__cimo_converted=!0,a.dispatchEvent(i)}else{const e=new Event("drop",{bubbles:!0});Object.defineProperty(e,"dataTransfer",{value:c,writable:!1}),e.__cimo_converted=!0,t.target.dispatchEvent(e)}}},!0),e.body.__cimo_dropzone_listener_attached=!0)}async function p(e){try{return await i(e,{format:"webp",quality:window.cimoSettings?.webpQuality||.8,maxDimension:window.cimoSettings?.maxImageDimension||0})}catch(t){return console.error(t),{file:e,metadata:null}}}e(()=>{d(document),o(e=>{d(e)})});const u=["image/jpg","image/jpeg","image/png","image/gif"];function f(e){if(!window.wp&&!e)return;if(!e.body)return;e.body.__cimo_selectfiles_listener_attached||(e.body.addEventListener("change",async e=>{if("file"!==e.target.type)return;if(e.__cimo_converted)return;if(!Array.from(e.target.files).some(e=>u.includes(e.type)))return;if(!(e.target.closest(".components-form-file-upload")||e.target.closest(".media-frame")||e.target.closest(".media-upload-form")||e.target.closest(".moxie-shim")))return;const t=Array.from(e.target.files),a=await Promise.all(t.map(p));if(a.some(e=>null===e.metadata))return;e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();const i=a.map(e=>e.file),n=a.map(e=>e.metadata),o=new DataTransfer;i.forEach(e=>{o.items.add(e)}),await r(n),e.target.files=o.files;const s=new Event("change",{bubbles:!0});s.__cimo_converted=!0,e.target.dispatchEvent(s)},!0),e.body.__cimo_selectfiles_listener_attached=!0)}function g(e,t=2,a=!1){if(0===e)return"0 Bytes";const i=t<0?0:t,n=Math.abs(e),o=Math.floor(Math.log(n)/Math.log(1024));let r=e<0?"-":"";return a&&(r="-"===r?"":"-"),r+parseFloat((n/Math.pow(1024,o)).toFixed(i))+" "+["Bytes","KB","MB","GB"][o]}e(()=>{f(document),o(e=>{f(e)})}),e(()=>{"undefined"!=typeof wp&&wp.media&&wp.media.view&&wp.media.view.Attachment&&wp.media.view.Attachment.Details&&(wp.media.view.Attachment.Details=wp.media.view.Attachment.Details.extend({template:function(e){const t=wp.media.template("attachment-details")(e),a=document.createElement("div");a.innerHTML=t;let i=e.model.get("cimo")||null;i&&0!==Object.keys(i).length||(i=c(e.model.get("originalImageName")||e.model.get("filename")));const o=a.querySelector(".attachment-info");if(i&&o){const e=document.createElement("div");e.className="cimo-media-manager-metadata";let t='<div class="cimo-media-manager-metadata-title-container">\n\t\t\t\t<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 672 672" height="20" width="20"><path d="M132.5 132.5C182.4 82.5 253 56 336 56C419 56 489.6 82.5 539.5 132.5C589.4 182.5 616 253 616 336C616 419 589.5 489.6 539.5 539.5C489.5 589.4 419 616 336 616C253 616 182.4 589.5 132.5 539.5C82.6 489.5 56 419 56 336C56 253 82.5 182.4 132.5 132.5zM465.5 273.9C477.6 264.2 479.5 246.6 469.9 234.5C460.3 222.4 442.6 220.5 430.5 230.1C378 272.1 330.3 341.9 306.7 379.4C291.4 359.3 267.2 331.1 239.5 312.6C226.6 304 209.2 307.5 200.7 320.4C192.2 333.3 195.6 350.7 208.5 359.2C237.4 378.5 264.1 415.1 274.1 429.9C281.5 440.9 294 447.9 307.9 447.9C322.3 447.9 335.5 440.3 342.8 428C357.2 403.5 410 318.3 465.6 273.8z"/></svg>\n\t\t\t\t<h3 class="cimo-media-manager-metadata-title">Image Optimized by Cimo</h3>\n\t\t\t\t</div>\n\t\t\t\t<ul>';const a=i.compressionSavings?(100-100*i.compressionSavings).toFixed(2):null,r=g(i.originalFilesize-i.convertedFilesize,1,!0);t+=`<li class="cimo-compression-savings ${n(a>0?"cimo-optimization-savings-up":"cimo-optimization-savings-down")}">Saved ${n(a)}% <span class="cimo-compression-savings-bytes">(${n(r)})</span></li>`;const s=g(parseInt(i.originalFilesize)||0),c=g(parseInt(i.convertedFilesize)||0);t+=`<li class="cimo-filesize-original">Original: <span class="cimo-value">${n(s)}</span></li>`,t+=`<li class="cimo-filesize-optimized">Optimized: <span class="cimo-value">${n(c)}</span></li>`,t+=`<li class="cimo-converted">🏞️ Converted to <span class="cimo-value">${n(function(e){const t=e.split("/")[1];return"webp"===t?"WebP":t.charAt(0).toUpperCase()+t.slice(1)}(i.convertedFormat))}</span></li>`;let l="N/A";if(i.conversionTime){const e=parseFloat(i.conversionTime);l=e<1e3?`${e.toFixed(0)} ms`:e<6e4?`${(e/1e3).toFixed(1)} sec`:`${(e/6e4).toFixed(1)} min`}t+=`<li class="cimo-time">⚡️ Done in <span class="cimo-value">${n(l)}</span></li>`,e.innerHTML=t,o.appendChild(e)}return a.innerHTML}}))})})();
  • cimo-image-optimizer/trunk/cimo.php

    r3377045 r3377061  
    88 * License: GPLv2 or later
    99 * Text Domain: cimo-image-optimizer
    10  * Version: 1.1.0
     10 * Version: 1.1.1
    1111 *
    1212 * @fs_premium_only /freemius.php, /freemius/
  • cimo-image-optimizer/trunk/readme.txt

    r3377045 r3377061  
    55Tested up to: 6.8.3
    66Requires PHP: 8.0
    7 Stable tag: 1.1.0
     7Stable tag: 1.1.1
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    189189== Changelog ==
    190190
     191= 1.1.1 =
     192
     193* Fixed: When uploading images using Safari, images will just upload as they normally would.
     194
    191195= 1.1.0 =
    192196
Note: See TracChangeset for help on using the changeset viewer.