extwee 2.3.3 → 2.3.5
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.core.min.js +1 -1
- package/build/extwee.twine1html.min.js +1 -1
- package/build/extwee.twine2archive.min.js +1 -1
- package/build/extwee.tws.min.js +1 -1
- package/docs/build/extwee.core.min.js +1 -0
- package/docs/build/extwee.twine1html.min.js +1 -0
- package/docs/build/extwee.twine2archive.min.js +1 -0
- package/docs/build/extwee.tws.min.js +1 -0
- package/docs/demos/compiler/extwee.core.min.js +1 -0
- package/docs/demos/compiler/index.css +105 -0
- package/docs/demos/compiler/index.html +359 -0
- package/package.json +19 -18
- package/src/CLI/CommandLineProcessing.js +148 -153
- package/src/Passage.js +6 -4
- package/src/Story.js +1 -1
- package/src/Twee/parse.js +117 -21
- package/src/Twine2HTML/parse-web.js +7 -1
- package/src/Web/web-core.js +22 -2
- package/src/Web/web-twine1html.js +25 -5
- package/src/Web/web-twine2archive.js +25 -5
- package/src/Web/web-tws.js +22 -4
- package/test/Objects/Passage.test.js +1 -1
- package/test/Twee/Twee.Escaping.test.js +200 -0
- package/test/Twine1HTML/Twine1HTML.Parse.Web.test.js +484 -0
- package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.Web.test.js +293 -0
- package/test/Twine2HTML/Twine2HTML.Parse.Web.test.js +329 -0
- package/test/Web/web-core-coverage.test.js +175 -0
- package/test/Web/web-core-global.test.js +93 -0
- package/test/Web/web-core.test.js +156 -0
- package/test/Web/web-twine1html.test.js +105 -0
- package/test/Web/web-twine2archive.test.js +96 -0
- package/test/Web/web-tws.test.js +77 -0
- package/test/Web/window.Extwee.test.js +7 -2
- package/types/src/Story.d.ts +1 -1
- package/types/src/Twee/parse.d.ts +21 -0
- package/types/src/Web/web-core.d.ts +23 -1
- package/types/src/Web/web-twine1html.d.ts +7 -0
- package/types/src/Web/web-twine2archive.d.ts +7 -0
- package/types/src/Web/web-tws.d.ts +5 -0
- package/webpack.config.js +2 -1
- package/src/Web/web-index.js +0 -31
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tests for web-tws.js module
|
|
7
|
+
* Tests module exports and functionality
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, expect, it } from '@jest/globals';
|
|
11
|
+
|
|
12
|
+
// Import to test basic functionality
|
|
13
|
+
import { parse } from '../../src/Web/web-tws.js';
|
|
14
|
+
import Extwee from '../../src/Web/web-tws.js';
|
|
15
|
+
|
|
16
|
+
describe('web-tws.js module tests', () => {
|
|
17
|
+
|
|
18
|
+
describe('ES6 module exports', () => {
|
|
19
|
+
it('should export parse function', () => {
|
|
20
|
+
expect(parse).toBeDefined();
|
|
21
|
+
expect(typeof parse).toBe('function');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should export default object with parseTWS', () => {
|
|
25
|
+
expect(Extwee.parseTWS).toBeDefined();
|
|
26
|
+
expect(Extwee.parse).toBeDefined();
|
|
27
|
+
expect(typeof Extwee.parseTWS).toBe('function');
|
|
28
|
+
expect(typeof Extwee.parse).toBe('function');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('Global object assignment', () => {
|
|
33
|
+
it('should assign functions to global object when available', () => {
|
|
34
|
+
// In Node.js environment, should assign to globalThis
|
|
35
|
+
expect(globalThis.Extwee).toBeDefined();
|
|
36
|
+
expect(globalThis.Extwee.parseTWS).toBeDefined();
|
|
37
|
+
expect(typeof globalThis.Extwee.parseTWS).toBe('function');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should preserve existing Extwee properties', () => {
|
|
41
|
+
// Should not overwrite the entire object, just add properties
|
|
42
|
+
if (globalThis.Extwee && globalThis.Extwee.version) {
|
|
43
|
+
expect(globalThis.Extwee.version).toBeDefined();
|
|
44
|
+
}
|
|
45
|
+
expect(globalThis.Extwee.parseTWS).toBeDefined();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('Functional integration tests', () => {
|
|
50
|
+
it('should have working parseTWS function', () => {
|
|
51
|
+
// Create a minimal valid TWS buffer (pickled data)
|
|
52
|
+
// This is a very basic test - TWS parsing is complex
|
|
53
|
+
const validBuffer = Buffer.from([
|
|
54
|
+
0x80, 0x02, // Python pickle protocol version 2
|
|
55
|
+
0x7d, 0x71, 0x00, // Empty dict
|
|
56
|
+
0x2e // STOP
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
expect(() => {
|
|
60
|
+
const result = parse(validBuffer);
|
|
61
|
+
expect(result).toBeDefined();
|
|
62
|
+
}).not.toThrow();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should throw error for invalid input', () => {
|
|
66
|
+
expect(() => {
|
|
67
|
+
parse("not a buffer");
|
|
68
|
+
}).toThrow();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should have same functions in exports and global', () => {
|
|
72
|
+
// Test that parse is the same function
|
|
73
|
+
expect(parse).toBe(Extwee.parse);
|
|
74
|
+
expect(parse).toBe(Extwee.parseTWS);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// Load the core web module to set up window.Extwee
|
|
6
|
-
import '../../src/Web/web-
|
|
6
|
+
import '../../src/Web/web-core.js';
|
|
7
|
+
|
|
8
|
+
// Load additional modular parsers
|
|
9
|
+
import '../../src/Web/web-twine1html.js';
|
|
10
|
+
import '../../src/Web/web-twine2archive.js';
|
|
11
|
+
import '../../src/Web/web-tws.js';
|
|
7
12
|
|
|
8
13
|
describe('Extwee', () => {
|
|
9
14
|
it('should have all the expected immediate properties', () => {
|
|
@@ -18,7 +23,7 @@ describe('Extwee', () => {
|
|
|
18
23
|
expect(window.Extwee).toHaveProperty('Passage');
|
|
19
24
|
expect(window.Extwee).toHaveProperty('StoryFormat');
|
|
20
25
|
|
|
21
|
-
// Additional parsers
|
|
26
|
+
// Additional parsers loaded via modular imports
|
|
22
27
|
expect(window.Extwee).toHaveProperty('parseTwine1HTML');
|
|
23
28
|
expect(window.Extwee).toHaveProperty('parseTwine2ArchiveHTML');
|
|
24
29
|
expect(window.Extwee).toHaveProperty('parseTWS');
|
package/types/src/Story.d.ts
CHANGED
|
@@ -6,4 +6,25 @@
|
|
|
6
6
|
* @returns {Story} story
|
|
7
7
|
*/
|
|
8
8
|
export function parse(fileContents: string): Story;
|
|
9
|
+
/**
|
|
10
|
+
* Escapes Twee 3 metacharacters according to the specification.
|
|
11
|
+
* This is used when writing Twee files to ensure special characters are properly escaped.
|
|
12
|
+
* @function escapeTweeMetacharacters
|
|
13
|
+
* @param {string} text - Text to escape
|
|
14
|
+
* @returns {string} Escaped text
|
|
15
|
+
*/
|
|
16
|
+
export function escapeTweeMetacharacters(text: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Unescapes Twee 3 metacharacters according to the specification.
|
|
19
|
+
*
|
|
20
|
+
* From the Twee 3 specification:
|
|
21
|
+
* - Encoding: To avoid ambiguity, non-escape backslashes must also be escaped via
|
|
22
|
+
* the same mechanism (i.e. `foo\bar` must become `foo\\bar`).
|
|
23
|
+
* - Decoding: To make decoding more robust, any escaped character within a chunk of
|
|
24
|
+
* encoded text must yield the character minus the backslash (i.e. `\q` must yield `q`).
|
|
25
|
+
* @function unescapeTweeMetacharacters
|
|
26
|
+
* @param {string} text - Text to unescape
|
|
27
|
+
* @returns {string} Unescaped text
|
|
28
|
+
*/
|
|
29
|
+
export function unescapeTweeMetacharacters(text: string): string;
|
|
9
30
|
import { Story } from '../Story.js';
|
|
@@ -1 +1,23 @@
|
|
|
1
|
-
export
|
|
1
|
+
export default Extwee;
|
|
2
|
+
import { parse as parseTwee } from '../Twee/parse.js';
|
|
3
|
+
import { parse as parseJSON } from '../JSON/parse.js';
|
|
4
|
+
import { parse as parseStoryFormat } from '../StoryFormat/parse.js';
|
|
5
|
+
import { parse as parseTwine2HTML } from '../Twine2HTML/parse-web.js';
|
|
6
|
+
import { compile as compileTwine2HTML } from '../Twine2HTML/compile.js';
|
|
7
|
+
import { generate as generateIFID } from '../IFID/generate.js';
|
|
8
|
+
import { Story } from '../Story.js';
|
|
9
|
+
import Passage from '../Passage.js';
|
|
10
|
+
import StoryFormat from '../StoryFormat.js';
|
|
11
|
+
declare namespace Extwee {
|
|
12
|
+
export { parseTwee };
|
|
13
|
+
export { parseJSON };
|
|
14
|
+
export { parseStoryFormat };
|
|
15
|
+
export { parseTwine2HTML };
|
|
16
|
+
export { compileTwine2HTML };
|
|
17
|
+
export { generateIFID };
|
|
18
|
+
export { Story };
|
|
19
|
+
export { Passage };
|
|
20
|
+
export { StoryFormat };
|
|
21
|
+
export let version: string;
|
|
22
|
+
}
|
|
23
|
+
export { parseTwee, parseJSON, parseStoryFormat, parseTwine2HTML, compileTwine2HTML, generateIFID, Story, Passage, StoryFormat };
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export default Extwee;
|
|
2
|
+
declare namespace Extwee {
|
|
3
|
+
export { parseTwine1HTML };
|
|
4
|
+
export { compileTwine1HTML };
|
|
5
|
+
export { parseTwine1HTML as parse };
|
|
6
|
+
export { compileTwine1HTML as compile };
|
|
7
|
+
}
|
|
1
8
|
import { parse as parseTwine1HTML } from '../Twine1HTML/parse-web.js';
|
|
2
9
|
import { compile as compileTwine1HTML } from '../Twine1HTML/compile.js';
|
|
3
10
|
export { parseTwine1HTML as parse, compileTwine1HTML as compile };
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export default Extwee;
|
|
2
|
+
declare namespace Extwee {
|
|
3
|
+
export { parseTwine2ArchiveHTML };
|
|
4
|
+
export { compileTwine2ArchiveHTML };
|
|
5
|
+
export { parseTwine2ArchiveHTML as parse };
|
|
6
|
+
export { compileTwine2ArchiveHTML as compile };
|
|
7
|
+
}
|
|
1
8
|
import { parse as parseTwine2ArchiveHTML } from '../Twine2ArchiveHTML/parse-web.js';
|
|
2
9
|
import { compile as compileTwine2ArchiveHTML } from '../Twine2ArchiveHTML/compile.js';
|
|
3
10
|
export { parseTwine2ArchiveHTML as parse, compileTwine2ArchiveHTML as compile };
|
package/webpack.config.js
CHANGED
|
@@ -15,7 +15,8 @@ export default {
|
|
|
15
15
|
filename: '[name].min.js',
|
|
16
16
|
library: {
|
|
17
17
|
type: 'umd',
|
|
18
|
-
name: 'Extwee' // Use a single library name for all modules
|
|
18
|
+
name: 'Extwee', // Use a single library name for all modules
|
|
19
|
+
export: 'default' // Export the default export directly
|
|
19
20
|
},
|
|
20
21
|
globalObject: 'this'
|
|
21
22
|
},
|
package/src/Web/web-index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { parse as parseTwee } from '../Twee/parse.js';
|
|
2
|
-
import { parse as parseJSON } from '../JSON/parse.js';
|
|
3
|
-
import { parse as parseStoryFormat } from '../StoryFormat/parse.js';
|
|
4
|
-
import { parse as parseTwine1HTML } from '../Twine1HTML/parse.js';
|
|
5
|
-
import { parse as parseTwine2HTML } from '../Twine2HTML/parse.js';
|
|
6
|
-
import { parse as parseTwine2ArchiveHTML } from '../Twine2ArchiveHTML/parse.js';
|
|
7
|
-
import { parse as parseTWS } from '../TWS/parse.js';
|
|
8
|
-
import { compile as compileTwine1HTML } from '../Twine1HTML/compile.js';
|
|
9
|
-
import { compile as compileTwine2HTML } from '../Twine2HTML/compile.js';
|
|
10
|
-
import { compile as compileTwine2ArchiveHTML } from '../Twine2ArchiveHTML/compile.js';
|
|
11
|
-
import { generate as generateIFID } from '../IFID/generate.js';
|
|
12
|
-
import { Story } from '../Story.js';
|
|
13
|
-
import Passage from '../Passage.js';
|
|
14
|
-
import StoryFormat from '../StoryFormat.js';
|
|
15
|
-
|
|
16
|
-
window.Extwee = {
|
|
17
|
-
parseTwee,
|
|
18
|
-
parseJSON,
|
|
19
|
-
parseTWS,
|
|
20
|
-
parseStoryFormat,
|
|
21
|
-
parseTwine1HTML,
|
|
22
|
-
parseTwine2HTML,
|
|
23
|
-
parseTwine2ArchiveHTML,
|
|
24
|
-
compileTwine1HTML,
|
|
25
|
-
compileTwine2HTML,
|
|
26
|
-
compileTwine2ArchiveHTML,
|
|
27
|
-
generateIFID,
|
|
28
|
-
Story,
|
|
29
|
-
Passage,
|
|
30
|
-
StoryFormat
|
|
31
|
-
};
|