├── .eslintrc.json ├── .gitattributes ├── .github └── CODEOWNERS ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── closure-output.txt ├── entrypoints ├── custom-elements-es5-adapter-index.js ├── webcomponents-bundle-index.js ├── webcomponents-ce-index.js ├── webcomponents-sd-ce-index.js ├── webcomponents-sd-ce-pf-index.js └── webcomponents-sd-index.js ├── externs └── webcomponents.js ├── gulpfile.js ├── license-header.txt ├── package-lock.json ├── package.json ├── src ├── baseuri.js ├── flag-parser.js ├── promise.js ├── symbol.js └── unresolved.js ├── tests ├── .eslintrc.json ├── async-loader-no-polyfills.html ├── async-loader-with-modules.html ├── baseuri.html ├── bundle-after-load.html ├── bundle-with-modules.html ├── dev-loader-swizzled.html ├── dev-loader.html ├── force-polyfills.html ├── imports │ ├── a1-define.html │ ├── a1-import.html │ ├── a1-instance.html │ ├── a1-reference.html │ ├── csp-import-1.html │ ├── csp-import-2.html │ ├── csp-script-1.js │ ├── csp-script-2.js │ ├── current-script.js │ ├── element-import-a.html │ ├── element-import-b.html │ ├── element-import.html │ ├── import-file.html │ ├── import-upgrade-order.html │ ├── script-1.html │ ├── script-2.html │ ├── simple-element-2.js │ ├── simple-element-es5.html │ ├── simple-element-es5.js │ ├── simple-element.html │ └── simple-element.js ├── integration-es5.html ├── integration.html ├── load.html ├── loader-after-load.html ├── loader-with-modules.html ├── loader-with-root-defined.html ├── modules │ ├── common-subclass.js │ ├── module-a-sub.js │ ├── module-a.js │ └── module-b.js ├── promise.html ├── runner.html ├── symbol.html ├── template-and-CE.html ├── url.html └── wct-config.js ├── wct.conf.json └── webcomponents-loader.js /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint:recommended", 3 | "env": { 4 | "browser": true, 5 | "es6": true 6 | }, 7 | "parserOptions": { 8 | "ecmaVersion": 2018, 9 | "sourceType": "module" 10 | }, 11 | "plugins": [ 12 | "html" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | /webcomponents-bundle.js* binary 2 | /package-lock.json binary 3 | /bundles/* binary 4 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @azakus 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | custom-elements-es5-adapter.js 3 | webcomponents-bundle.js* 4 | bundles/**/* 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | dist: trusty 4 | node_js: '9' 5 | addons: 6 | firefox: latest 7 | chrome: stable 8 | before_script: 9 | - npm run build 10 | script: 11 | - wct 12 | - if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then wct -s 'windows 10/microsoftedge@17' -s 'windows 10/microsoftedge@15' -s 'windows 8.1/internet explorer@11' -s 'macos 10.13/safari@11' -s 'macos 10.12/safari@10' -s 'os x 10.11/safari@9' -s 'Linux/chrome@41'; fi 13 | env: 14 | global: 15 | - secure: Fpp9LwJSGOdTrSIImQTlbzxozBsqe/2AJN5OfTXSe12FZxqzz50gevdxQcIlLypKaNyCtjb980DJbwdJR2cXUqaunLZAPWxrKa7ZPwamUxW+zVL7EHqy5zuvD+yJ+Vmk3ahs3WBTVyJ8T3XoaSfo9VumDIcKggWGJwgvM3blIMg= 16 | - secure: Bj8MgzUVP0X8MLgK3d9eF48V7x0rPJyrN1IyguzKyJJVC8LV2XZXF+6o/M+zNsVMSsjhgXMkS3RRuaUShxO/OS6gHeG31FWcZqbXfZfgMMyH8a8zDls+r8m2lGEICaZo1OTXR0uiR/VNVt7n2xoBnTmjmRFwkaxAZk4yCjbXYzQ= 17 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 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 | For any bug report, please use [this jsbin](http://jsbin.com/birajez/edit?html,console,output) to provide a concrete reproduction case that we can debug. 8 | 9 | ## Contributor License Agreement 10 | 11 | Before we can accept patches, there's a quick web form you need to fill out. 12 | 13 | - 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). 14 | - If you're contributing under a company, fill out [this form](http://code.google.com/legal/corporate-cla-v1.0.html) instead. 15 | 16 | This CLA asserts that contributions are owned by you and that we can license all work under our [license](LICENSE). 17 | 18 | Other projects require a similar agreement: jQuery, Firefox, Apache, Node, and many more. 19 | 20 | [More about CLAs](https://www.google.com/search?q=Contributor%20License%20Agreement) 21 | 22 | ## Initial setup 23 | 24 | 1. Setup Gulp: `sudo npm install -g gulp` 25 | 1. Fork the project on github and pull down your copy. 26 | > replace the {{ username }} with your username and {{ repository }} with the repository name 27 | 28 | git clone git@github.com:{{ username }}/{{ repository }}.git 29 | 30 | 1. Test your change results in a working build. 31 | > in the repo you've made changes to, try generating a build: 32 | 33 | cd $REPO 34 | npm install 35 | gulp 36 | 37 | The builds will be placed into the `dist/` directory if all goes well. 38 | 39 | 1. Commit your code and make a pull request. 40 | 41 | That's it for the one time setup. Now you're ready to make a change. 42 | 43 | ## Submitting a pull request 44 | 45 | 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: 46 | 47 | git remote add upstream git://github.com/polymer/webcomponentsjs.git 48 | 49 | Then before making a change, do a pull from the upstream `master` branch: 50 | 51 | git pull upstream master 52 | 53 | To make life easier, add a "pull upstream" alias in your `.gitconfig`: 54 | 55 | [alias] 56 | pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master" 57 | 58 | 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: 59 | 60 | git checkout master 61 | git pu 62 | # make change 63 | git commit -a -m 'Awesome things.' 64 | git push 65 | 66 | Lastly, don't forget to submit the pull request. 67 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 🚨 Moved to [`webcomponents/polyfills/packages/webcomponentsjs`][1] 🚨 2 | 3 | The [`webcomponents/webcomponentsjs`][2] repo has been migrated to [`packages/webcomponentsjs`][1] folder of the [`webcomponents/polyfills`][3] 🚝 *monorepo*. 4 | 5 | We are *actively* working on migrating open Issues and PRs to the new repo. New Issues and PRs should be filed at [`webcomponents/polyfills`][3]. 6 | 7 | [1]: https://github.com/webcomponents/polyfills/tree/master/packages/webcomponentsjs 8 | [2]: https://github.com/webcomponents/webcomponentsjs 9 | [3]: https://github.com/webcomponents/polyfills 10 | -------------------------------------------------------------------------------- /closure-output.txt: -------------------------------------------------------------------------------- 1 | /** 2 | @license @nocompile 3 | Copyright (c) 2018 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 | (function(){%output%}).call(this); -------------------------------------------------------------------------------- /entrypoints/custom-elements-es5-adapter-index.js: -------------------------------------------------------------------------------- 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: Custom Elements ES5 Shim 14 | */ 15 | 16 | import '../node_modules/@webcomponents/custom-elements/src/native-shim.js'; 17 | -------------------------------------------------------------------------------- /entrypoints/webcomponents-bundle-index.js: -------------------------------------------------------------------------------- 1 | /** 2 | @license 3 | Copyright (c) 2018 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, platform polyfills, template 14 | * Used in: webcomponents bundle to load ALL the things 15 | */ 16 | 17 | import './webcomponents-sd-ce-pf-index.js'; 18 | 19 | const customElements = window.customElements; 20 | 21 | let shouldFlush = false; 22 | /** @type {?function()} */ 23 | let flusher = null; 24 | 25 | if (customElements['polyfillWrapFlushCallback']) { 26 | customElements['polyfillWrapFlushCallback']((flush) => { 27 | flusher = flush; 28 | if (shouldFlush) { 29 | flush(); 30 | } 31 | }); 32 | } 33 | 34 | function flushAndFire() { 35 | if (window.HTMLTemplateElement.bootstrap) { 36 | window.HTMLTemplateElement.bootstrap(window.document); 37 | } 38 | flusher && flusher(); 39 | shouldFlush = true; 40 | window.WebComponents.ready = true; 41 | document.dispatchEvent(new CustomEvent('WebComponentsReady', { bubbles: true })); 42 | } 43 | 44 | if (document.readyState !== 'complete') { 45 | // this script may come between DCL and load, so listen for both, and cancel load listener if DCL fires 46 | window.addEventListener('load', flushAndFire) 47 | window.addEventListener('DOMContentLoaded', () => { 48 | window.removeEventListener('load', flushAndFire); 49 | flushAndFire(); 50 | }); 51 | } else { 52 | flushAndFire(); 53 | } -------------------------------------------------------------------------------- /entrypoints/webcomponents-ce-index.js: -------------------------------------------------------------------------------- 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: Custom Elements 14 | * Used in: Safari 10 15 | */ 16 | 17 | import '../node_modules/@webcomponents/custom-elements/src/custom-elements.js'; -------------------------------------------------------------------------------- /entrypoints/webcomponents-sd-ce-index.js: -------------------------------------------------------------------------------- 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: Custom Elements, Shady DOM/Shady CSS 14 | * Used in: Safari 9, Firefox, Edge 15 | */ 16 | 17 | import '../node_modules/@webcomponents/shadydom/src/shadydom.js'; 18 | import '../node_modules/@webcomponents/custom-elements/src/custom-elements.js'; 19 | import '../node_modules/@webcomponents/shadycss/entrypoints/scoping-shim.js'; -------------------------------------------------------------------------------- /entrypoints/webcomponents-sd-ce-pf-index.js: -------------------------------------------------------------------------------- 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: Custom Elements, Shady DOM/Shady CSS, platform polyfills, template 14 | * Used in: IE 11 15 | */ 16 | 17 | import '../node_modules/@webcomponents/webcomponents-platform/webcomponents-platform.js'; 18 | import '../node_modules/@webcomponents/template/template.js'; 19 | import '../src/promise.js'; 20 | import '../src/symbol.js'; 21 | import '../src/flag-parser.js'; 22 | import '../node_modules/@webcomponents/shadydom/src/shadydom.js'; 23 | import '../node_modules/@webcomponents/custom-elements/src/custom-elements.js'; 24 | import '../node_modules/@webcomponents/shadycss/entrypoints/scoping-shim.js'; 25 | import '../node_modules/@webcomponents/url/url.js'; 26 | import '../src/baseuri.js'; 27 | import '../src/unresolved.js'; 28 | -------------------------------------------------------------------------------- /entrypoints/webcomponents-sd-index.js: -------------------------------------------------------------------------------- 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: Shady DOM/Shady CSS 14 | * Used in: Firefox when CE is implemented 15 | */ 16 | 17 | import '../node_modules/@webcomponents/shadydom/src/shadydom.js'; 18 | import '../node_modules/@webcomponents/shadycss/entrypoints/scoping-shim.js'; -------------------------------------------------------------------------------- /externs/webcomponents.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @externs 3 | * @fileoverview Symbols needed to compile webcomponents 4 | * @license 5 | * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. 6 | * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 7 | * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 8 | * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 9 | * Code distributed by Google as part of the polymer project is also 10 | * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 11 | */ 12 | var require; 13 | var global; 14 | var ES6Promise; 15 | var process; 16 | var define; 17 | var module; 18 | var exports; 19 | 20 | var ShadyDOM; 21 | var WebComponents; 22 | 23 | /** @type {!Function} */ 24 | Promise.cast; 25 | 26 | /** @type {function()} */ 27 | HTMLTemplateElement.bootstrap; 28 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 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 | 11 | 'use strict'; 12 | 13 | /* eslint-env node */ 14 | /* eslint-disable no-console */ 15 | 16 | const gulp = require('gulp'); 17 | const sourcemaps = require('gulp-sourcemaps'); 18 | const sourcesContent = require('@gulp-sourcemaps/sources-content'); 19 | const rename = require('gulp-rename'); 20 | const rollup = require('gulp-rollup'); 21 | const del = require('del'); 22 | const runseq = require('run-sequence'); 23 | const closure = require('google-closure-compiler').gulp(); 24 | const babel = require('rollup-plugin-babel'); 25 | const commonjs = require('rollup-plugin-commonjs'); 26 | const license = require('rollup-plugin-license'); 27 | 28 | function debugify(sourceName, fileName, extraRollupOptions) { 29 | const outDir = fileName ? '.' : './bundles'; 30 | 31 | if (!fileName) { 32 | fileName = sourceName; 33 | } 34 | 35 | const entry = `./entrypoints/${sourceName}-index.js`; 36 | 37 | const options = { 38 | input: entry, 39 | output: { 40 | format: 'iife', 41 | name: 'webcomponentsjs' 42 | }, 43 | allowRealFiles: true, 44 | rollup: require('rollup') 45 | }; 46 | 47 | Object.assign(options, extraRollupOptions); 48 | 49 | return gulp.src(entry) 50 | .pipe(rollup(options)) 51 | .pipe(rename(`${fileName}.js`)) 52 | .pipe(gulp.dest(outDir)) 53 | } 54 | 55 | function closurify(sourceName, fileName) { 56 | const outDir = fileName ? '.' : './bundles'; 57 | const smPrefix = fileName ? '' : '../'; 58 | 59 | if (!fileName) { 60 | fileName = sourceName; 61 | } 62 | 63 | const closureOptions = { 64 | compilation_level: 'ADVANCED', 65 | language_in: 'ES6_STRICT', 66 | language_out: 'ES5_STRICT', 67 | isolation_mode: 'NONE', 68 | output_wrapper_file: 'closure-output.txt', 69 | assume_function_wrapper: true, 70 | js_output_file: `${fileName}.js`, 71 | warning_level: 'VERBOSE', 72 | rewrite_polyfills: false, 73 | module_resolution: 'NODE', 74 | entry_point: `entrypoints/${sourceName}-index.js`, 75 | dependency_mode: 'STRICT', 76 | process_common_js_modules: true, 77 | externs: [ 78 | 'externs/webcomponents.js', 79 | 'node_modules/@webcomponents/custom-elements/externs/custom-elements.js', 80 | 'node_modules/@webcomponents/shadycss/externs/shadycss-externs.js', 81 | 'node_modules/@webcomponents/shadydom/externs/shadydom.js' 82 | ] 83 | }; 84 | 85 | return gulp.src([ 86 | 'entrypoints/*.js', 87 | 'src/*.js', 88 | 'node_modules/get-own-property-symbols/build/get-own-property-symbols.max.js', 89 | 'node_modules/promise-polyfill/src/**/*.js', 90 | 'node_modules/@webcomponents/**/*.js', 91 | '!node_modules/@webcomponents/*/externs/*.js', 92 | '!node_modules/@webcomponents/*/node_modules/**' 93 | ], {base: './', follow: true}) 94 | .pipe(sourcemaps.init()) 95 | .pipe(closure(closureOptions)) 96 | .pipe(sourcesContent()) 97 | .pipe(sourcemaps.mapSources( 98 | // We load from node_modules, but the other polyfills are technically siblings of us. 99 | // Therefore, rewrite the sourcemap files to fixup the directory location 100 | sourcePath => sourcePath 101 | .replace(/node_modules\/@webcomponents/, smPrefix + '..') 102 | .replace(/node_modules/, smPrefix + '../..') 103 | .replace(/^src/, smPrefix + 'src') 104 | )) 105 | .pipe(sourcemaps.write('.')) 106 | .pipe(gulp.dest(outDir)); 107 | } 108 | 109 | gulp.task('debugify-ce', () => { 110 | return debugify('webcomponents-ce') 111 | }); 112 | 113 | gulp.task('debugify-sd-ce-pf', () => { 114 | const rollupOptions = { 115 | plugins: [commonjs()] 116 | }; 117 | return debugify('webcomponents-sd-ce-pf', null, rollupOptions) 118 | }); 119 | 120 | gulp.task('debugify-sd-ce', () => { 121 | return debugify('webcomponents-sd-ce') 122 | }); 123 | 124 | gulp.task('debugify-sd', () => { 125 | return debugify('webcomponents-sd') 126 | }); 127 | 128 | gulp.task('debugify-bundle', () => { 129 | const rollupOptions = { 130 | plugins: [commonjs()] 131 | }; 132 | return debugify('webcomponents-bundle', 'webcomponents-bundle', rollupOptions); 133 | }) 134 | 135 | gulp.task('closurify-ce', () => { 136 | return closurify('webcomponents-ce') 137 | }); 138 | 139 | gulp.task('closurify-sd-ce-pf', () => { 140 | return closurify('webcomponents-sd-ce-pf') 141 | }); 142 | 143 | gulp.task('closurify-sd-ce', () => { 144 | return closurify('webcomponents-sd-ce') 145 | }); 146 | 147 | gulp.task('closurify-sd', () => { 148 | return closurify('webcomponents-sd') 149 | }); 150 | 151 | gulp.task('closurify-bundle', () => { 152 | return closurify('webcomponents-bundle', 'webcomponents-bundle'); 153 | }); 154 | 155 | gulp.task('debugify-ce-es5-adapter', () => { 156 | const rollupOptions = { 157 | plugins: [ 158 | babel({ 159 | presets: [ 160 | ['minify', {'keepFnName': true}] 161 | ], 162 | }), 163 | license({ 164 | banner: { 165 | file: './license-header.txt' 166 | } 167 | }) 168 | ] 169 | }; 170 | return debugify('custom-elements-es5-adapter', 'custom-elements-es5-adapter', rollupOptions); 171 | }); 172 | 173 | gulp.task('default', ['closure']); 174 | 175 | gulp.task('clean', () => { 176 | return del([ 177 | 'custom-elements-es5-adapter.js{,.map}', 178 | 'bundles', 179 | 'webcomponents-bundle.js{,.map}' 180 | ]); 181 | }); 182 | 183 | gulp.task('debug', (cb) => { 184 | const tasks = [ 185 | 'debugify-ce', 186 | 'debugify-sd', 187 | 'debugify-sd-ce', 188 | 'debugify-sd-ce-pf', 189 | 'debugify-bundle', 190 | 'debugify-ce-es5-adapter' 191 | ]; 192 | runseq('clean', tasks, cb); 193 | }); 194 | 195 | gulp.task('closure', (cb) => { 196 | const tasks = [ 197 | 'closurify-ce', 198 | 'closurify-sd', 199 | 'closurify-sd-ce', 200 | 'closurify-sd-ce-pf', 201 | 'closurify-bundle', 202 | 'debugify-ce-es5-adapter' 203 | ]; 204 | runseq('clean', ...tasks, cb); 205 | }); 206 | 207 | process.on('unhandledRejection', (err) => { 208 | console.error('Unhandled Promise Rejection:', err); 209 | process.exit(1); 210 | }) 211 | -------------------------------------------------------------------------------- /license-header.txt: -------------------------------------------------------------------------------- 1 | /** 2 | @license @nocompile 3 | Copyright (c) 2018 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 | */ -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@webcomponents/webcomponentsjs", 3 | "version": "2.2.10", 4 | "description": "Web Components Polyfills", 5 | "main": "webcomponents-bundle.js", 6 | "directories": { 7 | "test": "tests" 8 | }, 9 | "keywords": [ 10 | "webcomponents", 11 | "web-components", 12 | "polyfill", 13 | "shim" 14 | ], 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/webcomponents/webcomponentsjs.git" 18 | }, 19 | "author": "The Polymer Authors", 20 | "license": "BSD-3-Clause", 21 | "bugs": { 22 | "url": "https://github.com/webcomponents/webcomponentsjs/issues" 23 | }, 24 | "scripts": { 25 | "build": "gulp", 26 | "test": "wct", 27 | "regen-package-lock": "rm -rf node_modules package-lock.json; npm install", 28 | "prepack": "npm run build", 29 | "clean": "gulp clean" 30 | }, 31 | "homepage": "https://webcomponents.org/polyfills", 32 | "devDependencies": { 33 | "@gulp-sourcemaps/sources-content": "^1.1.0", 34 | "@webcomponents/custom-elements": "^1.2.4", 35 | "@webcomponents/shadycss": "^1.9.1", 36 | "@webcomponents/shadydom": "^1.6.0", 37 | "@webcomponents/template": "^1.4.0", 38 | "@webcomponents/url": "^0.7.3", 39 | "@webcomponents/webcomponents-platform": "^1.0.1", 40 | "babel-core": "^6.26.3", 41 | "babel-preset-minify": "^0.4.3", 42 | "del": "^3.0.0", 43 | "eslint": "^5.16.0", 44 | "eslint-plugin-html": "^4.0.6", 45 | "get-own-property-symbols": "^0.9.2", 46 | "google-closure-compiler": "^20180805.0.0", 47 | "gulp": "^3.8.8", 48 | "gulp-babel": "^7.0.1", 49 | "gulp-rename": "^1.4.0", 50 | "gulp-rollup": "^2.16.2", 51 | "gulp-sourcemaps": "^2.6.5", 52 | "promise-polyfill": "^8.0.0", 53 | "rollup": "^0.60.7", 54 | "rollup-plugin-babel": "^3.0.7", 55 | "rollup-plugin-commonjs": "^9.3.4", 56 | "rollup-plugin-license": "^0.6.0", 57 | "run-sequence": "^2.2.1", 58 | "wct-browser-legacy": "^1.0.2", 59 | "web-component-tester": "^6.9.2" 60 | }, 61 | "publishConfig": { 62 | "access": "public" 63 | }, 64 | "files": [ 65 | "bundles/**/*", 66 | "entrypoints/**/*", 67 | "custom-elements-es5-adapter.js", 68 | "webcomponents-bundle.js", 69 | "webcomponents-bundle.js.map", 70 | "webcomponents-loader.js" 71 | ] 72 | } 73 | -------------------------------------------------------------------------------- /src/baseuri.js: -------------------------------------------------------------------------------- 1 | /** 2 | @license 3 | Copyright (c) 2018 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 | 11 | export {}; 12 | 13 | // Implement Node.baseURI for IE 11 14 | // adapted from 15 | // https://github.com/webcomponents/html-imports/blob/v1.2.0/src/html-imports.js 16 | 17 | /** @type {Object|undefined} */ 18 | const native_baseURI = Object.getOwnPropertyDescriptor(Node.prototype, 'baseURI'); 19 | if (!native_baseURI) { 20 | Object.defineProperty(Node.prototype, 'baseURI', { 21 | /** 22 | * @this {Node} 23 | * @return {string} 24 | */ 25 | get() { 26 | // this.ownerDocument is `null` for documents 27 | const doc = this.ownerDocument || this; 28 | const base = /** @type {HTMLBaseElement} */ (doc.querySelector('base[href]')); 29 | return base && base.href || window.location.href; 30 | }, 31 | configurable: true, 32 | enumerable: true 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /src/flag-parser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright (c) 2014 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 | 11 | export {}; 12 | 13 | // Establish scope. 14 | window['WebComponents'] = window['WebComponents'] || {'flags':{}}; 15 | 16 | // loading script 17 | let file = 'webcomponents-bundle'; 18 | let script = document.querySelector('script[src*="' + file + '"]'); 19 | let flagMatcher = /wc-(.+)/; 20 | 21 | // Flags. Convert url arguments to flags 22 | let flags = {}; 23 | if (!flags['noOpts']) { 24 | // from url 25 | location.search.slice(1).split('&').forEach(function(option) { 26 | let parts = option.split('='); 27 | let match; 28 | if (parts[0] && (match = parts[0].match(flagMatcher))) { 29 | flags[match[1]] = parts[1] || true; 30 | } 31 | }); 32 | // from script 33 | if (script) { 34 | for (let i=0, a; (a=script.attributes[i]); i++) { 35 | if (a.name !== 'src') { 36 | flags[a.name] = a.value || true; 37 | } 38 | } 39 | } 40 | // log flags 41 | if (flags['log'] && flags['log']['split']) { 42 | let parts = flags['log'].split(','); 43 | flags['log'] = {}; 44 | parts.forEach(function(f) { 45 | flags['log'][f] = true; 46 | }); 47 | } else { 48 | flags['log'] = {}; 49 | } 50 | } 51 | 52 | // exports 53 | window['WebComponents']['flags'] = flags; 54 | let forceShady = flags['shadydom']; 55 | if (forceShady) { 56 | window['ShadyDOM'] = window['ShadyDOM'] || {}; 57 | window['ShadyDOM']['force'] = forceShady; 58 | } 59 | 60 | let forceCE = flags['register'] || flags['ce']; 61 | if (forceCE && window['customElements']) { 62 | window['customElements']['forcePolyfill'] = forceCE; 63 | } 64 | -------------------------------------------------------------------------------- /src/promise.js: -------------------------------------------------------------------------------- 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 | 11 | import PromisePolyfill from '../node_modules/promise-polyfill/src/index.js'; 12 | 13 | /* 14 | Assign the ES6 promise polyfill to window ourselves instead of using the "auto" polyfill 15 | to work around https://github.com/webcomponents/webcomponentsjs/issues/837 16 | */ 17 | if (!window.Promise) { 18 | window.Promise = PromisePolyfill; 19 | // save Promise API 20 | /* eslint-disable no-self-assign */ 21 | // PromisePolyfill.prototype['catch'] = PromisePolyfill.prototype.catch; 22 | PromisePolyfill.prototype['then'] = PromisePolyfill.prototype.then; 23 | // PromisePolyfill.prototype['finally'] = PromisePolyfill.prototype.finally; 24 | PromisePolyfill['all'] = PromisePolyfill.all; 25 | PromisePolyfill['race'] = PromisePolyfill.race; 26 | PromisePolyfill['resolve'] = PromisePolyfill.resolve; 27 | PromisePolyfill['reject'] = PromisePolyfill.reject; 28 | /* eslint-enable */ 29 | 30 | // approach copied from https://github.com/Polymer/polymer/blob/v3.0.2/lib/utils/async.js 31 | const node = document.createTextNode(''); 32 | const twiddleNode = function twiddleNode() { 33 | node.textContent = node.textContent.length > 0 ? '' : 'a'; 34 | }; 35 | /** @type {!Array} */ 36 | const callbacks = []; 37 | (new MutationObserver(() => { 38 | const len = callbacks.length; 39 | for (let i = 0; i < len; i++) { 40 | callbacks[i](); 41 | } 42 | callbacks.splice(0, len); 43 | }).observe(node, {characterData: true})); 44 | 45 | // set _immediateFn to a MutationObserver for close-to-native timing 46 | PromisePolyfill._immediateFn = (fn) => { 47 | callbacks.push(fn); 48 | twiddleNode(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/symbol.js: -------------------------------------------------------------------------------- 1 | /** 2 | @license 3 | Copyright (c) 2018 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 | 11 | // import polyfill for Symbol and Object.getOwnPropertySymbols 12 | import '../node_modules/get-own-property-symbols/build/get-own-property-symbols.max.js'; 13 | 14 | // Fix issue in toString patch when compiled into strict mode via closure 15 | // https://github.com/es-shims/get-own-property-symbols/issues/16 16 | const toString = Object.prototype.toString; 17 | Object.prototype.toString = function() { 18 | if (this === undefined) { 19 | return '[object Undefined]'; 20 | } else if (this === null) { 21 | return '[object Null]'; 22 | } else { 23 | return toString.call(this); 24 | } 25 | } 26 | 27 | // overwrite Object.keys to filter out symbols 28 | Object.keys = function(obj) { 29 | return Object.getOwnPropertyNames(obj).filter((name) => { 30 | const prop = Object.getOwnPropertyDescriptor(obj, name); 31 | return prop && prop.enumerable; 32 | }); 33 | }; 34 | 35 | // implement iterators for IE 11 36 | const iterator = window.Symbol.iterator; 37 | 38 | if (!String.prototype[iterator] || !String.prototype.codePointAt) { 39 | /** @this {String} */ 40 | String.prototype[iterator] = function*() { 41 | for (let i = 0; i < this.length; i++) { 42 | yield this[i]; 43 | } 44 | } 45 | } 46 | 47 | if (!Set.prototype[iterator]) { 48 | /** @this {Set} */ 49 | Set.prototype[iterator] = function*() { 50 | const temp = []; 51 | this.forEach((value) => { 52 | temp.push(value); 53 | }); 54 | for (let i = 0; i < temp.length; i++) { 55 | yield temp[i]; 56 | } 57 | }; 58 | } 59 | 60 | if (!Map.prototype[iterator]) { 61 | /** @this {Map} */ 62 | Map.prototype[iterator] = function*() { 63 | const entries = []; 64 | this.forEach((value, key) => { 65 | entries.push([key, value]); 66 | }); 67 | for(let i = 0; i < entries.length; i++) { 68 | yield entries[i]; 69 | } 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /src/unresolved.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright (c) 2014 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 | 11 | export {}; 12 | 13 | // It's desireable to provide a default stylesheet 14 | // that's convenient for styling unresolved elements, but 15 | // it's cumbersome to have to include this manually in every page. 16 | // It would make sense to put inside some HTMLImport but 17 | // the HTMLImports polyfill does not allow loading of stylesheets 18 | // that block rendering. Therefore this injection is tolerated here. 19 | // 20 | // NOTE: position: relative fixes IE's failure to inherit opacity 21 | // when a child is not statically positioned. 22 | let style = document.createElement('style'); 23 | style.textContent = '' 24 | + 'body {' 25 | + 'transition: opacity ease-in 0.2s;' 26 | + ' } \n' 27 | + 'body[unresolved] {' 28 | + 'opacity: 0; display: block; overflow: hidden; position: relative;' 29 | + ' } \n' 30 | ; 31 | let head = document.querySelector('head'); 32 | head.insertBefore(style, head.firstChild); 33 | -------------------------------------------------------------------------------- /tests/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env":{ 3 | "mocha": true 4 | }, 5 | "globals": { 6 | "assert": true, 7 | "WCT": true 8 | } 9 | } -------------------------------------------------------------------------------- /tests/async-loader-no-polyfills.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 19 | Test loader async/no-polyfills cases 20 | 21 | 22 | 23 | 27 | 28 | 38 | 45 | 52 | 53 | 54 | 55 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /tests/async-loader-with-modules.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | Test full bundle and modules 15 | 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 28 | 29 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /tests/baseuri.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | Test baseURI Polyfill 14 | 15 | 16 | 17 | 18 | 19 | 33 | 34 | -------------------------------------------------------------------------------- /tests/bundle-after-load.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | Test full bundle and modules 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 35 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /tests/bundle-with-modules.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | Test full bundle and modules 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /tests/dev-loader-swizzled.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /tests/dev-loader.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /tests/force-polyfills.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | Force polyfills 15 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /tests/imports/a1-define.html: -------------------------------------------------------------------------------- 1 | 10 | 33 | -------------------------------------------------------------------------------- /tests/imports/a1-import.html: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/imports/a1-instance.html: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/imports/a1-reference.html: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 20 | -------------------------------------------------------------------------------- /tests/imports/csp-import-1.html: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/imports/csp-import-2.html: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /tests/imports/csp-script-1.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright (c) 2014 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 | 11 | window.externalScriptParsed1 = new Date().getTime(); 12 | -------------------------------------------------------------------------------- /tests/imports/csp-script-2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright (c) 2014 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 | 11 | window.externalScriptParsed2 = new Date().getTime(); 12 | -------------------------------------------------------------------------------- /tests/imports/current-script.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright (c) 2014 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 | 11 | remoteCurrentScriptExecuted = window.remoteCurrentScriptExecuted || 0; 12 | remoteCurrentScriptExecuted++; 13 | assert.ok(document._currentScript); 14 | -------------------------------------------------------------------------------- /tests/imports/element-import-a.html: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/imports/element-import-b.html: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/imports/element-import.html: -------------------------------------------------------------------------------- 1 | 10 | 11 | 21 | -------------------------------------------------------------------------------- /tests/imports/import-file.html: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /tests/imports/import-upgrade-order.html: -------------------------------------------------------------------------------- 1 | 10 | 11 | -------------------------------------------------------------------------------- /tests/imports/script-1.html: -------------------------------------------------------------------------------- 1 | 10 |
me
11 | 16 | 17 | -------------------------------------------------------------------------------- /tests/imports/script-2.html: -------------------------------------------------------------------------------- 1 | 10 |
me2
11 | 15 | 16 | -------------------------------------------------------------------------------- /tests/imports/simple-element-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | @license 3 | Copyright(c) 2016 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 | 11 | // Kick off shady CSS. 12 | class SimpleElement2 extends HTMLElement { 13 | constructor() { 14 | super(); 15 | this.upgraded = Date.now(); 16 | } 17 | connectedCallback() { 18 | this.textContent = `${this.localName} ${this.upgraded}`; 19 | } 20 | } 21 | 22 | window.customElements.define('simple-element-2', SimpleElement2); -------------------------------------------------------------------------------- /tests/imports/simple-element-es5.html: -------------------------------------------------------------------------------- 1 | 10 | 11 | 55 | -------------------------------------------------------------------------------- /tests/imports/simple-element-es5.js: -------------------------------------------------------------------------------- 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 | 11 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 12 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } 13 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } 14 | 15 | // Kick off shady CSS. 16 | var template = document.createElement('template'); 17 | template.innerHTML = 18 | ` 19 | 20 |

