@companix/utils-browser 0.0.1

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.
@@ -0,0 +1 @@
1
+ "use strict";const e=(t,o)=>{if(o(t),t.children)for(const s of Array.from(t.children))"DIV"===s.tagName&&e(s,o)},t="undefined"!=typeof window&&!!window.document&&!!window.document.createElement,o=t&&!!window.addEventListener;function s(e){e||(e=t?navigator.userAgent:"");const o=w(e=e.toLowerCase()),s=o||e.includes("ipad"),i=!s&&-1!==e.search(/iphone|ipod/),n=i||s;let r=n&&e.match(/os ([\d_]+) like mac os x/i),a=0,h=0;o?(a=13,h=0):r&&(r=r[1].split("_"),a=+r[0],h=+r[1]),r=null;const c=a<13&&!(11===a&&h<3),d=n&&function(e){if(!t)return!1;const o=window.webkit;if(o&&o.messageHandlers)return!0;const s=/constructor/i.test(String(window.HTMLElement)),i=!!window.indexedDB;if(e.includes("safari")&&e.includes("version")&&!navigator.standalone);else if(!i&&s||!window.statusbar||!window.statusbar.visible);else if(!s||i)return!0;return!1}(e);let u=!1;t&&(u=n&&375===window.screen.width&&812===window.screen.height&&3===window.devicePixelRatio);return{isIPad:s,isIPhone:i,isIOS:n,isIPadOS:o,iosMajor:a,iosMinor:h,isWKWebView:d,isScrollBasedViewport:c,isIPhoneX:u,isIOSChrome:-1!==e.search(/crios/i)}}const i=s(),n=i.isIPad,r=i.isIPhone,a=i.isIOS,h=i.isIPadOS,c=i.iosMajor,d=i.iosMinor,u=i.isWKWebView,p=i.isScrollBasedViewport,x=i.isIPhoneX,l=i.isIOSChrome;function w(e){if(!t)return!1;const o=!/ipPad|iPhone|iPod/i.test(e),s=/Mac OS/i.test(e);return o&&s&&"ontouchend"in document}const m=(()=>{const e={hasMouse:!1,hasTouchEvents:!1,hasHover:!1,hasTouch:!1};if(!t)return e;if(a&&!h)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})(),M=m.hasMouse,v=m.hasHover,E=m.hasTouchEvents,f=m.hasTouch;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=t,exports.canUseEventListeners=o,exports.capitalize=e=>e[0].toUpperCase()+e.slice(1),exports.checkIPadOS=w,exports.clamp=(e,t,o)=>Math.max(t,Math.min(e,o)),exports.contains=(e,t)=>!(!e||!t)&&e.contains(t),exports.detectIOS=s,exports.getActiveElementByAnotherElement=e=>e?e.ownerDocument.activeElement:null,exports.getContainers=e,exports.hasHover=v,exports.hasMouse=M,exports.hasTouch=f,exports.hasTouchEvents=E,exports.height=e=>({height:e,minHeight:e,maxHeight:e}),exports.iosMajor=c,exports.iosMinor=d,exports.isHTMLElement=e=>e.nodeType===Node.ELEMENT_NODE,exports.isIOS=a,exports.isIOSChrome=l,exports.isIPad=n,exports.isIPadOS=h,exports.isIPhone=r,exports.isIPhoneX=x,exports.isLandscapePhone=function(){return 90===Math.abs(window.orientation)&&!n},exports.isRetina=function(){return window.devicePixelRatio>=2},exports.isScrollBasedViewport=p,exports.isWKWebView=u,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.varToStyle=e=>e,exports.width=e=>({width:e,minWidth:e,maxWidth:e});
@@ -0,0 +1 @@
1
+ const e=e=>`${e}%`,i=e=>`${e}px`,o=e=>({width:e,minWidth:e,maxWidth:e}),t=e=>({height:e,minHeight:e,maxHeight:e}),n=(e=48,i)=>(i||(i=e),{width:i,minWidth:i,minHeight:e,height:e}),s=e=>({backgroundImage:`url("${e}")`}),a=(e,i)=>{document.documentElement.style.setProperty(e,i)},r=e=>e,h=e=>e[0].toUpperCase()+e.slice(1),c=e=>e?"":void 0,d=(e,i)=>{if(i(e),e.children)for(const o of Array.from(e.children))"DIV"===o.tagName&&d(o,i)},u="undefined"!=typeof window&&!!window.document&&!!window.document.createElement,w=u&&!!window.addEventListener,m=e=>{"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e)},l=(...e)=>(...i)=>e.filter(e=>"function"==typeof e).forEach(e=>e(...i)),f=e=>e?e.ownerDocument.activeElement:null,v=(e,i)=>!(!e||!i)&&e.contains(i),M=e=>e.nodeType===Node.ELEMENT_NODE,g=(e,i,o)=>Math.max(i,Math.min(e,o)),p=45,E=85,P=180,T=70;function I(e){e||(e=u?navigator.userAgent:"");const i=k(e=e.toLowerCase()),o=i||e.includes("ipad"),t=!o&&-1!==e.search(/iphone|ipod/),n=t||o;let s=n&&e.match(/os ([\d_]+) like mac os x/i),a=0,r=0;i?(a=13,r=0):s&&(s=s[1].split("_"),a=+s[0],r=+s[1]),s=null;const h=a<13&&!(11===a&&r<3),c=n&&function(e){if(!u)return!1;const i=window.webkit;if(i&&i.messageHandlers)return!0;const o=/constructor/i.test(String(window.HTMLElement)),t=!!window.indexedDB;if(e.includes("safari")&&e.includes("version")&&!navigator.standalone);else if(!t&&o||!window.statusbar||!window.statusbar.visible);else if(!o||t)return!0;return!1}(e);let d=!1;u&&(d=n&&375===window.screen.width&&812===window.screen.height&&3===window.devicePixelRatio);return{isIPad:o,isIPhone:t,isIOS:n,isIPadOS:i,iosMajor:a,iosMinor:r,isWKWebView:c,isScrollBasedViewport:h,isIPhoneX:d,isIOSChrome:-1!==e.search(/crios/i)}}const x=I(),S=x.isIPad,b=x.isIPhone,H=x.isIOS,y=x.isIPadOS,O=x.iosMajor,W=x.iosMinor,L=x.isWKWebView,C=x.isScrollBasedViewport,D=x.isIPhoneX,V=x.isIOSChrome;function N(){return 90===Math.abs(window.orientation)&&!S}function k(e){if(!u)return!1;const i=!/ipPad|iPhone|iPod/i.test(e),o=/Mac OS/i.test(e);return i&&o&&"ontouchend"in document}const A=(()=>{const e={hasMouse:!1,hasTouchEvents:!1,hasHover:!1,hasTouch:!1};if(!u)return e;if(H&&!y)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 i=!/android|mobile|tablet/i.test(navigator.userAgent);e.hasMouse="function"==typeof window.matchMedia&&window.matchMedia("(pointer)").matches?matchMedia("(pointer: fine)").matches:i,e.hasHover=e.hasMouse&&("function"==typeof window.matchMedia&&window.matchMedia("(hover)").matches?matchMedia("(hover: hover)").matches:i)}else e.hasMouse=!0,e.hasHover=!0;return e})(),B=A.hasMouse,$=A.hasHover,_=A.hasTouchEvents,j=A.hasTouch;function K(){return window.devicePixelRatio>=2}export{T as IOS_NO_KEYBOARD_ALLOWED_OFFSET,P as IPHONE_KEYBOARD_REJECT_OFFSET,p as IPHONE_SAFARI_BOTTOM_BAR,E as IPHONE_X_SAFARI_BOTTOM_BAR,c as attr,s as backgroundImage,n as box,l as callMultiple,u as canUseDOM,w as canUseEventListeners,h as capitalize,k as checkIPadOS,g as clamp,v as contains,I as detectIOS,f as getActiveElementByAnotherElement,d as getContainers,$ as hasHover,B as hasMouse,j as hasTouch,_ as hasTouchEvents,t as height,O as iosMajor,W as iosMinor,M as isHTMLElement,H as isIOS,V as isIOSChrome,S as isIPad,y as isIPadOS,b as isIPhone,D as isIPhoneX,N as isLandscapePhone,K as isRetina,C as isScrollBasedViewport,L as isWKWebView,m as onDOMLoaded,e as pc,i as px,a as setCssVariable,r as varToStyle,o as width};
package/dist/css.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ export declare const pc: (n: number) => string;
2
+ export declare const px: (n: number) => string;
3
+ export declare const width: (w: number) => {
4
+ width: number;
5
+ minWidth: number;
6
+ maxWidth: number;
7
+ };
8
+ export declare const height: (h: number) => {
9
+ height: number;
10
+ minHeight: number;
11
+ maxHeight: number;
12
+ };
13
+ export declare const box: (h?: number, w?: number) => {
14
+ width: number;
15
+ minWidth: number;
16
+ minHeight: number;
17
+ height: number;
18
+ };
19
+ export declare const backgroundImage: (source: string) => React.CSSProperties;
20
+ export declare const setCssVariable: (property: string, value: string) => void;
21
+ export declare const varToStyle: (props: Record<string, string | number>) => React.CSSProperties;
22
+ export declare const capitalize: (str: string) => string;
23
+ export declare const attr: (bool?: boolean | null) => "" | undefined;
@@ -0,0 +1,28 @@
1
+ export declare const IPHONE_SAFARI_BOTTOM_BAR = 45;
2
+ export declare const IPHONE_X_SAFARI_BOTTOM_BAR = 85;
3
+ export declare const IPHONE_KEYBOARD_REJECT_OFFSET = 180;
4
+ export declare const IOS_NO_KEYBOARD_ALLOWED_OFFSET = 70;
5
+ export declare function detectIOS(ua?: string): {
6
+ isIPad: boolean;
7
+ isIPhone: boolean;
8
+ isIOS: boolean;
9
+ isIPadOS: boolean;
10
+ iosMajor: number;
11
+ iosMinor: number;
12
+ isWKWebView: boolean;
13
+ isScrollBasedViewport: boolean;
14
+ isIPhoneX: boolean;
15
+ isIOSChrome: boolean;
16
+ };
17
+ export declare const isIPad: boolean;
18
+ export declare const isIPhone: boolean;
19
+ export declare const isIOS: boolean;
20
+ export declare const isIPadOS: boolean;
21
+ export declare const iosMajor: number;
22
+ export declare const iosMinor: number;
23
+ export declare const isWKWebView: boolean;
24
+ export declare const isScrollBasedViewport: boolean;
25
+ export declare const isIPhoneX: boolean;
26
+ export declare const isIOSChrome: boolean;
27
+ export declare function isLandscapePhone(): boolean;
28
+ export declare function checkIPadOS(ua: string): boolean;
@@ -0,0 +1,4 @@
1
+ export declare const hasMouse: boolean;
2
+ export declare const hasHover: boolean;
3
+ export declare const hasTouchEvents: boolean;
4
+ export declare const hasTouch: boolean;
@@ -0,0 +1,3 @@
1
+ export { IPHONE_SAFARI_BOTTOM_BAR, IPHONE_X_SAFARI_BOTTOM_BAR, IPHONE_KEYBOARD_REJECT_OFFSET, IOS_NO_KEYBOARD_ALLOWED_OFFSET, detectIOS, isIPad, isIPhone, isIOS, isIPadOS, iosMajor, iosMinor, isWKWebView, isScrollBasedViewport, isIPhoneX, isIOSChrome, isLandscapePhone, checkIPadOS } from './IOSDetections';
2
+ export { hasMouse, hasHover, hasTouchEvents, hasTouch } from './InputUtils';
3
+ export { isRetina } from './retina';
@@ -0,0 +1 @@
1
+ export declare function isRetina(): boolean;
@@ -0,0 +1 @@
1
+ export declare const deviceHeightListener: (minWidth: number, varname?: string) => void;
package/dist/dom.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export declare const getContainers: (element: Element, callback: (element: Element) => void) => void;
2
+ export declare const canUseDOM: boolean;
3
+ export declare const canUseEventListeners: boolean;
4
+ export declare const onDOMLoaded: (callback: (...args: any[]) => any) => void;
5
+ export declare const callMultiple: (...fns: any[]) => (...args: any[]) => void;
6
+ export declare const getActiveElementByAnotherElement: (el: Element | null) => Element | null;
7
+ export declare const contains: (parent?: Element | null, child?: Element | null) => boolean;
8
+ export declare const isHTMLElement: (value: any) => value is HTMLElement;
9
+ export declare const clamp: (value: number, min: number, max: number) => number;
@@ -0,0 +1,3 @@
1
+ export * from './css';
2
+ export * from './dom';
3
+ export * from './device/index';
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@companix/utils-browser",
3
+ "version": "0.0.01",
4
+ "main": "dist/bundle.cjs.js",
5
+ "module": "dist/bundle.esm.js",
6
+ "types": "./src/index.ts",
7
+ "author": "Pavel Victorov",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "rm -rf dist && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs"
13
+ },
14
+ "devDependencies": {
15
+ "@types/react": "^18.3.3",
16
+ "rollup": "^4.18.1",
17
+ "rollup-plugin-auto-external": "^2.0.0",
18
+ "@rollup/plugin-json": "^6.1.0",
19
+ "@rollup/plugin-node-resolve": "^15.2.3",
20
+ "@rollup/plugin-strip": "^3.0.4",
21
+ "@rollup/plugin-terser": "^0.4.4",
22
+ "@rollup/plugin-typescript": "^11.1.6"
23
+ }
24
+ }