questmark-webrenderer 1.0.10 → 1.0.12
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/.github/workflows/deploy.yml +63 -0
- package/README.md +54 -56
- package/dist/main.js +1 -1
- package/dist/webRender-basic.js +1 -1
- package/main.mjs +23 -23
- package/package.json +5 -4
- package/site/index.html +102 -0
- package/webRender-basic.js +62 -62
- package/webpack.config.js +31 -31
package/dist/webRender-basic.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let firstTime=!1,log=()=>{console.log(arguments)},clear=()=>{window.logElement.clear()};window.choices=e=>{console.table&&console.table(e);const t=document.createElement("div");return t.setAttribute("style","\n display: grid;\n align-content: stretch;\n justify-content: start;\n align-items: center;\n justify-items: start;\n "),window.logElement.appendChild(t),new Promise((
|
|
1
|
+
let firstTime=!1,log=()=>{console.log(arguments)},clear=()=>{window.logElement.clear()};window.choices=e=>{console.table&&console.table(e);const t=document.createElement("div");return t.setAttribute("style","\n display: grid;\n align-content: stretch;\n justify-content: start;\n align-items: center;\n justify-items: start;\n "),window.logElement.appendChild(t),new Promise((n,o)=>{e.forEach(e=>{const o=document.createElement("button");o.textContent=e.title,o.classList.add("questmark");const l=new CustomEvent("selectQuestmarkOption",{detail:e});window.dispatchEvent(l),o.onclick=()=>{clear(),console.log(`Picked #${e.id}: "${e.title}" `),n(e.id)},t.appendChild(o)})})},window.emit=e=>{if(!1===firstTime){document.body.textContent="",firstTime=!0;const e=document.createElement("style");e.textContent="span.questmark {\n white-space: pre-line;\n }",document.head.appendChild(e),window.logElement=document.createElement("div"),document.body.appendChild(window.logElement),log=e=>{console.log(e);const t=document.createElement("span");t.textContent=e,t.classList.add("questmark"),window.logElement.appendChild(t)},clear=()=>{window.logElement.innerHTML=""}}log(e)};
|
package/main.mjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { QuestVM, parseMarkdown } from "questmark";
|
|
2
|
-
|
|
3
|
-
const vm = new QuestVM(body => {
|
|
4
|
-
globalThis.emit(body);
|
|
5
|
-
}, (choices) => {
|
|
6
|
-
return globalThis.choices(choices);
|
|
7
|
-
}, globalThis.extraForeignFunctions ? globalThis.extraForeignFunctions : {});
|
|
8
|
-
|
|
9
|
-
const vmState = parseMarkdown(document.body.textContent).qvmState;
|
|
10
|
-
console.log(vmState);
|
|
11
|
-
vm.loadVMState(vmState);
|
|
12
|
-
let run = true;
|
|
13
|
-
if (globalThis.preRun) {
|
|
14
|
-
let result = globalThis.preRun(vm);
|
|
15
|
-
if (result === false) {
|
|
16
|
-
run = false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (run) {
|
|
20
|
-
vm.run();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
globalThis.vm = vm;
|
|
1
|
+
import { QuestVM, parseMarkdown } from "questmark";
|
|
2
|
+
|
|
3
|
+
const vm = new QuestVM(body => {
|
|
4
|
+
globalThis.emit(body);
|
|
5
|
+
}, (choices) => {
|
|
6
|
+
return globalThis.choices(choices);
|
|
7
|
+
}, globalThis.extraForeignFunctions ? globalThis.extraForeignFunctions : {});
|
|
8
|
+
|
|
9
|
+
const vmState = parseMarkdown(document.body.textContent).qvmState;
|
|
10
|
+
console.log(vmState);
|
|
11
|
+
vm.loadVMState(vmState);
|
|
12
|
+
let run = true;
|
|
13
|
+
if (globalThis.preRun) {
|
|
14
|
+
let result = globalThis.preRun(vm);
|
|
15
|
+
if (result === false) {
|
|
16
|
+
run = false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (run) {
|
|
20
|
+
vm.run();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
globalThis.vm = vm;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "questmark-webrenderer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "A simple inline parser and renderer for Questmark, to create live testable Questmark documents easily",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
"author": "",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"copy-webpack-plugin": "^
|
|
14
|
+
"copy-webpack-plugin": "^14.0.0",
|
|
15
|
+
"terser-webpack-plugin": "^5.6.1",
|
|
15
16
|
"webpack": "^5.54.0",
|
|
16
|
-
"webpack-cli": "^
|
|
17
|
+
"webpack-cli": "^7.2.3"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"questmark": "^0.0.
|
|
20
|
+
"questmark": "^0.0.37"
|
|
20
21
|
}
|
|
21
22
|
}
|
package/site/index.html
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Questmark webrenderer</title>
|
|
7
|
+
<meta name="description" content="A simple inline parser, interpreter and renderer for Questmark documents, so you can write and play them directly in the browser.">
|
|
8
|
+
<style>
|
|
9
|
+
:root {
|
|
10
|
+
--bg: #f7f6f3;
|
|
11
|
+
--fg: #1d1c1a;
|
|
12
|
+
--muted: #6b6a66;
|
|
13
|
+
--accent: #7c4dff;
|
|
14
|
+
--card: #ffffff;
|
|
15
|
+
--border: #e5e3de;
|
|
16
|
+
}
|
|
17
|
+
* { box-sizing: border-box; }
|
|
18
|
+
body {
|
|
19
|
+
margin: 0;
|
|
20
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
21
|
+
background: var(--bg);
|
|
22
|
+
color: var(--fg);
|
|
23
|
+
line-height: 1.55;
|
|
24
|
+
}
|
|
25
|
+
main { max-width: 720px; margin: 0 auto; padding: 4rem 1.5rem; }
|
|
26
|
+
h1 { font-size: 2.1rem; margin: 0 0 0.35rem; }
|
|
27
|
+
.subtitle { color: var(--muted); margin: 0 0 2.5rem; }
|
|
28
|
+
h2 {
|
|
29
|
+
font-size: 0.85rem;
|
|
30
|
+
text-transform: uppercase;
|
|
31
|
+
letter-spacing: 0.08em;
|
|
32
|
+
color: var(--muted);
|
|
33
|
+
margin: 2.5rem 0 1rem;
|
|
34
|
+
}
|
|
35
|
+
ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
|
|
36
|
+
li a {
|
|
37
|
+
display: block;
|
|
38
|
+
background: var(--card);
|
|
39
|
+
border: 1px solid var(--border);
|
|
40
|
+
border-radius: 10px;
|
|
41
|
+
padding: 1.1rem 1.3rem;
|
|
42
|
+
color: inherit;
|
|
43
|
+
text-decoration: none;
|
|
44
|
+
transition: border-color 0.15s, box-shadow 0.15s;
|
|
45
|
+
}
|
|
46
|
+
li a:hover, li a:focus { border-color: var(--accent); box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
|
|
47
|
+
.title { font-weight: 600; font-size: 1.1rem; }
|
|
48
|
+
li a:hover .title, li a:focus .title { color: var(--accent); }
|
|
49
|
+
.desc { color: var(--muted); margin-top: 0.15rem; font-size: 0.95rem; }
|
|
50
|
+
p code, li code { background: #ecebe7; padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.9em; }
|
|
51
|
+
pre {
|
|
52
|
+
background: #1d1c1a;
|
|
53
|
+
color: #f7f6f3;
|
|
54
|
+
padding: 1rem 1.2rem;
|
|
55
|
+
border-radius: 10px;
|
|
56
|
+
overflow-x: auto;
|
|
57
|
+
font-size: 0.85rem;
|
|
58
|
+
}
|
|
59
|
+
footer { color: var(--muted); font-size: 0.85rem; margin-top: 3rem; }
|
|
60
|
+
footer a, main > p a { color: var(--accent); }
|
|
61
|
+
</style>
|
|
62
|
+
</head>
|
|
63
|
+
<body>
|
|
64
|
+
<main>
|
|
65
|
+
<h1>Questmark webrenderer</h1>
|
|
66
|
+
<p class="subtitle">A simple inline parser, interpreter and renderer for Questmark documents — write Questmark and play it directly in your browser.</p>
|
|
67
|
+
|
|
68
|
+
<h2>Live demos</h2>
|
|
69
|
+
<ul>
|
|
70
|
+
<li>
|
|
71
|
+
<a href="./demos/space-alien.md.html">
|
|
72
|
+
<div class="title">Space Alien</div>
|
|
73
|
+
<div class="desc">A small conversation tree demonstrating states, options, context and preconditions.</div>
|
|
74
|
+
</a>
|
|
75
|
+
</li>
|
|
76
|
+
<li>
|
|
77
|
+
<a href="./demos/foreign-function.md.html">
|
|
78
|
+
<div class="title">Foreign functions</div>
|
|
79
|
+
<div class="desc">Extending a Questmark document with custom JavaScript functions via <code>extraForeignFunctions</code>.</div>
|
|
80
|
+
</a>
|
|
81
|
+
</li>
|
|
82
|
+
<li>
|
|
83
|
+
<a href="./demos/prerun.md.html">
|
|
84
|
+
<div class="title">Pre-run hook</div>
|
|
85
|
+
<div class="desc">Modifying (or preventing) the VM before it starts, using the <code>preRun</code> global.</div>
|
|
86
|
+
</a>
|
|
87
|
+
</li>
|
|
88
|
+
</ul>
|
|
89
|
+
|
|
90
|
+
<h2>Usage</h2>
|
|
91
|
+
<p>Save your Questmark document as an <code>.html</code> file and add these two scripts at the bottom:</p>
|
|
92
|
+
<pre><script src="https://unpkg.com/questmark-webrenderer/dist/webRender-basic.js"></script>
|
|
93
|
+
<script src="https://unpkg.com/questmark-webrenderer/dist/main.js" type="module"></script></pre>
|
|
94
|
+
<p>Then open the file in your browser. See the <a href="https://github.com/jorisvddonk/questmark-webrenderer#readme">README</a> for the full details and customization options.</p>
|
|
95
|
+
|
|
96
|
+
<footer>
|
|
97
|
+
Part of <a href="https://github.com/jorisvddonk/questmark">Questmark</a>.
|
|
98
|
+
Source: <a href="https://github.com/jorisvddonk/questmark-webrenderer">questmark-webrenderer</a>.
|
|
99
|
+
</footer>
|
|
100
|
+
</main>
|
|
101
|
+
</body>
|
|
102
|
+
</html>
|
package/webRender-basic.js
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
let firstTime = false;
|
|
2
|
-
let log = () => {
|
|
3
|
-
console.log(arguments);
|
|
4
|
-
};
|
|
5
|
-
let clear = () => {
|
|
6
|
-
window.logElement.clear();
|
|
7
|
-
};
|
|
8
|
-
window.choices = (choices) => {
|
|
9
|
-
if (console.table) {
|
|
10
|
-
console.table(choices);
|
|
11
|
-
}
|
|
12
|
-
const buttonsRoot = document.createElement('div');
|
|
13
|
-
buttonsRoot.setAttribute('style', `
|
|
14
|
-
display: grid;
|
|
15
|
-
align-content: stretch;
|
|
16
|
-
justify-content: start;
|
|
17
|
-
align-items: center;
|
|
18
|
-
justify-items: start;
|
|
19
|
-
`);
|
|
20
|
-
window.logElement.appendChild(buttonsRoot);
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
choices.forEach(element => {
|
|
23
|
-
const button = document.createElement('button');
|
|
24
|
-
button.textContent = element.title;
|
|
25
|
-
button.classList.add('questmark');
|
|
26
|
-
const event = new CustomEvent('selectQuestmarkOption', { detail: element });
|
|
27
|
-
window.dispatchEvent(event);
|
|
28
|
-
button.onclick = () => {
|
|
29
|
-
clear();
|
|
30
|
-
console.log(`Picked #${element.id}: "${element.title}" `);
|
|
31
|
-
resolve(element.id);
|
|
32
|
-
}
|
|
33
|
-
buttonsRoot.appendChild(button);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
window.emit = (body) => {
|
|
38
|
-
if (firstTime === false) {
|
|
39
|
-
document.body.textContent = '';
|
|
40
|
-
firstTime = true;
|
|
41
|
-
|
|
42
|
-
const style = document.createElement('style');
|
|
43
|
-
style.textContent = `span.questmark {
|
|
44
|
-
white-space: pre-line;
|
|
45
|
-
}`;
|
|
46
|
-
document.head.appendChild(style);
|
|
47
|
-
|
|
48
|
-
window.logElement = document.createElement('div');
|
|
49
|
-
document.body.appendChild(window.logElement);
|
|
50
|
-
log = (body) => {
|
|
51
|
-
console.log(body);
|
|
52
|
-
const span = document.createElement('span');
|
|
53
|
-
span.textContent = body;
|
|
54
|
-
span.classList.add('questmark');
|
|
55
|
-
window.logElement.appendChild(span);
|
|
56
|
-
}
|
|
57
|
-
clear = () => {
|
|
58
|
-
window.logElement.innerHTML = "";
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
log(body);
|
|
62
|
-
};
|
|
1
|
+
let firstTime = false;
|
|
2
|
+
let log = () => {
|
|
3
|
+
console.log(arguments);
|
|
4
|
+
};
|
|
5
|
+
let clear = () => {
|
|
6
|
+
window.logElement.clear();
|
|
7
|
+
};
|
|
8
|
+
window.choices = (choices) => {
|
|
9
|
+
if (console.table) {
|
|
10
|
+
console.table(choices);
|
|
11
|
+
}
|
|
12
|
+
const buttonsRoot = document.createElement('div');
|
|
13
|
+
buttonsRoot.setAttribute('style', `
|
|
14
|
+
display: grid;
|
|
15
|
+
align-content: stretch;
|
|
16
|
+
justify-content: start;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-items: start;
|
|
19
|
+
`);
|
|
20
|
+
window.logElement.appendChild(buttonsRoot);
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
choices.forEach(element => {
|
|
23
|
+
const button = document.createElement('button');
|
|
24
|
+
button.textContent = element.title;
|
|
25
|
+
button.classList.add('questmark');
|
|
26
|
+
const event = new CustomEvent('selectQuestmarkOption', { detail: element });
|
|
27
|
+
window.dispatchEvent(event);
|
|
28
|
+
button.onclick = () => {
|
|
29
|
+
clear();
|
|
30
|
+
console.log(`Picked #${element.id}: "${element.title}" `);
|
|
31
|
+
resolve(element.id);
|
|
32
|
+
}
|
|
33
|
+
buttonsRoot.appendChild(button);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
window.emit = (body) => {
|
|
38
|
+
if (firstTime === false) {
|
|
39
|
+
document.body.textContent = '';
|
|
40
|
+
firstTime = true;
|
|
41
|
+
|
|
42
|
+
const style = document.createElement('style');
|
|
43
|
+
style.textContent = `span.questmark {
|
|
44
|
+
white-space: pre-line;
|
|
45
|
+
}`;
|
|
46
|
+
document.head.appendChild(style);
|
|
47
|
+
|
|
48
|
+
window.logElement = document.createElement('div');
|
|
49
|
+
document.body.appendChild(window.logElement);
|
|
50
|
+
log = (body) => {
|
|
51
|
+
console.log(body);
|
|
52
|
+
const span = document.createElement('span');
|
|
53
|
+
span.textContent = body;
|
|
54
|
+
span.classList.add('questmark');
|
|
55
|
+
window.logElement.appendChild(span);
|
|
56
|
+
}
|
|
57
|
+
clear = () => {
|
|
58
|
+
window.logElement.innerHTML = "";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
log(body);
|
|
62
|
+
};
|
package/webpack.config.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const CopyPlugin = require("copy-webpack-plugin");
|
|
3
|
-
const TerserPlugin = require('terser-webpack-plugin');
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
entry: './main.mjs',
|
|
7
|
-
output: {
|
|
8
|
-
filename: 'main.js',
|
|
9
|
-
path: path.resolve(__dirname, 'dist'),
|
|
10
|
-
},
|
|
11
|
-
resolve: { fallback: { fs: false } },
|
|
12
|
-
optimization: {
|
|
13
|
-
minimize: true,
|
|
14
|
-
mangleExports: false,
|
|
15
|
-
minimizer: [
|
|
16
|
-
new TerserPlugin({
|
|
17
|
-
parallel: true,
|
|
18
|
-
terserOptions: {
|
|
19
|
-
keep_classnames: true,
|
|
20
|
-
keep_fnames: true
|
|
21
|
-
},
|
|
22
|
-
}),
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
plugins: [
|
|
26
|
-
new CopyPlugin({
|
|
27
|
-
patterns: [
|
|
28
|
-
{ from: "webRender-basic.js", to: "webRender-basic.js" }
|
|
29
|
-
],
|
|
30
|
-
}),
|
|
31
|
-
],
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const CopyPlugin = require("copy-webpack-plugin");
|
|
3
|
+
const TerserPlugin = require('terser-webpack-plugin');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
entry: './main.mjs',
|
|
7
|
+
output: {
|
|
8
|
+
filename: 'main.js',
|
|
9
|
+
path: path.resolve(__dirname, 'dist'),
|
|
10
|
+
},
|
|
11
|
+
resolve: { fallback: { fs: false } },
|
|
12
|
+
optimization: {
|
|
13
|
+
minimize: true,
|
|
14
|
+
mangleExports: false,
|
|
15
|
+
minimizer: [
|
|
16
|
+
new TerserPlugin({
|
|
17
|
+
parallel: true,
|
|
18
|
+
terserOptions: {
|
|
19
|
+
keep_classnames: true,
|
|
20
|
+
keep_fnames: true
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
plugins: [
|
|
26
|
+
new CopyPlugin({
|
|
27
|
+
patterns: [
|
|
28
|
+
{ from: "webRender-basic.js", to: "webRender-basic.js" }
|
|
29
|
+
],
|
|
30
|
+
}),
|
|
31
|
+
],
|
|
32
32
|
};
|