UNPKG

@onenexus/squery

Version:

Interact with Synergy modules/BEM DOM elements

1 lines 18.5 kB
!function(e,n){if("object"==typeof exports&&"object"==typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var t=n();for(var r in t)("object"==typeof exports?exports:e)[r]=t[r]}}("undefined"!=typeof self?self:this,function(){return function(t){var r={};function o(e){if(r[e])return r[e].exports;var n=r[e]={i:e,l:!1,exports:{}};return t[e].call(n.exports,n,n.exports,o),n.l=!0,n.exports}return o.m=t,o.c=r,o.d=function(e,n,t){o.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(n,e){if(1&e&&(n=o(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var t=Object.create(null);if(o.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var r in n)o.d(t,r,function(e){return n[e]}.bind(null,r));return t},o.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(n,"a",n),n},o.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},o.p="/",o(o.s=1)}([function(e,n,t){"use strict";function i(e){return e instanceof Buffer||e instanceof Date||e instanceof RegExp}function c(e){if(e instanceof Buffer){var n=Buffer.alloc?Buffer.alloc(e.length):new Buffer(e.length);return e.copy(n),n}if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e);throw new Error("Unexpected situation")}function u(e,n){return"__proto__"===n?void 0:e[n]}var f=e.exports=function(){if(arguments.length<1||"object"!=typeof arguments[0])return!1;if(arguments.length<2)return arguments[0];var t,r,o=arguments[0];return Array.prototype.slice.call(arguments,1).forEach(function(n){"object"!=typeof n||null===n||Array.isArray(n)||Object.keys(n).forEach(function(e){return r=u(o,e),(t=u(n,e))===o?void 0:"object"!=typeof t||null===t?void(o[e]=t):Array.isArray(t)?void(o[e]=function t(e){var r=[];return e.forEach(function(e,n){"object"==typeof e&&null!==e?Array.isArray(e)?r[n]=t(e):i(e)?r[n]=c(e):r[n]=f({},e):r[n]=e}),r}(t)):i(t)?void(o[e]=c(t)):"object"!=typeof r||null===r||Array.isArray(r)?void(o[e]=f({},t)):void(o[e]=f(r,t))})}),o}},function(e,n,L){"use strict";L.r(n);var t={};function E(e){if(!e||"string"!=typeof e)return!1;var n=document.createElement("br");n.textContent="Hello!";try{e&&n.querySelector(e)}catch(e){return!1}return!0}function G(e){return(G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function f(e){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function C(e,n,t){var r=t=Object.assign(this||{},t||{}),o=r.namespace,i=r.modifierGlue,c=r.componentGlue;if(e instanceof HTMLElement){if(e.hasAttribute("data-module"))return e.getAttribute("data-module");var u;if(e.classList.length)return o&&(u=[].slice.call(e.classList).filter(function(e){return 0===e.indexOf(o)})[0]),o&&u||(u=e.classList[0]),n?u.split(i)[0]:u.split(i)[0].split(c)[0];if(o)return o}return"string"==typeof e&&e.match("^[a-zA-Z0-9_-]+$")?e:e&&"object"===f(e)&&e.name?e.name:e&&e.constructor===Array?e[1]:void 0}L.r(t),L.d(t,"add",function(){return s}),L.d(t,"addModifier",function(){return s}),L.d(t,"component",function(){return y}),L.d(t,"components",function(){return y}),L.d(t,"find",function(){return S}),L.d(t,"getComponent",function(){return i}),L.d(t,"getComponents",function(){return v}),L.d(t,"getModifiers",function(){return x}),L.d(t,"getModules",function(){return d}),L.d(t,"getSubComponent",function(){return Q}),L.d(t,"getSubComponents",function(){return P}),L.d(t,"has",function(){return m}),L.d(t,"hasModifier",function(){return m}),L.d(t,"is",function(){return _}),L.d(t,"isComponent",function(){return p}),L.d(t,"isModule",function(){return M}),L.d(t,"modifier",function(){return k}),L.d(t,"module",function(){return q}),L.d(t,"modules",function(){return q}),L.d(t,"parent",function(){return b}),L.d(t,"parentModule",function(){return B}),L.d(t,"remove",function(){return R}),L.d(t,"removeModifier",function(){return R}),L.d(t,"setComponent",function(){return a}),L.d(t,"subComponent",function(){return D}),L.d(t,"subComponents",function(){return D}),L.d(t,"toggle",function(){return T}),L.d(t,"toggleModifier",function(){return T}),L.d(t,"toggleModifiers",function(){return T}),L.d(t,"unsetComponent",function(){return l});var r=function e(n,t,r,o,i,c){c=c||e.API;var u=window.Synergy||{};e.config=e.config||{};for(var f,s,a,l,p={},y=(f=r,s=o,a=i,l=process.env.SYNERGY?Synergy.config(f,s):"undefined"!=typeof Synergy&&"function"==typeof Synergy.config?Synergy.config(f,s):L(0)(f,s),"function"==typeof a?a(l):l),d=y.modifierGlue||u.modifierGlue||"-",m=y.componentGlue||u.componentGlue||"_",b=y.multipleClasses||u.multipleClasses||!1,g=C(n,!0,{componentGlue:m,modifierGlue:d}),v=function e(n){return n instanceof NodeList||n instanceof HTMLElement?n:n instanceof Array?n.every(function(e){return e instanceof HTMLElement})?n:e(n[0]):E(n)&&document.querySelectorAll(n).length?document.querySelectorAll(n):"object"===G(n)&&n.name?e(n.name):"string"==typeof n&&n.match("^[a-zA-Z0-9_-]+$")?document.querySelectorAll(".".concat(n,', [class*="').concat(n,'-"]')):[]}(n),O=Object.entries(c),h=0;h<O.length;h++){var j=O[h],S=j[0],A=j[1],w={componentGlue:m,modifierGlue:d,multipleClasses:b};v&&(v.length||v instanceof HTMLElement)?p[S]=A.bind(w,v):p[S]=A.bind(w)}"function"==typeof t&&v.forEach(function(e){return t(e,y)});var x=Array.from(v instanceof HTMLElement?[v]:v);return Object.assign(v,p,{namespace:g,nodes:x,node:x[0]})};function c(e,n){if(null==e)return{};var t,r,o=function(e,n){if(null==e)return{};var t,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t=i[r],0<=n.indexOf(t)||(o[t]=e[t]);return o}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)t=i[r],0<=n.indexOf(t)||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function u(e,n,t){var r=t.modifierGlue,o=c(t,["modifierGlue"]);if(e instanceof NodeList||e instanceof Array)return e.every(function(e){return u(e,n,function(o){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{},n=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(i).filter(function(e){return Object.getOwnPropertyDescriptor(i,e).enumerable}))),n.forEach(function(e){var n,t,r;n=o,r=i[t=e],t in n?Object.defineProperty(n,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):n[t]=r})}return o}({modifierGlue:r},o))});var i=[].slice.call(e.classList).filter(function(e){return[e===n,0===e.indexOf(n+r)].some(function(e){return!!e})});return 1===i.length&&i[0]}function s(e,n,t){if(t=Object.assign(this||{},t||{}),e instanceof NodeList||e instanceof Array)return e.forEach(function(e){return s(e,n,t)});var r=t.modifierGlue,o=t.namespace||C(e,!0,t),i=u(e,o,t);return n.constructor===Array&&(n=n.join(r)),i&&!t.multipleClasses?e.classList.replace(i,i+r+n):e.classList.add(o+r+n),e.repaint&&e.repaint(),"function"==typeof sQuery?sQuery(e):e}function b(e,n,t){if(t=Object.assign(this||{},t||{}),e instanceof NodeList||e instanceof Array)return[].slice.call(e).map(function(e){return b(e,n,t)});var r=t,o=r.componentGlue,i=r.modifierGlue,c=t.namespace||C(e,!1,t),u=n||c;u!==c&&(u=c+o+u);var f=u&&e.closest(".".concat(u,", [class*='").concat(u+i,"']"));if(f)return"function"==typeof sQuery?sQuery(f):f;(c=t.namespace||C(e,!0,t))&&c.indexOf(-1<n)&&(u=c.substring(0,c.indexOf(n)+n.length));var s=u&&e.closest(".".concat(u,", [class*='").concat(u+i,"']"));return s?"function"==typeof sQuery?sQuery(s):s:void 0}function g(n){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.forEach(function(e){o(n,e,t[e])})}return n}function o(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function v(u,f,s){if(s=Object.assign(this||{},s||{}),f&&!E(f))return[];if(u instanceof NodeList||u instanceof Array)return[].slice.call(u).reduce(function(e,n){return e.concat([].slice.call(v(n,f,s)))},[]);var e,n,t,r,o,i,c,a=s,l=a.subComponent,p=a.modifierGlue,y=a.componentGlue,d=s.namespace||C(u,l,s);if(f){var m=d+y+f;e=u.querySelectorAll(".".concat(m,", [class*='").concat(m+p,"']"))}else e=u.querySelectorAll("[class*='".concat(d+y,"']"));return e=[].slice.call(e).filter(function(e){var n=C(u,!0,g({},s,{namespace:d})),t=C(e,!0,g({},s,{namespace:d})),r=(n.match(new RegExp(y,"g"))||[]).length,o=(t.match(new RegExp(y,"g"))||[]).length;if(l&&!f&&-1===n.indexOf(y))return!0;if(l&&!r)return!1;!l&&r||r++;var i=!0,c=[].slice.call(e.classList).filter(function(e){return 0===e.indexOf(d)})[0];return s.modifier&&(i=-1<c.indexOf(s.modifier)),!l&&1<r?!(1<c.split(y).length-1)&&i:i&&o===r}),n=u,t=e,r=l,i=(o=s).namespace||C(n,r,o),e=(c=b(n,i,o))?t=[].slice.call(t).filter(function(e){var n=b(e,i,o);return!n||n===c}):t,"function"==typeof sQuery?sQuery(e):e}function i(e,n,t){return t=Object.assign(this||{},t||{}),e instanceof NodeList||e instanceof Array?[].slice.call(e).map(function(e){return i(e,n,t)}):v(e,n,t)[0]}function a(e,n,t,r,o){if(o=Object.assign(this||{},o||{}),e instanceof NodeList||e instanceof Array)return e.forEach(function(e){return a(e,n,t,r,o)});t||r||(r=o.namespace||C(e,!1,o)),t=t||o.namespace||C(e,!1,o),e.classList.add(t+o.componentGlue+n),e.setAttribute("data-component",n),r&&e.classList.remove(r)}function l(r,o,n){if(n=Object.assign(this||{},n||{}),r instanceof NodeList||r instanceof Array)return r.forEach(function(e){return l(e,o,n)});var i=n.componentGlue,c=n.namespace||C(r,!1,n);return[].slice.call(r.classList).forEach(function(e){var n=e.split(i).length-1==1,t=0===e.indexOf(c+i+o);n&&t&&r.classList.remove(e)})}function p(e,c,u){if(u=Object.assign(this||{},u||{}),e instanceof NodeList||e instanceof Array)return[].slice.call(e).every(function(e){return p(e,c,u)});var f=u.componentGlue,s=u.namespace||C(e,!1,u);return[].slice.call(e.classList).some(function(e){if(u.subComponent){var n=1<e.split(f).length-1,t=e.indexOf(c)===e.length-c.length;return n&&t}var r=e.split(f).length-1==1,o=s+f+c,i=-1<o.indexOf(f+c);return 0===e.indexOf(o)&&r&&i})}function y(e,n,t,r){return r=Object.assign(this||{},r||{}),n||t?t&&"find"!==t?"first"===t?(r.getSubComponent||i)(e,n,r):"is"===t?p(e,n,r):"set"===t?a(e,n,null,null,r):"unset"===t?l(e,n,r):"function"==typeof t?v(e,n,r).forEach(function(e){return t(e)}):void 0:(r.getSubComponents||v)(e,n,r):(r.getSubComponents||v)(e,!1,r)}function d(e,r,o){var n=(o=Object.assign(this||{},o||{})).modifierGlue;if(e instanceof NodeList||e instanceof Array)return[].slice.call(e).reduce(function(e,n){var t=[].slice.call(d(n,r,o));return(e=e.filter(function(n){return t.every(function(e){return e!==n})})).concat(t)},[]);var t=e.querySelectorAll(".".concat(r,', [class*="').concat(r+n,'"]')),i=[].slice.call(t).filter(function(e){return[].slice.call(e.classList).some(function(e){return 0===e.indexOf(r)})});return"function"==typeof sQuery?sQuery(i):i}function m(n,i,t){if(t=Object.assign(this||{},t||{}),i){if(i.constructor===Array)return i.every(function(e){return m(n,e,t)});if(n instanceof NodeList||n instanceof Array)return[].slice.call(n).every(function(e){return m(e,i,t)});var c=t.modifierGlue,u=t.namespace||n.namespace||C(n,!1,t);return[].slice.call(n.classList).some(function(e){var n=e.indexOf(c+i),t=0===e.indexOf(u),r=-1<e.indexOf(c+i+c),o=-1<n&&n===e.length-i.length-c.length;return t&&(r||o)})}}function O(n){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.forEach(function(e){h(n,e,t[e])})}return n}function h(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function j(e){return(j="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function S(e,t,r){if(r=Object.assign(this||{},r||{}),"object"===j(t))return e instanceof NodeList||e instanceof Array?[].slice.call(e).reduce(function(e,n){return e.concat(A(n,t,r))},[]):A(e,t,r);if("string"==typeof t){var n=d(e,t,r);if(n.length)return n;var o=v(e,t,r);if(o.length)return o}}function A(e,n,t){t=Object.assign(this||{},t||{});var r=n.module,o=n.component,i=n.modifier,c=[];return r?c=o?v(e,o,O({},t,{namespace:r,modifier:i})):d(e,r,t):o&&(c=v(e,o,O({},t,{modifier:i}))),i&&(c=[].slice.call(c).filter(function(e){return m(e,i,t)})),c}function w(e){return function(e){if(Array.isArray(e)){for(var n=0,t=new Array(e.length);n<e.length;n++)t[n]=e[n];return t}}(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")}()}function x(n,t){if(t=Object.assign(this||{},t||{}),n instanceof NodeList||n instanceof Array){var e=[].slice.call(n).reduce(function(e,n){return e.concat(x(n,t))},[]);return e=w(new Set(e))}var r=t,o=r.namespace,i=r.modifierGlue;return[].slice.call(n.classList).filter(function(e){return 0===e.indexOf(o||C(n,!1,t))})[0].split(i).slice(1)}function P(e,n,t){return(t=Object.assign(this||{},t||{})).subComponent=!0,v(e,n,t)}function Q(e,n,t){return t=Object.assign(this||{},t||{}),e instanceof NodeList||e instanceof Array?[].slice.call(e).map(function(e){return Q(e,n,t)}):P(e,n,t)[0]}function M(e,n,t){t=Object.assign(this||{},t||{});var r=e instanceof NodeList||e instanceof Array?e:[e];return[].slice.call(r).every(function(e){return e.matches(".".concat(n,', [class*="').concat(n+t.modifierGlue,'"]'))})}function N(e){return(N="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _(e,n,t){var r=(t=Object.assign(this||{},t||{})).namespace||C(e,!1,t);if("object"===N(n)){var o=n.module,i=n.component,c=n.modifier;if(o){if(i){var u=r===o,f=p(e,i,t);return c?u&&f&&m(e,c,t):u&&f}return c?M(e,o,t)&&m(e,c,t):M(e,o,t)}if(i)return c?p(e,i,t)&&m(e,c,t):p(e,i,t);if(c)return m(e,c,t)}if("string"==typeof n){if(M(e,n,t))return M(e,n,t);if(p(e,n,t))return p(e,n,t);if(m(e,n,t))return m(e,n,t)}return!1}function R(o,i,n){if(n=Object.assign(this||{},n||{}),i.constructor===Array)return i.forEach(function(e){return R(o,e,n)});if(o instanceof NodeList||o instanceof Array)return o.forEach(function(e){return R(e,i,n)});var c=n.modifierGlue,u=n.namespace||C(o,!0,n);return[].slice.call(o.classList).forEach(function(e){var n=0===e.indexOf(u+c),t=-1<e.indexOf(c+i),r=e.replace(new RegExp(c+i,"g"),"");n&&t&&o.classList.replace(e,r)}),o.repaint&&o.repaint(),"function"==typeof sQuery?sQuery(o):o}function T(e,n,t){return t=Object.assign(this||{},t||{}),e instanceof NodeList||e instanceof Array?e.forEach(function(e){return T(e,n,t)}):m(e,n,t)?R(e,n,t):s(e,n,t)}function k(e,n,t,r){return r=Object.assign(this||{},r||{}),t||n?t&&"is"!==t?"set"===t||"add"===t?s(e,n,r):"unset"===t||"remove"===t?R(e,n,r):"toggle"===t?T(e,n,r):void 0:m(e,n,r):x(e,r)}function q(e,n,t,r){return r=Object.assign(this||{},r||{}),t&&"find"!==t?"is"===t?M(e,n,r):"function"==typeof t?d(e,n,r).forEach(function(e){return t(e)}):void 0:d(e,n,r)}function B(e,n){if(n=Object.assign(this||{},n||{}),e instanceof NodeList||e instanceof Array)return[].slice.call(e).map(function(e){return B(e,n)});var t=n.namespace||C(e,!1,n),r=e.closest(".".concat(t,", [class*='").concat(t+n.modifierGlue,"']"));return"function"==typeof sQuery?sQuery(r):r}function D(e,n,t,r){return(r=Object.assign(this||{},r||{})).subComponent=!0,r.getSubComponent=Q,r.getSubComponents=P,y(e,n,t,r)}"undefined"==typeof process&&(window.process={env:{}}),r.init=function(e,n){var t=window.Synergy||{};n=n||this;var o=Object.assign({elementProto:!0,nodeListProto:!0,preset:"Synergy",Synergy:!0,componentGlue:"undefined"!=typeof sQuery&&t.componentGlue||"_",modifierGlue:"undefined"!=typeof sQuery&&t.modifierGlue||"-",multipleClasses:"undefined"!=typeof sQuery&&t.multipleClasses||!1},e);"BEM"===o.preset&&(o.componentGlue=e.componentGlue||"__",o.modifierGlue=e.modifierGlue||"--",o.multipleClasses=e.multipleClasses||!0,o.elementProto=e.elementProto||!1,o.nodeListProto=e.nodeListProto||!1,n=function(e){for(var n={},t=Object.entries(e),r=0;r<t.length;r++){var o=t[r],i=o[0],c=o[1],u=i;-1<u.indexOf("module")&&(u=u.replace(new RegExp("module","g"),"block")),-1<u.indexOf("Module")&&(u=u.replace(new RegExp("Module","g"),"Block")),-1<u.indexOf("component")&&(u=u.replace(new RegExp("component","g"),"element")),-1<u.indexOf("Component")&&(u=u.replace(new RegExp("Component","g"),"Element")),n[u]=c}return n}(n));var i=o.componentGlue,c=o.modifierGlue,u=o.multipleClasses;o.Synergy&&(window.Synergy=t,Object.assign(window.Synergy,{componentGlue:i,modifierGlue:c,multipleClasses:u}));for(var f=Object.entries(n),r=function(){var e=f[s],n=e[0],r=e[1];o.elementProto&&(Element.prototype[n]&&Element.prototype[n].sQuery&&(Element.prototype[n]=void 0),void 0===document.body[n]&&(Element.prototype[n]=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return r.bind({componentGlue:i,modifierGlue:c,multipleClasses:u}).apply(void 0,[this].concat(n))},Element.prototype[n].sQuery=!0)),o.nodeListProto&&(NodeList.prototype[n]=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return r.bind({componentGlue:i,modifierGlue:c,multipleClasses:u}).apply(void 0,[this].concat(n))},NodeList.prototype[n].sQuery=!0)},s=0;s<f.length;s++)r();"undefined"!=typeof sQuery&&Object.assign(sQuery,{config:o,API:n})}.bind(t);for(var H=Object.entries(t),I=0;I<H.length;I++){var z=H[I];r[z[0]]=z[1]}"undefined"!=typeof window&&(window.sQuery=r);n.default=r}])});