southnote-mini-sdk 1.0.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 (309) hide show
  1. package/app.js +22 -0
  2. package/app.json +53 -0
  3. package/app.wxss +15 -0
  4. package/assets/file/badwords.js +63008 -0
  5. package/assets/file/rules.js +38 -0
  6. package/assets/images/emoji/smile001.png +0 -0
  7. package/assets/images/emoji/smile002.png +0 -0
  8. package/assets/images/emoji/smile003.png +0 -0
  9. package/assets/images/emoji/smile004.png +0 -0
  10. package/assets/images/emoji/smile005.png +0 -0
  11. package/assets/images/emoji/smile006.png +0 -0
  12. package/assets/images/emoji/smile007.png +0 -0
  13. package/assets/images/emoji/smile008.png +0 -0
  14. package/assets/images/emoji/smile009.png +0 -0
  15. package/assets/images/emoji/smile010.png +0 -0
  16. package/assets/images/emoji/smile011.png +0 -0
  17. package/assets/images/emoji/smile012.png +0 -0
  18. package/assets/images/emoji/smile013.png +0 -0
  19. package/assets/images/emoji/smile014.png +0 -0
  20. package/assets/images/emoji/smile015.png +0 -0
  21. package/assets/images/emoji/smile016.png +0 -0
  22. package/assets/images/emoji/smile017.png +0 -0
  23. package/assets/images/emoji/smile018.png +0 -0
  24. package/assets/images/emoji/smile019.png +0 -0
  25. package/assets/images/emoji/smile020.png +0 -0
  26. package/assets/images/emoji/smile021.png +0 -0
  27. package/assets/images/emoji/smile022.png +0 -0
  28. package/assets/images/emoji/smile023.png +0 -0
  29. package/assets/images/emoji/smile024.png +0 -0
  30. package/assets/images/emoji/smile025.png +0 -0
  31. package/assets/images/emoji/smile026.png +0 -0
  32. package/assets/images/emoji/smile027.png +0 -0
  33. package/assets/images/emoji/smile028.png +0 -0
  34. package/assets/images/emoji/smile029.png +0 -0
  35. package/assets/images/emoji/smile030.png +0 -0
  36. package/assets/images/emoji/smile031.png +0 -0
  37. package/assets/images/emoji/smile032.png +0 -0
  38. package/assets/images/emoji/smile033.png +0 -0
  39. package/assets/images/emoji/smile034.png +0 -0
  40. package/assets/images/emoji/smile035.png +0 -0
  41. package/assets/images/emoji/smile036.png +0 -0
  42. package/assets/images/emoji/smile037.png +0 -0
  43. package/assets/images/emoji/smile038.png +0 -0
  44. package/assets/images/emoji/smile039.png +0 -0
  45. package/assets/images/emoji/smile040.png +0 -0
  46. package/assets/images/emoji/smile041.png +0 -0
  47. package/assets/images/emoji/smile042.png +0 -0
  48. package/assets/images/emoji/smile043.png +0 -0
  49. package/assets/images/emoji/smile044.png +0 -0
  50. package/assets/images/emoji/smile045.png +0 -0
  51. package/assets/images/emoji/smile046.png +0 -0
  52. package/assets/images/emoji/smile047.png +0 -0
  53. package/assets/images/emoji/smile048.png +0 -0
  54. package/assets/images/emoji/smile049.png +0 -0
  55. package/assets/images/emoji/smile050.png +0 -0
  56. package/assets/images/emoji/smile051.png +0 -0
  57. package/assets/images/emoji/smile052.png +0 -0
  58. package/assets/images/icons/age1.png +0 -0
  59. package/assets/images/icons/age2.png +0 -0
  60. package/assets/images/icons/age3.png +0 -0
  61. package/assets/images/icons/attachment.png +0 -0
  62. package/assets/images/icons/clear.png +0 -0
  63. package/assets/images/icons/edit_input.png +0 -0
  64. package/assets/images/icons/header_placeholder.png +0 -0
  65. package/assets/images/icons/home_collect.png +0 -0
  66. package/assets/images/icons/home_collected.png +0 -0
  67. package/assets/images/icons/home_comment.png +0 -0
  68. package/assets/images/icons/home_like.png +0 -0
  69. package/assets/images/icons/home_liked.png +0 -0
  70. package/assets/images/icons/home_message.png +0 -0
  71. package/assets/images/icons/home_share.png +0 -0
  72. package/assets/images/icons/icon_more.png +0 -0
  73. package/assets/images/icons/input_game.png +0 -0
  74. package/assets/images/icons/logo.png +0 -0
  75. package/assets/images/icons/lv1.png +0 -0
  76. package/assets/images/icons/lv2.png +0 -0
  77. package/assets/images/icons/lv3.png +0 -0
  78. package/assets/images/icons/lv4.png +0 -0
  79. package/assets/images/icons/search.png +0 -0
  80. package/assets/images/icons/sex1.png +0 -0
  81. package/assets/images/icons/sex2.png +0 -0
  82. package/assets/images/icons/sign_empty.png +0 -0
  83. package/assets/images/icons/sign_login.png +0 -0
  84. package/assets/wheel/wheel_bg.png +0 -0
  85. package/assets/wheel/wheel_bg2.png +0 -0
  86. package/assets/wheel/wheel_fore.png +0 -0
  87. package/assets/wheel/wheel_to.png +0 -0
  88. package/components/bottomSheet/bottomSheet.js +473 -0
  89. package/components/bottomSheet/bottomSheet.json +3 -0
  90. package/components/bottomSheet/bottomSheet.wxml +73 -0
  91. package/components/bottomSheet/bottomSheet.wxss +238 -0
  92. package/components/experience-item/experience-item.js +105 -0
  93. package/components/experience-item/experience-item.json +4 -0
  94. package/components/experience-item/experience-item.wxml +39 -0
  95. package/components/experience-item/experience-item.wxss +110 -0
  96. package/components/grid-item/grid-item.js +8 -0
  97. package/components/grid-item/grid-item.json +4 -0
  98. package/components/grid-item/grid-item.wxml +62 -0
  99. package/components/grid-item/grid-item.wxss +191 -0
  100. package/components/post-item/post-item.js +1085 -0
  101. package/components/post-item/post-item.json +4 -0
  102. package/components/post-item/post-item.wxml +427 -0
  103. package/components/post-item/post-item.wxss +525 -0
  104. package/components/wiki-renderer/wiki-renderer.js +636 -0
  105. package/components/wiki-renderer/wiki-renderer.json +12 -0
  106. package/components/wiki-renderer/wiki-renderer.wxml +150 -0
  107. package/components/wiki-renderer/wiki-renderer.wxss +412 -0
  108. package/components/wiki-tabs/wiki-tabs.js +52 -0
  109. package/components/wiki-tabs/wiki-tabs.json +3 -0
  110. package/components/wiki-tabs/wiki-tabs.wxml +28 -0
  111. package/components/wiki-tabs/wiki-tabs.wxss +43 -0
  112. package/index.js +49 -0
  113. package/package.json +35 -0
  114. package/pages/addGame/addGame.js +454 -0
  115. package/pages/addGame/addGame.json +3 -0
  116. package/pages/addGame/addGame.wxml +71 -0
  117. package/pages/addGame/addGame.wxss +110 -0
  118. package/pages/addSubject/addSubject.js +199 -0
  119. package/pages/addSubject/addSubject.json +4 -0
  120. package/pages/addSubject/addSubject.wxml +78 -0
  121. package/pages/addSubject/addSubject.wxss +85 -0
  122. package/pages/commonLogin/commonLogin.js +269 -0
  123. package/pages/commonLogin/commonLogin.json +4 -0
  124. package/pages/commonLogin/commonLogin.wxml +57 -0
  125. package/pages/commonLogin/commonLogin.wxss +177 -0
  126. package/pages/copyOfficial/copyOfficial.js +25 -0
  127. package/pages/copyOfficial/copyOfficial.json +3 -0
  128. package/pages/copyOfficial/copyOfficial.wxml +22 -0
  129. package/pages/copyOfficial/copyOfficial.wxss +49 -0
  130. package/pages/demo/demo.js +23 -0
  131. package/pages/demo/demo.json +3 -0
  132. package/pages/demo/demo.wxml +8 -0
  133. package/pages/demo/demo.wxss +24 -0
  134. package/pages/game/game.js +1254 -0
  135. package/pages/game/game.json +8 -0
  136. package/pages/game/game.wxml +371 -0
  137. package/pages/game/game.wxss +672 -0
  138. package/pages/home/home.js +665 -0
  139. package/pages/home/home.json +10 -0
  140. package/pages/home/home.wxml +115 -0
  141. package/pages/home/home.wxss +231 -0
  142. package/pages/lottery-winners/lottery-winners.js +60 -0
  143. package/pages/lottery-winners/lottery-winners.json +4 -0
  144. package/pages/lottery-winners/lottery-winners.wxml +53 -0
  145. package/pages/lottery-winners/lottery-winners.wxss +127 -0
  146. package/pages/message/messageCommentsAndAt/messageCommentsAndAt.js +178 -0
  147. package/pages/message/messageCommentsAndAt/messageCommentsAndAt.json +5 -0
  148. package/pages/message/messageCommentsAndAt/messageCommentsAndAt.wxml +93 -0
  149. package/pages/message/messageCommentsAndAt/messageCommentsAndAt.wxss +177 -0
  150. package/pages/message/messageEntire/messageEntire.js +112 -0
  151. package/pages/message/messageEntire/messageEntire.json +4 -0
  152. package/pages/message/messageEntire/messageEntire.wxml +44 -0
  153. package/pages/message/messageEntire/messageEntire.wxss +88 -0
  154. package/pages/message/messageLikeAndCollect/messageLikeAndCollect.js +147 -0
  155. package/pages/message/messageLikeAndCollect/messageLikeAndCollect.json +5 -0
  156. package/pages/message/messageLikeAndCollect/messageLikeAndCollect.wxml +84 -0
  157. package/pages/message/messageLikeAndCollect/messageLikeAndCollect.wxss +166 -0
  158. package/pages/message/messageNewFans/messageNewFans.js +139 -0
  159. package/pages/message/messageNewFans/messageNewFans.json +5 -0
  160. package/pages/message/messageNewFans/messageNewFans.wxml +35 -0
  161. package/pages/message/messageNewFans/messageNewFans.wxss +85 -0
  162. package/pages/officialWebview/officialWebview.js +13 -0
  163. package/pages/officialWebview/officialWebview.json +3 -0
  164. package/pages/officialWebview/officialWebview.wxml +2 -0
  165. package/pages/officialWebview/officialWebview.wxss +1 -0
  166. package/pages/post/post.js +1856 -0
  167. package/pages/post/post.json +6 -0
  168. package/pages/post/post.wxml +694 -0
  169. package/pages/post/post.wxss +1003 -0
  170. package/pages/post-editor/post-editor.js +465 -0
  171. package/pages/post-editor/post-editor.json +4 -0
  172. package/pages/post-editor/post-editor.wxml +63 -0
  173. package/pages/post-editor/post-editor.wxss +195 -0
  174. package/pages/postDialog/postDialog.js +560 -0
  175. package/pages/postDialog/postDialog.json +6 -0
  176. package/pages/postDialog/postDialog.wxml +377 -0
  177. package/pages/postDialog/postDialog.wxss +979 -0
  178. package/pages/report-category/report-category.js +29 -0
  179. package/pages/report-category/report-category.json +4 -0
  180. package/pages/report-category/report-category.wxml +14 -0
  181. package/pages/report-category/report-category.wxss +43 -0
  182. package/pages/report-form/report-form.js +65 -0
  183. package/pages/report-form/report-form.json +3 -0
  184. package/pages/report-form/report-form.wxml +11 -0
  185. package/pages/report-form/report-form.wxss +44 -0
  186. package/pages/sevenDaySignDetail/sevenDaySignDetail.js +273 -0
  187. package/pages/sevenDaySignDetail/sevenDaySignDetail.json +3 -0
  188. package/pages/sevenDaySignDetail/sevenDaySignDetail.wxml +82 -0
  189. package/pages/sevenDaySignDetail/sevenDaySignDetail.wxss +173 -0
  190. package/pages/topic/topic.js +266 -0
  191. package/pages/topic/topic.json +6 -0
  192. package/pages/topic/topic.wxml +77 -0
  193. package/pages/topic/topic.wxss +162 -0
  194. package/pages/user/user.js +939 -0
  195. package/pages/user/user.json +5 -0
  196. package/pages/user/user.wxml +179 -0
  197. package/pages/user/user.wxss +340 -0
  198. package/pages/userDatum/userDatum.js +24 -0
  199. package/pages/userDatum/userDatum.json +4 -0
  200. package/pages/userDatum/userDatum.wxml +36 -0
  201. package/pages/userDatum/userDatum.wxss +41 -0
  202. package/pages/userGameLib/userGameLib.js +105 -0
  203. package/pages/userGameLib/userGameLib.json +4 -0
  204. package/pages/userGameLib/userGameLib.wxml +42 -0
  205. package/pages/userGameLib/userGameLib.wxss +119 -0
  206. package/pages/webview/webview.js +25 -0
  207. package/pages/webview/webview.json +3 -0
  208. package/pages/webview/webview.wxml +22 -0
  209. package/pages/webview/webview.wxss +50 -0
  210. package/pages/wheelActivivty/wheelActivivty.js +492 -0
  211. package/pages/wheelActivivty/wheelActivivty.json +8 -0
  212. package/pages/wheelActivivty/wheelActivivty.wxml +131 -0
  213. package/pages/wheelActivivty/wheelActivivty.wxss +459 -0
  214. package/pages/wiki/wiki.js +138 -0
  215. package/pages/wiki/wiki.json +6 -0
  216. package/pages/wiki/wiki.wxml +20 -0
  217. package/pages/wiki/wiki.wxss +44 -0
  218. package/request/JKRequest.js +177 -0
  219. package/services/home.js +603 -0
  220. package/towxml/config.js +291 -0
  221. package/towxml/decode.js +35 -0
  222. package/towxml/decode.json +11 -0
  223. package/towxml/decode.wxml +137 -0
  224. package/towxml/decode.wxss +0 -0
  225. package/towxml/img/img.js +98 -0
  226. package/towxml/img/img.json +3 -0
  227. package/towxml/img/img.wxml +1 -0
  228. package/towxml/img/img.wxss +0 -0
  229. package/towxml/index.js +19 -0
  230. package/towxml/latex/latex.js +53 -0
  231. package/towxml/latex/latex.json +5 -0
  232. package/towxml/latex/latex.wxml +1 -0
  233. package/towxml/latex/latex.wxss +0 -0
  234. package/towxml/parse/highlight/highlight.js +1 -0
  235. package/towxml/parse/highlight/index.js +8 -0
  236. package/towxml/parse/highlight/languages/bash.js +111 -0
  237. package/towxml/parse/highlight/languages/c-like.js +236 -0
  238. package/towxml/parse/highlight/languages/c.js +22 -0
  239. package/towxml/parse/highlight/languages/css.js +132 -0
  240. package/towxml/parse/highlight/languages/dart.js +134 -0
  241. package/towxml/parse/highlight/languages/go.js +63 -0
  242. package/towxml/parse/highlight/languages/htmlbars.js +80 -0
  243. package/towxml/parse/highlight/languages/java.js +125 -0
  244. package/towxml/parse/highlight/languages/javascript.js +265 -0
  245. package/towxml/parse/highlight/languages/json.js +52 -0
  246. package/towxml/parse/highlight/languages/less.js +148 -0
  247. package/towxml/parse/highlight/languages/nginx.js +101 -0
  248. package/towxml/parse/highlight/languages/php.js +161 -0
  249. package/towxml/parse/highlight/languages/python-repl.js +29 -0
  250. package/towxml/parse/highlight/languages/python.js +131 -0
  251. package/towxml/parse/highlight/languages/scss.js +122 -0
  252. package/towxml/parse/highlight/languages/shell.js +22 -0
  253. package/towxml/parse/highlight/languages/typescript.js +215 -0
  254. package/towxml/parse/highlight/languages/xml.js +139 -0
  255. package/towxml/parse/highlight/style/github.wxss +99 -0
  256. package/towxml/parse/highlight/style/monokai.wxss +70 -0
  257. package/towxml/parse/index.js +118 -0
  258. package/towxml/parse/markdown/index.js +67 -0
  259. package/towxml/parse/markdown/markdown.js +4 -0
  260. package/towxml/parse/markdown/plugins/echarts.js +11 -0
  261. package/towxml/parse/markdown/plugins/emoji.js +2 -0
  262. package/towxml/parse/markdown/plugins/ins.js +1 -0
  263. package/towxml/parse/markdown/plugins/latex.js +158 -0
  264. package/towxml/parse/markdown/plugins/mark.js +1 -0
  265. package/towxml/parse/markdown/plugins/sub.js +1 -0
  266. package/towxml/parse/markdown/plugins/sup.js +1 -0
  267. package/towxml/parse/markdown/plugins/todo.js +147 -0
  268. package/towxml/parse/markdown/plugins/yuml.js +20 -0
  269. package/towxml/parse/parse2/Parser.js +492 -0
  270. package/towxml/parse/parse2/Tokenizer.js +903 -0
  271. package/towxml/parse/parse2/domelementtype/index.js +55 -0
  272. package/towxml/parse/parse2/domhandler/index.js +145 -0
  273. package/towxml/parse/parse2/domhandler/node.js +474 -0
  274. package/towxml/parse/parse2/entities/decode.js +179 -0
  275. package/towxml/parse/parse2/entities/decode_codepoint.js +60 -0
  276. package/towxml/parse/parse2/entities/encode.js +77 -0
  277. package/towxml/parse/parse2/entities/escape.js +112 -0
  278. package/towxml/parse/parse2/entities/generated/decode-data-html.js +9 -0
  279. package/towxml/parse/parse2/entities/generated/decode-data-xml.js +9 -0
  280. package/towxml/parse/parse2/entities/generated/encode-html.js +12 -0
  281. package/towxml/parse/parse2/entities/index.js +137 -0
  282. package/towxml/parse/parse2/index.js +8 -0
  283. package/towxml/style/main.wxss +419 -0
  284. package/towxml/style/theme/dark.wxss +73 -0
  285. package/towxml/style/theme/light.wxss +63 -0
  286. package/towxml/table/table.js +11 -0
  287. package/towxml/table/table.json +6 -0
  288. package/towxml/table/table.wxml +24 -0
  289. package/towxml/table/table.wxss +0 -0
  290. package/towxml/todogroup/todogroup.js +20 -0
  291. package/towxml/todogroup/todogroup.json +6 -0
  292. package/towxml/todogroup/todogroup.wxml +12 -0
  293. package/towxml/todogroup/todogroup.wxss +3 -0
  294. package/towxml/towxml.js +22 -0
  295. package/towxml/towxml.json +6 -0
  296. package/towxml/towxml.wxml +5 -0
  297. package/towxml/towxml.wxss +8 -0
  298. package/towxml/yuml/yuml.js +51 -0
  299. package/towxml/yuml/yuml.json +5 -0
  300. package/towxml/yuml/yuml.wxml +5 -0
  301. package/towxml/yuml/yuml.wxss +0 -0
  302. package/utils/auth.js +17 -0
  303. package/utils/base64.js +67 -0
  304. package/utils/compressImage.js +41 -0
  305. package/utils/exp.js +49 -0
  306. package/utils/formatPost.js +18 -0
  307. package/utils/parseContent.js +191 -0
  308. package/utils/query-select.js +9 -0
  309. package/utils/sensitive.js +82 -0
