@rohal12/twee-ts 1.16.0 → 1.17.0
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 +1540 -796
- package/dist/bin/twee-ts.js.map +1 -1
- package/dist/{compiler-BiDNwR9q.js → diagnostics-DZNS7W41.js} +692 -289
- package/dist/diagnostics-DZNS7W41.js.map +1 -0
- package/dist/index.cjs +1462 -704
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -15
- package/dist/index.d.ts +93 -15
- package/dist/index.js +1464 -706
- package/dist/index.js.map +1 -1
- package/dist/plugins/rollup.d.ts +20 -1
- package/dist/plugins/rollup.js +34 -8
- package/dist/plugins/rollup.js.map +1 -1
- package/dist/plugins/vite.js +46 -33
- package/dist/plugins/vite.js.map +1 -1
- package/package.json +2 -1
- package/dist/compiler-BiDNwR9q.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -55,9 +55,9 @@ interface CompileToFileOptions extends CompileOptions {
|
|
|
55
55
|
outFile: string;
|
|
56
56
|
}
|
|
57
57
|
interface WatchOptions extends CompileToFileOptions {
|
|
58
|
-
/** Called after each
|
|
58
|
+
/** Called after each build is written, including one whose diagnostics report errors. */
|
|
59
59
|
onBuild?: (result: CompileResult) => void;
|
|
60
|
-
/** Called
|
|
60
|
+
/** Called when a build fails with a fatal error (nothing is written). */
|
|
61
61
|
onError?: (error: Error) => void;
|
|
62
62
|
}
|
|
63
63
|
type Diagnostic = {
|
|
@@ -142,6 +142,35 @@ type ReadonlyStory = Readonly<Omit<Story, 'passages' | 'twine1' | 'twine2'>> & {
|
|
|
142
142
|
readonly tagColors: ReadonlyMap<string, string>;
|
|
143
143
|
};
|
|
144
144
|
};
|
|
145
|
+
type OmittingTag = 'Twine.private' | 'script' | 'stylesheet';
|
|
146
|
+
type PassageOmission = {
|
|
147
|
+
readonly kind: 'special-name';
|
|
148
|
+
readonly name: 'StoryData' | 'StoryTitle';
|
|
149
|
+
} | {
|
|
150
|
+
readonly kind: 'tag';
|
|
151
|
+
readonly tag: OmittingTag;
|
|
152
|
+
} | {
|
|
153
|
+
readonly kind: 'empty-story-settings';
|
|
154
|
+
};
|
|
155
|
+
/** The output whose rules decide which passages a story emits as passages. */
|
|
156
|
+
type PassageOutputTarget = 'twine1' | 'twine2';
|
|
157
|
+
interface DecompileOptions {
|
|
158
|
+
/**
|
|
159
|
+
* Trim whitespace at both ends of passage text (and of the Twine 2 story stylesheet and script),
|
|
160
|
+
* as the Twee lexer does. When false, the stored text is kept exactly. Default: true.
|
|
161
|
+
*/
|
|
162
|
+
readonly trim?: boolean;
|
|
163
|
+
}
|
|
164
|
+
interface InspectOptions {
|
|
165
|
+
/**
|
|
166
|
+
* Check link destinations against this output's passage rules. A link to a passage that the
|
|
167
|
+
* output leaves out (in Twine 2: `script`, `stylesheet` and `Twine.private` passages,
|
|
168
|
+
* StoryData, StoryTitle and an empty StorySettings; in Twine 1: `Twine.private` passages) is
|
|
169
|
+
* then a broken link, and says why. Without a target, a link is broken only when no passage
|
|
170
|
+
* has its name.
|
|
171
|
+
*/
|
|
172
|
+
readonly target?: PassageOutputTarget;
|
|
173
|
+
}
|
|
145
174
|
interface StoryFormatInfo {
|
|
146
175
|
id: string;
|
|
147
176
|
filename: string;
|
|
@@ -195,6 +224,12 @@ interface SFAIndex {
|
|
|
195
224
|
}
|
|
196
225
|
interface FileCacheEntry {
|
|
197
226
|
readonly mtimeMs: number;
|
|
227
|
+
/**
|
|
228
|
+
* Identity of the parse options (`trim`, `twee2Compat`) the entry was parsed with. An entry is
|
|
229
|
+
* reused only when this matches the current options; an entry without it is treated as stale
|
|
230
|
+
* and reparsed. The value is opaque: leave it to twee-ts to set.
|
|
231
|
+
*/
|
|
232
|
+
readonly parseOptionsKey?: string;
|
|
198
233
|
readonly passages: readonly Passage[];
|
|
199
234
|
readonly diagnostics: readonly Diagnostic[];
|
|
200
235
|
}
|
|
@@ -236,10 +271,16 @@ export declare function compileToFile(options: CompileToFileOptions): Promise<Co
|
|
|
236
271
|
/**
|
|
237
272
|
* Compile with incremental caching support.
|
|
238
273
|
* Plugins and advanced users can manage their own cache and changed-file tracking.
|
|
274
|
+
*
|
|
275
|
+
* Without `changedFiles`, a cached file is reused while its modification time is unchanged.
|
|
276
|
+
* With it, a file it names (by the path source discovery gives it, relative to the working
|
|
277
|
+
* directory) is always reparsed, whatever its modification time, and every other cached
|
|
278
|
+
* file is reused as it is.
|
|
239
279
|
*/
|
|
240
280
|
export declare function compileIncremental(options: CompileOptions, cache: Map<string, FileCacheEntry>, changedFiles?: ReadonlySet<string>): Promise<CompileResult>;
|
|
241
281
|
/**
|
|
242
|
-
* Watch for file changes and recompile.
|
|
282
|
+
* Watch for file changes and recompile. Every build is written to `outFile`, including
|
|
283
|
+
* one whose diagnostics report errors.
|
|
243
284
|
*/
|
|
244
285
|
export declare function watch(options: WatchOptions): Promise<AbortController>;
|
|
245
286
|
//#endregion
|
|
@@ -259,12 +300,18 @@ interface StoryMap {
|
|
|
259
300
|
tagsByPassage: Map<string, string[]>;
|
|
260
301
|
/**
|
|
261
302
|
* Map of passage name → passage names it links to.
|
|
262
|
-
* Parses `[[target]]`, `[[display->target]]`, `[[display|target]]`,
|
|
263
|
-
*
|
|
264
|
-
*
|
|
303
|
+
* Parses `[[target]]`, `[[display->target]]`, `[[target<-display]]`, `[[display|target]]`,
|
|
304
|
+
* each with or without a setter (`[[display|target][$x to 1]]`), and SugarCube's
|
|
305
|
+
* `<<goto "target">>` / `<<link "display" "target">>`, read as SugarCube 2 reads them
|
|
306
|
+
* (see `sugarcube-macros.ts`). Links and calls in comments are not read. A script passage is
|
|
307
|
+
* read for links only in its strings; a stylesheet passage (including a loaded `.css` file) is
|
|
308
|
+
* CSS and links to nothing.
|
|
265
309
|
*/
|
|
266
310
|
links: Map<string, string[]>;
|
|
267
|
-
/**
|
|
311
|
+
/**
|
|
312
|
+
* Broken links: `{ from, to }` pairs where `to` doesn't exist as a passage, or, with a `target`
|
|
313
|
+
* (see `InspectOptions`), where that output leaves the `to` passage out (`omission` says why).
|
|
314
|
+
*/
|
|
268
315
|
brokenLinks: BrokenLink[];
|
|
269
316
|
/** Story passages with no outgoing links (potential dead ends). */
|
|
270
317
|
deadEnds: string[];
|
|
@@ -276,6 +323,11 @@ interface StoryMap {
|
|
|
276
323
|
interface BrokenLink {
|
|
277
324
|
from: string;
|
|
278
325
|
to: string;
|
|
326
|
+
/**
|
|
327
|
+
* Set when a passage named `to` exists, but the inspected output leaves it out of the story
|
|
328
|
+
* (only with a `target`): why it is left out. Absent when no passage has the name.
|
|
329
|
+
*/
|
|
330
|
+
omission?: PassageOmission;
|
|
279
331
|
}
|
|
280
332
|
/**
|
|
281
333
|
* Inspect a story and return its full structural map.
|
|
@@ -292,8 +344,13 @@ interface BrokenLink {
|
|
|
292
344
|
* expect(map.brokenLinks).toEqual([]);
|
|
293
345
|
* expect(map.deadEnds).not.toContain('Start');
|
|
294
346
|
* ```
|
|
347
|
+
*
|
|
348
|
+
* By default, a link is broken only when no passage has its name. Pass a `target` to check links
|
|
349
|
+
* against what that output emits: `storyInspect(result.story, { target: 'twine2' })` also reports
|
|
350
|
+
* links to passages Twine 2 output leaves out, such as script, stylesheet and `Twine.private`
|
|
351
|
+
* passages.
|
|
295
352
|
*/
|
|
296
|
-
export declare function storyInspect(story: ReadonlyStory): StoryMap;
|
|
353
|
+
export declare function storyInspect(story: ReadonlyStory, options?: InspectOptions): StoryMap;
|
|
297
354
|
//#endregion
|
|
298
355
|
//#region src/story.d.ts
|
|
299
356
|
/**
|
|
@@ -320,8 +377,9 @@ interface DecompileResult {
|
|
|
320
377
|
}
|
|
321
378
|
/**
|
|
322
379
|
* Parse a Twine 2 or Twine 1 compiled HTML file back into a Story model.
|
|
380
|
+
* Tweego always trims passage text; here `trim: false` keeps it exactly, as for Twee sources.
|
|
323
381
|
*/
|
|
324
|
-
export declare function decompileHTML(html: string): DecompileResult;
|
|
382
|
+
export declare function decompileHTML(html: string, options?: DecompileOptions): DecompileResult;
|
|
325
383
|
//#endregion
|
|
326
384
|
//#region src/lint.d.ts
|
|
327
385
|
interface LintResult {
|
|
@@ -341,7 +399,11 @@ interface LintResult {
|
|
|
341
399
|
storyPassages: number;
|
|
342
400
|
/** Info/special passage count. */
|
|
343
401
|
infoPassages: number;
|
|
344
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* Broken links: link targets that don't exist as passages, or that Twine 2 output leaves out
|
|
404
|
+
* (script, stylesheet and `Twine.private` passages, StoryData, StoryTitle, an empty
|
|
405
|
+
* StorySettings); for those, `omission` says why.
|
|
406
|
+
*/
|
|
345
407
|
brokenLinks: BrokenLink[];
|
|
346
408
|
/** Story passages with no outgoing links. */
|
|
347
409
|
deadEnds: string[];
|
|
@@ -350,7 +412,10 @@ interface LintResult {
|
|
|
350
412
|
}
|
|
351
413
|
/**
|
|
352
414
|
* Lint a story: compile without output rendering, then inspect structure.
|
|
353
|
-
* Uses JSON output mode internally to avoid format resolution
|
|
415
|
+
* Uses JSON output mode internally to avoid format resolution, so it checks
|
|
416
|
+
* the starting passage itself, against the Twine 2 passage rules. Link
|
|
417
|
+
* destinations are checked against the same rules: a link to a passage that
|
|
418
|
+
* Twine 2 output leaves out is broken.
|
|
354
419
|
*/
|
|
355
420
|
export declare function lint(options: Omit<CompileOptions, 'outputMode'>): Promise<LintResult>;
|
|
356
421
|
/**
|
|
@@ -400,16 +465,23 @@ interface ParseResult {
|
|
|
400
465
|
}
|
|
401
466
|
/**
|
|
402
467
|
* Parse Twee source text into passages.
|
|
468
|
+
*
|
|
469
|
+
* The source is normalized first, as files are when they are read: a leading UTF-8 BOM is
|
|
470
|
+
* removed and CRLF and bare CR line endings become LF.
|
|
403
471
|
*/
|
|
404
472
|
export declare function parseTwee(source: string, options?: ParseOptions): ParseResult;
|
|
405
473
|
//#endregion
|
|
406
474
|
//#region src/formats.d.ts
|
|
407
475
|
/**
|
|
408
476
|
* Parse the Twine 2 format.js JSON chunk.
|
|
409
|
-
* Handles Harlowe's malformed JSON by stripping the "setup" function property.
|
|
477
|
+
* Handles Harlowe's malformed JSON by stripping the "setup" function property. The workaround
|
|
478
|
+
* keys on the property itself, so the same bytes parse whether they come from a `harlowe-3`
|
|
479
|
+
* directory or a direct download.
|
|
410
480
|
* Per spec, the name key is Optional.
|
|
481
|
+
*
|
|
482
|
+
* @param _formatId No longer used; kept so existing callers keep compiling.
|
|
411
483
|
*/
|
|
412
|
-
export declare function parseFormatJSON(source: string,
|
|
484
|
+
export declare function parseFormatJSON(source: string, _formatId?: string): Twine2FormatJSON | null;
|
|
413
485
|
/**
|
|
414
486
|
* Discover all story formats in the given search directories.
|
|
415
487
|
* Implements SemVer-based version pruning: within each (name, major) group,
|
|
@@ -456,9 +528,11 @@ export declare function fetchAndCacheFormat(entry: SFAIndexEntry, downloadUrl: s
|
|
|
456
528
|
export declare function fetchDirectFormat(url: string): Promise<StoryFormatInfo>;
|
|
457
529
|
/**
|
|
458
530
|
* Try to resolve a remote story format by name and version.
|
|
531
|
+
* 0. Use an exactly matching cached download, without touching the network
|
|
459
532
|
* 1. Try direct format URLs
|
|
460
533
|
* 2. Try custom index URLs
|
|
461
534
|
* 3. Try default SFA indices
|
|
535
|
+
* 4. Fall back to a compatible cached download (e.g. when offline)
|
|
462
536
|
*/
|
|
463
537
|
export declare function resolveRemoteFormat(name: string, version: string, indices?: string[], urls?: string[]): Promise<StoryFormatInfo | undefined>;
|
|
464
538
|
/** Discover all cached remote formats. Returns a Map like discoverFormats(). */
|
|
@@ -472,7 +546,11 @@ interface CachedFormatEntry {
|
|
|
472
546
|
}
|
|
473
547
|
/** List all cached formats with size and modification date. */
|
|
474
548
|
export declare function listCachedFormats(): readonly CachedFormatEntry[];
|
|
475
|
-
/**
|
|
549
|
+
/**
|
|
550
|
+
* Clear all cached formats, or only those matching a given name. Returns the number of entries removed.
|
|
551
|
+
* A name must be a single cache entry name (as `listCachedFormats()` reports it); anything with a
|
|
552
|
+
* path separator or `.`/`..` throws instead of deleting outside the format's own directory.
|
|
553
|
+
*/
|
|
476
554
|
export declare function clearCachedFormats(name?: string): number;
|
|
477
555
|
/** Get total cache size in bytes and format count. */
|
|
478
556
|
export declare function getCacheSize(): {
|
|
@@ -480,4 +558,4 @@ export declare function getCacheSize(): {
|
|
|
480
558
|
count: number;
|
|
481
559
|
};
|
|
482
560
|
//#endregion
|
|
483
|
-
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 };
|
|
561
|
+
export type { BrokenLink, CachedFormatEntry, CompileOptions, CompileResult, CompileStats, CompileToFileOptions, DecompileOptions, DecompileResult, Diagnostic, FileCacheEntry, IFID, InlineSource, InspectOptions, LexerItem, LintResult, OmittingTag, OutputMode, Passage, PassageMetadata, PassageOmission, PassageOutputTarget, ReadonlyPassage, ReadonlyStory, SFAIndex, SFAIndexEntry, SourceInput, SourceLocation, Story, StoryFormatInfo, StoryMap, TweeTsConfig, WatchOptions, WordCountMethod };
|
package/dist/index.d.ts
CHANGED
|
@@ -55,9 +55,9 @@ interface CompileToFileOptions extends CompileOptions {
|
|
|
55
55
|
outFile: string;
|
|
56
56
|
}
|
|
57
57
|
interface WatchOptions extends CompileToFileOptions {
|
|
58
|
-
/** Called after each
|
|
58
|
+
/** Called after each build is written, including one whose diagnostics report errors. */
|
|
59
59
|
onBuild?: (result: CompileResult) => void;
|
|
60
|
-
/** Called
|
|
60
|
+
/** Called when a build fails with a fatal error (nothing is written). */
|
|
61
61
|
onError?: (error: Error) => void;
|
|
62
62
|
}
|
|
63
63
|
type Diagnostic = {
|
|
@@ -142,6 +142,35 @@ type ReadonlyStory = Readonly<Omit<Story, 'passages' | 'twine1' | 'twine2'>> & {
|
|
|
142
142
|
readonly tagColors: ReadonlyMap<string, string>;
|
|
143
143
|
};
|
|
144
144
|
};
|
|
145
|
+
type OmittingTag = 'Twine.private' | 'script' | 'stylesheet';
|
|
146
|
+
type PassageOmission = {
|
|
147
|
+
readonly kind: 'special-name';
|
|
148
|
+
readonly name: 'StoryData' | 'StoryTitle';
|
|
149
|
+
} | {
|
|
150
|
+
readonly kind: 'tag';
|
|
151
|
+
readonly tag: OmittingTag;
|
|
152
|
+
} | {
|
|
153
|
+
readonly kind: 'empty-story-settings';
|
|
154
|
+
};
|
|
155
|
+
/** The output whose rules decide which passages a story emits as passages. */
|
|
156
|
+
type PassageOutputTarget = 'twine1' | 'twine2';
|
|
157
|
+
interface DecompileOptions {
|
|
158
|
+
/**
|
|
159
|
+
* Trim whitespace at both ends of passage text (and of the Twine 2 story stylesheet and script),
|
|
160
|
+
* as the Twee lexer does. When false, the stored text is kept exactly. Default: true.
|
|
161
|
+
*/
|
|
162
|
+
readonly trim?: boolean;
|
|
163
|
+
}
|
|
164
|
+
interface InspectOptions {
|
|
165
|
+
/**
|
|
166
|
+
* Check link destinations against this output's passage rules. A link to a passage that the
|
|
167
|
+
* output leaves out (in Twine 2: `script`, `stylesheet` and `Twine.private` passages,
|
|
168
|
+
* StoryData, StoryTitle and an empty StorySettings; in Twine 1: `Twine.private` passages) is
|
|
169
|
+
* then a broken link, and says why. Without a target, a link is broken only when no passage
|
|
170
|
+
* has its name.
|
|
171
|
+
*/
|
|
172
|
+
readonly target?: PassageOutputTarget;
|
|
173
|
+
}
|
|
145
174
|
interface StoryFormatInfo {
|
|
146
175
|
id: string;
|
|
147
176
|
filename: string;
|
|
@@ -195,6 +224,12 @@ interface SFAIndex {
|
|
|
195
224
|
}
|
|
196
225
|
interface FileCacheEntry {
|
|
197
226
|
readonly mtimeMs: number;
|
|
227
|
+
/**
|
|
228
|
+
* Identity of the parse options (`trim`, `twee2Compat`) the entry was parsed with. An entry is
|
|
229
|
+
* reused only when this matches the current options; an entry without it is treated as stale
|
|
230
|
+
* and reparsed. The value is opaque: leave it to twee-ts to set.
|
|
231
|
+
*/
|
|
232
|
+
readonly parseOptionsKey?: string;
|
|
198
233
|
readonly passages: readonly Passage[];
|
|
199
234
|
readonly diagnostics: readonly Diagnostic[];
|
|
200
235
|
}
|
|
@@ -236,10 +271,16 @@ export declare function compileToFile(options: CompileToFileOptions): Promise<Co
|
|
|
236
271
|
/**
|
|
237
272
|
* Compile with incremental caching support.
|
|
238
273
|
* Plugins and advanced users can manage their own cache and changed-file tracking.
|
|
274
|
+
*
|
|
275
|
+
* Without `changedFiles`, a cached file is reused while its modification time is unchanged.
|
|
276
|
+
* With it, a file it names (by the path source discovery gives it, relative to the working
|
|
277
|
+
* directory) is always reparsed, whatever its modification time, and every other cached
|
|
278
|
+
* file is reused as it is.
|
|
239
279
|
*/
|
|
240
280
|
export declare function compileIncremental(options: CompileOptions, cache: Map<string, FileCacheEntry>, changedFiles?: ReadonlySet<string>): Promise<CompileResult>;
|
|
241
281
|
/**
|
|
242
|
-
* Watch for file changes and recompile.
|
|
282
|
+
* Watch for file changes and recompile. Every build is written to `outFile`, including
|
|
283
|
+
* one whose diagnostics report errors.
|
|
243
284
|
*/
|
|
244
285
|
export declare function watch(options: WatchOptions): Promise<AbortController>;
|
|
245
286
|
//#endregion
|
|
@@ -259,12 +300,18 @@ interface StoryMap {
|
|
|
259
300
|
tagsByPassage: Map<string, string[]>;
|
|
260
301
|
/**
|
|
261
302
|
* Map of passage name → passage names it links to.
|
|
262
|
-
* Parses `[[target]]`, `[[display->target]]`, `[[display|target]]`,
|
|
263
|
-
*
|
|
264
|
-
*
|
|
303
|
+
* Parses `[[target]]`, `[[display->target]]`, `[[target<-display]]`, `[[display|target]]`,
|
|
304
|
+
* each with or without a setter (`[[display|target][$x to 1]]`), and SugarCube's
|
|
305
|
+
* `<<goto "target">>` / `<<link "display" "target">>`, read as SugarCube 2 reads them
|
|
306
|
+
* (see `sugarcube-macros.ts`). Links and calls in comments are not read. A script passage is
|
|
307
|
+
* read for links only in its strings; a stylesheet passage (including a loaded `.css` file) is
|
|
308
|
+
* CSS and links to nothing.
|
|
265
309
|
*/
|
|
266
310
|
links: Map<string, string[]>;
|
|
267
|
-
/**
|
|
311
|
+
/**
|
|
312
|
+
* Broken links: `{ from, to }` pairs where `to` doesn't exist as a passage, or, with a `target`
|
|
313
|
+
* (see `InspectOptions`), where that output leaves the `to` passage out (`omission` says why).
|
|
314
|
+
*/
|
|
268
315
|
brokenLinks: BrokenLink[];
|
|
269
316
|
/** Story passages with no outgoing links (potential dead ends). */
|
|
270
317
|
deadEnds: string[];
|
|
@@ -276,6 +323,11 @@ interface StoryMap {
|
|
|
276
323
|
interface BrokenLink {
|
|
277
324
|
from: string;
|
|
278
325
|
to: string;
|
|
326
|
+
/**
|
|
327
|
+
* Set when a passage named `to` exists, but the inspected output leaves it out of the story
|
|
328
|
+
* (only with a `target`): why it is left out. Absent when no passage has the name.
|
|
329
|
+
*/
|
|
330
|
+
omission?: PassageOmission;
|
|
279
331
|
}
|
|
280
332
|
/**
|
|
281
333
|
* Inspect a story and return its full structural map.
|
|
@@ -292,8 +344,13 @@ interface BrokenLink {
|
|
|
292
344
|
* expect(map.brokenLinks).toEqual([]);
|
|
293
345
|
* expect(map.deadEnds).not.toContain('Start');
|
|
294
346
|
* ```
|
|
347
|
+
*
|
|
348
|
+
* By default, a link is broken only when no passage has its name. Pass a `target` to check links
|
|
349
|
+
* against what that output emits: `storyInspect(result.story, { target: 'twine2' })` also reports
|
|
350
|
+
* links to passages Twine 2 output leaves out, such as script, stylesheet and `Twine.private`
|
|
351
|
+
* passages.
|
|
295
352
|
*/
|
|
296
|
-
export declare function storyInspect(story: ReadonlyStory): StoryMap;
|
|
353
|
+
export declare function storyInspect(story: ReadonlyStory, options?: InspectOptions): StoryMap;
|
|
297
354
|
//#endregion
|
|
298
355
|
//#region src/story.d.ts
|
|
299
356
|
/**
|
|
@@ -320,8 +377,9 @@ interface DecompileResult {
|
|
|
320
377
|
}
|
|
321
378
|
/**
|
|
322
379
|
* Parse a Twine 2 or Twine 1 compiled HTML file back into a Story model.
|
|
380
|
+
* Tweego always trims passage text; here `trim: false` keeps it exactly, as for Twee sources.
|
|
323
381
|
*/
|
|
324
|
-
export declare function decompileHTML(html: string): DecompileResult;
|
|
382
|
+
export declare function decompileHTML(html: string, options?: DecompileOptions): DecompileResult;
|
|
325
383
|
//#endregion
|
|
326
384
|
//#region src/lint.d.ts
|
|
327
385
|
interface LintResult {
|
|
@@ -341,7 +399,11 @@ interface LintResult {
|
|
|
341
399
|
storyPassages: number;
|
|
342
400
|
/** Info/special passage count. */
|
|
343
401
|
infoPassages: number;
|
|
344
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* Broken links: link targets that don't exist as passages, or that Twine 2 output leaves out
|
|
404
|
+
* (script, stylesheet and `Twine.private` passages, StoryData, StoryTitle, an empty
|
|
405
|
+
* StorySettings); for those, `omission` says why.
|
|
406
|
+
*/
|
|
345
407
|
brokenLinks: BrokenLink[];
|
|
346
408
|
/** Story passages with no outgoing links. */
|
|
347
409
|
deadEnds: string[];
|
|
@@ -350,7 +412,10 @@ interface LintResult {
|
|
|
350
412
|
}
|
|
351
413
|
/**
|
|
352
414
|
* Lint a story: compile without output rendering, then inspect structure.
|
|
353
|
-
* Uses JSON output mode internally to avoid format resolution
|
|
415
|
+
* Uses JSON output mode internally to avoid format resolution, so it checks
|
|
416
|
+
* the starting passage itself, against the Twine 2 passage rules. Link
|
|
417
|
+
* destinations are checked against the same rules: a link to a passage that
|
|
418
|
+
* Twine 2 output leaves out is broken.
|
|
354
419
|
*/
|
|
355
420
|
export declare function lint(options: Omit<CompileOptions, 'outputMode'>): Promise<LintResult>;
|
|
356
421
|
/**
|
|
@@ -400,16 +465,23 @@ interface ParseResult {
|
|
|
400
465
|
}
|
|
401
466
|
/**
|
|
402
467
|
* Parse Twee source text into passages.
|
|
468
|
+
*
|
|
469
|
+
* The source is normalized first, as files are when they are read: a leading UTF-8 BOM is
|
|
470
|
+
* removed and CRLF and bare CR line endings become LF.
|
|
403
471
|
*/
|
|
404
472
|
export declare function parseTwee(source: string, options?: ParseOptions): ParseResult;
|
|
405
473
|
//#endregion
|
|
406
474
|
//#region src/formats.d.ts
|
|
407
475
|
/**
|
|
408
476
|
* Parse the Twine 2 format.js JSON chunk.
|
|
409
|
-
* Handles Harlowe's malformed JSON by stripping the "setup" function property.
|
|
477
|
+
* Handles Harlowe's malformed JSON by stripping the "setup" function property. The workaround
|
|
478
|
+
* keys on the property itself, so the same bytes parse whether they come from a `harlowe-3`
|
|
479
|
+
* directory or a direct download.
|
|
410
480
|
* Per spec, the name key is Optional.
|
|
481
|
+
*
|
|
482
|
+
* @param _formatId No longer used; kept so existing callers keep compiling.
|
|
411
483
|
*/
|
|
412
|
-
export declare function parseFormatJSON(source: string,
|
|
484
|
+
export declare function parseFormatJSON(source: string, _formatId?: string): Twine2FormatJSON | null;
|
|
413
485
|
/**
|
|
414
486
|
* Discover all story formats in the given search directories.
|
|
415
487
|
* Implements SemVer-based version pruning: within each (name, major) group,
|
|
@@ -456,9 +528,11 @@ export declare function fetchAndCacheFormat(entry: SFAIndexEntry, downloadUrl: s
|
|
|
456
528
|
export declare function fetchDirectFormat(url: string): Promise<StoryFormatInfo>;
|
|
457
529
|
/**
|
|
458
530
|
* Try to resolve a remote story format by name and version.
|
|
531
|
+
* 0. Use an exactly matching cached download, without touching the network
|
|
459
532
|
* 1. Try direct format URLs
|
|
460
533
|
* 2. Try custom index URLs
|
|
461
534
|
* 3. Try default SFA indices
|
|
535
|
+
* 4. Fall back to a compatible cached download (e.g. when offline)
|
|
462
536
|
*/
|
|
463
537
|
export declare function resolveRemoteFormat(name: string, version: string, indices?: string[], urls?: string[]): Promise<StoryFormatInfo | undefined>;
|
|
464
538
|
/** Discover all cached remote formats. Returns a Map like discoverFormats(). */
|
|
@@ -472,7 +546,11 @@ interface CachedFormatEntry {
|
|
|
472
546
|
}
|
|
473
547
|
/** List all cached formats with size and modification date. */
|
|
474
548
|
export declare function listCachedFormats(): readonly CachedFormatEntry[];
|
|
475
|
-
/**
|
|
549
|
+
/**
|
|
550
|
+
* Clear all cached formats, or only those matching a given name. Returns the number of entries removed.
|
|
551
|
+
* A name must be a single cache entry name (as `listCachedFormats()` reports it); anything with a
|
|
552
|
+
* path separator or `.`/`..` throws instead of deleting outside the format's own directory.
|
|
553
|
+
*/
|
|
476
554
|
export declare function clearCachedFormats(name?: string): number;
|
|
477
555
|
/** Get total cache size in bytes and format count. */
|
|
478
556
|
export declare function getCacheSize(): {
|
|
@@ -480,4 +558,4 @@ export declare function getCacheSize(): {
|
|
|
480
558
|
count: number;
|
|
481
559
|
};
|
|
482
560
|
//#endregion
|
|
483
|
-
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 };
|
|
561
|
+
export type { BrokenLink, CachedFormatEntry, CompileOptions, CompileResult, CompileStats, CompileToFileOptions, DecompileOptions, DecompileResult, Diagnostic, FileCacheEntry, IFID, InlineSource, InspectOptions, LexerItem, LintResult, OmittingTag, OutputMode, Passage, PassageMetadata, PassageOmission, PassageOutputTarget, ReadonlyPassage, ReadonlyStory, SFAIndex, SFAIndexEntry, SourceInput, SourceLocation, Story, StoryFormatInfo, StoryMap, TweeTsConfig, WatchOptions, WordCountMethod };
|