squiffy-runtime 6.0.0-beta.1 → 6.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/squiffy.runtime.d.ts +1 -0
- package/dist/squiffy.runtime.global.js +95 -96
- package/dist/squiffy.runtime.global.js.map +1 -1
- package/dist/squiffy.runtime.js +9451 -7635
- package/dist/squiffy.runtime.js.map +1 -1
- package/package.json +21 -19
- package/src/__snapshots__/squiffy.runtime.test.ts.snap +3 -1
- package/src/linkHandler.ts +1 -1
- package/src/plugins/animate.ts +1 -1
- package/src/plugins/replaceLabel.ts +2 -2
- package/src/plugins/rotateSequence.ts +1 -1
- package/src/squiffy.runtime.ts +7 -5
- package/src/textProcessor.ts +4 -2
- package/src/updater.ts +3 -3
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "squiffy-runtime",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.3",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/textadventures/squiffy.git",
|
|
7
|
+
"directory": "runtime"
|
|
8
|
+
},
|
|
4
9
|
"type": "module",
|
|
5
10
|
"main": "dist/squiffy.runtime.js",
|
|
6
|
-
"types": "dist/squiffy.runtime.d.ts",
|
|
11
|
+
"types": "dist/src/squiffy.runtime.d.ts",
|
|
7
12
|
"exports": {
|
|
8
13
|
".": {
|
|
9
|
-
"types": "./dist/squiffy.runtime.d.ts",
|
|
14
|
+
"types": "./dist/src/squiffy.runtime.d.ts",
|
|
10
15
|
"default": "./dist/squiffy.runtime.js"
|
|
11
16
|
},
|
|
12
17
|
"./squiffy.runtime.css": "./dist/squiffy.runtime.css",
|
|
13
18
|
"./dist/squiffy.runtime.global.js": "./dist/squiffy.runtime.global.js",
|
|
14
|
-
"./dist/squiffy.runtime.css": "./dist/squiffy.runtime.css"
|
|
15
|
-
"./dist/events": {
|
|
16
|
-
"types": "./dist/events.d.ts",
|
|
17
|
-
"default": "./dist/events.js"
|
|
18
|
-
}
|
|
19
|
+
"./dist/squiffy.runtime.css": "./dist/squiffy.runtime.css"
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|
|
21
22
|
"dev": "vitest",
|
|
@@ -32,19 +33,20 @@
|
|
|
32
33
|
"license": "MIT",
|
|
33
34
|
"description": "",
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@types/jsdom": "^
|
|
36
|
+
"@types/jsdom": "^30.0.0",
|
|
36
37
|
"css.escape": "^1.5.1",
|
|
37
|
-
"
|
|
38
|
-
"jsdom": "^
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"vite
|
|
38
|
+
"esbuild": "^0.28.2",
|
|
39
|
+
"global-jsdom": "^29.0.0",
|
|
40
|
+
"jsdom": "^30.0.1",
|
|
41
|
+
"squiffy-compiler": "^6.0.0-beta.3",
|
|
42
|
+
"typescript": "^6.0.3",
|
|
43
|
+
"vite": "^8.2.2",
|
|
44
|
+
"vite-plugin-dts": "^5.1.0"
|
|
43
45
|
},
|
|
44
46
|
"dependencies": {
|
|
45
|
-
"animejs": "^4.
|
|
46
|
-
"handlebars": "^4.7.
|
|
47
|
-
"marked": "^
|
|
47
|
+
"animejs": "^4.5.0",
|
|
48
|
+
"handlebars": "^4.7.10",
|
|
49
|
+
"marked": "^18.0.11"
|
|
48
50
|
},
|
|
49
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "d932cf0684a7fa941dc8097bcc430761949e07fb"
|
|
50
52
|
}
|
|
@@ -26,7 +26,9 @@ exports[`Click a passage link 2`] = `
|
|
|
26
26
|
<p>And this goes to the <a class="squiffy-link link-section" data-section="section2" role="link" tabindex="0">next section</a>.</p>
|
|
27
27
|
<p>This line has links to <a class="squiffy-link link-section" data-section="section 3" role="link" tabindex="0">section 3</a> and <a class="squiffy-link link-section" data-section="section four" role="link" tabindex="0">section 4</a>.</p>
|
|
28
28
|
<p>This line has links to <a class="squiffy-link link-passage" data-passage="passage 3" role="link" tabindex="0">passage 3</a> and <a class="squiffy-link link-passage" data-passage="passage four" role="link" tabindex="0">passage 4</a>.</p>
|
|
29
|
-
<p>Oh look - <a class="squiffy-link link-passage" data-passage="it's a passage with an apostrophe" role="link" tabindex="0">it's a passage with an apostrophe</a>.</p></div></div><div class="squiffy-output-passage" data-passage="passage" data-undo="{"_turncount":0,"_seen_sections":["Introduction"]}"><div class="squiffy-output-block"><div data-source="[[Introduction]][passage]"><p>Here's some text for the passage.</p
|
|
29
|
+
<p>Oh look - <a class="squiffy-link link-passage" data-passage="it's a passage with an apostrophe" role="link" tabindex="0">it's a passage with an apostrophe</a>.</p></div></div><div class="squiffy-output-passage" data-passage="passage" data-undo="{"_turncount":0,"_seen_sections":["Introduction"]}"><div class="squiffy-output-block"><div data-source="[[Introduction]][passage]"><p>Here's some text for the passage.</p>
|
|
30
|
+
<p>This passage has a picture in it. It's by <a href="https://unsplash.com/@lmablankers?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Lars Blankers</a> on <a href="https://unsplash.com/photos/brown-potato-lot-B0s3Xndk6tw?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>.</p>
|
|
31
|
+
<p><img src="lars-blankers-B0s3Xndk6tw-unsplash.jpg" alt=""></p></div></div></div></div></div>"
|
|
30
32
|
`;
|
|
31
33
|
|
|
32
34
|
exports[`Click a passage link and go back 1`] = `
|
package/src/linkHandler.ts
CHANGED
package/src/plugins/animate.ts
CHANGED
|
@@ -86,7 +86,7 @@ export function AnimatePlugin(): SquiffyPlugin {
|
|
|
86
86
|
init(sq: PluginHost) {
|
|
87
87
|
squiffy = sq;
|
|
88
88
|
|
|
89
|
-
squiffy.registerHelper("animate", function(name: string, options) {
|
|
89
|
+
squiffy.registerHelper("animate", function(this: any, name: string, options) {
|
|
90
90
|
const content = options.fn(this);
|
|
91
91
|
const dataset: Record<string, any> = {
|
|
92
92
|
name,
|
|
@@ -7,10 +7,10 @@ export function ReplaceLabel() : SquiffyPlugin {
|
|
|
7
7
|
return {
|
|
8
8
|
name: "replaceLabel",
|
|
9
9
|
init(squiffy: PluginHost) {
|
|
10
|
-
squiffy.registerHelper("label", function(name: string, options) {
|
|
10
|
+
squiffy.registerHelper("label", function(this: any, name: string, options) {
|
|
11
11
|
return new Handlebars.SafeString(`<span class="squiffy-label-${name}">${options.fn(this)}</span>`);
|
|
12
12
|
});
|
|
13
|
-
squiffy.registerHelper("replace", function(name: string, options) {
|
|
13
|
+
squiffy.registerHelper("replace", function(this: any, name: string, options) {
|
|
14
14
|
const result = options.fn(this);
|
|
15
15
|
const element = squiffy.outputElement.querySelector<HTMLElement>(`.squiffy-label-${name}`);
|
|
16
16
|
if (element) {
|
|
@@ -25,7 +25,7 @@ export function RotateSequencePlugin() : SquiffyPlugin {
|
|
|
25
25
|
|
|
26
26
|
const handleLink = (squiffy: PluginHost, link: HTMLElement, isRotate: boolean) => {
|
|
27
27
|
const result: HandleLinkResult = {};
|
|
28
|
-
const options = JSON.parse(link.getAttribute("data-options")) as string[] || [];
|
|
28
|
+
const options = JSON.parse(link.getAttribute("data-options") ?? "[]") as string[] || [];
|
|
29
29
|
|
|
30
30
|
const rotateResult = rotate(options, isRotate ? link.getAttribute("data-value") : "");
|
|
31
31
|
|
package/src/squiffy.runtime.ts
CHANGED
|
@@ -11,13 +11,14 @@ import { imports } from "./import.js";
|
|
|
11
11
|
import { areInputsValid, setupInputValidation } from "./inputValidation.js";
|
|
12
12
|
|
|
13
13
|
export type { SquiffyApi } from "./types.js";
|
|
14
|
+
export type { SquiffyEventHandler, SquiffyEventMap } from "./events.js";
|
|
14
15
|
|
|
15
16
|
export const init = async (options: SquiffyInitOptions): Promise<SquiffyApi> => {
|
|
16
17
|
let story: Story;
|
|
17
18
|
let currentSection: Section;
|
|
18
19
|
let currentSectionElement: HTMLElement;
|
|
19
|
-
let currentPassageElement: HTMLElement;
|
|
20
|
-
let currentBlockOutputElement: HTMLElement;
|
|
20
|
+
let currentPassageElement: HTMLElement | null;
|
|
21
|
+
let currentBlockOutputElement: HTMLElement | null;
|
|
21
22
|
let scrollPosition = 0;
|
|
22
23
|
const emitter = new Emitter<SquiffyEventMap>();
|
|
23
24
|
const transitions: (() => Promise<void>)[] = [];
|
|
@@ -462,6 +463,7 @@ export const init = async (options: SquiffyInitOptions): Promise<SquiffyApi> =>
|
|
|
462
463
|
|
|
463
464
|
function unClearScreen() {
|
|
464
465
|
const clearStack = getClearStack();
|
|
466
|
+
if (!clearStack) return;
|
|
465
467
|
for (const child of [...outputElement.children]) {
|
|
466
468
|
if (child !== clearStack) {
|
|
467
469
|
child.remove();
|
|
@@ -499,7 +501,7 @@ export const init = async (options: SquiffyInitOptions): Promise<SquiffyApi> =>
|
|
|
499
501
|
|
|
500
502
|
div.innerHTML = html;
|
|
501
503
|
pluginManager.onWrite(div);
|
|
502
|
-
currentBlockOutputElement
|
|
504
|
+
currentBlockOutputElement!.appendChild(div);
|
|
503
505
|
|
|
504
506
|
// Setup validation for any new inputs that were just added
|
|
505
507
|
setupInputValidation(currentSectionElement);
|
|
@@ -515,7 +517,7 @@ export const init = async (options: SquiffyInitOptions): Promise<SquiffyApi> =>
|
|
|
515
517
|
// do nothing
|
|
516
518
|
}
|
|
517
519
|
else if (settings.scroll === "element") {
|
|
518
|
-
outputElement.lastElementChild
|
|
520
|
+
outputElement.lastElementChild?.scrollIntoView({ block: "end", inline: "nearest", behavior: "smooth" });
|
|
519
521
|
}
|
|
520
522
|
else {
|
|
521
523
|
let scrollTo = scrollPosition;
|
|
@@ -555,7 +557,7 @@ export const init = async (options: SquiffyInitOptions): Promise<SquiffyApi> =>
|
|
|
555
557
|
const allSectionElements = outputElement.querySelectorAll<HTMLElement>(".squiffy-output-section:last-child");
|
|
556
558
|
currentSectionElement = allSectionElements[allSectionElements.length - 1];
|
|
557
559
|
const sectionName = currentSectionElement.getAttribute("data-section");
|
|
558
|
-
currentSection = story.sections[sectionName];
|
|
560
|
+
currentSection = story.sections[sectionName!];
|
|
559
561
|
}
|
|
560
562
|
|
|
561
563
|
function setCurrentPassageElement() {
|
package/src/textProcessor.ts
CHANGED
|
@@ -174,14 +174,16 @@ export class TextProcessor {
|
|
|
174
174
|
return result;
|
|
175
175
|
};
|
|
176
176
|
|
|
177
|
+
const escapeAttr = (s: string) => s.replace(/&/g, "&").replace(/"/g, """);
|
|
178
|
+
|
|
177
179
|
this.handlebars.registerHelper("section", (section: string, options) => {
|
|
178
180
|
const text = options.hash.text as string || section;
|
|
179
|
-
return new Handlebars.SafeString(`<a class="squiffy-link link-section" data-section="${section}"${addAdditionalParameters(options)} role="link" tabindex="0">${text}</a>`);
|
|
181
|
+
return new Handlebars.SafeString(`<a class="squiffy-link link-section" data-section="${escapeAttr(section)}"${addAdditionalParameters(options)} role="link" tabindex="0">${text}</a>`);
|
|
180
182
|
});
|
|
181
183
|
|
|
182
184
|
this.handlebars.registerHelper("passage", (passage: string, options) => {
|
|
183
185
|
const text = options.hash.text as string || passage;
|
|
184
|
-
return new Handlebars.SafeString(`<a class="squiffy-link link-passage" data-passage="${passage}"${addAdditionalParameters(options)} role="link" tabindex="0">${text}</a>`);
|
|
186
|
+
return new Handlebars.SafeString(`<a class="squiffy-link link-passage" data-passage="${escapeAttr(passage)}"${addAdditionalParameters(options)} role="link" tabindex="0">${text}</a>`);
|
|
185
187
|
});
|
|
186
188
|
}
|
|
187
189
|
|
package/src/updater.ts
CHANGED
|
@@ -30,7 +30,7 @@ export function updateStory(oldStory: Story,
|
|
|
30
30
|
// Record which passage links are disabled
|
|
31
31
|
const disabledPassages = Array.from(element
|
|
32
32
|
.querySelectorAll("a.link-passage.disabled"))
|
|
33
|
-
.map((el:
|
|
33
|
+
.map((el: Element) => el.getAttribute("data-passage"));
|
|
34
34
|
|
|
35
35
|
element.innerHTML = text;
|
|
36
36
|
|
|
@@ -49,7 +49,7 @@ export function updateStory(oldStory: Story,
|
|
|
49
49
|
// section has been deleted
|
|
50
50
|
for (const element of elements) {
|
|
51
51
|
const parentOutputSection = element.closest(".squiffy-output-section");
|
|
52
|
-
parentOutputSection
|
|
52
|
+
parentOutputSection?.remove();
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
@@ -82,7 +82,7 @@ export function updateStory(oldStory: Story,
|
|
|
82
82
|
// passage has been deleted
|
|
83
83
|
for (const element of elements) {
|
|
84
84
|
const parentOutputPassage = element.closest(".squiffy-output-passage");
|
|
85
|
-
parentOutputPassage
|
|
85
|
+
parentOutputPassage?.remove();
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
else {
|