mirror of
https://github.com/2234839/web-font.git
synced 2026-09-04 23:02:27 +08:00
chore(packages): 补齐两包 npm 发布元数据(LICENSE/README/types 路径修正/author/repository)
This commit is contained in:
parent
8d53425483
commit
ec5740c266
21
packages/leafer-x-webfont/LICENSE
Normal file
21
packages/leafer-x-webfont/LICENSE
Normal file
@ -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.
|
||||
@ -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"
|
||||
|
||||
21
packages/webfont-sdk/LICENSE
Normal file
21
packages/webfont-sdk/LICENSE
Normal file
@ -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.
|
||||
72
packages/webfont-sdk/README.md
Normal file
72
packages/webfont-sdk/README.md
Normal file
@ -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
|
||||
<script src="https://webfont.shenzilong.cn/webfont-sdk.js"></script>
|
||||
<script>
|
||||
WebFont.observeFont({ fontName: '令东齐伋复刻体.ttf', selector: '.title', family: 'MyFont' })
|
||||
</script>
|
||||
```
|
||||
|
||||
## 文档
|
||||
|
||||
完整 API 文档:<https://webfont.shenzilong.cn/docs>
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user