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