npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lxc2006/mindmap-core

v0.2.1

Published

字符网格思维导图布局引擎 —— org-mindmap (Emacs Lisp) 的 TypeScript 移植,与原版渲染逐字符对拍

Readme

@lxc2006/mindmap-core

npm version npm downloads License: MIT

字符网格思维导图布局引擎(纯 TypeScript,零框架依赖,零运行时依赖)。 布局算法移植自 Emacs Lisp 项目 org-mindmap,并以 golden 测试与其渲染输出 逐字符对拍保证一致。

Vue 组件封装(平移缩放 / 节点拖拽 / 折叠选中)见 npm 包 @lxc2006/mindmap-vue。

安装

npm install @lxc2006/mindmap-core

能力

  • buildViewModel(input) —— { data, options?, collapsed?, theme? } → 视图模型:每个节点的行列坐标、多行显示文本、逐行连接符段 (box-drawing 字符)、子树颜色、总尺寸。纯函数。
  • viewModelToText(vm) —— 视图模型 → 字符网格文本(调试 / 对拍)。
  • parseOutline(text) —— 缩进大纲 → 树数据(left: / right: 前缀定向)。
  • toOutline(tree, options?) —— 树数据 → 缩进大纲(逆函数;文本以 left:/right: 开头或空文本节点除外)。
  • walkTree(node, fn) —— 深度优先先序遍历数据树。
  • moveNode(tree, drag, target, position) —— 树结构编辑(拖拽语义: before / after / inside,不可变更新 + 环检测 + side 规范化)。
  • 文本度量:CJK 宽字符 = 2 显示列;软换行按 Emacs string-fill 的断点模型 (ASCII 词不拆、CJK 逐字断行、简化禁则)。

布局选项(对齐 org-mindmap 块属性)

| 选项 | 默认 | 说明 | | ---------------- | ------------ | ------------------------------------- | | layout | 'centered' | 父节点垂直居中于后代 / 'top' 置顶 | | compacted | false | 子树上浮填充空隙(永不重排兄弟顺序) | | spacing | 1 | 碰撞检测边距(列) | | maxWidth | null | 软换行目标宽度(显示列),null 不换行 | | wrapLeaves | 3 | 叶节点换行倍数(false = 叶不换行) | | paintDepth | 0 | 从该深度起子树着色(null 关闭) | | rootDelimiters | ['«','»'] | 根节点定界符 |

用法

import { buildViewModel, viewModelToText, parseOutline } from '@lxc2006/mindmap-core'

const vm = buildViewModel({
  data: {
    text: 'Root',
    children: [{ text: '左侧', side: 'left', children: [{ text: '子节点' }] }, { text: '右侧' }],
  },
  options: { compacted: true },
})
console.log(viewModelToText(vm))
//   子节点 ─┬ 左侧 ─┬ « Root » ── 右侧

数据格式:

interface MindmapNodeData {
  text: string
  children?: MindmapNodeData[]
  side?: 'left' | 'right' // 仅根的直接子级有效,缺省 right
  id?: string // 稳定标识,缺省由使用方管理
}

分层架构(对照 org-mindmap)

MindmapNodeData
 → normalize.ts    id/side/depth/parent,折叠子树摘除        [数据准备]
 → text.ts         显示宽度(CJK=2)、软换行、pad、根定界符      [node box]
 → layout.ts       后序递归分配 row/col 网格坐标              [build-tree-layout]
 → occupancy.ts    子树占用碰撞检测(compacted 模式)          [occupancy]
 → connectors.ts   box-drawing 真值表与连线段                 [draw-subtree]
 → viewModel.ts    节点矩形 + 逐行连接段 + 颜色 + 尺寸         [render-tree]
 → treeOps.ts      moveNode / 环检测                          [transformations]

测试

tests/golden.spec.ts 把 org-mindmap tests/test-rendering.org 的全部用例

  • CJK 补充用例作为金标准:fixtures 由 scripts/gen-golden.el 从原版 Emacs 实现生成,本引擎通过 viewModelToText() 与其逐字符比对。
vp install
vp test    # 57 个用例
vp check
vp pack    # 构建 dist(ESM + CJS + dts)

重新生成 fixtures(需 Emacs 与本地 org-mindmap 仓库):

emacs --batch -Q -l scripts/gen-golden.el