source: imaps-frontend/node_modules/css-select/lib/index.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 6.7 KB
RevLine 
[79a0317]1"use strict";
2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 if (k2 === undefined) k2 = k;
4 var desc = Object.getOwnPropertyDescriptor(m, k);
5 if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6 desc = { enumerable: true, get: function() { return m[k]; } };
7 }
8 Object.defineProperty(o, k2, desc);
9}) : (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 o[k2] = m[k];
12}));
13var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14 Object.defineProperty(o, "default", { enumerable: true, value: v });
15}) : function(o, v) {
16 o["default"] = v;
17});
18var __importStar = (this && this.__importStar) || function (mod) {
19 if (mod && mod.__esModule) return mod;
20 var result = {};
21 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22 __setModuleDefault(result, mod);
23 return result;
24};
25Object.defineProperty(exports, "__esModule", { value: true });
26exports.aliases = exports.pseudos = exports.filters = exports.is = exports.selectOne = exports.selectAll = exports.prepareContext = exports._compileToken = exports._compileUnsafe = exports.compile = void 0;
27var DomUtils = __importStar(require("domutils"));
28var boolbase_1 = require("boolbase");
29var compile_1 = require("./compile");
30var subselects_1 = require("./pseudo-selectors/subselects");
31var defaultEquals = function (a, b) { return a === b; };
32var defaultOptions = {
33 adapter: DomUtils,
34 equals: defaultEquals,
35};
36function convertOptionFormats(options) {
37 var _a, _b, _c, _d;
38 /*
39 * We force one format of options to the other one.
40 */
41 // @ts-expect-error Default options may have incompatible `Node` / `ElementNode`.
42 var opts = options !== null && options !== void 0 ? options : defaultOptions;
43 // @ts-expect-error Same as above.
44 (_a = opts.adapter) !== null && _a !== void 0 ? _a : (opts.adapter = DomUtils);
45 // @ts-expect-error `equals` does not exist on `Options`
46 (_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);
47 return opts;
48}
49function wrapCompile(func) {
50 return function addAdapter(selector, options, context) {
51 var opts = convertOptionFormats(options);
52 return func(selector, opts, context);
53 };
54}
55/**
56 * Compiles the query, returns a function.
57 */
58exports.compile = wrapCompile(compile_1.compile);
59exports._compileUnsafe = wrapCompile(compile_1.compileUnsafe);
60exports._compileToken = wrapCompile(compile_1.compileToken);
61function getSelectorFunc(searchFunc) {
62 return function select(query, elements, options) {
63 var opts = convertOptionFormats(options);
64 if (typeof query !== "function") {
65 query = (0, compile_1.compileUnsafe)(query, opts, elements);
66 }
67 var filteredElements = prepareContext(elements, opts.adapter, query.shouldTestNextSiblings);
68 return searchFunc(query, filteredElements, opts);
69 };
70}
71function prepareContext(elems, adapter, shouldTestNextSiblings) {
72 if (shouldTestNextSiblings === void 0) { shouldTestNextSiblings = false; }
73 /*
74 * Add siblings if the query requires them.
75 * See https://github.com/fb55/css-select/pull/43#issuecomment-225414692
76 */
77 if (shouldTestNextSiblings) {
78 elems = appendNextSiblings(elems, adapter);
79 }
80 return Array.isArray(elems)
81 ? adapter.removeSubsets(elems)
82 : adapter.getChildren(elems);
83}
84exports.prepareContext = prepareContext;
85function appendNextSiblings(elem, adapter) {
86 // Order matters because jQuery seems to check the children before the siblings
87 var elems = Array.isArray(elem) ? elem.slice(0) : [elem];
88 var elemsLength = elems.length;
89 for (var i = 0; i < elemsLength; i++) {
90 var nextSiblings = (0, subselects_1.getNextSiblings)(elems[i], adapter);
91 elems.push.apply(elems, nextSiblings);
92 }
93 return elems;
94}
95/**
96 * @template Node The generic Node type for the DOM adapter being used.
97 * @template ElementNode The Node type for elements for the DOM adapter being used.
98 * @param elems Elements to query. If it is an element, its children will be queried..
99 * @param query can be either a CSS selector string or a compiled query function.
100 * @param [options] options for querying the document.
101 * @see compile for supported selector queries.
102 * @returns All matching elements.
103 *
104 */
105exports.selectAll = getSelectorFunc(function (query, elems, options) {
106 return query === boolbase_1.falseFunc || !elems || elems.length === 0
107 ? []
108 : options.adapter.findAll(query, elems);
109});
110/**
111 * @template Node The generic Node type for the DOM adapter being used.
112 * @template ElementNode The Node type for elements for the DOM adapter being used.
113 * @param elems Elements to query. If it is an element, its children will be queried..
114 * @param query can be either a CSS selector string or a compiled query function.
115 * @param [options] options for querying the document.
116 * @see compile for supported selector queries.
117 * @returns the first match, or null if there was no match.
118 */
119exports.selectOne = getSelectorFunc(function (query, elems, options) {
120 return query === boolbase_1.falseFunc || !elems || elems.length === 0
121 ? null
122 : options.adapter.findOne(query, elems);
123});
124/**
125 * Tests whether or not an element is matched by query.
126 *
127 * @template Node The generic Node type for the DOM adapter being used.
128 * @template ElementNode The Node type for elements for the DOM adapter being used.
129 * @param elem The element to test if it matches the query.
130 * @param query can be either a CSS selector string or a compiled query function.
131 * @param [options] options for querying the document.
132 * @see compile for supported selector queries.
133 * @returns
134 */
135function is(elem, query, options) {
136 var opts = convertOptionFormats(options);
137 return (typeof query === "function" ? query : (0, compile_1.compile)(query, opts))(elem);
138}
139exports.is = is;
140/**
141 * Alias for selectAll(query, elems, options).
142 * @see [compile] for supported selector queries.
143 */
144exports.default = exports.selectAll;
145// Export filters, pseudos and aliases to allow users to supply their own.
146var pseudo_selectors_1 = require("./pseudo-selectors");
147Object.defineProperty(exports, "filters", { enumerable: true, get: function () { return pseudo_selectors_1.filters; } });
148Object.defineProperty(exports, "pseudos", { enumerable: true, get: function () { return pseudo_selectors_1.pseudos; } });
149Object.defineProperty(exports, "aliases", { enumerable: true, get: function () { return pseudo_selectors_1.aliases; } });
Note: See TracBrowser for help on using the repository browser.