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,19 +0,0 @@
1
- import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue } from '../syntax/parser';
3
- import { isLengthPercentage, LengthPercentageTuple, parseLengthPercentageTuple } from '../types/length-percentage';
4
- import { Context } from '../../core/context';
5
- export type BorderRadius = LengthPercentageTuple;
6
-
7
- const borderRadiusForSide = (side: string): IPropertyListDescriptor<BorderRadius> => ({
8
- name: `border-radius-${side}`,
9
- initialValue: '0 0',
10
- prefix: false,
11
- type: PropertyDescriptorParsingType.LIST,
12
- parse: (_context: Context, tokens: CSSValue[]): BorderRadius =>
13
- parseLengthPercentageTuple(tokens.filter(isLengthPercentage))
14
- });
15
-
16
- export const borderTopLeftRadius: IPropertyListDescriptor<BorderRadius> = borderRadiusForSide('top-left');
17
- export const borderTopRightRadius: IPropertyListDescriptor<BorderRadius> = borderRadiusForSide('top-right');
18
- export const borderBottomRightRadius: IPropertyListDescriptor<BorderRadius> = borderRadiusForSide('bottom-right');
19
- export const borderBottomLeftRadius: IPropertyListDescriptor<BorderRadius> = borderRadiusForSide('bottom-left');
@@ -1,34 +0,0 @@
1
- import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { Context } from '../../core/context';
3
- export const enum BORDER_STYLE {
4
- NONE = 0,
5
- SOLID = 1,
6
- DASHED = 2,
7
- DOTTED = 3,
8
- DOUBLE = 4
9
- }
10
-
11
- const borderStyleForSide = (side: string): IPropertyIdentValueDescriptor<BORDER_STYLE> => ({
12
- name: `border-${side}-style`,
13
- initialValue: 'solid',
14
- prefix: false,
15
- type: PropertyDescriptorParsingType.IDENT_VALUE,
16
- parse: (_context: Context, style: string): BORDER_STYLE => {
17
- switch (style) {
18
- case 'none':
19
- return BORDER_STYLE.NONE;
20
- case 'dashed':
21
- return BORDER_STYLE.DASHED;
22
- case 'dotted':
23
- return BORDER_STYLE.DOTTED;
24
- case 'double':
25
- return BORDER_STYLE.DOUBLE;
26
- }
27
- return BORDER_STYLE.SOLID;
28
- }
29
- });
30
-
31
- export const borderTopStyle: IPropertyIdentValueDescriptor<BORDER_STYLE> = borderStyleForSide('top');
32
- export const borderRightStyle: IPropertyIdentValueDescriptor<BORDER_STYLE> = borderStyleForSide('right');
33
- export const borderBottomStyle: IPropertyIdentValueDescriptor<BORDER_STYLE> = borderStyleForSide('bottom');
34
- export const borderLeftStyle: IPropertyIdentValueDescriptor<BORDER_STYLE> = borderStyleForSide('left');
@@ -1,20 +0,0 @@
1
- import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue, isDimensionToken } from '../syntax/parser';
3
- import { Context } from '../../core/context';
4
- const borderWidthForSide = (side: string): IPropertyValueDescriptor<number> => ({
5
- name: `border-${side}-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
- });
16
-
17
- export const borderTopWidth: IPropertyValueDescriptor<number> = borderWidthForSide('top');
18
- export const borderRightWidth: IPropertyValueDescriptor<number> = borderWidthForSide('right');
19
- export const borderBottomWidth: IPropertyValueDescriptor<number> = borderWidthForSide('bottom');
20
- export const borderLeftWidth: IPropertyValueDescriptor<number> = borderWidthForSide('left');
@@ -1,60 +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 } from '../types/color';
5
- import { isLength, Length } from '../types/length';
6
- import { Context } from '../../core/context';
7
-
8
- export type BoxShadow = BoxShadowItem[];
9
- interface BoxShadowItem {
10
- inset: boolean;
11
- color: Color;
12
- offsetX: Length;
13
- offsetY: Length;
14
- blur: Length;
15
- spread: Length;
16
- }
17
-
18
- export const boxShadow: IPropertyListDescriptor<BoxShadow> = {
19
- name: 'box-shadow',
20
- initialValue: 'none',
21
- type: PropertyDescriptorParsingType.LIST,
22
- prefix: false,
23
- parse: (context: Context, tokens: CSSValue[]): BoxShadow => {
24
- if (tokens.length === 1 && isIdentWithValue(tokens[0], 'none')) {
25
- return [];
26
- }
27
-
28
- return parseFunctionArgs(tokens).map((values: CSSValue[]) => {
29
- const shadow: BoxShadowItem = {
30
- color: 0x000000ff,
31
- offsetX: ZERO_LENGTH,
32
- offsetY: ZERO_LENGTH,
33
- blur: ZERO_LENGTH,
34
- spread: ZERO_LENGTH,
35
- inset: false
36
- };
37
- let c = 0;
38
- for (let i = 0; i < values.length; i++) {
39
- const token = values[i];
40
- if (isIdentWithValue(token, 'inset')) {
41
- shadow.inset = true;
42
- } else if (isLength(token)) {
43
- if (c === 0) {
44
- shadow.offsetX = token;
45
- } else if (c === 1) {
46
- shadow.offsetY = token;
47
- } else if (c === 2) {
48
- shadow.blur = token;
49
- } else {
50
- shadow.spread = token;
51
- }
52
- c++;
53
- } else {
54
- shadow.color = color.parse(context, token);
55
- }
56
- }
57
- return shadow;
58
- });
59
- }
60
- };
@@ -1,271 +0,0 @@
1
- import { IPropertyValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue, isIdentToken, isIdentWithValue, nonWhiteSpace, parseFunctionArgs } from '../syntax/parser';
3
- import { StringValueToken, TokenType } from '../syntax/tokenizer';
4
- import {
5
- LengthPercentage,
6
- FIFTY_PERCENT,
7
- HUNDRED_PERCENT,
8
- ZERO_LENGTH,
9
- isLengthPercentage
10
- } from '../types/length-percentage';
11
- import { Context } from '../../core/context';
12
-
13
- export const enum CLIP_PATH_TYPE {
14
- NONE = 0,
15
- INSET = 1,
16
- CIRCLE = 2,
17
- ELLIPSE = 3,
18
- POLYGON = 4,
19
- PATH = 5
20
- }
21
-
22
- /** Radius keyword or length-percentage for circle/ellipse. */
23
- export type ShapeRadius = LengthPercentage | 'closest-side' | 'farthest-side';
24
-
25
- export interface NoneClipPath {
26
- type: CLIP_PATH_TYPE.NONE;
27
- }
28
-
29
- /**
30
- * inset(top right bottom left [ round <border-radius> ]?)
31
- * Amounts to cut from each side of the reference box.
32
- */
33
- export interface InsetClipPath {
34
- type: CLIP_PATH_TYPE.INSET;
35
- top: LengthPercentage;
36
- right: LengthPercentage;
37
- bottom: LengthPercentage;
38
- left: LengthPercentage;
39
- }
40
-
41
- /**
42
- * circle( [ <shape-radius> ]? [ at <position> ]? )
43
- */
44
- export interface CircleClipPath {
45
- type: CLIP_PATH_TYPE.CIRCLE;
46
- radius: ShapeRadius;
47
- cx: LengthPercentage;
48
- cy: LengthPercentage;
49
- }
50
-
51
- /**
52
- * ellipse( [ <shape-radius>{2} ]? [ at <position> ]? )
53
- */
54
- export interface EllipseClipPath {
55
- type: CLIP_PATH_TYPE.ELLIPSE;
56
- rx: ShapeRadius;
57
- ry: ShapeRadius;
58
- cx: LengthPercentage;
59
- cy: LengthPercentage;
60
- }
61
-
62
- /**
63
- * polygon( [ <fill-rule>, ]? [ <length-percentage> <length-percentage> ]# )
64
- */
65
- export interface PolygonClipPath {
66
- type: CLIP_PATH_TYPE.POLYGON;
67
- points: [LengthPercentage, LengthPercentage][];
68
- }
69
-
70
- /**
71
- * path( [ <fill-rule>, ]? <string> )
72
- * The string contains SVG path data in the element's local coordinate space.
73
- */
74
- export interface PathClipPath {
75
- type: CLIP_PATH_TYPE.PATH;
76
- d: string;
77
- }
78
-
79
- export type ClipPathValue =
80
- | NoneClipPath
81
- | InsetClipPath
82
- | CircleClipPath
83
- | EllipseClipPath
84
- | PolygonClipPath
85
- | PathClipPath;
86
-
87
- const NONE: NoneClipPath = { type: CLIP_PATH_TYPE.NONE };
88
-
89
- /**
90
- * Parse a shape-radius token: <length-percentage> | closest-side | farthest-side.
91
- * Defaults to 'closest-side' when no tokens are provided.
92
- */
93
- const parseShapeRadius = (tokens: CSSValue[]): ShapeRadius => {
94
- const [first] = tokens;
95
- if (!first) return 'closest-side';
96
- if (isIdentToken(first)) {
97
- // Any unrecognised keyword (e.g. 'closest-corner') intentionally falls back to
98
- // 'closest-side' as the CSS spec requires unknown values to be treated as invalid
99
- // and the initial value of <shape-radius> is 'closest-side'.
100
- return first.value === 'farthest-side' ? 'farthest-side' : 'closest-side';
101
- }
102
- return isLengthPercentage(first) ? first : 'closest-side';
103
- };
104
-
105
- /**
106
- * Parse a CSS <position> as (cx, cy), each as a LengthPercentage.
107
- *
108
- * Supports the **1–2 value** subset of the CSS `<position>` syntax.
109
- * The 4-value form (`at left 10px top 20px`) is not supported and will be
110
- * parsed on a best-effort basis.
111
- *
112
- * Axis assignment rules:
113
- * - `left` / `right` → x-axis (cx)
114
- * - `top` / `bottom` → y-axis (cy)
115
- * - `center` or a <length-percentage> → fills the first unset axis, in order
116
- *
117
- * Examples:
118
- * "at left" → cx=0, cy=50% (left is x; y defaults to center)
119
- * "at top" → cx=50%, cy=0 (top is y; x defaults to center)
120
- * "at center 30%" → cx=50%, cy=30%
121
- * "at 30% center" → cx=30%, cy=50%
122
- * "at left top" → cx=0, cy=0
123
- * "at top left" → cx=0, cy=0 (keyword order is irrelevant)
124
- *
125
- * Unset axes fall back to 50%.
126
- */
127
- const parsePosition = (tokens: CSSValue[]): { cx: LengthPercentage; cy: LengthPercentage } => {
128
- let cx: LengthPercentage | null = null;
129
- let cy: LengthPercentage | null = null;
130
-
131
- for (const token of tokens) {
132
- if (isIdentToken(token)) {
133
- switch (token.value) {
134
- case 'left':
135
- cx = ZERO_LENGTH;
136
- break;
137
- case 'right':
138
- cx = HUNDRED_PERCENT;
139
- break;
140
- case 'top':
141
- cy = ZERO_LENGTH;
142
- break;
143
- case 'bottom':
144
- cy = HUNDRED_PERCENT;
145
- break;
146
- case 'center':
147
- // `center` fills whichever axis has not yet been claimed.
148
- if (cx === null) cx = FIFTY_PERCENT;
149
- else if (cy === null) cy = FIFTY_PERCENT;
150
- break;
151
- }
152
- } else if (isLengthPercentage(token)) {
153
- // Length-percentages are assigned in source order.
154
- if (cx === null) cx = token;
155
- else if (cy === null) cy = token;
156
- }
157
- }
158
-
159
- return { cx: cx ?? FIFTY_PERCENT, cy: cy ?? FIFTY_PERCENT };
160
- };
161
-
162
- /**
163
- * inset( <length-percentage>{1,4} [ round <'border-radius'> ]? )
164
- * The 1-4 shorthand follows the same expansion as margin/padding:
165
- * 1 value → all four sides
166
- * 2 values → top/bottom | left/right
167
- * 3 values → top | left/right | bottom
168
- * 4 values → top | right | bottom | left
169
- * The optional `round` clause (border-radius) is parsed but ignored.
170
- */
171
- const parseInset = (values: CSSValue[]): InsetClipPath => {
172
- const lengths: LengthPercentage[] = [];
173
- for (const token of values) {
174
- if (token.type === TokenType.WHITESPACE_TOKEN) continue;
175
- if (isIdentToken(token) && token.value === 'round') break;
176
- if (isLengthPercentage(token)) lengths.push(token);
177
- }
178
- const v0 = lengths[0] ?? ZERO_LENGTH;
179
- const v1 = lengths[1] ?? v0;
180
- const v2 = lengths[2] ?? v0;
181
- const v3 = lengths[3] ?? v1;
182
- return { type: CLIP_PATH_TYPE.INSET, top: v0, right: v1, bottom: v2, left: v3 };
183
- };
184
-
185
- /**
186
- * circle( [ <shape-radius> ]? [ at <position> ]? )
187
- */
188
- const parseCircle = (values: CSSValue[]): CircleClipPath => {
189
- const nonWs = values.filter(nonWhiteSpace);
190
- const atIdx = nonWs.findIndex((t) => isIdentWithValue(t, 'at'));
191
- const radiusTokens = atIdx === -1 ? nonWs : nonWs.slice(0, atIdx);
192
- const posTokens = atIdx === -1 ? [] : nonWs.slice(atIdx + 1);
193
- return {
194
- type: CLIP_PATH_TYPE.CIRCLE,
195
- radius: parseShapeRadius(radiusTokens),
196
- ...parsePosition(posTokens)
197
- };
198
- };
199
-
200
- /**
201
- * ellipse( [ <shape-radius>{2} ]? [ at <position> ]? )
202
- */
203
- const parseEllipse = (values: CSSValue[]): EllipseClipPath => {
204
- const nonWs = values.filter(nonWhiteSpace);
205
- const atIdx = nonWs.findIndex((t) => isIdentWithValue(t, 'at'));
206
- const radiusTokens = atIdx === -1 ? nonWs : nonWs.slice(0, atIdx);
207
- const posTokens = atIdx === -1 ? [] : nonWs.slice(atIdx + 1);
208
- return {
209
- type: CLIP_PATH_TYPE.ELLIPSE,
210
- rx: parseShapeRadius(radiusTokens.slice(0, 1)),
211
- ry: parseShapeRadius(radiusTokens.slice(1, 2)),
212
- ...parsePosition(posTokens)
213
- };
214
- };
215
-
216
- /**
217
- * polygon( [ <fill-rule>, ]? [ <length-percentage> <length-percentage> ]# )
218
- * Each comma-separated group defines one vertex (x y).
219
- * A leading fill-rule keyword (nonzero/evenodd) is skipped.
220
- */
221
- const parsePolygon = (values: CSSValue[]): PolygonClipPath => {
222
- const args = parseFunctionArgs(values);
223
- const points: [LengthPercentage, LengthPercentage][] = [];
224
- for (const arg of args) {
225
- if (arg.length === 1 && isIdentToken(arg[0])) continue; // skip fill-rule
226
- const lengths = arg.filter(isLengthPercentage);
227
- if (lengths.length >= 2) {
228
- points.push([lengths[0], lengths[1]]);
229
- }
230
- }
231
- return { type: CLIP_PATH_TYPE.POLYGON, points };
232
- };
233
-
234
- /**
235
- * path( [ <fill-rule>, ]? <string> )
236
- * The string value is the SVG path data (coordinates in the element's local space).
237
- */
238
- const parsePath = (values: CSSValue[]): PathClipPath | NoneClipPath => {
239
- const stringToken = values.find((t) => t.type === TokenType.STRING_TOKEN) as StringValueToken | undefined;
240
- if (!stringToken) return NONE;
241
- return { type: CLIP_PATH_TYPE.PATH, d: stringToken.value };
242
- };
243
-
244
- export const clipPath: IPropertyValueDescriptor<ClipPathValue> = {
245
- name: 'clip-path',
246
- initialValue: 'none',
247
- prefix: false,
248
- type: PropertyDescriptorParsingType.VALUE,
249
- parse: (_context: Context, token: CSSValue): ClipPathValue => {
250
- if (isIdentToken(token) && token.value === 'none') {
251
- return NONE;
252
- }
253
-
254
- if (token.type === TokenType.FUNCTION) {
255
- switch (token.name) {
256
- case 'inset':
257
- return parseInset(token.values);
258
- case 'circle':
259
- return parseCircle(token.values);
260
- case 'ellipse':
261
- return parseEllipse(token.values);
262
- case 'polygon':
263
- return parsePolygon(token.values);
264
- case 'path':
265
- return parsePath(token.values);
266
- }
267
- }
268
-
269
- return NONE;
270
- }
271
- };
@@ -1,9 +0,0 @@
1
- import { IPropertyTypeValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
-
3
- export const color: IPropertyTypeValueDescriptor = {
4
- name: `color`,
5
- initialValue: 'transparent',
6
- prefix: false,
7
- type: PropertyDescriptorParsingType.TYPE_VALUE,
8
- format: 'color'
9
- };
@@ -1,26 +0,0 @@
1
- import { TokenType } from '../syntax/tokenizer';
2
- import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
3
- import { CSSValue } from '../syntax/parser';
4
- import { Context } from '../../core/context';
5
-
6
- export type Content = CSSValue[];
7
-
8
- export const content: IPropertyListDescriptor<Content> = {
9
- name: 'content',
10
- initialValue: 'none',
11
- type: PropertyDescriptorParsingType.LIST,
12
- prefix: false,
13
- parse: (_context: Context, tokens: CSSValue[]) => {
14
- if (tokens.length === 0) {
15
- return [];
16
- }
17
-
18
- const first = tokens[0];
19
-
20
- if (first.type === TokenType.IDENT_TOKEN && first.value === 'none') {
21
- return [];
22
- }
23
-
24
- return tokens;
25
- }
26
- };
@@ -1,43 +0,0 @@
1
- import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue, isNumberToken, nonWhiteSpace } from '../syntax/parser';
3
- import { TokenType } from '../syntax/tokenizer';
4
- import { Context } from '../../core/context';
5
-
6
- export interface COUNTER_INCREMENT {
7
- counter: string;
8
- increment: number;
9
- }
10
-
11
- export type CounterIncrement = COUNTER_INCREMENT[] | null;
12
-
13
- export const counterIncrement: IPropertyListDescriptor<CounterIncrement> = {
14
- name: 'counter-increment',
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 increments = [];
30
- const filtered = tokens.filter(nonWhiteSpace);
31
-
32
- for (let i = 0; i < filtered.length; i++) {
33
- const counter = filtered[i];
34
- const next = filtered[i + 1];
35
- if (counter.type === TokenType.IDENT_TOKEN) {
36
- const increment = next && isNumberToken(next) ? next.number : 1;
37
- increments.push({ counter: counter.value, increment });
38
- }
39
- }
40
-
41
- return increments;
42
- }
43
- };
@@ -1,36 +0,0 @@
1
- import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { CSSValue, isIdentToken, isNumberToken, nonWhiteSpace } from '../syntax/parser';
3
- import { Context } from '../../core/context';
4
-
5
- export interface COUNTER_RESET {
6
- counter: string;
7
- reset: number;
8
- }
9
-
10
- export type CounterReset = COUNTER_RESET[];
11
-
12
- export const counterReset: IPropertyListDescriptor<CounterReset> = {
13
- name: 'counter-reset',
14
- initialValue: 'none',
15
- prefix: true,
16
- type: PropertyDescriptorParsingType.LIST,
17
- parse: (_context: Context, tokens: CSSValue[]) => {
18
- if (tokens.length === 0) {
19
- return [];
20
- }
21
-
22
- const resets = [];
23
- const filtered = tokens.filter(nonWhiteSpace);
24
-
25
- for (let i = 0; i < filtered.length; i++) {
26
- const counter = filtered[i];
27
- const next = filtered[i + 1];
28
- if (isIdentToken(counter) && counter.value !== 'none') {
29
- const reset = next && isNumberToken(next) ? next.number : 0;
30
- resets.push({ counter: counter.value, reset });
31
- }
32
- }
33
-
34
- return resets;
35
- }
36
- };
@@ -1,23 +0,0 @@
1
- import { IPropertyIdentValueDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { Context } from '../../core/context';
3
-
4
- export const enum DIRECTION {
5
- LTR = 0,
6
- RTL = 1
7
- }
8
-
9
- export const direction: IPropertyIdentValueDescriptor<DIRECTION> = {
10
- name: 'direction',
11
- initialValue: 'ltr',
12
- prefix: false,
13
- type: PropertyDescriptorParsingType.IDENT_VALUE,
14
- parse: (_context: Context, direction: string) => {
15
- switch (direction) {
16
- case 'rtl':
17
- return DIRECTION.RTL;
18
- case 'ltr':
19
- default:
20
- return DIRECTION.LTR;
21
- }
22
- }
23
- };
@@ -1,117 +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 DISPLAY {
5
- NONE = 0,
6
- BLOCK = 1 << 1,
7
- INLINE = 1 << 2,
8
- RUN_IN = 1 << 3,
9
- FLOW = 1 << 4,
10
- FLOW_ROOT = 1 << 5,
11
- TABLE = 1 << 6,
12
- FLEX = 1 << 7,
13
- GRID = 1 << 8,
14
- RUBY = 1 << 9,
15
- SUBGRID = 1 << 10,
16
- LIST_ITEM = 1 << 11,
17
- TABLE_ROW_GROUP = 1 << 12,
18
- TABLE_HEADER_GROUP = 1 << 13,
19
- TABLE_FOOTER_GROUP = 1 << 14,
20
- TABLE_ROW = 1 << 15,
21
- TABLE_CELL = 1 << 16,
22
- TABLE_COLUMN_GROUP = 1 << 17,
23
- TABLE_COLUMN = 1 << 18,
24
- TABLE_CAPTION = 1 << 19,
25
- RUBY_BASE = 1 << 20,
26
- RUBY_TEXT = 1 << 21,
27
- RUBY_BASE_CONTAINER = 1 << 22,
28
- RUBY_TEXT_CONTAINER = 1 << 23,
29
- CONTENTS = 1 << 24,
30
- INLINE_BLOCK = 1 << 25,
31
- INLINE_LIST_ITEM = 1 << 26,
32
- INLINE_TABLE = 1 << 27,
33
- INLINE_FLEX = 1 << 28,
34
- INLINE_GRID = 1 << 29
35
- }
36
-
37
- export type Display = number;
38
-
39
- export const display: IPropertyListDescriptor<Display> = {
40
- name: 'display',
41
- initialValue: 'inline-block',
42
- prefix: false,
43
- type: PropertyDescriptorParsingType.LIST,
44
- parse: (_context: Context, tokens: CSSValue[]): Display => {
45
- return tokens.filter(isIdentToken).reduce((bit, token) => {
46
- return bit | parseDisplayValue(token.value);
47
- }, DISPLAY.NONE);
48
- }
49
- };
50
-
51
- const parseDisplayValue = (display: string): Display => {
52
- switch (display) {
53
- case 'block':
54
- case '-webkit-box':
55
- return DISPLAY.BLOCK;
56
- case 'inline':
57
- return DISPLAY.INLINE;
58
- case 'run-in':
59
- return DISPLAY.RUN_IN;
60
- case 'flow':
61
- return DISPLAY.FLOW;
62
- case 'flow-root':
63
- return DISPLAY.FLOW_ROOT;
64
- case 'table':
65
- return DISPLAY.TABLE;
66
- case 'flex':
67
- case '-webkit-flex':
68
- return DISPLAY.FLEX;
69
- case 'grid':
70
- case '-ms-grid':
71
- return DISPLAY.GRID;
72
- case 'ruby':
73
- return DISPLAY.RUBY;
74
- case 'subgrid':
75
- return DISPLAY.SUBGRID;
76
- case 'list-item':
77
- return DISPLAY.LIST_ITEM;
78
- case 'table-row-group':
79
- return DISPLAY.TABLE_ROW_GROUP;
80
- case 'table-header-group':
81
- return DISPLAY.TABLE_HEADER_GROUP;
82
- case 'table-footer-group':
83
- return DISPLAY.TABLE_FOOTER_GROUP;
84
- case 'table-row':
85
- return DISPLAY.TABLE_ROW;
86
- case 'table-cell':
87
- return DISPLAY.TABLE_CELL;
88
- case 'table-column-group':
89
- return DISPLAY.TABLE_COLUMN_GROUP;
90
- case 'table-column':
91
- return DISPLAY.TABLE_COLUMN;
92
- case 'table-caption':
93
- return DISPLAY.TABLE_CAPTION;
94
- case 'ruby-base':
95
- return DISPLAY.RUBY_BASE;
96
- case 'ruby-text':
97
- return DISPLAY.RUBY_TEXT;
98
- case 'ruby-base-container':
99
- return DISPLAY.RUBY_BASE_CONTAINER;
100
- case 'ruby-text-container':
101
- return DISPLAY.RUBY_TEXT_CONTAINER;
102
- case 'contents':
103
- return DISPLAY.CONTENTS;
104
- case 'inline-block':
105
- return DISPLAY.INLINE_BLOCK;
106
- case 'inline-list-item':
107
- return DISPLAY.INLINE_LIST_ITEM;
108
- case 'inline-table':
109
- return DISPLAY.INLINE_TABLE;
110
- case 'inline-flex':
111
- return DISPLAY.INLINE_FLEX;
112
- case 'inline-grid':
113
- return DISPLAY.INLINE_GRID;
114
- }
115
-
116
- return DISPLAY.NONE;
117
- };
@@ -1,14 +0,0 @@
1
- import { IPropertyListDescriptor, PropertyDescriptorParsingType } from '../property-descriptor';
2
- import { Context } from '../../core/context';
3
- import { CSSValue, isDimensionToken } from '../syntax/parser';
4
- import { time } from '../types/time';
5
-
6
- export const duration: IPropertyListDescriptor<number[]> = {
7
- name: 'duration',
8
- initialValue: '0s',
9
- prefix: false,
10
- type: PropertyDescriptorParsingType.LIST,
11
- parse: (context: Context, tokens: CSSValue[]) => {
12
- return tokens.filter(isDimensionToken).map((token) => time.parse(context, token));
13
- }
14
- };