@miragon/slidev-speaker-profiles 0.2.3 → 0.4.0-beta.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/README.md CHANGED
@@ -94,6 +94,43 @@ SLIDEV_PROFILE=thomas npm run build
94
94
 
95
95
  Here the switched-off slides are really removed, not just skipped.
96
96
 
97
+ ## Keeping a slide, with less on it
98
+
99
+ Sometimes the slide should stay and only its detail should go: three cards in a
100
+ lightning talk, titles only, while the published deck keeps the text because
101
+ nobody is there to say it.
102
+
103
+ In `dev:profile`, **Reduce this slide** sits next to **Hide this slide**. One
104
+ click, saved immediately, and the slide renders the way the room will see it.
105
+ On a slide with nothing to reduce the button says so and changes nothing.
106
+
107
+ What counts as detail is decided once, by the theme, per component. With
108
+ `@miragon/slidev-toolkit` that is the body of a titled `Card`, the text after a
109
+ `Step` label and a `Figure` caption. Everything marked on a slide goes together.
110
+
111
+ A reduced slide is reduced wherever the profile applies: presenting, the
112
+ presenter view, the overview, and a build or export that names the profile.
113
+ Without a profile nothing is reduced.
114
+
115
+ A profile is a named cut, so it does not have to be a person:
116
+ `SLIDEV_PROFILE=lightning` is as valid as `SLIDEV_PROFILE=thomas`.
117
+
118
+ **This is presentation, not redaction.** The detail is not displayed, so it is
119
+ not in the PDF either, but it still ships inside a built deck. To keep content
120
+ out of a build, hide the slide.
121
+
122
+ ### For theme authors
123
+
124
+ Put `data-detail` on any element a slide still works without:
125
+
126
+ ```vue
127
+ <div class="card-body" data-detail><slot /></div>
128
+ ```
129
+
130
+ That is the whole contract. The addon hides those elements on a reduced slide;
131
+ the theme ships no CSS for it and never imports the addon. A theme that marks
132
+ nothing has nothing to reduce.
133
+
97
134
  ## When the deck moves on
98
135
 
99
136
  **New slides are on by default**, so a slide somebody adds shows up rather than
@@ -166,6 +203,7 @@ slide-ids --stamp --also 'chapter/*/*.md'
166
203
  "schemaVersion": 1,
167
204
  "speaker": "thomas",
168
205
  "hidden": ["s-4b81f0ac", "s-9d2e77c1"],
206
+ "reduced": ["s-4e0c2290"],
169
207
  "order": null,
170
208
  "knownIds": ["s-29076475", "..."]
171
209
  }
@@ -182,6 +220,9 @@ time they saved, which is how "new since your last change" is computed. **Unknow
182
220
  means visible.** Ids that vanished are reported but never dropped from `hidden`,
183
221
  because the slide may come back on another branch.
184
222
 
223
+ `reduced` is what the speaker kept, without its detail. A file written before
224
+ that existed has no such key and reads as an empty list.
225
+
185
226
  `order` is reserved for reordering and is always `null` today.
186
227
 
187
228
  Gitignore two entries in `.slidev-profiles/`: `.current`, which says which
