Skip to content

Commit bdea2a9

Browse files
committed
feat: 初始化
0 parents  commit bdea2a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+20940
-0
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue}]
2+
charset = utf-8
3+
indent_size = 2
4+
indent_style = space
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
8+
end_of_line = lf
9+
max_line_length = 100

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.gitignore

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
.DS_Store
12+
dist
13+
dist-ssr
14+
coverage
15+
*.local
16+
17+
/cypress/videos/
18+
/cypress/screenshots/
19+
20+
# Editor directories and files
21+
.vscode/*
22+
!.vscode/extensions.json
23+
.idea
24+
*.suo
25+
*.ntvs*
26+
*.njsproj
27+
*.sln
28+
*.sw?
29+
30+
*.tsbuildinfo

.husky/commit-msg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env sh
2+
3+
npx --no-install commitlint --edit "$1"

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
3+
# npm run test
4+
npx --no-install nano-staged

.prettierrc.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
{
3+
"$schema": "https://json.schemastore.org/prettierrc",
4+
"semi": false,
5+
"singleQuote": true,
6+
"printWidth": 100
7+
}

.vscode/extensions.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"recommendations": [
3+
"Vue.volar",
4+
"vitest.explorer",
5+
"dbaeumer.vscode-eslint",
6+
"EditorConfig.EditorConfig",
7+
"esbenp.prettier-vscode"
8+
]
9+
}

README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# html-to-pdf 文档手册
2+
3+
本库致力于 html 在线导出为 pdf,实现智能分页效果,不会切断文本图片表格等内容,可兼容手机端。本库依赖 html2canvas 和 jspdf,使用 canvas 绘图,请保证使用浏览器对以上库是支持的。
4+
5+
### 安装
6+
7+
```bash
8+
# 使用npm
9+
npm i -S ai-html-to-pdf
10+
# 使用yarn
11+
yarn add ai-html-to-pdf
12+
```
13+
14+
### 用法
15+
16+
```ts
17+
// ...
18+
import htmlToPdf from 'ai-html-to-pdf'
19+
20+
function exportPDF() {
21+
Loading.show()
22+
const element = document.getElementById('pdf-container')
23+
htmlToPdf
24+
.exportPDF(element, {
25+
name: '葵花宝典',
26+
})
27+
.finally(() => {
28+
Loading.hide()
29+
})
30+
}
31+
```
32+
33+
### 方法
34+
35+
使用规则:htmlToPdf(element, PdfOptions)
36+
37+
- element 要导出的 dom 元素
38+
- PdfOptions 通过设置配置,来达到更理想的效果
39+
40+
### PdfOptions
41+
42+
| 参数 | 类型 | 必填项 | 默认 | 说明 |
43+
| ------------------ | ------------------------------- | ------------------------ | ------------------------------------------------------------------------------ | -------------------------------------------- |
44+
| name | string || -- | 导出文件名称 |
45+
| monoblockClassName | string \| string[] || 'html-pdf-monoblock' | 分页处理时,将元素内容当作一个整体 |
46+
| scale | number || 2 | 导出内容放大倍数,增加内容清晰度,必须大于 0 |
47+
| margin | number \| number[] || 10 | PDF 内容边距 |
48+
| ignoreElement | (element: Element) => Element[] | 否 | 分页计算忽略的元素 |
49+
| resetStyleTags | string[] || 需要重置样式的标签,目前只发现 h1-h6 标签在 html2canvas 中默认增加了 margin 值 |
50+
| header | string || -- | 页眉文案 |
51+
| headerAlign | 'center' \| 'left' \| 'right' | 'left' | 页眉对齐方式 |
52+
| footer | string || -- | 页脚文案 |
53+
| footerAlign | 'center' \| 'left' \| 'right' | 'right' | 页脚对齐方式 |
54+
| adaptive | boolean | true | 是否开启自适应,开启自适应会根据设置宽度导出 PDF |
55+
| adaptiveOptions | AdaptiveOptions || -- | 自适应导出 PDF 配置 |
56+
57+
### AdaptiveOptions
58+
59+
| 参数 | 类型 | 必填项 | 默认 | 说明 |
60+
| -------------- | -------------------------- | ------ | ------------- | ---------------------------------------------------------------- |
61+
| pdfWidth | number || 800 | 按此宽度绘制导出 PDF 内容 |
62+
| parentElement | HTMLElement || document.body | 自适应创建元素挂载节点,必要时可以规避一些样式问题 |
63+
| |
64+
| resetView | (element: Element) => void || -- | 自适应模式下,是克隆的元素,导致 canvas 无法展示,对内容重新绘制 |
65+
| resetViewDelay | number || 1000 | 图表重绘后,延迟处理导出,给图表绘制预留充足的时间 |
66+
67+
## License
68+
69+
MIT

auto-imports.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-disable */
2+
/* prettier-ignore */
3+
// @ts-nocheck
4+
// noinspection JSUnusedGlobalSymbols
5+
// Generated by unplugin-auto-import
6+
// biome-ignore lint: disable
7+
export {}
8+
declare global {}
9+
10+
declare module '@kangc/v-md-editor/lib/codemirror-editor'
11+
declare module '@kangc/v-md-editor/lib/theme/github.js'
12+
declare module '@kangc/v-md-editor/lib/plugins/katex/cdn'

commitlint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { extends: ['@commitlint/config-conventional'] }

components.d.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable */
2+
// @ts-nocheck
3+
// Generated by unplugin-vue-components
4+
// Read more: https://github.com/vuejs/core/pull/3399
5+
// biome-ignore lint: disable
6+
export {}
7+
8+
/* prettier-ignore */
9+
declare module 'vue' {
10+
export interface GlobalComponents {
11+
AButton: typeof import('@arco-design/web-vue')['Button']
12+
AModal: typeof import('@arco-design/web-vue')['Modal']
13+
ASwitch: typeof import('@arco-design/web-vue')['Switch']
14+
Footer: typeof import('./src/components/footer.vue')['default']
15+
Header: typeof import('./src/components/header.vue')['default']
16+
Layout: typeof import('./src/components/layout.vue')['default']
17+
Loading: typeof import('./src/components/Loading/Loading.vue')['default']
18+
Nav: typeof import('./src/components/nav.vue')['default']
19+
RouterLink: typeof import('vue-router')['RouterLink']
20+
RouterView: typeof import('vue-router')['RouterView']
21+
}
22+
}

env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

eslint.config.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pluginVue from 'eslint-plugin-vue'
2+
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
3+
import pluginVitest from '@vitest/eslint-plugin'
4+
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
5+
6+
// To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
7+
// import { configureVueProject } from '@vue/eslint-config-typescript'
8+
// configureVueProject({ scriptLangs: ['ts', 'tsx'] })
9+
// More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup
10+
11+
export default defineConfigWithVueTs(
12+
{
13+
name: 'app/files-to-lint',
14+
files: ['**/*.{ts,mts,tsx,vue}'],
15+
},
16+
17+
{
18+
name: 'app/files-to-ignore',
19+
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
20+
},
21+
22+
pluginVue.configs['flat/essential'],
23+
vueTsConfigs.recommended,
24+
25+
{
26+
...pluginVitest.configs.recommended,
27+
files: ['src/**/__tests__/*'],
28+
},
29+
skipFormatting,
30+
)

index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Html-To-Pdf</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)