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

@mojikumi/rehype

v0.2.1

Published

Rehype plugin for Mojikumi-ready Japanese HTML

Readme

Mojikumi

Web上の日本語を出版物に近い字組みへ整える、標準CSS優先のタイポグラフィ基盤です。

Mojikumiは独自の組版エンジンではありません。text-spacing-trimtext-autospaceline-breakhanging-punctuationなどの標準CSSを 優先し、ブラウザに足りない部分だけを小さなDOMフォールバックで補います。

Japanese typography compatibility layer for the Web

現在の実装範囲

v0.1の土台として次を実装しています。

  • CSS-onlyのwebbookeditorialminimalnativeプリセット
  • 書記素クラスタを壊さない文字分割と約物クラス分類
  • 重複する約物アキの保守的なペアルール
  • 和文とLatin文字・数字の境界検出
  • 約物だけをラップするDOMフォールバック
  • 段落先頭と折り返し行頭を区別するRangeベースの測定
  • Resize、Mutation、フォント読み込み後の再評価
  • refresh() / destroy()を備えた冪等な公開API
  • SSR時に本文を変更しないReactコンポーネントとHook
  • langとプリセットクラスを付与するrehypeプラグイン
  • Before / YakuHanJP / Native CSS / Mojikumiを比較できるPlayground

フォントプロファイルと縦書きの精密対応は次のフェーズです。

開発版を試す

npm install
npm run dev

表示されたローカルURLでPlaygroundを開けます。

npm test
npm run typecheck
npm run build

スクリプトタグで使う

ビルド設定を持たないサイトでは、<script>を1つ置くだけで使えます。CSSはバンドル に含まれているため、読み込むファイルは1つです。

<script
  src="https://cdn.mojikumi.jp/v1/mojikumi.min.js"
  data-target=".entry-content"
  data-style="article"
></script>

| 属性 | 既定値 | 内容 | | --- | --- | --- | | data-target | auto | 本文のセレクター。autoは既知の本文要素を順に探す | | data-style | article | article(記事向け)、book(書籍風)、headline(見出し重視) | | data-precision | auto | native / auto / full | | data-exclude | なし | 追加で除外するセレクター。カンマ区切り | | data-css | true | 同梱CSSを読み込むか | | data-auto | true | falseにするとMojikumi.start()を呼ぶまで何もしない |

data-styleにはプリセット名(webbookeditorialminimalnative)も そのまま書けます。読み込み後に追加された記事も自動で対象になります。

Mojikumi.start({ target: ".article", style: "book" });
Mojikumi.refresh();
Mojikumi.stop();

stop()は生成した要素とクラス、読み込んだCSSをすべて取り除きます。

CDNを使わない場合は、node_modules/mojikumi/dist/mojikumi.browser.jsを自分の サーバーへ置いても同じように動作します。

ビルド環境がある場合は、同じAPIをモジュールとして読み込めます。スクリプトタグ 経由ではないため自動では開始せず、start()を呼んだ時点から適用されます。CSSは 別途読み込んでください。

import "mojikumi/css";
import { start } from "mojikumi/browser";

start({ target: ".article", style: "article" });

CSSだけで使う

import "mojikumi/css";
<article lang="ja" class="mjk mjk-book">
  <p>『「引用」』とNext.jsを含む日本語。</p>
</article>

lang="ja"は禁則処理やword-break: auto-phraseの前提になるため、省略しないで ください。

DOMフォールバックを使う

import "mojikumi/css";
import { mojikumi } from "mojikumi";

const instance = mojikumi(".article", {
  preset: "book",
  precision: "auto"
});

instance.refresh();
instance.destroy();

precisionには次を指定できます。

  • native: 標準CSSだけを使用
  • auto: ネイティブ対応を検出し、不足機能だけ補完
  • full: 検証用に常にフォールバックを適用

codepre、フォーム部品、contenteditable、SVG、MathMLは既定で除外されます。 任意の範囲はdata-no-mojikumiで除外できます。

<span data-no-mojikumi>console.log("日本語")</span>

Reactで使う

import "mojikumi/css";
import { Mojikumi } from "@mojikumi/react";

export function Article({ children }) {
  return (
    <Mojikumi as="article" preset="book">
      {children}
    </Mojikumi>
  );
}

SSRでは通常のHTMLとクラスだけを出し、必要なDOM補完はマウント後に行います。 useMojikumi() Hookも利用できます。

Markdown / MDXで使う

import rehypeMojikumi from "@mojikumi/rehype";

export default {
  rehypePlugins: [[rehypeMojikumi, { preset: "editorial" }]]
};

既定ではarticlemainlang="ja"とプリセットクラスを付与します。レスポンシブ な行頭・行末はビルド時に確定しないため、rehype側では測定しません。

パッケージ

| パッケージ | 役割 | | --- | --- | | mojikumi | 通常利用向け統合API | | @mojikumi/core | DOM非依存の分類・解析 | | @mojikumi/css | CSS-onlyプリセット | | @mojikumi/dom | ブラウザ差を補うDOM層 | | @mojikumi/presets | バージョン管理されたプリセット | | @mojikumi/react | ReactコンポーネントとHook | | @mojikumi/rehype | Markdown・MDX向け静的マークアップ |

詳細は仕様互換性方針フォント検証表npm公開手順を参照してください。

設計原則

  1. 標準CSSを最優先する
  2. 本文の文字列、コピー結果、読み上げ内容を変えない
  3. 約物を一律半角化せず、位置と前後関係を扱う
  4. ネイティブ実装の進展に合わせてフォールバックを削除できるようにする
  5. 未知のフォントでは過度に詰めない

License

MIT