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

@mortimer333/dito

v1.0.1

Published

Lightweight library with components, template syntax, bindings and dynamic CSS.

Downloads

6

Readme

Dito

Lightweight library with components, template syntax, bindings and dynamic CSS.

Preview

JS:

import { DitoElement } from 'src/ditoelement.js';

class PlanetElement extends DitoElement {
  init() {
    this.$.icons = ['🌎', , '🪐'];
    this.$.planets = ['earth', , 'jupiter'];
    this.$.className = 'planet-class';
  }
}

export { PlanetElement as default };

HTML:

<h1 @a:class="className" @for="3" @if="$value !== 1">Planet {{ $value + 1 }}: {{ planets[$value] }} {{ icons[$value] }}</h1>

Output:

<h1 class="planet-class">Planet 1: earth 🌎</h1>
<h1 class="planet-class">Planet 3: jupiter 🪐</h1>

Why even try?

The purpose of this library is to have dynamic, scoped and reusable FE components packed with functionality without need for any framework or dependencies which works in plain JS.

Installation

Native

Just download dito.min.js and ditoelement.min.js and require them as modules on your page:

<script type="module" src="/media/script/dist/dito.min.js" charset="utf-8"></script>
import { DitoElement } from "/media/script/dist/dito.min.js";
class CustomElement extends DitoElement {
  // [...]
}

but remember that you will have to update them by hand each time new version is released.

npm

npm i @mortimer333/dito

This would be it for node project, but it is not really a node module. So if you want to use npm but without webpack or gulp check this installation document.

Framework

If you are looking for a ready to go project or just example check this:

  • 💥 Micro Front End,
  • 💥 One-Page Application with Router,
  • 💥 NPM configured Tailwind CSS and esbuild for Dito components with dev/prod mode,
  • 💥 User/Permissions System,

app skeleton made with Dito 🔥.

Quick Start

Start with creating your first component, let's name it showcase-earth (must contain hyphen -):

public/ <- Website root folder
-- components/
-- -- dito.js
-- -- ditoelement.js
-- -- showcase-earth/
-- -- -- showcase-earth.js
-- -- -- showcase-earth.css
-- -- -- showcase-earth.html

We are following Angular-like naming pattern when creating our components.

Now fill your JS with:

import { DitoElement } from 'components/ditoelement.js';
class EarthElement extends DitoElement {
  init() {
    this.$.icon = '🌎';
    this.$.name = 'earth';
    this.$.className = 'earth-class';
  }
}
export { EarthElement as default };

and HTML with:

<h1 @a:class="className">Planet: {{ name }} {{ icon }}</h1>

Notice that all variables used in the HTML file are assigned to the attribute $ which works as a global scope for HTML template. Think of it as a barbaric version of variable visibility and anything set in $ is accessible in HTML.

We also need to create our index file and request just created component:

<body>
  <showcase-earth></showcase-earth>
</body>

Now create new instance of Dito (and only one) and set URL path to the folder containing your components:

const container = new Dito({
  url: 'http://localhost:80/components/',
});

There must be only one instance of Dito per website and attempt to create second will result in error. If you need to access it from different point then you can find it under window.__dito.main or just __dito.main.

Register your first component by Dito::register method which requires the name of the component and version (for cache bursting if necessary):

container.register('showcase-earth', 1);

With all our components registered we can call Dito::load method which will start searching current file for registered components and loads them asynchronously.

await container.load();

At this point our body should look like this:

<body>
  <showcase-earth></showcase-earth>
  <script type="module">
    import { Dito } from 'components/dito.js';
    const container = new Dito({
      url: 'http://localhost:80/components/',
    });
    container.register('earth-element', 1);
    await container.load();
    console.log('Top level components loaded!')
  </script>
</body>

and render into this:

<body>
  <showcase-earth dito-t="1696445746936" dito-i="1" dito-ready>
    <h1 class="earth-class">Planet: earth 🌎</h1>
  </showcase-earth>
  <script type="module">[...]</script>
</body>

We Are Done! Few steps are required and I wouldn't call it the easiest to learn library in the world. You need to understand basics, at least, to start with it but once learned it's pretty good and pleasant to use.

Advanced stuff

With the Quick Start you can't really use the library, it's only to honestly show the very basics of setup and first usage. If you want to be able to use @actions, Injectables, Dynamic CSS, Observables, In-Out Communication and understand Component's Life Cycle then have a read (from top to bottom):