@serene-pub/core-catalog 0.6.0-pr-2 → 0.6.0-pr-5
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 +21 -1
- package/components/{sessions → genres/chat}/authors-note/AuthorsNote.svelte +1 -1
- package/components/{sessions → genres/chat}/authors-note/AuthorsNoteWidget.svelte +1 -1
- package/components/{sessions/world-state/WorldState.svelte → shared/actions/Actions.svelte} +5 -5
- package/components/shared/actions/ActionsWidget.svelte +118 -0
- package/components/shared/actions/actions.ts +11 -0
- package/components/shared/album/Album.svelte +24 -0
- package/components/shared/album/AlbumWidget.svelte +163 -0
- package/components/shared/album/album.ts +10 -0
- package/components/shared/annex/Annex.svelte +24 -0
- package/components/shared/annex/AnnexWidget.svelte +151 -0
- package/components/shared/annex/annex.ts +10 -0
- package/components/shared/attendance/Attendance.svelte +24 -0
- package/components/shared/attendance/AttendanceWidget.svelte +136 -0
- package/components/shared/attendance/attendance.ts +12 -0
- package/components/shared/backdrop/Backdrop.svelte +24 -0
- package/components/shared/backdrop/BackdropWidget.svelte +345 -0
- package/components/shared/backdrop/backdrop.ts +10 -0
- package/components/shared/chronicle/Chronicle.svelte +36 -0
- package/components/shared/chronicle/ChronicleWidget.svelte +569 -0
- package/components/shared/chronicle/chronicle.ts +11 -0
- package/components/{sessions → shared}/lore-entries/LoreEntries.svelte +1 -1
- package/components/{sessions → shared}/lore-entries/LoreEntriesWidget.svelte +3 -3
- package/components/shared/map-canvas/MapCanvas.svelte +171 -0
- package/components/shared/map-canvas/index.ts +390 -0
- package/components/{sessions → shared}/messages/MessageComposer.svelte +1 -1
- package/components/{sessions → shared}/messages/MessageControls.svelte +42 -0
- package/components/{sessions → shared}/messages/MessageStateLedger.svelte +19 -8
- package/components/{sessions → shared}/messages/Messages.svelte +1 -1
- package/components/{sessions → shared}/messages/MessagesWidget.svelte +126 -40
- package/components/{sessions → shared}/messages/NextCharacterBlock.svelte +17 -14
- package/components/shared/messages/SceneCueChip.svelte +82 -0
- package/components/shared/messages/SceneDivider.svelte +399 -0
- package/components/{sessions → shared}/messages/SessionComposer.svelte +33 -9
- package/components/shared/messages/SessionContainer.svelte +651 -0
- package/components/{sessions → shared}/messages/SessionMessage.svelte +52 -7
- package/components/shared/messages/TurnLine.svelte +254 -0
- package/components/{sessions → shared}/messages/conversation.svelte.ts +191 -2
- package/components/shared/messages/sceneMarks.ts +397 -0
- package/components/shared/places/Places.svelte +24 -0
- package/components/shared/places/PlacesWidget.svelte +290 -0
- package/components/shared/places/places.ts +11 -0
- package/components/{sessions → shared}/scene-portraits/ScenePortraits.svelte +1 -1
- package/components/shared/scene-portraits/ScenePortraitsWidget.svelte +404 -0
- package/components/{sessions → shared}/state/SlotControl.svelte +9 -1
- package/components/{sessions → shared}/stats/Stats.svelte +1 -1
- package/components/shared/stats/StatsWidget.svelte +350 -0
- package/components/{sessions → shared}/stats/stats.ts +3 -2
- package/components/shared/turn-order/TurnOrder.svelte +24 -0
- package/components/shared/turn-order/TurnOrderWidget.svelte +167 -0
- package/components/shared/turn-order/turn-order.ts +11 -0
- package/components/{sessions/shared → shared}/widgetRef.svelte.ts +9 -2
- package/components/shared/world-state/WorldState.svelte +33 -0
- package/components/shared/world-state/world-state.ts +10 -0
- package/components/tsconfig.json +2 -2
- package/dist/components/actions.js +294 -0
- package/dist/components/actions.source.json +1 -0
- package/dist/components/album.js +386 -0
- package/dist/components/album.source.json +1 -0
- package/dist/components/annex.js +457 -0
- package/dist/components/annex.source.json +1 -0
- package/dist/components/attendance.js +353 -0
- package/dist/components/attendance.source.json +1 -0
- package/dist/components/authors-note.js +5 -5
- package/dist/components/authors-note.source.json +1 -1
- package/dist/components/backdrop.js +561 -0
- package/dist/components/backdrop.source.json +1 -0
- package/dist/components/chronicle.js +1141 -0
- package/dist/components/chronicle.source.json +1 -0
- package/dist/components/core-ui.json +1 -1
- package/dist/components/lore-entries.js +5 -5
- package/dist/components/lore-entries.source.json +1 -1
- package/dist/components/messages.js +3014 -2489
- package/dist/components/messages.source.json +1 -1
- package/dist/components/places.js +1133 -0
- package/dist/components/places.source.json +1 -0
- package/dist/components/scene-portraits.js +514 -345
- package/dist/components/scene-portraits.source.json +1 -1
- package/dist/components/shared-3K7SOGH7.js +16 -0
- package/dist/components/shared-452PIS46.js +156 -0
- package/dist/components/shared-GEDAMORM.js +45 -0
- package/dist/components/{shared-TCQZXBE3.js → shared-GXTL5G2H.js} +4 -3
- package/dist/components/shared-ITSLBJB5.js +478 -0
- package/dist/components/shared-NK7QSVMU.js +400 -0
- package/dist/components/shared-TDWKI2QV.js +58 -0
- package/dist/components/{shared-UAQVMZZK.js → shared-XBPH6USH.js} +586 -18
- package/dist/components/{shared-AINANAIA.js → shared-XISPHAKY.js} +502 -98
- package/dist/components/stats.js +8 -208
- package/dist/components/stats.source.json +1 -1
- package/dist/components/turn-order.js +461 -0
- package/dist/components/turn-order.source.json +1 -0
- package/dist/components/world-state.js +14 -202
- package/dist/components/world-state.source.json +1 -1
- package/dist/{answerForm.d.ts → factories/answerForm.d.ts} +4 -30
- package/dist/{answerForm.js → factories/answerForm.js} +10 -39
- package/dist/factories/once.d.ts +7 -0
- package/dist/factories/once.js +9 -0
- package/dist/{turnOrder.d.ts → factories/turnOrder.d.ts} +0 -22
- package/dist/{turnOrder.js → factories/turnOrder.js} +4 -104
- package/dist/genres/adventure/advanceTime.d.ts +18 -0
- package/dist/genres/adventure/advanceTime.js +24 -0
- package/dist/genres/adventure/answer.d.ts +23 -0
- package/dist/genres/adventure/answer.js +59 -0
- package/dist/genres/adventure/answerForm.d.ts +9 -0
- package/dist/genres/adventure/answerForm.js +11 -0
- package/dist/genres/adventure/ask.d.ts +73 -0
- package/dist/genres/adventure/ask.js +157 -0
- package/dist/genres/adventure/create.d.ts +36 -0
- package/dist/genres/adventure/create.js +62 -0
- package/dist/genres/adventure/illustrateScene.d.ts +7 -0
- package/dist/genres/adventure/illustrateScene.js +19 -0
- package/dist/genres/adventure/index.d.ts +45 -0
- package/dist/genres/adventure/index.js +45 -0
- package/dist/genres/adventure/keeperAction.d.ts +43 -0
- package/dist/genres/adventure/keeperAction.js +217 -0
- package/dist/genres/adventure/look.d.ts +45 -0
- package/dist/genres/adventure/look.js +209 -0
- package/dist/{adventure.d.ts → genres/adventure/respond.d.ts} +74 -65
- package/dist/{adventure.js → genres/adventure/respond.js} +125 -65
- package/dist/genres/adventure/rest.d.ts +10 -0
- package/dist/genres/adventure/rest.js +16 -0
- package/dist/genres/adventure/summarizeScene.d.ts +7 -0
- package/dist/genres/adventure/summarizeScene.js +14 -0
- package/dist/genres/adventure/turnOrder.d.ts +10 -0
- package/dist/genres/adventure/turnOrder.js +27 -0
- package/dist/genres/chat/advanceTime.d.ts +7 -0
- package/dist/genres/chat/advanceTime.js +17 -0
- package/dist/genres/chat/answerForm.d.ts +9 -0
- package/dist/genres/chat/answerForm.js +11 -0
- package/dist/genres/chat/create.d.ts +7 -0
- package/dist/{createChat.js → genres/chat/create.js} +6 -6
- package/dist/genres/chat/generateImage.d.ts +7 -0
- package/dist/{generateImage.js → genres/chat/generateImage.js} +26 -22
- package/dist/genres/chat/illustrateScene.d.ts +8 -0
- package/dist/genres/chat/illustrateScene.js +19 -0
- package/dist/genres/chat/index.d.ts +18 -0
- package/dist/genres/chat/index.js +19 -0
- package/dist/{narrate.d.ts → genres/chat/narrate.d.ts} +3 -3
- package/dist/{narrate.js → genres/chat/narrate.js} +37 -12
- package/dist/{narrateCharacter.d.ts → genres/chat/narrateCharacter.d.ts} +2 -2
- package/dist/{narrateCharacter.js → genres/chat/narrateCharacter.js} +39 -17
- package/dist/genres/chat/respond.d.ts +25 -0
- package/dist/{respond.js → genres/chat/respond.js} +91 -23
- package/dist/genres/chat/summarizeScene.d.ts +7 -0
- package/dist/genres/chat/summarizeScene.js +14 -0
- package/dist/genres/chat/turnOrder.d.ts +9 -0
- package/dist/genres/chat/turnOrder.js +28 -0
- package/dist/{ui/sessions → genres/chat/ui}/authors-note/index.d.ts +1 -1
- package/dist/genres/guide/answerForm.d.ts +9 -0
- package/dist/genres/guide/answerForm.js +11 -0
- package/dist/genres/guide/create.d.ts +24 -0
- package/dist/genres/guide/create.js +58 -0
- package/dist/genres/guide/index.d.ts +10 -0
- package/dist/genres/guide/index.js +10 -0
- package/dist/{guide.d.ts → genres/guide/respond.d.ts} +1 -20
- package/dist/{guide.js → genres/guide/respond.js} +32 -61
- package/dist/genres/guide/summarizeScene.d.ts +7 -0
- package/dist/genres/guide/summarizeScene.js +14 -0
- package/dist/genres/guide/turnOrder.d.ts +10 -0
- package/dist/genres/guide/turnOrder.js +27 -0
- package/dist/genres/index.d.ts +14 -0
- package/dist/genres/index.js +41 -0
- package/dist/genres/lair/advanceTime.d.ts +7 -0
- package/dist/genres/lair/advanceTime.js +17 -0
- package/dist/genres/lair/answerForm.d.ts +17 -0
- package/dist/genres/lair/answerForm.js +19 -0
- package/dist/genres/lair/buildRoom.d.ts +64 -0
- package/dist/genres/lair/buildRoom.js +244 -0
- package/dist/genres/lair/castellanAction.d.ts +27 -0
- package/dist/genres/lair/castellanAction.js +177 -0
- package/dist/genres/lair/create.d.ts +28 -0
- package/dist/genres/lair/create.js +69 -0
- package/dist/genres/lair/fileRoom.d.ts +53 -0
- package/dist/genres/lair/fileRoom.js +288 -0
- package/dist/genres/lair/index.d.ts +62 -0
- package/dist/genres/lair/index.js +63 -0
- package/dist/genres/lair/nudge.d.ts +25 -0
- package/dist/genres/lair/nudge.js +78 -0
- package/dist/{lair.d.ts → genres/lair/respond.d.ts} +46 -59
- package/dist/{lair.js → genres/lair/respond.js} +55 -76
- package/dist/genres/lair/reveal.d.ts +10 -0
- package/dist/genres/lair/reveal.js +18 -0
- package/dist/genres/lair/roomAnswer.d.ts +86 -0
- package/dist/genres/lair/roomAnswer.js +378 -0
- package/dist/genres/lair/summarizeScene.d.ts +39 -0
- package/dist/genres/lair/summarizeScene.js +51 -0
- package/dist/genres/lair/trap.d.ts +11 -0
- package/dist/genres/lair/trap.js +24 -0
- package/dist/genres/lair/turnOrder.d.ts +9 -0
- package/dist/genres/lair/turnOrder.js +36 -0
- package/dist/genres/lair/whisper.d.ts +35 -0
- package/dist/genres/lair/whisper.js +90 -0
- package/dist/index.d.ts +52 -29
- package/dist/index.js +192 -86
- package/dist/loadouts.d.ts +37 -0
- package/dist/loadouts.js +105 -0
- package/dist/{entries.d.ts → registry/entries.d.ts} +1 -1
- package/dist/{genres.js → registry/genres.js} +40 -6
- package/dist/{ui/sessions → registry}/layouts.d.ts +41 -27
- package/dist/{ui/sessions → registry}/layouts.js +90 -49
- package/dist/{ui/sessions → registry}/widgets.d.ts +22 -0
- package/dist/registry/widgets.js +1294 -0
- package/dist/{presets.js → seed/presets.js} +28 -13
- package/dist/{prompts.d.ts → seed/prompts.d.ts} +10 -5
- package/dist/{prompts.js → seed/prompts.js} +225 -176
- package/dist/{annexField.d.ts → shared/annexField.d.ts} +12 -8
- package/dist/{annexField.js → shared/annexField.js} +16 -15
- package/dist/shared/builtins/branch.d.ts +8 -0
- package/dist/shared/builtins/branch.js +13 -0
- package/dist/{builtins.d.ts → shared/builtins/builtIn.d.ts} +16 -21
- package/dist/{builtins.js → shared/builtins/builtIn.js} +3 -37
- package/dist/shared/builtins/delete.d.ts +8 -0
- package/dist/shared/builtins/delete.js +13 -0
- package/dist/shared/builtins/edit.d.ts +8 -0
- package/dist/shared/builtins/edit.js +13 -0
- package/dist/shared/builtins/hide.d.ts +8 -0
- package/dist/shared/builtins/hide.js +13 -0
- package/dist/shared/builtins/index.d.ts +11 -0
- package/dist/shared/builtins/index.js +11 -0
- package/dist/shared/builtins/swipe.d.ts +8 -0
- package/dist/shared/builtins/swipe.js +17 -0
- package/dist/shared/describeLikeness.d.ts +14 -0
- package/dist/shared/describeLikeness.js +65 -0
- package/dist/shared/illustrateScene.d.ts +28 -0
- package/dist/shared/illustrateScene.js +181 -0
- package/dist/shared/portrait.d.ts +21 -0
- package/dist/shared/portrait.js +101 -0
- package/dist/shared/spriteFill.d.ts +14 -0
- package/dist/shared/spriteFill.js +107 -0
- package/dist/shared/sprites.d.ts +34 -0
- package/dist/shared/sprites.js +98 -0
- package/dist/shared/summarize/character.d.ts +9 -0
- package/dist/shared/summarize/character.js +10 -0
- package/dist/shared/summarize/history.d.ts +9 -0
- package/dist/shared/summarize/history.js +10 -0
- package/dist/shared/summarize/index.d.ts +12 -0
- package/dist/shared/summarize/index.js +12 -0
- package/dist/shared/summarize/scene.d.ts +38 -0
- package/dist/shared/summarize/scene.js +42 -0
- package/dist/shared/summarize/sceneIds.d.ts +17 -0
- package/dist/shared/summarize/sceneIds.js +17 -0
- package/dist/shared/summarize/summarizeScene.d.ts +113 -0
- package/dist/shared/summarize/summarizeScene.js +234 -0
- package/dist/shared/summarize/summarizeSpec.d.ts +54 -0
- package/dist/{summarize.js → shared/summarize/summarizeSpec.js} +23 -53
- package/dist/shared/summarize/world.d.ts +8 -0
- package/dist/shared/summarize/world.js +9 -0
- package/dist/shared/timePasses.d.ts +56 -0
- package/dist/shared/timePasses.js +86 -0
- package/dist/{toolLoop.d.ts → shared/toolLoop.d.ts} +25 -3
- package/dist/{toolLoop.js → shared/toolLoop.js} +70 -14
- package/dist/shared/ui/actions/index.d.ts +117 -0
- package/dist/shared/ui/actions/index.js +154 -0
- package/dist/shared/ui/album/index.d.ts +115 -0
- package/dist/shared/ui/album/index.js +178 -0
- package/dist/shared/ui/annex/index.d.ts +163 -0
- package/dist/shared/ui/annex/index.js +273 -0
- package/dist/shared/ui/attendance/index.d.ts +97 -0
- package/dist/shared/ui/attendance/index.js +89 -0
- package/dist/shared/ui/backdrop/index.d.ts +78 -0
- package/dist/shared/ui/backdrop/index.js +98 -0
- package/dist/shared/ui/chronicle/index.d.ts +230 -0
- package/dist/shared/ui/chronicle/index.js +249 -0
- package/dist/shared/ui/conversation/dossier.d.ts +33 -0
- package/dist/shared/ui/conversation/dossier.js +31 -0
- package/dist/{ui/sessions → shared/ui}/conversation/index.d.ts +2 -1
- package/dist/{ui/sessions → shared/ui}/conversation/index.js +3 -1
- package/dist/{ui/sessions → shared/ui}/conversation/messageVerbState.d.ts +1 -1
- package/dist/shared/ui/conversation/storyDays.d.ts +21 -0
- package/dist/shared/ui/conversation/storyDays.js +23 -0
- package/dist/{ui/sessions → shared/ui}/coreWidgetsEntry.d.ts +1 -1
- package/dist/{ui/sessions → shared/ui}/coreWidgetsEntry.js +1 -1
- package/dist/{ui/sessions → shared/ui}/lore-entries/index.d.ts +2 -2
- package/dist/shared/ui/places/index.d.ts +148 -0
- package/dist/shared/ui/places/index.js +249 -0
- package/dist/{ui/sessions → shared/ui}/scene-portraits/index.d.ts +1 -1
- package/dist/{ui/sessions → shared/ui}/scene-portraits/index.js +1 -1
- package/dist/shared/ui/scene-portraits/portraits.d.ts +191 -0
- package/dist/shared/ui/scene-portraits/portraits.js +223 -0
- package/dist/shared/ui/session-state/index.d.ts +16 -0
- package/dist/shared/ui/session-state/index.js +16 -0
- package/dist/{ui/sessions → shared/ui}/session-state/shapes.d.ts +2 -2
- package/dist/shared/ui/session-state/stateView.d.ts +249 -0
- package/dist/shared/ui/session-state/stateView.js +247 -0
- package/dist/shared/ui/turn-order/index.d.ts +146 -0
- package/dist/shared/ui/turn-order/index.js +257 -0
- package/dist/{ui/sessions → shared/ui}/widgetContext.d.ts +19 -10
- package/package.json +69 -30
- package/components/sessions/messages/SessionContainer.svelte +0 -459
- package/components/sessions/scene-portraits/ScenePortraitsWidget.svelte +0 -249
- package/components/sessions/stats/StatsWidget.svelte +0 -112
- package/components/sessions/world-state/WorldStateWidget.svelte +0 -112
- package/components/sessions/world-state/world-state.ts +0 -10
- package/dist/adventureActions.d.ts +0 -169
- package/dist/adventureActions.js +0 -599
- package/dist/createChat.d.ts +0 -7
- package/dist/generateImage.d.ts +0 -7
- package/dist/lairActions.d.ts +0 -296
- package/dist/lairActions.js +0 -1287
- package/dist/respond.d.ts +0 -24
- package/dist/sprites.d.ts +0 -24
- package/dist/sprites.js +0 -102
- package/dist/summarize.d.ts +0 -76
- package/dist/ui/sessions/conversation/dossier.d.ts +0 -328
- package/dist/ui/sessions/conversation/dossier.js +0 -31
- package/dist/ui/sessions/scene-portraits/portraits.d.ts +0 -95
- package/dist/ui/sessions/scene-portraits/portraits.js +0 -115
- package/dist/ui/sessions/session-state/index.d.ts +0 -15
- package/dist/ui/sessions/session-state/index.js +0 -15
- package/dist/ui/sessions/session-state/stateView.d.ts +0 -155
- package/dist/ui/sessions/session-state/stateView.js +0 -141
- package/dist/ui/sessions/widgets.js +0 -567
- package/components/{sessions → genres/chat}/authors-note/authors-note.ts +0 -0
- package/components/{sessions/shared → shared}/context.ts +0 -0
- package/components/{sessions → shared}/lore-entries/lore-entries.ts +0 -0
- package/components/{sessions → shared}/messages/MessageBlocksView.svelte +0 -0
- package/components/{sessions → shared}/messages/MessageMediaStrip.svelte +0 -0
- package/components/{sessions → shared}/messages/MessagePartsView.svelte +0 -0
- package/components/{sessions → shared}/messages/StateProposalList.svelte +0 -0
- package/components/{sessions → shared}/messages/mediaStrip.ts +0 -0
- package/components/{sessions → shared}/messages/messages.ts +0 -0
- package/components/{sessions → shared}/scene-portraits/StatBars.svelte +0 -0
- package/components/{sessions → shared}/scene-portraits/scene-portraits.ts +0 -0
- package/components/{sessions → shared}/state/entryFinder.ts +0 -0
- package/components/{sessions → shared}/state/slotWriter.svelte.ts +0 -0
- package/dist/components/{shared-RJDGOAVC.js → shared-FTRGUE7G.js} +78 -78
- /package/dist/{ui/sessions → genres/chat/ui}/authors-note/index.js +0 -0
- /package/dist/{entries.js → registry/entries.js} +0 -0
- /package/dist/{genres.d.ts → registry/genres.d.ts} +0 -0
- /package/dist/{slots.d.ts → registry/slots.d.ts} +0 -0
- /package/dist/{slots.js → registry/slots.js} +0 -0
- /package/dist/{statShapes.d.ts → registry/statShapes.d.ts} +0 -0
- /package/dist/{statShapes.js → registry/statShapes.js} +0 -0
- /package/dist/{guideMascotImage.d.ts → seed/guideMascotImage.d.ts} +0 -0
- /package/dist/{guideMascotImage.js → seed/guideMascotImage.js} +0 -0
- /package/dist/{presets.d.ts → seed/presets.d.ts} +0 -0
- /package/dist/{graphBuild.d.ts → shared/graphBuild.d.ts} +0 -0
- /package/dist/{graphBuild.js → shared/graphBuild.js} +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/actionsDisclosure.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/actionsDisclosure.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/composerTray.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/composerTray.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/formAnswer.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/formAnswer.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/itemValues.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/itemValues.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/messageOrder.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/messageOrder.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/messageSpeaker.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/messageSpeaker.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/messageVerbState.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/slashPalette.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/slashPalette.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/text.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/text.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/lore-entries/index.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/session-state/barMath.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/session-state/barMath.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/session-state/shapes.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/widgetContext.js +0 -0
package/dist/components/stats.js
CHANGED
|
@@ -1,220 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import "./shared-TCQZXBE3.js";
|
|
8
|
-
import "./shared-RJDGOAVC.js";
|
|
2
|
+
StatsWidget
|
|
3
|
+
} from "./shared-XISPHAKY.js";
|
|
4
|
+
import "./shared-452PIS46.js";
|
|
5
|
+
import "./shared-GXTL5G2H.js";
|
|
6
|
+
import "./shared-FTRGUE7G.js";
|
|
9
7
|
import {
|
|
10
8
|
WIDGET_CONTEXT_KEY,
|
|
11
|
-
append,
|
|
12
|
-
child,
|
|
13
|
-
comment,
|
|
14
|
-
each,
|
|
15
|
-
first_child,
|
|
16
|
-
from_html,
|
|
17
|
-
get,
|
|
18
|
-
if_block,
|
|
19
9
|
pop,
|
|
20
10
|
push,
|
|
21
|
-
reset,
|
|
22
11
|
setContext,
|
|
23
|
-
set_attribute,
|
|
24
|
-
set_custom_element_data,
|
|
25
|
-
set_text,
|
|
26
|
-
sibling,
|
|
27
12
|
svelteComponent,
|
|
28
|
-
template_effect,
|
|
29
13
|
untrack,
|
|
30
|
-
useWidgetContext,
|
|
31
|
-
user_derived,
|
|
32
14
|
widgetRefFromComponent
|
|
33
|
-
} from "./shared-
|
|
15
|
+
} from "./shared-XBPH6USH.js";
|
|
34
16
|
|
|
35
|
-
// components/
|
|
36
|
-
var root = from_html(`<p data-widget-part="stats.alert" role="alert"> </p>`);
|
|
37
|
-
var root_1 = from_html(`<div data-widget-part="stats.empty empty" role="status" data-scope-not-granted="session:state"><sp-icon></sp-icon> <span> </span></div>`, 2);
|
|
38
|
-
var root_2 = from_html(`<div data-widget-part="stats.empty empty" role="status"><sp-icon></sp-icon> <span> </span></div>`, 2);
|
|
39
|
-
var root_3 = from_html(`<div data-widget-part="stats.empty empty"><sp-icon></sp-icon> <span> </span></div>`, 2);
|
|
40
|
-
var root_4 = from_html(`<p data-widget-part="stats.card-note"> </p>`);
|
|
41
|
-
var root_5 = from_html(`<div data-widget-part="stats.card-body list"></div>`);
|
|
42
|
-
var root_6 = from_html(`<section data-widget-part="stats.card card"><header data-widget-part="stats.card-head card-head"><sp-icon></sp-icon> <span data-widget-part="stats.card-name"> </span></header> <!></section>`, 2);
|
|
43
|
-
var root_7 = from_html(`<div data-widget-part="stats.root" data-state-widget="stats"><!> <!> <!></div>`);
|
|
44
|
-
function StatsWidget($$anchor, $$props) {
|
|
45
|
-
push($$props, true);
|
|
46
|
-
const widget = useWidgetContext();
|
|
47
|
-
const writer = createSlotWriter(widget);
|
|
48
|
-
const t = (source) => widget?.current.t(source) ?? source;
|
|
49
|
-
const findEntries = createEntryFinder(widget, t);
|
|
50
|
-
let section = user_derived(() => widget?.current.session_state?.v1);
|
|
51
|
-
let settings = user_derived(() => widget?.current.settings.v1 ?? {});
|
|
52
|
-
let view = user_derived(() => statsView(get(section), get(settings), widget?.current.grants?.includes("session:state")));
|
|
53
|
-
var div = root_7();
|
|
54
|
-
var node = child(div);
|
|
55
|
-
{
|
|
56
|
-
var consequent = ($$anchor2) => {
|
|
57
|
-
var p = root();
|
|
58
|
-
var text = child(p, true);
|
|
59
|
-
reset(p);
|
|
60
|
-
template_effect(() => set_text(text, get(section).error));
|
|
61
|
-
append($$anchor2, p);
|
|
62
|
-
};
|
|
63
|
-
if_block(node, ($$render) => {
|
|
64
|
-
if (get(section)?.error) $$render(consequent);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
var node_1 = sibling(node, 2);
|
|
68
|
-
{
|
|
69
|
-
var consequent_1 = ($$anchor2) => {
|
|
70
|
-
var p_1 = root();
|
|
71
|
-
var text_1 = child(p_1, true);
|
|
72
|
-
reset(p_1);
|
|
73
|
-
template_effect(() => set_text(text_1, writer.error));
|
|
74
|
-
append($$anchor2, p_1);
|
|
75
|
-
};
|
|
76
|
-
if_block(node_1, ($$render) => {
|
|
77
|
-
if (writer.error) $$render(consequent_1);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
var node_2 = sibling(node_1, 2);
|
|
81
|
-
{
|
|
82
|
-
var consequent_2 = ($$anchor2) => {
|
|
83
|
-
var div_1 = root_1();
|
|
84
|
-
var sp_icon = child(div_1);
|
|
85
|
-
set_custom_element_data(sp_icon, "name", "lock");
|
|
86
|
-
set_custom_element_data(sp_icon, "size", "20");
|
|
87
|
-
var span = sibling(sp_icon, 2);
|
|
88
|
-
var text_2 = child(span, true);
|
|
89
|
-
reset(span);
|
|
90
|
-
reset(div_1);
|
|
91
|
-
template_effect(($0) => set_text(text_2, $0), [
|
|
92
|
-
() => t("This widget has not been granted the session's stats. An administrator can grant it in the extension's permissions.")
|
|
93
|
-
]);
|
|
94
|
-
append($$anchor2, div_1);
|
|
95
|
-
};
|
|
96
|
-
var consequent_3 = ($$anchor2) => {
|
|
97
|
-
var div_2 = root_2();
|
|
98
|
-
var sp_icon_1 = child(div_2);
|
|
99
|
-
set_custom_element_data(sp_icon_1, "name", "heart-pulse");
|
|
100
|
-
set_custom_element_data(sp_icon_1, "size", "20");
|
|
101
|
-
var span_1 = sibling(sp_icon_1, 2);
|
|
102
|
-
var text_3 = child(span_1, true);
|
|
103
|
-
reset(span_1);
|
|
104
|
-
reset(div_2);
|
|
105
|
-
template_effect(($0) => set_text(text_3, $0), [() => t("Loading the cast's stats\u2026")]);
|
|
106
|
-
append($$anchor2, div_2);
|
|
107
|
-
};
|
|
108
|
-
var consequent_4 = ($$anchor2) => {
|
|
109
|
-
};
|
|
110
|
-
var consequent_5 = ($$anchor2) => {
|
|
111
|
-
var div_3 = root_3();
|
|
112
|
-
var sp_icon_2 = child(div_3);
|
|
113
|
-
set_custom_element_data(sp_icon_2, "name", "heart-pulse");
|
|
114
|
-
set_custom_element_data(sp_icon_2, "size", "20");
|
|
115
|
-
var span_2 = sibling(sp_icon_2, 2);
|
|
116
|
-
var text_4 = child(span_2, true);
|
|
117
|
-
reset(span_2);
|
|
118
|
-
reset(div_3);
|
|
119
|
-
template_effect(($0) => set_text(text_4, $0), [
|
|
120
|
-
() => t("Nothing in this session declares stats. A genre, an extension or an administrator adds them, and they show up here.")
|
|
121
|
-
]);
|
|
122
|
-
append($$anchor2, div_3);
|
|
123
|
-
};
|
|
124
|
-
var consequent_6 = ($$anchor2) => {
|
|
125
|
-
var div_4 = root_3();
|
|
126
|
-
var sp_icon_3 = child(div_4);
|
|
127
|
-
set_custom_element_data(sp_icon_3, "name", "heart-pulse");
|
|
128
|
-
set_custom_element_data(sp_icon_3, "size", "20");
|
|
129
|
-
var span_3 = sibling(sp_icon_3, 2);
|
|
130
|
-
var text_5 = child(span_3, true);
|
|
131
|
-
reset(span_3);
|
|
132
|
-
reset(div_4);
|
|
133
|
-
template_effect(($0) => set_text(text_5, $0), [
|
|
134
|
-
() => get(view).members === "pick" ? t("No cast member matches the names in this widget's settings.") : t("No one in the cast has a stat in play yet. Set one on a cast member's page, or let the story change one.")
|
|
135
|
-
]);
|
|
136
|
-
append($$anchor2, div_4);
|
|
137
|
-
};
|
|
138
|
-
var alternate_1 = ($$anchor2) => {
|
|
139
|
-
const density = user_derived(() => get(view).density);
|
|
140
|
-
var fragment = comment();
|
|
141
|
-
var node_3 = first_child(fragment);
|
|
142
|
-
each(node_3, 17, () => get(view).members, (member) => member.owner.key, ($$anchor3, member) => {
|
|
143
|
-
var section_1 = root_6();
|
|
144
|
-
var header = child(section_1);
|
|
145
|
-
var sp_icon_4 = child(header);
|
|
146
|
-
set_custom_element_data(sp_icon_4, "name", "user-round");
|
|
147
|
-
set_custom_element_data(sp_icon_4, "size", "13");
|
|
148
|
-
var span_4 = sibling(sp_icon_4, 2);
|
|
149
|
-
var text_6 = child(span_4, true);
|
|
150
|
-
reset(span_4);
|
|
151
|
-
reset(header);
|
|
152
|
-
var node_4 = sibling(header, 2);
|
|
153
|
-
{
|
|
154
|
-
var consequent_7 = ($$anchor4) => {
|
|
155
|
-
var p_2 = root_4();
|
|
156
|
-
var text_7 = child(p_2, true);
|
|
157
|
-
reset(p_2);
|
|
158
|
-
template_effect(($0) => set_text(text_7, $0), [() => t("No stats to show for this member.")]);
|
|
159
|
-
append($$anchor4, p_2);
|
|
160
|
-
};
|
|
161
|
-
var alternate = ($$anchor4) => {
|
|
162
|
-
var div_5 = root_5();
|
|
163
|
-
each(div_5, 21, () => get(member).slots, (shown) => shown.slot.slotId, ($$anchor5, shown) => {
|
|
164
|
-
SlotControl($$anchor5, {
|
|
165
|
-
get slot() {
|
|
166
|
-
return get(shown).slot;
|
|
167
|
-
},
|
|
168
|
-
get density() {
|
|
169
|
-
return get(density);
|
|
170
|
-
},
|
|
171
|
-
get config() {
|
|
172
|
-
return get(shown).config;
|
|
173
|
-
},
|
|
174
|
-
get value() {
|
|
175
|
-
return get(shown).value;
|
|
176
|
-
},
|
|
177
|
-
t,
|
|
178
|
-
get findEntries() {
|
|
179
|
-
return findEntries;
|
|
180
|
-
},
|
|
181
|
-
onset: (next) => void writer.set(get(member).owner, get(shown).slot.slotId, next)
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
reset(div_5);
|
|
185
|
-
template_effect(() => set_attribute(div_5, "data-density", get(density)));
|
|
186
|
-
append($$anchor4, div_5);
|
|
187
|
-
};
|
|
188
|
-
if_block(node_4, ($$render) => {
|
|
189
|
-
if (!get(member).slots.length) $$render(consequent_7);
|
|
190
|
-
else $$render(alternate, -1);
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
reset(section_1);
|
|
194
|
-
template_effect(() => {
|
|
195
|
-
set_attribute(section_1, "data-owner-key", get(member).owner.key);
|
|
196
|
-
set_attribute(section_1, "aria-label", get(member).owner.label);
|
|
197
|
-
set_text(text_6, get(member).owner.label);
|
|
198
|
-
});
|
|
199
|
-
append($$anchor3, section_1);
|
|
200
|
-
});
|
|
201
|
-
append($$anchor2, fragment);
|
|
202
|
-
};
|
|
203
|
-
if_block(node_2, ($$render) => {
|
|
204
|
-
if (get(view).status === "not-granted") $$render(consequent_2);
|
|
205
|
-
else if (get(view).status === "loading") $$render(consequent_3, 1);
|
|
206
|
-
else if (get(view).status === "failed") $$render(consequent_4, 2);
|
|
207
|
-
else if (get(view).status === "none-declared") $$render(consequent_5, 3);
|
|
208
|
-
else if (get(view).status === "no-members") $$render(consequent_6, 4);
|
|
209
|
-
else $$render(alternate_1, -1);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
reset(div);
|
|
213
|
-
append($$anchor, div);
|
|
214
|
-
pop();
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// components/sessions/stats/Stats.svelte
|
|
17
|
+
// components/shared/stats/Stats.svelte
|
|
218
18
|
function Stats($$anchor, $$props) {
|
|
219
19
|
push($$props, true);
|
|
220
20
|
setContext(WIDGET_CONTEXT_KEY, widgetRefFromComponent(untrack(() => $$props.ctx), { id: "stats", instanceId: "stats", title: "Stats" }));
|
|
@@ -222,7 +22,7 @@ function Stats($$anchor, $$props) {
|
|
|
222
22
|
pop();
|
|
223
23
|
}
|
|
224
24
|
|
|
225
|
-
// components/
|
|
25
|
+
// components/shared/stats/stats.ts
|
|
226
26
|
var stats_default = svelteComponent(Stats);
|
|
227
27
|
export {
|
|
228
28
|
stats_default as default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"slug":"stats","framework":"svelte","entry":"sessions/stats/stats.ts","files":{"sessions/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","sessions/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_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} 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\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// No host menu across the port yet: dismissed, as a native host without one answers.\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\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","sessions/state/SlotControl.svelte":"<script lang=\"ts\">\n\t/**\n\t * One attribute slot, drawn as what it is and edited in place — shared by\n\t * core's World State and Stats widgets (R21).\n\t *\n\t * The slot's STAT SHAPE decides the control (`slotKind`: its field, or its\n\t * type when the host predates shapes), and the configuration in force\n\t * decides its bounds: a bounded number is a bar, a choice is a chip over a\n\t * closed set (an `sp-menu` on the chip), a list opens to its items — add,\n\t * remove, move up and down — a story time is read through the calendar\n\t * and opens to its year, month, day and time, text is a line, a boolean is\n\t * a toggle. A derived slot is computed on every read and a retired one\n\t * takes nothing new, so both are shown greyed and never offered.\n\t *\n\t * Every edit here is the USER's, which is the one writer with authority: it\n\t * applies at once (`set-attribute-value`) rather than waiting at the review\n\t * gate. Nothing is applied optimistically — the new value arrives as a\n\t * `session_state` push, so what is drawn a beat later is the resolver's\n\t * answer and not this component's guess. A list is written whole, its\n\t * items in order.\n\t *\n\t * A number or text field commits on Enter, and Escape puts the stored\n\t * value back (R80: the field's `keys`). Leaving the field commits what was\n\t * typed, and only closes it when nothing was — never a write of the value\n\t * already stored. A text field also commits on `change`; a number field\n\t * does not, because the browser raises `change` on every spinner step and\n\t * a person may step several times before they are done. A list's new item\n\t * is added on Enter; a story time is saved on Enter or its Save button —\n\t * it has four fields, so leaving one of them is not being done.\n\t *\n\t * A list that takes lore references (one not closed over words) also\n\t * picks from the session's lorebook (phase 3c): item entries first, then\n\t * the rest of the book, with how many to add — Enter in the count field\n\t * adds, Escape closes the picker. A held reference reads \"Name ×N\" and\n\t * steps up and down; one fewer than one takes it out.\n\t *\n\t * The markup carries no look. A shared control owns its parts under its own\n\t * name, so every element here is `stat-slot.<part>` in `data-widget-part`\n\t * (with a generic part where the element truly is one): a style draws a\n\t * slot once for every widget, and scopes it to one through the widget's\n\t * root (STYLE-GUIDE §6.16). A slot's state is its own `data-*` or ARIA,\n\t * never a part: `data-density`, `data-retired`, `data-slot-shape`,\n\t * `data-empty` (nothing to show), `aria-pressed` (a switch on, a row\n\t * chosen), `role=\"alert\"` (refused).\n\t */\n\timport type { SessionStateSlotV1 } from \"@serene-pub/core-catalog/widgets\"\n\timport {\n\t\tbarView,\n\t\tenumValues,\n\t\tlistItemKeyOf,\n\t\tlistItemRef,\n\t\tlistItemText,\n\t\tlistItemsOf,\n\t\tlistMoved,\n\t\tcountDraftFor,\n\t\tlistWithAdded,\n\t\tlistWithRefAdded,\n\t\tlistWithRefStep,\n\t\tlistWithout,\n\t\tnumberDraftFor,\n\t\tpickableEntries,\n\t\tslotTakesLoreRefs,\n\t\ttype PickableEntry,\n\t\tshownValueText,\n\t\tslotIsWhole,\n\t\tslotKind,\n\t\tslotWritable,\n\t\tstoryTimeDraftOf,\n\t\tstoryTimeDraftValue,\n\t\ttextDraftValue,\n\t\ttype SlotWriteValue,\n\t\ttype StoryTimeDraft\n\t} from \"@serene-pub/core-catalog/session-state\"\n\timport type { HostKeyEventDetail } from \"@serene-pub/sdk/component\"\n\timport type { EntryFinder, EntryFinds } from \"./entryFinder\"\n\n\tinterface Props {\n\t\tslot: SessionStateSlotV1\n\t\t/** The configuration in force for this owner: bounds, options, a list's limits. */\n\t\tconfig: Record<string, unknown>\n\t\tvalue: unknown\n\t\t/** Compact drops the label into the control's own line. */\n\t\tdensity?: \"compact\" | \"full\"\n\t\t/** The widget's language. */\n\t\tt: (source: string) => string\n\t\t/** `null` clears this layer, so the read inherits again. */\n\t\tonset: (value: SlotWriteValue) => void\n\t\t/** Searches the session's lorebook for a list's picker; absent, a list adds words only. */\n\t\tfindEntries?: EntryFinder\n\t}\n\n\tlet { slot, config, value, density = \"full\", t, onset, findEntries }: Props = $props()\n\n\t/** A menu item's value for \"not set\" — never an option's, which are `opt:`-prefixed. */\n\tconst CLEAR = \"clear\"\n\n\tlet editing = $state(false)\n\tlet numberDraft = $state<number | null>(null)\n\tlet textDraft = $state(\"\")\n\tlet itemDraft = $state(\"\")\n\tlet timeDraft = $state<StoryTimeDraft>({ year: \"\", month: \"\", day: \"\", time: \"\" })\n\t/** Why the editor's last attempt wrote nothing — a list over its limit, a time that is not one. */\n\tlet invalid = $state<string | null>(null)\n\t/** The drafts as the field opened, so leaving it untouched writes nothing. */\n\tlet numberOpened: number | null = null\n\tlet textOpened = \"\"\n\n\t// The lorebook picker, inside a list's editor.\n\tlet picking = $state(false)\n\tlet pickWords = $state(\"\")\n\tlet pickCount = $state<number | null>(1)\n\tlet pickFound = $state<EntryFinds | null>(null)\n\tlet pickChosen = $state<number | null>(null)\n\tlet pickBusy = $state(false)\n\t/** The newest search owns the list: an older answer that lands late is dropped. */\n\tlet searches = 0\n\n\tlet kind = $derived(slotKind(slot))\n\tlet bar = $derived(kind === \"number\" ? barView(value, config as { min?: number; max?: number }) : null)\n\tlet options = $derived(enumValues(config))\n\tlet items = $derived(listItemsOf(value))\n\tlet canPick = $derived(!!findEntries && slotTakesLoreRefs(config))\n\tlet offered = $derived<PickableEntry[]>(pickFound ? pickableEntries(value, pickFound.pages) : [])\n\tlet offeredItems = $derived(offered.filter((e) => e.item))\n\tlet offeredOthers = $derived(offered.filter((e) => !e.item))\n\tlet chosen = $derived(offered.find((e) => e.entryId === pickChosen) ?? null)\n\tlet writable = $derived(slotWritable(slot))\n\tlet shown = $derived(shownValueText(slot, value, t))\n\tlet notSet = $derived(t(\"not set\"))\n\tlet fieldLabel = $derived(t(\"{label} value\").replace(\"{label}\", slot.label))\n\tlet editLabel = $derived(t(\"{label}, edit\").replace(\"{label}\", slot.label))\n\tlet barEditLabel = $derived(\n\t\tbar ? t(\"{label} {value}, edit\").replace(\"{label}\", slot.label).replace(\"{value}\", bar.label) : editLabel\n\t)\n\n\tfunction open() {\n\t\tif (!writable) return\n\t\tnumberDraft = numberOpened = typeof value === \"number\" ? value : null\n\t\ttextDraft = textOpened = value === undefined || value === null ? \"\" : String(value)\n\t\titemDraft = \"\"\n\t\ttimeDraft = storyTimeDraftOf(value)\n\t\tinvalid = null\n\t\tpicking = false\n\t\tediting = true\n\t}\n\n\t/** One commit per edit: Enter and `change` may both arrive for one. */\n\tfunction commitNumber() {\n\t\tif (!editing) return\n\t\tediting = false\n\t\tconst next = numberDraftFor(numberDraft, config as { min?: number; max?: number }, slotIsWhole(slot))\n\t\tif (next !== undefined) onset(next)\n\t}\n\n\tfunction commitText() {\n\t\tif (!editing) return\n\t\tediting = false\n\t\tonset(textDraftValue(textDraft, config as { maxLength?: unknown }))\n\t}\n\n\t/** Enter commits; Escape leaves the stored value as it was. */\n\tfunction onkey(e: CustomEvent<HostKeyEventDetail>, commit: () => void) {\n\t\tif (e.detail.key === \"Enter\") commit()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n\n\t/** Leaving the field: commit what was typed, or just close it. */\n\tfunction onblur(unchanged: boolean, commit: () => void) {\n\t\tif (!editing) return\n\t\tif (unchanged) editing = false\n\t\telse commit()\n\t}\n\n\tfunction pick(e: CustomEvent<{ value: string }>) {\n\t\tconst v = e.detail.value\n\t\tif (v === CLEAR) onset(null)\n\t\telse if (v.startsWith(\"opt:\")) onset(v.slice(4))\n\t}\n\n\t// ── A list: every change writes the whole list, and the editor stays open ──\n\n\tfunction addItem() {\n\t\tconst edit = listWithAdded(value, itemDraft, config)\n\t\tif (!edit) return\n\t\tif (edit.refusal) {\n\t\t\tinvalid = edit.refusal\n\t\t\treturn\n\t\t}\n\t\tinvalid = null\n\t\titemDraft = \"\"\n\t\tonset(edit.value)\n\t}\n\n\tfunction onItemKey(e: CustomEvent<HostKeyEventDetail>) {\n\t\tif (e.detail.key === \"Enter\") addItem()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n\n\t// ── A list's lorebook picker: choose an entry, say how many, add ──\n\n\tasync function search() {\n\t\tif (!findEntries) return\n\t\tconst mine = ++searches\n\t\tpickBusy = true\n\t\ttry {\n\t\t\tconst found = await findEntries(pickWords)\n\t\t\tif (mine !== searches) return\n\t\t\tpickFound = found\n\t\t\tif (pickChosen !== null && !found.pages.some((p) => p.some((r) => r.id === pickChosen))) pickChosen = null\n\t\t} catch (e) {\n\t\t\tif (mine !== searches) return\n\t\t\tpickFound = { pages: [], notice: e instanceof Error ? e.message : String(e) }\n\t\t} finally {\n\t\t\tif (mine === searches) pickBusy = false\n\t\t}\n\t}\n\n\tfunction openPicker() {\n\t\tpicking = true\n\t\tpickWords = \"\"\n\t\tpickCount = 1\n\t\tpickChosen = null\n\t\tpickFound = null\n\t\tinvalid = null\n\t\tvoid search()\n\t}\n\n\tfunction closePicker() {\n\t\tpicking = false\n\t\tpickChosen = null\n\t}\n\n\tfunction addPicked() {\n\t\tif (!chosen) {\n\t\t\tinvalid = t(\"Choose an entry to add first.\")\n\t\t\treturn\n\t\t}\n\t\tconst count = countDraftFor(pickCount)\n\t\tif (count === undefined) {\n\t\t\tinvalid = t(\"How many is a whole number, 1 or more.\")\n\t\t\treturn\n\t\t}\n\t\tconst edit = listWithRefAdded(value, chosen.entryId, count, config)\n\t\tif (edit.refusal) {\n\t\t\tinvalid = edit.refusal\n\t\t\treturn\n\t\t}\n\t\tinvalid = null\n\t\tpickCount = 1\n\t\tonset(edit.value)\n\t}\n\n\tfunction onPickKey(e: CustomEvent<HostKeyEventDetail>, enter: () => void) {\n\t\tif (e.detail.key === \"Enter\") enter()\n\t\telse if (e.detail.key === \"Escape\") closePicker()\n\t}\n\n\t// ── A story time: four fields, saved together ──\n\n\tfunction commitTime() {\n\t\tif (!editing) return\n\t\tconst next = storyTimeDraftValue(timeDraft)\n\t\tif (next === undefined) {\n\t\t\tinvalid = t(\"That is not a story time: a year, then a month, a day and a time as hh:mm — each optional, a day only with a month.\")\n\t\t\treturn\n\t\t}\n\t\tediting = false\n\t\tinvalid = null\n\t\tonset(next)\n\t}\n\n\tfunction onTimeKey(e: CustomEvent<HostKeyEventDetail>) {\n\t\tif (e.detail.key === \"Enter\") commitTime()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n</script>\n\n<div\n\tdata-widget-part=\"stat-slot.root row\"\n\tdata-density={density}\n\tdata-slot-id={slot.slotId}\n\tdata-slot-type={slot.type}\n\tdata-slot-shape={kind}\n\tdata-retired={slot.retired ? \"\" : undefined}\n>\n\t<span data-widget-part=\"stat-slot.label label\" title={slot.description ?? slot.label}>\n\t\t{slot.label}\n\t\t{#if slot.required}\n\t\t\t<span data-widget-part=\"stat-slot.required\" role=\"img\" aria-label={t(\"required\")} title={t(\"required\")}>*</span>\n\t\t{/if}\n\t\t{#if slot.retired}\n\t\t\t<sp-icon name=\"archive\" size=\"10\" label={t(\"retired\")}></sp-icon>\n\t\t{:else if kind === \"derived\"}\n\t\t\t<sp-icon name=\"sigma\" size=\"10\"></sp-icon>\n\t\t{/if}\n\t</span>\n\n\t<div data-widget-part=\"stat-slot.control\">\n\t\t{#if kind === \"boolean\" && writable}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\taria-pressed={value === true}\n\t\t\t\tonclick={() => onset(value === true ? false : true)}\n\t\t\t>\n\t\t\t\t{value === undefined ? notSet : shown}\n\t\t\t</button>\n\t\t{:else if editing && kind === \"number\"}\n\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t<input\n\t\t\t\tdata-widget-part=\"stat-slot.field\"\n\t\t\t\ttype=\"number\"\n\t\t\t\taria-label={fieldLabel}\n\t\t\t\tmin={(config as { min?: number }).min}\n\t\t\t\tmax={(config as { max?: number }).max}\n\t\t\t\tstep={slotIsWhole(slot) ? \"1\" : \"any\"}\n\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\tautofocus\n\t\t\t\tbind:value={numberDraft}\n\t\t\t\tonblur={() => onblur(numberDraft === numberOpened, commitNumber)}\n\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onkey(e, commitNumber)}\n\t\t\t/>\n\t\t{:else if editing && kind === \"list\"}\n\t\t\t<div data-widget-part=\"stat-slot.editor\" role=\"group\" aria-label={fieldLabel}>\n\t\t\t\t{#if items.length}\n\t\t\t\t\t<ol data-widget-part=\"stat-slot.items list\">\n\t\t\t\t\t\t{#each items as item, i (listItemKeyOf(item, i))}\n\t\t\t\t\t\t\t{@const itemText = listItemText(item, t)}\n\t\t\t\t\t\t\t{@const ref = listItemRef(item)}\n\t\t\t\t\t\t\t<li data-widget-part=\"stat-slot.item row\" data-item-index={i}>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.item-text label\">{itemText}</span>\n\t\t\t\t\t\t\t\t{#if ref}\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-less\"\n\t\t\t\t\t\t\t\t\t\taria-label={t(\"One fewer {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithRefStep(value, ref.entryId, -1))}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"minus\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-more\"\n\t\t\t\t\t\t\t\t\t\taria-label={t(\"One more {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithRefStep(value, ref.entryId, 1))}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"plus\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-up\"\n\t\t\t\t\t\t\t\t\tdisabled={i === 0}\n\t\t\t\t\t\t\t\t\taria-label={t(\"Move {item} up\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listMoved(value, i, -1))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"arrow-up\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-down\"\n\t\t\t\t\t\t\t\t\tdisabled={i === items.length - 1}\n\t\t\t\t\t\t\t\t\taria-label={t(\"Move {item} down\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listMoved(value, i, 1))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"arrow-down\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-remove\"\n\t\t\t\t\t\t\t\t\taria-label={t(\"Remove {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithout(value, i))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"x\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</ol>\n\t\t\t\t{:else}\n\t\t\t\t\t<p data-widget-part=\"stat-slot.items-empty empty\">{t(\"Nothing in the list yet.\")}</p>\n\t\t\t\t{/if}\n\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.add stat-slot.field\"\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\taria-label={t(\"Add to {label}\").replace(\"{label}\", slot.label)}\n\t\t\t\t\tplaceholder={t(\"Add an item, then Enter\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tautofocus\n\t\t\t\t\tbind:value={itemDraft}\n\t\t\t\t\tonkey={onItemKey}\n\t\t\t\t/>\n\t\t\t\t{#if canPick && !picking}\n\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-open\" onclick={openPicker}>\n\t\t\t\t\t\t<sp-icon name=\"book-open\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t<span>{t(\"Add from the lorebook\")}</span>\n\t\t\t\t\t</button>\n\t\t\t\t{:else if canPick}\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"stat-slot.picker\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={t(\"Add to {label} from the lorebook\").replace(\"{label}\", slot.label)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-search stat-slot.field\"\n\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\taria-label={t(\"Search the lorebook\")}\n\t\t\t\t\t\t\tplaceholder={t(\"Search by name or key, then Enter\")}\n\t\t\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\t\t\tautofocus\n\t\t\t\t\t\t\tbind:value={pickWords}\n\t\t\t\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onPickKey(e, () => void search())}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{#if !pickFound}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Searching the lorebook…\")}</p>\n\t\t\t\t\t\t{:else if pickFound.notice}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{pickFound.notice}</p>\n\t\t\t\t\t\t{:else if !offered.length}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Nothing in the lorebook matches.\")}</p>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t{#each [{ heading: t(\"Items\"), rows: offeredItems, group: \"items\" }, { heading: t(\"Other entries\"), rows: offeredOthers, group: \"others\" }] as part (part.group)}\n\t\t\t\t\t\t\t\t{#if part.rows.length}\n\t\t\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-heading\">{part.heading}</p>\n\t\t\t\t\t\t\t\t\t<ul data-widget-part=\"stat-slot.pick-list list\" aria-label={part.heading} data-pick-group={part.group}>\n\t\t\t\t\t\t\t\t\t\t{#each part.rows as entry (entry.entryId)}\n\t\t\t\t\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-entry row\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata-entry-id={entry.entryId}\n\t\t\t\t\t\t\t\t\t\t\t\t\taria-pressed={pickChosen === entry.entryId}\n\t\t\t\t\t\t\t\t\t\t\t\t\tonclick={() => (pickChosen = pickChosen === entry.entryId ? null : entry.entryId)}\n\t\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.pick-title label\">{entry.title}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{#if entry.held}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.pick-held\">{t(\"held ×{n}\").replace(\"{n}\", String(entry.held))}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if pickBusy && pickFound}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Searching the lorebook…\")}</p>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<div data-widget-part=\"stat-slot.pick-add toolbar\">\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-count stat-slot.field\"\n\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\tmin=\"1\"\n\t\t\t\t\t\t\t\tstep=\"1\"\n\t\t\t\t\t\t\t\taria-label={chosen ? t(\"How many {item} to add\").replace(\"{item}\", chosen.title) : t(\"How many to add\")}\n\t\t\t\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\t\t\t\tbind:value={pickCount}\n\t\t\t\t\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onPickKey(e, addPicked)}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-confirm\" disabled={!chosen} onclick={addPicked}>\n\t\t\t\t\t\t\t\t{chosen ? t(\"Add {item}\").replace(\"{item}\", chosen.title) : t(\"Add\")}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-close\" onclick={closePicker}>{t(\"Close\")}</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t\t{#if invalid}<p data-widget-part=\"stat-slot.invalid\" role=\"alert\">{invalid}</p>{/if}\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.done\" onclick={() => (editing = false)}>{t(\"Done\")}</button>\n\t\t\t</div>\n\t\t{:else if editing && kind === \"story-time\"}\n\t\t\t<div data-widget-part=\"stat-slot.editor\" role=\"group\" aria-label={fieldLabel}>\n\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.year stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Year\")}\n\t\t\t\t\tplaceholder={t(\"Year\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tautofocus\n\t\t\t\t\tbind:value={timeDraft.year}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.month stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tmin=\"1\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Month\")}\n\t\t\t\t\tplaceholder={t(\"Month\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.month}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.day stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tmin=\"1\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Day\")}\n\t\t\t\t\tplaceholder={t(\"Day\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.day}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.clock stat-slot.field\"\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\taria-label={t(\"Time of day\")}\n\t\t\t\t\tplaceholder=\"hh:mm\"\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.time}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t{#if invalid}<p data-widget-part=\"stat-slot.invalid\" role=\"alert\">{invalid}</p>{/if}\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.save\" onclick={commitTime}>{t(\"Save\")}</button>\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.cancel\" onclick={() => (editing = false)}>{t(\"Cancel\")}</button>\n\t\t\t</div>\n\t\t{:else if editing}\n\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t<input\n\t\t\t\tdata-widget-part=\"stat-slot.field\"\n\t\t\t\ttype=\"text\"\n\t\t\t\taria-label={fieldLabel}\n\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\tautofocus\n\t\t\t\tbind:value={textDraft}\n\t\t\t\tonchange={commitText}\n\t\t\t\tonblur={() => onblur(textDraft === textOpened, commitText)}\n\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onkey(e, commitText)}\n\t\t\t/>\n\t\t{:else if bar}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.bar\"\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={barEditLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t<span data-widget-part=\"stat-slot.track meter\">\n\t\t\t\t\t<span data-widget-part=\"stat-slot.fill\" style:--sp-fill=\"{bar.percent}%\"></span>\n\t\t\t\t</span>\n\t\t\t\t<span data-widget-part=\"stat-slot.bar-value value\">{bar.label}</span>\n\t\t\t</button>\n\t\t{:else if kind === \"choice\" && writable}\n\t\t\t<!-- The chip opens the closed set; picking one writes it. -->\n\t\t\t<sp-menu label={fieldLabel} onselect={pick}>\n\t\t\t\t<button\n\t\t\t\t\tslot=\"trigger\"\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\t\tdata-empty={value == null ? \"\" : undefined}\n\t\t\t\t\taria-label={editLabel}\n\t\t\t\t>\n\t\t\t\t\t{shown || notSet}\n\t\t\t\t</button>\n\t\t\t\t<sp-menu-item value={CLEAR} data-widget-part=\"stat-slot.option\" data-empty=\"\">{notSet}</sp-menu-item>\n\t\t\t\t{#each options as option (option)}\n\t\t\t\t\t<sp-menu-item value=\"opt:{option}\" data-widget-part=\"stat-slot.option\">\n\t\t\t\t\t\t{#if value === option}<sp-icon name=\"check\" size=\"12\" label={t(\"current\")}></sp-icon>{/if}\n\t\t\t\t\t\t<span>{option}</span>\n\t\t\t\t\t</sp-menu-item>\n\t\t\t\t{/each}\n\t\t\t</sp-menu>\n\t\t{:else if kind === \"choice\"}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\tdata-empty={value == null ? \"\" : undefined}\n\t\t\t\tdisabled\n\t\t\t\taria-label={editLabel}\n\t\t\t>\n\t\t\t\t{shown || notSet}\n\t\t\t</button>\n\t\t{:else if kind === \"list\"}\n\t\t\t<!-- A list reads as its items; opening it edits them. -->\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.line value\"\n\t\t\t\tdata-empty={items.length ? undefined : \"\"}\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={editLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t{items.length ? shown : value === undefined ? notSet : t(\"none\")}\n\t\t\t</button>\n\t\t{:else}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.line value\"\n\t\t\t\tdata-empty={value === undefined ? \"\" : undefined}\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={editLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t{shown || notSet}\n\t\t\t</button>\n\t\t{/if}\n\t</div>\n</div>\n","sessions/state/entryFinder.ts":"/**\n * 🚧 A state widget's lorebook search for a list's picker (attributes phase\n * 3c): the session's book through `session-entries`, item entries asked for\n * first (`typeIds`), then the rest of the book — two pages the picker merges\n * (`pickableEntries`), so the items lead even in a book too big for one page.\n *\n * A session that reads no lorebook, and a viewer who does not own the book,\n * are told so in words (`notice`) rather than shown an empty list that reads\n * as \"nothing to pick\". A declined request rejects, and the picker says why.\n */\nimport type { WidgetContextRef } from \"@serene-pub/core-catalog/widgets\"\nimport { ITEM_ENTRY_TYPE_ID } from \"@serene-pub/core-catalog/session-state\"\n\n/** One row the picker can offer, as `session-entries` answered it. */\nexport interface FoundEntry {\n\tid: number\n\ttypeId: string\n\ttitle: string\n}\n\n/** What one search found: the item page, then the book's page; or why there is nothing. */\nexport interface EntryFinds {\n\tpages: FoundEntry[][]\n\tnotice: string | null\n}\n\n/** Search the session's lorebook by title or key; blank is the whole book. */\nexport type EntryFinder = (titleOrKey: string) => Promise<EntryFinds>\n\n/** How many of each the picker shows before the search has to narrow it. */\nconst PAGE = 25\n\nexport function createEntryFinder(\n\twidget: WidgetContextRef | undefined,\n\tt: (source: string) => string\n): EntryFinder | undefined {\n\tif (!widget) return undefined\n\treturn async (titleOrKey) => {\n\t\tconst words = titleOrKey.trim()\n\t\tconst ask = (typeIds?: string[]) =>\n\t\t\twidget.current.request(\"session-entries\", {\n\t\t\t\t...(words ? { titleOrKey: words } : {}),\n\t\t\t\tsort: \"name\",\n\t\t\t\t...(typeIds ? { typeIds } : {}),\n\t\t\t\tlimit: PAGE\n\t\t\t})\n\t\tconst items = await ask([ITEM_ENTRY_TYPE_ID])\n\t\tif (items.lorebookId == null) return { pages: [], notice: t(\"This session reads no lorebook, so there is nothing to pick from.\") }\n\t\tif (items.ownerOnly)\n\t\t\treturn { pages: [], notice: t(\"Only the lorebook's owner can pick from it. Type the item's name instead.\") }\n\t\tconst rest = await ask()\n\t\tconst rows = (page: { rows: FoundEntry[] }) => page.rows.map(({ id, typeId, title }) => ({ id, typeId, title }))\n\t\treturn { pages: [rows(items), rows(rest)], notice: null }\n\t}\n}\n","sessions/state/slotWriter.svelte.ts":"/**\n * A state widget's writes (R21): `set-attribute-value` through the widget's\n * own context, and the widget's OWN error line (R77) — a write that fails is\n * said in the widget that asked, never in every state widget on the page.\n *\n * The newest write owns the line: asking again clears it, and a refusal of\n * an older write that lands after a newer one was asked says nothing.\n */\nimport type { SessionStateOwnerV1, WidgetContextRef } from \"@serene-pub/core-catalog/widgets\"\nimport type { SlotWriteValue } from \"@serene-pub/core-catalog/session-state\"\n\nexport interface SlotWriter {\n\t/** Why the newest write failed, in words; null when it did not (or has not answered). */\n\treadonly error: string | null\n\tset(owner: SessionStateOwnerV1, slotId: string, value: SlotWriteValue): Promise<void>\n}\n\nexport function createSlotWriter(widget: WidgetContextRef | undefined): SlotWriter {\n\tlet error = $state<string | null>(null)\n\tlet asked = 0\n\treturn {\n\t\tget error() {\n\t\t\treturn error\n\t\t},\n\t\tasync set(owner, slotId, value) {\n\t\t\tconst mine = ++asked\n\t\t\terror = null\n\t\t\tif (!widget) return\n\t\t\ttry {\n\t\t\t\tawait widget.current.request(\"set-attribute-value\", {\n\t\t\t\t\towner: { kind: owner.kind, id: owner.id },\n\t\t\t\t\tslotId,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t} catch (e) {\n\t\t\t\tif (mine === asked) error = e instanceof Error ? e.message : String(e)\n\t\t\t}\n\t\t}\n\t}\n}\n","sessions/stats/Stats.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's Stats widget as a remote component (R21): 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 StatsWidget from \"./StatsWidget.svelte\"\n\timport { widgetRefFromComponent } from \"../shared/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: \"stats\", instanceId: \"stats\", title: \"Stats\" }\n\t\t)\n\t)\n</script>\n\n<StatsWidget />\n","sessions/stats/StatsWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * The Stats widget: one card per cast member, one row per slot they carry\n\t * (R21).\n\t *\n\t * Values come from the session's one resolved read (the `session_state`\n\t * section), so this widget never resolves anything itself — which layer a\n\t * number came from is a question for the cast member's page, not for the\n\t * playing surface. What it does own is the drawing: a bounded integer is a\n\t * bar, an enum a chip, text a line, a boolean a toggle, and a derived or\n\t * retired slot is greyed because there is nothing to write.\n\t *\n\t * A genre that declares no slots gets an empty state that says so rather\n\t * than a card of blanks — a newcomer in a chat session never sees a bar.\n\t * Writes `set-attribute-value`, whose refusal is this widget's own line\n\t * (R77).\n\t *\n\t * The markup carries no look: each element names what it is in\n\t * `data-widget-part` (`stats.card card`, …), density rides on\n\t * `data-density`, and the default widget stylesheet draws them\n\t * (STYLE-GUIDE §6.16).\n\t */\n\timport { statsView } from \"@serene-pub/core-catalog/session-state\"\n\timport { useWidgetContext } from \"../shared/context\"\n\timport SlotControl from \"../state/SlotControl.svelte\"\n\timport { createSlotWriter } from \"../state/slotWriter.svelte\"\n\timport { createEntryFinder } from \"../state/entryFinder\"\n\n\tconst widget = useWidgetContext()\n\tconst writer = createSlotWriter(widget)\n\tconst t = (source: string) => widget?.current.t(source) ?? source\n\t// A list's lorebook picker (phase 3c) searches through `session-entries`.\n\tconst findEntries = createEntryFinder(widget, t)\n\n\tlet section = $derived(widget?.current.session_state?.v1)\n\tlet settings = $derived((widget?.current.settings.v1 ?? {}) as Record<string, unknown>)\n\t// Not granted `session:state` (a plugin's copy an admin was not asked to,\n\t// or refused): the section will never come — said, not waited for.\n\tlet view = $derived(statsView(section, settings, widget?.current.grants?.includes(\"session:state\")))\n</script>\n\n<div data-widget-part=\"stats.root\" data-state-widget=\"stats\">\n\t{#if section?.error}\n\t\t<p data-widget-part=\"stats.alert\" role=\"alert\">{section.error}</p>\n\t{/if}\n\t{#if writer.error}\n\t\t<p data-widget-part=\"stats.alert\" role=\"alert\">{writer.error}</p>\n\t{/if}\n\n\t{#if view.status === \"not-granted\"}\n\t\t<div data-widget-part=\"stats.empty empty\" role=\"status\" data-scope-not-granted=\"session:state\">\n\t\t\t<sp-icon name=\"lock\" size=\"20\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{t(\"This widget has not been granted the session's stats. An administrator can grant it in the extension's permissions.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else if view.status === \"loading\"}\n\t\t<div data-widget-part=\"stats.empty empty\" role=\"status\">\n\t\t\t<sp-icon name=\"heart-pulse\" size=\"20\"></sp-icon>\n\t\t\t<span>{t(\"Loading the cast's stats…\")}</span>\n\t\t</div>\n\t{:else if view.status === \"failed\"}\n\t\t<!-- The first read was refused: the alert above is the whole story. -->\n\t{:else if view.status === \"none-declared\"}\n\t\t<div data-widget-part=\"stats.empty empty\">\n\t\t\t<sp-icon name=\"heart-pulse\" size=\"20\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{t(\n\t\t\t\t\t\"Nothing in this session declares stats. A genre, an extension or an administrator adds them, and they show up here.\"\n\t\t\t\t)}\n\t\t\t</span>\n\t\t</div>\n\t{:else if view.status === \"no-members\"}\n\t\t<div data-widget-part=\"stats.empty empty\">\n\t\t\t<sp-icon name=\"heart-pulse\" size=\"20\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{view.members === \"pick\"\n\t\t\t\t\t? t(\"No cast member matches the names in this widget's settings.\")\n\t\t\t\t\t: t(\n\t\t\t\t\t\t\t\"No one in the cast has a stat in play yet. Set one on a cast member's page, or let the story change one.\"\n\t\t\t\t\t\t)}\n\t\t\t</span>\n\t\t</div>\n\t{:else}\n\t\t{@const density = view.density}\n\t\t{#each view.members as member (member.owner.key)}\n\t\t\t<section data-widget-part=\"stats.card card\" data-owner-key={member.owner.key} aria-label={member.owner.label}>\n\t\t\t\t<header data-widget-part=\"stats.card-head card-head\">\n\t\t\t\t\t<sp-icon name=\"user-round\" size=\"13\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"stats.card-name\">{member.owner.label}</span>\n\t\t\t\t</header>\n\t\t\t\t{#if !member.slots.length}\n\t\t\t\t\t<p data-widget-part=\"stats.card-note\">{t(\"No stats to show for this member.\")}</p>\n\t\t\t\t{:else}\n\t\t\t\t\t<div data-widget-part=\"stats.card-body list\" data-density={density}>\n\t\t\t\t\t\t{#each member.slots as shown (shown.slot.slotId)}\n\t\t\t\t\t\t\t<SlotControl\n\t\t\t\t\t\t\t\tslot={shown.slot}\n\t\t\t\t\t\t\t\t{density}\n\t\t\t\t\t\t\t\tconfig={shown.config}\n\t\t\t\t\t\t\t\tvalue={shown.value}\n\t\t\t\t\t\t\t\t{t}\n\t\t\t\t\t\t\t\t{findEntries}\n\t\t\t\t\t\t\t\tonset={(next) => void writer.set(member.owner, shown.slot.slotId, next)}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t</section>\n\t\t{/each}\n\t{/if}\n</div>\n","sessions/stats/stats.ts":"/**\n * Core's `stats` component (R21): one card per cast member, one row per stat\n * they carry, as the page's UI worker runs it. `npm run build` compiles it\n * with the CLI's component bundler to `dist/components/stats.js`, the module\n * the app serves at `/core-ui/stats`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport Stats from './Stats.svelte'\n\nexport default svelteComponent(Stats)\n"},"sourceHash":"1d0e8294d23c3890ca3c2ca106c33e284f11c3d008c094568830ba68c0c20ea0","catalogVersion":"0.6.0-pr-2"}
|
|
1
|
+
{"slug":"stats","framework":"svelte","entry":"shared/stats/stats.ts","files":{"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/state/SlotControl.svelte":"<script lang=\"ts\">\n\t/**\n\t * One attribute slot, drawn as what it is and edited in place — shared by\n\t * core's World State and Stats widgets (R21).\n\t *\n\t * The slot's STAT SHAPE decides the control (`slotKind`: its field, or its\n\t * type when the host predates shapes), and the configuration in force\n\t * decides its bounds: a bounded number is a bar, a choice is a chip over a\n\t * closed set (an `sp-menu` on the chip), a list opens to its items — add,\n\t * remove, move up and down — a story time is read through the calendar\n\t * and opens to its year, month, day and time, text is a line, a boolean is\n\t * a toggle. A derived slot is computed on every read and a retired one\n\t * takes nothing new, so both are shown greyed and never offered.\n\t *\n\t * Every edit here is the USER's, which is the one writer with authority: it\n\t * applies at once (`set-attribute-value`) rather than waiting at the review\n\t * gate. Nothing is applied optimistically — the new value arrives as a\n\t * `session_state` push, so what is drawn a beat later is the resolver's\n\t * answer and not this component's guess. A list is written whole, its\n\t * items in order.\n\t *\n\t * A number or text field commits on Enter, and Escape puts the stored\n\t * value back (R80: the field's `keys`). Leaving the field commits what was\n\t * typed, and only closes it when nothing was — never a write of the value\n\t * already stored. A text field also commits on `change`; a number field\n\t * does not, because the browser raises `change` on every spinner step and\n\t * a person may step several times before they are done. A list's new item\n\t * is added on Enter; a story time is saved on Enter or its Save button —\n\t * it has four fields, so leaving one of them is not being done.\n\t *\n\t * A list that takes lore references (one not closed over words) also\n\t * picks from the session's lorebook (phase 3c): item entries first, then\n\t * the rest of the book, with how many to add — Enter in the count field\n\t * adds, Escape closes the picker. A held reference reads \"Name ×N\" and\n\t * steps up and down; one fewer than one takes it out.\n\t *\n\t * The markup carries no look. A shared control owns its parts under its own\n\t * name, so every element here is `stat-slot.<part>` in `data-widget-part`\n\t * (with a generic part where the element truly is one): a style draws a\n\t * slot once for every widget, and scopes it to one through the widget's\n\t * root (STYLE-GUIDE §6.16). A slot's state is its own `data-*` or ARIA,\n\t * never a part: `data-density`, `data-retired`, `data-slot-shape`,\n\t * `data-empty` (nothing to show), `aria-pressed` (a switch on, a row\n\t * chosen), `role=\"alert\"` (refused).\n\t *\n\t * A widget may put something of its own at the end of the row — Stats'\n\t * **stat trail** (F2) — through `trail`; it carries that widget's parts,\n\t * not this control's.\n\t */\n\timport type { Snippet } from \"svelte\"\n\timport type { SessionStateSlotV1 } from \"@serene-pub/core-catalog/widgets\"\n\timport {\n\t\tbarView,\n\t\tenumValues,\n\t\tlistItemKeyOf,\n\t\tlistItemRef,\n\t\tlistItemText,\n\t\tlistItemsOf,\n\t\tlistMoved,\n\t\tcountDraftFor,\n\t\tlistWithAdded,\n\t\tlistWithRefAdded,\n\t\tlistWithRefStep,\n\t\tlistWithout,\n\t\tnumberDraftFor,\n\t\tpickableEntries,\n\t\tslotTakesLoreRefs,\n\t\ttype PickableEntry,\n\t\tshownValueText,\n\t\tslotIsWhole,\n\t\tslotKind,\n\t\tslotWritable,\n\t\tstoryTimeDraftOf,\n\t\tstoryTimeDraftValue,\n\t\ttextDraftValue,\n\t\ttype SlotWriteValue,\n\t\ttype StoryTimeDraft\n\t} from \"@serene-pub/core-catalog/session-state\"\n\timport type { HostKeyEventDetail } from \"@serene-pub/sdk/component\"\n\timport type { EntryFinder, EntryFinds } from \"./entryFinder\"\n\n\tinterface Props {\n\t\tslot: SessionStateSlotV1\n\t\t/** The configuration in force for this owner: bounds, options, a list's limits. */\n\t\tconfig: Record<string, unknown>\n\t\tvalue: unknown\n\t\t/** Compact drops the label into the control's own line. */\n\t\tdensity?: \"compact\" | \"full\"\n\t\t/** The widget's language. */\n\t\tt: (source: string) => string\n\t\t/** `null` clears this layer, so the read inherits again. */\n\t\tonset: (value: SlotWriteValue) => void\n\t\t/** Searches the session's lorebook for a list's picker; absent, a list adds words only. */\n\t\tfindEntries?: EntryFinder\n\t\t/** The asking widget's own end of the row (Stats' stat trail); absent, none. */\n\t\ttrail?: Snippet\n\t}\n\n\tlet { slot, config, value, density = \"full\", t, onset, findEntries, trail }: Props = $props()\n\n\t/** A menu item's value for \"not set\" — never an option's, which are `opt:`-prefixed. */\n\tconst CLEAR = \"clear\"\n\n\tlet editing = $state(false)\n\tlet numberDraft = $state<number | null>(null)\n\tlet textDraft = $state(\"\")\n\tlet itemDraft = $state(\"\")\n\tlet timeDraft = $state<StoryTimeDraft>({ year: \"\", month: \"\", day: \"\", time: \"\" })\n\t/** Why the editor's last attempt wrote nothing — a list over its limit, a time that is not one. */\n\tlet invalid = $state<string | null>(null)\n\t/** The drafts as the field opened, so leaving it untouched writes nothing. */\n\tlet numberOpened: number | null = null\n\tlet textOpened = \"\"\n\n\t// The lorebook picker, inside a list's editor.\n\tlet picking = $state(false)\n\tlet pickWords = $state(\"\")\n\tlet pickCount = $state<number | null>(1)\n\tlet pickFound = $state<EntryFinds | null>(null)\n\tlet pickChosen = $state<number | null>(null)\n\tlet pickBusy = $state(false)\n\t/** The newest search owns the list: an older answer that lands late is dropped. */\n\tlet searches = 0\n\n\tlet kind = $derived(slotKind(slot))\n\tlet bar = $derived(kind === \"number\" ? barView(value, config as { min?: number; max?: number }) : null)\n\tlet options = $derived(enumValues(config))\n\tlet items = $derived(listItemsOf(value))\n\tlet canPick = $derived(!!findEntries && slotTakesLoreRefs(config))\n\tlet offered = $derived<PickableEntry[]>(pickFound ? pickableEntries(value, pickFound.pages) : [])\n\tlet offeredItems = $derived(offered.filter((e) => e.item))\n\tlet offeredOthers = $derived(offered.filter((e) => !e.item))\n\tlet chosen = $derived(offered.find((e) => e.entryId === pickChosen) ?? null)\n\tlet writable = $derived(slotWritable(slot))\n\tlet shown = $derived(shownValueText(slot, value, t))\n\tlet notSet = $derived(t(\"not set\"))\n\tlet fieldLabel = $derived(t(\"{label} value\").replace(\"{label}\", slot.label))\n\tlet editLabel = $derived(t(\"{label}, edit\").replace(\"{label}\", slot.label))\n\tlet barEditLabel = $derived(\n\t\tbar ? t(\"{label} {value}, edit\").replace(\"{label}\", slot.label).replace(\"{value}\", bar.label) : editLabel\n\t)\n\n\tfunction open() {\n\t\tif (!writable) return\n\t\tnumberDraft = numberOpened = typeof value === \"number\" ? value : null\n\t\ttextDraft = textOpened = value === undefined || value === null ? \"\" : String(value)\n\t\titemDraft = \"\"\n\t\ttimeDraft = storyTimeDraftOf(value)\n\t\tinvalid = null\n\t\tpicking = false\n\t\tediting = true\n\t}\n\n\t/** One commit per edit: Enter and `change` may both arrive for one. */\n\tfunction commitNumber() {\n\t\tif (!editing) return\n\t\tediting = false\n\t\tconst next = numberDraftFor(numberDraft, config as { min?: number; max?: number }, slotIsWhole(slot))\n\t\tif (next !== undefined) onset(next)\n\t}\n\n\tfunction commitText() {\n\t\tif (!editing) return\n\t\tediting = false\n\t\tonset(textDraftValue(textDraft, config as { maxLength?: unknown }))\n\t}\n\n\t/** Enter commits; Escape leaves the stored value as it was. */\n\tfunction onkey(e: CustomEvent<HostKeyEventDetail>, commit: () => void) {\n\t\tif (e.detail.key === \"Enter\") commit()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n\n\t/** Leaving the field: commit what was typed, or just close it. */\n\tfunction onblur(unchanged: boolean, commit: () => void) {\n\t\tif (!editing) return\n\t\tif (unchanged) editing = false\n\t\telse commit()\n\t}\n\n\tfunction pick(e: CustomEvent<{ value: string }>) {\n\t\tconst v = e.detail.value\n\t\tif (v === CLEAR) onset(null)\n\t\telse if (v.startsWith(\"opt:\")) onset(v.slice(4))\n\t}\n\n\t// ── A list: every change writes the whole list, and the editor stays open ──\n\n\tfunction addItem() {\n\t\tconst edit = listWithAdded(value, itemDraft, config)\n\t\tif (!edit) return\n\t\tif (edit.refusal) {\n\t\t\tinvalid = edit.refusal\n\t\t\treturn\n\t\t}\n\t\tinvalid = null\n\t\titemDraft = \"\"\n\t\tonset(edit.value)\n\t}\n\n\tfunction onItemKey(e: CustomEvent<HostKeyEventDetail>) {\n\t\tif (e.detail.key === \"Enter\") addItem()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n\n\t// ── A list's lorebook picker: choose an entry, say how many, add ──\n\n\tasync function search() {\n\t\tif (!findEntries) return\n\t\tconst mine = ++searches\n\t\tpickBusy = true\n\t\ttry {\n\t\t\tconst found = await findEntries(pickWords)\n\t\t\tif (mine !== searches) return\n\t\t\tpickFound = found\n\t\t\tif (pickChosen !== null && !found.pages.some((p) => p.some((r) => r.id === pickChosen))) pickChosen = null\n\t\t} catch (e) {\n\t\t\tif (mine !== searches) return\n\t\t\tpickFound = { pages: [], notice: e instanceof Error ? e.message : String(e) }\n\t\t} finally {\n\t\t\tif (mine === searches) pickBusy = false\n\t\t}\n\t}\n\n\tfunction openPicker() {\n\t\tpicking = true\n\t\tpickWords = \"\"\n\t\tpickCount = 1\n\t\tpickChosen = null\n\t\tpickFound = null\n\t\tinvalid = null\n\t\tvoid search()\n\t}\n\n\tfunction closePicker() {\n\t\tpicking = false\n\t\tpickChosen = null\n\t}\n\n\tfunction addPicked() {\n\t\tif (!chosen) {\n\t\t\tinvalid = t(\"Choose an entry to add first.\")\n\t\t\treturn\n\t\t}\n\t\tconst count = countDraftFor(pickCount)\n\t\tif (count === undefined) {\n\t\t\tinvalid = t(\"How many is a whole number, 1 or more.\")\n\t\t\treturn\n\t\t}\n\t\tconst edit = listWithRefAdded(value, chosen.entryId, count, config)\n\t\tif (edit.refusal) {\n\t\t\tinvalid = edit.refusal\n\t\t\treturn\n\t\t}\n\t\tinvalid = null\n\t\tpickCount = 1\n\t\tonset(edit.value)\n\t}\n\n\tfunction onPickKey(e: CustomEvent<HostKeyEventDetail>, enter: () => void) {\n\t\tif (e.detail.key === \"Enter\") enter()\n\t\telse if (e.detail.key === \"Escape\") closePicker()\n\t}\n\n\t// ── A story time: four fields, saved together ──\n\n\tfunction commitTime() {\n\t\tif (!editing) return\n\t\tconst next = storyTimeDraftValue(timeDraft)\n\t\tif (next === undefined) {\n\t\t\tinvalid = t(\"That is not a story time: a year, then a month, a day and a time as hh:mm — each optional, a day only with a month.\")\n\t\t\treturn\n\t\t}\n\t\tediting = false\n\t\tinvalid = null\n\t\tonset(next)\n\t}\n\n\tfunction onTimeKey(e: CustomEvent<HostKeyEventDetail>) {\n\t\tif (e.detail.key === \"Enter\") commitTime()\n\t\telse if (e.detail.key === \"Escape\") editing = false\n\t}\n</script>\n\n<div\n\tdata-widget-part=\"stat-slot.root row\"\n\tdata-density={density}\n\tdata-slot-id={slot.slotId}\n\tdata-slot-type={slot.type}\n\tdata-slot-shape={kind}\n\tdata-retired={slot.retired ? \"\" : undefined}\n>\n\t<span data-widget-part=\"stat-slot.label label\" title={slot.description ?? slot.label}>\n\t\t{slot.label}\n\t\t{#if slot.required}\n\t\t\t<span data-widget-part=\"stat-slot.required\" role=\"img\" aria-label={t(\"required\")} title={t(\"required\")}>*</span>\n\t\t{/if}\n\t\t{#if slot.retired}\n\t\t\t<sp-icon name=\"archive\" size=\"10\" label={t(\"retired\")}></sp-icon>\n\t\t{:else if kind === \"derived\"}\n\t\t\t<sp-icon name=\"sigma\" size=\"10\"></sp-icon>\n\t\t{/if}\n\t</span>\n\n\t<div data-widget-part=\"stat-slot.control\">\n\t\t{#if kind === \"boolean\" && writable}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\taria-pressed={value === true}\n\t\t\t\tonclick={() => onset(value === true ? false : true)}\n\t\t\t>\n\t\t\t\t{value === undefined ? notSet : shown}\n\t\t\t</button>\n\t\t{:else if editing && kind === \"number\"}\n\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t<input\n\t\t\t\tdata-widget-part=\"stat-slot.field\"\n\t\t\t\ttype=\"number\"\n\t\t\t\taria-label={fieldLabel}\n\t\t\t\tmin={(config as { min?: number }).min}\n\t\t\t\tmax={(config as { max?: number }).max}\n\t\t\t\tstep={slotIsWhole(slot) ? \"1\" : \"any\"}\n\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\tautofocus\n\t\t\t\tbind:value={numberDraft}\n\t\t\t\tonblur={() => onblur(numberDraft === numberOpened, commitNumber)}\n\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onkey(e, commitNumber)}\n\t\t\t/>\n\t\t{:else if editing && kind === \"list\"}\n\t\t\t<div data-widget-part=\"stat-slot.editor\" role=\"group\" aria-label={fieldLabel}>\n\t\t\t\t{#if items.length}\n\t\t\t\t\t<ol data-widget-part=\"stat-slot.items list\">\n\t\t\t\t\t\t{#each items as item, i (listItemKeyOf(item, i))}\n\t\t\t\t\t\t\t{@const itemText = listItemText(item, t)}\n\t\t\t\t\t\t\t{@const ref = listItemRef(item)}\n\t\t\t\t\t\t\t<li data-widget-part=\"stat-slot.item row\" data-item-index={i}>\n\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.item-text label\">{itemText}</span>\n\t\t\t\t\t\t\t\t{#if ref}\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-less\"\n\t\t\t\t\t\t\t\t\t\taria-label={t(\"One fewer {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithRefStep(value, ref.entryId, -1))}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"minus\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-more\"\n\t\t\t\t\t\t\t\t\t\taria-label={t(\"One more {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithRefStep(value, ref.entryId, 1))}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"plus\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-up\"\n\t\t\t\t\t\t\t\t\tdisabled={i === 0}\n\t\t\t\t\t\t\t\t\taria-label={t(\"Move {item} up\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listMoved(value, i, -1))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"arrow-up\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-down\"\n\t\t\t\t\t\t\t\t\tdisabled={i === items.length - 1}\n\t\t\t\t\t\t\t\t\taria-label={t(\"Move {item} down\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listMoved(value, i, 1))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"arrow-down\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.item-remove\"\n\t\t\t\t\t\t\t\t\taria-label={t(\"Remove {item}\").replace(\"{item}\", itemText)}\n\t\t\t\t\t\t\t\t\tonclick={() => onset(listWithout(value, i))}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"x\" size=\"11\"></sp-icon>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t{/each}\n\t\t\t\t\t</ol>\n\t\t\t\t{:else}\n\t\t\t\t\t<p data-widget-part=\"stat-slot.items-empty empty\">{t(\"Nothing in the list yet.\")}</p>\n\t\t\t\t{/if}\n\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.add stat-slot.field\"\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\taria-label={t(\"Add to {label}\").replace(\"{label}\", slot.label)}\n\t\t\t\t\tplaceholder={t(\"Add an item, then Enter\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tautofocus\n\t\t\t\t\tbind:value={itemDraft}\n\t\t\t\t\tonkey={onItemKey}\n\t\t\t\t/>\n\t\t\t\t{#if canPick && !picking}\n\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-open\" onclick={openPicker}>\n\t\t\t\t\t\t<sp-icon name=\"book-open\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t<span>{t(\"Add from the lorebook\")}</span>\n\t\t\t\t\t</button>\n\t\t\t\t{:else if canPick}\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-widget-part=\"stat-slot.picker\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={t(\"Add to {label} from the lorebook\").replace(\"{label}\", slot.label)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-search stat-slot.field\"\n\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\taria-label={t(\"Search the lorebook\")}\n\t\t\t\t\t\t\tplaceholder={t(\"Search by name or key, then Enter\")}\n\t\t\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\t\t\tautofocus\n\t\t\t\t\t\t\tbind:value={pickWords}\n\t\t\t\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onPickKey(e, () => void search())}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{#if !pickFound}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Searching the lorebook…\")}</p>\n\t\t\t\t\t\t{:else if pickFound.notice}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{pickFound.notice}</p>\n\t\t\t\t\t\t{:else if !offered.length}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Nothing in the lorebook matches.\")}</p>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t{#each [{ heading: t(\"Items\"), rows: offeredItems, group: \"items\" }, { heading: t(\"Other entries\"), rows: offeredOthers, group: \"others\" }] as part (part.group)}\n\t\t\t\t\t\t\t\t{#if part.rows.length}\n\t\t\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-heading\">{part.heading}</p>\n\t\t\t\t\t\t\t\t\t<ul data-widget-part=\"stat-slot.pick-list list\" aria-label={part.heading} data-pick-group={part.group}>\n\t\t\t\t\t\t\t\t\t\t{#each part.rows as entry (entry.entryId)}\n\t\t\t\t\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-entry row\"\n\t\t\t\t\t\t\t\t\t\t\t\t\tdata-entry-id={entry.entryId}\n\t\t\t\t\t\t\t\t\t\t\t\t\taria-pressed={pickChosen === entry.entryId}\n\t\t\t\t\t\t\t\t\t\t\t\t\tonclick={() => (pickChosen = pickChosen === entry.entryId ? null : entry.entryId)}\n\t\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.pick-title label\">{entry.title}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{#if entry.held}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span data-widget-part=\"stat-slot.pick-held\">{t(\"held ×{n}\").replace(\"{n}\", String(entry.held))}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if pickBusy && pickFound}\n\t\t\t\t\t\t\t<p data-widget-part=\"stat-slot.pick-status\" role=\"status\">{t(\"Searching the lorebook…\")}</p>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<div data-widget-part=\"stat-slot.pick-add toolbar\">\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\tdata-widget-part=\"stat-slot.pick-count stat-slot.field\"\n\t\t\t\t\t\t\t\ttype=\"number\"\n\t\t\t\t\t\t\t\tmin=\"1\"\n\t\t\t\t\t\t\t\tstep=\"1\"\n\t\t\t\t\t\t\t\taria-label={chosen ? t(\"How many {item} to add\").replace(\"{item}\", chosen.title) : t(\"How many to add\")}\n\t\t\t\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\t\t\t\tbind:value={pickCount}\n\t\t\t\t\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onPickKey(e, addPicked)}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-confirm\" disabled={!chosen} onclick={addPicked}>\n\t\t\t\t\t\t\t\t{chosen ? t(\"Add {item}\").replace(\"{item}\", chosen.title) : t(\"Add\")}\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.pick-close\" onclick={closePicker}>{t(\"Close\")}</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{/if}\n\t\t\t\t{#if invalid}<p data-widget-part=\"stat-slot.invalid\" role=\"alert\">{invalid}</p>{/if}\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.done\" onclick={() => (editing = false)}>{t(\"Done\")}</button>\n\t\t\t</div>\n\t\t{:else if editing && kind === \"story-time\"}\n\t\t\t<div data-widget-part=\"stat-slot.editor\" role=\"group\" aria-label={fieldLabel}>\n\t\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.year stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Year\")}\n\t\t\t\t\tplaceholder={t(\"Year\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tautofocus\n\t\t\t\t\tbind:value={timeDraft.year}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.month stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tmin=\"1\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Month\")}\n\t\t\t\t\tplaceholder={t(\"Month\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.month}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.day stat-slot.field\"\n\t\t\t\t\ttype=\"number\"\n\t\t\t\t\tmin=\"1\"\n\t\t\t\t\tstep=\"1\"\n\t\t\t\t\taria-label={t(\"Day\")}\n\t\t\t\t\tplaceholder={t(\"Day\")}\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.day}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\tdata-widget-part=\"stat-slot.clock stat-slot.field\"\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\taria-label={t(\"Time of day\")}\n\t\t\t\t\tplaceholder=\"hh:mm\"\n\t\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\t\tbind:value={timeDraft.time}\n\t\t\t\t\tonkey={onTimeKey}\n\t\t\t\t/>\n\t\t\t\t{#if invalid}<p data-widget-part=\"stat-slot.invalid\" role=\"alert\">{invalid}</p>{/if}\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.save\" onclick={commitTime}>{t(\"Save\")}</button>\n\t\t\t\t<button type=\"button\" data-widget-part=\"stat-slot.cancel\" onclick={() => (editing = false)}>{t(\"Cancel\")}</button>\n\t\t\t</div>\n\t\t{:else if editing}\n\t\t\t<!-- svelte-ignore a11y_autofocus -->\n\t\t\t<input\n\t\t\t\tdata-widget-part=\"stat-slot.field\"\n\t\t\t\ttype=\"text\"\n\t\t\t\taria-label={fieldLabel}\n\t\t\t\tkeys=\"Escape Enter\"\n\t\t\t\tautofocus\n\t\t\t\tbind:value={textDraft}\n\t\t\t\tonchange={commitText}\n\t\t\t\tonblur={() => onblur(textDraft === textOpened, commitText)}\n\t\t\t\tonkey={(e: CustomEvent<HostKeyEventDetail>) => onkey(e, commitText)}\n\t\t\t/>\n\t\t{:else if bar}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.bar\"\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={barEditLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t<span data-widget-part=\"stat-slot.track meter\">\n\t\t\t\t\t<span data-widget-part=\"stat-slot.fill\" style:--sp-fill=\"{bar.percent}%\"></span>\n\t\t\t\t</span>\n\t\t\t\t<span data-widget-part=\"stat-slot.bar-value value\">{bar.label}</span>\n\t\t\t</button>\n\t\t{:else if kind === \"choice\" && writable}\n\t\t\t<!-- The chip opens the closed set; picking one writes it. -->\n\t\t\t<sp-menu label={fieldLabel} onselect={pick}>\n\t\t\t\t<button\n\t\t\t\t\tslot=\"trigger\"\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\t\tdata-empty={value == null ? \"\" : undefined}\n\t\t\t\t\taria-label={editLabel}\n\t\t\t\t>\n\t\t\t\t\t{shown || notSet}\n\t\t\t\t</button>\n\t\t\t\t<sp-menu-item value={CLEAR} data-widget-part=\"stat-slot.option\" data-empty=\"\">{notSet}</sp-menu-item>\n\t\t\t\t{#each options as option (option)}\n\t\t\t\t\t<sp-menu-item value=\"opt:{option}\" data-widget-part=\"stat-slot.option\">\n\t\t\t\t\t\t{#if value === option}<sp-icon name=\"check\" size=\"12\" label={t(\"current\")}></sp-icon>{/if}\n\t\t\t\t\t\t<span>{option}</span>\n\t\t\t\t\t</sp-menu-item>\n\t\t\t\t{/each}\n\t\t\t</sp-menu>\n\t\t{:else if kind === \"choice\"}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.chip chip\"\n\t\t\t\tdata-empty={value == null ? \"\" : undefined}\n\t\t\t\tdisabled\n\t\t\t\taria-label={editLabel}\n\t\t\t>\n\t\t\t\t{shown || notSet}\n\t\t\t</button>\n\t\t{:else if kind === \"list\"}\n\t\t\t<!-- A list reads as its items; opening it edits them. -->\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.line value\"\n\t\t\t\tdata-empty={items.length ? undefined : \"\"}\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={editLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t{items.length ? shown : value === undefined ? notSet : t(\"none\")}\n\t\t\t</button>\n\t\t{:else}\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"stat-slot.line value\"\n\t\t\t\tdata-empty={value === undefined ? \"\" : undefined}\n\t\t\t\tdisabled={!writable}\n\t\t\t\taria-label={editLabel}\n\t\t\t\tonclick={open}\n\t\t\t>\n\t\t\t\t{shown || notSet}\n\t\t\t</button>\n\t\t{/if}\n\t</div>\n\t{@render trail?.()}\n</div>\n","shared/state/entryFinder.ts":"/**\n * 🚧 A state widget's lorebook search for a list's picker (attributes phase\n * 3c): the session's book through `session-entries`, item entries asked for\n * first (`typeIds`), then the rest of the book — two pages the picker merges\n * (`pickableEntries`), so the items lead even in a book too big for one page.\n *\n * A session that reads no lorebook, and a viewer who does not own the book,\n * are told so in words (`notice`) rather than shown an empty list that reads\n * as \"nothing to pick\". A declined request rejects, and the picker says why.\n */\nimport type { WidgetContextRef } from \"@serene-pub/core-catalog/widgets\"\nimport { ITEM_ENTRY_TYPE_ID } from \"@serene-pub/core-catalog/session-state\"\n\n/** One row the picker can offer, as `session-entries` answered it. */\nexport interface FoundEntry {\n\tid: number\n\ttypeId: string\n\ttitle: string\n}\n\n/** What one search found: the item page, then the book's page; or why there is nothing. */\nexport interface EntryFinds {\n\tpages: FoundEntry[][]\n\tnotice: string | null\n}\n\n/** Search the session's lorebook by title or key; blank is the whole book. */\nexport type EntryFinder = (titleOrKey: string) => Promise<EntryFinds>\n\n/** How many of each the picker shows before the search has to narrow it. */\nconst PAGE = 25\n\nexport function createEntryFinder(\n\twidget: WidgetContextRef | undefined,\n\tt: (source: string) => string\n): EntryFinder | undefined {\n\tif (!widget) return undefined\n\treturn async (titleOrKey) => {\n\t\tconst words = titleOrKey.trim()\n\t\tconst ask = (typeIds?: string[]) =>\n\t\t\twidget.current.request(\"session-entries\", {\n\t\t\t\t...(words ? { titleOrKey: words } : {}),\n\t\t\t\tsort: \"name\",\n\t\t\t\t...(typeIds ? { typeIds } : {}),\n\t\t\t\tlimit: PAGE\n\t\t\t})\n\t\tconst items = await ask([ITEM_ENTRY_TYPE_ID])\n\t\tif (items.lorebookId == null) return { pages: [], notice: t(\"This session reads no lorebook, so there is nothing to pick from.\") }\n\t\tif (items.ownerOnly)\n\t\t\treturn { pages: [], notice: t(\"Only the lorebook's owner can pick from it. Type the item's name instead.\") }\n\t\tconst rest = await ask()\n\t\tconst rows = (page: { rows: FoundEntry[] }) => page.rows.map(({ id, typeId, title }) => ({ id, typeId, title }))\n\t\treturn { pages: [rows(items), rows(rest)], notice: null }\n\t}\n}\n","shared/state/slotWriter.svelte.ts":"/**\n * A state widget's writes (R21): `set-attribute-value` through the widget's\n * own context, and the widget's OWN error line (R77) — a write that fails is\n * said in the widget that asked, never in every state widget on the page.\n *\n * The newest write owns the line: asking again clears it, and a refusal of\n * an older write that lands after a newer one was asked says nothing.\n */\nimport type { SessionStateOwnerV1, WidgetContextRef } from \"@serene-pub/core-catalog/widgets\"\nimport type { SlotWriteValue } from \"@serene-pub/core-catalog/session-state\"\n\nexport interface SlotWriter {\n\t/** Why the newest write failed, in words; null when it did not (or has not answered). */\n\treadonly error: string | null\n\tset(owner: SessionStateOwnerV1, slotId: string, value: SlotWriteValue): Promise<void>\n}\n\nexport function createSlotWriter(widget: WidgetContextRef | undefined): SlotWriter {\n\tlet error = $state<string | null>(null)\n\tlet asked = 0\n\treturn {\n\t\tget error() {\n\t\t\treturn error\n\t\t},\n\t\tasync set(owner, slotId, value) {\n\t\t\tconst mine = ++asked\n\t\t\terror = null\n\t\t\tif (!widget) return\n\t\t\ttry {\n\t\t\t\tawait widget.current.request(\"set-attribute-value\", {\n\t\t\t\t\towner: { kind: owner.kind, id: owner.id },\n\t\t\t\t\tslotId,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t} catch (e) {\n\t\t\t\tif (mine === asked) error = e instanceof Error ? e.message : String(e)\n\t\t\t}\n\t\t}\n\t}\n}\n","shared/stats/Stats.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's Stats widget as a remote component (R21): 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 StatsWidget from \"./StatsWidget.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: \"stats\", instanceId: \"stats\", title: \"Stats\" }\n\t\t)\n\t)\n</script>\n\n<StatsWidget />\n","shared/stats/StatsWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * The Stats widget: the session's stats for every owner that holds them —\n\t * the world, the cast, the places — as cards, a list or a strip (R21; W7).\n\t *\n\t * Values come from the session's one resolved read (the `session_state`\n\t * section), so this widget never resolves anything itself — which layer a\n\t * number came from is a question for the owner's page, not for the\n\t * playing surface. What it does own is the drawing: a bounded integer is a\n\t * bar, an enum a chip, text a line, a boolean a toggle, and a derived or\n\t * retired slot is greyed because there is nothing to write. Whose stats,\n\t * which ones and how they are laid out are its settings (`owners`,\n\t * `castScope`, `slots`, `arrangement`, `density`; `statsView`).\n\t *\n\t * A cards arrangement draws a card per owner. A list or a strip is World\n\t * State's drawing, moved here: the world's own slots bare, then each\n\t * other owner as a line — its name, then its slots. `owners: all` heads\n\t * each kind (world → cast → places) with a group.\n\t *\n\t * World State is this widget now (an alias, W7): its ⏳ module wraps this\n\t * one with the settings it implies and its own name, which rides on\n\t * `data-state-widget`.\n\t *\n\t * A genre that declares no slots gets an empty state that says so rather\n\t * than a card of blanks — a newcomer in a chat session never sees a bar.\n\t * Writes `set-attribute-value`, whose refusal is this widget's own line\n\t * (R77).\n\t *\n\t * 🚧 With `trail` (the default), a button at the end of each stat's row\n\t * opens its **stat trail** in a popover (F2): the changes this session\n\t * made to it, newest first — what it was, what it became, who changed it\n\t * and when — asked by `stat-trail` when opened. Anyone may read it; a\n\t * derived stat has none, so it gets no button.\n\t *\n\t * The markup carries no look: each element names what it is in\n\t * `data-widget-part` (`stats.card card`, `stats.strip`, …), the\n\t * arrangement rides on `data-arrangement` and density on `data-density`,\n\t * and the default widget stylesheet draws them (STYLE-GUIDE §6.16).\n\t */\n\timport type { SessionStateOwnerV1, SessionStateSlotV1 } from \"@serene-pub/core-catalog/widgets\"\n\timport {\n\t\tstatsSettingsOf,\n\t\tstatsView,\n\t\tstatTrailByText,\n\t\tstatTrailRows,\n\t\ttype SlotWriteValue,\n\t\ttype StatsOwnerGroup,\n\t\ttype StatsShownOwner,\n\t\ttype StatTrailRow\n\t} from \"@serene-pub/core-catalog/session-state\"\n\timport { useWidgetContext } from \"../context\"\n\timport SlotControl from \"../state/SlotControl.svelte\"\n\timport { createSlotWriter } from \"../state/slotWriter.svelte\"\n\timport { createEntryFinder } from \"../state/entryFinder\"\n\n\tlet {\n\t\timplied = {}\n\t}: {\n\t\t/**\n\t\t * Settings an alias implies, laid UNDER the host's (World State's\n\t\t * wrapper: `owners: world`, `arrangement: strip`).\n\t\t */\n\t\timplied?: Record<string, unknown>\n\t} = $props()\n\n\tconst widget = useWidgetContext()\n\tconst writer = createSlotWriter(widget)\n\tconst t = (source: string) => widget?.current.t(source) ?? source\n\t// A list's lorebook picker (phase 3c) searches through `session-entries`.\n\tconst findEntries = createEntryFinder(widget, t)\n\n\tlet section = $derived(widget?.current.scope(\"session:state\"))\n\tlet settings = $derived.by(() => {\n\t\tconst raw = widget?.current.settings.v1 ?? {}\n\t\t// ⏳ A key written the old way overrides what the alias implies for its\n\t\t// new one: World State's stored `layout: list` is the arrangement, not\n\t\t// the implied strip (`statsSettingsOf` reads it).\n\t\tconst under = { ...implied }\n\t\tif (raw.layout !== undefined) delete under.arrangement\n\t\treturn { ...under, ...raw }\n\t})\n\t// Not granted `session:state` (a plugin's copy an admin was not asked to,\n\t// or refused): the section will never come — said, not waited for.\n\tlet view = $derived(statsView(section, settings, widget?.current.grants?.includes(\"session:state\")))\n\t/** The widget's own name — `stats`, or `world-state` through its wrapper. */\n\tlet identity = $derived(widget?.current.widget?.id ?? \"stats\")\n\tlet worldOnly = $derived(view.owners === \"world\")\n\t/** A strip is one line across the top: its slots read compact. */\n\tlet slotDensity = $derived<\"compact\" | \"full\">(view.arrangement === \"strip\" ? \"compact\" : view.density)\n\t// The world is `Globe` (NOMENCLATURE §22: the world door), never the\n\t// narrator's `CloudSun`, which World State had borrowed.\n\tlet emptyIcon = $derived(worldOnly ? \"globe\" : \"heart-pulse\")\n\tlet emptyIconSize = $derived(view.arrangement === \"cards\" ? \"20\" : \"16\")\n\n\t// A kind's head: the world's door, the characters', the places' lens (§22).\n\tconst GROUP_ICON: Record<StatsOwnerGroup, string> = { world: \"globe\", cast: \"users-round\", places: \"map\" }\n\tconst OWNER_ICON: Record<StatsOwnerGroup, string> = { world: \"globe\", cast: \"user-round\", places: \"map-pin\" }\n\tconst groupLabel = (kind: StatsOwnerGroup) =>\n\t\tkind === \"world\" ? t(\"World\") : kind === \"cast\" ? t(\"Cast\") : t(\"Places\")\n\n\t/** What `nothing-shown` says, by whose stats the widget draws. */\n\tfunction nothingShown(): string {\n\t\tswitch (view.owners) {\n\t\t\tcase \"world\":\n\t\t\t\treturn t(\"This session's world declares no stats to show here.\")\n\t\t\tcase \"places\":\n\t\t\t\treturn t(\"No place has a stat in play yet.\")\n\t\t\tcase \"all\":\n\t\t\t\treturn t(\"Nothing in this session has a stat in play yet.\")\n\t\t\tcase \"pick\":\n\t\t\t\treturn t(\"Nothing in this session matches the names in this widget's settings.\")\n\t\t\tdefault:\n\t\t\t\treturn t(\n\t\t\t\t\t\"No one in the cast has a stat in play yet. Set one on a cast member's page, or let the story change one.\"\n\t\t\t\t)\n\t\t}\n\t}\n\n\tconst write = (owner: SessionStateOwnerV1, slotId: string) => (next: SlotWriteValue) =>\n\t\tvoid writer.set(owner, slotId, next)\n\n\t/* ── the stat trail (F2) ───────────────────────────────────────────── */\n\n\t/** How many changes one trail asks for. */\n\tconst TRAIL_LIMIT = 20\n\tlet offersTrail = $derived(statsSettingsOf(settings).trail)\n\t/** Whose trail is open: `<owner key>|<slot id>`; null for none. */\n\tlet trailFor = $state<string | null>(null)\n\t/** The open trail as it stands: asked, answered, or refused (said in the popover, R77). */\n\tlet trail = $state<{ status: \"loading\" | \"shown\" | \"failed\"; rows: StatTrailRow[]; error: string | null }>({\n\t\tstatus: \"loading\",\n\t\trows: [],\n\t\terror: null\n\t})\n\t/** Counts asks, so an answer to one closed since is dropped. */\n\tlet trailAsked = 0\n\tconst trailKey = (owner: SessionStateOwnerV1, slotId: string) => `${owner.key}|${slotId}`\n\tconst messageOf = (e: unknown) => (e instanceof Error ? e.message : String(e ?? t(\"Something went wrong\")))\n\n\t/** Open (and ask for) one stat's trail, or close it. */\n\tasync function toggleTrail(owner: SessionStateOwnerV1, slot: SessionStateSlotV1, open: boolean) {\n\t\tconst key = trailKey(owner, slot.slotId)\n\t\tif (!open) {\n\t\t\tif (trailFor === key) trailFor = null\n\t\t\treturn\n\t\t}\n\t\ttrailFor = key\n\t\ttrail = { status: \"loading\", rows: [], error: null }\n\t\tconst asked = ++trailAsked\n\t\ttry {\n\t\t\tconst res = (await widget?.current.request(\"stat-trail\", {\n\t\t\t\towner: { kind: owner.kind, id: owner.id },\n\t\t\t\tslotId: slot.slotId,\n\t\t\t\tlimit: TRAIL_LIMIT\n\t\t\t})) as { changes?: unknown } | undefined\n\t\t\tif (asked !== trailAsked) return\n\t\t\ttrail = { status: \"shown\", rows: statTrailRows(slot, res?.changes, t), error: null }\n\t\t} catch (e) {\n\t\t\tif (asked !== trailAsked) return\n\t\t\ttrail = { status: \"failed\", rows: [], error: messageOf(e) }\n\t\t}\n\t}\n\n\tconst whenText = (at: number) =>\n\t\tat > 0 ? new Date(at).toLocaleString(undefined, { dateStyle: \"short\", timeStyle: \"short\" }) : \"\"\n</script>\n\n{#snippet trailOf(owner: SessionStateOwnerV1, slot: SessionStateSlotV1)}\n\t{@const key = trailKey(owner, slot.slotId)}\n\t<!-- `sp-popover` (§3.5): the button is the trigger, the changes the panel. -->\n\t<sp-popover\n\t\tdata-widget-part=\"stats.trail\"\n\t\tplacement=\"bottom-end\"\n\t\tlabel={t(\"Changes to {label}\").replace(\"{label}\", slot.label)}\n\t\topen={trailFor === key}\n\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) => toggleTrail(owner, slot, e.detail.open)}\n\t>\n\t\t<button\n\t\t\tslot=\"trigger\"\n\t\t\ttype=\"button\"\n\t\t\tdata-widget-part=\"stats.trail-open\"\n\t\t\taria-label={t(\"How {label} changed\").replace(\"{label}\", slot.label)}\n\t\t\ttitle={t(\"Changes\")}\n\t\t>\n\t\t\t<sp-icon name=\"history\" size=\"12\"></sp-icon>\n\t\t</button>\n\t\t<div data-widget-part=\"stats.trail-panel\">\n\t\t\t<header data-widget-part=\"stats.trail-head card-head\">\n\t\t\t\t<sp-icon name=\"history\" size=\"14\"></sp-icon>\n\t\t\t\t<span>{slot.label} · {owner.label}</span>\n\t\t\t</header>\n\t\t\t{#if trailFor === key && trail.status === \"loading\"}\n\t\t\t\t<p data-widget-part=\"stats.trail-note\" role=\"status\">{t(\"Reading the changes…\")}</p>\n\t\t\t{:else if trailFor === key && trail.status === \"failed\"}\n\t\t\t\t<p data-widget-part=\"stats.trail-note\" role=\"alert\">{trail.error}</p>\n\t\t\t{:else if trailFor === key && !trail.rows.length}\n\t\t\t\t<p data-widget-part=\"stats.trail-note empty\">{t(\"No changes in this session yet.\")}</p>\n\t\t\t{:else if trailFor === key}\n\t\t\t\t<ol data-widget-part=\"stats.trail-list list\" aria-label={t(\"Changes to {label}\").replace(\"{label}\", slot.label)}>\n\t\t\t\t\t{#each trail.rows as row (row.key)}\n\t\t\t\t\t\t<li\n\t\t\t\t\t\t\tdata-widget-part=\"stats.trail-row row\"\n\t\t\t\t\t\t\tdata-by={row.by}\n\t\t\t\t\t\t\tdata-message-id={row.messageId ?? undefined}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<span data-widget-part=\"stats.trail-value value\">\n\t\t\t\t\t\t\t\t{row.from ? `${row.from} → ${row.to}` : row.to}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span data-widget-part=\"stats.trail-by label\">\n\t\t\t\t\t\t\t\t{statTrailByText(row.by, t)}{row.at ? ` · ${whenText(row.at)}` : \"\"}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</li>\n\t\t\t\t\t{/each}\n\t\t\t\t</ol>\n\t\t\t{/if}\n\t\t</div>\n\t</sp-popover>\n{/snippet}\n\n{#snippet slotsOf(shown: StatsShownOwner, density: \"compact\" | \"full\")}\n\t{#each shown.slots as one (one.slot.slotId)}\n\t\t<SlotControl\n\t\t\tslot={one.slot}\n\t\t\t{density}\n\t\t\tconfig={one.config}\n\t\t\tvalue={one.value}\n\t\t\t{t}\n\t\t\t{findEntries}\n\t\t\tonset={write(shown.owner, one.slot.slotId)}\n\t\t>\n\t\t\t{#snippet trail()}\n\t\t\t\t{#if offersTrail && one.slot.type !== \"derived\"}\n\t\t\t\t\t{@render trailOf(shown.owner, one.slot)}\n\t\t\t\t{/if}\n\t\t\t{/snippet}\n\t\t</SlotControl>\n\t{/each}\n{/snippet}\n\n{#snippet ownerOf(shown: StatsShownOwner)}\n\t{#if view.arrangement === \"cards\"}\n\t\t<section\n\t\t\tdata-widget-part=\"stats.card card\"\n\t\t\tdata-owner-key={shown.owner.key}\n\t\t\tdata-owner-group={shown.group}\n\t\t\taria-label={shown.owner.label}\n\t\t>\n\t\t\t<header data-widget-part=\"stats.card-head card-head\">\n\t\t\t\t<sp-icon name={OWNER_ICON[shown.group]} size=\"13\"></sp-icon>\n\t\t\t\t<span data-widget-part=\"stats.card-name\">{shown.owner.label}</span>\n\t\t\t</header>\n\t\t\t{#if !shown.slots.length}\n\t\t\t\t<p data-widget-part=\"stats.card-note\">\n\t\t\t\t\t{shown.group === \"cast\" ? t(\"No stats to show for this member.\") : t(\"No stats to show here.\")}\n\t\t\t\t</p>\n\t\t\t{:else}\n\t\t\t\t<div data-widget-part=\"stats.card-body list\" data-density={view.density}>\n\t\t\t\t\t{@render slotsOf(shown, view.density)}\n\t\t\t\t</div>\n\t\t\t{/if}\n\t\t</section>\n\t{:else if shown.group === \"world\"}\n\t\t<!-- The world is the scene: its own slots need no name over them. -->\n\t\t{@render slotsOf(shown, slotDensity)}\n\t{:else}\n\t\t<section\n\t\t\tdata-widget-part=\"stats.strip\"\n\t\t\tdata-owner-key={shown.owner.key}\n\t\t\tdata-owner-group={shown.group}\n\t\t\taria-label={shown.owner.label}\n\t\t>\n\t\t\t<header data-widget-part=\"stats.strip-head\">\n\t\t\t\t<sp-icon name={OWNER_ICON[shown.group]} size=\"13\"></sp-icon>\n\t\t\t\t<span data-widget-part=\"stats.strip-name\">{shown.owner.label}</span>\n\t\t\t</header>\n\t\t\t{@render slotsOf(shown, slotDensity)}\n\t\t</section>\n\t{/if}\n{/snippet}\n\n<div\n\tdata-widget-part=\"stats.root\"\n\tdata-state-widget={identity}\n\tdata-arrangement={view.arrangement}\n\tdata-owners={view.owners}\n\tdata-owner-key={worldOnly ? \"world\" : undefined}\n>\n\t{#if section?.error}\n\t\t<p data-widget-part=\"stats.alert\" role=\"alert\">{section.error}</p>\n\t{/if}\n\t{#if writer.error}\n\t\t<p data-widget-part=\"stats.alert\" role=\"alert\">{writer.error}</p>\n\t{/if}\n\n\t{#if view.status === \"not-granted\"}\n\t\t<div data-widget-part=\"stats.empty empty\" role=\"status\" data-scope-not-granted=\"session:state\">\n\t\t\t<sp-icon name=\"lock\" size={emptyIconSize}></sp-icon>\n\t\t\t<span>\n\t\t\t\t{t(\"This widget has not been granted the session's stats. An administrator can grant it in the extension's permissions.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else if view.status === \"loading\"}\n\t\t<div data-widget-part=\"stats.empty empty\" role=\"status\">\n\t\t\t<sp-icon name={emptyIcon} size={emptyIconSize}></sp-icon>\n\t\t\t<span>\n\t\t\t\t{worldOnly\n\t\t\t\t\t? t(\"Loading the world's stats…\")\n\t\t\t\t\t: view.owners === \"cast\"\n\t\t\t\t\t\t? t(\"Loading the cast's stats…\")\n\t\t\t\t\t\t: t(\"Loading the session's stats…\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else if view.status === \"failed\"}\n\t\t<!-- The first read was refused: the alert above is the whole story. -->\n\t{:else if view.status === \"none-declared\"}\n\t\t<div data-widget-part=\"stats.empty empty\">\n\t\t\t<sp-icon name={emptyIcon} size={emptyIconSize}></sp-icon>\n\t\t\t<span>\n\t\t\t\t{worldOnly\n\t\t\t\t\t? t(\"Nothing in this session declares world stats. A genre or an extension adds them.\")\n\t\t\t\t\t: t(\n\t\t\t\t\t\t\t\"Nothing in this session declares stats. A genre, an extension or an administrator adds them, and they show up here.\"\n\t\t\t\t\t\t)}\n\t\t\t</span>\n\t\t</div>\n\t{:else if view.status === \"nothing-shown\"}\n\t\t<div data-widget-part=\"stats.empty empty\">\n\t\t\t<sp-icon name={emptyIcon} size={emptyIconSize}></sp-icon>\n\t\t\t<span>{nothingShown()}</span>\n\t\t</div>\n\t{:else if view.status === \"shown\"}\n\t\t{#each view.groups as group (group.kind)}\n\t\t\t{#if view.owners === \"all\"}\n\t\t\t\t<section data-widget-part=\"stats.group\" data-owner-group={group.kind} aria-label={groupLabel(group.kind)}>\n\t\t\t\t\t<header data-widget-part=\"stats.group-head\">\n\t\t\t\t\t\t<sp-icon name={GROUP_ICON[group.kind]} size=\"13\"></sp-icon>\n\t\t\t\t\t\t<span>{groupLabel(group.kind)}</span>\n\t\t\t\t\t</header>\n\t\t\t\t\t{#each group.owners as shown (shown.owner.key)}\n\t\t\t\t\t\t{@render ownerOf(shown)}\n\t\t\t\t\t{/each}\n\t\t\t\t</section>\n\t\t\t{:else}\n\t\t\t\t{#each group.owners as shown (shown.owner.key)}\n\t\t\t\t\t{@render ownerOf(shown)}\n\t\t\t\t{/each}\n\t\t\t{/if}\n\t\t{/each}\n\t{/if}\n</div>\n","shared/stats/stats.ts":"/**\n * Core's `stats` component (R21): the session's stats — the world's, the\n * cast's, the places' — as cards, a list or a strip (W7), as the page's UI\n * worker runs it. `npm run build` compiles it\n * with the CLI's component bundler to `dist/components/stats.js`, the module\n * the app serves at `/core-ui/stats`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport Stats from './Stats.svelte'\n\nexport default svelteComponent(Stats)\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":"7d90cf8cbd7ee81223b4855f01a21d486457f4500b9f5db2a7de24caf38ed7e2","catalogVersion":"0.6.0-pr-5"}
|