var allDescriptors=[];var applicationDescriptor;var _loadedScripts={};function loadResource(url)
{var xhr=new XMLHttpRequest();xhr.open("GET",url,false);try{xhr.send(null);}catch(e){console.error(url+" -> "+new Error().stack);throw e;}
return xhr.status<400?xhr.responseText:"";}
function normalizePath(path)
{if(path.indexOf("..")===-1&&path.indexOf('.')===-1)
return path;var normalizedSegments=[];var segments=path.split("/");for(var i=0;i<segments.length;i++){var segment=segments[i];if(segment===".")
continue;else if(segment==="..")
normalizedSegments.pop();else if(segment)
normalizedSegments.push(segment);}
var normalizedPath=normalizedSegments.join("/");if(normalizedPath[normalizedPath.length-1]==="/")
return normalizedPath;if(path[0]==="/"&&normalizedPath)
normalizedPath="/"+normalizedPath;if((path[path.length-1]==="/")||(segments[segments.length-1]===".")||(segments[segments.length-1]===".."))
normalizedPath=normalizedPath+"/";return normalizedPath;}
function loadScript(scriptName)
{var sourceURL=self._importScriptPathPrefix+scriptName;var schemaIndex=sourceURL.indexOf("://")+3;sourceURL=sourceURL.substring(0,schemaIndex)+normalizePath(sourceURL.substring(schemaIndex));if(_loadedScripts[sourceURL])
return;_loadedScripts[sourceURL]=true;var scriptSource=loadResource(sourceURL);if(!scriptSource){console.error("Empty response arrived for script '"+sourceURL+"'");return;}
var oldPrefix=self._importScriptPathPrefix;self._importScriptPathPrefix+=scriptName.substring(0,scriptName.lastIndexOf("/")+1);try{self.eval(scriptSource+"\n//# sourceURL="+sourceURL);}finally{self._importScriptPathPrefix=oldPrefix;}}
(function(){var baseUrl=self.location?self.location.origin+self.location.pathname:"";self._importScriptPathPrefix=baseUrl.substring(0,baseUrl.lastIndexOf("/")+1);})();var Runtime=function()
{this._modules=[];this._modulesMap={};this._extensions=[];this._cachedTypeClasses={};this._descriptorsMap={};for(var i=0;i<allDescriptors.length;++i)
this._descriptorsMap[allDescriptors[i]["name"]]=allDescriptors[i];}
Runtime._queryParamsObject={__proto__:null};Runtime.isReleaseMode=function()
{return!!allDescriptors.length;}
Runtime.startSharedWorker=function(moduleName,workerName)
{if(Runtime.isReleaseMode())
return new SharedWorker(moduleName+"_module.js",workerName);var content=loadResource(moduleName+"/module.json");if(!content)
throw new Error("Worker is not defined: "+moduleName+" "+new Error().stack);var scripts=JSON.parse(content)["scripts"];if(scripts.length!==1)
throw Error("Runtime.startSharedWorker supports modules with only one script!");return new SharedWorker(moduleName+"/"+scripts[0],workerName);}
Runtime.startWorker=function(moduleName)
{if(Runtime.isReleaseMode())
return new Worker(moduleName+"_module.js");var content=loadResource(moduleName+"/module.json");if(!content)
throw new Error("Worker is not defined: "+moduleName+" "+new Error().stack);var message=[];var scripts=JSON.parse(content)["scripts"];for(var i=0;i<scripts.length;++i){var url=self._importScriptPathPrefix+moduleName+"/"+scripts[i];var parts=url.split("://");url=parts.length===1?url:parts[0]+"://"+normalizePath(parts[1]);message.push({source:loadResource(moduleName+"/"+scripts[i]),url:url});}
var loader=function(){self.onmessage=function(event){self.onmessage=null;var scripts=event.data;for(var i=0;i<scripts.length;++i){var source=scripts[i]["source"];self.eval(source+"\n//# sourceURL="+scripts[i]["url"]);}};};var blob=new Blob(["("+loader.toString()+")()\n//# sourceURL="+moduleName],{type:"text/javascript"});var workerURL=window.URL.createObjectURL(blob);try{var worker=new Worker(workerURL);worker.postMessage(message);return worker;}finally{window.URL.revokeObjectURL(workerURL);}}
Runtime.startApplication=function(appName)
{console.timeStamp("Runtime.startApplication");var experiments=Runtime._experimentsSetting();var allDescriptorsByName={};for(var i=0;Runtime.isReleaseMode()&&i<allDescriptors.length;++i){var d=allDescriptors[i];allDescriptorsByName[d["name"]]=d;}
var moduleDescriptors=applicationDescriptor||Runtime._parseJsonURL(appName+".json");var allModules=[];var coreModuleNames=[];moduleDescriptors.forEach(populateModules);function populateModules(desc)
{if(!isActive(desc))
return;var name=desc.name;var moduleJSON=allDescriptorsByName[name];if(!moduleJSON){moduleJSON=Runtime._parseJsonURL(name+"/module.json");moduleJSON["name"]=name;}
allModules.push(moduleJSON);if(desc["type"]==="autostart")
coreModuleNames.push(name);}
function isActive(descriptor)
{var activatorExperiment=descriptor["experiment"];if(activatorExperiment){var shouldBePresent=activatorExperiment.charAt(0)!=="!";if(!shouldBePresent)
activatorExperiment=activatorExperiment.substr(1);if(!!experiments[activatorExperiment]!==shouldBePresent)
return false;}
return descriptor["type"]!=="worker";}
Runtime._initializeApplication(allModules);self.runtime.loadAutoStartModules(coreModuleNames);}
Runtime.queryParam=function(name)
{return Runtime._queryParamsObject[name]||null;}
Runtime._experimentsSetting=function()
{try{return(JSON.parse(self.localStorage&&self.localStorage["experiments"]?self.localStorage["experiments"]:"{}"));}catch(e){console.error("Failed to parse localStorage['experiments']");return{};}}
Runtime._initializeApplication=function(descriptors)
{self.runtime=new Runtime();var names=[];for(var i=0;i<descriptors.length;++i){var name=descriptors[i]["name"];self.runtime._descriptorsMap[name]=descriptors[i];names.push(name);}
self.runtime._registerModules(names);}
Runtime._parseJsonURL=function(url)
{var json=loadResource(url);if(!json)
throw new Error("Resource not found at "+url+" "+new Error().stack);return JSON.parse(json);}
Runtime.prototype={_registerModules:function(configuration)
{for(var i=0;i<configuration.length;++i)
this._registerModule(configuration[i]);},_registerModule:function(moduleName)
{if(!this._descriptorsMap[moduleName]){var content=loadResource(moduleName+"/module.json");if(!content)
throw new Error("Module is not defined: "+moduleName+" "+new Error().stack);var module=(self.eval("("+content+")"));module["name"]=moduleName;this._descriptorsMap[moduleName]=module;}
var module=new Runtime.Module(this,this._descriptorsMap[moduleName]);this._modules.push(module);this._modulesMap[moduleName]=module;},loadModule:function(moduleName)
{this._modulesMap[moduleName]._load();},loadAutoStartModules:function(moduleNames)
{for(var i=0;i<moduleNames.length;++i){if(Runtime.isReleaseMode())
self.runtime._modulesMap[moduleNames[i]]._loaded=true;else
self.runtime.loadModule(moduleNames[i]);}},_checkExtensionApplicability:function(extension,predicate)
{if(!predicate)
return false;var contextTypes=(extension.descriptor().contextTypes);if(!contextTypes)
return true;for(var i=0;i<contextTypes.length;++i){var contextType=this._resolve(contextTypes[i]);var isMatching=!!contextType&&predicate(contextType);if(isMatching)
return true;}
return false;},isExtensionApplicableToContext:function(extension,context)
{if(!context)
return true;return this._checkExtensionApplicability(extension,isInstanceOf);function isInstanceOf(targetType)
{return context instanceof targetType;}},isExtensionApplicableToContextTypes:function(extension,currentContextTypes)
{if(!extension.descriptor().contextTypes)
return true;for(var i=0;i<currentContextTypes.length;++i)
currentContextTypes[i]["__applicable"]=true;var result=this._checkExtensionApplicability(extension,currentContextTypes?isContextTypeKnown:null);for(var i=0;i<currentContextTypes.length;++i)
delete currentContextTypes[i]["__applicable"];return result;function isContextTypeKnown(targetType)
{return!!targetType["__applicable"];}},extensions:function(type,context)
{function filter(extension)
{if(extension._type!==type&&extension._typeClass()!==type)
return false;var activatorExperiment=extension.descriptor()["experiment"];if(activatorExperiment&&!Runtime.experiments.isEnabled(activatorExperiment))
return false;return!context||extension.isApplicable(context);}
return this._extensions.filter(filter);},extension:function(type,context)
{return this.extensions(type,context)[0]||null;},instances:function(type,context)
{function instantiate(extension)
{return extension.instance();}
return this.extensions(type,context).filter(instantiate).map(instantiate);},instance:function(type,context)
{var extension=this.extension(type,context);return extension?extension.instance():null;},orderComparator:function(type,nameProperty,orderProperty)
{var extensions=this.extensions(type);var orderForName={};for(var i=0;i<extensions.length;++i){var descriptor=extensions[i].descriptor();orderForName[descriptor[nameProperty]]=descriptor[orderProperty];}
function result(name1,name2)
{if(name1 in orderForName&&name2 in orderForName)
return orderForName[name1]-orderForName[name2];if(name1 in orderForName)
return-1;if(name2 in orderForName)
return 1;return compare(name1,name2);}
function compare(left,right)
{if(left>right)
return 1;if(left<right)
return-1;return 0;}
return result;},_resolve:function(typeName)
{if(!this._cachedTypeClasses[typeName]){var path=typeName.split(".");var object=window;for(var i=0;object&&(i<path.length);++i)
object=object[path[i]];if(object)
this._cachedTypeClasses[typeName]=(object);}
return this._cachedTypeClasses[typeName];}}
Runtime.ModuleDescriptor=function()
{this.name;this.extensions;this.dependencies;this.scripts;}
Runtime.ExtensionDescriptor=function()
{this.type;this.className;this.contextTypes;}
Runtime.Module=function(manager,descriptor)
{this._manager=manager;this._descriptor=descriptor;this._name=descriptor.name;var extensions=(descriptor.extensions);for(var i=0;extensions&&i<extensions.length;++i)
this._manager._extensions.push(new Runtime.Extension(this,extensions[i]));this._loaded=false;}
Runtime.Module.prototype={name:function()
{return this._name;},_load:function()
{if(this._loaded)
return;if(this._isLoading){var oldStackTraceLimit=Error.stackTraceLimit;Error.stackTraceLimit=50;console.assert(false,"Module "+this._name+" is loaded from itself: "+new Error().stack);Error.stackTraceLimit=oldStackTraceLimit;return;}
this._isLoading=true;var dependencies=this._descriptor.dependencies;for(var i=0;dependencies&&i<dependencies.length;++i)
this._manager.loadModule(dependencies[i]);if(this._descriptor.scripts){if(Runtime.isReleaseMode()){loadScript(this._name+"_module.js");}else{var scripts=this._descriptor.scripts;for(var i=0;i<scripts.length;++i)
loadScript(this._name+"/"+scripts[i]);}}
this._isLoading=false;this._loaded=true;}}
Runtime.Extension=function(module,descriptor)
{this._module=module;this._descriptor=descriptor;this._type=descriptor.type;this._hasTypeClass=this._type.charAt(0)==="@";this._className=descriptor.className||null;}
Runtime.Extension.prototype={descriptor:function()
{return this._descriptor;},module:function()
{return this._module;},_typeClass:function()
{if(!this._hasTypeClass)
return null;return this._module._manager._resolve(this._type.substring(1));},isApplicable:function(context)
{return this._module._manager.isExtensionApplicableToContext(this,context);},instance:function()
{if(!this._className)
return null;if(!this._instance){this._module._load();var constructorFunction=window.eval(this._className);if(!(constructorFunction instanceof Function))
return null;this._instance=new constructorFunction();}
return this._instance;}}
Runtime.ExperimentsSupport=function()
{this._supportEnabled=Runtime.queryParam("experiments")!==null;this._experiments=[];this._experimentNames={};this._enabledTransiently={};}
Runtime.ExperimentsSupport.prototype={allExperiments:function()
{return this._experiments.slice();},supportEnabled:function()
{return this._supportEnabled;},_setExperimentsSetting:function(value)
{if(!self.localStorage)
return;self.localStorage["experiments"]=JSON.stringify(value);},register:function(experimentName,experimentTitle,hidden)
{console.assert(!this._experimentNames[experimentName],"Duplicate registration of experiment "+experimentName);this._experimentNames[experimentName]=true;this._experiments.push(new Runtime.Experiment(this,experimentName,experimentTitle,!!hidden));},isEnabled:function(experimentName)
{this._checkExperiment(experimentName);if(this._enabledTransiently[experimentName])
return true;if(!this.supportEnabled())
return false;return!!Runtime._experimentsSetting()[experimentName];},setEnabled:function(experimentName,enabled)
{this._checkExperiment(experimentName);if(!enabled)
delete this._enabledTransiently[experimentName];var experimentsSetting=Runtime._experimentsSetting();experimentsSetting[experimentName]=enabled;this._setExperimentsSetting(experimentsSetting);},setDefaultExperiments:function(experimentNames)
{for(var i=0;i<experimentNames.length;++i){this._checkExperiment(experimentNames[i]);this._enabledTransiently[experimentNames[i]]=true;}},enableForTest:function(experimentName)
{this._checkExperiment(experimentName);this._enabledTransiently[experimentName]=true;},cleanUpStaleExperiments:function()
{var experimentsSetting=Runtime._experimentsSetting();var cleanedUpExperimentSetting={};for(var i=0;i<this._experiments.length;++i){var experimentName=this._experiments[i].name;if(experimentsSetting[experimentName])
cleanedUpExperimentSetting[experimentName]=true;}
this._setExperimentsSetting(cleanedUpExperimentSetting);},_checkExperiment:function(experimentName)
{console.assert(this._experimentNames[experimentName],"Unknown experiment "+experimentName);}}
Runtime.Experiment=function(experiments,name,title,hidden)
{this.name=name;this.title=title;this.hidden=hidden;this._experiments=experiments;}
Runtime.Experiment.prototype={isEnabled:function()
{return this._experiments.isEnabled(this.name);},setEnabled:function(enabled)
{this._experiments.setEnabled(this.name,enabled);}}
{(function parseQueryParameters()
{var queryParams=location.search;if(!queryParams)
return;var params=queryParams.substring(1).split("&");for(var i=0;i<params.length;++i){var pair=params[i].split("=");Runtime._queryParamsObject[pair[0]]=pair[1];}
var settingsParam=Runtime.queryParam("settings");if(settingsParam){try{var settings=JSON.parse(window.decodeURI(settingsParam));for(var key in settings)
window.localStorage[key]=settings[key];}catch(e){}}})();}
Runtime.experiments=new Runtime.ExperimentsSupport();var runtime;var ports=[];var isTempStorageCleared=false;var tempStorageError;self.onconnect=function(event)
{var newPort=(event.ports[0]);if(isTempStorageCleared){notifyTempStorageCleared(newPort);return;}
newPort.onmessage=handleMessage;newPort.onerror=handleError;ports.push(newPort);if(ports.length===1)
clearTempStorage();}
function clearTempStorage()
{function didFail(e)
{tempStorageError="Failed to clear temp storage: "+e.message+" "+e.name;console.error(tempStorageError);didClearTempStorage();}
function didGetFS(fs)
{fs.root.createReader().readEntries(didReadEntries,didFail);}
function didReadEntries(entries)
{var remainingEntries=entries.length;if(!remainingEntries){didClearTempStorage();return;}
function didDeleteEntry()
{if(!--remainingEntries)
didClearTempStorage();}
function failedToDeleteEntry(e)
{tempStorageError="Failed to delete entry: "+e.message+" "+e.name;console.error(tempStorageError);didDeleteEntry();}
for(var i=0;i<entries.length;i++){var entry=entries[i];if(entry.isFile)
entry.remove(didDeleteEntry,failedToDeleteEntry);else
entry.removeRecursively(didDeleteEntry,failedToDeleteEntry);}}
self.webkitRequestFileSystem(self.TEMPORARY,10,didGetFS,didFail);}
function didClearTempStorage()
{isTempStorageCleared=true;for(var i=0;i<ports.length;i++)
notifyTempStorageCleared(ports[i]);ports=null;}
function notifyTempStorageCleared(port)
{port.postMessage({type:"tempStorageCleared",error:tempStorageError});}
function handleMessage(event)
{if(event.data.type==="disconnect")
removePort(event.target);}
function handleError(event)
{console.error("Error: "+event.data);removePort(event.target);}
function removePort(port)
{if(!ports)
return;var index=ports.indexOf(port);ports.splice(index,1);};