@os-design/use-safe-area-inset 1.0.6 → 1.0.9
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/cjs/index.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +7 -6
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["computeSafeAreaInset","res","top","right","bottom","left","Object","keys","reduce","acc","cur","style","getComputedStyle","document","documentElement","getPropertyValue","parseFloat","useSafeAreaInset","useState","safeAreaInset","setSafeAreaInset","updateSafeAreaInset","useCallback","nextSafeAreaInset","JSON","stringify","updateSafeAreaInsetRef","useRef","useEffect","current","useBrowserLayoutEffect","forEach","item","setProperty","useEvent","window","undefined"],"sources":["../../src/index.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport useEvent from '@os-design/use-event';\nimport useBrowserLayoutEffect from '@os-design/use-browser-layout-effect';\n\ninterface UseSafeAreaInsetRes {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\nconst computeSafeAreaInset = () => {\n const res = { top: 0, right: 0, bottom: 0, left: 0 };\n // Get css properties\n return Object.keys(res).reduce<UseSafeAreaInsetRes>((acc, cur) => {\n const style = getComputedStyle(document.documentElement).getPropertyValue(\n `--safe-area-inset-${cur}`\n );\n return { ...acc, [cur]: parseFloat(style) || 0 };\n }, res);\n};\n\nconst useSafeAreaInset = (): UseSafeAreaInsetRes => {\n const [safeAreaInset, setSafeAreaInset] = useState<UseSafeAreaInsetRes>({\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n });\n\n const updateSafeAreaInset = useCallback(() => {\n const nextSafeAreaInset = computeSafeAreaInset();\n if (JSON.stringify(safeAreaInset) === JSON.stringify(nextSafeAreaInset))\n return;\n setSafeAreaInset(nextSafeAreaInset);\n }, [safeAreaInset]);\n\n const updateSafeAreaInsetRef = useRef(updateSafeAreaInset);\n useEffect(() => {\n updateSafeAreaInsetRef.current = updateSafeAreaInset;\n }, [updateSafeAreaInset]);\n\n useBrowserLayoutEffect(() => {\n // Set css properties\n ['top', 'right', 'bottom', 'left'].forEach((item) => {\n document.documentElement.style.setProperty(\n `--safe-area-inset-${item}`,\n `env(safe-area-inset-${item})`\n );\n });\n // Update initial values\n updateSafeAreaInsetRef.current();\n }, []);\n\n useEvent(\n (typeof window !== 'undefined' ? window : undefined) as EventTarget,\n 'scroll',\n updateSafeAreaInset\n );\n\n return safeAreaInset;\n};\n\nexport default useSafeAreaInset;\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;AASA,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAuB,GAAM;EACjC,IAAMC,GAAG,GAAG;IAAEC,GAAG,EAAE,CAAP;IAAUC,KAAK,EAAE,CAAjB;IAAoBC,MAAM,EAAE,CAA5B;IAA+BC,IAAI,EAAE;EAArC,CAAZ,CADiC,CAEjC;;EACA,OAAOC,MAAM,CAACC,IAAP,CAAYN,GAAZ,EAAiBO,MAAjB,CAA6C,UAACC,GAAD,EAAMC,GAAN,EAAc;IAChE,IAAMC,KAAK,GAAGC,gBAAgB,CAACC,QAAQ,CAACC,eAAV,CAAhB,CAA2CC,gBAA3C,6BACSL,GADT,EAAd;IAGA,uCAAYD,GAAZ,2BAAkBC,GAAlB,EAAwBM,UAAU,CAACL,KAAD,CAAV,IAAqB,CAA7C;EACD,CALM,EAKJV,GALI,CAAP;AAMD,CATD;;AAWA,IAAMgB,gBAAgB,GAAG,SAAnBA,gBAAmB,GAA2B;EAClD,gBAA0C,IAAAC,eAAA,EAA8B;IACtEhB,GAAG,EAAE,CADiE;IAEtEC,KAAK,EAAE,CAF+D;IAGtEC,MAAM,EAAE,CAH8D;IAItEC,IAAI,EAAE;EAJgE,CAA9B,CAA1C;EAAA;EAAA,IAAOc,aAAP;EAAA,IAAsBC,gBAAtB;;EAOA,IAAMC,mBAAmB,GAAG,IAAAC,kBAAA,EAAY,YAAM;IAC5C,IAAMC,iBAAiB,GAAGvB,oBAAoB,EAA9C;IACA,IAAIwB,IAAI,CAACC,SAAL,CAAeN,aAAf,MAAkCK,IAAI,CAACC,SAAL,CAAeF,iBAAf,CAAtC,EACE;IACFH,gBAAgB,CAACG,iBAAD,CAAhB;EACD,CAL2B,EAKzB,CAACJ,aAAD,CALyB,CAA5B;EAOA,IAAMO,sBAAsB,GAAG,IAAAC,aAAA,EAAON,mBAAP,CAA/B;EACA,IAAAO,gBAAA,EAAU,YAAM;IACdF,sBAAsB,CAACG,OAAvB,GAAiCR,mBAAjC;EACD,CAFD,EAEG,CAACA,mBAAD,CAFH;EAIA,IAAAS,kCAAA,EAAuB,YAAM;IAC3B;IACA,CAAC,KAAD,EAAQ,OAAR,EAAiB,QAAjB,EAA2B,MAA3B,EAAmCC,OAAnC,CAA2C,UAACC,IAAD,EAAU;MACnDnB,QAAQ,CAACC,eAAT,CAAyBH,KAAzB,CAA+BsB,WAA/B,6BACuBD,IADvB,iCAEyBA,IAFzB;IAID,CALD,EAF2B,CAQ3B;;IACAN,sBAAsB,CAACG,OAAvB;EACD,CAVD,EAUG,EAVH;EAYA,IAAAK,oBAAA,EACG,OAAOC,MAAP,KAAkB,WAAlB,GAAgCA,MAAhC,GAAyCC,SAD5C,EAEE,QAFF,EAGEf,mBAHF;EAMA,OAAOF,aAAP;AACD,CAvCD;;eAyCeF,gB"}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["useCallback","useEffect","useRef","useState","useEvent","useBrowserLayoutEffect","computeSafeAreaInset","res","top","right","bottom","left","Object","keys","reduce","acc","cur","style","getComputedStyle","document","documentElement","getPropertyValue","parseFloat","useSafeAreaInset","safeAreaInset","setSafeAreaInset","updateSafeAreaInset","nextSafeAreaInset","JSON","stringify","updateSafeAreaInsetRef","current","forEach","item","setProperty","window","undefined"],"sources":["../../src/index.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport useEvent from '@os-design/use-event';\nimport useBrowserLayoutEffect from '@os-design/use-browser-layout-effect';\n\ninterface UseSafeAreaInsetRes {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\nconst computeSafeAreaInset = () => {\n const res = { top: 0, right: 0, bottom: 0, left: 0 };\n // Get css properties\n return Object.keys(res).reduce<UseSafeAreaInsetRes>((acc, cur) => {\n const style = getComputedStyle(document.documentElement).getPropertyValue(\n `--safe-area-inset-${cur}`\n );\n return { ...acc, [cur]: parseFloat(style) || 0 };\n }, res);\n};\n\nconst useSafeAreaInset = (): UseSafeAreaInsetRes => {\n const [safeAreaInset, setSafeAreaInset] = useState<UseSafeAreaInsetRes>({\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n });\n\n const updateSafeAreaInset = useCallback(() => {\n const nextSafeAreaInset = computeSafeAreaInset();\n if (JSON.stringify(safeAreaInset) === JSON.stringify(nextSafeAreaInset))\n return;\n setSafeAreaInset(nextSafeAreaInset);\n }, [safeAreaInset]);\n\n const updateSafeAreaInsetRef = useRef(updateSafeAreaInset);\n useEffect(() => {\n updateSafeAreaInsetRef.current = updateSafeAreaInset;\n }, [updateSafeAreaInset]);\n\n useBrowserLayoutEffect(() => {\n // Set css properties\n ['top', 'right', 'bottom', 'left'].forEach((item) => {\n document.documentElement.style.setProperty(\n `--safe-area-inset-${item}`,\n `env(safe-area-inset-${item})`\n );\n });\n // Update initial values\n updateSafeAreaInsetRef.current();\n }, []);\n\n useEvent(\n (typeof window !== 'undefined' ? window : undefined) as EventTarget,\n 'scroll',\n updateSafeAreaInset\n );\n\n return safeAreaInset;\n};\n\nexport default useSafeAreaInset;\n"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,MAAjC,EAAyCC,QAAzC,QAAyD,OAAzD;AACA,OAAOC,QAAP,MAAqB,sBAArB;AACA,OAAOC,sBAAP,MA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sB,CAAC,MAAM;IAC3B;IACA,CAAC,KAAD,EAAQ,OAAR,EAAiB,QAAjB,EAA2B,MAA3B,EAAmC2B,OAAnC,CAA4CC,IAAD,IAAU;MACnDd,QAAQ,CAACC,eAAT,CAAyBH,KAAzB,CAA+BiB,WAA/B,CACG,qBAAoBD,IAAK,EAD5B,EAEG,uBAAsBA,IAAK,GAF9B;IAID,CALD,EAF2B,CAQ3B;;IACAH,sBAAsB,CAACC,OAAvB;EACD,CAVqB,EAUnB,EAVmB,CAAtB;EAYA3B,QAAQ,CACL,OAAO+B,MAAP,KAAkB,WAAlB,GAAgCA,MAAhC,GAAyCC,SADpC,EAEN,QAFM,EAGNV,mBAHM,CAAR;EAMA,OAAOF,aAAP;AACD,CAvCD;;AAyCA,eAAeD,gBAAf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@os-design/use-safe-area-inset",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": "git@gitlab.com:os-team/libs/os-design.git",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"require": "./dist/cjs/index.js",
|
|
12
12
|
"default": "./dist/esm/index.js"
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"dist"
|
|
@@ -28,11 +29,11 @@
|
|
|
28
29
|
"access": "public"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@os-design/use-browser-layout-effect": "^1.0.
|
|
32
|
-
"@os-design/use-event": "^1.0.
|
|
32
|
+
"@os-design/use-browser-layout-effect": "^1.0.7",
|
|
33
|
+
"@os-design/use-event": "^1.0.8"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
|
-
"react": ">=
|
|
36
|
+
"react": ">=18"
|
|
36
37
|
},
|
|
37
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "6920c75ea791cbb8edc94c2dd506183d41ffeac6"
|
|
38
39
|
}
|