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,42 +0,0 @@
1
- import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue, isIdentToken } from '../syntax/parser';
3
- import { Context } from '../../core/context';
4
- export const enum PAINT_ORDER_LAYER {
5
- FILL,
6
- STROKE,
7
- MARKERS
8
- }
9
-
10
- export type PaintOrder = PAINT_ORDER_LAYER[];
11
-
12
- export const paintOrder: IPropertyListDescriptor<PaintOrder> = {
13
- name: 'paint-order',
14
- initialValue: 'normal',
15
- prefix: false,
16
- type: PropertyDescriptorParsingType.LIST,
17
- parse: (_context: Context, tokens: CSSValue[]): PaintOrder => {
18
- const DEFAULT_VALUE = [PAINT_ORDER_LAYER.FILL, PAINT_ORDER_LAYER.STROKE, PAINT_ORDER_LAYER.MARKERS];
19
- const layers: PaintOrder = [];
20
-
21
- tokens.filter(isIdentToken).forEach((token) => {
22
- switch (token.value) {
23
- case 'stroke':
24
- layers.push(PAINT_ORDER_LAYER.STROKE);
25
- break;
26
- case 'fill':
27
- layers.push(PAINT_ORDER_LAYER.FILL);
28
- break;
29
- case 'markers':
30
- layers.push(PAINT_ORDER_LAYER.MARKERS);
31
- break;
32
- }
33
- });
34
- DEFAULT_VALUE.forEach((value) => {
35
- if (layers.indexOf(value) === -1) {
36
- layers.push(value);
37
- }
38
- });
39
-
40
- return layers;
41
- }
42
- };
@@ -1,30 +0,0 @@
1
- import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { Context } from '../../core/context';
3
- export const enum POSITION {
4
- STATIC = 0,
5
- RELATIVE = 1,
6
- ABSOLUTE = 2,
7
- FIXED = 3,
8
- STICKY = 4
9
- }
10
-
11
- export const position: IPropertyIdentValueDescriptor<POSITION> = {
12
- name: 'position',
13
- initialValue: 'static',
14
- prefix: false,
15
- type: PropertyDescriptorParsingType.IDENT_VALUE,
16
- parse: (_context: Context, position: string) => {
17
- switch (position) {
18
- case 'relative':
19
- return POSITION.RELATIVE;
20
- case 'absolute':
21
- return POSITION.ABSOLUTE;
22
- case 'fixed':
23
- return POSITION.FIXED;
24
- case 'sticky':
25
- return POSITION.STICKY;
26
- }
27
-
28
- return POSITION.STATIC;
29
- }
30
- };
@@ -1,57 +0,0 @@
1
- import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue, isStringToken } from '../syntax/parser';
3
- import { TokenType } from '../syntax/tokenizer';
4
- import { Context } from '../../core/context';
5
-
6
- export interface QUOTE {
7
- open: string;
8
- close: string;
9
- }
10
-
11
- export type Quotes = QUOTE[] | null;
12
-
13
- export const quotes: IPropertyListDescriptor<Quotes> = {
14
- name: 'quotes',
15
- initialValue: 'none',
16
- prefix: true,
17
- type: PropertyDescriptorParsingType.LIST,
18
- parse: (_context: Context, tokens: CSSValue[]) => {
19
- if (tokens.length === 0) {
20
- return null;
21
- }
22
-
23
- const first = tokens[0];
24
-
25
- if (first.type === TokenType.IDENT_TOKEN && first.value === 'none') {
26
- return null;
27
- }
28
-
29
- const quotes = [];
30
- const filtered = tokens.filter(isStringToken);
31
-
32
- if (filtered.length % 2 !== 0) {
33
- return null;
34
- }
35
-
36
- for (let i = 0; i < filtered.length; i += 2) {
37
- const open = filtered[i].value;
38
- const close = filtered[i + 1].value;
39
- quotes.push({ open, close });
40
- }
41
-
42
- return quotes;
43
- }
44
- };
45
-
46
- export const getQuote = (quotes: Quotes, depth: number, open: boolean): string => {
47
- if (!quotes) {
48
- return '';
49
- }
50
-
51
- const quote = quotes[Math.min(depth, quotes.length - 1)];
52
- if (!quote) {
53
- return '';
54
- }
55
-
56
- return open ? quote.open : quote.close;
57
- };
@@ -1,34 +0,0 @@
1
- import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue } from '../syntax/parser';
3
- import { TokenType } from '../syntax/tokenizer';
4
- import { Context } from '../../core/context';
5
- import { angle } from '../types/angle';
6
-
7
- export type Rotate = number | null;
8
-
9
- export const rotate: IPropertyValueDescriptor<Rotate> = {
10
- name: 'rotate',
11
- initialValue: 'none',
12
- prefix: false,
13
- type: PropertyDescriptorParsingType.VALUE,
14
- parse: (_context: Context, token: CSSValue): Rotate => {
15
- if (token.type === TokenType.IDENT_TOKEN && token.value === 'none') {
16
- return null;
17
- }
18
-
19
- if (token.type === TokenType.NUMBER_TOKEN) {
20
- if (token.number === 0) {
21
- return 0;
22
- }
23
- }
24
-
25
- if (token.type === TokenType.DIMENSION_TOKEN) {
26
- // Parse angle and convert to degrees for storage
27
- const radians = angle.parse(_context, token);
28
- // Store as degrees for consistency
29
- return (radians * 180) / Math.PI;
30
- }
31
-
32
- return null;
33
- }
34
- };
@@ -1,26 +0,0 @@
1
- import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { Context } from '../../core/context';
3
- export const enum TEXT_ALIGN {
4
- LEFT = 0,
5
- CENTER = 1,
6
- RIGHT = 2
7
- }
8
-
9
- export const textAlign: IPropertyIdentValueDescriptor<TEXT_ALIGN> = {
10
- name: 'text-align',
11
- initialValue: 'left',
12
- prefix: false,
13
- type: PropertyDescriptorParsingType.IDENT_VALUE,
14
- parse: (_context: Context, textAlign: string) => {
15
- switch (textAlign) {
16
- case 'right':
17
- return TEXT_ALIGN.RIGHT;
18
- case 'center':
19
- case 'justify':
20
- return TEXT_ALIGN.CENTER;
21
- case 'left':
22
- default:
23
- return TEXT_ALIGN.LEFT;
24
- }
25
- }
26
- };
@@ -1,9 +0,0 @@
1
- import { IPropertyTypeValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
-
3
- export const textDecorationColor: IPropertyTypeValueDescriptor = {
4
- name: `text-decoration-color`,
5
- initialValue: 'transparent',
6
- prefix: false,
7
- type: PropertyDescriptorParsingType.TYPE_VALUE,
8
- format: 'color'
9
- };
@@ -1,38 +0,0 @@
1
- import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue, isIdentToken } from '../syntax/parser';
3
- import { Context } from '../../core/context';
4
-
5
- export const enum TEXT_DECORATION_LINE {
6
- NONE = 0,
7
- UNDERLINE = 1,
8
- OVERLINE = 2,
9
- LINE_THROUGH = 3,
10
- BLINK = 4
11
- }
12
-
13
- export type TextDecorationLine = TEXT_DECORATION_LINE[];
14
-
15
- export const textDecorationLine: IPropertyListDescriptor<TextDecorationLine> = {
16
- name: 'text-decoration-line',
17
- initialValue: 'none',
18
- prefix: false,
19
- type: PropertyDescriptorParsingType.LIST,
20
- parse: (_context: Context, tokens: CSSValue[]): TextDecorationLine => {
21
- return tokens
22
- .filter(isIdentToken)
23
- .map((token) => {
24
- switch (token.value) {
25
- case 'underline':
26
- return TEXT_DECORATION_LINE.UNDERLINE;
27
- case 'overline':
28
- return TEXT_DECORATION_LINE.OVERLINE;
29
- case 'line-through':
30
- return TEXT_DECORATION_LINE.LINE_THROUGH;
31
- case 'none':
32
- return TEXT_DECORATION_LINE.BLINK;
33
- }
34
- return TEXT_DECORATION_LINE.NONE;
35
- })
36
- .filter((line) => line !== TEXT_DECORATION_LINE.NONE);
37
- }
38
- };
@@ -1,32 +0,0 @@
1
- import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { Context } from '../../core/context';
3
-
4
- export const enum TEXT_DECORATION_STYLE {
5
- SOLID = 0,
6
- DOUBLE = 1,
7
- DOTTED = 2,
8
- DASHED = 3,
9
- WAVY = 4
10
- }
11
-
12
- export const textDecorationStyle: IPropertyIdentValueDescriptor<TEXT_DECORATION_STYLE> = {
13
- name: 'text-decoration-style',
14
- initialValue: 'solid',
15
- prefix: false,
16
- type: PropertyDescriptorParsingType.IDENT_VALUE,
17
- parse: (_context: Context, style: string): TEXT_DECORATION_STYLE => {
18
- switch (style) {
19
- case 'double':
20
- return TEXT_DECORATION_STYLE.DOUBLE;
21
- case 'dotted':
22
- return TEXT_DECORATION_STYLE.DOTTED;
23
- case 'dashed':
24
- return TEXT_DECORATION_STYLE.DASHED;
25
- case 'wavy':
26
- return TEXT_DECORATION_STYLE.WAVY;
27
- case 'solid':
28
- default:
29
- return TEXT_DECORATION_STYLE.SOLID;
30
- }
31
- }
32
- };
@@ -1,30 +0,0 @@
1
- import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue, isIdentToken, isDimensionToken } from '../syntax/parser';
3
- import { Context } from '../../core/context';
4
-
5
- export type TextDecorationThickness = number | 'auto' | 'from-font';
6
-
7
- export const textDecorationThickness: IPropertyValueDescriptor<TextDecorationThickness> = {
8
- name: 'text-decoration-thickness',
9
- initialValue: 'auto',
10
- prefix: false,
11
- type: PropertyDescriptorParsingType.VALUE,
12
- parse: (_context: Context, token: CSSValue): TextDecorationThickness => {
13
- if (isIdentToken(token)) {
14
- switch (token.value) {
15
- case 'auto':
16
- return 'auto';
17
- case 'from-font':
18
- return 'from-font';
19
- }
20
- }
21
-
22
- if (isDimensionToken(token)) {
23
- // Convert to pixels
24
- return token.number;
25
- }
26
-
27
- // Default to auto
28
- return 'auto';
29
- }
30
- };
@@ -1,23 +0,0 @@
1
- import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { Context } from '../../core/context';
3
-
4
- export const enum TEXT_OVERFLOW {
5
- CLIP = 0,
6
- ELLIPSIS = 1
7
- }
8
-
9
- export const textOverflow: IPropertyIdentValueDescriptor<TEXT_OVERFLOW> = {
10
- name: 'text-overflow',
11
- initialValue: 'clip',
12
- prefix: false,
13
- type: PropertyDescriptorParsingType.IDENT_VALUE,
14
- parse: (_context: Context, textOverflow: string) => {
15
- switch (textOverflow) {
16
- case 'ellipsis':
17
- return TEXT_OVERFLOW.ELLIPSIS;
18
- case 'clip':
19
- default:
20
- return TEXT_OVERFLOW.CLIP;
21
- }
22
- }
23
- };
@@ -1,52 +0,0 @@
1
- import { PropertyDescriptorParsingType, IPropertyListDescriptor } from '../property-descriptor';
2
- import { CSSValue, isIdentWithValue, parseFunctionArgs } from '../syntax/parser';
3
- import { ZERO_LENGTH } from '../types/length-percentage';
4
- import { color, Color, COLORS } from '../types/color';
5
- import { isLength, Length } from '../types/length';
6
- import { Context } from '../../core/context';
7
-
8
- export type TextShadow = TextShadowItem[];
9
- interface TextShadowItem {
10
- color: Color;
11
- offsetX: Length;
12
- offsetY: Length;
13
- blur: Length;
14
- }
15
-
16
- export const textShadow: IPropertyListDescriptor<TextShadow> = {
17
- name: 'text-shadow',
18
- initialValue: 'none',
19
- type: PropertyDescriptorParsingType.LIST,
20
- prefix: false,
21
- parse: (context: Context, tokens: CSSValue[]): TextShadow => {
22
- if (tokens.length === 1 && isIdentWithValue(tokens[0], 'none')) {
23
- return [];
24
- }
25
-
26
- return parseFunctionArgs(tokens).map((values: CSSValue[]) => {
27
- const shadow: TextShadowItem = {
28
- color: COLORS.TRANSPARENT,
29
- offsetX: ZERO_LENGTH,
30
- offsetY: ZERO_LENGTH,
31
- blur: ZERO_LENGTH
32
- };
33
- let c = 0;
34
- for (let i = 0; i < values.length; i++) {
35
- const token = values[i];
36
- if (isLength(token)) {
37
- if (c === 0) {
38
- shadow.offsetX = token;
39
- } else if (c === 1) {
40
- shadow.offsetY = token;
41
- } else {
42
- shadow.blur = token;
43
- }
44
- c++;
45
- } else {
46
- shadow.color = color.parse(context, token);
47
- }
48
- }
49
- return shadow;
50
- });
51
- }
52
- };
@@ -1,27 +0,0 @@
1
- import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { Context } from '../../core/context';
3
- export const enum TEXT_TRANSFORM {
4
- NONE = 0,
5
- LOWERCASE = 1,
6
- UPPERCASE = 2,
7
- CAPITALIZE = 3
8
- }
9
-
10
- export const textTransform: IPropertyIdentValueDescriptor<TEXT_TRANSFORM> = {
11
- name: 'text-transform',
12
- initialValue: 'none',
13
- prefix: false,
14
- type: PropertyDescriptorParsingType.IDENT_VALUE,
15
- parse: (_context: Context, textTransform: string) => {
16
- switch (textTransform) {
17
- case 'uppercase':
18
- return TEXT_TRANSFORM.UPPERCASE;
19
- case 'lowercase':
20
- return TEXT_TRANSFORM.LOWERCASE;
21
- case 'capitalize':
22
- return TEXT_TRANSFORM.CAPITALIZE;
23
- }
24
-
25
- return TEXT_TRANSFORM.NONE;
26
- }
27
- };
@@ -1,27 +0,0 @@
1
- import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue, isIdentToken, isDimensionToken } from '../syntax/parser';
3
- import { Context } from '../../core/context';
4
-
5
- export type TextUnderlineOffset = number | 'auto';
6
-
7
- export const textUnderlineOffset: IPropertyValueDescriptor<TextUnderlineOffset> = {
8
- name: 'text-underline-offset',
9
- initialValue: 'auto',
10
- prefix: false,
11
- type: PropertyDescriptorParsingType.VALUE,
12
- parse: (_context: Context, token: CSSValue): TextUnderlineOffset => {
13
- if (isIdentToken(token)) {
14
- if (token.value === 'auto') {
15
- return 'auto';
16
- }
17
- }
18
-
19
- if (isDimensionToken(token)) {
20
- // Return pixel value
21
- return token.number;
22
- }
23
-
24
- // Default to auto
25
- return 'auto';
26
- }
27
- };
@@ -1,29 +0,0 @@
1
- import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue } from '../syntax/parser';
3
- import { isLengthPercentage, LengthPercentage } from '../types/length-percentage';
4
- import { FLAG_INTEGER, TokenType } from '../syntax/tokenizer';
5
- import { Context } from '../../core/context';
6
- export type TransformOrigin = [LengthPercentage, LengthPercentage];
7
-
8
- const DEFAULT_VALUE: LengthPercentage = {
9
- type: TokenType.PERCENTAGE_TOKEN,
10
- number: 50,
11
- flags: FLAG_INTEGER
12
- };
13
- const DEFAULT: TransformOrigin = [DEFAULT_VALUE, DEFAULT_VALUE];
14
-
15
- export const transformOrigin: IPropertyListDescriptor<TransformOrigin> = {
16
- name: 'transform-origin',
17
- initialValue: '50% 50%',
18
- prefix: true,
19
- type: PropertyDescriptorParsingType.LIST,
20
- parse: (_context: Context, tokens: CSSValue[]) => {
21
- const origins: LengthPercentage[] = tokens.filter(isLengthPercentage);
22
-
23
- if (origins.length !== 2) {
24
- return DEFAULT;
25
- }
26
-
27
- return [origins[0], origins[1]];
28
- }
29
- };
@@ -1,74 +0,0 @@
1
- import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue } from '../syntax/parser';
3
- import { NumberValueToken, TokenType } from '../syntax/tokenizer';
4
- import { Context } from '../../core/context';
5
- import { angle } from '../types/angle';
6
- export type Matrix = [number, number, number, number, number, number];
7
- export type Transform = Matrix | null;
8
-
9
- export const transform: IPropertyValueDescriptor<Transform> = {
10
- name: 'transform',
11
- initialValue: 'none',
12
- prefix: true,
13
- type: PropertyDescriptorParsingType.VALUE,
14
- parse: (_context: Context, token: CSSValue) => {
15
- if (token.type === TokenType.IDENT_TOKEN && token.value === 'none') {
16
- return null;
17
- }
18
-
19
- if (token.type === TokenType.FUNCTION) {
20
- const transformFunction = SUPPORTED_TRANSFORM_FUNCTIONS[token.name];
21
- if (typeof transformFunction === 'undefined') {
22
- throw new Error(`Attempting to parse an unsupported transform function "${token.name}"`);
23
- }
24
- return transformFunction(_context, token.values);
25
- }
26
-
27
- return null;
28
- }
29
- };
30
-
31
- const matrix = (_context: Context, args: CSSValue[]): Transform => {
32
- const values = args.filter((arg) => arg.type === TokenType.NUMBER_TOKEN).map((arg: NumberValueToken) => arg.number);
33
-
34
- return values.length === 6 ? (values as Matrix) : null;
35
- };
36
-
37
- // doesn't support 3D transforms at the moment
38
- const matrix3d = (_context: Context, args: CSSValue[]): Transform => {
39
- const values = args.filter((arg) => arg.type === TokenType.NUMBER_TOKEN).map((arg: NumberValueToken) => arg.number);
40
-
41
- const [a1, b1, {}, {}, a2, b2, {}, {}, {}, {}, {}, {}, a4, b4, {}, {}] = values;
42
-
43
- return values.length === 16 ? [a1, b1, a2, b2, a4, b4] : null;
44
- };
45
-
46
- const rotate = (context: Context, args: CSSValue[]): Transform => {
47
- if (args.length !== 1) {
48
- return null;
49
- }
50
-
51
- const arg = args[0];
52
- let radians = 0;
53
-
54
- if (arg.type === TokenType.NUMBER_TOKEN && arg.number === 0) {
55
- radians = 0;
56
- } else if (arg.type === TokenType.DIMENSION_TOKEN) {
57
- radians = angle.parse(context, arg);
58
- } else {
59
- return null;
60
- }
61
-
62
- const cos = Math.cos(radians);
63
- const sin = Math.sin(radians);
64
-
65
- return [cos, sin, -sin, cos, 0, 0];
66
- };
67
-
68
- const SUPPORTED_TRANSFORM_FUNCTIONS: {
69
- [key: string]: (context: Context, args: CSSValue[]) => Transform;
70
- } = {
71
- matrix: matrix,
72
- matrix3d: matrix3d,
73
- rotate: rotate
74
- };
@@ -1,25 +0,0 @@
1
- import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { Context } from '../../core/context';
3
- export const enum VISIBILITY {
4
- VISIBLE = 0,
5
- HIDDEN = 1,
6
- COLLAPSE = 2
7
- }
8
-
9
- export const visibility: IPropertyIdentValueDescriptor<VISIBILITY> = {
10
- name: 'visible',
11
- initialValue: 'none',
12
- prefix: false,
13
- type: PropertyDescriptorParsingType.IDENT_VALUE,
14
- parse: (_context: Context, visibility: string) => {
15
- switch (visibility) {
16
- case 'hidden':
17
- return VISIBILITY.HIDDEN;
18
- case 'collapse':
19
- return VISIBILITY.COLLAPSE;
20
- case 'visible':
21
- default:
22
- return VISIBILITY.VISIBLE;
23
- }
24
- }
25
- };
@@ -1,30 +0,0 @@
1
- import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue } from '../syntax/parser';
3
- import { TokenType } from '../syntax/tokenizer';
4
- import { Context } from '../../core/context';
5
-
6
- /**
7
- * -webkit-line-clamp property descriptor
8
- * Used with display: -webkit-box and -webkit-box-orient: vertical
9
- * to limit text to a specific number of lines
10
- */
11
- export const webkitLineClamp: IPropertyValueDescriptor<number> = {
12
- name: '-webkit-line-clamp',
13
- initialValue: 'none',
14
- prefix: true,
15
- type: PropertyDescriptorParsingType.VALUE,
16
- parse: (_context: Context, token: CSSValue) => {
17
- // 'none' means no line clamping
18
- if (token.type === TokenType.IDENT_TOKEN && token.value === 'none') {
19
- return 0;
20
- }
21
-
22
- // Number value specifies the number of lines
23
- if (token.type === TokenType.NUMBER_TOKEN) {
24
- return Math.max(0, Math.floor(token.number));
25
- }
26
-
27
- // Default to 0 (no clamping)
28
- return 0;
29
- }
30
- };
@@ -1,8 +0,0 @@
1
- import { IPropertyTypeValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- export const webkitTextStrokeColor: IPropertyTypeValueDescriptor = {
3
- name: `-webkit-text-stroke-color`,
4
- initialValue: 'currentcolor',
5
- prefix: false,
6
- type: PropertyDescriptorParsingType.TYPE_VALUE,
7
- format: 'color'
8
- };
@@ -1,15 +0,0 @@
1
- import { CSSValue, isDimensionToken } from '../syntax/parser';
2
- import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
3
- import { Context } from '../../core/context';
4
- export const webkitTextStrokeWidth: IPropertyValueDescriptor<number> = {
5
- name: `-webkit-text-stroke-width`,
6
- initialValue: '0',
7
- type: PropertyDescriptorParsingType.VALUE,
8
- prefix: false,
9
- parse: (_context: Context, token: CSSValue): number => {
10
- if (isDimensionToken(token)) {
11
- return token.number;
12
- }
13
- return 0;
14
- }
15
- };
@@ -1,25 +0,0 @@
1
- import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { Context } from '../../core/context';
3
- export enum WORD_BREAK {
4
- NORMAL = 'normal',
5
- BREAK_ALL = 'break-all',
6
- KEEP_ALL = 'keep-all'
7
- }
8
-
9
- export const wordBreak: IPropertyIdentValueDescriptor<WORD_BREAK> = {
10
- name: 'word-break',
11
- initialValue: 'normal',
12
- prefix: false,
13
- type: PropertyDescriptorParsingType.IDENT_VALUE,
14
- parse: (_context: Context, wordBreak: string): WORD_BREAK => {
15
- switch (wordBreak) {
16
- case 'break-all':
17
- return WORD_BREAK.BREAK_ALL;
18
- case 'keep-all':
19
- return WORD_BREAK.KEEP_ALL;
20
- case 'normal':
21
- default:
22
- return WORD_BREAK.NORMAL;
23
- }
24
- }
25
- };