@zumer/snapdom-plugins 4.4.1-dev.1 → 5.0.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 +29 -0
- package/README.md +30 -83
- package/ascii-export.d.ts +0 -7
- package/ascii-export.js +0 -21
- package/index.d.ts +0 -3
- package/index.js +1 -4
- package/package.json +4 -19
- package/pdf/LICENSE +0 -21
- package/pdf/README.md +0 -22
- package/pdf/REFERENCE.md +0 -520
- package/pdf/src/frontmatter.js +0 -200
- package/pdf/src/furniture.js +0 -398
- package/pdf/src/index.js +0 -2415
- package/pdf/src/mega/README.md +0 -47
- package/pdf/src/mega/diag.js +0 -148
- package/pdf/src/mega/flow.js +0 -56
- package/pdf/src/mega/fonts.js +0 -287
- package/pdf/src/mega/forms.js +0 -479
- package/pdf/src/mega/labels.js +0 -43
- package/pdf/src/mega/meta.js +0 -145
- package/pdf/src/nav.js +0 -357
- package/pdf/src/paginate.js +0 -583
- package/pdf/src/tagged.js +0 -355
- package/pdf/src/text-layer.js +0 -1771
- package/pdf/src/writer/encrypt.js +0 -218
- package/pdf/src/writer/font.js +0 -507
- package/pdf/src/writer/index.js +0 -1135
- package/pdf/src/writer/subset.js +0 -387
- package/pdf.d.ts +0 -294
- package/pdf.js +0 -1
- package/stream/LICENSE +0 -21
- package/stream/README.md +0 -142
- package/stream/src/index.js +0 -41
- package/stream/src/overlays.js +0 -153
- package/stream/src/recorder.js +0 -41
- package/stream/src/stream.js +0 -686
- package/stream/src/webgl.js +0 -58
- package/stream.d.ts +0 -86
- package/stream.js +0 -1
- package/vector/CONTRACT.md +0 -903
- package/vector/LICENSE +0 -21
- package/vector/README.md +0 -35
- package/vector/src/adapters/snapdom.js +0 -795
- package/vector/src/collect/box.js +0 -1676
- package/vector/src/collect/font.js +0 -487
- package/vector/src/collect/image.js +0 -1458
- package/vector/src/collect/mathml.js +0 -272
- package/vector/src/collect/text.js +0 -3027
- package/vector/src/css/color.js +0 -823
- package/vector/src/css/gradient.js +0 -1126
- package/vector/src/css/matrix.js +0 -398
- package/vector/src/css/radius.js +0 -124
- package/vector/src/css/shadow.js +0 -201
- package/vector/src/emit/figma-json.js +0 -1995
- package/vector/src/emit/h2d-vector.js +0 -215
- package/vector/src/emit/h2d.js +0 -1147
- package/vector/src/emit/pdf.js +0 -2571
- package/vector/src/emit/svg-flat.js +0 -4842
- package/vector/src/exclusion.js +0 -13
- package/vector/src/index.js +0 -2910
- package/vector/src/paint.js +0 -2908
- package/vector/src/public.js +0 -57
- package/vector/src/writer/encrypt.js +0 -227
- package/vector/src/writer/font.js +0 -507
- package/vector/src/writer/index.js +0 -1148
- package/vector/src/writer/subset.js +0 -387
- package/vector/svd/index.js +0 -72
- package/vector/svd/schema.js +0 -985
- package/vector.d.ts +0 -28
- package/vector.js +0 -1
package/stream/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 ZumerLab
|
|
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.
|
package/stream/README.md
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
# stream
|
|
2
|
-
|
|
3
|
-
A live element as a canvas that repaints only what changed. For WebGL textures, video overlays
|
|
4
|
-
and anything else that needs the DOM as pixels, many times a second.
|
|
5
|
-
|
|
6
|
-
```js
|
|
7
|
-
import { stream } from '@zumer/snapdom-plugins/stream';
|
|
8
|
-
|
|
9
|
-
const live = stream(panel, {
|
|
10
|
-
scale: 2,
|
|
11
|
-
onFrame(frame) {
|
|
12
|
-
// frame.canvas is updated in place; frame.rects lists what changed, in canvas pixels.
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
await live.ready;
|
|
16
|
-
// ...
|
|
17
|
-
live.stop();
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## How it works
|
|
21
|
-
|
|
22
|
-
The first frame is a full capture. After that, every change (mutations, typing, focus, hover,
|
|
23
|
-
running animations) is traced to the nearest box that can be repainted on its own, and only
|
|
24
|
-
that subtree is captured and drawn into its rect. A change in a box that cannot (a value on a
|
|
25
|
-
translucent card, a row under a badge) repaints a window of the element instead: a `clip`
|
|
26
|
-
capture of that box, with everything that paints there. The pointer repaints only what a
|
|
27
|
-
`:hover` rule restyles. A frame that cannot be patched exactly is a full frame, and
|
|
28
|
-
`frame.reason` says why (`'root resized'`, `'no host for <div.x>'`, ...).
|
|
29
|
-
A keyframe in idle time heals anything the change tracking could not see, at most every 2 s
|
|
30
|
-
and never more than 2% of the main thread.
|
|
31
|
-
|
|
32
|
-
Every patched frame is meant to match a full capture of the same DOM state pixel for pixel.
|
|
33
|
-
The test suite checks exactly that on Chromium, Firefox and WebKit.
|
|
34
|
-
|
|
35
|
-
Measured on a 1000px grid with one card changing per frame, median per frame:
|
|
36
|
-
|
|
37
|
-
| cards | Chromium full / patch | Firefox | WebKit |
|
|
38
|
-
|---|---|---|---|
|
|
39
|
-
| 400 | 11.7 / 4.2 ms | 28 / 4 ms | 20 / 4 ms |
|
|
40
|
-
| 2000 | 52.9 / 4.9 ms | 119 / 5 ms | 90 / 4 ms |
|
|
41
|
-
|
|
42
|
-
## Options
|
|
43
|
-
|
|
44
|
-
All [capture options](https://snapdom.dev/) apply (`scale`, `dpr`, `embedFonts`, `exclude`,
|
|
45
|
-
...), plus:
|
|
46
|
-
|
|
47
|
-
| option | default | |
|
|
48
|
-
|---|---|---|
|
|
49
|
-
| `onFrame(frame)` | | called after each repaint: `{ full, reason, rects, ms, busyMs, canvas }`. `ms` is wall time; `busyMs` is the part the stream held the main thread, the one to budget on |
|
|
50
|
-
| `fps` | every animation frame | upper bound on repaints per second |
|
|
51
|
-
| `patches` | `true` | `false` repaints full frames only, for comparison |
|
|
52
|
-
| `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 |
|
|
53
|
-
|
|
54
|
-
`stream()` returns `{ canvas, ready, stats, stop() }`.
|
|
55
|
-
|
|
56
|
-
## WebGL
|
|
57
|
-
|
|
58
|
-
`streamTexture(gl)` keeps a texture in step with the stream. On WebGL2 it uploads only the
|
|
59
|
-
changed rects (4% of the texture per frame in the WebGL demo, against 100%).
|
|
60
|
-
|
|
61
|
-
```js
|
|
62
|
-
import { stream, streamTexture } from '@zumer/snapdom-plugins/stream';
|
|
63
|
-
|
|
64
|
-
const tex = streamTexture(gl);
|
|
65
|
-
stream(panel, { onFrame: (frame) => tex.update(frame) });
|
|
66
|
-
// draw with tex.texture
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Video
|
|
70
|
-
|
|
71
|
-
Composite `live.canvas` over anything with `drawImage`, and record the result:
|
|
72
|
-
|
|
73
|
-
```js
|
|
74
|
-
import { recordCanvas } from '@zumer/snapdom-plugins/stream';
|
|
75
|
-
|
|
76
|
-
const rec = recordCanvas(output, { fps: 30, duration: 10000 });
|
|
77
|
-
const blob = await rec.done; // MP4 or WebM, whichever the browser records
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## WebRTC
|
|
81
|
-
|
|
82
|
-
The composited canvas is a video track like a camera's, so an HTML overlay travels inside the
|
|
83
|
-
video to every viewer, with no desktop software and no server-side render:
|
|
84
|
-
|
|
85
|
-
```js
|
|
86
|
-
const track = output.captureStream(30).getVideoTracks()[0];
|
|
87
|
-
track.contentHint = 'detail'; // graphics are text: keep the resolution
|
|
88
|
-
peerConnection.addTrack(track, new MediaStream([track]));
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
`demos/stream-webrtc.html` sends one tab's program to viewer tabs this way.
|
|
92
|
-
|
|
93
|
-
## Overlay templates
|
|
94
|
-
|
|
95
|
-
A stage and four broadcast graphics, as plain DOM with a small controller each. Every box that
|
|
96
|
-
changes is opaque and the lower third slides with `left`, so a score, a clock tick or a slide
|
|
97
|
-
costs a patch, not a full frame.
|
|
98
|
-
|
|
99
|
-
```js
|
|
100
|
-
import { stream, overlayStage, scoreboard, lowerThird, ticker, liveBadge } from '@zumer/snapdom-plugins/stream';
|
|
101
|
-
|
|
102
|
-
const stage = overlayStage({ width: 1920, height: 1080, theme: { accent: '#facc15' } });
|
|
103
|
-
const score = scoreboard({ home: 'HOME', away: 'AWAY' });
|
|
104
|
-
const lower = lowerThird({ name: 'Alex Morgan', role: 'Commentator' });
|
|
105
|
-
stage.append(score.el, liveBadge().el, lower.el, ticker({ items: ['Kick-off at 18:00'] }).el);
|
|
106
|
-
document.body.append(stage);
|
|
107
|
-
|
|
108
|
-
score.clock.start();
|
|
109
|
-
score.add('home');
|
|
110
|
-
lower.set({ name: 'Jamie Rivera' });
|
|
111
|
-
lower.hide();
|
|
112
|
-
|
|
113
|
-
const live = stream(stage, { onFrame });
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Theme through CSS variables on the stage: `accent`, `panel`, `panel-2`, `text`, `ink`, `live`,
|
|
117
|
-
`font`.
|
|
118
|
-
|
|
119
|
-
## As an export
|
|
120
|
-
|
|
121
|
-
`streamExport()` adds `toStream()` to a capture result, next to `toMp4()` and `toGif()`:
|
|
122
|
-
|
|
123
|
-
```js
|
|
124
|
-
import { streamExport } from '@zumer/snapdom-plugins/stream';
|
|
125
|
-
|
|
126
|
-
const result = await snapdom(panel, { plugins: [streamExport()] });
|
|
127
|
-
const live = await result.toStream({ onFrame });
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## Limits
|
|
131
|
-
|
|
132
|
-
- Patches need a box that can be repainted standalone. A change inside a transparent box with
|
|
133
|
-
no solid backdrop, under a positioned element, or that moves its siblings is a full frame.
|
|
134
|
-
- Programmatic CSSOM edits (`insertRule`, `rule.style`) produce no signal; the keyframe heals
|
|
135
|
-
them.
|
|
136
|
-
- Text ink that spills past a box edge onto a pixel shared with a neighbour waits for the
|
|
137
|
-
keyframe.
|
|
138
|
-
- Needs SnapDOM 3.4.0 or newer, which has the `__subpixel` layout option. On an older core the
|
|
139
|
-
stream still runs, but patches at fractional positions are not pixel-exact.
|
|
140
|
-
|
|
141
|
-
Demos: `demos/stream-templates.html`, `demos/stream-overlay.html`, `demos/stream-webrtc.html`, `demos/stream-webgl.html`,
|
|
142
|
-
`demos/stream-lab.html`, `demos/stream-glass.html`, `demos/stream-fx.html`, `demos/stream-virtual.html`.
|
package/stream/src/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Live DOM streaming for SnapDOM: an element as a canvas that repaints only what changed,
|
|
3
|
-
* plus the pieces that put it to work (a WebGL texture that uploads only dirty rects, a
|
|
4
|
-
* recorder, broadcast overlay templates). `stream(el)` is the entry; `streamExport()` adds the same thing to a capture
|
|
5
|
-
* result as `toStream()`, next to toMp4 and toGif.
|
|
6
|
-
* @module plugins/stream
|
|
7
|
-
*/
|
|
8
|
-
import { stream } from './stream.js'
|
|
9
|
-
import { captureInputs, exportOption } from '../../capture-frames.js'
|
|
10
|
-
|
|
11
|
-
export { stream } from './stream.js'
|
|
12
|
-
export { streamTexture } from './webgl.js'
|
|
13
|
-
export { recordCanvas } from './recorder.js'
|
|
14
|
-
export { overlayStage, scoreboard, lowerThird, ticker, liveBadge } from './overlays.js'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Plugin form: `result.toStream(options)` streams the captured element with the capture's
|
|
18
|
-
* own options. Returns the stream at once, so it never holds the result's export queue.
|
|
19
|
-
* Pinned by __tests__/plugin.stream.test.js.
|
|
20
|
-
* @param {object} [defaults] - stream options applied to every toStream()
|
|
21
|
-
* @returns {object} SnapDOM plugin
|
|
22
|
-
*/
|
|
23
|
-
export function streamExport(defaults = {}) {
|
|
24
|
-
return {
|
|
25
|
-
name: 'stream',
|
|
26
|
-
defineExports() {
|
|
27
|
-
return {
|
|
28
|
-
stream: (ctx, opts = {}) => {
|
|
29
|
-
if (!ctx.element) throw new Error('[SnapDOM] stream: there is no element to stream.')
|
|
30
|
-
const requested = ctx.export?.requestedOptions || opts
|
|
31
|
-
return stream(ctx.element, {
|
|
32
|
-
...captureInputs(ctx, opts),
|
|
33
|
-
scale: exportOption(ctx, opts, 'scale', ctx.scale ?? 1),
|
|
34
|
-
...defaults,
|
|
35
|
-
...requested,
|
|
36
|
-
})
|
|
37
|
-
},
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
}
|
package/stream/src/overlays.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Broadcast overlay templates: a stage, a scoreboard with a clock, a lower third, a ticker and
|
|
3
|
-
* a live badge, as plain DOM with a small controller each. Framework-free: append `.el`
|
|
4
|
-
* wherever the overlay lives and stream the stage.
|
|
5
|
-
*
|
|
6
|
-
* Built to patch. Every box that changes is opaque, so a score or a clock tick repaints that
|
|
7
|
-
* box alone; the lower third slides with `left`, which moves an out-of-flow box the stream
|
|
8
|
-
* clears and redraws, where a `transform` slide would be a full frame on every step of it.
|
|
9
|
-
* Theme through CSS variables on the stage (--sdo-accent, --sdo-panel, --sdo-text, --sdo-font).
|
|
10
|
-
* Pinned by __tests__/plugin.stream.overlays.test.js.
|
|
11
|
-
* @module plugins/stream/overlays
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const CSS = `
|
|
15
|
-
.sdo-stage{position:relative;overflow:hidden;--sdo-accent:#facc15;--sdo-panel:#0b0f17;--sdo-panel-2:#161d2b;--sdo-text:#fff;--sdo-ink:#111;--sdo-live:#ef4444;--sdo-font:Arial,Helvetica,sans-serif;font:16px/20px var(--sdo-font);color:var(--sdo-text)}
|
|
16
|
-
.sdo-score{position:absolute;left:24px;top:24px;display:flex;background:var(--sdo-panel);border-radius:6px;overflow:hidden;box-shadow:0 4px 14px #0009}
|
|
17
|
-
.sdo-team{display:flex;align-items:center;gap:10px;padding:8px 14px;background:var(--sdo-panel);font-weight:700;letter-spacing:.04em}
|
|
18
|
-
.sdo-team i{width:10px;height:28px;border-radius:2px;display:block}
|
|
19
|
-
.sdo-pts{min-width:44px;text-align:center;font:700 26px/32px var(--sdo-font);padding:4px 8px;background:var(--sdo-panel-2)}
|
|
20
|
-
.sdo-clock{padding:0 14px;display:flex;align-items:center;background:var(--sdo-accent);color:var(--sdo-ink);font:700 20px/40px ui-monospace,Menlo,monospace}
|
|
21
|
-
.sdo-live{position:absolute;right:24px;top:24px;background:var(--sdo-panel);border-radius:6px;padding:6px 12px 6px 28px;font-weight:700;letter-spacing:.1em}
|
|
22
|
-
.sdo-live::before{content:'';position:absolute;left:11px;top:11px;width:10px;height:10px;border-radius:50%;background:var(--sdo-live);animation:sdo-pulse 1s ease-in-out infinite}
|
|
23
|
-
@keyframes sdo-pulse{50%{opacity:.25}}
|
|
24
|
-
.sdo-lower{position:absolute;left:24px;bottom:76px;display:flex;flex-direction:column;transition:left .45s cubic-bezier(.2,.8,.2,1)}
|
|
25
|
-
.sdo-lower.sdo-hidden{left:-720px}
|
|
26
|
-
.sdo-name{background:#f8fafc;color:#0b0f17;font:700 24px/30px var(--sdo-font);padding:6px 16px;border-radius:4px 4px 0 0}
|
|
27
|
-
.sdo-role{background:#1d4ed8;color:#fff;padding:6px 16px;border-radius:0 0 4px 4px}
|
|
28
|
-
.sdo-ticker{position:absolute;left:0;right:0;bottom:0;height:40px;background:var(--sdo-panel);overflow:hidden;display:flex;align-items:center}
|
|
29
|
-
.sdo-tag{background:var(--sdo-live);height:40px;padding:0 14px;display:flex;align-items:center;font-weight:700;position:relative;z-index:1}
|
|
30
|
-
.sdo-run{white-space:nowrap;padding-left:20px;animation:sdo-run var(--sdo-speed,18s) linear infinite}
|
|
31
|
-
@keyframes sdo-run{from{transform:translateX(0)}to{transform:translateX(-50%)}}
|
|
32
|
-
`
|
|
33
|
-
|
|
34
|
-
function el(tag, className, text) {
|
|
35
|
-
const node = document.createElement(tag)
|
|
36
|
-
if (className) node.className = className
|
|
37
|
-
if (text != null) node.textContent = text
|
|
38
|
-
return node
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function injectCss(doc = document) {
|
|
42
|
-
if (doc.getElementById('sdo-css')) return
|
|
43
|
-
const style = el('style')
|
|
44
|
-
style.id = 'sdo-css'
|
|
45
|
-
style.textContent = CSS
|
|
46
|
-
doc.head.append(style)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The transparent stage every overlay sits on; stream this element.
|
|
51
|
-
* @param {{width?: number, height?: number, theme?: Record<string, string>}} [options] -
|
|
52
|
-
* size in CSS px (default 960x540); theme maps --sdo-* names without the prefix.
|
|
53
|
-
* @returns {HTMLDivElement}
|
|
54
|
-
*/
|
|
55
|
-
export function overlayStage({ width = 960, height = 540, theme = {} } = {}) {
|
|
56
|
-
injectCss()
|
|
57
|
-
const stage = el('div', 'sdo-stage')
|
|
58
|
-
stage.style.width = `${width}px`
|
|
59
|
-
stage.style.height = `${height}px`
|
|
60
|
-
for (const [k, v] of Object.entries(theme)) stage.style.setProperty(`--sdo-${k}`, v)
|
|
61
|
-
return stage
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Two teams, their points and a running clock.
|
|
66
|
-
* @param {{home?: string, away?: string, homeColor?: string, awayColor?: string}} [options]
|
|
67
|
-
* @returns {{el: HTMLElement, score(home: number, away: number): void, add(side: 'home'|'away', n?: number): void,
|
|
68
|
-
* clock: {start(): void, stop(): void, reset(seconds?: number): void, set(text: string): void}}}
|
|
69
|
-
*/
|
|
70
|
-
export function scoreboard({ home = 'HOME', away = 'AWAY', homeColor = '#22c55e', awayColor = '#3b82f6' } = {}) {
|
|
71
|
-
injectCss()
|
|
72
|
-
const root = el('div', 'sdo-score')
|
|
73
|
-
const team = (name, color, first) => {
|
|
74
|
-
const t = el('div', 'sdo-team')
|
|
75
|
-
const swatch = el('i')
|
|
76
|
-
swatch.style.background = color
|
|
77
|
-
t.append(...(first ? [swatch, el('span', '', name)] : [el('span', '', name), swatch]))
|
|
78
|
-
return t
|
|
79
|
-
}
|
|
80
|
-
const pts = [el('div', 'sdo-pts', '0'), el('div', 'sdo-pts', '0')]
|
|
81
|
-
const clockEl = el('div', 'sdo-clock', '00:00.0')
|
|
82
|
-
root.append(team(home, homeColor, true), pts[0], pts[1], team(away, awayColor, false), clockEl)
|
|
83
|
-
const points = [0, 0]
|
|
84
|
-
let started = 0, offset = 0, timer = 0
|
|
85
|
-
const show = (s) => { clockEl.textContent = `${String(Math.floor(s / 60)).padStart(2, '0')}:${(s % 60).toFixed(1).padStart(4, '0')}` }
|
|
86
|
-
return {
|
|
87
|
-
el: root,
|
|
88
|
-
score(h, a) { points[0] = h; points[1] = a; pts[0].textContent = h; pts[1].textContent = a },
|
|
89
|
-
add(side, n = 1) { const i = side === 'away' ? 1 : 0; points[i] += n; pts[i].textContent = points[i] },
|
|
90
|
-
clock: {
|
|
91
|
-
start() {
|
|
92
|
-
if (timer) return
|
|
93
|
-
started = performance.now()
|
|
94
|
-
timer = setInterval(() => show(offset + (performance.now() - started) / 1000), 100)
|
|
95
|
-
},
|
|
96
|
-
stop() {
|
|
97
|
-
if (!timer) return
|
|
98
|
-
clearInterval(timer)
|
|
99
|
-
timer = 0
|
|
100
|
-
offset += (performance.now() - started) / 1000
|
|
101
|
-
},
|
|
102
|
-
reset(seconds = 0) { offset = seconds; started = performance.now(); show(seconds) },
|
|
103
|
-
set(text) { clockEl.textContent = text },
|
|
104
|
-
},
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* A name and a role that slide in and out.
|
|
110
|
-
* @param {{name?: string, role?: string, visible?: boolean}} [options]
|
|
111
|
-
* @returns {{el: HTMLElement, set(fields: {name?: string, role?: string}): void, show(): void, hide(): void}}
|
|
112
|
-
*/
|
|
113
|
-
export function lowerThird({ name = '', role = '', visible = true } = {}) {
|
|
114
|
-
injectCss()
|
|
115
|
-
const root = el('div', 'sdo-lower' + (visible ? '' : ' sdo-hidden'))
|
|
116
|
-
const nameEl = el('div', 'sdo-name', name)
|
|
117
|
-
const roleEl = el('div', 'sdo-role', role)
|
|
118
|
-
root.append(nameEl, roleEl)
|
|
119
|
-
return {
|
|
120
|
-
el: root,
|
|
121
|
-
set({ name: n, role: r } = {}) { if (n != null) nameEl.textContent = n; if (r != null) roleEl.textContent = r },
|
|
122
|
-
show() { root.classList.remove('sdo-hidden') },
|
|
123
|
-
hide() { root.classList.add('sdo-hidden') },
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* A scrolling news line.
|
|
129
|
-
* @param {{label?: string, items?: string[], speed?: number}} [options] - speed: seconds per loop.
|
|
130
|
-
* @returns {{el: HTMLElement, set(items: string[]): void}}
|
|
131
|
-
*/
|
|
132
|
-
export function ticker({ label = 'NEWS', items = [], speed = 18 } = {}) {
|
|
133
|
-
injectCss()
|
|
134
|
-
const root = el('div', 'sdo-ticker')
|
|
135
|
-
const run = el('div', 'sdo-run')
|
|
136
|
-
root.style.setProperty('--sdo-speed', `${speed}s`)
|
|
137
|
-
root.append(el('div', 'sdo-tag', label), run)
|
|
138
|
-
// Twice over, so the loop's -50% lands exactly where it started.
|
|
139
|
-
const set = (list) => { run.textContent = (list.join(' · ') + ' · ').repeat(2) }
|
|
140
|
-
set(items)
|
|
141
|
-
return { el: root, set }
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* A pulsing "LIVE" bug.
|
|
146
|
-
* @param {{text?: string}} [options]
|
|
147
|
-
* @returns {{el: HTMLElement, set(text: string): void}}
|
|
148
|
-
*/
|
|
149
|
-
export function liveBadge({ text = 'LIVE' } = {}) {
|
|
150
|
-
injectCss()
|
|
151
|
-
const root = el('div', 'sdo-live', text)
|
|
152
|
-
return { el: root, set(t) { root.textContent = t } }
|
|
153
|
-
}
|
package/stream/src/recorder.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Record any canvas a stream feeds (the stream's own, or one it is composited into over
|
|
3
|
-
* video) with the native MediaRecorder. The container follows the browser: Safari records
|
|
4
|
-
* MP4, Chromium and Firefox WebM unless they support MP4.
|
|
5
|
-
* @module plugins/stream/recorder
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const TYPES = ['video/mp4;codecs=avc1', 'video/mp4', 'video/webm;codecs=vp9', 'video/webm;codecs=vp8', 'video/webm']
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Start recording `canvas`.
|
|
12
|
-
* @param {HTMLCanvasElement} canvas
|
|
13
|
-
* @param {{fps?: number, duration?: number, bitrate?: number}} [options] - fps default 30;
|
|
14
|
-
* with `duration` (ms) the recording stops by itself.
|
|
15
|
-
* @returns {{done: Promise<Blob>, stop: () => Promise<Blob>, type: string}}
|
|
16
|
-
*/
|
|
17
|
-
export function recordCanvas(canvas, options = {}) {
|
|
18
|
-
if (typeof MediaRecorder === 'undefined' || typeof canvas.captureStream !== 'function') {
|
|
19
|
-
throw new Error('[SnapDOM] stream: recording needs MediaRecorder and canvas.captureStream')
|
|
20
|
-
}
|
|
21
|
-
const type = TYPES.find((t) => MediaRecorder.isTypeSupported(t)) || ''
|
|
22
|
-
const recorder = new MediaRecorder(canvas.captureStream(options.fps ?? 30), {
|
|
23
|
-
mimeType: type, videoBitsPerSecond: options.bitrate,
|
|
24
|
-
})
|
|
25
|
-
const chunks = []
|
|
26
|
-
recorder.ondataavailable = (e) => { if (e.data.size) chunks.push(e.data) }
|
|
27
|
-
const done = new Promise((resolve, reject) => {
|
|
28
|
-
recorder.onstop = () => resolve(new Blob(chunks, { type: recorder.mimeType || type }))
|
|
29
|
-
recorder.onerror = (e) => reject(e.error || e)
|
|
30
|
-
})
|
|
31
|
-
recorder.start(1000)
|
|
32
|
-
if (options.duration) setTimeout(() => recorder.state !== 'inactive' && recorder.stop(), options.duration)
|
|
33
|
-
return {
|
|
34
|
-
done,
|
|
35
|
-
type: recorder.mimeType || type,
|
|
36
|
-
stop() {
|
|
37
|
-
if (recorder.state !== 'inactive') recorder.stop()
|
|
38
|
-
return done
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
}
|