polite-media 0.3.0
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/CHANGELOG.md +113 -0
- package/LICENSE +21 -0
- package/README.md +675 -0
- package/dist/coordinator.d.ts +231 -0
- package/dist/coordinator.d.ts.map +1 -0
- package/dist/coordinator.js +1017 -0
- package/dist/coordinator.js.map +1 -0
- package/dist/env.d.ts +30 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +49 -0
- package/dist/env.js.map +1 -0
- package/dist/events.d.ts +70 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +42 -0
- package/dist/events.js.map +1 -0
- package/dist/image.css +1 -0
- package/dist/image.d.ts +45 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +127 -0
- package/dist/image.js.map +1 -0
- package/dist/layer.css +1 -0
- package/dist/reveal.d.ts +34 -0
- package/dist/reveal.d.ts.map +1 -0
- package/dist/reveal.js +72 -0
- package/dist/reveal.js.map +1 -0
- package/dist/sources.d.ts +22 -0
- package/dist/sources.d.ts.map +1 -0
- package/dist/sources.js +148 -0
- package/dist/sources.js.map +1 -0
- package/dist/targets.d.ts +20 -0
- package/dist/targets.d.ts.map +1 -0
- package/dist/targets.js +17 -0
- package/dist/targets.js.map +1 -0
- package/dist/video.css +1 -0
- package/dist/video.d.ts +15 -0
- package/dist/video.d.ts.map +1 -0
- package/dist/video.js +17 -0
- package/dist/video.js.map +1 -0
- package/dist/warm.d.ts +13 -0
- package/dist/warm.d.ts.map +1 -0
- package/dist/warm.js +12 -0
- package/dist/warm.js.map +1 -0
- package/dist/warming.d.ts +62 -0
- package/dist/warming.d.ts.map +1 -0
- package/dist/warming.js +136 -0
- package/dist/warming.js.map +1 -0
- package/package.json +96 -0
- package/src/coordinator.ts +1337 -0
- package/src/env.ts +56 -0
- package/src/events.ts +78 -0
- package/src/image.css +74 -0
- package/src/image.ts +160 -0
- package/src/layer.css +60 -0
- package/src/reveal.ts +75 -0
- package/src/sources.ts +164 -0
- package/src/targets.ts +27 -0
- package/src/video.css +74 -0
- package/src/video.ts +32 -0
- package/src/warm.ts +12 -0
- package/src/warming.ts +162 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Notable changes, newest first. Versions follow [semver](https://semver.org); while
|
|
4
|
+
this is `0.x`, a minor bump may still break things and will say so here.
|
|
5
|
+
|
|
6
|
+
## 0.3.0 (2026-09-02)
|
|
7
|
+
|
|
8
|
+
### Changed
|
|
9
|
+
|
|
10
|
+
- **Breaking: `playAbove`, `hysteresis` and `pauseGraceMs` are no longer
|
|
11
|
+
options.** All three tuned the same thing, oscillation, and none was a policy a
|
|
12
|
+
caller has a view on. `playAbove` is gone outright; it shipped disabled at `0`.
|
|
13
|
+
The other two keep working at their previous defaults as constants: a video
|
|
14
|
+
leaving the viewport still waits 400ms before stopping, and an incumbent still
|
|
15
|
+
holds the single slot until a rival is 15% more visible. Nine options become
|
|
16
|
+
six.
|
|
17
|
+
|
|
18
|
+
- **`resetWarmed` is no longer exported from `polite-media/warm`.** It clears the
|
|
19
|
+
dedup record for a test and had no caller outside the suite; the entry point is
|
|
20
|
+
a barrel now, the way `polite-media/video` already was. No published version
|
|
21
|
+
ever carried it.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **A pause now survives a navigation.** It is kept in `sessionStorage`, so on a
|
|
26
|
+
multi-page site the motion stays stopped as the visitor clicks through. It was
|
|
27
|
+
a module-level flag, which died with the document, so someone who stopped the
|
|
28
|
+
motion was asked to stop it again on every page.
|
|
29
|
+
|
|
30
|
+
## 0.2.0 (2026-08-11)
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- **Breaking: `startWhen` now defaults to `'page-loaded'`, was `'interaction'`.**
|
|
35
|
+
A video plays on its own once `window`'s `load` event has fired, rather than
|
|
36
|
+
waiting for the visitor's first pointer, key or scroll. The old default meant a
|
|
37
|
+
visitor who read a desktop page without scrolling saw a still poster for as
|
|
38
|
+
long as they stayed. The cost is that a hero is once again a Largest Contentful
|
|
39
|
+
Paint candidate; set `startWhen: 'interaction'`, per video or globally, to take
|
|
40
|
+
that back.
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
|
|
44
|
+
- `polite-media/warm`, a third entry point. Fetches the image the next page will
|
|
45
|
+
show while the visitor is still deciding to go there, since document
|
|
46
|
+
prefetchers fetch the HTML and stop.
|
|
47
|
+
- `warm(options)` warms one image; `warmOnIntent(selector, resolve)` does it on
|
|
48
|
+
hover, focus or touch, delegated on the document, and returns a teardown.
|
|
49
|
+
- Candidates are given as `sources`, `srcset`, `src` and `sizes`, mirroring
|
|
50
|
+
`<picture>`.
|
|
51
|
+
|
|
52
|
+
### Notes
|
|
53
|
+
|
|
54
|
+
- **Nothing in the package parses `sizes`.** The candidates are assembled as a
|
|
55
|
+
detached `<picture>` and the browser selects, so warming cannot disagree with
|
|
56
|
+
what the destination renders.
|
|
57
|
+
- No `<link>` hint is injected. A detached image both selects and fetches, which
|
|
58
|
+
avoids `rel="prefetch"` being unsupported in Safari and aborted in Firefox
|
|
59
|
+
without a cache header.
|
|
60
|
+
- Skipped on Save-Data and 2g, deduped per candidate set, and fetched at
|
|
61
|
+
`fetchpriority="low"`.
|
|
62
|
+
- The image entry point is untouched. The only video change is the `startWhen`
|
|
63
|
+
default above.
|
|
64
|
+
|
|
65
|
+
## 0.1.0 (2026-08-11)
|
|
66
|
+
|
|
67
|
+
First release.
|
|
68
|
+
|
|
69
|
+
### Added
|
|
70
|
+
|
|
71
|
+
- `polite-media/video`. Reveals a background video on its first genuinely
|
|
72
|
+
presented frame via `requestVideoFrameCallback`, plays only what is on screen,
|
|
73
|
+
limits how many run at once, falls through the `<source>` list when a codec
|
|
74
|
+
cannot be decoded, honours `prefers-reduced-motion` and Save-Data, recovers
|
|
75
|
+
from bfcache restores and refused autoplay, and ships a pause hook for
|
|
76
|
+
[WCAG 2.2.2][wcag].
|
|
77
|
+
- `polite-media/image`. Reveals an image once `decode()` resolves, rather than on
|
|
78
|
+
`load`, which fires before the pixels exist.
|
|
79
|
+
- Three optional stylesheets. `video.css` and `image.css` handle timing and set no
|
|
80
|
+
geometry; `layer.css` handles the standard poster-over-video stacking.
|
|
81
|
+
- `configure()` options: `startWhen`, `requireBuffered`, `atOnce`,
|
|
82
|
+
`smallViewport`, `hysteresis`, `pauseBelow`, `playAbove`, `pauseGraceMs` and
|
|
83
|
+
`prefetchMargin`. The README explains what each does and when to reach for it.
|
|
84
|
+
- Per-video options at `register()`: `until`, `observe` and `startWhen`.
|
|
85
|
+
- `registerAll()`, `unregister()`, `unregisterAll()`, `pauseAll()`, `resumeAll()`.
|
|
86
|
+
- Events `polite-video:ready`, `polite-video:failed`, `polite-video:pausechange`
|
|
87
|
+
and `polite-image:ready`, with exported name constants.
|
|
88
|
+
- A reveal failsafe, so a marked image can never stay hidden if nothing reveals
|
|
89
|
+
it. Tunable with `--polite-failsafe`, default `5s`.
|
|
90
|
+
- Console warnings for the misconfigurations that are otherwise silent: markup
|
|
91
|
+
that gives the reveal nothing to act on, a looping video with no pause control,
|
|
92
|
+
a video too tall to reach its start threshold, an image nothing manages, and a
|
|
93
|
+
`<source>` list that no viewport claims.
|
|
94
|
+
|
|
95
|
+
### Defaults worth knowing
|
|
96
|
+
|
|
97
|
+
- **`startWhen: 'interaction'`.** Video fetches once `window`'s `load` event has
|
|
98
|
+
fired and plays once the visitor's first pointer, key or scroll follows, which
|
|
99
|
+
keeps it out of Largest Contentful Paint entirely. (Changed in 0.2.0.)
|
|
100
|
+
- **`--polite-fade: 0s` for video, a cut.** Images default to `350ms`. Scope the
|
|
101
|
+
property to one container to give that video its own fade.
|
|
102
|
+
- **`atOnce: { small: 1, large: 'all' }`.** One video at a time on small
|
|
103
|
+
viewports, all of them elsewhere.
|
|
104
|
+
- **`pauseBelow: 0.5`.** A video stops once less than half of it is on screen.
|
|
105
|
+
This caps how tall a managed video can be at about twice the viewport.
|
|
106
|
+
|
|
107
|
+
### Notes
|
|
108
|
+
|
|
109
|
+
- The box carrying `data-polite-media` must be the video's **direct parent**.
|
|
110
|
+
- Client-side routers need `register()` re-run per navigation.
|
|
111
|
+
- ESM only, for browsers. There is no CommonJS entry point.
|
|
112
|
+
|
|
113
|
+
[wcag]: https://www.w3.org/WAI/WCAG22/Understanding/pause-stop-hide.html
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sixra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|