Refactored JSX elements from lowercase to PascalCase, including `<scene>` to `<Scene>`, `<text>` to `<Text>`, and others, to improve consistency and clarity in the codebase. Updated related documentation to reflect these changes, ensuring that the usage of JSX elements aligns with the new naming conventions. This update enhances the overall readability and usability of the JSX API.
3.9 KiB
Project module
The entry file is a standard Solid component module:
import { Scene } from "@diffusionstudio/jsx";
export default function Project() {
return (
<Scene key="intro" name="Intro" fill="black" width={1920} height={1080}>
{/* ... */}
</Scene>
);
}
The element import is optional at runtime — the compiler auto-imports PascalCase elements — but it makes the file typecheck (see Types and tooling).
The component receives no props; which document node each rendered root maps onto is declared in the JSX itself via key (see roots.md).
Module environment
Imports resolve by category:
- Host modules (marked external at compile time, resolved in-app so the project shares the editor's reactive runtime):
solid-js,solid-js/store,@diffusionstudio/jsx. These must be the editor's own instance and never come from anywhere else. - Userland packages — any other bare specifier (
three,gsap,d3-scale, …). These are not installed and not bundled: the CLI rewrites them to a CDN URL (defaulthttps://esm.sh/<specifier>, sothree/examples/jsm/loaders/GLTFLoader.jsbecomeshttps://esm.sh/three/examples/jsm/loaders/GLTFLoader.js) and the renderer imports them natively at runtime. Any npm package works without anode_modules, so this works in a packaged app too. The package's own transitive deps are resolved by the CDN. Libraries must be browser-compatible (no Node builtins). - Local and URL imports: relative/absolute paths (
./helper, local JSON) are resolved on disk and bundled as before; explicithttps://…imports pass through to the renderer untouched. - The module executes inside the editor process, unsandboxed. This is local tooling with a local trust model, the same trust as running the CLI itself. Only effects made through the JSX runtime are part of the document (and its undo history); anything else the module does is unsupported.
- Solid's control flow (
<For>,<Show>,<Index>,<Switch>) and primitives (createSignal,createMemo, …) are fully available during mount. See lifecycle.md for what happens after mount.
Import map (dapi.config.json)
A dapi.config.json in the working directory pins versions or redirects userland specifiers — for reproducible mounts, a self-hosted mirror, or a local vendored copy. Exact keys match a specifier; a trailing-slash key maps its subpaths (longest prefix wins):
{
"cdnBase": "https://esm.sh",
"imports": {
"three": "https://esm.sh/three@0.185.1",
"three/": "https://esm.sh/three@0.185.1/"
}
}
cdnBase overrides the default CDN for anything not in imports. The DAPI_CDN_BASE and DAPI_IMPORT_MAP (a JSON object) env vars override for one-offs. An unpinned specifier resolves to the CDN's latest.
Types and tooling
@diffusionstudio/jsx ships the composition elements and their prop types, the JSX namespace, Time, AssetRef, and the generate namespace. The PascalCase elements auto-import at compile time, so project files use them without import statements. For editor IntelliSense and typechecking in a project folder:
{
"compilerOptions": {
"jsx": "preserve",
"jsxImportSource": "@diffusionstudio/jsx"
}
}
The CLI does not typecheck; types are stripped at compile time. Run tsc --noEmit in the project folder for type safety. The compile-time auto-import is invisible to TypeScript, so for typechecking import the elements you use explicitly (import { Scene, Text } from "@diffusionstudio/jsx") — explicit imports and the auto-import behave identically at runtime.
Userland packages resolve from a CDN at runtime, so they need no runtime install, but the editor still wants their type declarations. For IntelliSense on a library, install it (or its @types/…) as a dev-only dependency (npm i -D three); it is used purely for typechecking and never bundled or shipped.