{"_id":"18s","_rev":"6-54ad7a5d027fcec30e5800ebe70c3cc0","name":"18s","dist-tags":{"latest":"0.2.24"},"versions":{"0.1.4":{"name":"18s","version":"0.1.4","keywords":[],"author":{"name":"i18n.site@gmail.com"},"license":"Apache-2.0","_id":"18s@0.1.4","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://atomgit.com/i18n/site/tree/dev","dist":{"shasum":"e9579d81cff7d4b26f693e190834b4fdea1bddaa","tarball":"https://registry.npmjs.org/18s/-/18s-0.1.4.tgz","fileCount":10,"integrity":"sha512-9eBNL5olBhq06SNpg0CoBtqSKeZyPog9YrkvJUn6YyY+Ns3obiSEkAeTY5HPUdTsCSbNWkM9N+DJPvzwiJ8Aig==","signatures":[{"sig":"MEUCIQD62BEBWNFWSGKuKayzkWJoWbZoDycMQ3mSQBQtVqJqUAIgZMzdHrfViOZnmmWUBzfV3cS7DNkaci+ZSRLQ5203HnE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":678717},"type":"module","exports":{"./*":"./*"},"gitHead":"e2c5baba81b091ada83c465d1e464e016c8b62d8","_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://atomgit.com/i18n/site.git","type":"git"},"_npmVersion":"10.7.0","description":"i18n.site self","directories":{},"_nodeVersion":"22.1.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/18s_0.1.4_1717327883731_0.10564618118433189","host":"s3://npm-registry-packages"}},"0.1.5":{"name":"18s","version":"0.1.5","keywords":[],"author":{"name":"i18n.site@gmail.com"},"license":"Apache-2.0","_id":"18s@0.1.5","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://atomgit.com/i18n/site/tree/dev","dist":{"shasum":"d5bf8c4cc3a05363f89c028df63abf304acec763","tarball":"https://registry.npmjs.org/18s/-/18s-0.1.5.tgz","fileCount":10,"integrity":"sha512-ziTteqEOvddJaplFTkmZ3omxbiCYJhTxpS9rxK78Hl0CuurMsI3BBzAyoaepk2y++3L/ybKnmSBylNglJ725zw==","signatures":[{"sig":"MEUCIQDGLcCTjqA37kFdDMrhJS+sEW7LvzF7IE7gJG+h+Kmc8QIgQBQkxc8PcEil5J5/5HmM5jojqMSXZELEYns7cye+QmU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":678717},"type":"module","exports":{"./*":"./*"},"gitHead":"e2c5baba81b091ada83c465d1e464e016c8b62d8","_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://atomgit.com/i18n/site.git","type":"git"},"_npmVersion":"10.7.0","description":"i18n.site self","directories":{},"_nodeVersion":"22.1.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/18s_0.1.5_1717328286596_0.17426013435125953","host":"s3://npm-registry-packages"}},"0.2.9":{"name":"18s","version":"0.2.9","keywords":["font","subset","woff2","webc","cjk"],"license":"MIT","_id":"18s@0.2.9","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/font#readme","bugs":{"url":"https://github.com/webc-site/font/issues"},"dist":{"shasum":"6b415c0d9760297862d1945b6673272cdc0900fb","tarball":"https://registry.npmjs.org/18s/-/18s-0.2.9.tgz","fileCount":310,"integrity":"sha512-FVSbhHYzml3dFQiBKxDrTvasrZSZ9wggp7vneEJuV42rattOvuNxuB8JYJ1nR6q50tJJsZsfWBB0pKMtmm5Dtw==","signatures":[{"sig":"MEUCIQCdzWV9nsIxl97iflz2d1CrmwHRW3bP1L0Qco5dLmZoqAIgWIRjhVTHkDK8lnLGpx5cgXPzqNe3C2Xbva96Uq5XlP4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22428675},"type":"module","gitHead":"4b7a2b3236707b57da9cedd89ec42a5af6cca402","_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/font.git","type":"git"},"_npmVersion":"11.13.0","description":"High-performance subsetted font packages for WebC components / 面向 WebC 组件库的高性能分片字体包","directories":{},"_nodeVersion":"25.4.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"@3-/mdt":"^0.1.5","@3-/write":"^0.0.2"},"_npmOperationalInternal":{"tmp":"tmp/18s_0.2.9_1779553856326_0.6732876842406936","host":"s3://npm-registry-packages-npm-production"}},"0.2.15":{"name":"18s","version":"0.2.15","keywords":["font","subset","woff2","webc","cjk"],"license":"MIT","_id":"18s@0.2.15","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/font#readme","bugs":{"url":"https://github.com/webc-site/font/issues"},"dist":{"shasum":"62b5a30846192c3215adf3ebb74cb6a63cd8155c","tarball":"https://registry.npmjs.org/18s/-/18s-0.2.15.tgz","fileCount":310,"integrity":"sha512-7mrTF36stEoyHdHkjEUgLnKH35wBk+kbMYx94BV4MNWP8Zo95ihsup1L3hRz9I8sf3TuCEU8ht0cHlWOS1/trQ==","signatures":[{"sig":"MEUCICiFqolSPwSo8zexBy3JFov7jMhuemQxlYpUHlsDpU3gAiEAt8UIHCLOFiH4+UpIfgeSpK9KmSr1V98v0SIRdLsxej0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22427971},"type":"module","gitHead":"fed855cf1fdb41c92add00b7b22abbcfe9090782","_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/font.git","type":"git"},"_npmVersion":"11.11.0","description":"Chinese font subsetting packages for WebC (Web Components library for AI-assisted development) / WebC（面向 AI 辅助开发的 Web Components 组件库）中文字体分片包","directories":{},"_nodeVersion":"24.14.1","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"@3-/mdt":"^0.1.5","@3-/write":"^0.0.2"},"_npmOperationalInternal":{"tmp":"tmp/18s_0.2.15_1779586260326_0.10891807260392317","host":"s3://npm-registry-packages-npm-production"}},"0.2.16":{"name":"18s","version":"0.2.16","keywords":["font","subset","woff2","webc","cjk"],"license":"MIT","_id":"18s@0.2.16","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/font#readme","bugs":{"url":"https://github.com/webc-site/font/issues"},"dist":{"shasum":"65827e07d17407002bbd678e59c37961b59f9048","tarball":"https://registry.npmjs.org/18s/-/18s-0.2.16.tgz","fileCount":310,"integrity":"sha512-PYuOhm/fMxmIGCgrHFrRwW6JmYjPPO09nt3+FRUidy0OwoUHTyEw34ed8uGHyQAd7N7btbPucqLYJPb8N+1T5A==","signatures":[{"sig":"MEYCIQCirblfhx3o7BN+QQzbhunRUnXoTj4LkslS4xs9zF+L0AIhAN+GyoES3qdOKBFPAJKsNYC/knNluBXVcbEReEHtmY0a","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22427971},"type":"module","gitHead":"b97225ab0b229f07b8f4c05b0f59b9f38c95cb96","_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/font.git","type":"git"},"_npmVersion":"11.11.0","description":"Chinese font subsetting packages for WebC (Web Components library for AI-assisted development) / WebC（面向 AI 辅助开发的 Web Components 组件库）中文字体分片包","directories":{},"_nodeVersion":"24.14.1","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"@3-/mdt":"^0.1.5","@3-/write":"^0.0.2"},"_npmOperationalInternal":{"tmp":"tmp/18s_0.2.16_1779587289390_0.6362942873612896","host":"s3://npm-registry-packages-npm-production"}},"0.2.24":{"name":"18s","version":"0.2.24","license":"MIT","type":"module","description":"Chinese font subsetting packages for WebC (Web Components library for AI-assisted development) / WebC（面向 AI 辅助开发的 Web Components 组件库）中文字体分片包","keywords":["font","subset","woff2","webc","cjk"],"homepage":"https://github.com/webc-site/font#readme","repository":{"type":"git","url":"git+https://github.com/webc-site/font.git"},"dependencies":{},"devDependencies":{"@3-/write":"^0.0.2","@3-/mdt":"^0.1.5"},"gitHead":"70e943d39fc0090f3cbadbb2f68e40f811b4dca5","_id":"18s@0.2.24","bugs":{"url":"https://github.com/webc-site/font/issues"},"_nodeVersion":"26.2.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-keTPYuhWS67z3SqHTkShGFKeIZPEZ2EhuJnMLEF2YQA7H9/0HRlZDSVfy9fjdiSVMDtnBwjJCxSEZq4DBb07dA==","shasum":"02138c2040341f6be8e4cfac4fa8f092be6d040c","tarball":"https://registry.npmjs.org/18s/-/18s-0.2.24.tgz","fileCount":312,"unpackedSize":22822518,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCvxbtex4QDWIEhO1LwIqiDX7NrFtujiVBTAFY9EdvCBAIhAPNY24elyVru5Z/jXrtJj89ReBNjfbPHSKmjQnMVUmHi"}]},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"directories":{},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/18s_0.2.24_1780800194841_0.0952949281472224"},"_hasShrinkwrap":false}},"time":{"created":"2024-06-02T11:31:23.639Z","modified":"2026-06-07T02:43:15.337Z","0.1.4":"2024-06-02T11:31:23.947Z","0.1.5":"2024-06-02T11:38:06.803Z","0.2.9":"2026-05-23T16:30:57.015Z","0.2.15":"2026-05-24T01:31:00.732Z","0.2.16":"2026-05-24T01:48:09.835Z","0.2.24":"2026-06-07T02:43:15.239Z"},"bugs":{"url":"https://github.com/webc-site/font/issues"},"license":"MIT","homepage":"https://github.com/webc-site/font#readme","keywords":["font","subset","woff2","webc","cjk"],"repository":{"type":"git","url":"git+https://github.com/webc-site/font.git"},"description":"Chinese font subsetting packages for WebC (Web Components library for AI-assisted development) / WebC（面向 AI 辅助开发的 Web Components 组件库）中文字体分片包","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"readme":"[English](#en) | [中文](#zh)\n\n---\n\n<a id=\"en\"></a>\n# 18s : Chinese font subsetting packages for the WebC component library\n\nWebC is a Web Components library designed for AI-assisted development. This package provides Chinese font subsetting support for WebC.\n\nOnline Preview: [https://webc-zh.pages.dev](https://webc-zh.pages.dev)\n\n* [Features](#features)\n* [Directory Structure](#directory-structure)\n* [Design & Process](#design--process)\n* [Tech Stack](#tech-stack)\n* [Usage](#usage)\n* [History & Background](#history--background)\n\n## Features\n\n- **Chinese Font Subsetting**: Splits Chinese fonts (CJK) into WOFF2 chunks (128KB) to reduce loading times.\n- **Cache Busting**: Uses MD5 hashes of chunk content as filenames to prevent collision and improve caching.\n- **Variable & Math Font Support**: Includes Source Han Sans SC (`t`) and JetBrains Mono (`c`) variable font subsets, and supports publishing the math font `m` (Latin Modern Math) without subsetting (automatically compressed from `otf/latinmodern-math.otf`).\n- **CSS**: Outputs minimized CSS containing `@font-face` rules mapping character ranges to chunks or mapping weights/styles to math font.\n\n## Directory Structure\n\n```\n.\n├── gen/                 # Generation workspace containing raw TTF/OTF files and processing scripts\n│   ├── lib/             # Processing modules (font splitting, hash resolution, CSS minification)\n│   ├── ttf/             # Source TrueType Font (.ttf) files and configurations\n│   ├── gen.js           # Subsetting execution script\n│   ├── m.js             # Math font processing script (no subsetting)\n│   └── gen.sh           # Setup and FFI dependencies download script\n├── woff2/               # Output distribution directory containing published assets\n│   ├── *.woff2          # Content-addressed subset/full font chunks\n│   ├── t.css            # Source Han Sans SC Font-face mappings\n│   ├── c.css            # JetBrains Mono Font-face mappings\n│   ├── m.css            # Math font m mappings\n│   └── _.css            # Merged Font-face mappings for all fonts (including t, c, and math font m)\n├── readme/              # Project documentation\n│   ├── en.md            # English README\n│   └── zh.md            # Chinese README\n├── package.json         # Project configuration metadata\n└── README.mdt           # Compilation template for root README\n```\n\n## Design & Process\n\nThe compiler processes fonts defined in `gen/ttf/gen.yml`, splitting them and preparing CSS and font chunks.\n\n```mermaid\ngraph TD\n    A[Font files: SourceHanSansSC / JetBrainsMono] --> B[fontSplit / cn-font-split]\n    B --> C[Generate WOFF2 subsets & result.css]\n    C --> D[Rename WOFF2 subsets to MD5 Base64url hashes]\n    D --> E[Rewrite CSS font-family & URLs]\n    E --> F[Output woff2/t.css, woff2/c.css & woff2/_.css]\n```\n\n1. **Splitting**: Fonts are subsetted using `cn-font-split` into WOFF2 chunks.\n2. **Hashing**: Each chunk is renamed to its MD5 base64url hash (starting at length 4, expanding on conflict).\n3. **Rewriting**: CSS is parsed to replace font-family names with aliases (`t` and `c`), omit local paths, and update chunk URLs.\n4. **Publishing**: CSS and WOFF2 chunks are output to `woff2/` for npm publication.\n\n## Tech Stack\n\n- **Runtime**: Bun\n- **Font Splitter**: `cn-font-split`\n- **CSS Minifier**: `lightningcss`\n- **Hash Function**: `@3-/base64url`\n\n## Usage\n\n### Installation\n\n```bash\nnpm install 18s\n```\n\n### Importing Fonts\n\nImport the required CSS file in web components or application entries:\n\n```javascript\n// Import all fonts at once (merged CSS, including t, c, and math font m)\nimport '18s/_.css';\n\n// Or import individual fonts as needed\n// Import Source Han Sans SC\nimport '18s/t.css';\n\n// Import JetBrains Mono\nimport '18s/c.css';\n\n// Import math font m\nimport '18s/m.css';\n```\n\nApply in CSS stylesheets:\n\n```css\nbody {\n  font-family: t, sans-serif;\n}\n\ncode {\n  font-family: c, t, monospace;\n}\n\nmath {\n  font-family: m, t, sans-serif;\n}\n```\n\n### Publishing Math Font\n\n1. The source font file is located at `otf/latinmodern-math.otf` in the project root.\n2. Run `./gen.sh` in the `gen/` directory. The build system will compress this font file into WOFF2 format under `woff2/` (using content-addressed hashing) and generate `woff2/m.css` mapped to font family `m`.\n\n## History & Background\n\nCJK font files are large (10MB to 50MB) as they contain tens of thousands of glyphs. Loading them in browsers causes rendering latency. Previously, developers embedded static character subsets or relied on system defaults, limiting design options.\n\nSource Han Sans, introduced by Adobe and Google in 2014, solved CJK typeface quality issues but still had large file sizes. Font splitters like `cn-font-split` split these typefaces into chunks based on character frequency. Browsers fetch chunks containing characters present on the page, improving performance.\n\nJetBrains Mono, released in 2020, is designed for readability. Project `18s` bundles these typefaces as variable fonts to provide Chinese font support for WebC.\n\n### Latin Modern Math\n\n**Latin Modern Math** is an OpenType mathematical font designed to serve as a modern companion to the Latin Modern family of typefaces, completing the modernization of Donald Knuth's classic Computer Modern typeface. It includes a comprehensive set of mathematical and technical characters and supports advanced layout features required for complex mathematical typesetting (using the OpenType `MATH` table). It is widely used in LaTeX and other modern typesetting systems to render mathematical equations.\n\n---\n\n<a id=\"zh\"></a>\n# 18s : WebC 组件库中文字体分片包\n\nWebC 是面向 AI 辅助开发的 Web Components 组件库。本包为 WebC 提供中文字体分片支持。\n\n组件库在线浏览地址：[https://webc-zh.pages.dev](https://webc-zh.pages.dev)\n\n* [功能特性](#功能特性)\n* [目录结构](#目录结构)\n* [设计思路与调用流程](#设计思路与调用流程)\n* [技术堆栈](#技术堆栈)\n* [使用指南](#使用指南)\n* [历史背景](#历史背景)\n\n## 功能特性\n\n- **中文字体分片**：将中文字体（CJK）切分为 WOFF2 分片（默认 128KB），降低加载时延。\n- **防止冲突**：基于分片内容生成 MD5 哈希作为文件名，解决缓存冲突并提升缓存命中率。\n- **可变字重与多字重支持**：提供思源黑体（`t`）与 JetBrains Mono（`c`）可变字重分片版本，同时支持发布免切片的数学字体 `m`（由 `otf/latinmodern-math.otf` 自动压缩生成）。\n- **CSS**：输出压缩的 CSS 代码，内置 `@font-face` 规则，映射字符区间至对应字体分片或映射多字重字体。\n\n## 目录结构\n\n```\n.\n├── gen/                 # 字体构建工作区，包含原始 TTF/OTF 文件与处理脚本\n│   ├── lib/             # 分片处理、哈希寻址与 CSS 压缩模块\n│   ├── ttf/             # 原始字体文件及配置\n│   ├── gen.js           # 字体分片执行脚本\n│   ├── m.js             # 数学字体处理脚本（无分片）\n│   └── gen.sh           # 依赖拉取与构建脚本\n├── woff2/               # 编译分发目录，包含最终发布资源\n│   ├── *.woff2          # 内容寻址的 WOFF2 字体分片/整包\n│   ├── t.css            # 思源黑体字体映射表\n│   ├── c.css            # JetBrains Mono 字体映射表\n│   ├── m.css            # 数学字体 m 的映射表\n│   └── _.css            # 合并所有字体的映射表（包含 t、c 与数学字体 m）\n├── readme/              # 文档目录\n│   ├── en.md            # 英文文档\n│   └── zh.md            # 中文文档\n├── package.json         # 项目元数据配置\n└── README.mdt           # 主 README 模板文件\n```\n\n## 设计思路与调用流程\n\n构建系统读取 `gen/ttf/gen.yml` 配置，处理字体并生成发布资源。\n\n```mermaid\ngraph TD\n    A[Font files: SourceHanSansSC / JetBrainsMono] --> B[fontSplit / cn-font-split]\n    B --> C[生成 WOFF2 分片与 result.css]\n    C --> D[将 WOFF2 分片重命名为 MD5 Base64url 哈希]\n    D --> E[重写 CSS 字体族名称与分片路径]\n    E --> F[输出 woff2/t.css、woff2/c.css 与 woff2/_.css]\n```\n\n1. **分片处理**：调用 `cn-font-split` 工具，将字体切分为 WOFF2 片段。\n2. **哈希映射**：计算分片内容的 MD5 base64url 哈希作为文件名（长度从 4 开始，遇冲突时递增），实现内容寻址。\n3. **样式重写**：解析 CSS，将 font-family 替换为别名（`t` 或 `c`），移除本地路径（`local`）查询，更新字体分片 URL 引用。\n4. **资源输出**：将 CSS 及字体分片写入发布目录 `woff2/`，进行 npm 发布。\n\n## 技术堆栈\n\n- **运行环境**：Bun\n- **分片工具**：`cn-font-split`\n- **样式压缩**：`lightningcss`\n- **哈希算法**：`@3-/base64url`\n\n## 使用指南\n\n### 安装依赖\n\n```bash\nnpm install 18s\n```\n\n### 导入字体\n\n在 Web 组件或应用入口中引入 CSS 文件：\n\n```javascript\n// 一次性引入所有字体（合并后的 CSS，包含 t、c 与数学字体 m）\nimport '18s/_.css';\n\n// 或者按需引入单个字体\n// 引入思源黑体\nimport '18s/t.css';\n\n// 引入 JetBrains Mono\nimport '18s/c.css';\n\n// 引入数学字体 m\nimport '18s/m.css';\n```\n\n在样式表中应用对应的字体族：\n\n```css\nbody {\n  font-family: t, sans-serif;\n}\n\ncode {\n  font-family: c, t, monospace;\n}\n\nmath {\n  font-family: m, t, sans-serif;\n}\n```\n\n### 发布数学字体\n\n1. 字体源文件为项目根目录下的 `otf/latinmodern-math.otf`。\n2. 在 `gen/` 目录运行构建命令 `./gen.sh`，构建系统会自动将其压缩为 WOFF2 并保存到 `woff2/` 下（通过内容寻址哈希命名），同时生成映射到字体族 `m` 的 `woff2/m.css`。\n\n## 历史背景\n\nCJK 字体由于文件大（10MB 至 50MB），直接加载会导致白屏或字体闪烁。以往开发多采用系统默认字体，或通过静态抽字工具仅保留部分字词，限制了动态内容展示。\n\n2014 年，Adobe 与 Google 推出 CJK 字体思源黑体（Source Han Sans），但体积问题依旧存在。随着分片技术（如 `cn-font-split`）出现，字体文件能按字符使用频率切分为数百个分片。浏览器按需下载分片，优化了中文字体加载体验。\n\nJetBrains Mono 是 2020 年发布的编程字体。`18s` 将思源黑体与 JetBrains Mono 作为可变字体整合分片，为 WebC 提供中文字体支持。\n\n### Latin Modern Math 数学字体\n\n**Latin Modern Math** 是一款 OpenType 格式的数学字体，旨在作为 Latin Modern 字体家族的现代伴侣，完成了对高德纳（Donald Knuth）经典 Computer Modern 字体的现代化重构。该字体包含了丰富的数学和技术符号，并支持高级 OpenType 数学排版特性（支持 `MATH` 表），广泛应用于 LaTeX 及其他现代排版系统中，以提供高质量、规范的数学公式渲染效果。\n","readmeFilename":"README.md"}