@polyv/utils 2.10.0-beta.1 → 2.10.0-beta.2

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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  ## 安装
6
6
 
7
7
  ```
8
- npm install @polyv/utils@next
8
+ npm install @polyv/utils
9
9
  ```
10
10
 
11
11
  NPM 包同时提供了 ES 模块以及 CommonJS 模块,分别位于 `es` 和 `cjs` 两个文件夹。它们使用上的区别和优缺点在于:
package/cjs/image.js CHANGED
@@ -1 +1 @@
1
- "use strict";function supportWebP(){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}function supportAVIF(){return 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)}))}function genOssProcessParams(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"),"gif"!==A&&(e.allowAVIF?t+="/format,avif":e.allowWebP?t+="/format,webp/quality,Q_80":e.allowJPG&&(t+="/format,jpg/quality,Q_80")),t}function ossCompress(A,e){var t;if("undefined"!=typeof document){var s=document.createElement("a");s.href=A,t=s}else"function"==typeof URL&&(t=new URL(/^\/\//.test(A)?"https:"+A:A));if(!t)return A;if(-1===["liveimages.videocc.net","vod-assets.videocc.net","polyvschool.videocc.net","img.videocc.net"].indexOf(t.hostname))return A;var o=(t.pathname.split("/").pop()||"").split("."),r=genOssProcessParams(o[o.length-1].toLowerCase(),e);if(r){var n=t.search.replace(/(?:\?|&)x-oss-process=[^&]+/g,"");n+=(-1===n.indexOf("?")?"?":"&")+"x-oss-process=image"+r,t.search=n}return t.href}function compressHTMLImgs(A,e){return A?A.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,(function(A,t,s,o,r){return t+'"'+ossCompress(o,e)+'" data-src="'+o+'"'+r})):""}Object.defineProperty(exports,"__esModule",{value:!0}),exports.supportWebP=supportWebP,exports.supportAVIF=supportAVIF,exports.ossCompress=ossCompress,exports.compressHTMLImgs=compressHTMLImgs;
1
+ "use strict";function supportWebP(){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}function supportAVIF(){return 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)}))}function genOssProcessParams(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"),"gif"!==A&&(e.allowAVIF?t+="/format,avif":e.allowWebP?t+="/format,webp/quality,Q_80":e.allowJPG&&(t+="/format,jpg/quality,Q_80")),t}function ossCompress(A,e){var t;if("undefined"!=typeof document){var s=document.createElement("a");s.href=A,t=s}else"function"==typeof URL&&(t=new URL(/^\/\//.test(A)?"https:"+A:A));if(!t)return A;if(-1===["liveimages.videocc.net","vod-assets.videocc.net","polyvschool.videocc.net","img.videocc.net"].indexOf(t.hostname)||/(?:\?|&)x-oss-process(?:=|&|$)/.test(t.search))return A;var o=(t.pathname.split("/").pop()||"").split("."),r=genOssProcessParams(o[o.length-1].toLowerCase(),e);if(r){var n=t.search;n+=(-1===n.indexOf("?")?"?":"&")+"x-oss-process=image"+r,t.search=n}return t.href}function compressHTMLImgs(A,e){return A?A.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,(function(A,t,s,o,r){return t+'"'+ossCompress(o,e)+'" data-src="'+o+'"'+r})):""}Object.defineProperty(exports,"__esModule",{value:!0}),exports.supportWebP=supportWebP,exports.supportAVIF=supportAVIF,exports.ossCompress=ossCompress,exports.compressHTMLImgs=compressHTMLImgs;
package/es/image.js CHANGED
@@ -1 +1 @@
1
- export function supportWebP(){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}export function supportAVIF(){return 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)}))}function genOssProcessParams(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"),"gif"!==A&&(e.allowAVIF?t+="/format,avif":e.allowWebP?t+="/format,webp/quality,Q_80":e.allowJPG&&(t+="/format,jpg/quality,Q_80")),t}export function ossCompress(A,e){let t;if("undefined"!=typeof document){const e=document.createElement("a");e.href=A,t=e}else"function"==typeof URL&&(t=new URL(/^\/\//.test(A)?"https:"+A:A));if(!t)return A;if(-1===["liveimages.videocc.net","vod-assets.videocc.net","polyvschool.videocc.net","img.videocc.net"].indexOf(t.hostname))return A;const o=(t.pathname.split("/").pop()||"").split("."),s=genOssProcessParams(o[o.length-1].toLowerCase(),e);if(s){let A=t.search.replace(/(?:\?|&)x-oss-process=[^&]+/g,"");A+=(-1===A.indexOf("?")?"?":"&")+"x-oss-process=image"+s,t.search=A}return t.href}export function compressHTMLImgs(A,e){return A?A.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,((A,t,o,s,n)=>t+'"'+ossCompress(s,e)+'" data-src="'+s+'"'+n)):""}
1
+ export function supportWebP(){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}export function supportAVIF(){return 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)}))}function genOssProcessParams(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"),"gif"!==A&&(e.allowAVIF?t+="/format,avif":e.allowWebP?t+="/format,webp/quality,Q_80":e.allowJPG&&(t+="/format,jpg/quality,Q_80")),t}export function ossCompress(A,e){let t;if("undefined"!=typeof document){const e=document.createElement("a");e.href=A,t=e}else"function"==typeof URL&&(t=new URL(/^\/\//.test(A)?"https:"+A:A));if(!t)return A;if(-1===["liveimages.videocc.net","vod-assets.videocc.net","polyvschool.videocc.net","img.videocc.net"].indexOf(t.hostname)||/(?:\?|&)x-oss-process(?:=|&|$)/.test(t.search))return A;const s=(t.pathname.split("/").pop()||"").split("."),o=genOssProcessParams(s[s.length-1].toLowerCase(),e);if(o){let A=t.search;A+=(-1===A.indexOf("?")?"?":"&")+"x-oss-process=image"+o,t.search=A}return t.href}export function compressHTMLImgs(A,e){return A?A.replace(/(<img.*?\ssrc=)(["']?)(.+?)\2(.*?>)/gi,((A,t,s,o,n)=>t+'"'+ossCompress(o,e)+'" data-src="'+o+'"'+n)):""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyv/utils",
3
- "version": "2.10.0-beta.1",
3
+ "version": "2.10.0-beta.2",
4
4
  "description": "Utility functions of Polyv frontend development.",
5
5
  "keywords": [
6
6
  "polyv",