@adguard/agtree 2.0.0-alpha.0 → 2.0.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.
- package/README.md +12 -0
- package/dist/agtree.cjs +2056 -1384
- package/dist/agtree.d.ts +80 -9
- package/dist/agtree.esm.js +2055 -1385
- package/dist/agtree.iife.min.js +5 -5
- package/dist/agtree.umd.min.js +5 -5
- package/dist/build.txt +1 -1
- package/dist/compatibility-tables.json +286 -98
- package/package.json +2 -2
package/dist/agtree.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v2.0.
|
|
2
|
+
* AGTree v2.0.1 (build date: Fri, 06 Sep 2024 12:11:38 GMT)
|
|
3
3
|
* (c) 2024 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -132,9 +132,13 @@ declare const IF = "if";
|
|
|
132
132
|
declare const INCLUDE = "include";
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
135
|
+
* Possible operators in the logical expression.
|
|
136
136
|
*/
|
|
137
|
-
|
|
137
|
+
declare const enum OperatorValue {
|
|
138
|
+
Not = "!",
|
|
139
|
+
And = "&&",
|
|
140
|
+
Or = "||"
|
|
141
|
+
}
|
|
138
142
|
/**
|
|
139
143
|
* Represents possible new line types.
|
|
140
144
|
*/
|
|
@@ -392,7 +396,7 @@ interface ExpressionVariableNode extends Node {
|
|
|
392
396
|
*/
|
|
393
397
|
interface ExpressionOperatorNode extends Node {
|
|
394
398
|
type: 'Operator';
|
|
395
|
-
operator:
|
|
399
|
+
operator: OperatorValue;
|
|
396
400
|
left: AnyExpressionNode;
|
|
397
401
|
right?: AnyExpressionNode;
|
|
398
402
|
}
|
|
@@ -1498,16 +1502,23 @@ declare class OutputByteBuffer extends ByteBuffer {
|
|
|
1498
1502
|
*/
|
|
1499
1503
|
private offset;
|
|
1500
1504
|
/**
|
|
1501
|
-
* Size of the shared buffer for encoding strings.
|
|
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).
|
|
1502
1509
|
*/
|
|
1503
1510
|
private static readonly ENCODER_BUFFER_SIZE;
|
|
1504
1511
|
/**
|
|
1505
|
-
*
|
|
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).
|
|
1506
1517
|
*/
|
|
1507
1518
|
private static readonly SHORT_STRING_THRESHOLD;
|
|
1508
1519
|
/**
|
|
1509
1520
|
* Represents the maximum value that can be written as a 'storage optimized' unsigned integer.
|
|
1510
|
-
* 0x1FFFFFFF means 32 bits minus 3 bits
|
|
1521
|
+
* 0x1FFFFFFF means 29 bits — 32 bits minus 3 bits — because the last bit in each byte is a flag indicating
|
|
1511
1522
|
* if there are more bytes (except for the last byte).
|
|
1512
1523
|
*/
|
|
1513
1524
|
static MAX_OPTIMIZED_UINT: number;
|
|
@@ -3263,6 +3274,16 @@ declare class RuleConverter extends RuleConverterBase {
|
|
|
3263
3274
|
* @throws If the rule is invalid or cannot be converted
|
|
3264
3275
|
*/
|
|
3265
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>;
|
|
3266
3287
|
}
|
|
3267
3288
|
|
|
3268
3289
|
/**
|
|
@@ -3679,9 +3700,29 @@ declare const modifierDataSchema: zod.ZodEffects<zod.ZodTypeAny, {
|
|
|
3679
3700
|
type ModifierDataSchema = zod.infer<typeof modifierDataSchema>;
|
|
3680
3701
|
|
|
3681
3702
|
/**
|
|
3682
|
-
* @file
|
|
3703
|
+
* @file Resource type schema.
|
|
3683
3704
|
*/
|
|
3684
3705
|
|
|
3706
|
+
/**
|
|
3707
|
+
* Resource type.
|
|
3708
|
+
*
|
|
3709
|
+
* @see {@link https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-ResourceType}
|
|
3710
|
+
*/
|
|
3711
|
+
declare enum ResourceType {
|
|
3712
|
+
MainFrame = "main_frame",
|
|
3713
|
+
SubFrame = "sub_frame",
|
|
3714
|
+
Stylesheet = "stylesheet",
|
|
3715
|
+
Script = "script",
|
|
3716
|
+
Image = "image",
|
|
3717
|
+
Font = "font",
|
|
3718
|
+
Object = "object",
|
|
3719
|
+
XmlHttpRequest = "xmlhttprequest",
|
|
3720
|
+
Ping = "ping",
|
|
3721
|
+
Media = "media",
|
|
3722
|
+
WebSocket = "websocket",
|
|
3723
|
+
Other = "other"
|
|
3724
|
+
}
|
|
3725
|
+
|
|
3685
3726
|
/**
|
|
3686
3727
|
* Zod schema for redirect data.
|
|
3687
3728
|
*/
|
|
@@ -3697,6 +3738,7 @@ declare const redirectDataSchema: zod.ZodEffects<zod.ZodTypeAny, {
|
|
|
3697
3738
|
removed: boolean;
|
|
3698
3739
|
removalMessage: string | null;
|
|
3699
3740
|
isBlocking: boolean;
|
|
3741
|
+
resourceTypes: ResourceType[];
|
|
3700
3742
|
}, any>;
|
|
3701
3743
|
/**
|
|
3702
3744
|
* Type of the redirect data schema.
|
|
@@ -4018,6 +4060,16 @@ declare class RedirectsCompatibilityTable extends CompatibilityTableBase<Redirec
|
|
|
4018
4060
|
* @param data Compatibility table data.
|
|
4019
4061
|
*/
|
|
4020
4062
|
constructor(data: CompatibilityTable<RedirectDataSchema>);
|
|
4063
|
+
/**
|
|
4064
|
+
* Gets the resource type adblock modifiers for the redirect for the given platform
|
|
4065
|
+
* based on the `resourceTypes` field.
|
|
4066
|
+
*
|
|
4067
|
+
* @param redirect Redirect name or redirect data.
|
|
4068
|
+
* @param platform Platform to get the modifiers for.
|
|
4069
|
+
*
|
|
4070
|
+
* @returns Set of resource type modifiers or an empty set if the redirect is not found or has no resource types.
|
|
4071
|
+
*/
|
|
4072
|
+
getResourceTypeModifiers(redirect: string | RedirectDataSchema, platform: SpecificPlatform | GenericPlatform): Set<string>;
|
|
4021
4073
|
}
|
|
4022
4074
|
/**
|
|
4023
4075
|
* Compatibility table instance for redirects.
|
|
@@ -4069,9 +4121,28 @@ declare const getPlatformId: (platform: string) => SpecificPlatform | GenericPla
|
|
|
4069
4121
|
*/
|
|
4070
4122
|
declare const getSpecificPlatformName: (platform: SpecificPlatform) => string;
|
|
4071
4123
|
|
|
4124
|
+
/**
|
|
4125
|
+
* Gets the adblock modifier name for the given resource type.
|
|
4126
|
+
*
|
|
4127
|
+
* @param resourceType Resource type to get the modifier name for.
|
|
4128
|
+
* @param platform Platform to get the modifier for.
|
|
4129
|
+
*
|
|
4130
|
+
* @returns A string containing the adblock modifier name for the given resource type
|
|
4131
|
+
* or `null` if the modifier could not be found.
|
|
4132
|
+
*/
|
|
4133
|
+
declare const getResourceTypeModifier: (resourceType: ResourceType, platform: SpecificPlatform | GenericPlatform) => string | null;
|
|
4134
|
+
/**
|
|
4135
|
+
* Checks if the given resource type is valid.
|
|
4136
|
+
*
|
|
4137
|
+
* @param resourceType Resource type to check.
|
|
4138
|
+
*
|
|
4139
|
+
* @returns `true` if the resource type is valid, `false` otherwise.
|
|
4140
|
+
*/
|
|
4141
|
+
declare const isValidResourceType: (resourceType: string) => boolean;
|
|
4142
|
+
|
|
4072
4143
|
/**
|
|
4073
4144
|
* @file AGTree version
|
|
4074
4145
|
*/
|
|
4075
4146
|
declare const AGTREE_VERSION: string;
|
|
4076
4147
|
|
|
4077
|
-
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,
|
|
4148
|
+
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 };
|