@adguard/agtree 2.1.2 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (734) hide show
  1. package/dist/cjs/ast-utils/clone.js +65 -0
  2. package/dist/cjs/ast-utils/modifiers.js +56 -0
  3. package/dist/cjs/ast-utils/network-rules.js +43 -0
  4. package/dist/cjs/ast-utils/scriptlets.js +93 -0
  5. package/dist/cjs/common/abp-snippet-injection-body-common.js +18 -0
  6. package/dist/cjs/common/agent-common.js +58 -0
  7. package/dist/cjs/common/ubo-selector-common.js +18 -0
  8. package/dist/cjs/compatibility-tables/base.js +264 -0
  9. package/dist/cjs/compatibility-tables/compatibility-table-data.js +15 -0
  10. package/dist/cjs/compatibility-tables/modifiers.js +57 -0
  11. package/dist/cjs/compatibility-tables/platforms.js +58 -0
  12. package/dist/cjs/compatibility-tables/redirects.js +102 -0
  13. package/dist/cjs/compatibility-tables/schemas/base.js +116 -0
  14. package/dist/cjs/compatibility-tables/schemas/modifier.js +107 -0
  15. package/dist/cjs/compatibility-tables/schemas/platform.js +71 -0
  16. package/dist/cjs/compatibility-tables/schemas/redirect.js +31 -0
  17. package/dist/cjs/compatibility-tables/schemas/resource-type.js +39 -0
  18. package/dist/cjs/compatibility-tables/schemas/scriptlet.js +81 -0
  19. package/dist/cjs/compatibility-tables/scriptlets.js +30 -0
  20. package/dist/cjs/compatibility-tables/utils/platform-helpers.js +112 -0
  21. package/dist/cjs/compatibility-tables/utils/resource-type-helpers.js +64 -0
  22. package/dist/cjs/compatibility-tables/utils/zod-camelcase.js +27 -0
  23. package/dist/cjs/converter/base-interfaces/base-converter.js +61 -0
  24. package/dist/cjs/converter/base-interfaces/conversion-result.js +41 -0
  25. package/dist/cjs/converter/base-interfaces/rule-converter-base.js +62 -0
  26. package/dist/cjs/converter/comment/index.js +56 -0
  27. package/dist/cjs/converter/cosmetic/css.js +71 -0
  28. package/dist/cjs/converter/cosmetic/element-hiding.js +64 -0
  29. package/dist/cjs/converter/cosmetic/header-removal.js +126 -0
  30. package/dist/cjs/converter/cosmetic/html.js +384 -0
  31. package/dist/cjs/converter/cosmetic/index.js +120 -0
  32. package/dist/cjs/converter/cosmetic/rule-modifiers/adg.js +81 -0
  33. package/dist/cjs/converter/cosmetic/scriptlet.js +356 -0
  34. package/dist/cjs/converter/css/index.js +193 -0
  35. package/dist/cjs/converter/data/css.js +133 -0
  36. package/dist/cjs/converter/filter-list.js +90 -0
  37. package/dist/cjs/converter/index.js +15 -0
  38. package/dist/cjs/converter/misc/network-rule-modifier.js +313 -0
  39. package/dist/cjs/converter/network/index.js +101 -0
  40. package/dist/cjs/converter/raw-filter-list.js +58 -0
  41. package/dist/cjs/converter/rule.js +83 -0
  42. package/dist/cjs/deserializer/base-deserializer.js +31 -0
  43. package/dist/cjs/deserializer/comment/agent-comment-deserializer.js +76 -0
  44. package/dist/cjs/deserializer/comment/agent-deserializer.js +67 -0
  45. package/dist/cjs/deserializer/comment/comment-rule-deserializer.js +109 -0
  46. package/dist/cjs/deserializer/comment/config-comment-deserializer.js +113 -0
  47. package/dist/cjs/deserializer/comment/hint-comment-deserializer.js +69 -0
  48. package/dist/cjs/deserializer/comment/hint-deserializer.js +88 -0
  49. package/dist/cjs/deserializer/comment/metadata-comment-deserializer.js +71 -0
  50. package/dist/cjs/deserializer/comment/pre-processor-comment-deserializer.js +114 -0
  51. package/dist/cjs/deserializer/comment/simple-comment-deserializer.js +67 -0
  52. package/dist/cjs/deserializer/cosmetic/cosmetic-rule-deserializer.js +127 -0
  53. package/dist/cjs/deserializer/cosmetic/css-injection-body-deserializer.js +55 -0
  54. package/dist/cjs/deserializer/cosmetic/element-hiding-body-deserializer.js +46 -0
  55. package/dist/cjs/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.js +37 -0
  56. package/dist/cjs/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.js +37 -0
  57. package/dist/cjs/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.js +52 -0
  58. package/dist/cjs/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.js +38 -0
  59. package/dist/cjs/deserializer/empty-rule-deserializer.js +46 -0
  60. package/dist/cjs/deserializer/filterlist-deserializer.js +83 -0
  61. package/dist/cjs/deserializer/index.js +15 -0
  62. package/dist/cjs/deserializer/invalid-rule-deserializer.js +48 -0
  63. package/dist/cjs/deserializer/invalid-rule-error-node-deserializer.js +48 -0
  64. package/dist/cjs/deserializer/misc/domain-list-deserializer.js +66 -0
  65. package/dist/cjs/deserializer/misc/list-item-deserializer.js +65 -0
  66. package/dist/cjs/deserializer/misc/list-items-deserializer.js +28 -0
  67. package/dist/cjs/deserializer/misc/logical-expression-deserializer.js +199 -0
  68. package/dist/cjs/deserializer/misc/modifier-deserializer.js +89 -0
  69. package/dist/cjs/deserializer/misc/modifier-list-deserializer.js +58 -0
  70. package/dist/cjs/deserializer/misc/parameter-list-deserializer.js +62 -0
  71. package/dist/cjs/deserializer/misc/value-deserializer.js +52 -0
  72. package/dist/cjs/deserializer/network/host-rule-deserializer.js +81 -0
  73. package/dist/cjs/deserializer/network/hostname-list-deserializer.js +50 -0
  74. package/dist/cjs/deserializer/network/network-rule-deserializer.js +67 -0
  75. package/dist/cjs/deserializer/rule-deserializer.js +67 -0
  76. package/dist/cjs/deserializer/syntax-deserialization-map.js +23 -0
  77. package/dist/cjs/errors/adblock-syntax-error.js +41 -0
  78. package/dist/cjs/errors/binary-schema-mismatch-error.js +39 -0
  79. package/dist/cjs/errors/not-implemented-error.js +33 -0
  80. package/dist/cjs/errors/rule-conversion-error.js +28 -0
  81. package/dist/cjs/generator/base-generator.js +29 -0
  82. package/dist/cjs/generator/comment/agent-comment-generator.js +30 -0
  83. package/dist/cjs/generator/comment/agent-generator.js +34 -0
  84. package/dist/cjs/generator/comment/comment-rule-generator.js +102 -0
  85. package/dist/cjs/generator/comment/config-comment-generator.js +44 -0
  86. package/dist/cjs/generator/comment/hint-comment-generator.js +27 -0
  87. package/dist/cjs/generator/comment/hint-generator.js +32 -0
  88. package/dist/cjs/generator/comment/metadata-comment-generator.js +32 -0
  89. package/dist/cjs/generator/comment/pre-processor-comment-generator.js +47 -0
  90. package/dist/cjs/generator/comment/simple-comment-generator.js +28 -0
  91. package/dist/cjs/generator/cosmetic/body/abp-snippet-injection-body-generator.js +36 -0
  92. package/dist/cjs/generator/cosmetic/body/adg-scriptlet-injection-body-generator.js +41 -0
  93. package/dist/cjs/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.js +43 -0
  94. package/dist/cjs/generator/cosmetic/cosmetic-rule-body-generator.js +92 -0
  95. package/dist/cjs/generator/cosmetic/cosmetic-rule-generator.js +66 -0
  96. package/dist/cjs/generator/cosmetic/cosmetic-rule-pattern-generator.js +41 -0
  97. package/dist/cjs/generator/css/adg-css-injection-generator.js +41 -0
  98. package/dist/cjs/generator/filterlist-generator.js +57 -0
  99. package/dist/cjs/generator/index.js +17 -0
  100. package/dist/cjs/generator/misc/domain-list-generator.js +25 -0
  101. package/dist/cjs/generator/misc/list-items-generator.js +38 -0
  102. package/dist/cjs/generator/misc/logical-expression-generator.js +47 -0
  103. package/dist/cjs/generator/misc/modifier-generator.js +33 -0
  104. package/dist/cjs/generator/misc/modifier-list-generator.js +28 -0
  105. package/dist/cjs/generator/misc/parameter-list-generator.js +41 -0
  106. package/dist/cjs/generator/misc/value-generator.js +23 -0
  107. package/dist/cjs/generator/network/host-rule-generator.js +38 -0
  108. package/dist/cjs/generator/network/network-rule-generator.js +37 -0
  109. package/dist/cjs/generator/rule-generator.js +64 -0
  110. package/dist/cjs/index.js +201 -0
  111. package/dist/cjs/marshalling-utils/comment/agent-comment-common.js +22 -0
  112. package/dist/cjs/marshalling-utils/comment/agent-common.js +43 -0
  113. package/dist/cjs/marshalling-utils/comment/config-comment-common.js +58 -0
  114. package/dist/cjs/marshalling-utils/comment/hint-comment-common.js +23 -0
  115. package/dist/cjs/marshalling-utils/comment/hint-common.js +60 -0
  116. package/dist/cjs/marshalling-utils/comment/metadata-comment-common.js +44 -0
  117. package/dist/cjs/marshalling-utils/comment/pre-processor-comment-common.js +63 -0
  118. package/dist/cjs/marshalling-utils/comment/simple-comment-common.js +23 -0
  119. package/dist/cjs/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.js +64 -0
  120. package/dist/cjs/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.js +68 -0
  121. package/dist/cjs/marshalling-utils/cosmetic/body/css-injection-body-common.js +25 -0
  122. package/dist/cjs/marshalling-utils/cosmetic/body/element-hiding-body-common.js +22 -0
  123. package/dist/cjs/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.js +116 -0
  124. package/dist/cjs/marshalling-utils/cosmetic/cosmetic-rule-common.js +51 -0
  125. package/dist/cjs/marshalling-utils/empty-rule-common.js +21 -0
  126. package/dist/cjs/marshalling-utils/filter-list-common.js +22 -0
  127. package/dist/cjs/marshalling-utils/invalid-rule-common.js +22 -0
  128. package/dist/cjs/marshalling-utils/invalid-rule-error-node-common.js +23 -0
  129. package/dist/cjs/marshalling-utils/misc/binary-type-common.js +67 -0
  130. package/dist/cjs/marshalling-utils/misc/domain-list-common.js +39 -0
  131. package/dist/cjs/marshalling-utils/misc/host-rule-common.js +26 -0
  132. package/dist/cjs/marshalling-utils/misc/hostname-list-common.js +22 -0
  133. package/dist/cjs/marshalling-utils/misc/list-item-common.js +23 -0
  134. package/dist/cjs/marshalling-utils/misc/logical-expression-common.js +89 -0
  135. package/dist/cjs/marshalling-utils/misc/modifier-common.js +236 -0
  136. package/dist/cjs/marshalling-utils/misc/modifier-list-common.js +22 -0
  137. package/dist/cjs/marshalling-utils/misc/parameter-list-common.js +22 -0
  138. package/dist/cjs/marshalling-utils/misc/value-common.js +23 -0
  139. package/dist/cjs/marshalling-utils/network/network-rule-common.js +26 -0
  140. package/dist/cjs/marshalling-utils/syntax-serialization-map.js +32 -0
  141. package/dist/cjs/nodes/index.js +180 -0
  142. package/dist/cjs/package.json.js +11 -0
  143. package/dist/cjs/parser/base-parser.js +32 -0
  144. package/dist/cjs/parser/comment/agent-comment-parser.js +121 -0
  145. package/dist/cjs/parser/comment/agent-parser.js +111 -0
  146. package/dist/cjs/parser/comment/comment-parser.js +110 -0
  147. package/dist/cjs/parser/comment/config-comment-parser.js +139 -0
  148. package/dist/cjs/parser/comment/hint-comment-parser.js +119 -0
  149. package/dist/cjs/parser/comment/hint-parser.js +131 -0
  150. package/dist/cjs/parser/comment/metadata-comment-parser.js +131 -0
  151. package/dist/cjs/parser/comment/preprocessor-parser.js +201 -0
  152. package/dist/cjs/parser/comment/simple-comment-parser.js +108 -0
  153. package/dist/cjs/parser/cosmetic/body/abp-snippet-injection-body-parser.js +81 -0
  154. package/dist/cjs/parser/cosmetic/body/adg-scriptlet-injection-body-parser.js +151 -0
  155. package/dist/cjs/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.js +112 -0
  156. package/dist/cjs/parser/cosmetic/cosmetic-rule-parser.js +456 -0
  157. package/dist/cjs/parser/css/adg-css-injection-parser.js +213 -0
  158. package/dist/cjs/parser/css/balancing.js +97 -0
  159. package/dist/cjs/parser/css/constants.js +21 -0
  160. package/dist/cjs/parser/css/css-token-stream.js +345 -0
  161. package/dist/cjs/parser/css/ubo-selector-parser.js +373 -0
  162. package/dist/cjs/parser/filterlist-parser.js +104 -0
  163. package/dist/cjs/parser/index.js +21 -0
  164. package/dist/cjs/parser/misc/app-list-parser.js +47 -0
  165. package/dist/cjs/parser/misc/domain-list-parser.js +54 -0
  166. package/dist/cjs/parser/misc/list-items-parser.js +116 -0
  167. package/dist/cjs/parser/misc/logical-expression-parser.js +283 -0
  168. package/dist/cjs/parser/misc/method-list-parser.js +48 -0
  169. package/dist/cjs/parser/misc/modifier-list.js +72 -0
  170. package/dist/cjs/parser/misc/modifier-parser.js +91 -0
  171. package/dist/cjs/parser/misc/parameter-list-parser.js +74 -0
  172. package/dist/cjs/parser/misc/stealth-option-list-parser.js +48 -0
  173. package/dist/cjs/parser/misc/ubo-parameter-list-parser.js +148 -0
  174. package/dist/cjs/parser/misc/value-parser.js +39 -0
  175. package/dist/cjs/parser/network/host-rule-parser.js +151 -0
  176. package/dist/cjs/parser/network/network-rule-parser.js +113 -0
  177. package/dist/cjs/parser/options.js +25 -0
  178. package/dist/cjs/parser/rule-parser.js +194 -0
  179. package/dist/cjs/serializer/base-serializer.js +31 -0
  180. package/dist/cjs/serializer/comment/agent-comment-serializer.js +73 -0
  181. package/dist/cjs/serializer/comment/agent-serializer.js +70 -0
  182. package/dist/cjs/serializer/comment/comment-rule-serializer.js +107 -0
  183. package/dist/cjs/serializer/comment/config-comment-serializer.js +84 -0
  184. package/dist/cjs/serializer/comment/hint-comment-serializer.js +64 -0
  185. package/dist/cjs/serializer/comment/hint-serializer.js +56 -0
  186. package/dist/cjs/serializer/comment/metadata-comment-serializer.js +75 -0
  187. package/dist/cjs/serializer/comment/pre-processor-comment-serializer.js +73 -0
  188. package/dist/cjs/serializer/comment/simple-comment-serializer.js +54 -0
  189. package/dist/cjs/serializer/cosmetic/body/abp-snippet-injection-body-serializer.js +38 -0
  190. package/dist/cjs/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.js +38 -0
  191. package/dist/cjs/serializer/cosmetic/body/scriptlet-body-serializer.js +49 -0
  192. package/dist/cjs/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.js +38 -0
  193. package/dist/cjs/serializer/cosmetic/cosmetic-rule-serializer.js +131 -0
  194. package/dist/cjs/serializer/cosmetic/css-injection-body-serializer.js +50 -0
  195. package/dist/cjs/serializer/cosmetic/element-hiding-body-serializer.js +39 -0
  196. package/dist/cjs/serializer/empty-rule-serializer.js +36 -0
  197. package/dist/cjs/serializer/filterlist-serializer.js +48 -0
  198. package/dist/cjs/serializer/index.js +13 -0
  199. package/dist/cjs/serializer/invalid-rule-error-node-serializer.js +40 -0
  200. package/dist/cjs/serializer/invalid-rule-serializer.js +39 -0
  201. package/dist/cjs/serializer/misc/domain-list-serializer.js +66 -0
  202. package/dist/cjs/serializer/misc/list-item-serializer.js +57 -0
  203. package/dist/cjs/serializer/misc/list-items-serializer.js +28 -0
  204. package/dist/cjs/serializer/misc/logical-expression-serializer.js +138 -0
  205. package/dist/cjs/serializer/misc/modifier-list-serializer.js +57 -0
  206. package/dist/cjs/serializer/misc/modifier-serializer.js +51 -0
  207. package/dist/cjs/serializer/misc/parameter-list-serializer.js +51 -0
  208. package/dist/cjs/serializer/misc/value-serializer.js +52 -0
  209. package/dist/cjs/serializer/network/host-rule-serializer.js +72 -0
  210. package/dist/cjs/serializer/network/hostname-list-serializer.js +49 -0
  211. package/dist/cjs/serializer/network/network-rule-serializer.js +56 -0
  212. package/dist/cjs/serializer/rule-serializer.js +63 -0
  213. package/dist/cjs/utils/adblockers.js +57 -0
  214. package/dist/cjs/utils/binary-schema-version.js +19 -0
  215. package/dist/cjs/utils/byte-buffer.js +93 -0
  216. package/dist/cjs/utils/categorizer.js +46 -0
  217. package/dist/cjs/utils/clone.js +30 -0
  218. package/dist/cjs/utils/constants.js +380 -0
  219. package/dist/cjs/utils/cosmetic-rule-separator.js +129 -0
  220. package/dist/cjs/utils/deep-freeze.js +34 -0
  221. package/dist/cjs/utils/domain.js +60 -0
  222. package/dist/cjs/utils/error.js +51 -0
  223. package/dist/cjs/utils/index.js +69 -0
  224. package/dist/cjs/utils/input-byte-buffer.js +259 -0
  225. package/dist/cjs/utils/is-chromium.js +22 -0
  226. package/dist/cjs/utils/logical-expression.js +94 -0
  227. package/dist/cjs/utils/multi-value-map.js +35 -0
  228. package/dist/cjs/utils/output-byte-buffer.js +225 -0
  229. package/dist/cjs/utils/position-provider.js +75 -0
  230. package/dist/cjs/utils/quotes.js +218 -0
  231. package/dist/cjs/utils/regexp.js +190 -0
  232. package/dist/cjs/utils/string.js +560 -0
  233. package/dist/cjs/utils/text-decoder-polyfill.js +109 -0
  234. package/dist/cjs/utils/text-encoder-polyfill.js +80 -0
  235. package/dist/cjs/utils/type-guards.js +52 -0
  236. package/dist/cjs/validator/constants.js +222 -0
  237. package/dist/cjs/validator/helpers.js +49 -0
  238. package/dist/cjs/validator/index.js +176 -0
  239. package/dist/cjs/validator/value.js +565 -0
  240. package/dist/cjs/version.js +20 -0
  241. package/dist/esm/ast-utils/clone.mjs +61 -0
  242. package/dist/esm/ast-utils/modifiers.mjs +53 -0
  243. package/dist/esm/ast-utils/network-rules.mjs +41 -0
  244. package/dist/esm/ast-utils/scriptlets.mjs +87 -0
  245. package/dist/esm/common/abp-snippet-injection-body-common.mjs +16 -0
  246. package/dist/esm/common/agent-common.mjs +56 -0
  247. package/dist/esm/common/ubo-selector-common.mjs +18 -0
  248. package/dist/esm/compatibility-tables/base.mjs +262 -0
  249. package/dist/esm/compatibility-tables/compatibility-table-data.mjs +11 -0
  250. package/dist/esm/compatibility-tables/modifiers.mjs +55 -0
  251. package/dist/esm/compatibility-tables/platforms.mjs +58 -0
  252. package/dist/esm/compatibility-tables/redirects.mjs +100 -0
  253. package/dist/esm/compatibility-tables/schemas/base.mjs +111 -0
  254. package/dist/esm/compatibility-tables/schemas/modifier.mjs +105 -0
  255. package/dist/esm/compatibility-tables/schemas/platform.mjs +69 -0
  256. package/dist/esm/compatibility-tables/schemas/redirect.mjs +29 -0
  257. package/dist/esm/compatibility-tables/schemas/resource-type.mjs +37 -0
  258. package/dist/esm/compatibility-tables/schemas/scriptlet.mjs +79 -0
  259. package/dist/esm/compatibility-tables/scriptlets.mjs +28 -0
  260. package/dist/esm/compatibility-tables/utils/platform-helpers.mjs +105 -0
  261. package/dist/esm/compatibility-tables/utils/resource-type-helpers.mjs +61 -0
  262. package/dist/esm/compatibility-tables/utils/zod-camelcase.mjs +25 -0
  263. package/dist/esm/converter/base-interfaces/base-converter.mjs +59 -0
  264. package/dist/esm/converter/base-interfaces/conversion-result.mjs +38 -0
  265. package/dist/esm/converter/base-interfaces/rule-converter-base.mjs +60 -0
  266. package/dist/esm/converter/comment/index.mjs +54 -0
  267. package/dist/esm/converter/cosmetic/css.mjs +69 -0
  268. package/dist/esm/converter/cosmetic/element-hiding.mjs +62 -0
  269. package/dist/esm/converter/cosmetic/header-removal.mjs +123 -0
  270. package/dist/esm/converter/cosmetic/html.mjs +381 -0
  271. package/dist/esm/converter/cosmetic/index.mjs +118 -0
  272. package/dist/esm/converter/cosmetic/rule-modifiers/adg.mjs +79 -0
  273. package/dist/esm/converter/cosmetic/scriptlet.mjs +354 -0
  274. package/dist/esm/converter/css/index.mjs +190 -0
  275. package/dist/esm/converter/data/css.mjs +126 -0
  276. package/dist/esm/converter/filter-list.mjs +88 -0
  277. package/dist/esm/converter/index.mjs +8 -0
  278. package/dist/esm/converter/misc/network-rule-modifier.mjs +311 -0
  279. package/dist/esm/converter/network/index.mjs +99 -0
  280. package/dist/esm/converter/raw-filter-list.mjs +56 -0
  281. package/dist/esm/converter/rule.mjs +81 -0
  282. package/dist/esm/deserializer/base-deserializer.mjs +29 -0
  283. package/dist/esm/deserializer/comment/agent-comment-deserializer.mjs +74 -0
  284. package/dist/esm/deserializer/comment/agent-deserializer.mjs +65 -0
  285. package/dist/esm/deserializer/comment/comment-rule-deserializer.mjs +107 -0
  286. package/dist/esm/deserializer/comment/config-comment-deserializer.mjs +111 -0
  287. package/dist/esm/deserializer/comment/hint-comment-deserializer.mjs +67 -0
  288. package/dist/esm/deserializer/comment/hint-deserializer.mjs +85 -0
  289. package/dist/esm/deserializer/comment/metadata-comment-deserializer.mjs +69 -0
  290. package/dist/esm/deserializer/comment/pre-processor-comment-deserializer.mjs +112 -0
  291. package/dist/esm/deserializer/comment/simple-comment-deserializer.mjs +65 -0
  292. package/dist/esm/deserializer/cosmetic/cosmetic-rule-deserializer.mjs +125 -0
  293. package/dist/esm/deserializer/cosmetic/css-injection-body-deserializer.mjs +53 -0
  294. package/dist/esm/deserializer/cosmetic/element-hiding-body-deserializer.mjs +44 -0
  295. package/dist/esm/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.mjs +35 -0
  296. package/dist/esm/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.mjs +35 -0
  297. package/dist/esm/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.mjs +50 -0
  298. package/dist/esm/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.mjs +35 -0
  299. package/dist/esm/deserializer/empty-rule-deserializer.mjs +44 -0
  300. package/dist/esm/deserializer/filterlist-deserializer.mjs +81 -0
  301. package/dist/esm/deserializer/index.mjs +8 -0
  302. package/dist/esm/deserializer/invalid-rule-deserializer.mjs +46 -0
  303. package/dist/esm/deserializer/invalid-rule-error-node-deserializer.mjs +46 -0
  304. package/dist/esm/deserializer/misc/domain-list-deserializer.mjs +64 -0
  305. package/dist/esm/deserializer/misc/list-item-deserializer.mjs +63 -0
  306. package/dist/esm/deserializer/misc/list-items-deserializer.mjs +26 -0
  307. package/dist/esm/deserializer/misc/logical-expression-deserializer.mjs +196 -0
  308. package/dist/esm/deserializer/misc/modifier-deserializer.mjs +87 -0
  309. package/dist/esm/deserializer/misc/modifier-list-deserializer.mjs +56 -0
  310. package/dist/esm/deserializer/misc/parameter-list-deserializer.mjs +60 -0
  311. package/dist/esm/deserializer/misc/value-deserializer.mjs +50 -0
  312. package/dist/esm/deserializer/network/host-rule-deserializer.mjs +79 -0
  313. package/dist/esm/deserializer/network/hostname-list-deserializer.mjs +48 -0
  314. package/dist/esm/deserializer/network/network-rule-deserializer.mjs +65 -0
  315. package/dist/esm/deserializer/rule-deserializer.mjs +65 -0
  316. package/dist/esm/deserializer/syntax-deserialization-map.mjs +21 -0
  317. package/dist/esm/errors/adblock-syntax-error.mjs +39 -0
  318. package/dist/esm/errors/binary-schema-mismatch-error.mjs +37 -0
  319. package/dist/esm/errors/not-implemented-error.mjs +31 -0
  320. package/dist/esm/errors/rule-conversion-error.mjs +26 -0
  321. package/dist/esm/generator/base-generator.mjs +27 -0
  322. package/dist/esm/generator/comment/agent-comment-generator.mjs +28 -0
  323. package/dist/esm/generator/comment/agent-generator.mjs +32 -0
  324. package/dist/esm/generator/comment/comment-rule-generator.mjs +100 -0
  325. package/dist/esm/generator/comment/config-comment-generator.mjs +42 -0
  326. package/dist/esm/generator/comment/hint-comment-generator.mjs +25 -0
  327. package/dist/esm/generator/comment/hint-generator.mjs +30 -0
  328. package/dist/esm/generator/comment/metadata-comment-generator.mjs +30 -0
  329. package/dist/esm/generator/comment/pre-processor-comment-generator.mjs +45 -0
  330. package/dist/esm/generator/comment/simple-comment-generator.mjs +26 -0
  331. package/dist/esm/generator/cosmetic/body/abp-snippet-injection-body-generator.mjs +34 -0
  332. package/dist/esm/generator/cosmetic/body/adg-scriptlet-injection-body-generator.mjs +39 -0
  333. package/dist/esm/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.mjs +41 -0
  334. package/dist/esm/generator/cosmetic/cosmetic-rule-body-generator.mjs +90 -0
  335. package/dist/esm/generator/cosmetic/cosmetic-rule-generator.mjs +64 -0
  336. package/dist/esm/generator/cosmetic/cosmetic-rule-pattern-generator.mjs +39 -0
  337. package/dist/esm/generator/css/adg-css-injection-generator.mjs +39 -0
  338. package/dist/esm/generator/filterlist-generator.mjs +55 -0
  339. package/dist/esm/generator/index.mjs +9 -0
  340. package/dist/esm/generator/misc/domain-list-generator.mjs +23 -0
  341. package/dist/esm/generator/misc/list-items-generator.mjs +36 -0
  342. package/dist/esm/generator/misc/logical-expression-generator.mjs +45 -0
  343. package/dist/esm/generator/misc/modifier-generator.mjs +31 -0
  344. package/dist/esm/generator/misc/modifier-list-generator.mjs +26 -0
  345. package/dist/esm/generator/misc/parameter-list-generator.mjs +39 -0
  346. package/dist/esm/generator/misc/value-generator.mjs +21 -0
  347. package/dist/esm/generator/network/host-rule-generator.mjs +36 -0
  348. package/dist/esm/generator/network/network-rule-generator.mjs +35 -0
  349. package/dist/esm/generator/rule-generator.mjs +62 -0
  350. package/dist/esm/index.mjs +70 -0
  351. package/dist/esm/marshalling-utils/comment/agent-comment-common.mjs +22 -0
  352. package/dist/esm/marshalling-utils/comment/agent-common.mjs +41 -0
  353. package/dist/esm/marshalling-utils/comment/config-comment-common.mjs +56 -0
  354. package/dist/esm/marshalling-utils/comment/hint-comment-common.mjs +23 -0
  355. package/dist/esm/marshalling-utils/comment/hint-common.mjs +57 -0
  356. package/dist/esm/marshalling-utils/comment/metadata-comment-common.mjs +42 -0
  357. package/dist/esm/marshalling-utils/comment/pre-processor-comment-common.mjs +60 -0
  358. package/dist/esm/marshalling-utils/comment/simple-comment-common.mjs +23 -0
  359. package/dist/esm/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.mjs +62 -0
  360. package/dist/esm/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.mjs +66 -0
  361. package/dist/esm/marshalling-utils/cosmetic/body/css-injection-body-common.mjs +25 -0
  362. package/dist/esm/marshalling-utils/cosmetic/body/element-hiding-body-common.mjs +22 -0
  363. package/dist/esm/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.mjs +114 -0
  364. package/dist/esm/marshalling-utils/cosmetic/cosmetic-rule-common.mjs +49 -0
  365. package/dist/esm/marshalling-utils/empty-rule-common.mjs +21 -0
  366. package/dist/esm/marshalling-utils/filter-list-common.mjs +22 -0
  367. package/dist/esm/marshalling-utils/invalid-rule-common.mjs +22 -0
  368. package/dist/esm/marshalling-utils/invalid-rule-error-node-common.mjs +23 -0
  369. package/dist/esm/marshalling-utils/misc/binary-type-common.mjs +67 -0
  370. package/dist/esm/marshalling-utils/misc/domain-list-common.mjs +37 -0
  371. package/dist/esm/marshalling-utils/misc/host-rule-common.mjs +26 -0
  372. package/dist/esm/marshalling-utils/misc/hostname-list-common.mjs +22 -0
  373. package/dist/esm/marshalling-utils/misc/list-item-common.mjs +23 -0
  374. package/dist/esm/marshalling-utils/misc/logical-expression-common.mjs +86 -0
  375. package/dist/esm/marshalling-utils/misc/modifier-common.mjs +232 -0
  376. package/dist/esm/marshalling-utils/misc/modifier-list-common.mjs +22 -0
  377. package/dist/esm/marshalling-utils/misc/parameter-list-common.mjs +22 -0
  378. package/dist/esm/marshalling-utils/misc/value-common.mjs +23 -0
  379. package/dist/esm/marshalling-utils/network/network-rule-common.mjs +26 -0
  380. package/dist/esm/marshalling-utils/syntax-serialization-map.mjs +30 -0
  381. package/dist/esm/nodes/index.mjs +180 -0
  382. package/dist/esm/package.json.mjs +9 -0
  383. package/dist/esm/parser/base-parser.mjs +30 -0
  384. package/dist/esm/parser/comment/agent-comment-parser.mjs +119 -0
  385. package/dist/esm/parser/comment/agent-parser.mjs +109 -0
  386. package/dist/esm/parser/comment/comment-parser.mjs +108 -0
  387. package/dist/esm/parser/comment/config-comment-parser.mjs +137 -0
  388. package/dist/esm/parser/comment/hint-comment-parser.mjs +117 -0
  389. package/dist/esm/parser/comment/hint-parser.mjs +129 -0
  390. package/dist/esm/parser/comment/metadata-comment-parser.mjs +129 -0
  391. package/dist/esm/parser/comment/preprocessor-parser.mjs +199 -0
  392. package/dist/esm/parser/comment/simple-comment-parser.mjs +106 -0
  393. package/dist/esm/parser/cosmetic/body/abp-snippet-injection-body-parser.mjs +79 -0
  394. package/dist/esm/parser/cosmetic/body/adg-scriptlet-injection-body-parser.mjs +149 -0
  395. package/dist/esm/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.mjs +110 -0
  396. package/dist/esm/parser/cosmetic/cosmetic-rule-parser.mjs +453 -0
  397. package/dist/esm/parser/css/adg-css-injection-parser.mjs +208 -0
  398. package/dist/esm/parser/css/balancing.mjs +94 -0
  399. package/dist/esm/parser/css/constants.mjs +18 -0
  400. package/dist/esm/parser/css/css-token-stream.mjs +343 -0
  401. package/dist/esm/parser/css/ubo-selector-parser.mjs +369 -0
  402. package/dist/esm/parser/filterlist-parser.mjs +102 -0
  403. package/dist/esm/parser/index.mjs +11 -0
  404. package/dist/esm/parser/misc/app-list-parser.mjs +45 -0
  405. package/dist/esm/parser/misc/domain-list-parser.mjs +52 -0
  406. package/dist/esm/parser/misc/list-items-parser.mjs +113 -0
  407. package/dist/esm/parser/misc/logical-expression-parser.mjs +281 -0
  408. package/dist/esm/parser/misc/method-list-parser.mjs +46 -0
  409. package/dist/esm/parser/misc/modifier-list.mjs +70 -0
  410. package/dist/esm/parser/misc/modifier-parser.mjs +89 -0
  411. package/dist/esm/parser/misc/parameter-list-parser.mjs +72 -0
  412. package/dist/esm/parser/misc/stealth-option-list-parser.mjs +46 -0
  413. package/dist/esm/parser/misc/ubo-parameter-list-parser.mjs +146 -0
  414. package/dist/esm/parser/misc/value-parser.mjs +37 -0
  415. package/dist/esm/parser/network/host-rule-parser.mjs +130 -0
  416. package/dist/esm/parser/network/network-rule-parser.mjs +111 -0
  417. package/dist/esm/parser/options.mjs +23 -0
  418. package/dist/esm/parser/rule-parser.mjs +192 -0
  419. package/dist/esm/serializer/base-serializer.mjs +29 -0
  420. package/dist/esm/serializer/comment/agent-comment-serializer.mjs +71 -0
  421. package/dist/esm/serializer/comment/agent-serializer.mjs +68 -0
  422. package/dist/esm/serializer/comment/comment-rule-serializer.mjs +105 -0
  423. package/dist/esm/serializer/comment/config-comment-serializer.mjs +82 -0
  424. package/dist/esm/serializer/comment/hint-comment-serializer.mjs +62 -0
  425. package/dist/esm/serializer/comment/hint-serializer.mjs +54 -0
  426. package/dist/esm/serializer/comment/metadata-comment-serializer.mjs +73 -0
  427. package/dist/esm/serializer/comment/pre-processor-comment-serializer.mjs +71 -0
  428. package/dist/esm/serializer/comment/simple-comment-serializer.mjs +52 -0
  429. package/dist/esm/serializer/cosmetic/body/abp-snippet-injection-body-serializer.mjs +36 -0
  430. package/dist/esm/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.mjs +36 -0
  431. package/dist/esm/serializer/cosmetic/body/scriptlet-body-serializer.mjs +47 -0
  432. package/dist/esm/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.mjs +36 -0
  433. package/dist/esm/serializer/cosmetic/cosmetic-rule-serializer.mjs +129 -0
  434. package/dist/esm/serializer/cosmetic/css-injection-body-serializer.mjs +48 -0
  435. package/dist/esm/serializer/cosmetic/element-hiding-body-serializer.mjs +37 -0
  436. package/dist/esm/serializer/empty-rule-serializer.mjs +34 -0
  437. package/dist/esm/serializer/filterlist-serializer.mjs +46 -0
  438. package/dist/esm/serializer/index.mjs +7 -0
  439. package/dist/esm/serializer/invalid-rule-error-node-serializer.mjs +38 -0
  440. package/dist/esm/serializer/invalid-rule-serializer.mjs +37 -0
  441. package/dist/esm/serializer/misc/domain-list-serializer.mjs +64 -0
  442. package/dist/esm/serializer/misc/list-item-serializer.mjs +55 -0
  443. package/dist/esm/serializer/misc/list-items-serializer.mjs +26 -0
  444. package/dist/esm/serializer/misc/logical-expression-serializer.mjs +136 -0
  445. package/dist/esm/serializer/misc/modifier-list-serializer.mjs +55 -0
  446. package/dist/esm/serializer/misc/modifier-serializer.mjs +49 -0
  447. package/dist/esm/serializer/misc/parameter-list-serializer.mjs +49 -0
  448. package/dist/esm/serializer/misc/value-serializer.mjs +50 -0
  449. package/dist/esm/serializer/network/host-rule-serializer.mjs +70 -0
  450. package/dist/esm/serializer/network/hostname-list-serializer.mjs +47 -0
  451. package/dist/esm/serializer/network/network-rule-serializer.mjs +54 -0
  452. package/dist/esm/serializer/rule-serializer.mjs +61 -0
  453. package/dist/esm/utils/adblockers.mjs +57 -0
  454. package/dist/esm/utils/binary-schema-version.mjs +17 -0
  455. package/dist/esm/utils/byte-buffer.mjs +91 -0
  456. package/dist/esm/utils/categorizer.mjs +44 -0
  457. package/dist/esm/utils/clone.mjs +28 -0
  458. package/dist/esm/utils/constants.mjs +249 -0
  459. package/dist/esm/utils/cosmetic-rule-separator.mjs +127 -0
  460. package/dist/esm/utils/deep-freeze.mjs +32 -0
  461. package/dist/esm/utils/domain.mjs +56 -0
  462. package/dist/esm/utils/error.mjs +49 -0
  463. package/dist/esm/utils/index.mjs +21 -0
  464. package/dist/esm/utils/input-byte-buffer.mjs +257 -0
  465. package/dist/esm/utils/is-chromium.mjs +20 -0
  466. package/dist/esm/utils/logical-expression.mjs +92 -0
  467. package/dist/esm/utils/multi-value-map.mjs +33 -0
  468. package/dist/esm/utils/output-byte-buffer.mjs +223 -0
  469. package/dist/esm/utils/position-provider.mjs +73 -0
  470. package/dist/esm/utils/quotes.mjs +215 -0
  471. package/dist/esm/utils/regexp.mjs +176 -0
  472. package/dist/esm/utils/string.mjs +556 -0
  473. package/dist/esm/utils/text-decoder-polyfill.mjs +107 -0
  474. package/dist/esm/utils/text-encoder-polyfill.mjs +78 -0
  475. package/dist/esm/utils/type-guards.mjs +47 -0
  476. package/dist/esm/validator/constants.mjs +210 -0
  477. package/dist/esm/validator/helpers.mjs +45 -0
  478. package/dist/esm/validator/index.mjs +174 -0
  479. package/dist/esm/validator/value.mjs +563 -0
  480. package/dist/esm/version.mjs +18 -0
  481. package/dist/types/ast-utils/clone.d.ts +26 -0
  482. package/dist/types/ast-utils/filter-list.d.ts +11 -0
  483. package/dist/types/ast-utils/modifiers.d.ts +20 -0
  484. package/dist/types/ast-utils/network-rules.d.ts +15 -0
  485. package/dist/types/ast-utils/scriptlets.d.ts +52 -0
  486. package/dist/types/common/abp-snippet-injection-body-common.d.ts +8 -0
  487. package/dist/types/common/agent-common.d.ts +10 -0
  488. package/dist/types/common/ubo-selector-common.d.ts +9 -0
  489. package/dist/types/compatibility-tables/base.d.ts +157 -0
  490. package/dist/types/compatibility-tables/compatibility-table-data.d.ts +67 -0
  491. package/dist/types/compatibility-tables/index.d.ts +13 -0
  492. package/dist/types/compatibility-tables/modifiers.d.ts +22 -0
  493. package/dist/types/compatibility-tables/platforms.d.ts +47 -0
  494. package/dist/types/compatibility-tables/redirects.d.ts +33 -0
  495. package/dist/types/compatibility-tables/schemas/base.d.ts +135 -0
  496. package/dist/types/compatibility-tables/schemas/index.d.ts +8 -0
  497. package/dist/types/compatibility-tables/schemas/modifier.d.ts +31 -0
  498. package/dist/types/compatibility-tables/schemas/platform.d.ts +16 -0
  499. package/dist/types/compatibility-tables/schemas/redirect.d.ts +25 -0
  500. package/dist/types/compatibility-tables/schemas/resource-type.d.ts +27 -0
  501. package/dist/types/compatibility-tables/schemas/scriptlet.d.ts +31 -0
  502. package/dist/types/compatibility-tables/scriptlets.d.ts +15 -0
  503. package/dist/types/compatibility-tables/types.d.ts +34 -0
  504. package/dist/types/compatibility-tables/utils/platform-helpers.d.ts +44 -0
  505. package/dist/types/compatibility-tables/utils/resource-type-helpers.d.ts +20 -0
  506. package/dist/types/compatibility-tables/utils/zod-camelcase.d.ts +15 -0
  507. package/dist/types/converter/base-interfaces/base-converter.d.ts +42 -0
  508. package/dist/types/converter/base-interfaces/conversion-result.d.ts +43 -0
  509. package/dist/types/converter/base-interfaces/rule-converter-base.d.ts +44 -0
  510. package/dist/types/converter/comment/index.d.ts +23 -0
  511. package/dist/types/converter/cosmetic/css.d.ts +23 -0
  512. package/dist/types/converter/cosmetic/element-hiding.d.ts +23 -0
  513. package/dist/types/converter/cosmetic/header-removal.d.ts +37 -0
  514. package/dist/types/converter/cosmetic/html.d.ts +54 -0
  515. package/dist/types/converter/cosmetic/index.d.ts +33 -0
  516. package/dist/types/converter/cosmetic/rule-modifiers/adg.d.ts +21 -0
  517. package/dist/types/converter/cosmetic/scriptlet.d.ts +33 -0
  518. package/dist/types/converter/css/index.d.ts +23 -0
  519. package/dist/types/converter/data/css.d.ts +48 -0
  520. package/dist/types/converter/filter-list.d.ts +31 -0
  521. package/dist/types/converter/index.d.ts +5 -0
  522. package/dist/types/converter/misc/network-rule-modifier.d.ts +35 -0
  523. package/dist/types/converter/network/index.d.ts +33 -0
  524. package/dist/types/converter/raw-filter-list.d.ts +31 -0
  525. package/dist/types/converter/raw-rule.d.ts +28 -0
  526. package/dist/types/converter/rule.d.ts +37 -0
  527. package/dist/types/deserializer/base-deserializer.d.ts +15 -0
  528. package/dist/types/deserializer/comment/agent-comment-deserializer.d.ts +34 -0
  529. package/dist/types/deserializer/comment/agent-deserializer.d.ts +25 -0
  530. package/dist/types/deserializer/comment/comment-rule-deserializer.d.ts +69 -0
  531. package/dist/types/deserializer/comment/config-comment-deserializer.d.ts +27 -0
  532. package/dist/types/deserializer/comment/hint-comment-deserializer.d.ts +24 -0
  533. package/dist/types/deserializer/comment/hint-deserializer.d.ts +26 -0
  534. package/dist/types/deserializer/comment/metadata-comment-deserializer.d.ts +26 -0
  535. package/dist/types/deserializer/comment/pre-processor-comment-deserializer.d.ts +29 -0
  536. package/dist/types/deserializer/comment/simple-comment-deserializer.d.ts +26 -0
  537. package/dist/types/deserializer/cosmetic/cosmetic-rule-deserializer.d.ts +12 -0
  538. package/dist/types/deserializer/cosmetic/css-injection-body-deserializer.d.ts +12 -0
  539. package/dist/types/deserializer/cosmetic/element-hiding-body-deserializer.d.ts +12 -0
  540. package/dist/types/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.d.ts +13 -0
  541. package/dist/types/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.d.ts +13 -0
  542. package/dist/types/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.d.ts +15 -0
  543. package/dist/types/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.d.ts +14 -0
  544. package/dist/types/deserializer/empty-rule-deserializer.d.ts +12 -0
  545. package/dist/types/deserializer/filterlist-deserializer.d.ts +30 -0
  546. package/dist/types/deserializer/index.d.ts +2 -0
  547. package/dist/types/deserializer/invalid-rule-deserializer.d.ts +12 -0
  548. package/dist/types/deserializer/invalid-rule-error-node-deserializer.d.ts +12 -0
  549. package/dist/types/deserializer/misc/domain-list-deserializer.d.ts +15 -0
  550. package/dist/types/deserializer/misc/list-item-deserializer.d.ts +13 -0
  551. package/dist/types/deserializer/misc/list-items-deserializer.d.ts +12 -0
  552. package/dist/types/deserializer/misc/logical-expression-deserializer.d.ts +55 -0
  553. package/dist/types/deserializer/misc/modifier-deserializer.d.ts +18 -0
  554. package/dist/types/deserializer/misc/modifier-list-deserializer.d.ts +20 -0
  555. package/dist/types/deserializer/misc/parameter-list-deserializer.d.ts +14 -0
  556. package/dist/types/deserializer/misc/value-deserializer.d.ts +17 -0
  557. package/dist/types/deserializer/network/host-rule-deserializer.d.ts +30 -0
  558. package/dist/types/deserializer/network/hostname-list-deserializer.d.ts +12 -0
  559. package/dist/types/deserializer/network/network-rule-deserializer.d.ts +18 -0
  560. package/dist/types/deserializer/rule-deserializer.d.ts +17 -0
  561. package/dist/types/deserializer/syntax-deserialization-map.d.ts +2 -0
  562. package/dist/types/errors/adblock-syntax-error.d.ts +25 -0
  563. package/dist/types/errors/binary-schema-mismatch-error.d.ts +23 -0
  564. package/dist/types/errors/not-implemented-error.d.ts +14 -0
  565. package/dist/types/errors/rule-conversion-error.d.ts +14 -0
  566. package/dist/types/generator/base-generator.d.ts +12 -0
  567. package/dist/types/generator/comment/agent-comment-generator.d.ts +11 -0
  568. package/dist/types/generator/comment/agent-generator.d.ts +11 -0
  569. package/dist/types/generator/comment/comment-rule-generator.d.ts +67 -0
  570. package/dist/types/generator/comment/config-comment-generator.d.ts +11 -0
  571. package/dist/types/generator/comment/hint-comment-generator.d.ts +11 -0
  572. package/dist/types/generator/comment/hint-generator.d.ts +11 -0
  573. package/dist/types/generator/comment/index.d.ts +2 -0
  574. package/dist/types/generator/comment/metadata-comment-generator.d.ts +11 -0
  575. package/dist/types/generator/comment/pre-processor-comment-generator.d.ts +11 -0
  576. package/dist/types/generator/comment/simple-comment-generator.d.ts +11 -0
  577. package/dist/types/generator/cosmetic/body/abp-snippet-injection-body-generator.d.ts +11 -0
  578. package/dist/types/generator/cosmetic/body/adg-scriptlet-injection-body-generator.d.ts +17 -0
  579. package/dist/types/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.d.ts +17 -0
  580. package/dist/types/generator/cosmetic/cosmetic-rule-body-generator.d.ts +15 -0
  581. package/dist/types/generator/cosmetic/cosmetic-rule-generator.d.ts +36 -0
  582. package/dist/types/generator/cosmetic/cosmetic-rule-pattern-generator.d.ts +15 -0
  583. package/dist/types/generator/cosmetic/index.d.ts +1 -0
  584. package/dist/types/generator/css/adg-css-injection-generator.d.ts +12 -0
  585. package/dist/types/generator/css/ubo-selector-generator.d.ts +11 -0
  586. package/dist/types/generator/filterlist-generator.d.ts +17 -0
  587. package/dist/types/generator/index.d.ts +3 -0
  588. package/dist/types/generator/misc/domain-list-generator.d.ts +12 -0
  589. package/dist/types/generator/misc/list-items-generator.d.ts +22 -0
  590. package/dist/types/generator/misc/logical-expression-generator.d.ts +11 -0
  591. package/dist/types/generator/misc/modifier-generator.d.ts +11 -0
  592. package/dist/types/generator/misc/modifier-list-generator.d.ts +11 -0
  593. package/dist/types/generator/misc/parameter-list-generator.d.ts +12 -0
  594. package/dist/types/generator/misc/value-generator.d.ts +11 -0
  595. package/dist/types/generator/network/host-rule-generator.d.ts +11 -0
  596. package/dist/types/generator/network/index.d.ts +2 -0
  597. package/dist/types/generator/network/network-rule-generator.d.ts +11 -0
  598. package/dist/types/generator/rule-generator.d.ts +21 -0
  599. package/dist/types/index.d.ts +55 -0
  600. package/dist/types/marshalling-utils/comment/agent-comment-common.d.ts +13 -0
  601. package/dist/types/marshalling-utils/comment/agent-common.d.ts +19 -0
  602. package/dist/types/marshalling-utils/comment/config-comment-common.d.ts +40 -0
  603. package/dist/types/marshalling-utils/comment/hint-comment-common.d.ts +14 -0
  604. package/dist/types/marshalling-utils/comment/hint-common.d.ts +32 -0
  605. package/dist/types/marshalling-utils/comment/metadata-comment-common.d.ts +20 -0
  606. package/dist/types/marshalling-utils/comment/pre-processor-comment-common.d.ts +36 -0
  607. package/dist/types/marshalling-utils/comment/simple-comment-common.d.ts +14 -0
  608. package/dist/types/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.d.ts +22 -0
  609. package/dist/types/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.d.ts +9 -0
  610. package/dist/types/marshalling-utils/cosmetic/body/css-injection-body-common.d.ts +16 -0
  611. package/dist/types/marshalling-utils/cosmetic/body/element-hiding-body-common.d.ts +13 -0
  612. package/dist/types/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.d.ts +9 -0
  613. package/dist/types/marshalling-utils/cosmetic/cosmetic-rule-common.d.ts +27 -0
  614. package/dist/types/marshalling-utils/empty-rule-common.d.ts +12 -0
  615. package/dist/types/marshalling-utils/filter-list-common.d.ts +13 -0
  616. package/dist/types/marshalling-utils/invalid-rule-common.d.ts +13 -0
  617. package/dist/types/marshalling-utils/invalid-rule-error-node-common.d.ts +14 -0
  618. package/dist/types/marshalling-utils/misc/binary-type-common.d.ts +56 -0
  619. package/dist/types/marshalling-utils/misc/domain-list-common.d.ts +23 -0
  620. package/dist/types/marshalling-utils/misc/host-rule-common.d.ts +17 -0
  621. package/dist/types/marshalling-utils/misc/hostname-list-common.d.ts +13 -0
  622. package/dist/types/marshalling-utils/misc/list-item-common.d.ts +14 -0
  623. package/dist/types/marshalling-utils/misc/logical-expression-common.d.ts +44 -0
  624. package/dist/types/marshalling-utils/misc/modifier-common.d.ts +40 -0
  625. package/dist/types/marshalling-utils/misc/modifier-list-common.d.ts +13 -0
  626. package/dist/types/marshalling-utils/misc/parameter-list-common.d.ts +13 -0
  627. package/dist/types/marshalling-utils/misc/value-common.d.ts +14 -0
  628. package/dist/types/marshalling-utils/network/network-rule-common.d.ts +17 -0
  629. package/dist/types/marshalling-utils/syntax-serialization-map.d.ts +2 -0
  630. package/dist/types/nodes/index.d.ts +1177 -0
  631. package/dist/types/parser/base-parser.d.ts +16 -0
  632. package/dist/types/parser/comment/agent-comment-parser.d.ts +42 -0
  633. package/dist/types/parser/comment/agent-parser.d.ts +33 -0
  634. package/dist/types/parser/comment/comment-parser.d.ts +76 -0
  635. package/dist/types/parser/comment/config-comment-parser.d.ts +31 -0
  636. package/dist/types/parser/comment/hint-comment-parser.d.ts +33 -0
  637. package/dist/types/parser/comment/hint-parser.d.ts +30 -0
  638. package/dist/types/parser/comment/metadata-comment-parser.d.ts +29 -0
  639. package/dist/types/parser/comment/preprocessor-parser.d.ts +43 -0
  640. package/dist/types/parser/comment/simple-comment-parser.d.ts +33 -0
  641. package/dist/types/parser/cosmetic/body/abp-snippet-injection-body-parser.d.ts +34 -0
  642. package/dist/types/parser/cosmetic/body/adg-scriptlet-injection-body-parser.d.ts +47 -0
  643. package/dist/types/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.d.ts +44 -0
  644. package/dist/types/parser/cosmetic/cosmetic-rule-parser.d.ts +51 -0
  645. package/dist/types/parser/css/adg-css-injection-parser.d.ts +28 -0
  646. package/dist/types/parser/css/balancing.d.ts +36 -0
  647. package/dist/types/parser/css/constants.d.ts +10 -0
  648. package/dist/types/parser/css/css-token-stream.d.ts +210 -0
  649. package/dist/types/parser/css/ubo-selector-parser.d.ts +46 -0
  650. package/dist/types/parser/filterlist-parser.d.ts +29 -0
  651. package/dist/types/parser/index.d.ts +5 -0
  652. package/dist/types/parser/misc/app-list-parser.d.ts +22 -0
  653. package/dist/types/parser/misc/domain-list-parser.d.ts +26 -0
  654. package/dist/types/parser/misc/list-items-parser.d.ts +34 -0
  655. package/dist/types/parser/misc/logical-expression-parser.d.ts +41 -0
  656. package/dist/types/parser/misc/method-list-parser.d.ts +22 -0
  657. package/dist/types/parser/misc/modifier-list.d.ts +24 -0
  658. package/dist/types/parser/misc/modifier-parser.d.ts +21 -0
  659. package/dist/types/parser/misc/parameter-list-parser.d.ts +14 -0
  660. package/dist/types/parser/misc/stealth-option-list-parser.d.ts +22 -0
  661. package/dist/types/parser/misc/ubo-parameter-list-parser.d.ts +18 -0
  662. package/dist/types/parser/misc/value-parser.d.ts +18 -0
  663. package/dist/types/parser/network/host-rule-parser.d.ts +35 -0
  664. package/dist/types/parser/network/network-rule-parser.d.ts +31 -0
  665. package/dist/types/parser/options.d.ts +41 -0
  666. package/dist/types/parser/rule-parser.d.ts +78 -0
  667. package/dist/types/serializer/base-serializer.d.ts +15 -0
  668. package/dist/types/serializer/comment/agent-comment-serializer.d.ts +34 -0
  669. package/dist/types/serializer/comment/agent-serializer.d.ts +24 -0
  670. package/dist/types/serializer/comment/comment-rule-serializer.d.ts +68 -0
  671. package/dist/types/serializer/comment/config-comment-serializer.d.ts +25 -0
  672. package/dist/types/serializer/comment/hint-comment-serializer.d.ts +23 -0
  673. package/dist/types/serializer/comment/hint-serializer.d.ts +24 -0
  674. package/dist/types/serializer/comment/metadata-comment-serializer.d.ts +25 -0
  675. package/dist/types/serializer/comment/pre-processor-comment-serializer.d.ts +28 -0
  676. package/dist/types/serializer/comment/simple-comment-serializer.d.ts +24 -0
  677. package/dist/types/serializer/cosmetic/body/abp-snippet-injection-body-serializer.d.ts +25 -0
  678. package/dist/types/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.d.ts +25 -0
  679. package/dist/types/serializer/cosmetic/body/scriptlet-body-serializer.d.ts +14 -0
  680. package/dist/types/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.d.ts +25 -0
  681. package/dist/types/serializer/cosmetic/cosmetic-rule-serializer.d.ts +26 -0
  682. package/dist/types/serializer/cosmetic/css-injection-body-serializer.d.ts +12 -0
  683. package/dist/types/serializer/cosmetic/element-hiding-body-serializer.d.ts +12 -0
  684. package/dist/types/serializer/empty-rule-serializer.d.ts +12 -0
  685. package/dist/types/serializer/filterlist-serializer.d.ts +16 -0
  686. package/dist/types/serializer/index.d.ts +1 -0
  687. package/dist/types/serializer/invalid-rule-error-node-serializer.d.ts +12 -0
  688. package/dist/types/serializer/invalid-rule-serializer.d.ts +12 -0
  689. package/dist/types/serializer/misc/domain-list-serializer.d.ts +21 -0
  690. package/dist/types/serializer/misc/list-item-serializer.d.ts +13 -0
  691. package/dist/types/serializer/misc/list-items-serializer.d.ts +12 -0
  692. package/dist/types/serializer/misc/logical-expression-serializer.d.ts +51 -0
  693. package/dist/types/serializer/misc/modifier-list-serializer.d.ts +20 -0
  694. package/dist/types/serializer/misc/modifier-serializer.d.ts +18 -0
  695. package/dist/types/serializer/misc/parameter-list-serializer.d.ts +14 -0
  696. package/dist/types/serializer/misc/value-serializer.d.ts +17 -0
  697. package/dist/types/serializer/network/host-rule-serializer.d.ts +30 -0
  698. package/dist/types/serializer/network/hostname-list-serializer.d.ts +12 -0
  699. package/dist/types/serializer/network/network-rule-serializer.d.ts +18 -0
  700. package/dist/types/serializer/rule-serializer.d.ts +17 -0
  701. package/dist/types/utils/adblockers.d.ts +48 -0
  702. package/dist/types/utils/binary-schema-version.d.ts +9 -0
  703. package/dist/types/utils/byte-buffer.d.ts +54 -0
  704. package/dist/types/utils/categorizer.d.ts +14 -0
  705. package/dist/types/utils/clone.d.ts +15 -0
  706. package/dist/types/utils/constants.d.ts +188 -0
  707. package/dist/types/utils/cosmetic-rule-separator.d.ts +45 -0
  708. package/dist/types/utils/deep-freeze.d.ts +13 -0
  709. package/dist/types/utils/domain.d.ts +26 -0
  710. package/dist/types/utils/error.d.ts +8 -0
  711. package/dist/types/utils/index.d.ts +15 -0
  712. package/dist/types/utils/input-byte-buffer.d.ts +140 -0
  713. package/dist/types/utils/is-chromium.d.ts +7 -0
  714. package/dist/types/utils/logical-expression.d.ts +45 -0
  715. package/dist/types/utils/multi-value-map.d.ts +16 -0
  716. package/dist/types/utils/output-byte-buffer.d.ts +126 -0
  717. package/dist/types/utils/position-provider.d.ts +46 -0
  718. package/dist/types/utils/quotes.d.ts +93 -0
  719. package/dist/types/utils/regexp.d.ts +54 -0
  720. package/dist/types/utils/storage-interface.d.ts +23 -0
  721. package/dist/types/utils/string.d.ts +277 -0
  722. package/dist/types/utils/text-decoder-polyfill.d.ts +14 -0
  723. package/dist/types/utils/text-encoder-polyfill.d.ts +18 -0
  724. package/dist/types/utils/type-guards.d.ts +47 -0
  725. package/dist/types/validator/constants.d.ts +89 -0
  726. package/dist/types/validator/helpers.d.ts +37 -0
  727. package/dist/types/validator/index.d.ts +38 -0
  728. package/dist/types/validator/value.d.ts +11 -0
  729. package/dist/types/version.d.ts +5 -0
  730. package/package.json +91 -37
  731. package/dist/agtree.d.ts +0 -4152
  732. package/dist/agtree.js +0 -15710
  733. package/dist/agtree.mjs +0 -15611
  734. package/dist/compatibility-table-data.js +0 -12634
