Skip to content

Commit 30b8bcb

Browse files
clemclaude
andcommitted
feat: add Passage type and passage lookup methods to published types
release-npm Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 7e805ec commit 30b8bcb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pkg/types/index.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ export interface SettingsAPI {
8585
hasAny(): boolean;
8686
}
8787

88+
/**
89+
* A parsed passage from the story data.
90+
* @see {@link ../../src/parser.ts} for the implementation.
91+
*/
92+
export interface Passage {
93+
/** Passage ID from the story data. */
94+
pid: number;
95+
/** Passage name. */
96+
name: string;
97+
/** Tags from the passage header. */
98+
tags: string[];
99+
/** Metadata from the Twee 3 passage header (e.g. position, size, or custom keys). */
100+
metadata: Record<string, string>;
101+
/** Raw passage content. */
102+
content: string;
103+
}
104+
88105
/**
89106
* The main Story API available as `window.Story` at runtime.
90107
* Provides access to variables, navigation, save/load, and visit tracking.
@@ -144,9 +161,18 @@ export interface StoryAPI {
144161
/** Check if all of the given passages have been rendered. */
145162
hasRenderedAll(...names: string[]): boolean;
146163

164+
/** Return the full Passage object for the current passage. */
165+
currentPassage(): Passage | undefined;
166+
167+
/** Return the full Passage object for the previous passage in history. */
168+
previousPassage(): Passage | undefined;
169+
147170
/** The story title. */
148171
readonly title: string;
149172

173+
/** The current passage name. */
174+
readonly passage: string;
175+
150176
/** The settings API. */
151177
readonly settings: SettingsAPI;
152178

0 commit comments

Comments
 (0)