2023-11-06 13:45:43 +01:00
|
|
|
let is_registered= false;
|
2023-09-26 16:02:10 +02:00
|
|
|
import { styles } from "../index.css.js";
|
|
|
|
export const css= styles().scope(example).css`
|
|
|
|
:host{
|
|
|
|
--body-max-width: 80rem;
|
2023-11-05 21:49:32 +01:00
|
|
|
height: 25rem;
|
2023-09-26 16:02:10 +02:00
|
|
|
}
|
|
|
|
`
|
2023-11-05 21:49:32 +01:00
|
|
|
import { el } from "deka-dom-el";
|
2023-09-26 16:02:10 +02:00
|
|
|
export function example({ src, language= "javascript" }){
|
|
|
|
register();
|
|
|
|
const cwd= "components";
|
|
|
|
src= "."+src.slice(src.indexOf(cwd)+cwd.length);
|
|
|
|
const code= s.cat(new URL(src, import.meta.url))
|
|
|
|
.toString()
|
|
|
|
.replaceAll(' from "../../../index-with-signals.js";', ' from "https://cdn.jsdelivr.net/gh/jaandrle/deka-dom-el/dist/esm-with-signals.js";');
|
|
|
|
const id= "code-"+Math.random().toString(36).slice(2, 7);
|
2023-11-06 14:04:27 +01:00
|
|
|
return el().append(
|
2023-09-26 16:02:10 +02:00
|
|
|
el("div", { id, className: example.name }).append(
|
|
|
|
el("pre").append(
|
2023-11-06 13:45:43 +01:00
|
|
|
el("code", { className: "language-"+language, textContent: code })
|
2023-09-26 16:02:10 +02:00
|
|
|
)
|
|
|
|
),
|
2023-10-09 13:51:55 +02:00
|
|
|
elCode({ id, content: code })
|
2023-09-26 16:02:10 +02:00
|
|
|
);
|
|
|
|
}
|
2023-10-09 13:51:55 +02:00
|
|
|
function elCode({ id, content }){
|
|
|
|
const options= JSON.stringify({
|
|
|
|
files: [{ name: ".js", content }],
|
|
|
|
toolbar: false
|
|
|
|
});
|
2023-11-05 21:49:32 +01:00
|
|
|
return el("script", `Flems(document.getElementById("${id}"), JSON.parse(${JSON.stringify(options)}));`);
|
2023-10-09 13:51:55 +02:00
|
|
|
}
|
2023-09-26 16:02:10 +02:00
|
|
|
function register(){
|
2023-11-06 13:45:43 +01:00
|
|
|
if(is_registered) return;
|
2023-09-26 16:02:10 +02:00
|
|
|
document.head.append(
|
|
|
|
el("script", { src: "https://flems.io/flems.html", type: "text/javascript", charset: "utf-8" })
|
|
|
|
);
|
2023-11-06 13:45:43 +01:00
|
|
|
is_registered= true;
|
2023-09-26 16:02:10 +02:00
|
|
|
}
|