react-screen-wake-lock
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e||self).reactScreenWakeLock={},e.react)}(this,function(e,r){e.useWakeLock=function(e){var n=void 0===e?{}:e,t=n.onError,o=n.onRequest,u=n.onRelease,c=r.useState(),i=c[0],s=c[1],l=r.useRef(null),a="undefined"!=typeof window&&"wakeLock"in navigator,f=r.useCallback(function(e){void 0===e&&(e="screen");try{if(!a||null!=l.current)return Promise.resolve();var r=function(r,n){try{var t=Promise.resolve(navigator.wakeLock.request(e)).then(function(e){var r;l.current=e,l.current.onrelease=function(e){var r;s(null==(r=l.current&&l.current.released)||r),u&&u(e),l.current=null},null==o||o(),s(null!=(r=l.current&&l.current.released)&&r)})}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(0,function(e){t&&t(e)});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[a,o,t,u]),d=r.useCallback(function(){try{return a&&null!=l.current?Promise.resolve(l.current?Promise.resolve(l.current.release()).then(function(e){}):void 0):Promise.resolve()}catch(e){return Promise.reject(e)}},[a]);return{isSupported:a,request:f,released:i,release:d,type:l.current&&l.current.type||void 0}}}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e||self).reactScreenWakeLock={},e.react)}(this,function(e,r){function t(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var n=/*#__PURE__*/t(r);e.useWakeLock=function(e){var r=void 0===e?{}:e,t=r.onError,o=r.onRequest,u=r.onRelease,c=n.useState(),i=c[0],a=c[1],s=n.useRef(null),l="undefined"!=typeof window&&"wakeLock"in navigator,f=n.useCallback(function(e){void 0===e&&(e="screen");try{if(!l||null!=s.current)return Promise.resolve();var r=function(r,t){try{var n=Promise.resolve(navigator.wakeLock.request(e)).then(function(e){s.current=e,s.current.onrelease=function(e){a(s.current&&s.current.released||!0),u&&u(e),s.current=null},o&&o(),a(s.current&&s.current.released||!1)})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){t&&t(e)});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[l,o,t,u]),d=n.useCallback(function(){try{return l&&null!=s.current?Promise.resolve(s.current?Promise.resolve(s.current.release()).then(function(e){}):void 0):Promise.resolve()}catch(e){return Promise.reject(e)}},[l]);return{isSupported:l,request:f,released:i,release:d,type:s.current&&s.current.type||void 0}}}); | ||
//# sourceMappingURL=react-screen-wake-lock.umd.js.map |
{ | ||
"name": "react-screen-wake-lock", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "React implementation of the Screen Wake Lock API. It provides a way to prevent devices from dimming or locking the screen when an application needs to keep running.", | ||
@@ -28,15 +28,8 @@ "author": { | ||
"sideEffects": false, | ||
"type": "module", | ||
"source": "src/index.ts", | ||
"main": "dist/react-screen-wake-lock.js", | ||
"module": "dist/react-screen-wake-lock.module.js", | ||
"main": "dist/react-screen-wake-lock.cjs", | ||
"exports": "./dist/react-screen-wake-lock.esm.js", | ||
"umd:main": "dist/react-screen-wake-lock.umd.js", | ||
"unpkg": "dist/react-screen-wake-lock.umd.js", | ||
"exports": { | ||
".": { | ||
"browser": "./dist/react-screen-wake-lock.module.js", | ||
"umd": "./dist/react-screen-wake-lock.umd.js", | ||
"import": "./dist/react-screen-wake-lock.module.js", | ||
"require": "./dist/react-screen-wake-lock.js" | ||
} | ||
}, | ||
"typings": "dist/index.d.ts", | ||
@@ -48,16 +41,13 @@ "files": [ | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=14.16" | ||
}, | ||
"scripts": { | ||
"postinstall": "yarn husky install", | ||
"start": "microbundle watch", | ||
"prebuild": "rimraf dist", | ||
"build": "npm-run-all --parallel build:*", | ||
"build:other": "microbundle --define process.env.NODE_ENV=production -f cjs,umd,modern", | ||
"build:other": "microbundle --define process.env.NODE_ENV=production -f cjs,umd", | ||
"build:es": "microbundle -f es", | ||
"test": "jest", | ||
"lint": "eslint --ignore-path .gitignore --ext .ts,.tsx .", | ||
"prepare": "yarn build", | ||
"size": "size-limit", | ||
"analyze": "size-limit --why", | ||
"semantic-release": "semantic-release" | ||
"lint": "eslint --ignore-path .gitignore --ext .ts,.tsx ." | ||
}, | ||
@@ -67,22 +57,3 @@ "peerDependencies": { | ||
}, | ||
"size-limit": [ | ||
{ | ||
"path": "dist/react-screen-wake-lock.js", | ||
"limit": "393 B" | ||
}, | ||
{ | ||
"path": "dist/react-screen-wake-lock.modern.js", | ||
"limit": "314 B" | ||
}, | ||
{ | ||
"path": "dist/react-screen-wake-lock.module.js", | ||
"limit": "415 B" | ||
}, | ||
{ | ||
"path": "dist/react-screen-wake-lock.umd.js", | ||
"limit": "398 B" | ||
} | ||
], | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^4.10.1", | ||
"@testing-library/dom": "^7.30.1", | ||
@@ -92,32 +63,34 @@ "@testing-library/react": "^11.2.5", | ||
"@types/dom-screen-wake-lock": "^1.0.0", | ||
"@types/jest": "^26.0.22", | ||
"@types/jest": "^29.1.1", | ||
"@types/react": "^18.0.13", | ||
"@types/react-dom": "^18.0.5", | ||
"@typescript-eslint/eslint-plugin": "^4.19.0", | ||
"@typescript-eslint/parser": "^4.19.0", | ||
"eslint": "^7.23.0", | ||
"@typescript-eslint/eslint-plugin": "^5.38.1", | ||
"@typescript-eslint/parser": "^5.38.1", | ||
"eslint": "^8.24.0", | ||
"eslint-plugin-react": "^7.23.1", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"eslint-plugin-testing-library": "^3.10.2", | ||
"husky": "^4.3.8", | ||
"jest": "^26.6.3", | ||
"eslint-plugin-testing-library": "^5.7.0", | ||
"jest": "^29.1.2", | ||
"jest-environment-jsdom": "^29.1.2", | ||
"jest-wake-lock-mock": "^1.1.0", | ||
"lint-staged": ">=10.5.4", | ||
"microbundle": "^0.13.0", | ||
"microbundle": "^0.15.1", | ||
"nano-staged": "^0.8.0", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.2.1", | ||
"react": "18.0.0", | ||
"react-dom": "18.0.0", | ||
"react-test-renderer": "18.0.0", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"react-test-renderer": "18.2.0", | ||
"rimraf": "^3.0.2", | ||
"semantic-release": "^17.4.2", | ||
"size-limit": "^4.10.1", | ||
"tiny-warning": "^1.0.3", | ||
"ts-jest": "^26.5.4", | ||
"ts-jest": "^29.0.3", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.2.3" | ||
}, | ||
"lint-staged": { | ||
"nano-staged": { | ||
"*.{ts,tsx}": "eslint --fix", | ||
"*.{js,css,md}": "prettier --write" | ||
}, | ||
"dependencies": { | ||
"husky": "^8.0.1" | ||
} | ||
} |
@@ -1,43 +0,55 @@ | ||
<h1 align="center">Welcome to react-screen-wake-lock ๐</h1> | ||
<p> | ||
<img alt="npm" src="https://img.shields.io/npm/v/react-screen-wake-lock?style=for-the-badge"> | ||
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/jorisre/react-screen-wake-lock/CI?style=for-the-badge"> | ||
<img alt="Codecov" src="https://img.shields.io/codecov/c/github/jorisre/react-screen-wake-lock?style=for-the-badge"> | ||
<a href="https://bundlephobia.com/result?p=react-screen-wake-lock"> | ||
<img src="https://img.shields.io/bundlephobia/minzip/react-screen-wake-lock?style=for-the-badge" /> | ||
</a> | ||
<a href="https://twitter.com/_jorisre" target="_blank"> | ||
<img alt="Twitter: _jorisre" src="https://img.shields.io/twitter/follow/_jorisre.svg?style=for-the-badge" /> | ||
</a> | ||
<div align="center"><h1>๐ react-screen-wake-lock</h1></div> | ||
<p align="center"> | ||
Tiniest React implementation of the Screen Wake Lock API. <br/>It provides a way to prevent devices from dimming or locking the screen when an application needs to keep running. | ||
</p> | ||
> React implementation of the [Screen Wake Lock API](https://w3c.github.io/screen-wake-lock/). It provides a way to prevent devices from dimming or locking the screen when an application needs to keep running. | ||
<br /> | ||
<p align="center"> | ||
<a href="react-screen-wake-lock.vercel.app/">Demo</a> | ||
<span> ยท </span> | ||
<a href="https://github.com/jorisre/react-screen-wake-lock#installation">Documentation</a> | ||
<span> ยท </span> | ||
<a href="https://twitter.com/_jorisre">Twitter</a> | ||
<sub>Created by <a href="https://joris.re">Joris</a></sub> | ||
</p> | ||
### ๐ [Homepage](https://github.com/jorisre/react-screen-wake-lock#readme) | ||
## Features | ||
### โจ [Demo](https://react-screen-wake-lock.vercel.app/) | ||
- ๐ Follows the **[W3C Screen Wake Lock API specifications](https://w3c.github.io/screen-wake-lock/)** | ||
- ๐ฃ **Easy to use** - just one react hook `useWakeLock` | ||
- ๐ชถ **Lightweight** - _less than **[370b](https://bundlephobia.com/result?p=react-screen-wake-lock)**_ | ||
- ๐ **Easily integration** - _it works without additional configuration (React, remix, Next.js...)_ | ||
- โ ๏ธ **Browser Support** - [Screen Wake Lock API](https://caniuse.com/wake-lock) | ||
## Browser support [Screen Wake Lock API](https://caniuse.com/wake-lock) | ||
<details> | ||
<summary> <code>react-screen-wake-lock</code> use native Screen Wake Lock API under the hood which is not supported by all browsers.</summary> | ||
<a href="https://caniuse.com/wake-lock"> | ||
<picture> | ||
<source type="image/webp" srcset="https://caniuse.bitsofco.de/image/wake-lock.webp" width="600px"> | ||
<source type="image/png" srcset="https://caniuse.bitsofco.de/image/wake-lock.png" width="600px"> | ||
<img src="https://caniuse.bitsofco.de/image/wake-lock.jpg" alt="Data on support for the wake-lock feature across the major browsers from caniuse.com" width="600px"> | ||
</picture> | ||
</a> | ||
</details> | ||
`react-screen-wake-lock` use native Screen Wake Lock API under the hood which is not supported by all browsers. | ||
### Examples (<a href="https://react-screen-wake-lock.joris.re">Demo</a>) | ||
<a href="https://caniuse.com/wake-lock"> | ||
<picture> | ||
<source type="image/webp" srcset="https://caniuse.bitsofco.de/image/wake-lock.webp" width="600px"> | ||
<source type="image/png" srcset="https://caniuse.bitsofco.de/image/wake-lock.png" width="600px"> | ||
<img src="https://caniuse.bitsofco.de/image/wake-lock.jpg" alt="Data on support for the wake-lock feature across the major browsers from caniuse.com" width="600px"> | ||
</picture> | ||
</a> | ||
- [Basic](https://github.com/jorisre/react-screen-wake-lock#usage) | ||
- [Demo example](https://github.com/jorisre/react-screen-wake-lock/blob/main/example/src/App.tsx) | ||
## Install | ||
## Installation | ||
```sh | ||
npm i react-screen-wake-lock | ||
# or | ||
yarn add react-screen-wake-lock | ||
``` | ||
or | ||
```sh | ||
npm i react-screen-wake-lock | ||
``` | ||
## Usage | ||
```jsx | ||
```tsx | ||
import { useWakeLock } from 'react-screen-wake-lock'; | ||
@@ -72,5 +84,5 @@ | ||
### Options | ||
## Props | ||
| Option | description | default | required | | ||
| Prop | description | default | required | | ||
| :---------: | :-----------------------------------------------------------: | :---------: | :------: | | ||
@@ -83,4 +95,4 @@ | `onRequest` | called on successfully `navigator.wakeLock.request` | `undefined` | false | | ||
| Name | description | type | | ||
| :-----------: | :-----------------------------------------------------------------------------------: | :------: | | ||
| Prop | description | type | | | ||
| :-----------: | :-----------------------------------------------------------------------------------: | :------: | --------- | | ||
| `isSupported` | Browser support for the Screen Wake Lock API | boolean | | ||
@@ -97,22 +109,2 @@ | `released` | Once WakeLock is released, `released` become `true` and the value never changes again | boolean | undefined | | ||
๐ค **Joris** | ||
- Twitter: [@\_jorisre](https://twitter.com/_jorisre) | ||
- Github: [@jorisre](https://github.com/jorisre) | ||
## ๐ค Contributing | ||
Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/jorisre/react-screen-wake-lock/issues). You can also take a look at the [contributing guide](https://github.com/jorisre/react-screen-wake-lock/blob/master/CONTRIBUTING.md) and [code of conduct](https://github.com/jorisre/react-screen-wake-lock/blob/master/CODE_OF_CONDUCT.md). | ||
## Show your support | ||
Give a โญ๏ธ if this project helped you! | ||
## ๐ License | ||
Copyright ยฉ 2020 [Joris](https://github.com/jorisre).<br /> | ||
This project is [MIT](https://github.com/jorisre/react-screen-wake-lock/blob/master/LICENSE) licensed. | ||
--- | ||
_This README was generated with โค๏ธ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_ | ||
**๐ [Joris](https://github.com/jorisre)** ยท [@\_jorisre](https://twitter.com/_jorisre) |
@@ -41,3 +41,3 @@ import * as React from 'react'; | ||
// Default to `true` - `released` API is experimental: https://caniuse.com/mdn-api_wakelocksentinel_released | ||
setReleased((wakeLock.current && wakeLock.current.released) ?? true); | ||
setReleased((wakeLock.current && wakeLock.current.released) || true); | ||
onRelease && onRelease(e); | ||
@@ -47,5 +47,5 @@ wakeLock.current = null; | ||
onRequest?.(); | ||
setReleased((wakeLock.current && wakeLock.current.released) ?? false); | ||
} catch (error) { | ||
onRequest && onRequest(); | ||
setReleased((wakeLock.current && wakeLock.current.released) || false); | ||
} catch (error: any) { | ||
onError && onError(error); | ||
@@ -52,0 +52,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
28
Yes
28385
2
13
105
108
1
+ Addedhusky@^8.0.1
+ Addedhusky@8.0.3(transitive)