@polyv/utils 2.10.0-beta.2 → 2.10.0-beta.3
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/browser.d.ts +1 -1
- package/cjs/browser.js +1 -1
- package/cjs/image.d.ts +4 -4
- package/cjs/image.js +1 -1
- package/es/browser.d.ts +1 -1
- package/es/browser.js +1 -1
- package/es/image.d.ts +4 -4
- package/es/image.js +1 -1
- package/package.json +1 -1
package/cjs/browser.d.ts
CHANGED
package/cjs/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function isMobile(){var t=navigator.userAgent;return
|
|
1
|
+
"use strict";function isMobile(){var t=navigator.userAgent;return!/\(X11[;)]/i.test(t)&&!/\b(Windows\sNT|Macintosh)\b/.test(t)&&/mobile|tablet|android/i.test(t)}function hasMobileFeature(){var t=navigator.platform;return"onorientationchange"in window&&"number"==typeof window.orientation||(!!/^(iPhone|iPod|iPad)/.test(t)||"Win32"!==t&&!/^Linux\s*(x86|i686)/.test(t)&&("MacIntel"===t||"Macintosh"===t?navigator.maxTouchPoints>0:"function"==typeof matchMedia&&(matchMedia("(hover: none)").matches&&matchMedia("(pointer: coarse)").matches&&!matchMedia("(pointer: fine)").matches)))}function isMaxthon(){var t=navigator.userAgent;if(/\bMaxthon\b/i.test(t))return!0;if("maxthon"in window){var e=window.maxthon;return"function"==typeof e.IsMaxthon&&e.IsMaxthon()}return!1}function supportMSEH264(){var t=window.MediaSource;return t&&"function"==typeof t.isTypeSupported&&t.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"')}Object.defineProperty(exports,"__esModule",{value:!0}),exports.isMobile=isMobile,exports.hasMobileFeature=hasMobileFeature,exports.isMaxthon=isMaxthon,exports.supportMSEH264=supportMSEH264;
|
package/cjs/image.d.ts
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
* 检查当前浏览器是否支持 WebP 格式。
|
|
7
7
|
* @returns 当前浏览器是否支持 WebP 格式。
|
|
8
8
|
*/
|
|
9
|
-
export declare
|
|
9
|
+
export declare const supportWebP: () => boolean;
|
|
10
10
|
/**
|
|
11
11
|
* 检查当前浏览器是否支持 AVIF 格式(注意,本函数是异步函数)。
|
|
12
12
|
* @returns 当前浏览器是否支持 AVIF 格式。
|
|
13
13
|
*/
|
|
14
|
-
export declare
|
|
14
|
+
export declare const supportAVIF: () => Promise<boolean>;
|
|
15
15
|
/**
|
|
16
16
|
* 压缩选项。
|
|
17
17
|
*/
|
|
@@ -29,9 +29,9 @@ export interface IOSSCompressOptions {
|
|
|
29
29
|
*/
|
|
30
30
|
allowJPG?: boolean;
|
|
31
31
|
/**
|
|
32
|
-
* 是否允许转换为 WebP
|
|
32
|
+
* 是否允许转换为 WebP。设为 'auto' 时,只要当前浏览器支持 WebP,就进行转换。
|
|
33
33
|
*/
|
|
34
|
-
allowWebP?: boolean;
|
|
34
|
+
allowWebP?: boolean | 'auto';
|
|
35
35
|
/**
|
|
36
36
|
* 是否允许转换为 AVIF。
|
|
37
37
|
*/
|
package/cjs/image.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function
|
|
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}}();
|
package/es/browser.d.ts
CHANGED
package/es/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function isMobile(){const
|
|
1
|
+
export function isMobile(){const t=navigator.userAgent;return!/\(X11[;)]/i.test(t)&&!/\b(Windows\sNT|Macintosh)\b/.test(t)&&/mobile|tablet|android/i.test(t)}export function hasMobileFeature(){const t=navigator.platform;return"onorientationchange"in window&&"number"==typeof window.orientation||(!!/^(iPhone|iPod|iPad)/.test(t)||"Win32"!==t&&!/^Linux\s*(x86|i686)/.test(t)&&("MacIntel"===t||"Macintosh"===t?navigator.maxTouchPoints>0:"function"==typeof matchMedia&&(matchMedia("(hover: none)").matches&&matchMedia("(pointer: coarse)").matches&&!matchMedia("(pointer: fine)").matches)))}export function isMaxthon(){const t=navigator.userAgent;if(/\bMaxthon\b/i.test(t))return!0;if("maxthon"in window){const t=window.maxthon;return"function"==typeof t.IsMaxthon&&t.IsMaxthon()}return!1}export function supportMSEH264(){const t=window.MediaSource;return t&&"function"==typeof t.isTypeSupported&&t.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"')}
|
package/es/image.d.ts
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
* 检查当前浏览器是否支持 WebP 格式。
|
|
7
7
|
* @returns 当前浏览器是否支持 WebP 格式。
|
|
8
8
|
*/
|
|
9
|
-
export declare
|
|
9
|
+
export declare const supportWebP: () => boolean;
|
|
10
10
|
/**
|
|
11
11
|
* 检查当前浏览器是否支持 AVIF 格式(注意,本函数是异步函数)。
|
|
12
12
|
* @returns 当前浏览器是否支持 AVIF 格式。
|
|
13
13
|
*/
|
|
14
|
-
export declare
|
|
14
|
+
export declare const supportAVIF: () => Promise<boolean>;
|
|
15
15
|
/**
|
|
16
16
|
* 压缩选项。
|
|
17
17
|
*/
|
|
@@ -29,9 +29,9 @@ export interface IOSSCompressOptions {
|
|
|
29
29
|
*/
|
|
30
30
|
allowJPG?: boolean;
|
|
31
31
|
/**
|
|
32
|
-
* 是否允许转换为 WebP
|
|
32
|
+
* 是否允许转换为 WebP。设为 'auto' 时,只要当前浏览器支持 WebP,就进行转换。
|
|
33
33
|
*/
|
|
34
|
-
allowWebP?: boolean;
|
|
34
|
+
allowWebP?: boolean | 'auto';
|
|
35
35
|
/**
|
|
36
36
|
* 是否允许转换为 AVIF。
|
|
37
37
|
*/
|
package/es/image.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
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)):""}
|