kanji-typesetting
v1.1.0
Published
A JavaScript library for Japanese/Chinese typography and typesetting
Downloads
232
Maintainers
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:
- Removed the old Gulp build system — everything now uses ES Modules and can be imported directly through modern bundlers.
- Supports server-side rendering (SSR).
- Reorganized the codebase following modern JavaScript standards.
- Redesigned the API for greater simplicity, consistency, and flexibility.
- 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-typesettingAlternatively, install directly from GitHub:
yarn add git+https://github.com/syhily/kanji
# or
npm install git+https://github.com/syhily/kanjiUsage
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:
Initialization —
initCond()Semantic element normalization —
renderElem(), including:renderRuby()— ruby annotationsrenderDecoLine()— text decorationrenderEm()— emphasized text
Hanging punctuation —
renderHanging()Punctuation compression (jiya) —
renderJiya()Han–Western spacing —
renderHWS()Basic punctuation correction —
correctBasicBD()(for browsers without native support)Ligature substitution —
substCombLigaWithPUA()Character accuracy correction —
substInaccurateChar()
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.
