dompdf.js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +566 -0
- package/LICENSE +22 -0
- package/README.md +155 -0
- package/README_CN.md +305 -0
- package/dist/__tests__/index.d.ts +1 -0
- package/dist/core/__mocks__/cache-storage.d.ts +2 -0
- package/dist/core/__mocks__/context.d.ts +9 -0
- package/dist/core/__mocks__/features.d.ts +8 -0
- package/dist/core/__mocks__/logger.d.ts +9 -0
- package/dist/core/__tests__/cache-storage.d.ts +1 -0
- package/dist/core/__tests__/logger.d.ts +1 -0
- package/dist/core/bitwise.d.ts +1 -0
- package/dist/core/cache-storage.d.ts +26 -0
- package/dist/core/context.d.ts +15 -0
- package/dist/core/debugger.d.ts +8 -0
- package/dist/core/features.d.ts +12 -0
- package/dist/core/logger.d.ts +18 -0
- package/dist/core/util.d.ts +1 -0
- package/dist/css/IPropertyDescriptor.d.ts +36 -0
- package/dist/css/ITypeDescriptor.d.ts +6 -0
- package/dist/css/index.d.ts +132 -0
- package/dist/css/layout/__mocks__/bounds.d.ts +2 -0
- package/dist/css/layout/bounds.d.ts +14 -0
- package/dist/css/layout/text.d.ts +10 -0
- package/dist/css/property-descriptors/__tests__/background-tests.d.ts +1 -0
- package/dist/css/property-descriptors/__tests__/font-family.d.ts +1 -0
- package/dist/css/property-descriptors/__tests__/paint-order.d.ts +1 -0
- package/dist/css/property-descriptors/__tests__/text-shadow.d.ts +1 -0
- package/dist/css/property-descriptors/__tests__/transform-tests.d.ts +1 -0
- package/dist/css/property-descriptors/background-clip.d.ts +8 -0
- package/dist/css/property-descriptors/background-color.d.ts +2 -0
- package/dist/css/property-descriptors/background-image.d.ts +3 -0
- package/dist/css/property-descriptors/background-origin.d.ts +8 -0
- package/dist/css/property-descriptors/background-position.d.ts +5 -0
- package/dist/css/property-descriptors/background-repeat.d.ts +9 -0
- package/dist/css/property-descriptors/background-size.d.ts +11 -0
- package/dist/css/property-descriptors/border-color.d.ts +5 -0
- package/dist/css/property-descriptors/border-radius.d.ts +7 -0
- package/dist/css/property-descriptors/border-style.d.ts +12 -0
- package/dist/css/property-descriptors/border-width.d.ts +5 -0
- package/dist/css/property-descriptors/box-shadow.d.ts +14 -0
- package/dist/css/property-descriptors/color.d.ts +2 -0
- package/dist/css/property-descriptors/content.d.ts +4 -0
- package/dist/css/property-descriptors/counter-increment.d.ts +7 -0
- package/dist/css/property-descriptors/counter-reset.d.ts +7 -0
- package/dist/css/property-descriptors/direction.d.ts +6 -0
- package/dist/css/property-descriptors/display.d.ts +35 -0
- package/dist/css/property-descriptors/duration.d.ts +2 -0
- package/dist/css/property-descriptors/float.d.ts +9 -0
- package/dist/css/property-descriptors/font-family.d.ts +4 -0
- package/dist/css/property-descriptors/font-size.d.ts +2 -0
- package/dist/css/property-descriptors/font-style.d.ts +7 -0
- package/dist/css/property-descriptors/font-variant.d.ts +2 -0
- package/dist/css/property-descriptors/font-weight.d.ts +2 -0
- package/dist/css/property-descriptors/letter-spacing.d.ts +2 -0
- package/dist/css/property-descriptors/line-break.d.ts +6 -0
- package/dist/css/property-descriptors/line-height.d.ts +4 -0
- package/dist/css/property-descriptors/list-style-image.d.ts +3 -0
- package/dist/css/property-descriptors/list-style-position.d.ts +6 -0
- package/dist/css/property-descriptors/list-style-type.d.ts +58 -0
- package/dist/css/property-descriptors/margin.d.ts +5 -0
- package/dist/css/property-descriptors/opacity.d.ts +2 -0
- package/dist/css/property-descriptors/overflow-wrap.d.ts +6 -0
- package/dist/css/property-descriptors/overflow.d.ts +9 -0
- package/dist/css/property-descriptors/padding.d.ts +5 -0
- package/dist/css/property-descriptors/paint-order.d.ts +8 -0
- package/dist/css/property-descriptors/position.d.ts +9 -0
- package/dist/css/property-descriptors/quotes.d.ts +8 -0
- package/dist/css/property-descriptors/text-align.d.ts +7 -0
- package/dist/css/property-descriptors/text-decoration-color.d.ts +2 -0
- package/dist/css/property-descriptors/text-decoration-line.d.ts +10 -0
- package/dist/css/property-descriptors/text-shadow.d.ts +12 -0
- package/dist/css/property-descriptors/text-transform.d.ts +8 -0
- package/dist/css/property-descriptors/transform-origin.d.ts +4 -0
- package/dist/css/property-descriptors/transform.d.ts +4 -0
- package/dist/css/property-descriptors/visibility.d.ts +7 -0
- package/dist/css/property-descriptors/webkit-text-stroke-color.d.ts +2 -0
- package/dist/css/property-descriptors/webkit-text-stroke-width.d.ts +2 -0
- package/dist/css/property-descriptors/word-break.d.ts +7 -0
- package/dist/css/property-descriptors/z-index.d.ts +7 -0
- package/dist/css/syntax/__tests__/tokernizer-tests.d.ts +1 -0
- package/dist/css/syntax/parser.d.ts +34 -0
- package/dist/css/syntax/tokenizer.d.ts +94 -0
- package/dist/css/types/__tests__/color-tests.d.ts +1 -0
- package/dist/css/types/__tests__/image-tests.d.ts +1 -0
- package/dist/css/types/angle.d.ts +7 -0
- package/dist/css/types/color.d.ts +11 -0
- package/dist/css/types/functions/-prefix-linear-gradient.d.ts +4 -0
- package/dist/css/types/functions/-prefix-radial-gradient.d.ts +4 -0
- package/dist/css/types/functions/-webkit-gradient.d.ts +4 -0
- package/dist/css/types/functions/__tests__/radial-gradient.d.ts +1 -0
- package/dist/css/types/functions/counter.d.ts +10 -0
- package/dist/css/types/functions/gradient.d.ts +7 -0
- package/dist/css/types/functions/linear-gradient.d.ts +4 -0
- package/dist/css/types/functions/radial-gradient.d.ts +12 -0
- package/dist/css/types/image.d.ts +54 -0
- package/dist/css/types/index.d.ts +1 -0
- package/dist/css/types/length-percentage.d.ts +11 -0
- package/dist/css/types/length.d.ts +4 -0
- package/dist/css/types/time.d.ts +2 -0
- package/dist/dom/__mocks__/document-cloner.d.ts +6 -0
- package/dist/dom/document-cloner.d.ts +45 -0
- package/dist/dom/element-container.d.ts +21 -0
- package/dist/dom/elements/li-element-container.d.ts +6 -0
- package/dist/dom/elements/ol-element-container.d.ts +7 -0
- package/dist/dom/elements/select-element-container.d.ts +6 -0
- package/dist/dom/elements/textarea-element-container.d.ts +6 -0
- package/dist/dom/node-parser.d.ts +23 -0
- package/dist/dom/replaced-elements/canvas-element-container.d.ts +8 -0
- package/dist/dom/replaced-elements/iframe-element-container.d.ts +11 -0
- package/dist/dom/replaced-elements/image-element-container.d.ts +8 -0
- package/dist/dom/replaced-elements/index.d.ts +4 -0
- package/dist/dom/replaced-elements/input-element-container.d.ts +12 -0
- package/dist/dom/replaced-elements/svg-element-container.d.ts +8 -0
- package/dist/dom/text-container.d.ts +8 -0
- package/dist/dompdf.esm.js +33182 -0
- package/dist/dompdf.esm.js.map +1 -0
- package/dist/dompdf.js +33190 -0
- package/dist/dompdf.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/invariant.d.ts +1 -0
- package/dist/render/background.d.ts +16 -0
- package/dist/render/bezier-curve.d.ts +14 -0
- package/dist/render/border.d.ts +6 -0
- package/dist/render/bound-curves.d.ts +32 -0
- package/dist/render/box-sizing.d.ts +4 -0
- package/dist/render/canvas/canvas-renderer2.d.ts +81 -0
- package/dist/render/canvas/foreignobject-renderer.d.ts +11 -0
- package/dist/render/canvas/pdf-renderer.d.ts +82 -0
- package/dist/render/effects.d.ts +38 -0
- package/dist/render/font-metrics.d.ts +11 -0
- package/dist/render/path.d.ts +13 -0
- package/dist/render/renderer.d.ts +7 -0
- package/dist/render/stacking-context.d.ts +24 -0
- package/dist/render/vector.d.ts +9 -0
- package/html2pdf-userscript.js +936 -0
- package/package.json +134 -0
- package/tsconfig.json +23 -0
- package/userscript.js +372 -0
- package/webpack.base.js +31 -0
- package/webpack.dev.js +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# dompdf
|
|
2
|
+
|
|
3
|
+
<!-- [主页](https://html2canvas.hertzen.com) | [下载](https://github.com/niklasvh/html2canvas/releases) | [问题](https://github.com/niklasvh/html2canvas/discussions/categories/q-a)
|
|
4
|
+
|
|
5
|
+
[](https://gitter.im/niklasvh/html2canvas?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
|
6
|
+

|
|
7
|
+
[](https://www.npmjs.org/package/html2canvas)
|
|
8
|
+
[](https://www.npmjs.org/package/html2canvas) -->
|
|
9
|
+
|
|
10
|
+
该脚本允许您直接在用户浏览器上将网页或部分网页生成为可编辑、非图片式、可打印的 pdf。由于生成是基于 DOM 的,因此可能与实际表现不会 100% 一致。
|
|
11
|
+
|
|
12
|
+
### 它是如何工作的
|
|
13
|
+
|
|
14
|
+
该脚本基于[html2canvas](https://github.com/niklasvh/html2canvas)和[jspdf](https://github.com/MrRio/jsPDF),与以往将 html 页面通过 html2canvas 渲染为图片,再通过 jspdf 将图片生成 pdf 文件不同,该脚本通过读取 DOM 和应用于元素的不同样式,改造了 html2canvas 的 canvas-renderer 文件,调用 jspdf 的方法生成 pdf 文件。
|
|
15
|
+
所以他有以下优势:
|
|
16
|
+
|
|
17
|
+
1. 不需要服务器端的任何渲染,因为整个 pdf 是在**客户端浏览器**上创建的。
|
|
18
|
+
2. 生成的是真正的 pdf 文件,而不是图片式的,这样生成的 pdf 质量更高,您也可以编辑和打印生成 pdf 文件。
|
|
19
|
+
3. 更小的 pdf 文件体积
|
|
20
|
+
|
|
21
|
+
当然,它也有一些缺点:
|
|
22
|
+
|
|
23
|
+
1. 由于是基于 DOM 的,所以可能与实际表现不会 100% 一致。
|
|
24
|
+
2. 有的 css 属性还没有被支持,查看[支持的 css 属性](https://www.html2canvas.cn/html2canvas-features.html)。
|
|
25
|
+
3. 不适合在 nodejs 中使用。
|
|
26
|
+
4. 有的样式可能无法被正确渲染,比如:
|
|
27
|
+
- text-shadow
|
|
28
|
+
|
|
29
|
+
### 已实现功能
|
|
30
|
+
|
|
31
|
+
| 功能 | 状态 | 说明 |
|
|
32
|
+
| -------- | ---- | --------------------------------------------------------------------------------------------------------- |
|
|
33
|
+
| 文本渲染 | ✅ | 支持基础文本内容渲染,font-family,font-size,font-style,font-variant,color 等,支持文字描边,不支持文字阴影 |
|
|
34
|
+
| 图片渲染 | ✅ | 支持网络图片,base64 图片,svg 图片 |
|
|
35
|
+
| 边框 | ✅ | 支持 border-width,border-color,border-style,border-radius,暂时只实现了实线边框 |
|
|
36
|
+
| 背景 | ✅ | 支持背景颜色,背景图片,背景渐变 |
|
|
37
|
+
| canvas | ✅ | 支持渲染 canvas |
|
|
38
|
+
| svg | ✅ | 支持渲染 svg |
|
|
39
|
+
| iframe | ❌ | 支持渲染 iframe |
|
|
40
|
+
| 阴影渲染 | ✅ | 使用 foreignObjectRendering,支持边框阴影渲染 |
|
|
41
|
+
| 渐变渲染 | ✅ | 使用 foreignObjectRendering,支持背景渐变渲染 |
|
|
42
|
+
|
|
43
|
+
### foreignObjectRendering 使用
|
|
44
|
+
|
|
45
|
+
在 dom 十分复杂,或者 pdf 无法绘制的情况(比如:复杂的表格,边框阴影,渐变等),可以考虑使用 foreignObjectRendering。
|
|
46
|
+
给要渲染的元素添加 foreignObjectRendering 属性,就可以通过 svg 的 foreignObject 将它渲染成一张背景图插入到 pdf 文件中。
|
|
47
|
+
|
|
48
|
+
但是,由于 foreignObject 元素的渲染依赖于浏览器的实现,因此在不同的浏览器中可能会有不同的表现。
|
|
49
|
+
所以,在使用 foreignObjectRendering 时,需要注意以下事项:
|
|
50
|
+
|
|
51
|
+
1. foreignObject 元素的渲染依赖于浏览器的实现,因此在不同的浏览器中可能会有不同的表现。
|
|
52
|
+
2. IE 浏览器完全不支持,推荐在 chrome 和 firefox,edge 中使用。
|
|
53
|
+
3. 生成的图片会导致 pdf 文件体积变大。
|
|
54
|
+
|
|
55
|
+
示例
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
<div style="width: 100px;height: 100px;" foreignObjectRendering>
|
|
59
|
+
<div
|
|
60
|
+
style="width: 50px;height: 50px;border: 1px solid #000;box-shadow: 2px 2px 5px rgba(0,0,0,0.3);background: linear-gradient(45deg, #ff6b6b, #4ecdc4);"
|
|
61
|
+
>
|
|
62
|
+
这是一个div元素
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 浏览器兼容性
|
|
68
|
+
|
|
69
|
+
该库应该可以在以下浏览器上正常工作(需要 `Promise` polyfill):
|
|
70
|
+
|
|
71
|
+
- Firefox 3.5+
|
|
72
|
+
- Google Chrome
|
|
73
|
+
- Opera 12+
|
|
74
|
+
- IE9+
|
|
75
|
+
- Safari 6+
|
|
76
|
+
|
|
77
|
+
### 使用方法
|
|
78
|
+
|
|
79
|
+
dompdf 库使用 `Promise` 并期望它们在全局上下文中可用。如果您希望支持不原生支持 `Promise` 的[较旧浏览器](http://caniuse.com/#search=promise),请在引入 `dompdf` 之前包含一个 polyfill,比如 [es6-promise](https://github.com/jakearchibald/es6-promise)。
|
|
80
|
+
|
|
81
|
+
安装:
|
|
82
|
+
|
|
83
|
+
npm install dompdf.js --save
|
|
84
|
+
|
|
85
|
+
#### 基础用法
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import dompdf from 'dompdf.js';
|
|
89
|
+
dompdf(document.querySelector("#capture"), {
|
|
90
|
+
useCORS: true //是否允许跨域
|
|
91
|
+
})
|
|
92
|
+
.then(function (blob) {
|
|
93
|
+
const url = URL.createObjectURL(blob);
|
|
94
|
+
const a = document.createElement('a');
|
|
95
|
+
a.href = url;
|
|
96
|
+
a.download = 'example.pdf';
|
|
97
|
+
document.body.appendChild(a);
|
|
98
|
+
a.click();
|
|
99
|
+
})
|
|
100
|
+
.catch(function (err) {
|
|
101
|
+
console.log(err, 'err');
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### 字体支持
|
|
106
|
+
|
|
107
|
+
如果需要自定义字体,在[这里](https://rawgit.com/MrRio/jsPDF/master/fontconverter/fontconverter.html)将字体 tff 文件转化成 base64 格式的 js 文件,中文字体推荐使用[思源黑体](https://github.com/lmn1919/dompdf.js/blob/main/examples/SourceHanSansSC-Normal-Min-normal.js),体积较小。
|
|
108
|
+
在代码中引入该文件即可。
|
|
109
|
+
|
|
110
|
+
````js
|
|
111
|
+
<script type="text/javascript" src="./SourceHanSansSC-Normal-Min-normal.js"></script>
|
|
112
|
+
dompdf(document.querySelector("#capture"), {
|
|
113
|
+
useCORS: true, //是否允许跨域
|
|
114
|
+
fontConfig: {
|
|
115
|
+
fontFamily: 'SourceHanSansSC-Normal-Min',
|
|
116
|
+
fontBase64: window.fontBase64,
|
|
117
|
+
},
|
|
118
|
+
})
|
|
119
|
+
.then(function (blob) {
|
|
120
|
+
const url = URL.createObjectURL(blob);
|
|
121
|
+
const a = document.createElement('a');
|
|
122
|
+
a.href = url;
|
|
123
|
+
a.download = 'example.pdf';
|
|
124
|
+
document.body.appendChild(a);
|
|
125
|
+
a.click();
|
|
126
|
+
})
|
|
127
|
+
.catch(function (err) {
|
|
128
|
+
console.log(err, 'err');
|
|
129
|
+
});
|
|
130
|
+
````
|
|
131
|
+
|
|
132
|
+
### 构建
|
|
133
|
+
|
|
134
|
+
<!-- 您可以在[这里](https://github.com/niklasvh/html2canvas/releases)下载已构建好的版本。 -->
|
|
135
|
+
|
|
136
|
+
克隆 git 仓库:
|
|
137
|
+
|
|
138
|
+
$ git clone git@github.com:lmn1919/dompdf.js.git
|
|
139
|
+
|
|
140
|
+
安装依赖:
|
|
141
|
+
|
|
142
|
+
$ npm install
|
|
143
|
+
|
|
144
|
+
构建浏览器包:
|
|
145
|
+
|
|
146
|
+
$ npm run build
|
|
147
|
+
|
|
148
|
+
<!-- ### 示例
|
|
149
|
+
|
|
150
|
+
有关更多信息和示例,请访问[主页](https://html2canvas.hertzen.com)或尝试[测试控制台](https://html2canvas.hertzen.com/tests/)。
|
|
151
|
+
|
|
152
|
+
### 贡献
|
|
153
|
+
|
|
154
|
+
如果您希望为项目做出贡献,请将拉取请求发送到 develop 分支。在提交任何更改之前,请尝试测试这些更改是否适用于所有支持的浏览器。如果某些 CSS 属性不受支持或不完整,请在提交任何代码更改之前也为其创建适当的测试。 -->
|
|
155
|
+
````
|
package/README_CN.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# dompdf
|
|
2
|
+
|
|
3
|
+
dompdf 纯前端将HTML转换为可编辑,非图片式的,可打印的PDF文件。
|
|
4
|
+
|
|
5
|
+
> :warning: v0.10 版本中报告了一些问题。这些问题正在调查中,同时您可以考虑继续使用 v0.9.3 版本("^0.9.3" in npm, 或者[在 HTML script 标签中使用 cdnjs](https://cdnjs.com/libraries/dompdf.js/0.9.3))。
|
|
6
|
+
|
|
7
|
+
## 目录
|
|
8
|
+
|
|
9
|
+
- [开始使用](#开始使用)
|
|
10
|
+
- [CDN](#cdn)
|
|
11
|
+
- [原生 JS](#原生-js)
|
|
12
|
+
- [NPM](#npm)
|
|
13
|
+
- [Bower](#bower)
|
|
14
|
+
- [控制台](#控制台)
|
|
15
|
+
- [使用方法](#使用方法)
|
|
16
|
+
- [高级用法](#高级用法)
|
|
17
|
+
- [工作流程](#工作流程)
|
|
18
|
+
- [Worker API](#worker-api)
|
|
19
|
+
- [配置选项](#配置选项)
|
|
20
|
+
- [分页](#分页)
|
|
21
|
+
- [分页设置](#分页设置)
|
|
22
|
+
- [分页模式](#分页模式)
|
|
23
|
+
- [使用示例](#使用示例)
|
|
24
|
+
- [图片类型和质量](#图片类型和质量)
|
|
25
|
+
- [进度跟踪](#进度跟踪)
|
|
26
|
+
- [依赖项](#依赖项)
|
|
27
|
+
- [贡献](#贡献)
|
|
28
|
+
- [问题](#问题)
|
|
29
|
+
- [测试](#测试)
|
|
30
|
+
- [Pull requests](#pull-requests)
|
|
31
|
+
- [致谢](#致谢)
|
|
32
|
+
- [许可证](#许可证)
|
|
33
|
+
|
|
34
|
+
## 开始使用
|
|
35
|
+
|
|
36
|
+
#### CDN
|
|
37
|
+
|
|
38
|
+
使用 dompdf.js 最简单的方法是通过 cdnjs 在 HTML 中引入它:
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompdf.js/0.10.1/dompdf.bundle.min.js" integrity="sha512-GsLlZN/3F2ErC5ifS5QtgpiJtWd43JWSuIgh7mbzZ8zBps+dvLusV+eNQATqgA/HdeKFVgA5v3S/cIrLF7QnIg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
使用 CDN URL 会锁定到特定版本,这可以确保稳定性并让您控制何时更改版本。cdnjs 提供访问 [dompdf.js 的所有历史版本](https://cdnjs.com/libraries/dompdf.js)。
|
|
45
|
+
|
|
46
|
+
*注意: 关于使用未打包版本 `dist/html2canvas.min.js` 的更多信息,请参阅[依赖项](#依赖项)。*
|
|
47
|
+
|
|
48
|
+
#### 原生 JS
|
|
49
|
+
|
|
50
|
+
您也可以直接下载 `dist/dompdf.bundle.min.js` 到项目文件夹中,并在 HTML 中引入:
|
|
51
|
+
|
|
52
|
+
```html
|
|
53
|
+
<script src="dompdf.bundle.min.js"></script>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### NPM
|
|
57
|
+
|
|
58
|
+
使用 NPM 安装 dompdf.js 及其依赖项: `npm install --save dompdf.js` (请确保包名中包含 `.js`)。
|
|
59
|
+
|
|
60
|
+
*注意: 您可以使用 NPM 创建项目,但 dompdf.js **不能在 Node.js 中运行**,它必须在浏览器中运行。*
|
|
61
|
+
|
|
62
|
+
#### Bower
|
|
63
|
+
|
|
64
|
+
使用 Bower 安装 dompdf.js 及其依赖项: `bower install --save dompdf.js` (请确保包名中包含 `.js`)。
|
|
65
|
+
|
|
66
|
+
#### 控制台
|
|
67
|
+
|
|
68
|
+
如果您在一个无法直接修改的网页上想要使用 dompdf.js 来捕获截图,可以按照以下步骤操作:
|
|
69
|
+
|
|
70
|
+
1. 打开浏览器控制台(不同浏览器的说明[在此](https://webmasters.stackexchange.com/a/77337/94367))。
|
|
71
|
+
2. 粘贴以下代码:
|
|
72
|
+
```js
|
|
73
|
+
function addScript(url) {
|
|
74
|
+
var script = document.createElement('script');
|
|
75
|
+
script.type = 'application/javascript';
|
|
76
|
+
script.src = url;
|
|
77
|
+
document.head.appendChild(script);
|
|
78
|
+
}
|
|
79
|
+
addScript('https://cdnjs.cloudflare.com/ajax/libs/dompdf.js/0.10.1/dompdf.bundle.min.js');
|
|
80
|
+
```
|
|
81
|
+
3. 现在您可以直接在控制台中执行 dompdf.js 命令。要捕获整个页面的默认 PDF,使用 `dompdf(document.body)`。
|
|
82
|
+
|
|
83
|
+
## 使用方法
|
|
84
|
+
|
|
85
|
+
安装完成后,dompdf.js 就可以使用了。以下命令将生成 `#element-to-print` 的 PDF 并提示用户保存结果:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
var element = document.getElementById('element-to-print');
|
|
89
|
+
dompdf(element);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 高级用法
|
|
93
|
+
|
|
94
|
+
dompdf.js 的每个步骤都是可配置的,使用其新的基于 Promise 的 API。如果调用 dompdf.js 时没有参数,它将返回一个 `Worker` 对象:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
var worker = dompdf(); // 或: var worker = new dompdf.Worker;
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
这个 worker 有一些方法可以按顺序链式调用,每个 Promise 解析后,允许在步骤之间插入您自己的中间函数。先决条件系统允许您跳过必需的步骤(如画布创建)而不会出现任何问题:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
// 这将在保存之前隐式创建画布和 PDF 对象
|
|
104
|
+
var worker = dompdf().from(element).save();
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### 工作流程
|
|
108
|
+
|
|
109
|
+
dompdf.js 任务的基本工作流程(由先决条件系统强制执行)是:
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
.from() -> .toContainer() -> .toCanvas() -> .toImg() -> .toPdf() -> .save()
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Worker API
|
|
116
|
+
|
|
117
|
+
| Method | Arguments | Description |
|
|
118
|
+
|--------------|--------------------|-------------|
|
|
119
|
+
| from | src, type | Sets the source (HTML string or element) for the PDF. Optional `type` specifies other sources: `'string'`, `'element'`, `'canvas'`, or `'img'`. |
|
|
120
|
+
| to | target | Converts the source to the specified target (`'container'`, `'canvas'`, `'img'`, or `'pdf'`). Each target also has its own `toX` method that can be called directly: `toContainer()`, `toCanvas()`, `toImg()`, and `toPdf()`. |
|
|
121
|
+
| output | type, options, src | Routes to the appropriate `outputPdf` or `outputImg` method based on specified `src` (`'pdf'` (default) or `'img'`). |
|
|
122
|
+
| outputPdf | type, options | Sends `type` and `options` to the jsPDF object's `output` method, and returns the result as a Promise (use `.then` to access). See the [jsPDF source code](https://rawgit.com/MrRio/jsPDF/master/docs/jspdf.js.html#line992) for more info. |
|
|
123
|
+
| outputImg | type, options | Returns the specified data type for the image as a Promise (use `.then` to access). Supported types: `'img'`, `'datauristring'`/`'dataurlstring'`, and `'datauri'`/`'dataurl'`. |
|
|
124
|
+
| save | filename | Saves the PDF object with the optional filename (creates user download prompt). |
|
|
125
|
+
| set | opt | Sets the specified properties. See [Options](#options) below for more details. |
|
|
126
|
+
| get | key, cbk | Returns the property specified in `key`, either as a Promise (use `.then` to access), or by calling `cbk` if provided. |
|
|
127
|
+
| then | onFulfilled, onRejected | Standard Promise method, with `this` re-bound to the Worker, and with added progress-tracking (see [Progress](#progress) below). Note that `.then` returns a `Worker`, which is a subclass of Promise. |
|
|
128
|
+
| thenCore | onFulFilled, onRejected | Standard Promise method, with `this` re-bound to the Worker (no progress-tracking). Note that `.thenCore` returns a `Worker`, which is a subclass of Promise. |
|
|
129
|
+
| thenExternal | onFulfilled, onRejected | True Promise method. Using this 'exits' the Worker chain - you will not be able to continue chaining Worker methods after `.thenExternal`. |
|
|
130
|
+
| catch, catchExternal | onRejected | Standard Promise method. `catchExternal` exits the Worker chain - you will not be able to continue chaining Worker methods after `.catchExternal`. |
|
|
131
|
+
| error | msg | Throws an error in the Worker's Promise chain. |
|
|
132
|
+
|
|
133
|
+
A few aliases are also provided for convenience:
|
|
134
|
+
|
|
135
|
+
| Method | Alias |
|
|
136
|
+
|-----------|-----------|
|
|
137
|
+
| save | saveAs |
|
|
138
|
+
| set | using |
|
|
139
|
+
| output | export |
|
|
140
|
+
| then | run |
|
|
141
|
+
|
|
142
|
+
## 配置选项
|
|
143
|
+
|
|
144
|
+
dompdf.js 可以使用可选的 `opt` 参数进行配置:
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
var element = document.getElementById('element-to-print');
|
|
148
|
+
var opt = {
|
|
149
|
+
margin: 1,
|
|
150
|
+
filename: 'myfile.pdf',
|
|
151
|
+
image: { type: 'jpeg', quality: 0.98 },
|
|
152
|
+
html2canvas: { scale: 2 },
|
|
153
|
+
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// New Promise-based usage:
|
|
157
|
+
dompdf().set(opt).from(element).save();
|
|
158
|
+
|
|
159
|
+
// Old monolithic-style usage:
|
|
160
|
+
dompdf(element, opt);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`opt` 参数具有以下可选字段:
|
|
164
|
+
|
|
165
|
+
|Name |Type |Default |Description |
|
|
166
|
+
|------------|----------------|--------------------------------|------------------------------------------------------------------------------------------------------------|
|
|
167
|
+
|margin |number or array |`0` |PDF margin (in jsPDF units). Can be a single number, `[vMargin, hMargin]`, or `[top, left, bottom, right]`. |
|
|
168
|
+
|filename |string |`'file.pdf'` |The default filename of the exported PDF. |
|
|
169
|
+
|pagebreak |object |`{mode: ['css', 'legacy']}` |Controls the pagebreak behaviour on the page. See [Page-breaks](#page-breaks) below. |
|
|
170
|
+
|image |object |`{type: 'jpeg', quality: 0.95}` |The image type and quality used to generate the PDF. See [Image type and quality](#image-type-and-quality) below.|
|
|
171
|
+
|enableLinks |boolean |`true` |If enabled, PDF hyperlinks are automatically added ontop of all anchor tags. |
|
|
172
|
+
|html2canvas |object |`{ }` |Configuration options sent directly to `html2canvas` ([see here](https://html2canvas.hertzen.com/configuration) for usage).|
|
|
173
|
+
|jsPDF |object |`{ }` |Configuration options sent directly to `jsPDF` ([see here](http://rawgit.com/MrRio/jsPDF/master/docs/jsPDF.html) for usage).|
|
|
174
|
+
|
|
175
|
+
### Page-breaks
|
|
176
|
+
|
|
177
|
+
dompdf.js 具有自动添加页面断点的能力,以清理您的文档。页面断点可以通过 CSS 样式、使用选择器设置在单个元素上,或者避免在所有元素内部断开(`avoid-all` 模式)。
|
|
178
|
+
|
|
179
|
+
默认情况下,dompdf.js 将尊重大多数 CSS [`break-before`](https://developer.mozilla.org/en-US/docs/Web/CSS/break-before), [`break-after`](https://developer.mozilla.org/en-US/docs/Web/CSS/break-after), 和 [`break-inside`](https://developer.mozilla.org/en-US/docs/Web/CSS/break-inside) 规则,并在任何元素具有类 `dompdf__page-break` 时添加页面断点(出于遗留目的)。
|
|
180
|
+
|
|
181
|
+
#### Page-break settings
|
|
182
|
+
|
|
183
|
+
|Setting |Type |Default |Description |
|
|
184
|
+
|----------|----------------|--------------------|------------|
|
|
185
|
+
|mode |string or array |`['css', 'legacy']` |The mode(s) on which to automatically add page-breaks. One or more of `'avoid-all'`, `'css'`, and `'legacy'`. |
|
|
186
|
+
|before |string or array |`[]` |CSS selectors for which to add page-breaks before each element. Can be a specific element with an ID (`'#myID'`), all elements of a type (e.g. `'img'`), all of a class (`'.myClass'`), or even `'*'` to match every element. |
|
|
187
|
+
|after |string or array |`[]` |Like 'before', but adds a page-break immediately after the element. |
|
|
188
|
+
|avoid |string or array |`[]` |Like 'before', but avoids page-breaks on these elements. You can enable this feature on every element using the 'avoid-all' mode. |
|
|
189
|
+
|
|
190
|
+
#### Page-break modes
|
|
191
|
+
|
|
192
|
+
| Mode | Description |
|
|
193
|
+
|-----------|-------------|
|
|
194
|
+
| avoid-all | Automatically adds page-breaks to avoid splitting any elements across pages. |
|
|
195
|
+
| css | Adds page-breaks according to the CSS `break-before`, `break-after`, and `break-inside` properties. Only recognizes `always/left/right` for before/after, and `avoid` for inside. |
|
|
196
|
+
| legacy | Adds page-breaks after elements with class `dompdf__page-break`. This feature may be removed in the future. |
|
|
197
|
+
|
|
198
|
+
#### 使用示例
|
|
199
|
+
|
|
200
|
+
```js
|
|
201
|
+
// Avoid page-breaks on all elements, and add one before #page2el.
|
|
202
|
+
dompdf().set({
|
|
203
|
+
pagebreak: { mode: 'avoid-all', before: '#page2el' }
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Enable all 'modes', with no explicit elements.
|
|
207
|
+
dompdf().set({
|
|
208
|
+
pagebreak: { mode: ['avoid-all', 'css', 'legacy'] }
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// No modes, only explicit elements.
|
|
212
|
+
dompdf().set({
|
|
213
|
+
pagebreak: { before: '.beforeClass', after: ['#after1', '#after2'], avoid: 'img' }
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Image type and quality
|
|
218
|
+
|
|
219
|
+
You may customize the image type and quality exported from the canvas by setting the `image` option. This must be an object with the following fields:
|
|
220
|
+
|
|
221
|
+
|Name |Type |Default |Description |
|
|
222
|
+
|------------|----------------|------------------------------|---------------------------------------------------------------------------------------------|
|
|
223
|
+
|type |string |'jpeg' |The image type. HTMLCanvasElement only supports 'png', 'jpeg', and 'webp' (on Chrome). |
|
|
224
|
+
|quality |number |0.95 |The image quality, from 0 to 1. This setting is only used for jpeg/webp (not png). |
|
|
225
|
+
|
|
226
|
+
These options are limited to the available settings for [HTMLCanvasElement.toDataURL()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL), which ignores quality settings for 'png' images. To enable png image compression, try using the [canvas-png-compression shim](https://github.com/ShyykoSerhiy/canvas-png-compression), which should be an in-place solution to enable png compression via the `quality` option.
|
|
227
|
+
|
|
228
|
+
## 进度跟踪
|
|
229
|
+
|
|
230
|
+
`dompdf()` 返回的 Worker 对象具有内置的进度跟踪机制。它将更新以允许进度回调,但目前仍在进行中。
|
|
231
|
+
|
|
232
|
+
## 依赖项
|
|
233
|
+
|
|
234
|
+
dompdf.js 依赖于外部包 [html2canvas](https://github.com/niklasvh/html2canvas), [jsPDF](https://github.com/MrRio/jsPDF), 和 [es6-promise](https://github.com/stefanpenner/es6-promise)。这些依赖项在使用 NPM 或捆绑包时自动加载。
|
|
235
|
+
|
|
236
|
+
如果使用未打包的 `dist/dompdf.min.js` (或其未最小化的版本),您还必须包括每个依赖项。顺序很重要,否则 html2canvas 将被 jsPDF 的内部实现覆盖:
|
|
237
|
+
|
|
238
|
+
```html
|
|
239
|
+
<script src="es6-promise.auto.min.js"></script>
|
|
240
|
+
<script src="jspdf.min.js"></script>
|
|
241
|
+
<script src="html2canvas.min.js"></script>
|
|
242
|
+
<script src="dompdf.min.js"></script>
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## 贡献
|
|
246
|
+
|
|
247
|
+
### 问题
|
|
248
|
+
|
|
249
|
+
在提交问题时,请提供可重现的代码,最好是创建一个[这个模板 jsFiddle](https://jsfiddle.net/u6o6ne41/) 的 fork(已经加载了 dompdf.js),记住 dompdf.js 使用 [html2canvas](https://github.com/niklasvh/html2canvas) 和 [jsPDF](https://github.com/MrRio/jsPDF) 作为依赖项,所以检查每个仓库的问题跟踪器以查看是否已经解决了您的问题。
|
|
250
|
+
|
|
251
|
+
#### 已知问题
|
|
252
|
+
|
|
253
|
+
1. **渲染:** html2canvas 渲染引擎不是完美的(尽管它相当不错!)。如果 html2canvas 没有正确渲染您的内容,我无法修复它。
|
|
254
|
+
- 您可以使用[这个 fiddle](https://jsfiddle.net/eKoopmans/z1rupL4c/) 进行测试,看看画布创建本身是否有问题。
|
|
255
|
+
|
|
256
|
+
2. **节点克隆(CSS 等):** dompdf.js 克隆内容的方式存在错误。正在开发修复 - 尝试:
|
|
257
|
+
- 直接文件: 转到 [dompdf.js/bugfix/clone-nodes-BUILD](/eKoopmans/dompdf.js/tree/bugfix/clone-nodes-BUILD) 并替换项目中的相关文件(例如 `dist/dompdf.bundle.js`)
|
|
258
|
+
- npm: `npm install eKoopmans/dompdf.js#bugfix/clone-nodes-BUILD`
|
|
259
|
+
- 相关项目: [Bugfix: Cloned nodes](https://github.com/eKoopmans/dompdf.js/projects/9)
|
|
260
|
+
|
|
261
|
+
3. **调整大小:** 目前,dompdf.js 将根元素调整大小以适应 PDF 页面(导致内部内容"重新流动")。
|
|
262
|
+
- 这通常是所需的行为,但并非总是如此。
|
|
263
|
+
- 有计划添加替代行为(例如"shrink-to-page"),但尚未准备好测试。
|
|
264
|
+
- 相关项目: [Feature: Single-page PDFs](https://github.com/eKoopmans/dompdf.js/projects/1)
|
|
265
|
+
|
|
266
|
+
4. **渲染为图像:** dompdf.js 将所有内容渲染为图像,然后将该图像放入 PDF 中。
|
|
267
|
+
- 这意味着文本是*不可选择或可搜索的*,并导致大文件大小。
|
|
268
|
+
- 这是目前不可避免的,但是最近在 jsPDF 中的改进可能很快使其能够直接渲染为矢量图形。
|
|
269
|
+
- 相关项目: [Feature: New renderer](https://github.com/eKoopmans/dompdf.js/projects/4)
|
|
270
|
+
|
|
271
|
+
5. **Promise 冲突:** dompdf.js 依赖于特定的 Promise 行为,并且可能在与自定义 Promise 库一起使用时失败。
|
|
272
|
+
- 在下一个版本中,Promises 将在 dompdf.js 中沙盒化以删除此问题。
|
|
273
|
+
- 相关项目: [Bugfix: Sandboxed promises](https://github.com/eKoopmans/dompdf.js/projects/11)
|
|
274
|
+
|
|
275
|
+
6. **最大大小:** HTML5 画布具有[最大高度/宽度](https://stackoverflow.com/a/11585939/4080966)。任何大于该值的都会失败。
|
|
276
|
+
- 这是 HTML5 本身的限制,导致 dompdf.js 中的大 PDF 完全空白。
|
|
277
|
+
- jsPDF 画布渲染器(在已知问题 #4 中提到)可能能够修复此问题!
|
|
278
|
+
- 相关项目: [Bugfix: Maximum canvas size](https://github.com/eKoopmans/dompdf.js/projects/5)
|
|
279
|
+
|
|
280
|
+
### 测试
|
|
281
|
+
|
|
282
|
+
dompdf.js 目前严重缺乏单元测试。任何贡献或建议的自动(或手动)测试都是受欢迎的。这是这个项目的高优先级待办事项。
|
|
283
|
+
|
|
284
|
+
### Pull requests
|
|
285
|
+
|
|
286
|
+
如果您想创建新功能或错误修复,请随时分叉并提交拉取请求!分叉,从 `main` 分支分支,并对 `/src/` 文件进行更改(而不是直接对 `/dist/` 进行更改)。您可以通过重建 `npm run build` 来测试更改。
|
|
287
|
+
|
|
288
|
+
## 致谢
|
|
289
|
+
|
|
290
|
+
[Erik Koopmans](https://github.com/eKoopmans)
|
|
291
|
+
|
|
292
|
+
#### 贡献者
|
|
293
|
+
|
|
294
|
+
- [@WilcoBreedt](https://github.com/WilcoBreedt)
|
|
295
|
+
- [@Ranger1230](https://github.com/Ranger1230)
|
|
296
|
+
|
|
297
|
+
#### 特别感谢
|
|
298
|
+
|
|
299
|
+
- [Sauce Labs](https://saucelabs.com/) 用于单元测试。
|
|
300
|
+
|
|
301
|
+
## 许可证
|
|
302
|
+
|
|
303
|
+
[The MIT License](http://opensource.org/licenses/MIT)
|
|
304
|
+
|
|
305
|
+
Copyright (c) 2017-2019 Erik Koopmans <[http://www.erik-koopmans.com/](http://www.erik-koopmans.com/)>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const contains: (bit: number, value: number) => boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Context } from './context';
|
|
2
|
+
export declare class CacheStorage {
|
|
3
|
+
private static _link?;
|
|
4
|
+
private static _origin;
|
|
5
|
+
static getOrigin(url: string): string;
|
|
6
|
+
static isSameOrigin(src: string): boolean;
|
|
7
|
+
static setContext(window: Window): void;
|
|
8
|
+
}
|
|
9
|
+
export interface ResourceOptions {
|
|
10
|
+
imageTimeout: number;
|
|
11
|
+
useCORS: boolean;
|
|
12
|
+
allowTaint: boolean;
|
|
13
|
+
proxy?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class Cache {
|
|
16
|
+
private readonly context;
|
|
17
|
+
private readonly _options;
|
|
18
|
+
private readonly _cache;
|
|
19
|
+
constructor(context: Context, _options: ResourceOptions);
|
|
20
|
+
addImage(src: string): Promise<void>;
|
|
21
|
+
match(src: string): Promise<any>;
|
|
22
|
+
private loadImage;
|
|
23
|
+
private has;
|
|
24
|
+
keys(): Promise<string[]>;
|
|
25
|
+
private proxy;
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Logger } from './logger';
|
|
2
|
+
import { Cache, ResourceOptions } from './cache-storage';
|
|
3
|
+
import { Bounds } from '../css/layout/bounds';
|
|
4
|
+
export type ContextOptions = {
|
|
5
|
+
logging: boolean;
|
|
6
|
+
cache?: Cache;
|
|
7
|
+
} & ResourceOptions;
|
|
8
|
+
export declare class Context {
|
|
9
|
+
windowBounds: Bounds;
|
|
10
|
+
private readonly instanceName;
|
|
11
|
+
readonly logger: Logger;
|
|
12
|
+
readonly cache: Cache;
|
|
13
|
+
private static instanceCount;
|
|
14
|
+
constructor(options: ContextOptions, windowBounds: Bounds);
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const createForeignObjectSVG: (width: number, height: number, x: number, y: number, node: Node) => SVGForeignObjectElement;
|
|
2
|
+
export declare const loadSerializedSVG: (svg: Node) => Promise<HTMLImageElement>;
|
|
3
|
+
export declare const FEATURES: {
|
|
4
|
+
readonly SUPPORT_RANGE_BOUNDS: boolean;
|
|
5
|
+
readonly SUPPORT_WORD_BREAKING: boolean;
|
|
6
|
+
readonly SUPPORT_SVG_DRAWING: boolean;
|
|
7
|
+
readonly SUPPORT_FOREIGNOBJECT_DRAWING: Promise<boolean>;
|
|
8
|
+
readonly SUPPORT_CORS_IMAGES: boolean;
|
|
9
|
+
readonly SUPPORT_RESPONSE_TYPE: boolean;
|
|
10
|
+
readonly SUPPORT_CORS_XHR: boolean;
|
|
11
|
+
readonly SUPPORT_NATIVE_TEXT_SEGMENTATION: boolean;
|
|
12
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface LoggerOptions {
|
|
2
|
+
id: string;
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare class Logger {
|
|
6
|
+
static instances: {
|
|
7
|
+
[key: string]: Logger;
|
|
8
|
+
};
|
|
9
|
+
private readonly id;
|
|
10
|
+
private readonly enabled;
|
|
11
|
+
private readonly start;
|
|
12
|
+
constructor({ id, enabled }: LoggerOptions);
|
|
13
|
+
debug(...args: unknown[]): void;
|
|
14
|
+
getTime(): number;
|
|
15
|
+
info(...args: unknown[]): void;
|
|
16
|
+
warn(...args: unknown[]): void;
|
|
17
|
+
error(...args: unknown[]): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SMALL_IMAGE = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CSSValue } from './syntax/parser';
|
|
2
|
+
import { CSSTypes } from './types';
|
|
3
|
+
import { Context } from '../core/context';
|
|
4
|
+
export declare const enum PropertyDescriptorParsingType {
|
|
5
|
+
VALUE = 0,
|
|
6
|
+
LIST = 1,
|
|
7
|
+
IDENT_VALUE = 2,
|
|
8
|
+
TYPE_VALUE = 3,
|
|
9
|
+
TOKEN_VALUE = 4
|
|
10
|
+
}
|
|
11
|
+
export interface IPropertyDescriptor {
|
|
12
|
+
name: string;
|
|
13
|
+
type: PropertyDescriptorParsingType;
|
|
14
|
+
initialValue: string;
|
|
15
|
+
prefix: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface IPropertyIdentValueDescriptor<T> extends IPropertyDescriptor {
|
|
18
|
+
type: PropertyDescriptorParsingType.IDENT_VALUE;
|
|
19
|
+
parse: (context: Context, token: string) => T;
|
|
20
|
+
}
|
|
21
|
+
export interface IPropertyTypeValueDescriptor extends IPropertyDescriptor {
|
|
22
|
+
type: PropertyDescriptorParsingType.TYPE_VALUE;
|
|
23
|
+
format: CSSTypes;
|
|
24
|
+
}
|
|
25
|
+
export interface IPropertyValueDescriptor<T> extends IPropertyDescriptor {
|
|
26
|
+
type: PropertyDescriptorParsingType.VALUE;
|
|
27
|
+
parse: (context: Context, token: CSSValue) => T;
|
|
28
|
+
}
|
|
29
|
+
export interface IPropertyListDescriptor<T> extends IPropertyDescriptor {
|
|
30
|
+
type: PropertyDescriptorParsingType.LIST;
|
|
31
|
+
parse: (context: Context, tokens: CSSValue[]) => T;
|
|
32
|
+
}
|
|
33
|
+
export interface IPropertyTokenValueDescriptor extends IPropertyDescriptor {
|
|
34
|
+
type: PropertyDescriptorParsingType.TOKEN_VALUE;
|
|
35
|
+
}
|
|
36
|
+
export type CSSPropertyDescriptor<T> = IPropertyValueDescriptor<T> | IPropertyListDescriptor<T> | IPropertyIdentValueDescriptor<T> | IPropertyTypeValueDescriptor | IPropertyTokenValueDescriptor;
|