Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit 19bde72

Browse files
authored
Merge pull request #514 from webcomponents/v1
Custom Elements v1
2 parents 5b70476 + f286932 commit 19bde72

File tree

340 files changed

+1721
-32667
lines changed

Some content is hidden

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

340 files changed

+1721
-32667
lines changed

.autoclave-build.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

.eslintrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"env": {
4+
"browser": true,
5+
"es6": true
6+
},
7+
"parserOptions": {
8+
"ecmaVersion": 6,
9+
"sourceType": "module"
10+
}
11+
}

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/webcomponents*.js binary
2+
/webcomponents*.js.map binary
3+
/webcomponents-loader.js text

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ sudo: required
33
dist: trusty
44
node_js: stable
55
addons:
6-
sauce_connect: true
7-
firefox: 48.0
6+
firefox: latest
87
apt:
98
sources:
109
- google-chrome
1110
packages:
1211
- google-chrome-stable
13-
before_script:
14-
- export PATH=$PWD/node_modules/.bin:$PATH
1512
script:
16-
- xvfb-run wct
17-
- if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then wct -s 'default'; fi
13+
- npm install -g bower
14+
- bower install
15+
- xvfb-run wct -l chrome
16+
- xvfb-run wct -l firefox
17+
- if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then wct -s 'windows 10/microsoftedge@14' -s 'windows 8.1/internet explorer@11' -s 'os x 10.11/safari@10' -s 'os x 10.11/safari@9'; fi
1818
env:
1919
global:
2020
- secure: Fpp9LwJSGOdTrSIImQTlbzxozBsqe/2AJN5OfTXSe12FZxqzz50gevdxQcIlLypKaNyCtjb980DJbwdJR2cXUqaunLZAPWxrKa7ZPwamUxW+zVL7EHqy5zuvD+yJ+Vmk3ahs3WBTVyJ8T3XoaSfo9VumDIcKggWGJwgvM3blIMg=

README.md

Lines changed: 65 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,86 @@
1-
webcomponents.js (v0 spec polyfills)
1+
webcomponents.js (v1 spec polyfills)
22
================
33

