@blackglory/match 0.3.3
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/CHANGELOG.md +62 -0
- package/LICENSE +21 -0
- package/README.md +273 -0
- package/dist/es2015/index.min.mjs +2 -0
- package/dist/es2015/index.min.mjs.map +1 -0
- package/dist/es2015/index.mjs +3918 -0
- package/dist/es2015/index.mjs.map +1 -0
- package/dist/es2015/index.umd.js +3944 -0
- package/dist/es2015/index.umd.js.map +1 -0
- package/dist/es2015/index.umd.min.js +2 -0
- package/dist/es2015/index.umd.min.js.map +1 -0
- package/dist/es2018/index.min.mjs +2 -0
- package/dist/es2018/index.min.mjs.map +1 -0
- package/dist/es2018/index.mjs +3926 -0
- package/dist/es2018/index.mjs.map +1 -0
- package/dist/es2018/index.umd.js +3952 -0
- package/dist/es2018/index.umd.js.map +1 -0
- package/dist/es2018/index.umd.min.js +2 -0
- package/dist/es2018/index.umd.min.js.map +1 -0
- package/lib/es2015/index.d.ts +17 -0
- package/lib/es2015/index.js +38 -0
- package/lib/es2015/index.js.map +1 -0
- package/lib/es2015/match-element.d.ts +4 -0
- package/lib/es2015/match-element.js +22 -0
- package/lib/es2015/match-element.js.map +1 -0
- package/lib/es2015/match.d.ts +4 -0
- package/lib/es2015/match.js +22 -0
- package/lib/es2015/match.js.map +1 -0
- package/lib/es2015/matchers/any-of.d.ts +6 -0
- package/lib/es2015/matchers/any-of.js +10 -0
- package/lib/es2015/matchers/any-of.js.map +1 -0
- package/lib/es2015/matchers/child-nodes.d.ts +2 -0
- package/lib/es2015/matchers/child-nodes.js +23 -0
- package/lib/es2015/matchers/child-nodes.js.map +1 -0
- package/lib/es2015/matchers/children.d.ts +2 -0
- package/lib/es2015/matchers/children.js +23 -0
- package/lib/es2015/matchers/children.js.map +1 -0
- package/lib/es2015/matchers/css.d.ts +3 -0
- package/lib/es2015/matchers/css.js +18 -0
- package/lib/es2015/matchers/css.js.map +1 -0
- package/lib/es2015/matchers/element.d.ts +4 -0
- package/lib/es2015/matchers/element.js +34 -0
- package/lib/es2015/matchers/element.js.map +1 -0
- package/lib/es2015/matchers/multiple.d.ts +10 -0
- package/lib/es2015/matchers/multiple.js +42 -0
- package/lib/es2015/matchers/multiple.js.map +1 -0
- package/lib/es2015/matchers/node.d.ts +4 -0
- package/lib/es2015/matchers/node.js +31 -0
- package/lib/es2015/matchers/node.js.map +1 -0
- package/lib/es2015/matchers/optional.d.ts +2 -0
- package/lib/es2015/matchers/optional.js +9 -0
- package/lib/es2015/matchers/optional.js.map +1 -0
- package/lib/es2015/matchers/repeat.d.ts +2 -0
- package/lib/es2015/matchers/repeat.js +20 -0
- package/lib/es2015/matchers/repeat.js.map +1 -0
- package/lib/es2015/matchers/tap.d.ts +2 -0
- package/lib/es2015/matchers/tap.js +12 -0
- package/lib/es2015/matchers/tap.js.map +1 -0
- package/lib/es2015/matchers/text-content-equals.d.ts +7 -0
- package/lib/es2015/matchers/text-content-equals.js +20 -0
- package/lib/es2015/matchers/text-content-equals.js.map +1 -0
- package/lib/es2015/matchers/text-content-includes.d.ts +7 -0
- package/lib/es2015/matchers/text-content-includes.js +20 -0
- package/lib/es2015/matchers/text-content-includes.js.map +1 -0
- package/lib/es2015/matchers/text-content-matches.d.ts +6 -0
- package/lib/es2015/matchers/text-content-matches.js +16 -0
- package/lib/es2015/matchers/text-content-matches.js.map +1 -0
- package/lib/es2015/matchers/text-node.d.ts +4 -0
- package/lib/es2015/matchers/text-node.js +34 -0
- package/lib/es2015/matchers/text-node.js.map +1 -0
- package/lib/es2015/matchers/xpath.d.ts +3 -0
- package/lib/es2015/matchers/xpath.js +34 -0
- package/lib/es2015/matchers/xpath.js.map +1 -0
- package/lib/es2015/types.d.ts +18 -0
- package/lib/es2015/types.js +3 -0
- package/lib/es2015/types.js.map +1 -0
- package/lib/es2015/utils/concat.d.ts +1 -0
- package/lib/es2015/utils/concat.js +14 -0
- package/lib/es2015/utils/concat.js.map +1 -0
- package/lib/es2015/utils/match-multiple.d.ts +2 -0
- package/lib/es2015/utils/match-multiple.js +21 -0
- package/lib/es2015/utils/match-multiple.js.map +1 -0
- package/lib/es2015/utils/match-one-by-one.d.ts +2 -0
- package/lib/es2015/utils/match-one-by-one.js +38 -0
- package/lib/es2015/utils/match-one-by-one.js.map +1 -0
- package/lib/es2015/utils/merge.d.ts +5 -0
- package/lib/es2015/utils/merge.js +30 -0
- package/lib/es2015/utils/merge.js.map +1 -0
- package/lib/es2015/utils/next-element-sibling.d.ts +1 -0
- package/lib/es2015/utils/next-element-sibling.js +11 -0
- package/lib/es2015/utils/next-element-sibling.js.map +1 -0
- package/lib/es2015/utils/next-sibling.d.ts +1 -0
- package/lib/es2015/utils/next-sibling.js +11 -0
- package/lib/es2015/utils/next-sibling.js.map +1 -0
- package/lib/es2018/index.d.ts +17 -0
- package/lib/es2018/index.js +38 -0
- package/lib/es2018/index.js.map +1 -0
- package/lib/es2018/match-element.d.ts +4 -0
- package/lib/es2018/match-element.js +22 -0
- package/lib/es2018/match-element.js.map +1 -0
- package/lib/es2018/match.d.ts +4 -0
- package/lib/es2018/match.js +22 -0
- package/lib/es2018/match.js.map +1 -0
- package/lib/es2018/matchers/any-of.d.ts +6 -0
- package/lib/es2018/matchers/any-of.js +10 -0
- package/lib/es2018/matchers/any-of.js.map +1 -0
- package/lib/es2018/matchers/child-nodes.d.ts +2 -0
- package/lib/es2018/matchers/child-nodes.js +27 -0
- package/lib/es2018/matchers/child-nodes.js.map +1 -0
- package/lib/es2018/matchers/children.d.ts +2 -0
- package/lib/es2018/matchers/children.js +27 -0
- package/lib/es2018/matchers/children.js.map +1 -0
- package/lib/es2018/matchers/css.d.ts +3 -0
- package/lib/es2018/matchers/css.js +18 -0
- package/lib/es2018/matchers/css.js.map +1 -0
- package/lib/es2018/matchers/element.d.ts +4 -0
- package/lib/es2018/matchers/element.js +34 -0
- package/lib/es2018/matchers/element.js.map +1 -0
- package/lib/es2018/matchers/multiple.d.ts +10 -0
- package/lib/es2018/matchers/multiple.js +42 -0
- package/lib/es2018/matchers/multiple.js.map +1 -0
- package/lib/es2018/matchers/node.d.ts +4 -0
- package/lib/es2018/matchers/node.js +31 -0
- package/lib/es2018/matchers/node.js.map +1 -0
- package/lib/es2018/matchers/optional.d.ts +2 -0
- package/lib/es2018/matchers/optional.js +9 -0
- package/lib/es2018/matchers/optional.js.map +1 -0
- package/lib/es2018/matchers/repeat.d.ts +2 -0
- package/lib/es2018/matchers/repeat.js +20 -0
- package/lib/es2018/matchers/repeat.js.map +1 -0
- package/lib/es2018/matchers/tap.d.ts +2 -0
- package/lib/es2018/matchers/tap.js +12 -0
- package/lib/es2018/matchers/tap.js.map +1 -0
- package/lib/es2018/matchers/text-content-equals.d.ts +7 -0
- package/lib/es2018/matchers/text-content-equals.js +20 -0
- package/lib/es2018/matchers/text-content-equals.js.map +1 -0
- package/lib/es2018/matchers/text-content-includes.d.ts +7 -0
- package/lib/es2018/matchers/text-content-includes.js +20 -0
- package/lib/es2018/matchers/text-content-includes.js.map +1 -0
- package/lib/es2018/matchers/text-content-matches.d.ts +6 -0
- package/lib/es2018/matchers/text-content-matches.js +16 -0
- package/lib/es2018/matchers/text-content-matches.js.map +1 -0
- package/lib/es2018/matchers/text-node.d.ts +4 -0
- package/lib/es2018/matchers/text-node.js +34 -0
- package/lib/es2018/matchers/text-node.js.map +1 -0
- package/lib/es2018/matchers/xpath.d.ts +3 -0
- package/lib/es2018/matchers/xpath.js +34 -0
- package/lib/es2018/matchers/xpath.js.map +1 -0
- package/lib/es2018/types.d.ts +18 -0
- package/lib/es2018/types.js +3 -0
- package/lib/es2018/types.js.map +1 -0
- package/lib/es2018/utils/concat.d.ts +1 -0
- package/lib/es2018/utils/concat.js +14 -0
- package/lib/es2018/utils/concat.js.map +1 -0
- package/lib/es2018/utils/match-multiple.d.ts +2 -0
- package/lib/es2018/utils/match-multiple.js +21 -0
- package/lib/es2018/utils/match-multiple.js.map +1 -0
- package/lib/es2018/utils/match-one-by-one.d.ts +2 -0
- package/lib/es2018/utils/match-one-by-one.js +38 -0
- package/lib/es2018/utils/match-one-by-one.js.map +1 -0
- package/lib/es2018/utils/merge.d.ts +5 -0
- package/lib/es2018/utils/merge.js +30 -0
- package/lib/es2018/utils/merge.js.map +1 -0
- package/lib/es2018/utils/next-element-sibling.d.ts +1 -0
- package/lib/es2018/utils/next-element-sibling.js +11 -0
- package/lib/es2018/utils/next-element-sibling.js.map +1 -0
- package/lib/es2018/utils/next-sibling.d.ts +1 -0
- package/lib/es2018/utils/next-sibling.js +11 -0
- package/lib/es2018/utils/next-sibling.js.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.xpath = void 0;
|
|
4
|
+
const types_1 = require("@blackglory/types");
|
|
5
|
+
const concat_1 = require("../utils/concat");
|
|
6
|
+
const errors_1 = require("@blackglory/errors");
|
|
7
|
+
const UNORDERED_NODE_ITERATOR_TYPE = 'XPathResult' in globalThis
|
|
8
|
+
? XPathResult.UNORDERED_NODE_ITERATOR_TYPE
|
|
9
|
+
: 4;
|
|
10
|
+
function xpath(...args) {
|
|
11
|
+
if ((0, types_1.isString)(args[0])) {
|
|
12
|
+
const [expression] = args;
|
|
13
|
+
(0, errors_1.assert)(expression.startsWith('//*'), 'XPath expressions must start with "//*"');
|
|
14
|
+
return function (node) {
|
|
15
|
+
return xpathMatches(this.document, expression, node);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const [strings, ...values] = args;
|
|
20
|
+
const expression = (0, concat_1.concat)(strings, values).join('');
|
|
21
|
+
return xpath(expression);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.xpath = xpath;
|
|
25
|
+
function xpathMatches(document, expression, node) {
|
|
26
|
+
const iterator = document.evaluate(expression, node, null, UNORDERED_NODE_ITERATOR_TYPE, null);
|
|
27
|
+
let value;
|
|
28
|
+
while ((value = iterator.iterateNext()) !== null) {
|
|
29
|
+
if (value === node)
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=xpath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xpath.js","sourceRoot":"","sources":["../../../src/matchers/xpath.ts"],"names":[],"mappings":";;;AACA,6CAA4C;AAC5C,0CAAsC;AACtC,+CAA2C;AAE3C,MAAM,4BAA4B,GAChC,aAAa,IAAI,UAAU;IAC3B,CAAC,CAAC,WAAW,CAAC,4BAA4B;IAC1C,CAAC,CAAC,CAAC,CAAA;AASL,SAAgB,KAAK,CAAC,GAAG,IAE6B;IAEpD,IAAI,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;QACrB,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,CAAA;QACzB,IAAA,eAAM,EAAC,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,yCAAyC,CAAC,CAAA;QAE/E,OAAO,UAEL,IAAU;YAEV,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,CAAC,CAAA;QACtD,CAAC,CAAA;KACF;SAAM;QACL,MAAM,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,GAAG,IAAI,CAAA;QACjC,MAAM,UAAU,GAAG,IAAA,eAAM,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAEnD,OAAO,KAAK,CAAC,UAAU,CAAC,CAAA;KACzB;AACH,CAAC;AApBD,sBAoBC;AAED,SAAS,YAAY,CAAC,QAAkB,EAAE,UAAkB,EAAE,IAAU;IACtE,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAChC,UAAU,EACV,IAAI,EACJ,IAAI,EACJ,4BAA4B,EAC5B,IAAI,CACL,CAAA;IAED,IAAI,KAAK,CAAA;IACT,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC,KAAK,IAAI,EAAE;QAChD,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAA;KAChC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface IContext {
|
|
2
|
+
readonly document: Document;
|
|
3
|
+
readonly next: (node: Node, distance?: number) => Node | undefined;
|
|
4
|
+
readonly collection: {
|
|
5
|
+
[name: string]: Node | Node[];
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export interface IReadonlyContext {
|
|
9
|
+
readonly document: Document;
|
|
10
|
+
readonly next: (node: Node, distance?: number) => Node | undefined;
|
|
11
|
+
readonly collection: {
|
|
12
|
+
readonly [name: string]: Node | Node[];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare type IMatcher<T extends Node> = ITerminalMatcher<T> | INestedMatcher<T> | ISkipMatcher<T> | (<T extends Node>(this: IReadonlyContext, node: T) => boolean | number | Iterable<number>);
|
|
16
|
+
export declare type INestedMatcher<T extends Node> = (this: IReadonlyContext, node: T) => boolean;
|
|
17
|
+
export declare type ISkipMatcher<T extends Node> = (this: IReadonlyContext, node: T) => number | Iterable<number> | false;
|
|
18
|
+
export declare type ITerminalMatcher<T extends Node> = (this: IReadonlyContext, node: T) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function concat(strings: TemplateStringsArray, values: string[]): string[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.concat = void 0;
|
|
4
|
+
function concat(strings, values) {
|
|
5
|
+
const result = [];
|
|
6
|
+
for (let i = 0, len = values.length; i < len; i++) {
|
|
7
|
+
result.push(strings[i]);
|
|
8
|
+
result.push(values[i]);
|
|
9
|
+
}
|
|
10
|
+
result.push(strings[strings.length - 1]);
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
exports.concat = concat;
|
|
14
|
+
//# sourceMappingURL=concat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concat.js","sourceRoot":"","sources":["../../../src/utils/concat.ts"],"names":[],"mappings":";;;AAAA,SAAgB,MAAM,CAAC,OAA6B,EAAE,MAAgB;IACpE,MAAM,MAAM,GAAG,EAAE,CAAA;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;QACjD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;QACvB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;KACvB;IACD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAA;IACxC,OAAO,MAAM,CAAA;AACf,CAAC;AARD,wBAQC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchMultiple = void 0;
|
|
4
|
+
const extra_generator_1 = require("extra-generator");
|
|
5
|
+
function matchMultiple(node, ubound, matcher) {
|
|
6
|
+
let currentNode = node;
|
|
7
|
+
for (const round of (0, extra_generator_1.countup)(1, ubound)) {
|
|
8
|
+
if (!currentNode)
|
|
9
|
+
return round - 1;
|
|
10
|
+
const result = matcher.call(this, currentNode);
|
|
11
|
+
if (result) {
|
|
12
|
+
currentNode = this.next(currentNode);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return round - 1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return ubound;
|
|
19
|
+
}
|
|
20
|
+
exports.matchMultiple = matchMultiple;
|
|
21
|
+
//# sourceMappingURL=match-multiple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-multiple.js","sourceRoot":"","sources":["../../../src/utils/match-multiple.ts"],"names":[],"mappings":";;;AAAA,qDAAyC;AAMzC,SAAgB,aAAa,CAE3B,IAAO,EACP,MAAc,EACd,OAAgD;IAEhD,IAAI,WAAW,GAAa,IAAI,CAAA;IAEhC,KAAK,MAAM,KAAK,IAAI,IAAA,yBAAO,EAAC,CAAC,EAAE,MAAM,CAAC,EAAE;QACtC,IAAI,CAAC,WAAW;YAAE,OAAO,KAAK,GAAG,CAAC,CAAA;QAElC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;QAC9C,IAAI,MAAM,EAAE;YACV,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAa,CAAA;SACjD;aAAM;YACL,OAAO,KAAK,GAAG,CAAC,CAAA;SACjB;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AApBD,sCAoBC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchOneByOne = void 0;
|
|
4
|
+
const types_1 = require("@blackglory/types");
|
|
5
|
+
function matchOneByOne(context, source, ...matchers) {
|
|
6
|
+
if (matchers.length === 0)
|
|
7
|
+
return true;
|
|
8
|
+
if (!source)
|
|
9
|
+
return false;
|
|
10
|
+
const [matcher, ...otherMatchers] = matchers;
|
|
11
|
+
const result = Reflect.apply(matcher, context, [source]);
|
|
12
|
+
if ((0, types_1.isBoolean)(result)) {
|
|
13
|
+
if (result) {
|
|
14
|
+
const nextNode = context.next(source);
|
|
15
|
+
return matchOneByOne(context, nextNode, ...otherMatchers);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if ((0, types_1.isNumber)(result)) {
|
|
22
|
+
const distance = result;
|
|
23
|
+
const nextNode = context.next(source, distance);
|
|
24
|
+
return matchOneByOne(context, nextNode, ...otherMatchers);
|
|
25
|
+
}
|
|
26
|
+
if ((0, types_1.isIterable)(result)) {
|
|
27
|
+
for (const distance of result) {
|
|
28
|
+
const nextNode = context.next(source, distance);
|
|
29
|
+
if (matchOneByOne(context, nextNode, ...otherMatchers)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
throw new Error('Unknown return value');
|
|
36
|
+
}
|
|
37
|
+
exports.matchOneByOne = matchOneByOne;
|
|
38
|
+
//# sourceMappingURL=match-one-by-one.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-one-by-one.js","sourceRoot":"","sources":["../../../src/utils/match-one-by-one.ts"],"names":[],"mappings":";;;AACA,6CAAmE;AAEnE,SAAgB,aAAa,CAC3B,OAAyB,EACzB,MAAgB,EAChB,GAAG,QAA4B;IAE/B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACtC,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IAEzB,MAAM,CAAC,OAAO,EAAE,GAAG,aAAa,CAAC,GAAG,QAAQ,CAAA;IAE5C,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,CAA+B,CAAA;IAGtF,IAAI,IAAA,iBAAS,EAAC,MAAM,CAAC,EAAE;QACrB,IAAI,MAAM,EAAE;YACV,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAa,CAAA;YACjD,OAAO,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC,CAAA;SAC1D;aAAM;YACL,OAAO,KAAK,CAAA;SACb;KACF;IAGD,IAAI,IAAA,gBAAQ,EAAC,MAAM,CAAC,EAAE;QACpB,MAAM,QAAQ,GAAG,MAAM,CAAA;QACvB,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAa,CAAA;QAC3D,OAAO,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC,CAAA;KAC1D;IAGD,IAAI,IAAA,kBAAU,EAAC,MAAM,CAAC,EAAE;QACtB,KAAK,MAAM,QAAQ,IAAI,MAAM,EAAE;YAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAa,CAAA;YAC3D,IAAI,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC,EAAE;gBACtD,OAAO,IAAI,CAAA;aACZ;SACF;QAGD,OAAO,KAAK,CAAA;KACb;IAED,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;AACzC,CAAC;AA3CD,sCA2CC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.merge = void 0;
|
|
4
|
+
function merge(target, source) {
|
|
5
|
+
for (const [key, value] of Object.entries(source)) {
|
|
6
|
+
if (target[key]) {
|
|
7
|
+
if (Array.isArray(target[key])) {
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
target[key] = [...target[key], ...value];
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
target[key] = [...target[key], value];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
target[key] = [target[key], ...value];
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
target[key] = [target[key], value];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
target[key] = value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.merge = merge;
|
|
30
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../../src/utils/merge.ts"],"names":[],"mappings":";;;AAAA,SAAgB,KAAK,CACnB,MAAkC,EAClC,MAAkC;IAElC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE;YACf,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;gBAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;oBACxB,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAQ,EAAE,GAAG,KAAK,CAAC,CAAA;iBAChD;qBAAM;oBACL,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAQ,EAAE,KAAK,CAAC,CAAA;iBAC7C;aACF;iBAAM;gBACL,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;oBACxB,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAM,EAAE,GAAG,KAAK,CAAC,CAAA;iBAC3C;qBAAM;oBACL,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAM,EAAE,KAAK,CAAC,CAAA;iBACxC;aACF;SACF;aAAM;YACL,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;SACpB;KACF;AACH,CAAC;AAvBD,sBAuBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function nextElementSibling(node: Node, distance?: number): Node | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nextElementSibling = void 0;
|
|
4
|
+
const ExtraDOM = require("extra-dom");
|
|
5
|
+
function nextElementSibling(node, distance = 1) {
|
|
6
|
+
if (distance === 0)
|
|
7
|
+
return node;
|
|
8
|
+
return ExtraDOM.nextElementSibling(node, distance);
|
|
9
|
+
}
|
|
10
|
+
exports.nextElementSibling = nextElementSibling;
|
|
11
|
+
//# sourceMappingURL=next-element-sibling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-element-sibling.js","sourceRoot":"","sources":["../../../src/utils/next-element-sibling.ts"],"names":[],"mappings":";;;AAAA,sCAAqC;AAErC,SAAgB,kBAAkB,CAChC,IAAU,EACV,WAAmB,CAAC;IAEpB,IAAI,QAAQ,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAE/B,OAAO,QAAQ,CAAC,kBAAkB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AACpD,CAAC;AAPD,gDAOC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function nextSibling(node: Node, distance?: number): Node | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nextSibling = void 0;
|
|
4
|
+
const ExtraDOM = require("extra-dom");
|
|
5
|
+
function nextSibling(node, distance = 1) {
|
|
6
|
+
if (distance === 0)
|
|
7
|
+
return node;
|
|
8
|
+
return ExtraDOM.nextSibling(node, distance);
|
|
9
|
+
}
|
|
10
|
+
exports.nextSibling = nextSibling;
|
|
11
|
+
//# sourceMappingURL=next-sibling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-sibling.js","sourceRoot":"","sources":["../../../src/utils/next-sibling.ts"],"names":[],"mappings":";;;AAAA,sCAAqC;AAErC,SAAgB,WAAW,CAAC,IAAU,EAAE,WAAmB,CAAC;IAC1D,IAAI,QAAQ,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAE/B,OAAO,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AAC7C,CAAC;AAJD,kCAIC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { match } from './match';
|
|
2
|
+
export { matchElement } from './match-element';
|
|
3
|
+
export { anyOf } from './matchers/any-of';
|
|
4
|
+
export { childNodes } from './matchers/child-nodes';
|
|
5
|
+
export { children } from './matchers/children';
|
|
6
|
+
export { css } from './matchers/css';
|
|
7
|
+
export { element } from './matchers/element';
|
|
8
|
+
export { multiple } from './matchers/multiple';
|
|
9
|
+
export { node } from './matchers/node';
|
|
10
|
+
export { optional } from './matchers/optional';
|
|
11
|
+
export { repeat } from './matchers/repeat';
|
|
12
|
+
export { tap } from './matchers/tap';
|
|
13
|
+
export { textContentEquals } from './matchers/text-content-equals';
|
|
14
|
+
export { textContentIncludes } from './matchers/text-content-includes';
|
|
15
|
+
export { textContentMatches } from './matchers/text-content-matches';
|
|
16
|
+
export { textNode } from './matchers/text-node';
|
|
17
|
+
export { xpath } from './matchers/xpath';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.xpath = exports.textNode = exports.textContentMatches = exports.textContentIncludes = exports.textContentEquals = exports.tap = exports.repeat = exports.optional = exports.node = exports.multiple = exports.element = exports.css = exports.children = exports.childNodes = exports.anyOf = exports.matchElement = exports.match = void 0;
|
|
4
|
+
var match_1 = require("./match");
|
|
5
|
+
Object.defineProperty(exports, "match", { enumerable: true, get: function () { return match_1.match; } });
|
|
6
|
+
var match_element_1 = require("./match-element");
|
|
7
|
+
Object.defineProperty(exports, "matchElement", { enumerable: true, get: function () { return match_element_1.matchElement; } });
|
|
8
|
+
var any_of_1 = require("./matchers/any-of");
|
|
9
|
+
Object.defineProperty(exports, "anyOf", { enumerable: true, get: function () { return any_of_1.anyOf; } });
|
|
10
|
+
var child_nodes_1 = require("./matchers/child-nodes");
|
|
11
|
+
Object.defineProperty(exports, "childNodes", { enumerable: true, get: function () { return child_nodes_1.childNodes; } });
|
|
12
|
+
var children_1 = require("./matchers/children");
|
|
13
|
+
Object.defineProperty(exports, "children", { enumerable: true, get: function () { return children_1.children; } });
|
|
14
|
+
var css_1 = require("./matchers/css");
|
|
15
|
+
Object.defineProperty(exports, "css", { enumerable: true, get: function () { return css_1.css; } });
|
|
16
|
+
var element_1 = require("./matchers/element");
|
|
17
|
+
Object.defineProperty(exports, "element", { enumerable: true, get: function () { return element_1.element; } });
|
|
18
|
+
var multiple_1 = require("./matchers/multiple");
|
|
19
|
+
Object.defineProperty(exports, "multiple", { enumerable: true, get: function () { return multiple_1.multiple; } });
|
|
20
|
+
var node_1 = require("./matchers/node");
|
|
21
|
+
Object.defineProperty(exports, "node", { enumerable: true, get: function () { return node_1.node; } });
|
|
22
|
+
var optional_1 = require("./matchers/optional");
|
|
23
|
+
Object.defineProperty(exports, "optional", { enumerable: true, get: function () { return optional_1.optional; } });
|
|
24
|
+
var repeat_1 = require("./matchers/repeat");
|
|
25
|
+
Object.defineProperty(exports, "repeat", { enumerable: true, get: function () { return repeat_1.repeat; } });
|
|
26
|
+
var tap_1 = require("./matchers/tap");
|
|
27
|
+
Object.defineProperty(exports, "tap", { enumerable: true, get: function () { return tap_1.tap; } });
|
|
28
|
+
var text_content_equals_1 = require("./matchers/text-content-equals");
|
|
29
|
+
Object.defineProperty(exports, "textContentEquals", { enumerable: true, get: function () { return text_content_equals_1.textContentEquals; } });
|
|
30
|
+
var text_content_includes_1 = require("./matchers/text-content-includes");
|
|
31
|
+
Object.defineProperty(exports, "textContentIncludes", { enumerable: true, get: function () { return text_content_includes_1.textContentIncludes; } });
|
|
32
|
+
var text_content_matches_1 = require("./matchers/text-content-matches");
|
|
33
|
+
Object.defineProperty(exports, "textContentMatches", { enumerable: true, get: function () { return text_content_matches_1.textContentMatches; } });
|
|
34
|
+
var text_node_1 = require("./matchers/text-node");
|
|
35
|
+
Object.defineProperty(exports, "textNode", { enumerable: true, get: function () { return text_node_1.textNode; } });
|
|
36
|
+
var xpath_1 = require("./matchers/xpath");
|
|
37
|
+
Object.defineProperty(exports, "xpath", { enumerable: true, get: function () { return xpath_1.xpath; } });
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAA+B;AAAtB,8FAAA,KAAK,OAAA;AACd,iDAA8C;AAArC,6GAAA,YAAY,OAAA;AAErB,2CAAwC;AAA/B,+FAAA,KAAK,OAAA;AACd,qDAAkD;AAAzC,yGAAA,UAAU,OAAA;AACnB,+CAA6C;AAApC,oGAAA,QAAQ,OAAA;AACjB,qCAAmC;AAA1B,0FAAA,GAAG,OAAA;AACZ,6CAA2C;AAAlC,kGAAA,OAAO,OAAA;AAChB,+CAA6C;AAApC,oGAAA,QAAQ,OAAA;AACjB,uCAAqC;AAA5B,4FAAA,IAAI,OAAA;AACb,+CAA6C;AAApC,oGAAA,QAAQ,OAAA;AACjB,2CAAyC;AAAhC,gGAAA,MAAM,OAAA;AACf,qCAAmC;AAA1B,0FAAA,GAAG,OAAA;AACZ,qEAAiE;AAAxD,wHAAA,iBAAiB,OAAA;AAC1B,yEAAqE;AAA5D,4HAAA,mBAAmB,OAAA;AAC5B,uEAAmE;AAA1D,0HAAA,kBAAkB,OAAA;AAC3B,iDAA8C;AAArC,qGAAA,QAAQ,OAAA;AACjB,yCAAuC;AAA9B,8FAAA,KAAK,OAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchElement = void 0;
|
|
4
|
+
const extra_dom_1 = require("extra-dom");
|
|
5
|
+
const match_one_by_one_1 = require("./utils/match-one-by-one");
|
|
6
|
+
const next_element_sibling_1 = require("./utils/next-element-sibling");
|
|
7
|
+
function matchElement(element, ...matchers) {
|
|
8
|
+
const document = (0, extra_dom_1.isDocument)(this) ? this : globalThis.document;
|
|
9
|
+
const context = {
|
|
10
|
+
document,
|
|
11
|
+
collection: {},
|
|
12
|
+
next: next_element_sibling_1.nextElementSibling
|
|
13
|
+
};
|
|
14
|
+
if ((0, match_one_by_one_1.matchOneByOne)(context, element, ...matchers)) {
|
|
15
|
+
return context.collection;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.matchElement = matchElement;
|
|
22
|
+
//# sourceMappingURL=match-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-element.js","sourceRoot":"","sources":["../../src/match-element.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAEtC,8DAAuD;AACvD,sEAAgE;AAEhE,SAAgB,YAAY,CAE1B,OAAgB,EAChB,GAAG,QAAkC;IAErC,MAAM,QAAQ,GAAG,IAAA,sBAAU,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAA;IAC9D,MAAM,OAAO,GAAa;QACxB,QAAQ;QACR,UAAU,EAAE,EAAE;QACd,IAAI,EAAE,yCAAkB;KACzB,CAAA;IAED,IAAI,IAAA,gCAAa,EAAC,OAAO,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,EAAE;QAChD,OAAO,OAAO,CAAC,UAAU,CAAA;KAC1B;SAAM;QACL,OAAO,IAAI,CAAA;KACZ;AACH,CAAC;AAjBD,oCAiBC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.match = void 0;
|
|
4
|
+
const extra_dom_1 = require("extra-dom");
|
|
5
|
+
const match_one_by_one_1 = require("./utils/match-one-by-one");
|
|
6
|
+
const next_sibling_1 = require("./utils/next-sibling");
|
|
7
|
+
function match(node, ...matchers) {
|
|
8
|
+
const document = (0, extra_dom_1.isDocument)(this) ? this : globalThis.document;
|
|
9
|
+
const context = {
|
|
10
|
+
document,
|
|
11
|
+
collection: {},
|
|
12
|
+
next: next_sibling_1.nextSibling
|
|
13
|
+
};
|
|
14
|
+
if ((0, match_one_by_one_1.matchOneByOne)(context, node, ...matchers)) {
|
|
15
|
+
return context.collection;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.match = match;
|
|
22
|
+
//# sourceMappingURL=match.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/match.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAEtC,8DAAuD;AACvD,sDAAiD;AAEjD,SAAgB,KAAK,CAEnB,IAAU,EACV,GAAG,QAA+B;IAElC,MAAM,QAAQ,GAAG,IAAA,sBAAU,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAA;IAC9D,MAAM,OAAO,GAAa;QACxB,QAAQ;QACR,UAAU,EAAE,EAAE;QACd,IAAI,EAAE,0BAAW;KAClB,CAAA;IAED,IAAI,IAAA,gCAAa,EAAC,OAAO,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,EAAE;QAC7C,OAAO,OAAO,CAAC,UAAU,CAAA;KAC1B;SAAM;QACL,OAAO,IAAI,CAAA;KACZ;AACH,CAAC;AAjBD,sBAiBC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ITerminalMatcher, INestedMatcher } from '../types';
|
|
2
|
+
export declare function anyOf<T extends Node>(...matchers: [
|
|
3
|
+
INestedMatcher<T> | ITerminalMatcher<T>,
|
|
4
|
+
INestedMatcher<T> | ITerminalMatcher<T>,
|
|
5
|
+
...Array<INestedMatcher<T> | ITerminalMatcher<T>>
|
|
6
|
+
]): INestedMatcher<T>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.anyOf = void 0;
|
|
4
|
+
function anyOf(...matchers) {
|
|
5
|
+
return function (node) {
|
|
6
|
+
return matchers.some(match => match.call(this, node));
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
exports.anyOf = anyOf;
|
|
10
|
+
//# sourceMappingURL=any-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"any-of.js","sourceRoot":"","sources":["../../../src/matchers/any-of.ts"],"names":[],"mappings":";;;AAEA,SAAgB,KAAK,CACnB,GAAG,QAIF;IAED,OAAO,UAAkC,IAAO;QAC9C,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IACvD,CAAC,CAAA;AACH,CAAC;AAVD,sBAUC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.childNodes = void 0;
|
|
4
|
+
const match_one_by_one_1 = require("../utils/match-one-by-one");
|
|
5
|
+
const merge_1 = require("../utils/merge");
|
|
6
|
+
const next_sibling_1 = require("../utils/next-sibling");
|
|
7
|
+
function childNodes(...matchers) {
|
|
8
|
+
return function (node) {
|
|
9
|
+
if (matchers.length === 0) {
|
|
10
|
+
return node.childNodes.length === 0;
|
|
11
|
+
}
|
|
12
|
+
if (node.childNodes.length === 0)
|
|
13
|
+
return false;
|
|
14
|
+
const context = {
|
|
15
|
+
...this,
|
|
16
|
+
collection: {},
|
|
17
|
+
next: next_sibling_1.nextSibling
|
|
18
|
+
};
|
|
19
|
+
const result = (0, match_one_by_one_1.matchOneByOne)(context, node.childNodes[0], ...matchers);
|
|
20
|
+
if (result) {
|
|
21
|
+
(0, merge_1.merge)(this.collection, context.collection);
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.childNodes = childNodes;
|
|
27
|
+
//# sourceMappingURL=child-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child-nodes.js","sourceRoot":"","sources":["../../../src/matchers/child-nodes.ts"],"names":[],"mappings":";;;AACA,8DAAuD;AACvD,wCAAoC;AACpC,sDAAiD;AAEjD,SAAgB,UAAU,CAAC,GAAG,QAA+B;IAC3D,OAAO,UAAkC,IAAU;QAEjD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAA;SACpC;QAED,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAA;QAE9C,MAAM,OAAO,GAAqB;YAChC,GAAG,IAAI;YACP,UAAU,EAAE,EAAE;YACd,IAAI,EAAE,0BAAW;SAClB,CAAA;QAED,MAAM,MAAM,GAAG,IAAA,gCAAa,EAC1B,OAAO,EACP,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAClB,GAAG,QAAQ,CACZ,CAAA;QAED,IAAI,MAAM,EAAE;YACV,IAAA,aAAK,EAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;SAC3C;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AA3BD,gCA2BC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.children = void 0;
|
|
4
|
+
const match_one_by_one_1 = require("../utils/match-one-by-one");
|
|
5
|
+
const merge_1 = require("../utils/merge");
|
|
6
|
+
const next_element_sibling_1 = require("../utils/next-element-sibling");
|
|
7
|
+
function children(...matchers) {
|
|
8
|
+
return function (element) {
|
|
9
|
+
if (matchers.length === 0) {
|
|
10
|
+
return element.children.length === 0;
|
|
11
|
+
}
|
|
12
|
+
if (element.children.length === 0)
|
|
13
|
+
return false;
|
|
14
|
+
const context = {
|
|
15
|
+
...this,
|
|
16
|
+
collection: {},
|
|
17
|
+
next: next_element_sibling_1.nextElementSibling
|
|
18
|
+
};
|
|
19
|
+
const result = (0, match_one_by_one_1.matchOneByOne)(context, element.children[0], ...matchers);
|
|
20
|
+
if (result) {
|
|
21
|
+
(0, merge_1.merge)(this.collection, context.collection);
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.children = children;
|
|
27
|
+
//# sourceMappingURL=children.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"children.js","sourceRoot":"","sources":["../../../src/matchers/children.ts"],"names":[],"mappings":";;;AACA,8DAAuD;AACvD,wCAAoC;AACpC,sEAAgE;AAEhE,SAAgB,QAAQ,CACtB,GAAG,QAAkC;IAErC,OAAO,UAAkC,OAAgB;QAEvD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAA;SACrC;QAED,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAA;QAE/C,MAAM,OAAO,GAAqB;YAChC,GAAG,IAAI;YACP,UAAU,EAAE,EAAE;YACd,IAAI,EAAE,yCAAkB;SACzB,CAAA;QAED,MAAM,MAAM,GAAG,IAAA,gCAAa,EAC1B,OAAO,EACP,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EACnB,GAAG,QAAQ,CACZ,CAAA;QAED,IAAI,MAAM,EAAE;YACV,IAAA,aAAK,EAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;SAC3C;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AA7BD,4BA6BC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.css = void 0;
|
|
4
|
+
const concat_1 = require("../utils/concat");
|
|
5
|
+
const types_1 = require("@blackglory/types");
|
|
6
|
+
function css(...args) {
|
|
7
|
+
if ((0, types_1.isString)(args[0])) {
|
|
8
|
+
const [selector] = args;
|
|
9
|
+
return (element) => element.matches(selector);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
const [strings, ...values] = args;
|
|
13
|
+
const selector = (0, concat_1.concat)(strings, values).join('');
|
|
14
|
+
return css(selector);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.css = css;
|
|
18
|
+
//# sourceMappingURL=css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.js","sourceRoot":"","sources":["../../../src/matchers/css.ts"],"names":[],"mappings":";;;AAAA,0CAAsC;AAEtC,6CAA4C;AAO5C,SAAgB,GAAG,CAAC,GAAG,IAE+B;IAEpD,IAAI,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;QACrB,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;QAEvB,OAAO,CAAC,OAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;KACvD;SAAM;QACL,MAAM,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,GAAG,IAAI,CAAA;QACjC,MAAM,QAAQ,GAAG,IAAA,eAAM,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAEjD,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAA;KACrB;AACH,CAAC;AAdD,kBAcC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { INestedMatcher, ITerminalMatcher } from '../types';
|
|
2
|
+
export declare function element(strings: TemplateStringsArray, ...values: string[]): (...matchers: Array<INestedMatcher<Element> | ITerminalMatcher<Element>>) => INestedMatcher<Node>;
|
|
3
|
+
export declare function element(name: string, ...matchers: Array<INestedMatcher<Element>>): INestedMatcher<Node>;
|
|
4
|
+
export declare function element(...matchers: Array<INestedMatcher<Element>>): INestedMatcher<Node>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.element = void 0;
|
|
4
|
+
const extra_dom_1 = require("extra-dom");
|
|
5
|
+
const types_1 = require("@blackglory/types");
|
|
6
|
+
const concat_1 = require("../utils/concat");
|
|
7
|
+
const merge_1 = require("../utils/merge");
|
|
8
|
+
function element(...args) {
|
|
9
|
+
if (Array.isArray(args[0])) {
|
|
10
|
+
const [strings, ...values] = args;
|
|
11
|
+
const name = (0, concat_1.concat)(strings, values).join('');
|
|
12
|
+
return (...matchers) => element(name, ...matchers);
|
|
13
|
+
}
|
|
14
|
+
if ((0, types_1.isString)(args[0])) {
|
|
15
|
+
const [name, ...matchers] = args;
|
|
16
|
+
return function (_element) {
|
|
17
|
+
const result = element(...matchers).call(this, _element);
|
|
18
|
+
if (result) {
|
|
19
|
+
(0, merge_1.merge)(this.collection, { [name]: _element });
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const [...matchers] = args;
|
|
25
|
+
return function (element) {
|
|
26
|
+
if ((0, extra_dom_1.isntElement)(element))
|
|
27
|
+
return false;
|
|
28
|
+
if (matchers.length === 0)
|
|
29
|
+
return true;
|
|
30
|
+
return matchers.every(match => match.call(this, element));
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.element = element;
|
|
34
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","sourceRoot":"","sources":["../../../src/matchers/element.ts"],"names":[],"mappings":";;;AAAA,yCAAuC;AAEvC,6CAA4C;AAC5C,0CAAsC;AACtC,wCAAoC;AAUpC,SAAgB,OAAO,CAAC,GAAG,IAGgD;IAEzE,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;QAC1B,MAAM,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,GACxB,IAA4D,CAAA;QAC9D,MAAM,IAAI,GAAG,IAAA,eAAM,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAE7C,OAAO,CAAC,GAAG,QAAoE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAA;KAC/G;IAED,IAAI,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;QACrB,MAAM,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,GACvB,IAA+F,CAAA;QAEjG,OAAO,UAAkC,QAAiB;YACxD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YACxD,IAAI,MAAM,EAAE;gBACV,IAAA,aAAK,EAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;aAC7C;YACD,OAAO,MAAM,CAAA;QACf,CAAC,CAAA;KACF;IAED,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,IAAiF,CAAA;IAEvG,OAAO,UAAkC,OAAgB;QACvD,IAAI,IAAA,uBAAW,EAAC,OAAO,CAAC;YAAE,OAAO,KAAK,CAAA;QACtC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAA;QAEtC,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAA;IAC3D,CAAC,CAAA;AACH,CAAC;AAlCD,0BAkCC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { INestedMatcher, ITerminalMatcher, ISkipMatcher } from '../types';
|
|
2
|
+
export declare enum Range {
|
|
3
|
+
Min = 0,
|
|
4
|
+
Max = 1
|
|
5
|
+
}
|
|
6
|
+
interface IMultipleOptions {
|
|
7
|
+
greedy: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function multiple<T extends Node>([min, max]: [min: number, max: number], matcher: INestedMatcher<T> | ITerminalMatcher<T>, options?: IMultipleOptions): ISkipMatcher<T>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.multiple = exports.Range = void 0;
|
|
4
|
+
const extra_generator_1 = require("extra-generator");
|
|
5
|
+
const errors_1 = require("@blackglory/errors");
|
|
6
|
+
const match_multiple_1 = require("../utils/match-multiple");
|
|
7
|
+
var Range;
|
|
8
|
+
(function (Range) {
|
|
9
|
+
Range[Range["Min"] = 0] = "Min";
|
|
10
|
+
Range[Range["Max"] = 1] = "Max";
|
|
11
|
+
})(Range = exports.Range || (exports.Range = {}));
|
|
12
|
+
function multiple([min, max], matcher, options = { greedy: true }) {
|
|
13
|
+
(0, errors_1.assert)(Number.isInteger(min), 'parameter min must be an integer');
|
|
14
|
+
(0, errors_1.assert)(Number.isInteger(max) || max === Infinity, 'parameter max must be an integer or Infinity');
|
|
15
|
+
(0, errors_1.assert)(min >= 0, 'parameter min must be greater than or equal to 0');
|
|
16
|
+
(0, errors_1.assert)(min <= max, 'parameter max must be greater than or equal to min');
|
|
17
|
+
return function* (node) {
|
|
18
|
+
if (options.greedy) {
|
|
19
|
+
let ubound = max;
|
|
20
|
+
while (true) {
|
|
21
|
+
const round = match_multiple_1.matchMultiple.call(this, node, ubound, matcher);
|
|
22
|
+
if (round < min)
|
|
23
|
+
break;
|
|
24
|
+
yield round;
|
|
25
|
+
ubound = round - 1;
|
|
26
|
+
if (ubound < min)
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
for (const ubound of (0, extra_generator_1.countup)(min, max)) {
|
|
32
|
+
const result = match_multiple_1.matchMultiple.call(this, node, ubound, matcher);
|
|
33
|
+
if (result < ubound)
|
|
34
|
+
break;
|
|
35
|
+
if (result === ubound)
|
|
36
|
+
yield ubound;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.multiple = multiple;
|
|
42
|
+
//# sourceMappingURL=multiple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiple.js","sourceRoot":"","sources":["../../../src/matchers/multiple.ts"],"names":[],"mappings":";;;AACA,qDAAyC;AACzC,+CAA2C;AAC3C,0DAAqD;AAErD,IAAY,KAGX;AAHD,WAAY,KAAK;IACf,+BAAO,CAAA;IACP,+BAAO,CAAA;AACT,CAAC,EAHW,KAAK,GAAL,aAAK,KAAL,aAAK,QAGhB;AAOD,SAAgB,QAAQ,CACtB,CAAC,GAAG,EAAE,GAAG,CAA6B,EACtC,OAAgD,EAChD,UAA4B,EAAE,MAAM,EAAE,IAAI,EAAE;IAE5C,IAAA,eAAM,EAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,kCAAkC,CAAC,CAAA;IACjE,IAAA,eAAM,EAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,QAAQ,EAAE,8CAA8C,CAAC,CAAA;IACjG,IAAA,eAAM,EAAC,GAAG,IAAI,CAAC,EAAE,kDAAkD,CAAC,CAAA;IACpE,IAAA,eAAM,EAAC,GAAG,IAAI,GAAG,EAAE,oDAAoD,CAAC,CAAA;IAExE,OAAO,QAAQ,CAAC,EAA0B,IAAO;QAC/C,IAAI,OAAO,CAAC,MAAM,EAAE;YAClB,IAAI,MAAM,GAAG,GAAG,CAAA;YAChB,OAAO,IAAI,EAAE;gBACX,MAAM,KAAK,GAAG,8BAAa,CAAC,IAAI,CAC9B,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,OAAwD,CACzD,CAAA;gBAED,IAAI,KAAK,GAAG,GAAG;oBAAE,MAAK;gBACtB,MAAM,KAAK,CAAA;gBAEX,MAAM,GAAG,KAAK,GAAG,CAAC,CAAA;gBAClB,IAAI,MAAM,GAAG,GAAG;oBAAE,MAAK;aACxB;SACF;aAAM;YACL,KAAK,MAAM,MAAM,IAAI,IAAA,yBAAO,EAAC,GAAG,EAAE,GAAG,CAAC,EAAE;gBACtC,MAAM,MAAM,GAAG,8BAAa,CAAC,IAAI,CAC/B,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,OAAsD,CACvD,CAAA;gBAGD,IAAI,MAAM,GAAG,MAAM;oBAAE,MAAK;gBAE1B,IAAI,MAAM,KAAK,MAAM;oBAAE,MAAM,MAAM,CAAA;aACpC;SACF;IACH,CAAC,CAAA;AACH,CAAC;AA3CD,4BA2CC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { INestedMatcher, ITerminalMatcher } from '../types';
|
|
2
|
+
export declare function node(strings: TemplateStringsArray, ...values: string[]): (...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>) => INestedMatcher<Node>;
|
|
3
|
+
export declare function node(name: string, ...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>): INestedMatcher<Node>;
|
|
4
|
+
export declare function node(...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>): INestedMatcher<Node>;
|