From a0a48ea84a84e03f83114ffd8374fa5458d1f1d4 Mon Sep 17 00:00:00 2001 From: imasustink Date: Wed, 1 Nov 2017 16:02:37 -0700 Subject: [PATCH] 3.6.3 --- dist/amd/can-view-parser.js | 354 ++++++++++++++++++ dist/global/can-view-parser.js | 659 +++++++++++++++++++++++++++++++++ 2 files changed, 1013 insertions(+) create mode 100644 dist/amd/can-view-parser.js create mode 100644 dist/global/can-view-parser.js diff --git a/dist/amd/can-view-parser.js b/dist/amd/can-view-parser.js new file mode 100644 index 0000000..26ce582 --- /dev/null +++ b/dist/amd/can-view-parser.js @@ -0,0 +1,354 @@ +/*can-view-parser@3.6.2#can-view-parser*/ +define([ + 'require', + 'exports', + 'module', + 'can-namespace', + 'can-log/dev', + 'can-attribute-encoder' +], function (require, exports, module) { + var namespace = require('can-namespace'), dev = require('can-log/dev'), encoder = require('can-attribute-encoder'); + function each(items, callback) { + for (var i = 0; i < items.length; i++) { + callback(items[i], i); + } + } + function makeMap(str) { + var obj = {}, items = str.split(','); + each(items, function (name) { + obj[name] = true; + }); + return obj; + } + function handleIntermediate(intermediate, handler) { + for (var i = 0, len = intermediate.length; i < len; i++) { + var item = intermediate[i]; + handler[item.tokenType].apply(handler, item.args); + } + return intermediate; + } + var alphaNumeric = 'A-Za-z0-9', alphaNumericHU = '-:_' + alphaNumeric, defaultMagicStart = '{{', endTag = new RegExp('^<\\/([' + alphaNumericHU + ']+)[^>]*>'), defaultMagicMatch = new RegExp('\\{\\{(![\\s\\S]*?!|[\\s\\S]*?)\\}\\}\\}?', 'g'), space = /\s/, alphaRegex = new RegExp('[' + alphaNumeric + ']'); + var empty = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'); + var caseMattersElements = makeMap('altGlyph,altGlyphDef,altGlyphItem,animateColor,animateMotion,animateTransform,clipPath,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,foreignObject,glyphRef,linearGradient,radialGradient,textPath'); + var closeSelf = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'); + var special = makeMap('script'); + var tokenTypes = 'start,end,close,attrStart,attrEnd,attrValue,chars,comment,special,done'.split(','); + var startOppositesMap = { + '{': '}', + '(': ')' + }; + var fn = function () { + }; + var HTMLParser = function (html, handler, returnIntermediate) { + if (typeof html === 'object') { + return handleIntermediate(html, handler); + } + var intermediate = []; + handler = handler || {}; + if (returnIntermediate) { + each(tokenTypes, function (name) { + var callback = handler[name] || fn; + handler[name] = function () { + if (callback.apply(this, arguments) !== false) { + var end = arguments.length; + if (arguments[end - 1] === undefined) { + end = arguments.length - 1; + } + intermediate.push({ + tokenType: name, + args: [].slice.call(arguments, 0, end) + }); + } + }; + }); + } + var magicMatch = handler.magicMatch || defaultMagicMatch, magicStart = handler.magicStart || defaultMagicStart; + function parseStartTag(tag, tagName, rest, unary) { + tagName = caseMattersElements[tagName] ? tagName : tagName.toLowerCase(); + if (closeSelf[tagName] && stack.last() === tagName) { + parseEndTag('', tagName); + } + unary = empty[tagName] || !!unary; + handler.start(tagName, unary, lineNo); + if (!unary) { + stack.push(tagName); + } + HTMLParser.parseAttrs(rest, handler, lineNo); + handler.end(tagName, unary, lineNo); + } + function parseEndTag(tag, tagName) { + var pos; + if (!tagName) { + pos = 0; + } else { + tagName = caseMattersElements[tagName] ? tagName : tagName.toLowerCase(); + for (pos = stack.length - 1; pos >= 0; pos--) { + if (stack[pos] === tagName) { + break; + } + } + } + if (pos >= 0) { + for (var i = stack.length - 1; i >= pos; i--) { + if (handler.close) { + handler.close(stack[i], lineNo); + } + } + stack.length = pos; + } + } + function parseMustache(mustache, inside) { + if (handler.special) { + handler.special(inside, lineNo); + } + } + var callChars = function () { + if (charsText) { + if (handler.chars) { + handler.chars(charsText, lineNo); + } + } + charsText = ''; + }; + var index, chars, match, lineNo, stack = [], last = html, charsText = ''; + stack.last = function () { + return this[this.length - 1]; + }; + while (html) { + chars = true; + if (!stack.last() || !special[stack.last()]) { + if (html.indexOf(''); + if (index >= 0) { + callChars(); + if (handler.comment) { + handler.comment(html.substring(4, index), lineNo); + } + html = html.substring(index + 3); + chars = false; + } + } else if (html.indexOf(']*>'), function (all, text) { + text = text.replace(/|/g, '$1$2'); + if (handler.chars) { + handler.chars(text, lineNo); + } + return ''; + }); + parseEndTag('', stack.last()); + } + if (html === last) { + throw new Error('Parse Error: ' + html); + } + last = html; + } + callChars(); + parseEndTag(); + handler.done(lineNo); + return intermediate; + }; + var callAttrStart = function (state, curIndex, handler, rest, lineNo) { + var attrName = rest.substring(typeof state.nameStart === 'number' ? state.nameStart : curIndex, curIndex), newAttrName = encoder.encode(attrName); + state.attrStart = newAttrName; + handler.attrStart(state.attrStart, lineNo); + state.inName = false; + }; + var callAttrEnd = function (state, curIndex, handler, rest, lineNo) { + if (state.valueStart !== undefined && state.valueStart < curIndex) { + var val = rest.substring(state.valueStart, curIndex); + handler.attrValue(val, lineNo); + } + handler.attrEnd(state.attrStart, lineNo); + state.attrStart = undefined; + state.valueStart = undefined; + state.inValue = false; + state.inName = false; + state.lookingForEq = false; + state.inQuote = false; + state.lookingForName = true; + }; + var findBreak = function (str, magicStart) { + var magicLength = magicStart.length; + for (var i = 0, len = str.length; i < len; i++) { + if (str[i] === '<' || str.substr(i, magicLength) === magicStart) { + return i; + } + } + return -1; + }; + HTMLParser.parseAttrs = function (rest, handler, lineNo) { + if (!rest) { + return; + } + var magicMatch = handler.magicMatch || defaultMagicMatch, magicStart = handler.magicStart || defaultMagicStart; + var i = 0; + var curIndex; + var state = { + inName: false, + nameStart: undefined, + inValue: false, + valueStart: undefined, + inQuote: false, + attrStart: undefined, + lookingForName: true, + lookingForValue: false, + lookingForEq: false + }; + while (i < rest.length) { + curIndex = i; + var cur = rest.charAt(i); + i++; + if (magicStart === rest.substr(curIndex, magicStart.length)) { + if (state.inValue && curIndex > state.valueStart) { + handler.attrValue(rest.substring(state.valueStart, curIndex), lineNo); + } else if (state.inName && state.nameStart < curIndex) { + callAttrStart(state, curIndex, handler, rest, lineNo); + callAttrEnd(state, curIndex, handler, rest, lineNo); + } else if (state.lookingForValue) { + state.inValue = true; + } else if (state.lookingForEq && state.attrStart) { + callAttrEnd(state, curIndex, handler, rest, lineNo); + } + magicMatch.lastIndex = curIndex; + var match = magicMatch.exec(rest); + if (match) { + handler.special(match[1], lineNo); + i = curIndex + match[0].length; + if (state.inValue) { + state.valueStart = curIndex + match[0].length; + } + } + } else if (state.inValue) { + if (state.inQuote) { + if (cur === state.inQuote) { + callAttrEnd(state, curIndex, handler, rest, lineNo); + } + } else if (space.test(cur)) { + callAttrEnd(state, curIndex, handler, rest, lineNo); + } + } else if (cur === '=' && (state.lookingForEq || state.lookingForName || state.inName)) { + if (!state.attrStart) { + callAttrStart(state, curIndex, handler, rest, lineNo); + } + state.lookingForValue = true; + state.lookingForEq = false; + state.lookingForName = false; + } else if (state.inName) { + var started = rest[state.nameStart], otherStart, otherOpposite; + if (startOppositesMap[started] === cur) { + otherStart = started === '{' ? '(' : '{'; + otherOpposite = startOppositesMap[otherStart]; + if (rest[curIndex + 1] === otherOpposite) { + callAttrStart(state, curIndex + 2, handler, rest, lineNo); + i++; + } else { + callAttrStart(state, curIndex + 1, handler, rest, lineNo); + } + state.lookingForEq = true; + } else if (space.test(cur) && started !== '{' && started !== '(') { + callAttrStart(state, curIndex, handler, rest, lineNo); + state.lookingForEq = true; + } + } else if (state.lookingForName) { + if (!space.test(cur)) { + if (state.attrStart) { + callAttrEnd(state, curIndex, handler, rest, lineNo); + } + state.nameStart = curIndex; + state.inName = true; + } + } else if (state.lookingForValue) { + if (!space.test(cur)) { + state.lookingForValue = false; + state.inValue = true; + if (cur === '\'' || cur === '"') { + state.inQuote = cur; + state.valueStart = curIndex + 1; + } else { + state.valueStart = curIndex; + } + } else if (i === rest.length) { + callAttrEnd(state, curIndex, handler, rest, lineNo); + } + } + } + if (state.inName) { + callAttrStart(state, curIndex + 1, handler, rest, lineNo); + callAttrEnd(state, curIndex + 1, handler, rest, lineNo); + } else if (state.lookingForEq || state.lookingForValue || state.inValue) { + callAttrEnd(state, curIndex + 1, handler, rest, lineNo); + } + magicMatch.lastIndex = 0; + }; + HTMLParser.searchStartTag = function (html) { + var closingIndex = html.indexOf('>'); + if (closingIndex === -1 || !alphaRegex.test(html[1])) { + return null; + } + var tagName, tagContent, match, rest = '', unary = ''; + var startTag = html.substring(0, closingIndex + 1); + var isUnary = startTag[startTag.length - 2] === '/'; + var spaceIndex = startTag.search(space); + if (isUnary) { + unary = '/'; + tagContent = startTag.substring(1, startTag.length - 2).trim(); + } else { + tagContent = startTag.substring(1, startTag.length - 1).trim(); + } + if (spaceIndex === -1) { + tagName = tagContent; + } else { + spaceIndex--; + tagName = tagContent.substring(0, spaceIndex); + rest = tagContent.substring(spaceIndex); + } + match = [ + startTag, + tagName, + rest, + unary + ]; + return { + match: match, + html: html.substring(startTag.length) + }; + }; + module.exports = namespace.HTMLParser = HTMLParser; +}); \ No newline at end of file diff --git a/dist/global/can-view-parser.js b/dist/global/can-view-parser.js new file mode 100644 index 0000000..f3d169d --- /dev/null +++ b/dist/global/can-view-parser.js @@ -0,0 +1,659 @@ +/*[global-shim-start]*/ +(function(exports, global, doEval) { + // jshint ignore:line + var origDefine = global.define; + + var get = function(name) { + var parts = name.split("."), + cur = global, + i; + for (i = 0; i < parts.length; i++) { + if (!cur) { + break; + } + cur = cur[parts[i]]; + } + return cur; + }; + var set = function(name, val) { + var parts = name.split("."), + cur = global, + i, + part, + next; + for (i = 0; i < parts.length - 1; i++) { + part = parts[i]; + next = cur[part]; + if (!next) { + next = cur[part] = {}; + } + cur = next; + } + part = parts[parts.length - 1]; + cur[part] = val; + }; + var useDefault = function(mod) { + if (!mod || !mod.__esModule) return false; + var esProps = { __esModule: true, default: true }; + for (var p in mod) { + if (!esProps[p]) return false; + } + return true; + }; + + var hasCjsDependencies = function(deps) { + return ( + deps[0] === "require" && deps[1] === "exports" && deps[2] === "module" + ); + }; + + var modules = + (global.define && global.define.modules) || + (global._define && global._define.modules) || + {}; + var ourDefine = (global.define = function(moduleName, deps, callback) { + var module; + if (typeof deps === "function") { + callback = deps; + deps = []; + } + var args = [], + i; + for (i = 0; i < deps.length; i++) { + args.push( + exports[deps[i]] + ? get(exports[deps[i]]) + : modules[deps[i]] || get(deps[i]) + ); + } + // CJS has no dependencies but 3 callback arguments + if (hasCjsDependencies(deps) || (!deps.length && callback.length)) { + module = { exports: {} }; + args[0] = function(name) { + return exports[name] ? get(exports[name]) : modules[name]; + }; + args[1] = module.exports; + args[2] = module; + } else if (!args[0] && deps[0] === "exports") { + // Babel uses the exports and module object. + module = { exports: {} }; + args[0] = module.exports; + if (deps[1] === "module") { + args[1] = module; + } + } else if (!args[0] && deps[0] === "module") { + args[0] = { id: moduleName }; + } + + global.define = origDefine; + var result = callback ? callback.apply(null, args) : undefined; + global.define = ourDefine; + + // Favor CJS module.exports over the return value + result = module && module.exports ? module.exports : result; + modules[moduleName] = result; + + // Set global exports + var globalExport = exports[moduleName]; + if (globalExport && !get(globalExport)) { + if (useDefault(result)) { + result = result["default"]; + } + set(globalExport, result); + } + }); + global.define.orig = origDefine; + global.define.modules = modules; + global.define.amd = true; + ourDefine("@loader", [], function() { + // shim for @@global-helpers + var noop = function() {}; + return { + get: function() { + return { prepareGlobal: noop, retrieveGlobal: noop }; + }, + global: global, + __exec: function(__load) { + doEval(__load.source, global); + } + }; + }); +})( + { "can-namespace": "can" }, + typeof self == "object" && self.Object == Object ? self : window, + function(__$source__, __$global__) { + // jshint ignore:line + eval("(function() { " + __$source__ + " \n }).call(__$global__);"); + } +); + +/*can-namespace@1.0.0#can-namespace*/ +define('can-namespace', function (require, exports, module) { + module.exports = {}; +}); +/*can-log@0.1.0#can-log*/ +define('can-log', function (require, exports, module) { + 'use strict'; + exports.warnTimeout = 5000; + exports.logLevel = 0; + exports.warn = function (out) { + var ll = this.logLevel; + if (ll < 2) { + Array.prototype.unshift.call(arguments, 'WARN:'); + if (typeof console !== 'undefined' && console.warn) { + this._logger('warn', Array.prototype.slice.call(arguments)); + } else if (typeof console !== 'undefined' && console.log) { + this._logger('log', Array.prototype.slice.call(arguments)); + } else if (window && window.opera && window.opera.postError) { + window.opera.postError('CanJS WARNING: ' + out); + } + } + }; + exports.log = function (out) { + var ll = this.logLevel; + if (ll < 1) { + if (typeof console !== 'undefined' && console.log) { + Array.prototype.unshift.call(arguments, 'INFO:'); + this._logger('log', Array.prototype.slice.call(arguments)); + } else if (window && window.opera && window.opera.postError) { + window.opera.postError('CanJS INFO: ' + out); + } + } + }; + exports.error = function (out) { + var ll = this.logLevel; + if (ll < 1) { + if (typeof console !== 'undefined' && console.error) { + Array.prototype.unshift.call(arguments, 'ERROR:'); + this._logger('error', Array.prototype.slice.call(arguments)); + } else if (window && window.opera && window.opera.postError) { + window.opera.postError('ERROR: ' + out); + } + } + }; + exports._logger = function (type, arr) { + try { + console[type].apply(console, arr); + } catch (e) { + console[type](arr); + } + }; +}); +/*can-log@0.1.0#dev/dev*/ +define('can-log/dev/dev', [ + 'require', + 'exports', + 'module', + 'can-log' +], function (require, exports, module) { + 'use strict'; + var canLog = require('can-log'); + module.exports = { + warnTimeout: 5000, + logLevel: 0, + stringify: function (value) { + var flagUndefined = function flagUndefined(key, value) { + return value === undefined ? '/* void(undefined) */' : value; + }; + return JSON.stringify(value, flagUndefined, ' ').replace(/"\/\* void\(undefined\) \*\/"/g, 'undefined'); + }, + warn: function () { + }, + log: function () { + }, + error: function () { + }, + _logger: canLog._logger + }; +}); +/*can-attribute-encoder@0.3.1#can-attribute-encoder*/ +define('can-attribute-encoder', [ + 'require', + 'exports', + 'module', + 'can-namespace', + 'can-log/dev/dev' +], function (require, exports, module) { + var namespace = require('can-namespace'); + var dev = require('can-log/dev/dev'); + function each(items, callback) { + for (var i = 0; i < items.length; i++) { + callback(items[i], i); + } + } + function makeMap(str) { + var obj = {}, items = str.split(','); + each(items, function (name) { + obj[name] = true; + }); + return obj; + } + var caseMattersAttributes = makeMap('allowReorder,attributeName,attributeType,autoReverse,baseFrequency,baseProfile,calcMode,clipPathUnits,contentScriptType,contentStyleType,diffuseConstant,edgeMode,externalResourcesRequired,filterRes,filterUnits,glyphRef,gradientTransform,gradientUnits,kernelMatrix,kernelUnitLength,keyPoints,keySplines,keyTimes,lengthAdjust,limitingConeAngle,markerHeight,markerUnits,markerWidth,maskContentUnits,maskUnits,patternContentUnits,patternTransform,patternUnits,pointsAtX,pointsAtY,pointsAtZ,preserveAlpha,preserveAspectRatio,primitiveUnits,repeatCount,repeatDur,requiredExtensions,requiredFeatures,specularConstant,specularExponent,spreadMethod,startOffset,stdDeviation,stitchTiles,surfaceScale,systemLanguage,tableValues,textLength,viewBox,viewTarget,xChannelSelector,yChannelSelector'); + function camelCaseToSpinalCase(match, lowerCaseChar, upperCaseChar) { + return lowerCaseChar + '-' + upperCaseChar.toLowerCase(); + } + function startsWith(allOfIt, startsWith) { + return allOfIt.indexOf(startsWith) === 0; + } + function endsWith(allOfIt, endsWith) { + return allOfIt.length - allOfIt.indexOf(endsWith) === endsWith.length; + } + var regexes = { + leftParens: /\(/g, + rightParens: /\)/g, + leftBrace: /\{/g, + rightBrace: /\}/g, + camelCase: /([a-z])([A-Z])/g, + forwardSlash: /\//g, + space: /\s/g, + uppercase: /[A-Z]/g, + uppercaseDelimiterThenChar: /:u:([a-z])/g, + caret: /\^/g, + dollar: /\$/g, + at: /@/g + }; + var delimiters = { + prependUppercase: ':u:', + replaceSpace: ':s:', + replaceForwardSlash: ':f:', + replaceLeftParens: ':lp:', + replaceRightParens: ':rp:', + replaceLeftBrace: ':lb:', + replaceRightBrace: ':rb:', + replaceCaret: ':c:', + replaceDollar: ':d:', + replaceAt: ':at:' + }; + var encoder = {}; + encoder.encode = function (name) { + var encoded = name; + if (!caseMattersAttributes[encoded] && encoded.match(regexes.camelCase)) { + if (startsWith(encoded, 'on:') || endsWith(encoded, ':to') || endsWith(encoded, ':from') || endsWith(encoded, ':bind')) { + encoded = encoded.replace(regexes.uppercase, function (char) { + return delimiters.prependUppercase + char.toLowerCase(); + }); + } else { + encoded = encoded.replace(regexes.camelCase, camelCaseToSpinalCase); + } + } + encoded = encoded.replace(regexes.space, delimiters.replaceSpace).replace(regexes.forwardSlash, delimiters.replaceForwardSlash).replace(regexes.leftParens, delimiters.replaceLeftParens).replace(regexes.rightParens, delimiters.replaceRightParens).replace(regexes.leftBrace, delimiters.replaceLeftBrace).replace(regexes.rightBrace, delimiters.replaceRightBrace).replace(regexes.caret, delimiters.replaceCaret).replace(regexes.dollar, delimiters.replaceDollar).replace(regexes.at, delimiters.replaceAt); + return encoded; + }; + encoder.decode = function (name) { + var decoded = name; + decoded = decoded.replace(delimiters.replaceLeftParens, '(').replace(delimiters.replaceRightParens, ')').replace(delimiters.replaceLeftBrace, '{').replace(delimiters.replaceRightBrace, '}').replace(delimiters.replaceForwardSlash, '/').replace(delimiters.replaceSpace, ' ').replace(delimiters.replaceCaret, '^').replace(delimiters.replaceDollar, '$').replace(delimiters.replaceAt, '@'); + if (!caseMattersAttributes[decoded] && decoded.match(regexes.uppercaseDelimiterThenChar)) { + if (startsWith(decoded, 'on:') || endsWith(decoded, ':to') || endsWith(decoded, ':from') || endsWith(decoded, ':bind')) { + decoded = decoded.replace(regexes.uppercaseDelimiterThenChar, function (match, char) { + return char.toUpperCase(); + }); + } + } + return decoded; + }; + if (namespace.encoder) { + throw new Error('You can\'t have two versions of can-attribute-encoder, check your dependencies'); + } else { + module.exports = namespace.encoder = encoder; + } +}); +/*can-view-parser@3.6.2#can-view-parser*/ +define('can-view-parser', [ + 'require', + 'exports', + 'module', + 'can-namespace', + 'can-log/dev/dev', + 'can-attribute-encoder' +], function (require, exports, module) { + var namespace = require('can-namespace'), dev = require('can-log/dev/dev'), encoder = require('can-attribute-encoder'); + function each(items, callback) { + for (var i = 0; i < items.length; i++) { + callback(items[i], i); + } + } + function makeMap(str) { + var obj = {}, items = str.split(','); + each(items, function (name) { + obj[name] = true; + }); + return obj; + } + function handleIntermediate(intermediate, handler) { + for (var i = 0, len = intermediate.length; i < len; i++) { + var item = intermediate[i]; + handler[item.tokenType].apply(handler, item.args); + } + return intermediate; + } + var alphaNumeric = 'A-Za-z0-9', alphaNumericHU = '-:_' + alphaNumeric, defaultMagicStart = '{{', endTag = new RegExp('^<\\/([' + alphaNumericHU + ']+)[^>]*>'), defaultMagicMatch = new RegExp('\\{\\{(![\\s\\S]*?!|[\\s\\S]*?)\\}\\}\\}?', 'g'), space = /\s/, alphaRegex = new RegExp('[' + alphaNumeric + ']'); + var empty = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'); + var caseMattersElements = makeMap('altGlyph,altGlyphDef,altGlyphItem,animateColor,animateMotion,animateTransform,clipPath,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,foreignObject,glyphRef,linearGradient,radialGradient,textPath'); + var closeSelf = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'); + var special = makeMap('script'); + var tokenTypes = 'start,end,close,attrStart,attrEnd,attrValue,chars,comment,special,done'.split(','); + var startOppositesMap = { + '{': '}', + '(': ')' + }; + var fn = function () { + }; + var HTMLParser = function (html, handler, returnIntermediate) { + if (typeof html === 'object') { + return handleIntermediate(html, handler); + } + var intermediate = []; + handler = handler || {}; + if (returnIntermediate) { + each(tokenTypes, function (name) { + var callback = handler[name] || fn; + handler[name] = function () { + if (callback.apply(this, arguments) !== false) { + var end = arguments.length; + if (arguments[end - 1] === undefined) { + end = arguments.length - 1; + } + intermediate.push({ + tokenType: name, + args: [].slice.call(arguments, 0, end) + }); + } + }; + }); + } + var magicMatch = handler.magicMatch || defaultMagicMatch, magicStart = handler.magicStart || defaultMagicStart; + function parseStartTag(tag, tagName, rest, unary) { + tagName = caseMattersElements[tagName] ? tagName : tagName.toLowerCase(); + if (closeSelf[tagName] && stack.last() === tagName) { + parseEndTag('', tagName); + } + unary = empty[tagName] || !!unary; + handler.start(tagName, unary, lineNo); + if (!unary) { + stack.push(tagName); + } + HTMLParser.parseAttrs(rest, handler, lineNo); + handler.end(tagName, unary, lineNo); + } + function parseEndTag(tag, tagName) { + var pos; + if (!tagName) { + pos = 0; + } else { + tagName = caseMattersElements[tagName] ? tagName : tagName.toLowerCase(); + for (pos = stack.length - 1; pos >= 0; pos--) { + if (stack[pos] === tagName) { + break; + } + } + } + if (pos >= 0) { + for (var i = stack.length - 1; i >= pos; i--) { + if (handler.close) { + handler.close(stack[i], lineNo); + } + } + stack.length = pos; + } + } + function parseMustache(mustache, inside) { + if (handler.special) { + handler.special(inside, lineNo); + } + } + var callChars = function () { + if (charsText) { + if (handler.chars) { + handler.chars(charsText, lineNo); + } + } + charsText = ''; + }; + var index, chars, match, lineNo, stack = [], last = html, charsText = ''; + stack.last = function () { + return this[this.length - 1]; + }; + while (html) { + chars = true; + if (!stack.last() || !special[stack.last()]) { + if (html.indexOf(''); + if (index >= 0) { + callChars(); + if (handler.comment) { + handler.comment(html.substring(4, index), lineNo); + } + html = html.substring(index + 3); + chars = false; + } + } else if (html.indexOf(']*>'), function (all, text) { + text = text.replace(/|/g, '$1$2'); + if (handler.chars) { + handler.chars(text, lineNo); + } + return ''; + }); + parseEndTag('', stack.last()); + } + if (html === last) { + throw new Error('Parse Error: ' + html); + } + last = html; + } + callChars(); + parseEndTag(); + handler.done(lineNo); + return intermediate; + }; + var callAttrStart = function (state, curIndex, handler, rest, lineNo) { + var attrName = rest.substring(typeof state.nameStart === 'number' ? state.nameStart : curIndex, curIndex), newAttrName = encoder.encode(attrName); + state.attrStart = newAttrName; + handler.attrStart(state.attrStart, lineNo); + state.inName = false; + }; + var callAttrEnd = function (state, curIndex, handler, rest, lineNo) { + if (state.valueStart !== undefined && state.valueStart < curIndex) { + var val = rest.substring(state.valueStart, curIndex); + handler.attrValue(val, lineNo); + } + handler.attrEnd(state.attrStart, lineNo); + state.attrStart = undefined; + state.valueStart = undefined; + state.inValue = false; + state.inName = false; + state.lookingForEq = false; + state.inQuote = false; + state.lookingForName = true; + }; + var findBreak = function (str, magicStart) { + var magicLength = magicStart.length; + for (var i = 0, len = str.length; i < len; i++) { + if (str[i] === '<' || str.substr(i, magicLength) === magicStart) { + return i; + } + } + return -1; + }; + HTMLParser.parseAttrs = function (rest, handler, lineNo) { + if (!rest) { + return; + } + var magicMatch = handler.magicMatch || defaultMagicMatch, magicStart = handler.magicStart || defaultMagicStart; + var i = 0; + var curIndex; + var state = { + inName: false, + nameStart: undefined, + inValue: false, + valueStart: undefined, + inQuote: false, + attrStart: undefined, + lookingForName: true, + lookingForValue: false, + lookingForEq: false + }; + while (i < rest.length) { + curIndex = i; + var cur = rest.charAt(i); + i++; + if (magicStart === rest.substr(curIndex, magicStart.length)) { + if (state.inValue && curIndex > state.valueStart) { + handler.attrValue(rest.substring(state.valueStart, curIndex), lineNo); + } else if (state.inName && state.nameStart < curIndex) { + callAttrStart(state, curIndex, handler, rest, lineNo); + callAttrEnd(state, curIndex, handler, rest, lineNo); + } else if (state.lookingForValue) { + state.inValue = true; + } else if (state.lookingForEq && state.attrStart) { + callAttrEnd(state, curIndex, handler, rest, lineNo); + } + magicMatch.lastIndex = curIndex; + var match = magicMatch.exec(rest); + if (match) { + handler.special(match[1], lineNo); + i = curIndex + match[0].length; + if (state.inValue) { + state.valueStart = curIndex + match[0].length; + } + } + } else if (state.inValue) { + if (state.inQuote) { + if (cur === state.inQuote) { + callAttrEnd(state, curIndex, handler, rest, lineNo); + } + } else if (space.test(cur)) { + callAttrEnd(state, curIndex, handler, rest, lineNo); + } + } else if (cur === '=' && (state.lookingForEq || state.lookingForName || state.inName)) { + if (!state.attrStart) { + callAttrStart(state, curIndex, handler, rest, lineNo); + } + state.lookingForValue = true; + state.lookingForEq = false; + state.lookingForName = false; + } else if (state.inName) { + var started = rest[state.nameStart], otherStart, otherOpposite; + if (startOppositesMap[started] === cur) { + otherStart = started === '{' ? '(' : '{'; + otherOpposite = startOppositesMap[otherStart]; + if (rest[curIndex + 1] === otherOpposite) { + callAttrStart(state, curIndex + 2, handler, rest, lineNo); + i++; + } else { + callAttrStart(state, curIndex + 1, handler, rest, lineNo); + } + state.lookingForEq = true; + } else if (space.test(cur) && started !== '{' && started !== '(') { + callAttrStart(state, curIndex, handler, rest, lineNo); + state.lookingForEq = true; + } + } else if (state.lookingForName) { + if (!space.test(cur)) { + if (state.attrStart) { + callAttrEnd(state, curIndex, handler, rest, lineNo); + } + state.nameStart = curIndex; + state.inName = true; + } + } else if (state.lookingForValue) { + if (!space.test(cur)) { + state.lookingForValue = false; + state.inValue = true; + if (cur === '\'' || cur === '"') { + state.inQuote = cur; + state.valueStart = curIndex + 1; + } else { + state.valueStart = curIndex; + } + } else if (i === rest.length) { + callAttrEnd(state, curIndex, handler, rest, lineNo); + } + } + } + if (state.inName) { + callAttrStart(state, curIndex + 1, handler, rest, lineNo); + callAttrEnd(state, curIndex + 1, handler, rest, lineNo); + } else if (state.lookingForEq || state.lookingForValue || state.inValue) { + callAttrEnd(state, curIndex + 1, handler, rest, lineNo); + } + magicMatch.lastIndex = 0; + }; + HTMLParser.searchStartTag = function (html) { + var closingIndex = html.indexOf('>'); + if (closingIndex === -1 || !alphaRegex.test(html[1])) { + return null; + } + var tagName, tagContent, match, rest = '', unary = ''; + var startTag = html.substring(0, closingIndex + 1); + var isUnary = startTag[startTag.length - 2] === '/'; + var spaceIndex = startTag.search(space); + if (isUnary) { + unary = '/'; + tagContent = startTag.substring(1, startTag.length - 2).trim(); + } else { + tagContent = startTag.substring(1, startTag.length - 1).trim(); + } + if (spaceIndex === -1) { + tagName = tagContent; + } else { + spaceIndex--; + tagName = tagContent.substring(0, spaceIndex); + rest = tagContent.substring(spaceIndex); + } + match = [ + startTag, + tagName, + rest, + unary + ]; + return { + match: match, + html: html.substring(startTag.length) + }; + }; + module.exports = namespace.HTMLParser = HTMLParser; +}); +/*[global-shim-end]*/ +(function(global) { // jshint ignore:line + global._define = global.define; + global.define = global.define.orig; +} +)(typeof self == "object" && self.Object == Object ? self : window); \ No newline at end of file