@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,367 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCounterText = exports.CounterState = void 0;
4
+ const css_line_break_1 = require("css-line-break");
5
+ const bitwise_1 = require("../../../core/bitwise");
6
+ class CounterState {
7
+ constructor() {
8
+ this.counters = {};
9
+ }
10
+ getCounterValue(name) {
11
+ const counter = this.counters[name];
12
+ if (counter && counter.length) {
13
+ return counter[counter.length - 1];
14
+ }
15
+ return 1;
16
+ }
17
+ getCounterValues(name) {
18
+ const counter = this.counters[name];
19
+ return counter ? counter : [];
20
+ }
21
+ pop(counters) {
22
+ counters.forEach((counter) => this.counters[counter].pop());
23
+ }
24
+ parse(style) {
25
+ const counterIncrement = style.counterIncrement;
26
+ const counterReset = style.counterReset;
27
+ let canReset = true;
28
+ if (counterIncrement !== null) {
29
+ counterIncrement.forEach((entry) => {
30
+ const counter = this.counters[entry.counter];
31
+ if (counter && entry.increment !== 0) {
32
+ canReset = false;
33
+ if (!counter.length) {
34
+ counter.push(1);
35
+ }
36
+ counter[Math.max(0, counter.length - 1)] += entry.increment;
37
+ }
38
+ });
39
+ }
40
+ const counterNames = [];
41
+ if (canReset) {
42
+ counterReset.forEach((entry) => {
43
+ let counter = this.counters[entry.counter];
44
+ counterNames.push(entry.counter);
45
+ if (!counter) {
46
+ counter = this.counters[entry.counter] = [];
47
+ }
48
+ counter.push(entry.reset);
49
+ });
50
+ }
51
+ return counterNames;
52
+ }
53
+ }
54
+ exports.CounterState = CounterState;
55
+ const ROMAN_UPPER = {
56
+ integers: [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1],
57
+ values: ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
58
+ };
59
+ const ARMENIAN = {
60
+ integers: [
61
+ 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 90, 80, 70,
62
+ 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
63
+ ],
64
+ values: [
65
+ 'Ք',
66
+ 'Փ',
67
+ 'Ւ',
68
+ 'Ց',
69
+ 'Ր',
70
+ 'Տ',
71
+ 'Վ',
72
+ 'Ս',
73
+ 'Ռ',
74
+ 'Ջ',
75
+ 'Պ',
76
+ 'Չ',
77
+ 'Ո',
78
+ 'Շ',
79
+ 'Ն',
80
+ 'Յ',
81
+ 'Մ',
82
+ 'Ճ',
83
+ 'Ղ',
84
+ 'Ձ',
85
+ 'Հ',
86
+ 'Կ',
87
+ 'Ծ',
88
+ 'Խ',
89
+ 'Լ',
90
+ 'Ի',
91
+ 'Ժ',
92
+ 'Թ',
93
+ 'Ը',
94
+ 'Է',
95
+ 'Զ',
96
+ 'Ե',
97
+ 'Դ',
98
+ 'Գ',
99
+ 'Բ',
100
+ 'Ա'
101
+ ]
102
+ };
103
+ const HEBREW = {
104
+ integers: [
105
+ 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20,
106
+ 19, 18, 17, 16, 15, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
107
+ ],
108
+ values: [
109
+ 'י׳',
110
+ 'ט׳',
111
+ 'ח׳',
112
+ 'ז׳',
113
+ 'ו׳',
114
+ 'ה׳',
115
+ 'ד׳',
116
+ 'ג׳',
117
+ 'ב׳',
118
+ 'א׳',
119
+ 'ת',
120
+ 'ש',
121
+ 'ר',
122
+ 'ק',
123
+ 'צ',
124
+ 'פ',
125
+ 'ע',
126
+ 'ס',
127
+ 'נ',
128
+ 'מ',
129
+ 'ל',
130
+ 'כ',
131
+ 'יט',
132
+ 'יח',
133
+ 'יז',
134
+ 'טז',
135
+ 'טו',
136
+ 'י',
137
+ 'ט',
138
+ 'ח',
139
+ 'ז',
140
+ 'ו',
141
+ 'ה',
142
+ 'ד',
143
+ 'ג',
144
+ 'ב',
145
+ 'א'
146
+ ]
147
+ };
148
+ const GEORGIAN = {
149
+ integers: [
150
+ 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 90,
151
+ 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
152
+ ],
153
+ values: [
154
+ 'ჵ',
155
+ 'ჰ',
156
+ 'ჯ',
157
+ 'ჴ',
158
+ 'ხ',
159
+ 'ჭ',
160
+ 'წ',
161
+ 'ძ',
162
+ 'ც',
163
+ 'ჩ',
164
+ 'შ',
165
+ 'ყ',
166
+ 'ღ',
167
+ 'ქ',
168
+ 'ფ',
169
+ 'ჳ',
170
+ 'ტ',
171
+ 'ს',
172
+ 'რ',
173
+ 'ჟ',
174
+ 'პ',
175
+ 'ო',
176
+ 'ჲ',
177
+ 'ნ',
178
+ 'მ',
179
+ 'ლ',
180
+ 'კ',
181
+ 'ი',
182
+ 'თ',
183
+ 'ჱ',
184
+ 'ზ',
185
+ 'ვ',
186
+ 'ე',
187
+ 'დ',
188
+ 'გ',
189
+ 'ბ',
190
+ 'ა'
191
+ ]
192
+ };
193
+ const createAdditiveCounter = (value, min, max, symbols, fallback, suffix) => {
194
+ if (value < min || value > max) {
195
+ return (0, exports.createCounterText)(value, fallback, suffix.length > 0);
196
+ }
197
+ return (symbols.integers.reduce((string, integer, index) => {
198
+ while (value >= integer) {
199
+ value -= integer;
200
+ string += symbols.values[index];
201
+ }
202
+ return string;
203
+ }, '') + suffix);
204
+ };
205
+ const createCounterStyleWithSymbolResolver = (value, codePointRangeLength, isNumeric, resolver) => {
206
+ let string = '';
207
+ do {
208
+ if (!isNumeric) {
209
+ value--;
210
+ }
211
+ string = resolver(value) + string;
212
+ value /= codePointRangeLength;
213
+ } while (value * codePointRangeLength >= codePointRangeLength);
214
+ return string;
215
+ };
216
+ const createCounterStyleFromRange = (value, codePointRangeStart, codePointRangeEnd, isNumeric, suffix) => {
217
+ const codePointRangeLength = codePointRangeEnd - codePointRangeStart + 1;
218
+ return ((value < 0 ? '-' : '') +
219
+ (createCounterStyleWithSymbolResolver(Math.abs(value), codePointRangeLength, isNumeric, (codePoint) => (0, css_line_break_1.fromCodePoint)(Math.floor(codePoint % codePointRangeLength) + codePointRangeStart)) +
220
+ suffix));
221
+ };
222
+ const createCounterStyleFromSymbols = (value, symbols, suffix = '. ') => {
223
+ const codePointRangeLength = symbols.length;
224
+ return (createCounterStyleWithSymbolResolver(Math.abs(value), codePointRangeLength, false, (codePoint) => symbols[Math.floor(codePoint % codePointRangeLength)]) + suffix);
225
+ };
226
+ const CJK_ZEROS = 1 << 0;
227
+ const CJK_TEN_COEFFICIENTS = 1 << 1;
228
+ const CJK_TEN_HIGH_COEFFICIENTS = 1 << 2;
229
+ const CJK_HUNDRED_COEFFICIENTS = 1 << 3;
230
+ const createCJKCounter = (value, numbers, multipliers, negativeSign, suffix, flags) => {
231
+ if (value < -9999 || value > 9999) {
232
+ return (0, exports.createCounterText)(value, 4 /* LIST_STYLE_TYPE.CJK_DECIMAL */, suffix.length > 0);
233
+ }
234
+ let tmp = Math.abs(value);
235
+ let string = suffix;
236
+ if (tmp === 0) {
237
+ return numbers[0] + string;
238
+ }
239
+ for (let digit = 0; tmp > 0 && digit <= 4; digit++) {
240
+ const coefficient = tmp % 10;
241
+ if (coefficient === 0 && (0, bitwise_1.contains)(flags, CJK_ZEROS) && string !== '') {
242
+ string = numbers[coefficient] + string;
243
+ }
244
+ else if (coefficient > 1 ||
245
+ (coefficient === 1 && digit === 0) ||
246
+ (coefficient === 1 && digit === 1 && (0, bitwise_1.contains)(flags, CJK_TEN_COEFFICIENTS)) ||
247
+ (coefficient === 1 && digit === 1 && (0, bitwise_1.contains)(flags, CJK_TEN_HIGH_COEFFICIENTS) && value > 100) ||
248
+ (coefficient === 1 && digit > 1 && (0, bitwise_1.contains)(flags, CJK_HUNDRED_COEFFICIENTS))) {
249
+ string = numbers[coefficient] + (digit > 0 ? multipliers[digit - 1] : '') + string;
250
+ }
251
+ else if (coefficient === 1 && digit > 0) {
252
+ string = multipliers[digit - 1] + string;
253
+ }
254
+ tmp = Math.floor(tmp / 10);
255
+ }
256
+ return (value < 0 ? negativeSign : '') + string;
257
+ };
258
+ const CHINESE_INFORMAL_MULTIPLIERS = '十百千萬';
259
+ const CHINESE_FORMAL_MULTIPLIERS = '拾佰仟萬';
260
+ const JAPANESE_NEGATIVE = 'マイナス';
261
+ const KOREAN_NEGATIVE = '마이너스';
262
+ const createCounterText = (value, type, appendSuffix) => {
263
+ const defaultSuffix = appendSuffix ? '. ' : '';
264
+ const cjkSuffix = appendSuffix ? '、' : '';
265
+ const koreanSuffix = appendSuffix ? ', ' : '';
266
+ const spaceSuffix = appendSuffix ? ' ' : '';
267
+ switch (type) {
268
+ case 0 /* LIST_STYLE_TYPE.DISC */:
269
+ return '•' + spaceSuffix;
270
+ case 1 /* LIST_STYLE_TYPE.CIRCLE */:
271
+ return '◦' + spaceSuffix;
272
+ case 2 /* LIST_STYLE_TYPE.SQUARE */:
273
+ return '◾' + spaceSuffix;
274
+ case 5 /* LIST_STYLE_TYPE.DECIMAL_LEADING_ZERO */:
275
+ const string = createCounterStyleFromRange(value, 48, 57, true, defaultSuffix);
276
+ return string.length < 4 ? `0${string}` : string;
277
+ case 4 /* LIST_STYLE_TYPE.CJK_DECIMAL */:
278
+ return createCounterStyleFromSymbols(value, '〇一二三四五六七八九', cjkSuffix);
279
+ case 6 /* LIST_STYLE_TYPE.LOWER_ROMAN */:
280
+ return createAdditiveCounter(value, 1, 3999, ROMAN_UPPER, 3 /* LIST_STYLE_TYPE.DECIMAL */, defaultSuffix).toLowerCase();
281
+ case 7 /* LIST_STYLE_TYPE.UPPER_ROMAN */:
282
+ return createAdditiveCounter(value, 1, 3999, ROMAN_UPPER, 3 /* LIST_STYLE_TYPE.DECIMAL */, defaultSuffix);
283
+ case 8 /* LIST_STYLE_TYPE.LOWER_GREEK */:
284
+ return createCounterStyleFromRange(value, 945, 969, false, defaultSuffix);
285
+ case 9 /* LIST_STYLE_TYPE.LOWER_ALPHA */:
286
+ return createCounterStyleFromRange(value, 97, 122, false, defaultSuffix);
287
+ case 10 /* LIST_STYLE_TYPE.UPPER_ALPHA */:
288
+ return createCounterStyleFromRange(value, 65, 90, false, defaultSuffix);
289
+ case 11 /* LIST_STYLE_TYPE.ARABIC_INDIC */:
290
+ return createCounterStyleFromRange(value, 1632, 1641, true, defaultSuffix);
291
+ case 12 /* LIST_STYLE_TYPE.ARMENIAN */:
292
+ case 49 /* LIST_STYLE_TYPE.UPPER_ARMENIAN */:
293
+ return createAdditiveCounter(value, 1, 9999, ARMENIAN, 3 /* LIST_STYLE_TYPE.DECIMAL */, defaultSuffix);
294
+ case 35 /* LIST_STYLE_TYPE.LOWER_ARMENIAN */:
295
+ return createAdditiveCounter(value, 1, 9999, ARMENIAN, 3 /* LIST_STYLE_TYPE.DECIMAL */, defaultSuffix).toLowerCase();
296
+ case 13 /* LIST_STYLE_TYPE.BENGALI */:
297
+ return createCounterStyleFromRange(value, 2534, 2543, true, defaultSuffix);
298
+ case 14 /* LIST_STYLE_TYPE.CAMBODIAN */:
299
+ case 30 /* LIST_STYLE_TYPE.KHMER */:
300
+ return createCounterStyleFromRange(value, 6112, 6121, true, defaultSuffix);
301
+ case 15 /* LIST_STYLE_TYPE.CJK_EARTHLY_BRANCH */:
302
+ return createCounterStyleFromSymbols(value, '子丑寅卯辰巳午未申酉戌亥', cjkSuffix);
303
+ case 16 /* LIST_STYLE_TYPE.CJK_HEAVENLY_STEM */:
304
+ return createCounterStyleFromSymbols(value, '甲乙丙丁戊己庚辛壬癸', cjkSuffix);
305
+ case 17 /* LIST_STYLE_TYPE.CJK_IDEOGRAPHIC */:
306
+ case 48 /* LIST_STYLE_TYPE.TRAD_CHINESE_INFORMAL */:
307
+ return createCJKCounter(value, '零一二三四五六七八九', CHINESE_INFORMAL_MULTIPLIERS, '負', cjkSuffix, CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
308
+ case 47 /* LIST_STYLE_TYPE.TRAD_CHINESE_FORMAL */:
309
+ return createCJKCounter(value, '零壹貳參肆伍陸柒捌玖', CHINESE_FORMAL_MULTIPLIERS, '負', cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
310
+ case 42 /* LIST_STYLE_TYPE.SIMP_CHINESE_INFORMAL */:
311
+ return createCJKCounter(value, '零一二三四五六七八九', CHINESE_INFORMAL_MULTIPLIERS, '负', cjkSuffix, CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
312
+ case 41 /* LIST_STYLE_TYPE.SIMP_CHINESE_FORMAL */:
313
+ return createCJKCounter(value, '零壹贰叁肆伍陆柒捌玖', CHINESE_FORMAL_MULTIPLIERS, '负', cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS);
314
+ case 26 /* LIST_STYLE_TYPE.JAPANESE_INFORMAL */:
315
+ return createCJKCounter(value, '〇一二三四五六七八九', '十百千万', JAPANESE_NEGATIVE, cjkSuffix, 0);
316
+ case 25 /* LIST_STYLE_TYPE.JAPANESE_FORMAL */:
317
+ return createCJKCounter(value, '零壱弐参四伍六七八九', '拾百千万', JAPANESE_NEGATIVE, cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS);
318
+ case 31 /* LIST_STYLE_TYPE.KOREAN_HANGUL_FORMAL */:
319
+ return createCJKCounter(value, '영일이삼사오육칠팔구', '십백천만', KOREAN_NEGATIVE, koreanSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS);
320
+ case 33 /* LIST_STYLE_TYPE.KOREAN_HANJA_INFORMAL */:
321
+ return createCJKCounter(value, '零一二三四五六七八九', '十百千萬', KOREAN_NEGATIVE, koreanSuffix, 0);
322
+ case 32 /* LIST_STYLE_TYPE.KOREAN_HANJA_FORMAL */:
323
+ return createCJKCounter(value, '零壹貳參四五六七八九', '拾百千', KOREAN_NEGATIVE, koreanSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS);
324
+ case 18 /* LIST_STYLE_TYPE.DEVANAGARI */:
325
+ return createCounterStyleFromRange(value, 0x966, 0x96f, true, defaultSuffix);
326
+ case 20 /* LIST_STYLE_TYPE.GEORGIAN */:
327
+ return createAdditiveCounter(value, 1, 19999, GEORGIAN, 3 /* LIST_STYLE_TYPE.DECIMAL */, defaultSuffix);
328
+ case 21 /* LIST_STYLE_TYPE.GUJARATI */:
329
+ return createCounterStyleFromRange(value, 0xae6, 0xaef, true, defaultSuffix);
330
+ case 22 /* LIST_STYLE_TYPE.GURMUKHI */:
331
+ return createCounterStyleFromRange(value, 0xa66, 0xa6f, true, defaultSuffix);
332
+ case 52 /* LIST_STYLE_TYPE.HEBREW */:
333
+ return createAdditiveCounter(value, 1, 10999, HEBREW, 3 /* LIST_STYLE_TYPE.DECIMAL */, defaultSuffix);
334
+ case 23 /* LIST_STYLE_TYPE.HIRAGANA */:
335
+ return createCounterStyleFromSymbols(value, 'あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわゐゑをん');
336
+ case 24 /* LIST_STYLE_TYPE.HIRAGANA_IROHA */:
337
+ return createCounterStyleFromSymbols(value, 'いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす');
338
+ case 27 /* LIST_STYLE_TYPE.KANNADA */:
339
+ return createCounterStyleFromRange(value, 0xce6, 0xcef, true, defaultSuffix);
340
+ case 28 /* LIST_STYLE_TYPE.KATAKANA */:
341
+ return createCounterStyleFromSymbols(value, 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヰヱヲン', cjkSuffix);
342
+ case 29 /* LIST_STYLE_TYPE.KATAKANA_IROHA */:
343
+ return createCounterStyleFromSymbols(value, 'イロハニホヘトチリヌルヲワカヨタレソツネナラムウヰノオクヤマケフコエテアサキユメミシヱヒモセス', cjkSuffix);
344
+ case 34 /* LIST_STYLE_TYPE.LAO */:
345
+ return createCounterStyleFromRange(value, 0xed0, 0xed9, true, defaultSuffix);
346
+ case 37 /* LIST_STYLE_TYPE.MONGOLIAN */:
347
+ return createCounterStyleFromRange(value, 0x1810, 0x1819, true, defaultSuffix);
348
+ case 38 /* LIST_STYLE_TYPE.MYANMAR */:
349
+ return createCounterStyleFromRange(value, 0x1040, 0x1049, true, defaultSuffix);
350
+ case 39 /* LIST_STYLE_TYPE.ORIYA */:
351
+ return createCounterStyleFromRange(value, 0xb66, 0xb6f, true, defaultSuffix);
352
+ case 40 /* LIST_STYLE_TYPE.PERSIAN */:
353
+ return createCounterStyleFromRange(value, 0x6f0, 0x6f9, true, defaultSuffix);
354
+ case 43 /* LIST_STYLE_TYPE.TAMIL */:
355
+ return createCounterStyleFromRange(value, 0xbe6, 0xbef, true, defaultSuffix);
356
+ case 44 /* LIST_STYLE_TYPE.TELUGU */:
357
+ return createCounterStyleFromRange(value, 0xc66, 0xc6f, true, defaultSuffix);
358
+ case 45 /* LIST_STYLE_TYPE.THAI */:
359
+ return createCounterStyleFromRange(value, 0xe50, 0xe59, true, defaultSuffix);
360
+ case 46 /* LIST_STYLE_TYPE.TIBETAN */:
361
+ return createCounterStyleFromRange(value, 0xf20, 0xf29, true, defaultSuffix);
362
+ case 3 /* LIST_STYLE_TYPE.DECIMAL */:
363
+ default:
364
+ return createCounterStyleFromRange(value, 48, 57, true, defaultSuffix);
365
+ }
366
+ };
367
+ exports.createCounterText = createCounterText;
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateRadius = exports.calculateGradientDirection = exports.processColorStops = exports.parseColorStop = void 0;
4
+ const color_1 = require("../color");
5
+ const length_percentage_1 = require("../length-percentage");
6
+ const parseColorStop = (context, args) => {
7
+ const color = color_1.color.parse(context, args[0]);
8
+ const stop = args[1];
9
+ return stop && (0, length_percentage_1.isLengthPercentage)(stop) ? { color, stop } : { color, stop: null };
10
+ };
11
+ exports.parseColorStop = parseColorStop;
12
+ const processColorStops = (stops, lineLength) => {
13
+ const first = stops[0];
14
+ const last = stops[stops.length - 1];
15
+ if (first.stop === null) {
16
+ first.stop = length_percentage_1.ZERO_LENGTH;
17
+ }
18
+ if (last.stop === null) {
19
+ last.stop = length_percentage_1.HUNDRED_PERCENT;
20
+ }
21
+ const processStops = [];
22
+ let previous = 0;
23
+ for (let i = 0; i < stops.length; i++) {
24
+ const stop = stops[i].stop;
25
+ if (stop !== null) {
26
+ const absoluteValue = (0, length_percentage_1.getAbsoluteValue)(stop, lineLength);
27
+ if (absoluteValue > previous) {
28
+ processStops.push(absoluteValue);
29
+ }
30
+ else {
31
+ processStops.push(previous);
32
+ }
33
+ previous = absoluteValue;
34
+ }
35
+ else {
36
+ processStops.push(null);
37
+ }
38
+ }
39
+ let gapBegin = null;
40
+ for (let i = 0; i < processStops.length; i++) {
41
+ const stop = processStops[i];
42
+ if (stop === null) {
43
+ if (gapBegin === null) {
44
+ gapBegin = i;
45
+ }
46
+ }
47
+ else if (gapBegin !== null) {
48
+ const gapLength = i - gapBegin;
49
+ const beforeGap = processStops[gapBegin - 1];
50
+ const gapValue = (stop - beforeGap) / (gapLength + 1);
51
+ for (let g = 1; g <= gapLength; g++) {
52
+ processStops[gapBegin + g - 1] = gapValue * g;
53
+ }
54
+ gapBegin = null;
55
+ }
56
+ }
57
+ return stops.map(({ color }, i) => {
58
+ return { color, stop: Math.max(Math.min(1, processStops[i] / lineLength), 0) };
59
+ });
60
+ };
61
+ exports.processColorStops = processColorStops;
62
+ const getAngleFromCorner = (corner, width, height) => {
63
+ const centerX = width / 2;
64
+ const centerY = height / 2;
65
+ const x = (0, length_percentage_1.getAbsoluteValue)(corner[0], width) - centerX;
66
+ const y = centerY - (0, length_percentage_1.getAbsoluteValue)(corner[1], height);
67
+ return (Math.atan2(y, x) + Math.PI * 2) % (Math.PI * 2);
68
+ };
69
+ const calculateGradientDirection = (angle, width, height) => {
70
+ const radian = typeof angle === 'number' ? angle : getAngleFromCorner(angle, width, height);
71
+ const lineLength = Math.abs(width * Math.sin(radian)) + Math.abs(height * Math.cos(radian));
72
+ const halfWidth = width / 2;
73
+ const halfHeight = height / 2;
74
+ const halfLineLength = lineLength / 2;
75
+ const yDiff = Math.sin(radian - Math.PI / 2) * halfLineLength;
76
+ const xDiff = Math.cos(radian - Math.PI / 2) * halfLineLength;
77
+ return [lineLength, halfWidth - xDiff, halfWidth + xDiff, halfHeight - yDiff, halfHeight + yDiff];
78
+ };
79
+ exports.calculateGradientDirection = calculateGradientDirection;
80
+ const distance = (a, b) => Math.sqrt(a * a + b * b);
81
+ const findCorner = (width, height, x, y, closest) => {
82
+ const corners = [
83
+ [0, 0],
84
+ [0, height],
85
+ [width, 0],
86
+ [width, height]
87
+ ];
88
+ return corners.reduce((stat, corner) => {
89
+ const [cx, cy] = corner;
90
+ const d = distance(x - cx, y - cy);
91
+ if (closest ? d < stat.optimumDistance : d > stat.optimumDistance) {
92
+ return {
93
+ optimumCorner: corner,
94
+ optimumDistance: d
95
+ };
96
+ }
97
+ return stat;
98
+ }, {
99
+ optimumDistance: closest ? Infinity : -Infinity,
100
+ optimumCorner: null
101
+ }).optimumCorner;
102
+ };
103
+ const calculateRadius = (gradient, x, y, width, height) => {
104
+ let rx = 0;
105
+ let ry = 0;
106
+ switch (gradient.size) {
107
+ case 0 /* CSSRadialExtent.CLOSEST_SIDE */:
108
+ // The ending shape is sized so that that it exactly meets the side of the gradient box closest to the gradient’s center.
109
+ // If the shape is an ellipse, it exactly meets the closest side in each dimension.
110
+ if (gradient.shape === 0 /* CSSRadialShape.CIRCLE */) {
111
+ rx = ry = Math.min(Math.abs(x), Math.abs(x - width), Math.abs(y), Math.abs(y - height));
112
+ }
113
+ else if (gradient.shape === 1 /* CSSRadialShape.ELLIPSE */) {
114
+ rx = Math.min(Math.abs(x), Math.abs(x - width));
115
+ ry = Math.min(Math.abs(y), Math.abs(y - height));
116
+ }
117
+ break;
118
+ case 2 /* CSSRadialExtent.CLOSEST_CORNER */:
119
+ // The ending shape is sized so that that it passes through the corner of the gradient box closest to the gradient’s center.
120
+ // If the shape is an ellipse, the ending shape is given the same aspect-ratio it would have if closest-side were specified.
121
+ if (gradient.shape === 0 /* CSSRadialShape.CIRCLE */) {
122
+ rx = ry = Math.min(distance(x, y), distance(x, y - height), distance(x - width, y), distance(x - width, y - height));
123
+ }
124
+ else if (gradient.shape === 1 /* CSSRadialShape.ELLIPSE */) {
125
+ // Compute the ratio ry/rx (which is to be the same as for "closest-side")
126
+ const c = Math.min(Math.abs(y), Math.abs(y - height)) / Math.min(Math.abs(x), Math.abs(x - width));
127
+ const [cx, cy] = findCorner(width, height, x, y, true);
128
+ rx = distance(cx - x, (cy - y) / c);
129
+ ry = c * rx;
130
+ }
131
+ break;
132
+ case 1 /* CSSRadialExtent.FARTHEST_SIDE */:
133
+ // Same as closest-side, except the ending shape is sized based on the farthest side(s)
134
+ if (gradient.shape === 0 /* CSSRadialShape.CIRCLE */) {
135
+ rx = ry = Math.max(Math.abs(x), Math.abs(x - width), Math.abs(y), Math.abs(y - height));
136
+ }
137
+ else if (gradient.shape === 1 /* CSSRadialShape.ELLIPSE */) {
138
+ rx = Math.max(Math.abs(x), Math.abs(x - width));
139
+ ry = Math.max(Math.abs(y), Math.abs(y - height));
140
+ }
141
+ break;
142
+ case 3 /* CSSRadialExtent.FARTHEST_CORNER */:
143
+ // Same as closest-corner, except the ending shape is sized based on the farthest corner.
144
+ // If the shape is an ellipse, the ending shape is given the same aspect ratio it would have if farthest-side were specified.
145
+ if (gradient.shape === 0 /* CSSRadialShape.CIRCLE */) {
146
+ rx = ry = Math.max(distance(x, y), distance(x, y - height), distance(x - width, y), distance(x - width, y - height));
147
+ }
148
+ else if (gradient.shape === 1 /* CSSRadialShape.ELLIPSE */) {
149
+ // Compute the ratio ry/rx (which is to be the same as for "farthest-side")
150
+ const c = Math.max(Math.abs(y), Math.abs(y - height)) / Math.max(Math.abs(x), Math.abs(x - width));
151
+ const [cx, cy] = findCorner(width, height, x, y, false);
152
+ rx = distance(cx - x, (cy - y) / c);
153
+ ry = c * rx;
154
+ }
155
+ break;
156
+ }
157
+ if (Array.isArray(gradient.size)) {
158
+ rx = (0, length_percentage_1.getAbsoluteValue)(gradient.size[0], width);
159
+ ry = gradient.size.length === 2 ? (0, length_percentage_1.getAbsoluteValue)(gradient.size[1], height) : rx;
160
+ }
161
+ return [rx, ry];
162
+ };
163
+ exports.calculateRadius = calculateRadius;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.linearGradient = void 0;
4
+ const parser_1 = require("../../syntax/parser");
5
+ const angle_1 = require("../angle");
6
+ const gradient_1 = require("./gradient");
7
+ const linearGradient = (context, tokens) => {
8
+ let angle = (0, angle_1.deg)(180);
9
+ const stops = [];
10
+ (0, parser_1.parseFunctionArgs)(tokens).forEach((arg, i) => {
11
+ if (i === 0) {
12
+ const firstToken = arg[0];
13
+ if (firstToken.type === 20 /* TokenType.IDENT_TOKEN */ && firstToken.value === 'to') {
14
+ angle = (0, angle_1.parseNamedSide)(arg);
15
+ return;
16
+ }
17
+ else if ((0, angle_1.isAngle)(firstToken)) {
18
+ angle = angle_1.angle.parse(context, firstToken);
19
+ return;
20
+ }
21
+ }
22
+ const colorStop = (0, gradient_1.parseColorStop)(context, arg);
23
+ stops.push(colorStop);
24
+ });
25
+ return { angle, stops, type: 1 /* CSSImageType.LINEAR_GRADIENT */ };
26
+ };
27
+ exports.linearGradient = linearGradient;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.radialGradient = exports.CONTAIN = exports.COVER = exports.ELLIPSE = exports.CIRCLE = exports.FARTHEST_CORNER = exports.CLOSEST_CORNER = exports.FARTHEST_SIDE = exports.CLOSEST_SIDE = void 0;
4
+ const parser_1 = require("../../syntax/parser");
5
+ const gradient_1 = require("./gradient");
6
+ const length_percentage_1 = require("../length-percentage");
7
+ const length_1 = require("../length");
8
+ exports.CLOSEST_SIDE = 'closest-side';
9
+ exports.FARTHEST_SIDE = 'farthest-side';
10
+ exports.CLOSEST_CORNER = 'closest-corner';
11
+ exports.FARTHEST_CORNER = 'farthest-corner';
12
+ exports.CIRCLE = 'circle';
13
+ exports.ELLIPSE = 'ellipse';
14
+ exports.COVER = 'cover';
15
+ exports.CONTAIN = 'contain';
16
+ const radialGradient = (context, tokens) => {
17
+ let shape = 0 /* CSSRadialShape.CIRCLE */;
18
+ let size = 3 /* CSSRadialExtent.FARTHEST_CORNER */;
19
+ const stops = [];
20
+ const position = [];
21
+ (0, parser_1.parseFunctionArgs)(tokens).forEach((arg, i) => {
22
+ let isColorStop = true;
23
+ if (i === 0) {
24
+ let isAtPosition = false;
25
+ isColorStop = arg.reduce((acc, token) => {
26
+ if (isAtPosition) {
27
+ if ((0, parser_1.isIdentToken)(token)) {
28
+ switch (token.value) {
29
+ case 'center':
30
+ position.push(length_percentage_1.FIFTY_PERCENT);
31
+ return acc;
32
+ case 'top':
33
+ case 'left':
34
+ position.push(length_percentage_1.ZERO_LENGTH);
35
+ return acc;
36
+ case 'right':
37
+ case 'bottom':
38
+ position.push(length_percentage_1.HUNDRED_PERCENT);
39
+ return acc;
40
+ }
41
+ }
42
+ else if ((0, length_percentage_1.isLengthPercentage)(token) || (0, length_1.isLength)(token)) {
43
+ position.push(token);
44
+ }
45
+ }
46
+ else if ((0, parser_1.isIdentToken)(token)) {
47
+ switch (token.value) {
48
+ case exports.CIRCLE:
49
+ shape = 0 /* CSSRadialShape.CIRCLE */;
50
+ return false;
51
+ case exports.ELLIPSE:
52
+ shape = 1 /* CSSRadialShape.ELLIPSE */;
53
+ return false;
54
+ case 'at':
55
+ isAtPosition = true;
56
+ return false;
57
+ case exports.CLOSEST_SIDE:
58
+ size = 0 /* CSSRadialExtent.CLOSEST_SIDE */;
59
+ return false;
60
+ case exports.COVER:
61
+ case exports.FARTHEST_SIDE:
62
+ size = 1 /* CSSRadialExtent.FARTHEST_SIDE */;
63
+ return false;
64
+ case exports.CONTAIN:
65
+ case exports.CLOSEST_CORNER:
66
+ size = 2 /* CSSRadialExtent.CLOSEST_CORNER */;
67
+ return false;
68
+ case exports.FARTHEST_CORNER:
69
+ size = 3 /* CSSRadialExtent.FARTHEST_CORNER */;
70
+ return false;
71
+ }
72
+ }
73
+ else if ((0, length_1.isLength)(token) || (0, length_percentage_1.isLengthPercentage)(token)) {
74
+ if (!Array.isArray(size)) {
75
+ size = [];
76
+ }
77
+ size.push(token);
78
+ return false;
79
+ }
80
+ return acc;
81
+ }, isColorStop);
82
+ }
83
+ if (isColorStop) {
84
+ const colorStop = (0, gradient_1.parseColorStop)(context, arg);
85
+ stops.push(colorStop);
86
+ }
87
+ });
88
+ return { size, shape, stops, position, type: 2 /* CSSImageType.RADIAL_GRADIENT */ };
89
+ };
90
+ exports.radialGradient = radialGradient;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.repeatingLinearGradient = void 0;
4
+ const linear_gradient_1 = require("./linear-gradient");
5
+ const repeatingLinearGradient = (context, tokens) => {
6
+ const gradient = (0, linear_gradient_1.linearGradient)(context, tokens);
7
+ return { ...gradient, type: 3 /* CSSImageType.REPEATING_LINEAR_GRADIENT */ };
8
+ };
9
+ exports.repeatingLinearGradient = repeatingLinearGradient;