@serene-pub/core-catalog 0.6.0-pr-6 → 0.6.0-pr-7
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/components/shared/messages/MessageControls.svelte +151 -4
- package/components/shared/messages/MessageMediaStrip.svelte +4 -1
- package/components/shared/messages/SessionMessage.svelte +185 -12
- package/components/shared/messages/SpokenLine.svelte +273 -0
- package/components/shared/messages/conversation.svelte.ts +79 -1
- package/components/shared/messages/spokenLine.ts +177 -0
- package/dist/components/actions.js +6 -7
- package/dist/components/actions.source.json +1 -1
- package/dist/components/album.js +2 -4
- package/dist/components/album.source.json +1 -1
- package/dist/components/annex.js +2 -2
- package/dist/components/annex.source.json +1 -1
- package/dist/components/attendance.js +1 -1
- package/dist/components/attendance.source.json +1 -1
- package/dist/components/authors-note.js +1 -1
- package/dist/components/authors-note.source.json +1 -1
- package/dist/components/backdrop.js +4 -5
- package/dist/components/backdrop.source.json +1 -1
- package/dist/components/chronicle.js +1 -1
- package/dist/components/chronicle.source.json +1 -1
- package/dist/components/core-ui.json +1 -1
- package/dist/components/lore-entries.js +1 -1
- package/dist/components/lore-entries.source.json +1 -1
- package/dist/components/messages.js +1453 -696
- package/dist/components/messages.source.json +1 -1
- package/dist/components/places.js +6 -6
- package/dist/components/places.source.json +1 -1
- package/dist/components/routine-log.js +1 -1
- package/dist/components/routine-log.source.json +1 -1
- package/dist/components/scene-portraits.js +5 -5
- package/dist/components/scene-portraits.source.json +1 -1
- package/dist/components/shared-4ME6NFDK.js +277 -0
- package/dist/components/{shared-E2Y4ILGR.js → shared-7VDIXYAL.js} +1 -1
- package/dist/components/{shared-4RLNEXUH.js → shared-BBF64YGL.js} +9 -6
- package/dist/components/{shared-KYLSTWAJ.js → shared-BIWKZFUU.js} +3 -3
- package/dist/components/{shared-53LSB5XW.js → shared-JPG5DQO7.js} +598 -6
- package/dist/components/{shared-5YNCLFKM.js → shared-QXF5CJVN.js} +4 -2
- package/dist/components/{shared-WWDBUSJ5.js → shared-WV3QTKZT.js} +2 -2
- package/dist/components/{shared-3QXBXWVS.js → shared-XBDUENRA.js} +1 -1
- package/dist/components/{shared-YMBM3PBR.js → shared-YDS7HYL6.js} +30 -3
- package/dist/components/stats.js +6 -6
- package/dist/components/stats.source.json +1 -1
- package/dist/components/turn-order.js +5 -6
- package/dist/components/turn-order.source.json +1 -1
- package/dist/functions/time.d.ts +9 -3
- package/dist/functions/time.js +33 -10
- package/dist/genres/defaults.d.ts +24 -0
- package/dist/genres/defaults.js +17 -0
- package/dist/genres/guide/respond.js +18 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +16 -2
- package/dist/primers/ninth-mile.d.ts +16 -0
- package/dist/primers/ninth-mile.js +68 -0
- package/dist/registry/genres.d.ts +3 -1
- package/dist/registry/genres.js +12 -4
- package/dist/registry/primers.d.ts +3 -1
- package/dist/registry/primers.js +7 -2
- package/dist/registry/rulesets.d.ts +94 -0
- package/dist/registry/slots.d.ts +86 -0
- package/dist/registry/slots.js +70 -1
- package/dist/rulesets/archetypes/cardGame.js +1 -1
- package/dist/rulesets/archetypes/romance.js +2 -2
- package/dist/rulesets/archetypes/sliceOfLife.js +5 -4
- package/dist/rulesets/archetypes/workplace.js +4 -4
- package/dist/rulesets/templates/d20Style.js +1 -1
- package/dist/rulesets/templates/dicePool.js +1 -1
- package/dist/rulesets/templates/dicelessPools.js +1 -1
- package/dist/rulesets/templates/slots.d.ts +8 -0
- package/dist/rulesets/templates/slots.js +1 -0
- package/dist/rulesets/vis-itineris/slots.d.ts +37 -0
- package/dist/rulesets/vis-itineris/slots.js +16 -0
- package/dist/rulesets/wherewithal/slots.d.ts +4 -0
- package/dist/rulesets/wherewithal/slots.js +1 -0
- package/dist/seed/prompts.js +20 -0
- package/dist/seed/scripts.js +3 -0
- package/dist/seed/speechTemplates.d.ts +106 -0
- package/dist/seed/speechTemplates.js +201 -0
- package/dist/shared/characterReachesOut.d.ts +14 -0
- package/dist/shared/characterReachesOut.js +66 -0
- package/dist/shared/speakMessage.d.ts +12 -0
- package/dist/shared/speakMessage.js +157 -0
- package/dist/shared/speechFields.d.ts +37 -0
- package/dist/shared/speechFields.js +83 -0
- package/dist/shared/ui/conversation/messageVerbState.d.ts +11 -1
- package/dist/shared/ui/conversation/messageVerbState.js +9 -3
- package/dist/shared/ui/widgetContext.d.ts +2 -2
- package/dist/shared/weather.d.ts +16 -0
- package/dist/shared/weather.js +86 -0
- package/package.json +8 -8
- package/dist/components/shared-QCE7JYD3.js +0 -101
- package/dist/components/shared-XKA5BV4M.js +0 -51
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* 🚧 **The spoken line** (speech build lane E; design §6.4; polish pass
|
|
4
|
+
* 2026-10-29): under a line that was spoken — a `core:audio` part and
|
|
5
|
+
* `metadata.spoken` — one compact strip: a state glyph, the browser's own
|
|
6
|
+
* player, the clock, who spoke (a voice chip, and the mood when there is
|
|
7
|
+
* one) and a `⋯` with *Say it as…*. The speak verbs *Read aloud* / *Say it
|
|
8
|
+
* again* and *Stop* live in the message heading; this strip keeps only a
|
|
9
|
+
* small Stop while it is speaking. A spoken line whose file is gone reads
|
|
10
|
+
* *Not spoken yet*, never a broken player.
|
|
11
|
+
*
|
|
12
|
+
* The player is the browser's own (`<audio controls>`): a component runs
|
|
13
|
+
* in the UI worker and speaks to the page in attributes and events only,
|
|
14
|
+
* so it cannot call `play()`. Hence:
|
|
15
|
+
*
|
|
16
|
+
* - **Autoplay** is the `autoplay` attribute (core's alone), decided ONCE
|
|
17
|
+
* per audio part: under *Make and play*, the NEWEST line's audio, spoken
|
|
18
|
+
* since this page opened and still fresh — never an older line, never
|
|
19
|
+
* on page load. A browser that refuses a sound nobody asked for leaves
|
|
20
|
+
* the player waiting; its own play button is right there.
|
|
21
|
+
* - **The playhead** arrives as the host `audio` events (1.7: `play`,
|
|
22
|
+
* `pause`, `ended`, `timeupdate` with `{ currentTime, duration, paused }`,
|
|
23
|
+
* seconds). They drive the state glyph, the clock and the **caption**: the
|
|
24
|
+
* words of the cue playing now, read off the recorded cue map.
|
|
25
|
+
* - **Speaking…** (speech follow-ups A4): while the line's speak run is live
|
|
26
|
+
* (`metadata.spoken.pending`, a run id) the line reads *Speaking…* with a
|
|
27
|
+
* small **Stop** that raises `onStop(runId)` — the host cancels that run. The
|
|
28
|
+
* line mounts for a pending run even before it has any audio; when the
|
|
29
|
+
* run ends, the audio lands and *Make and play* autoplays it as before
|
|
30
|
+
* (the `at` of the new record is what freshness reads, not the marker).
|
|
31
|
+
*/
|
|
32
|
+
import type { SpokenMeta } from '@serene-pub/sdk/component'
|
|
33
|
+
import { mediaSrc, type MediaStripItem } from './mediaStrip'
|
|
34
|
+
import {
|
|
35
|
+
cueCaptionAt,
|
|
36
|
+
formatClock,
|
|
37
|
+
isFresh,
|
|
38
|
+
isOwnVoice,
|
|
39
|
+
isSpeaking,
|
|
40
|
+
moodOf,
|
|
41
|
+
playbackOf,
|
|
42
|
+
spokenAsLine,
|
|
43
|
+
spokenSinceLoad,
|
|
44
|
+
voiceNameOf,
|
|
45
|
+
type Playback,
|
|
46
|
+
type SpokenPending,
|
|
47
|
+
} from './spokenLine'
|
|
48
|
+
|
|
49
|
+
interface Props {
|
|
50
|
+
/** What the speak step recorded; null while the line has only a pending run. */
|
|
51
|
+
spoken: SpokenMeta | null
|
|
52
|
+
/** The speak run in flight for this line, if any (`metadata.spoken.pending`). */
|
|
53
|
+
pending?: SpokenPending | null
|
|
54
|
+
/** The run ids in flight, off the host's run-status pushes; absent: none known. */
|
|
55
|
+
liveRunIds?: readonly string[]
|
|
56
|
+
/** Stop was pressed: the host cancels this run. */
|
|
57
|
+
onStop?: (runId: string) => void
|
|
58
|
+
/** The line's audio file; null while it has none. */
|
|
59
|
+
item: MediaStripItem | null
|
|
60
|
+
/** The newest line of the log. */
|
|
61
|
+
isLastMessage: boolean
|
|
62
|
+
/** The session's Read aloud setting. */
|
|
63
|
+
readAloud: 'off' | 'make' | 'play'
|
|
64
|
+
/** The viewer's own playback choice; `never` is handled by the host (no spoken line at all). */
|
|
65
|
+
spokenPlayback?: 'auto' | 'click' | 'never'
|
|
66
|
+
/** The recorded voice id's display name, when the host can say it (else the record's own). */
|
|
67
|
+
voiceName?: string | null
|
|
68
|
+
/** The speaker's face; drawn on the voice chip when the voice is the character's own. */
|
|
69
|
+
speakerFace?: string | null
|
|
70
|
+
/** *Say it as…*: offered only to a viewer who may; absent, the `⋯` is not drawn. */
|
|
71
|
+
onSayItAs?: () => void
|
|
72
|
+
/** The audio part's file failed to load (cleared, swept): the host may say Read aloud again. */
|
|
73
|
+
onGone?: (partId: number) => void
|
|
74
|
+
/** 🚧 Heading audio control: the conversation says this line's strip player is the playing one. */
|
|
75
|
+
playing?: boolean
|
|
76
|
+
/** The rewind counter: a Stop re-keys the player so it starts over (and never autoplays again). */
|
|
77
|
+
take?: number
|
|
78
|
+
/** The strip player's own play / pause / ended, for the conversation's one-playing-line state. */
|
|
79
|
+
onPlayback?: (paused: boolean) => void
|
|
80
|
+
/** The ⋮ › Speech player's playhead while it is the one playing this line: the caption and glyph follow it too. */
|
|
81
|
+
menuAt?: Playback | null
|
|
82
|
+
}
|
|
83
|
+
let {
|
|
84
|
+
spoken,
|
|
85
|
+
pending = null,
|
|
86
|
+
liveRunIds,
|
|
87
|
+
onStop,
|
|
88
|
+
item,
|
|
89
|
+
isLastMessage,
|
|
90
|
+
readAloud,
|
|
91
|
+
spokenPlayback = 'auto',
|
|
92
|
+
voiceName = null,
|
|
93
|
+
speakerFace = null,
|
|
94
|
+
onSayItAs,
|
|
95
|
+
onGone,
|
|
96
|
+
playing: shouldPlay = false,
|
|
97
|
+
take = 0,
|
|
98
|
+
onPlayback,
|
|
99
|
+
menuAt = null,
|
|
100
|
+
}: Props = $props()
|
|
101
|
+
|
|
102
|
+
/** Parts already auto-played this page life, so a re-render never plays twice. */
|
|
103
|
+
const played = ((globalThis as { __spAutoplayed?: Set<number> }).__spAutoplayed ??= new Set<number>())
|
|
104
|
+
/** The autoplay decision per audio part, taken once: a later change never re-creates a playing player. */
|
|
105
|
+
const decided = new Map<number, boolean>()
|
|
106
|
+
function decide(id: number): boolean {
|
|
107
|
+
const known = decided.get(id)
|
|
108
|
+
if (known !== undefined) return known
|
|
109
|
+
const yes =
|
|
110
|
+
spokenPlayback === 'auto' &&
|
|
111
|
+
readAloud === 'play' &&
|
|
112
|
+
isLastMessage &&
|
|
113
|
+
!played.has(id) &&
|
|
114
|
+
!!spoken &&
|
|
115
|
+
isFresh(spoken) &&
|
|
116
|
+
spokenSinceLoad(spoken)
|
|
117
|
+
decided.set(id, yes)
|
|
118
|
+
if (yes) played.add(id)
|
|
119
|
+
return yes
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The run id this view last saw in flight: a run seen live and gone since is over. */
|
|
123
|
+
let seenLive = $state<string | null>(null)
|
|
124
|
+
$effect(() => {
|
|
125
|
+
if (pending && liveRunIds?.includes(pending.runId)) seenLive = pending.runId
|
|
126
|
+
})
|
|
127
|
+
const speaking = $derived(isSpeaking(pending, liveRunIds, seenLive))
|
|
128
|
+
|
|
129
|
+
/** Per part id: its file failed to load (cleared, swept). */
|
|
130
|
+
let failedPart = $state<number | null>(null)
|
|
131
|
+
function fail(partId: number) {
|
|
132
|
+
failedPart = partId
|
|
133
|
+
onGone?.(partId)
|
|
134
|
+
}
|
|
135
|
+
const src = $derived(item ? mediaSrc(item.assetId) : null)
|
|
136
|
+
const gone = $derived(!item || failedPart === item.partId)
|
|
137
|
+
// Only the FIRST element of a part may autoplay: a Stop re-key (take > 0) never does.
|
|
138
|
+
const autoplay = $derived(item && spoken && !speaking && take === 0 ? decide(item.partId) : false)
|
|
139
|
+
|
|
140
|
+
/** The last thing the player said about itself, with the part it said it for. */
|
|
141
|
+
let heard = $state<{ part: number; at: Playback; ended: boolean } | null>(null)
|
|
142
|
+
const playback = $derived(item && heard && heard.part === item.partId ? heard : null)
|
|
143
|
+
const playing = $derived(!!playback && !playback.ended && !playback.at.paused)
|
|
144
|
+
const menuPlaying = $derived(!!menuAt && !menuAt.paused)
|
|
145
|
+
const caption = $derived(
|
|
146
|
+
spoken && menuPlaying && menuAt
|
|
147
|
+
? cueCaptionAt(spoken.cueMap, menuAt.currentTime)
|
|
148
|
+
: spoken && playing && playback
|
|
149
|
+
? cueCaptionAt(spoken.cueMap, playback.at.currentTime)
|
|
150
|
+
: null,
|
|
151
|
+
)
|
|
152
|
+
const clock = $derived(
|
|
153
|
+
playback && playback.at.duration > 0
|
|
154
|
+
? `${formatClock(playback.ended ? playback.at.duration : playback.at.currentTime)} / ${formatClock(playback.at.duration)}`
|
|
155
|
+
: null,
|
|
156
|
+
)
|
|
157
|
+
function hear(e: Event, ended = false) {
|
|
158
|
+
const at = playbackOf((e as CustomEvent).detail)
|
|
159
|
+
if (at && item) heard = { part: item.partId, at: ended ? { ...at, paused: true } : at, ended }
|
|
160
|
+
if (e.type === 'play') onPlayback?.(false)
|
|
161
|
+
else if (e.type === 'pause' || ended) onPlayback?.(true)
|
|
162
|
+
}
|
|
163
|
+
/** The host `audio`'s `playing` attribute (1.8): present while the conversation says so. */
|
|
164
|
+
const playAttr = $derived(shouldPlay ? { playing: '' } : {})
|
|
165
|
+
/** The player's events, spread on whichever `<audio>` is drawn. */
|
|
166
|
+
const listeners = {
|
|
167
|
+
onplay: (e: Event) => hear(e),
|
|
168
|
+
onpause: (e: Event) => hear(e),
|
|
169
|
+
ontimeupdate: (e: Event) => hear(e),
|
|
170
|
+
onended: (e: Event) => hear(e, true),
|
|
171
|
+
onloadedmetadata: (e: Event) => hear(e),
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const asLine = $derived(spoken ? spokenAsLine(spoken, voiceName) : '')
|
|
175
|
+
const name = $derived(spoken ? voiceNameOf(spoken, voiceName) : '')
|
|
176
|
+
const mood = $derived(spoken ? moodOf(spoken) : null)
|
|
177
|
+
const ownFace = $derived(spoken && speakerFace && isOwnVoice(spoken.spokenAs.voiceFrom) ? speakerFace : null)
|
|
178
|
+
</script>
|
|
179
|
+
|
|
180
|
+
<div
|
|
181
|
+
data-widget-part="messages.spoken-line"
|
|
182
|
+
role="group"
|
|
183
|
+
aria-label="Spoken line"
|
|
184
|
+
data-state={speaking ? 'speaking' : gone ? 'missing' : playing || menuPlaying ? 'playing' : 'ready'}
|
|
185
|
+
>
|
|
186
|
+
{#if speaking && pending}
|
|
187
|
+
<p data-widget-part="messages.spoken-pending" role="status">
|
|
188
|
+
<span data-widget-part="messages.spoken-pulse" aria-hidden="true"><span></span><span></span><span></span></span>
|
|
189
|
+
<span>Speaking…</span>
|
|
190
|
+
</p>
|
|
191
|
+
<button
|
|
192
|
+
type="button"
|
|
193
|
+
data-widget-part="messages.spoken-stop"
|
|
194
|
+
aria-label="Stop speaking this line"
|
|
195
|
+
title="Stop speaking this line"
|
|
196
|
+
onclick={() => onStop?.(pending.runId)}
|
|
197
|
+
>
|
|
198
|
+
<sp-icon name="square" size="14"></sp-icon>
|
|
199
|
+
</button>
|
|
200
|
+
{:else if !spoken}
|
|
201
|
+
<!-- A pending marker that ended with nothing recorded: nothing to show. -->
|
|
202
|
+
{:else if gone || !item}
|
|
203
|
+
<p data-widget-part="messages.spoken-missing">
|
|
204
|
+
<sp-icon name="volume-x" size="14"></sp-icon>
|
|
205
|
+
<span>Not spoken yet</span>
|
|
206
|
+
</p>
|
|
207
|
+
{:else}
|
|
208
|
+
<span data-widget-part="messages.spoken-state" aria-hidden="true">
|
|
209
|
+
<sp-icon name={playing || menuPlaying ? 'audio-lines' : 'volume-2'} size="14"></sp-icon>
|
|
210
|
+
</span>
|
|
211
|
+
{#key `${item.partId}:${take}`}
|
|
212
|
+
{#if autoplay}
|
|
213
|
+
<audio
|
|
214
|
+
data-widget-part="messages.spoken-audio"
|
|
215
|
+
aria-label="Play the spoken line"
|
|
216
|
+
controls
|
|
217
|
+
autoplay
|
|
218
|
+
{...playAttr}
|
|
219
|
+
preload="auto"
|
|
220
|
+
{src}
|
|
221
|
+
onerror={() => fail(item.partId)}
|
|
222
|
+
{...listeners}
|
|
223
|
+
></audio>
|
|
224
|
+
{:else}
|
|
225
|
+
<audio
|
|
226
|
+
data-widget-part="messages.spoken-audio"
|
|
227
|
+
aria-label="Play the spoken line"
|
|
228
|
+
controls
|
|
229
|
+
{...playAttr}
|
|
230
|
+
preload="metadata"
|
|
231
|
+
{src}
|
|
232
|
+
onerror={() => fail(item.partId)}
|
|
233
|
+
{...listeners}
|
|
234
|
+
></audio>
|
|
235
|
+
{/if}
|
|
236
|
+
{/key}
|
|
237
|
+
{#if clock}<span data-widget-part="messages.spoken-time">{clock}</span>{/if}
|
|
238
|
+
<span data-widget-part="messages.spoken-voice" title={asLine}>
|
|
239
|
+
{#if ownFace}
|
|
240
|
+
<img data-widget-part="messages.spoken-face" src={ownFace} alt="" />
|
|
241
|
+
{:else}
|
|
242
|
+
<sp-icon name="mic" size="12"></sp-icon>
|
|
243
|
+
{/if}
|
|
244
|
+
<span aria-hidden="true">{name}</span>
|
|
245
|
+
<span data-widget-part="messages.spoken-sr">{asLine}</span>
|
|
246
|
+
</span>
|
|
247
|
+
{#if mood}<span data-widget-part="messages.spoken-mood">{mood}</span>{/if}
|
|
248
|
+
{#if onSayItAs}
|
|
249
|
+
<sp-menu
|
|
250
|
+
placement="bottom-end"
|
|
251
|
+
label="Spoken line options"
|
|
252
|
+
onselect={(e: CustomEvent<{ value: string }>) => {
|
|
253
|
+
if (e.detail.value === 'say-it-as') onSayItAs?.()
|
|
254
|
+
}}
|
|
255
|
+
>
|
|
256
|
+
<button
|
|
257
|
+
slot="trigger"
|
|
258
|
+
type="button"
|
|
259
|
+
data-widget-part="messages.spoken-menu"
|
|
260
|
+
aria-label="More about this spoken line"
|
|
261
|
+
title="More about this spoken line"
|
|
262
|
+
>
|
|
263
|
+
<sp-icon name="ellipsis" size="14"></sp-icon>
|
|
264
|
+
</button>
|
|
265
|
+
<sp-menu-item value="say-it-as">
|
|
266
|
+
<sp-icon name="drama" size="12"></sp-icon>
|
|
267
|
+
<span>Say it as…</span>
|
|
268
|
+
</sp-menu-item>
|
|
269
|
+
</sp-menu>
|
|
270
|
+
{/if}
|
|
271
|
+
{#if caption}<p data-widget-part="messages.spoken-caption" aria-hidden="true">{caption}</p>{/if}
|
|
272
|
+
{/if}
|
|
273
|
+
</div>
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* action) or a `request` (something the host opens). Nothing here imports a
|
|
11
11
|
* store, the socket or the page: the same source runs in a UI worker.
|
|
12
12
|
*/
|
|
13
|
-
import { getContext, setContext, untrack } from "svelte"
|
|
13
|
+
import { getContext, setContext, tick, untrack } from "svelte"
|
|
14
14
|
import { SvelteMap, SvelteSet } from "svelte/reactivity"
|
|
15
15
|
import { useWidgetContext } from "../context"
|
|
16
16
|
import type { WidgetContextRef } from "@serene-pub/core-catalog/conversation"
|
|
@@ -78,6 +78,20 @@ export function createConversation(widget: WidgetContextRef) {
|
|
|
78
78
|
/** A scene boundary is being written: its presses wait. */
|
|
79
79
|
let sceneBusy = $state(false)
|
|
80
80
|
let menuFor = $state<number | undefined>(undefined)
|
|
81
|
+
/**
|
|
82
|
+
* 🚧 Heading audio control (2026-10-29): the ONE line audible in this
|
|
83
|
+
* widget, and which of its players holds it. Starting any line's audio
|
|
84
|
+
* stops the previous one (pause + rewind). `takes` re-keys a player so a
|
|
85
|
+
* stopped one starts over from the top; plain records, not a Map.
|
|
86
|
+
*/
|
|
87
|
+
let speechNow = $state<{ id: number; player: "line" | "menu" } | null>(null)
|
|
88
|
+
let speechTakes = $state<Record<string, number>>({})
|
|
89
|
+
/** The menu player's last playhead for a line (caption + state glyph read it). */
|
|
90
|
+
let speechMenuAt = $state<{ id: number; at: { currentTime: number; duration: number; paused: boolean } } | null>(null)
|
|
91
|
+
const bumpTake = (id: number, player: "line" | "menu") => {
|
|
92
|
+
const k = `${id}:${player}`
|
|
93
|
+
speechTakes = { ...speechTakes, [k]: (speechTakes[k] ?? 0) + 1 }
|
|
94
|
+
}
|
|
81
95
|
let selecting = $state(false)
|
|
82
96
|
/** The lane the composer writes to, and the log shows (`main` by default). */
|
|
83
97
|
let lane = $state("main")
|
|
@@ -399,6 +413,70 @@ export function createConversation(widget: WidgetContextRef) {
|
|
|
399
413
|
}
|
|
400
414
|
},
|
|
401
415
|
|
|
416
|
+
/**
|
|
417
|
+
* 🚧 Heading audio control: which line's audio is playing (one at a
|
|
418
|
+
* time) and through which player. `take(id, player)` is the rewind
|
|
419
|
+
* counter a player is keyed by.
|
|
420
|
+
*/
|
|
421
|
+
speech: {
|
|
422
|
+
get playing() {
|
|
423
|
+
return speechNow
|
|
424
|
+
},
|
|
425
|
+
isPlaying(id: number, player: "line" | "menu") {
|
|
426
|
+
return speechNow?.id === id && speechNow.player === player
|
|
427
|
+
},
|
|
428
|
+
/** The ⋮ player's playhead for this line while it is the current player; else null. */
|
|
429
|
+
menuAt(id: number) {
|
|
430
|
+
return speechMenuAt?.id === id && speechNow?.id === id && speechNow.player === "menu"
|
|
431
|
+
? speechMenuAt.at
|
|
432
|
+
: null
|
|
433
|
+
},
|
|
434
|
+
reportMenuAt(id: number, at: { currentTime: number; duration: number; paused: boolean } | null) {
|
|
435
|
+
if (at) speechMenuAt = { id, at }
|
|
436
|
+
},
|
|
437
|
+
take(id: number, player: "line" | "menu" = "line"): number {
|
|
438
|
+
return speechTakes[`${id}:${player}`] ?? 0
|
|
439
|
+
},
|
|
440
|
+
/**
|
|
441
|
+
* Make this line's player the playing one. Another line is stopped
|
|
442
|
+
* first (its `playing` off, its player re-keyed = pause + rewind),
|
|
443
|
+
* a tick ahead of the new one flipping on; the same line's other
|
|
444
|
+
* player is only paused.
|
|
445
|
+
*/
|
|
446
|
+
async play(id: number, player: "line" | "menu" = "line") {
|
|
447
|
+
const prev = speechNow
|
|
448
|
+
if (prev && !(prev.id === id && prev.player === player)) {
|
|
449
|
+
if (prev.id !== id) bumpTake(prev.id, prev.player)
|
|
450
|
+
speechNow = null
|
|
451
|
+
await tick()
|
|
452
|
+
}
|
|
453
|
+
speechNow = { id, player }
|
|
454
|
+
},
|
|
455
|
+
/** Pause and rewind: nothing playing, that player starts over. */
|
|
456
|
+
stop(id: number) {
|
|
457
|
+
if (speechNow?.id === id) {
|
|
458
|
+
bumpTake(id, speechNow.player)
|
|
459
|
+
speechNow = null
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
/**
|
|
463
|
+
* A player's own play / pause / ended. A play makes it the current
|
|
464
|
+
* one (stopping any other line); a pause or end of the current one
|
|
465
|
+
* clears it. A pause from a player that is not current is old news.
|
|
466
|
+
*/
|
|
467
|
+
heard(id: number, player: "line" | "menu", paused: boolean) {
|
|
468
|
+
const cur = speechNow
|
|
469
|
+
const mine = cur?.id === id && cur.player === player
|
|
470
|
+
if (paused) {
|
|
471
|
+
if (mine) speechNow = null
|
|
472
|
+
return
|
|
473
|
+
}
|
|
474
|
+
if (mine) return
|
|
475
|
+
if (cur && cur.id !== id) bumpTake(cur.id, cur.player)
|
|
476
|
+
speechNow = { id, player }
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
|
|
402
480
|
// ── 🚧 live scenes: the boundaries a person places (§7, §14 C) ─────
|
|
403
481
|
scenes: {
|
|
404
482
|
/** The viewer may place scene boundaries here (the dossier's verdict). */
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🚧 The spoken line's reading of a message (speech build, lane E3; design
|
|
3
|
+
* §6.4): what `metadata.spoken` (seam S6) says, which of the row's files is
|
|
4
|
+
* its audio, and which cue is speaking at a moment. Pure, so the spoken
|
|
5
|
+
* line and its tests read one answer. Types only from the SDK: a component
|
|
6
|
+
* imports no runtime from it.
|
|
7
|
+
*/
|
|
8
|
+
import type { CueMap, Inflection, SpokenAs, SpokenMeta, SpokenVoiceFrom } from '@serene-pub/sdk/component'
|
|
9
|
+
import type { MediaStripItem } from './mediaStrip'
|
|
10
|
+
|
|
11
|
+
export type ReadAloudMode = 'off' | 'make' | 'play'
|
|
12
|
+
|
|
13
|
+
/** The session's Read aloud setting off a dossier-like object; anything else is `off`. */
|
|
14
|
+
export function readAloudOf(dossier: unknown): ReadAloudMode {
|
|
15
|
+
const v = (dossier as { readAloud?: unknown } | null | undefined)?.readAloud
|
|
16
|
+
return v === 'make' || v === 'play' ? v : 'off'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type SpokenPlayback = 'auto' | 'click' | 'never'
|
|
20
|
+
|
|
21
|
+
/** The viewer's own playback choice off a dossier-like object; anything else is `auto`. */
|
|
22
|
+
export function spokenPlaybackOf(dossier: unknown): SpokenPlayback {
|
|
23
|
+
const v = (dossier as { spokenPlayback?: unknown } | null | undefined)?.spokenPlayback
|
|
24
|
+
return v === 'click' || v === 'never' ? v : 'auto'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** `metadata.spoken` when it has the shape the speak step records; otherwise null. */
|
|
28
|
+
export function spokenOf(metadata: unknown): SpokenMeta | null {
|
|
29
|
+
const s = (metadata as { spoken?: unknown } | null | undefined)?.spoken as Partial<SpokenMeta> | undefined
|
|
30
|
+
if (!s || typeof s !== 'object') return null
|
|
31
|
+
const as = s.spokenAs as SpokenAs | undefined
|
|
32
|
+
if (!as || typeof as !== 'object' || typeof as.voice !== 'string') return null
|
|
33
|
+
const cueMap: CueMap =
|
|
34
|
+
s.cueMap && Array.isArray(s.cueMap.spans) ? s.cueMap : { source: 'none', spans: [] }
|
|
35
|
+
return {
|
|
36
|
+
spokenAs: as,
|
|
37
|
+
cueMap,
|
|
38
|
+
inflection: (s.inflection as Inflection | null | undefined) ?? null,
|
|
39
|
+
template: typeof s.template === 'string' ? s.template : null,
|
|
40
|
+
at: typeof s.at === 'string' ? s.at : '',
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A speak run in flight for a line: `metadata.spoken.pending` (the host writes it when the run is enqueued, clears it when the run ends). */
|
|
45
|
+
export interface SpokenPending {
|
|
46
|
+
runId: string
|
|
47
|
+
at: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* `metadata.spoken.pending` when it has its shape; otherwise null. Read apart from
|
|
52
|
+
* `spokenOf`: a `spoken` holding only `pending` is not a spoken line.
|
|
53
|
+
*/
|
|
54
|
+
export function spokenPendingOf(metadata: unknown): SpokenPending | null {
|
|
55
|
+
const s = (metadata as { spoken?: unknown } | null | undefined)?.spoken as { pending?: unknown } | null | undefined
|
|
56
|
+
const p = s && typeof s === 'object' ? (s.pending as Partial<SpokenPending> | null | undefined) : null
|
|
57
|
+
if (!p || typeof p !== 'object' || typeof p.runId !== 'string' || !p.runId) return null
|
|
58
|
+
return { runId: p.runId, at: typeof p.at === 'string' ? p.at : '' }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Whether the line reads *Speaking…*: its run is pending, and has not been seen
|
|
63
|
+
* to end. `seenLive` is the run id this view last saw in `liveRunIds`: a run seen
|
|
64
|
+
* live and gone since is over (a stale marker must not say Speaking… forever); a
|
|
65
|
+
* run never seen (queued, or the push not yet heard) is taken at the marker's word.
|
|
66
|
+
*/
|
|
67
|
+
export function isSpeaking(
|
|
68
|
+
pending: SpokenPending | null,
|
|
69
|
+
liveRunIds: readonly string[] | undefined,
|
|
70
|
+
seenLive: string | null,
|
|
71
|
+
): boolean {
|
|
72
|
+
if (!pending) return false
|
|
73
|
+
if (liveRunIds?.includes(pending.runId)) return true
|
|
74
|
+
return seenLive !== pending.runId
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The label that reads as no inflection at all. */
|
|
78
|
+
const NEUTRAL = new Set(['', 'neutral', 'none'])
|
|
79
|
+
|
|
80
|
+
/** The inflection label of a spoken line when it is worth a chip (not neutral), else null. */
|
|
81
|
+
export function moodOf(spoken: SpokenMeta): string | null {
|
|
82
|
+
const label = spoken.inflection?.label?.trim()
|
|
83
|
+
return label && !NEUTRAL.has(label.toLowerCase()) ? label : null
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* *Spoken as Bruno · Qwen3-TTS 1.7B · said with sadness.* `voiceName` is the
|
|
88
|
+
* display name when the host can resolve the recorded voice id (the record's own
|
|
89
|
+
* `spokenAs.voiceName` first); the id otherwise. Parts that are absent are left
|
|
90
|
+
* out, never blanked.
|
|
91
|
+
*/
|
|
92
|
+
export function spokenAsLine(spoken: SpokenMeta, voiceName?: string | null): string {
|
|
93
|
+
const parts = [`Spoken as ${voiceNameOf(spoken, voiceName)}`]
|
|
94
|
+
if (spoken.spokenAs.model) parts.push(spoken.spokenAs.model)
|
|
95
|
+
const mood = moodOf(spoken)
|
|
96
|
+
if (mood) parts.push(`said with ${mood}`)
|
|
97
|
+
return parts.join(' · ')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The voice's display name: the one passed, else the record's, else the id. */
|
|
101
|
+
export function voiceNameOf(spoken: SpokenMeta, voiceName?: string | null): string {
|
|
102
|
+
return voiceName?.trim() || spoken.spokenAs.voiceName?.trim() || spoken.spokenAs.voice
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Whether the voice is the speaker's own (their card's, or their envoy's) rather than a default. */
|
|
106
|
+
export function isOwnVoice(from: SpokenVoiceFrom | undefined): boolean {
|
|
107
|
+
return from === 'timbre' || from === 'envoy' || from === 'narration-timbre' || from === 'envoy-narration'
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** What a host `audio` event raises (seconds). */
|
|
111
|
+
export interface Playback {
|
|
112
|
+
currentTime: number
|
|
113
|
+
duration: number
|
|
114
|
+
paused: boolean
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The `{ currentTime, duration, paused }` an `audio` event carries; a misshapen detail reads as none. */
|
|
118
|
+
export function playbackOf(detail: unknown): Playback | null {
|
|
119
|
+
const d = (detail as { detail?: unknown } | null | undefined)?.detail ?? detail
|
|
120
|
+
const p = d as Partial<Playback> | null | undefined
|
|
121
|
+
if (!p || typeof p !== 'object') return null
|
|
122
|
+
const num = (v: unknown) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : 0)
|
|
123
|
+
return { currentTime: num(p.currentTime), duration: num(p.duration), paused: p.paused !== false }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** `m:ss` for a count of seconds (a negative, NaN or infinite count reads `0:00`). */
|
|
127
|
+
export function formatClock(seconds: number): string {
|
|
128
|
+
const s = Number.isFinite(seconds) && seconds > 0 ? Math.floor(seconds) : 0
|
|
129
|
+
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The words of the cue(s) speaking at `seconds` into the audio: the spans whose
|
|
134
|
+
* `[startMs, endMs)` hold the moment (the last span holds its end), their text
|
|
135
|
+
* joined once each. Null when nothing is known there (no map, a gap, older
|
|
136
|
+
* records without cue text).
|
|
137
|
+
*/
|
|
138
|
+
export function cueCaptionAt(cueMap: CueMap, seconds: number): string | null {
|
|
139
|
+
if (!cueMap.spans.length || !Number.isFinite(seconds) || seconds < 0) return null
|
|
140
|
+
const ms = seconds * 1000
|
|
141
|
+
const lastEnd = Math.max(...cueMap.spans.map((s) => s.endMs))
|
|
142
|
+
const seen: string[] = []
|
|
143
|
+
for (const span of cueMap.spans) {
|
|
144
|
+
const inside = ms >= span.startMs && (ms < span.endMs || (ms === span.endMs && span.endMs === lastEnd))
|
|
145
|
+
if (inside && span.text && !seen.includes(span.text)) seen.push(span.text)
|
|
146
|
+
}
|
|
147
|
+
return seen.length ? seen.join(' ') : null
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** The row's spoken audio: the newest audio file the strip found, else null. */
|
|
151
|
+
export function spokenAudioItem(items: readonly MediaStripItem[]): MediaStripItem | null {
|
|
152
|
+
for (let i = items.length - 1; i >= 0; i--) if (items[i].kind === 'audio') return items[i]
|
|
153
|
+
return null
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** A spoken line made within this window counts as arriving now, not as history. */
|
|
157
|
+
export const AUTOPLAY_FRESH_MS = 60_000
|
|
158
|
+
|
|
159
|
+
/** Whether the line's audio just arrived (its `at` is recent). */
|
|
160
|
+
export function isFresh(spoken: SpokenMeta, now = Date.now()): boolean {
|
|
161
|
+
const t = Date.parse(spoken.at)
|
|
162
|
+
return Number.isFinite(t) && now - t >= -5_000 && now - t <= AUTOPLAY_FRESH_MS
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** When this page (the widget's module) loaded — what "already there" is measured against. */
|
|
166
|
+
export const PAGE_LOADED_AT = Date.now()
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The line was spoken while this page was open — an arrival, not history.
|
|
170
|
+
* The spoken line mounts only once a line HAS audio, so "it appeared while
|
|
171
|
+
* mounted" cannot be seen from inside it; the record's own time can. A
|
|
172
|
+
* second of slack for the server's clock against this one.
|
|
173
|
+
*/
|
|
174
|
+
export function spokenSinceLoad(spoken: SpokenMeta, loadedAt = PAGE_LOADED_AT): boolean {
|
|
175
|
+
const t = Date.parse(spoken.at)
|
|
176
|
+
return Number.isFinite(t) && t >= loadedAt - 1_000
|
|
177
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
paletteRowState,
|
|
3
3
|
statusTextIn
|
|
4
|
-
} from "./shared-
|
|
5
|
-
import "./shared-
|
|
6
|
-
import "./shared-
|
|
7
|
-
import "./shared-
|
|
8
|
-
import "./shared-YMBM3PBR.js";
|
|
4
|
+
} from "./shared-BBF64YGL.js";
|
|
5
|
+
import "./shared-XBDUENRA.js";
|
|
6
|
+
import "./shared-QXF5CJVN.js";
|
|
7
|
+
import "./shared-YDS7HYL6.js";
|
|
9
8
|
import "./shared-W3XS5FEL.js";
|
|
10
|
-
import "./shared-
|
|
9
|
+
import "./shared-4ME6NFDK.js";
|
|
11
10
|
import {
|
|
12
11
|
WIDGET_CONTEXT_KEY,
|
|
13
12
|
actionIdentity,
|
|
@@ -39,7 +38,7 @@ import {
|
|
|
39
38
|
user_derived,
|
|
40
39
|
user_effect,
|
|
41
40
|
widgetRefFromComponent
|
|
42
|
-
} from "./shared-
|
|
41
|
+
} from "./shared-JPG5DQO7.js";
|
|
43
42
|
|
|
44
43
|
// dist/shared/ui/actions/index.js
|
|
45
44
|
var ACTIONS_GROUP_ORDER = Object.freeze([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"slug":"actions","framework":"svelte","entry":"shared/actions/actions.ts","files":{"shared/actions/Actions.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's Actions widget as a remote component (W8): the component\n\t * context, as the widget context, around the widget.\n\t */\n\timport { setContext, untrack } from \"svelte\"\n\timport type { ComponentContext } from \"@serene-pub/sdk/component\"\n\timport { WIDGET_CONTEXT_KEY } from \"@serene-pub/core-catalog/widgets\"\n\timport ActionsWidget from \"./ActionsWidget.svelte\"\n\timport { widgetRefFromComponent } from \"../widgetRef.svelte\"\n\n\tlet { ctx }: { ctx: ComponentContext } = $props()\n\n\t// The context is the mount's, handed once: its sections move, it does not.\n\tsetContext(\n\t\tWIDGET_CONTEXT_KEY,\n\t\twidgetRefFromComponent(\n\t\t\tuntrack(() => ctx),\n\t\t\t{ id: \"actions\", instanceId: \"actions\", title: \"Actions\" }\n\t\t)\n\t)\n</script>\n\n<ActionsWidget />\n","shared/actions/ActionsWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * Actions (PLAN-core-widgets W8): what can I do right now — the session's\n\t * listed actions (`actions.v1`) as real buttons, each with its icon and\n\t * name, grouped from fields the listing carries: the turn controls, then\n\t * the genre's own, then the ones added to it (`actionsView`, the plain\n\t * half; this only draws it).\n\t *\n\t * A press is `invoke(identity)` — the same door the composer's chips\n\t * take, so a core verb reaches the page's own handler and an action that\n\t * collects text or recipients opens the page's collect modal before it\n\t * fires. A greyed action is greyed, not disabled: `aria-disabled` keeps it\n\t * in the tab order, its reason is its `title` and its description\n\t * (`actions.reason`), and the click is guarded — as the chips do.\n\t *\n\t * Drawing a newcomer is meeting it: the widget shows every action at\n\t * once, as opening **More** does in the composer, so the identities it\n\t * draws wearing the *new* mark are told to the page (`actions-seen`),\n\t * once each.\n\t *\n\t * ⚠ `showWaiting` (the questions waiting on the viewer) is declared and\n\t * not drawn: no section this widget reads carries a session's open forms.\n\t *\n\t * The markup carries no look: each element names what it is in\n\t * `data-widget-part`, the size rides on the root's `data-size`, a\n\t * newcomer on its button's `data-new`, and the default widget stylesheet\n\t * draws them (STYLE-GUIDE §6.16).\n\t */\n\timport { actionsView, readActionsSettings, type ActionsButtonView } from \"@serene-pub/core-catalog/actions\"\n\timport { useWidgetContext } from \"../context\"\n\n\tconst widget = useWidgetContext()\n\tconst t = (source: string): string => widget?.current.t(source) ?? source\n\tconst uid = $props.id()\n\n\tconst settings = $derived(\n\t\treadActionsSettings(widget?.current.settings?.v1)\n\t)\n\tconst view = $derived(\n\t\tactionsView({\n\t\t\tactions: widget?.current.actions?.v1,\n\t\t\tsettings,\n\t\t\tlocale: widget?.current.locale?.v1,\n\t\t\tt\n\t\t})\n\t)\n\n\t/** An element id from an action's identity (`core#advance` → `core-advance`). */\n\tconst idOf = (identity: string): string => identity.replace(/[^a-zA-Z0-9-]/g, \"-\")\n\n\t/** The newcomers already told to the page — each once. */\n\tconst met = new Set<string>()\n\t$effect(() => {\n\t\tconst fresh = view.fresh.filter((k) => !met.has(k))\n\t\tif (!fresh.length) return\n\t\tfor (const k of fresh) met.add(k)\n\t\tvoid widget?.current.request(\"actions-seen\", { keys: fresh })?.catch(() => {})\n\t})\n\n\t/** Why the last press did not go through, this widget's own. */\n\tlet refusal = $state<string | null>(null)\n\n\tfunction press(button: ActionsButtonView): void {\n\t\tif (button.disabled) return\n\t\trefusal = null\n\t\ttry {\n\t\t\twidget?.current.invoke(button.identity)\n\t\t} catch (e) {\n\t\t\trefusal = e instanceof Error && e.message ? e.message : t(\"That did not go through. Try again.\")\n\t\t}\n\t}\n</script>\n\n<div data-widget-part=\"actions.root\" data-size={settings.size}>\n\t{#if refusal}\n\t\t<p data-widget-part=\"actions.alert\" role=\"alert\">{refusal}</p>\n\t{/if}\n\n\t{#if view.empty}\n\t\t<div data-widget-part=\"actions.empty empty\" role=\"status\">\n\t\t\t<sp-icon name=\"mouse-pointer-click\" size=\"20\"></sp-icon>\n\t\t\t<span>{view.empty}</span>\n\t\t</div>\n\t{:else}\n\t\t{#each view.groups as group (group.key)}\n\t\t\t<div\n\t\t\t\tdata-widget-part=\"actions.group\"\n\t\t\t\tdata-group={group.key}\n\t\t\t\trole=\"group\"\n\t\t\t\taria-labelledby={`actions-${uid}-${group.key}`}\n\t\t\t>\n\t\t\t\t<p data-widget-part=\"actions.group-head\" id={`actions-${uid}-${group.key}`}>{group.title}</p>\n\t\t\t\t{#each group.buttons as button (button.identity)}\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tdata-widget-part=\"actions.button\"\n\t\t\t\t\t\tdata-identity={button.identity}\n\t\t\t\t\t\tdata-new={button.isNew ? \"\" : undefined}\n\t\t\t\t\t\taria-disabled={button.disabled ? \"true\" : undefined}\n\t\t\t\t\t\taria-describedby={button.reason ? `actions-${uid}-reason-${idOf(button.identity)}` : undefined}\n\t\t\t\t\t\ttitle={button.title}\n\t\t\t\t\t\tonclick={() => press(button)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-icon name={button.icon} size=\"16\"></sp-icon>\n\t\t\t\t\t\t<span>{button.name}</span>\n\t\t\t\t\t\t{#if button.reason}\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tdata-widget-part=\"actions.reason\"\n\t\t\t\t\t\t\t\tid={`actions-${uid}-reason-${idOf(button.identity)}`}\n\t\t\t\t\t\t\t\taria-hidden=\"true\">{button.reason}</span\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</button>\n\t\t\t\t{/each}\n\t\t\t</div>\n\t\t{/each}\n\t{/if}\n</div>\n","shared/actions/actions.ts":"/**\n * Core's `actions` component (PLAN-core-widgets W8): the session's actions as\n * buttons — the turn controls, the genre's own, the added ones — as the\n * page's UI worker runs it. `npm run build` compiles it with the CLI's\n * component bundler to `dist/components/actions.js`, the module the app\n * serves at `/core-ui/actions`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport Actions from './Actions.svelte'\n\nexport default svelteComponent(Actions)\n","shared/context.ts":"/**\n * Core's widgets read their widget context with their own `getContext`, so\n * the lookup resolves in whichever Svelte runtime renders them — the\n * component's, in the page's UI worker. The key and the context's shape are\n * the host's contract (`@serene-pub/core-catalog/widgets`). Shared by every\n * core widget (R21); the conversation was the first.\n */\nimport { getContext } from 'svelte'\nimport { WIDGET_CONTEXT_KEY, type WidgetContextRef } from '@serene-pub/core-catalog/widgets'\n\n/** The widget context, if a host provides one; undefined outside a host (tests, a bare mount). */\nexport function useWidgetContext(): WidgetContextRef | undefined {\n\treturn getContext<WidgetContextRef | undefined>(WIDGET_CONTEXT_KEY)\n}\n","shared/widgetRef.svelte.ts":"/**\n * A remote's widget context (C0b): the component context a UI worker hands\n * a component, as the native `WidgetContext` core's widgets read\n * (`useWidgetContext`). So a core widget — written against the native\n * context — runs in a worker with no change to its source: the same\n * sections, the same verbs, reaching the host over the component's port.\n * Shared by every core widget (R21); the conversation was the first.\n */\nimport {\n\tEMPTY_ATTENDANCE,\n\tEMPTY_TURN_ORDER,\n\tWIDGET_PROTOCOL,\n\ttype ComponentContext,\n\ttype LayoutV1,\n\ttype ViewerV1,\n\ttype WidgetEvent,\n\ttype WidgetEventKind\n} from \"@serene-pub/sdk/component\"\nimport {\n\tWIDGET_SCOPED_SECTIONS,\n\ttype WidgetContext,\n\ttype WidgetContextRef,\n\ttype WidgetScopedData,\n\ttype WidgetSectionScope\n} from \"@serene-pub/core-catalog/widgets\"\n\n/** Every scoped section's posted name — the SDK's one table, read once. */\nconst SCOPED_NAMES = Object.values(WIDGET_SCOPED_SECTIONS)\n\nconst NOBODY: ViewerV1 = { userId: null, isAdmin: false, isGuest: false }\n\n/**\n * A remote's context carries its saved view state besides: what it saved\n * last mount (`state`) and the host's save-state channel (`saveState`) —\n * read by core's widgets off the context where a remote has them.\n */\ntype RemoteWidgetContext = WidgetContext & {\n\tstate: unknown\n\tsaveState: (state: unknown) => void\n}\n\n/** The granted scoped sections as the envelope carries them: `{ <name>: { v1 } }`, absent when not granted. */\nfunction scopedData(scoped: ComponentContext[\"scoped\"]): WidgetScopedData {\n\tconst out: Record<string, { v1: unknown }> = {}\n\tfor (const name of SCOPED_NAMES) if (scoped[name] !== undefined) out[name] = { v1: scoped[name] }\n\treturn out as WidgetScopedData\n}\n\nexport function widgetRefFromComponent(\n\tctx: ComponentContext,\n\twidget: WidgetContext[\"widget\"]\n): WidgetContextRef {\n\t// Any section the host pushes re-projects the context, as a native\n\t// host's re-projection does.\n\tlet version = $state(0)\n\tctx.subscribe(() => version++)\n\n\tconst current = $derived.by((): RemoteWidgetContext => {\n\t\tvoid version\n\t\tconst scoped = ctx.scoped ?? {}\n\t\treturn {\n\t\t\tprotocol: WIDGET_PROTOCOL,\n\t\t\twidget,\n\t\t\tlayout: { v1: (ctx.layout ?? {}) as LayoutV1 },\n\t\t\tsession: { v1: (ctx.session ?? { id: 0, name: null }) as WidgetContext[\"session\"][\"v1\"] },\n\t\t\tchannels: { v1: Object.keys(ctx.channels ?? {}) },\n\t\t\tmessages: { v1: (ctx.messages ?? []) as WidgetContext[\"messages\"][\"v1\"] },\n\t\t\tprops: { v1: ctx.props ?? {} },\n\t\t\tactions: { v1: (ctx.actions ?? {}) as WidgetContext[\"actions\"][\"v1\"] },\n\t\t\tsettings: { v1: ctx.settings ?? {} },\n\t\t\tannex: { v1: (ctx.annex ?? {}) as WidgetContext[\"annex\"][\"v1\"] },\n\t\t\tlocale: { v1: ctx.locale ?? \"en\" },\n\t\t\tviewer: { v1: ctx.viewer ?? NOBODY },\n\t\t\tturnOrder: { v1: ctx.turnOrder ?? EMPTY_TURN_ORDER },\n\t\t\tattendance: { v1: ctx.attendance ?? EMPTY_ATTENDANCE },\n\t\t\t// What the host said this widget holds — absent until it has — so a\n\t\t\t// widget can tell a scope never granted apart from a section not yet posted.\n\t\t\tgrants: ctx.grants,\n\t\t\t// The scoped sections the host granted, each as its `{ v1 }` bag — by\n\t\t\t// the table, so a section the SDK adds arrives with no change here.\n\t\t\t...scopedData(scoped),\n\t\t\taction: (fn, messageId, payload, action, blockId) => ctx.action(fn, messageId, payload, action, blockId),\n\t\t\tinvoke: (key, args) => ctx.invoke(key, args),\n\t\t\trequest: ((kind, params) => ctx.request(kind, params)) as WidgetContext[\"request\"],\n\t\t\t// ⏳ The retired `menu` verb (C4, 2026-10-10; REMOVE in 0.7.0): no host\n\t\t\t// draws one, so it answers dismissed. A component places `sp-menu`.\n\t\t\tmenu: async () => null,\n\t\t\ton: (kind: WidgetEventKind | \"*\", cb: (e: WidgetEvent) => void) =>\n\t\t\t\tctx.onEvent((e) => {\n\t\t\t\t\tconst ev = e as WidgetEvent\n\t\t\t\t\tif (kind === \"*\" || ev.kind === kind) cb(ev)\n\t\t\t\t}),\n\t\t\t// The scope string, by the table, to the section's `v1` — the same\n\t\t\t// lookup `ComponentContext.scope` makes, so both answer alike.\n\t\t\tscope: <S extends WidgetSectionScope>(scope: S) => scoped[WIDGET_SCOPED_SECTIONS[scope]],\n\t\t\tt: (source) => ctx.t(source),\n\t\t\tstate: ctx.state,\n\t\t\tsaveState: (state) => ctx.saveState(state)\n\t\t}\n\t})\n\n\treturn {\n\t\tget current() {\n\t\t\treturn current\n\t\t}\n\t}\n}\n"},"sourceHash":"1da04e8570764b02f68637cf1665e942b24b303291c361e24a41a92cefee266b","catalogVersion":"0.6.0-pr-6"}
|
|
1
|
+
{"slug":"actions","framework":"svelte","entry":"shared/actions/actions.ts","files":{"shared/actions/Actions.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's Actions widget as a remote component (W8): the component\n\t * context, as the widget context, around the widget.\n\t */\n\timport { setContext, untrack } from \"svelte\"\n\timport type { ComponentContext } from \"@serene-pub/sdk/component\"\n\timport { WIDGET_CONTEXT_KEY } from \"@serene-pub/core-catalog/widgets\"\n\timport ActionsWidget from \"./ActionsWidget.svelte\"\n\timport { widgetRefFromComponent } from \"../widgetRef.svelte\"\n\n\tlet { ctx }: { ctx: ComponentContext } = $props()\n\n\t// The context is the mount's, handed once: its sections move, it does not.\n\tsetContext(\n\t\tWIDGET_CONTEXT_KEY,\n\t\twidgetRefFromComponent(\n\t\t\tuntrack(() => ctx),\n\t\t\t{ id: \"actions\", instanceId: \"actions\", title: \"Actions\" }\n\t\t)\n\t)\n</script>\n\n<ActionsWidget />\n","shared/actions/ActionsWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * Actions (PLAN-core-widgets W8): what can I do right now — the session's\n\t * listed actions (`actions.v1`) as real buttons, each with its icon and\n\t * name, grouped from fields the listing carries: the turn controls, then\n\t * the genre's own, then the ones added to it (`actionsView`, the plain\n\t * half; this only draws it).\n\t *\n\t * A press is `invoke(identity)` — the same door the composer's chips\n\t * take, so a core verb reaches the page's own handler and an action that\n\t * collects text or recipients opens the page's collect modal before it\n\t * fires. A greyed action is greyed, not disabled: `aria-disabled` keeps it\n\t * in the tab order, its reason is its `title` and its description\n\t * (`actions.reason`), and the click is guarded — as the chips do.\n\t *\n\t * Drawing a newcomer is meeting it: the widget shows every action at\n\t * once, as opening **More** does in the composer, so the identities it\n\t * draws wearing the *new* mark are told to the page (`actions-seen`),\n\t * once each.\n\t *\n\t * ⚠ `showWaiting` (the questions waiting on the viewer) is declared and\n\t * not drawn: no section this widget reads carries a session's open forms.\n\t *\n\t * The markup carries no look: each element names what it is in\n\t * `data-widget-part`, the size rides on the root's `data-size`, a\n\t * newcomer on its button's `data-new`, and the default widget stylesheet\n\t * draws them (STYLE-GUIDE §6.16).\n\t */\n\timport { actionsView, readActionsSettings, type ActionsButtonView } from \"@serene-pub/core-catalog/actions\"\n\timport { useWidgetContext } from \"../context\"\n\n\tconst widget = useWidgetContext()\n\tconst t = (source: string): string => widget?.current.t(source) ?? source\n\tconst uid = $props.id()\n\n\tconst settings = $derived(\n\t\treadActionsSettings(widget?.current.settings?.v1)\n\t)\n\tconst view = $derived(\n\t\tactionsView({\n\t\t\tactions: widget?.current.actions?.v1,\n\t\t\tsettings,\n\t\t\tlocale: widget?.current.locale?.v1,\n\t\t\tt\n\t\t})\n\t)\n\n\t/** An element id from an action's identity (`core#advance` → `core-advance`). */\n\tconst idOf = (identity: string): string => identity.replace(/[^a-zA-Z0-9-]/g, \"-\")\n\n\t/** The newcomers already told to the page — each once. */\n\tconst met = new Set<string>()\n\t$effect(() => {\n\t\tconst fresh = view.fresh.filter((k) => !met.has(k))\n\t\tif (!fresh.length) return\n\t\tfor (const k of fresh) met.add(k)\n\t\tvoid widget?.current.request(\"actions-seen\", { keys: fresh })?.catch(() => {})\n\t})\n\n\t/** Why the last press did not go through, this widget's own. */\n\tlet refusal = $state<string | null>(null)\n\n\tfunction press(button: ActionsButtonView): void {\n\t\tif (button.disabled) return\n\t\trefusal = null\n\t\ttry {\n\t\t\twidget?.current.invoke(button.identity)\n\t\t} catch (e) {\n\t\t\trefusal = e instanceof Error && e.message ? e.message : t(\"That did not go through. Try again.\")\n\t\t}\n\t}\n</script>\n\n<div data-widget-part=\"actions.root\" data-size={settings.size}>\n\t{#if refusal}\n\t\t<p data-widget-part=\"actions.alert\" role=\"alert\">{refusal}</p>\n\t{/if}\n\n\t{#if view.empty}\n\t\t<div data-widget-part=\"actions.empty empty\" role=\"status\">\n\t\t\t<sp-icon name=\"mouse-pointer-click\" size=\"20\"></sp-icon>\n\t\t\t<span>{view.empty}</span>\n\t\t</div>\n\t{:else}\n\t\t{#each view.groups as group (group.key)}\n\t\t\t<div\n\t\t\t\tdata-widget-part=\"actions.group\"\n\t\t\t\tdata-group={group.key}\n\t\t\t\trole=\"group\"\n\t\t\t\taria-labelledby={`actions-${uid}-${group.key}`}\n\t\t\t>\n\t\t\t\t<p data-widget-part=\"actions.group-head\" id={`actions-${uid}-${group.key}`}>{group.title}</p>\n\t\t\t\t{#each group.buttons as button (button.identity)}\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tdata-widget-part=\"actions.button\"\n\t\t\t\t\t\tdata-identity={button.identity}\n\t\t\t\t\t\tdata-new={button.isNew ? \"\" : undefined}\n\t\t\t\t\t\taria-disabled={button.disabled ? \"true\" : undefined}\n\t\t\t\t\t\taria-describedby={button.reason ? `actions-${uid}-reason-${idOf(button.identity)}` : undefined}\n\t\t\t\t\t\ttitle={button.title}\n\t\t\t\t\t\tonclick={() => press(button)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<sp-icon name={button.icon} size=\"16\"></sp-icon>\n\t\t\t\t\t\t<span>{button.name}</span>\n\t\t\t\t\t\t{#if button.reason}\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tdata-widget-part=\"actions.reason\"\n\t\t\t\t\t\t\t\tid={`actions-${uid}-reason-${idOf(button.identity)}`}\n\t\t\t\t\t\t\t\taria-hidden=\"true\">{button.reason}</span\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</button>\n\t\t\t\t{/each}\n\t\t\t</div>\n\t\t{/each}\n\t{/if}\n</div>\n","shared/actions/actions.ts":"/**\n * Core's `actions` component (PLAN-core-widgets W8): the session's actions as\n * buttons — the turn controls, the genre's own, the added ones — as the\n * page's UI worker runs it. `npm run build` compiles it with the CLI's\n * component bundler to `dist/components/actions.js`, the module the app\n * serves at `/core-ui/actions`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport Actions from './Actions.svelte'\n\nexport default svelteComponent(Actions)\n","shared/context.ts":"/**\n * Core's widgets read their widget context with their own `getContext`, so\n * the lookup resolves in whichever Svelte runtime renders them — the\n * component's, in the page's UI worker. The key and the context's shape are\n * the host's contract (`@serene-pub/core-catalog/widgets`). Shared by every\n * core widget (R21); the conversation was the first.\n */\nimport { getContext } from 'svelte'\nimport { WIDGET_CONTEXT_KEY, type WidgetContextRef } from '@serene-pub/core-catalog/widgets'\n\n/** The widget context, if a host provides one; undefined outside a host (tests, a bare mount). */\nexport function useWidgetContext(): WidgetContextRef | undefined {\n\treturn getContext<WidgetContextRef | undefined>(WIDGET_CONTEXT_KEY)\n}\n","shared/widgetRef.svelte.ts":"/**\n * A remote's widget context (C0b): the component context a UI worker hands\n * a component, as the native `WidgetContext` core's widgets read\n * (`useWidgetContext`). So a core widget — written against the native\n * context — runs in a worker with no change to its source: the same\n * sections, the same verbs, reaching the host over the component's port.\n * Shared by every core widget (R21); the conversation was the first.\n */\nimport {\n\tEMPTY_ATTENDANCE,\n\tEMPTY_TURN_ORDER,\n\tWIDGET_PROTOCOL,\n\ttype ComponentContext,\n\ttype LayoutV1,\n\ttype ViewerV1,\n\ttype WidgetEvent,\n\ttype WidgetEventKind\n} from \"@serene-pub/sdk/component\"\nimport {\n\tWIDGET_SCOPED_SECTIONS,\n\ttype WidgetContext,\n\ttype WidgetContextRef,\n\ttype WidgetScopedData,\n\ttype WidgetSectionScope\n} from \"@serene-pub/core-catalog/widgets\"\n\n/** Every scoped section's posted name — the SDK's one table, read once. */\nconst SCOPED_NAMES = Object.values(WIDGET_SCOPED_SECTIONS)\n\nconst NOBODY: ViewerV1 = { userId: null, isAdmin: false, isGuest: false }\n\n/**\n * A remote's context carries its saved view state besides: what it saved\n * last mount (`state`) and the host's save-state channel (`saveState`) —\n * read by core's widgets off the context where a remote has them.\n */\ntype RemoteWidgetContext = WidgetContext & {\n\tstate: unknown\n\tsaveState: (state: unknown) => void\n}\n\n/** The granted scoped sections as the envelope carries them: `{ <name>: { v1 } }`, absent when not granted. */\nfunction scopedData(scoped: ComponentContext[\"scoped\"]): WidgetScopedData {\n\tconst out: Record<string, { v1: unknown }> = {}\n\tfor (const name of SCOPED_NAMES) if (scoped[name] !== undefined) out[name] = { v1: scoped[name] }\n\treturn out as WidgetScopedData\n}\n\nexport function widgetRefFromComponent(\n\tctx: ComponentContext,\n\twidget: WidgetContext[\"widget\"]\n): WidgetContextRef {\n\t// Any section the host pushes re-projects the context, as a native\n\t// host's re-projection does.\n\tlet version = $state(0)\n\tctx.subscribe(() => version++)\n\n\tconst current = $derived.by((): RemoteWidgetContext => {\n\t\tvoid version\n\t\tconst scoped = ctx.scoped ?? {}\n\t\treturn {\n\t\t\tprotocol: WIDGET_PROTOCOL,\n\t\t\twidget,\n\t\t\tlayout: { v1: (ctx.layout ?? {}) as LayoutV1 },\n\t\t\tsession: { v1: (ctx.session ?? { id: 0, name: null }) as WidgetContext[\"session\"][\"v1\"] },\n\t\t\tchannels: { v1: Object.keys(ctx.channels ?? {}) },\n\t\t\tmessages: { v1: (ctx.messages ?? []) as WidgetContext[\"messages\"][\"v1\"] },\n\t\t\tprops: { v1: ctx.props ?? {} },\n\t\t\tactions: { v1: (ctx.actions ?? {}) as WidgetContext[\"actions\"][\"v1\"] },\n\t\t\tsettings: { v1: ctx.settings ?? {} },\n\t\t\tannex: { v1: (ctx.annex ?? {}) as WidgetContext[\"annex\"][\"v1\"] },\n\t\t\tlocale: { v1: ctx.locale ?? \"en\" },\n\t\t\tviewer: { v1: ctx.viewer ?? NOBODY },\n\t\t\tturnOrder: { v1: ctx.turnOrder ?? EMPTY_TURN_ORDER },\n\t\t\tattendance: { v1: ctx.attendance ?? EMPTY_ATTENDANCE },\n\t\t\t// What the host said this widget holds — absent until it has — so a\n\t\t\t// widget can tell a scope never granted apart from a section not yet posted.\n\t\t\tgrants: ctx.grants,\n\t\t\t// The scoped sections the host granted, each as its `{ v1 }` bag — by\n\t\t\t// the table, so a section the SDK adds arrives with no change here.\n\t\t\t...scopedData(scoped),\n\t\t\taction: (fn, messageId, payload, action, blockId) => ctx.action(fn, messageId, payload, action, blockId),\n\t\t\tinvoke: (key, args) => ctx.invoke(key, args),\n\t\t\trequest: ((kind, params) => ctx.request(kind, params)) as WidgetContext[\"request\"],\n\t\t\t// ⏳ The retired `menu` verb (C4, 2026-10-10; REMOVE in 0.7.0): no host\n\t\t\t// draws one, so it answers dismissed. A component places `sp-menu`.\n\t\t\tmenu: async () => null,\n\t\t\ton: (kind: WidgetEventKind | \"*\", cb: (e: WidgetEvent) => void) =>\n\t\t\t\tctx.onEvent((e) => {\n\t\t\t\t\tconst ev = e as WidgetEvent\n\t\t\t\t\tif (kind === \"*\" || ev.kind === kind) cb(ev)\n\t\t\t\t}),\n\t\t\t// The scope string, by the table, to the section's `v1` — the same\n\t\t\t// lookup `ComponentContext.scope` makes, so both answer alike.\n\t\t\tscope: <S extends WidgetSectionScope>(scope: S) => scoped[WIDGET_SCOPED_SECTIONS[scope]],\n\t\t\tt: (source) => ctx.t(source),\n\t\t\tstate: ctx.state,\n\t\t\tsaveState: (state) => ctx.saveState(state)\n\t\t}\n\t})\n\n\treturn {\n\t\tget current() {\n\t\t\treturn current\n\t\t}\n\t}\n}\n"},"sourceHash":"1da04e8570764b02f68637cf1665e942b24b303291c361e24a41a92cefee266b","catalogVersion":"0.6.0-pr-7"}
|
package/dist/components/album.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseChannel
|
|
3
|
-
} from "./shared-XKA5BV4M.js";
|
|
4
1
|
import {
|
|
5
2
|
SvelteSet,
|
|
6
3
|
WIDGET_CONTEXT_KEY,
|
|
@@ -16,6 +13,7 @@ import {
|
|
|
16
13
|
get,
|
|
17
14
|
if_block,
|
|
18
15
|
noop,
|
|
16
|
+
parseChannel,
|
|
19
17
|
pop,
|
|
20
18
|
push,
|
|
21
19
|
replay_events,
|
|
@@ -33,7 +31,7 @@ import {
|
|
|
33
31
|
useWidgetContext,
|
|
34
32
|
user_derived,
|
|
35
33
|
widgetRefFromComponent
|
|
36
|
-
} from "./shared-
|
|
34
|
+
} from "./shared-JPG5DQO7.js";
|
|
37
35
|
|
|
38
36
|
// dist/shared/ui/album/index.js
|
|
39
37
|
var ALBUM_DEFAULTS = Object.freeze({
|