basichtml
A NodeJS based, standard oriented, HTML implementation.
Last updated 4 months ago by webreflection .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install basichtml 
SYNC missed versions from official npm registry.

basicHTML

donate Coverage Status Build Status License: ISC Greenkeeper badge

A NodeJS based, standard oriented, HTML implementation.

viperHTML logo

Breaking V2 Changes

As the canvas module brought in ~100MB of dependency, and as it's not even a common use case, I've decided to move the canvas package into devDependencies, so that you need to explicitly include it when you use basicHTML.

npm i basichtml canvas

By default, no canvas module will be installed at all.

New in v1

Introduced optional node-canvas dependency behind the <canvas> and <img> scene ????

  • automatic fallback if the canvas module doesn't build
  • provide canvas 2d API, with the ability to create real images
  • provide the node-canvas Image ability to react on load and error events
const {Image, document} = require('basichtml').init({});

const canvas = document.createElement('canvas');
canvas.width = 320;
canvas.height = 200;

const ctx = canvas.getContext('2d');
ctx.moveTo(0, 0);
ctx.lineTo(320, 200);
ctx.stroke();

const img = new Image();
img.onload = () => {
  console.log(img.outerHTML);
};
img.src = canvas.toDataURL();

New in 0.23

Custom Elements built-in extends are finally supported ????

customElements.define('my-special-thing', MySpecialThing, {extends: 'div'});
document.createElement('div', {is: 'my-special-thing'});

New init(...) in 0.13

// easy way, introduced in 0.13
// pollutes by default the global with:
//  - window
//  - document
//  - customElements
//  - HTMLElement
// if a non global window is provided
// it will use it as defaultView
require('basichtml').init({
  // all properties are optional
  window: global,
  // in case you'd like to share a predefined
  // registry of Custom Elements
  customElements,
  // specify a different selector
  selector: {
    // use the module sizzle, it will be required
    // automatically
    name: 'sizzle',
    // or alternatively, use a module function
    module() {
      return require('sizzle');
    },
    // how to retrieve results => querySelectorAll
    $(Sizzle, element, css) {
      return Sizzle(css, element);
    }
  }
});
// returns the window itself

Good old way to init with basic selectors

const {Document} = require('basichtml');

const document = new Document();

// attributes
document.documentElement.setAttribute('lang', 'en');

// common accessors
document.documentElement.innerHTML = `
  <head></head>
  <body></body>
`;
document.body.textContent = 'Hello basicHTML';

// basic querySelector / querySelectorAll
document.querySelector('head').appendChild(
  document.createElement('title')
).textContent = 'HTML on NodeJS';

// toString() necessary to read, it's a Buffer
console.log(document.toString());

Above log will produce an output like the following one.

<!DOCTYPE html>
<html lang="en">
  <head><title>HTML on NodeJS</title></head>
  <body>Hello basicHTML</body>
</html>

Features

  • create any amount of documents
  • document fragments, comments, text nodes, and elements
  • elements have classList and dataset too
  • Event and CustomEvent through add/removeEventListener and dispatchEvent
  • DOM Level 0 compatible events
  • Attributes compatible with Custom Elements reactions
  • arbitrary Custom Elements creation
  • customizable selector engine

Current caveats / exceptions

  • since v0.2, the property nodeName is case-sensitive to make basicHTML compatible with XML projects too
  • el.querySelectorAll(css) works with tagName, #id, or .className. You can use more complex selectors including 3rd parts libraries such Sizzle, as shown in this test example.
  • el.querySelector(css) is not optimized and will return just index 0 of the whole collection. However, selecting a lot is not the goal of this library.
  • el.getElementsByTagName as well as el.getElementsByClassName and el.getElementsById are all available. The latter is the fastest one of the trio.
  • all collections are basically just arrays. You should use official DOM methods to mutate them. As example, do not ever childNodes.push(new Node) 'cause that's not what you could do on the DOM. The whole point here is to provide a Web like env, not to write defensive code for NodeJS or other non strictly Web environments.
  • most historical properties and standards are most likely not implemented

License

ISC License

Copyright (c) 2017, Andrea Giammarchi, @WebReflection

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

