@sccharts-lab/embed 0.0.0-stage → 0.1.0
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/LICENSE +277 -0
- package/README.md +92 -2
- package/dist/element.d.ts +112 -0
- package/dist/element.js +389 -0
- package/dist/element.js.map +1 -0
- package/dist/embed.min.js +12 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +1 -0
- package/dist/loader.js +9 -0
- package/dist/loader.js.map +1 -0
- package/dist/options.d.ts +58 -0
- package/dist/options.js +139 -0
- package/dist/options.js.map +1 -0
- package/dist/protocol.d.ts +183 -0
- package/dist/protocol.js +149 -0
- package/dist/protocol.js.map +1 -0
- package/package.json +60 -3
package/dist/element.js
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
// <sccharts-lab-chart>: a live SCCharts chart in any page. It makes the iframe of SCCharts Lab's embed (/embed/),
|
|
2
|
+
// sizes it to its content, and turns the postMessage protocol (protocol.ts) into methods and DOM events.
|
|
3
|
+
//
|
|
4
|
+
// <script src="https://sccharts.jmw.nz/embed.js" async></script>
|
|
5
|
+
// <sccharts-lab-chart example="learn/hierarchy/abro" view="sim"></sccharts-lab-chart>
|
|
6
|
+
// <sccharts-lab-chart view="full"><pre>scchart Toggle { ... }</pre></sccharts-lab-chart>
|
|
7
|
+
//
|
|
8
|
+
// The chart: `example` (a guide example), else `src` (a .sctx file the element fetches), else the element's own
|
|
9
|
+
// `<pre>`, `<textarea>` or `<script type="text/sctx">` children (several with `data-file="lib/beep.sctx"` make a
|
|
10
|
+
// project). A `<pre>` reads as code before the script runs, and stays the page's fallback without JavaScript.
|
|
11
|
+
// `run` replays a run (the playground's "Copy link to this run" encoding).
|
|
12
|
+
// Dependency-free: built on its own into /embed.js.
|
|
13
|
+
import { DEFAULT_BASE, embedUrl, estimateHeight, targetFromAttributes } from "./options.js";
|
|
14
|
+
import { envelope, parseEvent } from "./protocol.js";
|
|
15
|
+
export const TAG = 'sccharts-lab-chart';
|
|
16
|
+
/** Attributes that change the embed's address (the frame loads again). */
|
|
17
|
+
const ADDRESS = ['example', 'src', 'view', 'height', 'tick', 'tour', 'controls', 'chart', 'run', 'base'];
|
|
18
|
+
const REPLY_TIMEOUT = 15000;
|
|
19
|
+
const VIEW_WORDS = { diagram: 'diagram', sim: 'simulation', editor: 'editor', full: 'editor and simulation' };
|
|
20
|
+
/** Source text written inside HTML: the first and last blank lines and the indentation they share go. */
|
|
21
|
+
export function dedent(text) {
|
|
22
|
+
const lines = text.replace(/\r\n?/g, '\n').split('\n');
|
|
23
|
+
while (lines.length && !lines[0].trim())
|
|
24
|
+
lines.shift();
|
|
25
|
+
while (lines.length && !lines[lines.length - 1].trim())
|
|
26
|
+
lines.pop();
|
|
27
|
+
const indent = Math.min(...lines.filter(l => l.trim()).map(l => /^[ \t]*/.exec(l)[0].length));
|
|
28
|
+
return lines.map(l => l.slice(Number.isFinite(indent) ? indent : 0)).join('\n') + '\n';
|
|
29
|
+
}
|
|
30
|
+
/** The files written inside the element: `<pre>`, `<textarea>` and `<script type="text/sctx">` children, each its
|
|
31
|
+
* `data-file` (else `main.sctx`, `main-2.sctx`, ...). Undefined when there are none. */
|
|
32
|
+
export function inlineFiles(host) {
|
|
33
|
+
const blocks = [...host.children].filter(c => c.matches('pre, textarea, script[type="text/sctx"]'));
|
|
34
|
+
if (!blocks.length)
|
|
35
|
+
return undefined;
|
|
36
|
+
const files = {};
|
|
37
|
+
let active;
|
|
38
|
+
blocks.forEach((b, i) => {
|
|
39
|
+
const named = b.getAttribute('data-file')?.trim();
|
|
40
|
+
const path = named && /^[\w ./+-]+$/.test(named) ? (named.endsWith('.sctx') ? named : `${named}.sctx`) : `main${i ? `-${i + 1}` : ''}.sctx`;
|
|
41
|
+
files[path] = dedent(b.tagName === 'TEXTAREA' ? b.value : (b.textContent ?? ''));
|
|
42
|
+
if (b.hasAttribute('data-active'))
|
|
43
|
+
active = path;
|
|
44
|
+
});
|
|
45
|
+
return { files, active: active ?? Object.keys(files)[0] };
|
|
46
|
+
}
|
|
47
|
+
const STYLE = `
|
|
48
|
+
:host { display: block; position: relative; }
|
|
49
|
+
:host([hidden]) { display: none; }
|
|
50
|
+
:host([data-height='fill']) { height: 480px; }
|
|
51
|
+
iframe { display: block; width: 100%; height: 100%; border: 0; background: transparent; color-scheme: light; }
|
|
52
|
+
.sclab-error { margin: 0; padding: 0.75em 1em; border: 1px solid #d4c23a; border-radius: 6px; background: #fffbd1; color: #2b2a1e; font: 0.875rem/1.5 system-ui, sans-serif; }
|
|
53
|
+
`;
|
|
54
|
+
// Importable where there is no DOM (the site's build, tests): the class is only defined, never made, there.
|
|
55
|
+
const Base = (typeof HTMLElement === 'undefined' ? class {
|
|
56
|
+
} : HTMLElement);
|
|
57
|
+
export class SCChartsLabChart extends Base {
|
|
58
|
+
addEventListener(type, listener, options) {
|
|
59
|
+
super.addEventListener(type, listener, options);
|
|
60
|
+
}
|
|
61
|
+
removeEventListener(type, listener, options) {
|
|
62
|
+
super.removeEventListener(type, listener, options);
|
|
63
|
+
}
|
|
64
|
+
/** Where /embed/ is: the site the loader came from (set by `define`), else sccharts.jmw.nz. */
|
|
65
|
+
static base = DEFAULT_BASE;
|
|
66
|
+
static get observedAttributes() {
|
|
67
|
+
return [...ADDRESS, 'label', 'loading'];
|
|
68
|
+
}
|
|
69
|
+
frame;
|
|
70
|
+
message;
|
|
71
|
+
pending = new Map();
|
|
72
|
+
/** Commands waiting for the embed to be ready. */
|
|
73
|
+
queue = [];
|
|
74
|
+
nextId = 1;
|
|
75
|
+
live = false;
|
|
76
|
+
renderQueued = false;
|
|
77
|
+
generation = 0;
|
|
78
|
+
/** The frame a render is replacing: its messages are ignored meanwhile. */
|
|
79
|
+
stale;
|
|
80
|
+
origin = '';
|
|
81
|
+
chartName;
|
|
82
|
+
resolveReady;
|
|
83
|
+
readyPromise;
|
|
84
|
+
readySettled = true;
|
|
85
|
+
lastTick;
|
|
86
|
+
lastCompiled;
|
|
87
|
+
onMessage = (e) => this.receive(e);
|
|
88
|
+
constructor() {
|
|
89
|
+
super();
|
|
90
|
+
this.resetReady();
|
|
91
|
+
}
|
|
92
|
+
// ----- Lifecycle ------------------------------------------------------------------------------------------------
|
|
93
|
+
connectedCallback() {
|
|
94
|
+
window.addEventListener('message', this.onMessage);
|
|
95
|
+
// Parsed before its children (the script ran first): read them once the document is parsed.
|
|
96
|
+
if (document.readyState === 'loading')
|
|
97
|
+
document.addEventListener('DOMContentLoaded', () => this.scheduleRender(), { once: true });
|
|
98
|
+
else
|
|
99
|
+
this.scheduleRender();
|
|
100
|
+
}
|
|
101
|
+
disconnectedCallback() {
|
|
102
|
+
window.removeEventListener('message', this.onMessage);
|
|
103
|
+
const error = new Error('The chart was removed from the page.');
|
|
104
|
+
this.fail(error);
|
|
105
|
+
for (const q of this.queue.splice(0))
|
|
106
|
+
q.reject(error);
|
|
107
|
+
}
|
|
108
|
+
attributeChangedCallback(name, old, value) {
|
|
109
|
+
// Before the first render (the element being made or upgraded, its inline code perhaps not parsed yet) the
|
|
110
|
+
// render reads every attribute; after it, a change renders again, also while a chart is fetched or after a
|
|
111
|
+
// fetch failed (render's generation drops the fetch it replaces).
|
|
112
|
+
if (old === value || !this.isConnected || !this.generation)
|
|
113
|
+
return;
|
|
114
|
+
if (ADDRESS.includes(name)) {
|
|
115
|
+
this.invalidate();
|
|
116
|
+
this.scheduleRender();
|
|
117
|
+
}
|
|
118
|
+
else if (name === 'label')
|
|
119
|
+
this.updateTitle();
|
|
120
|
+
else if (name === 'loading' && this.frame)
|
|
121
|
+
this.frame.loading = value === 'eager' ? 'eager' : 'lazy';
|
|
122
|
+
}
|
|
123
|
+
scheduleRender() {
|
|
124
|
+
if (this.renderQueued)
|
|
125
|
+
return;
|
|
126
|
+
this.renderQueued = true;
|
|
127
|
+
queueMicrotask(() => {
|
|
128
|
+
this.renderQueued = false;
|
|
129
|
+
if (this.isConnected)
|
|
130
|
+
void this.render();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/** The embed's address for the attributes now, and the chart to send it (inline or fetched). */
|
|
134
|
+
async render() {
|
|
135
|
+
const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' });
|
|
136
|
+
if (!root.firstChild)
|
|
137
|
+
root.innerHTML = `<style>${STYLE}</style>`;
|
|
138
|
+
const target = this.target();
|
|
139
|
+
const base = this.getAttribute('base') || SCChartsLabChart.base;
|
|
140
|
+
this.origin = new URL(base, location.href).origin;
|
|
141
|
+
this.dataset.height = typeof target.height === 'number' ? 'fixed' : (target.height ?? 'auto');
|
|
142
|
+
this.invalidate();
|
|
143
|
+
const generation = ++this.generation;
|
|
144
|
+
// The frame on screen stays until the new one is made (no jump), but it is the old chart's: what it says (a
|
|
145
|
+
// late `ready`) is not about the chart these attributes ask for.
|
|
146
|
+
this.stale = this.frame;
|
|
147
|
+
this.message?.remove();
|
|
148
|
+
this.message = undefined;
|
|
149
|
+
let files;
|
|
150
|
+
if (!target.example) {
|
|
151
|
+
const src = this.getAttribute('src');
|
|
152
|
+
if (src) {
|
|
153
|
+
try {
|
|
154
|
+
const url = new URL(src, document.baseURI);
|
|
155
|
+
const res = await fetch(url);
|
|
156
|
+
if (!res.ok)
|
|
157
|
+
throw new Error(`${res.status} ${res.statusText}`.trim());
|
|
158
|
+
const name = decodeURIComponent(url.pathname.split('/').pop() || 'main.sctx');
|
|
159
|
+
const path = /^[\w ./+-]+\.sctx$/.test(name) ? name : 'main.sctx';
|
|
160
|
+
files = { files: { [path]: await res.text() }, active: path };
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (generation === this.generation)
|
|
164
|
+
this.showError(`The chart ${src} could not be loaded (${error instanceof Error ? error.message : String(error)}).`);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
// The attributes changed while the file was on its way: a later render has it.
|
|
168
|
+
if (generation !== this.generation)
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
else
|
|
172
|
+
files = inlineFiles(this);
|
|
173
|
+
}
|
|
174
|
+
// A run to replay (the playground's `run=`, lz-string's URL-safe letters only).
|
|
175
|
+
const run = this.getAttribute('run')?.trim();
|
|
176
|
+
const url = embedUrl(base, { ...target, ...(files ? { source: 'parent' } : {}) }, run && /^[\w+$-]+$/.test(run) ? `run=${run}` : undefined);
|
|
177
|
+
const old = this.frame;
|
|
178
|
+
const frame = document.createElement('iframe');
|
|
179
|
+
frame.setAttribute('part', 'frame');
|
|
180
|
+
frame.loading = this.getAttribute('loading') === 'eager' ? 'eager' : 'lazy';
|
|
181
|
+
frame.allow = 'clipboard-write';
|
|
182
|
+
frame.src = url;
|
|
183
|
+
if (typeof target.height === 'number')
|
|
184
|
+
frame.style.height = `${target.height}px`;
|
|
185
|
+
else if (target.height === 'auto')
|
|
186
|
+
frame.style.height = `${old?.offsetHeight || estimateHeight(target.view ?? 'sim', this.clientWidth || 640)}px`;
|
|
187
|
+
frame.addEventListener('load', () => {
|
|
188
|
+
// The embed listens from its first script on: send the chart the page holds, then what waited.
|
|
189
|
+
if (files)
|
|
190
|
+
this.post({ command: 'setFiles', files: files.files, active: files.active });
|
|
191
|
+
});
|
|
192
|
+
this.frame = frame;
|
|
193
|
+
this.stale = undefined;
|
|
194
|
+
this.live = false;
|
|
195
|
+
this.updateTitle();
|
|
196
|
+
if (old)
|
|
197
|
+
old.replaceWith(frame);
|
|
198
|
+
else
|
|
199
|
+
root.append(frame);
|
|
200
|
+
}
|
|
201
|
+
target() {
|
|
202
|
+
return targetFromAttributes(n => this.getAttribute(n));
|
|
203
|
+
}
|
|
204
|
+
showError(text) {
|
|
205
|
+
this.frame?.remove();
|
|
206
|
+
this.frame = undefined;
|
|
207
|
+
const p = document.createElement('p');
|
|
208
|
+
p.className = 'sclab-error';
|
|
209
|
+
p.setAttribute('role', 'alert');
|
|
210
|
+
p.textContent = text;
|
|
211
|
+
this.message = p;
|
|
212
|
+
this.shadowRoot?.append(p);
|
|
213
|
+
for (const q of this.queue.splice(0))
|
|
214
|
+
q.reject(new Error(text));
|
|
215
|
+
this.emit('error', { message: text });
|
|
216
|
+
}
|
|
217
|
+
updateTitle() {
|
|
218
|
+
if (!this.frame)
|
|
219
|
+
return;
|
|
220
|
+
const view = VIEW_WORDS[this.target().view ?? 'sim'];
|
|
221
|
+
this.frame.title = this.getAttribute('label') || `SCCharts Lab: ${this.chartName ?? this.target().example?.split('/').pop() ?? 'chart'} (${view})`;
|
|
222
|
+
}
|
|
223
|
+
// ----- Messages -------------------------------------------------------------------------------------------------
|
|
224
|
+
/** The page has no web origin (a frame sandboxed without allow-same-origin, as an LMS frames its pages): the embed it
|
|
225
|
+
* frames has none either, since sandbox flags pass down, so messages go to '*' and arrive from 'null'. The frame's
|
|
226
|
+
* own window, which this element made, is what identifies them then. */
|
|
227
|
+
get opaque() {
|
|
228
|
+
return self.origin === 'null';
|
|
229
|
+
}
|
|
230
|
+
receive(e) {
|
|
231
|
+
if (!this.frame || this.frame === this.stale || e.source !== this.frame.contentWindow)
|
|
232
|
+
return;
|
|
233
|
+
if (e.origin !== this.origin && !(this.opaque && e.origin === 'null'))
|
|
234
|
+
return;
|
|
235
|
+
const msg = parseEvent(e.data);
|
|
236
|
+
if (!msg)
|
|
237
|
+
return;
|
|
238
|
+
switch (msg.event) {
|
|
239
|
+
case 'ready': {
|
|
240
|
+
const { type: _t, version: _v, event: _e, ...info } = msg;
|
|
241
|
+
this.live = true;
|
|
242
|
+
this.lastCompiled = info.compiled;
|
|
243
|
+
this.lastTick = info.tick;
|
|
244
|
+
this.chartName = info.compiled?.chart ?? this.chartName;
|
|
245
|
+
this.updateTitle();
|
|
246
|
+
this.readySettled = true;
|
|
247
|
+
this.resolveReady(info);
|
|
248
|
+
for (const q of this.queue.splice(0))
|
|
249
|
+
q.send();
|
|
250
|
+
this.emit('ready', info);
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
case 'compiled': {
|
|
254
|
+
const { type: _t, version: _v, event: _e, ...info } = msg;
|
|
255
|
+
this.lastCompiled = info;
|
|
256
|
+
if (info.chart && info.chart !== this.chartName) {
|
|
257
|
+
this.chartName = info.chart;
|
|
258
|
+
this.updateTitle();
|
|
259
|
+
}
|
|
260
|
+
this.emit('compiled', info);
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case 'tick': {
|
|
264
|
+
const { type: _t, version: _v, event: _e, ...info } = msg;
|
|
265
|
+
this.lastTick = info;
|
|
266
|
+
this.emit('tick', info);
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
case 'resize': {
|
|
270
|
+
const h = Number(msg.height);
|
|
271
|
+
if (this.dataset.height === 'auto' && Number.isFinite(h) && h > 0)
|
|
272
|
+
this.frame.style.height = `${Math.ceil(h)}px`;
|
|
273
|
+
this.emit('resize', { height: h });
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case 'error':
|
|
277
|
+
this.emit('error', { message: msg.message, command: msg.command });
|
|
278
|
+
break;
|
|
279
|
+
case 'reply': {
|
|
280
|
+
const p = this.pending.get(msg.id);
|
|
281
|
+
if (!p)
|
|
282
|
+
break;
|
|
283
|
+
this.pending.delete(msg.id);
|
|
284
|
+
clearTimeout(p.timer);
|
|
285
|
+
if (msg.ok)
|
|
286
|
+
p.resolve(msg.result);
|
|
287
|
+
else
|
|
288
|
+
p.reject(new Error(msg.error ?? 'The embed could not do that.'));
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
emit(name, detail) {
|
|
294
|
+
this.dispatchEvent(new CustomEvent(name, { detail }));
|
|
295
|
+
}
|
|
296
|
+
post(command) {
|
|
297
|
+
this.frame?.contentWindow?.postMessage(envelope(command), this.opaque ? '*' : this.origin);
|
|
298
|
+
}
|
|
299
|
+
/** Sends a command once the embed is ready; resolves with its reply's result. */
|
|
300
|
+
request(command) {
|
|
301
|
+
return new Promise((resolve, reject) => {
|
|
302
|
+
const send = () => {
|
|
303
|
+
const id = this.nextId++;
|
|
304
|
+
const timer = setTimeout(() => {
|
|
305
|
+
this.pending.delete(id);
|
|
306
|
+
reject(new Error(`The embed did not answer ${command.command}.`));
|
|
307
|
+
}, REPLY_TIMEOUT);
|
|
308
|
+
this.pending.set(id, { resolve: resolve, reject, timer });
|
|
309
|
+
this.post({ ...command, id });
|
|
310
|
+
};
|
|
311
|
+
if (this.live)
|
|
312
|
+
send();
|
|
313
|
+
else
|
|
314
|
+
this.queue.push({ send, reject });
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
/** The frame is about to load again: commands sent to it are lost with it (those still waiting go to the next one
|
|
318
|
+
* once it is ready), and `ready` is a new promise, at once (a pending one is kept for the next frame). */
|
|
319
|
+
invalidate() {
|
|
320
|
+
this.fail(new Error('The chart was loaded again.'));
|
|
321
|
+
if (this.readySettled)
|
|
322
|
+
this.resetReady();
|
|
323
|
+
}
|
|
324
|
+
/** A new `ready` for the next frame. */
|
|
325
|
+
resetReady() {
|
|
326
|
+
this.readySettled = false;
|
|
327
|
+
this.readyPromise = new Promise(resolve => (this.resolveReady = resolve));
|
|
328
|
+
}
|
|
329
|
+
/** Rejects the commands sent to the frame that are not answered yet. */
|
|
330
|
+
fail(error) {
|
|
331
|
+
for (const p of this.pending.values()) {
|
|
332
|
+
clearTimeout(p.timer);
|
|
333
|
+
p.reject(error);
|
|
334
|
+
}
|
|
335
|
+
this.pending.clear();
|
|
336
|
+
this.live = false;
|
|
337
|
+
}
|
|
338
|
+
// ----- API ------------------------------------------------------------------------------------------------------
|
|
339
|
+
/** Resolves once the chart is live (its first compile and tick 0). */
|
|
340
|
+
get ready() {
|
|
341
|
+
return this.readyPromise;
|
|
342
|
+
}
|
|
343
|
+
/** The latest compile and tick the embed reported. */
|
|
344
|
+
get compiled() {
|
|
345
|
+
return this.lastCompiled;
|
|
346
|
+
}
|
|
347
|
+
get tick() {
|
|
348
|
+
return this.lastTick;
|
|
349
|
+
}
|
|
350
|
+
get iframe() {
|
|
351
|
+
return this.frame;
|
|
352
|
+
}
|
|
353
|
+
/** Replaces the chart's text; resolves with its compile. */
|
|
354
|
+
setSource(source) {
|
|
355
|
+
return this.request({ command: 'setSource', source });
|
|
356
|
+
}
|
|
357
|
+
/** Opens a project of several files; resolves with the compile of the active one. */
|
|
358
|
+
setFiles(files, active) {
|
|
359
|
+
return this.request({ command: 'setFiles', files, ...(active ? { active } : {}) });
|
|
360
|
+
}
|
|
361
|
+
selectChart(chart) {
|
|
362
|
+
return this.request({ command: 'selectChart', chart });
|
|
363
|
+
}
|
|
364
|
+
/** Sets these inputs (they keep their values afterwards) and runs one tick; resolves with it. */
|
|
365
|
+
step(inputs) {
|
|
366
|
+
return this.request({ command: 'step', ...(inputs ? { inputs } : {}) });
|
|
367
|
+
}
|
|
368
|
+
setInputs(inputs) {
|
|
369
|
+
return this.request({ command: 'setInputs', inputs });
|
|
370
|
+
}
|
|
371
|
+
reset() {
|
|
372
|
+
return this.request({ command: 'reset' });
|
|
373
|
+
}
|
|
374
|
+
/** Shows tick `tick` of the ticks computed (0: before the first). */
|
|
375
|
+
rewind(tick) {
|
|
376
|
+
return this.request({ command: 'rewind', tick });
|
|
377
|
+
}
|
|
378
|
+
getState() {
|
|
379
|
+
return this.request({ command: 'getState' });
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/** Registers <sccharts-lab-chart> (once), with the site its embeds come from. */
|
|
383
|
+
export function define(base) {
|
|
384
|
+
if (base)
|
|
385
|
+
SCChartsLabChart.base = base;
|
|
386
|
+
if (!customElements.get(TAG))
|
|
387
|
+
customElements.define(TAG, SCChartsLabChart);
|
|
388
|
+
}
|
|
389
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,yGAAyG;AACzG,EAAE;AACF,mEAAmE;AACnE,wFAAwF;AACxF,2FAA2F;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,CAAC,CAAA;IACpD,CAAC;IACD,QAAQ;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAA;IAChD,CAAC;;AAGL,iFAAiF;AACjF,MAAM,UAAU,MAAM,CAAC,IAAa;IAChC,IAAI,IAAI;QAAE,gBAAgB,CAAC,IAAI,GAAG,IAAI,CAAA;IACtC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["// <sccharts-lab-chart>: a live SCCharts chart in any page. It makes the iframe of SCCharts Lab's embed (/embed/),\n// sizes it to its content, and turns the postMessage protocol (protocol.ts) into methods and DOM events.\n//\n// <script src=\"https://sccharts.jmw.nz/embed.js\" async></script>\n// <sccharts-lab-chart example=\"learn/hierarchy/abro\" view=\"sim\"></sccharts-lab-chart>\n// <sccharts-lab-chart view=\"full\"><pre>scchart Toggle { ... }</pre></sccharts-lab-chart>\n//\n// The chart: `example` (a guide example), else `src` (a .sctx file the element fetches), else the element's own\n// `<pre>`, `<textarea>` or `<script type=\"text/sctx\">` children (several with `data-file=\"lib/beep.sctx\"` make a\n// project). A `<pre>` reads as code before the script runs, and stays the page's fallback without JavaScript.\n// `run` replays a run (the playground's \"Copy link to this run\" encoding).\n// Dependency-free: built on its own into /embed.js.\n\nimport { DEFAULT_BASE, embedUrl, estimateHeight, targetFromAttributes, type EmbedTarget } from './options'\nimport { envelope, parseEvent, type CommandId, type CompiledInfo, type EmbedCommand, type Inputs, type ReadyInfo, type TickInfo } from './protocol'\n\nexport const TAG = 'sccharts-lab-chart'\n\n/** Attributes that change the embed's address (the frame loads again). */\nconst ADDRESS = ['example', 'src', 'view', 'height', 'tick', 'tour', 'controls', 'chart', 'run', 'base']\nconst REPLY_TIMEOUT = 15000\nconst VIEW_WORDS: Record<string, string> = { diagram: 'diagram', sim: 'simulation', editor: 'editor', full: 'editor and simulation' }\n\n/** Source text written inside HTML: the first and last blank lines and the indentation they share go. */\nexport function dedent(text: string): string {\n const lines = text.replace(/\\r\\n?/g, '\\n').split('\\n')\n while (lines.length && !lines[0].trim()) lines.shift()\n while (lines.length && !lines[lines.length - 1].trim()) lines.pop()\n const indent = Math.min(...lines.filter(l => l.trim()).map(l => /^[ \\t]*/.exec(l)![0].length))\n return lines.map(l => l.slice(Number.isFinite(indent) ? indent : 0)).join('\\n') + '\\n'\n}\n\n/** The files written inside the element: `<pre>`, `<textarea>` and `<script type=\"text/sctx\">` children, each its\n * `data-file` (else `main.sctx`, `main-2.sctx`, ...). Undefined when there are none. */\nexport function inlineFiles(host: Element): { files: Record<string, string>; active: string } | undefined {\n const blocks = [...host.children].filter(c => c.matches('pre, textarea, script[type=\"text/sctx\"]'))\n if (!blocks.length) return undefined\n const files: Record<string, string> = {}\n let active: string | undefined\n blocks.forEach((b, i) => {\n const named = b.getAttribute('data-file')?.trim()\n const path = named && /^[\\w ./+-]+$/.test(named) ? (named.endsWith('.sctx') ? named : `${named}.sctx`) : `main${i ? `-${i + 1}` : ''}.sctx`\n files[path] = dedent(b.tagName === 'TEXTAREA' ? (b as HTMLTextAreaElement).value : (b.textContent ?? ''))\n if (b.hasAttribute('data-active')) active = path\n })\n return { files, active: active ?? Object.keys(files)[0] }\n}\n\ninterface Pending {\n resolve: (value: unknown) => void\n reject: (error: Error) => void\n timer: ReturnType<typeof setTimeout>\n}\n\nconst STYLE = `\n:host { display: block; position: relative; }\n:host([hidden]) { display: none; }\n:host([data-height='fill']) { height: 480px; }\niframe { display: block; width: 100%; height: 100%; border: 0; background: transparent; color-scheme: light; }\n.sclab-error { margin: 0; padding: 0.75em 1em; border: 1px solid #d4c23a; border-radius: 6px; background: #fffbd1; color: #2b2a1e; font: 0.875rem/1.5 system-ui, sans-serif; }\n`\n\n// Importable where there is no DOM (the site's build, tests): the class is only defined, never made, there.\nconst Base = (typeof HTMLElement === 'undefined' ? class {} : HTMLElement) as typeof HTMLElement\n\n/** The element's events (CustomEvents, not bubbling) and their `detail`. */\nexport interface SCChartsLabChartEventMap {\n /** The chart is live: what it shows, and its tick. */\n ready: CustomEvent<ReadyInfo>\n /** A chart compiled (a new source, files or chart): `ok`, its diagnostics, inputs and outputs. */\n compiled: CustomEvent<CompiledInfo>\n /** A tick shown: its values (KIELER's names), active states, taken transitions, printed text. */\n tick: CustomEvent<TickInfo>\n /** The embed's content height, with `height=\"auto\"`. */\n resize: CustomEvent<{ height: number }>\n /** What went wrong: a file that could not be fetched, a command the embed refused. */\n error: CustomEvent<{ message: string; command?: string }>\n}\n\nexport class SCChartsLabChart extends Base {\n addEventListener<K extends keyof SCChartsLabChartEventMap>(type: K, listener: (this: SCChartsLabChart, event: SCChartsLabChartEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void\n addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void\n addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void {\n super.addEventListener(type, listener, options)\n }\n\n removeEventListener<K extends keyof SCChartsLabChartEventMap>(type: K, listener: (this: SCChartsLabChart, event: SCChartsLabChartEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void\n removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void\n removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void {\n super.removeEventListener(type, listener, options)\n }\n\n /** Where /embed/ is: the site the loader came from (set by `define`), else sccharts.jmw.nz. */\n static base = DEFAULT_BASE\n static get observedAttributes() {\n return [...ADDRESS, 'label', 'loading']\n }\n\n private frame?: HTMLIFrameElement\n private message?: HTMLParagraphElement\n private pending = new Map<CommandId, Pending>()\n /** Commands waiting for the embed to be ready. */\n private queue: { send: () => void; reject: (error: Error) => void }[] = []\n private nextId = 1\n private live = false\n private renderQueued = false\n private generation = 0\n /** The frame a render is replacing: its messages are ignored meanwhile. */\n private stale?: HTMLIFrameElement\n private origin = ''\n private chartName?: string\n private resolveReady!: (info: ReadyInfo) => void\n private readyPromise!: Promise<ReadyInfo>\n private readySettled = true\n private lastTick?: TickInfo\n private lastCompiled?: CompiledInfo\n private onMessage = (e: MessageEvent) => this.receive(e)\n\n constructor() {\n super()\n this.resetReady()\n }\n\n // ----- Lifecycle ------------------------------------------------------------------------------------------------\n\n connectedCallback() {\n window.addEventListener('message', this.onMessage)\n // Parsed before its children (the script ran first): read them once the document is parsed.\n if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => this.scheduleRender(), { once: true })\n else this.scheduleRender()\n }\n\n disconnectedCallback() {\n window.removeEventListener('message', this.onMessage)\n const error = new Error('The chart was removed from the page.')\n this.fail(error)\n for (const q of this.queue.splice(0)) q.reject(error)\n }\n\n attributeChangedCallback(name: string, old: string | null, value: string | null) {\n // Before the first render (the element being made or upgraded, its inline code perhaps not parsed yet) the\n // render reads every attribute; after it, a change renders again, also while a chart is fetched or after a\n // fetch failed (render's generation drops the fetch it replaces).\n if (old === value || !this.isConnected || !this.generation) return\n if (ADDRESS.includes(name)) {\n this.invalidate()\n this.scheduleRender()\n }\n else if (name === 'label') this.updateTitle()\n else if (name === 'loading' && this.frame) this.frame.loading = value === 'eager' ? 'eager' : 'lazy'\n }\n\n private scheduleRender() {\n if (this.renderQueued) return\n this.renderQueued = true\n queueMicrotask(() => {\n this.renderQueued = false\n if (this.isConnected) void this.render()\n })\n }\n\n /** The embed's address for the attributes now, and the chart to send it (inline or fetched). */\n private async render() {\n const root = this.shadowRoot ?? this.attachShadow({ mode: 'open' })\n if (!root.firstChild) root.innerHTML = `<style>${STYLE}</style>`\n const target = this.target()\n const base = this.getAttribute('base') || SCChartsLabChart.base\n this.origin = new URL(base, location.href).origin\n this.dataset.height = typeof target.height === 'number' ? 'fixed' : (target.height ?? 'auto')\n this.invalidate()\n const generation = ++this.generation\n // The frame on screen stays until the new one is made (no jump), but it is the old chart's: what it says (a\n // late `ready`) is not about the chart these attributes ask for.\n this.stale = this.frame\n this.message?.remove()\n this.message = undefined\n\n let files: { files: Record<string, string>; active: string } | undefined\n if (!target.example) {\n const src = this.getAttribute('src')\n if (src) {\n try {\n const url = new URL(src, document.baseURI)\n const res = await fetch(url)\n if (!res.ok) throw new Error(`${res.status} ${res.statusText}`.trim())\n const name = decodeURIComponent(url.pathname.split('/').pop() || 'main.sctx')\n const path = /^[\\w ./+-]+\\.sctx$/.test(name) ? name : 'main.sctx'\n files = { files: { [path]: await res.text() }, active: path }\n } catch (error) {\n if (generation === this.generation) this.showError(`The chart ${src} could not be loaded (${error instanceof Error ? error.message : String(error)}).`)\n return\n }\n // The attributes changed while the file was on its way: a later render has it.\n if (generation !== this.generation) return\n } else files = inlineFiles(this)\n }\n // A run to replay (the playground's `run=`, lz-string's URL-safe letters only).\n const run = this.getAttribute('run')?.trim()\n const url = embedUrl(base, { ...target, ...(files ? { source: 'parent' as const } : {}) }, run && /^[\\w+$-]+$/.test(run) ? `run=${run}` : undefined)\n const old = this.frame\n const frame = document.createElement('iframe')\n frame.setAttribute('part', 'frame')\n frame.loading = this.getAttribute('loading') === 'eager' ? 'eager' : 'lazy'\n frame.allow = 'clipboard-write'\n frame.src = url\n if (typeof target.height === 'number') frame.style.height = `${target.height}px`\n else if (target.height === 'auto') frame.style.height = `${old?.offsetHeight || estimateHeight(target.view ?? 'sim', this.clientWidth || 640)}px`\n frame.addEventListener('load', () => {\n // The embed listens from its first script on: send the chart the page holds, then what waited.\n if (files) this.post({ command: 'setFiles', files: files.files, active: files.active })\n })\n this.frame = frame\n this.stale = undefined\n this.live = false\n this.updateTitle()\n if (old) old.replaceWith(frame)\n else root.append(frame)\n }\n\n private target(): EmbedTarget {\n return targetFromAttributes(n => this.getAttribute(n))\n }\n\n private showError(text: string) {\n this.frame?.remove()\n this.frame = undefined\n const p = document.createElement('p')\n p.className = 'sclab-error'\n p.setAttribute('role', 'alert')\n p.textContent = text\n this.message = p\n this.shadowRoot?.append(p)\n for (const q of this.queue.splice(0)) q.reject(new Error(text))\n this.emit('error', { message: text })\n }\n\n private updateTitle() {\n if (!this.frame) return\n const view = VIEW_WORDS[this.target().view ?? 'sim']\n this.frame.title = this.getAttribute('label') || `SCCharts Lab: ${this.chartName ?? this.target().example?.split('/').pop() ?? 'chart'} (${view})`\n }\n\n // ----- Messages -------------------------------------------------------------------------------------------------\n\n /** The page has no web origin (a frame sandboxed without allow-same-origin, as an LMS frames its pages): the embed it\n * frames has none either, since sandbox flags pass down, so messages go to '*' and arrive from 'null'. The frame's\n * own window, which this element made, is what identifies them then. */\n private get opaque(): boolean {\n return self.origin === 'null'\n }\n\n private receive(e: MessageEvent) {\n if (!this.frame || this.frame === this.stale || e.source !== this.frame.contentWindow) return\n if (e.origin !== this.origin && !(this.opaque && e.origin === 'null')) return\n const msg = parseEvent(e.data)\n if (!msg) return\n switch (msg.event) {\n case 'ready': {\n const { type: _t, version: _v, event: _e, ...info } = msg\n this.live = true\n this.lastCompiled = info.compiled\n this.lastTick = info.tick\n this.chartName = info.compiled?.chart ?? this.chartName\n this.updateTitle()\n this.readySettled = true\n this.resolveReady(info)\n for (const q of this.queue.splice(0)) q.send()\n this.emit('ready', info)\n break\n }\n case 'compiled': {\n const { type: _t, version: _v, event: _e, ...info } = msg\n this.lastCompiled = info\n if (info.chart && info.chart !== this.chartName) {\n this.chartName = info.chart\n this.updateTitle()\n }\n this.emit('compiled', info)\n break\n }\n case 'tick': {\n const { type: _t, version: _v, event: _e, ...info } = msg\n this.lastTick = info\n this.emit('tick', info)\n break\n }\n case 'resize': {\n const h = Number(msg.height)\n if (this.dataset.height === 'auto' && Number.isFinite(h) && h > 0) this.frame.style.height = `${Math.ceil(h)}px`\n this.emit('resize', { height: h })\n break\n }\n case 'error':\n this.emit('error', { message: msg.message, command: msg.command })\n break\n case 'reply': {\n const p = this.pending.get(msg.id)\n if (!p) break\n this.pending.delete(msg.id)\n clearTimeout(p.timer)\n if (msg.ok) p.resolve(msg.result)\n else p.reject(new Error(msg.error ?? 'The embed could not do that.'))\n break\n }\n }\n }\n\n private emit(name: string, detail: unknown) {\n this.dispatchEvent(new CustomEvent(name, { detail }))\n }\n\n private post(command: EmbedCommand & { id?: CommandId }) {\n this.frame?.contentWindow?.postMessage(envelope(command), this.opaque ? '*' : this.origin)\n }\n\n /** Sends a command once the embed is ready; resolves with its reply's result. */\n private request<T>(command: EmbedCommand): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const send = () => {\n const id = this.nextId++\n const timer = setTimeout(() => {\n this.pending.delete(id)\n reject(new Error(`The embed did not answer ${command.command}.`))\n }, REPLY_TIMEOUT)\n this.pending.set(id, { resolve: resolve as (v: unknown) => void, reject, timer })\n this.post({ ...command, id })\n }\n if (this.live) send()\n else this.queue.push({ send, reject })\n })\n }\n\n /** The frame is about to load again: commands sent to it are lost with it (those still waiting go to the next one\n * once it is ready), and `ready` is a new promise, at once (a pending one is kept for the next frame). */\n private invalidate() {\n this.fail(new Error('The chart was loaded again.'))\n if (this.readySettled) this.resetReady()\n }\n\n /** A new `ready` for the next frame. */\n private resetReady() {\n this.readySettled = false\n this.readyPromise = new Promise(resolve => (this.resolveReady = resolve))\n }\n\n /** Rejects the commands sent to the frame that are not answered yet. */\n private fail(error: Error) {\n for (const p of this.pending.values()) {\n clearTimeout(p.timer)\n p.reject(error)\n }\n this.pending.clear()\n this.live = false\n }\n\n // ----- API ------------------------------------------------------------------------------------------------------\n\n /** Resolves once the chart is live (its first compile and tick 0). */\n get ready(): Promise<ReadyInfo> {\n return this.readyPromise\n }\n /** The latest compile and tick the embed reported. */\n get compiled(): CompiledInfo | undefined {\n return this.lastCompiled\n }\n get tick(): TickInfo | undefined {\n return this.lastTick\n }\n get iframe(): HTMLIFrameElement | undefined {\n return this.frame\n }\n\n /** Replaces the chart's text; resolves with its compile. */\n setSource(source: string): Promise<CompiledInfo> {\n return this.request({ command: 'setSource', source })\n }\n /** Opens a project of several files; resolves with the compile of the active one. */\n setFiles(files: Record<string, string>, active?: string): Promise<CompiledInfo> {\n return this.request({ command: 'setFiles', files, ...(active ? { active } : {}) })\n }\n selectChart(chart: string): Promise<CompiledInfo> {\n return this.request({ command: 'selectChart', chart })\n }\n /** Sets these inputs (they keep their values afterwards) and runs one tick; resolves with it. */\n step(inputs?: Inputs): Promise<TickInfo> {\n return this.request({ command: 'step', ...(inputs ? { inputs } : {}) })\n }\n setInputs(inputs: Inputs): Promise<TickInfo> {\n return this.request({ command: 'setInputs', inputs })\n }\n reset(): Promise<TickInfo> {\n return this.request({ command: 'reset' })\n }\n /** Shows tick `tick` of the ticks computed (0: before the first). */\n rewind(tick: number): Promise<TickInfo> {\n return this.request({ command: 'rewind', tick })\n }\n getState(): Promise<{ compiled?: CompiledInfo; tick: TickInfo }> {\n return this.request({ command: 'getState' })\n }\n}\n\n/** Registers <sccharts-lab-chart> (once), with the site its embeds come from. */\nexport function define(base?: string) {\n if (base) SCChartsLabChart.base = base\n if (!customElements.get(TAG)) customElements.define(TAG, SCChartsLabChart)\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sccharts-lab-chart': SCChartsLabChart\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*! SCCharts Lab embed: <sccharts-lab-chart>. EPL-2.0. How to use it: https://sccharts.jmw.nz/reference/embed/ */
|
|
2
|
+
(function(){var e=[`diagram`,`sim`,`editor`,`full`],t=4e3,n=1e3,r=/^[A-Za-z_]\w{0,199}$/,i=/^[\w-]+(\/[\w.-]+)*$/,a=new Set([``,`1`,`true`,`yes`,`on`]),o=new Set([`0`,`false`,`no`,`off`,`none`]);function s(e,t){if(e==null)return t;let n=e.trim().toLowerCase();return a.has(n)?!0:!o.has(n)&&t}function c(t){let n=t?.trim().toLowerCase();return e.includes(n)?n:`sim`}function l(e,n=`fill`){let r=e?.trim().toLowerCase();if(!r)return n;if(r===`auto`||r===`fill`)return r;let i=/^(\d{2,4})(px)?$/.exec(r);return i?Math.max(120,Math.min(t,Number(i[1]))):n}function u(e){let t=e?.trim();if(t&&/^\d{1,6}$/.test(t))return Math.min(n,Number(t))}function d(e){let t=e?.trim();return t&&r.test(t)?t:void 0}function f(e){let t=e?.trim().replace(/^\/+/,``).replace(/\.sctx$/,``);return t&&t.length<=200&&i.test(t)&&!t.split(`/`).includes(`..`)?t:void 0}function p(e){let t=[],i=f(e.example);return i&&t.push(`example=${encodeURIComponent(i).replace(/%2F/g,`/`)}`),e.source===`parent`&&t.push(`source=parent`),e.view&&e.view!==`sim`&&t.push(`view=${e.view}`),e.height!==void 0&&e.height!==`fill`&&t.push(`height=${e.height}`),e.tour&&t.push(`tour`),e.tick!==void 0&&e.tick>0&&t.push(`tick=${Math.min(n,Math.floor(e.tick))}`),e.controls===!1&&t.push(`controls=0`),e.chart&&r.test(e.chart)&&t.push(`chart=${e.chart}`),t.length?`?${t.join(`&`)}`:``}var m=`https://sccharts.jmw.nz/`;function h(e,t,n){let r=e.endsWith(`/`)?e:`${e}/`,i=n?.replace(/^#/,``);return`${r}embed/${p(t)}${i?`#${i}`:``}`}function g(e){let t=u(e(`tick`)),n=d(e(`chart`)),r=f(e(`example`));return{view:c(e(`view`)),height:l(e(`height`),`auto`),tour:s(e(`tour`),!1),controls:s(e(`controls`),!0),...t===void 0?{}:{tick:t},...n?{chart:n}:{},...r?{example:r}:{}}}function _(e,t=640){let n=t<640;switch(e){case`diagram`:return 340;case`sim`:return n?620:560;case`editor`:return n?640:380;case`full`:return n?960:720}}var v=`sccharts-lab`;function y(e){return{type:v,version:1,...e}}var b=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function x(e){if(b(e)&&e.type===`sccharts-lab`&&e.version===1&&typeof e.event==`string`)return e}function S(e){"@babel/helpers - typeof";return S=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},S(e)}function C(e,t){if(S(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(S(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function w(e){var t=C(e,`string`);return S(t)==`symbol`?t:t+``}function T(e,t,n){return(t=w(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var E=`sccharts-lab-chart`,D=[`example`,`src`,`view`,`height`,`tick`,`tour`,`controls`,`chart`,`run`,`base`],O=15e3,k={diagram:`diagram`,sim:`simulation`,editor:`editor`,full:`editor and simulation`};function A(e){let t=e.replace(/\r\n?/g,`
|
|
3
|
+
`).split(`
|
|
4
|
+
`);for(;t.length&&!t[0].trim();)t.shift();for(;t.length&&!t[t.length-1].trim();)t.pop();let n=Math.min(...t.filter(e=>e.trim()).map(e=>/^[ \t]*/.exec(e)[0].length));return t.map(e=>e.slice(Number.isFinite(n)?n:0)).join(`
|
|
5
|
+
`)+`
|
|
6
|
+
`}function j(e){let t=[...e.children].filter(e=>e.matches(`pre, textarea, script[type="text/sctx"]`));if(!t.length)return;let n={},r;return t.forEach((e,t)=>{let i=e.getAttribute(`data-file`)?.trim(),a=i&&/^[\w ./+-]+$/.test(i)?i.endsWith(`.sctx`)?i:`${i}.sctx`:`main${t?`-${t+1}`:``}.sctx`;n[a]=A(e.tagName===`TEXTAREA`?e.value:e.textContent??``),e.hasAttribute(`data-active`)&&(r=a)}),{files:n,active:r??Object.keys(n)[0]}}var M=`
|
|
7
|
+
:host { display: block; position: relative; }
|
|
8
|
+
:host([hidden]) { display: none; }
|
|
9
|
+
:host([data-height='fill']) { height: 480px; }
|
|
10
|
+
iframe { display: block; width: 100%; height: 100%; border: 0; background: transparent; color-scheme: light; }
|
|
11
|
+
.sclab-error { margin: 0; padding: 0.75em 1em; border: 1px solid #d4c23a; border-radius: 6px; background: #fffbd1; color: #2b2a1e; font: 0.875rem/1.5 system-ui, sans-serif; }
|
|
12
|
+
`,N=typeof HTMLElement>`u`?class{}:HTMLElement,P=class e extends N{addEventListener(e,t,n){super.addEventListener(e,t,n)}removeEventListener(e,t,n){super.removeEventListener(e,t,n)}static get observedAttributes(){return[...D,`label`,`loading`]}constructor(){super(),T(this,`frame`,void 0),T(this,`message`,void 0),T(this,`pending`,new Map),T(this,`queue`,[]),T(this,`nextId`,1),T(this,`live`,!1),T(this,`renderQueued`,!1),T(this,`generation`,0),T(this,`stale`,void 0),T(this,`origin`,``),T(this,`chartName`,void 0),T(this,`resolveReady`,void 0),T(this,`readyPromise`,void 0),T(this,`readySettled`,!0),T(this,`lastTick`,void 0),T(this,`lastCompiled`,void 0),T(this,`onMessage`,e=>this.receive(e)),this.resetReady()}connectedCallback(){window.addEventListener(`message`,this.onMessage),document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>this.scheduleRender(),{once:!0}):this.scheduleRender()}disconnectedCallback(){window.removeEventListener(`message`,this.onMessage);let e=Error(`The chart was removed from the page.`);this.fail(e);for(let t of this.queue.splice(0))t.reject(e)}attributeChangedCallback(e,t,n){t!==n&&this.isConnected&&this.generation&&(D.includes(e)?(this.invalidate(),this.scheduleRender()):e===`label`?this.updateTitle():e===`loading`&&this.frame&&(this.frame.loading=n===`eager`?`eager`:`lazy`))}scheduleRender(){this.renderQueued||(this.renderQueued=!0,queueMicrotask(()=>{this.renderQueued=!1,this.isConnected&&this.render()}))}async render(){let t=this.shadowRoot??this.attachShadow({mode:`open`});t.firstChild||(t.innerHTML=`<style>${M}</style>`);let n=this.target(),r=this.getAttribute(`base`)||e.base;this.origin=new URL(r,location.href).origin,this.dataset.height=typeof n.height==`number`?`fixed`:n.height??`auto`,this.invalidate();let i=++this.generation;this.stale=this.frame,this.message?.remove(),this.message=void 0;let a;if(!n.example){let e=this.getAttribute(`src`);if(e){try{let t=new URL(e,document.baseURI),n=await fetch(t);if(!n.ok)throw Error(`${n.status} ${n.statusText}`.trim());let r=decodeURIComponent(t.pathname.split(`/`).pop()||`main.sctx`),i=/^[\w ./+-]+\.sctx$/.test(r)?r:`main.sctx`;a={files:{[i]:await n.text()},active:i}}catch(t){i===this.generation&&this.showError(`The chart ${e} could not be loaded (${t instanceof Error?t.message:String(t)}).`);return}if(i!==this.generation)return}else a=j(this)}let o=this.getAttribute(`run`)?.trim(),s=h(r,{...n,...a?{source:`parent`}:{}},o&&/^[\w+$-]+$/.test(o)?`run=${o}`:void 0),c=this.frame,l=document.createElement(`iframe`);l.setAttribute(`part`,`frame`),l.loading=this.getAttribute(`loading`)===`eager`?`eager`:`lazy`,l.allow=`clipboard-write`,l.src=s,typeof n.height==`number`?l.style.height=`${n.height}px`:n.height===`auto`&&(l.style.height=`${c?.offsetHeight||_(n.view??`sim`,this.clientWidth||640)}px`),l.addEventListener(`load`,()=>{a&&this.post({command:`setFiles`,files:a.files,active:a.active})}),this.frame=l,this.stale=void 0,this.live=!1,this.updateTitle(),c?c.replaceWith(l):t.append(l)}target(){return g(e=>this.getAttribute(e))}showError(e){this.frame?.remove(),this.frame=void 0;let t=document.createElement(`p`);t.className=`sclab-error`,t.setAttribute(`role`,`alert`),t.textContent=e,this.message=t,this.shadowRoot?.append(t);for(let t of this.queue.splice(0))t.reject(Error(e));this.emit(`error`,{message:e})}updateTitle(){if(!this.frame)return;let e=k[this.target().view??`sim`];this.frame.title=this.getAttribute(`label`)||`SCCharts Lab: ${this.chartName??this.target().example?.split(`/`).pop()??`chart`} (${e})`}get opaque(){return self.origin===`null`}receive(e){if(!this.frame||this.frame===this.stale||e.source!==this.frame.contentWindow||e.origin!==this.origin&&!(this.opaque&&e.origin===`null`))return;let t=x(e.data);if(t)switch(t.event){case`ready`:{let{type:e,version:n,event:r,...i}=t;this.live=!0,this.lastCompiled=i.compiled,this.lastTick=i.tick,this.chartName=i.compiled?.chart??this.chartName,this.updateTitle(),this.readySettled=!0,this.resolveReady(i);for(let e of this.queue.splice(0))e.send();this.emit(`ready`,i);break}case`compiled`:{let{type:e,version:n,event:r,...i}=t;this.lastCompiled=i,i.chart&&i.chart!==this.chartName&&(this.chartName=i.chart,this.updateTitle()),this.emit(`compiled`,i);break}case`tick`:{let{type:e,version:n,event:r,...i}=t;this.lastTick=i,this.emit(`tick`,i);break}case`resize`:{let e=Number(t.height);this.dataset.height===`auto`&&Number.isFinite(e)&&e>0&&(this.frame.style.height=`${Math.ceil(e)}px`),this.emit(`resize`,{height:e});break}case`error`:this.emit(`error`,{message:t.message,command:t.command});break;case`reply`:{let e=this.pending.get(t.id);if(!e)break;this.pending.delete(t.id),clearTimeout(e.timer),t.ok?e.resolve(t.result):e.reject(Error(t.error??`The embed could not do that.`));break}}}emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}post(e){this.frame?.contentWindow?.postMessage(y(e),this.opaque?`*`:this.origin)}request(e){return new Promise((t,n)=>{let r=()=>{let r=this.nextId++,i=setTimeout(()=>{this.pending.delete(r),n(Error(`The embed did not answer ${e.command}.`))},O);this.pending.set(r,{resolve:t,reject:n,timer:i}),this.post({...e,id:r})};this.live?r():this.queue.push({send:r,reject:n})})}invalidate(){this.fail(Error(`The chart was loaded again.`)),this.readySettled&&this.resetReady()}resetReady(){this.readySettled=!1,this.readyPromise=new Promise(e=>this.resolveReady=e)}fail(e){for(let t of this.pending.values())clearTimeout(t.timer),t.reject(e);this.pending.clear(),this.live=!1}get ready(){return this.readyPromise}get compiled(){return this.lastCompiled}get tick(){return this.lastTick}get iframe(){return this.frame}setSource(e){return this.request({command:`setSource`,source:e})}setFiles(e,t){return this.request({command:`setFiles`,files:e,...t?{active:t}:{}})}selectChart(e){return this.request({command:`selectChart`,chart:e})}step(e){return this.request({command:`step`,...e?{inputs:e}:{}})}setInputs(e){return this.request({command:`setInputs`,inputs:e})}reset(){return this.request({command:`reset`})}rewind(e){return this.request({command:`rewind`,tick:e})}getState(){return this.request({command:`getState`})}};T(P,`base`,m);function F(e){e&&(P.base=e),customElements.get(`sccharts-lab-chart`)||customElements.define(E,P)}var I=typeof document<`u`?document.currentScript:null,L=I?.src?new URL(I.src):void 0;F(I?.dataset.base||(L?.pathname.endsWith(`/embed.js`)?new URL(`.`,L).href:void 0))})();
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @sccharts-lab/embed: SCCharts Lab's embeds. The postMessage protocol (protocol.ts), the embed's options and
|
|
2
|
+
// address (options.ts) and the <sccharts-lab-chart> element (element.ts; `define()` registers it; loader.ts is the
|
|
3
|
+
// entry point of the site's /embed.js).
|
|
4
|
+
export * from "./protocol.js";
|
|
5
|
+
export * from "./options.js";
|
|
6
|
+
export { SCChartsLabChart, TAG, define, dedent, inlineFiles } from "./element.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,mHAAmH;AACnH,wCAAwC;AACxC,8BAA0B;AAC1B,6BAAyB;AACzB,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAiC,qBAAiB","sourcesContent":["// @sccharts-lab/embed: SCCharts Lab's embeds. The postMessage protocol (protocol.ts), the embed's options and\n// address (options.ts) and the <sccharts-lab-chart> element (element.ts; `define()` registers it; loader.ts is the\n// entry point of the site's /embed.js).\nexport * from './protocol'\nexport * from './options'\nexport { SCChartsLabChart, TAG, define, dedent, inlineFiles, type SCChartsLabChartEventMap } from './element'\n"]}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The entry point of /embed.js and of the npm package's dist/embed.min.js (both built by
|
|
2
|
+
// tools/packages/embed-bundle.mjs): registers <sccharts-lab-chart>. Its embeds come from the site that served this
|
|
3
|
+
// script as `<site>/embed.js`; a copy under another name (a CDN serving dist/embed.min.js, an ES module import) uses
|
|
4
|
+
// sccharts.jmw.nz, unless the script tag says otherwise with `data-base`.
|
|
5
|
+
import { define } from "./element.js";
|
|
6
|
+
const script = typeof document !== 'undefined' ? document.currentScript : null;
|
|
7
|
+
const src = script?.src ? new URL(script.src) : undefined;
|
|
8
|
+
define(script?.dataset.base || (src?.pathname.endsWith('/embed.js') ? new URL('.', src).href : undefined));
|
|
9
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,mHAAmH;AACnH,qHAAqH;AACrH,0EAA0E;AAC1E,OAAO,EAAE,MAAM,EAAE,qBAAiB;AAElC,MAAM,MAAM,GAAG,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAE,QAAQ,CAAC,aAA0C,CAAC,CAAC,CAAC,IAAI,CAAA;AAC5G,MAAM,GAAG,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACzD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA","sourcesContent":["// The entry point of /embed.js and of the npm package's dist/embed.min.js (both built by\n// tools/packages/embed-bundle.mjs): registers <sccharts-lab-chart>. Its embeds come from the site that served this\n// script as `<site>/embed.js`; a copy under another name (a CDN serving dist/embed.min.js, an ES module import) uses\n// sccharts.jmw.nz, unless the script tag says otherwise with `data-base`.\nimport { define } from './element'\n\nconst script = typeof document !== 'undefined' ? (document.currentScript as HTMLScriptElement | null) : null\nconst src = script?.src ? new URL(script.src) : undefined\ndefine(script?.dataset.base || (src?.pathname.endsWith('/embed.js') ? new URL('.', src).href : undefined))\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export type EmbedView = 'diagram' | 'sim' | 'editor' | 'full';
|
|
2
|
+
export declare const VIEWS: readonly EmbedView[];
|
|
3
|
+
export declare const DEFAULT_VIEW: EmbedView;
|
|
4
|
+
/** What each view shows. */
|
|
5
|
+
export declare const VIEW_PARTS: Record<EmbedView, {
|
|
6
|
+
editor: boolean;
|
|
7
|
+
sim: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
/** `fill`: the embed fills its frame (the iframe's height decides); `auto`: it takes the height its content needs and
|
|
10
|
+
* reports it (`resize`); a number: it is that many pixels tall. */
|
|
11
|
+
export type EmbedHeight = 'fill' | 'auto' | number;
|
|
12
|
+
export declare const MIN_HEIGHT = 120;
|
|
13
|
+
export declare const MAX_HEIGHT = 4000;
|
|
14
|
+
export declare const MAX_TICK = 1000;
|
|
15
|
+
export interface EmbedOptions {
|
|
16
|
+
view: EmbedView;
|
|
17
|
+
height: EmbedHeight;
|
|
18
|
+
/** Start at this tick: of the shared run, of the guided tour, or stepped with the inputs as they are. */
|
|
19
|
+
tick?: number;
|
|
20
|
+
/** Start in the example's guided tour (its scripted inputs, with notes). */
|
|
21
|
+
tour: boolean;
|
|
22
|
+
/** The simulation's controls and the diagram's tools are shown (off: the page drives it with postMessage). */
|
|
23
|
+
controls: boolean;
|
|
24
|
+
/** The chart of the file to show and simulate, when not its first. */
|
|
25
|
+
chart?: string;
|
|
26
|
+
/** The chart comes from the page (postMessage `setSource` or `setFiles`), not from the address. */
|
|
27
|
+
source?: 'parent';
|
|
28
|
+
}
|
|
29
|
+
export interface EmbedTarget extends Partial<EmbedOptions> {
|
|
30
|
+
/** A guide example (`learn/abro/abro`, `showcase/abro`). */
|
|
31
|
+
example?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare const DEFAULTS: EmbedOptions;
|
|
34
|
+
/** A flag: present and empty, or 1/true/yes/on; absent or anything else is `fallback`. */
|
|
35
|
+
export declare function parseFlag(value: string | null | undefined, fallback: boolean): boolean;
|
|
36
|
+
export declare function parseView(value: string | null | undefined): EmbedView;
|
|
37
|
+
/** `auto`, `fill`, or a number of pixels (`480`, `480px`) between MIN_HEIGHT and MAX_HEIGHT; else `fallback`. */
|
|
38
|
+
export declare function parseHeight(value: string | null | undefined, fallback?: EmbedHeight): EmbedHeight;
|
|
39
|
+
/** A tick from 0 to MAX_TICK, or undefined. */
|
|
40
|
+
export declare function parseTick(value: string | null | undefined): number | undefined;
|
|
41
|
+
export declare function parseChartName(value: string | null | undefined): string | undefined;
|
|
42
|
+
/** A guide example's id as links write it (`learn/abro/abro`), or undefined. */
|
|
43
|
+
export declare function parseExample(value: string | null | undefined): string | undefined;
|
|
44
|
+
/** The options in an embed address's query (`location.search`); anything unknown or malformed is left at its default. */
|
|
45
|
+
export declare function parseEmbedQuery(search: string | URLSearchParams): EmbedOptions & {
|
|
46
|
+
example?: string;
|
|
47
|
+
};
|
|
48
|
+
/** The query for these options: only what differs from the defaults, in a fixed order. */
|
|
49
|
+
export declare function embedQuery(t: EmbedTarget): string;
|
|
50
|
+
/** The site an embed comes from (where /embed/ and /embed.js are). */
|
|
51
|
+
export declare const DEFAULT_BASE = "https://sccharts.jmw.nz/";
|
|
52
|
+
/** The address of an embed: `<base>embed/?<options>#<hash>` (`hash`: a playground hash, `code=...`, without `#`). */
|
|
53
|
+
export declare function embedUrl(base: string, t: EmbedTarget, hash?: string): string;
|
|
54
|
+
/** The options of a <sccharts-lab-chart> from its attributes (`get`: the attribute's value, null when absent). Its
|
|
55
|
+
* height is `auto` unless given: the element resizes its frame to the content. */
|
|
56
|
+
export declare function targetFromAttributes(get: (name: string) => string | null): EmbedTarget;
|
|
57
|
+
/** A first guess at an auto-sized embed's height, so the page moves little once it reports its own. */
|
|
58
|
+
export declare function estimateHeight(view: EmbedView, width?: number): number;
|