Socket
Socket
Sign inDemoInstall

uhooks-dom

Package Overview
Dependencies
4
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.0.2

9

cjs/index.js
'use strict';
/*! (c) Andrea Giammarchi - ISC */
const CustomEvent = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/custom-event'));
const {observe} = require('uconnect');
const {
hooked: $hooked,
dropEffect,
hasEffect
} = require('uhooks');
const {hooked: $hooked, dropEffect, hasEffect} = require('uhooks');

@@ -34,3 +31,3 @@ let observer = null;

if (!observer)
observer = observe();
observer = observe(document, 'childNodes', CustomEvent);
if (!observer.has(disconnectable))

@@ -37,0 +34,0 @@ observer.connect(disconnectable, {

@@ -1,3 +0,3 @@

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

@@ -32,3 +30,3 @@ let observer = null;

if (!observer)
observer = observe();
observer = observe(document, 'childNodes', CustomEvent);
if (!observer.has(disconnectable))

@@ -35,0 +33,0 @@ observer.connect(disconnectable, {

@@ -31,3 +31,2 @@ self.uhooksDOM = (function (exports) {

*/
var CONNECTED = 'connected';

@@ -41,22 +40,8 @@ var DISCONNECTED = 'disconnected';

};
var notifyObserved = function notifyObserved(nodes, type, observed, wmin, wmout) {
for (var length = nodes.length, i = 0; i < length; i++) {
notifyTarget(nodes[i], type, observed, wmin, wmout);
}
};
var notifyTarget = function notifyTarget(node, type, observed, wmin, wmout) {
if (observed.has(node) && !wmin.has(node)) {
wmout["delete"](node);
wmin.set(node, 0);
node.dispatchEvent(new CustomEvent$1(type));
}
notifyObserved(node.childNodes, type, observed, wmin, wmout);
};
/**
* Attach a MutationObserver to a generic node and returns a UConnect instance.
* @param {Node} root a DOM node to observe for mutations
* @param {MutationObserver} MO a MutationObserver constructor (polyfilled in SSR)
* @param {Node} root a DOM node to observe for mutations.
* @param {string} parse the kind of nodes to parse: childNodes, by default, or children.
* @param {Event} CE an Event/CustomEvent constructor (polyfilled in SSR).
* @param {MutationObserver} MO a MutationObserver constructor (polyfilled in SSR).
* @returns {UConnect} an utility to connect or disconnect nodes to observe.

@@ -68,3 +53,5 @@ */

var root = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
var MO = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : MutationObserver;
var parse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'childNodes';
var CE = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : CustomEvent;
var MO = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : MutationObserver;
var observed = new WeakMap(); // these two should be WeakSet but IE11 happens

@@ -94,2 +81,18 @@

var notifyObserved = function notifyObserved(nodes, type, wmin, wmout) {
for (var length = nodes.length, i = 0; i < length; i++) {
notifyTarget(nodes[i], type, wmin, wmout);
}
};
var notifyTarget = function notifyTarget(node, type, wmin, wmout) {
if (has(node) && !wmin.has(node)) {
wmout["delete"](node);
wmin.set(node, 0);
node.dispatchEvent(new CE(type));
}
notifyObserved(node[parse] || [], type, wmin, wmout);
};
var mo = new MO(function (nodes) {

@@ -100,4 +103,4 @@ for (var length = nodes.length, i = 0; i < length; i++) {

addedNodes = _nodes$i.addedNodes;
notifyObserved(removedNodes, DISCONNECTED, observed, wmout, wmin);
notifyObserved(addedNodes, CONNECTED, observed, wmin, wmout);
notifyObserved(removedNodes, DISCONNECTED, wmout, wmin);
notifyObserved(addedNodes, CONNECTED, wmin, wmout);
}

@@ -365,3 +368,3 @@ });

if (!disconnectable) throw 'unobservable';
if (!observer) observer = observe();
if (!observer) observer = observe(document, 'childNodes', CustomEvent$1);
if (!observer.has(disconnectable)) observer.connect(disconnectable, {

@@ -368,0 +371,0 @@ disconnected: function disconnected() {

self.uhooksDOM=function(n){"use strict";
/*! (c) Andrea Giammarchi - ISC */var e={};e.CustomEvent="function"==typeof CustomEvent?CustomEvent:function(n){return e[n]=new e("").constructor[n],e;function e(n,e){e||(e={});var t=document.createEvent("CustomEvent");return t.initCustomEvent(n,!!e.bubbles,!!e.cancelable,e.detail),t}}("prototype");var t=e.CustomEvent,r="connected",u="disconnected",o="EventListener",i=function(n,e,t){n[e+o](r,t),n[e+o](u,t)},c=function(n,e,t,r,u){for(var o=n.length,i=0;i<o;i++)a(n[i],e,t,r,u)},a=function(n,e,r,u,o){r.has(n)&&!u.has(n)&&(o.delete(n),u.set(n,0),n.dispatchEvent(new t(e))),c(n.childNodes,e,r,u,o)},s=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:MutationObserver,t=new WeakMap,o=new WeakMap,a=new WeakMap,s=function(n){return t.has(n)},h=function(n){s(n)&&(i(n,"remove",t.get(n)),t.delete(n))},l=function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};h(n),e.handleEvent||(e.handleEvent=f),i(n,"add",e),t.set(n,e)},v=new e((function(n){for(var e=n.length,i=0;i<e;i++){var s=n[i],f=s.removedNodes,h=s.addedNodes;c(f,u,t,a,o),c(h,r,t,o,a)}}));return v.observe(n,{subtree:!0,childList:!0}),{has:s,connect:l,disconnect:h,kill:function(){v.disconnect()}}};function f(n){n.type in this&&this[n.type](n)}var h="function"==typeof Promise?Promise:function(n){var e,t=[],r=0;return n((function(n){e=n,r=1,t.splice(0).forEach(u)})),{then:u};function u(n){return r?setTimeout(n,0,e):t.push(n),this}},l=null,v=null,d=null,p=new Set,E=new WeakMap,g=new h((function(n){return n()})),m=function(n){var e=n.$,t=n.r,r=n.h;S(t)&&(y.get(r).delete(n),t()),S(n.r=e())&&y.get(r).add(n)},w=function(){var n=p;p=new Set,n.forEach(W)},y=new WeakMap,b=[],_=[];function C(n,e){return n!==this[e]}var k=function(n){var e=y.get(n);e&&g.then((function(){e.forEach((function(n){n.r(),n.r=null})),e.clear()}))},M=function(){var n=E.get(d);return n.a=l,n.c=v,n},$=function(n){return y.has(n)},S=function(n){return"function"==typeof n},W=function(n){n.i=0,n.h.apply(n.c,n.a)};function O(n){var e=this._;this.value!==n&&(this._=new Set,this.value=n,e.forEach(W))}var L=function(n,e){var t=M(),r=t.i,u=t.s;return r===u.length?u.push({$:n(),_:e}):e&&!e.some(C,u[r]._)||(u[r]={$:n(),_:e}),u[t.i++].$},N=function(n){return function(e,t){var r=M(),u=r.i,o=r.s,i=r.h,c=u===o.length;c&&(y.has(i)||y.set(i,new Set),o.push({$:e,_:t,r:null,h:i}));var a=o[r.i++];(c||!t||t.some(C,a._))&&n.push(a)}},P=N(b),x=N(_),R=function(n,e){return S(e)?e(n):e},T=function(n,e,t){var r=M(),u=r.i,o=r.s;u===o.length&&o.push({$:S(t)?t(e):R(void 0,e),set:function(e){o[u].$=n(o[u].$,e),function(n){p.has(n)||(p.add(n),g.then(w))}(r)}});var i=o[r.i++];return[i.$,i.set]},j=null,D=function n(e){var t=e.firstChild,r=e.nodeType;if(r)return r<11?e:t;var u=e.valueOf();return u!==e?n(u):t};return n.createContext=function(n){return{_:new Set,provide:O,value:n}},n.hooked=function(n){var e=function(n){return E.set(e,{a:l,c:v,h:e,i:0,s:[]}),e;function e(){var t=l,r=v,u=d;l=arguments,v=this,d=e;try{return n.apply(v,l)}finally{l=t,v=r,d=u,b.length&&g.then(b.forEach.bind(b.splice(0),m)),_.length&&_.splice(0).forEach(m)}}}(n);return function(){var n=e.apply(this,arguments);if($(e)){var t=D(n);if(!t)throw"unobservable";j||(j=s()),j.has(t)||j.connect(t,{disconnected:function(){k(e)}})}return n}},n.useCallback=function(n,e){return L((function(){return n}),e)},n.useContext=function(n){var e=n._,t=n.value;return e.add(M()),t},n.useEffect=P,n.useLayoutEffect=x,n.useMemo=L,n.useReducer=T,n.useRef=function(n){var e=M(),t=e.i,r=e.s;return t===r.length&&r.push({current:n}),r[e.i++]},n.useState=function(n){return T(R,n)},Object.defineProperty(n,"__esModule",{value:!0}),n}({});
/*! (c) Andrea Giammarchi - ISC */var e={};e.CustomEvent="function"==typeof CustomEvent?CustomEvent:function(n){return e[n]=new e("").constructor[n],e;function e(n,e){e||(e={});var t=document.createEvent("CustomEvent");return t.initCustomEvent(n,!!e.bubbles,!!e.cancelable,e.detail),t}}("prototype");var t=e.CustomEvent,u="connected",r="disconnected",o="EventListener",i=function(n,e,t){n[e+o](u,t),n[e+o](r,t)},c=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"childNodes",t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:CustomEvent,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:MutationObserver,c=new WeakMap,s=new WeakMap,f=new WeakMap,h=function(n){return c.has(n)},l=function(n){h(n)&&(i(n,"remove",c.get(n)),c.delete(n))},v=function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};l(n),e.handleEvent||(e.handleEvent=a),i(n,"add",e),c.set(n,e)},d=function(n,e,t,u){for(var r=n.length,o=0;o<r;o++)p(n[o],e,t,u)},p=function(n,u,r,o){h(n)&&!r.has(n)&&(o.delete(n),r.set(n,0),n.dispatchEvent(new t(u))),d(n[e]||[],u,r,o)},E=new o((function(n){for(var e=n.length,t=0;t<e;t++){var o=n[t],i=o.removedNodes,c=o.addedNodes;d(i,r,f,s),d(c,u,s,f)}}));return E.observe(n,{subtree:!0,childList:!0}),{has:h,connect:v,disconnect:l,kill:function(){E.disconnect()}}};function a(n){n.type in this&&this[n.type](n)}var s="function"==typeof Promise?Promise:function(n){var e,t=[],u=0;return n((function(n){e=n,u=1,t.splice(0).forEach(r)})),{then:r};function r(n){return u?setTimeout(n,0,e):t.push(n),this}},f=null,h=null,l=null,v=new Set,d=new WeakMap,p=new s((function(n){return n()})),E=function(n){var e=n.$,t=n.r,u=n.h;M(t)&&(m.get(u).delete(n),t()),M(n.r=e())&&m.get(u).add(n)},g=function(){var n=v;v=new Set,n.forEach($)},m=new WeakMap,w=[],y=[];function b(n,e){return n!==this[e]}var C=function(n){var e=m.get(n);e&&p.then((function(){e.forEach((function(n){n.r(),n.r=null})),e.clear()}))},_=function(){var n=d.get(l);return n.a=f,n.c=h,n},k=function(n){return m.has(n)},M=function(n){return"function"==typeof n},$=function(n){n.i=0,n.h.apply(n.c,n.a)};function S(n){var e=this._;this.value!==n&&(this._=new Set,this.value=n,e.forEach($))}var W=function(n,e){var t=_(),u=t.i,r=t.s;return u===r.length?r.push({$:n(),_:e}):e&&!e.some(b,r[u]._)||(r[u]={$:n(),_:e}),r[t.i++].$},N=function(n){return function(e,t){var u=_(),r=u.i,o=u.s,i=u.h,c=r===o.length;c&&(m.has(i)||m.set(i,new Set),o.push({$:e,_:t,r:null,h:i}));var a=o[u.i++];(c||!t||t.some(b,a._))&&n.push(a)}},O=N(w),L=N(y),P=function(n,e){return M(e)?e(n):e},x=function(n,e,t){var u=_(),r=u.i,o=u.s;r===o.length&&o.push({$:M(t)?t(e):P(void 0,e),set:function(e){o[r].$=n(o[r].$,e),function(n){v.has(n)||(v.add(n),p.then(g))}(u)}});var i=o[u.i++];return[i.$,i.set]},R=null,T=function n(e){var t=e.firstChild,u=e.nodeType;if(u)return u<11?e:t;var r=e.valueOf();return r!==e?n(r):t};return n.createContext=function(n){return{_:new Set,provide:S,value:n}},n.hooked=function(n){var e=function(n){return d.set(e,{a:f,c:h,h:e,i:0,s:[]}),e;function e(){var t=f,u=h,r=l;f=arguments,h=this,l=e;try{return n.apply(h,f)}finally{f=t,h=u,l=r,w.length&&p.then(w.forEach.bind(w.splice(0),E)),y.length&&y.splice(0).forEach(E)}}}(n);return function(){var n=e.apply(this,arguments);if(k(e)){var u=T(n);if(!u)throw"unobservable";R||(R=c(document,"childNodes",t)),R.has(u)||R.connect(u,{disconnected:function(){C(e)}})}return n}},n.useCallback=function(n,e){return W((function(){return n}),e)},n.useContext=function(n){var e=n._,t=n.value;return e.add(_()),t},n.useEffect=O,n.useLayoutEffect=L,n.useMemo=W,n.useReducer=x,n.useRef=function(n){var e=_(),t=e.i,u=e.s;return t===u.length&&u.push({current:n}),u[e.i++]},n.useState=function(n){return x(P,n)},Object.defineProperty(n,"__esModule",{value:!0}),n}({});
{
"name": "uhooks-dom",
"version": "0.0.1",
"version": "0.0.2",
"description": "A dom-augmentor alternative based on uhooks",

@@ -43,5 +43,6 @@ "main": "./cjs/index.js",

"dependencies": {
"uconnect": "^0.1.4",
"uhooks": "^0.1.11"
"@ungap/custom-event": "^0.3.1",
"uconnect": "^0.2.2",
"uhooks": "^0.1.12"
}
}
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