npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lens.js

v1.0.4

Published

Bring transition to height changing.

Downloads

7

Readme

Lens.js

Building status

Bring transition to size changing.

Change element's size with transition automaticlly when content is changed.

Demo is here.

Quick start.

Let's see HTML:

<!-- This is the content of your page. -->
<style>
#my-popup {
  width: 300px;
  padding: 30px;
  margin: 30px;
  background-color: red;
  color: white;
  font-size: 13px;
  border: 1px solid black;  
  border-radius: 10px;
}
</style>

<!-- Element to observe. -->
<div id="my-popup">
  <!-- Content will be changed, so is size. -->
  <content-inside></content-inside>
</div>

We need to do some small work first:

<!-- For using Lens.js, -->
<!-- We must change it to: -->
<style>
#my-popup {
  color: white;
  font-size: 13px;
}

/* All styles related to box-sizing are transferred to this new role: */
#my-popup[data-lens="#my-popup"] {
  width: 300px;
  padding: 30px;
  margin: 30px;
  background-color: red;
  border: 1px solid black;
  border-radius: 10px;
}
</style>

<div id="my-popup">
  <content-inside></content-inside>
</div>

Then add transition style in your project.

/*
   Add this rule to your project. Specify transition value as you wish.
   This will affect all Lens-instance's transition style.
 */
.lens-transition {
  transition: all ease .5s;
}

/*
   If you want something special:
*/
.lens-transition[data-lens="#my-popup"] {
  transition: all cubic-bezier(0.4, 0, 1, 1) .4s;
}

Then call lens in JavaScript:

const Lens = require('lens.js')

// Observe height changing of "#my-popup".
const lens = new Lens('#my-popup')
lens.observe()  // Rock and roll!

That's it! Leave it alone and have a coffee. The height will be changed automaticlly.

API.

Create a new lens instance.

const lens = new Lens(selector | HTMLElement)
  • Methods on lens instance:
    • observe: Start observing. Size will be changed with transition automaticlly.
    • disconnect: Stop observing, everything is going back to nomral.
    • update: Update size manually.

Start observing.

Size will be changed with transition automaticlly.

lens.observe()

Start observing with configuration.

Four options available:

  • width
  • height
  • watchStyle
  • deepWatch
lens.observe({
  width: true,        // If enabled, width changing will be in transition.
                      // Default: true

  height: true,       // If enabled, height changing will be in transition.
                      // Default: true

  watchStyle: true,   // If enabled, every style changing in children element will be caught.
                      // Default: true.

  deepWatch: true     // If enabled, children in second and deeper level will be observed.
                      // Default: false.
})

Stop observing.

No more changing. Everything is going back to nomral.

lens.disconnect()

Force update.

lens.update()  // Interface will be update immediately.

You can use it with resize or something else.

window.addEventListener('resize', () => {
  lens.update()
  console.log('Updated.')
  // ...
})

License

MIT.