🐛 Full ES6 => ES5 transpiling
This commit is contained in:
parent
88e598f794
commit
6d6af1092d
311
bundle.js
311
bundle.js
|
@ -1,7 +1,23 @@
|
|||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||
"use strict";
|
||||
|
||||
function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
|
||||
|
||||
(function e(t, n, r) {
|
||||
function s(o, u) {
|
||||
if (!n[o]) {
|
||||
if (!t[o]) {
|
||||
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);var f = new Error("Cannot find module '" + o + "'");throw f.code = "MODULE_NOT_FOUND", f;
|
||||
}var l = n[o] = { exports: {} };t[o][0].call(l.exports, function (e) {
|
||||
var n = t[o][1][e];return s(n ? n : e);
|
||||
}, l, l.exports, e, t, n, r);
|
||||
}return n[o].exports;
|
||||
}var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) {
|
||||
s(r[o]);
|
||||
}return s;
|
||||
})({ 1: [function (require, module, exports) {
|
||||
'use strict';
|
||||
|
||||
const wrapNode = require('./lib/node');
|
||||
var wrapNode = require('./lib/node');
|
||||
|
||||
/**
|
||||
* Import given node into `the-dom`
|
||||
|
@ -9,7 +25,9 @@ const wrapNode = require('./lib/node');
|
|||
* @param {Node} node Node to import
|
||||
* @return {Object} Wrapped node
|
||||
*/
|
||||
exports.import = (node) => wrapNode(node);
|
||||
exports.import = function (node) {
|
||||
return wrapNode(node);
|
||||
};
|
||||
|
||||
/**
|
||||
* Import an HTML document into `the-dom`
|
||||
|
@ -17,21 +35,24 @@ exports.import = (node) => wrapNode(node);
|
|||
* @param {HTMLDocument} doc Document to import
|
||||
* @return {Object} A hash with doctype, body, head, html props
|
||||
*/
|
||||
exports.html = doc => ({
|
||||
create: name => doc.createElement(name),
|
||||
exports.html = function (doc) {
|
||||
return {
|
||||
create: function create(name) {
|
||||
return doc.createElement(name);
|
||||
},
|
||||
body: wrapNode(doc.body),
|
||||
head: wrapNode(doc.head),
|
||||
html: wrapNode(doc.documentElement),
|
||||
doctype: wrapNode(doc.doctype)
|
||||
});
|
||||
|
||||
};
|
||||
};
|
||||
}, { "./lib/node": 3 }], 2: [function (require, module, exports) {
|
||||
'use strict';
|
||||
|
||||
const utils = require('./utils');
|
||||
var utils = require('./utils');
|
||||
|
||||
const split = utils.split;
|
||||
const iterateArray = utils.iterateArray;
|
||||
var split = utils.split;
|
||||
var iterateArray = utils.iterateArray;
|
||||
|
||||
/**
|
||||
* Create an object to manipulate given node's CSS classes
|
||||
|
@ -40,11 +61,11 @@ const iterateArray = utils.iterateArray;
|
|||
* @see `Set` documentation for behaviour information
|
||||
* @return {Object} Set-like object
|
||||
*/
|
||||
const wrapClass = node => {
|
||||
const res = {
|
||||
add: function (el) {
|
||||
var wrapClass = function wrapClass(node) {
|
||||
var res = {
|
||||
add: function add(el) {
|
||||
if (!this.has(el)) {
|
||||
const classes = split(node.className);
|
||||
var classes = split(node.className);
|
||||
|
||||
classes.push(el);
|
||||
node.className = classes.join(' ');
|
||||
|
@ -53,8 +74,9 @@ const wrapClass = node => {
|
|||
return this;
|
||||
},
|
||||
|
||||
delete: el => {
|
||||
const classes = split(node.className), pos = classes.indexOf(el);
|
||||
delete: function _delete(el) {
|
||||
var classes = split(node.className),
|
||||
pos = classes.indexOf(el);
|
||||
|
||||
if (pos > -1) {
|
||||
classes.splice(pos, 1);
|
||||
|
@ -65,21 +87,54 @@ const wrapClass = node => {
|
|||
return false;
|
||||
},
|
||||
|
||||
has: el => split(node.className).indexOf(el) !== -1,
|
||||
clear: () => node.className = '',
|
||||
has: function has(el) {
|
||||
return split(node.className).indexOf(el) !== -1;
|
||||
},
|
||||
clear: function clear() {
|
||||
return node.className = '';
|
||||
},
|
||||
|
||||
get size() {
|
||||
return split(node.className).length;
|
||||
},
|
||||
|
||||
keys: () => iterateArray(split(node.className)),
|
||||
values: () => iterateArray(split(node.className)),
|
||||
entries: () => iterateArray(split(node.className).map(el => [el, el])),
|
||||
keys: function keys() {
|
||||
return iterateArray(split(node.className));
|
||||
},
|
||||
values: function values() {
|
||||
return iterateArray(split(node.className));
|
||||
},
|
||||
entries: function entries() {
|
||||
return iterateArray(split(node.className).map(function (el) {
|
||||
return [el, el];
|
||||
}));
|
||||
},
|
||||
|
||||
forEach: function forEach(callback, thisArg) {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = this[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var cls = _step.value;
|
||||
|
||||
forEach: function (callback, thisArg) {
|
||||
for (let cls of this) {
|
||||
callback.call(thisArg, cls, cls, this);
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -88,13 +143,12 @@ const wrapClass = node => {
|
|||
};
|
||||
|
||||
module.exports = wrapClass;
|
||||
|
||||
}, { "./utils": 5 }], 3: [function (require, module, exports) {
|
||||
'use strict';
|
||||
|
||||
const wrapClass = require('./class');
|
||||
const wrapStyle = require('./style');
|
||||
const split = require('./utils').split;
|
||||
var wrapClass = require('./class');
|
||||
var wrapStyle = require('./style');
|
||||
var split = require('./utils').split;
|
||||
|
||||
/**
|
||||
* Ensure a node is not wrapped before using it in native methods
|
||||
|
@ -102,8 +156,9 @@ const split = require('./utils').split;
|
|||
* @param {Node|Object} node A node, wrapped or not
|
||||
* @return {Node} Unwrapped node
|
||||
*/
|
||||
const unwrap = node =>
|
||||
(typeof node !== 'object' || node === null || !node.node) ? node : node.node;
|
||||
var unwrap = function unwrap(node) {
|
||||
return (typeof node === "undefined" ? "undefined" : _typeof(node)) !== 'object' || node === null || !node.node ? node : node.node;
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn a NodeList/HTMLCollection into an array
|
||||
|
@ -112,21 +167,25 @@ const unwrap = node =>
|
|||
* @param {NodeList|HTMLCollection} list Input collection
|
||||
* @return {Array} Wrapping array
|
||||
*/
|
||||
const wrapList = list => {
|
||||
const length = list.length;
|
||||
let result = [];
|
||||
var wrapList = function wrapList(list) {
|
||||
var length = list.length;
|
||||
var result = [];
|
||||
|
||||
for (let i = 0; i < length; i += 1) {
|
||||
for (var i = 0; i < length; i += 1) {
|
||||
result.push(wrapNode(list.item(i)));
|
||||
}
|
||||
|
||||
return Object.assign(result, {
|
||||
on: (evts, handler) => {
|
||||
result.forEach(node => node.on(evts, handler));
|
||||
on: function on(evts, handler) {
|
||||
result.forEach(function (node) {
|
||||
return node.on(evts, handler);
|
||||
});
|
||||
},
|
||||
|
||||
off: (evts, handler) => {
|
||||
result.forEach(node => node.off(evts, handler));
|
||||
off: function off(evts, handler) {
|
||||
result.forEach(function (node) {
|
||||
return node.off(evts, handler);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -138,20 +197,26 @@ const wrapList = list => {
|
|||
* @param {Node} Input node
|
||||
* @return {Object} DOM shortcuts
|
||||
*/
|
||||
const wrapNode = node => {
|
||||
if (node === null || typeof node !== 'object') {
|
||||
var wrapNode = function wrapNode(node) {
|
||||
if (node === null || (typeof node === "undefined" ? "undefined" : _typeof(node)) !== 'object') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
node,
|
||||
node: node,
|
||||
|
||||
// search among children
|
||||
find: query => wrapNode(node.querySelector(query)),
|
||||
findAll: query => wrapList(node.querySelectorAll(query)),
|
||||
find: function find(query) {
|
||||
return wrapNode(node.querySelector(query));
|
||||
},
|
||||
findAll: function findAll(query) {
|
||||
return wrapList(node.querySelectorAll(query));
|
||||
},
|
||||
|
||||
// access node's relative tree (parent, children, siblings)
|
||||
equal: el => unwrap(el) === node,
|
||||
equal: function equal(el) {
|
||||
return unwrap(el) === node;
|
||||
},
|
||||
|
||||
get following() {
|
||||
return wrapNode(node.nextElementSibling);
|
||||
|
@ -170,10 +235,18 @@ const wrapNode = node => {
|
|||
},
|
||||
|
||||
// check relative positions
|
||||
precedes: el => !!(unwrap(el).compareDocumentPosition(node) & 2),
|
||||
follows: el => !!(unwrap(el).compareDocumentPosition(node) & 4),
|
||||
contains: el => !!(unwrap(el).compareDocumentPosition(node) & 8),
|
||||
contained: el => !!(unwrap(el).compareDocumentPosition(node) & 16),
|
||||
precedes: function precedes(el) {
|
||||
return !!(unwrap(el).compareDocumentPosition(node) & 2);
|
||||
},
|
||||
follows: function follows(el) {
|
||||
return !!(unwrap(el).compareDocumentPosition(node) & 4);
|
||||
},
|
||||
contains: function contains(el) {
|
||||
return !!(unwrap(el).compareDocumentPosition(node) & 8);
|
||||
},
|
||||
contained: function contained(el) {
|
||||
return !!(unwrap(el).compareDocumentPosition(node) & 16);
|
||||
},
|
||||
|
||||
// get and set element attributes
|
||||
get name() {
|
||||
|
@ -182,24 +255,40 @@ const wrapNode = node => {
|
|||
|
||||
get type() {
|
||||
switch (node.nodeType) {
|
||||
case 1: return 'element';
|
||||
case 3: return 'text';
|
||||
case 7: return 'processing-instruction';
|
||||
case 8: return 'comment';
|
||||
case 9: return 'document';
|
||||
case 10: return 'document-type';
|
||||
case 11: return 'document-fragment';
|
||||
default: return null;
|
||||
case 1:
|
||||
return 'element';
|
||||
case 3:
|
||||
return 'text';
|
||||
case 7:
|
||||
return 'processing-instruction';
|
||||
case 8:
|
||||
return 'comment';
|
||||
case 9:
|
||||
return 'document';
|
||||
case 10:
|
||||
return 'document-type';
|
||||
case 11:
|
||||
return 'document-fragment';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
getAttr: attr => node.getAttribute(attr),
|
||||
setAttr: (attr, value) => node.setAttribute(attr, value),
|
||||
getAttr: function getAttr(attr) {
|
||||
return node.getAttribute(attr);
|
||||
},
|
||||
setAttr: function setAttr(attr, value) {
|
||||
return node.setAttribute(attr, value);
|
||||
},
|
||||
|
||||
// place an element in the DOM tree
|
||||
append: subnode => node.appendChild(unwrap(subnode)),
|
||||
attach: parent => unwrap(parent).appendChild(node),
|
||||
remove: child => {
|
||||
append: function append(subnode) {
|
||||
return node.appendChild(unwrap(subnode));
|
||||
},
|
||||
attach: function attach(parent) {
|
||||
return unwrap(parent).appendChild(node);
|
||||
},
|
||||
remove: function remove(child) {
|
||||
if (child) {
|
||||
node.removeChild(unwrap(child));
|
||||
return;
|
||||
|
@ -230,14 +319,14 @@ const wrapNode = node => {
|
|||
},
|
||||
|
||||
// listen to events
|
||||
on: (evts, handler) => {
|
||||
split(evts).forEach(evt => {
|
||||
on: function on(evts, handler) {
|
||||
split(evts).forEach(function (evt) {
|
||||
node.addEventListener(evt, handler);
|
||||
});
|
||||
},
|
||||
|
||||
off: (evts, handler) => {
|
||||
split(evts).forEach(evt => {
|
||||
off: function off(evts, handler) {
|
||||
split(evts).forEach(function (evt) {
|
||||
node.removeEventListener(evt, handler);
|
||||
});
|
||||
}
|
||||
|
@ -245,11 +334,10 @@ const wrapNode = node => {
|
|||
};
|
||||
|
||||
module.exports = wrapNode;
|
||||
|
||||
}, { "./class": 2, "./style": 4, "./utils": 5 }], 4: [function (require, module, exports) {
|
||||
'use strict';
|
||||
|
||||
const iterateArray = require('./utils').iterateArray;
|
||||
var iterateArray = require('./utils').iterateArray;
|
||||
|
||||
/**
|
||||
* Create an object to manipulate given node's CSS styles
|
||||
|
@ -258,18 +346,22 @@ const iterateArray = require('./utils').iterateArray;
|
|||
* @see `Map` documentation for behaviour information
|
||||
* @return {Object} Map-like object
|
||||
*/
|
||||
const wrapStyle = node => {
|
||||
const res = {
|
||||
set: function (prop, value) {
|
||||
var wrapStyle = function wrapStyle(node) {
|
||||
var res = {
|
||||
set: function set(prop, value) {
|
||||
node.style.setProperty(prop, value);
|
||||
return this;
|
||||
},
|
||||
|
||||
delete: prop => node.style.removeProperty(prop) !== '',
|
||||
has: prop => [].slice.call(node.style).indexOf(prop) > -1,
|
||||
delete: function _delete(prop) {
|
||||
return node.style.removeProperty(prop) !== '';
|
||||
},
|
||||
has: function has(prop) {
|
||||
return [].slice.call(node.style).indexOf(prop) > -1;
|
||||
},
|
||||
|
||||
get: prop => {
|
||||
const result = node.style.getPropertyValue(prop);
|
||||
get: function get(prop) {
|
||||
var result = node.style.getPropertyValue(prop);
|
||||
|
||||
if (result.trim() === '') {
|
||||
return undefined;
|
||||
|
@ -278,10 +370,10 @@ const wrapStyle = node => {
|
|||
return result;
|
||||
},
|
||||
|
||||
clear: () => {
|
||||
const length = node.style.length;
|
||||
clear: function clear() {
|
||||
var length = node.style.length;
|
||||
|
||||
for (let i = 0; i < length; i += 1) {
|
||||
for (var i = 0; i < length; i += 1) {
|
||||
node.style.removeProperty(node.style[i]);
|
||||
}
|
||||
},
|
||||
|
@ -290,16 +382,45 @@ const wrapStyle = node => {
|
|||
return node.style.length;
|
||||
},
|
||||
|
||||
keys: () => iterateArray([].slice.call(node.style)),
|
||||
values: () => iterateArray([].slice.call(node.style).map(
|
||||
prop => node.style.getPropertyValue(prop))),
|
||||
entries: () => iterateArray([].slice.call(node.style).map(
|
||||
prop => [prop, node.style.getPropertyValue(prop)])),
|
||||
keys: function keys() {
|
||||
return iterateArray([].slice.call(node.style));
|
||||
},
|
||||
values: function values() {
|
||||
return iterateArray([].slice.call(node.style).map(function (prop) {
|
||||
return node.style.getPropertyValue(prop);
|
||||
}));
|
||||
},
|
||||
entries: function entries() {
|
||||
return iterateArray([].slice.call(node.style).map(function (prop) {
|
||||
return [prop, node.style.getPropertyValue(prop)];
|
||||
}));
|
||||
},
|
||||
|
||||
forEach: function forEach(callback, thisArg) {
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = this[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var cls = _step2.value;
|
||||
|
||||
forEach: function (callback, thisArg) {
|
||||
for (let cls of this) {
|
||||
callback.call(thisArg, cls, cls, this);
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -308,11 +429,10 @@ const wrapStyle = node => {
|
|||
};
|
||||
|
||||
module.exports = wrapStyle;
|
||||
|
||||
}, { "./utils": 5 }], 5: [function (require, module, exports) {
|
||||
'use strict';
|
||||
|
||||
const whitespace = /\s+/g;
|
||||
var whitespace = /\s+/g;
|
||||
|
||||
/**
|
||||
* Split a list of whitespace separated tokens,
|
||||
|
@ -321,7 +441,11 @@ const whitespace = /\s+/g;
|
|||
* @param {string} str Input string
|
||||
* @return {Array} Split tokens
|
||||
*/
|
||||
exports.split = str => str.split(whitespace).filter(el => el.trim().length);
|
||||
exports.split = function (str) {
|
||||
return str.split(whitespace).filter(function (el) {
|
||||
return el.trim().length;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an iterator on an array
|
||||
|
@ -329,16 +453,15 @@ exports.split = str => str.split(whitespace).filter(el => el.trim().length);
|
|||
* @param {Array} arr Array to iterate on
|
||||
* @return {Object} Iterator for given array
|
||||
*/
|
||||
exports.iterateArray = (arr) => {
|
||||
let next = 0;
|
||||
exports.iterateArray = function (arr) {
|
||||
var _next = 0;
|
||||
|
||||
return {
|
||||
next: () => next < arr.length ?
|
||||
{value: arr[next++], done: false} :
|
||||
{done: true}
|
||||
next: function next() {
|
||||
return _next < arr.length ? { value: arr[_next++], done: false } : { done: true };
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}, {}], 6: [function (require, module, exports) {
|
||||
'use strict';
|
||||
|
||||
|
@ -473,7 +596,6 @@ var resize = function resize() {
|
|||
|
||||
window.onresize = resize;
|
||||
resize();
|
||||
|
||||
}, { "./utils": 7, "the-dom": 1 }], 7: [function (require, module, exports) {
|
||||
'use strict'
|
||||
|
||||
|
@ -485,6 +607,7 @@ resize();
|
|||
* @return {number} Random number
|
||||
*/
|
||||
;
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
@ -527,5 +650,5 @@ var hex = function hex(input) {
|
|||
var rgbToHex = exports.rgbToHex = function rgbToHex(color) {
|
||||
return '#' + hex(color[0]) + hex(color[1]) + hex(color[2]);
|
||||
};
|
||||
|
||||
}, {}] }, {}, [6]);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"url": "git+https://github.com/MattouFP/chaos.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "browserify -t [ babelify --presets [ es2015 ] ] scripts/index.js > bundle.js"
|
||||
"build": "browserify -t [ babelify --presets [ es2015 ] ] scripts/index.js | babel --presets es2015 > bundle.js"
|
||||
},
|
||||
"keywords": [
|
||||
"chaos",
|
||||
|
@ -23,7 +23,9 @@
|
|||
"dependencies": {
|
||||
"babel-preset-es2015": "^6.3.13",
|
||||
"babelify": "^7.2.0",
|
||||
"babel-cli": "^6.3.17",
|
||||
"browserify": "^12.0.1",
|
||||
|
||||
"the-dom": "^0.1.0"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue