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

@bibliotype/annotation

v26.10.25-rc.1

Published

批注 / 高亮 / 书签 / 评论模型与存储 - bibliotype 标注包

Readme

@bibliotype/annotation

批注 / 高亮 / 书签 / 评论模型与容器:挂在 core 锚点之上,不改进正文。

四类语义共用一套结构,位置用「节点 id + 字符偏移」表达,重排、改字号、切直排都不会漂移。 纯数据与纯函数,无 DOM / 框架依赖。

安装

pnpm add @bibliotype/annotation @bibliotype/core

快速上手

import { createTextAnchor } from '@bibliotype/core';
import { AnnotationStore, createHighlight, createComment, resolveAnnotations } from '@bibliotype/annotation';

const anchor = createTextAnchor('p-1', 0, 4);
const store = new AnnotationStore();

store.add(createHighlight(anchor, { createdAt: '2026-10-20T00:00:00.000Z' }));
store.add(createComment(anchor, '底本作「悦」', { id: 'u1' }, { createdAt: '2026-10-20T00:00:00.000Z' }));

const { resolved, orphans } = resolveAnnotations(document.root, store.list());

API 概览

| 分组 | 导出 | | --- | --- | | 类型 | Annotation / AnnotationKind / AnnotationAuthor / CommentEntry / AnnotationSet / AnnotationFilter / AnnotationStorage、ANNOTATION_KINDS | | 构造 | createAnnotation / createHighlight / createBookmark / createNote / createComment、addComment / setCommentResolved、buildAnnotationId、DEFAULT_HIGHLIGHT_COLOR | | 容器 | AnnotationStore(add / addMany / update / remove / list / subscribe / hydrate / persist)、AnnotationPatch | | 解析 | resolveAnnotation / resolveAnnotations、groupAnnotationsByNode、countByKind | | 序列化 | serializeAnnotationSet / deserializeAnnotationSet、isAnnotation / validateAnnotations、ANNOTATION_SCHEMA_VERSION | | 加密 | createEncryptedAnnotationStorage(独立密钥,EncryptedAnnotationStorageOptions) |

约定

  • id 是内容哈希(kind + 锚点 + 时间 + 作者 + 正文),同一记录天然去重,不用随机数;
  • 时间通过 createdAt / clock 注入,测试可断言确定性输出;
  • 目标节点被删除时解析结果归入 orphans,文本变短时 clamped = true——不抛错;
  • 标注建议单独存储(AnnotationStorage),不要塞回 BookDocument。

注记独立加密(H5)

import { createEncryptedAnnotationStorage } from '@bibliotype/annotation';
import { createStringCipher, deriveKeyPbkdf2 } from '@bibliotype/core';

const notesKey = await deriveKeyPbkdf2({ password, salt: notesSalt });   // 与正文密钥分开
const storage = createEncryptedAnnotationStorage({
  read, write, remove,                       // 宿主提供三个读写函数
  cipher: createStringCipher(notesKey),
});

await store.persist(storage, 'lunyu');       // 落盘为密文信封
  • 只锁笔记与批注,正文可照常阅读(反之正文加密也可先不解锁注记);
  • 载荷是 JSON 信封,底层存储只见密文;历史明文 / 被改写的载荷抛 CryptoError(CORRUPT_PAYLOAD),口令错抛 WRONG_KEY,不静默降级为明文;
  • 密钥只驻内存,会话结束失效;脱敏导出(redactAnnotations)是另一件事,不要混用。

相关