Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
<script src="https://cdn.jsdelivr.net/npm/@ramstack/pagelock@1.0.0/dist/pagelock.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@ramstack/pagelock@1/dist/pagelock.min.js"></script>
```

## Usage examples
Expand All @@ -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();
Expand Down Expand Up @@ -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;
```
Expand Down
14 changes: 7 additions & 7 deletions src/pagelock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down