Socket
Socket
Sign inDemoInstall

forgo

Package Overview
Dependencies
Maintainers
2
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

forgo - npm Package Compare versions

Comparing version 4.0.5 to 4.0.6

2

dist/forgo.min.js

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

var ce=Object.defineProperty,be=Object.defineProperties;var ye=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var fe=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var J=(t,r,a)=>r in t?ce(t,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[r]=a,_=(t,r)=>{for(var a in r||(r={}))fe.call(r,a)&&J(t,a,r[a]);if($)for(var a of $(r))Ee.call(r,a)&&J(t,a,r[a]);return t},H=(t,r)=>be(t,ye(r));var A={};var he=["ref","dangerouslySetInnerHTML"],Te=Symbol.for("FORGO_FRAGMENT"),ve="http://www.w3.org/2000/svg";var W=1,K=3,G=8,C={mount(t,r){t.__internal.eventListeners.mount.forEach(a=>a(r,t))},remount(t,r){t.__internal.eventListeners.remount.forEach(a=>a(r,t))},unmount(t,r){t.__internal.eventListeners.unmount.forEach(a=>a(r,t))},shouldUpdate(t,r,a){return t.__internal.eventListeners.shouldUpdate.length===0?!0:t.__internal.eventListeners.shouldUpdate.map(h=>h(r,a,t)).some(Boolean)},afterRender(t,r,a){t.__internal.eventListeners.afterRender.forEach(h=>h(r,a,t))}},M=class{constructor(r){this.__internal={registeredMethods:r,unmounted:!1,eventListeners:{afterRender:[],mount:[],remount:[],unmount:[],shouldUpdate:[]},element:{componentIndex:-1}}}update(r){return xe(this.__internal.element,r)}mount(r){this.__internal.eventListeners.mount.push(r)}remount(r){this.__internal.eventListeners.remount.push(r)}unmount(r){this.__internal.eventListeners.unmount.push(r)}shouldUpdate(r){this.__internal.eventListeners.shouldUpdate.push(r)}afterRender(r){this.__internal.eventListeners.afterRender.push(r)}};function I(t,r,...a){var T;r=r!=null?r:{},r.children=a.length>1?w(Array.from(a)):a.length===1?w(a[0]):void 0;let h=(T=r.key)!=null?T:void 0;return{type:t,props:r,key:h,__is_forgo_element__:!0}}var we=I;function Ne(t,r){return a=>{if(t.__forgo===void 0||t.__forgo.deleted===!1)return r(a)}}function te(t){var Y;let r=t;r.__internal=(Y=r.__internal)!=null?Y:{Text:r.window.Text,HTMLElement:r.window.HTMLElement};function a(n,e,i,u){return Array.isArray(n)||z(n)?oe(w(n),e,i,u):q(n)?Ce(n)?T(n,e,i,u):re(n,e,i,u):h(n,e,i)}function h(n,e,i){var g;let u;k(n)?u=r.document.createComment("null component render"):u=r.document.createTextNode(Pe(n));let c;if(e.type==="search"){let b=e.parentElement.childNodes;if(e.length){let d=b[e.currentNodeIndex];if(d.nodeType===K||d.nodeType===G)d.replaceWith(u),c=(g=N(d))==null?void 0:g.components;else{let o=b[e.currentNodeIndex];e.parentElement.insertBefore(u,o!=null?o:null)}}else if(b.length===0||e.currentNodeIndex===0)e.parentElement.prepend(u);else{let d=b[e.currentNodeIndex];e.parentElement.insertBefore(u,d!=null?d:null)}}return D(n,u,!0,i),{nodes:[u]}}function T(n,e,i,u){if(e.type==="detached")return b(void 0,void 0);{let d=e.parentElement.childNodes;return se(n,e,i)?g(e):b(e.parentElement,e.currentNodeIndex)}function c(d){if(n.props.dangerouslySetInnerHTML)d.innerHTML=n.props.dangerouslySetInnerHTML.__html;else{let o=N(d);x(o);let s=w([n.props.children]).filter(y=>!k(y)),p=0;for(let y of s){let{nodes:m}=a(y,{type:"search",parentElement:d,currentNodeIndex:p,length:d.childNodes.length-p},[],u);p+=m.length}L(d.childNodes,p,d.childNodes.length),j(d),X(o)}}function g(d){let o=d.parentElement.childNodes,s=N(d.parentElement),p=o[d.currentNodeIndex];return i.forEach((y,m)=>{var l;if(y.key!==void 0){let E=S(y.key,m),f=(l=s.lookups.newlyAddedKeyedComponentNodes.get(E))!=null?l:[];f.push(p),s.lookups.newlyAddedKeyedComponentNodes.set(E,f)}}),n.key!==void 0&&s.lookups.newlyAddedKeyedElementNodes.set(n.key,p),D(n,p,!1,i),c(p),{nodes:[p]}}function b(d,o){let s=ue(n,d);n.props.ref&&(n.props.ref.value=s);let p=o!==void 0?d.childNodes[o]:null;if(d){let y=N(d);i.forEach((m,l)=>{if(m.key!==void 0){let E=S(m.key,l);y.lookups.newlyAddedKeyedComponentNodes.set(E,[s])}}),n.key!==void 0&&y.lookups.newlyAddedKeyedElementNodes.set(n.key,s)}return d&&d.insertBefore(s,p!=null?p:null),D(n,s,!0,i),c(s),{nodes:[s]}}}function x(n){n.lookups.renderCount++}function X(n){n.lookups.renderCount--,n.lookups.renderCount===0&&(n.lookups.keyedComponentNodes=n.lookups.newlyAddedKeyedComponentNodes,n.lookups.keyedElementNodes=n.lookups.newlyAddedKeyedElementNodes,n.lookups.newlyAddedKeyedComponentNodes=new Map,n.lookups.newlyAddedKeyedElementNodes=new Map,n.lookups.deletedKeyedComponentNodes=new Map,n.lookups.deletedKeyedElementNodes=new Map,n.lookups.deletedUnkeyedNodes=[])}function re(n,e,i,u){let c=i.length;if(e.type!=="detached"&&!u){let o=e.parentElement.childNodes;if(de(n,e,i.length))return g(o,e)}return b();function g(o,s){let p=o[s.currentNodeIndex],m=N(p).components[c];if(C.shouldUpdate(m.component,n.props,m.props)){let l=H(_({},m),{props:n.props}),E=l.component.__internal.registeredMethods.render(n.props,l.component),f=i.length,v=i.concat(l),P=m.component.__internal.element.node,F=l.component.__internal.registeredMethods.error?l.component:void 0,ge=d(n.props,v,F,()=>{let me={type:"search",currentNodeIndex:s.currentNodeIndex,length:l.nodes.length,parentElement:s.parentElement};return V(E,me,v,f,l.nodes.length,u)});return C.afterRender(l.component,n.props,P),ge}else{let l=B(s.parentElement.childNodes,m.component.__internal.element.node,s.currentNodeIndex);return{nodes:O(s.parentElement.childNodes,l,l+m.nodes.length)}}}function b(){let o=n.type,s=Fe(o,o(n.props),r.window.FORGO_NO_LEGACY_WARN!==!0);s.__internal.element.componentIndex=c;let p=s.__internal.registeredMethods.error?s:void 0,y={key:n.key,ctor:o,component:s,props:n.props,nodes:[],isMounted:!1},m=i.length,l=i.concat(y);return d(n.props,l,p,()=>{let E=s.__internal.registeredMethods.render(n.props,s),f=e.type==="detached"?e:{type:"search",currentNodeIndex:e.currentNodeIndex,length:u?e.length:0,parentElement:e.parentElement},v=a(E,f,l,u),F=N(v.nodes[0]).components[m];return F.nodes=v.nodes,F.component.__internal.element.node=v.nodes[0],C.mount(y.component,n.props),C.afterRender(s,n.props,void 0),v})}function d(o,s,p,y){try{return y()}catch(m){if(p!=null&&p.__internal.registeredMethods.error){let l=p.__internal.registeredMethods.error(o,m,p);return a(l,e,s,u)}else throw m}}}function V(n,e,i,u,c,g){let b=e.parentElement.childNodes.length,d=i.slice(-1)[0],o=d.component.__internal.element.node,s=a(n,e,i,g),p=d.component.__internal.element.node;o!==p&&C.remount(d.component,d.props);let y=e.parentElement.childNodes.length,m=b+s.nodes.length-y,l=e.currentNodeIndex+s.nodes.length;if(L(e.parentElement.childNodes,l,l+c-m),s.nodes.length){let f=N(s.nodes[0]).components[u];f.nodes=s.nodes,f.component.__internal.element.node=s.nodes[0]}return s}function oe(n,e,i,u){let c=w(n);if(e.type==="detached")throw new Error("Arrays and fragments cannot be rendered at the top level.");{let g={nodes:[]},b=e.currentNodeIndex,d=e.length,o=N(e.parentElement);x(o);for(let s of c){let p=e.parentElement.childNodes.length,y=H(_({},e),{currentNodeIndex:b,length:d}),m=a(s,y,i,u);g.nodes.push(...m.nodes);let l=e.parentElement.childNodes.length,E=p+m.nodes.length-l;b+=m.nodes.length,d-=E}return X(o),g}}function L(n,e,i){let u=[];if(i>e){let c=n[e].parentElement,g=N(c);for(let b=e;b<i;b++){let d=n[e],o=N(d);d.remove(),o.components.forEach((s,p)=>{var y;if(s.key!==void 0){let m=S(s.key,p),l=g.lookups.keyedComponentNodes.get(m);if(l!==void 0){let f=l.filter(v=>v!==d);f.length?g.lookups.keyedComponentNodes.set(m,f):g.lookups.keyedComponentNodes.delete(m)}let E=(y=g.lookups.deletedKeyedComponentNodes.get(m))!=null?y:[];E.push(d),g.lookups.deletedKeyedComponentNodes.set(m,E)}}),o.key!==void 0?(g.lookups.keyedComponentNodes.delete(o.key),g.lookups.deletedKeyedComponentNodes.set(o.key,[d])):g.lookups.deletedUnkeyedNodes.push({node:d}),u.push(d)}}return u}function j(n){function e(u){let c=N(u);c.deleted=!0;for(let g of c.components)g.component.__internal.element.node===u&&(g.component.__internal.unmounted||C.unmount(g.component,g.props))}let i=N(n);for(let u of i.lookups.deletedKeyedComponentNodes.values())for(let c of u)c.isConnected&&e(c);for(let{node:u}of i.lookups.deletedUnkeyedNodes)e(u);i.lookups.deletedKeyedComponentNodes.clear(),i.lookups.deletedUnkeyedNodes=[]}function se(n,e,i){function u(b,d,o){if(U(b)){let s=N(b);return b.tagName.toLowerCase()===d.type&&s.components.every((p,y)=>o[y]!==void 0&&o[y].component===p.component)}else return!1}function c(b,d,o){let{parentElement:s,currentNodeIndex:p}=d,y=N(s),m=y.lookups.keyedElementNodes.get(b.key);if(m!==void 0)if(u(m,b,o)){let l=s.childNodes[p];return m!==l&&s.insertBefore(m,l!=null?l:null),!0}else return y.lookups.keyedComponentNodes.delete(b.key),!1;else{let l=y.lookups.deletedKeyedElementNodes.get(b.key);if(l!==void 0){let E=s.childNodes;if(y.lookups.deletedKeyedComponentNodes.delete(b.key),u(l,b,o)){let f=E[p];return l!==f&&s.insertBefore(l,f!=null?f:null),!0}}return!1}}function g(b,d,o){var l;let{parentElement:s,currentNodeIndex:p,length:y}=d,m=s.childNodes;for(let E=p;E<p+y;E++){let f=m[E];if(U(f)){let v=N(f);if(f.tagName.toLowerCase()===b.type&&v.key===void 0&&u(f,b,o)){let P=(l=s.childNodes[p])!=null?l:null;return f!==P&&s.insertBefore(f,P),!0}}}return!1}return ne(n)?c(n,e,i):g(n,e,i)}function de(n,e,i){function u(g,b,d){let{parentElement:o,currentNodeIndex:s}=b,p=S(g.key,d),y=N(o),m=y.lookups.keyedComponentNodes.get(p);if(m!==void 0){let l=o.childNodes[s];for(let E of m)E!==l&&o.insertBefore(E,l!=null?l:null);return!0}else{let l=y.lookups.deletedKeyedComponentNodes.get(p);if(l!==void 0){y.lookups.deletedKeyedComponentNodes.delete(p);for(let E of l){let f=o.childNodes[s];E!==f&&o.insertBefore(E,f!=null?f:null)}return!0}}return!1}function c(g,b,d){var m;let{parentElement:o,currentNodeIndex:s,length:p}=b,y=o.childNodes;for(let l=s;l<s+p;l++){let E=y[l],f=N(E);if(f!==void 0&&f.components.length>d&&f.components[d].ctor===g.type){let v=(m=o.childNodes[s])!=null?m:null;return E!==v&&o.insertBefore(E,v),!0}}return!1}return ne(n)?u(n,e,i):c(n,e,i)}function D(n,e,i,u){var c;if(u.length>0&&(u[u.length-1].component.__internal.element.node=e),q(n)){let g=N(e);if(g!==void 0&&g.props)for(let o in g.props)o in n.props||o!=="children"&&o!=="xmlns"&&(e.nodeType===K||e.nodeType===G||e instanceof r.__internal.HTMLElement&&o in e?delete e[o]:e.removeAttribute(o));else if(!i&&U(e)&&e.hasAttributes()){let o=Array.from(e.attributes);for(let s of o){let p=s.name;p in n.props||e.removeAttribute(p)}}let b=Object.entries(n.props);for(let[o,s]of b)if(!he.includes(o)&&((c=g==null?void 0:g.props)==null?void 0:c[o])!==s&&o!=="children"&&o!=="xmlns")if(e.nodeType===K||e.nodeType===G)e[o]=s;else if(e instanceof r.__internal.HTMLElement)if(o==="style"){if(g===void 0||g.style===void 0||g.style!==n.props.style){let p=_e(n.props.style);e.style.cssText!==p&&(e.style.cssText=p)}}else o==="onblur"?e[o]=Ne(e,s):o in e?e[o]=s:e.setAttribute(o,s);else typeof s=="string"?e.setAttribute(o,s):e[o]=s;let d=H(_({},g),{key:n.key,props:n.props,components:u});Q(e,d)}else Q(e,{components:u,lookups:{deletedKeyedComponentNodes:new Map,deletedUnkeyedNodes:[],keyedComponentNodes:new Map,newlyAddedKeyedComponentNodes:new Map,deletedKeyedElementNodes:new Map,newlyAddedKeyedElementNodes:new Map,keyedElementNodes:new Map,renderCount:0}})}function ie(n,e){let i=ee(e)?r.document.querySelector(e):e;if(i==null)throw new Error(`The mount() function was called on a non-element (${typeof e=="string"?e:e==null?void 0:e.tagName}).`);if(i.nodeType!==W)throw new Error("The container argument to the mount() function should be an HTML element.");let u=i.childNodes.length>0,c=a(n,{type:"search",currentNodeIndex:0,length:i.childNodes.length,parentElement:i},[],u);if(c.nodes.length<i.childNodes.length){let g=O(i.childNodes,c.nodes.length,i.childNodes.length);for(let b of g)b.remove()}return c}function ae(n){let e=ee(n)?r.document.querySelector(n):n;if(e===null)throw new Error(`The unmount() function was called on a non-element (${typeof n=="string"?n:n==null?void 0:n.tagName}).`);if(e.nodeType!==W)throw new Error("The container argument to the unmount() function should be an HTML element.");L(e.childNodes,0,e.childNodes.length),j(e)}function le(n){let e=a(n,{type:"detached"},[],!1);return{node:e.nodes[0],nodes:e.nodes}}function pe(n,e){if(!(n!=null&&n.node))throw new Error("Missing node information in rerender() argument.");let i=n.node.parentElement;if(k(i))return{nodes:[]};{let u=N(n.node),c=u.components[n.componentIndex],g=e!=null?e:c.props;if(!C.shouldUpdate(c.component,g,c.props)){let f=B(i.childNodes,n.node,0);return{nodes:O(i.childNodes,f,f+c.nodes.length)}}let b=H(_({},c),{props:g}),d=u.components.slice(0,n.componentIndex),o=d.length,s=d.concat(b),p=c.component.__internal.element.node,y=c.component.__internal.registeredMethods.render(g,c.component),m=B(i.childNodes,n.node,0),l={type:"search",currentNodeIndex:m,length:c.nodes.length,parentElement:i},E=V(y,l,s,o,c.nodes.length,!1);for(let f=0;f<d.length;f++){let v=d[f],P=v.nodes.findIndex(F=>F===c.nodes[0]);v.nodes=v.nodes.slice(0,P).concat(E.nodes).concat(v.nodes.slice(P+c.nodes.length)),v.nodes.length>0&&(v.component.__internal.element.node=v.nodes[0])}return j(i),C.afterRender(c.component,g,p),E}}function ue(n,e){let i=k(n.props.xmlns)?n.type==="svg"?ve:e!==void 0?e.namespaceURI:null:n.props.xmlns;return n.props.is!==void 0?i!==null?r.document.createElementNS(i,n.type,{is:n.props.is}):r.document.createElement(n.type,{is:n.props.is}):i!==null?r.document.createElementNS(i,n.type):r.document.createElement(n.type)}return{mount:ie,unmount:ae,render:le,rerender:pe}}var Z=globalThis!==void 0?globalThis:window,R=te({window:Z,document:Z.document});function Me(t){R=te(t)}function Re(t,r){return R.mount(t,r)}function Ae(t){return R.unmount(t)}function Se(t){return R.render(t)}function xe(t,r){return R.rerender(t,r)}function w(t){function r(a,h=[]){let T=Array.isArray(a)?a:z(a)?Array.isArray(a.props.children)?a.props.children:k(a.props.children)?[]:[a.props.children]:[a];for(let x of T)Array.isArray(x)||z(x)?r(x,h):h.push(x);return h}return r(t,[])}function Pe(t){return t.toString()}function q(t){return!k(t)&&t.__is_forgo_element__===!0}function Ce(t){return q(t)&&typeof t.type=="string"}function z(t){return!k(t)&&t.type===Te}function N(t){return t.__forgo===void 0&&(t.__forgo={components:[],lookups:{deletedKeyedComponentNodes:new Map,deletedUnkeyedNodes:[],keyedComponentNodes:new Map,newlyAddedKeyedComponentNodes:new Map,deletedKeyedElementNodes:new Map,keyedElementNodes:new Map,newlyAddedKeyedElementNodes:new Map,renderCount:0}}),t.__forgo}function Q(t,r){t.__forgo=r}var ke=t=>{let r=T=>({get element(){return T.__internal.element},update(x){return T.update(x)}}),a={render(T,x){return t.render(T,r(x))}};t.error&&(a.error=(T,x)=>t.error(T,Object.assign(r(h),{error:x})));let h=new M(_({},a));return t.mount&&h.mount(T=>{t.mount(T,r(h))}),t.remount&&h.remount(T=>{t.remount(T,r(h))}),t.unmount&&h.unmount(T=>{t.unmount(T,r(h))}),t.afterRender&&h.afterRender((T,x)=>{t.afterRender(T,Object.assign(r(h),{previousNode:x}))}),t.shouldUpdate&&h.shouldUpdate((T,x)=>t.shouldUpdate(T,x)),h};function S(t,r){return`$Component${r}_${t}`}function Fe(t,r,a){if(!(r instanceof M)&&Reflect.has(r,"render"))return a&&(console.warn("Legacy component syntax is deprecated since v3.2.0 and will be removed in v5.0. The affected component was found here:"),console.warn(new Error().stack)),ke(r);if(!(r instanceof M))throw new Error(`${t.name||"Unnamed"} component constructor must return an instance of the Component class`);return r}function k(t){return t==null}function ee(t){return typeof t=="string"}function U(t){return t.nodeType===W}function _e(t){return typeof t=="string"?t:t==null?"":Object.keys(t).reduce((r,a)=>r+a.split(/(?=[A-Z])/).join("-").toLowerCase()+":"+t[a]+";","")}function ne(t){return t.key!==void 0}function O(t,r,a){let h=[];for(let T=r;T<a;T++)h.push(t[T]);return h}function B(t,r,a){if(r===void 0)return-1;for(let h=a;h<t.length;h++)if(t[h]===r)return h;return-1}(r=>r.JSX=A)(I||(I={}));export{M as Component,Te as Fragment,A as JSX,I as createElement,te as createForgoInstance,N as getForgoState,we as h,ke as legacyComponentSyntaxCompat,Re as mount,Se as render,xe as rerender,Me as setCustomEnv,Q as setForgoState,Ae as unmount};
var be=Object.defineProperty,ye=Object.defineProperties;var fe=Object.getOwnPropertyDescriptors;var Y=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable;var $=(t,r,i)=>r in t?be(t,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[r]=i,F=(t,r)=>{for(var i in r||(r={}))Ee.call(r,i)&&$(t,i,r[i]);if(Y)for(var i of Y(r))he.call(r,i)&&$(t,i,r[i]);return t},_=(t,r)=>ye(t,fe(r));var S={};var Te=["ref","dangerouslySetInnerHTML"],ve=Symbol.for("FORGO_FRAGMENT"),Ne="http://www.w3.org/2000/svg";var B=1,G=3,U=8,P={mount(t,r){t.__internal.eventListeners.mount.forEach(i=>i(r,t))},remount(t,r){t.__internal.eventListeners.remount.forEach(i=>i(r,t))},unmount(t,r){t.__internal.eventListeners.unmount.forEach(i=>i(r,t))},shouldUpdate(t,r,i){return t.__internal.eventListeners.shouldUpdate.length===0?!0:t.__internal.eventListeners.shouldUpdate.map(h=>h(r,i,t)).some(Boolean)},afterRender(t,r,i){t.__internal.eventListeners.afterRender.forEach(h=>h(r,i,t))}},M=class{constructor(r){this.__internal={registeredMethods:r,unmounted:!1,eventListeners:{afterRender:[],mount:[],remount:[],unmount:[],shouldUpdate:[]},element:{componentIndex:-1,nodeIndex:-1}}}update(r){return Pe(this.__internal.element,r)}mount(r){this.__internal.eventListeners.mount.push(r)}remount(r){this.__internal.eventListeners.remount.push(r)}unmount(r){this.__internal.eventListeners.unmount.push(r)}shouldUpdate(r){this.__internal.eventListeners.shouldUpdate.push(r)}afterRender(r){this.__internal.eventListeners.afterRender.push(r)}};function j(t,r,...i){var T;r=r!=null?r:{},r.children=i.length>1?w(Array.from(i)):i.length===1?w(i[0]):void 0;let h=(T=r.key)!=null?T:void 0;return{type:t,props:r,key:h,__is_forgo_element__:!0}}var Me=j;function xe(t,r){return i=>{if(t.__forgo===void 0||t.__forgo.deleted===!1)return r(i)}}function re(t){var V;let r=t;r.__internal=(V=r.__internal)!=null?V:{Text:r.window.Text,HTMLElement:r.window.HTMLElement};function i(n,e,d,g){return Array.isArray(n)||q(n)?se(w(n),e,d,g):W(n)?ke(n)?T(n,e,d,g):oe(n,e,d,g):h(n,e,d)}function h(n,e,d){var y;let g;k(n)?g=r.document.createComment("null component render"):g=r.document.createTextNode(Ce(n));let m;if(e.type==="search"){let p=e.parentElement.childNodes;if(e.length){let s=p[e.currentNodeIndex];if(s.nodeType===G||s.nodeType===U)s.replaceWith(g),m=(y=v(s))==null?void 0:y.components;else{let l=p[e.currentNodeIndex];e.parentElement.insertBefore(g,l!=null?l:null)}}else if(p.length===0||e.currentNodeIndex===0)e.parentElement.prepend(g);else{let s=p[e.currentNodeIndex];e.parentElement.insertBefore(g,s!=null?s:null)}H(n,g,e.currentNodeIndex,!0,d)}else H(n,g,-1,!0,d);return{nodes:[g]}}function T(n,e,d,g){if(e.type==="detached")return p(void 0,void 0);{let s=e.parentElement.childNodes;return de(n,e,d)?y(e):p(e.parentElement,e.currentNodeIndex)}function m(s){if(n.props.dangerouslySetInnerHTML)s.innerHTML=n.props.dangerouslySetInnerHTML.__html;else{let l=v(s);x(l);let o=w([n.props.children]).filter(c=>!k(c)),a=0;for(let c of o){let{nodes:b}=i(c,{type:"search",parentElement:s,currentNodeIndex:a,length:s.childNodes.length-a},[],g);a+=b.length}D(s.childNodes,a,s.childNodes.length),K(s),z(l)}}function y(s){let l=s.parentElement.childNodes,o=v(s.parentElement),a=l[s.currentNodeIndex];return d.forEach((c,b)=>{var u;if(c.key!==void 0){let E=I(c.key,b),f=(u=o.lookups.newlyAddedKeyedComponentNodes.get(E))!=null?u:[];f.push(a),o.lookups.newlyAddedKeyedComponentNodes.set(E,f)}}),n.key!==void 0&&o.lookups.newlyAddedKeyedElementNodes.set(n.key,a),H(n,a,s.currentNodeIndex,!1,d),m(a),{nodes:[a]}}function p(s,l){let o=ge(n,s);n.props.ref&&(n.props.ref.value=o);let a=l!==void 0?s.childNodes[l]:null;if(s){let c=v(s);d.forEach((b,u)=>{if(b.key!==void 0){let E=I(b.key,u);c.lookups.newlyAddedKeyedComponentNodes.set(E,[o])}}),n.key!==void 0&&c.lookups.newlyAddedKeyedElementNodes.set(n.key,o)}return s?(s.insertBefore(o,a!=null?a:null),H(n,o,e.type==="search"?e.currentNodeIndex:te(s.childNodes,o,0),!0,d)):H(n,o,e.type==="search"?e.currentNodeIndex:-1,!0,d),m(o),{nodes:[o]}}}function x(n){n.lookups.renderCount++}function z(n){n.lookups.renderCount--,n.lookups.renderCount===0&&(n.lookups.keyedComponentNodes=n.lookups.newlyAddedKeyedComponentNodes,n.lookups.keyedElementNodes=n.lookups.newlyAddedKeyedElementNodes,n.lookups.newlyAddedKeyedComponentNodes=new Map,n.lookups.newlyAddedKeyedElementNodes=new Map,n.lookups.deletedKeyedComponentNodes=new Map,n.lookups.deletedKeyedElementNodes=new Map,n.lookups.deletedUnkeyedNodes=[])}function oe(n,e,d,g){let m=d.length;if(e.type!=="detached"&&!g){let l=e.parentElement.childNodes;if(ie(n,e,d.length))return y(l,e)}return p();function y(l,o){let a=l[o.currentNodeIndex],b=v(a).components[m];if(P.shouldUpdate(b.component,n.props,b.props)){let u=_(F({},b),{props:n.props}),E=u.component.__internal.registeredMethods.render(n.props,u.component),f=d.length,N=d.concat(u),C=b.component.__internal.element.node,A=u.component.__internal.registeredMethods.error?u.component:void 0,me=s(n.props,N,A,()=>{let ce={type:"search",currentNodeIndex:o.currentNodeIndex,length:u.nodes.length,parentElement:o.parentElement};return X(E,ce,N,f,u.nodes.length,g)});return P.afterRender(u.component,n.props,C),me}else return{nodes:b.nodes}}function p(){let l=n.type,o=He(l,l(n.props),r.window.FORGO_NO_LEGACY_WARN!==!0);o.__internal.element.componentIndex=m;let a=o.__internal.registeredMethods.error?o:void 0,c={key:n.key,ctor:l,component:o,props:n.props,nodes:[],isMounted:!1},b=d.length,u=d.concat(c);return s(n.props,u,a,()=>{let E=o.__internal.registeredMethods.render(n.props,o),f=e.type==="detached"?e:{type:"search",currentNodeIndex:e.currentNodeIndex,length:g?e.length:0,parentElement:e.parentElement},N=i(E,f,u,g),A=v(N.nodes[0]).components[b];return A.nodes=N.nodes,L(A.component.__internal.element,N.nodes[0],e.type!=="detached"?e.currentNodeIndex:-1),P.mount(c.component,n.props),P.afterRender(o,n.props,void 0),N})}function s(l,o,a,c){try{return c()}catch(b){if(a!=null&&a.__internal.registeredMethods.error){let u=a.__internal.registeredMethods.error(l,b,a);return i(u,e,o,g)}else throw b}}}function X(n,e,d,g,m,y){let p=e.parentElement.childNodes.length,s=d.slice(-1)[0],l=s.component.__internal.element.node,o=i(n,e,d,y),a=s.component.__internal.element.node;l!==a&&P.remount(s.component,s.props);let c=e.parentElement.childNodes.length,b=p+o.nodes.length-c,u=e.currentNodeIndex+o.nodes.length;if(D(e.parentElement.childNodes,u,u+m-b),o.nodes.length){let f=v(o.nodes[0]).components[g];f.nodes=o.nodes,L(f.component.__internal.element,o.nodes[0],e.currentNodeIndex)}return o}function se(n,e,d,g){let m=w(n);if(e.type==="detached")throw new Error("Arrays and fragments cannot be rendered at the top level.");{let y={nodes:[]},p=e.currentNodeIndex,s=e.length,l=v(e.parentElement);x(l);for(let o of m){let a=e.parentElement.childNodes.length,c=_(F({},e),{currentNodeIndex:p,length:s}),b=i(o,c,d,g);y.nodes.push(...b.nodes);let u=e.parentElement.childNodes.length,E=a+b.nodes.length-u;p+=b.nodes.length,s-=E}return z(l),y}}function D(n,e,d){let g=[];if(d>e){let m=n[e].parentElement,y=v(m);for(let p=e;p<d;p++){let s=n[e],l=v(s);s.remove(),l.components.forEach((o,a)=>{var c;if(o.key!==void 0){let b=I(o.key,a),u=y.lookups.keyedComponentNodes.get(b);if(u!==void 0){let f=u.filter(N=>N!==s);f.length?y.lookups.keyedComponentNodes.set(b,f):y.lookups.keyedComponentNodes.delete(b)}let E=(c=y.lookups.deletedKeyedComponentNodes.get(b))!=null?c:[];E.push(s),y.lookups.deletedKeyedComponentNodes.set(b,E)}}),l.key!==void 0?(y.lookups.keyedComponentNodes.delete(l.key),y.lookups.deletedKeyedComponentNodes.set(l.key,[s])):y.lookups.deletedUnkeyedNodes.push({node:s}),g.push(s)}}return g}function K(n){function e(g){let m=v(g);m.deleted=!0;for(let y of m.components)y.component.__internal.element.node===g&&(y.component.__internal.unmounted||P.unmount(y.component,y.props))}let d=v(n);for(let g of d.lookups.deletedKeyedComponentNodes.values())for(let m of g)m.isConnected&&e(m);for(let{node:g}of d.lookups.deletedUnkeyedNodes)e(g);d.lookups.deletedKeyedComponentNodes.clear(),d.lookups.deletedUnkeyedNodes=[]}function de(n,e,d){function g(p,s,l){if(O(p)){let o=v(p);return p.tagName.toLowerCase()===s.type&&o.components.every((a,c)=>l[c]!==void 0&&l[c].component===a.component)}else return!1}function m(p,s,l){let{parentElement:o,currentNodeIndex:a}=s,c=v(o),b=c.lookups.keyedElementNodes.get(p.key);if(b!==void 0)if(g(b,p,l)){let u=o.childNodes[a];return b!==u&&o.insertBefore(b,u!=null?u:null),!0}else return c.lookups.keyedComponentNodes.delete(p.key),!1;else{let u=c.lookups.deletedKeyedElementNodes.get(p.key);if(u!==void 0){let E=o.childNodes;if(c.lookups.deletedKeyedComponentNodes.delete(p.key),g(u,p,l)){let f=E[a];return u!==f&&o.insertBefore(u,f!=null?f:null),!0}}return!1}}function y(p,s,l){var u;let{parentElement:o,currentNodeIndex:a,length:c}=s,b=o.childNodes;for(let E=a;E<a+c;E++){let f=b[E];if(O(f)){let N=v(f);if(f.tagName.toLowerCase()===p.type&&N.key===void 0&&g(f,p,l)){let C=(u=o.childNodes[a])!=null?u:null;return f!==C&&o.insertBefore(f,C),!0}}}return!1}return ee(n)?m(n,e,d):y(n,e,d)}function ie(n,e,d){function g(y,p,s){let{parentElement:l,currentNodeIndex:o}=p,a=I(y.key,s),c=v(l),b=c.lookups.keyedComponentNodes.get(a);if(b!==void 0){let u=l.childNodes[o];for(let E of b)E!==u&&l.insertBefore(E,u!=null?u:null);return!0}else{let u=c.lookups.deletedKeyedComponentNodes.get(a);if(u!==void 0){c.lookups.deletedKeyedComponentNodes.delete(a);for(let E of u){let f=l.childNodes[o];E!==f&&l.insertBefore(E,f!=null?f:null)}return!0}}return!1}function m(y,p,s){var b;let{parentElement:l,currentNodeIndex:o,length:a}=p,c=l.childNodes;for(let u=o;u<o+a;u++){let E=c[u],f=v(E);if(f!==void 0&&f.components.length>s&&f.components[s].ctor===y.type){let N=(b=l.childNodes[o])!=null?b:null;return E!==N&&l.insertBefore(E,N),!0}}return!1}return ee(n)?g(n,e,d):m(n,e,d)}function H(n,e,d,g,m){var y;if(m.length>0&&L(m[m.length-1].component.__internal.element,e,d),W(n)){let p=v(e);if(p!==void 0&&p.props)for(let o in p.props)o in n.props||o!=="children"&&o!=="xmlns"&&(e.nodeType===G||e.nodeType===U||e instanceof r.__internal.HTMLElement&&o in e?delete e[o]:e.removeAttribute(o));else if(!g&&O(e)&&e.hasAttributes()){let o=Array.from(e.attributes);for(let a of o){let c=a.name;c in n.props||e.removeAttribute(c)}}let s=Object.entries(n.props);for(let[o,a]of s)if(!Te.includes(o)&&((y=p==null?void 0:p.props)==null?void 0:y[o])!==a&&o!=="children"&&o!=="xmlns")if(e.nodeType===G||e.nodeType===U)e[o]=a;else if(e instanceof r.__internal.HTMLElement)if(o==="style"){if(p===void 0||p.style===void 0||p.style!==n.props.style){let c=_e(n.props.style);e.style.cssText!==c&&(e.style.cssText=c)}}else o==="onblur"?e[o]=xe(e,a):o in e?e[o]=a:e.setAttribute(o,a);else typeof a=="string"?e.setAttribute(o,a):e[o]=a;let l=_(F({},p),{key:n.key,props:n.props,components:m});Z(e,l)}else Z(e,{components:m,lookups:{deletedKeyedComponentNodes:new Map,deletedUnkeyedNodes:[],keyedComponentNodes:new Map,newlyAddedKeyedComponentNodes:new Map,deletedKeyedElementNodes:new Map,newlyAddedKeyedElementNodes:new Map,keyedElementNodes:new Map,renderCount:0}})}function ae(n,e){let d=Q(e)?r.document.querySelector(e):e;if(d==null)throw new Error(`The mount() function was called on a non-element (${typeof e=="string"?e:e==null?void 0:e.tagName}).`);if(d.nodeType!==B)throw new Error("The container argument to the mount() function should be an HTML element.");let g=d.childNodes.length>0,m=i(n,{type:"search",currentNodeIndex:0,length:d.childNodes.length,parentElement:d},[],g);if(m.nodes.length<d.childNodes.length){let y=ne(d.childNodes,m.nodes.length,d.childNodes.length);for(let p of y)p.remove()}return m}function le(n){let e=Q(n)?r.document.querySelector(n):n;if(e===null)throw new Error(`The unmount() function was called on a non-element (${typeof n=="string"?n:n==null?void 0:n.tagName}).`);if(e.nodeType!==B)throw new Error("The container argument to the unmount() function should be an HTML element.");D(e.childNodes,0,e.childNodes.length),K(e)}function ue(n){let e=i(n,{type:"detached"},[],!1);return{node:e.nodes[0],nodes:e.nodes}}function pe(n,e){if(n===void 0||n.node===void 0)throw new Error("Missing node information in rerender() argument.");n.node.parentElement!==null&&n.nodeIndex===-1&&(n.nodeIndex=te(n.node.parentElement.childNodes,n.node,0));let d=n.node.parentElement;if(k(d))return{nodes:[]};{let g=v(n.node),m=g.components[n.componentIndex],y=e!=null?e:m.props;if(!P.shouldUpdate(m.component,y,m.props))return{nodes:ne(d.childNodes,n.nodeIndex,n.nodeIndex+m.nodes.length)};let p=_(F({},m),{props:y}),s=g.components.slice(0,n.componentIndex),l=s.length,o=s.concat(p),a=m.component.__internal.element.node,c=m.component.__internal.registeredMethods.render(y,m.component),b={type:"search",currentNodeIndex:n.nodeIndex,length:m.nodes.length,parentElement:d},u=X(c,b,o,l,m.nodes.length,!1);for(let E=0;E<s.length;E++){let f=s[E],N=f.nodes.findIndex(C=>C===m.nodes[0]);f.nodes=f.nodes.slice(0,N).concat(u.nodes).concat(f.nodes.slice(N+m.nodes.length)),f.nodes.length>0&&L(f.component.__internal.element,f.nodes[0],N)}return K(d),P.afterRender(m.component,y,a),u}}function ge(n,e){let d=k(n.props.xmlns)?n.type==="svg"?Ne:e!==void 0?e.namespaceURI:null:n.props.xmlns;return n.props.is!==void 0?d!==null?r.document.createElementNS(d,n.type,{is:n.props.is}):r.document.createElement(n.type,{is:n.props.is}):d!==null?r.document.createElementNS(d,n.type):r.document.createElement(n.type)}return{mount:ae,unmount:le,render:ue,rerender:pe}}var J=globalThis!==void 0?globalThis:window,R=re({window:J,document:J.document});function Re(t){R=re(t)}function Ae(t,r){return R.mount(t,r)}function Se(t){return R.unmount(t)}function Ie(t){return R.render(t)}function Pe(t,r){return R.rerender(t,r)}function w(t){function r(i,h=[]){let T=Array.isArray(i)?i:q(i)?Array.isArray(i.props.children)?i.props.children:k(i.props.children)?[]:[i.props.children]:[i];for(let x of T)Array.isArray(x)||q(x)?r(x,h):h.push(x);return h}return r(t,[])}function Ce(t){return t.toString()}function W(t){return!k(t)&&t.__is_forgo_element__===!0}function ke(t){return W(t)&&typeof t.type=="string"}function q(t){return!k(t)&&t.type===ve}function v(t){return t.__forgo===void 0&&(t.__forgo={components:[],lookups:{deletedKeyedComponentNodes:new Map,deletedUnkeyedNodes:[],keyedComponentNodes:new Map,newlyAddedKeyedComponentNodes:new Map,deletedKeyedElementNodes:new Map,keyedElementNodes:new Map,newlyAddedKeyedElementNodes:new Map,renderCount:0}}),t.__forgo}function Z(t,r){t.__forgo=r}var Fe=t=>{let r=T=>({get element(){return T.__internal.element},update(x){return T.update(x)}}),i={render(T,x){return t.render(T,r(x))}};t.error&&(i.error=(T,x)=>t.error(T,Object.assign(r(h),{error:x})));let h=new M(F({},i));return t.mount&&h.mount(T=>{t.mount(T,r(h))}),t.remount&&h.remount(T=>{t.remount(T,r(h))}),t.unmount&&h.unmount(T=>{t.unmount(T,r(h))}),t.afterRender&&h.afterRender((T,x)=>{t.afterRender(T,Object.assign(r(h),{previousNode:x}))}),t.shouldUpdate&&h.shouldUpdate((T,x)=>t.shouldUpdate(T,x)),h};function I(t,r){return`$Component${r}_${t}`}function He(t,r,i){if(!(r instanceof M)&&Reflect.has(r,"render"))return i&&(console.warn("Legacy component syntax is deprecated since v3.2.0 and will be removed in v5.0. The affected component was found here:"),console.warn(new Error().stack)),Fe(r);if(!(r instanceof M))throw new Error(`${t.name||"Unnamed"} component constructor must return an instance of the Component class`);return r}function k(t){return t==null}function Q(t){return typeof t=="string"}function O(t){return t.nodeType===B}function _e(t){return typeof t=="string"?t:t==null?"":Object.keys(t).reduce((r,i)=>r+i.split(/(?=[A-Z])/).join("-").toLowerCase()+":"+t[i]+";","")}function ee(t){return t.key!==void 0}function ne(t,r,i){let h=[];for(let T=r;T<i;T++)h.push(t[T]);return h}function L(t,r,i){t.node=r,t.nodeIndex=i}function te(t,r,i){if(r===void 0)return-1;for(let h=i;h<t.length;h++)if(t[h]===r)return h;return-1}(r=>r.JSX=S)(j||(j={}));export{M as Component,ve as Fragment,S as JSX,j as createElement,re as createForgoInstance,v as getForgoState,Me as h,Fe as legacyComponentSyntaxCompat,Ae as mount,Ie as render,Pe as rerender,Re as setCustomEnv,Z as setForgoState,Se as unmount};
//# sourceMappingURL=forgo.min.js.map

@@ -16,2 +16,3 @@ export type ForgoRef<T> = {

node?: ChildNode;
nodeIndex: number;
componentIndex: number;

@@ -18,0 +19,0 @@ };

@@ -71,3 +71,3 @@ // Since we'll set any attribute the user passes us, we need to be sure not to

},
element: { componentIndex: -1 },
element: { componentIndex: -1, nodeIndex: -1 },
};

