-
Notifications
You must be signed in to change notification settings - Fork 9
/
rtc.js
6806 lines (5398 loc) · 167 KB
/
rtc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.RTC = f()}})(function(){var define,module,exports;return (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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// a default configuration that is used by the rtc package
module.exports = {
// simple constraints for defaults
constraints: {
video: true,
audio: true
},
// use the public development switchboard for signalling
signaller: 'https://switchboard.rtc.io/',
// no room is defined by default
// rtc-quickconnect will autogenerate using a location.hash
room: undefined,
// specify ice servers or a generator function to create ice servers
ice: [],
// any data channels that we want to create for the conference
// by default a chat channel is created, but other channels can be added also
// additionally options can be supplied to customize the data channel config
// see: <http://w3c.github.io/webrtc-pc/#idl-def-RTCDataChannelInit>
channels: {},
// the selector that will be used to identify the localvideo container
localContainer: '#l-video',
// the selector that will be used to identify the remotevideo container
remoteContainer: '#r-video',
// should we atempt to load any plugins?
plugins: [],
// common options overrides that are used across rtc.io packages
options: {}
};
},{}],2:[function(require,module,exports){
var defaults = require('cog/defaults');
var extend = require('cog/extend');
var attach = require('rtc-attach');
var capture = require('rtc-capture');
var quickconnect = require('rtc-quickconnect');
var chain = require('whisk/chain');
var append = require('fdom/append');
var tweak = require('fdom/classtweak');
var qsa = require('fdom/qsa');
var kgo = require('kgo');
module.exports = function(config) {
var conference;
// extend our configuration with the defaults
config = defaults({}, config, require('./defaultconfig.js'));
// remap our options based on top level settings
config.options = extend({
room: config.room,
ice: config.ice,
plugins: config.plugins,
expectedLocalStreams: config.constraints ? 1 : 0
}, config.options);
// create our conference instance
conference = quickconnect(config.signaller, config.options);
conference
.on('call:ended', removeRemoteVideos)
.on('stream:added', remoteVideo(conference, config));
Object.keys(config.channels || {}).forEach(function(name) {
var channelConfig = config.channels[name];
conference.createDataChannel(name, channelConfig === true ? null : channelConfig);
});
// if we have constraints, then capture video
if (config.constraints) {
localVideo(conference, config);
}
return conference;
};
function flagOwnership(peerId) {
return function(el) {
el.dataset.peer = peerId;
};
}
function localVideo(qc, config) {
// use kgo to help with flow control
kgo(config)
('capture', [ 'constraints', 'options' ], capture)
('attach', [ 'capture', 'options' ], attach.local)
('render-local', [ 'attach' ], chain([
tweak('+rtc'),
tweak('+localvideo'),
append.to((config || {}).localContainer || '#l-video')
]))
('start-conference', [ 'capture' ], qc.addStream)
.on('error', reportError(qc, config));
}
function remoteVideo(qc, config) {
return function(id, stream) {
kgo(extend({ stream: stream }, config))
('attach', [ 'stream', 'options' ], attach)
('render-remote', [ 'attach' ], chain([
tweak('+rtc'),
tweak('+remotevideo'),
flagOwnership(id),
append.to((config || {}).remoteContainer || '#r-video')
]))
.on('error', reportError(qc, config));
};
}
function removeRemoteVideos(id) {
qsa('[data-peer="' + id + '"]').forEach(function(el) {
el.parentNode.removeChild(el);
});
}
function reportError(qc, config) {
return function(err) {
console.error(err);
};
}
},{"./defaultconfig.js":1,"cog/defaults":5,"cog/extend":6,"fdom/append":11,"fdom/classtweak":12,"fdom/qsa":13,"kgo":14,"rtc-attach":16,"rtc-capture":17,"rtc-quickconnect":22,"whisk/chain":66}],3:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
function EventEmitter() {
this._events = this._events || {};
this._maxListeners = this._maxListeners || undefined;
}
module.exports = EventEmitter;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
EventEmitter.defaultMaxListeners = 10;
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function(n) {
if (!isNumber(n) || n < 0 || isNaN(n))
throw TypeError('n must be a positive number');
this._maxListeners = n;
return this;
};
EventEmitter.prototype.emit = function(type) {
var er, handler, len, args, i, listeners;
if (!this._events)
this._events = {};
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events.error ||
(isObject(this._events.error) && !this._events.error.length)) {
er = arguments[1];
if (er instanceof Error) {
throw er; // Unhandled 'error' event
}
throw TypeError('Uncaught, unspecified "error" event.');
}
}
handler = this._events[type];
if (isUndefined(handler))
return false;
if (isFunction(handler)) {
switch (arguments.length) {
// fast cases
case 1:
handler.call(this);
break;
case 2:
handler.call(this, arguments[1]);
break;
case 3:
handler.call(this, arguments[1], arguments[2]);
break;
// slower
default:
len = arguments.length;
args = new Array(len - 1);
for (i = 1; i < len; i++)
args[i - 1] = arguments[i];
handler.apply(this, args);
}
} else if (isObject(handler)) {
len = arguments.length;
args = new Array(len - 1);
for (i = 1; i < len; i++)
args[i - 1] = arguments[i];
listeners = handler.slice();
len = listeners.length;
for (i = 0; i < len; i++)
listeners[i].apply(this, args);
}
return true;
};
EventEmitter.prototype.addListener = function(type, listener) {
var m;
if (!isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events)
this._events = {};
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (this._events.newListener)
this.emit('newListener', type,
isFunction(listener.listener) ?
listener.listener : listener);
if (!this._events[type])
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
else if (isObject(this._events[type]))
// If we've already got an array, just append.
this._events[type].push(listener);
else
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
// Check for listener leak
if (isObject(this._events[type]) && !this._events[type].warned) {
var m;
if (!isUndefined(this._maxListeners)) {
m = this._maxListeners;
} else {
m = EventEmitter.defaultMaxListeners;
}
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
console.error('(node) warning: possible EventEmitter memory ' +
'leak detected. %d listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
this._events[type].length);
if (typeof console.trace === 'function') {
// not supported in IE 10
console.trace();
}
}
}
return this;
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function(type, listener) {
if (!isFunction(listener))
throw TypeError('listener must be a function');
var fired = false;
function g() {
this.removeListener(type, g);
if (!fired) {
fired = true;
listener.apply(this, arguments);
}
}
g.listener = listener;
this.on(type, g);
return this;
};
// emits a 'removeListener' event iff the listener was removed
EventEmitter.prototype.removeListener = function(type, listener) {
var list, position, length, i;
if (!isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events || !this._events[type])
return this;
list = this._events[type];
length = list.length;
position = -1;
if (list === listener ||
(isFunction(list.listener) && list.listener === listener)) {
delete this._events[type];
if (this._events.removeListener)
this.emit('removeListener', type, listener);
} else if (isObject(list)) {
for (i = length; i-- > 0;) {
if (list[i] === listener ||
(list[i].listener && list[i].listener === listener)) {
position = i;
break;
}
}
if (position < 0)
return this;
if (list.length === 1) {
list.length = 0;
delete this._events[type];
} else {
list.splice(position, 1);
}
if (this._events.removeListener)
this.emit('removeListener', type, listener);
}
return this;
};
EventEmitter.prototype.removeAllListeners = function(type) {
var key, listeners;
if (!this._events)
return this;
// not listening for removeListener, no need to emit
if (!this._events.removeListener) {
if (arguments.length === 0)
this._events = {};
else if (this._events[type])
delete this._events[type];
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
for (key in this._events) {
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = {};
return this;
}
listeners = this._events[type];
if (isFunction(listeners)) {
this.removeListener(type, listeners);
} else {
// LIFO order
while (listeners.length)
this.removeListener(type, listeners[listeners.length - 1]);
}
delete this._events[type];
return this;
};
EventEmitter.prototype.listeners = function(type) {
var ret;
if (!this._events || !this._events[type])
ret = [];
else if (isFunction(this._events[type]))
ret = [this._events[type]];
else
ret = this._events[type].slice();
return ret;
};
EventEmitter.listenerCount = function(emitter, type) {
var ret;
if (!emitter._events || !emitter._events[type])
ret = 0;
else if (isFunction(emitter._events[type]))
ret = 1;
else
ret = emitter._events[type].length;
return ret;
};
function isFunction(arg) {
return typeof arg === 'function';
}
function isNumber(arg) {
return typeof arg === 'number';
}
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
}
function isUndefined(arg) {
return arg === void 0;
}
},{}],4:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
var queue = [];
var draining = false;
function drainQueue() {
if (draining) {
return;
}
draining = true;
var currentQueue;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
var i = -1;
while (++i < len) {
currentQueue[i]();
}
len = queue.length;
}
draining = false;
}
process.nextTick = function (fun) {
queue.push(fun);
if (!draining) {
setTimeout(drainQueue, 0);
}
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
// TODO(shtylman)
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
},{}],5:[function(require,module,exports){
/* jshint node: true */
'use strict';
/**
## cog/defaults
```js
var defaults = require('cog/defaults');
```
### defaults(target, *)
Shallow copy object properties from the supplied source objects (*) into
the target object, returning the target object once completed. Do not,
however, overwrite existing keys with new values:
```js
defaults({ a: 1, b: 2 }, { c: 3 }, { d: 4 }, { b: 5 }));
```
See an example on [requirebin](http://requirebin.com/?gist=6079475).
**/
module.exports = function(target) {
// ensure we have a target
target = target || {};
// iterate through the sources and copy to the target
[].slice.call(arguments, 1).forEach(function(source) {
if (! source) {
return;
}
for (var prop in source) {
if (target[prop] === void 0) {
target[prop] = source[prop];
}
}
});
return target;
};
},{}],6:[function(require,module,exports){
/* jshint node: true */
'use strict';
/**
## cog/extend
```js
var extend = require('cog/extend');
```
### extend(target, *)
Shallow copy object properties from the supplied source objects (*) into
the target object, returning the target object once completed:
```js
extend({ a: 1, b: 2 }, { c: 3 }, { d: 4 }, { b: 5 }));
```
See an example on [requirebin](http://requirebin.com/?gist=6079475).
**/
module.exports = function(target) {
[].slice.call(arguments, 1).forEach(function(source) {
if (! source) {
return;
}
for (var prop in source) {
target[prop] = source[prop];
}
});
return target;
};
},{}],7:[function(require,module,exports){
/**
## cog/getable
Take an object and provide a wrapper that allows you to `get` and
`set` values on that object.
**/
module.exports = function(target) {
function get(key) {
return target[key];
}
function set(key, value) {
target[key] = value;
}
function remove(key) {
return delete target[key];
}
function keys() {
return Object.keys(target);
};
function values() {
return Object.keys(target).map(function(key) {
return target[key];
});
};
if (typeof target != 'object') {
return target;
}
return {
get: get,
set: set,
remove: remove,
delete: remove,
keys: keys,
values: values
};
};
},{}],8:[function(require,module,exports){
/* jshint node: true */
'use strict';
/**
## cog/jsonparse
```js
var jsonparse = require('cog/jsonparse');
```
### jsonparse(input)
This function will attempt to automatically detect stringified JSON, and
when detected will parse into JSON objects. The function looks for strings
that look and smell like stringified JSON, and if found attempts to
`JSON.parse` the input into a valid object.
**/
module.exports = function(input) {
var isString = typeof input == 'string' || (input instanceof String);
var reNumeric = /^\-?\d+\.?\d*$/;
var shouldParse ;
var firstChar;
var lastChar;
if ((! isString) || input.length < 2) {
if (isString && reNumeric.test(input)) {
return parseFloat(input);
}
return input;
}
// check for true or false
if (input === 'true' || input === 'false') {
return input === 'true';
}
// check for null
if (input === 'null') {
return null;
}
// get the first and last characters
firstChar = input.charAt(0);
lastChar = input.charAt(input.length - 1);
// determine whether we should JSON.parse the input
shouldParse =
(firstChar == '{' && lastChar == '}') ||
(firstChar == '[' && lastChar == ']') ||
(firstChar == '"' && lastChar == '"');
if (shouldParse) {
try {
return JSON.parse(input);
}
catch (e) {
// apparently it wasn't valid json, carry on with regular processing
}
}
return reNumeric.test(input) ? parseFloat(input) : input;
};
},{}],9:[function(require,module,exports){
/* jshint node: true */
'use strict';
/**
## cog/logger
```js
var logger = require('cog/logger');
```
Simple browser logging offering similar functionality to the
[debug](https://github.com/visionmedia/debug) module.
### Usage
Create your self a new logging instance and give it a name:
```js
var debug = logger('phil');
```
Now do some debugging:
```js
debug('hello');
```
At this stage, no log output will be generated because your logger is
currently disabled. Enable it:
```js
logger.enable('phil');
```
Now do some more logger:
```js
debug('Oh this is so much nicer :)');
// --> phil: Oh this is some much nicer :)
```
### Reference
**/
var active = [];
var unleashListeners = [];
var targets = [ console ];
/**
#### logger(name)
Create a new logging instance.
**/
var logger = module.exports = function(name) {
// initial enabled check
var enabled = checkActive();
function checkActive() {
return enabled = active.indexOf('*') >= 0 || active.indexOf(name) >= 0;
}
// register the check active with the listeners array
unleashListeners[unleashListeners.length] = checkActive;
// return the actual logging function
return function() {
var args = [].slice.call(arguments);
// if we have a string message
if (typeof args[0] == 'string' || (args[0] instanceof String)) {
args[0] = name + ': ' + args[0];
}
// if not enabled, bail
if (! enabled) {
return;
}
// log
targets.forEach(function(target) {
target.log.apply(target, args);
});
};
};
/**
#### logger.reset()
Reset logging (remove the default console logger, flag all loggers as
inactive, etc, etc.
**/
logger.reset = function() {
// reset targets and active states
targets = [];
active = [];
return logger.enable();
};
/**
#### logger.to(target)
Add a logging target. The logger must have a `log` method attached.
**/
logger.to = function(target) {
targets = targets.concat(target || []);
return logger;
};
/**
#### logger.enable(names*)
Enable logging via the named logging instances. To enable logging via all
instances, you can pass a wildcard:
```js
logger.enable('*');
```
__TODO:__ wildcard enablers
**/
logger.enable = function() {
// update the active
active = active.concat([].slice.call(arguments));
// trigger the unleash listeners
unleashListeners.forEach(function(listener) {
listener();
});
return logger;
};
},{}],10:[function(require,module,exports){
/* jshint node: true */
'use strict';
/**
## cog/throttle
```js
var throttle = require('cog/throttle');
```
### throttle(fn, delay, opts)
A cherry-pickable throttle function. Used to throttle `fn` to ensure
that it can be called at most once every `delay` milliseconds. Will
fire first event immediately, ensuring the next event fired will occur
at least `delay` milliseconds after the first, and so on.
**/
module.exports = function(fn, delay, opts) {
var lastExec = (opts || {}).leading !== false ? 0 : Date.now();
var trailing = (opts || {}).trailing;
var timer;
var queuedArgs;
var queuedScope;
// trailing defaults to true
trailing = trailing || trailing === undefined;
function invokeDefered() {
fn.apply(queuedScope, queuedArgs || []);
lastExec = Date.now();
}
return function() {
var tick = Date.now();
var elapsed = tick - lastExec;
// always clear the defered timer
clearTimeout(timer);
if (elapsed < delay) {
queuedArgs = [].slice.call(arguments, 0);
queuedScope = this;
return trailing && (timer = setTimeout(invokeDefered, delay - elapsed));
}
// call the function
lastExec = tick;
fn.apply(this, arguments);
};
};
},{}],11:[function(require,module,exports){
/* jshint node: true */
'use strict';
/**
### append
```js
var append = require('fdom/append');
```
**/
var append = module.exports = function() {
console.log('not yet implemented');
return false;
};
/**
#### append.to(target, => child) => child
Append the specified `child` element to the `target` element using the
familiar `appendChild` method of the target.
<<< examples/append-to.js
**/
append.to = function(target, child) {
function append(el) {
var t = target;
if (typeof t == 'string' || (t instanceof String)) {
t = document.querySelector(t);
}
if (t && typeof t.appendChild == 'function') {
t.appendChild(el);
return el;
}
}
return child ? append(child) : append;
};
},{}],12:[function(require,module,exports){
/* jshint node: true */
'use strict';
var reDelim = /[\s\,]\s*/;
var opMappings = {
'+': 'add',
'-': 'remove',
'~': 'toggle',
'!': 'toggle'
};
/**
### classtweak(operations, => el)
A functional helper for making
[classList](http://www.w3.org/TR/domcore/#dom-element-classlist)
modifications to elements, supporting partial application.
<<< examples/classtweak.js
**/
module.exports = function(mods, element) {
var rules = mods.trim().split(reDelim)
// create the rule objects
.map(function(rule) {
return {
op: opMappings[rule.charAt(0)],
cls: rule.slice(1)
};
})
// removed non mapped operation codes
.filter(function(rule) {
return rule.op;
});
function tweak(el) {
if (! el.classList) {
return el;
}
// iterate through the rules and apply the changes
rules.forEach(function(rule) {
el.classList[rule.op](rule.cls);
});
return el;
}
return element ? tweak(element) : tweak;
};
},{}],13:[function(require,module,exports){
/* jshint node: true */
/* global document: false */
'use strict';
var classSelectorRE = /^\.([\w\-]+)$/;
var idSelectorRE = /^#([\w\-]+)$/;
var tagSelectorRE = /^[\w\-]+$/;
/**
### qsa(selector, scope?)
This function is used to get the results of the querySelectorAll output
in the fastest possible way. This code is very much based on the
implementation in
[zepto](https://github.com/madrobby/zepto/blob/master/src/zepto.js#L104),
but perhaps not quite as terse.
<<< examples/qsa.js
**/
module.exports = function(selector, scope) {
var idSearch;
// default the element to the document
scope = scope || document;
// determine whether we are doing an id search or not
idSearch = scope === document && idSelectorRE.test(selector);
// perform the search
return idSearch ?
// we are doing an id search, return the element search in an array
[scope.getElementById(RegExp.$1)] :