@polyv/utils 2.10.0-beta.3 → 2.10.0-beta.4

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.d.ts CHANGED
@@ -25,11 +25,11 @@ export interface IOSSCompressOptions {
25
25
  */
26
26
  height?: number;
27
27
  /**
28
- * 是否允许转换为 JPG。
28
+ * 是否允许转换为 JPG。默认为 true
29
29
  */
30
30
  allowJPG?: boolean;
31
31
  /**
32
- * 是否允许转换为 WebP。设为 'auto' 时,只要当前浏览器支持 WebP,就进行转换。
32
+ * 是否允许转换为 WebP,默认为 'auto'。'auto' 表示当前浏览器支持 WebP,就进行转换。
33
33
  */
34
34
  allowWebP?: boolean | 'auto';
35
35
  /**
@@ -46,7 +46,8 @@ export interface IOSSCompressOptions {
46
46
  * ```javascript
47
47
  * ossCompress(url, {
48
48
  * width: 300,
49
- * allowWebp: true
49
+ * allowJPG: true,
50
+ * allowWebP: 'auto'
50
51
  * });
51
52
  * ```
52
53
  */
package/cjs/image.js CHANGED
@@ -1 +1 @@
1
- "use strict";function genOSSCompressParams(A,e){var t="";return null==e.width&&null==e.height||(t+="/resize",e.width&&(t+=",w_"+e.width),e.height&&(t+=",h_"+e.height),t+=",limit_1"),e.allowAVIF&&"gif"!==A?t+="/format,avif":!0===e.allowWebP||"auto"===e.allowWebP&&(0,exports.supportWebP)()?t+="/format,webp/quality,Q_80":e.allowJPG&&"gif"!==A&&(t+="/format,jpg/quality,Q_80"),t}function setOSSCompressParams(A,e){var t=!1;return A=A.replace(/([?&]x-oss-process)(?:=([^&]*))?/,(function(A,r,s){return t=!0,/^image/.test(s)?r+"="+s.replace(/\/(?:resize|format|quality)[^/]*/gi,"")+e:A})),t?A:A+(-1===A.indexOf("?")?"?":"&")+"x-oss-process=image"+e}function ossCompress(A,e){var t;if("undefined"!=typeof document){var r=document.createElement("a");r.href=A,t=r}else if("function"==typeof URL)try{t=new URL(/^\/\//.test(A)?"https:"+A:A)}catch(A){}if(!t)return A;if(!/\.videocc\.net$/i.test(t.hostname))return A;var s=(t.pathname.split("/").pop()||"").split("."),o=genOSSCompressParams(s[s.length-1].toLowerCase(),e);return o&&(t.search=setOSSCompressParams(t.search,o)),t.href}function compressHTMLImgs(A,e){return A?A.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,(function(A,t,r,s,o){return t+'"'+ossCompress(s,e)+'" data-src="'+s+'"'+o})):""}Object.defineProperty(exports,"__esModule",{value:!0}),exports.supportAVIF=exports.supportWebP=void 0,exports.ossCompress=ossCompress,exports.compressHTMLImgs=compressHTMLImgs,exports.supportWebP=function(){var A;return function(){return null==A&&(A=function(){var A=document.createElement("canvas");if(A.getContext&&A.getContext("2d")){var e="image/webp";return 0===A.toDataURL(e).indexOf("data:"+e)}return!1}()),A}}(),exports.supportAVIF=function(){var A;return function(){return A||(A=new Promise((function(A){var e=new Image;e.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",e.onerror=function(){A(!1)},e.onload=function(){A(!0)},setTimeout((function(){A(!1)}),1e3)}))),A}}();
1
+ "use strict";function genOSSCompressParams(A,e){var t="";return null==e.width&&null==e.height||(t+="/resize",e.width&&(t+=",w_"+e.width),e.height&&(t+=",h_"+e.height),t+=",limit_1"),e.allowAVIF&&"gif"!==A?t+="/format,avif":!0===e.allowWebP||"auto"===e.allowWebP&&(0,exports.supportWebP)()?t+="/format,webp/quality,Q_80":e.allowJPG&&"gif"!==A&&(t+="/format,jpg/quality,Q_80"),t}function setOSSCompressParams(A,e){var t=!1;return A=A.replace(/([?&]x-oss-process)(?:=([^&]*))?/,(function(A,r,o){return t=!0,/^image/.test(o)?r+"="+o.replace(/\/(?:resize|format|quality)[^/]*/gi,"")+e:A})),t?A:A+(-1===A.indexOf("?")?"?":"&")+"x-oss-process=image"+e}function ossCompress(A,e){var t,r,o;if("undefined"!=typeof document){var s=document.createElement("a");s.href=A,o=s}else if("function"==typeof URL)try{o=new URL(/^\/\//.test(A)?"https:"+A:A)}catch(A){}if(!o)return A;if(!/\.videocc\.net$/i.test(o.hostname))return A;var a=(o.pathname.split("/").pop()||"").split("."),n=a[a.length-1].toLowerCase();e.allowJPG=null===(t=e.allowJPG)||void 0===t||t,e.allowWebP=null!==(r=e.allowWebP)&&void 0!==r?r:"auto";var i=genOSSCompressParams(n,e);return i&&(o.search=setOSSCompressParams(o.search,i)),o.href}function compressHTMLImgs(A,e){return A?A.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,(function(A,t,r,o,s){return t+'"'+ossCompress(o,e)+'" data-src="'+o+'"'+s})):""}Object.defineProperty(exports,"__esModule",{value:!0}),exports.supportAVIF=exports.supportWebP=void 0,exports.ossCompress=ossCompress,exports.compressHTMLImgs=compressHTMLImgs,exports.supportWebP=function(){var A;return function(){return null==A&&(A=function(){var A=document.createElement("canvas");if(A.getContext&&A.getContext("2d")){var e="image/webp";return 0===A.toDataURL(e).indexOf("data:"+e)}return!1}()),A}}(),exports.supportAVIF=function(){var A;return function(){return A||(A=new Promise((function(A){var e=new Image;e.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",e.onerror=function(){A(!1)},e.onload=function(){A(!0)},setTimeout((function(){A(!1)}),1e3)}))),A}}();
package/es/image.d.ts CHANGED
@@ -25,11 +25,11 @@ export interface IOSSCompressOptions {
25
25
  */
26
26
  height?: number;
27
27
  /**
28
- * 是否允许转换为 JPG。
28
+ * 是否允许转换为 JPG。默认为 true
29
29
  */
30
30
  allowJPG?: boolean;
31
31
  /**
32
- * 是否允许转换为 WebP。设为 'auto' 时,只要当前浏览器支持 WebP,就进行转换。
32
+ * 是否允许转换为 WebP,默认为 'auto'。'auto' 表示当前浏览器支持 WebP,就进行转换。
33
33
  */
34
34
  allowWebP?: boolean | 'auto';
35
35
  /**
@@ -46,7 +46,8 @@ export interface IOSSCompressOptions {
46
46
  * ```javascript
47
47
  * ossCompress(url, {
48
48
  * width: 300,
49
- * allowWebp: true
49
+ * allowJPG: true,
50
+ * allowWebP: 'auto'
50
51
  * });
51
52
  * ```
52
53
  */
package/es/image.js CHANGED
@@ -1 +1 @@
1
- export const supportWebP=(()=>{let A;return()=>(null==A&&(A=function(){const A=document.createElement("canvas");if(A.getContext&&A.getContext("2d")){const e="image/webp";return 0===A.toDataURL(e).indexOf("data:"+e)}return!1}()),A)})();export const supportAVIF=(()=>{let A;return()=>(A||(A=new Promise((A=>{const e=new Image;e.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",e.onerror=()=>{A(!1)},e.onload=()=>{A(!0)},setTimeout((()=>{A(!1)}),1e3)}))),A)})();function genOSSCompressParams(A,e){let t="";return null==e.width&&null==e.height||(t+="/resize",e.width&&(t+=",w_"+e.width),e.height&&(t+=",h_"+e.height),t+=",limit_1"),e.allowAVIF&&"gif"!==A?t+="/format,avif":!0===e.allowWebP||"auto"===e.allowWebP&&supportWebP()?t+="/format,webp/quality,Q_80":e.allowJPG&&"gif"!==A&&(t+="/format,jpg/quality,Q_80"),t}function setOSSCompressParams(A,e){let t=!1;return A=A.replace(/([?&]x-oss-process)(?:=([^&]*))?/,((A,s,r)=>(t=!0,/^image/.test(r)?s+"="+r.replace(/\/(?:resize|format|quality)[^/]*/gi,"")+e:A))),t?A:A+(-1===A.indexOf("?")?"?":"&")+"x-oss-process=image"+e}export function ossCompress(A,e){let t;if("undefined"!=typeof document){const e=document.createElement("a");e.href=A,t=e}else if("function"==typeof URL)try{t=new URL(/^\/\//.test(A)?"https:"+A:A)}catch(A){}if(!t)return A;if(!/\.videocc\.net$/i.test(t.hostname))return A;const s=(t.pathname.split("/").pop()||"").split("."),r=genOSSCompressParams(s[s.length-1].toLowerCase(),e);return r&&(t.search=setOSSCompressParams(t.search,r)),t.href}export function compressHTMLImgs(A,e){return A?A.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,((A,t,s,r,o)=>t+'"'+ossCompress(r,e)+'" data-src="'+r+'"'+o)):""}
1
+ export const supportWebP=(()=>{let A;return()=>(null==A&&(A=function(){const A=document.createElement("canvas");if(A.getContext&&A.getContext("2d")){const e="image/webp";return 0===A.toDataURL(e).indexOf("data:"+e)}return!1}()),A)})();export const supportAVIF=(()=>{let A;return()=>(A||(A=new Promise((A=>{const e=new Image;e.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=",e.onerror=()=>{A(!1)},e.onload=()=>{A(!0)},setTimeout((()=>{A(!1)}),1e3)}))),A)})();function genOSSCompressParams(A,e){let t="";return null==e.width&&null==e.height||(t+="/resize",e.width&&(t+=",w_"+e.width),e.height&&(t+=",h_"+e.height),t+=",limit_1"),e.allowAVIF&&"gif"!==A?t+="/format,avif":!0===e.allowWebP||"auto"===e.allowWebP&&supportWebP()?t+="/format,webp/quality,Q_80":e.allowJPG&&"gif"!==A&&(t+="/format,jpg/quality,Q_80"),t}function setOSSCompressParams(A,e){let t=!1;return A=A.replace(/([?&]x-oss-process)(?:=([^&]*))?/,((A,o,s)=>(t=!0,/^image/.test(s)?o+"="+s.replace(/\/(?:resize|format|quality)[^/]*/gi,"")+e:A))),t?A:A+(-1===A.indexOf("?")?"?":"&")+"x-oss-process=image"+e}export function ossCompress(A,e){var t,o;let s;if("undefined"!=typeof document){const e=document.createElement("a");e.href=A,s=e}else if("function"==typeof URL)try{s=new URL(/^\/\//.test(A)?"https:"+A:A)}catch(A){}if(!s)return A;if(!/\.videocc\.net$/i.test(s.hostname))return A;const a=(s.pathname.split("/").pop()||"").split("."),r=a[a.length-1].toLowerCase();e.allowJPG=null===(t=e.allowJPG)||void 0===t||t,e.allowWebP=null!==(o=e.allowWebP)&&void 0!==o?o:"auto";const n=genOSSCompressParams(r,e);return n&&(s.search=setOSSCompressParams(s.search,n)),s.href}export function compressHTMLImgs(A,e){return A?A.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,((A,t,o,s,a)=>t+'"'+ossCompress(s,e)+'" data-src="'+s+'"'+a)):""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyv/utils",
3
- "version": "2.10.0-beta.3",
3
+ "version": "2.10.0-beta.4",
4
4
  "description": "Utility functions of Polyv frontend development.",
5
5
  "keywords": [
6
6
  "polyv",