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
@@ -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
- };