Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@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.7.9 to 0.7.10

609

dist/dom.common.js
/*!
* @pluginjs/dom v0.7.9 (https://pluginjs.com)
* @pluginjs/dom v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var utils = require('@pluginjs/utils');
var is = require('@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 parseHTML = function parseHTML() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
const htmlString = Array.isArray(args[0]) ? args[0].reduce((result, str, index) => result + args[index] + str) : args[0]; // if('content' in document.createElement('template')) {
// const temp = document.createElement('template')
// temp.innerHTML = htmlString
// return temp.content.cloneNode(true)
// } else {
const el = document.createElement('div');
el.innerHTML = htmlString;
if (el.children.length === 1) {
return el.children[0];
}
const fragment = document.createDocumentFragment();
if (el.children.length) {
while (el.children.length > 0) {
fragment.appendChild(el.children[0]);
}
} else {
while (el.childNodes.length > 0) {
fragment.appendChild(el.childNodes[0]);
}
}
return fragment; // }
}; // ----------
// Traversal
// ----------
const query = function query(selector) {
let parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
return parent.querySelector(selector);
};
const queryAll = function queryAll(selector) {
let parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
return Array.from(parent.querySelectorAll(selector));
};
const find = utils.curry((selector, parent) => parent.querySelector(selector));
const findAll = utils.curry((selector, parent) => Array.from(parent.querySelectorAll(selector)));
const has = (selector, parent) => {
if (is.isString(selector)) {
return Boolean(queryAll(selector, parent).length);
}
return parent.contains(selector);
};
const contents = el => {
if (el.tagName === 'IFRAME') {
return [el.contentDocument];
}
return el.childNodes;
};
const children = (selector, el) => {
if (!is.isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
if (!is.isElement(el)) {
return [];
}
if (is.isString(selector)) {
return Array.from(el.children).filter(c => c.matches(selector));
}
return Array.from(el.children);
};
const siblings = (selector, el) => {
if (!is.isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
if (!is.isElement(el)) {
return [];
}
return children(selector, el.parentNode).filter(element => element !== el);
};
const prev = el => el.previousElementSibling;
const next = el => el.nextElementSibling;
const prevWith = utils.curry((fn, el) => {
const prevElement = el.previousElementSibling;
if (!prevElement) {
return null;
}
if (fn(prevElement)) {
return prevElement;
}
return prevWith(fn, prevElement);
});
const nextWith = utils.curry((fn, el) => {
const nextElement = el.nextElementSibling;
if (!nextElement) {
return null;
}
if (fn(nextElement)) {
return nextElement;
}
return nextWith(fn, nextElement);
});
const parent = el => el.parentNode;
const parents = (selector, el) => {
if (!is.isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
const result = [];
let last = el;
while (is.isElement(last) && last.parentNode && last !== document.body.parentNode) {
last = last.parentNode;
if (!selector || selector && last.matches(selector)) {
result.push(last);
}
}
return result;
};
const parentWith = utils.curry((fn, el) => {
const parentElement = el.parentNode;
if (!parentElement || parentElement === document) {
return false;
}
if (fn(parentElement)) {
return parentElement;
}
return parentWith(fn, parentElement);
});
const closest = (selector, el) => {
if (el.matches(selector)) {
return el;
}
return parentWith(el => el.matches(selector), el);
};
const offsetParent = el => {
let offsetParent = el.offsetParent;
while (offsetParent && offsetParent.style.position === 'static') {
offsetParent = offsetParent.offsetParent;
}
return offsetParent || document.documentElement;
};
const scrollParent = el => {
return parentWith(parent => parent.scrollHeight > parent.clientHeight, el);
};
const indexOf = el => {
return [...el.parentElement.children].indexOf(el);
}; // ---------
// Data
// ----------
const dataStore = '__pluginjsData';
const getCachedData = el => {
return el[dataStore] = el[dataStore] || {};
};
const getData = (key, el) => {
if (is.isElement(key) && typeof el === 'undefined') {
el = key;
key = undefined;
}
const cache = getCachedData(el);
if (key) {
if (!(key in cache)) {
let value = el.dataset[key] || el.dataset[utils.camelize(key, false)];
if (value !== undefined) {
try {
value = JSON.parse(value);
} catch (e) {} // eslint-disable-line
cache[key] = value;
}
}
return cache[key];
}
return cache;
};
const setData = (key, value, el) => {
getCachedData(el)[key] = value;
return el;
};
const removeData = (key, el) => {
if (is.isElement(key) && typeof el === 'undefined') {
el = key;
key = undefined;
}
if (typeof key === 'undefined') {
delete el[dataStore];
} else {
delete getCachedData(el)[key];
}
return el;
};
const hasData = el => {
return dataStore in el ? !is.isEmptyObject(el[dataStore]) : false;
};
const data = utils.curryWith((key, value, el) => {
if (is.isElement(value) && typeof el === 'undefined') {
el = value;
value = undefined;
}
if (typeof key === 'string') {
if (typeof value !== 'undefined') {
setData(key, value, el);
} else {
return getData(key, el);
}
} else {
Object.entries(key).forEach((_ref) => {
let _ref2 = _slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return setData(k, v, el);
});
}
return el;
}, is.isElement); // -----------
// Attributes
// -----------
const attr = utils.curryWith((args, value, el) => {
if (is.isElement(value) && typeof el === 'undefined') {
el = value;
value = undefined;
}
if (typeof args === 'string') {
if (typeof value !== 'undefined') {
el.setAttribute(args, value);
} else {
return el.getAttribute(args);
}
} else {
Object.entries(args).forEach((_ref3) => {
let _ref4 = _slicedToArray(_ref3, 2),
key = _ref4[0],
value = _ref4[1];
return el.setAttribute(key, value);
});
}
return el;
}, is.isElement);
const removeAttr = utils.curry((attrs, el) => {
attrs.split(' ').forEach(attr => {
el.removeAttribute(attr);
});
return el;
});
const propMap = {
tabindex: 'tabIndex',
readonly: 'readOnly',
for: 'htmlFor',
class: 'className',
maxlength: 'maxLength',
cellspacing: 'cellSpacing',
cellpadding: 'cellPadding',
rowspan: 'rowSpan',
colspan: 'colSpan',
usemap: 'useMap',
frameborder: 'frameBorder',
contenteditable: 'contentEditable'
};
const prop = utils.curryWith((props, value, el) => {
if (is.isElement(value) && typeof el === 'undefined') {
el = value;
value = undefined;
}
if (typeof props === 'string') {
if (typeof value !== 'undefined') {
el[propMap[props] || props] = value;
} else {
return el[propMap[props] || props];
}
} else {
Object.entries(props).forEach((_ref5) => {
let _ref6 = _slicedToArray(_ref5, 2),
key = _ref6[0],
value = _ref6[1];
el[propMap[key] || key] = value;
});
}
return el;
}, is.isElement);
const removeProp = utils.curry((props, el) => {
props.split(' ').forEach(prop => {
prop = propMap[prop] || prop;
delete el[prop];
});
return el;
}); // --------------
// Manipulation
// --------------
const clone = utils.curry(el => el.cloneNode(true));
const detach = utils.curry(el => {
if (el.parentNode) {
el.parentNode.removeChild(el);
}
return el;
});
const remove = utils.curry(el => el.remove());
const empty = utils.curry(el => {
while (el.lastChild) {
el.removeChild(el.lastChild);
}
return el;
});
const html = utils.curryWith((content, el) => {
if (!is.isString(content) && typeof el === 'undefined') {
el = content;
content = undefined;
}
if (typeof content === 'undefined') {
return el.innerHTML;
}
el.innerHTML = content;
return el;
}, is.isElement);
const text = utils.curryWith((content, el) => {
if (!is.isString(content) && typeof el === 'undefined') {
el = content;
content = undefined;
}
if (typeof content === 'undefined') {
return el.textContent;
}
el.textContent = content;
return el;
}, is.isElement);
const append = utils.curry((child, el) => {
if (is.isString(child)) {
el.insertAdjacentHTML('beforeend', child);
} else {
el.append(child);
}
return el;
});
const appendTo = utils.curry((child, el) => {
if (is.isString(child)) {
child = parseHTML(child);
}
el.append(child);
return child;
});
const prepend = utils.curry((child, el) => {
if (is.isString(child)) {
el.insertAdjacentHTML('afterbegin', child);
} else {
el.prepend(child);
}
return el;
});
const prependTo = utils.curry((child, el) => {
if (is.isString(child)) {
child = parseHTML(child);
}
el.prepend(child);
return child;
});
const before = utils.curry((newElement, el) => {
if (is.isString(newElement)) {
el.insertAdjacentHTML('beforebegin', newElement);
} else {
el.parentNode.insertBefore(newElement, el);
}
return el;
});
const insertBefore = utils.curry((newElement, el) => {
if (is.isString(newElement)) {
newElement = parseHTML(newElement);
}
if (NodeList.prototype.isPrototypeOf(newElement)) {
// eslint-disable-line
newElement.forEach(i => {
el.parentNode.insertBefore(i, el);
});
} else {
el.parentNode.insertBefore(newElement, el);
}
return newElement;
});
const after = utils.curry((newElement, el) => {
if (is.isString(newElement)) {
el.insertAdjacentHTML('afterend', newElement);
} else {
el.parentNode.insertBefore(newElement, el.nextElementSibling);
}
return el;
});
const insertAfter = utils.curry((newElement, el) => {
if (is.isString(newElement)) {
newElement = parseHTML(newElement);
}
if (NodeList.prototype.isPrototypeOf(newElement)) {
// eslint-disable-line
newElement.forEach(i => {
el.parentNode.insertBefore(i, el.nextElementSibling);
});
} else {
el.parentNode.insertBefore(newElement, el.nextElementSibling);
}
return newElement;
});
const wrap = utils.curry((wrapElement, el) => {
if (is.isString(wrapElement)) {
wrapElement = parseHTML(wrapElement);
}
insertBefore(wrapElement, el);
append(el, wrapElement);
return wrapElement;
});
const wrapInner = utils.curry((newElement, el) => {
if (is.isString(newElement)) {
newElement = parseHTML(newElement);
}
newElement.innerHTML = el.innerHTML;
el.innerHTML = '';
el.append(newElement);
return el;
});
const wrapAll = utils.curry((wrapElement, elementList) => {
if (is.isString(wrapElement)) {
wrapElement = parseHTML(wrapElement);
}
insertBefore(wrapElement, elementList[0]);
wrapElement.append(...elementList);
return wrapElement;
});
const unwrap = utils.curryWith((selector, el) => {
if (!is.isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
const parentEl = el.parentNode;
if (!selector || parentEl.matches(selector)) {
children(parentEl).forEach(child => {
insertBefore(child, parentEl);
});
parentEl.remove();
}
return el;
}, is.isElement);
const replace = utils.curry((newContent, el) => {
if (is.isString(newContent)) {
newContent = parseHTML(newContent);
}
el.parentNode.replaceChild(newContent, el);
el.remove();
return newContent;
});
exports.after = after;
exports.append = append;
exports.appendTo = appendTo;
exports.attr = attr;
exports.before = before;
exports.children = children;
exports.clone = clone;
exports.closest = closest;
exports.contents = contents;
exports.data = data;
exports.detach = detach;
exports.empty = empty;
exports.find = find;
exports.findAll = findAll;
exports.getData = getData;
exports.has = has;
exports.hasData = hasData;
exports.html = html;
exports.indexOf = indexOf;
exports.insertAfter = insertAfter;
exports.insertBefore = insertBefore;
exports.next = next;
exports.nextWith = nextWith;
exports.offsetParent = offsetParent;
exports.parent = parent;
exports.parentWith = parentWith;
exports.parents = parents;
exports.parseHTML = parseHTML;
exports.prepend = prepend;
exports.prependTo = prependTo;
exports.prev = prev;
exports.prevWith = prevWith;
exports.prop = prop;
exports.query = query;
exports.queryAll = queryAll;
exports.remove = remove;
exports.removeAttr = removeAttr;
exports.removeData = removeData;
exports.removeProp = removeProp;
exports.replace = replace;
exports.scrollParent = scrollParent;
exports.setData = setData;
exports.siblings = siblings;
exports.text = text;
exports.unwrap = unwrap;
exports.wrap = wrap;
exports.wrapAll = wrapAll;
exports.wrapInner = wrapInner;

4

dist/dom.common.min.js
/*!
* @pluginjs/dom v0.7.9 (https://pluginjs.com)
* @pluginjs/dom v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var utils=require("@pluginjs/utils"),is=require("@pluginjs/is");function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_nonIterableRest()}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArrayLimit(e,t){var r=[],i=!0,n=!1,s=void 0;try{for(var o,a=e[Symbol.iterator]();!(i=(o=a.next()).done)&&(r.push(o.value),!t||r.length!==t);i=!0);}catch(e){n=!0,s=e}finally{try{i||null==a.return||a.return()}finally{if(n)throw s}}return r}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}const parseHTML=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];const i=Array.isArray(t[0])?t[0].reduce((e,r,i)=>e+t[i]+r):t[0],n=document.createElement("div");if(n.innerHTML=i,1===n.children.length)return n.children[0];const s=document.createDocumentFragment();if(n.children.length)for(;n.children.length>0;)s.appendChild(n.children[0]);else for(;n.childNodes.length>0;)s.appendChild(n.childNodes[0]);return s},query=function(e){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:document).querySelector(e)},queryAll=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;return Array.from(t.querySelectorAll(e))},find=utils.curry((e,t)=>t.querySelector(e)),findAll=utils.curry((e,t)=>Array.from(t.querySelectorAll(e))),has=(e,t)=>is.isString(e)?Boolean(queryAll(e,t).length):t.contains(e),contents=e=>"IFRAME"===e.tagName?[e.contentDocument]:e.childNodes,children=(e,t)=>(is.isString(e)||void 0!==t||(t=e,e=void 0),is.isElement(t)?is.isString(e)?Array.from(t.children).filter(t=>t.matches(e)):Array.from(t.children):[]),siblings=(e,t)=>(is.isString(e)||void 0!==t||(t=e,e=void 0),is.isElement(t)?children(e,t.parentNode).filter(e=>e!==t):[]),prev=e=>e.previousElementSibling,next=e=>e.nextElementSibling,prevWith=utils.curry((e,t)=>{const r=t.previousElementSibling;return r?e(r)?r:prevWith(e,r):null}),nextWith=utils.curry((e,t)=>{const r=t.nextElementSibling;return r?e(r)?r:nextWith(e,r):null}),parent=e=>e.parentNode,parents=(e,t)=>{is.isString(e)||void 0!==t||(t=e,e=void 0);const r=[];let i=t;for(;is.isElement(i)&&i.parentNode&&i!==document.body.parentNode;)i=i.parentNode,(!e||e&&i.matches(e))&&r.push(i);return r},parentWith=utils.curry((e,t)=>{const r=t.parentNode;return!(!r||r===document)&&(e(r)?r:parentWith(e,r))}),closest=(e,t)=>t.matches(e)?t:parentWith(t=>t.matches(e),t),offsetParent=e=>{let t=e.offsetParent;for(;t&&"static"===t.style.position;)t=t.offsetParent;return t||document.documentElement},scrollParent=e=>parentWith(e=>e.scrollHeight>e.clientHeight,e),indexOf=e=>[...e.parentElement.children].indexOf(e),dataStore="__pluginjsData",getCachedData=e=>e[dataStore]=e[dataStore]||{},getData=(e,t)=>{is.isElement(e)&&void 0===t&&(t=e,e=void 0);const r=getCachedData(t);if(e){if(!(e in r)){let i=t.dataset[e]||t.dataset[utils.camelize(e,!1)];if(void 0!==i){try{i=JSON.parse(i)}catch(e){}r[e]=i}}return r[e]}return r},setData=(e,t,r)=>(getCachedData(r)[e]=t,r),removeData=(e,t)=>(is.isElement(e)&&void 0===t&&(t=e,e=void 0),void 0===e?delete t[dataStore]:delete getCachedData(t)[e],t),hasData=e=>dataStore in e&&!is.isEmptyObject(e[dataStore]),data=utils.curryWith((e,t,r)=>{if(is.isElement(t)&&void 0===r&&(r=t,t=void 0),"string"==typeof e){if(void 0===t)return getData(e,r);setData(e,t,r)}else Object.entries(e).forEach(e=>{let t=_slicedToArray(e,2),i=t[0],n=t[1];return setData(i,n,r)});return r},is.isElement),attr=utils.curryWith((e,t,r)=>{if(is.isElement(t)&&void 0===r&&(r=t,t=void 0),"string"==typeof e){if(void 0===t)return r.getAttribute(e);r.setAttribute(e,t)}else Object.entries(e).forEach(e=>{let t=_slicedToArray(e,2),i=t[0],n=t[1];return r.setAttribute(i,n)});return r},is.isElement),removeAttr=utils.curry((e,t)=>(e.split(" ").forEach(e=>{t.removeAttribute(e)}),t)),propMap={tabindex:"tabIndex",readonly:"readOnly",for:"htmlFor",class:"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop=utils.curryWith((e,t,r)=>{if(is.isElement(t)&&void 0===r&&(r=t,t=void 0),"string"==typeof e){if(void 0===t)return r[propMap[e]||e];r[propMap[e]||e]=t}else Object.entries(e).forEach(e=>{let t=_slicedToArray(e,2),i=t[0],n=t[1];r[propMap[i]||i]=n});return r},is.isElement),removeProp=utils.curry((e,t)=>(e.split(" ").forEach(e=>{delete t[e=propMap[e]||e]}),t)),clone=utils.curry(e=>e.cloneNode(!0)),detach=utils.curry(e=>(e.parentNode&&e.parentNode.removeChild(e),e)),remove=utils.curry(e=>e.remove()),empty=utils.curry(e=>{for(;e.lastChild;)e.removeChild(e.lastChild);return e}),html=utils.curryWith((e,t)=>(is.isString(e)||void 0!==t||(t=e,e=void 0),void 0===e?t.innerHTML:(t.innerHTML=e,t)),is.isElement),text=utils.curryWith((e,t)=>(is.isString(e)||void 0!==t||(t=e,e=void 0),void 0===e?t.textContent:(t.textContent=e,t)),is.isElement),append=utils.curry((e,t)=>(is.isString(e)?t.insertAdjacentHTML("beforeend",e):t.append(e),t)),appendTo=utils.curry((e,t)=>(is.isString(e)&&(e=parseHTML(e)),t.append(e),e)),prepend=utils.curry((e,t)=>(is.isString(e)?t.insertAdjacentHTML("afterbegin",e):t.prepend(e),t)),prependTo=utils.curry((e,t)=>(is.isString(e)&&(e=parseHTML(e)),t.prepend(e),e)),before=utils.curry((e,t)=>(is.isString(e)?t.insertAdjacentHTML("beforebegin",e):t.parentNode.insertBefore(e,t),t)),insertBefore=utils.curry((e,t)=>(is.isString(e)&&(e=parseHTML(e)),NodeList.prototype.isPrototypeOf(e)?e.forEach(e=>{t.parentNode.insertBefore(e,t)}):t.parentNode.insertBefore(e,t),e)),after=utils.curry((e,t)=>(is.isString(e)?t.insertAdjacentHTML("afterend",e):t.parentNode.insertBefore(e,t.nextElementSibling),t)),insertAfter=utils.curry((e,t)=>(is.isString(e)&&(e=parseHTML(e)),NodeList.prototype.isPrototypeOf(e)?e.forEach(e=>{t.parentNode.insertBefore(e,t.nextElementSibling)}):t.parentNode.insertBefore(e,t.nextElementSibling),e)),wrap=utils.curry((e,t)=>(is.isString(e)&&(e=parseHTML(e)),insertBefore(e,t),append(t,e),e)),wrapInner=utils.curry((e,t)=>(is.isString(e)&&(e=parseHTML(e)),e.innerHTML=t.innerHTML,t.innerHTML="",t.append(e),t)),wrapAll=utils.curry((e,t)=>(is.isString(e)&&(e=parseHTML(e)),insertBefore(e,t[0]),e.append(...t),e)),unwrap=utils.curryWith((e,t)=>{is.isString(e)||void 0!==t||(t=e,e=void 0);const r=t.parentNode;return e&&!r.matches(e)||(children(r).forEach(e=>{insertBefore(e,r)}),r.remove()),t},is.isElement),replace=utils.curry((e,t)=>(is.isString(e)&&(e=parseHTML(e)),t.parentNode.replaceChild(e,t),t.remove(),e));exports.after=after,exports.append=append,exports.appendTo=appendTo,exports.attr=attr,exports.before=before,exports.children=children,exports.clone=clone,exports.closest=closest,exports.contents=contents,exports.data=data,exports.detach=detach,exports.empty=empty,exports.find=find,exports.findAll=findAll,exports.getData=getData,exports.has=has,exports.hasData=hasData,exports.html=html,exports.indexOf=indexOf,exports.insertAfter=insertAfter,exports.insertBefore=insertBefore,exports.next=next,exports.nextWith=nextWith,exports.offsetParent=offsetParent,exports.parent=parent,exports.parentWith=parentWith,exports.parents=parents,exports.parseHTML=parseHTML,exports.prepend=prepend,exports.prependTo=prependTo,exports.prev=prev,exports.prevWith=prevWith,exports.prop=prop,exports.query=query,exports.queryAll=queryAll,exports.remove=remove,exports.removeAttr=removeAttr,exports.removeData=removeData,exports.removeProp=removeProp,exports.replace=replace,exports.scrollParent=scrollParent,exports.setData=setData,exports.siblings=siblings,exports.text=text,exports.unwrap=unwrap,exports.wrap=wrap,exports.wrapAll=wrapAll,exports.wrapInner=wrapInner;
/*!
* @pluginjs/dom v0.7.9 (https://pluginjs.com)
* @pluginjs/dom v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
import { curry, camelize, curryWith } from '@pluginjs/utils';
import { isString, isElement, isEmptyObject } 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 parseHTML = function parseHTML() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
const htmlString = Array.isArray(args[0]) ? args[0].reduce((result, str, index) => result + args[index] + str) : args[0]; // if('content' in document.createElement('template')) {
// const temp = document.createElement('template')
// temp.innerHTML = htmlString
// return temp.content.cloneNode(true)
// } else {
const el = document.createElement('div');
el.innerHTML = htmlString;
if (el.children.length === 1) {
return el.children[0];
}
const fragment = document.createDocumentFragment();
if (el.children.length) {
while (el.children.length > 0) {
fragment.appendChild(el.children[0]);
}
} else {
while (el.childNodes.length > 0) {
fragment.appendChild(el.childNodes[0]);
}
}
return fragment; // }
}; // ----------
// Traversal
// ----------
const query = function query(selector) {
let parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
return parent.querySelector(selector);
};
const queryAll = function queryAll(selector) {
let parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
return Array.from(parent.querySelectorAll(selector));
};
const find = curry((selector, parent) => parent.querySelector(selector));
const findAll = curry((selector, parent) => Array.from(parent.querySelectorAll(selector)));
const has = (selector, parent) => {
if (isString(selector)) {
return Boolean(queryAll(selector, parent).length);
}
return parent.contains(selector);
};
const contents = el => {
if (el.tagName === 'IFRAME') {
return [el.contentDocument];
}
return el.childNodes;
};
const children = (selector, el) => {
if (!isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
if (!isElement(el)) {
return [];
}
if (isString(selector)) {
return Array.from(el.children).filter(c => c.matches(selector));
}
return Array.from(el.children);
};
const siblings = (selector, el) => {
if (!isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
if (!isElement(el)) {
return [];
}
return children(selector, el.parentNode).filter(element => element !== el);
};
const prev = el => el.previousElementSibling;
const next = el => el.nextElementSibling;
const prevWith = curry((fn, el) => {
const prevElement = el.previousElementSibling;
if (!prevElement) {
return null;
}
if (fn(prevElement)) {
return prevElement;
}
return prevWith(fn, prevElement);
});
const nextWith = curry((fn, el) => {
const nextElement = el.nextElementSibling;
if (!nextElement) {
return null;
}
if (fn(nextElement)) {
return nextElement;
}
return nextWith(fn, nextElement);
});
const parent = el => el.parentNode;
const parents = (selector, el) => {
if (!isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
const result = [];
let last = el;
while (isElement(last) && last.parentNode && last !== document.body.parentNode) {
last = last.parentNode;
if (!selector || selector && last.matches(selector)) {
result.push(last);
}
}
return result;
};
const parentWith = curry((fn, el) => {
const parentElement = el.parentNode;
if (!parentElement || parentElement === document) {
return false;
}
if (fn(parentElement)) {
return parentElement;
}
return parentWith(fn, parentElement);
});
const closest = (selector, el) => {
if (el.matches(selector)) {
return el;
}
return parentWith(el => el.matches(selector), el);
};
const offsetParent = el => {
let offsetParent = el.offsetParent;
while (offsetParent && offsetParent.style.position === 'static') {
offsetParent = offsetParent.offsetParent;
}
return offsetParent || document.documentElement;
};
const scrollParent = el => {
return parentWith(parent => parent.scrollHeight > parent.clientHeight, el);
};
const indexOf = el => {
return [...el.parentElement.children].indexOf(el);
}; // ---------
// Data
// ----------
const dataStore = '__pluginjsData';
const getCachedData = el => {
return el[dataStore] = el[dataStore] || {};
};
const getData = (key, el) => {
if (isElement(key) && typeof el === 'undefined') {
el = key;
key = undefined;
}
const cache = getCachedData(el);
if (key) {
if (!(key in cache)) {
let value = el.dataset[key] || el.dataset[camelize(key, false)];
if (value !== undefined) {
try {
value = JSON.parse(value);
} catch (e) {} // eslint-disable-line
cache[key] = value;
}
}
return cache[key];
}
return cache;
};
const setData = (key, value, el) => {
getCachedData(el)[key] = value;
return el;
};
const removeData = (key, el) => {
if (isElement(key) && typeof el === 'undefined') {
el = key;
key = undefined;
}
if (typeof key === 'undefined') {
delete el[dataStore];
} else {
delete getCachedData(el)[key];
}
return el;
};
const hasData = el => {
return dataStore in el ? !isEmptyObject(el[dataStore]) : false;
};
const data = curryWith((key, value, el) => {
if (isElement(value) && typeof el === 'undefined') {
el = value;
value = undefined;
}
if (typeof key === 'string') {
if (typeof value !== 'undefined') {
setData(key, value, el);
} else {
return getData(key, el);
}
} else {
Object.entries(key).forEach((_ref) => {
let _ref2 = _slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return setData(k, v, el);
});
}
return el;
}, isElement); // -----------
// Attributes
// -----------
const attr = curryWith((args, value, el) => {
if (isElement(value) && typeof el === 'undefined') {
el = value;
value = undefined;
}
if (typeof args === 'string') {
if (typeof value !== 'undefined') {
el.setAttribute(args, value);
} else {
return el.getAttribute(args);
}
} else {
Object.entries(args).forEach((_ref3) => {
let _ref4 = _slicedToArray(_ref3, 2),
key = _ref4[0],
value = _ref4[1];
return el.setAttribute(key, value);
});
}
return el;
}, isElement);
const removeAttr = curry((attrs, el) => {
attrs.split(' ').forEach(attr => {
el.removeAttribute(attr);
});
return el;
});
const propMap = {
tabindex: 'tabIndex',
readonly: 'readOnly',
for: 'htmlFor',
class: 'className',
maxlength: 'maxLength',
cellspacing: 'cellSpacing',
cellpadding: 'cellPadding',
rowspan: 'rowSpan',
colspan: 'colSpan',
usemap: 'useMap',
frameborder: 'frameBorder',
contenteditable: 'contentEditable'
};
const prop = curryWith((props, value, el) => {
if (isElement(value) && typeof el === 'undefined') {
el = value;
value = undefined;
}
if (typeof props === 'string') {
if (typeof value !== 'undefined') {
el[propMap[props] || props] = value;
} else {
return el[propMap[props] || props];
}
} else {
Object.entries(props).forEach((_ref5) => {
let _ref6 = _slicedToArray(_ref5, 2),
key = _ref6[0],
value = _ref6[1];
el[propMap[key] || key] = value;
});
}
return el;
}, isElement);
const removeProp = curry((props, el) => {
props.split(' ').forEach(prop => {
prop = propMap[prop] || prop;
delete el[prop];
});
return el;
}); // --------------
// Manipulation
// --------------
const clone = curry(el => el.cloneNode(true));
const detach = curry(el => {
if (el.parentNode) {
el.parentNode.removeChild(el);
}
return el;
});
const remove = curry(el => el.remove());
const empty = curry(el => {
while (el.lastChild) {
el.removeChild(el.lastChild);
}
return el;
});
const html = curryWith((content, el) => {
if (!isString(content) && typeof el === 'undefined') {
el = content;
content = undefined;
}
if (typeof content === 'undefined') {
return el.innerHTML;
}
el.innerHTML = content;
return el;
}, isElement);
const text = curryWith((content, el) => {
if (!isString(content) && typeof el === 'undefined') {
el = content;
content = undefined;
}
if (typeof content === 'undefined') {
return el.textContent;
}
el.textContent = content;
return el;
}, isElement);
const append = curry((child, el) => {
if (isString(child)) {
el.insertAdjacentHTML('beforeend', child);
} else {
el.append(child);
}
return el;
});
const appendTo = curry((child, el) => {
if (isString(child)) {
child = parseHTML(child);
}
el.append(child);
return child;
});
const prepend = curry((child, el) => {
if (isString(child)) {
el.insertAdjacentHTML('afterbegin', child);
} else {
el.prepend(child);
}
return el;
});
const prependTo = curry((child, el) => {
if (isString(child)) {
child = parseHTML(child);
}
el.prepend(child);
return child;
});
const before = curry((newElement, el) => {
if (isString(newElement)) {
el.insertAdjacentHTML('beforebegin', newElement);
} else {
el.parentNode.insertBefore(newElement, el);
}
return el;
});
const insertBefore = curry((newElement, el) => {
if (isString(newElement)) {
newElement = parseHTML(newElement);
}
if (NodeList.prototype.isPrototypeOf(newElement)) {
// eslint-disable-line
newElement.forEach(i => {
el.parentNode.insertBefore(i, el);
});
} else {
el.parentNode.insertBefore(newElement, el);
}
return newElement;
});
const after = curry((newElement, el) => {
if (isString(newElement)) {
el.insertAdjacentHTML('afterend', newElement);
} else {
el.parentNode.insertBefore(newElement, el.nextElementSibling);
}
return el;
});
const insertAfter = curry((newElement, el) => {
if (isString(newElement)) {
newElement = parseHTML(newElement);
}
if (NodeList.prototype.isPrototypeOf(newElement)) {
// eslint-disable-line
newElement.forEach(i => {
el.parentNode.insertBefore(i, el.nextElementSibling);
});
} else {
el.parentNode.insertBefore(newElement, el.nextElementSibling);
}
return newElement;
});
const wrap = curry((wrapElement, el) => {
if (isString(wrapElement)) {
wrapElement = parseHTML(wrapElement);
}
insertBefore(wrapElement, el);
append(el, wrapElement);
return wrapElement;
});
const wrapInner = curry((newElement, el) => {
if (isString(newElement)) {
newElement = parseHTML(newElement);
}
newElement.innerHTML = el.innerHTML;
el.innerHTML = '';
el.append(newElement);
return el;
});
const wrapAll = curry((wrapElement, elementList) => {
if (isString(wrapElement)) {
wrapElement = parseHTML(wrapElement);
}
insertBefore(wrapElement, elementList[0]);
wrapElement.append(...elementList);
return wrapElement;
});
const unwrap = curryWith((selector, el) => {
if (!isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
const parentEl = el.parentNode;
if (!selector || parentEl.matches(selector)) {
children(parentEl).forEach(child => {
insertBefore(child, parentEl);
});
parentEl.remove();
}
return el;
}, isElement);
const replace = curry((newContent, el) => {
if (isString(newContent)) {
newContent = parseHTML(newContent);
}
el.parentNode.replaceChild(newContent, el);
el.remove();
return newContent;
});
export { after, append, appendTo, attr, before, children, clone, closest, contents, data, detach, empty, find, findAll, getData, has, hasData, html, indexOf, insertAfter, insertBefore, next, nextWith, offsetParent, parent, parentWith, parents, parseHTML, prepend, prependTo, prev, prevWith, prop, query, queryAll, remove, removeAttr, removeData, removeProp, replace, scrollParent, setData, siblings, text, unwrap, wrap, wrapAll, wrapInner };
/*!
* @pluginjs/dom v0.7.9 (https://pluginjs.com)
* @pluginjs/dom v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
import{curry as e,camelize as t,curryWith as r}from"@pluginjs/utils";import{isString as n,isElement as o,isEmptyObject as i}from"@pluginjs/is";function d(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var d,l=e[Symbol.iterator]();!(n=(d=l.next()).done)&&(r.push(d.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==l.return||l.return()}finally{if(o)throw i}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}const l=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];const n=Array.isArray(t[0])?t[0].reduce((e,r,n)=>e+t[n]+r):t[0],o=document.createElement("div");if(o.innerHTML=n,1===o.children.length)return o.children[0];const i=document.createDocumentFragment();if(o.children.length)for(;o.children.length>0;)i.appendChild(o.children[0]);else for(;o.childNodes.length>0;)i.appendChild(o.childNodes[0]);return i},a=function(e){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:document).querySelector(e)},c=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;return Array.from(t.querySelectorAll(e))},s=e((e,t)=>t.querySelector(e)),f=e((e,t)=>Array.from(t.querySelectorAll(e))),p=(e,t)=>n(e)?Boolean(c(e,t).length):t.contains(e),u=e=>"IFRAME"===e.tagName?[e.contentDocument]:e.childNodes,h=(e,t)=>(n(e)||void 0!==t||(t=e,e=void 0),o(t)?n(e)?Array.from(t.children).filter(t=>t.matches(e)):Array.from(t.children):[]),m=(e,t)=>(n(e)||void 0!==t||(t=e,e=void 0),o(t)?h(e,t.parentNode).filter(e=>e!==t):[]),v=e=>e.previousElementSibling,g=e=>e.nextElementSibling,y=e((e,t)=>{const r=t.previousElementSibling;return r?e(r)?r:y(e,r):null}),b=e((e,t)=>{const r=t.nextElementSibling;return r?e(r)?r:b(e,r):null}),N=e=>e.parentNode,E=(e,t)=>{n(e)||void 0!==t||(t=e,e=void 0);const r=[];let i=t;for(;o(i)&&i.parentNode&&i!==document.body.parentNode;)i=i.parentNode,(!e||e&&i.matches(e))&&r.push(i);return r},A=e((e,t)=>{const r=t.parentNode;return!(!r||r===document)&&(e(r)?r:A(e,r))}),S=(e,t)=>t.matches(e)?t:A(t=>t.matches(e),t),x=e=>{let t=e.offsetParent;for(;t&&"static"===t.style.position;)t=t.offsetParent;return t||document.documentElement},L=e=>A(e=>e.scrollHeight>e.clientHeight,e),H=e=>[...e.parentElement.children].indexOf(e),M="__pluginjsData",T=e=>e[M]=e[M]||{},j=(e,r)=>{o(e)&&void 0===r&&(r=e,e=void 0);const n=T(r);if(e){if(!(e in n)){let o=r.dataset[e]||r.dataset[t(e,!1)];if(void 0!==o){try{o=JSON.parse(o)}catch(e){}n[e]=o}}return n[e]}return n},C=(e,t,r)=>(T(r)[e]=t,r),B=(e,t)=>(o(e)&&void 0===t&&(t=e,e=void 0),void 0===e?delete t[M]:delete T(t)[e],t),O=e=>M in e&&!i(e[M]),w=r((e,t,r)=>{if(o(t)&&void 0===r&&(r=t,t=void 0),"string"==typeof e){if(void 0===t)return j(e,r);C(e,t,r)}else Object.entries(e).forEach(e=>{let t=d(e,2),n=t[0],o=t[1];return C(n,o,r)});return r},o),P=r((e,t,r)=>{if(o(t)&&void 0===r&&(r=t,t=void 0),"string"==typeof e){if(void 0===t)return r.getAttribute(e);r.setAttribute(e,t)}else Object.entries(e).forEach(e=>{let t=d(e,2),n=t[0],o=t[1];return r.setAttribute(n,o)});return r},o),q=e((e,t)=>(e.split(" ").forEach(e=>{t.removeAttribute(e)}),t)),D={tabindex:"tabIndex",readonly:"readOnly",for:"htmlFor",class:"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},F=r((e,t,r)=>{if(o(t)&&void 0===r&&(r=t,t=void 0),"string"==typeof e){if(void 0===t)return r[D[e]||e];r[D[e]||e]=t}else Object.entries(e).forEach(e=>{let t=d(e,2),n=t[0],o=t[1];r[D[n]||n]=o});return r},o),I=e((e,t)=>(e.split(" ").forEach(e=>{delete t[e=D[e]||e]}),t)),_=e(e=>e.cloneNode(!0)),J=e(e=>(e.parentNode&&e.parentNode.removeChild(e),e)),R=e(e=>e.remove()),k=e(e=>{for(;e.lastChild;)e.removeChild(e.lastChild);return e}),z=r((e,t)=>(n(e)||void 0!==t||(t=e,e=void 0),void 0===e?t.innerHTML:(t.innerHTML=e,t)),o),G=r((e,t)=>(n(e)||void 0!==t||(t=e,e=void 0),void 0===e?t.textContent:(t.textContent=e,t)),o),K=e((e,t)=>(n(e)?t.insertAdjacentHTML("beforeend",e):t.append(e),t)),Q=e((e,t)=>(n(e)&&(e=l(e)),t.append(e),e)),U=e((e,t)=>(n(e)?t.insertAdjacentHTML("afterbegin",e):t.prepend(e),t)),V=e((e,t)=>(n(e)&&(e=l(e)),t.prepend(e),e)),W=e((e,t)=>(n(e)?t.insertAdjacentHTML("beforebegin",e):t.parentNode.insertBefore(e,t),t)),X=e((e,t)=>(n(e)&&(e=l(e)),NodeList.prototype.isPrototypeOf(e)?e.forEach(e=>{t.parentNode.insertBefore(e,t)}):t.parentNode.insertBefore(e,t),e)),Y=e((e,t)=>(n(e)?t.insertAdjacentHTML("afterend",e):t.parentNode.insertBefore(e,t.nextElementSibling),t)),Z=e((e,t)=>(n(e)&&(e=l(e)),NodeList.prototype.isPrototypeOf(e)?e.forEach(e=>{t.parentNode.insertBefore(e,t.nextElementSibling)}):t.parentNode.insertBefore(e,t.nextElementSibling),e)),$=e((e,t)=>(n(e)&&(e=l(e)),X(e,t),K(t,e),e)),ee=e((e,t)=>(n(e)&&(e=l(e)),e.innerHTML=t.innerHTML,t.innerHTML="",t.append(e),t)),te=e((e,t)=>(n(e)&&(e=l(e)),X(e,t[0]),e.append(...t),e)),re=r((e,t)=>{n(e)||void 0!==t||(t=e,e=void 0);const r=t.parentNode;return e&&!r.matches(e)||(h(r).forEach(e=>{X(e,r)}),r.remove()),t},o),ne=e((e,t)=>(n(e)&&(e=l(e)),t.parentNode.replaceChild(e,t),t.remove(),e));export{Y as after,K as append,Q as appendTo,P as attr,W as before,h as children,_ as clone,S as closest,u as contents,w as data,J as detach,k as empty,s as find,f as findAll,j as getData,p as has,O as hasData,z as html,H as indexOf,Z as insertAfter,X as insertBefore,g as next,b as nextWith,x as offsetParent,N as parent,A as parentWith,E as parents,l as parseHTML,U as prepend,V as prependTo,v as prev,y as prevWith,F as prop,a as query,c as queryAll,R as remove,q as removeAttr,B as removeData,I as removeProp,ne as replace,L as scrollParent,C as setData,m as siblings,G as text,re as unwrap,$ as wrap,te as wrapAll,ee as wrapInner};
/*!
* @pluginjs/dom v0.7.9 (https://pluginjs.com)
* @pluginjs/dom v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
(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) :
(global = global || self, factory(global['@pluginjs/dom'] = {}, global['@pluginjs/utils'], global['@pluginjs/is']));
}(this, function (exports, utils, is) { 'use strict';
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
}
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}
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 _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
var parseHTML = function parseHTML() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var htmlString = Array.isArray(args[0]) ? args[0].reduce(function (result, str, index) {
return result + args[index] + str;
}) : args[0]; // if('content' in document.createElement('template')) {
// const temp = document.createElement('template')
// temp.innerHTML = htmlString
// return temp.content.cloneNode(true)
// } else {
var el = document.createElement('div');
el.innerHTML = htmlString;
if (el.children.length === 1) {
return el.children[0];
}
var fragment = document.createDocumentFragment();
if (el.children.length) {
while (el.children.length > 0) {
fragment.appendChild(el.children[0]);
}
} else {
while (el.childNodes.length > 0) {
fragment.appendChild(el.childNodes[0]);
}
}
return fragment; // }
}; // ----------
// Traversal
// ----------
var query = function query(selector) {
var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
return parent.querySelector(selector);
};
var queryAll = function queryAll(selector) {
var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
return Array.from(parent.querySelectorAll(selector));
};
var find = utils.curry(function (selector, parent) {
return parent.querySelector(selector);
});
var findAll = utils.curry(function (selector, parent) {
return Array.from(parent.querySelectorAll(selector));
});
var has = function has(selector, parent) {
if (is.isString(selector)) {
return Boolean(queryAll(selector, parent).length);
}
return parent.contains(selector);
};
var contents = function contents(el) {
if (el.tagName === 'IFRAME') {
return [el.contentDocument];
}
return el.childNodes;
};
var children = function children(selector, el) {
if (!is.isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
if (!is.isElement(el)) {
return [];
}
if (is.isString(selector)) {
return Array.from(el.children).filter(function (c) {
return c.matches(selector);
});
}
return Array.from(el.children);
};
var siblings = function siblings(selector, el) {
if (!is.isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
if (!is.isElement(el)) {
return [];
}
return children(selector, el.parentNode).filter(function (element) {
return element !== el;
});
};
var prev = function prev(el) {
return el.previousElementSibling;
};
var next = function next(el) {
return el.nextElementSibling;
};
var prevWith = utils.curry(function (fn, el) {
var prevElement = el.previousElementSibling;
if (!prevElement) {
return null;
}
if (fn(prevElement)) {
return prevElement;
}
return prevWith(fn, prevElement);
});
var nextWith = utils.curry(function (fn, el) {
var nextElement = el.nextElementSibling;
if (!nextElement) {
return null;
}
if (fn(nextElement)) {
return nextElement;
}
return nextWith(fn, nextElement);
});
var parent = function parent(el) {
return el.parentNode;
};
var parents = function parents(selector, el) {
if (!is.isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
var result = [];
var last = el;
while (is.isElement(last) && last.parentNode && last !== document.body.parentNode) {
last = last.parentNode;
if (!selector || selector && last.matches(selector)) {
result.push(last);
}
}
return result;
};
var parentWith = utils.curry(function (fn, el) {
var parentElement = el.parentNode;
if (!parentElement || parentElement === document) {
return false;
}
if (fn(parentElement)) {
return parentElement;
}
return parentWith(fn, parentElement);
});
var closest = function closest(selector, el) {
if (el.matches(selector)) {
return el;
}
return parentWith(function (el) {
return el.matches(selector);
}, el);
};
var offsetParent = function offsetParent(el) {
var offsetParent = el.offsetParent;
while (offsetParent && offsetParent.style.position === 'static') {
offsetParent = offsetParent.offsetParent;
}
return offsetParent || document.documentElement;
};
var scrollParent = function scrollParent(el) {
return parentWith(function (parent) {
return parent.scrollHeight > parent.clientHeight;
}, el);
};
var indexOf = function indexOf(el) {
return _toConsumableArray(el.parentElement.children).indexOf(el);
}; // ---------
// Data
// ----------
var dataStore = '__pluginjsData';
var getCachedData = function getCachedData(el) {
return el[dataStore] = el[dataStore] || {};
};
var getData = function getData(key, el) {
if (is.isElement(key) && typeof el === 'undefined') {
el = key;
key = undefined;
}
var cache = getCachedData(el);
if (key) {
if (!(key in cache)) {
var value = el.dataset[key] || el.dataset[utils.camelize(key, false)];
if (value !== undefined) {
try {
value = JSON.parse(value);
} catch (e) {} // eslint-disable-line
cache[key] = value;
}
}
return cache[key];
}
return cache;
};
var setData = function setData(key, value, el) {
getCachedData(el)[key] = value;
return el;
};
var removeData = function removeData(key, el) {
if (is.isElement(key) && typeof el === 'undefined') {
el = key;
key = undefined;
}
if (typeof key === 'undefined') {
delete el[dataStore];
} else {
delete getCachedData(el)[key];
}
return el;
};
var hasData = function hasData(el) {
return dataStore in el ? !is.isEmptyObject(el[dataStore]) : false;
};
var data = utils.curryWith(function (key, value, el) {
if (is.isElement(value) && typeof el === 'undefined') {
el = value;
value = undefined;
}
if (typeof key === 'string') {
if (typeof value !== 'undefined') {
setData(key, value, el);
} else {
return getData(key, el);
}
} else {
Object.entries(key).forEach(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return setData(k, v, el);
});
}
return el;
}, is.isElement); // -----------
// Attributes
// -----------
var attr = utils.curryWith(function (args, value, el) {
if (is.isElement(value) && typeof el === 'undefined') {
el = value;
value = undefined;
}
if (typeof args === 'string') {
if (typeof value !== 'undefined') {
el.setAttribute(args, value);
} else {
return el.getAttribute(args);
}
} else {
Object.entries(args).forEach(function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
key = _ref4[0],
value = _ref4[1];
return el.setAttribute(key, value);
});
}
return el;
}, is.isElement);
var removeAttr = utils.curry(function (attrs, el) {
attrs.split(' ').forEach(function (attr) {
el.removeAttribute(attr);
});
return el;
});
var propMap = {
tabindex: 'tabIndex',
readonly: 'readOnly',
for: 'htmlFor',
class: 'className',
maxlength: 'maxLength',
cellspacing: 'cellSpacing',
cellpadding: 'cellPadding',
rowspan: 'rowSpan',
colspan: 'colSpan',
usemap: 'useMap',
frameborder: 'frameBorder',
contenteditable: 'contentEditable'
};
var prop = utils.curryWith(function (props, value, el) {
if (is.isElement(value) && typeof el === 'undefined') {
el = value;
value = undefined;
}
if (typeof props === 'string') {
if (typeof value !== 'undefined') {
el[propMap[props] || props] = value;
} else {
return el[propMap[props] || props];
}
} else {
Object.entries(props).forEach(function (_ref5) {
var _ref6 = _slicedToArray(_ref5, 2),
key = _ref6[0],
value = _ref6[1];
el[propMap[key] || key] = value;
});
}
return el;
}, is.isElement);
var removeProp = utils.curry(function (props, el) {
props.split(' ').forEach(function (prop) {
prop = propMap[prop] || prop;
delete el[prop];
});
return el;
}); // --------------
// Manipulation
// --------------
var clone = utils.curry(function (el) {
return el.cloneNode(true);
});
var detach = utils.curry(function (el) {
if (el.parentNode) {
el.parentNode.removeChild(el);
}
return el;
});
var remove = utils.curry(function (el) {
return el.remove();
});
var empty = utils.curry(function (el) {
while (el.lastChild) {
el.removeChild(el.lastChild);
}
return el;
});
var html = utils.curryWith(function (content, el) {
if (!is.isString(content) && typeof el === 'undefined') {
el = content;
content = undefined;
}
if (typeof content === 'undefined') {
return el.innerHTML;
}
el.innerHTML = content;
return el;
}, is.isElement);
var text = utils.curryWith(function (content, el) {
if (!is.isString(content) && typeof el === 'undefined') {
el = content;
content = undefined;
}
if (typeof content === 'undefined') {
return el.textContent;
}
el.textContent = content;
return el;
}, is.isElement);
var append = utils.curry(function (child, el) {
if (is.isString(child)) {
el.insertAdjacentHTML('beforeend', child);
} else {
el.append(child);
}
return el;
});
var appendTo = utils.curry(function (child, el) {
if (is.isString(child)) {
child = parseHTML(child);
}
el.append(child);
return child;
});
var prepend = utils.curry(function (child, el) {
if (is.isString(child)) {
el.insertAdjacentHTML('afterbegin', child);
} else {
el.prepend(child);
}
return el;
});
var prependTo = utils.curry(function (child, el) {
if (is.isString(child)) {
child = parseHTML(child);
}
el.prepend(child);
return child;
});
var before = utils.curry(function (newElement, el) {
if (is.isString(newElement)) {
el.insertAdjacentHTML('beforebegin', newElement);
} else {
el.parentNode.insertBefore(newElement, el);
}
return el;
});
var insertBefore = utils.curry(function (newElement, el) {
if (is.isString(newElement)) {
newElement = parseHTML(newElement);
}
if (NodeList.prototype.isPrototypeOf(newElement)) {
// eslint-disable-line
newElement.forEach(function (i) {
el.parentNode.insertBefore(i, el);
});
} else {
el.parentNode.insertBefore(newElement, el);
}
return newElement;
});
var after = utils.curry(function (newElement, el) {
if (is.isString(newElement)) {
el.insertAdjacentHTML('afterend', newElement);
} else {
el.parentNode.insertBefore(newElement, el.nextElementSibling);
}
return el;
});
var insertAfter = utils.curry(function (newElement, el) {
if (is.isString(newElement)) {
newElement = parseHTML(newElement);
}
if (NodeList.prototype.isPrototypeOf(newElement)) {
// eslint-disable-line
newElement.forEach(function (i) {
el.parentNode.insertBefore(i, el.nextElementSibling);
});
} else {
el.parentNode.insertBefore(newElement, el.nextElementSibling);
}
return newElement;
});
var wrap = utils.curry(function (wrapElement, el) {
if (is.isString(wrapElement)) {
wrapElement = parseHTML(wrapElement);
}
insertBefore(wrapElement, el);
append(el, wrapElement);
return wrapElement;
});
var wrapInner = utils.curry(function (newElement, el) {
if (is.isString(newElement)) {
newElement = parseHTML(newElement);
}
newElement.innerHTML = el.innerHTML;
el.innerHTML = '';
el.append(newElement);
return el;
});
var wrapAll = utils.curry(function (wrapElement, elementList) {
var _wrapElement;
if (is.isString(wrapElement)) {
wrapElement = parseHTML(wrapElement);
}
insertBefore(wrapElement, elementList[0]);
(_wrapElement = wrapElement).append.apply(_wrapElement, _toConsumableArray(elementList));
return wrapElement;
});
var unwrap = utils.curryWith(function (selector, el) {
if (!is.isString(selector) && typeof el === 'undefined') {
el = selector;
selector = undefined;
}
var parentEl = el.parentNode;
if (!selector || parentEl.matches(selector)) {
children(parentEl).forEach(function (child) {
insertBefore(child, parentEl);
});
parentEl.remove();
}
return el;
}, is.isElement);
var replace = utils.curry(function (newContent, el) {
if (is.isString(newContent)) {
newContent = parseHTML(newContent);
}
el.parentNode.replaceChild(newContent, el);
el.remove();
return newContent;
});
exports.after = after;
exports.append = append;
exports.appendTo = appendTo;
exports.attr = attr;
exports.before = before;
exports.children = children;
exports.clone = clone;
exports.closest = closest;
exports.contents = contents;
exports.data = data;
exports.detach = detach;
exports.empty = empty;
exports.find = find;
exports.findAll = findAll;
exports.getData = getData;
exports.has = has;
exports.hasData = hasData;
exports.html = html;
exports.indexOf = indexOf;
exports.insertAfter = insertAfter;
exports.insertBefore = insertBefore;
exports.next = next;
exports.nextWith = nextWith;
exports.offsetParent = offsetParent;
exports.parent = parent;
exports.parentWith = parentWith;
exports.parents = parents;
exports.parseHTML = parseHTML;
exports.prepend = prepend;
exports.prependTo = prependTo;
exports.prev = prev;
exports.prevWith = prevWith;
exports.prop = prop;
exports.query = query;
exports.queryAll = queryAll;
exports.remove = remove;
exports.removeAttr = removeAttr;
exports.removeData = removeData;
exports.removeProp = removeProp;
exports.replace = replace;
exports.scrollParent = scrollParent;
exports.setData = setData;
exports.siblings = siblings;
exports.text = text;
exports.unwrap = unwrap;
exports.wrap = wrap;
exports.wrapAll = wrapAll;
exports.wrapInner = wrapInner;
Object.defineProperty(exports, '__esModule', { value: true });
}));
/*!
* @pluginjs/dom v0.7.9 (https://pluginjs.com)
* @pluginjs/dom v0.7.10 (https://pluginjs.com)
* Copyright 2019 Creation Studio Limited
* Released under the GPL-3.0 License.
*/
undefined
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@pluginjs/utils"),require("@pluginjs/is")):"function"==typeof define&&define.amd?define(["exports","@pluginjs/utils","@pluginjs/is"],n):n((e=e||self)["@pluginjs/dom"]={},e["@pluginjs/utils"],e["@pluginjs/is"])}(this,function(e,n,r){"use strict";function t(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var r=[],t=!0,i=!1,o=void 0;try{for(var u,c=e[Symbol.iterator]();!(t=(u=c.next()).done)&&(r.push(u.value),!n||r.length!==n);t=!0);}catch(e){i=!0,o=e}finally{try{t||null==c.return||c.return()}finally{if(i)throw o}}return r}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function i(e){return function(e){if(Array.isArray(e)){for(var n=0,r=new Array(e.length);n<e.length;n++)r[n]=e[n];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var o=function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];var t=Array.isArray(n[0])?n[0].reduce(function(e,r,t){return e+n[t]+r}):n[0],i=document.createElement("div");if(i.innerHTML=t,1===i.children.length)return i.children[0];var o=document.createDocumentFragment();if(i.children.length)for(;i.children.length>0;)o.appendChild(i.children[0]);else for(;i.childNodes.length>0;)o.appendChild(i.childNodes[0]);return o},u=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;return Array.from(n.querySelectorAll(e))},c=n.curry(function(e,n){return n.querySelector(e)}),a=n.curry(function(e,n){return Array.from(n.querySelectorAll(e))}),l=function(e,n){return r.isString(e)||void 0!==n||(n=e,e=void 0),r.isElement(n)?r.isString(e)?Array.from(n.children).filter(function(n){return n.matches(e)}):Array.from(n.children):[]},f=n.curry(function(e,n){var r=n.previousElementSibling;return r?e(r)?r:f(e,r):null}),d=n.curry(function(e,n){var r=n.nextElementSibling;return r?e(r)?r:d(e,r):null}),s=n.curry(function(e,n){var r=n.parentNode;return!(!r||r===document)&&(e(r)?r:s(e,r))}),p="__pluginjsData",y=function(e){return e[p]=e[p]||{}},m=function(e,t){r.isElement(e)&&void 0===t&&(t=e,e=void 0);var i=y(t);if(e){if(!(e in i)){var o=t.dataset[e]||t.dataset[n.camelize(e,!1)];if(void 0!==o){try{o=JSON.parse(o)}catch(e){}i[e]=o}}return i[e]}return i},v=function(e,n,r){return y(r)[e]=n,r},h=n.curryWith(function(e,n,i){if(r.isElement(n)&&void 0===i&&(i=n,n=void 0),"string"==typeof e){if(void 0===n)return m(e,i);v(e,n,i)}else Object.entries(e).forEach(function(e){var n=t(e,2),r=n[0],o=n[1];return v(r,o,i)});return i},r.isElement),g=n.curryWith(function(e,n,i){if(r.isElement(n)&&void 0===i&&(i=n,n=void 0),"string"==typeof e){if(void 0===n)return i.getAttribute(e);i.setAttribute(e,n)}else Object.entries(e).forEach(function(e){var n=t(e,2),r=n[0],o=n[1];return i.setAttribute(r,o)});return i},r.isElement),S=n.curry(function(e,n){return e.split(" ").forEach(function(e){n.removeAttribute(e)}),n}),E={tabindex:"tabIndex",readonly:"readOnly",for:"htmlFor",class:"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},b=n.curryWith(function(e,n,i){if(r.isElement(n)&&void 0===i&&(i=n,n=void 0),"string"==typeof e){if(void 0===n)return i[E[e]||e];i[E[e]||e]=n}else Object.entries(e).forEach(function(e){var n=t(e,2),r=n[0],o=n[1];i[E[r]||r]=o});return i},r.isElement),A=n.curry(function(e,n){return e.split(" ").forEach(function(e){delete n[e=E[e]||e]}),n}),N=n.curry(function(e){return e.cloneNode(!0)}),j=n.curry(function(e){return e.parentNode&&e.parentNode.removeChild(e),e}),x=n.curry(function(e){return e.remove()}),T=n.curry(function(e){for(;e.lastChild;)e.removeChild(e.lastChild);return e}),L=n.curryWith(function(e,n){return r.isString(e)||void 0!==n||(n=e,e=void 0),void 0===e?n.innerHTML:(n.innerHTML=e,n)},r.isElement),M=n.curryWith(function(e,n){return r.isString(e)||void 0!==n||(n=e,e=void 0),void 0===e?n.textContent:(n.textContent=e,n)},r.isElement),w=n.curry(function(e,n){return r.isString(e)?n.insertAdjacentHTML("beforeend",e):n.append(e),n}),H=n.curry(function(e,n){return r.isString(e)&&(e=o(e)),n.append(e),e}),O=n.curry(function(e,n){return r.isString(e)?n.insertAdjacentHTML("afterbegin",e):n.prepend(e),n}),B=n.curry(function(e,n){return r.isString(e)&&(e=o(e)),n.prepend(e),e}),C=n.curry(function(e,n){return r.isString(e)?n.insertAdjacentHTML("beforebegin",e):n.parentNode.insertBefore(e,n),n}),P=n.curry(function(e,n){return r.isString(e)&&(e=o(e)),NodeList.prototype.isPrototypeOf(e)?e.forEach(function(e){n.parentNode.insertBefore(e,n)}):n.parentNode.insertBefore(e,n),e}),W=n.curry(function(e,n){return r.isString(e)?n.insertAdjacentHTML("afterend",e):n.parentNode.insertBefore(e,n.nextElementSibling),n}),q=n.curry(function(e,n){return r.isString(e)&&(e=o(e)),NodeList.prototype.isPrototypeOf(e)?e.forEach(function(e){n.parentNode.insertBefore(e,n.nextElementSibling)}):n.parentNode.insertBefore(e,n.nextElementSibling),e}),D=n.curry(function(e,n){return r.isString(e)&&(e=o(e)),P(e,n),w(n,e),e}),I=n.curry(function(e,n){return r.isString(e)&&(e=o(e)),e.innerHTML=n.innerHTML,n.innerHTML="",n.append(e),n}),_=n.curry(function(e,n){var t;return r.isString(e)&&(e=o(e)),P(e,n[0]),(t=e).append.apply(t,i(n)),e}),F=n.curryWith(function(e,n){r.isString(e)||void 0!==n||(n=e,e=void 0);var t=n.parentNode;return e&&!t.matches(e)||(l(t).forEach(function(e){P(e,t)}),t.remove()),n},r.isElement),z=n.curry(function(e,n){return r.isString(e)&&(e=o(e)),n.parentNode.replaceChild(e,n),n.remove(),e});e.after=W,e.append=w,e.appendTo=H,e.attr=g,e.before=C,e.children=l,e.clone=N,e.closest=function(e,n){return n.matches(e)?n:s(function(n){return n.matches(e)},n)},e.contents=function(e){return"IFRAME"===e.tagName?[e.contentDocument]:e.childNodes},e.data=h,e.detach=j,e.empty=T,e.find=c,e.findAll=a,e.getData=m,e.has=function(e,n){return r.isString(e)?Boolean(u(e,n).length):n.contains(e)},e.hasData=function(e){return p in e&&!r.isEmptyObject(e[p])},e.html=L,e.indexOf=function(e){return i(e.parentElement.children).indexOf(e)},e.insertAfter=q,e.insertBefore=P,e.next=function(e){return e.nextElementSibling},e.nextWith=d,e.offsetParent=function(e){for(var n=e.offsetParent;n&&"static"===n.style.position;)n=n.offsetParent;return n||document.documentElement},e.parent=function(e){return e.parentNode},e.parentWith=s,e.parents=function(e,n){r.isString(e)||void 0!==n||(n=e,e=void 0);for(var t=[],i=n;r.isElement(i)&&i.parentNode&&i!==document.body.parentNode;)i=i.parentNode,(!e||e&&i.matches(e))&&t.push(i);return t},e.parseHTML=o,e.prepend=O,e.prependTo=B,e.prev=function(e){return e.previousElementSibling},e.prevWith=f,e.prop=b,e.query=function(e){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:document).querySelector(e)},e.queryAll=u,e.remove=x,e.removeAttr=S,e.removeData=function(e,n){return r.isElement(e)&&void 0===n&&(n=e,e=void 0),void 0===e?delete n[p]:delete y(n)[e],n},e.removeProp=A,e.replace=z,e.scrollParent=function(e){return s(function(e){return e.scrollHeight>e.clientHeight},e)},e.setData=v,e.siblings=function(e,n){return r.isString(e)||void 0!==n||(n=e,e=void 0),r.isElement(n)?l(e,n.parentNode).filter(function(e){return e!==n}):[]},e.text=M,e.unwrap=F,e.wrap=D,e.wrapAll=_,e.wrapInner=I,Object.defineProperty(e,"__esModule",{value:!0})});

@@ -14,3 +14,3 @@ {

},
"version": "0.7.9",
"version": "0.7.10",
"category": "utils",

@@ -37,9 +37,9 @@ "main": "dist/dom.common.js",

"dependencies": {
"@pluginjs/is": "^0.7.8",
"@pluginjs/utils": "^0.7.9"
"@pluginjs/is": "^0.7.9",
"@pluginjs/utils": "^0.7.10"
},
"devDependencies": {
"@babel/core": "^7.4.4",
"@pluginjs/browserslist-config": "^1.2.5",
"@pluginjs/cli": "^0.7.8",
"@pluginjs/browserslist-config": "^1.2.6",
"@pluginjs/cli": "^0.7.9",
"babel-jest": "*",

@@ -69,3 +69,4 @@ "jest": "*",

"extends @pluginjs/browserslist-config"
]
],
"gitHead": "9ae759d6378f7bd8b952e5c1951dec91a101966e"
}
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