@jesscss/core 2.0.0-alpha.5 → 2.0.0-alpha.6
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/lib/index.cjs +20159 -0
- package/lib/index.d.cts +5993 -0
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.ts +5992 -21
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +19926 -22
- package/lib/index.js.map +1 -1
- package/package.json +15 -14
- package/src/__tests__/define-function-record.test.ts +58 -0
- package/src/__tests__/define-function-simple.test.ts +55 -0
- package/src/__tests__/define-function-split-sequence.test.ts +547 -0
- package/src/__tests__/define-function-type-parity.test.ts +9 -0
- package/src/__tests__/define-function.test.ts +763 -0
- package/src/__tests__/num-operations.test.ts +91 -0
- package/src/__tests__/safe-parse.test.ts +374 -0
- package/src/context.ts +896 -0
- package/src/conversions.ts +282 -0
- package/src/debug-log.ts +29 -0
- package/src/define-function.ts +1006 -0
- package/src/deprecation.ts +67 -0
- package/src/globals.d.ts +26 -0
- package/src/index.ts +31 -0
- package/src/jess-error.ts +773 -0
- package/src/logger/deprecation-processing.ts +109 -0
- package/src/logger.ts +31 -0
- package/src/plugin.ts +292 -0
- package/src/tree/LOOKUP_CHAINS.md +35 -0
- package/src/tree/README.md +18 -0
- package/src/tree/__tests__/__snapshots__/extend-eval-integration.test.ts.snap +1455 -0
- package/src/tree/__tests__/ampersand.test.ts +382 -0
- package/src/tree/__tests__/at-rule.test.ts +2047 -0
- package/src/tree/__tests__/basic-render.test.ts +212 -0
- package/src/tree/__tests__/block.test.ts +40 -0
- package/src/tree/__tests__/call.test.ts +346 -0
- package/src/tree/__tests__/color.test.ts +537 -0
- package/src/tree/__tests__/condition.test.ts +186 -0
- package/src/tree/__tests__/control.test.ts +564 -0
- package/src/tree/__tests__/declaration.test.ts +253 -0
- package/src/tree/__tests__/dependency-graph.test.ts +177 -0
- package/src/tree/__tests__/detached-rulesets.test.ts +213 -0
- package/src/tree/__tests__/dimension.test.ts +236 -0
- package/src/tree/__tests__/expression.test.ts +73 -0
- package/src/tree/__tests__/ext-node.test.ts +31 -0
- package/src/tree/__tests__/extend-eval-integration.test.ts +1033 -0
- package/src/tree/__tests__/extend-import-style.test.ts +929 -0
- package/src/tree/__tests__/extend-less-fixtures.test.ts +851 -0
- package/src/tree/__tests__/extend-list.test.ts +31 -0
- package/src/tree/__tests__/extend-roots.test.ts +1045 -0
- package/src/tree/__tests__/extend-rules.test.ts +740 -0
- package/src/tree/__tests__/func.test.ts +171 -0
- package/src/tree/__tests__/import-js.test.ts +33 -0
- package/src/tree/__tests__/import-style-test-helpers.ts +56 -0
- package/src/tree/__tests__/import-style.test.ts +1967 -0
- package/src/tree/__tests__/interpolated-reference.test.ts +44 -0
- package/src/tree/__tests__/interpolated.test.ts +41 -0
- package/src/tree/__tests__/list.test.ts +177 -0
- package/src/tree/__tests__/log.test.ts +83 -0
- package/src/tree/__tests__/mixin-recursion.test.ts +639 -0
- package/src/tree/__tests__/mixin.test.ts +2171 -0
- package/src/tree/__tests__/negative.test.ts +45 -0
- package/src/tree/__tests__/nesting-collapse.test.ts +519 -0
- package/src/tree/__tests__/node-flags-perf.test.ts +195 -0
- package/src/tree/__tests__/node-flags.test.ts +410 -0
- package/src/tree/__tests__/node-graph.test.ts +598 -0
- package/src/tree/__tests__/node-mutation.test.ts +182 -0
- package/src/tree/__tests__/operation.test.ts +18 -0
- package/src/tree/__tests__/paren.test.ts +90 -0
- package/src/tree/__tests__/preserve-mode-output.test.ts +50 -0
- package/src/tree/__tests__/quoted.test.ts +72 -0
- package/src/tree/__tests__/range.test.ts +59 -0
- package/src/tree/__tests__/reference.test.ts +743 -0
- package/src/tree/__tests__/rest.test.ts +29 -0
- package/src/tree/__tests__/rules-raw.test.ts +14 -0
- package/src/tree/__tests__/rules.test.ts +1271 -0
- package/src/tree/__tests__/ruleset.test.ts +597 -0
- package/src/tree/__tests__/selector-attr.test.ts +50 -0
- package/src/tree/__tests__/selector-basic.test.ts +44 -0
- package/src/tree/__tests__/selector-capture.test.ts +22 -0
- package/src/tree/__tests__/selector-complex.test.ts +120 -0
- package/src/tree/__tests__/selector-compound.test.ts +74 -0
- package/src/tree/__tests__/selector-interpolated.test.ts +50 -0
- package/src/tree/__tests__/selector-list.test.ts +59 -0
- package/src/tree/__tests__/selector-pseudo.test.ts +23 -0
- package/src/tree/__tests__/selector.test.ts +182 -0
- package/src/tree/__tests__/sequence.test.ts +226 -0
- package/src/tree/__tests__/serialize-types.test.ts +529 -0
- package/src/tree/__tests__/spaced.test.ts +8 -0
- package/src/tree/__tests__/url.test.ts +72 -0
- package/src/tree/__tests__/var-declaration.test.ts +90 -0
- package/src/tree/ampersand.ts +538 -0
- package/src/tree/any.ts +169 -0
- package/src/tree/at-rule.ts +760 -0
- package/src/tree/block.ts +72 -0
- package/src/tree/bool.ts +46 -0
- package/src/tree/call.ts +593 -0
- package/src/tree/collection.ts +52 -0
- package/src/tree/color.ts +629 -0
- package/src/tree/combinator.ts +30 -0
- package/src/tree/comment.ts +36 -0
- package/src/tree/condition.ts +194 -0
- package/src/tree/control.ts +452 -0
- package/src/tree/declaration-custom.ts +56 -0
- package/src/tree/declaration-var.ts +87 -0
- package/src/tree/declaration.ts +742 -0
- package/src/tree/default-guard.ts +35 -0
- package/src/tree/dimension.ts +392 -0
- package/src/tree/expression.ts +97 -0
- package/src/tree/extend-list.ts +51 -0
- package/src/tree/extend.ts +391 -0
- package/src/tree/function.ts +254 -0
- package/src/tree/import-js.ts +130 -0
- package/src/tree/import-style.ts +875 -0
- package/{lib/tree/index.js → src/tree/index.ts} +49 -22
- package/src/tree/interpolated.ts +346 -0
- package/src/tree/js-array.ts +21 -0
- package/src/tree/js-expr.ts +50 -0
- package/src/tree/js-function.ts +31 -0
- package/src/tree/js-object.ts +22 -0
- package/src/tree/list.ts +415 -0
- package/src/tree/log.ts +89 -0
- package/src/tree/mixin.ts +331 -0
- package/src/tree/negative.ts +58 -0
- package/src/tree/nil.ts +57 -0
- package/src/tree/node-base.ts +1716 -0
- package/src/tree/node-type.ts +122 -0
- package/src/tree/node.ts +118 -0
- package/src/tree/number.ts +54 -0
- package/src/tree/operation.ts +187 -0
- package/src/tree/paren.ts +132 -0
- package/src/tree/query-condition.ts +47 -0
- package/src/tree/quoted.ts +119 -0
- package/src/tree/range.ts +101 -0
- package/src/tree/reference.ts +1099 -0
- package/src/tree/rest.ts +55 -0
- package/src/tree/rules-raw.ts +52 -0
- package/src/tree/rules.ts +2896 -0
- package/src/tree/ruleset.ts +1217 -0
- package/src/tree/selector-attr.ts +172 -0
- package/src/tree/selector-basic.ts +75 -0
- package/src/tree/selector-capture.ts +85 -0
- package/src/tree/selector-complex.ts +189 -0
- package/src/tree/selector-compound.ts +205 -0
- package/src/tree/selector-interpolated.ts +95 -0
- package/src/tree/selector-list.ts +245 -0
- package/src/tree/selector-pseudo.ts +173 -0
- package/src/tree/selector-simple.ts +10 -0
- package/src/tree/selector.ts +152 -0
- package/src/tree/sequence.ts +463 -0
- package/src/tree/tree.ts +130 -0
- package/src/tree/url.ts +95 -0
- package/src/tree/util/EXTEND_ARCHITECTURE_ANALYSIS.md +215 -0
- package/src/tree/util/EXTEND_AUDIT.md +233 -0
- package/src/tree/util/EXTEND_BASELINE.md +64 -0
- package/src/tree/util/EXTEND_CALL_GRAPH_ANALYSIS.md +244 -0
- package/src/tree/util/EXTEND_DOCS.md +24 -0
- package/src/tree/util/EXTEND_FINAL_SUMMARY.md +95 -0
- package/src/tree/util/EXTEND_FUNCTION_AUDIT.md +1433 -0
- package/src/tree/util/EXTEND_OPTIMIZATION_PLAN.md +114 -0
- package/src/tree/util/EXTEND_REFACTORING_SUMMARY.md +152 -0
- package/src/tree/util/EXTEND_RULES.md +74 -0
- package/src/tree/util/EXTEND_UNUSED_FUNCTIONS.md +127 -0
- package/src/tree/util/EXTEND_UNUSED_FUNCTIONS_ANALYSIS.md +227 -0
- package/src/tree/util/NODE_COPY_REDUCTION_PLAN.md +12 -0
- package/src/tree/util/__tests__/EXTEND_TEST_INDEX.md +59 -0
- package/src/tree/util/__tests__/OPTIMIZATION-ANALYSIS.md +130 -0
- package/src/tree/util/__tests__/WALK_AND_CONSUME_DESIGN.md +138 -0
- package/src/tree/util/__tests__/_archive/2026-02-09__OPTIMIZATION-ANALYSIS.md +9 -0
- package/src/tree/util/__tests__/_archive/README.md +4 -0
- package/src/tree/util/__tests__/bitset.test.ts +142 -0
- package/src/tree/util/__tests__/debug-log.ts +50 -0
- package/src/tree/util/__tests__/extend-comment-handling.test.ts +187 -0
- package/src/tree/util/__tests__/extend-core-unit.test.ts +941 -0
- package/src/tree/util/__tests__/extend-pipeline-bench.test.ts +154 -0
- package/src/tree/util/__tests__/extend-pipeline-bench.ts +190 -0
- package/src/tree/util/__tests__/fast-reject.test.ts +377 -0
- package/src/tree/util/__tests__/is-node.test.ts +63 -0
- package/src/tree/util/__tests__/list-like.test.ts +63 -0
- package/src/tree/util/__tests__/outputwriter.test.ts +523 -0
- package/src/tree/util/__tests__/print.test.ts +183 -0
- package/src/tree/util/__tests__/process-extends.test.ts +226 -0
- package/src/tree/util/__tests__/process-leading-is.test.ts +205 -0
- package/src/tree/util/__tests__/recursion-helper.test.ts +184 -0
- package/src/tree/util/__tests__/selector-match-unit.test.ts +1427 -0
- package/src/tree/util/__tests__/sourcemap.test.ts +117 -0
- package/src/tree/util/ampersand-template.ts +9 -0
- package/src/tree/util/bitset.ts +194 -0
- package/src/tree/util/calculate.ts +11 -0
- package/src/tree/util/cast.ts +89 -0
- package/src/tree/util/cloning.ts +8 -0
- package/src/tree/util/collections.ts +299 -0
- package/src/tree/util/compare.ts +90 -0
- package/src/tree/util/cursor.ts +171 -0
- package/src/tree/util/extend-core.ts +2139 -0
- package/src/tree/util/extend-roots.ts +1108 -0
- package/src/tree/util/field-helpers.ts +354 -0
- package/src/tree/util/is-node.ts +43 -0
- package/src/tree/util/list-like.ts +93 -0
- package/src/tree/util/mixin-instance-primitives.ts +2020 -0
- package/src/tree/util/print.ts +303 -0
- package/src/tree/util/process-leading-is.ts +421 -0
- package/src/tree/util/recursion-helper.ts +54 -0
- package/src/tree/util/regex.ts +2 -0
- package/src/tree/util/registry-utils.ts +1953 -0
- package/src/tree/util/ruleset-trace.ts +17 -0
- package/src/tree/util/scoped-body-eval.ts +320 -0
- package/src/tree/util/selector-match-core.ts +2005 -0
- package/src/tree/util/selector-utils.ts +757 -0
- package/src/tree/util/serialize-helper.ts +535 -0
- package/src/tree/util/serialize-types.ts +318 -0
- package/src/tree/util/should-operate.ts +78 -0
- package/src/tree/util/sourcemap.ts +37 -0
- package/src/types/config.ts +247 -0
- package/src/types/index.ts +12 -0
- package/{lib/types/modes.d.ts → src/types/modes.ts} +2 -1
- package/src/types.d.ts +9 -0
- package/src/types.ts +68 -0
- package/src/use-webpack-resolver.ts +56 -0
- package/src/visitor/__tests__/visitor.test.ts +136 -0
- package/src/visitor/index.ts +263 -0
- package/{lib/visitor/less-visitor.js → src/visitor/less-visitor.ts} +3 -2
- package/lib/context.d.ts +0 -352
- package/lib/context.d.ts.map +0 -1
- package/lib/context.js +0 -636
- package/lib/context.js.map +0 -1
- package/lib/conversions.d.ts +0 -73
- package/lib/conversions.d.ts.map +0 -1
- package/lib/conversions.js +0 -253
- package/lib/conversions.js.map +0 -1
- package/lib/debug-log.d.ts +0 -2
- package/lib/debug-log.d.ts.map +0 -1
- package/lib/debug-log.js +0 -27
- package/lib/debug-log.js.map +0 -1
- package/lib/define-function.d.ts +0 -587
- package/lib/define-function.d.ts.map +0 -1
- package/lib/define-function.js +0 -726
- package/lib/define-function.js.map +0 -1
- package/lib/deprecation.d.ts +0 -34
- package/lib/deprecation.d.ts.map +0 -1
- package/lib/deprecation.js +0 -57
- package/lib/deprecation.js.map +0 -1
- package/lib/jess-error.d.ts +0 -343
- package/lib/jess-error.d.ts.map +0 -1
- package/lib/jess-error.js +0 -508
- package/lib/jess-error.js.map +0 -1
- package/lib/logger/deprecation-processing.d.ts +0 -41
- package/lib/logger/deprecation-processing.d.ts.map +0 -1
- package/lib/logger/deprecation-processing.js +0 -81
- package/lib/logger/deprecation-processing.js.map +0 -1
- package/lib/logger.d.ts +0 -10
- package/lib/logger.d.ts.map +0 -1
- package/lib/logger.js +0 -20
- package/lib/logger.js.map +0 -1
- package/lib/plugin.d.ts +0 -94
- package/lib/plugin.d.ts.map +0 -1
- package/lib/plugin.js +0 -174
- package/lib/plugin.js.map +0 -1
- package/lib/tree/ampersand.d.ts +0 -98
- package/lib/tree/ampersand.d.ts.map +0 -1
- package/lib/tree/ampersand.js +0 -319
- package/lib/tree/ampersand.js.map +0 -1
- package/lib/tree/any.d.ts +0 -58
- package/lib/tree/any.d.ts.map +0 -1
- package/lib/tree/any.js +0 -104
- package/lib/tree/any.js.map +0 -1
- package/lib/tree/at-rule.d.ts +0 -53
- package/lib/tree/at-rule.d.ts.map +0 -1
- package/lib/tree/at-rule.js +0 -503
- package/lib/tree/at-rule.js.map +0 -1
- package/lib/tree/block.d.ts +0 -22
- package/lib/tree/block.d.ts.map +0 -1
- package/lib/tree/block.js +0 -24
- package/lib/tree/block.js.map +0 -1
- package/lib/tree/bool.d.ts +0 -18
- package/lib/tree/bool.d.ts.map +0 -1
- package/lib/tree/bool.js +0 -28
- package/lib/tree/bool.js.map +0 -1
- package/lib/tree/call.d.ts +0 -66
- package/lib/tree/call.d.ts.map +0 -1
- package/lib/tree/call.js +0 -306
- package/lib/tree/call.js.map +0 -1
- package/lib/tree/collection.d.ts +0 -30
- package/lib/tree/collection.d.ts.map +0 -1
- package/lib/tree/collection.js +0 -37
- package/lib/tree/collection.js.map +0 -1
- package/lib/tree/color.d.ts +0 -101
- package/lib/tree/color.d.ts.map +0 -1
- package/lib/tree/color.js +0 -513
- package/lib/tree/color.js.map +0 -1
- package/lib/tree/combinator.d.ts +0 -13
- package/lib/tree/combinator.d.ts.map +0 -1
- package/lib/tree/combinator.js +0 -12
- package/lib/tree/combinator.js.map +0 -1
- package/lib/tree/comment.d.ts +0 -20
- package/lib/tree/comment.d.ts.map +0 -1
- package/lib/tree/comment.js +0 -19
- package/lib/tree/comment.js.map +0 -1
- package/lib/tree/condition.d.ts +0 -31
- package/lib/tree/condition.d.ts.map +0 -1
- package/lib/tree/condition.js +0 -103
- package/lib/tree/condition.js.map +0 -1
- package/lib/tree/control.d.ts +0 -104
- package/lib/tree/control.d.ts.map +0 -1
- package/lib/tree/control.js +0 -430
- package/lib/tree/control.js.map +0 -1
- package/lib/tree/declaration-custom.d.ts +0 -18
- package/lib/tree/declaration-custom.d.ts.map +0 -1
- package/lib/tree/declaration-custom.js +0 -24
- package/lib/tree/declaration-custom.js.map +0 -1
- package/lib/tree/declaration-var.d.ts +0 -35
- package/lib/tree/declaration-var.d.ts.map +0 -1
- package/lib/tree/declaration-var.js +0 -63
- package/lib/tree/declaration-var.js.map +0 -1
- package/lib/tree/declaration.d.ts +0 -78
- package/lib/tree/declaration.d.ts.map +0 -1
- package/lib/tree/declaration.js +0 -286
- package/lib/tree/declaration.js.map +0 -1
- package/lib/tree/default-guard.d.ts +0 -15
- package/lib/tree/default-guard.d.ts.map +0 -1
- package/lib/tree/default-guard.js +0 -19
- package/lib/tree/default-guard.js.map +0 -1
- package/lib/tree/dimension.d.ts +0 -34
- package/lib/tree/dimension.d.ts.map +0 -1
- package/lib/tree/dimension.js +0 -294
- package/lib/tree/dimension.js.map +0 -1
- package/lib/tree/expression.d.ts +0 -25
- package/lib/tree/expression.d.ts.map +0 -1
- package/lib/tree/expression.js +0 -32
- package/lib/tree/expression.js.map +0 -1
- package/lib/tree/extend-list.d.ts +0 -23
- package/lib/tree/extend-list.d.ts.map +0 -1
- package/lib/tree/extend-list.js +0 -23
- package/lib/tree/extend-list.js.map +0 -1
- package/lib/tree/extend.d.ts +0 -47
- package/lib/tree/extend.d.ts.map +0 -1
- package/lib/tree/extend.js +0 -296
- package/lib/tree/extend.js.map +0 -1
- package/lib/tree/function.d.ts +0 -48
- package/lib/tree/function.d.ts.map +0 -1
- package/lib/tree/function.js +0 -74
- package/lib/tree/function.js.map +0 -1
- package/lib/tree/import-js.d.ts +0 -35
- package/lib/tree/import-js.d.ts.map +0 -1
- package/lib/tree/import-js.js +0 -45
- package/lib/tree/import-js.js.map +0 -1
- package/lib/tree/import-style.d.ts +0 -156
- package/lib/tree/import-style.d.ts.map +0 -1
- package/lib/tree/import-style.js +0 -566
- package/lib/tree/import-style.js.map +0 -1
- package/lib/tree/index.d.ts +0 -71
- package/lib/tree/index.d.ts.map +0 -1
- package/lib/tree/index.js.map +0 -1
- package/lib/tree/interpolated-reference.d.ts +0 -24
- package/lib/tree/interpolated-reference.d.ts.map +0 -1
- package/lib/tree/interpolated-reference.js +0 -37
- package/lib/tree/interpolated-reference.js.map +0 -1
- package/lib/tree/interpolated.d.ts +0 -62
- package/lib/tree/interpolated.d.ts.map +0 -1
- package/lib/tree/interpolated.js +0 -204
- package/lib/tree/interpolated.js.map +0 -1
- package/lib/tree/js-array.d.ts +0 -10
- package/lib/tree/js-array.d.ts.map +0 -1
- package/lib/tree/js-array.js +0 -10
- package/lib/tree/js-array.js.map +0 -1
- package/lib/tree/js-expr.d.ts +0 -23
- package/lib/tree/js-expr.d.ts.map +0 -1
- package/lib/tree/js-expr.js +0 -28
- package/lib/tree/js-expr.js.map +0 -1
- package/lib/tree/js-function.d.ts +0 -20
- package/lib/tree/js-function.d.ts.map +0 -1
- package/lib/tree/js-function.js +0 -16
- package/lib/tree/js-function.js.map +0 -1
- package/lib/tree/js-object.d.ts +0 -10
- package/lib/tree/js-object.d.ts.map +0 -1
- package/lib/tree/js-object.js +0 -10
- package/lib/tree/js-object.js.map +0 -1
- package/lib/tree/list.d.ts +0 -38
- package/lib/tree/list.d.ts.map +0 -1
- package/lib/tree/list.js +0 -83
- package/lib/tree/list.js.map +0 -1
- package/lib/tree/log.d.ts +0 -29
- package/lib/tree/log.d.ts.map +0 -1
- package/lib/tree/log.js +0 -56
- package/lib/tree/log.js.map +0 -1
- package/lib/tree/mixin.d.ts +0 -87
- package/lib/tree/mixin.d.ts.map +0 -1
- package/lib/tree/mixin.js +0 -112
- package/lib/tree/mixin.js.map +0 -1
- package/lib/tree/negative.d.ts +0 -17
- package/lib/tree/negative.d.ts.map +0 -1
- package/lib/tree/negative.js +0 -22
- package/lib/tree/negative.js.map +0 -1
- package/lib/tree/nil.d.ts +0 -30
- package/lib/tree/nil.d.ts.map +0 -1
- package/lib/tree/nil.js +0 -35
- package/lib/tree/nil.js.map +0 -1
- package/lib/tree/node-base.d.ts +0 -361
- package/lib/tree/node-base.d.ts.map +0 -1
- package/lib/tree/node-base.js +0 -930
- package/lib/tree/node-base.js.map +0 -1
- package/lib/tree/node.d.ts +0 -10
- package/lib/tree/node.d.ts.map +0 -1
- package/lib/tree/node.js +0 -45
- package/lib/tree/node.js.map +0 -1
- package/lib/tree/number.d.ts +0 -21
- package/lib/tree/number.d.ts.map +0 -1
- package/lib/tree/number.js +0 -27
- package/lib/tree/number.js.map +0 -1
- package/lib/tree/operation.d.ts +0 -26
- package/lib/tree/operation.d.ts.map +0 -1
- package/lib/tree/operation.js +0 -103
- package/lib/tree/operation.js.map +0 -1
- package/lib/tree/paren.d.ts +0 -19
- package/lib/tree/paren.d.ts.map +0 -1
- package/lib/tree/paren.js +0 -92
- package/lib/tree/paren.js.map +0 -1
- package/lib/tree/query-condition.d.ts +0 -17
- package/lib/tree/query-condition.d.ts.map +0 -1
- package/lib/tree/query-condition.js +0 -39
- package/lib/tree/query-condition.js.map +0 -1
- package/lib/tree/quoted.d.ts +0 -28
- package/lib/tree/quoted.d.ts.map +0 -1
- package/lib/tree/quoted.js +0 -75
- package/lib/tree/quoted.js.map +0 -1
- package/lib/tree/range.d.ts +0 -33
- package/lib/tree/range.d.ts.map +0 -1
- package/lib/tree/range.js +0 -47
- package/lib/tree/range.js.map +0 -1
- package/lib/tree/reference.d.ts +0 -76
- package/lib/tree/reference.d.ts.map +0 -1
- package/lib/tree/reference.js +0 -521
- package/lib/tree/reference.js.map +0 -1
- package/lib/tree/rest.d.ts +0 -15
- package/lib/tree/rest.d.ts.map +0 -1
- package/lib/tree/rest.js +0 -32
- package/lib/tree/rest.js.map +0 -1
- package/lib/tree/rules-raw.d.ts +0 -17
- package/lib/tree/rules-raw.d.ts.map +0 -1
- package/lib/tree/rules-raw.js +0 -37
- package/lib/tree/rules-raw.js.map +0 -1
- package/lib/tree/rules.d.ts +0 -262
- package/lib/tree/rules.d.ts.map +0 -1
- package/lib/tree/rules.js +0 -2359
- package/lib/tree/rules.js.map +0 -1
- package/lib/tree/ruleset.d.ts +0 -92
- package/lib/tree/ruleset.d.ts.map +0 -1
- package/lib/tree/ruleset.js +0 -528
- package/lib/tree/ruleset.js.map +0 -1
- package/lib/tree/selector-attr.d.ts +0 -31
- package/lib/tree/selector-attr.d.ts.map +0 -1
- package/lib/tree/selector-attr.js +0 -99
- package/lib/tree/selector-attr.js.map +0 -1
- package/lib/tree/selector-basic.d.ts +0 -24
- package/lib/tree/selector-basic.d.ts.map +0 -1
- package/lib/tree/selector-basic.js +0 -38
- package/lib/tree/selector-basic.js.map +0 -1
- package/lib/tree/selector-capture.d.ts +0 -23
- package/lib/tree/selector-capture.d.ts.map +0 -1
- package/lib/tree/selector-capture.js +0 -34
- package/lib/tree/selector-capture.js.map +0 -1
- package/lib/tree/selector-complex.d.ts +0 -40
- package/lib/tree/selector-complex.d.ts.map +0 -1
- package/lib/tree/selector-complex.js +0 -143
- package/lib/tree/selector-complex.js.map +0 -1
- package/lib/tree/selector-compound.d.ts +0 -16
- package/lib/tree/selector-compound.d.ts.map +0 -1
- package/lib/tree/selector-compound.js +0 -114
- package/lib/tree/selector-compound.js.map +0 -1
- package/lib/tree/selector-interpolated.d.ts +0 -23
- package/lib/tree/selector-interpolated.d.ts.map +0 -1
- package/lib/tree/selector-interpolated.js +0 -27
- package/lib/tree/selector-interpolated.js.map +0 -1
- package/lib/tree/selector-list.d.ts +0 -17
- package/lib/tree/selector-list.d.ts.map +0 -1
- package/lib/tree/selector-list.js +0 -174
- package/lib/tree/selector-list.js.map +0 -1
- package/lib/tree/selector-pseudo.d.ts +0 -42
- package/lib/tree/selector-pseudo.d.ts.map +0 -1
- package/lib/tree/selector-pseudo.js +0 -204
- package/lib/tree/selector-pseudo.js.map +0 -1
- package/lib/tree/selector-simple.d.ts +0 -5
- package/lib/tree/selector-simple.d.ts.map +0 -1
- package/lib/tree/selector-simple.js +0 -6
- package/lib/tree/selector-simple.js.map +0 -1
- package/lib/tree/selector.d.ts +0 -43
- package/lib/tree/selector.d.ts.map +0 -1
- package/lib/tree/selector.js +0 -56
- package/lib/tree/selector.js.map +0 -1
- package/lib/tree/sequence.d.ts +0 -43
- package/lib/tree/sequence.d.ts.map +0 -1
- package/lib/tree/sequence.js +0 -151
- package/lib/tree/sequence.js.map +0 -1
- package/lib/tree/tree.d.ts +0 -87
- package/lib/tree/tree.d.ts.map +0 -1
- package/lib/tree/tree.js +0 -2
- package/lib/tree/tree.js.map +0 -1
- package/lib/tree/url.d.ts +0 -18
- package/lib/tree/url.d.ts.map +0 -1
- package/lib/tree/url.js +0 -35
- package/lib/tree/url.js.map +0 -1
- package/lib/tree/util/__tests__/debug-log.d.ts +0 -1
- package/lib/tree/util/__tests__/debug-log.d.ts.map +0 -1
- package/lib/tree/util/__tests__/debug-log.js +0 -36
- package/lib/tree/util/__tests__/debug-log.js.map +0 -1
- package/lib/tree/util/calculate.d.ts +0 -3
- package/lib/tree/util/calculate.d.ts.map +0 -1
- package/lib/tree/util/calculate.js +0 -10
- package/lib/tree/util/calculate.js.map +0 -1
- package/lib/tree/util/cast.d.ts +0 -10
- package/lib/tree/util/cast.d.ts.map +0 -1
- package/lib/tree/util/cast.js +0 -87
- package/lib/tree/util/cast.js.map +0 -1
- package/lib/tree/util/cloning.d.ts +0 -4
- package/lib/tree/util/cloning.d.ts.map +0 -1
- package/lib/tree/util/cloning.js +0 -8
- package/lib/tree/util/cloning.js.map +0 -1
- package/lib/tree/util/collections.d.ts +0 -57
- package/lib/tree/util/collections.d.ts.map +0 -1
- package/lib/tree/util/collections.js +0 -136
- package/lib/tree/util/collections.js.map +0 -1
- package/lib/tree/util/compare.d.ts +0 -11
- package/lib/tree/util/compare.d.ts.map +0 -1
- package/lib/tree/util/compare.js +0 -89
- package/lib/tree/util/compare.js.map +0 -1
- package/lib/tree/util/extend-helpers.d.ts +0 -2
- package/lib/tree/util/extend-helpers.d.ts.map +0 -1
- package/lib/tree/util/extend-helpers.js +0 -2
- package/lib/tree/util/extend-helpers.js.map +0 -1
- package/lib/tree/util/extend-roots.d.ts +0 -37
- package/lib/tree/util/extend-roots.d.ts.map +0 -1
- package/lib/tree/util/extend-roots.js +0 -700
- package/lib/tree/util/extend-roots.js.map +0 -1
- package/lib/tree/util/extend-roots.old.d.ts +0 -132
- package/lib/tree/util/extend-roots.old.d.ts.map +0 -1
- package/lib/tree/util/extend-roots.old.js +0 -2272
- package/lib/tree/util/extend-roots.old.js.map +0 -1
- package/lib/tree/util/extend-trace-debug.d.ts +0 -13
- package/lib/tree/util/extend-trace-debug.d.ts.map +0 -1
- package/lib/tree/util/extend-trace-debug.js +0 -34
- package/lib/tree/util/extend-trace-debug.js.map +0 -1
- package/lib/tree/util/extend-walk.d.ts +0 -53
- package/lib/tree/util/extend-walk.d.ts.map +0 -1
- package/lib/tree/util/extend-walk.js +0 -881
- package/lib/tree/util/extend-walk.js.map +0 -1
- package/lib/tree/util/extend.d.ts +0 -218
- package/lib/tree/util/extend.d.ts.map +0 -1
- package/lib/tree/util/extend.js +0 -3182
- package/lib/tree/util/extend.js.map +0 -1
- package/lib/tree/util/find-extendable-locations.d.ts +0 -2
- package/lib/tree/util/find-extendable-locations.d.ts.map +0 -1
- package/lib/tree/util/find-extendable-locations.js +0 -2
- package/lib/tree/util/find-extendable-locations.js.map +0 -1
- package/lib/tree/util/format.d.ts +0 -20
- package/lib/tree/util/format.d.ts.map +0 -1
- package/lib/tree/util/format.js +0 -67
- package/lib/tree/util/format.js.map +0 -1
- package/lib/tree/util/is-node.d.ts +0 -13
- package/lib/tree/util/is-node.d.ts.map +0 -1
- package/lib/tree/util/is-node.js +0 -43
- package/lib/tree/util/is-node.js.map +0 -1
- package/lib/tree/util/print.d.ts +0 -80
- package/lib/tree/util/print.d.ts.map +0 -1
- package/lib/tree/util/print.js +0 -205
- package/lib/tree/util/print.js.map +0 -1
- package/lib/tree/util/process-leading-is.d.ts +0 -25
- package/lib/tree/util/process-leading-is.d.ts.map +0 -1
- package/lib/tree/util/process-leading-is.js +0 -364
- package/lib/tree/util/process-leading-is.js.map +0 -1
- package/lib/tree/util/recursion-helper.d.ts +0 -15
- package/lib/tree/util/recursion-helper.d.ts.map +0 -1
- package/lib/tree/util/recursion-helper.js +0 -43
- package/lib/tree/util/recursion-helper.js.map +0 -1
- package/lib/tree/util/regex.d.ts +0 -4
- package/lib/tree/util/regex.d.ts.map +0 -1
- package/lib/tree/util/regex.js +0 -4
- package/lib/tree/util/regex.js.map +0 -1
- package/lib/tree/util/registry-utils.d.ts +0 -192
- package/lib/tree/util/registry-utils.d.ts.map +0 -1
- package/lib/tree/util/registry-utils.js +0 -1214
- package/lib/tree/util/registry-utils.js.map +0 -1
- package/lib/tree/util/ruleset-trace.d.ts +0 -4
- package/lib/tree/util/ruleset-trace.d.ts.map +0 -1
- package/lib/tree/util/ruleset-trace.js +0 -14
- package/lib/tree/util/ruleset-trace.js.map +0 -1
- package/lib/tree/util/selector-compare.d.ts +0 -2
- package/lib/tree/util/selector-compare.d.ts.map +0 -1
- package/lib/tree/util/selector-compare.js +0 -2
- package/lib/tree/util/selector-compare.js.map +0 -1
- package/lib/tree/util/selector-match-core.d.ts +0 -184
- package/lib/tree/util/selector-match-core.d.ts.map +0 -1
- package/lib/tree/util/selector-match-core.js +0 -1603
- package/lib/tree/util/selector-match-core.js.map +0 -1
- package/lib/tree/util/selector-utils.d.ts +0 -30
- package/lib/tree/util/selector-utils.d.ts.map +0 -1
- package/lib/tree/util/selector-utils.js +0 -100
- package/lib/tree/util/selector-utils.js.map +0 -1
- package/lib/tree/util/serialize-helper.d.ts +0 -13
- package/lib/tree/util/serialize-helper.d.ts.map +0 -1
- package/lib/tree/util/serialize-helper.js +0 -387
- package/lib/tree/util/serialize-helper.js.map +0 -1
- package/lib/tree/util/serialize-types.d.ts +0 -9
- package/lib/tree/util/serialize-types.d.ts.map +0 -1
- package/lib/tree/util/serialize-types.js +0 -216
- package/lib/tree/util/serialize-types.js.map +0 -1
- package/lib/tree/util/should-operate.d.ts +0 -23
- package/lib/tree/util/should-operate.d.ts.map +0 -1
- package/lib/tree/util/should-operate.js +0 -46
- package/lib/tree/util/should-operate.js.map +0 -1
- package/lib/tree/util/sourcemap.d.ts +0 -7
- package/lib/tree/util/sourcemap.d.ts.map +0 -1
- package/lib/tree/util/sourcemap.js +0 -25
- package/lib/tree/util/sourcemap.js.map +0 -1
- package/lib/types/config.d.ts +0 -205
- package/lib/types/config.d.ts.map +0 -1
- package/lib/types/config.js +0 -2
- package/lib/types/config.js.map +0 -1
- package/lib/types/index.d.ts +0 -15
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/index.js +0 -3
- package/lib/types/index.js.map +0 -1
- package/lib/types/modes.d.ts.map +0 -1
- package/lib/types/modes.js +0 -2
- package/lib/types/modes.js.map +0 -1
- package/lib/types.d.ts +0 -61
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/lib/use-webpack-resolver.d.ts +0 -9
- package/lib/use-webpack-resolver.d.ts.map +0 -1
- package/lib/use-webpack-resolver.js +0 -41
- package/lib/use-webpack-resolver.js.map +0 -1
- package/lib/visitor/index.d.ts +0 -136
- package/lib/visitor/index.d.ts.map +0 -1
- package/lib/visitor/index.js +0 -135
- package/lib/visitor/index.js.map +0 -1
- package/lib/visitor/less-visitor.d.ts +0 -7
- package/lib/visitor/less-visitor.d.ts.map +0 -1
- package/lib/visitor/less-visitor.js.map +0 -1
|
@@ -1,881 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Walk-and-consume extend algorithm.
|
|
3
|
-
*
|
|
4
|
-
* The find selector decomposes into *positions* — each position is a set of
|
|
5
|
-
* simple selectors (AND). Positions are separated by combinators. The walk
|
|
6
|
-
* progresses through the target tree, consuming find positions:
|
|
7
|
-
*
|
|
8
|
-
* - SimpleSelector find → 1 position, 1 simple
|
|
9
|
-
* - CompoundSelector find → 1 position, N simples
|
|
10
|
-
* - ComplexSelector find → M positions separated by combinators
|
|
11
|
-
*
|
|
12
|
-
* At each target position:
|
|
13
|
-
* - full match → consume ALL of a compound
|
|
14
|
-
* - partial → consume any subset of a compound
|
|
15
|
-
* - :is() / SelectorList → OR (try each alternative)
|
|
16
|
-
*
|
|
17
|
-
* ## :is() as AND branch
|
|
18
|
-
*
|
|
19
|
-
* When :is() appears as a component in a compound selector, it adds an AND
|
|
20
|
-
* branch. The *last* selector in each :is() alternative occupies the same
|
|
21
|
-
* compound position as its sibling components. Everything before the last
|
|
22
|
-
* selector is an ancestral prefix — a separate path.
|
|
23
|
-
*
|
|
24
|
-
* .a:is(.x > .y).b
|
|
25
|
-
* → subject has .a, .b, .y (all at one position, ANDed)
|
|
26
|
-
* → AND is child of .x (ancestral branch from :is())
|
|
27
|
-
*
|
|
28
|
-
* This is equivalent to .x > .a.y.b when there's only one branch. But when
|
|
29
|
-
* combined with outer complex context, the branches can't be flattened:
|
|
30
|
-
*
|
|
31
|
-
* div + .a:is(.x > .y).b
|
|
32
|
-
* → subject has .a, .b, .y
|
|
33
|
-
* → AND follows div (outer complex path)
|
|
34
|
-
* → AND is child of .x (:is() branch path)
|
|
35
|
-
*
|
|
36
|
-
* Walking handles both paths naturally. Flattening cannot represent this.
|
|
37
|
-
*
|
|
38
|
-
* ## Reading back-to-front
|
|
39
|
-
*
|
|
40
|
-
* Selectors read back-to-front: rightmost = subject element, leftward =
|
|
41
|
-
* ancestors/preceding. For :is() alternatives that are complex selectors,
|
|
42
|
-
* the last element is at the current position; the rest is a branch going up.
|
|
43
|
-
*
|
|
44
|
-
* ComplexSelector find support is currently used for diagnostics only
|
|
45
|
-
* (wouldExtendChange); the extend application falls through to legacy
|
|
46
|
-
* due to createProcessedSelector differences.
|
|
47
|
-
*/
|
|
48
|
-
import { SelectorList } from '../selector-list.js';
|
|
49
|
-
import { ComplexSelector } from '../selector-complex.js';
|
|
50
|
-
import { CompoundSelector } from '../selector-compound.js';
|
|
51
|
-
import { PseudoSelector } from '../selector-pseudo.js';
|
|
52
|
-
import { Ampersand } from '../ampersand.js';
|
|
53
|
-
import { isNode } from './is-node.js';
|
|
54
|
-
import { F_EXTENDED, F_EXTEND_TARGET } from '../node.js';
|
|
55
|
-
import { createProcessedSelector } from './extend.js';
|
|
56
|
-
const { isArray } = Array;
|
|
57
|
-
function decomposeFind(find) {
|
|
58
|
-
if (isNode(find, 'ComplexSelector')) {
|
|
59
|
-
const positions = [];
|
|
60
|
-
const combinators = [];
|
|
61
|
-
for (const comp of find.value) {
|
|
62
|
-
if (isNode(comp, 'Combinator')) {
|
|
63
|
-
combinators.push(comp.value);
|
|
64
|
-
}
|
|
65
|
-
else if (isNode(comp, 'CompoundSelector')) {
|
|
66
|
-
positions.push([...comp.value]);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
positions.push([comp]);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return { positions, combinators, original: find };
|
|
73
|
-
}
|
|
74
|
-
if (isNode(find, 'CompoundSelector')) {
|
|
75
|
-
return {
|
|
76
|
-
positions: [[...find.value]],
|
|
77
|
-
combinators: [],
|
|
78
|
-
original: find
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
// SimpleSelector or anything else: single position, single simple
|
|
82
|
-
return { positions: [[find]], combinators: [], original: find };
|
|
83
|
-
}
|
|
84
|
-
/** Whether the find spans multiple positions (has combinators) */
|
|
85
|
-
function isMultiPosition(spec) {
|
|
86
|
-
return spec.positions.length > 1;
|
|
87
|
-
}
|
|
88
|
-
/** Whether the current position has multiple simples (compound) */
|
|
89
|
-
function isMultiSimple(spec) {
|
|
90
|
-
return spec.positions.length === 1 && spec.positions[0].length > 1;
|
|
91
|
-
}
|
|
92
|
-
// ─────────────────────────────────────────────────
|
|
93
|
-
// Equivalence checks
|
|
94
|
-
// ─────────────────────────────────────────────────
|
|
95
|
-
function isWholeNodeMatch(node, spec) {
|
|
96
|
-
const find = spec.original;
|
|
97
|
-
if (isNode(node, 'SelectorList') && !isNode(find, 'SelectorList')) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
if (isNode(node, 'ComplexSelector') && isNode(find, 'ComplexSelector')) {
|
|
101
|
-
return areComplexEquivalent(node, find);
|
|
102
|
-
}
|
|
103
|
-
if (isNode(node, 'ComplexSelector') && !isNode(find, 'ComplexSelector')) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
if (isNode(node, 'CompoundSelector') && isNode(find, 'CompoundSelector')) {
|
|
107
|
-
return areCompoundsEquivalent(node, find);
|
|
108
|
-
}
|
|
109
|
-
if (isNode(node, 'CompoundSelector') && !isNode(find, 'CompoundSelector')) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
return node.valueOf() === find.valueOf();
|
|
113
|
-
}
|
|
114
|
-
function areCompoundsEquivalent(a, b) {
|
|
115
|
-
if (a.value.length !== b.value.length) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
if (a.valueOf() === b.valueOf()) {
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
const used = new Uint8Array(b.value.length);
|
|
122
|
-
for (const aComp of a.value) {
|
|
123
|
-
const aVal = aComp.valueOf();
|
|
124
|
-
let found = false;
|
|
125
|
-
for (let j = 0; j < b.value.length; j++) {
|
|
126
|
-
if (!used[j] && b.value[j].valueOf() === aVal) {
|
|
127
|
-
used[j] = 1;
|
|
128
|
-
found = true;
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (!found) {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
function areComplexEquivalent(a, b) {
|
|
139
|
-
if (a.value.length !== b.value.length) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
if (a.valueOf() === b.valueOf()) {
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
for (let i = 0; i < a.value.length; i++) {
|
|
146
|
-
const ac = a.value[i];
|
|
147
|
-
const bc = b.value[i];
|
|
148
|
-
if (isNode(ac, 'Combinator') !== isNode(bc, 'Combinator')) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
if (isNode(ac, 'Combinator')) {
|
|
152
|
-
if (ac.value !== bc.value) {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
if (isNode(ac, 'CompoundSelector') && isNode(bc, 'CompoundSelector')) {
|
|
158
|
-
if (!areCompoundsEquivalent(ac, bc)) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
else if (ac.valueOf() !== bc.valueOf()) {
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
// ─────────────────────────────────────────────────
|
|
169
|
-
// Position matching
|
|
170
|
-
// ─────────────────────────────────────────────────
|
|
171
|
-
/**
|
|
172
|
-
* Extract what's at the current position from a selector.
|
|
173
|
-
*
|
|
174
|
-
* For a ComplexSelector, the last non-combinator component is at the current
|
|
175
|
-
* position; everything before it is an ancestral prefix. For anything else,
|
|
176
|
-
* the entire selector is at the current position.
|
|
177
|
-
*
|
|
178
|
-
* .a → .a
|
|
179
|
-
* .a.b → .a.b
|
|
180
|
-
* .x > .y → .y (the .x > prefix is an ancestral branch)
|
|
181
|
-
* .x > .y.z → .y.z
|
|
182
|
-
*/
|
|
183
|
-
function tailOf(sel) {
|
|
184
|
-
if (isNode(sel, 'ComplexSelector')) {
|
|
185
|
-
const comps = sel.value;
|
|
186
|
-
for (let i = comps.length - 1; i >= 0; i--) {
|
|
187
|
-
if (!isNode(comps[i], 'Combinator')) {
|
|
188
|
-
return comps[i];
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return sel;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Does `find` match `target` at this compound position?
|
|
196
|
-
*
|
|
197
|
-
* Like compoundComponentMatches, but tail-aware: when an :is() alternative
|
|
198
|
-
* is a ComplexSelector, only its tail (last non-combinator) is at the
|
|
199
|
-
* current position.
|
|
200
|
-
*
|
|
201
|
-
* .y vs :is(.x > .y) → true (.y is the tail of .x > .y)
|
|
202
|
-
* .x vs :is(.x > .y) → false (.x is in the ancestral prefix)
|
|
203
|
-
*/
|
|
204
|
-
function positionSimpleMatches(find, target) {
|
|
205
|
-
if (find.valueOf() === target.valueOf()) {
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
// find is :is() → OR: try each alternative's tail
|
|
209
|
-
if (isNode(find, 'PseudoSelector') && find.value.name === ':is' && find.value.arg) {
|
|
210
|
-
const arg = find.value.arg;
|
|
211
|
-
if (isNode(arg, 'SelectorList')) {
|
|
212
|
-
return arg.value.some((alt) => positionSimpleMatches(tailOf(alt), target));
|
|
213
|
-
}
|
|
214
|
-
return positionSimpleMatches(tailOf(arg), target);
|
|
215
|
-
}
|
|
216
|
-
// target is :is() → OR: try each alternative's tail
|
|
217
|
-
if (isNode(target, 'PseudoSelector') && target.value.name === ':is' && target.value.arg) {
|
|
218
|
-
const arg = target.value.arg;
|
|
219
|
-
if (isNode(arg, 'SelectorList')) {
|
|
220
|
-
return arg.value.some((alt) => positionSimpleMatches(find, tailOf(alt)));
|
|
221
|
-
}
|
|
222
|
-
return positionSimpleMatches(find, tailOf(arg));
|
|
223
|
-
}
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Does `targetComp` match `findComp` at this position?
|
|
228
|
-
* Handles :is() as OR alternatives (tail-aware) and compound equivalence.
|
|
229
|
-
*/
|
|
230
|
-
function positionComponentMatches(findComp, targetComp) {
|
|
231
|
-
if (isNode(findComp, 'CompoundSelector') && isNode(targetComp, 'CompoundSelector')) {
|
|
232
|
-
return areCompoundsEquivalent(findComp, targetComp);
|
|
233
|
-
}
|
|
234
|
-
return positionSimpleMatches(findComp, targetComp);
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Try to match find positions as a contiguous subsequence in target
|
|
238
|
-
* components. Returns the start index or -1.
|
|
239
|
-
*/
|
|
240
|
-
function findSubsequence(targetComps, spec) {
|
|
241
|
-
// Reconstruct find components (positions interleaved with combinators)
|
|
242
|
-
const findComps = [];
|
|
243
|
-
for (let p = 0; p < spec.positions.length; p++) {
|
|
244
|
-
if (p > 0) {
|
|
245
|
-
findComps.push({ type: 'Combinator', value: spec.combinators[p - 1] });
|
|
246
|
-
}
|
|
247
|
-
const simples = spec.positions[p];
|
|
248
|
-
if (simples.length === 1) {
|
|
249
|
-
findComps.push(simples[0]);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
findComps.push({ type: 'CompoundSelector', value: simples, _isVirtual: true, simples });
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
const maxStart = targetComps.length - findComps.length;
|
|
256
|
-
for (let start = 0; start <= maxStart; start++) {
|
|
257
|
-
let matches = true;
|
|
258
|
-
for (let j = 0; j < findComps.length; j++) {
|
|
259
|
-
const tc = targetComps[start + j];
|
|
260
|
-
const fc = findComps[j];
|
|
261
|
-
if (fc.type === 'Combinator') {
|
|
262
|
-
if (!isNode(tc, 'Combinator') || tc.value !== fc.value) {
|
|
263
|
-
matches = false;
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
if (isNode(tc, 'Combinator')) {
|
|
269
|
-
matches = false;
|
|
270
|
-
break;
|
|
271
|
-
}
|
|
272
|
-
if (fc._isVirtual) {
|
|
273
|
-
// Virtual compound: check if all simples match the target component
|
|
274
|
-
if (isNode(tc, 'CompoundSelector')) {
|
|
275
|
-
if (!areCompoundsEquivalent(CompoundSelector.create(fc.simples), tc)) {
|
|
276
|
-
matches = false;
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
matches = false;
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
else if (!positionComponentMatches(fc, tc)) {
|
|
286
|
-
matches = false;
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
if (matches) {
|
|
292
|
-
return start;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return -1;
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Try to consume find simples from a compound's components (subsequence match).
|
|
299
|
-
* Returns matched indices or null if not all consumed.
|
|
300
|
-
*/
|
|
301
|
-
function consumeSimples(targetComps, findSimples) {
|
|
302
|
-
const matchIndices = [];
|
|
303
|
-
let findIdx = 0;
|
|
304
|
-
for (let i = 0; i < targetComps.length && findIdx < findSimples.length; i++) {
|
|
305
|
-
if (positionSimpleMatches(findSimples[findIdx], targetComps[i])) {
|
|
306
|
-
matchIndices.push(i);
|
|
307
|
-
findIdx++;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return matchIndices.length === findSimples.length ? matchIndices : null;
|
|
311
|
-
}
|
|
312
|
-
const ROOT_CTX = {
|
|
313
|
-
isRoot: true,
|
|
314
|
-
parentType: null,
|
|
315
|
-
hasContentBefore: false,
|
|
316
|
-
hasContentAfter: false
|
|
317
|
-
};
|
|
318
|
-
// ─────────────────────────────────────────────────
|
|
319
|
-
// Quick eligibility check
|
|
320
|
-
// ─────────────────────────────────────────────────
|
|
321
|
-
export function canUseWalkAndConsume(target, find) {
|
|
322
|
-
if (!isNode(find, 'SimpleSelector')
|
|
323
|
-
&& !isNode(find, 'CompoundSelector')
|
|
324
|
-
&& !isNode(find, 'ComplexSelector')) {
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
if (containsAmpersand(target)) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
return true;
|
|
331
|
-
}
|
|
332
|
-
export function extendWithNeedsConflictValidation(extendWith) {
|
|
333
|
-
if (isNode(extendWith, 'CompoundSelector')) {
|
|
334
|
-
return extendWith.value.some((child) => child.isTag || child.isId);
|
|
335
|
-
}
|
|
336
|
-
if (extendWith.isTag || extendWith.isId) {
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
return false;
|
|
340
|
-
}
|
|
341
|
-
function containsAmpersand(sel) {
|
|
342
|
-
if (sel instanceof Ampersand) {
|
|
343
|
-
return true;
|
|
344
|
-
}
|
|
345
|
-
if (isNode(sel, 'SelectorList') || isNode(sel, 'CompoundSelector') || isNode(sel, 'ComplexSelector')) {
|
|
346
|
-
return sel.value.some((child) => containsAmpersand(child));
|
|
347
|
-
}
|
|
348
|
-
if (isNode(sel, 'PseudoSelector') && sel.value.arg && sel.value.arg.isSelector) {
|
|
349
|
-
return containsAmpersand(sel.value.arg);
|
|
350
|
-
}
|
|
351
|
-
return false;
|
|
352
|
-
}
|
|
353
|
-
// ─────────────────────────────────────────────────
|
|
354
|
-
// Main entry point
|
|
355
|
-
// ─────────────────────────────────────────────────
|
|
356
|
-
export function walkAndExtend(target, find, extendWith, partial) {
|
|
357
|
-
const spec = decomposeFind(find);
|
|
358
|
-
return walkNode(target, spec, extendWith, partial, ROOT_CTX);
|
|
359
|
-
}
|
|
360
|
-
// ─────────────────────────────────────────────────
|
|
361
|
-
// Recursive walk
|
|
362
|
-
// ─────────────────────────────────────────────────
|
|
363
|
-
function walkNode(node, spec, extendWith, partial, ctx) {
|
|
364
|
-
// 1. Whole-node equivalence
|
|
365
|
-
if (isWholeNodeMatch(node, spec)) {
|
|
366
|
-
return applyWholeMatch(node, spec, extendWith, partial, ctx);
|
|
367
|
-
}
|
|
368
|
-
// 2. Recurse into containers
|
|
369
|
-
if (isNode(node, 'SelectorList')) {
|
|
370
|
-
return walkSelectorList(node, spec, extendWith, partial, ctx);
|
|
371
|
-
}
|
|
372
|
-
if (isNode(node, 'ComplexSelector')) {
|
|
373
|
-
return walkComplexSelector(node, spec, extendWith, partial, ctx);
|
|
374
|
-
}
|
|
375
|
-
if (isNode(node, 'CompoundSelector')) {
|
|
376
|
-
return walkCompoundSelector(node, spec, extendWith, partial, ctx);
|
|
377
|
-
}
|
|
378
|
-
if (isNode(node, 'PseudoSelector') && node.value.arg && node.value.arg.isSelector) {
|
|
379
|
-
return walkPseudoSelector(node, spec, extendWith, partial, ctx);
|
|
380
|
-
}
|
|
381
|
-
// 3. No match
|
|
382
|
-
return node;
|
|
383
|
-
}
|
|
384
|
-
// ─────────────────────────────────────────────────
|
|
385
|
-
// Whole-match transformation
|
|
386
|
-
// ─────────────────────────────────────────────────
|
|
387
|
-
function applyWholeMatch(node, spec, extendWith, partial, ctx) {
|
|
388
|
-
const findVal = spec.original.valueOf();
|
|
389
|
-
const extendVal = extendWith.valueOf();
|
|
390
|
-
if (findVal === extendVal) {
|
|
391
|
-
return node;
|
|
392
|
-
}
|
|
393
|
-
if (!partial) {
|
|
394
|
-
if (ctx.parentType === 'CompoundSelector' || ctx.parentType === 'ComplexSelector') {
|
|
395
|
-
return node;
|
|
396
|
-
}
|
|
397
|
-
return makeList(node, extendWith);
|
|
398
|
-
}
|
|
399
|
-
if (ctx.parentType === 'CompoundSelector' || ctx.parentType === 'ComplexSelector') {
|
|
400
|
-
return wrapInIs(node, extendWith);
|
|
401
|
-
}
|
|
402
|
-
return makeList(node, extendWith, true);
|
|
403
|
-
}
|
|
404
|
-
// ─────────────────────────────────────────────────
|
|
405
|
-
// Container walkers
|
|
406
|
-
// ─────────────────────────────────────────────────
|
|
407
|
-
function walkSelectorList(list, spec, extendWith, partial, _ctx) {
|
|
408
|
-
const items = list.value;
|
|
409
|
-
const originals = [];
|
|
410
|
-
const appended = [];
|
|
411
|
-
let anyChanged = false;
|
|
412
|
-
for (let i = 0; i < items.length; i++) {
|
|
413
|
-
const item = items[i];
|
|
414
|
-
const childCtx = {
|
|
415
|
-
isRoot: false,
|
|
416
|
-
parentType: 'SelectorList',
|
|
417
|
-
hasContentBefore: i > 0,
|
|
418
|
-
hasContentAfter: i < items.length - 1
|
|
419
|
-
};
|
|
420
|
-
const extended = walkNode(item, spec, extendWith, partial, childCtx);
|
|
421
|
-
if (extended === item) {
|
|
422
|
-
originals.push(item);
|
|
423
|
-
}
|
|
424
|
-
else if (isNode(extended, 'SelectorList')) {
|
|
425
|
-
const extItems = extended.value;
|
|
426
|
-
const first = extItems[0];
|
|
427
|
-
first.addFlag(F_EXTENDED);
|
|
428
|
-
if (partial) {
|
|
429
|
-
first.addFlag(F_EXTEND_TARGET);
|
|
430
|
-
}
|
|
431
|
-
originals.push(first);
|
|
432
|
-
for (let j = 1; j < extItems.length; j++) {
|
|
433
|
-
const ext = extItems[j];
|
|
434
|
-
ext.addFlag(F_EXTENDED);
|
|
435
|
-
appended.push(ext);
|
|
436
|
-
}
|
|
437
|
-
anyChanged = true;
|
|
438
|
-
}
|
|
439
|
-
else {
|
|
440
|
-
extended.addFlag(F_EXTENDED);
|
|
441
|
-
originals.push(extended);
|
|
442
|
-
anyChanged = true;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
if (!anyChanged) {
|
|
446
|
-
return list;
|
|
447
|
-
}
|
|
448
|
-
const allSelectors = [...originals, ...appended];
|
|
449
|
-
const processed = createProcessedSelector(allSelectors, true);
|
|
450
|
-
const processedArray = isArray(processed) ? processed : [processed];
|
|
451
|
-
const safe = processedArray.map(s => (s === list ? s.clone(true) : s));
|
|
452
|
-
return SelectorList.create(safe).inherit(list);
|
|
453
|
-
}
|
|
454
|
-
function walkComplexSelector(complex, spec, extendWith, partial, ctx) {
|
|
455
|
-
// Multi-position find: try contiguous subsequence match
|
|
456
|
-
if (isMultiPosition(spec)) {
|
|
457
|
-
return consumePositionsFromComplex(complex, spec, extendWith, partial, ctx);
|
|
458
|
-
}
|
|
459
|
-
// Single-position find: walk each component individually
|
|
460
|
-
const components = complex.value;
|
|
461
|
-
let anyChanged = false;
|
|
462
|
-
const newComponents = [...components];
|
|
463
|
-
for (let i = 0; i < components.length; i++) {
|
|
464
|
-
const comp = components[i];
|
|
465
|
-
if (isNode(comp, 'Combinator')) {
|
|
466
|
-
continue;
|
|
467
|
-
}
|
|
468
|
-
const childCtx = {
|
|
469
|
-
isRoot: false,
|
|
470
|
-
parentType: 'ComplexSelector',
|
|
471
|
-
hasContentBefore: i > 0,
|
|
472
|
-
hasContentAfter: i < components.length - 1
|
|
473
|
-
};
|
|
474
|
-
const extended = walkNode(comp, spec, extendWith, partial, childCtx);
|
|
475
|
-
if (extended !== comp) {
|
|
476
|
-
newComponents[i] = extended;
|
|
477
|
-
anyChanged = true;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
if (!anyChanged) {
|
|
481
|
-
return complex;
|
|
482
|
-
}
|
|
483
|
-
return ComplexSelector.create(newComponents).inherit(complex);
|
|
484
|
-
}
|
|
485
|
-
function walkCompoundSelector(compound, spec, extendWith, partial, _ctx) {
|
|
486
|
-
// Multi-position: can't consume from a single compound
|
|
487
|
-
if (isMultiPosition(spec)) {
|
|
488
|
-
return compound;
|
|
489
|
-
}
|
|
490
|
-
// Multi-simple: consume find simples from compound components
|
|
491
|
-
if (isMultiSimple(spec) && partial) {
|
|
492
|
-
return consumeSimplesFromCompound(compound, spec, extendWith);
|
|
493
|
-
}
|
|
494
|
-
// Single-simple: walk individual components (recurses into :is())
|
|
495
|
-
const components = compound.value;
|
|
496
|
-
let anyChanged = false;
|
|
497
|
-
const newComponents = [...components];
|
|
498
|
-
for (let i = 0; i < components.length; i++) {
|
|
499
|
-
const comp = components[i];
|
|
500
|
-
const childCtx = {
|
|
501
|
-
isRoot: false,
|
|
502
|
-
parentType: 'CompoundSelector',
|
|
503
|
-
hasContentBefore: i > 0,
|
|
504
|
-
hasContentAfter: i < components.length - 1
|
|
505
|
-
};
|
|
506
|
-
const extended = walkNode(comp, spec, extendWith, partial, childCtx);
|
|
507
|
-
if (extended !== comp) {
|
|
508
|
-
newComponents[i] = extended;
|
|
509
|
-
anyChanged = true;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
if (!anyChanged) {
|
|
513
|
-
return compound;
|
|
514
|
-
}
|
|
515
|
-
return CompoundSelector.create(newComponents).inherit(compound);
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Consume find simples from a compound's components.
|
|
519
|
-
* Matched components → :is(matched, extendWith). Remainder stays.
|
|
520
|
-
*/
|
|
521
|
-
function consumeSimplesFromCompound(compound, spec, extendWith) {
|
|
522
|
-
const targetComps = compound.value;
|
|
523
|
-
const findSimples = spec.positions[0];
|
|
524
|
-
const matchIndices = consumeSimples(targetComps, findSimples);
|
|
525
|
-
if (!matchIndices) {
|
|
526
|
-
return compound;
|
|
527
|
-
}
|
|
528
|
-
const matchedSet = new Set(matchIndices);
|
|
529
|
-
const remainders = [];
|
|
530
|
-
for (let i = 0; i < targetComps.length; i++) {
|
|
531
|
-
if (!matchedSet.has(i)) {
|
|
532
|
-
remainders.push(targetComps[i]);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
const isWrapper = wrapInIs(spec.original, extendWith);
|
|
536
|
-
const newComponents = [isWrapper, ...remainders];
|
|
537
|
-
const result = CompoundSelector.create(newComponents).inherit(compound);
|
|
538
|
-
result.addFlag(F_EXTENDED);
|
|
539
|
-
return result;
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* Consume find positions from a complex selector's components.
|
|
543
|
-
* Contiguous subsequence match with exact combinator matching.
|
|
544
|
-
*/
|
|
545
|
-
function consumePositionsFromComplex(complex, spec, extendWith, partial, _ctx) {
|
|
546
|
-
const targetComps = complex.value;
|
|
547
|
-
const start = findSubsequence(targetComps, spec);
|
|
548
|
-
if (start < 0) {
|
|
549
|
-
return complex;
|
|
550
|
-
}
|
|
551
|
-
// Reconstruct find component count (positions + combinators)
|
|
552
|
-
const findLen = spec.positions.length + spec.combinators.length;
|
|
553
|
-
const end = start + findLen;
|
|
554
|
-
const hasBefore = start > 0;
|
|
555
|
-
const hasAfter = end < targetComps.length;
|
|
556
|
-
if (!partial && (hasBefore || hasAfter)) {
|
|
557
|
-
return complex;
|
|
558
|
-
}
|
|
559
|
-
if (!hasBefore && !hasAfter) {
|
|
560
|
-
return makeList(complex, extendWith, true);
|
|
561
|
-
}
|
|
562
|
-
// Wrap the matched segment
|
|
563
|
-
const matchedSegment = targetComps.slice(start, end);
|
|
564
|
-
const matchedComplex = ComplexSelector.create(matchedSegment).inherit(complex);
|
|
565
|
-
const isWrapper = wrapInIs(matchedComplex, extendWith);
|
|
566
|
-
const before = targetComps.slice(0, start);
|
|
567
|
-
const after = targetComps.slice(end);
|
|
568
|
-
const newComps = [...before, isWrapper, ...after];
|
|
569
|
-
const result = ComplexSelector.create(newComps).inherit(complex);
|
|
570
|
-
result.addFlag(F_EXTENDED);
|
|
571
|
-
return result;
|
|
572
|
-
}
|
|
573
|
-
function walkPseudoSelector(pseudo, spec, extendWith, partial, ctx) {
|
|
574
|
-
const arg = pseudo.value.arg;
|
|
575
|
-
// When :is() is inside a compound, only the tail of each complex
|
|
576
|
-
// alternative is at the current position. The ancestral prefix is
|
|
577
|
-
// a separate branch and should not be walked for matching.
|
|
578
|
-
if (ctx.parentType === 'CompoundSelector') {
|
|
579
|
-
return walkPseudoTailAware(pseudo, arg, spec, extendWith, partial, ctx);
|
|
580
|
-
}
|
|
581
|
-
const childCtx = {
|
|
582
|
-
isRoot: false,
|
|
583
|
-
parentType: 'PseudoSelector',
|
|
584
|
-
hasContentBefore: false,
|
|
585
|
-
hasContentAfter: false
|
|
586
|
-
};
|
|
587
|
-
const extendedArg = walkNode(arg, spec, extendWith, partial, childCtx);
|
|
588
|
-
if (extendedArg === arg) {
|
|
589
|
-
return pseudo;
|
|
590
|
-
}
|
|
591
|
-
if (!partial && (ctx.hasContentBefore || ctx.hasContentAfter)) {
|
|
592
|
-
return pseudo;
|
|
593
|
-
}
|
|
594
|
-
const result = PseudoSelector.create({
|
|
595
|
-
name: pseudo.value.name,
|
|
596
|
-
arg: extendedArg
|
|
597
|
-
}).inherit(pseudo);
|
|
598
|
-
result.generated = pseudo.generated;
|
|
599
|
-
return result;
|
|
600
|
-
}
|
|
601
|
-
/**
|
|
602
|
-
* Walk :is() alternatives tail-aware: for complex alternatives, only the
|
|
603
|
-
* last non-combinator component (the tail) is at the current compound
|
|
604
|
-
* position. The ancestral prefix is not walked.
|
|
605
|
-
*/
|
|
606
|
-
function walkPseudoTailAware(pseudo, arg, spec, extendWith, partial, ctx) {
|
|
607
|
-
if (isNode(arg, 'SelectorList')) {
|
|
608
|
-
const items = arg.value;
|
|
609
|
-
let anyChanged = false;
|
|
610
|
-
const originals = [];
|
|
611
|
-
const appended = [];
|
|
612
|
-
for (let i = 0; i < items.length; i++) {
|
|
613
|
-
const alt = items[i];
|
|
614
|
-
const extended = walkAlternativeTailAware(alt, spec, extendWith, partial);
|
|
615
|
-
if (extended === alt) {
|
|
616
|
-
originals.push(alt);
|
|
617
|
-
}
|
|
618
|
-
else if (isNode(extended, 'SelectorList')) {
|
|
619
|
-
// Decompose: first item stays in position, rest appended at end
|
|
620
|
-
const extItems = extended.value;
|
|
621
|
-
originals.push(extItems[0]);
|
|
622
|
-
for (let j = 1; j < extItems.length; j++) {
|
|
623
|
-
appended.push(extItems[j]);
|
|
624
|
-
}
|
|
625
|
-
anyChanged = true;
|
|
626
|
-
}
|
|
627
|
-
else {
|
|
628
|
-
originals.push(extended);
|
|
629
|
-
anyChanged = true;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
if (!anyChanged) {
|
|
633
|
-
return pseudo;
|
|
634
|
-
}
|
|
635
|
-
if (!partial && (ctx.hasContentBefore || ctx.hasContentAfter)) {
|
|
636
|
-
return pseudo;
|
|
637
|
-
}
|
|
638
|
-
const newList = SelectorList.create([...originals, ...appended]).inherit(arg);
|
|
639
|
-
const result = PseudoSelector.create({
|
|
640
|
-
name: pseudo.value.name,
|
|
641
|
-
arg: newList
|
|
642
|
-
}).inherit(pseudo);
|
|
643
|
-
result.generated = pseudo.generated;
|
|
644
|
-
return result;
|
|
645
|
-
}
|
|
646
|
-
// Single alternative
|
|
647
|
-
const extended = walkAlternativeTailAware(arg, spec, extendWith, partial);
|
|
648
|
-
if (extended === arg) {
|
|
649
|
-
return pseudo;
|
|
650
|
-
}
|
|
651
|
-
if (!partial && (ctx.hasContentBefore || ctx.hasContentAfter)) {
|
|
652
|
-
return pseudo;
|
|
653
|
-
}
|
|
654
|
-
const result = PseudoSelector.create({
|
|
655
|
-
name: pseudo.value.name,
|
|
656
|
-
arg: extended
|
|
657
|
-
}).inherit(pseudo);
|
|
658
|
-
result.generated = pseudo.generated;
|
|
659
|
-
return result;
|
|
660
|
-
}
|
|
661
|
-
/**
|
|
662
|
-
* Walk a single :is() alternative. If it's a ComplexSelector, only walk
|
|
663
|
-
* the tail (last non-combinator). Otherwise walk normally.
|
|
664
|
-
*/
|
|
665
|
-
function walkAlternativeTailAware(alt, spec, extendWith, partial) {
|
|
666
|
-
if (!isNode(alt, 'ComplexSelector')) {
|
|
667
|
-
// Simple or compound alternative: walk normally
|
|
668
|
-
const childCtx = {
|
|
669
|
-
isRoot: false,
|
|
670
|
-
parentType: 'PseudoSelector',
|
|
671
|
-
hasContentBefore: false,
|
|
672
|
-
hasContentAfter: false
|
|
673
|
-
};
|
|
674
|
-
return walkNode(alt, spec, extendWith, partial, childCtx);
|
|
675
|
-
}
|
|
676
|
-
// Complex alternative: only walk the tail
|
|
677
|
-
const comps = alt.value;
|
|
678
|
-
let tailIdx = -1;
|
|
679
|
-
for (let i = comps.length - 1; i >= 0; i--) {
|
|
680
|
-
if (!isNode(comps[i], 'Combinator')) {
|
|
681
|
-
tailIdx = i;
|
|
682
|
-
break;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
if (tailIdx < 0) {
|
|
686
|
-
return alt;
|
|
687
|
-
}
|
|
688
|
-
const tail = comps[tailIdx];
|
|
689
|
-
// The tail is at the compound position — walk it as if it were a compound child
|
|
690
|
-
const tailCtx = {
|
|
691
|
-
isRoot: false,
|
|
692
|
-
parentType: 'CompoundSelector',
|
|
693
|
-
hasContentBefore: tailIdx > 0,
|
|
694
|
-
hasContentAfter: tailIdx < comps.length - 1
|
|
695
|
-
};
|
|
696
|
-
const extendedTail = walkNode(tail, spec, extendWith, partial, tailCtx);
|
|
697
|
-
if (extendedTail === tail) {
|
|
698
|
-
return alt;
|
|
699
|
-
}
|
|
700
|
-
// Reconstruct complex with modified tail, keeping prefix intact
|
|
701
|
-
const newComps = [...comps];
|
|
702
|
-
newComps[tailIdx] = extendedTail;
|
|
703
|
-
return ComplexSelector.create(newComps).inherit(alt);
|
|
704
|
-
}
|
|
705
|
-
// ─────────────────────────────────────────────────
|
|
706
|
-
// Helpers
|
|
707
|
-
// ─────────────────────────────────────────────────
|
|
708
|
-
function makeList(original, extendWith, partial = false) {
|
|
709
|
-
const a = original.clone(true);
|
|
710
|
-
a.addFlag(F_EXTENDED);
|
|
711
|
-
if (partial) {
|
|
712
|
-
a.addFlag(F_EXTEND_TARGET);
|
|
713
|
-
}
|
|
714
|
-
const extendItems = extractIsArgs(extendWith);
|
|
715
|
-
const items = [a];
|
|
716
|
-
for (const item of extendItems) {
|
|
717
|
-
const b = item.clone(true);
|
|
718
|
-
b.addFlag(F_EXTENDED);
|
|
719
|
-
items.push(b);
|
|
720
|
-
}
|
|
721
|
-
const processed = createProcessedSelector(items, true);
|
|
722
|
-
const processedArray = isArray(processed) ? processed : [processed];
|
|
723
|
-
return SelectorList.create(processedArray).inherit(original);
|
|
724
|
-
}
|
|
725
|
-
function extractIsArgs(selector) {
|
|
726
|
-
if (isNode(selector, 'PseudoSelector') && selector.value.name === ':is' && selector.value.arg) {
|
|
727
|
-
const arg = selector.value.arg;
|
|
728
|
-
if (isNode(arg, 'SelectorList')) {
|
|
729
|
-
return arg.value;
|
|
730
|
-
}
|
|
731
|
-
return [arg];
|
|
732
|
-
}
|
|
733
|
-
return [selector];
|
|
734
|
-
}
|
|
735
|
-
function wrapInIs(matched, extendWith) {
|
|
736
|
-
const a = matched.copy(true);
|
|
737
|
-
a.addFlag(F_EXTEND_TARGET);
|
|
738
|
-
const extendItems = extractIsArgs(extendWith);
|
|
739
|
-
const extendCopies = extendItems.map((item) => {
|
|
740
|
-
const c = item.copy(true);
|
|
741
|
-
c.addFlag(F_EXTENDED);
|
|
742
|
-
return c;
|
|
743
|
-
});
|
|
744
|
-
if (isNode(matched, 'PseudoSelector') && matched.value.name === ':is' && matched.value.arg) {
|
|
745
|
-
const existing = isNode(matched.value.arg, 'SelectorList')
|
|
746
|
-
? matched.value.arg.value
|
|
747
|
-
: [matched.value.arg];
|
|
748
|
-
const existingVals = new Set(existing.map(s => s.valueOf()));
|
|
749
|
-
const newItems = extendCopies.filter(c => !existingVals.has(c.valueOf()));
|
|
750
|
-
if (newItems.length === 0) {
|
|
751
|
-
return matched;
|
|
752
|
-
}
|
|
753
|
-
const merged = [...existing.map(s => s.copy(true)), ...newItems];
|
|
754
|
-
const list = SelectorList.create(merged);
|
|
755
|
-
const result = PseudoSelector.create({ name: ':is', arg: list }).inherit(matched);
|
|
756
|
-
result.generated = true;
|
|
757
|
-
return result;
|
|
758
|
-
}
|
|
759
|
-
const list = SelectorList.create([a, ...extendCopies]);
|
|
760
|
-
const result = PseudoSelector.create({ name: ':is', arg: list }).inherit(matched);
|
|
761
|
-
result.generated = true;
|
|
762
|
-
return result;
|
|
763
|
-
}
|
|
764
|
-
// ─────────────────────────────────────────────────
|
|
765
|
-
// Dry-run: would this extend change the selector?
|
|
766
|
-
// ─────────────────────────────────────────────────
|
|
767
|
-
export function wouldExtendChange(target, find, extendWith, partial) {
|
|
768
|
-
const spec = decomposeFind(find);
|
|
769
|
-
return wouldMatchNode(target, spec, extendWith, partial, ROOT_CTX);
|
|
770
|
-
}
|
|
771
|
-
function wouldMatchNode(node, spec, extendWith, partial, ctx) {
|
|
772
|
-
if (spec.original.valueOf() === extendWith.valueOf()) {
|
|
773
|
-
return false;
|
|
774
|
-
}
|
|
775
|
-
if (isWholeNodeMatch(node, spec)) {
|
|
776
|
-
if (!partial) {
|
|
777
|
-
if (ctx.parentType === 'CompoundSelector' || ctx.parentType === 'ComplexSelector') {
|
|
778
|
-
return false;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
return true;
|
|
782
|
-
}
|
|
783
|
-
if (isNode(node, 'SelectorList')) {
|
|
784
|
-
return node.value.some((item, i) => wouldMatchNode(item, spec, extendWith, partial, {
|
|
785
|
-
isRoot: false,
|
|
786
|
-
parentType: 'SelectorList',
|
|
787
|
-
hasContentBefore: i > 0,
|
|
788
|
-
hasContentAfter: i < node.value.length - 1
|
|
789
|
-
}));
|
|
790
|
-
}
|
|
791
|
-
if (isNode(node, 'ComplexSelector')) {
|
|
792
|
-
if (isMultiPosition(spec)) {
|
|
793
|
-
return wouldSubsequenceMatch(node, spec, partial);
|
|
794
|
-
}
|
|
795
|
-
return node.value.some((comp, i) => {
|
|
796
|
-
if (isNode(comp, 'Combinator')) {
|
|
797
|
-
return false;
|
|
798
|
-
}
|
|
799
|
-
return wouldMatchNode(comp, spec, extendWith, partial, {
|
|
800
|
-
isRoot: false,
|
|
801
|
-
parentType: 'ComplexSelector',
|
|
802
|
-
hasContentBefore: i > 0,
|
|
803
|
-
hasContentAfter: i < node.value.length - 1
|
|
804
|
-
});
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
if (isNode(node, 'CompoundSelector')) {
|
|
808
|
-
if (isMultiSimple(spec) && partial) {
|
|
809
|
-
return wouldSimplesMatch(node, spec);
|
|
810
|
-
}
|
|
811
|
-
return node.value.some((comp, i) => wouldMatchNode(comp, spec, extendWith, partial, {
|
|
812
|
-
isRoot: false,
|
|
813
|
-
parentType: 'CompoundSelector',
|
|
814
|
-
hasContentBefore: i > 0,
|
|
815
|
-
hasContentAfter: i < node.value.length - 1
|
|
816
|
-
}));
|
|
817
|
-
}
|
|
818
|
-
if (isNode(node, 'PseudoSelector') && node.value.arg && node.value.arg.isSelector) {
|
|
819
|
-
const pseudo = node;
|
|
820
|
-
if (!partial && (ctx.hasContentBefore || ctx.hasContentAfter)) {
|
|
821
|
-
return false;
|
|
822
|
-
}
|
|
823
|
-
// Tail-aware: when :is() is inside a compound, only the tail of
|
|
824
|
-
// complex alternatives is at the current position.
|
|
825
|
-
if (ctx.parentType === 'CompoundSelector') {
|
|
826
|
-
return wouldMatchPseudoTailAware(pseudo, spec, extendWith, partial);
|
|
827
|
-
}
|
|
828
|
-
return wouldMatchNode(pseudo.value.arg, spec, extendWith, partial, {
|
|
829
|
-
isRoot: false,
|
|
830
|
-
parentType: 'PseudoSelector',
|
|
831
|
-
hasContentBefore: false,
|
|
832
|
-
hasContentAfter: false
|
|
833
|
-
});
|
|
834
|
-
}
|
|
835
|
-
return false;
|
|
836
|
-
}
|
|
837
|
-
function wouldMatchPseudoTailAware(pseudo, spec, extendWith, partial) {
|
|
838
|
-
const arg = pseudo.value.arg;
|
|
839
|
-
const checkAlt = (alt) => {
|
|
840
|
-
if (!isNode(alt, 'ComplexSelector')) {
|
|
841
|
-
return wouldMatchNode(alt, spec, extendWith, partial, {
|
|
842
|
-
isRoot: false,
|
|
843
|
-
parentType: 'PseudoSelector',
|
|
844
|
-
hasContentBefore: false,
|
|
845
|
-
hasContentAfter: false
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
// Complex: only check the tail
|
|
849
|
-
const comps = alt.value;
|
|
850
|
-
for (let i = comps.length - 1; i >= 0; i--) {
|
|
851
|
-
if (!isNode(comps[i], 'Combinator')) {
|
|
852
|
-
return wouldMatchNode(comps[i], spec, extendWith, partial, {
|
|
853
|
-
isRoot: false,
|
|
854
|
-
parentType: 'CompoundSelector',
|
|
855
|
-
hasContentBefore: i > 0,
|
|
856
|
-
hasContentAfter: i < comps.length - 1
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
return false;
|
|
861
|
-
};
|
|
862
|
-
if (isNode(arg, 'SelectorList')) {
|
|
863
|
-
return arg.value.some((alt) => checkAlt(alt));
|
|
864
|
-
}
|
|
865
|
-
return checkAlt(arg);
|
|
866
|
-
}
|
|
867
|
-
function wouldSimplesMatch(target, spec) {
|
|
868
|
-
return consumeSimples(target.value, spec.positions[0]) !== null;
|
|
869
|
-
}
|
|
870
|
-
function wouldSubsequenceMatch(target, spec, partial) {
|
|
871
|
-
const start = findSubsequence(target.value, spec);
|
|
872
|
-
if (start < 0) {
|
|
873
|
-
return false;
|
|
874
|
-
}
|
|
875
|
-
if (!partial) {
|
|
876
|
-
const findLen = spec.positions.length + spec.combinators.length;
|
|
877
|
-
return start === 0 && findLen === target.value.length;
|
|
878
|
-
}
|
|
879
|
-
return true;
|
|
880
|
-
}
|
|
881
|
-
//# sourceMappingURL=extend-walk.js.map
|