Xuda Slim
Xuda Slim
Xuda Slim is the lightweight browser runtime for running Xuda programs without the full project-loader flow.
It is designed for:
- standalone HTML pages
- HTML-authored Slim pages that Xuda converts into
progUi - embeddable widgets and plugin test harnesses
- local Vite-based experiments
- hand-authored
project_data project_data-driven pages
The important mental model is:
- Xuda Slim is still the Xuda runtime
- it still creates a Xuda session and datasource system
- it is not an Alpine clone with local proxy state
- it becomes "HTML-like" by letting you author
xu-*directives and/or provideproject_datadirectly
<template> is supported, but it is not required.
What Slim Can Boot From
Xuda Slim currently supports three practical input modes:
- HTML-authored pages via
<template>tags project_data- plugin runtime pages that load the slim bundle and then mount custom runtime code
These modes can also be mixed. If slim mode receives project_data and the page also contains <template> tags, the templates are parsed and added into project_data.programs.
Important precision:
- In the current checked-in runtime, the verified automatic HTML-to-
progUipath is template-driven. - There is commented code hinting at parsing the mount/root element HTML directly, but the active local path I could verify is
<template>parsing.
How Slim Starts
In slim mode the runtime:
- creates a session with
SLIM_BUNDLEenabled - resolves session values from URL params, root element attributes, constructor options, cookies, and local storage
- creates the app shell and embed container
- creates the system datasource
- renders the selected program from
_session.project_data
Session value resolution order is:
- URL parameter
- root element attribute
options.params[key]options[key]- cookie
- local storage
Default values relevant to slim are:
domain: current hostengine_mode:miniappapp_id:unknown
Loading Xuda Slim
Option 1: HTML-Authored Slim Page
Use this when you want to author the UI in HTML and let Xuda convert it into progUi.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://dev.xuda.ai/dist/runtime/js/xuda-runtime-slim.js"></script>
<script>
const boot = function () {
const Xuda = globalThis.xuda?.xuda || globalThis.xuda;
document.body.addEventListener("on_mounted", () => {
console.log("HTML Slim page mounted");
}, { once: true });
new Xuda(document.getElementById("app"), {
domain: "dev.xuda.ai",
prog_id: "demo",
});
};
document.addEventListener("DOMContentLoaded", boot, { once: true });
</script>
</head>
<body>
<div id="app"></div>
<template id="demo">
<div class="p-6" xu-store="{'title':'Hello from Slim HTML'}">
<h1 xu-exp:xu-content="@title"></h1>
</div>
</template>
</body>
</html>
Notes:
- In slim mode the mount element is optional. If you omit it, the runtime falls back to
body. - Use
prog_idto choose the startup program. Some older local examples still showprog, but the current slim bootstrap readsprog_id. - The automatic HTML conversion path currently reads
<template>tags and parses them into programs.
Option 2: Global CDN Script With project_data
Use this when you want a plain HTML page and want to provide the UI tree explicitly as project_data.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://dev.xuda.ai/dist/runtime/js/xuda-runtime-slim.js"></script>
</head>
<body>
<script>
const setMounted = () => {
console.log("Xuda Slim mounted");
};
const project_data = {
globals: {
ViewEventObj: {},
progFields: [],
properties: { menuType: "globals" },
},
tables: {},
programs: {
hello: {
_id: "hello",
properties: { menuType: "component", renderType: "form" },
progDataSource: {},
progEvents: [],
progFields: [],
progUi: [
{
id: "root",
type: "element",
tagName: "div",
attributes: {
class: "p-6 text-xl",
"xu-content": "Hello from Xuda Slim",
},
children: [],
},
],
},
},
};
document.body.addEventListener("on_mounted", setMounted, { once: true });
new xuda(document.body, {
domain: "dev.xuda.ai",
prog_id: "hello",
project_data,
});
</script>
</body>
</html>
Option 3: ES Module Package
Use this when you want a package-managed build. For manual local HTML testing in this repo, prefer the live CDN bundle so you always pick up the latest post-bundle runtime.
Current local example package:
@xuda.io/xuda-runtime-slim-es
Example:
import { xuda as xudaRuntime } from "@xuda.io/xuda-runtime-slim-es";
import { project_data } from "./project_data.js";
const Xuda = xudaRuntime.xuda || xudaRuntime.default || xudaRuntime;
document.addEventListener("DOMContentLoaded", () => {
document.body.addEventListener("on_mounted", () => {
console.log("Slim program mounted");
}, { once: true });
new Xuda(document.body, {
domain: "dev.xuda.ai",
prog_id: "test_prog",
project_data,
});
}, { once: true });
The local repo test package lives in:
test/slim/package.json- The repo HTML examples use the live CDN bundle so they track the newest runtime immediately after you rebuild and publish Slim.
Constructor API
Xuda Slim uses the same top-level constructor shape as the browser runtime:
new xuda(element?, options?, callback?)
new xuda.xuda(element?, options?, callback?)
Arguments:
element: a real DOM element to mount into. Optional in slim mode.options: slim/session/runtime options.callback: an optional runtime callback. When the app is ready, Xuda calls it ascallback("xuda_ready", SESSION_ID, SESSION_OBJ).
For mount completion, the most compatible hook is the body event:
document.body.addEventListener("on_mounted", () => {
// called after Slim boot finishes
}, { once: true });
Some builds also return an object with app.on_mounted(fn), but the event listener works across local examples without depending on that helper shape.
Common Options
These are the most useful options for slim pages.
domain- Used for runtime asset/module URLs.
- In local repo examples this is often
dev.xuda.ai.
prog_id- The startup program id.
- Must exist in
project_data.programsor be created from a<template id="...">.
project_data- Inline Xuda project definition.
- This is the main non-template path for slim.
debug_js- Enables debug mode behavior.
params- Supplemental session values by key.
url_params- Extra program input values to feed into the session.
app_id- Optional in slim when you fully provide
project_data.
- Optional in slim when you fully provide
engine_mode- Defaults to
miniappif not provided.
- Defaults to
route_idandmenu_id- Advanced route-driven startup flow.
The project_data Shape
The minimum practical shape is:
export const project_data = {
globals: {
ViewEventObj: {},
progFields: [],
properties: { menuType: "globals" },
},
tables: {},
programs: {
my_program: {
_id: "my_program",
properties: {
menuType: "component",
renderType: "form",
},
progDataSource: {},
progEvents: [],
progFields: [],
progUi: [
{
id: "node-1",
type: "element",
tagName: "div",
attributes: {
class: "p-4",
"xu-content": "Hello",
},
children: [],
},
],
},
},
};
Key fields:
globals- Global program fields and metadata.
tables- Table definitions if your program depends on them.
programs- Program map keyed by program id.
progUi- The render tree Xuda consumes.
- This can be hand-authored, generated by tools, or derived from
<template>.
Using <template> Tags
<template> is a convenience layer, not a requirement.
In slim mode, when the page contains templates:
- Xuda reads every
<template> - uses the template
idas the program id, ortemplate_<index>if no id exists - parses the HTML into
progUi - stores the result under
_session.project_data.programs - chooses the first template as
prog_idif none was supplied
Example:
<body></body>
<template id="counter">
<div class="p-6 space-y-4" xu-store="{'count': 0}">
<h1 class="text-2xl font-bold" xu-exp:xu-content="'Count: ' + @count"></h1>
<button
class="rounded bg-black px-4 py-2 text-white"
xu-click="{'@count': @count + 1}">
Increment
</button>
</div>
</template>
<script type="module">
import { xuda as xudaRuntime } from "@xuda.io/xuda-runtime-slim-es";
const Xuda = xudaRuntime.xuda || xudaRuntime.default || xudaRuntime;
document.addEventListener("DOMContentLoaded", () => {
new Xuda(document.body, {
domain: "dev.xuda.ai",
prog_id: "counter",
});
}, { once: true });
</script>
Important details:
- Templates are optional.
- If you already pass
project_data, templates extend that data instead of replacing slim entirely. - Template attributes that look like valid JSON are auto-parsed with
JSON.parse. - If JSON parsing fails, the raw string is preserved.
Attribute Value Rules in Template Mode
The template parser tries to JSON.parse attributes that look like:
- arrays:
[...] - objects:
{...} - quoted JSON strings:
"value"
That means:
- valid JSON objects/arrays become real objects/arrays in
progUi - invalid JSON stays a string
xu-storeis a special case because its handler parses with JSON5 later, so JSON5-style strings are still usable there
Examples:
<div xu-exp:xu-class='{"text-red-500": "@error", "text-green-500": "!@error"}'></div>
<div xu-on:click='[{"handler":"custom","props":{},"workflow":[]}]'></div>
<div xu-store="{'count': 0, 'label': 'Demo'}"></div>
Use valid JSON when you want the parser to produce an object directly.
Authoring Model
The easiest way to think about Xuda Slim is:
- HTML or
progUidescribes the DOM - datasource fields hold state
- expressions read fields using
@field_name - Xuda refreshes affected nodes when those fields change
This is why Slim feels HTML-first but still behaves like Xuda.
Directives
Core Directives
xu-bind- Two-way bind an input-like element to a field.
- Example:
xu-bind="user_name"
xu-render- Conditionally render or remove an element.
- Example:
xu-render="@is_logged_in"
xu-show- Toggle visibility without removing the element from the DOM.
- Example:
xu-show="@expanded"
xu-for- Repeat an element for each item in an array or object.
- Example:
xu-for="@students"
xu-for-key- Rename the iterator key field.
- Example:
xu-for-key="student_index"
xu-for-val- Rename the iterator value field.
- Example:
xu-for-val="student"
xu-text- Set text content.
xu-html- Set HTML content.
xu-content- General content setter used throughout the renderer.
xu-class- Apply conditional classes.
- Best used with
xu-exp:xu-class.
xu-ref- Register an element reference for other runtime logic.
xu-store- Add dynamic fields into the current datasource.
- This is the easiest way to create local-ish slim state.
xu-style- Append CSS scoped to the current element subtree.
xu-style-global- Append CSS globally.
xu-script- Run inline JavaScript after the element becomes visible.
xu-viewport- Turn on viewport-aware deferred rendering behavior.
Expressions
Any runtime attribute can be driven by an expression with:
<div xu-exp:xu-content="'Hello ' + @first_name"></div>
<div xu-exp:class="@is_active ? 'text-green-500' : 'text-gray-500'"></div>
Expression notes:
- field references use
@field_id - expressions are evaluated by the Xuda expression engine
- this is more powerful than string interpolation, but it also means state is datasource-driven
Event Attributes
There are two event styles in the current runtime.
xu-on:<event>- Full event workflow structure.
- Best for generated JSON/project data.
shorthand attributes such as
xu-click,xu-change,xu-init,xu-blur,xu-focus- These are normalized into
xu-on:*update workflows by the runtime. - Useful in hand-authored slim pages for simple field updates.
- These are normalized into
If you are hand-writing HTML, prefer simple shorthand when possible and reserve full xu-on:* payloads for advanced workflows.
Advanced Directives
xu-attrs- Inject multiple runtime attributes at once.
xu-cdn- Load runtime resources dynamically.
- Best supplied as object/array data, not a bare string.
xu-ui-plugin- Attach UI plugins to nodes.
- Best supplied as object data.
Special Tags
Xuda Slim also supports Xuda-specific nodes.
xu-widget- Widget runtime node.
xu-panel- Render another Xuda program as an embedded panel.
- The
programattribute is handled specially.
xu-teleport- Render children into another DOM container.
- The
toattribute is handled specially.
xu-single-view- Single-view runtime node.
xu-multi-view- Multi-view runtime node.
Local State in Slim
For lightweight pages, xu-store is the easiest way to bootstrap state without predeclaring every field in globals.
Example:
<template id="demo">
<div class="p-6 space-y-3" xu-store="{'message': 'Hello', 'visible': true}">
<p xu-exp:xu-content="@message"></p>
<p xu-show="@visible">I can be hidden</p>
</div>
</template>
For larger apps, define fields in:
project_data.globals.progFieldsprogram.progFields
Plugin and Widget Sandbox Usage
Slim is also used as a support runtime for plugin pages.
That mode looks different from template mode:
- load
xuda-runtime-slim.js - import the plugin runtime module
- use
@xuda.io/plugin-sandbox - let the sandbox build a config UI and call the selected plugin method
Example pattern:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://dev.xuda.ai/dist/runtime/js/xuda-runtime-slim.js"></script>
<script type="module">
import * as plugin from "../src/runtime.mjs";
import { methods } from "../src/index.mjs";
import { initializeWidgetPlugin } from "@xuda.io/plugin-sandbox";
initializeWidgetPlugin(document.body, plugin, methods);
</script>
</head>
<body></body>
</html>
This mode is still "using Xuda Slim", but it is not the same as authoring a declarative Xuda page. The page uses slim as a runtime foundation for plugin code.
Repo Examples
Useful local examples:
Small HTML-authored Slim demo:
Small non-template
project_datademo:ES-module slim package usage:
Global slim bundle with inline
project_data:Plugin sandbox on top of slim:
Troubleshooting
Nothing renders
Check:
- the slim bundle actually loaded
prog_idpoints to an existing program- your
project_data.programs[prog_id]exists - you mounted into a real DOM element, or intentionally relied on body fallback
Program not found
This usually means:
prog_idis missing- the template
iddoes not match the program you requested - the program was not present in
project_data.programs
My local ES module page returns a 404 while fetching the runtime script
This usually means the page is being served as a raw static file and the wrapper package import is resolving to the wrong relative node_modules location.
Use one of these instead:
- the live CDN bundle,
https://dev.xuda.ai/dist/runtime/js/xuda-runtime-slim.js - a package-managed import path resolved by your bundler, instead of a hand-written relative wrapper-package URL in a raw static page
My object-valued attribute is behaving like a string
In template mode:
- use valid JSON if you want automatic object parsing
- if you use JSON5-style syntax, the parser will usually keep the raw string
xu-storeis the main exception because it parses JSON5 internally
xu-show vs xu-render
Use:
xu-showwhen the node should remain mounted and just hidexu-renderwhen the node should be removed from the live DOM when false
I do not want <template>
That is supported.
Use:
- inline
project_data - imported
project_data - a plugin/runtime page on top of
xuda-runtime-slim.js
Recommended Starting Points
Choose one of these based on your goal:
"I want a plain HTML page with a few directives"
- Use
<template>plus the live CDN bundle.
- Use
"I want deterministic, tool-generated runtime input"
- Use
project_data.
- Use
"I want to preview a widget or UI plugin in isolation"
- Use the plugin sandbox pattern with the global slim bundle.
Summary
Xuda Slim is best understood as:
- Xuda runtime booted without the full remote project loader
- able to render from
project_data - optionally able to parse HTML templates into
progUi - good for embedded pages, plugin sandboxes, and local experiments
If you remember only one thing, remember this:
Xuda Slim does not require <template>. Templates are just one authoring mode on top of a project_data-driven runtime.