An open API service indexing awesome lists of open source software.

https://github.com/rodydavis/object-dom

HTML Object Declarative Dom
https://github.com/rodydavis/object-dom

declarative-ui dom html5 typescript virtual-dom

Last synced: about 1 year ago
JSON representation

HTML Object Declarative Dom

Awesome Lists containing this project

README

          

# object-dom

Declarative dom with 1:1 mapping of objects and tags, typed css, reactive updates and no bundler needed.

[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Tests](https://github.com/rodydavis/object_dom/actions/workflows/tests.yml/badge.svg)](https://github.com/rodydavis/object_dom/actions/workflows/tests.yml)
[![Published on npm](https://img.shields.io/npm/v/object-dom.svg)](https://www.npmjs.com/package/object-dom)

- ✅ No Dependencies
- ✅ ES Modules
- ✅ Full Browser Support
- ✅ Full types for CSS
- ✅ Full types for DOM Events
- ✅ Full types for Attributes
- ✅ 100% Typescript

## Supported Tags

https://www.w3schools.com/TAGS/default.ASP

| Tag | Class | Description |
| -------------- | ---------- | -------------------------------------------------------------------------------------------------------- |
| [``](https://www.w3schools.com/TAGS/tag_a.asp) | A | Defines a hyperlink |
| [``](https://www.w3schools.com/TAGS/tag_abbr.asp) | Abbr | Defines an abbreviation or an acronym |
| [`

`](https://www.w3schools.com/TAGS/tag_address.asp) | Address | Defines contact information for the author/owner of a document |
| [``](https://www.w3schools.com/TAGS/tag_area.asp) | Area | Defines an area inside an image map |
| [``](https://www.w3schools.com/TAGS/tag_article.asp) | Article | Defines an article |
| [``](https://www.w3schools.com/TAGS/tag_aside.asp) | Aside | Defines content aside from the page content |
| [``](https://www.w3schools.com/TAGS/tag_audio.asp) | Audio | Defines embedded sound content |
| [``](https://www.w3schools.com/TAGS/tag_b.asp) | B | Defines bold text |
| [``](https://www.w3schools.com/TAGS/tag_base.asp) | Base | Specifies the base URL/target for all relative URLs in a document |
| [``](https://www.w3schools.com/TAGS/tag_bdi.asp) | Bdi | Isolates a part of text that might be formatted in a different direction from other text outside it |
| [``](https://www.w3schools.com/TAGS/tag_bdo.asp) | Bdo | Overrides the current text direction |
| [`
`](https://www.w3schools.com/TAGS/tag_blockquote.asp) | Blockquote | Defines a section that is quoted from another source |
| [``](https://www.w3schools.com/TAGS/tag_body.asp) | Body | Defines the document's body |
| [`
`](https://www.w3schools.com/TAGS/tag_br.asp) | Br | Defines a single line break |
| [``](https://www.w3schools.com/TAGS/tag_button.asp) | Button | Defines a clickable button |
| [``](https://www.w3schools.com/TAGS/tag_canvas.asp) | Canvas | Used to draw graphics, on the fly, via scripting (usually JavaScript) |
| [``](https://www.w3schools.com/TAGS/tag_caption.asp) | Caption | Defines a table caption |
| [``](https://www.w3schools.com/TAGS/tag_cite.asp) | Cite | Defines the title of a work |
| [``](https://www.w3schools.com/TAGS/tag_code.asp) | Code | Defines a piece of computer code |
| [``](https://www.w3schools.com/TAGS/tag_col.asp) | Col | Specifies column properties for each column within a `` element |
| [``](https://www.w3schools.com/TAGS/tag_colgroup.asp) | Colgroup | Specifies a group of one or more columns in a table for formatting |
| [``](https://www.w3schools.com/TAGS/tag_data.asp) | Data | Adds a machine-readable translation of a given content |
| [``](https://www.w3schools.com/TAGS/tag_datalist.asp) | Datalist | Specifies a list of pre-defined options for input controls |
| [`
`](https://www.w3schools.com/TAGS/tag_dd.asp) | Dd | Defines a description/value of a term in a description list |
| [``](https://www.w3schools.com/TAGS/tag_del.asp) | Del | Defines text that has been deleted from a document |
| [``](https://www.w3schools.com/TAGS/tag_details.asp) | Details | Defines additional details that the user can view or hide |
| [``](https://www.w3schools.com/TAGS/tag_dfn.asp) | Dfn | Specifies a term that is going to be defined within the content |
| [``](https://www.w3schools.com/TAGS/tag_dialog.asp) | Dialog | Defines a dialog box or window |
| [`
`](https://www.w3schools.com/TAGS/tag_div.asp) | Div | Defines a section in a document |
| [`
`](https://www.w3schools.com/TAGS/tag_dl.asp) | Dl | Defines a description list |
| [`
`](https://www.w3schools.com/TAGS/tag_dt.asp) | Dt | Defines a term/name in a description list |
| [``](https://www.w3schools.com/TAGS/tag_em.asp) | Em | Defines emphasized text |
| [``](https://www.w3schools.com/TAGS/tag_embed.asp) | Embed | Defines a container for an external application |
| [``](https://www.w3schools.com/TAGS/tag_fieldset.asp) | Fieldset | Groups related elements in a form |
| [``](https://www.w3schools.com/TAGS/tag_figcaption.asp) | Figcaption | Defines a caption for a `` element |
| [``](https://www.w3schools.com/TAGS/tag_figure.asp) | Figure | Specifies self-contained content |
| [``](https://www.w3schools.com/TAGS/tag_footer.asp) | Footer | Defines a footer for a document or section |
| [``](https://www.w3schools.com/TAGS/tag_form.asp) | Form | Defines an HTML form for user input |
| [`

`](https://www.w3schools.com/TAGS/tag_h1.asp) | H1 | Defines HTML headings |
| [`

`](https://www.w3schools.com/TAGS/tag_h2.asp) | H2 | Defines HTML headings |
| [`

`](https://www.w3schools.com/TAGS/tag_h3.asp) | H3 | Defines HTML headings |
| [`

`](https://www.w3schools.com/TAGS/tag_h4.asp) | H4 | Defines HTML headings |
| [`

`](https://www.w3schools.com/TAGS/tag_h5.asp) | H5 | Defines HTML headings |
| [`
`](https://www.w3schools.com/TAGS/tag_h6.asp) | H6 | Defines HTML headings |
| [``](https://www.w3schools.com/TAGS/tag_head.asp) | Head | Contains metadata/information for the document |
| [``](https://www.w3schools.com/TAGS/tag_header.asp) | Header | Defines a header for a document or section |
| [`
`](https://www.w3schools.com/TAGS/tag_hr.asp) | Hr | Defines a thematic change in the content |
| [``](https://www.w3schools.com/TAGS/tag_html.asp) | Html | Defines the root of an HTML document |
| [``](https://www.w3schools.com/TAGS/tag_i.asp) | I | Defines a part of text in an alternate voice or mood |
| [``](https://www.w3schools.com/TAGS/tag_iframe.asp) | Iframe | Defines an inline frame |
| [``](https://www.w3schools.com/TAGS/tag_img.asp) | Img | Defines an image |
| [``](https://www.w3schools.com/TAGS/tag_input.asp) | Input | Defines an input control |
| [``](https://www.w3schools.com/TAGS/tag_ins.asp) | Ins | Defines a text that has been inserted into a document |
| [``](https://www.w3schools.com/TAGS/tag_kbd.asp) | Kbd | Defines keyboard input |
| [``](https://www.w3schools.com/TAGS/tag_label.asp) | Label | Defines a label for an `` element |
| [``](https://www.w3schools.com/TAGS/tag_legend.asp) | Legend | Defines a caption for a `` element |
| [`
  • `](https://www.w3schools.com/TAGS/tag_li.asp) | Li | Defines a list item |
    | [``](https://www.w3schools.com/TAGS/tag_link.asp) | Link | Defines the relationship between a document and an external resource (most used to link to style sheets) |
    | [``](https://www.w3schools.com/TAGS/tag_main.asp) | Main | Specifies the main content of a document |
    | [``](https://www.w3schools.com/TAGS/tag_map.asp) | Map | Defines an image map |
    | [``](https://www.w3schools.com/TAGS/tag_mark.asp) | Mark | Defines marked/highlighted text |
    | [``](https://www.w3schools.com/TAGS/tag_meta.asp) | Meta | Defines metadata about an HTML document |
    | [``](https://www.w3schools.com/TAGS/tag_meter.asp) | Meter | Defines a scalar measurement within a known range (a gauge) |
    | [``](https://www.w3schools.com/TAGS/tag_nav.asp) | Nav | Defines navigation links |
    | [``](https://www.w3schools.com/TAGS/tag_noscript.asp) | Noscript | Defines an alternate content for users that do not support client-side scripts |
    | [``](https://www.w3schools.com/TAGS/tag_object.asp) | Obj | Defines a container for an external application |
    | [`
      `](https://www.w3schools.com/TAGS/tag_ol.asp) | Ol | Defines an ordered list |
      | [``](https://www.w3schools.com/TAGS/tag_optgroup.asp) | Optgroup | Defines a group of related options in a drop-down list |
      | [``](https://www.w3schools.com/TAGS/tag_option.asp) | Option | Defines an option in a drop-down list |
      | [``](https://www.w3schools.com/TAGS/tag_output.asp) | Output | Defines the result of a calculation |
      | [`

      `](https://www.w3schools.com/TAGS/tag_p.asp) | P | Defines a paragraph |
      | [``](https://www.w3schools.com/TAGS/tag_param.asp) | Param | Defines a parameter for an object |
      | [``](https://www.w3schools.com/TAGS/tag_picture.asp) | Picture | Defines a container for multiple image resources |
      | [`

      `](https://www.w3schools.com/TAGS/tag_pre.asp) | Pre | Defines preformatted text |
      
      | [``](https://www.w3schools.com/TAGS/tag_progress.asp) | Progress | Represents the progress of a task |
      | [``](https://www.w3schools.com/TAGS/tag_q.asp) | Q | Defines a short quotation |
      | [``](https://www.w3schools.com/TAGS/tag_rp.asp) | Rp | Defines what to show in browsers that do not support ruby annotations |
      | [``](https://www.w3schools.com/TAGS/tag_rt.asp) | Rt | Defines an explanation/pronunciation of characters (for East Asian typography) |
      | [``](https://www.w3schools.com/TAGS/tag_ruby.asp) | Ruby | Defines a ruby annotation (for East Asian typography) |
      | [``](https://www.w3schools.com/TAGS/tag_s.asp) | S | Defines text that is no longer correct |
      | [``](https://www.w3schools.com/TAGS/tag_samp.asp) | Samp | Defines sample output from a computer program |
      | [``](https://www.w3schools.com/TAGS/tag_script.asp) | Script | Defines a client-side script |
      | [`<section>`](https://www.w3schools.com/TAGS/tag_section.asp) | Section | Defines a section in a document |
      | [`<select>`](https://www.w3schools.com/TAGS/tag_select.asp) | Select | Defines a drop-down list |
      | [`<small>`](https://www.w3schools.com/TAGS/tag_small.asp) | Small | Defines smaller text |
      | [`<source>`](https://www.w3schools.com/TAGS/tag_source.asp) | Source | Defines multiple media resources for media elements (`<video>` and `<audio>`) |
      | [`<span>`](https://www.w3schools.com/TAGS/tag_span.asp) | Span | Defines a section in a document |
      | [`<strong>`](https://www.w3schools.com/TAGS/tag_strong.asp) | Strong | Defines important text |
      | [`<style>`](https://www.w3schools.com/TAGS/tag_style.asp) | Style | Defines style information for a document |
      | [`<sub>`](https://www.w3schools.com/TAGS/tag_sub.asp) | Sub | Defines subscripted text |
      | [`<summary>`](https://www.w3schools.com/TAGS/tag_summary.asp) | Summary | Defines a visible heading for a `<details>` element |
      | [`<sup>`](https://www.w3schools.com/TAGS/tag_sup.asp) | Sup | Defines superscripted text |
      | [`<svg>`](https://www.w3schools.com/TAGS/tag_svg.asp) | Svg | Defines a container for SVG graphics |
      | [`<table>`](https://www.w3schools.com/TAGS/tag_table.asp) | Table | Defines a table |
      | [`<tbody>`](https://www.w3schools.com/TAGS/tag_tbody.asp) | Tbody | Groups the body content in a table |
      | [`<td>`](https://www.w3schools.com/TAGS/tag_td.asp) | Td | Defines a cell in a table |
      | [`<template>`](https://www.w3schools.com/TAGS/tag_template.asp) | Template | Defines a container for content that should be hidden when the page loads |
      | [`<textarea>`](https://www.w3schools.com/TAGS/tag_textarea.asp) | Textarea | Defines a multiline input control (text area) |
      | [`<tfoot>`](https://www.w3schools.com/TAGS/tag_tfoot.asp) | Tfoot | Groups the footer content in a table |
      | [`<th>`](https://www.w3schools.com/TAGS/tag_th.asp) | Th | Defines a header cell in a table |
      | [`<thead>`](https://www.w3schools.com/TAGS/tag_thead.asp) | Thead | Groups the header content in a table |
      | [`<time>`](https://www.w3schools.com/TAGS/tag_time.asp) | Time | Defines a specific time (or datetime) |
      | [`<title>`](https://www.w3schools.com/TAGS/tag_title.asp) | Title | Defines a title for the document |
      | [`<tr>`](https://www.w3schools.com/TAGS/tag_tr.asp) | Tr | Defines a row in a table |
      | [`<track>`](https://www.w3schools.com/TAGS/tag_track.asp) | Track | Defines text tracks for media elements (`<video>` and `<audio>`) |
      | [`<u>`](https://www.w3schools.com/TAGS/tag_u.asp) | U | Defines some text that is unarticulated and styled differently from normal text |
      | [`<ul>`](https://www.w3schools.com/TAGS/tag_ul.asp) | Ul | Defines an unordered list |
      | [`<var>`](https://www.w3schools.com/TAGS/tag_var.asp) | Var | Defines a variable |
      | [`<video>`](https://www.w3schools.com/TAGS/tag_video.asp) | Video | Defines embedded video content |
      | [`<wbr>`](https://www.w3schools.com/TAGS/tag_wbr.asp) | Wbr | Defines a possible line-break |
      <!-- END_TAGS -->

      ## Available Methods

      - jsonTable
      - render
      - generateHtml
      - parseHtml
      - textContent

      ## Getting Started

      ### Functional Approach

      ```html
      <div id="root"></div>
      <script type="module">
      import { Div, P, Button, Row, Column, render } from "object-dom";

      const label = new P({ text: "Hello World!" });
      const button = new Button({
      text: "Update",
      styles: { width: "100px" },
      });
      const app = new Div({
      children: [
      new Column({
      children: [
      label,
      button,
      new Row({
      styles: { padding: "10px" },
      children: ["A", "B", "C"],
      }),
      ],
      }),
      ],
      });
      button.addEventListener('click', () => {
      label.text = "New Update!";
      }, false);
      render(app, document.body.querySelector("#root"));

      ```

      ### Class Approach

      ```js
      import { ObjectDom, Div, H1, Button, Row, Canvas } from "object-dom";

      export class MyApp extends ObjectDom {
      render = () => {
      return new Div({
      children: [new H1({ text: "Counter Example" }), new Counter(), new CanvasExample()],
      });
      };
      }

      class Counter extends ObjectDom {
      value = 0;
      render() {
      return new Div({
      styles: { margin: "5px" },
      children: [
      `${this.value}`,
      new Row({
      children: [
      new Button({
      text: "-",
      styles: { width: "50px" },
      events: {
      click: () => {
      this.value -= 1;
      this.update();
      },
      },
      }),
      new Button({
      text: "+",
      styles: { width: "50px", marginLeft: "5px" },
      events: {
      click: () => {
      this.value += 1;
      this.update();
      },
      },
      }),
      ],
      }),
      ],
      });
      }
      }

      class CanvasExample extends ObjectDom {
      render() {
      return new Canvas({
      styles: { width: "200px", height: "200px" },
      onCreate: (node) => {
      const canvas = node as HTMLCanvasElement;
      const ctx = canvas.getContext("2d")!;

      // Create gradient
      const grd = ctx.createRadialGradient(75, 50, 5, 90, 60, 100);
      grd.addColorStop(0, "red");
      grd.addColorStop(1, "white");

      // Fill with gradient
      ctx.fillStyle = grd;
      ctx.fillRect(10, 10, 150, 80);
      },
      });
      }
      }

      render(new MyApp(), document.body.querySelector("#root"));
      ```

      ### JSON Table

      ```js
      jsonTable(
      [
      {
      first_name: "John",
      last_name: "Smith",
      company: "N/A",
      },
      {
      first_name: "Steve",
      last_name: "Jobs",
      company: "Apple",
      },
      {
      first_name: "Bill",
      last_name: "Gates",
      company: "Microsoft",
      },
      {
      first_name: "Elon",
      last_name: "Musk",
      company: "Tesla",
      },
      ],
      { style: { margin: "10px" } }
      );
      ```

      Which renders the following html:

      ```html


      first_name
      last_name
      company


      John
      Smith
      N/A


      Steve
      Jobs
      Apple


      Bill
      Gates
      Microsoft


      Elon
      Musk
      Tesla

      ```