@ohos-ports/html2canvas-pro 0.0.0-stage → 2.3.2-beta.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.
Files changed (344) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -2
  3. package/dist/html2canvas-pro.cjs +11191 -0
  4. package/dist/html2canvas-pro.cjs.map +1 -0
  5. package/dist/html2canvas-pro.esm.js +11182 -0
  6. package/dist/html2canvas-pro.esm.js.map +1 -0
  7. package/dist/html2canvas-pro.js +11196 -0
  8. package/dist/html2canvas-pro.js.map +1 -0
  9. package/dist/html2canvas-pro.min.js +10 -0
  10. package/dist/lib/config.js +49 -0
  11. package/dist/lib/core/abort-helper.js +20 -0
  12. package/dist/lib/core/background-parser.js +41 -0
  13. package/dist/lib/core/bitwise.js +5 -0
  14. package/dist/lib/core/cache-storage.js +268 -0
  15. package/dist/lib/core/config-assembler.js +88 -0
  16. package/dist/lib/core/constants.js +25 -0
  17. package/dist/lib/core/context.js +19 -0
  18. package/dist/lib/core/debugger.js +27 -0
  19. package/dist/lib/core/features.js +190 -0
  20. package/dist/lib/core/logger.js +56 -0
  21. package/dist/lib/core/lru-map.js +66 -0
  22. package/dist/lib/core/origin-checker.js +53 -0
  23. package/dist/lib/core/performance-monitor.js +185 -0
  24. package/dist/lib/core/render-element.js +132 -0
  25. package/dist/lib/core/util.js +4 -0
  26. package/dist/lib/core/validator.js +500 -0
  27. package/dist/lib/css/grouped/background-styles.js +36 -0
  28. package/dist/lib/css/grouped/border-styles.js +75 -0
  29. package/dist/lib/css/grouped/font-styles.js +93 -0
  30. package/dist/lib/css/grouped/layout-styles.js +127 -0
  31. package/dist/lib/css/index.js +330 -0
  32. package/dist/lib/css/layout/bounds.js +52 -0
  33. package/dist/lib/css/layout/text.js +133 -0
  34. package/dist/lib/css/property-descriptor.js +2 -0
  35. package/dist/lib/css/property-descriptors/background-blend-mode.js +41 -0
  36. package/dist/lib/css/property-descriptors/background-clip.js +23 -0
  37. package/dist/lib/css/property-descriptors/background-color.js +10 -0
  38. package/dist/lib/css/property-descriptors/background-image.js +24 -0
  39. package/dist/lib/css/property-descriptors/background-origin.js +23 -0
  40. package/dist/lib/css/property-descriptors/background-position.js +19 -0
  41. package/dist/lib/css/property-descriptors/background-repeat.js +33 -0
  42. package/dist/lib/css/property-descriptors/background-size.js +23 -0
  43. package/dist/lib/css/property-descriptors/border-color.js +14 -0
  44. package/dist/lib/css/property-descriptors/border-image-repeat.js +42 -0
  45. package/dist/lib/css/property-descriptors/border-image-slice.js +45 -0
  46. package/dist/lib/css/property-descriptors/border-image-source.js +22 -0
  47. package/dist/lib/css/property-descriptors/border-radius.js +15 -0
  48. package/dist/lib/css/property-descriptors/border-style.js +26 -0
  49. package/dist/lib/css/property-descriptors/border-width.js +20 -0
  50. package/dist/lib/css/property-descriptors/box-decoration-break.js +18 -0
  51. package/dist/lib/css/property-descriptors/box-shadow.js +54 -0
  52. package/dist/lib/css/property-descriptors/clip-path.js +189 -0
  53. package/dist/lib/css/property-descriptors/color.js +10 -0
  54. package/dist/lib/css/property-descriptors/content.js +19 -0
  55. package/dist/lib/css/property-descriptors/counter-increment.js +35 -0
  56. package/dist/lib/css/property-descriptors/counter-reset.js +18 -0
  57. package/dist/lib/css/property-descriptors/direction.js +18 -0
  58. package/dist/lib/css/property-descriptors/display.js +81 -0
  59. package/dist/lib/css/property-descriptors/duration.js +14 -0
  60. package/dist/lib/css/property-descriptors/filter.js +76 -0
  61. package/dist/lib/css/property-descriptors/float.js +22 -0
  62. package/dist/lib/css/property-descriptors/font-family.js +32 -0
  63. package/dist/lib/css/property-descriptors/font-size.js +10 -0
  64. package/dist/lib/css/property-descriptors/font-style.js +20 -0
  65. package/dist/lib/css/property-descriptors/font-variant-ligatures.js +34 -0
  66. package/dist/lib/css/property-descriptors/font-variant.js +13 -0
  67. package/dist/lib/css/property-descriptors/font-weight.js +25 -0
  68. package/dist/lib/css/property-descriptors/image-rendering.js +33 -0
  69. package/dist/lib/css/property-descriptors/letter-spacing.js +21 -0
  70. package/dist/lib/css/property-descriptors/line-break.js +23 -0
  71. package/dist/lib/css/property-descriptors/line-height.js +24 -0
  72. package/dist/lib/css/property-descriptors/list-style-image.js +17 -0
  73. package/dist/lib/css/property-descriptors/list-style-position.js +18 -0
  74. package/dist/lib/css/property-descriptors/list-style-type.js +122 -0
  75. package/dist/lib/css/property-descriptors/margin.js +13 -0
  76. package/dist/lib/css/property-descriptors/mix-blend-mode.js +31 -0
  77. package/dist/lib/css/property-descriptors/object-fit.js +28 -0
  78. package/dist/lib/css/property-descriptors/object-position.js +42 -0
  79. package/dist/lib/css/property-descriptors/opacity.js +16 -0
  80. package/dist/lib/css/property-descriptors/overflow-wrap.js +18 -0
  81. package/dist/lib/css/property-descriptors/overflow.js +27 -0
  82. package/dist/lib/css/property-descriptors/padding.js +14 -0
  83. package/dist/lib/css/property-descriptors/paint-order.js +33 -0
  84. package/dist/lib/css/property-descriptors/position.js +22 -0
  85. package/dist/lib/css/property-descriptors/quotes.js +41 -0
  86. package/dist/lib/css/property-descriptors/rotate.js +27 -0
  87. package/dist/lib/css/property-descriptors/text-align.js +21 -0
  88. package/dist/lib/css/property-descriptors/text-decoration-color.js +10 -0
  89. package/dist/lib/css/property-descriptors/text-decoration-line.js +28 -0
  90. package/dist/lib/css/property-descriptors/text-decoration-style.js +24 -0
  91. package/dist/lib/css/property-descriptors/text-decoration-thickness.js +26 -0
  92. package/dist/lib/css/property-descriptors/text-overflow.js +18 -0
  93. package/dist/lib/css/property-descriptors/text-shadow.js +46 -0
  94. package/dist/lib/css/property-descriptors/text-transform.js +20 -0
  95. package/dist/lib/css/property-descriptors/text-underline-offset.js +23 -0
  96. package/dist/lib/css/property-descriptors/transform-origin.js +24 -0
  97. package/dist/lib/css/property-descriptors/transform.js +57 -0
  98. package/dist/lib/css/property-descriptors/visibility.js +20 -0
  99. package/dist/lib/css/property-descriptors/webkit-line-clamp.js +26 -0
  100. package/dist/lib/css/property-descriptors/webkit-text-stroke-color.js +10 -0
  101. package/dist/lib/css/property-descriptors/webkit-text-stroke-width.js +16 -0
  102. package/dist/lib/css/property-descriptors/word-break.js +26 -0
  103. package/dist/lib/css/property-descriptors/writing-mode.js +28 -0
  104. package/dist/lib/css/property-descriptors/z-index.js +19 -0
  105. package/dist/lib/css/property-descriptors/zoom.js +18 -0
  106. package/dist/lib/css/syntax/parser.js +140 -0
  107. package/dist/lib/css/syntax/token-constants.js +214 -0
  108. package/dist/lib/css/syntax/token-singletons.js +36 -0
  109. package/dist/lib/css/syntax/token-types.js +10 -0
  110. package/dist/lib/css/syntax/tokenizer.js +502 -0
  111. package/dist/lib/css/type-descriptor.js +2 -0
  112. package/dist/lib/css/types/angle.js +80 -0
  113. package/dist/lib/css/types/color-math.js +25 -0
  114. package/dist/lib/css/types/color-spaces/a98.js +78 -0
  115. package/dist/lib/css/types/color-spaces/p3.js +86 -0
  116. package/dist/lib/css/types/color-spaces/pro-photo.js +83 -0
  117. package/dist/lib/css/types/color-spaces/rec2020.js +85 -0
  118. package/dist/lib/css/types/color-spaces/srgb.js +79 -0
  119. package/dist/lib/css/types/color-utilities.js +342 -0
  120. package/dist/lib/css/types/color.js +400 -0
  121. package/dist/lib/css/types/functions/-prefix-linear-gradient.js +32 -0
  122. package/dist/lib/css/types/functions/-prefix-radial-gradient.js +83 -0
  123. package/dist/lib/css/types/functions/-webkit-gradient.js +59 -0
  124. package/dist/lib/css/types/functions/counter.js +367 -0
  125. package/dist/lib/css/types/functions/gradient.js +163 -0
  126. package/dist/lib/css/types/functions/linear-gradient.js +27 -0
  127. package/dist/lib/css/types/functions/radial-gradient.js +90 -0
  128. package/dist/lib/css/types/functions/repeating-linear-gradient.js +9 -0
  129. package/dist/lib/css/types/image.js +62 -0
  130. package/dist/lib/css/types/index.js +2 -0
  131. package/dist/lib/css/types/length-percentage.js +197 -0
  132. package/dist/lib/css/types/length.js +5 -0
  133. package/dist/lib/css/types/safe-eval.js +80 -0
  134. package/dist/lib/css/types/time.js +17 -0
  135. package/dist/lib/dom/document-cloner.js +597 -0
  136. package/dist/lib/dom/dom-normalizer.js +115 -0
  137. package/dist/lib/dom/element-container.js +56 -0
  138. package/dist/lib/dom/elements/li-element-container.js +11 -0
  139. package/dist/lib/dom/elements/ol-element-container.js +12 -0
  140. package/dist/lib/dom/elements/select-element-container.js +12 -0
  141. package/dist/lib/dom/elements/textarea-element-container.js +11 -0
  142. package/dist/lib/dom/node-parser.js +112 -0
  143. package/dist/lib/dom/node-type-guards.js +81 -0
  144. package/dist/lib/dom/replaced-elements/canvas-element-container.js +13 -0
  145. package/dist/lib/dom/replaced-elements/iframe-element-container.js +38 -0
  146. package/dist/lib/dom/replaced-elements/image-element-container.js +14 -0
  147. package/dist/lib/dom/replaced-elements/index.js +2 -0
  148. package/dist/lib/dom/replaced-elements/input-element-container.js +89 -0
  149. package/dist/lib/dom/replaced-elements/svg-element-container.js +19 -0
  150. package/dist/lib/dom/slot-cloner.js +176 -0
  151. package/dist/lib/dom/text-container.js +35 -0
  152. package/dist/lib/index.js +49 -0
  153. package/dist/lib/options.js +2 -0
  154. package/dist/lib/render/background.js +188 -0
  155. package/dist/lib/render/bezier-curve.js +34 -0
  156. package/dist/lib/render/border.js +104 -0
  157. package/dist/lib/render/bound-curves.js +188 -0
  158. package/dist/lib/render/box-sizing.js +20 -0
  159. package/dist/lib/render/canvas/background-renderer.js +327 -0
  160. package/dist/lib/render/canvas/border-image-renderer.js +153 -0
  161. package/dist/lib/render/canvas/border-renderer.js +184 -0
  162. package/dist/lib/render/canvas/canvas-path.js +25 -0
  163. package/dist/lib/render/canvas/canvas-renderer.js +312 -0
  164. package/dist/lib/render/canvas/content-renderer.js +204 -0
  165. package/dist/lib/render/canvas/effects-renderer.js +171 -0
  166. package/dist/lib/render/canvas/font-utils.js +29 -0
  167. package/dist/lib/render/canvas/foreignobject-renderer.js +38 -0
  168. package/dist/lib/render/canvas/text/text-decoration-renderer.js +99 -0
  169. package/dist/lib/render/canvas/text-renderer.js +485 -0
  170. package/dist/lib/render/effects.js +231 -0
  171. package/dist/lib/render/font-metrics.js +53 -0
  172. package/dist/lib/render/object-fit.js +91 -0
  173. package/dist/lib/render/path.js +26 -0
  174. package/dist/lib/render/renderer-interface.js +2 -0
  175. package/dist/lib/render/stacking-context.js +340 -0
  176. package/dist/lib/render/vector.js +16 -0
  177. package/dist/types/config.d.ts +44 -0
  178. package/dist/types/core/abort-helper.d.ts +12 -0
  179. package/dist/types/core/background-parser.d.ts +16 -0
  180. package/dist/types/core/bitwise.d.ts +1 -0
  181. package/dist/types/core/cache-storage.d.ts +68 -0
  182. package/dist/types/core/config-assembler.d.ts +28 -0
  183. package/dist/types/core/constants.d.ts +22 -0
  184. package/dist/types/core/context.d.ts +22 -0
  185. package/dist/types/core/debugger.d.ts +8 -0
  186. package/dist/types/core/features.d.ts +12 -0
  187. package/dist/types/core/logger.d.ts +18 -0
  188. package/dist/types/core/lru-map.d.ts +37 -0
  189. package/dist/types/core/origin-checker.d.ts +33 -0
  190. package/dist/types/core/performance-monitor.d.ts +120 -0
  191. package/dist/types/core/render-element.d.ts +3 -0
  192. package/dist/types/core/util.d.ts +1 -0
  193. package/dist/types/core/validator.d.ts +130 -0
  194. package/dist/types/css/grouped/background-styles.d.ts +16 -0
  195. package/dist/types/css/grouped/border-styles.d.ts +31 -0
  196. package/dist/types/css/grouped/font-styles.d.ts +35 -0
  197. package/dist/types/css/grouped/layout-styles.d.ts +46 -0
  198. package/dist/types/css/index.d.ts +185 -0
  199. package/dist/types/css/layout/bounds.d.ts +14 -0
  200. package/dist/types/css/layout/text.d.ts +10 -0
  201. package/dist/types/css/property-descriptor.d.ts +40 -0
  202. package/dist/types/css/property-descriptors/background-blend-mode.d.ts +23 -0
  203. package/dist/types/css/property-descriptors/background-clip.d.ts +8 -0
  204. package/dist/types/css/property-descriptors/background-color.d.ts +2 -0
  205. package/dist/types/css/property-descriptors/background-image.d.ts +3 -0
  206. package/dist/types/css/property-descriptors/background-origin.d.ts +8 -0
  207. package/dist/types/css/property-descriptors/background-position.d.ts +5 -0
  208. package/dist/types/css/property-descriptors/background-repeat.d.ts +9 -0
  209. package/dist/types/css/property-descriptors/background-size.d.ts +11 -0
  210. package/dist/types/css/property-descriptors/border-color.d.ts +5 -0
  211. package/dist/types/css/property-descriptors/border-image-repeat.d.ts +12 -0
  212. package/dist/types/css/property-descriptors/border-image-slice.d.ts +10 -0
  213. package/dist/types/css/property-descriptors/border-image-source.d.ts +4 -0
  214. package/dist/types/css/property-descriptors/border-radius.d.ts +7 -0
  215. package/dist/types/css/property-descriptors/border-style.d.ts +12 -0
  216. package/dist/types/css/property-descriptors/border-width.d.ts +5 -0
  217. package/dist/types/css/property-descriptors/box-decoration-break.d.ts +6 -0
  218. package/dist/types/css/property-descriptors/box-shadow.d.ts +14 -0
  219. package/dist/types/css/property-descriptors/clip-path.d.ts +62 -0
  220. package/dist/types/css/property-descriptors/color.d.ts +2 -0
  221. package/dist/types/css/property-descriptors/content.d.ts +4 -0
  222. package/dist/types/css/property-descriptors/counter-increment.d.ts +10 -0
  223. package/dist/types/css/property-descriptors/counter-reset.d.ts +7 -0
  224. package/dist/types/css/property-descriptors/direction.d.ts +6 -0
  225. package/dist/types/css/property-descriptors/display.d.ts +35 -0
  226. package/dist/types/css/property-descriptors/duration.d.ts +2 -0
  227. package/dist/types/css/property-descriptors/filter.d.ts +3 -0
  228. package/dist/types/css/property-descriptors/float.d.ts +9 -0
  229. package/dist/types/css/property-descriptors/font-family.d.ts +4 -0
  230. package/dist/types/css/property-descriptors/font-size.d.ts +2 -0
  231. package/dist/types/css/property-descriptors/font-style.d.ts +7 -0
  232. package/dist/types/css/property-descriptors/font-variant-ligatures.d.ts +14 -0
  233. package/dist/types/css/property-descriptors/font-variant.d.ts +2 -0
  234. package/dist/types/css/property-descriptors/font-weight.d.ts +2 -0
  235. package/dist/types/css/property-descriptors/image-rendering.d.ts +8 -0
  236. package/dist/types/css/property-descriptors/letter-spacing.d.ts +2 -0
  237. package/dist/types/css/property-descriptors/line-break.d.ts +6 -0
  238. package/dist/types/css/property-descriptors/line-height.d.ts +4 -0
  239. package/dist/types/css/property-descriptors/list-style-image.d.ts +3 -0
  240. package/dist/types/css/property-descriptors/list-style-position.d.ts +6 -0
  241. package/dist/types/css/property-descriptors/list-style-type.d.ts +58 -0
  242. package/dist/types/css/property-descriptors/margin.d.ts +5 -0
  243. package/dist/types/css/property-descriptors/mix-blend-mode.d.ts +21 -0
  244. package/dist/types/css/property-descriptors/object-fit.d.ts +10 -0
  245. package/dist/types/css/property-descriptors/object-position.d.ts +4 -0
  246. package/dist/types/css/property-descriptors/opacity.d.ts +2 -0
  247. package/dist/types/css/property-descriptors/overflow-wrap.d.ts +6 -0
  248. package/dist/types/css/property-descriptors/overflow.d.ts +9 -0
  249. package/dist/types/css/property-descriptors/padding.d.ts +5 -0
  250. package/dist/types/css/property-descriptors/paint-order.d.ts +8 -0
  251. package/dist/types/css/property-descriptors/position.d.ts +9 -0
  252. package/dist/types/css/property-descriptors/quotes.d.ts +8 -0
  253. package/dist/types/css/property-descriptors/rotate.d.ts +3 -0
  254. package/dist/types/css/property-descriptors/text-align.d.ts +7 -0
  255. package/dist/types/css/property-descriptors/text-decoration-color.d.ts +2 -0
  256. package/dist/types/css/property-descriptors/text-decoration-line.d.ts +10 -0
  257. package/dist/types/css/property-descriptors/text-decoration-style.d.ts +9 -0
  258. package/dist/types/css/property-descriptors/text-decoration-thickness.d.ts +3 -0
  259. package/dist/types/css/property-descriptors/text-overflow.d.ts +6 -0
  260. package/dist/types/css/property-descriptors/text-shadow.d.ts +12 -0
  261. package/dist/types/css/property-descriptors/text-transform.d.ts +8 -0
  262. package/dist/types/css/property-descriptors/text-underline-offset.d.ts +3 -0
  263. package/dist/types/css/property-descriptors/transform-origin.d.ts +4 -0
  264. package/dist/types/css/property-descriptors/transform.d.ts +4 -0
  265. package/dist/types/css/property-descriptors/visibility.d.ts +7 -0
  266. package/dist/types/css/property-descriptors/webkit-line-clamp.d.ts +7 -0
  267. package/dist/types/css/property-descriptors/webkit-text-stroke-color.d.ts +2 -0
  268. package/dist/types/css/property-descriptors/webkit-text-stroke-width.d.ts +2 -0
  269. package/dist/types/css/property-descriptors/word-break.d.ts +7 -0
  270. package/dist/types/css/property-descriptors/writing-mode.d.ts +11 -0
  271. package/dist/types/css/property-descriptors/z-index.d.ts +7 -0
  272. package/dist/types/css/property-descriptors/zoom.d.ts +3 -0
  273. package/dist/types/css/syntax/parser.d.ts +34 -0
  274. package/dist/types/css/syntax/token-constants.d.ts +74 -0
  275. package/dist/types/css/syntax/token-singletons.d.ts +22 -0
  276. package/dist/types/css/syntax/token-types.d.ts +72 -0
  277. package/dist/types/css/syntax/tokenizer.d.ts +32 -0
  278. package/dist/types/css/type-descriptor.d.ts +6 -0
  279. package/dist/types/css/types/angle.d.ts +7 -0
  280. package/dist/types/css/types/color-math.d.ts +12 -0
  281. package/dist/types/css/types/color-spaces/a98.d.ts +39 -0
  282. package/dist/types/css/types/color-spaces/p3.d.ts +45 -0
  283. package/dist/types/css/types/color-spaces/pro-photo.d.ts +45 -0
  284. package/dist/types/css/types/color-spaces/rec2020.d.ts +45 -0
  285. package/dist/types/css/types/color-spaces/srgb.d.ts +38 -0
  286. package/dist/types/css/types/color-utilities.d.ts +107 -0
  287. package/dist/types/css/types/color.d.ts +8 -0
  288. package/dist/types/css/types/functions/-prefix-linear-gradient.d.ts +4 -0
  289. package/dist/types/css/types/functions/-prefix-radial-gradient.d.ts +4 -0
  290. package/dist/types/css/types/functions/-webkit-gradient.d.ts +4 -0
  291. package/dist/types/css/types/functions/counter.d.ts +10 -0
  292. package/dist/types/css/types/functions/gradient.d.ts +7 -0
  293. package/dist/types/css/types/functions/linear-gradient.d.ts +4 -0
  294. package/dist/types/css/types/functions/radial-gradient.d.ts +12 -0
  295. package/dist/types/css/types/functions/repeating-linear-gradient.d.ts +4 -0
  296. package/dist/types/css/types/image.d.ts +56 -0
  297. package/dist/types/css/types/index.d.ts +1 -0
  298. package/dist/types/css/types/length-percentage.d.ts +62 -0
  299. package/dist/types/css/types/length.d.ts +4 -0
  300. package/dist/types/css/types/safe-eval.d.ts +8 -0
  301. package/dist/types/css/types/time.d.ts +2 -0
  302. package/dist/types/dom/document-cloner.d.ts +57 -0
  303. package/dist/types/dom/dom-normalizer.d.ts +62 -0
  304. package/dist/types/dom/element-container.d.ts +31 -0
  305. package/dist/types/dom/elements/li-element-container.d.ts +6 -0
  306. package/dist/types/dom/elements/ol-element-container.d.ts +7 -0
  307. package/dist/types/dom/elements/select-element-container.d.ts +6 -0
  308. package/dist/types/dom/elements/textarea-element-container.d.ts +6 -0
  309. package/dist/types/dom/node-parser.d.ts +3 -0
  310. package/dist/types/dom/node-type-guards.d.ts +32 -0
  311. package/dist/types/dom/replaced-elements/canvas-element-container.d.ts +8 -0
  312. package/dist/types/dom/replaced-elements/iframe-element-container.d.ts +14 -0
  313. package/dist/types/dom/replaced-elements/image-element-container.d.ts +8 -0
  314. package/dist/types/dom/replaced-elements/index.d.ts +4 -0
  315. package/dist/types/dom/replaced-elements/input-element-container.d.ts +14 -0
  316. package/dist/types/dom/replaced-elements/svg-element-container.d.ts +8 -0
  317. package/dist/types/dom/slot-cloner.d.ts +66 -0
  318. package/dist/types/dom/text-container.d.ts +8 -0
  319. package/dist/types/index.d.ts +36 -0
  320. package/dist/types/options.d.ts +62 -0
  321. package/dist/types/render/background.d.ts +16 -0
  322. package/dist/types/render/bezier-curve.d.ts +14 -0
  323. package/dist/types/render/border.d.ts +6 -0
  324. package/dist/types/render/bound-curves.d.ts +32 -0
  325. package/dist/types/render/box-sizing.d.ts +4 -0
  326. package/dist/types/render/canvas/background-renderer.d.ts +94 -0
  327. package/dist/types/render/canvas/border-image-renderer.d.ts +18 -0
  328. package/dist/types/render/canvas/border-renderer.d.ts +67 -0
  329. package/dist/types/render/canvas/canvas-path.d.ts +3 -0
  330. package/dist/types/render/canvas/canvas-renderer.d.ts +60 -0
  331. package/dist/types/render/canvas/content-renderer.d.ts +43 -0
  332. package/dist/types/render/canvas/effects-renderer.d.ts +90 -0
  333. package/dist/types/render/canvas/font-utils.d.ts +19 -0
  334. package/dist/types/render/canvas/foreignobject-renderer.d.ts +10 -0
  335. package/dist/types/render/canvas/text/text-decoration-renderer.d.ts +18 -0
  336. package/dist/types/render/canvas/text-renderer.d.ts +103 -0
  337. package/dist/types/render/effects.d.ts +112 -0
  338. package/dist/types/render/font-metrics.d.ts +11 -0
  339. package/dist/types/render/object-fit.d.ts +19 -0
  340. package/dist/types/render/path.d.ts +13 -0
  341. package/dist/types/render/renderer-interface.d.ts +28 -0
  342. package/dist/types/render/stacking-context.d.ts +49 -0
  343. package/dist/types/render/vector.d.ts +9 -0
  344. package/package.json +139 -4
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderReplacedElements = renderReplacedElements;
4
+ exports.renderFormElements = renderFormElements;
5
+ exports.renderListMarker = renderListMarker;
6
+ const color_utilities_1 = require("../../css/types/color-utilities");
7
+ const image_element_container_1 = require("../../dom/replaced-elements/image-element-container");
8
+ const canvas_element_container_1 = require("../../dom/replaced-elements/canvas-element-container");
9
+ const svg_element_container_1 = require("../../dom/replaced-elements/svg-element-container");
10
+ const iframe_element_container_1 = require("../../dom/replaced-elements/iframe-element-container");
11
+ const input_element_container_1 = require("../../dom/replaced-elements/input-element-container");
12
+ const textarea_element_container_1 = require("../../dom/elements/textarea-element-container");
13
+ const select_element_container_1 = require("../../dom/elements/select-element-container");
14
+ const bounds_1 = require("../../css/layout/bounds");
15
+ const text_1 = require("../../css/layout/text");
16
+ const vector_1 = require("../vector");
17
+ const box_sizing_1 = require("../box-sizing");
18
+ const font_utils_1 = require("./font-utils");
19
+ const image_rendering_1 = require("../../css/property-descriptors/image-rendering");
20
+ const length_percentage_1 = require("../../css/types/length-percentage");
21
+ const line_height_1 = require("../../css/property-descriptors/line-height");
22
+ const bitwise_1 = require("../../core/bitwise");
23
+ /**
24
+ * Render replaced elements: Image, Canvas, SVG, IFrame.
25
+ */
26
+ async function renderReplacedElements(ctx, context, options, iframeRendererFactory, container, curves, styles, renderReplacedElementFn) {
27
+ if (container instanceof image_element_container_1.ImageElementContainer) {
28
+ try {
29
+ const image = await context.cache.match(container.src);
30
+ const prevSmoothing = ctx.imageSmoothingEnabled;
31
+ if (styles.imageRendering === image_rendering_1.IMAGE_RENDERING.PIXELATED ||
32
+ styles.imageRendering === image_rendering_1.IMAGE_RENDERING.CRISP_EDGES) {
33
+ ctx.imageSmoothingEnabled = false;
34
+ }
35
+ else if (styles.imageRendering === image_rendering_1.IMAGE_RENDERING.SMOOTH) {
36
+ ctx.imageSmoothingEnabled = true;
37
+ }
38
+ renderReplacedElementFn(container, curves, image);
39
+ ctx.imageSmoothingEnabled = prevSmoothing;
40
+ }
41
+ catch (e) {
42
+ context.logger.error(`Error loading image ${container.src}`);
43
+ context.onError?.(e instanceof Error ? e : new Error(String(e)));
44
+ }
45
+ }
46
+ if (container instanceof canvas_element_container_1.CanvasElementContainer) {
47
+ renderReplacedElementFn(container, curves, container.canvas);
48
+ }
49
+ if (container instanceof svg_element_container_1.SVGElementContainer) {
50
+ try {
51
+ const image = await context.cache.match(container.svg);
52
+ renderReplacedElementFn(container, curves, image);
53
+ }
54
+ catch (e) {
55
+ context.logger.error(`Error loading svg ${container.svg.substring(0, 255)}`);
56
+ context.onError?.(e instanceof Error ? e : new Error(String(e)));
57
+ }
58
+ }
59
+ if (container instanceof iframe_element_container_1.IFrameElementContainer && container.tree) {
60
+ const iframeRenderer = iframeRendererFactory(context, {
61
+ scale: options.scale,
62
+ backgroundColor: container.backgroundColor,
63
+ x: 0,
64
+ y: 0,
65
+ width: container.width,
66
+ height: container.height
67
+ });
68
+ const canvas = await iframeRenderer.render(container.tree);
69
+ if (container.width && container.height) {
70
+ ctx.drawImage(canvas, 0, 0, container.width, container.height, container.bounds.left, container.bounds.top, container.bounds.width, container.bounds.height);
71
+ }
72
+ }
73
+ }
74
+ /**
75
+ * Render form element content: checkbox, radio, text input.
76
+ */
77
+ function renderFormElements(ctx, textRenderer, pathFn, container, styles) {
78
+ if (container instanceof input_element_container_1.InputElementContainer) {
79
+ const size = Math.min(container.bounds.width, container.bounds.height);
80
+ if (container.type === input_element_container_1.CHECKBOX && container.checked) {
81
+ ctx.save();
82
+ pathFn([
83
+ new vector_1.Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79),
84
+ new vector_1.Vector(container.bounds.left + size * 0.16, container.bounds.top + size * 0.5549),
85
+ new vector_1.Vector(container.bounds.left + size * 0.27347, container.bounds.top + size * 0.44071),
86
+ new vector_1.Vector(container.bounds.left + size * 0.39694, container.bounds.top + size * 0.5649),
87
+ new vector_1.Vector(container.bounds.left + size * 0.72983, container.bounds.top + size * 0.23),
88
+ new vector_1.Vector(container.bounds.left + size * 0.84, container.bounds.top + size * 0.34085),
89
+ new vector_1.Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79)
90
+ ]);
91
+ ctx.fillStyle = (0, color_utilities_1.asString)(input_element_container_1.INPUT_COLOR);
92
+ ctx.fill();
93
+ ctx.restore();
94
+ }
95
+ else if (container.type === input_element_container_1.RADIO && container.checked) {
96
+ ctx.save();
97
+ ctx.beginPath();
98
+ ctx.arc(container.bounds.left + size / 2, container.bounds.top + size / 2, size / 4, 0, Math.PI * 2, true);
99
+ ctx.fillStyle = (0, color_utilities_1.asString)(input_element_container_1.INPUT_COLOR);
100
+ ctx.fill();
101
+ ctx.restore();
102
+ }
103
+ }
104
+ if (isTextInputElement(container) && container.value.length) {
105
+ const [font] = textRenderer.createFontStyle(styles);
106
+ // Use Canvas API to measure baseline from the actual rendered font
107
+ ctx.font = font;
108
+ const baseline = (0, font_utils_1.measureBaseline)(ctx, (0, length_percentage_1.getAbsoluteValue)(styles.fontSize, 0));
109
+ const isPlaceholder = container instanceof input_element_container_1.InputElementContainer && container.isPlaceholder;
110
+ ctx.fillStyle = isPlaceholder ? (0, color_utilities_1.asString)(input_element_container_1.PLACEHOLDER_COLOR) : (0, color_utilities_1.asString)(styles.color);
111
+ ctx.textBaseline = 'alphabetic';
112
+ ctx.textAlign = canvasTextAlign(container.styles.textAlign);
113
+ const bounds = (0, box_sizing_1.contentBox)(container);
114
+ let x = 0;
115
+ switch (container.styles.textAlign) {
116
+ case 1 /* TEXT_ALIGN.CENTER */:
117
+ x += bounds.width / 2;
118
+ break;
119
+ case 2 /* TEXT_ALIGN.RIGHT */:
120
+ x += bounds.width;
121
+ break;
122
+ }
123
+ let verticalOffset = 0;
124
+ if (container instanceof input_element_container_1.InputElementContainer) {
125
+ const fontSizeValue = (0, length_percentage_1.getAbsoluteValue)(styles.fontSize, 0);
126
+ verticalOffset = (bounds.height - fontSizeValue) / 2;
127
+ }
128
+ const textBounds = bounds.add(x, verticalOffset, 0, 0);
129
+ ctx.save();
130
+ pathFn([
131
+ new vector_1.Vector(bounds.left, bounds.top),
132
+ new vector_1.Vector(bounds.left + bounds.width, bounds.top),
133
+ new vector_1.Vector(bounds.left + bounds.width, bounds.top + bounds.height),
134
+ new vector_1.Vector(bounds.left, bounds.top + bounds.height)
135
+ ]);
136
+ ctx.clip();
137
+ textRenderer.renderTextWithLetterSpacing(new text_1.TextBounds(container.value, textBounds), styles.letterSpacing, baseline, styles.writingMode);
138
+ ctx.restore();
139
+ ctx.textBaseline = 'alphabetic';
140
+ ctx.textAlign = 'left';
141
+ }
142
+ }
143
+ /**
144
+ * Render list-item marker (image or text).
145
+ */
146
+ async function renderListMarker(ctx, context, textRenderer, paint, container, styles) {
147
+ if (!(0, bitwise_1.contains)(container.styles.display, 2048 /* DISPLAY.LIST_ITEM */)) {
148
+ return;
149
+ }
150
+ if (container.styles.listStyleImage !== null) {
151
+ const img = container.styles.listStyleImage;
152
+ if (img.type === 0 /* CSSImageType.URL */) {
153
+ const url = img.url;
154
+ try {
155
+ const image = await context.cache.match(url);
156
+ ctx.drawImage(image, container.bounds.left - (image.width + 10), container.bounds.top);
157
+ }
158
+ catch (e) {
159
+ context.logger.error(`Error loading list-style-image ${url}`);
160
+ context.onError?.(e instanceof Error ? e : new Error(String(e)));
161
+ }
162
+ }
163
+ }
164
+ else if (paint.listValue && container.styles.listStyleType !== -1 /* LIST_STYLE_TYPE.NONE */) {
165
+ const [font] = textRenderer.createFontStyle(styles);
166
+ ctx.font = font;
167
+ ctx.fillStyle = (0, color_utilities_1.asString)(styles.color);
168
+ ctx.textBaseline = 'middle';
169
+ ctx.textAlign = 'right';
170
+ const 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);
171
+ textRenderer.renderTextWithLetterSpacing(new text_1.TextBounds(paint.listValue, bounds), styles.letterSpacing, (0, line_height_1.computeLineHeight)(styles.lineHeight, styles.fontSize.number) / 2 + 2, styles.writingMode);
172
+ ctx.textBaseline = 'bottom';
173
+ ctx.textAlign = 'left';
174
+ }
175
+ }
176
+ /**
177
+ * Type guard for text input containers.
178
+ */
179
+ const isTextInputElement = (container) => {
180
+ if (container instanceof textarea_element_container_1.TextareaElementContainer) {
181
+ return true;
182
+ }
183
+ else if (container instanceof select_element_container_1.SelectElementContainer) {
184
+ return true;
185
+ }
186
+ else if (container instanceof input_element_container_1.InputElementContainer && container.type !== input_element_container_1.RADIO && container.type !== input_element_container_1.CHECKBOX) {
187
+ return true;
188
+ }
189
+ return false;
190
+ };
191
+ /**
192
+ * Map CSS text-align to Canvas textAlign.
193
+ */
194
+ const canvasTextAlign = (textAlign) => {
195
+ switch (textAlign) {
196
+ case 1 /* TEXT_ALIGN.CENTER */:
197
+ return 'center';
198
+ case 2 /* TEXT_ALIGN.RIGHT */:
199
+ return 'right';
200
+ case 0 /* TEXT_ALIGN.LEFT */:
201
+ default:
202
+ return 'left';
203
+ }
204
+ };
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ /**
3
+ * Effects Renderer
4
+ *
5
+ * Handles rendering effects including:
6
+ * - Opacity effects
7
+ * - Transform effects (matrix transformations)
8
+ * - Clip effects (overflow / border-radius clipping via Path[])
9
+ * - Clip-path effects (CSS clip-path shapes: inset, circle, ellipse, polygon, path)
10
+ * - Blend effects (mix-blend-mode)
11
+ * - Filter effects (CSS filter functions)
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.EffectsRenderer = void 0;
15
+ const effects_1 = require("../effects");
16
+ /**
17
+ * Effects Renderer
18
+ *
19
+ * Manages rendering effects stack including opacity, transforms, and clipping.
20
+ * Extracted from CanvasRenderer to improve code organization and maintainability.
21
+ *
22
+ * ## Save/restore optimisation
23
+ *
24
+ * Canvas `save()` / `restore()` snapshot and restore the entire canvas state
25
+ * (transform matrix, clip region, compositing mode, filter, shadow, …) which
26
+ * is relatively expensive. The old implementation called `save()` / `restore()`
27
+ * for every single effect unconditionally.
28
+ *
29
+ * This implementation does a **batch pre-scan** before applying effects:
30
+ *
31
+ * | Effect type | Modifies | Reversible? | Needs save? |
32
+ * |--------------------|----------------------|---------------|-------------|
33
+ * | TransformEffect | transform matrix | ❌ irreversible | **YES** |
34
+ * | ClipEffect | clip region | ❌ cumulative | **YES** |
35
+ * | ClipPathEffect | clip region | ❌ cumulative | **YES** |
36
+ * | OpacityEffect | globalAlpha | ✅ scalar | NO |
37
+ * | BlendEffect | globalCompositeOp | ✅ scalar | NO |
38
+ * | FilterEffect | filter + shadow | ✅ string+vec | NO |
39
+ *
40
+ * When the batch contains *only* lightweight effects (opacity / blend / filter)
41
+ * we skip `save()` entirely and manually reset properties on pop.
42
+ *
43
+ * When the batch contains at least one heavyweight effect (transform / clip /
44
+ * clip-path) we call `save()` **once** before the first heavyweight effect and
45
+ * `restore()` **once** when that effect is popped.
46
+ */
47
+ class EffectsRenderer {
48
+ constructor(deps, pathCallback) {
49
+ this.activeEffects = [];
50
+ /** Whether a canvas state save was performed for the current batch. */
51
+ this.didSave = false;
52
+ /** Index (0-based, from start of activeEffects array) of the last
53
+ * heavyweight effect in the batch — the one whose pop triggers
54
+ * restore(). Set to -1 when no save was performed. */
55
+ this.saveAtDepth = -1;
56
+ this.ctx = deps.ctx;
57
+ this.pathCallback = pathCallback;
58
+ }
59
+ /**
60
+ * Apply multiple effects.
61
+ * Clears existing effects and applies new ones.
62
+ */
63
+ applyEffects(effects) {
64
+ // ── 1. Pop all previously active effects ──────────────────────
65
+ while (this.activeEffects.length) {
66
+ this.popEffect();
67
+ }
68
+ // ── 2. Determine whether to save canvas state ─────────────────
69
+ this.didSave = false;
70
+ this.saveAtDepth = -1;
71
+ const isHeavy = (e) => (0, effects_1.isTransformEffect)(e) || (0, effects_1.isClipEffect)(e) || (0, effects_1.isClipPathEffect)(e);
72
+ // Pre-compute the index of the *last* heavyweight effect so pop
73
+ // can reliably match it regardless of how many heavyweight effects
74
+ // are in the batch (the save was issued before the first, but the
75
+ // restore must happen when the LAST heavyweight is popped).
76
+ const lastHeavyIdx = effects.reduceRight((found, e, idx) => (found !== -1 ? found : isHeavy(e) ? idx : -1), -1);
77
+ // ── 3. Apply each effect ──────────────────────────────────────
78
+ for (let i = 0; i < effects.length; i++) {
79
+ const effect = effects[i];
80
+ if (isHeavy(effect)) {
81
+ if (!this.didSave) {
82
+ this.ctx.save();
83
+ this.didSave = true;
84
+ }
85
+ if (i === lastHeavyIdx) {
86
+ this.saveAtDepth = this.activeEffects.length;
87
+ }
88
+ }
89
+ this.applyEffect(effect);
90
+ }
91
+ }
92
+ /**
93
+ * Apply a single effect (called internally by applyEffects).
94
+ */
95
+ applyEffect(effect) {
96
+ if ((0, effects_1.isTransformEffect)(effect)) {
97
+ this.ctx.translate(effect.offsetX, effect.offsetY);
98
+ this.ctx.transform(effect.matrix[0], effect.matrix[1], effect.matrix[2], effect.matrix[3], effect.matrix[4], effect.matrix[5]);
99
+ this.ctx.translate(-effect.offsetX, -effect.offsetY);
100
+ }
101
+ else if ((0, effects_1.isClipEffect)(effect)) {
102
+ this.pathCallback.path(effect.path);
103
+ this.ctx.clip();
104
+ }
105
+ else if ((0, effects_1.isClipPathEffect)(effect)) {
106
+ effect.applyClip(this.ctx);
107
+ }
108
+ else if ((0, effects_1.isOpacityEffect)(effect)) {
109
+ // Multiply into current globalAlpha so nested opacity works
110
+ // without save/restore overhead.
111
+ this.ctx.globalAlpha *= effect.opacity;
112
+ }
113
+ else if ((0, effects_1.isBlendEffect)(effect)) {
114
+ this.ctx.globalCompositeOperation = effect.compositeOperation;
115
+ }
116
+ else if ((0, effects_1.isFilterEffect)(effect)) {
117
+ // drop-shadow() is rendered via ctx.shadow* to avoid canvas
118
+ // taint; remaining filters go through ctx.filter.
119
+ this.ctx.filter = effect.safeFilterString || 'none';
120
+ if (effect.shadow) {
121
+ this.ctx.shadowOffsetX = effect.shadow.offsetX;
122
+ this.ctx.shadowOffsetY = effect.shadow.offsetY;
123
+ this.ctx.shadowBlur = effect.shadow.blur;
124
+ this.ctx.shadowColor = effect.shadow.color;
125
+ }
126
+ }
127
+ this.activeEffects.push(effect);
128
+ }
129
+ /**
130
+ * Remove the most recent effect.
131
+ * Restores canvas state if needed.
132
+ */
133
+ popEffect() {
134
+ if (this.activeEffects.length === 0)
135
+ return;
136
+ // If the effect being popped is the one that triggered the save,
137
+ // restore the canvas state now.
138
+ if (this.didSave && this.activeEffects.length - 1 === this.saveAtDepth) {
139
+ this.ctx.restore();
140
+ this.didSave = false;
141
+ this.saveAtDepth = -1;
142
+ }
143
+ this.activeEffects.pop();
144
+ // If the batch had ONLY lightweight effects (no save was performed),
145
+ // reset properties to their defaults. We only do this when all effects
146
+ // have been popped (activeEffects is empty), so properties don't
147
+ // flip mid-batch.
148
+ if (!this.didSave && this.activeEffects.length === 0) {
149
+ this.ctx.globalAlpha = 1;
150
+ this.ctx.globalCompositeOperation = 'source-over';
151
+ this.ctx.filter = 'none';
152
+ this.ctx.shadowOffsetX = 0;
153
+ this.ctx.shadowOffsetY = 0;
154
+ this.ctx.shadowBlur = 0;
155
+ this.ctx.shadowColor = 'rgba(0, 0, 0, 0)';
156
+ }
157
+ }
158
+ /**
159
+ * Get the current number of active effects.
160
+ */
161
+ getActiveEffectCount() {
162
+ return this.activeEffects.length;
163
+ }
164
+ /**
165
+ * Check if there are any active effects.
166
+ */
167
+ hasActiveEffects() {
168
+ return this.activeEffects.length > 0;
169
+ }
170
+ }
171
+ exports.EffectsRenderer = EffectsRenderer;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /**
3
+ * Font measurement utility
4
+ *
5
+ * Provides Canvas API-based baseline measurement that works correctly with
6
+ * webfonts (which may not be loaded in the original document) and system fonts.
7
+ *
8
+ * Fallback chain:
9
+ * 1. fontBoundingBoxAscent — font-level metric (Chrome 99+, FF 116+, Safari 17.4+)
10
+ * 2. actualBoundingBoxAscent — glyph-level metric (widely supported)
11
+ * 3. fallback value — coarse CSS fallback
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.measureBaseline = void 0;
15
+ const SAMPLE_TEXT = 'Mg'; // characters with both ascender and descender
16
+ /**
17
+ * Measure the baseline ascent for the currently set font.
18
+ *
19
+ * @param ctx - Canvas 2D rendering context with ctx.font already set
20
+ * @param fallback - Fallback value when no metrics are available (e.g. fontSize.number)
21
+ * @returns The distance from the text baseline to the top of the bounding box
22
+ */
23
+ const measureBaseline = (ctx, fallback) => {
24
+ const tm = ctx.measureText(SAMPLE_TEXT);
25
+ const fmAscent = tm.fontBoundingBoxAscent;
26
+ const ascent = fmAscent !== undefined && !Number.isNaN(fmAscent) ? fmAscent : tm.actualBoundingBoxAscent;
27
+ return ascent !== undefined && !Number.isNaN(ascent) ? ascent : fallback;
28
+ };
29
+ exports.measureBaseline = measureBaseline;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ForeignObjectRenderer = void 0;
4
+ const features_1 = require("../../core/features");
5
+ const color_utilities_1 = require("../../css/types/color-utilities");
6
+ class ForeignObjectRenderer {
7
+ constructor(context, options) {
8
+ this.context = context;
9
+ this.options = options;
10
+ this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
11
+ const ctx = this.canvas.getContext('2d');
12
+ if (!ctx) {
13
+ throw new Error('Failed to get 2D rendering context from canvas');
14
+ }
15
+ this.ctx = ctx;
16
+ this.canvas.width = Math.floor(options.width * options.scale);
17
+ this.canvas.height = Math.floor(options.height * options.scale);
18
+ this.canvas.style.width = `${options.width}px`;
19
+ this.canvas.style.height = `${options.height}px`;
20
+ this.ctx.scale(this.options.scale, this.options.scale);
21
+ this.ctx.translate(-options.x, -options.y);
22
+ this.context.logger.debug(`EXPERIMENTAL ForeignObject renderer initialized (${options.width}x${options.height} at ${options.x},${options.y}) with scale ${options.scale}`);
23
+ }
24
+ async render(element) {
25
+ if (this.options.signal?.aborted) {
26
+ throw new DOMException('The operation was aborted.', 'AbortError');
27
+ }
28
+ const svg = (0, features_1.createForeignObjectSVG)(this.options.width * this.options.scale, this.options.height * this.options.scale, this.options.scale, this.options.scale, element);
29
+ const img = await (0, features_1.loadSerializedSVG)(svg);
30
+ if (this.options.backgroundColor) {
31
+ this.ctx.fillStyle = (0, color_utilities_1.asString)(this.options.backgroundColor);
32
+ this.ctx.fillRect(0, 0, this.options.width * this.options.scale, this.options.height * this.options.scale);
33
+ }
34
+ this.ctx.drawImage(img, -this.options.x * this.options.scale, -this.options.y * this.options.scale);
35
+ return this.canvas;
36
+ }
37
+ }
38
+ exports.ForeignObjectRenderer = ForeignObjectRenderer;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextDecorationRenderer = void 0;
4
+ const color_utilities_1 = require("../../../css/types/color-utilities");
5
+ class TextDecorationRenderer {
6
+ constructor(ctx) {
7
+ this.ctx = ctx;
8
+ }
9
+ render(bounds, styles) {
10
+ this.ctx.fillStyle = (0, color_utilities_1.asString)(styles.textDecorationColor || styles.color);
11
+ let thickness = 1;
12
+ if (typeof styles.textDecorationThickness === 'number') {
13
+ thickness = styles.textDecorationThickness;
14
+ }
15
+ else if (styles.textDecorationThickness === 'from-font') {
16
+ thickness = Math.max(1, Math.floor(styles.fontSize.number * 0.05));
17
+ }
18
+ let underlineOffset = 0;
19
+ if (typeof styles.textUnderlineOffset === 'number') {
20
+ underlineOffset = styles.textUnderlineOffset;
21
+ }
22
+ const decorationStyle = styles.textDecorationStyle;
23
+ styles.textDecorationLine.forEach((line) => {
24
+ let y = 0;
25
+ switch (line) {
26
+ case 1 /* TEXT_DECORATION_LINE.UNDERLINE */:
27
+ y = bounds.top + bounds.height - thickness + underlineOffset;
28
+ break;
29
+ case 2 /* TEXT_DECORATION_LINE.OVERLINE */:
30
+ y = bounds.top;
31
+ break;
32
+ case 3 /* TEXT_DECORATION_LINE.LINE_THROUGH */:
33
+ y = bounds.top + (bounds.height / 2 - thickness / 2);
34
+ break;
35
+ default:
36
+ return;
37
+ }
38
+ this.draw(bounds.left, y, bounds.width, thickness, decorationStyle);
39
+ });
40
+ }
41
+ draw(x, y, width, thickness, style) {
42
+ switch (style) {
43
+ case 0 /* TEXT_DECORATION_STYLE.SOLID */:
44
+ this.ctx.fillRect(x, y, width, thickness);
45
+ break;
46
+ case 1 /* TEXT_DECORATION_STYLE.DOUBLE */: {
47
+ const gap = Math.max(1, thickness);
48
+ this.ctx.fillRect(x, y, width, thickness);
49
+ this.ctx.fillRect(x, y + thickness + gap, width, thickness);
50
+ break;
51
+ }
52
+ case 2 /* TEXT_DECORATION_STYLE.DOTTED */:
53
+ this.drawPattern(x, y, width, thickness, [thickness, thickness * 2]);
54
+ break;
55
+ case 3 /* TEXT_DECORATION_STYLE.DASHED */:
56
+ this.drawPattern(x, y, width, thickness, [thickness * 3, thickness * 2]);
57
+ break;
58
+ case 4 /* TEXT_DECORATION_STYLE.WAVY */:
59
+ this.drawWavy(x, y, width, thickness);
60
+ break;
61
+ default:
62
+ this.ctx.fillRect(x, y, width, thickness);
63
+ }
64
+ }
65
+ drawPattern(x, y, width, thickness, dash) {
66
+ this.ctx.save();
67
+ this.ctx.beginPath();
68
+ this.ctx.setLineDash(dash);
69
+ this.ctx.lineWidth = thickness;
70
+ this.ctx.strokeStyle = this.ctx.fillStyle;
71
+ this.ctx.moveTo(x, y + thickness / 2);
72
+ this.ctx.lineTo(x + width, y + thickness / 2);
73
+ this.ctx.stroke();
74
+ this.ctx.restore();
75
+ }
76
+ drawWavy(x, y, width, thickness) {
77
+ this.ctx.save();
78
+ this.ctx.beginPath();
79
+ this.ctx.lineWidth = thickness;
80
+ this.ctx.strokeStyle = this.ctx.fillStyle;
81
+ const amplitude = thickness * 2;
82
+ const wavelength = thickness * 4;
83
+ let currentX = x;
84
+ this.ctx.moveTo(currentX, y + thickness / 2);
85
+ while (currentX < x + width) {
86
+ const nextX = Math.min(currentX + wavelength / 2, x + width);
87
+ this.ctx.quadraticCurveTo(currentX + wavelength / 4, y + thickness / 2 - amplitude, nextX, y + thickness / 2);
88
+ currentX = nextX;
89
+ if (currentX < x + width) {
90
+ const nextX2 = Math.min(currentX + wavelength / 2, x + width);
91
+ this.ctx.quadraticCurveTo(currentX + wavelength / 4, y + thickness / 2 + amplitude, nextX2, y + thickness / 2);
92
+ currentX = nextX2;
93
+ }
94
+ }
95
+ this.ctx.stroke();
96
+ this.ctx.restore();
97
+ }
98
+ }
99
+ exports.TextDecorationRenderer = TextDecorationRenderer;