squiffy-runtime 7.0.0-beta.2 → 7.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/preview-html.js +1 -1
- package/dist/squiffy.preview.html +67 -64
- package/dist/squiffy.runtime.global.js +67 -64
- package/dist/squiffy.runtime.global.js.map +1 -1
- package/dist/squiffy.runtime.js +3250 -3157
- package/dist/squiffy.runtime.js.map +1 -1
- package/package.json +6 -6
- package/src/squiffy.runtime.test.ts +30 -0
- package/src/squiffy.runtime.ts +18 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "squiffy-runtime",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/textadventures/squiffy.git",
|
|
@@ -48,16 +48,16 @@
|
|
|
48
48
|
"css.escape": "^1.5.1",
|
|
49
49
|
"esbuild": "^0.28.2",
|
|
50
50
|
"global-jsdom": "^31.0.0",
|
|
51
|
-
"jsdom": "^31.0.
|
|
52
|
-
"squiffy-compiler": "^7.0.0-beta.
|
|
51
|
+
"jsdom": "^31.0.1",
|
|
52
|
+
"squiffy-compiler": "^7.0.0-beta.3",
|
|
53
53
|
"typescript": "^6.0.3",
|
|
54
|
-
"vite": "^8.3.
|
|
54
|
+
"vite": "^8.3.8",
|
|
55
55
|
"vite-plugin-dts": "^5.1.2"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"animejs": "^4.5.0",
|
|
59
59
|
"handlebars": "^4.7.10",
|
|
60
|
-
"marked": "^18.
|
|
60
|
+
"marked": "^18.2.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "016f53cc52dc2cf504787ef8329740ca2cf8d481"
|
|
63
63
|
}
|
|
@@ -470,6 +470,36 @@ Three.
|
|
|
470
470
|
expect(visibleText(element)).toBe("Two. a three");
|
|
471
471
|
});
|
|
472
472
|
|
|
473
|
+
test("Clearing the screen scrolls up to the top of the output", async () => {
|
|
474
|
+
// https://github.com/textadventures/squiffy/issues/54
|
|
475
|
+
const script = `
|
|
476
|
+
[[start]]:
|
|
477
|
+
Start. [[two]]
|
|
478
|
+
|
|
479
|
+
[[two]]:
|
|
480
|
+
Two. [[three]]
|
|
481
|
+
|
|
482
|
+
[[three]]:
|
|
483
|
+
@clear
|
|
484
|
+
Three.
|
|
485
|
+
`;
|
|
486
|
+
const { squiffyApi, element } = await initScript(script);
|
|
487
|
+
|
|
488
|
+
// The reader has scrolled down to 500px, and the output starts 20px from the top of the page
|
|
489
|
+
Object.defineProperty(document.documentElement, "scrollTop", { configurable: true, get: () => 500 });
|
|
490
|
+
(element.firstElementChild as HTMLElement).getBoundingClientRect = () => ({ top: -480 }) as DOMRect;
|
|
491
|
+
const scrollTo = vi.fn();
|
|
492
|
+
window.scrollTo = scrollTo;
|
|
493
|
+
|
|
494
|
+
// No clear, so no scrolling up
|
|
495
|
+
await squiffyApi.clickLink(findLink(element, "section", "two"));
|
|
496
|
+
expect(scrollTo).not.toHaveBeenCalled();
|
|
497
|
+
|
|
498
|
+
await squiffyApi.clickLink(findLink(element, "section", "three"));
|
|
499
|
+
expect(scrollTo).toHaveBeenCalledTimes(1);
|
|
500
|
+
expect(scrollTo).toHaveBeenCalledWith({ top: 20, behavior: "smooth" });
|
|
501
|
+
});
|
|
502
|
+
|
|
473
503
|
test("Run JavaScript functions", async () => {
|
|
474
504
|
const script = `
|
|
475
505
|
document.getElementById('test').innerText = 'Initial JavaScript';
|
package/src/squiffy.runtime.ts
CHANGED
|
@@ -21,6 +21,8 @@ export const init = async (options: SquiffyInitOptions): Promise<SquiffyApi> =>
|
|
|
21
21
|
let currentPassageElement: HTMLElement | null;
|
|
22
22
|
let currentBlockOutputElement: HTMLElement | null;
|
|
23
23
|
let scrollPosition = 0;
|
|
24
|
+
// Set when the screen is cleared, so the next scroll goes up to the top of the new screen (#54)
|
|
25
|
+
let scrollToTop = false;
|
|
24
26
|
const emitter = new Emitter<SquiffyEventMap>();
|
|
25
27
|
const transitions: (() => Promise<void>)[] = [];
|
|
26
28
|
let runningTransitions = false;
|
|
@@ -461,6 +463,7 @@ export const init = async (options: SquiffyInitOptions): Promise<SquiffyApi> =>
|
|
|
461
463
|
|
|
462
464
|
const clearStackItem = document.createElement("div");
|
|
463
465
|
clearStack.appendChild(clearStackItem);
|
|
466
|
+
scrollToTop = true;
|
|
464
467
|
|
|
465
468
|
// Move everything in the outputElement (except the clearStack itself) into the new clearStackItem
|
|
466
469
|
for (const child of [...outputElement.children]) {
|
|
@@ -528,6 +531,21 @@ export const init = async (options: SquiffyInitOptions): Promise<SquiffyApi> =>
|
|
|
528
531
|
if (settings.scroll === "none") {
|
|
529
532
|
// do nothing
|
|
530
533
|
}
|
|
534
|
+
else if (scrollToTop) {
|
|
535
|
+
// The screen was cleared, so the new text starts at the top of the output, which may be
|
|
536
|
+
// above where the reader has scrolled to.
|
|
537
|
+
scrollToTop = false;
|
|
538
|
+
if (settings.scroll === "element") {
|
|
539
|
+
currentSectionElement.scrollIntoView({ block: "start", inline: "nearest", behavior: "smooth" });
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
const currentScrollTop = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
|
|
543
|
+
const outputTop = outputElement.getBoundingClientRect().top + currentScrollTop;
|
|
544
|
+
if (outputTop < currentScrollTop) {
|
|
545
|
+
window.scrollTo({ top: outputTop, behavior: "smooth" });
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
531
549
|
else if (settings.scroll === "element") {
|
|
532
550
|
outputElement.lastElementChild?.scrollIntoView({ block: "end", inline: "nearest", behavior: "smooth" });
|
|
533
551
|
}
|