squiffy-compiler 7.0.0-beta.5 → 7.0.0-beta.7
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/README.md +10 -2
- package/dist/analyse.d.ts +6 -0
- package/dist/analyse.js +101 -11
- package/dist/compiler.d.ts +9 -2
- package/dist/compiler.js +5 -2
- package/dist/css-urls.d.ts +4 -0
- package/dist/css-urls.js +59 -0
- package/dist/emit.d.ts +13 -0
- package/dist/emit.js +45 -1
- package/dist/language-service.d.ts +1 -0
- package/dist/language-service.js +39 -13
- package/dist/node.d.ts +7 -1
- package/dist/node.js +16 -5
- package/dist/parse.d.ts +3 -0
- package/dist/parse.js +25 -2
- package/dist/project.d.ts +56 -0
- package/dist/project.js +148 -15
- package/dist/quest/aslx.d.ts +50 -0
- package/dist/quest/aslx.js +181 -0
- package/dist/quest/convert.d.ts +20 -0
- package/dist/quest/convert.js +504 -0
- package/dist/quest/script.d.ts +92 -0
- package/dist/quest/script.js +453 -0
- package/dist/quest/scripts.d.ts +24 -0
- package/dist/quest/scripts.js +505 -0
- package/dist/quest/text.d.ts +17 -0
- package/dist/quest/text.js +305 -0
- package/dist/setters.d.ts +4 -0
- package/dist/setters.js +10 -5
- package/dist/story-graph.d.ts +2 -1
- package/dist/story-graph.js +2 -0
- package/dist/syntax.d.ts +27 -2
- package/dist/text.d.ts +2 -0
- package/dist/text.js +24 -15
- package/dist/twine/audio.d.ts +21 -0
- package/dist/twine/audio.js +80 -0
- package/dist/twine/convert.d.ts +15 -1
- package/dist/twine/convert.js +217 -21
- package/dist/twine/expression.d.ts +26 -1
- package/dist/twine/expression.js +111 -6
- package/dist/twine/harlowe.d.ts +10 -0
- package/dist/twine/harlowe.js +417 -58
- package/dist/twine/sugarcube.d.ts +4 -0
- package/dist/twine/sugarcube.js +388 -86
- package/dist/v5.js +2 -1
- package/package.json +3 -2
- package/syntaxes/squiffy.tmLanguage.json +9 -4
package/dist/node.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PageStrings, type Panel } from "./project.js";
|
|
1
2
|
export interface StoryOnDisk {
|
|
2
3
|
mainFile: string;
|
|
3
4
|
storyFiles?: string[];
|
|
@@ -5,11 +6,16 @@ export interface StoryOnDisk {
|
|
|
5
6
|
note?: string;
|
|
6
7
|
expressions: boolean;
|
|
7
8
|
backButton?: boolean;
|
|
9
|
+
strings?: PageStrings;
|
|
10
|
+
saveButton?: boolean;
|
|
11
|
+
projectId?: string;
|
|
12
|
+
panels?: Panel[];
|
|
8
13
|
}
|
|
9
14
|
export declare class StoryNotFoundError extends Error {
|
|
10
15
|
}
|
|
11
16
|
export interface FindStoryOptions {
|
|
12
17
|
skip?: string[];
|
|
13
18
|
}
|
|
14
|
-
export declare
|
|
19
|
+
export declare const listSquiffyFiles: (folder: string) => Promise<string[]>;
|
|
20
|
+
export declare const listStoryFiles: (folder: string) => Promise<string[]>;
|
|
15
21
|
export declare function findStory(input: string, options?: FindStoryOptions): Promise<StoryOnDisk>;
|
package/dist/node.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// rest of the compiler stays free of Node dependencies.
|
|
5
5
|
import fs from "fs/promises";
|
|
6
6
|
import path from "path";
|
|
7
|
-
import { getStoryFiles, isAlwaysSkipped, parseProjectFile, PROJECT_FILENAME } from "./project.js";
|
|
7
|
+
import { getStoryFiles, isAlwaysSkipped, isSquiffyPath, isStoryFilePath, parseProjectFile, PROJECT_FILENAME, storyFileList, } from "./project.js";
|
|
8
8
|
// A problem finding the story, with a message to show the author as is
|
|
9
9
|
export class StoryNotFoundError extends Error {
|
|
10
10
|
}
|
|
@@ -37,7 +37,11 @@ async function findProjectFile(folder) {
|
|
|
37
37
|
}
|
|
38
38
|
// Every .squiffy file in a folder and its subfolders, relative to it with "/" separators, without
|
|
39
39
|
// looking inside the folders that are never part of a story.
|
|
40
|
-
export
|
|
40
|
+
export const listSquiffyFiles = (folder) => listFiles(folder, isSquiffyPath);
|
|
41
|
+
// Every .squiffy, .css and .js file in a folder and its subfolders, as listSquiffyFiles, and any
|
|
42
|
+
// index.html, which getStoryFiles needs to see to leave out an old build
|
|
43
|
+
export const listStoryFiles = (folder) => listFiles(folder, name => isStoryFilePath(name) || name == "index.html");
|
|
44
|
+
async function listFiles(folder, include) {
|
|
41
45
|
const result = [];
|
|
42
46
|
const walk = async (relative) => {
|
|
43
47
|
const entries = await fs.readdir(path.join(folder, relative), { withFileTypes: true });
|
|
@@ -47,7 +51,7 @@ export async function listSquiffyFiles(folder) {
|
|
|
47
51
|
if (!isAlwaysSkipped(`${child}/x`))
|
|
48
52
|
await walk(child);
|
|
49
53
|
}
|
|
50
|
-
else if (entry.name
|
|
54
|
+
else if (include(entry.name)) {
|
|
51
55
|
result.push(child);
|
|
52
56
|
}
|
|
53
57
|
}
|
|
@@ -69,10 +73,17 @@ async function folderStory(projectFile, options) {
|
|
|
69
73
|
if (!await exists(mainFile)) {
|
|
70
74
|
throw new StoryNotFoundError(`The main file in ${projectFile}, ${project.main}, doesn't exist.`);
|
|
71
75
|
}
|
|
72
|
-
|
|
76
|
+
// Absolute paths to skip are made relative to the project, and any outside it are ignored
|
|
77
|
+
const skip = (options.skip ?? []).map(file => path.isAbsolute(file) ? path.relative(root, file).split(path.sep).join("/") : file)
|
|
78
|
+
.filter(file => file && !file.startsWith("..") && !path.isAbsolute(file));
|
|
79
|
+
const story = getStoryFiles(project, await listStoryFiles(root), skip);
|
|
73
80
|
return {
|
|
74
|
-
mainFile, storyFiles: story.
|
|
81
|
+
mainFile, storyFiles: storyFileList(story).map(file => path.resolve(root, file)), projectFile, expressions: true,
|
|
75
82
|
...(project.backButton !== undefined ? { backButton: project.backButton } : {}),
|
|
83
|
+
...(project.strings !== undefined ? { strings: project.strings } : {}),
|
|
84
|
+
...(project.saveButton !== undefined ? { saveButton: project.saveButton } : {}),
|
|
85
|
+
...(project.id !== undefined ? { projectId: project.id } : {}),
|
|
86
|
+
...(project.panels !== undefined ? { panels: project.panels } : {}),
|
|
76
87
|
};
|
|
77
88
|
}
|
|
78
89
|
// Finds the story to build from what the author gave: a folder with a squiffy.json in it, or a
|
package/dist/parse.d.ts
CHANGED
package/dist/parse.js
CHANGED
|
@@ -13,6 +13,9 @@ export const lineRegexes = {
|
|
|
13
13
|
js: /^(\t| {4})(.*)$/,
|
|
14
14
|
continue: /^\+\+\+(.*)$/,
|
|
15
15
|
ui: /^@ui (.*)$/,
|
|
16
|
+
music: /^@music (.*)$/,
|
|
17
|
+
sound: /^@sound (.*)$/,
|
|
18
|
+
class: /^@class (.*)$/,
|
|
16
19
|
};
|
|
17
20
|
// Parses one .squiffy file into a syntax tree. This never fails: problems such as a passage
|
|
18
21
|
// with no section are reported by analyse(), which knows how the file fits into the story.
|
|
@@ -123,7 +126,7 @@ export function parse(text, filename) {
|
|
|
123
126
|
body: [],
|
|
124
127
|
links: [],
|
|
125
128
|
embeds: [],
|
|
126
|
-
gotos: [],
|
|
129
|
+
gotos: [], deactivates: [],
|
|
127
130
|
};
|
|
128
131
|
section.passages.push(passage);
|
|
129
132
|
textStarted = false;
|
|
@@ -159,6 +162,9 @@ export function parse(text, filename) {
|
|
|
159
162
|
haveSection = true;
|
|
160
163
|
add({ type: "clear", range });
|
|
161
164
|
}
|
|
165
|
+
else if (stripLine == "@repeat") {
|
|
166
|
+
add({ type: "repeat", range });
|
|
167
|
+
}
|
|
162
168
|
else if (stripLine == "@end") {
|
|
163
169
|
if (!passage)
|
|
164
170
|
haveSection = true;
|
|
@@ -173,6 +179,17 @@ export function parse(text, filename) {
|
|
|
173
179
|
else if (match.import) {
|
|
174
180
|
add({ type: "import", pattern: match.import[1], patternRange: valueRange(i, match.import[1]), range });
|
|
175
181
|
}
|
|
182
|
+
else if (match.music || match.sound) {
|
|
183
|
+
if (!passage)
|
|
184
|
+
haveSection = true;
|
|
185
|
+
const value = (match.music ?? match.sound)[1];
|
|
186
|
+
add({ type: "sound", directive: match.music ? "music" : "sound", value, valueRange: valueRange(i, value), range });
|
|
187
|
+
}
|
|
188
|
+
else if (match.class) {
|
|
189
|
+
if (!passage)
|
|
190
|
+
haveSection = true;
|
|
191
|
+
add({ type: "class", value: match.class[1], valueRange: valueRange(i, match.class[1]), range });
|
|
192
|
+
}
|
|
176
193
|
else if (match.attributes || match.unset) {
|
|
177
194
|
haveSection = true;
|
|
178
195
|
const value = (match.attributes ?? match.unset)[1];
|
|
@@ -233,7 +250,7 @@ export function parse(text, filename) {
|
|
|
233
250
|
return file;
|
|
234
251
|
}
|
|
235
252
|
function newSection(kind, range) {
|
|
236
|
-
return { type: "section", kind, range, body: [], passages: [], links: [], embeds: [], gotos: [] };
|
|
253
|
+
return { type: "section", kind, range, body: [], passages: [], links: [], embeds: [], gotos: [], deactivates: [] };
|
|
237
254
|
}
|
|
238
255
|
// Fills in the links, embeds and gotos in a section's or passage's text.
|
|
239
256
|
function findLinks(node, lines) {
|
|
@@ -269,4 +286,10 @@ function findLinks(node, lines) {
|
|
|
269
286
|
range: toRange(goto.start, goto.end),
|
|
270
287
|
nameRange: toRange(goto.nameStart, goto.nameEnd),
|
|
271
288
|
}));
|
|
289
|
+
node.deactivates = result.deactivates.map((deactivate) => ({
|
|
290
|
+
type: "deactivate",
|
|
291
|
+
name: deactivate.name,
|
|
292
|
+
range: toRange(deactivate.start, deactivate.end),
|
|
293
|
+
nameRange: toRange(deactivate.nameStart, deactivate.nameEnd),
|
|
294
|
+
}));
|
|
272
295
|
}
|
package/dist/project.d.ts
CHANGED
|
@@ -3,11 +3,57 @@ export declare const PROJECT_FILE_VERSION = 1;
|
|
|
3
3
|
export declare const PROJECT_SCHEMA_URL = "https://squiffystory.com/schema/squiffy.json";
|
|
4
4
|
export interface ProjectFile {
|
|
5
5
|
version: number;
|
|
6
|
+
id?: string;
|
|
6
7
|
main: string;
|
|
7
8
|
exclude: string[];
|
|
8
9
|
map?: MapPositions;
|
|
9
10
|
backButton?: boolean;
|
|
11
|
+
saveButton?: boolean;
|
|
12
|
+
strings?: PageStrings;
|
|
13
|
+
panels?: Panel[];
|
|
10
14
|
}
|
|
15
|
+
export declare const PANEL_ICONS: readonly ["bag", "person", "map", "help", "info", "list", "book", "star", "heart"];
|
|
16
|
+
export type PanelIcon = typeof PANEL_ICONS[number];
|
|
17
|
+
export interface Panel {
|
|
18
|
+
passage: string;
|
|
19
|
+
label: string;
|
|
20
|
+
position?: "side" | "button";
|
|
21
|
+
icon?: PanelIcon;
|
|
22
|
+
}
|
|
23
|
+
export type PageStringName = keyof typeof PAGE_STRINGS;
|
|
24
|
+
export type PageStrings = Partial<Record<PageStringName, string>>;
|
|
25
|
+
export declare const PAGE_STRINGS: {
|
|
26
|
+
back: string;
|
|
27
|
+
restart: string;
|
|
28
|
+
restartConfirm: string;
|
|
29
|
+
switchToDark: string;
|
|
30
|
+
switchToLight: string;
|
|
31
|
+
mute: string;
|
|
32
|
+
unmute: string;
|
|
33
|
+
saves: string;
|
|
34
|
+
saveName: string;
|
|
35
|
+
save: string;
|
|
36
|
+
noSaves: string;
|
|
37
|
+
savedGame: string;
|
|
38
|
+
savedToday: string;
|
|
39
|
+
savedYesterday: string;
|
|
40
|
+
load: string;
|
|
41
|
+
loadConfirm: string;
|
|
42
|
+
saveOptions: string;
|
|
43
|
+
overwrite: string;
|
|
44
|
+
overwriteConfirm: string;
|
|
45
|
+
rename: string;
|
|
46
|
+
newName: string;
|
|
47
|
+
saveToFile: string;
|
|
48
|
+
loadFromFile: string;
|
|
49
|
+
delete: string;
|
|
50
|
+
deleteConfirm: string;
|
|
51
|
+
cancel: string;
|
|
52
|
+
close: string;
|
|
53
|
+
wrongStory: string;
|
|
54
|
+
notASave: string;
|
|
55
|
+
cantSave: string;
|
|
56
|
+
};
|
|
11
57
|
export interface MapPositions {
|
|
12
58
|
sections: Record<string, [number, number]>;
|
|
13
59
|
passages: Record<string, Record<string, [number, number]>>;
|
|
@@ -23,17 +69,27 @@ export declare function parseProjectFile(text: string): ParsedProjectFile;
|
|
|
23
69
|
export declare function globToRegExp(pattern: string): RegExp;
|
|
24
70
|
export declare function isExcluded(path: string, exclude: string[]): boolean;
|
|
25
71
|
export declare function isAlwaysSkipped(path: string): boolean;
|
|
72
|
+
export declare const BUILD_FOLDER = "build";
|
|
73
|
+
export declare const isSquiffyPath: (path: string) => boolean;
|
|
74
|
+
export declare const isStylesheetPath: (path: string) => boolean;
|
|
75
|
+
export declare const isScriptPath: (path: string) => boolean;
|
|
76
|
+
export declare const isStoryFilePath: (path: string) => boolean;
|
|
26
77
|
export interface StoryFiles {
|
|
27
78
|
main: string;
|
|
28
79
|
included: string[];
|
|
80
|
+
stylesheets: string[];
|
|
81
|
+
scripts: string[];
|
|
29
82
|
excluded: string[];
|
|
30
83
|
}
|
|
31
84
|
export declare const comparePaths: (a: string, b: string) => 1 | 0 | -1;
|
|
32
85
|
export declare function getStoryFiles(project: ProjectFile, paths: Iterable<string>, skip?: string[]): StoryFiles;
|
|
86
|
+
export declare const storyFileList: (story: StoryFiles) => string[];
|
|
33
87
|
export declare function formatProjectFile(project: {
|
|
34
88
|
main: string;
|
|
35
89
|
exclude?: string[];
|
|
36
90
|
map?: MapPositions;
|
|
91
|
+
id?: string;
|
|
92
|
+
panels?: Panel[];
|
|
37
93
|
}): string;
|
|
38
94
|
export declare function updateProjectFile(text: string, changes: {
|
|
39
95
|
main?: string;
|
package/dist/project.js
CHANGED
|
@@ -3,15 +3,52 @@
|
|
|
3
3
|
// { "version": 1, "main": "story.squiffy", "exclude": ["drafts/**"] }
|
|
4
4
|
//
|
|
5
5
|
// Without it, a story is its main file plus whatever that @imports. With it, the story is every
|
|
6
|
-
// .squiffy file in the folder and its subfolders, except those `exclude` matches:
|
|
7
|
-
// first, then the rest in path order. These are the rules the CLI, the Vite plugin,
|
|
8
|
-
// service and the editor all share. They're pure functions, so each can supply its own file list.
|
|
6
|
+
// .squiffy, .css and .js file in the folder and its subfolders, except those `exclude` matches:
|
|
7
|
+
// the main file first, then the rest in path order. These are the rules the CLI, the Vite plugin,
|
|
8
|
+
// the language service and the editor all share. They're pure functions, so each can supply its own file list.
|
|
9
9
|
export const PROJECT_FILENAME = "squiffy.json";
|
|
10
10
|
// The newest project file format this version of Squiffy understands. It counts the file
|
|
11
11
|
// format, not the Squiffy release, and only goes up when the meaning of a project changes.
|
|
12
12
|
export const PROJECT_FILE_VERSION = 1;
|
|
13
13
|
// Where the project file's JSON schema is published
|
|
14
14
|
export const PROJECT_SCHEMA_URL = "https://squiffystory.com/schema/squiffy.json";
|
|
15
|
+
// The icons a panel's button can have. The runtime has the same list (PANEL_ICONS).
|
|
16
|
+
export const PANEL_ICONS = ["bag", "person", "map", "help", "info", "list", "book", "star", "heart"];
|
|
17
|
+
// The published page's text in English, which squiffy.json's "strings" can replace
|
|
18
|
+
export const PAGE_STRINGS = {
|
|
19
|
+
back: "Back",
|
|
20
|
+
restart: "Restart",
|
|
21
|
+
restartConfirm: "Are you sure you want to restart?",
|
|
22
|
+
switchToDark: "Switch to dark mode",
|
|
23
|
+
switchToLight: "Switch to light mode",
|
|
24
|
+
// The mute button, for a story with music or sounds
|
|
25
|
+
mute: "Mute",
|
|
26
|
+
unmute: "Unmute",
|
|
27
|
+
// The Saved games dialog, opened by the Save button. [name] and [time] are filled in.
|
|
28
|
+
saves: "Saved games",
|
|
29
|
+
saveName: "Name (optional)",
|
|
30
|
+
save: "Save",
|
|
31
|
+
noSaves: "No saved games yet.",
|
|
32
|
+
savedGame: "Saved game",
|
|
33
|
+
savedToday: "Today, [time]",
|
|
34
|
+
savedYesterday: "Yesterday, [time]",
|
|
35
|
+
load: "Load",
|
|
36
|
+
loadConfirm: "Load \"[name]\"? You'll lose anything you've done since you last saved.",
|
|
37
|
+
saveOptions: "Options for [name]",
|
|
38
|
+
overwrite: "Overwrite",
|
|
39
|
+
overwriteConfirm: "Overwrite \"[name]\"?",
|
|
40
|
+
rename: "Rename",
|
|
41
|
+
newName: "New name",
|
|
42
|
+
saveToFile: "Save to file",
|
|
43
|
+
loadFromFile: "Load from file",
|
|
44
|
+
delete: "Delete",
|
|
45
|
+
deleteConfirm: "Delete \"[name]\"? This can't be undone.",
|
|
46
|
+
cancel: "Cancel",
|
|
47
|
+
close: "Close",
|
|
48
|
+
wrongStory: "This saved game is for a different story.",
|
|
49
|
+
notASave: "This file isn't a saved game.",
|
|
50
|
+
cantSave: "The game couldn't be saved. Try Save to file instead.",
|
|
51
|
+
};
|
|
15
52
|
// Parses and checks a squiffy.json. An error is a sentence to show the author as is.
|
|
16
53
|
export function parseProjectFile(text) {
|
|
17
54
|
const fail = (error) => ({ success: false, error });
|
|
@@ -54,20 +91,78 @@ export function parseProjectFile(text) {
|
|
|
54
91
|
if (!Array.isArray(exclude) || exclude.some(pattern => typeof pattern != "string")) {
|
|
55
92
|
return fail(`${PROJECT_FILENAME}'s "exclude" should be a list of file patterns, such as ["drafts/**"].`);
|
|
56
93
|
}
|
|
94
|
+
const id = data.id;
|
|
95
|
+
if (id !== undefined && (typeof id != "string" || !id.trim())) {
|
|
96
|
+
return fail(`${PROJECT_FILENAME}'s "id" should be text that identifies the story, such as "${EXAMPLE_ID}".`);
|
|
97
|
+
}
|
|
57
98
|
const backButton = data.backButton;
|
|
58
99
|
if (backButton !== undefined && typeof backButton != "boolean") {
|
|
59
100
|
return fail(`${PROJECT_FILENAME}'s "backButton" should be true or false.`);
|
|
60
101
|
}
|
|
102
|
+
const saveButton = data.saveButton;
|
|
103
|
+
if (saveButton !== undefined && typeof saveButton != "boolean") {
|
|
104
|
+
return fail(`${PROJECT_FILENAME}'s "saveButton" should be true or false.`);
|
|
105
|
+
}
|
|
106
|
+
const strings = data.strings;
|
|
107
|
+
if (strings !== undefined && (!isObject(strings) || Object.values(strings).some(value => typeof value != "string"))) {
|
|
108
|
+
return fail(`${PROJECT_FILENAME}'s "strings" should be an object of text, such as { "restart": "Recommencer" }.`);
|
|
109
|
+
}
|
|
110
|
+
const panels = parsePanels(data.panels);
|
|
111
|
+
if (typeof panels == "string")
|
|
112
|
+
return fail(panels);
|
|
61
113
|
const map = parseMapPositions(data.map);
|
|
62
114
|
return {
|
|
63
115
|
success: true,
|
|
64
116
|
project: {
|
|
65
117
|
version, main: mainPath, exclude: exclude,
|
|
118
|
+
...(id !== undefined ? { id: id.trim() } : {}),
|
|
66
119
|
...(map ? { map } : {}),
|
|
67
120
|
...(backButton !== undefined ? { backButton } : {}),
|
|
121
|
+
...(saveButton !== undefined ? { saveButton } : {}),
|
|
122
|
+
...(strings !== undefined ? { strings: pickPageStrings(strings) } : {}),
|
|
123
|
+
...(panels !== undefined ? { panels } : {}),
|
|
68
124
|
},
|
|
69
125
|
};
|
|
70
126
|
}
|
|
127
|
+
// The page strings Squiffy knows about. Others are left out, so a story written for a newer Squiffy,
|
|
128
|
+
// with strings this one doesn't have, still builds.
|
|
129
|
+
function pickPageStrings(strings) {
|
|
130
|
+
return Object.fromEntries(Object.entries(strings).filter(([name]) => Object.prototype.hasOwnProperty.call(PAGE_STRINGS, name)));
|
|
131
|
+
}
|
|
132
|
+
// squiffy.json's "panels", or an error to show the author
|
|
133
|
+
function parsePanels(value) {
|
|
134
|
+
if (value === undefined)
|
|
135
|
+
return undefined;
|
|
136
|
+
const example = "{ \"passage\": \"inventory\", \"label\": \"Inventory\" }";
|
|
137
|
+
if (!Array.isArray(value))
|
|
138
|
+
return `${PROJECT_FILENAME}'s "panels" should be a list, such as [${example}].`;
|
|
139
|
+
const panels = [];
|
|
140
|
+
for (const [i, item] of value.entries()) {
|
|
141
|
+
const which = `${PROJECT_FILENAME}'s panel ${i + 1}`;
|
|
142
|
+
if (!isObject(item))
|
|
143
|
+
return `${which} should be an object, such as ${example}.`;
|
|
144
|
+
if (typeof item.passage != "string" || !item.passage.trim()) {
|
|
145
|
+
return `${which} needs a "passage": the name of a passage in the master section [[]].`;
|
|
146
|
+
}
|
|
147
|
+
if (typeof item.label != "string" || !item.label.trim()) {
|
|
148
|
+
return `${which} needs a "label", for its button, such as "Inventory".`;
|
|
149
|
+
}
|
|
150
|
+
if (item.position !== undefined && item.position !== "side" && item.position !== "button") {
|
|
151
|
+
return `${which}'s "position" should be "side" or "button".`;
|
|
152
|
+
}
|
|
153
|
+
if (item.icon !== undefined && !PANEL_ICONS.includes(item.icon)) {
|
|
154
|
+
return `${which}'s "icon" should be one of ${PANEL_ICONS.map(icon => `"${icon}"`).join(", ")}.`;
|
|
155
|
+
}
|
|
156
|
+
panels.push({
|
|
157
|
+
passage: item.passage.trim(),
|
|
158
|
+
label: item.label.trim(),
|
|
159
|
+
...(item.position !== undefined ? { position: item.position } : {}),
|
|
160
|
+
...(item.icon !== undefined ? { icon: item.icon } : {}),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return panels;
|
|
164
|
+
}
|
|
165
|
+
const EXAMPLE_ID = "0b7c6d9e-3f1a-4e2b-9c5d-8a7f6e5d4c3b";
|
|
71
166
|
const isPosition = (value) => Array.isArray(value) && value.length == 2 && value.every(n => typeof n == "number" && Number.isFinite(n));
|
|
72
167
|
const isObject = (value) => !!value && typeof value == "object" && !Array.isArray(value);
|
|
73
168
|
// The story map's positions. Only the editor uses them, so anything that isn't a position is
|
|
@@ -155,39 +250,77 @@ export function isExcluded(path, exclude) {
|
|
|
155
250
|
return false;
|
|
156
251
|
});
|
|
157
252
|
}
|
|
158
|
-
// Folders whose
|
|
159
|
-
//
|
|
253
|
+
// Folders whose files are never part of a story, whatever `exclude` says: node_modules, and
|
|
254
|
+
// folders whose names start with "." (.git, .vscode and the like).
|
|
160
255
|
export function isAlwaysSkipped(path) {
|
|
161
256
|
const folders = path.split("/").slice(0, -1);
|
|
162
257
|
return folders.some(folder => folder == "node_modules" || folder.startsWith("."));
|
|
163
258
|
}
|
|
259
|
+
// The folder, next to squiffy.json, that the CLI builds a project's published files into. Its
|
|
260
|
+
// files are never part of the story.
|
|
261
|
+
export const BUILD_FOLDER = "build";
|
|
262
|
+
// The files that Squiffy 6, and Squiffy 7 without a squiffy.json, write next to the main file
|
|
263
|
+
// when publishing a story, with its index.html. With an index.html beside them, they're taken to
|
|
264
|
+
// be an old build, and aren't part of the story unless it @imports them.
|
|
265
|
+
const OLD_BUILD_FILES = ["story.js", "style.css", "squiffy.runtime.js", "squiffy.runtime.global.js"];
|
|
266
|
+
// The kinds of file that are part of a story
|
|
267
|
+
export const isSquiffyPath = (path) => path.endsWith(".squiffy");
|
|
268
|
+
export const isStylesheetPath = (path) => path.endsWith(".css");
|
|
269
|
+
export const isScriptPath = (path) => path.endsWith(".js");
|
|
270
|
+
export const isStoryFilePath = (path) => isSquiffyPath(path) || isStylesheetPath(path) || isScriptPath(path);
|
|
164
271
|
// Sorts paths by code point, so the order is the same everywhere, whatever the locale.
|
|
165
272
|
export const comparePaths = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
166
|
-
// Which of a project's files make up the story
|
|
167
|
-
// with "/" separators, as from a recursive
|
|
168
|
-
//
|
|
273
|
+
// Which of a project's files make up the story: its .squiffy files, stylesheets and scripts.
|
|
274
|
+
// `paths` are relative to the project file's folder, with "/" separators, as from a recursive
|
|
275
|
+
// listing of the folder; files of other kinds are ignored. Pass `skip` to leave out more files
|
|
276
|
+
// or folders, such as a build's output folder.
|
|
169
277
|
export function getStoryFiles(project, paths, skip = []) {
|
|
170
278
|
const included = [];
|
|
279
|
+
const stylesheets = [];
|
|
280
|
+
const scripts = [];
|
|
171
281
|
const excluded = [];
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
282
|
+
const all = new Set(paths);
|
|
283
|
+
const skipped = [BUILD_FOLDER, ...skip].map(folder => normalisePath(folder)).filter(folder => folder !== null);
|
|
284
|
+
const mainSlash = project.main.lastIndexOf("/");
|
|
285
|
+
const mainFolder = mainSlash < 0 ? "" : project.main.substring(0, mainSlash + 1);
|
|
286
|
+
const oldBuild = all.has(mainFolder + "index.html") ? new Set(OLD_BUILD_FILES.map(file => mainFolder + file)) : new Set();
|
|
287
|
+
for (const path of all) {
|
|
288
|
+
if (!isStoryFilePath(path) || path == project.main || isAlwaysSkipped(path) || oldBuild.has(path))
|
|
175
289
|
continue;
|
|
176
|
-
if (skipped.some(folder => path.startsWith(folder + "/")))
|
|
290
|
+
if (skipped.some(folder => path == folder || path.startsWith(folder + "/")))
|
|
177
291
|
continue;
|
|
178
|
-
(isExcluded(path, project.exclude)
|
|
292
|
+
if (isExcluded(path, project.exclude))
|
|
293
|
+
excluded.push(path);
|
|
294
|
+
else if (isSquiffyPath(path))
|
|
295
|
+
included.push(path);
|
|
296
|
+
else if (isStylesheetPath(path))
|
|
297
|
+
stylesheets.push(path);
|
|
298
|
+
else
|
|
299
|
+
scripts.push(path);
|
|
179
300
|
}
|
|
180
|
-
return {
|
|
301
|
+
return {
|
|
302
|
+
main: project.main,
|
|
303
|
+
included: included.sort(comparePaths),
|
|
304
|
+
stylesheets: stylesheets.sort(comparePaths),
|
|
305
|
+
scripts: scripts.sort(comparePaths),
|
|
306
|
+
excluded: excluded.sort(comparePaths),
|
|
307
|
+
};
|
|
181
308
|
}
|
|
182
|
-
// The
|
|
309
|
+
// The story's files after the main file, in the order the compiler takes them (see
|
|
310
|
+
// AnalyseSettings.storyFiles): its .squiffy files, then its stylesheets, then its scripts.
|
|
311
|
+
export const storyFileList = (story) => [...story.included, ...story.stylesheets, ...story.scripts];
|
|
312
|
+
// The text of a new project file. It's given a new random id, unless one is passed in.
|
|
183
313
|
export function formatProjectFile(project) {
|
|
184
314
|
const json = {
|
|
185
315
|
$schema: PROJECT_SCHEMA_URL,
|
|
186
316
|
version: PROJECT_FILE_VERSION,
|
|
317
|
+
id: project.id ?? crypto.randomUUID(),
|
|
187
318
|
main: project.main,
|
|
188
319
|
};
|
|
189
320
|
if (project.exclude?.length)
|
|
190
321
|
json.exclude = project.exclude;
|
|
322
|
+
if (project.panels?.length)
|
|
323
|
+
json.panels = project.panels;
|
|
191
324
|
const text = JSON.stringify(json, null, 2) + "\n";
|
|
192
325
|
return project.map ? updateProjectFile(text, { map: project.map }) : text;
|
|
193
326
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare class QuestParseError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export interface XmlElement {
|
|
4
|
+
name: string;
|
|
5
|
+
attrs: Record<string, string>;
|
|
6
|
+
children: XmlElement[];
|
|
7
|
+
text: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function parseXml(source: string): XmlElement;
|
|
10
|
+
export type QuestValue = {
|
|
11
|
+
type: "string";
|
|
12
|
+
value: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: "boolean";
|
|
15
|
+
value: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
type: "number";
|
|
18
|
+
value: number;
|
|
19
|
+
} | {
|
|
20
|
+
type: "script";
|
|
21
|
+
value: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "stringdictionary";
|
|
24
|
+
value: [string, string][];
|
|
25
|
+
} | {
|
|
26
|
+
type: "stringlist";
|
|
27
|
+
value: string[];
|
|
28
|
+
} | {
|
|
29
|
+
type: "other";
|
|
30
|
+
typeName: string;
|
|
31
|
+
value: string;
|
|
32
|
+
};
|
|
33
|
+
export declare function readValue(element: XmlElement): QuestValue;
|
|
34
|
+
export interface QuestObject {
|
|
35
|
+
name: string;
|
|
36
|
+
inherits: string[];
|
|
37
|
+
attributes: Map<string, QuestValue>;
|
|
38
|
+
children: QuestObject[];
|
|
39
|
+
}
|
|
40
|
+
export interface QuestGame {
|
|
41
|
+
aslVersion: string;
|
|
42
|
+
gamebook: boolean;
|
|
43
|
+
game: QuestObject;
|
|
44
|
+
gameDefaults: Map<string, QuestValue>;
|
|
45
|
+
pages: QuestObject[];
|
|
46
|
+
start?: string;
|
|
47
|
+
javascript: string[];
|
|
48
|
+
}
|
|
49
|
+
export declare function parseQuestGame(source: string): QuestGame;
|
|
50
|
+
export declare function isQuestSource(source: string): boolean;
|