@aarongustafson/pull-to-refresh 1.1.1 → 1.1.3

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.
Files changed (2) hide show
  1. package/README.md +101 -62
  2. package/package.json +5 -3
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Pull to Refresh Web Component
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@aarongustafson/pull-to-refresh.svg)](https://www.npmjs.com/package/@aarongustafson/pull-to-refresh)
4
- [![Build Status](https://img.shields.io/github/actions/workflow/status/aarongustafson/pull-to-refresh/ci.yml?branch=main)](https://github.com/aarongustafson/pull-to-refresh/actions)
4
+ [![CI status](https://img.shields.io/github/actions/workflow/status/aarongustafson/pull-to-refresh/ci.yml?branch=main&label=CI)](https://github.com/aarongustafson/pull-to-refresh/actions/workflows/ci.yml)
5
+ [![Minified + gzipped size](https://img.shields.io/bundlejs/size/@aarongustafson/pull-to-refresh?format=minzip&label=min%2Bgzip)](https://bundlejs.com/?q=@aarongustafson/pull-to-refresh)
6
+ [![License](https://img.shields.io/npm/l/@aarongustafson/pull-to-refresh)](https://github.com/aarongustafson/pull-to-refresh/blob/main/LICENSE)
7
+ [![Type definitions](https://img.shields.io/npm/types/@aarongustafson/pull-to-refresh)](https://github.com/aarongustafson/pull-to-refresh/blob/main/pull-to-refresh.d.ts)
5
8
 
6
9
  A lightweight, customizable Web Component that adds pull-to-refresh functionality to your web applications. Perfect for mobile-first experiences and progressive web apps.
7
10
 
@@ -43,6 +46,7 @@ npm install @aarongustafson/pull-to-refresh
43
46
  ### Usage
44
47
 
45
48
  **Option 1: Manual registration**
49
+
46
50
  ```javascript
47
51
  import { PullToRefreshElement } from '@aarongustafson/pull-to-refresh';
48
52
 
@@ -50,6 +54,7 @@ customElements.define('pull-to-refresh', PullToRefreshElement);
50
54
  ```
51
55
 
52
56
  **Option 2: Auto-define (browser environments only)**
57
+
53
58
  ```javascript
54
59
  import '@aarongustafson/pull-to-refresh/define.js';
55
60
  // Registers <pull-to-refresh> when customElements is available
@@ -66,7 +71,10 @@ definePullToRefresh();
66
71
  You can also include the guarded script from HTML:
67
72
 
68
73
  ```html
69
- <script src="./node_modules/@aarongustafson/pull-to-refresh/define.js" type="module"></script>
74
+ <script
75
+ src="./node_modules/@aarongustafson/pull-to-refresh/define.js"
76
+ type="module"
77
+ ></script>
70
78
  ```
71
79
 
72
80
  ### Basic Example
@@ -87,8 +95,8 @@ You can also include the guarded script from HTML:
87
95
  ptr.addEventListener('ptr:refresh', (e) => {
88
96
  // Perform your refresh logic (fetch data, etc.)
89
97
  fetch('/api/data')
90
- .then(response => response.json())
91
- .then(data => {
98
+ .then((response) => response.json())
99
+ .then((data) => {
92
100
  // Update your content
93
101
  updateContent(data);
94
102
  // Signal completion
@@ -102,15 +110,15 @@ You can also include the guarded script from HTML:
102
110
 
103
111
  ### Attributes
104
112
 
105
- | Attribute | Type | Default | Description |
106
- |-----------|------|---------|-------------|
107
- | `threshold` | number | `80` | Distance in pixels to trigger refresh |
108
- | `indicator-text` | string | localized | Text shown when pulling down |
109
- | `release-text` | string | localized | Text shown when ready to release |
110
- | `refreshing-text` | string | localized | Text shown while refreshing |
111
- | `lang` | string | auto-detected | Language code for localization |
112
- | `disabled` | boolean | `false` | Disables pull-to-refresh functionality |
113
- | `disable-selection` | boolean | `false` | Prevents text selection during pull gesture |
113
+ | Attribute | Type | Default | Description |
114
+ | ------------------- | ------- | ------------- | ------------------------------------------- |
115
+ | `threshold` | number | `80` | Distance in pixels to trigger refresh |
116
+ | `indicator-text` | string | localized | Text shown when pulling down |
117
+ | `release-text` | string | localized | Text shown when ready to release |
118
+ | `refreshing-text` | string | localized | Text shown while refreshing |
119
+ | `lang` | string | auto-detected | Language code for localization |
120
+ | `disabled` | boolean | `false` | Disables pull-to-refresh functionality |
121
+ | `disable-selection` | boolean | `false` | Prevents text selection during pull gesture |
114
122
 
115
123
  **Note:** The text attributes use automatic localization based on the `lang` attribute or auto-detection. See [Localization](#-localization-i18n) below.
116
124
 
@@ -127,13 +135,13 @@ ptr.disabled = true;
127
135
 
128
136
  ### Events
129
137
 
130
- | Event | Detail | Description |
131
- |-------|--------|-------------|
132
- | `ptr:pull-start` | `{}` | Fired when pull gesture starts |
133
- | `ptr:pull-move` | `{ distance: number }` | Fired during pull gesture |
134
- | `ptr:pull-end` | `{}` | Fired when pull gesture ends |
135
- | `ptr:refresh` | `{ complete: Function }` | Fired when refresh is triggered |
136
- | `ptr:refresh-complete` | `{}` | Fired when refresh completes |
138
+ | Event | Detail | Description |
139
+ | ---------------------- | ------------------------ | ------------------------------- |
140
+ | `ptr:pull-start` | `{}` | Fired when pull gesture starts |
141
+ | `ptr:pull-move` | `{ distance: number }` | Fired during pull gesture |
142
+ | `ptr:pull-end` | `{}` | Fired when pull gesture ends |
143
+ | `ptr:refresh` | `{ complete: Function }` | Fired when refresh is triggered |
144
+ | `ptr:refresh-complete` | `{}` | Fired when refresh completes |
137
145
 
138
146
  **Important**: Call `event.detail.complete()` in your `ptr:refresh` handler to signal completion:
139
147
 
@@ -149,25 +157,25 @@ If you don't call `complete()`, the component will auto-complete after 2 seconds
149
157
 
150
158
  ### Slots
151
159
 
152
- | Slot | Description |
153
- |------|-------------|
154
- | (default) | Your scrollable content |
160
+ | Slot | Description |
161
+ | ----------- | --------------------------------- |
162
+ | (default) | Your scrollable content |
155
163
  | `indicator` | Optional custom indicator element |
156
164
 
157
165
  ### CSS Custom Properties
158
166
 
159
- | Property | Default | Description |
160
- |----------|---------|-------------|
161
- | `--ptr-indicator-height` | `3.125rem` | Height of the indicator area |
162
- | `--ptr-indicator-bg` | `ButtonFace` | Background color of indicator |
163
- | `--ptr-indicator-color` | `ButtonText` | Text color of indicator |
164
- | `--ptr-indicator-font-size` | `0.875rem` | Font size of indicator text |
165
- | `--ptr-transition-duration` | `0.2s` | Duration of indicator transitions |
167
+ | Property | Default | Description |
168
+ | --------------------------- | ------------ | --------------------------------- |
169
+ | `--ptr-indicator-height` | `3.125rem` | Height of the indicator area |
170
+ | `--ptr-indicator-bg` | `ButtonFace` | Background color of indicator |
171
+ | `--ptr-indicator-color` | `ButtonText` | Text color of indicator |
172
+ | `--ptr-indicator-font-size` | `0.875rem` | Font size of indicator text |
173
+ | `--ptr-transition-duration` | `0.2s` | Duration of indicator transitions |
166
174
 
167
175
  ### Methods
168
176
 
169
- | Method | Description |
170
- |--------|-------------|
177
+ | Method | Description |
178
+ | ------------------- | -------------------------------------------------------------------------------- |
171
179
  | `completeRefresh()` | Manually complete the refresh (alternative to calling `event.detail.complete()`) |
172
180
 
173
181
  ## Examples
@@ -202,6 +210,7 @@ The component automatically detects the language and displays localized text:
202
210
  ```
203
211
 
204
212
  The component supports 16 languages with automatic fallback to English. Language is detected from:
213
+
205
214
  1. The element's `lang` attribute
206
215
  2. The nearest ancestor's `lang` attribute
207
216
  3. The document's `lang` attribute
@@ -216,8 +225,8 @@ PullToRefreshElement.registerTranslations({
216
225
  'pt-BR': {
217
226
  indicator: '↓ Puxe para atualizar',
218
227
  release: '↻ Solte para atualizar',
219
- refreshing: '⏳ Atualizando...'
220
- }
228
+ refreshing: '⏳ Atualizando...',
229
+ },
221
230
  });
222
231
  ```
223
232
 
@@ -226,8 +235,8 @@ PullToRefreshElement.registerTranslations({
226
235
  ```html
227
236
  <style>
228
237
  pull-to-refresh {
229
- --ptr-indicator-bg: #f0f0f0;
230
- --ptr-indicator-color: #1976d2;
238
+ --ptr-indicator-bg: #102030;
239
+ --ptr-indicator-color: #ffffff;
231
240
  --ptr-indicator-font-size: 1rem;
232
241
  --ptr-indicator-height: 3.75rem;
233
242
  }
@@ -238,13 +247,41 @@ PullToRefreshElement.registerTranslations({
238
247
  </pull-to-refresh>
239
248
  ```
240
249
 
250
+ The indicator defaults to `ButtonText` on `ButtonFace`. Set
251
+ `--ptr-indicator-bg` and `--ptr-indicator-color` together; changing one can
252
+ make the other unreadable. Custom properties override these defaults and
253
+ inherit from the host. A custom slotted indicator supplies its own markup
254
+ and styles. Test your complete pair, including nested text, in each supported
255
+ scheme and user palette. Automatic forced-color adjustment remains enabled.
256
+ The indicator uses different authored or localized messages for pulling,
257
+ release, and loading, rather than color alone.
258
+
259
+ The demos use `CanvasText` on `Canvas` for reading surfaces and status
260
+ messages, `ButtonText` on `ButtonFace` for code and buttons, and
261
+ `MarkText` on `Mark` for marked examples. They preserve native keyboard focus.
262
+ Each standalone demo includes a native Refresh form: enhancement runs the
263
+ existing refresh handler; without JavaScript or a successful module load,
264
+ the form reloads the document. The component does not generate a keyboard
265
+ button. Supply one for tasks that must not depend on a pull gesture.
266
+ Keep existing data visible during loading or failure, provide a readable
267
+ error and retry action, and call `event.detail.complete()` when your handler
268
+ finishes. Completion reports the end of the interaction, not success.
269
+
270
+ Recorded-palette substitution and browser emulation are regression checks,
271
+ not proof of native high-contrast repainting or assistive-technology support.
272
+ The recorded study’s 19 distinct palettes pass the tested demo pairs; bundled
273
+ Ubuntu WebKit has a known dark `ButtonText`/`ButtonFace` contrast limitation
274
+ outside that dataset. The browser suite tracks it as a narrowly scoped expected
275
+ failure instead of replacing every platform’s native pair.
276
+
241
277
  ### Custom Messages
242
278
 
243
279
  ```html
244
280
  <pull-to-refresh
245
281
  indicator-text="⬇ Swipe down"
246
282
  release-text="🔄 Let go!"
247
- refreshing-text="⏳ Loading...">
283
+ refreshing-text="⏳ Loading..."
284
+ >
248
285
  <div>Content here</div>
249
286
  </pull-to-refresh>
250
287
  ```
@@ -292,24 +329,24 @@ ptr.addEventListener('ptr:pull-move', (e) => {
292
329
 
293
330
  The component includes built-in translations for **16 languages**:
294
331
 
295
- | Language | Code | Indicator Text |
296
- |----------|------|----------------|
297
- | English | `en` | ↓ Pull to refresh |
298
- | Chinese (Mandarin) | `zh` | ↓ 下拉刷新 |
299
- | Hindi | `hi` | ↓ रीफ्रेश करने के लिए खींचें |
300
- | Spanish | `es` | ↓ Desliza para actualizar |
301
- | French | `fr` | ↓ Tirez pour actualiser |
302
- | Arabic | `ar` | ↓ اسحب للتحديث |
303
- | Bengali | `bn` | ↓ রিফ্রেশ করতে টানুন |
304
- | Portuguese | `pt` | ↓ Puxe para atualizar |
305
- | Russian | `ru` | ↓ Потяните для обновления |
306
- | Japanese | `ja` | ↓ 引っ張って更新 |
307
- | German | `de` | ↓ Zum Aktualisieren ziehen |
308
- | Punjabi | `pa` | ↓ ਤਾਜ਼ਾ ਕਰਨ ਲਈ ਖਿੱਚੋ |
309
- | Javanese | `jv` | ↓ Tarik kanggo nyegerake |
310
- | Korean | `ko` | ↓ 당겨서 새로고침 |
311
- | Vietnamese | `vi` | ↓ Kéo để làm mới |
312
- | Italian | `it` | ↓ Trascina per aggiornare |
332
+ | Language | Code | Indicator Text |
333
+ | ------------------ | ---- | ---------------------------- |
334
+ | English | `en` | ↓ Pull to refresh |
335
+ | Chinese (Mandarin) | `zh` | ↓ 下拉刷新 |
336
+ | Hindi | `hi` | ↓ रीफ्रेश करने के लिए खींचें |
337
+ | Spanish | `es` | ↓ Desliza para actualizar |
338
+ | French | `fr` | ↓ Tirez pour actualiser |
339
+ | Arabic | `ar` | ↓ اسحب للتحديث |
340
+ | Bengali | `bn` | ↓ রিফ্রেশ করতে টানুন |
341
+ | Portuguese | `pt` | ↓ Puxe para atualizar |
342
+ | Russian | `ru` | ↓ Потяните для обновления |
343
+ | Japanese | `ja` | ↓ 引っ張って更新 |
344
+ | German | `de` | ↓ Zum Aktualisieren ziehen |
345
+ | Punjabi | `pa` | ↓ ਤਾਜ਼ਾ ਕਰਨ ਲਈ ਖਿੱਚੋ |
346
+ | Javanese | `jv` | ↓ Tarik kanggo nyegerake |
347
+ | Korean | `ko` | ↓ 당겨서 새로고침 |
348
+ | Vietnamese | `vi` | ↓ Kéo để làm mới |
349
+ | Italian | `it` | ↓ Trascina per aggiornare |
313
350
 
314
351
  ### Language Detection
315
352
 
@@ -331,20 +368,20 @@ import { PullToRefreshElement } from '@aarongustafson/pull-to-refresh';
331
368
 
332
369
  // Add a new language
333
370
  PullToRefreshElement.registerTranslations({
334
- 'nl': {
371
+ nl: {
335
372
  indicator: '↓ Trek om te vernieuwen',
336
373
  release: '↻ Loslaten om te vernieuwen',
337
- refreshing: '⏳ Vernieuwen...'
338
- }
374
+ refreshing: '⏳ Vernieuwen...',
375
+ },
339
376
  });
340
377
 
341
378
  // Override existing translations
342
379
  PullToRefreshElement.registerTranslations({
343
- 'en': {
380
+ en: {
344
381
  indicator: '⬇ Pull down',
345
382
  release: '🔄 Let go',
346
- refreshing: '⏳ Loading...'
347
- }
383
+ refreshing: '⏳ Loading...',
384
+ },
348
385
  });
349
386
  ```
350
387
 
@@ -356,7 +393,8 @@ You can always override translations for individual instances:
356
393
  <pull-to-refresh
357
394
  lang="es"
358
395
  indicator-text="Custom Spanish text"
359
- release-text="Custom release text">
396
+ release-text="Custom release text"
397
+ >
360
398
  <!-- Content -->
361
399
  </pull-to-refresh>
362
400
  ```
@@ -382,6 +420,7 @@ npm run format # Format code
382
420
  ## Browser Support
383
421
 
384
422
  Works in all modern browsers supporting:
423
+
385
424
  - Custom Elements v1
386
425
  - Shadow DOM v1
387
426
  - ES Modules
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aarongustafson/pull-to-refresh",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Web component that enables pull-to-refresh functionality.",
5
5
  "keywords": [
6
6
  "html",
@@ -56,16 +56,18 @@
56
56
  "test:ui": "vitest --ui",
57
57
  "test:run": "vitest run",
58
58
  "test:coverage": "vitest run --coverage",
59
+ "test:browser": "playwright test",
59
60
  "lint": "npm run lint:eslint && npm run lint:prettier",
60
61
  "format": "npm run format:eslint && npm run format:prettier",
61
62
  "lint:eslint": "eslint .",
62
63
  "format:eslint": "eslint . --fix",
63
- "lint:prettier": "prettier \"**/*.js\" --check --ignore-path .gitignore",
64
- "format:prettier": "prettier \"**/*.js\" --write --ignore-path .gitignore",
64
+ "lint:prettier": "prettier \"**/*.{js,ts,html,css,md,json}\" --check --ignore-path .gitignore",
65
+ "format:prettier": "prettier \"**/*.{js,ts,html,css,md,json}\" --write --ignore-path .gitignore",
65
66
  "version": "node scripts/update-demo-versions.js && git add demo/esm.html",
66
67
  "postversion": "git push --follow-tags"
67
68
  },
68
69
  "devDependencies": {
70
+ "@playwright/test": "^1.64.0",
69
71
  "@open-wc/eslint-config": "^13.1.0",
70
72
  "@testing-library/dom": "^10.4.2",
71
73
  "@testing-library/user-event": "^14.6.7",