11# element-lite
2- [ ![ Build Status] ( https://travis-ci.org/tjmonsi/element-lite.svg?branch=master )] ( https://travis-ci.org/tjmonsi/element-lite )
2+ Master: [ ![ Build Status] ( https://travis-ci.org/tjmonsi/element-lite.svg?branch=master )] ( https://travis-ci.org/tjmonsi/element-lite )
3+ Develop: [ ![ Build Status] ( https://travis-ci.org/tjmonsi/element-lite.svg?branch=develop )] ( https://travis-ci.org/tjmonsi/element-lite )
34
45A take on using lit-html and using methods coming from Polymer.
56
67This is based on https://github.com/PolymerLabs/lit-element and added my own take on creating my own
7- simple library.
8+ simple library. You can freely use it on your own projects.
89
9- This is a work in progress but I will use it on my own projects. You can freely use it on your own projects .
10+ Most of the methods and its internals came from Polymer's properties-mixin, properties-changed, property-accessors mixin, and property-effects mixin ( You can see each file on where parts are copied/modified from) .
1011
11- Most of the methods and its internals came from Polymer's properties-mixin, properties-changed, property-accessors mixin, and property-effects mixin.
12+ The reason for copying rather than depending on files is the added overhead of extending classes and
13+ the number of method overrides, making some inherited methods not used in the final part of
14+ upgrading the element. This is to squeeze out unused parts from the mixins.
1215
1316
1417## How to install:
1518
16- ### using npm
19+ ### Using npm
1720
1821This is the recommended way. To install, just do this:
1922```
2023npm i --save @littleq/element-lite
2124```
2225
2326
24-
25-
2627## Out of the box, what can I do?
2728
29+ ### On evergreen browsers that support ES6 and import (Latest Firefox and Chrome)
30+
2831You can add this to your JS
2932
3033``` js
@@ -43,21 +46,71 @@ customElement.define('web-component', Component);
4346and add this to your HTML
4447
4548``` html
46- <script src =" main.js" type =" module" >
49+ <script src =" main.js" type =" module" ></ script >
4750```
4851
49- You can also add these additional scripts for polyfill
52+ ### Usage on bundlers like Webpack
53+
54+ Same as above.
55+
56+ ### For non-Chrome evergreen browsers (Latest Firefox, Safari, and Edge)
57+
58+ You need to add this additional script for polyfill
5059
5160``` html
5261<script src =" node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js" >
5362` ` `
5463
55- And if you are using Webpack and you have bundled it in ES5 for older browsers, you also need:
64+ And then wrap around the files after the ` WebComponentsReady` event has been fired
65+
66+ ` ` ` html
67+ < script>
68+ window .addEventListener (' WebComponentsReady' , function () {
69+ var component = document .createElement (' script' );
70+ component .src = ' main.js' ;
71+ component .type = ' module' ;
72+ document .head .appendChild (component);
73+ });
74+ </script >
75+ ```
76+
77+ ### If you compiled and bundled the elements to ES5
78+
79+ if you are using Webpack and you have bundled it in ES5 for older browsers, you also need:
5680
5781``` html
5882<script src =" node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js" >
5983` ` `
6084
85+ ### If you don't need a bundler but is capable for use in older browsers
86+
87+ ` ` ` html
88+ < script src= " /node_modules/@littleq/element-lite/dist/element-lite.umd.es5.min.js" >
89+ < script>
90+ window .addEventListener (' WebComponentsReady' , function () {
91+ var component = document .createElement (' script' );
92+ component .src = ' main.js' ;
93+ document .head .appendChild (component);
94+ });
95+ </script >
96+ ```
97+
98+ ``` js
99+ // main.js
100+ // wrap in anonymous function
101+ // Bundle this in ES5 either using Rollup or Webpack
102+ (function (){
103+ // get ElementLite from window.ElementLite;
104+ var ElementLite = window .ElementLite .ElementLite ;
105+ class Component extends ElementLite (HTMLElement ) {
106+ render () {
107+ return html ` Whatever you want to put in the ShadowDom` ;
108+ }
109+ }
110+ })();
111+ ```
112+
113+
61114## What else can it do?
62115
63116You can put a default value on a property.
@@ -206,6 +259,7 @@ el.splice('prop1', 1, 0, '1', '2') // el.prop1 = ['a', '1', '2', 'b', 'c']
206259el .splice (' prop1' , 1 , 1 ) // el.prop1 = ['a', '2', 'b', 'c']
207260```
208261
262+
209263## Example usage
210264
211265index.html
@@ -225,6 +279,7 @@ index.html
225279
226280test-element.js
227281``` js
282+ // you can get lit-html's `html` from the bundle as well
228283import { ElementLite , html } from ' ./node_modules/@littleq/element-lite/element-lite.js' ;
229284const { customElements } = window ;
230285
@@ -319,6 +374,127 @@ class Component extends ElementLiteStaticShadow(HTMLElement) {
319374customElement .define (' web-component-static' , Component);
320375```
321376
377+ ## Element-lite-lit-only
378+
379+ If you don't need the power of element-lite-base but need to the power of lit-html,
380+ use ` element-lite-lit-only `
381+
382+ ``` js
383+ // main-static.js
384+ import { ElementLiteLitOnly } from ' node_modules/@littleq/element-lite/element-lite-lit-only.js'
385+
386+ class Component extends ElementLiteLitOnly (HTMLElement ) {
387+ render () {
388+ return ` Hello World!`
389+ }
390+ }
391+
392+ customElement .define (' web-component-static' , Component);
393+ ```
394+
395+
396+ ## What files to import and how?
397+
398+ If you are going to use it on Evergreen Browsers that allows ` <script type="module"> ` ,
399+ then you can just do this on your ` js ` files
400+
401+ ``` js
402+ import { ElementLite } from ' ./node_modules/@littleq/element-lite/element-lite.js' ;
403+ ```
404+
405+ If you are going to use it on Webpack or Rollup, you can do any of these
406+
407+ ``` js
408+ // provided that node_modules is resolved in your configurations
409+ import { ElementLite } from ' element-lite/@littleq/element-lite.js' ;
410+ ```
411+
412+ or
413+
414+ ``` js
415+ import { ElementLite } from ' ./node_modules/@littleq/element-lite' ;
416+ ```
417+
418+ or
419+
420+ ``` js
421+ import { ElementLite } from ' ./node_modules/@littleq/element-lite/dist/element-lite.esm.js' ;
422+ ```
423+
424+ If you are going to use ` require ` and not ` import ` you can do any of these
425+
426+ ``` js
427+ // provided that node_modules is resolved in your configurations
428+ var ElementLite = require (' @littleq/element-lite' ).ElementLite ;
429+ ```
430+
431+ or
432+
433+ ``` js
434+ // provided that node_modules is resolved in your configurations
435+ var ElementLite = require (' @littleq/element-lite/dist/element-lite.cjs.js' ).ElementLite ;
436+ ```
437+
438+ If you are going to load it via the ` <script> ` tag, you need to do these
439+
440+ For ES6
441+
442+ ``` html
443+ <script src =" /node_modules/@littleq/element-lite/dist/element-lite.umd.es6.js" >
444+ <!-- < script src= " /node_modules/@littleq/element-lite/dist/element-lite.umd.es6.min.js" >
445+ if you need the minified file -->
446+ ` ` `
447+
448+ For ES5
449+
450+ ` ` ` html
451+ < script src= " /node_modules/@littleq/element-lite/dist/element-lite.umd.es5.js" >
452+ <!-- < script src= " /node_modules/@littleq/element-lite/dist/element-lite.umd.es5.min.js" >
453+ if you need the minified file -->
454+ ` ` `
455+
456+ and then can access it here
457+
458+ ` ` ` js
459+ var ElementLite = window .ElementLite .ElementLite
460+ ` ` `
461+
462+ You can also load ElementLiteBase, ElementLiteStaticShadow and ElementLiteLitOnly from ElementLite as well
463+
464+ ` ` ` js
465+ // right from the box
466+ import { ElementLiteBase , ElementLiteStaticShadow , ElementLiteLitOnly } from ' ./node_modules/element-lite/element-lite.js' ;
467+ ` ` `
468+
469+ using ` require`
470+
471+ ` ` ` js
472+ // provided that node_modules is resolved in your configurations
473+ var ElementLiteBase = require (' @littleq/element-lite/dist/element-lite.cjs.js' ).ElementLiteBase ;
474+ var ElementLiteStaticShadow = require (' @littleq/element-lite/dist/element-lite.cjs.js' ).ElementLiteStaticShadow ;
475+ var ElementLiteLitOnly = require (' @littleq/element-lite/dist/element-lite.cjs.js' ).ElementLiteLitOnly ;
476+ ` ` `
477+
478+ using ` < script> `
479+
480+ ` ` ` js
481+ var ElementLiteBase = window .ElementLite .ElementLiteBase
482+ var ElementLiteStaticShadow = window .ElementLite .ElementLiteStaticShadow
483+ var ElementLiteLitOnly = window .ElementLite .ElementLiteLitOnly
484+ ` ` `
485+
486+
487+ ## And does it work on?
488+
489+ It works on all major evergreen Browsers (Edge, Safari, Chrome, Firefox) as long as you have the Polyfills
490+ set (make sure to add ` webcomponents- lite` or ` webcomponents- loader` and create the components after the
491+ ` WebComponentsReady` event has been fired)
492+
493+ It also works on IE 11, Safari 11, Safari 10.1, Safari 9, and Safari 8.
494+
495+ Still checking on IE 10, 9, 8 and Safari 7, 6. (Need polyfills for ` Map ` and ` WeakMap ` ).
496+
497+
322498## Size
323499
324500Based on size-limit
@@ -342,7 +518,7 @@ npm run size
342518 Size limit: 3 KB
343519
344520 element- lite .js
345- Package size: 5.23 KB
521+ Package size: 5.33 KB
346522 Size limit: 5.5 KB
347523
348524 With all dependencies, minified and gzipped
@@ -352,4 +528,4 @@ npm run size
352528
3535291. Not yet tested for Production #2
3545302. Not yet tested using Webpack on older browsers #2
355- 4 . Haven't tested a proper loop and if-then-else in #2
531+ 3 . Haven't tested a proper loop and if-then-else in #2
0 commit comments