1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11 | }) : function(o, v) {
|
12 | o["default"] = v;
|
13 | });
|
14 | var __importStar = (this && this.__importStar) || function (mod) {
|
15 | if (mod && mod.__esModule) return mod;
|
16 | var result = {};
|
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18 | __setModuleDefault(result, mod);
|
19 | return result;
|
20 | };
|
21 | Object.defineProperty(exports, "__esModule", { value: true });
|
22 | exports.aliases = exports.pseudos = exports.filters = exports.is = exports.selectOne = exports.selectAll = exports.prepareContext = exports._compileToken = exports._compileUnsafe = exports.compile = void 0;
|
23 | var DomUtils = __importStar(require("domutils"));
|
24 | var boolbase_1 = require("boolbase");
|
25 | var compile_1 = require("./compile");
|
26 | var subselects_1 = require("./pseudo-selectors/subselects");
|
27 | var defaultEquals = function (a, b) { return a === b; };
|
28 | var defaultOptions = {
|
29 | adapter: DomUtils,
|
30 | equals: defaultEquals,
|
31 | };
|
32 | function convertOptionFormats(options) {
|
33 | var _a, _b, _c, _d;
|
34 | |
35 |
|
36 |
|
37 |
|
38 | var opts = options !== null && options !== void 0 ? options : defaultOptions;
|
39 |
|
40 | (_a = opts.adapter) !== null && _a !== void 0 ? _a : (opts.adapter = DomUtils);
|
41 |
|
42 | (_b = opts.equals) !== null && _b !== void 0 ? _b : (opts.equals = (_d = (_c = opts.adapter) === null || _c === void 0 ? void 0 : _c.equals) !== null && _d !== void 0 ? _d : defaultEquals);
|
43 | return opts;
|
44 | }
|
45 | function wrapCompile(func) {
|
46 | return function addAdapter(selector, options, context) {
|
47 | var opts = convertOptionFormats(options);
|
48 | return func(selector, opts, context);
|
49 | };
|
50 | }
|
51 |
|
52 |
|
53 |
|
54 | exports.compile = wrapCompile(compile_1.compile);
|
55 | exports._compileUnsafe = wrapCompile(compile_1.compileUnsafe);
|
56 | exports._compileToken = wrapCompile(compile_1.compileToken);
|
57 | function getSelectorFunc(searchFunc) {
|
58 | return function select(query, elements, options) {
|
59 | var opts = convertOptionFormats(options);
|
60 | if (typeof query !== "function") {
|
61 | query = (0, compile_1.compileUnsafe)(query, opts, elements);
|
62 | }
|
63 | var filteredElements = prepareContext(elements, opts.adapter, query.shouldTestNextSiblings);
|
64 | return searchFunc(query, filteredElements, opts);
|
65 | };
|
66 | }
|
67 | function prepareContext(elems, adapter, shouldTestNextSiblings) {
|
68 | if (shouldTestNextSiblings === void 0) { shouldTestNextSiblings = false; }
|
69 | |
70 |
|
71 |
|
72 |
|
73 | if (shouldTestNextSiblings) {
|
74 | elems = appendNextSiblings(elems, adapter);
|
75 | }
|
76 | return Array.isArray(elems)
|
77 | ? adapter.removeSubsets(elems)
|
78 | : adapter.getChildren(elems);
|
79 | }
|
80 | exports.prepareContext = prepareContext;
|
81 | function appendNextSiblings(elem, adapter) {
|
82 |
|
83 | var elems = Array.isArray(elem) ? elem.slice(0) : [elem];
|
84 | for (var i = 0; i < elems.length; i++) {
|
85 | var nextSiblings = (0, subselects_1.getNextSiblings)(elems[i], adapter);
|
86 | elems.push.apply(elems, nextSiblings);
|
87 | }
|
88 | return elems;
|
89 | }
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | exports.selectAll = getSelectorFunc(function (query, elems, options) {
|
101 | return query === boolbase_1.falseFunc || !elems || elems.length === 0
|
102 | ? []
|
103 | : options.adapter.findAll(query, elems);
|
104 | });
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | exports.selectOne = getSelectorFunc(function (query, elems, options) {
|
115 | return query === boolbase_1.falseFunc || !elems || elems.length === 0
|
116 | ? null
|
117 | : options.adapter.findOne(query, elems);
|
118 | });
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | function is(elem, query, options) {
|
131 | var opts = convertOptionFormats(options);
|
132 | return (typeof query === "function" ? query : (0, compile_1.compile)(query, opts))(elem);
|
133 | }
|
134 | exports.is = is;
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | exports.default = exports.selectAll;
|
140 |
|
141 | var pseudo_selectors_1 = require("./pseudo-selectors");
|
142 | Object.defineProperty(exports, "filters", { enumerable: true, get: function () { return pseudo_selectors_1.filters; } });
|
143 | Object.defineProperty(exports, "pseudos", { enumerable: true, get: function () { return pseudo_selectors_1.pseudos; } });
|
144 | Object.defineProperty(exports, "aliases", { enumerable: true, get: function () { return pseudo_selectors_1.aliases; } });
|