html2canvas-pro 2.1.0 → 2.2.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 (266) hide show
  1. package/dist/html2canvas-pro.esm.js +10226 -10526
  2. package/dist/html2canvas-pro.esm.js.map +1 -1
  3. package/dist/html2canvas-pro.js +10869 -11171
  4. package/dist/html2canvas-pro.js.map +1 -1
  5. package/dist/html2canvas-pro.min.js +8 -8
  6. package/dist/lib/config.js +0 -22
  7. package/dist/lib/core/cache-storage.js +3 -40
  8. package/dist/lib/core/constants.js +25 -0
  9. package/dist/lib/core/context.js +1 -0
  10. package/dist/lib/core/features.js +3 -2
  11. package/dist/lib/core/validator.js +3 -3
  12. package/dist/lib/css/grouped/background-styles.js +36 -0
  13. package/dist/lib/css/grouped/border-styles.js +75 -0
  14. package/dist/lib/css/grouped/font-styles.js +93 -0
  15. package/dist/lib/css/grouped/layout-styles.js +127 -0
  16. package/dist/lib/css/index.js +74 -46
  17. package/dist/lib/css/layout/text.js +7 -6
  18. package/dist/lib/css/property-descriptors/background-blend-mode.js +41 -0
  19. package/dist/lib/css/property-descriptors/border-image-repeat.js +42 -0
  20. package/dist/lib/css/property-descriptors/border-image-slice.js +45 -0
  21. package/dist/lib/css/property-descriptors/border-image-source.js +21 -0
  22. package/dist/lib/css/property-descriptors/border-radius.js +1 -1
  23. package/dist/lib/css/property-descriptors/box-decoration-break.js +18 -0
  24. package/dist/lib/css/property-descriptors/counter-increment.js +17 -12
  25. package/dist/lib/css/property-descriptors/counter-reset.js +4 -12
  26. package/dist/lib/css/property-descriptors/filter.js +76 -0
  27. package/dist/lib/css/property-descriptors/font-variant-ligatures.js +34 -0
  28. package/dist/lib/css/property-descriptors/object-fit.js +1 -1
  29. package/dist/lib/css/property-descriptors/object-position.js +42 -0
  30. package/dist/lib/css/property-descriptors/visibility.js +1 -1
  31. package/dist/lib/css/property-descriptors/zoom.js +18 -0
  32. package/dist/lib/css/syntax/parser.js +0 -1
  33. package/dist/lib/css/types/color.js +5 -1
  34. package/dist/lib/css/types/functions/repeating-linear-gradient.js +9 -0
  35. package/dist/lib/css/types/image.js +12 -2
  36. package/dist/lib/css/types/length-percentage.js +6 -2
  37. package/dist/lib/css/types/safe-eval.js +80 -0
  38. package/dist/lib/dom/document-cloner.js +23 -163
  39. package/dist/lib/dom/slot-cloner.js +176 -0
  40. package/dist/lib/index.js +1 -17
  41. package/dist/lib/render/canvas/background-renderer.js +169 -30
  42. package/dist/lib/render/canvas/border-image-renderer.js +153 -0
  43. package/dist/lib/render/canvas/canvas-renderer.js +39 -190
  44. package/dist/lib/render/canvas/content-renderer.js +202 -0
  45. package/dist/lib/render/canvas/effects-renderer.js +3 -0
  46. package/dist/lib/render/canvas/foreignobject-renderer.js +5 -1
  47. package/dist/lib/render/canvas/text/text-decoration-renderer.js +99 -0
  48. package/dist/lib/render/canvas/text-renderer.js +100 -224
  49. package/dist/lib/render/effects.js +38 -3
  50. package/dist/lib/render/object-fit.js +19 -15
  51. package/dist/lib/render/stacking-context.js +11 -0
  52. package/dist/types/config.d.ts +0 -10
  53. package/dist/types/core/cache-storage.d.ts +0 -24
  54. package/dist/types/core/constants.d.ts +22 -0
  55. package/dist/types/core/context.d.ts +3 -0
  56. package/dist/types/core/performance-monitor.d.ts +4 -4
  57. package/dist/types/core/validator.d.ts +6 -8
  58. package/dist/types/css/grouped/background-styles.d.ts +16 -0
  59. package/dist/types/css/grouped/border-styles.d.ts +31 -0
  60. package/dist/types/css/grouped/font-styles.d.ts +35 -0
  61. package/dist/types/css/grouped/layout-styles.d.ts +46 -0
  62. package/dist/types/css/index.d.ts +30 -0
  63. package/dist/types/css/property-descriptors/background-blend-mode.d.ts +23 -0
  64. package/dist/types/css/property-descriptors/border-image-repeat.d.ts +12 -0
  65. package/dist/types/css/property-descriptors/border-image-slice.d.ts +10 -0
  66. package/dist/types/css/property-descriptors/border-image-source.d.ts +4 -0
  67. package/dist/types/css/property-descriptors/box-decoration-break.d.ts +6 -0
  68. package/dist/types/css/property-descriptors/counter-increment.d.ts +3 -0
  69. package/dist/types/css/property-descriptors/filter.d.ts +3 -0
  70. package/dist/types/css/property-descriptors/font-variant-ligatures.d.ts +14 -0
  71. package/dist/types/css/property-descriptors/object-position.d.ts +4 -0
  72. package/dist/types/css/property-descriptors/zoom.d.ts +3 -0
  73. package/dist/types/css/types/functions/repeating-linear-gradient.d.ts +4 -0
  74. package/dist/types/css/types/image.d.ts +4 -2
  75. package/dist/types/css/types/safe-eval.d.ts +8 -0
  76. package/dist/types/dom/document-cloner.d.ts +3 -44
  77. package/dist/types/dom/slot-cloner.d.ts +66 -0
  78. package/dist/types/index.d.ts +3 -7
  79. package/dist/types/options.d.ts +11 -0
  80. package/dist/types/render/canvas/background-renderer.d.ts +23 -0
  81. package/dist/types/render/canvas/border-image-renderer.d.ts +18 -0
  82. package/dist/types/render/canvas/canvas-renderer.d.ts +1 -0
  83. package/dist/types/render/canvas/content-renderer.d.ts +44 -0
  84. package/dist/types/render/canvas/text/text-decoration-renderer.d.ts +18 -0
  85. package/dist/types/render/canvas/text-renderer.d.ts +12 -1
  86. package/dist/types/render/effects.d.ts +12 -2
  87. package/dist/types/render/object-fit.d.ts +2 -1
  88. package/dist/types/render/renderer-interface.d.ts +11 -9
  89. package/package.json +7 -20
  90. package/dist/lib/dom/replaced-elements/pseudo-elements.js +0 -0
  91. package/dist/lib/invariant.js +0 -9
  92. package/dist/types/dom/replaced-elements/pseudo-elements.d.ts +0 -0
  93. package/dist/types/invariant.d.ts +0 -1
  94. package/src/__tests__/index.ts +0 -99
  95. package/src/config.ts +0 -107
  96. package/src/core/__mocks__/cache-storage.ts +0 -1
  97. package/src/core/__mocks__/context.ts +0 -19
  98. package/src/core/__mocks__/features.ts +0 -8
  99. package/src/core/__mocks__/logger.ts +0 -17
  100. package/src/core/__tests__/cache-storage.test.ts +0 -205
  101. package/src/core/__tests__/cache-storage.ts +0 -278
  102. package/src/core/__tests__/logger.ts +0 -29
  103. package/src/core/__tests__/validator.ts +0 -359
  104. package/src/core/bitwise.ts +0 -1
  105. package/src/core/cache-storage.ts +0 -315
  106. package/src/core/context.ts +0 -31
  107. package/src/core/debugger.ts +0 -32
  108. package/src/core/features.ts +0 -222
  109. package/src/core/logger.ts +0 -64
  110. package/src/core/origin-checker.ts +0 -57
  111. package/src/core/performance-monitor.ts +0 -241
  112. package/src/core/render-element.ts +0 -272
  113. package/src/core/util.ts +0 -1
  114. package/src/core/validator.ts +0 -593
  115. package/src/css/index.ts +0 -427
  116. package/src/css/layout/__mocks__/bounds.ts +0 -6
  117. package/src/css/layout/bounds.ts +0 -79
  118. package/src/css/layout/text.ts +0 -161
  119. package/src/css/property-descriptor.ts +0 -49
  120. package/src/css/property-descriptors/__tests__/background-tests.ts +0 -65
  121. package/src/css/property-descriptors/__tests__/clip-path.test.ts +0 -280
  122. package/src/css/property-descriptors/__tests__/font-family.ts +0 -25
  123. package/src/css/property-descriptors/__tests__/image-rendering-integration.test.ts +0 -153
  124. package/src/css/property-descriptors/__tests__/image-rendering-performance.test.ts +0 -175
  125. package/src/css/property-descriptors/__tests__/image-rendering.test.ts +0 -72
  126. package/src/css/property-descriptors/__tests__/paint-order.ts +0 -87
  127. package/src/css/property-descriptors/__tests__/text-shadow.ts +0 -94
  128. package/src/css/property-descriptors/__tests__/transform-tests.ts +0 -18
  129. package/src/css/property-descriptors/background-clip.ts +0 -30
  130. package/src/css/property-descriptors/background-color.ts +0 -9
  131. package/src/css/property-descriptors/background-image.ts +0 -27
  132. package/src/css/property-descriptors/background-origin.ts +0 -31
  133. package/src/css/property-descriptors/background-position.ts +0 -38
  134. package/src/css/property-descriptors/background-repeat.ts +0 -44
  135. package/src/css/property-descriptors/background-size.ts +0 -27
  136. package/src/css/property-descriptors/border-color.ts +0 -13
  137. package/src/css/property-descriptors/border-radius.ts +0 -19
  138. package/src/css/property-descriptors/border-style.ts +0 -34
  139. package/src/css/property-descriptors/border-width.ts +0 -20
  140. package/src/css/property-descriptors/box-shadow.ts +0 -60
  141. package/src/css/property-descriptors/clip-path.ts +0 -271
  142. package/src/css/property-descriptors/color.ts +0 -9
  143. package/src/css/property-descriptors/content.ts +0 -26
  144. package/src/css/property-descriptors/counter-increment.ts +0 -43
  145. package/src/css/property-descriptors/counter-reset.ts +0 -36
  146. package/src/css/property-descriptors/direction.ts +0 -23
  147. package/src/css/property-descriptors/display.ts +0 -117
  148. package/src/css/property-descriptors/duration.ts +0 -14
  149. package/src/css/property-descriptors/float.ts +0 -29
  150. package/src/css/property-descriptors/font-family.ts +0 -38
  151. package/src/css/property-descriptors/font-size.ts +0 -9
  152. package/src/css/property-descriptors/font-style.ts +0 -25
  153. package/src/css/property-descriptors/font-variant.ts +0 -12
  154. package/src/css/property-descriptors/font-weight.ts +0 -26
  155. package/src/css/property-descriptors/image-rendering.ts +0 -33
  156. package/src/css/property-descriptors/letter-spacing.ts +0 -25
  157. package/src/css/property-descriptors/line-break.ts +0 -22
  158. package/src/css/property-descriptors/line-height.ts +0 -22
  159. package/src/css/property-descriptors/list-style-image.ts +0 -19
  160. package/src/css/property-descriptors/list-style-position.ts +0 -22
  161. package/src/css/property-descriptors/list-style-type.ts +0 -179
  162. package/src/css/property-descriptors/margin.ts +0 -13
  163. package/src/css/property-descriptors/mix-blend-mode.ts +0 -35
  164. package/src/css/property-descriptors/object-fit.ts +0 -39
  165. package/src/css/property-descriptors/opacity.ts +0 -15
  166. package/src/css/property-descriptors/overflow-wrap.ts +0 -22
  167. package/src/css/property-descriptors/overflow.ts +0 -34
  168. package/src/css/property-descriptors/padding.ts +0 -14
  169. package/src/css/property-descriptors/paint-order.ts +0 -42
  170. package/src/css/property-descriptors/position.ts +0 -30
  171. package/src/css/property-descriptors/quotes.ts +0 -57
  172. package/src/css/property-descriptors/rotate.ts +0 -34
  173. package/src/css/property-descriptors/text-align.ts +0 -26
  174. package/src/css/property-descriptors/text-decoration-color.ts +0 -9
  175. package/src/css/property-descriptors/text-decoration-line.ts +0 -38
  176. package/src/css/property-descriptors/text-decoration-style.ts +0 -32
  177. package/src/css/property-descriptors/text-decoration-thickness.ts +0 -30
  178. package/src/css/property-descriptors/text-overflow.ts +0 -23
  179. package/src/css/property-descriptors/text-shadow.ts +0 -52
  180. package/src/css/property-descriptors/text-transform.ts +0 -27
  181. package/src/css/property-descriptors/text-underline-offset.ts +0 -27
  182. package/src/css/property-descriptors/transform-origin.ts +0 -29
  183. package/src/css/property-descriptors/transform.ts +0 -74
  184. package/src/css/property-descriptors/visibility.ts +0 -25
  185. package/src/css/property-descriptors/webkit-line-clamp.ts +0 -30
  186. package/src/css/property-descriptors/webkit-text-stroke-color.ts +0 -8
  187. package/src/css/property-descriptors/webkit-text-stroke-width.ts +0 -15
  188. package/src/css/property-descriptors/word-break.ts +0 -25
  189. package/src/css/property-descriptors/writing-mode.ts +0 -37
  190. package/src/css/property-descriptors/z-index.ts +0 -27
  191. package/src/css/syntax/__tests__/tokernizer-tests.ts +0 -29
  192. package/src/css/syntax/parser.ts +0 -188
  193. package/src/css/syntax/tokenizer.ts +0 -822
  194. package/src/css/type-descriptor.ts +0 -7
  195. package/src/css/types/__tests__/color-tests.ts +0 -147
  196. package/src/css/types/__tests__/image-tests.ts +0 -239
  197. package/src/css/types/angle.ts +0 -86
  198. package/src/css/types/color-math.ts +0 -22
  199. package/src/css/types/color-spaces/a98.ts +0 -86
  200. package/src/css/types/color-spaces/p3.ts +0 -92
  201. package/src/css/types/color-spaces/pro-photo.ts +0 -87
  202. package/src/css/types/color-spaces/rec2020.ts +0 -90
  203. package/src/css/types/color-spaces/srgb.ts +0 -87
  204. package/src/css/types/color-utilities.ts +0 -452
  205. package/src/css/types/color.ts +0 -485
  206. package/src/css/types/functions/-prefix-linear-gradient.ts +0 -35
  207. package/src/css/types/functions/-prefix-radial-gradient.ts +0 -106
  208. package/src/css/types/functions/-webkit-gradient.ts +0 -69
  209. package/src/css/types/functions/__tests__/radial-gradient.ts +0 -69
  210. package/src/css/types/functions/counter.ts +0 -511
  211. package/src/css/types/functions/gradient.ts +0 -206
  212. package/src/css/types/functions/linear-gradient.ts +0 -28
  213. package/src/css/types/functions/radial-gradient.ts +0 -101
  214. package/src/css/types/image.ts +0 -120
  215. package/src/css/types/index.ts +0 -1
  216. package/src/css/types/length-percentage.ts +0 -137
  217. package/src/css/types/length.ts +0 -7
  218. package/src/css/types/time.ts +0 -20
  219. package/src/dom/__mocks__/document-cloner.ts +0 -22
  220. package/src/dom/__tests__/dom-normalizer.test.ts +0 -133
  221. package/src/dom/__tests__/element-container.test.ts +0 -129
  222. package/src/dom/document-cloner.ts +0 -929
  223. package/src/dom/dom-normalizer.ts +0 -133
  224. package/src/dom/element-container.ts +0 -75
  225. package/src/dom/elements/li-element-container.ts +0 -10
  226. package/src/dom/elements/ol-element-container.ts +0 -12
  227. package/src/dom/elements/select-element-container.ts +0 -10
  228. package/src/dom/elements/textarea-element-container.ts +0 -9
  229. package/src/dom/node-parser.ts +0 -177
  230. package/src/dom/node-type-guards.ts +0 -70
  231. package/src/dom/replaced-elements/canvas-element-container.ts +0 -15
  232. package/src/dom/replaced-elements/iframe-element-container.ts +0 -55
  233. package/src/dom/replaced-elements/image-element-container.ts +0 -16
  234. package/src/dom/replaced-elements/index.ts +0 -5
  235. package/src/dom/replaced-elements/input-element-container.ts +0 -105
  236. package/src/dom/replaced-elements/pseudo-elements.ts +0 -0
  237. package/src/dom/replaced-elements/svg-element-container.ts +0 -23
  238. package/src/dom/text-container.ts +0 -42
  239. package/src/global.d.ts +0 -19
  240. package/src/index.ts +0 -82
  241. package/src/invariant.ts +0 -5
  242. package/src/options.ts +0 -55
  243. package/src/render/__tests__/object-fit.test.ts +0 -85
  244. package/src/render/background.ts +0 -298
  245. package/src/render/bezier-curve.ts +0 -47
  246. package/src/render/border.ts +0 -165
  247. package/src/render/bound-curves.ts +0 -388
  248. package/src/render/box-sizing.ts +0 -31
  249. package/src/render/canvas/__tests__/background-renderer.test.ts +0 -72
  250. package/src/render/canvas/__tests__/border-renderer.test.ts +0 -24
  251. package/src/render/canvas/__tests__/effects-renderer.test.ts +0 -32
  252. package/src/render/canvas/__tests__/text-renderer.test.ts +0 -471
  253. package/src/render/canvas/background-renderer.ts +0 -271
  254. package/src/render/canvas/border-renderer.ts +0 -224
  255. package/src/render/canvas/canvas-path.ts +0 -31
  256. package/src/render/canvas/canvas-renderer.ts +0 -641
  257. package/src/render/canvas/effects-renderer.ts +0 -130
  258. package/src/render/canvas/foreignobject-renderer.ts +0 -53
  259. package/src/render/canvas/text-renderer.ts +0 -700
  260. package/src/render/effects.ts +0 -75
  261. package/src/render/font-metrics.ts +0 -72
  262. package/src/render/object-fit.ts +0 -100
  263. package/src/render/path.ts +0 -37
  264. package/src/render/renderer-interface.ts +0 -28
  265. package/src/render/stacking-context.ts +0 -386
  266. package/src/render/vector.ts +0 -19