@@ -201,4 +201,7 @@ }

}
syncAttrsAndState(forgoNode, node, insertionOptions.currentNodeIndex, true, pendingAttachStates);
}
syncAttrsAndState(forgoNode, node, true, pendingAttachStates);
else {
syncAttrsAndState(forgoNode, node, -1, true, pendingAttachStates);
}
return {

@@ -272,3 +275,3 @@ nodes: [node],

}
syncAttrsAndState(forgoElement, targetElement, false, pendingAttachStates);
syncAttrsAndState(forgoElement, targetElement, insertionOptions.currentNodeIndex, false, pendingAttachStates);
renderChildNodes(targetElement);

@@ -303,4 +306,11 @@ return {

parentElement.insertBefore(newElement, oldNode !== null && oldNode !== void 0 ? oldNode : null);
syncAttrsAndState(forgoElement, newElement, insertionOptions.type === "search"
? insertionOptions.currentNodeIndex
: findNodeIndex(parentElement.childNodes, newElement, 0), true, pendingAttachStates);
}
syncAttrsAndState(forgoElement, newElement, true, pendingAttachStates);
else {
syncAttrsAndState(forgoElement, newElement, insertionOptions.type === "search"
? insertionOptions.currentNodeIndex
: -1, true, pendingAttachStates);
}
renderChildNodes(newElement);

