Socket
Socket
Sign inDemoInstall

@pluginjs/dom

Package Overview
Dependencies
Maintainers
2
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pluginjs/dom - npm Package Compare versions

Comparing version 0.0.15 to 0.5.0

dist/dom.cjs.js

152

dist/dom.esm.js
import { curry, compose } from '@pluginjs/utils';
import is from '@pluginjs/is';
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
const objDataName = 'objData';
const query = (selector, parent = document) => parent.querySelector(selector);
const queryAll = (selector, parent = document) => Array.from(parent.querySelectorAll(selector));
const find = curry((selector, parent) => parent.querySelector(selector));
const finds = curry((selector, parent) => Array.from(parent.querySelectorAll(selector)));
const remove = el => el.remove();
const html = curry((content, el) => {

@@ -20,3 +52,2 @@ el.innerHTML = content;

});
const children = el => {

@@ -26,20 +57,24 @@ if (!el) {

}
return Array.from(el.children);
};
const childrenSelect = (selector, el) => Array.from(el.children).filter(c => c.nodeName.toLowerCase() === selector);
const getSiblings = el => {
const childrenArr = children(el.parentNode);
const index = childrenArr.indexOf(el);
if (index > -1) {
childrenArr.splice(index, 1);
}
return childrenArr;
};
const attrVerify = (attrName, value, el) => {
const Obj = {
data: element => {
const [key, v] = value.split('=');
const _value$split = value.split('='),
_value$split2 = _slicedToArray(_value$split, 2),
key = _value$split2[0],
v = _value$split2[1];
if (!is.null(element.dataset[key]) && !is.undefined(element.dataset[key])) {

@@ -49,2 +84,3 @@ if (v) {

}
return true;

@@ -57,3 +93,7 @@ }

attr: element => {
const [key, v] = value.split('=');
const _value$split3 = value.split('='),
_value$split4 = _slicedToArray(_value$split3, 2),
key = _value$split4[0],
v = _value$split4[1];
if (!is.null(element.getAttribute(key)) && !is.undefined(element.getAttribute(key))) {

@@ -63,2 +103,3 @@ if (v) {

}
return true;

@@ -70,4 +111,7 @@ }

};
const childQuery = ({ type, value, level = 3 }, el) => {
const childQuery = ({
type,
value,
level = 3
}, el) => {
const res = [];

@@ -92,6 +136,4 @@

childNodeCompare(el, level);
return res;
};
const Each = (obj, callback) => {

@@ -103,2 +145,3 @@ let i = 0,

length = obj.length;
for (; i < length; i++) {

@@ -113,5 +156,9 @@ callback(obj[i], i);

};
const parentQuery = ({
type,
value,
level = 3
}, el) => {
const res = [];
const parentQuery = ({ type, value, level = 3 }, el) => {
const res = [];
const parentCompare = element => {

@@ -121,3 +168,5 @@ if (attrVerify(type, value, element.parentNode)) {

}
level--;
if (level >= 0) {

@@ -131,14 +180,14 @@ parentCompare(element.parentNode);

};
const parent = el => el.parentNode; // 解析 HTML/SVG/XML 字符串
const parent = el => el.parentNode;
// 解析 HTML/SVG/XML 字符串
const parseHTML = (...args) => {
const htmlString = Array.isArray(args[0]) ? args[0].reduce((result, str, index) => result + args[index] + str) : args[0];
const childNodes = compose(children, html(htmlString))(document.createElement('div'));
if (childNodes.length === 1) {
return childNodes[0];
}
return childNodes;
};
const setObjData = (name, data, el) => {

@@ -152,3 +201,2 @@ if (!el[objDataName]) {

};
const getObjData = (name, el) => {

@@ -161,5 +209,3 @@ if (!el[objDataName]) {

};
const clone = el => el.cloneNode(true);
const empty = el => {

@@ -169,7 +215,4 @@ el.innerHTML = '';

};
const prev = el => el.previousElementSibling;
const next = el => el.nextElementSibling;
const attr = curry((args, el) => {

@@ -179,2 +222,3 @@ if (typeof args === 'string') {

}
Object.entries(args).forEach(([k, v]) => el.setAttribute(k, v));

@@ -184,3 +228,2 @@ return el;

const removeAttribute = curry((name, el) => el.removeAttribute(name));
const dataset = curry((args, el) => {

@@ -190,2 +233,3 @@ if (typeof args === 'string') {

}
Object.entries(args).forEach(([k, v]) => {

@@ -196,3 +240,2 @@ el.dataset[k] = v;

});
const text = curry((content, el) => {

@@ -202,3 +245,2 @@ el.textContent = content;

});
const append = curry((child, el) => {

@@ -210,5 +252,5 @@ if (is.string(child)) {

}
return el;
});
const prepend = curry((child, el) => {

@@ -220,5 +262,5 @@ if (is.string(child)) {

}
return el;
});
const insertBefore = curry((newElement, el) => {

@@ -228,7 +270,8 @@ if (is.string(newElement)) {

} else {
el.insertAdjacentElement('beforebegin', newElement);
const parentElement = parent(el);
parentElement.insertBefore(newElement, el);
}
return el;
});
const insertAfter = curry((newElement, el) => {

@@ -238,12 +281,14 @@ if (is.string(newElement)) {

} else {
el.insertAdjacentElement('afterend', newElement);
const parentElement = parent(el);
parentElement.insertBefore(newElement, el.nextElementSibling);
}
return el;
});
const wrap = curry((wrapElement, el) => {
if (is.string(wrapElement)) {
wrapElement = parseHTML(wrapElement);
}
// compose(append(wrapElement), clone, insertBefore(wrapElement))(el)
} // compose(append(wrapElement), clone, insertBefore(wrapElement))(el)
insertBefore(wrapElement, el);

@@ -254,3 +299,2 @@ remove(el);

});
const wrapInner = (newElement, wrap) => {

@@ -260,2 +304,3 @@ if (is.string(newElement)) {

}
newElement.innerHTML = wrap.innerHTML;

@@ -266,3 +311,2 @@ wrap.innerHTML = '';

};
const wrapAll = (wrapElement, elementList) => {

@@ -273,3 +317,2 @@ insertBefore(wrapElement, elementList[0]);

};
const unwrap = el => {

@@ -283,3 +326,2 @@ const parentEl = parent(el);

};
const clearChild = el => {

@@ -289,15 +331,15 @@ children(el).map(remove);

};
const parentWith = curry((fn, el) => {
const parentElement = parent(el); // console.log(el, parentElement)
const parentWith = curry((fn, el) => {
const parentElement = parent(el);
// console.log(el, parentElement)
if (!parentElement || parentElement === document) {
return false;
}
if (fn(parentElement)) {
return parentElement;
}
return parentWith(fn, parentElement);
});
const clearData = el => {

@@ -307,5 +349,3 @@ Object.keys(el).map(name => el.removeAttribute(`data-${name}`));

};
const contains = curry((el, parent) => parent.contains(el));
const closest = curry((selector, el) => {

@@ -315,16 +355,19 @@ if (el.matches(selector)) {

}
return parentWith(el => el.matches(selector), el);
});
const nextElementWith = curry((fn, el) => {
const nextElement = next(el);
if (fn(nextElement)) {
return nextElement;
}
return nextElementWith(fn, nextElement);
});
}); // == animation == //
// == animation == //
const fade = curry((type, { duration, callback }, element) => {
const fade = curry((type, {
duration,
callback
}, element) => {
const isIn = type === 'in';

@@ -338,2 +381,3 @@ let opacity = isIn ? 0 : 1;

}
element.style.opacity = opacity;

@@ -346,2 +390,3 @@ }

}
const progress = timestamp - start;

@@ -365,3 +410,2 @@ const percent = progress / duration;

});
const fadeOut = fade('out');

@@ -368,0 +412,0 @@ const fadeIn = fade('in');

@@ -1,517 +0,425 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@pluginjs/utils'), require('@pluginjs/is')) :
typeof define === 'function' && define.amd ? define(['exports', '@pluginjs/utils', '@pluginjs/is'], factory) :
(factory((global['@pluginjs/dom'] = {}),global['@pluginjs/utils'],global['@pluginjs/is']));
}(this, (function (exports,utils,is) { 'use strict';
'use strict';
is = is && is.hasOwnProperty('default') ? is['default'] : is;
Object.defineProperty(exports, '__esModule', { value: true });
var slicedToArray = function () {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
var utils = require('@pluginjs/utils');
var is = _interopDefault(require('@pluginjs/is'));
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
}
return _arr;
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
return function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
return sliceIterator(arr, i);
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
};
}();
function _iterableToArrayLimit(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
return arr2;
} else {
return Array.from(arr);
if (i && _arr.length === i) break;
}
};
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
var objDataName = 'objData';
return _arr;
}
var query = function query(selector) {
var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
return parent.querySelector(selector);
};
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
var queryAll = function queryAll(selector) {
var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
return Array.from(parent.querySelectorAll(selector));
};
const objDataName = 'objData';
const query = (selector, parent = document) => parent.querySelector(selector);
const queryAll = (selector, parent = document) => Array.from(parent.querySelectorAll(selector));
const find = utils.curry((selector, parent) => parent.querySelector(selector));
const finds = utils.curry((selector, parent) => Array.from(parent.querySelectorAll(selector)));
const remove = el => el.remove();
const html = utils.curry((content, el) => {
el.innerHTML = content;
return el;
});
const children = el => {
if (!el) {
return null;
}
var find = utils.curry(function (selector, parent) {
return parent.querySelector(selector);
});
return Array.from(el.children);
};
const childrenSelect = (selector, el) => Array.from(el.children).filter(c => c.nodeName.toLowerCase() === selector);
const getSiblings = el => {
const childrenArr = children(el.parentNode);
const index = childrenArr.indexOf(el);
var finds = utils.curry(function (selector, parent) {
return Array.from(parent.querySelectorAll(selector));
});
if (index > -1) {
childrenArr.splice(index, 1);
}
var remove = function remove(el) {
return el.remove();
};
var html = utils.curry(function (content, el) {
el.innerHTML = content;
return el;
});
var children = function children(el) {
if (!el) {
return null;
}
return Array.from(el.children);
};
var childrenSelect = function childrenSelect(selector, el) {
return Array.from(el.children).filter(function (c) {
return c.nodeName.toLowerCase() === selector;
});
};
var getSiblings = function getSiblings(el) {
var childrenArr = children(el.parentNode);
var index = childrenArr.indexOf(el);
if (index > -1) {
childrenArr.splice(index, 1);
}
return childrenArr;
};
var attrVerify = function attrVerify(attrName, value, el) {
var Obj = {
data: function data(element) {
var _value$split = value.split('='),
_value$split2 = slicedToArray(_value$split, 2),
return childrenArr;
};
const attrVerify = (attrName, value, el) => {
const Obj = {
data: element => {
const _value$split = value.split('='),
_value$split2 = _slicedToArray(_value$split, 2),
key = _value$split2[0],
v = _value$split2[1];
if (!is.null(element.dataset[key]) && !is.undefined(element.dataset[key])) {
if (v) {
return element.dataset[key] === v;
}
return true;
if (!is.null(element.dataset[key]) && !is.undefined(element.dataset[key])) {
if (v) {
return element.dataset[key] === v;
}
},
tagName: function tagName(element) {
return element.nodeName.toLowerCase() === value;
},
class: function _class(element) {
return element.classList.contains(value);
},
id: function id(element) {
return element.id === value;
},
attr: function attr(element) {
var _value$split3 = value.split('='),
_value$split4 = slicedToArray(_value$split3, 2),
return true;
}
},
tagName: element => element.nodeName.toLowerCase() === value,
class: element => element.classList.contains(value),
id: element => element.id === value,
attr: element => {
const _value$split3 = value.split('='),
_value$split4 = _slicedToArray(_value$split3, 2),
key = _value$split4[0],
v = _value$split4[1];
if (!is.null(element.getAttribute(key)) && !is.undefined(element.getAttribute(key))) {
if (v) {
return element.getAttribute(key) === v;
}
return true;
if (!is.null(element.getAttribute(key)) && !is.undefined(element.getAttribute(key))) {
if (v) {
return element.getAttribute(key) === v;
}
}
};
return Obj[attrName] && Obj[attrName](el);
};
var childQuery = function childQuery(_ref, el) {
var type = _ref.type,
value = _ref.value,
_ref$level = _ref.level,
level = _ref$level === undefined ? 3 : _ref$level;
var res = [];
var hasChild = function hasChild(element) {
return Array.from(element.children).lenght !== 0;
};
var childNodeCompare = function childNodeCompare(element, l) {
if (hasChild(element)) {
Array.from(element.children).map(function (c) {
if (attrVerify(type, value, c)) {
res.push(c);
}
if (hasChild(c) && l > 0) {
childNodeCompare(c, l - 1);
}
});
return true;
}
};
childNodeCompare(el, level);
return res;
}
};
return Obj[attrName] && Obj[attrName](el);
};
const childQuery = ({
type,
value,
level = 3
}, el) => {
const res = [];
var Each = function Each(obj, callback) {
var i = 0,
length = void 0;
const hasChild = element => Array.from(element.children).lenght !== 0;
if (is.array(obj)) {
length = obj.length;
for (; i < length; i++) {
callback(obj[i], i);
}
} else {
Object.entries(obj).map(function (_ref2) {
var _ref3 = slicedToArray(_ref2, 2),
k = _ref3[0],
v = _ref3[1];
const childNodeCompare = (element, l) => {
if (hasChild(element)) {
Array.from(element.children).map(c => {
if (attrVerify(type, value, c)) {
res.push(c);
}
return callback(k, v);
if (hasChild(c) && l > 0) {
childNodeCompare(c, l - 1);
}
});
}
return obj;
};
var parentQuery = function parentQuery(_ref4, el) {
var type = _ref4.type,
value = _ref4.value,
_ref4$level = _ref4.level,
level = _ref4$level === undefined ? 3 : _ref4$level;
childNodeCompare(el, level);
return res;
};
const Each = (obj, callback) => {
let i = 0,
length;
var res = [];
var parentCompare = function parentCompare(element) {
if (attrVerify(type, value, element.parentNode)) {
res.push(element.parentNode);
}
level--;
if (level >= 0) {
parentCompare(element.parentNode);
}
};
if (is.array(obj)) {
length = obj.length;
parentCompare(el);
return res;
};
var parent = function parent(el) {
return el.parentNode;
};
// 解析 HTML/SVG/XML 字符串
var parseHTML = function parseHTML() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
for (; i < length; i++) {
callback(obj[i], i);
}
} else {
Object.entries(obj).map(([k, v]) => callback(k, v));
}
var htmlString = Array.isArray(args[0]) ? args[0].reduce(function (result, str, index) {
return result + args[index] + str;
}) : args[0];
var childNodes = utils.compose(children, html(htmlString))(document.createElement('div'));
if (childNodes.length === 1) {
return childNodes[0];
}
return childNodes;
};
return obj;
};
const parentQuery = ({
type,
value,
level = 3
}, el) => {
const res = [];
var setObjData = function setObjData(name, data, el) {
if (!el[objDataName]) {
el[objDataName] = {};
const parentCompare = element => {
if (attrVerify(type, value, element.parentNode)) {
res.push(element.parentNode);
}
el[objDataName][name] = data;
return el;
};
level--;
var getObjData = function getObjData(name, el) {
if (!el[objDataName]) {
return false;
if (level >= 0) {
parentCompare(element.parentNode);
}
return el[objDataName][name];
};
var clone = function clone(el) {
return el.cloneNode(true);
};
parentCompare(el);
return res;
};
const parent = el => el.parentNode; // 解析 HTML/SVG/XML 字符串
var empty = function empty(el) {
el.innerHTML = '';
return el;
};
const parseHTML = (...args) => {
const htmlString = Array.isArray(args[0]) ? args[0].reduce((result, str, index) => result + args[index] + str) : args[0];
const childNodes = utils.compose(children, html(htmlString))(document.createElement('div'));
var prev = function prev(el) {
return el.previousElementSibling;
};
if (childNodes.length === 1) {
return childNodes[0];
}
var next = function next(el) {
return el.nextElementSibling;
};
return childNodes;
};
const setObjData = (name, data, el) => {
if (!el[objDataName]) {
el[objDataName] = {};
}
var attr = utils.curry(function (args, el) {
if (typeof args === 'string') {
return el.getAttribute(args);
}
Object.entries(args).forEach(function (_ref5) {
var _ref6 = slicedToArray(_ref5, 2),
k = _ref6[0],
v = _ref6[1];
el[objDataName][name] = data;
return el;
};
const getObjData = (name, el) => {
if (!el[objDataName]) {
return false;
}
return el.setAttribute(k, v);
});
return el;
});
var removeAttribute = utils.curry(function (name, el) {
return el.removeAttribute(name);
});
return el[objDataName][name];
};
const clone = el => el.cloneNode(true);
const empty = el => {
el.innerHTML = '';
return el;
};
const prev = el => el.previousElementSibling;
const next = el => el.nextElementSibling;
const attr = utils.curry((args, el) => {
if (typeof args === 'string') {
return el.getAttribute(args);
}
var dataset = utils.curry(function (args, el) {
if (typeof args === 'string') {
return el.dataset[args];
}
Object.entries(args).forEach(function (_ref7) {
var _ref8 = slicedToArray(_ref7, 2),
k = _ref8[0],
v = _ref8[1];
Object.entries(args).forEach(([k, v]) => el.setAttribute(k, v));
return el;
});
const removeAttribute = utils.curry((name, el) => el.removeAttribute(name));
const dataset = utils.curry((args, el) => {
if (typeof args === 'string') {
return el.dataset[args];
}
el.dataset[k] = v;
});
return el;
Object.entries(args).forEach(([k, v]) => {
el.dataset[k] = v;
});
return el;
});
const text = utils.curry((content, el) => {
el.textContent = content;
return el;
});
const append = utils.curry((child, el) => {
if (is.string(child)) {
el.insertAdjacentHTML('beforeend', child);
} else {
el.append(child);
}
var text = utils.curry(function (content, el) {
el.textContent = content;
return el;
});
return el;
});
const prepend = utils.curry((child, el) => {
if (is.string(child)) {
el.insertAdjacentHTML('afterbegin', child);
} else {
el.prepend(child);
}
var append = utils.curry(function (child, el) {
if (is.string(child)) {
el.insertAdjacentHTML('beforeend', child);
} else {
el.append(child);
}
return el;
});
return el;
});
const insertBefore = utils.curry((newElement, el) => {
if (is.string(newElement)) {
el.insertAdjacentHTML('beforebegin', newElement);
} else {
el.insertAdjacentElement('beforebegin', newElement);
}
var prepend = utils.curry(function (child, el) {
if (is.string(child)) {
el.insertAdjacentHTML('afterbegin', child);
} else {
el.prepend(child);
}
return el;
});
return el;
});
const insertAfter = utils.curry((newElement, el) => {
if (is.string(newElement)) {
el.insertAdjacentHTML('afterend', newElement);
} else {
el.insertAdjacentElement('afterend', newElement);
}
var insertBefore = utils.curry(function (newElement, el) {
if (is.string(newElement)) {
el.insertAdjacentHTML('beforebegin', newElement);
} else {
el.insertAdjacentElement('beforebegin', newElement);
}
return el;
});
return el;
});
const wrap = utils.curry((wrapElement, el) => {
if (is.string(wrapElement)) {
wrapElement = parseHTML(wrapElement);
} // compose(append(wrapElement), clone, insertBefore(wrapElement))(el)
var insertAfter = utils.curry(function (newElement, el) {
if (is.string(newElement)) {
el.insertAdjacentHTML('afterend', newElement);
} else {
el.insertAdjacentElement('afterend', newElement);
}
return el;
});
var wrap = utils.curry(function (wrapElement, el) {
if (is.string(wrapElement)) {
wrapElement = parseHTML(wrapElement);
}
// compose(append(wrapElement), clone, insertBefore(wrapElement))(el)
insertBefore(wrapElement, el);
remove(el);
append(el, wrapElement);
return wrapElement;
insertBefore(wrapElement, el);
remove(el);
append(el, wrapElement);
return wrapElement;
});
const wrapInner = (newElement, wrap) => {
if (is.string(newElement)) {
newElement = parseHTML(newElement);
}
newElement.innerHTML = wrap.innerHTML;
wrap.innerHTML = '';
wrap.append(newElement);
return wrap;
};
const wrapAll = (wrapElement, elementList) => {
insertBefore(wrapElement, elementList[0]);
wrapElement.append(...elementList);
return wrapElement;
};
const unwrap = el => {
const parentEl = parent(el);
children(parentEl).forEach(child => {
insertBefore(child, parentEl);
});
parentEl.remove();
return el;
};
const clearChild = el => {
children(el).map(remove);
return el;
};
const parentWith = utils.curry((fn, el) => {
const parentElement = parent(el); // console.log(el, parentElement)
var wrapInner = function wrapInner(newElement, wrap) {
if (is.string(newElement)) {
newElement = parseHTML(newElement);
}
newElement.innerHTML = wrap.innerHTML;
wrap.innerHTML = '';
wrap.append(newElement);
return wrap;
};
if (!parentElement || parentElement === document) {
return false;
}
var wrapAll = function wrapAll(wrapElement, elementList) {
insertBefore(wrapElement, elementList[0]);
wrapElement.append.apply(wrapElement, toConsumableArray(elementList));
return wrapElement;
};
if (fn(parentElement)) {
return parentElement;
}
var unwrap = function unwrap(el) {
var parentEl = parent(el);
children(parentEl).forEach(function (child) {
insertBefore(child, parentEl);
});
parentEl.remove();
return parentWith(fn, parentElement);
});
const clearData = el => {
Object.keys(el).map(name => el.removeAttribute(`data-${name}`));
return el;
};
const contains = utils.curry((el, parent) => parent.contains(el));
const closest = utils.curry((selector, el) => {
if (el.matches(selector)) {
return el;
};
}
var clearChild = function clearChild(el) {
children(el).map(remove);
return el;
};
return parentWith(el => el.matches(selector), el);
});
const nextElementWith = utils.curry((fn, el) => {
const nextElement = next(el);
var parentWith = utils.curry(function (fn, el) {
var parentElement = parent(el);
// console.log(el, parentElement)
if (!parentElement || parentElement === document) {
return false;
}
if (fn(parentElement)) {
return parentElement;
}
return parentWith(fn, parentElement);
});
if (fn(nextElement)) {
return nextElement;
}
var clearData = function clearData(el) {
Object.keys(el).map(function (name) {
return el.removeAttribute('data-' + name);
});
return el;
};
return nextElementWith(fn, nextElement);
}); // == animation == //
var contains = utils.curry(function (el, parent) {
return parent.contains(el);
});
const fade = utils.curry((type, {
duration,
callback
}, element) => {
const isIn = type === 'in';
let opacity = isIn ? 0 : 1;
let start = null;
var closest = utils.curry(function (selector, el) {
if (el.matches(selector)) {
return el;
if (isIn) {
if (element.style.display === 'none') {
element.style.display = 'inline';
}
return parentWith(function (el) {
return el.matches(selector);
}, el);
});
var nextElementWith = utils.curry(function (fn, el) {
var nextElement = next(el);
if (fn(nextElement)) {
return nextElement;
element.style.opacity = opacity;
}
function step(timestamp) {
if (!start) {
start = timestamp;
}
return nextElementWith(fn, nextElement);
});
// == animation == //
const progress = timestamp - start;
const percent = progress / duration;
opacity = isIn ? opacity + percent : opacity - percent;
element.style.opacity = opacity;
var fade = utils.curry(function (type, _ref9, element) {
var duration = _ref9.duration,
callback = _ref9.callback;
var isIn = type === 'in';
var opacity = isIn ? 0 : 1;
var start = null;
if (isIn) {
if (element.style.display === 'none') {
element.style.display = 'inline';
}
element.style.opacity = opacity;
if (opacity <= 0) {
element.style.display = 'none';
}
function step(timestamp) {
if (!start) {
start = timestamp;
}
var progress = timestamp - start;
var percent = progress / duration;
opacity = isIn ? opacity + percent : opacity - percent;
element.style.opacity = opacity;
if (opacity <= 0) {
element.style.display = 'none';
}
if (progress < duration) {
window.requestAnimationFrame(step);
} else if (callback) {
callback();
}
if (progress < duration) {
window.requestAnimationFrame(step);
} else if (callback) {
callback();
}
}
window.requestAnimationFrame(step);
});
window.requestAnimationFrame(step);
});
const fadeOut = fade('out');
const fadeIn = fade('in');
var fadeOut = fade('out');
var fadeIn = fade('in');
exports.query = query;
exports.queryAll = queryAll;
exports.find = find;
exports.finds = finds;
exports.remove = remove;
exports.html = html;
exports.children = children;
exports.childrenSelect = childrenSelect;
exports.getSiblings = getSiblings;
exports.attrVerify = attrVerify;
exports.childQuery = childQuery;
exports.Each = Each;
exports.parentQuery = parentQuery;
exports.parent = parent;
exports.parseHTML = parseHTML;
exports.setObjData = setObjData;
exports.getObjData = getObjData;
exports.clone = clone;
exports.empty = empty;
exports.prev = prev;
exports.next = next;
exports.attr = attr;
exports.removeAttribute = removeAttribute;
exports.dataset = dataset;
exports.text = text;
exports.append = append;
exports.prepend = prepend;
exports.insertBefore = insertBefore;
exports.insertAfter = insertAfter;
exports.wrap = wrap;
exports.wrapInner = wrapInner;
exports.wrapAll = wrapAll;
exports.unwrap = unwrap;
exports.clearChild = clearChild;
exports.parentWith = parentWith;
exports.clearData = clearData;
exports.contains = contains;
exports.closest = closest;
exports.nextElementWith = nextElementWith;
exports.fade = fade;
exports.fadeOut = fadeOut;
exports.fadeIn = fadeIn;
Object.defineProperty(exports, '__esModule', { value: true });
})));
exports.query = query;
exports.queryAll = queryAll;
exports.find = find;
exports.finds = finds;
exports.remove = remove;
exports.html = html;
exports.children = children;
exports.childrenSelect = childrenSelect;
exports.getSiblings = getSiblings;
exports.attrVerify = attrVerify;
exports.childQuery = childQuery;
exports.Each = Each;
exports.parentQuery = parentQuery;
exports.parent = parent;
exports.parseHTML = parseHTML;
exports.setObjData = setObjData;
exports.getObjData = getObjData;
exports.clone = clone;
exports.empty = empty;
exports.prev = prev;
exports.next = next;
exports.attr = attr;
exports.removeAttribute = removeAttribute;
exports.dataset = dataset;
exports.text = text;
exports.append = append;
exports.prepend = prepend;
exports.insertBefore = insertBefore;
exports.insertAfter = insertAfter;
exports.wrap = wrap;
exports.wrapInner = wrapInner;
exports.wrapAll = wrapAll;
exports.unwrap = unwrap;
exports.clearChild = clearChild;
exports.parentWith = parentWith;
exports.clearData = clearData;
exports.contains = contains;
exports.closest = closest;
exports.nextElementWith = nextElementWith;
exports.fade = fade;
exports.fadeOut = fadeOut;
exports.fadeIn = fadeIn;
{
"name": "@pluginjs/dom",
"main": "dist/dom.js",
"main": "dist/dom.umd.js",
"module": "dist/dom.esm.js",
"dev-main": "src/main.js",
"source": "src/main.js",
"dependencies": {

@@ -10,7 +10,7 @@ "@pluginjs/is": "^0.2.19",

},
"version": "0.0.15",
"version": "0.5.0",
"description": "A flexible modern dom js plugin.",
"author": "Creation Studio Limited",
"homepage": "https://github.com/pluginjs/plugin.js",
"license": "GPL-v3",
"license": "GPL-3.0",
"files": [

@@ -31,3 +31,28 @@ "dist",

},
"category": "utils"
"category": "utils",
"scripts": {
"build": "plugin build",
"build:js": "plugin script build-js",
"build:scss": "plugin script build-scss",
"test": "jest",
"build:md": "plugin script build-md"
},
"cjs": "dist/dom.cjs.js",
"jest": {
"setupTestFrameworkScriptFile": "jest-extended",
"verbose": true,
"testPathIgnorePatterns": [
"fixtures"
]
},
"devDependencies": {
"@pluginjs/cli": "^0.5.18",
"babel-jest": "^23.0.1",
"jest": "^23.1.0",
"jest-extended": "^0.7.2",
"rollup": "^0.59.2",
"rollup-plugin-babel": "^4.0.0-beta.4",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-node-resolve": "^3.3.0"
}
}

@@ -57,2 +57,3 @@ import { curry, compose } from '@pluginjs/utils'

}
return false
},

@@ -73,2 +74,3 @@ tagName: element => element.nodeName.toLowerCase() === value,

}
return false
}

@@ -86,3 +88,3 @@ }

if (hasChild(element)) {
Array.from(element.children).map(c => {
Array.from(element.children).forEach(c => {
if (attrVerify(type, value, c)) {

@@ -105,4 +107,4 @@ res.push(c)

export const Each = (obj, callback) => {
let i = 0,
length
let i = 0
let length

@@ -226,3 +228,4 @@ if (is.array(obj)) {

} else {
el.insertAdjacentElement('beforebegin', newElement)
const parentElement = parent(el)
parentElement.insertBefore(newElement, el)
}

@@ -236,3 +239,4 @@ return el

} else {
el.insertAdjacentElement('afterend', newElement)
const parentElement = parent(el)
parentElement.insertBefore(newElement, el.nextElementSibling)
}

@@ -239,0 +243,0 @@ return el

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc