@stonecrop/utilities 0.4.16 → 0.4.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":"5.6.3"}
1
+ {"version":"5.8.3"}
@@ -1,2 +1,2 @@
1
- (function(h,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],u):(h=typeof globalThis<"u"?globalThis:h||self,u(h["@stonecrop/utilities"]={},h.Vue))})(this,function(h,u){"use strict";function T(e){return u.getCurrentScope()?(u.onScopeDispose(e),!0):!1}const I=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const N=e=>e!=null,W=Object.prototype.toString,K=e=>W.call(e)==="[object Object]",F=()=>{};function v(e){return Array.isArray(e)?e:[e]}function j(e,t,n){return u.watch(e,t,{...n,immediate:!0})}const $=I?window:void 0;function b(e){var t;const n=u.toValue(e);return(t=n==null?void 0:n.$el)!=null?t:n}function w(...e){const t=[],n=()=>{t.forEach(s=>s()),t.length=0},o=(s,i,f,c)=>(s.addEventListener(i,f,c),()=>s.removeEventListener(i,f,c)),a=u.computed(()=>{const s=v(u.toValue(e[0])).filter(i=>i!=null);return s.every(i=>typeof i!="string")?s:void 0}),r=j(()=>{var s,i;return[(i=(s=a.value)==null?void 0:s.map(f=>b(f)))!=null?i:[$].filter(f=>f!=null),v(u.toValue(a.value?e[1]:e[0])),v(u.unref(a.value?e[2]:e[1])),u.toValue(a.value?e[3]:e[2])]},([s,i,f,c])=>{if(n(),!(s!=null&&s.length)||!(i!=null&&i.length)||!(f!=null&&f.length))return;const p=K(c)?{...c}:c;t.push(...s.flatMap(d=>i.flatMap(m=>f.map(g=>o(d,m,g,p)))))},{flush:"post"}),l=()=>{r(),n()};return T(n),l}function B(){const e=u.shallowRef(!1),t=u.getCurrentInstance();return t&&u.onMounted(()=>{e.value=!0},t),e}function q(e){const t=B();return u.computed(()=>(t.value,!!e()))}function G(e,t,n={}){const{window:o=$,...a}=n;let r;const l=q(()=>o&&"MutationObserver"in o),s=()=>{r&&(r.disconnect(),r=void 0)},i=u.computed(()=>{const d=u.toValue(e),m=v(d).map(b).filter(N);return new Set(m)}),f=u.watch(()=>i.value,d=>{s(),l.value&&d.size&&(r=new MutationObserver(t),d.forEach(m=>r.observe(m,a)))},{immediate:!0,flush:"post"}),c=()=>r==null?void 0:r.takeRecords(),p=()=>{f(),s()};return T(p),{isSupported:l,stop:p,takeRecords:c}}function z(e,t,n={}){const{window:o=$,document:a=o==null?void 0:o.document,flush:r="sync"}=n;if(!o||!a)return F;let l;const s=c=>{l==null||l(),l=c},i=u.watchEffect(()=>{const c=b(e);if(c){const{stop:p}=G(a,d=>{d.map(g=>[...g.removedNodes]).flat().some(g=>g===c||g.contains(c))&&t(d)},{window:o,childList:!0,subtree:!0});s(p)}},{flush:r}),f=()=>{i(),s()};return T(f),f}function J(e={}){var t;const{window:n=$,deep:o=!0,triggerOnRemoval:a=!1}=e,r=(t=e.document)!=null?t:n==null?void 0:n.document,l=()=>{var f;let c=r==null?void 0:r.activeElement;if(o)for(;c!=null&&c.shadowRoot;)c=(f=c==null?void 0:c.shadowRoot)==null?void 0:f.activeElement;return c},s=u.ref(),i=()=>{s.value=l()};if(n){const f={capture:!0,passive:!0};w(n,"blur",c=>{c.relatedTarget===null&&i()},f),w(n,"focus",i,f)}return a&&z(s,i,{document:r}),i(),s}const Q="focusin",X="focusout",Y=":focus-within";function Z(e,t={}){const{window:n=$}=t,o=u.computed(()=>b(e)),a=u.shallowRef(!1),r=u.computed(()=>a.value),l=J(t);if(!n||!l.value)return{focused:r};const s={passive:!0};return w(o,Q,()=>a.value=!0,s),w(o,X,()=>{var i,f,c;return a.value=(c=(f=(i=o.value)==null?void 0:i.matches)==null?void 0:f.call(i,Y))!=null?c:!1},s),{focused:r}}function ee(e,{window:t=$,scrollTarget:n}={}){const o=u.ref(!1),a=()=>{if(!t)return;const r=t.document,l=b(e);if(!l)o.value=!1;else{const s=l.getBoundingClientRect();o.value=s.top<=(t.innerHeight||r.documentElement.clientHeight)&&s.left<=(t.innerWidth||r.documentElement.clientWidth)&&s.bottom>=0&&s.right>=0}};return u.watch(()=>b(e),()=>a(),{immediate:!0,flush:"post"}),t&&w(n||t,"scroll",a,{capture:!1,passive:!0}),o}const E=e=>{let t=ee(e).value;return t=t&&e.offsetHeight>0,t},C=e=>e.tabIndex>=0,R=e=>{const t=e.target;return M(t)},M=e=>{var n;let t;if(e instanceof HTMLTableCellElement){const o=(n=e.parentElement)==null?void 0:n.previousElementSibling;if(o){const r=Array.from(o.children)[e.cellIndex];r&&(t=r)}}else if(e instanceof HTMLTableRowElement){const o=e.previousElementSibling;o&&(t=o)}return t&&(!C(t)||!E(t))?M(t):t},te=e=>{var o;const t=e.target;let n;if(t instanceof HTMLTableCellElement){const a=(o=t.parentElement)==null?void 0:o.parentElement;if(a){const r=a.firstElementChild,l=r==null?void 0:r.children[t.cellIndex];l&&(n=l)}}else if(t instanceof HTMLTableRowElement){const a=t.parentElement;if(a){const r=a.firstElementChild;r&&(n=r)}}return n&&(!C(n)||!E(n))?k(n):n},D=e=>{const t=e.target;return k(t)},k=e=>{var n;let t;if(e instanceof HTMLTableCellElement){const o=(n=e.parentElement)==null?void 0:n.nextElementSibling;if(o){const r=Array.from(o.children)[e.cellIndex];r&&(t=r)}}else if(e instanceof HTMLTableRowElement){const o=e.nextElementSibling;o&&(t=o)}return t&&(!C(t)||!E(t))?k(t):t},ne=e=>{var o;const t=e.target;let n;if(t instanceof HTMLTableCellElement){const a=(o=t.parentElement)==null?void 0:o.parentElement;if(a){const r=a.lastElementChild,l=r==null?void 0:r.children[t.cellIndex];l&&(n=l)}}else if(t instanceof HTMLTableRowElement){const a=t.parentElement;if(a){const r=a.lastElementChild;r&&(n=r)}}return n&&(!C(n)||!E(n))?M(n):n},P=e=>{const t=e.target;return A(t)},A=e=>{var n;let t;if(e.previousElementSibling)t=e.previousElementSibling;else{const o=(n=e.parentElement)==null?void 0:n.previousElementSibling;t=o==null?void 0:o.lastElementChild}return t&&(!C(t)||!E(t))?A(t):t},x=e=>{const t=e.target;return H(t)},H=e=>{var n;let t;if(e.nextElementSibling)t=e.nextElementSibling;else{const o=(n=e.parentElement)==null?void 0:n.nextElementSibling;t=o==null?void 0:o.firstElementChild}return t&&(!C(t)||!E(t))?H(t):t},O=e=>{const n=e.target.parentElement,o=n==null?void 0:n.firstElementChild;return o&&(!C(o)||!E(o))?H(o):o},U=e=>{const n=e.target.parentElement,o=n==null?void 0:n.lastElementChild;return o&&(!C(o)||!E(o))?A(o):o},S=["alt","control","shift","meta"],oe={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"},V={"keydown.up":e=>{const t=R(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.down":e=>{const t=D(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.left":e=>{const t=P(e);e.preventDefault(),e.stopPropagation(),t&&t.focus()},"keydown.right":e=>{const t=x(e);e.preventDefault(),e.stopPropagation(),t&&t.focus()},"keydown.control.up":e=>{const t=te(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.down":e=>{const t=ne(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.left":e=>{const t=O(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.right":e=>{const t=U(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.end":e=>{const t=U(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const n=D(e);n&&n.focus()}},"keydown.shift.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const n=R(e);n&&n.focus()}},"keydown.home":e=>{const t=O(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.tab":e=>{const t=x(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.shift.tab":e=>{const t=P(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())}};function le(e){const t=l=>{let s=null;return l.parent&&(typeof l.parent=="string"?s=document.querySelector(l.parent):l.parent instanceof HTMLElement?s=l.parent:s=l.parent.value),s},n=l=>{var f;const s=t(l);let i=[];if(typeof l.selectors=="string")i=s?Array.from(s.querySelectorAll(l.selectors)):Array.from(document.querySelectorAll(l.selectors));else if(Array.isArray(l.selectors))for(const c of l.selectors)c instanceof HTMLElement?i.push(c):i.push(c.$el);else if(l.selectors instanceof HTMLElement)i.push(l.selectors);else if((f=l.selectors)!=null&&f.value)if(Array.isArray(l.selectors.value))for(const c of l.selectors.value)c instanceof HTMLElement?i.push(c):i.push(c.$el);else i.push(l.selectors.value);return i},o=l=>{const s=t(l);let i=[];return l.selectors?i=n(l):s&&(i=Array.from(s.children).filter(c=>C(c)&&E(c))),i},a=l=>s=>{const i=oe[s.key]||s.key.toLowerCase();if(S.includes(i))return;const f=l.handlers||V;for(const c of Object.keys(f)){const[p,...d]=c.split(".");if(p==="keydown"&&d.includes(i)){const m=f[c],g=d.filter(y=>S.includes(y)),_=S.some(y=>{const L=y.charAt(0).toUpperCase()+y.slice(1);return s.getModifierState(L)});if(g.length>0){if(_){for(const y of S)if(d.includes(y)){const L=y.charAt(0).toUpperCase()+y.slice(1);s.getModifierState(L)&&m(s)}}}else _||m(s)}}},r=[];u.onMounted(()=>{for(const l of e){const s=t(l),i=o(l),f=a(l),c=s?[s]:i;for(const p of c){const{focused:d}=Z(u.ref(p)),m=u.watch(d,g=>{g?p.addEventListener("keydown",f):p.removeEventListener("keydown",f)});r.push(m)}}}),u.onBeforeUnmount(()=>{for(const l of r)l()})}function se(e){}h.defaultKeypressHandlers=V,h.install=se,h.useKeyboardNav=le,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(h,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],u):(h=typeof globalThis<"u"?globalThis:h||self,u(h["@stonecrop/utilities"]={},h.Vue))})(this,function(h,u){"use strict";function T(e){return u.getCurrentScope()?(u.onScopeDispose(e),!0):!1}const I=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const N=e=>e!=null,W=Object.prototype.toString,K=e=>W.call(e)==="[object Object]",F=()=>{};function v(e){return Array.isArray(e)?e:[e]}function j(e,t,n){return u.watch(e,t,{...n,immediate:!0})}const $=I?window:void 0;function b(e){var t;const n=u.toValue(e);return(t=n==null?void 0:n.$el)!=null?t:n}function w(...e){const t=[],n=()=>{t.forEach(s=>s()),t.length=0},o=(s,i,f,c)=>(s.addEventListener(i,f,c),()=>s.removeEventListener(i,f,c)),a=u.computed(()=>{const s=v(u.toValue(e[0])).filter(i=>i!=null);return s.every(i=>typeof i!="string")?s:void 0}),r=j(()=>{var s,i;return[(i=(s=a.value)==null?void 0:s.map(f=>b(f)))!=null?i:[$].filter(f=>f!=null),v(u.toValue(a.value?e[1]:e[0])),v(u.unref(a.value?e[2]:e[1])),u.toValue(a.value?e[3]:e[2])]},([s,i,f,c])=>{if(n(),!(s!=null&&s.length)||!(i!=null&&i.length)||!(f!=null&&f.length))return;const p=K(c)?{...c}:c;t.push(...s.flatMap(d=>i.flatMap(m=>f.map(g=>o(d,m,g,p)))))},{flush:"post"}),l=()=>{r(),n()};return T(n),l}function B(){const e=u.shallowRef(!1),t=u.getCurrentInstance();return t&&u.onMounted(()=>{e.value=!0},t),e}function q(e){const t=B();return u.computed(()=>(t.value,!!e()))}function G(e,t,n={}){const{window:o=$,...a}=n;let r;const l=q(()=>o&&"MutationObserver"in o),s=()=>{r&&(r.disconnect(),r=void 0)},i=u.computed(()=>{const d=u.toValue(e),m=v(d).map(b).filter(N);return new Set(m)}),f=u.watch(()=>i.value,d=>{s(),l.value&&d.size&&(r=new MutationObserver(t),d.forEach(m=>r.observe(m,a)))},{immediate:!0,flush:"post"}),c=()=>r==null?void 0:r.takeRecords(),p=()=>{f(),s()};return T(p),{isSupported:l,stop:p,takeRecords:c}}function z(e,t,n={}){const{window:o=$,document:a=o==null?void 0:o.document,flush:r="sync"}=n;if(!o||!a)return F;let l;const s=c=>{l==null||l(),l=c},i=u.watchEffect(()=>{const c=b(e);if(c){const{stop:p}=G(a,d=>{d.map(g=>[...g.removedNodes]).flat().some(g=>g===c||g.contains(c))&&t(d)},{window:o,childList:!0,subtree:!0});s(p)}},{flush:r}),f=()=>{i(),s()};return T(f),f}function J(e={}){var t;const{window:n=$,deep:o=!0,triggerOnRemoval:a=!1}=e,r=(t=e.document)!=null?t:n==null?void 0:n.document,l=()=>{var f;let c=r==null?void 0:r.activeElement;if(o)for(;c!=null&&c.shadowRoot;)c=(f=c==null?void 0:c.shadowRoot)==null?void 0:f.activeElement;return c},s=u.shallowRef(),i=()=>{s.value=l()};if(n){const f={capture:!0,passive:!0};w(n,"blur",c=>{c.relatedTarget===null&&i()},f),w(n,"focus",i,f)}return a&&z(s,i,{document:r}),i(),s}const Q="focusin",X="focusout",Y=":focus-within";function Z(e,t={}){const{window:n=$}=t,o=u.computed(()=>b(e)),a=u.shallowRef(!1),r=u.computed(()=>a.value),l=J(t);if(!n||!l.value)return{focused:r};const s={passive:!0};return w(o,Q,()=>a.value=!0,s),w(o,X,()=>{var i,f,c;return a.value=(c=(f=(i=o.value)==null?void 0:i.matches)==null?void 0:f.call(i,Y))!=null?c:!1},s),{focused:r}}function ee(e,{window:t=$,scrollTarget:n}={}){const o=u.ref(!1),a=()=>{if(!t)return;const r=t.document,l=b(e);if(!l)o.value=!1;else{const s=l.getBoundingClientRect();o.value=s.top<=(t.innerHeight||r.documentElement.clientHeight)&&s.left<=(t.innerWidth||r.documentElement.clientWidth)&&s.bottom>=0&&s.right>=0}};return u.watch(()=>b(e),()=>a(),{immediate:!0,flush:"post"}),t&&w(n||t,"scroll",a,{capture:!1,passive:!0}),o}const E=e=>{let t=ee(e).value;return t=t&&e.offsetHeight>0,t},C=e=>e.tabIndex>=0,R=e=>{const t=e.target;return M(t)},M=e=>{var n;let t;if(e instanceof HTMLTableCellElement){const o=(n=e.parentElement)==null?void 0:n.previousElementSibling;if(o){const r=Array.from(o.children)[e.cellIndex];r&&(t=r)}}else if(e instanceof HTMLTableRowElement){const o=e.previousElementSibling;o&&(t=o)}return t&&(!C(t)||!E(t))?M(t):t},te=e=>{var o;const t=e.target;let n;if(t instanceof HTMLTableCellElement){const a=(o=t.parentElement)==null?void 0:o.parentElement;if(a){const r=a.firstElementChild,l=r==null?void 0:r.children[t.cellIndex];l&&(n=l)}}else if(t instanceof HTMLTableRowElement){const a=t.parentElement;if(a){const r=a.firstElementChild;r&&(n=r)}}return n&&(!C(n)||!E(n))?k(n):n},D=e=>{const t=e.target;return k(t)},k=e=>{var n;let t;if(e instanceof HTMLTableCellElement){const o=(n=e.parentElement)==null?void 0:n.nextElementSibling;if(o){const r=Array.from(o.children)[e.cellIndex];r&&(t=r)}}else if(e instanceof HTMLTableRowElement){const o=e.nextElementSibling;o&&(t=o)}return t&&(!C(t)||!E(t))?k(t):t},ne=e=>{var o;const t=e.target;let n;if(t instanceof HTMLTableCellElement){const a=(o=t.parentElement)==null?void 0:o.parentElement;if(a){const r=a.lastElementChild,l=r==null?void 0:r.children[t.cellIndex];l&&(n=l)}}else if(t instanceof HTMLTableRowElement){const a=t.parentElement;if(a){const r=a.lastElementChild;r&&(n=r)}}return n&&(!C(n)||!E(n))?M(n):n},P=e=>{const t=e.target;return A(t)},A=e=>{var n;let t;if(e.previousElementSibling)t=e.previousElementSibling;else{const o=(n=e.parentElement)==null?void 0:n.previousElementSibling;t=o==null?void 0:o.lastElementChild}return t&&(!C(t)||!E(t))?A(t):t},x=e=>{const t=e.target;return H(t)},H=e=>{var n;let t;if(e.nextElementSibling)t=e.nextElementSibling;else{const o=(n=e.parentElement)==null?void 0:n.nextElementSibling;t=o==null?void 0:o.firstElementChild}return t&&(!C(t)||!E(t))?H(t):t},O=e=>{const n=e.target.parentElement,o=n==null?void 0:n.firstElementChild;return o&&(!C(o)||!E(o))?H(o):o},U=e=>{const n=e.target.parentElement,o=n==null?void 0:n.lastElementChild;return o&&(!C(o)||!E(o))?A(o):o},S=["alt","control","shift","meta"],oe={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"},V={"keydown.up":e=>{const t=R(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.down":e=>{const t=D(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.left":e=>{const t=P(e);e.preventDefault(),e.stopPropagation(),t&&t.focus()},"keydown.right":e=>{const t=x(e);e.preventDefault(),e.stopPropagation(),t&&t.focus()},"keydown.control.up":e=>{const t=te(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.down":e=>{const t=ne(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.left":e=>{const t=O(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.control.right":e=>{const t=U(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.end":e=>{const t=U(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const n=D(e);n&&n.focus()}},"keydown.shift.enter":e=>{if(e.target instanceof HTMLTableCellElement){e.preventDefault(),e.stopPropagation();const n=R(e);n&&n.focus()}},"keydown.home":e=>{const t=O(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.tab":e=>{const t=x(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())},"keydown.shift.tab":e=>{const t=P(e);t&&(e.preventDefault(),e.stopPropagation(),t.focus())}};function le(e){const t=l=>{let s=null;return l.parent&&(typeof l.parent=="string"?s=document.querySelector(l.parent):l.parent instanceof HTMLElement?s=l.parent:s=l.parent.value),s},n=l=>{var f;const s=t(l);let i=[];if(typeof l.selectors=="string")i=s?Array.from(s.querySelectorAll(l.selectors)):Array.from(document.querySelectorAll(l.selectors));else if(Array.isArray(l.selectors))for(const c of l.selectors)c instanceof HTMLElement?i.push(c):i.push(c.$el);else if(l.selectors instanceof HTMLElement)i.push(l.selectors);else if((f=l.selectors)!=null&&f.value)if(Array.isArray(l.selectors.value))for(const c of l.selectors.value)c instanceof HTMLElement?i.push(c):i.push(c.$el);else i.push(l.selectors.value);return i},o=l=>{const s=t(l);let i=[];return l.selectors?i=n(l):s&&(i=Array.from(s.children).filter(c=>C(c)&&E(c))),i},a=l=>s=>{const i=oe[s.key]||s.key.toLowerCase();if(S.includes(i))return;const f=l.handlers||V;for(const c of Object.keys(f)){const[p,...d]=c.split(".");if(p==="keydown"&&d.includes(i)){const m=f[c],g=d.filter(y=>S.includes(y)),_=S.some(y=>{const L=y.charAt(0).toUpperCase()+y.slice(1);return s.getModifierState(L)});if(g.length>0){if(_){for(const y of S)if(d.includes(y)){const L=y.charAt(0).toUpperCase()+y.slice(1);s.getModifierState(L)&&m(s)}}}else _||m(s)}}},r=[];u.onMounted(()=>{for(const l of e){const s=t(l),i=o(l),f=a(l),c=s?[s]:i;for(const p of c){const{focused:d}=Z(u.ref(p)),m=u.watch(d,g=>{g?p.addEventListener("keydown",f):p.removeEventListener("keydown",f)});r.push(m)}}}),u.onBeforeUnmount(()=>{for(const l of r)l()})}function se(e){}h.defaultKeypressHandlers=V,h.install=se,h.useKeyboardNav=le,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=utilities.umd.cjs.map