zag-ripple 0.1.3 → 0.1.4

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/index.d.mts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { MachineSchema, Machine, Service } from '@zag-js/core';
2
+ export { mergeProps } from '@zag-js/core';
2
3
  import { Tracked } from 'ripple';
3
4
  import * as _zag_js_types from '@zag-js/types';
4
5
 
5
- declare function mergeProps<T extends Record<string, any>>(...args: T[]): T;
6
-
7
6
  type MaybeTracked<T> = {
8
7
  [K in keyof T]?: T[K] | Tracked<T[K]>;
9
8
  };
@@ -24,4 +23,4 @@ declare const normalizeProps: _zag_js_types.NormalizeProps<PropTypes>;
24
23
 
25
24
  declare function onMount(fn: () => void | (() => void)): void;
26
25
 
27
- export { type PropTypes, mergeProps, normalizeProps, onMount, useMachine };
26
+ export { type PropTypes, normalizeProps, onMount, useMachine };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { MachineSchema, Machine, Service } from '@zag-js/core';
2
+ export { mergeProps } from '@zag-js/core';
2
3
  import { Tracked } from 'ripple';
3
4
  import * as _zag_js_types from '@zag-js/types';
4
5
 
5
- declare function mergeProps<T extends Record<string, any>>(...args: T[]): T;
6
-
7
6
  type MaybeTracked<T> = {
8
7
  [K in keyof T]?: T[K] | Tracked<T[K]>;
9
8
  };
@@ -24,4 +23,4 @@ declare const normalizeProps: _zag_js_types.NormalizeProps<PropTypes>;
24
23
 
25
24
  declare function onMount(fn: () => void | (() => void)): void;
26
25
 
