From ec5740c266134b75f976af25f459639742f0364d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=AE=E7=94=9F=EF=BC=88=E5=AD=90=E8=99=9A=EF=BC=89?= <2234839456@qq.com> Date: Sat, 15 Aug 2026 16:09:30 +0800 Subject: [PATCH] =?UTF-8?q?chore(packages):=20=E8=A1=A5=E9=BD=90=E4=B8=A4?= =?UTF-8?q?=E5=8C=85=20npm=20=E5=8F=91=E5=B8=83=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=EF=BC=88LICENSE/README/types=20=E8=B7=AF=E5=BE=84=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3/author/repository=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/leafer-x-webfont/LICENSE | 21 ++++++++ packages/leafer-x-webfont/package.json | 18 ++++--- packages/webfont-sdk/LICENSE | 21 ++++++++ packages/webfont-sdk/README.md | 72 ++++++++++++++++++++++++++ packages/webfont-sdk/package.json | 9 +++- 5 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 packages/leafer-x-webfont/LICENSE create mode 100644 packages/webfont-sdk/LICENSE create mode 100644 packages/webfont-sdk/README.md diff --git a/packages/leafer-x-webfont/LICENSE b/packages/leafer-x-webfont/LICENSE new file mode 100644 index 0000000..5ac0d6b --- /dev/null +++ b/packages/leafer-x-webfont/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 崮生(子虚) <2234839456@qq.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/leafer-x-webfont/package.json b/packages/leafer-x-webfont/package.json index fdeba52..3c6803b 100644 --- a/packages/leafer-x-webfont/package.json +++ b/packages/leafer-x-webfont/package.json @@ -3,18 +3,17 @@ "version": "0.1.0", "description": "LeaferJS 字体插件 —— Text 元素自动按需加载字体子集(6 字 ≈ 6KB),让画布与导出图用上任意中文字体", "type": "module", - "main": "./dist/leafer-x-webfont.esm.js", - "module": "./dist/leafer-x-webfont.esm.js", - "types": "./types/index.d.ts", + "main": "./dist/index.js", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", "exports": { ".": { - "types": "./types/index.d.ts", - "import": "./dist/leafer-x-webfont.esm.js" + "types": "./dist/index.d.ts", + "import": "./dist/index.js" } }, "files": [ "dist", - "types", "README.md", "LICENSE" ], @@ -31,7 +30,12 @@ "chinese-font", "poster" ], - "repository": "https://github.com/2234839/web-font", + "repository": { + "type": "git", + "url": "git+https://github.com/2234839/web-font.git", + "directory": "packages/leafer-x-webfont" + }, + "author": "崮生(子虚)", "license": "MIT", "peerDependencies": { "leafer-ui": "^2.0.0" diff --git a/packages/webfont-sdk/LICENSE b/packages/webfont-sdk/LICENSE new file mode 100644 index 0000000..5ac0d6b --- /dev/null +++ b/packages/webfont-sdk/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 崮生(子虚) <2234839456@qq.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/webfont-sdk/README.md b/packages/webfont-sdk/README.md new file mode 100644 index 0000000..b2f6c81 --- /dev/null +++ b/packages/webfont-sdk/README.md @@ -0,0 +1,72 @@ +# webfont-sdk + +> 中文字体按需增量加载 SDK —— 只加载页面/画布实际用到的字符(6 字 ≈ 6KB,而非 16MB),无闪烁。 + +[webfont.shenzilong.cn](https://webfont.shenzilong.cn) 子集化服务的官方前端 SDK,也是 +[leafer-x-webfont](https://github.com/2234839/web-font/tree/main/packages/leafer-x-webfont)(LeaferJS 插件)的底层引擎。 + +## 特性 + +- **增量加载**:`IncrementalEngine` 按字符集去重,只请求新增字符,同类文字滚动输入不重复请求 +- **双模式**:CSS 模式(`WebFont`,面向 DOM)+ FontFace 模式(`WebFontCanvas`,面向 Canvas) +- **失败记忆**:裁剪失败的字符自动记录,不反复重试浪费请求 +- **unicodeRange 注册**:Canvas 模式用 unicodeRange 精确注册字符片段,天然无闪烁 +- **并发控制**:可配置请求并发池,避免瞬时打爆服务端 +- **自定义 provider**:`setSubsetProvider` 可替换为本地裁剪(离线场景) + +## 安装 + +```bash +npm install webfont-sdk +``` + +## 使用 + +### CSS 模式 —— DOM 页面按需加载 + +```ts +import { WebFont } from 'webfont-sdk' + +// 事件驱动:自动观察 selector 内的文字变化 +const observer = WebFont.observeFont({ + fontName: '令东齐伋复刻体.ttf', + selector: '.title, .content', + family: 'MyFont', + baseUrl: 'https://webfont.shenzilong.cn', // 默认 location.origin +}) +observer.dispose() + +// 手动传文本 +const loader = WebFont.loadText({ fontName: '令东齐伋复刻体.ttf', text: '静心茶舍', family: 'MyFont' }) +loader.update('追加的文字') +loader.dispose() +``` + +### FontFace 模式 —— Canvas / LeaferJS 场景 + +```ts +import { WebFontCanvas } from 'webfont-sdk' + +const face = WebFontCanvas.loadFontFace({ fontName: '令东齐伋复刻体.ttf' }, () => { + /* 字体片段就绪,在此重绘画布 */ +}) +face.update('画布上的文字') +await WebFontCanvas.ready() +``` + +### script 标签直引(不打包场景) + +```html + + +``` + +## 文档 + +完整 API 文档: + +## License + +MIT diff --git a/packages/webfont-sdk/package.json b/packages/webfont-sdk/package.json index 20be6d7..972c658 100644 --- a/packages/webfont-sdk/package.json +++ b/packages/webfont-sdk/package.json @@ -15,6 +15,7 @@ }, "files": [ "dist", + "dist-iife", "README.md", "LICENSE" ], @@ -30,7 +31,13 @@ "canvas-font", "chinese-font" ], - "repository": "https://github.com/2234839/web-font", + "repository": { + "type": "git", + "url": "git+https://github.com/2234839/web-font.git", + "directory": "packages/webfont-sdk" + }, + "author": "崮生(子虚)", + "license": "MIT", "license": "MIT", "peerDependencies": { "@napi-rs/canvas": ">=0.1"