html2canvas-pro 2.1.0 → 2.1.1

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 (186) hide show
  1. package/dist/html2canvas-pro.esm.js +21 -7
  2. package/dist/html2canvas-pro.esm.js.map +1 -1
  3. package/dist/html2canvas-pro.js +21 -7
  4. package/dist/html2canvas-pro.js.map +1 -1
  5. package/dist/html2canvas-pro.min.js +3 -3
  6. package/dist/lib/core/cache-storage.js +2 -2
  7. package/dist/lib/core/features.js +2 -2
  8. package/dist/lib/render/canvas/background-renderer.js +6 -0
  9. package/dist/lib/render/canvas/canvas-renderer.js +5 -1
  10. package/dist/lib/render/canvas/foreignobject-renderer.js +5 -1
  11. package/package.json +3 -11
  12. package/dist/lib/invariant.js +0 -9
  13. package/dist/types/invariant.d.ts +0 -1
  14. package/src/__tests__/index.ts +0 -99
  15. package/src/config.ts +0 -107
  16. package/src/core/__mocks__/cache-storage.ts +0 -1
  17. package/src/core/__mocks__/context.ts +0 -19
  18. package/src/core/__mocks__/features.ts +0 -8
  19. package/src/core/__mocks__/logger.ts +0 -17
  20. package/src/core/__tests__/cache-storage.test.ts +0 -205
  21. package/src/core/__tests__/cache-storage.ts +0 -278
  22. package/src/core/__tests__/logger.ts +0 -29
  23. package/src/core/__tests__/validator.ts +0 -359
  24. package/src/core/bitwise.ts +0 -1
  25. package/src/core/cache-storage.ts +0 -315
  26. package/src/core/context.ts +0 -31
  27. package/src/core/debugger.ts +0 -32
  28. package/src/core/features.ts +0 -222
  29. package/src/core/logger.ts +0 -64
  30. package/src/core/origin-checker.ts +0 -57
  31. package/src/core/performance-monitor.ts +0 -241
  32. package/src/core/render-element.ts +0 -272
  33. package/src/core/util.ts +0 -1
  34. package/src/core/validator.ts +0 -593
  35. package/src/css/index.ts +0 -427
  36. package/src/css/layout/__mocks__/bounds.ts +0 -6
  37. package/src/css/layout/bounds.ts +0 -79
  38. package/src/css/layout/text.ts +0 -161
  39. package/src/css/property-descriptor.ts +0 -49
  40. package/src/css/property-descriptors/__tests__/background-tests.ts +0 -65
  41. package/src/css/property-descriptors/__tests__/clip-path.test.ts +0 -280
  42. package/src/css/property-descriptors/__tests__/font-family.ts +0 -25
  43. package/src/css/property-descriptors/__tests__/image-rendering-integration.test.ts +0 -153
  44. package/src/css/property-descriptors/__tests__/image-rendering-performance.test.ts +0 -175
  45. package/src/css/property-descriptors/__tests__/image-rendering.test.ts +0 -72
  46. package/src/css/property-descriptors/__tests__/paint-order.ts +0 -87
  47. package/src/css/property-descriptors/__tests__/text-shadow.ts +0 -94
  48. package/src/css/property-descriptors/__tests__/transform-tests.ts +0 -18
  49. package/src/css/property-descriptors/background-clip.ts +0 -30
  50. package/src/css/property-descriptors/background-color.ts +0 -9
  51. package/src/css/property-descriptors/background-image.ts +0 -27
  52. package/src/css/property-descriptors/background-origin.ts +0 -31
  53. package/src/css/property-descriptors/background-position.ts +0 -38
  54. package/src/css/property-descriptors/background-repeat.ts +0 -44
  55. package/src/css/property-descriptors/background-size.ts +0 -27
  56. package/src/css/property-descriptors/border-color.ts +0 -13
  57. package/src/css/property-descriptors/border-radius.ts +0 -19
  58. package/src/css/property-descriptors/border-style.ts +0 -34
  59. package/src/css/property-descriptors/border-width.ts +0 -20
  60. package/src/css/property-descriptors/box-shadow.ts +0 -60
  61. package/src/css/property-descriptors/clip-path.ts +0 -271
  62. package/src/css/property-descriptors/color.ts +0 -9
  63. package/src/css/property-descriptors/content.ts +0 -26
  64. package/src/css/property-descriptors/counter-increment.ts +0 -43
  65. package/src/css/property-descriptors/counter-reset.ts +0 -36
  66. package/src/css/property-descriptors/direction.ts +0 -23
  67. package/src/css/property-descriptors/display.ts +0 -117
  68. package/src/css/property-descriptors/duration.ts +0 -14
  69. package/src/css/property-descriptors/float.ts +0 -29
  70. package/src/css/property-descriptors/font-family.ts +0 -38
  71. package/src/css/property-descriptors/font-size.ts +0 -9
  72. package/src/css/property-descriptors/font-style.ts +0 -25
  73. package/src/css/property-descriptors/font-variant.ts +0 -12
  74. package/src/css/property-descriptors/font-weight.ts +0 -26
  75. package/src/css/property-descriptors/image-rendering.ts +0 -33
  76. package/src/css/property-descriptors/letter-spacing.ts +0 -25
  77. package/src/css/property-descriptors/line-break.ts +0 -22
  78. package/src/css/property-descriptors/line-height.ts +0 -22
  79. package/src/css/property-descriptors/list-style-image.ts +0 -19
  80. package/src/css/property-descriptors/list-style-position.ts +0 -22
  81. package/src/css/property-descriptors/list-style-type.ts +0 -179
  82. package/src/css/property-descriptors/margin.ts +0 -13
  83. package/src/css/property-descriptors/mix-blend-mode.ts +0 -35
  84. package/src/css/property-descriptors/object-fit.ts +0 -39
  85. package/src/css/property-descriptors/opacity.ts +0 -15
  86. package/src/css/property-descriptors/overflow-wrap.ts +0 -22
  87. package/src/css/property-descriptors/overflow.ts +0 -34
  88. package/src/css/property-descriptors/padding.ts +0 -14
  89. package/src/css/property-descriptors/paint-order.ts +0 -42
  90. package/src/css/property-descriptors/position.ts +0 -30
  91. package/src/css/property-descriptors/quotes.ts +0 -57
  92. package/src/css/property-descriptors/rotate.ts +0 -34
  93. package/src/css/property-descriptors/text-align.ts +0 -26
  94. package/src/css/property-descriptors/text-decoration-color.ts +0 -9
  95. package/src/css/property-descriptors/text-decoration-line.ts +0 -38
  96. package/src/css/property-descriptors/text-decoration-style.ts +0 -32
  97. package/src/css/property-descriptors/text-decoration-thickness.ts +0 -30
  98. package/src/css/property-descriptors/text-overflow.ts +0 -23
  99. package/src/css/property-descriptors/text-shadow.ts +0 -52
  100. package/src/css/property-descriptors/text-transform.ts +0 -27
  101. package/src/css/property-descriptors/text-underline-offset.ts +0 -27
  102. package/src/css/property-descriptors/transform-origin.ts +0 -29
  103. package/src/css/property-descriptors/transform.ts +0 -74
  104. package/src/css/property-descriptors/visibility.ts +0 -25
  105. package/src/css/property-descriptors/webkit-line-clamp.ts +0 -30
  106. package/src/css/property-descriptors/webkit-text-stroke-color.ts +0 -8
  107. package/src/css/property-descriptors/webkit-text-stroke-width.ts +0 -15
  108. package/src/css/property-descriptors/word-break.ts +0 -25
  109. package/src/css/property-descriptors/writing-mode.ts +0 -37
  110. package/src/css/property-descriptors/z-index.ts +0 -27
  111. package/src/css/syntax/__tests__/tokernizer-tests.ts +0 -29
  112. package/src/css/syntax/parser.ts +0 -188
  113. package/src/css/syntax/tokenizer.ts +0 -822
  114. package/src/css/type-descriptor.ts +0 -7
  115. package/src/css/types/__tests__/color-tests.ts +0 -147
  116. package/src/css/types/__tests__/image-tests.ts +0 -239
  117. package/src/css/types/angle.ts +0 -86
  118. package/src/css/types/color-math.ts +0 -22
  119. package/src/css/types/color-spaces/a98.ts +0 -86
  120. package/src/css/types/color-spaces/p3.ts +0 -92
  121. package/src/css/types/color-spaces/pro-photo.ts +0 -87
  122. package/src/css/types/color-spaces/rec2020.ts +0 -90
  123. package/src/css/types/color-spaces/srgb.ts +0 -87
  124. package/src/css/types/color-utilities.ts +0 -452
  125. package/src/css/types/color.ts +0 -485
  126. package/src/css/types/functions/-prefix-linear-gradient.ts +0 -35
  127. package/src/css/types/functions/-prefix-radial-gradient.ts +0 -106
  128. package/src/css/types/functions/-webkit-gradient.ts +0 -69
  129. package/src/css/types/functions/__tests__/radial-gradient.ts +0 -69
  130. package/src/css/types/functions/counter.ts +0 -511
  131. package/src/css/types/functions/gradient.ts +0 -206
  132. package/src/css/types/functions/linear-gradient.ts +0 -28
  133. package/src/css/types/functions/radial-gradient.ts +0 -101
  134. package/src/css/types/image.ts +0 -120
  135. package/src/css/types/index.ts +0 -1
  136. package/src/css/types/length-percentage.ts +0 -137
  137. package/src/css/types/length.ts +0 -7
  138. package/src/css/types/time.ts +0 -20
  139. package/src/dom/__mocks__/document-cloner.ts +0 -22
  140. package/src/dom/__tests__/dom-normalizer.test.ts +0 -133
  141. package/src/dom/__tests__/element-container.test.ts +0 -129
  142. package/src/dom/document-cloner.ts +0 -929
  143. package/src/dom/dom-normalizer.ts +0 -133
  144. package/src/dom/element-container.ts +0 -75
  145. package/src/dom/elements/li-element-container.ts +0 -10
  146. package/src/dom/elements/ol-element-container.ts +0 -12
  147. package/src/dom/elements/select-element-container.ts +0 -10
  148. package/src/dom/elements/textarea-element-container.ts +0 -9
  149. package/src/dom/node-parser.ts +0 -177
  150. package/src/dom/node-type-guards.ts +0 -70
  151. package/src/dom/replaced-elements/canvas-element-container.ts +0 -15
  152. package/src/dom/replaced-elements/iframe-element-container.ts +0 -55
  153. package/src/dom/replaced-elements/image-element-container.ts +0 -16
  154. package/src/dom/replaced-elements/index.ts +0 -5
  155. package/src/dom/replaced-elements/input-element-container.ts +0 -105
  156. package/src/dom/replaced-elements/pseudo-elements.ts +0 -0
  157. package/src/dom/replaced-elements/svg-element-container.ts +0 -23
  158. package/src/dom/text-container.ts +0 -42
  159. package/src/global.d.ts +0 -19
  160. package/src/index.ts +0 -82
  161. package/src/invariant.ts +0 -5
  162. package/src/options.ts +0 -55
  163. package/src/render/__tests__/object-fit.test.ts +0 -85
  164. package/src/render/background.ts +0 -298
  165. package/src/render/bezier-curve.ts +0 -47
  166. package/src/render/border.ts +0 -165
  167. package/src/render/bound-curves.ts +0 -388
  168. package/src/render/box-sizing.ts +0 -31
  169. package/src/render/canvas/__tests__/background-renderer.test.ts +0 -72
  170. package/src/render/canvas/__tests__/border-renderer.test.ts +0 -24
  171. package/src/render/canvas/__tests__/effects-renderer.test.ts +0 -32
  172. package/src/render/canvas/__tests__/text-renderer.test.ts +0 -471
  173. package/src/render/canvas/background-renderer.ts +0 -271
  174. package/src/render/canvas/border-renderer.ts +0 -224
  175. package/src/render/canvas/canvas-path.ts +0 -31
  176. package/src/render/canvas/canvas-renderer.ts +0 -641
  177. package/src/render/canvas/effects-renderer.ts +0 -130
  178. package/src/render/canvas/foreignobject-renderer.ts +0 -53
  179. package/src/render/canvas/text-renderer.ts +0 -700
  180. package/src/render/effects.ts +0 -75
  181. package/src/render/font-metrics.ts +0 -72
  182. package/src/render/object-fit.ts +0 -100
  183. package/src/render/path.ts +0 -37
  184. package/src/render/renderer-interface.ts +0 -28
  185. package/src/render/stacking-context.ts +0 -386
  186. package/src/render/vector.ts +0 -19
package/src/css/index.ts DELETED
@@ -1,427 +0,0 @@
1
- import { CSSPropertyDescriptor, PropertyDescriptorParsingType } from './property-descriptor';
2
- import { backgroundClip } from './property-descriptors/background-clip';
3
- import { backgroundColor } from './property-descriptors/background-color';
4
- import { backgroundImage } from './property-descriptors/background-image';
5
- import { backgroundOrigin } from './property-descriptors/background-origin';
6
- import { backgroundPosition } from './property-descriptors/background-position';
7
- import { backgroundRepeat } from './property-descriptors/background-repeat';
8
- import { backgroundSize } from './property-descriptors/background-size';
9
- import {
10
- borderBottomColor,
11
- borderLeftColor,
12
- borderRightColor,
13
- borderTopColor
14
- } from './property-descriptors/border-color';
15
- import {
16
- borderBottomLeftRadius,
17
- borderBottomRightRadius,
18
- borderTopLeftRadius,
19
- borderTopRightRadius
20
- } from './property-descriptors/border-radius';
21
- import {
22
- borderBottomStyle,
23
- borderLeftStyle,
24
- borderRightStyle,
25
- borderTopStyle
26
- } from './property-descriptors/border-style';
27
- import {
28
- borderBottomWidth,
29
- borderLeftWidth,
30
- borderRightWidth,
31
- borderTopWidth
32
- } from './property-descriptors/border-width';
33
- import { clipPath, ClipPathValue } from './property-descriptors/clip-path';
34
- import { color } from './property-descriptors/color';
35
- import { direction } from './property-descriptors/direction';
36
- import { display, DISPLAY } from './property-descriptors/display';
37
- import { float, FLOAT } from './property-descriptors/float';
38
- import { letterSpacing } from './property-descriptors/letter-spacing';
39
- import { lineBreak } from './property-descriptors/line-break';
40
- import { lineHeight } from './property-descriptors/line-height';
41
- import { listStyleImage } from './property-descriptors/list-style-image';
42
- import { listStylePosition } from './property-descriptors/list-style-position';
43
- import { listStyleType } from './property-descriptors/list-style-type';
44
- import { marginBottom, marginLeft, marginRight, marginTop } from './property-descriptors/margin';
45
- import { overflow, OVERFLOW } from './property-descriptors/overflow';
46
- import { overflowWrap } from './property-descriptors/overflow-wrap';
47
- import { paddingBottom, paddingLeft, paddingRight, paddingTop } from './property-descriptors/padding';
48
- import { textAlign } from './property-descriptors/text-align';
49
- import { position, POSITION } from './property-descriptors/position';
50
- import { textShadow } from './property-descriptors/text-shadow';
51
- import { textTransform } from './property-descriptors/text-transform';
52
- import { transform } from './property-descriptors/transform';
53
- import { transformOrigin } from './property-descriptors/transform-origin';
54
- import { rotate } from './property-descriptors/rotate';
55
- import { visibility, VISIBILITY } from './property-descriptors/visibility';
56
- import { wordBreak } from './property-descriptors/word-break';
57
- import { writingMode } from './property-descriptors/writing-mode';
58
- import { zIndex } from './property-descriptors/z-index';
59
- import { CSSValue, isIdentToken, Parser } from './syntax/parser';
60
- import { Tokenizer } from './syntax/tokenizer';
61
- import { Color, color as colorType } from './types/color';
62
- import { isTransparent } from './types/color-utilities';
63
- import { angle } from './types/angle';
64
- import { image } from './types/image';
65
- import { time } from './types/time';
66
- import { opacity } from './property-descriptors/opacity';
67
- import { textDecorationColor } from './property-descriptors/text-decoration-color';
68
- import { textDecorationLine } from './property-descriptors/text-decoration-line';
69
- import { textDecorationStyle } from './property-descriptors/text-decoration-style';
70
- import { textDecorationThickness } from './property-descriptors/text-decoration-thickness';
71
- import { textUnderlineOffset } from './property-descriptors/text-underline-offset';
72
- import { isLengthPercentage, LengthPercentage, ZERO_LENGTH } from './types/length-percentage';
73
- import { fontFamily } from './property-descriptors/font-family';
74
- import { fontSize } from './property-descriptors/font-size';
75
- import { isLength } from './types/length';
76
- import { fontWeight } from './property-descriptors/font-weight';
77
- import { fontVariant } from './property-descriptors/font-variant';
78
- import { fontStyle } from './property-descriptors/font-style';
79
- import { contains } from '../core/bitwise';
80
- import { content } from './property-descriptors/content';
81
- import { counterIncrement } from './property-descriptors/counter-increment';
82
- import { counterReset } from './property-descriptors/counter-reset';
83
- import { duration } from './property-descriptors/duration';
84
- import { quotes } from './property-descriptors/quotes';
85
- import { boxShadow } from './property-descriptors/box-shadow';
86
- import { paintOrder } from './property-descriptors/paint-order';
87
- import { webkitTextStrokeColor } from './property-descriptors/webkit-text-stroke-color';
88
- import { webkitTextStrokeWidth } from './property-descriptors/webkit-text-stroke-width';
89
- import { webkitLineClamp } from './property-descriptors/webkit-line-clamp';
90
- import { Context } from '../core/context';
91
- import { objectFit } from './property-descriptors/object-fit';
92
- import { textOverflow } from './property-descriptors/text-overflow';
93
- import { imageRendering } from './property-descriptors/image-rendering';
94
- import { mixBlendMode, MixBlendMode } from './property-descriptors/mix-blend-mode';
95
-
96
- export class CSSParsedDeclaration {
97
- animationDuration!: ReturnType<typeof duration.parse>;
98
- backgroundClip!: ReturnType<typeof backgroundClip.parse>;
99
- backgroundColor!: Color;
100
- backgroundImage!: ReturnType<typeof backgroundImage.parse>;
101
- backgroundOrigin!: ReturnType<typeof backgroundOrigin.parse>;
102
- backgroundPosition!: ReturnType<typeof backgroundPosition.parse>;
103
- backgroundRepeat!: ReturnType<typeof backgroundRepeat.parse>;
104
- backgroundSize!: ReturnType<typeof backgroundSize.parse>;
105
- borderTopColor!: Color;
106
- borderRightColor!: Color;
107
- borderBottomColor!: Color;
108
- borderLeftColor!: Color;
109
- borderTopLeftRadius!: ReturnType<typeof borderTopLeftRadius.parse>;
110
- borderTopRightRadius!: ReturnType<typeof borderTopRightRadius.parse>;
111
- borderBottomRightRadius!: ReturnType<typeof borderBottomRightRadius.parse>;
112
- borderBottomLeftRadius!: ReturnType<typeof borderBottomLeftRadius.parse>;
113
- borderTopStyle!: ReturnType<typeof borderTopStyle.parse>;
114
- borderRightStyle!: ReturnType<typeof borderRightStyle.parse>;
115
- borderBottomStyle!: ReturnType<typeof borderBottomStyle.parse>;
116
- borderLeftStyle!: ReturnType<typeof borderLeftStyle.parse>;
117
- borderTopWidth!: ReturnType<typeof borderTopWidth.parse>;
118
- borderRightWidth!: ReturnType<typeof borderRightWidth.parse>;
119
- borderBottomWidth!: ReturnType<typeof borderBottomWidth.parse>;
120
- borderLeftWidth!: ReturnType<typeof borderLeftWidth.parse>;
121
- boxShadow!: ReturnType<typeof boxShadow.parse>;
122
- clipPath!: ClipPathValue;
123
- color!: Color;
124
- direction!: ReturnType<typeof direction.parse>;
125
- display!: ReturnType<typeof display.parse>;
126
- float!: ReturnType<typeof float.parse>;
127
- fontFamily!: ReturnType<typeof fontFamily.parse>;
128
- fontSize!: LengthPercentage;
129
- fontStyle!: ReturnType<typeof fontStyle.parse>;
130
- fontVariant!: ReturnType<typeof fontVariant.parse>;
131
- fontWeight!: ReturnType<typeof fontWeight.parse>;
132
- letterSpacing!: ReturnType<typeof letterSpacing.parse>;
133
- lineBreak!: ReturnType<typeof lineBreak.parse>;
134
- lineHeight!: CSSValue;
135
- listStyleImage!: ReturnType<typeof listStyleImage.parse>;
136
- listStylePosition!: ReturnType<typeof listStylePosition.parse>;
137
- listStyleType!: ReturnType<typeof listStyleType.parse>;
138
- marginTop!: CSSValue;
139
- marginRight!: CSSValue;
140
- marginBottom!: CSSValue;
141
- marginLeft!: CSSValue;
142
- opacity!: ReturnType<typeof opacity.parse>;
143
- overflowX!: OVERFLOW;
144
- overflowY!: OVERFLOW;
145
- overflowWrap!: ReturnType<typeof overflowWrap.parse>;
146
- paddingTop!: LengthPercentage;
147
- paddingRight!: LengthPercentage;
148
- paddingBottom!: LengthPercentage;
149
- paddingLeft!: LengthPercentage;
150
- paintOrder!: ReturnType<typeof paintOrder.parse>;
151
- position!: ReturnType<typeof position.parse>;
152
- textAlign!: ReturnType<typeof textAlign.parse>;
153
- textDecorationColor!: Color;
154
- textDecorationLine!: ReturnType<typeof textDecorationLine.parse>;
155
- textDecorationStyle!: ReturnType<typeof textDecorationStyle.parse>;
156
- textDecorationThickness!: ReturnType<typeof textDecorationThickness.parse>;
157
- textUnderlineOffset!: ReturnType<typeof textUnderlineOffset.parse>;
158
- textShadow!: ReturnType<typeof textShadow.parse>;
159
- textTransform!: ReturnType<typeof textTransform.parse>;
160
- textOverflow!: ReturnType<typeof textOverflow.parse>;
161
- transform!: ReturnType<typeof transform.parse>;
162
- transformOrigin!: ReturnType<typeof transformOrigin.parse>;
163
- rotate!: ReturnType<typeof rotate.parse>;
164
- visibility!: ReturnType<typeof visibility.parse>;
165
- webkitTextStrokeColor!: Color;
166
- webkitTextStrokeWidth!: ReturnType<typeof webkitTextStrokeWidth.parse>;
167
- webkitLineClamp!: ReturnType<typeof webkitLineClamp.parse>;
168
- wordBreak!: ReturnType<typeof wordBreak.parse>;
169
- writingMode!: ReturnType<typeof writingMode.parse>;
170
- zIndex!: ReturnType<typeof zIndex.parse>;
171
- objectFit!: ReturnType<typeof objectFit.parse>;
172
- imageRendering!: ReturnType<typeof imageRendering.parse>;
173
- mixBlendMode!: MixBlendMode;
174
-
175
- private static readonly standardProps: [keyof CSSParsedDeclaration, CSSPropertyDescriptor<unknown>, string][] = [
176
- ['animationDuration', duration, 'animationDuration'],
177
- ['backgroundClip', backgroundClip, 'backgroundClip'],
178
- ['backgroundColor', backgroundColor, 'backgroundColor'],
179
- ['backgroundImage', backgroundImage, 'backgroundImage'],
180
- ['backgroundOrigin', backgroundOrigin, 'backgroundOrigin'],
181
- ['backgroundPosition', backgroundPosition, 'backgroundPosition'],
182
- ['backgroundRepeat', backgroundRepeat, 'backgroundRepeat'],
183
- ['backgroundSize', backgroundSize, 'backgroundSize'],
184
- ['borderTopColor', borderTopColor, 'borderTopColor'],
185
- ['borderRightColor', borderRightColor, 'borderRightColor'],
186
- ['borderBottomColor', borderBottomColor, 'borderBottomColor'],
187
- ['borderLeftColor', borderLeftColor, 'borderLeftColor'],
188
- ['borderTopLeftRadius', borderTopLeftRadius, 'borderTopLeftRadius'],
189
- ['borderTopRightRadius', borderTopRightRadius, 'borderTopRightRadius'],
190
- ['borderBottomRightRadius', borderBottomRightRadius, 'borderBottomRightRadius'],
191
- ['borderBottomLeftRadius', borderBottomLeftRadius, 'borderBottomLeftRadius'],
192
- ['borderTopStyle', borderTopStyle, 'borderTopStyle'],
193
- ['borderRightStyle', borderRightStyle, 'borderRightStyle'],
194
- ['borderBottomStyle', borderBottomStyle, 'borderBottomStyle'],
195
- ['borderLeftStyle', borderLeftStyle, 'borderLeftStyle'],
196
- ['borderTopWidth', borderTopWidth, 'borderTopWidth'],
197
- ['borderRightWidth', borderRightWidth, 'borderRightWidth'],
198
- ['borderBottomWidth', borderBottomWidth, 'borderBottomWidth'],
199
- ['borderLeftWidth', borderLeftWidth, 'borderLeftWidth'],
200
- ['boxShadow', boxShadow, 'boxShadow'],
201
- ['clipPath', clipPath, 'clipPath'],
202
- ['color', color, 'color'],
203
- ['direction', direction, 'direction'],
204
- ['display', display, 'display'],
205
- ['fontFamily', fontFamily, 'fontFamily'],
206
- ['fontSize', fontSize, 'fontSize'],
207
- ['fontStyle', fontStyle, 'fontStyle'],
208
- ['fontVariant', fontVariant, 'fontVariant'],
209
- ['fontWeight', fontWeight, 'fontWeight'],
210
- ['letterSpacing', letterSpacing, 'letterSpacing'],
211
- ['lineBreak', lineBreak, 'lineBreak'],
212
- ['lineHeight', lineHeight, 'lineHeight'],
213
- ['listStyleImage', listStyleImage, 'listStyleImage'],
214
- ['listStylePosition', listStylePosition, 'listStylePosition'],
215
- ['listStyleType', listStyleType, 'listStyleType'],
216
- ['marginTop', marginTop, 'marginTop'],
217
- ['marginRight', marginRight, 'marginRight'],
218
- ['marginBottom', marginBottom, 'marginBottom'],
219
- ['marginLeft', marginLeft, 'marginLeft'],
220
- ['opacity', opacity, 'opacity'],
221
- ['overflowWrap', overflowWrap, 'overflowWrap'],
222
- ['paddingTop', paddingTop, 'paddingTop'],
223
- ['paddingRight', paddingRight, 'paddingRight'],
224
- ['paddingBottom', paddingBottom, 'paddingBottom'],
225
- ['paddingLeft', paddingLeft, 'paddingLeft'],
226
- ['paintOrder', paintOrder, 'paintOrder'],
227
- ['position', position, 'position'],
228
- ['textAlign', textAlign, 'textAlign'],
229
- ['textDecorationStyle', textDecorationStyle, 'textDecorationStyle'],
230
- ['textDecorationThickness', textDecorationThickness, 'textDecorationThickness'],
231
- ['textUnderlineOffset', textUnderlineOffset, 'textUnderlineOffset'],
232
- ['textShadow', textShadow, 'textShadow'],
233
- ['textTransform', textTransform, 'textTransform'],
234
- ['textOverflow', textOverflow, 'textOverflow'],
235
- ['transform', transform, 'transform'],
236
- ['transformOrigin', transformOrigin, 'transformOrigin'],
237
- ['rotate', rotate, 'rotate'],
238
- ['visibility', visibility, 'visibility'],
239
- ['webkitTextStrokeColor', webkitTextStrokeColor, 'webkitTextStrokeColor'],
240
- ['webkitTextStrokeWidth', webkitTextStrokeWidth, 'webkitTextStrokeWidth'],
241
- ['webkitLineClamp', webkitLineClamp, 'webkitLineClamp'],
242
- ['wordBreak', wordBreak, 'wordBreak'],
243
- ['writingMode', writingMode, 'writingMode'],
244
- ['zIndex', zIndex, 'zIndex'],
245
- ['objectFit', objectFit, 'objectFit'],
246
- ['imageRendering', imageRendering, 'imageRendering'],
247
- ['mixBlendMode', mixBlendMode, 'mixBlendMode']
248
- ];
249
-
250
- constructor(context: Context, declaration: CSSStyleDeclaration) {
251
- const standardProps = CSSParsedDeclaration.standardProps;
252
-
253
- // Fast path: display:none elements are invisible and their descendants
254
- // are never rendered. Parse only initial values instead of full computed styles.
255
- if (declaration.display === 'none') {
256
- this.display = DISPLAY.NONE;
257
- for (const [key, descriptor] of standardProps) {
258
- if (key !== 'display') {
259
- (this as Record<string, unknown>)[key] = parse(context, descriptor, undefined);
260
- }
261
- }
262
- this.float = parse(context, float, undefined);
263
- this.textDecorationColor = parse(context, textDecorationColor, undefined);
264
- this.textDecorationLine = parse(context, textDecorationLine, undefined);
265
- const overflowTuple = parse(context, overflow, undefined);
266
- this.overflowX = overflowTuple[0];
267
- this.overflowY = overflowTuple[overflowTuple.length > 1 ? 1 : 0];
268
- return;
269
- }
270
-
271
- for (const [key, descriptor, cssProp] of standardProps) {
272
- (this as Record<string, unknown>)[key] = parse(
273
- context,
274
- descriptor,
275
- (declaration as unknown as Record<string, string | undefined>)[cssProp]
276
- );
277
- }
278
-
279
- // Special cases that need different CSS property names or fallback values
280
- this.float = parse(context, float, declaration.cssFloat);
281
- this.textDecorationColor = parse(
282
- context,
283
- textDecorationColor,
284
- declaration.textDecorationColor ?? declaration.color
285
- );
286
- this.textDecorationLine = parse(
287
- context,
288
- textDecorationLine,
289
- declaration.textDecorationLine ?? declaration.textDecoration
290
- );
291
-
292
- // overflow returns a tuple that must be split into X/Y
293
- const overflowTuple = parse(context, overflow, declaration.overflow);
294
- this.overflowX = overflowTuple[0];
295
- this.overflowY = overflowTuple[overflowTuple.length > 1 ? 1 : 0];
296
- }
297
-
298
- isVisible(): boolean {
299
- return this.display > 0 && this.opacity > 0 && this.visibility === VISIBILITY.VISIBLE;
300
- }
301
-
302
- isTransparent(): boolean {
303
- return isTransparent(this.backgroundColor);
304
- }
305
-
306
- isTransformed(): boolean {
307
- return this.transform !== null || this.rotate !== null;
308
- }
309
-
310
- isPositioned(): boolean {
311
- return this.position !== POSITION.STATIC;
312
- }
313
-
314
- isPositionedWithZIndex(): boolean {
315
- return this.isPositioned() && !this.zIndex.auto;
316
- }
317
-
318
- isFloating(): boolean {
319
- return this.float !== FLOAT.NONE;
320
- }
321
-
322
- isInlineLevel(): boolean {
323
- return (
324
- contains(this.display, DISPLAY.INLINE) ||
325
- contains(this.display, DISPLAY.INLINE_BLOCK) ||
326
- contains(this.display, DISPLAY.INLINE_FLEX) ||
327
- contains(this.display, DISPLAY.INLINE_GRID) ||
328
- contains(this.display, DISPLAY.INLINE_LIST_ITEM) ||
329
- contains(this.display, DISPLAY.INLINE_TABLE)
330
- );
331
- }
332
- }
333
-
334
- export class CSSParsedPseudoDeclaration {
335
- content: ReturnType<typeof content.parse>;
336
- quotes: ReturnType<typeof quotes.parse>;
337
-
338
- constructor(context: Context, declaration: CSSStyleDeclaration) {
339
- this.content = parse(context, content, declaration.content);
340
- this.quotes = parse(context, quotes, declaration.quotes);
341
- }
342
- }
343
-
344
- export class CSSParsedCounterDeclaration {
345
- counterIncrement: ReturnType<typeof counterIncrement.parse>;
346
- counterReset: ReturnType<typeof counterReset.parse>;
347
-
348
- constructor(context: Context, declaration: CSSStyleDeclaration) {
349
- this.counterIncrement = parse(context, counterIncrement, declaration.counterIncrement);
350
- this.counterReset = parse(context, counterReset, declaration.counterReset);
351
- }
352
- }
353
-
354
- const parseCache = new Map<CSSPropertyDescriptor<any>, Map<string, unknown>>();
355
- const PARSE_CACHE_MAX_PER_DESCRIPTOR = 200;
356
-
357
- const parse = (context: Context, descriptor: CSSPropertyDescriptor<any>, style?: string | null) => {
358
- const rawValue = style !== null && typeof style !== 'undefined' ? style.toString() : descriptor.initialValue;
359
-
360
- let valueCache = parseCache.get(descriptor);
361
- if (valueCache) {
362
- const cached = valueCache.get(rawValue);
363
- if (cached !== undefined) {
364
- return cached;
365
- }
366
- }
367
-
368
- const tokenizer = Tokenizer.get();
369
- tokenizer.write(rawValue);
370
- const parser = new Parser(tokenizer.read());
371
- Tokenizer.release(tokenizer);
372
-
373
- let result: any;
374
- switch (descriptor.type) {
375
- case PropertyDescriptorParsingType.IDENT_VALUE: {
376
- const token = parser.parseComponentValue();
377
- result = descriptor.parse(context, isIdentToken(token) ? token.value : descriptor.initialValue);
378
- break;
379
- }
380
- case PropertyDescriptorParsingType.VALUE:
381
- result = descriptor.parse(context, parser.parseComponentValue());
382
- break;
383
- case PropertyDescriptorParsingType.LIST:
384
- result = descriptor.parse(context, parser.parseComponentValues());
385
- break;
386
- case PropertyDescriptorParsingType.TOKEN_VALUE:
387
- result = parser.parseComponentValue();
388
- break;
389
- case PropertyDescriptorParsingType.TYPE_VALUE:
390
- switch (descriptor.format) {
391
- case 'angle':
392
- result = angle.parse(context, parser.parseComponentValue());
393
- break;
394
- case 'color':
395
- result = colorType.parse(context, parser.parseComponentValue());
396
- break;
397
- case 'image':
398
- result = image.parse(context, parser.parseComponentValue());
399
- break;
400
- case 'length': {
401
- const length = parser.parseComponentValue();
402
- result = isLength(length) ? length : ZERO_LENGTH;
403
- break;
404
- }
405
- case 'length-percentage': {
406
- const value = parser.parseComponentValue();
407
- result = isLengthPercentage(value) ? value : ZERO_LENGTH;
408
- break;
409
- }
410
- case 'time':
411
- result = time.parse(context, parser.parseComponentValue());
412
- break;
413
- }
414
- break;
415
- }
416
-
417
- if (!valueCache) {
418
- valueCache = new Map();
419
- parseCache.set(descriptor, valueCache);
420
- }
421
- if (valueCache.size >= PARSE_CACHE_MAX_PER_DESCRIPTOR) {
422
- valueCache.clear();
423
- }
424
- valueCache.set(rawValue, result);
425
-
426
- return result;
427
- };
@@ -1,6 +0,0 @@
1
- import type { Bounds as BoundsType } from '../bounds';
2
- const actual = await vi.importActual<typeof import('../bounds')>('../bounds');
3
- export const { Bounds } = actual;
4
- export const parseBounds = (): BoundsType => {
5
- return new Bounds(0, 0, 200, 50);
6
- };
@@ -1,79 +0,0 @@
1
- import { Context } from '../../core/context';
2
-
3
- export class Bounds {
4
- constructor(
5
- readonly left: number,
6
- readonly top: number,
7
- readonly width: number,
8
- readonly height: number
9
- ) {}
10
-
11
- add(x: number, y: number, w: number, h: number): Bounds {
12
- return new Bounds(this.left + x, this.top + y, this.width + w, this.height + h);
13
- }
14
-
15
- static fromClientRect(context: Context, clientRect: ClientRect): Bounds {
16
- return new Bounds(
17
- clientRect.left + context.windowBounds.left,
18
- clientRect.top + context.windowBounds.top,
19
- clientRect.width,
20
- clientRect.height
21
- );
22
- }
23
-
24
- static fromDOMRectList(context: Context, domRectList: DOMRectList): Bounds {
25
- const rects = Array.from(domRectList);
26
-
27
- // First try to find a rect with non-zero width
28
- let domRect = rects.find((rect) => rect.width !== 0);
29
-
30
- // If not found, try to find a rect with non-zero height
31
- // This handles cases like inline-flex with single child where width might be 0
32
- if (!domRect) {
33
- domRect = rects.find((rect) => rect.height !== 0);
34
- }
35
-
36
- // If still not found but rects exist, use the first rect
37
- // Position info (left, top) might still be valid even if dimensions are 0
38
- if (!domRect && rects.length > 0) {
39
- domRect = rects[0];
40
- }
41
-
42
- return domRect
43
- ? new Bounds(
44
- domRect.left + context.windowBounds.left,
45
- domRect.top + context.windowBounds.top,
46
- domRect.width,
47
- domRect.height
48
- )
49
- : Bounds.EMPTY;
50
- }
51
-
52
- static EMPTY = new Bounds(0, 0, 0, 0);
53
- }
54
-
55
- export const parseBounds = (context: Context, node: Element): Bounds => {
56
- return Bounds.fromClientRect(context, node.getBoundingClientRect());
57
- };
58
-
59
- export const parseDocumentSize = (document: Document): Bounds => {
60
- const body = document.body;
61
- const documentElement = document.documentElement;
62
-
63
- if (!body || !documentElement) {
64
- throw new Error(`Unable to get document size`);
65
- }
66
- const width = Math.max(
67
- Math.max(body.scrollWidth, documentElement.scrollWidth),
68
- Math.max(body.offsetWidth, documentElement.offsetWidth),
69
- Math.max(body.clientWidth, documentElement.clientWidth)
70
- );
71
-
72
- const height = Math.max(
73
- Math.max(body.scrollHeight, documentElement.scrollHeight),
74
- Math.max(body.offsetHeight, documentElement.offsetHeight),
75
- Math.max(body.clientHeight, documentElement.clientHeight)
76
- );
77
-
78
- return new Bounds(0, 0, width, height);
79
- };
@@ -1,161 +0,0 @@
1
- import { OVERFLOW_WRAP } from '../property-descriptors/overflow-wrap';
2
- import { CSSParsedDeclaration } from '../index';
3
- import { fromCodePoint, LineBreaker, toCodePoints } from 'css-line-break';
4
- import { splitGraphemes } from 'text-segmentation';
5
- import { Bounds, parseBounds } from './bounds';
6
- import { FEATURES } from '../../core/features';
7
- import { Context } from '../../core/context';
8
- import { isVerticalWritingMode } from '../property-descriptors/writing-mode';
9
-
10
- export class TextBounds {
11
- readonly text: string;
12
- readonly bounds: Bounds;
13
-
14
- constructor(text: string, bounds: Bounds) {
15
- this.text = text;
16
- this.bounds = bounds;
17
- }
18
- }
19
-
20
- export const parseTextBounds = (
21
- context: Context,
22
- value: string,
23
- styles: CSSParsedDeclaration,
24
- node: Text
25
- ): TextBounds[] => {
26
- const textList = breakText(value, styles);
27
- const textBounds: TextBounds[] = [];
28
- let offset = 0;
29
- textList.forEach((text) => {
30
- if (styles.textDecorationLine.length || text.trim().length > 0) {
31
- if (FEATURES.SUPPORT_RANGE_BOUNDS) {
32
- const clientRects = createRange(node, offset, text.length).getClientRects();
33
- if (clientRects.length > 1) {
34
- const subSegments = segmentGraphemes(text);
35
- let subOffset = 0;
36
- subSegments.forEach((subSegment) => {
37
- textBounds.push(
38
- new TextBounds(
39
- subSegment,
40
- Bounds.fromDOMRectList(
41
- context,
42
- createRange(node, subOffset + offset, subSegment.length).getClientRects()
43
- )
44
- )
45
- );
46
- subOffset += subSegment.length;
47
- });
48
- } else {
49
- textBounds.push(new TextBounds(text, Bounds.fromDOMRectList(context, clientRects)));
50
- }
51
- } else {
52
- const replacementNode = node.splitText(text.length);
53
- textBounds.push(new TextBounds(text, getWrapperBounds(context, node)));
54
- node = replacementNode;
55
- }
56
- } else if (!FEATURES.SUPPORT_RANGE_BOUNDS) {
57
- node = node.splitText(text.length);
58
- }
59
- offset += text.length;
60
- });
61
-
62
- return textBounds;
63
- };
64
-
65
- const getWrapperBounds = (context: Context, node: Text): Bounds => {
66
- const ownerDocument = node.ownerDocument;
67
- if (ownerDocument) {
68
- const wrapper = ownerDocument.createElement('html2canvaswrapper');
69
- wrapper.appendChild(node.cloneNode(true));
70
- const parentNode = node.parentNode;
71
- if (parentNode) {
72
- parentNode.replaceChild(wrapper, node);
73
- const bounds = parseBounds(context, wrapper);
74
- if (wrapper.firstChild) {
75
- parentNode.replaceChild(wrapper.firstChild, wrapper);
76
- }
77
- return bounds;
78
- }
79
- }
80
-
81
- return Bounds.EMPTY;
82
- };
83
-
84
- const createRange = (node: Text, offset: number, length: number): Range => {
85
- const ownerDocument = node.ownerDocument;
86
- if (!ownerDocument) {
87
- throw new Error('Node has no owner document');
88
- }
89
- const range = ownerDocument.createRange();
90
- range.setStart(node, offset);
91
- range.setEnd(node, offset + length);
92
- return range;
93
- };
94
-
95
- export const segmentGraphemes = (value: string): string[] => {
96
- if (FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) {
97
- const segmenter = new (Intl as any).Segmenter(void 0, { granularity: 'grapheme' });
98
-
99
- return Array.from(segmenter.segment(value)).map((segment: any) => segment.segment);
100
- }
101
-
102
- return splitGraphemes(value);
103
- };
104
-
105
- const segmentWords = (value: string, styles: CSSParsedDeclaration): string[] => {
106
- if (FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) {
107
- const segmenter = new (Intl as any).Segmenter(void 0, {
108
- granularity: 'word'
109
- });
110
-
111
- return Array.from(segmenter.segment(value)).map((segment: any) => segment.segment);
112
- }
113
-
114
- return breakWords(value, styles);
115
- };
116
-
117
- const breakText = (value: string, styles: CSSParsedDeclaration): string[] => {
118
- if (isVerticalWritingMode(styles.writingMode)) {
119
- return segmentGraphemes(value);
120
- }
121
-
122
- return styles.letterSpacing !== 0 ? segmentGraphemes(value) : segmentWords(value, styles);
123
- };
124
-
125
- // https://drafts.csswg.org/css-text/#word-separator
126
- const wordSeparators = [0x0020, 0x00a0, 0x1361, 0x10100, 0x10101, 0x1039, 0x1091];
127
-
128
- const breakWords = (str: string, styles: CSSParsedDeclaration): string[] => {
129
- const breaker = LineBreaker(str, {
130
- lineBreak: styles.lineBreak,
131
- wordBreak: styles.overflowWrap === OVERFLOW_WRAP.BREAK_WORD ? 'break-word' : styles.wordBreak
132
- });
133
-
134
- const words = [];
135
- let bk;
136
-
137
- while (!(bk = breaker.next()).done) {
138
- if (bk.value) {
139
- const value = bk.value.slice();
140
- const codePoints = toCodePoints(value);
141
- let word = '';
142
- codePoints.forEach((codePoint) => {
143
- if (wordSeparators.indexOf(codePoint) === -1) {
144
- word += fromCodePoint(codePoint);
145
- } else {
146
- if (word.length) {
147
- words.push(word);
148
- }
149
- words.push(fromCodePoint(codePoint));
150
- word = '';
151
- }
152
- });
153
-
154
- if (word.length) {
155
- words.push(word);
156
- }
157
- }
158
- }
159
-
160
- return words;
161
- };