@expressive/dom

中文文档
0.12.1发布于 2026/11/12MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2501

MVC-native DOM renderer.

原始使用文档

@expressive/dom

MVC-native JSX rendering for the browser DOM.


@expressive/dom renders Expressive MVC without React or Preact. Function components are renderer-stateless: they project props and MVC snapshots into DOM, while Model.get() supplies dependency tracking. Owned state lives on classes - a Component field or <Component for>.

npm install @expressive/mvc @expressive/dom
{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "@expressive/dom"
  }
}
import { Model, Component } from '@expressive/mvc';
import { render } from '@expressive/dom';

class Counter extends Model {
  count = 0;
  increment() {
    this.count++;
  }
}

function Count() {
  const { count, increment } = Counter.get();
  return <button onClick={increment}>{count}</button>;
}

const unmount = render(
  <Component for={Counter}><Count /></Component>,
  document.getElementById('app')!
);

style recursively composes conditional class tokens and inline declarations. Strings become classes; objects merge left-to-right and render inline. Use className for a browser-specific class outside the composition. The class attribute spelling and CSS declaration strings are not supported.

<button
  className="external-widget"
  style={[styles.button, active && 'active', { width }]}
/>

style on a component automatically reaches its rendered host root, including through component, fragment, provider, portal, and collection boundaries. A fragment applies it to each host root. Forwarded style overrides the root's own, with the outermost caller winning. A component which reads its style prop while rendering owns placement, and nothing is forwarded. It receives a frozen object of the caller's inline declarations - spread, pluck or merge it freely; the caller's classes travel hidden with it. className applies to elements only.

A component may register immutable maps with style(Component, map). A _name entry is a rule, applied by a truthy _name attribute or a matching host tag and emitted as one class named after its source; nested inside a rule it opens a descendant scope. Component names never match - they do not survive minification. Bare keys are declarations, or macro calls where a macro owns the name, and those at the top of a map form a base rule applied to each of the component's host roots. Macros are methods of a Style subclass, whose use() returns the style resolving them; maps passed to use() hold rules for every component it styles, below each component's own; a function inside a map is a value, not a definition. $name keys apply a condition named by a $name field on the pack, or set a CSS variable any other $name field declares - with its value as the :root default, or a --name to use as is; a map may be a function receiving var() references to them. _ attributes never reach the DOM, and 0 or '' leaves a rule off. A map never reaches inside a child component; only the class chain inherits.

function Button({ active }: { active: boolean }) {
  return <button _active={active}>Save</button>;
}

style(Button, {
  padding: '8px',
  _active: { fontWeight: 700 }
});

Register styles before the component's first render. A key resolves at its topmost definition, the subclass first; a macro returning its own name falls to the next definition down, then through any default(value, key) method. Unhandled keys reach the host, which joins arrays and rejects functions and objects - units belong to a macro, never a guess.

Inline style always beats classes; among classes, a caller's rule beats the callee's, and a rule carried through more component style props wins - independent of render order. false, null, and undefined omit an entry; 0 remains a macro argument.

Component retains the React adapter's semantics: fields read by render() are dependencies, owned instances mount and clean up with the DOM range, and an externally activated instance can be placed directly without transferring ownership.

The first release includes keyed reconciliation, native events, refs, SVG, <Component for> providers, direct has / map collection rendering, portals, lazy components, error and suspense fallbacks, generated component appearance rules, and retention of committed content while pending() work suspends. It deliberately excludes standalone hooks, synthetic events, memo wrappers, SSR, hydration, and build-time style extraction.

See the DOM renderer guide for the API and constraints. This package currently targets browser DOM; native rendering and build-time expressive-jsx extraction are not included.

License

MIT

版本与发布记录

@expressive/dom 共发布 17 个版本,首次发布于 2026/09/28;过去 12 个月发布了 17 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.12.1latest2026/11/122 天前
0.12.02026/11/113 天前
0.11.02026/11/103 天前
0.10.12026/11/095 天前
0.10.02026/11/059 天前
0.9.02026/11/0311 天前

关于 @expressive/dom 的常见问题

@expressive/dom 是什么?

MVC-native DOM renderer.

如何安装 @expressive/dom?

在项目目录运行 npm install @expressive/dom,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@expressive/mvc(^0.94.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@expressive/dom 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@expressive/dom 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@expressive/dom 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@expressive/dom 可以商用吗?

@expressive/dom 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@expressive/dom 的下载量有多少?

根据 npm 官方下载统计,@expressive/dom 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,501 次,日均约 83 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@expressive/dom 还在维护吗?

最新版本 0.12.1 发布于 2026/11/12(2 天前);至今共发布 17 个版本,其中过去 12 个月发布了 17 个;首次发布于 2026/09/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。