0.3.8 • Published 21 days ago

imm-dom v0.3.8

Weekly downloads
1
License
BSD-2-Clause
Repository
github
Last release
21 days ago

Immediate-Mode DOM Tools

Lightweight tooling around DOM creation. Designed to be embedded piecewise in self-contained Web Components.

I love virtual DOM libraries like superfine, preact, and inferno. But not all creations need the efficient updating logic. Creations like self-sufficient Web Components, where every byte of superfluous logic is wasted.

The imm-dom library enables concise expression of DOM creation, while never setting innerHTML with uncontrolled content. Elements are created using createElement() or createElementNS(). Strings become Text nodes via createTextNode() or elem.append(). Attributes are set using elem.setAttribute(). DOM injection is protected against, in conjunction with caution and expertise, to provide tools for dynamic content.

Demo

See the mini demo and the demo's index.html source.

API

imm-dom provdes layers of DOM tools:

  • Creating new DOM elements, both HTML and SVG
  • Manipulating (existing) DOM elements
  • Defining Web Components
  • Misc utilities: promises, deferreds, render animation frames, etc.

Read more in docs/README.md

Immediate Custom Element Web Componet API:

<section>
  <imm-demo-cdn data-demo=yes kind=awesome title='my demo title'>
    some body text for the CDN demo
  </imm-demo-cdn>

  <script type=module>
    import {imm_html as h, ImmElem} from 'https://cdn.jsdelivr.net/npm/imm-dom@latest/esm/index.js'

    ImmElem.elem('imm-demo-cdn', ns =>
      h.article(
        {class: ns.kind},
        h.h3(`${ns.title}`),
        h.slot('Body text Slot')) )
  </script>
</section>

Inspired by:

Immediate DOM API:

imm_html.article({class: 'awesome'},
  imm_html.h3('my demo title'),
  'some body text')

// or

tag('article', {class: 'awesome'},
  tag('h3', 'my demo title'),
  'some body text')

Inspired by:

Immediate Template API:

imm_tmpl`
  <article ${ {class: 'awesome'} }>
    <h3>${ 'my demo title' }</h3>
    ${ 'some body text' }
  </article>`

Inspired by:

Immediate requestAnimationFrame API

  • imm_raf() returns a promise for the next requestAnimationFrame tick.
  • ImmRAF is like ImmElem using requestAnimationFrame to decouple attribute updates from rendering.

Size Cost in Bytes

To be embedded in each web component custom element, the individual pieces must be small. Thus imm-dom is designed to include only the parts actually used when paired with a tree-shaking tool like rollup.

One component might only use imm_set() from imm_dom_core.js for ~ 1350 bytes minified; ~ 700 brotli.

An web component may take advantage of ImmElem from imm_elem.js for ~ 2700 bytes minified; ~ 1200 brotli.

A heavy rendering component may take advantage of ImmRAF from imm_elem_raf.js for ~ 3200 bytes minified; ~ 1500 brotli.

The entire library is ~ 9500 bytes minified; ~ 4000 brotli -- perfect for bundling a larger web component library and sharing structure.

modulebrotliminifiedsource
index3910 B9462 B21672 B
imm_dom697 B1344 B3562 B
imm_elem1203 B2684 B7317 B
imm_tmpl951 B1918 B5623 B

See auto-generated compressed size report.

License

BSD 2-clause

0.3.8

21 days ago

0.3.7

1 month ago

0.3.6

2 months ago

0.3.5

2 months ago

0.3.4

4 months ago

0.3.3

5 months ago

0.3.2

6 months ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.5

1 year ago

0.2.0-2

2 years ago

0.2.0-1

2 years ago

0.2.0-0

2 years ago

0.1.4

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.4

2 years ago

0.0.44

2 years ago

0.0.45

2 years ago

0.0.46

2 years ago

0.0.47

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.3

2 years ago

0.0.51

2 years ago

0.0.52

2 years ago

0.0.53

2 years ago

0.0.54

2 years ago

0.0.55

2 years ago

0.0.56

2 years ago

0.0.57

2 years ago

0.0.50

2 years ago

0.0.48

2 years ago

0.0.49

2 years ago

0.0.40

2 years ago

0.0.41

2 years ago

0.0.42

2 years ago

0.0.43

2 years ago

0.0.37

2 years ago

0.0.38

2 years ago

0.0.39

2 years ago

0.0.36

2 years ago

0.0.34

2 years ago

0.0.35

2 years ago

0.0.33

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.27

3 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.25

3 years ago

0.0.26

3 years ago

0.0.24

3 years ago

0.0.23

3 years ago

0.0.22

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.19

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.13

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago