Finished support for new connector type

This commit is contained in:
DadaMonad
2014-11-25 15:51:30 +00:00
parent 03925ab32f
commit e1900e8561
170 changed files with 73970 additions and 8705 deletions

40
bower_components/connector/.bower.json vendored Normal file
View File

@@ -0,0 +1,40 @@
{
"name": "connector",
"authors": [
"Kevin Jahns <kevin.jahns@rwth-aachen.de>"
],
"description": "Connect to other users via a generic connector. The interface is standardized, so you can use other connectors without changing your code.",
"main": [
"peerjs-connector/peerjs-connector.min.js",
"peerjs-connector/peerjs-connector.html"
],
"moduleType": [
"globals",
"node"
],
"keywords": [
"peerjs"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"polymer": "Polymer/polymer#~0.5.1"
},
"homepage": "https://github.com/DadaMonad/Connector",
"_release": "35f8d81ce7",
"_resolution": {
"type": "branch",
"branch": "master",
"commit": "35f8d81ce73ecac317b3dd7fabf32a871a4926a6"
},
"_source": "git://github.com/DadaMonad/Connector.git",
"_target": "*",
"_originalSource": "DadaMonad/Connector",
"_direct": true
}

13
bower_components/connector/README.md vendored Normal file
View File

@@ -0,0 +1,13 @@
# Connector-Interface
The idea is, to create different implementations of the Connector interface that enable communication within a group.
It has a minimal interface and covers some frequently occuring problems thay you probably will encounter if you use communitcation protocols directly.
E.g. You can exchange the PeerJs-Connector with the XMPP-Connector only by changing few lines of code.
It is the communication interface used by [Yatta](https://github.com/DadaMonad/Yatta).
Currently we have interfaces for:
* PeerJs
More information about the Connector interface will follow. (Trust the update frequency, this could be a lie)

30
bower_components/connector/bower.json vendored Normal file
View File

@@ -0,0 +1,30 @@
{
"name": "connector",
"version": "0.0.0",
"authors": [
"Kevin Jahns <kevin.jahns@rwth-aachen.de>"
],
"description": "Connect to other users via a generic connector. The interface is standardized, so you can use other connectors without changing your code.",
"main": [
"peerjs-connector/peerjs-connector.min.js",
"peerjs-connector/peerjs-connector.html"
],
"moduleType": [
"globals",
"node"
],
"keywords": [
"peerjs"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"polymer": "Polymer/polymer#~0.5.1"
}
}

View File

@@ -0,0 +1,50 @@
gulp = require 'gulp'
coffee = require 'gulp-coffee'
concat = require 'gulp-concat'
uglify = require 'gulp-uglify'
sourcemaps = require 'gulp-sourcemaps'
plumber = require 'gulp-plumber'
browserify = require 'gulp-browserify'
rename = require 'gulp-rename'
paths =
peerjs: ['./lib/peerjs-connector/**/*.coffee']
test: ['./lib/test-connector/**/*.coffee']
buildConnector = (connector_name)->
()->
gulp.src(paths[connector_name], {read: false})
.pipe(plumber())
.pipe browserify
transform: ['coffeeify']
extensions: ['.coffee']
debug: true
.pipe rename
extname: ".js"
.pipe gulp.dest('./'+connector_name+'-connector')
.pipe uglify()
.pipe rename
extname: ".min.js"
.pipe gulp.dest('./'+connector_name+'-connector')
gulp.task 'peerjs', [], buildConnector 'peerjs'
gulp.task 'test', [], buildConnector 'test'
gulp.task 'build', ['peerjs','test']
# Rerun the task when a file changes
gulp.task 'watch', ()->
gulp.watch(paths.peerjs, ['peerjs'])
gulp.watch(paths.test, ['test'])
gulp.task('default', ['watch', 'build'])

View File

@@ -0,0 +1,77 @@
class Connector
constructor: ()->
# is set to true when this is synced with all other connections
@is_synced = false
# compute all of these functions when all connections are synced.
@compute_when_synced = []
# Peerjs Connections: key: conn-id, value: conn
@connections = {}
# Connections, that have been initialized, but have not been (fully) synced yet.
@unsynced_connections = {}
# List of functions that shall process incoming data
@receive_handlers = []
# A list of functions that are executed (left to right) when syncing with a peer.
@sync_process_order = []
#
# Execute a function _when_ we are connected. If not connected, wait until connected.
# @param f {Function} Will be executed on the PeerJs-Connector context.
#
whenSynced: (args)->
if @is_synced
args[0].apply this, args[1..]
else
@compute_when_synced.push args
#
# Execute an function _when_ a message is received.
# @param f {Function} Will be executed on the PeerJs-Connector context. f will be called with (sender_id, broadcast {true|false}, message).
#
whenReceiving: (f)->
@receive_handlers.push f
#
# Send a message to a (sub)-set of all connected peers.
# @param peers {Array<connection_ids>} A set of ids.
# @param message {Object} The message to send.
#
multicast: (peers, message)->
@whenSynced [_send, peers, message]
#
# Send a message to one of the connected peers.
# @param peers {connection_id} A connection id.
# @param message {Object} The message to send.
#
unicast: (peer, message)->
@whenSynced [_send, peer, message]
#
# Broadcast a message to all connected peers.
# @param message {Object} The message to broadcast.
#
broadcast: (message)->
@whenSynced [()=>
for peerid,peer of @connections
@_send peerid, message]
#
# Define how you want to handle the sync process of two users.
# This is a synchronous handshake. Every user will perform exactly the same actions at the same time. E.g.
# @example
# whenSyncing(function(){ // first call must not have parameters!
# return this.id; // Send the id of this connector.
# },function(peerid){ // you receive the peerid of the other connections.
# // you can do something with the peerid
# // return "you are my friend"; // you could send another massage.
# }); // this is the end of the sync process.
#
whenSyncing: ()->
for i in [(arguments.length-1)..0]
@sync_process_order.unshift arguments[i]
module.exports = Connector

View File

@@ -0,0 +1,29 @@
new Polymer 'peerjs-connector',
join: (id)->
idChanged: (old_val,new_val)->
if this.is_initialized
throw new Error "You must not set the user_id twice!"
else
this.initializeConnection()
initializeConnection: ()->
if this.conn_id?
console.log("now initializing")
options = {}
writeIfAvailable = (name, value)->
if value?
options[name] = value
writeIfAvailable 'key', this.key
writeIfAvailable 'host', this.host
writeIfAvailable 'port', this.port
writeIfAvailable 'path', this.path
writeIfAvailable 'secure', this.secure
writeIfAvailable 'debug', this.debug
this.is_initialized = true;
this.connector = new PeerJsConnector this.conn_id, options
ready: ()->
if this.conn_id != null
this.initializeConnection()

View File

@@ -0,0 +1,108 @@
Connector = require '../connector'
window.PeerJsConnector = class PeerJsConnector extends Connector
constructor: (@id, options)->
super()
that = this
# The following two functions should be performed at the end of the syncing process.
# In peerjs all connection ids must be send.
@sync_process_order.push ()->
peers = for peerid,conn of that.connections
peerid
peers
# Then connect to the connection ids.
@sync_process_order.push (peers)->
for peerid in peers
that.join peerid
true
# Create the Peerjs instance
@conn = new Peer @id, options
# TODO: improve error handling, what happens if disconnected? provide feedback
@conn.on 'error', (err)->
throw new Error "Peerjs connector: #{err}"
@conn.on 'disconnected', ()->
throw new Error "Peerjs connector disconnected from signalling server. Cannot accept new connections. Not fatal, but not so good either.."
@conn.on 'disconnect', ()->
that.conn.reconnect()
@conn.on 'connection', @_addConnection
#
# Join a communication room. In case of peerjs, you just have to join to one other client. This connector will join to the other peers automatically.
# @param id {String} The connection id of another client.
#
join: (peerid)->
if not @unsynced_connections[peerid]? and not @connections[peerid]? and peerid isnt @id
peer = @conn.connect peerid, {reliable: true}
@unsynced_connections[peerid] = peer
@_addConnection peer
true
else
false
#
# Send a message to a peer or set of peers. This is peerjs specific.
# @overload _send(peerid, message)
# @param peerid {String} PeerJs connection id of _another_ peer
# @param message {Object} Some object that shall be send
# @overload _send(peerids, message)
# @param peerids {Array<String>} PeerJs connection ids of _other_ peers
# @param message {Object} Some object that shall be send
#
_send: (peer_s, message)->
if peer_s.constructor is [].constructor
# Throw errors _after_ the message has been send to all other peers.
# Just in case a connection is invalid.
errors = []
for peer in peer_s
try
@connection[peer].send message
catch error
errors.push(error+"")
if errors.length > 0
throw new Error errors
else
@connections[peer_s].send message
#
# @private
# This is a helper function that is only related to the peerjs connector.
# Connect to another peer.
_addConnection: (peer)=>
peer.on 'open', ()=>
that = @
peer.send that.sync_process_order[0]()
current_sync_i = 1
peer.on 'data', (data)->
console.log("receive data: #{JSON.stringify data}")
if current_sync_i < that.sync_process_order.length
peer.send that.sync_process_order[current_sync_i++].call that, data
else if current_sync_i is that.sync_process_order.length
# All sync functions have been called. Increment current_sync_i one last time
current_sync_i++
# add it to the connections object
delete that.unsynced_connections[peer.peer]
that.connections[peer.peer] = peer
# when the conn closes, delete it from the connections object
peer.on 'close', ()->
delete that.connections[peer.peer]
# helper fkt. true iff os is an object that does not hold enumerable properties
isEmpty = (os)->
for o of os
return false
return true
if isEmpty(that.unsynced_connections)
# there are no unsynced connections. we are now synced.
# therefore execute all fkts in this.compute_when_synced
that.is_synced = true
for comp in that.compute_when_synced
comp[0].apply that, comp[1..]
that.compute_when_synced = []
else
# you received a new message, that is not a sync message.
# notify the receive_handlers
for f in that.receive_handlers
f peer.peer, data

View File

@@ -0,0 +1,98 @@
_ = require "underscore"
Connector = require '../connector'
#
# A trivial Connector that simulates network delay.
#
class TestConnector extends Connector
#
# @param id {String} Some unique id
# @param user_connectors {Array<TestConnector>} List of TestConnectors instances
#
constructor: (@id)->
super()
# If you think of operations, this will mirror the
# execiton order of operations (when a message is send, or received it is put into this)
@execution_order = []
# The messages are buffered under the name of teh sending user.
@receive_buffer = {}
@connections = {}
@whenReceiving (user, message)=>
@execution_order.push message
@is_synced = true
# join another user connector
join: (conn)->
@_addConnection conn.id, conn
for cid,c of conn.connections
@_addConnection cid, c
for comp in @compute_when_synced
comp[0].apply @, comp[1..]
#
# @private
# This is a helper function that is only related to the peerjs connector.
# Connect to another peer.
_addConnection: (id, user_connector)->
if not @connections[id]? and id isnt @id
data = null
user_data = null
for i in [0...@sync_process_order.length]
data_ = @sync_process_order[i].call @, user_data
user_data = user_connector.sync_process_order[i].call user_connector, data
data = data_
@connections[id]=user_connector
user_connector.connections[@id] = @
#
# Get the ops in the execution order.
#
getOpsInExecutionOrder: ()->
@execution_order
#
# Send a message to another peer
# @param {Operation} o The operation that was executed.
#
_send: (uid, message)->
rb = @connections[uid].receive_buffer
rb[@id] ?= []
rb[@id].push message
#
# Flush one operation from the line of a specific user.
#
flushOne: (uid)->
if @receive_buffer[uid]?.length > 0
message = @receive_buffer[uid].shift()
for f in @receive_handlers
f uid, message
#
# Flush one operation on a random line.
#
flushOneRandom: ()->
connlist = for cid,c of @receive_buffer
cid
@flushOne connlist[(_.random 0, (connlist.length-1))]
#
# Flush all operations on every line.
#
flushAll: ()->
for n,messages of @receive_buffer
for message in messages
for f in @receive_handlers
f n, message
@receive_buffer = {}
if window?
window.TestConnector = TestConnector
if module?
module.exports = TestConnector

29
bower_components/connector/package.json vendored Normal file
View File

@@ -0,0 +1,29 @@
{
"name": "connector",
"version": "0.0.0",
"description": "Connect to other users via a generic interface. The interface is standardized, so you can use other connectors without changing your code. ",
"main": "peerjs-connector/peerjs-connector.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"peerjs"
],
"author": "Kevin Jahns <kevin.jahns@rwth-aachen.de>",
"license": "MIT",
"dependencies": {
"peerjs": "~0.3.14"
},
"devDependencies": {
"gulp-sourcemaps": "~1.2.8",
"gulp-concat": "~2.4.1",
"gulp-coffee": "~2.2.0",
"gulp-uglify": "~1.0.1",
"gulp": "~3.8.10",
"coffee-script": "~1.8.0",
"gulp-plumber": "~0.6.6",
"gulp-browserify": "~0.5.0",
"coffeeify": "~1.0.0",
"underscore": "~1.7.0"
}
}

View File

@@ -0,0 +1,41 @@
(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<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
new Polymer('peerjs-connector', {
join: function(id) {},
idChanged: function(old_val, new_val) {
if (this.is_initialized) {
throw new Error("You must not set the user_id twice!");
} else {
return this.initializeConnection();
}
},
initializeConnection: function() {
var options, writeIfAvailable;
if (this.conn_id != null) {
console.log("now initializing");
options = {};
writeIfAvailable = function(name, value) {
if (value != null) {
return options[name] = value;
}
};
writeIfAvailable('key', this.key);
writeIfAvailable('host', this.host);
writeIfAvailable('port', this.port);
writeIfAvailable('path', this.path);
writeIfAvailable('secure', this.secure);
writeIfAvailable('debug', this.debug);
this.is_initialized = true;
return this.connector = new PeerJsConnector(this.conn_id, options);
}
},
ready: function() {
if (this.conn_id !== null) {
return this.initializeConnection();
}
}
});
},{}]},{},[1])
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLC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gICAgICB3cml0ZUlmQXZhaWxhYmxlICdwYXRoJywgdGhpcy5wYXRoXG4gICAgICB3cml0ZUlmQXZhaWxhYmxlICdzZWN1cmUnLCB0aGlzLnNlY3VyZVxuICAgICAgd3JpdGVJZkF2YWlsYWJsZSAnZGVidWcnLCB0aGlzLmRlYnVnXG4gICAgICB0aGlzLmlzX2luaXRpYWxpemVkID0gdHJ1ZTtcbiAgICAgIHRoaXMuY29ubmVjdG9yID0gbmV3IFBlZXJKc0Nvbm5lY3RvciB0aGlzLmNvbm5faWQsIG9wdGlvbnNcbiAgICBcbiAgcmVhZHk6ICgpLT5cbiAgICBpZiB0aGlzLmNvbm5faWQgIT0gbnVsbFxuICAgICAgdGhpcy5pbml0aWFsaXplQ29ubmVjdGlvbigpXG4gIFxuIl19

View File

