extwee 2.2.2 → 2.2.4
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/build/extwee +0 -0
- package/build/extwee.web.min.js +1 -1
- package/eslint.config.js +19 -0
- package/jest.config.json +5 -0
- package/package.json +24 -27
- package/src/JSON/parse.js +1 -1
- package/src/Story.js +30 -25
- package/src/StoryFormat/parse.js +2 -2
- package/src/TWS/parse.js +2 -1
- package/src/Twee/parse.js +3 -1
- package/test/{Passage.test.js → Objects/Passage.test.js} +4 -4
- package/test/{Story.test.js → Objects/Story.test.js} +39 -14
- package/test/{StoryFormat.test.js → Objects/StoryFormat.test.js} +2 -2
- package/test/TWS/Parse.test.js +3 -3
- package/test/Twee/Twee.Parse.test.js +17 -0
- package/test/Twee/TweeParser/cursed.twee +16 -0
- package/test/Twee/TweeParser/malformed.twee +2 -0
- package/test/Twee/TweeParser/start.twee +2 -0
- package/types/IFID/generate.d.ts +14 -0
- package/types/JSON/parse.d.ts +51 -0
- package/types/Passage.d.ts +117 -0
- package/types/Story.d.ts +230 -0
- package/types/StoryFormat/parse.d.ts +50 -0
- package/types/StoryFormat.d.ts +121 -0
- package/types/TWS/parse.d.ts +10 -0
- package/types/Twee/parse.d.ts +9 -0
- package/types/Twine1HTML/compile.d.ts +19 -0
- package/types/Twine1HTML/parse.d.ts +9 -0
- package/types/Twine2ArchiveHTML/compile.d.ts +14 -0
- package/types/Twine2ArchiveHTML/parse.d.ts +36 -0
- package/types/Twine2HTML/compile.d.ts +14 -0
- package/types/Twine2HTML/parse.d.ts +20 -0
- package/.eslintrc.json +0 -25
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passage class.
|
|
3
|
+
* @class
|
|
4
|
+
* @classdesc Represents a passage in a Twine story.
|
|
5
|
+
* @property {string} name - Name of the passage.
|
|
6
|
+
* @property {Array} tags - Tags for the passage.
|
|
7
|
+
* @property {object} metadata - Metadata for the passage.
|
|
8
|
+
* @property {string} text - Text content of the passage.
|
|
9
|
+
* @method {string} toTwee - Return a Twee representation.
|
|
10
|
+
* @method {string} toJSON - Return JSON representation.
|
|
11
|
+
* @method {string} toTwine2HTML - Return Twine 2 HTML representation.
|
|
12
|
+
* @method {string} toTwine1HTML - Return Twine 1 HTML representation.
|
|
13
|
+
* @example
|
|
14
|
+
* const p = new Passage('Start', 'This is the start of the story.');
|
|
15
|
+
* console.log(p.toTwee());
|
|
16
|
+
* // :: Start
|
|
17
|
+
* // This is the start of the story.
|
|
18
|
+
* //
|
|
19
|
+
* console.log(p.toJSON());
|
|
20
|
+
* // {"name":"Start","tags":[],"metadata":{},"text":"This is the start of the story."}
|
|
21
|
+
* console.log(p.toTwine2HTML());
|
|
22
|
+
* // <tw-passagedata pid="1" name="Start" tags="" >This is the start of the story.</tw-passagedata>
|
|
23
|
+
* console.log(p.toTwine1HTML());
|
|
24
|
+
* // <div tiddler="Start" tags="" modifier="extwee" twine-position="10,10">This is the start of the story.</div>
|
|
25
|
+
* @example
|
|
26
|
+
* const p = new Passage('Start', 'This is the start of the story.', ['start', 'beginning'], {position: '10,10', size: '100,100'});
|
|
27
|
+
* console.log(p.toTwee());
|
|
28
|
+
* // :: Start [start beginning] {"position":"10,10","size":"100,100"}
|
|
29
|
+
* // This is the start of the story.
|
|
30
|
+
* //
|
|
31
|
+
* console.log(p.toJSON());
|
|
32
|
+
* // {"name":"Start","tags":["start","beginning"],"metadata":{"position":"10,10","size":"100,100"},"text":"This is the start of the story."}
|
|
33
|
+
* console.log(p.toTwine2HTML());
|
|
34
|
+
* // <tw-passagedata pid="1" name="Start" tags="start beginning" position="10,10" size="100,100">This is the start of the story.</tw-passagedata>
|
|
35
|
+
* console.log(p.toTwine1HTML());
|
|
36
|
+
* // <div tiddler="Start" tags="start beginning" modifier="extwee" twine-position="10,10">This is the start of the story.</div>
|
|
37
|
+
*/
|
|
38
|
+
export default class Passage {
|
|
39
|
+
/**
|
|
40
|
+
* Create a passage.
|
|
41
|
+
* @param {string} name - Name
|
|
42
|
+
* @param {string} text - Content
|
|
43
|
+
* @param {Array} tags - Tags
|
|
44
|
+
* @param {object} metadata - Metadata
|
|
45
|
+
*/
|
|
46
|
+
constructor(name?: string, text?: string, tags?: any[], metadata?: object);
|
|
47
|
+
/**
|
|
48
|
+
* @param {string} s - Name to replace
|
|
49
|
+
* @throws {Error} Name must be a String!
|
|
50
|
+
*/
|
|
51
|
+
set name(s: string);
|
|
52
|
+
/**
|
|
53
|
+
* Name
|
|
54
|
+
* @returns {string} Name
|
|
55
|
+
*/
|
|
56
|
+
get name(): string;
|
|
57
|
+
/**
|
|
58
|
+
* @param {Array} t - Replacement array
|
|
59
|
+
* @throws {Error} Tags must be an array!
|
|
60
|
+
*/
|
|
61
|
+
set tags(t: any[]);
|
|
62
|
+
/**
|
|
63
|
+
* Tags
|
|
64
|
+
* @returns {Array} Tags
|
|
65
|
+
*/
|
|
66
|
+
get tags(): any[];
|
|
67
|
+
/**
|
|
68
|
+
* @param {object} m - Replacement object
|
|
69
|
+
* @throws {Error} Metadata must be an object literal!
|
|
70
|
+
*/
|
|
71
|
+
set metadata(m: any);
|
|
72
|
+
/**
|
|
73
|
+
* Metadata
|
|
74
|
+
* @returns {object} Metadata
|
|
75
|
+
*/
|
|
76
|
+
get metadata(): any;
|
|
77
|
+
/**
|
|
78
|
+
* @param {string} t - Replacement text
|
|
79
|
+
* @throws {Error} Text should be a String!
|
|
80
|
+
*/
|
|
81
|
+
set text(t: string);
|
|
82
|
+
/**
|
|
83
|
+
* Text
|
|
84
|
+
* @returns {string} Text
|
|
85
|
+
*/
|
|
86
|
+
get text(): string;
|
|
87
|
+
/**
|
|
88
|
+
* Return a Twee representation.
|
|
89
|
+
*
|
|
90
|
+
* See: https://github.com/iftechfoundation/twine-specs/blob/master/twee-3-specification.md
|
|
91
|
+
*
|
|
92
|
+
* @method toTwee
|
|
93
|
+
* @returns {string} String form of passage.
|
|
94
|
+
*/
|
|
95
|
+
toTwee(): string;
|
|
96
|
+
/**
|
|
97
|
+
* Return JSON representation.
|
|
98
|
+
* @method toJSON
|
|
99
|
+
* @returns {string} JSON string.
|
|
100
|
+
*/
|
|
101
|
+
toJSON(): string;
|
|
102
|
+
/**
|
|
103
|
+
* Return Twine 2 HTML representation.
|
|
104
|
+
* (Default Passage ID is 1.)
|
|
105
|
+
* @method toTwine2HTML
|
|
106
|
+
* @param {number} pid - Passage ID (PID) to record in HTML.
|
|
107
|
+
* @returns {string} Twine 2 HTML string.
|
|
108
|
+
*/
|
|
109
|
+
toTwine2HTML(pid?: number): string;
|
|
110
|
+
/**
|
|
111
|
+
* Return Twine 1 HTML representation.
|
|
112
|
+
* @method toTwine1HTML
|
|
113
|
+
* @returns {string} Twine 1 HTML string.
|
|
114
|
+
*/
|
|
115
|
+
toTwine1HTML(): string;
|
|
116
|
+
#private;
|
|
117
|
+
}
|
package/types/Story.d.ts
ADDED
|
@@ -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.4";
|
|
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';
|