@@ -1,298 +0,0 @@
1
- import { Bounds } from '../css/layout/bounds';
2
- import { BACKGROUND_ORIGIN } from '../css/property-descriptors/background-origin';
3
- import { ElementContainer } from '../dom/element-container';
4
- import { BACKGROUND_SIZE, BackgroundSizeInfo } from '../css/property-descriptors/background-size';
5
- import { Vector } from './vector';
6
- import { BACKGROUND_REPEAT } from '../css/property-descriptors/background-repeat';
7
- import { getAbsoluteValue, getAbsoluteValueForTuple, isLengthPercentage } from '../css/types/length-percentage';
8
- import { CSSValue, isIdentToken } from '../css/syntax/parser';
9
- import { contentBox, paddingBox } from './box-sizing';
10
- import { Path } from './path';
11
- import { BACKGROUND_CLIP } from '../css/property-descriptors/background-clip';
12
-
13
- export const calculateBackgroundPositioningArea = (
14
- backgroundOrigin: BACKGROUND_ORIGIN,
15
- element: ElementContainer
16
- ): Bounds => {
17
- if (backgroundOrigin === BACKGROUND_ORIGIN.BORDER_BOX) {
18
- return element.bounds;
19
- }
20
-
21
- if (backgroundOrigin === BACKGROUND_ORIGIN.CONTENT_BOX) {
22
- return contentBox(element);
23
- }
24
-
25
- return paddingBox(element);
26
- };
27
-
28
- export const calculateBackgroundPaintingArea = (backgroundClip: BACKGROUND_CLIP, element: ElementContainer): Bounds => {
29
- if (backgroundClip === BACKGROUND_CLIP.BORDER_BOX) {
30
- return element.bounds;
31
- }
32
-
33
- if (backgroundClip === BACKGROUND_CLIP.CONTENT_BOX) {
34
- return contentBox(element);
35
- }
36
-
37
- return paddingBox(element);
38
- };
39
-
40
- export const calculateBackgroundRendering = (
41
- container: ElementContainer,
42
- index: number,
43
- intrinsicSize: [number | null, number | null, number | null]
44
- ): [Path[], number, number, number, number] => {
45
- const backgroundPositioningArea = calculateBackgroundPositioningArea(
46
- getBackgroundValueForIndex(container.styles.backgroundOrigin, index),
47
- container
48
- );
49
-
50
- const backgroundPaintingArea = calculateBackgroundPaintingArea(
51
- getBackgroundValueForIndex(container.styles.backgroundClip, index),
52
- container
53
- );
54
-
55
- const backgroundImageSize = calculateBackgroundSize(
56
- getBackgroundValueForIndex(container.styles.backgroundSize, index),
57
- intrinsicSize,
58
- backgroundPositioningArea
59
- );
60
-
61
- let [sizeWidth, sizeHeight] = backgroundImageSize;
62
-
63
- const position = getAbsoluteValueForTuple(
64
- getBackgroundValueForIndex(container.styles.backgroundPosition, index),
65
- backgroundPositioningArea.width - sizeWidth,
66
- backgroundPositioningArea.height - sizeHeight
67
- );
68
-
69
- const path = calculateBackgroundRepeatPath(
70
- getBackgroundValueForIndex(container.styles.backgroundRepeat, index),
71
- position,
72
- backgroundImageSize,
73
- backgroundPositioningArea,
74
- backgroundPaintingArea
75
- );
76
-
77
- const offsetX = Math.round(backgroundPositioningArea.left + position[0]);
78
- const offsetY = Math.round(backgroundPositioningArea.top + position[1]);
79
-
80
- sizeWidth = Math.max(1, sizeWidth);
81
- sizeHeight = Math.max(1, sizeHeight);
82
-
83
- return [path, offsetX, offsetY, sizeWidth, sizeHeight];
84
- };
85
-
86
- export const isAuto = (token: CSSValue): boolean => isIdentToken(token) && token.value === BACKGROUND_SIZE.AUTO;
87
-
88
- const hasIntrinsicValue = (value: number | null): value is number => typeof value === 'number';
89
-
90
- export const calculateBackgroundSize = (
91
- size: BackgroundSizeInfo[],
92
- [intrinsicWidth, intrinsicHeight, intrinsicProportion]: [number | null, number | null, number | null],
93
- bounds: Bounds
94
- ): [number, number] => {
95
- const [first, second] = size;
96
-
97
- if (!first) {
98
- return [0, 0];
99
- }
100
-
101
- if (isLengthPercentage(first) && second && isLengthPercentage(second)) {
102
- return [getAbsoluteValue(first, bounds.width), getAbsoluteValue(second, bounds.height)];
103
- }
104
-
105
- const hasIntrinsicProportion = hasIntrinsicValue(intrinsicProportion);
106
-
107
- if (isIdentToken(first) && (first.value === BACKGROUND_SIZE.CONTAIN || first.value === BACKGROUND_SIZE.COVER)) {
108
- if (hasIntrinsicValue(intrinsicProportion)) {
109
- const targetRatio = bounds.width / bounds.height;
110
-
111
- return targetRatio < intrinsicProportion !== (first.value === BACKGROUND_SIZE.COVER)
112
- ? [bounds.width, bounds.width / intrinsicProportion]
113
- : [bounds.height * intrinsicProportion, bounds.height];
114
- }
115
-
116
- return [bounds.width, bounds.height];
117
- }
118
-
119
- const hasIntrinsicWidth = hasIntrinsicValue(intrinsicWidth);
120
- const hasIntrinsicHeight = hasIntrinsicValue(intrinsicHeight);
121
- const hasIntrinsicDimensions = hasIntrinsicWidth || hasIntrinsicHeight;
122
-
123
- // If the background-size is auto or auto auto:
124
- if (isAuto(first) && (!second || isAuto(second))) {
125
- // If the image has both horizontal and vertical intrinsic dimensions, it's rendered at that size.
126
- if (hasIntrinsicWidth && hasIntrinsicHeight) {
127
- return [intrinsicWidth as number, intrinsicHeight as number];
128
- }
129
-
130
- // If the image has no intrinsic dimensions and has no intrinsic proportions,
131
- // it's rendered at the size of the background positioning area.
132
-
133
- if (!hasIntrinsicProportion && !hasIntrinsicDimensions) {
134
- return [bounds.width, bounds.height];
135
- }
136
-
137
- // TODO If the image has no intrinsic dimensions but has intrinsic proportions, it's rendered as if contain had been specified instead.
138
-
139
- // If the image has only one intrinsic dimension and has intrinsic proportions, it's rendered at the size corresponding to that one dimension.
140
- // The other dimension is computed using the specified dimension and the intrinsic proportions.
141
- if (hasIntrinsicDimensions && hasIntrinsicProportion) {
142
- const width = hasIntrinsicWidth
143
- ? (intrinsicWidth as number)
144
- : (intrinsicHeight as number) * (intrinsicProportion as number);
145
- const height = hasIntrinsicHeight
146
- ? (intrinsicHeight as number)
147
- : (intrinsicWidth as number) / (intrinsicProportion as number);
148
- return [width, height];
149
- }
150
-
151
- // If the image has only one intrinsic dimension but has no intrinsic proportions,
152
- // it's rendered using the specified dimension and the other dimension of the background positioning area.
153
- const width = hasIntrinsicWidth ? (intrinsicWidth as number) : bounds.width;
154
- const height = hasIntrinsicHeight ? (intrinsicHeight as number) : bounds.height;
155
- return [width, height];
156
- }
157
-
158
- // If the image has intrinsic proportions, it's stretched to the specified dimension.
159
- // The unspecified dimension is computed using the specified dimension and the intrinsic proportions.
160
- if (hasIntrinsicProportion) {
161
- let width = 0;
162
- let height = 0;
163
- if (isLengthPercentage(first)) {
164
- width = getAbsoluteValue(first, bounds.width);
165
- } else if (isLengthPercentage(second)) {
166
- height = getAbsoluteValue(second, bounds.height);
167
- }
168
-
169
- if (isAuto(first)) {
170
- width = height * (intrinsicProportion as number);
171
- } else if (!second || isAuto(second)) {
172
- height = width / (intrinsicProportion as number);
173
- }
174
-
175
- return [width, height];
176
- }
177
-
178
- // If the image has no intrinsic proportions, it's stretched to the specified dimension.
179
- // The unspecified dimension is computed using the image's corresponding intrinsic dimension,
180
- // if there is one. If there is no such intrinsic dimension,
181
- // it becomes the corresponding dimension of the background positioning area.
182
-
183
- let width = null;
184
- let height = null;
185
-
186
- if (isLengthPercentage(first)) {
187
- width = getAbsoluteValue(first, bounds.width);
188
- } else if (second && isLengthPercentage(second)) {
189
- height = getAbsoluteValue(second, bounds.height);
190
- }
191
-
192
- if (width !== null && (!second || isAuto(second))) {
193
- height =
194
- hasIntrinsicWidth && hasIntrinsicHeight
195
- ? (width / (intrinsicWidth as number)) * (intrinsicHeight as number)
196
- : bounds.height;
197
- }
198
-
199
- if (height !== null && isAuto(first)) {
200
- width =
201
- hasIntrinsicWidth && hasIntrinsicHeight
202
- ? (height / (intrinsicHeight as number)) * (intrinsicWidth as number)
203
- : bounds.width;
204
- }
205
-
206
- if (width !== null && height !== null) {
207
- return [width, height];
208
- }
209
-
210
- throw new Error(`Unable to calculate background-size for element`);
211
- };
212
-
213
- export const getBackgroundValueForIndex = <T>(values: T[], index: number): T => {
214
- const value = values[index];
215
- if (typeof value === 'undefined') {
216
- return values[0];
217
- }
218
-
219
- return value;
220
- };
221
-
222
- export const calculateBackgroundRepeatPath = (
223
- repeat: BACKGROUND_REPEAT,
224
- [x, y]: [number, number],
225
- [width, height]: [number, number],
226
- backgroundPositioningArea: Bounds,
227
- backgroundPaintingArea: Bounds
228
- ): [Vector, Vector, Vector, Vector] => {
229
- switch (repeat) {
230
- case BACKGROUND_REPEAT.REPEAT_X:
231
- return [
232
- new Vector(Math.round(backgroundPositioningArea.left), Math.round(backgroundPositioningArea.top + y)),
233
- new Vector(
234
- Math.round(backgroundPositioningArea.left + backgroundPositioningArea.width),
235
- Math.round(backgroundPositioningArea.top + y)
236
- ),
237
- new Vector(
238
- Math.round(backgroundPositioningArea.left + backgroundPositioningArea.width),
239
- Math.round(height + backgroundPositioningArea.top + y)
240
- ),
241
- new Vector(
242
- Math.round(backgroundPositioningArea.left),
243
- Math.round(height + backgroundPositioningArea.top + y)
244
- )
245
- ];
246
- case BACKGROUND_REPEAT.REPEAT_Y:
247
- return [
248
- new Vector(Math.round(backgroundPositioningArea.left + x), Math.round(backgroundPositioningArea.top)),
249
- new Vector(
250
- Math.round(backgroundPositioningArea.left + x + width),
251
- Math.round(backgroundPositioningArea.top)
252
- ),
253
- new Vector(
254
- Math.round(backgroundPositioningArea.left + x + width),
255
- Math.round(backgroundPositioningArea.height + backgroundPositioningArea.top)
256
- ),
257
- new Vector(
258
- Math.round(backgroundPositioningArea.left + x),
259
- Math.round(backgroundPositioningArea.height + backgroundPositioningArea.top)
260
- )
261
- ];
262
- case BACKGROUND_REPEAT.NO_REPEAT:
263
- return [
264
- new Vector(
265
- Math.round(backgroundPositioningArea.left + x),
266
- Math.round(backgroundPositioningArea.top + y)
267
- ),
268
- new Vector(
269
- Math.round(backgroundPositioningArea.left + x + width),
270
- Math.round(backgroundPositioningArea.top + y)
271
- ),
272
- new Vector(
273
- Math.round(backgroundPositioningArea.left + x + width),
274
- Math.round(backgroundPositioningArea.top + y + height)
275
- ),
276
- new Vector(
277
- Math.round(backgroundPositioningArea.left + x),
278
- Math.round(backgroundPositioningArea.top + y + height)
279
- )
280
- ];
281
- default:
282
- return [
283
- new Vector(Math.round(backgroundPaintingArea.left), Math.round(backgroundPaintingArea.top)),
284
- new Vector(
285
- Math.round(backgroundPaintingArea.left + backgroundPaintingArea.width),
286
- Math.round(backgroundPaintingArea.top)
287
- ),
288
- new Vector(
289
- Math.round(backgroundPaintingArea.left + backgroundPaintingArea.width),
290
- Math.round(backgroundPaintingArea.height + backgroundPaintingArea.top)
291
- ),
292
- new Vector(
293
- Math.round(backgroundPaintingArea.left),
294
- Math.round(backgroundPaintingArea.height + backgroundPaintingArea.top)
295
- )
296
- ];
297
- }
298
- };
@@ -1,47 +0,0 @@
1
- import { Vector } from './vector';
2
- import { IPath, PathType, Path } from './path';
3
-
4
- const lerp = (a: Vector, b: Vector, t: number): Vector => {
5
- return new Vector(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t);
6
- };
7
-
8
- export class BezierCurve implements IPath {
9
- type: PathType;
10
- start: Vector;
11
- startControl: Vector;
12
- endControl: Vector;
13
- end: Vector;
14
-
15
- constructor(start: Vector, startControl: Vector, endControl: Vector, end: Vector) {
16
- this.type = PathType.BEZIER_CURVE;
17
- this.start = start;
18
- this.startControl = startControl;
19
- this.endControl = endControl;
20
- this.end = end;
21
- }
22
-
23
- subdivide(t: number, firstHalf: boolean): BezierCurve {
24
- const ab = lerp(this.start, this.startControl, t);
25
- const bc = lerp(this.startControl, this.endControl, t);
26
- const cd = lerp(this.endControl, this.end, t);
27
- const abbc = lerp(ab, bc, t);
28
- const bccd = lerp(bc, cd, t);
29
- const dest = lerp(abbc, bccd, t);
30
- return firstHalf ? new BezierCurve(this.start, ab, abbc, dest) : new BezierCurve(dest, bccd, cd, this.end);
31
- }
32
-
33
- add(deltaX: number, deltaY: number): BezierCurve {
34
- return new BezierCurve(
35
- this.start.add(deltaX, deltaY),
36
- this.startControl.add(deltaX, deltaY),
37
- this.endControl.add(deltaX, deltaY),
38
- this.end.add(deltaX, deltaY)
39
- );
40
- }
41
-
42
- reverse(): BezierCurve {
43
- return new BezierCurve(this.end, this.endControl, this.startControl, this.start);
44
- }
45
- }
46
-
47
- export const isBezierCurve = (path: Path): path is BezierCurve => path.type === PathType.BEZIER_CURVE;
@@ -1,165 +0,0 @@
1
- import { Path } from './path';
2
- import { BoundCurves } from './bound-curves';
3
- import { isBezierCurve } from './bezier-curve';
4
-
5
- export const parsePathForBorder = (curves: BoundCurves, borderSide: number): Path[] => {
6
- switch (borderSide) {
7
- case 0:
8
- return createPathFromCurves(
9
- curves.topLeftBorderBox,
10
- curves.topLeftPaddingBox,
11
- curves.topRightBorderBox,
12
- curves.topRightPaddingBox
13
- );
14
- case 1:
15
- return createPathFromCurves(
16
- curves.topRightBorderBox,
17
- curves.topRightPaddingBox,
18
- curves.bottomRightBorderBox,
19
- curves.bottomRightPaddingBox
20
- );
21
- case 2:
22
- return createPathFromCurves(
23
- curves.bottomRightBorderBox,
24
- curves.bottomRightPaddingBox,
25
- curves.bottomLeftBorderBox,
26
- curves.bottomLeftPaddingBox
27
- );
28
- case 3:
29
- default:
30
- return createPathFromCurves(
31
- curves.bottomLeftBorderBox,
32
- curves.bottomLeftPaddingBox,
33
- curves.topLeftBorderBox,
34
- curves.topLeftPaddingBox
35
- );
36
- }
37
- };
38
-
39
- export const parsePathForBorderDoubleOuter = (curves: BoundCurves, borderSide: number): Path[] => {
40
- switch (borderSide) {
41
- case 0:
42
- return createPathFromCurves(
43
- curves.topLeftBorderBox,
44
- curves.topLeftBorderDoubleOuterBox,
45
- curves.topRightBorderBox,
46
- curves.topRightBorderDoubleOuterBox
47
- );
48
- case 1:
49
- return createPathFromCurves(
50
- curves.topRightBorderBox,
51
- curves.topRightBorderDoubleOuterBox,
52
- curves.bottomRightBorderBox,
53
- curves.bottomRightBorderDoubleOuterBox
54
- );
55
- case 2:
56
- return createPathFromCurves(
57
- curves.bottomRightBorderBox,
58
- curves.bottomRightBorderDoubleOuterBox,
59
- curves.bottomLeftBorderBox,
60
- curves.bottomLeftBorderDoubleOuterBox
61
- );
62
- case 3:
63
- default:
64
- return createPathFromCurves(
65
- curves.bottomLeftBorderBox,
66
- curves.bottomLeftBorderDoubleOuterBox,
67
- curves.topLeftBorderBox,
68
- curves.topLeftBorderDoubleOuterBox
69
- );
70
- }
71
- };
72
-
73
- export const parsePathForBorderDoubleInner = (curves: BoundCurves, borderSide: number): Path[] => {
74
- switch (borderSide) {
75
- case 0:
76
- return createPathFromCurves(
77
- curves.topLeftBorderDoubleInnerBox,
78
- curves.topLeftPaddingBox,
79
- curves.topRightBorderDoubleInnerBox,
80
- curves.topRightPaddingBox
81
- );
82
- case 1:
83
- return createPathFromCurves(
84
- curves.topRightBorderDoubleInnerBox,
85
- curves.topRightPaddingBox,
86
- curves.bottomRightBorderDoubleInnerBox,
87
- curves.bottomRightPaddingBox
88
- );
89
- case 2:
90
- return createPathFromCurves(
91
- curves.bottomRightBorderDoubleInnerBox,
92
- curves.bottomRightPaddingBox,
93
- curves.bottomLeftBorderDoubleInnerBox,
94
- curves.bottomLeftPaddingBox
95
- );
96
- case 3:
97
- default:
98
- return createPathFromCurves(
99
- curves.bottomLeftBorderDoubleInnerBox,
100
- curves.bottomLeftPaddingBox,
101
- curves.topLeftBorderDoubleInnerBox,
102
- curves.topLeftPaddingBox
103
- );
104
- }
105
- };
106
-
107
- export const parsePathForBorderStroke = (curves: BoundCurves, borderSide: number): Path[] => {
108
- switch (borderSide) {
109
- case 0:
110
- return createStrokePathFromCurves(curves.topLeftBorderStroke, curves.topRightBorderStroke);
111
- case 1:
112
- return createStrokePathFromCurves(curves.topRightBorderStroke, curves.bottomRightBorderStroke);
113
- case 2:
114
- return createStrokePathFromCurves(curves.bottomRightBorderStroke, curves.bottomLeftBorderStroke);
115
- case 3:
116
- default:
117
- return createStrokePathFromCurves(curves.bottomLeftBorderStroke, curves.topLeftBorderStroke);
118
- }
119
- };
120
-
121
- const createStrokePathFromCurves = (outer1: Path, outer2: Path): Path[] => {
122
- const path = [];
123
- if (isBezierCurve(outer1)) {
124
- path.push(outer1.subdivide(0.5, false));
125
- } else {
126
- path.push(outer1);
127
- }
128
-
129
- if (isBezierCurve(outer2)) {
130
- path.push(outer2.subdivide(0.5, true));
131
- } else {
132
- path.push(outer2);
133
- }
134
-
135
- return path;
136
- };
137
-
138
- const createPathFromCurves = (outer1: Path, inner1: Path, outer2: Path, inner2: Path): Path[] => {
139
- const path = [];
140
- if (isBezierCurve(outer1)) {
141
- path.push(outer1.subdivide(0.5, false));
142
- } else {
143
- path.push(outer1);
144
- }
145
-
146
- if (isBezierCurve(outer2)) {
147
- path.push(outer2.subdivide(0.5, true));
148
- } else {
149
- path.push(outer2);
150
- }
151
-
152
- if (isBezierCurve(inner2)) {
153
- path.push(inner2.subdivide(0.5, true).reverse());
154
- } else {
155
- path.push(inner2);
156
- }
157
-
158
- if (isBezierCurve(inner1)) {
159
- path.push(inner1.subdivide(0.5, false).reverse());
160
- } else {
161
- path.push(inner1);
162
- }
163
-
164
- return path;
165
- };