@polyv/utils 2.9.0-beta.2 → 2.9.0

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 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 ossCompress(A,e){var t=document.createElement("a");t.href=A;var s=t.search,o=t.hostname.toLowerCase();if(-1===["liveimages.videocc.net","vod-assets.videocc.net"].indexOf(o)||/(?:\?|&)x-oss-process(?:=|&|$)/.test(s))return A;var r="";return null==e.width&&null==e.height||(r+="/resize",e.width&&(r+=",w_"+e.width),e.height&&(r+=",h_"+e.height),r+=",limit_1"),e.allowAVIF?r+="/format,avif":e.allowWebP&&(r+="/format,webp"),r&&(r="x-oss-process=image"+r,A+=(-1===A.indexOf("?")?"?":"&")+r),A}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 ossCompress(A,e){var t="",s="";if("undefined"!=typeof document){var o=document.createElement("a");o.href=A,t=o.search,s=o.hostname}else if("function"==typeof URL){var r=new URL(/^\/\//.test(A)?"https:"+A:A);t=r.search,s=r.hostname}if(s=s.toLowerCase(),-1===["liveimages.videocc.net","vod-assets.videocc.net","polyvschool.videocc.net","img.videocc.net"].indexOf(s)||/(?:\?|&)x-oss-process(?:=|&|$)/.test(t))return A;var n="";return null==e.width&&null==e.height||(n+="/resize",e.width&&(n+=",w_"+e.width),e.height&&(n+=",h_"+e.height),n+=",limit_1"),e.allowAVIF?n+="/format,avif":e.allowWebP&&(n+="/format,webp"),n&&(n="x-oss-process=image"+n,A+=(-1===A.indexOf("?")?"?":"&")+n),A}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)}))}export function ossCompress(A,e){const t=document.createElement("a");t.href=A;const o=t.search,s=t.hostname.toLowerCase();if(-1===["liveimages.videocc.net","vod-assets.videocc.net"].indexOf(s)||/(?:\?|&)x-oss-process(?:=|&|$)/.test(o))return A;let a="";return null==e.width&&null==e.height||(a+="/resize",e.width&&(a+=",w_"+e.width),e.height&&(a+=",h_"+e.height),a+=",limit_1"),e.allowAVIF?a+="/format,avif":e.allowWebP&&(a+="/format,webp"),a&&(a="x-oss-process=image"+a,A+=(-1===A.indexOf("?")?"?":"&")+a),A}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)):""}
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)}))}export function ossCompress(A,e){let t="",o="";if("undefined"!=typeof document){const e=document.createElement("a");e.href=A,t=e.search,o=e.hostname}else if("function"==typeof URL){const e=new URL(/^\/\//.test(A)?"https:"+A:A);t=e.search,o=e.hostname}if(o=o.toLowerCase(),-1===["liveimages.videocc.net","vod-assets.videocc.net","polyvschool.videocc.net","img.videocc.net"].indexOf(o)||/(?:\?|&)x-oss-process(?:=|&|$)/.test(t))return A;let s="";return null==e.width&&null==e.height||(s+="/resize",e.width&&(s+=",w_"+e.width),e.height&&(s+=",h_"+e.height),s+=",limit_1"),e.allowAVIF?s+="/format,avif":e.allowWebP&&(s+="/format,webp"),s&&(s="x-oss-process=image"+s,A+=(-1===A.indexOf("?")?"?":"&")+s),A}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)):""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyv/utils",
3
- "version": "2.9.0-beta.2",
3
+ "version": "2.9.0",
4
4
  "description": "Utility functions of Polyv frontend development.",
5
5
  "keywords": [
6
6
  "polyv",