extwee 2.2.0 → 2.2.1

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.
Files changed (42) hide show
  1. package/build/extwee +0 -0
  2. package/build/extwee.web.min.js +1 -1
  3. package/docs/_sidebar.md +1 -0
  4. package/docs/examples/dynamicPassages.md +1 -1
  5. package/docs/examples/twsToTwee.md +1 -1
  6. package/index.js +1 -1
  7. package/package.json +15 -12
  8. package/src/JSON/parse.js +1 -1
  9. package/src/Passage.js +9 -28
  10. package/src/Story.js +9 -6
  11. package/src/TWS/parse.js +1 -1
  12. package/src/Twee/parse.js +1 -1
  13. package/src/Twine1HTML/compile.js +1 -1
  14. package/src/Twine1HTML/parse.js +1 -1
  15. package/src/Twine2ArchiveHTML/compile.js +1 -1
  16. package/src/Twine2HTML/compile.js +1 -1
  17. package/src/Twine2HTML/parse.js +5 -4
  18. package/test/JSON/JSON.Parse.test.js +20 -20
  19. package/test/Passage.test.js +69 -0
  20. package/test/Story.test.js +42 -3
  21. package/test/Twine1HTML/Twine1HTML.Compile.test.js +1 -1
  22. package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Compile.test.js +1 -1
  23. package/test/Twine2HTML/Twine2HTML.Compile.test.js +1 -1
  24. package/test/Twine2HTML/Twine2HTML.Parse.test.js +6 -5
  25. package/test/Twine2HTML/Twine2HTMLParser/unescaping.html +33 -0
  26. package/tsconfig.json +21 -0
  27. package/types/index.d.ts +14 -0
  28. package/types/src/JSON/parse.d.ts +8 -0
  29. package/types/src/Passage.d.ts +72 -0
  30. package/types/src/Story.d.ts +161 -0
  31. package/types/src/StoryFormat/parse.d.ts +7 -0
  32. package/types/src/StoryFormat.d.ts +97 -0
  33. package/types/src/TWS/parse.d.ts +10 -0
  34. package/types/src/Twee/parse.d.ts +10 -0
  35. package/types/src/Twine1HTML/compile.d.ts +17 -0
  36. package/types/src/Twine1HTML/parse.d.ts +10 -0
  37. package/types/src/Twine2ArchiveHTML/compile.d.ts +6 -0
  38. package/types/src/Twine2ArchiveHTML/parse.d.ts +6 -0
  39. package/types/src/Twine2HTML/compile.d.ts +9 -0
  40. package/types/src/Twine2HTML/parse.d.ts +17 -0
  41. package/types/src/extwee.d.ts +2 -0
  42. package/web-index.js +1 -1
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ // Change this to match your project
3
+ "include": ["src/**/*"],
4
+ "compilerOptions": {
5
+ // Tells TypeScript to read JS files, as
6
+ // normally they are ignored as source files
7
+ "allowJs": true,
8
+ // Generate d.ts files
9
+ "declaration": true,
10
+ // This compiler run should
11
+ // only output d.ts files
12
+ "emitDeclarationOnly": true,
13
+ // Types should go into this directory.
14
+ // Removing this would place the .d.ts files
15
+ // next to the .js files
16
+ "outDir": "types",
17
+ // go to js file when using IDE functions like
18
+ // "Go to Definition" in VSCode
19
+ "declarationMap": true
20
+ }
21
+ }
@@ -0,0 +1,14 @@
1
+ import { parse as parseTwee } from './src/Twee/parse.js';
2
+ import { parse as parseJSON } from './src/JSON/parse.js';
3
+ import { parse as parseTWS } from './src/TWS/parse.js';
4
+ import { parse as parseStoryFormat } from './src/StoryFormat/parse.js';
5
+ import { parse as parseTwine1HTML } from './src/Twine1HTML/parse.js';
6
+ import { parse as parseTwine2HTML } from './src/Twine2HTML/parse.js';
7
+ import { parse as parseTwine2ArchiveHTML } from './src/Twine2ArchiveHTML/parse.js';
8
+ import { compile as compileTwine1HTML } from './src/Twine1HTML/compile.js';
9
+ import { compile as compileTwine2HTML } from './src/Twine2HTML/compile.js';
10
+ import { compile as compileTwine2ArchiveHTML } from './src/Twine2ArchiveHTML/compile.js';
11
+ import Story from './src/Story.js';
12
+ import Passage from './src/Passage.js';
13
+ import StoryFormat from './src/StoryFormat.js';
14
+ export { parseTwee, parseJSON, parseTWS, parseStoryFormat, parseTwine1HTML, parseTwine2HTML, parseTwine2ArchiveHTML, compileTwine1HTML, compileTwine2HTML, compileTwine2ArchiveHTML, Story, Passage, StoryFormat };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Parse JSON representation into Story.
3
+ * @function parse
4
+ * @param {string} jsonString - JSON string to convert to Story.
5
+ * @returns {Story} Story object.
6
+ */
7
+ export function parse(jsonString: string): Story;
8
+ import Story from '../Story.js';
@@ -0,0 +1,72 @@
1
+ /**
2
+ * A passage is the smallest unit of a Twine story.
3
+ */
4
+ export default class Passage {
5
+ /**
6
+ * Create a passage.
7
+ * @param {string} name - Name
8
+ * @param {string} text - Content
9
+ * @param {Array} tags - Tags
10
+ * @param {object} metadata - Metadata
11
+ */
12
+ constructor(name?: string, text?: string, tags?: any[], metadata?: object);
13
+ /**
14
+ * @param {string} s - Name to replace
15
+ */
16
+ set name(s: string);
17
+ /**
18
+ * Name
19
+ * @returns {string} Name
20
+ */
21
+ get name(): string;
22
+ /**
23
+ * @param {Array} t - Replacement array
24
+ */
25
+ set tags(t: any[]);
26
+ /**
27
+ * Tags
28
+ * @returns {Array} Tags
29
+ */
30
+ get tags(): any[];
31
+ /**
32
+ * @param {object} m - Replacement object
33
+ */
34
+ set metadata(m: any);
35
+ /**
36
+ * Metadata
37
+ * @returns {object} Metadata
38
+ */
39
+ get metadata(): any;
40
+ /**
41
+ * @param {string} t - Replacement text
42
+ */
43
+ set text(t: string);
44
+ /**
45
+ * Text
46
+ * @returns {string} Text
47
+ */
48
+ get text(): string;
49
+ /**
50
+ * Return a Twee representation.
51
+ * @returns {string} String form of passage.
52
+ */
53
+ toTwee(): string;
54
+ /**
55
+ * Return JSON representation.
56
+ * @returns {string} JSON string.
57
+ */
58
+ toJSON(): string;
59
+ /**
60
+ * Return Twine 2 HTML representation.
61
+ * (Default Passage ID is 1.)
62
+ * @param {number} pid - Passage ID (PID) to record in HTML.
63
+ * @returns {string} Twine 2 HTML string.
64
+ */
65
+ toTwine2HTML(pid?: number): string;
66
+ /**
67
+ * Return Twine 1 HTML representation.
68
+ * @returns {string} Twine 1 HTML string.
69
+ */
70
+ toTwine1HTML(): string;
71
+ #private;
72
+ }
@@ -0,0 +1,161 @@
1
+ export default class Story {
2
+ /**
3
+ * Creates a story.
4
+ * @param {string} name - Name of the story.
5
+ */
6
+ constructor(name?: string);
7
+ /**
8
+ * @param {string} a - Replacement story name
9
+ */
10
+ set name(a: string);
11
+ /**
12
+ * Each story has a name
13
+ * @returns {string} Name
14
+ */
15
+ get name(): string;
16
+ /**
17
+ * @param {object} a - Replacement tag colors
18
+ */
19
+ set tagColors(a: any);
20
+ /**
21
+ * Tag Colors object (each property is a tag and its color)
22
+ * @returns {object} tag colors array
23
+ */
24
+ get tagColors(): any;
25
+ /**
26
+ * @param {string} i - Replacement IFID
27
+ */
28
+ set IFID(i: string);
29
+ /**
30
+ * Interactive Fiction ID (IFID) of Story
31
+ * @returns {string} IFID
32
+ */
33
+ get IFID(): string;
34
+ /**
35
+ * @param {string} s - Replacement start
36
+ */
37
+ set start(s: string);
38
+ /**
39
+ * Name of start passage.
40
+ * @returns {string} start
41
+ */
42
+ get start(): string;
43
+ /**
44
+ * @param {string} f - Replacement format version
45
+ */
46
+ set formatVersion(f: string);
47
+ /**
48
+ * Story format version of Story.
49
+ * @returns {string} story format version
50
+ */
51
+ get formatVersion(): string;
52
+ /**
53
+ * @param {object} o - Replacement metadata
54
+ */
55
+ set metadata(o: any);
56
+ /**
57
+ * Metadata of Story.
58
+ * @returns {object} metadata of story
59
+ */
60
+ get metadata(): any;
61
+ /**
62
+ * @param {string} f - Replacement format
63
+ */
64
+ set format(f: string);
65
+ /**
66
+ * Story format of Story.
67
+ * @returns {string} format
68
+ */
69
+ get format(): string;
70
+ /**
71
+ * @param {string} c - Creator Program of Story
72
+ */
73
+ set creator(c: string);
74
+ /**
75
+ * Program used to create Story.
76
+ * @returns {string} Creator Program
77
+ */
78
+ get creator(): string;
79
+ /**
80
+ * @param {string} c - Version of creator program
81
+ */
82
+ set creatorVersion(c: string);
83
+ /**
84
+ * Version used to create Story.
85
+ * @returns {string} Version
86
+ */
87
+ get creatorVersion(): string;
88
+ /**
89
+ * @param {number} n - Replacement zoom level
90
+ */
91
+ set zoom(n: number);
92
+ /**
93
+ * Zoom level.
94
+ * @returns {number} Zoom level
95
+ */
96
+ get zoom(): number;
97
+ /**
98
+ * Add a passage to the story.
99
+ * `StoryData` will override story metadata and `StoryTitle` will override story name.
100
+ * @param {Passage} p - Passage to add to Story.
101
+ */
102
+ addPassage(p: Passage): void;
103
+ /**
104
+ * Remove a passage from the story by name.
105
+ * @param {string} name - Passage name to remove
106
+ */
107
+ removePassageByName(name: string): void;
108
+ /**
109
+ * Find passages by tag.
110
+ * @param {string} t - Passage name to search for
111
+ * @returns {Array} Return array of passages
112
+ */
113
+ getPassagesByTag(t: string): any[];
114
+ /**
115
+ * Find passage by name.
116
+ * @param {string} name - Passage name to search for
117
+ * @returns {Passage | null} Return passage or null
118
+ */
119
+ getPassageByName(name: string): Passage | null;
120
+ /**
121
+ * Size (number of passages).
122
+ * @returns {number} Return number of passages
123
+ */
124
+ size(): number;
125
+ /**
126
+ * forEach-style iterator of passages in Story.
127
+ * @param {Function} callback - Callback function
128
+ */
129
+ forEachPassage(callback: Function): void;
130
+ /**
131
+ * Export Story as JSON representation.
132
+ * @returns {string} JSON string.
133
+ */
134
+ toJSON(): string;
135
+ /**
136
+ * Return Twee representation.
137
+ *
138
+ * See: Twee 3 Specification
139
+ * (https://github.com/iftechfoundation/twine-specs/blob/master/twee-3-specification.md)
140
+ * @returns {string} Twee String
141
+ */
142
+ toTwee(): string;
143
+ /**
144
+ * Return Twine 2 HTML.
145
+ *
146
+ * See: Twine 2 HTML Output
147
+ * (https://github.com/iftechfoundation/twine-specs/blob/master/twine-2-htmloutput-spec.md)
148
+ * @returns {string} Twine 2 HTML string
149
+ */
150
+ toTwine2HTML(): string;
151
+ /**
152
+ * Return Twine 1 HTML.
153
+ *
154
+ * See: Twine 1 HTML Output
155
+ * (https://github.com/iftechfoundation/twine-specs/blob/master/twine-1-htmloutput-doc.md)
156
+ * @returns {string} Twine 1 HTML string.
157
+ */
158
+ toTwine1HTML(): string;
159
+ #private;
160
+ }
161
+ import Passage from './Passage.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Parse a Story Format file.
3
+ * @param {string} contents - Content
4
+ * @returns {StoryFormat} StoryFormat object
5
+ */
6
+ export function parse(contents: string): StoryFormat;
7
+ import StoryFormat from '../StoryFormat.js';
@@ -0,0 +1,97 @@
1
+ export default class StoryFormat {
2
+ /**
3
+ * Create a story format.
4
+ * @param {string} name - Name
5
+ * @param {string} version - Version
6
+ * @param {string} description - Description
7
+ * @param {string} author - Author
8
+ * @param {string} image - Image
9
+ * @param {string} url - URL
10
+ * @param {string} license - License
11
+ * @param {boolean} proofing - If proofing or not
12
+ * @param {string} source - Source
13
+ */
14
+ constructor(name?: string, version?: string, description?: string, author?: string, image?: string, url?: string, license?: string, proofing?: boolean, source?: string);
15
+ /**
16
+ * @param {string} n - Replacement name
17
+ */
18
+ set name(n: string);
19
+ /**
20
+ * Name
21
+ * @returns {string} Name
22
+ */
23
+ get name(): string;
24
+ /**
25
+ * @param {string} n - Replacement version
26
+ */
27
+ set version(n: string);
28
+ /**
29
+ * Version
30
+ * @returns {string} Version
31
+ */
32
+ get version(): string;
33
+ /**
34
+ * @param {string} d - Replacement description
35
+ */
36
+ set description(d: string);
37
+ /**
38
+ * Description
39
+ * @returns {string} Description
40
+ */
41
+ get description(): string;
42
+ /**
43
+ * @param {string} a - Replacement author
44
+ */
45
+ set author(a: string);
46
+ /**
47
+ * Author
48
+ * @returns {string} Author
49
+ */
50
+ get author(): string;
51
+ /**
52
+ * @param {string} i - Replacement image
53
+ */
54
+ set image(i: string);
55
+ /**
56
+ * Image
57
+ * @returns {string} Image
58
+ */
59
+ get image(): string;
60
+ /**
61
+ * @param {string} u - Replacement URL
62
+ */
63
+ set url(u: string);
64
+ /**
65
+ * URL
66
+ * @returns {string} URL
67
+ */
68
+ get url(): string;
69
+ /**
70
+ * @param {string} l - Replacement license
71
+ */
72
+ set license(l: string);
73
+ /**
74
+ * License
75
+ * @returns {string} License
76
+ */
77
+ get license(): string;
78
+ /**
79
+ * @param {boolean} p - Replacement proofing
80
+ */
81
+ set proofing(p: boolean);
82
+ /**
83
+ * Proofing
84
+ * @returns {boolean} Proofing
85
+ */
86
+ get proofing(): boolean;
87
+ /**
88
+ * @param {string} s - Replacement source
89
+ */
90
+ set source(s: string);
91
+ /**
92
+ * Source
93
+ * @returns {string} Source
94
+ */
95
+ get source(): string;
96
+ #private;
97
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Parse TWS file (as Buffer) into Story.
3
+ * Unless it throws an error, it will return a Story object.
4
+ *
5
+ * See: Twine 1 TWS Documentation [Approval Pending]
6
+ * @param {Buffer} binaryFileContents - File contents to parse as Buffer.
7
+ * @returns {Story} Story object.
8
+ */
9
+ export function parse(binaryFileContents: Buffer): Story;
10
+ import Story from '../Story.js';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Parses Twee 3 text into a Story object.
3
+ *
4
+ * See: Twee 3 Specification
5
+ * (https://github.com/iftechfoundation/twine-specs/blob/master/twee-3-specification.md)
6
+ * @param {string} fileContents - File contents to parse
7
+ * @returns {Story} story
8
+ */
9
+ export function parse(fileContents: string): Story;
10
+ import Story from '../Story.js';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Write a combination of Story object, `engine.js` (from Twine 1), `header.html`, and optional `code.js`.
3
+ * @param {Story} story - Story object to write.
4
+ * @param {string} engine - Source of `engine.js` file from Twine 1.
5
+ * @param {string} header - `header.html` content for Twine 1 story format.
6
+ * @param {string} name - Name of the story format (needed for `code.js` inclusion).
7
+ * @param {string} codeJS - `code.js` content with additional JavaScript.
8
+ * @param {object} config - Limited configuration object acting in place of `StorySettings`.
9
+ * @param {string} config.jquery - jQuery source.
10
+ * @param {string} config.modernizr - Modernizr source.
11
+ * @returns {string} Twine 1 HTML.
12
+ */
13
+ export function compile(story: Story, engine?: string, header?: string, name?: string, codeJS?: string, config?: {
14
+ jquery: string;
15
+ modernizr: string;
16
+ }): string;
17
+ import Story from '../Story.js';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Parses Twine 1 HTML into a Story object.
3
+ *
4
+ * See: Twine 1 HTML Output Documentation
5
+ * (https://github.com/iftechfoundation/twine-specs/blob/master/twine-1-htmloutput-doc.md)
6
+ * @param {string} content - Twine 1 HTML content to parse.
7
+ * @returns {Story} Story object
8
+ */
9
+ export function parse(content: string): Story;
10
+ import Story from '../Story.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Write array of Story objects into Twine 2 Archive HTML.
3
+ * @param {Array} stories - Array of Story objects.
4
+ * @returns {string} Twine 2 Archive HTML.
5
+ */
6
+ export function compile(stories: any[]): string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Parse HTML for one or more Twine 2 HTML elements and return array of story objects.
3
+ * @param {string} content - Content to parse for Twine 2 HTML elements.
4
+ * @returns {Array} Array of stories found in content.
5
+ */
6
+ export function parse(content: string): any[];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Write a combination of Story + StoryFormat into Twine 2 HTML file.
3
+ * @param {Story} story - Story object to write.
4
+ * @param {StoryFormat} storyFormat - StoryFormat to write.
5
+ * @returns {string} Twine 2 HTML.
6
+ */
7
+ export function compile(story: Story, storyFormat: StoryFormat): string;
8
+ import Story from '../Story.js';
9
+ import StoryFormat from '../StoryFormat.js';
@@ -0,0 +1,17 @@
1
+ export default parse;
2
+ /**
3
+ * Parse Twine 2 HTML into Story object.
4
+ *
5
+ * See: Twine 2 HTML Output Specification
6
+ * (https://github.com/iftechfoundation/twine-specs/blob/master/twine-2-htmloutput-spec.md)
7
+ * @param {string} content - Twine 2 HTML content to parse.
8
+ * @returns {Story} Story
9
+ */
10
+ export function parse(content: string): Story;
11
+ /**
12
+ * Try to escape Twine 2 meta-characters.
13
+ * @param {string} result - Text to parse.
14
+ * @returns {string} Escaped characters.
15
+ */
16
+ export function escapeMetacharacters(result: string): string;
17
+ import Story from '../Story.js';
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/web-index.js CHANGED
@@ -8,7 +8,7 @@ import { parse as parseTWS } from './src/TWS/parse.js';
8
8
  import { compile as compileTwine1HTML } from './src/Twine1HTML/compile.js';
9
9
  import { compile as compileTwine2HTML } from './src/Twine2HTML/compile.js';
10
10
  import { compile as compileTwine2ArchiveHTML } from './src/Twine2ArchiveHTML/compile.js';
11
- import Story from './src/Story.js';
11
+ import { Story } from './src/Story.js';
12
12
  import Passage from './src/Passage.js';
13
13
  import StoryFormat from './src/StoryFormat.js';
14
14