{"version":3,"names":[],"mappings":"","sources":["himalaya.js"],"sourcesContent":["(function(f){if(typeof exports===\"object\"&&typeof module!==\"undefined\"){module.exports=f()}else if(typeof define===\"function\"&&define.amd){define([],f)}else{var g;if(typeof window!==\"undefined\"){g=window}else if(typeof global!==\"undefined\"){g=global}else if(typeof self!==\"undefined\"){g=self}else{g=this}g.himalaya = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o= 0 ? lookupIndex : len + lookupIndex;\n while (searchIndex < len) {\n var element = array[searchIndex++];\n if (element === searchElement) return true;\n if (isNaNElement && isRealNaN(element)) return true;\n }\n\n return false;\n}\n\n},{}],2:[function(require,module,exports){\n'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.splitHead = splitHead;\nexports.unquote = unquote;\nexports.format = format;\nexports.formatAttributes = formatAttributes;\nfunction splitHead(str, sep) {\n var idx = str.indexOf(sep);\n if (idx === -1) return [str];\n return [str.slice(0, idx), str.slice(idx + sep.length)];\n}\n\nfunction unquote(str) {\n var car = str.charAt(0);\n var end = str.length - 1;\n var isQuoteStart = car === '\"' || car === \"'\";\n if (isQuoteStart && car === str.charAt(end)) {\n return str.slice(1, end);\n }\n return str;\n}\n\nfunction format(nodes, options) {\n return nodes.map(function (node) {\n var type = node.type;\n var outputNode = type === 'element' ? {\n type: type,\n tagName: node.tagName.toLowerCase(),\n attributes: formatAttributes(node.attributes),\n children: format(node.children, options)\n } : { type: type, content: node.content };\n if (options.includePositions) {\n outputNode.position = node.position;\n }\n return outputNode;\n });\n}\n\nfunction formatAttributes(attributes) {\n return attributes.map(function (attribute) {\n var parts = splitHead(attribute.trim(), '=');\n var key = parts[0];\n var value = typeof parts[1] === 'string' ? unquote(parts[1]) : null;\n return { key: key, value: value };\n });\n}\n\n},{}],3:[function(require,module,exports){\n'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.parseDefaults = undefined;\nexports.parse = parse;\nexports.stringify = stringify;\n\nvar _lexer = require('./lexer');\n\nvar _lexer2 = _interopRequireDefault(_lexer);\n\nvar _parser = require('./parser');\n\nvar _parser2 = _interopRequireDefault(_parser);\n\nvar _format = require('./format');\n\nvar _stringify = require('./stringify');\n\nvar _tags = require('./tags');\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar parseDefaults = exports.parseDefaults = {\n voidTags: _tags.voidTags,\n closingTags: _tags.closingTags,\n childlessTags: _tags.childlessTags,\n closingTagAncestorBreakers: _tags.closingTagAncestorBreakers,\n includePositions: false\n};\n\nfunction parse(str) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : parseDefaults;\n\n var tokens = (0, _lexer2.default)(str, options);\n var nodes = (0, _parser2.default)(tokens, options);\n return (0, _format.format)(nodes, options);\n}\n\nfunction stringify(ast) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : parseDefaults;\n\n return (0, _stringify.toHTML)(ast, options);\n}\n\n},{\"./format\":2,\"./lexer\":4,\"./parser\":5,\"./stringify\":6,\"./tags\":7}],4:[function(require,module,exports){\n'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.feedPosition = feedPosition;\nexports.jumpPosition = jumpPosition;\nexports.makeInitialPosition = makeInitialPosition;\nexports.copyPosition = copyPosition;\nexports.default = lexer;\nexports.lex = lex;\nexports.findTextEnd = findTextEnd;\nexports.lexText = lexText;\nexports.lexComment = lexComment;\nexports.lexTag = lexTag;\nexports.isWhitespaceChar = isWhitespaceChar;\nexports.lexTagName = lexTagName;\nexports.lexTagAttributes = lexTagAttributes;\nexports.lexSkipTag = lexSkipTag;\n\nvar _compat = require('./compat');\n\nfunction feedPosition(position, str, len) {\n var start = position.index;\n var end = position.index = start + len;\n for (var i = start; i < end; i++) {\n var char = str.charAt(i);\n if (char === '\\n') {\n position.line++;\n position.column = 0;\n } else {\n position.column++;\n }\n }\n}\n\nfunction jumpPosition(position, str, end) {\n var len = end - position.index;\n return feedPosition(position, str, len);\n}\n\nfunction makeInitialPosition() {\n return {\n index: 0,\n column: 0,\n line: 0\n };\n}\n\nfunction copyPosition(position) {\n return {\n index: position.index,\n line: position.line,\n column: position.column\n };\n}\n\nfunction lexer(str, options) {\n var state = {\n str: str,\n options: options,\n position: makeInitialPosition(),\n tokens: []\n };\n lex(state);\n return state.tokens;\n}\n\nfunction lex(state) {\n var str = state.str,\n childlessTags = state.options.childlessTags;\n\n var len = str.length;\n while (state.position.index < len) {\n var start = state.position.index;\n lexText(state);\n if (state.position.index === start) {\n var isComment = (0, _compat.startsWith)(str, '!--', start + 1);\n if (isComment) {\n lexComment(state);\n } else {\n var tagName = lexTag(state);\n var safeTag = tagName.toLowerCase();\n if ((0, _compat.arrayIncludes)(childlessTags, safeTag)) {\n lexSkipTag(tagName, state);\n }\n }\n }\n }\n}\n\nvar alphanumeric = /[A-Za-z0-9]/;\nfunction findTextEnd(str, index) {\n while (true) {\n var textEnd = str.indexOf('<', index);\n if (textEnd === -1) {\n return textEnd;\n }\n var char = str.charAt(textEnd + 1);\n if (char === '/' || char === '!' || alphanumeric.test(char)) {\n return textEnd;\n }\n index = textEnd + 1;\n }\n}\n\nfunction lexText(state) {\n var type = 'text';\n var str = state.str,\n position = state.position;\n\n var textEnd = findTextEnd(str, position.index);\n if (textEnd === position.index) return;\n if (textEnd === -1) {\n textEnd = str.length;\n }\n\n var start = copyPosition(position);\n var content = str.slice(position.index, textEnd);\n jumpPosition(position, str, textEnd);\n var end = copyPosition(position);\n state.tokens.push({ type: type, content: content, position: { start: start, end: end } });\n}\n\nfunction lexComment(state) {\n var str = state.str,\n position = state.position;\n\n var start = copyPosition(position);\n feedPosition(position, str, 4); // \"', position.index);\n var commentEnd = contentEnd + 3; // \"-->\".length\n if (contentEnd === -1) {\n contentEnd = commentEnd = str.length;\n }\n\n var content = str.slice(position.index, contentEnd);\n jumpPosition(position, str, commentEnd);\n state.tokens.push({\n type: 'comment',\n content: content,\n position: {\n start: start,\n end: copyPosition(position)\n }\n });\n}\n\nfunction lexTag(state) {\n var str = state.str,\n position = state.position;\n\n {\n var secondChar = str.charAt(position.index + 1);\n var close = secondChar === '/';\n var start = copyPosition(position);\n feedPosition(position, str, close ? 2 : 1);\n state.tokens.push({ type: 'tag-start', close: close, position: { start: start } });\n }\n var tagName = lexTagName(state);\n lexTagAttributes(state);\n {\n var firstChar = str.charAt(position.index);\n var _close = firstChar === '/';\n feedPosition(position, str, _close ? 2 : 1);\n var end = copyPosition(position);\n state.tokens.push({ type: 'tag-end', close: _close, position: { end: end } });\n }\n return tagName;\n}\n\n// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-white-space\nvar whitespace = /\\s/;\nfunction isWhitespaceChar(char) {\n return whitespace.test(char);\n}\n\nfunction lexTagName(state) {\n var str = state.str,\n position = state.position;\n\n var len = str.length;\n var start = position.index;\n while (start < len) {\n var char = str.charAt(start);\n var isTagChar = !(isWhitespaceChar(char) || char === '/' || char === '>');\n if (isTagChar) break;\n start++;\n }\n\n var end = start + 1;\n while (end < len) {\n var _char = str.charAt(end);\n var _isTagChar = !(isWhitespaceChar(_char) || _char === '/' || _char === '>');\n if (!_isTagChar) break;\n end++;\n }\n\n jumpPosition(position, str, end);\n var tagName = str.slice(start, end);\n state.tokens.push({\n type: 'tag',\n content: tagName\n });\n return tagName;\n}\n\nfunction lexTagAttributes(state) {\n var str = state.str,\n position = state.position,\n tokens = state.tokens;\n\n var cursor = position.index;\n var quote = null; // null, single-, or double-quote\n var wordBegin = cursor; // index of word start\n var words = []; // \"key\", \"key=value\", \"key='value'\", etc\n var len = str.length;\n while (cursor < len) {\n var char = str.charAt(cursor);\n if (quote) {\n var isQuoteEnd = char === quote;\n if (isQuoteEnd) {\n quote = null;\n }\n cursor++;\n continue;\n }\n\n var isTagEnd = char === '/' || char === '>';\n if (isTagEnd) {\n if (cursor !== wordBegin) {\n words.push(str.slice(wordBegin, cursor));\n }\n break;\n }\n\n var isWordEnd = isWhitespaceChar(char);\n if (isWordEnd) {\n if (cursor !== wordBegin) {\n words.push(str.slice(wordBegin, cursor));\n }\n wordBegin = cursor + 1;\n cursor++;\n continue;\n }\n\n var isQuoteStart = char === '\\'' || char === '\"';\n if (isQuoteStart) {\n quote = char;\n cursor++;\n continue;\n }\n\n cursor++;\n }\n jumpPosition(position, str, cursor);\n\n var wLen = words.length;\n var type = 'attribute';\n for (var i = 0; i < wLen; i++) {\n var word = words[i];\n var isNotPair = word.indexOf('=') === -1;\n if (isNotPair) {\n var secondWord = words[i + 1];\n if (secondWord && (0, _compat.startsWith)(secondWord, '=')) {\n if (secondWord.length > 1) {\n var newWord = word + secondWord;\n tokens.push({ type: type, content: newWord });\n i += 1;\n continue;\n }\n var thirdWord = words[i + 2];\n i += 1;\n if (thirdWord) {\n var _newWord = word + '=' + thirdWord;\n tokens.push({ type: type, content: _newWord });\n i += 1;\n continue;\n }\n }\n }\n if ((0, _compat.endsWith)(word, '=')) {\n var _secondWord = words[i + 1];\n if (_secondWord && !(0, _compat.stringIncludes)(_secondWord, '=')) {\n var _newWord3 = word + _secondWord;\n tokens.push({ type: type, content: _newWord3 });\n i += 1;\n continue;\n }\n\n var _newWord2 = word.slice(0, -1);\n tokens.push({ type: type, content: _newWord2 });\n continue;\n }\n\n tokens.push({ type: type, content: word });\n }\n}\n\nvar push = [].push;\n\nfunction lexSkipTag(tagName, state) {\n var str = state.str,\n position = state.position,\n tokens = state.tokens;\n\n var safeTagName = tagName.toLowerCase();\n var len = str.length;\n var index = position.index;\n while (index < len) {\n var nextTag = str.indexOf('= 0) {\n var parentTagName = stack[currentIndex].tagName;\n if (parentTagName === tagName) {\n break;\n }\n if ((0, _compat.arrayIncludes)(tagParents, parentTagName)) {\n return true;\n }\n currentIndex--;\n }\n }\n return false;\n}\n\nfunction rewindStack(stack, newLength, childrenEndPosition, endPosition) {\n stack[newLength].position.end = endPosition;\n for (var i = newLength + 1, len = stack.length; i < len; i++) {\n stack[i].position.end = childrenEndPosition;\n }\n stack.splice(newLength);\n}\n\nfunction parse(state) {\n var tokens = state.tokens,\n options = state.options;\n var stack = state.stack;\n\n var nodes = stack[stack.length - 1].children;\n var len = tokens.length;\n var cursor = state.cursor;\n\n while (cursor < len) {\n var token = tokens[cursor];\n if (token.type !== 'tag-start') {\n nodes.push(token);\n cursor++;\n continue;\n }\n\n var tagToken = tokens[++cursor];\n cursor++;\n var tagName = tagToken.content.toLowerCase();\n if (token.close) {\n var index = stack.length;\n var shouldRewind = false;\n while (--index > -1) {\n if (stack[index].tagName === tagName) {\n shouldRewind = true;\n break;\n }\n }\n while (cursor < len) {\n var endToken = tokens[cursor];\n if (endToken.type !== 'tag-end') break;\n cursor++;\n }\n if (shouldRewind) {\n rewindStack(stack, index, token.position.start, tokens[cursor - 1].position.end);\n break;\n } else {\n continue;\n }\n }\n\n var isClosingTag = (0, _compat.arrayIncludes)(options.closingTags, tagName);\n var shouldRewindToAutoClose = isClosingTag;\n if (shouldRewindToAutoClose) {\n var terminals = options.closingTagAncestorBreakers;\n\n shouldRewindToAutoClose = !hasTerminalParent(tagName, stack, terminals);\n }\n\n if (shouldRewindToAutoClose) {\n // rewind the stack to just above the previous\n // closing tag of the same name\n var currentIndex = stack.length - 1;\n while (currentIndex > 0) {\n if (tagName === stack[currentIndex].tagName) {\n rewindStack(stack, currentIndex, token.position.start, token.position.start);\n var previousIndex = currentIndex - 1;\n nodes = stack[previousIndex].children;\n break;\n }\n currentIndex = currentIndex - 1;\n }\n }\n\n var attributes = [];\n var attrToken = void 0;\n while (cursor < len) {\n attrToken = tokens[cursor];\n if (attrToken.type === 'tag-end') break;\n attributes.push(attrToken.content);\n cursor++;\n }\n\n cursor++;\n var children = [];\n var position = {\n start: token.position.start,\n end: attrToken.position.end\n };\n var elementNode = {\n type: 'element',\n tagName: tagToken.content,\n attributes: attributes,\n children: children,\n position: position\n };\n nodes.push(elementNode);\n\n var hasChildren = !(attrToken.close || (0, _compat.arrayIncludes)(options.voidTags, tagName));\n if (hasChildren) {\n var size = stack.push({ tagName: tagName, children: children, position: position });\n var innerState = { tokens: tokens, options: options, cursor: cursor, stack: stack };\n parse(innerState);\n cursor = innerState.cursor;\n var rewoundInElement = stack.length === size;\n if (rewoundInElement) {\n elementNode.position.end = tokens[cursor - 1].position.end;\n }\n }\n }\n state.cursor = cursor;\n}\n\n},{\"./compat\":1}],6:[function(require,module,exports){\n'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.formatAttributes = formatAttributes;\nexports.toHTML = toHTML;\n\nvar _compat = require('./compat');\n\nfunction formatAttributes(attributes) {\n return attributes.reduce(function (attrs, attribute) {\n var key = attribute.key,\n value = attribute.value;\n\n if (value === null) {\n return attrs + ' ' + key;\n }\n var quoteEscape = value.indexOf('\\'') !== -1;\n var quote = quoteEscape ? '\"' : '\\'';\n return attrs + ' ' + key + '=' + quote + value + quote;\n }, '');\n}\n\nfunction toHTML(tree, options) {\n return tree.map(function (node) {\n if (node.type === 'text') {\n return node.content;\n }\n if (node.type === 'comment') {\n return '';\n }\n var tagName = node.tagName,\n attributes = node.attributes,\n children = node.children;\n\n var isSelfClosing = (0, _compat.arrayIncludes)(options.voidTags, tagName.toLowerCase());\n return isSelfClosing ? '<' + tagName + formatAttributes(attributes) + '>' : '<' + tagName + formatAttributes(attributes) + '>' + toHTML(children, options) + '';\n }).join('');\n}\n\nexports.default = { toHTML: toHTML };\n\n},{\"./compat\":1}],7:[function(require,module,exports){\n'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n/*\n Tags which contain arbitary non-parsed content\n For example: