extwee 2.0.6 → 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.
- package/.eslintrc.json +25 -25
- package/.github/FUNDING.yml +3 -0
- package/.github/dependabot.yml +11 -0
- package/.github/workflows/nodejs.yml +25 -24
- package/.travis.yml +13 -13
- package/CODE_OF_CONDUCT.md +82 -82
- package/LICENSE +21 -21
- package/README.md +173 -36
- package/SECURITY.md +12 -12
- package/babel.config.json +18 -22
- package/build/extwee +0 -0
- package/build/extwee.exe +0 -0
- package/build/extwee.web.min.js +2 -0
- package/build/extwee.web.min.js.LICENSE.txt +1 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +167 -0
- package/docs/_sidebar.md +20 -0
- package/docs/examples/dynamicPassages.md +28 -0
- package/docs/examples/jsonToTwee.md +23 -0
- package/docs/examples/twsToTwee.md +25 -0
- package/docs/formats/json.md +17 -0
- package/docs/formats/twee.md +13 -0
- package/docs/formats/twine1HTML.md +13 -0
- package/docs/formats/twine2ArchiveHTML.md +13 -0
- package/docs/formats/twine2HTML.md +13 -0
- package/docs/formats/tws.md +9 -0
- package/docs/index.html +26 -0
- package/docs/install/binaries.md +9 -0
- package/docs/install/npm.md +20 -0
- package/docs/install/npx.md +9 -0
- package/docs/objects/passage.md +47 -0
- package/docs/objects/story.md +70 -0
- package/docs/objects/storyformat.md +27 -0
- package/index.html +22 -0
- package/index.js +29 -31
- package/package.json +68 -58
- package/src/JSON/parse.js +128 -0
- package/src/Passage.js +279 -202
- package/src/Story.js +653 -523
- package/src/StoryFormat/parse.js +134 -0
- package/src/StoryFormat.js +259 -300
- package/src/TWS/parse.js +86 -0
- package/src/Twee/parse.js +157 -0
- package/src/Twine1HTML/compile.js +58 -0
- package/src/Twine1HTML/parse.js +134 -0
- package/src/Twine2ArchiveHTML/compile.js +36 -0
- package/src/Twine2ArchiveHTML/parse.js +49 -0
- package/src/Twine2HTML/compile.js +35 -0
- package/src/Twine2HTML/parse.js +349 -0
- package/src/extwee.js +206 -0
- package/test/CLI/CLI.test.js +49 -0
- package/test/CLI/files/example.json +1 -0
- package/test/CLI/files/example6.twee +22 -0
- package/test/{Roundtrip → CLI/files}/harlowe.js +2 -2
- package/test/CLI/{input.html → files/input.html} +47 -47
- package/test/CLI/files/output/test.twee +0 -0
- package/test/CLI/{tweeExample.twee → files/tweeExample.twee} +17 -17
- package/test/CLI/files/twine1/LICENSE.txt +32 -0
- package/test/CLI/files/twine1/code.js +5 -0
- package/test/CLI/files/twine1/engine.js +43 -0
- package/test/CLI/files/twine1/header.html +325 -0
- package/test/CLI/files/twine1Test.html +371 -0
- package/test/CLI/{twineExample.html → files/twineExample.html} +16 -15
- package/test/JSON/JSON.Parse.test.js +316 -0
- package/test/Passage.test.js +244 -104
- package/test/Roundtrip/{Example1.html → Files/Example1.html} +63 -63
- package/test/Roundtrip/Files/LICENSE +19 -0
- package/test/Roundtrip/Files/example1.twee +10 -0
- package/test/Roundtrip/{example2.twee → Files/example2.twee} +27 -18
- package/test/Roundtrip/{example4.twee → Files/example4.twee} +27 -27
- package/test/{StoryFormatParser → Roundtrip/Files}/harlowe.js +2 -2
- package/test/Roundtrip/{round.html → Files/round.html} +6 -4
- package/test/Roundtrip/Roundtrip.test.js +54 -0
- package/test/Story.test.js +677 -423
- package/test/StoryFormat/StoryFormat.Parse.test.js +91 -0
- package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/example.js +3 -3
- package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/example2.js +3 -3
- package/test/{CLI → StoryFormat/StoryFormatParser}/harlowe.js +2 -2
- package/test/StoryFormat.test.js +152 -152
- package/test/TWS/Parse.test.js +78 -0
- package/test/TWS/TWSParser/Example1.tws +150 -0
- package/test/TWS/TWSParser/Example5.tws +414 -0
- package/test/TWS/TWSParser/noscale.tws +0 -0
- package/test/TWS/TWSParser/nostory.tws +0 -0
- package/test/Twee/Twee.Parse.test.js +76 -0
- package/test/{TweeParser → Twee/TweeParser}/emptytags.twee +2 -2
- package/test/{TweeParser → Twee/TweeParser}/example.twee +32 -32
- package/test/{TweeParser → Twee/TweeParser}/missing.twee +19 -19
- package/test/{TweeParser → Twee/TweeParser}/multipleScriptPassages.twee +19 -19
- package/test/{TweeParser → Twee/TweeParser}/multipleStyleTag.twee +19 -19
- package/test/{TweeParser → Twee/TweeParser}/multipletags.twee +10 -10
- package/test/{TweeParser → Twee/TweeParser}/noTitle.twee +2 -2
- package/test/{TweeParser → Twee/TweeParser}/notes.twee +16 -16
- package/test/{TweeParser → Twee/TweeParser}/pasagemetadataerror.twee +2 -2
- package/test/{TweeParser → Twee/TweeParser}/scriptPassage.twee +16 -16
- package/test/{TweeParser → Twee/TweeParser}/singletag.twee +13 -13
- package/test/{TweeParser → Twee/TweeParser}/startMetadata.twee +14 -14
- package/test/{TweeParser → Twee/TweeParser}/storydataerror.twee +25 -25
- package/test/{TweeParser → Twee/TweeParser}/stylePassage.twee +16 -16
- package/test/{Story → Twee/TweeParser}/test.twee +25 -25
- package/test/Twine1HTML/Twine1HTML.Compile.test.js +180 -0
- package/test/Twine1HTML/Twine1HTML.Parse.test.js +183 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/LICENSE +674 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/engine.js +43 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/jquery.js +4 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/modernizr.js +4 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/engineTest.html +1 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/LICENSE +32 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/code.js +4 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/header.html +327 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test.html +0 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test1.html +6 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test2.html +6 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test3.html +43 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test4.html +372 -0
- package/test/Twine1HTML/Twine1HTMLCompiler/test5.html +372 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Compile.test.js +35 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.test.js +25 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLCompiler/test1.html +6 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLParser/test1.html +3 -0
- package/test/Twine2HTML/Twine2HTML.Compile.test.js +224 -0
- package/test/Twine2HTML/Twine2HTML.Parse.test.js +173 -0
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/creator.html +4 -4
- package/test/{CLI → Twine2HTML/Twine2HTMLCompiler}/example6.twee +15 -15
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/missingStoryTitle.twee +29 -29
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test2.html +10 -8
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test3.html +1 -1
- package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test4.html +4 -4
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/Example1.html +52 -52
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/Tags.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/lyingStartnode.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/lyingTagColors.html +48 -48
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingCreator.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingCreatorVersion.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingFormat.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingFormatVersion.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingIFID.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingName.html +33 -33
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPID.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPassageName.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPassageTags.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingPosition.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingScript.html +14 -14
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingSize.html +35 -35
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingStartnode.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingStyle.html +14 -14
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/missingZoom.html +11 -11
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/twineExample.html +23 -23
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/twineExample2.html +15 -15
- package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/twineExample3.html +15 -15
- package/test/Twine2HTML/Twine2HTMLParser/unescaping.html +33 -0
- package/tsconfig.json +21 -0
- package/types/index.d.ts +14 -0
- package/types/src/JSON/parse.d.ts +8 -0
- package/types/src/Passage.d.ts +72 -0
- package/types/src/Story.d.ts +161 -0
- package/types/src/StoryFormat/parse.d.ts +7 -0
- package/types/src/StoryFormat.d.ts +97 -0
- package/types/src/TWS/parse.d.ts +10 -0
- package/types/src/Twee/parse.d.ts +10 -0
- package/types/src/Twine1HTML/compile.d.ts +17 -0
- package/types/src/Twine1HTML/parse.d.ts +10 -0
- package/types/src/Twine2ArchiveHTML/compile.d.ts +6 -0
- package/types/src/Twine2ArchiveHTML/parse.d.ts +6 -0
- package/types/src/Twine2HTML/compile.d.ts +9 -0
- package/types/src/Twine2HTML/parse.d.ts +17 -0
- package/types/src/extwee.d.ts +2 -0
- package/web-index.js +29 -0
- package/webpack.config.js +12 -0
- package/bin/extwee.js +0 -47
- package/src/FileReader.js +0 -33
- package/src/HTMLParser.js +0 -345
- package/src/HTMLWriter.js +0 -231
- package/src/StoryFormatParser.js +0 -142
- package/src/TweeParser.js +0 -161
- package/src/TweeWriter.js +0 -121
- package/story-formats/chapbook-1.2.0/format.js +0 -1
- package/story-formats/chapbook-1.2.0/logo.svg +0 -1
- package/story-formats/harlowe-1.2.4/format.js +0 -1
- package/story-formats/harlowe-1.2.4/icon.svg +0 -78
- package/story-formats/harlowe-2.1.0/format.js +0 -2
- package/story-formats/harlowe-2.1.0/icon.svg +0 -78
- package/story-formats/harlowe-3.1.0/format.js +0 -3
- package/story-formats/harlowe-3.1.0/icon.svg +0 -78
- package/story-formats/paperthin-1.0.0/format.js +0 -1
- package/story-formats/paperthin-1.0.0/icon.svg +0 -5
- package/story-formats/snowman-1.4.0/format.js +0 -1
- package/story-formats/snowman-1.4.0/icon.svg +0 -436
- package/story-formats/snowman-2.0.2/format.js +0 -1
- package/story-formats/snowman-2.0.2/icon.svg +0 -436
- package/story-formats/sugarcube-1.0.35/LICENSE +0 -23
- package/story-formats/sugarcube-1.0.35/format.js +0 -1
- package/story-formats/sugarcube-1.0.35/icon.svg +0 -56
- package/story-formats/sugarcube-2.31.1/LICENSE +0 -22
- package/story-formats/sugarcube-2.31.1/format.js +0 -1
- package/story-formats/sugarcube-2.31.1/icon.svg +0 -56
- package/test/CLI/test2.html +0 -45
- package/test/CLI.test.js +0 -30
- package/test/FileReader/t1.txt +0 -1
- package/test/FileReader.test.js +0 -14
- package/test/HTMLParser.test.js +0 -177
- package/test/HTMLWriter/example6.twee +0 -16
- package/test/HTMLWriter.test.js +0 -287
- package/test/Roundtrip/example1.twee +0 -21
- package/test/Roundtrip.test.js +0 -48
- package/test/Story/startmeta.twee +0 -29
- package/test/StoryFormatParser.test.js +0 -91
- package/test/TweeParser/test.twee +0 -25
- package/test/TweeParser.test.js +0 -79
- package/test/TweeWriter/test1.twee +0 -18
- package/test/TweeWriter/test3.twee +0 -12
- package/test/TweeWriter/test4.twee +0 -14
- package/test/TweeWriter/test5.twee +0 -20
- package/test/TweeWriter/test6.twee +0 -15
- package/test/TweeWriter/test7.twee +0 -15
- package/test/TweeWriter.test.js +0 -107
- /package/test/CLI/{test.twee → files/test.twee} +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/format.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/format_doublename.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingAuthor.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingDescription.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingImage.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingLicense.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingName.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingProofing.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingSource.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingURL.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/missingVersion.js +0 -0
- /package/test/{StoryFormatParser → StoryFormat/StoryFormatParser}/versionWrong.js +0 -0
- /package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/TestTags.html +0 -0
- /package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test11.html +0 -0
- /package/test/{HTMLWriter → Twine2HTML/Twine2HTMLCompiler}/test6.html +0 -0
- /package/test/{HTMLParser → Twine2HTML/Twine2HTMLParser}/tagColors.html +0 -0
package/src/StoryFormat.js
CHANGED
|
@@ -1,300 +1,259 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @private
|
|
17
|
-
*/
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Internal
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*
|
|
58
|
-
* @
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
*
|
|
126
|
-
* @returns {string}
|
|
127
|
-
*/
|
|
128
|
-
get
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @param {string} n - Replacement
|
|
132
|
-
*/
|
|
133
|
-
set
|
|
134
|
-
if (typeof n === 'string') {
|
|
135
|
-
this.#
|
|
136
|
-
} else {
|
|
137
|
-
throw new Error('
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
* @
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
*
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
* @
|
|
212
|
-
*/
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
*
|
|
245
|
-
* @
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Proofing
|
|
263
|
-
*
|
|
264
|
-
* @public
|
|
265
|
-
* @memberof StoryFormat
|
|
266
|
-
* @returns {boolean} Proofing
|
|
267
|
-
*/
|
|
268
|
-
get proofing () { return this.#_proofing; }
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* @param {boolean} p - Replacement proofing
|
|
272
|
-
*/
|
|
273
|
-
set proofing (p) {
|
|
274
|
-
if (typeof p === 'boolean') {
|
|
275
|
-
this.#_proofing = p;
|
|
276
|
-
} else {
|
|
277
|
-
throw new Error('Proofing must be a Boolean!');
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Source
|
|
283
|
-
*
|
|
284
|
-
* @public
|
|
285
|
-
* @memberof StoryFormat
|
|
286
|
-
* @returns {string} Source
|
|
287
|
-
*/
|
|
288
|
-
get source () { return this.#_source; }
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* @param {string} s - Replacement source
|
|
292
|
-
*/
|
|
293
|
-
set source (s) {
|
|
294
|
-
if (typeof s === 'string') {
|
|
295
|
-
this.#_source = s;
|
|
296
|
-
} else {
|
|
297
|
-
throw new Error('Source must be a String!');
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
1
|
+
export default class StoryFormat {
|
|
2
|
+
/**
|
|
3
|
+
* Internal name.
|
|
4
|
+
* @private
|
|
5
|
+
*/
|
|
6
|
+
#_name = '';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal version.
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
#_version = '';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal description.
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
#_description = '';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal author.
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
#_author = '';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Internal image.
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
#_image = '';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Internal URL.
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
#_url = '';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Internal license.
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
#_license = '';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Internal proofing.
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
#_proofing = '';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Internal source.
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
#_source = '';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create a story format.
|
|
58
|
+
* @param {string} name - Name
|
|
59
|
+
* @param {string} version - Version
|
|
60
|
+
* @param {string} description - Description
|
|
61
|
+
* @param {string} author - Author
|
|
62
|
+
* @param {string} image - Image
|
|
63
|
+
* @param {string} url - URL
|
|
64
|
+
* @param {string} license - License
|
|
65
|
+
* @param {boolean} proofing - If proofing or not
|
|
66
|
+
* @param {string} source - Source
|
|
67
|
+
*/
|
|
68
|
+
constructor (
|
|
69
|
+
name = 'Untitled Story Format',
|
|
70
|
+
version = '',
|
|
71
|
+
description = '',
|
|
72
|
+
author = '',
|
|
73
|
+
image = '',
|
|
74
|
+
url = '',
|
|
75
|
+
license = '',
|
|
76
|
+
proofing = false,
|
|
77
|
+
source = ''
|
|
78
|
+
) {
|
|
79
|
+
// Set name
|
|
80
|
+
this.name = name;
|
|
81
|
+
|
|
82
|
+
// Set version
|
|
83
|
+
this.version = version;
|
|
84
|
+
|
|
85
|
+
// Set description
|
|
86
|
+
this.description = description;
|
|
87
|
+
|
|
88
|
+
// Set author
|
|
89
|
+
this.author = author;
|
|
90
|
+
|
|
91
|
+
// Set image
|
|
92
|
+
this.image = image;
|
|
93
|
+
|
|
94
|
+
// Set URL
|
|
95
|
+
this.url = url;
|
|
96
|
+
|
|
97
|
+
// Set license
|
|
98
|
+
this.license = license;
|
|
99
|
+
|
|
100
|
+
// Set proofing
|
|
101
|
+
this.proofing = proofing;
|
|
102
|
+
|
|
103
|
+
// Set source
|
|
104
|
+
this.source = source;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Name
|
|
109
|
+
* @returns {string} Name
|
|
110
|
+
*/
|
|
111
|
+
get name () { return this.#_name; }
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @param {string} n - Replacement name
|
|
115
|
+
*/
|
|
116
|
+
set name (n) {
|
|
117
|
+
if (typeof n === 'string') {
|
|
118
|
+
this.#_name = n;
|
|
119
|
+
} else {
|
|
120
|
+
throw new Error('Name must be a string!');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Version
|
|
126
|
+
* @returns {string} Version
|
|
127
|
+
*/
|
|
128
|
+
get version () { return this.#_version; }
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @param {string} n - Replacement version
|
|
132
|
+
*/
|
|
133
|
+
set version (n) {
|
|
134
|
+
if (typeof n === 'string') {
|
|
135
|
+
this.#_version = n;
|
|
136
|
+
} else {
|
|
137
|
+
throw new Error('Version must be a string!');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Description
|
|
143
|
+
* @returns {string} Description
|
|
144
|
+
*/
|
|
145
|
+
get description () { return this.#_description; }
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @param {string} d - Replacement description
|
|
149
|
+
*/
|
|
150
|
+
set description (d) {
|
|
151
|
+
if (typeof d === 'string') {
|
|
152
|
+
this.#_description = d;
|
|
153
|
+
} else {
|
|
154
|
+
throw new Error('Description must be a string!');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Author
|
|
160
|
+
* @returns {string} Author
|
|
161
|
+
*/
|
|
162
|
+
get author () { return this.#_author; }
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @param {string} a - Replacement author
|
|
166
|
+
*/
|
|
167
|
+
set author (a) {
|
|
168
|
+
if (typeof a === 'string') {
|
|
169
|
+
this.#_author = a;
|
|
170
|
+
} else {
|
|
171
|
+
throw new Error('Author must be a string!');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Image
|
|
177
|
+
* @returns {string} Image
|
|
178
|
+
*/
|
|
179
|
+
get image () { return this.#_image; }
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @param {string} i - Replacement image
|
|
183
|
+
*/
|
|
184
|
+
set image (i) {
|
|
185
|
+
if (typeof i === 'string') {
|
|
186
|
+
this.#_image = i;
|
|
187
|
+
} else {
|
|
188
|
+
throw new Error('Image must be a string!');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* URL
|
|
194
|
+
* @returns {string} URL
|
|
195
|
+
*/
|
|
196
|
+
get url () { return this.#_url; }
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* @param {string} u - Replacement URL
|
|
200
|
+
*/
|
|
201
|
+
set url (u) {
|
|
202
|
+
if (typeof u === 'string') {
|
|
203
|
+
this.#_url = u;
|
|
204
|
+
} else {
|
|
205
|
+
throw new Error('URL must be a string!');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* License
|
|
211
|
+
* @returns {string} License
|
|
212
|
+
*/
|
|
213
|
+
get license () { return this.#_license; }
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @param {string} l - Replacement license
|
|
217
|
+
*/
|
|
218
|
+
set license (l) {
|
|
219
|
+
if (typeof l === 'string') {
|
|
220
|
+
this.#_license = l;
|
|
221
|
+
} else {
|
|
222
|
+
throw new Error('License must be a string!');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Proofing
|
|
228
|
+
* @returns {boolean} Proofing
|
|
229
|
+
*/
|
|
230
|
+
get proofing () { return this.#_proofing; }
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* @param {boolean} p - Replacement proofing
|
|
234
|
+
*/
|
|
235
|
+
set proofing (p) {
|
|
236
|
+
if (typeof p === 'boolean') {
|
|
237
|
+
this.#_proofing = p;
|
|
238
|
+
} else {
|
|
239
|
+
throw new Error('Proofing must be a Boolean!');
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Source
|
|
245
|
+
* @returns {string} Source
|
|
246
|
+
*/
|
|
247
|
+
get source () { return this.#_source; }
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* @param {string} s - Replacement source
|
|
251
|
+
*/
|
|
252
|
+
set source (s) {
|
|
253
|
+
if (typeof s === 'string') {
|
|
254
|
+
this.#_source = s;
|
|
255
|
+
} else {
|
|
256
|
+
throw new Error('Source must be a String!');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
package/src/TWS/parse.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Story } from '../Story.js';
|
|
2
|
+
import Passage from '../Passage.js';
|
|
3
|
+
import { Parser } from 'pickleparser';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse TWS file (as Buffer) into Story.
|
|
7
|
+
* Unless it throws an error, it will return a Story object.
|
|
8
|
+
*
|
|
9
|
+
* See: Twine 1 TWS Documentation [Approval Pending]
|
|
10
|
+
* @param {Buffer} binaryFileContents - File contents to parse as Buffer.
|
|
11
|
+
* @returns {Story} Story object.
|
|
12
|
+
*/
|
|
13
|
+
function parse (binaryFileContents) {
|
|
14
|
+
// Is this Buffer?
|
|
15
|
+
if (!Buffer.isBuffer(binaryFileContents)) {
|
|
16
|
+
// Throw an error. We cannot proceed.
|
|
17
|
+
throw new Error('Only parsing of Buffer is allowed!');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Create a new PickleParser.
|
|
21
|
+
const parser = new Parser();
|
|
22
|
+
|
|
23
|
+
// Set default value.
|
|
24
|
+
let pythonObject = null;
|
|
25
|
+
|
|
26
|
+
// Does the Buffer contain pickle data?
|
|
27
|
+
try {
|
|
28
|
+
// Try to parse the pickle data, assuming it is pickle data.
|
|
29
|
+
pythonObject = parser.parse(binaryFileContents);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
// This is a Buffer, but not pickle data.
|
|
32
|
+
throw new Error('Buffer does not contain Python pickle data!');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Create Story object.
|
|
36
|
+
const result = new Story();
|
|
37
|
+
|
|
38
|
+
// Does 'storyPanel' exist?
|
|
39
|
+
// (While Twine 1 will always generate it, we must verify.)
|
|
40
|
+
if (Object.prototype.hasOwnProperty.call(pythonObject, 'storyPanel')) {
|
|
41
|
+
// Check and possibly override Zoom level.
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(pythonObject.storyPanel, 'scale')) {
|
|
43
|
+
// Save Zoom level from TWS.
|
|
44
|
+
result.zoom = pythonObject.storyPanel.scale;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Parse storyPanel.widgets.
|
|
48
|
+
if (Object.prototype.hasOwnProperty.call(pythonObject.storyPanel, 'widgets')) {
|
|
49
|
+
// Parse `widgets` for passages.
|
|
50
|
+
for (const widget of pythonObject.storyPanel.widgets) {
|
|
51
|
+
// Create a passage.
|
|
52
|
+
const passage = new Passage();
|
|
53
|
+
|
|
54
|
+
// Get title.
|
|
55
|
+
passage.name = widget.passage.title;
|
|
56
|
+
|
|
57
|
+
// Get position.
|
|
58
|
+
// passage.attributes.position = `${widget.pos[0]},${widget.pos[1]}`;
|
|
59
|
+
|
|
60
|
+
// Get tags.
|
|
61
|
+
passage.tags = widget.passage.tags;
|
|
62
|
+
|
|
63
|
+
// Get source.
|
|
64
|
+
passage.text = widget.passage.text;
|
|
65
|
+
|
|
66
|
+
// Set startingPassage (if found).
|
|
67
|
+
if (passage.name === 'Start') {
|
|
68
|
+
result.start = passage.name;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Set the story name (if found).
|
|
72
|
+
if (passage.name === 'StoryTitle') {
|
|
73
|
+
result.name = passage.text;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Add the passage.
|
|
77
|
+
result.addPassage(passage);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Return Story object.
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { parse };
|