@fibrae/semi-json-viewer-core

中文文档
0.7.0发布于 2026/11/14MITES Module零依赖构建来源已验证近 30 天下载 2349

Framework-free JSON viewer and editor core of Semi's JsonViewer

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Internals
  4. Related packages
  5. Development

@fibrae/semi-json-viewer-core

简体中文

The framework-agnostic editor core behind JsonViewer in Semi Design Next, derived from the JSON viewing and editing implementation in VS Code. Given a container element and JSON text, it provides rendering, editing, search and replace, completion and formatting. Most users reach it through the JsonViewer in each framework's UI package, and the JsonViewer foundation in @fibrae/semi-foundation depends on this package.

Installation

pnpm add @fibrae/semi-json-viewer-core

It has no peer or runtime dependencies (jsonc-parser is bundled into dist). The package has no styles; the JsonViewer component provides them.

Usage

import { JsonViewer } from '@fibrae/semi-json-viewer-core';

const viewer = new JsonViewer(container, '{"name": "semi"}', { readOnly: true });
viewer.layout();
// release when no longer needed
viewer.dispose();

Constructor: new JsonViewer(container: HTMLElement, value: string, options?: JsonViewerOptions).

OptionDescription
lineHeightLine height
autoWrapWhether to wrap lines automatically
readOnlyWhether the content is read-only
formatOptionsFormatting, with tabSize, insertSpaces and eol
completionOptionsCompletion, with staticCompletions
customRenderRuleArray of custom render rules { match, render }, where match is a string, a RegExp or (value, pathChain, tokenType) => boolean
prefixClsClass name prefix
ariaLabelThe name of the scroll region when read-only, and of the textbox when editable

Instance methods: layout(), resetMeasuredHeights(), getModel(), getSearchWidget(), format() and dispose(), plus the public property emitter. Each instance isolates its events and worker in its own namespace, so you must call dispose() when done.

Exported types: JsonViewerOptions, CompletionOptions, FormattingOptions, TokenRenderType and CustomRenderRule. Component docs are in website/content/plus/json-viewer.

Internals

src/tokens handles lexical analysis and highlighting of JSON text:

  • tokenize.ts recognizes delimiters, keywords, strings, numbers and comments, and records bracket nesting depth.
  • tokenizationJsonModelPart.ts holds the token state of the whole document and marks affected lines when content changes.
  • jsonModelToken.ts does incremental analysis, recomputing only what changed and finishing in the background during idle time through IdleDeadline.
  • offsetRange.ts provides merge, intersection, shift and containment operations on offset ranges, used to bound what needs recomputing.

The language service runs in a Web Worker. At build time a plugin in vite.semi.ts inlines the worker source, and at runtime it starts from a blob URL.

Depended on by @fibrae/semi-foundation. Depends on no other Semi package.

Development

pnpm build runs vp pack in this package directory and emits a single-entry ESM file with type declarations. For tests, lint and type checks, see CONTRIBUTING.md at the repository root.

版本与发布记录

@fibrae/semi-json-viewer-core 共发布 10 个版本,首次发布于 2026/10/28;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.7.0latest2026/11/14今天
0.6.02026/11/113 天前
0.5.02026/11/086 天前
0.4.02026/11/077 天前
0.3.12026/11/0410 天前
0.3.02026/11/0212 天前

关于 @fibrae/semi-json-viewer-core 的常见问题

@fibrae/semi-json-viewer-core 是什么?

Framework-free JSON viewer and editor core of Semi's JsonViewer

如何安装 @fibrae/semi-json-viewer-core?

在项目目录运行 npm install @fibrae/semi-json-viewer-core,或使用 pnpm add / yarn add / bun add。

@fibrae/semi-json-viewer-core 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/fibrae__semi-json-viewer-core 是否存在。

@fibrae/semi-json-viewer-core 支持 ESM 还是 CommonJS?

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

@fibrae/semi-json-viewer-core 可以商用吗?

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

@fibrae/semi-json-viewer-core 的下载量有多少?

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

@fibrae/semi-json-viewer-core 还在维护吗?

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