Commit dedd8a3d authored by Akari Labs's avatar Akari Labs

line endings again, what a fucking mess

parent bef2d77a
MIT License
Copyright (c) 2019 caela akari
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.
MIT License
Copyright (c) 2019 caela akari
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.
# inert2
# inert2
jsx compilation and 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);
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 = {
install() {
require.extensions['.jsx'] = (module, filename) => module._compile(transform(fs.readFileSync(filename, 'utf8')), filename);
},
render(tag, attrs, ...children) {
return inertdom.apply(null, arguments).outerHTML;
}
const buble = require('buble');
const { JSDOM } = require('jsdom');
const dom = new JSDOM();
const getDom = require('./inertdom');
const inertdom = getDom(dom.window);
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 = {
install() {
require.extensions['.jsx'] = (module, filename) => module._compile(transform(fs.readFileSync(filename, 'utf8')), filename);
},
render(tag, attrs, ...children) {
return inertdom.apply(null, arguments).outerHTML;
}
};
\ 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;
}
/*
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
{
"friendly_name": "inert",
"modules": {
"dom": {
"filename": "inertdom.js",
"provides": "jsx"
}
}
{
"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