zag-ripple 0.0.17 → 0.0.19

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,8 +1,19 @@
1
1
  import { MachineSchema, Machine, Service } from '@zag-js/core';
2
- export { mergeProps } from '@zag-js/core';
2
+ import { Tracked } from 'ripple';
3
3
  import * as _zag_js_types from '@zag-js/types';
4
4
 
5
- declare function useMachine<T extends MachineSchema>(machine: Machine<T>, userProps?: Partial<T["props"]>): Service<T>;
5
+ declare function mergeProps<T extends Record<string, any>>(...args: T[]): T;
6
+
7
+ type MaybeTracked<T> = {
8
+ [K in keyof T]?: T[K] | Tracked<T[K]>;
9
+ };
10
+ /**
11
+ * UseMachine hook for Ripple JS
12
+ * @param machine - The machine to use
13
+ * @param userProps - The user props to use
14
+ * @returns The service
15
+ */
16
+ declare function useMachine<T extends MachineSchema>(machine: Machine<T>, userProps?: MaybeTracked<T["props"]>): Service<T>;
6
17
 
7
18
  type PropTypes<T = Dict> = Record<"button" | "label" | "input" | "textarea" | "img" | "output" | "element" | "select" | "rect" | "style" | "circle" | "svg" | "path", T>;
8
19
  type Dict = Record<string, any>;
@@ -10,4 +21,4 @@ declare const normalizeProps: _zag_js_types.NormalizeProps<PropTypes<Dict>>;
10
21
 
11
22
  declare function onMount(fn: () => void | (() => void)): void;
12
23
 
13
- export { normalizeProps, onMount, useMachine };
24
+ export { mergeProps, normalizeProps, onMount, useMachine };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,19 @@
1
1
  import { MachineSchema, Machine, Service } from '@zag-js/core';
2
- export { mergeProps } from '@zag-js/core';
2
+ import { Tracked } from 'ripple';
3
3
  import * as _zag_js_types from '@zag-js/types';
4
4
 
5
- declare function useMachine<T extends MachineSchema>(machine: Machine<T>, userProps?: Partial<T["props"]>): Service<T>;
5
+ declare function mergeProps<T extends Record<string, any>>(...args: T[]): T;
6
+
7
+ type MaybeTracked<T> = {
8
+ [K in keyof T]?: T[K] | Tracked<T[K]>;
9
+ };
10
+ /**
11
+ * UseMachine hook for Ripple JS
12
+ * @param machine - The machine to use
13
+ * @param userProps - The user props to use
14
+ * @returns The service
15
+ */
16
+ declare function useMachine<T extends MachineSchema>(machine: Machine<T>, userProps?: MaybeTracked<T["props"]>): Service<T>;
6
17
 
7
18
  type PropTypes<T = Dict> = Record<"button" | "label" | "input" | "textarea" | "img" | "output" | "element" | "select" | "rect" | "style" | "circle" | "svg" | "path", T>;
8
19
  type Dict = Record<string, any>;
@@ -10,4 +21,4 @@ declare const normalizeProps: _zag_js_types.NormalizeProps<PropTypes<Dict>>;
10
21
 
11
22
  declare function onMount(fn: () => void | (() => void)): void;
12
23
 
