Skip to content
This repository was archived by the owner on Oct 26, 2021. It is now read-only.

Commit e8b250b

Browse files
Merge pull request #1 from webcomponents/initial
Initial move from webcomponents.js
2 parents 91d740e + 3f5abb7 commit e8b250b

File tree

131 files changed

+15826
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+15826
-35
lines changed

.gitignore

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,4 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
6-
# Runtime data
7-
pids
8-
*.pid
9-
*.seed
10-
11-
# Directory for instrumented libs generated by jscoverage/JSCover
12-
lib-cov
13-
14-
# Coverage directory used by tools like istanbul
15-
coverage
16-
17-
# nyc test coverage
18-
.nyc_output
19-
20-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21-
.grunt
22-
23-
# node-waf configuration
24-
.lock-wscript
25-
26-
# Compiled binary addons (http://nodejs.org/api/addons.html)
27-
build/Release
28-
29-
# Dependency directories
301
node_modules
31-
jspm_packages
2+
bower_components
323

33-
# Optional npm cache directory
34-
.npm
35-
36-
# Optional REPL history
37-
.node_repl_history
4+
npm-debug.log*

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: node_js
2+
sudo: required
3+
dist: trusty
4+
node_js: stable
5+
addons:
6+
sauce_connect: true
7+
firefox: 48.0
8+
apt:
9+
sources:
10+
- google-chrome
11+
packages:
12+
- google-chrome-stable
13+
before_script:
14+
- export PATH=$PWD/node_modules/.bin:$PATH
15+
script:
16+
- npm run build
17+
- xvfb-run wct
18+
- if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then wct -s 'default'; fi
19+
env:
20+
global:
21+
- secure: Fpp9LwJSGOdTrSIImQTlbzxozBsqe/2AJN5OfTXSe12FZxqzz50gevdxQcIlLypKaNyCtjb980DJbwdJR2cXUqaunLZAPWxrKa7ZPwamUxW+zVL7EHqy5zuvD+yJ+Vmk3ahs3WBTVyJ8T3XoaSfo9VumDIcKggWGJwgvM3blIMg=
22+
- secure: Bj8MgzUVP0X8MLgK3d9eF48V7x0rPJyrN1IyguzKyJJVC8LV2XZXF+6o/M+zNsVMSsjhgXMkS3RRuaUShxO/OS6gHeG31FWcZqbXfZfgMMyH8a8zDls+r8m2lGEICaZo1OTXR0uiR/VNVt7n2xoBnTmjmRFwkaxAZk4yCjbXYzQ=