@@ -376,5 +386,4 @@ return { nodes: [newElement] };

else {
const indexOfNode = findNodeIndex(insertionOptions.parentElement.childNodes, componentState.component.__internal.element.node, insertionOptions.currentNodeIndex);
return {
nodes: sliceNodes(insertionOptions.parentElement.childNodes, indexOfNode, indexOfNode + componentState.nodes.length),
nodes: componentState.nodes,
};

@@ -419,4 +428,5 @@ }

componentStateAttached.nodes = renderResult.nodes;
componentStateAttached.component.__internal.element.node =
renderResult.nodes[0];
setNodeInfo(componentStateAttached.component.__internal.element, renderResult.nodes[0], insertionOptions.type !== "detached"
? insertionOptions.currentNodeIndex
: -1);
lifecycleEmitters.mount(newComponentState.component, forgoComponent.props);

@@ -472,4 +482,3 @@ // No previousNode since new component. So just args and not

componentStateAttached.nodes = renderResult.nodes;
componentStateAttached.component.__internal.element.node =
renderResult.nodes[0];
setNodeInfo(componentStateAttached.component.__internal.element, renderResult.nodes[0], insertionOptions.currentNodeIndex);
}

@@ -736,3 +745,3 @@ return renderResult;

*/
function syncAttrsAndState(forgoNode, node, isNewNode, pendingAttachStates) {
function syncAttrsAndState(forgoNode, node, nodeIndex, isNewNode, pendingAttachStates) {
var _a;

@@ -743,3 +752,4 @@ // We have to inject node into the args object.

if (pendingAttachStates.length > 0) {
pendingAttachStates[pendingAttachStates.length - 1].component.__internal.element.node = node;
setNodeInfo(pendingAttachStates[pendingAttachStates.length - 1].component.__internal
.element, node, nodeIndex);
}

@@ -924,5 +934,8 @@ if (isForgoElement(forgoNode)) {

function rerender(element, props) {
if (!(element === null || element === void 0 ? void 0 : element.node)) {
if (element === undefined || element.node === undefined) {
throw new Error(`Missing node information in rerender() argument.`);
}
if (element.node.parentElement !== null && element.nodeIndex === -1) {
element.nodeIndex = findNodeIndex(element.node.parentElement.childNodes, element.node, 0);
}
const parentElement = element.node.parentElement;

@@ -934,5 +947,4 @@ if (!isNullOrUndefined(parentElement)) {

if (!lifecycleEmitters.shouldUpdate(originalComponentState.component, effectiveProps, originalComponentState.props)) {
const indexOfNode = findNodeIndex(parentElement.childNodes, element.node, 0);
return {
nodes: sliceNodes(parentElement.childNodes, indexOfNode, indexOfNode + originalComponentState.nodes.length),
nodes: sliceNodes(parentElement.childNodes, element.nodeIndex, element.nodeIndex + originalComponentState.nodes.length),
};

@@ -946,6 +958,5 @@ }

const forgoNode = originalComponentState.component.__internal.registeredMethods.render(effectiveProps, originalComponentState.component);
const nodeIndex = findNodeIndex(parentElement.childNodes, element.node, 0);
const insertionOptions = {
type: "search",
currentNodeIndex: nodeIndex,
currentNodeIndex: element.nodeIndex,
length: originalComponentState.nodes.length,

@@ -978,3 +989,3 @@ parentElement,

// The root node might have changed, so fix it up just in case.
parentState.component.__internal.element.node = parentState.nodes[0];
setNodeInfo(parentState.component.__internal.element, parentState.nodes[0], indexOfOriginalRootNode);
}

@@ -1223,6 +1234,2 @@ }

}
/**
* node.childNodes is some funky data structure that's not really not an array,
* so we can't just slice it like normal
*/
function sliceNodes(nodes, from, to) {

@@ -1235,6 +1242,6 @@ const result = [];

}
/**
* node.childNodes is some funky data structure that's not really not an array,
* so we can't just search for the value like normal
*/
function setNodeInfo(element, node, nodeIndex) {
element.node = node;
element.nodeIndex = nodeIndex;
}
function findNodeIndex(nodes, element, startSearchFrom) {

@@ -1241,0 +1248,0 @@ if (element === undefined)

{
"name": "forgo",
"version": "4.0.5",
"version": "4.0.6",
"main": "./dist/forgo.min.js",

@@ -5,0 +5,0 @@ "type": "module",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc