mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 02:37:41 -05:00
Improve offline dist content (#1836)
This commit is contained in:
committed by
GitHub
parent
e81830a2ea
commit
c8ec29a3d8
@@ -1,9 +1,6 @@
|
||||
// PyScript py-terminal plugin
|
||||
import { TYPES, hooks } from "../core.js";
|
||||
|
||||
const CDN = "https://cdn.jsdelivr.net/npm/xterm";
|
||||
const XTERM = "5.3.0";
|
||||
const XTERM_READLINE = "1.1.1";
|
||||
const SELECTOR = [...TYPES.keys()]
|
||||
.map((type) => `script[type="${type}"][terminal],${type}-script[terminal]`)
|
||||
.join(",");
|
||||
@@ -26,22 +23,18 @@ const pyTerminal = async () => {
|
||||
if (element.matches('script[type="mpy"],mpy-script'))
|
||||
throw new Error("Unsupported terminal");
|
||||
|
||||
// import styles once and lazily (only on valid terminal)
|
||||
if (!document.querySelector(`link[href^="${CDN}"]`)) {
|
||||
document.head.append(
|
||||
Object.assign(document.createElement("link"), {
|
||||
rel: "stylesheet",
|
||||
href: `${CDN}@${XTERM}/css/xterm.min.css`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
// import styles lazily
|
||||
document.head.append(
|
||||
Object.assign(document.createElement("link"), {
|
||||
rel: "stylesheet",
|
||||
href: new URL("./xterm.css", import.meta.url),
|
||||
}),
|
||||
);
|
||||
|
||||
// lazy load these only when a valid terminal is found
|
||||
const [{ Terminal }, { Readline }] = await Promise.all([
|
||||
import(/* webpackIgnore: true */ `${CDN}@${XTERM}/+esm`),
|
||||
import(
|
||||
/* webpackIgnore: true */ `${CDN}-readline@${XTERM_READLINE}/+esm`
|
||||
),
|
||||
import(/* webpackIgnore: true */ "../3rd-party/xterm.js"),
|
||||
import(/* webpackIgnore: true */ "../3rd-party/xterm-readline.js"),
|
||||
]);
|
||||
|
||||
const readline = new Readline();
|
||||
|
||||
Reference in New Issue
Block a user