CONTRIBUTING.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Contributing
2+
3+
Want to contribute to webcomponents.js? Great!
4+
5+
We are more than happy to accept external contributions to the project in the form of [bug reports](../../issues) and pull requests.
6+
7+
## Contributor License Agreement
8+
9+
Before we can accept patches, there's a quick web form you need to fill out.
10+
11+
- If you're contributing as an individual (e.g. you own the intellectual property), fill out [this form](http://code.google.com/legal/individual-cla-v1.0.html).
12+
- If you're contributing under a company, fill out [this form](http://code.google.com/legal/corporate-cla-v1.0.html) instead.
13+
14+
This CLA asserts that contributions are owned by you and that we can license all work under our [license](LICENSE).
15+
16+
Other projects require a similar agreement: jQuery, Firefox, Apache, Node, and many more.
17+
18+
[More about CLAs](https://www.google.com/search?q=Contributor%20License%20Agreement)
19+
20+
## Initial setup
21+
22+
1. Setup Gulp: `sudo npm install -g gulp`
23+
1. Fork the project on github and pull down your copy.
24+
> replace the {{ username }} with your username and {{ repository }} with the repository name
25+
26+
git clone [email protected]:{{ username }}/{{ repository }}.git
27+
28+
1. Test your change results in a working build.
29+
> in the repo you've made changes to, try generating a build:
30+
31+
cd $REPO
32+
npm install
33+
gulp build
34+
35+
The builds will be placed into the `dist/` directory if all goes well.
36+
37+
1. Commit your code and make a pull request.
38+
39+
That's it for the one time setup. Now you're ready to make a change.
40+
41+
## Submitting a pull request
42+
43+
We iterate fast! To avoid potential merge conflicts, it's a good idea to pull from the main project before making a change and submitting a pull request. The easiest way to do this is setup a remote called `upstream` and do a pull before working on a change:
44+
45+
git remote add upstream git://github.com/polymer/webcomponentsjs.git
46+
47+
Then before making a change, do a pull from the upstream `master` branch:
48+
49+
git pull upstream master
50+
51+
To make life easier, add a "pull upstream" alias in your `.gitconfig`:
52+
53+
[alias]
54+
pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
55+
56+
That will pull in changes from your forked repo, the main (upstream) repo, and merge the two. Then it's just a matter of running `git pu` before a change and pushing to your repo:
57+
58+
git checkout master
59+
git pu
60+
# make change
61+
git commit -a -m 'Awesome things.'
62+
git push
63+
64+
Lastly, don't forget to submit the pull request.

CustomElements.min.js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CustomElements.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DEVELOPING.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Custom Elements v1
2+
3+
## Status
4+
5+
The polyfill should be mostly feature complete now. It supports defining
6+
custom elements, the custom element reactions, and upgrading existing elements. It integrates with native Shadow DOM v1, and native and polyfilled HTML Imports.
7+
8+
The implementation could use more tests, especially around ordering of
9+
reactions. The source references old versions of the spec.
10+
11+
### To do
12+
13+
1. Implement Node#isConnected
14+
2. Implement built-in element extension (is=)
15+
3. Add reaction callback ordering tests
16+
4. Reorganize tests to be closer to spec structure
17+
5. Performance tests
18+
19+
## Building & Running Tests
20+
21+
1. Install web-component-tester
22+
23+
```bash
24+
$ npm i -g web-component-tester
25+
```
26+
27+
2. Checkout the webcomponentsjs v1 branch
28+
29+
```bash
30+
$ git clone https://github.com/webcomponents/webcomponentsjs.git
31+
$ cd webcomponentsjs
32+
$ npm i
33+
$ gulp build
34+
```
35+
36+
3. Run tests
37+
38+
```bash
39+
$ wct tests/CustomElements/v1/index.html -l chrome
40+
```
41+
42+
4. Bower link to use in another project
43+
44+
```bash
45+
$ bower link
46+
$ cd {your project directory}
47+
$ bower link webcomponentsjs
48+
```
49+
50+
## Implementation approach and browser support
51+
52+
The polyfill leans heavily on MutationObservers to drive custom element creation and reactions. This means that the polyfill requires native or polyfilled MutationObservers. The polyfill also uses Map and Set, though those would be easy to polyfill or remove.
53+
54+
The implementation should work without additional polyfills in IE 11, Edge, Safari >6, Firefox, Chrome, Android Browser >4.4, and Opera (not Mini).
55+
56+
IE 10 should be supported with the Mutation Observer polyfill.
57+
58+
This branch does not pass the CI tests yet, but it passes locally in Chrome 52, Safari 9.1, Safari Technical Preview, and Firefox 47.
59+
60+
Because MutationObservers are used to create custom element instances and react to document structure and attribute changes, all reactions are asynchronous while in the specs, some are synchronous. This is by design, since some of the synchronous reactions are impossible to polyfill. We consider it more important that reactions have the same relative timing to each other as the spec, for example attributeChangedCallback happens after connectedCallback.
61+
62+
### Implementing the "Constructor-call Trick"
63+
64+
The HTMLElement constructor is now specified to return a different object than `this`, so that the parser and upgrades can call the constructor on elements that have already been allocated. JavaScript allows this, but some compilers, such as TypeScript and Closure currently don't.
65+
66+
The HTMLElement constructor is also specified to look up the tag name associated with a constructor by using `new.target`. `new.target` isn't available in ES5, is not polyfillable, but `this.constructor` behaves similarly for most ES5 class patterns, including the output of Babel, TypeScript and Closure, so the polyfill uses that to look up tag names.
67+
68+
`new.target` isn't even feature detectable, since it's a syntax error in ES5. Because of this, the polyfill can't check `new.target` first and fallback to `this.constructor`. This also means that ES5-style constructors can't conditionally make a "super" call to the HTMLElement constructor (with `Reflect.construct`) in non-ES6 environments to be compatible with native Custom Elements.
69+
70+
To allow for elements that work in both ES5 and ES6 environments, we provide a shim to be used in browsers that have native Custom Elements v1 support, that overrides the HTMLElement constructor and calls `Reflect.construct` with either the value of `new.target` or `this.constructor`. This shim can only be executed in ES6 environments that support `new.target`, and so should be conditionally loaded. The shim and the polyfill should not be loaded at the same time.
71+
72+
## Building
73+
74+
The Custom Elements V1 polyfill does not use the same module or build system as
75+
the other webcomponentsjs polyfills, and its build is not integrated into the default build tasks yet.
76+
77+
To build run:
78+
79+
gulp CustomElementsV1
80+
81+
This creates a CustomElementsV1.min.js file in dist/
82+
83+
## Custom Elements in the DOM Spec
84+
85+
### 4.2.3 Mutation Algorithms
86+
87+
https://dom.spec.whatwg.org/#mutation-algorithms
88+
89+
* insert 6.5.2.1: call connectedCallback
90+
* insert 6.5.2.2: upgrade
91+
* remove 14: call disconnectedCallback
92+
* remove 15.2: call disconnectedCallback
93+
94+
### 4.4 Node
95+
96+
https://dom.spec.whatwg.org/#concept-node-clone
97+
98+
* clone 2.1: performs create-element
99+
* clone 2.2: append attributes
100+
101+
isConnected looks like it's Custom Elements related, but it's actually part of Shadow DOM. We might want to implement it for on non-native Shadow DOM environments, since we already watch for all connections and disconnections.
102+
103+
### 4.5 Document
104+
105+
https://dom.spec.whatwg.org/#interface-document
106+
107+
* createElement and createElementNS take ElementCreationOptions
108+
109+
https://dom.spec.whatwg.org/#dom-document-createelement
110+
111+
* createElement 3, 4, 5, 7
112+
* createElementNS 2, 3, 4, 5
113+
114+
### 4.9 Element
115+
116+
https://dom.spec.whatwg.org/#concept-element-custom-element-state
117+
118+
https://dom.spec.whatwg.org/#concept-create-element
119+
120+
* create an element 2, 3, 4, 5, 6
121+
122+
https://dom.spec.whatwg.org/#concept-element-attributes-change
123+
124+
* change an attribute 2
125+
126+
https://dom.spec.whatwg.org/#concept-element-attributes-append
127+
128+
* append an attribute 2
129+
130+
https://dom.spec.whatwg.org/#concept-element-attributes-remove
131+
132+
* remove an attribute 2
133+
134+
https://dom.spec.whatwg.org/#concept-element-attributes-replace
135+
136+
* replace an attribute 2
137+
138+
https://dom.spec.whatwg.org/#dom-element-attachshadow
139+
140+
* attachShadow 2 (nothing to implement)
141+
142+
## Custom Elements in the HTML Spec
143+
144+
145+
### 3.2.3 HTML element constructors
146+
147+
https://html.spec.whatwg.org/multipage/dom.html#html-element-constructors
148+
149+
* HTML element constructors 1-9
150+
151+
### 4.13 Custom Elements
152+
153+
https://html.spec.whatwg.org/multipage/scripting.html#custom-elements
154+
155+
https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-name
156+
157+
https://html.spec.whatwg.org/multipage/scripting.html#customelementsregistry
158+
159+
### 7.3 Window
160+
161+
https://html.spec.whatwg.org/multipage/browsers.html#window
162+
163+
* Window#customElements
164+
165+
https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-the-token
166+
167+
* create an element for a token 3, 4, 5, 6, 7, 8, 9

LICENSE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# License
2+
3+
Everything in this repo is BSD style license unless otherwise specified.
4+
5+
Copyright (c) 2015 The Polymer Authors. All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following disclaimer
13+
in the documentation and/or other materials provided with the
14+
distribution.
15+
* Neither the name of Google Inc. nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)