package/dist/agtree.d.ts DELETED
@@ -1,4152 +0,0 @@
1
- /*
2
- * AGTree v2.1.2 (build date: Thu, 19 Sep 2024 15:44:40 GMT)
3
- * (c) 2024 Adguard Software Ltd.
4
- * Released under the MIT license
5
- * https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
6
- */
7
- import zod from 'zod';
8
-
9
- /**
10
- * @file Common options for all parsers.
11
- */
12
- /**
13
- * Common options for all parsers.
14
- */
15
- interface ParserOptions {
16
- /**
17
- * If `true`, then the parser will not throw an error if the rule is syntactically invalid, instead it will
18
- * return an `InvalidRule` object with the error attached to it.
19
- */
20
- tolerant?: boolean;
21
- /**
22
- * Whether to include location information in the AST nodes.
23
- */
24
- isLocIncluded?: boolean;
25
- /**
26
- * Whether to parse AdBlock-specific rules.
27
- */
28
- parseAbpSpecificRules?: boolean;
29
- /**
30
- * Whether to parse uBlock Origin-specific rules.
31
- */
32
- parseUboSpecificRules?: boolean;
33
- /**
34
- * Whether to parse raw parts.
35
- */
36
- includeRaws?: boolean;
37
- /**
38
- * Whether to ignore comment-rules.
39
- */
40
- ignoreComments?: boolean;
41
- /**
42
- * Whether to parse host rules.
43
- */
44
- parseHostRules?: boolean;
45
- }
46
- /**
47
- * Default parser options.
48
- */
49
- declare const defaultParserOptions: ParserOptions;
50
-
51
- /**
52
- * @file Possible adblock syntaxes are listed here.
53
- */
54
- /**
55
- * Possible adblock syntaxes (supported by this library)
56
- */
57
- declare enum AdblockSyntax {
58
- /**
59
- * Common syntax, which is supported by more than one adblocker (or by all adblockers).
60
- *
61
- * We typically use this syntax when we cannot determine the concrete syntax of the rule,
62
- * because the syntax is used by more than one adblocker natively.
63
- *
64
- * @example
65
- * - `||example.org^$important` is a common syntax, since it is used by all adblockers natively, and
66
- * we cannot determine at parsing level whether `important` is a valid option or not, and if it is valid,
67
- * then which adblocker supports it.
68
- */
69
- Common = "Common",
70
- /**
71
- * Adblock Plus syntax.
72
- *
73
- * @example
74
- * - `example.org#$#abort-on-property-read alert` is an Adblock Plus syntax, since it is not used by any other
75
- * adblockers directly (probably supported by some on-the-fly conversion, but this is not the native syntax).
76
- * @see {@link https://adblockplus.org/}
77
- */
78
- Abp = "AdblockPlus",
79
- /**
80
- * uBlock Origin syntax.
81
- *
82
- * @example
83
- * - `example.com##+js(set, atob, noopFunc)` is an uBlock Origin syntax, since it is not used by any other
84
- * adblockers directly (probably supported by some on-the-fly conversion, but this is not the native syntax).
85
- * @see {@link https://github.com/gorhill/uBlock}
86
- */
87
- Ubo = "UblockOrigin",
88
- /**
89
- * AdGuard syntax.
90
- *
91
- * @example
92
- * - `example.org#%#//scriptlet("abort-on-property-read", "alert")` is an AdGuard syntax, since it is not used
93
- * by any other adblockers directly (probably supported by some on-the-fly conversion, but this is not the native
94
- * syntax).
95
- * @see {@link https://adguard.com/}
96
- */
97
- Adg = "AdGuard"
98
- }
99
-
100
- declare const ADG_SCRIPTLET_MASK = "//scriptlet";
101
- declare const UBO_SCRIPTLET_MASK = "+js";
102
- declare const MODIFIERS_SEPARATOR = ",";
103
- declare const MODIFIER_ASSIGN_OPERATOR = "=";
104
- declare const NEGATION_MARKER = "~";
105
- /**
106
- * Classic domain separator.
107
- *
108
- * @example
109
- * ```adblock
110
- * ! Domains are separated by ",":
111
- * example.com,~example.org##.ads
112
- * ```
113
- */
114
- declare const COMMA_DOMAIN_LIST_SEPARATOR = ",";
115
- /**
116
- * Modifier separator for $app, $denyallow, $domain, $method.
117
- *
118
- * @example
119
- * ```adblock
120
- * ! Domains are separated by "|":
121
- * ads.js^$script,domains=example.com|~example.org
122
- * ```
123
- */
124
- declare const PIPE_MODIFIER_SEPARATOR = "|";
125
- declare const HINT_MARKER = "!+";
126
- declare const NETWORK_RULE_EXCEPTION_MARKER = "@@";
127
- declare const NETWORK_RULE_SEPARATOR = "$";
128
- declare const AGLINT_COMMAND_PREFIX = "aglint";
129
- declare const PREPROCESSOR_MARKER = "!#";
130
- declare const SAFARI_CB_AFFINITY = "safari_cb_affinity";
131
- declare const IF = "if";
132
- declare const INCLUDE = "include";
133
-
134
- /**
135
- * Possible operators in the logical expression.
136
- */
137
- declare const enum OperatorValue {
138
- Not = "!",
139
- And = "&&",
140
- Or = "||"
141
- }
142
- /**
143
- * Represents possible new line types.
144
- */
145
- type NewLine = 'crlf' | 'lf' | 'cr';
146
- /**
147
- * Represents any kind of logical expression node.
148
- */
149
- type AnyExpressionNode = ExpressionVariableNode | ExpressionOperatorNode | ExpressionParenthesisNode;
150
- /**
151
- * Represents any kind of adblock rule.
152
- */
153
- type AnyRule = EmptyRule | AnyCommentRule | AnyCosmeticRule | AnyNetworkRule | InvalidRule;
154
- /**
155
- * Represents any comment-like adblock rule.
156
- */
157
- type AnyCommentRule = AgentCommentRule | CommentRule | ConfigCommentRule | HintCommentRule | MetadataCommentRule | PreProcessorCommentRule;
158
- /**
159
- * Represents any cosmetic adblock rule.
160
- */
161
- type AnyCosmeticRule = CssInjectionRule | ElementHidingRule | ScriptletInjectionRule | HtmlFilteringRule | JsInjectionRule;
162
- /**
163
- * Represents any network adblock rule.
164
- */
165
- type AnyNetworkRule = NetworkRule | HostRule;
166
- /**
167
- * Represents the different comment markers that can be used in an adblock rule.
168
- *
169
- * @example
170
- * - If the rule is `! This is just a comment`, then the marker will be `!`.
171
- * - If the rule is `# This is just a comment`, then the marker will be `#`.
172
- */
173
- declare const enum CommentMarker {
174
- /**
175
- * Regular comment marker. It is supported by all ad blockers.
176
- */
177
- Regular = "!",
178
- /**
179
- * Hashmark comment marker. It is supported by uBlock Origin and AdGuard,
180
- * and also used in hosts files.
181
- */
182
- Hashmark = "#"
183
- }
184
- /**
185
- * Represents the main categories that an adblock rule can belong to.
186
- * Of course, these include additional subcategories.
187
- */
188
- declare enum RuleCategory {
189
- /**
190
- * Empty "rules" that are only containing whitespaces. These rules are handled just for convenience.
191
- */
192
- Empty = "Empty",
193
- /**
194
- * Syntactically invalid rules (tolerant mode only).
195
- */
196
- Invalid = "Invalid",
197
- /**
198
- * Comment rules, such as comment rules, metadata rules, preprocessor rules, etc.
199
- */
200
- Comment = "Comment",
201
- /**
202
- * Cosmetic rules, such as element hiding rules, CSS rules, scriptlet rules, HTML rules, and JS rules.
203
- */
204
- Cosmetic = "Cosmetic",
205
- /**
206
- * Network rules, such as basic network rules, header remover network rules, redirect network rules,
207
- * response header filtering rules, etc.
208
- */
209
- Network = "Network"
210
- }
211
- /**
212
- * Represents similar types of modifiers values
213
- * which may be separated by a comma `,` (only for DomainList) or a pipe `|`.
214
- */
215
- declare const enum ListNodeType {
216
- Unknown = "Unknown",
217
- AppList = "AppList",
218
- DomainList = "DomainList",
219
- MethodList = "MethodList",
220
- StealthOptionList = "StealthOptionList"
221
- }
222
- /**
223
- * Represents child items for {@link ListNodeType}.
224
- */
225
- declare enum ListItemNodeType {
226
- Unknown = "Unknown",
227
- App = "App",
228
- Domain = "Domain",
229
- Method = "Method",
230
- StealthOption = "StealthOption"
231
- }
232
- /**
233
- * Represents possible comment types.
234
- */
235
- declare enum CommentRuleType {
236
- AgentCommentRule = "AgentCommentRule",
237
- CommentRule = "CommentRule",
238
- ConfigCommentRule = "ConfigCommentRule",
239
- HintCommentRule = "HintCommentRule",
240
- MetadataCommentRule = "MetadataCommentRule",
241
- PreProcessorCommentRule = "PreProcessorCommentRule"
242
- }
243
- /**
244
- * Represents possible cosmetic rule types.
245
- */
246
- declare enum CosmeticRuleType {
247
- ElementHidingRule = "ElementHidingRule",
248
- CssInjectionRule = "CssInjectionRule",
249
- ScriptletInjectionRule = "ScriptletInjectionRule",
250
- HtmlFilteringRule = "HtmlFilteringRule",
251
- JsInjectionRule = "JsInjectionRule"
252
- }
253
- /**
254
- * Represents possible cosmetic rule separators.
255
- */
256
- declare const enum CosmeticRuleSeparator {
257
- /**
258
- * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
259
- */
260
- ElementHiding = "##",
261
- /**
262
- * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
263
- */
264
- ElementHidingException = "#@#",
265
- /**
266
- * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
267
- */
268
- ExtendedElementHiding = "#?#",
269
- /**
270
- * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
271
- */
272
- ExtendedElementHidingException = "#@?#",
273
- /**
274
- * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
275
- */
276
- AbpSnippet = "#$#",
277
- /**
278
- * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
279
- */
280
- AbpSnippetException = "#@$#",
281
- /**
282
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#cosmetic-css-rules}
283
- */
284
- AdgCssInjection = "#$#",
285
- /**
286
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#cosmetic-css-rules}
287
- */
288
- AdgCssInjectionException = "#@$#",
289
- /**
290
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#cosmetic-css-rules}
291
- */
292
- AdgExtendedCssInjection = "#$?#",
293
- /**
294
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#cosmetic-css-rules}
295
- */
296
- AdgExtendedCssInjectionException = "#@$?#",
297
- /**
298
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#scriptlets}
299
- */
300
- AdgJsInjection = "#%#",
301
- /**
302
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#scriptlets}
303
- */
304
- AdgJsInjectionException = "#@%#",
305
- /**
306
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#html-filtering-rules}
307
- */
308
- AdgHtmlFiltering = "$$",
309
- /**
310
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#html-filtering-rules}
311
- */
312
- AdgHtmlFilteringException = "$@$"
313
- }
314
- /**
315
- * Represents a basic node in the AST.
316
- */
317
- interface Node {
318
- /**
319
- * The type of the node. Every node should have a type.
320
- */
321
- type: string;
322
- /**
323
- * Optionally the raw representation of the node in the source code.
324
- */
325
- raw?: string;
326
- /**
327
- * Start offset of the node.
328
- */
329
- start?: number;
330
- /**
331
- * End offset of the node.
332
- */
333
- end?: number;
334
- }
335
- /**
336
- * Represents a location in the source code.
337
- */
338
- interface Location {
339
- /**
340
- * Zero-based index of the first character of the parsed source region.
341
- */
342
- offset: number;
343
- /**
344
- * One-based line index of the first character of the parsed source region.
345
- */
346
- line: number;
347
- /**
348
- * One-based column index of the first character of the parsed source region.
349
- */
350
- column: number;
351
- }
352
- /**
353
- * Represents a location range in the source code.
354
- */
355
- interface LocationRange {
356
- /**
357
- * The start location of the node.
358
- */
359
- start: Location;
360
- /**
361
- * The end location of the node.
362
- */
363
- end: Location;
364
- }
365
- /**
366
- * Represents a basic value node in the AST.
367
- */
368
- interface Value<T = string> extends Node {
369
- type: 'Value';
370
- /**
371
- * Value of the node.
372
- */
373
- value: T;
374
- }
375
- /**
376
- * Represents a list of parameters.
377
- */
378
- interface ParameterList extends Node {
379
- type: 'ParameterList';
380
- /**
381
- * List of values
382
- *
383
- * @note `null` values are allowed in the list, they represent empty parameters.
384
- */
385
- children: (Value | null)[];
386
- }
387
- /**
388
- * Represents a logical expression variable node in the AST.
389
- */
390
- interface ExpressionVariableNode extends Node {
391
- type: 'Variable';
392
- name: string;
393
- }
394
- /**
395
- * Represents a logical expression operator node in the AST.
396
- */
397
- interface ExpressionOperatorNode extends Node {
398
- type: 'Operator';
399
- operator: OperatorValue;
400
- left: AnyExpressionNode;
401
- right?: AnyExpressionNode;
402
- }
403
- /**
404
- * Represents a logical expression parenthesis node in the AST.
405
- */
406
- interface ExpressionParenthesisNode extends Node {
407
- type: 'Parenthesis';
408
- expression: AnyExpressionNode;
409
- }
410
- /**
411
- * Represents a filter list (list of rules).
412
- */
413
- interface FilterList extends Node {
414
- type: 'FilterList';
415
- /**
416
- * List of rules
417
- */
418
- children: AnyRule[];
419
- }
420
- /**
421
- * Represents a basic adblock rule. Every adblock rule should extend this interface.
422
- * We don't use this interface directly, so we don't specify the `type` property.
423
- */
424
- interface RuleBase extends Node {
425
- /**
426
- * Syntax of the adblock rule. If we are not able to determine the syntax of the rule,
427
- * we should use `AdblockSyntax.Common` as the value.
428
- */
429
- syntax: AdblockSyntax;
430
- /**
431
- * Category of the adblock rule
432
- */
433
- category: RuleCategory;
434
- /**
435
- * Raw data of the rule
436
- */
437
- raws?: {
438
- /**
439
- * Original rule text
440
- */
441
- text?: string;
442
- /**
443
- * Newline character used in the rule (if any)
444
- */
445
- nl?: NewLine;
446
- };
447
- }
448
- interface InvalidRuleError extends Node {
449
- type: 'InvalidRuleError';
450
- /**
451
- * Error name
452
- */
453
- name: string;
454
- /**
455
- * Error message
456
- */
457
- message: string;
458
- }
459
- /**
460
- * Represents an invalid rule (used by tolerant mode).
461
- */
462
- interface InvalidRule extends RuleBase {
463
- type: 'InvalidRule';
464
- /**
465
- * Category of the adblock rule
466
- */
467
- category: RuleCategory.Invalid;
468
- /**
469
- * Raw rule text
470
- */
471
- raw: string;
472
- /**
473
- * Error details
474
- */
475
- error: InvalidRuleError;
476
- }
477
- /**
478
- * Represents an "empty rule" (practically an empty line)
479
- */
480
- interface EmptyRule extends RuleBase {
481
- /**
482
- * Type of the adblock rule (should be always present)
483
- */
484
- type: 'EmptyRule';
485
- /**
486
- * Category of the adblock rule
487
- */
488
- category: RuleCategory.Empty;
489
- }
490
- /**
491
- * Represents the basic comment rule interface.
492
- */
493
- interface CommentBase extends RuleBase {
494
- category: RuleCategory.Comment;
495
- type: CommentRuleType;
496
- }
497
- /**
498
- * Represents a simple comment.
499
- *
500
- * @example
501
- * Example rules:
502
- * - ```adblock
503
- * ! This is just a comment
504
- * ```
505
- * - ```adblock
506
- * # This is just a comment
507
- * ```
508
- */
509
- interface CommentRule extends CommentBase {
510
- type: CommentRuleType.CommentRule;
511
- /**
512
- * Comment marker.
513
- *
514
- * @example
515
- * - If the rule is `! This is just a comment`, then the marker will be `!`.
516
- * - If the rule is `# This is just a comment`, then the marker will be `#`.
517
- */
518
- marker: Value;
519
- /**
520
- * Comment text.
521
- *
522
- * @example
523
- * If the rule is `! This is just a comment`, then the text will be `This is just a comment`.
524
- */
525
- text: Value;
526
- }
527
- /**
528
- * Represents a metadata comment rule. This is a special comment that specifies
529
- * the name and value of the metadata header.
530
- *
531
- * @example
532
- * For example, in the case of
533
- * ```adblock
534
- * ! Title: My List
535
- * ```
536
- * the name of the header is `Title`, and the value is `My List`.
537
- */
538
- interface MetadataCommentRule extends CommentBase {
539
- type: CommentRuleType.MetadataCommentRule;
540
- /**
541
- * Comment marker.
542
- */
543
- marker: Value;
544
- /**
545
- * Metadata header name.
546
- */
547
- header: Value;
548
- /**
549
- * Metadata header value (always should present).
550
- */
551
- value: Value;
552
- }
553
- /**
554
- * Represents an AGLint configuration node.
555
- *
556
- * Used within config comments.
557
- *
558
- * @example
559
- * ```adblock
560
- * ! aglint "rule-1": ["warn", { "option1": "value1" }], "rule-2": "off"
561
- * ! ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
562
- * ```
563
- */
564
- interface ConfigNode extends Node {
565
- type: 'ConfigNode';
566
- value: object;
567
- }
568
- /**
569
- * Represents an inline linter configuration comment.
570
- *
571
- * @example
572
- * For example, if the comment is
573
- * ```adblock
574
- * ! aglint-disable some-rule another-rule
575
- * ```
576
- * then the command is `aglint-disable` and its params is `["some-rule", "another-rule"]`.
577
- */
578
- interface ConfigCommentRule extends CommentBase {
579
- category: RuleCategory.Comment;
580
- type: CommentRuleType.ConfigCommentRule;
581
- /**
582
- * The marker for the comment. It can be `!` or `#`. It is always the first non-whitespace character in the comment.
583
- */
584
- marker: Value;
585
- /**
586
- * The command for the comment. It is always begins with the `aglint` prefix.
587
- *
588
- * @example
589
- * ```adblock
590
- * ! aglint-disable-next-line
591
- * ```
592
- */
593
- command: Value;
594
- /**
595
- * Params for the command. Can be a rule configuration object or a list of rule names.
596
- *
597
- * @example
598
- * For the following comment:
599
- * ```adblock
600
- * ! aglint-disable some-rule another-rule
601
- * ```
602
- * the params would be `["some-rule", "another-rule"]`.
603
- */
604
- params?: ConfigNode | ParameterList;
605
- /**
606
- * Config comment text. The idea is generally the same as in ESLint.
607
- *
608
- * @example
609
- * You can use the following syntax to specify a comment for a config comment:
610
- * `! aglint-enable -- this is the comment`
611
- */
612
- comment?: Value;
613
- }
614
- /**
615
- * Represents a preprocessor comment.
616
- *
617
- * @example
618
- * For example, if the comment is
619
- * ```adblock
620
- * !#if (adguard)
621
- * ```
622
- * then the directive's name is `if` and its value is `(adguard)`.
623
- *
624
- * In such a case, the parameters must be submitted for further parsing and validation, as this parser only handles
625
- * the general syntax.
626
- */
627
- interface PreProcessorCommentRule extends CommentBase {
628
- category: RuleCategory.Comment;
629
- type: CommentRuleType.PreProcessorCommentRule;
630
- /**
631
- * Name of the directive
632
- */
633
- name: Value;
634
- /**
635
- * Params (optional)
636
- */
637
- params?: Value | ParameterList | AnyExpressionNode;
638
- }
639
- /**
640
- * Represents an adblock agent.
641
- */
642
- interface Agent extends Node {
643
- type: 'Agent';
644
- /**
645
- * Adblock name.
646
- */
647
- adblock: Value;
648
- /**
649
- * Adblock version (if specified).
650
- */
651
- version?: Value;
652
- /**
653
- * Needed for network rules modifier validation.
654
- */
655
- syntax: AdblockSyntax;
656
- }
657
- /**
658
- * Represents an agent comment rule.
659
- *
660
- * @example
661
- * - ```adblock
662
- * [Adblock Plus 2.0]
663
- * ```
664
- * - ```adblock
665
- * [uBlock Origin 1.16.4; AdGuard 1.0]
666
- * ```
667
- */
668
- interface AgentCommentRule extends RuleBase {
669
- category: RuleCategory.Comment;
670
- type: CommentRuleType.AgentCommentRule;
671
- /**
672
- * Agent list.
673
- */
674
- children: Agent[];
675
- }
676
- /**
677
- * Represents a hint.
678
- *
679
- * @example
680
- * ```adblock
681
- * !+ PLATFORM(windows, mac)
682
- * ```
683
- * the name would be `PLATFORM` and the params would be `["windows", "mac"]`.
684
- */
685
- interface Hint extends Node {
686
- type: 'Hint';
687
- /**
688
- * Hint name.
689
- *
690
- * @example
691
- * For `PLATFORM(windows, mac)` the name would be `PLATFORM`.
692
- */
693
- name: Value;
694
- /**
695
- * Hint parameters.
696
- *
697
- * @example
698
- * For `PLATFORM(windows, mac)` the params would be `["windows", "mac"]`.
699
- */
700
- params?: ParameterList;
701
- }
702
- /**
703
- * Represents a hint comment rule.
704
- *
705
- * There can be several hints in a hint rule.
706
- *
707
- * @example
708
- * If the rule is
709
- * ```adblock
710
- * !+ NOT_OPTIMIZED PLATFORM(windows)
711
- * ```
712
- * then there are two hint members: `NOT_OPTIMIZED` and `PLATFORM`.
713
- */
714
- interface HintCommentRule extends RuleBase {
715
- category: RuleCategory.Comment;
716
- type: CommentRuleType.HintCommentRule;
717
- /**
718
- * Currently only AdGuard supports hints.
719
- */
720
- syntax: AdblockSyntax;
721
- /**
722
- * List of hints.
723
- */
724
- children: Hint[];
725
- }
726
- /**
727
- * Represents a modifier list.
728
- *
729
- * @example
730
- * If the rule is
731
- * ```adblock
732
- * some-rule$script,domain=example.com
733
- * ```
734
- * then the list of modifiers will be `script,domain=example.com`.
735
- */
736
- interface ModifierList extends Node {
737
- type: 'ModifierList';
738
- /**
739
- * List of modifiers.
740
- */
741
- children: Modifier[];
742
- }
743
- /**
744
- * Represents a modifier.
745
- *
746
- * @example
747
- * If the modifier is `third-party`, the value of the modifier property
748
- * will be `third-party`, but the value will remain undefined.
749
- *
750
- * But if the modifier is `domain=example.com`, then the modifier property will be
751
- * `domain` and the value property will be `example.com`.
752
- */
753
- interface Modifier extends Node {
754
- /**
755
- * Modifier name
756
- */
757
- name: Value;
758
- /**
759
- * Is this modifier an exception? For example, `~third-party` is an exception
760
- */
761
- exception?: boolean;
762
- /**
763
- * Modifier value (optional)
764
- */
765
- value?: Value;
766
- }
767
- /**
768
- * Represents the separator used for various modifier values.
769
- *
770
- * @example
771
- * `||example.com^$app=com.test1.app|TestApp.exe`
772
- */
773
- type PipeSeparator = typeof PIPE_MODIFIER_SEPARATOR;
774
- /**
775
- * Represents the separator used for basic rules domain list.
776
- *
777
- * @example
778
- * `example.com,example.org###banner`
779
- */
780
- type CommaSeparator = typeof COMMA_DOMAIN_LIST_SEPARATOR;
781
- /**
782
- * Represents the separator used in a domain list.
783
- *
784
- * @example
785
- * - `,` — for the classic domain list,
786
- * - `|` — for the $domain modifier value
787
- */
788
- type DomainListSeparator = CommaSeparator | PipeSeparator;
789
- /**
790
- * Common interface for a list item of $app, $denyallow, $domain, $method
791
- * which have similar syntax.
792
- */
793
- interface ListItem<T extends ListItemNodeType> extends Node {
794
- type: T;
795
- /**
796
- * Value of the node.
797
- */
798
- value: string;
799
- /**
800
- * If the value is an negated.
801
- *
802
- * @example
803
- * `~example.com` is negated, but `example.com` is not. `~` is the exception marker here.
804
- */
805
- exception: boolean;
806
- }
807
- /**
808
- * Represents an element of the app list — $app.
809
- */
810
- type App = ListItem<ListItemNodeType.App>;
811
- /**
812
- * Represents an element of the domain list — $domain, $denyallow.
813
- */
814
- type Domain = ListItem<ListItemNodeType.Domain>;
815
- /**
816
- * Represents an element of the method list — $method.
817
- */
818
- type Method = ListItem<ListItemNodeType.Method>;
819
- /**
820
- * Represents an element of the stealth option list — $stealth.
821
- */
822
- type StealthOption = ListItem<ListItemNodeType.StealthOption>;
823
- /**
824
- * Represents a list of domains.
825
- * Needed for $domain and $denyallow.
826
- *
827
- * @example
828
- * `example.com,~example.net` or `example.com|~example.net`
829
- */
830
- interface DomainList extends Node {
831
- /**
832
- * Type of the node. Basically, the idea is that each main AST part should have a type
833
- */
834
- type: ListNodeType.DomainList;
835
- /**
836
- * Separator used in the domain list.
837
- */
838
- separator: DomainListSeparator;
839
- /**
840
- * List of domains
841
- */
842
- children: Domain[];
843
- }
844
- /**
845
- * Represents a list of apps.
846
- * Needed for $app.
847
- *
848
- * @example
849
- * `Example.exe|com.example.osx`.
850
- */
851
- interface AppList extends Node {
852
- /**
853
- * Type of the node. Basically, the idea is that each main AST part should have a type
854
- */
855
- type: ListNodeType.AppList;
856
- /**
857
- * Separator used in the app list.
858
- */
859
- separator: PipeSeparator;
860
- /**
861
- * List of apps
862
- */
863
- children: App[];
864
- }
865
- /**
866
- * Represents a list of methods.
867
- * Needed for $method.
868
- *
869
- * @example
870
- * `get|post|put`.
871
- */
872
- interface MethodList extends Node {
873
- /**
874
- * Type of the node. Basically, the idea is that each main AST part should have a type
875
- */
876
- type: ListNodeType.MethodList;
877
- /**
878
- * Separator used in the method list.
879
- */
880
- separator: PipeSeparator;
881
- /**
882
- * List of methods
883
- */
884
- children: Method[];
885
- }
886
- /**
887
- * Represents a list of stealth options.
888
- * Needed for $stealth.
889
- *
890
- * @example
891
- * `referrer|ip`.
892
- */
893
- interface StealthOptionList extends Node {
894
- /**
895
- * Type of the node. Basically, the idea is that each main AST part should have a type
896
- */
897
- type: ListNodeType.StealthOptionList;
898
- /**
899
- * Separator used in the stealth option list.
900
- */
901
- separator: PipeSeparator;
902
- /**
903
- * List of stealth options
904
- */
905
- children: StealthOption[];
906
- }
907
- /**
908
- * Represents a CSS injection body.
909
- */
910
- interface CssInjectionRuleBody extends Node {
911
- type: 'CssInjectionRuleBody';
912
- /**
913
- * Media query, if any.
914
- *
915
- * @example
916
- *
917
- * ```text
918
- * @media (max-width: 768px) { ... }
919
- * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
920
- * ```
921
- */
922
- mediaQueryList?: Value;
923
- /**
924
- * CSS selector list.
925
- *
926
- * @example
927
- * section:has(> .ad) { display: none; }
928
- * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
929
- * section:has(> .ad), article > p[advert] { display: none; }
930
- * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
931
- */
932
- selectorList: Value;
933
- /**
934
- * Declaration list.
935
- *
936
- * @example
937
- * section:has(> .ad) { display: none; }
938
- * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑
939
- * section:has(> .ad), article > p[advert] { display: none; }
940
- * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑
941
- * div[ad] { padding-top: 10px; padding-bottom: 10px; }
942
- * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
943
- */
944
- declarationList?: Value;
945
- /**
946
- * Remove flag
947
- */
948
- remove?: boolean;
949
- }
950
- /**
951
- * Represents an element hiding rule body. There can even be several selectors in a rule,
952
- * but the best practice is to place the selectors in separate rules.
953
- */
954
- interface ElementHidingRuleBody extends Node {
955
- type: 'ElementHidingRuleBody';
956
- /**
957
- * Element hiding rule selector(s).
958
- */
959
- selectorList: Value;
960
- }
961
- /**
962
- * Represents a scriptlet injection rule body.
963
- */
964
- interface ScriptletInjectionRuleBody extends Node {
965
- type: 'ScriptletInjectionRuleBody';
966
- /**
967
- * List of scriptlets (list of parameter lists).
968
- */
969
- children: ParameterList[];
970
- }
971
- /**
972
- * Represents an HTML filtering rule body.
973
- */
974
- interface HtmlFilteringRuleBody extends Node {
975
- type: 'HtmlFilteringRuleBody';
976
- /**
977
- * HTML rule selector(s).
978
- */
979
- body: Value;
980
- }
981
- /**
982
- * A generic representation of a cosmetic rule.
983
- *
984
- * Regarding the categories, there is only a difference in the body,
985
- * all other properties can be defined at this level.
986
- */
987
- interface CosmeticRule extends RuleBase {
988
- category: RuleCategory.Cosmetic;
989
- type: CosmeticRuleType;
990
- /**
991
- * List of modifiers (optional)
992
- */
993
- modifiers?: ModifierList;
994
- /**
995
- * List of domains.
996
- */
997
- domains: DomainList;
998
- /**
999
- * Separator between pattern and body. For example, in the following rule:
1000
- * ```adblock
1001
- * example.com##.ads
1002
- * ```
1003
- * then the separator is `##`.
1004
- */
1005
- separator: Value;
1006
- /**
1007
- * If the rule is an exception. For example, in the following rule:
1008
- * ```adblock
1009
- * example.com#@#.ads
1010
- * ```
1011
- * then the rule is an exception and @ is the exception marker.
1012
- */
1013
- exception: boolean;
1014
- /**
1015
- * Body of the rule. It can be a CSS rule, an element hiding rule, a scriptlet rule, etc.
1016
- */
1017
- body: unknown;
1018
- }
1019
- /**
1020
- * Representation of an element hiding rule.
1021
- *
1022
- * Example rules:
1023
- * - ```adblock
1024
- * example.com##.ads
1025
- * ```
1026
- * - ```adblock
1027
- * example.com#@#.ads
1028
- * ```
1029
- * - ```adblock
1030
- * example.com#?#.ads:has(> .something)
1031
- * ```
1032
- * - ```adblock
1033
- * example.com#@?#.ads:has(> .something)
1034
- * ```
1035
- */
1036
- interface ElementHidingRule extends CosmeticRule {
1037
- type: CosmeticRuleType.ElementHidingRule;
1038
- body: ElementHidingRuleBody;
1039
- }
1040
- /**
1041
- * Representation of a CSS injection rule.
1042
- *
1043
- * Example rules (AdGuard):
1044
- * - ```adblock
1045
- * example.com#$#body { padding-top: 0 !important; }
1046
- * ```
1047
- * - ```adblock
1048
- * example.com#$#@media (min-width: 1024px) { body { padding-top: 0 !important; } }
1049
- * ```
1050
- * - ```adblock
1051
- * example.com#$?#@media (min-width: 1024px) { .something:has(.ads) { padding-top: 0 !important; } }
1052
- * ```
1053
- * - ```adblock
1054
- * example.com#$#.ads { remove: true; }
1055
- * ```
1056
- *
1057
- * Example rules (uBlock Origin):
1058
- * - ```adblock
1059
- * example.com##body:style(padding-top: 0 !important;)
1060
- * ```
1061
- * - ```adblock
1062
- * example.com##.ads:remove()
1063
- * ```
1064
- */
1065
- interface CssInjectionRule extends CosmeticRule {
1066
- type: CosmeticRuleType.CssInjectionRule;
1067
- body: CssInjectionRuleBody;
1068
- }
1069
- /**
1070
- * Representation of a scriptlet injection rule.
1071
- *
1072
- * Example rules (AdGuard):
1073
- * - ```adblock
1074
- * example.com#%#//scriptlet('scriptlet-name', 'arg0', 'arg1')
1075
- * ```
1076
- * - ```adblock
1077
- * example.com#@%#//scriptlet('scriptlet-name', 'arg0', 'arg1')
1078
- * ```
1079
- *
1080
- * Example rules (uBlock Origin):
1081
- * - ```adblock
1082
- * example.com##+js(scriptlet-name, arg0, arg1)
1083
- * ```
1084
- * - ```adblock
1085
- * example.com#@#+js(scriptlet-name, arg0, arg1)
1086
- * ```
1087
- *
1088
- * Example rules (Adblock Plus):
1089
- * - ```adblock
1090
- * example.com#$#scriptlet-name arg0 arg1
1091
- * ```
1092
- * - ```adblock
1093
- * example.com#@$#scriptlet-name arg0 arg1
1094
- * ```
1095
- * - ```adblock
1096
- * example.com#$#scriptlet0 arg00 arg01; scriptlet1 arg10 arg11
1097
- * ```
1098
- */
1099
- interface ScriptletInjectionRule extends CosmeticRule {
1100
- type: CosmeticRuleType.ScriptletInjectionRule;
1101
- body: ScriptletInjectionRuleBody;
1102
- }
1103
- /**
1104
- * Representation of a HTML filtering rule.
1105
- *
1106
- * Example rules (AdGuard):
1107
- * - ```adblock
1108
- * example.com$$script[tag-content="detect"]
1109
- * ```
1110
- * - ```adblock
1111
- * example.com$@$script[tag-content="detect"]
1112
- * ```
1113
- *
1114
- * Example rules (uBlock Origin):
1115
- * - ```adblock
1116
- * example.com##^script:has-text(detect)
1117
- * ```
1118
- * - ```adblock
1119
- * example.com#@#^script:has-text(detect)
1120
- * ```
1121
- */
1122
- interface HtmlFilteringRule extends CosmeticRule {
1123
- type: CosmeticRuleType.HtmlFilteringRule;
1124
- body: Value;
1125
- }
1126
- /**
1127
- * Representation of a JS injection rule.
1128
- *
1129
- * Example rules (AdGuard):
1130
- * - ```adblock
1131
- * example.com#%#let a = 2;
1132
- * ```
1133
- * - ```adblock
1134
- * example.com#@%#let a = 2;
1135
- * ```
1136
- */
1137
- interface JsInjectionRule extends CosmeticRule {
1138
- type: CosmeticRuleType.JsInjectionRule;
1139
- body: Value;
1140
- }
1141
- /**
1142
- * Represents the different types of network rules.
1143
- */
1144
- declare enum NetworkRuleType {
1145
- NetworkRule = "NetworkRule",
1146
- HostRule = "HostRule"
1147
- }
1148
- /**
1149
- * Represents the common properties of network rules
1150
- */
1151
- interface NetworkRuleBase extends RuleBase {
1152
- /**
1153
- * Category of the adblock rule.
1154
- */
1155
- category: RuleCategory.Network;
1156
- /**
1157
- * Type of the network rule.
1158
- */
1159
- type: NetworkRuleType;
1160
- /**
1161
- * Syntax of the adblock rule. If we are not able to determine the syntax of the rule,
1162
- * we should use `AdblockSyntax.Common` as the value.
1163
- */
1164
- syntax: AdblockSyntax;
1165
- }
1166
- /**
1167
- * Represents the common properties of network rules
1168
- */
1169
- interface NetworkRule extends NetworkRuleBase {
1170
- /**
1171
- * Type of the node.
1172
- */
1173
- type: NetworkRuleType.NetworkRule;
1174
- /**
1175
- * If the rule is an exception rule. If the rule begins with `@@`, it means that it is an exception rule.
1176
- *
1177
- * @example
1178
- * The following rule is an exception rule:
1179
- * ```adblock
1180
- * @@||example.org^
1181
- * ```
1182
- * since it begins with `@@`, which is the exception marker.
1183
- *
1184
- * But the following rule is not an exception rule:
1185
- * ```adblock
1186
- * ||example.org^
1187
- * ```
1188
- * since it does not begins with `@@`.
1189
- */
1190
- exception: boolean;
1191
- /**
1192
- * The rule pattern.
1193
- *
1194
- * @example
1195
- * - Let's say we have the following rule:
1196
- * ```adblock
1197
- * ||example.org^
1198
- * ```
1199
- * then the pattern of this rule is `||example.org^`.
1200
- * - But let's say we have the following rule:
1201
- * ```adblock
1202
- * ||example.org^$third-party,script
1203
- * ```
1204
- * then the pattern of this rule is also `||example.org^`.
1205
- */
1206
- pattern: Value;
1207
- /**
1208
- * The rule modifiers.
1209
- *
1210
- * @example
1211
- * - Let's say we have the following rule:
1212
- * ```adblock
1213
- * ||example.org^$third-party
1214
- * ```
1215
- * then the modifiers of this rule are `["third-party"]`.
1216
- */
1217
- modifiers?: ModifierList;
1218
- }
1219
- /**
1220
- * Represents a list of hostnames.
1221
- */
1222
- interface HostnameList extends Node {
1223
- /**
1224
- * Type of the node.
1225
- */
1226
- type: 'HostnameList';
1227
- /**
1228
- * List of hostnames.
1229
- */
1230
- children: Value[];
1231
- }
1232
- /**
1233
- * Represents the common properties of host rules.
1234
- *
1235
- * @see https://adguard-dns.io/kb/general/dns-filtering-syntax/#etc-hosts-syntax
1236
- */
1237
- interface HostRule extends NetworkRuleBase {
1238
- /**
1239
- * Type of the node.
1240
- */
1241
- type: NetworkRuleType.HostRule;
1242
- /**
1243
- * IP address. It can be an IPv4 or IPv6 address.
1244
- *
1245
- * @example
1246
- * ```text
1247
- * 127.0.0.1 example.com example.org
1248
- * ↑↑↑↑↑↑↑↑↑
1249
- * ```
1250
- * @note If IP is not specified in the rule, it parsed as null IP: `0.0.0.0`.
1251
- */
1252
- ip: Value;
1253
- /**
1254
- * Hostnames.
1255
- *
1256
- * @example
1257
- * ```text
1258
- * 127.0.0.1 example.com example.org
1259
- * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
1260
- * ```
1261
- */
1262
- hostnames: HostnameList;
1263
- /**
1264
- * Comment (optional).
1265
- *
1266
- * @example
1267
- * ```text
1268
- * 127.0.0.1 localhost # This is just a comment
1269
- * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
1270
- * ```
1271
- */
1272
- comment?: Value;
1273
- }
1274
-
1275
- /**
1276
- * @file Core ByteBuffer implementation for handling binary data in chunks.
1277
- */
1278
- /**
1279
- * Core ByteBuffer implementation for handling binary data in chunks.
1280
- * This class allows for efficient byte storage and manipulation by organizing data into chunks
1281
- * and providing methods to read and write bytes.
1282
- */
1283
- declare class ByteBuffer {
1284
- /**
1285
- * The size of each chunk in bytes (32 KB).
1286
- */
1287
- static readonly CHUNK_SIZE = 32768;
1288
- /**
1289
- * An array of Uint8Array chunks that make up the buffer.
1290
- */
1291
- protected chunks: Uint8Array[];
1292
- /**
1293
- * The total number of chunks in the buffer.
1294
- */
1295
- protected chunksLength: number;
1296
- /**
1297
- * Constructs a new ByteBuffer instance.
1298
- *
1299
- * @param chunks Optional array of chunks to initialize the ByteBuffer with.
1300
- * @param cloneChunks Flag indicating if the chunks should be cloned. For performance reasons,
1301
- * its default value is `false`. If the original chunks are guaranteed not to change,
1302
- * leave this flag as `false` to avoid unnecessary copying.
1303
- */
1304
- constructor(chunks?: Uint8Array[], cloneChunks?: boolean);
1305
- /**
1306
- * Ensures that the buffer has enough capacity to accommodate a given position.
1307
- * This method adjusts the `chunks` array size to ensure it can hold the specified position.
1308
- *
1309
- * @param position The position to ensure capacity for.
1310
- */
1311
- protected ensureCapacity(position: number): void;
1312
- /**
1313
- * Writes a byte to the buffer at the specified position.
1314
- * If the position is outside of the buffer's current size, the buffer is resized to accommodate it.
1315
- *
1316
- * @param position The position at which to write the byte.
1317
- * @param value The byte value to write (0-255).
1318
- */
1319
- protected writeByte(position: number, value: number): void;
1320
- /**
1321
- * Reads a byte from the specified position in the buffer.
1322
- * Returns `undefined` if the position is outside of the buffer's current size.
1323
- *
1324
- * @param position The position from which to read the byte.
1325
- * @returns The read byte value, or `undefined` if the position is out of bounds.
1326
- */
1327
- protected readByte(position: number): number | undefined;
1328
- }
1329
-
1330
- /**
1331
- * @file Represents a storage interface for reading and writing data.
1332
- */
1333
- /**
1334
- * Represents a storage interface for reading and writing data.
1335
- */
1336
- interface Storage<K = string, V = unknown> {
1337
- /**
1338
- * Writes the given data to the storage with the specified key.
1339
- *
1340
- * @param key The key to identify the data in the storage.
1341
- * @param chunks The data to write to the storage.
1342
- * @returns A promise that resolves when the write operation is complete.
1343
- */
1344
- set(key: K, data: V): Promise<void>;
1345
- /**
1346
- * Reads the data from the storage with the specified key.
1347
- *
1348
- * @param key The key to identify the data in the storage.
1349
- * @returns A promise that resolves with the data read from the storage.
1350
- */
1351
- get(key: K): Promise<V | undefined>;
1352
- }
1353
-
1354
- /**
1355
- * @file Input byte buffer for reading binary data.
1356
- */
1357
-
1358
- /**
1359
- * Input byte buffer for reading binary data.
1360
- *
1361
- * @note Internally, this class uses a {@link ByteBuffer} instance, just providing a convenient API for reading data.
1362
- */
1363
- declare class InputByteBuffer extends ByteBuffer {
1364
- /**
1365
- * Current offset in the buffer for reading.
1366
- */
1367
- private offset;
1368
- /**
1369
- * Shared native decoder for decoding strings.
1370
- */
1371
- private readonly sharedNativeDecoder;
1372
- /**
1373
- * Flag indicating if the current environment is Chromium.
1374
- * This is used for performance optimizations, because Chromium's TextEncoder/TextDecoder has a relatively
1375
- * large marshalling overhead for small strings.
1376
- */
1377
- private readonly isChromium;
1378
- /**
1379
- * Constructs a new `InputByteBuffer` instance.
1380
- *
1381
- * @param chunks Array of chunks to initialize the ByteBuffer with.
1382
- * @param cloneChunks Flag indicating if the chunks should be cloned. For performance reasons,
1383
- * its default value is `false`. If the original chunks are guaranteed not to change,
1384
- * leave this flag as `false` to avoid unnecessary copying.
1385
- * @param initialOffset Initial offset in the buffer for reading.
1386
- *
1387
- * @throws If the specified chunks array is empty.
1388
- * @throws If the binary schema version in the buffer is not equal to the expected version.
1389
- * @throws If the initial offset is out of bounds.
1390
- */
1391
- constructor(chunks: Uint8Array[], cloneChunks?: boolean, initialOffset?: number);
1392
- /**
1393
- * Creates a new InputByteBuffer instance from a Storage instance by reading chunks from the storage.
1394
- *
1395
- * @param storage Storage instance.
1396
- * @param key Key to read from the storage.
1397
- * @returns New InputByteBuffer instance.
1398
- * @note For performance reasons, chunks are passed by reference and not copied.
1399
- */
1400
- static createFromStorage(storage: Storage, key: string): Promise<InputByteBuffer>;
1401
- /**
1402
- * Reads a 8-bit unsigned integer from the buffer.
1403
- *
1404
- * @returns 8-bit unsigned integer from the buffer.
1405
- */
1406
- readUint8(): number;
1407
- /**
1408
- * Reads a 16-bit unsigned integer from the buffer.
1409
- *
1410
- * @returns 16-bit unsigned integer from the buffer.
1411
- */
1412
- readUint16(): number;
1413
- /**
1414
- * Reads a 32-bit unsigned integer from the buffer at the specified index.
1415
- *
1416
- * @param index Index to read the 32-bit unsigned integer from.
1417
- *
1418
- * @returns 32-bit unsigned integer from the buffer.
1419
- */
1420
- private readUint32FromIndex;
1421
- /**
1422
- * Reads a 32-bit unsigned integer from the buffer.
1423
- *
1424
- * @returns 32-bit unsigned integer from the buffer.
1425
- */
1426
- readUint32(): number;
1427
- /**
1428
- * Reads schema version from the buffer.
1429
- *
1430
- * @returns 32-bit unsigned integer from the buffer.
1431
- * @note Schema version is always stored at the beginning of the buffer.
1432
- */
1433
- readSchemaVersion(): number;
1434
- /**
1435
- * Reads a 32-bit signed integer from the buffer.
1436
- *
1437
- * @returns 32-bit signed integer from the buffer.
1438
- */
1439
- readInt32(): number;
1440
- /**
1441
- * Reads an optimized unsigned integer from the buffer.
1442
- * 'Optimized' means that the integer is stored in a variable number of bytes, depending on its value,
1443
- * so that smaller numbers occupy less space.
1444
- *
1445
- * @returns Decoded unsigned integer from the buffer.
1446
- */
1447
- readOptimizedUint(): number;
1448
- /**
1449
- * Reads a string from the buffer.
1450
- *
1451
- * @returns Decoded string from the buffer.
1452
- */
1453
- readString(): string;
1454
- /**
1455
- * Reads a 8-bit unsigned integer from the buffer without advancing the offset.
1456
- *
1457
- * @returns 8-bit unsigned integer from the buffer.
1458
- */
1459
- peekUint8(): number;
1460
- /**
1461
- * Helper method for asserting the next 8-bit unsigned integer in the buffer.
1462
- *
1463
- * @param value Expected value.
1464
- * @throws If the next value in the buffer is not equal to the expected value.
1465
- */
1466
- assertUint8(value: number): void;
1467
- /**
1468
- * Creates a new `InputByteBuffer` instance with the given initial offset.
1469
- *
1470
- * @param initialOffset Initial offset for the new buffer.
1471
- * @param cloneChunks Flag indicating if the chunks should be cloned. For performance reasons,
1472
- * its default value is `false`. If the original chunks are guaranteed not to change,
1473
- * leave this flag as `false` to avoid unnecessary copying.
1474
- *
1475
- * @returns New `InputByteBuffer` instance with the given initial offset.
1476
- *
1477
- * @note This method is useful if you want to read some data from a specific index.
1478
- */
1479
- createCopyWithOffset(initialOffset: number, cloneChunks?: boolean): InputByteBuffer;
1480
- /**
1481
- * Gets the current offset in the buffer for reading.
1482
- *
1483
- * @returns Current offset in the buffer for reading.
1484
- */
1485
- get currentOffset(): number;
1486
- /**
1487
- * Gets the capacity of the buffer.
1488
- *
1489
- * @returns Capacity of the buffer.
1490
- */
1491
- get capacity(): number;
1492
- }
1493
-
1494
- /**
1495
- * Output byte buffer for writing binary data.
1496
- *
1497
- * @note Internally, this class uses a {@link ByteBuffer} instance, just providing a convenient API for reading data.
1498
- */
1499
- declare class OutputByteBuffer extends ByteBuffer {
1500
- /**
1501
- * Current offset in the buffer for writing.
1502
- */
1503
- private offset;
1504
- /**
1505
- * Size of the shared buffer for encoding strings in bytes.
1506
- * This is a divisor of ByteBuffer.CHUNK_SIZE and experience shows that this value works optimally.
1507
- * This is sufficient for most strings that occur in filter lists (we checked average string length in popular
1508
- * filter lists).
1509
- */
1510
- private static readonly ENCODER_BUFFER_SIZE;
1511
- /**
1512
- * Length threshold for using a shared buffer for encoding strings.
1513
- * This temp buffer is needed because we write the short strings in it
1514
- * (so there is no need to constantly allocate a new buffer).
1515
- * The reason for dividing ENCODER_BUFFER_SIZE by 4 is to ensure that the encoded string fits in the buffer,
1516
- * if we also take into account the worst possible case (each character is encoded with 4 bytes).
1517
- */
1518
- private static readonly SHORT_STRING_THRESHOLD;
1519
- /**
1520
- * Represents the maximum value that can be written as a 'storage optimized' unsigned integer.
1521
- * 0x1FFFFFFF means 29 bits — 32 bits minus 3 bits — because the last bit in each byte is a flag indicating
1522
- * if there are more bytes (except for the last byte).
1523
- */
1524
- static MAX_OPTIMIZED_UINT: number;
1525
- /**
1526
- * Shared buffer for encoding strings.
1527
- */
1528
- private readonly sharedBuffer;
1529
- /**
1530
- * Shared native encoder for encoding strings.
1531
- */
1532
- private readonly sharedNativeEncoder;
1533
- /**
1534
- * Flag indicating if the current environment is Chromium.
1535
- * This is used for performance optimizations, because Chromium's TextEncoder/TextDecoder has a relatively
1536
- * large marshalling overhead for small strings.
1537
- */
1538
- private readonly isChromium;
1539
- /**
1540
- * Constructs a new OutputByteBuffer instance.
1541
- */
1542
- constructor();
1543
- /**
1544
- * Writes a 8-bit unsigned integer to the buffer.
1545
- *
1546
- * @param value Value to write.
1547
- * @returns Number of bytes written to the buffer.
1548
- */
1549
- writeUint8(value: number): number;
1550
- /**
1551
- * Writes a 16-bit unsigned integer to the buffer.
1552
- *
1553
- * @param value Value to write.
1554
- * @returns Number of bytes written to the buffer.
1555
- */
1556
- writeUint16(value: number): number;
1557
- /**
1558
- * Writes a 32-bit unsigned integer to the buffer at a specific index.
1559
- *
1560
- * @param value Value to write.
1561
- * @param index Index to write the value to.
1562
- * @returns Number of bytes written to the buffer.
1563
- */
1564
- private writeUint32ToIndex;
1565
- /**
1566
- * Writes a 32-bit unsigned integer to the buffer.
1567
- *
1568
- * @param value Value to write.
1569
- * @returns Number of bytes written to the buffer.
1570
- */
1571
- writeUint32(value: number): number;
1572
- /**
1573
- * Writes a 32-bit signed integer to the buffer.
1574
- *
1575
- * @param value Value to write.
1576
- * @returns Number of bytes written to the buffer.
1577
- */
1578
- writeInt32(value: number): number;
1579
- /**
1580
- * Writes a Uint8Array to the byte buffer.
1581
- *
1582
- * @param buffer Buffer to write.
1583
- */
1584
- private writeBuffer;
1585
- /**
1586
- * Writes a string to the buffer.
1587
- *
1588
- * @param value Value to write.
1589
- * @returns Number of bytes written to the buffer.
1590
- */
1591
- writeString(value: string): number;
1592
- /**
1593
- * Writes chunks to the storage.
1594
- *
1595
- * @param storage Storage to write the chunks to.
1596
- * @param key Key to write the chunks to.
1597
- * @note For performance reasons, chunks are passed by reference and not copied.
1598
- * @throws If the storage write operation throws.
1599
- */
1600
- writeChunksToStorage(storage: Storage, key: string): Promise<void>;
1601
- /**
1602
- * Writes an 'optimized' unsigned integer to the buffer.
1603
- * 'Optimized' means smaller storage usage for smaller numbers.
1604
- * Except for the last byte, each byte's most significant bit is a flag indicating if there are more bytes.
1605
- *
1606
- * @param value Value to write.
1607
- * @returns Number of bytes written to the buffer.
1608
- * @throws If the value exceeds the 29-bit limit.
1609
- */
1610
- writeOptimizedUint(value: number): number;
1611
- /**
1612
- * Gets the current offset in the buffer for writing.
1613
- *
1614
- * @returns Current offset in the buffer for writing.
1615
- */
1616
- get currentOffset(): number;
1617
- }
1618
-
1619
- /**
1620
- * Base class for parsers. Each parser should extend this class.
1621
- */
1622
- declare class ParserBase {
1623
- /**
1624
- * Parses the input string and returns the AST node.
1625
- *
1626
- * @param input Input string to parse.
1627
- * @param options Parser options, see {@link ParserOptions}.
1628
- * @param baseOffset Base offset. Locations in the AST node will be relative to this offset.
1629
- * @param args Additional, parser-specific arguments, if needed.
1630
- */
1631
- static parse(input: string, options: ParserOptions, baseOffset: number, ...args: unknown[]): Node | null;
1632
- /**
1633
- * Generates a string from the AST node.
1634
- *
1635
- * @param node AST node to generate a string from.
1636
- */
1637
- static generate(node: Node): string;
1638
- /**
1639
- * Serializes the AST node to a byte buffer.
1640
- *
1641
- * @param node AST node to serialize.
1642
- * @param buffer Output byte buffer to write to.
1643
- * @param args Additional, parser-specific arguments, if needed.
1644
- */
1645
- static serialize(node: Node, buffer: OutputByteBuffer, ...args: unknown[]): void;
1646
- /**
1647
- * Deserializes the AST node from a byte buffer.
1648
- *
1649
- * @param buffer Input byte buffer to read from.
1650
- * @param node Destination node to write to.
1651
- * @param args Additional, parser-specific arguments, if needed.
1652
- */
1653
- static deserialize(buffer: InputByteBuffer, node: Partial<Node>, ...args: unknown[]): void;
1654
- }
1655
-
1656
- /**
1657
- * `RuleParser` is responsible for parsing the rules.
1658
- *
1659
- * It automatically determines the category and syntax of the rule, so you can pass any kind of rule to it.
1660
- */
1661
- declare class RuleParser extends ParserBase {
1662
- /**
1663
- * Helper method to parse host rules if the `parseHostRules` option is enabled, otherwise it will
1664
- * parse network rules.
1665
- *
1666
- * @param raw Raw input to parse.
1667
- * @param options Global parser options.
1668
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1669
- * @returns Host rule or network rule node.
1670
- */
1671
- private static parseHostOrNetworkRule;
1672
- /**
1673
- * Parse an adblock rule. You can pass any kind of rule to this method, since it will automatically determine
1674
- * the category and syntax. If the rule is syntactically invalid, then an error will be thrown. If the
1675
- * syntax / compatibility cannot be determined clearly, then the value of the `syntax` property will be
1676
- * `Common`.
1677
- *
1678
- * For example, let's have this network rule:
1679
- * ```adblock
1680
- * ||example.org^$important
1681
- * ```
1682
- * The `syntax` property will be `Common`, since the rule is syntactically correct in every adblockers, but we
1683
- * cannot determine at parsing level whether `important` is an existing option or not, nor if it exists, then
1684
- * which adblocker supports it. This is why the `syntax` property is simply `Common` at this point.
1685
- * The concrete COMPATIBILITY of the rule will be determined later, in a different, higher-level layer, called
1686
- * "Compatibility table".
1687
- *
1688
- * But we can determinate the concrete syntax of this rule:
1689
- * ```adblock
1690
- * example.org#%#//scriptlet("scriptlet0", "arg0")
1691
- * ```
1692
- * since it is clearly an AdGuard-specific rule and no other adblockers uses this syntax natively. However, we also
1693
- * cannot determine the COMPATIBILITY of this rule, as it is not clear at this point whether the `scriptlet0`
1694
- * scriptlet is supported by AdGuard or not. This is also the task of the "Compatibility table". Here, we simply
1695
- * mark the rule with the `AdGuard` syntax in this case.
1696
- *
1697
- * @param raw Raw input to parse.
1698
- * @param options Global parser options.
1699
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1700
- * @returns Adblock rule node
1701
- * @throws If the input matches a pattern but syntactically invalid
1702
- * @example
1703
- * Take a look at the following example:
1704
- * ```js
1705
- * // Parse a network rule
1706
- * const ast1 = RuleParser.parse("||example.org^$important");
1707
- *
1708
- * // Parse another network rule
1709
- * const ast2 = RuleParser.parse("/ads.js^$important,third-party,domain=example.org|~example.com");
1710
- *
1711
- * // Parse a cosmetic rule
1712
- * const ast2 = RuleParser.parse("example.org##.banner");
1713
- *
1714
- * // Parse another cosmetic rule
1715
- * const ast3 = RuleParser.parse("example.org#?#.banner:-abp-has(.ad)");
1716
- *
1717
- * // Parse a comment rule
1718
- * const ast4 = RuleParser.parse("! Comment");
1719
- *
1720
- * // Parse an empty rule
1721
- * const ast5 = RuleParser.parse("");
1722
- *
1723
- * // Parse a comment rule (with metadata)
1724
- * const ast6 = RuleParser.parse("! Title: Example");
1725
- *
1726
- * // Parse a pre-processor rule
1727
- * const ast7 = RuleParser.parse("!#if (adguard)");
1728
- * ```
1729
- */
1730
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): AnyRule;
1731
- /**
1732
- * Converts a rule AST to a string.
1733
- *
1734
- * @param ast - Adblock rule AST
1735
- * @returns Raw string
1736
- * @example
1737
- * Take a look at the following example:
1738
- * ```js
1739
- * // Parse the rule to the AST
1740
- * const ast = RuleParser.parse("example.org##.banner");
1741
- * // Generate the rule from the AST
1742
- * const raw = RuleParser.generate(ast);
1743
- * // Print the generated rule
1744
- * console.log(raw); // "example.org##.banner"
1745
- * ```
1746
- */
1747
- static generate(ast: AnyRule): string;
1748
- /**
1749
- * Serializes an empty rule node to binary format.
1750
- *
1751
- * @param node Node to serialize.
1752
- * @param buffer ByteBuffer for writing binary data.
1753
- */
1754
- static serializeEmptyRule(node: EmptyRule, buffer: OutputByteBuffer): void;
1755
- /**
1756
- * Deserializes an empty rule node from binary format.
1757
- *
1758
- * @param buffer ByteBuffer for reading binary data.
1759
- * @param node Destination node.
1760
- */
1761
- static deserializeEmptyRule(buffer: InputByteBuffer, node: EmptyRule): void;
1762
- /**
1763
- * Serializes an invalid rule error node to binary format.
1764
- *
1765
- * @param node Node to serialize.
1766
- * @param buffer ByteBuffer for writing binary data.
1767
- */
1768
- static serializeInvalidRuleErrorNode(node: InvalidRuleError, buffer: OutputByteBuffer): void;
1769
- /**
1770
- * Deserializes an invalid rule error node from binary format.
1771
- *
1772
- * @param buffer ByteBuffer for reading binary data.
1773
- * @param node Destination node.
1774
- */
1775
- static deserializeInvalidRuleErrorNode(buffer: InputByteBuffer, node: Partial<InvalidRuleError>): void;
1776
- /**
1777
- * Serializes an invalid rule node to binary format.
1778
- *
1779
- * @param node Node to serialize.
1780
- * @param buffer ByteBuffer for writing binary data.
1781
- */
1782
- static serializeInvalidRule(node: InvalidRule, buffer: OutputByteBuffer): void;
1783
- /**
1784
- * Deserializes an invalid rule node from binary format.
1785
- *
1786
- * @param buffer ByteBuffer for reading binary data.
1787
- * @param node Destination node.
1788
- */
1789
- static deserializeInvalidRule(buffer: InputByteBuffer, node: InvalidRule): void;
1790
- /**
1791
- * Serializes a rule node to binary format.
1792
- *
1793
- * @param node Node to serialize.
1794
- * @param buffer ByteBuffer for writing binary data.
1795
- */
1796
- static serialize(node: AnyRule, buffer: OutputByteBuffer): void;
1797
- /**
1798
- * Deserializes a rule node from binary format.
1799
- *
1800
- * @param buffer ByteBuffer for reading binary data.
1801
- * @param node Destination node.
1802
- */
1803
- static deserialize(buffer: InputByteBuffer, node: Partial<AnyRule>): void;
1804
- }
1805
-
1806
- /**
1807
- * @file Customized syntax error class for Adblock Filter Parser.
1808
- */
1809
- /**
1810
- * Customized syntax error class for Adblock Filter Parser,
1811
- * which contains the location range of the error.
1812
- */
1813
- declare class AdblockSyntaxError extends SyntaxError {
1814
- /**
1815
- * Start offset of the error.
1816
- */
1817
- start: number;
1818
- /**
1819
- * End offset of the error.
1820
- */
1821
- end: number;
1822
- /**
1823
- * Constructs a new `AdblockSyntaxError` instance.
1824
- *
1825
- * @param message Error message.
1826
- * @param start Start offset of the error.
1827
- * @param end End offset of the error.
1828
- */
1829
- constructor(message: string, start: number, end: number);
1830
- }
1831
-
1832
- /**
1833
- * `AgentParser` is responsible for parsing an Adblock agent rules.
1834
- * Adblock agent comment marks that the filter list is supposed to
1835
- * be used by the specified ad blockers.
1836
- *
1837
- * @example
1838
- * - ```adblock
1839
- * [AdGuard]
1840
- * ```
1841
- * - ```adblock
1842
- * [Adblock Plus 2.0]
1843
- * ```
1844
- * - ```adblock
1845
- * [uBlock Origin]
1846
- * ```
1847
- * - ```adblock
1848
- * [uBlock Origin 1.45.3]
1849
- * ```
1850
- * - ```adblock
1851
- * [Adblock Plus 2.0; AdGuard]
1852
- * ```
1853
- */
1854
- declare class AgentCommentRuleParser extends ParserBase {
1855
- /**
1856
- * Checks if the raw rule is an adblock agent comment.
1857
- *
1858
- * @param raw Raw rule
1859
- * @returns `true` if the rule is an adblock agent, `false` otherwise
1860
- */
1861
- static isAgentRule(raw: string): boolean;
1862
- /**
1863
- * Parses a raw rule as an adblock agent comment.
1864
- *
1865
- * @param raw Raw input to parse.
1866
- * @param options Global parser options.
1867
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1868
- * @returns Agent rule AST or null (if the raw rule cannot be parsed as an adblock agent comment)
1869
- */
1870
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): AgentCommentRule | null;
1871
- /**
1872
- * Converts an adblock agent AST to a string.
1873
- *
1874
- * @param ast Agent rule AST
1875
- * @returns Raw string
1876
- */
1877
- static generate(ast: AgentCommentRule): string;
1878
- /**
1879
- * Serializes an adblock agent list node to binary format.
1880
- *
1881
- * @param node Node to serialize.
1882
- * @param buffer ByteBuffer for writing binary data.
1883
- */
1884
- static serialize(node: AgentCommentRule, buffer: OutputByteBuffer): void;
1885
- /**
1886
- * Deserializes an agent list node from binary format.
1887
- *
1888
- * @param buffer ByteBuffer for reading binary data.
1889
- * @param node Destination node.
1890
- */
1891
- static deserialize(buffer: InputByteBuffer, node: Partial<AgentCommentRule>): void;
1892
- }
1893
-
1894
- /**
1895
- * `AgentParser` is responsible for parsing single adblock agent elements.
1896
- *
1897
- * @example
1898
- * If the adblock agent rule is
1899
- * ```adblock
1900
- * [Adblock Plus 2.0; AdGuard]
1901
- * ```
1902
- * then the adblock agents are `Adblock Plus 2.0` and `AdGuard`, and this
1903
- * class is responsible for parsing them. The rule itself is parsed by
1904
- * `AgentCommentRuleParser`, which uses this class to parse single agents.
1905
- */
1906
- declare class AgentParser extends ParserBase {
1907
- /**
1908
- * Checks if the string is a valid version.
1909
- *
1910
- * @param str String to check
1911
- * @returns `true` if the string is a valid version, `false` otherwise
1912
- */
1913
- private static isValidVersion;
1914
- /**
1915
- * Parses a raw rule as an adblock agent comment.
1916
- *
1917
- * @param raw Raw input to parse.
1918
- * @param options Global parser options.
1919
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1920
- * @returns Agent rule AST
1921
- * @throws {AdblockSyntaxError} If the raw rule cannot be parsed as an adblock agent
1922
- */
1923
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): Agent;
1924
- /**
1925
- * Converts an adblock agent node to a string.
1926
- *
1927
- * @param value Agent node
1928
- * @returns Raw string
1929
- */
1930
- static generate(value: Agent): string;
1931
- /**
1932
- * Serializes an agent node to binary format.
1933
- *
1934
- * @param node Node to serialize.
1935
- * @param buffer ByteBuffer for writing binary data.
1936
- */
1937
- static serialize(node: Agent, buffer: OutputByteBuffer): void;
1938
- /**
1939
- * Deserializes an agent node from binary format.
1940
- *
1941
- * @param buffer ByteBuffer for reading binary data.
1942
- * @param node Destination node.
1943
- * @throws If the binary data is malformed.
1944
- */
1945
- static deserialize(buffer: InputByteBuffer, node: Partial<Agent>): void;
1946
- }
1947
-
1948
- /**
1949
- * `CommentParser` is responsible for parsing any comment-like adblock rules.
1950
- *
1951
- * @example
1952
- * Example rules:
1953
- * - Adblock agent rules:
1954
- * - ```adblock
1955
- * [AdGuard]
1956
- * ```
1957
- * - ```adblock
1958
- * [Adblock Plus 2.0]
1959
- * ```
1960
- * - etc.
1961
- * - AdGuard hint rules:
1962
- * - ```adblock
1963
- * !+ NOT_OPTIMIZED
1964
- * ```
1965
- * - ```adblock
1966
- * !+ NOT_OPTIMIZED PLATFORM(windows)
1967
- * ```
1968
- * - etc.
1969
- * - Pre-processor rules:
1970
- * - ```adblock
1971
- * !#if (adguard)
1972
- * ```
1973
- * - ```adblock
1974
- * !#endif
1975
- * ```
1976
- * - etc.
1977
- * - Metadata rules:
1978
- * - ```adblock
1979
- * ! Title: My List
1980
- * ```
1981
- * - ```adblock
1982
- * ! Version: 2.0.150
1983
- * ```
1984
- * - etc.
1985
- * - AGLint inline config rules:
1986
- * - ```adblock
1987
- * ! aglint-enable some-rule
1988
- * ```
1989
- * - ```adblock
1990
- * ! aglint-disable some-rule
1991
- * ```
1992
- * - etc.
1993
- * - Simple comments:
1994
- * - Regular version:
1995
- * ```adblock
1996
- * ! This is just a comment
1997
- * ```
1998
- * - uBlock Origin / "hostlist" version:
1999
- * ```adblock
2000
- * # This is just a comment
2001
- * ```
2002
- * - etc.
2003
- */
2004
- declare class CommentRuleParser extends ParserBase {
2005
- /**
2006
- * Checks whether a rule is a comment.
2007
- *
2008
- * @param raw Raw rule
2009
- * @returns `true` if the rule is a comment, `false` otherwise
2010
- */
2011
- static isCommentRule(raw: string): boolean;
2012
- /**
2013
- * Parses a raw rule as comment.
2014
- *
2015
- * @param raw Raw input to parse.
2016
- * @param options Global parser options.
2017
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2018
- * @returns Comment AST or null (if the raw rule cannot be parsed as comment)
2019
- */
2020
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): AnyCommentRule | null;
2021
- /**
2022
- * Converts a comment rule node to a string.
2023
- *
2024
- * @param node Comment rule node
2025
- * @returns Raw string
2026
- */
2027
- static generate(node: AnyCommentRule): string;
2028
- /**
2029
- * Serializes a comment rule node to binary format.
2030
- *
2031
- * @param node Node to serialize.
2032
- * @param buffer ByteBuffer for writing binary data.
2033
- */
2034
- static serialize(node: AnyCommentRule, buffer: OutputByteBuffer): void;
2035
- /**
2036
- * Deserializes a comment rule node from binary format.
2037
- *
2038
- * @param buffer ByteBuffer for reading binary data.
2039
- * @param node Destination node.
2040
- * @throws If the binary data is malformed.
2041
- */
2042
- static deserialize(buffer: InputByteBuffer, node: Partial<AnyCommentRule>): void;
2043
- }
2044
-
2045
- /**
2046
- * `ConfigCommentParser` is responsible for parsing inline AGLint configuration rules.
2047
- * Generally, the idea is inspired by ESLint inline configuration comments.
2048
- *
2049
- * @see {@link https://eslint.org/docs/latest/user-guide/configuring/rules#using-configuration-comments}
2050
- */
2051
- declare class ConfigCommentRuleParser extends ParserBase {
2052
- /**
2053
- * Checks if the raw rule is an inline configuration comment rule.
2054
- *
2055
- * @param raw Raw rule
2056
- * @returns `true` if the rule is an inline configuration comment rule, otherwise `false`.
2057
- */
2058
- static isConfigComment(raw: string): boolean;
2059
- /**
2060
- * Parses a raw rule as an inline configuration comment.
2061
- *
2062
- * @param raw Raw input to parse.
2063
- * @param options Global parser options.
2064
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2065
- * @returns
2066
- * Inline configuration comment AST or null (if the raw rule cannot be parsed as configuration comment)
2067
- */
2068
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): ConfigCommentRule | null;
2069
- /**
2070
- * Converts an inline configuration comment node to a string.
2071
- *
2072
- * @param node Inline configuration comment node
2073
- * @returns Raw string
2074
- */
2075
- static generate(node: ConfigCommentRule): string;
2076
- /**
2077
- * Serializes a config node to binary format.
2078
- *
2079
- * @param node Node to serialize.
2080
- * @param buffer ByteBuffer for writing binary data.
2081
- */
2082
- private static serializeConfigNode;
2083
- /**
2084
- * Deserializes a metadata comment node from binary format.
2085
- *
2086
- * @param buffer ByteBuffer for reading binary data.
2087
- * @param node Destination node.
2088
- * @throws If the binary data is malformed.
2089
- */
2090
- private static deserializeConfigNode;
2091
- /**
2092
- * Serializes a metadata comment node to binary format.
2093
- *
2094
- * @param node Node to serialize.
2095
- * @param buffer ByteBuffer for writing binary data.
2096
- */
2097
- static serialize(node: ConfigCommentRule, buffer: OutputByteBuffer): void;
2098
- /**
2099
- * Deserializes a metadata comment node from binary format.
2100
- *
2101
- * @param buffer ByteBuffer for reading binary data.
2102
- * @param node Destination node.
2103
- * @throws If the binary data is malformed.
2104
- */
2105
- static deserialize(buffer: InputByteBuffer, node: Partial<ConfigCommentRule>): void;
2106
- }
2107
-
2108
- /**
2109
- * `CosmeticRuleParser` is responsible for parsing cosmetic rules.
2110
- *
2111
- * Where possible, it automatically detects the difference between supported syntaxes:
2112
- * - AdGuard
2113
- * - uBlock Origin
2114
- * - Adblock Plus
2115
- *
2116
- * If the syntax is common / cannot be determined, the parser gives `Common` syntax.
2117
- *
2118
- * Please note that syntactically correct rules are parsed even if they are not actually
2119
- * compatible with the given adblocker. This is a completely natural behavior, meaningful
2120
- * checking of compatibility is not done at the parser level.
2121
- */
2122
- declare class CosmeticRuleParser extends ParserBase {
2123
- /**
2124
- * Determines whether a rule is a cosmetic rule. The rule is considered cosmetic if it
2125
- * contains a cosmetic rule separator.
2126
- *
2127
- * @param raw Raw rule
2128
- * @returns `true` if the rule is a cosmetic rule, `false` otherwise
2129
- */
2130
- static isCosmeticRule(raw: string): boolean;
2131
- /**
2132
- * Parses a cosmetic rule. The structure of the cosmetic rules:
2133
- * - pattern (AdGuard pattern can have modifiers, other syntaxes don't)
2134
- * - separator
2135
- * - body
2136
- *
2137
- * @param raw Raw input to parse.
2138
- * @param options Global parser options.
2139
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2140
- * @returns
2141
- * Parsed cosmetic rule AST or null if it failed to parse based on the known cosmetic rules
2142
- * @throws If the input matches the cosmetic rule pattern but syntactically invalid
2143
- */
2144
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): AnyCosmeticRule | null;
2145
- /**
2146
- * Generates the rule pattern from the AST.
2147
- *
2148
- * @param node Cosmetic rule node
2149
- * @returns Raw rule pattern
2150
- * @example
2151
- * - '##.foo' → ''
2152
- * - 'example.com,example.org##.foo' → 'example.com,example.org'
2153
- * - '[$path=/foo/bar]example.com##.foo' → '[$path=/foo/bar]example.com'
2154
- */
2155
- static generatePattern(node: AnyCosmeticRule): string;
2156
- /**
2157
- * Generates the rule body from the node.
2158
- *
2159
- * @param node Cosmetic rule node
2160
- * @returns Raw rule body
2161
- * @example
2162
- * - '##.foo' → '.foo'
2163
- * - 'example.com,example.org##.foo' → '.foo'
2164
- * - 'example.com#%#//scriptlet('foo')' → '//scriptlet('foo')'
2165
- */
2166
- static generateBody(node: AnyCosmeticRule): string;
2167
- /**
2168
- * Converts a cosmetic rule AST into a string.
2169
- *
2170
- * @param node Cosmetic rule AST
2171
- * @returns Raw string
2172
- */
2173
- static generate(node: AnyCosmeticRule): string;
2174
- /**
2175
- * Serializes an element hiding rule body node to binary format.
2176
- *
2177
- * @param node Node to serialize.
2178
- * @param buffer ByteBuffer for writing binary data.
2179
- */
2180
- private static serializeElementHidingBody;
2181
- /**
2182
- * Deserializes an element hiding rule body node from binary format.
2183
- *
2184
- * @param buffer ByteBuffer for reading binary data.
2185
- * @param node Destination node.
2186
- */
2187
- private static deserializeElementHidingBody;
2188
- /**
2189
- * Serializes a CSS injection rule body node to binary format.
2190
- *
2191
- * @param node Node to serialize.
2192
- * @param buffer ByteBuffer for writing binary data.
2193
- */
2194
- private static serializeCssInjectionBody;
2195
- /**
2196
- * Deserializes CSS injection rule body node from binary format.
2197
- *
2198
- * @param buffer ByteBuffer for reading binary data.
2199
- * @param node Destination node.
2200
- */
2201
- private static deserializeCssInjectionBody;
2202
- /**
2203
- * Serializes a cosmetic rule node to binary format.
2204
- *
2205
- * @param node Node to serialize.
2206
- * @param buffer ByteBuffer for writing binary data.
2207
- */
2208
- static serialize(node: AnyCosmeticRule, buffer: OutputByteBuffer): void;
2209
- /**
2210
- * Deserializes a cosmetic rule node from binary format.
2211
- *
2212
- * @param buffer ByteBuffer for reading binary data.
2213
- * @param node Destination node.
2214
- */
2215
- static deserialize(buffer: InputByteBuffer, node: Partial<AnyCosmeticRule>): void;
2216
- }
2217
-
2218
- /**
2219
- * `AppListParser` is responsible for parsing an app list.
2220
- *
2221
- * @see {@link https://adguard.app/kb/general/ad-filtering/create-own-filters/#app-modifier}
2222
- */
2223
- declare class AppListParser extends ParserBase {
2224
- /**
2225
- * Parses an app list which items are separated by `|`,
2226
- * e.g. `Example.exe|com.example.osx`.
2227
- *
2228
- * @param raw Raw input to parse.
2229
- * @param options Global parser options.
2230
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2231
- *
2232
- * @returns App list AST.
2233
- * @throws An {@link AdblockSyntaxError} if the app list is syntactically invalid.
2234
- * @throws An {@link Error} if the options are invalid.
2235
- */
2236
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): AppList;
2237
- }
2238
-
2239
- /**
2240
- * `DomainListParser` is responsible for parsing a domain list.
2241
- *
2242
- * @example
2243
- * - If the rule is `example.com,~example.net##.ads`, the domain list is `example.com,~example.net`.
2244
- * - If the rule is `ads.js^$script,domains=example.com|~example.org`, the domain list is `example.com|~example.org`.
2245
- * This parser is responsible for parsing these domain lists.
2246
- * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_domains}
2247
- */
2248
- declare class DomainListParser extends ParserBase {
2249
- /**
2250
- * Parses a domain list, eg. `example.com,example.org,~example.org`
2251
- *
2252
- * @param raw Raw input to parse.
2253
- * @param options Global parser options.
2254
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2255
- * @param separator Separator character (default: comma)
2256
- *
2257
- * @returns Domain list AST.
2258
- * @throws An {@link AdblockSyntaxError} if the domain list is syntactically invalid.
2259
- * @throws An {@link Error} if the options are invalid.
2260
- */
2261
- static parse(raw: string, options?: ParserOptions, baseOffset?: number, separator?: string): DomainList;
2262
- /**
2263
- * Converts a domain list node to a string.
2264
- *
2265
- * @param node Domain list node.
2266
- *
2267
- * @returns Raw string.
2268
- */
2269
- static generate(node: DomainList): string;
2270
- /**
2271
- * Serializes a domain list node to binary format.
2272
- *
2273
- * @param node Node to serialize.
2274
- * @param buffer ByteBuffer for writing binary data.
2275
- */
2276
- static serialize(node: DomainList, buffer: OutputByteBuffer): void;
2277
- /**
2278
- * Deserializes a modifier list node from binary format.
2279
- *
2280
- * @param buffer ByteBuffer for reading binary data.
2281
- * @param node Destination node.
2282
- */
2283
- static deserialize(buffer: InputByteBuffer, node: DomainList): void;
2284
- }
2285
-
2286
- /**
2287
- * `MethodListParser` is responsible for parsing a method list.
2288
- *
2289
- * @see {@link https://adguard.app/kb/general/ad-filtering/create-own-filters/#method-modifier}
2290
- */
2291
- declare class MethodListParser extends ParserBase {
2292
- /**
2293
- * Parses a method list which items are separated by `|`,
2294
- * e.g. `get|post|put`.
2295
- *
2296
- * @param raw Raw input to parse.
2297
- * @param options Global parser options.
2298
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2299
- *
2300
- * @returns Method list AST.
2301
- * @throws An {@link AdblockSyntaxError} if the method list is syntactically invalid.
2302
- * @throws An {@link Error} if the options are invalid.
2303
- */
2304
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): MethodList;
2305
- }
2306
-
2307
- /**
2308
- * `StealthOptionListParser` is responsible for parsing a list of stealth options.
2309
- *
2310
- * @see {@link https://adguard.app/kb/general/ad-filtering/create-own-filters/#stealth-modifier}
2311
- */
2312
- declare class StealthOptionListParser extends ParserBase {
2313
- /**
2314
- * Parses a stealth option list which items are separated by `|`,
2315
- * e.g. `dpi|ip`.
2316
- *
2317
- * @param raw Raw input to parse.
2318
- * @param options Global parser options.
2319
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2320
- *
2321
- * @returns Stealth option list AST.
2322
- * @throws An {@link AdblockSyntaxError} if the stealth option list is syntactically invalid.
2323
- * @throws An {@link Error} if the options are invalid.
2324
- */
2325
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): StealthOptionList;
2326
- }
2327
-
2328
- /**
2329
- * `FilterListParser` is responsible for parsing a whole adblock filter list (list of rules).
2330
- * It is a wrapper around `RuleParser` which parses each line separately.
2331
- */
2332
- declare class FilterListParser extends ParserBase {
2333
- /**
2334
- * Parses a whole adblock filter list (list of rules).
2335
- *
2336
- * @param raw Raw input to parse.
2337
- * @param options Global parser options.
2338
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2339
- * @returns AST of the source code (list of rules)
2340
- * @example
2341
- * ```js
2342
- * import { readFileSync } from 'fs';
2343
- * import { FilterListParser } from '@adguard/agtree';
2344
- *
2345
- * // Read filter list content from file
2346
- * const content = readFileSync('your-adblock-filter-list.txt', 'utf-8');
2347
- *
2348
- * // Parse the filter list content, then do something with the AST
2349
- * const ast = FilterListParser.parse(content);
2350
- * ```
2351
- * @throws If one of the rules is syntactically invalid (if `tolerant` is `false`)
2352
- */
2353
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): FilterList;
2354
- /**
2355
- * Serializes a whole adblock filter list (list of rules).
2356
- *
2357
- * @param ast AST to generate
2358
- * @param preferRaw If `true`, then the parser will use `raws.text` property of each rule
2359
- * if it is available. Default is `false`.
2360
- * @returns Serialized filter list
2361
- */
2362
- static generate(ast: FilterList, preferRaw?: boolean): string;
2363
- /**
2364
- * Serializes a filter list node to binary format.
2365
- *
2366
- * @param node Node to serialize.
2367
- * @param buffer ByteBuffer for writing binary data.
2368
- */
2369
- static serialize(node: FilterList, buffer: OutputByteBuffer): void;
2370
- /**
2371
- * Deserializes a filter list node from binary format.
2372
- *
2373
- * @param buffer ByteBuffer for reading binary data.
2374
- * @param node Destination node.
2375
- */
2376
- static deserialize(buffer: InputByteBuffer, node: Partial<FilterList>): void;
2377
- /**
2378
- * Helper method to jump to the children of the filter list node.
2379
- *
2380
- * Filter lists serialized in binary format are structured as follows:
2381
- * - `FilterListNode` filter list node indicator (1 byte)
2382
- * - Properties:
2383
- * - `Children` (1 byte) - children count, followed by children nodes
2384
- * - `Start` (1 byte) - start offset, if present, followed by the value
2385
- * - `End` (1 byte) - end offset, if present, followed by the value
2386
- * - `NULL` (1 byte) - closing indicator
2387
- *
2388
- * This method skips indicators, reads the children count and returns it.
2389
- * This way the buffer is positioned at the beginning of the children nodes.
2390
- *
2391
- * @param buffer Reference to the input byte buffer.
2392
- * @returns Number of children nodes.
2393
- */
2394
- static jumpToChildren(buffer: InputByteBuffer): number;
2395
- }
2396
-
2397
- /**
2398
- * `HintRuleParser` is responsible for parsing AdGuard hint rules.
2399
- *
2400
- * @example
2401
- * The following hint rule
2402
- * ```adblock
2403
- * !+ NOT_OPTIMIZED PLATFORM(windows)
2404
- * ```
2405
- * contains two hints: `NOT_OPTIMIZED` and `PLATFORM`.
2406
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#hints}
2407
- */
2408
- declare class HintCommentRuleParser extends ParserBase {
2409
- /**
2410
- * Checks if the raw rule is a hint rule.
2411
- *
2412
- * @param raw Raw rule
2413
- * @returns `true` if the rule is a hint rule, `false` otherwise
2414
- */
2415
- static isHintRule(raw: string): boolean;
2416
- /**
2417
- * Parses a raw rule as a hint comment.
2418
- *
2419
- * @param raw Raw input to parse.
2420
- * @param options Global parser options.
2421
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2422
- * @returns Hint AST or null (if the raw rule cannot be parsed as a hint comment)
2423
- * @throws If the input matches the HINT pattern but syntactically invalid
2424
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#hints-1}
2425
- */
2426
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): HintCommentRule | null;
2427
- /**
2428
- * Converts a hint rule node to a raw string.
2429
- *
2430
- * @param node Hint rule node
2431
- * @returns Raw string
2432
- */
2433
- static generate(node: HintCommentRule): string;
2434
- /**
2435
- * Serializes a hint rule node to binary format.
2436
- *
2437
- * @param node Node to serialize.
2438
- * @param buffer ByteBuffer for writing binary data.
2439
- */
2440
- static serialize(node: HintCommentRule, buffer: OutputByteBuffer): void;
2441
- /**
2442
- * Deserializes a hint rule node from binary format.
2443
- *
2444
- * @param buffer ByteBuffer for reading binary data.
2445
- * @param node Destination node.
2446
- * @throws If the binary data is malformed.
2447
- */
2448
- static deserialize(buffer: InputByteBuffer, node: Partial<HintCommentRule>): void;
2449
- }
2450
-
2451
- /**
2452
- * `HintParser` is responsible for parsing AdGuard hints.
2453
- *
2454
- * @example
2455
- * If the hint rule is
2456
- * ```adblock
2457
- * !+ NOT_OPTIMIZED PLATFORM(windows)
2458
- * ```
2459
- * then the hints are `NOT_OPTIMIZED` and `PLATFORM(windows)`, and this
2460
- * class is responsible for parsing them. The rule itself is parsed by
2461
- * the `HintRuleParser`, which uses this class to parse single hints.
2462
- */
2463
- declare class HintParser extends ParserBase {
2464
- /**
2465
- * Parses a raw rule as a hint.
2466
- *
2467
- * @param raw Raw input to parse.
2468
- * @param options Global parser options.
2469
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2470
- * @returns Hint rule AST or null
2471
- * @throws If the syntax is invalid
2472
- */
2473
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): Hint;
2474
- /**
2475
- * Converts a single hint AST to a string.
2476
- *
2477
- * @param hint Hint AST
2478
- * @returns Hint string
2479
- */
2480
- static generate(hint: Hint): string;
2481
- /**
2482
- * Serializes a hint node to binary format.
2483
- *
2484
- * @param node Node to serialize.
2485
- * @param buffer ByteBuffer for writing binary data.
2486
- */
2487
- static serialize(node: Hint, buffer: OutputByteBuffer): void;
2488
- /**
2489
- * Deserializes a hint node from binary format.
2490
- *
2491
- * @param buffer ByteBuffer for reading binary data.
2492
- * @param node Destination node.
2493
- * @throws If the binary data is malformed.
2494
- */
2495
- static deserialize(buffer: InputByteBuffer, node: Partial<Hint>): void;
2496
- }
2497
-
2498
- /**
2499
- * `LogicalExpressionParser` is responsible for parsing logical expressions.
2500
- *
2501
- * @example
2502
- * From the following rule:
2503
- * ```adblock
2504
- * !#if (adguard_ext_android_cb || adguard_ext_safari)
2505
- * ```
2506
- * this parser will parse the expression `(adguard_ext_android_cb || adguard_ext_safari)`.
2507
- */
2508
- declare class LogicalExpressionParser extends ParserBase {
2509
- /**
2510
- * Split the expression into tokens.
2511
- *
2512
- * @param raw Source code of the expression
2513
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2514
- * @returns Token list
2515
- * @throws {AdblockSyntaxError} If the expression is invalid
2516
- */
2517
- private static tokenize;
2518
- /**
2519
- * Parses a logical expression.
2520
- *
2521
- * @param raw Raw input to parse.
2522
- * @param options Global parser options.
2523
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2524
- * @returns Parsed expression
2525
- * @throws {AdblockSyntaxError} If the expression is invalid
2526
- */
2527
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): AnyExpressionNode;
2528
- /**
2529
- * Generates a string representation of the logical expression (serialization).
2530
- *
2531
- * @param node Expression node
2532
- * @returns String representation of the logical expression
2533
- */
2534
- static generate(node: AnyExpressionNode): string;
2535
- /**
2536
- * Serializes a variable node to binary format.
2537
- *
2538
- * @param node Node to serialize.
2539
- * @param buffer ByteBuffer for writing binary data.
2540
- */
2541
- private static serializeVariableNode;
2542
- /**
2543
- * Serializes a parenthesis node to binary format.
2544
- *
2545
- * @param node Node to serialize.
2546
- * @param buffer ByteBuffer for writing binary data.
2547
- */
2548
- private static serializeParenthesisNode;
2549
- /**
2550
- * Serializes an operator node to binary format.
2551
- *
2552
- * @param node Node to serialize.
2553
- * @param buffer ByteBuffer for writing binary data.
2554
- */
2555
- private static serializeOperatorNode;
2556
- /**
2557
- * Serializes a logical expression node to binary format.
2558
- *
2559
- * @param node Node to serialize.
2560
- * @param buffer ByteBuffer for writing binary data.
2561
- */
2562
- static serialize(node: AnyExpressionNode, buffer: OutputByteBuffer): void;
2563
- /**
2564
- * Deserializes a variable node from binary format.
2565
- *
2566
- * @param buffer ByteBuffer for reading binary data.
2567
- * @param node Destination node.
2568
- * @throws If the binary data is malformed.
2569
- */
2570
- private static deserializeVariableNode;
2571
- /**
2572
- * Deserializes a parenthesis node from binary format.
2573
- *
2574
- * @param buffer ByteBuffer for reading binary data.
2575
- * @param node Destination node.
2576
- * @throws If the binary data is malformed.
2577
- */
2578
- private static deserializeParenthesisNode;
2579
- /**
2580
- * Deserializes an operator node from binary format.
2581
- *
2582
- * @param buffer ByteBuffer for reading binary data.
2583
- * @param node Destination node.
2584
- * @throws If the binary data is malformed.
2585
- */
2586
- private static deserializeOperatorNode;
2587
- /**
2588
- * Deserializes a logical expression node from binary format.
2589
- *
2590
- * @param buffer ByteBuffer for reading binary data.
2591
- * @param node Destination node.
2592
- * @throws If the binary data is malformed.
2593
- */
2594
- static deserialize(buffer: InputByteBuffer, node: Partial<AnyExpressionNode>): void;
2595
- }
2596
-
2597
- /**
2598
- * Known metadata headers.
2599
- */
2600
- declare const KNOWN_METADATA_HEADERS: string[];
2601
- /**
2602
- * `MetadataParser` is responsible for parsing metadata comments.
2603
- * Metadata comments are special comments that specify some properties of the list.
2604
- *
2605
- * @example
2606
- * For example, in the case of
2607
- * ```adblock
2608
- * ! Title: My List
2609
- * ```
2610
- * the name of the header is `Title`, and the value is `My List`, which means that
2611
- * the list title is `My List`, and it can be used in the adblocker UI.
2612
- * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#special-comments}
2613
- */
2614
- declare class MetadataCommentRuleParser extends ParserBase {
2615
- /**
2616
- * Parses a raw rule as a metadata comment.
2617
- *
2618
- * @param raw Raw input to parse.
2619
- * @param options Global parser options.
2620
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2621
- * @returns Metadata comment AST or null (if the raw rule cannot be parsed as a metadata comment)
2622
- */
2623
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): MetadataCommentRule | null;
2624
- /**
2625
- * Converts a metadata comment rule node to a string.
2626
- *
2627
- * @param node Metadata comment rule node.
2628
- * @returns Raw string.
2629
- */
2630
- static generate(node: MetadataCommentRule): string;
2631
- /**
2632
- * Serializes a metadata comment node to binary format.
2633
- *
2634
- * @param node Node to serialize.
2635
- * @param buffer ByteBuffer for writing binary data.
2636
- */
2637
- static serialize(node: MetadataCommentRule, buffer: OutputByteBuffer): void;
2638
- /**
2639
- * Deserializes a metadata comment node from binary format.
2640
- *
2641
- * @param buffer ByteBuffer for reading binary data.
2642
- * @param node Destination node.
2643
- * @throws If the binary data is malformed.
2644
- */
2645
- static deserialize(buffer: InputByteBuffer, node: Partial<MetadataCommentRule>): void;
2646
- }
2647
-
2648
- /**
2649
- * `ModifierListParser` is responsible for parsing modifier lists. Please note that the name is not
2650
- * uniform, "modifiers" are also known as "options".
2651
- *
2652
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#basic-rules-modifiers}
2653
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#non-basic-rules-modifiers}
2654
- * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#options}
2655
- */
2656
- declare class ModifierListParser extends ParserBase {
2657
- /**
2658
- * Parses the cosmetic rule modifiers, eg. `third-party,domain=example.com|~example.org`.
2659
- *
2660
- * _Note:_ you should remove `$` separator before passing the raw modifiers to this function,
2661
- * or it will be parsed in the first modifier.
2662
- *
2663
- * @param raw Raw input to parse.
2664
- * @param options Global parser options.
2665
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2666
- * @returns Parsed modifiers interface
2667
- */
2668
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): ModifierList;
2669
- /**
2670
- * Converts a modifier list AST to a string.
2671
- *
2672
- * @param ast Modifier list AST
2673
- * @returns Raw string
2674
- */
2675
- static generate(ast: ModifierList): string;
2676
- /**
2677
- * Serializes a modifier list node to binary format.
2678
- *
2679
- * @param node Node to serialize.
2680
- * @param buffer ByteBuffer for writing binary data.
2681
- */
2682
- static serialize(node: ModifierList, buffer: OutputByteBuffer): void;
2683
- /**
2684
- * Deserializes a modifier list node from binary format.
2685
- *
2686
- * @param buffer ByteBuffer for reading binary data.
2687
- * @param node Destination node.
2688
- */
2689
- static deserialize(buffer: InputByteBuffer, node: ModifierList): void;
2690
- }
2691
-
2692
- /**
2693
- * `ModifierParser` is responsible for parsing modifiers.
2694
- *
2695
- * @example
2696
- * `match-case`, `~third-party`, `domain=example.com|~example.org`
2697
- */
2698
- declare class ModifierParser extends ParserBase {
2699
- /**
2700
- * Parses a modifier.
2701
- *
2702
- * @param raw Raw input to parse.
2703
- * @param options Global parser options.
2704
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2705
- *
2706
- * @returns Parsed modifier
2707
- * @throws An error if modifier name or value is empty.
2708
- */
2709
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): Modifier;
2710
- /**
2711
- * Generates a string from a modifier (serializes it).
2712
- *
2713
- * @param modifier Modifier to generate string from
2714
- * @returns String representation of the modifier
2715
- */
2716
- static generate(modifier: Modifier): string;
2717
- /**
2718
- * Serializes a modifier node to binary format.
2719
- *
2720
- * @param node Node to serialize.
2721
- * @param buffer ByteBuffer for writing binary data.
2722
- */
2723
- static serialize(node: Modifier, buffer: OutputByteBuffer): void;
2724
- /**
2725
- * Deserializes a modifier node from binary format.
2726
- *
2727
- * @param buffer ByteBuffer for reading binary data.
2728
- * @param node Destination node.
2729
- */
2730
- static deserialize(buffer: InputByteBuffer, node: Partial<Modifier>): void;
2731
- }
2732
-
2733
- /**
2734
- * `NetworkRuleParser` is responsible for parsing network rules.
2735
- *
2736
- * Please note that this will parse all syntactically correct network rules.
2737
- * Modifier compatibility is not checked at the parser level.
2738
- *
2739
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#basic-rules}
2740
- * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#basic}
2741
- */
2742
- declare class NetworkRuleParser extends ParserBase {
2743
- /**
2744
- * Parses a network rule (also known as basic rule).
2745
- *
2746
- * @param raw Raw input to parse.
2747
- * @param options Global parser options.
2748
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2749
- * @returns Network rule AST
2750
- *
2751
- * @throws If the rule is syntactically incorrect.
2752
- */
2753
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): NetworkRule;
2754
- /**
2755
- * Finds the index of the separator character in a network rule.
2756
- *
2757
- * @param rule Network rule to check
2758
- * @returns The index of the separator character, or -1 if there is no separator
2759
- */
2760
- private static findNetworkRuleSeparatorIndex;
2761
- /**
2762
- * Converts a network rule (basic rule) AST to a string.
2763
- *
2764
- * @param node Network rule node
2765
- * @returns Raw string
2766
- */
2767
- static generate(node: NetworkRule): string;
2768
- /**
2769
- * Serializes a network rule node to binary format.
2770
- *
2771
- * @param node Node to serialize.
2772
- * @param buffer ByteBuffer for writing binary data.
2773
- */
2774
- static serialize(node: NetworkRule, buffer: OutputByteBuffer): void;
2775
- /**
2776
- * Deserializes a modifier node from binary format.
2777
- *
2778
- * @param buffer ByteBuffer for reading binary data.
2779
- * @param node Destination node.
2780
- */
2781
- static deserialize(buffer: InputByteBuffer, node: Partial<NetworkRule>): void;
2782
- }
2783
-
2784
- /**
2785
- * @file Customized error class for not implemented features.
2786
- */
2787
- /**
2788
- * Customized error class for not implemented features.
2789
- */
2790
- declare class NotImplementedError extends Error {
2791
- /**
2792
- * Constructs a new `NotImplementedError` instance.
2793
- *
2794
- * @param message Additional error message (optional)
2795
- */
2796
- constructor(message?: string | undefined);
2797
- }
2798
-
2799
- declare class ParameterListParser extends ParserBase {
2800
- /**
2801
- * Parses a raw parameter list.
2802
- *
2803
- * @param raw Raw input to parse.
2804
- * @param options Global parser options.
2805
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2806
- * @param separator Separator character (default: comma)
2807
- * @returns Parameter list AST
2808
- */
2809
- static parse(raw: string, options?: ParserOptions, baseOffset?: number, separator?: string): ParameterList;
2810
- /**
2811
- * Converts a parameter list AST to a string.
2812
- *
2813
- * @param params Parameter list AST
2814
- * @param separator Separator character (default: comma)
2815
- * @returns String representation of the parameter list
2816
- */
2817
- static generate(params: ParameterList, separator?: string): string;
2818
- /**
2819
- * Serializes a parameter list node to binary format.
2820
- *
2821
- * @param node Node to serialize.
2822
- * @param buffer ByteBuffer for writing binary data.
2823
- * @param frequentValuesMap Optional map of frequent values.
2824
- * @param toLower Whether to lowercase the value before the frequent value match (defaults to `false`).
2825
- */
2826
- static serialize(node: ParameterList, buffer: OutputByteBuffer, frequentValuesMap?: Map<string, number>, toLower?: boolean): void;
2827
- /**
2828
- * Deserializes a parameter list node from binary format.
2829
- *
2830
- * @param buffer ByteBuffer for reading binary data.
2831
- * @param node Destination node.
2832
- * @param frequentValuesMap Optional map of frequent values.
2833
- * @throws If the binary data is malformed.
2834
- */
2835
- static deserialize(buffer: InputByteBuffer, node: ParameterList, frequentValuesMap?: Map<number, string>): void;
2836
- }
2837
-
2838
- /**
2839
- * `HostRuleParser` is responsible for parsing hosts-like rules.
2840
- *
2841
- * HostRule is a structure for simple host-level rules (i.e. /etc/hosts syntax).
2842
- * It also supports "just domain" syntax. In this case, the IP will be set to 0.0.0.0.
2843
- *
2844
- * Rules syntax looks like this:
2845
- * ```text
2846
- * IP_address canonical_hostname [aliases...]
2847
- * ```
2848
- *
2849
- * @example
2850
- * `192.168.1.13 bar.mydomain.org bar` -- ipv4
2851
- * `ff02::1 ip6-allnodes` -- ipv6
2852
- * `::1 localhost ip6-localhost ip6-loopback` -- ipv6 aliases
2853
- * `example.org` -- "just domain" syntax
2854
- * @see {@link http://man7.org/linux/man-pages/man5/hosts.5.html}
2855
- */
2856
- declare class HostRuleParser extends ParserBase {
2857
- static readonly NULL_IP = "0.0.0.0";
2858
- static readonly COMMENT_MARKER = "#";
2859
- /**
2860
- * Parses an etc/hosts-like rule.
2861
- *
2862
- * @param raw Raw input to parse.
2863
- * @param options Global parser options.
2864
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2865
- * @returns Host rule node.
2866
- *
2867
- * @throws If the input contains invalid data.
2868
- */
2869
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): HostRule;
2870
- /**
2871
- * Converts a host rule node to a raw string.
2872
- *
2873
- * @param node Host rule node.
2874
- * @returns Raw string.
2875
- */
2876
- static generate(node: HostRule): string;
2877
- /**
2878
- * Serializes a hostname list node to binary format.
2879
- *
2880
- * @param node Node to serialize.
2881
- * @param buffer ByteBuffer for writing binary data.
2882
- */
2883
- private static serializeHostnameList;
2884
- /**
2885
- * Deserializes a hostname list node from binary format.
2886
- *
2887
- * @param buffer ByteBuffer for reading binary data.
2888
- * @param node Destination node.
2889
- */
2890
- private static deserializeHostnameList;
2891
- /**
2892
- * Serializes a host rule node to binary format.
2893
- *
2894
- * @param node Node to serialize.
2895
- * @param buffer ByteBuffer for writing binary data.
2896
- */
2897
- static serialize(node: HostRule, buffer: OutputByteBuffer): void;
2898
- /**
2899
- * Deserializes a modifier node from binary format.
2900
- *
2901
- * @param buffer ByteBuffer for reading binary data.
2902
- * @param node Destination node.
2903
- */
2904
- static deserialize(buffer: InputByteBuffer, node: Partial<HostRule>): void;
2905
- }
2906
-
2907
- /**
2908
- * `PreProcessorParser` is responsible for parsing preprocessor rules.
2909
- * Pre-processor comments are special comments that are used to control the behavior of the filter list processor.
2910
- * Please note that this parser only handles general syntax for now, and does not validate the parameters at
2911
- * the parsing stage.
2912
- *
2913
- * @example
2914
- * If your rule is
2915
- * ```adblock
2916
- * !#if (adguard)
2917
- * ```
2918
- * then the directive's name is `if` and its value is `(adguard)`, but the parameter list
2919
- * is not parsed / validated further.
2920
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#pre-processor-directives}
2921
- * @see {@link https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#pre-parsing-directives}
2922
- */
2923
- declare class PreProcessorCommentRuleParser extends ParserBase {
2924
- /**
2925
- * Determines whether the rule is a pre-processor rule.
2926
- *
2927
- * @param raw Raw rule
2928
- * @returns `true` if the rule is a pre-processor rule, `false` otherwise
2929
- */
2930
- static isPreProcessorRule(raw: string): boolean;
2931
- /**
2932
- * Parses a raw rule as a pre-processor comment.
2933
- *
2934
- * @param raw Raw input to parse.
2935
- * @param options Global parser options.
2936
- * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2937
- * @returns
2938
- * Pre-processor comment AST or null (if the raw rule cannot be parsed as a pre-processor comment)
2939
- */
2940
- static parse(raw: string, options?: ParserOptions, baseOffset?: number): PreProcessorCommentRule | null;
2941
- /**
2942
- * Converts a pre-processor comment node to a string.
2943
- *
2944
- * @param node Pre-processor comment node
2945
- * @returns Raw string
2946
- */
2947
- static generate(node: PreProcessorCommentRule): string;
2948
- /**
2949
- * Serializes a pre-processor comment node to binary format.
2950
- *
2951
- * @param node Node to serialize.
2952
- * @param buffer ByteBuffer for writing binary data.
2953
- */
2954
- static serialize(node: PreProcessorCommentRule, buffer: OutputByteBuffer): void;
2955
- /**
2956
- * Deserializes a pre-processor comment node from binary format.
2957
- *
2958
- * @param buffer ByteBuffer for reading binary data.
2959
- * @param node Destination node.
2960
- * @throws If the binary data is malformed.
2961
- */
2962
- static deserialize(buffer: InputByteBuffer, node: Partial<PreProcessorCommentRule>): void;
2963
- }
2964
-
2965
- /**
2966
- * @file Customized error class for conversion errors.
2967
- */
2968
- /**
2969
- * Customized error class for conversion errors.
2970
- */
2971
- declare class RuleConversionError extends Error {
2972
- /**
2973
- * Constructs a new `RuleConversionError` instance.
2974
- *
2975
- * @param message Error message
2976
- */
2977
- constructor(message: string);
2978
- }
2979
-
2980
- /**
2981
- * @file Customized error for binary schema mismatch.
2982
- */
2983
- /**
2984
- * Customized error for binary schema mismatch.
2985
- */
2986
- declare class BinarySchemaMismatchError extends Error {
2987
- /**
2988
- * Expected schema version.
2989
- */
2990
- expectedVersion: number;
2991
- /**
2992
- * Actual schema version.
2993
- */
2994
- actualVersion: number;
2995
- /**
2996
- * Constructs a new `BinarySchemaMismatchError` instance.
2997
- *
2998
- * @param expectedVersion Expected schema version.
2999
- * @param actualVersion Actual schema version.
3000
- */
3001
- constructor(expectedVersion: number, actualVersion: number);
3002
- }
3003
-
3004
- /**
3005
- * Result of modifier validation:
3006
- * - `{ valid: true }` for valid and _fully supported_ modifier;
3007
- * - `{ valid: true, warn: <deprecation notice> }` for valid
3008
- * and _still supported but deprecated_ modifier;
3009
- * - otherwise `{ valid: true, error: <invalidity reason> }`
3010
- */
3011
- type ValidationResult = {
3012
- valid: boolean;
3013
- error?: string;
3014
- warn?: string;
3015
- };
3016
-
3017
- /**
3018
- * @file Validator for modifiers.
3019
- */
3020
-
3021
- /**
3022
- * Modifier validator class.
3023
- */
3024
- declare class ModifierValidator {
3025
- /**
3026
- * Simply checks whether the modifier exists in any adblocker.
3027
- *
3028
- * **Deprecated** and **removed** modifiers are considered as **existent**.
3029
- *
3030
- * @param modifier Already parsed modifier AST node.
3031
- *
3032
- * @returns True if modifier exists, false otherwise.
3033
- */
3034
- exists: (modifier: Modifier) => boolean;
3035
- /**
3036
- * Checks whether the given `modifier` is valid for specified `syntax`.
3037
- *
3038
- * For `Common` syntax it simply checks whether the modifier exists.
3039
- * For specific syntax the validation is more complex —
3040
- * deprecated, assignable, negatable and other requirements are checked.
3041
- *
3042
- * @param syntax Adblock syntax to check the modifier for.
3043
- * @param rawModifier Modifier AST node.
3044
- * @param isException Whether the modifier is used in exception rule, default to false.
3045
- * Needed to check whether the modifier is allowed only in blocking or exception rules.
3046
- *
3047
- * @returns Result of modifier validation.
3048
- */
3049
- validate: (syntax: AdblockSyntax, rawModifier: Modifier, isException?: boolean) => ValidationResult;
3050
- }
3051
- declare const modifierValidator: ModifierValidator;
3052
-
3053
- /**
3054
- * @file Conversion result interface and helper functions
3055
- */
3056
-
3057
- /**
3058
- * Common conversion result interface
3059
- *
3060
- * @template T Type of the item to convert
3061
- * @template U Type of the conversion result (defaults to `T`, but can be `T[]` as well)
3062
- */
3063
- interface ConversionResult<T, U extends T | T[] = T> {
3064
- /**
3065
- * Conversion result
3066
- */
3067
- result: U;
3068
- /**
3069
- * Indicates whether the input item was converted
3070
- */
3071
- isConverted: boolean;
3072
- }
3073
- /**
3074
- * Adblock rule node conversion result interface, where the conversion result is an array of rules
3075
- */
3076
- type NodeConversionResult<T extends Node> = ConversionResult<T, T[]>;
3077
-
3078
- /**
3079
- * @file Base class for converters
3080
- *
3081
- * TS doesn't support abstract static methods, so we should use
3082
- * a workaround and extend this class instead of implementing it
3083
- */
3084
-
3085
- /**
3086
- * Basic class for rule converters
3087
- */
3088
- declare class ConverterBase {
3089
- /**
3090
- * Converts some data to AdGuard format
3091
- *
3092
- * @param data Data to convert
3093
- * @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
3094
- * the converted node, and its `isConverted` flag indicates whether the original node was converted.
3095
- * If the node was not converted, the result will contain the original node with the same object reference
3096
- * @throws If the data is invalid or incompatible
3097
- */
3098
- static convertToAdg(data: unknown): ConversionResult<unknown>;
3099
- /**
3100
- * Converts some data to Adblock Plus format
3101
- *
3102
- * @param data Data to convert
3103
- * @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
3104
- * the converted node, and its `isConverted` flag indicates whether the original node was converted.
3105
- * If the node was not converted, the result will contain the original node with the same object reference
3106
- * @throws If the data is invalid or incompatible
3107
- */
3108
- static convertToAbp(data: unknown): ConversionResult<unknown>;
3109
- /**
3110
- * Converts some data to uBlock Origin format
3111
- *
3112
- * @param data Data to convert
3113
- * @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
3114
- * the converted node, and its `isConverted` flag indicates whether the original node was converted.
3115
- * If the node was not converted, the result will contain the original node with the same object reference
3116
- * @throws If the data is invalid or incompatible
3117
- */
3118
- static convertToUbo(data: unknown): ConversionResult<unknown>;
3119
- }
3120
-
3121
- /**
3122
- * @file Adblock filter list converter
3123
- */
3124
-
3125
- /**
3126
- * Adblock filter list converter class
3127
- *
3128
- * This class just provides an extra layer on top of the {@link RuleConverter}
3129
- * and can be used to convert entire filter lists.
3130
- *
3131
- * @todo Implement `convertToUbo` and `convertToAbp`
3132
- * @todo Implement tolerant mode, which will allow to convert a filter list
3133
- * even if some of its rules are invalid
3134
- */
3135
- declare class FilterListConverter extends ConverterBase {
3136
- /**
3137
- * Converts an adblock filter list to AdGuard format, if possible.
3138
- *
3139
- * @param filterListNode Filter list node to convert
3140
- * @param tolerant Indicates whether the converter should be tolerant to invalid rules. If enabled and a rule is
3141
- * invalid, it will be left as is. If disabled and a rule is invalid, the whole filter list will be failed.
3142
- * Defaults to `true`.
3143
- * @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
3144
- * the converted node, and its `isConverted` flag indicates whether the original node was converted.
3145
- * If the node was not converted, the result will contain the original node with the same object reference
3146
- * @throws If the filter list is invalid or cannot be converted (if the tolerant mode is disabled)
3147
- */
3148
- static convertToAdg(filterListNode: FilterList, tolerant?: boolean): ConversionResult<FilterList>;
3149
- }
3150
-
3151
- /**
3152
- * @file Filter list converter for raw filter lists
3153
- *
3154
- * Technically, this is a wrapper around `FilterListConverter` that works with nodes instead of strings.
3155
- */
3156
-
3157
- /**
3158
- * Adblock filter list converter class.
3159
- *
3160
- * You can use this class to convert string-based filter lists, since most of the converters work with nodes.
3161
- * This class just provides an extra layer on top of the {@link FilterListConverter} and calls the parser/serializer
3162
- * before/after the conversion internally.
3163
- *
3164
- * @todo Implement `convertToUbo` and `convertToAbp`
3165
- */
3166
- declare class RawFilterListConverter extends ConverterBase {
3167
- /**
3168
- * Converts an adblock filter list text to AdGuard format, if possible.
3169
- *
3170
- * @param rawFilterList Raw filter list text to convert
3171
- * @param tolerant Indicates whether the converter should be tolerant to invalid rules. If enabled and a rule is
3172
- * invalid, it will be left as is. If disabled and a rule is invalid, the whole filter list will be failed.
3173
- * Defaults to `true`.
3174
- * @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
3175
- * the array of converted filter list text, and its `isConverted` flag indicates whether the original rule was
3176
- * converted. If the rule was not converted, the original filter list text will be returned
3177
- * @throws If the filter list is invalid or cannot be converted (if the tolerant mode is disabled)
3178
- */
3179
- static convertToAdg(rawFilterList: string, tolerant?: boolean): ConversionResult<string>;
3180
- }
3181
-
3182
- /**
3183
- * @file Rule converter for raw rules
3184
- *
3185
- * Technically, this is a wrapper around `RuleConverter` that works with nodes instead of strings.
3186
- */
3187
-
3188
- /**
3189
- * Adblock filtering rule converter class.
3190
- *
3191
- * You can use this class to convert string-based adblock rules, since most of the converters work with nodes.
3192
- * This class just provides an extra layer on top of the {@link RuleConverter} and calls the parser/serializer
3193
- * before/after the conversion internally.
3194
- *
3195
- * @todo Implement `convertToUbo` and `convertToAbp`
3196
- */
3197
- declare class RawRuleConverter extends ConverterBase {
3198
- /**
3199
- * Converts an adblock filtering rule to AdGuard format, if possible.
3200
- *
3201
- * @param rawRule Raw rule text to convert
3202
- * @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
3203
- * the array of converted rule texts, and its `isConverted` flag indicates whether the original rule was converted.
3204
- * If the rule was not converted, the original rule text will be returned
3205
- * @throws If the rule is invalid or cannot be converted
3206
- */
3207
- static convertToAdg(rawRule: string): ConversionResult<string, string[]>;
3208
- }
3209
-
3210
- /**
3211
- * @file Base class for rule converters
3212
- *
3213
- * TS doesn't support abstract static methods, so we should use
3214
- * a workaround and extend this class instead of implementing it
3215
- */
3216
-
3217
- /**
3218
- * Basic class for rule converters
3219
- */
3220
- declare class RuleConverterBase extends ConverterBase {
3221
- /**
3222
- * Converts an adblock filtering rule to AdGuard format, if possible.
3223
- *
3224
- * @param rule Rule node to convert
3225
- * @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains
3226
- * the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted.
3227
- * If the rule was not converted, the result array will contain the original node with the same object reference
3228
- * @throws If the rule is invalid or cannot be converted
3229
- */
3230
- static convertToAdg(rule: Node): NodeConversionResult<Node>;
3231
- /**
3232
- * Converts an adblock filtering rule to Adblock Plus format, if possible.
3233
- *
3234
- * @param rule Rule node to convert
3235
- * @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains
3236
- * the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted.
3237
- * If the rule was not converted, the result array will contain the original node with the same object reference
3238
- * @throws If the rule is invalid or cannot be converted
3239
- */
3240
- static convertToAbp(rule: Node): NodeConversionResult<Node>;
3241
- /**
3242
- * Converts an adblock filtering rule to uBlock Origin format, if possible.
3243
- *
3244
- * @param rule Rule node to convert
3245
- * @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains
3246
- * the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted.
3247
- * If the rule was not converted, the result array will contain the original node with the same object reference
3248
- * @throws If the rule is invalid or cannot be converted
3249
- */
3250
- static convertToUbo(rule: Node): NodeConversionResult<Node>;
3251
- }
3252
-
3253
- /**
3254
- * @file Adblock rule converter
3255
- *
3256
- * This file is the entry point for all rule converters
3257
- * which automatically detects the rule type and calls
3258
- * the corresponding "sub-converter".
3259
- */
3260
-
3261
- /**
3262
- * Adblock filtering rule converter class
3263
- *
3264
- * @todo Implement `convertToUbo` and `convertToAbp`
3265
- */
3266
- declare class RuleConverter extends RuleConverterBase {
3267
- /**
3268
- * Converts an adblock filtering rule to AdGuard format, if possible.
3269
- *
3270
- * @param rule Rule node to convert
3271
- * @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains
3272
- * the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted.
3273
- * If the rule was not converted, the result array will contain the original node with the same object reference
3274
- * @throws If the rule is invalid or cannot be converted
3275
- */
3276
- static convertToAdg(rule: AnyRule): NodeConversionResult<AnyRule>;
3277
- /**
3278
- * Converts an adblock filtering rule to uBlock Origin format, if possible.
3279
- *
3280
- * @param rule Rule node to convert
3281
- * @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains
3282
- * the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted.
3283
- * If the rule was not converted, the result array will contain the original node with the same object reference
3284
- * @throws If the rule is invalid or cannot be converted
3285
- */
3286
- static convertToUbo(rule: AnyRule): NodeConversionResult<AnyRule>;
3287
- }
3288
-
3289
- /**
3290
- * @file Binary schema version.
3291
- */
3292
- /**
3293
- * Binary schema version.
3294
- * This version number is used to ensure that the binary format is compatible with the current library version.
3295
- * We increment this number if the serialized format changes in a way that is not backwards-compatible.
3296
- */
3297
- declare const BINARY_SCHEMA_VERSION = 1;
3298
-
3299
- /**
3300
- * @file Cosmetic rule separator finder and categorizer
3301
- */
3302
-
3303
- interface CosmeticRuleSeparatorFinderResult {
3304
- /**
3305
- * Separator type
3306
- */
3307
- separator: CosmeticRuleSeparator;
3308
- /**
3309
- * Separator start position
3310
- */
3311
- start: number;
3312
- /**
3313
- * Separator end position
3314
- */
3315
- end: number;
3316
- }
3317
- /**
3318
- * Utility class for cosmetic rule separators.
3319
- */
3320
- declare class CosmeticRuleSeparatorUtils {
3321
- /**
3322
- * Checks whether the specified separator is an exception.
3323
- *
3324
- * @param separator Separator to check
3325
- * @returns `true` if the separator is an exception, `false` otherwise
3326
- */
3327
- static isException(separator: CosmeticRuleSeparator): boolean;
3328
- /**
3329
- * Checks whether the specified separator is marks an Extended CSS cosmetic rule.
3330
- *
3331
- * @param separator Separator to check
3332
- * @returns `true` if the separator is marks an Extended CSS cosmetic rule, `false` otherwise
3333
- */
3334
- static isExtendedCssMarker(separator: CosmeticRuleSeparator): boolean;
3335
- /**
3336
- * Looks for the cosmetic rule separator in the rule. This is a simplified version that
3337
- * masks the recursive function.
3338
- *
3339
- * @param rule Raw rule
3340
- * @returns Separator result or null if no separator was found
3341
- */
3342
- static find(rule: string): CosmeticRuleSeparatorFinderResult | null;
3343
- }
3344
-
3345
- declare class DomainUtils {
3346
- /**
3347
- * Check if the input is a valid domain or hostname.
3348
- *
3349
- * @param domain Domain to check
3350
- * @returns `true` if the domain is valid, `false` otherwise
3351
- */
3352
- static isValidDomainOrHostname(domain: string): boolean;
3353
- }
3354
-
3355
- /**
3356
- * @file Utility functions for logical expression node.
3357
- */
3358
-
3359
- /**
3360
- * Variable table. Key is variable name, value is boolean.
3361
- */
3362
- type VariableTable = {
3363
- [key: string]: boolean;
3364
- };
3365
- /**
3366
- * Utility functions for logical expression node.
3367
- */
3368
- declare class LogicalExpressionUtils {
3369
- /**
3370
- * Get all variables in the expression.
3371
- *
3372
- * @param node Logical expression node
3373
- * @returns List of variables in the expression (nodes)
3374
- * @example
3375
- * If the expression is `a && b || c`, the returned list will be
3376
- * nodes for `a`, `b`, and `c`.
3377
- */
3378
- static getVariables(node: AnyExpressionNode): ExpressionVariableNode[];
3379
- /**
3380
- * Evaluate the parsed logical expression. You'll need to provide a
3381
- * variable table.
3382
- *
3383
- * @param node Logical expression node
3384
- * @param table Variable table (key: variable name, value: boolean)
3385
- * @returns Evaluation result
3386
- * @example
3387
- * If the expression is `a && b`, and the variable table is
3388
- * `{ a: true, b: false }`, the result will be `false`.
3389
- *
3390
- * Example code:
3391
- * ```js
3392
- * LogicalExpressionUtils.evaluate(
3393
- * LogicalExpressionParser.parse('a && b'),
3394
- * { a: true, b: false }
3395
- * );
3396
- * ```
3397
- */
3398
- static evaluate(node: AnyExpressionNode, table: VariableTable): boolean;
3399
- }
3400
-
3401
- declare const ADBLOCK_URL_START: string;
3402
- declare const ADBLOCK_URL_START_REGEX = "^(http|https|ws|wss)://([a-z0-9-_.]+\\.)?";
3403
- declare const ADBLOCK_URL_SEPARATOR = "^";
3404
- declare const ADBLOCK_URL_SEPARATOR_REGEX = "([^ a-zA-Z0-9.%_-]|$)";
3405
- declare const ADBLOCK_WILDCARD = "*";
3406
- declare const ADBLOCK_WILDCARD_REGEX: string;
3407
- /**
3408
- * Special RegExp symbols
3409
- *
3410
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-escape
3411
- */
3412
- declare const SPECIAL_REGEX_SYMBOLS: Set<string>;
3413
- /**
3414
- * Utility functions for working with RegExp patterns
3415
- */
3416
- declare class RegExpUtils {
3417
- /**
3418
- * Checks whether a string possibly is a RegExp pattern.
3419
- * Flags are not supported.
3420
- *
3421
- * Note: it does not perform a full validation of the pattern,
3422
- * it just checks if the string starts and ends with a slash.
3423
- *
3424
- * @param pattern - Pattern to check
3425
- * @returns `true` if the string is a RegExp pattern, `false` otherwise
3426
- */
3427
- static isRegexPattern(pattern: string): boolean;
3428
- /**
3429
- * Negates a RegExp pattern. Technically, this method wraps the pattern in `^((?!` and `).)*$`.
3430
- *
3431
- * RegExp modifiers are not supported.
3432
- *
3433
- * @param pattern Pattern to negate (can be wrapped in slashes or not)
3434
- * @returns Negated RegExp pattern
3435
- */
3436
- static negateRegexPattern(pattern: string): string;
3437
- /**
3438
- * Converts a basic adblock rule pattern to a RegExp pattern. Based on
3439
- * https://github.com/AdguardTeam/tsurlfilter/blob/9b26e0b4a0e30b87690bc60f7cf377d112c3085c/packages/tsurlfilter/src/rules/simple-regex.ts#L219
3440
- *
3441
- * @param pattern Pattern to convert
3442
- * @returns RegExp equivalent of the pattern
3443
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#basic-rules}
3444
- */
3445
- static patternToRegexp(pattern: string): string;
3446
- }
3447
-
3448
- /**
3449
- * Possible quote types for scriptlet parameters
3450
- */
3451
- declare enum QuoteType {
3452
- /**
3453
- * No quotes at all
3454
- */
3455
- None = "none",
3456
- /**
3457
- * Single quotes (`'`)
3458
- */
3459
- Single = "single",
3460
- /**
3461
- * Double quotes (`"`)
3462
- */
3463
- Double = "double",
3464
- /**
3465
- * Backtick quotes (`` ` ``)
3466
- */
3467
- Backtick = "backtick"
3468
- }
3469
- /**
3470
- * Utility functions for working with quotes
3471
- */
3472
- declare class QuoteUtils {
3473
- /**
3474
- * Escape all unescaped occurrences of the character
3475
- *
3476
- * @param string String to escape
3477
- * @param char Character to escape
3478
- * @returns Escaped string
3479
- */
3480
- static escapeUnescapedOccurrences(string: string, char: string): string;
3481
- /**
3482
- * Unescape all single escaped occurrences of the character
3483
- *
3484
- * @param string String to unescape
3485
- * @param char Character to unescape
3486
- * @returns Unescaped string
3487
- */
3488
- static unescapeSingleEscapedOccurrences(string: string, char: string): string;
3489
- /**
3490
- * Get quote type of the string
3491
- *
3492
- * @param string String to check
3493
- * @returns Quote type of the string
3494
- */
3495
- static getStringQuoteType(string: string): QuoteType;
3496
- /**
3497
- * Set quote type of the string
3498
- *
3499
- * @param string String to set quote type of
3500
- * @param quoteType Quote type to set
3501
- * @returns String with the specified quote type
3502
- */
3503
- static setStringQuoteType(string: string, quoteType: QuoteType): string;
3504
- /**
3505
- * Removes bounding quotes from a string, if any
3506
- *
3507
- * @param string Input string
3508
- * @returns String without quotes
3509
- */
3510
- static removeQuotes(string: string): string;
3511
- /**
3512
- * Removes bounding quotes from a string, if any, and unescapes the escaped quotes,
3513
- * like transforming `'abc\'def'` to `abc'def`.
3514
- *
3515
- * @param string Input string
3516
- * @returns String without quotes
3517
- */
3518
- static removeQuotesAndUnescape(string: string): string;
3519
- /**
3520
- * Wraps given `strings` with `quote` (defaults to single quote `'`)
3521
- * and joins them with `separator` (defaults to comma+space `, `).
3522
- *
3523
- * @param strings Strings to quote and join.
3524
- * @param quoteType Quote to use.
3525
- * @param separator Separator to use.
3526
- *
3527
- * @returns String with joined items.
3528
- *
3529
- * @example
3530
- * ['abc', 'def']: strings[] -> "'abc', 'def'": string
3531
- */
3532
- static quoteAndJoinStrings(strings: string[], quoteType?: QuoteType, separator?: string): string;
3533
- }
3534
-
3535
- /**
3536
- * @file Position provider class.
3537
- */
3538
- /**
3539
- * Represents a position in the source code.
3540
- */
3541
- interface Position {
3542
- /**
3543
- * 1-based line number
3544
- */
3545
- line: number;
3546
- /**
3547
- * 1-based column number
3548
- */
3549
- column: number;
3550
- }
3551
- /**
3552
- * Class responsible for converting a character offset in source code into a line and column position.
3553
- * This conversion is particularly needed in linters and VSCode extensions,
3554
- * where line and column numbers are more human-friendly and intuitive than character offsets.
3555
- * Moreover, the VSCode diagnostics API does not directly support character offsets,
3556
- * it also requires line and column numbers.
3557
- */
3558
- declare class PositionProvider {
3559
- /**
3560
- * Maps a character offset to a line number.
3561
- */
3562
- private offsetToLine;
3563
- /**
3564
- * Maps a line number to the starting character offset of that line.
3565
- */
3566
- private lineStartOffsets;
3567
- /**
3568
- * Constructs a new PositionProvider instance.
3569
- *
3570
- * @param sourceCode The source code as a string.
3571
- */
3572
- constructor(sourceCode: string);
3573
- /**
3574
- * Converts a character offset to a line and column position.
3575
- *
3576
- * @param offset The zero-based character offset in the source code.
3577
- * @returns A Position object containing the 1-based line and column number, or null if the offset is out of range.
3578
- */
3579
- convertOffsetToPosition(offset: number): Position | null;
3580
- }
3581
-
3582
- /**
3583
- * @file Utility for encoding strings to byte sequences.
3584
- */
3585
- interface TextEncoderPolyfillResult {
3586
- readonly written: number;
3587
- readonly read: number;
3588
- }
3589
- /**
3590
- * Encodes an UTF-8 string into a byte sequence according to the WHATWG spec.
3591
- *
3592
- * @param str String to encode.
3593
- * @param buffer Buffer to write the encoded bytes to.
3594
- * @returns Number of bytes written to the buffer.
3595
- * @see {@link https://encoding.spec.whatwg.org/#utf-8-encoder}
3596
- * @note Bytes written maybe larger than the string length, but never smaller.
3597
- * For example, the string '你好' has a length of 2, but its byte representation has a length of 6.
3598
- */
3599
- declare const encodeIntoPolyfill: (str: string, buffer: Uint8Array) => TextEncoderPolyfillResult;
3600
-
3601
- /**
3602
- * @file Optimized utility for decoding strings from byte sequences.
3603
- */
3604
- /**
3605
- * Decodes a byte sequence into an UTF-8 string according to the WHATWG spec.
3606
- * Optimized for performance.
3607
- *
3608
- * @param buffer Buffer to read the bytes from.
3609
- * @param start Start offset in the buffer.
3610
- * @param end End offset in the buffer.
3611
- * @returns Decoded string.
3612
- * @see {@link https://encoding.spec.whatwg.org/#utf-8-decoder}
3613
- */
3614
- declare const decodeTextPolyfill: (buffer: Uint8Array, start?: number, end?: number) => string;
3615
-
3616
- /**
3617
- * Utility functions for categorizing rules.
3618
- */
3619
- declare class RuleCategorizer {
3620
- /**
3621
- * Determines the type of a given raw cosmetic rule.
3622
- *
3623
- * @param rawRule Raw rule to check.
3624
- *
3625
- * @returns Type of the cosmetic rule or `null` if the rule is cannot be parsed as a cosmetic rule.
3626
- */
3627
- static getCosmeticRuleType(rawRule: string): CosmeticRuleType | null;
3628
- }
3629
-
3630
- /**
3631
- * _ALL_ known Extended CSS pseudo-classes. Please, keep this list sorted.
3632
- * It includes strict pseudo-classes and additional pseudo-classes that may be
3633
- * supported by some browsers natively.
3634
- */
3635
- declare const EXT_CSS_PSEUDO_CLASSES: Set<string>;
3636
- /**
3637
- * Known legacy Extended CSS attributes. These attributes are deprecated and
3638
- * should be replaced with the corresponding pseudo-classes. In a long term,
3639
- * these attributes will be COMPLETELY removed from the Extended CSS syntax.
3640
- *
3641
- * Please, keep this list sorted.
3642
- */
3643
- declare const EXT_CSS_LEGACY_ATTRIBUTES: Set<string>;
3644
- /**
3645
- * Known CSS functions that aren't allowed in CSS injection rules, because they
3646
- * able to load external resources. Please, keep this list sorted.
3647
- */
3648
- declare const FORBIDDEN_CSS_FUNCTIONS: Set<string>;
3649
-
3650
- /**
3651
- * @file Base compatibility data schema, which is commonly used in compatibility tables.
3652
- */
3653
-
3654
- /**
3655
- * Zod schema for base compatibility data with camelCase properties.
3656
- */
3657
- declare const baseCompatibilityDataSchemaCamelCase: zod.ZodEffects<zod.ZodTypeAny, {
3658
- name: string;
3659
- description: string | null;
3660
- aliases: string[] | null;
3661
- docs: string | null;
3662
- versionAdded: string | null;
3663
- versionRemoved: string | null;
3664
- deprecated: boolean;
3665
- deprecationMessage: string | null;
3666
- removed: boolean;
3667
- removalMessage: string | null;
3668
- }, any>;
3669
- /**
3670
- * Type of the base compatibility data schema.
3671
- */
3672
- type BaseCompatibilityDataSchema = zod.infer<typeof baseCompatibilityDataSchemaCamelCase>;
3673
-
3674
- /**
3675
- * @file Schema for modifier data.
3676
- */
3677
-
3678
- /**
3679
- * Zod schema for modifier data.
3680
- */
3681
- declare const modifierDataSchema: zod.ZodEffects<zod.ZodTypeAny, {
3682
- name: string;
3683
- description: string | null;
3684
- aliases: string[] | null;
3685
- docs: string | null;
3686
- versionAdded: string | null;
3687
- versionRemoved: string | null;
3688
- deprecated: boolean;
3689
- deprecationMessage: string | null;
3690
- removed: boolean;
3691
- removalMessage: string | null;
3692
- conflicts: string[] | null;
3693
- inverseConflicts: boolean;
3694
- assignable: boolean;
3695
- negatable: boolean;
3696
- blockOnly: boolean;
3697
- exceptionOnly: boolean;
3698
- valueOptional: boolean;
3699
- valueFormat: string | null;
3700
- }, any>;
3701
- /**
3702
- * Type of the modifier data schema.
3703
- */
3704
- type ModifierDataSchema = zod.infer<typeof modifierDataSchema>;
3705
-
3706
- /**
3707
- * @file Resource type schema.
3708
- */
3709
-
3710
- /**
3711
- * Resource type.
3712
- *
3713
- * @see {@link https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-ResourceType}
3714
- */
3715
- declare enum ResourceType {
3716
- MainFrame = "main_frame",
3717
- SubFrame = "sub_frame",
3718
- Stylesheet = "stylesheet",
3719
- Script = "script",
3720
- Image = "image",
3721
- Font = "font",
3722
- Object = "object",
3723
- XmlHttpRequest = "xmlhttprequest",
3724
- Ping = "ping",
3725
- Media = "media",
3726
- WebSocket = "websocket",
3727
- Other = "other"
3728
- }
3729
-
3730
- /**
3731
- * Zod schema for redirect data.
3732
- */
3733
- declare const redirectDataSchema: zod.ZodEffects<zod.ZodTypeAny, {
3734
- name: string;
3735
- description: string | null;
3736
- aliases: string[] | null;
3737
- docs: string | null;
3738
- versionAdded: string | null;
3739
- versionRemoved: string | null;
3740
- deprecated: boolean;
3741
- deprecationMessage: string | null;
3742
- removed: boolean;
3743
- removalMessage: string | null;
3744
- isBlocking: boolean;
3745
- resourceTypes: ResourceType[];
3746
- }, any>;
3747
- /**
3748
- * Type of the redirect data schema.
3749
- */
3750
- type RedirectDataSchema = zod.infer<typeof redirectDataSchema>;
3751
-
3752
- /**
3753
- * @file Schema for scriptlet data.
3754
- */
3755
-
3756
- /**
3757
- * Zod schema for scriptlet data.
3758
- */
3759
- declare const scriptletDataSchema: zod.ZodEffects<zod.ZodTypeAny, {
3760
- name: string;
3761
- description: string | null;
3762
- aliases: string[] | null;
3763
- docs: string | null;
3764
- versionAdded: string | null;
3765
- versionRemoved: string | null;
3766
- deprecated: boolean;
3767
- deprecationMessage: string | null;
3768
- removed: boolean;
3769
- removalMessage: string | null;
3770
- parameters?: {
3771
- name: string;
3772
- debug: boolean;
3773
- pattern: string | null;
3774
- description: string | null;
3775
- default: string | null;
3776
- required: boolean;
3777
- }[] | undefined;
3778
- }, any>;
3779
- /**
3780
- * Type of the scriptlet data schema.
3781
- */
3782
- type ScriptletDataSchema = zod.infer<typeof scriptletDataSchema>;
3783
-
3784
- /**
3785
- * @file Platform schema.
3786
- */
3787
-
3788
- /**
3789
- * Parses a raw platform string into a platform bitmask.
3790
- *
3791
- * @param rawPlatforms Raw platform string, e.g. 'adg_safari_any|adg_os_any'.
3792
- *
3793
- * @returns Platform bitmask.
3794
- */
3795
- declare const parseRawPlatforms: (rawPlatforms: string) => number;
3796
-
3797
- /**
3798
- * @file Provides platform enums.
3799
- * The difference between specific and generic platforms is that specific platforms are individual platforms
3800
- * (e.g. AdGuard for Windows, AdGuard for Android, etc.),
3801
- * while generic platforms are groups of specific platforms
3802
- * (e.g. AdGuard for any OS, AdGuard for any Chromium-based extension, etc.).
3803
- */
3804
- /**
3805
- * List of specific platforms.
3806
- */
3807
- declare enum SpecificPlatform {
3808
- AdgOsWindows = 1,
3809
- AdgOsMac = 2,
3810
- AdgOsAndroid = 4,
3811
- AdgExtChrome = 8,
3812
- AdgExtOpera = 16,
3813
- AdgExtEdge = 32,
3814
- AdgExtFirefox = 64,
3815
- AdgCbAndroid = 128,
3816
- AdgCbIos = 256,
3817
- AdgCbSafari = 512,
3818
- UboExtChrome = 1024,
3819
- UboExtOpera = 2048,
3820
- UboExtEdge = 4096,
3821
- UboExtFirefox = 8192,
3822
- AbpExtChrome = 16384,
3823
- AbpExtOpera = 32768,
3824
- AbpExtEdge = 65536,
3825
- AbpExtFirefox = 131072
3826
- }
3827
- /**
3828
- * List of generic platforms (combinations of specific platforms).
3829
- */
3830
- declare enum GenericPlatform {
3831
- AdgOsAny = 7,
3832
- AdgSafariAny = 768,
3833
- AdgExtChromium = 56,
3834
- AdgExtAny = 120,
3835
- AdgAny = 1023,
3836
- UboExtChromium = 7168,
3837
- UboExtAny = 15360,
3838
- UboAny = 15360,
3839
- AbpExtChromium = 114688,
3840
- AbpExtAny = 245760,
3841
- AbpAny = 245760,
3842
- Any = 262143
3843
- }
3844
-
3845
- /**
3846
- * @file Compatibility tables types.
3847
- */
3848
- /**
3849
- * Map with shared storage.
3850
- * The idea is to avoid storing the same value multiple times in the map,
3851
- * so the value is stored in the `shared` array and the map refers to the index in the `shared` array.
3852
- *
3853
- * @template K Type of the map keys.
3854
- * @template V Type of the map values.
3855
- */
3856
- interface MapWithSharedStorage<K extends string | number | symbol, V> {
3857
- /**
3858
- * Shared storage.
3859
- */
3860
- shared: V[];
3861
- /**
3862
- * Map of the values where the value is a pointer to the shared storage (refers to the index in the `shared` array).
3863
- */
3864
- map: Record<K, number>;
3865
- }
3866
- /**
3867
- * Compatibility table row.
3868
- *
3869
- * @template T Type of the compatibility data.
3870
- */
3871
- type CompatibilityTableRow<T> = MapWithSharedStorage<number, T>;
3872
- /**
3873
- * Compatibility table.
3874
- *
3875
- * @template T Type of the compatibility data.
3876
- */
3877
- type CompatibilityTable<T> = MapWithSharedStorage<string, CompatibilityTableRow<T>>;
3878
-
3879
- /**
3880
- * @file Provides common compatibility table methods.
3881
- */
3882
-
3883
- /**
3884
- * Lists all supported entity records by a product.
3885
- *
3886
- * Keys are compatibility flags, values are compatibility data records.
3887
- *
3888
- * @template T Compatibility data schema.
3889
- */
3890
- type ProductRecords<T> = {
3891
- [key: string]: T;
3892
- };
3893
- /**
3894
- * Defines a compatibility table row by product.
3895
- *
3896
- * Keys are Adblock syntaxes, values are product records.
3897
- *
3898
- * @template T Compatibility data schema.
3899
- */
3900
- type RowByProduct<T> = {
3901
- [AdblockSyntax.Adg]: ProductRecords<T>;
3902
- [AdblockSyntax.Ubo]: ProductRecords<T>;
3903
- [AdblockSyntax.Abp]: ProductRecords<T>;
3904
- };
3905
- /**
3906
- * Defines multiple compatibility table rows by product.
3907
- *
3908
- * @template T Compatibility data schema.
3909
- */
3910
- type RowsByProduct<T> = RowByProduct<T>[];
3911
- /**
3912
- * Single platform records type.
3913
- *
3914
- * Keys are platform enums values, values are compatibility data records.
3915
- *
3916
- * @template T Compatibility data schema.
3917
- */
3918
- type SinglePlatformRecords<T> = {
3919
- [key: string]: T;
3920
- };
3921
- /**
3922
- * Name transformer function type. This function is used to normalize compatibility data names before processing them,
3923
- * e.g. converting to lowercase, remove unnecessary prefixes, etc.
3924
- *
3925
- * @param name Compatibility data name.
3926
- *
3927
- * @returns Normalized name.
3928
- */
3929
- type NameTransformer = (name: string) => string;
3930
- /**
3931
- * Base compatibility table class which provides common methods to work with compatibility data.
3932
- *
3933
- * @template T Compatibility data schema.
3934
- */
3935
- declare abstract class CompatibilityTableBase<T extends BaseCompatibilityDataSchema> {
3936
- /**
3937
- * Compatibility table data.
3938
- */
3939
- private data;
3940
- /**
3941
- * Optional name transformer function. If provided,
3942
- * it will be called in all methods before processing compatibility data names.
3943
- */
3944
- private readonly nameTransformer;
3945
- /**
3946
- * Creates a new instance of the common compatibility table.
3947
- *
3948
- * @param data Compatibility table data.
3949
- * @param nameTransformer Optional name transformer function.
3950
- */
3951
- constructor(data: CompatibilityTable<T>, nameTransformer?: NameTransformer | null);
3952
- /**
3953
- * Helper method to get a 'row' from the compatibility table data by name.
3954
- *
3955
- * @param name Compatibility data name.
3956
- * @returns Compatibility table row storage or `null` if not found.
3957
- */
3958
- private getRowStorage;
3959
- /**
3960
- * Checks whether a compatibility data `name` exists for any platform.
3961
- *
3962
- * @note Technically, do the same as `exists()` method with generic platform _any_
3963
- * but it is faster because it does not apply complex logic.
3964
- *
3965
- * @param name Compatibility data name.
3966
- *
3967
- * @returns True if the compatibility data exists, false otherwise.
3968
- */
3969
- existsAny(name: string): boolean;
3970
- /**
3971
- * Checks whether a compatibility data `name` exists for a specified platform.
3972
- *
3973
- * @param name Compatibility data name.
3974
- * @param platform Specific or generic platform.
3975
- *
3976
- * @returns True if the compatibility data exists, false otherwise.
3977
- */
3978
- exists(name: string, platform: SpecificPlatform | GenericPlatform): boolean;
3979
- /**
3980
- * Returns a compatibility data by name and specific platform.
3981
- *
3982
- * @param name The name of the compatibility data.
3983
- * @param platform The specific platform.
3984
- *
3985
- * @returns A single compatibility data or `null` if not found.
3986
- */
3987
- getSingle(name: string, platform: SpecificPlatform): T | null;
3988
- /**
3989
- * Returns all compatibility data records for name and specified platform.
3990
- *
3991
- * @param name Compatibility data name.
3992
- * @param platform Specific or generic platform.
3993
- *
3994
- * @returns Multiple records grouped by platforms.
3995
- * Technically, it is an object where keys are platform enums values and values are compatibility data records.
3996
- *
3997
- * @note Platform enum values can be converted to string names using {@link getSpecificPlatformName} on demand.
3998
- */
3999
- getMultiple(name: string, platform: SpecificPlatform | GenericPlatform): SinglePlatformRecords<T> | null;
4000
- /**
4001
- * Returns all compatibility data records for the specified platform.
4002
- *
4003
- * @param platform Specific or generic platform.
4004
- *
4005
- * @returns Array of multiple records grouped by platforms.
4006
- */
4007
- getAllMultiple(platform: SpecificPlatform | GenericPlatform): SinglePlatformRecords<T>[];
4008
- /**
4009
- * Returns the first compatibility data record for name and specified platform.
4010
- *
4011
- * @param name Compatibility data name.
4012
- * @param platform Specific or generic platform.
4013
- *
4014
- * @returns First found compatibility data record or `null` if not found.
4015
- */
4016
- getFirst(name: string, platform: SpecificPlatform | GenericPlatform): T | null;
4017
- /**
4018
- * Returns all compatibility data records for the specified name.
4019
- *
4020
- * @param name Compatibility data name.
4021
- *
4022
- * @returns Array of multiple records grouped by platforms.
4023
- */
4024
- getRow(name: string): T[];
4025
- /**
4026
- * Returns all compatibility data grouped by products.
4027
- *
4028
- * @returns Array of multiple records grouped by products.
4029
- */
4030
- getRowsByProduct(): RowsByProduct<T>;
4031
- }
4032
-
4033
- /**
4034
- * @file Compatibility tables for modifiers.
4035
- */
4036
-
4037
- /**
4038
- * Compatibility table for modifiers.
4039
- */
4040
- declare class ModifiersCompatibilityTable extends CompatibilityTableBase<ModifierDataSchema> {
4041
- /**
4042
- * Creates a new instance of the compatibility table for modifiers.
4043
- *
4044
- * @param data Compatibility table data.
4045
- */
4046
- constructor(data: CompatibilityTable<ModifierDataSchema>);
4047
- }
4048
- /**
4049
- * Compatibility table instance for modifiers.
4050
- */
4051
- declare const modifiersCompatibilityTable: ModifiersCompatibilityTable;
4052
-
4053
- /**
4054
- * @file Compatibility tables for redirects.
4055
- */
4056
-
4057
- /**
4058
- * Compatibility table for redirects.
4059
- */
4060
- declare class RedirectsCompatibilityTable extends CompatibilityTableBase<RedirectDataSchema> {
4061
- /**
4062
- * Creates a new instance of the compatibility table for redirects.
4063
- *
4064
- * @param data Compatibility table data.
4065
- */
4066
- constructor(data: CompatibilityTable<RedirectDataSchema>);
4067
- /**
4068
- * Gets the resource type adblock modifiers for the redirect for the given platform
4069
- * based on the `resourceTypes` field.
4070
- *
4071
- * @param redirect Redirect name or redirect data.
4072
- * @param platform Platform to get the modifiers for.
4073
- *
4074
- * @returns Set of resource type modifiers or an empty set if the redirect is not found or has no resource types.
4075
- */
4076
- getResourceTypeModifiers(redirect: string | RedirectDataSchema, platform: SpecificPlatform | GenericPlatform): Set<string>;
4077
- }
4078
- /**
4079
- * Compatibility table instance for redirects.
4080
- */
4081
- declare const redirectsCompatibilityTable: RedirectsCompatibilityTable;
4082
-
4083
- /**
4084
- * @file Compatibility tables for scriptlets.
4085
- */
4086
-
4087
- /**
4088
- * Compatibility table for scriptlets.
4089
- */
4090
- declare class ScriptletsCompatibilityTable extends CompatibilityTableBase<ScriptletDataSchema> {
4091
- }
4092
- /**
4093
- * Compatibility table instance for scriptlets.
4094
- */
4095
- declare const scriptletsCompatibilityTable: ScriptletsCompatibilityTable;
4096
-
4097
- /**
4098
- * @file Provides platform mapping and helper functions.
4099
- */
4100
-
4101
- /**
4102
- * Check if the platform is a generic platform.
4103
- *
4104
- * @param platform Platform to check.
4105
- *
4106
- * @returns True if the platform is a generic platform, false otherwise.
4107
- */
4108
- declare const isGenericPlatform: (platform: number) => boolean;
4109
- /**
4110
- * Returns the platform enum value for the given platform string name.
4111
- *
4112
- * @param platform Platform string name, e.g., 'adg_os_windows'.
4113
- *
4114
- * @returns Specific or generic platform enum value.
4115
- * @throws Error if the platform is unknown.
4116
- */
4117
- declare const getPlatformId: (platform: string) => SpecificPlatform | GenericPlatform;
4118
- /**
4119
- * Returns the specific platform string name for the given platform enum value.
4120
- *
4121
- * @param platform Specific platform enum value.
4122
- *
4123
- * @returns Specific platform string name, e.g., 'adg_os_windows'.
4124
- * @throws Error if the platform is unknown.
4125
- */
4126
- declare const getSpecificPlatformName: (platform: SpecificPlatform) => string;
4127
-
4128
- /**
4129
- * Gets the adblock modifier name for the given resource type.
4130
- *
4131
- * @param resourceType Resource type to get the modifier name for.
4132
- * @param platform Platform to get the modifier for.
4133
- *
4134
- * @returns A string containing the adblock modifier name for the given resource type
4135
- * or `null` if the modifier could not be found.
4136
- */
4137
- declare const getResourceTypeModifier: (resourceType: ResourceType, platform: SpecificPlatform | GenericPlatform) => string | null;
4138
- /**
4139
- * Checks if the given resource type is valid.
4140
- *
4141
- * @param resourceType Resource type to check.
4142
- *
4143
- * @returns `true` if the resource type is valid, `false` otherwise.
4144
- */
4145
- declare const isValidResourceType: (resourceType: string) => boolean;
4146
-
4147
- /**
4148
- * @file AGTree version
4149
- */
4150
- declare const AGTREE_VERSION: string;
4151
-
4152
- export { ADBLOCK_URL_SEPARATOR, ADBLOCK_URL_SEPARATOR_REGEX, ADBLOCK_URL_START, ADBLOCK_URL_START_REGEX, ADBLOCK_WILDCARD, ADBLOCK_WILDCARD_REGEX, ADG_SCRIPTLET_MASK, AGLINT_COMMAND_PREFIX, AGTREE_VERSION, AdblockSyntax, AdblockSyntaxError, Agent, AgentCommentRule, AgentCommentRuleParser, AgentParser, AnyCommentRule, AnyCosmeticRule, AnyExpressionNode, AnyNetworkRule, AnyRule, AppListParser, BINARY_SCHEMA_VERSION, BinarySchemaMismatchError, ByteBuffer, COMMA_DOMAIN_LIST_SEPARATOR, CommentBase, CommentMarker, CommentRule, CommentRuleParser, CommentRuleType, CompatibilityTable, CompatibilityTableRow, ConfigCommentRule, ConfigCommentRuleParser, CosmeticRule, CosmeticRuleParser, CosmeticRuleSeparator, CosmeticRuleSeparatorFinderResult, CosmeticRuleSeparatorUtils, CosmeticRuleType, CssInjectionRule, CssInjectionRuleBody, Domain, DomainList, DomainListParser, DomainListSeparator, DomainUtils, EXT_CSS_LEGACY_ATTRIBUTES, EXT_CSS_PSEUDO_CLASSES, ElementHidingRule, ElementHidingRuleBody, EmptyRule, ExpressionOperatorNode, ExpressionParenthesisNode, ExpressionVariableNode, FORBIDDEN_CSS_FUNCTIONS, FilterList, FilterListConverter, FilterListParser, GenericPlatform, HINT_MARKER, Hint, HintCommentRule, HintCommentRuleParser, HintParser, HostRule, HostRuleParser, HostnameList, HtmlFilteringRule, HtmlFilteringRuleBody, IF, INCLUDE, InputByteBuffer, JsInjectionRule, KNOWN_METADATA_HEADERS, Location, LocationRange, LogicalExpressionParser, LogicalExpressionUtils, MODIFIERS_SEPARATOR, MODIFIER_ASSIGN_OPERATOR, MetadataCommentRule, MetadataCommentRuleParser, MethodListParser, Modifier, ModifierList, ModifierListParser, ModifierParser, NEGATION_MARKER, NETWORK_RULE_EXCEPTION_MARKER, NETWORK_RULE_SEPARATOR, NetworkRule, NetworkRuleParser, NetworkRuleType, Node, NotImplementedError, OutputByteBuffer, PIPE_MODIFIER_SEPARATOR, PREPROCESSOR_MARKER, ParameterList, ParameterListParser, ParserOptions, Position, PositionProvider, PreProcessorCommentRule, PreProcessorCommentRuleParser, ProductRecords, QuoteType, QuoteUtils, RawFilterListConverter, RawRuleConverter, RegExpUtils, ResourceType, RowByProduct, RowsByProduct, RuleBase, RuleCategorizer, RuleCategory, RuleConversionError, RuleConverter, RuleParser, SAFARI_CB_AFFINITY, SPECIAL_REGEX_SYMBOLS, ScriptletInjectionRule, ScriptletInjectionRuleBody, SpecificPlatform, StealthOptionListParser, TextEncoderPolyfillResult, UBO_SCRIPTLET_MASK, Value, VariableTable, decodeTextPolyfill, defaultParserOptions, encodeIntoPolyfill, getPlatformId, getResourceTypeModifier, getSpecificPlatformName, isGenericPlatform, isValidResourceType, modifierValidator, modifiersCompatibilityTable, parseRawPlatforms, redirectsCompatibilityTable, scriptletsCompatibilityTable };