13
- export { normalizeProps, onMount, useMachine };
24
+ export { mergeProps, normalizeProps, onMount, useMachine };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var core=require('@zag-js/core'),utils=require('@zag-js/utils'),ripple=require('ripple'),types=require('@zag-js/types');function v(t){let n=t().value??t().defaultValue,o=t().isEqual??Object.is,s=ripple.track(n),f=ripple.track(()=>t().value!=null),a={current:ripple.untrack(()=>ripple.get(s))},p={current:void 0};ripple.effect(()=>{let u=ripple.get(f)?t().value:ripple.get(s);p.current=u,a.current=u;});let x=u=>{let m=p.current,d=utils.isFunction(u)?u(a.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:d,prev:m}),ripple.get(f)||ripple.set(s,d),o(d,m)||t().onChange?.(d,m);};function T(){return ripple.get(f)?t().value:ripple.get(s)}return {initial:n,ref:a,get:T,set:x,invoke(u,m){t().onChange?.(u,m);},hash(u){return t().hash?.(u)??String(u)}}}v.cleanup=t=>{ripple.effect(()=>()=>t());};v.ref=t=>{let n=t;return {get:()=>n,set:o=>{n=o;}}};function E(t){return t!=null&&typeof t=="object"&&"__v"in t&&typeof t.f=="number"}function q(t){let n={current:t};return {get(o){return n.current[o]},set(o,s){n.current[o]=s;}}}function N(t){return utils.isFunction(t)?t():E(t)?ripple.get(t):t}var _=(t,n)=>{let o=[],s=true;ripple.effect(()=>{if(s){o=t.map(a=>N(a)),s=false;return}let f=false;for(let a=0;a<t.length;a++)if(!utils.isEqual(o[a],N(t[a]))){f=true;break}f&&(o=t.map(a=>N(a)),n());});};function M(t){return E(t)?ripple.get(t):utils.isFunction(t)?t():t}function dt(t){let n=M(t);if(n==null||typeof n!="object")return n;let o={};for(let s of Object.keys(n)){let f=n[s];f!==void 0&&(E(f)&&(f=ripple.get(f)),o[s]=f);}return o}function Jt(t,n={}){let o=ripple.track(()=>{let{id:e,ids:r,getRootNode:i}=M(n);return core.createScope({id:e,ids:r,getRootNode:i})}),s=(...e)=>{t.debug&&console.log(...e);},f=ripple.track(()=>t.props?.({props:dt(n),scope:ripple.get(o)})??M(n)),a=pt(()=>ripple.get(f)),p=t.context?.({prop:a,bindable:v,get scope(){return ripple.get(o)},flush:W,getContext(){return x},getComputed(){return R},getRefs(){return O},getEvent(){return P()}}),x={get(e){return p?.[e].get()},set(e,r){p?.[e].set(r);},initial(e){return p?.[e].initial},hash(e){let r=p?.[e].get();return p?.[e].hash(r)}},T={current:new Map},u={current:null},m={current:null},d={current:{type:""}},P=()=>({...d.current,current(){return d.current},previous(){return m.current}}),B=()=>({...h,matches(...e){let r=h.get();return e.some(i=>core.matchesState(r,i))},hasTag(e){let r=h.get();return core.hasTag(t,r,e)}}),O=q(t.refs?.({prop:a,context:x})??{}),y=()=>({state:B(),context:x,event:P(),prop:a,send:A,action:S,guard:K,track:_,refs:O,computed:R,flush:W,get scope(){return ripple.get(o)},choose:D}),S=e=>{let r=utils.isFunction(e)?e(y()):e;if(!r)return;let i=r.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());},K=e=>utils.isFunction(e)?e(y()):t.implementations?.guards?.[e](y()),w=e=>{let r=utils.isFunction(e)?e(y()):e;if(!r)return;let i=r.map(c=>{let g=t.implementations?.effects?.[c];return g||utils.warn(`[zag-js] No implementation found for effect "${JSON.stringify(c)}"`),g}),l=[];for(let c of i){let g=c?.(y());g&&l.push(g);}return ()=>l.forEach(c=>c?.())},D=e=>utils.toArray(e).find(r=>{let i=!r.guard;return utils.isString(r.guard)?i=!!K(r.guard):utils.isFunction(r.guard)&&(i=r.guard(y())),i}),R=e=>{utils.ensure(t.computed,()=>"[zag-js] No computed object found on machine");let r=t.computed[e];return r({context:x,event:d.current,prop:a,refs:O,scope:ripple.get(o),computed:R})},h=v(()=>({defaultValue:core.resolveStateValue(t,t.initialState({prop:a})),onChange(e,r){let{exiting:i,entering:l}=core.getExitEnterStates(t,r,e,u.current?.reenter);if(i.forEach(c=>{T.current.get(c.path)?.(),T.current.delete(c.path);}),i.forEach(c=>{S(c.state?.exit);}),S(u.current?.actions),l.forEach(c=>{let g=w(c.state?.effects);g&&T.current.set(c.path,g);}),r===core.INIT_STATE){S(t.entry);let c=w(t.effects);c&&T.current.set(core.INIT_STATE,c);}l.forEach(c=>{S(c.state?.entry);});}})),k=core.MachineStatus.NotStarted;ripple.effect(()=>ripple.untrack(()=>{let e=k===core.MachineStatus.Started;return k=core.MachineStatus.Started,s(e?"rehydrating...":"initializing..."),h.invoke(h.initial,core.INIT_STATE),()=>{s("unmounting..."),k=core.MachineStatus.Stopped,T.current.forEach(i=>i?.()),T.current=new Map,u.current=null,S(t.exit);}}));let A=e=>{if(k!==core.MachineStatus.Started)return;m.current=d.current,d.current=e;let r=ripple.untrack(()=>h.get()),{transitions:i,source:l}=core.findTransition(t,r,e.type),c=D(i);if(!c)return;u.current=c;let g=core.resolveStateValue(t,c.target??r,l);s("transition",e.type,c.target||r,`(${c.actions})`),g!==r?h.set(g):c.reenter?h.invoke(r,r):S(c.actions);};return t.watch?.(y()),{get state(){return B()},send:A,context:x,prop:a,get scope(){return ripple.get(o)},refs:O,computed:R,get event(){return P()},getStatus:()=>k}}function W(t){t();}function pt(t){return function(o){return t()[o]}}var Z={onFocus:"onFocusIn",onBlur:"onFocusOut",onDoubleClick:"onDblClick",onChange:"onInput",defaultChecked:"checked",defaultValue:"value",htmlFor:"for",className:"class"};function ht(t){return t in Z?Z[t]:t}var Zt=types.createNormalizer(t=>{let n={};for(let o in t){let s=t[o];if(!(o==="readOnly"&&s===false)){if(o==="style"&&utils.isObject(s)){n.style=bt(s);continue}if(o==="children"){utils.isString(s)&&(n.textContent=s);continue}n[ht(o)]=s;}}return n});function bt(t){let n={};for(let o in t){let s=t[o];!utils.isString(s)&&!utils.isNumber(s)||(n[xt(o)]=s);}return n}var xt=t=>t.startsWith("--")?t:vt(t),St=/[A-Z]/g,Ft=/^ms-/;function kt(t){return "-"+t.toLowerCase()}var z={};function vt(t){if(z.hasOwnProperty(t))return z[t];let n=t.replace(St,kt);return z[t]=Ft.test(n)?"-"+n:n}function jt(t){ripple.effect(()=>ripple.untrack(()=>{let n=t();if(typeof n=="function")return n}));}Object.defineProperty(exports,"mergeProps",{enumerable:true,get:function(){return core.mergeProps}});exports.normalizeProps=Zt;exports.onMount=jt;exports.useMachine=Jt;
1
+ 'use strict';var ripple=require('ripple'),core=require('@zag-js/core'),utils=require('@zag-js/utils'),types=require('@zag-js/types');function Kt(...t){let e={};for(let o of t)if(o){for(let n in e){let f=o[n],a=ripple.get(f);if(n.startsWith("on")&&typeof e[n]=="function"&&typeof a=="function"){let g=e[n];e[n]=(...T)=>{a(...T),g(...T);};continue}e[n]=a!==void 0?a: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 E(t){let e=t().value??t().defaultValue,o=t().isEqual??Object.is,n=ripple.track(e),f=ripple.track(()=>t().value!=null),a={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,a.current=u;});let T=u=>{let y=g.current,l=utils.isFunction(u)?u(a.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:l,prev:y}),ripple.get(f)||ripple.set(n,l),a.current=l,g.current=l,o(l,y)||t().onChange?.(l,y);};function m(){return ripple.get(f)?t().value:ripple.get(n)}return {initial:e,ref:a,get:m,set:T,invoke(u,y){t().onChange?.(u,y);},hash(u){return t().hash?.(u)??String(u)}}}E.cleanup=t=>{ripple.effect(()=>()=>t());};E.ref=t=>{let e=t;return {get:()=>e,set:o=>{e=o;}}};function q(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 M(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]=M(f));}return o}var J=(t,e)=>{let o=[],n=true;ripple.effect(()=>{if(n){o=t.map(a=>v(a)),n=false;return}let f=false;for(let a=0;a<t.length;a++)if(!utils.isEqual(o[a],v(t[a]))){f=true;break}f&&(o=t.map(a=>v(a)),e());});};function Qt(t,e={}){let o=ripple.track(()=>{let{id:r,ids:c,getRootNode:i}=v(e);return core.createScope({id:r,ids:c,getRootNode:i})}),n=(...r)=>{t.debug&&console.log(...r);},f=ripple.track(()=>{let r=M(v(e));return t.props?.({props:r,scope:ripple.get(o)})??r}),a=gt(()=>ripple.get(f)),g=t.context?.({prop:a,bindable:E,get scope(){return ripple.get(o)},flush:_,getContext(){return T},getComputed(){return C},getRefs(){return R},getEvent(){return K()}}),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},u={current:null},y={current:null},l={current:{type:""}},K=()=>({...l.current,current(){return l.current},previous(){return y.current}}),j=()=>({...x,matches(...r){let c=x.get();return r.some(i=>core.matchesState(c,i))},hasTag(r){let c=x.get();return core.hasTag(t,c,r)}}),R=q(t.refs?.({prop:a,context:T})??{}),h=()=>({state:j(),context:T,event:K(),prop:a,send:D,action:S,guard:w,track:J,refs:R,computed:C,flush:_,get scope(){return ripple.get(o)},choose:B}),S=r=>{let c=utils.isFunction(r)?r(h()):r;if(!c)return;let i=c.map(p=>{let s=t.implementations?.actions?.[p];return s||utils.warn(`[zag-js] No implementation found for action "${JSON.stringify(p)}"`),s});for(let p of i)p?.(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 i=c.map(s=>{let d=t.implementations?.effects?.[s];return d||utils.warn(`[zag-js] No implementation found for effect "${JSON.stringify(s)}"`),d}),p=[];for(let s of i){let d=s?.(h());d&&p.push(d);}return ()=>p.forEach(s=>s?.())},B=r=>utils.toArray(r).find(c=>{let i=!c.guard;return utils.isString(c.guard)?i=!!w(c.guard):utils.isFunction(c.guard)&&(i=c.guard(h())),i}),C=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:a,refs:R,scope:ripple.get(o),computed:C})},x=E(()=>({defaultValue:core.resolveStateValue(t,t.initialState({prop:a})),onChange(r,c){let{exiting:i,entering:p}=core.getExitEnterStates(t,c,r,u.current?.reenter);if(i.forEach(s=>{m.current.get(s.path)?.(),m.current.delete(s.path);}),i.forEach(s=>{S(s.state?.exit);}),S(u.current?.actions),p.forEach(s=>{let d=z(s.state?.effects);d&&m.current.set(s.path,d);}),c===core.INIT_STATE){S(t.entry);let s=z(t.effects);s&&m.current.set(core.INIT_STATE,s);}p.forEach(s=>{S(s.state?.entry);});}})),F=core.MachineStatus.NotStarted;ripple.effect(()=>ripple.untrack(()=>{let r=F===core.MachineStatus.Started;return F=core.MachineStatus.Started,n(r?"rehydrating...":"initializing..."),x.invoke(x.initial,core.INIT_STATE),()=>{n("unmounting..."),F=core.MachineStatus.Stopped,m.current.forEach(i=>i?.()),m.current=new Map,u.current=null,S(t.exit);}}));let D=r=>{if(F!==core.MachineStatus.Started)return;y.current=l.current,l.current=r;let c=ripple.untrack(()=>x.get()),{transitions:i,source:p}=core.findTransition(t,c,r.type),s=B(i);if(!s)return;u.current=s;let d=core.resolveStateValue(t,s.target??c,p);n("transition",r.type,s.target||c,`(${s.actions})`),d!==c?x.set(d):s.reenter?x.invoke(c,c):S(s.actions);};return t.watch?.(h()),{get state(){return j()},send:D,context:T,prop:a,get scope(){return ripple.get(o)},refs:R,computed:C,get event(){return K()},getStatus:()=>F}}function _(t){t();}function gt(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 ht(t){return t in Q?Q[t]:t}var te=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=xt(n);continue}if(o==="children"){utils.isString(n)&&(e.textContent=n);continue}e[ht(o)]=n;}}return e});function xt(t){let e={};for(let o in t){let n=t[o];!utils.isString(n)&&!utils.isNumber(n)||(e[St(o)]=n);}return e}var St=t=>t.startsWith("--")?t:Ft(t),vt=/[A-Z]/g,bt=/^ms-/;function kt(t){return "-"+t.toLowerCase()}var V={};function Ft(t){if(V.hasOwnProperty(t))return V[t];let e=t.replace(vt,kt);return V[t]=bt.test(e)?"-"+e:e}function Rt(t){ripple.effect(()=>ripple.untrack(()=>{let e=t();if(typeof e=="function")return e}));}exports.mergeProps=Kt;exports.normalizeProps=te;exports.onMount=Rt;exports.useMachine=Qt;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
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,isEqual}from'@zag-js/utils';import {track,get,effect,untrack,set}from'ripple';import {createNormalizer}from'@zag-js/types';function v(t){let n=t().value??t().defaultValue,o=t().isEqual??Object.is,s=track(n),f=track(()=>t().value!=null),a={current:untrack(()=>get(s))},p={current:void 0};effect(()=>{let u=get(f)?t().value:get(s);p.current=u,a.current=u;});let x=u=>{let m=p.current,d=isFunction(u)?u(a.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:d,prev:m}),get(f)||set(s,d),o(d,m)||t().onChange?.(d,m);};function T(){return get(f)?t().value:get(s)}return {initial:n,ref:a,get:T,set:x,invoke(u,m){t().onChange?.(u,m);},hash(u){return t().hash?.(u)??String(u)}}}v.cleanup=t=>{effect(()=>()=>t());};v.ref=t=>{let n=t;return {get:()=>n,set:o=>{n=o;}}};function E(t){return t!=null&&typeof t=="object"&&"__v"in t&&typeof t.f=="number"}function q(t){let n={current:t};return {get(o){return n.current[o]},set(o,s){n.current[o]=s;}}}function N(t){return isFunction(t)?t():E(t)?get(t):t}var _=(t,n)=>{let o=[],s=true;effect(()=>{if(s){o=t.map(a=>N(a)),s=false;return}let f=false;for(let a=0;a<t.length;a++)if(!isEqual(o[a],N(t[a]))){f=true;break}f&&(o=t.map(a=>N(a)),n());});};function M(t){return E(t)?get(t):isFunction(t)?t():t}function dt(t){let n=M(t);if(n==null||typeof n!="object")return n;let o={};for(let s of Object.keys(n)){let f=n[s];f!==void 0&&(E(f)&&(f=get(f)),o[s]=f);}return o}function Jt(t,n={}){let o=track(()=>{let{id:e,ids:r,getRootNode:i}=M(n);return createScope({id:e,ids:r,getRootNode:i})}),s=(...e)=>{t.debug&&console.log(...e);},f=track(()=>t.props?.({props:dt(n),scope:get(o)})??M(n)),a=pt(()=>get(f)),p=t.context?.({prop:a,bindable:v,get scope(){return get(o)},flush:W,getContext(){return x},getComputed(){return R},getRefs(){return O},getEvent(){return P()}}),x={get(e){return p?.[e].get()},set(e,r){p?.[e].set(r);},initial(e){return p?.[e].initial},hash(e){let r=p?.[e].get();return p?.[e].hash(r)}},T={current:new Map},u={current:null},m={current:null},d={current:{type:""}},P=()=>({...d.current,current(){return d.current},previous(){return m.current}}),B=()=>({...h,matches(...e){let r=h.get();return e.some(i=>matchesState(r,i))},hasTag(e){let r=h.get();return hasTag(t,r,e)}}),O=q(t.refs?.({prop:a,context:x})??{}),y=()=>({state:B(),context:x,event:P(),prop:a,send:A,action:S,guard:K,track:_,refs:O,computed:R,flush:W,get scope(){return get(o)},choose:D}),S=e=>{let r=isFunction(e)?e(y()):e;if(!r)return;let i=r.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());},K=e=>isFunction(e)?e(y()):t.implementations?.guards?.[e](y()),w=e=>{let r=isFunction(e)?e(y()):e;if(!r)return;let i=r.map(c=>{let g=t.implementations?.effects?.[c];return g||warn(`[zag-js] No implementation found for effect "${JSON.stringify(c)}"`),g}),l=[];for(let c of i){let g=c?.(y());g&&l.push(g);}return ()=>l.forEach(c=>c?.())},D=e=>toArray(e).find(r=>{let i=!r.guard;return isString(r.guard)?i=!!K(r.guard):isFunction(r.guard)&&(i=r.guard(y())),i}),R=e=>{ensure(t.computed,()=>"[zag-js] No computed object found on machine");let r=t.computed[e];return r({context:x,event:d.current,prop:a,refs:O,scope:get(o),computed:R})},h=v(()=>({defaultValue:resolveStateValue(t,t.initialState({prop:a})),onChange(e,r){let{exiting:i,entering:l}=getExitEnterStates(t,r,e,u.current?.reenter);if(i.forEach(c=>{T.current.get(c.path)?.(),T.current.delete(c.path);}),i.forEach(c=>{S(c.state?.exit);}),S(u.current?.actions),l.forEach(c=>{let g=w(c.state?.effects);g&&T.current.set(c.path,g);}),r===INIT_STATE){S(t.entry);let c=w(t.effects);c&&T.current.set(INIT_STATE,c);}l.forEach(c=>{S(c.state?.entry);});}})),k=MachineStatus.NotStarted;effect(()=>untrack(()=>{let e=k===MachineStatus.Started;return k=MachineStatus.Started,s(e?"rehydrating...":"initializing..."),h.invoke(h.initial,INIT_STATE),()=>{s("unmounting..."),k=MachineStatus.Stopped,T.current.forEach(i=>i?.()),T.current=new Map,u.current=null,S(t.exit);}}));let A=e=>{if(k!==MachineStatus.Started)return;m.current=d.current,d.current=e;let r=untrack(()=>h.get()),{transitions:i,source:l}=findTransition(t,r,e.type),c=D(i);if(!c)return;u.current=c;let g=resolveStateValue(t,c.target??r,l);s("transition",e.type,c.target||r,`(${c.actions})`),g!==r?h.set(g):c.reenter?h.invoke(r,r):S(c.actions);};return t.watch?.(y()),{get state(){return B()},send:A,context:x,prop:a,get scope(){return get(o)},refs:O,computed:R,get event(){return P()},getStatus:()=>k}}function W(t){t();}function pt(t){return function(o){return t()[o]}}var Z={onFocus:"onFocusIn",onBlur:"onFocusOut",onDoubleClick:"onDblClick",onChange:"onInput",defaultChecked:"checked",defaultValue:"value",htmlFor:"for",className:"class"};function ht(t){return t in Z?Z[t]:t}var Zt=createNormalizer(t=>{let n={};for(let o in t){let s=t[o];if(!(o==="readOnly"&&s===false)){if(o==="style"&&isObject(s)){n.style=bt(s);continue}if(o==="children"){isString(s)&&(n.textContent=s);continue}n[ht(o)]=s;}}return n});function bt(t){let n={};for(let o in t){let s=t[o];!isString(s)&&!isNumber(s)||(n[xt(o)]=s);}return n}var xt=t=>t.startsWith("--")?t:vt(t),St=/[A-Z]/g,Ft=/^ms-/;function kt(t){return "-"+t.toLowerCase()}var z={};function vt(t){if(z.hasOwnProperty(t))return z[t];let n=t.replace(St,kt);return z[t]=Ft.test(n)?"-"+n:n}function jt(t){effect(()=>untrack(()=>{let n=t();if(typeof n=="function")return n}));}export{Zt as normalizeProps,jt as onMount,Jt as useMachine};
1
+ import {get,track,effect,untrack,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,isEqual}from'@zag-js/utils';import {createNormalizer}from'@zag-js/types';function Kt(...t){let e={};for(let o of t)if(o){for(let n in e){let f=o[n],a=get(f);if(n.startsWith("on")&&typeof e[n]=="function"&&typeof a=="function"){let g=e[n];e[n]=(...T)=>{a(...T),g(...T);};continue}e[n]=a!==void 0?a: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 E(t){let e=t().value??t().defaultValue,o=t().isEqual??Object.is,n=track(e),f=track(()=>t().value!=null),a={current:untrack(()=>get(n))},g={current:void 0};effect(()=>{let u=get(f)?t().value:get(n);g.current=u,a.current=u;});let T=u=>{let y=g.current,l=isFunction(u)?u(a.current):u;t().debug&&console.log(`[bindable > ${t().debug}] setValue`,{next:l,prev:y}),get(f)||set(n,l),a.current=l,g.current=l,o(l,y)||t().onChange?.(l,y);};function m(){return get(f)?t().value:get(n)}return {initial:e,ref:a,get:m,set:T,invoke(u,y){t().onChange?.(u,y);},hash(u){return t().hash?.(u)??String(u)}}}E.cleanup=t=>{effect(()=>()=>t());};E.ref=t=>{let e=t;return {get:()=>e,set:o=>{e=o;}}};function q(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 M(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]=M(f));}return o}var J=(t,e)=>{let o=[],n=true;effect(()=>{if(n){o=t.map(a=>v(a)),n=false;return}let f=false;for(let a=0;a<t.length;a++)if(!isEqual(o[a],v(t[a]))){f=true;break}f&&(o=t.map(a=>v(a)),e());});};function Qt(t,e={}){let o=track(()=>{let{id:r,ids:c,getRootNode:i}=v(e);return createScope({id:r,ids:c,getRootNode:i})}),n=(...r)=>{t.debug&&console.log(...r);},f=track(()=>{let r=M(v(e));return t.props?.({props:r,scope:get(o)})??r}),a=gt(()=>get(f)),g=t.context?.({prop:a,bindable:E,get scope(){return get(o)},flush:_,getContext(){return T},getComputed(){return C},getRefs(){return R},getEvent(){return K()}}),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},u={current:null},y={current:null},l={current:{type:""}},K=()=>({...l.current,current(){return l.current},previous(){return y.current}}),j=()=>({...x,matches(...r){let c=x.get();return r.some(i=>matchesState(c,i))},hasTag(r){let c=x.get();return hasTag(t,c,r)}}),R=q(t.refs?.({prop:a,context:T})??{}),h=()=>({state:j(),context:T,event:K(),prop:a,send:D,action:S,guard:w,track:J,refs:R,computed:C,flush:_,get scope(){return get(o)},choose:B}),S=r=>{let c=isFunction(r)?r(h()):r;if(!c)return;let i=c.map(p=>{let s=t.implementations?.actions?.[p];return s||warn(`[zag-js] No implementation found for action "${JSON.stringify(p)}"`),s});for(let p of i)p?.(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 i=c.map(s=>{let d=t.implementations?.effects?.[s];return d||warn(`[zag-js] No implementation found for effect "${JSON.stringify(s)}"`),d}),p=[];for(let s of i){let d=s?.(h());d&&p.push(d);}return ()=>p.forEach(s=>s?.())},B=r=>toArray(r).find(c=>{let i=!c.guard;return isString(c.guard)?i=!!w(c.guard):isFunction(c.guard)&&(i=c.guard(h())),i}),C=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:a,refs:R,scope:get(o),computed:C})},x=E(()=>({defaultValue:resolveStateValue(t,t.initialState({prop:a})),onChange(r,c){let{exiting:i,entering:p}=getExitEnterStates(t,c,r,u.current?.reenter);if(i.forEach(s=>{m.current.get(s.path)?.(),m.current.delete(s.path);}),i.forEach(s=>{S(s.state?.exit);}),S(u.current?.actions),p.forEach(s=>{let d=z(s.state?.effects);d&&m.current.set(s.path,d);}),c===INIT_STATE){S(t.entry);let s=z(t.effects);s&&m.current.set(INIT_STATE,s);}p.forEach(s=>{S(s.state?.entry);});}})),F=MachineStatus.NotStarted;effect(()=>untrack(()=>{let r=F===MachineStatus.Started;return F=MachineStatus.Started,n(r?"rehydrating...":"initializing..."),x.invoke(x.initial,INIT_STATE),()=>{n("unmounting..."),F=MachineStatus.Stopped,m.current.forEach(i=>i?.()),m.current=new Map,u.current=null,S(t.exit);}}));let D=r=>{if(F!==MachineStatus.Started)return;y.current=l.current,l.current=r;let c=untrack(()=>x.get()),{transitions:i,source:p}=findTransition(t,c,r.type),s=B(i);if(!s)return;u.current=s;let d=resolveStateValue(t,s.target??c,p);n("transition",r.type,s.target||c,`(${s.actions})`),d!==c?x.set(d):s.reenter?x.invoke(c,c):S(s.actions);};return t.watch?.(h()),{get state(){return j()},send:D,context:T,prop:a,get scope(){return get(o)},refs:R,computed:C,get event(){return K()},getStatus:()=>F}}function _(t){t();}function gt(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 ht(t){return t in Q?Q[t]:t}var te=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=xt(n);continue}if(o==="children"){isString(n)&&(e.textContent=n);continue}e[ht(o)]=n;}}return e});function xt(t){let e={};for(let o in t){let n=t[o];!isString(n)&&!isNumber(n)||(e[St(o)]=n);}return e}var St=t=>t.startsWith("--")?t:Ft(t),vt=/[A-Z]/g,bt=/^ms-/;function kt(t){return "-"+t.toLowerCase()}var V={};function Ft(t){if(V.hasOwnProperty(t))return V[t];let e=t.replace(vt,kt);return V[t]=bt.test(e)?"-"+e:e}function Rt(t){effect(()=>untrack(()=>{let e=t();if(typeof e=="function")return e}));}export{Kt as mergeProps,te as normalizeProps,Rt as onMount,Qt as useMachine};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zag-ripple",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "RippleJS Adapter for Zag JS",
5
5
  "keywords": [
6
6
  "js",