squiffy-runtime 6.0.0-beta.2 → 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/package.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "squiffy-runtime",
3
- "version": "6.0.0-beta.2",
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": "^21.1.7",
36
+ "@types/jsdom": "^30.0.0",
36
37
  "css.escape": "^1.5.1",
37
- "global-jsdom": "^25.0.0",
38
- "jsdom": "^25.0.0",
39
- "squiffy-compiler": "^6.0.0-beta.2",
40
- "typescript": "^5.6.2",
41
- "vite": "^7.1.3",
42
- "vite-plugin-dts": "^4.5.4"
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.1.3",
46
- "handlebars": "^4.7.8",
47
- "marked": "^16.2.0"
47
+ "animejs": "^4.5.0",
48
+ "handlebars": "^4.7.10",
49
+ "marked": "^18.0.11"
48
50
  },
49
- "gitHead": "d8f215aafa4534ddff8ecee0f8eaa4dd3eb9a46a"
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="{&quot;_turncount&quot;:0,&quot;_seen_sections&quot;:[&quot;Introduction&quot;]}"><div class="squiffy-output-block"><div data-source="[[Introduction]][passage]"><p>Here's some text for the passage.</p></div></div></div></div></div>"
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="{&quot;_turncount&quot;:0,&quot;_seen_sections&quot;:[&quot;Introduction&quot;]}"><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&amp;utm_medium=referral&amp;utm_content=creditCopyText">Lars Blankers</a> on <a href="https://unsplash.com/photos/brown-potato-lot-B0s3Xndk6tw?utm_source=unsplash&amp;utm_medium=referral&amp;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`] = `
@@ -13,6 +13,6 @@ export class LinkHandler {
13
13
  if (handler) {
14
14
  return [true, type, handler(link)];
15
15
  }
16
- return [false, type, null];
16
+ return [false, type, {}];
17
17
  }
18
18
  }
@@ -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
 
@@ -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.appendChild(div);
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.scrollIntoView({ block: "end", inline: "nearest", behavior: "smooth" });
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() {
@@ -174,14 +174,16 @@ export class TextProcessor {
174
174
  return result;
175
175
  };
176
176
 
177
+ const escapeAttr = (s: string) => s.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
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: HTMLElement) => el.getAttribute("data-passage"));
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.remove();
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.remove();
85
+ parentOutputPassage?.remove();
86
86
  }
87
87
  }
88
88
  else {