@serene-pub/core-catalog 0.6.0-pr-2 → 0.6.0-pr-4
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 → shared}/lore-entries/LoreEntries.svelte +1 -1
- package/components/{sessions → shared}/lore-entries/LoreEntriesWidget.svelte +1 -1
- package/components/{sessions → shared}/messages/MessageComposer.svelte +1 -1
- package/components/{sessions → shared}/messages/Messages.svelte +1 -1
- package/components/{sessions → shared}/messages/MessagesWidget.svelte +1 -1
- package/components/{sessions → shared}/messages/SessionComposer.svelte +1 -1
- package/components/{sessions → shared}/messages/SessionMessage.svelte +1 -1
- package/components/{sessions → shared}/messages/conversation.svelte.ts +1 -1
- package/components/{sessions → shared}/scene-portraits/ScenePortraits.svelte +1 -1
- package/components/{sessions → shared}/scene-portraits/ScenePortraitsWidget.svelte +1 -1
- package/components/{sessions → shared}/stats/Stats.svelte +1 -1
- package/components/{sessions → shared}/stats/StatsWidget.svelte +1 -1
- package/components/{sessions → shared}/world-state/WorldState.svelte +1 -1
- package/components/{sessions → shared}/world-state/WorldStateWidget.svelte +1 -1
- package/dist/components/authors-note.js +5 -5
- package/dist/components/authors-note.source.json +1 -1
- 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 +26 -26
- package/dist/components/messages.source.json +1 -1
- package/dist/components/scene-portraits.js +7 -7
- package/dist/components/scene-portraits.source.json +1 -1
- package/dist/components/{shared-TCQZXBE3.js → shared-3FGURYVS.js} +2 -2
- package/dist/components/{shared-AINANAIA.js → shared-FXYLABGF.js} +6 -6
- package/dist/components/{shared-UAQVMZZK.js → shared-U3UU5V7L.js} +3 -3
- package/dist/components/stats.js +6 -6
- package/dist/components/stats.source.json +1 -1
- package/dist/components/world-state.js +6 -6
- 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} +4 -37
- 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 +11 -0
- package/dist/genres/adventure/advanceTime.js +17 -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/index.d.ts +43 -0
- package/dist/genres/adventure/index.js +43 -0
- package/dist/genres/adventure/keeperAction.d.ts +24 -0
- package/dist/genres/adventure/keeperAction.js +150 -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} +10 -34
- package/dist/{adventure.js → genres/adventure/respond.js} +34 -60
- package/dist/genres/adventure/rest.d.ts +10 -0
- package/dist/genres/adventure/rest.js +16 -0
- package/dist/genres/adventure/turnOrder.d.ts +10 -0
- package/dist/genres/adventure/turnOrder.js +27 -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} +5 -5
- package/dist/genres/chat/index.d.ts +15 -0
- package/dist/genres/chat/index.js +15 -0
- package/dist/{narrate.d.ts → genres/chat/narrate.d.ts} +3 -3
- package/dist/{narrate.js → genres/chat/narrate.js} +34 -12
- package/dist/{narrateCharacter.d.ts → genres/chat/narrateCharacter.d.ts} +2 -2
- package/dist/{narrateCharacter.js → genres/chat/narrateCharacter.js} +35 -16
- package/dist/genres/chat/respond.d.ts +25 -0
- package/dist/{respond.js → genres/chat/respond.js} +48 -22
- 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 +9 -0
- package/dist/genres/guide/index.js +9 -0
- package/dist/{guide.d.ts → genres/guide/respond.d.ts} +1 -20
- package/dist/{guide.js → genres/guide/respond.js} +29 -60
- 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/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 +60 -0
- package/dist/genres/lair/index.js +60 -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} +15 -28
- package/dist/{lair.js → genres/lair/respond.js} +45 -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/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 +47 -29
- package/dist/index.js +117 -88
- package/dist/{genres.js → registry/genres.js} +4 -4
- package/dist/{ui/sessions → registry}/widgets.js +6 -6
- package/dist/{presets.js → seed/presets.js} +28 -13
- package/dist/{prompts.js → seed/prompts.js} +27 -56
- package/dist/{annexField.d.ts → shared/annexField.d.ts} +3 -2
- package/dist/{annexField.js → shared/annexField.js} +6 -8
- 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/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 +10 -0
- package/dist/shared/summarize/index.js +10 -0
- package/dist/shared/summarize/scene.d.ts +38 -0
- package/dist/shared/summarize/scene.js +42 -0
- package/dist/shared/summarize/summarizeSpec.d.ts +54 -0
- package/dist/{summarize.js → shared/summarize/summarizeSpec.js} +8 -53
- package/dist/shared/summarize/world.d.ts +8 -0
- package/dist/shared/summarize/world.js +9 -0
- package/dist/{toolLoop.d.ts → shared/toolLoop.d.ts} +25 -3
- package/dist/{toolLoop.js → shared/toolLoop.js} +67 -14
- package/dist/{ui/sessions → shared/ui}/conversation/index.d.ts +1 -1
- package/dist/{ui/sessions → shared/ui}/conversation/index.js +1 -1
- 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 +1 -1
- 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/{ui/sessions → shared/ui}/session-state/index.d.ts +1 -1
- package/dist/{ui/sessions → shared/ui}/session-state/index.js +1 -1
- package/package.json +28 -28
- 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/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/MessageControls.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/MessageStateLedger.svelte +0 -0
- /package/components/{sessions → shared}/messages/NextCharacterBlock.svelte +0 -0
- /package/components/{sessions → shared}/messages/SessionContainer.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/SlotControl.svelte +0 -0
- /package/components/{sessions → shared}/state/entryFinder.ts +0 -0
- /package/components/{sessions → shared}/state/slotWriter.svelte.ts +0 -0
- /package/components/{sessions → shared}/stats/stats.ts +0 -0
- /package/components/{sessions/shared → shared}/widgetRef.svelte.ts +0 -0
- /package/components/{sessions → shared}/world-state/world-state.ts +0 -0
- /package/dist/{ui/sessions → genres/chat/ui}/authors-note/index.js +0 -0
- /package/dist/{entries.d.ts → registry/entries.d.ts} +0 -0
- /package/dist/{entries.js → registry/entries.js} +0 -0
- /package/dist/{genres.d.ts → registry/genres.d.ts} +0 -0
- /package/dist/{ui/sessions → registry}/layouts.d.ts +0 -0
- /package/dist/{ui/sessions → registry}/layouts.js +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/{ui/sessions → registry}/widgets.d.ts +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/{prompts.d.ts → seed/prompts.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/dossier.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/conversation/dossier.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.d.ts +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}/scene-portraits/portraits.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/scene-portraits/portraits.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.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/session-state/shapes.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/session-state/stateView.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/session-state/stateView.js +0 -0
- /package/dist/{ui/sessions → shared/ui}/widgetContext.d.ts +0 -0
- /package/dist/{ui/sessions → shared/ui}/widgetContext.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
barView,
|
|
3
3
|
slotKind
|
|
4
|
-
} from "./shared-
|
|
4
|
+
} from "./shared-3FGURYVS.js";
|
|
5
5
|
import "./shared-RJDGOAVC.js";
|
|
6
6
|
import {
|
|
7
7
|
WIDGET_CONTEXT_KEY,
|
|
@@ -34,9 +34,9 @@ import {
|
|
|
34
34
|
useWidgetContext,
|
|
35
35
|
user_derived,
|
|
36
36
|
widgetRefFromComponent
|
|
37
|
-
} from "./shared-
|
|
37
|
+
} from "./shared-U3UU5V7L.js";
|
|
38
38
|
|
|
39
|
-
// dist/ui/
|
|
39
|
+
// dist/shared/ui/scene-portraits/portraits.js
|
|
40
40
|
var SCENE_PORTRAITS_DEFAULTS = Object.freeze({
|
|
41
41
|
source: "pinned",
|
|
42
42
|
persona: false,
|
|
@@ -124,7 +124,7 @@ function statBarsOf(state2, ownerKey, limit = 3) {
|
|
|
124
124
|
return out;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
// components/
|
|
127
|
+
// components/shared/scene-portraits/StatBars.svelte
|
|
128
128
|
var root = from_html(`<div data-widget-part="scene-portraits.bar row"><span data-widget-part="scene-portraits.bar-label label"> </span> <span data-widget-part="scene-portraits.bar-track meter"><span data-widget-part="scene-portraits.bar-fill"></span></span></div>`);
|
|
129
129
|
var root_1 = from_html(`<div data-widget-part="scene-portraits.bars list"></div>`);
|
|
130
130
|
function StatBars($$anchor, $$props) {
|
|
@@ -163,7 +163,7 @@ function StatBars($$anchor, $$props) {
|
|
|
163
163
|
pop();
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
// components/
|
|
166
|
+
// components/shared/scene-portraits/ScenePortraitsWidget.svelte
|
|
167
167
|
var root2 = from_html(`<div data-widget-part="scene-portraits.alert" role="alert"><span data-widget-part="scene-portraits.alert-text"> </span> <button type="button" data-widget-part="scene-portraits.dismiss"><sp-icon></sp-icon></button></div>`, 2);
|
|
168
168
|
var root_12 = from_html(`<div data-widget-part="scene-portraits.empty empty" role="status" data-scope-not-granted="characters"><sp-icon></sp-icon> <span> </span></div>`, 2);
|
|
169
169
|
var root_2 = from_html(`<div data-widget-part="scene-portraits.empty empty"><sp-icon></sp-icon> <span> </span></div>`, 2);
|
|
@@ -515,7 +515,7 @@ function ScenePortraitsWidget($$anchor, $$props) {
|
|
|
515
515
|
}
|
|
516
516
|
delegate(["click"]);
|
|
517
517
|
|
|
518
|
-
// components/
|
|
518
|
+
// components/shared/scene-portraits/ScenePortraits.svelte
|
|
519
519
|
function ScenePortraits($$anchor, $$props) {
|
|
520
520
|
push($$props, true);
|
|
521
521
|
setContext(WIDGET_CONTEXT_KEY, widgetRefFromComponent(untrack(() => $$props.ctx), {
|
|
@@ -527,7 +527,7 @@ function ScenePortraits($$anchor, $$props) {
|
|
|
527
527
|
pop();
|
|
528
528
|
}
|
|
529
529
|
|
|
530
|
-
// components/
|
|
530
|
+
// components/shared/scene-portraits/scene-portraits.ts
|
|
531
531
|
var scene_portraits_default = svelteComponent(ScenePortraits);
|
|
532
532
|
export {
|
|
533
533
|
scene_portraits_default as default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"slug":"scene-portraits","framework":"svelte","entry":"sessions/scene-portraits/scene-portraits.ts","files":{"sessions/scene-portraits/ScenePortraits.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's Scene Portraits widget as a remote component (R21): the\n\t * component context, as the widget context core's widgets read, around\n\t * the widget itself.\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 ScenePortraitsWidget from \"./ScenePortraitsWidget.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: \"scene-portraits\", instanceId: \"scene-portraits\", title: \"Scene Portraits\" }\n\t\t)\n\t)\n</script>\n\n<ScenePortraitsWidget />\n","sessions/scene-portraits/ScenePortraitsWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * The scene portraits: faces beside the conversation, from one of two\n\t * sources (`settings.source`).\n\t *\n\t * `pinned` is the two images a person pins from the session's avatar\n\t * gallery — the PAGE's pins, riding along on `characters.v1`\n\t * (`sceneImages`) and cleared through the page (`clear-scene-image`), so\n\t * the page and this widget never disagree about what is pinned (R77). It\n\t * is the default because pinning is the only thing a Chat session has to\n\t * show.\n\t *\n\t * `scene` is the cast itself — every character still in the session, and\n\t * the persona the viewer is voicing when `settings.persona` asks for it\n\t * (R77: the viewer's own, never merely the first listed). A genre that\n\t * docks this widget means \"who is here\", and a fresh session has pinned\n\t * nothing, so a docked portrait rail on the pinned source is an empty rail\n\t * on day one.\n\t *\n\t * Every URL and each member's current sprite are the host's (`characters`,\n\t * R76): this widget reads no log. The mini bar rows read `session_state`.\n\t *\n\t * The markup carries widget parts (`data-widget-part`), never a look: the\n\t * default widget stylesheet draws them, a style may redraw them\n\t * (STYLE-GUIDE §6.16). A face with no picture is the same part with\n\t * `data-blank`.\n\t */\n\timport type { SessionCharactersV1, SessionStateV1 } from \"@serene-pub/sdk/component\"\n\timport {\n\t\tpinnedPortraitsOf,\n\t\treadScenePortraitsSettings,\n\t\tscenePortraitsOf,\n\t\tstatBarsOf\n\t} from \"@serene-pub/core-catalog/scene-portraits\"\n\timport { scopeNotGranted } from \"@serene-pub/core-catalog/widgets\"\n\timport { useWidgetContext } from \"../shared/context\"\n\timport StatBars from \"./StatBars.svelte\"\n\n\tconst w = useWidgetContext()\n\tconst t = (source: string) => w?.current.t?.(source) ?? source\n\n\tconst settings = $derived(\n\t\treadScenePortraitsSettings(\n\t\t\tw?.current.settings?.v1 as Record<string, unknown> | undefined\n\t\t)\n\t)\n\tconst characters = $derived(\n\t\tw?.current.characters?.v1 as SessionCharactersV1 | undefined\n\t)\n\tconst sessionState = $derived(\n\t\tw?.current.session_state?.v1 as SessionStateV1 | undefined\n\t)\n\t/**\n\t * The host said this widget does not hold `characters` (a plugin's copy\n\t * not granted it): the cast will never come — said, not waited for. Its\n\t * bars read `session_state`, which is optional: without it, no bars.\n\t */\n\tconst castNotGranted = $derived(scopeNotGranted(w?.current, \"characters\"))\n\tconst fromScene = $derived(settings.source === \"scene\")\n\tconst portraits = $derived(scenePortraitsOf(characters, sessionState, settings))\n\tconst pins = $derived(pinnedPortraitsOf(characters, sessionState))\n\tconst hasAny = $derived(pins.some((p) => !!p.src))\n\n\t/**\n\t * This widget's own error (R77): a refused sprite-set switch or clear is\n\t * said here, never in another widget, and gone with the next success or\n\t * a dismiss.\n\t */\n\tlet error = $state<string | null>(null)\n\tconst messageOf = (e: unknown) =>\n\t\te instanceof Error ? e.message : String(e ?? t(\"Something went wrong\"))\n\n\t/** Which face's sprite-set menu is open, by member key. */\n\tlet menuFor = $state<string | null>(null)\n\n\t/**\n\t * The face menu's sprite-set switch: show a character in another of its\n\t * sprite sets for this session only (`null`: as the story has it). The\n\t * page asks the server, which checks the asker may and pushes the change\n\t * to every member; the menu is offered only where it will be allowed.\n\t */\n\tasync function changeSpriteSet(characterId: number, set: string | null) {\n\t\tmenuFor = null\n\t\ttry {\n\t\t\tawait w?.current.request(\"set-sprite-set\", { characterId, set })\n\t\t\terror = null\n\t\t} catch (e) {\n\t\t\terror = messageOf(e)\n\t\t}\n\t}\n\n\t/** Clear one side's pin — the page's pin, so the page's tab clears with it. */\n\tasync function clear(side: \"left\" | \"right\") {\n\t\ttry {\n\t\t\tawait w?.current.request(\"clear-scene-image\", { side })\n\t\t\terror = null\n\t\t} catch (e) {\n\t\t\terror = messageOf(e)\n\t\t}\n\t}\n</script>\n\n<div data-widget-part=\"scene-portraits.root\" data-state-widget=\"scene-portraits\">\n\t{#if error}\n\t\t<div data-widget-part=\"scene-portraits.alert\" role=\"alert\">\n\t\t\t<span data-widget-part=\"scene-portraits.alert-text\">{error}</span>\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"scene-portraits.dismiss\"\n\t\t\t\taria-label={t(\"Dismiss\")}\n\t\t\t\ttitle={t(\"Dismiss\")}\n\t\t\t\tonclick={() => (error = null)}\n\t\t\t>\n\t\t\t\t<sp-icon name=\"x\" size=\"12\"></sp-icon>\n\t\t\t</button>\n\t\t</div>\n\t{/if}\n\t{#if castNotGranted}\n\t\t<div data-widget-part=\"scene-portraits.empty empty\" role=\"status\" data-scope-not-granted=\"characters\">\n\t\t\t<sp-icon name=\"lock\" size=\"22\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{t(\"This widget has not been granted the session's cast. An administrator can grant it in the extension's permissions.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else if !characters}\n\t\t<!-- Not yet arrived: say nothing rather than \"nothing is here\". -->\n\t{:else if fromScene}\n\t\t{#if !portraits.length}\n\t\t\t<div data-widget-part=\"scene-portraits.empty empty\">\n\t\t\t\t<sp-icon name=\"users\" size=\"22\"></sp-icon>\n\t\t\t\t<span>\n\t\t\t\t\t{t(\"Nobody is in this scene yet. Add a character to the session and they show up here.\")}\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t{:else}\n\t\t\t<div data-widget-part=\"scene-portraits.scene\">\n\t\t\t\t{#each portraits as member (member.key)}\n\t\t\t\t\t<div data-widget-part=\"scene-portraits.face\" data-scene-member={member.isPersona ? `persona:${member.characterId}` : member.key}>\n\t\t\t\t\t\t{#if member.src}\n\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\tsrc={member.src}\n\t\t\t\t\t\t\t\talt={member.name}\n\t\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.face-img\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t<div data-widget-part=\"scene-portraits.face-img\" data-blank>\n\t\t\t\t\t\t\t\t<sp-icon name=\"user-round\" size=\"20\"></sp-icon>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<span data-widget-part=\"scene-portraits.face-name\">{member.name}</span>\n\t\t\t\t\t\t{#if member.offersSpriteSets}\n\t\t\t\t\t\t\t<!-- `sp-popover` (§3.5): our button is the trigger, the set panel the panel. -->\n\t\t\t\t\t\t\t<sp-popover\n\t\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.set-menu\"\n\t\t\t\t\t\t\t\tplacement=\"bottom-end\"\n\t\t\t\t\t\t\t\tlabel={t(\"Sprite set\")}\n\t\t\t\t\t\t\t\topen={menuFor === member.key}\n\t\t\t\t\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) =>\n\t\t\t\t\t\t\t\t\t(menuFor = e.detail.open ? member.key : null)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\tslot=\"trigger\"\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.set\"\n\t\t\t\t\t\t\t\t\taria-label={t(\"Change {name}'s sprite set\").replace(\"{name}\", member.name)}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"shirt\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t<span data-widget-part=\"scene-portraits.set-name\">{member.spriteSetOverride ?? t(\"Sprite set\")}</span>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t<div data-widget-part=\"scene-portraits.set-panel\">\n\t\t\t\t\t\t\t\t\t<header data-widget-part=\"scene-portraits.set-title\">\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"shirt\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t<p>{t(\"Sprite set\")}</p>\n\t\t\t\t\t\t\t\t\t</header>\n\t\t\t\t\t\t\t\t\t<div data-widget-part=\"scene-portraits.set-list\" role=\"menu\" aria-label={t(\"Sprite set\")}>\n\t\t\t\t\t\t\t\t\t\t{#each member.spriteSets as setName (setName)}\n\t\t\t\t\t\t\t\t\t\t\t<button\n\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\trole=\"menuitemradio\"\n\t\t\t\t\t\t\t\t\t\t\t\taria-checked={member.spriteSetOverride === setName}\n\t\t\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.set-option\"\n\t\t\t\t\t\t\t\t\t\t\t\tonclick={() => changeSpriteSet(member.characterId, setName)}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{setName}</span>\n\t\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\trole=\"menuitemradio\"\n\t\t\t\t\t\t\t\t\t\t\taria-checked={!member.spriteSetOverride}\n\t\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.set-option\"\n\t\t\t\t\t\t\t\t\t\t\tonclick={() => changeSpriteSet(member.characterId, null)}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t<span>{t(\"As the story has it\")}</span>\n\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t<p data-widget-part=\"scene-portraits.set-note\">\n\t\t\t\t\t\t\t\t\t\t{t(\"For this session only. An outfit, an age or a form; the lorebook's cast decides it everywhere else.\")}\n\t\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</sp-popover>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if settings.bars && member.ownerKey}\n\t\t\t\t\t\t\t<StatBars ownerKey={member.ownerKey} rows={statBarsOf(sessionState, member.ownerKey)} />\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</div>\n\t\t\t\t{/each}\n\t\t\t</div>\n\t\t{/if}\n\t{:else if !hasAny}\n\t\t<div data-widget-part=\"scene-portraits.empty empty\">\n\t\t\t<sp-icon name=\"users\" size=\"22\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{t(\"No scene portraits set. Click a character's avatar in the chat to pin one here.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else}\n\t\t<div data-widget-part=\"scene-portraits.pins\">\n\t\t\t{#each pins as pin (pin.side)}\n\t\t\t\t{@const ownerKey = settings.bars ? pin.ownerKey : null}\n\t\t\t\t<div data-widget-part=\"scene-portraits.pin\">\n\t\t\t\t\t{#if pin.src}\n\t\t\t\t\t\t<img\n\t\t\t\t\t\t\tsrc={pin.src}\n\t\t\t\t\t\t\talt={pin.side === \"left\" ? t(\"left scene portrait\") : t(\"right scene portrait\")}\n\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.pin-img\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{#if ownerKey}\n\t\t\t\t\t\t\t<StatBars {ownerKey} rows={statBarsOf(sessionState, ownerKey)} />\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.pin-clear\"\n\t\t\t\t\t\t\tonclick={() => clear(pin.side)}\n\t\t\t\t\t\t\ttitle={pin.side === \"left\" ? t(\"Clear left portrait\") : t(\"Clear right portrait\")}\n\t\t\t\t\t\t\taria-label={pin.side === \"left\" ? t(\"Clear left portrait\") : t(\"Clear right portrait\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"x\" size=\"13\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t{:else}\n\t\t\t\t\t\t<div data-widget-part=\"scene-portraits.pin-placeholder\">\n\t\t\t\t\t\t\t{t(\"Empty\")}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t{/if}\n\t\t\t\t</div>\n\t\t\t{/each}\n\t\t</div>\n\t{/if}\n</div>\n","sessions/scene-portraits/StatBars.svelte":"<script lang=\"ts\">\n\t/**\n\t * A mini bar row: one owner's bounded stats, read-only.\n\t *\n\t * Read-only on purpose. This sits under a portrait, where the pointer is\n\t * already doing something else, and a bar you can nudge by a stray click\n\t * is a stat nobody can trust. Editing lives in the Stats widget.\n\t *\n\t * Only slots whose configuration declares both ends of a range are drawn\n\t * (`statBarsOf`): everything else is not a bar, and this row has no room\n\t * to say what it is.\n\t */\n\timport type { StatBarRow } from \"@serene-pub/core-catalog/scene-portraits\"\n\n\tinterface Props {\n\t\t/** The owner key the resolved state files these values under. */\n\t\townerKey: string\n\t\trows: StatBarRow[]\n\t}\n\tlet { ownerKey, rows }: Props = $props()\n</script>\n\n{#if rows.length}\n\t<div data-widget-part=\"scene-portraits.bars list\" data-state-bars={ownerKey}>\n\t\t{#each rows as row (row.slotId)}\n\t\t\t<div\n\t\t\t\tdata-widget-part=\"scene-portraits.bar row\"\n\t\t\t\ttitle=\"{row.label} {row.bar.label}\"\n\t\t\t\taria-label=\"{row.label} {row.bar.label}\"\n\t\t\t>\n\t\t\t\t<span data-widget-part=\"scene-portraits.bar-label label\">{row.label}</span>\n\t\t\t\t<span data-widget-part=\"scene-portraits.bar-track meter\">\n\t\t\t\t\t<span\n\t\t\t\t\t\tdata-widget-part=\"scene-portraits.bar-fill\"\n\t\t\t\t\t\tstyle=\"--sp-fill: {row.bar.percent}%\"\n\t\t\t\t\t></span>\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t{/each}\n\t</div>\n{/if}\n","sessions/scene-portraits/scene-portraits.ts":"/**\n * Core's `scene-portraits` component (R21): the faces beside the\n * conversation, as the page's UI worker runs it. `npm run build` compiles it\n * with the CLI's component bundler to `dist/components/scene-portraits.js`,\n * the module the app serves at `/core-ui/scene-portraits`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport ScenePortraits from './ScenePortraits.svelte'\n\nexport default svelteComponent(ScenePortraits)\n","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"},"sourceHash":"f6b94c148fd67a7dc6cfd757a1d660df1624bbf9c0e5d7ba02d91912bbcf906a","catalogVersion":"0.6.0-pr-2"}
|
|
1
|
+
{"slug":"scene-portraits","framework":"svelte","entry":"shared/scene-portraits/scene-portraits.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/scene-portraits/ScenePortraits.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's Scene Portraits widget as a remote component (R21): the\n\t * component context, as the widget context core's widgets read, around\n\t * the widget itself.\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 ScenePortraitsWidget from \"./ScenePortraitsWidget.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: \"scene-portraits\", instanceId: \"scene-portraits\", title: \"Scene Portraits\" }\n\t\t)\n\t)\n</script>\n\n<ScenePortraitsWidget />\n","shared/scene-portraits/ScenePortraitsWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * The scene portraits: faces beside the conversation, from one of two\n\t * sources (`settings.source`).\n\t *\n\t * `pinned` is the two images a person pins from the session's avatar\n\t * gallery — the PAGE's pins, riding along on `characters.v1`\n\t * (`sceneImages`) and cleared through the page (`clear-scene-image`), so\n\t * the page and this widget never disagree about what is pinned (R77). It\n\t * is the default because pinning is the only thing a Chat session has to\n\t * show.\n\t *\n\t * `scene` is the cast itself — every character still in the session, and\n\t * the persona the viewer is voicing when `settings.persona` asks for it\n\t * (R77: the viewer's own, never merely the first listed). A genre that\n\t * docks this widget means \"who is here\", and a fresh session has pinned\n\t * nothing, so a docked portrait rail on the pinned source is an empty rail\n\t * on day one.\n\t *\n\t * Every URL and each member's current sprite are the host's (`characters`,\n\t * R76): this widget reads no log. The mini bar rows read `session_state`.\n\t *\n\t * The markup carries widget parts (`data-widget-part`), never a look: the\n\t * default widget stylesheet draws them, a style may redraw them\n\t * (STYLE-GUIDE §6.16). A face with no picture is the same part with\n\t * `data-blank`.\n\t */\n\timport type { SessionCharactersV1, SessionStateV1 } from \"@serene-pub/sdk/component\"\n\timport {\n\t\tpinnedPortraitsOf,\n\t\treadScenePortraitsSettings,\n\t\tscenePortraitsOf,\n\t\tstatBarsOf\n\t} from \"@serene-pub/core-catalog/scene-portraits\"\n\timport { scopeNotGranted } from \"@serene-pub/core-catalog/widgets\"\n\timport { useWidgetContext } from \"../context\"\n\timport StatBars from \"./StatBars.svelte\"\n\n\tconst w = useWidgetContext()\n\tconst t = (source: string) => w?.current.t?.(source) ?? source\n\n\tconst settings = $derived(\n\t\treadScenePortraitsSettings(\n\t\t\tw?.current.settings?.v1 as Record<string, unknown> | undefined\n\t\t)\n\t)\n\tconst characters = $derived(\n\t\tw?.current.characters?.v1 as SessionCharactersV1 | undefined\n\t)\n\tconst sessionState = $derived(\n\t\tw?.current.session_state?.v1 as SessionStateV1 | undefined\n\t)\n\t/**\n\t * The host said this widget does not hold `characters` (a plugin's copy\n\t * not granted it): the cast will never come — said, not waited for. Its\n\t * bars read `session_state`, which is optional: without it, no bars.\n\t */\n\tconst castNotGranted = $derived(scopeNotGranted(w?.current, \"characters\"))\n\tconst fromScene = $derived(settings.source === \"scene\")\n\tconst portraits = $derived(scenePortraitsOf(characters, sessionState, settings))\n\tconst pins = $derived(pinnedPortraitsOf(characters, sessionState))\n\tconst hasAny = $derived(pins.some((p) => !!p.src))\n\n\t/**\n\t * This widget's own error (R77): a refused sprite-set switch or clear is\n\t * said here, never in another widget, and gone with the next success or\n\t * a dismiss.\n\t */\n\tlet error = $state<string | null>(null)\n\tconst messageOf = (e: unknown) =>\n\t\te instanceof Error ? e.message : String(e ?? t(\"Something went wrong\"))\n\n\t/** Which face's sprite-set menu is open, by member key. */\n\tlet menuFor = $state<string | null>(null)\n\n\t/**\n\t * The face menu's sprite-set switch: show a character in another of its\n\t * sprite sets for this session only (`null`: as the story has it). The\n\t * page asks the server, which checks the asker may and pushes the change\n\t * to every member; the menu is offered only where it will be allowed.\n\t */\n\tasync function changeSpriteSet(characterId: number, set: string | null) {\n\t\tmenuFor = null\n\t\ttry {\n\t\t\tawait w?.current.request(\"set-sprite-set\", { characterId, set })\n\t\t\terror = null\n\t\t} catch (e) {\n\t\t\terror = messageOf(e)\n\t\t}\n\t}\n\n\t/** Clear one side's pin — the page's pin, so the page's tab clears with it. */\n\tasync function clear(side: \"left\" | \"right\") {\n\t\ttry {\n\t\t\tawait w?.current.request(\"clear-scene-image\", { side })\n\t\t\terror = null\n\t\t} catch (e) {\n\t\t\terror = messageOf(e)\n\t\t}\n\t}\n</script>\n\n<div data-widget-part=\"scene-portraits.root\" data-state-widget=\"scene-portraits\">\n\t{#if error}\n\t\t<div data-widget-part=\"scene-portraits.alert\" role=\"alert\">\n\t\t\t<span data-widget-part=\"scene-portraits.alert-text\">{error}</span>\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\tdata-widget-part=\"scene-portraits.dismiss\"\n\t\t\t\taria-label={t(\"Dismiss\")}\n\t\t\t\ttitle={t(\"Dismiss\")}\n\t\t\t\tonclick={() => (error = null)}\n\t\t\t>\n\t\t\t\t<sp-icon name=\"x\" size=\"12\"></sp-icon>\n\t\t\t</button>\n\t\t</div>\n\t{/if}\n\t{#if castNotGranted}\n\t\t<div data-widget-part=\"scene-portraits.empty empty\" role=\"status\" data-scope-not-granted=\"characters\">\n\t\t\t<sp-icon name=\"lock\" size=\"22\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{t(\"This widget has not been granted the session's cast. An administrator can grant it in the extension's permissions.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else if !characters}\n\t\t<!-- Not yet arrived: say nothing rather than \"nothing is here\". -->\n\t{:else if fromScene}\n\t\t{#if !portraits.length}\n\t\t\t<div data-widget-part=\"scene-portraits.empty empty\">\n\t\t\t\t<sp-icon name=\"users\" size=\"22\"></sp-icon>\n\t\t\t\t<span>\n\t\t\t\t\t{t(\"Nobody is in this scene yet. Add a character to the session and they show up here.\")}\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t{:else}\n\t\t\t<div data-widget-part=\"scene-portraits.scene\">\n\t\t\t\t{#each portraits as member (member.key)}\n\t\t\t\t\t<div data-widget-part=\"scene-portraits.face\" data-scene-member={member.isPersona ? `persona:${member.characterId}` : member.key}>\n\t\t\t\t\t\t{#if member.src}\n\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\tsrc={member.src}\n\t\t\t\t\t\t\t\talt={member.name}\n\t\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.face-img\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t<div data-widget-part=\"scene-portraits.face-img\" data-blank>\n\t\t\t\t\t\t\t\t<sp-icon name=\"user-round\" size=\"20\"></sp-icon>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<span data-widget-part=\"scene-portraits.face-name\">{member.name}</span>\n\t\t\t\t\t\t{#if member.offersSpriteSets}\n\t\t\t\t\t\t\t<!-- `sp-popover` (§3.5): our button is the trigger, the set panel the panel. -->\n\t\t\t\t\t\t\t<sp-popover\n\t\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.set-menu\"\n\t\t\t\t\t\t\t\tplacement=\"bottom-end\"\n\t\t\t\t\t\t\t\tlabel={t(\"Sprite set\")}\n\t\t\t\t\t\t\t\topen={menuFor === member.key}\n\t\t\t\t\t\t\t\tonopen-change={(e: CustomEvent<{ open: boolean }>) =>\n\t\t\t\t\t\t\t\t\t(menuFor = e.detail.open ? member.key : null)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\tslot=\"trigger\"\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.set\"\n\t\t\t\t\t\t\t\t\taria-label={t(\"Change {name}'s sprite set\").replace(\"{name}\", member.name)}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<sp-icon name=\"shirt\" size=\"12\"></sp-icon>\n\t\t\t\t\t\t\t\t\t<span data-widget-part=\"scene-portraits.set-name\">{member.spriteSetOverride ?? t(\"Sprite set\")}</span>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t<div data-widget-part=\"scene-portraits.set-panel\">\n\t\t\t\t\t\t\t\t\t<header data-widget-part=\"scene-portraits.set-title\">\n\t\t\t\t\t\t\t\t\t\t<sp-icon name=\"shirt\" size=\"16\"></sp-icon>\n\t\t\t\t\t\t\t\t\t\t<p>{t(\"Sprite set\")}</p>\n\t\t\t\t\t\t\t\t\t</header>\n\t\t\t\t\t\t\t\t\t<div data-widget-part=\"scene-portraits.set-list\" role=\"menu\" aria-label={t(\"Sprite set\")}>\n\t\t\t\t\t\t\t\t\t\t{#each member.spriteSets as setName (setName)}\n\t\t\t\t\t\t\t\t\t\t\t<button\n\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\trole=\"menuitemradio\"\n\t\t\t\t\t\t\t\t\t\t\t\taria-checked={member.spriteSetOverride === setName}\n\t\t\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.set-option\"\n\t\t\t\t\t\t\t\t\t\t\t\tonclick={() => changeSpriteSet(member.characterId, setName)}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{setName}</span>\n\t\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\t{/each}\n\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\trole=\"menuitemradio\"\n\t\t\t\t\t\t\t\t\t\t\taria-checked={!member.spriteSetOverride}\n\t\t\t\t\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.set-option\"\n\t\t\t\t\t\t\t\t\t\t\tonclick={() => changeSpriteSet(member.characterId, null)}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t<span>{t(\"As the story has it\")}</span>\n\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t<p data-widget-part=\"scene-portraits.set-note\">\n\t\t\t\t\t\t\t\t\t\t{t(\"For this session only. An outfit, an age or a form; the lorebook's cast decides it everywhere else.\")}\n\t\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</sp-popover>\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{#if settings.bars && member.ownerKey}\n\t\t\t\t\t\t\t<StatBars ownerKey={member.ownerKey} rows={statBarsOf(sessionState, member.ownerKey)} />\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t</div>\n\t\t\t\t{/each}\n\t\t\t</div>\n\t\t{/if}\n\t{:else if !hasAny}\n\t\t<div data-widget-part=\"scene-portraits.empty empty\">\n\t\t\t<sp-icon name=\"users\" size=\"22\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{t(\"No scene portraits set. Click a character's avatar in the chat to pin one here.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else}\n\t\t<div data-widget-part=\"scene-portraits.pins\">\n\t\t\t{#each pins as pin (pin.side)}\n\t\t\t\t{@const ownerKey = settings.bars ? pin.ownerKey : null}\n\t\t\t\t<div data-widget-part=\"scene-portraits.pin\">\n\t\t\t\t\t{#if pin.src}\n\t\t\t\t\t\t<img\n\t\t\t\t\t\t\tsrc={pin.src}\n\t\t\t\t\t\t\talt={pin.side === \"left\" ? t(\"left scene portrait\") : t(\"right scene portrait\")}\n\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.pin-img\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{#if ownerKey}\n\t\t\t\t\t\t\t<StatBars {ownerKey} rows={statBarsOf(sessionState, ownerKey)} />\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tdata-widget-part=\"scene-portraits.pin-clear\"\n\t\t\t\t\t\t\tonclick={() => clear(pin.side)}\n\t\t\t\t\t\t\ttitle={pin.side === \"left\" ? t(\"Clear left portrait\") : t(\"Clear right portrait\")}\n\t\t\t\t\t\t\taria-label={pin.side === \"left\" ? t(\"Clear left portrait\") : t(\"Clear right portrait\")}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<sp-icon name=\"x\" size=\"13\"></sp-icon>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t{:else}\n\t\t\t\t\t\t<div data-widget-part=\"scene-portraits.pin-placeholder\">\n\t\t\t\t\t\t\t{t(\"Empty\")}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t{/if}\n\t\t\t\t</div>\n\t\t\t{/each}\n\t\t</div>\n\t{/if}\n</div>\n","shared/scene-portraits/StatBars.svelte":"<script lang=\"ts\">\n\t/**\n\t * A mini bar row: one owner's bounded stats, read-only.\n\t *\n\t * Read-only on purpose. This sits under a portrait, where the pointer is\n\t * already doing something else, and a bar you can nudge by a stray click\n\t * is a stat nobody can trust. Editing lives in the Stats widget.\n\t *\n\t * Only slots whose configuration declares both ends of a range are drawn\n\t * (`statBarsOf`): everything else is not a bar, and this row has no room\n\t * to say what it is.\n\t */\n\timport type { StatBarRow } from \"@serene-pub/core-catalog/scene-portraits\"\n\n\tinterface Props {\n\t\t/** The owner key the resolved state files these values under. */\n\t\townerKey: string\n\t\trows: StatBarRow[]\n\t}\n\tlet { ownerKey, rows }: Props = $props()\n</script>\n\n{#if rows.length}\n\t<div data-widget-part=\"scene-portraits.bars list\" data-state-bars={ownerKey}>\n\t\t{#each rows as row (row.slotId)}\n\t\t\t<div\n\t\t\t\tdata-widget-part=\"scene-portraits.bar row\"\n\t\t\t\ttitle=\"{row.label} {row.bar.label}\"\n\t\t\t\taria-label=\"{row.label} {row.bar.label}\"\n\t\t\t>\n\t\t\t\t<span data-widget-part=\"scene-portraits.bar-label label\">{row.label}</span>\n\t\t\t\t<span data-widget-part=\"scene-portraits.bar-track meter\">\n\t\t\t\t\t<span\n\t\t\t\t\t\tdata-widget-part=\"scene-portraits.bar-fill\"\n\t\t\t\t\t\tstyle=\"--sp-fill: {row.bar.percent}%\"\n\t\t\t\t\t></span>\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t{/each}\n\t</div>\n{/if}\n","shared/scene-portraits/scene-portraits.ts":"/**\n * Core's `scene-portraits` component (R21): the faces beside the\n * conversation, as the page's UI worker runs it. `npm run build` compiles it\n * with the CLI's component bundler to `dist/components/scene-portraits.js`,\n * the module the app serves at `/core-ui/scene-portraits`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport ScenePortraits from './ScenePortraits.svelte'\n\nexport default svelteComponent(ScenePortraits)\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_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"},"sourceHash":"677f6a54144d91c17f18a4f67a088f2823123a888b8086d80faf1bb0cf4b627f","catalogVersion":"0.6.0-pr-4"}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
storyTimeText
|
|
13
13
|
} from "./shared-RJDGOAVC.js";
|
|
14
14
|
|
|
15
|
-
// dist/ui/
|
|
15
|
+
// dist/shared/ui/session-state/barMath.js
|
|
16
16
|
var finite = (v) => typeof v === "number" && Number.isFinite(v);
|
|
17
17
|
function barView(value, config) {
|
|
18
18
|
const { min, max } = config;
|
|
@@ -46,7 +46,7 @@ function formatSlotValue(value) {
|
|
|
46
46
|
return String(value);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
// dist/ui/
|
|
49
|
+
// dist/shared/ui/session-state/shapes.js
|
|
50
50
|
var slotFieldOf = (slot) => slot.type === "derived" ? void 0 : slot.field ?? fieldForSlotType(slot.type);
|
|
51
51
|
function slotKind(slot) {
|
|
52
52
|
if (slot.type === "derived")
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
slotTakesLoreRefs,
|
|
20
20
|
storyTimeDraftOf,
|
|
21
21
|
storyTimeDraftValue
|
|
22
|
-
} from "./shared-
|
|
22
|
+
} from "./shared-3FGURYVS.js";
|
|
23
23
|
import {
|
|
24
24
|
append,
|
|
25
25
|
autofocus,
|
|
@@ -49,9 +49,9 @@ import {
|
|
|
49
49
|
state,
|
|
50
50
|
template_effect,
|
|
51
51
|
user_derived
|
|
52
|
-
} from "./shared-
|
|
52
|
+
} from "./shared-U3UU5V7L.js";
|
|
53
53
|
|
|
54
|
-
// dist/ui/
|
|
54
|
+
// dist/shared/ui/session-state/stateView.js
|
|
55
55
|
function pickedNames(raw) {
|
|
56
56
|
return Array.isArray(raw) ? raw.map((n) => String(n).trim().toLowerCase()).filter(Boolean) : [];
|
|
57
57
|
}
|
|
@@ -132,7 +132,7 @@ function enumValues(config) {
|
|
|
132
132
|
return Array.isArray(config.of) ? config.of.map(String) : [];
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
// components/
|
|
135
|
+
// components/shared/state/SlotControl.svelte
|
|
136
136
|
var root = from_html(`<span data-widget-part="stat-slot.required" role="img">*</span>`);
|
|
137
137
|
var root_1 = from_html(`<sp-icon></sp-icon>`, 2);
|
|
138
138
|
var root_2 = from_html(`<button type="button" data-widget-part="stat-slot.chip chip"> </button>`);
|
|
@@ -922,7 +922,7 @@ function SlotControl($$anchor, $$props) {
|
|
|
922
922
|
}
|
|
923
923
|
delegate(["click", "change"]);
|
|
924
924
|
|
|
925
|
-
// components/
|
|
925
|
+
// components/shared/state/slotWriter.svelte.ts
|
|
926
926
|
function createSlotWriter(widget) {
|
|
927
927
|
let error = state(null);
|
|
928
928
|
let asked = 0;
|
|
@@ -943,7 +943,7 @@ function createSlotWriter(widget) {
|
|
|
943
943
|
};
|
|
944
944
|
}
|
|
945
945
|
|
|
946
|
-
// components/
|
|
946
|
+
// components/shared/state/entryFinder.ts
|
|
947
947
|
var PAGE = 25;
|
|
948
948
|
function createEntryFinder(widget, t) {
|
|
949
949
|
if (!widget) return void 0;
|
|
@@ -6384,11 +6384,11 @@ var EMPTY_TURN_ORDER = Object.freeze({
|
|
|
6384
6384
|
strategy: null
|
|
6385
6385
|
});
|
|
6386
6386
|
|
|
6387
|
-
// dist/ui/
|
|
6387
|
+
// dist/shared/ui/widgetContext.js
|
|
6388
6388
|
var scopeNotGranted = (ctx, scope) => !!ctx?.grants && !ctx.grants.includes(scope);
|
|
6389
6389
|
var WIDGET_CONTEXT_KEY = "widget";
|
|
6390
6390
|
|
|
6391
|
-
// components/
|
|
6391
|
+
// components/shared/widgetRef.svelte.ts
|
|
6392
6392
|
var SCOPED_NAMES = Object.values(WIDGET_SCOPED_SECTIONS);
|
|
6393
6393
|
var NOBODY = { userId: null, isAdmin: false, isGuest: false };
|
|
6394
6394
|
function scopedData(scoped) {
|
|
@@ -6443,7 +6443,7 @@ function widgetRefFromComponent(ctx, widget) {
|
|
|
6443
6443
|
};
|
|
6444
6444
|
}
|
|
6445
6445
|
|
|
6446
|
-
// components/
|
|
6446
|
+
// components/shared/context.ts
|
|
6447
6447
|
function useWidgetContext() {
|
|
6448
6448
|
return getContext(WIDGET_CONTEXT_KEY);
|
|
6449
6449
|
}
|
package/dist/components/stats.js
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
createEntryFinder,
|
|
4
4
|
createSlotWriter,
|
|
5
5
|
statsView
|
|
6
|
-
} from "./shared-
|
|
7
|
-
import "./shared-
|
|
6
|
+
} from "./shared-FXYLABGF.js";
|
|
7
|
+
import "./shared-3FGURYVS.js";
|
|
8
8
|
import "./shared-RJDGOAVC.js";
|
|
9
9
|
import {
|
|
10
10
|
WIDGET_CONTEXT_KEY,
|
|
@@ -30,9 +30,9 @@ import {
|
|
|
30
30
|
useWidgetContext,
|
|
31
31
|
user_derived,
|
|
32
32
|
widgetRefFromComponent
|
|
33
|
-
} from "./shared-
|
|
33
|
+
} from "./shared-U3UU5V7L.js";
|
|
34
34
|
|
|
35
|
-
// components/
|
|
35
|
+
// components/shared/stats/StatsWidget.svelte
|
|
36
36
|
var root = from_html(`<p data-widget-part="stats.alert" role="alert"> </p>`);
|
|
37
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
38
|
var root_2 = from_html(`<div data-widget-part="stats.empty empty" role="status"><sp-icon></sp-icon> <span> </span></div>`, 2);
|
|
@@ -214,7 +214,7 @@ function StatsWidget($$anchor, $$props) {
|
|
|
214
214
|
pop();
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
// components/
|
|
217
|
+
// components/shared/stats/Stats.svelte
|
|
218
218
|
function Stats($$anchor, $$props) {
|
|
219
219
|
push($$props, true);
|
|
220
220
|
setContext(WIDGET_CONTEXT_KEY, widgetRefFromComponent(untrack(() => $$props.ctx), { id: "stats", instanceId: "stats", title: "Stats" }));
|
|
@@ -222,7 +222,7 @@ function Stats($$anchor, $$props) {
|
|
|
222
222
|
pop();
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
// components/
|
|
225
|
+
// components/shared/stats/stats.ts
|
|
226
226
|
var stats_default = svelteComponent(Stats);
|
|
227
227
|
export {
|
|
228
228
|
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\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","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: 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 \"../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","shared/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","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"},"sourceHash":"74680abbc2b2337e5c228617263d78aa2b0a3fac8097d157315a26fbfb87a736","catalogVersion":"0.6.0-pr-4"}
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
createEntryFinder,
|
|
4
4
|
createSlotWriter,
|
|
5
5
|
worldStateView
|
|
6
|
-
} from "./shared-
|
|
7
|
-
import "./shared-
|
|
6
|
+
} from "./shared-FXYLABGF.js";
|
|
7
|
+
import "./shared-3FGURYVS.js";
|
|
8
8
|
import "./shared-RJDGOAVC.js";
|
|
9
9
|
import {
|
|
10
10
|
WIDGET_CONTEXT_KEY,
|
|
@@ -29,9 +29,9 @@ import {
|
|
|
29
29
|
useWidgetContext,
|
|
30
30
|
user_derived,
|
|
31
31
|
widgetRefFromComponent
|
|
32
|
-
} from "./shared-
|
|
32
|
+
} from "./shared-U3UU5V7L.js";
|
|
33
33
|
|
|
34
|
-
// components/
|
|
34
|
+
// components/shared/world-state/WorldStateWidget.svelte
|
|
35
35
|
var root = from_html(`<p data-widget-part="world-state.alert" role="alert"> </p>`);
|
|
36
36
|
var root_1 = from_html(`<div data-widget-part="world-state.empty empty" role="status" data-scope-not-granted="session:state"><sp-icon></sp-icon> <span> </span></div>`, 2);
|
|
37
37
|
var root_2 = from_html(`<div data-widget-part="world-state.empty empty" role="status"><sp-icon></sp-icon> <span> </span></div>`, 2);
|
|
@@ -207,7 +207,7 @@ function WorldStateWidget($$anchor, $$props) {
|
|
|
207
207
|
pop();
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
// components/
|
|
210
|
+
// components/shared/world-state/WorldState.svelte
|
|
211
211
|
function WorldState($$anchor, $$props) {
|
|
212
212
|
push($$props, true);
|
|
213
213
|
setContext(WIDGET_CONTEXT_KEY, widgetRefFromComponent(untrack(() => $$props.ctx), {
|
|
@@ -219,7 +219,7 @@ function WorldState($$anchor, $$props) {
|
|
|
219
219
|
pop();
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
// components/
|
|
222
|
+
// components/shared/world-state/world-state.ts
|
|
223
223
|
var world_state_default = svelteComponent(WorldState);
|
|
224
224
|
export {
|
|
225
225
|
world_state_default as default
|