@serene-pub/core-catalog 0.6.0-pr-1 → 0.6.0-pr-2

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.
@@ -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-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 +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-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 +1 @@
1
- {"slug":"world-state","framework":"svelte","entry":"sessions/world-state/world-state.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/world-state/WorldState.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's World State 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 WorldStateWidget from \"./WorldStateWidget.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: \"world-state\", instanceId: \"world-state\", title: \"World State\" }\n\t\t)\n\t)\n</script>\n\n<WorldStateWidget />\n","sessions/world-state/WorldStateWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * The World State widget: the session's world slots, editable (R21).\n\t *\n\t * The same values a template reads as `state.world.*` and the conditions\n\t * vocabulary reads for layout rules — so what is edited here is what the\n\t * model is told and what a rule fires on, which is why it is worth one\n\t * strip above the messages rather than a page somewhere else.\n\t *\n\t * A world slot belongs to the session's own owner, so an edit is a\n\t * session-layer deviation: the world's own answer is untouched, and clearing\n\t * one goes back to inheriting it. Reads the `session_state` section and its\n\t * settings (`layout`, `slots`, `pickSlots`); writes `set-attribute-value`,\n\t * whose refusal is this widget's own line (R77).\n\t *\n\t * 🚧 A location holding state (attributes phase 4) is drawn as a place\n\t * under the world's slots — only one with a value in play.\n\t *\n\t * The markup carries no look: each element names what it is in\n\t * `data-widget-part` (`world-state.place`, …), the layout rides on\n\t * `data-layout`, and the default widget stylesheet draws them\n\t * (STYLE-GUIDE §6.16).\n\t */\n\timport { worldStateView } 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`: the section will never come — said, not waited for.\n\tlet view = $derived(worldStateView(section, settings, widget?.current.grants?.includes(\"session:state\")))\n</script>\n\n<div\n\tdata-widget-part=\"world-state.root\"\n\tdata-layout={view.layout === \"strip\" ? \"strip\" : \"list\"}\n\tdata-state-widget=\"world-state\"\n\tdata-owner-key=\"world\"\n>\n\t{#if section?.error}\n\t\t<p data-widget-part=\"world-state.alert\" role=\"alert\">{section.error}</p>\n\t{/if}\n\t{#if writer.error}\n\t\t<p data-widget-part=\"world-state.alert\" role=\"alert\">{writer.error}</p>\n\t{/if}\n\n\t{#if view.status === \"not-granted\"}\n\t\t<div data-widget-part=\"world-state.empty empty\" role=\"status\" data-scope-not-granted=\"session:state\">\n\t\t\t<sp-icon name=\"lock\" size=\"16\"></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=\"world-state.empty empty\" role=\"status\">\n\t\t\t<sp-icon name=\"cloud-sun\" size=\"16\"></sp-icon>\n\t\t\t<span>{t(\"Loading the world'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 === \"empty\"}\n\t\t<div data-widget-part=\"world-state.empty empty\">\n\t\t\t<sp-icon name=\"cloud-sun\" size=\"16\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{view.reason === \"none-shown\"\n\t\t\t\t\t? t(\"This session's world declares no stats to show here.\")\n\t\t\t\t\t: t(\"Nothing in this session declares world stats. A genre or an extension adds them.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else}\n\t\t{@const owner = view.owner}\n\t\t{#each view.slots as shown (shown.slot.slotId)}\n\t\t\t<SlotControl\n\t\t\t\tslot={shown.slot}\n\t\t\t\tdensity={view.layout === \"strip\" ? \"compact\" : \"full\"}\n\t\t\t\tconfig={shown.config}\n\t\t\t\tvalue={shown.value}\n\t\t\t\t{t}\n\t\t\t\t{findEntries}\n\t\t\t\tonset={(next) => void writer.set(owner, shown.slot.slotId, next)}\n\t\t\t/>\n\t\t{/each}\n\t\t<!-- Phase 4: each location in play, under the world's own slots. -->\n\t\t{#each view.places as place (place.owner.key)}\n\t\t\t<section data-widget-part=\"world-state.place\" data-owner-key={place.owner.key} aria-label={place.owner.label}>\n\t\t\t\t<header data-widget-part=\"world-state.place-head\">\n\t\t\t\t\t<sp-icon name=\"map-pin\" size=\"13\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"world-state.place-name\">{place.owner.label}</span>\n\t\t\t\t</header>\n\t\t\t\t{#each place.slots as shown (shown.slot.slotId)}\n\t\t\t\t\t<SlotControl\n\t\t\t\t\t\tslot={shown.slot}\n\t\t\t\t\t\tdensity={view.layout === \"strip\" ? \"compact\" : \"full\"}\n\t\t\t\t\t\tconfig={shown.config}\n\t\t\t\t\t\tvalue={shown.value}\n\t\t\t\t\t\t{t}\n\t\t\t\t\t\t{findEntries}\n\t\t\t\t\t\tonset={(next) => void writer.set(place.owner, shown.slot.slotId, next)}\n\t\t\t\t\t/>\n\t\t\t\t{/each}\n\t\t\t</section>\n\t\t{/each}\n\t{/if}\n</div>\n","sessions/world-state/world-state.ts":"/**\n * Core's `world-state` component (R21): the session's world stats, as the\n * page's UI worker runs it. `npm run build` compiles it with the CLI's\n * component bundler to `dist/components/world-state.js`, the module the app\n * serves at `/core-ui/world-state`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport WorldState from './WorldState.svelte'\n\nexport default svelteComponent(WorldState)\n"},"sourceHash":"5b44affdf8ef7178ec2eb1043913b475e2aba22cf863f2ae4104d28334b69cd5","catalogVersion":"0.6.0-pr-1"}
1
+ {"slug":"world-state","framework":"svelte","entry":"sessions/world-state/world-state.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/world-state/WorldState.svelte":"<script lang=\"ts\">\n\t/**\n\t * Core's World State 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 WorldStateWidget from \"./WorldStateWidget.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: \"world-state\", instanceId: \"world-state\", title: \"World State\" }\n\t\t)\n\t)\n</script>\n\n<WorldStateWidget />\n","sessions/world-state/WorldStateWidget.svelte":"<script lang=\"ts\">\n\t/**\n\t * The World State widget: the session's world slots, editable (R21).\n\t *\n\t * The same values a template reads as `state.world.*` and the conditions\n\t * vocabulary reads for layout rules — so what is edited here is what the\n\t * model is told and what a rule fires on, which is why it is worth one\n\t * strip above the messages rather than a page somewhere else.\n\t *\n\t * A world slot belongs to the session's own owner, so an edit is a\n\t * session-layer deviation: the world's own answer is untouched, and clearing\n\t * one goes back to inheriting it. Reads the `session_state` section and its\n\t * settings (`layout`, `slots`, `pickSlots`); writes `set-attribute-value`,\n\t * whose refusal is this widget's own line (R77).\n\t *\n\t * 🚧 A location holding state (attributes phase 4) is drawn as a place\n\t * under the world's slots — only one with a value in play.\n\t *\n\t * The markup carries no look: each element names what it is in\n\t * `data-widget-part` (`world-state.place`, …), the layout rides on\n\t * `data-layout`, and the default widget stylesheet draws them\n\t * (STYLE-GUIDE §6.16).\n\t */\n\timport { worldStateView } 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`: the section will never come — said, not waited for.\n\tlet view = $derived(worldStateView(section, settings, widget?.current.grants?.includes(\"session:state\")))\n</script>\n\n<div\n\tdata-widget-part=\"world-state.root\"\n\tdata-layout={view.layout === \"strip\" ? \"strip\" : \"list\"}\n\tdata-state-widget=\"world-state\"\n\tdata-owner-key=\"world\"\n>\n\t{#if section?.error}\n\t\t<p data-widget-part=\"world-state.alert\" role=\"alert\">{section.error}</p>\n\t{/if}\n\t{#if writer.error}\n\t\t<p data-widget-part=\"world-state.alert\" role=\"alert\">{writer.error}</p>\n\t{/if}\n\n\t{#if view.status === \"not-granted\"}\n\t\t<div data-widget-part=\"world-state.empty empty\" role=\"status\" data-scope-not-granted=\"session:state\">\n\t\t\t<sp-icon name=\"lock\" size=\"16\"></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=\"world-state.empty empty\" role=\"status\">\n\t\t\t<sp-icon name=\"cloud-sun\" size=\"16\"></sp-icon>\n\t\t\t<span>{t(\"Loading the world'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 === \"empty\"}\n\t\t<div data-widget-part=\"world-state.empty empty\">\n\t\t\t<sp-icon name=\"cloud-sun\" size=\"16\"></sp-icon>\n\t\t\t<span>\n\t\t\t\t{view.reason === \"none-shown\"\n\t\t\t\t\t? t(\"This session's world declares no stats to show here.\")\n\t\t\t\t\t: t(\"Nothing in this session declares world stats. A genre or an extension adds them.\")}\n\t\t\t</span>\n\t\t</div>\n\t{:else}\n\t\t{@const owner = view.owner}\n\t\t{#each view.slots as shown (shown.slot.slotId)}\n\t\t\t<SlotControl\n\t\t\t\tslot={shown.slot}\n\t\t\t\tdensity={view.layout === \"strip\" ? \"compact\" : \"full\"}\n\t\t\t\tconfig={shown.config}\n\t\t\t\tvalue={shown.value}\n\t\t\t\t{t}\n\t\t\t\t{findEntries}\n\t\t\t\tonset={(next) => void writer.set(owner, shown.slot.slotId, next)}\n\t\t\t/>\n\t\t{/each}\n\t\t<!-- Phase 4: each location in play, under the world's own slots. -->\n\t\t{#each view.places as place (place.owner.key)}\n\t\t\t<section data-widget-part=\"world-state.place\" data-owner-key={place.owner.key} aria-label={place.owner.label}>\n\t\t\t\t<header data-widget-part=\"world-state.place-head\">\n\t\t\t\t\t<sp-icon name=\"map-pin\" size=\"13\"></sp-icon>\n\t\t\t\t\t<span data-widget-part=\"world-state.place-name\">{place.owner.label}</span>\n\t\t\t\t</header>\n\t\t\t\t{#each place.slots as shown (shown.slot.slotId)}\n\t\t\t\t\t<SlotControl\n\t\t\t\t\t\tslot={shown.slot}\n\t\t\t\t\t\tdensity={view.layout === \"strip\" ? \"compact\" : \"full\"}\n\t\t\t\t\t\tconfig={shown.config}\n\t\t\t\t\t\tvalue={shown.value}\n\t\t\t\t\t\t{t}\n\t\t\t\t\t\t{findEntries}\n\t\t\t\t\t\tonset={(next) => void writer.set(place.owner, shown.slot.slotId, next)}\n\t\t\t\t\t/>\n\t\t\t\t{/each}\n\t\t\t</section>\n\t\t{/each}\n\t{/if}\n</div>\n","sessions/world-state/world-state.ts":"/**\n * Core's `world-state` component (R21): the session's world stats, as the\n * page's UI worker runs it. `npm run build` compiles it with the CLI's\n * component bundler to `dist/components/world-state.js`, the module the app\n * serves at `/core-ui/world-state`.\n */\nimport { svelteComponent } from '@serene-pub/component-client/svelte'\nimport WorldState from './WorldState.svelte'\n\nexport default svelteComponent(WorldState)\n"},"sourceHash":"5b44affdf8ef7178ec2eb1043913b475e2aba22cf863f2ae4104d28334b69cd5","catalogVersion":"0.6.0-pr-2"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serene-pub/core-catalog",
3
- "version": "0.6.0-pr-1",
3
+ "version": "0.6.0-pr-2",
4
4
  "description": "The genres, pipelines, hook declarations and core components Serene Pub ships. Serene Pub seeds from it at boot, conformance uses it as fixtures, and plugin authors import it for typed references.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/SerenePub/serene-pub-sdk/tree/main/core-catalog#readme",
@@ -71,9 +71,9 @@
71
71
  "./package.json": "./package.json"
72
72
  },
73
73
  "peerDependencies": {
74
- "@serene-pub/sdk": "^0.6.0-pr-1",
75
- "@serene-pub/contracts": "^0.6.0-pr-1",
76
- "@serene-pub/component-client": "^0.6.0-pr-1",
74
+ "@serene-pub/sdk": "^0.6.0-pr-2",
75
+ "@serene-pub/contracts": "^0.6.0-pr-2",
76
+ "@serene-pub/component-client": "^0.6.0-pr-2",
77
77
  "svelte": ">=5"
78
78
  },
79
79
  "peerDependenciesMeta": {
@@ -88,10 +88,10 @@
88
88
  "build": "tsc -p tsconfig.build.json && node scripts/buildComponents.mjs"
89
89
  },
90
90
  "devDependencies": {
91
- "@serene-pub/sdk": "0.6.0-pr-1",
92
- "@serene-pub/contracts": "0.6.0-pr-1",
93
- "@serene-pub/cli": "0.6.0-pr-1",
94
- "@serene-pub/component-client": "0.6.0-pr-1",
91
+ "@serene-pub/sdk": "0.6.0-pr-2",
92
+ "@serene-pub/contracts": "0.6.0-pr-2",
93
+ "@serene-pub/cli": "0.6.0-pr-2",
94
+ "@serene-pub/component-client": "0.6.0-pr-2",
95
95
  "svelte": "^5.56.0"
96
96
  },
97
97
  "publishConfig": {