package/global-top.vue CHANGED
@@ -26,6 +26,7 @@ import {
26
26
  hiddenIds,
27
27
  initFromSlides,
28
28
  isHidden,
29
+ isReduced,
29
30
  isSlideOff,
30
31
  ensureLoaded,
31
32
  ready,
@@ -37,6 +38,7 @@ import {
37
38
  slideTitle,
38
39
  speaker,
39
40
  toggle,
41
+ toggleReduced,
40
42
  } from './state'
41
43
 
42
44
  const nav = useNav()
@@ -96,8 +98,33 @@ async function toggleCurrent() {
96
98
  await save(currentIds.value)
97
99
  }
98
100
 
101
+ const currentIsReduced = computed(() => isReduced(currentId.value))
102
+ const nothingToReduce = ref(false)
103
+
104
+ function currentSlideHasDetail() {
105
+ return !!document.querySelector(`[data-slidev-no="${nav.currentSlideNo.value}"] [data-detail]`)
106
+ }
107
+
108
+ async function toggleReducedCurrent() {
109
+ if (!currentId.value)
110
+ return
111
+ if (!currentIsReduced.value && !currentSlideHasDetail()) {
112
+ nothingToReduce.value = true
113
+ setTimeout(() => { nothingToReduce.value = false }, 2000)
114
+ return
115
+ }
116
+ toggleReduced(currentId.value)
117
+ await save(currentIds.value)
118
+ }
119
+
120
+ const reduceLabel = computed(() => {
121
+ if (nothingToReduce.value)
122
+ return 'Nothing to reduce here'
123
+ return currentIsReduced.value ? 'Show full slide' : 'Reduce this slide'
124
+ })
125
+
99
126
  const chapters = computed(() => {
100
- const groups: { name: string, slides: { no: number, id: string, title: string, off: boolean }[] }[] = []
127
+ const groups: { name: string, slides: { no: number, id: string, title: string, off: boolean, reduced: boolean }[] }[] = []
101
128
  for (const route of nav.slides.value) {
102
129
  const id = slideId(route)
103
130
  if (!id)
@@ -108,7 +135,7 @@ const chapters = computed(() => {
108
135
  group = { name, slides: [] }
109
136
  groups.push(group)
110
137
  }
111
- group.slides.push({ no: route.no, id, title: slideTitle(route), off: isHidden(id) })
138
+ group.slides.push({ no: route.no, id, title: slideTitle(route), off: isHidden(id), reduced: isReduced(id) })
112
139
  }
113
140
  return groups
114
141
  })
@@ -206,6 +233,15 @@ function goTo(no: number) {
206
233
  <span class="sp-chip-dot" />
207
234
  {{ currentIsOff ? 'Show this slide' : 'Hide this slide' }}
208
235
  </button>
236
+ <button
237
+ class="sp-chip"
238
+ :disabled="!currentId || saveState === 'saving'"
239
+ :title="currentIsReduced ? 'Show the detail on this slide again' : 'Keep this slide, without its detail'"
240
+ data-testid="speaker-profiles-toggle-reduced"
241
+ @click="toggleReducedCurrent"
242
+ >
243
+ {{ reduceLabel }}
244
+ </button>
209
245
  <button class="sp-chip sp-chip-quiet" title="Speaker profile" @click="editorOpen = true">
210
246
  {{ speaker }} · {{ onCount }}/{{ nav.slides.value.length }}
211
247
  </button>
@@ -270,6 +306,7 @@ function goTo(no: number) {
270
306
  <input type="checkbox" :checked="!slide.off" @change="toggle(slide.id)">
271
307
  <span class="sp-no" @click.prevent="goTo(slide.no)">{{ slide.no }}</span>
272
308
  <span class="sp-title">{{ slide.title }}</span>
309
+ <span v-if="slide.reduced" class="sp-tag">reduced</span>
273
310
  </label>
274
311
  </section>
275
312
  </div>
@@ -494,4 +531,5 @@ function goTo(no: number) {
494
531
  .sp-row-current { background: rgba(51, 93, 229, 0.22); border-radius: 0.25rem; }
495
532
  .sp-no { min-width: 2.1rem; font-variant-numeric: tabular-nums; opacity: 0.5; text-align: right; }
496
533
  .sp-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
534
+ .sp-tag { flex: 0 0 auto; padding: 0 0.4rem; font-size: 0.68rem; opacity: 0.7; border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 999px; }
497
535
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miragon/slidev-speaker-profiles",
3
- "version": "0.2.3",
3
+ "version": "0.4.0-beta.0",
4
4
  "type": "module",
5
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
6
  "keywords": [
@@ -21,17 +21,20 @@
21
21
  "bin": {
22
22
  "slide-ids": "bin/slide-ids.mjs"
23
23
  },
24
+ "scripts": {
25
+ "test": "node --test"
26
+ },
24
27
  "slidev": {},
25
28
  "engines": {
26
29
  "node": ">=20",
27
30
  "slidev": ">=0.48.0"
28
31
  },
29
32
  "devDependencies": {
30
- "@slidev/parser": "52.19.1",
31
- "@slidev/types": "52.19.1"
33
+ "@slidev/parser": "53.0.0",
34
+ "@slidev/types": "53.0.0"
32
35
  },
33
36
  "peerDependencies": {
34
- "@slidev/parser": "^52.0.0",
37
+ "@slidev/parser": "^53.0.0",
35
38
  "vue": "3.5.43"
36
39
  },
37
40
  "files": [
package/profiles.mjs CHANGED
@@ -91,12 +91,13 @@ export function isValidName(name) {
91
91
  export function readProfile(root, speaker) {
92
92
  const file = profilePath(root, speaker)
93
93
  if (!existsSync(file))
94
- return { schemaVersion: SCHEMA_VERSION, speaker, hidden: [], order: null, knownIds: [] }
94
+ return { schemaVersion: SCHEMA_VERSION, speaker, hidden: [], reduced: [], order: null, knownIds: [] }
95
95
  const raw = JSON.parse(readFileSync(file, 'utf-8'))
96
96
  return {
97
97
  schemaVersion: raw.schemaVersion ?? SCHEMA_VERSION,
98
98
  speaker,
99
99
  hidden: Array.isArray(raw.hidden) ? raw.hidden : [],
100
+ reduced: Array.isArray(raw.reduced) ? raw.reduced : [],
100
101
  order: raw.order ?? null,
101
102
  knownIds: Array.isArray(raw.knownIds) ? raw.knownIds : [],
102
103
  }
@@ -110,6 +111,7 @@ export function writeProfile(root, speaker, profile) {
110
111
  schemaVersion: SCHEMA_VERSION,
111
112
  speaker,
112
113
  hidden: [...new Set(profile.hidden ?? [])].sort(),
114
+ reduced: [...new Set(profile.reduced ?? [])].sort(),
113
115
  order: profile.order ?? null,
114
116
  knownIds: [...new Set(profile.knownIds ?? [])].sort(),
115
117
  }
@@ -44,9 +44,10 @@ export default function ({ filepath, mode }: { filepath: string, headmatter: Rec
44
44
 
45
45
  const profile = speaker ? readProfile(profilesRoot, speaker) : undefined
46
46
  const hidden = new Set<string>(profile?.hidden ?? [])
47
+ const reduced = new Set<string>(profile?.reduced ?? [])
47
48
 
48
49
  if (speaker)
49
- console.log(`[speaker-profiles] profile "${speaker}": ${hidden.size} slide(s) off, ${shouldHide ? 'removed from this build' : 'skipped at runtime'}`)
50
+ console.log(`[speaker-profiles] profile "${speaker}": ${hidden.size} slide(s) off, ${shouldHide ? 'removed from this build' : 'skipped at runtime'}, ${reduced.size} reduced`)
50
51
  else
51
52
  console.log(`[speaker-profiles] no profile selected (${isDev ? 'set SLIDEV_PROFILE or .slidev-profiles/.current' : 'set SLIDEV_PROFILE'}) - showing the full deck`)
52
53
 
@@ -82,6 +83,8 @@ export default function ({ filepath, mode }: { filepath: string, headmatter: Rec
82
83
  else
83
84
  frontmatter['data-profile-off'] = true
84
85
  }
86
+ if (reduced.has(id))
87
+ frontmatter['data-profile-reduced'] = true
85
88
  return undefined
86
89
  },
87
90
  }]
@@ -84,6 +84,7 @@ export default function (options: any) {
84
84
  const userRoot = options.userRoot as string
85
85
  const profilesRoot = findProfilesRoot(userRoot)
86
86
  const editable = process.env.SLIDEV_PROFILE_EDIT === '1'
87
+ const sameSpeakerAsThePreparser = { allowCurrentFile: options.mode === 'dev' }
87
88
 
88
89
  return {
89
90
  name: 'speaker-profiles:server',
@@ -94,7 +95,7 @@ export default function (options: any) {
94
95
  void stampOnce(options.entry as string, profilesRoot)
95
96
 
96
97
  server.middlewares.use(`${BASE}/state`, (_req: any, res: any) => {
97
- const speaker = resolveSpeaker(profilesRoot)
98
+ const speaker = resolveSpeaker(profilesRoot, sameSpeakerAsThePreparser)
98
99
  json(res, 200, {
99
100
  editable,
100
101
  speaker: speaker ?? null,
@@ -115,10 +116,11 @@ export default function (options: any) {
115
116
  return json(res, 400, { error: `invalid profile name "${speaker}"` })
116
117
  const written = writeProfile(profilesRoot, speaker, {
117
118
  hidden: payload.hidden ?? [],
119
+ reduced: payload.reduced ?? [],
118
120
  order: payload.order ?? null,
119
121
  knownIds: payload.knownIds ?? [],
120
122
  })
121
- console.log(`[speaker-profiles] saved ${speaker}.json (${written.hidden.length} off)`)
123
+ console.log(`[speaker-profiles] saved ${speaker}.json (${written.hidden.length} off, ${written.reduced.length} reduced)`)
122
124
  return json(res, 200, { ok: true, profile: written })
123
125
  }
124
126
  catch (error: any) {
package/slide-top.vue CHANGED
@@ -11,13 +11,14 @@
11
11
  * Interaction is not possible here: the overview wraps each card in
12
12
  * `pointer-events: none` and puts its own click handler on the parent.
13
13
  */
14
- import { useSlideContext } from '@slidev/client'
14
+ import { useNav, useSlideContext } from '@slidev/client'
15
15
  import { computed } from 'vue'
16
- import { ensureLoaded, isHidden } from './state'
16
+ import { ensureLoaded, initFromSlides, isHidden, isReduced } from './state'
17
17
 
18
18
  const { $renderContext, $frontmatter } = useSlideContext()
19
19
 
20
20
  // the standalone /overview/ page renders these without a GlobalTop above them
21
+ initFromSlides(useNav().slides.value)
21
22
  ensureLoaded()
22
23
 
23
24
  const id = computed(() => ($frontmatter as any)?.['data-profile-id'] as string | undefined)
@@ -25,9 +26,11 @@ const show = computed(() =>
25
26
  (['overview', 'previewNext'].includes($renderContext.value))
26
27
  && isHidden(id.value),
27
28
  )
29
+ const reduced = computed(() => isReduced(id.value))
28
30
  </script>
29
31
 
30
32
  <template>
33
+ <i v-if="reduced" class="speaker-profiles-reduced" data-testid="speaker-profiles-reduced" hidden />
31
34
  <div v-if="show" class="speaker-profiles-dim" data-testid="speaker-profiles-dim">
32
35
  <div class="speaker-profiles-dim-label">
33
36
  OFF
@@ -36,6 +39,10 @@ const show = computed(() =>
36
39
  </template>
37
40
 
38
41
  <style>
42
+ :has(> .speaker-profiles-reduced) [data-detail] {
43
+ display: none !important;
44
+ }
45
+
39
46
  .speaker-profiles-dim {
40
47
  position: absolute;
41
48
  inset: 0;
package/state.ts CHANGED
@@ -10,6 +10,7 @@ import type { SlideRoute } from '@slidev/types'
10
10
  import { computed, ref } from 'vue'
11
11
 
12
12
  export const hiddenIds = ref<Set<string>>(new Set())
13
+ export const reducedIds = ref<Set<string>>(new Set())
13
14
  export const knownIds = ref<string[]>([])
14
15
  export const speaker = ref<string | null>(null)
15
16
  export const editable = ref(false)
@@ -62,12 +63,17 @@ export function initFromSlides(slides: SlideRoute[]) {
62
63
  return
63
64
  initialised = true
64
65
  const off = new Set<string>()
66
+ const reduced = new Set<string>()
65
67
  for (const route of slides) {
66
68
  const id = slideId(route)
67
- if (id && (route.meta?.slide?.frontmatter as any)?.['data-profile-off'])
69
+ const frontmatter = route.meta?.slide?.frontmatter as any
70
+ if (id && frontmatter?.['data-profile-off'])
68
71
  off.add(id)
72
+ if (id && frontmatter?.['data-profile-reduced'])
73
+ reduced.add(id)
69
74
  }
70
75
  hiddenIds.value = off
76
+ reducedIds.value = reduced
71
77
  dirty.value = false
72
78
  }
73
79
 
@@ -89,6 +95,18 @@ export function toggle(id: string) {
89
95
  dirty.value = true
90
96
  }
91
97
 
98
+ export function isReduced(id: string | undefined) {
99
+ return !!id && reducedIds.value.has(id)
100
+ }
101
+
102
+ export function toggleReduced(id: string) {
103
+ const next = new Set(reducedIds.value)
104
+ if (!next.delete(id))
105
+ next.add(id)
106
+ reducedIds.value = next
107
+ dirty.value = true
108
+ }
109
+
92
110
  export const hiddenCount = computed(() => hiddenIds.value.size)
93
111
 
94
112
  /**
@@ -137,6 +155,7 @@ export async function loadServerState() {
137
155
  knownIds.value = data.profile?.knownIds ?? []
138
156
  if (data.profile) {
139
157
  hiddenIds.value = new Set<string>(data.profile.hidden ?? [])
158
+ reducedIds.value = new Set<string>(data.profile.reduced ?? [])
140
159
  dirty.value = false
141
160
  }
142
161
  }
@@ -173,6 +192,7 @@ export async function save(currentIds: string[]) {
173
192
  body: JSON.stringify({
174
193
  speaker: speaker.value,
175
194
  hidden: [...hiddenIds.value],
195
+ reduced: [...reducedIds.value],
176
196
  order: null,
177
197
  // Additive, never a replacement. Saving from a single-chapter run must
178
198
  // not shrink what this profile has already seen, or every slide of the