@miragon/slidev-speaker-profiles 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Miragon GmbH
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/README.md ADDED
@@ -0,0 +1,205 @@
1
+ # @miragon/slidev-speaker-profiles
2
+
3
+ **Several people present the same deck, and each of them wants a different cut
4
+ of it.** This addon lets every speaker keep their own selection of slides in a
5
+ small JSON file, committed alongside the deck. Nobody overwrites anybody, and
6
+ `main` never changes.
7
+
8
+ It is inert until a profile is selected, and a plain `npm run build` always
9
+ produces the complete deck, so a shortened one can never be deployed by
10
+ accident.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm i -D @miragon/slidev-speaker-profiles
16
+ ```
17
+
18
+ Register it as an addon in your deck's headmatter:
19
+
20
+ ```yaml
21
+ ---
22
+ addons:
23
+ - '@miragon/slidev-speaker-profiles'
24
+ ---
25
+ ```
26
+
27
+ That is the whole installation. **Ids are stamped by the addon itself**, when a
28
+ dev server starts, whatever the script that started it is called - which matters
29
+ for a deck with one dev script per chapter, where a `predev` hook would have to
30
+ be repeated in each of them and would be forgotten in one.
31
+
32
+ Add two things to your scripts: a way in for the speaker, and the guard for CI.
33
+
34
+ ```json
35
+ {
36
+ "scripts": {
37
+ "dev": "slidev slides.md --open",
38
+ "dev:profile": "SLIDEV_PROFILE_EDIT=1 npm run dev",
39
+ "check:ids": "slide-ids --check",
40
+ "preverify": "npm run check:ids",
41
+ "verify": "SLIDEV_PROFILE=none slidev-validator --rendered"
42
+ }
43
+ }
44
+ ```
45
+
46
+ `check:ids` belongs in CI: it is what guarantees that everything on `main` is
47
+ addressable, for the case where somebody commits a slide without ever having
48
+ started the dev server. **Do not stamp in a build** - a build must not mutate
49
+ its own sources.
50
+
51
+ `SLIDEV_PROFILE=none` belongs on anything that drives the deck slide by slide
52
+ (the validator, a screenshot run). It switches the addon off for that run, so
53
+ the skip logic cannot navigate away from the slide the tool is waiting for, and
54
+ so the run cannot leave a modified working tree behind.
55
+
56
+ Two ways to keep the dev server's hands off your sources, if you want that:
57
+ `SLIDEV_SPEAKER_PROFILES_NO_STAMP=1` for a single run, or stamp explicitly with
58
+ `slide-ids --stamp` from a `predev` hook.
59
+
60
+ ## What a speaker does
61
+
62
+ ```bash
63
+ echo thomas > .slidev-profiles/.current # once per machine, gitignored
64
+ npm run dev:profile
65
+ ```
66
+
67
+ Then either walk the deck and click **Hide this slide** bottom right, or open
68
+ the chip next to it for the full list, grouped by chapter, with all-on/all-off
69
+ per chapter. Bulk edits there need **Save profile**; a single click saves
70
+ immediately.
71
+
72
+ While editing, nothing jumps: you can walk onto a switched-off slide and turn it
73
+ back on, which is the point. Slidev's own overview (`o`) greys them out.
74
+
75
+ **Present with plain `npm run dev`.** The arrow keys, space and PageDown step
76
+ straight over the switched-off slides and there is nothing on screen to
77
+ mis-click in front of the room.
78
+
79
+ | | `dev:profile` | `dev` |
80
+ |---|---|---|
81
+ | Editing controls | yes | **no** |
82
+ | Switched-off slides | shown, framed red | skipped |
83
+ | What it is for | choosing | presenting |
84
+
85
+ A personal PDF or build spells the name out:
86
+
87
+ ```bash
88
+ SLIDEV_PROFILE=thomas npm run export
89
+ SLIDEV_PROFILE=thomas npm run build
90
+ ```
91
+
92
+ Here the switched-off slides are really removed, not just skipped.
93
+
94
+ ## When the deck moves on
95
+
96
+ **New slides are on by default**, so a slide somebody adds shows up rather than
97
+ disappearing without a word. `dev:profile` lists the new ones by name with a
98
+ **Hide all new** button; plain `dev` shows a short notice that takes itself off
99
+ screen again.
100
+
101
+ **Pick your slides in the full deck.** A deck can have an entry per chapter, and
102
+ running one of those shows and skips exactly what your profile says - that part
103
+ is right, because the ids live in the slide files. But saving from there only
104
+ ever adds to what your profile has seen, never replaces it, so a chapter-sized
105
+ run cannot make the other chapters look new. Presenting a single chapter is
106
+ fine; choosing is a job for the whole deck.
107
+
108
+ ## Slide ids
109
+
110
+ Nobody types these. Every slide carries a random id in its frontmatter:
111
+
112
+ ```yaml
113
+ ---
114
+ id: s-4b81f0ac
115
+ layout: content
116
+ title: Typical modeling errors
117
+ ---
118
+ ```
119
+
120
+ That is what a profile stores, and it is why a selection survives retitling a
121
+ slide, reordering slides, moving one to another chapter, renumbering chapter
122
+ files and having anything inserted around it. The addon removes the line again
123
+ before the slide reaches the layout, so it never lands in the DOM.
124
+
125
+ Do not edit an id and do not copy a slide including its id; `--check` fails when
126
+ two slides claim the same one.
127
+
128
+ ```
129
+ slide-ids --stamp write an id into every slide that has none
130
+ slide-ids --check exit 1 if an id is missing, malformed or duplicated
131
+ slide-ids list the deck with its ids
132
+ ```
133
+
134
+ Hidden slides are stamped too. `hide: true` is how a deck parks content it means
135
+ to bring back, and an unstamped parked slide would return as a new slide for
136
+ every speaker the day the line is deleted. The file keeps its `hide: true`.
137
+
138
+ ### Decks that are not laid out the usual way
139
+
140
+ The entry defaults to `slides.md`, then `deck/slides.md`. Anything else says so:
141
+
142
+ ```bash
143
+ slide-ids --stamp --entry deck/slides.md
144
+ ```
145
+
146
+ Nesting does not matter. Ids are written to the file a slide is *written* in,
147
+ never to the `src:` wrapper that imports it, so a deck composed of two levels of
148
+ imports where every file is called `slides.md` works the same as one chapter
149
+ file per chapter.
150
+
151
+ If your deck parks a chapter by taking its `src:` line out, no entry reaches
152
+ that file any more and its slides would go unstamped. Name it so it keeps its
153
+ ids:
154
+
155
+ ```bash
156
+ slide-ids --stamp --also 'chapter/*/*.md'
157
+ ```
158
+
159
+ ## The profile file
160
+
161
+ ```json
162
+ {
163
+ "schemaVersion": 1,
164
+ "speaker": "thomas",
165
+ "hidden": ["s-4b81f0ac", "s-9d2e77c1"],
166
+ "order": null,
167
+ "knownIds": ["s-29076475", "..."]
168
+ }
169
+ ```
170
+
171
+ One file per speaker in `.slidev-profiles/`, committed like any other file. Two
172
+ speakers editing at the same time touch disjoint files, so git cannot put them
173
+ in conflict. Arrays are written sorted and there is deliberately no timestamp:
174
+ it would be the one line that changes on every save and would turn "same person,
175
+ two machines" into a conflict carrying no information.
176
+
177
+ `hidden` is what the speaker switched off. `knownIds` is what existed the last
178
+ time they saved, which is how "new since your last change" is computed. **Unknown
179
+ means visible.** Ids that vanished are reported but never dropped from `hidden`,
180
+ because the slide may come back on another branch.
181
+
182
+ `order` is reserved for reordering and is always `null` today.
183
+
184
+ Gitignore two entries in `.slidev-profiles/`: `.current`, which says which
185
+ profile *this machine* uses and belongs to nobody else, and `.stamp.lock`, the
186
+ transient lock that keeps two dev servers starting at once from both minting
187
+ ids.
188
+
189
+ ## Environment
190
+
191
+ | | |
192
+ |---|---|
193
+ | `SLIDEV_PROFILE=<name>` | pick the profile explicitly; wins over `.current` |
194
+ | `SLIDEV_PROFILE=none` | switch the addon off entirely |
195
+ | `SLIDEV_PROFILE_EDIT=1` | unlock the editing controls |
196
+ | `SLIDEV_SPEAKER_PROFILES_NO_STAMP=1` | the dev server does not write ids this run |
197
+
198
+ **Anything that drives the deck slide by slide needs `SLIDEV_PROFILE=none`** (a
199
+ validator, a screenshot run): the skip logic would navigate away from the slide
200
+ they are waiting for.
201
+
202
+ ## Internals
203
+
204
+ The traps that shaped this design are documented in
205
+ [`INTERNALS.md`](INTERNALS.md).
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Every slide carries a stable id, and nobody has to think about it.
4
+ *
5
+ * A profile addresses slides by the `id:` in their frontmatter, so the id has to
6
+ * hold still: derived from a title or a position it would move the moment
7
+ * somebody retitles a slide, inserts one above it or renumbers a chapter file,
8
+ * and the speaker's selection would then point at a slide they never chose.
9
+ *
10
+ * slide-ids --stamp # give every unstamped slide an id
11
+ * slide-ids --check # fail if one is missing, malformed or duplicated
12
+ * slide-ids # list the deck with its ids
13
+ *
14
+ * **You normally do not need `--stamp`.** Registering the addon is enough: the
15
+ * dev server stamps new slides when it starts, whatever the script that started
16
+ * it is called. Use it for a deck whose parked files no entry imports (`--also`),
17
+ * for a `predev` hook if you want the stamping to be explicit, or to fix a deck
18
+ * that `--check` has just failed on.
19
+ *
20
+ * Put `--check` in CI. Never stamp in a build: a build must not mutate its own
21
+ * sources.
22
+ *
23
+ * The id is `s-` plus 8 hex characters. Short enough to stay readable in a
24
+ * frontmatter block and in a profile's `hidden` list, random so that two
25
+ * branches adding a slide at the same time can never pick the same one.
26
+ */
27
+ import { existsSync } from 'node:fs'
28
+ import path from 'node:path'
29
+ import process from 'node:process'
30
+ import { RE_ID, collectSlides, stampSlides } from '../stamp.mjs'
31
+
32
+ const USAGE = `slide-ids - stable ids for the slides of a Slidev deck
33
+
34
+ slide-ids [--check | --stamp] [options]
35
+
36
+ --stamp write an id into every slide that has none
37
+ --check exit 1 if an id is missing, malformed or duplicated
38
+ (neither) list the deck with its ids
39
+
40
+ --entry <file> the deck entry (default: slides.md, else deck/slides.md)
41
+ --also <glob> additionally parse files no entry imports, relative to the
42
+ deck root; repeatable. Supports * and **. Use it when the
43
+ deck parks a chapter by removing its src: line, so the
44
+ parked file keeps its ids instead of coming back as new
45
+ slides for every speaker.
46
+ --help
47
+ `
48
+
49
+ function parseArgs(argv) {
50
+ const options = { mode: 'list', entry: undefined, also: [] }
51
+ for (let i = 0; i < argv.length; i++) {
52
+ const arg = argv[i]
53
+ if (arg === '--stamp')
54
+ options.mode = 'stamp'
55
+ else if (arg === '--check')
56
+ options.mode = 'check'
57
+ else if (arg === '--entry')
58
+ options.entry = argv[++i]
59
+ else if (arg === '--also')
60
+ options.also.push(argv[++i])
61
+ else if (arg === '--help' || arg === '-h')
62
+ options.help = true
63
+ else
64
+ throw new Error(`unknown argument "${arg}"`)
65
+ }
66
+ return options
67
+ }
68
+
69
+ let options
70
+ try {
71
+ options = parseArgs(process.argv.slice(2))
72
+ }
73
+ catch (error) {
74
+ console.error(`${error.message}\n\n${USAGE}`)
75
+ process.exit(2)
76
+ }
77
+
78
+ if (options.help) {
79
+ console.log(USAGE)
80
+ process.exit(0)
81
+ }
82
+
83
+ /**
84
+ * Where the deck is. Slidev's own default is `slides.md` next to you, which is
85
+ * right when the scripts live in the deck's own workspace; `deck/slides.md`
86
+ * covers the repo that keeps the deck in a subfolder. Anything else says so
87
+ * with --entry.
88
+ */
89
+ function resolveEntry(explicit) {
90
+ if (explicit)
91
+ return path.resolve(explicit)
92
+ for (const candidate of ['slides.md', path.join('deck', 'slides.md')]) {
93
+ if (existsSync(path.resolve(candidate)))
94
+ return path.resolve(candidate)
95
+ }
96
+ console.error(`no deck entry found (looked for slides.md and deck/slides.md). Pass --entry <file>.\n\n${USAGE}`)
97
+ process.exit(2)
98
+ }
99
+
100
+ const entry = resolveEntry(options.entry)
101
+ const also = options.also
102
+ const rel = file => path.relative(process.cwd(), file)
103
+ const where = row => `${rel(row.file)}:${row.start + 1}`
104
+ const name = row => row.title || '(untitled)'
105
+
106
+ if (options.mode === 'stamp') {
107
+ const { stamped, unwritable, total, skipped, files } = await stampSlides({ entry, also })
108
+ if (unwritable.length) {
109
+ for (const row of unwritable)
110
+ console.error(`FAIL: ${where(row)} has no writable frontmatter block (style: ${row.style})`)
111
+ process.exit(1)
112
+ }
113
+ if (skipped) {
114
+ console.error('slide ids: another stamping run holds the lock, nothing written')
115
+ process.exit(1)
116
+ }
117
+ if (!stamped.length) {
118
+ console.log(`slide ids: ${total} slides, all stamped`)
119
+ }
120
+ else {
121
+ for (const row of stamped)
122
+ console.log(` + ${row.id} ${where(row)} ${name(row)}`)
123
+ console.log(`slide ids: stamped ${stamped.length} slide(s) in ${files} file(s)`)
124
+ }
125
+ }
126
+ else {
127
+ const { rows } = await collectSlides({ entry, also })
128
+
129
+ if (options.mode === 'check') {
130
+ const missing = rows.filter(row => !row.id)
131
+ const malformed = rows.filter(row => row.id && !RE_ID.test(row.id))
132
+ const byId = new Map()
133
+ for (const row of rows.filter(row => row.id))
134
+ byId.set(row.id, [...(byId.get(row.id) ?? []), row])
135
+ const duplicates = [...byId.entries()].filter(([, list]) => list.length > 1)
136
+
137
+ for (const row of missing)
138
+ console.error(`FAIL: no id on "${name(row)}" (${where(row)})`)
139
+ for (const row of malformed)
140
+ console.error(`FAIL: id "${row.id}" is not of the form s-xxxxxxxx (${where(row)})`)
141
+ for (const [id, list] of duplicates)
142
+ console.error(`FAIL: id "${id}" used by ${list.length} slides: ${list.map(where).join(', ')}`)
143
+
144
+ if (missing.length || malformed.length || duplicates.length) {
145
+ console.error('\nRun `slide-ids --stamp` to give every slide an id.')
146
+ process.exit(1)
147
+ }
148
+ console.log(`slide ids: ${rows.length} slides, ${byId.size} distinct ids, all stamped`)
149
+ }
150
+ else {
151
+ let file = null
152
+ for (const row of rows) {
153
+ if (row.file !== file) {
154
+ file = row.file
155
+ console.log(`\n${rel(file)}`)
156
+ }
157
+ console.log(` ${(row.id || '(none)').padEnd(12)} ${name(row)}`)
158
+ }
159
+ console.log(`\n${rows.length} slides`)
160
+ }
161
+ }