@@ -0,0 +1 @@
!function i(n,t,e){function r(u,s){if(!t[u]){if(!n[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(o)return o(u,!0);throw new Error("Cannot find module '"+u+"'")}var h=t[u]={exports:{}};n[u][0].call(h.exports,function(i){var t=n[u][1][i];return r(t?t:i)},h,h.exports,i,n,t,e)}return t[u].exports}for(var o="function"==typeof require&&require,u=0;u<e.length;u++)r(e[u]);return r}({1:[function(){new Polymer("peerjs-connector",{join:function(){},idChanged:function(){if(this.is_initialized)throw new Error("You must not set the user_id twice!");return this.initializeConnection()},initializeConnection:function(){var i,n;return null!=this.conn_id?(console.log("now initializing"),i={},n=function(n,t){return null!=t?i[n]=t:void 0},n("key",this.key),n("host",this.host),n("port",this.port),n("path",this.path),n("secure",this.secure),n("debug",this.debug),this.is_initialized=!0,this.connector=new PeerJsConnector(this.conn_id,i)):void 0},ready:function(){return null!==this.conn_id?this.initializeConnection():void 0}})},{}]},{},[1]);

View File

@@ -0,0 +1,10 @@
<link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name="peerjs-connector" hidden attributes="conn_id connector key host port path secure debug">
<script src="../bower_components/peerjs/peer.min.js"></script>
<script src="./peerjs-connector.js"></script>
<template>
</template>
<script src="./peerjs-connector-polymer.min.js"></script>
</polymer-element>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
!function n(e,t,r){function o(i,s){if(!t[i]){if(!e[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(c)return c(i,!0);throw new Error("Cannot find module '"+i+"'")}var h=t[i]={exports:{}};e[i][0].call(h.exports,function(n){var t=e[i][1][n];return o(t?t:n)},h,h.exports,n,e,t,r)}return t[i].exports}for(var c="function"==typeof require&&require,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(n,e){var t;t=function(){function n(){this.is_synced=!1,this.compute_when_synced=[],this.connections={},this.unsynced_connections={},this.receive_handlers=[],this.sync_process_order=[]}return n.prototype.whenSynced=function(n){return this.is_synced?n[0].apply(this,n.slice(1)):this.compute_when_synced.push(n)},n.prototype.whenReceiving=function(n){return this.receive_handlers.push(n)},n.prototype.multicast=function(n,e){return this.whenSynced([_send,n,e])},n.prototype.unicast=function(n,e){return this.whenSynced([_send,n,e])},n.prototype.broadcast=function(n){return this.whenSynced([function(e){return function(){var t,r,o,c;o=e.connections,c=[];for(r in o)t=o[r],c.push(e._send(r,n));return c}}(this)])},n.prototype.whenSyncing=function(){var n,e,t,r;for(r=[],n=e=t=arguments.length-1;0>=t?0>=e:e>=0;n=0>=t?++e:--e)r.push(this.sync_process_order.unshift(arguments[n]));return r},n}(),e.exports=t},{}],2:[function(n){var e,t,r=function(n,e){return function(){return n.apply(e,arguments)}},o={}.hasOwnProperty,c=function(n,e){function t(){this.constructor=n}for(var r in e)o.call(e,r)&&(n[r]=e[r]);return t.prototype=e.prototype,n.prototype=new t,n.__super__=e.prototype,n};e=n("../connector"),window.PeerJsConnector=t=function(n){function e(n,t){var o;this.id=n,this._addConnection=r(this._addConnection,this),e.__super__.constructor.call(this),o=this,this.sync_process_order.push(function(){var n,e,t;return t=function(){var t,r;t=o.connections,r=[];for(e in t)n=t[e],r.push(e);return r}()}),this.sync_process_order.push(function(n){var e,t,r;for(t=0,r=n.length;r>t;t++)e=n[t],o.join(e);return!0}),this.conn=new Peer(this.id,t),this.conn.on("error",function(n){throw new Error("Peerjs connector: "+n)}),this.conn.on("disconnected",function(){throw new Error("Peerjs connector disconnected from signalling server. Cannot accept new connections. Not fatal, but not so good either..")}),this.conn.on("disconnect",function(){return o.conn.reconnect()}),this.conn.on("connection",this._addConnection)}return c(e,n),e.prototype.join=function(n){var e;return null==this.unsynced_connections[n]&&null==this.connections[n]&&n!==this.id?(e=this.conn.connect(n,{reliable:!0}),this.unsynced_connections[n]=e,this._addConnection(e),!0):!1},e.prototype._send=function(n,e){var t,r,o,c,i;if(n.constructor!==[].constructor)return this.connections[n].send(e);for(r=[],c=0,i=n.length;i>c;c++){o=n[c];try{this.connection[o].send(e)}catch(s){t=s,r.push(t+"")}}if(r.length>0)throw new Error(r)},e.prototype._addConnection=function(n){return n.on("open",function(e){return function(){var t,r;return r=e,n.send(r.sync_process_order[0]()),t=1,n.on("data",function(e){var o,c,i,s,u,h,p,f,d,a;if(console.log("receive data: "+JSON.stringify(e)),t<r.sync_process_order.length)return n.send(r.sync_process_order[t++].call(r,e));if(t!==r.sync_process_order.length){for(d=r.receive_handlers,a=[],u=0,p=d.length;p>u;u++)c=d[u],a.push(c(n.peer,e));return a}if(t++,delete r.unsynced_connections[n.peer],r.connections[n.peer]=n,n.on("close",function(){return delete r.connections[n.peer]}),(i=function(n){var e;for(e in n)return!1;return!0})(r.unsynced_connections)){for(r.is_synced=!0,f=r.compute_when_synced,s=0,h=f.length;h>s;s++)o=f[s],o[0].apply(r,o.slice(1));return r.compute_when_synced=[]}})}}(this))},e}(e)},{"../connector":1}]},{},[2]);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
{
"name": "core-component-page",
"private": true,
"dependencies": {
"webcomponentsjs": "Polymer/webcomponentsjs#^0.5.0",
"polymer": "Polymer/polymer#^0.5.0"
},
"version": "0.5.1",
"homepage": "https://github.com/Polymer/core-component-page",
"_release": "0.5.1",
"_resolution": {
"type": "version",
"tag": "0.5.1",
"commit": "ef1f86e659fd7498755e027d1561acc963d67807"
},
"_source": "git://github.com/Polymer/core-component-page.git",
"_target": "^0.5.0",
"_originalSource": "Polymer/core-component-page"
}

View File

@@ -0,0 +1,6 @@
core-component-page
===================
See the [component page](http://polymer-project.org/docs/elements/core-elements.html#core-component-page) for more information.
Note: this is the vulcanized version of [`core-component-page-dev`](https://github.com/Polymer/core-component-page-dev) (the source).

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@@ -0,0 +1,9 @@
{
"name": "core-component-page",
"private": true,
"dependencies": {
"webcomponentsjs": "Polymer/webcomponentsjs#^0.5.0",
"polymer": "Polymer/polymer#^0.5.0"
},
"version": "0.5.1"
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,23 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE
The complete set of authors may be found at http://polymer.github.io/AUTHORS
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS
-->
<html>
<head>
<script src="../webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="core-component-page.html">
</head>
<body unresolved>
<core-component-page></core-component-page>
</body>
</html>

View File

@@ -0,0 +1,22 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE
The complete set of authors may be found at http://polymer.github.io/AUTHORS
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS
-->
<html>
<head>
<script src="../webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="../core-component-page/core-component-page.html">
</head>
<body unresolved>
<core-component-page></core-component-page>
</body>
</html>

32
bower_components/polymer/.bower.json vendored Normal file
View File

@@ -0,0 +1,32 @@
{
"name": "polymer",
"description": "Polymer is a new type of library for the web, built on top of Web Components, and designed to leverage the evolving web platform on modern browsers.",
"homepage": "http://www.polymer-project.org/",
"keywords": [
"util",
"client",
"browser",
"web components",
"web-components"
],
"author": "Polymer Authors <polymer-dev@googlegroups.com>",
"private": true,
"dependencies": {
"core-component-page": "Polymer/core-component-page#^0.5.0",
"webcomponentsjs": "Polymer/webcomponentsjs#^0.5.0"
},
"devDependencies": {
"tools": "Polymer/tools#master",
"web-component-tester": "Polymer/web-component-tester#^1.4.2"
},
"version": "0.5.1",
"_release": "0.5.1",
"_resolution": {
"type": "version",
"tag": "0.5.1",
"commit": "c654b2b4996a643e79234ac624d7bc38179dfc2c"
},
"_source": "git://github.com/Polymer/polymer.git",
"_target": "~0.5.1",
"_originalSource": "Polymer/polymer"
}

21
bower_components/polymer/README.md vendored Normal file
View File

@@ -0,0 +1,21 @@
# Polymer
[![Polymer build status](http://www.polymer-project.org/build/polymer-dev/status.png "Polymer build status")](http://build.chromium.org/p/client.polymer/waterfall)
## Brief Overview
For more detailed info goto [http://polymer-project.org/](http://polymer-project.org/).
Polymer is a new type of library for the web, designed to leverage the existing browser infrastructure to provide the encapsulation and extendability currently only available in JS libraries.
Polymer is based on a set of future technologies, including [Shadow DOM](https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html), [Custom Elements](https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html) and Model Driven Views. Currently these technologies are implemented as polyfills or shims, but as browsers adopt these features natively, the platform code that drives Polymer evacipates, leaving only the value-adds.
## Tools & Testing
For running tests or building minified files, consult the [tooling information](http://polymer-project.org/resources/tooling-strategy.html).
## Releases
[Release (tagged) versions](https://github.com/Polymer/polymer/releases) of Polymer include concatenated and minified sources for your convenience.
[![Analytics](https://ga-beacon.appspot.com/UA-39334307-2/Polymer/polymer/README)](https://github.com/igrigorik/ga-beacon)

23
bower_components/polymer/bower.json vendored Normal file
View File

@@ -0,0 +1,23 @@
{
"name": "polymer",
"description": "Polymer is a new type of library for the web, built on top of Web Components, and designed to leverage the evolving web platform on modern browsers.",
"homepage": "http://www.polymer-project.org/",
"keywords": [
"util",
"client",
"browser",
"web components",
"web-components"
],
"author": "Polymer Authors <polymer-dev@googlegroups.com>",
"private": true,
"dependencies": {
"core-component-page": "Polymer/core-component-page#^0.5.0",
"webcomponentsjs": "Polymer/webcomponentsjs#^0.5.0"
},
"devDependencies": {
"tools": "Polymer/tools#master",
"web-component-tester": "Polymer/web-component-tester#^1.4.2"
},
"version": "0.5.1"
}

26
bower_components/polymer/build.log vendored Normal file
View File

@@ -0,0 +1,26 @@
BUILD LOG
---------
Build Time: 2014-11-12T14:32:18
NODEJS INFORMATION
==================
nodejs: v0.10.33
grunt: 0.4.5
grunt-audit: 1.0.0
grunt-contrib-concat: 0.5.0
grunt-contrib-copy: 0.7.0
grunt-contrib-uglify: 0.6.0
grunt-string-replace: 1.0.0
web-component-tester: 1.6.0
REPO REVISIONS
==============
polymer-expressions: 1288fe573dc57cde304f66f0833d0644c766158c
polymer-gestures: 94660a514772e182d27f79c3d8d1bb88796a2327
polymer: da75e633f39b7761494cc3139a60733c488b2215
BUILD HASHES
============
dist/polymer.js: 59e0d3e669a3a1d163d8337766aa63bf809bfe79
dist/polymer.min.js: a9145f911c5b9fecc0d4aa422ac658d1d462d15a
dist/layout.html: 348d358a91712ecc2f8811efa430fcd954b4590c

286
bower_components/polymer/layout.html vendored Normal file
View File

@@ -0,0 +1,286 @@
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<style shim-shadowdom>
/*******************************
Flex Layout
*******************************/
html /deep/ [layout][horizontal], html /deep/ [layout][vertical] {
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
html /deep/ [layout][horizontal][inline], html /deep/ [layout][vertical][inline] {
display: -ms-inline-flexbox;
display: -webkit-inline-flex;
display: inline-flex;
}
html /deep/ [layout][horizontal] {
-ms-flex-direction: row;
-webkit-flex-direction: row;
flex-direction: row;
}
html /deep/ [layout][horizontal][reverse] {
-ms-flex-direction: row-reverse;
-webkit-flex-direction: row-reverse;
flex-direction: row-reverse;
}
html /deep/ [layout][vertical] {
-ms-flex-direction: column;
-webkit-flex-direction: column;
flex-direction: column;
}
html /deep/ [layout][vertical][reverse] {
-ms-flex-direction: column-reverse;
-webkit-flex-direction: column-reverse;
flex-direction: column-reverse;
}
html /deep/ [layout][wrap] {
-ms-flex-wrap: wrap;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
html /deep/ [layout][wrap-reverse] {
-ms-flex-wrap: wrap-reverse;
-webkit-flex-wrap: wrap-reverse;
flex-wrap: wrap-reverse;
}
html /deep/ [flex] {
-ms-flex: 1 1 0.000000001px;
-webkit-flex: 1;
flex: 1;
-webkit-flex-basis: 0.000000001px;
flex-basis: 0.000000001px;
}
html /deep/ [vertical][layout] > [flex][auto-vertical], html /deep/ [vertical][layout]::shadow [flex][auto-vertical] {
-ms-flex: 1 1 auto;
-webkit-flex-basis: auto;
flex-basis: auto;
}
html /deep/ [flex][auto] {
-ms-flex: 1 1 auto;
-webkit-flex-basis: auto;
flex-basis: auto;
}
html /deep/ [flex][none] {
-ms-flex: none;
-webkit-flex: none;
flex: none;
}
html /deep/ [flex][one] {
-ms-flex: 1;
-webkit-flex: 1;
flex: 1;
}
html /deep/ [flex][two] {
-ms-flex: 2;
-webkit-flex: 2;
flex: 2;
}
html /deep/ [flex][three] {
-ms-flex: 3;
-webkit-flex: 3;
flex: 3;
}
html /deep/ [flex][four] {
-ms-flex: 4;
-webkit-flex: 4;
flex: 4;
}
html /deep/ [flex][five] {
-ms-flex: 5;
-webkit-flex: 5;
flex: 5;
}
html /deep/ [flex][six] {
-ms-flex: 6;
-webkit-flex: 6;
flex: 6;
}
html /deep/ [flex][seven] {
-ms-flex: 7;
-webkit-flex: 7;
flex: 7;
}
html /deep/ [flex][eight] {
-ms-flex: 8;
-webkit-flex: 8;
flex: 8;
}
html /deep/ [flex][nine] {
-ms-flex: 9;
-webkit-flex: 9;
flex: 9;
}
html /deep/ [flex][ten] {
-ms-flex: 10;
-webkit-flex: 10;
flex: 10;
}
html /deep/ [flex][eleven] {
-ms-flex: 11;
-webkit-flex: 11;
flex: 11;
}
html /deep/ [flex][twelve] {
-ms-flex: 12;
-webkit-flex: 12;
flex: 12;
}
/* alignment in cross axis */
html /deep/ [layout][start] {
-ms-flex-align: start;
-webkit-align-items: flex-start;
align-items: flex-start;
}
html /deep/ [layout][center], html /deep/ [layout][center-center] {
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
html /deep/ [layout][end] {
-ms-flex-align: end;
-webkit-align-items: flex-end;
align-items: flex-end;
}
/* alignment in main axis */
html /deep/ [layout][start-justified] {
-ms-flex-pack: start;
-webkit-justify-content: flex-start;
justify-content: flex-start;
}
html /deep/ [layout][center-justified], html /deep/ [layout][center-center] {
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
}
html /deep/ [layout][end-justified] {
-ms-flex-pack: end;
-webkit-justify-content: flex-end;
justify-content: flex-end;
}
html /deep/ [layout][around-justified] {
-ms-flex-pack: distribute;
-webkit-justify-content: space-around;
justify-content: space-around;
}
html /deep/ [layout][justified] {
-ms-flex-pack: justify;
-webkit-justify-content: space-between;
justify-content: space-between;
}
/* self alignment */
html /deep/ [self-start] {
-ms-align-self: flex-start;
-webkit-align-self: flex-start;
align-self: flex-start;
}
html /deep/ [self-center] {
-ms-align-self: center;
-webkit-align-self: center;
align-self: center;
}
html /deep/ [self-end] {
-ms-align-self: flex-end;
-webkit-align-self: flex-end;
align-self: flex-end;
}
html /deep/ [self-stretch] {
-ms-align-self: stretch;
-webkit-align-self: stretch;
align-self: stretch;
}
/*******************************
Other Layout
*******************************/
html /deep/ [block] {
display: block;
}
/* ie support for hidden */
html /deep/ [hidden] {
display: none !important;
}
html /deep/ [relative] {
position: relative;
}
html /deep/ [fit] {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
body[fullbleed] {
margin: 0;
height: 100vh;
}
/*******************************
Other
*******************************/
html /deep/ [segment], html /deep/ segment {
display: block;
position: relative;
-webkit-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
margin: 1em 0.5em;
padding: 1em;
background-color: white;
-webkit-box-shadow: 0px 0px 0px 1px rgba(0, 0, 0, 0.1);
box-shadow: 0px 0px 0px 1px rgba(0, 0, 0, 0.1);
border-radius: 5px 5px 5px 5px;
}
</style>

12
bower_components/polymer/polymer.html vendored Normal file
View File

@@ -0,0 +1,12 @@
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="layout.html">
<script src="polymer.js"></script>

11829
bower_components/polymer/polymer.js vendored Normal file

File diff suppressed because it is too large Load Diff

14
bower_components/polymer/polymer.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,23 @@
{
"name": "webcomponentsjs",
"main": "webcomponents.js",
"version": "0.5.1",
"homepage": "http://webcomponents.org",
"authors": [
"The Polymer Authors"
],
"keywords": [
"webcomponents"
],
"license": "BSD",
"ignore": [],
"_release": "0.5.1",
"_resolution": {
"type": "version",
"tag": "0.5.1",
"commit": "89c466eb29642c3e5ba2594e9330eb62ade1dbab"
},
"_source": "git://github.com/Polymer/webcomponentsjs.git",
"_target": "^0.5.0",
"_originalSource": "Polymer/webcomponentsjs"
}

View File

@@ -0,0 +1,931 @@
/**
* @license
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
// @version 0.5.1
if (typeof WeakMap === "undefined") {
(function() {
var defineProperty = Object.defineProperty;
var counter = Date.now() % 1e9;
var WeakMap = function() {
this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
};
WeakMap.prototype = {
set: function(key, value) {
var entry = key[this.name];
if (entry && entry[0] === key) entry[1] = value; else defineProperty(key, this.name, {
value: [ key, value ],
writable: true
});
return this;
},
get: function(key) {
var entry;
return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefined;
},
"delete": function(key) {
var entry = key[this.name];
if (!entry || entry[0] !== key) return false;
entry[0] = entry[1] = undefined;
return true;
},
has: function(key) {
var entry = key[this.name];
if (!entry) return false;
return entry[0] === key;
}
};
window.WeakMap = WeakMap;
})();
}
(function(global) {
var registrationsTable = new WeakMap();
var setImmediate;
if (/Trident/.test(navigator.userAgent)) {
setImmediate = setTimeout;
} else if (window.setImmediate) {
setImmediate = window.setImmediate;
} else {
var setImmediateQueue = [];
var sentinel = String(Math.random());
window.addEventListener("message", function(e) {
if (e.data === sentinel) {
var queue = setImmediateQueue;
setImmediateQueue = [];
queue.forEach(function(func) {
func();
});
}
});
setImmediate = function(func) {
setImmediateQueue.push(func);
window.postMessage(sentinel, "*");
};
}
var isScheduled = false;
var scheduledObservers = [];
function scheduleCallback(observer) {
scheduledObservers.push(observer);
if (!isScheduled) {
isScheduled = true;
setImmediate(dispatchCallbacks);
}
}
function wrapIfNeeded(node) {
return window.ShadowDOMPolyfill && window.ShadowDOMPolyfill.wrapIfNeeded(node) || node;
}
function dispatchCallbacks() {
isScheduled = false;
var observers = scheduledObservers;
scheduledObservers = [];
observers.sort(function(o1, o2) {
return o1.uid_ - o2.uid_;
});
var anyNonEmpty = false;
observers.forEach(function(observer) {
var queue = observer.takeRecords();
removeTransientObserversFor(observer);
if (queue.length) {
observer.callback_(queue, observer);
anyNonEmpty = true;
}
});
if (anyNonEmpty) dispatchCallbacks();
}
function removeTransientObserversFor(observer) {
observer.nodes_.forEach(function(node) {
var registrations = registrationsTable.get(node);
if (!registrations) return;
registrations.forEach(function(registration) {
if (registration.observer === observer) registration.removeTransientObservers();
});
});
}
function forEachAncestorAndObserverEnqueueRecord(target, callback) {
for (var node = target; node; node = node.parentNode) {
var registrations = registrationsTable.get(node);
if (registrations) {
for (var j = 0; j < registrations.length; j++) {
var registration = registrations[j];
var options = registration.options;
if (node !== target && !options.subtree) continue;
var record = callback(options);
if (record) registration.enqueue(record);
}
}
}
}
var uidCounter = 0;
function JsMutationObserver(callback) {
this.callback_ = callback;
this.nodes_ = [];
this.records_ = [];
this.uid_ = ++uidCounter;
}
JsMutationObserver.prototype = {
observe: function(target, options) {
target = wrapIfNeeded(target);
if (!options.childList && !options.attributes && !options.characterData || options.attributeOldValue && !options.attributes || options.attributeFilter && options.attributeFilter.length && !options.attributes || options.characterDataOldValue && !options.characterData) {
throw new SyntaxError();
}
var registrations = registrationsTable.get(target);
if (!registrations) registrationsTable.set(target, registrations = []);
var registration;
for (var i = 0; i < registrations.length; i++) {
if (registrations[i].observer === this) {
registration = registrations[i];
registration.removeListeners();
registration.options = options;
break;
}
}
if (!registration) {
registration = new Registration(this, target, options);
registrations.push(registration);
this.nodes_.push(target);
}
registration.addListeners();
},
disconnect: function() {
this.nodes_.forEach(function(node) {
var registrations = registrationsTable.get(node);
for (var i = 0; i < registrations.length; i++) {
var registration = registrations[i];
if (registration.observer === this) {
registration.removeListeners();
registrations.splice(i, 1);
break;
}
}
}, this);
this.records_ = [];
},
takeRecords: function() {
var copyOfRecords = this.records_;
this.records_ = [];
return copyOfRecords;
}
};
function MutationRecord(type, target) {
this.type = type;
this.target = target;
this.addedNodes = [];
this.removedNodes = [];
this.previousSibling = null;
this.nextSibling = null;
this.attributeName = null;
this.attributeNamespace = null;
this.oldValue = null;
}
function copyMutationRecord(original) {
var record = new MutationRecord(original.type, original.target);
record.addedNodes = original.addedNodes.slice();
record.removedNodes = original.removedNodes.slice();
record.previousSibling = original.previousSibling;
record.nextSibling = original.nextSibling;
record.attributeName = original.attributeName;
record.attributeNamespace = original.attributeNamespace;
record.oldValue = original.oldValue;
return record;
}
var currentRecord, recordWithOldValue;
function getRecord(type, target) {
return currentRecord = new MutationRecord(type, target);
}
function getRecordWithOldValue(oldValue) {
if (recordWithOldValue) return recordWithOldValue;
recordWithOldValue = copyMutationRecord(currentRecord);
recordWithOldValue.oldValue = oldValue;
return recordWithOldValue;
}
function clearRecords() {
currentRecord = recordWithOldValue = undefined;
}
function recordRepresentsCurrentMutation(record) {
return record === recordWithOldValue || record === currentRecord;
}
function selectRecord(lastRecord, newRecord) {
if (lastRecord === newRecord) return lastRecord;
if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord)) return recordWithOldValue;
return null;
}
function Registration(observer, target, options) {
this.observer = observer;
this.target = target;
this.options = options;
this.transientObservedNodes = [];
}
Registration.prototype = {
enqueue: function(record) {
var records = this.observer.records_;
var length = records.length;
if (records.length > 0) {
var lastRecord = records[length - 1];
var recordToReplaceLast = selectRecord(lastRecord, record);
if (recordToReplaceLast) {
records[length - 1] = recordToReplaceLast;
return;
}
} else {
scheduleCallback(this.observer);
}
records[length] = record;
},
addListeners: function() {
this.addListeners_(this.target);
},
addListeners_: function(node) {
var options = this.options;
if (options.attributes) node.addEventListener("DOMAttrModified", this, true);
if (options.characterData) node.addEventListener("DOMCharacterDataModified", this, true);
if (options.childList) node.addEventListener("DOMNodeInserted", this, true);
if (options.childList || options.subtree) node.addEventListener("DOMNodeRemoved", this, true);
},
removeListeners: function() {
this.removeListeners_(this.target);
},
removeListeners_: function(node) {
var options = this.options;
if (options.attributes) node.removeEventListener("DOMAttrModified", this, true);
if (options.characterData) node.removeEventListener("DOMCharacterDataModified", this, true);
if (options.childList) node.removeEventListener("DOMNodeInserted", this, true);
if (options.childList || options.subtree) node.removeEventListener("DOMNodeRemoved", this, true);
},
addTransientObserver: function(node) {
if (node === this.target) return;
this.addListeners_(node);
this.transientObservedNodes.push(node);
var registrations = registrationsTable.get(node);
if (!registrations) registrationsTable.set(node, registrations = []);
registrations.push(this);
},
removeTransientObservers: function() {
var transientObservedNodes = this.transientObservedNodes;
this.transientObservedNodes = [];
transientObservedNodes.forEach(function(node) {
this.removeListeners_(node);
var registrations = registrationsTable.get(node);
for (var i = 0; i < registrations.length; i++) {
if (registrations[i] === this) {
registrations.splice(i, 1);
break;
}
}
}, this);
},
handleEvent: function(e) {
e.stopImmediatePropagation();
switch (e.type) {
case "DOMAttrModified":
var name = e.attrName;
var namespace = e.relatedNode.namespaceURI;
var target = e.target;
var record = new getRecord("attributes", target);
record.attributeName = name;
record.attributeNamespace = namespace;
var oldValue = e.attrChange === MutationEvent.ADDITION ? null : e.prevValue;
forEachAncestorAndObserverEnqueueRecord(target, function(options) {
if (!options.attributes) return;
if (options.attributeFilter && options.attributeFilter.length && options.attributeFilter.indexOf(name) === -1 && options.attributeFilter.indexOf(namespace) === -1) {
return;
}
if (options.attributeOldValue) return getRecordWithOldValue(oldValue);
return record;
});
break;
case "DOMCharacterDataModified":
var target = e.target;
var record = getRecord("characterData", target);
var oldValue = e.prevValue;
forEachAncestorAndObserverEnqueueRecord(target, function(options) {
if (!options.characterData) return;
if (options.characterDataOldValue) return getRecordWithOldValue(oldValue);
return record;
});
break;
case "DOMNodeRemoved":
this.addTransientObserver(e.target);
case "DOMNodeInserted":
var target = e.relatedNode;
var changedNode = e.target;
var addedNodes, removedNodes;
if (e.type === "DOMNodeInserted") {
addedNodes = [ changedNode ];
removedNodes = [];
} else {
addedNodes = [];
removedNodes = [ changedNode ];
}
var previousSibling = changedNode.previousSibling;
var nextSibling = changedNode.nextSibling;
var record = getRecord("childList", target);
record.addedNodes = addedNodes;
record.removedNodes = removedNodes;
record.previousSibling = previousSibling;
record.nextSibling = nextSibling;
forEachAncestorAndObserverEnqueueRecord(target, function(options) {
if (!options.childList) return;
return record;
});
}
clearRecords();
}
};
global.JsMutationObserver = JsMutationObserver;
if (!global.MutationObserver) global.MutationObserver = JsMutationObserver;
})(this);
window.CustomElements = window.CustomElements || {
flags: {}
};
(function(scope) {
var flags = scope.flags;
var modules = [];
var addModule = function(module) {
modules.push(module);
};
var initializeModules = function() {
modules.forEach(function(module) {
module(scope);
});
};
scope.addModule = addModule;
scope.initializeModules = initializeModules;
scope.hasNative = Boolean(document.registerElement);
scope.useNative = !flags.register && scope.hasNative && !window.ShadowDOMPolyfill && (!window.HTMLImports || HTMLImports.useNative);
})(CustomElements);
CustomElements.addModule(function(scope) {
var IMPORT_LINK_TYPE = window.HTMLImports ? HTMLImports.IMPORT_LINK_TYPE : "none";
function forSubtree(node, cb) {
findAllElements(node, function(e) {
if (cb(e)) {
return true;
}
forRoots(e, cb);
});
forRoots(node, cb);
}
function findAllElements(node, find, data) {
var e = node.firstElementChild;
if (!e) {
e = node.firstChild;
while (e && e.nodeType !== Node.ELEMENT_NODE) {
e = e.nextSibling;
}
}
while (e) {
if (find(e, data) !== true) {
findAllElements(e, find, data);
}
e = e.nextElementSibling;
}
return null;
}
function forRoots(node, cb) {
var root = node.shadowRoot;
while (root) {
forSubtree(root, cb);
root = root.olderShadowRoot;
}
}
var processingDocuments;
function forDocumentTree(doc, cb) {
processingDocuments = [];
_forDocumentTree(doc, cb);
processingDocuments = null;
}
function _forDocumentTree(doc, cb) {
doc = wrap(doc);
if (processingDocuments.indexOf(doc) >= 0) {
return;
}
processingDocuments.push(doc);
var imports = doc.querySelectorAll("link[rel=" + IMPORT_LINK_TYPE + "]");
for (var i = 0, l = imports.length, n; i < l && (n = imports[i]); i++) {
if (n.import) {
_forDocumentTree(n.import, cb);
}
}
cb(doc);
}
scope.forDocumentTree = forDocumentTree;
scope.forSubtree = forSubtree;
});
CustomElements.addModule(function(scope) {
var flags = scope.flags;
var forSubtree = scope.forSubtree;
var forDocumentTree = scope.forDocumentTree;
function addedNode(node) {
return added(node) || addedSubtree(node);
}
function added(node) {
if (scope.upgrade(node)) {
return true;
}
attached(node);
}
function addedSubtree(node) {
forSubtree(node, function(e) {
if (added(e)) {
return true;
}
});
}
function attachedNode(node) {
attached(node);
if (inDocument(node)) {
forSubtree(node, function(e) {
attached(e);
});
}
}
var hasPolyfillMutations = !window.MutationObserver || window.MutationObserver === window.JsMutationObserver;
scope.hasPolyfillMutations = hasPolyfillMutations;
var isPendingMutations = false;
var pendingMutations = [];
function deferMutation(fn) {
pendingMutations.push(fn);
if (!isPendingMutations) {
isPendingMutations = true;
setTimeout(takeMutations);
}
}
function takeMutations() {
isPendingMutations = false;
var $p = pendingMutations;
for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) {
p();
}
pendingMutations = [];
}
function attached(element) {
if (hasPolyfillMutations) {
deferMutation(function() {
_attached(element);
});
} else {
_attached(element);
}
}
function _attached(element) {
if (element.__upgraded__ && (element.attachedCallback || element.detachedCallback)) {
if (!element.__attached && inDocument(element)) {
element.__attached = true;
if (element.attachedCallback) {
element.attachedCallback();
}
}
}
}
function detachedNode(node) {
detached(node);
forSubtree(node, function(e) {
detached(e);
});
}
function detached(element) {
if (hasPolyfillMutations) {
deferMutation(function() {
_detached(element);
});
} else {
_detached(element);
}
}
function _detached(element) {
if (element.__upgraded__ && (element.attachedCallback || element.detachedCallback)) {
if (element.__attached && !inDocument(element)) {
element.__attached = false;
if (element.detachedCallback) {
element.detachedCallback();
}
}
}
}
function inDocument(element) {
var p = element;
var doc = wrap(document);
while (p) {
if (p == doc) {
return true;
}
p = p.parentNode || p.host;
}
}
function watchShadow(node) {
if (node.shadowRoot && !node.shadowRoot.__watched) {
flags.dom && console.log("watching shadow-root for: ", node.localName);
var root = node.shadowRoot;
while (root) {
observe(root);
root = root.olderShadowRoot;
}
}
}
function handler(mutations) {
if (flags.dom) {
var mx = mutations[0];
if (mx && mx.type === "childList" && mx.addedNodes) {
if (mx.addedNodes) {
var d = mx.addedNodes[0];
while (d && d !== document && !d.host) {
d = d.parentNode;
}
var u = d && (d.URL || d._URL || d.host && d.host.localName) || "";
u = u.split("/?").shift().split("/").pop();
}
}
console.group("mutations (%d) [%s]", mutations.length, u || "");
}
mutations.forEach(function(mx) {
if (mx.type === "childList") {
forEach(mx.addedNodes, function(n) {
if (!n.localName) {
return;
}
addedNode(n);
});
forEach(mx.removedNodes, function(n) {
if (!n.localName) {
return;
}
detachedNode(n);
});
}
});
flags.dom && console.groupEnd();
}
function takeRecords(node) {
node = wrap(node);
if (!node) {
node = wrap(document);
}
while (node.parentNode) {
node = node.parentNode;
}
var observer = node.__observer;
if (observer) {
handler(observer.takeRecords());
takeMutations();
}
}
var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);
function observe(inRoot) {
if (inRoot.__observer) {
return;
}
var observer = new MutationObserver(handler);
observer.observe(inRoot, {
childList: true,
subtree: true
});
inRoot.__observer = observer;
}
function upgradeDocument(doc) {
doc = wrap(doc);
flags.dom && console.group("upgradeDocument: ", doc.baseURI.split("/").pop());
addedNode(doc);
observe(doc);
flags.dom && console.groupEnd();
}
function upgradeDocumentTree(doc) {
forDocumentTree(doc, upgradeDocument);
}
var originalCreateShadowRoot = Element.prototype.createShadowRoot;
Element.prototype.createShadowRoot = function() {
var root = originalCreateShadowRoot.call(this);
CustomElements.watchShadow(this);
return root;
};
scope.watchShadow = watchShadow;
scope.upgradeDocumentTree = upgradeDocumentTree;
scope.upgradeSubtree = addedSubtree;
scope.upgradeAll = addedNode;
scope.attachedNode = attachedNode;
scope.takeRecords = takeRecords;
});
CustomElements.addModule(function(scope) {
var flags = scope.flags;
function upgrade(node) {
if (!node.__upgraded__ && node.nodeType === Node.ELEMENT_NODE) {
var is = node.getAttribute("is");
var definition = scope.getRegisteredDefinition(is || node.localName);
if (definition) {
if (is && definition.tag == node.localName) {
return upgradeWithDefinition(node, definition);
} else if (!is && !definition.extends) {
return upgradeWithDefinition(node, definition);
}
}
}
}
function upgradeWithDefinition(element, definition) {
flags.upgrade && console.group("upgrade:", element.localName);
if (definition.is) {
element.setAttribute("is", definition.is);
}
implementPrototype(element, definition);
element.__upgraded__ = true;
created(element);
scope.attachedNode(element);
scope.upgradeSubtree(element);
flags.upgrade && console.groupEnd();
return element;
}
function implementPrototype(element, definition) {
if (Object.__proto__) {
element.__proto__ = definition.prototype;
} else {
customMixin(element, definition.prototype, definition.native);
element.__proto__ = definition.prototype;
}
}
function customMixin(inTarget, inSrc, inNative) {
var used = {};
var p = inSrc;
while (p !== inNative && p !== HTMLElement.prototype) {
var keys = Object.getOwnPropertyNames(p);
for (var i = 0, k; k = keys[i]; i++) {
if (!used[k]) {
Object.defineProperty(inTarget, k, Object.getOwnPropertyDescriptor(p, k));
used[k] = 1;
}
}
p = Object.getPrototypeOf(p);
}
}
function created(element) {
if (element.createdCallback) {
element.createdCallback();
}
}
scope.upgrade = upgrade;
scope.upgradeWithDefinition = upgradeWithDefinition;
scope.implementPrototype = implementPrototype;
});
CustomElements.addModule(function(scope) {
var upgradeDocumentTree = scope.upgradeDocumentTree;
var upgrade = scope.upgrade;
var upgradeWithDefinition = scope.upgradeWithDefinition;
var implementPrototype = scope.implementPrototype;
var useNative = scope.useNative;
function register(name, options) {
var definition = options || {};
if (!name) {
throw new Error("document.registerElement: first argument `name` must not be empty");
}
if (name.indexOf("-") < 0) {
throw new Error("document.registerElement: first argument ('name') must contain a dash ('-'). Argument provided was '" + String(name) + "'.");
}
if (isReservedTag(name)) {
throw new Error("Failed to execute 'registerElement' on 'Document': Registration failed for type '" + String(name) + "'. The type name is invalid.");
}
if (getRegisteredDefinition(name)) {
throw new Error("DuplicateDefinitionError: a type with name '" + String(name) + "' is already registered");
}
if (!definition.prototype) {
definition.prototype = Object.create(HTMLElement.prototype);
}
definition.__name = name.toLowerCase();
definition.lifecycle = definition.lifecycle || {};
definition.ancestry = ancestry(definition.extends);
resolveTagName(definition);
resolvePrototypeChain(definition);
overrideAttributeApi(definition.prototype);
registerDefinition(definition.__name, definition);
definition.ctor = generateConstructor(definition);
definition.ctor.prototype = definition.prototype;
definition.prototype.constructor = definition.ctor;
if (scope.ready) {
upgradeDocumentTree(document);
}
return definition.ctor;
}
function overrideAttributeApi(prototype) {
if (prototype.setAttribute._polyfilled) {
return;
}
var setAttribute = prototype.setAttribute;
prototype.setAttribute = function(name, value) {
changeAttribute.call(this, name, value, setAttribute);
};
var removeAttribute = prototype.removeAttribute;
prototype.removeAttribute = function(name) {
changeAttribute.call(this, name, null, removeAttribute);
};
prototype.setAttribute._polyfilled = true;
}
function changeAttribute(name, value, operation) {
name = name.toLowerCase();
var oldValue = this.getAttribute(name);
operation.apply(this, arguments);
var newValue = this.getAttribute(name);
if (this.attributeChangedCallback && newValue !== oldValue) {
this.attributeChangedCallback(name, oldValue, newValue);
}
}
function isReservedTag(name) {
for (var i = 0; i < reservedTagList.length; i++) {
if (name === reservedTagList[i]) {
return true;
}
}
}
var reservedTagList = [ "annotation-xml", "color-profile", "font-face", "font-face-src", "font-face-uri", "font-face-format", "font-face-name", "missing-glyph" ];
function ancestry(extnds) {
var extendee = getRegisteredDefinition(extnds);
if (extendee) {
return ancestry(extendee.extends).concat([ extendee ]);
}
return [];
}
function resolveTagName(definition) {
var baseTag = definition.extends;
for (var i = 0, a; a = definition.ancestry[i]; i++) {
baseTag = a.is && a.tag;
}
definition.tag = baseTag || definition.__name;
if (baseTag) {
definition.is = definition.__name;
}
}
function resolvePrototypeChain(definition) {
if (!Object.__proto__) {
var nativePrototype = HTMLElement.prototype;
if (definition.is) {
var inst = document.createElement(definition.tag);
var expectedPrototype = Object.getPrototypeOf(inst);
if (expectedPrototype === definition.prototype) {
nativePrototype = expectedPrototype;
}
}
var proto = definition.prototype, ancestor;
while (proto && proto !== nativePrototype) {
ancestor = Object.getPrototypeOf(proto);
proto.__proto__ = ancestor;
proto = ancestor;
}
definition.native = nativePrototype;
}
}
function instantiate(definition) {
return upgradeWithDefinition(domCreateElement(definition.tag), definition);
}
var registry = {};
function getRegisteredDefinition(name) {
if (name) {
return registry[name.toLowerCase()];
}
}
function registerDefinition(name, definition) {
registry[name] = definition;
}
function generateConstructor(definition) {
return function() {
return instantiate(definition);
};
}
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
function createElementNS(namespace, tag, typeExtension) {
if (namespace === HTML_NAMESPACE) {
return createElement(tag, typeExtension);
} else {
return domCreateElementNS(namespace, tag);
}
}
function createElement(tag, typeExtension) {
var definition = getRegisteredDefinition(typeExtension || tag);
if (definition) {
if (tag == definition.tag && typeExtension == definition.is) {
return new definition.ctor();
}
if (!typeExtension && !definition.is) {
return new definition.ctor();
}
}
var element;
if (typeExtension) {
element = createElement(tag);
element.setAttribute("is", typeExtension);
return element;
}
element = domCreateElement(tag);
if (tag.indexOf("-") >= 0) {
implementPrototype(element, HTMLElement);
}
return element;
}
function cloneNode(deep) {
var n = domCloneNode.call(this, deep);
upgrade(n);
return n;
}
var domCreateElement = document.createElement.bind(document);
var domCreateElementNS = document.createElementNS.bind(document);
var domCloneNode = Node.prototype.cloneNode;
var isInstance;
if (!Object.__proto__ && !useNative) {
isInstance = function(obj, ctor) {
var p = obj;
while (p) {
if (p === ctor.prototype) {
return true;
}
p = p.__proto__;
}
return false;
};
} else {
isInstance = function(obj, base) {
return obj instanceof base;
};
}
document.registerElement = register;
document.createElement = createElement;
document.createElementNS = createElementNS;
Node.prototype.cloneNode = cloneNode;
scope.registry = registry;
scope.instanceof = isInstance;
scope.reservedTagList = reservedTagList;
scope.getRegisteredDefinition = getRegisteredDefinition;
document.register = document.registerElement;
});
(function(scope) {
var useNative = scope.useNative;
var initializeModules = scope.initializeModules;
if (useNative) {
var nop = function() {};
scope.watchShadow = nop;
scope.upgrade = nop;
scope.upgradeAll = nop;
scope.upgradeDocumentTree = nop;
scope.upgradeSubtree = nop;
scope.takeRecords = nop;
scope.instanceof = function(obj, base) {
return obj instanceof base;
};
} else {
initializeModules();
}
var upgradeDocumentTree = scope.upgradeDocumentTree;
if (!window.wrap) {
if (window.ShadowDOMPolyfill) {
window.wrap = ShadowDOMPolyfill.wrapIfNeeded;
window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded;
} else {
window.wrap = window.unwrap = function(node) {
return node;
};
}
}
function bootstrap() {
upgradeDocumentTree(wrap(document));
if (window.HTMLImports) {
HTMLImports.__importsParsingHook = function(elt) {
upgradeDocumentTree(wrap(elt.import));
};
}
CustomElements.ready = true;
setTimeout(function() {
CustomElements.readyTime = Date.now();
if (window.HTMLImports) {
CustomElements.elapsed = CustomElements.readyTime - HTMLImports.readyTime;
}
document.dispatchEvent(new CustomEvent("WebComponentsReady", {
bubbles: true
}));
});
}
if (typeof window.CustomEvent !== "function") {
window.CustomEvent = function(inType, params) {
params = params || {};
var e = document.createEvent("CustomEvent");
e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
return e;
};
window.CustomEvent.prototype = window.Event.prototype;
}
if (document.readyState === "complete" || scope.flags.eager) {
bootstrap();
} else if (document.readyState === "interactive" && !window.attachEvent && (!window.HTMLImports || window.HTMLImports.ready)) {
bootstrap();
} else {
var loadEvent = window.HTMLImports && !HTMLImports.ready ? "HTMLImportsLoaded" : "DOMContentLoaded";
window.addEventListener(loadEvent, bootstrap);
}
})(window.CustomElements);

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,38 @@
webcomponents.js
================
A suite of polyfills supporting the HTML web components specs:
**Custom Elements**: allows authors to define their own custom tags ([spec](https://w3c.github.io/webcomponents/spec/custom/)).
**HTML Imports**: a way to include and reuse HTML documents via other HTML documents ([spec](https://w3c.github.io/webcomponents/spec/imports/)).
**Shadow DOM**: provides encapsulation by hiding DOM subtrees under shadow roots ([spec](https://w3c.github.io/webcomponents/spec/shadow/)).
This also folds in polyfills for `MutationObserver` and `WeakMap`.
## Releases
Pre-built (concatenated & minified) versions of the polyfills are maintained in the [tagged versions](https://github.com/Polymer/webcomponentsjs/releases) of this repo. There are two variants:
`webcomponents.js` includes all of the polyfills.
`webcomponents-lite.js` includes all polyfills except for shadow DOM.
### Manually Building
If you wish to build the polyfills yourself, you'll need `node` and `gulp` on your system:
* install [node.js](http://nodejs.org/) using the instructions on their website
* use `npm` to install [gulp.js](http://gulpjs.com/): `npm install -g gulp`
Now you are ready to build the polyfills with:
# install dependencies
npm install
# build
gulp build
The builds will be placed into the `dist/` directory.

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,14 @@
{
"name": "webcomponentsjs",
"main": "webcomponents.js",
"version": "0.5.1",
"homepage": "http://webcomponents.org",
"authors": [
"The Polymer Authors"
],
"keywords": [
"webcomponents"
],
"license": "BSD",
"ignore": []
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long