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 🙏

© 2025 – Pkg Stats / Ryan Hefner

kanji-typesetting

v1.1.0

Published

A JavaScript library for Japanese/Chinese typography and typesetting

Downloads

232

Readme

Kanji Typesetting (formerly Han-CSS-Q)

Kanji Typesetting (npm: kanji-typesetting) is a modernized reimplementation of Han-CSS, a typesetting framework for Chinese and other Han-script web pages. It integrates semantic style normalization, text design, and advanced typesetting features into a unified CSS + JavaScript framework.

Kanji Typesetting provides a beautiful, standardized environment for Han character typography — faithful to traditional reading habits yet optimized for digital screens — effectively solving the long-standing layout challenges in Han-script web design.

The original Han-CSS project, however, has not been actively maintained for years. Its build system depends on an outdated version of Gulp, the code does not follow modern JavaScript conventions, and it lacks features such as server-side rendering (SSR) support.

Han-CSS-Q was created as an effort to modernize Han-CSS. I (syhily) have now forked Han-CSS-Q again, continuing its modernization under the new name Kanji Typesetting, distributed via npm as kanji-typesetting. This fork inherits all improvements from Han-CSS-Q while further enhancing usability, modularity, and compatibility with modern front-end ecosystems.


Differences from the Original Han-CSS

Compared with the original Han-CSS, Kanji Typesetting introduces several major updates:

  1. Removed the old Gulp build system — everything now uses ES Modules and can be imported directly through modern bundlers.
  2. Supports server-side rendering (SSR).
  3. Reorganized the codebase following modern JavaScript standards.
  4. Redesigned the API for greater simplicity, consistency, and flexibility.
  5. Precompiled CSS distribution — no need for Sass loaders; simply import the built stylesheet.

Kanji Typesetting is still under active development. Most features are functional, but due to the scope of the refactor and incomplete testing, results may differ slightly from the original Han-CSS. You can see it in production on sharzy.in, which fully adopts Han-CSS-Q.


Installation

Install Kanji Typesetting from npm:

yarn add kanji-typesetting
# or
npm install kanji-typesetting

Alternatively, install directly from GitHub:

yarn add git+https://github.com/syhily/kanji
# or
npm install git+https://github.com/syhily/kanji

Usage

Kanji Typesetting consists of two parts:

  • CSS styles for visual and typographic rendering
  • JavaScript runtime for semantic and contextual processing

1. Import the CSS

Since Kanji Typesetting ships with precompiled CSS, you can import it directly from the package:

import 'kanji-typesetting/style'

or in a CSS file:

@import 'kanji-typesetting/style';

This works with most modern bundlers and frameworks, including Vite, Next.js, Nuxt, and Webpack.

💡 Tip: The CSS bundle automatically includes the default font and layout settings. If you need to override font paths or variables, you can do so via standard CSS overrides after import.

Example:

@import 'kanji-typesetting/style';

:root {
  --han-line-height: 1.6;
  --han-article-line-height: 1.6;
}

2. Initialize with JavaScript

Import the JavaScript API in your entry script or component:

import Han from 'kanji-typesetting'
import 'kanji-typesetting/style'

Create a Han instance and render:

const han = new Han(
  document.querySelector('article'),
  document.documentElement,
)

han.render()

The default rendering pipeline runs the following steps:

const defaultRoutine = [
  'initCond',
  'renderElem',
  'renderJiya',
  'renderHanging',
  'correctBiaodian',
  'renderHWS',
]

You can customize it:

han.setRoutine(['initCond', 'renderElem', 'renderJiya', 'renderHWS']).render()

Rendering Steps

Kanji Typesetting provides the following processing steps:

  • InitializationinitCond()

  • Semantic element normalizationrenderElem(), including:

    • renderRuby() — ruby annotations
    • renderDecoLine() — text decoration
    • renderEm() — emphasized text
  • Hanging punctuationrenderHanging()

  • Punctuation compression (jiya)renderJiya()

  • Han–Western spacingrenderHWS()

  • Basic punctuation correctioncorrectBasicBD() (for browsers without native support)

  • Ligature substitutionsubstCombLigaWithPUA()

  • Character accuracy correctionsubstInaccurateChar()

For detailed explanations, see the Han-CSS documentation.


Style Corrections

Kanji Typesetting provides typographic corrections for standard HTML elements, ensuring they conform to professional Han typesetting conventions. See the original documentation for details.

It also defines refined font stacks for consistent rendering across platforms. See text design documentation for more details.


Summary

Kanji Typesetting (npm: kanji-typesetting) is a modern, production-ready reimplementation of Han-CSS, continuing from Han-CSS-Q with:

  • ES Module–based architecture
  • Server-side rendering support
  • Precompiled CSS (no Sass required)
  • Modern JavaScript API
  • Simplified configuration
  • npm distribution

Kanji Typesetting aims to deliver a clean, modular, and production-ready framework for high-quality Han character web typography.