@lionlang/ui 0.0.0-stage → 0.2.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/README.md +32 -2
- package/dist/artifact.d.mts +33 -0
- package/dist/artifact.d.mts.map +1 -0
- package/dist/artifact.mjs +141 -0
- package/dist/artifact.mjs.map +1 -0
- package/dist/browser-runtime.d.mts +24 -0
- package/dist/browser-runtime.d.mts.map +1 -0
- package/dist/browser-runtime.mjs +77 -0
- package/dist/browser-runtime.mjs.map +1 -0
- package/dist/dom-KrgvYUCe.mjs +1572 -0
- package/dist/dom-KrgvYUCe.mjs.map +1 -0
- package/dist/dom.d.mts +20 -0
- package/dist/dom.d.mts.map +1 -0
- package/dist/dom.mjs +3 -0
- package/dist/index.d.mts +32 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +99 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types-DREmbo5H.d.mts +28 -0
- package/dist/types-DREmbo5H.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +79 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +45 -4
- package/src/styles.css +1435 -0
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lionlang/ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Declarative, interactive, and streaming UI bindings and DOM renderer for Lion.
|
|
4
|
+
|
|
5
|
+
- **Pure Lion data:** every `ui/*` call (`ui/stack`, `ui/card`, `ui/metric`, `ui/alert`, `ui/table`, `ui/slider`, `ui/select`, `ui/toggle`, `ui/why`, `ui/proof`, ...) returns plain JSON-serializable nodes with zero DOM dependency.
|
|
6
|
+
- **Reactive state via Lion's logic database:** interactive controls carry quoted Lion actions (`onChange`, `onClick`) that update keyed facts and re-derive the view in memory.
|
|
7
|
+
- **Streaming UI:** stream newline-delimited Lion forms (`fact`, `rule`, `define`) into `createUiSession()` and re-render automatically as rules fire.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { Effect } from "effect";
|
|
13
|
+
import { createUiSession } from "@lionlang/ui";
|
|
14
|
+
import { renderUi } from "@lionlang/ui/dom";
|
|
15
|
+
import "@lionlang/ui/styles.css";
|
|
16
|
+
|
|
17
|
+
const session = createUiSession();
|
|
18
|
+
const tree = await Effect.runPromise(session.load(program));
|
|
19
|
+
renderUi(tree, container, {
|
|
20
|
+
onAction: async (action, value) => {
|
|
21
|
+
const next = await Effect.runPromise(session.dispatch(action, value));
|
|
22
|
+
renderUi(next, container, { onAction });
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Customizing CSS
|
|
28
|
+
|
|
29
|
+
`@lionlang/ui` supports three levels of styling control:
|
|
30
|
+
|
|
31
|
+
1. **CSS custom properties (`@lionlang/ui/styles.css`):** override `--lion-ui-bg`, `--lion-ui-surface`, `--lion-ui-surface-elevated`, `--lion-ui-border`, `--lion-ui-fg`, `--lion-ui-muted`, `--lion-ui-accent`, `--lion-ui-radius`, `--lion-ui-font-sans`, `--lion-ui-font-mono`, etc., or pass `theme: "light"` (`data-lion-theme="light"`).
|
|
32
|
+
2. **Per-slot class overrides:** pass `classes: { card: "...", button: "...", selectTrigger: "...", selectMenu: "..." }` to `renderUi()` (and optionally `unstyled: true` to omit default `lion-ui-*` classes for Tailwind or CSS Modules).
|
|
33
|
+
3. **Per-node classes:** any `ui/*` node accepts `{"className": "..."}` in its props.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/artifact.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Pure, zero-I/O standalone public HTML artifact builder (`@lionlang/ui/artifact`).
|
|
4
|
+
*
|
|
5
|
+
* Generates a self-contained, shareable HTML document whose entire interactive
|
|
6
|
+
* UI, Datalog queries, and formal proofs are evaluated and rendered by Lion in
|
|
7
|
+
* the browser. Works in Node, Bun, and browser environments alike.
|
|
8
|
+
*/
|
|
9
|
+
interface PublicArtifactOptions {
|
|
10
|
+
/** Optional CSS stylesheet content to inline into `<style>`. */
|
|
11
|
+
readonly css?: string;
|
|
12
|
+
/** Short meta description for shared links. */
|
|
13
|
+
readonly description?: string;
|
|
14
|
+
/** Optional link back to an artifact gallery (e.g. `../playground.html`). */
|
|
15
|
+
readonly galleryHref?: string;
|
|
16
|
+
/** Optional inline JS bundle for 100% offline single-file HTML export. */
|
|
17
|
+
readonly inlineRuntimeJs?: string;
|
|
18
|
+
/** Lion program (parsed JSON value or raw JSON string). */
|
|
19
|
+
readonly program: unknown;
|
|
20
|
+
/** External module URL when not inlining the runtime (default: `./lion-artifact-runtime.js`). */
|
|
21
|
+
readonly runtimeScriptUrl?: string;
|
|
22
|
+
/** Optional link to open this preset directly in the Playground Studio. */
|
|
23
|
+
readonly studioHref?: string;
|
|
24
|
+
/** Color theme preset (`"dark"` or `"light"`). */
|
|
25
|
+
readonly theme?: "dark" | "light";
|
|
26
|
+
/** Document `<title>` shown in browser tabs and link previews. */
|
|
27
|
+
readonly title: string;
|
|
28
|
+
}
|
|
29
|
+
/** Builds a complete, shareable public HTML page driven by a Lion UI program. */
|
|
30
|
+
declare const buildPublicArtifactHtml: (options: PublicArtifactOptions) => string;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { PublicArtifactOptions, buildPublicArtifactHtml };
|
|
33
|
+
//# sourceMappingURL=artifact.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact.d.mts","names":[],"sources":["../src/artifact.ts"],"mappings":";;AAQA;;;;;;UAAiB,qBAAA;EAQN;EAAA,SANA,GAAA;EAUA;EAAA,SARA,WAAA;EAYA;EAAA,SAVA,WAAA;EAYK;EAAA,SAVL,eAAA;EAwHE;EAAA,SAtHF,OAAA;;WAEA,gBAAA;EAqHqB;EAAA,SAnHrB,UAAA;;WAEA,KAAA;;WAEA,KAAA;AAAA;;cA8GE,uBAAA,GACX,OAAA,EAAS,qBAAA"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
//#region src/artifact.ts
|
|
2
|
+
const escapeHtml = (text) => text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
3
|
+
/** Escapes `<\/script>` and HTML comment markers inside embedded `<script>` blocks. */
|
|
4
|
+
const escapeScriptPayload = (text) => text.replaceAll("<", "\\u003c").replaceAll(">", "\\u003e");
|
|
5
|
+
const SHELL_CSS = `
|
|
6
|
+
* { box-sizing: border-box; }
|
|
7
|
+
body {
|
|
8
|
+
margin: 0;
|
|
9
|
+
min-height: 100vh;
|
|
10
|
+
background-color: var(--lion-ui-bg, #0b0c10);
|
|
11
|
+
background-image: radial-gradient(
|
|
12
|
+
ellipse 78% 36% at 50% -6%,
|
|
13
|
+
rgba(245, 158, 11, 0.13),
|
|
14
|
+
transparent 70%
|
|
15
|
+
);
|
|
16
|
+
color: var(--lion-ui-fg, #f8f7f4);
|
|
17
|
+
font-family: var(--lion-ui-font-sans, system-ui, sans-serif);
|
|
18
|
+
-webkit-font-smoothing: antialiased;
|
|
19
|
+
}
|
|
20
|
+
[data-lion-theme="light"] body {
|
|
21
|
+
background-image: radial-gradient(
|
|
22
|
+
ellipse 78% 36% at 50% -6%,
|
|
23
|
+
rgba(194, 101, 12, 0.08),
|
|
24
|
+
transparent 70%
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
.lion-artifact-shell {
|
|
28
|
+
max-width: 1120px;
|
|
29
|
+
margin: 0 auto;
|
|
30
|
+
padding: 1.5rem 1.25rem 3rem;
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-direction: column;
|
|
33
|
+
gap: 1.25rem;
|
|
34
|
+
}
|
|
35
|
+
.lion-artifact-nav {
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: space-between;
|
|
39
|
+
gap: 0.75rem;
|
|
40
|
+
font-size: 0.82rem;
|
|
41
|
+
color: var(--lion-ui-muted, #a1a1aa);
|
|
42
|
+
}
|
|
43
|
+
.lion-artifact-nav a {
|
|
44
|
+
color: var(--lion-ui-muted, #a1a1aa);
|
|
45
|
+
text-decoration: none;
|
|
46
|
+
padding: 0.3rem 0.6rem;
|
|
47
|
+
border-radius: 6px;
|
|
48
|
+
border: 1px solid var(--lion-ui-border, #27272a);
|
|
49
|
+
}
|
|
50
|
+
.lion-artifact-nav a:hover {
|
|
51
|
+
color: var(--lion-ui-fg, #fafafa);
|
|
52
|
+
border-color: var(--lion-ui-border-strong, #3f3f46);
|
|
53
|
+
}
|
|
54
|
+
.lion-artifact-footer {
|
|
55
|
+
margin-top: 1.5rem;
|
|
56
|
+
padding-top: 1rem;
|
|
57
|
+
border-top: 1px solid var(--lion-ui-border, #27272a);
|
|
58
|
+
display: flex;
|
|
59
|
+
flex-wrap: wrap;
|
|
60
|
+
align-items: center;
|
|
61
|
+
justify-content: space-between;
|
|
62
|
+
gap: 0.75rem;
|
|
63
|
+
font-size: 0.8rem;
|
|
64
|
+
color: var(--lion-ui-muted, #a1a1aa);
|
|
65
|
+
}
|
|
66
|
+
.lion-artifact-source {
|
|
67
|
+
margin-top: 0.5rem;
|
|
68
|
+
border: 1px solid var(--lion-ui-border, #27272a);
|
|
69
|
+
border-radius: var(--lion-ui-radius, 10px);
|
|
70
|
+
padding: 0.75rem 1rem;
|
|
71
|
+
background: var(--lion-ui-surface, rgba(255,255,255,0.025));
|
|
72
|
+
}
|
|
73
|
+
.lion-artifact-source summary {
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
font-weight: 600;
|
|
76
|
+
font-size: 0.85rem;
|
|
77
|
+
}
|
|
78
|
+
.lion-artifact-source pre {
|
|
79
|
+
margin: 0.75rem 0 0;
|
|
80
|
+
max-height: 360px;
|
|
81
|
+
overflow: auto;
|
|
82
|
+
font-family: var(--lion-ui-font-mono, monospace);
|
|
83
|
+
font-size: 0.78rem;
|
|
84
|
+
line-height: 1.45;
|
|
85
|
+
white-space: pre-wrap;
|
|
86
|
+
word-break: break-word;
|
|
87
|
+
}
|
|
88
|
+
.lion-artifact-copy {
|
|
89
|
+
cursor: pointer;
|
|
90
|
+
border: 1px solid var(--lion-ui-border-strong, #3f3f46);
|
|
91
|
+
background: transparent;
|
|
92
|
+
color: var(--lion-ui-fg, #fafafa);
|
|
93
|
+
border-radius: 6px;
|
|
94
|
+
padding: 0.3rem 0.65rem;
|
|
95
|
+
font-size: 0.78rem;
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
/** Builds a complete, shareable public HTML page driven by a Lion UI program. */
|
|
99
|
+
const buildPublicArtifactHtml = (options) => {
|
|
100
|
+
const theme = options.theme ?? "dark";
|
|
101
|
+
const sourceJson = typeof options.program === "string" ? options.program : JSON.stringify(options.program, null, 2);
|
|
102
|
+
const runtimeTag = options.inlineRuntimeJs === void 0 ? `<script type="module" src="${escapeHtml(options.runtimeScriptUrl ?? "./lion-artifact-runtime.js")}"><\/script>` : `<script type="module">${options.inlineRuntimeJs.replaceAll("<\/script>", "<\\/script>")}<\/script>`;
|
|
103
|
+
const navBar = options.galleryHref || options.studioHref ? `<nav class="lion-artifact-nav">
|
|
104
|
+
${options.galleryHref ? `<a href="${escapeHtml(options.galleryHref)}">← All Lion Artifacts</a>` : "<span></span>"}
|
|
105
|
+
${options.studioHref ? `<a href="${escapeHtml(options.studioHref)}">Open in Live Studio →</a>` : ""}
|
|
106
|
+
</nav>` : "";
|
|
107
|
+
return `<!doctype html>
|
|
108
|
+
<html lang="en" data-lion-theme="${theme}">
|
|
109
|
+
<head>
|
|
110
|
+
<meta charset="utf-8">
|
|
111
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
112
|
+
<title>${escapeHtml(options.title)}</title>
|
|
113
|
+
${options.description ? `<meta name="description" content="${escapeHtml(options.description)}">` : ""}
|
|
114
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
115
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
116
|
+
<link href="https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
|
|
117
|
+
<style>${options.css ?? ""}\n${SHELL_CSS}</style>
|
|
118
|
+
</head>
|
|
119
|
+
<body>
|
|
120
|
+
<main class="lion-artifact-shell">
|
|
121
|
+
${navBar}
|
|
122
|
+
<div id="lion-artifact-root" data-lion-theme="${theme}">Loading Lion artifact…</div>
|
|
123
|
+
<details class="lion-artifact-source">
|
|
124
|
+
<summary>Inspect Lion Program Source (JSON)</summary>
|
|
125
|
+
<pre>${escapeHtml(sourceJson)}</pre>
|
|
126
|
+
</details>
|
|
127
|
+
<footer class="lion-artifact-footer">
|
|
128
|
+
<span>Generated & executed live in-browser by <strong>Lion</strong> (Graph-as-Code + Declarative UI)</span>
|
|
129
|
+
<button id="lion-artifact-copy" class="lion-artifact-copy" type="button">Copy Lion JSON</button>
|
|
130
|
+
</footer>
|
|
131
|
+
</main>
|
|
132
|
+
<script id="lion-artifact-program" type="application/json">${escapeScriptPayload(sourceJson)}<\/script>
|
|
133
|
+
${runtimeTag}
|
|
134
|
+
</body>
|
|
135
|
+
</html>
|
|
136
|
+
`;
|
|
137
|
+
};
|
|
138
|
+
//#endregion
|
|
139
|
+
export { buildPublicArtifactHtml };
|
|
140
|
+
|
|
141
|
+
//# sourceMappingURL=artifact.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact.mjs","names":[],"sources":["../src/artifact.ts"],"sourcesContent":["/**\n * Pure, zero-I/O standalone public HTML artifact builder (`@lionlang/ui/artifact`).\n *\n * Generates a self-contained, shareable HTML document whose entire interactive\n * UI, Datalog queries, and formal proofs are evaluated and rendered by Lion in\n * the browser. Works in Node, Bun, and browser environments alike.\n */\n\nexport interface PublicArtifactOptions {\n /** Optional CSS stylesheet content to inline into `<style>`. */\n readonly css?: string;\n /** Short meta description for shared links. */\n readonly description?: string;\n /** Optional link back to an artifact gallery (e.g. `../playground.html`). */\n readonly galleryHref?: string;\n /** Optional inline JS bundle for 100% offline single-file HTML export. */\n readonly inlineRuntimeJs?: string;\n /** Lion program (parsed JSON value or raw JSON string). */\n readonly program: unknown;\n /** External module URL when not inlining the runtime (default: `./lion-artifact-runtime.js`). */\n readonly runtimeScriptUrl?: string;\n /** Optional link to open this preset directly in the Playground Studio. */\n readonly studioHref?: string;\n /** Color theme preset (`\"dark\"` or `\"light\"`). */\n readonly theme?: \"dark\" | \"light\";\n /** Document `<title>` shown in browser tabs and link previews. */\n readonly title: string;\n}\n\nconst escapeHtml = (text: string): string =>\n text\n .replaceAll(\"&\", \"&\")\n .replaceAll(\"<\", \"<\")\n .replaceAll(\">\", \">\")\n .replaceAll('\"', \""\")\n .replaceAll(\"'\", \"'\");\n\n/** Escapes `</script>` and HTML comment markers inside embedded `<script>` blocks. */\nconst escapeScriptPayload = (text: string): string =>\n text.replaceAll(\"<\", \"\\\\u003c\").replaceAll(\">\", \"\\\\u003e\");\n\nconst SHELL_CSS = `\n* { box-sizing: border-box; }\nbody {\n margin: 0;\n min-height: 100vh;\n background-color: var(--lion-ui-bg, #0b0c10);\n background-image: radial-gradient(\n ellipse 78% 36% at 50% -6%,\n rgba(245, 158, 11, 0.13),\n transparent 70%\n );\n color: var(--lion-ui-fg, #f8f7f4);\n font-family: var(--lion-ui-font-sans, system-ui, sans-serif);\n -webkit-font-smoothing: antialiased;\n}\n[data-lion-theme=\"light\"] body {\n background-image: radial-gradient(\n ellipse 78% 36% at 50% -6%,\n rgba(194, 101, 12, 0.08),\n transparent 70%\n );\n}\n.lion-artifact-shell {\n max-width: 1120px;\n margin: 0 auto;\n padding: 1.5rem 1.25rem 3rem;\n display: flex;\n flex-direction: column;\n gap: 1.25rem;\n}\n.lion-artifact-nav {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 0.75rem;\n font-size: 0.82rem;\n color: var(--lion-ui-muted, #a1a1aa);\n}\n.lion-artifact-nav a {\n color: var(--lion-ui-muted, #a1a1aa);\n text-decoration: none;\n padding: 0.3rem 0.6rem;\n border-radius: 6px;\n border: 1px solid var(--lion-ui-border, #27272a);\n}\n.lion-artifact-nav a:hover {\n color: var(--lion-ui-fg, #fafafa);\n border-color: var(--lion-ui-border-strong, #3f3f46);\n}\n.lion-artifact-footer {\n margin-top: 1.5rem;\n padding-top: 1rem;\n border-top: 1px solid var(--lion-ui-border, #27272a);\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n justify-content: space-between;\n gap: 0.75rem;\n font-size: 0.8rem;\n color: var(--lion-ui-muted, #a1a1aa);\n}\n.lion-artifact-source {\n margin-top: 0.5rem;\n border: 1px solid var(--lion-ui-border, #27272a);\n border-radius: var(--lion-ui-radius, 10px);\n padding: 0.75rem 1rem;\n background: var(--lion-ui-surface, rgba(255,255,255,0.025));\n}\n.lion-artifact-source summary {\n cursor: pointer;\n font-weight: 600;\n font-size: 0.85rem;\n}\n.lion-artifact-source pre {\n margin: 0.75rem 0 0;\n max-height: 360px;\n overflow: auto;\n font-family: var(--lion-ui-font-mono, monospace);\n font-size: 0.78rem;\n line-height: 1.45;\n white-space: pre-wrap;\n word-break: break-word;\n}\n.lion-artifact-copy {\n cursor: pointer;\n border: 1px solid var(--lion-ui-border-strong, #3f3f46);\n background: transparent;\n color: var(--lion-ui-fg, #fafafa);\n border-radius: 6px;\n padding: 0.3rem 0.65rem;\n font-size: 0.78rem;\n}\n`;\n\n/** Builds a complete, shareable public HTML page driven by a Lion UI program. */\nexport const buildPublicArtifactHtml = (\n options: PublicArtifactOptions\n): string => {\n const theme = options.theme ?? \"dark\";\n const sourceJson =\n typeof options.program === \"string\"\n ? options.program\n : JSON.stringify(options.program, null, 2);\n const runtimeTag =\n options.inlineRuntimeJs === undefined\n ? `<script type=\"module\" src=\"${escapeHtml(options.runtimeScriptUrl ?? \"./lion-artifact-runtime.js\")}\"></script>`\n : `<script type=\"module\">${options.inlineRuntimeJs.replaceAll(\"</script>\", \"<\\\\/script>\")}</script>`;\n\n const navBar =\n options.galleryHref || options.studioHref\n ? `<nav class=\"lion-artifact-nav\">\n ${options.galleryHref ? `<a href=\"${escapeHtml(options.galleryHref)}\">← All Lion Artifacts</a>` : \"<span></span>\"}\n ${options.studioHref ? `<a href=\"${escapeHtml(options.studioHref)}\">Open in Live Studio →</a>` : \"\"}\n </nav>`\n : \"\";\n\n return `<!doctype html>\n<html lang=\"en\" data-lion-theme=\"${theme}\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>${escapeHtml(options.title)}</title>\n ${options.description ? `<meta name=\"description\" content=\"${escapeHtml(options.description)}\">` : \"\"}\n <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n <link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\n <link href=\"https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap\" rel=\"stylesheet\">\n <style>${options.css ?? \"\"}\\n${SHELL_CSS}</style>\n</head>\n<body>\n <main class=\"lion-artifact-shell\">\n ${navBar}\n <div id=\"lion-artifact-root\" data-lion-theme=\"${theme}\">Loading Lion artifact…</div>\n <details class=\"lion-artifact-source\">\n <summary>Inspect Lion Program Source (JSON)</summary>\n <pre>${escapeHtml(sourceJson)}</pre>\n </details>\n <footer class=\"lion-artifact-footer\">\n <span>Generated & executed live in-browser by <strong>Lion</strong> (Graph-as-Code + Declarative UI)</span>\n <button id=\"lion-artifact-copy\" class=\"lion-artifact-copy\" type=\"button\">Copy Lion JSON</button>\n </footer>\n </main>\n <script id=\"lion-artifact-program\" type=\"application/json\">${escapeScriptPayload(sourceJson)}</script>\n ${runtimeTag}\n</body>\n</html>\n`;\n};\n"],"mappings":";AA6BA,MAAM,cAAc,SAClB,KACG,WAAW,KAAK,QAAQ,CACxB,WAAW,KAAK,OAAO,CACvB,WAAW,KAAK,OAAO,CACvB,WAAW,MAAK,SAAS,CACzB,WAAW,KAAK,QAAQ;;AAG7B,MAAM,uBAAuB,SAC3B,KAAK,WAAW,KAAK,UAAU,CAAC,WAAW,KAAK,UAAU;AAE5D,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FlB,MAAa,2BACX,YACW;CACX,MAAM,QAAQ,QAAQ,SAAS;CAC/B,MAAM,aACJ,OAAO,QAAQ,YAAY,WACvB,QAAQ,UACR,KAAK,UAAU,QAAQ,SAAS,MAAM,EAAE;CAC9C,MAAM,aACJ,QAAQ,oBAAoB,KAAA,IACxB,8BAA8B,WAAW,QAAQ,oBAAoB,6BAA6B,CAAC,gBACnG,yBAAyB,QAAQ,gBAAgB,WAAW,cAAa,cAAc,CAAC;CAE9F,MAAM,SACJ,QAAQ,eAAe,QAAQ,aAC3B;QACA,QAAQ,cAAc,YAAY,WAAW,QAAQ,YAAY,CAAC,mCAAmC,gBAAgB;QACrH,QAAQ,aAAa,YAAY,WAAW,QAAQ,WAAW,CAAC,oCAAoC,GAAG;cAEvG;AAEN,QAAO;mCAC0B,MAAM;;;;WAI9B,WAAW,QAAQ,MAAM,CAAC;IACjC,QAAQ,cAAc,qCAAqC,WAAW,QAAQ,YAAY,CAAC,MAAM,GAAG;;;;WAI7F,QAAQ,OAAO,GAAG,IAAI,UAAU;;;;MAIrC,OAAO;oDACuC,MAAM;;;aAG7C,WAAW,WAAW,CAAC;;;;;;;+DAO2B,oBAAoB,WAAW,CAAC;IAC3F,WAAW"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PublicArtifactOptions } from "./artifact.mjs";
|
|
2
|
+
import { UiSession } from "./index.mjs";
|
|
3
|
+
import { RenderUiOptions } from "./dom.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/browser-runtime.d.ts
|
|
6
|
+
/** Builds a standalone public HTML artifact page from a Lion UI program. */
|
|
7
|
+
declare const buildPublicArtifactHtml: (options: PublicArtifactOptions) => string;
|
|
8
|
+
interface MountArtifactOptions extends RenderUiOptions {
|
|
9
|
+
readonly onError?: (message: string) => void;
|
|
10
|
+
readonly onProgramLoaded?: (source: string) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Mounts a live, interactive Lion program into `container` entirely in the
|
|
14
|
+
* browser using `createUiSession` + `renderUi`.
|
|
15
|
+
*/
|
|
16
|
+
declare const mountLionArtifact: (container: HTMLElement, program: unknown, options?: MountArtifactOptions) => {
|
|
17
|
+
load: (nextProgram: unknown) => Promise<void>;
|
|
18
|
+
session: UiSession;
|
|
19
|
+
};
|
|
20
|
+
/** Auto-boots standalone HTML pages generated by `buildPublicArtifactHtml`. */
|
|
21
|
+
declare const bootDocumentArtifact: () => void;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { MountArtifactOptions, bootDocumentArtifact, buildPublicArtifactHtml, mountLionArtifact };
|
|
24
|
+
//# sourceMappingURL=browser-runtime.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-runtime.d.mts","names":[],"sources":["../src/browser-runtime.ts"],"mappings":";;;;;;cAca,uBAAA,GACX,OAAA,EAAS,qBAAA;AAAA,UAGM,oBAAA,SAA6B,eAAA;EAAA,SACnC,OAAA,IAAW,OAAA;EAAA,SACX,eAAA,IAAmB,MAAA;AAAA;;;AAF9B;;cASa,iBAAA,GACX,SAAA,EAAW,WAAA,EACX,OAAA,WACA,OAAA,GAAS,oBAAA;kCA8ByB,OAAA;WAAA,SAAA;AAAA;;cAiBvB,oBAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { isUiNode } from "./types.mjs";
|
|
2
|
+
import { createUiSession } from "./index.mjs";
|
|
3
|
+
import { t as renderUi } from "./dom-KrgvYUCe.mjs";
|
|
4
|
+
import { buildPublicArtifactHtml as buildPublicArtifactHtml$1 } from "./artifact.mjs";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
//#region src/browser-runtime.ts
|
|
7
|
+
/**
|
|
8
|
+
* Browser runtime bootstrap for standalone public Lion UI artifacts
|
|
9
|
+
* (`@lionlang/ui/browser-runtime`).
|
|
10
|
+
*/
|
|
11
|
+
/** Builds a standalone public HTML artifact page from a Lion UI program. */
|
|
12
|
+
const buildPublicArtifactHtml = (options) => buildPublicArtifactHtml$1(options);
|
|
13
|
+
/**
|
|
14
|
+
* Mounts a live, interactive Lion program into `container` entirely in the
|
|
15
|
+
* browser using `createUiSession` + `renderUi`.
|
|
16
|
+
*/
|
|
17
|
+
const mountLionArtifact = (container, program, options = {}) => {
|
|
18
|
+
const session = createUiSession();
|
|
19
|
+
const showError = (err) => {
|
|
20
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
21
|
+
options.onError?.(msg);
|
|
22
|
+
const pre = container.ownerDocument.createElement("pre");
|
|
23
|
+
pre.className = "lion-ui-code";
|
|
24
|
+
pre.textContent = `Lion error: ${msg}`;
|
|
25
|
+
container.replaceChildren(pre);
|
|
26
|
+
};
|
|
27
|
+
const paint = (value) => {
|
|
28
|
+
if (isUiNode(value)) {
|
|
29
|
+
renderUi(value, container, {
|
|
30
|
+
...options,
|
|
31
|
+
onAction: (action, val) => {
|
|
32
|
+
Effect.runPromise(session.dispatch(action, val)).then(paint).catch(showError);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const pre = container.ownerDocument.createElement("pre");
|
|
38
|
+
pre.className = "lion-ui-code";
|
|
39
|
+
pre.textContent = JSON.stringify(value, null, 2);
|
|
40
|
+
container.replaceChildren(pre);
|
|
41
|
+
};
|
|
42
|
+
const load = (nextProgram) => Effect.runPromise(session.load(nextProgram)).then((res) => {
|
|
43
|
+
paint(res);
|
|
44
|
+
options.onProgramLoaded?.(typeof nextProgram === "string" ? nextProgram : JSON.stringify(nextProgram, null, 2));
|
|
45
|
+
}).catch(showError);
|
|
46
|
+
load(program);
|
|
47
|
+
return {
|
|
48
|
+
load,
|
|
49
|
+
session
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/** Auto-boots standalone HTML pages generated by `buildPublicArtifactHtml`. */
|
|
53
|
+
const bootDocumentArtifact = () => {
|
|
54
|
+
if (typeof document === "undefined") return;
|
|
55
|
+
const root = document.getElementById("lion-artifact-root");
|
|
56
|
+
const scriptEl = document.getElementById("lion-artifact-program");
|
|
57
|
+
if (!(root && scriptEl)) return;
|
|
58
|
+
const theme = document.documentElement.dataset.lionTheme === "light" ? "light" : "dark";
|
|
59
|
+
const sourceText = scriptEl.textContent ?? "null";
|
|
60
|
+
mountLionArtifact(root, sourceText, { theme });
|
|
61
|
+
const copyBtn = document.getElementById("lion-artifact-copy");
|
|
62
|
+
if (copyBtn) copyBtn.addEventListener("click", () => {
|
|
63
|
+
navigator.clipboard?.writeText(sourceText).then(() => {
|
|
64
|
+
const prev = copyBtn.textContent;
|
|
65
|
+
copyBtn.textContent = "Copied JSON";
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
copyBtn.textContent = prev;
|
|
68
|
+
}, 1400);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
if (typeof document !== "undefined") if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", bootDocumentArtifact);
|
|
73
|
+
else bootDocumentArtifact();
|
|
74
|
+
//#endregion
|
|
75
|
+
export { bootDocumentArtifact, buildPublicArtifactHtml, mountLionArtifact };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=browser-runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-runtime.mjs","names":["buildArtifactHtml"],"sources":["../src/browser-runtime.ts"],"sourcesContent":["/**\n * Browser runtime bootstrap for standalone public Lion UI artifacts\n * (`@lionlang/ui/browser-runtime`).\n */\nimport { Effect } from \"effect\";\nimport {\n buildPublicArtifactHtml as buildArtifactHtml,\n type PublicArtifactOptions,\n} from \"./artifact.ts\";\nimport { type RenderUiOptions, renderUi } from \"./dom.ts\";\nimport { createUiSession } from \"./index.ts\";\nimport { isUiNode } from \"./types.ts\";\n\n/** Builds a standalone public HTML artifact page from a Lion UI program. */\nexport const buildPublicArtifactHtml = (\n options: PublicArtifactOptions\n): string => buildArtifactHtml(options);\n\nexport interface MountArtifactOptions extends RenderUiOptions {\n readonly onError?: (message: string) => void;\n readonly onProgramLoaded?: (source: string) => void;\n}\n\n/**\n * Mounts a live, interactive Lion program into `container` entirely in the\n * browser using `createUiSession` + `renderUi`.\n */\nexport const mountLionArtifact = (\n container: HTMLElement,\n program: unknown,\n options: MountArtifactOptions = {}\n) => {\n const session = createUiSession();\n const showError = (err: unknown) => {\n const msg = err instanceof Error ? err.message : String(err);\n options.onError?.(msg);\n const pre = container.ownerDocument.createElement(\"pre\");\n pre.className = \"lion-ui-code\";\n pre.textContent = `Lion error: ${msg}`;\n container.replaceChildren(pre);\n };\n\n const paint = (value: unknown) => {\n if (isUiNode(value)) {\n renderUi(value, container, {\n ...options,\n onAction: (action, val) => {\n Effect.runPromise(session.dispatch(action, val))\n .then(paint)\n .catch(showError);\n },\n });\n return;\n }\n const pre = container.ownerDocument.createElement(\"pre\");\n pre.className = \"lion-ui-code\";\n pre.textContent = JSON.stringify(value, null, 2);\n container.replaceChildren(pre);\n };\n\n const load = (nextProgram: unknown) =>\n Effect.runPromise(session.load(nextProgram))\n .then((res) => {\n paint(res);\n options.onProgramLoaded?.(\n typeof nextProgram === \"string\"\n ? nextProgram\n : JSON.stringify(nextProgram, null, 2)\n );\n })\n .catch(showError);\n\n load(program);\n return { load, session };\n};\n\n/** Auto-boots standalone HTML pages generated by `buildPublicArtifactHtml`. */\nexport const bootDocumentArtifact = (): void => {\n if (typeof document === \"undefined\") {\n return;\n }\n const root = document.getElementById(\"lion-artifact-root\");\n const scriptEl = document.getElementById(\"lion-artifact-program\");\n if (!(root && scriptEl)) {\n return;\n }\n const theme =\n document.documentElement.dataset.lionTheme === \"light\" ? \"light\" : \"dark\";\n const sourceText = scriptEl.textContent ?? \"null\";\n mountLionArtifact(root, sourceText, { theme });\n\n const copyBtn = document.getElementById(\"lion-artifact-copy\");\n if (copyBtn) {\n copyBtn.addEventListener(\"click\", () => {\n navigator.clipboard?.writeText(sourceText).then(() => {\n const prev = copyBtn.textContent;\n copyBtn.textContent = \"Copied JSON\";\n setTimeout(() => {\n copyBtn.textContent = prev;\n }, 1400);\n });\n });\n }\n};\n\nif (typeof document !== \"undefined\") {\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", bootDocumentArtifact);\n } else {\n bootDocumentArtifact();\n }\n}\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,2BACX,YACWA,0BAAkB,QAAQ;;;;;AAWvC,MAAa,qBACX,WACA,SACA,UAAgC,EAAE,KAC/B;CACH,MAAM,UAAU,iBAAiB;CACjC,MAAM,aAAa,QAAiB;EAClC,MAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;AAC5D,UAAQ,UAAU,IAAI;EACtB,MAAM,MAAM,UAAU,cAAc,cAAc,MAAM;AACxD,MAAI,YAAY;AAChB,MAAI,cAAc,eAAe;AACjC,YAAU,gBAAgB,IAAI;;CAGhC,MAAM,SAAS,UAAmB;AAChC,MAAI,SAAS,MAAM,EAAE;AACnB,YAAS,OAAO,WAAW;IACzB,GAAG;IACH,WAAW,QAAQ,QAAQ;AACzB,YAAO,WAAW,QAAQ,SAAS,QAAQ,IAAI,CAAC,CAC7C,KAAK,MAAM,CACX,MAAM,UAAU;;IAEtB,CAAC;AACF;;EAEF,MAAM,MAAM,UAAU,cAAc,cAAc,MAAM;AACxD,MAAI,YAAY;AAChB,MAAI,cAAc,KAAK,UAAU,OAAO,MAAM,EAAE;AAChD,YAAU,gBAAgB,IAAI;;CAGhC,MAAM,QAAQ,gBACZ,OAAO,WAAW,QAAQ,KAAK,YAAY,CAAC,CACzC,MAAM,QAAQ;AACb,QAAM,IAAI;AACV,UAAQ,kBACN,OAAO,gBAAgB,WACnB,cACA,KAAK,UAAU,aAAa,MAAM,EAAE,CACzC;GACD,CACD,MAAM,UAAU;AAErB,MAAK,QAAQ;AACb,QAAO;EAAE;EAAM;EAAS;;;AAI1B,MAAa,6BAAmC;AAC9C,KAAI,OAAO,aAAa,YACtB;CAEF,MAAM,OAAO,SAAS,eAAe,qBAAqB;CAC1D,MAAM,WAAW,SAAS,eAAe,wBAAwB;AACjE,KAAI,EAAE,QAAQ,UACZ;CAEF,MAAM,QACJ,SAAS,gBAAgB,QAAQ,cAAc,UAAU,UAAU;CACrE,MAAM,aAAa,SAAS,eAAe;AAC3C,mBAAkB,MAAM,YAAY,EAAE,OAAO,CAAC;CAE9C,MAAM,UAAU,SAAS,eAAe,qBAAqB;AAC7D,KAAI,QACF,SAAQ,iBAAiB,eAAe;AACtC,YAAU,WAAW,UAAU,WAAW,CAAC,WAAW;GACpD,MAAM,OAAO,QAAQ;AACrB,WAAQ,cAAc;AACtB,oBAAiB;AACf,YAAQ,cAAc;MACrB,KAAK;IACR;GACF;;AAIN,IAAI,OAAO,aAAa,YACtB,KAAI,SAAS,eAAe,UAC1B,UAAS,iBAAiB,oBAAoB,qBAAqB;IAEnE,uBAAsB"}
|