squiffy-runtime 6.0.0 → 7.0.0-beta.1
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/assets.d.ts +2 -0
- package/dist/assets.test.d.ts +1 -0
- package/dist/events.d.ts +4 -0
- package/dist/pluginManager.d.ts +2 -1
- package/dist/preview-host.d.ts +29 -0
- package/dist/preview-host.js +83 -0
- package/dist/preview-host.js.map +7 -0
- package/dist/preview-host.test.d.ts +1 -0
- package/dist/preview-html.d.ts +2 -0
- package/dist/preview-html.js +2 -0
- package/dist/preview-protocol.d.ts +53 -0
- package/dist/preview.d.ts +14 -0
- package/dist/preview.main.d.ts +1 -0
- package/dist/preview.test.d.ts +1 -0
- package/dist/squiffy.preview.html +298 -0
- package/dist/squiffy.runtime.global.js +58 -53
- package/dist/squiffy.runtime.global.js.map +1 -1
- package/dist/squiffy.runtime.js +2146 -1996
- package/dist/squiffy.runtime.js.map +1 -1
- package/dist/types.d.ts +12 -1
- package/dist/types.plugins.d.ts +1 -0
- package/package.json +21 -12
- package/src/assets.test.ts +227 -0
- package/src/assets.ts +92 -0
- package/src/events.ts +1 -0
- package/src/pluginManager.ts +5 -1
- package/src/plugins/animate.ts +6 -5
- package/src/preview-host.test.ts +75 -0
- package/src/preview-host.ts +129 -0
- package/src/preview-protocol.ts +57 -0
- package/src/preview.main.ts +33 -0
- package/src/preview.test.ts +168 -0
- package/src/preview.ts +165 -0
- package/src/squiffy.runtime.ts +25 -6
- package/src/types.plugins.ts +4 -0
- package/src/types.ts +17 -1
- package/vite.preview.config.ts +72 -0
package/src/types.ts
CHANGED
|
@@ -7,6 +7,13 @@ export interface SquiffyInitOptions {
|
|
|
7
7
|
persist?: boolean,
|
|
8
8
|
storyId?: string,
|
|
9
9
|
onSet?: (attribute: string, value: any) => void,
|
|
10
|
+
/**
|
|
11
|
+
* Maps an asset path used in the story (e.g. "cat.png" in an img src) to the URL it should be
|
|
12
|
+
* loaded from. Applied to src, srcset and poster attributes, and url() in inline styles, of
|
|
13
|
+
* rendered output. Absolute URLs (http:, https:, data:, blob: etc. and protocol-relative) are
|
|
14
|
+
* left alone. When not provided, paths are used as they are.
|
|
15
|
+
*/
|
|
16
|
+
resolveAssetUrl?: (path: string) => string,
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
export interface SquiffySettings {
|
|
@@ -15,8 +22,17 @@ export interface SquiffySettings {
|
|
|
15
22
|
onSet: (attribute: string, value: any) => void,
|
|
16
23
|
}
|
|
17
24
|
|
|
25
|
+
// Where to start a story, instead of its start section or a saved game
|
|
26
|
+
export interface StartAt {
|
|
27
|
+
section: string;
|
|
28
|
+
// A passage in that section, shown after the section
|
|
29
|
+
passage?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
export interface SquiffyApi {
|
|
19
|
-
|
|
33
|
+
// Starts the story: from startAt if it's given (ignoring any saved game), otherwise from the
|
|
34
|
+
// saved game, or the story's start section.
|
|
35
|
+
begin: (startAt?: StartAt) => Promise<void>;
|
|
20
36
|
restart: () => void;
|
|
21
37
|
get: (attribute: string) => any;
|
|
22
38
|
set: (attribute: string, value: any) => void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Builds the preview page (src/preview.main.ts) as a single self-contained HTML file,
|
|
2
|
+
// dist/squiffy.preview.html, which hosts load into a sandboxed iframe with srcdoc or use as a
|
|
3
|
+
// VS Code webview's html. It's self-contained because a sandboxed frame has an opaque origin,
|
|
4
|
+
// so it can't rely on loading anything from the host's server. Also builds the host helper,
|
|
5
|
+
// dist/preview-host.js, and dist/preview-html.js, which exports the page as a string.
|
|
6
|
+
// See preview-protocol.ts, and #307 for the spike results behind this.
|
|
7
|
+
import { defineConfig } from "vite";
|
|
8
|
+
import { build } from "esbuild";
|
|
9
|
+
import { readFileSync, rmSync, writeFileSync } from "fs";
|
|
10
|
+
import { resolve } from "path";
|
|
11
|
+
|
|
12
|
+
const template = (css: string, js: string) => `<!doctype html>
|
|
13
|
+
<html lang="en">
|
|
14
|
+
<head>
|
|
15
|
+
<meta charset="utf-8">
|
|
16
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
17
|
+
<title>Squiffy preview</title>
|
|
18
|
+
<style>
|
|
19
|
+
html, body { height: 100%; margin: 0; }
|
|
20
|
+
#squiffy, .squiffy-preview-story, .squiffy-preview-story > div { height: 100%; box-sizing: border-box; }
|
|
21
|
+
.squiffy-preview-story > div { padding: 1em; }
|
|
22
|
+
${css}
|
|
23
|
+
</style>
|
|
24
|
+
</head>
|
|
25
|
+
<body>
|
|
26
|
+
<div id="squiffy"></div>
|
|
27
|
+
<script>
|
|
28
|
+
${js.replace(/<\/(script)/gi, "<\\/$1")}
|
|
29
|
+
</script>
|
|
30
|
+
</body>
|
|
31
|
+
</html>
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
build: {
|
|
36
|
+
target: "es2020",
|
|
37
|
+
minify: "esbuild",
|
|
38
|
+
emptyOutDir: false,
|
|
39
|
+
outDir: "dist/preview-build",
|
|
40
|
+
lib: {
|
|
41
|
+
entry: "src/preview.main.ts",
|
|
42
|
+
name: "squiffyPreview",
|
|
43
|
+
formats: ["iife"],
|
|
44
|
+
fileName: () => "squiffy.preview.js",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
plugins: [
|
|
48
|
+
{
|
|
49
|
+
name: "inline-preview-page",
|
|
50
|
+
async closeBundle() {
|
|
51
|
+
const js = readFileSync(resolve("dist/preview-build/squiffy.preview.js"), "utf8");
|
|
52
|
+
const css = readFileSync(resolve("src/squiffy.runtime.css"), "utf8");
|
|
53
|
+
const html = template(css, js);
|
|
54
|
+
writeFileSync(resolve("dist/squiffy.preview.html"), html);
|
|
55
|
+
writeFileSync(resolve("dist/preview-html.js"),
|
|
56
|
+
`// The Squiffy preview page, built from squiffy-runtime's src/preview.main.ts\nexport const previewHtml = ${JSON.stringify(html)};\n`);
|
|
57
|
+
writeFileSync(resolve("dist/preview-html.d.ts"),
|
|
58
|
+
"/** The Squiffy preview page, as HTML to use with setUpPreviewFrame() from squiffy-runtime/preview-host. */\nexport declare const previewHtml: string;\n");
|
|
59
|
+
rmSync(resolve("dist/preview-build"), { recursive: true, force: true });
|
|
60
|
+
|
|
61
|
+
await build({
|
|
62
|
+
entryPoints: [resolve("src/preview-host.ts")],
|
|
63
|
+
bundle: true,
|
|
64
|
+
format: "esm",
|
|
65
|
+
target: "es2020",
|
|
66
|
+
outfile: resolve("dist/preview-host.js"),
|
|
67
|
+
sourcemap: true,
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
});
|