44
[![Build Status](https://travis-ci.org/webcomponents/webcomponentsjs.svg?branch=master)](https://travis-ci.org/webcomponents/webcomponentsjs)
55

6-
> **Note**. For polyfills that work with Custom Elements and Shadow DOM v1, see the [v1 branch](https://github.com/webcomponents/webcomponentsjs/tree/v1).
6+
> **Note**. For polyfills that work with the older Custom Elements and Shadow DOM v0 specs, see the [master branch](https://github.com/webcomponents/webcomponentsjs/).
77
88
A suite of polyfills supporting the [Web Components](http://webcomponents.org) specs:
99

10-
**Custom Elements v0**: allows authors to define their own custom tags ([spec](https://w3c.github.io/webcomponents/spec/custom/)).
10+
- **Custom Elements v1**: allows authors to define their own custom tags ([spec](https://w3c.github.io/webcomponents/spec/custom/), [tutorial](https://developers.google.com/web/fundamentals/getting-started/primers/customelements)).
11+
- **HTML Imports**: a way to include and reuse HTML documents via other HTML documents ([spec](https://w3c.github.io/webcomponents/spec/imports/), [tutorial](https://www.html5rocks.com/en/tutorials/webcomponents/imports/)).
12+
- **Shadow DOM v1**: provides encapsulation by hiding DOM subtrees under shadow roots ([spec](https://w3c.github.io/webcomponents/spec/shadow/), [tutorial](https://developers.google.com/web/fundamentals/getting-started/primers/shadowdom)).
1113

12-
**HTML Imports**: a way to include and reuse HTML documents via other HTML documents ([spec](https://w3c.github.io/webcomponents/spec/imports/)).
14+
For browsers that need it, there are also some minor polyfills included:
15+
- [`HTMLTemplateElement`](https://github.com/webcomponents/template)
16+
- [`Promise`](https://github.com/stefanpenner/es6-promise)
17+
- `Event`, `CustomEvent`, `MouseEvent` constructors and `Object.assign`, `Array.from` (see [webcomponents-platform](https://github.com/webcomponents/webcomponents-platform))
1318

14-
**Shadow DOM v0**: provides encapsulation by hiding DOM subtrees under shadow roots ([spec](https://w3c.github.io/webcomponents/spec/shadow/)).
19+
## How to use
1520

16-
This also folds in polyfills for `MutationObserver` and `WeakMap`.
21+
The polyfills are built (concatenated & minified) into several bundles that target
22+
different browsers and spec readiness:
1723

18-
## Releases
24+
- `webcomponents-hi.js` -- HTML Imports (needed by Safari Tech Preview)
25+
- `webcomponents-hi-ce.js` -- HTML Imports and Custom Elements v1 (needed by Safari 10)
26+
- `webcomponents-hi-sd-ce.js` -- HTML Imports, Custom Elements v1 and Shady DOM/CSS (needed by Safari 9, Firefox, Edge)
27+
- `webcomponents-sd-ce.js` -- Custom Elements and Shady DOM/CSS (no HTML Imports)
28+
- `webcomponents-lite.js` -- all of the polyfills: HTML Imports, Custom Elements, Shady DOM/CSS and generic platform polyfills (such as ES6 Promise, Constructable events, etc.) (needed by Internet Explorer 11), and Template (needed by IE 11 and Edge)
1929

20-
Pre-built (concatenated & minified) versions of the polyfills are maintained in the [tagged versions](https://github.com/webcomponents/webcomponentsjs/releases) of this repo. There are two variants:
30+
If you are only targeting a specific browser, you can just use the bundle that's
31+
needed by it; alternatively, if your server is capable of serving different assets based on user agent, you can send the polyfill bundle that's necessary for the browser making that request.
2132

22-
`webcomponents.js` includes all of the polyfills.
33+
## `webcomponents-loader.js`
2334

24-
`webcomponents-lite.js` includes all polyfills except for shadow DOM.
35+
Alternatively, this repo also comes with `webcomponents-loader.js`, a client-side
36+
loader that dynamically loads the minimum polyfill bundle, using feature detection.
37+
Note that because the bundle will be loaded asynchronously, you should wait for the `WebComponentsReady` before you can safely assume that all the polyfills have
38+
loaded and are ready to be used (i.e. if you want to dynamically load other custom
39+
elements, etc.). Here's an example:
2540

41+
```
42+
<!-- Load polyfills; note that "loader" will load these async -->
43+
<script src="bower_components/webcomponentsjs/webcomponents-loader.js"></script>
44+
45+
<!-- Load a custom element definition via HTMLImports -->
46+
<link rel="import" href="my-element.html">
47+
48+
<!-- Use the custom element -->
49+
<my-element></my-element>
50+
51+
<!-- Interact with the upgraded element -->
52+
<script>
53+
window.addEventListener('WebComponentsReady', function() {
54+
// At this point we are guaranteed that all required polyfills have loaded,
55+
// all HTML imports have loaded, and all defined custom elements have upgraded
56+
let MyElement = customElements.get('my-element');
57+
let element = document.querySelector('my-element');
58+
console.assert(element instanceof MyElement); // 👍
59+
element.someAPI(); // 👍
60+
});
61+
</script>
62+
```
2663

2764
## Browser Support
2865

29-
Our polyfills are intended to work in the latest versions of evergreen browsers. See below
66+
The polyfills are intended to work in the latest versions of evergreen browsers. See below
3067
for our complete browser support matrix:
3168

32-
| Polyfill | IE10 | IE11+ | Chrome* | Firefox* | Safari 7+* | Chrome Android* | Mobile Safari* |
33-
| ---------- |:----:|:-----:|:-------:|:--------:|:----------:|:---------------:|:--------------:|
34-
| Custom Elements | ~ |||||||
35-
| HTML Imports | ~ |||||||
36-
| Shadow DOM ||||||||
37-
| Templates ||||||||
38-
69+
| Polyfill | IE11+ | Chrome* | Firefox* | Safari 9+* | Chrome Android* | Mobile Safari* |
70+
| ---------- |:-----:|:-------:|:--------:|:----------:|:---------------:|:--------------:|
71+
| Custom Elements |||||||
72+
| HTML Imports |||||||
73+
| Shady CSS/DOM |||||||
3974

40-
*Indicates the current version of the browser
75+
\*Indicates the current version of the browser
4176

42-
~Indicates support may be flaky. If using Custom Elements or HTML Imports with Shadow DOM,
43-
you will get the non-flaky Mutation Observer polyfill that Shadow DOM includes.
44-
45-
The polyfills may work in older browsers, however require additional polyfills (such as classList)
46-
to be used. We cannot guarantee support for browsers outside of our compatibility matrix.
77+
The polyfills may work in older browsers, however require additional polyfills (such as classList, or other [platform](https://github.com/webcomponents/webcomponents-platform)
78+
polyfills) to be used. We cannot guarantee support for browsers outside of our compatibility matrix.
4779

4880

4981
### Manually Building
5082

51-
If you wish to build the polyfills yourself, you'll need `node` and `gulp` on your system:
83+
If you wish to build the bundles yourself, you'll need `node` and `npm` on your system:
5284

5385
* install [node.js](http://nodejs.org/) using the instructions on their website
5486
* use `npm` to install [gulp.js](http://gulpjs.com/): `npm install -g gulp`
@@ -57,10 +89,11 @@ Now you are ready to build the polyfills with:
5789

5890
# install dependencies
5991
npm install
92+
bower install
6093
# build
6194
gulp build
6295

63-
The builds will be placed into the `dist/` directory.
96+
The builds will be placed into the root directory.
6497

6598
## Contribute
6699

@@ -76,11 +109,11 @@ Copyright (c) 2015 The Polymer Authors. All rights reserved.
76109

77110
### `WebComponentsReady`
78111

79-
Under native HTML Imports, `<script>` tags in the main document block the loading of such imports. This is to ensure the imports have loaded and any registered elements in them have been upgraded.
112+
Under native HTML Imports, `<script>` tags in the main document block the loading of such imports. This is to ensure the imports have loaded and any registered elements in them have been upgraded.
80113

81-
The webcomponents.js and webcomponents-lite.js polyfills parse element definitions and handle their upgrade asynchronously. If prematurely fetching the element from the DOM before it has an opportunity to upgrade, you'll be working with an `HTMLUnknownElement`.
114+
The `webcomponents-lite.js` polyfill (as well as the smaller bundles and the loader) parse element definitions and handle their upgrade asynchronously. If prematurely fetching the element from the DOM before it has an opportunity to upgrade, you'll be working with an `HTMLUnknownElement`.
82115

83-
For these situations (or when you need an approximate replacement for the Polymer 0.5 `polymer-ready` behavior), you can use the `WebComponentsReady` event as a signal before interacting with the element. The criteria for this event to fire is all Custom Elements with definitions registered by the time HTML Imports available at load time have loaded have upgraded.
116+
For these situations, you can use the `WebComponentsReady` event as a signal before interacting with the element. The criteria for this event to fire is all Custom Elements with definitions registered by the time HTML Imports available at load time have loaded have upgraded.
84117

85118
```js
86119
window.addEventListener('WebComponentsReady', function(e) {
@@ -91,34 +124,9 @@ window.addEventListener('WebComponentsReady', function(e) {
91124

92125
## Known Issues
93126

94-
* [Limited CSS encapsulation](#encapsulation)
95-
* [Element wrapping / unwrapping limitations](#wrapping)
96127
* [Custom element's constructor property is unreliable](#constructor)
97128
* [Contenteditable elements do not trigger MutationObserver](#contentedit)
98-
* [ShadowCSS: :host-context(...):host(...) doesn't work](#hostcontext)
99-
* [ShadowCSS: :host(.zot:not(.bar:nth-child(2))) doesn't work](#nestedparens)
100-
* [HTML imports: document.currentScript doesn't work as expected](#currentscript)
101-
* [execCommand isn't supported under Shadow DOM](#execcommand)
102-
103-
### Limited CSS encapsulation <a id="encapsulation"></a>
104-
Under native Shadow DOM, CSS selectors cannot cross the shadow boundary. This means document level styles don't apply to shadow roots, and styles defined within a shadow root don't apply outside of that shadow root. [Several selectors](http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-201/) are provided to be able to deal with the shadow boundary.
105-
106-
The Shadow DOM polyfill can't prevent document styles from leaking into shadow roots. It can, however, encapsulate styles within shadow roots to some extent. This behavior isn't automatically emulated by the Shadow DOM polyfill, but it can be achieved by manually using the included ShadowCSS shim:
107-
108-
```
109-
WebComponents.ShadowCSS.shimStyling( shadowRoot, scope );
110-
```
111-
112-
... where `shadowRoot` is the shadow root of a DOM element, and `scope` is the name of the scope used to prefix the selectors. This removes all `<style>` elements from the shadow root, rewrites it rules using the given scope and reinserts the style as a document level stylesheet. Note that the `:host` and `:host-context` pseudo classes are also rewritten.
113-
114-
For a full explanation on the implementation and both the possibilities and the limitations of ShadowCSS please view the documentation in the [ShadowCSS source](src/ShadowCSS/ShadowCSS.js).
115-
116-
### Element wrapping / unwrapping limitations <a id="wrapping"></a>
117-
The Shadow DOM polyfill is implemented by [wrapping](http://webcomponents.org/polyfills/shadow-dom/#wrappers) DOM elements whenever possible. It does this by wrapping methods like `document.querySelector` to return wrapped DOM elements. This has a few caveats:
118-
* Not _everything_ can be wrapped. For example, elements like `document`, `window`, `document.body`, `document.fullscreenElement` and others are non-configurable and thus cannot be overridden.
119-
* Wrappers don't support [live NodeLists](https://developer.mozilla.org/en-US/docs/Web/API/NodeList#A_sometimes-live_collection) like `HTMLElement.childNodes` and `HTMLFormElement.elements`. All NodeLists are snapshotted upon read. See [#217](https://github.com/webcomponents/webcomponentsjs/issues/217) for an explanation.
120-
121-
In order to work around these limitations the polyfill provides the `ShadowDOMPolyfill.wrap` and `ShadowDOMPolyfill.unwrap` methods to respectively wrap and unwrap DOM elements manually.
129+
* [ShadyCSS: :host(.zot:not(.bar:nth-child(2))) doesn't work](#nestedparens)
122130

123131
### Custom element's constructor property is unreliable <a id="constructor"></a>
124132
See [#215](https://github.com/webcomponents/webcomponentsjs/issues/215) for background.
@@ -131,26 +139,5 @@ It's worth noting that `customElement.__proto__.__proto__.constructor` is `HTMLE
131139
Using the MutationObserver polyfill, it isn't possible to monitor mutations of an element marked `contenteditable`.
132140
See [the mailing list](https://groups.google.com/forum/#!msg/polymer-dev/LHdtRVXXVsA/v1sGoiTYWUkJ)
133141

134-
### ShadowCSS: :host-context(...):host(...) doesn't work <a id="hostcontext"></a>
135-
See [#16](https://github.com/webcomponents/webcomponentsjs/issues/16) for background.
136-
137-
Under the shadow DOM polyfill, rules like:
138-
```
139-
:host-context(.foo):host(.bar) {...}
140-
```
141-
don't work, despite working under native Shadow DOM. The solution is to use `polyfill-next-selector` like:
142-
143-
```
144-
polyfill-next-selector { content: '.foo :host.bar, :host.foo.bar'; }
145-
```
146-
147-
### ShadowCSS: :host(.zot:not(.bar:nth-child(2))) doesn't work <a id="nestedparens"></a>
148-
ShadowCSS `:host()` rules can only have (at most) 1-level of nested parentheses in its argument selector under ShadowCSS. For example, `:host(.zot)` and `:host(.zot:not(.bar))` both work, but `:host(.zot:not(.bar:nth-child(2)))` does not.
149-
150-
### HTML imports: document.currentScript doesn't work as expected <a id="currentscript"></a>
151-
In native HTML Imports, document.currentScript.ownerDocument references the import document itself. In the polyfill use document._currentScript.ownerDocument (note the underscore).
152-
153-
### execCommand and contenteditable isn't supported under Shadow DOM <a id="execcommand"></a>
154-
See [#212](https://github.com/webcomponents/webcomponentsjs/issues/212)
155-
156-
`execCommand`, and `contenteditable` aren't supported under the ShadowDOM polyfill, with commands that insert or remove nodes being especially prone to failure.
142+
### ShadyCSS: :host(.zot:not(.bar:nth-child(2))) doesn't work <a id="nestedparens"></a>
143+
ShadyCSS `:host()` rules can only have (at most) 1-level of nested parentheses in its argument selector under ShadyCSS. For example, `:host(.zot)` and `:host(.zot:not(.bar))` both work, but `:host(.zot:not(.bar:nth-child(2)))` does not.

bower.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "webcomponentsjs",
33
"main": "webcomponents.js",
4-
"version": "0.7.24",
4+
"version": "1.0.0",
55
"homepage": "http://webcomponents.org",
66
"authors": [
77
"The Polymer Authors"
@@ -16,6 +16,13 @@
1616
"license": "BSD",
1717
"ignore": [],
1818
"devDependencies": {
19-
"web-component-tester": "^4.0.1"
19+
"web-component-tester": "^5",
20+
"custom-elements": "webcomponents/custom-elements#master",
21+
"es6-promise": "stefanpenner/es6-promise#^4.0.0",
22+
"html-imports": "webcomponents/html-imports#master",
23+
"shadydom": "webcomponents/shadydom#master",
24+
"shadycss": "webcomponents/shadycss#master",
25+
"template": "webcomponents/template#master",
26+
"webcomponents-platform": "webcomponents/webcomponents-platform#master"
2027
}
2128
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
@license
3+
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
4+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7+
Code distributed by Google as part of the polymer project is also
8+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9+
*/
10+
'use strict';
11+
12+
/*
13+
* Polyfills loaded: HTML Imports, Custom Elements
14+
* Used in: Safari 10, Firefox once SD is shipped
15+
*/
16+
17+
import '../bower_components/html-imports/src/html-imports.js'
18+
import '../bower_components/custom-elements/src/custom-elements.js'
19+
20+
import '../src/post-polyfill.js'
21+
import '../src/unresolved.js'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
@license
3+
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
4+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7+
Code distributed by Google as part of the polymer project is also
8+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9+
*/
10+
'use strict';
11+
12+
/*
13+
* Polyfills loaded: HTML Imports
14+
* Used in: Safari Tech Preview
15+
*/
16+
17+
import '../bower_components/html-imports/src/html-imports.js'
18+
19+
import '../src/post-polyfill.js'
20+
import '../src/unresolved.js'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
@license
3+
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
4+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7+
Code distributed by Google as part of the polymer project is also
8+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9+
*/
10+
'use strict';
11+
12+
/*
13+
* Polyfills loaded: HTML Imports, Custom Elements, Shady DOM/Shady CSS
14+
* Used in: Safari 9, Firefox, Edge
15+
*/
16+
17+
import '../bower_components/html-imports/src/html-imports.js'
18+
import '../bower_components/shadydom/src/shadydom.js'
19+
import '../bower_components/custom-elements/src/custom-elements.js'
20+
import '../bower_components/shadycss/entrypoints/scoping-shim.js'
21+
import '../src/post-polyfill.js'
22+
import '../src/unresolved.js'

0 commit comments

Comments
 (0)