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,822 +0,0 @@
1
- // https://www.w3.org/TR/css-syntax-3
2
-
3
- import { fromCodePoint, toCodePoints } from 'css-line-break';
4
-
5
- export const enum TokenType {
6
- STRING_TOKEN,
7
- BAD_STRING_TOKEN,
8
- LEFT_PARENTHESIS_TOKEN,
9
- RIGHT_PARENTHESIS_TOKEN,
10
- COMMA_TOKEN,
11
- HASH_TOKEN,
12
- DELIM_TOKEN,
13
- AT_KEYWORD_TOKEN,
14
- PREFIX_MATCH_TOKEN,
15
- DASH_MATCH_TOKEN,
16
- INCLUDE_MATCH_TOKEN,
17
- LEFT_CURLY_BRACKET_TOKEN,
18
- RIGHT_CURLY_BRACKET_TOKEN,
19
- SUFFIX_MATCH_TOKEN,
20
- SUBSTRING_MATCH_TOKEN,
21
- DIMENSION_TOKEN,
22
- PERCENTAGE_TOKEN,
23
- NUMBER_TOKEN,
24
- FUNCTION,
25
- FUNCTION_TOKEN,
26
- IDENT_TOKEN,
27
- COLUMN_TOKEN,
28
- URL_TOKEN,
29
- BAD_URL_TOKEN,
30
- CDC_TOKEN,
31
- CDO_TOKEN,
32
- COLON_TOKEN,
33
- SEMICOLON_TOKEN,
34
- LEFT_SQUARE_BRACKET_TOKEN,
35
- RIGHT_SQUARE_BRACKET_TOKEN,
36
- UNICODE_RANGE_TOKEN,
37
- WHITESPACE_TOKEN,
38
- EOF_TOKEN
39
- }
40
-
41
- interface IToken {
42
- type: TokenType;
43
- }
44
-
45
- export interface Token extends IToken {
46
- type:
47
- | TokenType.BAD_URL_TOKEN
48
- | TokenType.BAD_STRING_TOKEN
49
- | TokenType.LEFT_PARENTHESIS_TOKEN
50
- | TokenType.RIGHT_PARENTHESIS_TOKEN
51
- | TokenType.COMMA_TOKEN
52
- | TokenType.SUBSTRING_MATCH_TOKEN
53
- | TokenType.PREFIX_MATCH_TOKEN
54
- | TokenType.SUFFIX_MATCH_TOKEN
55
- | TokenType.COLON_TOKEN
56
- | TokenType.SEMICOLON_TOKEN
57
- | TokenType.LEFT_SQUARE_BRACKET_TOKEN
58
- | TokenType.RIGHT_SQUARE_BRACKET_TOKEN
59
- | TokenType.LEFT_CURLY_BRACKET_TOKEN
60
- | TokenType.RIGHT_CURLY_BRACKET_TOKEN
61
- | TokenType.DASH_MATCH_TOKEN
62
- | TokenType.INCLUDE_MATCH_TOKEN
63
- | TokenType.COLUMN_TOKEN
64
- | TokenType.WHITESPACE_TOKEN
65
- | TokenType.CDC_TOKEN
66
- | TokenType.CDO_TOKEN
67
- | TokenType.EOF_TOKEN;
68
- }
69
-
70
- export interface StringValueToken extends IToken {
71
- type:
72
- | TokenType.STRING_TOKEN
73
- | TokenType.DELIM_TOKEN
74
- | TokenType.FUNCTION_TOKEN
75
- | TokenType.IDENT_TOKEN
76
- | TokenType.URL_TOKEN
77
- | TokenType.AT_KEYWORD_TOKEN;
78
- value: string;
79
- }
80
-
81
- export interface HashToken extends IToken {
82
- type: TokenType.HASH_TOKEN;
83
- flags: number;
84
- value: string;
85
- }
86
-
87
- export interface NumberValueToken extends IToken {
88
- type: TokenType.PERCENTAGE_TOKEN | TokenType.NUMBER_TOKEN;
89
- flags: number;
90
- number: number;
91
- }
92
-
93
- export interface DimensionToken extends IToken {
94
- type: TokenType.DIMENSION_TOKEN;
95
- flags: number;
96
- unit: string;
97
- number: number;
98
- }
99
-
100
- export interface UnicodeRangeToken extends IToken {
101
- type: TokenType.UNICODE_RANGE_TOKEN;
102
- start: number;
103
- end: number;
104
- }
105
-
106
- export type CSSToken = Token | StringValueToken | NumberValueToken | DimensionToken | UnicodeRangeToken | HashToken;
107
-
108
- export const FLAG_UNRESTRICTED = 1 << 0;
109
- export const FLAG_ID = 1 << 1;
110
- export const FLAG_INTEGER = 1 << 2;
111
- export const FLAG_NUMBER = 1 << 3;
112
-
113
- const LINE_FEED = 0x000a;
114
- const SOLIDUS = 0x002f;
115
- const REVERSE_SOLIDUS = 0x005c;
116
- const CHARACTER_TABULATION = 0x0009;
117
- const SPACE = 0x0020;
118
- const QUOTATION_MARK = 0x0022;
119
- const EQUALS_SIGN = 0x003d;
120
- const NUMBER_SIGN = 0x0023;
121
- const DOLLAR_SIGN = 0x0024;
122
- const PERCENTAGE_SIGN = 0x0025;
123
- const APOSTROPHE = 0x0027;
124
- const LEFT_PARENTHESIS = 0x0028;
125
- const RIGHT_PARENTHESIS = 0x0029;
126
- const LOW_LINE = 0x005f;
127
- const HYPHEN_MINUS = 0x002d;
128
- const EXCLAMATION_MARK = 0x0021;
129
- const LESS_THAN_SIGN = 0x003c;
130
- const GREATER_THAN_SIGN = 0x003e;
131
- const COMMERCIAL_AT = 0x0040;
132
- const LEFT_SQUARE_BRACKET = 0x005b;
133
- const RIGHT_SQUARE_BRACKET = 0x005d;
134
- const CIRCUMFLEX_ACCENT = 0x003d;
135
- const LEFT_CURLY_BRACKET = 0x007b;
136
- const QUESTION_MARK = 0x003f;
137
- const RIGHT_CURLY_BRACKET = 0x007d;
138
- const VERTICAL_LINE = 0x007c;
139
- const TILDE = 0x007e;
140
- const CONTROL = 0x0080;
141
- const REPLACEMENT_CHARACTER = 0xfffd;
142
- const ASTERISK = 0x002a;
143
- const PLUS_SIGN = 0x002b;
144
- const COMMA = 0x002c;
145
- const COLON = 0x003a;
146
- const SEMICOLON = 0x003b;
147
- const FULL_STOP = 0x002e;
148
- const NULL = 0x0000;
149
- const BACKSPACE = 0x0008;
150
- const LINE_TABULATION = 0x000b;
151
- const SHIFT_OUT = 0x000e;
152
- const INFORMATION_SEPARATOR_ONE = 0x001f;
153
- const DELETE = 0x007f;
154
- const EOF = -1;
155
- const ZERO = 0x0030;
156
- const a = 0x0061;
157
- const e = 0x0065;
158
- const f = 0x0066;
159
- const u = 0x0075;
160
- const z = 0x007a;
161
- const A = 0x0041;
162
- const E = 0x0045;
163
- const F = 0x0046;
164
- const U = 0x0055;
165
- const Z = 0x005a;
166
-
167
- const isDigit = (codePoint: number) => codePoint >= ZERO && codePoint <= 0x0039;
168
- const isSurrogateCodePoint = (codePoint: number) => codePoint >= 0xd800 && codePoint <= 0xdfff;
169
- const isHex = (codePoint: number) =>
170
- isDigit(codePoint) || (codePoint >= A && codePoint <= F) || (codePoint >= a && codePoint <= f);
171
- const isLowerCaseLetter = (codePoint: number) => codePoint >= a && codePoint <= z;
172
- const isUpperCaseLetter = (codePoint: number) => codePoint >= A && codePoint <= Z;
173
- const isLetter = (codePoint: number) => isLowerCaseLetter(codePoint) || isUpperCaseLetter(codePoint);
174
- const isNonASCIICodePoint = (codePoint: number) => codePoint >= CONTROL;
175
- const isWhiteSpace = (codePoint: number): boolean =>
176
- codePoint === LINE_FEED || codePoint === CHARACTER_TABULATION || codePoint === SPACE;
177
- const isNameStartCodePoint = (codePoint: number): boolean =>
178
- isLetter(codePoint) || isNonASCIICodePoint(codePoint) || codePoint === LOW_LINE;
179
- const isNameCodePoint = (codePoint: number): boolean =>
180
- isNameStartCodePoint(codePoint) || isDigit(codePoint) || codePoint === HYPHEN_MINUS;
181
- const isNonPrintableCodePoint = (codePoint: number): boolean => {
182
- return (
183
- (codePoint >= NULL && codePoint <= BACKSPACE) ||
184
- codePoint === LINE_TABULATION ||
185
- (codePoint >= SHIFT_OUT && codePoint <= INFORMATION_SEPARATOR_ONE) ||
186
- codePoint === DELETE
187
- );
188
- };
189
- const isValidEscape = (c1: number, c2: number): boolean => {
190
- if (c1 !== REVERSE_SOLIDUS) {
191
- return false;
192
- }
193
-
194
- return c2 !== LINE_FEED;
195
- };
196
- const isIdentifierStart = (c1: number, c2: number, c3: number): boolean => {
197
- if (c1 === HYPHEN_MINUS) {
198
- return isNameStartCodePoint(c2) || isValidEscape(c2, c3);
199
- } else if (isNameStartCodePoint(c1)) {
200
- return true;
201
- } else if (c1 === REVERSE_SOLIDUS && isValidEscape(c1, c2)) {
202
- return true;
203
- }
204
- return false;
205
- };
206
-
207
- const isNumberStart = (c1: number, c2: number, c3: number): boolean => {
208
- if (c1 === PLUS_SIGN || c1 === HYPHEN_MINUS) {
209
- if (isDigit(c2)) {
210
- return true;
211
- }
212
-
213
- return c2 === FULL_STOP && isDigit(c3);
214
- }
215
-
216
- if (c1 === FULL_STOP) {
217
- return isDigit(c2);
218
- }
219
-
220
- return isDigit(c1);
221
- };
222
-
223
- const stringToNumber = (codePoints: number[]): number => {
224
- let c = 0;
225
- let sign = 1;
226
- if (codePoints[c] === PLUS_SIGN || codePoints[c] === HYPHEN_MINUS) {
227
- if (codePoints[c] === HYPHEN_MINUS) {
228
- sign = -1;
229
- }
230
- c++;
231
- }
232
-
233
- const integers = [];
234
-
235
- while (isDigit(codePoints[c])) {
236
- integers.push(codePoints[c++]);
237
- }
238
-
239
- const int = integers.length ? parseInt(fromCodePoint(...integers), 10) : 0;
240
-
241
- if (codePoints[c] === FULL_STOP) {
242
- c++;
243
- }
244
-
245
- const fraction = [];
246
- while (isDigit(codePoints[c])) {
247
- fraction.push(codePoints[c++]);
248
- }
249
-
250
- const fracd = fraction.length;
251
- const frac = fracd ? parseInt(fromCodePoint(...fraction), 10) : 0;
252
-
253
- if (codePoints[c] === E || codePoints[c] === e) {
254
- c++;
255
- }
256
-
257
- let expsign = 1;
258
-
259
- if (codePoints[c] === PLUS_SIGN || codePoints[c] === HYPHEN_MINUS) {
260
- if (codePoints[c] === HYPHEN_MINUS) {
261
- expsign = -1;
262
- }
263
- c++;
264
- }
265
-
266
- const exponent = [];
267
-
268
- while (isDigit(codePoints[c])) {
269
- exponent.push(codePoints[c++]);
270
- }
271
-
272
- const exp = exponent.length ? parseInt(fromCodePoint(...exponent), 10) : 0;
273
-
274
- return sign * (int + frac * Math.pow(10, -fracd)) * Math.pow(10, expsign * exp);
275
- };
276
-
277
- const LEFT_PARENTHESIS_TOKEN: Token = {
278
- type: TokenType.LEFT_PARENTHESIS_TOKEN
279
- };
280
- const RIGHT_PARENTHESIS_TOKEN: Token = {
281
- type: TokenType.RIGHT_PARENTHESIS_TOKEN
282
- };
283
- const COMMA_TOKEN: Token = { type: TokenType.COMMA_TOKEN };
284
- const SUFFIX_MATCH_TOKEN: Token = { type: TokenType.SUFFIX_MATCH_TOKEN };
285
- const PREFIX_MATCH_TOKEN: Token = { type: TokenType.PREFIX_MATCH_TOKEN };
286
- const COLUMN_TOKEN: Token = { type: TokenType.COLUMN_TOKEN };
287
- const DASH_MATCH_TOKEN: Token = { type: TokenType.DASH_MATCH_TOKEN };
288
- const INCLUDE_MATCH_TOKEN: Token = { type: TokenType.INCLUDE_MATCH_TOKEN };
289
- const LEFT_CURLY_BRACKET_TOKEN: Token = {
290
- type: TokenType.LEFT_CURLY_BRACKET_TOKEN
291
- };
292
- const RIGHT_CURLY_BRACKET_TOKEN: Token = {
293
- type: TokenType.RIGHT_CURLY_BRACKET_TOKEN
294
- };
295
- const SUBSTRING_MATCH_TOKEN: Token = { type: TokenType.SUBSTRING_MATCH_TOKEN };
296
- const BAD_URL_TOKEN: Token = { type: TokenType.BAD_URL_TOKEN };
297
- const BAD_STRING_TOKEN: Token = { type: TokenType.BAD_STRING_TOKEN };
298
- const CDO_TOKEN: Token = { type: TokenType.CDO_TOKEN };
299
- const CDC_TOKEN: Token = { type: TokenType.CDC_TOKEN };
300
- const COLON_TOKEN: Token = { type: TokenType.COLON_TOKEN };
301
- const SEMICOLON_TOKEN: Token = { type: TokenType.SEMICOLON_TOKEN };
302
- const LEFT_SQUARE_BRACKET_TOKEN: Token = {
303
- type: TokenType.LEFT_SQUARE_BRACKET_TOKEN
304
- };
305
- const RIGHT_SQUARE_BRACKET_TOKEN: Token = {
306
- type: TokenType.RIGHT_SQUARE_BRACKET_TOKEN
307
- };
308
- const WHITESPACE_TOKEN: Token = { type: TokenType.WHITESPACE_TOKEN };
309
- export const EOF_TOKEN: Token = { type: TokenType.EOF_TOKEN };
310
-
311
- export class Tokenizer {
312
- private static _pool: Tokenizer[] = [];
313
- private static readonly MAX_POOL_SIZE = 40;
314
-
315
- static get(): Tokenizer {
316
- return Tokenizer._pool.pop() || new Tokenizer();
317
- }
318
-
319
- static release(tokenizer: Tokenizer): void {
320
- if (Tokenizer._pool.length < Tokenizer.MAX_POOL_SIZE) {
321
- tokenizer._reset();
322
- Tokenizer._pool.push(tokenizer);
323
- }
324
- }
325
-
326
- private _value: number[];
327
-
328
- constructor() {
329
- this._value = [];
330
- }
331
-
332
- private _reset(): void {
333
- this._value = [];
334
- }
335
-
336
- write(chunk: string): void {
337
- this._value = this._value.concat(toCodePoints(chunk));
338
- }
339
-
340
- read(): CSSToken[] {
341
- const tokens = [];
342
- let token = this.consumeToken();
343
- while (token !== EOF_TOKEN) {
344
- tokens.push(token);
345
- token = this.consumeToken();
346
- }
347
- return tokens;
348
- }
349
-
350
- private consumeToken(): CSSToken {
351
- const codePoint = this.consumeCodePoint();
352
-
353
- switch (codePoint) {
354
- case QUOTATION_MARK:
355
- return this.consumeStringToken(QUOTATION_MARK);
356
- case NUMBER_SIGN:
357
- const c1 = this.peekCodePoint(0);
358
- const c2 = this.peekCodePoint(1);
359
- const c3 = this.peekCodePoint(2);
360
- if (isNameCodePoint(c1) || isValidEscape(c2, c3)) {
361
- const flags = isIdentifierStart(c1, c2, c3) ? FLAG_ID : FLAG_UNRESTRICTED;
362
- const value = this.consumeName();
363
-
364
- return { type: TokenType.HASH_TOKEN, value, flags };
365
- }
366
- break;
367
- case DOLLAR_SIGN:
368
- if (this.peekCodePoint(0) === EQUALS_SIGN) {
369
- this.consumeCodePoint();
370
- return SUFFIX_MATCH_TOKEN;
371
- }
372
- break;
373
- case APOSTROPHE:
374
- return this.consumeStringToken(APOSTROPHE);
375
- case LEFT_PARENTHESIS:
376
- return LEFT_PARENTHESIS_TOKEN;
377
- case RIGHT_PARENTHESIS:
378
- return RIGHT_PARENTHESIS_TOKEN;
379
- case ASTERISK:
380
- if (this.peekCodePoint(0) === EQUALS_SIGN) {
381
- this.consumeCodePoint();
382
- return SUBSTRING_MATCH_TOKEN;
383
- }
384
- break;
385
- case PLUS_SIGN:
386
- if (isNumberStart(codePoint, this.peekCodePoint(0), this.peekCodePoint(1))) {
387
- this.reconsumeCodePoint(codePoint);
388
- return this.consumeNumericToken();
389
- }
390
- break;
391
- case COMMA:
392
- return COMMA_TOKEN;
393
- case HYPHEN_MINUS:
394
- const e1 = codePoint;
395
- const e2 = this.peekCodePoint(0);
396
- const e3 = this.peekCodePoint(1);
397
-
398
- if (isNumberStart(e1, e2, e3)) {
399
- this.reconsumeCodePoint(codePoint);
400
- return this.consumeNumericToken();
401
- }
402
-
403
- if (isIdentifierStart(e1, e2, e3)) {
404
- this.reconsumeCodePoint(codePoint);
405
- return this.consumeIdentLikeToken();
406
- }
407
-
408
- if (e2 === HYPHEN_MINUS && e3 === GREATER_THAN_SIGN) {
409
- this.consumeCodePoint();
410
- this.consumeCodePoint();
411
- return CDC_TOKEN;
412
- }
413
- break;
414
-
415
- case FULL_STOP:
416
- if (isNumberStart(codePoint, this.peekCodePoint(0), this.peekCodePoint(1))) {
417
- this.reconsumeCodePoint(codePoint);
418
- return this.consumeNumericToken();
419
- }
420
- break;
421
- case SOLIDUS:
422
- if (this.peekCodePoint(0) === ASTERISK) {
423
- this.consumeCodePoint();
424
- while (true) {
425
- let c = this.consumeCodePoint();
426
- if (c === ASTERISK) {
427
- c = this.consumeCodePoint();
428
- if (c === SOLIDUS) {
429
- return this.consumeToken();
430
- }
431
- }
432
- if (c === EOF) {
433
- return this.consumeToken();
434
- }
435
- }
436
- }
437
- break;
438
- case COLON:
439
- return COLON_TOKEN;
440
- case SEMICOLON:
441
- return SEMICOLON_TOKEN;
442
- case LESS_THAN_SIGN:
443
- if (
444
- this.peekCodePoint(0) === EXCLAMATION_MARK &&
445
- this.peekCodePoint(1) === HYPHEN_MINUS &&
446
- this.peekCodePoint(2) === HYPHEN_MINUS
447
- ) {
448
- this.consumeCodePoint();
449
- this.consumeCodePoint();
450
- return CDO_TOKEN;
451
- }
452
- break;
453
- case COMMERCIAL_AT:
454
- const a1 = this.peekCodePoint(0);
455
- const a2 = this.peekCodePoint(1);
456
- const a3 = this.peekCodePoint(2);
457
- if (isIdentifierStart(a1, a2, a3)) {
458
- const value = this.consumeName();
459
- return { type: TokenType.AT_KEYWORD_TOKEN, value };
460
- }
461
- break;
462
- case LEFT_SQUARE_BRACKET:
463
- return LEFT_SQUARE_BRACKET_TOKEN;
464
- case REVERSE_SOLIDUS:
465
- if (isValidEscape(codePoint, this.peekCodePoint(0))) {
466
- this.reconsumeCodePoint(codePoint);
467
- return this.consumeIdentLikeToken();
468
- }
469
- break;
470
- case RIGHT_SQUARE_BRACKET:
471
- return RIGHT_SQUARE_BRACKET_TOKEN;
472
- case CIRCUMFLEX_ACCENT:
473
- if (this.peekCodePoint(0) === EQUALS_SIGN) {
474
- this.consumeCodePoint();
475
- return PREFIX_MATCH_TOKEN;
476
- }
477
- break;
478
- case LEFT_CURLY_BRACKET:
479
- return LEFT_CURLY_BRACKET_TOKEN;
480
- case RIGHT_CURLY_BRACKET:
481
- return RIGHT_CURLY_BRACKET_TOKEN;
482
- case u:
483
- case U:
484
- const u1 = this.peekCodePoint(0);
485
- const u2 = this.peekCodePoint(1);
486
- if (u1 === PLUS_SIGN && (isHex(u2) || u2 === QUESTION_MARK)) {
487
- this.consumeCodePoint();
488
- this.consumeUnicodeRangeToken();
489
- }
490
- this.reconsumeCodePoint(codePoint);
491
- return this.consumeIdentLikeToken();
492
- case VERTICAL_LINE:
493
- if (this.peekCodePoint(0) === EQUALS_SIGN) {
494
- this.consumeCodePoint();
495
- return DASH_MATCH_TOKEN;
496
- }
497
- if (this.peekCodePoint(0) === VERTICAL_LINE) {
498
- this.consumeCodePoint();
499
- return COLUMN_TOKEN;
500
- }
501
- break;
502
- case TILDE:
503
- if (this.peekCodePoint(0) === EQUALS_SIGN) {
504
- this.consumeCodePoint();
505
- return INCLUDE_MATCH_TOKEN;
506
- }
507
- break;
508
- case EOF:
509
- return EOF_TOKEN;
510
- }
511
-
512
- if (isWhiteSpace(codePoint)) {
513
- this.consumeWhiteSpace();
514
- return WHITESPACE_TOKEN;
515
- }
516
-
517
- if (isDigit(codePoint)) {
518
- this.reconsumeCodePoint(codePoint);
519
- return this.consumeNumericToken();
520
- }
521
-
522
- if (isNameStartCodePoint(codePoint)) {
523
- this.reconsumeCodePoint(codePoint);
524
- return this.consumeIdentLikeToken();
525
- }
526
-
527
- return { type: TokenType.DELIM_TOKEN, value: fromCodePoint(codePoint) };
528
- }
529
-
530
- private consumeCodePoint(): number {
531
- const value = this._value.shift();
532
-
533
- return typeof value === 'undefined' ? -1 : value;
534
- }
535
-
536
- private reconsumeCodePoint(codePoint: number) {
537
- this._value.unshift(codePoint);
538
- }
539
-
540
- private peekCodePoint(delta: number): number {
541
- if (delta >= this._value.length) {
542
- return -1;
543
- }
544
-
545
- return this._value[delta];
546
- }
547
-
548
- private consumeUnicodeRangeToken(): UnicodeRangeToken {
549
- const digits = [];
550
- let codePoint = this.consumeCodePoint();
551
- while (isHex(codePoint) && digits.length < 6) {
552
- digits.push(codePoint);
553
- codePoint = this.consumeCodePoint();
554
- }
555
- let questionMarks = false;
556
- while (codePoint === QUESTION_MARK && digits.length < 6) {
557
- digits.push(codePoint);
558
- codePoint = this.consumeCodePoint();
559
- questionMarks = true;
560
- }
561
-
562
- if (questionMarks) {
563
- const start = parseInt(
564
- fromCodePoint(...digits.map((digit) => (digit === QUESTION_MARK ? ZERO : digit))),
565
- 16
566
- );
567
- const end = parseInt(fromCodePoint(...digits.map((digit) => (digit === QUESTION_MARK ? F : digit))), 16);
568
- return { type: TokenType.UNICODE_RANGE_TOKEN, start, end };
569
- }
570
-
571
- const start = parseInt(fromCodePoint(...digits), 16);
572
- if (this.peekCodePoint(0) === HYPHEN_MINUS && isHex(this.peekCodePoint(1))) {
573
- this.consumeCodePoint();
574
- codePoint = this.consumeCodePoint();
575
- const endDigits = [];
576
- while (isHex(codePoint) && endDigits.length < 6) {
577
- endDigits.push(codePoint);
578
- codePoint = this.consumeCodePoint();
579
- }
580
- const end = parseInt(fromCodePoint(...endDigits), 16);
581
-
582
- return { type: TokenType.UNICODE_RANGE_TOKEN, start, end };
583
- } else {
584
- return { type: TokenType.UNICODE_RANGE_TOKEN, start, end: start };
585
- }
586
- }
587
-
588
- private consumeIdentLikeToken(): StringValueToken | Token {
589
- const value = this.consumeName();
590
- if (value.toLowerCase() === 'url' && this.peekCodePoint(0) === LEFT_PARENTHESIS) {
591
- this.consumeCodePoint();
592
- return this.consumeUrlToken();
593
- } else if (this.peekCodePoint(0) === LEFT_PARENTHESIS) {
594
- this.consumeCodePoint();
595
- return { type: TokenType.FUNCTION_TOKEN, value };
596
- }
597
-
598
- return { type: TokenType.IDENT_TOKEN, value };
599
- }
600
-
601
- private consumeUrlToken(): StringValueToken | Token {
602
- const value = [];
603
- this.consumeWhiteSpace();
604
-
605
- if (this.peekCodePoint(0) === EOF) {
606
- return { type: TokenType.URL_TOKEN, value: '' };
607
- }
608
-
609
- const next = this.peekCodePoint(0);
610
- if (next === APOSTROPHE || next === QUOTATION_MARK) {
611
- const stringToken = this.consumeStringToken(this.consumeCodePoint());
612
- if (stringToken.type === TokenType.STRING_TOKEN) {
613
- this.consumeWhiteSpace();
614
-
615
- if (this.peekCodePoint(0) === EOF || this.peekCodePoint(0) === RIGHT_PARENTHESIS) {
616
- this.consumeCodePoint();
617
- return { type: TokenType.URL_TOKEN, value: stringToken.value };
618
- }
619
- }
620
-
621
- this.consumeBadUrlRemnants();
622
- return BAD_URL_TOKEN;
623
- }
624
-
625
- while (true) {
626
- const codePoint = this.consumeCodePoint();
627
- if (codePoint === EOF || codePoint === RIGHT_PARENTHESIS) {
628
- return { type: TokenType.URL_TOKEN, value: fromCodePoint(...value) };
629
- } else if (isWhiteSpace(codePoint)) {
630
- this.consumeWhiteSpace();
631
- if (this.peekCodePoint(0) === EOF || this.peekCodePoint(0) === RIGHT_PARENTHESIS) {
632
- this.consumeCodePoint();
633
- return { type: TokenType.URL_TOKEN, value: fromCodePoint(...value) };
634
- }
635
- this.consumeBadUrlRemnants();
636
- return BAD_URL_TOKEN;
637
- } else if (
638
- codePoint === QUOTATION_MARK ||
639
- codePoint === APOSTROPHE ||
640
- codePoint === LEFT_PARENTHESIS ||
641
- isNonPrintableCodePoint(codePoint)
642
- ) {
643
- this.consumeBadUrlRemnants();
644
- return BAD_URL_TOKEN;
645
- } else if (codePoint === REVERSE_SOLIDUS) {
646
- if (isValidEscape(codePoint, this.peekCodePoint(0))) {
647
- value.push(this.consumeEscapedCodePoint());
648
- } else {
649
- this.consumeBadUrlRemnants();
650
- return BAD_URL_TOKEN;
651
- }
652
- } else {
653
- value.push(codePoint);
654
- }
655
- }
656
- }
657
-
658
- private consumeWhiteSpace(): void {
659
- while (isWhiteSpace(this.peekCodePoint(0))) {
660
- this.consumeCodePoint();
661
- }
662
- }
663
-
664
- private consumeBadUrlRemnants(): void {
665
- while (true) {
666
- const codePoint = this.consumeCodePoint();
667
- if (codePoint === RIGHT_PARENTHESIS || codePoint === EOF) {
668
- return;
669
- }
670
-
671
- if (isValidEscape(codePoint, this.peekCodePoint(0))) {
672
- this.consumeEscapedCodePoint();
673
- }
674
- }
675
- }
676
-
677
- private consumeStringSlice(count: number): string {
678
- const SLICE_STACK_SIZE = 50000;
679
- let value = '';
680
- while (count > 0) {
681
- const amount = Math.min(SLICE_STACK_SIZE, count);
682
- value += fromCodePoint(...this._value.splice(0, amount));
683
- count -= amount;
684
- }
685
- this._value.shift();
686
-
687
- return value;
688
- }
689
-
690
- private consumeStringToken(endingCodePoint: number): StringValueToken | Token {
691
- let value = '';
692
- let i = 0;
693
-
694
- do {
695
- const codePoint = this._value[i];
696
- if (codePoint === EOF || codePoint === undefined || codePoint === endingCodePoint) {
697
- value += this.consumeStringSlice(i);
698
- return { type: TokenType.STRING_TOKEN, value };
699
- }
700
-
701
- if (codePoint === LINE_FEED) {
702
- this._value.splice(0, i);
703
- return BAD_STRING_TOKEN;
704
- }
705
-
706
- if (codePoint === REVERSE_SOLIDUS) {
707
- const next = this._value[i + 1];
708
- if (next !== EOF && next !== undefined) {
709
- if (next === LINE_FEED) {
710
- value += this.consumeStringSlice(i);
711
- i = -1;
712
- this._value.shift();
713
- } else if (isValidEscape(codePoint, next)) {
714
- value += this.consumeStringSlice(i);
715
- value += fromCodePoint(this.consumeEscapedCodePoint());
716
- i = -1;
717
- }
718
- }
719
- }
720
-
721
- i++;
722
- } while (true);
723
- }
724
-
725
- private consumeNumber() {
726
- const repr = [];
727
- let type = FLAG_INTEGER;
728
- let c1 = this.peekCodePoint(0);
729
- if (c1 === PLUS_SIGN || c1 === HYPHEN_MINUS) {
730
- repr.push(this.consumeCodePoint());
731
- }
732
-
733
- while (isDigit(this.peekCodePoint(0))) {
734
- repr.push(this.consumeCodePoint());
735
- }
736
- c1 = this.peekCodePoint(0);
737
- let c2 = this.peekCodePoint(1);
738
- if (c1 === FULL_STOP && isDigit(c2)) {
739
- repr.push(this.consumeCodePoint(), this.consumeCodePoint());
740
- type = FLAG_NUMBER;
741
- while (isDigit(this.peekCodePoint(0))) {
742
- repr.push(this.consumeCodePoint());
743
- }
744
- }
745
-
746
- c1 = this.peekCodePoint(0);
747
- c2 = this.peekCodePoint(1);
748
- const c3 = this.peekCodePoint(2);
749
- if ((c1 === E || c1 === e) && (((c2 === PLUS_SIGN || c2 === HYPHEN_MINUS) && isDigit(c3)) || isDigit(c2))) {
750
- repr.push(this.consumeCodePoint(), this.consumeCodePoint());
751
- type = FLAG_NUMBER;
752
- while (isDigit(this.peekCodePoint(0))) {
753
- repr.push(this.consumeCodePoint());
754
- }
755
- }
756
-
757
- return [stringToNumber(repr), type];
758
- }
759
-
760
- private consumeNumericToken(): NumberValueToken | DimensionToken {
761
- const [number, flags] = this.consumeNumber();
762
- const c1 = this.peekCodePoint(0);
763
- const c2 = this.peekCodePoint(1);
764
- const c3 = this.peekCodePoint(2);
765
-
766
- if (isIdentifierStart(c1, c2, c3)) {
767
- const unit = this.consumeName();
768
- return { type: TokenType.DIMENSION_TOKEN, number, flags, unit };
769
- }
770
-
771
- if (c1 === PERCENTAGE_SIGN) {
772
- this.consumeCodePoint();
773
- return { type: TokenType.PERCENTAGE_TOKEN, number, flags };
774
- }
775
-
776
- return { type: TokenType.NUMBER_TOKEN, number, flags };
777
- }
778
-
779
- private consumeEscapedCodePoint(): number {
780
- const codePoint = this.consumeCodePoint();
781
-
782
- if (isHex(codePoint)) {
783
- let hex = fromCodePoint(codePoint);
784
- while (isHex(this.peekCodePoint(0)) && hex.length < 6) {
785
- hex += fromCodePoint(this.consumeCodePoint());
786
- }
787
-
788
- if (isWhiteSpace(this.peekCodePoint(0))) {
789
- this.consumeCodePoint();
790
- }
791
-
792
- const hexCodePoint = parseInt(hex, 16);
793
-
794
- if (hexCodePoint === 0 || isSurrogateCodePoint(hexCodePoint) || hexCodePoint > 0x10ffff) {
795
- return REPLACEMENT_CHARACTER;
796
- }
797
-
798
- return hexCodePoint;
799
- }
800
-
801
- if (codePoint === EOF) {
802
- return REPLACEMENT_CHARACTER;
803
- }
804
-
805
- return codePoint;
806
- }
807
-
808
- private consumeName(): string {
809
- let result = '';
810
- while (true) {
811
- const codePoint = this.consumeCodePoint();
812
- if (isNameCodePoint(codePoint)) {
813
- result += fromCodePoint(codePoint);
814
- } else if (isValidEscape(codePoint, this.peekCodePoint(0))) {
815
- result += fromCodePoint(this.consumeEscapedCodePoint());
816
- } else {
817
- this.reconsumeCodePoint(codePoint);
818
- return result;
819
- }
820
- }
821
- }
822
- }