diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index da3d263..36a68c2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,7 +19,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: "20" + node-version: "24" registry-url: "https://registry.npmjs.org" - name: Checkout diff --git a/README.md b/README.md index 3acaed5..644a9a2 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,20 @@ -# Pagelock +# @ramstack/pagelock +[![NPM](https://img.shields.io/npm/v/@ramstack/pagelock)](https://www.npmjs.com/package/@ramstack/pagelock) +[![MIT](https://img.shields.io/github/license/rameel/pagelock)](https://github.com/rameel/pagelock/blob/main/LICENSE) -The `@ramstack/pagelock` represents a simple utility for managing page scroll locking. -The library weighs around 750 bytes, and has no external dependencies. +`@ramstack/pagelock` is a simple utility for managing page scroll locking. +The library is around 750 bytes in size and has no external dependencies. ## Installation -### Via NPM +### Using NPM ```sh npm install --save @ramstack/pagelock ``` -### Via CDN +### Using CDN ```html - + ``` ## Usage examples @@ -26,7 +28,7 @@ npm install --save @ramstack/pagelock let release; async function show() { - // Lock the page scroll before show modal dialog + // Lock the page scroll before showing the modal dialog release = pagelock(); await showModal(); @@ -76,23 +78,23 @@ watch(show, value => { ```js /** * Locks the page scroll. Subsequent calls to the function add to the queue of lock holders. - * Page scroll remains locked until the queue is empty. To forcibly release the page scroll, + * The page scroll remains locked until the queue is empty. To forcibly release the page scroll, * bypassing the queue, call the {@link pageunlock} function with `force = true`. * * @returns {() => void} - A function to unlock the page scroll. - * Subsequent calls to the release function are safe and only release its own captured lock, - * without affecting the other locks in the queue. + * Subsequent calls to this release function are safe: it only releases its own lock + * without affecting the others in the queue. */ function pagelock(): () => void; ``` ```js /** - * Unlocks the page scroll. In contrast to the release function returned by {@link pagelock}, - * the {@link pageunlock} function sequentially clears the queue of lock holders. + * Unlocks the page scroll. Unlike the release function returned by {@link pagelock}, + * this function removes locks from the end of the queue (one by one). * - * @param {boolean} [force] - If `true`, forcibly unlocks the page scroll, bypassing the queue; - * otherwise, only the last lock in the queue will be released. The default is `false`. + * @param {boolean} [force] - If `true`, forcibly unlocks the page scroll, clearing the entire queue. + * Otherwise, only the most recent lock is released. Defaults to `false`. */ function pageunlock(force?: boolean): void; ``` diff --git a/src/pagelock.ts b/src/pagelock.ts index 4f44a34..e3cdbe1 100644 --- a/src/pagelock.ts +++ b/src/pagelock.ts @@ -10,12 +10,12 @@ let props: { /** * Locks the page scroll. Subsequent calls to the function add to the queue of lock holders. - * Page scroll remains locked until the queue is empty. To forcibly release the page scroll, + * The page scroll remains locked until the queue is empty. To forcibly release the page scroll, * bypassing the queue, call the {@link pageunlock} function with `force = true`. * * @returns {() => void} - A function to unlock the page scroll. - * Subsequent calls to the release function are safe and only release its own captured lock, - * without affecting the other locks in the queue. + * Subsequent calls to this release function are safe: it only releases its own lock + * without affecting the others in the queue. */ export function pagelock(): () => void { if (!props) { @@ -47,11 +47,11 @@ export function pagelock(): () => void { } /** - * Unlocks the page scroll. In contrast to the release function returned by {@link pagelock}, - * the {@link pageunlock} function sequentially clears the queue of lock holders. + * Unlocks the page scroll. Unlike the release function returned by {@link pagelock}, + * this function removes locks from the end of the queue (one by one). * - * @param {boolean} [force] - If `true`, forcibly unlocks the page scroll, bypassing the queue; - * otherwise, only the last lock in the queue will be released. The default is `false`. + * @param {boolean} [force] - If `true`, forcibly unlocks the page scroll, clearing the entire queue. + * Otherwise, only the most recent lock is released. Defaults to `false`. */ export function pageunlock(force?: boolean): void { force ? locks = [] : locks.pop();