dompdf.js 1.0.2 → 1.0.4

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.
Files changed (392) hide show
  1. package/README.md +165 -154
  2. package/dist/dom/node-parser.d.ts +1 -1
  3. package/dist/dompdf.esm.js +3244 -3258
  4. package/dist/dompdf.esm.js.map +1 -1
  5. package/dist/dompdf.js +3245 -3259
  6. package/dist/dompdf.js.map +1 -1
  7. package/dist/lib/__tests__/index.js +144 -0
  8. package/dist/lib/__tests__/index.js.map +1 -0
  9. package/dist/lib/core/__mocks__/cache-storage.js +10 -0
  10. package/dist/lib/core/__mocks__/cache-storage.js.map +1 -0
  11. package/dist/lib/core/__mocks__/context.js +22 -0
  12. package/dist/lib/core/__mocks__/context.js.map +1 -0
  13. package/dist/lib/core/__mocks__/features.js +12 -0
  14. package/dist/lib/core/__mocks__/features.js.map +1 -0
  15. package/dist/lib/core/__mocks__/logger.js +24 -0
  16. package/dist/lib/core/__mocks__/logger.js.map +1 -0
  17. package/dist/lib/core/__tests__/cache-storage.js +420 -0
  18. package/dist/lib/core/__tests__/cache-storage.js.map +1 -0
  19. package/dist/lib/core/__tests__/logger.js +28 -0
  20. package/dist/lib/core/__tests__/logger.js.map +1 -0
  21. package/dist/lib/core/bitwise.js +6 -0
  22. package/dist/lib/core/bitwise.js.map +1 -0
  23. package/dist/lib/core/cache-storage.js +198 -0
  24. package/dist/lib/core/cache-storage.js.map +1 -0
  25. package/dist/lib/core/context.js +18 -0
  26. package/dist/lib/core/context.js.map +1 -0
  27. package/dist/lib/core/debugger.js +25 -0
  28. package/dist/lib/core/debugger.js.map +1 -0
  29. package/dist/lib/core/features.js +193 -0
  30. package/dist/lib/core/features.js.map +1 -0
  31. package/dist/lib/core/logger.js +92 -0
  32. package/dist/lib/core/logger.js.map +1 -0
  33. package/dist/lib/core/util.js +5 -0
  34. package/dist/lib/core/util.js.map +1 -0
  35. package/dist/lib/css/IPropertyDescriptor.js +3 -0
  36. package/dist/lib/css/IPropertyDescriptor.js.map +1 -0
  37. package/dist/lib/css/ITypeDescriptor.js +3 -0
  38. package/dist/lib/css/ITypeDescriptor.js.map +1 -0
  39. package/dist/lib/css/index.js +216 -0
  40. package/dist/lib/css/index.js.map +1 -0
  41. package/dist/lib/css/layout/__mocks__/bounds.js +9 -0
  42. package/dist/lib/css/layout/__mocks__/bounds.js.map +1 -0
  43. package/dist/lib/css/layout/bounds.js +42 -0
  44. package/dist/lib/css/layout/bounds.js.map +1 -0
  45. package/dist/lib/css/layout/text.js +137 -0
  46. package/dist/lib/css/layout/text.js.map +1 -0
  47. package/dist/lib/css/property-descriptors/__tests__/background-tests.js +48 -0
  48. package/dist/lib/css/property-descriptors/__tests__/background-tests.js.map +1 -0
  49. package/dist/lib/css/property-descriptors/__tests__/font-family.js +25 -0
  50. package/dist/lib/css/property-descriptors/__tests__/font-family.js.map +1 -0
  51. package/dist/lib/css/property-descriptors/__tests__/paint-order.js +88 -0
  52. package/dist/lib/css/property-descriptors/__tests__/paint-order.js.map +1 -0
  53. package/dist/lib/css/property-descriptors/__tests__/text-shadow.js +94 -0
  54. package/dist/lib/css/property-descriptors/__tests__/text-shadow.js.map +1 -0
  55. package/dist/lib/css/property-descriptors/__tests__/transform-tests.js +18 -0
  56. package/dist/lib/css/property-descriptors/__tests__/transform-tests.js.map +1 -0
  57. package/dist/lib/css/property-descriptors/background-clip.js +24 -0
  58. package/dist/lib/css/property-descriptors/background-clip.js.map +1 -0
  59. package/dist/lib/css/property-descriptors/background-color.js +11 -0
  60. package/dist/lib/css/property-descriptors/background-color.js.map +1 -0
  61. package/dist/lib/css/property-descriptors/background-image.js +24 -0
  62. package/dist/lib/css/property-descriptors/background-image.js.map +1 -0
  63. package/dist/lib/css/property-descriptors/background-origin.js +24 -0
  64. package/dist/lib/css/property-descriptors/background-origin.js.map +1 -0
  65. package/dist/lib/css/property-descriptors/background-position.js +17 -0
  66. package/dist/lib/css/property-descriptors/background-position.js.map +1 -0
  67. package/dist/lib/css/property-descriptors/background-repeat.js +36 -0
  68. package/dist/lib/css/property-descriptors/background-repeat.js.map +1 -0
  69. package/dist/lib/css/property-descriptors/background-size.js +24 -0
  70. package/dist/lib/css/property-descriptors/background-size.js.map +1 -0
  71. package/dist/lib/css/property-descriptors/border-color.js +15 -0
  72. package/dist/lib/css/property-descriptors/border-color.js.map +1 -0
  73. package/dist/lib/css/property-descriptors/border-radius.js +18 -0
  74. package/dist/lib/css/property-descriptors/border-radius.js.map +1 -0
  75. package/dist/lib/css/property-descriptors/border-style.js +30 -0
  76. package/dist/lib/css/property-descriptors/border-style.js.map +1 -0
  77. package/dist/lib/css/property-descriptors/border-width.js +21 -0
  78. package/dist/lib/css/property-descriptors/border-width.js.map +1 -0
  79. package/dist/lib/css/property-descriptors/box-shadow.js +55 -0
  80. package/dist/lib/css/property-descriptors/box-shadow.js.map +1 -0
  81. package/dist/lib/css/property-descriptors/color.js +11 -0
  82. package/dist/lib/css/property-descriptors/color.js.map +1 -0
  83. package/dist/lib/css/property-descriptors/content.js +20 -0
  84. package/dist/lib/css/property-descriptors/content.js.map +1 -0
  85. package/dist/lib/css/property-descriptors/counter-increment.js +31 -0
  86. package/dist/lib/css/property-descriptors/counter-increment.js.map +1 -0
  87. package/dist/lib/css/property-descriptors/counter-reset.js +27 -0
  88. package/dist/lib/css/property-descriptors/counter-reset.js.map +1 -0
  89. package/dist/lib/css/property-descriptors/direction.js +19 -0
  90. package/dist/lib/css/property-descriptors/direction.js.map +1 -0
  91. package/dist/lib/css/property-descriptors/display.js +82 -0
  92. package/dist/lib/css/property-descriptors/display.js.map +1 -0
  93. package/dist/lib/css/property-descriptors/duration.js +15 -0
  94. package/dist/lib/css/property-descriptors/duration.js.map +1 -0
  95. package/dist/lib/css/property-descriptors/float.js +23 -0
  96. package/dist/lib/css/property-descriptors/float.js.map +1 -0
  97. package/dist/lib/css/property-descriptors/font-family.js +33 -0
  98. package/dist/lib/css/property-descriptors/font-family.js.map +1 -0
  99. package/dist/lib/css/property-descriptors/font-size.js +11 -0
  100. package/dist/lib/css/property-descriptors/font-size.js.map +1 -0
  101. package/dist/lib/css/property-descriptors/font-style.js +21 -0
  102. package/dist/lib/css/property-descriptors/font-style.js.map +1 -0
  103. package/dist/lib/css/property-descriptors/font-variant.js +14 -0
  104. package/dist/lib/css/property-descriptors/font-variant.js.map +1 -0
  105. package/dist/lib/css/property-descriptors/font-weight.js +26 -0
  106. package/dist/lib/css/property-descriptors/font-weight.js.map +1 -0
  107. package/dist/lib/css/property-descriptors/letter-spacing.js +22 -0
  108. package/dist/lib/css/property-descriptors/letter-spacing.js.map +1 -0
  109. package/dist/lib/css/property-descriptors/line-break.js +24 -0
  110. package/dist/lib/css/property-descriptors/line-break.js.map +1 -0
  111. package/dist/lib/css/property-descriptors/line-height.js +25 -0
  112. package/dist/lib/css/property-descriptors/line-height.js.map +1 -0
  113. package/dist/lib/css/property-descriptors/list-style-image.js +17 -0
  114. package/dist/lib/css/property-descriptors/list-style-image.js.map +1 -0
  115. package/dist/lib/css/property-descriptors/list-style-position.js +19 -0
  116. package/dist/lib/css/property-descriptors/list-style-position.js.map +1 -0
  117. package/dist/lib/css/property-descriptors/list-style-type.js +123 -0
  118. package/dist/lib/css/property-descriptors/list-style-type.js.map +1 -0
  119. package/dist/lib/css/property-descriptors/margin.js +14 -0
  120. package/dist/lib/css/property-descriptors/margin.js.map +1 -0
  121. package/dist/lib/css/property-descriptors/opacity.js +17 -0
  122. package/dist/lib/css/property-descriptors/opacity.js.map +1 -0
  123. package/dist/lib/css/property-descriptors/overflow-wrap.js +19 -0
  124. package/dist/lib/css/property-descriptors/overflow-wrap.js.map +1 -0
  125. package/dist/lib/css/property-descriptors/overflow.js +28 -0
  126. package/dist/lib/css/property-descriptors/overflow.js.map +1 -0
  127. package/dist/lib/css/property-descriptors/padding.js +15 -0
  128. package/dist/lib/css/property-descriptors/padding.js.map +1 -0
  129. package/dist/lib/css/property-descriptors/paint-order.js +34 -0
  130. package/dist/lib/css/property-descriptors/paint-order.js.map +1 -0
  131. package/dist/lib/css/property-descriptors/position.js +23 -0
  132. package/dist/lib/css/property-descriptors/position.js.map +1 -0
  133. package/dist/lib/css/property-descriptors/quotes.js +42 -0
  134. package/dist/lib/css/property-descriptors/quotes.js.map +1 -0
  135. package/dist/lib/css/property-descriptors/text-align.js +22 -0
  136. package/dist/lib/css/property-descriptors/text-align.js.map +1 -0
  137. package/dist/lib/css/property-descriptors/text-decoration-color.js +11 -0
  138. package/dist/lib/css/property-descriptors/text-decoration-color.js.map +1 -0
  139. package/dist/lib/css/property-descriptors/text-decoration-line.js +29 -0
  140. package/dist/lib/css/property-descriptors/text-decoration-line.js.map +1 -0
  141. package/dist/lib/css/property-descriptors/text-shadow.js +47 -0
  142. package/dist/lib/css/property-descriptors/text-shadow.js.map +1 -0
  143. package/dist/lib/css/property-descriptors/text-transform.js +21 -0
  144. package/dist/lib/css/property-descriptors/text-transform.js.map +1 -0
  145. package/dist/lib/css/property-descriptors/transform-origin.js +25 -0
  146. package/dist/lib/css/property-descriptors/transform-origin.js.map +1 -0
  147. package/dist/lib/css/property-descriptors/transform.js +37 -0
  148. package/dist/lib/css/property-descriptors/transform.js.map +1 -0
  149. package/dist/lib/css/property-descriptors/visibility.js +21 -0
  150. package/dist/lib/css/property-descriptors/visibility.js.map +1 -0
  151. package/dist/lib/css/property-descriptors/webkit-text-stroke-color.js +11 -0
  152. package/dist/lib/css/property-descriptors/webkit-text-stroke-color.js.map +1 -0
  153. package/dist/lib/css/property-descriptors/webkit-text-stroke-width.js +17 -0
  154. package/dist/lib/css/property-descriptors/webkit-text-stroke-width.js.map +1 -0
  155. package/dist/lib/css/property-descriptors/word-break.js +27 -0
  156. package/dist/lib/css/property-descriptors/word-break.js.map +1 -0
  157. package/dist/lib/css/property-descriptors/z-index.js +20 -0
  158. package/dist/lib/css/property-descriptors/z-index.js.map +1 -0
  159. package/dist/lib/css/syntax/__tests__/tokernizer-tests.js +34 -0
  160. package/dist/lib/css/syntax/__tests__/tokernizer-tests.js.map +1 -0
  161. package/dist/lib/css/syntax/parser.js +147 -0
  162. package/dist/lib/css/syntax/parser.js.map +1 -0
  163. package/dist/lib/css/syntax/tokenizer.js +630 -0
  164. package/dist/lib/css/syntax/tokenizer.js.map +1 -0
  165. package/dist/lib/css/types/__tests__/color-tests.js +66 -0
  166. package/dist/lib/css/types/__tests__/color-tests.js.map +1 -0
  167. package/dist/lib/css/types/__tests__/image-tests.js +233 -0
  168. package/dist/lib/css/types/__tests__/image-tests.js.map +1 -0
  169. package/dist/lib/css/types/angle.js +81 -0
  170. package/dist/lib/css/types/angle.js.map +1 -0
  171. package/dist/lib/css/types/color.js +311 -0
  172. package/dist/lib/css/types/color.js.map +1 -0
  173. package/dist/lib/css/types/functions/-prefix-linear-gradient.js +33 -0
  174. package/dist/lib/css/types/functions/-prefix-linear-gradient.js.map +1 -0
  175. package/dist/lib/css/types/functions/-prefix-radial-gradient.js +84 -0
  176. package/dist/lib/css/types/functions/-prefix-radial-gradient.js.map +1 -0
  177. package/dist/lib/css/types/functions/-webkit-gradient.js +60 -0
  178. package/dist/lib/css/types/functions/-webkit-gradient.js.map +1 -0
  179. package/dist/lib/css/types/functions/__tests__/radial-gradient.js +68 -0
  180. package/dist/lib/css/types/functions/__tests__/radial-gradient.js.map +1 -0
  181. package/dist/lib/css/types/functions/counter.js +374 -0
  182. package/dist/lib/css/types/functions/counter.js.map +1 -0
  183. package/dist/lib/css/types/functions/gradient.js +165 -0
  184. package/dist/lib/css/types/functions/gradient.js.map +1 -0
  185. package/dist/lib/css/types/functions/linear-gradient.js +28 -0
  186. package/dist/lib/css/types/functions/linear-gradient.js.map +1 -0
  187. package/dist/lib/css/types/functions/radial-gradient.js +91 -0
  188. package/dist/lib/css/types/functions/radial-gradient.js.map +1 -0
  189. package/dist/lib/css/types/image.js +53 -0
  190. package/dist/lib/css/types/image.js.map +1 -0
  191. package/dist/lib/css/types/index.js +3 -0
  192. package/dist/lib/css/types/index.js.map +1 -0
  193. package/dist/lib/css/types/length-percentage.js +52 -0
  194. package/dist/lib/css/types/length-percentage.js.map +1 -0
  195. package/dist/lib/css/types/length.js +8 -0
  196. package/dist/lib/css/types/length.js.map +1 -0
  197. package/dist/lib/css/types/time.js +18 -0
  198. package/dist/lib/css/types/time.js.map +1 -0
  199. package/dist/lib/dom/__mocks__/document-cloner.js +24 -0
  200. package/dist/lib/dom/__mocks__/document-cloner.js.map +1 -0
  201. package/dist/lib/dom/document-cloner.js +530 -0
  202. package/dist/lib/dom/document-cloner.js.map +1 -0
  203. package/dist/lib/dom/element-container.js +37 -0
  204. package/dist/lib/dom/element-container.js.map +1 -0
  205. package/dist/lib/dom/elements/li-element-container.js +30 -0
  206. package/dist/lib/dom/elements/li-element-container.js.map +1 -0
  207. package/dist/lib/dom/elements/ol-element-container.js +31 -0
  208. package/dist/lib/dom/elements/ol-element-container.js.map +1 -0
  209. package/dist/lib/dom/elements/select-element-container.js +31 -0
  210. package/dist/lib/dom/elements/select-element-container.js.map +1 -0
  211. package/dist/lib/dom/elements/textarea-element-container.js +30 -0
  212. package/dist/lib/dom/elements/textarea-element-container.js.map +1 -0
  213. package/dist/lib/dom/node-parser.js +360 -0
  214. package/dist/lib/dom/node-parser.js.map +1 -0
  215. package/dist/lib/dom/replaced-elements/canvas-element-container.js +32 -0
  216. package/dist/lib/dom/replaced-elements/canvas-element-container.js.map +1 -0
  217. package/dist/lib/dom/replaced-elements/iframe-element-container.js +54 -0
  218. package/dist/lib/dom/replaced-elements/iframe-element-container.js.map +1 -0
  219. package/dist/lib/dom/replaced-elements/image-element-container.js +33 -0
  220. package/dist/lib/dom/replaced-elements/image-element-container.js.map +1 -0
  221. package/dist/lib/dom/replaced-elements/index.js +3 -0
  222. package/dist/lib/dom/replaced-elements/index.js.map +1 -0
  223. package/dist/lib/dom/replaced-elements/input-element-container.js +102 -0
  224. package/dist/lib/dom/replaced-elements/input-element-container.js.map +1 -0
  225. package/dist/lib/dom/replaced-elements/pseudo-elements.js +1 -0
  226. package/dist/lib/dom/replaced-elements/pseudo-elements.js.map +1 -0
  227. package/dist/lib/dom/replaced-elements/svg-element-container.js +38 -0
  228. package/dist/lib/dom/replaced-elements/svg-element-container.js.map +1 -0
  229. package/dist/lib/dom/text-container.js +32 -0
  230. package/dist/lib/dom/text-container.js.map +1 -0
  231. package/dist/lib/index.js +202 -0
  232. package/dist/lib/index.js.map +1 -0
  233. package/dist/lib/invariant.js +10 -0
  234. package/dist/lib/invariant.js.map +1 -0
  235. package/dist/lib/render/background.js +187 -0
  236. package/dist/lib/render/background.js.map +1 -0
  237. package/dist/lib/render/bezier-curve.js +36 -0
  238. package/dist/lib/render/bezier-curve.js.map +1 -0
  239. package/dist/lib/render/border.js +105 -0
  240. package/dist/lib/render/border.js.map +1 -0
  241. package/dist/lib/render/bound-curves.js +190 -0
  242. package/dist/lib/render/bound-curves.js.map +1 -0
  243. package/dist/lib/render/box-sizing.js +21 -0
  244. package/dist/lib/render/box-sizing.js.map +1 -0
  245. package/dist/lib/render/canvas/canvas-renderer2.js +1415 -0
  246. package/dist/lib/render/canvas/canvas-renderer2.js.map +1 -0
  247. package/dist/lib/render/canvas/foreignobject-renderer.js +108 -0
  248. package/dist/lib/render/canvas/foreignobject-renderer.js.map +1 -0
  249. package/dist/lib/render/canvas/pdf-renderer.js +1406 -0
  250. package/dist/lib/render/canvas/pdf-renderer.js.map +1 -0
  251. package/dist/lib/render/effects.js +41 -0
  252. package/dist/lib/render/effects.js.map +1 -0
  253. package/dist/lib/render/font-metrics.js +55 -0
  254. package/dist/lib/render/font-metrics.js.map +1 -0
  255. package/dist/lib/render/path.js +27 -0
  256. package/dist/lib/render/path.js.map +1 -0
  257. package/dist/lib/render/renderer.js +12 -0
  258. package/dist/lib/render/renderer.js.map +1 -0
  259. package/dist/lib/render/stacking-context.js +172 -0
  260. package/dist/lib/render/stacking-context.js.map +1 -0
  261. package/dist/lib/render/vector.js +18 -0
  262. package/dist/lib/render/vector.js.map +1 -0
  263. package/dist/render/canvas/pdf-renderer.d.ts +0 -1
  264. package/dist/types/__tests__/index.d.ts +1 -0
  265. package/dist/types/core/__mocks__/cache-storage.d.ts +2 -0
  266. package/dist/types/core/__mocks__/context.d.ts +9 -0
  267. package/dist/types/core/__mocks__/features.d.ts +8 -0
  268. package/dist/types/core/__mocks__/logger.d.ts +9 -0
  269. package/dist/types/core/__tests__/cache-storage.d.ts +1 -0
  270. package/dist/types/core/__tests__/logger.d.ts +1 -0
  271. package/dist/types/core/bitwise.d.ts +1 -0
  272. package/dist/types/core/cache-storage.d.ts +26 -0
  273. package/dist/types/core/context.d.ts +15 -0
  274. package/dist/types/core/debugger.d.ts +8 -0
  275. package/dist/types/core/features.d.ts +12 -0
  276. package/dist/types/core/logger.d.ts +18 -0
  277. package/dist/types/core/util.d.ts +1 -0
  278. package/dist/types/css/IPropertyDescriptor.d.ts +36 -0
  279. package/dist/types/css/ITypeDescriptor.d.ts +6 -0
  280. package/dist/types/css/index.d.ts +132 -0
  281. package/dist/types/css/layout/__mocks__/bounds.d.ts +2 -0
  282. package/dist/types/css/layout/bounds.d.ts +14 -0
  283. package/dist/types/css/layout/text.d.ts +10 -0
  284. package/dist/types/css/property-descriptors/__tests__/background-tests.d.ts +1 -0
  285. package/dist/types/css/property-descriptors/__tests__/font-family.d.ts +1 -0
  286. package/dist/types/css/property-descriptors/__tests__/paint-order.d.ts +1 -0
  287. package/dist/types/css/property-descriptors/__tests__/text-shadow.d.ts +1 -0
  288. package/dist/types/css/property-descriptors/__tests__/transform-tests.d.ts +1 -0
  289. package/dist/types/css/property-descriptors/background-clip.d.ts +8 -0
  290. package/dist/types/css/property-descriptors/background-color.d.ts +2 -0
  291. package/dist/types/css/property-descriptors/background-image.d.ts +3 -0
  292. package/dist/types/css/property-descriptors/background-origin.d.ts +8 -0
  293. package/dist/types/css/property-descriptors/background-position.d.ts +5 -0
  294. package/dist/types/css/property-descriptors/background-repeat.d.ts +9 -0
  295. package/dist/types/css/property-descriptors/background-size.d.ts +11 -0
  296. package/dist/types/css/property-descriptors/border-color.d.ts +5 -0
  297. package/dist/types/css/property-descriptors/border-radius.d.ts +7 -0
  298. package/dist/types/css/property-descriptors/border-style.d.ts +12 -0
  299. package/dist/types/css/property-descriptors/border-width.d.ts +5 -0
  300. package/dist/types/css/property-descriptors/box-shadow.d.ts +14 -0
  301. package/dist/types/css/property-descriptors/color.d.ts +2 -0
  302. package/dist/types/css/property-descriptors/content.d.ts +4 -0
  303. package/dist/types/css/property-descriptors/counter-increment.d.ts +7 -0
  304. package/dist/types/css/property-descriptors/counter-reset.d.ts +7 -0
  305. package/dist/types/css/property-descriptors/direction.d.ts +6 -0
  306. package/dist/types/css/property-descriptors/display.d.ts +35 -0
  307. package/dist/types/css/property-descriptors/duration.d.ts +2 -0
  308. package/dist/types/css/property-descriptors/float.d.ts +9 -0
  309. package/dist/types/css/property-descriptors/font-family.d.ts +4 -0
  310. package/dist/types/css/property-descriptors/font-size.d.ts +2 -0
  311. package/dist/types/css/property-descriptors/font-style.d.ts +7 -0
  312. package/dist/types/css/property-descriptors/font-variant.d.ts +2 -0
  313. package/dist/types/css/property-descriptors/font-weight.d.ts +2 -0
  314. package/dist/types/css/property-descriptors/letter-spacing.d.ts +2 -0
  315. package/dist/types/css/property-descriptors/line-break.d.ts +6 -0
  316. package/dist/types/css/property-descriptors/line-height.d.ts +4 -0
  317. package/dist/types/css/property-descriptors/list-style-image.d.ts +3 -0
  318. package/dist/types/css/property-descriptors/list-style-position.d.ts +6 -0
  319. package/dist/types/css/property-descriptors/list-style-type.d.ts +58 -0
  320. package/dist/types/css/property-descriptors/margin.d.ts +5 -0
  321. package/dist/types/css/property-descriptors/opacity.d.ts +2 -0
  322. package/dist/types/css/property-descriptors/overflow-wrap.d.ts +6 -0
  323. package/dist/types/css/property-descriptors/overflow.d.ts +9 -0
  324. package/dist/types/css/property-descriptors/padding.d.ts +5 -0
  325. package/dist/types/css/property-descriptors/paint-order.d.ts +8 -0
  326. package/dist/types/css/property-descriptors/position.d.ts +9 -0
  327. package/dist/types/css/property-descriptors/quotes.d.ts +8 -0
  328. package/dist/types/css/property-descriptors/text-align.d.ts +7 -0
  329. package/dist/types/css/property-descriptors/text-decoration-color.d.ts +2 -0
  330. package/dist/types/css/property-descriptors/text-decoration-line.d.ts +10 -0
  331. package/dist/types/css/property-descriptors/text-shadow.d.ts +12 -0
  332. package/dist/types/css/property-descriptors/text-transform.d.ts +8 -0
  333. package/dist/types/css/property-descriptors/transform-origin.d.ts +4 -0
  334. package/dist/types/css/property-descriptors/transform.d.ts +4 -0
  335. package/dist/types/css/property-descriptors/visibility.d.ts +7 -0
  336. package/dist/types/css/property-descriptors/webkit-text-stroke-color.d.ts +2 -0
  337. package/dist/types/css/property-descriptors/webkit-text-stroke-width.d.ts +2 -0
  338. package/dist/types/css/property-descriptors/word-break.d.ts +7 -0
  339. package/dist/types/css/property-descriptors/z-index.d.ts +7 -0
  340. package/dist/types/css/syntax/__tests__/tokernizer-tests.d.ts +1 -0
  341. package/dist/types/css/syntax/parser.d.ts +34 -0
  342. package/dist/types/css/syntax/tokenizer.d.ts +94 -0
  343. package/dist/types/css/types/__tests__/color-tests.d.ts +1 -0
  344. package/dist/types/css/types/__tests__/image-tests.d.ts +1 -0
  345. package/dist/types/css/types/angle.d.ts +7 -0
  346. package/dist/types/css/types/color.d.ts +11 -0
  347. package/dist/types/css/types/functions/-prefix-linear-gradient.d.ts +4 -0
  348. package/dist/types/css/types/functions/-prefix-radial-gradient.d.ts +4 -0
  349. package/dist/types/css/types/functions/-webkit-gradient.d.ts +4 -0
  350. package/dist/types/css/types/functions/__tests__/radial-gradient.d.ts +1 -0
  351. package/dist/types/css/types/functions/counter.d.ts +10 -0
  352. package/dist/types/css/types/functions/gradient.d.ts +7 -0
  353. package/dist/types/css/types/functions/linear-gradient.d.ts +4 -0
  354. package/dist/types/css/types/functions/radial-gradient.d.ts +12 -0
  355. package/dist/types/css/types/image.d.ts +54 -0
  356. package/dist/types/css/types/index.d.ts +1 -0
  357. package/dist/types/css/types/length-percentage.d.ts +11 -0
  358. package/dist/types/css/types/length.d.ts +4 -0
  359. package/dist/types/css/types/time.d.ts +2 -0
  360. package/dist/types/dom/__mocks__/document-cloner.d.ts +6 -0
  361. package/dist/types/dom/document-cloner.d.ts +45 -0
  362. package/dist/types/dom/element-container.d.ts +21 -0
  363. package/dist/types/dom/elements/li-element-container.d.ts +6 -0
  364. package/dist/types/dom/elements/ol-element-container.d.ts +7 -0
  365. package/dist/types/dom/elements/select-element-container.d.ts +6 -0
  366. package/dist/types/dom/elements/textarea-element-container.d.ts +6 -0
  367. package/dist/types/dom/node-parser.d.ts +23 -0
  368. package/dist/types/dom/replaced-elements/canvas-element-container.d.ts +8 -0
  369. package/dist/types/dom/replaced-elements/iframe-element-container.d.ts +11 -0
  370. package/dist/types/dom/replaced-elements/image-element-container.d.ts +8 -0
  371. package/dist/types/dom/replaced-elements/index.d.ts +4 -0
  372. package/dist/types/dom/replaced-elements/input-element-container.d.ts +12 -0
  373. package/dist/types/dom/replaced-elements/pseudo-elements.d.ts +0 -0
  374. package/dist/types/dom/replaced-elements/svg-element-container.d.ts +8 -0
  375. package/dist/types/dom/text-container.d.ts +8 -0
  376. package/dist/types/index.d.ts +18 -0
  377. package/dist/types/invariant.d.ts +1 -0
  378. package/dist/types/render/background.d.ts +16 -0
  379. package/dist/types/render/bezier-curve.d.ts +14 -0
  380. package/dist/types/render/border.d.ts +6 -0
  381. package/dist/types/render/bound-curves.d.ts +32 -0
  382. package/dist/types/render/box-sizing.d.ts +4 -0
  383. package/dist/types/render/canvas/canvas-renderer2.d.ts +81 -0
  384. package/dist/types/render/canvas/foreignobject-renderer.d.ts +11 -0
  385. package/dist/types/render/canvas/pdf-renderer.d.ts +80 -0
  386. package/dist/types/render/effects.d.ts +38 -0
  387. package/dist/types/render/font-metrics.d.ts +11 -0
  388. package/dist/types/render/path.d.ts +13 -0
  389. package/dist/types/render/renderer.d.ts +7 -0
  390. package/dist/types/render/stacking-context.d.ts +24 -0
  391. package/dist/types/render/vector.d.ts +9 -0
  392. package/package.json +1 -1
@@ -0,0 +1,1406 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.CanvasRenderer = void 0;
55
+ var jspdf_1 = require("jspdf"); // 用于生成PDF文档
56
+ // import "../../SourceHanSansSC-Normal-Min-normal"; // 导入思源黑体
57
+ // import "../../SourceHanSansCN-Medium-normal"; // 导入阿里巴巴普惠体字体
58
+ var bitwise_1 = require("../../core/bitwise"); // 位运算工具函数
59
+ var bounds_1 = require("../../css/layout/bounds"); // 边界计算
60
+ var text_1 = require("../../css/layout/text"); // 文本分段和边界
61
+ var line_height_1 = require("../../css/property-descriptors/line-height"); // 行高计算
62
+ // import { TextShadow } from '../../css/property-descriptors/text-shadow'; // 文本阴影
63
+ var parser_1 = require("../../css/syntax/parser"); // 维度标记判断
64
+ var color_1 = require("../../css/types/color"); // 颜色相关工具
65
+ // import { calculateGradientDirection, calculateRadius, processColorStops } from '../../css/types/functions/gradient'; // 渐变计算
66
+ var image_1 = require("../../css/types/image"); // 图片类型
67
+ var length_percentage_1 = require("../../css/types/length-percentage"); // 长度百分比FIFTY_PERCENT,
68
+ var select_element_container_1 = require("../../dom/elements/select-element-container"); // Select元素容器
69
+ var textarea_element_container_1 = require("../../dom/elements/textarea-element-container"); // Textarea元素容器
70
+ var canvas_element_container_1 = require("../../dom/replaced-elements/canvas-element-container"); // Canvas元素容器
71
+ var iframe_element_container_1 = require("../../dom/replaced-elements/iframe-element-container"); // IFrame元素容器
72
+ var image_element_container_1 = require("../../dom/replaced-elements/image-element-container"); // Image元素容器
73
+ var input_element_container_1 = require("../../dom/replaced-elements/input-element-container"); // Input元素容器
74
+ var svg_element_container_1 = require("../../dom/replaced-elements/svg-element-container"); // SVG元素容器
75
+ var background_1 = require("../background"); // 背景渲染计算
76
+ var bezier_curve_1 = require("../bezier-curve"); // 贝塞尔曲线
77
+ var border_1 = require("../border"); // 边框路径解析
78
+ var bound_curves_1 = require("../bound-curves"); // 边界曲线计算
79
+ var box_sizing_1 = require("../box-sizing"); // 内容盒模型
80
+ var effects_1 = require("../effects"); // 效果相关
81
+ var font_metrics_1 = require("../font-metrics"); // 字体度量
82
+ var renderer_1 = require("../renderer"); // 渲染器基类
83
+ var stacking_context_1 = require("../stacking-context"); // 堆叠上下文
84
+ var vector_1 = require("../vector"); // 向量
85
+ // 遮罩偏移常量
86
+ // const MASK_OFFSET = 10000;
87
+ // Canvas渲染器类,继承自Renderer
88
+ var CanvasRenderer = /** @class */ (function (_super) {
89
+ __extends(CanvasRenderer, _super);
90
+ // 构造函数
91
+ function CanvasRenderer(context, options) {
92
+ var _this = this;
93
+ console.log('options参数', options, context);
94
+ _this = _super.call(this, context, options) || this;
95
+ _this._activeEffects = []; // 活动效果数组
96
+ _this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
97
+ _this.ctx = _this.canvas.getContext('2d');
98
+ // 计算页面尺寸并转换为 pt 单位 (1pt = 1/72 inch, 1px = 1/96 inch)
99
+ var pxToPt = function (px) { return px * (72 / 96); };
100
+ //
101
+ var pageWidth = pxToPt(options.width);
102
+ var pageHeight = pxToPt(options.height);
103
+ // 初始化 jsPDF
104
+ _this.jspdfCtx = new jspdf_1.jsPDF({
105
+ orientation: pageWidth > pageHeight ? 'landscape' : 'portrait',
106
+ unit: 'pt',
107
+ format: [pageWidth, pageHeight],
108
+ hotfixes: ["px_scaling"]
109
+ });
110
+ // 设置PDF文件的保存方式
111
+ _this.context2dCtx = _this.jspdfCtx.context2d;
112
+ _this.context2dCtx.scale(0.75, 0.75);
113
+ _this.context2dCtx.translate(-options.x, -options.y);
114
+ // 确保字体已加载并注册到 jsPDF
115
+ if (options.fontConfig) {
116
+ try {
117
+ _this.loadFont();
118
+ }
119
+ catch (error) {
120
+ console.warn('Failed to set font:', error);
121
+ // 如果设置失败,使用默认字体
122
+ _this.jspdfCtx.setFont('Helvetica');
123
+ }
124
+ }
125
+ // this.jspdfCtx.setFont('SourceHanSansSC-Normal-Min');
126
+ // 将 pxToPt 保存为实例属性,以便其他方法使用
127
+ _this.pxToPt = pxToPt;
128
+ if (!options.canvas) {
129
+ _this.canvas.width = 10;
130
+ _this.canvas.height = 10;
131
+ _this.canvas.style.width = "10px";
132
+ _this.canvas.style.height = "10px";
133
+ }
134
+ _this.fontMetrics = new font_metrics_1.FontMetrics(document);
135
+ // this.ctx.scale(this.options.scale, this.options.scale);
136
+ // this.ctx.translate(-options.x, -options.y);
137
+ // this.ctx.textBaseline = 'bottom';
138
+ _this.context2dCtx.textBaseline = 'bottom';
139
+ _this._activeEffects = [];
140
+ _this.context.logger.debug("Canvas renderer initialized (".concat(options.width, "x").concat(options.height, ") with scale ").concat(options.scale));
141
+ return _this;
142
+ }
143
+ CanvasRenderer.prototype.loadFont = function () {
144
+ return __awaiter(this, void 0, void 0, function () {
145
+ var fontData;
146
+ return __generator(this, function (_a) {
147
+ switch (_a.label) {
148
+ case 0:
149
+ if (!this.options.fontConfig.fontBase64) return [3 /*break*/, 1];
150
+ // 直接使用 Base64 编码
151
+ fontData = this.options.fontConfig.fontBase64;
152
+ return [3 /*break*/, 3];
153
+ case 1:
154
+ if (!this.options.fontConfig.fontUrl) return [3 /*break*/, 3];
155
+ return [4 /*yield*/, this.loadFontFromURL(this.options.fontConfig.fontUrl)];
156
+ case 2:
157
+ fontData = _a.sent();
158
+ _a.label = 3;
159
+ case 3:
160
+ // console.log('fontData',fontData)
161
+ // 将字体添加到 jsPDF
162
+ this.addFontToJsPDF(fontData);
163
+ return [2 /*return*/];
164
+ }
165
+ });
166
+ });
167
+ };
168
+ CanvasRenderer.prototype.loadFontFromURL = function (url) {
169
+ return __awaiter(this, void 0, void 0, function () {
170
+ var response, blob;
171
+ return __generator(this, function (_a) {
172
+ switch (_a.label) {
173
+ case 0: return [4 /*yield*/, fetch(url, {
174
+ mode: 'no-cors',
175
+ headers: {
176
+ 'Content-Type': 'font/ttf'
177
+ }
178
+ })];
179
+ case 1:
180
+ response = _a.sent();
181
+ return [4 /*yield*/, response.blob()];
182
+ case 2:
183
+ blob = _a.sent();
184
+ // const fontUrl = URL.createObjectURL(blob);
185
+ // console.log('response', blob, fontUrl)
186
+ // 注意:no-cors 模式下无法读取响应内容!
187
+ // const blob = await response.blob();
188
+ return [2 /*return*/, new Promise(function (resolve, reject) {
189
+ var reader = new FileReader();
190
+ reader.onload = function () { return resolve(reader.result.split(',')[1]); }; // 提取 Base64 数据
191
+ reader.onerror = function () { return reject(new Error('字体文件读取失败')); };
192
+ reader.readAsDataURL(blob);
193
+ })];
194
+ }
195
+ });
196
+ });
197
+ };
198
+ CanvasRenderer.prototype.addFontToJsPDF = function (fontData) {
199
+ var _a = this.options.fontConfig, fontFamily = _a.fontFamily, fontWeight = _a.fontWeight, fontStyle = _a.fontStyle;
200
+ if (!fontFamily) {
201
+ return;
202
+ }
203
+ this.jspdfCtx.addFileToVFS("".concat(fontFamily, ".ttf"), fontData); // 将字体添加到虚拟文件系统
204
+ this.jspdfCtx.addFont("".concat(fontFamily, ".ttf"), fontFamily, fontStyle, fontWeight); // 注册字体
205
+ this.jspdfCtx.setFont(fontFamily); // 设置当前字体
206
+ };
207
+ // 应用效果数组
208
+ CanvasRenderer.prototype.applyEffects = function (effects) {
209
+ var _this = this;
210
+ while (this._activeEffects.length) {
211
+ this.popEffect();
212
+ }
213
+ effects.forEach(function (effect) { return _this.applyEffect(effect); });
214
+ };
215
+ // 应用单个效果
216
+ CanvasRenderer.prototype.applyEffect = function (effect) {
217
+ this.ctx.save();
218
+ // this.context2dCtx.save()
219
+ if ((0, effects_1.isOpacityEffect)(effect)) {
220
+ this.ctx.globalAlpha = effect.opacity;
221
+ // this.context2dCtx.globalAlpha = effect.opacity
222
+ }
223
+ if ((0, effects_1.isTransformEffect)(effect)) {
224
+ this.ctx.translate(effect.offsetX, effect.offsetY);
225
+ this.ctx.transform(effect.matrix[0], effect.matrix[1], effect.matrix[2], effect.matrix[3], effect.matrix[4], effect.matrix[5]);
226
+ this.ctx.translate(-effect.offsetX, -effect.offsetY);
227
+ // this.context2dCtx.translate(effect.offsetX, effect.offsetY);
228
+ // this.context2dCtx.transform(
229
+ // effect.matrix[0],
230
+ // effect.matrix[1],
231
+ // effect.matrix[2],
232
+ // effect.matrix[3],
233
+ // effect.matrix[4],
234
+ // effect.matrix[5]
235
+ // );
236
+ // this.context2dCtx.translate(-effect.offsetX, -effect.offsetY);
237
+ }
238
+ if ((0, effects_1.isClipEffect)(effect)) {
239
+ this.path(effect.path);
240
+ this.ctx.clip();
241
+ // this.context2dCtx.clip()
242
+ }
243
+ this._activeEffects.push(effect);
244
+ };
245
+ // 移除最后应用的效果
246
+ CanvasRenderer.prototype.popEffect = function () {
247
+ this._activeEffects.pop();
248
+ // this.ctx.restore();
249
+ this.context2dCtx.restore();
250
+ if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
251
+ this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
252
+ }
253
+ };
254
+ // 渲染堆叠上下文
255
+ CanvasRenderer.prototype.renderStack = function (stack) {
256
+ return __awaiter(this, void 0, void 0, function () {
257
+ var styles;
258
+ return __generator(this, function (_a) {
259
+ switch (_a.label) {
260
+ case 0:
261
+ styles = stack.element.container.styles;
262
+ if (!styles.isVisible()) return [3 /*break*/, 2];
263
+ return [4 /*yield*/, this.renderStackContent(stack)];
264
+ case 1:
265
+ _a.sent();
266
+ return [3 /*break*/, 2];
267
+ case 2: return [2 /*return*/];
268
+ }
269
+ });
270
+ });
271
+ };
272
+ // 渲染节点
273
+ CanvasRenderer.prototype.renderNode = function (paint) {
274
+ return __awaiter(this, void 0, void 0, function () {
275
+ return __generator(this, function (_a) {
276
+ switch (_a.label) {
277
+ case 0:
278
+ if ((0, bitwise_1.contains)(paint.container.flags, 16 /* FLAGS.DEBUG_RENDER */)) {
279
+ debugger;
280
+ }
281
+ if (!paint.container.styles.isVisible()) return [3 /*break*/, 3];
282
+ return [4 /*yield*/, this.renderNodeBackgroundAndBorders(paint)];
283
+ case 1:
284
+ _a.sent();
285
+ return [4 /*yield*/, this.renderNodeContent(paint)];
286
+ case 2:
287
+ _a.sent();
288
+ _a.label = 3;
289
+ case 3: return [2 /*return*/];
290
+ }
291
+ });
292
+ });
293
+ };
294
+ // 渲染带有字母间距的文本
295
+ CanvasRenderer.prototype.renderTextWithLetterSpacing = function (text, letterSpacing, baseline) {
296
+ var _this = this;
297
+ if (letterSpacing === 0) {
298
+ // console.log(text.text, text.bounds.left,'绘制文字-没有letterSpacing')
299
+ // this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
300
+ this.context2dCtx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
301
+ }
302
+ else {
303
+ var letters = (0, text_1.segmentGraphemes)(text.text);
304
+ letters.reduce(function (left, letter) {
305
+ // console.log(left, letter,'绘制文字')
306
+ // this.ctx.fillText(letter, left, text.bounds.top + baseline);
307
+ // this.context2dCtx.fillText(letter, left - leftMargin, text.bounds.top + baseline - topMargin);
308
+ // 使用jspdf绘制文字
309
+ _this.context2dCtx.fillText(letter, left, text.bounds.top + baseline);
310
+ return left + _this.ctx.measureText(letter).width;
311
+ }, text.bounds.left);
312
+ }
313
+ };
314
+ // 创建字体样式
315
+ CanvasRenderer.prototype.createFontStyle = function (styles) {
316
+ var fontVariant = styles.fontVariant
317
+ .filter(function (variant) { return variant === 'normal' || variant === 'small-caps'; })
318
+ .join('');
319
+ var fontFamily = fixIOSSystemFonts(styles.fontFamily).join(', ');
320
+ var fontSize = (0, parser_1.isDimensionToken)(styles.fontSize)
321
+ ? "".concat(styles.fontSize.number).concat(styles.fontSize.unit)
322
+ : "".concat(styles.fontSize.number, "px");
323
+ return [
324
+ [styles.fontStyle, fontVariant, styles.fontWeight, fontSize, fontFamily].join(' '),
325
+ fontFamily,
326
+ fontSize
327
+ ];
328
+ };
329
+ // 添加一个新的颜色转换函数
330
+ CanvasRenderer.prototype.convertColor = function (color) {
331
+ // 如果是透明色,返回白色
332
+ if ((0, color_1.isTransparent)(color)) {
333
+ return '#FFFFFF';
334
+ }
335
+ // 将 rgba 转换为 rgb
336
+ // 从32位整数中提取RGB分量
337
+ var r = 0xff & (color >> 24);
338
+ var g = 0xff & (color >> 16);
339
+ var b = 0xff & (color >> 8);
340
+ return "#".concat(r.toString(16).padStart(2, '0')).concat(g.toString(16).padStart(2, '0')).concat(b.toString(16).padStart(2, '0'));
341
+ // 其他颜色格式直接使用 asString
342
+ return (0, color_1.asString)(color);
343
+ };
344
+ CanvasRenderer.prototype.renderTextNode = function (text, styles) {
345
+ return __awaiter(this, void 0, void 0, function () {
346
+ var _a, font, fontFamily, fontSize, fontSizePt, _b, baseline, middle, paintOrder;
347
+ var _this = this;
348
+ return __generator(this, function (_c) {
349
+ _a = this.createFontStyle(styles), font = _a[0], fontFamily = _a[1], fontSize = _a[2];
350
+ // ,
351
+ // 设置 CanvasRenderingContext2D 的字体样式
352
+ this.ctx.font = font;
353
+ // 设置 jsPDF context2d 的字体样式 (如果需要,jsPDF 通常会自动同步)
354
+ this.context2dCtx.font = this.options.fontConfig.fontFamily; // 通常不需要显式设置,jsPDF 会处理
355
+ this.ctx.direction = styles.direction === 1 /* DIRECTION.RTL */ ? 'rtl' : 'ltr';
356
+ this.context2dCtx.direction = styles.direction === 1 /* DIRECTION.RTL */ ? 'rtl' : 'ltr'; // 根据 jsPDF API 调整
357
+ this.ctx.textAlign = 'left';
358
+ this.context2dCtx.textAlign = 'left'; // 根据 jsPDF API 调整
359
+ fontSizePt = styles.fontSize.number;
360
+ this.jspdfCtx.setFontSize(fontSizePt);
361
+ _b = this.fontMetrics.getMetrics(fontFamily, fontSize), baseline = _b.baseline, middle = _b.middle;
362
+ paintOrder = styles.paintOrder;
363
+ text.textBounds.forEach(function (textItem) {
364
+ paintOrder.forEach(function (paintOrderLayer) {
365
+ switch (paintOrderLayer) {
366
+ case 0 /* PAINT_ORDER_LAYER.FILL */:
367
+ // 设置 CanvasRenderingContext2D 的填充样式
368
+ // this.ctx.fillStyle = asString(styles.color);
369
+ // 设置 jsPDF context2d 的填充样式
370
+ _this.context2dCtx.fillStyle = (0, color_1.asString)(styles.color);
371
+ _this.renderTextWithLetterSpacing(textItem, styles.letterSpacing, baseline);
372
+ if (styles.textDecorationLine.length) {
373
+ // 设置 CanvasRenderingContext2D 的填充样式
374
+ // this.ctx.fillStyle = asString(styles.textDecorationColor || styles.color);
375
+ // 设置 jsPDF context2d 的填充样式
376
+ _this.context2dCtx.fillStyle = (0, color_1.asString)(styles.textDecorationColor || styles.color);
377
+ styles.textDecorationLine.forEach(function (textDecorationLine) {
378
+ var x = textItem.bounds.left;
379
+ var width = textItem.bounds.width;
380
+ var y_underline = Math.round(textItem.bounds.top + baseline);
381
+ var y_overline = Math.round(textItem.bounds.top);
382
+ var y_line_through = Math.ceil(textItem.bounds.top + middle);
383
+ var thickness = 1; // 装饰线的粗细,可以根据需要调整
384
+ switch (textDecorationLine) {
385
+ case 1 /* TEXT_DECORATION_LINE.UNDERLINE */:
386
+ // this.ctx.fillRect(x, y_underline, width, thickness);
387
+ _this.context2dCtx.fillRect(x, y_underline, width, thickness);
388
+ break;
389
+ case 2 /* TEXT_DECORATION_LINE.OVERLINE */:
390
+ // this.ctx.fillRect(x, y_overline, width, thickness);
391
+ _this.context2dCtx.fillRect(x, y_overline, width, thickness);
392
+ break;
393
+ case 3 /* TEXT_DECORATION_LINE.LINE_THROUGH */:
394
+ // this.ctx.fillRect(x, y_line_through, width, thickness);
395
+ _this.context2dCtx.fillRect(x, y_line_through, width, thickness);
396
+ break;
397
+ }
398
+ });
399
+ }
400
+ break;
401
+ case 1 /* PAINT_ORDER_LAYER.STROKE */:
402
+ if (styles.webkitTextStrokeWidth && textItem.text.trim().length) {
403
+ // 设置 CanvasRenderingContext2D 的描边样式
404
+ // this.ctx.strokeStyle = asString(styles.webkitTextStrokeColor);
405
+ // this.ctx.lineWidth = styles.webkitTextStrokeWidth;
406
+ // this.ctx.lineJoin = !!(window as any).chrome ? 'miter' : 'round';
407
+ // 设置 jsPDF context2d 的描边样式
408
+ _this.context2dCtx.strokeStyle = (0, color_1.asString)(styles.webkitTextStrokeColor);
409
+ _this.context2dCtx.lineWidth = styles.webkitTextStrokeWidth;
410
+ // this.context2dCtx.lineJoin = ...; // 根据 jsPDF API 调整
411
+ // CanvasRenderingContext2D 描边
412
+ // this.ctx.strokeText(textItem.text, textItem.bounds.left, textItem.bounds.top + baseline);
413
+ // jsPDF context2d 描边
414
+ _this.context2dCtx.strokeText(textItem.text, textItem.bounds.left, textItem.bounds.top + baseline);
415
+ }
416
+ // 清除 CanvasRenderingContext2D 的描边样式
417
+ // this.ctx.strokeStyle = '';
418
+ // this.ctx.lineWidth = 0;
419
+ // this.ctx.lineJoin = 'miter';
420
+ // 清除 jsPDF context2d 的描边样式
421
+ _this.context2dCtx.strokeStyle = '';
422
+ _this.context2dCtx.lineWidth = 0;
423
+ _this.context2dCtx.lineJoin = 'miter';
424
+ break;
425
+ }
426
+ });
427
+ });
428
+ return [2 /*return*/];
429
+ });
430
+ });
431
+ };
432
+ CanvasRenderer.prototype.renderReplacedElement = function (container, curves, image) {
433
+ if (image && container.intrinsicWidth > 0 && container.intrinsicHeight > 0) {
434
+ var box = (0, box_sizing_1.contentBox)(container);
435
+ var path = (0, bound_curves_1.calculatePaddingBoxPath)(curves);
436
+ this.path(path);
437
+ this.ctx.save();
438
+ this.ctx.clip();
439
+ this.ctx.drawImage(image, 0, 0, container.intrinsicWidth, container.intrinsicHeight, box.left, box.top, box.width, box.height);
440
+ this.ctx.restore();
441
+ // this.context2dCtx.save();
442
+ // this.context2dCtx.clip();
443
+ // this.context2dCtx.drawImage(
444
+ // image,
445
+ // 0,
446
+ // 0,
447
+ // container.intrinsicWidth,
448
+ // container.intrinsicHeight,
449
+ // box.left,
450
+ // box.top,
451
+ // box.width,
452
+ // box.height
453
+ // );
454
+ // this.context2dCtx.restore();
455
+ }
456
+ };
457
+ // 渲染节点内容
458
+ // 渲染节点内容的异步方法
459
+ CanvasRenderer.prototype.renderNodeContent = function (paint) {
460
+ return __awaiter(this, void 0, void 0, function () {
461
+ var container, curves, styles, _i, _a, child, image, bounds, x, y, width, height, e_1, bounds, x, y, width, height, dataURL, image, bounds, x, y, width, height, canvas, ctx, dataURL, e_2, iframeRenderer, canvas, size, _b, fontFamily, fontSize, baseline, bounds, x, textBounds, img, image, url, e_3, fontFamily, bounds;
462
+ return __generator(this, function (_c) {
463
+ switch (_c.label) {
464
+ case 0:
465
+ // 应用内容效果
466
+ this.applyEffects(paint.getEffects(4 /* EffectTarget.CONTENT */));
467
+ container = paint.container;
468
+ curves = paint.curves;
469
+ styles = container.styles;
470
+ _i = 0, _a = container.textNodes;
471
+ _c.label = 1;
472
+ case 1:
473
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
474
+ child = _a[_i];
475
+ return [4 /*yield*/, this.renderTextNode(child, styles)];
476
+ case 2:
477
+ _c.sent();
478
+ _c.label = 3;
479
+ case 3:
480
+ _i++;
481
+ return [3 /*break*/, 1];
482
+ case 4:
483
+ if (!(container instanceof image_element_container_1.ImageElementContainer)) return [3 /*break*/, 8];
484
+ _c.label = 5;
485
+ case 5:
486
+ _c.trys.push([5, 7, , 8]);
487
+ return [4 /*yield*/, this.context.cache.match(container.src)];
488
+ case 6:
489
+ image = _c.sent();
490
+ // 渲染到 Canvas
491
+ this.renderReplacedElement(container, curves, image);
492
+ // 添加到 PDF
493
+ try {
494
+ bounds = (0, box_sizing_1.contentBox)(container);
495
+ x = this.pxToPt(bounds.left - this.options.x);
496
+ y = this.pxToPt(bounds.top - this.options.y);
497
+ width = this.pxToPt(bounds.width);
498
+ height = this.pxToPt(bounds.height);
499
+ // 将图片添加到 PDF
500
+ this.jspdfCtx.addImage(image, 'JPEG', // 默认使用 JPEG 格式
501
+ x, y, width, height);
502
+ }
503
+ catch (err) {
504
+ this.context.logger.error("Error adding image to PDF: ".concat(err));
505
+ }
506
+ return [3 /*break*/, 8];
507
+ case 7:
508
+ e_1 = _c.sent();
509
+ this.context.logger.error("Error loading image ".concat(container));
510
+ return [3 /*break*/, 8];
511
+ case 8:
512
+ if (container instanceof canvas_element_container_1.CanvasElementContainer) {
513
+ // 渲染到 Canvas
514
+ this.renderReplacedElement(container, curves, container.canvas);
515
+ // 添加到 PDF
516
+ try {
517
+ bounds = (0, box_sizing_1.contentBox)(container);
518
+ x = this.pxToPt(bounds.left - this.options.x);
519
+ y = this.pxToPt(bounds.top - this.options.y);
520
+ width = this.pxToPt(bounds.width);
521
+ height = this.pxToPt(bounds.height);
522
+ dataURL = container.canvas.toDataURL('image/png', 0.95);
523
+ // 将 Canvas 添加到 PDF
524
+ this.jspdfCtx.addImage(dataURL, 'PNG', x, y, width, height);
525
+ }
526
+ catch (err) {
527
+ this.context.logger.error("Error adding canvas to PDF: ".concat(err));
528
+ }
529
+ }
530
+ if (!(container instanceof svg_element_container_1.SVGElementContainer)) return [3 /*break*/, 12];
531
+ _c.label = 9;
532
+ case 9:
533
+ _c.trys.push([9, 11, , 12]);
534
+ return [4 /*yield*/, this.context.cache.match(container.svg)];
535
+ case 10:
536
+ image = _c.sent();
537
+ // 渲染到 Canvas
538
+ this.renderReplacedElement(container, curves, image);
539
+ // 添加到 PDF
540
+ try {
541
+ bounds = (0, box_sizing_1.contentBox)(container);
542
+ x = this.pxToPt(bounds.left - this.options.x);
543
+ y = this.pxToPt(bounds.top - this.options.y);
544
+ width = this.pxToPt(bounds.width);
545
+ height = this.pxToPt(bounds.height);
546
+ canvas = document.createElement('canvas');
547
+ canvas.width = container.intrinsicWidth || image.width;
548
+ canvas.height = container.intrinsicHeight || image.height;
549
+ ctx = canvas.getContext('2d');
550
+ if (ctx) {
551
+ // 设置白色背景或保持透明
552
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
553
+ // 绘制SVG图像
554
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
555
+ dataURL = canvas.toDataURL('image/png');
556
+ // 将 SVG 添加到 PDF
557
+ this.jspdfCtx.addImage(dataURL, 'PNG', x, y, width, height);
558
+ }
559
+ }
560
+ catch (err) {
561
+ this.context.logger.error("Error adding SVG to PDF: ".concat(err));
562
+ }
563
+ return [3 /*break*/, 12];
564
+ case 11:
565
+ e_2 = _c.sent();
566
+ this.context.logger.error("Error loading svg ".concat(e_2));
567
+ return [3 /*break*/, 12];
568
+ case 12:
569
+ if (!(container instanceof iframe_element_container_1.IFrameElementContainer && container.tree)) return [3 /*break*/, 14];
570
+ iframeRenderer = new CanvasRenderer(this.context, {
571
+ scale: this.options.scale,
572
+ fontConfig: this.options.fontConfig,
573
+ backgroundColor: container.backgroundColor,
574
+ x: 0,
575
+ y: 0,
576
+ width: container.width,
577
+ height: container.height
578
+ });
579
+ return [4 /*yield*/, iframeRenderer.render(container.tree)];
580
+ case 13:
581
+ canvas = _c.sent();
582
+ if (container.width && container.height) {
583
+ // this.ctx.drawImage(
584
+ // canvas,
585
+ // 0,
586
+ // 0,
587
+ // container.width,
588
+ // container.height,
589
+ // container.bounds.left,
590
+ // container.bounds.top,
591
+ // container.bounds.width,
592
+ // container.bounds.height
593
+ // );
594
+ this.context2dCtx.drawImage(canvas, 0, 0, container.width, container.height, container.bounds.left, container.bounds.top, container.bounds.width, container.bounds.height);
595
+ }
596
+ _c.label = 14;
597
+ case 14:
598
+ // 处理Input元素
599
+ if (container instanceof input_element_container_1.InputElementContainer) {
600
+ size = Math.min(container.bounds.width, container.bounds.height);
601
+ // 渲染复选框
602
+ if (container.type === input_element_container_1.CHECKBOX) {
603
+ if (container.checked) {
604
+ // this.ctx.save();
605
+ this.context2dCtx.save();
606
+ this.path([
607
+ new vector_1.Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79),
608
+ new vector_1.Vector(container.bounds.left + size * 0.16, container.bounds.top + size * 0.5549),
609
+ new vector_1.Vector(container.bounds.left + size * 0.27347, container.bounds.top + size * 0.44071),
610
+ new vector_1.Vector(container.bounds.left + size * 0.39694, container.bounds.top + size * 0.5649),
611
+ new vector_1.Vector(container.bounds.left + size * 0.72983, container.bounds.top + size * 0.23),
612
+ new vector_1.Vector(container.bounds.left + size * 0.84, container.bounds.top + size * 0.34085),
613
+ new vector_1.Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79)
614
+ ]);
615
+ // this.ctx.fillStyle = this.convertColor(INPUT_COLOR);
616
+ // this.ctx.fill();
617
+ // this.ctx.restore();
618
+ this.context2dCtx.fillStyle = this.convertColor(input_element_container_1.INPUT_COLOR);
619
+ this.context2dCtx.fill();
620
+ this.context2dCtx.restore();
621
+ if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
622
+ this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
623
+ }
624
+ }
625
+ }
626
+ // 渲染单选框
627
+ else if (container.type === input_element_container_1.RADIO) {
628
+ if (container.checked) {
629
+ // this.ctx.save();
630
+ // this.ctx.beginPath();
631
+ // this.ctx.arc(
632
+ // container.bounds.left + size / 2,
633
+ // container.bounds.top + size / 2,
634
+ // size / 4,
635
+ // 0,
636
+ // Math.PI * 2,
637
+ // true
638
+ // );
639
+ // this.ctx.fillStyle = this.convertColor(INPUT_COLOR);
640
+ // this.ctx.fill();
641
+ // this.ctx.restore();
642
+ this.context2dCtx.save();
643
+ this.context2dCtx.beginPath();
644
+ this.context2dCtx.arc(container.bounds.left + size / 2, container.bounds.top + size / 2, size / 4, 0, Math.PI * 2, true);
645
+ this.context2dCtx.fillStyle = this.convertColor(input_element_container_1.INPUT_COLOR);
646
+ this.context2dCtx.fill();
647
+ this.context2dCtx.restore();
648
+ // 在 restore 之后重新设置字体
649
+ }
650
+ }
651
+ }
652
+ // 处理文本输入元素
653
+ if (isTextInputElement(container) && container.value.length) {
654
+ _b = this.createFontStyle(styles), fontFamily = _b[0], fontSize = _b[1];
655
+ baseline = this.fontMetrics.getMetrics(fontFamily, fontSize).baseline;
656
+ // this.ctx.font = fontFamily;
657
+ // this.ctx.fillStyle = this.convertColor(styles.color);
658
+ // this.context2dCtx.font = fontFamily;
659
+ this.context2dCtx.fillStyle = this.convertColor(styles.color);
660
+ // this.ctx.textBaseline = 'alphabetic';
661
+ // this.ctx.textAlign = canvasTextAlign(container.styles.textAlign);
662
+ this.context2dCtx.textBaseline = 'alphabetic';
663
+ this.context2dCtx.textAlign = canvasTextAlign(container.styles.textAlign);
664
+ bounds = (0, box_sizing_1.contentBox)(container);
665
+ x = 0;
666
+ // 根据文本对齐方式调整x坐标
667
+ switch (container.styles.textAlign) {
668
+ case 1 /* TEXT_ALIGN.CENTER */:
669
+ x += bounds.width / 2;
670
+ break;
671
+ case 2 /* TEXT_ALIGN.RIGHT */:
672
+ x += bounds.width;
673
+ break;
674
+ }
675
+ textBounds = bounds.add(x, 0, 0, -bounds.height / 2 + 1);
676
+ // this.ctx.save();
677
+ this.context2dCtx.save();
678
+ this.path([
679
+ new vector_1.Vector(bounds.left, bounds.top),
680
+ new vector_1.Vector(bounds.left + bounds.width, bounds.top),
681
+ new vector_1.Vector(bounds.left + bounds.width, bounds.top + bounds.height),
682
+ new vector_1.Vector(bounds.left, bounds.top + bounds.height)
683
+ ]);
684
+ // this.ctx.clip();
685
+ this.context2dCtx.clip();
686
+ this.renderTextWithLetterSpacing(new text_1.TextBounds(container.value, textBounds), styles.letterSpacing, baseline);
687
+ // this.ctx.restore();
688
+ // this.ctx.textBaseline = 'alphabetic';
689
+ // this.ctx.textAlign = 'left';
690
+ this.context2dCtx.restore();
691
+ this.context2dCtx.textBaseline = 'alphabetic';
692
+ this.context2dCtx.textAlign = 'left';
693
+ }
694
+ if (!(0, bitwise_1.contains)(container.styles.display, 2048 /* DISPLAY.LIST_ITEM */)) return [3 /*break*/, 20];
695
+ if (!(container.styles.listStyleImage !== null)) return [3 /*break*/, 19];
696
+ img = container.styles.listStyleImage;
697
+ if (!(img.type === 0 /* CSSImageType.URL */)) return [3 /*break*/, 18];
698
+ image = void 0;
699
+ url = img.url;
700
+ _c.label = 15;
701
+ case 15:
702
+ _c.trys.push([15, 17, , 18]);
703
+ return [4 /*yield*/, this.context.cache.match(url)];
704
+ case 16:
705
+ image = _c.sent();
706
+ // this.ctx.drawImage(image, container.bounds.left - (image.width + 10), container.bounds.top);
707
+ this.context2dCtx.drawImage(image, container.bounds.left - (image.width + 10), container.bounds.top);
708
+ return [3 /*break*/, 18];
709
+ case 17:
710
+ e_3 = _c.sent();
711
+ this.context.logger.error("Error loading list-style-image ".concat(url));
712
+ return [3 /*break*/, 18];
713
+ case 18: return [3 /*break*/, 20];
714
+ case 19:
715
+ if (paint.listValue && container.styles.listStyleType !== -1 /* LIST_STYLE_TYPE.NONE */) {
716
+ fontFamily = this.createFontStyle(styles)[0];
717
+ // this.ctx.font = fontFamily;
718
+ // this.ctx.fillStyle = this.convertColor(styles.color);
719
+ this.context2dCtx.font = fontFamily;
720
+ this.context2dCtx.fillStyle = this.convertColor(styles.color);
721
+ // this.ctx.textBaseline = 'middle';
722
+ // this.ctx.textAlign = 'right';
723
+ this.context2dCtx.textBaseline = 'middle';
724
+ this.context2dCtx.textAlign = 'right';
725
+ bounds = new bounds_1.Bounds(container.bounds.left, container.bounds.top + (0, length_percentage_1.getAbsoluteValue)(container.styles.paddingTop, container.bounds.width), container.bounds.width, (0, line_height_1.computeLineHeight)(styles.lineHeight, styles.fontSize.number) / 2 + 1);
726
+ this.renderTextWithLetterSpacing(new text_1.TextBounds(paint.listValue, bounds), styles.letterSpacing, (0, line_height_1.computeLineHeight)(styles.lineHeight, styles.fontSize.number) / 2 + 2);
727
+ // this.ctx.textBaseline = 'bottom';
728
+ // this.ctx.textAlign = 'left';
729
+ this.context2dCtx.textBaseline = 'bottom';
730
+ this.context2dCtx.textAlign = 'left';
731
+ }
732
+ _c.label = 20;
733
+ case 20:
734
+ if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
735
+ this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
736
+ }
737
+ return [2 /*return*/];
738
+ }
739
+ });
740
+ });
741
+ };
742
+ // 渲染堆叠上下文内容
743
+ CanvasRenderer.prototype.renderStackContent = function (stack) {
744
+ return __awaiter(this, void 0, void 0, function () {
745
+ var _i, _a, child, _b, _c, child, _d, _e, child, _f, _g, child, _h, _j, child, _k, _l, child, _m, _o, child;
746
+ return __generator(this, function (_p) {
747
+ switch (_p.label) {
748
+ case 0:
749
+ if ((0, bitwise_1.contains)(stack.element.container.flags, 16 /* FLAGS.DEBUG_RENDER */)) {
750
+ debugger;
751
+ }
752
+ // https://www.w3.org/TR/css-position-3/#painting-order
753
+ // 1. the background and borders of the element forming the stacking context.
754
+ return [4 /*yield*/, this.renderNodeBackgroundAndBorders(stack.element)];
755
+ case 1:
756
+ // https://www.w3.org/TR/css-position-3/#painting-order
757
+ // 1. the background and borders of the element forming the stacking context.
758
+ _p.sent();
759
+ _i = 0, _a = stack.negativeZIndex;
760
+ _p.label = 2;
761
+ case 2:
762
+ if (!(_i < _a.length)) return [3 /*break*/, 5];
763
+ child = _a[_i];
764
+ return [4 /*yield*/, this.renderStack(child)];
765
+ case 3:
766
+ _p.sent();
767
+ _p.label = 4;
768
+ case 4:
769
+ _i++;
770
+ return [3 /*break*/, 2];
771
+ case 5:
772
+ // 3. For all its in-flow, non-positioned, block-level descendants in tree order:
773
+ return [4 /*yield*/, this.renderNodeContent(stack.element)];
774
+ case 6:
775
+ // 3. For all its in-flow, non-positioned, block-level descendants in tree order:
776
+ _p.sent();
777
+ _b = 0, _c = stack.nonInlineLevel;
778
+ _p.label = 7;
779
+ case 7:
780
+ if (!(_b < _c.length)) return [3 /*break*/, 10];
781
+ child = _c[_b];
782
+ return [4 /*yield*/, this.renderNode(child)];
783
+ case 8:
784
+ _p.sent();
785
+ _p.label = 9;
786
+ case 9:
787
+ _b++;
788
+ return [3 /*break*/, 7];
789
+ case 10:
790
+ _d = 0, _e = stack.nonPositionedFloats;
791
+ _p.label = 11;
792
+ case 11:
793
+ if (!(_d < _e.length)) return [3 /*break*/, 14];
794
+ child = _e[_d];
795
+ return [4 /*yield*/, this.renderStack(child)];
796
+ case 12:
797
+ _p.sent();
798
+ _p.label = 13;
799
+ case 13:
800
+ _d++;
801
+ return [3 /*break*/, 11];
802
+ case 14:
803
+ _f = 0, _g = stack.nonPositionedInlineLevel;
804
+ _p.label = 15;
805
+ case 15:
806
+ if (!(_f < _g.length)) return [3 /*break*/, 18];
807
+ child = _g[_f];
808
+ return [4 /*yield*/, this.renderStack(child)];
809
+ case 16:
810
+ _p.sent();
811
+ _p.label = 17;
812
+ case 17:
813
+ _f++;
814
+ return [3 /*break*/, 15];
815
+ case 18:
816
+ _h = 0, _j = stack.inlineLevel;
817
+ _p.label = 19;
818
+ case 19:
819
+ if (!(_h < _j.length)) return [3 /*break*/, 22];
820
+ child = _j[_h];
821
+ return [4 /*yield*/, this.renderNode(child)];
822
+ case 20:
823
+ _p.sent();
824
+ _p.label = 21;
825
+ case 21:
826
+ _h++;
827
+ return [3 /*break*/, 19];
828
+ case 22:
829
+ _k = 0, _l = stack.zeroOrAutoZIndexOrTransformedOrOpacity;
830
+ _p.label = 23;
831
+ case 23:
832
+ if (!(_k < _l.length)) return [3 /*break*/, 26];
833
+ child = _l[_k];
834
+ return [4 /*yield*/, this.renderStack(child)];
835
+ case 24:
836
+ _p.sent();
837
+ _p.label = 25;
838
+ case 25:
839
+ _k++;
840
+ return [3 /*break*/, 23];
841
+ case 26:
842
+ _m = 0, _o = stack.positiveZIndex;
843
+ _p.label = 27;
844
+ case 27:
845
+ if (!(_m < _o.length)) return [3 /*break*/, 30];
846
+ child = _o[_m];
847
+ return [4 /*yield*/, this.renderStack(child)];
848
+ case 28:
849
+ _p.sent();
850
+ _p.label = 29;
851
+ case 29:
852
+ _m++;
853
+ return [3 /*break*/, 27];
854
+ case 30: return [2 /*return*/];
855
+ }
856
+ });
857
+ });
858
+ };
859
+ // 创建遮罩
860
+ CanvasRenderer.prototype.mask = function (paths) {
861
+ // this.ctx.beginPath();
862
+ // this.ctx.moveTo(0, 0);
863
+ // this.ctx.lineTo(this.canvas.width, 0);
864
+ // this.ctx.lineTo(this.canvas.width, this.canvas.height);
865
+ // this.ctx.lineTo(0, this.canvas.height);
866
+ // this.ctx.lineTo(0, 0);
867
+ // this.formatPath(paths.slice(0).reverse());
868
+ // this.ctx.closePath();
869
+ this.context2dCtx.beginPath();
870
+ this.context2dCtx.moveTo(0, 0);
871
+ this.context2dCtx.lineTo(this.options.width, 0);
872
+ this.context2dCtx.lineTo(this.options.width, this.options.height);
873
+ this.context2dCtx.lineTo(0, this.options.height);
874
+ this.context2dCtx.lineTo(0, 0);
875
+ this.formatPath(paths.slice(0).reverse());
876
+ this.context2dCtx.closePath();
877
+ };
878
+ // 创建路径
879
+ CanvasRenderer.prototype.path = function (paths) {
880
+ // this.ctx.beginPath();
881
+ // this.formatPath(paths);
882
+ // this.ctx.closePath();
883
+ this.context2dCtx.beginPath();
884
+ this.formatPath(paths);
885
+ this.context2dCtx.closePath();
886
+ };
887
+ // 格式化路径
888
+ CanvasRenderer.prototype.formatPath = function (paths) {
889
+ var _this = this;
890
+ paths.forEach(function (point, index) {
891
+ var start = (0, bezier_curve_1.isBezierCurve)(point) ? point.start : point;
892
+ if (index === 0) {
893
+ // this.ctx.moveTo(start.x, start.y);
894
+ _this.context2dCtx.moveTo(start.x, start.y);
895
+ }
896
+ else {
897
+ // this.ctx.lineTo(start.x, start.y);
898
+ _this.context2dCtx.lineTo(start.x, start.y);
899
+ }
900
+ if ((0, bezier_curve_1.isBezierCurve)(point)) {
901
+ // this.ctx.bezierCurveTo(
902
+ // point.startControl.x,
903
+ // point.startControl.y,
904
+ // point.endControl.x,
905
+ // point.endControl.y,
906
+ // point.end.x,
907
+ // point.end.y
908
+ // );
909
+ _this.context2dCtx.bezierCurveTo(point.startControl.x, point.startControl.y, point.endControl.x, point.endControl.y, point.end.x, point.end.y);
910
+ }
911
+ });
912
+ };
913
+ // 渲染重复图案
914
+ CanvasRenderer.prototype.renderRepeat = function (path, pattern, offsetX, offsetY) {
915
+ this.path(path);
916
+ this.ctx.fillStyle = pattern;
917
+ // this.ctx.translate(offsetX, offsetY);
918
+ // this.ctx.fill();
919
+ // this.ctx.translate(-offsetX, -offsetY);
920
+ // this.context2dCtx.fillStyle =this.convertColor(pattern) ;
921
+ this.context2dCtx.translate(offsetX, offsetY);
922
+ this.context2dCtx.fill();
923
+ this.context2dCtx.translate(-offsetX, -offsetY);
924
+ };
925
+ // 调整图片大小
926
+ CanvasRenderer.prototype.resizeImage = function (image, width, height) {
927
+ var _a;
928
+ if (image.width === width && image.height === height) {
929
+ return image;
930
+ }
931
+ var ownerDocument = (_a = this.canvas.ownerDocument) !== null && _a !== void 0 ? _a : document;
932
+ var canvas = ownerDocument.createElement('canvas');
933
+ canvas.width = Math.max(1, width);
934
+ canvas.height = Math.max(1, height);
935
+ var ctx = canvas.getContext('2d');
936
+ ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
937
+ return canvas;
938
+ };
939
+ // 渲染背景图片
940
+ CanvasRenderer.prototype.renderBackgroundImage = function (container) {
941
+ return __awaiter(this, void 0, void 0, function () {
942
+ var index, _i, _a, backgroundImage, image, url, e_4, _b, path, x, y, width, height, pattern, xPt, yPt, widthPt, heightPt;
943
+ return __generator(this, function (_c) {
944
+ switch (_c.label) {
945
+ case 0:
946
+ index = container.styles.backgroundImage.length - 1;
947
+ _i = 0, _a = container.styles.backgroundImage.slice(0).reverse();
948
+ _c.label = 1;
949
+ case 1:
950
+ if (!(_i < _a.length)) return [3 /*break*/, 9];
951
+ backgroundImage = _a[_i];
952
+ if (!(backgroundImage.type === 0 /* CSSImageType.URL */)) return [3 /*break*/, 6];
953
+ image = void 0;
954
+ url = backgroundImage.url;
955
+ _c.label = 2;
956
+ case 2:
957
+ _c.trys.push([2, 4, , 5]);
958
+ return [4 /*yield*/, this.context.cache.match(url)];
959
+ case 3:
960
+ image = _c.sent();
961
+ return [3 /*break*/, 5];
962
+ case 4:
963
+ e_4 = _c.sent();
964
+ this.context.logger.error("Error loading background-image ".concat(url));
965
+ return [3 /*break*/, 5];
966
+ case 5:
967
+ if (image) {
968
+ _b = (0, background_1.calculateBackgroundRendering)(container, index, [
969
+ image.width,
970
+ image.height,
971
+ image.width / image.height
972
+ ]), path = _b[0], x = _b[1], y = _b[2], width = _b[3], height = _b[4];
973
+ pattern = this.ctx.createPattern(this.resizeImage(image, width, height), 'repeat');
974
+ this.renderRepeat(path, pattern, x, y);
975
+ xPt = this.pxToPt(x - this.options.x);
976
+ yPt = this.pxToPt(y - this.options.y);
977
+ widthPt = this.pxToPt(width);
978
+ heightPt = this.pxToPt(height);
979
+ // console.log('绘制背景图片', xPt, yPt, image)
980
+ this.jspdfCtx.addImage(image, 'JPEG', xPt, yPt, widthPt, heightPt);
981
+ }
982
+ return [3 /*break*/, 7];
983
+ case 6:
984
+ if ((0, image_1.isLinearGradient)(backgroundImage)) {
985
+ // const [path, x, y, width, height] = calculateBackgroundRendering(container, index, [null, null, null]);
986
+ // const [lineLength, x0, x1, y0, y1] = calculateGradientDirection(backgroundImage.angle, width, height);
987
+ // const canvas = document.createElement('canvas');
988
+ // canvas.width = width;
989
+ // canvas.height = height;
990
+ // const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
991
+ // const gradient = ctx.createLinearGradient(x0, y0, x1, y1);
992
+ // processColorStops(backgroundImage.stops, lineLength).forEach((colorStop) =>
993
+ // gradient.addColorStop(colorStop.stop, this.convertColor(colorStop.color))
994
+ // );
995
+ // ctx.fillStyle = gradient;
996
+ // ctx.fillRect(0, 0, width, height);
997
+ // if (width > 0 && height > 0) {
998
+ // const pattern = this.ctx.createPattern(canvas, 'repeat') as CanvasPattern;
999
+ // this.renderRepeat(path, pattern, x, y);
1000
+ // }
1001
+ }
1002
+ else if ((0, image_1.isRadialGradient)(backgroundImage)) {
1003
+ // const [path, left, top, width, height] = calculateBackgroundRendering(container, index, [
1004
+ // null,
1005
+ // null,
1006
+ // null
1007
+ // ]);
1008
+ // const position = backgroundImage.position.length === 0 ? [FIFTY_PERCENT] : backgroundImage.position;
1009
+ // const x = getAbsoluteValue(position[0], width);
1010
+ // const y = getAbsoluteValue(position[position.length - 1], height);
1011
+ // const [rx, ry] = calculateRadius(backgroundImage, x, y, width, height);
1012
+ // if (rx > 0 && ry > 0) {
1013
+ // const radialGradient = this.ctx.createRadialGradient(left + x, top + y, 0, left + x, top + y, rx);
1014
+ // processColorStops(backgroundImage.stops, rx * 2).forEach((colorStop) =>
1015
+ // radialGradient.addColorStop(colorStop.stop, this.convertColor(colorStop.color))
1016
+ // );
1017
+ // this.path(path);
1018
+ // this.ctx.fillStyle = radialGradient;
1019
+ // this.context2dCtx.fillStyle = this.convertColor(radialGradient);
1020
+ // if (rx !== ry) {
1021
+ // // transforms for elliptical radial gradient
1022
+ // const midX = container.bounds.left + 0.5 * container.bounds.width;
1023
+ // const midY = container.bounds.top + 0.5 * container.bounds.height;
1024
+ // const f = ry / rx;
1025
+ // const invF = 1 / f;
1026
+ // // this.ctx.save();
1027
+ // // this.ctx.translate(midX, midY);
1028
+ // // this.ctx.transform(1, 0, 0, f, 0, 0);
1029
+ // // this.ctx.translate(-midX, -midY);
1030
+ // // this.ctx.fillRect(left, invF * (top - midY) + midY, width, height * invF);
1031
+ // // this.ctx.restore();
1032
+ // this.context2dCtx.save();
1033
+ // this.context2dCtx.translate(midX, midY);
1034
+ // this.context2dCtx.transform(1, 0, 0, f, 0, 0);
1035
+ // this.context2dCtx.translate(-midX, -midY);
1036
+ // this.context2dCtx.fillRect(left, invF * (top - midY) + midY, width, height * invF);
1037
+ // this.context2dCtx.restore();
1038
+ // } else {
1039
+ // // this.ctx.fill();
1040
+ // this.context2dCtx.fill()
1041
+ // }
1042
+ // }
1043
+ }
1044
+ _c.label = 7;
1045
+ case 7:
1046
+ index--;
1047
+ _c.label = 8;
1048
+ case 8:
1049
+ _i++;
1050
+ return [3 /*break*/, 1];
1051
+ case 9: return [2 /*return*/];
1052
+ }
1053
+ });
1054
+ });
1055
+ };
1056
+ /**
1057
+ * 渲染实线边框
1058
+ * @param color - 边框颜色
1059
+ * @param side - 边的位置(0-3,分别代表上右下左)
1060
+ * @param curvePoints - 边框曲线点
1061
+ */
1062
+ CanvasRenderer.prototype.renderSolidBorder = function (color, side, curvePoints) {
1063
+ return __awaiter(this, void 0, void 0, function () {
1064
+ return __generator(this, function (_a) {
1065
+ // console.log('绘制边框')
1066
+ // 解析边框路径
1067
+ // console.log('Border curve points:', JSON.stringify(curvePoints));
1068
+ // console.log('Page height:', this.jspdf.internal.pageSize.height);
1069
+ this.path((0, border_1.parsePathForBorder)(curvePoints, side));
1070
+ // 设置填充颜色
1071
+ // this.ctx.fillStyle = this.convertColor(color);
1072
+ this.context2dCtx.fillStyle = this.convertColor(color);
1073
+ // 填充路径
1074
+ // this.ctx.fill();
1075
+ this.jspdfCtx.fill();
1076
+ this.context2dCtx.fill();
1077
+ return [2 /*return*/];
1078
+ });
1079
+ });
1080
+ };
1081
+ // 渲染双线边框
1082
+ CanvasRenderer.prototype.renderDoubleBorder = function (color, width, side, curvePoints) {
1083
+ return __awaiter(this, void 0, void 0, function () {
1084
+ var outerPaths, innerPaths;
1085
+ return __generator(this, function (_a) {
1086
+ switch (_a.label) {
1087
+ case 0:
1088
+ if (!(width < 3)) return [3 /*break*/, 2];
1089
+ return [4 /*yield*/, this.renderSolidBorder(color, side, curvePoints)];
1090
+ case 1:
1091
+ _a.sent();
1092
+ return [2 /*return*/];
1093
+ case 2:
1094
+ outerPaths = (0, border_1.parsePathForBorderDoubleOuter)(curvePoints, side);
1095
+ this.path(outerPaths);
1096
+ // this.ctx.fillStyle = this.convertColor(color);
1097
+ // this.ctx.fill();
1098
+ this.context2dCtx.fillStyle = this.convertColor(color);
1099
+ this.context2dCtx.fill();
1100
+ innerPaths = (0, border_1.parsePathForBorderDoubleInner)(curvePoints, side);
1101
+ this.path(innerPaths);
1102
+ // this.ctx.fill();
1103
+ this.context2dCtx.fill();
1104
+ return [2 /*return*/];
1105
+ }
1106
+ });
1107
+ });
1108
+ };
1109
+ // 渲染节点的背景和边框
1110
+ CanvasRenderer.prototype.renderNodeBackgroundAndBorders = function (paint) {
1111
+ return __awaiter(this, void 0, void 0, function () {
1112
+ var styles, hasBackground, borders, backgroundPaintingArea, foreignobjectrendering, side, _i, borders_1, border;
1113
+ return __generator(this, function (_a) {
1114
+ switch (_a.label) {
1115
+ case 0:
1116
+ // 应用背景和边框的效果
1117
+ this.applyEffects(paint.getEffects(2 /* EffectTarget.BACKGROUND_BORDERS */));
1118
+ styles = paint.container.styles;
1119
+ hasBackground = !(0, color_1.isTransparent)(styles.backgroundColor) || styles.backgroundImage.length;
1120
+ borders = [
1121
+ { style: styles.borderTopStyle, color: styles.borderTopColor, width: styles.borderTopWidth },
1122
+ { style: styles.borderRightStyle, color: styles.borderRightColor, width: styles.borderRightWidth },
1123
+ { style: styles.borderBottomStyle, color: styles.borderBottomColor, width: styles.borderBottomWidth },
1124
+ { style: styles.borderLeftStyle, color: styles.borderLeftColor, width: styles.borderLeftWidth }
1125
+ ];
1126
+ backgroundPaintingArea = calculateBackgroundCurvedPaintingArea((0, background_1.getBackgroundValueForIndex)(styles.backgroundClip, 0), paint.curves);
1127
+ foreignobjectrendering = paint.container.foreignobjectrendering;
1128
+ if (!(hasBackground || styles.boxShadow.length)) return [3 /*break*/, 2];
1129
+ // console.log(paint,foreignobjectrendering, 'paint边框')
1130
+ // 在 save 之前确保字体设置正确
1131
+ if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
1132
+ this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
1133
+ }
1134
+ if (!foreignobjectrendering) {
1135
+ this.context2dCtx.save();
1136
+ this.path(backgroundPaintingArea);
1137
+ this.context2dCtx.clip();
1138
+ // this.ctx.save();
1139
+ // this.path(backgroundPaintingArea);
1140
+ // this.ctx.clip();
1141
+ if (!(0, color_1.isTransparent)(styles.backgroundColor)) {
1142
+ // this.ctx.fillStyle = asString(styles.backgroundColor);
1143
+ // this.ctx.fill();
1144
+ this.context2dCtx.fillStyle = this.convertColor(styles.backgroundColor);
1145
+ this.context2dCtx.fill();
1146
+ }
1147
+ }
1148
+ return [4 /*yield*/, this.renderBackgroundImage(paint.container)];
1149
+ case 1:
1150
+ _a.sent();
1151
+ // this.ctx.restore();
1152
+ this.context2dCtx.restore();
1153
+ // 在 restore 之后重新设置字体
1154
+ if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
1155
+ this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
1156
+ }
1157
+ _a.label = 2;
1158
+ case 2:
1159
+ side = 0;
1160
+ _i = 0, borders_1 = borders;
1161
+ _a.label = 3;
1162
+ case 3:
1163
+ if (!(_i < borders_1.length)) return [3 /*break*/, 13];
1164
+ border = borders_1[_i];
1165
+ if (!(border.style !== 0 /* BORDER_STYLE.NONE */ && !(0, color_1.isTransparent)(border.color) && border.width > 0)) return [3 /*break*/, 11];
1166
+ if (!(border.style === 2 /* BORDER_STYLE.DASHED */)) return [3 /*break*/, 5];
1167
+ return [4 /*yield*/, this.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 2 /* BORDER_STYLE.DASHED */)];
1168
+ case 4:
1169
+ _a.sent();
1170
+ return [3 /*break*/, 11];
1171
+ case 5:
1172
+ if (!(border.style === 3 /* BORDER_STYLE.DOTTED */)) return [3 /*break*/, 7];
1173
+ return [4 /*yield*/, this.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 3 /* BORDER_STYLE.DOTTED */)];
1174
+ case 6:
1175
+ _a.sent();
1176
+ return [3 /*break*/, 11];
1177
+ case 7:
1178
+ if (!(border.style === 4 /* BORDER_STYLE.DOUBLE */)) return [3 /*break*/, 9];
1179
+ return [4 /*yield*/, this.renderDoubleBorder(border.color, border.width, side, paint.curves)];
1180
+ case 8:
1181
+ _a.sent();
1182
+ return [3 /*break*/, 11];
1183
+ case 9:
1184
+ if (!!foreignobjectrendering) return [3 /*break*/, 11];
1185
+ return [4 /*yield*/, this.renderSolidBorder(border.color, side, paint.curves)];
1186
+ case 10:
1187
+ _a.sent();
1188
+ _a.label = 11;
1189
+ case 11:
1190
+ side++;
1191
+ _a.label = 12;
1192
+ case 12:
1193
+ _i++;
1194
+ return [3 /*break*/, 3];
1195
+ case 13: return [2 /*return*/];
1196
+ }
1197
+ });
1198
+ });
1199
+ };
1200
+ // 这个方法用于渲染虚线和点线边框
1201
+ CanvasRenderer.prototype.renderDashedDottedBorder = function (color, // 边框颜色
1202
+ width, // 边框宽度
1203
+ side, // 边的位置(0-3,分别代表上右下左)
1204
+ curvePoints, // 边框曲线点
1205
+ style // 边框样式(DASHED或DOTTED)
1206
+ ) {
1207
+ return __awaiter(this, void 0, void 0, function () {
1208
+ var strokePaths, boxPaths, startX, startY, endX, endY, length, dashLength, spaceLength, useLineDash, multiplier, numberOfDashes, minSpace, maxSpace, path1, path2, x1, y1, x2, y2, path1, path2;
1209
+ return __generator(this, function (_a) {
1210
+ // this.ctx.save(); // 保存当前画布状态
1211
+ // this.jspdfCtx.saveGraphicsState(); // 保存PDF绘图状态
1212
+ this.context2dCtx.save();
1213
+ strokePaths = (0, border_1.parsePathForBorderStroke)(curvePoints, side);
1214
+ boxPaths = (0, border_1.parsePathForBorder)(curvePoints, side);
1215
+ // 如果是虚线边框,需要先裁剪路径
1216
+ if (style === 2 /* BORDER_STYLE.DASHED */) {
1217
+ this.path(boxPaths);
1218
+ // this.ctx.clip();
1219
+ // // PDF裁剪路径
1220
+ // this.jspdfCtx.clip();
1221
+ this.context2dCtx.clip();
1222
+ }
1223
+ if ((0, bezier_curve_1.isBezierCurve)(boxPaths[0])) {
1224
+ startX = boxPaths[0].start.x;
1225
+ startY = boxPaths[0].start.y;
1226
+ }
1227
+ else {
1228
+ startX = boxPaths[0].x;
1229
+ startY = boxPaths[0].y;
1230
+ }
1231
+ if ((0, bezier_curve_1.isBezierCurve)(boxPaths[1])) {
1232
+ endX = boxPaths[1].end.x;
1233
+ endY = boxPaths[1].end.y;
1234
+ }
1235
+ else {
1236
+ endX = boxPaths[1].x;
1237
+ endY = boxPaths[1].y;
1238
+ }
1239
+ if (side === 0 || side === 2) {
1240
+ length = Math.abs(startX - endX);
1241
+ }
1242
+ else {
1243
+ length = Math.abs(startY - endY);
1244
+ }
1245
+ // 开始绘制路径
1246
+ // this.ctx.beginPath();
1247
+ this.context2dCtx.beginPath();
1248
+ this.jspdfCtx.setDrawColor(this.convertColor(color)); // 设置PDF绘制颜色
1249
+ if (style === 3 /* BORDER_STYLE.DOTTED */) {
1250
+ this.formatPath(strokePaths);
1251
+ }
1252
+ else {
1253
+ this.formatPath(boxPaths.slice(0, 2));
1254
+ }
1255
+ dashLength = width < 3 ? width * 3 : width * 2;
1256
+ spaceLength = width < 3 ? width * 2 : width;
1257
+ if (style === 3 /* BORDER_STYLE.DOTTED */) {
1258
+ dashLength = width;
1259
+ spaceLength = width;
1260
+ }
1261
+ useLineDash = true;
1262
+ if (length <= dashLength * 2) {
1263
+ useLineDash = false;
1264
+ }
1265
+ else if (length <= dashLength * 2 + spaceLength) {
1266
+ multiplier = length / (2 * dashLength + spaceLength);
1267
+ dashLength *= multiplier;
1268
+ spaceLength *= multiplier;
1269
+ }
1270
+ else {
1271
+ numberOfDashes = Math.floor((length + spaceLength) / (dashLength + spaceLength));
1272
+ minSpace = (length - numberOfDashes * dashLength) / (numberOfDashes - 1);
1273
+ maxSpace = (length - (numberOfDashes + 1) * dashLength) / numberOfDashes;
1274
+ spaceLength =
1275
+ maxSpace <= 0 || Math.abs(spaceLength - minSpace) < Math.abs(spaceLength - maxSpace)
1276
+ ? minSpace
1277
+ : maxSpace;
1278
+ }
1279
+ // 设置虚线样式
1280
+ if (useLineDash) {
1281
+ if (style === 3 /* BORDER_STYLE.DOTTED */) {
1282
+ // this.ctx.setLineDash([0, dashLength + spaceLength]);
1283
+ this.jspdfCtx.setLineDashPattern([0, dashLength + spaceLength], 0); // PDF虚线样式
1284
+ }
1285
+ else {
1286
+ // this.ctx.setLineDash([dashLength, spaceLength]);
1287
+ this.jspdfCtx.setLineDashPattern([dashLength, spaceLength], 0); // PDF虚线样式
1288
+ }
1289
+ }
1290
+ // 设置线条样式并绘制
1291
+ if (style === 3 /* BORDER_STYLE.DOTTED */) {
1292
+ // this.ctx.lineCap = 'round';
1293
+ // this.ctx.lineWidth = width;
1294
+ this.jspdfCtx.setLineCap('round'); // PDF线帽样式
1295
+ this.jspdfCtx.setLineWidth(width);
1296
+ }
1297
+ else {
1298
+ // this.ctx.lineWidth = width * 2 + 1.1;
1299
+ this.jspdfCtx.setLineWidth(width * 2 + 1.1);
1300
+ }
1301
+ // this.ctx.strokeStyle = this.convertColor(color);
1302
+ // this.ctx.stroke();
1303
+ this.jspdfCtx.stroke(); // PDF绘制线条
1304
+ // this.ctx.setLineDash([]);
1305
+ this.jspdfCtx.setLineDashPattern([], 0); // 重置PDF虚线样式
1306
+ // 处理虚线边框的圆角连接处
1307
+ if (style === 2 /* BORDER_STYLE.DASHED */) {
1308
+ if ((0, bezier_curve_1.isBezierCurve)(boxPaths[0])) {
1309
+ path1 = boxPaths[3];
1310
+ path2 = boxPaths[0];
1311
+ x1 = this.pxToPt(path1.end.x);
1312
+ y1 = this.pxToPt(path1.end.y);
1313
+ x2 = this.pxToPt(path2.start.x);
1314
+ y2 = this.pxToPt(path2.start.y);
1315
+ try {
1316
+ this.jspdfCtx.line(x1, y1, x2, y2);
1317
+ this.jspdfCtx.stroke();
1318
+ }
1319
+ catch (error) {
1320
+ console.warn('Failed to draw dashed border:', error);
1321
+ }
1322
+ }
1323
+ if ((0, bezier_curve_1.isBezierCurve)(boxPaths[1])) {
1324
+ path1 = boxPaths[1];
1325
+ path2 = boxPaths[2];
1326
+ // this.ctx.beginPath();
1327
+ // this.formatPath([new Vector(path1.end.x, path1.end.y), new Vector(path2.start.x, path2.start.y)]);
1328
+ // this.ctx.stroke();
1329
+ this.jspdfCtx.lines([[path1.end.x, path1.end.y, path2.start.x, path2.start.y]], path1.end.x, path1.end.y); // PDF绘制连接线
1330
+ this.jspdfCtx.stroke();
1331
+ }
1332
+ }
1333
+ // this.ctx.restore(); // 恢复画布状态
1334
+ this.jspdfCtx.restoreGraphicsState(); // 恢复PDF绘图状态
1335
+ return [2 /*return*/];
1336
+ });
1337
+ });
1338
+ };
1339
+ CanvasRenderer.prototype.render = function (element) {
1340
+ return __awaiter(this, void 0, void 0, function () {
1341
+ var stack, pdfBlob;
1342
+ return __generator(this, function (_a) {
1343
+ switch (_a.label) {
1344
+ case 0:
1345
+ if (this.options.backgroundColor) {
1346
+ // this.ctx.fillStyle = this.convertColor(this.options.backgroundColor);
1347
+ // this.ctx.fillRect(this.options.x, this.options.y, this.options.width, this.options.height);
1348
+ this.jspdfCtx.setFillColor(this.convertColor(this.options.backgroundColor)); // PDF填充背景颜色
1349
+ this.jspdfCtx.rect(this.options.x, this.options.y, this.options.width, this.options.height, 'F'); // PDF绘制矩形
1350
+ }
1351
+ stack = (0, stacking_context_1.parseStackingContexts)(element);
1352
+ return [4 /*yield*/, this.renderStack(stack)];
1353
+ case 1:
1354
+ _a.sent();
1355
+ this.applyEffects([]);
1356
+ pdfBlob = this.jspdfCtx.output('blob');
1357
+ return [2 /*return*/, pdfBlob];
1358
+ }
1359
+ });
1360
+ });
1361
+ };
1362
+ return CanvasRenderer;
1363
+ }(renderer_1.Renderer));
1364
+ exports.CanvasRenderer = CanvasRenderer;
1365
+ var isTextInputElement = function (container) {
1366
+ if (container instanceof textarea_element_container_1.TextareaElementContainer) {
1367
+ return true;
1368
+ }
1369
+ else if (container instanceof select_element_container_1.SelectElementContainer) {
1370
+ return true;
1371
+ }
1372
+ else if (container instanceof input_element_container_1.InputElementContainer && container.type !== input_element_container_1.RADIO && container.type !== input_element_container_1.CHECKBOX) {
1373
+ return true;
1374
+ }
1375
+ return false;
1376
+ };
1377
+ var calculateBackgroundCurvedPaintingArea = function (clip, curves) {
1378
+ switch (clip) {
1379
+ case 0 /* BACKGROUND_CLIP.BORDER_BOX */:
1380
+ return (0, bound_curves_1.calculateBorderBoxPath)(curves);
1381
+ case 2 /* BACKGROUND_CLIP.CONTENT_BOX */:
1382
+ return (0, bound_curves_1.calculateContentBoxPath)(curves);
1383
+ case 1 /* BACKGROUND_CLIP.PADDING_BOX */:
1384
+ default:
1385
+ return (0, bound_curves_1.calculatePaddingBoxPath)(curves);
1386
+ }
1387
+ };
1388
+ var canvasTextAlign = function (textAlign) {
1389
+ switch (textAlign) {
1390
+ case 1 /* TEXT_ALIGN.CENTER */:
1391
+ return 'center';
1392
+ case 2 /* TEXT_ALIGN.RIGHT */:
1393
+ return 'right';
1394
+ case 0 /* TEXT_ALIGN.LEFT */:
1395
+ default:
1396
+ return 'left';
1397
+ }
1398
+ };
1399
+ // see https://github.com/niklasvh/html2canvas/pull/2645
1400
+ var iOSBrokenFonts = ['-apple-system', 'system-ui'];
1401
+ var fixIOSSystemFonts = function (fontFamilies) {
1402
+ return /iPhone OS 15_(0|1)/.test(window.navigator.userAgent)
1403
+ ? fontFamilies.filter(function (fontFamily) { return iOSBrokenFonts.indexOf(fontFamily) === -1; })
1404
+ : fontFamilies;
1405
+ };
1406
+ //# sourceMappingURL=pdf-renderer.js.map