Shadow DOM

21 | 22 | `; 23 | if (template) { 24 | if (window.ShadyCSS) { 25 | window.ShadyCSS.prepareTemplate(template, 'simple-element'); 26 | } 27 | } 28 | 29 | var SimpleElement = function (_HTMLElement) { 30 | _inherits(SimpleElement, _HTMLElement); 31 | 32 | function SimpleElement() { 33 | _classCallCheck(this, SimpleElement); 34 | 35 | var _this = _possibleConstructorReturn(this, (SimpleElement.__proto__ || Object.getPrototypeOf(SimpleElement)).call(this)); 36 | 37 | _this.bestName = 'batman'; 38 | if (window.ShadyCSS) { 39 | window.ShadyCSS.styleElement(_this); 40 | } 41 | 42 | if (template && !_this.shadowRoot) { 43 | _this.attachShadow({ mode: 'open' }); 44 | _this.shadowRoot.appendChild(document.importNode(template.content, true)); 45 | } 46 | return _this; 47 | } 48 | 49 | return SimpleElement; 50 | }(HTMLElement); 51 | 52 | window.customElements.define('simple-element', SimpleElement); -------------------------------------------------------------------------------- /tests/imports/simple-element.html: -------------------------------------------------------------------------------- 1 | 10 | 11 | 43 | -------------------------------------------------------------------------------- /tests/imports/simple-element.js: -------------------------------------------------------------------------------- 1 | /* 2 | @license 3 | Copyright(c) 2016 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 | 11 | // Kick off shady CSS. 12 | var template = document.createElement('template'); 13 | template.innerHTML = 14 | ` 15 | 16 |

