Skip to content
Open
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
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 1.2.0

Comment thread
mvanderkamp marked this conversation as resolved.
- Add multi-format build targets (CJS, ESM, UMD) via Parcel 2, replacing the
single `dist/index.js` bundle.
- Add `"module"` field (`dist/westures.esm.js`) for tree-shaking with modern
bundlers (webpack 5, Rollup, Vite, esbuild).
- Add `"browser"` field (`dist/westures.umd.js`) for direct `<script>` tag
usage; exposes a `window.westures` global.
- Add `"exports"` map with conditional exports so that bundlers and Node.js
automatically receive the correct bundle for their environment.
- Add headless Node.js entry point (`index.headless.js`). Node.js consumers
receive this build automatically via the `"node"` condition in the exports
map; `Region` defaults to `headless: true` so no DOM is required.
- Add `"nodeHeadless"` Parcel target that bundles `index.headless.js` into
`dist/westures.node.cjs.js`.
- Document the three consumption patterns (bundler / script tag / Node.js
headless) in `README.md`.

## 1.1.0

- Switch to docdash for documentation.
Expand Down
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ region.addGesture(pan)
## Table of Contents

- [Overview](#overview)
- [Installation & Import](#installation--import)
- [Basic Usage](#basic-usage)
- [Implementing Custom Gestures](#implementing-custom-gestures)
- [What's Changed](#changes)
Expand Down Expand Up @@ -77,7 +78,57 @@ information about each gesture.
Note that all x,y positions are obtained from the corresponding `clientX` and
`clientY` properties of the input event.

## Basic Usage
## Installation & Import

Install via npm:

```bash
npm install westures
```

The package ships three pre-built bundles and selects the right one
automatically based on your environment:

### Bundler (webpack / Rollup / Vite / esbuild)

Import the ES module build for full tree-shaking support:

```javascript
import { Region, Pan } from 'westures';
```

### Browser — `<script>` tag / CDN

A UMD/IIFE build is available that exposes a `window.westures` global:

```html
<script src="node_modules/westures/dist/westures.umd.js"></script>
<script>
const region = new westures.Region();
</script>
```

### Node.js — headless / server-side

When you `require` or `import` westures in a Node.js process, you
automatically get the **headless** build. In headless mode the `Region` does
not attach DOM event listeners; instead, you feed events to it manually via
`Region.arbitrate(event)`, `Region.cancel(event)`, and
`Region.handleKeyboardEvent(event)`. This makes westures usable in JSDOM,
testing frameworks, and server-side gesture processing.

```javascript
// CommonJS — headless mode is the default in Node.js
const { Region, Pan } = require('westures');

// ES module in Node.js — same headless default
import { Region, Pan } from 'westures';
Comment on lines +124 to +125
```

You can still opt out of headless mode on a per-region basis by passing
`{ headless: false }` to the `Region` constructor.



Comment thread
mvanderkamp marked this conversation as resolved.
- [Declaring a Region](#declaring-a-region)
- [Instantiating a Gesture](#instantiating-a-gesture)
Expand Down
23 changes: 23 additions & 0 deletions index.headless.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

/**
* Headless entry point for Westures. Re-exports everything from the main
* module but provides a Region subclass that defaults `headless: true`.
*
* When imported via the `"node"` condition (i.e. `require('westures')` or
* `import ... from 'westures'` in a Node.js process), consumers get this
* build automatically. They can still override headless mode by passing
* `{ headless: false }` explicitly.
*
* @module westures/headless
*/

const base = require('./index.js');

class Region extends base.Region {
constructor(element, options = {}) {
super(element, { headless: true, ...options });
}
}

module.exports = { ...base, Region };
Comment on lines +15 to +23
46 changes: 45 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,51 @@
"pointer"
],
"source": "index.js",
"main": "dist/index.js",
"main": "dist/westures.cjs.js",
"module": "dist/westures.esm.js",
"browser": "dist/westures.umd.js",
"nodeHeadless": "dist/westures.node.cjs.js",
Comment on lines +25 to +28
"exports": {
".": {
"node": "./dist/westures.node.cjs.js",
"import": "./dist/westures.esm.js",
"require": "./dist/westures.cjs.js",
"browser": "./dist/westures.umd.js"
}
Comment on lines +29 to +35
},
"targets": {
"main": {
"outputFormat": "commonjs",
"isLibrary": true,
"optimize": true,
"engines": {
"node": ">=12"
}
},
"module": {
"outputFormat": "esmodule",
"isLibrary": true,
"optimize": true
},
"browser": {
"outputFormat": "global",
"global": "westures",
"isLibrary": true,
"optimize": true,
"engines": {
"browsers": "> 0.5%, last 2 versions"
}
},
"nodeHeadless": {
"source": "index.headless.js",
"outputFormat": "commonjs",
"isLibrary": true,
"optimize": true,
"engines": {
"node": ">=12"
}
}
},
"directories": {
"test": "test"
},
Expand Down
Loading