kempo 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M756-120 537-339l84-84 219 219-84 84Zm-552 0-84-84 276-276-68-68-28 28-51-51v82l-28 28-121-121 28-28h82l-50-50 142-142q20-20 43-29t47-9q24 0 47 9t43 29l-92 92 50 50-28 28 68 68 90-90q-4-11-6.5-23t-2.5-24q0-59 40.5-99.5T701-841q15 0 28.5 3t27.5 9l-99 99 72 72 99-99q7 14 9.5 27.5T841-701q0 59-40.5 99.5T701-561q-12 0-24-2t-23-7L204-120Z"/></svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kempo",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "type": "module",
5
5
  "description": "A web component library",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  import Component from './Component.js';
2
2
  import { isInView } from '../utils/element.js';
3
-
3
+ import raf from '../utils/raf.js';
4
4
 
5
5
  export default class LazyComponent extends Component {
6
6
  constructor(shadowDetails){
@@ -18,21 +18,24 @@ export default class LazyComponent extends Component {
18
18
  async connectedCallback(){
19
19
  // Do not do super.connectedCallback() because it will render the component prematurely
20
20
  await this.renderSkelton(); // so that the skeleton height is rendered, which will give it the propert height so potentional LazyComponents below it will get out of the viewport as they normally would, before we then check if it is in View (which is delayed a few frames.
21
- if(await isInView(this)){
22
- await this.inViewCallback();
23
- }
21
+ raf(async ()=>{
22
+ if(await isInView(this)) await this.inViewCallback();
23
+ }, 2);
24
24
  }
25
25
  async inViewCallback(){
26
- await this.render();
26
+ return await this.render();
27
27
  }
28
28
  async outOfViewCallback(){
29
29
  if(this.unrender){
30
30
  await this.renderSkelton();
31
+ return true;
31
32
  }
33
+ return false;
32
34
  }
33
35
  async renderSkelton(){
34
36
  this.shadowRoot.innerHTML = `<link rel="stylesheet" href="${Component.pathToKempo}/kempo-styles.css" />${this.skeletonTemplate}<style>${this.shadowStyles}</style>`;
35
37
  this.rendered = false;
38
+ return true;
36
39
  }
37
40
  get skeletonTemplate(){
38
41
  return /*html*/`<div style="height: var(--skeleton_height, 1rem)"></div>`;
@@ -0,0 +1,10 @@
1
+ const raf = (callback, frames = 1) => {
2
+ requestAnimationFrame(()=>{
3
+ if(frames === 1){
4
+ callback();
5
+ } else {
6
+ raf(callback, frames-1);
7
+ }
8
+ });
9
+ }
10
+ export default raf;