@adguard/agtree 3.4.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast-utils/clone.js +2 -2
- package/dist/ast-utils/modifiers.js +2 -2
- package/dist/ast-utils/network-rules.js +2 -2
- package/dist/ast-utils/scriptlets.js +2 -2
- package/dist/common/abp-snippet-injection-body-common.js +2 -2
- package/dist/common/agent-common.js +2 -2
- package/dist/common/ubo-html-filtering-body-common.js +40 -0
- package/dist/common/ubo-selector-common.js +2 -2
- package/dist/compatibility-tables/base.js +2 -2
- package/dist/compatibility-tables/compatibility-table-data.js +4 -4
- package/dist/compatibility-tables/modifiers.js +2 -2
- package/dist/compatibility-tables/platforms.js +2 -2
- package/dist/compatibility-tables/redirects.js +2 -2
- package/dist/compatibility-tables/schemas/base.js +2 -2
- package/dist/compatibility-tables/schemas/modifier.js +2 -2
- package/dist/compatibility-tables/schemas/platform.js +2 -2
- package/dist/compatibility-tables/schemas/redirect.js +2 -2
- package/dist/compatibility-tables/schemas/resource-type.js +2 -2
- package/dist/compatibility-tables/schemas/scriptlet.js +2 -2
- package/dist/compatibility-tables/scriptlets.js +2 -2
- package/dist/compatibility-tables/utils/platform-helpers.js +2 -2
- package/dist/compatibility-tables/utils/resource-type-helpers.js +2 -2
- package/dist/compatibility-tables/utils/zod-camelcase.js +2 -2
- package/dist/converter/base-interfaces/base-converter.js +2 -2
- package/dist/converter/base-interfaces/conversion-result.js +2 -2
- package/dist/converter/base-interfaces/rule-converter-base.js +2 -2
- package/dist/converter/comment/index.js +2 -2
- package/dist/converter/cosmetic/css.js +2 -2
- package/dist/converter/cosmetic/element-hiding.js +2 -2
- package/dist/converter/cosmetic/header-removal.js +24 -42
- package/dist/converter/cosmetic/html.js +580 -438
- package/dist/converter/cosmetic/index.js +3 -2
- package/dist/converter/cosmetic/rule-modifiers/adg.js +2 -2
- package/dist/converter/cosmetic/rule-modifiers/ubo.js +2 -2
- package/dist/converter/cosmetic/scriptlet.js +2 -2
- package/dist/converter/css/index.js +3 -2
- package/dist/converter/data/css.js +32 -54
- package/dist/converter/filter-list.js +2 -2
- package/dist/converter/index.js +2 -2
- package/dist/converter/misc/network-rule-modifier.js +2 -2
- package/dist/converter/network/index.js +2 -2
- package/dist/converter/raw-filter-list.js +2 -2
- package/dist/converter/raw-rule.js +6 -3
- package/dist/converter/rule.js +2 -2
- package/dist/errors/adblock-syntax-error.js +2 -2
- package/dist/errors/binary-schema-mismatch-error.js +2 -2
- package/dist/errors/not-implemented-error.js +2 -2
- package/dist/errors/rule-conversion-error.js +2 -2
- package/dist/generator/base-generator.js +2 -2
- package/dist/generator/comment/agent-comment-generator.js +2 -2
- package/dist/generator/comment/agent-generator.js +2 -2
- package/dist/generator/comment/comment-rule-generator.js +2 -2
- package/dist/generator/comment/config-comment-generator.js +2 -2
- package/dist/generator/comment/hint-comment-generator.js +2 -2
- package/dist/generator/comment/hint-generator.js +2 -2
- package/dist/generator/comment/metadata-comment-generator.js +2 -2
- package/dist/generator/comment/pre-processor-comment-generator.js +2 -2
- package/dist/generator/comment/simple-comment-generator.js +2 -2
- package/dist/generator/cosmetic/cosmetic-rule-body-generator.js +21 -6
- package/dist/generator/cosmetic/cosmetic-rule-generator.js +2 -2
- package/dist/generator/cosmetic/cosmetic-rule-pattern-generator.js +2 -2
- package/dist/generator/cosmetic/html-filtering-body/adg-html-filtering-body-generator.js +38 -0
- package/dist/generator/cosmetic/html-filtering-body/html-filtering-body-generator.js +32 -0
- package/dist/generator/cosmetic/html-filtering-body/ubo-html-filtering-body-generator.js +65 -0
- package/dist/generator/cosmetic/{body → scriptlet-body}/abp-snippet-injection-body-generator.js +2 -2
- package/dist/generator/cosmetic/{body → scriptlet-body}/adg-scriptlet-injection-body-generator.js +2 -2
- package/dist/generator/cosmetic/{body → scriptlet-body}/ubo-scriptlet-injection-body-generator.js +2 -2
- package/dist/generator/cosmetic/selector/attribute-selector-generator.js +42 -0
- package/dist/generator/cosmetic/selector/class-selector-generator.js +26 -0
- package/dist/generator/cosmetic/selector/complex-selector-generator.js +71 -0
- package/dist/generator/cosmetic/selector/id-selector-generator.js +26 -0
- package/dist/generator/cosmetic/selector/pseudo-class-selector-generator.js +35 -0
- package/dist/generator/cosmetic/selector/selector-combinator-generator.js +30 -0
- package/dist/generator/cosmetic/selector/selector-list-generator.js +41 -0
- package/dist/generator/cosmetic/selector/type-selector-generator.js +25 -0
- package/dist/generator/css/adg-css-injection-generator.js +5 -6
- package/dist/generator/filterlist-generator.js +2 -2
- package/dist/generator/index.js +2 -2
- package/dist/generator/misc/domain-list-generator.js +2 -2
- package/dist/generator/misc/list-items-generator.js +2 -2
- package/dist/generator/misc/logical-expression-generator.js +2 -2
- package/dist/generator/misc/modifier-generator.js +2 -2
- package/dist/generator/misc/modifier-list-generator.js +2 -2
- package/dist/generator/misc/parameter-list-generator.js +2 -2
- package/dist/generator/misc/value-generator.js +2 -2
- package/dist/generator/network/host-rule-generator.js +2 -2
- package/dist/generator/network/network-rule-generator.js +2 -2
- package/dist/generator/rule-generator.js +2 -2
- package/dist/index.js +4 -14
- package/dist/nodes/index.js +2 -2
- package/dist/package.json.js +3 -3
- package/dist/parser/base-parser.js +2 -2
- package/dist/parser/comment/agent-comment-parser.js +2 -2
- package/dist/parser/comment/agent-parser.js +2 -2
- package/dist/parser/comment/comment-parser.js +2 -2
- package/dist/parser/comment/config-comment-parser.js +2 -2
- package/dist/parser/comment/hint-comment-parser.js +2 -2
- package/dist/parser/comment/hint-parser.js +2 -2
- package/dist/parser/comment/metadata-comment-parser.js +2 -2
- package/dist/parser/comment/preprocessor-parser.js +2 -2
- package/dist/parser/comment/simple-comment-parser.js +2 -2
- package/dist/parser/cosmetic/cosmetic-rule-parser.js +10 -21
- package/dist/parser/cosmetic/html-filtering-body/adg-html-filtering-body-parser.js +49 -0
- package/dist/parser/cosmetic/html-filtering-body/html-filtering-body-parser.js +70 -0
- package/dist/parser/cosmetic/html-filtering-body/ubo-html-filtering-body-parser.js +180 -0
- package/dist/parser/cosmetic/{body → scriptlet-body}/abp-snippet-injection-body-parser.js +2 -2
- package/dist/parser/cosmetic/{body → scriptlet-body}/adg-scriptlet-injection-body-parser.js +2 -2
- package/dist/parser/cosmetic/{body → scriptlet-body}/ubo-scriptlet-injection-body-parser.js +2 -2
- package/dist/parser/cosmetic/selector/handlers/attribute-selector-handler.js +206 -0
- package/dist/parser/cosmetic/selector/handlers/class-selector-handler.js +48 -0
- package/dist/parser/cosmetic/selector/handlers/complex-selector-handler.js +67 -0
- package/dist/parser/cosmetic/selector/handlers/compound-selector-handler.js +97 -0
- package/dist/parser/cosmetic/selector/handlers/id-selector-handler.js +42 -0
- package/dist/parser/cosmetic/selector/handlers/pseudo-class-selector-handler.js +128 -0
- package/dist/parser/cosmetic/selector/handlers/type-selector-handler.js +58 -0
- package/dist/parser/cosmetic/selector/selector-list-parser.js +164 -0
- package/dist/parser/css/adg-css-injection-parser.js +4 -5
- package/dist/parser/css/balancing.js +2 -2
- package/dist/parser/css/constants.js +2 -2
- package/dist/parser/css/css-token-stream.js +41 -4
- package/dist/parser/css/ubo-selector-parser.js +2 -2
- package/dist/parser/filterlist-parser.js +2 -2
- package/dist/parser/index.js +2 -2
- package/dist/parser/misc/app-list-parser.js +2 -2
- package/dist/parser/misc/domain-list-parser.js +2 -2
- package/dist/parser/misc/list-items-parser.js +2 -2
- package/dist/parser/misc/logical-expression-parser.js +2 -2
- package/dist/parser/misc/method-list-parser.js +2 -2
- package/dist/parser/misc/modifier-list.js +9 -3
- package/dist/parser/misc/modifier-parser.js +2 -2
- package/dist/parser/misc/parameter-list-parser.js +2 -2
- package/dist/parser/misc/stealth-option-list-parser.js +2 -2
- package/dist/parser/misc/ubo-parameter-list-parser.js +2 -2
- package/dist/parser/misc/value-parser.js +2 -2
- package/dist/parser/network/host-rule-parser.js +2 -2
- package/dist/parser/network/network-rule-parser.js +2 -2
- package/dist/parser/options.js +3 -2
- package/dist/parser/rule-parser.js +2 -2
- package/dist/types/common/ubo-html-filtering-body-common.d.ts +12 -0
- package/dist/types/compatibility-tables/compatibility-table-data.d.ts +3 -3
- package/dist/types/compatibility-tables/schemas/redirect.d.ts +1 -1
- package/dist/types/compatibility-tables/schemas/scriptlet.d.ts +2 -2
- package/dist/types/converter/cosmetic/html.d.ts +167 -42
- package/dist/types/converter/data/css.d.ts +18 -6
- package/dist/types/generator/cosmetic/html-filtering-body/adg-html-filtering-body-generator.d.ts +17 -0
- package/dist/types/generator/cosmetic/html-filtering-body/html-filtering-body-generator.d.ts +17 -0
- package/dist/types/generator/cosmetic/html-filtering-body/ubo-html-filtering-body-generator.d.ts +30 -0
- package/dist/types/generator/cosmetic/selector/attribute-selector-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/selector/class-selector-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/selector/complex-selector-generator.d.ts +17 -0
- package/dist/types/generator/cosmetic/selector/id-selector-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/selector/pseudo-class-selector-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/selector/selector-combinator-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/selector/selector-list-generator.d.ts +17 -0
- package/dist/types/generator/cosmetic/selector/type-selector-generator.d.ts +15 -0
- package/dist/types/generator/css/adg-css-injection-generator.d.ts +1 -1
- package/dist/types/index.d.ts +3 -13
- package/dist/types/nodes/index.d.ts +159 -3
- package/dist/types/parser/cosmetic/html-filtering-body/adg-html-filtering-body-parser.d.ts +35 -0
- package/dist/types/parser/cosmetic/html-filtering-body/html-filtering-body-parser.d.ts +39 -0
- package/dist/types/parser/cosmetic/html-filtering-body/ubo-html-filtering-body-parser.d.ts +63 -0
- package/dist/types/parser/cosmetic/selector/context.d.ts +42 -0
- package/dist/types/parser/cosmetic/selector/handlers/attribute-selector-handler.d.ts +35 -0
- package/dist/types/parser/cosmetic/selector/handlers/class-selector-handler.d.ts +15 -0
- package/dist/types/parser/cosmetic/selector/handlers/complex-selector-handler.d.ts +20 -0
- package/dist/types/parser/cosmetic/selector/handlers/compound-selector-handler.d.ts +25 -0
- package/dist/types/parser/cosmetic/selector/handlers/id-selector-handler.d.ts +15 -0
- package/dist/types/parser/cosmetic/selector/handlers/pseudo-class-selector-handler.d.ts +15 -0
- package/dist/types/parser/cosmetic/selector/handlers/type-selector-handler.d.ts +15 -0
- package/dist/types/parser/cosmetic/selector/selector-list-parser.d.ts +38 -0
- package/dist/types/parser/css/adg-css-injection-parser.d.ts +0 -2
- package/dist/types/parser/css/css-token-stream.d.ts +18 -0
- package/dist/types/parser/network/network-rule-parser.d.ts +1 -1
- package/dist/types/parser/options.d.ts +5 -0
- package/dist/types/utils/constants.d.ts +1 -0
- package/dist/types/utils/index.d.ts +0 -6
- package/dist/types/utils/quotes.d.ts +44 -0
- package/dist/types/utils/regexp.d.ts +24 -0
- package/dist/utils/adblockers.js +2 -2
- package/dist/utils/bit-count.js +2 -2
- package/dist/utils/categorizer.js +2 -2
- package/dist/utils/clone.js +2 -2
- package/dist/utils/constants.js +6 -9
- package/dist/utils/cosmetic-rule-separator.js +2 -2
- package/dist/utils/deep-freeze.js +2 -2
- package/dist/utils/domain.js +2 -2
- package/dist/utils/error.js +2 -2
- package/dist/utils/index.js +2 -8
- package/dist/utils/logical-expression.js +2 -2
- package/dist/utils/multi-value-map.js +2 -2
- package/dist/utils/noop-modifier.js +2 -2
- package/dist/utils/position-provider.js +2 -2
- package/dist/utils/quotes.js +163 -10
- package/dist/utils/regexp.js +31 -2
- package/dist/utils/string.js +2 -2
- package/dist/utils/type-guards.js +3 -13
- package/dist/validator/constants.js +2 -2
- package/dist/validator/helpers.js +2 -2
- package/dist/validator/index.js +2 -2
- package/dist/validator/value.js +2 -2
- package/dist/version.js +2 -2
- package/package.json +8 -16
- package/dist/deserializer/base-deserializer.js +0 -29
- package/dist/deserializer/comment/agent-comment-deserializer.js +0 -79
- package/dist/deserializer/comment/agent-deserializer.js +0 -65
- package/dist/deserializer/comment/comment-rule-deserializer.js +0 -54
- package/dist/deserializer/comment/config-comment-deserializer.js +0 -111
- package/dist/deserializer/comment/hint-comment-deserializer.js +0 -72
- package/dist/deserializer/comment/hint-deserializer.js +0 -85
- package/dist/deserializer/comment/metadata-comment-deserializer.js +0 -69
- package/dist/deserializer/comment/pre-processor-comment-deserializer.js +0 -112
- package/dist/deserializer/comment/simple-comment-deserializer.js +0 -65
- package/dist/deserializer/cosmetic/cosmetic-rule-deserializer.js +0 -131
- package/dist/deserializer/cosmetic/css-injection-body-deserializer.js +0 -56
- package/dist/deserializer/cosmetic/element-hiding-body-deserializer.js +0 -48
- package/dist/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.js +0 -39
- package/dist/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.js +0 -40
- package/dist/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.js +0 -54
- package/dist/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.js +0 -38
- package/dist/deserializer/empty-rule-deserializer.js +0 -48
- package/dist/deserializer/filterlist-deserializer.js +0 -85
- package/dist/deserializer/index.js +0 -8
- package/dist/deserializer/invalid-rule-deserializer.js +0 -50
- package/dist/deserializer/invalid-rule-error-node-deserializer.js +0 -50
- package/dist/deserializer/misc/domain-list-deserializer.js +0 -64
- package/dist/deserializer/misc/list-item-deserializer.js +0 -69
- package/dist/deserializer/misc/list-items-deserializer.js +0 -30
- package/dist/deserializer/misc/logical-expression-deserializer.js +0 -196
- package/dist/deserializer/misc/modifier-deserializer.js +0 -87
- package/dist/deserializer/misc/modifier-list-deserializer.js +0 -61
- package/dist/deserializer/misc/parameter-list-deserializer.js +0 -64
- package/dist/deserializer/misc/value-deserializer.js +0 -50
- package/dist/deserializer/network/host-rule-deserializer.js +0 -67
- package/dist/deserializer/network/hostname-list-deserializer.js +0 -56
- package/dist/deserializer/network/network-rule-deserializer.js +0 -65
- package/dist/deserializer/rule-deserializer.js +0 -65
- package/dist/deserializer/syntax-deserialization-map.js +0 -21
- package/dist/marshalling-utils/comment/agent-comment-common.js +0 -21
- package/dist/marshalling-utils/comment/agent-common.js +0 -40
- package/dist/marshalling-utils/comment/config-comment-common.js +0 -54
- package/dist/marshalling-utils/comment/hint-comment-common.js +0 -22
- package/dist/marshalling-utils/comment/hint-common.js +0 -56
- package/dist/marshalling-utils/comment/metadata-comment-common.js +0 -41
- package/dist/marshalling-utils/comment/pre-processor-comment-common.js +0 -59
- package/dist/marshalling-utils/comment/simple-comment-common.js +0 -22
- package/dist/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.js +0 -61
- package/dist/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.js +0 -66
- package/dist/marshalling-utils/cosmetic/body/css-injection-body-common.js +0 -24
- package/dist/marshalling-utils/cosmetic/body/element-hiding-body-common.js +0 -21
- package/dist/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.js +0 -114
- package/dist/marshalling-utils/cosmetic/cosmetic-rule-common.js +0 -46
- package/dist/marshalling-utils/empty-rule-common.js +0 -20
- package/dist/marshalling-utils/filter-list-common.js +0 -21
- package/dist/marshalling-utils/invalid-rule-common.js +0 -21
- package/dist/marshalling-utils/invalid-rule-error-node-common.js +0 -22
- package/dist/marshalling-utils/misc/binary-type-common.js +0 -54
- package/dist/marshalling-utils/misc/domain-list-common.js +0 -36
- package/dist/marshalling-utils/misc/host-rule-common.js +0 -24
- package/dist/marshalling-utils/misc/hostname-list-common.js +0 -21
- package/dist/marshalling-utils/misc/list-item-common.js +0 -22
- package/dist/marshalling-utils/misc/logical-expression-common.js +0 -83
- package/dist/marshalling-utils/misc/modifier-common.js +0 -231
- package/dist/marshalling-utils/misc/modifier-list-common.js +0 -21
- package/dist/marshalling-utils/misc/parameter-list-common.js +0 -21
- package/dist/marshalling-utils/misc/value-common.js +0 -22
- package/dist/marshalling-utils/network/network-rule-common.js +0 -24
- package/dist/marshalling-utils/syntax-serialization-map.js +0 -30
- package/dist/serializer/base-serializer.js +0 -29
- package/dist/serializer/comment/agent-comment-serializer.js +0 -74
- package/dist/serializer/comment/agent-serializer.js +0 -59
- package/dist/serializer/comment/comment-rule-serializer.js +0 -105
- package/dist/serializer/comment/config-comment-serializer.js +0 -82
- package/dist/serializer/comment/hint-comment-serializer.js +0 -65
- package/dist/serializer/comment/hint-serializer.js +0 -54
- package/dist/serializer/comment/metadata-comment-serializer.js +0 -73
- package/dist/serializer/comment/pre-processor-comment-serializer.js +0 -71
- package/dist/serializer/comment/simple-comment-serializer.js +0 -52
- package/dist/serializer/cosmetic/body/abp-snippet-injection-body-serializer.js +0 -36
- package/dist/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.js +0 -36
- package/dist/serializer/cosmetic/body/scriptlet-body-serializer.js +0 -50
- package/dist/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.js +0 -36
- package/dist/serializer/cosmetic/cosmetic-rule-serializer.js +0 -120
- package/dist/serializer/cosmetic/css-injection-body-serializer.js +0 -51
- package/dist/serializer/cosmetic/element-hiding-body-serializer.js +0 -40
- package/dist/serializer/empty-rule-serializer.js +0 -37
- package/dist/serializer/filterlist-serializer.js +0 -45
- package/dist/serializer/index.js +0 -7
- package/dist/serializer/invalid-rule-error-node-serializer.js +0 -41
- package/dist/serializer/invalid-rule-serializer.js +0 -40
- package/dist/serializer/misc/domain-list-serializer.js +0 -64
- package/dist/serializer/misc/list-item-serializer.js +0 -58
- package/dist/serializer/misc/list-items-serializer.js +0 -29
- package/dist/serializer/misc/logical-expression-serializer.js +0 -136
- package/dist/serializer/misc/modifier-list-serializer.js +0 -58
- package/dist/serializer/misc/modifier-serializer.js +0 -49
- package/dist/serializer/misc/parameter-list-serializer.js +0 -52
- package/dist/serializer/misc/value-serializer.js +0 -50
- package/dist/serializer/network/host-rule-serializer.js +0 -70
- package/dist/serializer/network/hostname-list-serializer.js +0 -53
- package/dist/serializer/network/network-rule-serializer.js +0 -54
- package/dist/serializer/rule-serializer.js +0 -61
- package/dist/types/deserializer/base-deserializer.d.ts +0 -15
- package/dist/types/deserializer/comment/agent-comment-deserializer.d.ts +0 -34
- package/dist/types/deserializer/comment/agent-deserializer.d.ts +0 -25
- package/dist/types/deserializer/comment/comment-rule-deserializer.d.ts +0 -16
- package/dist/types/deserializer/comment/config-comment-deserializer.d.ts +0 -27
- package/dist/types/deserializer/comment/hint-comment-deserializer.d.ts +0 -24
- package/dist/types/deserializer/comment/hint-deserializer.d.ts +0 -26
- package/dist/types/deserializer/comment/metadata-comment-deserializer.d.ts +0 -26
- package/dist/types/deserializer/comment/pre-processor-comment-deserializer.d.ts +0 -29
- package/dist/types/deserializer/comment/simple-comment-deserializer.d.ts +0 -26
- package/dist/types/deserializer/cosmetic/cosmetic-rule-deserializer.d.ts +0 -18
- package/dist/types/deserializer/cosmetic/css-injection-body-deserializer.d.ts +0 -15
- package/dist/types/deserializer/cosmetic/element-hiding-body-deserializer.d.ts +0 -16
- package/dist/types/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.d.ts +0 -17
- package/dist/types/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.d.ts +0 -18
- package/dist/types/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.d.ts +0 -19
- package/dist/types/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.d.ts +0 -17
- package/dist/types/deserializer/empty-rule-deserializer.d.ts +0 -16
- package/dist/types/deserializer/filterlist-deserializer.d.ts +0 -34
- package/dist/types/deserializer/index.d.ts +0 -2
- package/dist/types/deserializer/invalid-rule-deserializer.d.ts +0 -16
- package/dist/types/deserializer/invalid-rule-error-node-deserializer.d.ts +0 -16
- package/dist/types/deserializer/misc/domain-list-deserializer.d.ts +0 -15
- package/dist/types/deserializer/misc/list-item-deserializer.d.ts +0 -19
- package/dist/types/deserializer/misc/list-items-deserializer.d.ts +0 -16
- package/dist/types/deserializer/misc/logical-expression-deserializer.d.ts +0 -55
- package/dist/types/deserializer/misc/modifier-deserializer.d.ts +0 -18
- package/dist/types/deserializer/misc/modifier-list-deserializer.d.ts +0 -20
- package/dist/types/deserializer/misc/parameter-list-deserializer.d.ts +0 -18
- package/dist/types/deserializer/misc/value-deserializer.d.ts +0 -17
- package/dist/types/deserializer/network/host-rule-deserializer.d.ts +0 -18
- package/dist/types/deserializer/network/hostname-list-deserializer.d.ts +0 -15
- package/dist/types/deserializer/network/network-rule-deserializer.d.ts +0 -18
- package/dist/types/deserializer/rule-deserializer.d.ts +0 -17
- package/dist/types/deserializer/syntax-deserialization-map.d.ts +0 -2
- package/dist/types/marshalling-utils/comment/agent-comment-common.d.ts +0 -14
- package/dist/types/marshalling-utils/comment/agent-common.d.ts +0 -20
- package/dist/types/marshalling-utils/comment/config-comment-common.d.ts +0 -42
- package/dist/types/marshalling-utils/comment/hint-comment-common.d.ts +0 -15
- package/dist/types/marshalling-utils/comment/hint-common.d.ts +0 -33
- package/dist/types/marshalling-utils/comment/metadata-comment-common.d.ts +0 -21
- package/dist/types/marshalling-utils/comment/pre-processor-comment-common.d.ts +0 -37
- package/dist/types/marshalling-utils/comment/simple-comment-common.d.ts +0 -15
- package/dist/types/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.d.ts +0 -23
- package/dist/types/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.d.ts +0 -9
- package/dist/types/marshalling-utils/cosmetic/body/css-injection-body-common.d.ts +0 -17
- package/dist/types/marshalling-utils/cosmetic/body/element-hiding-body-common.d.ts +0 -14
- package/dist/types/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.d.ts +0 -9
- package/dist/types/marshalling-utils/cosmetic/cosmetic-rule-common.d.ts +0 -28
- package/dist/types/marshalling-utils/empty-rule-common.d.ts +0 -13
- package/dist/types/marshalling-utils/filter-list-common.d.ts +0 -14
- package/dist/types/marshalling-utils/invalid-rule-common.d.ts +0 -14
- package/dist/types/marshalling-utils/invalid-rule-error-node-common.d.ts +0 -15
- package/dist/types/marshalling-utils/misc/binary-type-common.d.ts +0 -57
- package/dist/types/marshalling-utils/misc/domain-list-common.d.ts +0 -24
- package/dist/types/marshalling-utils/misc/host-rule-common.d.ts +0 -18
- package/dist/types/marshalling-utils/misc/hostname-list-common.d.ts +0 -14
- package/dist/types/marshalling-utils/misc/list-item-common.d.ts +0 -15
- package/dist/types/marshalling-utils/misc/logical-expression-common.d.ts +0 -47
- package/dist/types/marshalling-utils/misc/modifier-common.d.ts +0 -41
- package/dist/types/marshalling-utils/misc/modifier-list-common.d.ts +0 -14
- package/dist/types/marshalling-utils/misc/parameter-list-common.d.ts +0 -14
- package/dist/types/marshalling-utils/misc/value-common.d.ts +0 -15
- package/dist/types/marshalling-utils/network/network-rule-common.d.ts +0 -18
- package/dist/types/marshalling-utils/syntax-serialization-map.d.ts +0 -2
- package/dist/types/serializer/base-serializer.d.ts +0 -15
- package/dist/types/serializer/comment/agent-comment-serializer.d.ts +0 -34
- package/dist/types/serializer/comment/agent-serializer.d.ts +0 -15
- package/dist/types/serializer/comment/comment-rule-serializer.d.ts +0 -68
- package/dist/types/serializer/comment/config-comment-serializer.d.ts +0 -25
- package/dist/types/serializer/comment/hint-comment-serializer.d.ts +0 -23
- package/dist/types/serializer/comment/hint-serializer.d.ts +0 -24
- package/dist/types/serializer/comment/metadata-comment-serializer.d.ts +0 -25
- package/dist/types/serializer/comment/pre-processor-comment-serializer.d.ts +0 -28
- package/dist/types/serializer/comment/simple-comment-serializer.d.ts +0 -24
- package/dist/types/serializer/cosmetic/body/abp-snippet-injection-body-serializer.d.ts +0 -25
- package/dist/types/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.d.ts +0 -25
- package/dist/types/serializer/cosmetic/body/scriptlet-body-serializer.d.ts +0 -17
- package/dist/types/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.d.ts +0 -25
- package/dist/types/serializer/cosmetic/cosmetic-rule-serializer.d.ts +0 -19
- package/dist/types/serializer/cosmetic/css-injection-body-serializer.d.ts +0 -15
- package/dist/types/serializer/cosmetic/element-hiding-body-serializer.d.ts +0 -15
- package/dist/types/serializer/empty-rule-serializer.d.ts +0 -15
- package/dist/types/serializer/filterlist-serializer.d.ts +0 -15
- package/dist/types/serializer/index.d.ts +0 -1
- package/dist/types/serializer/invalid-rule-error-node-serializer.d.ts +0 -15
- package/dist/types/serializer/invalid-rule-serializer.d.ts +0 -15
- package/dist/types/serializer/misc/domain-list-serializer.d.ts +0 -21
- package/dist/types/serializer/misc/list-item-serializer.d.ts +0 -16
- package/dist/types/serializer/misc/list-items-serializer.d.ts +0 -15
- package/dist/types/serializer/misc/logical-expression-serializer.d.ts +0 -52
- package/dist/types/serializer/misc/modifier-list-serializer.d.ts +0 -20
- package/dist/types/serializer/misc/modifier-serializer.d.ts +0 -18
- package/dist/types/serializer/misc/parameter-list-serializer.d.ts +0 -17
- package/dist/types/serializer/misc/value-serializer.d.ts +0 -17
- package/dist/types/serializer/network/host-rule-serializer.d.ts +0 -30
- package/dist/types/serializer/network/hostname-list-serializer.d.ts +0 -15
- package/dist/types/serializer/network/network-rule-serializer.d.ts +0 -18
- package/dist/types/serializer/rule-serializer.d.ts +0 -17
- package/dist/types/utils/binary-schema-version.d.ts +0 -9
- package/dist/types/utils/byte-buffer.d.ts +0 -54
- package/dist/types/utils/input-byte-buffer.d.ts +0 -146
- package/dist/types/utils/is-chromium.d.ts +0 -7
- package/dist/types/utils/output-byte-buffer.d.ts +0 -132
- package/dist/types/utils/storage-interface.d.ts +0 -23
- package/dist/types/utils/text-decoder-polyfill.d.ts +0 -14
- package/dist/types/utils/text-encoder-polyfill.d.ts +0 -18
- package/dist/utils/binary-schema-version.js +0 -17
- package/dist/utils/byte-buffer.js +0 -91
- package/dist/utils/input-byte-buffer.js +0 -266
- package/dist/utils/is-chromium.js +0 -20
- package/dist/utils/output-byte-buffer.js +0 -231
- package/dist/utils/text-decoder-polyfill.js +0 -107
- package/dist/utils/text-encoder-polyfill.js +0 -78
- /package/dist/types/generator/cosmetic/{body → scriptlet-body}/abp-snippet-injection-body-generator.d.ts +0 -0
- /package/dist/types/generator/cosmetic/{body → scriptlet-body}/adg-scriptlet-injection-body-generator.d.ts +0 -0
- /package/dist/types/generator/cosmetic/{body → scriptlet-body}/ubo-scriptlet-injection-body-generator.d.ts +0 -0
- /package/dist/types/parser/cosmetic/{body → scriptlet-body}/abp-snippet-injection-body-parser.d.ts +0 -0
- /package/dist/types/parser/cosmetic/{body → scriptlet-body}/adg-scriptlet-injection-body-parser.d.ts +0 -0
- /package/dist/types/parser/cosmetic/{body → scriptlet-body}/ubo-scriptlet-injection-body-parser.d.ts +0 -0
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* AGTree v3.4.1 (build date: Fri, 28 Nov 2025 11:48:53 GMT)
|
|
3
|
-
* (c) 2025 Adguard Software Ltd.
|
|
4
|
-
* Released under the MIT license
|
|
5
|
-
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
-
*/
|
|
7
|
-
import { ByteBuffer } from './byte-buffer.js';
|
|
8
|
-
import { isArrayOfUint8Arrays } from './type-guards.js';
|
|
9
|
-
import { isChromium } from './is-chromium.js';
|
|
10
|
-
import { decodeTextPolyfill } from './text-decoder-polyfill.js';
|
|
11
|
-
import { BINARY_SCHEMA_VERSION } from './binary-schema-version.js';
|
|
12
|
-
import { BinarySchemaMismatchError } from '../errors/binary-schema-mismatch-error.js';
|
|
13
|
-
|
|
14
|
-
/* eslint-disable max-len */
|
|
15
|
-
/* eslint-disable no-plusplus */
|
|
16
|
-
/* eslint-disable no-bitwise */
|
|
17
|
-
/**
|
|
18
|
-
* @file Input byte buffer for reading binary data.
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Input byte buffer for reading binary data.
|
|
22
|
-
*
|
|
23
|
-
* @note Internally, this class uses a {@link ByteBuffer} instance, just providing a convenient API for reading data.
|
|
24
|
-
*/
|
|
25
|
-
class InputByteBuffer extends ByteBuffer {
|
|
26
|
-
/**
|
|
27
|
-
* Current offset in the buffer for reading.
|
|
28
|
-
*/
|
|
29
|
-
offset;
|
|
30
|
-
/**
|
|
31
|
-
* Shared native decoder for decoding strings.
|
|
32
|
-
*/
|
|
33
|
-
sharedNativeDecoder;
|
|
34
|
-
/**
|
|
35
|
-
* Flag indicating if the current environment is Chromium.
|
|
36
|
-
* This is used for performance optimizations, because Chromium's TextEncoder/TextDecoder has a relatively
|
|
37
|
-
* large marshalling overhead for small strings.
|
|
38
|
-
*/
|
|
39
|
-
isChromium;
|
|
40
|
-
/**
|
|
41
|
-
* Constructs a new `InputByteBuffer` instance.
|
|
42
|
-
*
|
|
43
|
-
* @param chunks Array of chunks to initialize the ByteBuffer with.
|
|
44
|
-
* @param cloneChunks Flag indicating if the chunks should be cloned. For performance reasons,
|
|
45
|
-
* its default value is `false`. If the original chunks are guaranteed not to change,
|
|
46
|
-
* leave this flag as `false` to avoid unnecessary copying.
|
|
47
|
-
* @param initialOffset Initial offset in the buffer for reading.
|
|
48
|
-
*
|
|
49
|
-
* @throws If the specified chunks array is empty.
|
|
50
|
-
* @throws If the binary schema version in the buffer is not equal to the expected version.
|
|
51
|
-
* @throws If the initial offset is out of bounds.
|
|
52
|
-
*/
|
|
53
|
-
constructor(chunks, cloneChunks = false, initialOffset = 0) {
|
|
54
|
-
super(chunks, cloneChunks);
|
|
55
|
-
// TODO: Consider accepting an empty array of chunks
|
|
56
|
-
// Check binary schema version
|
|
57
|
-
if (chunks.length === 0) {
|
|
58
|
-
throw new Error('No data in the buffer');
|
|
59
|
-
}
|
|
60
|
-
const actualVersion = this.readSchemaVersion();
|
|
61
|
-
if (actualVersion !== BINARY_SCHEMA_VERSION) {
|
|
62
|
-
throw new BinarySchemaMismatchError(BINARY_SCHEMA_VERSION, actualVersion);
|
|
63
|
-
}
|
|
64
|
-
// Throw an error if the initial offset is out of bounds
|
|
65
|
-
if (initialOffset < 0 || initialOffset > this.chunks.length * ByteBuffer.CHUNK_SIZE) {
|
|
66
|
-
throw new Error(`Invalid offset: ${initialOffset}`);
|
|
67
|
-
}
|
|
68
|
-
// Schema version is always stored at the beginning of the buffer - skip it, because it is already processed
|
|
69
|
-
this.offset = Math.max(4, initialOffset);
|
|
70
|
-
this.sharedNativeDecoder = new TextDecoder();
|
|
71
|
-
this.isChromium = isChromium();
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Creates a new InputByteBuffer instance from a Storage instance by reading chunks from the storage.
|
|
75
|
-
*
|
|
76
|
-
* @param storage Storage instance.
|
|
77
|
-
* @param key Key to read from the storage.
|
|
78
|
-
* @returns New InputByteBuffer instance.
|
|
79
|
-
* @note For performance reasons, chunks are passed by reference and not copied.
|
|
80
|
-
*/
|
|
81
|
-
static async createFromStorage(storage, key) {
|
|
82
|
-
const chunks = await storage.get(key);
|
|
83
|
-
if (!isArrayOfUint8Arrays(chunks)) {
|
|
84
|
-
throw new Error('The data from storage is not an array of Uint8Arrays');
|
|
85
|
-
}
|
|
86
|
-
return new InputByteBuffer(chunks);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Reads a 8-bit unsigned integer from the buffer.
|
|
90
|
-
*
|
|
91
|
-
* @returns 8-bit unsigned integer from the buffer.
|
|
92
|
-
*/
|
|
93
|
-
readUint8() {
|
|
94
|
-
const result = this.readByte(this.offset++) ?? 0;
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Reads a 16-bit unsigned integer from the buffer.
|
|
99
|
-
*
|
|
100
|
-
* @returns 16-bit unsigned integer from the buffer.
|
|
101
|
-
*/
|
|
102
|
-
readUint16() {
|
|
103
|
-
const result = (((this.readByte(this.offset++) ?? 0) << 8)
|
|
104
|
-
| ((this.readByte(this.offset++) ?? 0))) >>> 0;
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Reads a 32-bit unsigned integer from the buffer at the specified index.
|
|
109
|
-
*
|
|
110
|
-
* @param index Index to read the 32-bit unsigned integer from.
|
|
111
|
-
*
|
|
112
|
-
* @returns 32-bit unsigned integer from the buffer.
|
|
113
|
-
*/
|
|
114
|
-
readUint32FromIndex(index) {
|
|
115
|
-
const result = (((this.readByte(index) ?? 0) << 24)
|
|
116
|
-
| ((this.readByte(index + 1) ?? 0) << 16)
|
|
117
|
-
| ((this.readByte(index + 2) ?? 0) << 8)
|
|
118
|
-
| ((this.readByte(index + 3) ?? 0))) >>> 0;
|
|
119
|
-
return result;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Reads a 32-bit unsigned integer from the buffer.
|
|
123
|
-
*
|
|
124
|
-
* @returns 32-bit unsigned integer from the buffer.
|
|
125
|
-
*/
|
|
126
|
-
readUint32() {
|
|
127
|
-
const result = this.readUint32FromIndex(this.offset);
|
|
128
|
-
this.offset += 4;
|
|
129
|
-
return result;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Reads schema version from the buffer.
|
|
133
|
-
*
|
|
134
|
-
* @returns 32-bit unsigned integer from the buffer.
|
|
135
|
-
* @note Schema version is always stored at the beginning of the buffer.
|
|
136
|
-
*/
|
|
137
|
-
readSchemaVersion() {
|
|
138
|
-
return this.readUint32FromIndex(0);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Reads a 32-bit signed integer from the buffer.
|
|
142
|
-
*
|
|
143
|
-
* @returns 32-bit signed integer from the buffer.
|
|
144
|
-
*/
|
|
145
|
-
readInt32() {
|
|
146
|
-
const result = this.readUint32();
|
|
147
|
-
return result > 0x7fffffff ? result - 0x100000000 : result;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Reads an optimized unsigned integer from the buffer.
|
|
151
|
-
* 'Optimized' means that the integer is stored in a variable number of bytes, depending on its value,
|
|
152
|
-
* so that smaller numbers occupy less space.
|
|
153
|
-
*
|
|
154
|
-
* @returns Decoded unsigned integer from the buffer.
|
|
155
|
-
*/
|
|
156
|
-
readOptimizedUint() {
|
|
157
|
-
let result = 0;
|
|
158
|
-
let shift = 0;
|
|
159
|
-
while (shift <= 28) {
|
|
160
|
-
const byteValue = this.readByte(this.offset++) ?? 0;
|
|
161
|
-
result |= (byteValue & 0x7F) << shift;
|
|
162
|
-
shift += 7;
|
|
163
|
-
if ((byteValue & 0x80) === 0) {
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return result;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Reads a string from the buffer.
|
|
171
|
-
*
|
|
172
|
-
* @returns Decoded string from the buffer.
|
|
173
|
-
*/
|
|
174
|
-
readString() {
|
|
175
|
-
const length = this.readOptimizedUint();
|
|
176
|
-
let chunkIndex = this.offset >>> 0x000F;
|
|
177
|
-
const chunkOffset = this.offset & 0x7FFF; // offset is only relevant for the first chunk
|
|
178
|
-
const endOffset = chunkOffset + length;
|
|
179
|
-
// In most cases, the string is stored in the current chunk
|
|
180
|
-
if (endOffset < ByteBuffer.CHUNK_SIZE) {
|
|
181
|
-
this.offset += length;
|
|
182
|
-
if (this.isChromium) {
|
|
183
|
-
return decodeTextPolyfill(this.chunks[chunkIndex], chunkOffset, endOffset);
|
|
184
|
-
}
|
|
185
|
-
return this.sharedNativeDecoder.decode(this.chunks[chunkIndex].subarray(chunkOffset, endOffset));
|
|
186
|
-
}
|
|
187
|
-
const result = [];
|
|
188
|
-
result.push(this.sharedNativeDecoder.decode(this.chunks[chunkIndex++].subarray(chunkOffset), { stream: true }));
|
|
189
|
-
let remaining = length - (ByteBuffer.CHUNK_SIZE - chunkOffset);
|
|
190
|
-
while (remaining) {
|
|
191
|
-
const chunk = this.chunks[chunkIndex];
|
|
192
|
-
if (!chunk) {
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
const toRead = Math.min(remaining, ByteBuffer.CHUNK_SIZE);
|
|
196
|
-
result.push(this.sharedNativeDecoder.decode(chunk.subarray(0, toRead), { stream: true }));
|
|
197
|
-
remaining -= toRead;
|
|
198
|
-
chunkIndex += 1;
|
|
199
|
-
}
|
|
200
|
-
// Finish decoding, if something is left
|
|
201
|
-
result.push(this.sharedNativeDecoder.decode());
|
|
202
|
-
this.offset += length;
|
|
203
|
-
return result.join('');
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Reads a 8-bit unsigned integer from the buffer without advancing the offset.
|
|
207
|
-
*
|
|
208
|
-
* @returns 8-bit unsigned integer from the buffer.
|
|
209
|
-
*/
|
|
210
|
-
peekUint8() {
|
|
211
|
-
return this.readByte(this.offset) ?? 0;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Helper method for asserting the next 8-bit unsigned integer in the buffer.
|
|
215
|
-
*
|
|
216
|
-
* @param value Expected value.
|
|
217
|
-
* @throws If the next value in the buffer is not equal to the expected value.
|
|
218
|
-
*/
|
|
219
|
-
assertUint8(value) {
|
|
220
|
-
const result = this.readUint8();
|
|
221
|
-
if (result !== value) {
|
|
222
|
-
throw new Error(`Expected ${value}, but got ${result}`);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Creates a new `InputByteBuffer` instance with the given initial offset.
|
|
227
|
-
*
|
|
228
|
-
* @param initialOffset Initial offset for the new buffer.
|
|
229
|
-
* @param cloneChunks Flag indicating if the chunks should be cloned. For performance reasons,
|
|
230
|
-
* its default value is `false`. If the original chunks are guaranteed not to change,
|
|
231
|
-
* leave this flag as `false` to avoid unnecessary copying.
|
|
232
|
-
*
|
|
233
|
-
* @returns New `InputByteBuffer` instance with the given initial offset.
|
|
234
|
-
*
|
|
235
|
-
* @note This method is useful if you want to read some data from a specific index.
|
|
236
|
-
*/
|
|
237
|
-
createCopyWithOffset(initialOffset, cloneChunks = false) {
|
|
238
|
-
return new InputByteBuffer(this.chunks, cloneChunks, initialOffset);
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Gets the current offset in the buffer for reading.
|
|
242
|
-
*
|
|
243
|
-
* @returns Current offset in the buffer for reading.
|
|
244
|
-
*/
|
|
245
|
-
get currentOffset() {
|
|
246
|
-
return this.offset;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Gets the capacity of the buffer.
|
|
250
|
-
*
|
|
251
|
-
* @returns Capacity of the buffer.
|
|
252
|
-
*/
|
|
253
|
-
get capacity() {
|
|
254
|
-
return this.chunks.length * ByteBuffer.CHUNK_SIZE;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Gets the chunks of the buffer.
|
|
258
|
-
*
|
|
259
|
-
* @returns Chunks of the buffer.
|
|
260
|
-
*/
|
|
261
|
-
getChunks() {
|
|
262
|
-
return this.chunks;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export { InputByteBuffer };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* AGTree v3.4.1 (build date: Fri, 28 Nov 2025 11:48:53 GMT)
|
|
3
|
-
* (c) 2025 Adguard Software Ltd.
|
|
4
|
-
* Released under the MIT license
|
|
5
|
-
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* A simple function to check if the current browser is Chromium-based.
|
|
9
|
-
*
|
|
10
|
-
* @returns `true` if the current browser is Chromium-based, `false` otherwise.
|
|
11
|
-
* @see {@link https://stackoverflow.com/a/62797156}
|
|
12
|
-
*/
|
|
13
|
-
const isChromium = () => {
|
|
14
|
-
return typeof window !== 'undefined'
|
|
15
|
-
&& (Object.prototype.hasOwnProperty.call(window, 'chrome')
|
|
16
|
-
|| (typeof window.navigator !== 'undefined'
|
|
17
|
-
&& /chrome/i.test(window.navigator.userAgent)));
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export { isChromium };
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* AGTree v3.4.1 (build date: Fri, 28 Nov 2025 11:48:53 GMT)
|
|
3
|
-
* (c) 2025 Adguard Software Ltd.
|
|
4
|
-
* Released under the MIT license
|
|
5
|
-
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
-
*/
|
|
7
|
-
import { BINARY_SCHEMA_VERSION } from './binary-schema-version.js';
|
|
8
|
-
import { ByteBuffer } from './byte-buffer.js';
|
|
9
|
-
import { isChromium } from './is-chromium.js';
|
|
10
|
-
import { encodeIntoPolyfill } from './text-encoder-polyfill.js';
|
|
11
|
-
|
|
12
|
-
/* eslint-disable no-plusplus */
|
|
13
|
-
/* eslint-disable no-bitwise */
|
|
14
|
-
/**
|
|
15
|
-
* @file Output byte buffer for writing binary data.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Output byte buffer for writing binary data.
|
|
19
|
-
*
|
|
20
|
-
* @note Internally, this class uses a {@link ByteBuffer} instance, just providing a convenient API for reading data.
|
|
21
|
-
*/
|
|
22
|
-
class OutputByteBuffer extends ByteBuffer {
|
|
23
|
-
/**
|
|
24
|
-
* Current offset in the buffer for writing.
|
|
25
|
-
*/
|
|
26
|
-
offset;
|
|
27
|
-
/**
|
|
28
|
-
* Size of the shared buffer for encoding strings in bytes.
|
|
29
|
-
* This is a divisor of ByteBuffer.CHUNK_SIZE and experience shows that this value works optimally.
|
|
30
|
-
* This is sufficient for most strings that occur in filter lists (we checked average string length in popular
|
|
31
|
-
* filter lists).
|
|
32
|
-
*/
|
|
33
|
-
static ENCODER_BUFFER_SIZE = 8192;
|
|
34
|
-
/**
|
|
35
|
-
* Length threshold for using a shared buffer for encoding strings.
|
|
36
|
-
* This temp buffer is needed because we write the short strings in it
|
|
37
|
-
* (so there is no need to constantly allocate a new buffer).
|
|
38
|
-
* The reason for dividing ENCODER_BUFFER_SIZE by 4 is to ensure that the encoded string fits in the buffer,
|
|
39
|
-
* if we also take into account the worst possible case (each character is encoded with 4 bytes).
|
|
40
|
-
*/
|
|
41
|
-
static SHORT_STRING_THRESHOLD = 2048; // 8192 / 4
|
|
42
|
-
/**
|
|
43
|
-
* Represents the maximum value that can be written as a 'storage optimized' unsigned integer.
|
|
44
|
-
* 0x1FFFFFFF means 29 bits — 32 bits minus 3 bits — because the last bit in each byte is a flag indicating
|
|
45
|
-
* if there are more bytes (except for the last byte).
|
|
46
|
-
*/
|
|
47
|
-
static MAX_OPTIMIZED_UINT = 0x1FFFFFFF;
|
|
48
|
-
/**
|
|
49
|
-
* Shared buffer for encoding strings.
|
|
50
|
-
*/
|
|
51
|
-
sharedBuffer;
|
|
52
|
-
/**
|
|
53
|
-
* Shared native encoder for encoding strings.
|
|
54
|
-
*/
|
|
55
|
-
sharedNativeEncoder;
|
|
56
|
-
/**
|
|
57
|
-
* Flag indicating if the current environment is Chromium.
|
|
58
|
-
* This is used for performance optimizations, because Chromium's TextEncoder/TextDecoder has a relatively
|
|
59
|
-
* large marshalling overhead for small strings.
|
|
60
|
-
*/
|
|
61
|
-
isChromium;
|
|
62
|
-
/**
|
|
63
|
-
* Constructs a new OutputByteBuffer instance.
|
|
64
|
-
*/
|
|
65
|
-
// TODO: add chunks as a parameter, if ever needed
|
|
66
|
-
constructor() {
|
|
67
|
-
super();
|
|
68
|
-
this.sharedBuffer = new Uint8Array(OutputByteBuffer.ENCODER_BUFFER_SIZE);
|
|
69
|
-
this.sharedNativeEncoder = new TextEncoder();
|
|
70
|
-
this.isChromium = isChromium();
|
|
71
|
-
// write the schema version at the beginning of the buffer
|
|
72
|
-
this.writeUint32ToIndex(BINARY_SCHEMA_VERSION, 0);
|
|
73
|
-
this.offset = 4; // schema version is already written
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Writes a 8-bit unsigned integer to the buffer.
|
|
77
|
-
*
|
|
78
|
-
* @param value Value to write.
|
|
79
|
-
* @returns Number of bytes written to the buffer.
|
|
80
|
-
*/
|
|
81
|
-
writeUint8(value) {
|
|
82
|
-
this.writeByte(this.offset++, value);
|
|
83
|
-
return 1;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Writes a 16-bit unsigned integer to the buffer.
|
|
87
|
-
*
|
|
88
|
-
* @param value Value to write.
|
|
89
|
-
* @returns Number of bytes written to the buffer.
|
|
90
|
-
*/
|
|
91
|
-
writeUint16(value) {
|
|
92
|
-
this.writeByte(this.offset++, value >> 8);
|
|
93
|
-
this.writeByte(this.offset++, value);
|
|
94
|
-
return 2;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Writes a 32-bit unsigned integer to the buffer at a specific index.
|
|
98
|
-
*
|
|
99
|
-
* @param value Value to write.
|
|
100
|
-
* @param index Index to write the value to.
|
|
101
|
-
* @returns Number of bytes written to the buffer.
|
|
102
|
-
*/
|
|
103
|
-
writeUint32ToIndex(value, index) {
|
|
104
|
-
this.writeByte(index, value >> 24);
|
|
105
|
-
this.writeByte(index + 1, value >> 16);
|
|
106
|
-
this.writeByte(index + 2, value >> 8);
|
|
107
|
-
this.writeByte(index + 3, value);
|
|
108
|
-
return 4;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Writes a 32-bit unsigned integer to the buffer.
|
|
112
|
-
*
|
|
113
|
-
* @param value Value to write.
|
|
114
|
-
* @returns Number of bytes written to the buffer.
|
|
115
|
-
*/
|
|
116
|
-
writeUint32(value) {
|
|
117
|
-
this.writeUint32ToIndex(value, this.offset);
|
|
118
|
-
this.offset += 4;
|
|
119
|
-
return 4;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Writes a 32-bit signed integer to the buffer.
|
|
123
|
-
*
|
|
124
|
-
* @param value Value to write.
|
|
125
|
-
* @returns Number of bytes written to the buffer.
|
|
126
|
-
*/
|
|
127
|
-
writeInt32(value) {
|
|
128
|
-
return this.writeUint32(value ? value >>> 0 : 0);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Writes a Uint8Array to the byte buffer.
|
|
132
|
-
*
|
|
133
|
-
* @param buffer Buffer to write.
|
|
134
|
-
*/
|
|
135
|
-
writeBuffer(buffer) {
|
|
136
|
-
const { length } = buffer;
|
|
137
|
-
this.ensureCapacity(this.offset + length);
|
|
138
|
-
let chunkIndex = this.offset >>> 0x000F;
|
|
139
|
-
let chunkOffset = this.offset & 0x7FFF;
|
|
140
|
-
let remainingBytes = length;
|
|
141
|
-
while (remainingBytes) {
|
|
142
|
-
const leftInChunk = ByteBuffer.CHUNK_SIZE - chunkOffset;
|
|
143
|
-
const bytesToWrite = Math.min(remainingBytes, leftInChunk);
|
|
144
|
-
this.chunks[chunkIndex].set(buffer.subarray(length - remainingBytes, length - remainingBytes + bytesToWrite), chunkOffset);
|
|
145
|
-
remainingBytes -= bytesToWrite;
|
|
146
|
-
chunkIndex += 1;
|
|
147
|
-
chunkOffset = 0;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Writes a string to the buffer.
|
|
152
|
-
*
|
|
153
|
-
* @param value Value to write.
|
|
154
|
-
* @returns Number of bytes written to the buffer.
|
|
155
|
-
*/
|
|
156
|
-
writeString(value) {
|
|
157
|
-
const start = this.offset;
|
|
158
|
-
if (value.length <= OutputByteBuffer.SHORT_STRING_THRESHOLD) {
|
|
159
|
-
let bytesWritten;
|
|
160
|
-
if (this.isChromium) {
|
|
161
|
-
bytesWritten = encodeIntoPolyfill(value, this.sharedBuffer).written ?? 0;
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
bytesWritten = this.sharedNativeEncoder.encodeInto(value, this.sharedBuffer).written ?? 0;
|
|
165
|
-
}
|
|
166
|
-
this.writeOptimizedUint(bytesWritten);
|
|
167
|
-
this.writeBuffer(this.sharedBuffer.subarray(0, bytesWritten));
|
|
168
|
-
this.offset += bytesWritten;
|
|
169
|
-
return this.offset - start;
|
|
170
|
-
}
|
|
171
|
-
// TODO: Optimize for long strings, if needed. Not a common case for our use case
|
|
172
|
-
const buffer = this.sharedNativeEncoder.encode(value);
|
|
173
|
-
const bytesWritten = buffer.length;
|
|
174
|
-
this.writeOptimizedUint(bytesWritten);
|
|
175
|
-
this.writeBuffer(buffer);
|
|
176
|
-
this.offset += bytesWritten;
|
|
177
|
-
return this.offset - start;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Writes chunks to the storage.
|
|
181
|
-
*
|
|
182
|
-
* @param storage Storage to write the chunks to.
|
|
183
|
-
* @param key Key to write the chunks to.
|
|
184
|
-
* @note For performance reasons, chunks are passed by reference and not copied.
|
|
185
|
-
* @throws If the storage write operation throws.
|
|
186
|
-
*/
|
|
187
|
-
async writeChunksToStorage(storage, key) {
|
|
188
|
-
await storage.set(key, this.chunks);
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Writes an 'optimized' unsigned integer to the buffer.
|
|
192
|
-
* 'Optimized' means smaller storage usage for smaller numbers.
|
|
193
|
-
* Except for the last byte, each byte's most significant bit is a flag indicating if there are more bytes.
|
|
194
|
-
*
|
|
195
|
-
* @param value Value to write.
|
|
196
|
-
* @returns Number of bytes written to the buffer.
|
|
197
|
-
* @throws If the value exceeds the 29-bit limit.
|
|
198
|
-
*/
|
|
199
|
-
writeOptimizedUint(value) {
|
|
200
|
-
if (value < 0 || value > OutputByteBuffer.MAX_OPTIMIZED_UINT) {
|
|
201
|
-
throw new Error('Value exceeds 29-bit limit');
|
|
202
|
-
}
|
|
203
|
-
let remainingValue = value;
|
|
204
|
-
const startOffset = this.offset;
|
|
205
|
-
while (remainingValue >= 0x80) {
|
|
206
|
-
const byteValue = remainingValue & 0x7F;
|
|
207
|
-
remainingValue >>>= 7;
|
|
208
|
-
this.writeByte(this.offset++, byteValue | 0x80);
|
|
209
|
-
}
|
|
210
|
-
this.writeByte(this.offset++, remainingValue);
|
|
211
|
-
return this.offset - startOffset;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Gets the current offset in the buffer for writing.
|
|
215
|
-
*
|
|
216
|
-
* @returns Current offset in the buffer for writing.
|
|
217
|
-
*/
|
|
218
|
-
get currentOffset() {
|
|
219
|
-
return this.offset;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Gets the chunks of the buffer.
|
|
223
|
-
*
|
|
224
|
-
* @returns Chunks of the buffer.
|
|
225
|
-
*/
|
|
226
|
-
getChunks() {
|
|
227
|
-
return this.chunks;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export { OutputByteBuffer };
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* AGTree v3.4.1 (build date: Fri, 28 Nov 2025 11:48:53 GMT)
|
|
3
|
-
* (c) 2025 Adguard Software Ltd.
|
|
4
|
-
* Released under the MIT license
|
|
5
|
-
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
-
*/
|
|
7
|
-
import { EMPTY } from './constants.js';
|
|
8
|
-
|
|
9
|
-
/* eslint-disable no-plusplus */
|
|
10
|
-
/* eslint-disable no-bitwise */
|
|
11
|
-
/**
|
|
12
|
-
* @file Optimized utility for decoding strings from byte sequences.
|
|
13
|
-
*/
|
|
14
|
-
const REPLACEMENT_CHAR = String.fromCodePoint(0xFFFD);
|
|
15
|
-
/**
|
|
16
|
-
* Decodes a byte sequence into an UTF-8 string according to the WHATWG spec.
|
|
17
|
-
* Optimized for performance.
|
|
18
|
-
*
|
|
19
|
-
* @param buffer Buffer to read the bytes from.
|
|
20
|
-
* @param start Start offset in the buffer.
|
|
21
|
-
* @param end End offset in the buffer.
|
|
22
|
-
* @returns Decoded string.
|
|
23
|
-
* @see {@link https://encoding.spec.whatwg.org/#utf-8-decoder}
|
|
24
|
-
*/
|
|
25
|
-
const decodeTextPolyfill = (buffer, start = 0, end = -1) => {
|
|
26
|
-
let codePoint = 0;
|
|
27
|
-
let bytesSeen = 0;
|
|
28
|
-
let bytesNeeded = 0;
|
|
29
|
-
let lowerBoundary = 0x0080;
|
|
30
|
-
let upperBoundary = 0x00BF;
|
|
31
|
-
let i = start;
|
|
32
|
-
const { length } = buffer;
|
|
33
|
-
const realEnd = end === -1 ? length : Math.min(end, length);
|
|
34
|
-
const result = new Array(realEnd - start);
|
|
35
|
-
let resIdx = 0;
|
|
36
|
-
for (; i < realEnd; i += 1) {
|
|
37
|
-
const byte = buffer[i];
|
|
38
|
-
if (bytesNeeded === 0) {
|
|
39
|
-
if (byte <= 0x007F) {
|
|
40
|
-
codePoint = byte & 0x00FF;
|
|
41
|
-
}
|
|
42
|
-
else if (byte >= 0x00C2 && byte <= 0x00DF) {
|
|
43
|
-
bytesNeeded = 1;
|
|
44
|
-
codePoint = byte & 0x001F;
|
|
45
|
-
}
|
|
46
|
-
else if (byte >= 0x00E0 && byte <= 0x00EF) {
|
|
47
|
-
bytesNeeded = 2;
|
|
48
|
-
codePoint = byte & 0x000F;
|
|
49
|
-
if (byte === 0x00E0) {
|
|
50
|
-
// Adjust lower boundary for exclusion of overlong sequences
|
|
51
|
-
lowerBoundary = 0x00A0;
|
|
52
|
-
}
|
|
53
|
-
else if (byte === 0x00ED) {
|
|
54
|
-
// Adjust upper boundary to exclude surrogates
|
|
55
|
-
upperBoundary = 0x009F;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else if (byte >= 0x00F0 && byte <= 0x00F4) {
|
|
59
|
-
bytesNeeded = 3;
|
|
60
|
-
codePoint = byte & 0x0007;
|
|
61
|
-
if (byte === 0x00F0) {
|
|
62
|
-
// Adjust lower boundary for exclusion of overlong sequences
|
|
63
|
-
lowerBoundary = 0x0090;
|
|
64
|
-
}
|
|
65
|
-
else if (byte === 0x00F4) {
|
|
66
|
-
// Adjust upper boundary to limit to valid Unicode range
|
|
67
|
-
upperBoundary = 0x008F;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
// For bytes that are not valid initial bytes of UTF-8 sequences, add replacement character
|
|
72
|
-
result[resIdx++] = REPLACEMENT_CHAR;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
// For subsequent bytes in a multibyte sequence, check if the byte is in the expected range
|
|
78
|
-
if (!(byte >= lowerBoundary && byte <= upperBoundary)) {
|
|
79
|
-
// Reset the state for illegal sequences and add replacement character
|
|
80
|
-
bytesNeeded = 0;
|
|
81
|
-
bytesSeen = 0;
|
|
82
|
-
lowerBoundary = 0x0080;
|
|
83
|
-
upperBoundary = 0x00BF;
|
|
84
|
-
result[resIdx++] = REPLACEMENT_CHAR;
|
|
85
|
-
// Decrement `i` to re-evaluate this byte as the start of a new sequence
|
|
86
|
-
i -= 1;
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
codePoint = (codePoint << 6) | (byte & 0x003F);
|
|
90
|
-
// Reset boundaries for next bytes
|
|
91
|
-
lowerBoundary = 0x0080;
|
|
92
|
-
upperBoundary = 0x00BF;
|
|
93
|
-
bytesSeen += 1;
|
|
94
|
-
}
|
|
95
|
-
if (bytesSeen === bytesNeeded) {
|
|
96
|
-
// Complete the code point assembly and add it to the result
|
|
97
|
-
result[resIdx++] = String.fromCodePoint(codePoint);
|
|
98
|
-
// Reset for the next character
|
|
99
|
-
bytesNeeded = 0;
|
|
100
|
-
bytesSeen = 0;
|
|
101
|
-
codePoint = 0;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return result.join(EMPTY);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export { decodeTextPolyfill };
|