@companix/utils-browser 0.0.15 → 0.0.16

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.
@@ -1 +1 @@
1
- "use strict";var e=require("axios");const t=(e,o)=>{if(o(e),e.children)for(const s of Array.from(e.children))"DIV"===s.tagName&&t(s,o)},o="undefined"!=typeof window&&!!window.document&&!!window.document.createElement,s=o&&!!window.addEventListener;function n(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(n).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({"&":"&amp;","<":"&lt;",">":"&gt;","'":"&#39;",'"':"&quot;"}),a=new r({"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"'});function c(e){e||(e=o?navigator.userAgent:"");const t=O(e=e.toLowerCase()),s=t||e.includes("ipad"),n=!s&&-1!==e.search(/iphone|ipod/),r=n||s;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 h=a<13&&!(11===a&&c<3),d=r&&function(e){if(!o)return!1;const t=window.webkit;if(t&&t.messageHandlers)return!0;const s=/constructor/i.test(String(window.HTMLElement)),n=!!window.indexedDB;if(e.includes("safari")&&e.includes("version")&&!navigator.standalone);else if(!n&&s||!window.statusbar||!window.statusbar.visible);else if(!s||n)return!0;return!1}(e);let u=!1;o&&(u=r&&375===window.screen.width&&812===window.screen.height&&3===window.devicePixelRatio);return{isIPad:s,isIPhone:n,isIOS:r,isIPadOS:t,iosMajor:a,iosMinor:c,isWKWebView:d,isScrollBasedViewport:h,isIPhoneX:u,isIOSChrome:-1!==e.search(/crios/i)}}const h=c(),d=h.isIPad,u=h.isIPhone,p=h.isIOS,l=h.isIPadOS,m=h.iosMajor,x=h.iosMinor,w=h.isWKWebView,g=h.isScrollBasedViewport,f=h.isIPhoneX,E=h.isIOSChrome;function O(e){if(!o)return!1;const t=!/ipPad|iPhone|iPod/i.test(e),s=/Mac OS/i.test(e);return t&&s&&"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,I=T.hasTouchEvents,M=T.hasTouch;const b=({response:e})=>{throw e};const P=(e,t={})=>{const o=new FormData;for(const t in e){const s=e[t];Array.isArray(s)?s.forEach(e=>{o.append(t,e)}):o.append(t,s)}for(const e in t)o.append(e,String(t[e]));return o},y=(e,t="token")=>{const o=e??localStorage.getItem(t);return o?`Bearer ${o}`:""};exports.Download=async(e,t)=>{const o=document.createElement("a"),s=URL.createObjectURL(e);o.href=s,o.setAttribute("download",t),o.click(),URL.revokeObjectURL(s)},exports.HttpAPI=class{http;handleException;constructor({handleException:t=b,...o}={}){this.http=e.create(o),this.handleException=t}async request(e){const{url:t,body:o={},method:s,config:n={}}=e,r="GET"===s?"params":"data";return this.http({url:t,method:s,[r]:o,...n}).then(({data:e})=>e).catch(this.handleException)}createIORoutesScheme(){return e=>this.useRoutes(e)}useIOFRoutes(e){return(t,o,s,n)=>this.request({method:"POST",url:e+"/"+t.toString(),config:{headers:{"Content-Type":"multipart/form-data; charset=utf-8"},...n},body:P(o,s)})}useIOFLRoutes(e){return(t,o,s)=>this.request({method:"POST",url:e+"/"+t.toString(),config:{headers:{"Content-Type":"multipart/form-data; charset=utf-8"},...s},body:P(o)})}useRoutes(e){const t=this.request.bind(this);return{post:(o,s,n)=>t({method:"POST",url:e+"/"+o.toString(),config:n,body:s}),get:(o,s)=>t({method:"GET",url:e+"/"+o.toString(),body:s}),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.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=s,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.getAuthToken=y,exports.getContainers=t,exports.getFiles=e=>Array.from(e),exports.getHeaders=({token:e,tokenSource:t}={})=>{const o=y(e,t),s={"Content-Type":"application/json"};return o&&(s.Authorization=o),s},exports.hasHover=v,exports.hasMouse=S,exports.hasTouch=M,exports.hasTouchEvents=I,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=d,exports.isIPadOS=l,exports.isIPhone=u,exports.isIPhoneX=f,exports.isLandscapePhone=function(){return 90===Math.abs(window.orientation)&&!d},exports.isRetina=function(){return window.devicePixelRatio>=2},exports.isScrollBasedViewport=g,exports.isTextNode=e=>e.nodeType===Node.TEXT_NODE,exports.isWKWebView=w,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});
1
+ "use strict";var e=require("axios");const t=(e,o)=>{if(o(e),e.children)for(const s of Array.from(e.children))"DIV"===s.tagName&&t(s,o)},o="undefined"!=typeof window&&!!window.document&&!!window.document.createElement,s=o&&!!window.addEventListener;function n(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(n).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({"&":"&amp;","<":"&lt;",">":"&gt;","'":"&#39;",'"':"&quot;"}),a=new r({"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"'});function c(e){e||(e=o?navigator.userAgent:"");const t=O(e=e.toLowerCase()),s=t||e.includes("ipad"),n=!s&&-1!==e.search(/iphone|ipod/),r=n||s;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 h=a<13&&!(11===a&&c<3),d=r&&function(e){if(!o)return!1;const t=window.webkit;if(t&&t.messageHandlers)return!0;const s=/constructor/i.test(String(window.HTMLElement)),n=!!window.indexedDB;if(e.includes("safari")&&e.includes("version")&&!navigator.standalone);else if(!n&&s||!window.statusbar||!window.statusbar.visible);else if(!s||n)return!0;return!1}(e);let u=!1;o&&(u=r&&375===window.screen.width&&812===window.screen.height&&3===window.devicePixelRatio);return{isIPad:s,isIPhone:n,isIOS:r,isIPadOS:t,iosMajor:a,iosMinor:c,isWKWebView:d,isScrollBasedViewport:h,isIPhoneX:u,isIOSChrome:-1!==e.search(/crios/i)}}const h=c(),d=h.isIPad,u=h.isIPhone,p=h.isIOS,l=h.isIPadOS,m=h.iosMajor,x=h.iosMinor,w=h.isWKWebView,g=h.isScrollBasedViewport,f=h.isIPhoneX,E=h.isIOSChrome;function O(e){if(!o)return!1;const t=!/ipPad|iPhone|iPod/i.test(e),s=/Mac OS/i.test(e);return t&&s&&"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,I=T.hasTouchEvents,M=T.hasTouch;const b=({response:e})=>{throw e};const P=(e,t={})=>{const o=new FormData;for(const t in e){const s=e[t];Array.isArray(s)?s.forEach(e=>{o.append(t,e)}):s&&o.append(t,s)}for(const e in t)o.append(e,String(t[e]));return o},y=(e,t="token")=>{const o=e??localStorage.getItem(t);return o?`Bearer ${o}`:""};exports.Download=async(e,t)=>{const o=document.createElement("a"),s=URL.createObjectURL(e);o.href=s,o.setAttribute("download",t),o.click(),URL.revokeObjectURL(s)},exports.HttpAPI=class{http;handleException;constructor({handleException:t=b,...o}={}){this.http=e.create(o),this.handleException=t}async request(e){const{url:t,body:o={},method:s,config:n={}}=e,r="GET"===s?"params":"data";return this.http({url:t,method:s,[r]:o,...n}).then(({data:e})=>e).catch(this.handleException)}createIORoutesScheme(){return e=>this.useRoutes(e)}useIOFRoutes(e){return(t,o,s,n)=>this.request({method:"POST",url:e+"/"+t.toString(),config:{headers:{"Content-Type":"multipart/form-data; charset=utf-8"},...n},body:P(o,s)})}useIOFLRoutes(e){return(t,o,s)=>this.request({method:"POST",url:e+"/"+t.toString(),config:{headers:{"Content-Type":"multipart/form-data; charset=utf-8"},...s},body:P(o)})}useRoutes(e){const t=this.request.bind(this);return{post:(o,s,n)=>t({method:"POST",url:e+"/"+o.toString(),config:n,body:s}),get:(o,s)=>t({method:"GET",url:e+"/"+o.toString(),body:s}),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.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=s,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.getAuthToken=y,exports.getContainers=t,exports.getFiles=e=>Array.from(e),exports.getHeaders=({token:e,tokenSource:t}={})=>{const o=y(e,t),s={"Content-Type":"application/json"};return o&&(s.Authorization=o),s},exports.hasHover=v,exports.hasMouse=S,exports.hasTouch=M,exports.hasTouchEvents=I,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=d,exports.isIPadOS=l,exports.isIPhone=u,exports.isIPhoneX=f,exports.isLandscapePhone=function(){return 90===Math.abs(window.orientation)&&!d},exports.isRetina=function(){return window.devicePixelRatio>=2},exports.isScrollBasedViewport=g,exports.isTextNode=e=>e.nodeType===Node.TEXT_NODE,exports.isWKWebView=w,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});
@@ -1 +1 @@
1
- import e from"axios";const t=e=>`${e}%`,o=e=>`${e}px`,n=e=>({width:e,minWidth:e,maxWidth:e}),i=e=>({height:e,minHeight:e,maxHeight:e}),r=(e=48,t)=>(t||(t=e),{width:t,minWidth:t,minHeight:e,height:e}),s=e=>({backgroundImage:`url("${e}")`}),a=(e,t)=>{document.documentElement.style.setProperty(e,t)},c=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)},d="undefined"!=typeof window&&!!window.document&&!!window.document.createElement,l=d&&!!window.addEventListener,m=e=>{"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e)},p=(...e)=>(...t)=>e.filter(e=>"function"==typeof e).forEach(e=>e(...t)),w=e=>e?e.ownerDocument.activeElement:null,f=(e,t)=>!(!e||!t)&&e.contains(t),g=e=>e.nodeType===Node.ELEMENT_NODE,E=e=>e.nodeType===Node.TEXT_NODE,T=e=>e.nodeType===Node.ELEMENT_NODE,b=(e,t,o)=>Math.max(t,Math.min(e,o));function v(e){return e?e.replace(/([.*+?^${}()|[\]\/\\])/g,"\\$1"):""}class y{regexp;map;constructor(e){this.map=e}build(){if(this.regexp)return;const e=`(?:${Object.keys(this.map).map(v).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 M=new y({"&":"&amp;","<":"&lt;",">":"&gt;","'":"&#39;",'"':"&quot;"}),O=new y({"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"'});function S(e){return M.replace(e)}function x(e){return O.replace(e)}const P=45,I=85,L=180,R=70;function k(e){e||(e=d?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),h=i&&function(e){if(!d)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 u=!1;d&&(u=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:h,isScrollBasedViewport:c,isIPhoneX:u,isIOSChrome:-1!==e.search(/crios/i)}}const H=k(),j=H.isIPad,N=H.isIPhone,A=H.isIOS,D=H.isIPadOS,U=H.iosMajor,C=H.iosMinor,W=H.isWKWebView,$=H.isScrollBasedViewport,q=H.isIPhoneX,B=H.isIOSChrome;function V(){return 90===Math.abs(window.orientation)&&!j}function _(e){if(!d)return!1;const t=!/ipPad|iPhone|iPod/i.test(e),o=/Mac OS/i.test(e);return t&&o&&"ontouchend"in document}const F=(()=>{const e={hasMouse:!1,hasTouchEvents:!1,hasHover:!1,hasTouch:!1};if(!d)return e;if(A&&!D)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=F.hasMouse,G=F.hasHover,K=F.hasTouchEvents,z=F.hasTouch;function J(){return window.devicePixelRatio>=2}const Q=async(e,t)=>{const o=document.createElement("a"),n=URL.createObjectURL(e);o.href=n,o.setAttribute("download",t),o.click(),URL.revokeObjectURL(n)},Y=e=>{const t=URL.createObjectURL(e);return{url:t,cleanup:()=>{URL.revokeObjectURL(t)}}},Z=e=>Array.from(e),ee=({response:e})=>{throw e};class te{http;handleException;constructor({handleException:t=ee,...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:oe(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:oe(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 oe=(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)}):o.append(t,n)}for(const e in t)o.append(e,String(t[e]));return o},ne=({token:e,tokenSource:t}={})=>{const o=ie(e,t),n={"Content-Type":"application/json"};return o&&(n.Authorization=o),n},ie=(e,t="token")=>{const o=e??localStorage.getItem(t);return o?`Bearer ${o}`:""};export{Q as Download,te as HttpAPI,R as IOS_NO_KEYBOARD_ALLOWED_OFFSET,L as IPHONE_KEYBOARD_REJECT_OFFSET,P as IPHONE_SAFARI_BOTTOM_BAR,I as IPHONE_X_SAFARI_BOTTOM_BAR,h as attr,s as backgroundImage,r as box,p as callMultiple,d as canUseDOM,l as canUseEventListeners,_ as checkIPadOS,b as clamp,f as contains,c as customCSS,k as detectIOS,S as escape,Y as generatePreview,w as getActiveElementByAnotherElement,ie as getAuthToken,u as getContainers,Z as getFiles,ne as getHeaders,G as hasHover,X as hasMouse,z as hasTouch,K as hasTouchEvents,i as height,U as iosMajor,C as iosMinor,T as isElementNode,g as isHTMLElement,A as isIOS,B as isIOSChrome,j as isIPad,D as isIPadOS,N as isIPhone,q as isIPhoneX,V as isLandscapePhone,J as isRetina,$ as isScrollBasedViewport,E as isTextNode,W as isWKWebView,m as onDOMLoaded,t as pc,o as px,a as setCssVariable,x as unescape,n as width};
1
+ import e from"axios";const t=e=>`${e}%`,o=e=>`${e}px`,n=e=>({width:e,minWidth:e,maxWidth:e}),i=e=>({height:e,minHeight:e,maxHeight:e}),r=(e=48,t)=>(t||(t=e),{width:t,minWidth:t,minHeight:e,height:e}),s=e=>({backgroundImage:`url("${e}")`}),a=(e,t)=>{document.documentElement.style.setProperty(e,t)},c=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)},d="undefined"!=typeof window&&!!window.document&&!!window.document.createElement,l=d&&!!window.addEventListener,m=e=>{"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e)},p=(...e)=>(...t)=>e.filter(e=>"function"==typeof e).forEach(e=>e(...t)),w=e=>e?e.ownerDocument.activeElement:null,f=(e,t)=>!(!e||!t)&&e.contains(t),g=e=>e.nodeType===Node.ELEMENT_NODE,E=e=>e.nodeType===Node.TEXT_NODE,T=e=>e.nodeType===Node.ELEMENT_NODE,b=(e,t,o)=>Math.max(t,Math.min(e,o));function v(e){return e?e.replace(/([.*+?^${}()|[\]\/\\])/g,"\\$1"):""}class y{regexp;map;constructor(e){this.map=e}build(){if(this.regexp)return;const e=`(?:${Object.keys(this.map).map(v).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 M=new y({"&":"&amp;","<":"&lt;",">":"&gt;","'":"&#39;",'"':"&quot;"}),O=new y({"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"'});function S(e){return M.replace(e)}function x(e){return O.replace(e)}const P=45,I=85,L=180,R=70;function k(e){e||(e=d?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),h=i&&function(e){if(!d)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 u=!1;d&&(u=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:h,isScrollBasedViewport:c,isIPhoneX:u,isIOSChrome:-1!==e.search(/crios/i)}}const H=k(),j=H.isIPad,N=H.isIPhone,A=H.isIOS,D=H.isIPadOS,U=H.iosMajor,C=H.iosMinor,W=H.isWKWebView,$=H.isScrollBasedViewport,q=H.isIPhoneX,B=H.isIOSChrome;function V(){return 90===Math.abs(window.orientation)&&!j}function _(e){if(!d)return!1;const t=!/ipPad|iPhone|iPod/i.test(e),o=/Mac OS/i.test(e);return t&&o&&"ontouchend"in document}const F=(()=>{const e={hasMouse:!1,hasTouchEvents:!1,hasHover:!1,hasTouch:!1};if(!d)return e;if(A&&!D)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=F.hasMouse,G=F.hasHover,K=F.hasTouchEvents,z=F.hasTouch;function J(){return window.devicePixelRatio>=2}const Q=async(e,t)=>{const o=document.createElement("a"),n=URL.createObjectURL(e);o.href=n,o.setAttribute("download",t),o.click(),URL.revokeObjectURL(n)},Y=e=>{const t=URL.createObjectURL(e);return{url:t,cleanup:()=>{URL.revokeObjectURL(t)}}},Z=e=>Array.from(e),ee=({response:e})=>{throw e};class te{http;handleException;constructor({handleException:t=ee,...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:oe(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:oe(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 oe=(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},ne=({token:e,tokenSource:t}={})=>{const o=ie(e,t),n={"Content-Type":"application/json"};return o&&(n.Authorization=o),n},ie=(e,t="token")=>{const o=e??localStorage.getItem(t);return o?`Bearer ${o}`:""};export{Q as Download,te as HttpAPI,R as IOS_NO_KEYBOARD_ALLOWED_OFFSET,L as IPHONE_KEYBOARD_REJECT_OFFSET,P as IPHONE_SAFARI_BOTTOM_BAR,I as IPHONE_X_SAFARI_BOTTOM_BAR,h as attr,s as backgroundImage,r as box,p as callMultiple,d as canUseDOM,l as canUseEventListeners,_ as checkIPadOS,b as clamp,f as contains,c as customCSS,k as detectIOS,S as escape,Y as generatePreview,w as getActiveElementByAnotherElement,ie as getAuthToken,u as getContainers,Z as getFiles,ne as getHeaders,G as hasHover,X as hasMouse,z as hasTouch,K as hasTouchEvents,i as height,U as iosMajor,C as iosMinor,T as isElementNode,g as isHTMLElement,A as isIOS,B as isIOSChrome,j as isIPad,D as isIPadOS,N as isIPhone,q as isIPhoneX,V as isLandscapePhone,J as isRetina,$ as isScrollBasedViewport,E as isTextNode,W as isWKWebView,m as onDOMLoaded,t as pc,o as px,a as setCssVariable,x as unescape,n as width};
@@ -28,6 +28,8 @@ export declare class HttpAPI {
28
28
  }
29
29
  type FileParam<T extends AnyFileInput> = T extends FileInput.Single<infer N> ? {
30
30
  [K in N & string]: Blob;
31
+ } : T extends FileInput.SingleOptional<infer N> ? {
32
+ [K in N & string]?: Blob;
31
33
  } : T extends FileInput.Set<infer N> ? {
32
34
  [K in N & string]: Blob[];
33
35
  } : T extends FileInput.Map<infer N> ? {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@companix/utils-browser",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "main": "dist/bundle.cjs.js",
5
5
  "module": "dist/bundle.esm.js",
6
6
  "types": "./dist/index.d.ts",