27
- export { type PropTypes, mergeProps, normalizeProps, onMount, useMachine };
26
+ export { type PropTypes, normalizeProps, onMount, useMachine };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var ripple=require('ripple'),core=require('@zag-js/core'),utils=require('@zag-js/utils'),types=require('@zag-js/types');function Nt(...t){let e={};for(let o of t)if(o){for(let n in e){let f=o[n],i=ripple.get(f);if(n.startsWith("on")&&typeof e[n]=="function"&&typeof i=="function"){let g=e[n];e[n]=(...T)=>{i(...T),g(...T);};continue}e[n]=i!==void 0?i:e[n];}for(let n in o)if(e[n]===void 0){let f=o[n];e[n]=ripple.get(f);}for(let n of Object.getOwnPropertySymbols(o))e[n]=o[n];}return e}function O(t){let e=t().value??t().defaultValue,o=t().isEqual??Object.is,n=ripple.track(e),f=ripple.track(()=>t().value!=null),i={current:ripple.untrack(()=>ripple.get(n))},g={current:void 0};ripple.effect(()=>{let u=ripple.get(f)?t().value:ripple.get(n);g.current=u,i.current=u;});let T=u=>{let l=t().sync?ripple.flushSync:utils.identity;ripple.untrack(()=>l(()=>m(u)));},m=u=>{let l=g.current,y=utils.isFunction(u)?u(i.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:y,prev:l}),ripple.get(f)||ripple.set(n,y),i.current=y,g.current=y,o(y,l)||t().onChange?.(y,l);};function b(){return ripple.get(f)?t().value:ripple.get(n)}return {initial:e,ref:i,get:b,set:T,invoke(u,l){t().onChange?.(u,l);},hash(u){return t().hash?.(u)??String(u)}}}O.cleanup=t=>{ripple.effect(()=>()=>t());};O.ref=t=>{let e=t;return {get:()=>e,set:o=>{e=o;}}};function $(t){let e={current:t};return {get(o){return e.current[o]},set(o,n){e.current[o]=n;}}}function v(t){let e=utils.isFunction(t)?t():t;return ripple.get(e)}function K(t){if(!utils.isPlainObject(t)||t===void 0)return t;let e=Reflect.ownKeys(t).filter(n=>typeof n=="string"),o={};for(let n of e){let f=ripple.get(t[n]);f!==void 0&&(o[n]=K(f));}return o}var H=(t,e)=>{let o=[],n=true;ripple.effect(()=>{if(n){o=t.map(i=>v(i)),n=false;return}let f=false;for(let i=0;i<t.length;i++)if(!utils.isEqual(o[i],v(t[i]))){f=true;break}f&&(o=t.map(i=>v(i)),e());});};function Ut(t,e={}){let o=ripple.track(()=>{let{id:r,ids:c,getRootNode:a}=v(e);return core.createScope({id:r,ids:c,getRootNode:a})}),n=(...r)=>{t.debug&&console.log(...r);},f=ripple.track(()=>{let r=K(v(e));return t.props?.({props:r,scope:ripple.get(o)})??r}),i=yt(()=>ripple.get(f)),g=t.context?.({prop:i,bindable:O,get scope(){return ripple.get(o)},flush:_,getContext(){return T},getComputed(){return P},getRefs(){return C},getEvent(){return y()}}),T={get(r){return g?.[r].get()},set(r,c){g?.[r].set(c);},initial(r){return g?.[r].initial},hash(r){let c=g?.[r].get();return g?.[r].hash(c)}},m={current:new Map},b={current:null},u={current:null},l={current:{type:""}},y=()=>({...l.current,current(){return l.current},previous(){return u.current}}),j=()=>({...x,matches(...r){let c=x.get();return r.some(a=>core.matchesState(c,a))},hasTag(r){let c=x.get();return core.hasTag(t,c,r)}}),C=$(t.refs?.({prop:i,context:T})??{}),h=()=>({state:j(),context:T,event:y(),prop:i,send:A,action:S,guard:w,track:H,refs:C,computed:P,flush:_,get scope(){return ripple.get(o)},choose:B}),S=r=>{let c=utils.isFunction(r)?r(h()):r;if(!c)return;let a=c.map(d=>{let s=t.implementations?.actions?.[d];return s||utils.warn(`[zag-js] No implementation found for action "${JSON.stringify(d)}"`),s});for(let d of a)d?.(h());},w=r=>utils.isFunction(r)?r(h()):t.implementations?.guards?.[r](h()),z=r=>{let c=utils.isFunction(r)?r(h()):r;if(!c)return;let a=c.map(s=>{let p=t.implementations?.effects?.[s];return p||utils.warn(`[zag-js] No implementation found for effect "${JSON.stringify(s)}"`),p}),d=[];for(let s of a){let p=s?.(h());p&&d.push(p);}return ()=>d.forEach(s=>s?.())},B=r=>utils.toArray(r).find(c=>{let a=!c.guard;return utils.isString(c.guard)?a=!!w(c.guard):utils.isFunction(c.guard)&&(a=c.guard(h())),a}),P=r=>{utils.ensure(t.computed,()=>"[zag-js] No computed object found on machine");let c=t.computed[r];return c({context:T,event:l.current,prop:i,refs:C,scope:ripple.get(o),computed:P})},x=O(()=>({defaultValue:core.resolveStateValue(t,t.initialState({prop:i})),onChange(r,c){let{exiting:a,entering:d}=core.getExitEnterStates(t,c,r,b.current?.reenter);if(a.forEach(s=>{m.current.get(s.path)?.(),m.current.delete(s.path);}),a.forEach(s=>{S(s.state?.exit);}),S(b.current?.actions),d.forEach(s=>{let p=z(s.state?.effects);p&&m.current.set(s.path,p);}),c===core.INIT_STATE){S(t.entry);let s=z(t.effects);s&&m.current.set(core.INIT_STATE,s);}d.forEach(s=>{S(s.state?.entry);});}})),E=core.MachineStatus.NotStarted;ripple.effect(()=>ripple.untrack(()=>{let r=E===core.MachineStatus.Started;return E=core.MachineStatus.Started,n(r?"rehydrating...":"initializing..."),x.invoke(x.initial,core.INIT_STATE),()=>{n("unmounting..."),E=core.MachineStatus.Stopped,m.current.forEach(a=>a?.()),m.current=new Map,b.current=null,S(t.exit);}}));let A=r=>{if(E!==core.MachineStatus.Started)return;u.current=l.current,l.current=r;let c=ripple.untrack(()=>x.get()),{transitions:a,source:d}=core.findTransition(t,c,r.type),s=B(a);if(!s)return;b.current=s;let p=core.resolveStateValue(t,s.target??c,d);n("transition",r.type,s.target||c,`(${s.actions})`),p!==c?x.set(p):s.reenter?x.invoke(c,c):S(s.actions);};return t.watch?.(h()),{get state(){return j()},send:A,context:T,prop:i,get scope(){return ripple.get(o)},refs:C,computed:P,get event(){return y()},getStatus:()=>E}}function _(t){t();}function yt(t){return function(o){return t()[o]}}var Q={onFocus:"onFocusIn",onBlur:"onFocusOut",onDoubleClick:"onDblClick",onChange:"onInput",defaultChecked:"checked",defaultValue:"value",htmlFor:"for",className:"class"};function St(t){return t in Q?Q[t]:t}var ne=types.createNormalizer(t=>{let e={};for(let o in t){let n=t[o];if(!(o==="readOnly"&&n===false)){if(o==="style"&&utils.isObject(n)){e.style=vt(n);continue}if(o==="children"){utils.isString(n)&&(e.textContent=n);continue}e[St(o)]=n;}}return e});function vt(t){let e={};for(let o in t){let n=t[o];!utils.isString(n)&&!utils.isNumber(n)||(e[bt(o)]=n);}return e}var bt=t=>t.startsWith("--")?t:Ot(t),kt=/[A-Z]/g,Ft=/^ms-/;function Et(t){return "-"+t.toLowerCase()}var V={};function Ot(t){if(V.hasOwnProperty(t))return V[t];let e=t.replace(kt,Et);return V[t]=Ft.test(e)?"-"+e:e}function Pt(t){ripple.effect(()=>ripple.untrack(()=>{let e=t();if(typeof e=="function")return e}));}exports.mergeProps=Nt;exports.normalizeProps=ne;exports.onMount=Pt;exports.useMachine=Ut;
1
+ 'use strict';var core=require('@zag-js/core'),utils=require('@zag-js/utils'),ripple=require('ripple'),types=require('@zag-js/types');function C(t){let r=t().value??t().defaultValue,o=t().isEqual??Object.is,s=ripple.track(r),g=ripple.track(()=>t().value!=null),a={current:ripple.untrack(()=>ripple.get(s))},T={current:void 0};ripple.effect(()=>{let u=ripple.get(g)?t().value:ripple.get(s);T.current=u,a.current=u;});let x=u=>{let f=t().sync?ripple.flushSync:utils.identity;ripple.untrack(()=>f(()=>m(u)));},m=u=>{let f=T.current,p=utils.isFunction(u)?u(a.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:p,prev:f}),ripple.get(g)||ripple.set(s,p),a.current=p,T.current=p,o(p,f)||t().onChange?.(p,f);};function v(){return ripple.get(g)?t().value:ripple.get(s)}return {initial:r,ref:a,get:v,set:x,invoke(u,f){t().onChange?.(u,f);},hash(u){return t().hash?.(u)??String(u)}}}C.cleanup=t=>{ripple.effect(()=>()=>t());};C.ref=t=>{let r=t;return {get:()=>r,set:o=>{r=o;}}};function L(t){let r={current:t};return {get(o){return r.current[o]},set(o,s){r.current[o]=s;}}}function b(t){let r=utils.isFunction(t)?t():t;return ripple.get(r)}function K(t){if(!utils.isPlainObject(t)||t===void 0)return t;let r=Reflect.ownKeys(t).filter(s=>typeof s=="string"),o={};for(let s of r){let g=ripple.get(t[s]);g!==void 0&&(o[s]=K(g));}return o}var q=(t,r)=>{let o=[],s=true;ripple.effect(()=>{if(s){o=t.map(a=>b(a)),s=false;return}let g=false;for(let a=0;a<t.length;a++)if(!utils.isEqual(o[a],b(t[a]))){g=true;break}g&&(o=t.map(a=>b(a)),r());});};function Wt(t,r={}){let o=ripple.track(()=>{let{id:e,ids:n,getRootNode:i}=b(r);return core.createScope({id:e,ids:n,getRootNode:i})}),s=(...e)=>{t.debug&&console.log(...e);},g=ripple.track(()=>{let e=K(b(r));return t.props?.({props:e,scope:ripple.get(o)})??e}),a=Tt(()=>ripple.get(g)),T=t.context?.({prop:a,bindable:C,get scope(){return ripple.get(o)},flush:Z,getContext(){return x},getComputed(){return M},getRefs(){return O},getEvent(){return p()}}),x={get(e){return T?.[e].get()},set(e,n){T?.[e].set(n);},initial(e){return T?.[e].initial},hash(e){let n=T?.[e].get();return T?.[e].hash(n)}},m={current:new Map},v={current:null},u={current:null},f={current:{type:""}},p=()=>({...f.current,current(){return f.current},previous(){return u.current}}),j=()=>({...h,matches(...e){let n=h.get();return e.some(i=>core.matchesState(n,i))},hasTag(e){let n=h.get();return core.hasTag(t,n,e)}}),O=L(t.refs?.({prop:a,context:x})??{}),y=()=>({state:j(),context:x,event:p(),prop:a,send:A,action:S,guard:w,track:q,refs:O,computed:M,flush:Z,get scope(){return ripple.get(o)},choose:B}),S=e=>{let n=utils.isFunction(e)?e(y()):e;if(!n)return;let i=n.map(l=>{let c=t.implementations?.actions?.[l];return c||utils.warn(`[zag-js] No implementation found for action "${JSON.stringify(l)}"`),c});for(let l of i)l?.(y());},w=e=>utils.isFunction(e)?e(y()):t.implementations?.guards?.[e](y()),z=e=>{let n=utils.isFunction(e)?e(y()):e;if(!n)return;let i=n.map(c=>{let d=t.implementations?.effects?.[c];return d||utils.warn(`[zag-js] No implementation found for effect "${JSON.stringify(c)}"`),d}),l=[];for(let c of i){let d=c?.(y());d&&l.push(d);}return ()=>l.forEach(c=>c?.())},B=e=>utils.toArray(e).find(n=>{let i=!n.guard;return utils.isString(n.guard)?i=!!w(n.guard):utils.isFunction(n.guard)&&(i=n.guard(y())),i}),M=e=>{utils.ensure(t.computed,()=>"[zag-js] No computed object found on machine");let n=t.computed[e];return n({context:x,event:f.current,prop:a,refs:O,scope:ripple.get(o),computed:M})},h=C(()=>({defaultValue:core.resolveStateValue(t,t.initialState({prop:a})),onChange(e,n){let{exiting:i,entering:l}=core.getExitEnterStates(t,n,e,v.current?.reenter);if(i.forEach(c=>{m.current.get(c.path)?.(),m.current.delete(c.path);}),i.forEach(c=>{S(c.state?.exit);}),S(v.current?.actions),l.forEach(c=>{let d=z(c.state?.effects);d&&m.current.set(c.path,d);}),n===core.INIT_STATE){S(t.entry);let c=z(t.effects);c&&m.current.set(core.INIT_STATE,c);}l.forEach(c=>{S(c.state?.entry);});}})),E=core.MachineStatus.NotStarted;ripple.effect(()=>ripple.untrack(()=>{let e=E===core.MachineStatus.Started;return E=core.MachineStatus.Started,s(e?"rehydrating...":"initializing..."),h.invoke(h.initial,core.INIT_STATE),()=>{s("unmounting..."),E=core.MachineStatus.Stopped,m.current.forEach(i=>i?.()),m.current=new Map,v.current=null,S(t.exit);}}));let A=e=>{if(E!==core.MachineStatus.Started)return;u.current=f.current,f.current=e;let n=ripple.untrack(()=>h.get()),{transitions:i,source:l}=core.findTransition(t,n,e.type),c=B(i);if(!c)return;v.current=c;let d=core.resolveStateValue(t,c.target??n,l);s("transition",e.type,c.target||n,`(${c.actions})`),d!==n?h.set(d):c.reenter?h.invoke(n,n):S(c.actions);};return t.watch?.(y()),{get state(){return j()},send:A,context:x,prop:a,get scope(){return ripple.get(o)},refs:O,computed:M,get event(){return p()},getStatus:()=>E}}function Z(t){t();}function Tt(t){return function(o){return t()[o]}}var _={onFocus:"onFocusIn",onBlur:"onFocusOut",onDoubleClick:"onDblClick",onChange:"onInput",defaultChecked:"checked",defaultValue:"value",htmlFor:"for",className:"class"};function xt(t){return t in _?_[t]:t}var Ut=types.createNormalizer(t=>{let r={};for(let o in t){let s=t[o];if(!(o==="readOnly"&&s===false)){if(o==="style"&&utils.isObject(s)){r.style=St(s);continue}if(o==="children"){utils.isString(s)&&(r.textContent=s);continue}r[xt(o)]=s;}}return r});function St(t){let r={};for(let o in t){let s=t[o];!utils.isString(s)&&!utils.isNumber(s)||(r[bt(o)]=s);}return r}var bt=t=>t.startsWith("--")?t:Et(t),vt=/[A-Z]/g,Ft=/^ms-/;function kt(t){return "-"+t.toLowerCase()}var V={};function Et(t){if(V.hasOwnProperty(t))return V[t];let r=t.replace(vt,kt);return V[t]=Ft.test(r)?"-"+r:r}function Ot(t){ripple.effect(()=>ripple.untrack(()=>{let r=t();if(typeof r=="function")return r}));}Object.defineProperty(exports,"mergeProps",{enumerable:true,get:function(){return core.mergeProps}});exports.normalizeProps=Ut;exports.onMount=Ot;exports.useMachine=Wt;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import {get,track,effect,untrack,flushSync,set}from'ripple';import {createScope,INIT_STATE,MachineStatus,hasTag,matchesState,findTransition,resolveStateValue,getExitEnterStates}from'@zag-js/core';import {isObject,isString,isNumber,ensure,isFunction,warn,toArray,isPlainObject,identity,isEqual}from'@zag-js/utils';import {createNormalizer}from'@zag-js/types';function Nt(...t){let e={};for(let o of t)if(o){for(let n in e){let f=o[n],i=get(f);if(n.startsWith("on")&&typeof e[n]=="function"&&typeof i=="function"){let g=e[n];e[n]=(...T)=>{i(...T),g(...T);};continue}e[n]=i!==void 0?i:e[n];}for(let n in o)if(e[n]===void 0){let f=o[n];e[n]=get(f);}for(let n of Object.getOwnPropertySymbols(o))e[n]=o[n];}return e}function O(t){let e=t().value??t().defaultValue,o=t().isEqual??Object.is,n=track(e),f=track(()=>t().value!=null),i={current:untrack(()=>get(n))},g={current:void 0};effect(()=>{let u=get(f)?t().value:get(n);g.current=u,i.current=u;});let T=u=>{let l=t().sync?flushSync:identity;untrack(()=>l(()=>m(u)));},m=u=>{let l=g.current,y=isFunction(u)?u(i.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:y,prev:l}),get(f)||set(n,y),i.current=y,g.current=y,o(y,l)||t().onChange?.(y,l);};function b(){return get(f)?t().value:get(n)}return {initial:e,ref:i,get:b,set:T,invoke(u,l){t().onChange?.(u,l);},hash(u){return t().hash?.(u)??String(u)}}}O.cleanup=t=>{effect(()=>()=>t());};O.ref=t=>{let e=t;return {get:()=>e,set:o=>{e=o;}}};function $(t){let e={current:t};return {get(o){return e.current[o]},set(o,n){e.current[o]=n;}}}function v(t){let e=isFunction(t)?t():t;return get(e)}function K(t){if(!isPlainObject(t)||t===void 0)return t;let e=Reflect.ownKeys(t).filter(n=>typeof n=="string"),o={};for(let n of e){let f=get(t[n]);f!==void 0&&(o[n]=K(f));}return o}var H=(t,e)=>{let o=[],n=true;effect(()=>{if(n){o=t.map(i=>v(i)),n=false;return}let f=false;for(let i=0;i<t.length;i++)if(!isEqual(o[i],v(t[i]))){f=true;break}f&&(o=t.map(i=>v(i)),e());});};function Ut(t,e={}){let o=track(()=>{let{id:r,ids:c,getRootNode:a}=v(e);return createScope({id:r,ids:c,getRootNode:a})}),n=(...r)=>{t.debug&&console.log(...r);},f=track(()=>{let r=K(v(e));return t.props?.({props:r,scope:get(o)})??r}),i=yt(()=>get(f)),g=t.context?.({prop:i,bindable:O,get scope(){return get(o)},flush:_,getContext(){return T},getComputed(){return P},getRefs(){return C},getEvent(){return y()}}),T={get(r){return g?.[r].get()},set(r,c){g?.[r].set(c);},initial(r){return g?.[r].initial},hash(r){let c=g?.[r].get();return g?.[r].hash(c)}},m={current:new Map},b={current:null},u={current:null},l={current:{type:""}},y=()=>({...l.current,current(){return l.current},previous(){return u.current}}),j=()=>({...x,matches(...r){let c=x.get();return r.some(a=>matchesState(c,a))},hasTag(r){let c=x.get();return hasTag(t,c,r)}}),C=$(t.refs?.({prop:i,context:T})??{}),h=()=>({state:j(),context:T,event:y(),prop:i,send:A,action:S,guard:w,track:H,refs:C,computed:P,flush:_,get scope(){return get(o)},choose:B}),S=r=>{let c=isFunction(r)?r(h()):r;if(!c)return;let a=c.map(d=>{let s=t.implementations?.actions?.[d];return s||warn(`[zag-js] No implementation found for action "${JSON.stringify(d)}"`),s});for(let d of a)d?.(h());},w=r=>isFunction(r)?r(h()):t.implementations?.guards?.[r](h()),z=r=>{let c=isFunction(r)?r(h()):r;if(!c)return;let a=c.map(s=>{let p=t.implementations?.effects?.[s];return p||warn(`[zag-js] No implementation found for effect "${JSON.stringify(s)}"`),p}),d=[];for(let s of a){let p=s?.(h());p&&d.push(p);}return ()=>d.forEach(s=>s?.())},B=r=>toArray(r).find(c=>{let a=!c.guard;return isString(c.guard)?a=!!w(c.guard):isFunction(c.guard)&&(a=c.guard(h())),a}),P=r=>{ensure(t.computed,()=>"[zag-js] No computed object found on machine");let c=t.computed[r];return c({context:T,event:l.current,prop:i,refs:C,scope:get(o),computed:P})},x=O(()=>({defaultValue:resolveStateValue(t,t.initialState({prop:i})),onChange(r,c){let{exiting:a,entering:d}=getExitEnterStates(t,c,r,b.current?.reenter);if(a.forEach(s=>{m.current.get(s.path)?.(),m.current.delete(s.path);}),a.forEach(s=>{S(s.state?.exit);}),S(b.current?.actions),d.forEach(s=>{let p=z(s.state?.effects);p&&m.current.set(s.path,p);}),c===INIT_STATE){S(t.entry);let s=z(t.effects);s&&m.current.set(INIT_STATE,s);}d.forEach(s=>{S(s.state?.entry);});}})),E=MachineStatus.NotStarted;effect(()=>untrack(()=>{let r=E===MachineStatus.Started;return E=MachineStatus.Started,n(r?"rehydrating...":"initializing..."),x.invoke(x.initial,INIT_STATE),()=>{n("unmounting..."),E=MachineStatus.Stopped,m.current.forEach(a=>a?.()),m.current=new Map,b.current=null,S(t.exit);}}));let A=r=>{if(E!==MachineStatus.Started)return;u.current=l.current,l.current=r;let c=untrack(()=>x.get()),{transitions:a,source:d}=findTransition(t,c,r.type),s=B(a);if(!s)return;b.current=s;let p=resolveStateValue(t,s.target??c,d);n("transition",r.type,s.target||c,`(${s.actions})`),p!==c?x.set(p):s.reenter?x.invoke(c,c):S(s.actions);};return t.watch?.(h()),{get state(){return j()},send:A,context:T,prop:i,get scope(){return get(o)},refs:C,computed:P,get event(){return y()},getStatus:()=>E}}function _(t){t();}function yt(t){return function(o){return t()[o]}}var Q={onFocus:"onFocusIn",onBlur:"onFocusOut",onDoubleClick:"onDblClick",onChange:"onInput",defaultChecked:"checked",defaultValue:"value",htmlFor:"for",className:"class"};function St(t){return t in Q?Q[t]:t}var ne=createNormalizer(t=>{let e={};for(let o in t){let n=t[o];if(!(o==="readOnly"&&n===false)){if(o==="style"&&isObject(n)){e.style=vt(n);continue}if(o==="children"){isString(n)&&(e.textContent=n);continue}e[St(o)]=n;}}return e});function vt(t){let e={};for(let o in t){let n=t[o];!isString(n)&&!isNumber(n)||(e[bt(o)]=n);}return e}var bt=t=>t.startsWith("--")?t:Ot(t),kt=/[A-Z]/g,Ft=/^ms-/;function Et(t){return "-"+t.toLowerCase()}var V={};function Ot(t){if(V.hasOwnProperty(t))return V[t];let e=t.replace(kt,Et);return V[t]=Ft.test(e)?"-"+e:e}function Pt(t){effect(()=>untrack(()=>{let e=t();if(typeof e=="function")return e}));}export{Nt as mergeProps,ne as normalizeProps,Pt as onMount,Ut as useMachine};
1
+ import {createScope,INIT_STATE,MachineStatus,hasTag,matchesState,findTransition,resolveStateValue,getExitEnterStates}from'@zag-js/core';export{mergeProps}from'@zag-js/core';import {isObject,isString,isNumber,ensure,isFunction,warn,toArray,isPlainObject,identity,isEqual}from'@zag-js/utils';import {track,get,effect,untrack,flushSync,set}from'ripple';import {createNormalizer}from'@zag-js/types';function C(t){let r=t().value??t().defaultValue,o=t().isEqual??Object.is,s=track(r),g=track(()=>t().value!=null),a={current:untrack(()=>get(s))},T={current:void 0};effect(()=>{let u=get(g)?t().value:get(s);T.current=u,a.current=u;});let x=u=>{let f=t().sync?flushSync:identity;untrack(()=>f(()=>m(u)));},m=u=>{let f=T.current,p=isFunction(u)?u(a.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:p,prev:f}),get(g)||set(s,p),a.current=p,T.current=p,o(p,f)||t().onChange?.(p,f);};function v(){return get(g)?t().value:get(s)}return {initial:r,ref:a,get:v,set:x,invoke(u,f){t().onChange?.(u,f);},hash(u){return t().hash?.(u)??String(u)}}}C.cleanup=t=>{effect(()=>()=>t());};C.ref=t=>{let r=t;return {get:()=>r,set:o=>{r=o;}}};function L(t){let r={current:t};return {get(o){return r.current[o]},set(o,s){r.current[o]=s;}}}function b(t){let r=isFunction(t)?t():t;return get(r)}function K(t){if(!isPlainObject(t)||t===void 0)return t;let r=Reflect.ownKeys(t).filter(s=>typeof s=="string"),o={};for(let s of r){let g=get(t[s]);g!==void 0&&(o[s]=K(g));}return o}var q=(t,r)=>{let o=[],s=true;effect(()=>{if(s){o=t.map(a=>b(a)),s=false;return}let g=false;for(let a=0;a<t.length;a++)if(!isEqual(o[a],b(t[a]))){g=true;break}g&&(o=t.map(a=>b(a)),r());});};function Wt(t,r={}){let o=track(()=>{let{id:e,ids:n,getRootNode:i}=b(r);return createScope({id:e,ids:n,getRootNode:i})}),s=(...e)=>{t.debug&&console.log(...e);},g=track(()=>{let e=K(b(r));return t.props?.({props:e,scope:get(o)})??e}),a=Tt(()=>get(g)),T=t.context?.({prop:a,bindable:C,get scope(){return get(o)},flush:Z,getContext(){return x},getComputed(){return M},getRefs(){return O},getEvent(){return p()}}),x={get(e){return T?.[e].get()},set(e,n){T?.[e].set(n);},initial(e){return T?.[e].initial},hash(e){let n=T?.[e].get();return T?.[e].hash(n)}},m={current:new Map},v={current:null},u={current:null},f={current:{type:""}},p=()=>({...f.current,current(){return f.current},previous(){return u.current}}),j=()=>({...h,matches(...e){let n=h.get();return e.some(i=>matchesState(n,i))},hasTag(e){let n=h.get();return hasTag(t,n,e)}}),O=L(t.refs?.({prop:a,context:x})??{}),y=()=>({state:j(),context:x,event:p(),prop:a,send:A,action:S,guard:w,track:q,refs:O,computed:M,flush:Z,get scope(){return get(o)},choose:B}),S=e=>{let n=isFunction(e)?e(y()):e;if(!n)return;let i=n.map(l=>{let c=t.implementations?.actions?.[l];return c||warn(`[zag-js] No implementation found for action "${JSON.stringify(l)}"`),c});for(let l of i)l?.(y());},w=e=>isFunction(e)?e(y()):t.implementations?.guards?.[e](y()),z=e=>{let n=isFunction(e)?e(y()):e;if(!n)return;let i=n.map(c=>{let d=t.implementations?.effects?.[c];return d||warn(`[zag-js] No implementation found for effect "${JSON.stringify(c)}"`),d}),l=[];for(let c of i){let d=c?.(y());d&&l.push(d);}return ()=>l.forEach(c=>c?.())},B=e=>toArray(e).find(n=>{let i=!n.guard;return isString(n.guard)?i=!!w(n.guard):isFunction(n.guard)&&(i=n.guard(y())),i}),M=e=>{ensure(t.computed,()=>"[zag-js] No computed object found on machine");let n=t.computed[e];return n({context:x,event:f.current,prop:a,refs:O,scope:get(o),computed:M})},h=C(()=>({defaultValue:resolveStateValue(t,t.initialState({prop:a})),onChange(e,n){let{exiting:i,entering:l}=getExitEnterStates(t,n,e,v.current?.reenter);if(i.forEach(c=>{m.current.get(c.path)?.(),m.current.delete(c.path);}),i.forEach(c=>{S(c.state?.exit);}),S(v.current?.actions),l.forEach(c=>{let d=z(c.state?.effects);d&&m.current.set(c.path,d);}),n===INIT_STATE){S(t.entry);let c=z(t.effects);c&&m.current.set(INIT_STATE,c);}l.forEach(c=>{S(c.state?.entry);});}})),E=MachineStatus.NotStarted;effect(()=>untrack(()=>{let e=E===MachineStatus.Started;return E=MachineStatus.Started,s(e?"rehydrating...":"initializing..."),h.invoke(h.initial,INIT_STATE),()=>{s("unmounting..."),E=MachineStatus.Stopped,m.current.forEach(i=>i?.()),m.current=new Map,v.current=null,S(t.exit);}}));let A=e=>{if(E!==MachineStatus.Started)return;u.current=f.current,f.current=e;let n=untrack(()=>h.get()),{transitions:i,source:l}=findTransition(t,n,e.type),c=B(i);if(!c)return;v.current=c;let d=resolveStateValue(t,c.target??n,l);s("transition",e.type,c.target||n,`(${c.actions})`),d!==n?h.set(d):c.reenter?h.invoke(n,n):S(c.actions);};return t.watch?.(y()),{get state(){return j()},send:A,context:x,prop:a,get scope(){return get(o)},refs:O,computed:M,get event(){return p()},getStatus:()=>E}}function Z(t){t();}function Tt(t){return function(o){return t()[o]}}var _={onFocus:"onFocusIn",onBlur:"onFocusOut",onDoubleClick:"onDblClick",onChange:"onInput",defaultChecked:"checked",defaultValue:"value",htmlFor:"for",className:"class"};function xt(t){return t in _?_[t]:t}var Ut=createNormalizer(t=>{let r={};for(let o in t){let s=t[o];if(!(o==="readOnly"&&s===false)){if(o==="style"&&isObject(s)){r.style=St(s);continue}if(o==="children"){isString(s)&&(r.textContent=s);continue}r[xt(o)]=s;}}return r});function St(t){let r={};for(let o in t){let s=t[o];!isString(s)&&!isNumber(s)||(r[bt(o)]=s);}return r}var bt=t=>t.startsWith("--")?t:Et(t),vt=/[A-Z]/g,Ft=/^ms-/;function kt(t){return "-"+t.toLowerCase()}var V={};function Et(t){if(V.hasOwnProperty(t))return V[t];let r=t.replace(vt,kt);return V[t]=Ft.test(r)?"-"+r:r}function Ot(t){effect(()=>untrack(()=>{let r=t();if(typeof r=="function")return r}));}export{Ut as normalizeProps,Ot as onMount,Wt as useMachine};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zag-ripple",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "RippleJS Adapter for Zag JS",
5
5
  "keywords": [
6
6
  "js",