@rohal12/twee-ts 1.16.1 → 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/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 successful rebuild. */
58
+ /** Called after each build is written, including one whose diagnostics report errors. */
59
59
  onBuild?: (result: CompileResult) => void;
60
- /** Called on build errors. */
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;
@@ -242,10 +271,16 @@ export declare function compileToFile(options: CompileToFileOptions): Promise<Co
242
271
  /**
243
272
  * Compile with incremental caching support.
244
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.
245
279
  */
246
280
  export declare function compileIncremental(options: CompileOptions, cache: Map<string, FileCacheEntry>, changedFiles?: ReadonlySet<string>): Promise<CompileResult>;
247
281
  /**
248
- * 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.
249
284
  */
250
285
  export declare function watch(options: WatchOptions): Promise<AbortController>;
251
286
  //#endregion
@@ -268,10 +303,15 @@ interface StoryMap {
268
303
  * Parses `[[target]]`, `[[display->target]]`, `[[target<-display]]`, `[[display|target]]`,
269
304
  * each with or without a setter (`[[display|target][$x to 1]]`), and SugarCube's
270
305
  * `<<goto "target">>` / `<<link "display" "target">>`, read as SugarCube 2 reads them
271
- * (see `sugarcube-macros.ts`). Links and calls in comments are not read.
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.
272
309
  */
273
310
  links: Map<string, string[]>;
274
- /** Broken links: `{ from, to }` pairs where `to` doesn't exist as a passage. */
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
+ */
275
315
  brokenLinks: BrokenLink[];
276
316
  /** Story passages with no outgoing links (potential dead ends). */
277
317
  deadEnds: string[];
@@ -283,6 +323,11 @@ interface StoryMap {
283
323
  interface BrokenLink {
284
324
  from: string;
285
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;
286
331
  }
287
332
  /**
288
333
  * Inspect a story and return its full structural map.
@@ -299,8 +344,13 @@ interface BrokenLink {
299
344
  * expect(map.brokenLinks).toEqual([]);
300
345
  * expect(map.deadEnds).not.toContain('Start');
301
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.
302
352
  */
303
- export declare function storyInspect(story: ReadonlyStory): StoryMap;
353
+ export declare function storyInspect(story: ReadonlyStory, options?: InspectOptions): StoryMap;
304
354
  //#endregion
305
355
  //#region src/story.d.ts
306
356
  /**
@@ -327,8 +377,9 @@ interface DecompileResult {
327
377
  }
328
378
  /**
329
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.
330
381
  */
331
- export declare function decompileHTML(html: string): DecompileResult;
382
+ export declare function decompileHTML(html: string, options?: DecompileOptions): DecompileResult;
332
383
  //#endregion
333
384
  //#region src/lint.d.ts
334
385
  interface LintResult {
@@ -348,7 +399,11 @@ interface LintResult {
348
399
  storyPassages: number;
349
400
  /** Info/special passage count. */
350
401
  infoPassages: number;
351
- /** Broken links: link targets that don't exist as passages. */
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
+ */
352
407
  brokenLinks: BrokenLink[];
353
408
  /** Story passages with no outgoing links. */
354
409
  deadEnds: string[];
@@ -358,7 +413,9 @@ interface LintResult {
358
413
  /**
359
414
  * Lint a story: compile without output rendering, then inspect structure.
360
415
  * Uses JSON output mode internally to avoid format resolution, so it checks
361
- * the starting passage itself, against the Twine 2 passage rules.
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.
362
419
  */
363
420
  export declare function lint(options: Omit<CompileOptions, 'outputMode'>): Promise<LintResult>;
364
421
  /**
@@ -501,4 +558,4 @@ export declare function getCacheSize(): {
501
558
  count: number;
502
559
  };
503
560
  //#endregion
504
- 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 successful rebuild. */
58
+ /** Called after each build is written, including one whose diagnostics report errors. */
59
59
  onBuild?: (result: CompileResult) => void;
60
- /** Called on build errors. */
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;
@@ -242,10 +271,16 @@ export declare function compileToFile(options: CompileToFileOptions): Promise<Co
242
271
  /**
243
272
  * Compile with incremental caching support.
244
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.
245
279
  */
246
280
  export declare function compileIncremental(options: CompileOptions, cache: Map<string, FileCacheEntry>, changedFiles?: ReadonlySet<string>): Promise<CompileResult>;
247
281
  /**
248
- * 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.
249
284
  */
250
285
  export declare function watch(options: WatchOptions): Promise<AbortController>;
251
286
  //#endregion
@@ -268,10 +303,15 @@ interface StoryMap {
268
303
  * Parses `[[target]]`, `[[display->target]]`, `[[target<-display]]`, `[[display|target]]`,
269
304
  * each with or without a setter (`[[display|target][$x to 1]]`), and SugarCube's
270
305
  * `<<goto "target">>` / `<<link "display" "target">>`, read as SugarCube 2 reads them
271
- * (see `sugarcube-macros.ts`). Links and calls in comments are not read.
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.
272
309
  */
273
310
  links: Map<string, string[]>;
274
- /** Broken links: `{ from, to }` pairs where `to` doesn't exist as a passage. */
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
+ */
275
315
  brokenLinks: BrokenLink[];
276
316
  /** Story passages with no outgoing links (potential dead ends). */
277
317
  deadEnds: string[];
@@ -283,6 +323,11 @@ interface StoryMap {
283
323
  interface BrokenLink {
284
324
  from: string;
285
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;
286
331
  }
287
332
  /**
288
333
  * Inspect a story and return its full structural map.
@@ -299,8 +344,13 @@ interface BrokenLink {
299
344
  * expect(map.brokenLinks).toEqual([]);
300
345
  * expect(map.deadEnds).not.toContain('Start');
301
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.
302
352
  */
303
- export declare function storyInspect(story: ReadonlyStory): StoryMap;
353
+ export declare function storyInspect(story: ReadonlyStory, options?: InspectOptions): StoryMap;
304
354
  //#endregion
305
355
  //#region src/story.d.ts
306
356
  /**
@@ -327,8 +377,9 @@ interface DecompileResult {
327
377
  }
328
378
  /**
329
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.
330
381
  */
331
- export declare function decompileHTML(html: string): DecompileResult;
382
+ export declare function decompileHTML(html: string, options?: DecompileOptions): DecompileResult;
332
383
  //#endregion
333
384
  //#region src/lint.d.ts
334
385
  interface LintResult {
@@ -348,7 +399,11 @@ interface LintResult {
348
399
  storyPassages: number;
349
400
  /** Info/special passage count. */
350
401
  infoPassages: number;
351
- /** Broken links: link targets that don't exist as passages. */
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
+ */
352
407
  brokenLinks: BrokenLink[];
353
408
  /** Story passages with no outgoing links. */
354
409
  deadEnds: string[];
@@ -358,7 +413,9 @@ interface LintResult {
358
413
  /**
359
414
  * Lint a story: compile without output rendering, then inspect structure.
360
415
  * Uses JSON output mode internally to avoid format resolution, so it checks
361
- * the starting passage itself, against the Twine 2 passage rules.
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.
362
419
  */
363
420
  export declare function lint(options: Omit<CompileOptions, 'outputMode'>): Promise<LintResult>;
364
421
  /**
@@ -501,4 +558,4 @@ export declare function getCacheSize(): {
501
558
  count: number;
502
559
  };
503
560
  //#endregion
504
- 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 };