├── .gitignore
├── LICENCE
├── README.md
├── bower_components
└── webcomponentsjs
│ ├── .bower.json
│ ├── .eslintrc.json
│ ├── .gitattributes
│ ├── .github
│ └── CODEOWNERS
│ ├── .gitignore
│ ├── .travis.yml
│ ├── CONTRIBUTING.md
│ ├── LICENSE.md
│ ├── README.md
│ ├── bower.json
│ ├── closure-output.txt
│ ├── custom-elements-es5-adapter.js
│ ├── entrypoints
│ ├── custom-elements-es5-adapter-index.js
│ ├── webcomponents-hi-ce-index.js
│ ├── webcomponents-hi-index.js
│ ├── webcomponents-hi-sd-ce-index.js
│ ├── webcomponents-hi-sd-ce-pf-index.js
│ ├── webcomponents-hi-sd-index.js
│ └── webcomponents-sd-ce-index.js
│ ├── externs
│ └── webcomponents.js
│ ├── gulpfile.js
│ ├── package-lock.json
│ ├── package.json
│ ├── src
│ ├── post-polyfill.js
│ ├── pre-polyfill.js
│ ├── promise.js
│ └── unresolved.js
│ ├── tests
│ ├── ce-import-upgrade-async.html
│ ├── ce-import-upgrade.html
│ ├── ce-import.html
│ ├── ce-upgrade-order.html
│ ├── ce-upgradedocumenttree.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-es5.html
│ │ └── simple-element.html
│ ├── integration-es5.html
│ ├── integration.html
│ ├── load.html
│ ├── promise.html
│ ├── runner.html
│ ├── smoke.html
│ ├── template-and-CE.html
│ └── template-and-imports.html
│ ├── wct.conf.json
│ ├── webcomponents-hi-ce.js
│ ├── webcomponents-hi-ce.js.map
│ ├── webcomponents-hi-sd-ce.js
│ ├── webcomponents-hi-sd-ce.js.map
│ ├── webcomponents-hi-sd.js
│ ├── webcomponents-hi-sd.js.map
│ ├── webcomponents-hi.js
│ ├── webcomponents-hi.js.map
│ ├── webcomponents-lite.js
│ ├── webcomponents-lite.js.map
│ ├── webcomponents-loader.js
│ ├── webcomponents-sd-ce.js
│ └── webcomponents-sd-ce.js.map
├── dist
├── img-2.es5.js
└── img-2.js
├── index.html
├── package-lock.json
├── package.json
└── src
└── img-2.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | node_modules
--------------------------------------------------------------------------------
/LICENCE:
--------------------------------------------------------------------------------
1 | Copyright 2018 Leon Revill
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Img2
2 | Replace `` elements with `` to automatically pre-cache images and improve page performance. Displaying even a small number of high-quality images on a web page can be difficult to do without causing jank or slowing down the initial load of the page. This is why clever developers employ techniques with JavaScript to pre-cache images and lazy load them as they become visible on the user's screen.
3 |
4 | Img2 makes this super easy, just swap out your `` elements with `` and let it do the work for you.
5 |
6 | ## Img2 will automatically:
7 |
8 | 1. Only render initial images which are visible to the user
9 | 2. Pre-cache all other images off the main thread with a Web Worker
10 | 3. Lazy load images as they enter the user's viewport instantly from the cache
11 | 4. Display a blurred preview image while the user waits for initial images
12 |
13 | ___
14 |
15 | [Live Demo](https://revillweb.github.io/img-2/)
16 |
17 | ___
18 |
19 | ## Install
20 |
21 | `npm install --save img-2`
22 |
23 | ## Usage
24 |
25 | You can include Img2 into your project in various ways:
26 |
27 | ### As a ES6 Module
28 |
29 | `import "img-2"`
30 |
31 | ### Via `
35 | ```
36 |
37 | ### Via `
41 | ```
42 |
43 | Then you simply use the `` element in place of an `` element.
44 |
45 | ```html
46 |
47 |
Cat Photos
48 |
49 |
50 | ```
51 |
52 | ### Attributes
53 |
54 | There are currently five attributes available on Img2, three of which are required.
55 |
56 | #### src
57 |
58 | The full-size source image to be pre-cached and lazy loaded.
59 |
60 | #### width & height
61 |
62 | Both of these are required to figure out the position of the image on screen to then determine if the image should be loaded right away or lazily loaded.
63 |
64 | #### src-preview
65 |
66 | A really small representation of the full-size image (e.g. 10px by 10px). This image will be displayed as a blurred preview while the full-size image is downloading if the image hasn't already been pre-cached.
67 |
68 | #### alt
69 |
70 | The alt text for the image, just maps on to the `alt` attribute of the `` element used in the component.
71 |
72 | ## Supported platforms &
73 |
74 | | Platform Support | Chrome | Chrome for Android | Firefox | Safari | iOS Safari | Edge | IE 11 |
75 | | ------------------ |:------:|:------:|:------:|:------:|:------:|:----:|:-----:|
76 | | Supported |✓|✓|✓|✓|✓|✓|✓|✓|
77 | | Polyfill(s) Required |-|-|✓|✓|✓|✓|✓|✓|
78 |
79 | Img-2 uses the [Intersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) to detect when an image is in the users visible viewport. For Safari and IE 11 you'll need to load the Intersection Observer polyfill.
80 |
81 | ```html
82 |
83 | ```
84 |
85 | Img-2 uses Custom Elements and Shadow DOM so for FireFox, Edge and IE11 you'll need to use the webcomponents-loader from [webcomponentsjs](https://github.com/webcomponents/webcomponentsjs).
86 |
87 | ```html
88 |
89 | ```
90 |
91 | If you need to support IE11 which doesn't support ES6 you'll want to conditionally load `img-2.es5.js`.
92 |
93 | ```js
94 | var supportsES6 = function() {
95 | try {
96 | new Function("(a = 0) => a");
97 | return true;
98 | }
99 | catch (err) {
100 | return false;
101 | }
102 | }();
103 |
104 | var $script = document.createElement("script");
105 | $script.setAttribute("defer", "");
106 | $script.src = (supportsES6 === true) ? "dist/img-2.js" : "dist/img-2.es5.js";
107 | document.head.appendChild($script);
108 | ```
109 |
110 | Take a look at `index.html` in the root of this repo for further examples.
111 |
112 | ### Contributing
113 |
114 | Any contributions are welcome, feel free to submit a pull request for review.
115 |
116 | ### To Do
117 |
118 | 1. Add srcset support
119 | 2. Consider A11y
120 |
--------------------------------------------------------------------------------
/bower_components/webcomponentsjs/.bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "webcomponentsjs",
3 | "description": "Web components polyfill",
4 | "main": "webcomponents.js",
5 | "homepage": "http://webcomponents.org",
6 | "authors": [
7 | "The Polymer Authors"
8 | ],
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/webcomponents/webcomponentsjs.git"
12 | },
13 | "keywords": [
14 | "webcomponents",
15 | "web-components",
16 | "polyfill",
17 | "shim"
18 | ],
19 | "license": "BSD-3-Clause",
20 | "ignore": [],
21 | "devDependencies": {
22 | "web-component-tester": "^v6.0.0"
23 | },
24 | "version": "1.1.1",
25 | "_release": "1.1.1",
26 | "_resolution": {
27 | "type": "version",
28 | "tag": "v1.1.1",
29 | "commit": "2bb2c2c92008d2354b75c0fa633ea404c5c999c3"
30 | },
31 | "_source": "https://github.com/Polymer/webcomponentsjs.git",
32 | "_target": "^1.1.1",
33 | "_originalSource": "webcomponentsjs",
34 | "_direct": true
35 | }
--------------------------------------------------------------------------------
/bower_components/webcomponentsjs/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "eslint:recommended",
3 | "env": {
4 | "browser": true,
5 | "es6": true
6 | },
7 | "parserOptions": {
8 | "ecmaVersion": 6,
9 | "sourceType": "module"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/bower_components/webcomponentsjs/.gitattributes:
--------------------------------------------------------------------------------
1 | /webcomponents*.js binary
2 | /webcomponents*.js.map binary
3 | /webcomponents-loader.js -binary
4 | /package-lock.json binary
5 |
--------------------------------------------------------------------------------
/bower_components/webcomponentsjs/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @azakus
2 |
--------------------------------------------------------------------------------
/bower_components/webcomponentsjs/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | bower_components
3 | dist
4 |
--------------------------------------------------------------------------------
/bower_components/webcomponentsjs/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | sudo: required
3 | dist: trusty
4 | node_js: stable
5 | addons:
6 | firefox: latest
7 | apt:
8 | sources:
9 | - google-chrome
10 | packages:
11 | - google-chrome-stable
12 | before_script:
13 | - export DISPLAY=:99.0
14 | - sh -e /etc/init.d/xvfb start
15 | - sleep 3
16 | script:
17 | - npm install -g bower
18 | - bower install
19 | - wct -l chrome
20 | - wct -l firefox
21 | - 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' -s 'Linux/chrome@41'; fi
22 | env:
23 | global:
24 | - secure: Fpp9LwJSGOdTrSIImQTlbzxozBsqe/2AJN5OfTXSe12FZxqzz50gevdxQcIlLypKaNyCtjb980DJbwdJR2cXUqaunLZAPWxrKa7ZPwamUxW+zVL7EHqy5zuvD+yJ+Vmk3ahs3WBTVyJ8T3XoaSfo9VumDIcKggWGJwgvM3blIMg=
25 | - secure: Bj8MgzUVP0X8MLgK3d9eF48V7x0rPJyrN1IyguzKyJJVC8LV2XZXF+6o/M+zNsVMSsjhgXMkS3RRuaUShxO/OS6gHeG31FWcZqbXfZfgMMyH8a8zDls+r8m2lGEICaZo1OTXR0uiR/VNVt7n2xoBnTmjmRFwkaxAZk4yCjbXYzQ=
26 |
--------------------------------------------------------------------------------
/bower_components/webcomponentsjs/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 | ## Contributor License Agreement
8 |
9 | Before we can accept patches, there's a quick web form you need to fill out.
10 |
11 | - If you're contributing as an individual (e.g. you own the intellectual property), fill out [this form](http://code.google.com/legal/individual-cla-v1.0.html).
12 | - If you're contributing under a company, fill out [this form](http://code.google.com/legal/corporate-cla-v1.0.html) instead.
13 |
14 | This CLA asserts that contributions are owned by you and that we can license all work under our [license](LICENSE).
15 |
16 | Other projects require a similar agreement: jQuery, Firefox, Apache, Node, and many more.
17 |
18 | [More about CLAs](https://www.google.com/search?q=Contributor%20License%20Agreement)
19 |
20 | ## Initial setup
21 |
22 | 1. Setup Gulp: `sudo npm install -g gulp`
23 | 1. Fork the project on github and pull down your copy.
24 | > replace the {{ username }} with your username and {{ repository }} with the repository name
25 |
26 | git clone git@github.com:{{ username }}/{{ repository }}.git
27 |
28 | 1. Test your change results in a working build.
29 | > in the repo you've made changes to, try generating a build:
30 |
31 | cd $REPO
32 | npm install
33 | gulp
34 |
35 | The builds will be placed into the `dist/` directory if all goes well.
36 |
37 | 1. Commit your code and make a pull request.
38 |
39 | That's it for the one time setup. Now you're ready to make a change.
40 |
41 | ## Submitting a pull request
42 |
43 | We iterate fast! To avoid potential merge conflicts, it's a good idea to pull from the main project before making a change and submitting a pull request. The easiest way to do this is setup a remote called `upstream` and do a pull before working on a change:
44 |
45 | git remote add upstream git://github.com/polymer/webcomponentsjs.git
46 |
47 | Then before making a change, do a pull from the upstream `master` branch:
48 |
49 | git pull upstream master
50 |
51 | To make life easier, add a "pull upstream" alias in your `.gitconfig`:
52 |
53 | [alias]
54 | pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
55 |
56 | That will pull in changes from your forked repo, the main (upstream) repo, and merge the two. Then it's just a matter of running `git pu` before a change and pushing to your repo:
57 |
58 | git checkout master
59 | git pu
60 | # make change
61 | git commit -a -m 'Awesome things.'
62 | git push
63 |
64 | Lastly, don't forget to submit the pull request.
--------------------------------------------------------------------------------
/bower_components/webcomponentsjs/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.
--------------------------------------------------------------------------------
/bower_components/webcomponentsjs/README.md:
--------------------------------------------------------------------------------
1 | webcomponents.js (v1 spec polyfills)
2 | ================
3 |
4 | [](https://travis-ci.org/webcomponents/webcomponentsjs)
5 |
6 | > **Note**. For polyfills that work with the older Custom Elements and Shadow DOM v0 specs, see the [v0 branch](https://github.com/webcomponents/webcomponentsjs/tree/v0).
7 |
8 | A suite of polyfills supporting the [Web Components](http://webcomponents.org) specs:
9 |
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)).
13 |
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))
18 |
19 | ## How to use
20 |
21 | The polyfills are built (concatenated & minified) into several bundles that target
22 | different browsers and spec readiness:
23 |
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)
29 |
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.
32 |
33 | ## `webcomponents-loader.js`
34 | Alternatively, this repo also comes with `webcomponents-loader.js`, a client-side
35 | loader that dynamically loads the minimum polyfill bundle, using feature detection.
36 | 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
37 | loaded and are ready to be used (i.e. if you want to dynamically load other custom
38 | elements, etc.).
39 |
40 | Additionally, you can check if `window.WebComponents` exists to know if the `WebComponentsReady` event will fire, and you can check if `window.WebComponents.ready` is true to check if the `WebComponentsReady` event has already fired.
41 |
42 | Here's an example:
43 |
44 | ```html
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
65 | ```
66 |
67 | ## `custom-elements-es5-adapter.js`
68 | According to the spec, Custom Elements must be ES6 classes (https://html.spec.whatwg.org/multipage/scripting.html#custom-element-conformance). Since most projects need to support a wide range of browsers that don't necessary support ES6, it may make sense to compile your project to ES5. However, ES5-style custom element classes will **not** work with native Custom Elements because ES5-style classes cannot properly extend ES6 classes, like `HTMLElement`.
69 |
70 | To work around this, load `custom-elements-es5-adapter.js` before declaring new Custom Elements.
71 |
72 | **The adapter must NOT be compiled.**
73 |
74 | ```html
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | ```
85 |
86 | ## Browser Support
87 |
88 | The polyfills are intended to work in the latest versions of evergreen browsers. See below
89 | for our complete browser support matrix:
90 |
91 | | Polyfill | IE11+ | Chrome* | Firefox* | Safari 9+* | Chrome Android* | Mobile Safari* |
92 | | ---------- |:-----:|:-------:|:--------:|:----------:|:---------------:|:--------------:|
93 | | Custom Elements | ✓ | ✓ | ✓ | ✓ | ✓| ✓ |
94 | | HTML Imports | ✓ | ✓ | ✓ | ✓| ✓| ✓ |
95 | | Shady CSS/DOM | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
96 |
97 | \*Indicates the current version of the browser
98 |
99 | The polyfills may work in older browsers, however require additional polyfills (such as classList, or other [platform](https://github.com/webcomponents/webcomponents-platform)
100 | polyfills) to be used. We cannot guarantee support for browsers outside of our compatibility matrix.
101 |
102 |
103 | ### Manually Building
104 |
105 | If you wish to build the bundles yourself, you'll need `node` and `npm` on your system:
106 |
107 | * install [node.js](http://nodejs.org/) using the instructions on their website
108 | * use `npm` to install [gulp.js](http://gulpjs.com/): `npm install -g gulp`
109 |
110 | Now you are ready to build the polyfills with:
111 |
112 | # install dependencies
113 | npm install
114 | bower install
115 | # build
116 | gulp
117 |
118 | The builds will be placed into the root directory.
119 |
120 | ## Contribute
121 |
122 | See the [contributing guide](CONTRIBUTING.md)
123 |
124 | ## License
125 |
126 | Everything in this repository is BSD style license unless otherwise specified.
127 |
128 | Copyright (c) 2015 The Polymer Authors. All rights reserved.
129 |
130 | ## Helper utilities
131 |
132 | ### `WebComponentsReady`
133 |
134 | Under native HTML Imports, `
16 |
17 |
18 |
19 |
45 |
46 |