Skip to content

sebastien/select.js

Repository files navigation

 $$$$$$\            $$\                       $$\
$$  __$$\           $$ |                      $$ |
$$ /  \__| $$$$$$\  $$ | $$$$$$\   $$$$$$$\ $$$$$$\       $$\  $$$$$$$\
\$$$$$$\  $$  __$$\ $$ |$$  __$$\ $$  _____|\_$$  _|      \__|$$  _____|
 \____$$\ $$$$$$$$ |$$ |$$$$$$$$ |$$ /        $$ |        $$\ \$$$$$$\
$$\   $$ |$$   ____|$$ |$$   ____|$$ |        $$ |$$\     $$ | \____$$\
\$$$$$$  |\$$$$$$$\ $$ |\$$$$$$$\ \$$$$$$$\   \$$$$  |$$\ $$ |$$$$$$$  |
 \______/  \_______|\__| \_______| \_______|   \____/ \__|$$ |\_______/
                                                    $$\   $$ |
                                                    \$$$$$$  |
                                                     \______/

Select.js is a lightweight toolkit for modern browser interfaces in JavaScript. It started as faster alternative to the venerable jQuery, with support for DOM/SVG manipulation (select.js), and then go expanded with a UI template library (select.ui.js) and supporting fine-grained reactive state primitives (select.cells.js).

While select.js is fast, the select.ui library is not the fastest, but it is fast enough and lightweight enough to be used in a wide range of contexts, in particular when writing plugins or small UIs that need to be embedded into others.

In that sense, Select is designed to fill the niche for little tools that can be composed and embedded. If you want to do a larger scale application, have a look at ui.js which offers high-performance and advanced features for complete web applications.

You can learn more about each component:

In a nutshell

<!DOCTYPE html>
<html><body>
<div id="app"></div>

<script type="importmap">
{
  "imports": {
    "@./": "./src/js/"
  }
}
</script>

<script type="module">
import $ from "@./select.js"
import cell from "@./select.cells.js"
import ui from "@./select.ui.js"

const Counter = ui(`
  <div>
    <button on:click="dec">-</button>
    <span out="count">0</span>
    <button on:click="inc">+</button>
  </div>
`).does({
  count: (self, { count }) => count.value,
  dec: (self, { count }) => count.set(count.value - 1),
  inc: (self, { count }) => count.set(count.value + 1),
})

Counter.new().set({ count: cell(0) }).mount("#app")
$("#app").addClass("ready")
</script>

</body></html>

API

  • select(selector, scope?) ($, S): DOM/SVG selection and manipulation API.
  • cell(value?): mutable reactive cell.
  • derived(template, processor?, initial?): derived reactive value.
  • ui(selection, scope?): template component factory.
  • webcomponent(name, componentFactory, initial?, options?): native custom element registration from Select UI or pure render functions.
  • Dynamic(type, props?): dynamic component resolution by name/function.
  • lazy(loader, placeholder?): lazy component loader.
  • len, type, remap: shared utility helpers from select.ui.js.
  • clsx, bind, drag, autoresize, Keyboard: agnostic helpers from select.extra.js.

Modules

Notable examples

Features

  • DOM + SVG support: one selection API across HTML and SVG nodes.
  • Fine-grained reactivity: explicit cell/derived primitives.
  • Template-driven UI: declarative slot attributes with direct DOM updates.
  • No build step required: works in modern browsers with native ESM.
  • Small and fast: designed with explicit loops and low-overhead primitives.

About

A simplified jquery-like API designed for HTML5 with SVG support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors