Socket
Socket
Sign inDemoInstall

uhooks-dom

Package Overview
Dependencies
2
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0 to 0.0.1

cjs/custom-event.js

57

cjs/index.js
'use strict';
Object.defineProperty(exports, '__esModule', {value: true}).default = () => {};
/*! (c) Andrea Giammarchi - ISC */
const {observe} = require('uconnect');
const {
hooked: $hooked,
dropEffect,
hasEffect
} = require('uhooks');
let observer = null;
const get = node => {
const {firstChild, nodeType} = node;
if (nodeType)
return nodeType < 11 ? node : firstChild;
else {
// give a chance to facades to return a reasonable value
const value = node.valueOf();
return value !== node ? get(value) : firstChild;
}
};
const hooked = fn => {
const hook = $hooked(fn);
return function () {
const node = hook.apply(this, arguments);
if (hasEffect(hook)) {
const disconnectable = get(node);
if (!disconnectable)
throw 'unobservable';
if (!observer)
observer = observe();
if (!observer.has(disconnectable))
observer.connect(disconnectable, {
disconnected() {
dropEffect(hook);
}
});
}
return node;
};
};
exports.hooked = hooked;
(m => {
exports.createContext = m.createContext;
exports.useContext = m.useContext;
exports.useCallback = m.useCallback;
exports.useMemo = m.useMemo;
exports.useEffect = m.useEffect;
exports.useLayoutEffect = m.useLayoutEffect;
exports.useReducer = m.useReducer;
exports.useState = m.useState;
exports.useRef = m.useRef;
})(require('uhooks'));

4

es.js

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

self.uhooksDom=function(e){"use strict";return e.default=()=>{},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
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]};
/*! (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}({});

@@ -1,1 +0,49 @@

export default () => {};
/*! (c) Andrea Giammarchi - ISC */
import {observe} from 'uconnect';
import {
hooked as $hooked,
dropEffect, hasEffect
} from 'uhooks';
let observer = null;
const get = node => {
const {firstChild, nodeType} = node;
if (nodeType)
return nodeType < 11 ? node : firstChild;
else {
// give a chance to facades to return a reasonable value
const value = node.valueOf();
return value !== node ? get(value) : firstChild;
}
};
export const hooked = fn => {
const hook = $hooked(fn);
return function () {
const node = hook.apply(this, arguments);
if (hasEffect(hook)) {
const disconnectable = get(node);
if (!disconnectable)
throw 'unobservable';
if (!observer)
observer = observe();
if (!observer.has(disconnectable))
observer.connect(disconnectable, {
disconnected() {
dropEffect(hook);
}
});
}
return node;
};
};
export {
createContext, useContext,
useCallback, useMemo,
useEffect, useLayoutEffect,
useReducer, useState, useRef
} from 'uhooks';

@@ -1,12 +0,387 @@

