Commit b79c6f64 authored by Akari Labs's avatar Akari Labs

remove nanopack and compilation support

parent dedd8a3d
# inert2
jsx compilation and rendering without react
\ No newline at end of file
jsx rendering without react
\ No newline at end of file
const buble = require('buble');
const { JSDOM } = require('jsdom');
const dom = new JSDOM();
/*
const getDom = require('./inertdom');
const inertdom = getDom(dom.window);
inertDOM
a ridiculously simple jsx dom function
Copyright 2019 caela and astra akari (lp0 and nocebo)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
function transform(code) {
return `const inert = require(${JSON.stringify(__filename)}); ${buble.transform(code, {
jsx: 'inert.render',
objectAssign: 'Object.assign',
target: { chrome: 52 }
}).code}`;
}
*/
module.exports = {
module.exports = function getDom(window) {
return function dom(tag, attrs, ...children) {
install() {
require.extensions['.jsx'] = (module, filename) => module._compile(transform(fs.readFileSync(filename, 'utf8')), filename);
},
function reduceChild(child) {
if (Array.isArray(child)) return child.map(reduceChild);
return [child];
}
render(tag, attrs, ...children) {
return inertdom.apply(null, arguments).outerHTML;
}
if (children.length === 1 && Array.isArray(children[0])) children = children[0];
if (children.length !== 0)
children = children.map(reduceChild)
.reduce((p, c) => p.concat(c));
var element;
switch (typeof tag) {
case 'function':
element = tag(attrs || {}, children);
break;
case 'string':
element = window.document.createElement(tag);
if (attrs) Object.keys(attrs).forEach(k => {
const a = attrs[k];
switch (typeof a) {
case 'boolean':
if (a) element.setAttribute(k, '');
break;
case 'function':
// a bit of a hack, but it works
if (k.startsWith('on')) {
element[k] = a;
break;
}
default:
element.setAttribute(k, a);
break;
}
});
};
\ No newline at end of file
function addChild(child) {
if (Array.isArray(child)) child.forEach(addChild);
else if (child instanceof window.HTMLElement) element.appendChild(child);
else if (child) element.append(child.toString());
}
addChild(children);
break;
}
return element;
}
}
\ No newline at end of file
/*
inertDOM
a ridiculously simple jsx dom function
Copyright 2019 caela and astra akari (lp0 and nocebo)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
module.exports = function getDom(window) {
return function dom(tag, attrs, ...children) {
function reduceChild(child) {
if (Array.isArray(child)) return child.map(reduceChild);
return [child];
}
if (children.length === 1 && Array.isArray(children[0])) children = children[0];
if (children.length !== 0)
children = children.map(reduceChild)
.reduce((p, c) => p.concat(c));
var element;
switch (typeof tag) {
case 'function':
element = tag(attrs || {}, children);
break;
case 'string':
element = window.document.createElement(tag);
if (attrs) Object.keys(attrs).forEach(k => {
const a = attrs[k];
switch (typeof a) {
case 'boolean':
if (a) element.setAttribute(k, '');
break;
case 'function':
// a bit of a hack, but it works
if (k.startsWith('on')) {
element[k] = a;
break;
}
default:
element.setAttribute(k, a);
break;
}
});
function addChild(child) {
if (Array.isArray(child)) child.forEach(addChild);
else if (child instanceof window.HTMLElement) element.appendChild(child);
else if (child) element.append(child.toString());
}
addChild(children);
break;
}
return element;
}
}
\ No newline at end of file
This diff is collapsed.
{
"name": "inert2",
"version": "2.0.0",
"description": "jsx compilation and rendering without react",
"main": "index.js",
"dependencies": {
"buble": "^0.19.7",
"jsdom": "^15.1.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"description": "jsx rendering without react",
"browser": "index.js",
"repository": {
"type": "git",
"url": "https://git.agiri.ninja/lp0/inert2.git"
......
{
"friendly_name": "inert",
"modules": {
"dom": {
"filename": "inertdom.js",
"provides": "jsx"
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment