UNPKG

15.9 kBJavaScriptView Raw
1
2/**
3 * Require the given path.
4 *
5 * @param {String} path
6 * @return {Object} exports
7 * @api public
8 */
9
10function require(path, parent, orig) {
11 var resolved = require.resolve(path);
12
13 // lookup failed
14 if (null == resolved) {
15 orig = orig || path;
16 parent = parent || 'root';
17 var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
18 err.path = orig;
19 err.parent = parent;
20 err.require = true;
21 throw err;
22 }
23
24 var module = require.modules[resolved];
25
26 // perform real require()
27 // by invoking the module's
28 // registered function
29 if (!module._resolving && !module.exports) {
30 var mod = {};
31 mod.exports = {};
32 mod.client = mod.component = true;
33 module._resolving = true;
34 module.call(this, mod.exports, require.relative(resolved), mod);
35 delete module._resolving;
36 module.exports = mod.exports;
37 }
38
39 return module.exports;
40}
41
42/**
43 * Registered modules.
44 */
45
46require.modules = {};
47
48/**
49 * Registered aliases.
50 */
51
52require.aliases = {};
53
54/**
55 * Resolve `path`.
56 *
57 * Lookup:
58 *
59 * - PATH/index.js
60 * - PATH.js
61 * - PATH
62 *
63 * @param {String} path
64 * @return {String} path or null
65 * @api private
66 */
67
68require.resolve = function(path) {
69 if (path.charAt(0) === '/') path = path.slice(1);
70
71 var paths = [
72 path,
73 path + '.js',
74 path + '.json',
75 path + '/index.js',
76 path + '/index.json'
77 ];
78
79 for (var i = 0; i < paths.length; i++) {
80 var path = paths[i];
81 if (require.modules.hasOwnProperty(path)) return path;
82 if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
83 }
84};
85
86/**
87 * Normalize `path` relative to the current path.
88 *
89 * @param {String} curr
90 * @param {String} path
91 * @return {String}
92 * @api private
93 */
94
95require.normalize = function(curr, path) {
96 var segs = [];
97
98 if ('.' != path.charAt(0)) return path;
99
100 curr = curr.split('/');
101 path = path.split('/');
102
103 for (var i = 0; i < path.length; ++i) {
104 if ('..' == path[i]) {
105 curr.pop();
106 } else if ('.' != path[i] && '' != path[i]) {
107 segs.push(path[i]);
108 }
109 }
110
111 return curr.concat(segs).join('/');
112};
113
114/**
115 * Register module at `path` with callback `definition`.
116 *
117 * @param {String} path
118 * @param {Function} definition
119 * @api private
120 */
121
122require.register = function(path, definition) {
123 require.modules[path] = definition;
124};
125
126/**
127 * Alias a module definition.
128 *
129 * @param {String} from
130 * @param {String} to
131 * @api private
132 */
133
134require.alias = function(from, to) {
135 if (!require.modules.hasOwnProperty(from)) {
136 throw new Error('Failed to alias "' + from + '", it does not exist');
137 }
138 require.aliases[to] = from;
139};
140
141/**
142 * Return a require function relative to the `parent` path.
143 *
144 * @param {String} parent
145 * @return {Function}
146 * @api private
147 */
148
149require.relative = function(parent) {
150 var p = require.normalize(parent, '..');
151
152 /**
153 * lastIndexOf helper.
154 */
155
156 function lastIndexOf(arr, obj) {
157 var i = arr.length;
158 while (i--) {
159 if (arr[i] === obj) return i;
160 }
161 return -1;
162 }
163
164 /**
165 * The relative require() itself.
166 */
167
168 function localRequire(path) {
169 var resolved = localRequire.resolve(path);
170 return require(resolved, parent, path);
171 }
172
173 /**
174 * Resolve relative to the parent.
175 */
176
177 localRequire.resolve = function(path) {
178 var c = path.charAt(0);
179 if ('/' == c) return path.slice(1);
180 if ('.' == c) return require.normalize(p, path);
181
182 // resolve deps by returning
183 // the dep in the nearest "deps"
184 // directory
185 var segs = parent.split('/');
186 var i = lastIndexOf(segs, 'deps') + 1;
187 if (!i) i = 0;
188 path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
189 return path;
190 };
191
192 /**
193 * Check if module is defined at `path`.
194 */
195
196 localRequire.exists = function(path) {
197 return require.modules.hasOwnProperty(localRequire.resolve(path));
198 };
199
200 return localRequire;
201};
202require.register("component-stack/index.js", Function("exports, require, module",
203"\n\
204/**\n\
205 * Expose `stack()`.\n\
206 */\n\
207\n\
208module.exports = stack;\n\
209\n\
210/**\n\
211 * Return the stack.\n\
212 *\n\
213 * @return {Array}\n\
214 * @api public\n\
215 */\n\
216\n\
217function stack() {\n\
218 var orig = Error.prepareStackTrace;\n\
219 Error.prepareStackTrace = function(_, stack){ return stack; };\n\
220 var err = new Error;\n\
221 Error.captureStackTrace(err, arguments.callee);\n\
222 var stack = err.stack;\n\
223 Error.prepareStackTrace = orig;\n\
224 return stack;\n\
225}//@ sourceURL=component-stack/index.js"
226));
227require.register("jkroso-type/index.js", Function("exports, require, module",
228"\n\
229/**\n\
230 * refs\n\
231 */\n\
232\n\
233var toString = Object.prototype.toString;\n\
234\n\
235/**\n\
236 * Return the type of `val`.\n\
237 *\n\
238 * @param {Mixed} val\n\
239 * @return {String}\n\
240 * @api public\n\
241 */\n\
242\n\
243module.exports = function(v){\n\
244 // .toString() is slow so try avoid it\n\
245 return typeof v === 'object'\n\
246 ? types[toString.call(v)]\n\
247 : typeof v\n\
248};\n\
249\n\
250var types = {\n\
251 '[object Function]': 'function',\n\
252 '[object Date]': 'date',\n\
253 '[object RegExp]': 'regexp',\n\
254 '[object Arguments]': 'arguments',\n\
255 '[object Array]': 'array',\n\
256 '[object String]': 'string',\n\
257 '[object Null]': 'null',\n\
258 '[object Undefined]': 'undefined',\n\
259 '[object Number]': 'number',\n\
260 '[object Boolean]': 'boolean',\n\
261 '[object Object]': 'object',\n\
262 '[object Text]': 'textnode',\n\
263 '[object Uint8Array]': '8bit-array',\n\
264 '[object Uint16Array]': '16bit-array',\n\
265 '[object Uint32Array]': '32bit-array',\n\
266 '[object Uint8ClampedArray]': '8bit-array',\n\
267 '[object Error]': 'error'\n\
268}\n\
269\n\
270if (typeof window != 'undefined') {\n\
271 for (var el in window) if (/^HTML\\w+Element$/.test(el)) {\n\
272 types['[object '+el+']'] = 'element'\n\
273 }\n\
274}\n\
275\n\
276module.exports.types = types\n\
277//@ sourceURL=jkroso-type/index.js"
278));
279require.register("jkroso-equals/index.js", Function("exports, require, module",
280"\n\
281var type = require('type')\n\
282\n\
283/**\n\
284 * assert all values are equal\n\
285 *\n\
286 * @param {Any} [...]\n\
287 * @return {Boolean}\n\
288 */\n\
289\n\
290module.exports = function(){\n\
291\tvar i = arguments.length - 1\n\
292\twhile (i > 0) {\n\
293\t\tif (!compare(arguments[i], arguments[--i])) return false\n\
294\t}\n\
295\treturn true\n\
296}\n\
297\n\
298// (any, any, [array]) -> boolean\n\
299function compare(a, b, memos){\n\
300\t// All identical values are equivalent\n\
301\tif (a === b) return true\n\
302\tvar fnA = types[type(a)]\n\
303\tif (fnA !== types[type(b)]) return false\n\
304\treturn fnA ? fnA(a, b, memos) : false\n\
305}\n\
306\n\
307var types = {}\n\
308\n\
309// (Number) -> boolean\n\
310types.number = function(a){\n\
311\t// NaN check\n\
312\treturn a !== a\n\
313}\n\
314\n\
315// (function, function, array) -> boolean\n\
316types['function'] = function(a, b, memos){\n\
317\treturn a.toString() === b.toString()\n\
318\t\t// Functions can act as objects\n\
319\t && types.object(a, b, memos) \n\
320\t\t&& compare(a.prototype, b.prototype)\n\
321}\n\
322\n\
323// (date, date) -> boolean\n\
324types.date = function(a, b){\n\
325\treturn +a === +b\n\
326}\n\
327\n\
328// (regexp, regexp) -> boolean\n\
329types.regexp = function(a, b){\n\
330\treturn a.toString() === b.toString()\n\
331}\n\
332\n\
333// (DOMElement, DOMElement) -> boolean\n\
334types.element = function(a, b){\n\
335\treturn a.outerHTML === b.outerHTML\n\
336}\n\
337\n\
338// (textnode, textnode) -> boolean\n\
339types.textnode = function(a, b){\n\
340\treturn a.textContent === b.textContent\n\
341}\n\
342\n\
343// decorate `fn` to prevent it re-checking objects\n\
344// (function) -> function\n\
345function memoGaurd(fn){\n\
346\treturn function(a, b, memos){\n\
347\t\tif (!memos) return fn(a, b, [])\n\
348\t\tvar i = memos.length, memo\n\
349\t\twhile (memo = memos[--i]) {\n\
350\t\t\tif (memo[0] === a && memo[1] === b) return true\n\
351\t\t}\n\
352\t\treturn fn(a, b, memos)\n\
353\t}\n\
354}\n\
355\n\
356types['arguments'] =\n\
357types.array = memoGaurd(compareArrays)\n\
358\n\
359// (array, array, array) -> boolean\n\
360function compareArrays(a, b, memos){\n\
361\tvar i = a.length\n\
362\tif (i !== b.length) return false\n\
363\tmemos.push([a, b])\n\
364\twhile (i--) {\n\
365\t\tif (!compare(a[i], b[i], memos)) return false\n\
366\t}\n\
367\treturn true\n\
368}\n\
369\n\
370types.object = memoGaurd(compareObjects)\n\
371\n\
372// (object, object, array) -> boolean\n\
373function compareObjects(a, b, memos) {\n\
374\tvar ka = getEnumerableProperties(a)\n\
375\tvar kb = getEnumerableProperties(b)\n\
376\tvar i = ka.length\n\
377\n\
378\t// same number of properties\n\
379\tif (i !== kb.length) return false\n\
380\n\
381\t// although not necessarily the same order\n\
382\tka.sort()\n\
383\tkb.sort()\n\
384\n\
385\t// cheap key test\n\
386\twhile (i--) if (ka[i] !== kb[i]) return false\n\
387\n\
388\t// remember\n\
389\tmemos.push([a, b])\n\
390\n\
391\t// iterate again this time doing a thorough check\n\
392\ti = ka.length\n\
393\twhile (i--) {\n\
394\t\tvar key = ka[i]\n\
395\t\tif (!compare(a[key], b[key], memos)) return false\n\
396\t}\n\
397\n\
398\treturn true\n\
399}\n\
400\n\
401// (object) -> array\n\
402function getEnumerableProperties (object) {\n\
403\tvar result = []\n\
404\tfor (var k in object) if (k !== 'constructor') {\n\
405\t\tresult.push(k)\n\
406\t}\n\
407\treturn result\n\
408}\n\
409\n\
410// expose compare\n\
411module.exports.compare = compare\n\
412//@ sourceURL=jkroso-equals/index.js"
413));
414require.register("component-assert/index.js", Function("exports, require, module",
415"\n\
416/**\n\
417 * Module dependencies.\n\
418 */\n\
419\n\
420var stack = require('stack');\n\
421var equals = require('equals');\n\
422\n\
423/**\n\
424 * Assert `expr` with optional failure `msg`.\n\
425 *\n\
426 * @param {Mixed} expr\n\
427 * @param {String} [msg]\n\
428 * @api public\n\
429 */\n\
430\n\
431module.exports = exports = function (expr, msg) {\n\
432 if (expr) return;\n\
433 throw new Error(msg || message());\n\
434};\n\
435\n\
436/**\n\
437 * Assert `actual` is weak equal to `expected`.\n\
438 *\n\
439 * @param {Mixed} actual\n\
440 * @param {Mixed} expected\n\
441 * @param {String} [msg]\n\
442 * @api public\n\
443 */\n\
444\n\
445exports.equal = function (actual, expected, msg) {\n\
446 if (actual == expected) return;\n\
447 throw new Error(msg || message());\n\
448};\n\
449\n\
450/**\n\
451 * Assert `actual` is not weak equal to `expected`.\n\
452 *\n\
453 * @param {Mixed} actual\n\
454 * @param {Mixed} expected\n\
455 * @param {String} [msg]\n\
456 * @api public\n\
457 */\n\
458\n\
459exports.notEqual = function (actual, expected, msg) {\n\
460 if (actual != expected) return;\n\
461 throw new Error(msg || message());\n\
462};\n\
463\n\
464/**\n\
465 * Assert `actual` is deep equal to `expected`.\n\
466 *\n\
467 * @param {Mixed} actual\n\
468 * @param {Mixed} expected\n\
469 * @param {String} [msg]\n\
470 * @api public\n\
471 */\n\
472\n\
473exports.deepEqual = function (actual, expected, msg) {\n\
474 if (equals(actual, expected)) return;\n\
475 throw new Error(msg || message());\n\
476};\n\
477\n\
478/**\n\
479 * Assert `actual` is not deep equal to `expected`.\n\
480 *\n\
481 * @param {Mixed} actual\n\
482 * @param {Mixed} expected\n\
483 * @param {String} [msg]\n\
484 * @api public\n\
485 */\n\
486\n\
487exports.notDeepEqual = function (actual, expected, msg) {\n\
488 if (!equals(actual, expected)) return;\n\
489 throw new Error(msg || message());\n\
490};\n\
491\n\
492/**\n\
493 * Assert `actual` is strict equal to `expected`.\n\
494 *\n\
495 * @param {Mixed} actual\n\
496 * @param {Mixed} expected\n\
497 * @param {String} [msg]\n\
498 * @api public\n\
499 */\n\
500\n\
501exports.strictEqual = function (actual, expected, msg) {\n\
502 if (actual === expected) return;\n\
503 throw new Error(msg || message());\n\
504};\n\
505\n\
506/**\n\
507 * Assert `actual` is not strict equal to `expected`.\n\
508 *\n\
509 * @param {Mixed} actual\n\
510 * @param {Mixed} expected\n\
511 * @param {String} [msg]\n\
512 * @api public\n\
513 */\n\
514\n\
515exports.notStrictEqual = function (actual, expected, msg) {\n\
516 if (actual !== expected) return;\n\
517 throw new Error(msg || message());\n\
518};\n\
519\n\
520/**\n\
521 * Assert `block` throws an `error`.\n\
522 *\n\
523 * @param {Function} block\n\
524 * @param {Function} [error]\n\
525 * @param {String} [msg]\n\
526 * @api public\n\
527 */\n\
528\n\
529exports.throws = function (block, error, msg) {\n\
530 var err;\n\
531 try {\n\
532 block();\n\
533 } catch (e) {\n\
534 err = e;\n\
535 }\n\
536 if (!err) throw new Error(msg || message());\n\
537 if (error && !(err instanceof error)) throw new Error(msg || message());\n\
538};\n\
539\n\
540/**\n\
541 * Assert `block` doesn't throw an `error`.\n\
542 *\n\
543 * @param {Function} block\n\
544 * @param {Function} [error]\n\
545 * @param {String} [msg]\n\
546 * @api public\n\
547 */\n\
548\n\
549exports.doesNotThrow = function (block, error, msg) {\n\
550 var err;\n\
551 try {\n\
552 block();\n\
553 } catch (e) {\n\
554 err = e;\n\
555 }\n\
556 if (error && (err instanceof error)) throw new Error(msg || message());\n\
557 if (err) throw new Error(msg || message());\n\
558};\n\
559\n\
560/**\n\
561 * Create a message from the call stack.\n\
562 *\n\
563 * @return {String}\n\
564 * @api private\n\
565 */\n\
566\n\
567function message() {\n\
568 if (!Error.captureStackTrace) return 'assertion failed';\n\
569 var callsite = stack()[2];\n\
570 var fn = callsite.getFunctionName();\n\
571 var file = callsite.getFileName();\n\
572 var line = callsite.getLineNumber() - 1;\n\
573 var col = callsite.getColumnNumber() - 1;\n\
574 var src = getScript(file);\n\
575 line = src.split('\\n\
576')[line].slice(col);\n\
577 var m = line.match(/assert\\((.*)\\)/);\n\
578 return m && m[1].trim();\n\
579}\n\
580\n\
581/**\n\
582 * Load contents of `script`.\n\
583 *\n\
584 * @param {String} script\n\
585 * @return {String}\n\
586 * @api private\n\
587 */\n\
588\n\
589function getScript(script) {\n\
590 var xhr = new XMLHttpRequest;\n\
591 xhr.open('GET', script, false);\n\
592 xhr.send(null);\n\
593 return xhr.responseText;\n\
594}\n\
595//@ sourceURL=component-assert/index.js"
596));
597require.register("domify/index.js", Function("exports, require, module",
598"\n\
599/**\n\
600 * Expose `parse`.\n\
601 */\n\
602\n\
603module.exports = parse;\n\
604\n\
605/**\n\
606 * Wrap map from jquery.\n\
607 */\n\
608\n\
609var map = {\n\
610 legend: [1, '<fieldset>', '</fieldset>'],\n\
611 tr: [2, '<table><tbody>', '</tbody></table>'],\n\
612 col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],\n\
613 _default: [0, '', '']\n\
614};\n\
615\n\
616map.td =\n\
617map.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'];\n\
618\n\
619map.option =\n\
620map.optgroup = [1, '<select multiple=\"multiple\">', '</select>'];\n\
621\n\
622map.thead =\n\
623map.tbody =\n\
624map.colgroup =\n\
625map.caption =\n\
626map.tfoot = [1, '<table>', '</table>'];\n\
627\n\
628map.text =\n\
629map.circle =\n\
630map.ellipse =\n\
631map.line =\n\
632map.path =\n\
633map.polygon =\n\
634map.polyline =\n\
635map.rect = [1, '<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">','</svg>'];\n\
636\n\
637/**\n\
638 * Parse `html` and return the children.\n\
639 *\n\
640 * @param {String} html\n\
641 * @return {Array}\n\
642 * @api private\n\
643 */\n\
644\n\
645function parse(html) {\n\
646 if ('string' != typeof html) throw new TypeError('String expected');\n\
647 \n\
648 // tag name\n\
649 var m = /<([\\w:]+)/.exec(html);\n\
650 if (!m) return document.createTextNode(html);\n\
651\n\
652 html = html.replace(/^\\s+|\\s+$/g, ''); // Remove leading/trailing whitespace\n\
653\n\
654 var tag = m[1];\n\
655\n\
656 // body support\n\
657 if (tag == 'body') {\n\
658 var el = document.createElement('html');\n\
659 el.innerHTML = html;\n\
660 return el.removeChild(el.lastChild);\n\
661 }\n\
662\n\
663 // wrap map\n\
664 var wrap = map[tag] || map._default;\n\
665 var depth = wrap[0];\n\
666 var prefix = wrap[1];\n\
667 var suffix = wrap[2];\n\
668 var el = document.createElement('div');\n\
669 el.innerHTML = prefix + html + suffix;\n\
670 while (depth--) el = el.lastChild;\n\
671\n\
672 // one element\n\
673 if (el.firstChild == el.lastChild) {\n\
674 return el.removeChild(el.firstChild);\n\
675 }\n\
676\n\
677 // several elements\n\
678 var fragment = document.createDocumentFragment();\n\
679 while (el.firstChild) {\n\
680 fragment.appendChild(el.removeChild(el.firstChild));\n\
681 }\n\
682\n\
683 return fragment;\n\
684}\n\
685//@ sourceURL=domify/index.js"
686));
687
688
689
690
691require.alias("component-assert/index.js", "domify/deps/assert/index.js");
692require.alias("component-assert/index.js", "assert/index.js");
693require.alias("component-stack/index.js", "component-assert/deps/stack/index.js");
694
695require.alias("jkroso-equals/index.js", "component-assert/deps/equals/index.js");
696require.alias("jkroso-type/index.js", "jkroso-equals/deps/type/index.js");