@companix/utils-browser 0.0.17 → 0.0.18
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/dist/boot-guard.d.ts +7 -0
- package/dist/bundle.cjs.js +1 -1
- package/dist/bundle.esm.js +1 -1
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/bundle.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("axios");const t=(e,o)=>{if(o(e),e.children)for(const
|
|
1
|
+
"use strict";var e=require("axios");const t=(e,o)=>{if(o(e),e.children)for(const n of Array.from(e.children))"DIV"===n.tagName&&t(n,o)},o="undefined"!=typeof window&&!!window.document&&!!window.document.createElement,n=o&&!!window.addEventListener;function s(e){return e?e.replace(/([.*+?^${}()|[\]\/\\])/g,"\\$1"):""}class r{regexp;map;constructor(e){this.map=e}build(){if(this.regexp)return;const e=`(?:${Object.keys(this.map).map(s).sort((e,t)=>t.length-e.length).join("|")})`;this.regexp=new RegExp(e,"g")}replace(e){return e?(this.build(),e.replace(this.regexp,e=>this.map[e])):""}}const i=new r({"&":"&","<":"<",">":">","'":"'",'"':"""}),a=new r({"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'});function c(e){e||(e=o?navigator.userAgent:"");const t=O(e=e.toLowerCase()),n=t||e.includes("ipad"),s=!n&&-1!==e.search(/iphone|ipod/),r=s||n;let i=r&&e.match(/os ([\d_]+) like mac os x/i),a=0,c=0;t?(a=13,c=0):i&&(i=i[1].split("_"),a=+i[0],c=+i[1]),i=null;const d=a<13&&!(11===a&&c<3),h=r&&function(e){if(!o)return!1;const t=window.webkit;if(t&&t.messageHandlers)return!0;const n=/constructor/i.test(String(window.HTMLElement)),s=!!window.indexedDB;if(e.includes("safari")&&e.includes("version")&&!navigator.standalone);else if(!s&&n||!window.statusbar||!window.statusbar.visible);else if(!n||s)return!0;return!1}(e);let u=!1;o&&(u=r&&375===window.screen.width&&812===window.screen.height&&3===window.devicePixelRatio);return{isIPad:n,isIPhone:s,isIOS:r,isIPadOS:t,iosMajor:a,iosMinor:c,isWKWebView:h,isScrollBasedViewport:d,isIPhoneX:u,isIOSChrome:-1!==e.search(/crios/i)}}const d=c(),h=d.isIPad,u=d.isIPhone,p=d.isIOS,l=d.isIPadOS,m=d.iosMajor,x=d.iosMinor,g=d.isWKWebView,w=d.isScrollBasedViewport,f=d.isIPhoneX,E=d.isIOSChrome;function O(e){if(!o)return!1;const t=!/ipPad|iPhone|iPod/i.test(e),n=/Mac OS/i.test(e);return t&&n&&"ontouchend"in document}const T=(()=>{const e={hasMouse:!1,hasTouchEvents:!1,hasHover:!1,hasTouch:!1};if(!o)return e;if(p&&!l)e.hasMouse=!1,e.hasHover=!1,e.hasTouchEvents=!0,e.hasTouch=!0;else if(e.hasTouchEvents="ontouchstart"in document,e.hasTouch=e.hasTouchEvents||"maxTouchPoints"in navigator&&navigator.maxTouchPoints>0,e.hasTouch){const t=!/android|mobile|tablet/i.test(navigator.userAgent);e.hasMouse="function"==typeof window.matchMedia&&window.matchMedia("(pointer)").matches?matchMedia("(pointer: fine)").matches:t,e.hasHover=e.hasMouse&&("function"==typeof window.matchMedia&&window.matchMedia("(hover)").matches?matchMedia("(hover: hover)").matches:t)}else e.hasMouse=!0,e.hasHover=!0;return e})(),S=T.hasMouse,v=T.hasHover,M=T.hasTouchEvents,b=T.hasTouch;const I=({response:e})=>{throw e};const y=(e,t={})=>{const o=new FormData;for(const t in e){const n=e[t];Array.isArray(n)?n.forEach(e=>{o.append(t,e)}):n&&o.append(t,n)}for(const e in t)o.append(e,String(t[e]));return o},L=(e="token")=>{const t=localStorage.getItem(e);return t?`Bearer ${t}`:""};exports.Download=async(e,t)=>{const o=document.createElement("a"),n=URL.createObjectURL(e);o.href=n,o.setAttribute("download",t),o.click(),URL.revokeObjectURL(n)},exports.HttpAPI=class{http;handleException;constructor({handleException:t=I,...o}={}){this.http=e.create(o),this.handleException=t}async request(e){const{url:t,body:o={},method:n,config:s={}}=e,r="GET"===n?"params":"data";return this.http({url:t,method:n,[r]:o,...s}).then(({data:e})=>e).catch(this.handleException)}createIORoutesScheme(){return e=>this.useRoutes(e)}useIOFRoutes(e){return(t,o,n,s)=>this.request({method:"POST",url:e+"/"+t.toString(),config:{headers:{"Content-Type":"multipart/form-data; charset=utf-8"},...s},body:y(o,n)})}useIOFLRoutes(e){return(t,o,n)=>this.request({method:"POST",url:e+"/"+t.toString(),config:{headers:{"Content-Type":"multipart/form-data; charset=utf-8"},...n},body:y(o)})}useRoutes(e){const t=this.request.bind(this);return{post:(o,n,s)=>t({method:"POST",url:e+"/"+o.toString(),config:s,body:n}),get:(o,n)=>t({method:"GET",url:e+"/"+o.toString(),body:n}),blob(e,t){return this.post(e,t,{responseType:"arraybuffer"}).then(e=>new Blob([e]))}}}},exports.IOS_NO_KEYBOARD_ALLOWED_OFFSET=70,exports.IPHONE_KEYBOARD_REJECT_OFFSET=180,exports.IPHONE_SAFARI_BOTTOM_BAR=45,exports.IPHONE_X_SAFARI_BOTTOM_BAR=85,exports.attr=e=>e?"":void 0,exports.backgroundImage=e=>({backgroundImage:`url("${e}")`}),exports.bootGuard=e=>{const{assets:t,template:o,reloadWindow:n=3e4,storageKey:s="boot-guard"}=e,r={isBooting:!0,hasFailed:!1},i=()=>{if("loading"===document.readyState)return void document.addEventListener("DOMContentLoaded",i,{once:!0});const e=document.getElementById(o);if(!(e instanceof HTMLTemplateElement))return;const t=e.content.cloneNode(!0),n=t.querySelector("[data-boot-reload]");n?.addEventListener("click",()=>location.reload()),document.body.append(t)};window.addEventListener("error",e=>{const o=(a=e.target)instanceof HTMLScriptElement?a.src:a instanceof HTMLLinkElement&&"stylesheet"===a.rel?a.href:"";var a;if(!r.isBooting||r.hasFailed||!o)return;const{origin:c,pathname:d}=new URL(o,location.href);c===location.origin&&d.startsWith(t)&&(r.hasFailed=!0,(()=>{try{const e=Number(sessionStorage.getItem(s));return!(Date.now()-e<n||(sessionStorage.setItem(s,String(Date.now())),location.reload(),0))}catch{return!1}})()||i())},!0),document.addEventListener("DOMContentLoaded",()=>{r.isBooting=!1})},exports.box=(e=48,t)=>(t||(t=e),{width:t,minWidth:t,minHeight:e,height:e}),exports.callMultiple=(...e)=>(...t)=>e.filter(e=>"function"==typeof e).forEach(e=>e(...t)),exports.canUseDOM=o,exports.canUseEventListeners=n,exports.checkIPadOS=O,exports.clamp=(e,t,o)=>Math.max(t,Math.min(e,o)),exports.contains=(e,t)=>!(!e||!t)&&e.contains(t),exports.customCSS=e=>e,exports.detectIOS=c,exports.escape=function(e){return i.replace(e)},exports.generatePreview=e=>{const t=URL.createObjectURL(e);return{url:t,cleanup:()=>{URL.revokeObjectURL(t)}}},exports.getActiveElementByAnotherElement=e=>e?e.ownerDocument.activeElement:null,exports.getAuthorizationHeaders=(e={})=>({Authorization:L(e.tokenSource)}),exports.getAuthorizationToken=L,exports.getContainers=t,exports.getFiles=e=>Array.from(e),exports.hasHover=v,exports.hasMouse=S,exports.hasTouch=b,exports.hasTouchEvents=M,exports.height=e=>({height:e,minHeight:e,maxHeight:e}),exports.iosMajor=m,exports.iosMinor=x,exports.isElementNode=e=>e.nodeType===Node.ELEMENT_NODE,exports.isHTMLElement=e=>e.nodeType===Node.ELEMENT_NODE,exports.isIOS=p,exports.isIOSChrome=E,exports.isIPad=h,exports.isIPadOS=l,exports.isIPhone=u,exports.isIPhoneX=f,exports.isLandscapePhone=function(){return 90===Math.abs(window.orientation)&&!h},exports.isRetina=function(){return window.devicePixelRatio>=2},exports.isScrollBasedViewport=w,exports.isTextNode=e=>e.nodeType===Node.TEXT_NODE,exports.isWKWebView=g,exports.onDOMLoaded=e=>{"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e)},exports.pc=e=>`${e}%`,exports.px=e=>`${e}px`,exports.setCssVariable=(e,t)=>{document.documentElement.style.setProperty(e,t)},exports.unescape=function(e){return a.replace(e)},exports.width=e=>({width:e,minWidth:e,maxWidth:e});
|
package/dist/bundle.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"axios";const t=e=>`${e}%`,
|
|
1
|
+
import e from"axios";const t=e=>{const{assets:t,template:o,reloadWindow:n=3e4,storageKey:i="boot-guard"}=e,r={isBooting:!0,hasFailed:!1},s=()=>{if("loading"===document.readyState)return void document.addEventListener("DOMContentLoaded",s,{once:!0});const e=document.getElementById(o);if(!(e instanceof HTMLTemplateElement))return;const t=e.content.cloneNode(!0),n=t.querySelector("[data-boot-reload]");n?.addEventListener("click",()=>location.reload()),document.body.append(t)};window.addEventListener("error",e=>{const o=(a=e.target)instanceof HTMLScriptElement?a.src:a instanceof HTMLLinkElement&&"stylesheet"===a.rel?a.href:"";var a;if(!r.isBooting||r.hasFailed||!o)return;const{origin:c,pathname:d}=new URL(o,location.href);c===location.origin&&d.startsWith(t)&&(r.hasFailed=!0,(()=>{try{const e=Number(sessionStorage.getItem(i));return!(Date.now()-e<n||(sessionStorage.setItem(i,String(Date.now())),location.reload(),0))}catch{return!1}})()||s())},!0),document.addEventListener("DOMContentLoaded",()=>{r.isBooting=!1})},o=e=>`${e}%`,n=e=>`${e}px`,i=e=>({width:e,minWidth:e,maxWidth:e}),r=e=>({height:e,minHeight:e,maxHeight:e}),s=(e=48,t)=>(t||(t=e),{width:t,minWidth:t,minHeight:e,height:e}),a=e=>({backgroundImage:`url("${e}")`}),c=(e,t)=>{document.documentElement.style.setProperty(e,t)},d=e=>e,h=e=>e?"":void 0,u=(e,t)=>{if(t(e),e.children)for(const o of Array.from(e.children))"DIV"===o.tagName&&u(o,t)},l="undefined"!=typeof window&&!!window.document&&!!window.document.createElement,m=l&&!!window.addEventListener,p=e=>{"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e)},w=(...e)=>(...t)=>e.filter(e=>"function"==typeof e).forEach(e=>e(...t)),f=e=>e?e.ownerDocument.activeElement:null,g=(e,t)=>!(!e||!t)&&e.contains(t),E=e=>e.nodeType===Node.ELEMENT_NODE,v=e=>e.nodeType===Node.TEXT_NODE,y=e=>e.nodeType===Node.ELEMENT_NODE,b=(e,t,o)=>Math.max(t,Math.min(e,o));function T(e){return e?e.replace(/([.*+?^${}()|[\]\/\\])/g,"\\$1"):""}class M{regexp;map;constructor(e){this.map=e}build(){if(this.regexp)return;const e=`(?:${Object.keys(this.map).map(T).sort((e,t)=>t.length-e.length).join("|")})`;this.regexp=new RegExp(e,"g")}replace(e){return e?(this.build(),e.replace(this.regexp,e=>this.map[e])):""}}const S=new M({"&":"&","<":"<",">":">","'":"'",'"':"""}),L=new M({"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'});function O(e){return S.replace(e)}function x(e){return L.replace(e)}const I=45,P=85,R=180,H=70;function D(e){e||(e=l?navigator.userAgent:"");const t=_(e=e.toLowerCase()),o=t||e.includes("ipad"),n=!o&&-1!==e.search(/iphone|ipod/),i=n||o;let r=i&&e.match(/os ([\d_]+) like mac os x/i),s=0,a=0;t?(s=13,a=0):r&&(r=r[1].split("_"),s=+r[0],a=+r[1]),r=null;const c=s<13&&!(11===s&&a<3),d=i&&function(e){if(!l)return!1;const t=window.webkit;if(t&&t.messageHandlers)return!0;const o=/constructor/i.test(String(window.HTMLElement)),n=!!window.indexedDB;if(e.includes("safari")&&e.includes("version")&&!navigator.standalone);else if(!n&&o||!window.statusbar||!window.statusbar.visible);else if(!o||n)return!0;return!1}(e);let h=!1;l&&(h=i&&375===window.screen.width&&812===window.screen.height&&3===window.devicePixelRatio);return{isIPad:o,isIPhone:n,isIOS:i,isIPadOS:t,iosMajor:s,iosMinor:a,isWKWebView:d,isScrollBasedViewport:c,isIPhoneX:h,isIOSChrome:-1!==e.search(/crios/i)}}const k=D(),N=k.isIPad,B=k.isIPhone,U=k.isIOS,W=k.isIPadOS,j=k.iosMajor,A=k.iosMinor,C=k.isWKWebView,q=k.isScrollBasedViewport,$=k.isIPhoneX,F=k.isIOSChrome;function V(){return 90===Math.abs(window.orientation)&&!N}function _(e){if(!l)return!1;const t=!/ipPad|iPhone|iPod/i.test(e),o=/Mac OS/i.test(e);return t&&o&&"ontouchend"in document}const K=(()=>{const e={hasMouse:!1,hasTouchEvents:!1,hasHover:!1,hasTouch:!1};if(!l)return e;if(U&&!W)e.hasMouse=!1,e.hasHover=!1,e.hasTouchEvents=!0,e.hasTouch=!0;else if(e.hasTouchEvents="ontouchstart"in document,e.hasTouch=e.hasTouchEvents||"maxTouchPoints"in navigator&&navigator.maxTouchPoints>0,e.hasTouch){const t=!/android|mobile|tablet/i.test(navigator.userAgent);e.hasMouse="function"==typeof window.matchMedia&&window.matchMedia("(pointer)").matches?matchMedia("(pointer: fine)").matches:t,e.hasHover=e.hasMouse&&("function"==typeof window.matchMedia&&window.matchMedia("(hover)").matches?matchMedia("(hover: hover)").matches:t)}else e.hasMouse=!0,e.hasHover=!0;return e})(),X=K.hasMouse,G=K.hasHover,z=K.hasTouchEvents,J=K.hasTouch;function Q(){return window.devicePixelRatio>=2}const Y=async(e,t)=>{const o=document.createElement("a"),n=URL.createObjectURL(e);o.href=n,o.setAttribute("download",t),o.click(),URL.revokeObjectURL(n)},Z=e=>{const t=URL.createObjectURL(e);return{url:t,cleanup:()=>{URL.revokeObjectURL(t)}}},ee=e=>Array.from(e),te=({response:e})=>{throw e};class oe{http;handleException;constructor({handleException:t=te,...o}={}){this.http=e.create(o),this.handleException=t}async request(e){const{url:t,body:o={},method:n,config:i={}}=e,r="GET"===n?"params":"data";return this.http({url:t,method:n,[r]:o,...i}).then(({data:e})=>e).catch(this.handleException)}createIORoutesScheme(){return e=>this.useRoutes(e)}useIOFRoutes(e){return(t,o,n,i)=>this.request({method:"POST",url:e+"/"+t.toString(),config:{headers:{"Content-Type":"multipart/form-data; charset=utf-8"},...i},body:ne(o,n)})}useIOFLRoutes(e){return(t,o,n)=>this.request({method:"POST",url:e+"/"+t.toString(),config:{headers:{"Content-Type":"multipart/form-data; charset=utf-8"},...n},body:ne(o)})}useRoutes(e){const t=this.request.bind(this);return{post:(o,n,i)=>t({method:"POST",url:e+"/"+o.toString(),config:i,body:n}),get:(o,n)=>t({method:"GET",url:e+"/"+o.toString(),body:n}),blob(e,t){return this.post(e,t,{responseType:"arraybuffer"}).then(e=>new Blob([e]))}}}}const ne=(e,t={})=>{const o=new FormData;for(const t in e){const n=e[t];Array.isArray(n)?n.forEach(e=>{o.append(t,e)}):n&&o.append(t,n)}for(const e in t)o.append(e,String(t[e]));return o},ie=(e={})=>({Authorization:re(e.tokenSource)}),re=(e="token")=>{const t=localStorage.getItem(e);return t?`Bearer ${t}`:""};export{Y as Download,oe as HttpAPI,H as IOS_NO_KEYBOARD_ALLOWED_OFFSET,R as IPHONE_KEYBOARD_REJECT_OFFSET,I as IPHONE_SAFARI_BOTTOM_BAR,P as IPHONE_X_SAFARI_BOTTOM_BAR,h as attr,a as backgroundImage,t as bootGuard,s as box,w as callMultiple,l as canUseDOM,m as canUseEventListeners,_ as checkIPadOS,b as clamp,g as contains,d as customCSS,D as detectIOS,O as escape,Z as generatePreview,f as getActiveElementByAnotherElement,ie as getAuthorizationHeaders,re as getAuthorizationToken,u as getContainers,ee as getFiles,G as hasHover,X as hasMouse,J as hasTouch,z as hasTouchEvents,r as height,j as iosMajor,A as iosMinor,y as isElementNode,E as isHTMLElement,U as isIOS,F as isIOSChrome,N as isIPad,W as isIPadOS,B as isIPhone,$ as isIPhoneX,V as isLandscapePhone,Q as isRetina,q as isScrollBasedViewport,v as isTextNode,C as isWKWebView,p as onDOMLoaded,o as pc,n as px,c as setCssVariable,x as unescape,i as width};
|
package/dist/index.d.ts
CHANGED