redgin 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/redgin.min.js +1 -1
- package/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/redgin.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var U=Object.defineProperty;var
|
|
1
|
+
var U=Object.defineProperty;var W=(e,t,n)=>t in e?U(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var g=(e,t,n)=>(W(e,typeof t!="symbol"?t+"":t,n),n);function d(){return"id-"+Math.random().toString(16).slice(2)+"-"+Date.now()}var S=e=>e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`),u=e=>e.replace(/-./g,t=>t[1].toUpperCase());function T(e){let t=[];for(let n of p.reg)t.push(n.call(this,e));return t.filter(n=>n===!0).length>0}var m=class{static define(t){m.reg.push(t)}},p=m;g(p,"reg",[]);var k=(e,t)=>{let n=d(),r=window.__redgin_current_instance;if(r){for(let s=0;s<e.length;s++){let a=e[s],c=r._watchRegistry.get(a);c||(c=new Map,r._watchRegistry.set(a,c)),c.set(n,t)}r._idToProps.set(n,e)}return`<in-watch data-watch="${n}"></in-watch>`},y=class extends HTMLElement{disconnectedCallback(){let t=this.dataset.watch,r=this.getRootNode()?.host;t&&r&&r._cleanupWatch(t)}};customElements.get("in-watch")||customElements.define("in-watch",y);var A=e=>Array.isArray(e)?e.map(A).join(""):e===void 0?"":String(e);p.define(function(t){let n=u(t),r=this._watchRegistry.get(n);if(!r)return!1;let s=!1;for(let[a,c]of r){let i=this._watchElements.get(a);if((!i||!i.isConnected)&&(i=this.shadowRoot.querySelector(`[data-watch="${a}"]`),i&&this._watchElements.set(a,i)),i){let o=c?c.call(this):this[n],l=A(o);i.innerHTML!==String(l)&&(i.innerHTML=l,s=!0)}}return s});var q=e=>{let t=d(),n=window.__redgin_current_instance;if(n){let r=e.toString(),s=/this\.([a-zA-Z_$][\w$]*)/g,a,c=new Set;for(;(a=s.exec(r))!==null;){let i=a[1];n._reactiveCache?.includes(i)&&c.add(i)}for(let i of c){let o=n._watchRegistry.get(i);o||(o=new Map,n._watchRegistry.set(i,o)),o.set(t,e)}n._idToProps.set(t,Array.from(c))}return`<in-watch data-watch="${t}"></in-watch>`};var I=(e,t)=>{let n=d(),r=window.__redgin_current_instance;if(r){let s=t.toString(),a=/this\.([a-zA-Z_$][\w$]*)/g,c,i=new Set;for(;(c=a.exec(s))!==null;){let o=c[1];r._reactiveCache&&r._reactiveCache.includes(o)&&i.add(o)}for(let o of i){r._attrRegistry||(r._attrRegistry=new Map);let l=r._attrRegistry.get(o);l||(l=new Map,r._attrRegistry.set(o,l)),l.set(n,{attrName:e,exp:t})}}return`rg-attr__${e}="${n}"`};p.define(function(t){let n=u(t),r=this._attrRegistry?.get(n);if(!r)return!1;let s=!1;for(let[a,c]of r){let i=this._attrElements.get(a);if((!i||!i.isConnected)&&(i=this.shadowRoot.querySelector(`[rg-attr__${c.attrName}="${a}"]`),i&&this._attrElements.set(a,i)),i){let o=c.exp?c.exp.call(this):this[n],l=c.attrName;if(o===!1||o===null||o===void 0)i.hasAttribute(l)&&(i.removeAttribute(l),s=!0);else{let _=o===!0?"":String(o);i.getAttribute(l)!==_&&(i.setAttribute(l,_),s=!0)}}}return s});var C=(e,t)=>{let n=d(),r=window.__redgin_current_instance;return r&&(r._eventRegistry||(r._eventRegistry=new Map),r._eventRegistry.set(n,[e,t])),`rg-evt__${e}="${n}"`},L=C;function O(e,t,n){let r={detail:t,composed:!0},s=new CustomEvent(e,{...r,...n});this.shadowRoot&&this.shadowRoot.dispatchEvent(s)}function w(){if(!(!this._eventElements||!this._eventRegistry))for(let[e,t]of this._eventElements){let n=this._eventRegistry.get(e);if(!n)continue;let[r,s]=n;t.addEventListener(r,s)}}function $(){if(!(!this._eventElements||!this._eventRegistry))for(let[e,t]of this._eventElements){let n=this._eventRegistry.get(e);if(!n)continue;let[r,s]=n;t.removeEventListener(r,s)}}function P(e,t){for(let n of f.reg)n.call(this,e,t)}var b=class{static define(t){b.reg.push(t)}},f=b;g(f,"reg",[]);var D=["^class$","^style$","^className$","^classList$","^dataset$","^data-","^aria-","^hidden$","^tabindex$","^slot$","^contenteditable$","^draggable$","^spellcheck$"],F=D.map(e=>new RegExp(e)),j=new Set(["disabled","hidden","checked","selected","readonly","multiple"]),H=e=>{for(let t of F)if(t.test(e))return console.error(`Please remove attribute '${e}' from observedAttributes; browser already provides built-in reflection.`),!1;return!0};function z(e,t){if(!t||t.name!=="propReflect")return;let{type:n,value:r,serializerFn:s,deserializerFn:a}=t,c=this.constructor.observedAttributes,i=u(e),o=S(e);if(!c?.includes(o)){console.error(`propReflect '${i}' cannot map to '${o}'. Add '${o}' to observedAttributes of ${this.constructor.name}.`);return}if(!H(o))return;let l=n===Boolean||j.has(o)||typeof r=="boolean",_=n===Object||n===Array||["object","array"].includes(typeof r),R=n===String||n===Number||["string","number"].includes(typeof r);Object.defineProperty(this,i,{configurable:!0,set(h){if(a)return a.call(this,o,n,r,h);l?h?this.setAttribute(o,""):this.removeAttribute(o):_&&h!=null?this.setAttribute(o,JSON.stringify(h)):R&&h!=null?this.setAttribute(o,h):this.removeAttribute(o)},get(){if(s)return s.call(this,o,n,r);if(l)return this.hasAttribute(o);if(!this.hasAttribute(o))return r;if(_)try{return JSON.parse(this.getAttribute(o))}catch{return r}if(R){let h=this.getAttribute(o);return n===Number?Number(h):h}return this.getAttribute(o)}})}function B(e,t){return{value:e,...t,name:"propReflect"}}f.define(z);function G(e,t){if(t===void 0||t?.name!="getset")return;let{value:n,forWatch:r}=t,s=`#${e}`;this[s]=n,Object.defineProperty(this,e,{configurable:!0,set(a){this[s]!==a&&(this[s]=a,r&&this.requestUpdate(e))},get(){return this[s]}})}function K(e,t){return{value:e,...{forWatch:!0},...t,name:"getset"}}f.define(G);var M=new Map,E=[],Z=":host{display:block}";function v(e,t){let n=Array.isArray(e)?e:[e],r=[];if(!t)return n.join("");for(let s of n){if(s.startsWith("<link")){let a=s.match(/href="([^"]+)"/)?.[1];if(a&&!t.querySelector(`link[href="${a}"]`)){let c=document.createElement("div");c.innerHTML=s;let i=c.firstElementChild;i&&t.appendChild(i)}continue}if("adoptedStyleSheets"in t){let a=M.get(s);a||(a=new CSSStyleSheet,a.replaceSync(s),M.set(s,a)),t.adoptedStyleSheets=[...t.adoptedStyleSheets,a];continue}r.push(`<style>${s}</style>`)}return r.join("")}function Mt(e){E.includes(e)||E.push(e)}var x=e=>Array.isArray(e)?e.map(x).join(""):e===void 0?"":String(e),J=(e,...t)=>e.reduce((n,r,s)=>n+r+x(t[s]),""),V={"&":"&","<":"<",">":">",'"':""","'":"'"},Nt=e=>x(e).replace(/[&<>"']/g,n=>V[n]),Ut=J,N=class extends HTMLElement{_pending=!1;_changed=new Set;_connected=!1;_reactiveCache=[];_watchRegistry=new Map;_idToProps=new Map;_watchElements=new Map;_attrRegistry=new Map;_attrElements=new Map;_eventElements=new Map;styles=[];constructor(){super(),this.attachShadow({mode:"open",delegatesFocus:!0})}connectedCallback(){this._connected||(this._connected=!0,this._init())}disconnectedCallback(){$.call(this)}attributeChangedCallback(t,n,r){n!==r&&this.requestUpdate(t)}requestUpdate(t){this._changed.add(t),!this._pending&&(this._pending=!0,queueMicrotask(()=>this._flush()))}_flush(){if(this._pending=!1,!this._changed.size)return;let t=Array.from(this._changed);this._changed.clear();let n=!1;window.__redgin_current_instance=this;for(let r of t)this._update(r)&&(n=!0);window.__redgin_current_instance=null,n?this._afterUpdate():this._afterUpdateNoDomChange()}_init(){this._setupProps(),window.__redgin_current_instance=this,this.shadowRoot&&(v(E,this.shadowRoot),v(Z,this.shadowRoot),v(this.styles,this.shadowRoot),this.shadowRoot.innerHTML+=this.render()),this._collectElements(),this.onInit(),this._sync(),window.__redgin_current_instance=null}_collectElements(t="all"){if(!this.shadowRoot)return;t==="all"&&(this._watchElements.clear(),this._attrElements.clear()),this._eventElements.clear();let n=document.createTreeWalker(this.shadowRoot,NodeFilter.SHOW_ELEMENT,null),r;for(;r=n.nextNode();){let s=r.attributes;for(let a=0;a<s.length;a++){let{name:c,value:i}=s[a];c.startsWith("rg-evt__")?this._eventElements.set(i,r):t==="all"&&(c==="data-watch"?this._watchElements.set(i,r):c.startsWith("rg-attr__")&&this._attrElements.set(i,r))}}}_cleanupWatch(t){let n=this._idToProps.get(t);if(n){for(let r of n){let s=this._watchRegistry.get(r);s&&(s.delete(t),s.size||this._watchRegistry.delete(r))}this._idToProps.delete(t),this._watchElements.delete(t)}}_sync(){for(let t of this._reactiveProps())this._update(t);this._collectElements(),w.call(this),this.onDoUpdate()}_update(t){return T.call(this,t)}_afterUpdate(){this._collectElements("events"),w.call(this),this.onUpdated()}_afterUpdateNoDomChange(){this.onUpdated()}_setupProps(){if(!this._reactiveCache.length){let t=new Set(["styles","_pending","_changed","_connected"]);this._reactiveCache=Object.getOwnPropertyNames(this).filter(n=>!t.has(n))}for(let t of this._reactiveCache)P.call(this,t,this[t])}_reactiveProps(){return this._reactiveCache}onInit(){}onDoUpdate(){}onUpdated(){}render(){return""}};export{N as RedGin,v as _applyStyle,x as _f,I as attr,Ut as css,p as customDirectives,f as customPropsBehavior,Z as defaultStyle,O as emit,C as event,K as getset,J as html,L as on,B as propReflect,q as s,Nt as safe,Mt as shareStyle,E as shared,k as watch};
|
|
2
2
|
//# sourceMappingURL=redgin.min.js.map
|
package/index.d.ts
CHANGED