@zumer/snapdom-plugins 4.3.0 → 4.4.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Plugin changes
2
2
 
3
+ ## 4.4.0
4
+
5
+ > 27 October 2026
6
+
7
+ **Features**
8
+
9
+ - **stream:** add animations: false to stop following running animations [`932df5e`](https://github.com/zumerlab/snapdom/commit/932df5e7620ebcd9d5206d16fbd683383d77e0b3)
10
+
3
11
  ## 4.3.0
4
12
 
5
13
  > 25 October 2026
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zumer/snapdom-plugins",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
4
4
  "description": "Official plugins for SnapDOM",
5
5
  "type": "module",
6
6
  "scripts": {
package/stream/README.md CHANGED
@@ -46,6 +46,7 @@ All [capture options](https://snapdom.dev/) apply (`scale`, `dpr`, `embedFonts`,
46
46
  | `onFrame(frame)` | | called after each repaint: `{ full, reason, rects, ms, canvas }` |
47
47
  | `fps` | every animation frame | upper bound on repaints per second |
48
48
  | `patches` | `true` | `false` repaints full frames only, for comparison |
49
+ | `animations` | `true` | `false` stops following running animations and transitions: an animated box keeps the pixels it was last drawn with until a patch over it, a full frame or the keyframe. For a still of the page, where a spinner's angle does not matter but its full frames would |
49
50
 
50
51
  `stream()` returns `{ canvas, ready, stats, stop() }`.
51
52
 
@@ -137,10 +137,14 @@ async function decode(url) {
137
137
  * @param {(frame: {full: boolean, reason: string|null, rects: {x:number,y:number,width:number,height:number}[], ms: number, canvas: HTMLCanvasElement}) => void} [options.onFrame]
138
138
  * @param {number} [options.fps] - cap on frames per second; default every animation frame.
139
139
  * @param {boolean} [options.patches=true] - false repaints full frames only (the baseline).
140
+ * @param {boolean} [options.animations=true] - false stops following running animations and
141
+ * transitions: an animated box keeps its last drawn pixels until a patch, a full frame or the
142
+ * keyframe repaints it. A transparent spinner has no host, so by default every tick is a full
143
+ * frame (Zumly views at dpr 2, fps 5: 109 ms a frame, against 9-13 ms patches without it).
140
144
  * @returns {{canvas: HTMLCanvasElement, stop: () => void, ready: Promise<void>, stats: object}}
141
145
  */
142
146
  export function stream(element, options = {}) {
143
- const { onFrame, fps, patches = true, ...rest } = options
147
+ const { onFrame, fps, patches = true, animations = true, ...rest } = options
144
148
  const opts = { ...rest, outerShadows: false, dpr: rest.dpr ?? (globalThis.devicePixelRatio || 1) }
145
149
  const k = (opts.scale ?? 1) * opts.dpr
146
150
  const canvas = document.createElement('canvas')
@@ -433,13 +437,15 @@ export function stream(element, options = {}) {
433
437
  if (busy || (fps && now - lastTick < 1000 / fps)) return
434
438
  // A running animation repaints its target every frame, and once more when it stops: the
435
439
  // frame before a pause or the end of a transition is not where it came to rest.
436
- const running = new Set()
437
- for (const a of element.getAnimations?.({ subtree: true }) || []) {
438
- if (a.playState === 'running') running.add(a.effect?.target || element)
440
+ if (animations) {
441
+ const running = new Set()
442
+ for (const a of element.getAnimations?.({ subtree: true }) || []) {
443
+ if (a.playState === 'running') running.add(a.effect?.target || element)
444
+ }
445
+ for (const target of running) dirty.add(target)
446
+ for (const target of animating) if (!running.has(target)) dirty.add(target)
447
+ animating = running
439
448
  }
440
- for (const target of running) dirty.add(target)
441
- for (const target of animating) if (!running.has(target)) dirty.add(target)
442
- animating = running
443
449
  netTargets(observer.takeRecords(), dirty, restyled)
444
450
  // The keyframe waits for idle time, so it never lands on top of a burst of edits.
445
451
  if (!keyframeDue && !idleAsked && now - lastKeyframe > Math.max(KEYFRAME_MS, fullMs * KEYFRAME_COST)) {
package/stream.d.ts CHANGED
@@ -16,6 +16,8 @@ export interface StreamOptions extends SnapdomOptions {
16
16
  fps?: number
17
17
  /** false repaints full frames only. Default true. */
18
18
  patches?: boolean
19
+ /** false stops following running animations and transitions: an animated box keeps its last drawn pixels until something else repaints it. Default true. */
20
+ animations?: boolean
19
21
  }
20
22
 
21
23
  export interface Stream {