@fluffjs/fluff 0.1.6 → 0.1.8
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/package.json +1 -1
- package/runtime/FluffBase.js +3 -0
- package/bundle.min.js +0 -1
package/package.json
CHANGED
package/runtime/FluffBase.js
CHANGED
|
@@ -89,6 +89,9 @@ export class FluffBase extends HTMLElement {
|
|
|
89
89
|
this.__baseSubscriptions.push(sub);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
else if (!(propName in scope.locals) && !(propName in scope.host)) {
|
|
93
|
+
console.warn(`Binding dependency "${propName}" not found on component ${scope.host.constructor.name}`);
|
|
94
|
+
}
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
__getReactivePropFromScope(propName, scope) {
|
package/bundle.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var A=new Map;function N(i){return function(t){let e={...i,inputs:new Map,outputs:new Map};if(A.set(t,e),i.pipes&&i.pipes.length>0){let n={};for(let r of i.pipes){let s=r.__pipeName;if(s){let o=new r;n[s]=(c,...a)=>o.transform(c,...a)}}Reflect.set(t.prototype,"__pipes",n)}return t}}function v(i){return A.get(i)}var b=class{static getOrCreateArray(t,e){let n=Reflect.get(t,e);if(this.isTypedArray(n))return n;let r=[];return Reflect.set(t,e,r),r}static isTypedArray(t){return Array.isArray(t)}};function $(i){return function(t,e){let n=t.constructor;b.getOrCreateArray(n,"__hostBindings").push({property:String(e),hostProperty:i})}}function H(i){return function(t,e,n){let r=t.constructor;return b.getOrCreateArray(r,"__hostListeners").push({method:String(e),event:i}),n}}function W(i){return typeof i=="function"}function M(i){return function(t){return function(e,n){let{constructor:r}=e;if(!W(r))return;let s=v(r);if(s){let o=t??String(n);s[i].set(String(n),o)}}}}var V=M("inputs");var D=M("outputs");function z(i){return function(t){return t.__pipeName=i,t}}function j(){return(i,t)=>{}}function J(i){return function(t,e){let n=t.constructor;b.getOrCreateArray(n,"__viewChildren").push({property:String(e),selector:i})}}function q(...i){return function(t,e,n){let r=n.value;return typeof r=="function"&&Reflect.set(t,`__watch_${String(e)}`,r),n}}var m=class{static isCustomElement(t){let e=t.tagName.toLowerCase();return customElements.get(e)!==void 0}};var _;(function(i){i[i.Any=0]="Any",i[i.Inbound=1]="Inbound",i[i.Outbound=2]="Outbound"})(_||(_={}));var h=class{callbacks=new Set;async emit(t){for(let e of this.callbacks)try{await e(t)}catch(n){console.error(n)}}subscribe(t){return this.callbacks.add(t),{unsubscribe:()=>{this.callbacks.delete(t)}}}subscribeOnce(t){let e=async n=>{this.callbacks.delete(e),await t(n)};return this.callbacks.add(e),{unsubscribe:()=>{this.callbacks.delete(e)}}}};function F(i){let t=new WeakSet;return JSON.stringify(i,(e,n)=>{if(typeof n=="object"&&n!==null){if(t.has(n))return"[Circular]";t.add(n)}return n})}var l=class{onChange=new h;onInboundChange=new h;onOutboundChange=new h;value;committed=!0;_isChanging=!1;_propName;constructor(t){this.isOptionsObject(t)?(t.initialValue!==void 0&&(this.value=t.initialValue),t.propertyName!==void 0&&(this._propName=t.propertyName)):this.value=t}setValue(t,e=!1,n=!0){if(this._isChanging){console.error((this._propName?this._propName+": ":"")+"Binding loop detected: setValue called while change is in progress");return}if(t!==this.value&&F(t)!==F(this.value)){this._isChanging=!0;try{this.value=t,this.onChange.emit(t).catch(s=>{console.error(s)}),n||(this.committed=!1),e?(this.committed=!0,this.onInboundChange.emit(t).catch(s=>{console.error(s)})):(n||!this.committed)&&(this.committed=!0,this.value!==void 0&&this.onOutboundChange.emit(this.value).catch(s=>{console.error(s)}))}finally{this._isChanging=!1}}}async triggerChange(t=_.Any){this.value!==void 0&&(await this.onChange.emit(this.value),t==_.Outbound&&await this.onOutboundChange.emit(this.value),t==_.Inbound&&await this.onOutboundChange.emit(this.value))}subscribe(t,e){return t==_.Inbound?this.onInboundChange.subscribe(n=>{e(n)}):t==_.Outbound?this.onOutboundChange.subscribe(n=>{e(n)}):this.onChange.subscribe(n=>{e(n)})}getValue(){return this.value===void 0?null:this.value}isOptionsObject(t){return typeof t=="object"&&t!==null&&"initialValue"in t}};var C=class i extends HTMLElement{static __e=[];static __h=[];static __bindings={};__parentScope;__loopContext={};__baseSubscriptions=[];__getScope(){return{host:this,locals:this.__loopContext,parent:this.__parentScope}}__processBindingsOnElement(t,e,n){let r=t.getAttribute("data-lid");if(!r)return;let s=this.__getBindingsForLid(r);if(!(!s||s.length===0))for(let o of s)this.__applyBindingWithScope(t,o,e,n)}__getBindingsForLid(t){let e=this.constructor;if(typeof e=="function"){let n=Reflect.get(e,"__bindings");if(this.__isBindingsMap(n))return n[t]}}__isBindingsMap(t){return!(!t||typeof t!="object")}__applyBindingWithScope(t,e,n,r){switch(e.binding){case"property":this.__applyPropertyBindingWithScope(t,e,n,r);break;case"event":this.__applyEventBindingWithScope(t,e,n);break;case"two-way":this.__applyTwoWayBindingWithScope(t,e,n,r);break;case"class":this.__applyClassBindingWithScope(t,e,n,r);break;case"style":this.__applyStyleBindingWithScope(t,e,n,r);break;case"ref":break}}__getCompiledExprFn(t){let e=i.__e[t];if(typeof e!="function")throw new Error(`Missing compiled expression function for exprId ${t}`);return e}__getCompiledHandlerFn(t){let e=i.__h[t];if(typeof e!="function")throw new Error(`Missing compiled handler function for handlerId ${t}`);return e}__subscribeToExpressionInScope(t,e,n,r){if(t)for(let s of t){let o=Array.isArray(s)?s[0]:s,c=this.__getReactivePropFromScope(o,e);if(c){let a=c.onChange.subscribe(n);r?r.push(a):this.__baseSubscriptions.push(a)}}}__getReactivePropFromScope(t,e){if(t in e.locals)return;let n=`__${t}`;if(n in e.host){let r=Reflect.get(e.host,n);if(r instanceof l)return r}if(e.parent)return this.__getReactivePropFromScope(t,e.parent)}__setChildProperty(t,e,n){let r=Reflect.get(t,e);if(r instanceof l)r.setValue(n,!0);else if(m.isCustomElement(t)){let s=t.tagName.toLowerCase();customElements.whenDefined(s).then(()=>{t instanceof i&&Reflect.set(t,e,n)}).catch(console.error)}else e in t?Reflect.set(t,e,n):t.setAttribute(e,String(n))}__applyPropertyBindingWithScope(t,e,n,r){let s=t.tagName.toLowerCase(),o=customElements.get(s)!==void 0,c=()=>{try{if(typeof e.exprId!="number")throw new Error(`Binding for ${e.name} is missing exprId`);let p=this.__getCompiledExprFn(e.exprId)(this,n.locals);this.__setChildProperty(t,e.name,p)}catch(a){console.error("Property binding error:",a)}};this.__subscribeToExpressionInScope(e.deps,n,c,r),e.subscribe&&this.__subscribeToExpressionInScope([e.subscribe],n,c,r),o?(t instanceof i||customElements.upgrade(t),t instanceof i?c():customElements.whenDefined(s).then(()=>{t instanceof i&&c()}).catch(console.error)):c()}__applyEventBindingWithScope(t,e,n){if(typeof e.handlerId!="number")throw new Error(`Event binding for ${e.name} is missing handlerId`);let r=this.__getCompiledHandlerFn(e.handlerId);t.hasAttribute("x-fluff-component")?this.__applyOutputBinding(t,e.name,r,n):t.addEventListener(e.name,s=>{try{r(this,n.locals,s)}catch(o){console.error("Event binding error:",o)}})}__applyOutputBinding(t,e,n,r){let s=()=>{let c=Reflect.get(t,e);if(c instanceof h){let a=c.subscribe(p=>{try{n(this,r.locals,p)}catch(g){console.error("Output binding error:",g)}});return this.__baseSubscriptions.push(a),!0}return!1};if(s())return;let o=t.tagName.toLowerCase();customElements.whenDefined(o).then(()=>{customElements.upgrade(t),s()}).catch(console.error)}__applyTwoWayBindingWithScope(t,e,n,r){if(this.__applyPropertyBindingWithScope(t,e,n,r),typeof e.targetProp!="string"||e.targetProp.length===0)throw new Error(`Two-way binding for ${e.name} is missing targetProp`);let s=this.__getReactivePropFromScope(e.targetProp,n),o=Reflect.get(t,e.name);if(s&&o instanceof l){let c=o.onChange.subscribe(a=>{s.setValue(a,!0)});r?r.push(c):this.__baseSubscriptions.push(c)}}__applyClassBindingWithScope(t,e,n,r){let s=()=>{try{if(typeof e.exprId!="number")throw new Error(`Class binding for ${e.name} is missing exprId`);this.__getCompiledExprFn(e.exprId)(this,n.locals)?t.classList.add(e.name):t.classList.remove(e.name)}catch(o){console.error("Class binding error:",o)}};this.__subscribeToExpressionInScope(e.deps,n,s,r),s()}__applyStyleBindingWithScope(t,e,n,r){let s=()=>{try{if(typeof e.exprId!="number")throw new Error(`Style binding for ${e.name} is missing exprId`);let c=this.__getCompiledExprFn(e.exprId)(this,n.locals);t.style.setProperty(e.name,String(c))}catch(o){console.error("Style binding error:",o)}};this.__subscribeToExpressionInScope(e.deps,n,s,r),s()}};var L=new Map,G=0;function B(i){let t=`scope_${G++}`;return L.set(t,i),t}function O(i){return L.get(i)}var x=class extends C{__pipes={};_shadowRoot;_subscriptions=[];_initialized=!1;_markerManager=null;_markerConfigJson=null;constructor(){super(),this._shadowRoot=this.attachShadow({mode:"open"})}connectedCallback(){if(!this._initialized){let t=this.getAttribute("data-fluff-scope-id");t&&!this.__parentScope&&(this.__parentScope=O(t),this.__parentScope&&(this.__loopContext=this.__parentScope.locals));let e=this.getAttribute("data-fluff-loop-context");if(e&&Object.keys(this.__loopContext).length===0)try{this.__loopContext=JSON.parse(e)}catch{}this.__applyPendingProps(),this.__render(),this.__setupBindings(),this.getAttribute("data-fluff-scope-id")&&this.__processBindings(),this._initialized=!0,"onInit"in this&&typeof this.onInit=="function"&&this.onInit()}}disconnectedCallback(){"onDestroy"in this&&typeof this.onDestroy=="function"&&this.onDestroy(),this._markerManager&&(this._markerManager.cleanup(),this._markerManager=null);for(let t of this._subscriptions)t.unsubscribe();this._subscriptions=[];for(let t of this.__baseSubscriptions)t.unsubscribe();this.__baseSubscriptions=[]}$watch=(t,e)=>(e(),{unsubscribe:()=>{}});__processBindingsOnElementPublic(t,e,n){this.__processBindingsOnElement(t,e,n)}__addSubscription(t){this._subscriptions.push(t)}__pipe(t,e,...n){let r=this.__pipes[t];return r?r(e,...n):(console.warn(`Pipe "${t}" not found`),e)}__getShadowRoot(){return this._shadowRoot}__setMarkerConfigs(t){this._markerConfigJson=t}__initializeMarkers(t){this._markerConfigJson&&(this._markerManager=new t(this,this._shadowRoot),this._markerManager.initializeFromConfig(this._markerConfigJson))}__getElement(t){return this._shadowRoot.querySelector(`[data-lid="${t}"]`)}__setText(t,e){let n=this.__getElement(t);n&&(n.textContent=e)}__bindText(t,e){let n=this.__getElement(t);if(!n)return;let r=n.getAttribute("data-text-bind")??"",s=/this\.([a-zA-Z_][a-zA-Z0-9_]*)/.exec(r),o=()=>{try{n.textContent=e()}catch{n.textContent=""}};if(s){let[,c]=s,a=this.__getReactiveProp(c);a&&this.__bindPropertyChange(a,o)}o()}__setProperty(t,e,n){let r=this.__getElement(t);this.isHTMLElement(r)&&(e in r?Reflect.set(r,e,n):r.setAttribute(e,String(n)))}__addClass(t,e){let n=this.__getElement(t);this.isHTMLElement(n)&&n.classList.add(e)}__removeClass(t,e){let n=this.__getElement(t);this.isHTMLElement(n)&&n.classList.remove(e)}__bindEvent(t,e,n){let r=this.__getElement(t);r&&r.addEventListener(e,n)}__bindPropertyChange(t,e){let n=t.onChange.subscribe(e);this._subscriptions.push(n);let r=t.getValue();r!==null&&e(r)}__connectProperties(t,e){let n=t.onChange.subscribe(s=>{e.setValue(s,!0)});this._subscriptions.push(n);let r=t.getValue();r!==null&&e.setValue(r,!0)}__connectOutput(t,e){let n=t.subscribe(e);this._subscriptions.push(n)}__bindOutput(t,e,n){let r=this.__getElement(t);r&&this.__bindOutputOnElement(r,e,n)}__setChildProperty(t,e,n){if(t instanceof HTMLElement&&t.hasAttribute("x-fluff-component")){let s=t.tagName.toLowerCase();if(customElements.get(s)===void 0){customElements.whenDefined(s).then(()=>{customElements.upgrade(t),this.__setChildProperty(t,e,n)}).catch(console.error);return}}let r=Reflect.get(t,e);r instanceof l?r.setValue(n,!0):e in t?Reflect.set(t,e,n):t.setAttribute(e,String(n))}__bindToChild(t,e,n){let r=this.__getElement(t);r&&this.__setChildPropertyDeferred(r,e,n)}__setChildPropertyDeferred(t,e,n){if(Reflect.get(t,e)!==void 0){this.__setChildProperty(t,e,n);return}if(m.isCustomElement(t)){let r=t.tagName.toLowerCase();customElements.whenDefined(r).then(()=>{this.__setChildProperty(t,e,n)}).catch(s=>{console.error(s)})}else this.__setChildProperty(t,e,n)}__bindOutputOnElement(t,e,n){let r=Reflect.get(t,e);if(r instanceof h){this.__connectOutput(r,n);return}if(m.isCustomElement(t)){let s=t.tagName.toLowerCase();customElements.whenDefined(s).then(()=>{let o=Reflect.get(t,e);o instanceof h?this.__connectOutput(o,n):t.addEventListener(e,n)}).catch(o=>{console.error(o)})}else t.addEventListener(e,n)}__getReactivePropFromScope(t,e){let n=`__${t}`;if(n in e.host){let r=Reflect.get(e.host,n);if(r instanceof l)return r}if(e.parent)return this.__getReactivePropFromScope(t,e.parent)}__processBindings(){let t=this._shadowRoot.querySelectorAll("[data-lid]"),e=this.__getScope();for(let n of Array.from(t))if(!n.closest("[x-fluff-component]")&&n instanceof HTMLElement){let r=n.tagName.toLowerCase();if(customElements.get(r))continue;this.__processBindingsOnElement(n,e)}}__applyPendingProps(){let t=Reflect.get(this,"__pendingProps");if(this.isRecord(t)){for(let[e,n]of Object.entries(t)){console.log("apply-pending-prop",{propName:e,value:n,el:this.tagName});let r=`__${e}`;if(r in this){let s=Reflect.get(this,r);s instanceof l&&s.setValue(n,!0)}else e in this&&Reflect.set(this,e,n)}Reflect.deleteProperty(this,"__pendingProps")}}isHTMLElement(t){return t!==null}isRecord(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}__getReactiveProp(t){let e=`__${t}`;if(e in this){let n=Reflect.get(this,e);if(n instanceof l)return n}}};var d=class{static isFluffHostElement(t){return"__getReactiveProp"in t}static isIfConfig(t){return t.type==="if"}static isForConfig(t){return t.type==="for"}static isSwitchConfig(t){return t.type==="switch"}static isTextConfig(t){return t.type==="text"}static isBreakConfig(t){return t.type==="break"}};var f=class{id;startMarker;endMarker;subscriptions=[];host;shadowRoot;parentScope;loopContext={};markerManager;constructor(t,e,n,r,s){this.id=t,this.startMarker=e,this.endMarker=n,this.host=r,this.shadowRoot=s}setParentScope(t){this.parentScope=t}setLoopContext(t){this.loopContext=t}setMarkerManager(t){this.markerManager=t}cleanup(){for(let t of this.subscriptions)t.unsubscribe();this.subscriptions.length=0}updateRenderContext(t){}evaluateExpr(t){let e=this.getScope(),n=this.collectLocalsFromScope(e),r=this.getCompiledExprFn(t);try{return r(e.host,n)}catch{return}}getCompiledExprFn(t){let e=C.__e[t];if(typeof e!="function")throw new Error(`Missing compiled expression function for exprId ${t}`);return e}getScope(){if(this.parentScope)return this.parentScope;let t=this.__getFluffElementHost();return t?t.__getScope():{host:this.host,locals:this.loopContext,parent:void 0}}collectLocalsFromScope(t){let e={};return t.parent&&Object.assign(e,this.collectLocalsFromScope(t.parent)),Object.assign(e,t.locals),e}subscribeTo(t,e){let n=this.getScope();for(let r of t){let s=Array.isArray(r)?r[0]:r;if(s.startsWith("["))continue;let o=this.getReactivePropFromScope(s,n);if(o){let c=o.onChange.subscribe(e);this.subscriptions.push(c)}}}getReactivePropFromScope(t,e){if(!(t in e.locals)){if(e.parent)return this.getReactivePropFromScope(t,e.parent);if(d.isFluffHostElement(e.host)&&e.host.__getReactiveProp){let n=e.host.__getReactiveProp(t);if(n instanceof l)return n}}}createChildScope(t){return{host:this.host,locals:t,parent:this.parentScope}}clearContentBetweenMarkersWithCleanup(t){for(let r of t)r.unsubscribe();if(t.length=0,!this.endMarker)return;let e=this.startMarker.parentNode;if(!e)return;let n=this.startMarker.nextSibling;for(;n&&n!==this.endMarker;){let r=n.nextSibling;if(n instanceof Comment){let s=/^fluff:(if|for|switch|text|break):(\d+)$/.exec(n.data);if(s&&this.markerManager?.cleanupController){let o=parseInt(s[2],10);this.markerManager.cleanupController(o,n)}}n instanceof HTMLTemplateElement||e.removeChild(n),n=r}}insertBeforeEndMarker(t){if(!this.endMarker)return;let e=this.endMarker.parentNode;e&&e.insertBefore(t,this.endMarker)}processBindingsOnElement(t,e){let n=this.__getFluffElementHost();n&&n.__processBindingsOnElementPublic(t,e)}processBindingsOnElementWithSubscriptions(t,e,n){let r=this.__getFluffElementHost();r&&r.__processBindingsOnElementPublic(t,e,n)}__getFluffElementHost(){return this.host instanceof x?this.host:null}setScopeOnChildren(t,e,n,r,s){if(t instanceof Comment){let o=/^fluff:(if|for|switch|text|break):(\d+)$/.exec(t.data);if(o&&r){let[,c,a]=o,p=parseInt(a,10),g=`/fluff:${c}:${p}`,u=r.getController(p,t),R=u===void 0;if(!u&&r.ensureController){let T=null,y=t.nextSibling;for(;y;){if(y instanceof Comment&&y.data===g){T=y;break}y=y.nextSibling}u=r.ensureController(p,c,t,T)}u&&(u.setParentScope(e),u.setLoopContext(e.locals),u.updateRenderContext(n),R&&u.initialize())}}else if(t instanceof x)t.__loopContext=e.locals,t.__parentScope=e,this.processBindingsOnNode(t,e,s);else if(t instanceof HTMLElement&&m.isCustomElement(t)){let o=B(e);t.setAttribute("data-fluff-scope-id",o),this.processBindingsOnNode(t,e,s)}else t instanceof HTMLElement&&t.hasAttribute("data-lid")&&this.processBindingsOnNode(t,e,s);for(let o of Array.from(t.childNodes))this.setScopeOnChildren(o,e,n,r,s)}insertAndScopeTemplateContent(t,e,n,r,s,o){this.insertBeforeEndMarker(t);for(let c of e)this.setScopeOnChildren(c,n,r,s,o)}cloneAndInsertTemplate(t,e,n,r){let s=t.content.cloneNode(!0);if(!(s instanceof DocumentFragment))throw new Error("Expected DocumentFragment from template clone");let o=Array.from(s.childNodes),c=this.createChildScope(e);this.insertAndScopeTemplateContent(s,o,c,n,this.markerManager,r)}processBindingsOnNode(t,e,n){n?this.processBindingsOnElementWithSubscriptions(t,e,n):this.processBindingsOnElement(t,e)}};var S=class extends f{constructor(t,e,n,r,s,o){super(t,e,n,r,s)}initialize(){}updateRenderContext(t){t&&(t.shouldBreak=!0)}};var w=class extends f{config;itemTemplate=null;emptyTemplate=null;bindingsSubscriptions=[];constructor(t,e,n,r,s,o){super(t,e,n,r,s),this.config=o}initialize(){let e=`${this.host.tagName.toLowerCase()}-${this.id}`;this.itemTemplate=this.shadowRoot.querySelector(`template[data-fluff-tpl="${e}"]`),this.emptyTemplate=this.shadowRoot.querySelector(`template[data-fluff-empty="${e}"]`);let n=this.config.deps??[],r=()=>{this.clearContentBetweenMarkersWithCleanup(this.bindingsSubscriptions);let s=this.evaluateExpr(this.config.iterableExprId);if(!Array.isArray(s)||s.length===0){this.emptyTemplate&&this.cloneAndInsertTemplate(this.emptyTemplate,this.loopContext,void 0,this.bindingsSubscriptions);return}if(!this.itemTemplate)return;let o={shouldBreak:!1};for(let c=0;c<s.length&&!o.shouldBreak;c++){let a={...this.loopContext,[this.config.iterator]:s[c],$index:c};this.cloneAndInsertTemplate(this.itemTemplate,a,o,this.bindingsSubscriptions)}};this.subscribeTo(n,r),r()}};var E=class extends f{config;templates=[];currentBranchIndex=-1;bindingsSubscriptions=[];constructor(t,e,n,r,s,o){super(t,e,n,r,s),this.config=o}initialize(){let e=`${this.host.tagName.toLowerCase()}-${this.id}-`;this.templates=Array.from(this.shadowRoot.querySelectorAll(`template[data-fluff-branch^="${e}"]`));let n=[];for(let s of this.config.branches)s.deps&&n.push(...s.deps);let r=()=>{let s=-1;for(let o=0;o<this.config.branches.length;o++){let c=this.config.branches[o];if(c.exprId===void 0){s=o;break}if(this.evaluateExpr(c.exprId)){s=o;break}}s!==this.currentBranchIndex&&(this.clearContentBetweenMarkersWithCleanup(this.bindingsSubscriptions),this.currentBranchIndex=s,s>=0&&s<this.templates.length&&this.cloneAndInsertTemplate(this.templates[s],this.loopContext,void 0,this.bindingsSubscriptions))};this.subscribeTo(n,r),r()}};var k=class extends f{config;templates=[];bindingsSubscriptions=[];constructor(t,e,n,r,s,o){super(t,e,n,r,s),this.config=o}initialize(){let e=`${this.host.tagName.toLowerCase()}-${this.id}-`;this.templates=Array.from(this.shadowRoot.querySelectorAll(`template[data-fluff-case^="${e}"]`));let n=this.config.deps??[],r=()=>{this.clearContentBetweenMarkersWithCleanup(this.bindingsSubscriptions);let s=this.evaluateExpr(this.config.expressionExprId),o=!1,c=!1,a={shouldBreak:!1};for(let p=0;p<this.config.cases.length&&!a.shouldBreak;p++){let g=this.config.cases[p],u=this.templates[p];if(!u)continue;let R=g.isDefault||g.valueExprId!==void 0&&this.evaluateExpr(g.valueExprId)===s;(c||!o&&R)&&(o=!0,this.cloneAndInsertTemplate(u,this.loopContext,a,this.bindingsSubscriptions),c=g.fallthrough)}};this.subscribeTo(n,r),r()}};var P=class extends f{config;textNode=null;constructor(t,e,n,r,s,o){super(t,e,n,r,s),this.config=o}initialize(){this.textNode=document.createTextNode(""),this.insertBeforeEndMarker(this.textNode);let t=this.config.deps??[],e=this.config.pipes??[],n=()=>{let r=this.evaluateExpr(this.config.exprId);for(let s of e)r=this.applyPipe(s.name,r,s.argExprIds);this.textNode&&(this.textNode.textContent=this.formatValue(r))};this.subscribeTo(t,n),n()}formatValue(t){return t==null?"":typeof t=="object"?JSON.stringify(t):typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):""}applyPipe(t,e,n){let r=this.host.__pipes;if(!r)return e;let s=r[t];if(!s)return console.warn(`Pipe "${t}" not found`),e;let o=n.map(c=>this.evaluateExpr(c));return s(e,...o)}};var I=class{controllers=new Map;configs=new Map;host;shadowRoot;constructor(t,e){this.host=t,this.shadowRoot=e}initializeFromConfig(t){let e=JSON.parse(t);this.configs.clear();for(let[r,s]of e)this.configs.set(r,s);for(let[r,s]of e){let{startMarker:o,endMarker:c}=this.findMarkers(r,s.type);if(!o)continue;let a=this.createController(r,o,c,s);a&&(a.setMarkerManager(this),this.registerController(r,o,a))}let n=[];for(let r of this.controllers.values())n.push(...r.values());for(let r of n)r.initialize()}ensureController(t,e,n,r){let s=this.getController(t,n);if(s)return s;let o=this.configs.get(t);if(o?.type!==e)return;let c=this.createController(t,n,r,o);if(c)return c.setMarkerManager(this),this.registerController(t,n,c),c}getController(t,e){return this.controllers.get(t)?.get(e)}cleanupController(t,e){let n=this.controllers.get(t);if(n){if(e){let r=n.get(e);if(!r)return;r.cleanup(),n.delete(e),n.size===0&&this.controllers.delete(t);return}for(let r of n.values())r.cleanup();this.controllers.delete(t)}}cleanup(){for(let t of this.controllers.values())for(let e of t.values())e.cleanup();this.controllers.clear()}registerController(t,e,n){let r=this.controllers.get(t);r||(r=new Map,this.controllers.set(t,r)),r.set(e,n)}findMarkers(t,e){let n=`fluff:${e}:${t}`,r=`/fluff:${e}:${t}`,s=null,o=null,c=document.createTreeWalker(this.shadowRoot,NodeFilter.SHOW_COMMENT,null),a=c.nextNode();for(;a;)a instanceof Comment&&(a.data===n?s=a:a.data===r&&(o=a)),a=c.nextNode();return{startMarker:s,endMarker:o}}createController(t,e,n,r){return d.isIfConfig(r)?new E(t,e,n,this.host,this.shadowRoot,r):d.isForConfig(r)?new w(t,e,n,this.host,this.shadowRoot,r):d.isSwitchConfig(r)?new k(t,e,n,this.host,this.shadowRoot,r):d.isTextConfig(r)?new P(t,e,n,this.host,this.shadowRoot,r):d.isBreakConfig(r)?new S(t,e,n,this.host,this.shadowRoot,r):null}};export{N as Component,_ as Direction,C as FluffBase,x as FluffElement,$ as HostBinding,H as HostListener,V as Input,I as MarkerManager,D as Output,z as Pipe,l as Property,h as Publisher,j as Reactive,J as ViewChild,q as Watch};
|