hm-react-cli
Version:
Create a Huimei React project by module
1,496 lines (1,478 loc) • 127 kB
JavaScript
/**
* IE6+,有问题请加QQ 370262116 by 司徒正美 Copyright 2021-01-07
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory())
: typeof define === 'function' && define.amd
? define(factory)
: (global.React = factory());
})(this, function () {
var arrayPush = Array.prototype.push;
var innerHTML = 'dangerouslySetInnerHTML';
var hasOwnProperty = Object.prototype.hasOwnProperty;
var gSBU = 'getSnapshotBeforeUpdate';
var gDSFP = 'getDerivedStateFromProps';
var hasSymbol = typeof Symbol === 'function' && Symbol['for'];
var effects = [];
var topFibers = [];
var topNodes = [];
var emptyObject = {};
var REACT_ELEMENT_TYPE = hasSymbol ? Symbol['for']('react.element') : 0xeac7;
function noop() {}
function Fragment(props) {
return props.children;
}
function returnFalse() {
return false;
}
function returnTrue() {
return true;
}
function resetStack(info) {
keepLast(info.containerStack);
keepLast(info.contextStack);
}
function keepLast(list) {
var n = list.length;
list.splice(0, n - 1);
}
function get(key) {
return key._reactInternalFiber;
}
var __type = Object.prototype.toString;
var fakeWindow = {};
function getWindow() {
try {
if (window) {
return window;
}
} catch (e) {}
try {
if (global) {
return global;
}
} catch (e) {}
return fakeWindow;
}
function isMounted(instance) {
var fiber = get(instance);
return !!(fiber && fiber.hasMounted);
}
function toWarnDev(msg, deprecated) {
msg = deprecated ? msg + ' is deprecated' : msg;
var process = getWindow().process;
if (process && process.env.NODE_ENV === 'development') {
throw msg;
}
}
function extend(obj, props) {
for (var i in props) {
if (hasOwnProperty.call(props, i)) {
obj[i] = props[i];
}
}
return obj;
}
function inherit(SubClass, SupClass) {
function Bridge() {}
var orig = SubClass.prototype;
Bridge.prototype = SupClass.prototype;
var fn = (SubClass.prototype = new Bridge());
extend(fn, orig);
fn.constructor = SubClass;
return fn;
}
try {
var supportEval = Function('a', 'return a + 1')(2) == 3;
} catch (e) {}
var rname = /function\s+(\w+)/;
function miniCreateClass(ctor, superClass, methods, statics) {
var className = ctor.name || (ctor.toString().match(rname) || ['', 'Anonymous'])[1];
var Ctor = supportEval
? Function(
'superClass',
'ctor',
'return function ' +
className +
' (props, context) {\n superClass.apply(this, arguments); \n ctor.apply(this, arguments);\n }'
)(superClass, ctor)
: function ReactInstance() {
superClass.apply(this, arguments);
ctor.apply(this, arguments);
};
Ctor.displayName = className;
var proto = inherit(Ctor, superClass);
extend(proto, methods);
extend(Ctor, superClass);
if (statics) {
extend(Ctor, statics);
}
return Ctor;
}
var lowerCache = {};
function toLowerCase(s) {
return lowerCache[s] || (lowerCache[s] = s.toLowerCase());
}
function isFn(obj) {
return __type.call(obj) === '[object Function]';
}
var rword = /[^, ]+/g;
function oneObject(array, val) {
if (array + '' === array) {
array = array.match(rword) || [];
}
var result = {},
value = val !== void 666 ? val : 1;
for (var i = 0, n = array.length; i < n; i++) {
result[array[i]] = value;
}
return result;
}
var rcamelize = /[-_][^-_]/g;
function camelize(target) {
if (!target || (target.indexOf('-') < 0 && target.indexOf('_') < 0)) {
return target;
}
var str = target.replace(rcamelize, function (match) {
return match.charAt(1).toUpperCase();
});
return firstLetterLower(str);
}
function firstLetterLower(str) {
return str.charAt(0).toLowerCase() + str.slice(1);
}
var numberMap = {
'[object Boolean]': 2,
'[object Number]': 3,
'[object String]': 4,
'[object Function]': 5,
'[object Symbol]': 6,
'[object Array]': 7
};
function typeNumber(data) {
if (data === null) {
return 1;
}
if (data === void 666) {
return 0;
}
var a = numberMap[__type.call(data)];
return a || 8;
}
function createRenderer(methods) {
return extend(Renderer, methods);
}
var middlewares = [];
var Renderer = {
controlledCbs: [],
mountOrder: 1,
macrotasks: [],
boundaries: [],
onBeforeRender: noop,
onAfterRender: noop,
onDispose: noop,
middleware: function middleware(obj) {
if (obj.begin && obj.end) {
middlewares.push(obj);
}
},
updateControlled: function updateControlled() {},
fireMiddlewares: function fireMiddlewares(begin) {
var index = begin ? middlewares.length - 1 : 0,
delta = begin ? -1 : 1,
method = begin ? 'begin' : 'end',
obj;
while ((obj = middlewares[index])) {
obj[method]();
index += delta;
}
},
currentOwner: null
};
var fakeObject = {
enqueueSetState: returnFalse,
isMounted: returnFalse
};
function Component(props, context) {
Renderer.currentOwner = this;
this.context = context;
this.props = props;
this.refs = {};
this.updater = fakeObject;
this.state = null;
}
Component.prototype = {
constructor: Component,
replaceState: function replaceState() {
toWarnDev('replaceState', true);
},
isReactComponent: returnTrue,
isMounted: function isMounted$$1() {
toWarnDev('isMounted', true);
return this.updater.isMounted(this);
},
setState: function setState(state, cb) {
this.updater.enqueueSetState(get(this), state, cb);
},
forceUpdate: function forceUpdate(cb) {
this.updater.enqueueSetState(get(this), true, cb);
},
render: function render() {
throw 'must implement render';
}
};
var RESERVED_PROPS = {
key: true,
ref: true,
__self: true,
__source: true
};
function makeProps(type, config, props, children, len) {
var defaultProps, propName;
for (propName in config) {
if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
props[propName] = config[propName];
}
}
if (type && type.defaultProps) {
defaultProps = type.defaultProps;
for (propName in defaultProps) {
if (props[propName] === undefined) {
props[propName] = defaultProps[propName];
}
}
}
if (len === 1) {
props.children = children[0];
} else if (len > 1) {
props.children = children;
}
return props;
}
function hasValidRef(config) {
return config.ref !== undefined;
}
function hasValidKey(config) {
return config.key !== undefined;
}
function createElement(type, config) {
for (
var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2;
_key < _len;
_key++
) {
children[_key - 2] = arguments[_key];
}
var props = {},
tag = 5,
key = null,
ref = null,
argsLen = children.length;
if (type && type.call) {
tag = type.prototype && type.prototype.render ? 2 : 1;
} else if (type + '' !== type) {
toWarnDev('React.createElement: type is invalid.');
}
if (config != null) {
if (hasValidRef(config)) {
ref = config.ref;
}
if (hasValidKey(config)) {
key = '' + config.key;
}
}
props = makeProps(type, config || {}, props, children, argsLen);
return ReactElement(type, tag, props, key, ref, Renderer.currentOwner);
}
function cloneElement(element, config) {
var props = Object.assign({}, element.props);
var type = element.type;
var key = element.key;
var ref = element.ref;
var tag = element.tag;
var owner = element._owner;
for (
var _len2 = arguments.length, children = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2;
_key2 < _len2;
_key2++
) {
children[_key2 - 2] = arguments[_key2];
}
var argsLen = children.length;
if (config != null) {
if (hasValidRef(config)) {
ref = config.ref;
owner = Renderer.currentOwner;
}
if (hasValidKey(config)) {
key = '' + config.key;
}
}
props = makeProps(type, config || {}, props, children, argsLen);
return ReactElement(type, tag, props, key, ref, owner);
}
function createFactory(type) {
var factory = createElement.bind(null, type);
factory.type = type;
return factory;
}
function ReactElement(type, tag, props, key, ref, owner) {
var ret = {
type: type,
tag: tag,
props: props
};
if (tag !== 6) {
ret.$$typeof = REACT_ELEMENT_TYPE;
ret.key = key || null;
var refType = typeNumber(ref);
if (refType === 2 || refType === 3 || refType === 4 || refType === 5 || refType === 8) {
if (refType < 4) {
ref += '';
}
ret.ref = ref;
} else {
ret.ref = null;
}
ret._owner = owner;
}
return ret;
}
function isValidElement(vnode) {
return !!vnode && vnode.$$typeof === REACT_ELEMENT_TYPE;
}
function createVText(text) {
return ReactElement('#text', 6, text + '');
}
function escape(key) {
var escapeRegex = /[=:]/g;
var escaperLookup = {
'=': '=0',
':': '=2'
};
var escapedString = ('' + key).replace(escapeRegex, function (match) {
return escaperLookup[match];
});
return '$' + escapedString;
}
var lastText, flattenIndex, flattenObject;
function flattenCb(context, child, key, childType) {
if (child === null) {
lastText = null;
return;
}
if (childType === 3 || childType === 4) {
if (lastText) {
lastText.props += child;
return;
}
lastText = child = createVText(child);
} else {
lastText = null;
}
if (!flattenObject[key]) {
flattenObject[key] = child;
} else {
key = '.' + flattenIndex;
flattenObject[key] = child;
}
flattenIndex++;
}
function fiberizeChildren(children, fiber) {
flattenObject = {};
flattenIndex = 0;
if (children !== void 666) {
lastText = null;
traverseAllChildren(children, '', flattenCb);
}
flattenIndex = 0;
return (fiber.children = flattenObject);
}
function getComponentKey(component, index) {
if (Object(component).key != null) {
return escape(component.key);
}
return index.toString(36);
}
var SEPARATOR = '.';
var SUBSEPARATOR = ':';
function traverseAllChildren(children, nameSoFar, callback, bookKeeping) {
var childType = typeNumber(children);
var invokeCallback = false;
switch (childType) {
case 0:
case 1:
case 2:
case 5:
case 6:
children = null;
invokeCallback = true;
break;
case 3:
case 4:
invokeCallback = true;
break;
case 8:
if (children.$$typeof || children instanceof Component) {
invokeCallback = true;
} else if (children.hasOwnProperty('toString')) {
children = children + '';
invokeCallback = true;
childType = 3;
}
break;
}
if (invokeCallback) {
callback(
bookKeeping,
children,
nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar,
childType
);
return 1;
}
var subtreeCount = 0;
var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
if (children.forEach) {
children.forEach(function (child, i) {
var nextName = nextNamePrefix + getComponentKey(child, i);
subtreeCount += traverseAllChildren(child, nextName, callback, bookKeeping);
});
return subtreeCount;
}
var iteratorFn = getIteractor(children);
if (iteratorFn) {
var iterator = iteratorFn.call(children),
child,
ii = 0,
step,
nextName;
while (!(step = iterator.next()).done) {
child = step.value;
nextName = nextNamePrefix + getComponentKey(child, ii++);
subtreeCount += traverseAllChildren(child, nextName, callback, bookKeeping);
}
return subtreeCount;
}
throw 'children: type is invalid.';
}
var REAL_SYMBOL = hasSymbol && Symbol.iterator;
var FAKE_SYMBOL = '@@iterator';
function getIteractor(a) {
var iteratorFn = (REAL_SYMBOL && a[REAL_SYMBOL]) || a[FAKE_SYMBOL];
if (iteratorFn && iteratorFn.call) {
return iteratorFn;
}
}
var Children = {
only: function only(children) {
if (isValidElement(children)) {
return children;
}
throw new Error('expect only one child');
},
count: function count(children) {
if (children == null) {
return 0;
}
return traverseAllChildren(children, '', noop);
},
map: function map(children, func, context) {
return proxyIt(children, func, [], context);
},
forEach: function forEach(children, func, context) {
return proxyIt(children, func, null, context);
},
toArray: function toArray$$1(children) {
return proxyIt(children, K, []);
}
};
function proxyIt(children, func, result, context) {
if (children == null) {
return [];
}
mapChildren(children, null, func, result, context);
return result;
}
function K(el) {
return el;
}
function mapChildren(children, prefix, func, result, context) {
var keyPrefix = '';
if (prefix != null) {
keyPrefix = escapeUserProvidedKey(prefix) + '/';
}
traverseAllChildren(children, '', traverseCallback, {
context: context,
keyPrefix: keyPrefix,
func: func,
result: result,
count: 0
});
}
var userProvidedKeyEscapeRegex = /\/+/g;
function escapeUserProvidedKey(text) {
return ('' + text).replace(userProvidedKeyEscapeRegex, '$&/');
}
function traverseCallback(bookKeeping, child, childKey) {
var result = bookKeeping.result,
keyPrefix = bookKeeping.keyPrefix,
func = bookKeeping.func,
context = bookKeeping.context;
var mappedChild = func.call(context, child, bookKeeping.count++);
if (!result) {
return;
}
if (Array.isArray(mappedChild)) {
mapChildren(mappedChild, childKey, K, result);
} else if (mappedChild != null) {
if (isValidElement(mappedChild)) {
mappedChild = extend({}, mappedChild);
mappedChild.key =
keyPrefix +
(mappedChild.key && (!child || child.key !== mappedChild.key)
? escapeUserProvidedKey(mappedChild.key) + '/'
: '') +
childKey;
}
result.push(mappedChild);
}
}
var check = function check() {
return check;
};
check.isRequired = check;
var PropTypes = {
array: check,
bool: check,
func: check,
number: check,
object: check,
string: check,
any: check,
arrayOf: check,
element: check,
instanceOf: check,
node: check,
objectOf: check,
oneOf: check,
oneOfType: check,
shape: check
};
function shallowEqual(objA, objB) {
if (Object.is(objA, objB)) {
return true;
}
if (typeNumber(objA) < 7 || typeNumber(objB) < 7) {
return false;
}
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
for (var i = 0; i < keysA.length; i++) {
if (!hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
return false;
}
}
return true;
}
var PureComponent = miniCreateClass(
function PureComponent() {
this.isPureComponent = true;
},
Component,
{
shouldComponentUpdate: function shouldComponentUpdate(nextProps, nextState) {
var a = shallowEqual(this.props, nextProps);
var b = shallowEqual(this.state, nextState);
return !a || !b;
}
}
);
function createRef() {
return {
current: null
};
}
function forwardRef(fn) {
return function ForwardRefComponent(props) {
return fn(props, this.ref);
};
}
function AnuPortal(props) {
return props.children;
}
function createPortal(children, parent) {
var child = createElement(AnuPortal, {
children: children,
parent: parent
});
child.isPortal = true;
return child;
}
var MAX_NUMBER = 1073741823;
function createContext(defaultValue, calculateChangedBits) {
if (calculateChangedBits == void 0) {
calculateChangedBits = null;
}
var instance = {
value: defaultValue,
subscribers: []
};
var Provider = miniCreateClass(
function Provider(props) {
this.value = props.value;
getContext.subscribers = this.subscribers = [];
instance = this;
},
Component,
{
componentWillUnmount: function componentWillUnmount() {
this.subscribers.length = 0;
},
UNSAFE_componentWillReceiveProps: function UNSAFE_componentWillReceiveProps(nextProps) {
if (this.props.value !== nextProps.value) {
var oldValue = this.props.value;
var newValue = nextProps.value;
var changedBits = void 0;
if (Object.is(oldValue, newValue)) {
changedBits = 0;
} else {
this.value = newValue;
changedBits = isFn(calculateChangedBits)
? calculateChangedBits(oldValue, newValue)
: MAX_NUMBER;
changedBits |= 0;
if (changedBits !== 0) {
instance.subscribers.forEach(function (fiber) {
if (fiber.setState) {
fiber.setState({
value: newValue
});
fiber = get(fiber);
}
Renderer.updateComponent(fiber, true);
});
}
}
}
},
render: function render() {
return this.props.children;
}
}
);
var Consumer = miniCreateClass(
function Consumer() {
instance.subscribers.push(this);
this.observedBits = 0;
this.state = {
value: instance.value
};
},
Component,
{
componentWillUnmount: function componentWillUnmount() {
var i = instance.subscribers.indexOf(this);
instance.subscribers.splice(i, 1);
},
render: function render() {
return this.props.children(getContext(get(this)));
}
}
);
function getContext(fiber) {
while (fiber['return']) {
if (fiber.type == Provider) {
return instance.value;
}
fiber = fiber['return'];
}
return defaultValue;
}
getContext.subscribers = [];
getContext.Provider = Provider;
getContext.Consumer = Consumer;
return getContext;
}
function findHostInstance(fiber) {
if (!fiber) {
return null;
} else if (fiber.nodeType) {
return fiber;
} else if (fiber.tag > 3) {
return fiber.stateNode;
} else if (fiber.tag < 3) {
return findHostInstance(fiber.stateNode);
} else if (fiber.refs && fiber.render) {
fiber = get(fiber);
var childrenMap = fiber.children;
if (childrenMap) {
for (var i in childrenMap) {
var dom = findHostInstance(childrenMap[i]);
if (dom) {
return dom;
}
}
}
}
return null;
}
function findDOMNode(fiber) {
if (fiber == null) {
return null;
}
if (fiber.nodeType === 1) {
return fiber;
}
if (!fiber.render) {
throw 'findDOMNode:invalid type';
}
return findHostInstance(fiber);
}
function DOMElement(type) {
this.nodeName = type;
this.style = {};
this.children = [];
}
var NAMESPACE = {
svg: 'http://www.w3.org/2000/svg',
xmlns: 'http://www.w3.org/2000/xmlns/',
xlink: 'http://www.w3.org/1999/xlink',
xhtml: 'http://www.w3.org/1999/xhtml',
math: 'http://www.w3.org/1998/Math/MathML'
};
var fn = (DOMElement.prototype = {
contains: Boolean
});
String(
'replaceChild,appendChild,removeAttributeNS,setAttributeNS,removeAttribute,setAttribute' +
',getAttribute,insertBefore,removeChild,addEventListener,removeEventListener,attachEvent' +
',detachEvent'
).replace(/\w+/g, function (name) {
fn[name] = noop;
});
var fakeDoc = new DOMElement();
fakeDoc.createElement = fakeDoc.createElementNS = fakeDoc.createDocumentFragment = function (type) {
return new DOMElement(type);
};
fakeDoc.createTextNode = fakeDoc.createComment = Boolean;
fakeDoc.documentElement = new DOMElement('html');
fakeDoc.body = new DOMElement('body');
fakeDoc.nodeName = '#document';
fakeDoc.textContent = '';
var win = getWindow();
var inBrowser = !!win.alert;
if (!inBrowser) {
win.document = fakeDoc;
}
var document = win.document;
var versions = {
88: 7,
80: 6,
'00': NaN,
'08': NaN
};
var msie = document.documentMode || versions[typeNumber(document.all) + '' + typeNumber(win.XMLHttpRequest)];
var modern = /NaN|undefined/.test(msie) || msie > 8;
function contains(a, b) {
if (b) {
while ((b = b.parentNode)) {
if (b === a) {
return true;
}
}
}
return false;
}
var rnumber = /^-?\d+(\.\d+)?$/;
function patchStyle(dom, lastStyle, nextStyle) {
if (lastStyle === nextStyle) {
return;
}
for (var name in nextStyle) {
var val = nextStyle[name];
if (lastStyle[name] !== val) {
name = cssName(name, dom);
if (val !== 0 && !val) {
val = '';
} else if (rnumber.test(val) && !cssNumber[name]) {
val = val + 'px';
}
try {
dom.style[name] = val;
} catch (e) {
console.log('dom.style[' + name + '] = ' + val + 'throw error');
}
}
}
for (var _name in lastStyle) {
if (!(_name in nextStyle)) {
_name = cssName(_name, dom);
dom.style[_name] = '';
}
}
}
var cssNumber = oneObject(
'animationIterationCount,columnCount,order,flex,flexGrow,flexShrink,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom,WebkitLineClamp'
);
var prefixes = ['', '-webkit-', '-o-', '-moz-', '-ms-'];
var cssMap = oneObject('float', 'cssFloat');
function cssName(name, dom) {
if (cssMap[name]) {
return cssMap[name];
}
var host = (dom && dom.style) || {};
for (var i = 0, n = prefixes.length; i < n; i++) {
var camelCase = camelize(prefixes[i] + name);
if (camelCase in host) {
return (cssMap[name] = camelCase);
}
}
return null;
}
function getSafeValue(value) {
switch (typeNumber(value)) {
case 2:
case 3:
case 8:
case 4:
case 0:
return value;
default:
return '';
}
}
var duplexMap = {
input: {
init: function init(node, props) {
var defaultValue = props.defaultValue == null ? '' : props.defaultValue;
return (node._wrapperState = {
initialValue: getSafeValue(props.value != null ? props.value : defaultValue)
});
},
mount: function mount(node, props, state) {
if (props.hasOwnProperty('value') || props.hasOwnProperty('defaultValue')) {
var stateValue = '' + state.initialValue;
if (node.value === '' && node.value !== stateValue) {
syncValue(node, 'value', stateValue);
}
node.defaultValue = stateValue;
}
var name = node.name;
if (name !== '') {
node.name = '';
}
node.defaultChecked = !node.defaultChecked;
node.defaultChecked = !node.defaultChecked;
if (name !== '') {
node.name = name;
}
},
update: function update(node, props) {
if (props.checked != null) {
syncValue(node, 'checked', !!props.checked);
}
var isActive = node === node.ownerDocument.activeElement;
var value = getSafeValue(props.value);
if (value != null) {
if (props.type === 'number') {
if ((value === 0 && node.value === '') || node.value != value) {
syncValue(node, 'value', '' + value);
}
} else if (node.value !== '' + value) {
syncValue(node, 'value', '' + value);
}
}
if (props.hasOwnProperty('value')) {
setDefaultValue(node, props.type, value, isActive);
} else if (props.hasOwnProperty('defaultValue')) {
setDefaultValue(node, props.type, getSafeValue(props.defaultValue), isActive);
}
if (props.checked == null && props.defaultChecked != null) {
node.defaultChecked = !!props.defaultChecked;
}
}
},
select: {
init: function init(node, props) {
var value = props.value;
return (node._wrapperState = {
initialValue: value != null ? value : props.defaultValue,
wasMultiple: !!props.multiple
});
},
mount: function mount(node, props) {
var multiple = (node.multiple = !!props.multiple);
var value = props.value;
if (value != null) {
updateOptions(node, multiple, value, false);
} else if (props.defaultValue != null) {
updateOptions(node, multiple, props.defaultValue, true);
}
},
update: function update(node, props) {
node._wrapperState.initialValue = void 666;
var wasMultiple = node._wrapperState.wasMultiple;
var multiple = (node._wrapperState.wasMultiple = !!props.multiple);
var value = props.value;
if (value != null) {
updateOptions(node, multiple, value, false);
} else if (wasMultiple !== multiple) {
if (props.defaultValue != null) {
updateOptions(node, multiple, props.defaultValue, true);
} else {
updateOptions(node, multiple, multiple ? [] : '', false);
}
}
}
},
textarea: {
init: function init(node, props) {
var initialValue = props.value;
if (initialValue == null) {
var defaultValue = props.defaultValue;
var children = props.children;
if (children != null) {
defaultValue = textContent(node);
node.innerHTML = '';
}
if (defaultValue == null) {
defaultValue = '';
}
initialValue = defaultValue;
}
return (node._wrapperState = {
initialValue: '' + initialValue
});
},
mount: function mount(node, props, state) {
var text = textContent(node);
var stateValue = '' + state.initialValue;
if (text !== stateValue) {
syncValue(node, 'value', stateValue);
}
},
update: function update(node, props) {
var value = props.value;
if (value != null) {
var newValue = '' + value;
if (newValue !== node.value) {
syncValue(node, 'value', newValue);
}
if (props.defaultValue == null) {
node.defaultValue = newValue;
}
}
if (props.defaultValue != null) {
node.defaultValue = props.defaultValue;
}
}
},
option: {
init: function init() {},
update: function update(node, props) {
duplexMap.option.mount(node, props);
},
mount: function mount(node, props) {
var elems = node.getElementsByTagName('*');
var n = elems.length,
el;
if (n) {
for (n = n - 1, el; (el = elems[n--]); ) {
node.removeChild(el);
}
}
if ('value' in props) {
node.duplexValue = node.value = props.value;
} else {
node.duplexValue = node.text;
}
}
}
};
function textContent(node) {
return node.textContent || node.innerText;
}
function setDefaultValue(node, type, value, isActive) {
if (type !== 'number' || !isActive) {
if (value == null) {
node.defaultValue = '' + node._wrapperState.initialValue;
} else if (node.defaultValue !== '' + value) {
node.defaultValue = '' + value;
}
}
}
function updateOptions(node, multiple, propValue, setDefaultSelected) {
var options = node.options;
if (multiple) {
var selectedValues = propValue;
var selectedValue = {};
for (var i = 0; i < selectedValues.length; i++) {
selectedValue['$' + selectedValues[i]] = true;
}
for (var _i = 0; _i < options.length; _i++) {
var selected = selectedValue.hasOwnProperty('$' + options[_i].duplexValue);
if (options[_i].selected !== selected) {
options[_i].selected = selected;
}
if (selected && setDefaultSelected) {
options[_i].defaultSelected = true;
}
}
} else {
var _selectedValue = '' + propValue;
var defaultSelected = null;
for (var _i2 = 0; _i2 < options.length; _i2++) {
if (options[_i2].duplexValue === _selectedValue) {
options[_i2].selected = true;
if (setDefaultSelected) {
options[_i2].defaultSelected = true;
}
return;
}
if (defaultSelected === null && !options[_i2].disabled) {
defaultSelected = options[_i2];
}
}
if (defaultSelected !== null) {
defaultSelected.selected = true;
}
}
}
function syncValue(dom, name, value) {
dom.__anuSetValue = true;
dom[name] = value;
dom.__anuSetValue = false;
}
function duplexAction(fiber) {
var dom = fiber.stateNode,
name = fiber.name,
props = fiber.props,
lastProps = fiber.lastProps;
var fns = duplexMap[name];
if (name !== 'option') {
enqueueDuplex(dom);
}
if (!lastProps || lastProps == emptyObject) {
var state = fns.init(dom, props);
fns.mount(dom, props, state);
} else {
fns.update(dom, props);
}
}
var duplexNodes = [];
function enqueueDuplex(dom) {
if (duplexNodes.indexOf(dom) == -1) {
duplexNodes.push(dom);
}
}
function fireDuplex() {
var radioMap = {};
if (duplexNodes.length) {
do {
var dom = duplexNodes.shift();
var e = dom.__events;
var fiber = e && e.vnode;
if (fiber && !fiber.disposed) {
var props = fiber.props;
var tag = fiber.name;
if (name === 'select') {
var value = props.value;
if (value != null) {
updateOptions(dom, !!props.multiple, value, false);
}
} else {
duplexMap[tag].update(dom, props);
var _name = props.name;
if (props.type === 'radio' && _name != null && !radioMap[_name]) {
radioMap[_name] = 1;
collectNamedCousins(dom, _name);
}
}
}
} while (duplexNodes.length);
}
}
function collectNamedCousins(rootNode, name) {
var queryRoot = rootNode;
while (queryRoot.parentNode) {
queryRoot = queryRoot.parentNode;
}
var group = queryRoot.getElementsByTagName('input');
for (var i = 0; i < group.length; i++) {
var otherNode = group[i];
if (
otherNode === rootNode ||
otherNode.name !== name ||
otherNode.type !== 'radio' ||
otherNode.form !== rootNode.form
) {
continue;
}
enqueueDuplex(otherNode);
}
}
var rform = /textarea|input|select|option/i;
var globalEvents = {};
var eventPropHooks = {};
var eventHooks = {};
var eventLowerCache = {
onClick: 'click',
onChange: 'change',
onWheel: 'wheel'
};
function eventAction(dom, name, val, lastProps, fiber) {
var events = dom.__events || (dom.__events = {});
events.vnode = fiber;
var refName = toLowerCase(name.slice(2));
if (val === false) {
delete events[refName];
} else {
if (!lastProps[name]) {
var eventName = getBrowserName(name);
var hook = eventHooks[eventName];
if (hook) {
hook(dom, eventName);
}
addGlobalEvent(eventName);
}
events[refName] = val;
}
}
var isTouch = 'ontouchstart' in document;
function dispatchEvent(e, type, endpoint) {
e = new SyntheticEvent(e);
if (type) {
e.type = type;
}
var bubble = e.type,
terminal = endpoint || document,
hook = eventPropHooks[e.type];
if (hook && false === hook(e)) {
return;
}
Renderer.batchedUpdates(function () {
var paths = collectPaths(e.target, terminal, {});
var captured = bubble + 'capture';
triggerEventFlow(paths, captured, e);
if (!e._stopPropagation) {
triggerEventFlow(paths.reverse(), bubble, e);
}
}, e);
}
var nodeID = 1;
function collectPaths(begin, end, unique) {
var paths = [];
var node = begin;
while (node && node.nodeType == 1) {
var checkChange = node;
if (node.__events) {
var vnode = node.__events.vnode;
inner: while (vnode['return']) {
if (vnode.tag === 5) {
node = vnode.stateNode;
if (node === end) {
return paths;
}
if (!node) {
break inner;
}
var uid = node.uniqueID || (node.uniqueID = ++nodeID);
if (node.__events && !unique[uid]) {
unique[uid] = 1;
paths.push({
node: node,
events: node.__events
});
}
}
vnode = vnode['return'];
}
}
if (node === checkChange) {
node = node.parentNode;
}
}
return paths;
}
function triggerEventFlow(paths, prop, e) {
for (var i = paths.length; i--; ) {
var path = paths[i];
var fn = path.events[prop];
if (isFn(fn)) {
e.currentTarget = path.node;
fn.call(void 666, e);
if (e._stopPropagation) {
break;
}
}
}
}
function addGlobalEvent(name, capture) {
if (!globalEvents[name]) {
globalEvents[name] = true;
addEvent(document, name, dispatchEvent, capture);
}
}
function addEvent(el, type, fn, bool) {
if (el.addEventListener) {
el.addEventListener(type, fn, bool || false);
} else if (el.attachEvent) {
el.attachEvent('on' + type, fn);
}
}
var rcapture = /Capture$/;
function getBrowserName(onStr) {
var lower = eventLowerCache[onStr];
if (lower) {
return lower;
}
var camel = onStr.slice(2).replace(rcapture, '');
lower = camel.toLowerCase();
eventLowerCache[onStr] = lower;
return lower;
}
function getRelatedTarget(e) {
if (!e.timeStamp) {
e.relatedTarget = e.type === 'mouseover' ? e.fromElement : e.toElement;
}
return e.relatedTarget;
}
function getTarget(e) {
return e.target || e.srcElement;
}
String('load,error').replace(/\w+/g, function (name) {
eventHooks[name] = function (dom, type) {
var mark = '__' + type;
if (!dom[mark]) {
dom[mark] = true;
addEvent(dom, type, dispatchEvent);
}
};
});
String('mouseenter,mouseleave').replace(/\w+/g, function (name) {
eventHooks[name] = function (dom, type) {
var mark = '__' + type;
if (!dom[mark]) {
dom[mark] = true;
var mask = type === 'mouseenter' ? 'mouseover' : 'mouseout';
addEvent(dom, mask, function (e) {
var t = getRelatedTarget(e);
if (!t || (t !== dom && !contains(dom, t))) {
var common = getLowestCommonAncestor(dom, t);
dispatchEvent(e, type, common);
}
});
}
};
});
var specialHandles = {};
function createHandle(name, fn) {
return (specialHandles[name] = function (e) {
if (fn && fn(e) === false) {
return;
}
dispatchEvent(e, name);
});
}
function onCompositionStart(e) {
e.target.__onComposition = true;
}
function onCompositionUpdate(e) {
e.target.__onComposition = false;
}
function onCompositionEnd(e) {
e.target.__onComposition = false;
}
var input2change = /text|password|search|url|email/i;
if (!document['__input']) {
globalEvents.input = document['__input'] = true;
addEvent(document, 'compositionstart', onCompositionStart);
addEvent(document, 'compositionupdate', onCompositionUpdate);
addEvent(document, 'compositionend', onCompositionEnd);
addEvent(document, 'input', function (e) {
var dom = getTarget(e);
if (input2change.test(dom.type)) {
if (!dom.__onComposition) {
dispatchEvent(e, 'change');
}
}
dispatchEvent(e);
});
}
function getLowestCommonAncestor(instA, instB) {
var depthA = 0;
for (var tempA = instA; tempA; tempA = tempA.parentNode) {
depthA++;
}
var depthB = 0;
for (var tempB = instB; tempB; tempB = tempB.parentNode) {
depthB++;
}
while (depthA - depthB > 0) {
instA = instA.parentNode;
depthA--;
}
while (depthB - depthA > 0) {
instB = instB.parentNode;
depthB--;
}
var depth = depthA;
while (depth--) {
if (instA === instB) {
return instA;
}
instA = instA.parentNode;
instB = instB.parentNode;
}
return null;
}
eventPropHooks.change = function (e) {
enqueueDuplex(e.target);
};
createHandle('doubleclick');
createHandle('scroll');
createHandle('wheel');
globalEvents.wheel = true;
globalEvents.scroll = true;
globalEvents.doubleclick = true;
if (isTouch) {
eventHooks.click = eventHooks.clickcapture = function (dom) {
dom.onclick = dom.onclick || noop;
};
}
eventPropHooks.click = function (e) {
return !e.target.disabled;
};
var fixWheelType =
document.onwheel !== void 666 ? 'wheel' : 'onmousewheel' in document ? 'mousewheel' : 'DOMMouseScroll';
eventHooks.wheel = function (dom) {
addEvent(dom, fixWheelType, specialHandles.wheel);
};
eventPropHooks.wheel = function (event) {
event.deltaX = 'deltaX' in event ? event.deltaX : 'wheelDeltaX' in event ? -event.wheelDeltaX : 0;
event.deltaY =
'deltaY' in event
? event.deltaY
: 'wheelDeltaY' in event
? -event.wheelDeltaY
: 'wheelDelta' in event
? -event.wheelDelta
: 0;
};
var focusMap = {
focus: 'focus',
blur: 'blur'
};
var innerFocus;
function blurFocus(e) {
var dom = getTarget(e);
var type = focusMap[e.type];
if (Renderer.inserting) {
if (type === 'blur') {
innerFocus = true;
Renderer.inserting.focus();
return;
}
}
if (innerFocus) {
innerFocus = false;
return;
}
do {
if (dom.nodeType === 1) {
if (dom.__events && dom.__events[type]) {
dispatchEvent(e, type);
break;
}
} else {
break;
}
} while ((dom = dom.parentNode));
}
'blur,focus'.replace(/\w+/g, function (type) {
globalEvents[type] = true;
if (modern) {
var mark = '__' + type;
if (!document[mark]) {
document[mark] = true;
addEvent(document, type, blurFocus, true);
}
} else {
eventHooks[type] = function (dom, name) {
addEvent(dom, focusMap[name], blurFocus);
};
}
});
eventHooks.scroll = function (dom, name) {
addEvent(dom, name, specialHandles[name]);
};
eventHooks.doubleclick = function (dom, name) {
addEvent(document, 'dblclick', specialHandles[name]);
};
function SyntheticEvent(event) {
if (event.nativeEvent) {
return event;
}
for (var i in event) {
if (!eventProto[i]) {
this[i] = event[i];
}
}
if (!this.target) {
this.target = event.srcElement;
}
this.fixEvent();
this.timeStamp = new Date() - 0;
this.nativeEvent = event;
}
var eventProto = (SyntheticEvent.prototype = {
fixEvent: noop,
fixHooks: noop,
persist: noop,
preventDefault: function preventDefault() {
var e = this.nativeEvent || {};
e.returnValue = this.returnValue = false;
if (e.preventDefault) {
e.preventDefault();
this.defaultPrevented = true;
}
},
stopPropagation: function stopPropagation() {
var e = this.nativeEvent || {};
e.cancelBubble = this._stopPropagation = true;
if (e.stopPropagation) {
e.stopPropagation();
}
},
stopImmediatePropagation: function stopImmediatePropagation() {
this.stopPropagation();
this.stopImmediate = true;
},
toString: function toString() {
return '[object Event]';
}
});
Renderer.eventSystem = {
eventPropHooks: eventPropHooks,
addEvent: addEvent,
dispatchEvent: dispatchEvent,
SyntheticEvent: SyntheticEvent
};
var NOWORK = 1;
var WORKING = 2;
var PLACE = 3;
var CONTENT = 5;
var ATTR = 7;
var DUPLEX = 11;
var DETACH = 13;
var HOOK = 17;
var REF = 19;
var CALLBACK = 23;
var PASSIVE = 29;
var CAPTURE = 31;
var effect