extwee 2.2.1 → 2.2.3

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 (68) hide show
  1. package/.eslintrc.json +7 -13
  2. package/.github/codeql-analysis.yml +51 -0
  3. package/README.md +9 -3
  4. package/build/extwee +0 -0
  5. package/build/extwee.web.min.js +1 -1
  6. package/docs/objects/story.md +1 -2
  7. package/index.js +2 -0
  8. package/jest.config.json +5 -0
  9. package/package.json +24 -21
  10. package/src/IFID/generate.js +20 -0
  11. package/src/JSON/parse.js +43 -0
  12. package/src/Passage.js +52 -3
  13. package/src/Story.js +266 -107
  14. package/src/StoryFormat/parse.js +190 -80
  15. package/src/StoryFormat.js +78 -88
  16. package/src/TWS/parse.js +2 -2
  17. package/src/Twee/parse.js +2 -3
  18. package/src/Twine1HTML/compile.js +2 -0
  19. package/src/Twine1HTML/parse.js +2 -3
  20. package/src/Twine2ArchiveHTML/compile.js +8 -0
  21. package/src/Twine2ArchiveHTML/parse.js +33 -3
  22. package/src/Twine2HTML/compile.js +31 -6
  23. package/src/Twine2HTML/parse.js +49 -54
  24. package/test/IFID/IFID.Generate.test.js +10 -0
  25. package/test/JSON/JSON.Parse.test.js +4 -4
  26. package/test/{Passage.test.js → Objects/Passage.test.js} +4 -4
  27. package/test/{Story.test.js → Objects/Story.test.js} +259 -50
  28. package/test/{StoryFormat.test.js → Objects/StoryFormat.test.js} +10 -3
  29. package/test/StoryFormat/StoryFormat.Parse.test.js +442 -55
  30. package/test/TWS/Parse.test.js +1 -1
  31. package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.test.js +20 -4
  32. package/test/Twine2HTML/Twine2HTML.Compile.test.js +35 -120
  33. package/test/Twine2HTML/Twine2HTML.Parse.test.js +57 -38
  34. package/test/Twine2HTML/Twine2HTMLCompiler/format.js +9 -0
  35. package/test/Twine2HTML/Twine2HTMLParser/missingZoom.html +1 -1
  36. package/types/IFID/generate.d.ts +14 -0
  37. package/types/JSON/parse.d.ts +51 -0
  38. package/types/Passage.d.ts +117 -0
  39. package/types/Story.d.ts +230 -0
  40. package/types/StoryFormat/parse.d.ts +50 -0
  41. package/types/StoryFormat.d.ts +121 -0
  42. package/types/TWS/parse.d.ts +10 -0
  43. package/types/Twee/parse.d.ts +9 -0
  44. package/types/Twine1HTML/compile.d.ts +19 -0
  45. package/types/Twine1HTML/parse.d.ts +9 -0
  46. package/types/Twine2ArchiveHTML/compile.d.ts +14 -0
  47. package/types/Twine2ArchiveHTML/parse.d.ts +36 -0
  48. package/types/Twine2HTML/compile.d.ts +14 -0
  49. package/types/Twine2HTML/parse.d.ts +20 -0
  50. package/web-index.js +2 -0
  51. package/test/StoryFormat/StoryFormatParser/example.js +0 -3
  52. package/test/StoryFormat/StoryFormatParser/example2.js +0 -3
  53. package/test/StoryFormat/StoryFormatParser/format.js +0 -1
  54. package/test/StoryFormat/StoryFormatParser/format_doublename.js +0 -1
  55. package/test/StoryFormat/StoryFormatParser/harlowe.js +0 -3
  56. package/test/StoryFormat/StoryFormatParser/missingAuthor.js +0 -1
  57. package/test/StoryFormat/StoryFormatParser/missingDescription.js +0 -1
  58. package/test/StoryFormat/StoryFormatParser/missingImage.js +0 -1
  59. package/test/StoryFormat/StoryFormatParser/missingLicense.js +0 -1
  60. package/test/StoryFormat/StoryFormatParser/missingName.js +0 -1
  61. package/test/StoryFormat/StoryFormatParser/missingProofing.js +0 -1
  62. package/test/StoryFormat/StoryFormatParser/missingSource.js +0 -1
  63. package/test/StoryFormat/StoryFormatParser/missingURL.js +0 -1
  64. package/test/StoryFormat/StoryFormatParser/missingVersion.js +0 -1
  65. package/test/StoryFormat/StoryFormatParser/versionWrong.js +0 -1
  66. package/test/Twine2HTML/Twine2HTMLParser/missingName.html +0 -33
  67. package/test/Twine2HTML/Twine2HTMLParser/missingPID.html +0 -15
  68. package/test/Twine2HTML/Twine2HTMLParser/missingPassageName.html +0 -15
