Socket
Socket
Sign inDemoInstall

uhooks-dom

Package Overview
Dependencies
3
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.5.0

esm.js

6

async.js

@@ -1,4 +0,4 @@

self.uhooksDOM=function(e){"use strict";var t=CustomEvent;function n(e){this.observe(e,{subtree:!0,childList:!0})}function s(e){e.type in this&&this[e.type](e)}var c=Promise;let o=null,a=new Set;const r=e=>{const{$:t,r:n,h:s}=e;f(n)&&(i.get(s).delete(e),n()),f(e.r=t())&&i.get(s).add(e)},l=()=>{const e=a;a=new Set,e.forEach((({h:e,c:t,a:n,e:s})=>{s&&e.apply(t,n)}))},i=new WeakMap,u=[],h=[];function d(e,t){return e!==this[t]}const p=()=>o,f=e=>"function"==typeof e,v=e=>{const t={h:n,c:null,a:null,e:0,i:0,s:[]};return n;function n(){const n=o;o=t,t.e=t.i=0;try{return e.apply(t.c=this,t.a=arguments)}finally{o=n,u.length&&w.then(u.forEach.bind(u.splice(0),r)),h.length&&h.splice(0).forEach(r)}}},w=new c((e=>e()));function y(e){const{_:t,value:n}=this;n!==e&&(this._=new Set,this.value=e,t.forEach((({h:e,c:t,a:n})=>{e.apply(t,n)})))}const E=(e,t)=>{const n=p(),{i:s,s:c}=n;return s!==c.length&&t&&!t.some(d,c[s]._)||(c[s]={$:e(),_:t}),c[n.i++].$},g=e=>(t,n)=>{const s=p(),{i:c,s:o,h:a}=s,r=c===o.length;s.i++,r&&(i.has(a)||i.set(a,new Set),o[c]={$:t,_:n,r:null,d:!1,h:a}),(r||!n||o[c].d||n.some(d,o[c]._))&&e.push(o[c]),o[c].$=t,o[c]._=n},m=g(u),k=g(h),M=(e,t)=>f(t)?t(e):t,S=(e,t,n)=>{const s=p(),{i:c,s:o}=s;c===o.length&&o.push({$:f(n)?n(t):M(void 0,t),set:t=>{o[c].$=e(o[c].$,t),(e=>{a.has(e)||(e.e=1,a.add(e),w.then(l))})(s)}});const{$:r,set:i}=o[s.i++];return[r,i]},$=new WeakMap,_=e=>(e=>{const t=i.get(e);t&&w.then((()=>{t.forEach((e=>{e.r(),e.r=null,e.d=!0})),t.clear()}))})($.get(e)),b=e=>(e=>i.has(e))($.get(e)),W=e=>{const t=v(e);return $.set(n,t),n;async function n(){return await t.apply(this,arguments)}};
self.uhooksDOM=function(e){"use strict";function t(e){this.observe(e,{subtree:!0,childList:!0})}function n(e){e.type in this&&this[e.type](e)}let s=null,c=new Set;const o=e=>{const{$:t,r:n,h:s}=e;d(n)&&(r.get(s).delete(e),n()),d(e.r=t())&&r.get(s).add(e)},a=()=>{const e=c;c=new Set,e.forEach((({h:e,c:t,a:n,e:s})=>{s&&e.apply(t,n)}))},r=new WeakMap,l=[],i=[];function u(e,t){return e!==this[t]}const h=()=>s,d=e=>"function"==typeof e,p=e=>{const t={h:n,c:null,a:null,e:0,i:0,s:[]};return n;function n(){const n=s;s=t,t.e=t.i=0;try{return e.apply(t.c=this,t.a=arguments)}finally{s=n,l.length&&f.then(l.forEach.bind(l.splice(0),o)),i.length&&i.splice(0).forEach(o)}}},f=Promise.resolve();function y(e){const{_:t,value:n}=this;n!==e&&(this._=new Set,this.value=e,t.forEach((({h:e,c:t,a:n})=>{e.apply(t,n)})))}const v=(e,t)=>{const n=h(),{i:s,s:c}=n;return s!==c.length&&t&&!t.some(u,c[s]._)||(c[s]={$:e(),_:t}),c[n.i++].$},w=e=>(t,n)=>{const s=h(),{i:c,s:o,h:a}=s,l=c===o.length;s.i++,l&&(r.has(a)||r.set(a,new Set),o[c]={$:t,_:n,r:null,d:!1,h:a}),(l||!n||o[c].d||n.some(u,o[c]._))&&e.push(o[c]),o[c].$=t,o[c]._=n,o[c].d=!1},E=w(l),g=w(i),m=(e,t)=>d(t)?t(e):t,k=(e,t,n)=>{const s=h(),{i:o,s:r}=s;o===r.length&&r.push({$:d(n)?n(t):m(void 0,t),set:t=>{r[o].$=e(r[o].$,t),(e=>{c.has(e)||(e.e=1,c.add(e),f.then(a))})(s)}});const{$:l,set:i}=r[s.i++];return[l,i]},M=new WeakMap,S=e=>(e=>{const t=r.get(e);t&&f.then((()=>{t.forEach((e=>{e.r(),e.r=null,e.d=!0})),t.clear()}))})(M.get(e)),$=e=>(e=>r.has(e))(M.get(e)),_=e=>{const t=p(e);return M.set(n,t),n;async function n(){return await t.apply(this,arguments)}};
/*! (c) Andrea Giammarchi - ISC */
let C=null,L=null,x=null;const O=new WeakMap,N=new WeakMap,R=(e,t,n,s)=>{const c=c=>{O.has(e)||(O.set(e,0),w.then((()=>{O.delete(e),e.apply(t,n)}))),s(c)};return N.set(s,c),c},T=(e,t,n,s)=>e?[s[0],N.get(s[1])||R(e,t,n,s[1])]:s,D=(e,t)=>{const n=W(t?async function(){const[t,s,c]=[C,L,x];[C,L,x]=[n,this,arguments];try{return await e.apply(L,x)}finally{[C,L,x]=[t,s,c]}}:e);return n},P=((e,t,c,o)=>{const a=new WeakMap,r=new WeakMap,l=new WeakMap,i=e=>a.has(e),u=e=>{i(e)&&(h(e,e.removeEventListener,a.get(e)),a.delete(e))},h=(e,t,n)=>{t.call(e,"disconnected",n),t.call(e,"connected",n)},d=(e,t,n,s)=>{for(let{length:c}=e,o=0;o<c;o++)p(e[o],t,n,s)},p=(e,n,s,o)=>{i(e)&&!s.has(e)&&(o.delete(e),s.set(e,0),e.dispatchEvent(new(c||CustomEvent)(n))),d(e[t||"children"]||[],n,s,o)},f=new(o||MutationObserver)((e=>{for(let{length:t}=e,n=0;n<t;n++){const{removedNodes:t,addedNodes:s}=e[n];d(t,"disconnected",l,r),d(s,"connected",r,l)}}));f.add=n,f.add(e||document);const{attachShadow:v}=Element.prototype;return v&&(Element.prototype.attachShadow=function(e){const t=v.call(this,e);return f.add(t),t}),{has:i,connect:(e,t)=>{u(e),(t||(t={})).handleEvent||(t.handleEvent=s),h(e,e.addEventListener,t),a.set(e,t)},disconnect:u,kill(){f.disconnect()}}})(document,"children",t),j=({firstChild:e})=>{if(e&&1!==e.nodeType&&!(e=e.nextElementSibling))throw"unobservable";return e},q=e=>{const{nodeType:t}=e;if(t)return 1===t?e:j(e);{const t=e.valueOf();return t!==e?q(t):j(t)}};return e.createContext=e=>({_:new Set,provide:y,value:e}),e.hooked=(e,t)=>{const n=D(e,t);return async function(){const e=await n.apply(this,arguments);if(b(n)){const t=q(e);P.has(t)||P.connect(t,{disconnected(){_(n)}})}return e}},e.useCallback=(e,t)=>E((()=>e),t),e.useContext=({_:e,value:t})=>(e.add(p()),t),e.useEffect=m,e.useLayoutEffect=k,e.useMemo=E,e.useReducer=(e,t,n)=>T(C,L,x,S(e,t,n)),e.useRef=e=>{const t=p(),{i:n,s:s}=t;return n===s.length&&s.push({current:e}),s[t.i++]},e.useState=e=>T(C,L,x,(e=>S(M,e))(e))
/*! (c) Andrea Giammarchi - ISC */,e.wait=w,e}({});
let b=null,W=null,C=null;const L=new WeakMap,x=new WeakMap,O=(e,t,n,s)=>{const c=c=>{L.has(e)||(L.set(e,0),f.then((()=>{L.delete(e),e.apply(t,n)}))),s(c)};return x.set(s,c),c},N=(e,t,n,s)=>e?[s[0],x.get(s[1])||O(e,t,n,s[1])]:s,R=(e,t)=>{const n=_(t?async function(){const[t,s,c]=[b,W,C];[b,W,C]=[n,this,arguments];try{return await e.apply(W,C)}finally{[b,W,C]=[t,s,c]}}:e);return n},T=((e,s,c,o)=>{const a=new WeakMap,r=new WeakMap,l=new WeakMap,i=e=>a.has(e),u=e=>{i(e)&&(h(e,e.removeEventListener,a.get(e)),a.delete(e))},h=(e,t,n)=>{t.call(e,"disconnected",n),t.call(e,"connected",n)},d=(e,t,n,s)=>{for(let{length:c}=e,o=0;o<c;o++)p(e[o],t,n,s)},p=(e,t,n,o)=>{i(e)&&!n.has(e)&&(o.delete(e),n.set(e,0),e.dispatchEvent(new(c||CustomEvent)(t))),d(e[s||"children"]||[],t,n,o)},f=new(o||MutationObserver)((e=>{for(let{length:t}=e,n=0;n<t;n++){const{removedNodes:t,addedNodes:s}=e[n];d(t,"disconnected",l,r),d(s,"connected",r,l)}}));f.add=t,f.add(e||document);const{attachShadow:y}=Element.prototype;return y&&(Element.prototype.attachShadow=function(e){const t=y.call(this,e);return f.add(t),t}),{has:i,connect:(e,t)=>{u(e),(t||(t={})).handleEvent||(t.handleEvent=n),h(e,e.addEventListener,t),a.set(e,t)},disconnect:u,kill(){f.disconnect()}}})(document,"children",CustomEvent),D=({firstChild:e})=>{if(e&&1!==e.nodeType&&!(e=e.nextElementSibling))throw"unobservable";return e},P=e=>{const{nodeType:t}=e;if(t)return 1===t?e:D(e);{const t=e.valueOf();return t!==e?P(t):D(t)}};return e.createContext=e=>({_:new Set,provide:y,value:e}),e.hooked=(e,t)=>{const n=R(e,t);return async function(){const e=await n.apply(this,arguments);if($(n)){const t=P(e);T.has(t)||T.connect(t,{disconnected(){S(n)}})}return e}},e.useCallback=(e,t)=>v((()=>e),t),e.useContext=({_:e,value:t})=>(e.add(h()),t),e.useEffect=E,e.useLayoutEffect=g,e.useMemo=v,e.useReducer=(e,t,n)=>N(b,W,C,k(e,t,n)),e.useRef=e=>{const t=h(),{i:n,s:s}=t;return n===s.length&&s.push({current:e}),s[t.i++]},e.useState=e=>N(b,W,C,(e=>k(m,e))(e))
/*! (c) Andrea Giammarchi - ISC */,e.wait=f,e}({});
'use strict';
/*! (c) Andrea Giammarchi - ISC */
const CustomEvent = (m => /* c8 ignore start */ m.__esModule ? m.default : m /* c8 ignore stop */)(require('@ungap/custom-event'));
const {observe} = require('uconnect');

@@ -6,0 +5,0 @@ const observer = observe(document, 'children', CustomEvent);

'use strict';
/*! (c) Andrea Giammarchi - ISC */
const CustomEvent = (m => /* c8 ignore start */ m.__esModule ? m.default : m /* c8 ignore stop */)(require('@ungap/custom-event'));
const {observe} = require('uconnect');

@@ -6,0 +5,0 @@ const observer = observe(document, 'children', CustomEvent);

@@ -1,4 +0,4 @@

self.uhooksDOM=function(e){"use strict";var t=CustomEvent;function n(e){this.observe(e,{subtree:!0,childList:!0})}function s(e){e.type in this&&this[e.type](e)}var o=Promise;let c=null,a=new Set;const r=e=>{const{$:t,r:n,h:s}=e;w(n)&&(i.get(s).delete(e),n()),w(e.r=t())&&i.get(s).add(e)},l=()=>{const e=a;a=new Set,e.forEach((({h:e,c:t,a:n,e:s})=>{s&&e.apply(t,n)}))},i=new WeakMap,u=[],h=[];function d(e,t){return e!==this[t]}const p=e=>{const t=i.get(e);t&&E.then((()=>{t.forEach((e=>{e.r(),e.r=null,e.d=!0})),t.clear()}))},f=()=>c,v=e=>i.has(e),w=e=>"function"==typeof e,y=e=>{const t={h:n,c:null,a:null,e:0,i:0,s:[]};return n;function n(){const n=c;c=t,t.e=t.i=0;try{return e.apply(t.c=this,t.a=arguments)}finally{c=n,u.length&&E.then(u.forEach.bind(u.splice(0),r)),h.length&&h.splice(0).forEach(r)}}},E=new o((e=>e()));function g(e){const{_:t,value:n}=this;n!==e&&(this._=new Set,this.value=e,t.forEach((({h:e,c:t,a:n})=>{e.apply(t,n)})))}const m=(e,t)=>{const n=f(),{i:s,s:o}=n;return s!==o.length&&t&&!t.some(d,o[s]._)||(o[s]={$:e(),_:t}),o[n.i++].$},k=e=>(t,n)=>{const s=f(),{i:o,s:c,h:a}=s,r=o===c.length;s.i++,r&&(i.has(a)||i.set(a,new Set),c[o]={$:t,_:n,r:null,d:!1,h:a}),(r||!n||c[o].d||n.some(d,c[o]._))&&e.push(c[o]),c[o].$=t,c[o]._=n},M=k(u),S=k(h),$=(e,t)=>w(t)?t(e):t,_=(e,t,n)=>{const s=f(),{i:o,s:c}=s;o===c.length&&c.push({$:w(n)?n(t):$(void 0,t),set:t=>{c[o].$=e(c[o].$,t),(e=>{a.has(e)||(e.e=1,a.add(e),E.then(l))})(s)}});const{$:r,set:i}=c[s.i++];return[r,i]};
self.uhooksDOM=function(e){"use strict";function t(e){this.observe(e,{subtree:!0,childList:!0})}function n(e){e.type in this&&this[e.type](e)}let s=null,o=new Set;const c=e=>{const{$:t,r:n,h:s}=e;f(n)&&(a.get(s).delete(e),n()),f(e.r=t())&&a.get(s).add(e)},r=()=>{const e=o;o=new Set,e.forEach((({h:e,c:t,a:n,e:s})=>{s&&e.apply(t,n)}))},a=new WeakMap,l=[],i=[];function u(e,t){return e!==this[t]}const h=e=>{const t=a.get(e);t&&y.then((()=>{t.forEach((e=>{e.r(),e.r=null,e.d=!0})),t.clear()}))},d=()=>s,p=e=>a.has(e),f=e=>"function"==typeof e,v=e=>{const t={h:n,c:null,a:null,e:0,i:0,s:[]};return n;function n(){const n=s;s=t,t.e=t.i=0;try{return e.apply(t.c=this,t.a=arguments)}finally{s=n,l.length&&y.then(l.forEach.bind(l.splice(0),c)),i.length&&i.splice(0).forEach(c)}}},y=Promise.resolve();function w(e){const{_:t,value:n}=this;n!==e&&(this._=new Set,this.value=e,t.forEach((({h:e,c:t,a:n})=>{e.apply(t,n)})))}const E=(e,t)=>{const n=d(),{i:s,s:o}=n;return s!==o.length&&t&&!t.some(u,o[s]._)||(o[s]={$:e(),_:t}),o[n.i++].$},g=e=>(t,n)=>{const s=d(),{i:o,s:c,h:r}=s,l=o===c.length;s.i++,l&&(a.has(r)||a.set(r,new Set),c[o]={$:t,_:n,r:null,d:!1,h:r}),(l||!n||c[o].d||n.some(u,c[o]._))&&e.push(c[o]),c[o].$=t,c[o]._=n,c[o].d=!1},m=g(l),k=g(i),M=(e,t)=>f(t)?t(e):t,S=(e,t,n)=>{const s=d(),{i:c,s:a}=s;c===a.length&&a.push({$:f(n)?n(t):M(void 0,t),set:t=>{a[c].$=e(a[c].$,t),(e=>{o.has(e)||(e.e=1,o.add(e),y.then(r))})(s)}});const{$:l,set:i}=a[s.i++];return[l,i]};
/*! (c) Andrea Giammarchi - ISC */
let b=null,C=null,W=null;const L=new WeakMap,x=new WeakMap,O=(e,t,n,s)=>{const o=o=>{L.has(e)||(L.set(e,0),E.then((()=>{L.delete(e),e.apply(t,n)}))),s(o)};return x.set(s,o),o},N=(e,t,n,s)=>e?[s[0],x.get(s[1])||O(e,t,n,s[1])]:s,R=(e,t)=>{const n=y(t?function(){const[t,s,o]=[b,C,W];[b,C,W]=[n,this,arguments];try{return e.apply(C,W)}finally{[b,C,W]=[t,s,o]}}:e);return n},T=((e,t,o,c)=>{const a=new WeakMap,r=new WeakMap,l=new WeakMap,i=e=>a.has(e),u=e=>{i(e)&&(h(e,e.removeEventListener,a.get(e)),a.delete(e))},h=(e,t,n)=>{t.call(e,"disconnected",n),t.call(e,"connected",n)},d=(e,t,n,s)=>{for(let{length:o}=e,c=0;c<o;c++)p(e[c],t,n,s)},p=(e,n,s,c)=>{i(e)&&!s.has(e)&&(c.delete(e),s.set(e,0),e.dispatchEvent(new(o||CustomEvent)(n))),d(e[t||"children"]||[],n,s,c)},f=new(c||MutationObserver)((e=>{for(let{length:t}=e,n=0;n<t;n++){const{removedNodes:t,addedNodes:s}=e[n];d(t,"disconnected",l,r),d(s,"connected",r,l)}}));f.add=n,f.add(e||document);const{attachShadow:v}=Element.prototype;return v&&(Element.prototype.attachShadow=function(e){const t=v.call(this,e);return f.add(t),t}),{has:i,connect:(e,t)=>{u(e),(t||(t={})).handleEvent||(t.handleEvent=s),h(e,e.addEventListener,t),a.set(e,t)},disconnect:u,kill(){f.disconnect()}}})(document,"children",t),D=({firstChild:e})=>{if(e&&1!==e.nodeType&&!(e=e.nextElementSibling))throw"unobservable";return e},P=e=>{const{nodeType:t}=e;if(t)return 1===t?e:D(e);{const t=e.valueOf();return t!==e?P(t):D(t)}};return e.createContext=e=>({_:new Set,provide:g,value:e}),e.hooked=(e,t)=>{const n=R(e,t);return function(){const e=n.apply(this,arguments);if(v(n)){const t=P(e);T.has(t)||T.connect(t,{disconnected(){p(n)}})}return e}},e.useCallback=(e,t)=>m((()=>e),t),e.useContext=({_:e,value:t})=>(e.add(f()),t),e.useEffect=M,e.useLayoutEffect=S,e.useMemo=m,e.useReducer=(e,t,n)=>N(b,C,W,_(e,t,n)),e.useRef=e=>{const t=f(),{i:n,s:s}=t;return n===s.length&&s.push({current:e}),s[t.i++]},e.useState=e=>N(b,C,W,(e=>_($,e))(e))
/*! (c) Andrea Giammarchi - ISC */,e.wait=E,e}({});
let $=null,_=null,b=null;const C=new WeakMap,W=new WeakMap,L=(e,t,n,s)=>{const o=o=>{C.has(e)||(C.set(e,0),y.then((()=>{C.delete(e),e.apply(t,n)}))),s(o)};return W.set(s,o),o},x=(e,t,n,s)=>e?[s[0],W.get(s[1])||L(e,t,n,s[1])]:s,O=(e,t)=>{const n=v(t?function(){const[t,s,o]=[$,_,b];[$,_,b]=[n,this,arguments];try{return e.apply(_,b)}finally{[$,_,b]=[t,s,o]}}:e);return n},N=((e,s,o,c)=>{const r=new WeakMap,a=new WeakMap,l=new WeakMap,i=e=>r.has(e),u=e=>{i(e)&&(h(e,e.removeEventListener,r.get(e)),r.delete(e))},h=(e,t,n)=>{t.call(e,"disconnected",n),t.call(e,"connected",n)},d=(e,t,n,s)=>{for(let{length:o}=e,c=0;c<o;c++)p(e[c],t,n,s)},p=(e,t,n,c)=>{i(e)&&!n.has(e)&&(c.delete(e),n.set(e,0),e.dispatchEvent(new(o||CustomEvent)(t))),d(e[s||"children"]||[],t,n,c)},f=new(c||MutationObserver)((e=>{for(let{length:t}=e,n=0;n<t;n++){const{removedNodes:t,addedNodes:s}=e[n];d(t,"disconnected",l,a),d(s,"connected",a,l)}}));f.add=t,f.add(e||document);const{attachShadow:v}=Element.prototype;return v&&(Element.prototype.attachShadow=function(e){const t=v.call(this,e);return f.add(t),t}),{has:i,connect:(e,t)=>{u(e),(t||(t={})).handleEvent||(t.handleEvent=n),h(e,e.addEventListener,t),r.set(e,t)},disconnect:u,kill(){f.disconnect()}}})(document,"children",CustomEvent),R=({firstChild:e})=>{if(e&&1!==e.nodeType&&!(e=e.nextElementSibling))throw"unobservable";return e},T=e=>{const{nodeType:t}=e;if(t)return 1===t?e:R(e);{const t=e.valueOf();return t!==e?T(t):R(t)}};return e.createContext=e=>({_:new Set,provide:w,value:e}),e.hooked=(e,t)=>{const n=O(e,t);return function(){const e=n.apply(this,arguments);if(p(n)){const t=T(e);N.has(t)||N.connect(t,{disconnected(){h(n)}})}return e}},e.useCallback=(e,t)=>E((()=>e),t),e.useContext=({_:e,value:t})=>(e.add(d()),t),e.useEffect=m,e.useLayoutEffect=k,e.useMemo=E,e.useReducer=(e,t,n)=>x($,_,b,S(e,t,n)),e.useRef=e=>{const t=d(),{i:n,s:s}=t;return n===s.length&&s.push({current:e}),s[t.i++]},e.useState=e=>x($,_,b,(e=>S(M,e))(e))
/*! (c) Andrea Giammarchi - ISC */,e.wait=y,e}({});
/*! (c) Andrea Giammarchi - ISC */
import CustomEvent from '@ungap/custom-event';
import {observe} from 'uconnect';

