@polyv/utils 2.12.0 → 2.13.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/image.js +1 -1
- package/es/image.js +1 -1
- package/package.json +1 -1
package/cjs/image.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function getExtname(e){var A=(e||"").split("."),t=A[A.length-1];return t?t.toLowerCase():""}function handleCompressOptions(e){var A,t,r="number"==typeof e?{width:e}:e;return r.allowJPG=null===(A=r.allowJPG)||void 0===A||A,r.allowWebP=null!==(t=r.allowWebP)&&void 0!==t?t:"auto",r}function createURLObject(e){var A;if("undefined"!=typeof document){var t=document.createElement("a");t.href=e,A=t}else if("function"==typeof URL)try{A=new URL(/^\/\//.test(e)?"https:"+e:e)}catch(e){}return A}function genOSSCompressParams(e,A){var t="";return null==A.width&&null==A.height||(t+="/resize",A.width&&(t+=",w_"+A.width),A.height&&(t+=",h_"+A.height),t+=",limit_1"),A.allowAVIF&&"gif"!==e?t+="/format,avif":!0===A.allowWebP||"auto"===A.allowWebP&&(0,exports.supportWebP)()?t+="/format,webp/quality,Q_80":A.allowJPG&&"gif"!==e&&(t+="/format,jpg/quality,Q_80"),t}function setOSSCompressParams(e,A){var t=!1;return e=e.replace(/([?&]x-oss-process)(?:=([^&]*))?/,(function(e,r,
|
|
1
|
+
"use strict";function getExtname(e){var A=(e||"").split("."),t=A[A.length-1];return t?t.toLowerCase():""}function handleCompressOptions(e){var A,t,r="number"==typeof e?{width:e}:e;return r.allowJPG=null===(A=r.allowJPG)||void 0===A||A,r.allowWebP=null!==(t=r.allowWebP)&&void 0!==t?t:"auto",r}function createURLObject(e){var A;if("undefined"!=typeof document){var t=document.createElement("a");t.href=e,A=t}else if("function"==typeof URL)try{A=new URL(/^\/\//.test(e)?"https:"+e:e)}catch(e){}return A}function genOSSCompressParams(e,A){var t="";return null==A.width&&null==A.height||(t+="/resize",A.width&&(t+=",w_"+A.width),A.height&&(t+=",h_"+A.height),t+=",limit_1"),A.allowAVIF&&"gif"!==e?t+="/format,avif":!0===A.allowWebP||"auto"===A.allowWebP&&(0,exports.supportWebP)()?t+="/format,webp/quality,Q_80":A.allowJPG&&"gif"!==e&&(t+="/format,jpg/quality,Q_80"),t}function setOSSCompressParams(e,A){var t=!1;return e=e.replace(/([?&]x-oss-process)(?:=([^&]*))?/,(function(e,r,a){return t=!0,/^image/.test(a)?r+"="+a.replace(/\/(?:resize|format|quality)[^/]*/gi,"")+A:e})),t?e:e+(-1===e.indexOf("?")?"?":"&")+"x-oss-process=image"+A}function ossCompress(e,A){var t=createURLObject(e);if(!t)return e;var r=getExtname(t.pathname.split("/").pop());if(!/\.videocc\.net$/i.test(t.hostname)||"svg"===r)return e;var a=genOSSCompressParams(r,handleCompressOptions(A));return a&&(t.search=setOSSCompressParams(t.search,a)),t.href}function genCOSCompressParams(e,A){var t="";return null!=A.width&&null!=A.height?t+="/thumbnail/".concat(A.width,"x").concat(A.height):null!=A.width?t+="/thumbnail/".concat(A.width,"x"):null!=A.height&&(t+="/thumbnail/x".concat(A.height)),A.allowAVIF&&"gif"!==e?t+="/format/avif":!0===A.allowWebP||"auto"===A.allowWebP&&(0,exports.supportWebP)()?t+="/format/webp/quality/80":A.allowJPG&&"gif"!==e&&(t+="/format/jpg/quality/80"),t}function setCOSCompressParams(e,A){var t=!1;return e=e.replace(/([?&]imageMogr2)(\/[^&]*)/,(function(e,r,a){return t=!0,r+"="+a.replace(/\/(?:thumbnail|format|quality)\/[^/]+/gi,"")+A})),t?e:e+(-1===e.indexOf("?")?"?":"&")+"imageMogr2"+A}function cosCompress(e,A){var t=createURLObject(e);if(!t)return e;var r=getExtname(t.pathname.split("/").pop());if(!/(?:\.videocc\.net|\.kingswayvideo\.com)$/i.test(t.hostname)||"svg"===r)return e;var a=genCOSCompressParams(r,handleCompressOptions(A));return a&&(t.search=setCOSCompressParams(t.search,a)),t.href}function compressHTMLImgs(e,A,t){return void 0===t&&(t=ossCompress),e?e.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,(function(e,r,a,s,o){return r+'"'+t(s,A)+'" data-src="'+s+'"'+o})):""}Object.defineProperty(exports,"__esModule",{value:!0}),exports.supportAVIF=exports.supportWebP=void 0,exports.ossCompress=ossCompress,exports.cosCompress=cosCompress,exports.compressHTMLImgs=compressHTMLImgs,exports.supportWebP=function(){var e;return function(){if(null==e)try{e=function(){var e=document.createElement("canvas");if(e.getContext&&e.getContext("2d")){var A="image/webp";return 0===e.toDataURL(A).indexOf("data:"+A)}return!1}()||function(){var e=!1,A=navigator.userAgent,t=/\bOS\s([\d_.]+)\slike\sMac\sOS\sX\b/.exec(A);if(t)e=parseInt(t[1])>=14;else{var r=/\bVersion\/([\d.]+)\sSafari\b/.exec(A);r&&(e=parseInt(r[1])>=16)}return e}()}catch(A){e=!1}return e}}(),exports.supportAVIF=function(){var e;return function(){return e||(e=new Promise((function(e){var A=new Image;A.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",A.onerror=function(){e(!1)},A.onload=function(){e(!0)},setTimeout((function(){e(!1)}),1e3)}))),e}}();
|
package/es/image.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const supportWebP=(()=>{let
|
|
1
|
+
export const supportWebP=(()=>{let e;return()=>{if(null==e)try{e=function(){const e=document.createElement("canvas");if(e.getContext&&e.getContext("2d")){const A="image/webp";return 0===e.toDataURL(A).indexOf("data:"+A)}return!1}()||function(){let e=!1;const A=navigator.userAgent,t=/\bOS\s([\d_.]+)\slike\sMac\sOS\sX\b/.exec(A);if(t)e=parseInt(t[1])>=14;else{const t=/\bVersion\/([\d.]+)\sSafari\b/.exec(A);t&&(e=parseInt(t[1])>=16)}return e}()}catch(A){e=!1}return e}})();export const supportAVIF=(()=>{let e;return()=>(e||(e=new Promise((e=>{const A=new Image;A.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",A.onerror=()=>{e(!1)},A.onload=()=>{e(!0)},setTimeout((()=>{e(!1)}),1e3)}))),e)})();function getExtname(e){const A=(e||"").split("."),t=A[A.length-1];return t?t.toLowerCase():""}function handleCompressOptions(e){var A,t;const n="number"==typeof e?{width:e}:e;return n.allowJPG=null===(A=n.allowJPG)||void 0===A||A,n.allowWebP=null!==(t=n.allowWebP)&&void 0!==t?t:"auto",n}function createURLObject(e){let A;if("undefined"!=typeof document){const t=document.createElement("a");t.href=e,A=t}else if("function"==typeof URL)try{A=new URL(/^\/\//.test(e)?"https:"+e:e)}catch(e){}return A}function genOSSCompressParams(e,A){let t="";return null==A.width&&null==A.height||(t+="/resize",A.width&&(t+=",w_"+A.width),A.height&&(t+=",h_"+A.height),t+=",limit_1"),A.allowAVIF&&"gif"!==e?t+="/format,avif":!0===A.allowWebP||"auto"===A.allowWebP&&supportWebP()?t+="/format,webp/quality,Q_80":A.allowJPG&&"gif"!==e&&(t+="/format,jpg/quality,Q_80"),t}function setOSSCompressParams(e,A){let t=!1;return e=e.replace(/([?&]x-oss-process)(?:=([^&]*))?/,((e,n,r)=>(t=!0,/^image/.test(r)?n+"="+r.replace(/\/(?:resize|format|quality)[^/]*/gi,"")+A:e))),t?e:e+(-1===e.indexOf("?")?"?":"&")+"x-oss-process=image"+A}export function ossCompress(e,A){const t=createURLObject(e);if(!t)return e;const n=getExtname(t.pathname.split("/").pop());if(!/\.videocc\.net$/i.test(t.hostname)||"svg"===n)return e;const r=genOSSCompressParams(n,handleCompressOptions(A));return r&&(t.search=setOSSCompressParams(t.search,r)),t.href}function genCOSCompressParams(e,A){let t="";return null!=A.width&&null!=A.height?t+=`/thumbnail/${A.width}x${A.height}`:null!=A.width?t+=`/thumbnail/${A.width}x`:null!=A.height&&(t+=`/thumbnail/x${A.height}`),A.allowAVIF&&"gif"!==e?t+="/format/avif":!0===A.allowWebP||"auto"===A.allowWebP&&supportWebP()?t+="/format/webp/quality/80":A.allowJPG&&"gif"!==e&&(t+="/format/jpg/quality/80"),t}function setCOSCompressParams(e,A){let t=!1;return e=e.replace(/([?&]imageMogr2)(\/[^&]*)/,((e,n,r)=>(t=!0,n+"="+r.replace(/\/(?:thumbnail|format|quality)\/[^/]+/gi,"")+A))),t?e:e+(-1===e.indexOf("?")?"?":"&")+"imageMogr2"+A}export function cosCompress(e,A){const t=createURLObject(e);if(!t)return e;const n=getExtname(t.pathname.split("/").pop());if(!/(?:\.videocc\.net|\.kingswayvideo\.com)$/i.test(t.hostname)||"svg"===n)return e;const r=genCOSCompressParams(n,handleCompressOptions(A));return r&&(t.search=setCOSCompressParams(t.search,r)),t.href}export function compressHTMLImgs(e,A,t=ossCompress){return e?e.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,((e,n,r,s,o)=>n+'"'+t(s,A)+'" data-src="'+s+'"'+o)):""}
|