@pluginjs/dom
Advanced tools
Comparing version 0.7.8 to 0.7.9
/*! | ||
* @pluginjs/dom v0.7.8 (https://pluginjs.com) | ||
* @pluginjs/dom v0.7.9 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
'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.parseHTML = parseHTML; | ||
exports.query = query; | ||
exports.queryAll = queryAll; | ||
exports.find = find; | ||
exports.findAll = findAll; | ||
exports.has = has; | ||
exports.contents = contents; | ||
exports.children = children; | ||
exports.siblings = siblings; | ||
exports.prev = prev; | ||
exports.next = next; | ||
exports.prevWith = prevWith; | ||
exports.nextWith = nextWith; | ||
exports.parent = parent; | ||
exports.parents = parents; | ||
exports.parentWith = parentWith; | ||
exports.closest = closest; | ||
exports.offsetParent = offsetParent; | ||
exports.scrollParent = scrollParent; | ||
exports.indexOf = indexOf; | ||
exports.getData = getData; | ||
exports.setData = setData; | ||
exports.removeData = removeData; | ||
exports.hasData = hasData; | ||
exports.data = data; | ||
exports.attr = attr; | ||
exports.removeAttr = removeAttr; | ||
exports.prop = prop; | ||
exports.removeProp = removeProp; | ||
exports.clone = clone; | ||
exports.detach = detach; | ||
exports.remove = remove; | ||
exports.empty = empty; | ||
exports.html = html; | ||
exports.text = text; | ||
exports.append = append; | ||
exports.appendTo = appendTo; | ||
exports.prepend = prepend; | ||
exports.prependTo = prependTo; | ||
exports.before = before; | ||
exports.insertBefore = insertBefore; | ||
exports.after = after; | ||
exports.insertAfter = insertAfter; | ||
exports.wrap = wrap; | ||
exports.wrapInner = wrapInner; | ||
exports.wrapAll = wrapAll; | ||
exports.unwrap = unwrap; | ||
exports.replace = replace; | ||
undefined |
/*! | ||
* @pluginjs/dom v0.7.8 (https://pluginjs.com) | ||
* @pluginjs/dom v0.7.9 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
"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.parseHTML=parseHTML,exports.query=query,exports.queryAll=queryAll,exports.find=find,exports.findAll=findAll,exports.has=has,exports.contents=contents,exports.children=children,exports.siblings=siblings,exports.prev=prev,exports.next=next,exports.prevWith=prevWith,exports.nextWith=nextWith,exports.parent=parent,exports.parents=parents,exports.parentWith=parentWith,exports.closest=closest,exports.offsetParent=offsetParent,exports.scrollParent=scrollParent,exports.indexOf=indexOf,exports.getData=getData,exports.setData=setData,exports.removeData=removeData,exports.hasData=hasData,exports.data=data,exports.attr=attr,exports.removeAttr=removeAttr,exports.prop=prop,exports.removeProp=removeProp,exports.clone=clone,exports.detach=detach,exports.remove=remove,exports.empty=empty,exports.html=html,exports.text=text,exports.append=append,exports.appendTo=appendTo,exports.prepend=prepend,exports.prependTo=prependTo,exports.before=before,exports.insertBefore=insertBefore,exports.after=after,exports.insertAfter=insertAfter,exports.wrap=wrap,exports.wrapInner=wrapInner,exports.wrapAll=wrapAll,exports.unwrap=unwrap,exports.replace=replace; | ||
undefined |
/*! | ||
* @pluginjs/dom v0.7.8 (https://pluginjs.com) | ||
* @pluginjs/dom v0.7.9 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
import { curry, curryWith, camelize } 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 { parseHTML, query, queryAll, find, findAll, has, contents, children, siblings, prev, next, prevWith, nextWith, parent, parents, parentWith, closest, offsetParent, scrollParent, indexOf, getData, setData, removeData, hasData, data, attr, removeAttr, prop, removeProp, clone, detach, remove, empty, html, text, append, appendTo, prepend, prependTo, before, insertBefore, after, insertAfter, wrap, wrapInner, wrapAll, unwrap, replace }; | ||
undefined |
/*! | ||
* @pluginjs/dom v0.7.8 (https://pluginjs.com) | ||
* @pluginjs/dom v0.7.9 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
import{curry,curryWith,camelize}from"@pluginjs/utils";import{isString,isElement,isEmptyObject}from"@pluginjs/is";function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_nonIterableRest()}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArrayLimit(e,r){var t=[],n=!0,i=!1,a=void 0;try{for(var o,l=e[Symbol.iterator]();!(n=(o=l.next()).done)&&(t.push(o.value),!r||t.length!==r);n=!0);}catch(e){i=!0,a=e}finally{try{n||null==l.return||l.return()}finally{if(i)throw a}}return t}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}const parseHTML=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];const n=Array.isArray(r[0])?r[0].reduce((e,t,n)=>e+r[n]+t):r[0],i=document.createElement("div");if(i.innerHTML=n,1===i.children.length)return i.children[0];const a=document.createDocumentFragment();if(i.children.length)for(;i.children.length>0;)a.appendChild(i.children[0]);else for(;i.childNodes.length>0;)a.appendChild(i.childNodes[0]);return a},query=function(e){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:document).querySelector(e)},queryAll=function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;return Array.from(r.querySelectorAll(e))},find=curry((e,r)=>r.querySelector(e)),findAll=curry((e,r)=>Array.from(r.querySelectorAll(e))),has=(e,r)=>isString(e)?Boolean(queryAll(e,r).length):r.contains(e),contents=e=>"IFRAME"===e.tagName?[e.contentDocument]:e.childNodes,children=(e,r)=>(isString(e)||void 0!==r||(r=e,e=void 0),isElement(r)?isString(e)?Array.from(r.children).filter(r=>r.matches(e)):Array.from(r.children):[]),siblings=(e,r)=>(isString(e)||void 0!==r||(r=e,e=void 0),isElement(r)?children(e,r.parentNode).filter(e=>e!==r):[]),prev=e=>e.previousElementSibling,next=e=>e.nextElementSibling,prevWith=curry((e,r)=>{const t=r.previousElementSibling;return t?e(t)?t:prevWith(e,t):null}),nextWith=curry((e,r)=>{const t=r.nextElementSibling;return t?e(t)?t:nextWith(e,t):null}),parent=e=>e.parentNode,parents=(e,r)=>{isString(e)||void 0!==r||(r=e,e=void 0);const t=[];let n=r;for(;isElement(n)&&n.parentNode&&n!==document.body.parentNode;)n=n.parentNode,(!e||e&&n.matches(e))&&t.push(n);return t},parentWith=curry((e,r)=>{const t=r.parentNode;return!(!t||t===document)&&(e(t)?t:parentWith(e,t))}),closest=(e,r)=>r.matches(e)?r:parentWith(r=>r.matches(e),r),offsetParent=e=>{let r=e.offsetParent;for(;r&&"static"===r.style.position;)r=r.offsetParent;return r||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,r)=>{isElement(e)&&void 0===r&&(r=e,e=void 0);const t=getCachedData(r);if(e){if(!(e in t)){let n=r.dataset[e]||r.dataset[camelize(e,!1)];if(void 0!==n){try{n=JSON.parse(n)}catch(e){}t[e]=n}}return t[e]}return t},setData=(e,r,t)=>(getCachedData(t)[e]=r,t),removeData=(e,r)=>(isElement(e)&&void 0===r&&(r=e,e=void 0),void 0===e?delete r[dataStore]:delete getCachedData(r)[e],r),hasData=e=>dataStore in e&&!isEmptyObject(e[dataStore]),data=curryWith((e,r,t)=>{if(isElement(r)&&void 0===t&&(t=r,r=void 0),"string"==typeof e){if(void 0===r)return getData(e,t);setData(e,r,t)}else Object.entries(e).forEach(e=>{let r=_slicedToArray(e,2),n=r[0],i=r[1];return setData(n,i,t)});return t},isElement),attr=curryWith((e,r,t)=>{if(isElement(r)&&void 0===t&&(t=r,r=void 0),"string"==typeof e){if(void 0===r)return t.getAttribute(e);t.setAttribute(e,r)}else Object.entries(e).forEach(e=>{let r=_slicedToArray(e,2),n=r[0],i=r[1];return t.setAttribute(n,i)});return t},isElement),removeAttr=curry((e,r)=>(e.split(" ").forEach(e=>{r.removeAttribute(e)}),r)),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=curryWith((e,r,t)=>{if(isElement(r)&&void 0===t&&(t=r,r=void 0),"string"==typeof e){if(void 0===r)return t[propMap[e]||e];t[propMap[e]||e]=r}else Object.entries(e).forEach(e=>{let r=_slicedToArray(e,2),n=r[0],i=r[1];t[propMap[n]||n]=i});return t},isElement),removeProp=curry((e,r)=>(e.split(" ").forEach(e=>{delete r[e=propMap[e]||e]}),r)),clone=curry(e=>e.cloneNode(!0)),detach=curry(e=>(e.parentNode&&e.parentNode.removeChild(e),e)),remove=curry(e=>e.remove()),empty=curry(e=>{for(;e.lastChild;)e.removeChild(e.lastChild);return e}),html=curryWith((e,r)=>(isString(e)||void 0!==r||(r=e,e=void 0),void 0===e?r.innerHTML:(r.innerHTML=e,r)),isElement),text=curryWith((e,r)=>(isString(e)||void 0!==r||(r=e,e=void 0),void 0===e?r.textContent:(r.textContent=e,r)),isElement),append=curry((e,r)=>(isString(e)?r.insertAdjacentHTML("beforeend",e):r.append(e),r)),appendTo=curry((e,r)=>(isString(e)&&(e=parseHTML(e)),r.append(e),e)),prepend=curry((e,r)=>(isString(e)?r.insertAdjacentHTML("afterbegin",e):r.prepend(e),r)),prependTo=curry((e,r)=>(isString(e)&&(e=parseHTML(e)),r.prepend(e),e)),before=curry((e,r)=>(isString(e)?r.insertAdjacentHTML("beforebegin",e):r.parentNode.insertBefore(e,r),r)),insertBefore=curry((e,r)=>(isString(e)&&(e=parseHTML(e)),NodeList.prototype.isPrototypeOf(e)?e.forEach(e=>{r.parentNode.insertBefore(e,r)}):r.parentNode.insertBefore(e,r),e)),after=curry((e,r)=>(isString(e)?r.insertAdjacentHTML("afterend",e):r.parentNode.insertBefore(e,r.nextElementSibling),r)),insertAfter=curry((e,r)=>(isString(e)&&(e=parseHTML(e)),NodeList.prototype.isPrototypeOf(e)?e.forEach(e=>{r.parentNode.insertBefore(e,r.nextElementSibling)}):r.parentNode.insertBefore(e,r.nextElementSibling),e)),wrap=curry((e,r)=>(isString(e)&&(e=parseHTML(e)),insertBefore(e,r),append(r,e),e)),wrapInner=curry((e,r)=>(isString(e)&&(e=parseHTML(e)),e.innerHTML=r.innerHTML,r.innerHTML="",r.append(e),r)),wrapAll=curry((e,r)=>(isString(e)&&(e=parseHTML(e)),insertBefore(e,r[0]),e.append(...r),e)),unwrap=curryWith((e,r)=>{isString(e)||void 0!==r||(r=e,e=void 0);const t=r.parentNode;return e&&!t.matches(e)||(children(t).forEach(e=>{insertBefore(e,t)}),t.remove()),r},isElement),replace=curry((e,r)=>(isString(e)&&(e=parseHTML(e)),r.parentNode.replaceChild(e,r),r.remove(),e));export{parseHTML,query,queryAll,find,findAll,has,contents,children,siblings,prev,next,prevWith,nextWith,parent,parents,parentWith,closest,offsetParent,scrollParent,indexOf,getData,setData,removeData,hasData,data,attr,removeAttr,prop,removeProp,clone,detach,remove,empty,html,text,append,appendTo,prepend,prependTo,before,insertBefore,after,insertAfter,wrap,wrapInner,wrapAll,unwrap,replace}; | ||
undefined |
660
dist/dom.js
/*! | ||
* @pluginjs/dom v0.7.8 (https://pluginjs.com) | ||
* @pluginjs/dom v0.7.9 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
(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'; | ||
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.parseHTML = parseHTML; | ||
exports.query = query; | ||
exports.queryAll = queryAll; | ||
exports.find = find; | ||
exports.findAll = findAll; | ||
exports.has = has; | ||
exports.contents = contents; | ||
exports.children = children; | ||
exports.siblings = siblings; | ||
exports.prev = prev; | ||
exports.next = next; | ||
exports.prevWith = prevWith; | ||
exports.nextWith = nextWith; | ||
exports.parent = parent; | ||
exports.parents = parents; | ||
exports.parentWith = parentWith; | ||
exports.closest = closest; | ||
exports.offsetParent = offsetParent; | ||
exports.scrollParent = scrollParent; | ||
exports.indexOf = indexOf; | ||
exports.getData = getData; | ||
exports.setData = setData; | ||
exports.removeData = removeData; | ||
exports.hasData = hasData; | ||
exports.data = data; | ||
exports.attr = attr; | ||
exports.removeAttr = removeAttr; | ||
exports.prop = prop; | ||
exports.removeProp = removeProp; | ||
exports.clone = clone; | ||
exports.detach = detach; | ||
exports.remove = remove; | ||
exports.empty = empty; | ||
exports.html = html; | ||
exports.text = text; | ||
exports.append = append; | ||
exports.appendTo = appendTo; | ||
exports.prepend = prepend; | ||
exports.prependTo = prependTo; | ||
exports.before = before; | ||
exports.insertBefore = insertBefore; | ||
exports.after = after; | ||
exports.insertAfter = insertAfter; | ||
exports.wrap = wrap; | ||
exports.wrapInner = wrapInner; | ||
exports.wrapAll = wrapAll; | ||
exports.unwrap = unwrap; | ||
exports.replace = replace; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
undefined |
/*! | ||
* @pluginjs/dom v0.7.8 (https://pluginjs.com) | ||
* @pluginjs/dom v0.7.9 (https://pluginjs.com) | ||
* Copyright 2019 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
!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["@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.parseHTML=o,e.query=function(e){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:document).querySelector(e)},e.queryAll=u,e.find=c,e.findAll=a,e.has=function(e,n){return r.isString(e)?Boolean(u(e,n).length):n.contains(e)},e.contents=function(e){return"IFRAME"===e.tagName?[e.contentDocument]:e.childNodes},e.children=l,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.prev=function(e){return e.previousElementSibling},e.next=function(e){return e.nextElementSibling},e.prevWith=f,e.nextWith=d,e.parent=function(e){return e.parentNode},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.parentWith=s,e.closest=function(e,n){return n.matches(e)?n:s(function(n){return n.matches(e)},n)},e.offsetParent=function(e){for(var n=e.offsetParent;n&&"static"===n.style.position;)n=n.offsetParent;return n||document.documentElement},e.scrollParent=function(e){return s(function(e){return e.scrollHeight>e.clientHeight},e)},e.indexOf=function(e){return i(e.parentElement.children).indexOf(e)},e.getData=m,e.setData=v,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.hasData=function(e){return p in e&&!r.isEmptyObject(e[p])},e.data=h,e.attr=g,e.removeAttr=S,e.prop=b,e.removeProp=A,e.clone=N,e.detach=j,e.remove=x,e.empty=T,e.html=L,e.text=M,e.append=w,e.appendTo=H,e.prepend=O,e.prependTo=B,e.before=C,e.insertBefore=P,e.after=W,e.insertAfter=q,e.wrap=D,e.wrapInner=I,e.wrapAll=_,e.unwrap=F,e.replace=z,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
undefined |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "0.7.8", | ||
"version": "0.7.9", | ||
"category": "utils", | ||
@@ -37,9 +37,9 @@ "main": "dist/dom.common.js", | ||
"dependencies": { | ||
"@pluginjs/is": "^0.7.7", | ||
"@pluginjs/utils": "^0.7.8" | ||
"@pluginjs/is": "^0.7.8", | ||
"@pluginjs/utils": "^0.7.9" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.4.0", | ||
"@pluginjs/browserslist-config": "^1.2.4", | ||
"@pluginjs/cli": "^0.7.7", | ||
"@babel/core": "^7.4.4", | ||
"@pluginjs/browserslist-config": "^1.2.5", | ||
"@pluginjs/cli": "^0.7.8", | ||
"babel-jest": "*", | ||
@@ -69,4 +69,3 @@ "jest": "*", | ||
"extends @pluginjs/browserslist-config" | ||
], | ||
"gitHead": "290fd3939aca081ceab305e0d4157ee0d52b45bf" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
2
23318
9
460
1
Updated@pluginjs/is@^0.7.8
Updated@pluginjs/utils@^0.7.9