diff --git a/bower.json b/bower.json index b01f22b..4f5d918 100644 --- a/bower.json +++ b/bower.json @@ -19,13 +19,6 @@ "license": "BSD-3-Clause", "ignore": [], "devDependencies": { - "web-component-tester": "^v6.0.0", - "custom-elements": "webcomponents/custom-elements#^v1.0.0", - "es6-promise": "stefanpenner/es6-promise#^4.0.0", - "html-imports": "webcomponents/html-imports#^v1.0.0", - "shadydom": "webcomponents/shadydom#^v1.0.0", - "shadycss": "webcomponents/shadycss#^v1.0.0", - "template": "webcomponents/template#^v1.0.0", - "webcomponents-platform": "webcomponents/webcomponents-platform#^v1.0.0" + "web-component-tester": "^v6.0.0" } } diff --git a/entrypoints/custom-elements-es5-adapter-index.js b/entrypoints/custom-elements-es5-adapter-index.js index 93c0077..7000b62 100644 --- a/entrypoints/custom-elements-es5-adapter-index.js +++ b/entrypoints/custom-elements-es5-adapter-index.js @@ -13,4 +13,4 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN * Polyfills loaded: Custom Elements ES5 Shim */ -import '../bower_components/custom-elements/src/native-shim.js' +import '../node_modules/@webcomponents/custom-elements/src/native-shim.js'; diff --git a/entrypoints/webcomponents-hi-ce-index.js b/entrypoints/webcomponents-hi-ce-index.js index 5b85289..4f6ab4d 100644 --- a/entrypoints/webcomponents-hi-ce-index.js +++ b/entrypoints/webcomponents-hi-ce-index.js @@ -14,8 +14,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN * Used in: Safari 10, Firefox once SD is shipped */ -import '../bower_components/html-imports/src/html-imports.js' -import '../bower_components/custom-elements/src/custom-elements.js' +import '../node_modules/@webcomponents/html-imports/src/html-imports.js'; +import '../node_modules/@webcomponents/custom-elements/src/custom-elements.js'; -import '../src/post-polyfill.js' -import '../src/unresolved.js' +import '../src/post-polyfill.js'; +import '../src/unresolved.js'; diff --git a/entrypoints/webcomponents-hi-index.js b/entrypoints/webcomponents-hi-index.js index d02073c..e55027f 100644 --- a/entrypoints/webcomponents-hi-index.js +++ b/entrypoints/webcomponents-hi-index.js @@ -14,7 +14,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN * Used in: Safari Tech Preview */ -import '../bower_components/html-imports/src/html-imports.js' +import '../node_modules/@webcomponents/html-imports/src/html-imports.js'; -import '../src/post-polyfill.js' -import '../src/unresolved.js' +import '../src/post-polyfill.js'; +import '../src/unresolved.js'; \ No newline at end of file diff --git a/entrypoints/webcomponents-hi-sd-ce-index.js b/entrypoints/webcomponents-hi-sd-ce-index.js index 31b9217..3dbc4da 100644 --- a/entrypoints/webcomponents-hi-sd-ce-index.js +++ b/entrypoints/webcomponents-hi-sd-ce-index.js @@ -14,9 +14,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN * Used in: Safari 9, Firefox, Edge */ -import '../bower_components/html-imports/src/html-imports.js' -import '../bower_components/shadydom/src/shadydom.js' -import '../bower_components/custom-elements/src/custom-elements.js' -import '../bower_components/shadycss/entrypoints/scoping-shim.js' -import '../src/post-polyfill.js' -import '../src/unresolved.js' +import '../node_modules/@webcomponents/html-imports/src/html-imports.js'; +import '../node_modules/@webcomponents/shadydom/src/shadydom.js'; +import '../node_modules/@webcomponents/custom-elements/src/custom-elements.js'; +import '../node_modules/@webcomponents/shadycss/entrypoints/scoping-shim.js'; +import '../src/post-polyfill.js'; +import '../src/unresolved.js'; diff --git a/entrypoints/webcomponents-hi-sd-ce-pf-index.js b/entrypoints/webcomponents-hi-sd-ce-pf-index.js index 0fdcd9f..dcaba5c 100644 --- a/entrypoints/webcomponents-hi-sd-ce-pf-index.js +++ b/entrypoints/webcomponents-hi-sd-ce-pf-index.js @@ -14,13 +14,13 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN * Used in: IE 11 */ -import '../bower_components/webcomponents-platform/webcomponents-platform.js' -import '../bower_components/template/template.js' -import '../bower_components/es6-promise/dist/es6-promise.auto.min.js' -import '../bower_components/html-imports/src/html-imports.js' -import '../src/pre-polyfill.js' -import '../bower_components/shadydom/src/shadydom.js' -import '../bower_components/custom-elements/src/custom-elements.js' -import '../bower_components/shadycss/entrypoints/scoping-shim.js' -import '../src/post-polyfill.js' -import '../src/unresolved.js' +import '../node_modules/@webcomponents/webcomponents-platform/webcomponents-platform.js'; +import '../node_modules/@webcomponents/template/template.js'; +import '../node_modules/es6-promise/lib/es6-promise.auto.js'; +import '../node_modules/@webcomponents/html-imports/src/html-imports.js'; +import '../src/pre-polyfill.js'; +import '../node_modules/@webcomponents/shadydom/src/shadydom.js'; +import '../node_modules/@webcomponents/custom-elements/src/custom-elements.js'; +import '../node_modules/@webcomponents/shadycss/entrypoints/scoping-shim.js'; +import '../src/post-polyfill.js'; +import '../src/unresolved.js'; \ No newline at end of file diff --git a/entrypoints/webcomponents-sd-ce-index.js b/entrypoints/webcomponents-sd-ce-index.js index 9be5e40..1ff8e2c 100644 --- a/entrypoints/webcomponents-sd-ce-index.js +++ b/entrypoints/webcomponents-sd-ce-index.js @@ -14,32 +14,29 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN * Used in: Safari 9, Firefox, Edge */ -import '../bower_components/shadydom/src/shadydom.js' -import '../bower_components/custom-elements/src/custom-elements.js' -import '../bower_components/shadycss/entrypoints/scoping-shim.js' +import '../node_modules/@webcomponents/shadydom/src/shadydom.js'; +import '../node_modules/@webcomponents/custom-elements/src/custom-elements.js'; +import '../node_modules/@webcomponents/shadycss/entrypoints/scoping-shim.js'; -// NOTE: this is a load-bearing IIFE for Closure -(function() { - let document = window.document; - // global for (1) existence means `WebComponentsReady` will file, - // (2) WebComponents.ready == true means event has fired. - window.WebComponents = window.WebComponents || {}; +let document = window.document; +// global for (1) existence means `WebComponentsReady` will file, +// (2) WebComponents.ready == true means event has fired. +window.WebComponents = window.WebComponents || {}; - function fire() { - requestAnimationFrame(() => { - window.WebComponents.ready = true; - window.document.dispatchEvent(new CustomEvent('WebComponentsReady', { bubbles: true })); - }) - } +function fire() { + requestAnimationFrame(() => { + window.WebComponents.ready = true; + window.document.dispatchEvent(new CustomEvent('WebComponentsReady', { bubbles: true })); + }) +} - function wait() { - fire(); - document.removeEventListener('readystatechange', wait); - } +function wait() { + fire(); + document.removeEventListener('readystatechange', wait); +} - if (document.readyState !== 'loading') { - fire(); - } else { - document.addEventListener('readystatechange', wait); - } -})(); \ No newline at end of file +if (document.readyState !== 'loading') { + fire(); +} else { + document.addEventListener('readystatechange', wait); +} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index f5acfa4..7ce21b2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -20,7 +20,6 @@ const rename = require('gulp-rename'); const rollup = require('rollup-stream'); const source = require('vinyl-source-stream'); const del = require('del'); -const bower = require('bower'); const runseq = require('run-sequence'); const closure = require('google-closure-compiler').gulp(); const babel = require('rollup-plugin-babel'); @@ -60,10 +59,10 @@ function closurify(sourceName, fileName) { rewrite_polyfills: false, externs: [ 'externs/webcomponents.js', - 'bower_components/custom-elements/externs/custom-elements.js', - 'bower_components/html-imports/externs/html-imports.js', - 'bower_components/shadycss/externs/shadycss-externs.js', - 'bower_components/shadydom/externs/shadydom.js' + 'node_modules/@webcomponents/custom-elements/externs/custom-elements.js', + 'node_modules/@webcomponents/html-imports/externs/html-imports.js', + 'node_modules/@webcomponents/shadycss/externs/shadycss-externs.js', + 'node_modules/@webcomponents/shadydom/externs/shadydom.js' ] }; @@ -138,7 +137,7 @@ function singleLicenseComment() { } const babelOptions = { - presets: 'babili', + presets: 'minify', shouldPrintComment: singleLicenseComment() }; @@ -146,17 +145,7 @@ gulp.task('debugify-ce-es5-adapter', () => { return debugify('custom-elements-es5-adapter', '', {plugins: [babel(babelOptions)]}); }); -gulp.task('refresh-bower', () => { - return del('bower_components').then(() => { - return new Promise((resolve, reject) => { - bower.commands.install().on('end', () => resolve()).on('error', (e) => reject(e)); - }); - }); -}); - -gulp.task('default', (cb) => { - runseq('refresh-bower', 'closure', cb); -}); +gulp.task('default', ['closure']); gulp.task('clean-builds', () => { return del(['custom-elements-es5-adapter.js{,.map}', 'webcomponents*.js{,.map}', '!webcomponents-loader.js']); diff --git a/package.json b/package.json index 861e931..0f4458c 100644 --- a/package.json +++ b/package.json @@ -33,12 +33,11 @@ "@webcomponents/shadydom": "^1.0.0", "@webcomponents/template": "^1.0.0", "@webcomponents/webcomponents-platform": "^1.0.0", - "babel-preset-babili": "^0.1.4", - "bower": "^1.8.0", + "babel-preset-minify": "^0.2.0", "del": "^3.0.0", "es6-promise": "^4.1.1", - "eslint": "^3.16.1", - "google-closure-compiler": "^20170626.0.0", + "eslint": "^4.4.1", + "google-closure-compiler": "^20170806.0.0", "gulp": "^3.8.8", "gulp-rename": "^1.2.2", "gulp-sourcemaps": "^2.4.1", diff --git a/src/post-polyfill.js b/src/post-polyfill.js index 83c0431..eb6ce11 100644 --- a/src/post-polyfill.js +++ b/src/post-polyfill.js @@ -8,54 +8,50 @@ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt */ -(function() { +'use strict'; - 'use strict'; +let customElements = window['customElements']; +let HTMLImports = window['HTMLImports']; +// global for (1) existence means `WebComponentsReady` will file, +// (2) WebComponents.ready == true means event has fired. +window.WebComponents = window.WebComponents || {}; - var customElements = window['customElements']; - var HTMLImports = window['HTMLImports']; - // global for (1) existence means `WebComponentsReady` will file, - // (2) WebComponents.ready == true means event has fired. - window.WebComponents = window.WebComponents || {}; - - if (customElements && customElements['polyfillWrapFlushCallback']) { - // Here we ensure that the public `HTMLImports.whenReady` - // always comes *after* custom elements have upgraded. - var flushCallback; - var runAndClearCallback = function runAndClearCallback() { - if (flushCallback) { - var cb = flushCallback; - flushCallback = null; - cb(); - return true; - } +if (customElements && customElements['polyfillWrapFlushCallback']) { + // Here we ensure that the public `HTMLImports.whenReady` + // always comes *after* custom elements have upgraded. + let flushCallback; + let runAndClearCallback = function runAndClearCallback() { + if (flushCallback) { + let cb = flushCallback; + flushCallback = null; + cb(); + return true; } - var origWhenReady = HTMLImports['whenReady']; - customElements['polyfillWrapFlushCallback'](function(cb) { - flushCallback = cb; - origWhenReady(runAndClearCallback); - }); - - HTMLImports['whenReady'] = function(cb) { - origWhenReady(function() { - // custom element code may add dynamic imports - // to match processing of native custom elements before - // domContentLoaded, we wait for these imports to resolve first. - if (runAndClearCallback()) { - HTMLImports['whenReady'](cb); - } else { - cb(); - } - }); - } - } - - HTMLImports['whenReady'](function() { - requestAnimationFrame(function() { - window.WebComponents.ready = true; - document.dispatchEvent(new CustomEvent('WebComponentsReady', {bubbles: true})); - }); + let origWhenReady = HTMLImports['whenReady']; + customElements['polyfillWrapFlushCallback'](function(cb) { + flushCallback = cb; + origWhenReady(runAndClearCallback); }); -})(); \ No newline at end of file + HTMLImports['whenReady'] = function(cb) { + origWhenReady(function() { + // custom element code may add dynamic imports + // to match processing of native custom elements before + // domContentLoaded, we wait for these imports to resolve first. + if (runAndClearCallback()) { + HTMLImports['whenReady'](cb); + } else { + cb(); + } + }); + } + +} + +HTMLImports['whenReady'](function() { + requestAnimationFrame(function() { + window.WebComponents.ready = true; + document.dispatchEvent(new CustomEvent('WebComponentsReady', {bubbles: true})); + }); +}); \ No newline at end of file diff --git a/src/pre-polyfill.js b/src/pre-polyfill.js index 71f2ef7..336a86e 100644 --- a/src/pre-polyfill.js +++ b/src/pre-polyfill.js @@ -8,60 +8,56 @@ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt */ -(function() { +'use strict'; - 'use strict'; +// Establish scope. +window['WebComponents'] = window['WebComponents'] || {'flags':{}}; - // Establish scope. - window['WebComponents'] = window['WebComponents'] || {'flags':{}}; +// loading script +let file = 'webcomponents-lite.js'; +let script = document.querySelector('script[src*="' + file + '"]'); +let flagMatcher = /wc-(.+)/; - // loading script - var file = 'webcomponents-lite.js'; - var script = document.querySelector('script[src*="' + file + '"]'); - var flagMatcher = /wc-(.+)/; - - // Flags. Convert url arguments to flags - var flags = {}; - if (!flags['noOpts']) { - // from url - location.search.slice(1).split('&').forEach(function(option) { - var parts = option.split('='); - var match; - if (parts[0] && (match = parts[0].match(flagMatcher))) { - flags[match[1]] = parts[1] || true; +// Flags. Convert url arguments to flags +let flags = {}; +if (!flags['noOpts']) { + // from url + location.search.slice(1).split('&').forEach(function(option) { + let parts = option.split('='); + let match; + if (parts[0] && (match = parts[0].match(flagMatcher))) { + flags[match[1]] = parts[1] || true; + } + }); + // from script + if (script) { + for (let i=0, a; (a=script.attributes[i]); i++) { + if (a.name !== 'src') { + flags[a.name] = a.value || true; } + } + } + // log flags + if (flags['log'] && flags['log']['split']) { + let parts = flags['log'].split(','); + flags['log'] = {}; + parts.forEach(function(f) { + flags['log'][f] = true; }); - // from script - if (script) { - for (var i=0, a; (a=script.attributes[i]); i++) { - if (a.name !== 'src') { - flags[a.name] = a.value || true; - } - } - } - // log flags - if (flags['log'] && flags['log']['split']) { - var parts = flags['log'].split(','); - flags['log'] = {}; - parts.forEach(function(f) { - flags['log'][f] = true; - }); - } else { - flags['log'] = {}; - } + } else { + flags['log'] = {}; } +} - // exports - window['WebComponents']['flags'] = flags; - var forceShady = flags['shadydom']; - if (forceShady) { - window['ShadyDOM'] = window['ShadyDOM'] || {}; - window['ShadyDOM']['force'] = forceShady; - } +// exports +window['WebComponents']['flags'] = flags; +let forceShady = flags['shadydom']; +if (forceShady) { + window['ShadyDOM'] = window['ShadyDOM'] || {}; + window['ShadyDOM']['force'] = forceShady; +} - var forceCE = flags['register'] || flags['ce']; - if (forceCE && window['customElements']) { - window['customElements']['forcePolyfill'] = forceCE; - } - -})(); +let forceCE = flags['register'] || flags['ce']; +if (forceCE && window['customElements']) { + window['customElements']['forcePolyfill'] = forceCE; +} \ No newline at end of file diff --git a/src/unresolved.js b/src/unresolved.js index 1c7721e..f6f2bb2 100644 --- a/src/unresolved.js +++ b/src/unresolved.js @@ -8,27 +8,24 @@ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt */ -(function() { - 'use strict'; - // It's desireable to provide a default stylesheet - // that's convenient for styling unresolved elements, but - // it's cumbersome to have to include this manually in every page. - // It would make sense to put inside some HTMLImport but - // the HTMLImports polyfill does not allow loading of stylesheets - // that block rendering. Therefore this injection is tolerated here. - // - // NOTE: position: relative fixes IE's failure to inherit opacity - // when a child is not statically positioned. - var style = document.createElement('style'); - style.textContent = '' - + 'body {' - + 'transition: opacity ease-in 0.2s;' - + ' } \n' - + 'body[unresolved] {' - + 'opacity: 0; display: block; overflow: hidden; position: relative;' - + ' } \n' - ; - var head = document.querySelector('head'); - head.insertBefore(style, head.firstChild); - -})(); +'use strict'; +// It's desireable to provide a default stylesheet +// that's convenient for styling unresolved elements, but +// it's cumbersome to have to include this manually in every page. +// It would make sense to put inside some HTMLImport but +// the HTMLImports polyfill does not allow loading of stylesheets +// that block rendering. Therefore this injection is tolerated here. +// +// NOTE: position: relative fixes IE's failure to inherit opacity +// when a child is not statically positioned. +let style = document.createElement('style'); +style.textContent = '' + + 'body {' + + 'transition: opacity ease-in 0.2s;' + + ' } \n' + + 'body[unresolved] {' + + 'opacity: 0; display: block; overflow: hidden; position: relative;' + + ' } \n' + ; +let head = document.querySelector('head'); +head.insertBefore(style, head.firstChild); \ No newline at end of file diff --git a/tests/template-and-CE.html b/tests/template-and-CE.html index 45f9588..6c14982 100644 --- a/tests/template-and-CE.html +++ b/tests/template-and-CE.html @@ -11,8 +11,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN