"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.getLoad = getLoad; const options_js_1 = require("./options.js"); const staticMethods = __importStar(require("./static.js")); const cheerio_js_1 = require("./cheerio.js"); const utils_js_1 = require("./utils.js"); const htmlparser2_1 = require("htmlparser2"); function getLoad(parse, render) { /** * Create a querying function, bound to a document created from the provided * markup. * * Note that similar to web browser contexts, this operation may introduce * `
`, ``, and `
` elements; set `isDocument` to `false` to * switch to fragment mode and disable this. * * @param content - Markup to be loaded. * @param options - Options for the created instance. * @param isDocument - Allows parser to be switched to fragment mode. * @returns The loaded document. * @see {@link https://cheerio.js.org/docs/basics/loading#load} for additional usage information. */ return function load(content, options, isDocument = true) { if (content == null) { throw new Error('cheerio.load() expects a string'); } const internalOpts = (0, options_js_1.flattenOptions)(options); const initialRoot = parse(content, internalOpts, isDocument, null); /** * Create an extended class here, so that extensions only live on one * instance. */ class LoadedCheerio extends cheerio_js_1.Cheerio { _make(selector, context) { const cheerio = initialize(selector, context); cheerio.prevObject = this; return cheerio; } _parse(content, options, isDocument, context) { return parse(content, options, isDocument, context); } _render(dom) { return render(dom, this.options); } } function initialize(selector, context, root = initialRoot, opts) { // $($) if (selector && (0, utils_js_1.isCheerio)(selector)) return selector; const options = (0, options_js_1.flattenOptions)(opts, internalOpts); const r = typeof root === 'string' ? [parse(root, options, false, null)] : 'length' in root ? root : [root]; const rootInstance = (0, utils_js_1.isCheerio)(r) ? r : new LoadedCheerio(r, null, options); // Add a cyclic reference, so that calling methods on `_root` never fails. rootInstance._root = rootInstance; // $(), $(null), $(unde