@@ -0,0 +1,903 @@
1
+ var decode_js_1 = require("./entities/decode.js");
2
+ var CharCodes;
3
+ (function (CharCodes) {
4
+ CharCodes[CharCodes["Tab"] = 9] = "Tab";
5
+ CharCodes[CharCodes["NewLine"] = 10] = "NewLine";
6
+ CharCodes[CharCodes["FormFeed"] = 12] = "FormFeed";
7
+ CharCodes[CharCodes["CarriageReturn"] = 13] = "CarriageReturn";
8
+ CharCodes[CharCodes["Space"] = 32] = "Space";
9
+ CharCodes[CharCodes["ExclamationMark"] = 33] = "ExclamationMark";
10
+ CharCodes[CharCodes["Num"] = 35] = "Num";
11
+ CharCodes[CharCodes["Amp"] = 38] = "Amp";
12
+ CharCodes[CharCodes["SingleQuote"] = 39] = "SingleQuote";
13
+ CharCodes[CharCodes["DoubleQuote"] = 34] = "DoubleQuote";
14
+ CharCodes[CharCodes["Dash"] = 45] = "Dash";
15
+ CharCodes[CharCodes["Slash"] = 47] = "Slash";
16
+ CharCodes[CharCodes["Zero"] = 48] = "Zero";
17
+ CharCodes[CharCodes["Nine"] = 57] = "Nine";
18
+ CharCodes[CharCodes["Semi"] = 59] = "Semi";
19
+ CharCodes[CharCodes["Lt"] = 60] = "Lt";
20
+ CharCodes[CharCodes["Eq"] = 61] = "Eq";
21
+ CharCodes[CharCodes["Gt"] = 62] = "Gt";
22
+ CharCodes[CharCodes["Questionmark"] = 63] = "Questionmark";
23
+ CharCodes[CharCodes["UpperA"] = 65] = "UpperA";
24
+ CharCodes[CharCodes["LowerA"] = 97] = "LowerA";
25
+ CharCodes[CharCodes["UpperF"] = 70] = "UpperF";
26
+ CharCodes[CharCodes["LowerF"] = 102] = "LowerF";
27
+ CharCodes[CharCodes["UpperZ"] = 90] = "UpperZ";
28
+ CharCodes[CharCodes["LowerZ"] = 122] = "LowerZ";
29
+ CharCodes[CharCodes["LowerX"] = 120] = "LowerX";
30
+ CharCodes[CharCodes["OpeningSquareBracket"] = 91] = "OpeningSquareBracket";
31
+ })(CharCodes || (CharCodes = {}));
32
+ /** All the states the tokenizer can be in. */
33
+ var State;
34
+ (function (State) {
35
+ State[State["Text"] = 1] = "Text";
36
+ State[State["BeforeTagName"] = 2] = "BeforeTagName";
37
+ State[State["InTagName"] = 3] = "InTagName";
38
+ State[State["InSelfClosingTag"] = 4] = "InSelfClosingTag";
39
+ State[State["BeforeClosingTagName"] = 5] = "BeforeClosingTagName";
40
+ State[State["InClosingTagName"] = 6] = "InClosingTagName";
41
+ State[State["AfterClosingTagName"] = 7] = "AfterClosingTagName";
42
+ // Attributes
43
+ State[State["BeforeAttributeName"] = 8] = "BeforeAttributeName";
44
+ State[State["InAttributeName"] = 9] = "InAttributeName";
45
+ State[State["AfterAttributeName"] = 10] = "AfterAttributeName";
46
+ State[State["BeforeAttributeValue"] = 11] = "BeforeAttributeValue";
47
+ State[State["InAttributeValueDq"] = 12] = "InAttributeValueDq";
48
+ State[State["InAttributeValueSq"] = 13] = "InAttributeValueSq";
49
+ State[State["InAttributeValueNq"] = 14] = "InAttributeValueNq";
50
+ // Declarations
51
+ State[State["BeforeDeclaration"] = 15] = "BeforeDeclaration";
52
+ State[State["InDeclaration"] = 16] = "InDeclaration";
53
+ // Processing instructions
54
+ State[State["InProcessingInstruction"] = 17] = "InProcessingInstruction";
55
+ // Comments & CDATA
56
+ State[State["BeforeComment"] = 18] = "BeforeComment";
57
+ State[State["CDATASequence"] = 19] = "CDATASequence";
58
+ State[State["InSpecialComment"] = 20] = "InSpecialComment";
59
+ State[State["InCommentLike"] = 21] = "InCommentLike";
60
+ // Special tags
61
+ State[State["BeforeSpecialS"] = 22] = "BeforeSpecialS";
62
+ State[State["SpecialStartSequence"] = 23] = "SpecialStartSequence";
63
+ State[State["InSpecialTag"] = 24] = "InSpecialTag";
64
+ State[State["BeforeEntity"] = 25] = "BeforeEntity";
65
+ State[State["BeforeNumericEntity"] = 26] = "BeforeNumericEntity";
66
+ State[State["InNamedEntity"] = 27] = "InNamedEntity";
67
+ State[State["InNumericEntity"] = 28] = "InNumericEntity";
68
+ State[State["InHexEntity"] = 29] = "InHexEntity";
69
+ })(State || (State = {}));
70
+ function isWhitespace(c) {
71
+ return (c === CharCodes.Space ||
72
+ c === CharCodes.NewLine ||
73
+ c === CharCodes.Tab ||
74
+ c === CharCodes.FormFeed ||
75
+ c === CharCodes.CarriageReturn);
76
+ }
77
+ function isEndOfTagSection(c) {
78
+ return c === CharCodes.Slash || c === CharCodes.Gt || isWhitespace(c);
79
+ }
80
+ function isNumber(c) {
81
+ return c >= CharCodes.Zero && c <= CharCodes.Nine;
82
+ }
83
+ function isASCIIAlpha(c) {
84
+ return ((c >= CharCodes.LowerA && c <= CharCodes.LowerZ) ||
85
+ (c >= CharCodes.UpperA && c <= CharCodes.UpperZ));
86
+ }
87
+ function isHexDigit(c) {
88
+ return ((c >= CharCodes.UpperA && c <= CharCodes.UpperF) ||
89
+ (c >= CharCodes.LowerA && c <= CharCodes.LowerF));
90
+ }
91
+ var QuoteType;
92
+ (function (QuoteType) {
93
+ QuoteType[QuoteType["NoValue"] = 0] = "NoValue";
94
+ QuoteType[QuoteType["Unquoted"] = 1] = "Unquoted";
95
+ QuoteType[QuoteType["Single"] = 2] = "Single";
96
+ QuoteType[QuoteType["Double"] = 3] = "Double";
97
+ })(QuoteType = exports.QuoteType || (exports.QuoteType = {}));
98
+ /**
99
+ * Sequences used to match longer strings.
100
+ *
101
+ * We don't have `Script`, `Style`, or `Title` here. Instead, we re-use the *End
102
+ * sequences with an increased offset.
103
+ */
104
+ var Sequences = {
105
+ Cdata: new Uint8Array([0x43, 0x44, 0x41, 0x54, 0x41, 0x5b]),
106
+ CdataEnd: new Uint8Array([0x5d, 0x5d, 0x3e]),
107
+ CommentEnd: new Uint8Array([0x2d, 0x2d, 0x3e]),
108
+ ScriptEnd: new Uint8Array([0x3c, 0x2f, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74]),
109
+ StyleEnd: new Uint8Array([0x3c, 0x2f, 0x73, 0x74, 0x79, 0x6c, 0x65]),
110
+ TitleEnd: new Uint8Array([0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65]), // `</title`
111
+ };
112
+ var Tokenizer = /** @class */ (function () {
113
+ function Tokenizer(_a, cbs) {
114
+ var _b = _a.xmlMode, xmlMode = _b === void 0 ? false : _b, _c = _a.decodeEntities, decodeEntities = _c === void 0 ? true : _c;
115
+ this.cbs = cbs;
116
+ /** The current state the tokenizer is in. */
117
+ this.state = State.Text;
118
+ /** The read buffer. */
119
+ this.buffer = "";
120
+ /** The beginning of the section that is currently being read. */
121
+ this.sectionStart = 0;
122
+ /** The index within the buffer that we are currently looking at. */
123
+ this.index = 0;
124
+ /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
125
+ this.baseState = State.Text;
126
+ /** For special parsing behavior inside of script and style tags. */
127
+ this.isSpecial = false;
128
+ /** Indicates whether the tokenizer has been paused. */
129
+ this.running = true;
130
+ /** The offset of the current buffer. */
131
+ this.offset = 0;
132
+ this.sequenceIndex = 0;
133
+ this.trieIndex = 0;
134
+ this.trieCurrent = 0;
135
+ /** For named entities, the index of the value. For numeric entities, the code point. */
136
+ this.entityResult = 0;
137
+ this.entityExcess = 0;
138
+ this.xmlMode = xmlMode;
139
+ this.decodeEntities = decodeEntities;
140
+ this.entityTrie = xmlMode ? decode_js_1.xmlDecodeTree : decode_js_1.htmlDecodeTree;
141
+ }
142
+ Tokenizer.prototype.reset = function () {
143
+ this.state = State.Text;
144
+ this.buffer = "";
145
+ this.sectionStart = 0;
146
+ this.index = 0;
147
+ this.baseState = State.Text;
148
+ this.currentSequence = undefined;
149
+ this.running = true;
150
+ this.offset = 0;
151
+ };
152
+ Tokenizer.prototype.write = function (chunk) {
153
+ this.offset += this.buffer.length;
154
+ this.buffer = chunk;
155
+ this.parse();
156
+ };
157
+ Tokenizer.prototype.end = function () {
158
+ if (this.running)
159
+ this.finish();
160
+ };
161
+ Tokenizer.prototype.pause = function () {
162
+ this.running = false;
163
+ };
164
+ Tokenizer.prototype.resume = function () {
165
+ this.running = true;
166
+ if (this.index < this.buffer.length + this.offset) {
167
+ this.parse();
168
+ }
169
+ };
170
+ /**
171
+ * The current index within all of the written data.
172
+ */
173
+ Tokenizer.prototype.getIndex = function () {
174
+ return this.index;
175
+ };
176
+ /**
177
+ * The start of the current section.
178
+ */
179
+ Tokenizer.prototype.getSectionStart = function () {
180
+ return this.sectionStart;
181
+ };
182
+ Tokenizer.prototype.stateText = function (c) {
183
+ if (c === CharCodes.Lt ||
184
+ (!this.decodeEntities && this.fastForwardTo(CharCodes.Lt))) {
185
+ if (this.index > this.sectionStart) {
186
+ this.cbs.ontext(this.sectionStart, this.index);
187
+ }
188
+ this.state = State.BeforeTagName;
189
+ this.sectionStart = this.index;
190
+ }
191
+ else if (this.decodeEntities && c === CharCodes.Amp) {
192
+ this.state = State.BeforeEntity;
193
+ }
194
+ };
195
+ Tokenizer.prototype.stateSpecialStartSequence = function (c) {
196
+ var isEnd = this.sequenceIndex === this.currentSequence.length;
197
+ var isMatch = isEnd
198
+ ? // If we are at the end of the sequence, make sure the tag name has ended
199
+ isEndOfTagSection(c)
200
+ : // Otherwise, do a case-insensitive comparison
201
+ (c | 0x20) === this.currentSequence[this.sequenceIndex];
202
+ if (!isMatch) {
203
+ this.isSpecial = false;
204
+ }
205
+ else if (!isEnd) {
206
+ this.sequenceIndex++;
207
+ return;
208
+ }
209
+ this.sequenceIndex = 0;
210
+ this.state = State.InTagName;
211
+ this.stateInTagName(c);
212
+ };
213
+ /** Look for an end tag. For <title> tags, also decode entities. */
214
+ Tokenizer.prototype.stateInSpecialTag = function (c) {
215
+ if (this.sequenceIndex === this.currentSequence.length) {
216
+ if (c === CharCodes.Gt || isWhitespace(c)) {
217
+ var endOfText = this.index - this.currentSequence.length;
218
+ if (this.sectionStart < endOfText) {
219
+ // Spoof the index so that reported locations match up.
220
+ var actualIndex = this.index;
221
+ this.index = endOfText;
222
+ this.cbs.ontext(this.sectionStart, endOfText);
223
+ this.index = actualIndex;
224
+ }
225
+ this.isSpecial = false;
226
+ this.sectionStart = endOfText + 2; // Skip over the `</`
227
+ this.stateInClosingTagName(c);
228
+ return; // We are done; skip the rest of the function.
229
+ }
230
+ this.sequenceIndex = 0;
231
+ }
232
+ if ((c | 0x20) === this.currentSequence[this.sequenceIndex]) {
233
+ this.sequenceIndex += 1;
234
+ }
235
+ else if (this.sequenceIndex === 0) {
236
+ if (this.currentSequence === Sequences.TitleEnd) {
237
+ // We have to parse entities in <title> tags.
238
+ if (this.decodeEntities && c === CharCodes.Amp) {
239
+ this.state = State.BeforeEntity;
240
+ }
241
+ }
242
+ else if (this.fastForwardTo(CharCodes.Lt)) {
243
+ // Outside of <title> tags, we can fast-forward.
244
+ this.sequenceIndex = 1;
245
+ }
246
+ }
247
+ else {
248
+ // If we see a `<`, set the sequence index to 1; useful for eg. `<</script>`.
249
+ this.sequenceIndex = Number(c === CharCodes.Lt);
250
+ }
251
+ };
252
+ Tokenizer.prototype.stateCDATASequence = function (c) {
253
+ if (c === Sequences.Cdata[this.sequenceIndex]) {
254
+ if (++this.sequenceIndex === Sequences.Cdata.length) {
255
+ this.state = State.InCommentLike;
256
+ this.currentSequence = Sequences.CdataEnd;
257
+ this.sequenceIndex = 0;
258
+ this.sectionStart = this.index + 1;
259
+ }
260
+ }
261
+ else {
262
+ this.sequenceIndex = 0;
263
+ this.state = State.InDeclaration;
264
+ this.stateInDeclaration(c); // Reconsume the character
265
+ }
266
+ };
267
+ /**
268
+ * When we wait for one specific character, we can speed things up
269
+ * by skipping through the buffer until we find it.
270
+ *
271
+ * @returns Whether the character was found.
272
+ */
273
+ Tokenizer.prototype.fastForwardTo = function (c) {
274
+ while (++this.index < this.buffer.length + this.offset) {
275
+ if (this.buffer.charCodeAt(this.index - this.offset) === c) {
276
+ return true;
277
+ }
278
+ }
279
+ /*
280
+ * We increment the index at the end of the `parse` loop,
281
+ * so set it to `buffer.length - 1` here.
282
+ *
283
+ * TODO: Refactor `parse` to increment index before calling states.
284
+ */
285
+ this.index = this.buffer.length + this.offset - 1;
286
+ return false;
287
+ };
288
+ /**
289
+ * Comments and CDATA end with `-->` and `]]>`.
290
+ *
291
+ * Their common qualities are:
292
+ * - Their end sequences have a distinct character they start with.
293
+ * - That character is then repeated, so we have to check multiple repeats.
294
+ * - All characters but the start character of the sequence can be skipped.
295
+ */
296
+ Tokenizer.prototype.stateInCommentLike = function (c) {
297
+ if (c === this.currentSequence[this.sequenceIndex]) {
298
+ if (++this.sequenceIndex === this.currentSequence.length) {
299
+ if (this.currentSequence === Sequences.CdataEnd) {
300
+ this.cbs.oncdata(this.sectionStart, this.index, 2);
301
+ }
302
+ else {
303
+ this.cbs.oncomment(this.sectionStart, this.index, 2);
304
+ }
305
+ this.sequenceIndex = 0;
306
+ this.sectionStart = this.index + 1;
307
+ this.state = State.Text;
308
+ }
309
+ }
310
+ else if (this.sequenceIndex === 0) {
311
+ // Fast-forward to the first character of the sequence
312
+ if (this.fastForwardTo(this.currentSequence[0])) {
313
+ this.sequenceIndex = 1;
314
+ }
315
+ }
316
+ else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
317
+ // Allow long sequences, eg. --->, ]]]>
318
+ this.sequenceIndex = 0;
319
+ }
320
+ };
321
+ /**
322
+ * HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a tag name.
323
+ *
324
+ * XML allows a lot more characters here (@see https://www.w3.org/TR/REC-xml/#NT-NameStartChar).
325
+ * We allow anything that wouldn't end the tag.
326
+ */
327
+ Tokenizer.prototype.isTagStartChar = function (c) {
328
+ return this.xmlMode ? !isEndOfTagSection(c) : isASCIIAlpha(c);
329
+ };
330
+ Tokenizer.prototype.startSpecial = function (sequence, offset) {
331
+ this.isSpecial = true;
332
+ this.currentSequence = sequence;
333
+ this.sequenceIndex = offset;
334
+ this.state = State.SpecialStartSequence;
335
+ };
336
+ Tokenizer.prototype.stateBeforeTagName = function (c) {
337
+ if (c === CharCodes.ExclamationMark) {
338
+ this.state = State.BeforeDeclaration;
339
+ this.sectionStart = this.index + 1;
340
+ }
341
+ else if (c === CharCodes.Questionmark) {
342
+ this.state = State.InProcessingInstruction;
343
+ this.sectionStart = this.index + 1;
344
+ }
345
+ else if (this.isTagStartChar(c)) {
346
+ var lower = c | 0x20;
347
+ this.sectionStart = this.index;
348
+ if (!this.xmlMode && lower === Sequences.TitleEnd[2]) {
349
+ this.startSpecial(Sequences.TitleEnd, 3);
350
+ }
351
+ else {
352
+ this.state =
353
+ !this.xmlMode && lower === Sequences.ScriptEnd[2]
354
+ ? State.BeforeSpecialS
355
+ : State.InTagName;
356
+ }
357
+ }
358
+ else if (c === CharCodes.Slash) {
359
+ this.state = State.BeforeClosingTagName;
360
+ }
361
+ else {
362
+ this.state = State.Text;
363
+ this.stateText(c);
364
+ }
365
+ };
366
+ Tokenizer.prototype.stateInTagName = function (c) {
367
+ if (isEndOfTagSection(c)) {
368
+ this.cbs.onopentagname(this.sectionStart, this.index);
369
+ this.sectionStart = -1;
370
+ this.state = State.BeforeAttributeName;
371
+ this.stateBeforeAttributeName(c);
372
+ }
373
+ };
374
+ Tokenizer.prototype.stateBeforeClosingTagName = function (c) {
375
+ if (isWhitespace(c)) {
376
+ // Ignore
377
+ }
378
+ else if (c === CharCodes.Gt) {
379
+ this.state = State.Text;
380
+ }
381
+ else {
382
+ this.state = this.isTagStartChar(c)
383
+ ? State.InClosingTagName
384
+ : State.InSpecialComment;
385
+ this.sectionStart = this.index;
386
+ }
387
+ };
388
+ Tokenizer.prototype.stateInClosingTagName = function (c) {
389
+ if (c === CharCodes.Gt || isWhitespace(c)) {
390
+ this.cbs.onclosetag(this.sectionStart, this.index);
391
+ this.sectionStart = -1;
392
+ this.state = State.AfterClosingTagName;
393
+ this.stateAfterClosingTagName(c);
394
+ }
395
+ };
396
+ Tokenizer.prototype.stateAfterClosingTagName = function (c) {
397
+ // Skip everything until ">"
398
+ if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) {
399
+ this.state = State.Text;
400
+ this.sectionStart = this.index + 1;
401
+ }
402
+ };
403
+ Tokenizer.prototype.stateBeforeAttributeName = function (c) {
404
+ if (c === CharCodes.Gt) {
405
+ this.cbs.onopentagend(this.index);
406
+ if (this.isSpecial) {
407
+ this.state = State.InSpecialTag;
408
+ this.sequenceIndex = 0;
409
+ }
410
+ else {
411
+ this.state = State.Text;
412
+ }
413
+ this.baseState = this.state;
414
+ this.sectionStart = this.index + 1;
415
+ }
416
+ else if (c === CharCodes.Slash) {
417
+ this.state = State.InSelfClosingTag;
418
+ }
419
+ else if (!isWhitespace(c)) {
420
+ this.state = State.InAttributeName;
421
+ this.sectionStart = this.index;
422
+ }
423
+ };
424
+ Tokenizer.prototype.stateInSelfClosingTag = function (c) {
425
+ if (c === CharCodes.Gt) {
426
+ this.cbs.onselfclosingtag(this.index);
427
+ this.state = State.Text;
428
+ this.baseState = State.Text;
429
+ this.sectionStart = this.index + 1;
430
+ this.isSpecial = false; // Reset special state, in case of self-closing special tags
431
+ }
432
+ else if (!isWhitespace(c)) {
433
+ this.state = State.BeforeAttributeName;
434
+ this.stateBeforeAttributeName(c);
435
+ }
436
+ };
437
+ Tokenizer.prototype.stateInAttributeName = function (c) {
438
+ if (c === CharCodes.Eq || isEndOfTagSection(c)) {
439
+ this.cbs.onattribname(this.sectionStart, this.index);
440
+ this.sectionStart = -1;
441
+ this.state = State.AfterAttributeName;
442
+ this.stateAfterAttributeName(c);
443
+ }
444
+ };
445
+ Tokenizer.prototype.stateAfterAttributeName = function (c) {
446
+ if (c === CharCodes.Eq) {
447
+ this.state = State.BeforeAttributeValue;
448
+ }
449
+ else if (c === CharCodes.Slash || c === CharCodes.Gt) {
450
+ this.cbs.onattribend(QuoteType.NoValue, this.index);
451
+ this.state = State.BeforeAttributeName;
452
+ this.stateBeforeAttributeName(c);
453
+ }
454
+ else if (!isWhitespace(c)) {
455
+ this.cbs.onattribend(QuoteType.NoValue, this.index);
456
+ this.state = State.InAttributeName;
457
+ this.sectionStart = this.index;
458
+ }
459
+ };
460
+ Tokenizer.prototype.stateBeforeAttributeValue = function (c) {
461
+ if (c === CharCodes.DoubleQuote) {
462
+ this.state = State.InAttributeValueDq;
463
+ this.sectionStart = this.index + 1;
464
+ }
465
+ else if (c === CharCodes.SingleQuote) {
466
+ this.state = State.InAttributeValueSq;
467
+ this.sectionStart = this.index + 1;
468
+ }
469
+ else if (!isWhitespace(c)) {
470
+ this.sectionStart = this.index;
471
+ this.state = State.InAttributeValueNq;
472
+ this.stateInAttributeValueNoQuotes(c); // Reconsume token
473
+ }
474
+ };
475
+ Tokenizer.prototype.handleInAttributeValue = function (c, quote) {
476
+ if (c === quote ||
477
+ (!this.decodeEntities && this.fastForwardTo(quote))) {
478
+ this.cbs.onattribdata(this.sectionStart, this.index);
479
+ this.sectionStart = -1;
480
+ this.cbs.onattribend(quote === CharCodes.DoubleQuote
481
+ ? QuoteType.Double
482
+ : QuoteType.Single, this.index);
483
+ this.state = State.BeforeAttributeName;
484
+ }
485
+ else if (this.decodeEntities && c === CharCodes.Amp) {
486
+ this.baseState = this.state;
487
+ this.state = State.BeforeEntity;
488
+ }
489
+ };
490
+ Tokenizer.prototype.stateInAttributeValueDoubleQuotes = function (c) {
491
+ this.handleInAttributeValue(c, CharCodes.DoubleQuote);
492
+ };
493
+ Tokenizer.prototype.stateInAttributeValueSingleQuotes = function (c) {
494
+ this.handleInAttributeValue(c, CharCodes.SingleQuote);
495
+ };
496
+ Tokenizer.prototype.stateInAttributeValueNoQuotes = function (c) {
497
+ if (isWhitespace(c) || c === CharCodes.Gt) {
498
+ this.cbs.onattribdata(this.sectionStart, this.index);
499
+ this.sectionStart = -1;
500
+ this.cbs.onattribend(QuoteType.Unquoted, this.index);
501
+ this.state = State.BeforeAttributeName;
502
+ this.stateBeforeAttributeName(c);
503
+ }
504
+ else if (this.decodeEntities && c === CharCodes.Amp) {
505
+ this.baseState = this.state;
506
+ this.state = State.BeforeEntity;
507
+ }
508
+ };
509
+ Tokenizer.prototype.stateBeforeDeclaration = function (c) {
510
+ if (c === CharCodes.OpeningSquareBracket) {
511
+ this.state = State.CDATASequence;
512
+ this.sequenceIndex = 0;
513
+ }
514
+ else {
515
+ this.state =
516
+ c === CharCodes.Dash
517
+ ? State.BeforeComment
518
+ : State.InDeclaration;
519
+ }
520
+ };
521
+ Tokenizer.prototype.stateInDeclaration = function (c) {
522
+ if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) {
523
+ this.cbs.ondeclaration(this.sectionStart, this.index);
524
+ this.state = State.Text;
525
+ this.sectionStart = this.index + 1;
526
+ }
527
+ };
528
+ Tokenizer.prototype.stateInProcessingInstruction = function (c) {
529
+ if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) {
530
+ this.cbs.onprocessinginstruction(this.sectionStart, this.index);
531
+ this.state = State.Text;
532
+ this.sectionStart = this.index + 1;
533
+ }
534
+ };
535
+ Tokenizer.prototype.stateBeforeComment = function (c) {
536
+ if (c === CharCodes.Dash) {
537
+ this.state = State.InCommentLike;
538
+ this.currentSequence = Sequences.CommentEnd;
539
+ // Allow short comments (eg. <!-->)
540
+ this.sequenceIndex = 2;
541
+ this.sectionStart = this.index + 1;
542
+ }
543
+ else {
544
+ this.state = State.InDeclaration;
545
+ }
546
+ };
547
+ Tokenizer.prototype.stateInSpecialComment = function (c) {
548
+ if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) {
549
+ this.cbs.oncomment(this.sectionStart, this.index, 0);
550
+ this.state = State.Text;
551
+ this.sectionStart = this.index + 1;
552
+ }
553
+ };
554
+ Tokenizer.prototype.stateBeforeSpecialS = function (c) {
555
+ var lower = c | 0x20;
556
+ if (lower === Sequences.ScriptEnd[3]) {
557
+ this.startSpecial(Sequences.ScriptEnd, 4);
558
+ }
559
+ else if (lower === Sequences.StyleEnd[3]) {
560
+ this.startSpecial(Sequences.StyleEnd, 4);
561
+ }
562
+ else {
563
+ this.state = State.InTagName;
564
+ this.stateInTagName(c); // Consume the token again
565
+ }
566
+ };
567
+ Tokenizer.prototype.stateBeforeEntity = function (c) {
568
+ // Start excess with 1 to include the '&'
569
+ this.entityExcess = 1;
570
+ this.entityResult = 0;
571
+ if (c === CharCodes.Num) {
572
+ this.state = State.BeforeNumericEntity;
573
+ }
574
+ else if (c === CharCodes.Amp) {
575
+ // We have two `&` characters in a row. Stay in the current state.
576
+ }
577
+ else {
578
+ this.trieIndex = 0;
579
+ this.trieCurrent = this.entityTrie[0];
580
+ this.state = State.InNamedEntity;
581
+ this.stateInNamedEntity(c);
582
+ }
583
+ };
584
+ Tokenizer.prototype.stateInNamedEntity = function (c) {
585
+ this.entityExcess += 1;
586
+ this.trieIndex = (0, decode_js_1.determineBranch)(this.entityTrie, this.trieCurrent, this.trieIndex + 1, c);
587
+ if (this.trieIndex < 0) {
588
+ this.emitNamedEntity();
589
+ this.index--;
590
+ return;
591
+ }
592
+ this.trieCurrent = this.entityTrie[this.trieIndex];
593
+ var masked = this.trieCurrent & decode_js_1.BinTrieFlags.VALUE_LENGTH;
594
+ // If the branch is a value, store it and continue
595
+ if (masked) {
596
+ // The mask is the number of bytes of the value, including the current byte.
597
+ var valueLength = (masked >> 14) - 1;
598
+ // If we have a legacy entity while parsing strictly, just skip the number of bytes
599
+ if (!this.allowLegacyEntity() && c !== CharCodes.Semi) {
600
+ this.trieIndex += valueLength;
601
+ }
602
+ else {
603
+ // Add 1 as we have already incremented the excess
604
+ var entityStart = this.index - this.entityExcess + 1;
605
+ if (entityStart > this.sectionStart) {
606
+ this.emitPartial(this.sectionStart, entityStart);
607
+ }
608
+ // If this is a surrogate pair, consume the next two bytes
609
+ this.entityResult = this.trieIndex;
610
+ this.trieIndex += valueLength;
611
+ this.entityExcess = 0;
612
+ this.sectionStart = this.index + 1;
613
+ if (valueLength === 0) {
614
+ this.emitNamedEntity();
615
+ }
616
+ }
617
+ }
618
+ };
619
+ Tokenizer.prototype.emitNamedEntity = function () {
620
+ this.state = this.baseState;
621
+ if (this.entityResult === 0) {
622
+ return;
623
+ }
624
+ var valueLength = (this.entityTrie[this.entityResult] & decode_js_1.BinTrieFlags.VALUE_LENGTH) >>
625
+ 14;
626
+ switch (valueLength) {
627
+ case 1:
628
+ this.emitCodePoint(this.entityTrie[this.entityResult] &
629
+ ~decode_js_1.BinTrieFlags.VALUE_LENGTH);
630
+ break;
631
+ case 2:
632
+ this.emitCodePoint(this.entityTrie[this.entityResult + 1]);
633
+ break;
634
+ case 3: {
635
+ this.emitCodePoint(this.entityTrie[this.entityResult + 1]);
636
+ this.emitCodePoint(this.entityTrie[this.entityResult + 2]);
637
+ }
638
+ }
639
+ };
640
+ Tokenizer.prototype.stateBeforeNumericEntity = function (c) {
641
+ if ((c | 0x20) === CharCodes.LowerX) {
642
+ this.entityExcess++;
643
+ this.state = State.InHexEntity;
644
+ }
645
+ else {
646
+ this.state = State.InNumericEntity;
647
+ this.stateInNumericEntity(c);
648
+ }
649
+ };
650
+ Tokenizer.prototype.emitNumericEntity = function (strict) {
651
+ var entityStart = this.index - this.entityExcess - 1;
652
+ var numberStart = entityStart + 2 + Number(this.state === State.InHexEntity);
653
+ if (numberStart !== this.index) {
654
+ // Emit leading data if any
655
+ if (entityStart > this.sectionStart) {
656
+ this.emitPartial(this.sectionStart, entityStart);
657
+ }
658
+ this.sectionStart = this.index + Number(strict);
659
+ this.emitCodePoint((0, decode_js_1.replaceCodePoint)(this.entityResult));
660
+ }
661
+ this.state = this.baseState;
662
+ };
663
+ Tokenizer.prototype.stateInNumericEntity = function (c) {
664
+ if (c === CharCodes.Semi) {
665
+ this.emitNumericEntity(true);
666
+ }
667
+ else if (isNumber(c)) {
668
+ this.entityResult = this.entityResult * 10 + (c - CharCodes.Zero);
669
+ this.entityExcess++;
670
+ }
671
+ else {
672
+ if (this.allowLegacyEntity()) {
673
+ this.emitNumericEntity(false);
674
+ }
675
+ else {
676
+ this.state = this.baseState;
677
+ }
678
+ this.index--;
679
+ }
680
+ };
681
+ Tokenizer.prototype.stateInHexEntity = function (c) {
682
+ if (c === CharCodes.Semi) {
683
+ this.emitNumericEntity(true);
684
+ }
685
+ else if (isNumber(c)) {
686
+ this.entityResult = this.entityResult * 16 + (c - CharCodes.Zero);
687
+ this.entityExcess++;
688
+ }
689
+ else if (isHexDigit(c)) {
690
+ this.entityResult =
691
+ this.entityResult * 16 + ((c | 0x20) - CharCodes.LowerA + 10);
692
+ this.entityExcess++;
693
+ }
694
+ else {
695
+ if (this.allowLegacyEntity()) {
696
+ this.emitNumericEntity(false);
697
+ }
698
+ else {
699
+ this.state = this.baseState;
700
+ }
701
+ this.index--;
702
+ }
703
+ };
704
+ Tokenizer.prototype.allowLegacyEntity = function () {
705
+ return (!this.xmlMode &&
706
+ (this.baseState === State.Text ||
707
+ this.baseState === State.InSpecialTag));
708
+ };
709
+ /**
710
+ * Remove data that has already been consumed from the buffer.
711
+ */
712
+ Tokenizer.prototype.cleanup = function () {
713
+ // If we are inside of text or attributes, emit what we already have.
714
+ if (this.running && this.sectionStart !== this.index) {
715
+ if (this.state === State.Text ||
716
+ (this.state === State.InSpecialTag && this.sequenceIndex === 0)) {
717
+ this.cbs.ontext(this.sectionStart, this.index);
718
+ this.sectionStart = this.index;
719
+ }
720
+ else if (this.state === State.InAttributeValueDq ||
721
+ this.state === State.InAttributeValueSq ||
722
+ this.state === State.InAttributeValueNq) {
723
+ this.cbs.onattribdata(this.sectionStart, this.index);
724
+ this.sectionStart = this.index;
725
+ }
726
+ }
727
+ };
728
+ Tokenizer.prototype.shouldContinue = function () {
729
+ return this.index < this.buffer.length + this.offset && this.running;
730
+ };
731
+ /**
732
+ * Iterates through the buffer, calling the function corresponding to the current state.
733
+ *
734
+ * States that are more likely to be hit are higher up, as a performance improvement.
735
+ */
736
+ Tokenizer.prototype.parse = function () {
737
+ while (this.shouldContinue()) {
738
+ var c = this.buffer.charCodeAt(this.index - this.offset);
739
+ if (this.state === State.Text) {
740
+ this.stateText(c);
741
+ }
742
+ else if (this.state === State.SpecialStartSequence) {
743
+ this.stateSpecialStartSequence(c);
744
+ }
745
+ else if (this.state === State.InSpecialTag) {
746
+ this.stateInSpecialTag(c);
747
+ }
748
+ else if (this.state === State.CDATASequence) {
749
+ this.stateCDATASequence(c);
750
+ }
751
+ else if (this.state === State.InAttributeValueDq) {
752
+ this.stateInAttributeValueDoubleQuotes(c);
753
+ }
754
+ else if (this.state === State.InAttributeName) {
755
+ this.stateInAttributeName(c);
756
+ }
757
+ else if (this.state === State.InCommentLike) {
758
+ this.stateInCommentLike(c);
759
+ }
760
+ else if (this.state === State.InSpecialComment) {
761
+ this.stateInSpecialComment(c);
762
+ }
763
+ else if (this.state === State.BeforeAttributeName) {
764
+ this.stateBeforeAttributeName(c);
765
+ }
766
+ else if (this.state === State.InTagName) {
767
+ this.stateInTagName(c);
768
+ }
769
+ else if (this.state === State.InClosingTagName) {
770
+ this.stateInClosingTagName(c);
771
+ }
772
+ else if (this.state === State.BeforeTagName) {
773
+ this.stateBeforeTagName(c);
774
+ }
775
+ else if (this.state === State.AfterAttributeName) {
776
+ this.stateAfterAttributeName(c);
777
+ }
778
+ else if (this.state === State.InAttributeValueSq) {
779
+ this.stateInAttributeValueSingleQuotes(c);
780
+ }
781
+ else if (this.state === State.BeforeAttributeValue) {
782
+ this.stateBeforeAttributeValue(c);
783
+ }
784
+ else if (this.state === State.BeforeClosingTagName) {
785
+ this.stateBeforeClosingTagName(c);
786
+ }
787
+ else if (this.state === State.AfterClosingTagName) {
788
+ this.stateAfterClosingTagName(c);
789
+ }
790
+ else if (this.state === State.BeforeSpecialS) {
791
+ this.stateBeforeSpecialS(c);
792
+ }
793
+ else if (this.state === State.InAttributeValueNq) {
794
+ this.stateInAttributeValueNoQuotes(c);
795
+ }
796
+ else if (this.state === State.InSelfClosingTag) {
797
+ this.stateInSelfClosingTag(c);
798
+ }
799
+ else if (this.state === State.InDeclaration) {
800
+ this.stateInDeclaration(c);
801
+ }
802
+ else if (this.state === State.BeforeDeclaration) {
803
+ this.stateBeforeDeclaration(c);
804
+ }
805
+ else if (this.state === State.BeforeComment) {
806
+ this.stateBeforeComment(c);
807
+ }
808
+ else if (this.state === State.InProcessingInstruction) {
809
+ this.stateInProcessingInstruction(c);
810
+ }
811
+ else if (this.state === State.InNamedEntity) {
812
+ this.stateInNamedEntity(c);
813
+ }
814
+ else if (this.state === State.BeforeEntity) {
815
+ this.stateBeforeEntity(c);
816
+ }
817
+ else if (this.state === State.InHexEntity) {
818
+ this.stateInHexEntity(c);
819
+ }
820
+ else if (this.state === State.InNumericEntity) {
821
+ this.stateInNumericEntity(c);
822
+ }
823
+ else {
824
+ // `this._state === State.BeforeNumericEntity`
825
+ this.stateBeforeNumericEntity(c);
826
+ }
827
+ this.index++;
828
+ }
829
+ this.cleanup();
830
+ };
831
+ Tokenizer.prototype.finish = function () {
832
+ if (this.state === State.InNamedEntity) {
833
+ this.emitNamedEntity();
834
+ }
835
+ // If there is remaining data, emit it in a reasonable way
836
+ if (this.sectionStart < this.index) {
837
+ this.handleTrailingData();
838
+ }
839
+ this.cbs.onend();
840
+ };
841
+ /** Handle any trailing data. */
842
+ Tokenizer.prototype.handleTrailingData = function () {
843
+ var endIndex = this.buffer.length + this.offset;
844
+ if (this.state === State.InCommentLike) {
845
+ if (this.currentSequence === Sequences.CdataEnd) {
846
+ this.cbs.oncdata(this.sectionStart, endIndex, 0);
847
+ }
848
+ else {
849
+ this.cbs.oncomment(this.sectionStart, endIndex, 0);
850
+ }
851
+ }
852
+ else if (this.state === State.InNumericEntity &&
853
+ this.allowLegacyEntity()) {
854
+ this.emitNumericEntity(false);
855
+ // All trailing data will have been consumed
856
+ }
857
+ else if (this.state === State.InHexEntity &&
858
+ this.allowLegacyEntity()) {
859
+ this.emitNumericEntity(false);
860
+ // All trailing data will have been consumed
861
+ }
862
+ else if (this.state === State.InTagName ||
863
+ this.state === State.BeforeAttributeName ||
864
+ this.state === State.BeforeAttributeValue ||
865
+ this.state === State.AfterAttributeName ||
866
+ this.state === State.InAttributeName ||
867
+ this.state === State.InAttributeValueSq ||
868
+ this.state === State.InAttributeValueDq ||
869
+ this.state === State.InAttributeValueNq ||
870
+ this.state === State.InClosingTagName) {
871
+ /*
872
+ * If we are currently in an opening or closing tag, us not calling the
873
+ * respective callback signals that the tag should be ignored.
874
+ */
875
+ }
876
+ else {
877
+ this.cbs.ontext(this.sectionStart, endIndex);
878
+ }
879
+ };
880
+ Tokenizer.prototype.emitPartial = function (start, endIndex) {
881
+ if (this.baseState !== State.Text &&
882
+ this.baseState !== State.InSpecialTag) {
883
+ this.cbs.onattribdata(start, endIndex);
884
+ }
885
+ else {
886
+ this.cbs.ontext(start, endIndex);
887
+ }
888
+ };
889
+ Tokenizer.prototype.emitCodePoint = function (cp) {
890
+ if (this.baseState !== State.Text &&
891
+ this.baseState !== State.InSpecialTag) {
892
+ this.cbs.onattribentity(cp);
893
+ }
894
+ else {
895
+ this.cbs.ontextentity(cp);
896
+ }
897
+ };
898
+ return Tokenizer;
899
+ }());
900
+ module.exports = {
901
+ default:Tokenizer,
902
+ QuoteType
903
+ }