From 24ef5d2ac40058373d41016cd2680f1ec5a0703b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:40:27 +0000 Subject: [PATCH] Built release for 0.5.4. For a full change log look at the notes within the original/0.5.4 release. --- build.json | 2 +- ...ropper.88b7c347.js => cropper.7fec5ab2.js} | 2 +- inc/cropper/namespace.php | 29 +++++++++--- inc/cropper/src/cropper.js | 18 +++++++- inc/cropper/src/views/image-editor.js | 12 ++++- manifest.json | 2 +- package-lock.json | 44 +++++++++---------- 7 files changed, 76 insertions(+), 33 deletions(-) rename inc/cropper/build/{cropper.88b7c347.js => cropper.7fec5ab2.js} (60%) diff --git a/build.json b/build.json index 4dd3b49..0351d65 100644 --- a/build.json +++ b/build.json @@ -1 +1 @@ -{"owner":"humanmade","repo":"smart-media","sha":"a4746bf63287998b1b8ffc10966876e240219471","ref":"refs/tags/0.5.3","tagName":"0.5.3","branch":"gh-actions","tags":["0.5.3"],"updated_at":"2024-04-09T09:03:44.323Z"} \ No newline at end of file +{"owner":"humanmade","repo":"smart-media","sha":"239578e1130130b7d6ce58b5cd8f54347edbe78a","ref":"refs/tags/0.5.4","tagName":"0.5.4","branch":"gh-actions","tags":["0.5.4"],"updated_at":"2024-04-22T12:40:27.659Z"} \ No newline at end of file diff --git a/inc/cropper/build/cropper.88b7c347.js b/inc/cropper/build/cropper.7fec5ab2.js similarity index 60% rename from inc/cropper/build/cropper.88b7c347.js rename to inc/cropper/build/cropper.7fec5ab2.js index ad111db..4f0bdf2 100644 --- a/inc/cropper/build/cropper.88b7c347.js +++ b/inc/cropper/build/cropper.7fec5ab2.js @@ -1 +1 @@ -!function(t,e){for(var i in e)t[i]=e[i]}(this,function(t){var e={};function i(o){if(e[o])return e[o].exports;var n=e[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=t,i.c=e,i.d=function(t,e,o){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(i.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)i.d(o,n,function(e){return t[e]}.bind(null,n));return o},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="/",i(i.s=13)}([function(t,e){!function(){t.exports=this.wp.media}()},function(t,e){!function(){t.exports=this.wp.template}()},function(t,e){!function(){t.exports=this.wp.hooks}()},function(t,e){!function(){t.exports=this.wp.i18n}()},function(t,e){!function(){t.exports=this.wp.ajax}()},function(t,e){!function(){t.exports=this.jQuery}()},function(t,e,i){var o;!function(){"use strict";var n={};function r(t,e,i){for(var o=i.data,n=i.width,r=~~t.x,a=~~(t.x+t.width),s=~~t.y,l=~~(t.y+t.height),c=255*t.weight,d=s;di||i>=e.x+e.width||e.y>o||o>=e.y+e.height)return t.outsideImportance;i=(i-e.x)/e.width,o=(o-e.y)/e.height;var n=2*g(.5-i),r=2*g(.5-o),a=Math.max(n-1+t.edgeRadius,0),s=Math.max(r-1+t.edgeRadius,0),l=(a*a+s*s)*t.edgeWeight,c=1.41-f(n*n+r*r);return t.ruleOfThirds&&(c+=1.2*Math.max(0,c+l+.5)*(w(n)+w(r))),c+l}function l(t,e,i,o){var n=f(e*e+i*i+o*o),r=e/n-t.skinColor[0],a=i/n-t.skinColor[1],s=o/n-t.skinColor[2];return 1-f(r*r+a*a+s*s)}function c(t,e,i){this.width=t,this.height=e,this.data=i?new Uint8ClampedArray(i):new Uint8ClampedArray(t*e*4)}function d(t,e){for(var i=t.data,o=t.width,n=Math.floor(t.width/e),r=Math.floor(t.height/e),a=new c(n,r),s=a.data,l=1/(e*e),d=0;d=n-1||0===a||a>=r-1?y(i,c):4*y(i,c)-y(i,c-4*n)-y(i,c-4)-y(i,c+4)-y(i,c+4*n),o[c+1]=l}})(e,o),function(t,e,i){for(var o=e.data,n=i.data,r=e.width,a=e.height,s=0;st.skinThreshold,m=h>=t.skinBrightnessMin&&h<=t.skinBrightnessMax;n[d]=p&&m?(u-t.skinThreshold)*(255/(1-t.skinThreshold)):0}}(t,e,o),function(t,e,i){for(var o=e.data,n=i.data,r=e.width,a=e.height,s=0;st.saturationThreshold,p=d>=t.saturationBrightnessMin&&d<=t.saturationBrightnessMax;n[c+2]=p&&u?(h-t.saturationThreshold)*(255/(1-t.saturationThreshold)):0}}(t,e,o),function(t,e){if(!t.boost)return;for(var i=e.data,o=0;o=t.minScale;s-=t.scaleStep)for(var l=0;l+a*s<=i;l+=t.step)for(var c=0;c+r*s<=e;c+=t.step)o.push({x:c,y:l,width:r*s,height:a*s});return o}(t,e.width,e.height),m=0,g=u.length;ms&&(h=f,s=f.score.total)}i.topCrop=h,t.debug&&h&&(i.crops=u,i.debugOutput=o,i.debugOptions=t,i.debugTopCrop=v({},i.topCrop));return i}(o,t),n=e.crops||[e.topCrop],s=0,h=n.length;s.5?r/(2-o-n):r/(o+n)}void 0===(o=function(){return n}.call(e,i,e,t))||(t.exports=o),e.smartcrop=n,t.exports=n}()},function(t,e){!function(){t.exports=this._}()},function(t,e){!function(){t.exports=this.wp.BackBone}()},function(t,e,i){var o=i(10),n=i(11);"string"==typeof(n=n.__esModule?n.default:n)&&(n=[[t.i,n,""]]);var r={insert:"head",singleton:!1};o(n,r);t.exports=n.locals||{}},function(t,e,i){"use strict";var o,n=function(){return void 0===o&&(o=Boolean(window&&document&&document.all&&!window.atob)),o},r=function(){var t={};return function(e){if(void 0===t[e]){var i=document.querySelector(e);if(window.HTMLIFrameElement&&i instanceof window.HTMLIFrameElement)try{i=i.contentDocument.head}catch(t){i=null}t[e]=i}return t[e]}}(),a=[];function s(t){for(var e=-1,i=0;it.length)&&(e=t.length);for(var i=0,o=new Array(e);ii||i>=e.x+e.width||e.y>o||o>=e.y+e.height)return t.outsideImportance;i=(i-e.x)/e.width,o=(o-e.y)/e.height;var n=2*g(.5-i),r=2*g(.5-o),a=Math.max(n-1+t.edgeRadius,0),s=Math.max(r-1+t.edgeRadius,0),l=(a*a+s*s)*t.edgeWeight,c=1.41-f(n*n+r*r);return t.ruleOfThirds&&(c+=1.2*Math.max(0,c+l+.5)*(w(n)+w(r))),c+l}function l(t,e,i,o){var n=f(e*e+i*i+o*o),r=e/n-t.skinColor[0],a=i/n-t.skinColor[1],s=o/n-t.skinColor[2];return 1-f(r*r+a*a+s*s)}function c(t,e,i){this.width=t,this.height=e,this.data=i?new Uint8ClampedArray(i):new Uint8ClampedArray(t*e*4)}function d(t,e){for(var i=t.data,o=t.width,n=Math.floor(t.width/e),r=Math.floor(t.height/e),a=new c(n,r),s=a.data,l=1/(e*e),d=0;d=n-1||0===a||a>=r-1?y(i,c):4*y(i,c)-y(i,c-4*n)-y(i,c-4)-y(i,c+4)-y(i,c+4*n),o[c+1]=l}})(e,o),function(t,e,i){for(var o=e.data,n=i.data,r=e.width,a=e.height,s=0;st.skinThreshold,m=h>=t.skinBrightnessMin&&h<=t.skinBrightnessMax;n[d]=p&&m?(u-t.skinThreshold)*(255/(1-t.skinThreshold)):0}}(t,e,o),function(t,e,i){for(var o=e.data,n=i.data,r=e.width,a=e.height,s=0;st.saturationThreshold,p=d>=t.saturationBrightnessMin&&d<=t.saturationBrightnessMax;n[c+2]=p&&u?(h-t.saturationThreshold)*(255/(1-t.saturationThreshold)):0}}(t,e,o),function(t,e){if(!t.boost)return;for(var i=e.data,o=0;o=t.minScale;s-=t.scaleStep)for(var l=0;l+a*s<=i;l+=t.step)for(var c=0;c+r*s<=e;c+=t.step)o.push({x:c,y:l,width:r*s,height:a*s});return o}(t,e.width,e.height),m=0,g=u.length;ms&&(h=f,s=f.score.total)}i.topCrop=h,t.debug&&h&&(i.crops=u,i.debugOutput=o,i.debugOptions=t,i.debugTopCrop=v({},i.topCrop));return i}(o,t),n=e.crops||[e.topCrop],s=0,h=n.length;s.5?r/(2-o-n):r/(o+n)}void 0===(o=function(){return n}.call(e,i,e,t))||(t.exports=o),e.smartcrop=n,t.exports=n}()},function(t,e){!function(){t.exports=this._}()},function(t,e){!function(){t.exports=this.wp.BackBone}()},function(t,e,i){var o=i(10),n=i(11);"string"==typeof(n=n.__esModule?n.default:n)&&(n=[[t.i,n,""]]);var r={insert:"head",singleton:!1};o(n,r);t.exports=n.locals||{}},function(t,e,i){"use strict";var o,n=function(){return void 0===o&&(o=Boolean(window&&document&&document.all&&!window.atob)),o},r=function(){var t={};return function(e){if(void 0===t[e]){var i=document.querySelector(e);if(window.HTMLIFrameElement&&i instanceof window.HTMLIFrameElement)try{i=i.contentDocument.head}catch(t){i=null}t[e]=i}return t[e]}}(),a=[];function s(t){for(var e=-1,i=0;it.length)&&(e=t.length);for(var i=0,o=new Array(e);itrue. */ function img_tag_add_attr( bool $value, string $image ) : bool { - return ! defined( 'TACHYON_URL' ) || strpos( $image, TACHYON_URL ) === false ? $value : false; + return ! is_tachyon_url( $image ) ? $value : false; } /** @@ -1035,7 +1054,7 @@ function add_width_and_height_attr( $image, $image_meta ) : string { if ( empty( $image_meta ) ) { return $image; } - + $image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : ''; // Return early if we couldn't get the image source. @@ -1073,7 +1092,7 @@ function add_srcset_and_sizes_attr( $image, $image_meta, $attachment_id ) : stri if ( empty( $image_meta ) ) { return $image; } - + $image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : ''; // Return early if we couldn't get the image source. @@ -1151,7 +1170,7 @@ function image_srcset( array $sources, array $size_array, string $image_src, arr list( $width, $height ) = array_map( 'absint', $size_array ); // Ensure this is _not_ a tachyon image, not always the case when parsing from post content. - if ( ! defined( 'TACHYON_URL' ) || strpos( $image_src, TACHYON_URL ) === false ) { + if ( ! is_tachyon_url( $image_src ) ) { // If the aspect ratio requested matches a custom crop size, pull that // crop (in case there's a user custom crop). Otherwise just use the // given dimensions. diff --git a/inc/cropper/src/cropper.js b/inc/cropper/src/cropper.js index b528d69..a780510 100644 --- a/inc/cropper/src/cropper.js +++ b/inc/cropper/src/cropper.js @@ -33,7 +33,7 @@ addFilter( // Ensure Smart Media is supported by Asset Manager Framework. addAction( 'amf.extend_toolbar', 'smartmedia/cropper', extend_toolbar => { - Media.view.Toolbar = extend_toolbar( Media.view.Toolbar, 'apply' ); + Media.view.Toolbar = extend_toolbar( Media.view.Toolbar, 'apply' ); } ); @@ -158,9 +158,16 @@ Media.view.MediaFrame.Select = MediaFrameSelect.extend( { libraryState.get( 'selection' ).on( 'selection:single', () => { const single = this.state( 'edit' ).get( 'selection' ).single(); + if ( this._state === 'edit' ) { + return; + } + // Check that the attachment is a complete object. Built in placeholders // exist for the cover block that can confuse things. - if ( ( ! isFeaturedImage && ! single.get( 'url' ) ) || ! single.get( 'id' ) ) { + if ( ! single.get( 'id' ) ) { + single.fetch().then( () => { + this.setState( 'edit' ); + } ); return; } @@ -180,6 +187,9 @@ Media.view.MediaFrame.Select = MediaFrameSelect.extend( { } } + // Set size back to full. + single.set( { size: 'full' } ); + wp.media.view.settings.post.featuredImageId = single.get( 'id' ); } @@ -192,6 +202,10 @@ Media.view.MediaFrame.Select = MediaFrameSelect.extend( { wp.media.view.settings.post.featuredImageId = -1; } + if ( this._state !== 'edit' ) { + return; + } + this.setState( libraryState.id ); } ); }, diff --git a/inc/cropper/src/views/image-editor.js b/inc/cropper/src/views/image-editor.js index 74ad8e8..56722e3 100644 --- a/inc/cropper/src/views/image-editor.js +++ b/inc/cropper/src/views/image-editor.js @@ -91,8 +91,8 @@ const ImageEditor = Media.View.extend( { // Reset to focal point or smart crop by default. if ( ! crop.hasOwnProperty( 'x' ) ) { + const [ cropWidth, cropHeight ] = getMaxCrop( width, height, size.width, size.height ); if ( focalPoint.hasOwnProperty( 'x' ) ) { - const [ cropWidth, cropHeight ] = getMaxCrop( width, height, size.width, size.height ); this.setSelection( { x: Math.min( width - cropWidth, Math.max( 0, focalPoint.x - ( cropWidth / 2 ) ) ), y: Math.min( height - cropHeight, Math.max( 0, focalPoint.y - ( cropHeight / 2 ) ) ), @@ -108,6 +108,16 @@ const ImageEditor = Media.View.extend( { } ) .then( ( { topCrop } ) => { this.setSelection( topCrop ); + } ) + .catch( error => { + console.error( error ); + // Fallback to centered crop, can fail due to cross-origin canvas tainting. + this.setSelection( { + x: Math.max( 0 , ( width - cropWidth ) / 2 ), + y: Math.max( 0, ( height - cropHeight ) / 2 ), + width: cropWidth, + height: cropHeight, + } ); } ); } } else { diff --git a/manifest.json b/manifest.json index 584ae65..0bf8b10 100644 --- a/manifest.json +++ b/manifest.json @@ -1,3 +1,3 @@ { - "cropper.js": "/inc/cropper/build/cropper.88b7c347.js" + "cropper.js": "/inc/cropper/build/cropper.7fec5ab2.js" } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 80e4e88..23e2aa3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1784,13 +1784,13 @@ "dev": true }, "body-parser": { - "version": "1.20.1", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", - "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", + "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", "dev": true, "requires": { "bytes": "3.1.2", - "content-type": "~1.0.4", + "content-type": "~1.0.5", "debug": "2.6.9", "depd": "2.0.0", "destroy": "1.2.0", @@ -1798,7 +1798,7 @@ "iconv-lite": "0.4.24", "on-finished": "2.4.1", "qs": "6.11.0", - "raw-body": "2.5.1", + "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" }, @@ -2474,9 +2474,9 @@ } }, "content-type": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", - "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", "dev": true }, "convert-source-map": { @@ -2489,9 +2489,9 @@ } }, "cookie": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", - "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", "dev": true }, "cookie-signature": { @@ -3226,17 +3226,17 @@ } }, "express": { - "version": "4.18.2", - "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", - "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz", + "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==", "dev": true, "requires": { "accepts": "~1.3.8", "array-flatten": "1.1.1", - "body-parser": "1.20.1", + "body-parser": "1.20.2", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.5.0", + "cookie": "0.6.0", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "2.0.0", @@ -4806,9 +4806,9 @@ } }, "ip": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz", - "integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo=", + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.9.tgz", + "integrity": "sha512-cyRxvOEpNHNtchU3Ln9KC/auJgup87llfQpQ+t5ghoC/UhL16SWzbueiCsdTnWmqAWl7LadfuwhlqmtOaqMHdQ==", "dev": true }, "ip-regex": { @@ -6502,9 +6502,9 @@ "dev": true }, "raw-body": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", - "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", "dev": true, "requires": { "bytes": "3.1.2",