"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkP2BR4G3Jcjs = require('./chunk-P2BR4G3J.cjs');var P=()=>{_chunkP2BR4G3Jcjs.b.handlerAttributes.forEach((t,o)=>{let a=_chunkP2BR4G3Jcjs.b.handlers.get(o);a&&a.initialise(t)})},M=P;var T=()=>{_chunkP2BR4G3Jcjs.b.handlerAttributes.forEach((t,o)=>{let a=_chunkP2BR4G3Jcjs.b.handlers.get(o);a&&_optionalChain([a, 'access', _ => _.destroy, 'optionalCall', _2 => _2(t)])})},H=T;var $={initialiseHandlers:M,destroyHandlers:H},b=$;var j=()=>{let t=new Map,o=new Map,a={store:_chunkP2BR4G3Jcjs.c.helpers.buildAttribute(_chunkP2BR4G3Jcjs.b.options.attributes.selectors.store),state:_chunkP2BR4G3Jcjs.c.helpers.buildAttribute(_chunkP2BR4G3Jcjs.b.options.attributes.selectors.state),bind:_chunkP2BR4G3Jcjs.c.helpers.buildAttribute(_chunkP2BR4G3Jcjs.b.options.attributes.selectors.bind),handler:_chunkP2BR4G3Jcjs.c.helpers.buildAttribute(_chunkP2BR4G3Jcjs.b.options.attributes.selectors.handler)},h=document.querySelectorAll(`[${a.store}]`);for(let s of h){let d=s.getAttribute(a.store);if(!d)continue;o.set(d,{scope:d,state:new Map,bindState:new Map,bindActions:new Map});let u=o.get(d);if(!u)continue;for(let y of s.attributes){let{name:f,value:g}=y;if(f.startsWith(a.state)){let c=f.slice(a.state.length);u.state.set(c,_chunkP2BR4G3Jcjs.c.helpers.parseStateString(g))}}let V=_chunkP2BR4G3Jcjs.c.helpers.deepCollectAttr(s);for(let y of V){let{name:f,value:g}=y;if(f.startsWith(a.bind)){let c=f.slice(a.bind.length),i=_chunkP2BR4G3Jcjs.c.helpers.parseBindValue(g),m=_chunkP2BR4G3Jcjs.d.splitValue(i.value)[0];if(!m||m!==d)continue;i.type==="state"?(u.bindState.has(i.value)||u.bindState.set(i.value,new Set),_optionalChain([u, 'access', _3 => _3.bindState, 'access', _4 => _4.get, 'call', _5 => _5(i.value), 'optionalAccess', _6 => _6.add, 'call', _7 => _7(c)])):(u.bindActions.has(i.value)||u.bindActions.set(i.value,new Set),_optionalChain([u, 'access', _8 => _8.bindActions, 'access', _9 => _9.get, 'call', _10 => _10(i.value), 'optionalAccess', _11 => _11.add, 'call', _12 => _12(c)]))}else if(f.startsWith(a.handler)){let c=f.slice(a.handler.length).split(_chunkP2BR4G3Jcjs.b.options.attributes.seperators.handler);if(c.length===2){let[i,m]=c;if(!i||!m)continue;t.has(i)||t.set(i,new Map);let A=t.get(i);A&&(A.has(m)||A.set(m,new Set),_optionalChain([A, 'access', _13 => _13.get, 'call', _14 => _14(m), 'optionalAccess', _15 => _15.add, 'call', _16 => _16(g)]))}}}}return{elements:Array.from(h).map(s=>[s,s.getAttribute(_chunkP2BR4G3Jcjs.c.helpers.buildAttribute(_chunkP2BR4G3Jcjs.b.options.attributes.selectors.store))]),handlerAttributes:t,storeAttributes:o}},S=j;var W=t=>{if(_chunkP2BR4G3Jcjs.b.started){_chunkP2BR4G3Jcjs.c.log.warn("The library has already been started. Please don't call start() more than once.");return}_chunkP2BR4G3Jcjs.b.options={debug:_nullishCoalesce(_optionalChain([t, 'optionalAccess', _17 => _17.debug]), () => (_chunkP2BR4G3Jcjs.a.defaults.debug)),attributes:{prefix:_nullishCoalesce(_optionalChain([t, 'optionalAccess', _18 => _18.attributes, 'optionalAccess', _19 => _19.prefix]), () => (_chunkP2BR4G3Jcjs.a.defaults.attributes.prefix)),selectors:{store:_nullishCoalesce(_optionalChain([t, 'optionalAccess', _20 => _20.attributes, 'optionalAccess', _21 => _21.selectors, 'optionalAccess', _22 => _22.store]), () => (_chunkP2BR4G3Jcjs.a.defaults.attributes.selectors.store)),state:_nullishCoalesce(_optionalChain([t, 'optionalAccess', _23 => _23.attributes, 'optionalAccess', _24 => _24.selectors, 'optionalAccess', _25 => _25.state]), () => (_chunkP2BR4G3Jcjs.a.defaults.attributes.selectors.state)),bind:_nullishCoalesce(_optionalChain([t, 'optionalAccess', _26 => _26.attributes, 'optionalAccess', _27 => _27.selectors, 'optionalAccess', _28 => _28.bind]), () => (_chunkP2BR4G3Jcjs.a.defaults.attributes.selectors.bind)),handler:_nullishCoalesce(_optionalChain([t, 'optionalAccess', _29 => _29.attributes, 'optionalAccess', _30 => _30.selectors, 'optionalAccess', _31 => _31.handler]), () => (_chunkP2BR4G3Jcjs.a.defaults.attributes.selectors.handler)),ref:_nullishCoalesce(_optionalChain([t, 'optionalAccess', _32 => _32.attributes, 'optionalAccess', _33 => _33.selectors, 'optionalAccess', _34 => _34.ref]), () => (_chunkP2BR4G3Jcjs.a.defaults.attributes.selectors.ref))},seperators:{scope:_nullishCoalesce(_optionalChain([t, 'optionalAccess', _35 => _35.attributes, 'optionalAccess', _36 => _36.seperators, 'optionalAccess', _37 => _37.scope]), () => (_chunkP2BR4G3Jcjs.a.defaults.attributes.seperators.scope)),handler:_nullishCoalesce(_optionalChain([t, 'optionalAccess', _38 => _38.attributes, 'optionalAccess', _39 => _39.seperators, 'optionalAccess', _40 => _40.handler]), () => (_chunkP2BR4G3Jcjs.a.defaults.attributes.seperators.handler))}}};let{elements:o,handlerAttributes:a,storeAttributes:h}=S();_chunkP2BR4G3Jcjs.b.handlerAttributes=a;for(let s of o){if(!s[1]){_chunkP2BR4G3Jcjs.c.log.warn("Please ensure all 'data-store' attributes have a value. This is needed to scope state, binds and handler actions.");continue}_chunkP2BR4G3Jcjs.e.initialiseStore(s[0],s[1],h.get(s[1]))}b.initialiseHandlers(),_chunkP2BR4G3Jcjs.e.registerStoreObserver(),_chunkP2BR4G3Jcjs.b.started=!0,_chunkP2BR4G3Jcjs.c.log.debug("Library started.")},E=W;var C=()=>{b.destroyHandlers(),_chunkP2BR4G3Jcjs.b.stores.forEach((t,o)=>_chunkP2BR4G3Jcjs.e.destroyStore(o,t))},v=C;var L=t=>{let{elements:o,handlerAttributes:a,storeAttributes:h}=S();_chunkP2BR4G3Jcjs.b.handlerAttributes=a,b.destroyHandlers();for(let s of o){if(!s[1]){_chunkP2BR4G3Jcjs.c.log.warn("Please ensure all 'data-store' attributes have a value. This is needed to scope state, binds and handler actions.");continue}if(t&&t!==s[1])continue;let d=_chunkP2BR4G3Jcjs.b.stores.get(s[1]);d&&_chunkP2BR4G3Jcjs.e.destroyStore(s[1],d),_chunkP2BR4G3Jcjs.e.initialiseStore(s[0],s[1],h.get(s[1]))}b.initialiseHandlers(),_chunkP2BR4G3Jcjs.c.log.debug("Library refreshed.")},w=L;var N=(t,o)=>{if(_chunkP2BR4G3Jcjs.b.storeModules.has(t)){_chunkP2BR4G3Jcjs.c.log.warn(`The store "${t}" already has a module registered for it.`);return}_chunkP2BR4G3Jcjs.b.storeModules.set(t,o)},q= exports.storeModule =N;var B=t=>{if(_chunkP2BR4G3Jcjs.b.handlers.has(t.namespace)){_chunkP2BR4G3Jcjs.c.log.warn(`Handler for namespace "${t.namespace}" already registered`);return}_chunkP2BR4G3Jcjs.b.handlers.set(t.namespace,t),_chunkP2BR4G3Jcjs.c.log.debug(`Handler registered for namespace "${t.namespace}"`)},O= exports.registerHandler =B;var _solidjs = require('solid-js');var jt={start:E,destroy:v,refresh:w};exports.createEffect = _solidjs.createEffect; exports.createMemo = _solidjs.createMemo; exports.createSignal = _solidjs.createSignal; exports.default = jt; exports.registerHandler = O; exports.storeModule = q; //# sourceMappingURL=index.cjs.map