├── .gitignore
├── README.md
├── bower.json
├── dist
├── kvm-plugins.js
├── kvm-plugins.min.js
├── kvm.js
└── kvm.min.js
├── gulpfile.js
├── logo.png
├── package.json
├── plugins
├── alias.js
├── commonjs.js
├── css.js
├── json.js
├── package.js
├── shim.js
└── tmpl.js
├── src
├── core.js
├── emitter.js
├── kvm.js
└── utils.js
└── test
├── all.html
├── base.html
└── modules
├── amd
├── a.js
├── b.js
└── c-ab.js
├── commonjs
└── a.js
└── shim
└── a.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | .tmp
3 | .svn
4 | .DS_Store
5 | node_modules
6 | app/bower_components
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | KVM.js 模块管理器(v0.2.0),带给你不一样的模块管理体验
4 |
5 | 支持AMD,CMD规范,支持依赖注入,支持插件式加载脚本
6 |
7 | >如果你需要做一个浏览器书签,或者chrome插件,或者第三方组件,对于嵌入到对方网站上的情况,
8 | >你不能保证对方是否已经存在有你所依赖的相关库,这样就可能存在浪费资源的情况,所以我添加了冲突检测机制
9 | >使得该加载器更加智能化
10 |
11 | #bower安装
12 |
13 | ```
14 | bower install kvm
15 | ```
16 |
17 |
18 | #更新日志
19 |
20 | v0.2.0
21 | ===
22 | * 修复commonjs在safari下的性能问题
23 | * ES6重构,兼容至IE9
24 | * 将插件全部作为独立包
25 | * 支持在路径中直接添加querystring或者hashstring来作为版本迭代指令或者第三方插件指令
26 |
27 | v0.1.5
28 | ===
29 | * 重构,将内部模块解耦,以Promise为核心,可通过模块返回Promise对象来延迟加载依赖
30 | * 依赖可以依赖css,在querystring中使用media="xxxx"可以控制响应式样式表范围
31 | * 添加了插件模式,可以随意的给kvm添加各种插件
32 |
33 | v0.1.0
34 | ===
35 |
36 | * 已做添加包管理机制
37 | * 已添加cmd规范支持
38 | * 性能提升,实测为requirejs的2倍多
39 | * 因为维护时间有限,已经放弃mini版本的维护,非常抱歉.
40 |
41 |
42 | #API接口
43 |
44 | KVM.module
45 |
46 | * KVM.module.define 定义模块,这里,全局define也可以定义模块
47 |
48 | ```
49 | define([dep1,dep2,....],function(dep1,dep2,...){ //定义匿名模块
50 |
51 | })
52 | define([dep1,dep2,....,function(dep1,dep2,...){ //定义匿名模块,angular风格
53 |
54 | }])
55 | define(function(){ //定义匿名模块,无依赖
56 |
57 | })
58 | define(["require","exports","module"],function(require,exports,module){//commonjs风格
59 | var depA = require("depA");
60 |
61 | module.exports = function(){
62 | return depA.fun();
63 | };
64 |
65 | or
66 |
67 | exports.fun = function(){
68 | return depA.fun();
69 | };
70 | })
71 | 定义id模块,id就是模块路径
72 | define(id,后面的和匿名定义模块一样)
73 |
74 | 定义注入的依赖
75 |
76 | define(id,deps,facotry,injectors)
77 |
78 | injectors的规范:
79 | {
80 | module_id:[dep1,dep2,dep3,...,fucntion(dep1,dep2,dep3){//这里可以是数组也可以是函数,随便你怎样搞
81 |
82 | }]
83 | }
84 |
85 | ```
86 |
87 | * KVM.module.invoke 调用模块
88 |
89 | ```
90 | KVM.module.invoke('{module id}',injectors) //调用模块,可以指定模块路径,injectors是临时注入的依赖,同时它也能依赖其他模块
91 | KVM.module.invoke([dep1,dep2,...,function(dep1,dep2,...){ //调用匿名模块,通常用于临时将某些依赖合并使用
92 |
93 | }],injectors);
94 |
95 | injectors的规范:
96 | {
97 | module_id:[dep1,dep2,dep3,...,fucntion(dep1,dep2,dep3){//这里可以是数组也可以是函数,随便你怎样搞
98 |
99 | }]
100 | }
101 |
102 | invoke调用后返回的结果是一个promise对象,所以通过then可以获得模块的实例
103 |
104 | ```
105 |
106 | * KVM.module.use 使用某一模块,功能单一,没有注入依赖的功能
107 |
108 | ```
109 | KVM.module.use('id',function(instance){//仅仅只能使用id来调用,不能像invoke一样调用一个匿名工厂
110 |
111 | });
112 |
113 | ```
114 |
115 | * KVM.module.config 参数配置
116 |
117 | ```
118 | KVM.module.config(options);
119 |
120 | options = {
121 | baseUrl:"",//项目基础路径,这个对于按需加载应用来说是必须要配置
122 | shims:{//模块包装器,主要是为了兼容第三方模块
123 | angular:{
124 | url:"",
125 | facotry:[deps,function(){//这里定义facotry可以是数组也可以是函数,随便你怎样搞
126 | return angular
127 | }],
128 | exports:"$"//该字段针对于注入到全局作用域的第三方组件的组件名,可以用其替代factory,也能自动检测冲突,比如该例子,如果$存在于全局域中,系统就不会再请求脚本了
129 | }
130 | },
131 | vars:{
132 | mod:"./modules",
133 | hello:"{mod}/hello"//变量中可以互相重用
134 | },
135 | alias:{//路径别名,就是为了懒人准备的
136 | player:"{mod}/Player"//这样映射后每次依赖的时候就不需要每次都使用长长的路径id了,同时还支持别名路径的重用,通过使用{}语法来链接vars中的属性
137 | },
138 | packages:{//包管理机制
139 | packageName:{
140 | url:""//包路径
141 | }
142 | }
143 | }
144 | ```
145 |
146 | * KVM.module.data 返回当前配置
147 |
148 | ```
149 | KVM.module.data(name);如果name为空返回所有配置,如果name不为空则返回相应的配置项
150 |
151 | ```
152 |
153 | KVM.isArray 判断是否是数组
154 |
155 |
156 | KVM.isString 判断是否是字符串
157 |
158 |
159 | KVM.isObject 判断是否是对象,这个对象不包括数组
160 |
161 |
162 | KVM.isFunction 判断是否是函数
163 |
164 |
165 | KVM.isBoolean 判断是否是布尔值
166 |
167 |
168 | KVM.isReference 判断是否是引用类型
169 |
170 |
171 | KVM.isValue 判断是否是值类型
172 |
173 |
174 | KVM.isEmpty 判断对象是否为空,可以判断数组也可以判断对象
175 |
176 |
177 | ###内置模块接口
178 |
179 |
180 | ####$emitter 事件分发器
181 |
182 | ```
183 | var event = new $emitter(cache/*外部缓存事件队列*/);
184 |
185 | event.$on(“eventName”,callback) 注册事件
186 |
187 | event.$emit("eventName",param1,param2,....) 触发事件
188 |
189 | event.$remove("eventName",callback) 删除事件
190 |
191 | event.$one("eventName",callback) 注册事件,对于一个事件名只能注册一个事件处理器
192 |
193 | ```
194 |
195 | ###插件接口
196 |
197 | ```
198 |
199 | kvm.module.registerPlugin(function(interface){
200 | ....
201 | });
202 |
203 | 这是相关暴露出来的插件接口
204 |
205 | let PluginInterface = {
206 | registerModuleParser: Module.registerModuleParser,//用于模块解析,参造commonjs插件
207 |
208 | registerDriverLoader: Driver.registerDriverLoader,//用于各种加载驱动程序
209 | registerDriverLoaded: Driver.registerDriverLoaded,//驱动加载后的回调
210 | registerDriverBeforeLoad: Driver.registerDriverBeforeLoad,//驱动加载前的回调
211 |
212 | registerFileExtParser: Path.registerFileExtParser,//文件后缀解析器
213 | registerPathParser: Path.registerPathParser,//路径解析器
214 | registerPathMaper: Path.registerPathMaper,//路径映射解析器
215 |
216 | createModule: Module.createModule,//创建一个模块
217 | createPath: Path.createPath//创建一个path
218 | };
219 |
220 | ```
221 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "kvm.js",
3 | "version": "0.1.0",
4 | "homepage": "https://github.com/janryWang/kvm",
5 | "authors": [
6 | "白玄 "
7 | ],
8 | "description": "一款兼容AMD,AMD,angular模块规范同时支持依赖注入的模块管理器",
9 | "main": "./dist/kvm.min.js",
10 | "license": "MIT",
11 | "ignore": [
12 | "**/.*",
13 | "node_modules",
14 | "bower_components",
15 | "app/bower_components",
16 | "test",
17 | "tests"
18 | ]
19 | }
20 |
--------------------------------------------------------------------------------
/dist/kvm-plugins.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 可以使kvm支持别名机制
3 | */
4 | (function(){
5 | kvm.module.registerPlugin(function(API){
6 | API.registerPathMaper(function(){
7 | var alias = kvm.module.data('alias');
8 | if(kvm.isAbsolutePath(this.id)) return;
9 | if(alias[this.id]){
10 | this.uri = alias[this.id];
11 | this._parser();
12 | }
13 | });
14 | });
15 | })();
16 |
17 | /**
18 | * 可以使kvm支持commonjs规范
19 | */
20 |
21 | (function(){
22 |
23 | kvm.module.registerPlugin(function(API){
24 | API.registerModuleParser(function(){
25 | function uniquePath(paths){
26 | var i,j;
27 | for(i=0;i < paths.length;i++){
28 | for(j=i+1;j < paths.length;j++){
29 | if(paths[i].equal(paths[j])){
30 | paths.splice(j,1);
31 | }
32 | }
33 | }
34 | return paths;
35 | }
36 | this.injectCommonjs = function(){
37 | var _this = this;
38 | this.injectors.exports = function () {
39 | _this.module.exports = _this.module.exports || {};
40 | return _this.module.exports;
41 | };
42 | this.injectors.module = function(){
43 | return _this.module;
44 | };
45 | this.injectors.require = function(){
46 | return function(id){
47 | var path = API.createPath(id);
48 | var module = path.getModule();
49 | return module && module.module && module.module.exports ? module.module.exports : {};
50 | }
51 | };
52 | };
53 | this.collectDeps = function(){
54 | var deps;
55 | if(kvm.isFunction(this.factory)) {
56 | deps = this.parseDependencies(this.factory.toString());
57 | deps = deps.map(function(id){
58 | return API.createPath(id);
59 | });
60 | this.depPaths = uniquePath(this.depPaths.concat(deps));
61 | }
62 | };
63 | this.parseDependencies = function (s) {
64 | if(s.indexOf('require') == -1) {
65 | return [];
66 | }
67 | var index = 0, peek, length = s.length, isReg = 1, modName = 0, parentheseState = 0, parentheseStack = [], res = [];
68 | while(index < length) {
69 | readch();
70 | if(isBlank()) {
71 | }
72 | else if(isQuote()) {
73 | dealQuote();
74 | isReg = 1
75 | }
76 | else if(peek == '/') {
77 | readch();
78 | if(peek == '/') {
79 | index = s.indexOf('\n', index);
80 | if(index == -1) {
81 | index = s.length;
82 | }
83 | }
84 | else if(peek == '*') {
85 | index = s.indexOf('*/', index);
86 | if(index == -1) {
87 | index = length;
88 | }
89 | else {
90 | index += 2;
91 | }
92 | }
93 | else if(isReg) {
94 | dealReg();
95 | isReg = 0
96 | }
97 | else {
98 | index--;
99 | isReg = 1;
100 | }
101 | }
102 | else if(isWord()) {
103 | dealWord();
104 | }
105 | else if(isNumber()) {
106 | dealNumber();
107 | }
108 | else if(peek == '(') {
109 | parentheseStack.push(parentheseState);
110 | isReg = 1
111 | }
112 | else if(peek == ')') {
113 | isReg = parentheseStack.pop();
114 | }
115 | else {
116 | isReg = peek != ']';
117 | modName = 0
118 | }
119 | }
120 | return res;
121 | function readch() {
122 | peek = s.charAt(index++);
123 | }
124 | function isBlank() {
125 | return /\s/.test(peek);
126 | }
127 | function isQuote() {
128 | return peek == '"' || peek == "'";
129 | }
130 | function dealQuote() {
131 | var start = index;
132 | var c = peek;
133 | var end = s.indexOf(c, start);
134 | if(end == -1) {
135 | index = length;
136 | }
137 | else if(s.charAt(end - 1) != '\\') {
138 | index = end + 1;
139 | }
140 | else {
141 | while(index < length) {
142 | readch();
143 | if(peek == '\\') {
144 | index++;
145 | }
146 | else if(peek == c) {
147 | break;
148 | }
149 | }
150 | }
151 | if(modName) {
152 | res.push(s.slice(start, index - 1));
153 | modName = 0;
154 | }
155 | }
156 | function dealReg() {
157 | index--;
158 | while(index < length) {
159 | readch();
160 | if(peek == '\\') {
161 | index++
162 | }
163 | else if(peek == '/') {
164 | break
165 | }
166 | else if(peek == '[') {
167 | while(index < length) {
168 | readch();
169 | if(peek == '\\') {
170 | index++;
171 | }
172 | else if(peek == ']') {
173 | break;
174 | }
175 | }
176 | }
177 | }
178 | }
179 | function isWord() {
180 | return /[a-z_$]/i.test(peek);
181 | }
182 | function dealWord() {
183 | var s2 = s.slice(index - 1);
184 | var r = /^[\w$]+/.exec(s2)[0];
185 | parentheseState = {
186 | 'if': 1,
187 | 'for': 1,
188 | 'while': 1,
189 | 'with': 1
190 | }[r];
191 | isReg = {
192 | 'break': 1,
193 | 'case': 1,
194 | 'continue': 1,
195 | 'debugger': 1,
196 | 'delete': 1,
197 | 'do': 1,
198 | 'else': 1,
199 | 'false': 1,
200 | 'if': 1,
201 | 'in': 1,
202 | 'instanceof': 1,
203 | 'return': 1,
204 | 'typeof': 1,
205 | 'void': 1
206 | }[r];
207 | modName = /^require\s*\(\s*(['"]).+?\1\s*\)/.test(s2);
208 | if(modName) {
209 | r = /^require\s*\(\s*['"]/.exec(s2)[0];
210 | index += r.length - 2;
211 | }
212 | else {
213 | index += /^[\w$]+(?:\s*\.\s*[\w$]+)*/.exec(s2)[0].length - 1;
214 | }
215 | }
216 | function isNumber() {
217 | return /\d/.test(peek)
218 | || peek == '.' && /\d/.test(s.charAt(index));
219 | }
220 | function dealNumber() {
221 | var s2 = s.slice(index - 1);
222 | var r;
223 | if(peek == '.') {
224 | r = /^\.\d+(?:E[+-]?\d*)?\s*/i.exec(s2)[0];
225 | }
226 | else if(/^0x[\da-f]*/i.test(s2)) {
227 | r = /^0x[\da-f]*\s*/i.exec(s2)[0];
228 | }
229 | else {
230 | r = /^\d+\.?\d*(?:E[+-]?\d*)?\s*/i.exec(s2)[0];
231 | }
232 | index += r.length - 1;
233 | isReg = 0;
234 | }
235 | };
236 | function needParse(depPaths){
237 | var result = false;
238 | depPaths.forEach(function(path){
239 | if(path.id == "require"){
240 | result = true;
241 | return false;
242 | }
243 | });
244 | return result;
245 | }
246 | this.injectCommonjs();
247 | if(this.factory && needParse(this.depPaths)) {
248 | this.collectDeps();
249 | }
250 | });
251 | });
252 | })();
253 |
254 | /**
255 | * 可以使kvm加载css文件
256 | */
257 | (function(){
258 | kvm.module.registerPlugin(function(API){
259 | API.registerDriverLoader('css',function(uri,callback){
260 | var doc = document;
261 | var head = doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
262 | var ss = window.document.createElement( "link" );
263 | var sheets = window.document.styleSheets;
264 | var _this = this;
265 | ss.rel = "stylesheet";
266 | ss.href = uri;
267 | ss.media = "only x";
268 | if( callback ) {
269 | ss.onload = function(){
270 | callback && callback(null,ss);
271 | };
272 |
273 | ss.onerror = function(){
274 | callback && callback(true);
275 | };
276 | }
277 | head.appendChild(ss);
278 | ss.onloadcssdefined = function( cb ){
279 | var defined;
280 | for( var i = 0; i < sheets.length; i++ ){
281 | if( sheets[ i ].href && sheets[ i ].href.indexOf( uri ) > -1 ){
282 | defined = true;
283 | }
284 | }
285 | if( defined ){
286 | cb();
287 | } else {
288 | setTimeout(function() {
289 | ss.onloadcssdefined( cb );
290 | });
291 | }
292 | };
293 | ss.onloadcssdefined(function() {
294 | ss.media = _this.path.query && _this.path.query.media || "all";
295 | });
296 | });
297 |
298 | API.registerDriverLoaded(function (err,res) {
299 | var path = this.path;
300 | if(path.ext == "css" && !err){
301 | kvm.module.define(path.id, function(){
302 | return res;
303 | });
304 | }
305 | });
306 | });
307 | })();
308 |
309 | /**
310 | * 可以使kvm加载json文件
311 | */
312 | /**
313 | * 可以使kvm支持包管理
314 | */
315 | (function () {
316 | kvm.module.registerPlugin(function (API) {
317 | var Data = kvm.module.data();
318 | API.registerPathParser(function () {
319 | var baseUrl = Data.baseUrl;
320 | var packages = Data.packages;
321 | var packname, index,
322 | uri = this.uri || this.id;
323 | if(!uri) return;
324 | index = uri.indexOf("/");
325 | packname = uri.substr(0, index);
326 | if (packages && packages[packname]) {
327 | this.baseUrl = packages[packname].uri || packages[packname].url || baseUrl;
328 | this.uri = uri.substr(index + 1);
329 | this._parseVars();
330 | }
331 | });
332 | });
333 | })();
334 |
335 |
336 | /**
337 | * 可以使kvm支持包装器
338 | */
339 | (function () {
340 | kvm.module.registerPlugin(function (API) {
341 | var Data = kvm.module.data();
342 | API.registerPathMaper(function () {
343 | var shim = Data.shims[this.id];
344 | if (shim) {
345 | this.uri = shim.uri || shim.url;
346 | this._parser();
347 | }
348 | });
349 |
350 | API.registerDriverBeforeLoad(function () {
351 | var path = this.path;
352 | var shim = Data.shims[path.id];
353 | if (shim) {
354 | if (shim.exports && !shim.factory) {
355 | if (window[shim.exports]) {
356 | this.module = API.createModule(path.id, function () {
357 | return window[shim.exports];
358 | });
359 | }
360 | }
361 | }
362 | });
363 |
364 | API.registerDriverLoaded(function () {
365 | var path = this.path;
366 | var shim = Data.shims[path.id];
367 | if (shim && !path.getModule()) {
368 | if (kvm.isFunction(shim.factory) || kvm.isArray(shim.factory)) {
369 | kvm.module.define(path.id, shim.factory);
370 | } else {
371 | kvm.module.define(path.id, function () {
372 | return window[shim.exports]
373 | });
374 | }
375 | }
376 | });
377 | });
378 | })();
379 |
380 |
381 | /**
382 | * 可以使kvm加载html模板
383 | */
--------------------------------------------------------------------------------
/dist/kvm-plugins.min.js:
--------------------------------------------------------------------------------
1 | /**
2 | ** kvm.js - 一款兼容AMD,CMD,angular模块规范同时支持依赖注入的模块管理器
3 | ** @author Janry
4 | ** @version v0.2.2
5 | **/
6 | !function(){kvm.module.registerPlugin(function(e){e.registerPathMaper(function(){var e=kvm.module.data("alias");kvm.isAbsolutePath(this.id)||e[this.id]&&(this.uri=e[this.id],this._parser())})})}(),function(){kvm.module.registerPlugin(function(e){e.registerModuleParser(function(){function t(e){var t,i;for(t=0;tf;)if(t(),"\\"==d)f++;else if(d==r)break;m&&(g.push(e.slice(i,f-1)),m=0)}function s(){for(f--;l>f;)if(t(),"\\"==d)f++;else{if("/"==d)break;if("["==d)for(;l>f;)if(t(),"\\"==d)f++;else if("]"==d)break}}function o(){return/[a-z_$]/i.test(d)}function u(){var t=e.slice(f-1),i=/^[\w$]+/.exec(t)[0];v={"if":1,"for":1,"while":1,"with":1}[i],h={"break":1,"case":1,"continue":1,"debugger":1,"delete":1,"do":1,"else":1,"false":1,"if":1,"in":1,"instanceof":1,"return":1,"typeof":1,"void":1}[i],m=/^require\s*\(\s*(['"]).+?\1\s*\)/.test(t),m?(i=/^require\s*\(\s*['"]/.exec(t)[0],f+=i.length-2):f+=/^[\w$]+(?:\s*\.\s*[\w$]+)*/.exec(t)[0].length-1}function a(){return/\d/.test(d)||"."==d&&/\d/.test(e.charAt(f))}function c(){var t,i=e.slice(f-1);t="."==d?/^\.\d+(?:E[+-]?\d*)?\s*/i.exec(i)[0]:/^0x[\da-f]*/i.test(i)?/^0x[\da-f]*\s*/i.exec(i)[0]:/^\d+\.?\d*(?:E[+-]?\d*)?\s*/i.exec(i)[0],f+=t.length-1,h=0}if(-1==e.indexOf("require"))return[];for(var d,f=0,l=e.length,h=1,m=0,v=0,p=[],g=[];l>f;)t(),i()||(r()?(n(),h=1):"/"==d?(t(),"/"==d?(f=e.indexOf("\n",f),-1==f&&(f=e.length)):"*"==d?(f=e.indexOf("*/",f),-1==f?f=l:f+=2):h?(s(),h=0):(f--,h=1)):o()?u():a()?c():"("==d?(p.push(v),h=1):")"==d?h=p.pop():(h="]"!=d,m=0));return g},this.injectCommonjs(),this.factory&&i(this.depPaths)&&this.collectDeps()})})}(),function(){kvm.module.registerPlugin(function(e){e.registerDriverLoader("css",function(e,t){var i=document,r=i.head||i.getElementsByTagName("head")[0]||i.documentElement,n=window.document.createElement("link"),s=window.document.styleSheets,o=this;n.rel="stylesheet",n.href=e,n.media="only x",t&&(n.onload=function(){t&&t(null,n)},n.onerror=function(){t&&t(!0)}),r.appendChild(n),n.onloadcssdefined=function(t){for(var i,r=0;r-1&&(i=!0);i?t():setTimeout(function(){n.onloadcssdefined(t)})},n.onloadcssdefined(function(){n.media=o.path.query&&o.path.query.media||"all"})}),e.registerDriverLoaded(function(e,t){var i=this.path;"css"!=i.ext||e||kvm.module.define(i.id,function(){return t})})})}(),function(){kvm.module.registerPlugin(function(e){var t=kvm.module.data();e.registerPathParser(function(){var e,i,r=t.baseUrl,n=t.packages,s=this.uri||this.id;s&&(i=s.indexOf("/"),e=s.substr(0,i),n&&n[e]&&(this.baseUrl=n[e].uri||n[e].url||r,this.uri=s.substr(i+1),this._parseVars()))})})}(),function(){kvm.module.registerPlugin(function(e){var t=kvm.module.data();e.registerPathMaper(function(){var e=t.shims[this.id];e&&(this.uri=e.uri||e.url,this._parser())}),e.registerDriverBeforeLoad(function(){var i=this.path,r=t.shims[i.id];r&&r.exports&&!r.factory&&window[r.exports]&&(this.module=e.createModule(i.id,function(){return window[r.exports]}))}),e.registerDriverLoaded(function(){var e=this.path,i=t.shims[e.id];i&&!e.getModule()&&(kvm.isFunction(i.factory)||kvm.isArray(i.factory)?kvm.module.define(e.id,i.factory):kvm.module.define(e.id,function(){return window[i.exports]}))})})}();
--------------------------------------------------------------------------------
/dist/kvm.js:
--------------------------------------------------------------------------------
1 | (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o i){
153 | var S = $.ES5Object(arguments[i++])
154 | , keys = $.getKeys(S)
155 | , length = keys.length
156 | , j = 0
157 | , key;
158 | while(length > j)T[key = keys[j++]] = S[key];
159 | }
160 | return T;
161 | };
162 | },{"./$":21}],14:[function(require,module,exports){
163 | var $ = require('./$')
164 | , TAG = require('./$.wks')('toStringTag')
165 | , toString = {}.toString;
166 | function cof(it){
167 | return toString.call(it).slice(8, -1);
168 | }
169 | cof.classof = function(it){
170 | var O, T;
171 | return it == undefined ? it === undefined ? 'Undefined' : 'Null'
172 | : typeof (T = (O = Object(it))[TAG]) == 'string' ? T : cof(O);
173 | };
174 | cof.set = function(it, tag, stat){
175 | if(it && !$.has(it = stat ? it : it.prototype, TAG))$.hide(it, TAG, tag);
176 | };
177 | module.exports = cof;
178 | },{"./$":21,"./$.wks":27}],15:[function(require,module,exports){
179 | // Optional / simple context binding
180 | var assertFunction = require('./$.assert').fn;
181 | module.exports = function(fn, that, length){
182 | assertFunction(fn);
183 | if(~length && that === undefined)return fn;
184 | switch(length){
185 | case 1: return function(a){
186 | return fn.call(that, a);
187 | };
188 | case 2: return function(a, b){
189 | return fn.call(that, a, b);
190 | };
191 | case 3: return function(a, b, c){
192 | return fn.call(that, a, b, c);
193 | };
194 | } return function(/* ...args */){
195 | return fn.apply(that, arguments);
196 | };
197 | };
198 | },{"./$.assert":12}],16:[function(require,module,exports){
199 | var $ = require('./$')
200 | , global = $.g
201 | , core = $.core
202 | , isFunction = $.isFunction;
203 | function ctx(fn, that){
204 | return function(){
205 | return fn.apply(that, arguments);
206 | };
207 | }
208 | // type bitmap
209 | $def.F = 1; // forced
210 | $def.G = 2; // global
211 | $def.S = 4; // static
212 | $def.P = 8; // proto
213 | $def.B = 16; // bind
214 | $def.W = 32; // wrap
215 | function $def(type, name, source){
216 | var key, own, out, exp
217 | , isGlobal = type & $def.G
218 | , target = isGlobal ? global : type & $def.S
219 | ? global[name] : (global[name] || {}).prototype
220 | , exports = isGlobal ? core : core[name] || (core[name] = {});
221 | if(isGlobal)source = name;
222 | for(key in source){
223 | // contains in native
224 | own = !(type & $def.F) && target && key in target;
225 | if(own && key in exports)continue;
226 | // export native or passed
227 | out = own ? target[key] : source[key];
228 | // prevent global pollution for namespaces
229 | if(isGlobal && !isFunction(target[key]))exp = source[key];
230 | // bind timers to global for call from export context
231 | else if(type & $def.B && own)exp = ctx(out, global);
232 | // wrap global constructors for prevent change them in library
233 | else if(type & $def.W && target[key] == out)!function(C){
234 | exp = function(param){
235 | return this instanceof C ? new C(param) : C(param);
236 | };
237 | exp.prototype = C.prototype;
238 | }(out);
239 | else exp = type & $def.P && isFunction(out) ? ctx(Function.call, out) : out;
240 | // export
241 | $.hide(exports, key, exp);
242 | }
243 | }
244 | module.exports = $def;
245 | },{"./$":21}],17:[function(require,module,exports){
246 | module.exports = function($){
247 | $.FW = false;
248 | $.path = $.core;
249 | return $;
250 | };
251 | },{}],18:[function(require,module,exports){
252 | // Fast apply
253 | // http://jsperf.lnkit.com/fast-apply/5
254 | module.exports = function(fn, args, that){
255 | var un = that === undefined;
256 | switch(args.length){
257 | case 0: return un ? fn()
258 | : fn.call(that);
259 | case 1: return un ? fn(args[0])
260 | : fn.call(that, args[0]);
261 | case 2: return un ? fn(args[0], args[1])
262 | : fn.call(that, args[0], args[1]);
263 | case 3: return un ? fn(args[0], args[1], args[2])
264 | : fn.call(that, args[0], args[1], args[2]);
265 | case 4: return un ? fn(args[0], args[1], args[2], args[3])
266 | : fn.call(that, args[0], args[1], args[2], args[3]);
267 | case 5: return un ? fn(args[0], args[1], args[2], args[3], args[4])
268 | : fn.call(that, args[0], args[1], args[2], args[3], args[4]);
269 | } return fn.apply(that, args);
270 | };
271 | },{}],19:[function(require,module,exports){
272 | var SYMBOL_ITERATOR = require('./$.wks')('iterator')
273 | , SAFE_CLOSING = false;
274 | try {
275 | var riter = [7][SYMBOL_ITERATOR]();
276 | riter['return'] = function(){ SAFE_CLOSING = true; };
277 | Array.from(riter, function(){ throw 2; });
278 | } catch(e){ /* empty */ }
279 | module.exports = function(exec){
280 | if(!SAFE_CLOSING)return false;
281 | var safe = false;
282 | try {
283 | var arr = [7]
284 | , iter = arr[SYMBOL_ITERATOR]();
285 | iter.next = function(){ safe = true; };
286 | arr[SYMBOL_ITERATOR] = function(){ return iter; };
287 | exec(arr);
288 | } catch(e){ /* empty */ }
289 | return safe;
290 | };
291 | },{"./$.wks":27}],20:[function(require,module,exports){
292 | 'use strict';
293 | var $ = require('./$')
294 | , ctx = require('./$.ctx')
295 | , cof = require('./$.cof')
296 | , $def = require('./$.def')
297 | , assertObject = require('./$.assert').obj
298 | , SYMBOL_ITERATOR = require('./$.wks')('iterator')
299 | , FF_ITERATOR = '@@iterator'
300 | , Iterators = {}
301 | , IteratorPrototype = {};
302 | // Safari has byggy iterators w/o `next`
303 | var BUGGY = 'keys' in [] && !('next' in [].keys());
304 | // 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
305 | setIterator(IteratorPrototype, $.that);
306 | function setIterator(O, value){
307 | $.hide(O, SYMBOL_ITERATOR, value);
308 | // Add iterator for FF iterator protocol
309 | if(FF_ITERATOR in [])$.hide(O, FF_ITERATOR, value);
310 | }
311 | function defineIterator(Constructor, NAME, value, DEFAULT){
312 | var proto = Constructor.prototype
313 | , iter = proto[SYMBOL_ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT] || value;
314 | // Define iterator
315 | if($.FW)setIterator(proto, iter);
316 | if(iter !== value){
317 | var iterProto = $.getProto(iter.call(new Constructor));
318 | // Set @@toStringTag to native iterators
319 | cof.set(iterProto, NAME + ' Iterator', true);
320 | // FF fix
321 | if($.FW)$.has(proto, FF_ITERATOR) && setIterator(iterProto, $.that);
322 | }
323 | // Plug for library
324 | Iterators[NAME] = iter;
325 | // FF & v8 fix
326 | Iterators[NAME + ' Iterator'] = $.that;
327 | return iter;
328 | }
329 | function getIterator(it){
330 | var Symbol = $.g.Symbol
331 | , ext = it[Symbol && Symbol.iterator || FF_ITERATOR]
332 | , getIter = ext || it[SYMBOL_ITERATOR] || Iterators[cof.classof(it)];
333 | return assertObject(getIter.call(it));
334 | }
335 | function closeIterator(iterator){
336 | var ret = iterator['return'];
337 | if(ret !== undefined)assertObject(ret.call(iterator));
338 | }
339 | function stepCall(iterator, fn, value, entries){
340 | try {
341 | return entries ? fn(assertObject(value)[0], value[1]) : fn(value);
342 | } catch(e){
343 | closeIterator(iterator);
344 | throw e;
345 | }
346 | }
347 | var $iter = module.exports = {
348 | BUGGY: BUGGY,
349 | Iterators: Iterators,
350 | prototype: IteratorPrototype,
351 | step: function(done, value){
352 | return {value: value, done: !!done};
353 | },
354 | stepCall: stepCall,
355 | close: closeIterator,
356 | is: function(it){
357 | var O = Object(it)
358 | , Symbol = $.g.Symbol
359 | , SYM = Symbol && Symbol.iterator || FF_ITERATOR;
360 | return SYM in O || SYMBOL_ITERATOR in O || $.has(Iterators, cof.classof(O));
361 | },
362 | get: getIterator,
363 | set: setIterator,
364 | create: function(Constructor, NAME, next, proto){
365 | Constructor.prototype = $.create(proto || $iter.prototype, {next: $.desc(1, next)});
366 | cof.set(Constructor, NAME + ' Iterator');
367 | },
368 | define: defineIterator,
369 | std: function(Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCE){
370 | function createIter(kind){
371 | return function(){
372 | return new Constructor(this, kind);
373 | };
374 | }
375 | $iter.create(Constructor, NAME, next);
376 | var entries = createIter('key+value')
377 | , values = createIter('value')
378 | , proto = Base.prototype
379 | , methods, key;
380 | if(DEFAULT == 'value')values = defineIterator(Base, NAME, values, 'values');
381 | else entries = defineIterator(Base, NAME, entries, 'entries');
382 | if(DEFAULT){
383 | methods = {
384 | entries: entries,
385 | keys: IS_SET ? values : createIter('key'),
386 | values: values
387 | };
388 | $def($def.P + $def.F * BUGGY, NAME, methods);
389 | if(FORCE)for(key in methods){
390 | if(!(key in proto))$.hide(proto, key, methods[key]);
391 | }
392 | }
393 | },
394 | forOf: function(iterable, entries, fn, that){
395 | var iterator = getIterator(iterable)
396 | , f = ctx(fn, that, entries ? 2 : 1)
397 | , step;
398 | while(!(step = iterator.next()).done){
399 | if(stepCall(iterator, f, step.value, entries) === false){
400 | return closeIterator(iterator);
401 | }
402 | }
403 | }
404 | };
405 | },{"./$":21,"./$.assert":12,"./$.cof":14,"./$.ctx":15,"./$.def":16,"./$.wks":27}],21:[function(require,module,exports){
406 | 'use strict';
407 | var global = typeof self != 'undefined' ? self : Function('return this')()
408 | , core = {}
409 | , defineProperty = Object.defineProperty
410 | , hasOwnProperty = {}.hasOwnProperty
411 | , ceil = Math.ceil
412 | , floor = Math.floor
413 | , max = Math.max
414 | , min = Math.min;
415 | // The engine works fine with descriptors? Thank's IE8 for his funny defineProperty.
416 | var DESC = !!function(){
417 | try {
418 | return defineProperty({}, 'a', {get: function(){ return 2; }}).a == 2;
419 | } catch(e){ /* empty */ }
420 | }();
421 | var hide = createDefiner(1);
422 | // 7.1.4 ToInteger
423 | function toInteger(it){
424 | return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
425 | }
426 | function desc(bitmap, value){
427 | return {
428 | enumerable : !(bitmap & 1),
429 | configurable: !(bitmap & 2),
430 | writable : !(bitmap & 4),
431 | value : value
432 | };
433 | }
434 | function simpleSet(object, key, value){
435 | object[key] = value;
436 | return object;
437 | }
438 | function createDefiner(bitmap){
439 | return DESC ? function(object, key, value){
440 | return $.setDesc(object, key, desc(bitmap, value)); // eslint-disable-line no-use-before-define
441 | } : simpleSet;
442 | }
443 |
444 | function isObject(it){
445 | return it !== null && (typeof it == 'object' || typeof it == 'function');
446 | }
447 | function isFunction(it){
448 | return typeof it == 'function';
449 | }
450 | function assertDefined(it){
451 | if(it == undefined)throw TypeError("Can't call method on " + it);
452 | return it;
453 | }
454 |
455 | var $ = module.exports = require('./$.fw')({
456 | g: global,
457 | core: core,
458 | html: global.document && document.documentElement,
459 | // http://jsperf.com/core-js-isobject
460 | isObject: isObject,
461 | isFunction: isFunction,
462 | it: function(it){
463 | return it;
464 | },
465 | that: function(){
466 | return this;
467 | },
468 | // 7.1.4 ToInteger
469 | toInteger: toInteger,
470 | // 7.1.15 ToLength
471 | toLength: function(it){
472 | return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
473 | },
474 | toIndex: function(index, length){
475 | index = toInteger(index);
476 | return index < 0 ? max(index + length, 0) : min(index, length);
477 | },
478 | has: function(it, key){
479 | return hasOwnProperty.call(it, key);
480 | },
481 | create: Object.create,
482 | getProto: Object.getPrototypeOf,
483 | DESC: DESC,
484 | desc: desc,
485 | getDesc: Object.getOwnPropertyDescriptor,
486 | setDesc: defineProperty,
487 | getKeys: Object.keys,
488 | getNames: Object.getOwnPropertyNames,
489 | getSymbols: Object.getOwnPropertySymbols,
490 | // Dummy, fix for not array-like ES3 string in es5 module
491 | assertDefined: assertDefined,
492 | ES5Object: Object,
493 | toObject: function(it){
494 | return $.ES5Object(assertDefined(it));
495 | },
496 | hide: hide,
497 | def: createDefiner(0),
498 | set: global.Symbol ? simpleSet : hide,
499 | mix: function(target, src){
500 | for(var key in src)hide(target, key, src[key]);
501 | return target;
502 | },
503 | each: [].forEach
504 | });
505 | if(typeof __e != 'undefined')__e = core;
506 | if(typeof __g != 'undefined')__g = global;
507 | },{"./$.fw":17}],22:[function(require,module,exports){
508 | var $ = require('./$');
509 | module.exports = function(C){
510 | if($.DESC && $.FW)$.setDesc(C, require('./$.wks')('species'), {
511 | configurable: true,
512 | get: $.that
513 | });
514 | };
515 | },{"./$":21,"./$.wks":27}],23:[function(require,module,exports){
516 | 'use strict';
517 | // true -> String#at
518 | // false -> String#codePointAt
519 | var $ = require('./$');
520 | module.exports = function(TO_STRING){
521 | return function(pos){
522 | var s = String($.assertDefined(this))
523 | , i = $.toInteger(pos)
524 | , l = s.length
525 | , a, b;
526 | if(i < 0 || i >= l)return TO_STRING ? '' : undefined;
527 | a = s.charCodeAt(i);
528 | return a < 0xd800 || a > 0xdbff || i + 1 === l
529 | || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff
530 | ? TO_STRING ? s.charAt(i) : a
531 | : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000;
532 | };
533 | };
534 | },{"./$":21}],24:[function(require,module,exports){
535 | 'use strict';
536 | var $ = require('./$')
537 | , ctx = require('./$.ctx')
538 | , cof = require('./$.cof')
539 | , invoke = require('./$.invoke')
540 | , global = $.g
541 | , isFunction = $.isFunction
542 | , html = $.html
543 | , document = global.document
544 | , process = global.process
545 | , setTask = global.setImmediate
546 | , clearTask = global.clearImmediate
547 | , postMessage = global.postMessage
548 | , addEventListener = global.addEventListener
549 | , MessageChannel = global.MessageChannel
550 | , counter = 0
551 | , queue = {}
552 | , ONREADYSTATECHANGE = 'onreadystatechange'
553 | , defer, channel, port;
554 | function run(){
555 | var id = +this;
556 | if($.has(queue, id)){
557 | var fn = queue[id];
558 | delete queue[id];
559 | fn();
560 | }
561 | }
562 | function listner(event){
563 | run.call(event.data);
564 | }
565 | // Node.js 0.9+ & IE10+ has setImmediate, otherwise:
566 | if(!isFunction(setTask) || !isFunction(clearTask)){
567 | setTask = function(fn){
568 | var args = [], i = 1;
569 | while(arguments.length > i)args.push(arguments[i++]);
570 | queue[++counter] = function(){
571 | invoke(isFunction(fn) ? fn : Function(fn), args);
572 | };
573 | defer(counter);
574 | return counter;
575 | };
576 | clearTask = function(id){
577 | delete queue[id];
578 | };
579 | // Node.js 0.8-
580 | if(cof(process) == 'process'){
581 | defer = function(id){
582 | process.nextTick(ctx(run, id, 1));
583 | };
584 | // Modern browsers, skip implementation for WebWorkers
585 | // IE8 has postMessage, but it's sync & typeof its postMessage is object
586 | } else if(addEventListener && isFunction(postMessage) && !global.importScripts){
587 | defer = function(id){
588 | postMessage(id, '*');
589 | };
590 | addEventListener('message', listner, false);
591 | // WebWorkers
592 | } else if(isFunction(MessageChannel)){
593 | channel = new MessageChannel;
594 | port = channel.port2;
595 | channel.port1.onmessage = listner;
596 | defer = ctx(port.postMessage, port, 1);
597 | // IE8-
598 | } else if(document && ONREADYSTATECHANGE in document.createElement('script')){
599 | defer = function(id){
600 | html.appendChild(document.createElement('script'))[ONREADYSTATECHANGE] = function(){
601 | html.removeChild(this);
602 | run.call(id);
603 | };
604 | };
605 | // Rest old browsers
606 | } else {
607 | defer = function(id){
608 | setTimeout(ctx(run, id, 1), 0);
609 | };
610 | }
611 | }
612 | module.exports = {
613 | set: setTask,
614 | clear: clearTask
615 | };
616 | },{"./$":21,"./$.cof":14,"./$.ctx":15,"./$.invoke":18}],25:[function(require,module,exports){
617 | var sid = 0;
618 | function uid(key){
619 | return 'Symbol(' + key + ')_' + (++sid + Math.random()).toString(36);
620 | }
621 | uid.safe = require('./$').g.Symbol || uid;
622 | module.exports = uid;
623 | },{"./$":21}],26:[function(require,module,exports){
624 | // 22.1.3.31 Array.prototype[@@unscopables]
625 | var $ = require('./$')
626 | , UNSCOPABLES = require('./$.wks')('unscopables');
627 | if($.FW && !(UNSCOPABLES in []))$.hide(Array.prototype, UNSCOPABLES, {});
628 | module.exports = function(key){
629 | if($.FW)[][UNSCOPABLES][key] = true;
630 | };
631 | },{"./$":21,"./$.wks":27}],27:[function(require,module,exports){
632 | var global = require('./$').g
633 | , store = {};
634 | module.exports = function(name){
635 | return store[name] || (store[name] =
636 | global.Symbol && global.Symbol[name] || require('./$.uid').safe('Symbol.' + name));
637 | };
638 | },{"./$":21,"./$.uid":25}],28:[function(require,module,exports){
639 | var $ = require('./$')
640 | , setUnscope = require('./$.unscope')
641 | , ITER = require('./$.uid').safe('iter')
642 | , $iter = require('./$.iter')
643 | , step = $iter.step
644 | , Iterators = $iter.Iterators;
645 |
646 | // 22.1.3.4 Array.prototype.entries()
647 | // 22.1.3.13 Array.prototype.keys()
648 | // 22.1.3.29 Array.prototype.values()
649 | // 22.1.3.30 Array.prototype[@@iterator]()
650 | $iter.std(Array, 'Array', function(iterated, kind){
651 | $.set(this, ITER, {o: $.toObject(iterated), i: 0, k: kind});
652 | // 22.1.5.2.1 %ArrayIteratorPrototype%.next()
653 | }, function(){
654 | var iter = this[ITER]
655 | , O = iter.o
656 | , kind = iter.k
657 | , index = iter.i++;
658 | if(!O || index >= O.length){
659 | iter.o = undefined;
660 | return step(1);
661 | }
662 | if(kind == 'key' )return step(0, index);
663 | if(kind == 'value')return step(0, O[index]);
664 | return step(0, [index, O[index]]);
665 | }, 'value');
666 |
667 | // argumentsList[@@iterator] is %ArrayProto_values% (9.4.4.6, 9.4.4.7)
668 | Iterators.Arguments = Iterators.Array;
669 |
670 | setUnscope('keys');
671 | setUnscope('values');
672 | setUnscope('entries');
673 | },{"./$":21,"./$.iter":20,"./$.uid":25,"./$.unscope":26}],29:[function(require,module,exports){
674 | // 19.1.3.1 Object.assign(target, source)
675 | var $def = require('./$.def');
676 | $def($def.S, 'Object', {assign: require('./$.assign')});
677 | },{"./$.assign":13,"./$.def":16}],30:[function(require,module,exports){
678 | var $ = require('./$')
679 | , $def = require('./$.def')
680 | , isObject = $.isObject
681 | , toObject = $.toObject;
682 | function wrapObjectMethod(METHOD, MODE){
683 | var fn = ($.core.Object || {})[METHOD] || Object[METHOD]
684 | , f = 0
685 | , o = {};
686 | o[METHOD] = MODE == 1 ? function(it){
687 | return isObject(it) ? fn(it) : it;
688 | } : MODE == 2 ? function(it){
689 | return isObject(it) ? fn(it) : true;
690 | } : MODE == 3 ? function(it){
691 | return isObject(it) ? fn(it) : false;
692 | } : MODE == 4 ? function getOwnPropertyDescriptor(it, key){
693 | return fn(toObject(it), key);
694 | } : MODE == 5 ? function getPrototypeOf(it){
695 | return fn(Object($.assertDefined(it)));
696 | } : function(it){
697 | return fn(toObject(it));
698 | };
699 | try {
700 | fn('z');
701 | } catch(e){
702 | f = 1;
703 | }
704 | $def($def.S + $def.F * f, 'Object', o);
705 | }
706 | wrapObjectMethod('freeze', 1);
707 | wrapObjectMethod('seal', 1);
708 | wrapObjectMethod('preventExtensions', 1);
709 | wrapObjectMethod('isFrozen', 2);
710 | wrapObjectMethod('isSealed', 2);
711 | wrapObjectMethod('isExtensible', 3);
712 | wrapObjectMethod('getOwnPropertyDescriptor', 4);
713 | wrapObjectMethod('getPrototypeOf', 5);
714 | wrapObjectMethod('keys');
715 | wrapObjectMethod('getOwnPropertyNames');
716 | },{"./$":21,"./$.def":16}],31:[function(require,module,exports){
717 | 'use strict';
718 | var $ = require('./$')
719 | , ctx = require('./$.ctx')
720 | , cof = require('./$.cof')
721 | , $def = require('./$.def')
722 | , assert = require('./$.assert')
723 | , $iter = require('./$.iter')
724 | , SPECIES = require('./$.wks')('species')
725 | , RECORD = require('./$.uid').safe('record')
726 | , forOf = $iter.forOf
727 | , PROMISE = 'Promise'
728 | , global = $.g
729 | , process = global.process
730 | , asap = process && process.nextTick || require('./$.task').set
731 | , P = global[PROMISE]
732 | , Base = P
733 | , isFunction = $.isFunction
734 | , isObject = $.isObject
735 | , assertFunction = assert.fn
736 | , assertObject = assert.obj
737 | , test;
738 |
739 | // helpers
740 | function getConstructor(C){
741 | var S = assertObject(C)[SPECIES];
742 | return S != undefined ? S : C;
743 | }
744 | function isThenable(it){
745 | var then;
746 | if(isObject(it))then = it.then;
747 | return isFunction(then) ? then : false;
748 | }
749 | function isUnhandled(promise){
750 | var record = promise[RECORD]
751 | , chain = record.c
752 | , i = 0
753 | , react;
754 | if(record.h)return false;
755 | while(chain.length > i){
756 | react = chain[i++];
757 | if(react.fail || !isUnhandled(react.P))return false;
758 | } return true;
759 | }
760 | function notify(record, isReject){
761 | var chain = record.c;
762 | if(isReject || chain.length)asap(function(){
763 | var promise = record.p
764 | , value = record.v
765 | , ok = record.s == 1
766 | , i = 0;
767 | if(isReject && isUnhandled(promise)){
768 | setTimeout(function(){
769 | if(isUnhandled(promise)){
770 | if(cof(process) == 'process'){
771 | process.emit('unhandledRejection', value, promise);
772 | } else if(global.console && isFunction(console.error)){
773 | console.error('Unhandled promise rejection', value);
774 | }
775 | }
776 | }, 1e3);
777 | } else while(chain.length > i)!function(react){
778 | var cb = ok ? react.ok : react.fail
779 | , ret, then;
780 | try {
781 | if(cb){
782 | if(!ok)record.h = true;
783 | ret = cb === true ? value : cb(value);
784 | if(ret === react.P){
785 | react.rej(TypeError(PROMISE + '-chain cycle'));
786 | } else if(then = isThenable(ret)){
787 | then.call(ret, react.res, react.rej);
788 | } else react.res(ret);
789 | } else react.rej(value);
790 | } catch(err){
791 | react.rej(err);
792 | }
793 | }(chain[i++]);
794 | chain.length = 0;
795 | });
796 | }
797 | function $reject(value){
798 | var record = this;
799 | if(record.d)return;
800 | record.d = true;
801 | record = record.r || record; // unwrap
802 | record.v = value;
803 | record.s = 2;
804 | notify(record, true);
805 | }
806 | function $resolve(value){
807 | var record = this
808 | , then, wrapper;
809 | if(record.d)return;
810 | record.d = true;
811 | record = record.r || record; // unwrap
812 | try {
813 | if(then = isThenable(value)){
814 | wrapper = {r: record, d: false}; // wrap
815 | then.call(value, ctx($resolve, wrapper, 1), ctx($reject, wrapper, 1));
816 | } else {
817 | record.v = value;
818 | record.s = 1;
819 | notify(record);
820 | }
821 | } catch(err){
822 | $reject.call(wrapper || {r: record, d: false}, err); // wrap
823 | }
824 | }
825 |
826 | // constructor polyfill
827 | if(!(isFunction(P) && isFunction(P.resolve) && P.resolve(test = new P(function(){})) == test)){
828 | // 25.4.3.1 Promise(executor)
829 | P = function Promise(executor){
830 | assertFunction(executor);
831 | var record = {
832 | p: assert.inst(this, P, PROMISE), // <- promise
833 | c: [], // <- chain
834 | s: 0, // <- state
835 | d: false, // <- done
836 | v: undefined, // <- value
837 | h: false // <- handled rejection
838 | };
839 | $.hide(this, RECORD, record);
840 | try {
841 | executor(ctx($resolve, record, 1), ctx($reject, record, 1));
842 | } catch(err){
843 | $reject.call(record, err);
844 | }
845 | };
846 | $.mix(P.prototype, {
847 | // 25.4.5.3 Promise.prototype.then(onFulfilled, onRejected)
848 | then: function then(onFulfilled, onRejected){
849 | var S = assertObject(assertObject(this).constructor)[SPECIES];
850 | var react = {
851 | ok: isFunction(onFulfilled) ? onFulfilled : true,
852 | fail: isFunction(onRejected) ? onRejected : false
853 | };
854 | var promise = react.P = new (S != undefined ? S : P)(function(res, rej){
855 | react.res = assertFunction(res);
856 | react.rej = assertFunction(rej);
857 | });
858 | var record = this[RECORD];
859 | record.c.push(react);
860 | record.s && notify(record);
861 | return promise;
862 | },
863 | // 25.4.5.1 Promise.prototype.catch(onRejected)
864 | 'catch': function(onRejected){
865 | return this.then(undefined, onRejected);
866 | }
867 | });
868 | }
869 |
870 | // export
871 | $def($def.G + $def.W + $def.F * (P != Base), {Promise: P});
872 | cof.set(P, PROMISE);
873 | require('./$.species')(P);
874 |
875 | // statics
876 | $def($def.S, PROMISE, {
877 | // 25.4.4.5 Promise.reject(r)
878 | reject: function reject(r){
879 | return new (getConstructor(this))(function(res, rej){
880 | rej(r);
881 | });
882 | },
883 | // 25.4.4.6 Promise.resolve(x)
884 | resolve: function resolve(x){
885 | return isObject(x) && RECORD in x && $.getProto(x) === this.prototype
886 | ? x : new (getConstructor(this))(function(res){
887 | res(x);
888 | });
889 | }
890 | });
891 | $def($def.S + $def.F * !require('./$.iter-detect')(function(iter){
892 | P.all(iter)['catch'](function(){});
893 | }), PROMISE, {
894 | // 25.4.4.1 Promise.all(iterable)
895 | all: function all(iterable){
896 | var C = getConstructor(this)
897 | , values = [];
898 | return new C(function(res, rej){
899 | forOf(iterable, false, values.push, values);
900 | var remaining = values.length
901 | , results = Array(remaining);
902 | if(remaining)$.each.call(values, function(promise, index){
903 | C.resolve(promise).then(function(value){
904 | results[index] = value;
905 | --remaining || res(results);
906 | }, rej);
907 | });
908 | else res(results);
909 | });
910 | },
911 | // 25.4.4.4 Promise.race(iterable)
912 | race: function race(iterable){
913 | var C = getConstructor(this);
914 | return new C(function(res, rej){
915 | forOf(iterable, false, function(promise){
916 | C.resolve(promise).then(res, rej);
917 | });
918 | });
919 | }
920 | });
921 | },{"./$":21,"./$.assert":12,"./$.cof":14,"./$.ctx":15,"./$.def":16,"./$.iter":20,"./$.iter-detect":19,"./$.species":22,"./$.task":24,"./$.uid":25,"./$.wks":27}],32:[function(require,module,exports){
922 | var set = require('./$').set
923 | , at = require('./$.string-at')(true)
924 | , ITER = require('./$.uid').safe('iter')
925 | , $iter = require('./$.iter')
926 | , step = $iter.step;
927 |
928 | // 21.1.3.27 String.prototype[@@iterator]()
929 | $iter.std(String, 'String', function(iterated){
930 | set(this, ITER, {o: String(iterated), i: 0});
931 | // 21.1.5.2.1 %StringIteratorPrototype%.next()
932 | }, function(){
933 | var iter = this[ITER]
934 | , O = iter.o
935 | , index = iter.i
936 | , point;
937 | if(index >= O.length)return step(1);
938 | point = at.call(O, index);
939 | iter.i += point.length;
940 | return step(0, point);
941 | });
942 | },{"./$":21,"./$.iter":20,"./$.string-at":23,"./$.uid":25}],33:[function(require,module,exports){
943 | require('./es6.array.iterator');
944 | var $ = require('./$')
945 | , Iterators = require('./$.iter').Iterators
946 | , ITERATOR = require('./$.wks')('iterator')
947 | , ArrayValues = Iterators.Array
948 | , NodeList = $.g.NodeList;
949 | if($.FW && NodeList && !(ITERATOR in NodeList.prototype)){
950 | $.hide(NodeList.prototype, ITERATOR, ArrayValues);
951 | }
952 | Iterators.NodeList = ArrayValues;
953 | },{"./$":21,"./$.iter":20,"./$.wks":27,"./es6.array.iterator":28}],34:[function(require,module,exports){
954 | "use strict";
955 |
956 | var _inherits = require("babel-runtime/helpers/inherits")["default"];
957 |
958 | var _get = require("babel-runtime/helpers/get")["default"];
959 |
960 | var _createClass = require("babel-runtime/helpers/create-class")["default"];
961 |
962 | var _classCallCheck = require("babel-runtime/helpers/class-call-check")["default"];
963 |
964 | var _Promise = require("babel-runtime/core-js/promise")["default"];
965 |
966 | var _Object$assign = require("babel-runtime/core-js/object/assign")["default"];
967 |
968 | var _interopRequireWildcard = require("babel-runtime/helpers/interop-require-wildcard")["default"];
969 |
970 | Object.defineProperty(exports, "__esModule", {
971 | value: true
972 | });
973 |
974 | var _utils = require("./utils");
975 |
976 | var _utils2 = _interopRequireWildcard(_utils);
977 |
978 | var _Emitter5 = require("./emitter");
979 |
980 | var _Emitter6 = _interopRequireWildcard(_Emitter5);
981 |
982 | var Hook = new _Emitter6["default"]();
983 |
984 | var Data = {
985 | baseUrl: "",
986 | vars: {},
987 | packages: {},
988 | alias: {},
989 | shims: {},
990 | version: ""
991 | };
992 |
993 | var ModuleCache = {
994 | MODULES: {},
995 | insert: function insert(module) {
996 | var path = module.path;
997 | var mapId = module.path.id || module.path.uri;
998 | var driver = Driver.getDriver(path);
999 | if (!this.MODULES[mapId]) {
1000 | this.MODULES[mapId] = module;
1001 | driver && driver.$emit("loaded", module);
1002 | }
1003 | return this.MODULES[mapId];
1004 | },
1005 | find: function find(path) {
1006 | return this.MODULES[path.id || path.uri] || this.MODULES[path.id] || this.MODULES[path.uri];
1007 | }
1008 | };
1009 |
1010 | var Request = (function (_Emitter) {
1011 | function Request(sender, reqs, callback) {
1012 | _classCallCheck(this, Request);
1013 |
1014 | _get(Object.getPrototypeOf(Request.prototype), "constructor", this).call(this);
1015 | this.sender = sender;
1016 | this.reqs = _utils2["default"].isArray(reqs) ? reqs : [reqs];
1017 | this.drivers = [];
1018 | this.results = [];
1019 | this.callback = callback;
1020 | this._parseReqs();
1021 | this.send();
1022 | }
1023 |
1024 | _inherits(Request, _Emitter);
1025 |
1026 | _createClass(Request, [{
1027 | key: "_createDriver",
1028 | value: function _createDriver(path) {
1029 | var driver = Driver.getDriver(path),
1030 | that = this;
1031 | if (!driver) {
1032 | driver = new Driver(path);
1033 | driver.beforeLoad();
1034 | if (!driver.module) {
1035 | this.drivers.push(driver);
1036 | } else {
1037 | return that._done(driver.module);
1038 | }
1039 | }
1040 | if (!driver.module) {
1041 | driver.$on("loaded", function (module) {
1042 | driver.module = module;
1043 | that._done(module);
1044 | });
1045 | } else {
1046 | that._done(driver.module);
1047 | }
1048 | return this;
1049 | }
1050 | }, {
1051 | key: "_parseReqs",
1052 | value: function _parseReqs() {
1053 | var that = this,
1054 | module = undefined;
1055 | this.reqs = this.reqs.filter(function (req) {
1056 | return !!req;
1057 | });
1058 | if (this.reqs.length > 0) {
1059 | this.reqs.forEach(function (path) {
1060 | module = that.sender.getInjector(path);
1061 | module = module || path.getModule();
1062 | if (module) {
1063 | that._done(module);
1064 | } else {
1065 | that._createDriver(path);
1066 | }
1067 | });
1068 | } else {
1069 | that.callback([]);
1070 | }
1071 | return this;
1072 | }
1073 | }, {
1074 | key: "_checkDone",
1075 | value: function _checkDone() {
1076 | return this.reqs.length == this.results.length;
1077 | }
1078 | }, {
1079 | key: "_done",
1080 | value: function _done(module) {
1081 | this.results.push(module);
1082 | if (this._checkDone()) {
1083 | if (_utils2["default"].isFunction(this.callback)) {
1084 | this.callback(this.results);
1085 | }
1086 | }
1087 | return this;
1088 | }
1089 | }, {
1090 | key: "send",
1091 | value: function send() {
1092 | this.drivers.forEach(function (driver) {
1093 | driver.load();
1094 | });
1095 | return this;
1096 | }
1097 | }], [{
1098 | key: "fetch",
1099 | value: function fetch(sender, paths) {
1100 | paths = _utils2["default"].isArray(paths) ? paths : [paths];
1101 | return new _Promise(function (resolve) {
1102 | new Request(sender, paths, function (modules) {
1103 | resolve(modules);
1104 | });
1105 | });
1106 | }
1107 | }]);
1108 |
1109 | return Request;
1110 | })(_Emitter6["default"]);
1111 |
1112 | var Driver = (function (_Emitter2) {
1113 | function Driver(path) {
1114 | _classCallCheck(this, Driver);
1115 |
1116 | _get(Object.getPrototypeOf(Driver.prototype), "constructor", this).call(this);
1117 | this.path = path;
1118 | this.module = null;
1119 | if (!Driver.getDriver(path)) {
1120 | Driver.addDriver(this);
1121 | }
1122 | }
1123 |
1124 | _inherits(Driver, _Emitter2);
1125 |
1126 | _createClass(Driver, [{
1127 | key: "beforeLoad",
1128 | value: function beforeLoad() {
1129 | Hook.$emit("DRIVER_BEFORE_LOAD", this);
1130 | }
1131 | }, {
1132 | key: "load",
1133 | value: function load() {
1134 | var path = this.path;
1135 | var uri = path.uri;
1136 | uri = _utils2["default"].addQueryString(uri, _Object$assign({ version: Data.version }, path.query));
1137 | uri = _utils2["default"].addHashString(uri, path.hash);
1138 | if (path.ext != "js") {
1139 | Hook.$emit("DRIVER_LOADER_" + path.ext.toLocaleUpperCase(), this);
1140 | } else {
1141 | this._loadJS(uri, this.loaded.bind(this));
1142 | }
1143 | }
1144 | }, {
1145 | key: "loaded",
1146 | value: function loaded(err, res) {
1147 | var path = this.path;
1148 | if (path.ext != "js") {
1149 | Dectorator.define(path.id, function () {
1150 | return res;
1151 | });
1152 | } else {
1153 | Hook.$emit("DRIVER_LOADED", this, err, res);
1154 | }
1155 | }
1156 | }, {
1157 | key: "_loadJS",
1158 | value: function _loadJS(url, callback) {
1159 | var doc = document;
1160 | var head = doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
1161 | var baseElement = head.getElementsByTagName("base")[0];
1162 | var node = doc.createElement("script");
1163 | node.async = true;
1164 | node.src = url;
1165 | addOnload(node, callback);
1166 |
1167 | baseElement ? head.insertBefore(node, baseElement) : head.appendChild(node);
1168 |
1169 | function addOnload(node, callback) {
1170 | var supportOnload = ("onload" in node);
1171 |
1172 | if (supportOnload) {
1173 | node.onload = onload;
1174 | node.onerror = function () {
1175 | onload(true);
1176 | };
1177 | } else {
1178 | node.onreadystatechange = function () {
1179 | if (/loaded|complete/.test(node.readyState)) {
1180 | onload();
1181 | }
1182 | };
1183 | }
1184 |
1185 | function onload(e) {
1186 | // Ensure only run once and handle memory leak in IE
1187 | node.onload = node.onerror = node.onreadystatechange = null;
1188 |
1189 | // Remove the script to reduce memory leak
1190 | if (Dectorator.data("debug")) {
1191 | head.removeChild(node);
1192 | }
1193 |
1194 | // Dereference the node
1195 | node = null;
1196 |
1197 | callback && callback(e);
1198 | }
1199 | }
1200 | }
1201 | }], [{
1202 | key: "getDriver",
1203 | value: function getDriver(path) {
1204 | return Driver.DRIVERS[path.uri];
1205 | }
1206 | }, {
1207 | key: "addDriver",
1208 | value: function addDriver(driver) {
1209 | Driver.DRIVERS[driver.path.uri] = driver;
1210 | }
1211 | }, {
1212 | key: "registerDriverLoaded",
1213 | value: function registerDriverLoaded(method) {
1214 | if (!_utils2["default"].isFunction(method)) {
1215 | return;
1216 | }Hook.$on("DRIVER_LOADED", function (that) {
1217 | method.call(that);
1218 | });
1219 | }
1220 | }, {
1221 | key: "registerDriverLoader",
1222 | value: function registerDriverLoader(ext, method) {
1223 | if (!_utils2["default"].isFunction(method)) {
1224 | return;
1225 | }ext = ext.trim();
1226 | ext = ext.toUpperCase();
1227 | Hook.$one("DRIVER_LOADER_" + ext, function (that) {
1228 | method.call(that, that.path.uri, that.loaded.bind(that));
1229 | });
1230 | }
1231 | }, {
1232 | key: "registerDriverBeforeLoad",
1233 | value: function registerDriverBeforeLoad(method) {
1234 | if (!_utils2["default"].isFunction(method)) {
1235 | return;
1236 | }Hook.$on("DRIVER_BEFORE_LOAD", function (that) {
1237 | method.call(that);
1238 | });
1239 | }
1240 | }]);
1241 |
1242 | return Driver;
1243 | })(_Emitter6["default"]);
1244 |
1245 | Driver.DRIVERS = {};
1246 |
1247 | var Path = (function (_Emitter3) {
1248 | function Path(id, baseUrl) {
1249 | _classCallCheck(this, Path);
1250 |
1251 | _get(Object.getPrototypeOf(Path.prototype), "constructor", this).call(this);
1252 | this.baseUrl = baseUrl || Data.baseUrl;
1253 | this.id = id || "";
1254 | this._initId();
1255 | this._maper();
1256 | this._parser();
1257 | this._initUri();
1258 | }
1259 |
1260 | _inherits(Path, _Emitter3);
1261 |
1262 | _createClass(Path, [{
1263 | key: "_initId",
1264 | value: function _initId() {
1265 | if (!this.id) {
1266 | return;
1267 | }var _id = this.id;
1268 | this.query = _utils2["default"].getQuery(_id);
1269 | this.hash = _utils2["default"].getHash(this.id);
1270 | this.id = this.id.replace(/(#|\?).*/, "");
1271 | }
1272 | }, {
1273 | key: "_initUri",
1274 | value: function _initUri() {
1275 | this.baseUrl = this.baseUrl.replace(/\/$/, "") + "/";
1276 | this.uri = this.uri ? _utils2["default"].resolvePath(this.baseUrl, this.uri) : this.id ? _utils2["default"].resolvePath(this.baseUrl, this.id) : _utils2["default"].getCurrentScript().uri;
1277 | this._initExt();
1278 | }
1279 | }, {
1280 | key: "_initExt",
1281 | value: function _initExt() {
1282 | var ext = this.uri.match(/\.(\w+)$/);
1283 | if (ext && ext[1]) {
1284 | ext = ext[1].toLocaleLowerCase();
1285 | if (Path.__EXTS__.indexOf(ext) != -1) {
1286 | this.ext = ext;
1287 | } else {
1288 | this.$emit("FILE_EXTS_PARSER", this);
1289 | if (!Path.__EXTS__.indexOf(this.ext)) {
1290 | this.ext = "js";
1291 | }
1292 | }
1293 | } else {
1294 | this.ext = "js";
1295 | this.uri += ".js";
1296 | }
1297 | }
1298 | }, {
1299 | key: "_maper",
1300 | value: function _maper() {
1301 | if (!this.id) {
1302 | return;
1303 | }Hook.$emit("PATH_MAPER", this);
1304 | }
1305 | }, {
1306 | key: "_parser",
1307 | value: function _parser() {
1308 | if (!this.id) {
1309 | return;
1310 | }this._parseVars();
1311 | Hook.$emit("PATH_PARSER", this);
1312 | }
1313 | }, {
1314 | key: "_parseVars",
1315 | value: function _parseVars() {
1316 | this.baseUrl = this.template(this.baseUrl);
1317 | this.id = this.template(this.id);
1318 | this.uri = this.uri ? this.template(this.uri) : "";
1319 | }
1320 | }, {
1321 | key: "getModule",
1322 | value: function getModule() {
1323 | return ModuleCache.find(this);
1324 | }
1325 | }, {
1326 | key: "equal",
1327 | value: function equal(path) {
1328 | return this.id && this.id == path.id || this.uri && this.uri == path.uri;
1329 | }
1330 | }, {
1331 | key: "getMap",
1332 | value: function getMap(obj) {
1333 | var result = null,
1334 | that = this;
1335 | if (_utils2["default"].isArray(obj)) {
1336 | obj.forEach(function (item) {
1337 | if (item.equal && item.equal(that) || item.path && item.path.equal(that)) {
1338 | result = item;
1339 | return false;
1340 | }
1341 | });
1342 | } else if (_utils2["default"].isObject(obj)) {
1343 | return obj && obj[this.id || this.uri];
1344 | }
1345 | return result;
1346 | }
1347 | }, {
1348 | key: "template",
1349 | value: function template(url) {
1350 | if (!_utils2["default"].isString(url)) throw new Error("路径类型错误");
1351 | var reg = /\{([^{}]+)\}/g,
1352 | res = undefined,
1353 | that = this;
1354 | res = url.replace(reg, function (match, param) {
1355 | return Data.vars && Data.vars[param] ? Data.vars[param] : param;
1356 | });
1357 | if (reg.test(res)) {
1358 | return that.template(res);
1359 | } else {
1360 | return res;
1361 | }
1362 | }
1363 | }], [{
1364 | key: "registerFileExtParser",
1365 | value: function registerFileExtParser(method) {
1366 | if (!_utils2["default"].isFunction(method)) {
1367 | return;
1368 | }Hook.$on("FILE_EXTS_PARSER", function (that) {
1369 | method.call(that);
1370 | });
1371 | }
1372 | }, {
1373 | key: "registerPathParser",
1374 | value: function registerPathParser(method) {
1375 | if (!_utils2["default"].isFunction(method)) {
1376 | return;
1377 | }Hook.$on("PATH_PARSER", function (that) {
1378 | method.call(that);
1379 | });
1380 | }
1381 | }, {
1382 | key: "registerPathMaper",
1383 | value: function registerPathMaper(method) {
1384 | if (!_utils2["default"].isFunction(method)) {
1385 | return;
1386 | }Hook.$on("PATH_MAPER", function (that) {
1387 | method.call(that);
1388 | });
1389 | }
1390 | }, {
1391 | key: "createPath",
1392 | value: function createPath(id, baseUrl) {
1393 | return new Path(id, baseUrl);
1394 | }
1395 | }]);
1396 |
1397 | return Path;
1398 | })(_Emitter6["default"]);
1399 |
1400 | Path.__EXTS__ = ["js", "css", "json", "jsonp", "tpl", "html"];
1401 |
1402 | var Module = (function (_Emitter4) {
1403 | function Module(meta) {
1404 | _classCallCheck(this, Module);
1405 |
1406 | _get(Object.getPrototypeOf(Module.prototype), "constructor", this).call(this);
1407 | _utils2["default"].options(this, {
1408 | path: null,
1409 | depPaths: [],
1410 | factory: null,
1411 | injectors: {},
1412 | installed: false,
1413 | module: {
1414 | exports: null
1415 | }
1416 | }, meta);
1417 | Hook.$emit("MODULE_PARSER", this);
1418 | }
1419 |
1420 | _inherits(Module, _Emitter4);
1421 |
1422 | _createClass(Module, [{
1423 | key: "getInjector",
1424 | value: function getInjector(path) {
1425 | var injector = this.injectors[path.id];
1426 | if (injector) {
1427 | return Module.createModule(path.id, injector);
1428 | }
1429 | }
1430 | }, {
1431 | key: "invoke",
1432 | value: function invoke() {
1433 | var that = this;
1434 | return new _Promise(function (resolve) {
1435 | if (that.installed) {
1436 | resolve(_Promise.resolve(that.module.exports));
1437 | } else if (that.factory) {
1438 | resolve(_Promise.resolve(that._inject()));
1439 | } else {
1440 | if (that.path && !that.factory) {
1441 | resolve(Request.fetch(that, that.path).then(function (modules) {
1442 | return _Promise.resolve(modules[0]._inject());
1443 | }));
1444 | } else {
1445 | throw new Error("模块不符合规范!");
1446 | }
1447 | }
1448 | });
1449 | }
1450 | }, {
1451 | key: "_collectDeps",
1452 | value: function _collectDeps() {
1453 | var that = this,
1454 | dependencies = [],
1455 | injector = undefined;
1456 | return Request.fetch(this, this.depPaths).then(function (modules) {
1457 | return new _Promise(function (resolve) {
1458 | if (that.depPaths.length > 0) {
1459 | that.depPaths.forEach(function (path, index) {
1460 | injector = path.getMap(modules);
1461 | if (injector) {
1462 | dependencies[index] = injector.invoke();
1463 | if (dependencies.length == that.depPaths.length) {
1464 | resolve(_Promise.all(dependencies));
1465 | }
1466 | }
1467 | });
1468 | } else {
1469 | resolve(_Promise.all([]));
1470 | }
1471 | });
1472 | });
1473 | }
1474 | }, {
1475 | key: "_inject",
1476 | value: function _inject() {
1477 | var that = this;
1478 | return this._collectDeps().then(function (dependencies) {
1479 | var instance = that.factory.apply(null, dependencies);
1480 | if (that.module.exports) {
1481 | instance = that.module.exports;
1482 | } else {
1483 | that.module.exports = instance;
1484 | }
1485 | that.installed = true;
1486 | return instance;
1487 | });
1488 | }
1489 | }], [{
1490 | key: "createModule",
1491 | value: function createModule() {
1492 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
1493 | args[_key] = arguments[_key];
1494 | }
1495 |
1496 | return new Module(Module.parseMeta.apply(null, args));
1497 | }
1498 | }, {
1499 | key: "parseMeta",
1500 | value: function parseMeta() {
1501 | for (var _len2 = arguments.length, params = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1502 | params[_key2] = arguments[_key2];
1503 | }
1504 |
1505 | var meta = {},
1506 | auto_path = false;
1507 | if (_utils2["default"].isBoolean(params[0])) {
1508 | auto_path = params[0];
1509 | params = params.slice(1);
1510 | }
1511 | params.forEach(function (param) {
1512 | if (_utils2["default"].isFunction(param)) {
1513 | meta.factory = param;
1514 | } else if (_utils2["default"].isArray(param)) {
1515 | if (_utils2["default"].isFunction(param[param.length - 1])) {
1516 | meta.factory = param[param.length - 1];
1517 | meta.depPaths = param.slice(0, param.length - 1).map(function (id) {
1518 | return new Path(id);
1519 | });
1520 | } else {
1521 | meta.depPaths = param.map(function (id) {
1522 | return new Path(id);
1523 | });
1524 | }
1525 | } else if (_utils2["default"].isString(param)) {
1526 | meta.path = new Path(param);
1527 | } else if (_utils2["default"].isObject(param)) {
1528 | meta.injectors = param;
1529 | }
1530 | });
1531 | if (!meta.path && auto_path) {
1532 | meta.path = new Path();
1533 | }
1534 | return meta;
1535 | }
1536 | }, {
1537 | key: "registerModuleParser",
1538 | value: function registerModuleParser(method) {
1539 | if (!_utils2["default"].isFunction(method)) {
1540 | return;
1541 | }Hook.$on("MODULE_PARSER", function (that) {
1542 | method.call(that);
1543 | });
1544 | }
1545 | }]);
1546 |
1547 | return Module;
1548 | })(_Emitter6["default"]);
1549 |
1550 | var PluginInterface = {
1551 | registerModuleParser: Module.registerModuleParser,
1552 |
1553 | registerDriverLoader: Driver.registerDriverLoader,
1554 | registerDriverLoaded: Driver.registerDriverLoaded,
1555 | registerDriverBeforeLoad: Driver.registerDriverBeforeLoad,
1556 |
1557 | registerFileExtParser: Path.registerFileExtParser,
1558 | registerPathParser: Path.registerPathParser,
1559 | registerPathMaper: Path.registerPathMaper,
1560 |
1561 | createModule: Module.createModule,
1562 | createPath: Path.createPath
1563 | };
1564 |
1565 | var Dectorator = {
1566 |
1567 | config: function config(options) {
1568 | _utils2["default"].options(Data, options);
1569 | },
1570 |
1571 | data: function data(name) {
1572 | return Data[name] ? Data[name] : Data;
1573 | },
1574 |
1575 | define: function define() {
1576 | for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1577 | args[_key3] = arguments[_key3];
1578 | }
1579 |
1580 | ModuleCache.insert(Module.createModule.apply(null, [true].concat(args)));
1581 | return this;
1582 | },
1583 |
1584 | invoke: function invoke() {
1585 | for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1586 | args[_key4] = arguments[_key4];
1587 | }
1588 |
1589 | return Module.createModule.apply(null, args).invoke();
1590 | },
1591 |
1592 | use: function use(id, callback) {
1593 | var module = Module.createModule(id);
1594 | module.invoke(function (instance) {
1595 | _utils2["default"].isFunction(callback) && callback(instance);
1596 | })["catch"](function (e) {
1597 | throw e;
1598 | });
1599 | },
1600 |
1601 | registerPlugin: function registerPlugin(factory) {
1602 | if (_utils2["default"].isFunction(factory)) {
1603 | factory.call(this, PluginInterface);
1604 | }
1605 | }
1606 | };
1607 |
1608 | exports["default"] = Dectorator;
1609 | module.exports = exports["default"];
1610 |
1611 | },{"./emitter":35,"./utils":37,"babel-runtime/core-js/object/assign":1,"babel-runtime/core-js/promise":3,"babel-runtime/helpers/class-call-check":4,"babel-runtime/helpers/create-class":5,"babel-runtime/helpers/get":6,"babel-runtime/helpers/inherits":7,"babel-runtime/helpers/interop-require-wildcard":8}],35:[function(require,module,exports){
1612 | "use strict";
1613 |
1614 | var _createClass = require("babel-runtime/helpers/create-class")["default"];
1615 |
1616 | var _classCallCheck = require("babel-runtime/helpers/class-call-check")["default"];
1617 |
1618 | var _interopRequireWildcard = require("babel-runtime/helpers/interop-require-wildcard")["default"];
1619 |
1620 | Object.defineProperty(exports, "__esModule", {
1621 | value: true
1622 | });
1623 |
1624 | var _utils = require("./utils");
1625 |
1626 | var _utils2 = _interopRequireWildcard(_utils);
1627 |
1628 | var Emitter = (function () {
1629 | function Emitter(events) {
1630 | _classCallCheck(this, Emitter);
1631 |
1632 | if (events) this.$$EVENTS = events;else this.$$EVENTS = {};
1633 | }
1634 |
1635 | _createClass(Emitter, [{
1636 | key: "$on",
1637 | value: function $on(names, fn) {
1638 | var _this = this;
1639 | names.split(",").forEach(function (_name) {
1640 | if (_utils2["default"].isFunction(fn)) {
1641 | if (_this.$$EVENTS[_name] && _utils2["default"].isArray(_this.$$EVENTS[_name])) _this.$$EVENTS[_name].push(fn);else _this.$$EVENTS[_name] = [fn];
1642 | }
1643 | });
1644 | return this;
1645 | }
1646 | }, {
1647 | key: "$one",
1648 | value: function $one(names, fn) {
1649 | var _this = this;
1650 | names.split(",").forEach(function (_name) {
1651 | if (_utils2["default"].isFunction(fn)) {
1652 | if (!_this.$$EVENTS[_name]) _this.$$EVENTS[_name] = [fn];
1653 | }
1654 | });
1655 | return this;
1656 | }
1657 | }, {
1658 | key: "$emit",
1659 | value: function $emit(_name) {
1660 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1661 | args[_key - 1] = arguments[_key];
1662 | }
1663 |
1664 | var events = this.$$EVENTS[_name];
1665 | if (events && _utils2["default"].isArray(events)) {
1666 | for (var i = 0; i < events.length; i++) {
1667 | events[i].apply(null, args);
1668 | }
1669 | }
1670 | return this;
1671 | }
1672 | }, {
1673 | key: "$remove",
1674 | value: function $remove(_name, fn) {
1675 | var events = this.$$EVENTS[_name];
1676 | if (events && _utils2["default"].isArray(events)) {
1677 | if (fn) {
1678 | for (var i = events.length - 1; i >= 0; i--) {
1679 | if (fn === events[i]) {
1680 | events.splice(i, 1);
1681 | }
1682 | }
1683 | } else {
1684 | delete this.$$EVENTS[_name];
1685 | }
1686 | }
1687 | return this;
1688 | }
1689 | }]);
1690 |
1691 | return Emitter;
1692 | })();
1693 |
1694 | exports["default"] = Emitter;
1695 | module.exports = exports["default"];
1696 |
1697 | },{"./utils":37,"babel-runtime/helpers/class-call-check":4,"babel-runtime/helpers/create-class":5,"babel-runtime/helpers/interop-require-wildcard":8}],36:[function(require,module,exports){
1698 | "use strict";
1699 |
1700 | var _Object$assign = require("babel-runtime/core-js/object/assign")["default"];
1701 |
1702 | var _interopRequireWildcard = require("babel-runtime/helpers/interop-require-wildcard")["default"];
1703 |
1704 | var _utils = require("./utils");
1705 |
1706 | var _utils2 = _interopRequireWildcard(_utils);
1707 |
1708 | var _Emitter = require("./emitter");
1709 |
1710 | var _Emitter2 = _interopRequireWildcard(_Emitter);
1711 |
1712 | var _core = require("./core");
1713 |
1714 | var _core2 = _interopRequireWildcard(_core);
1715 |
1716 | var KVM = {};
1717 | window.kvm = window.KVM = KVM;
1718 | window.kvm.Module = window.kvm.module = _core2["default"];
1719 | _core2["default"].define.amd = true;
1720 | window.define = _core2["default"].define;
1721 | _Object$assign(KVM, _utils2["default"]);
1722 |
1723 | _core2["default"].define("$emitter", function () {
1724 | return _Emitter2["default"];
1725 | });
1726 |
1727 | },{"./core":34,"./emitter":35,"./utils":37,"babel-runtime/core-js/object/assign":1,"babel-runtime/helpers/interop-require-wildcard":8}],37:[function(require,module,exports){
1728 | 'use strict';
1729 |
1730 | var _Object$assign = require('babel-runtime/core-js/object/assign')['default'];
1731 |
1732 | Object.defineProperty(exports, '__esModule', {
1733 | value: true
1734 | });
1735 | var hasOwnProperty = Object.prototype.hasOwnProperty;
1736 |
1737 | var TYPES = 'Function,String,Array,Object,Number,Boolean'.split(',');
1738 |
1739 | var utils = {
1740 | isReference: function isReference(val) {
1741 | return this.isArray(val) || this.isObject(val);
1742 | },
1743 | isValue: function isValue(val) {
1744 | return !this.isReference(val);
1745 | },
1746 | isEmpty: function isEmpty(obj) {
1747 | if (obj == null) {
1748 | return true;
1749 | }if (obj.length > 0) {
1750 | return false;
1751 | }if (obj.length === 0) {
1752 | return true;
1753 | }for (var key in obj) {
1754 | if (hasOwnProperty.call(obj, key)) {
1755 | return false;
1756 | }
1757 | }
1758 |
1759 | return true;
1760 | },
1761 | options: function options() {
1762 | for (var _len = arguments.length, source = Array(_len), _key = 0; _key < _len; _key++) {
1763 | source[_key] = arguments[_key];
1764 | }
1765 |
1766 | return _Object$assign.apply(Object, source);
1767 | },
1768 | addQueryString: function addQueryString(url, query) {
1769 | var parser = document.createElement('a');
1770 | var str = '?';
1771 | var key = undefined;
1772 | parser.href = url.replace('?', '');
1773 | for (key in query) {
1774 | if (query.hasOwnProperty(key) && query[key]) {
1775 | str += '' + key + '=' + query[key] + '&';
1776 | }
1777 | }
1778 | parser.search = str.replace(/&$/, '');
1779 | return parser.toString();
1780 | },
1781 | getQuery: function getQuery(url) {
1782 | var parser = document.createElement('a');
1783 | parser.href = url;
1784 | return this.resolveQuery(parser.search);
1785 | },
1786 | getHash: function getHash(url) {
1787 | var parser = document.createElement('a');
1788 | parser.href = url;
1789 | return parser.hash.replace(/^#/, '');
1790 | },
1791 | addHashString: function addHashString(url, hash) {
1792 | var parser = document.createElement('a');
1793 | parser.href = url;
1794 | parser.hash = '#' + hash.replace(/^#/, '');
1795 | return parser.toString();
1796 | },
1797 | resolveQuery: function resolveQuery(query) {
1798 | var vars = query.replace('?', '').split('&'),
1799 | result = {};
1800 | for (var i = 0; i < vars.length; i++) {
1801 | if (vars[i]) {
1802 | var pair = vars[i].split('=');
1803 | result[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
1804 | }
1805 | }
1806 | return result;
1807 | },
1808 | isAbsolutePath: function isAbsolutePath(path) {
1809 | var reg = new RegExp('^(?:[a-z]+:)?//', 'i');
1810 | return reg.test(path);
1811 | },
1812 | resolvePath: function resolvePath() {
1813 | for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1814 | args[_key2] = arguments[_key2];
1815 | }
1816 |
1817 | var numUrls = args.length;
1818 |
1819 | if (numUrls === 0) {
1820 | throw new Error('resolveUrl requires at least one argument; got none.');
1821 | }
1822 |
1823 | var base = document.createElement('base');
1824 | base.href = args[0];
1825 |
1826 | if (numUrls === 1) {
1827 | return base.href;
1828 | }
1829 |
1830 | var head = document.getElementsByTagName('head')[0];
1831 | head.insertBefore(base, head.firstChild);
1832 |
1833 | var a = document.createElement('a');
1834 | var resolved = '';
1835 |
1836 | for (var index = 1; index < numUrls; index++) {
1837 | a.href = args[index];
1838 | resolved = a.href;
1839 | base.href = resolved;
1840 | }
1841 |
1842 | head.removeChild(base);
1843 | return resolved;
1844 | },
1845 | before: function before(context, name, fn) {
1846 | var _fn;
1847 | context = context || window;
1848 | _fn = context[name];
1849 | context[name] = function () {
1850 | for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1851 | args[_key3] = arguments[_key3];
1852 | }
1853 |
1854 | var result = fn.apply(context, args);
1855 | args.push(result);
1856 | _fn.apply(context, args);
1857 | return result;
1858 | };
1859 | },
1860 | after: function after(context, name, fn) {
1861 | var _fn;
1862 | context = context || window;
1863 | _fn = context[name];
1864 | context[name] = function () {
1865 | for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1866 | args[_key4] = arguments[_key4];
1867 | }
1868 |
1869 | var result = _fn.apply(context, args);
1870 | args.push(result);
1871 | return fn.apply(context, args);
1872 | };
1873 | },
1874 | getCurrentScript: function getCurrentScript() {
1875 | var uri = (function _getCur() {
1876 | var doc = document;
1877 | var head = doc.head || doc.getElementsByTagName('head')[0] || doc.documentElement;
1878 | if (doc.currentScript) {
1879 | return doc.currentScript.src;
1880 | }
1881 | var stack = undefined;
1882 | try {
1883 | a.b.c();
1884 | } catch (e) {
1885 | stack = e.stack;
1886 | if (!stack && window.opera) {
1887 | stack = (String(e).match(/of linked script \S+/g) || []).join(' ');
1888 | }
1889 | }
1890 | if (stack) {
1891 | stack = stack.split(/[@ ]/g).pop();
1892 | stack = stack[0] == '(' ? stack.slice(1, -1) : stack;
1893 | return stack.replace(/(:\d+)?:\d+$/i, '');
1894 | }
1895 | var nodes = head.getElementsByTagName('script');
1896 | for (var i = 0, node = undefined; node = nodes[i++];) {
1897 | if (node.readyState === 'interactive') {
1898 | return node.className = node.src;
1899 | }
1900 | }
1901 | })();
1902 | return {
1903 | uri: uri.replace(/(#|\?).*/, ''),
1904 | query: this.getQuery(uri),
1905 | hash: this.getHash(uri)
1906 | };
1907 | }
1908 | };
1909 |
1910 | TYPES.forEach(function (name) {
1911 | return utils['is' + name] = function (val) {
1912 | return Object.prototype.toString.call(val) === '[object ' + name + ']';
1913 | };
1914 | });
1915 |
1916 | exports['default'] = utils;
1917 | module.exports = exports['default'];
1918 |
1919 | },{"babel-runtime/core-js/object/assign":1}]},{},[36])
--------------------------------------------------------------------------------
/dist/kvm.min.js:
--------------------------------------------------------------------------------
1 | /**
2 | ** kvm.js - 一款兼容AMD,CMD,angular模块规范同时支持依赖注入的模块管理器
3 | ** @author Janry
4 | ** @version v0.2.2
5 | **/
6 | !function e(t,r,n){function i(a,u){if(!r[a]){if(!t[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(o)return o(a,!0);throw new Error("Cannot find module '"+a+"'")}var c=r[a]={exports:{}};t[a][0].call(c.exports,function(e){var r=t[a][1][e];return i(r?r:e)},c,c.exports,e,t,r,n)}return r[a].exports}for(var o="function"==typeof require&&require,a=0;ai;)for(var o,a=r.ES5Object(arguments[i++]),u=r.getKeys(a),s=u.length,c=0;s>c;)t[o=u[c++]]=a[o];return t}},{"./$":21}],14:[function(e,t){function r(e){return o.call(e).slice(8,-1)}var n=e("./$"),i=e("./$.wks")("toStringTag"),o={}.toString;r.classof=function(e){var t,n;return void 0==e?void 0===e?"Undefined":"Null":"string"==typeof(n=(t=Object(e))[i])?n:r(t)},r.set=function(e,t,r){e&&!n.has(e=r?e:e.prototype,i)&&n.hide(e,i,t)},t.exports=r},{"./$":21,"./$.wks":27}],15:[function(e,t){var r=e("./$.assert").fn;t.exports=function(e,t,n){if(r(e),~n&&void 0===t)return e;switch(n){case 1:return function(r){return e.call(t,r)};case 2:return function(r,n){return e.call(t,r,n)};case 3:return function(r,n,i){return e.call(t,r,n,i)}}return function(){return e.apply(t,arguments)}}},{"./$.assert":12}],16:[function(e,t){function r(e,t){return function(){return e.apply(t,arguments)}}function n(e,t,s){var c,l,f,d,h=e&n.G,p=h?o:e&n.S?o[t]:(o[t]||{}).prototype,v=h?a:a[t]||(a[t]={});h&&(s=t);for(c in s)l=!(e&n.F)&&p&&c in p,l&&c in v||(f=l?p[c]:s[c],h&&!u(p[c])?d=s[c]:e&n.B&&l?d=r(f,o):e&n.W&&p[c]==f?!function(e){d=function(t){return this instanceof e?new e(t):e(t)},d.prototype=e.prototype}(f):d=e&n.P&&u(f)?r(Function.call,f):f,i.hide(v,c,d))}var i=e("./$"),o=i.g,a=i.core,u=i.isFunction;n.F=1,n.G=2,n.S=4,n.P=8,n.B=16,n.W=32,t.exports=n},{"./$":21}],17:[function(e,t){t.exports=function(e){return e.FW=!1,e.path=e.core,e}},{}],18:[function(e,t){t.exports=function(e,t,r){var n=void 0===r;switch(t.length){case 0:return n?e():e.call(r);case 1:return n?e(t[0]):e.call(r,t[0]);case 2:return n?e(t[0],t[1]):e.call(r,t[0],t[1]);case 3:return n?e(t[0],t[1],t[2]):e.call(r,t[0],t[1],t[2]);case 4:return n?e(t[0],t[1],t[2],t[3]):e.call(r,t[0],t[1],t[2],t[3]);case 5:return n?e(t[0],t[1],t[2],t[3],t[4]):e.call(r,t[0],t[1],t[2],t[3],t[4])}return e.apply(r,t)}},{}],19:[function(e,t){var r=e("./$.wks")("iterator"),n=!1;try{var i=[7][r]();i["return"]=function(){n=!0},Array.from(i,function(){throw 2})}catch(o){}t.exports=function(e){if(!n)return!1;var t=!1;try{var i=[7],o=i[r]();o.next=function(){t=!0},i[r]=function(){return o},e(i)}catch(a){}return t}},{"./$.wks":27}],20:[function(e,t){"use strict";function r(e,t){u.hide(e,d,t),h in[]&&u.hide(e,h,t)}function n(e,t,n,i){var o=e.prototype,a=o[d]||o[h]||i&&o[i]||n;if(u.FW&&r(o,a),a!==n){var s=u.getProto(a.call(new e));c.set(s,t+" Iterator",!0),u.FW&&u.has(o,h)&&r(s,u.that)}return p[t]=a,p[t+" Iterator"]=u.that,a}function i(e){var t=u.g.Symbol,r=e[t&&t.iterator||h],n=r||e[d]||p[c.classof(e)];return f(n.call(e))}function o(e){var t=e["return"];void 0!==t&&f(t.call(e))}function a(e,t,r,n){try{return n?t(f(r)[0],r[1]):t(r)}catch(i){throw o(e),i}}var u=e("./$"),s=e("./$.ctx"),c=e("./$.cof"),l=e("./$.def"),f=e("./$.assert").obj,d=e("./$.wks")("iterator"),h="@@iterator",p={},v={},g="keys"in[]&&!("next"in[].keys());r(v,u.that);var m=t.exports={BUGGY:g,Iterators:p,prototype:v,step:function(e,t){return{value:t,done:!!e}},stepCall:a,close:o,is:function(e){var t=Object(e),r=u.g.Symbol,n=r&&r.iterator||h;return n in t||d in t||u.has(p,c.classof(t))},get:i,set:r,create:function(e,t,r,n){e.prototype=u.create(n||m.prototype,{next:u.desc(1,r)}),c.set(e,t+" Iterator")},define:n,std:function(e,t,r,i,o,a,s){function c(e){return function(){return new r(this,e)}}m.create(r,t,i);var f,d,h=c("key+value"),p=c("value"),v=e.prototype;if("value"==o?p=n(e,t,p,"values"):h=n(e,t,h,"entries"),o&&(f={entries:h,keys:a?p:c("key"),values:p},l(l.P+l.F*g,t,f),s))for(d in f)d in v||u.hide(v,d,f[d])},forOf:function(e,t,r,n){for(var u,c=i(e),l=s(r,n,t?2:1);!(u=c.next()).done;)if(a(c,l,u.value,t)===!1)return o(c)}}},{"./$":21,"./$.assert":12,"./$.cof":14,"./$.ctx":15,"./$.def":16,"./$.wks":27}],21:[function(e,t){"use strict";function r(e){return isNaN(e=+e)?0:(e>0?p:h)(e)}function n(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}function i(e,t,r){return e[t]=r,e}function o(e){return m?function(t,r,i){return b.setDesc(t,r,n(e,i))}:i}function a(e){return null!==e&&("object"==typeof e||"function"==typeof e)}function u(e){return"function"==typeof e}function s(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}var c="undefined"!=typeof self?self:Function("return this")(),l={},f=Object.defineProperty,d={}.hasOwnProperty,h=Math.ceil,p=Math.floor,v=Math.max,g=Math.min,m=!!function(){try{return 2==f({},"a",{get:function(){return 2}}).a}catch(e){}}(),y=o(1),b=t.exports=e("./$.fw")({g:c,core:l,html:c.document&&document.documentElement,isObject:a,isFunction:u,it:function(e){return e},that:function(){return this},toInteger:r,toLength:function(e){return e>0?g(r(e),9007199254740991):0},toIndex:function(e,t){return e=r(e),0>e?v(e+t,0):g(e,t)},has:function(e,t){return d.call(e,t)},create:Object.create,getProto:Object.getPrototypeOf,DESC:m,desc:n,getDesc:Object.getOwnPropertyDescriptor,setDesc:f,getKeys:Object.keys,getNames:Object.getOwnPropertyNames,getSymbols:Object.getOwnPropertySymbols,assertDefined:s,ES5Object:Object,toObject:function(e){return b.ES5Object(s(e))},hide:y,def:o(0),set:c.Symbol?i:y,mix:function(e,t){for(var r in t)y(e,r,t[r]);return e},each:[].forEach});"undefined"!=typeof __e&&(__e=l),"undefined"!=typeof __g&&(__g=c)},{"./$.fw":17}],22:[function(e,t){var r=e("./$");t.exports=function(t){r.DESC&&r.FW&&r.setDesc(t,e("./$.wks")("species"),{configurable:!0,get:r.that})}},{"./$":21,"./$.wks":27}],23:[function(e,t){"use strict";var r=e("./$");t.exports=function(e){return function(t){var n,i,o=String(r.assertDefined(this)),a=r.toInteger(t),u=o.length;return 0>a||a>=u?e?"":void 0:(n=o.charCodeAt(a),55296>n||n>56319||a+1===u||(i=o.charCodeAt(a+1))<56320||i>57343?e?o.charAt(a):n:e?o.slice(a,a+2):(n-55296<<10)+(i-56320)+65536)}}},{"./$":21}],24:[function(e,t){"use strict";function r(){var e=+this;if(u.has(j,e)){var t=j[e];delete j[e],t()}}function n(e){r.call(e.data)}var i,o,a,u=e("./$"),s=e("./$.ctx"),c=e("./$.cof"),l=e("./$.invoke"),f=u.g,d=u.isFunction,h=u.html,p=f.document,v=f.process,g=f.setImmediate,m=f.clearImmediate,y=f.postMessage,b=f.addEventListener,$=f.MessageChannel,E=0,j={},w="onreadystatechange";d(g)&&d(m)||(g=function(e){for(var t=[],r=1;arguments.length>r;)t.push(arguments[r++]);return j[++E]=function(){l(d(e)?e:Function(e),t)},i(E),E},m=function(e){delete j[e]},"process"==c(v)?i=function(e){v.nextTick(s(r,e,1))}:b&&d(y)&&!f.importScripts?(i=function(e){y(e,"*")},b("message",n,!1)):d($)?(o=new $,a=o.port2,o.port1.onmessage=n,i=s(a.postMessage,a,1)):i=p&&w in p.createElement("script")?function(e){h.appendChild(p.createElement("script"))[w]=function(){h.removeChild(this),r.call(e)}}:function(e){setTimeout(s(r,e,1),0)}),t.exports={set:g,clear:m}},{"./$":21,"./$.cof":14,"./$.ctx":15,"./$.invoke":18}],25:[function(e,t){function r(e){return"Symbol("+e+")_"+(++n+Math.random()).toString(36)}var n=0;r.safe=e("./$").g.Symbol||r,t.exports=r},{"./$":21}],26:[function(e,t){var r=e("./$"),n=e("./$.wks")("unscopables");!r.FW||n in[]||r.hide(Array.prototype,n,{}),t.exports=function(e){r.FW&&([][n][e]=!0)}},{"./$":21,"./$.wks":27}],27:[function(e,t){var r=e("./$").g,n={};t.exports=function(t){return n[t]||(n[t]=r.Symbol&&r.Symbol[t]||e("./$.uid").safe("Symbol."+t))}},{"./$":21,"./$.uid":25}],28:[function(e){var t=e("./$"),r=e("./$.unscope"),n=e("./$.uid").safe("iter"),i=e("./$.iter"),o=i.step,a=i.Iterators;i.std(Array,"Array",function(e,r){t.set(this,n,{o:t.toObject(e),i:0,k:r})},function(){var e=this[n],t=e.o,r=e.k,i=e.i++;return!t||i>=t.length?(e.o=void 0,o(1)):"key"==r?o(0,i):"value"==r?o(0,t[i]):o(0,[i,t[i]])},"value"),a.Arguments=a.Array,r("keys"),r("values"),r("entries")},{"./$":21,"./$.iter":20,"./$.uid":25,"./$.unscope":26}],29:[function(e){var t=e("./$.def");t(t.S,"Object",{assign:e("./$.assign")})},{"./$.assign":13,"./$.def":16}],30:[function(e){function t(e,t){var a=(r.core.Object||{})[e]||Object[e],u=0,s={};s[e]=1==t?function(e){return i(e)?a(e):e}:2==t?function(e){return i(e)?a(e):!0}:3==t?function(e){return i(e)?a(e):!1}:4==t?function(e,t){return a(o(e),t)}:5==t?function(e){return a(Object(r.assertDefined(e)))}:function(e){return a(o(e))};try{a("z")}catch(c){u=1}n(n.S+n.F*u,"Object",s)}var r=e("./$"),n=e("./$.def"),i=r.isObject,o=r.toObject;t("freeze",1),t("seal",1),t("preventExtensions",1),t("isFrozen",2),t("isSealed",2),t("isExtensible",3),t("getOwnPropertyDescriptor",4),t("getPrototypeOf",5),t("keys"),t("getOwnPropertyNames")},{"./$":21,"./$.def":16}],31:[function(e){"use strict";function t(e){var t=O(e)[p];return void 0!=t?t:e}function r(e){var t;return _(e)&&(t=e.then),w(t)?t:!1}function n(e){var t,r=e[v],i=r.c,o=0;if(r.h)return!1;for(;i.length>o;)if(t=i[o++],t.fail||!n(t.P))return!1;return!0}function i(e,t){var i=e.c;(t||i.length)&&$(function(){var o=e.p,a=e.v,u=1==e.s,s=0;if(t&&n(o))setTimeout(function(){n(o)&&("process"==l(b)?b.emit("unhandledRejection",a,o):y.console&&w(console.error)&&console.error("Unhandled promise rejection",a))},1e3);else for(;i.length>s;)!function(t){var n,i,o=u?t.ok:t.fail;try{o?(u||(e.h=!0),n=o===!0?a:o(a),n===t.P?t.rej(TypeError(m+"-chain cycle")):(i=r(n))?i.call(n,t.res,t.rej):t.res(n)):t.rej(a)}catch(s){t.rej(s)}}(i[s++]);i.length=0})}function o(e){var t=this;t.d||(t.d=!0,t=t.r||t,t.v=e,t.s=2,i(t,!0))}function a(e){var t,n,u=this;if(!u.d){u.d=!0,u=u.r||u;try{(t=r(e))?(n={r:u,d:!1},t.call(e,c(a,n,1),c(o,n,1))):(u.v=e,u.s=1,i(u))}catch(s){o.call(n||{r:u,d:!1},s)}}}var u,s=e("./$"),c=e("./$.ctx"),l=e("./$.cof"),f=e("./$.def"),d=e("./$.assert"),h=e("./$.iter"),p=e("./$.wks")("species"),v=e("./$.uid").safe("record"),g=h.forOf,m="Promise",y=s.g,b=y.process,$=b&&b.nextTick||e("./$.task").set,E=y[m],j=E,w=s.isFunction,_=s.isObject,k=d.fn,O=d.obj;w(E)&&w(E.resolve)&&E.resolve(u=new E(function(){}))==u||(E=function(e){k(e);var t={p:d.inst(this,E,m),c:[],s:0,d:!1,v:void 0,h:!1};s.hide(this,v,t);try{e(c(a,t,1),c(o,t,1))}catch(r){o.call(t,r)}},s.mix(E.prototype,{then:function(e,t){var r=O(O(this).constructor)[p],n={ok:w(e)?e:!0,fail:w(t)?t:!1},o=n.P=new(void 0!=r?r:E)(function(e,t){n.res=k(e),n.rej=k(t)}),a=this[v];return a.c.push(n),a.s&&i(a),o},"catch":function(e){return this.then(void 0,e)}})),f(f.G+f.W+f.F*(E!=j),{Promise:E}),l.set(E,m),e("./$.species")(E),f(f.S,m,{reject:function(e){return new(t(this))(function(t,r){r(e)})},resolve:function(e){return _(e)&&v in e&&s.getProto(e)===this.prototype?e:new(t(this))(function(t){t(e)})}}),f(f.S+f.F*!e("./$.iter-detect")(function(e){E.all(e)["catch"](function(){})}),m,{all:function(e){var r=t(this),n=[];return new r(function(t,i){g(e,!1,n.push,n);var o=n.length,a=Array(o);o?s.each.call(n,function(e,n){r.resolve(e).then(function(e){a[n]=e,--o||t(a)},i)}):t(a)})},race:function(e){var r=t(this);return new r(function(t,n){g(e,!1,function(e){r.resolve(e).then(t,n)})})}})},{"./$":21,"./$.assert":12,"./$.cof":14,"./$.ctx":15,"./$.def":16,"./$.iter":20,"./$.iter-detect":19,"./$.species":22,"./$.task":24,"./$.uid":25,"./$.wks":27}],32:[function(e){var t=e("./$").set,r=e("./$.string-at")(!0),n=e("./$.uid").safe("iter"),i=e("./$.iter"),o=i.step;i.std(String,"String",function(e){t(this,n,{o:String(e),i:0})},function(){var e,t=this[n],i=t.o,a=t.i;return a>=i.length?o(1):(e=r.call(i,a),t.i+=e.length,o(0,e))})},{"./$":21,"./$.iter":20,"./$.string-at":23,"./$.uid":25}],33:[function(e){e("./es6.array.iterator");var t=e("./$"),r=e("./$.iter").Iterators,n=e("./$.wks")("iterator"),i=r.Array,o=t.g.NodeList;!t.FW||!o||n in o.prototype||t.hide(o.prototype,n,i),r.NodeList=i},{"./$":21,"./$.iter":20,"./$.wks":27,"./es6.array.iterator":28}],34:[function(e,t,r){"use strict";var n=e("babel-runtime/helpers/inherits")["default"],i=e("babel-runtime/helpers/get")["default"],o=e("babel-runtime/helpers/create-class")["default"],a=e("babel-runtime/helpers/class-call-check")["default"],u=e("babel-runtime/core-js/promise")["default"],s=e("babel-runtime/core-js/object/assign")["default"],c=e("babel-runtime/helpers/interop-require-wildcard")["default"];Object.defineProperty(r,"__esModule",{value:!0});var l=e("./utils"),f=c(l),d=e("./emitter"),h=c(d),p=new h["default"],v={baseUrl:"",vars:{},packages:{},alias:{},shims:{},version:""},g={MODULES:{},insert:function(e){var t=e.path,r=e.path.id||e.path.uri,n=y.getDriver(t);return this.MODULES[r]||(this.MODULES[r]=e,n&&n.$emit("loaded",e)),this.MODULES[r]},find:function(e){return this.MODULES[e.id||e.uri]||this.MODULES[e.id]||this.MODULES[e.uri]}},m=function(e){function t(e,r,n){a(this,t),i(Object.getPrototypeOf(t.prototype),"constructor",this).call(this),this.sender=e,this.reqs=f["default"].isArray(r)?r:[r],this.drivers=[],this.results=[],this.callback=n,this._parseReqs(),this.send()}return n(t,e),o(t,[{key:"_createDriver",value:function(e){var t=y.getDriver(e),r=this;if(!t){if(t=new y(e),t.beforeLoad(),t.module)return r._done(t.module);this.drivers.push(t)}return t.module?r._done(t.module):t.$on("loaded",function(e){t.module=e,r._done(e)}),this}},{key:"_parseReqs",value:function(){var e=this,t=void 0;return this.reqs=this.reqs.filter(function(e){return!!e}),this.reqs.length>0?this.reqs.forEach(function(r){t=e.sender.getInjector(r),t=t||r.getModule(),t?e._done(t):e._createDriver(r)}):e.callback([]),this}},{key:"_checkDone",value:function(){return this.reqs.length==this.results.length}},{key:"_done",value:function(e){return this.results.push(e),this._checkDone()&&f["default"].isFunction(this.callback)&&this.callback(this.results),this}},{key:"send",value:function(){return this.drivers.forEach(function(e){e.load()}),this}}],[{key:"fetch",value:function(e,r){return r=f["default"].isArray(r)?r:[r],new u(function(n){new t(e,r,function(e){n(e)})})}}]),t}(h["default"]),y=function(e){function t(e){a(this,t),i(Object.getPrototypeOf(t.prototype),"constructor",this).call(this),this.path=e,this.module=null,t.getDriver(e)||t.addDriver(this)}return n(t,e),o(t,[{key:"beforeLoad",value:function(){p.$emit("DRIVER_BEFORE_LOAD",this)}},{key:"load",value:function(){var e=this.path,t=e.uri;t=f["default"].addQueryString(t,s({version:v.version},e.query)),t=f["default"].addHashString(t,e.hash),"js"!=e.ext?p.$emit("DRIVER_LOADER_"+e.ext.toLocaleUpperCase(),this):this._loadJS(t,this.loaded.bind(this))}},{key:"loaded",value:function(e,t){var r=this.path;"js"!=r.ext?j.define(r.id,function(){return t}):p.$emit("DRIVER_LOADED",this,e,t)}},{key:"_loadJS",value:function(e,t){function r(e,t){function r(r){e.onload=e.onerror=e.onreadystatechange=null,j.data("debug")&&i.removeChild(e),e=null,t&&t(r)}var n="onload"in e;n?(e.onload=r,e.onerror=function(){r(!0)}):e.onreadystatechange=function(){/loaded|complete/.test(e.readyState)&&r()}}var n=document,i=n.head||n.getElementsByTagName("head")[0]||n.documentElement,o=i.getElementsByTagName("base")[0],a=n.createElement("script");a.async=!0,a.src=e,r(a,t),o?i.insertBefore(a,o):i.appendChild(a)}}],[{key:"getDriver",value:function(e){return t.DRIVERS[e.uri]}},{key:"addDriver",value:function(e){t.DRIVERS[e.path.uri]=e}},{key:"registerDriverLoaded",value:function(e){f["default"].isFunction(e)&&p.$on("DRIVER_LOADED",function(t){e.call(t)})}},{key:"registerDriverLoader",value:function(e,t){f["default"].isFunction(t)&&(e=e.trim(),e=e.toUpperCase(),p.$one("DRIVER_LOADER_"+e,function(e){t.call(e,e.path.uri,e.loaded.bind(e))}))}},{key:"registerDriverBeforeLoad",value:function(e){f["default"].isFunction(e)&&p.$on("DRIVER_BEFORE_LOAD",function(t){e.call(t)})}}]),t}(h["default"]);y.DRIVERS={};var b=function(e){function t(e,r){a(this,t),i(Object.getPrototypeOf(t.prototype),"constructor",this).call(this),this.baseUrl=r||v.baseUrl,this.id=e||"",this._initId(),this._maper(),this._parser(),this._initUri()}return n(t,e),o(t,[{key:"_initId",value:function(){if(this.id){var e=this.id;this.query=f["default"].getQuery(e),this.hash=f["default"].getHash(this.id),this.id=this.id.replace(/(#|\?).*/,"")}}},{key:"_initUri",value:function(){this.baseUrl=this.baseUrl.replace(/\/$/,"")+"/",this.uri=this.uri?f["default"].resolvePath(this.baseUrl,this.uri):this.id?f["default"].resolvePath(this.baseUrl,this.id):f["default"].getCurrentScript().uri,this._initExt()}},{key:"_initExt",value:function(){var e=this.uri.match(/\.(\w+)$/);e&&e[1]?(e=e[1].toLocaleLowerCase(),-1!=t.__EXTS__.indexOf(e)?this.ext=e:(this.$emit("FILE_EXTS_PARSER",this),t.__EXTS__.indexOf(this.ext)||(this.ext="js"))):(this.ext="js",this.uri+=".js")}},{key:"_maper",value:function(){this.id&&p.$emit("PATH_MAPER",this)}},{key:"_parser",value:function(){this.id&&(this._parseVars(),p.$emit("PATH_PARSER",this))}},{key:"_parseVars",value:function(){this.baseUrl=this.template(this.baseUrl),this.id=this.template(this.id),this.uri=this.uri?this.template(this.uri):""}},{key:"getModule",value:function(){return g.find(this)}},{key:"equal",value:function(e){return this.id&&this.id==e.id||this.uri&&this.uri==e.uri}},{key:"getMap",value:function(e){var t=null,r=this;if(f["default"].isArray(e))e.forEach(function(e){return e.equal&&e.equal(r)||e.path&&e.path.equal(r)?(t=e,!1):void 0});else if(f["default"].isObject(e))return e&&e[this.id||this.uri];return t}},{key:"template",value:function(e){if(!f["default"].isString(e))throw new Error("路径类型错误");var t=/\{([^{}]+)\}/g,r=void 0,n=this;return r=e.replace(t,function(e,t){return v.vars&&v.vars[t]?v.vars[t]:t}),t.test(r)?n.template(r):r}}],[{key:"registerFileExtParser",value:function(e){f["default"].isFunction(e)&&p.$on("FILE_EXTS_PARSER",function(t){e.call(t)})}},{key:"registerPathParser",value:function(e){f["default"].isFunction(e)&&p.$on("PATH_PARSER",function(t){e.call(t)})}},{key:"registerPathMaper",value:function(e){f["default"].isFunction(e)&&p.$on("PATH_MAPER",function(t){e.call(t)})}},{key:"createPath",value:function(e,r){return new t(e,r)}}]),t}(h["default"]);b.__EXTS__=["js","css","json","jsonp","tpl","html"];var $=function(e){function t(e){a(this,t),i(Object.getPrototypeOf(t.prototype),"constructor",this).call(this),f["default"].options(this,{path:null,depPaths:[],factory:null,injectors:{},installed:!1,module:{exports:null}},e),p.$emit("MODULE_PARSER",this)}return n(t,e),o(t,[{key:"getInjector",value:function(e){var r=this.injectors[e.id];return r?t.createModule(e.id,r):void 0}},{key:"invoke",value:function(){var e=this;return new u(function(t){if(e.installed)t(u.resolve(e.module.exports));else if(e.factory)t(u.resolve(e._inject()));else{if(!e.path||e.factory)throw new Error("模块不符合规范!");t(m.fetch(e,e.path).then(function(e){return u.resolve(e[0]._inject())}))}})}},{key:"_collectDeps",value:function(){var e=this,t=[],r=void 0;return m.fetch(this,this.depPaths).then(function(n){return new u(function(i){e.depPaths.length>0?e.depPaths.forEach(function(o,a){r=o.getMap(n),r&&(t[a]=r.invoke(),t.length==e.depPaths.length&&i(u.all(t)))}):i(u.all([]))})})}},{key:"_inject",value:function(){var e=this;return this._collectDeps().then(function(t){var r=e.factory.apply(null,t);return e.module.exports?r=e.module.exports:e.module.exports=r,e.installed=!0,r})}}],[{key:"createModule",value:function(){for(var e=arguments.length,r=Array(e),n=0;e>n;n++)r[n]=arguments[n];return new t(t.parseMeta.apply(null,r))}},{key:"parseMeta",value:function(){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];var n={},i=!1;return f["default"].isBoolean(t[0])&&(i=t[0],t=t.slice(1)),t.forEach(function(e){f["default"].isFunction(e)?n.factory=e:f["default"].isArray(e)?f["default"].isFunction(e[e.length-1])?(n.factory=e[e.length-1],n.depPaths=e.slice(0,e.length-1).map(function(e){return new b(e)})):n.depPaths=e.map(function(e){return new b(e)}):f["default"].isString(e)?n.path=new b(e):f["default"].isObject(e)&&(n.injectors=e)}),!n.path&&i&&(n.path=new b),n}},{key:"registerModuleParser",value:function(e){f["default"].isFunction(e)&&p.$on("MODULE_PARSER",function(t){e.call(t)})}}]),t}(h["default"]),E={registerModuleParser:$.registerModuleParser,registerDriverLoader:y.registerDriverLoader,registerDriverLoaded:y.registerDriverLoaded,registerDriverBeforeLoad:y.registerDriverBeforeLoad,registerFileExtParser:b.registerFileExtParser,registerPathParser:b.registerPathParser,registerPathMaper:b.registerPathMaper,createModule:$.createModule,createPath:b.createPath},j={config:function(e){f["default"].options(v,e)},data:function(e){return v[e]?v[e]:v},define:function(){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];return g.insert($.createModule.apply(null,[!0].concat(t))),this},invoke:function(){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];return $.createModule.apply(null,t).invoke()},use:function(e,t){var r=$.createModule(e);r.invoke(function(e){f["default"].isFunction(t)&&t(e)})["catch"](function(e){throw e})},registerPlugin:function(e){f["default"].isFunction(e)&&e.call(this,E)}};r["default"]=j,t.exports=r["default"]},{"./emitter":35,"./utils":37,"babel-runtime/core-js/object/assign":1,"babel-runtime/core-js/promise":3,"babel-runtime/helpers/class-call-check":4,"babel-runtime/helpers/create-class":5,"babel-runtime/helpers/get":6,"babel-runtime/helpers/inherits":7,"babel-runtime/helpers/interop-require-wildcard":8}],35:[function(e,t,r){"use strict";var n=e("babel-runtime/helpers/create-class")["default"],i=e("babel-runtime/helpers/class-call-check")["default"],o=e("babel-runtime/helpers/interop-require-wildcard")["default"];Object.defineProperty(r,"__esModule",{value:!0});var a=e("./utils"),u=o(a),s=function(){function e(t){i(this,e),this.$$EVENTS=t?t:{}}return n(e,[{key:"$on",value:function(e,t){var r=this;return e.split(",").forEach(function(e){u["default"].isFunction(t)&&(r.$$EVENTS[e]&&u["default"].isArray(r.$$EVENTS[e])?r.$$EVENTS[e].push(t):r.$$EVENTS[e]=[t])}),this}},{key:"$one",value:function(e,t){var r=this;return e.split(",").forEach(function(e){u["default"].isFunction(t)&&(r.$$EVENTS[e]||(r.$$EVENTS[e]=[t]))}),this}},{key:"$emit",value:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;t>n;n++)r[n-1]=arguments[n];var i=this.$$EVENTS[e];if(i&&u["default"].isArray(i))for(var o=0;o=0;n--)t===r[n]&&r.splice(n,1);else delete this.$$EVENTS[e];return this}}]),e}();r["default"]=s,t.exports=r["default"]},{"./utils":37,"babel-runtime/helpers/class-call-check":4,"babel-runtime/helpers/create-class":5,"babel-runtime/helpers/interop-require-wildcard":8}],36:[function(e){"use strict";var t=e("babel-runtime/core-js/object/assign")["default"],r=e("babel-runtime/helpers/interop-require-wildcard")["default"],n=e("./utils"),i=r(n),o=e("./emitter"),a=r(o),u=e("./core"),s=r(u),c={};window.kvm=window.KVM=c,window.kvm.Module=window.kvm.module=s["default"],s["default"].define.amd=!0,window.define=s["default"].define,t(c,i["default"]),s["default"].define("$emitter",function(){return a["default"]})},{"./core":34,"./emitter":35,"./utils":37,"babel-runtime/core-js/object/assign":1,"babel-runtime/helpers/interop-require-wildcard":8}],37:[function(e,t,r){"use strict";var n=e("babel-runtime/core-js/object/assign")["default"];Object.defineProperty(r,"__esModule",{value:!0});var i=Object.prototype.hasOwnProperty,o="Function,String,Array,Object,Number,Boolean".split(","),u={isReference:function(e){return this.isArray(e)||this.isObject(e)},isValue:function(e){return!this.isReference(e)},isEmpty:function(e){if(null==e)return!0;if(e.length>0)return!1;if(0===e.length)return!0;for(var t in e)if(i.call(e,t))return!1;return!0},options:function(){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];return n.apply(Object,t)},addQueryString:function(e,t){var r=document.createElement("a"),n="?",i=void 0;r.href=e.replace("?","");for(i in t)t.hasOwnProperty(i)&&t[i]&&(n+=""+i+"="+t[i]+"&");return r.search=n.replace(/&$/,""),r.toString()},getQuery:function(e){var t=document.createElement("a");return t.href=e,this.resolveQuery(t.search)},getHash:function(e){var t=document.createElement("a");return t.href=e,t.hash.replace(/^#/,"")},addHashString:function(e,t){var r=document.createElement("a");return r.href=e,r.hash="#"+t.replace(/^#/,""),r.toString()},resolveQuery:function(e){for(var t=e.replace("?","").split("&"),r={},n=0;nr;r++)t[r]=arguments[r];var n=t.length;if(0===n)throw new Error("resolveUrl requires at least one argument; got none.");var i=document.createElement("base");if(i.href=t[0],1===n)return i.href;var o=document.getElementsByTagName("head")[0];o.insertBefore(i,o.firstChild);for(var a=document.createElement("a"),u="",s=1;n>s;s++)a.href=t[s],u=a.href,i.href=u;return o.removeChild(i),u},before:function(e,t,r){var n;e=e||window,n=e[t],e[t]=function(){for(var t=arguments.length,i=Array(t),o=0;t>o;o++)i[o]=arguments[o];var a=r.apply(e,i);return i.push(a),n.apply(e,i),a}},after:function(e,t,r){var n;e=e||window,n=e[t],e[t]=function(){for(var t=arguments.length,i=Array(t),o=0;t>o;o++)i[o]=arguments[o];var a=n.apply(e,i);return i.push(a),r.apply(e,i)}},getCurrentScript:function(){var e=function(){var e=document,t=e.head||e.getElementsByTagName("head")[0]||e.documentElement;if(e.currentScript)return e.currentScript.src;var r=void 0;try{a.b.c()}catch(n){r=n.stack,!r&&window.opera&&(r=(String(n).match(/of linked script \S+/g)||[]).join(" "))}if(r)return r=r.split(/[@ ]/g).pop(),r="("==r[0]?r.slice(1,-1):r,r.replace(/(:\d+)?:\d+$/i,"");for(var i=t.getElementsByTagName("script"),o=0,u=void 0;u=i[o++];)if("interactive"===u.readyState)return u.className=u.src}();return{uri:e.replace(/(#|\?).*/,""),query:this.getQuery(e),hash:this.getHash(e)}}};o.forEach(function(e){return u["is"+e]=function(t){return Object.prototype.toString.call(t)==="[object "+e+"]"}}),r["default"]=u,t.exports=r["default"]},{"babel-runtime/core-js/object/assign":1}]},{},[36]);
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | var gulp = require('gulp');
2 | var uglify = require('gulp-uglify');
3 | var concat = require('gulp-concat');
4 | var jshint = require('gulp-jshint');
5 | var clean = require('gulp-clean');
6 | var rename = require('gulp-rename');
7 | var header = require('gulp-header');
8 | var serve = require('gulp-serve');
9 | var pkg = require('./package.json');
10 | var browserify = require('gulp-browserify');
11 | var babelify = require('babelify');
12 | var banner = [
13 | '/**',
14 | ' ** <%= pkg.name %> - <%= pkg.description %>',
15 | ' ** @author <%= pkg.author %>',
16 | ' ** @version v<%= pkg.version %>',
17 | ' **/',
18 | ''
19 | ].join('\n');
20 |
21 |
22 | gulp.task('clean',function(){
23 | return gulp.src('dist', {read: false})
24 | .pipe(clean());
25 | });
26 |
27 | /*gulp.task('concat',['clean-scripts'],function () {
28 | return gulp.src([
29 | './src/intro.js',
30 | './src/lang.js',
31 | './src/do.js',
32 | './src/class.js',
33 | './src/emitter.js',
34 | './src/core.js',
35 | './src/kvm.js',
36 | './src/outro.js',
37 | './plugins/*.js'])
38 | .pipe(concat('kvm.js'))
39 | .pipe(jshint())
40 | .pipe(gulp.dest('dist'))
41 | });
42 |
43 | gulp.task('concat-mini',['concat'],function () {
44 | return gulp.src([
45 | './src/intro.js',
46 | './src/lang.js',
47 | './src/do.js',
48 | './src/class.js',
49 | './src/emitter.js',
50 | './src/core.js',
51 | './src/kvm.js',
52 | './src/outro.js'])
53 | .pipe(concat('kvm-mini.js'))
54 | .pipe(jshint())
55 | .pipe(gulp.dest('dist'))
56 | });
57 | */
58 |
59 | gulp.task('build-scripts',['clean'],function(){
60 | return gulp.src('src/kvm.js')
61 | .pipe(browserify({
62 | transform: [babelify.configure({
63 | optional: ["runtime"]
64 | })]
65 | }))
66 | .pipe(gulp.dest('dist'))
67 | });
68 |
69 | gulp.task('build-plugins',function(){
70 | return gulp.src('plugins/*.js')
71 | .pipe(concat('kvm-plugins.js'))
72 | .pipe(gulp.dest('dist'))
73 | });
74 |
75 | gulp.task('compress',['build-scripts','build-plugins'], function () {
76 | return gulp.src('dist/**/*.js')
77 | .pipe(uglify())
78 | .pipe(header(banner, {pkg: pkg}))
79 | .pipe(rename({
80 | extname: '.min.js'
81 | }))
82 | .pipe(gulp.dest('dist'));
83 |
84 | });
85 |
86 | gulp.task('serve',serve({
87 | root: ['dist', 'test'],
88 | port: 3000
89 | }));
90 |
91 | gulp.task('watch',function(){
92 | gulp.watch('./{src,plugins}/*.js', ['compress']);
93 | });
94 |
95 | gulp.task('default',['watch','serve']);
96 |
97 | gulp.task('build',['compress']);
98 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/janryWang/kvm/3923c6b28cb5eb64c1326eff93f8600fe26b5bb5/logo.png
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "kvm.js",
3 | "version": "0.2.2",
4 | "description": "一款兼容AMD,CMD,angular模块规范同时支持依赖注入的模块管理器",
5 | "keywords": [
6 | "模块管理器",
7 | "依赖注入",
8 | "module",
9 | "angular.js",
10 | "AMD",
11 | "CMD",
12 | "reuqire.js",
13 | "Injector"
14 | ],
15 | "author": "Janry",
16 | "files": [
17 | "./dist/kvm.js"
18 | ],
19 | "devDependencies": {
20 | "babelify": "^6.0.2",
21 | "gulp-browserify": "^0.5.1",
22 | "gulp-clean": "^0.3.1",
23 | "gulp-concat": "^2.5.2",
24 | "gulp-header": "^1.2.2",
25 | "gulp-mocha": "^2.0.1",
26 | "gulp-rename": "^1.2.0",
27 | "gulp-serve": "^0.3.1",
28 | "gulp-uglify": "^1.1.0"
29 | },
30 | "dependencies": {
31 | "babel-runtime": "^5.1.11",
32 | "gulp-jshint": "^1.9.2",
33 | "gulp-watch": "^4.1.1"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/plugins/alias.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 可以使kvm支持别名机制
3 | */
4 | (function(){
5 | kvm.module.registerPlugin(function(API){
6 | API.registerPathMaper(function(){
7 | var alias = kvm.module.data('alias');
8 | if(kvm.isAbsolutePath(this.id)) return;
9 | if(alias[this.id]){
10 | this.uri = alias[this.id];
11 | this._parser();
12 | }
13 | });
14 | });
15 | })();
16 |
--------------------------------------------------------------------------------
/plugins/commonjs.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 可以使kvm支持commonjs规范
3 | */
4 |
5 | (function(){
6 |
7 | kvm.module.registerPlugin(function(API){
8 | API.registerModuleParser(function(){
9 | function uniquePath(paths){
10 | var i,j;
11 | for(i=0;i < paths.length;i++){
12 | for(j=i+1;j < paths.length;j++){
13 | if(paths[i].equal(paths[j])){
14 | paths.splice(j,1);
15 | }
16 | }
17 | }
18 | return paths;
19 | }
20 | this.injectCommonjs = function(){
21 | var _this = this;
22 | this.injectors.exports = function () {
23 | _this.module.exports = _this.module.exports || {};
24 | return _this.module.exports;
25 | };
26 | this.injectors.module = function(){
27 | return _this.module;
28 | };
29 | this.injectors.require = function(){
30 | return function(id){
31 | var path = API.createPath(id);
32 | var module = path.getModule();
33 | return module && module.module && module.module.exports ? module.module.exports : {};
34 | }
35 | };
36 | };
37 | this.collectDeps = function(){
38 | var deps;
39 | if(kvm.isFunction(this.factory)) {
40 | deps = this.parseDependencies(this.factory.toString());
41 | deps = deps.map(function(id){
42 | return API.createPath(id);
43 | });
44 | this.depPaths = uniquePath(this.depPaths.concat(deps));
45 | }
46 | };
47 | this.parseDependencies = function (s) {
48 | if(s.indexOf('require') == -1) {
49 | return [];
50 | }
51 | var index = 0, peek, length = s.length, isReg = 1, modName = 0, parentheseState = 0, parentheseStack = [], res = [];
52 | while(index < length) {
53 | readch();
54 | if(isBlank()) {
55 | }
56 | else if(isQuote()) {
57 | dealQuote();
58 | isReg = 1
59 | }
60 | else if(peek == '/') {
61 | readch();
62 | if(peek == '/') {
63 | index = s.indexOf('\n', index);
64 | if(index == -1) {
65 | index = s.length;
66 | }
67 | }
68 | else if(peek == '*') {
69 | index = s.indexOf('*/', index);
70 | if(index == -1) {
71 | index = length;
72 | }
73 | else {
74 | index += 2;
75 | }
76 | }
77 | else if(isReg) {
78 | dealReg();
79 | isReg = 0
80 | }
81 | else {
82 | index--;
83 | isReg = 1;
84 | }
85 | }
86 | else if(isWord()) {
87 | dealWord();
88 | }
89 | else if(isNumber()) {
90 | dealNumber();
91 | }
92 | else if(peek == '(') {
93 | parentheseStack.push(parentheseState);
94 | isReg = 1
95 | }
96 | else if(peek == ')') {
97 | isReg = parentheseStack.pop();
98 | }
99 | else {
100 | isReg = peek != ']';
101 | modName = 0
102 | }
103 | }
104 | return res;
105 | function readch() {
106 | peek = s.charAt(index++);
107 | }
108 | function isBlank() {
109 | return /\s/.test(peek);
110 | }
111 | function isQuote() {
112 | return peek == '"' || peek == "'";
113 | }
114 | function dealQuote() {
115 | var start = index;
116 | var c = peek;
117 | var end = s.indexOf(c, start);
118 | if(end == -1) {
119 | index = length;
120 | }
121 | else if(s.charAt(end - 1) != '\\') {
122 | index = end + 1;
123 | }
124 | else {
125 | while(index < length) {
126 | readch();
127 | if(peek == '\\') {
128 | index++;
129 | }
130 | else if(peek == c) {
131 | break;
132 | }
133 | }
134 | }
135 | if(modName) {
136 | res.push(s.slice(start, index - 1));
137 | modName = 0;
138 | }
139 | }
140 | function dealReg() {
141 | index--;
142 | while(index < length) {
143 | readch();
144 | if(peek == '\\') {
145 | index++
146 | }
147 | else if(peek == '/') {
148 | break
149 | }
150 | else if(peek == '[') {
151 | while(index < length) {
152 | readch();
153 | if(peek == '\\') {
154 | index++;
155 | }
156 | else if(peek == ']') {
157 | break;
158 | }
159 | }
160 | }
161 | }
162 | }
163 | function isWord() {
164 | return /[a-z_$]/i.test(peek);
165 | }
166 | function dealWord() {
167 | var s2 = s.slice(index - 1);
168 | var r = /^[\w$]+/.exec(s2)[0];
169 | parentheseState = {
170 | 'if': 1,
171 | 'for': 1,
172 | 'while': 1,
173 | 'with': 1
174 | }[r];
175 | isReg = {
176 | 'break': 1,
177 | 'case': 1,
178 | 'continue': 1,
179 | 'debugger': 1,
180 | 'delete': 1,
181 | 'do': 1,
182 | 'else': 1,
183 | 'false': 1,
184 | 'if': 1,
185 | 'in': 1,
186 | 'instanceof': 1,
187 | 'return': 1,
188 | 'typeof': 1,
189 | 'void': 1
190 | }[r];
191 | modName = /^require\s*\(\s*(['"]).+?\1\s*\)/.test(s2);
192 | if(modName) {
193 | r = /^require\s*\(\s*['"]/.exec(s2)[0];
194 | index += r.length - 2;
195 | }
196 | else {
197 | index += /^[\w$]+(?:\s*\.\s*[\w$]+)*/.exec(s2)[0].length - 1;
198 | }
199 | }
200 | function isNumber() {
201 | return /\d/.test(peek)
202 | || peek == '.' && /\d/.test(s.charAt(index));
203 | }
204 | function dealNumber() {
205 | var s2 = s.slice(index - 1);
206 | var r;
207 | if(peek == '.') {
208 | r = /^\.\d+(?:E[+-]?\d*)?\s*/i.exec(s2)[0];
209 | }
210 | else if(/^0x[\da-f]*/i.test(s2)) {
211 | r = /^0x[\da-f]*\s*/i.exec(s2)[0];
212 | }
213 | else {
214 | r = /^\d+\.?\d*(?:E[+-]?\d*)?\s*/i.exec(s2)[0];
215 | }
216 | index += r.length - 1;
217 | isReg = 0;
218 | }
219 | };
220 | function needParse(depPaths){
221 | var result = false;
222 | depPaths.forEach(function(path){
223 | if(path.id == "require"){
224 | result = true;
225 | return false;
226 | }
227 | });
228 | return result;
229 | }
230 | this.injectCommonjs();
231 | if(this.factory && needParse(this.depPaths)) {
232 | this.collectDeps();
233 | }
234 | });
235 | });
236 | })();
237 |
--------------------------------------------------------------------------------
/plugins/css.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 可以使kvm加载css文件
3 | */
4 | (function(){
5 | kvm.module.registerPlugin(function(API){
6 | API.registerDriverLoader('css',function(uri,callback){
7 | var doc = document;
8 | var head = doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
9 | var ss = window.document.createElement( "link" );
10 | var sheets = window.document.styleSheets;
11 | var _this = this;
12 | ss.rel = "stylesheet";
13 | ss.href = uri;
14 | ss.media = "only x";
15 | if( callback ) {
16 | ss.onload = function(){
17 | callback && callback(null,ss);
18 | };
19 |
20 | ss.onerror = function(){
21 | callback && callback(true);
22 | };
23 | }
24 | head.appendChild(ss);
25 | ss.onloadcssdefined = function( cb ){
26 | var defined;
27 | for( var i = 0; i < sheets.length; i++ ){
28 | if( sheets[ i ].href && sheets[ i ].href.indexOf( uri ) > -1 ){
29 | defined = true;
30 | }
31 | }
32 | if( defined ){
33 | cb();
34 | } else {
35 | setTimeout(function() {
36 | ss.onloadcssdefined( cb );
37 | });
38 | }
39 | };
40 | ss.onloadcssdefined(function() {
41 | ss.media = _this.path.query && _this.path.query.media || "all";
42 | });
43 | });
44 |
45 | API.registerDriverLoaded(function (err,res) {
46 | var path = this.path;
47 | if(path.ext == "css" && !err){
48 | kvm.module.define(path.id, function(){
49 | return res;
50 | });
51 | }
52 | });
53 | });
54 | })();
55 |
--------------------------------------------------------------------------------
/plugins/json.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 可以使kvm加载json文件
3 | */
--------------------------------------------------------------------------------
/plugins/package.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 可以使kvm支持包管理
3 | */
4 | (function () {
5 | kvm.module.registerPlugin(function (API) {
6 | var Data = kvm.module.data();
7 | API.registerPathParser(function () {
8 | var baseUrl = Data.baseUrl;
9 | var packages = Data.packages;
10 | var packname, index,
11 | uri = this.uri || this.id;
12 | if(!uri) return;
13 | index = uri.indexOf("/");
14 | packname = uri.substr(0, index);
15 | if (packages && packages[packname]) {
16 | this.baseUrl = packages[packname].uri || packages[packname].url || baseUrl;
17 | this.uri = uri.substr(index + 1);
18 | this._parseVars();
19 | }
20 | });
21 | });
22 | })();
23 |
24 |
--------------------------------------------------------------------------------
/plugins/shim.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 可以使kvm支持包装器
3 | */
4 | (function () {
5 | kvm.module.registerPlugin(function (API) {
6 | var Data = kvm.module.data();
7 | API.registerPathMaper(function () {
8 | var shim = Data.shims[this.id];
9 | if (shim) {
10 | this.uri = shim.uri || shim.url;
11 | this._parser();
12 | }
13 | });
14 |
15 | API.registerDriverBeforeLoad(function () {
16 | var path = this.path;
17 | var shim = Data.shims[path.id];
18 | if (shim) {
19 | if (shim.exports && !shim.factory) {
20 | if (window[shim.exports]) {
21 | this.module = API.createModule(path.id, function () {
22 | return window[shim.exports];
23 | });
24 | }
25 | }
26 | }
27 | });
28 |
29 | API.registerDriverLoaded(function () {
30 | var path = this.path;
31 | var shim = Data.shims[path.id];
32 | if (shim && !path.getModule()) {
33 | if (kvm.isFunction(shim.factory) || kvm.isArray(shim.factory)) {
34 | kvm.module.define(path.id, shim.factory);
35 | } else {
36 | kvm.module.define(path.id, function () {
37 | return window[shim.exports]
38 | });
39 | }
40 | }
41 | });
42 | });
43 | })();
44 |
45 |
--------------------------------------------------------------------------------
/plugins/tmpl.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 可以使kvm加载html模板
3 | */
--------------------------------------------------------------------------------
/src/core.js:
--------------------------------------------------------------------------------
1 | import utils from "./utils";
2 | import Emitter from "./emitter";
3 |
4 |
5 | let Hook = new Emitter();
6 |
7 | let Data = {
8 | baseUrl: "",
9 | vars: {},
10 | packages: {},
11 | alias: {},
12 | shims: {},
13 | version:""
14 | };
15 |
16 | let ModuleCache = {
17 | MODULES: {},
18 | insert(module) {
19 | let path = module.path;
20 | let mapId = module.path.id || module.path.uri;
21 | let driver = Driver.getDriver(path);
22 | if (!this.MODULES[mapId]) {
23 | this.MODULES[mapId] = module;
24 | driver && driver.$emit("loaded", module);
25 | }
26 | return this.MODULES[mapId];
27 | },
28 | find(path) {
29 | return this.MODULES[path.id || path.uri] || this.MODULES[path.id] || this.MODULES[path.uri];
30 | }
31 | };
32 |
33 | class Request extends Emitter {
34 | constructor(sender, reqs, callback) {
35 | super();
36 | this.sender = sender;
37 | this.reqs = utils.isArray(reqs) ? reqs : [reqs];
38 | this.drivers = [];
39 | this.results = [];
40 | this.callback = callback;
41 | this._parseReqs();
42 | this.send();
43 | }
44 |
45 | static fetch(sender, paths) {
46 | paths = utils.isArray(paths) ? paths : [paths];
47 | return new Promise(function (resolve) {
48 | new Request(sender, paths, function (modules) {
49 | resolve(modules);
50 | });
51 | });
52 | }
53 |
54 | _createDriver(path) {
55 | let driver = Driver.getDriver(path),
56 | that = this;
57 | if (!driver) {
58 | driver = new Driver(path);
59 | driver.beforeLoad();
60 | if (!driver.module) {
61 | this.drivers.push(driver);
62 | } else {
63 | return that._done(driver.module);
64 | }
65 | }
66 | if (!driver.module) {
67 | driver.$on("loaded", function (module) {
68 | driver.module = module;
69 | that._done(module);
70 | });
71 | } else {
72 | that._done(driver.module);
73 | }
74 | return this;
75 | }
76 |
77 | _parseReqs() {
78 | let that = this, module;
79 | this.reqs = this.reqs.filter((req)=> !!req);
80 | if (this.reqs.length > 0) {
81 | this.reqs.forEach(function (path) {
82 | module = that.sender.getInjector(path);
83 | module = module || path.getModule();
84 | if (module) {
85 | that._done(module);
86 | } else {
87 | that._createDriver(path);
88 | }
89 | });
90 | } else {
91 | that.callback([]);
92 | }
93 | return this;
94 | }
95 |
96 | _checkDone() {
97 | return this.reqs.length == this.results.length;
98 | }
99 |
100 | _done(module) {
101 | this.results.push(module);
102 | if (this._checkDone()) {
103 | if (utils.isFunction(this.callback)) {
104 | this.callback(this.results);
105 | }
106 | }
107 | return this;
108 | }
109 |
110 | send() {
111 | this.drivers.forEach(function (driver) {
112 | driver.load();
113 | });
114 | return this;
115 | }
116 |
117 |
118 | }
119 |
120 | class Driver extends Emitter {
121 | constructor(path) {
122 | super();
123 | this.path = path;
124 | this.module = null;
125 | if (!Driver.getDriver(path)) {
126 | Driver.addDriver(this);
127 | }
128 | }
129 |
130 | static getDriver(path) {
131 | return Driver.DRIVERS[path.uri];
132 | }
133 |
134 | static addDriver(driver) {
135 | Driver.DRIVERS[driver.path.uri] = driver;
136 | }
137 |
138 | static registerDriverLoaded(method) {
139 | if (!utils.isFunction(method)) return;
140 | Hook.$on("DRIVER_LOADED", function (that) {
141 | method.call(that);
142 | });
143 | }
144 |
145 | static registerDriverLoader(ext, method) {
146 | if (!utils.isFunction(method)) return;
147 | ext = ext.trim();
148 | ext = ext.toUpperCase();
149 | Hook.$one("DRIVER_LOADER_" + ext, function (that) {
150 | method.call(that, that.path.uri, that.loaded.bind(that));
151 | });
152 | }
153 |
154 | static registerDriverBeforeLoad(method) {
155 | if (!utils.isFunction(method)) return;
156 | Hook.$on("DRIVER_BEFORE_LOAD", function (that) {
157 | method.call(that);
158 | });
159 | }
160 |
161 | beforeLoad() {
162 | Hook.$emit("DRIVER_BEFORE_LOAD", this);
163 | }
164 |
165 | load() {
166 | let path = this.path;
167 | let uri = path.uri;
168 | uri = utils.addQueryString(uri,Object.assign({version:Data.version},path.query));
169 | uri = utils.addHashString(uri,path.hash);
170 | if (path.ext != "js") {
171 | Hook.$emit("DRIVER_LOADER_" + path.ext.toLocaleUpperCase(), this);
172 | } else {
173 | this._loadJS(uri, this.loaded.bind(this));
174 | }
175 | }
176 |
177 | loaded(err, res) {
178 | let path = this.path;
179 | if (path.ext != "js") {
180 | Dectorator.define(path.id, function () {
181 | return res;
182 | });
183 | } else {
184 | Hook.$emit("DRIVER_LOADED", this, err, res);
185 | }
186 | }
187 |
188 | _loadJS(url, callback) {
189 | let doc = document;
190 | let head = doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
191 | let baseElement = head.getElementsByTagName("base")[0];
192 | let node = doc.createElement("script");
193 | node.async = true;
194 | node.src = url;
195 | addOnload(node, callback);
196 |
197 | baseElement ?
198 | head.insertBefore(node, baseElement) :
199 | head.appendChild(node);
200 |
201 | function addOnload(node, callback) {
202 | let supportOnload = "onload" in node;
203 |
204 | if (supportOnload) {
205 | node.onload = onload;
206 | node.onerror = function () {
207 | onload(true)
208 | }
209 | }
210 | else {
211 | node.onreadystatechange = function () {
212 | if (/loaded|complete/.test(node.readyState)) {
213 | onload()
214 | }
215 | }
216 | }
217 |
218 | function onload(e) {
219 | // Ensure only run once and handle memory leak in IE
220 | node.onload = node.onerror = node.onreadystatechange = null;
221 |
222 | // Remove the script to reduce memory leak
223 | if (Dectorator.data("debug")) {
224 | head.removeChild(node);
225 | }
226 |
227 | // Dereference the node
228 | node = null;
229 |
230 | callback && callback(e);
231 | }
232 | }
233 | }
234 | }
235 |
236 | Driver.DRIVERS = {};
237 |
238 |
239 | class Path extends Emitter {
240 | constructor(id, baseUrl) {
241 | super();
242 | this.baseUrl = baseUrl || Data.baseUrl;
243 | this.id = id || "";
244 | this._initId();
245 | this._maper();
246 | this._parser();
247 | this._initUri();
248 | }
249 |
250 | static registerFileExtParser(method) {
251 | if (!utils.isFunction(method)) return;
252 | Hook.$on("FILE_EXTS_PARSER", function (that) {
253 | method.call(that);
254 | });
255 | }
256 |
257 | static registerPathParser(method) {
258 | if (!utils.isFunction(method)) return;
259 | Hook.$on("PATH_PARSER", function (that) {
260 | method.call(that);
261 | });
262 | }
263 |
264 | static registerPathMaper(method) {
265 | if (!utils.isFunction(method)) return;
266 | Hook.$on("PATH_MAPER", function (that) {
267 | method.call(that);
268 | });
269 | }
270 |
271 | static createPath(id, baseUrl) {
272 | return new Path(id, baseUrl);
273 | }
274 |
275 | _initId() {
276 | if (!this.id) return;
277 | let _id = this.id;
278 | this.query = utils.getQuery(_id);
279 | this.hash = utils.getHash(this.id);
280 | this.id = this.id.replace(/(#|\?).*/, "");
281 | }
282 |
283 | _initUri() {
284 | this.baseUrl = this.baseUrl.replace(/\/$/, "") + "/";
285 | this.uri = this.uri ? utils.resolvePath(this.baseUrl, this.uri) :
286 | this.id ? utils.resolvePath(this.baseUrl, this.id) : utils.getCurrentScript().uri;
287 | this._initExt();
288 | }
289 |
290 | _initExt() {
291 | let ext = this.uri.match(/\.(\w+)$/);
292 | if (ext && ext[1]) {
293 | ext = ext[1].toLocaleLowerCase();
294 | if (Path.__EXTS__.indexOf(ext) != -1) {
295 | this.ext = ext;
296 | } else {
297 | this.$emit("FILE_EXTS_PARSER", this);
298 | if (!Path.__EXTS__.indexOf(this.ext)) {
299 | this.ext = "js";
300 | }
301 | }
302 | } else {
303 | this.ext = "js";
304 | this.uri += ".js";
305 | }
306 | }
307 |
308 | _maper() {
309 | if (!this.id) return;
310 | Hook.$emit("PATH_MAPER", this);
311 | }
312 |
313 | _parser() {
314 | if (!this.id) return;
315 | this._parseVars();
316 | Hook.$emit("PATH_PARSER", this);
317 | }
318 |
319 | _parseVars() {
320 | this.baseUrl = this.template(this.baseUrl);
321 | this.id = this.template(this.id);
322 | this.uri = this.uri ? this.template(this.uri) : "";
323 | }
324 |
325 | getModule() {
326 | return ModuleCache.find(this);
327 | }
328 |
329 | equal(path) {
330 | return (this.id && this.id == path.id) || (this.uri && this.uri == path.uri);
331 | }
332 |
333 | getMap(obj) {
334 | let result = null, that = this;
335 | if (utils.isArray(obj)) {
336 | obj.forEach(function (item) {
337 | if (item.equal && item.equal(that) || (item.path && item.path.equal(that))) {
338 | result = item;
339 | return false;
340 | }
341 | });
342 | } else if (utils.isObject(obj)) {
343 | return obj && obj[this.id || this.uri];
344 | }
345 | return result;
346 | }
347 |
348 | template(url) {
349 | if (!utils.isString(url)) throw new Error('路径类型错误');
350 | let reg = /\{([^{}]+)\}/g, res, that = this;
351 | res = url.replace(reg, function (match, param) {
352 | return Data.vars && Data.vars[param] ? Data.vars[param] : param
353 | });
354 | if (reg.test(res)) {
355 | return that.template(res);
356 | } else {
357 | return res;
358 | }
359 | }
360 |
361 | }
362 |
363 | Path.__EXTS__ = ["js", "css", "json", "jsonp", "tpl", "html"];
364 |
365 | class Module extends Emitter {
366 | constructor(meta) {
367 | super();
368 | utils.options(this, {
369 | path: null,
370 | depPaths: [],
371 | factory: null,
372 | injectors: {},
373 | installed: false,
374 | module: {
375 | exports: null
376 | }
377 | }, meta);
378 | Hook.$emit("MODULE_PARSER", this);
379 | }
380 |
381 | getInjector(path) {
382 | let injector = this.injectors[path.id];
383 | if (injector) {
384 | return Module.createModule(path.id, injector);
385 | }
386 | }
387 |
388 | invoke() {
389 | let that = this;
390 | return new Promise(function (resolve) {
391 | if (that.installed) {
392 | resolve(Promise.resolve(that.module.exports));
393 | } else if (that.factory) {
394 | resolve(Promise.resolve(that._inject()));
395 | } else {
396 | if (that.path && !that.factory) {
397 | resolve(Request.fetch(that, that.path).then(function (modules) {
398 | return Promise.resolve(modules[0]._inject());
399 | }));
400 | } else {
401 | throw new Error('模块不符合规范!');
402 | }
403 | }
404 | });
405 | }
406 |
407 | static createModule(...args) {
408 | return new Module(Module.parseMeta.apply(null, args));
409 | }
410 |
411 | static parseMeta(...params) {
412 | let meta = {},
413 | auto_path = false;
414 | if (utils.isBoolean(params[0])) {
415 | auto_path = params[0];
416 | params = params.slice(1);
417 | }
418 | params.forEach(function (param) {
419 | if (utils.isFunction(param)) {
420 | meta.factory = param;
421 | } else if (utils.isArray(param)) {
422 | if (utils.isFunction(param[param.length - 1])) {
423 | meta.factory = param[param.length - 1];
424 | meta.depPaths = param.slice(0, param.length - 1).map(function (id) {
425 | return new Path(id);
426 | });
427 | } else {
428 | meta.depPaths = param.map(function (id) {
429 | return new Path(id);
430 | });
431 | }
432 | } else if (utils.isString(param)) {
433 | meta.path = new Path(param);
434 | } else if (utils.isObject(param)) {
435 | meta.injectors = param;
436 | }
437 |
438 | });
439 | if (!meta.path && auto_path) {
440 | meta.path = new Path();
441 | }
442 | return meta;
443 | }
444 |
445 | static registerModuleParser(method) {
446 | if (!utils.isFunction(method)) return;
447 | Hook.$on("MODULE_PARSER", function (that) {
448 | method.call(that);
449 | });
450 | }
451 |
452 | _collectDeps() {
453 | let that = this,
454 | dependencies = [],
455 | injector;
456 | return Request.fetch(this, this.depPaths)
457 | .then(function (modules) {
458 | return new Promise(function (resolve) {
459 | if (that.depPaths.length > 0) {
460 | that.depPaths.forEach(function (path, index) {
461 | injector = path.getMap(modules);
462 | if (injector) {
463 | dependencies[index] = injector.invoke();
464 | if (dependencies.length == that.depPaths.length) {
465 | resolve(Promise.all(dependencies));
466 | }
467 | }
468 | });
469 | } else {
470 | resolve(Promise.all([]));
471 | }
472 | });
473 | });
474 | }
475 |
476 | _inject() {
477 | let that = this;
478 | return this._collectDeps().then(function (dependencies) {
479 | let instance = that.factory.apply(null, dependencies);
480 | if (that.module.exports) {
481 | instance = that.module.exports;
482 | } else {
483 | that.module.exports = instance;
484 | }
485 | that.installed = true;
486 | return instance;
487 | });
488 | }
489 | }
490 |
491 |
492 | let PluginInterface = {
493 | registerModuleParser: Module.registerModuleParser,
494 |
495 | registerDriverLoader: Driver.registerDriverLoader,
496 | registerDriverLoaded: Driver.registerDriverLoaded,
497 | registerDriverBeforeLoad: Driver.registerDriverBeforeLoad,
498 |
499 | registerFileExtParser: Path.registerFileExtParser,
500 | registerPathParser: Path.registerPathParser,
501 | registerPathMaper: Path.registerPathMaper,
502 |
503 | createModule: Module.createModule,
504 | createPath: Path.createPath
505 | };
506 |
507 | let Dectorator = {
508 |
509 | config(options){
510 | utils.options(Data, options);
511 | },
512 |
513 | data(name){
514 | return Data[name] ? Data[name] : Data;
515 | },
516 |
517 | define(...args){
518 | ModuleCache.insert(Module.createModule.apply(null, [true].concat(args)));
519 | return this;
520 | },
521 |
522 | invoke(...args){
523 | return Module.createModule.apply(null, args).invoke();
524 | },
525 |
526 | use(id, callback){
527 | let module = Module.createModule(id);
528 | module.invoke(function (instance) {
529 | utils.isFunction(callback) && callback(instance);
530 | }).catch(function (e) {
531 | throw e;
532 | });
533 | },
534 |
535 | registerPlugin(factory){
536 | if (utils.isFunction(factory)) {
537 | factory.call(this, PluginInterface);
538 | }
539 | }
540 | };
541 |
542 | export default Dectorator;
--------------------------------------------------------------------------------
/src/emitter.js:
--------------------------------------------------------------------------------
1 | import utils from "./utils";
2 |
3 | export default class Emitter {
4 | constructor(events) {
5 | if (events)
6 | this.$$EVENTS = events;
7 | else
8 | this.$$EVENTS = {};
9 |
10 | }
11 |
12 | $on(names, fn) {
13 | let _this = this;
14 | names.split(",").forEach(function (_name) {
15 | if (utils.isFunction(fn)) {
16 | if (_this.$$EVENTS[_name] && utils.isArray(_this.$$EVENTS[_name]))
17 | _this.$$EVENTS[_name].push(fn);
18 | else _this.$$EVENTS[_name] = [fn];
19 | }
20 | });
21 | return this;
22 | }
23 |
24 | $one(names, fn) {
25 | let _this = this;
26 | names.split(",").forEach(function (_name) {
27 | if (utils.isFunction(fn)) {
28 | if (!_this.$$EVENTS[_name])
29 | _this.$$EVENTS[_name] = [fn];
30 | }
31 | });
32 | return this;
33 | }
34 |
35 | $emit(_name,...args) {
36 |
37 | let events = this.$$EVENTS[_name];
38 | if (events && utils.isArray(events)) {
39 | for (let i = 0; i < events.length; i++) {
40 | events[i].apply(null, args);
41 | }
42 | }
43 | return this;
44 | }
45 |
46 | $remove(_name, fn) {
47 | let events = this.$$EVENTS[_name];
48 | if (events && utils.isArray(events)) {
49 | if (fn) {
50 | for (var i = events.length - 1; i >= 0; i--) {
51 | if (fn === events[i]) {
52 | events.splice(i, 1);
53 | }
54 | }
55 | } else {
56 | delete this.$$EVENTS[_name];
57 | }
58 | }
59 | return this;
60 | }
61 | }
--------------------------------------------------------------------------------
/src/kvm.js:
--------------------------------------------------------------------------------
1 | import utils from "./utils";
2 | import Emitter from "./emitter";
3 | import core from "./core";
4 |
5 | let KVM = {};
6 | window.kvm = window.KVM = KVM;
7 | window.kvm.Module = window.kvm.module = core;
8 | core.define.amd = true;
9 | window.define = core.define;
10 | Object.assign(KVM,utils);
11 |
12 | core.define("$emitter",function(){
13 | return Emitter;
14 | });
15 |
16 |
--------------------------------------------------------------------------------
/src/utils.js:
--------------------------------------------------------------------------------
1 | const hasOwnProperty = Object.prototype.hasOwnProperty;
2 |
3 | let TYPES = 'Function,String,Array,Object,Number,Boolean'.split(',');
4 |
5 | let utils = {
6 | isReference(val){
7 | return this.isArray(val) || this.isObject(val);
8 | },
9 | isValue(val){
10 | return !this.isReference(val);
11 | },
12 | isEmpty(obj){
13 | if (obj == null) return true;
14 |
15 | if (obj.length > 0) return false;
16 | if (obj.length === 0) return true;
17 | for (var key in obj) {
18 | if (hasOwnProperty.call(obj, key)) return false;
19 | }
20 |
21 | return true;
22 | },
23 | options(...source){
24 | return Object.assign.apply(Object, source);
25 | },
26 | addQueryString(url,query){
27 | let parser = document.createElement('a');
28 | let str = "?";
29 | let key;
30 | parser.href = url.replace("?","");
31 | for(key in query) {
32 | if(query.hasOwnProperty(key) && query[key]) {
33 | str += `${key}=${query[key]}&`;
34 | }
35 | }
36 | parser.search = str.replace(/&$/,"");
37 | return parser.toString();
38 | },
39 | getQuery(url){
40 | let parser = document.createElement('a');
41 | parser.href = url;
42 | return this.resolveQuery(parser.search);
43 | },
44 | getHash(url){
45 | let parser = document.createElement('a');
46 | parser.href = url;
47 | return parser.hash.replace(/^#/,"");
48 | },
49 | addHashString(url,hash){
50 | let parser = document.createElement('a');
51 | parser.href = url;
52 | parser.hash = "#"+hash.replace(/^#/,"");
53 | return parser.toString();
54 | },
55 | resolveQuery(query) {
56 | let vars = query.replace("?", "").split('&'), result = {};
57 | for (let i = 0; i < vars.length; i++) {
58 | if (vars[i]) {
59 | let pair = vars[i].split('=');
60 | result[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
61 | }
62 | }
63 | return result;
64 | },
65 | isAbsolutePath(path) {
66 | let reg = new RegExp('^(?:[a-z]+:)?\/\/', 'i');
67 | return reg.test(path);
68 | },
69 | resolvePath(...args) {
70 | let numUrls = args.length;
71 |
72 | if (numUrls === 0) {
73 | throw new Error("resolveUrl requires at least one argument; got none.")
74 | }
75 |
76 | let base = document.createElement("base");
77 | base.href = args[0];
78 |
79 | if (numUrls === 1) {
80 | return base.href
81 | }
82 |
83 | let head = document.getElementsByTagName("head")[0];
84 | head.insertBefore(base, head.firstChild);
85 |
86 | let a = document.createElement("a");
87 | let resolved = "";
88 |
89 | for (let index = 1; index < numUrls; index++) {
90 | a.href = args[index];
91 | resolved = a.href;
92 | base.href = resolved
93 | }
94 |
95 | head.removeChild(base);
96 | return resolved
97 | },
98 | before(context, name, fn){
99 | var _fn;
100 | context = context || window;
101 | _fn = context[name];
102 | context[name] = function (...args) {
103 | var result = fn.apply(context, args);
104 | args.push(result);
105 | _fn.apply(context,args);
106 | return result;
107 | }
108 | },
109 | after(context, name, fn){
110 | var _fn;
111 | context = context || window;
112 | _fn = context[name];
113 | context[name] = function (...args) {
114 | var result = _fn.apply(context,args);
115 | args.push(result);
116 | return fn.apply(context, args);
117 | }
118 | },
119 | getCurrentScript() {
120 | let uri = function _getCur() {
121 | let doc = document;
122 | let head = doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
123 | if (doc.currentScript) {
124 | return doc.currentScript.src;
125 | }
126 | let stack;
127 | try {
128 | a.b.c();
129 | } catch (e) {
130 | stack = e.stack;
131 | if (!stack && window.opera) {
132 | stack = (String(e).match(/of linked script \S+/g) || []).join(" ");
133 | }
134 | }
135 | if (stack) {
136 | stack = stack.split(/[@ ]/g).pop();
137 | stack = stack[0] == "(" ? stack.slice(1, -1) : stack;
138 | return stack.replace(/(:\d+)?:\d+$/i, "");
139 | }
140 | let nodes = head.getElementsByTagName("script");
141 | for (let i = 0, node; node = nodes[i++];) {
142 | if (node.readyState === "interactive") {
143 | return node.className = node.src;
144 | }
145 | }
146 | }();
147 | return {
148 | uri:uri.replace(/(#|\?).*/, ""),
149 | query:this.getQuery(uri),
150 | hash:this.getHash(uri)
151 | }
152 | }
153 | };
154 |
155 |
156 | TYPES.forEach((name) => utils[`is${name}`] = (val) => Object.prototype.toString.call(val) === `[object ${name}]`);
157 |
158 | export default utils;
159 |
160 |
161 |
--------------------------------------------------------------------------------
/test/all.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
55 |
56 |
--------------------------------------------------------------------------------
/test/base.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
20 |
21 |
--------------------------------------------------------------------------------
/test/modules/amd/a.js:
--------------------------------------------------------------------------------
1 | define(function(){
2 | return " I am A ";
3 | });
--------------------------------------------------------------------------------
/test/modules/amd/b.js:
--------------------------------------------------------------------------------
1 | define(function(){
2 | return " I am B ";
3 | });
--------------------------------------------------------------------------------
/test/modules/amd/c-ab.js:
--------------------------------------------------------------------------------
1 | define(["amd/a","amd/b"],function(A,B){
2 | return "I am C "+A+B;
3 | });
--------------------------------------------------------------------------------
/test/modules/commonjs/a.js:
--------------------------------------------------------------------------------
1 | define(["require","exports","module"],function(require,exports,module){
2 | var amd_a = require('amd/a');
3 | module.exports = function(){
4 | console.log(amd_a);
5 | console.log("I am commonjs");
6 | };
7 | });
--------------------------------------------------------------------------------
/test/modules/shim/a.js:
--------------------------------------------------------------------------------
1 | window.helloWorld = "....hello world....";
--------------------------------------------------------------------------------