Skip to main content

API Overview

Public surface on window.Dim after loading the CDN IIFE (dim.global.js or dim.wasm.global.js). For interactive demos, see Storybook.

const { html, css, define, useState, useStore, keyed, t } = Dim;

In components, prefer hooks and html/css from the second argument injected by define.


Renderer​

ExportRole
htmlTagged template for markup (Dim’s own renderer)
css / unsafeCSSStyle results for useStyle
keyedStable list keys (Dim directive)
unsafeHTMLTrusted HTML only
renderChildrenCompose children; strings render as text
const { html, css, keyed, unsafeHTML, renderChildren } = Dim;

define​

const { define } = Dim;

define({
tag: "my-widget",
component: MyWidget,
inputs: null, // optional t.record schema — see Contracts
});

Registers a DimElement custom element, stamps component.tag = tag, and injects shared deps (html, hooks, keyed, …) as the second argument of component(props, deps).


Hooks​

HookRole
useStateLocal state [value, setValue]
useEffectSide effects + cleanup
useMemoMemoized value
useRefMutable ref / DOM handle
useStyleShadow-scoped CSS
useScopeRegister child components in scope
useLazyScopeExperimental — loads via new Function; trusted sources only
// Inside component(props, { useState, useEffect, useStyle, useScope, html, css })
const [count, setCount] = useState(0);

useEffect(() => {
const id = setInterval(() => setCount((c) => c + 1), 1000);
return () => clearInterval(id);
}, []);

useStyle(css`.x { color: blue; }`);

useScope({ "child-tag": ChildFn });
// or after define() stamped .tag:
useScope({ ChildFn });

useStore​

Persists nested useState leaves to IndexedDB and syncs across components/tabs. Each leaf is a 5-tuple:

const {
notes: [notes, setNotes, isLoading, setIsLoading, isSaving],
} = useStore(
{ notes: useState([]) },
{ encryptionKey: "optional-secret" }, // omit for plaintext
);

// Shorthand: useStore({ notes: useState([]) }, "password");
IndexNameRole
0valueCurrent state
1setterUpdate + persist
2isLoadingtrue until initial IndexedDB read
3setIsLoadingManaged by the async manager
4isSavingtrue while a debounced persist is in flight

Encryption is opt-in. See Encrypted Storage.


File system & transitions​

ExportRole
useFSFile System Access / OPFS with optional encryption
useViewTransitionManual view transitions
viewTransitionStylesShared transition CSS helpers

Declarative slides also work via a transitionId attribute/prop on the host. See View Transitions.


Contracts​

const { define, t } = Dim;

define({
tag: "my-input",
component: Comp,
inputs: t.record({ label: t.string }),
});

Also on Dim: contract, fold, validateValue, getValidatorEngine. Rejected props render nothing and log an error. Browser verification: Contracts & DimVerify.


React interop (npm exception)​

CDN apps do not need this. Mixed React + Dim trees use the package subpath:

import { useDimStore } from "@positive-intentions/dim/react";

See useDimStore.


Managers (advanced)​

CryptoManager, StorageManager, AsyncronousStateManager, and debouncedDispatcher are on Dim for custom integrations. Prefer useStore in app code.