self.uhooksDom = (function (exports) {
'use strict';
self.uhooksDOM = (function (exports) {
'use strict';
var index = (function () {});
/*! (c) Andrea Giammarchi - ISC */
var self = {};
self.CustomEvent = typeof CustomEvent === 'function' ? CustomEvent : function (__p__) {
CustomEvent[__p__] = new CustomEvent('').constructor[__p__];
return CustomEvent;
exports.default = index;
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;
Object.defineProperty(exports, '__esModule', { value: true });
/**
* @typedef {Object} Handler an object that handle events.
* @property {(event: Event) => void} connected an optional method triggered when node is connected.
* @property {(event: Event) => void} disconnected an optional method triggered when node is disconnected.
*/
return exports;
/**
* @typedef {Object} UConnect an utility to connect or disconnect nodes to observe.
* @property {(node: Node, handler?: Handler) => void} connect a method to start observing a generic Node.
* @property {(node: Node) => void} disconnect a method to stop observing a generic Node.
* @property {() => void} kill a method to kill/disconnect the MutationObserver.
*/
var CONNECTED = 'connected';
var DISCONNECTED = 'disconnected';
var EVENT_LISTENER = 'EventListener';
var listener = function listener(node, call, handler) {
node[call + EVENT_LISTENER](CONNECTED, handler);
node[call + EVENT_LISTENER](DISCONNECTED, handler);
};
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)
* @returns {UConnect} an utility to connect or disconnect nodes to observe.
*/
var observe = function observe() {
var root = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
var MO = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : MutationObserver;
var observed = new WeakMap(); // these two should be WeakSet but IE11 happens
var wmin = new WeakMap();
var wmout = new WeakMap();
var has = function has(node) {
return observed.has(node);
};
var disconnect = function disconnect(node) {
if (has(node)) {
listener(node, 'remove', observed.get(node));
observed["delete"](node);
}
};
var connect = function connect(node) {
var handler = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
disconnect(node);
if (!handler.handleEvent) handler.handleEvent = handleEvent;
listener(node, 'add', handler);
observed.set(node, handler);
};
var mo = new MO(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;
notifyObserved(removedNodes, DISCONNECTED, observed, wmout, wmin);
notifyObserved(addedNodes, CONNECTED, observed, wmin, wmout);
}
});
mo.observe(root, {
subtree: true,
childList: true
});
return {
has: has,
connect: connect,
disconnect: disconnect,
kill: function kill() {
mo.disconnect();
}
};
};
function handleEvent(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
};
function then(fn) {
return resolved ? setTimeout(fn, 0, value) : queue.push(fn), this;
}
};
var a = null,
c = null,
h = null;
var schedule = new Set();
var hooks = new WeakMap();
var waitTick = new Lie(function ($) {
return $();
});
var invoke = function invoke(effect) {
var $ = effect.$,
r = effect.r,
h = effect.h;
if (isFunction(r)) {
fx.get(h)["delete"](effect);
r();
}
if (isFunction(effect.r = $())) fx.get(h).add(effect);
};
var runSchedule = function runSchedule() {
var previous = schedule;
schedule = new Set();
previous.forEach(update);
};
var fx = new WeakMap();
var effects = [];
var layoutEffects = [];
function different(value, i) {
return value !== this[i];
}
var dropEffect = function dropEffect(hook) {
var effects = fx.get(hook);
if (effects) waitTick.then(function () {
effects.forEach(function (effect) {
effect.r();
effect.r = null;
});
effects.clear();
});
};
var getInfo = function getInfo() {
var info = hooks.get(h);
info.a = a;
info.c = c;
return info;
};
var hasEffect = function hasEffect(hook) {
return fx.has(hook);
};
var isFunction = function isFunction(f) {
return typeof f === 'function';
};
var hooked = function hooked(callback) {
hooks.set(hook, {
a: a,
c: c,
h: hook,
i: 0,
s: []
});
return hook;
function hook() {
var pa = a,
pc = c,
ph = h;
a = arguments;
c = this;
h = hook;
try {
return callback.apply(c, a);
} finally {
a = pa;
c = pc;
h = ph;
if (effects.length) waitTick.then(effects.forEach.bind(effects.splice(0), invoke));
if (layoutEffects.length) layoutEffects.splice(0).forEach(invoke);
}
}
};
var reschedule = function reschedule(info) {
if (!schedule.has(info)) {
schedule.add(info);
waitTick.then(runSchedule);
}
};
var update = function update(info) {
info.i = 0;
info.h.apply(info.c, info.a);
};
var createContext = function createContext(value) {
return {
_: new Set(),
provide: provide,
value: value
};
};
var useContext = function useContext(_ref) {
var _ = _ref._,
value = _ref.value;
_.add(getInfo());
return value;
};
function provide(newValue) {
var _ = this._,
value = this.value;
if (value !== newValue) {
this._ = new Set();
this.value = newValue;
_.forEach(update);
}
}
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) s.push({
$: memo(),
_: guards
});else if (!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;
if (call) {
if (!fx.has(h)) fx.set(h, new Set());
s.push({
$: callback,
_: guards,
r: null,
h: h
});
}
var effect = s[info.i++];
if (call || !guards || guards.some(different, effect._)) stack.push(effect);
};
};
var useEffect = createEffect(effects);
var useLayoutEffect = createEffect(layoutEffects);
var getValue = function getValue(value, f) {
return isFunction(f) ? f(value) : f;
};
var useReducer = 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;
return [$, set];
};
var useState = function useState(value) {
return useReducer(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
});
return s[info.i++];
};
/*! (c) Andrea Giammarchi - ISC */
var observer = null;
var get = function get(node) {
var firstChild = node.firstChild,
nodeType = node.nodeType;
if (nodeType) return nodeType < 11 ? node : firstChild;else {
// give a chance to facades to return a reasonable value
var value = node.valueOf();
return value !== node ? get(value) : firstChild;
}
};
var hooked$1 = function hooked$1(fn) {
var hook = hooked(fn);
return function () {
var node = hook.apply(this, arguments);
if (hasEffect(hook)) {
var disconnectable = get(node);
if (!disconnectable) throw 'unobservable';
if (!observer) observer = observe();
if (!observer.has(disconnectable)) observer.connect(disconnectable, {
disconnected: function disconnected() {
dropEffect(hook);
}
});
}
return node;
};
};
exports.createContext = createContext;
exports.hooked = hooked$1;
exports.useCallback = useCallback;
exports.useContext = useContext;
exports.useEffect = useEffect;
exports.useLayoutEffect = useLayoutEffect;
exports.useMemo = useMemo;
exports.useReducer = useReducer;
exports.useRef = useRef;
exports.useState = useState;
Object.defineProperty(exports, '__esModule', { value: true });
return exports;
}({}));

@@ -1,1 +0,2 @@

self.uhooksDom=function(e){"use strict";return e.default=function(){},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
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}({});
{
"name": "uhooks-dom",
"version": "0.0.0",
"description": "",
"version": "0.0.1",
"description": "A dom-augmentor alternative based on uhooks",
"main": "./cjs/index.js",
"scripts": {
"build": "npm run cjs && npm run rollup:es && npm run rollup:babel && npm run min && npm run test",
"cjs": "ascjs esm cjs",
"cjs": "ascjs --no-default esm cjs",
"rollup:es": "rollup --config rollup/es.config.js && sed -i.bck 's/^var /self./' es.js && rm -rf es.js.bck",

@@ -13,4 +13,9 @@ "rollup:babel": "rollup --config rollup/babel.config.js && sed -i.bck 's/^var /self./' index.js && rm -rf index.js.bck",

},
"keywords": [],
"author": "",
"keywords": [
"uhooks",
"dom",
"dom-augmentor",
"augmentor"
],
"author": "Andrea Giammarchi",
"license": "ISC",

@@ -24,2 +29,3 @@ "devDependencies": {

"rollup": "^2.35.1",
"rollup-plugin-includepaths": "^0.2.4",
"rollup-plugin-terser": "^7.0.2",

@@ -37,3 +43,7 @@ "terser": "^5.5.1"

},
"unpkg": "min.js"
}
"unpkg": "min.js",
"dependencies": {
"uconnect": "^0.1.4",
"uhooks": "^0.1.11"
}
}
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