@rohal12/twee-ts 1.14.0 → 1.15.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.
- package/README.md +1 -1
- package/dist/bin/twee-ts.js +5570 -5232
- package/dist/bin/twee-ts.js.map +1 -1
- package/dist/compiler-Bfi1w-to.js +5074 -0
- package/dist/compiler-Bfi1w-to.js.map +1 -0
- package/dist/index.cjs +5368 -5089
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +306 -331
- package/dist/index.d.ts +306 -331
- package/dist/index.js +5332 -5027
- package/dist/index.js.map +1 -1
- package/dist/plugins/rollup.d.ts +21 -27
- package/dist/plugins/rollup.js +23 -31
- package/dist/plugins/rollup.js.map +1 -1
- package/dist/plugins/vite.d.ts +21 -56
- package/dist/plugins/vite.js +404 -67
- package/dist/plugins/vite.js.map +1 -1
- package/dist/types-BFyb40Zq.d.ts +49 -0
- package/package.json +23 -9
- package/dist/chunk-Z2CNKPVJ.js +0 -4771
- package/dist/chunk-Z2CNKPVJ.js.map +0 -1
- package/dist/types-FHZ3rZD6.d.ts +0 -48
package/dist/index.d.cts
CHANGED
|
@@ -1,284 +1,274 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* All public interfaces for twee-ts.
|
|
3
4
|
*/
|
|
4
5
|
type OutputMode = 'html' | 'twee3' | 'twee1' | 'twine2-archive' | 'twine1-archive' | 'json';
|
|
5
6
|
type WordCountMethod = 'tweego' | 'whitespace';
|
|
6
7
|
type InlineSource = {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
filename: string;
|
|
9
|
+
content: string | Buffer;
|
|
9
10
|
};
|
|
10
11
|
type SourceInput = string | InlineSource;
|
|
11
12
|
interface CompileOptions {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
13
|
+
/** Files, directories, or inline sources to compile. */
|
|
14
|
+
sources: SourceInput[];
|
|
15
|
+
/** Output mode. Default: 'html'. */
|
|
16
|
+
outputMode?: OutputMode;
|
|
17
|
+
/** Story format directory ID (e.g. 'sugarcube-2'). */
|
|
18
|
+
formatId?: string;
|
|
19
|
+
/** Name of the starting passage. Default: 'Start'. */
|
|
20
|
+
startPassage?: string;
|
|
21
|
+
/** Extra directories to search for story formats. */
|
|
22
|
+
formatPaths?: string[];
|
|
23
|
+
/** Also search TWEEGO_PATH env for formats. Default: true. */
|
|
24
|
+
useTweegoPath?: boolean;
|
|
25
|
+
/** Module files to inject into <head>. */
|
|
26
|
+
modules?: string[];
|
|
27
|
+
/** Raw HTML file to append to <head>. */
|
|
28
|
+
headFile?: string;
|
|
29
|
+
/** Trim passage whitespace. Default: true. */
|
|
30
|
+
trim?: boolean;
|
|
31
|
+
/** Twee2 compatibility mode. Default: false. */
|
|
32
|
+
twee2Compat?: boolean;
|
|
33
|
+
/** Enable debug/test mode option. Default: false. */
|
|
34
|
+
testMode?: boolean;
|
|
35
|
+
/** URLs to SFA-compatible index.json files for remote format lookup. */
|
|
36
|
+
formatIndices?: string[];
|
|
37
|
+
/** Direct URLs to format.js files. */
|
|
38
|
+
formatUrls?: string[];
|
|
39
|
+
/** Disable remote format fetching. Default: false. */
|
|
40
|
+
noRemote?: boolean;
|
|
41
|
+
/** Map alias tags to canonical special tags (e.g. { library: 'script' }). */
|
|
42
|
+
tagAliases?: Record<string, string>;
|
|
43
|
+
/** Emit source file and line as data- attributes on passage elements. Default: false. */
|
|
44
|
+
sourceInfo?: boolean;
|
|
45
|
+
/** Word counting method. Default: 'tweego'. */
|
|
46
|
+
wordCountMethod?: WordCountMethod;
|
|
46
47
|
}
|
|
47
48
|
interface CompileToFileOptions extends CompileOptions {
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
/** Output file path. */
|
|
50
|
+
outFile: string;
|
|
50
51
|
}
|
|
51
52
|
interface WatchOptions extends CompileToFileOptions {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
/** Called after each successful rebuild. */
|
|
54
|
+
onBuild?: (result: CompileResult) => void;
|
|
55
|
+
/** Called on build errors. */
|
|
56
|
+
onError?: (error: Error) => void;
|
|
56
57
|
}
|
|
57
58
|
type Diagnostic = {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
level: 'warning';
|
|
60
|
+
message: string;
|
|
61
|
+
file?: string;
|
|
62
|
+
line?: number;
|
|
62
63
|
} | {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
level: 'error';
|
|
65
|
+
message: string;
|
|
66
|
+
file?: string;
|
|
67
|
+
line?: number;
|
|
68
|
+
fatal?: boolean;
|
|
68
69
|
};
|
|
69
70
|
interface CompileResult {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
/** The compiled output string (HTML, Twee, JSON, etc.). */
|
|
72
|
+
output: string;
|
|
73
|
+
/** The parsed story model (read-only after compilation). */
|
|
74
|
+
story: ReadonlyStory;
|
|
75
|
+
/** The format used for compilation (undefined for non-HTML modes). */
|
|
76
|
+
format?: StoryFormatInfo;
|
|
77
|
+
/** Collected diagnostics. */
|
|
78
|
+
diagnostics: Diagnostic[];
|
|
79
|
+
/** Compilation statistics. */
|
|
80
|
+
stats: CompileStats;
|
|
80
81
|
}
|
|
81
82
|
interface CompileStats {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
passages: number;
|
|
84
|
+
storyPassages: number;
|
|
85
|
+
words: number;
|
|
86
|
+
files: string[];
|
|
86
87
|
}
|
|
87
88
|
interface SourceLocation {
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
readonly file: string;
|
|
90
|
+
readonly line: number;
|
|
90
91
|
}
|
|
91
92
|
interface PassageMetadata {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
position?: string;
|
|
94
|
+
size?: string;
|
|
95
|
+
[key: string]: string | undefined;
|
|
95
96
|
}
|
|
96
97
|
interface Passage {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
name: string;
|
|
99
|
+
tags: string[];
|
|
100
|
+
text: string;
|
|
101
|
+
metadata?: PassageMetadata;
|
|
102
|
+
source?: SourceLocation;
|
|
102
103
|
}
|
|
103
104
|
type IFID = string & {
|
|
104
|
-
|
|
105
|
+
readonly __brand: 'IFID';
|
|
105
106
|
};
|
|
106
107
|
interface Twine1Metadata {
|
|
107
|
-
|
|
108
|
+
settings: Map<string, string>;
|
|
108
109
|
}
|
|
109
110
|
interface Twine2Metadata {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
format: string;
|
|
112
|
+
formatVersion: string;
|
|
113
|
+
options: Map<string, boolean>;
|
|
114
|
+
start: string;
|
|
115
|
+
tags: string;
|
|
116
|
+
tagColors: Map<string, string>;
|
|
117
|
+
zoom: number;
|
|
117
118
|
}
|
|
118
119
|
interface Story {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
name: string;
|
|
121
|
+
ifid: IFID;
|
|
122
|
+
passages: Passage[];
|
|
123
|
+
legacyIFID: IFID;
|
|
124
|
+
twine1: Twine1Metadata;
|
|
125
|
+
twine2: Twine2Metadata;
|
|
125
126
|
}
|
|
126
127
|
type ReadonlyPassage = Readonly<Passage> & {
|
|
127
|
-
|
|
128
|
+
readonly tags: readonly string[];
|
|
128
129
|
};
|
|
129
130
|
type ReadonlyStory = Readonly<Omit<Story, 'passages' | 'twine1' | 'twine2'>> & {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
131
|
+
readonly passages: readonly ReadonlyPassage[];
|
|
132
|
+
readonly twine1: Readonly<Omit<Twine1Metadata, 'settings'>> & {
|
|
133
|
+
readonly settings: ReadonlyMap<string, string>;
|
|
134
|
+
};
|
|
135
|
+
readonly twine2: Readonly<Omit<Twine2Metadata, 'options' | 'tagColors'>> & {
|
|
136
|
+
readonly options: ReadonlyMap<string, boolean>;
|
|
137
|
+
readonly tagColors: ReadonlyMap<string, string>;
|
|
138
|
+
};
|
|
138
139
|
};
|
|
139
140
|
interface StoryFormatInfo {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
141
|
+
id: string;
|
|
142
|
+
filename: string;
|
|
143
|
+
isTwine2: boolean;
|
|
144
|
+
name: string;
|
|
145
|
+
version: string;
|
|
146
|
+
proofing: boolean;
|
|
147
|
+
author?: string;
|
|
148
|
+
description?: string;
|
|
149
|
+
image?: string;
|
|
150
|
+
url?: string;
|
|
151
|
+
license?: string;
|
|
151
152
|
}
|
|
152
153
|
interface Twine2FormatJSON {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
154
|
+
name: string;
|
|
155
|
+
version: string;
|
|
156
|
+
proofing?: boolean;
|
|
157
|
+
source: string;
|
|
158
|
+
author?: string;
|
|
159
|
+
description?: string;
|
|
160
|
+
image?: string;
|
|
161
|
+
url?: string;
|
|
162
|
+
license?: string;
|
|
162
163
|
}
|
|
163
|
-
declare const ItemType: {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
164
|
+
export declare const ItemType: {
|
|
165
|
+
readonly Error: 0;
|
|
166
|
+
readonly EOF: 1;
|
|
167
|
+
readonly Header: 2;
|
|
168
|
+
readonly Name: 3;
|
|
169
|
+
readonly Tags: 4;
|
|
170
|
+
readonly Metadata: 5;
|
|
171
|
+
readonly Content: 6;
|
|
171
172
|
};
|
|
172
|
-
type ItemType = (typeof ItemType)[keyof typeof ItemType];
|
|
173
|
+
export type ItemType = (typeof ItemType)[keyof typeof ItemType];
|
|
173
174
|
interface LexerItem {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
type: ItemType;
|
|
176
|
+
line: number;
|
|
177
|
+
pos: number;
|
|
178
|
+
val: string;
|
|
178
179
|
}
|
|
179
180
|
interface SFAIndexEntry {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
name: string;
|
|
182
|
+
version: string;
|
|
183
|
+
proofing: boolean;
|
|
184
|
+
files: string[];
|
|
185
|
+
checksums: Record<string, string>;
|
|
185
186
|
}
|
|
186
187
|
interface SFAIndex {
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
twine1: SFAIndexEntry[];
|
|
189
|
+
twine2: SFAIndexEntry[];
|
|
189
190
|
}
|
|
190
191
|
interface FileCacheEntry {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
readonly mtimeMs: number;
|
|
193
|
+
readonly passages: readonly Passage[];
|
|
194
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
194
195
|
}
|
|
195
196
|
interface TweeTsConfig {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
197
|
+
sources?: string[];
|
|
198
|
+
output?: string;
|
|
199
|
+
outputMode?: OutputMode;
|
|
200
|
+
formatId?: string;
|
|
201
|
+
startPassage?: string;
|
|
202
|
+
formatPaths?: string[];
|
|
203
|
+
formatIndices?: string[];
|
|
204
|
+
formatUrls?: string[];
|
|
205
|
+
useTweegoPath?: boolean;
|
|
206
|
+
modules?: string[];
|
|
207
|
+
headFile?: string;
|
|
208
|
+
trim?: boolean;
|
|
209
|
+
twee2Compat?: boolean;
|
|
210
|
+
testMode?: boolean;
|
|
211
|
+
noRemote?: boolean;
|
|
212
|
+
tagAliases?: Record<string, string>;
|
|
213
|
+
sourceInfo?: boolean;
|
|
214
|
+
wordCountMethod?: WordCountMethod;
|
|
214
215
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/compiler.d.ts
|
|
218
|
+
export declare class TweeTsError extends Error {
|
|
219
|
+
diagnostics: Diagnostic[];
|
|
220
|
+
constructor(message: string, diagnostics?: Diagnostic[]);
|
|
219
221
|
}
|
|
220
222
|
/**
|
|
221
223
|
* Compile Twee sources to HTML, Twee, or JSON.
|
|
222
224
|
*/
|
|
223
|
-
declare function compile(options: CompileOptions): Promise<CompileResult>;
|
|
225
|
+
export declare function compile(options: CompileOptions): Promise<CompileResult>;
|
|
224
226
|
/**
|
|
225
227
|
* Compile and write to a file.
|
|
226
228
|
*/
|
|
227
|
-
declare function compileToFile(options: CompileToFileOptions): Promise<CompileResult>;
|
|
229
|
+
export declare function compileToFile(options: CompileToFileOptions): Promise<CompileResult>;
|
|
228
230
|
/**
|
|
229
231
|
* Compile with incremental caching support.
|
|
230
232
|
* Plugins and advanced users can manage their own cache and changed-file tracking.
|
|
231
233
|
*/
|
|
232
|
-
declare function compileIncremental(options: CompileOptions, cache: Map<string, FileCacheEntry>, changedFiles?: ReadonlySet<string>): Promise<CompileResult>;
|
|
234
|
+
export declare function compileIncremental(options: CompileOptions, cache: Map<string, FileCacheEntry>, changedFiles?: ReadonlySet<string>): Promise<CompileResult>;
|
|
233
235
|
/**
|
|
234
236
|
* Watch for file changes and recompile.
|
|
235
237
|
*/
|
|
236
|
-
declare function watch(options: WatchOptions): Promise<AbortController>;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
* Story inspection utilities for unit testing.
|
|
240
|
-
*
|
|
241
|
-
* Extracts structural information from a compiled story:
|
|
242
|
-
* passage names, tags, link graph, broken links, dead ends, orphans.
|
|
243
|
-
*
|
|
244
|
-
* Usage:
|
|
245
|
-
* const result = await compile({ sources: ['./story'] });
|
|
246
|
-
* const map = storyInspect(result.story);
|
|
247
|
-
* expect(map.passages).toContain('Start');
|
|
248
|
-
* expect(map.brokenLinks).toHaveLength(0);
|
|
249
|
-
*/
|
|
250
|
-
|
|
238
|
+
export declare function watch(options: WatchOptions): Promise<AbortController>;
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/inspect.d.ts
|
|
251
241
|
interface StoryMap {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
242
|
+
/** All passage names, in source order. */
|
|
243
|
+
passages: string[];
|
|
244
|
+
/** Only story passages (excludes StoryData, StoryTitle, scripts, stylesheets, etc.). */
|
|
245
|
+
storyPassages: string[];
|
|
246
|
+
/** Only info/special passages. */
|
|
247
|
+
infoPassages: string[];
|
|
248
|
+
/** All unique tags used across the story, sorted alphabetically. */
|
|
249
|
+
tags: string[];
|
|
250
|
+
/** Map of tag → passage names that carry that tag. */
|
|
251
|
+
passagesByTag: Map<string, string[]>;
|
|
252
|
+
/** Map of passage name → tags on that passage. */
|
|
253
|
+
tagsByPassage: Map<string, string[]>;
|
|
254
|
+
/**
|
|
255
|
+
* Map of passage name → passage names it links to.
|
|
256
|
+
* Parses `[[target]]`, `[[display->target]]`, `[[display|target]]`,
|
|
257
|
+
* and SugarCube's `<<goto "target">>` / `<<link "display" "target">>`.
|
|
258
|
+
*/
|
|
259
|
+
links: Map<string, string[]>;
|
|
260
|
+
/** Broken links: `{ from, to }` pairs where `to` doesn't exist as a passage. */
|
|
261
|
+
brokenLinks: BrokenLink[];
|
|
262
|
+
/** Story passages with no outgoing links (potential dead ends). */
|
|
263
|
+
deadEnds: string[];
|
|
264
|
+
/** Story passages that no other passage links to (excluding the start passage). */
|
|
265
|
+
orphans: string[];
|
|
266
|
+
/** The configured start passage name, if any. */
|
|
267
|
+
start: string;
|
|
278
268
|
}
|
|
279
269
|
interface BrokenLink {
|
|
280
|
-
|
|
281
|
-
|
|
270
|
+
from: string;
|
|
271
|
+
to: string;
|
|
282
272
|
}
|
|
283
273
|
/**
|
|
284
274
|
* Inspect a story and return its full structural map.
|
|
@@ -296,206 +286,191 @@ interface BrokenLink {
|
|
|
296
286
|
* expect(map.deadEnds).not.toContain('Start');
|
|
297
287
|
* ```
|
|
298
288
|
*/
|
|
299
|
-
declare function storyInspect(story: ReadonlyStory): StoryMap;
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
* Story model + StoryData JSON marshal/unmarshal.
|
|
303
|
-
* Ported from story.go + storydata.go.
|
|
304
|
-
*/
|
|
305
|
-
|
|
289
|
+
export declare function storyInspect(story: ReadonlyStory): StoryMap;
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region src/story.d.ts
|
|
306
292
|
/**
|
|
307
293
|
* Builder that separates the mutable construction phase from the immutable consumption phase.
|
|
308
294
|
* During construction, the internal `Story` is mutable via `add()` and direct access.
|
|
309
295
|
* After `build()`, the story is returned as `ReadonlyStory`.
|
|
310
296
|
*/
|
|
311
|
-
declare class StoryBuilder {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
297
|
+
export declare class StoryBuilder {
|
|
298
|
+
/** The mutable story, accessible during construction for loader functions. */
|
|
299
|
+
readonly story: Story;
|
|
300
|
+
constructor();
|
|
301
|
+
/** Add a passage, handling special passages (StoryData, StoryTitle, etc.). */
|
|
302
|
+
add(passage: Passage, diagnostics: Diagnostic[]): void;
|
|
303
|
+
/** Check if a passage name exists. */
|
|
304
|
+
has(name: string): boolean;
|
|
305
|
+
/** Finalize and return the story as read-only. */
|
|
306
|
+
build(): ReadonlyStory;
|
|
321
307
|
}
|
|
322
|
-
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/html-parser.d.ts
|
|
323
310
|
interface DecompileResult {
|
|
324
|
-
|
|
325
|
-
|
|
311
|
+
story: Story;
|
|
312
|
+
diagnostics: Diagnostic[];
|
|
326
313
|
}
|
|
327
314
|
/**
|
|
328
315
|
* Parse a Twine 2 or Twine 1 compiled HTML file back into a Story model.
|
|
329
316
|
*/
|
|
330
|
-
declare function decompileHTML(html: string): DecompileResult;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
* Lint mode: compile + inspect story structure without producing output.
|
|
334
|
-
* Surfaces broken links, dead ends, orphans, and compilation diagnostics.
|
|
335
|
-
*/
|
|
336
|
-
|
|
317
|
+
export declare function decompileHTML(html: string): DecompileResult;
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/lint.d.ts
|
|
337
320
|
interface LintResult {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
321
|
+
/** Compilation diagnostics (errors and warnings). */
|
|
322
|
+
diagnostics: Diagnostic[];
|
|
323
|
+
/** Compilation statistics. */
|
|
324
|
+
stats: CompileStats;
|
|
325
|
+
/** Story format name from StoryData (e.g. "SugarCube"). */
|
|
326
|
+
formatName: string;
|
|
327
|
+
/** Story format version from StoryData (e.g. "2.37.3"). */
|
|
328
|
+
formatVersion: string;
|
|
329
|
+
/** The configured start passage name. */
|
|
330
|
+
start: string;
|
|
331
|
+
/** Total passage count. */
|
|
332
|
+
passages: number;
|
|
333
|
+
/** Story passage count (excludes StoryData, StoryTitle, scripts, etc.). */
|
|
334
|
+
storyPassages: number;
|
|
335
|
+
/** Info/special passage count. */
|
|
336
|
+
infoPassages: number;
|
|
337
|
+
/** Broken links: link targets that don't exist as passages. */
|
|
338
|
+
brokenLinks: BrokenLink[];
|
|
339
|
+
/** Story passages with no outgoing links. */
|
|
340
|
+
deadEnds: string[];
|
|
341
|
+
/** Story passages that no other passage links to. */
|
|
342
|
+
orphans: string[];
|
|
360
343
|
}
|
|
361
344
|
/**
|
|
362
345
|
* Lint a story: compile without output rendering, then inspect structure.
|
|
363
346
|
* Uses JSON output mode internally to avoid format resolution.
|
|
364
347
|
*/
|
|
365
|
-
declare function lint(options: Omit<CompileOptions, 'outputMode'>): Promise<LintResult>;
|
|
348
|
+
export declare function lint(options: Omit<CompileOptions, 'outputMode'>): Promise<LintResult>;
|
|
366
349
|
/**
|
|
367
350
|
* Format a lint result as a human-readable report string.
|
|
368
351
|
*/
|
|
369
|
-
declare function formatLintReport(result: LintResult): string;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
* Passage helpers and output methods.
|
|
373
|
-
* Ported from passage.go / passagedata.go.
|
|
374
|
-
*/
|
|
375
|
-
|
|
352
|
+
export declare function formatLintReport(result: LintResult): string;
|
|
353
|
+
//#endregion
|
|
354
|
+
//#region src/passage.d.ts
|
|
376
355
|
/**
|
|
377
356
|
* Apply tag aliases: for each passage carrying an alias tag, add the canonical
|
|
378
357
|
* tag if not already present. Returns new passage objects where tags changed;
|
|
379
358
|
* unchanged passages are returned as-is. Idempotent — safe to call multiple times.
|
|
380
359
|
*/
|
|
381
|
-
declare function applyTagAliases(passages: readonly Passage[], aliases: Record<string, string>): Passage[];
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
* Twee 3 state-machine lexer implemented as a synchronous generator.
|
|
385
|
-
* Ported from tweelexer.go — Go channels become `yield`.
|
|
386
|
-
*/
|
|
387
|
-
|
|
360
|
+
export declare function applyTagAliases(passages: readonly Passage[], aliases: Record<string, string>): Passage[];
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region src/lexer.d.ts
|
|
388
363
|
/**
|
|
389
364
|
* Twee 3 lexer — yields LexerItem tokens from Twee source text.
|
|
390
365
|
*
|
|
391
366
|
* In the Go reference, this uses goroutines and channels.
|
|
392
367
|
* Here we use a synchronous generator that accumulates items per state step.
|
|
393
368
|
*/
|
|
394
|
-
declare function tweeLexer(input: string): Generator<LexerItem, void, undefined>;
|
|
369
|
+
export declare function tweeLexer(input: string): Generator<LexerItem, void, undefined>;
|
|
395
370
|
/** Convenience class wrapper for the lexer generator. */
|
|
396
|
-
declare class TweeLexer {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
371
|
+
export declare class TweeLexer {
|
|
372
|
+
private gen;
|
|
373
|
+
constructor(input: string);
|
|
374
|
+
nextItem(): {
|
|
375
|
+
item: LexerItem;
|
|
376
|
+
done: boolean;
|
|
377
|
+
};
|
|
378
|
+
[Symbol.iterator](): Generator<LexerItem, void, undefined>;
|
|
404
379
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
* Parse lexer items into Passage[].
|
|
408
|
-
* Ported from storyload.go:loadTwee().
|
|
409
|
-
*/
|
|
410
|
-
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/parser.d.ts
|
|
411
382
|
interface ParseOptions {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
383
|
+
/** Filename for diagnostics. */
|
|
384
|
+
filename?: string;
|
|
385
|
+
/** Trim whitespace from passage content. Default: true. */
|
|
386
|
+
trim?: boolean;
|
|
387
|
+
/** Enable Twee2 compatibility. Default: false. */
|
|
388
|
+
twee2Compat?: boolean;
|
|
418
389
|
}
|
|
419
390
|
interface ParseResult {
|
|
420
|
-
|
|
421
|
-
|
|
391
|
+
passages: Passage[];
|
|
392
|
+
diagnostics: Diagnostic[];
|
|
422
393
|
}
|
|
423
394
|
/**
|
|
424
395
|
* Parse Twee source text into passages.
|
|
425
396
|
*/
|
|
426
|
-
declare function parseTwee(source: string, options?: ParseOptions): ParseResult;
|
|
427
|
-
|
|
397
|
+
export declare function parseTwee(source: string, options?: ParseOptions): ParseResult;
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region src/formats.d.ts
|
|
428
400
|
/**
|
|
429
401
|
* Parse the Twine 2 format.js JSON chunk.
|
|
430
402
|
* Handles Harlowe's malformed JSON by stripping the "setup" function property.
|
|
431
403
|
* Per spec, the name key is Optional.
|
|
432
404
|
*/
|
|
433
|
-
declare function parseFormatJSON(source: string, formatId: string): Twine2FormatJSON | null;
|
|
405
|
+
export declare function parseFormatJSON(source: string, formatId: string): Twine2FormatJSON | null;
|
|
434
406
|
/**
|
|
435
407
|
* Discover all story formats in the given search directories.
|
|
436
408
|
* Implements SemVer-based version pruning: within each (name, major) group,
|
|
437
409
|
* only the highest minor.patch survives.
|
|
438
410
|
*/
|
|
439
|
-
declare function discoverFormats(searchDirs: string[]): Map<string, StoryFormatInfo>;
|
|
411
|
+
export declare function discoverFormats(searchDirs: string[]): Map<string, StoryFormatInfo>;
|
|
440
412
|
/**
|
|
441
413
|
* Get the default format search directories.
|
|
442
414
|
*/
|
|
443
|
-
declare function getFormatSearchDirs(extraPaths?: string[], useTweegoPath?: boolean): string[];
|
|
415
|
+
export declare function getFormatSearchDirs(extraPaths?: string[], useTweegoPath?: boolean): string[];
|
|
444
416
|
/** Parse a simple semver string into [major, minor, patch]. */
|
|
445
|
-
declare function parseSemver(v: string): [number, number, number] | null;
|
|
446
|
-
declare function semverCompare(a: [number, number, number], b: [number, number, number]): number;
|
|
447
|
-
|
|
417
|
+
export declare function parseSemver(v: string): [number, number, number] | null;
|
|
418
|
+
export declare function semverCompare(a: [number, number, number], b: [number, number, number]): number;
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region src/ifid.d.ts
|
|
448
421
|
/** Generate a new IFID (UUID v4, uppercase). */
|
|
449
|
-
declare function generateIFID(): IFID;
|
|
422
|
+
export declare function generateIFID(): IFID;
|
|
450
423
|
/** Validate and brand an IFID string. Throws on invalid input. */
|
|
451
|
-
declare function createIFID(value: string): IFID;
|
|
424
|
+
export declare function createIFID(value: string): IFID;
|
|
452
425
|
/**
|
|
453
426
|
* Validate an IFID string.
|
|
454
427
|
* Accepts both bare UUIDs and UUID://...// wrapped format.
|
|
455
428
|
* Returns null if valid, or an error message string.
|
|
456
429
|
*/
|
|
457
|
-
declare function validateIFID(ifid: string): string | null;
|
|
458
|
-
|
|
459
|
-
|
|
430
|
+
export declare function validateIFID(ifid: string): string | null;
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/config.d.ts
|
|
433
|
+
export declare const CONFIG_FILENAME = "twee-ts.config.json";
|
|
460
434
|
/** Load a config file from the given directory (default: cwd). Returns null if not found. */
|
|
461
|
-
declare function loadConfig(dir?: string): TweeTsConfig | null;
|
|
435
|
+
export declare function loadConfig(dir?: string): TweeTsConfig | null;
|
|
462
436
|
/** Load a config from a specific file path. */
|
|
463
|
-
declare function loadConfigFile(filePath: string): TweeTsConfig;
|
|
437
|
+
export declare function loadConfigFile(filePath: string): TweeTsConfig;
|
|
464
438
|
/** Validate a config object. Returns an array of error strings (empty = valid). */
|
|
465
|
-
declare function validateConfig(data: unknown): string[];
|
|
439
|
+
export declare function validateConfig(data: unknown): string[];
|
|
466
440
|
/** Return a default config JSON string for --init scaffolding. */
|
|
467
|
-
declare function scaffoldConfig(): string;
|
|
468
|
-
|
|
441
|
+
export declare function scaffoldConfig(): string;
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/remote-formats.d.ts
|
|
469
444
|
/** Get the cache directory for downloaded story formats. */
|
|
470
|
-
declare function getCacheDir(): string;
|
|
445
|
+
export declare function getCacheDir(): string;
|
|
471
446
|
/** Download a format, verify its checksum, write to cache, and return StoryFormatInfo. */
|
|
472
|
-
declare function fetchAndCacheFormat(entry: SFAIndexEntry, downloadUrl: string): Promise<StoryFormatInfo>;
|
|
447
|
+
export declare function fetchAndCacheFormat(entry: SFAIndexEntry, downloadUrl: string): Promise<StoryFormatInfo>;
|
|
473
448
|
/** Download a direct format.js URL, parse its JSON, cache it, and return StoryFormatInfo. */
|
|
474
|
-
declare function fetchDirectFormat(url: string): Promise<StoryFormatInfo>;
|
|
449
|
+
export declare function fetchDirectFormat(url: string): Promise<StoryFormatInfo>;
|
|
475
450
|
/**
|
|
476
451
|
* Try to resolve a remote story format by name and version.
|
|
477
452
|
* 1. Try direct format URLs
|
|
478
453
|
* 2. Try custom index URLs
|
|
479
454
|
* 3. Try default SFA indices
|
|
480
455
|
*/
|
|
481
|
-
declare function resolveRemoteFormat(name: string, version: string, indices?: string[], urls?: string[]): Promise<StoryFormatInfo | undefined>;
|
|
456
|
+
export declare function resolveRemoteFormat(name: string, version: string, indices?: string[], urls?: string[]): Promise<StoryFormatInfo | undefined>;
|
|
482
457
|
/** Discover all cached remote formats. Returns a Map like discoverFormats(). */
|
|
483
|
-
declare function discoverCachedFormats(): Map<string, StoryFormatInfo>;
|
|
458
|
+
export declare function discoverCachedFormats(): Map<string, StoryFormatInfo>;
|
|
484
459
|
/** Info about a cached format entry with size and modification date. */
|
|
485
460
|
interface CachedFormatEntry {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
461
|
+
readonly name: string;
|
|
462
|
+
readonly version: string;
|
|
463
|
+
readonly sizeBytes: number;
|
|
464
|
+
readonly modifiedAt: Date;
|
|
490
465
|
}
|
|
491
466
|
/** List all cached formats with size and modification date. */
|
|
492
|
-
declare function listCachedFormats(): readonly CachedFormatEntry[];
|
|
467
|
+
export declare function listCachedFormats(): readonly CachedFormatEntry[];
|
|
493
468
|
/** Clear all cached formats, or only those matching a given name. Returns the number of entries removed. */
|
|
494
|
-
declare function clearCachedFormats(name?: string): number;
|
|
469
|
+
export declare function clearCachedFormats(name?: string): number;
|
|
495
470
|
/** Get total cache size in bytes and format count. */
|
|
496
|
-
declare function getCacheSize(): {
|
|
497
|
-
|
|
498
|
-
|
|
471
|
+
export declare function getCacheSize(): {
|
|
472
|
+
totalBytes: number;
|
|
473
|
+
count: number;
|
|
499
474
|
};
|
|
500
|
-
|
|
501
|
-
export {
|
|
475
|
+
//#endregion
|
|
476
|
+
export type { BrokenLink, CachedFormatEntry, CompileOptions, CompileResult, CompileStats, CompileToFileOptions, DecompileResult, Diagnostic, FileCacheEntry, IFID, InlineSource, LexerItem, LintResult, OutputMode, Passage, PassageMetadata, ReadonlyPassage, ReadonlyStory, SFAIndex, SFAIndexEntry, SourceInput, SourceLocation, Story, StoryFormatInfo, StoryMap, TweeTsConfig, WatchOptions, WordCountMethod };
|