@@ -0,0 +1,230 @@
1
+ /**
2
+ * Story class.
3
+ * @class
4
+ * @classdesc Represents a Twine story.
5
+ * @property {string} name - Name of the story.
6
+ * @property {string} IFID - Interactive Fiction ID (IFID) of Story.
7
+ * @property {string} start - Name of start passage.
8
+ * @property {string} format - Story format of Story.
9
+ * @property {string} formatVersion - Story format version of Story.
10
+ * @property {number} zoom - Zoom level.
11
+ * @property {Array} passages - Array of Passage objects. @see {@link Passage}
12
+ * @property {string} creator - Program used to create Story.
13
+ * @property {string} creatorVersion - Version used to create Story.
14
+ * @property {object} metadata - Metadata of Story.
15
+ * @property {object} tagColors - Tag Colors
16
+ * @method {number} addPassage - Add a passage to the story and returns the new length of the passages array.
17
+ * @method {number} removePassageByName - Remove a passage from the story by name and returns the new length of the passages array.
18
+ * @method {Array} getPassagesByTag - Find passages by tag.
19
+ * @method {Array} getPassageByName - Find passage by name.
20
+ * @method {number} size - Size (number of passages).
21
+ * @method {string} toJSON - Export Story as JSON representation.
22
+ * @method {string} toTwee - Return Twee representation.
23
+ * @method {string} toTwine2HTML - Return Twine 2 HTML representation.
24
+ * @method {string} toTwine1HTML - Return Twine 1 HTML representation.
25
+ * @example
26
+ * const story = new Story('My Story');
27
+ * story.IFID = '12345678-1234-5678-1234-567812345678';
28
+ * story.start = 'Start';
29
+ * story.format = 'SugarCube';
30
+ * story.formatVersion = '2.31.0';
31
+ * story.zoom = 1;
32
+ * story.creator = 'extwee';
33
+ * story.creatorVersion = '2.2.1';
34
+ */
35
+ export class Story {
36
+ /**
37
+ * Creates a story.
38
+ * @param {string} name - Name of the story.
39
+ */
40
+ constructor(name?: string);
41
+ /**
42
+ * @param {string} a - Replacement story name
43
+ */
44
+ set name(a: string);
45
+ /**
46
+ * Each story has a name
47
+ * @returns {string} Name
48
+ */
49
+ get name(): string;
50
+ /**
51
+ * @param {object} a - Replacement tag colors
52
+ */
53
+ set tagColors(a: any);
54
+ /**
55
+ * Tag Colors object (each property is a tag and its color)
56
+ * @returns {object} tag colors array
57
+ */
58
+ get tagColors(): any;
59
+ /**
60
+ * @param {string} i - Replacement IFID.
61
+ */
62
+ set IFID(i: string);
63
+ /**
64
+ * Interactive Fiction ID (IFID) of Story.
65
+ * @returns {string} IFID
66
+ */
67
+ get IFID(): string;
68
+ /**
69
+ * @param {string} s - Replacement start
70
+ */
71
+ set start(s: string);
72
+ /**
73
+ * Name of start passage.
74
+ * @returns {string} start
75
+ */
76
+ get start(): string;
77
+ /**
78
+ * @param {string} f - Replacement format version
79
+ */
80
+ set formatVersion(f: string);
81
+ /**
82
+ * Story format version of Story.
83
+ * @returns {string} story format version
84
+ */
85
+ get formatVersion(): string;
86
+ /**
87
+ * @param {object} o - Replacement metadata
88
+ */
89
+ set metadata(o: any);
90
+ /**
91
+ * Metadata of Story.
92
+ * @returns {object} metadata of story
93
+ */
94
+ get metadata(): any;
95
+ /**
96
+ * @param {string} f - Replacement format
97
+ */
98
+ set format(f: string);
99
+ /**
100
+ * Story format of Story.
101
+ * @returns {string} format
102
+ */
103
+ get format(): string;
104
+ /**
105
+ * @param {string} c - Creator Program of Story
106
+ */
107
+ set creator(c: string);
108
+ /**
109
+ * Program used to create Story.
110
+ * @returns {string} Creator Program
111
+ */
112
+ get creator(): string;
113
+ /**
114
+ * @param {string} c - Version of creator program
115
+ */
116
+ set creatorVersion(c: string);
117
+ /**
118
+ * Version used to create Story.
119
+ * @returns {string} Version
120
+ */
121
+ get creatorVersion(): string;
122
+ /**
123
+ * @param {number} n - Replacement zoom level
124
+ */
125
+ set zoom(n: number);
126
+ /**
127
+ * Zoom level.
128
+ * @returns {number} Zoom level
129
+ */
130
+ get zoom(): number;
131
+ /**
132
+ * Set passages in Story.
133
+ * @param {Array} p - Replacement passages
134
+ * @property {Array} passages - Passages
135
+ * @throws {Error} Passages must be an Array!
136
+ * @throws {Error} Passages must be an Array of Passage objects!
137
+ */
138
+ set passages(p: any[]);
139
+ /**
140
+ * Passages in Story.
141
+ * @returns {Array} Passages
142
+ * @property {Array} passages - Passages
143
+ */
144
+ get passages(): any[];
145
+ /**
146
+ * Add a passage to the story.
147
+ * Passing `StoryData` will override story metadata and `StoryTitle` will override story name.
148
+ * @method addPassage
149
+ * @param {Passage} p - Passage to add to Story.
150
+ * @returns {number} Return new length of passages array.
151
+ */
152
+ addPassage(p: Passage): number;
153
+ /**
154
+ * Remove a passage from the story by name.
155
+ * @method removePassageByName
156
+ * @param {string} name - Passage name to remove.
157
+ * @returns {number} Return new length of passages array.
158
+ */
159
+ removePassageByName(name: string): number;
160
+ /**
161
+ * Find passages by tag.
162
+ * @method getPassagesByTag
163
+ * @param {string} t - Passage name to search for
164
+ * @returns {Array} Return array of passages
165
+ */
166
+ getPassagesByTag(t: string): any[];
167
+ /**
168
+ * Find passage by name.
169
+ * @method getPassageByName
170
+ * @param {string} name - Passage name to search for
171
+ * @returns {Passage | null} Return passage or null
172
+ */
173
+ getPassageByName(name: string): Passage | null;
174
+ /**
175
+ * Size (number of passages).
176
+ * @method size
177
+ * @returns {number} Return number of passages
178
+ */
179
+ size(): number;
180
+ /**
181
+ * Export Story as JSON representation.
182
+ * @method toJSON
183
+ * @returns {string} JSON string.
184
+ */
185
+ toJSON(): string;
186
+ /**
187
+ * Return Twee representation.
188
+ *
189
+ * See: Twee 3 Specification
190
+ * (https://github.com/iftechfoundation/twine-specs/blob/master/twee-3-specification.md)
191
+ *
192
+ * @method toTwee
193
+ * @returns {string} Twee String
194
+ */
195
+ toTwee(): string;
196
+ /**
197
+ * Return Twine 2 HTML.
198
+ *
199
+ * See: Twine 2 HTML Output
200
+ * (https://github.com/iftechfoundation/twine-specs/blob/master/twine-2-htmloutput-spec.md)
201
+ *
202
+ * The only required attributes are `name` and `ifid` of the `<tw-storydata>` element. All others are optional.
203
+ *
204
+ * The `<tw-storydata>` element may have any number of optional attributes, which are:
205
+ * - `startnode`: (integer) Optional. The PID of the starting passage.
206
+ * - `creator`: (string) Optional. The name of the program that created the story.
207
+ * - `creator-version`: (string) Optional. The version of the program that created the story.
208
+ * - `zoom`: (decimal) Optional. The zoom level of the story.
209
+ * - `format`: (string) Optional. The format of the story.
210
+ * - `format-version`: (string) Optional. The version of the format of the story.
211
+ *
212
+ * @method toTwine2HTML
213
+ * @returns {string} Twine 2 HTML string
214
+ */
215
+ toTwine2HTML(): string;
216
+ /**
217
+ * Return Twine 1 HTML.
218
+ *
219
+ * See: Twine 1 HTML Output
220
+ * (https://github.com/iftechfoundation/twine-specs/blob/master/twine-1-htmloutput-doc.md)
221
+ *
222
+ * @method toTwine1HTML
223
+ * @returns {string} Twine 1 HTML string.
224
+ */
225
+ toTwine1HTML(): string;
226
+ #private;
227
+ }
228
+ export const creatorName: "extwee";
229
+ export const creatorVersion: "2.2.3";
230
+ import Passage from './Passage.js';
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Parses story format content into a {@link StoryFormat} object.
3
+ *
4
+ * Story formats are generally JSONP files containing a JSON object with the following properties:
5
+ * - name: (string) Optional. (Omitting the name will lead to an Untitled Story Format.)
6
+ * - version: (string) Required, and semantic version-style formatting (x.y.z, e.g., 1.2.1) of the version is also required.
7
+ * - author: (string) Optional.
8
+ * - description: (string) Optional.
9
+ * - image: (string) Optional.
10
+ * - url: (string) Optional.
11
+ * - license: (string) Optional.
12
+ * - proofing: (boolean) Optional (defaults to false).
13
+ * - source: (string) Required.
14
+ *
15
+ * If existing properties do not match their expected type, a warning will be produced and incoming value will be ignored.
16
+ *
17
+ * This function does "soft parsing." It will not throw an error if a specific property is missing or malformed.
18
+ * @see {@link https://github.com/iftechfoundation/twine-specs/blob/master/twine-2-storyformats-spec.md Twine 2 Story Formats Specification}
19
+ * @function parse
20
+ * @param {string} contents - JSONP content.
21
+ * @throws {Error} - Unable to find Twine 2 JSON chunk!
22
+ * @throws {Error} - Unable to parse Twine 2 JSON chunk!
23
+ * @returns {StoryFormat} StoryFormat object.
24
+ * @example
25
+ * const contents = `{
26
+ * "name": "My Story Format",
27
+ * "version": "1.0.0",
28
+ * "author": "Twine",
29
+ * "description": "A story format.",
30
+ * "image": "icon.svg",
31
+ * "url": "https://example.com",
32
+ * "license": "MIT",
33
+ * "proofing": false,
34
+ * "source": "<html></html>"
35
+ * }`;
36
+ * const storyFormat = parse(contents);
37
+ * console.log(storyFormat);
38
+ * // => StoryFormat {
39
+ * // name: 'My Story Format',
40
+ * // version: '1.0.0',
41
+ * // description: 'A story format.',
42
+ * // image: 'icon.svg',
43
+ * // url: 'https://example.com',
44
+ * // license: 'MIT',
45
+ * // proofing: false,
46
+ * // source: '<html></html>'
47
+ * // }
48
+ */
49
+ export function parse(contents: string): StoryFormat;
50
+ import StoryFormat from '../StoryFormat.js';
@@ -0,0 +1,121 @@
1
+ /**
2
+ * StoryFormat representing a Twine 2 story format.
3
+ *
4
+ * This class has type checking on all of its properties.
5
+ * If a property is set to a value of the wrong type, a TypeError will be thrown.
6
+ *
7
+ * @see {@link https://github.com/iftechfoundation/twine-specs/blob/master/twine-2-storyformats-spec.md Twine 2 Story Formats Specification}
8
+ *
9
+ * @class
10
+ * @classdesc A class representing a Twine 2 story format.
11
+ * @property {string} name - The name of the story format.
12
+ * @property {string} version - The semantic version of the story format.
13
+ * @property {string} description - The description of the story format.
14
+ * @property {string} author - The author of the story format.
15
+ * @property {string} image - The image of the story format.
16
+ * @property {string} url - The URL of the story format.
17
+ * @property {string} license - The license of the story format.
18
+ * @property {boolean} proofing - The proofing of the story format.
19
+ * @property {string} source - The source of the story format.
20
+ * @example
21
+ * const sf = new StoryFormat();
22
+ * sf.name = 'New';
23
+ * sf.version = '1.0.0';
24
+ * sf.description = 'New';
25
+ * sf.author = 'New';
26
+ * sf.image = 'New';
27
+ * sf.url = 'New';
28
+ * sf.license = 'New';
29
+ * sf.proofing = true;
30
+ * sf.source = 'New';
31
+ */
32
+ export default class StoryFormat {
33
+ /**
34
+ * @param {string} n - Replacement name.
35
+ */
36
+ set name(n: string);
37
+ /**
38
+ * Name
39
+ * @returns {string} Name.
40
+ */
41
+ get name(): string;
42
+ /**
43
+ * @param {string} n - Replacement version.
44
+ */
45
+ set version(n: string);
46
+ /**
47
+ * Version.
48
+ * @returns {string} Version.
49
+ */
50
+ get version(): string;
51
+ /**
52
+ * @param {string} d - Replacement description.
53
+ */
54
+ set description(d: string);
55
+ /**
56
+ * Description.
57
+ * @returns {string} Description.
58
+ */
59
+ get description(): string;
60
+ /**
61
+ * @param {string} a - Replacement author.
62
+ */
63
+ set author(a: string);
64
+ /**
65
+ * Author.
66
+ * @returns {string} Author.
67
+ */
68
+ get author(): string;
69
+ /**
70
+ * @param {string} i - Replacement image.
71
+ */
72
+ set image(i: string);
73
+ /**
74
+ * Image.
75
+ * @returns {string} Image.
76
+ */
77
+ get image(): string;
78
+ /**
79
+ * @param {string} u - Replacement URL.
80
+ */
81
+ set url(u: string);
82
+ /**
83
+ * URL.
84
+ * @returns {string} URL.
85
+ */
86
+ get url(): string;
87
+ /**
88
+ * @param {string} l - Replacement license.
89
+ */
90
+ set license(l: string);
91
+ /**
92
+ * License.
93
+ * @returns {string} License.
94
+ */
95
+ get license(): string;
96
+ /**
97
+ * @param {boolean} p - Replacement proofing.
98
+ */
99
+ set proofing(p: boolean);
100
+ /**
101
+ * Proofing.
102
+ * @returns {boolean} Proofing.
103
+ */
104
+ get proofing(): boolean;
105
+ /**
106
+ * @param {string} s - Replacement source.
107
+ */
108
+ set source(s: string);
109
+ /**
110
+ * Source.
111
+ * @returns {string} Source.
112
+ */
113
+ get source(): string;
114
+ /**
115
+ * Produces a string representation of the story format object.
116
+ * @method toString
117
+ * @returns {string} - A string representation of the story format.
118
+ */
119
+ toString(): string;
120
+ #private;
121
+ }
@@ -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
+ * @see {@link https://github.com/iftechfoundation/twine-specs/blob/master/twine-1-htmloutput-doc.md Twine 1 HTML Documentation}
5
+ * @function parse
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,9 @@
1
+ /**
2
+ * Parses Twee 3 text into a Story object.
3
+ * @see {@link https://github.com/iftechfoundation/twine-specs/blob/master/twee-3-specification.md Twee 3 Specification}
4
+ * @function parse
5
+ * @param {string} fileContents - File contents to parse
6
+ * @returns {Story} story
7
+ */
8
+ export function parse(fileContents: string): Story;
9
+ import { Story } from '../Story.js';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Write a combination of Story object, `engine.js` (from Twine 1), `header.html`, and optional `code.js`.
3
+ * @see {@link https://github.com/iftechfoundation/twine-specs/blob/master/twine-1-htmloutput-doc.md Twine 1 HTML Documentation}
4
+ * @function compile
5
+ * @param {Story} story - Story object to write.
6
+ * @param {string} engine - Source of `engine.js` file from Twine 1.
7
+ * @param {string} header - `header.html` content for Twine 1 story format.
8
+ * @param {string} name - Name of the story format (needed for `code.js` inclusion).
9
+ * @param {string} codeJS - `code.js` content with additional JavaScript.
10
+ * @param {object} config - Limited configuration object acting in place of `StorySettings`.
11
+ * @param {string} config.jquery - jQuery source.
12
+ * @param {string} config.modernizr - Modernizr source.
13
+ * @returns {string} Twine 1 HTML.
14
+ */
15
+ export function compile(story: Story, engine?: string, header?: string, name?: string, codeJS?: string, config?: {
16
+ jquery: string;
17
+ modernizr: string;
18
+ }): string;
19
+ import { Story } from '../Story.js';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Parses Twine 1 HTML into a Story object.
3
+ * @see {@link https://github.com/iftechfoundation/twine-specs/blob/master/twine-1-htmloutput-doc.md Twine 1 HTML Documentation}
4
+ * @function parse
5
+ * @param {string} content - Twine 1 HTML content to parse.
6
+ * @returns {Story} Story object
7
+ */
8
+ export function parse(content: string): Story;
9
+ import { Story } from '../Story.js';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Write array of Story objects into Twine 2 Archive HTML.
3
+ * @see {@link https://github.com/iftechfoundation/twine-specs/blob/master/twine-2-archive-spec.md Twine 2 Archive Specification}
4
+ * @function compile
5
+ * @param {Array} stories - Array of Story objects.
6
+ * @returns {string} Twine 2 Archive HTML.
7
+ * @example
8
+ * const story1 = new Story();
9
+ * const story2 = new Story();
10
+ * const stories = [story1, story2];
11
+ * console.log(compile(stories));
12
+ * // => '<tw-storydata name="Untitled" startnode="1" creator="Twine" creator-version="2.3.9" ifid="A1B2C3D4-E5F6-G7H8-I9J0-K1L2M3N4O5P6" zoom="1" format="Harlowe" format-version="3.1.0" options="" hidden><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style><script role="script" id="twine-user-script" type="text/twine-javascript"></script><tw-passagedata pid="1" name="Untitled Passage" tags="" position="0,0" size="100,100"></tw-passagedata></tw-storydata>\n\n<tw-storydata name="Untitled" startnode="1" creator="Twine" creator-version="2.3.9" ifid="A1B2C3D4-E5F6-G7H8-I9J0-K1L2M3N4O5P6" zoom="1" format="Harlowe" format-version="3.1.0" options="" hidden><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style><script role="script" id="twine-user-script" type="text/twine-javascript"></script><tw-passagedata pid="1" name="Untitled Passage" tags="" position="0,0" size="100,100"></tw-passagedata></tw-storydata>\n\n'
13
+ */
14
+ export function compile(stories: any[]): string;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Parse Twine 2 Archive HTML and returns an array of story objects.
3
+ * @see {@link https://github.com/iftechfoundation/twine-specs/blob/master/twine-2-archive-spec.md Twine 2 Archive Specification}
4
+ * @function parse
5
+ * @param {string} content - Content to parse for Twine 2 HTML elements.
6
+ * @throws {TypeError} - Content is not a string!
7
+ * @returns {Array} Array of stories found in content.
8
+ * @example
9
+ * const content = '<tw-storydata name="Untitled" startnode="1" creator="Twine" creator-version="2.3.9" ifid="A1B2C3D4-E5F6-G7H8-I9J0-K1L2M3N4O5P6" zoom="1" format="Harlowe" format-version="3.1.0" options="" hidden><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style><script role="script" id="twine-user-script" type="text/twine-javascript"></script><tw-passagedata pid="1" name="Untitled Passage" tags="" position="0,0" size="100,100"></tw-passagedata></tw-storydata>';
10
+ * console.log(parse(content));
11
+ * // => [
12
+ * // Story {
13
+ * // name: 'Untitled',
14
+ * // startnode: '1',
15
+ * // creator: 'Twine',
16
+ * // creatorVersion: '2.3.9',
17
+ * // ifid: 'A1B2C3D4-E5F6-G7H8-I9J0-K1L2M3N4O5P6',
18
+ * // zoom: '1',
19
+ * // format: 'Harlowe',
20
+ * // formatVersion: '3.1.0',
21
+ * // options: '',
22
+ * // hidden: '',
23
+ * // passages: [
24
+ * // Passage {
25
+ * // pid: '1',
26
+ * // name: 'Untitled Passage',
27
+ * // tags: '',
28
+ * // position: '0,0',
29
+ * // size: '100,100',
30
+ * // text: ''
31
+ * // }
32
+ * // ]
33
+ * // }
34
+ * // ]
35
+ */
36
+ export function parse(content: string): any[];
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Write a combination of Story + StoryFormat into Twine 2 HTML file.
3
+ * @see {@link https://github.com/iftechfoundation/twine-specs/blob/master/twine-2-htmloutput-spec.md Twine 2 HTML Output Specification}
4
+ * @function compile
5
+ * @param {Story} story - Story object to write.
6
+ * @param {StoryFormat} storyFormat - StoryFormat to write.
7
+ * @returns {string} Twine 2 HTML based on StoryFormat and Story.
8
+ * @throws {Error} If story is not instance of Story.
9
+ * @throws {Error} If storyFormat is not instance of StoryFormat.
10
+ * @throws {Error} If storyFormat.source is empty string.
11
+ */
12
+ export function compile(story: Story, storyFormat: StoryFormat): string;
13
+ import { Story } from '../Story.js';
14
+ import StoryFormat from '../StoryFormat.js';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Parse Twine 2 HTML into Story object.
3
+ *
4
+ * See: Twine 2 HTML Output Specification
5
+ * (https://github.com/iftechfoundation/twine-specs/blob/master/twine-2-htmloutput-spec.md)
6
+ *
7
+ * Produces warnings for:
8
+ * - Missing name attribute on `<tw-storydata>` element.
9
+ * - Missing IFID attribute on `<tw-storydata>` element.
10
+ * - Malformed IFID attribute on `<tw-storydata>` element.
11
+ * @function parse
12
+ * @param {string} content - Twine 2 HTML content to parse.
13
+ * @returns {Story} Story object based on Twine 2 HTML content.
14
+ * @throws {TypeError} Content is not a string.
15
+ * @throws {Error} Not Twine 2 HTML content!
16
+ * @throws {Error} Cannot parse passage data without name!
17
+ * @throws {Error} Passages are required to have PID!
18
+ */
19
+ export function parse(content: string): Story;
20
+ import { Story } from '../Story.js';
package/web-index.js CHANGED
@@ -8,6 +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 { generate as generateIFID } from './src/IFID/generate.js';
11
12
  import { Story } from './src/Story.js';
12
13
  import Passage from './src/Passage.js';
13
14
  import StoryFormat from './src/StoryFormat.js';
@@ -23,6 +24,7 @@ window.Extwee = {
23
24
  compileTwine1HTML,
24
25
  compileTwine2HTML,
25
26
  compileTwine2ArchiveHTML,
27
+ generateIFID,
26
28
  Story,
27
29
  Passage,
28
30
  StoryFormat
@@ -1,3 +0,0 @@
1
- [
2
- error
3
- ]
@@ -1,3 +0,0 @@
1
- {
2
- "malformed:
3
- }