UNPKG

sodajs

Version:

Light weight but powerful template engine for JavaScript.

1,423 lines (1,127 loc) 189 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["soda"] = factory(); else root["soda"] = factory(); })(this, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 17); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var EventTarget = __webpack_require__(6); var Node = function (_EventTarget) { _inherits(Node, _EventTarget); function Node() { _classCallCheck(this, Node); var _this = _possibleConstructorReturn(this, (Node.__proto__ || Object.getPrototypeOf(Node)).call(this)); _this.ELEMENT_NODE = 1; _this.ATTRIBUTE_NODE = 2; _this.TEXT_NODE = 3; _this.CDATA_SECTION_NODE = 4; _this.ENTITY_REFERENCE_NODE = 5; // historical _this.ENTITY_NODE = 6; // historical _this.PROCESSING_INSTRUCTION_NODE = 7; _this.COMMENT_NODE = 8; _this.DOCUMENT_NODE = 9; _this.DOCUMENT_TYPE_NODE = 10; _this.DOCUMENT_FRAGMENT_NODE = 11; _this.NOTATION_NODE = 12; // historical _this.childNodes = []; _this.nodeValue = ''; _this.ownerDocument = null; _this.parentNode = null; _this.textContent = ''; return _this; } _createClass(Node, [{ key: 'appendChild', value: function appendChild(node) { return this.insertBefore(node); } // @todo 这个参数有问题 }, { key: 'cloneNode', value: function cloneNode(deep) { if (this.nodeType === this.TEXT_NODE) { var node = this.ownerDocument.createTextNode(this.nodeValue); return node; } if (this.nodeType === this.COMMENT_NODE) { var node = this.ownerDocument.createComment(this.nodeValue); return node; } var node = this.ownerDocument.createDocumentFragment(); var tagName = this.tagName && this.tagName.toLowerCase(); if (deep) { node.innerHTML = "<" + tagName + " " + this._getAttributeString() + ">" + this.innerHTML + "</" + tagName + ">"; } else { node.innerHTML = "<" + tagName + " " + this._getAttributeString() + "></" + tagName + ">"; } return node.childNodes[0]; } }, { key: 'getRootNode', value: function getRootNode() { var getParentNode = function getParentNode(node) { if (node.parentNode) { return getParentNode(node.parentNode); } else { return node; } }; return getParentNode(this); } }, { key: 'contains', value: function contains(node) { if (node === this) { return true; } var flag = false; for (var i = 0; i < this.childNodes.length; i++) { var child = this.childNodes[i]; if (child.contains(node)) { flag = true; break; } } return flag; } }, { key: 'compareDocumentPosition', value: function compareDocumentPosition(node) { function comparePosition(a, b) { (a != b && a.contains(b) && 16) + (a != b && b.contains(a) && 8) + (a.sourceIndex >= 0 && b.sourceIndex >= 0 ? (a.sourceIndex < b.sourceIndex && 4) + (a.sourceIndex > b.sourceIndex && 2) : 1); } } }, { key: 'hasChildNodes', value: function hasChildNodes() { return this.childNodes.length; } }, { key: 'removeChild', value: function removeChild(node) { for (var i = 0; i < this.childNodes.length; i++) { if (this.childNodes[i] === node) { this.childNodes.splice(i, 1); node.parentNode = null; break; } } } }, { key: 'insertBefore', value: function insertBefore(newNode, oldNode) { for (var i = 0; i < this.childNodes.length; i++) { if (this.childNodes[i] === oldNode) { break; } } var checkInDocument = function checkInDocument(n) { var flag = 0; var checkNode = function checkNode(node) { if (node === window.DOMTREE._tree[0]) { flag = 1; return; } if (node.parentNode) { checkNode(node.parentNode); } }; checkNode(n); return flag; }; // var isInDocument = checkInDocument(this); // 如果是frament 则将子元素添加进去 if ((newNode.tagName || '').toLowerCase() === "fragment") { Array.prototype.splice.apply(this.childNodes, [i, 0].concat(newNode.childNodes)); for (var i = 0; i < newNode.childNodes.length; i++) { newNode.childNodes[i].parentNode = this; // 这里有待完善 /* if(isInDocument){ newNode.childNodes[i].getIdMap(window.DOMTREE._idMap); } */ } // 置空子元素 newNode.childNodes = []; } else { // 从原来的父元素中删除掉 if (newNode.parentNode) { newNode.parentNode.removeChild(newNode); } newNode.parentNode = this; this.childNodes.splice(i, 0, newNode); // 这里有待完善 /* if(isInDocument){ newNode.getIdMap(window.DOMTREE._idMap); } */ } /* if(newNode.tagName === "script"){ if(newNode.src){ var content = window.drequire(newNode.src, function(){ newNode.onload && newNode.onload.call(newNode); // 注意这里 把新加的脚本执行后就删除了 newNode.parentNode.removeChild(newNode); }); for(var i in content){ global[i] = content[i]; } } } */ return newNode; } }, { key: 'parentNodeElement', get: function get() { if (this.parentNode.nodeType === this.ELEMENT_NODE) { return this.parentNode; } else { return null; } } }, { key: 'previousSibling', get: function get() {} }, { key: 'firstChild', get: function get() { return this.childNodes[0]; } }, { key: 'lastChild', get: function get() { return this.childNodes[this.childNodes.length - 1]; } }, { key: 'nextSibling', get: function get() {} }, { key: 'nodeName', get: function get() { return this.tagName; } }]); return Node; }(EventTarget); module.exports = Node; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Node = __webpack_require__(0); var Text = function (_Node) { _inherits(Text, _Node); function Text(text) { _classCallCheck(this, Text); var _this = _possibleConstructorReturn(this, (Text.__proto__ || Object.getPrototypeOf(Text)).call(this)); _this.nodeType = _this.TEXT_NODE; _this.nodeValue = text || ''; return _this; } _createClass(Text, [{ key: '_getEnscapeValue', value: function _getEnscapeValue(value) { return value.replace(/</g, '&lt;').replace(/>/g, '&gt;'); } }]); return Text; }(Node); module.exports = Text; /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Document = __webpack_require__(3); var Window = function () { function Window(browserEnv) { _classCallCheck(this, Window); this.document = new Document(this); this.setGlobalVars(); } _createClass(Window, [{ key: 'setGlobalVars', value: function setGlobalVars() { this.setTimeout = setTimeout; this.clearTimeout = clearTimeout; this.setInterval = setInterval; this.clearInterval = clearInterval; this.parseInt = parseInt; this.parseFloat = parseFloat; this.console = { log: function log(val) { console.log(val); }, info: function info() {}, debug: function debug() {}, dir: function dir() {} }; } }]); return Window; }(); module.exports = Window; /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } //var Event = require('./event'); //var CanvasEl = require('./canvsel'); var HTMLElement = __webpack_require__(4); var Node = __webpack_require__(0); var Text = __webpack_require__(1); var Comment = __webpack_require__(10); var ElementClassDeclaredMap = { canvas: 'HTMLCanvasElement' }; var Document = function (_Node) { _inherits(Document, _Node); function Document(defaultView) { _classCallCheck(this, Document); var _this = _possibleConstructorReturn(this, (Document.__proto__ || Object.getPrototypeOf(Document)).call(this)); _this.__defaultView = defaultView; return _this; } _createClass(Document, [{ key: 'createElement', value: function createElement(tagName) { /* if(tagName === "canvas"){ return new CanvasEl(); } var node = new domEle.Element(); node.tagName = tagName; */ var node; tagName = (tagName || '').toUpperCase(); if (ElementClassDeclaredMap[tagName]) { var elementClass = __webpack_require__(34)("./" + ElementClassDeclaredMap[tagName].toLowerCase()); node = new elementClass(tagName); } else { node = new HTMLElement(tagName); } node.ownerDocument = this; return node; } }, { key: 'createDocumentFragment', value: function createDocumentFragment() { var node = this.createElement('fragment'); return node; } }, { key: 'createTextNode', value: function createTextNode(text) { return new Text(text); } }, { key: 'createComment', value: function createComment(text) { return new Comment(text); } }, { key: 'getElementById', value: function getElementById(id) { var result; var findChild = function findChild(node) { if (result) { return; } for (var i = 0; i < node.childNodes.length; i++) { var _node = node.childNodes[i]; var _id = _node.id; if (_id == id) { result = node.childNodes[i]; break; } if (_node.childNodes && _node.childNodes.length) { findChild(_node); } } }; findChild(this); return result; } }, { key: 'getElementsByClassName', value: function getElementsByClassName(className) { return this.documentElement.getElementsByClassName(className); } }, { key: 'getElementsByTagName', value: function getElementsByTagName(tagName) { return this.documentElement.getElementsByTagName(tagName); } }, { key: 'defaultView', get: function get() { return this.__defaultView; } }]); return Document; }(Node); module.exports = Document; /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Element = __webpack_require__(5); var CSSStyleDeclaration = __webpack_require__(9); var HTMLElement = function (_Element) { _inherits(HTMLElement, _Element); function HTMLElement(tagName) { _classCallCheck(this, HTMLElement); var _this = _possibleConstructorReturn(this, (HTMLElement.__proto__ || Object.getPrototypeOf(HTMLElement)).call(this, tagName)); _this.style = new CSSStyleDeclaration(); return _this; } _createClass(HTMLElement, [{ key: 'blur', value: function blur() { console.warn('blur is not realised'); } }, { key: 'unblur', value: function unblur() {} }, { key: 'click', value: function click() {} }, { key: 'focus', value: function focus() {} }, { key: 'forceSpellCheck', value: function forceSpellCheck() {} }]); return HTMLElement; }(Element); module.exports = HTMLElement; /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Node = __webpack_require__(0); var NamedNodeMap = __webpack_require__(7); var DOMTokenList = __webpack_require__(8); var exist = function exist(value) { return value !== null && value !== undefined && value !== "" && typeof value !== 'undefined'; }; var parseCssText = function parseCssText(style, val) { // 解析css if (val) { val = val.split(";"); val.map(function (item, index) { if (item) { var exp = item.split(":"); var name = exp[0]; var v = exp[1] || ''; style[name] = v; } }); } }; var getEnscapeValue = function getEnscapeValue(value) { return value.replace(/</g, '&lt;').replace(/>/g, '&gt;'); }; var donotEnscapeTagReg = /script|pre|code/; var Element = function (_Node) { _inherits(Element, _Node); function Element(tagName) { _classCallCheck(this, Element); var _this2 = _possibleConstructorReturn(this, (Element.__proto__ || Object.getPrototypeOf(Element)).call(this)); _this2.tagName = tagName; _this2.nodeType = _this2.ELEMENT_NODE; _this2.attributes = new NamedNodeMap(_this2); _this2.classList = new DOMTokenList(_this2); return _this2; } _createClass(Element, [{ key: '_getAttributeString', value: function _getAttributeString() { var attrArr = []; for (var i = 0; i < this.attributes.length; i++) { if (this.attributes[i].nodeType && this.attributes[i].nodeType === this.ATTRIBUTE_NODE) { var attrName = this.attributes[i].name; if (attrName === "className") { attrName = 'class'; } if (attrName === "style") { continue; } attrArr.push(attrName + "=\"" + (exist(this.attributes[i].value) ? this.attributes[i].value : '') + "\""); } } //console.log('style'); var styleCode = []; for (var i in this.style) { if (this.style[i]) { styleCode.push(i + ":" + this.style[i]); } } if (styleCode.length) { attrArr.push("style=\"" + styleCode.join(";") + "\""); } var attrStr = attrArr.join(" "); if (attrStr) { attrStr = " " + attrStr; } return attrStr; } }, { key: 'getAttribute', /*=====================method=======================*/ value: function getAttribute(attr) { var item = this.attributes.getNamedItem(attr); if (item) { return item.value; } else { return null; } } }, { key: 'setAttribute', value: function setAttribute(attr, val) { var _this = this; if (attr === "style") { parseCssText(this.style, val); } this.attributes.setNamedItem(attr, val); } }, { key: 'removeAttribute', value: function removeAttribute(attr) { this.attributes.removeNamedItem(attr); } }, { key: 'getElementsByClassName', value: function getElementsByClassName(className) { var result = []; if (this.childNodes.length) { for (var i = 0; i < this.childNodes.length; i++) { var _node = this.childNodes[i]; if (_node.nodeType === _node.ELEMENT_NODE) { if (_node.classList && _node.classList.contains(className)) { result.push(_node); } result = result.concat(_node.getElementsByClassName(className)); } } } return result; } }, { key: 'getElementsByTagName', value: function getElementsByTagName(tagName) { if (typeof tagName !== 'string') { throw new Error('getElementsByTagName first argument to be string!'); } var result = []; tagName = tagName.toLowerCase(); if (this.childNodes.length) { for (var i = 0; i < this.childNodes.length; i++) { var _node = this.childNodes[i]; if (_node.nodeType === _node.ELEMENT_NODE) { var nodeTagName = (_node.tagName || '').toLowerCase(); if (nodeTagName === tagName || tagName === "*") { result.push(_node); } result = result.concat(_node.getElementsByTagName(tagName)); } } } return result; } }, { key: 'className', get: function get() { return this.getAttribute('className'); }, set: function set(val) { this.setAttribute('className', val); } // @ready only }, { key: 'clientWidth', get: function get() {} }, { key: 'clientHeight', get: function get() {} }, { key: 'clientLeft', get: function get() {} }, { key: 'clientTop', get: function get() {} }, { key: 'computedName', get: function get() {} }, { key: 'computedRole', get: function get() {} }, { key: 'id', get: function get() { return this.getAttribute('id'); }, set: function set(val) { this.setAttribute(id); } }, { key: 'innerHTML', get: function get() { var tagName = (this.tagName || '').toLowerCase(); var html = ""; if (this.childNodes && this.childNodes.length) { for (var i = 0; i < this.childNodes.length; i++) { var child = this.childNodes[i]; if (child.nodeType === this.TEXT_NODE) { if (donotEnscapeTagReg.test(tagName)) { html += child.nodeValue; } else { html += getEnscapeValue(child.nodeValue); } } else { html += child.outerHTML; } } } else {} return html; }, set: function set(val) { var ParseDom = __webpack_require__(12); var document = this.ownerDocument; var window = document.defaultView || {}; var result = new ParseDom().parseHTMLFragment(val, window); var docTree = result.docTree; this.childNodes = docTree._tree.childNodes; for (var i = 0; i < this.childNodes.length; i++) { this.childNodes[i].parentNode = this; } } }, { key: 'localName', get: function get() { return this.tagName || ''; } }, { key: 'outerHTML', set: function set(val) { var document = this.ownerDocument; var div = document.createElement('div'); div.innerHTML = val; if (this.parentNode) { while (div.childNodes[0]) { this.parentNode.insertBefore(div.childNodes[0], this); } this.parentNode.removeChild(this); } }, get: function get() { var tagName = (this.tagName || '').toLowerCase(); var selfCloseTagReg = /br|hr|img|link|meta/; var isSelfEnd = selfCloseTagReg.test(tagName); if (this.nodeType === this.TEXT_NODE || !tagName) { return this.nodeValue || ""; } var attrStr = this._getAttributeString(); var html; if (isSelfEnd) { html = "<" + tagName + attrStr + " />"; } else { html = "<" + tagName + attrStr + ">"; if (this.childNodes) { for (var i = 0; i < this.childNodes.length; i++) { var child = this.childNodes[i]; if (child.nodeType === this.TEXT_NODE) { if (donotEnscapeTagReg.test(tagName)) { html += child.nodeValue; } else { html += getEnscapeValue(child.nodeValue); } } else { html += child.outerHTML; } } } html += "</" + tagName + ">"; } return html; } }, { key: 'scrollTop', get: function get() { return this.__scrollTop || 0; }, set: function set(val) { this.__scrollTop = val; } }]); return Element; }(Node); module.exports = Element; /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var EventEmitter = __webpack_require__(20); var EventTarget = function () { function EventTarget() { _classCallCheck(this, EventTarget); this.listeners = {}; this._emitter = new EventEmitter(); } _createClass(EventTarget, [{ key: 'addEventListener', value: function addEventListener(type, handler, isCapture) { this._emitter.addListener(type, handler.handleEvent || handler, isCapture); } }, { key: 'removeEventListener', value: function removeEventListener(type, callback) {} }, { key: 'dispatchEvent', value: function dispatchEvent(event) { var e = { preventDefault: function preventDefault() {}, stopPropagation: function stopPropagation() {}, target: this, srcElement: this }; if (this._emitter) { this._emitter.emit(event.type, e); } } }]); return EventTarget; }(); module.exports = EventTarget; /***/ }), /* 7 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Text = __webpack_require__(1); var NamedNodeMap = function () { function NamedNodeMap(node) { _classCallCheck(this, NamedNodeMap); this.length = 0; this.ownerElment = node; } _createClass(NamedNodeMap, [{ key: 'removeNamedItem', value: function removeNamedItem(name) { var index = -1; for (var i in this) { if (this.hasOwnProperty(i)) { var item = this[i]; if (item.name == name) { index = Number(i); break; } } } if (!isNaN(index) && index > -1) { delete this[index]; this.length--; for (var i = index; i < this.length; i++) { this[i] = this[i + 1]; } delete this[name]; } } }, { key: 'setNamedItem', value: function setNamedItem(name, value) { var attr = this.getNamedItem(name); var _this = this; if (attr) { attr.name = name; attr.nodeValue = value; attr.value = value; attr.firstChild.value = value; attr.firstChild.nodeValue = value; } else { this[this.length++] = { name: name, value: value, ownerElment: this.ownerElment, nodeType: this.ownerElment.ATTRIBUTE_NODE, nodeValue: value, childNodes: function () { var node = _this.ownerElment.ownerDocument.createTextNode(); return [node]; }(), get lastChild() { return this.childNodes[this.childNodes.length - 1]; }, get firstChild() { return this.childNodes[0]; } }; this[name] = this[this.length - 1]; } } }, { key: 'getNamedItem', value: function getNamedItem(name) { for (var i in this) { if (this.hasOwnProperty(i)) { var item = this[i]; if (item.name == name) { return item; } } } } }]); return NamedNodeMap; }(); module.exports = NamedNodeMap; /***/ }), /* 8 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var DOMTokenList = function () { function DOMTokenList(ownElement) { _classCallCheck(this, DOMTokenList); this.ownElement = ownElement; } _createClass(DOMTokenList, [{ key: 'item', value: function item(index) { return this.__class[index]; } }, { key: 'contains', value: function contains(className) { return this.__class.indexOf(className) > -1; } }, { key: 'add', value: function add(className) { if (this.contains(className)) {} else { var classList = this.__class; classList.push(className); this.ownElement.className = classList.join(' '); } } }, { key: 'remove', value: function remove(className) { var classList = this.__class; var index = classList.indexOf(className); if (index > -1) { classList.splice(index, 1); this.ownElement.className = classList.join(' '); } } }, { key: 'toggle', value: function toggle(className) { this.contains(className) ? this.remove(className) : this.add(className); } }, { key: 'keys', value: function keys() { return this.__class.keys(); } }, { key: 'values', value: function values() { return this.__class[Symbol.iterator](); } }, { key: 'toString', value: function toString() { return this.value; } }, { key: '__class', get: function get() { var className = this.ownElement.className || ''; if (className.trim()) { var nameArr = (this.ownElement.className || '').trim().split(/ +/); return nameArr; } else { return []; } } }, { key: 'length', get: function get() { return this.__class.length; } }, { key: 'value', get: function get() { return this.__class.join(' '); } }]); return DOMTokenList; }(); module.exports = DOMTokenList; /***/ }), /* 9 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var parseCssText = function parseCssText(style, val) { // 解析css if (val) { val = val.split(";"); val.map(function (item, index) { if (item) { var exp = item.split(":"); var name = exp[0]; var v = exp[1] || ''; style[name] = v; } }); } }; var CSSStyleDeclaration = function () { function CSSStyleDeclaration() { _classCallCheck(this, CSSStyleDeclaration); } _createClass(CSSStyleDeclaration, [{ key: "cssText", set: function set(val) { parseCssText(this, val); } }]); return CSSStyleDeclaration; }(); module.exports = CSSStyleDeclaration; /***/ }), /* 10 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Node = __webpack_require__(0); var Comment = function (_Node) { _inherits(Comment, _Node); function Comment(text) { _classCallCheck(this, Comment); var _this = _possibleConstructorReturn(this, (Comment.__proto__ || Object.getPrototypeOf(Comment)).call(this)); _this.nodeType = _this.COMMENT_NODE; _this.nodeValue = text || ''; _this.tagName = '#comment'; return _this; } // non-standard method _createClass(Comment, [{ key: 'outerHTML', get: function get() { return "<!--" + (this.nodeValue || '') + "-->"; } // non-standard method }, { key: 'innerHTML', get: function get() { return this.nodeValue || ''; } }]); return Comment; }(Node); module.exports = Comment; /***/ }), /* 11 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; module.exports = function (module) { if (!module.webpackPolyfill) { module.deprecate = function () {}; module.paths = []; // module.parent = undefined by default if (!module.children) module.children = []; Object.defineProperty(module, "loaded", { enumerable: true, get: function get() { return module.l; } }); Object.defineProperty(module, "id", { enumerable: true, get: function get() { return module.i; } }); module.webpackPolyfill = 1; } return module; }; /***/ }), /* 12 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Tree = __webpack_require__(21); var compileCode = __webpack_require__(22); var preParsedMap = {}; var ParseDom = function () { function ParseDom() { _classCallCheck(this, ParseDom); } _createClass(ParseDom, [{ key: 'parse', value: function parse(html, window) { return this.parseHTML(html, window); } }, { key: 'parseHTMLFragment', value: function parseHTMLFragment(htmlStr, window) { var document = window.document; var docTree = new Tree(); var currNode; var preParedQueue; if (preParsedMap[htmlStr]) {} else { preParsedMap[htmlStr] = this.preParse(htmlStr); } preParedQueue = preParsedMap[htmlStr]; var headNode, bodyNode, htmlNode; for (var i = 0; i < preParedQueue.length; i++) { var item = preParedQueue[i]; var tagType = item.tagType; var tagName = item.tagName; if (tagType === "startTag") { var node = document.createElement(tagName); if (tagName === "head") { headNode = node; } if (tagName === "body") { bodyNode = node; } if (tagName === "html") { htmlNode = node; } currNode = node; docTree.push(node); //_allNode.push(node); } else if (tagType === "attrs") { var match = item.match; if (match === ">") { if (currNode.getAttribute('type') && (currNode.getAttribute("type") + '').toLowerCase() !== "text/javascript") {} else { if (currNode.getAttribute("src") && currNode.tagName === 'script') { // @这里注释掉是直出不希望再执行, 使用sodajs会碰到 // var attrValue = currNode.getAttribute("src"); // var content = windowSpace.drequire(attrValue); } } if (item.goNext) { docTree.goNext(); } } else if (match === "/>") {} else { var attrName = item.attrName; var attrValue = item.attrValue; if (attrName === "id") { // _idMap[attrValue] = currNode; } currNode.setAttribute(attrName, attrValue); }