@@ -5,0 +4,0 @@ const observer = observe(document, 'children', CustomEvent);

/*! (c) Andrea Giammarchi - ISC */
import CustomEvent from '@ungap/custom-event';
import {observe} from 'uconnect';

@@ -5,0 +4,0 @@ const observer = observe(document, 'children', CustomEvent);

self.uhooksDOM = (function (exports) {
'use strict';
/*! (c) Andrea Giammarchi - ISC */
var self = {};
self.CustomEvent = typeof CustomEvent === 'function' ? CustomEvent : function (__p__) {
CustomEvent[__p__] = new CustomEvent('').constructor[__p__];
return CustomEvent;
function CustomEvent(type, init) {
if (!init) init = {};
var e = document.createEvent('CustomEvent');
e.initCustomEvent(type, !!init.bubbles, !!init.cancelable, init.detail);
return e;
}
}('prototype');
var CustomEvent$1 = self.CustomEvent;
/**

@@ -40,22 +25,20 @@ * @typedef {Object} Handler an object that handle events.

*/
var observe = function observe(root, parse, CE, MO) {
var observed = new WeakMap(); // these two should be WeakSet but IE11 happens
const observe = (root, parse, CE, MO) => {
const observed = new WeakMap;
var wmin = new WeakMap();
var wmout = new WeakMap();
// these two should be WeakSet but IE11 happens
const wmin = new WeakMap;
const wmout = new WeakMap;
var has = function has(node) {
return observed.has(node);
};
var disconnect = function disconnect(node) {
const has = node => observed.has(node);
const disconnect = node => {
if (has(node)) {
listener(node, node.removeEventListener, observed.get(node));
observed["delete"](node);
observed.delete(node);
}
};
var connect = function connect(node, handler) {
const connect = (node, handler) => {
disconnect(node);
if (!(handler || (handler = {})).handleEvent) handler.handleEvent = handleEvent;
if (!(handler || (handler = {})).handleEvent)
handler.handleEvent = handleEvent;
listener(node, node.addEventListener, handler);

@@ -65,3 +48,3 @@ observed.set(node, handler);

var listener = function listener(node, method, handler) {
const listener = (node, method, handler) => {
method.call(node, 'disconnected', handler);

@@ -71,23 +54,19 @@ method.call(node, 'connected', handler);

var notifyObserved = function notifyObserved(nodes, type, wmin, wmout) {
for (var length = nodes.length, i = 0; i < length; i++) {
const notifyObserved = (nodes, type, wmin, wmout) => {
for (let {length} = nodes, i = 0; i < length; i++)
notifyTarget(nodes[i], type, wmin, wmout);
}
};
var notifyTarget = function notifyTarget(node, type, wmin, wmout) {
const notifyTarget = (node, type, wmin, wmout) => {
if (has(node) && !wmin.has(node)) {
wmout["delete"](node);
wmout.delete(node);
wmin.set(node, 0);
node.dispatchEvent(new (CE || CustomEvent)(type));
}
notifyObserved(node[parse || 'children'] || [], type, wmin, wmout);
};
var mo = new (MO || MutationObserver)(function (nodes) {
for (var length = nodes.length, i = 0; i < length; i++) {
var _nodes$i = nodes[i],
removedNodes = _nodes$i.removedNodes,
addedNodes = _nodes$i.addedNodes;
const mo = new (MO || MutationObserver)(nodes => {
for (let {length} = nodes, i = 0; i < length; i++) {
const {removedNodes, addedNodes} = nodes[i];
notifyObserved(removedNodes, 'disconnected', wmout, wmin);

@@ -97,131 +76,96 @@ notifyObserved(addedNodes, 'connected', wmin, wmout);

});
mo.add = add;
mo.add(root || document);
var attachShadow = Element.prototype.attachShadow;
if (attachShadow) Element.prototype.attachShadow = function (init) {
var sd = attachShadow.call(this, init);
mo.add(sd);
return sd;
};
return {
has: has,
connect: connect,
disconnect: disconnect,
kill: function kill() {
mo.disconnect();
}
};
const {attachShadow} = Element.prototype;
if (attachShadow)
Element.prototype.attachShadow = function (init) {
const sd = attachShadow.call(this, init);
mo.add(sd);
return sd;
};
return {has, connect, disconnect, kill() { mo.disconnect(); }};
};
function add(node) {
this.observe(node, {
subtree: true,
childList: true
});
this.observe(node, {subtree: true, childList: true});
}
function handleEvent(event) {
if (event.type in this) this[event.type](event);
if (event.type in this)
this[event.type](event);
}
var Lie = typeof Promise === 'function' ? Promise : function (fn) {
var queue = [],
resolved = 0,
value;
fn(function ($) {
value = $;
resolved = 1;
queue.splice(0).forEach(then);
});
return {
then: then
};
let info = null, schedule = new Set;
function then(fn) {
return resolved ? setTimeout(fn, 0, value) : queue.push(fn), this;
}
};
var info = null,
schedule = new Set();
var invoke = function invoke(effect) {
var $ = effect.$,
r = effect.r,
h = effect.h;
const invoke = effect => {
const {$, r, h} = effect;
if (isFunction(r)) {
fx$1.get(h)["delete"](effect);
fx$1.get(h).delete(effect);
r();
}
if (isFunction(effect.r = $())) fx$1.get(h).add(effect);
if (isFunction(effect.r = $()))
fx$1.get(h).add(effect);
};
var runSchedule = function runSchedule() {
var previous = schedule;
schedule = new Set();
previous.forEach(function (_ref) {
var h = _ref.h,
c = _ref.c,
a = _ref.a,
e = _ref.e;
const runSchedule = () => {
const previous = schedule;
schedule = new Set;
previous.forEach(({h, c, a, e}) => {
// avoid running schedules when the hook is
// re-executed before such schedule happens
if (e) h.apply(c, a);
if (e)
h.apply(c, a);
});
};
var fx$1 = new WeakMap();
var effects = [];
var layoutEffects = [];
const fx$1 = new WeakMap;
const effects = [];
const layoutEffects = [];
function different(value, i) {
return value !== this[i];
}
var dropEffect = function dropEffect(hook) {
var effects = fx$1.get(hook);
if (effects) wait.then(function () {
effects.forEach(function (effect) {
effect.r();
effect.r = null;
effect.d = true;
const dropEffect = hook => {
const effects = fx$1.get(hook);
if (effects)
wait.then(() => {
effects.forEach(effect => {
effect.r();
effect.r = null;
effect.d = true;
});
effects.clear();
});
effects.clear();
});
};
var getInfo = function getInfo() {
return info;
};
var hasEffect = function hasEffect(hook) {
return fx$1.has(hook);
};
var isFunction = function isFunction(f) {
return typeof f === 'function';
};
var hooked$2 = function hooked(callback) {
var current = {
h: hook,
c: null,
a: null,
e: 0,
i: 0,
s: []
};
const getInfo = () => info;
const hasEffect = hook => fx$1.has(hook);
const isFunction = f => typeof f === 'function';
const hooked$2 = callback => {
const current = {h: hook, c: null, a: null, e: 0, i: 0, s: []};
return hook;
function hook() {
var prev = info;
const prev = info;
info = current;
current.e = current.i = 0;
try {
return callback.apply(current.c = this, current.a = arguments);
} finally {
}
finally {
info = prev;
if (effects.length) wait.then(effects.forEach.bind(effects.splice(0), invoke));
if (layoutEffects.length) layoutEffects.splice(0).forEach(invoke);
if (effects.length)
wait.then(effects.forEach.bind(effects.splice(0), invoke));
if (layoutEffects.length)
layoutEffects.splice(0).forEach(invoke);
}
}
};
var reschedule = function reschedule(info) {
const reschedule = info => {
if (!schedule.has(info)) {

@@ -233,19 +177,13 @@ info.e = 1;

};
var wait = new Lie(function ($) {
return $();
const wait = Promise.resolve();
const createContext = value => ({
_: new Set,
provide,
value
});
var createContext = function createContext(value) {
return {
_: new Set(),
provide: provide,
value: value
};
};
var useContext = function useContext(_ref) {
var _ = _ref._,
value = _ref.value;
const useContext = ({_, value}) => {
_.add(getInfo());
return value;

@@ -255,13 +193,7 @@ };

function provide(newValue) {
var _ = this._,
value = this.value;
const {_, value} = this;
if (value !== newValue) {
this._ = new Set();
this._ = new Set;
this.value = newValue;
_.forEach(function (_ref2) {
var h = _ref2.h,
c = _ref2.c,
a = _ref2.a;
_.forEach(({h, c, a}) => {
h.apply(c, a);

@@ -272,78 +204,58 @@ });

var useCallback = function useCallback(fn, guards) {
return useMemo(function () {
return fn;
}, guards);
};
var useMemo = function useMemo(memo, guards) {
var info = getInfo();
var i = info.i,
s = info.s;
if (i === s.length || !guards || guards.some(different, s[i]._)) s[i] = {
$: memo(),
_: guards
};
const useCallback = (fn, guards) => useMemo(() => fn, guards);
const useMemo = (memo, guards) => {
const info = getInfo();
const {i, s} = info;
if (i === s.length || !guards || guards.some(different, s[i]._))
s[i] = {$: memo(), _: guards};
return s[info.i++].$;
};
var createEffect = function createEffect(stack) {
return function (callback, guards) {
var info = getInfo();
var i = info.i,
s = info.s,
h = info.h;
var call = i === s.length;
info.i++;
const createEffect = stack => (callback, guards) => {
const info = getInfo();
const {i, s, h} = info;
const call = i === s.length;
info.i++;
if (call) {
if (!fx$1.has(h))
fx$1.set(h, new Set);
s[i] = {$: callback, _: guards, r: null, d: false, h};
}
if (call || !guards || s[i].d || guards.some(different, s[i]._))
stack.push(s[i]);
s[i].$ = callback;
s[i]._ = guards;
s[i].d = false;
};
if (call) {
if (!fx$1.has(h)) fx$1.set(h, new Set());
s[i] = {
$: callback,
_: guards,
r: null,
d: false,
h: h
};
}
const useEffect = createEffect(effects);
if (call || !guards || s[i].d || guards.some(different, s[i]._)) stack.push(s[i]);
s[i].$ = callback;
s[i]._ = guards;
};
};
const useLayoutEffect = createEffect(layoutEffects);
var useEffect = createEffect(effects);
var useLayoutEffect = createEffect(layoutEffects);
const getValue = (value, f) => isFunction(f) ? f(value) : f;
var getValue = function getValue(value, f) {
return isFunction(f) ? f(value) : f;
};
var useReducer$1 = function useReducer(reducer, value, init) {
var info = getInfo();
var i = info.i,
s = info.s;
if (i === s.length) s.push({
$: isFunction(init) ? init(value) : getValue(void 0, value),
set: function set(value) {
s[i].$ = reducer(s[i].$, value);
reschedule(info);
}
});
var _s$info$i = s[info.i++],
$ = _s$info$i.$,
set = _s$info$i.set;
const useReducer$1 = (reducer, value, init) => {
const info = getInfo();
const {i, s} = info;
if (i === s.length)
s.push({
$: isFunction(init) ?
init(value) : getValue(void 0, value),
set: value => {
s[i].$ = reducer(s[i].$, value);
reschedule(info);
}
});
const {$, set} = s[info.i++];
return [$, set];
};
var useState$1 = function useState(value) {
return useReducer$1(getValue, value);
};
var useRef = function useRef(current) {
var info = getInfo();
var i = info.i,
s = info.s;
if (i === s.length) s.push({
current: current
});
const useState$1 = value => useReducer$1(getValue, value);
const useRef = current => {
const info = getInfo();
const {i, s} = info;
if (i === s.length)
s.push({current});
return s[info.i++];

@@ -353,21 +265,19 @@ };

/*! (c) Andrea Giammarchi - ISC */
var h = null,
c = null,
a = null;
var fx = new WeakMap();
var states = new WeakMap();
var set = function set(h, c, a, update) {
var wrap = function wrap(value) {
let h = null, c = null, a = null;
const fx = new WeakMap;
const states = new WeakMap;
const set = (h, c, a, update) => {
const wrap = value => {
if (!fx.has(h)) {
fx.set(h, 0);
wait.then(function () {
fx["delete"](h);
wait.then(() => {
fx.delete(h);
h.apply(c, a);
});
}
update(value);
};
states.set(update, wrap);

@@ -377,51 +287,53 @@ return wrap;

var wrap = function wrap(h, c, a, state) {
return h ? [state[0], states.get(state[1]) || set(h, c, a, state[1])] : state;
};
const wrap = (h, c, a, state) => (
h ? [
state[0],
states.get(state[1]) || set(h, c, a, state[1])
] :
state
);
var hooked$1 = function hooked(callback, outer) {
var hook = hooked$2(outer ?
/*async*/
function () {
var ph = h,
pc = c,
pa = a;
h = hook;
c = this;
a = arguments;
try {
return (
/*await*/
callback.apply(c, a)
);
} finally {
h = ph;
c = pc;
a = pa;
}
} : callback);
const hooked$1 = (callback, outer) => {
const hook = hooked$2(
outer ?
/*async*/ function () {
const [ph, pc, pa] = [h, c, a];
[h, c, a] = [hook, this, arguments];
try {
return /*await*/ callback.apply(c, a);
}
finally {
[h, c, a] = [ph, pc, pa];
}
} :
callback
);
return hook;
};
var useReducer = function useReducer(reducer, value, init) {
return wrap(h, c, a, useReducer$1(reducer, value, init));
};
var useState = function useState(value) {
return wrap(h, c, a, useState$1(value));
};
const useReducer = (reducer, value, init) =>
wrap(h, c, a, useReducer$1(reducer, value, init));
const useState = value => wrap(h, c, a, useState$1(value));
/*! (c) Andrea Giammarchi - ISC */
var observer = observe(document, 'children', CustomEvent$1);
const observer = observe(document, 'children', CustomEvent);
var find = function find(_ref) {
var firstChild = _ref.firstChild;
if (firstChild && firstChild.nodeType !== 1 && !(firstChild = firstChild.nextElementSibling)) throw 'unobservable';
const find = ({firstChild}) => {
if (
firstChild &&
firstChild.nodeType !== 1 &&
!(firstChild = firstChild.nextElementSibling)
)
throw 'unobservable';
return firstChild;
};
var get = function get(node) {
var nodeType = node.nodeType;
if (nodeType) return nodeType === 1 ? node : find(node);else {
const get = node => {
const {nodeType} = node;
if (nodeType)
return nodeType === 1 ? node : find(node);
else {
// give a chance to facades to return a reasonable value
var value = node.valueOf();
const value = node.valueOf();
return value !== node ? get(value) : find(value);

@@ -431,23 +343,17 @@ }

var hooked = function hooked(fn, outer) {
var hook = hooked$1(fn, outer);
return (
/*async*/
function () {
var node =
/*await*/
hook.apply(this, arguments);
if (hasEffect(hook)) {
var element = get(node);
if (!observer.has(element)) observer.connect(element, {
disconnected: function disconnected() {
const hooked = (fn, outer) => {
const hook = hooked$1(fn, outer);
return /*async*/ function () {
const node = /*await*/ hook.apply(this, arguments);
if (hasEffect(hook)) {
const element = get(node);
if (!observer.has(element))
observer.connect(element, {
disconnected() {
dropEffect(hook);
}
});
}
return node;
}
);
return node;
};
};

@@ -454,0 +360,0 @@

{
"name": "uhooks-dom",
"version": "0.4.0",
"version": "0.5.0",
"description": "A uhooks + uconnect based alternative to dom-augmentor",
"main": "./cjs/index.js",
"scripts": {
"build": "npm run async && npm run cjs && npm run rollup:async && npm run rollup:es && npm run rollup:babel && npm run min && npm run size",
"build": "npm run async && npm run cjs && npm run rollup:async && npm run rollup:es && npm run rollup:index && npm run rollup:esm && npm run size",
"cjs": "ascjs --no-default esm cjs",
"async": "cp esm/index.js esm/async.js && sed -i.bck 's/uhooks-fx/uhooks-fx\\/async/; s/\\/\\*async\\*\\//async/; s/\\/\\*await\\*\\//await/' esm/async.js && rm -rf esm/async.js.bck",
"rollup:async": "rollup --config rollup/async.config.js && sed -i.bck 's/^var /self./' async.js && rm -rf async.js.bck",
"rollup:esm": "rollup --config rollup/esm.config.js",
"rollup:es": "rollup --config rollup/es.config.js && sed -i.bck 's/^var /self./' es.js && rm -rf es.js.bck",
"rollup:babel": "rollup --config rollup/babel.config.js && sed -i.bck 's/^var /self./' index.js && rm -rf index.js.bck",
"min": "terser index.js --comments='/^!/' -c -m -o min.js",
"size": "echo 'async ES6' && cat async.js | brotli | wc -c && echo '' && echo 'sync ES5 / ES6' && cat min.js | brotli | wc -c && cat es.js | brotli | wc -c"
"rollup:index": "rollup --config rollup/index.config.js && sed -i.bck 's/^var /self./' index.js && rm -rf index.js.bck",
"size": "echo 'async ES6' && cat async.js | brotli | wc -c && echo '' && echo 'sync ESM / ES6' && cat esm.js | brotli | wc -c && cat es.js | brotli | wc -c"
},

@@ -25,12 +25,7 @@ "keywords": [

"devDependencies": {
"@babel/core": "^7.17.10",
"@babel/preset-env": "^7.17.10",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-node-resolve": "^13.3.0",
"@ungap/degap": "^0.2.8",
"ascjs": "^5.0.1",
"rollup": "^2.72.0",
"rollup-plugin-includepaths": "^0.2.4",
"rollup-plugin-terser": "^7.0.2",
"terser": "^5.13.1"
"rollup": "^2.74.1",
"rollup-plugin-terser": "^7.0.2"
},

@@ -50,7 +45,6 @@ "module": "./esm/index.js",

},
"unpkg": "min.js",
"unpkg": "esm.js",
"dependencies": {
"@ungap/custom-event": "^0.3.1",
"uconnect": "^0.3.0",
"uhooks-fx": "^0.3.0"
"uhooks-fx": "^0.4.0"
},

@@ -57,0 +51,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc