@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/global-top.vue ADDED
@@ -0,0 +1,497 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Two jobs in one layer: the safety net under the navigation, and the editor.
4
+ *
5
+ * Safety net. The patched shortcuts only cover key presses. A direct URL, the
6
+ * goto dialog, a click on an overview card and the browser's back button all
7
+ * change the slide without going through them, so a watcher moves on from a
8
+ * switched-off slide in the direction of travel. It runs `immediate`, because
9
+ * without that a deck opened directly on a switched-off slide just sits there
10
+ * behind the cover. The one frame where the slide is still visible is hidden by
11
+ * an opaque cover.
12
+ *
13
+ * Both must be inert while printing. `GlobalTop` is rendered by
14
+ * `PrintSlideClick` as well, and a watcher that navigates during
15
+ * `slidev export --per-slide` makes the export time out waiting for a slide
16
+ * element that is no longer there.
17
+ */
18
+ import { useNav } from '@slidev/client'
19
+ import { computed, onMounted, ref, watch } from 'vue'
20
+ import {
21
+ dirty,
22
+ drift,
23
+ editable,
24
+ editorOpen,
25
+ hiddenCount,
26
+ hiddenIds,
27
+ initFromSlides,
28
+ isHidden,
29
+ isSlideOff,
30
+ ensureLoaded,
31
+ ready,
32
+ save,
33
+ saveError,
34
+ saveState,
35
+ slideChapter,
36
+ slideId,
37
+ slideTitle,
38
+ speaker,
39
+ toggle,
40
+ } from './state'
41
+
42
+ const nav = useNav()
43
+
44
+ initFromSlides(nav.slides.value)
45
+ onMounted(ensureLoaded)
46
+
47
+ const currentIds = computed(() => nav.slides.value.map(route => slideId(route)).filter(Boolean) as string[])
48
+ const currentIsOff = computed(() => ready.value && !nav.isPrintMode.value && isSlideOff(nav.slides.value, nav.currentSlideNo.value))
49
+
50
+ /**
51
+ * Editing means the play view with the controls on screen. The presenter window
52
+ * is presenting even when the editor is unlocked, so it keeps skipping - you
53
+ * rehearse the cut you are going to hold.
54
+ *
55
+ * MUST be declared before the watcher below: that watcher runs `immediate`, so
56
+ * its callback reads `editing.value` during setup. A `const` declared after it
57
+ * is in the temporal dead zone and throws `Cannot access 'editing' before
58
+ * initialization` - which crashes GlobalTop's setup on the browser exporter
59
+ * (/export), where the watcher fires with `ready` already true, so every slide
60
+ * fails to render and the PPTX/PDF capture freezes on the first slide.
61
+ */
62
+ const editing = computed(() => editable.value && nav.isPlaying.value)
63
+
64
+ watch([() => nav.currentSlideNo.value, ready], ([no, isReady]) => {
65
+ // While editing, navigation stays exactly as it is. Skipping here would make
66
+ // a switched-off slide unreachable: you could never walk back onto it to turn
67
+ // it on again. The red frame says what is off; `npm run dev` does the skipping.
68
+ if (!isReady || editing.value || nav.isPrintMode.value)
69
+ return
70
+ if (!isSlideOff(nav.slides.value, no))
71
+ return
72
+ const step = nav.navDirection.value >= 0 ? 1 : -1
73
+ let target = no + step
74
+ while (target >= 1 && target <= nav.slides.value.length && isSlideOff(nav.slides.value, target))
75
+ target += step
76
+ if (target >= 1 && target <= nav.slides.value.length)
77
+ nav.go(target)
78
+ }, { flush: 'post', immediate: true })
79
+
80
+ const currentId = computed(() => slideId(nav.slides.value[nav.currentSlideNo.value - 1]))
81
+ const onCount = computed(() => nav.slides.value.length - hiddenCount.value)
82
+
83
+ /**
84
+ * The quick way: switch the slide you are looking at on or off without opening
85
+ * the panel. It writes the profile straight away, because a single deliberate
86
+ * click should not need a second one to stick.
87
+ *
88
+ * Toggling the current slide off does NOT jump away: the watcher only reacts to
89
+ * a change of slide, so you keep looking at what you just switched off and can
90
+ * undo it. The skip happens the next time you navigate onto it.
91
+ */
92
+ async function toggleCurrent() {
93
+ if (!currentId.value)
94
+ return
95
+ toggle(currentId.value)
96
+ await save(currentIds.value)
97
+ }
98
+
99
+ const chapters = computed(() => {
100
+ const groups: { name: string, slides: { no: number, id: string, title: string, off: boolean }[] }[] = []
101
+ for (const route of nav.slides.value) {
102
+ const id = slideId(route)
103
+ if (!id)
104
+ continue
105
+ const name = slideChapter(route)
106
+ let group = groups.at(-1)
107
+ if (!group || group.name !== name) {
108
+ group = { name, slides: [] }
109
+ groups.push(group)
110
+ }
111
+ group.slides.push({ no: route.no, id, title: slideTitle(route), off: isHidden(id) })
112
+ }
113
+ return groups
114
+ })
115
+
116
+ const changes = computed(() => drift(currentIds.value))
117
+
118
+ /**
119
+ * The slides that appeared since this profile was last saved, by name.
120
+ *
121
+ * A count alone leaves the speaker to hunt for them. With stamped ids "new"
122
+ * finally means new - a retitled slide keeps its id and no longer shows up here
123
+ * - so the list is worth acting on directly.
124
+ */
125
+ const addedSlides = computed(() => {
126
+ const added = new Set(changes.value.added)
127
+ return nav.slides.value
128
+ .filter(route => added.has(slideId(route) ?? ''))
129
+ .map(route => ({ no: route.no, title: slideTitle(route), chapter: slideChapter(route) }))
130
+ })
131
+
132
+ function hideAllNew() {
133
+ const next = new Set(hiddenIds.value)
134
+ for (const id of changes.value.added)
135
+ next.add(id)
136
+ hiddenIds.value = next
137
+ dirty.value = true
138
+ }
139
+
140
+ /**
141
+ * The same news in the presenting view, where there is no panel to open.
142
+ *
143
+ * Only in dev (the state endpoint is what tells us there is drift at all), only
144
+ * when something actually changed, and it takes itself off screen again: this
145
+ * window is the one the room looks at.
146
+ */
147
+ const noticeDismissed = ref(false)
148
+ const showNotice = computed(() =>
149
+ ready.value
150
+ && !editing.value
151
+ && !nav.isPrintMode.value
152
+ && !noticeDismissed.value
153
+ && !!speaker.value
154
+ && changes.value.added.length > 0,
155
+ )
156
+ watch(showNotice, (visible) => {
157
+ if (visible)
158
+ setTimeout(() => { noticeDismissed.value = true }, 12000)
159
+ })
160
+
161
+ function toggleChapter(name: string, off: boolean) {
162
+ const next = new Set(hiddenIds.value)
163
+ for (const group of chapters.value) {
164
+ if (group.name !== name)
165
+ continue
166
+ for (const slide of group.slides)
167
+ off ? next.add(slide.id) : next.delete(slide.id)
168
+ }
169
+ hiddenIds.value = next
170
+ }
171
+
172
+ function goTo(no: number) {
173
+ editorOpen.value = false
174
+ nav.go(no)
175
+ }
176
+ </script>
177
+
178
+ <template>
179
+ <!-- presenting: cover the frame between landing on a switched-off slide and moving on -->
180
+ <div v-if="currentIsOff && !editing" class="sp-veil" data-testid="speaker-profiles-veil" />
181
+
182
+ <!-- presenting: the deck grew since this profile was last saved -->
183
+ <div v-if="showNotice" class="sp-notice" data-testid="speaker-profiles-notice">
184
+ <strong>{{ changes.added.length }} new slide(s)</strong> since your last selection, switched on.
185
+ Review them with <code>npm run dev:profile</code>.
186
+ <button class="sp-notice-close" title="Dismiss" @click="noticeDismissed = true">
187
+ ×
188
+ </button>
189
+ </div>
190
+
191
+ <template v-if="editing && !nav.isPrintMode.value">
192
+ <!-- editing: the slide stays readable, but it is unmistakably off -->
193
+ <div v-if="currentIsOff" class="sp-off-frame" data-testid="speaker-profiles-off-frame">
194
+ <span class="sp-off-badge">OFF</span>
195
+ </div>
196
+
197
+ <div v-if="!editorOpen" class="sp-cluster">
198
+ <button
199
+ class="sp-chip"
200
+ :class="{ 'sp-chip-on': currentIsOff }"
201
+ :disabled="!currentId || saveState === 'saving'"
202
+ :title="currentIsOff ? 'Put this slide back into your deck' : 'Drop this slide from your deck'"
203
+ data-testid="speaker-profiles-toggle-current"
204
+ @click="toggleCurrent"
205
+ >
206
+ <span class="sp-chip-dot" />
207
+ {{ currentIsOff ? 'Show this slide' : 'Hide this slide' }}
208
+ </button>
209
+ <button class="sp-chip sp-chip-quiet" title="Speaker profile" @click="editorOpen = true">
210
+ {{ speaker }} · {{ onCount }}/{{ nav.slides.value.length }}
211
+ </button>
212
+ </div>
213
+
214
+ <div v-if="editorOpen" class="sp-panel" data-testid="speaker-profiles-editor">
215
+ <header class="sp-head">
216
+ <div>
217
+ <strong>Speaker profile: {{ speaker }}</strong>
218
+ <div class="sp-sub">
219
+ {{ nav.slides.value.length - hiddenCount }} of {{ nav.slides.value.length }} slides on
220
+ </div>
221
+ </div>
222
+ <div class="sp-actions">
223
+ <span v-if="dirty && saveState !== 'saving'" class="sp-note sp-warn">unsaved</span>
224
+ <span v-if="saveState === 'saving'" class="sp-note">saving…</span>
225
+ <span v-else-if="saveState === 'saved'" class="sp-note sp-ok">saved</span>
226
+ <span v-else-if="saveState === 'error'" class="sp-note sp-err">{{ saveError }}</span>
227
+ <button class="sp-btn sp-primary" @click="save(currentIds)">
228
+ Save profile
229
+ </button>
230
+ <button class="sp-btn" @click="editorOpen = false">
231
+ Close
232
+ </button>
233
+ </div>
234
+ </header>
235
+
236
+ <div v-if="changes.added.length" class="sp-drift">
237
+ <div class="sp-drift-head">
238
+ <span>
239
+ {{ changes.added.length }} new slide(s) since your last change.
240
+ New slides are on by default.
241
+ </span>
242
+ <button v-if="changes.added.length" class="sp-btn" @click="hideAllNew">
243
+ Hide all new
244
+ </button>
245
+ </div>
246
+ <ul v-if="addedSlides.length" class="sp-drift-list">
247
+ <li v-for="slide in addedSlides" :key="slide.no">
248
+ <button class="sp-link" @click="goTo(slide.no)">{{ slide.no }}</button>
249
+ <span class="sp-drift-chapter">{{ slide.chapter }}</span>
250
+ {{ slide.title }}
251
+ </li>
252
+ </ul>
253
+ </div>
254
+
255
+ <div class="sp-body">
256
+ <section v-for="group in chapters" :key="group.name" class="sp-chapter">
257
+ <div class="sp-chapter-head">
258
+ <span>{{ group.name }}</span>
259
+ <span class="sp-chapter-actions">
260
+ <button class="sp-link" @click="toggleChapter(group.name, false)">all on</button>
261
+ <button class="sp-link" @click="toggleChapter(group.name, true)">all off</button>
262
+ </span>
263
+ </div>
264
+ <label
265
+ v-for="slide in group.slides"
266
+ :key="slide.id"
267
+ class="sp-row"
268
+ :class="{ 'sp-row-off': slide.off, 'sp-row-current': slide.no === nav.currentSlideNo.value }"
269
+ >
270
+ <input type="checkbox" :checked="!slide.off" @change="toggle(slide.id)">
271
+ <span class="sp-no" @click.prevent="goTo(slide.no)">{{ slide.no }}</span>
272
+ <span class="sp-title">{{ slide.title }}</span>
273
+ </label>
274
+ </section>
275
+ </div>
276
+ </div>
277
+ </template>
278
+ </template>
279
+
280
+ <style>
281
+ .sp-veil {
282
+ position: absolute;
283
+ inset: 0;
284
+ z-index: 2000;
285
+ background: var(--slidev-theme-background, #fff);
286
+ }
287
+
288
+ .sp-off-frame {
289
+ position: absolute;
290
+ inset: 0;
291
+ z-index: 1900;
292
+ pointer-events: none;
293
+ border: 4px solid rgba(255, 107, 107, 0.85);
294
+ }
295
+
296
+ .sp-off-badge {
297
+ position: absolute;
298
+ top: 0;
299
+ right: 0;
300
+ padding: 0.2rem 0.6rem;
301
+ font: 700 0.7rem/1.4 ui-sans-serif, system-ui, sans-serif;
302
+ letter-spacing: 0.16em;
303
+ color: #fff;
304
+ background: rgba(255, 107, 107, 0.92);
305
+ }
306
+
307
+ .sp-cluster {
308
+ position: absolute;
309
+ right: 1rem;
310
+ bottom: 1rem;
311
+ z-index: 2100;
312
+ display: flex;
313
+ gap: 0.4rem;
314
+ }
315
+
316
+ .sp-chip {
317
+ display: flex;
318
+ align-items: center;
319
+ gap: 0.45rem;
320
+ padding: 0.4rem 0.75rem;
321
+ font: 0.78rem/1.2 ui-sans-serif, system-ui, sans-serif;
322
+ color: #f4f4f6;
323
+ background: rgba(20, 20, 28, 0.88);
324
+ border: 1px solid rgba(255, 255, 255, 0.14);
325
+ border-radius: 999px;
326
+ cursor: pointer;
327
+ }
328
+
329
+ .sp-chip:disabled { opacity: 0.45; cursor: default; }
330
+ .sp-chip-quiet { opacity: 0.8; }
331
+
332
+ .sp-chip-dot {
333
+ width: 0.5rem;
334
+ height: 0.5rem;
335
+ border-radius: 999px;
336
+ background: #ff6b6b;
337
+ }
338
+
339
+ .sp-chip-on .sp-chip-dot { background: #00e676; }
340
+
341
+ .sp-cluster button, .sp-panel, .sp-panel * {
342
+ font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
343
+ }
344
+
345
+ .sp-panel {
346
+ position: fixed;
347
+ inset: 0;
348
+ z-index: 2100;
349
+ display: flex;
350
+ flex-direction: column;
351
+ color: #ececf1;
352
+ background: rgba(14, 14, 20, 0.97);
353
+ }
354
+
355
+ .sp-head {
356
+ display: flex;
357
+ align-items: center;
358
+ justify-content: space-between;
359
+ gap: 1rem;
360
+ padding: 0.9rem 1.2rem;
361
+ border-bottom: 1px solid rgba(255, 255, 255, 0.12);
362
+ }
363
+
364
+ .sp-sub { font-size: 0.78rem; opacity: 0.65; }
365
+ .sp-actions { display: flex; align-items: center; gap: 0.5rem; }
366
+ .sp-note { font-size: 0.75rem; opacity: 0.75; }
367
+ .sp-ok { color: #00e676; }
368
+ .sp-err { color: #ff6b6b; max-width: 22rem; }
369
+ .sp-warn { color: #ffd479; }
370
+
371
+ .sp-btn {
372
+ padding: 0.35rem 0.8rem;
373
+ font-size: 0.8rem;
374
+ color: inherit;
375
+ background: rgba(255, 255, 255, 0.08);
376
+ border: 1px solid rgba(255, 255, 255, 0.16);
377
+ border-radius: 0.35rem;
378
+ cursor: pointer;
379
+ }
380
+
381
+ .sp-primary { background: #335de5; border-color: #335de5; }
382
+
383
+ .sp-drift {
384
+ padding: 0.55rem 1.2rem;
385
+ font-size: 0.78rem;
386
+ color: #ffd479;
387
+ background: rgba(255, 212, 121, 0.09);
388
+ border-bottom: 1px solid rgba(255, 212, 121, 0.2);
389
+ }
390
+
391
+ .sp-drift-head {
392
+ display: flex;
393
+ align-items: center;
394
+ justify-content: space-between;
395
+ gap: 1rem;
396
+ }
397
+
398
+ .sp-drift-list {
399
+ max-height: 7.5rem;
400
+ margin: 0.4rem 0 0;
401
+ padding: 0;
402
+ overflow-y: auto;
403
+ list-style: none;
404
+ }
405
+
406
+ .sp-drift-list li {
407
+ display: flex;
408
+ align-items: baseline;
409
+ gap: 0.5rem;
410
+ padding: 0.1rem 0;
411
+ overflow: hidden;
412
+ white-space: nowrap;
413
+ text-overflow: ellipsis;
414
+ }
415
+
416
+ .sp-drift-chapter { opacity: 0.6; }
417
+
418
+ .sp-notice {
419
+ position: absolute;
420
+ bottom: 1rem;
421
+ left: 1rem;
422
+ z-index: 2100;
423
+ max-width: 26rem;
424
+ padding: 0.6rem 2.2rem 0.6rem 0.9rem;
425
+ font: 0.78rem/1.45 ui-sans-serif, system-ui, sans-serif;
426
+ color: #f4f4f6;
427
+ background: rgba(20, 20, 28, 0.9);
428
+ border: 1px solid rgba(255, 212, 121, 0.35);
429
+ border-radius: 0.5rem;
430
+ }
431
+
432
+ .sp-notice code {
433
+ padding: 0.05rem 0.3rem;
434
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
435
+ background: rgba(255, 255, 255, 0.1);
436
+ border-radius: 0.25rem;
437
+ }
438
+
439
+ .sp-notice-close {
440
+ position: absolute;
441
+ top: 0.15rem;
442
+ right: 0.35rem;
443
+ padding: 0.1rem 0.3rem;
444
+ font-size: 1rem;
445
+ color: inherit;
446
+ background: none;
447
+ border: 0;
448
+ cursor: pointer;
449
+ opacity: 0.6;
450
+ }
451
+
452
+ .sp-body {
453
+ flex: 1;
454
+ overflow-y: auto;
455
+ padding: 0.6rem 1.2rem 2rem;
456
+ columns: 2;
457
+ column-gap: 2.5rem;
458
+ }
459
+
460
+ .sp-chapter { break-inside: avoid-column; margin-bottom: 1.1rem; }
461
+
462
+ .sp-chapter-head {
463
+ display: flex;
464
+ justify-content: space-between;
465
+ padding: 0.3rem 0;
466
+ font-size: 0.72rem;
467
+ text-transform: uppercase;
468
+ letter-spacing: 0.08em;
469
+ opacity: 0.55;
470
+ border-bottom: 1px solid rgba(255, 255, 255, 0.1);
471
+ }
472
+
473
+ .sp-chapter-actions { display: flex; gap: 0.6rem; }
474
+
475
+ .sp-link {
476
+ color: inherit;
477
+ background: none;
478
+ border: 0;
479
+ font: inherit;
480
+ text-decoration: underline;
481
+ cursor: pointer;
482
+ }
483
+
484
+ .sp-row {
485
+ display: flex;
486
+ align-items: baseline;
487
+ gap: 0.5rem;
488
+ padding: 0.16rem 0;
489
+ font-size: 0.82rem;
490
+ cursor: pointer;
491
+ }
492
+
493
+ .sp-row-off .sp-title { opacity: 0.38; text-decoration: line-through; }
494
+ .sp-row-current { background: rgba(51, 93, 229, 0.22); border-radius: 0.25rem; }
495
+ .sp-no { min-width: 2.1rem; font-variant-numeric: tabular-nums; opacity: 0.5; text-align: right; }
496
+ .sp-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
497
+ </style>
package/identity.mjs ADDED
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Slide identity, shared by the preparser and the dev server.
3
+ *
4
+ * The id of a slide is the `id:` in its frontmatter, written there once by
5
+ * the `slide-ids` command and never touched again. It survives a retitle, a
6
+ * move within the chapter and a move to another chapter, which is what a
7
+ * speaker's selection needs: nothing about the slide's content or position can
8
+ * make a profile point at the wrong slide.
9
+ *
10
+ * Everything below the first step is a fallback for the seconds between writing
11
+ * a new slide and `slide-ids --stamp` running.
12
+ * It is derived from file plus title, so it is stable enough to work with and
13
+ * fragile enough that `slide-ids --check` refuses to let it reach main.
14
+ *
15
+ * Resolution chain, in order:
16
+ * 1. an explicit `id:` in the slide frontmatter (the normal case)
17
+ * 2. `<file-slug>/<title-slug>` plus `~n` for the 2nd, 3rd ... occurrence
18
+ * 3. `<file-slug>/untitled~n` when a slide has no title at all
19
+ *
20
+ * `transformSlide` does not receive the file path, so the file is identified by
21
+ * hashing the raw lines Slidev hands to `transformRawLines` and looking the
22
+ * hash up in an index of the deck's markdown files. That keeps Slidev in charge
23
+ * of splitting slides, which is the fragile part we do not want to re-implement.
24
+ */
25
+ import { createHash } from 'node:crypto'
26
+ import { readFileSync, readdirSync, statSync } from 'node:fs'
27
+ import { basename, extname, join, relative, sep } from 'node:path'
28
+
29
+ const SKIP_DIRS = new Set(['node_modules', 'dist', '.git', 'public', 'resources', '.slidev'])
30
+
31
+ /**
32
+ * Folder names that only say "slides live in here" and carry no meaning of
33
+ * their own. Dropped from the front of a label so the useful part leads.
34
+ */
35
+ const CONTAINER_DIRS = new Set(['chapter', 'chapters', 'content', 'contents', 'slides', 'pages', 'src'])
36
+
37
+ /**
38
+ * The label a slide's file contributes to the editor's grouping.
39
+ *
40
+ * Deliberately NOT the file name. A deck is free to call every one of its files
41
+ * `slides.md` and tell them apart by folder (both developer trainings do), and
42
+ * a basename would then collapse the whole deck into one group. The folder path
43
+ * is what actually says where a slide sits, at any nesting depth:
44
+ *
45
+ * chapter/03-bpmn-foundations/03-bpmn-foundations.md -> 03-bpmn-foundations
46
+ * content/1-fundamentals/01-about-miragon/slides.md -> 1-fundamentals/01-about-miragon
47
+ * slides.md -> slides
48
+ */
49
+ export function chapterLabel(root, file) {
50
+ const segments = relative(root, file).split(sep)
51
+ const dirs = segments.slice(0, -1)
52
+ if (!dirs.length)
53
+ return basename(file, extname(file))
54
+ const trimmed = CONTAINER_DIRS.has(dirs[0]) ? dirs.slice(1) : dirs
55
+ return (trimmed.length ? trimmed : dirs).join('/')
56
+ }
57
+
58
+ export function normalise(text) {
59
+ return text.split(/\r?\n/).join('\n')
60
+ }
61
+
62
+ export function hashContent(text) {
63
+ return createHash('sha1').update(normalise(text)).digest('hex')
64
+ }
65
+
66
+ /** Every markdown file under the deck, absolute paths, in a stable order. */
67
+ export function walkMarkdownFiles(root) {
68
+ const found = []
69
+ const walk = (dir) => {
70
+ let entries
71
+ try {
72
+ entries = readdirSync(dir)
73
+ }
74
+ catch {
75
+ return
76
+ }
77
+ for (const entry of entries.sort()) {
78
+ if (SKIP_DIRS.has(entry) || entry.startsWith('.'))
79
+ continue
80
+ const full = join(dir, entry)
81
+ let stat
82
+ try {
83
+ stat = statSync(full)
84
+ }
85
+ catch {
86
+ continue
87
+ }
88
+ if (stat.isDirectory())
89
+ walk(full)
90
+ else if (extname(entry) === '.md')
91
+ found.push(full)
92
+ }
93
+ }
94
+ walk(root)
95
+ return found
96
+ }
97
+
98
+ /** Map sha1(file content) -> chapter label, for every markdown file under the deck. */
99
+ export function indexMarkdownFiles(root) {
100
+ const index = new Map()
101
+ for (const file of walkMarkdownFiles(root)) {
102
+ try {
103
+ index.set(hashContent(readFileSync(file, 'utf-8')), chapterLabel(root, file))
104
+ }
105
+ catch {
106
+ // unreadable file, skip
107
+ }
108
+ }
109
+ return index
110
+ }
111
+
112
+ const RE_HEADING = /^\s{0,3}#{1,6}\s+(.+?)\s*$/m
113
+
114
+ export function titleOf(content, frontmatter) {
115
+ if (typeof frontmatter?.title === 'string' && frontmatter.title.trim())
116
+ return frontmatter.title.trim()
117
+ const heading = content.match(RE_HEADING)
118
+ if (heading)
119
+ return heading[1].replace(/\*\*/g, '').replace(/`/g, '').trim()
120
+ return ''
121
+ }
122
+
123
+ export function slugify(text) {
124
+ return text
125
+ .toLowerCase()
126
+ .normalize('NFKD')
127
+ .replace(/[\u0300-\u036f]/g, '')
128
+ .replace(/[^a-z0-9]+/g, '-')
129
+ .replace(/^-+|-+$/g, '')
130
+ .slice(0, 60) || 'untitled'
131
+ }
132
+
133
+ /**
134
+ * Stateful id assigner for one load pass. `startFile` is called once per
135
+ * markdown file (from `transformRawLines`), `next` once per slide of that file.
136
+ */
137
+ export function createIdAssigner(fileIndex) {
138
+ let fileSlug = 'unknown'
139
+ let counters = new Map()
140
+
141
+ return {
142
+ startFile(rawLines) {
143
+ fileSlug = fileIndex.get(hashContent(rawLines.join('\n'))) ?? 'unknown'
144
+ counters = new Map()
145
+ },
146
+ /**
147
+ * Which chapter file we are in. The id no longer says, so the editor's
148
+ * grouping asks here and the preparser hands the answer to the client.
149
+ */
150
+ file() {
151
+ return fileSlug
152
+ },
153
+ next(content, frontmatter) {
154
+ if (typeof frontmatter?.id === 'string' && frontmatter.id.trim())
155
+ return frontmatter.id.trim()
156
+ const slug = slugify(titleOf(content, frontmatter))
157
+ const n = (counters.get(slug) ?? 0) + 1
158
+ counters.set(slug, n)
159
+ return n === 1 ? `${fileSlug}/${slug}` : `${fileSlug}/${slug}~${n}`
160
+ },
161
+ }
162
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@miragon/slidev-speaker-profiles",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "description": "Per-speaker slide selection for a Slidev deck several people present. Each speaker keeps their own profile file, nobody overwrites anybody, and main never changes. Slides are addressed by a stable id the shipped slide-ids CLI stamps into their frontmatter, so a selection survives retitling, reordering and renumbered chapters.",
6
+ "keywords": [
7
+ "slidev",
8
+ "slidev-addon",
9
+ "miragon",
10
+ "speaker",
11
+ "presentation"
12
+ ],
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/Miragon/slidev-deck-template.git",
17
+ "directory": "packages/speaker-profiles"
18
+ },
19
+ "homepage": "https://github.com/Miragon/slidev-deck-template/tree/main/packages/speaker-profiles#readme",
20
+ "bugs": "https://github.com/Miragon/slidev-deck-template/issues",
21
+ "bin": {
22
+ "slide-ids": "bin/slide-ids.mjs"
23
+ },
24
+ "slidev": {},
25
+ "engines": {
26
+ "node": ">=20",
27
+ "slidev": ">=0.48.0"
28
+ },
29
+ "dependencies": {
30
+ "@slidev/parser": "52.19.0"
31
+ },
32
+ "devDependencies": {
33
+ "@slidev/types": "52.19.0"
34
+ },
35
+ "peerDependencies": {
36
+ "vue": "^3.5.0"
37
+ },
38
+ "files": [
39
+ "bin",
40
+ "setup",
41
+ "global-top.vue",
42
+ "slide-top.vue",
43
+ "state.ts",
44
+ "stamp.mjs",
45
+ "identity.mjs",
46
+ "profiles.mjs"
47
+ ],
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "provenance": true
51
+ }
52
+ }