What is this about?

This is an essential implementation of most common HTML operations without the necessary bloat brought in by the entire HTML specification.

The ideal scenario is together with hyperHTML to be able to create DOM trees and objects capable of being updated, refreshed, related to any native component.

The perfect scenario would be to drive NativeScript components using a CustomElementRegistry like you would do on the Web for Custom Elements.

Please bear in mind this project is not aiming to become a fully standard compliant implementation of the whole WebIDL based specifications, there are other projects for that.

Current Tags

  • 2.3.0                                ...           latest (4 months ago)

87 Versions

  • 2.3.0                                ...           4 months ago
  • 2.2.9                                ...           4 months ago
  • 2.2.8                                ...           5 months ago
  • 2.2.7                                ...           5 months ago
  • 2.2.6                                ...           5 months ago
  • 2.2.5                                ...           5 months ago
  • 2.2.4                                ...           5 months ago
  • 2.2.3                                ...           5 months ago
  • 2.2.2                                ...           6 months ago
  • 2.2.1                                ...           6 months ago
  • 2.2.0                                ...           6 months ago
  • 2.1.5                                ...           6 months ago
  • 2.1.4                                ...           6 months ago
  • 2.1.3                                ...           6 months ago
  • 2.1.2                                ...           6 months ago
  • 2.1.1                                ...           6 months ago
  • 2.1.0                                ...           6 months ago
  • 2.0.2                                ...           7 months ago
  • 2.0.1                                ...           7 months ago
  • 2.0.0                                ...           7 months ago
  • 1.1.2                                ...           a year ago
  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.24.0                                ...           a year ago
  • 0.23.4                                ...           a year ago
  • 0.23.3                                ...           a year ago
  • 0.23.2                                ...           a year ago
  • 0.23.1                                ...           a year ago
  • 0.23.0                                ...           a year ago
  • 0.22.1                                ...           a year ago
  • 0.22.0                                ...           a year ago
  • 0.21.2                                ...           2 years ago
  • 0.21.1                                ...           2 years ago
  • 0.21.0                                ...           2 years ago
  • 0.20.4                                ...           2 years ago
  • 0.20.3                                ...           2 years ago
  • 0.20.2                                ...           2 years ago
  • 0.20.1                                ...           2 years ago
  • 0.20.0                                ...           2 years ago
  • 0.19.0                                ...           2 years ago
  • 0.18.0                                ...           2 years ago
  • 0.17.0                                ...           2 years ago
  • 0.16.1                                ...           2 years ago
  • 0.16.0                                ...           2 years ago
  • 0.15.0                                ...           2 years ago
  • 0.14.0                                ...           3 years ago
  • 0.13.2                                ...           3 years ago
  • 0.13.1                                ...           3 years ago
  • 0.13.0                                ...           3 years ago
  • 0.12.3                                ...           3 years ago
  • 0.12.2                                ...           3 years ago
  • 0.12.1                                ...           3 years ago
  • 0.12.0                                ...           3 years ago
  • 0.11.1                                ...           3 years ago
  • 0.11.0                                ...           3 years ago
  • 0.10.5                                ...           3 years ago
  • 0.10.4                                ...           3 years ago
  • 0.10.3                                ...           3 years ago
  • 0.10.2                                ...           3 years ago
  • 0.10.1                                ...           3 years ago
  • 0.10.0                                ...           3 years ago
  • 0.9.4                                ...           3 years ago
  • 0.9.3                                ...           3 years ago
  • 0.9.2                                ...           3 years ago
  • 0.9.1                                ...           3 years ago
  • 0.9.0                                ...           3 years ago
  • 0.8.1                                ...           3 years ago
  • 0.8.0                                ...           3 years ago
  • 0.7.0                                ...           3 years ago
  • 0.6.2                                ...           3 years ago
  • 0.6.1                                ...           3 years ago
  • 0.6.0                                ...           3 years ago
  • 0.5.1                                ...           3 years ago
  • 0.5.0                                ...           3 years ago
  • 0.4.0                                ...           3 years ago
  • 0.3.1                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.3                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (4)
Dev Dependencies (8)

Copyright 2014 - 2016 © taobao.org |