{“ast”:null,“code”:“'use strict';nnObject.defineProperty(exports, "__esModule", {n value: truen});nnvar _extends = Object.assign || function (target) {n for (var i = 1; i < arguments.length; i++) {n var source = arguments;nn for (var key in source) {n if (Object.prototype.hasOwnProperty.call(source, key)) {n target = source;n }n }n }nn return target;n};nnexports = createSimmer;nnvar _queryEngine = require('./queryEngine');nnvar _queryEngine2 = _interopRequireDefault(_queryEngine);nnvar _methods = require('./methods');nnvar _methods2 = _interopRequireDefault(_methods);nnvar _validateSelector = require('./validateSelector');nnvar _validateSelector2 = _interopRequireDefault(_validateSelector);nnvar _convertSelectorStateIntoCSSSelector = require('./convertSelectorStateIntoCSSSelector');nnvar _convertSelectorStateIntoCSSSelector2 = _interopRequireDefault(_convertSelectorStateIntoCSSSelector);nnvar _parser = require('./parser');nnvar _parser2 = _interopRequireDefault(_parser);nnvar _stackHierarchy = require('./stackHierarchy');nnvar _stackHierarchy2 = _interopRequireDefault(_stackHierarchy);nnvar _configuration = require('./configuration');nnfunction _interopRequireDefault(obj) {n return obj && obj.__esModule ? obj : {n "default": objn };n}nnfunction createSimmer() {n var windowScope = arguments.length > 0 && arguments !== undefined ? arguments : window;n var customConfig = arguments.length > 1 && arguments !== undefined ? arguments : {};n var customQuery = arguments.length > 2 && arguments !== undefined ? arguments : false;n var config = (0, _configuration.configure)(customConfig);n var query = customQuery || (0, _queryEngine2)(windowScope, config.queryEnginen /**n * Handle errors in accordance with what is specified in the configurationn * @param {object/string} ex. The exception object or messagen * @param {object} element. The element Simmer was asked to processn */n );nn function onError(ex, element) {n // handle errorn if (config.errorHandling === true) {n throw ex;n }nn if (typeof config.errorHandling === 'function') {n config.errorHandling(ex, element);n }n } // Initialize the Simmer object and set it over the reference on the windownn /**n * The main Simmer action - parses an element on the page to produce a CSS selector for it.n * This function will be returned into the global Simmer object.n * @param {object} element. A DOM element you wish to create a selector for.n * @examplen <pre>\n var cssSelectorForDonJulio = Simmer(document.getElementByID('DonJulio'));\n </pre>
n */nnn var simmer = function simmer(element) {n if (!element) {n // handle errorn onError.call(simmer, new Error('Simmer: No element was specified for parsing.'), element);n return false;n } // The parser cycles through a set of parsing methods specified in an order optimaln // for creating as specific as possible a selectornnn var parser = new _parser2(_methods2); // get the element's ancestorsnn var hierarchy = (0, _stackHierarchy2)((0, _queryEngine.wrap)(element), config.depth // initialize the state of the selectorn );n var selectorState = {n // the stack is used to build a layer of selectors, each layer coresponding to a specific element in the heirarchyn // for each level we create a private stack of properties, so that we can then merge themn // comfortably and allow all methods to see the level at which existing properties have been setn stack: Array(hierarchy.length).fill().map(function () {n return [];n }),n // follow the current specificity level of the selector - the higher the bettern specificity: 0n };n var validator = (0, _validateSelector2)(element, config, query, onError // cycle through the available parsing methods and while we still have yet to find the requested element's one-to-one selectorn // we keep calling the methods until we are either satisfied or run out of methodsn );nn while (!parser.finished() && !selectorState.verified) {n try {n selectorState = parser.next(hierarchy, selectorState, validator, config, query // if we have reached a satisfactory level of specificity, try the selector, perhaps we have found our selector?n );nn if (selectorState.specificity >= config.specificityThreshold && !selectorState.verified) {n selectorState.verified = validator(selectorState);n }n } catch (ex) {n // handle errorn onError.call(simmer, ex, element);n }n } // if we were not able to produce a one-to-one selector, return falsennn if (selectorState.verified === undefined || selectorState.specificity < config.specificityThreshold) {n // if it is undefined then verfication has never been run!n // try and verify, and if verification fails - return falsen // if it is false and the specificity is too low to actually try and find the element in the first place, then we may simply have not runn // an up to date verification - try againn selectorState.verified = validator(selectorState);n }nn if (!selectorState.verified) {n return false;n }nn if (selectorState.verificationDepth) {n return (0, _convertSelectorStateIntoCSSSelector2)(selectorState, selectorState.verificationDepth);n }nn return (0, _convertSelectorStateIntoCSSSelector2)(selectorState);n };n /**n * Get/Set the configuration for the Simmer objectn * @param config (Object
) A configuration object with any of the properties tweeked (none/depth/minimumSpecificity)n * @examplen <pre>\n configuration({\n depth: 3\n });\n </pre>
n */nnn simmer.configure = function () {n var configValues = arguments.length > 0 && arguments !== undefined ? arguments : {};n var scope = arguments.length > 1 && arguments !== undefined ? arguments : windowScope;n var newConfig = (0, _configuration.configure)(_extends({}, config, configValues));n return createSimmer(scope, newConfig, (0, _queryEngine2)(scope, newConfig.queryEngine));n };nn return simmer;n}”,“map”:null,“metadata”:{},“sourceType”:“module”}