Skip to content

HTML API

glyphcss/elements is a side-effect import that registers a set of <glyph-*> custom elements with customElements. After the import runs, you can use them in plain HTML — no React, no Vue, no build step required.

Terminal window
pnpm add glyphcss
<script type="module" src="https://esm.sh/glyphcss/elements"></script>

Or in a bundled app:

import "glyphcss/elements"; // side-effect — registers customElements

Re-imports are idempotent (the module checks customElements.get before defining). In non-DOM environments (SSR, Node) the module silently no-ops.

Camera wraps scene. Attribute names are kebab-case (rot-x, rot-y, feature-edges, auto-size). Boolean attributes follow standard HTML convention — present means true.

<glyph-perspective-camera rot-x="65" rot-y="45" zoom="50" distance="3">
<glyph-scene mode="solid" cols="100" rows="30">
<glyph-orbit-controls drag wheel></glyph-orbit-controls>
<glyph-mesh geometry="cube"></glyph-mesh>
<glyph-hotspot hotspot-id="top" at="0,0.5,0" size="3,2"></glyph-hotspot>
</glyph-scene>
</glyph-perspective-camera>

Root container. Owns the <pre> rasterisation output and the lighting state.

AttributeTypeNotes
mode"wireframe" | "solid" | "voxel"Default solid
colsnumberGrid width in character columns
rowsnumberGrid height in character rows
cell-aspectnumberHeight ÷ width of the cell (default 2.0)
glyph-palettestringNamed palette: default, ascii, lines, blocks, stars, arrows, math, binary, hex
use-colorsboolEmit color spans in the output
directional-intensitynumberKey-light intensity
ambient-intensitynumberAmbient fill intensity
auto-sizeflagAuto-fit cols/rows to the host’s box via ResizeObserver
shadowflagEnable shadow-map pass. Must be present for any shadows to render
shadow-colorstringShadow tint hex color (default "#000000")
shadow-opacitynumberShadow darkness 0..1 (default 0.25)
shadow-liftnumberDepth bias — prevents self-shadow acne (default 0.05)
shadow-max-extendnumberHalf-extent of the light-space projection volume (default 2000)

<glyph-perspective-camera> / <glyph-orthographic-camera> / <glyph-camera>

Section titled “<glyph-perspective-camera> / <glyph-orthographic-camera> / <glyph-camera>”

<glyph-camera> is the ergonomic default — an alias for <glyph-orthographic-camera>. All three accept the same orientation attributes; perspective additionally accepts distance and stretch.

AttributeNotes
rot-xPitch in degrees
rot-yYaw in degrees
zoomPixels per world unit
distancePerspective only
stretchPerspective only

Polygon registration. Picks one source in descending precedence: geometry < src < explicit polygons (only available via JS property, not attribute).

AttributeNotes
srcURL of OBJ / GLB / glTF / VOX mesh
geometryBuilt-in name from @glyphcss/core registry (cube, dodecahedron, …)
sizeUniform size for geometry
colorFill color for geometry
positionx,y,z translation
scales or sx,sy,sz
rotationrx,ry,rz XYZ Euler degrees
normalizeflag — auto-fit imported mesh to a unit bbox
cast-shadowflag — this mesh casts shadows onto receive-shadow surfaces
receive-shadowflag — this mesh displays shadows from cast-shadow meshes. Present on both = self-shadow

3D-anchored DOM hotspot. Child nodes are positioned at the projected screen cell every render.

AttributeNotes
hotspot-idIdentifier for handle lookup
atx,y,z anchor in world space
sizew,h in cells

<glyph-orbit-controls> / <glyph-map-controls>

Section titled “<glyph-orbit-controls> / <glyph-map-controls>”

Camera controls. Orbit rotates around the target; map pans across the target plane.

AttributeNotes
dragflag — enable drag
wheelflag — enable wheel zoom
invertflag or number — invert axis multiplier
animate-speedOrbit-only: auto-rotation speed
animate-axisOrbit-only: x | y | z

Custom elements register asynchronously. If you need to call imperative methods on the scene from JavaScript, listen for glyph-scene-ready on the <glyph-scene> element:

const sceneEl = document.querySelector("glyph-scene")!;
sceneEl.addEventListener("glyph-scene-ready", (ev) => {
const scene = (ev.target as any).getScene();
scene.addHotspot({ id: "runtime", at: [0, 0, 1] }, () => alert("clicked"));
});
<!DOCTYPE html>
<html>
<head>
<script type="module" src="https://esm.sh/glyphcss/elements"></script>
<style>
glyph-scene { display: block; width: 600px; height: 400px; }
</style>
</head>
<body>
<glyph-perspective-camera rot-x="65" rot-y="45" zoom="50" distance="3">
<glyph-scene
mode="solid"
cols="120"
rows="36"
directional-intensity="1"
ambient-intensity="0.4"
>
<glyph-orbit-controls drag wheel></glyph-orbit-controls>
<glyph-mesh geometry="dodecahedron" color="#4488ff"></glyph-mesh>
<glyph-hotspot hotspot-id="top" at="0,0.5,0" size="3,2">
<span class="badge">top</span>
</glyph-hotspot>
</glyph-scene>
</glyph-perspective-camera>
</body>
</html>