Shadow DOM

17 | 18 | `; 19 | if (template) { 20 | if (window.ShadyCSS) { 21 | window.ShadyCSS.prepareTemplate(template, 'simple-element'); 22 | } 23 | } 24 | 25 | class SimpleElement extends HTMLElement { 26 | constructor() { 27 | super(); 28 | this.bestName = 'batman'; 29 | if (window.ShadyCSS) { 30 | window.ShadyCSS.styleElement(this); 31 | } 32 | 33 | if (template && !this.shadowRoot) { 34 | this.attachShadow({ mode: 'open' }); 35 | this.shadowRoot.appendChild(document.importNode(template.content, true)); 36 | } 37 | } 38 | } 39 | 40 | window.customElements.define('simple-element', SimpleElement); -------------------------------------------------------------------------------- /tests/integration-es5.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | Integration Test 14 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | Light DOM 30 | 31 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /tests/integration.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | Integration Test 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Light DOM 23 | 24 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /tests/load.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /tests/loader-after-load.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | Test full bundle and modules 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 35 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /tests/loader-with-modules.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | Test full bundle and modules 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /tests/loader-with-root-defined.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 32 | 33 | 34 | 35 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /tests/modules/common-subclass.js: -------------------------------------------------------------------------------- 1 | /** 2 | @license 3 | Copyright (c) 2018 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 | 11 | export class BaseClass extends HTMLElement { 12 | constructor() { 13 | super(); 14 | const template = this.constructor.template; 15 | if (template) { 16 | if (window.ShadyCSS && !template._prepared) { 17 | window.ShadyCSS.prepareTemplate(template, this.localName); 18 | } 19 | this.attachShadow({mode: 'open'}).appendChild(template.content.cloneNode(true)); 20 | } 21 | } 22 | connectedCallback() { 23 | if (window.ShadyCSS) { 24 | window.ShadyCSS.styleElement(this); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /tests/modules/module-a-sub.js: -------------------------------------------------------------------------------- 1 | /** 2 | @license 3 | Copyright (c) 2018 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 | 11 | import {BaseClass} from './common-subclass.js'; 12 | 13 | const template = document.createElement('template'); 14 | template.innerHTML = ` 15 | 21 | `; 22 | 23 | class ModuleASub extends BaseClass { 24 | static get template() { 25 | return template; 26 | } 27 | } 28 | 29 | customElements.define('module-a-sub', ModuleASub); -------------------------------------------------------------------------------- /tests/modules/module-a.js: -------------------------------------------------------------------------------- 1 | /** 2 | @license 3 | Copyright (c) 2018 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 | 11 | import {BaseClass} from './common-subclass.js'; 12 | import './module-a-sub.js'; 13 | 14 | const template = document.createElement('template'); 15 | template.innerHTML = ` 16 | 22 | 23 | `; 24 | 25 | class ModuleA extends BaseClass { 26 | static get template() { 27 | return template; 28 | } 29 | } 30 | 31 | customElements.define('module-a', ModuleA); -------------------------------------------------------------------------------- /tests/modules/module-b.js: -------------------------------------------------------------------------------- 1 | /** 2 | @license 3 | Copyright (c) 2018 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 | */ -------------------------------------------------------------------------------- /tests/promise.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | Test Promise Polyfill 14 | 15 | 16 | 17 | 18 | 19 | 20 | 45 | 46 | -------------------------------------------------------------------------------- /tests/runner.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | All WebComponents Tests 12 | 13 | 14 | 15 | 16 | 17 | 18 | 38 | 45 | 87 | 90 | -------------------------------------------------------------------------------- /tests/symbol.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | Symbol Polyfill 14 | 15 | 16 | 17 | 18 | 19 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /tests/template-and-CE.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | Template with HTMLImports Test 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /tests/url.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | URL Polyfill 15 | 16 | 17 | 18 | 19 | 20 | 21 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /tests/wct-config.js: -------------------------------------------------------------------------------- 1 | window.WCT = { 2 | environmentScripts: [ 3 | 'stacky/lib/parsing.js', 4 | 'stacky/lib/formatting.js', 5 | 'stacky/lib/normalization.js', 6 | 'mocha/mocha.js', 7 | 'chai/chai.js', 8 | '@polymer/sinonjs/sinon.js', 9 | // 'accessibility-developer-tools/dist/js/axs_testing.js', 10 | // '@polymer/test-fixture/test-fixture.js' 11 | ], 12 | environmentImports: [], 13 | // verbose: true 14 | } -------------------------------------------------------------------------------- /wct.conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "suites": ["tests/runner.html"], 3 | "clientOptions": { 4 | "environmentImports": [] 5 | }, 6 | "npm": true, 7 | "plugins": { 8 | "local": { 9 | "browserOptions": { 10 | "chrome": [ 11 | "headless", 12 | "disable-gpu", 13 | "no-sandbox" 14 | ], 15 | "firefox": [ 16 | "-headless" 17 | ] 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /webcomponents-loader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright (c) 2018 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 | 11 | (function() { 12 | 'use strict'; 13 | 14 | /** 15 | * Basic flow of the loader process 16 | * 17 | * There are 4 flows the loader can take when booting up 18 | * 19 | * - Synchronous script, no polyfills needed 20 | * - wait for `DOMContentLoaded` 21 | * - fire WCR event, as there could not be any callbacks passed to `waitFor` 22 | * 23 | * - Synchronous script, polyfills needed 24 | * - document.write the polyfill bundle 25 | * - wait on the `load` event of the bundle to batch Custom Element upgrades 26 | * - wait for `DOMContentLoaded` 27 | * - run callbacks passed to `waitFor` 28 | * - fire WCR event 29 | * 30 | * - Asynchronous script, no polyfills needed 31 | * - wait for `DOMContentLoaded` 32 | * - run callbacks passed to `waitFor` 33 | * - fire WCR event 34 | * 35 | * - Asynchronous script, polyfills needed 36 | * - Append the polyfill bundle script 37 | * - wait for `load` event of the bundle 38 | * - batch Custom Element Upgrades 39 | * - run callbacks pass to `waitFor` 40 | * - fire WCR event 41 | */ 42 | 43 | var polyfillsLoaded = false; 44 | var whenLoadedFns = []; 45 | var allowUpgrades = false; 46 | var flushFn; 47 | 48 | function fireEvent() { 49 | window.WebComponents.ready = true; 50 | document.dispatchEvent(new CustomEvent('WebComponentsReady', { bubbles: true })); 51 | } 52 | 53 | function batchCustomElements() { 54 | if (window.customElements && customElements.polyfillWrapFlushCallback) { 55 | customElements.polyfillWrapFlushCallback(function (flushCallback) { 56 | flushFn = flushCallback; 57 | if (allowUpgrades) { 58 | flushFn(); 59 | } 60 | }); 61 | } 62 | } 63 | 64 | function asyncReady() { 65 | batchCustomElements(); 66 | ready(); 67 | } 68 | 69 | function ready() { 70 | // bootstrap