@aarongustafson/pull-to-refresh 0.0.5 → 1.0.1

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/README.md CHANGED
@@ -9,6 +9,11 @@ A lightweight, customizable Web Component that adds pull-to-refresh functionalit
9
9
 
10
10
  [Live Demo](https://aarongustafson.github.io/pull-to-refresh/demo/) ([Source](./demo/index.html))
11
11
 
12
+ ### Additional Demos
13
+
14
+ - [esm.sh CDN](https://aarongustafson.github.io/pull-to-refresh/demo/esm.html) ([Source](./demo/esm.html)) - Loading from esm.sh
15
+ - [unpkg CDN](https://aarongustafson.github.io/pull-to-refresh/demo/unpkg.html) ([Source](./demo/unpkg.html)) - Loading from unpkg
16
+
12
17
  ## Features
13
18
 
14
19
  - **Touch-optimized**: Smooth pull gesture with momentum and feedback
@@ -29,21 +34,31 @@ npm install @aarongustafson/pull-to-refresh
29
34
 
30
35
  ### Usage
31
36
 
32
- **Option 1: Auto-define (easiest)**
37
+ **Option 1: Manual registration**
33
38
  ```javascript
34
- import '@aarongustafson/pull-to-refresh';
39
+ import { PullToRefreshElement } from '@aarongustafson/pull-to-refresh';
40
+
41
+ customElements.define('pull-to-refresh', PullToRefreshElement);
35
42
  ```
36
43
 
37
- **Option 2: Manual registration**
44
+ **Option 2: Auto-define (browser environments only)**
38
45
  ```javascript
39
- import { PullToRefreshElement } from '@aarongustafson/pull-to-refresh/pull-to-refresh.js';
40
- customElements.define('pull-to-refresh', PullToRefreshElement);
46
+ import '@aarongustafson/pull-to-refresh/define.js';
47
+ // Registers <pull-to-refresh> when customElements is available
41
48
  ```
42
49
 
43
- **Option 3: Both (class + auto-define)**
50
+ Prefer to control when registration happens? Call the helper directly:
51
+
44
52
  ```javascript
45
- import { PullToRefreshElement } from '@aarongustafson/pull-to-refresh';
46
- // Element is registered AND class is available
53
+ import { definePullToRefresh } from '@aarongustafson/pull-to-refresh/define.js';
54
+
55
+ definePullToRefresh();
56
+ ```
57
+
58
+ You can also include the guarded script from HTML:
59
+
60
+ ```html
61
+ <script src="./node_modules/@aarongustafson/pull-to-refresh/define.js" type="module"></script>
47
62
  ```
48
63
 
49
64
  ### Basic Example
package/define.js CHANGED
@@ -1,3 +1,18 @@
1
1
  import { PullToRefreshElement } from './pull-to-refresh.js';
2
2
 
3
- customElements.define('pull-to-refresh', PullToRefreshElement);
3
+ export function definePullToRefresh(tagName = 'pull-to-refresh') {
4
+ const hasWindow = typeof window !== 'undefined';
5
+ const registry = hasWindow ? window.customElements : undefined;
6
+
7
+ if (!registry || typeof registry.define !== 'function') {
8
+ return false;
9
+ }
10
+
11
+ if (!registry.get(tagName)) {
12
+ registry.define(tagName, PullToRefreshElement);
13
+ }
14
+
15
+ return true;
16
+ }
17
+
18
+ definePullToRefresh();
package/index.js CHANGED
@@ -1,2 +1 @@
1
1
  export { PullToRefreshElement } from './pull-to-refresh.js';
2
- import './define.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aarongustafson/pull-to-refresh",
3
- "version": "0.0.5",
3
+ "version": "1.0.1",
4
4
  "description": "Web component that enables pull-to-refresh functionality.",
5
5
  "keywords": [
6
6
  "html",
@@ -56,7 +56,8 @@
56
56
  "lint:eslint": "eslint .",
57
57
  "format:eslint": "eslint . --fix",
58
58
  "lint:prettier": "prettier \"**/*.js\" --check --ignore-path .gitignore",
59
- "format:prettier": "prettier \"**/*.js\" --write --ignore-path .gitignore"
59
+ "format:prettier": "prettier \"**/*.js\" --write --ignore-path .gitignore",
60
+ "version": "node scripts/update-demo-versions.js && git add demo/esm.html"
60
61
  },
61
62
  "devDependencies": {
62
63
  "@open-wc/eslint-config": "^13.0.0",
@@ -199,28 +199,14 @@ export class PullToRefreshElement extends HTMLElement {
199
199
  }
200
200
 
201
201
  handleStart(e) {
202
- console.log('[PTR] handleStart', {
203
- type: e.type,
204
- pointerId: e.pointerId,
205
- pointerType: e.pointerType,
206
- clientY: e.clientY,
207
- target: e.target,
208
- });
209
202
  if (
210
203
  this._container.scrollTop === 0 &&
211
204
  !this.isRefreshing &&
212
205
  !this.disabled
213
206
  ) {
214
- console.log('[PTR] Starting pull (pending direction confirmation)');
215
207
  this.isPulling = true;
216
208
  this.isPullingConfirmed = false;
217
209
  this.startY = e.clientY;
218
- } else {
219
- console.log('[PTR] Not starting pull', {
220
- scrollTop: this._container.scrollTop,
221
- isRefreshing: this.isRefreshing,
222
- disabled: this.disabled,
223
- });
224
210
  }
225
211
  }
226
212
 
@@ -229,25 +215,16 @@ export class PullToRefreshElement extends HTMLElement {
229
215
 
230
216
  const deltaY = e.clientY - this.startY;
231
217
 
232
- console.log('[PTR] handleMove', {
233
- clientY: e.clientY,
234
- startY: this.startY,
235
- delta: deltaY,
236
- isPullingConfirmed: this.isPullingConfirmed,
237
- });
238
-
239
218
  // If direction not yet confirmed, check if user is pulling down
240
219
  if (!this.isPullingConfirmed) {
241
220
  // Need some movement to determine direction (at least 5px)
242
221
  if (Math.abs(deltaY) > 5) {
243
222
  if (deltaY < 0) {
244
223
  // Upward pull - cancel the gesture
245
- console.log('[PTR] Upward pull detected, canceling');
246
224
  this.isPulling = false;
247
225
  return;
248
226
  } else {
249
227
  // Downward pull - confirm and proceed
250
- console.log('[PTR] Downward pull confirmed');
251
228
  this.isPullingConfirmed = true;
252
229
 
253
230
  // Prevent text selection during pull if disable-selection is set
@@ -300,11 +277,6 @@ export class PullToRefreshElement extends HTMLElement {
300
277
  }
301
278
 
302
279
  handleEnd() {
303
- console.log('[PTR] handleEnd', {
304
- isPulling: this.isPulling,
305
- currentY: this.currentY,
306
- threshold: this.threshold,
307
- });
308
280
  if (!this.isPulling) return;
309
281
 
310
282
  this.isPulling = false;
@@ -337,7 +309,6 @@ export class PullToRefreshElement extends HTMLElement {
337
309
  }
338
310
 
339
311
  async triggerRefresh() {
340
- console.log('[PTR] triggerRefresh called');
341
312
  this.isRefreshing = true;
342
313
  this._indicator.textContent = this.refreshingText;
343
314
  this._indicator.classList.add('active');