@zumer/snapdom-plugins 4.2.1 → 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 +16 -0
- package/package.json +1 -1
- package/stream/README.md +1 -0
- package/stream/src/stream.js +23 -9
- package/stream.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
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
|
+
|
|
11
|
+
## 4.3.0
|
|
12
|
+
|
|
13
|
+
> 25 October 2026
|
|
14
|
+
|
|
15
|
+
**Fixes**
|
|
16
|
+
|
|
17
|
+
- **stream:** report only dirty rects inside the canvas [`f9302d4`](https://github.com/zumerlab/snapdom/commit/f9302d4bd8b76f4dcab81c83314778cf9074b2a3)
|
|
18
|
+
|
|
3
19
|
## 4.2.1
|
|
4
20
|
|
|
5
21
|
- Fix the stream plugin: a box cut by an ancestor with overflow hidden was painted whole. Patches now stay inside every clipping ancestor.
|
package/package.json
CHANGED
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
|
|
package/stream/src/stream.js
CHANGED
|
@@ -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')
|
|
@@ -342,18 +346,26 @@ export function stream(element, options = {}) {
|
|
|
342
346
|
// demos/stream-webgl.html: 11.9 ms one after another.
|
|
343
347
|
const layers = await Promise.all(hosts.map(renderPatch))
|
|
344
348
|
const out = []
|
|
349
|
+
// The canvas clips draws past its edge; a reported rect must be clipped too, or a box
|
|
350
|
+
// sliding off the stage (the lower third hides to left:-720px) hands texSubImage2D a
|
|
351
|
+
// negative offset and the upload is rejected. Pinned by __tests__/plugin.stream.test.js.
|
|
352
|
+
const report = (x, y, w, h) => {
|
|
353
|
+
const x0 = Math.max(0, x), y0 = Math.max(0, y)
|
|
354
|
+
const x1 = Math.min(canvas.width, x + w), y1 = Math.min(canvas.height, y + h)
|
|
355
|
+
if (x1 > x0 && y1 > y0) out.push({ x: x0, y: y0, width: x1 - x0, height: y1 - y0 })
|
|
356
|
+
}
|
|
345
357
|
for (const [host, old] of movedFrom) {
|
|
346
358
|
const r = pixelRect(old)
|
|
347
359
|
const x = Math.round(ox + r.left * k), y = Math.round(oy + r.top * k)
|
|
348
360
|
const w = Math.round(ox + r.right * k) - x, h = Math.round(oy + r.bottom * k) - y
|
|
349
361
|
paintBackdrop(backdrops.get(host), x, y, w, h)
|
|
350
|
-
|
|
362
|
+
report(x, y, w, h)
|
|
351
363
|
}
|
|
352
364
|
for (const { layer, x, y, w, h, backdrop } of layers) {
|
|
353
365
|
// A backdrop layer is the full frame's pixels for its whole rect: replace, not blend.
|
|
354
366
|
if (backdrop) ctx.clearRect(x, y, w, h)
|
|
355
367
|
ctx.drawImage(layer, x, y)
|
|
356
|
-
|
|
368
|
+
report(x, y, w, h)
|
|
357
369
|
}
|
|
358
370
|
movedFrom.clear()
|
|
359
371
|
// Remember where each host was drawn, not where it is now: a sliding box kept moving
|
|
@@ -425,13 +437,15 @@ export function stream(element, options = {}) {
|
|
|
425
437
|
if (busy || (fps && now - lastTick < 1000 / fps)) return
|
|
426
438
|
// A running animation repaints its target every frame, and once more when it stops: the
|
|
427
439
|
// frame before a pause or the end of a transition is not where it came to rest.
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
|
431
448
|
}
|
|
432
|
-
for (const target of running) dirty.add(target)
|
|
433
|
-
for (const target of animating) if (!running.has(target)) dirty.add(target)
|
|
434
|
-
animating = running
|
|
435
449
|
netTargets(observer.takeRecords(), dirty, restyled)
|
|
436
450
|
// The keyframe waits for idle time, so it never lands on top of a burst of edits.
|
|
437
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 {
|