@buoy-gg/time-machine 7.0.73 → 7.0.75

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.TIME_MACHINE_FLOATING_TOOL_ID=void 0;exports.TimeMachineFloatingTool=TimeMachineFloatingTool;exports.openTimeMachineFloatingTool=openTimeMachineFloatingTool;exports.startTimeMachineFloatingToolPersistence=startTimeMachineFloatingToolPersistence;var _react=require("react");var _reactNative=require("react-native");var _sharedUi=require("@buoy-gg/shared-ui");var _useTimeMachine=require("../../hooks/useTimeMachine");var _timeMachineStore=require("../../store/timeMachineStore");var _routeRestore=require("../../store/routeRestore");var _sourceSettings=require("../../store/sourceSettings");var _RestoreOutcomeCard=require("../list/RestoreOutcomeCard");var _format=require("../format");var _armedPoint=require("./armedPoint");var _NamePromptModal=require("./NamePromptModal");var _barSettings=require("./barSettings");var _jsxRuntime=require("react/jsx-runtime");const TIME_MACHINE_FLOATING_TOOL_ID=exports.TIME_MACHINE_FLOATING_TOOL_ID="time-machine-restore";const RECENT_MS=1e4;const FLASH_MS=900;const PICKER_ROWS=6;const registration={id:TIME_MACHINE_FLOATING_TOOL_ID,render:r=>(0,_jsxRuntime.jsx)(TimeMachineFloatingTool,{...r})};let persistenceStarted=false;function startTimeMachineFloatingToolPersistence(){if(persistenceStarted)return;persistenceStarted=true;(0,_sharedUi.registerPersistentFloatingTool)(registration,_sharedUi.persistentStorage)}if(typeof __DEV__!=="undefined"&&__DEV__&&typeof navigator!=="undefined"&&navigator.product==="ReactNative"){startTimeMachineFloatingToolPersistence()}function openTimeMachineFloatingTool(r){if(r)(0,_armedPoint.setPickedPointId)(r);(0,_sharedUi.openFloatingTool)(registration)}function failureSummary(r){const n=Object.values(r.results);const d=n.filter(y=>!y.ok||y.skipped.length>0).length;const o=n.length;const u=r.route;const s=u?.status==="failed"||u?.status==="unavailable";if(d===0&&s)return"Route did not restore";return`${d} of ${o} source${o===1?"":"s"} failed`}function failureLines(r){const n=[];for(const[o,u]of Object.entries(r.results)){if(u.ok&&u.skipped.length===0)continue;const s=u.skipped[0]?.reason??u.warnings[0]??"did not apply";n.push(`${o}: ${s}`)}const d=r.route;if(d?.status==="failed"||d?.status==="unavailable")n.push(`route: ${d.status}`);return n}function useFlash(r){const[n,d]=(0,_react.useState)(0);(0,_react.useEffect)(()=>{if(!n)return;const o=setTimeout(()=>d(0),r);return()=>clearTimeout(o)},[n,r]);return[n>0,()=>d(o=>o+1)]}function TimeMachineFloatingTool({id:r,revealToken:n,dismiss:d}){const{snapshots:o,hasLoaded:u,busy:s}=(0,_useTimeMachine.useTimeMachineState)();const y=(0,_useTimeMachine.useSnapshotProviders)();const q=(0,_react.useSyncExternalStore)(_armedPoint.subscribePickedPoint,_armedPoint.getPickedPointId,_armedPoint.getPickedPointId);const k=(0,_sharedUi.useLimit)("timeMachine.snapshots");const w=(0,_react.useSyncExternalStore)(_barSettings.subscribeBarSettings,_barSettings.getBarReloadMode,_barSettings.getBarReloadMode);const{width:B}=(0,_reactNative.useWindowDimensions)();const[f,a]=(0,_react.useState)(null);const[h,I]=(0,_react.useState)(null);const[b,p]=(0,_react.useState)();const[W,v]=(0,_react.useState)(false);const[U,G]=useFlash(FLASH_MS);const[K,X]=useFlash(FLASH_MS);const[g,_]=(0,_react.useState)(null);const[T,A]=(0,_react.useState)(null);const[,J]=(0,_react.useState)(0);const m=(0,_react.useRef)(true);(0,_react.useEffect)(()=>{m.current=true;void(0,_armedPoint.ensurePickedPointLoaded)();void(0,_barSettings.ensureBarSettingsLoaded)();void _timeMachineStore.timeMachineStore.ensureLoaded();return()=>{m.current=false}},[]);const t=(0,_armedPoint.resolveArmedPoint)(o,q);const C=t?.id;const L=t?.lastRestoredAt;const O=t?.createdAt;(0,_react.useEffect)(()=>{if(L===void 0&&O===void 0&&!g&&T===null)return;const e=setInterval(()=>J(i=>i+1),2500);return()=>clearInterval(e)},[L,O,g,T]);(0,_react.useEffect)(()=>{if(h&&h.snapshotId!==C){I(null);a(e=>e==="outcome"?null:e)}},[C,h]);const S=Date.now();const z=g!==null&&S-g.at<RECENT_MS&&o.some(e=>e.id===g.id);const Q=o.filter(e=>!e.safety);const H=Q.length>=k;const P=!t||s!==null;const D=s!==null;const F=async(e,i)=>{if(s)return;a(null);p(void 0);try{const c=await _timeMachineStore.timeMachineStore.restore(e,w&&i.safetyCapture?"reload":"live",void 0,i);if(!m.current)return;if((0,_RestoreOutcomeCard.restoreNeedsAttention)(c)){I(c);a("outcome")}else{I(null);G()}_(c.safetySnapshotId?{id:c.safetySnapshotId,at:Date.now()}:null);if(c.safetySnapshotId)A(null)}catch(c){if(!m.current)return;p(c instanceof Error?c.message:String(c));a("error")}};const E=(e=false)=>{if(!t)return;void F(t.id,{safetyCapture:true,...e?{restoreRoute:false}:{}})};const Y=()=>{if(!g)return;void F(g.id,{safetyCapture:false,restoreRoute:false}).then(()=>{if(m.current)A(Date.now())})};const Z=()=>{if(s)return;p(void 0);if(H){a("cap");return}a(null);v(true)};const ee=async e=>{v(false);if(s)return;try{const i=await _timeMachineStore.timeMachineStore.capture(e);if(!m.current)return;(0,_armedPoint.setPickedPointId)(i.id);_(null);X()}catch(i){if(!m.current)return;p(i instanceof Error?i.message:String(i));a("error")}};const te=e=>{(0,_armedPoint.setPickedPointId)(e.id);a(null)};const N=t?.name??(u?"No restore points":"Loading\u2026");let l;let M="normal";let V=false;if(s==="restore")l="Restoring\u2026";else if(s==="capture")l="Capturing\u2026";else if(b){l=b;M="danger"}else if(h&&t&&h.snapshotId===t.id){l=failureSummary(h);M="danger"}else if(!t)l=u?"Capture one with +":"";else{V=true;const e=t.lastRestoredAt===void 0?null:S-t.lastRestoredAt;const i=S-t.createdAt;if(T!==null&&S-T<RECENT_MS)l="undone, state only";else if(e!==null&&e<RECENT_MS)l="restored just now";else if(i<RECENT_MS&&e===null)l="captured just now";else if(t.lastRestoredAt!==void 0)l=`restored ${(0,_format.timeAgo)(t.lastRestoredAt)}`;else l=`${Object.keys(t.sources).length} sources`;if(w)l+=" \xB7 reloads"}const j=V&&!z&&t&&t.route&&(0,_timeMachineStore.willRestoreRoute)(t)?t.route.pathname:null;const R=o.filter(e=>!e.baseline&&!e.safety);const ie=(()=>{const e=y.filter($=>$.status().canCapture&&(0,_sourceSettings.isSourceEnabled)($.id)).length;const i=(0,_routeRestore.captureCurrentRoute)();const c=[`${e} source${e===1?"":"s"}`];if(i)c.push(i.pathname);return c.join(" \xB7 ")})();let x;if(f==="picker"){x=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.menu,testID:"time-machine-bar-picker",children:[(0,_jsxRuntime.jsxs)(_reactNative.ScrollView,{style:styles.pickerList,bounces:false,children:[R.map(e=>{const i=e.id===t?.id;return(0,_jsxRuntime.jsxs)(_reactNative.TouchableOpacity,{testID:`time-machine-bar-pick-${e.id}`,accessibilityRole:"button",accessibilityState:{selected:i},accessibilityLabel:`Arm ${e.name}`,onPress:()=>te(e),style:styles.pickRow,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.pickText,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{numberOfLines:1,style:styles.pickName,children:e.name}),(0,_jsxRuntime.jsxs)(_reactNative.Text,{numberOfLines:1,style:styles.pickDetail,children:[(0,_format.timeAgo)(e.createdAt),e.route?` \xB7 ${e.route.pathname}`:"",e.lastRestoredAt!==void 0?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.pickRestored,children:` \xB7 restored ${(0,_format.timeAgo)(e.lastRestoredAt)}`}):null]})]}),i?(0,_jsxRuntime.jsx)(_sharedUi.Check,{size:14,color:_sharedUi.night.color.accent}):null]},e.id)}),R.length===0?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.menuText,children:"No restore points yet."}):null]}),R.length>PICKER_ROWS?(0,_jsxRuntime.jsxs)(_reactNative.Text,{style:styles.pickerMore,children:["Scroll for ",R.length-PICKER_ROWS," more"]}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.settingRow,testID:"time-machine-bar-reload-mode",children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.settingText,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.settingLabel,children:"Reload the app after restoring"}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.settingHint,children:"For screens that read their state from storage only when they open, like a cart kept in a React context."})]}),(0,_jsxRuntime.jsx)(_sharedUi.NightSwitch,{value:w,onValueChange:_barSettings.setBarReloadMode})]})]})}else if(f==="outcome"&&h){x=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.menu,testID:"time-machine-bar-outcome",children:[failureLines(h).map(e=>(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.menuDanger,children:e},e)),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.menuText,children:"The full report is on Time Machine's outcome card."}),(0,_jsxRuntime.jsx)(DismissLink,{onPress:()=>a(null)})]})}else if(f==="cap"){x=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.menu,testID:"time-machine-bar-cap",children:[(0,_jsxRuntime.jsxs)(_reactNative.Text,{style:styles.menuText,children:["Free plan keeps ",k," restore point",k===1?"":"s",". Delete one in Time Machine, or upgrade to Pro for unlimited snapshots."]}),(0,_jsxRuntime.jsx)(DismissLink,{onPress:()=>a(null)})]})}else if(f==="error"&&b){x=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.menu,testID:"time-machine-bar-error",children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{accessibilityRole:"alert",style:styles.menuDanger,children:b}),(0,_jsxRuntime.jsx)(DismissLink,{onPress:()=>{a(null);p(void 0)}})]})}return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_NamePromptModal.NamePromptModal,{visible:W,summary:ie,onCapture:e=>void ee(e),onCancel:()=>v(false)}),(0,_jsxRuntime.jsx)(_sharedUi.FloatingTool,{id:r,revealToken:n,variant:"strip",dragFromSurface:true,defaultPlacement:"bottom",accessibilityLabel:`Move or hide the action bar. ${t?`${t.name} armed`:"Nothing armed"}`,accessory:x,handleAdornment:(0,_jsxRuntime.jsx)(_sharedUi.TimeMachineIcon,{size:12,color:_sharedUi.night.color.accent}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[styles.row,{width:Math.max(260,Math.min(320,B-64))}],children:[(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-restore",accessibilityRole:"button",accessibilityLabel:t?`Restore ${t.name}`:"Restore, nothing armed",accessibilityHint:j?`Also returns to ${j}. Long press to restore state only.`:void 0,accessibilityState:{disabled:P},disabled:P,onPress:()=>E(false),onLongPress:()=>E(true),style:[styles.restoreButton,P&&styles.disabled],children:s==="restore"?(0,_jsxRuntime.jsx)(_reactNative.ActivityIndicator,{size:"small",color:_sharedUi.night.color.accent}):U?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.restoreText,testID:"time-machine-bar-restored",children:"Restored"}):(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.restoreText,children:"Restore"})}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.identity,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{testID:"time-machine-bar-name",accessibilityLabel:`Armed restore point: ${N}`,numberOfLines:1,ellipsizeMode:"middle",style:styles.name,children:N}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.statusRow,children:[(0,_jsxRuntime.jsxs)(_reactNative.Text,{testID:"time-machine-bar-status",numberOfLines:1,accessibilityLiveRegion:"polite",style:[styles.status,M==="danger"&&styles.danger],children:[l,j?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.destination,children:` \xB7 \u2192 ${j}`}):null]}),z&&!s?(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-undo",accessibilityRole:"button",accessibilityLabel:"Undo the last restore",onPress:Y,hitSlop:{top:8,bottom:8,left:6,right:6},children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.undo,children:"Undo"})}):null]})]}),(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-pick",accessibilityRole:"button",accessibilityLabel:"Choose another restore point",accessibilityState:{expanded:f==="picker"},onPress:()=>a(e=>e==="picker"?null:"picker"),style:styles.smallButton,children:f==="picker"?(0,_jsxRuntime.jsx)(_sharedUi.ChevronUp,{size:14,color:_sharedUi.night.color.textSecondary}):(0,_jsxRuntime.jsx)(_sharedUi.ChevronDown,{size:14,color:_sharedUi.night.color.textSecondary})}),(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-capture",accessibilityRole:"button",accessibilityLabel:"Capture a new restore point here and arm it",accessibilityState:{disabled:D},disabled:D,onPress:Z,style:[styles.smallButton,D&&styles.disabled],children:s==="capture"?(0,_jsxRuntime.jsx)(_reactNative.ActivityIndicator,{size:"small",color:_sharedUi.night.color.accent}):K?(0,_jsxRuntime.jsx)(_reactNative.View,{testID:"time-machine-bar-captured",children:(0,_jsxRuntime.jsx)(_sharedUi.Check,{size:18,color:_sharedUi.night.color.accent})}):(0,_jsxRuntime.jsx)(_sharedUi.Plus,{size:18,color:H?_sharedUi.night.color.textTertiary:_sharedUi.night.color.text})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.separator}),(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-close",accessibilityRole:"button",accessibilityLabel:"Close the action bar",onPress:d,style:styles.closeButton,children:(0,_jsxRuntime.jsx)(_sharedUi.X,{size:16,color:_sharedUi.night.color.textSecondary})})]})})]})}function DismissLink({onPress:r,label:n="Dismiss"}){return(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-dismiss",accessibilityRole:"button",onPress:r,style:styles.dismiss,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.dismissText,children:n})})}const styles=_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center",gap:4,paddingVertical:4,minHeight:48},restoreButton:{height:32,minWidth:72,paddingHorizontal:12,borderRadius:8,borderWidth:1,borderColor:_sharedUi.night.color.accentBorderStrong,backgroundColor:_sharedUi.night.color.accentSoft,alignItems:"center",justifyContent:"center",marginLeft:2},restoreText:{color:_sharedUi.night.color.accent,fontSize:12,fontWeight:"700"},smallButton:{width:32,minHeight:44,alignItems:"center",justifyContent:"center"},closeButton:{width:28,minHeight:44,alignItems:"center",justifyContent:"center"},identity:{flex:1,minHeight:44,justifyContent:"center",gap:1},name:{color:_sharedUi.night.color.text,fontSize:13,fontWeight:"500"},statusRow:{flexDirection:"row",alignItems:"center",gap:8},status:{color:_sharedUi.night.color.textSecondary,fontSize:10,lineHeight:14,flexShrink:1},destination:{color:_sharedUi.night.color.textTertiary},danger:{color:_sharedUi.night.color.danger},undo:{color:_sharedUi.night.color.accent,fontSize:10,lineHeight:14,fontWeight:"700"},separator:{height:20,width:1,backgroundColor:_sharedUi.night.color.separator,marginHorizontal:2},disabled:{opacity:.4},menu:{marginVertical:8,padding:6,borderRadius:_sharedUi.night.radius.card,borderWidth:1,borderColor:_sharedUi.night.color.separator,backgroundColor:_sharedUi.night.color.surface,shadowColor:"#000",shadowOffset:{width:0,height:6},shadowOpacity:.25,shadowRadius:16,elevation:8},menuText:{color:_sharedUi.night.color.textSecondary,fontSize:12,lineHeight:18,padding:10},menuDanger:{color:_sharedUi.night.color.danger,fontSize:12,lineHeight:18,paddingHorizontal:10,paddingTop:6},pickerList:{maxHeight:PICKER_ROWS*44},pickerMore:{color:_sharedUi.night.color.textTertiary,fontSize:10,lineHeight:14,textAlign:"center",paddingVertical:4},pickRow:{flexDirection:"row",alignItems:"center",gap:8,minHeight:44,paddingHorizontal:10,borderRadius:_sharedUi.night.radius.row},pickText:{flex:1},settingRow:{flexDirection:"row",alignItems:"center",gap:10,paddingHorizontal:10,paddingVertical:8,borderTopWidth:_reactNative.StyleSheet.hairlineWidth,borderTopColor:_sharedUi.night.color.separator,marginTop:4},settingText:{flex:1,gap:2},settingLabel:{color:_sharedUi.night.color.text,fontSize:12,fontWeight:"500"},settingHint:{color:_sharedUi.night.color.textTertiary,fontSize:10,lineHeight:13},pickName:{color:_sharedUi.night.color.text,fontSize:13,fontWeight:"500"},pickDetail:{color:_sharedUi.night.color.textSecondary,fontSize:10,lineHeight:14},pickRestored:{color:_sharedUi.night.color.accent},dismiss:{alignSelf:"flex-end",paddingHorizontal:10,paddingVertical:8},dismissText:{color:_sharedUi.night.color.accent,fontSize:12,fontWeight:"600"}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.TIME_MACHINE_FLOATING_TOOL_ID=void 0;exports.TimeMachineFloatingTool=TimeMachineFloatingTool;exports.openTimeMachineFloatingTool=openTimeMachineFloatingTool;exports.startTimeMachineFloatingToolPersistence=startTimeMachineFloatingToolPersistence;var _react=require("react");var _reactNative=require("react-native");var _sharedUi=require("@buoy-gg/shared-ui");var _useTimeMachine=require("../../hooks/useTimeMachine");var _timeMachineStore=require("../../store/timeMachineStore");var _routeRestore=require("../../store/routeRestore");var _sourceSettings=require("../../store/sourceSettings");var _RestoreOutcomeCard=require("../list/RestoreOutcomeCard");var _format=require("../format");var _armedPoint=require("./armedPoint");var _NamePromptModal=require("./NamePromptModal");var _barSettings=require("./barSettings");var _jsxRuntime=require("react/jsx-runtime");const TIME_MACHINE_FLOATING_TOOL_ID=exports.TIME_MACHINE_FLOATING_TOOL_ID="time-machine-restore";const RECENT_MS=1e4;const FLASH_MS=900;const PICKER_ROWS=6;const registration={id:TIME_MACHINE_FLOATING_TOOL_ID,render:r=>(0,_jsxRuntime.jsx)(TimeMachineFloatingTool,{...r})};let persistenceStarted=false;function startTimeMachineFloatingToolPersistence(){if(persistenceStarted)return;persistenceStarted=true;(0,_sharedUi.registerPersistentFloatingTool)(registration,_sharedUi.persistentStorage)}if(typeof __DEV__!=="undefined"&&__DEV__&&typeof navigator!=="undefined"&&navigator.product==="ReactNative"){startTimeMachineFloatingToolPersistence()}function openTimeMachineFloatingTool(r){if(r)(0,_armedPoint.setPickedPointId)(r);(0,_sharedUi.openFloatingTool)(registration)}function failureSummary(r){const n=Object.values(r.results);const d=n.filter(y=>!y.ok||y.skipped.length>0).length;const o=n.length;const u=r.route;const s=u?.status==="failed"||u?.status==="unavailable";if(d===0&&s)return"Route did not restore";return`${d} of ${o} source${o===1?"":"s"} failed`}function failureLines(r){const n=[];for(const[o,u]of Object.entries(r.results)){if(u.ok&&u.skipped.length===0)continue;const s=u.skipped[0]?.reason??u.warnings[0]??"did not apply";n.push(`${o}: ${s}`)}const d=r.route;if(d?.status==="failed"||d?.status==="unavailable")n.push(`route: ${d.status}`);return n}function useFlash(r){const[n,d]=(0,_react.useState)(0);(0,_react.useEffect)(()=>{if(!n)return;const o=setTimeout(()=>d(0),r);return()=>clearTimeout(o)},[n,r]);return[n>0,()=>d(o=>o+1)]}function TimeMachineFloatingTool({id:r,revealToken:n,dismiss:d}){const{snapshots:o,hasLoaded:u,busy:s}=(0,_useTimeMachine.useTimeMachineState)();const y=(0,_useTimeMachine.useSnapshotProviders)();const q=(0,_react.useSyncExternalStore)(_armedPoint.subscribePickedPoint,_armedPoint.getPickedPointId,_armedPoint.getPickedPointId);const k=(0,_sharedUi.useLimit)("timeMachine.snapshots");const w=(0,_react.useSyncExternalStore)(_barSettings.subscribeBarSettings,_barSettings.getBarReloadMode,_barSettings.getBarReloadMode);const{width:B}=(0,_reactNative.useWindowDimensions)();const[f,a]=(0,_react.useState)(null);const[h,I]=(0,_react.useState)(null);const[b,p]=(0,_react.useState)();const[W,v]=(0,_react.useState)(false);const[U,G]=useFlash(FLASH_MS);const[K,X]=useFlash(FLASH_MS);const[g,_]=(0,_react.useState)(null);const[T,L]=(0,_react.useState)(null);const[,J]=(0,_react.useState)(0);const m=(0,_react.useRef)(true);(0,_react.useEffect)(()=>{m.current=true;void(0,_armedPoint.ensurePickedPointLoaded)();void(0,_barSettings.ensureBarSettingsLoaded)();void _timeMachineStore.timeMachineStore.ensureLoaded();return()=>{m.current=false}},[]);const t=(0,_armedPoint.resolveArmedPoint)(o,q);const A=t?.id;const C=t?.lastRestoredAt;const O=t?.createdAt;(0,_react.useEffect)(()=>{if(C===void 0&&O===void 0&&!g&&T===null)return;const e=setInterval(()=>J(i=>i+1),2500);return()=>clearInterval(e)},[C,O,g,T]);(0,_react.useEffect)(()=>{if(h&&h.snapshotId!==A){I(null);a(e=>e==="outcome"?null:e)}},[A,h]);const S=Date.now();const z=g!==null&&S-g.at<RECENT_MS&&o.some(e=>e.id===g.id);const Q=o.filter(e=>!e.safety);const H=Q.length>=k;const D=!t||s!==null;const P=s!==null;const F=async(e,i)=>{if(s)return;a(null);p(void 0);try{const c=await _timeMachineStore.timeMachineStore.restore(e,w&&i.safetyCapture?"reload":"live",void 0,i);if(!m.current)return;if((0,_RestoreOutcomeCard.restoreNeedsAttention)(c)){I(c);a("outcome")}else{I(null);G()}_(c.safetySnapshotId?{id:c.safetySnapshotId,at:Date.now()}:null);if(c.safetySnapshotId)L(null)}catch(c){if(!m.current)return;p(c instanceof Error?c.message:String(c));a("error")}};const E=(e=false)=>{if(!t)return;void F(t.id,{safetyCapture:true,...e?{restoreRoute:false}:{}})};const Y=()=>{if(!g)return;void F(g.id,{safetyCapture:false,restoreRoute:false}).then(()=>{if(m.current)L(Date.now())})};const Z=()=>{if(s)return;p(void 0);if(H){a("cap");return}a(null);v(true)};const ee=async e=>{v(false);if(s)return;try{const i=await _timeMachineStore.timeMachineStore.capture(e);if(!m.current)return;(0,_armedPoint.setPickedPointId)(i.id);_(null);X()}catch(i){if(!m.current)return;p(i instanceof Error?i.message:String(i));a("error")}};const te=e=>{(0,_armedPoint.setPickedPointId)(e.id);a(null)};const N=t?.name??(u?"No restore points":"Loading\u2026");let l;let M="normal";let V=false;if(s==="restore")l="Restoring\u2026";else if(s==="capture")l="Capturing\u2026";else if(b){l=b;M="danger"}else if(h&&t&&h.snapshotId===t.id){l=failureSummary(h);M="danger"}else if(!t)l=u?"Capture one with +":"";else{V=true;const e=t.lastRestoredAt===void 0?null:S-t.lastRestoredAt;const i=S-t.createdAt;if(T!==null&&S-T<RECENT_MS)l="undone, state only";else if(e!==null&&e<RECENT_MS)l="restored just now";else if(i<RECENT_MS&&e===null)l="captured just now";else if(t.lastRestoredAt!==void 0)l=`restored ${(0,_format.timeAgo)(t.lastRestoredAt)}`;else l=`${Object.keys(t.sources).length} sources`;if(w)l+=" \xB7 reloads"}const j=V&&!z&&t&&t.route&&(0,_timeMachineStore.willRestoreRoute)(t)?t.route.pathname:null;const R=o.filter(e=>!e.baseline&&!e.safety);const ie=(()=>{const e=y.filter($=>$.status().canCapture&&(0,_sourceSettings.isSourceEnabled)($.id)).length;const i=(0,_routeRestore.captureCurrentRoute)();const c=[`${e} source${e===1?"":"s"}`];if(i)c.push(i.pathname);return c.join(" \xB7 ")})();let x;if(f==="picker"){x=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.menu,testID:"time-machine-bar-picker",children:[(0,_jsxRuntime.jsxs)(_reactNative.ScrollView,{style:styles.pickerList,bounces:false,children:[R.map(e=>{const i=e.id===t?.id;return(0,_jsxRuntime.jsxs)(_reactNative.TouchableOpacity,{testID:`time-machine-bar-pick-${e.id}`,accessibilityRole:"button",accessibilityState:{selected:i},accessibilityLabel:`Arm ${e.name}`,onPress:()=>te(e),style:styles.pickRow,children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.pickText,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{numberOfLines:1,style:styles.pickName,children:e.name}),(0,_jsxRuntime.jsxs)(_reactNative.Text,{numberOfLines:1,style:styles.pickDetail,children:[(0,_format.timeAgo)(e.createdAt),e.route?` \xB7 ${e.route.pathname}`:"",e.lastRestoredAt!==void 0?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.pickRestored,children:` \xB7 restored ${(0,_format.timeAgo)(e.lastRestoredAt)}`}):null]})]}),i?(0,_jsxRuntime.jsx)(_sharedUi.Check,{size:14,color:_sharedUi.night.color.accent}):null]},e.id)}),R.length===0?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.menuText,children:"No restore points yet."}):null]}),R.length>PICKER_ROWS?(0,_jsxRuntime.jsxs)(_reactNative.Text,{style:styles.pickerMore,children:["Scroll for ",R.length-PICKER_ROWS," more"]}):null,(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.settingRow,testID:"time-machine-bar-reload-mode",children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.settingText,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.settingLabel,children:"Reload the app after restoring"}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.settingHint,children:"For screens that read their state from storage only when they open, like a cart kept in a React context."})]}),(0,_jsxRuntime.jsx)(_sharedUi.NightSwitch,{value:w,onValueChange:_barSettings.setBarReloadMode,testID:"time-machine-bar-reload-switch",accessibilityLabel:"Reload the app after restoring"})]})]})}else if(f==="outcome"&&h){x=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.menu,testID:"time-machine-bar-outcome",children:[failureLines(h).map(e=>(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.menuDanger,children:e},e)),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.menuText,children:"The full report is on Time Machine's outcome card."}),(0,_jsxRuntime.jsx)(DismissLink,{onPress:()=>a(null)})]})}else if(f==="cap"){x=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.menu,testID:"time-machine-bar-cap",children:[(0,_jsxRuntime.jsxs)(_reactNative.Text,{style:styles.menuText,children:["Free plan keeps ",k," restore point",k===1?"":"s",". Delete one in Time Machine, or upgrade to Pro for unlimited snapshots."]}),(0,_jsxRuntime.jsx)(DismissLink,{onPress:()=>a(null)})]})}else if(f==="error"&&b){x=(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.menu,testID:"time-machine-bar-error",children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{accessibilityRole:"alert",style:styles.menuDanger,children:b}),(0,_jsxRuntime.jsx)(DismissLink,{onPress:()=>{a(null);p(void 0)}})]})}return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_NamePromptModal.NamePromptModal,{visible:W,summary:ie,onCapture:e=>void ee(e),onCancel:()=>v(false)}),(0,_jsxRuntime.jsx)(_sharedUi.FloatingTool,{id:r,revealToken:n,variant:"strip",dragFromSurface:true,defaultPlacement:"bottom",accessibilityLabel:`Move or hide the action bar. ${t?`${t.name} armed`:"Nothing armed"}`,accessory:x,handleAdornment:(0,_jsxRuntime.jsx)(_sharedUi.TimeMachineIcon,{size:12,color:_sharedUi.night.color.accent}),children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[styles.row,{width:Math.max(260,Math.min(320,B-64))}],children:[(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-restore",accessibilityRole:"button",accessibilityLabel:t?`Restore ${t.name}`:"Restore, nothing armed",accessibilityHint:j?`Also returns to ${j}. Long press to restore state only.`:void 0,accessibilityState:{disabled:D},disabled:D,onPress:()=>E(false),onLongPress:()=>E(true),style:[styles.restoreButton,D&&styles.disabled],children:s==="restore"?(0,_jsxRuntime.jsx)(_reactNative.ActivityIndicator,{size:"small",color:_sharedUi.night.color.accent}):U?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.restoreText,testID:"time-machine-bar-restored",children:"Restored"}):(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.restoreText,children:"Restore"})}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.identity,children:[(0,_jsxRuntime.jsx)(_reactNative.Text,{testID:"time-machine-bar-name",accessibilityLabel:`Armed restore point: ${N}`,numberOfLines:1,ellipsizeMode:"middle",style:styles.name,children:N}),(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.statusRow,children:[(0,_jsxRuntime.jsxs)(_reactNative.Text,{testID:"time-machine-bar-status",numberOfLines:1,accessibilityLiveRegion:"polite",style:[styles.status,M==="danger"&&styles.danger],children:[l,j?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.destination,children:` \xB7 \u2192 ${j}`}):null]}),z&&!s?(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-undo",accessibilityRole:"button",accessibilityLabel:"Undo the last restore",onPress:Y,hitSlop:{top:8,bottom:8,left:6,right:6},children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.undo,children:"Undo"})}):null]})]}),(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-pick",accessibilityRole:"button",accessibilityLabel:"Choose another restore point",accessibilityState:{expanded:f==="picker"},onPress:()=>a(e=>e==="picker"?null:"picker"),style:styles.smallButton,children:f==="picker"?(0,_jsxRuntime.jsx)(_sharedUi.ChevronUp,{size:14,color:_sharedUi.night.color.textSecondary}):(0,_jsxRuntime.jsx)(_sharedUi.ChevronDown,{size:14,color:_sharedUi.night.color.textSecondary})}),(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-capture",accessibilityRole:"button",accessibilityLabel:"Capture a new restore point here and arm it",accessibilityState:{disabled:P},disabled:P,onPress:Z,style:[styles.smallButton,P&&styles.disabled],children:s==="capture"?(0,_jsxRuntime.jsx)(_reactNative.ActivityIndicator,{size:"small",color:_sharedUi.night.color.accent}):K?(0,_jsxRuntime.jsx)(_reactNative.View,{testID:"time-machine-bar-captured",children:(0,_jsxRuntime.jsx)(_sharedUi.Check,{size:18,color:_sharedUi.night.color.accent})}):(0,_jsxRuntime.jsx)(_sharedUi.Plus,{size:18,color:H?_sharedUi.night.color.textTertiary:_sharedUi.night.color.text})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.separator}),(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-close",accessibilityRole:"button",accessibilityLabel:"Close the action bar",onPress:d,style:styles.closeButton,children:(0,_jsxRuntime.jsx)(_sharedUi.X,{size:16,color:_sharedUi.night.color.textSecondary})})]})})]})}function DismissLink({onPress:r,label:n="Dismiss"}){return(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"time-machine-bar-dismiss",accessibilityRole:"button",onPress:r,style:styles.dismiss,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.dismissText,children:n})})}const styles=_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center",gap:4,paddingVertical:4,minHeight:48},restoreButton:{height:32,minWidth:72,paddingHorizontal:12,borderRadius:8,borderWidth:1,borderColor:_sharedUi.night.color.accentBorderStrong,backgroundColor:_sharedUi.night.color.accentSoft,alignItems:"center",justifyContent:"center",marginLeft:2},restoreText:{color:_sharedUi.night.color.accent,fontSize:12,fontWeight:"700"},smallButton:{width:32,minHeight:44,alignItems:"center",justifyContent:"center"},closeButton:{width:28,minHeight:44,alignItems:"center",justifyContent:"center"},identity:{flex:1,minHeight:44,justifyContent:"center",gap:1},name:{color:_sharedUi.night.color.text,fontSize:13,fontWeight:"500"},statusRow:{flexDirection:"row",alignItems:"center",gap:8},status:{color:_sharedUi.night.color.textSecondary,fontSize:10,lineHeight:14,flexShrink:1},destination:{color:_sharedUi.night.color.textTertiary},danger:{color:_sharedUi.night.color.danger},undo:{color:_sharedUi.night.color.accent,fontSize:10,lineHeight:14,fontWeight:"700"},separator:{height:20,width:1,backgroundColor:_sharedUi.night.color.separator,marginHorizontal:2},disabled:{opacity:.4},menu:{marginVertical:8,padding:6,borderRadius:_sharedUi.night.radius.card,borderWidth:1,borderColor:_sharedUi.night.color.separator,backgroundColor:_sharedUi.night.color.surface,shadowColor:"#000",shadowOffset:{width:0,height:6},shadowOpacity:.25,shadowRadius:16,elevation:8},menuText:{color:_sharedUi.night.color.textSecondary,fontSize:12,lineHeight:18,padding:10},menuDanger:{color:_sharedUi.night.color.danger,fontSize:12,lineHeight:18,paddingHorizontal:10,paddingTop:6},pickerList:{maxHeight:PICKER_ROWS*44},pickerMore:{color:_sharedUi.night.color.textTertiary,fontSize:10,lineHeight:14,textAlign:"center",paddingVertical:4},pickRow:{flexDirection:"row",alignItems:"center",gap:8,minHeight:44,paddingHorizontal:10,borderRadius:_sharedUi.night.radius.row},pickText:{flex:1},settingRow:{flexDirection:"row",alignItems:"center",gap:10,paddingHorizontal:10,paddingVertical:8,borderTopWidth:_reactNative.StyleSheet.hairlineWidth,borderTopColor:_sharedUi.night.color.separator,marginTop:4},settingText:{flex:1,gap:2},settingLabel:{color:_sharedUi.night.color.text,fontSize:12,fontWeight:"500"},settingHint:{color:_sharedUi.night.color.textTertiary,fontSize:10,lineHeight:13},pickName:{color:_sharedUi.night.color.text,fontSize:13,fontWeight:"500"},pickDetail:{color:_sharedUi.night.color.textSecondary,fontSize:10,lineHeight:14},pickRestored:{color:_sharedUi.night.color.accent},dismiss:{alignSelf:"flex-end",paddingHorizontal:10,paddingVertical:8},dismissText:{color:_sharedUi.night.color.accent,fontSize:12,fontWeight:"600"}});
@@ -1 +1 @@
1
- "use strict";import{useEffect as z,useRef as Ce,useState as S,useSyncExternalStore as ne}from"react";import{ActivityIndicator as ie,ScrollView as Ae,StyleSheet as se,Text as s,TouchableOpacity as k,View as p,useWindowDimensions as ve}from"react-native";import{Check as le,ChevronDown as Pe,ChevronUp as ze,FloatingTool as He,NightSwitch as Me,Plus as _e,TimeMachineIcon as $e,X as Fe,night as r,openFloatingTool as je,persistentStorage as Ne,registerPersistentFloatingTool as Oe,useLimit as Ee}from"@buoy-gg/shared-ui";import{useSnapshotProviders as We,useTimeMachineState as Be}from"../../hooks/useTimeMachine";import{timeMachineStore as E,willRestoreRoute as Ve}from"../../store/timeMachineStore";import{captureCurrentRoute as Ue}from"../../store/routeRestore";import{isSourceEnabled as Ge}from"../../store/sourceSettings";import{restoreNeedsAttention as Ke}from"../list/RestoreOutcomeCard";import{timeAgo as W}from"../format";import{ensurePickedPointLoaded as Xe,getPickedPointId as ae,resolveArmedPoint as qe,setPickedPointId as B,subscribePickedPoint as Je}from"./armedPoint";import{NamePromptModal as Qe}from"./NamePromptModal";import{ensureBarSettingsLoaded as Ye,getBarReloadMode as ce,setBarReloadMode as Ze,subscribeBarSettings as et}from"./barSettings";import{jsx as o,jsxs as a,Fragment as tt}from"react/jsx-runtime";export const TIME_MACHINE_FLOATING_TOOL_ID="time-machine-restore";const H=1e4;const de=900;const V=6;const ue={id:TIME_MACHINE_FLOATING_TOOL_ID,render:l=>o(TimeMachineFloatingTool,{...l})};let he=false;export function startTimeMachineFloatingToolPersistence(){if(he)return;he=true;Oe(ue,Ne)}if(typeof __DEV__!=="undefined"&&__DEV__&&typeof navigator!=="undefined"&&navigator.product==="ReactNative"){startTimeMachineFloatingToolPersistence()}export function openTimeMachineFloatingTool(l){if(l)B(l);je(ue)}function ot(l){const c=Object.values(l.results);const g=c.filter(D=>!D.ok||D.skipped.length>0).length;const u=c.length;const y=l.route;const d=y?.status==="failed"||y?.status==="unavailable";if(g===0&&d)return"Route did not restore";return`${g} of ${u} source${u===1?"":"s"} failed`}function rt(l){const c=[];for(const[u,y]of Object.entries(l.results)){if(y.ok&&y.skipped.length===0)continue;const d=y.skipped[0]?.reason??y.warnings[0]??"did not apply";c.push(`${u}: ${d}`)}const g=l.route;if(g?.status==="failed"||g?.status==="unavailable")c.push(`route: ${g.status}`);return c}function me(l){const[c,g]=S(0);z(()=>{if(!c)return;const u=setTimeout(()=>g(0),l);return()=>clearTimeout(u)},[c,l]);return[c>0,()=>g(u=>u+1)]}export function TimeMachineFloatingTool({id:l,revealToken:c,dismiss:g}){const{snapshots:u,hasLoaded:y,busy:d}=Be();const D=We();const fe=ne(Je,ae,ae);const M=Ee("timeMachine.snapshots");const _=ne(et,ce,ce);const{width:pe}=ve();const[T,h]=S(null);const[b,$]=S(null);const[L,w]=S();const[ge,F]=S(false);const[ye,be]=me(de);const[Se,Re]=me(de);const[R,G]=S(null);const[C,K]=S(null);const[,xe]=S(0);const x=Ce(true);z(()=>{x.current=true;void Xe();void Ye();void E.ensureLoaded();return()=>{x.current=false}},[]);const n=qe(u,fe);const X=n?.id;const q=n?.lastRestoredAt;const J=n?.createdAt;z(()=>{if(q===void 0&&J===void 0&&!R&&C===null)return;const e=setInterval(()=>xe(i=>i+1),2500);return()=>clearInterval(e)},[q,J,R,C]);z(()=>{if(b&&b.snapshotId!==X){$(null);h(e=>e==="outcome"?null:e)}},[X,b]);const A=Date.now();const Q=R!==null&&A-R.at<H&&u.some(e=>e.id===R.id);const ke=u.filter(e=>!e.safety);const Y=ke.length>=M;const j=!n||d!==null;const N=d!==null;const Z=async(e,i)=>{if(d)return;h(null);w(void 0);try{const f=await E.restore(e,_&&i.safetyCapture?"reload":"live",void 0,i);if(!x.current)return;if(Ke(f)){$(f);h("outcome")}else{$(null);be()}G(f.safetySnapshotId?{id:f.safetySnapshotId,at:Date.now()}:null);if(f.safetySnapshotId)K(null)}catch(f){if(!x.current)return;w(f instanceof Error?f.message:String(f));h("error")}};const ee=(e=false)=>{if(!n)return;void Z(n.id,{safetyCapture:true,...e?{restoreRoute:false}:{}})};const Te=()=>{if(!R)return;void Z(R.id,{safetyCapture:false,restoreRoute:false}).then(()=>{if(x.current)K(Date.now())})};const we=()=>{if(d)return;w(void 0);if(Y){h("cap");return}h(null);F(true)};const Ie=async e=>{F(false);if(d)return;try{const i=await E.capture(e);if(!x.current)return;B(i.id);G(null);Re()}catch(i){if(!x.current)return;w(i instanceof Error?i.message:String(i));h("error")}};const De=e=>{B(e.id);h(null)};const te=n?.name??(y?"No restore points":"Loading\u2026");let m;let O="normal";let oe=false;if(d==="restore")m="Restoring\u2026";else if(d==="capture")m="Capturing\u2026";else if(L){m=L;O="danger"}else if(b&&n&&b.snapshotId===n.id){m=ot(b);O="danger"}else if(!n)m=y?"Capture one with +":"";else{oe=true;const e=n.lastRestoredAt===void 0?null:A-n.lastRestoredAt;const i=A-n.createdAt;if(C!==null&&A-C<H)m="undone, state only";else if(e!==null&&e<H)m="restored just now";else if(i<H&&e===null)m="captured just now";else if(n.lastRestoredAt!==void 0)m=`restored ${W(n.lastRestoredAt)}`;else m=`${Object.keys(n.sources).length} sources`;if(_)m+=" \xB7 reloads"}const v=oe&&!Q&&n&&n.route&&Ve(n)?n.route.pathname:null;const P=u.filter(e=>!e.baseline&&!e.safety);const Le=(()=>{const e=D.filter(re=>re.status().canCapture&&Ge(re.id)).length;const i=Ue();const f=[`${e} source${e===1?"":"s"}`];if(i)f.push(i.pathname);return f.join(" \xB7 ")})();let I;if(T==="picker"){I=a(p,{style:t.menu,testID:"time-machine-bar-picker",children:[a(Ae,{style:t.pickerList,bounces:false,children:[P.map(e=>{const i=e.id===n?.id;return a(k,{testID:`time-machine-bar-pick-${e.id}`,accessibilityRole:"button",accessibilityState:{selected:i},accessibilityLabel:`Arm ${e.name}`,onPress:()=>De(e),style:t.pickRow,children:[a(p,{style:t.pickText,children:[o(s,{numberOfLines:1,style:t.pickName,children:e.name}),a(s,{numberOfLines:1,style:t.pickDetail,children:[W(e.createdAt),e.route?` \xB7 ${e.route.pathname}`:"",e.lastRestoredAt!==void 0?o(s,{style:t.pickRestored,children:` \xB7 restored ${W(e.lastRestoredAt)}`}):null]})]}),i?o(le,{size:14,color:r.color.accent}):null]},e.id)}),P.length===0?o(s,{style:t.menuText,children:"No restore points yet."}):null]}),P.length>V?a(s,{style:t.pickerMore,children:["Scroll for ",P.length-V," more"]}):null,a(p,{style:t.settingRow,testID:"time-machine-bar-reload-mode",children:[a(p,{style:t.settingText,children:[o(s,{style:t.settingLabel,children:"Reload the app after restoring"}),o(s,{style:t.settingHint,children:"For screens that read their state from storage only when they open, like a cart kept in a React context."})]}),o(Me,{value:_,onValueChange:Ze})]})]})}else if(T==="outcome"&&b){I=a(p,{style:t.menu,testID:"time-machine-bar-outcome",children:[rt(b).map(e=>o(s,{style:t.menuDanger,children:e},e)),o(s,{style:t.menuText,children:"The full report is on Time Machine's outcome card."}),o(U,{onPress:()=>h(null)})]})}else if(T==="cap"){I=a(p,{style:t.menu,testID:"time-machine-bar-cap",children:[a(s,{style:t.menuText,children:["Free plan keeps ",M," restore point",M===1?"":"s",". Delete one in Time Machine, or upgrade to Pro for unlimited snapshots."]}),o(U,{onPress:()=>h(null)})]})}else if(T==="error"&&L){I=a(p,{style:t.menu,testID:"time-machine-bar-error",children:[o(s,{accessibilityRole:"alert",style:t.menuDanger,children:L}),o(U,{onPress:()=>{h(null);w(void 0)}})]})}return a(tt,{children:[o(Qe,{visible:ge,summary:Le,onCapture:e=>void Ie(e),onCancel:()=>F(false)}),o(He,{id:l,revealToken:c,variant:"strip",dragFromSurface:true,defaultPlacement:"bottom",accessibilityLabel:`Move or hide the action bar. ${n?`${n.name} armed`:"Nothing armed"}`,accessory:I,handleAdornment:o($e,{size:12,color:r.color.accent}),children:a(p,{style:[t.row,{width:Math.max(260,Math.min(320,pe-64))}],children:[o(k,{testID:"time-machine-bar-restore",accessibilityRole:"button",accessibilityLabel:n?`Restore ${n.name}`:"Restore, nothing armed",accessibilityHint:v?`Also returns to ${v}. Long press to restore state only.`:void 0,accessibilityState:{disabled:j},disabled:j,onPress:()=>ee(false),onLongPress:()=>ee(true),style:[t.restoreButton,j&&t.disabled],children:d==="restore"?o(ie,{size:"small",color:r.color.accent}):ye?o(s,{style:t.restoreText,testID:"time-machine-bar-restored",children:"Restored"}):o(s,{style:t.restoreText,children:"Restore"})}),a(p,{style:t.identity,children:[o(s,{testID:"time-machine-bar-name",accessibilityLabel:`Armed restore point: ${te}`,numberOfLines:1,ellipsizeMode:"middle",style:t.name,children:te}),a(p,{style:t.statusRow,children:[a(s,{testID:"time-machine-bar-status",numberOfLines:1,accessibilityLiveRegion:"polite",style:[t.status,O==="danger"&&t.danger],children:[m,v?o(s,{style:t.destination,children:` \xB7 \u2192 ${v}`}):null]}),Q&&!d?o(k,{testID:"time-machine-bar-undo",accessibilityRole:"button",accessibilityLabel:"Undo the last restore",onPress:Te,hitSlop:{top:8,bottom:8,left:6,right:6},children:o(s,{style:t.undo,children:"Undo"})}):null]})]}),o(k,{testID:"time-machine-bar-pick",accessibilityRole:"button",accessibilityLabel:"Choose another restore point",accessibilityState:{expanded:T==="picker"},onPress:()=>h(e=>e==="picker"?null:"picker"),style:t.smallButton,children:T==="picker"?o(ze,{size:14,color:r.color.textSecondary}):o(Pe,{size:14,color:r.color.textSecondary})}),o(k,{testID:"time-machine-bar-capture",accessibilityRole:"button",accessibilityLabel:"Capture a new restore point here and arm it",accessibilityState:{disabled:N},disabled:N,onPress:we,style:[t.smallButton,N&&t.disabled],children:d==="capture"?o(ie,{size:"small",color:r.color.accent}):Se?o(p,{testID:"time-machine-bar-captured",children:o(le,{size:18,color:r.color.accent})}):o(_e,{size:18,color:Y?r.color.textTertiary:r.color.text})}),o(p,{style:t.separator}),o(k,{testID:"time-machine-bar-close",accessibilityRole:"button",accessibilityLabel:"Close the action bar",onPress:g,style:t.closeButton,children:o(Fe,{size:16,color:r.color.textSecondary})})]})})]})}function U({onPress:l,label:c="Dismiss"}){return o(k,{testID:"time-machine-bar-dismiss",accessibilityRole:"button",onPress:l,style:t.dismiss,children:o(s,{style:t.dismissText,children:c})})}const t=se.create({row:{flexDirection:"row",alignItems:"center",gap:4,paddingVertical:4,minHeight:48},restoreButton:{height:32,minWidth:72,paddingHorizontal:12,borderRadius:8,borderWidth:1,borderColor:r.color.accentBorderStrong,backgroundColor:r.color.accentSoft,alignItems:"center",justifyContent:"center",marginLeft:2},restoreText:{color:r.color.accent,fontSize:12,fontWeight:"700"},smallButton:{width:32,minHeight:44,alignItems:"center",justifyContent:"center"},closeButton:{width:28,minHeight:44,alignItems:"center",justifyContent:"center"},identity:{flex:1,minHeight:44,justifyContent:"center",gap:1},name:{color:r.color.text,fontSize:13,fontWeight:"500"},statusRow:{flexDirection:"row",alignItems:"center",gap:8},status:{color:r.color.textSecondary,fontSize:10,lineHeight:14,flexShrink:1},destination:{color:r.color.textTertiary},danger:{color:r.color.danger},undo:{color:r.color.accent,fontSize:10,lineHeight:14,fontWeight:"700"},separator:{height:20,width:1,backgroundColor:r.color.separator,marginHorizontal:2},disabled:{opacity:.4},menu:{marginVertical:8,padding:6,borderRadius:r.radius.card,borderWidth:1,borderColor:r.color.separator,backgroundColor:r.color.surface,shadowColor:"#000",shadowOffset:{width:0,height:6},shadowOpacity:.25,shadowRadius:16,elevation:8},menuText:{color:r.color.textSecondary,fontSize:12,lineHeight:18,padding:10},menuDanger:{color:r.color.danger,fontSize:12,lineHeight:18,paddingHorizontal:10,paddingTop:6},pickerList:{maxHeight:V*44},pickerMore:{color:r.color.textTertiary,fontSize:10,lineHeight:14,textAlign:"center",paddingVertical:4},pickRow:{flexDirection:"row",alignItems:"center",gap:8,minHeight:44,paddingHorizontal:10,borderRadius:r.radius.row},pickText:{flex:1},settingRow:{flexDirection:"row",alignItems:"center",gap:10,paddingHorizontal:10,paddingVertical:8,borderTopWidth:se.hairlineWidth,borderTopColor:r.color.separator,marginTop:4},settingText:{flex:1,gap:2},settingLabel:{color:r.color.text,fontSize:12,fontWeight:"500"},settingHint:{color:r.color.textTertiary,fontSize:10,lineHeight:13},pickName:{color:r.color.text,fontSize:13,fontWeight:"500"},pickDetail:{color:r.color.textSecondary,fontSize:10,lineHeight:14},pickRestored:{color:r.color.accent},dismiss:{alignSelf:"flex-end",paddingHorizontal:10,paddingVertical:8},dismissText:{color:r.color.accent,fontSize:12,fontWeight:"600"}});
1
+ "use strict";import{useEffect as z,useRef as Ce,useState as S,useSyncExternalStore as ie}from"react";import{ActivityIndicator as ne,ScrollView as Ae,StyleSheet as se,Text as s,TouchableOpacity as k,View as p,useWindowDimensions as ve}from"react-native";import{Check as le,ChevronDown as Pe,ChevronUp as ze,FloatingTool as He,NightSwitch as Me,Plus as _e,TimeMachineIcon as $e,X as Fe,night as o,openFloatingTool as je,persistentStorage as Ne,registerPersistentFloatingTool as Oe,useLimit as Ee}from"@buoy-gg/shared-ui";import{useSnapshotProviders as We,useTimeMachineState as Be}from"../../hooks/useTimeMachine";import{timeMachineStore as E,willRestoreRoute as Ve}from"../../store/timeMachineStore";import{captureCurrentRoute as Ue}from"../../store/routeRestore";import{isSourceEnabled as Ge}from"../../store/sourceSettings";import{restoreNeedsAttention as Ke}from"../list/RestoreOutcomeCard";import{timeAgo as W}from"../format";import{ensurePickedPointLoaded as Xe,getPickedPointId as ae,resolveArmedPoint as qe,setPickedPointId as B,subscribePickedPoint as Je}from"./armedPoint";import{NamePromptModal as Qe}from"./NamePromptModal";import{ensureBarSettingsLoaded as Ye,getBarReloadMode as ce,setBarReloadMode as Ze,subscribeBarSettings as et}from"./barSettings";import{jsx as r,jsxs as a,Fragment as tt}from"react/jsx-runtime";export const TIME_MACHINE_FLOATING_TOOL_ID="time-machine-restore";const H=1e4;const de=900;const V=6;const ue={id:TIME_MACHINE_FLOATING_TOOL_ID,render:l=>r(TimeMachineFloatingTool,{...l})};let he=false;export function startTimeMachineFloatingToolPersistence(){if(he)return;he=true;Oe(ue,Ne)}if(typeof __DEV__!=="undefined"&&__DEV__&&typeof navigator!=="undefined"&&navigator.product==="ReactNative"){startTimeMachineFloatingToolPersistence()}export function openTimeMachineFloatingTool(l){if(l)B(l);je(ue)}function rt(l){const c=Object.values(l.results);const g=c.filter(D=>!D.ok||D.skipped.length>0).length;const u=c.length;const y=l.route;const d=y?.status==="failed"||y?.status==="unavailable";if(g===0&&d)return"Route did not restore";return`${g} of ${u} source${u===1?"":"s"} failed`}function ot(l){const c=[];for(const[u,y]of Object.entries(l.results)){if(y.ok&&y.skipped.length===0)continue;const d=y.skipped[0]?.reason??y.warnings[0]??"did not apply";c.push(`${u}: ${d}`)}const g=l.route;if(g?.status==="failed"||g?.status==="unavailable")c.push(`route: ${g.status}`);return c}function me(l){const[c,g]=S(0);z(()=>{if(!c)return;const u=setTimeout(()=>g(0),l);return()=>clearTimeout(u)},[c,l]);return[c>0,()=>g(u=>u+1)]}export function TimeMachineFloatingTool({id:l,revealToken:c,dismiss:g}){const{snapshots:u,hasLoaded:y,busy:d}=Be();const D=We();const fe=ie(Je,ae,ae);const M=Ee("timeMachine.snapshots");const _=ie(et,ce,ce);const{width:pe}=ve();const[T,h]=S(null);const[b,$]=S(null);const[L,w]=S();const[ge,F]=S(false);const[ye,be]=me(de);const[Se,Re]=me(de);const[R,G]=S(null);const[C,K]=S(null);const[,xe]=S(0);const x=Ce(true);z(()=>{x.current=true;void Xe();void Ye();void E.ensureLoaded();return()=>{x.current=false}},[]);const i=qe(u,fe);const X=i?.id;const q=i?.lastRestoredAt;const J=i?.createdAt;z(()=>{if(q===void 0&&J===void 0&&!R&&C===null)return;const e=setInterval(()=>xe(n=>n+1),2500);return()=>clearInterval(e)},[q,J,R,C]);z(()=>{if(b&&b.snapshotId!==X){$(null);h(e=>e==="outcome"?null:e)}},[X,b]);const A=Date.now();const Q=R!==null&&A-R.at<H&&u.some(e=>e.id===R.id);const ke=u.filter(e=>!e.safety);const Y=ke.length>=M;const j=!i||d!==null;const N=d!==null;const Z=async(e,n)=>{if(d)return;h(null);w(void 0);try{const f=await E.restore(e,_&&n.safetyCapture?"reload":"live",void 0,n);if(!x.current)return;if(Ke(f)){$(f);h("outcome")}else{$(null);be()}G(f.safetySnapshotId?{id:f.safetySnapshotId,at:Date.now()}:null);if(f.safetySnapshotId)K(null)}catch(f){if(!x.current)return;w(f instanceof Error?f.message:String(f));h("error")}};const ee=(e=false)=>{if(!i)return;void Z(i.id,{safetyCapture:true,...e?{restoreRoute:false}:{}})};const Te=()=>{if(!R)return;void Z(R.id,{safetyCapture:false,restoreRoute:false}).then(()=>{if(x.current)K(Date.now())})};const we=()=>{if(d)return;w(void 0);if(Y){h("cap");return}h(null);F(true)};const Ie=async e=>{F(false);if(d)return;try{const n=await E.capture(e);if(!x.current)return;B(n.id);G(null);Re()}catch(n){if(!x.current)return;w(n instanceof Error?n.message:String(n));h("error")}};const De=e=>{B(e.id);h(null)};const te=i?.name??(y?"No restore points":"Loading\u2026");let m;let O="normal";let re=false;if(d==="restore")m="Restoring\u2026";else if(d==="capture")m="Capturing\u2026";else if(L){m=L;O="danger"}else if(b&&i&&b.snapshotId===i.id){m=rt(b);O="danger"}else if(!i)m=y?"Capture one with +":"";else{re=true;const e=i.lastRestoredAt===void 0?null:A-i.lastRestoredAt;const n=A-i.createdAt;if(C!==null&&A-C<H)m="undone, state only";else if(e!==null&&e<H)m="restored just now";else if(n<H&&e===null)m="captured just now";else if(i.lastRestoredAt!==void 0)m=`restored ${W(i.lastRestoredAt)}`;else m=`${Object.keys(i.sources).length} sources`;if(_)m+=" \xB7 reloads"}const v=re&&!Q&&i&&i.route&&Ve(i)?i.route.pathname:null;const P=u.filter(e=>!e.baseline&&!e.safety);const Le=(()=>{const e=D.filter(oe=>oe.status().canCapture&&Ge(oe.id)).length;const n=Ue();const f=[`${e} source${e===1?"":"s"}`];if(n)f.push(n.pathname);return f.join(" \xB7 ")})();let I;if(T==="picker"){I=a(p,{style:t.menu,testID:"time-machine-bar-picker",children:[a(Ae,{style:t.pickerList,bounces:false,children:[P.map(e=>{const n=e.id===i?.id;return a(k,{testID:`time-machine-bar-pick-${e.id}`,accessibilityRole:"button",accessibilityState:{selected:n},accessibilityLabel:`Arm ${e.name}`,onPress:()=>De(e),style:t.pickRow,children:[a(p,{style:t.pickText,children:[r(s,{numberOfLines:1,style:t.pickName,children:e.name}),a(s,{numberOfLines:1,style:t.pickDetail,children:[W(e.createdAt),e.route?` \xB7 ${e.route.pathname}`:"",e.lastRestoredAt!==void 0?r(s,{style:t.pickRestored,children:` \xB7 restored ${W(e.lastRestoredAt)}`}):null]})]}),n?r(le,{size:14,color:o.color.accent}):null]},e.id)}),P.length===0?r(s,{style:t.menuText,children:"No restore points yet."}):null]}),P.length>V?a(s,{style:t.pickerMore,children:["Scroll for ",P.length-V," more"]}):null,a(p,{style:t.settingRow,testID:"time-machine-bar-reload-mode",children:[a(p,{style:t.settingText,children:[r(s,{style:t.settingLabel,children:"Reload the app after restoring"}),r(s,{style:t.settingHint,children:"For screens that read their state from storage only when they open, like a cart kept in a React context."})]}),r(Me,{value:_,onValueChange:Ze,testID:"time-machine-bar-reload-switch",accessibilityLabel:"Reload the app after restoring"})]})]})}else if(T==="outcome"&&b){I=a(p,{style:t.menu,testID:"time-machine-bar-outcome",children:[ot(b).map(e=>r(s,{style:t.menuDanger,children:e},e)),r(s,{style:t.menuText,children:"The full report is on Time Machine's outcome card."}),r(U,{onPress:()=>h(null)})]})}else if(T==="cap"){I=a(p,{style:t.menu,testID:"time-machine-bar-cap",children:[a(s,{style:t.menuText,children:["Free plan keeps ",M," restore point",M===1?"":"s",". Delete one in Time Machine, or upgrade to Pro for unlimited snapshots."]}),r(U,{onPress:()=>h(null)})]})}else if(T==="error"&&L){I=a(p,{style:t.menu,testID:"time-machine-bar-error",children:[r(s,{accessibilityRole:"alert",style:t.menuDanger,children:L}),r(U,{onPress:()=>{h(null);w(void 0)}})]})}return a(tt,{children:[r(Qe,{visible:ge,summary:Le,onCapture:e=>void Ie(e),onCancel:()=>F(false)}),r(He,{id:l,revealToken:c,variant:"strip",dragFromSurface:true,defaultPlacement:"bottom",accessibilityLabel:`Move or hide the action bar. ${i?`${i.name} armed`:"Nothing armed"}`,accessory:I,handleAdornment:r($e,{size:12,color:o.color.accent}),children:a(p,{style:[t.row,{width:Math.max(260,Math.min(320,pe-64))}],children:[r(k,{testID:"time-machine-bar-restore",accessibilityRole:"button",accessibilityLabel:i?`Restore ${i.name}`:"Restore, nothing armed",accessibilityHint:v?`Also returns to ${v}. Long press to restore state only.`:void 0,accessibilityState:{disabled:j},disabled:j,onPress:()=>ee(false),onLongPress:()=>ee(true),style:[t.restoreButton,j&&t.disabled],children:d==="restore"?r(ne,{size:"small",color:o.color.accent}):ye?r(s,{style:t.restoreText,testID:"time-machine-bar-restored",children:"Restored"}):r(s,{style:t.restoreText,children:"Restore"})}),a(p,{style:t.identity,children:[r(s,{testID:"time-machine-bar-name",accessibilityLabel:`Armed restore point: ${te}`,numberOfLines:1,ellipsizeMode:"middle",style:t.name,children:te}),a(p,{style:t.statusRow,children:[a(s,{testID:"time-machine-bar-status",numberOfLines:1,accessibilityLiveRegion:"polite",style:[t.status,O==="danger"&&t.danger],children:[m,v?r(s,{style:t.destination,children:` \xB7 \u2192 ${v}`}):null]}),Q&&!d?r(k,{testID:"time-machine-bar-undo",accessibilityRole:"button",accessibilityLabel:"Undo the last restore",onPress:Te,hitSlop:{top:8,bottom:8,left:6,right:6},children:r(s,{style:t.undo,children:"Undo"})}):null]})]}),r(k,{testID:"time-machine-bar-pick",accessibilityRole:"button",accessibilityLabel:"Choose another restore point",accessibilityState:{expanded:T==="picker"},onPress:()=>h(e=>e==="picker"?null:"picker"),style:t.smallButton,children:T==="picker"?r(ze,{size:14,color:o.color.textSecondary}):r(Pe,{size:14,color:o.color.textSecondary})}),r(k,{testID:"time-machine-bar-capture",accessibilityRole:"button",accessibilityLabel:"Capture a new restore point here and arm it",accessibilityState:{disabled:N},disabled:N,onPress:we,style:[t.smallButton,N&&t.disabled],children:d==="capture"?r(ne,{size:"small",color:o.color.accent}):Se?r(p,{testID:"time-machine-bar-captured",children:r(le,{size:18,color:o.color.accent})}):r(_e,{size:18,color:Y?o.color.textTertiary:o.color.text})}),r(p,{style:t.separator}),r(k,{testID:"time-machine-bar-close",accessibilityRole:"button",accessibilityLabel:"Close the action bar",onPress:g,style:t.closeButton,children:r(Fe,{size:16,color:o.color.textSecondary})})]})})]})}function U({onPress:l,label:c="Dismiss"}){return r(k,{testID:"time-machine-bar-dismiss",accessibilityRole:"button",onPress:l,style:t.dismiss,children:r(s,{style:t.dismissText,children:c})})}const t=se.create({row:{flexDirection:"row",alignItems:"center",gap:4,paddingVertical:4,minHeight:48},restoreButton:{height:32,minWidth:72,paddingHorizontal:12,borderRadius:8,borderWidth:1,borderColor:o.color.accentBorderStrong,backgroundColor:o.color.accentSoft,alignItems:"center",justifyContent:"center",marginLeft:2},restoreText:{color:o.color.accent,fontSize:12,fontWeight:"700"},smallButton:{width:32,minHeight:44,alignItems:"center",justifyContent:"center"},closeButton:{width:28,minHeight:44,alignItems:"center",justifyContent:"center"},identity:{flex:1,minHeight:44,justifyContent:"center",gap:1},name:{color:o.color.text,fontSize:13,fontWeight:"500"},statusRow:{flexDirection:"row",alignItems:"center",gap:8},status:{color:o.color.textSecondary,fontSize:10,lineHeight:14,flexShrink:1},destination:{color:o.color.textTertiary},danger:{color:o.color.danger},undo:{color:o.color.accent,fontSize:10,lineHeight:14,fontWeight:"700"},separator:{height:20,width:1,backgroundColor:o.color.separator,marginHorizontal:2},disabled:{opacity:.4},menu:{marginVertical:8,padding:6,borderRadius:o.radius.card,borderWidth:1,borderColor:o.color.separator,backgroundColor:o.color.surface,shadowColor:"#000",shadowOffset:{width:0,height:6},shadowOpacity:.25,shadowRadius:16,elevation:8},menuText:{color:o.color.textSecondary,fontSize:12,lineHeight:18,padding:10},menuDanger:{color:o.color.danger,fontSize:12,lineHeight:18,paddingHorizontal:10,paddingTop:6},pickerList:{maxHeight:V*44},pickerMore:{color:o.color.textTertiary,fontSize:10,lineHeight:14,textAlign:"center",paddingVertical:4},pickRow:{flexDirection:"row",alignItems:"center",gap:8,minHeight:44,paddingHorizontal:10,borderRadius:o.radius.row},pickText:{flex:1},settingRow:{flexDirection:"row",alignItems:"center",gap:10,paddingHorizontal:10,paddingVertical:8,borderTopWidth:se.hairlineWidth,borderTopColor:o.color.separator,marginTop:4},settingText:{flex:1,gap:2},settingLabel:{color:o.color.text,fontSize:12,fontWeight:"500"},settingHint:{color:o.color.textTertiary,fontSize:10,lineHeight:13},pickName:{color:o.color.text,fontSize:13,fontWeight:"500"},pickDetail:{color:o.color.textSecondary,fontSize:10,lineHeight:14},pickRestored:{color:o.color.accent},dismiss:{alignSelf:"flex-end",paddingHorizontal:10,paddingVertical:8},dismissText:{color:o.color.accent,fontSize:12,fontWeight:"600"}});
package/lib/web/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- "use client";var fr=Object.defineProperty;var Oo=Object.getOwnPropertyDescriptor;var Ho=Object.getOwnPropertyNames;var Bo=Object.prototype.hasOwnProperty;var Wo=(e,t)=>{for(var r in t)fr(e,r,{get:t[r],enumerable:true})},gr=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ho(t))!Bo.call(e,n)&&n!==r&&fr(e,n,{get:()=>t[n],enumerable:!(i=Oo(t,n))||i.enumerable});return e},jo=(e,t,r)=>(gr(e,t,"default"),r&&gr(r,t,"default"));var yr=(()=>{try{let e=globalThis.Capacitor;if(e&&typeof e.isNativePlatform=="function"&&e.isNativePlatform())return e.DEBUG===true}catch{}return process.env.NODE_ENV!=="production"})();typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);import{getSafeCurrentRoute as No,getSafeRouter as br,persistentStorage as Tt}from"@buoy-gg/shared-ui/web";var Ct="@react_buoy_time_machine:pending-route",Mo=6e4,Vo=8e3,Fo=250;function Ko(e){return{pathname:e.pathname,href:e.href}}function nt(){let e=No();return e?Ko(e):null}function _o(){return nt()}function Oe(){return br()!=null}function zt(e){let t={pathname:e.pathname,href:e.href},r=br();if(!r?.navigate)return{...t,status:"unavailable",error:"expo-router is not available on this device"};try{return r.navigate(e.href),{...t,status:"navigated"}}catch(i){return{...t,status:"failed",error:String(i)}}}async function qo(e,t){let r={...e,savedAt:Date.now(),...t?{snapshotName:t}:{}};await Tt.setItem(Ct,JSON.stringify(r))}async function Jo(){try{await Tt.removeItem(Ct)}catch{}}async function Uo(){try{let e=await Tt.getItem(Ct);if(!e)return null;let t=JSON.parse(e);return typeof t?.href!="string"||!t.href||typeof t.savedAt!="number"?null:{pathname:typeof t.pathname=="string"?t.pathname:t.href,href:t.href,savedAt:t.savedAt,snapshotName:typeof t.snapshotName=="string"?t.snapshotName:void 0}}catch{return null}}var wr=false;function vr(){wr||(wr=true,(async()=>{let e=await Uo();if(!e||(await Jo(),Date.now()-e.savedAt>Mo))return;let t=Date.now()+Vo;for(;!Oe()&&Date.now()<t;)await new Promise(r=>setTimeout(r,100));Oe()&&(await new Promise(r=>setTimeout(r,Fo)),zt({pathname:e.pathname,href:e.href}))})())}var Sr={};Wo(Sr,{AccessibilityInfo:()=>Qo,ActivityIndicator:()=>st,Alert:()=>Lr,Animated:()=>He,AppRegistry:()=>en,AppState:()=>tn,Appearance:()=>Zo,BackHandler:()=>rn,Button:()=>_n,CheckBox:()=>yn,Clipboard:()=>on,DeviceEventEmitter:()=>Ln,Dimensions:()=>nn,Easing:()=>an,FlatList:()=>Ir,I18nManager:()=>sn,Image:()=>bn,ImageBackground:()=>wn,InteractionManager:()=>cn,Keyboard:()=>ln,KeyboardAvoidingView:()=>Rr,LayoutAnimation:()=>dn,Linking:()=>un,LogBox:()=>$n,Modal:()=>$r,NativeEventEmitter:()=>pn,NativeModules:()=>Xo,PanResponder:()=>xr,Picker:()=>vn,PixelRatio:()=>hn,Platform:()=>it,Pressable:()=>Lt,ProgressBar:()=>Sn,RefreshControl:()=>xn,SafeAreaView:()=>In,ScrollView:()=>Pt,SectionList:()=>Rn,Share:()=>mn,StatusBar:()=>kn,StyleSheet:()=>A,Switch:()=>Kn,Text:()=>d,TextInput:()=>at,Touchable:()=>Dn,TouchableHighlight:()=>Vn,TouchableNativeFeedback:()=>Tn,TouchableOpacity:()=>P,TouchableWithoutFeedback:()=>Fn,UIManager:()=>fn,Vibration:()=>gn,View:()=>u,VirtualizedList:()=>Cn,YellowBox:()=>zn,findNodeHandle:()=>qn,unstable_createElement:()=>Go,useColorScheme:()=>Pn,useLocaleContext:()=>En,useWindowDimensions:()=>kr});jo(Sr,Yo);import*as Yo from"react-native-web";import{unstable_createElement as Go,NativeModules as Xo,AccessibilityInfo as Qo,Animated as He,Appearance as Zo,AppRegistry as en,AppState as tn,BackHandler as rn,Clipboard as on,Dimensions as nn,Easing as an,I18nManager as sn,Keyboard as ln,InteractionManager as cn,LayoutAnimation as dn,Linking as un,NativeEventEmitter as pn,PanResponder as xr,PixelRatio as hn,Platform as it,Share as mn,StyleSheet as A,UIManager as fn,Vibration as gn,CheckBox as yn,FlatList as Ir,Image as bn,ImageBackground as wn,KeyboardAvoidingView as Rr,Picker as vn,ProgressBar as Sn,RefreshControl as xn,SafeAreaView as In,SectionList as Rn,StatusBar as kn,Touchable as Dn,TouchableNativeFeedback as Tn,VirtualizedList as Cn,YellowBox as zn,LogBox as $n,DeviceEventEmitter as Ln,useColorScheme as Pn,useLocaleContext as En,useWindowDimensions as kr}from"react-native-web";import*as J from"react-native-web";import{createElement as $t,forwardRef as Dr,useCallback as An,useRef as On}from"react";import{useEffect as Hn,useState as Bn}from"react";import{createPortal as Wn}from"react-dom";var jn='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';import{jsx as Nn}from"react/jsx-runtime";var Be=Symbol.for("@buoy-gg/portal-host"),Tr=e=>{if(!(e instanceof Element))return false;if(e.closest("input, textarea, select"))return true;let t=e.closest("[contenteditable]")?.getAttribute("contenteditable")?.toLowerCase();return t===""||t==="true"||t==="plaintext-only"};function Cr(){let e=document;if(e[Be])return e[Be].host;let t=document.createElement("div");t.dataset.buoyPortalHost="",Object.assign(t.style,{position:"fixed",inset:"0",zIndex:"2147483647",pointerEvents:"none",fontFamily:jn});let r=()=>{let c=document.fullscreenElement,I=c&&c.tagName!=="CANVAS"?c:document.body;t.parentElement!==I&&I.appendChild(t)},i=new Map,n=c=>{(!t.contains(c.target)||!Tr(c.target))&&i.set(c.code||c.key,{key:c.key,code:c.code,location:c.location,keyCode:c.keyCode,which:c.which,altKey:c.altKey,ctrlKey:c.ctrlKey,metaKey:c.metaKey,shiftKey:c.shiftKey})},a=c=>{i.delete(c.code||c.key)},s=()=>i.clear(),h=()=>{let c=[...i.values()];i.clear();for(let I of c)document.dispatchEvent(new KeyboardEvent("keyup",{...I,bubbles:true}))},p=c=>{Tr(c.target)&&c.stopPropagation()},y=c=>c.stopPropagation();return r(),document.addEventListener("fullscreenchange",r),document.addEventListener("keydown",n,true),document.addEventListener("keyup",a,true),window.addEventListener("blur",s),t.addEventListener("focusin",h),t.addEventListener("keydown",p),t.addEventListener("keyup",p),t.addEventListener("keypress",p),t.addEventListener("wheel",y,{passive:true}),e[Be]={host:t,users:0,dispose:()=>{document.removeEventListener("fullscreenchange",r),document.removeEventListener("keydown",n,true),document.removeEventListener("keyup",a,true),window.removeEventListener("blur",s),t.remove(),delete e[Be]}},t}function Mn({children:e}){let[t,r]=Bn(null);return Hn(()=>{let i=Cr(),n=document[Be];return n.users++,r(i),()=>{--n.users===0&&n.dispose()}},[]),t?Wn(Nn("div",{"data-buoy-root":"",style:{display:"contents",pointerEvents:"auto"},children:e}),t):null}function Q(e){let t=Dr((i,n)=>{let{accessibilityState:a,accessibilityValue:s,...h}=i;for(let p of["busy","checked","disabled","expanded","selected"])a?.[p]!==void 0&&h[`aria-${p}`]===void 0&&(h[`aria-${p}`]=a[p]);for(let[p,y]of Object.entries({min:"valuemin",max:"valuemax",now:"valuenow",text:"valuetext"}))s?.[p]!==void 0&&h[`aria-${y}`]===void 0&&(h[`aria-${y}`]=s[p]);return $t(e,{...h,ref:n})}),r=e.State;return r&&Object.assign(t,{State:r}),t.displayName=e.displayName??e.name??"NativeWebView",t}var u=Q(J.View),d=Q(J.Text),at=Q(J.TextInput),P=Q(J.TouchableOpacity),Vn=Q(J.TouchableHighlight),Fn=Q(J.TouchableWithoutFeedback),Lt=Q(J.Pressable),Pt=Q(J.ScrollView),zr=Dr((e,t)=>{let r=On(null),i=An(n=>{if(n){let a=n;for(;a.parentElement&&a.parentElement!==document.body;)a=a.parentElement;a.parentElement===document.body&&(r.current=a,Object.assign(a.style,{position:"relative",zIndex:"2147483647",pointerEvents:"auto"}),Cr().appendChild(a))}else r.current&&(document.body.appendChild(r.current),r.current=null);typeof t=="function"?t(n):t&&(t.current=n)},[t]);return $t(Mn,null,$t(J.Modal,{...e,ref:i}))});zr.displayName="Modal";var $r=Q(zr),Kn=Q(J.Switch),st=Q(J.ActivityIndicator),_n=Q(J.Button),qn=J.findNodeHandle,Lr={alert(e,t,r,i){if(typeof document>"u")return;let n=document.createElement("dialog");n.dataset.buoyRoot="",n.setAttribute("aria-label",e),n.style.cssText="position:fixed;inset:0;margin:auto;width:min(440px,90vw);padding:24px;border:1px solid #475569;border-radius:14px;background:#17212e;color:#f1f5f9;font:14px system-ui;box-shadow:0 20px 80px #0008;z-index:2147483647";let a=document.createElement("h2");if(a.textContent=e,a.style.cssText="font-size:18px;margin:0 0 12px",n.appendChild(a),t){let y=document.createElement("p");y.textContent=t,y.style.cssText="line-height:1.5;white-space:pre-wrap;margin:0 0 20px",n.appendChild(y)}let s=document.createElement("div");s.style.cssText="display:flex;justify-content:flex-end;flex-wrap:wrap;gap:8px";let h=r?.length?r:[{text:"OK"}],p=()=>{n.close?.(),n.remove()};for(let y of h){let c=document.createElement("button");c.type="button",c.textContent=y.text??"OK",c.style.cssText=`padding:9px 14px;border:1px solid #64748b;border-radius:7px;color:white;background:${y.style==="destructive"?"#a52b38":"#283a4d"};cursor:pointer;font:inherit`,c.onclick=()=>{p(),y.onPress?.()},s.appendChild(c)}n.addEventListener("cancel",y=>{y.preventDefault(),i?.cancelable!==false&&(p(),i?.onDismiss?.())}),n.appendChild(s),document.body.appendChild(n),n.showModal?n.showModal():n.setAttribute("open","")}};import{TimeMachineIcon as Jn,TIME_MACHINE_ICON_COLOR as Un}from"@buoy-gg/shared-ui/web";import{useRef as Yn,useState as Pr,useSyncExternalStore as Er}from"react";import{useSafeAreaInsets as Gn,useLimit as Xn,ToolEmptyState as Qn,getFloatingTools as Zn,subscribeFloatingTools as ei}from"@buoy-gg/shared-ui/web";import{useToolHost as ti}from"@buoy-gg/core/web";import{useEffect as ri,useState as oi,useSyncExternalStore as ni}from"react";import{getStateSnapshotProviders as Et,subscribeToStateSnapshotProviders as ii}from"@buoy-gg/shared-ui/web";import{getStateSnapshotProvider as Ar,getStateSnapshotProviders as lt,scheduleReloadApp as ai,superJsonDeserialize as At,superJsonSerialize as si}from"@buoy-gg/shared-ui/web";import{objectDiff as li}from"@buoy-gg/shared-ui/web/dataViewer";import{persistentStorage as me}from"@buoy-gg/shared-ui/web";var Ot="@react_buoy_time_machine:index",We="@react_buoy_time_machine:snap:";async function ci(){try{let e=await me.getItem(Ot);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}async function Ht(e){await me.setItem(Ot,JSON.stringify(e))}async function ct(e,t){let r=JSON.stringify(e);e.meta.sizeBytes=r.length,await me.setItem(We+e.meta.id,JSON.stringify(e));let i=[e.meta,...t.filter(n=>n.id!==e.meta.id)];return await Ht(i),i}async function fe(e){try{let t=await me.getItem(We+e);return t?JSON.parse(t):null}catch{return null}}async function Or(e,t){await me.removeItem(We+e);let r=t.filter(i=>i.id!==e);return await Ht(r),r}async function dt(e,t,r){let i=s=>s.id===e?t(s):s,n=r.map(i);await me.setItem(Ot,JSON.stringify(n));let a=await fe(e);return a&&(a.meta=i(a.meta),await me.setItem(We+e,JSON.stringify(a))),n}function di(e,t,r){return dt(e,i=>{let n={...i};return t&&t.length>0?n.scope=t:delete n.scope,n},r)}function ui(e,t,r){return dt(e,i=>{let n={...i};return delete n.scope,t&&t.length>0?n.excludedKeys=t:delete n.excludedKeys,n},r)}function pi(e,t,r){return dt(e,i=>({...i,restoreRoute:t}),r)}function Hr(e,t,r){return dt(e,i=>({...i,lastRestoredAt:t}),r)}async function hi(e,t,r){let i=await fe(e);if(!i)return null;let n={meta:{...i.meta,id:`${i.meta.id}_copy_${Date.now().toString(36)}`,name:t,createdAt:Date.now(),lastRestoredAt:void 0},data:i.data};return delete n.meta.lastRestoredAt,{metas:await ct(n,r),meta:n.meta}}async function mi(e){return fe(e)}async function fi(e,t){return ct(e,t)}async function gi(e,t,r){let i=r.map(a=>a.id===e?{...a,name:t}:a);await Ht(i);let n=await fe(e);return n&&(n.meta.name=t,await me.setItem(We+e,JSON.stringify(n))),i}import{definePersistedSetting as yi,devToolsStorageKeys as bi}from"@buoy-gg/shared-ui/web";var Br=yi(bi.timeMachine.disabledSources(),[],{sanitize:e=>Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}),xe=new Set,Wr=false,Bt=null,Wt=new Set,jr=()=>Wt.forEach(e=>e());function ae(){return Wr?Promise.resolve():(Bt||(Bt=Br.load().then(e=>{xe.size===0&&(xe=new Set(e),jr())}).finally(()=>{Wr=true})),Bt)}function Nr(e){return Wt.add(e),()=>{Wt.delete(e)}}function Mr(){return xe}function se(e){return!xe.has(e)}function Vr(e,t){if(t===!xe.has(e))return;let r=new Set(xe);t?r.delete(e):r.add(e),xe=r,jr(),Br.save([...r])}var je="route";var Ne=["storage","redux","zustand","jotai","query"];function wi(e){let t=new Date,r=`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`,i=e?e.pathname==="/"?"Home":e.pathname:null;return i?`${i} \xB7 ${r}`:`Snapshot \xB7 ${r}`}function vi(e,t){let r=new Set(t.map(i=>i.name));if(!r.has(e))return e;for(let i=2;i<1e3;i++){let n=`${e} (${i})`;if(!r.has(n))return n}return e}function ut(e){return!!e.route&&(e.restoreRoute??true)}var jt="Before last restore",E=null;function Me(e){return{ok:false,applied:0,skipped:[{id:"*",reason:e}],warnings:[]}}var Fr=0;function Kr(){return Fr+=1,`snap_${Date.now().toString(36)}_${Fr.toString(36)}`}var Si=class{constructor(){this.state={snapshots:[],hasLoaded:false,busy:null,lastOutcome:null,preview:null,remoteProviders:null,remoteRoute:null,recentlyDeleted:null};this.previewRunId=0;this.listeners=new Set;this.loadPromise=null;this.subscribe=e=>(this.listeners.add(e),this.ensureLoaded(),()=>{this.listeners.delete(e)})}getState(){return this.state}setState(e){this.state={...this.state,...e},this.listeners.forEach(t=>{try{t()}catch{}})}ensureLoaded(){return E?Promise.resolve():(this.loadPromise||(this.loadPromise=ci().then(e=>{E||this.setState({snapshots:e,hasLoaded:true})})),this.loadPromise)}replaceFromSnapshot(e){this.setState({snapshots:e.snapshots??[],busy:e.busy??null,lastOutcome:e.lastOutcome??null,remoteProviders:e.providers??[],remoteRoute:e.route??{available:false},hasLoaded:true})}async capture(e,t,r){if(E)return(await E("capture",{name:e,sourceIds:t})).snapshot;await this.ensureLoaded(),await ae(),this.setState({busy:"capture"});try{let i=lt().filter(c=>c.status().canCapture&&se(c.id)&&(!t||t.includes(c.id))),n={},a={};for(let c of i)try{let I=await c.capture();n[c.id]=si(I.data),a[c.id]={warnings:I.warnings}}catch(I){a[c.id]={warnings:[`capture failed: ${String(I)}`]}}let s=se(je)?nt():null,h=this.state.snapshots;if(r?.safety)for(let c of h.filter(I=>I.safety))h=await Or(c.id,h);let p={meta:{id:Kr(),name:r?.safety?jt:vi(e.trim()||wi(s),h),createdAt:Date.now(),sizeBytes:0,...s?{route:s}:{},...r?.safety?{safety:true}:{},sources:a},data:n},y=await ct(p,h);return this.setState({snapshots:y}),p.meta}finally{this.setState({busy:null})}}async captureBaseline(){if(E)return(await E("captureBaseline",{})).snapshot;await this.ensureLoaded(),await ae();let e={meta:{id:Kr(),name:"Fresh install",createdAt:Date.now(),sizeBytes:0,baseline:true,sources:{}},data:{}},t=await ct(e,this.state.snapshots);return this.setState({snapshots:t}),e.meta}async restore(e,t,r,i){if(E){let a=await E("restore",{id:e,mode:t,excludeKeys:r,restoreRoute:i?.restoreRoute});return this.setState({lastOutcome:a}),a}await this.ensureLoaded(),await ae();let n;i?.safetyCapture&&!this.state.snapshots.find(a=>a.id===e)?.safety&&(n=(await this.capture(jt,void 0,{safety:true})).id),this.setState({busy:"restore"});try{let a=await fe(e);if(!a)throw new Error(`No snapshot with id "${e}"`);let s={snapshotId:e,snapshotName:a.meta.name,mode:t,at:Date.now(),willReload:false,results:{},...n?{safetySnapshotId:n}:{}};if(a.meta.baseline){for(let b of lt())if(b.clear)try{s.results[b.id]=await b.clear()}catch(O){s.results[b.id]=Me(String(O))}return s.willReload=this.scheduleReload("buoy time-machine baseline"),this.setState({lastOutcome:s}),s}let h=[...Ne.filter(b=>b in a.data),...Object.keys(a.data).filter(b=>!Ne.includes(b))],p=b=>{let O=new Map;for(let W of b){let j=W.indexOf("::");if(j<=0)continue;let w=W.slice(0,j),U=W.slice(j+2),ee=O.get(w)??[];ee.push(U),O.set(w,ee)}return O},y=r??a.meta.excludedKeys??[],c=p(y),I=!r&&a.meta.scope?.length?p(a.meta.scope):null,L=se(je)&&(i?.restoreRoute??ut(a.meta));if(t==="reload"){if(a.data.storage&&se("storage")&&(!I||I.has("storage"))&&(s.results.storage=await this.restoreSource("storage",a.data.storage,c.get("storage"),I?.get("storage"))),L){let b=a.meta.route;try{await qo(b,a.meta.name),s.route={...b,status:"deferred"}}catch(O){s.route={...b,status:"failed",error:String(O)}}}return s.willReload=this.scheduleReload("buoy time-machine restore"),this.setState({lastOutcome:s,snapshots:await Hr(e,s.at,this.state.snapshots)}),s}for(let b of h)if(!(I&&!I.has(b))){if(!se(b)){s.results[b]={ok:true,applied:0,skipped:[],warnings:["Switched off in Sources; left as it is"]};continue}s.results[b]=await this.restoreSource(b,a.data[b],c.get(b),I?.get(b))}return L&&(s.route=zt(a.meta.route)),this.setState({lastOutcome:s,snapshots:await Hr(e,s.at,this.state.snapshots)}),s}finally{this.setState({busy:null})}}async restoreSource(e,t,r,i){let n=Ar(e);if(!n)return Me("provider not available (package missing or not initialized)");let a=n.status();if(!a.canRestore)return Me(a.detail??"restore unavailable");try{let s=r?.length||i?.length?{...r?.length?{excludeKeys:r}:{},...i?.length?{includeKeys:i}:{}}:void 0;return await n.restore(At(t),s)}catch(s){return Me(String(s))}}scheduleReload(e){try{return ai({reason:e}),true}catch{return false}}async delete(e){if(E){await E("delete",{id:e});return}await this.ensureLoaded(),await ae();let t=await mi(e),r=await Or(e,this.state.snapshots);this.setState({snapshots:r,recentlyDeleted:t?{stored:t,at:Date.now()}:null})}async undoDelete(){let e=this.state.recentlyDeleted;if(!e)return;let t=await fi(e.stored,this.state.snapshots);this.setState({snapshots:t,recentlyDeleted:null})}clearRecentlyDeleted(){this.state.recentlyDeleted&&this.setState({recentlyDeleted:null})}async setRestoreRoute(e,t){if(E){await E("setRestoreRoute",{id:e,restoreRoute:t});return}await this.ensureLoaded(),await ae();let r=await pi(e,t,this.state.snapshots);this.setState({snapshots:r})}async duplicate(e){if(E)return(await E("duplicate",{id:e}))?.snapshot??null;await this.ensureLoaded(),await ae();let t=this.state.snapshots.find(i=>i.id===e);if(!t)return null;let r=await hi(e,`${t.name} copy`,this.state.snapshots);return r?(this.setState({snapshots:r.metas}),r.meta):null}async rename(e,t){if(E){await E("rename",{id:e,name:t});return}await this.ensureLoaded(),await ae();let r=await gi(e,t,this.state.snapshots);this.setState({snapshots:r})}async setScope(e,t){if(E){await E("setScope",{id:e,scope:t});return}await this.ensureLoaded(),await ae();let r=await di(e,t,this.state.snapshots);this.setState({snapshots:r})}async setExclusions(e,t){if(E){await E("setExclusions",{id:e,excludedKeys:t});return}await this.ensureLoaded(),await ae();let r=await ui(e,t,this.state.snapshots);this.setState({snapshots:r})}clearLastOutcome(){this.setState({lastOutcome:null})}async wipeAll(){if(E){let e=await E("wipeAll",{});return this.setState({lastOutcome:e}),e}this.setState({busy:"restore"});try{let e={snapshotId:"wipe-all",snapshotName:"Wipe all",mode:"reload",at:Date.now(),willReload:false,results:{}};for(let t of lt())if(t.clear)try{e.results[t.id]=await t.clear()}catch(r){e.results[t.id]=Me(String(r))}return e.willReload=this.scheduleReload("buoy time-machine wipe all"),this.setState({lastOutcome:e}),e}finally{this.setState({busy:null})}}clearPreview(){this.previewRunId+=1,this.setState({preview:null})}async buildPreview(e,t="current"){if(E){let n=++this.previewRunId;this.setState({preview:{left:t,right:e,building:true,builtAt:Date.now(),sources:[]}});try{let a=await E("preview",{id:e==="current"?void 0:e.snapshotId,compareTo:t==="current"?void 0:t.snapshotId});if(n!==this.previewRunId)return;this.setState({preview:{left:t,right:e,building:false,builtAt:Date.now(),sources:a.sources??[]}})}catch(a){if(n!==this.previewRunId)return;this.setState({preview:{left:t,right:e,building:false,builtAt:Date.now(),sources:[{id:"error",label:"Preview",items:[],notes:[],error:String(a)}]}})}return}await this.ensureLoaded(),await ae();let r=++this.previewRunId;this.setState({preview:{left:t,right:e,building:true,builtAt:Date.now(),sources:[]}});let i=async n=>{if(n==="current")return null;let a=await fe(n.snapshotId);if(!a)throw new Error(`No snapshot with id "${n.snapshotId}"`);return a.data};try{if(e==="current")throw new Error("preview target must be a snapshot");let[n,a]=await Promise.all([i(t),fe(e.snapshotId)]);if(r!==this.previewRunId)return;if(!a)throw new Error(`No snapshot with id "${e.snapshotId}"`);let s=a.data,h=a.meta.baseline===true,p=h?lt().filter(c=>c.clear).map(c=>c.id):[...Ne.filter(c=>c in s),...Object.keys(s).filter(c=>!Ne.includes(c))],y=[];for(let c of p){if(!se(c))continue;if(await new Promise(b=>setTimeout(b,0)),r!==this.previewRunId)return;let I=Ar(c),L=I?.label??c;try{let b=h?void 0:At(s[c]),O=n===null?void 0:c in n?At(n[c]):void 0,W;if(!I)W={items:[{key:c,label:L,verdict:"wont-apply",reason:"tool not installed \u2014 restore skips this source"}],notes:[]};else if(I.previewItems)W=await I.previewItems(b,O);else{let j=li(O,b);W={items:[{key:c,label:L,verdict:j.equal?"unchanged":"changed",oldValue:O,newValue:b}],notes:j.truncated?["diff truncated (large value)"]:[]}}if(r!==this.previewRunId)return;y.push({id:c,label:L,...W})}catch(b){y.push({id:c,label:L,items:[],notes:[],error:String(b)})}this.setState({preview:{left:t,right:e,building:true,builtAt:Date.now(),sources:[...y]}})}if(r!==this.previewRunId)return;this.setState({preview:{left:t,right:e,building:false,builtAt:Date.now(),sources:y}})}catch(n){if(r!==this.previewRunId)return;this.setState({preview:{left:t,right:e,building:false,builtAt:Date.now(),sources:[{id:"error",label:"Preview",items:[],notes:[],error:String(n)}]}})}}},S=new Si;function xi(e){E=e,e||S.replaceFromSnapshot({})}function Ii(e){S.replaceFromSnapshot(e)}function pt(){return ni(S.subscribe,()=>S.getState())}function _r(){let[e,t]=oi(Et);return ri(()=>(t(Et()),ii(()=>t(Et()))),[]),e}import{Children as Ri}from"react";import{ChevronRight as ki}from"@buoy-gg/shared-ui/web";import{night as N}from"@buoy-gg/shared-ui/web";import{monoFont as Di}from"@buoy-gg/shared-ui/web";var Nt="2E",Ti="4D",o={color:{sheet:"rgba(5, 5, 5, 0.92)",group:N.color.glass,groupBorder:N.color.glassBorder,rowPressed:N.color.glassElevated,separator:N.color.separator,fill:N.color.glassElevated,fillStrong:N.color.fillTertiary,ring:N.color.bg,disc:N.color.surfaceElevated,label:N.color.text,labelSecondary:N.color.textSecondary,labelTertiary:N.color.textTertiary,accent:N.color.accent,accentSoft:`${N.color.accent}${Nt}`,accentSoftStrong:`${N.color.accent}${Ti}`,onAccent:"#0A0A0A",warning:N.color.warning,warningSoft:`${N.color.warning}${Nt}`,danger:N.color.danger,dangerSoft:`${N.color.danger}${Nt}`,onDanger:"#FFFFFF",info:N.color.info},radius:{group:14,pill:99},gutter:14,textInset:16,separatorInset:16,font:{row:17,control:15,footnote:13,mono:12},tracking:{row:-.43,control:-.2},rowMinHeight:52},ht=Di;import{jsx as Ie,jsxs as Ci}from"react/jsx-runtime";function mt({children:e,testID:t}){return Ie(d,{style:ge.sectionLabel,testID:t,children:e})}function Ve({children:e,centered:t,tone:r="secondary",testID:i}){return Ie(d,{style:[ge.footnote,t?ge.footnoteCentered:null,r==="warning"?ge.footnoteWarning:null],testID:i,children:e})}function ft({children:e,style:t}){let r=Ri.toArray(e);return Ie(u,{style:[ge.group,t],children:r.map((i,n)=>Ci(u,{children:[n>0?Ie(u,{style:ge.separator}):null,i]},i.key??n))})}function qr(){return Ie(ki,{size:16,color:o.color.labelTertiary})}function zi({label:e,color:t,background:r,testID:i}){return Ie(u,{style:[ge.pill,{backgroundColor:r}],children:Ie(d,{style:[ge.pillText,{color:t}],testID:i,children:e})})}var ge=A.create({sectionLabel:{color:o.color.labelSecondary,fontSize:o.font.footnote,fontWeight:"500",textTransform:"uppercase",letterSpacing:.4,paddingHorizontal:o.gutter+o.textInset,paddingTop:22,paddingBottom:7},footnote:{color:o.color.labelSecondary,fontSize:o.font.footnote,lineHeight:o.font.footnote*1.35,paddingHorizontal:o.gutter+o.textInset,paddingTop:7},footnoteCentered:{textAlign:"center"},footnoteWarning:{color:o.color.warning},group:{marginHorizontal:o.gutter,backgroundColor:o.color.group,borderRadius:o.radius.group,borderWidth:1,borderColor:o.color.groupBorder,overflow:"hidden"},separator:{height:A.hairlineWidth,marginLeft:o.separatorInset,backgroundColor:o.color.separator},pill:{height:32,paddingHorizontal:15,borderRadius:o.radius.pill,alignItems:"center",justifyContent:"center"},pillText:{fontSize:o.font.control,fontWeight:"600",letterSpacing:o.tracking.control}});import{JotaiIcon as $i,QueryIcon as Li,ReduxIcon as Pi,RoutesIcon as Ei,StorageIcon as Ai,TimeMachineIcon as Oi,ZustandIcon as Hi}from"@buoy-gg/floating-tools-core/web";import{useSyncExternalStore as Bi}from"react";var Wi={storage:Ai,redux:Pi,zustand:Hi,jotai:$i,query:Li,route:Ei};function ji(e){return Wi[e]??Oi}function Ni(){let{remoteProviders:e,remoteRoute:t}=pt(),r=_r(),i=Bi(Nr,Mr,Mr),n=e?e.map(s=>({...s,enabled:s.enabled!==false})):r.map(s=>({id:s.id,label:s.label,...s.status(),enabled:!i.has(s.id)})),a=e?t?.available===true:Oe();return[...n,{id:je,label:"Route",canCapture:a,canRestore:a,enabled:e?t?.enabled!==false:!i.has(je),detail:a?"Recorded with every snapshot \u2014 a restore can take you back":"No Expo Router detected \u2014 snapshots record no route"}]}function Mi(e){let t=globalThis.confirm;return t?t(e):true}function Mt(e,t,r,i){if(it.OS==="web"){Mi(`${e}
1
+ "use client";var br=Object.defineProperty;var Wo=Object.getOwnPropertyDescriptor;var No=Object.getOwnPropertyNames;var Mo=Object.prototype.hasOwnProperty;var Vo=(e,t)=>{for(var r in t)br(e,r,{get:t[r],enumerable:true})},wr=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of No(t))!Mo.call(e,n)&&n!==r&&br(e,n,{get:()=>t[n],enumerable:!(i=Wo(t,n))||i.enumerable});return e},Fo=(e,t,r)=>(wr(e,t,"default"),r&&wr(r,t,"default"));var vr=(()=>{try{let e=globalThis.Capacitor;if(e&&typeof e.isNativePlatform=="function"&&e.isNativePlatform())return e.DEBUG===true}catch{}return process.env.NODE_ENV!=="production"})();typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);import{getSafeCurrentRoute as Ko,getSafeRouter as Sr,persistentStorage as zt}from"@buoy-gg/shared-ui/web";var $t="@react_buoy_time_machine:pending-route",_o=6e4,qo=8e3,Jo=250;function Uo(e){return{pathname:e.pathname,href:e.href}}function at(){let e=Ko();return e?Uo(e):null}function Go(){return at()}function Be(){return Sr()!=null}function Lt(e){let t={pathname:e.pathname,href:e.href},r=Sr();if(!r?.navigate)return{...t,status:"unavailable",error:"expo-router is not available on this device"};try{return r.navigate(e.href),{...t,status:"navigated"}}catch(i){return{...t,status:"failed",error:String(i)}}}async function Yo(e,t){let r={...e,savedAt:Date.now(),...t?{snapshotName:t}:{}};await zt.setItem($t,JSON.stringify(r))}async function Qo(){try{await zt.removeItem($t)}catch{}}async function Xo(){try{let e=await zt.getItem($t);if(!e)return null;let t=JSON.parse(e);return typeof t?.href!="string"||!t.href||typeof t.savedAt!="number"?null:{pathname:typeof t.pathname=="string"?t.pathname:t.href,href:t.href,savedAt:t.savedAt,snapshotName:typeof t.snapshotName=="string"?t.snapshotName:void 0}}catch{return null}}var xr=false;function Ir(){xr||(xr=true,(async()=>{let e=await Xo();if(!e||(await Qo(),Date.now()-e.savedAt>_o))return;let t=Date.now()+qo;for(;!Be()&&Date.now()<t;)await new Promise(r=>setTimeout(r,100));Be()&&(await new Promise(r=>setTimeout(r,Jo)),Lt({pathname:e.pathname,href:e.href}))})())}var Rr={};Vo(Rr,{AccessibilityInfo:()=>rn,ActivityIndicator:()=>ct,Alert:()=>Or,Animated:()=>We,AppRegistry:()=>nn,AppState:()=>an,Appearance:()=>on,BackHandler:()=>sn,Button:()=>Qn,CheckBox:()=>Sn,Clipboard:()=>ln,DeviceEventEmitter:()=>On,Dimensions:()=>cn,Easing:()=>dn,FlatList:()=>Dr,I18nManager:()=>un,Image:()=>xn,ImageBackground:()=>In,InteractionManager:()=>pn,Keyboard:()=>hn,KeyboardAvoidingView:()=>Tr,LayoutAnimation:()=>mn,Linking:()=>fn,LogBox:()=>Pn,Modal:()=>Pr,NativeEventEmitter:()=>gn,NativeModules:()=>tn,PanResponder:()=>kr,Picker:()=>Rn,PixelRatio:()=>yn,Platform:()=>st,Pressable:()=>Pt,ProgressBar:()=>kn,RefreshControl:()=>Dn,SafeAreaView:()=>Tn,ScrollView:()=>Ot,SectionList:()=>Cn,Share:()=>bn,StatusBar:()=>zn,StyleSheet:()=>P,Switch:()=>Yn,Text:()=>d,TextInput:()=>lt,Touchable:()=>$n,TouchableHighlight:()=>Un,TouchableNativeFeedback:()=>Ln,TouchableOpacity:()=>E,TouchableWithoutFeedback:()=>Gn,UIManager:()=>wn,Vibration:()=>vn,View:()=>h,VirtualizedList:()=>En,YellowBox:()=>An,findNodeHandle:()=>Xn,unstable_createElement:()=>en,useColorScheme:()=>Hn,useLocaleContext:()=>Bn,useWindowDimensions:()=>Cr});Fo(Rr,Zo);import*as Zo from"react-native-web";import{unstable_createElement as en,NativeModules as tn,AccessibilityInfo as rn,Appearance as on,AppRegistry as nn,AppState as an,BackHandler as sn,Clipboard as ln,Dimensions as cn,Easing as dn,I18nManager as un,Keyboard as hn,InteractionManager as pn,LayoutAnimation as mn,Linking as fn,NativeEventEmitter as gn,PanResponder as kr,PixelRatio as yn,Platform as st,Share as bn,UIManager as wn,Vibration as vn,CheckBox as Sn,FlatList as Dr,Image as xn,ImageBackground as In,KeyboardAvoidingView as Tr,Picker as Rn,ProgressBar as kn,RefreshControl as Dn,SafeAreaView as Tn,SectionList as Cn,StatusBar as zn,Touchable as $n,TouchableNativeFeedback as Ln,VirtualizedList as En,YellowBox as An,LogBox as Pn,DeviceEventEmitter as On,useColorScheme as Hn,useLocaleContext as Bn,useWindowDimensions as Cr}from"react-native-web";import*as J from"react-native-web";import{createElement as Et,forwardRef as zr,useCallback as jn,useRef as Wn}from"react";import{useEffect as Nn,useState as Mn}from"react";import{createPortal as Vn}from"react-dom";var Fn='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';import{jsx as Kn}from"react/jsx-runtime";var je=Symbol.for("@buoy-gg/portal-host"),$r=e=>{if(!(e instanceof Element))return false;if(e.closest("input, textarea, select"))return true;let t=e.closest("[contenteditable]")?.getAttribute("contenteditable")?.toLowerCase();return t===""||t==="true"||t==="plaintext-only"};function Lr(){let e=document;if(e[je])return e[je].host;let t=document.createElement("div");t.dataset.buoyPortalHost="",Object.assign(t.style,{position:"fixed",inset:"0",zIndex:"2147483647",pointerEvents:"none",fontFamily:Fn});let r=()=>{let l=document.fullscreenElement,p=l&&l.tagName!=="CANVAS"?l:document.body;t.parentElement!==p&&p.appendChild(t)},i=new Map,n=l=>{(!t.contains(l.target)||!$r(l.target))&&i.set(l.code||l.key,{key:l.key,code:l.code,location:l.location,keyCode:l.keyCode,which:l.which,altKey:l.altKey,ctrlKey:l.ctrlKey,metaKey:l.metaKey,shiftKey:l.shiftKey})},a=l=>{i.delete(l.code||l.key)},s=()=>i.clear(),f=()=>{let l=[...i.values()];i.clear();for(let p of l)document.dispatchEvent(new KeyboardEvent("keyup",{...p,bubbles:true}))},u=l=>{$r(l.target)&&l.stopPropagation()},g=l=>l.stopPropagation();return r(),document.addEventListener("fullscreenchange",r),document.addEventListener("keydown",n,true),document.addEventListener("keyup",a,true),window.addEventListener("blur",s),t.addEventListener("focusin",f),t.addEventListener("keydown",u),t.addEventListener("keyup",u),t.addEventListener("keypress",u),t.addEventListener("wheel",g,{passive:true}),e[je]={host:t,users:0,dispose:()=>{document.removeEventListener("fullscreenchange",r),document.removeEventListener("keydown",n,true),document.removeEventListener("keyup",a,true),window.removeEventListener("blur",s),t.remove(),delete e[je]}},t}function _n({children:e}){let[t,r]=Mn(null);return Nn(()=>{let i=Lr(),n=document[je];return n.users++,r(i),()=>{--n.users===0&&n.dispose()}},[]),t?Vn(Kn("div",{"data-buoy-root":"",style:{display:"contents",pointerEvents:"auto"},children:e}),t):null}var $e=J,qn=["shadowColor","shadowOffset","shadowOpacity","shadowRadius","textShadowColor","textShadowOffset","textShadowRadius"],Le=e=>typeof e=="number"?`${e}px`:e;function At(e){if(Array.isArray(e)){let p=e.map(At);return p.some((z,m)=>z!==e[m])?p:e}if(!e||typeof e!="object"||!qn.some(p=>e[p]!=null))return e;let{shadowColor:t,shadowOffset:r,shadowOpacity:i,shadowRadius:n,textShadowColor:a,textShadowOffset:s,textShadowRadius:f,...u}=e;if(t!=null||r!=null||i!=null||n!=null){let p=t??"black",z=i==null?p:`color-mix(in srgb, ${p} ${Math.min(i,1)*100}%, transparent)`,m=`${Le(r?.width??0)} ${Le(r?.height??0)} ${Le(n??0)} ${z}`;u.boxShadow=typeof u.boxShadow=="string"?`${u.boxShadow}, ${m}`:u.boxShadow??m}let{width:g=0,height:l=0}=s??{};if(a&&(g||l||f)){let p=`${Le(g)} ${Le(l)} ${Le(f??0)} ${a}`;u.textShadow=u.textShadow?`${u.textShadow}, ${p}`:p}return u}var Jn=$e.StyleSheet.create({auto:{pointerEvents:"auto"},none:{pointerEvents:"none"},"box-none":{pointerEvents:"box-none"},"box-only":{pointerEvents:"box-only"}});function Er(e,t){if(typeof e=="function")return i=>Er(e(i),t);let r=At(e);return t?[r,Jn[t]]:r}var P={...$e.StyleSheet,create:e=>$e.StyleSheet.create(Object.fromEntries(Object.entries(e).map(([t,r])=>[t,At(r)])))};function X(e){let t=zr((i,n)=>{let{accessibilityState:a,accessibilityValue:s,pointerEvents:f,...u}=i;for(let l of["busy","checked","disabled","expanded","selected"])a?.[l]!==void 0&&u[`aria-${l}`]===void 0&&(u[`aria-${l}`]=a[l]);for(let[l,p]of Object.entries({min:"valuemin",max:"valuemax",now:"valuenow",text:"valuetext"}))s?.[l]!==void 0&&u[`aria-${p}`]===void 0&&(u[`aria-${p}`]=s[l]);let g=Er(u.style,f);return g!==u.style&&(u.style=g),Et(e,{...u,ref:n})}),r=e.State;return r&&Object.assign(t,{State:r}),t.displayName=e.displayName??e.name??"NativeWebView",t}var h=X(J.View),d=X(J.Text),We={...$e.Animated,View:$e.Animated.createAnimatedComponent(h),Text:$e.Animated.createAnimatedComponent(d)},lt=X(J.TextInput),E=X(J.TouchableOpacity),Un=X(J.TouchableHighlight),Gn=X(J.TouchableWithoutFeedback),Pt=X(J.Pressable),Ot=X(J.ScrollView),Ar=zr((e,t)=>{let r=Wn(null),i=jn(n=>{if(n){let a=n;for(;a.parentElement&&a.parentElement!==document.body;)a=a.parentElement;a.parentElement===document.body&&(r.current=a,Object.assign(a.style,{position:"relative",zIndex:"2147483647",pointerEvents:"auto"}),Lr().appendChild(a))}else r.current&&(document.body.appendChild(r.current),r.current=null);typeof t=="function"?t(n):t&&(t.current=n)},[t]);return Et(_n,null,Et(J.Modal,{...e,ref:i}))});Ar.displayName="Modal";var Pr=X(Ar),Yn=X(J.Switch),ct=X(J.ActivityIndicator),Qn=X(J.Button),Xn=J.findNodeHandle,Or={alert(e,t,r,i){if(typeof document>"u")return;let n=document.createElement("dialog");n.dataset.buoyRoot="",n.setAttribute("aria-label",e),n.style.cssText="position:fixed;inset:0;margin:auto;width:min(440px,90vw);padding:24px;border:1px solid #475569;border-radius:14px;background:#17212e;color:#f1f5f9;font:14px system-ui;box-shadow:0 20px 80px #0008;z-index:2147483647";let a=document.createElement("h2");if(a.textContent=e,a.style.cssText="font-size:18px;margin:0 0 12px",n.appendChild(a),t){let g=document.createElement("p");g.textContent=t,g.style.cssText="line-height:1.5;white-space:pre-wrap;margin:0 0 20px",n.appendChild(g)}let s=document.createElement("div");s.style.cssText="display:flex;justify-content:flex-end;flex-wrap:wrap;gap:8px";let f=r?.length?r:[{text:"OK"}],u=()=>{n.close?.(),n.remove()};for(let g of f){let l=document.createElement("button");l.type="button",l.textContent=g.text??"OK",l.style.cssText=`padding:9px 14px;border:1px solid #64748b;border-radius:7px;color:white;background:${g.style==="destructive"?"#a52b38":"#283a4d"};cursor:pointer;font:inherit`,l.onclick=()=>{u(),g.onPress?.()},s.appendChild(l)}n.addEventListener("cancel",g=>{g.preventDefault(),i?.cancelable!==false&&(u(),i?.onDismiss?.())}),n.appendChild(s),document.body.appendChild(n),n.showModal?n.showModal():n.setAttribute("open","")}};import{TimeMachineIcon as Zn,TIME_MACHINE_ICON_COLOR as ei}from"@buoy-gg/shared-ui/web";import{useRef as ti,useState as Hr,useSyncExternalStore as Br}from"react";import{useSafeAreaInsets as ri,useLimit as oi,ToolEmptyState as ni,getFloatingTools as ii,subscribeFloatingTools as ai}from"@buoy-gg/shared-ui/web";import{useToolHost as si}from"@buoy-gg/core/web";import{useEffect as li,useState as ci,useSyncExternalStore as di}from"react";import{getStateSnapshotProviders as Ht,subscribeToStateSnapshotProviders as ui}from"@buoy-gg/shared-ui/web";import{getStateSnapshotProvider as jr,getStateSnapshotProviders as dt,scheduleReloadApp as hi,superJsonDeserialize as Bt,superJsonSerialize as pi}from"@buoy-gg/shared-ui/web";import{objectDiff as mi}from"@buoy-gg/shared-ui/web/dataViewer";import{persistentStorage as me}from"@buoy-gg/shared-ui/web";var jt="@react_buoy_time_machine:index",Ne="@react_buoy_time_machine:snap:";async function fi(){try{let e=await me.getItem(jt);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}async function Wt(e){await me.setItem(jt,JSON.stringify(e))}async function ut(e,t){let r=JSON.stringify(e);e.meta.sizeBytes=r.length,await me.setItem(Ne+e.meta.id,JSON.stringify(e));let i=[e.meta,...t.filter(n=>n.id!==e.meta.id)];return await Wt(i),i}async function fe(e){try{let t=await me.getItem(Ne+e);return t?JSON.parse(t):null}catch{return null}}async function Wr(e,t){await me.removeItem(Ne+e);let r=t.filter(i=>i.id!==e);return await Wt(r),r}async function ht(e,t,r){let i=s=>s.id===e?t(s):s,n=r.map(i);await me.setItem(jt,JSON.stringify(n));let a=await fe(e);return a&&(a.meta=i(a.meta),await me.setItem(Ne+e,JSON.stringify(a))),n}function gi(e,t,r){return ht(e,i=>{let n={...i};return t&&t.length>0?n.scope=t:delete n.scope,n},r)}function yi(e,t,r){return ht(e,i=>{let n={...i};return delete n.scope,t&&t.length>0?n.excludedKeys=t:delete n.excludedKeys,n},r)}function bi(e,t,r){return ht(e,i=>({...i,restoreRoute:t}),r)}function Nr(e,t,r){return ht(e,i=>({...i,lastRestoredAt:t}),r)}async function wi(e,t,r){let i=await fe(e);if(!i)return null;let n={meta:{...i.meta,id:`${i.meta.id}_copy_${Date.now().toString(36)}`,name:t,createdAt:Date.now(),lastRestoredAt:void 0},data:i.data};return delete n.meta.lastRestoredAt,{metas:await ut(n,r),meta:n.meta}}async function vi(e){return fe(e)}async function Si(e,t){return ut(e,t)}async function xi(e,t,r){let i=r.map(a=>a.id===e?{...a,name:t}:a);await Wt(i);let n=await fe(e);return n&&(n.meta.name=t,await me.setItem(Ne+e,JSON.stringify(n))),i}import{definePersistedSetting as Ii,devToolsStorageKeys as Ri}from"@buoy-gg/shared-ui/web";var Mr=Ii(Ri.timeMachine.disabledSources(),[],{sanitize:e=>Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}),xe=new Set,Vr=false,Nt=null,Mt=new Set,Fr=()=>Mt.forEach(e=>e());function ae(){return Vr?Promise.resolve():(Nt||(Nt=Mr.load().then(e=>{xe.size===0&&(xe=new Set(e),Fr())}).finally(()=>{Vr=true})),Nt)}function Kr(e){return Mt.add(e),()=>{Mt.delete(e)}}function _r(){return xe}function se(e){return!xe.has(e)}function qr(e,t){if(t===!xe.has(e))return;let r=new Set(xe);t?r.delete(e):r.add(e),xe=r,Fr(),Mr.save([...r])}var Me="route";var Ve=["storage","redux","zustand","jotai","query"];function ki(e){let t=new Date,r=`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`,i=e?e.pathname==="/"?"Home":e.pathname:null;return i?`${i} \xB7 ${r}`:`Snapshot \xB7 ${r}`}function Di(e,t){let r=new Set(t.map(i=>i.name));if(!r.has(e))return e;for(let i=2;i<1e3;i++){let n=`${e} (${i})`;if(!r.has(n))return n}return e}function pt(e){return!!e.route&&(e.restoreRoute??true)}var Vt="Before last restore",A=null;function Fe(e){return{ok:false,applied:0,skipped:[{id:"*",reason:e}],warnings:[]}}var Jr=0;function Ur(){return Jr+=1,`snap_${Date.now().toString(36)}_${Jr.toString(36)}`}var Ti=class{constructor(){this.state={snapshots:[],hasLoaded:false,busy:null,lastOutcome:null,preview:null,remoteProviders:null,remoteRoute:null,recentlyDeleted:null};this.previewRunId=0;this.listeners=new Set;this.loadPromise=null;this.subscribe=e=>(this.listeners.add(e),this.ensureLoaded(),()=>{this.listeners.delete(e)})}getState(){return this.state}setState(e){this.state={...this.state,...e},this.listeners.forEach(t=>{try{t()}catch{}})}ensureLoaded(){return A?Promise.resolve():(this.loadPromise||(this.loadPromise=fi().then(e=>{A||this.setState({snapshots:e,hasLoaded:true})})),this.loadPromise)}replaceFromSnapshot(e){this.setState({snapshots:e.snapshots??[],busy:e.busy??null,lastOutcome:e.lastOutcome??null,remoteProviders:e.providers??[],remoteRoute:e.route??{available:false},hasLoaded:true})}async capture(e,t,r){if(A)return(await A("capture",{name:e,sourceIds:t})).snapshot;await this.ensureLoaded(),await ae(),this.setState({busy:"capture"});try{let i=dt().filter(l=>l.status().canCapture&&se(l.id)&&(!t||t.includes(l.id))),n={},a={};for(let l of i)try{let p=await l.capture();n[l.id]=pi(p.data),a[l.id]={warnings:p.warnings}}catch(p){a[l.id]={warnings:[`capture failed: ${String(p)}`]}}let s=se(Me)?at():null,f=this.state.snapshots;if(r?.safety)for(let l of f.filter(p=>p.safety))f=await Wr(l.id,f);let u={meta:{id:Ur(),name:r?.safety?Vt:Di(e.trim()||ki(s),f),createdAt:Date.now(),sizeBytes:0,...s?{route:s}:{},...r?.safety?{safety:true}:{},sources:a},data:n},g=await ut(u,f);return this.setState({snapshots:g}),u.meta}finally{this.setState({busy:null})}}async captureBaseline(){if(A)return(await A("captureBaseline",{})).snapshot;await this.ensureLoaded(),await ae();let e={meta:{id:Ur(),name:"Fresh install",createdAt:Date.now(),sizeBytes:0,baseline:true,sources:{}},data:{}},t=await ut(e,this.state.snapshots);return this.setState({snapshots:t}),e.meta}async restore(e,t,r,i){if(A){let a=await A("restore",{id:e,mode:t,excludeKeys:r,restoreRoute:i?.restoreRoute});return this.setState({lastOutcome:a}),a}await this.ensureLoaded(),await ae();let n;i?.safetyCapture&&!this.state.snapshots.find(a=>a.id===e)?.safety&&(n=(await this.capture(Vt,void 0,{safety:true})).id),this.setState({busy:"restore"});try{let a=await fe(e);if(!a)throw new Error(`No snapshot with id "${e}"`);let s={snapshotId:e,snapshotName:a.meta.name,mode:t,at:Date.now(),willReload:false,results:{},...n?{safetySnapshotId:n}:{}};if(a.meta.baseline){for(let m of dt())if(m.clear)try{s.results[m.id]=await m.clear()}catch(O){s.results[m.id]=Fe(String(O))}return s.willReload=this.scheduleReload("buoy time-machine baseline"),this.setState({lastOutcome:s}),s}let f=[...Ve.filter(m=>m in a.data),...Object.keys(a.data).filter(m=>!Ve.includes(m))],u=m=>{let O=new Map;for(let j of m){let W=j.indexOf("::");if(W<=0)continue;let v=j.slice(0,W),U=j.slice(W+2),ee=O.get(v)??[];ee.push(U),O.set(v,ee)}return O},g=r??a.meta.excludedKeys??[],l=u(g),p=!r&&a.meta.scope?.length?u(a.meta.scope):null,z=se(Me)&&(i?.restoreRoute??pt(a.meta));if(t==="reload"){if(a.data.storage&&se("storage")&&(!p||p.has("storage"))&&(s.results.storage=await this.restoreSource("storage",a.data.storage,l.get("storage"),p?.get("storage"))),z){let m=a.meta.route;try{await Yo(m,a.meta.name),s.route={...m,status:"deferred"}}catch(O){s.route={...m,status:"failed",error:String(O)}}}return s.willReload=this.scheduleReload("buoy time-machine restore"),this.setState({lastOutcome:s,snapshots:await Nr(e,s.at,this.state.snapshots)}),s}for(let m of f)if(!(p&&!p.has(m))){if(!se(m)){s.results[m]={ok:true,applied:0,skipped:[],warnings:["Switched off in Sources; left as it is"]};continue}s.results[m]=await this.restoreSource(m,a.data[m],l.get(m),p?.get(m))}return z&&(s.route=Lt(a.meta.route)),this.setState({lastOutcome:s,snapshots:await Nr(e,s.at,this.state.snapshots)}),s}finally{this.setState({busy:null})}}async restoreSource(e,t,r,i){let n=jr(e);if(!n)return Fe("provider not available (package missing or not initialized)");let a=n.status();if(!a.canRestore)return Fe(a.detail??"restore unavailable");try{let s=r?.length||i?.length?{...r?.length?{excludeKeys:r}:{},...i?.length?{includeKeys:i}:{}}:void 0;return await n.restore(Bt(t),s)}catch(s){return Fe(String(s))}}scheduleReload(e){try{return hi({reason:e}),true}catch{return false}}async delete(e){if(A){await A("delete",{id:e});return}await this.ensureLoaded(),await ae();let t=await vi(e),r=await Wr(e,this.state.snapshots);this.setState({snapshots:r,recentlyDeleted:t?{stored:t,at:Date.now()}:null})}async undoDelete(){let e=this.state.recentlyDeleted;if(!e)return;let t=await Si(e.stored,this.state.snapshots);this.setState({snapshots:t,recentlyDeleted:null})}clearRecentlyDeleted(){this.state.recentlyDeleted&&this.setState({recentlyDeleted:null})}async setRestoreRoute(e,t){if(A){await A("setRestoreRoute",{id:e,restoreRoute:t});return}await this.ensureLoaded(),await ae();let r=await bi(e,t,this.state.snapshots);this.setState({snapshots:r})}async duplicate(e){if(A)return(await A("duplicate",{id:e}))?.snapshot??null;await this.ensureLoaded(),await ae();let t=this.state.snapshots.find(i=>i.id===e);if(!t)return null;let r=await wi(e,`${t.name} copy`,this.state.snapshots);return r?(this.setState({snapshots:r.metas}),r.meta):null}async rename(e,t){if(A){await A("rename",{id:e,name:t});return}await this.ensureLoaded(),await ae();let r=await xi(e,t,this.state.snapshots);this.setState({snapshots:r})}async setScope(e,t){if(A){await A("setScope",{id:e,scope:t});return}await this.ensureLoaded(),await ae();let r=await gi(e,t,this.state.snapshots);this.setState({snapshots:r})}async setExclusions(e,t){if(A){await A("setExclusions",{id:e,excludedKeys:t});return}await this.ensureLoaded(),await ae();let r=await yi(e,t,this.state.snapshots);this.setState({snapshots:r})}clearLastOutcome(){this.setState({lastOutcome:null})}async wipeAll(){if(A){let e=await A("wipeAll",{});return this.setState({lastOutcome:e}),e}this.setState({busy:"restore"});try{let e={snapshotId:"wipe-all",snapshotName:"Wipe all",mode:"reload",at:Date.now(),willReload:false,results:{}};for(let t of dt())if(t.clear)try{e.results[t.id]=await t.clear()}catch(r){e.results[t.id]=Fe(String(r))}return e.willReload=this.scheduleReload("buoy time-machine wipe all"),this.setState({lastOutcome:e}),e}finally{this.setState({busy:null})}}clearPreview(){this.previewRunId+=1,this.setState({preview:null})}async buildPreview(e,t="current"){if(A){let n=++this.previewRunId;this.setState({preview:{left:t,right:e,building:true,builtAt:Date.now(),sources:[]}});try{let a=await A("preview",{id:e==="current"?void 0:e.snapshotId,compareTo:t==="current"?void 0:t.snapshotId});if(n!==this.previewRunId)return;this.setState({preview:{left:t,right:e,building:false,builtAt:Date.now(),sources:a.sources??[]}})}catch(a){if(n!==this.previewRunId)return;this.setState({preview:{left:t,right:e,building:false,builtAt:Date.now(),sources:[{id:"error",label:"Preview",items:[],notes:[],error:String(a)}]}})}return}await this.ensureLoaded(),await ae();let r=++this.previewRunId;this.setState({preview:{left:t,right:e,building:true,builtAt:Date.now(),sources:[]}});let i=async n=>{if(n==="current")return null;let a=await fe(n.snapshotId);if(!a)throw new Error(`No snapshot with id "${n.snapshotId}"`);return a.data};try{if(e==="current")throw new Error("preview target must be a snapshot");let[n,a]=await Promise.all([i(t),fe(e.snapshotId)]);if(r!==this.previewRunId)return;if(!a)throw new Error(`No snapshot with id "${e.snapshotId}"`);let s=a.data,f=a.meta.baseline===true,u=f?dt().filter(l=>l.clear).map(l=>l.id):[...Ve.filter(l=>l in s),...Object.keys(s).filter(l=>!Ve.includes(l))],g=[];for(let l of u){if(!se(l))continue;if(await new Promise(m=>setTimeout(m,0)),r!==this.previewRunId)return;let p=jr(l),z=p?.label??l;try{let m=f?void 0:Bt(s[l]),O=n===null?void 0:l in n?Bt(n[l]):void 0,j;if(!p)j={items:[{key:l,label:z,verdict:"wont-apply",reason:"tool not installed \u2014 restore skips this source"}],notes:[]};else if(p.previewItems)j=await p.previewItems(m,O);else{let W=mi(O,m);j={items:[{key:l,label:z,verdict:W.equal?"unchanged":"changed",oldValue:O,newValue:m}],notes:W.truncated?["diff truncated (large value)"]:[]}}if(r!==this.previewRunId)return;g.push({id:l,label:z,...j})}catch(m){g.push({id:l,label:z,items:[],notes:[],error:String(m)})}this.setState({preview:{left:t,right:e,building:true,builtAt:Date.now(),sources:[...g]}})}if(r!==this.previewRunId)return;this.setState({preview:{left:t,right:e,building:false,builtAt:Date.now(),sources:g}})}catch(n){if(r!==this.previewRunId)return;this.setState({preview:{left:t,right:e,building:false,builtAt:Date.now(),sources:[{id:"error",label:"Preview",items:[],notes:[],error:String(n)}]}})}}},x=new Ti;function Ci(e){A=e,e||x.replaceFromSnapshot({})}function zi(e){x.replaceFromSnapshot(e)}function mt(){return di(x.subscribe,()=>x.getState())}function Gr(){let[e,t]=ci(Ht);return li(()=>(t(Ht()),ui(()=>t(Ht()))),[]),e}import{Children as $i}from"react";import{ChevronRight as Li}from"@buoy-gg/shared-ui/web";import{night as N}from"@buoy-gg/shared-ui/web";import{monoFont as Ei}from"@buoy-gg/shared-ui/web";var Ft="2E",Ai="4D",o={color:{sheet:"rgba(5, 5, 5, 0.92)",group:N.color.glass,groupBorder:N.color.glassBorder,rowPressed:N.color.glassElevated,separator:N.color.separator,fill:N.color.glassElevated,fillStrong:N.color.fillTertiary,ring:N.color.bg,disc:N.color.surfaceElevated,label:N.color.text,labelSecondary:N.color.textSecondary,labelTertiary:N.color.textTertiary,accent:N.color.accent,accentSoft:`${N.color.accent}${Ft}`,accentSoftStrong:`${N.color.accent}${Ai}`,onAccent:"#0A0A0A",warning:N.color.warning,warningSoft:`${N.color.warning}${Ft}`,danger:N.color.danger,dangerSoft:`${N.color.danger}${Ft}`,onDanger:"#FFFFFF",info:N.color.info},radius:{group:14,pill:99},gutter:14,textInset:16,separatorInset:16,font:{row:17,control:15,footnote:13,mono:12},tracking:{row:-.43,control:-.2},rowMinHeight:52},ft=Ei;import{jsx as Ie,jsxs as Pi}from"react/jsx-runtime";function gt({children:e,testID:t}){return Ie(d,{style:ge.sectionLabel,testID:t,children:e})}function Ke({children:e,centered:t,tone:r="secondary",testID:i}){return Ie(d,{style:[ge.footnote,t?ge.footnoteCentered:null,r==="warning"?ge.footnoteWarning:null],testID:i,children:e})}function yt({children:e,style:t}){let r=$i.toArray(e);return Ie(h,{style:[ge.group,t],children:r.map((i,n)=>Pi(h,{children:[n>0?Ie(h,{style:ge.separator}):null,i]},i.key??n))})}function Yr(){return Ie(Li,{size:16,color:o.color.labelTertiary})}function Oi({label:e,color:t,background:r,testID:i}){return Ie(h,{style:[ge.pill,{backgroundColor:r}],children:Ie(d,{style:[ge.pillText,{color:t}],testID:i,children:e})})}var ge=P.create({sectionLabel:{color:o.color.labelSecondary,fontSize:o.font.footnote,fontWeight:"500",textTransform:"uppercase",letterSpacing:.4,paddingHorizontal:o.gutter+o.textInset,paddingTop:22,paddingBottom:7},footnote:{color:o.color.labelSecondary,fontSize:o.font.footnote,lineHeight:o.font.footnote*1.35,paddingHorizontal:o.gutter+o.textInset,paddingTop:7},footnoteCentered:{textAlign:"center"},footnoteWarning:{color:o.color.warning},group:{marginHorizontal:o.gutter,backgroundColor:o.color.group,borderRadius:o.radius.group,borderWidth:1,borderColor:o.color.groupBorder,overflow:"hidden"},separator:{height:P.hairlineWidth,marginLeft:o.separatorInset,backgroundColor:o.color.separator},pill:{height:32,paddingHorizontal:15,borderRadius:o.radius.pill,alignItems:"center",justifyContent:"center"},pillText:{fontSize:o.font.control,fontWeight:"600",letterSpacing:o.tracking.control}});import{JotaiIcon as Hi,QueryIcon as Bi,ReduxIcon as ji,RoutesIcon as Wi,StorageIcon as Ni,TimeMachineIcon as Mi,ZustandIcon as Vi}from"@buoy-gg/floating-tools-core/web";import{useSyncExternalStore as Fi}from"react";var Ki={storage:Ni,redux:ji,zustand:Vi,jotai:Hi,query:Bi,route:Wi};function _i(e){return Ki[e]??Mi}function qi(){let{remoteProviders:e,remoteRoute:t}=mt(),r=Gr(),i=Fi(Kr,_r,_r),n=e?e.map(s=>({...s,enabled:s.enabled!==false})):r.map(s=>({id:s.id,label:s.label,...s.status(),enabled:!i.has(s.id)})),a=e?t?.available===true:Be();return[...n,{id:Me,label:"Route",canCapture:a,canRestore:a,enabled:e?t?.enabled!==false:!i.has(Me),detail:a?"Recorded with every snapshot \u2014 a restore can take you back":"No Expo Router detected \u2014 snapshots record no route"}]}function Ji(e){let t=globalThis.confirm;return t?t(e):true}function Kt(e,t,r,i){if(st.OS==="web"){Ji(`${e}
2
2
 
3
- ${t}`)&&i();return}Lr.alert(e,t,[{text:"Cancel",style:"cancel"},{text:r,style:"destructive",onPress:i}])}import{useState as Vi}from"react";import{jsx as Vt,jsxs as Fi}from"react/jsx-runtime";function Ki({disabled:e,busy:t,onCapture:r}){let[i,n]=Vi(""),a=()=>{e||(r(i),n(""))};return Fi(u,{style:Fe.bar,children:[Vt(at,{style:Fe.input,value:i,onChangeText:n,placeholder:"Name this restore point\u2026",placeholderTextColor:o.color.labelTertiary,editable:!e,onSubmitEditing:a,returnKeyType:"done",testID:"time-machine-name-input"}),Vt(P,{style:[Fe.button,e?Fe.buttonDisabled:null],onPress:a,disabled:e,accessibilityRole:"button",accessibilityLabel:"Capture restore point",testID:"time-machine-capture",children:Vt(d,{style:Fe.buttonText,children:t?"Capturing\u2026":"Capture"})})]})}var Fe=A.create({bar:{flexDirection:"row",alignItems:"center",gap:8,marginHorizontal:o.gutter,backgroundColor:o.color.group,borderRadius:o.radius.group,borderWidth:1,borderColor:o.color.groupBorder,paddingLeft:o.textInset,padding:6},input:{flex:1,minWidth:0,color:o.color.label,fontSize:o.font.row,letterSpacing:o.tracking.row,padding:0,backgroundColor:"transparent"},button:{height:34,paddingHorizontal:16,borderRadius:o.radius.pill,backgroundColor:o.color.accent,alignItems:"center",justifyContent:"center"},buttonDisabled:{opacity:.4},buttonText:{color:o.color.onAccent,fontSize:o.font.control,fontWeight:"600",letterSpacing:o.tracking.control}});import{X as _i}from"@buoy-gg/shared-ui/web";import{jsx as ye,jsxs as be}from"react/jsx-runtime";var qi={top:10,bottom:10,left:10,right:10};function Jr(e){if(Object.values(e.results).some(r=>!r.ok||r.skipped.length>0))return true;let t=e.route;return t?.status==="failed"||t?.status==="unavailable"}function gt({glyph:e,text:t,ok:r,testID:i}){return be(d,{style:[we.line,{color:r?o.color.accent:o.color.warning}],numberOfLines:2,testID:i,children:[be(d,{style:we.glyph,children:[e," "]}),t]})}var Ft="time-machine-outcome-route";function Ji({route:e}){return e.status==="navigated"?ye(gt,{glyph:"\u2713",ok:true,text:`route \u2014 ${e.href}`,testID:Ft}):e.status==="deferred"?ye(gt,{glyph:"\u21BB",ok:true,text:`route \u2014 ${e.href} after reload`,testID:Ft}):ye(gt,{glyph:"\u2715",ok:false,text:`route \u2014 ${e.error??e.status}`,testID:Ft})}function Ui({outcome:e}){let t=Object.entries(e.results),r=e.mode==="reload"||e.willReload;return be(u,{style:we.card,testID:"time-machine-outcome",children:[be(u,{style:we.headerRow,children:[be(d,{style:we.title,numberOfLines:1,testID:"time-machine-outcome-title",children:["Restored \u201C",e.snapshotName,"\u201D",r?" \xB7 reloading":""]}),ye(P,{onPress:()=>S.clearLastOutcome(),hitSlop:qi,accessibilityRole:"button",accessibilityLabel:"Dismiss restore result",testID:"time-machine-outcome-dismiss",children:ye(_i,{size:13,color:o.color.labelSecondary})})]}),t.length===0&&!e.route?ye(d,{style:we.empty,testID:"time-machine-outcome-empty",children:"No sources restored."}):null,e.route?ye(Ji,{route:e.route}):null,t.map(([i,n])=>be(u,{children:[ye(gt,{testID:`time-machine-outcome-${i}`,glyph:n.ok?"\u2713":"\u2715",ok:n.ok,text:`${i} \u2014 applied ${n.applied}${n.skipped.length>0?`, skipped ${n.skipped.length}`:""}`}),n.skipped.slice(0,3).map(a=>be(d,{style:we.detail,numberOfLines:2,children:[a.id,": ",a.reason]},a.id)),n.warnings.slice(0,3).map(a=>be(d,{style:we.detail,numberOfLines:2,children:["\u26A0 ",a]},a))]},i))]})}var we=A.create({card:{marginHorizontal:o.gutter,marginTop:12,backgroundColor:o.color.group,borderRadius:o.radius.group,borderWidth:1,borderColor:o.color.groupBorder,padding:14,gap:4},headerRow:{flexDirection:"row",alignItems:"center",gap:10,marginBottom:2},title:{flex:1,color:o.color.label,fontSize:15,fontWeight:"600",letterSpacing:o.tracking.control},line:{fontSize:o.font.footnote,lineHeight:o.font.footnote*1.4},glyph:{fontWeight:"700"},detail:{color:o.color.labelTertiary,fontSize:o.font.mono,lineHeight:o.font.mono*1.4,paddingLeft:14},empty:{color:o.color.labelSecondary,fontSize:o.font.footnote}});import{useEffect as Yi,useRef as Ur}from"react";import{jsx as yt,jsxs as Gi}from"react/jsx-runtime";var Yr=84,Gr=8,ve=null;function Xi(e,t){let r=false,i=a=>{r=a,a?(ve&&ve!==n&&ve(),ve=n):ve===n&&(ve=null),He.spring(e,{toValue:a?-t:0,useNativeDriver:true,bounciness:0,speed:18}).start()},n=()=>i(false);return{pan:xr.create({onMoveShouldSetPanResponder:(a,s)=>Math.abs(s.dx)>Math.abs(s.dy)*1.5?s.dx<-Gr||r&&s.dx>Gr:false,onPanResponderMove:(a,s)=>{let h=r?-t:0;e.setValue(Math.min(0,Math.max(-t,h+s.dx)))},onPanResponderRelease:(a,s)=>{let h=(r?-t:0)+s.dx;i(s.vx<-.5?true:s.vx>.5?false:h<-t/2)},onPanResponderTerminate:()=>i(r)}),close:n}}function Qi({children:e,actions:t,testID:r}){let i=Yr*t.length,n=Ur(new He.Value(0)).current,a=Ur(null);a.current===null&&(a.current=Xi(n,i));let{pan:s,close:h}=a.current;Yi(()=>()=>{ve===h&&(ve=null)},[h]);let p=n.interpolate({inputRange:[-24,0],outputRange:[1,0],extrapolate:"clamp"});return Gi(u,{style:Ke.clip,children:[yt(He.View,{style:[Ke.actionLayer,{width:i,opacity:p}],children:t.map(y=>yt(P,{style:[Ke.action,y.background?{backgroundColor:y.background}:null],onPress:()=>{h(),y.onPress()},accessibilityLabel:y.label,testID:y.testID??(r?`${r}-${y.label.toLowerCase()}`:void 0),children:yt(d,{style:[Ke.actionText,y.color?{color:y.color}:null],numberOfLines:1,children:y.label})},y.label))}),yt(He.View,{style:[Ke.content,{transform:[{translateX:n}]}],...s.panHandlers,children:e})]})}var Ke=A.create({clip:{overflow:"hidden"},actionLayer:{position:"absolute",top:0,bottom:0,right:0,flexDirection:"row"},action:{width:Yr,height:"100%",backgroundColor:o.color.fillStrong,alignItems:"center",justifyContent:"center",paddingHorizontal:6},actionText:{color:o.color.label,fontSize:o.font.footnote,fontWeight:"600",letterSpacing:o.tracking.control},content:{backgroundColor:o.color.group}});function _e(e){let t=Math.max(0,Math.round((Date.now()-e)/1e3));if(t<60)return`${t}s ago`;let r=Math.round(t/60);if(r<60)return`${r}m ago`;let i=Math.round(r/60);return i<24?`${i}h ago`:`${Math.round(i/24)}d ago`}function Zi(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}import{jsx as Re,jsxs as Kt}from"react/jsx-runtime";function Xr(e){if(e.baseline)return"Wipes to fresh install";let t=[_e(e.createdAt),Zi(e.sizeBytes),`${Object.keys(e.sources).length} sources`];return e.excludedKeys?.length?t.push(`skips ${e.excludedKeys.length}`):e.scope?.length&&t.push(`scoped (${e.scope.length})`),e.safety&&t.unshift("safety copy"),t.join(" \xB7 ")}function ea({meta:e,busy:t,armed:r=false,onOpen:i,onRestore:n,onDelete:a,onDuplicate:s,onArm:h}){let p=`time-machine-snap-${e.id}`;return Re(Qi,{testID:p,actions:[{label:"Bar",onPress:h},{label:"Dup",onPress:s},{label:"Delete",onPress:a,background:o.color.danger,color:o.color.onDanger}],children:Kt(u,{style:de.row,children:[Kt(P,{style:de.text,onPress:i,activeOpacity:.7,accessibilityRole:"button",accessibilityLabel:`${e.name}. ${Xr(e)}. Open restore preview`,testID:p,children:[Re(d,{style:de.name,numberOfLines:1,testID:`${p}-name`,children:e.name}),r?Re(d,{style:de.armed,numberOfLines:1,testID:`${p}-armed`,children:"On the action bar"}):null,Re(d,{style:de.meta,numberOfLines:1,testID:`${p}-meta`,children:Xr(e)}),e.lastRestoredAt?Kt(d,{style:de.restored,numberOfLines:1,testID:`${p}-restored`,children:["Restored ",_e(e.lastRestoredAt)]}):null,e.route?Re(d,{style:de.route,numberOfLines:1,testID:`${p}-route`,children:e.route.href}):null]}),Re(P,{onPress:n,disabled:t,style:[de.restore,t?de.actionDisabled:null],accessibilityRole:"button",accessibilityLabel:e.baseline?"Wipe and reload":"Restore",testID:`${p}-restore`,children:Re(zi,{testID:`${p}-restore-label`,label:e.baseline?"Wipe":"Restore",color:e.baseline?o.color.danger:o.color.accent,background:e.baseline?o.color.dangerSoft:o.color.accentSoft})})]})})}var de=A.create({row:{flexDirection:"row",alignItems:"center",gap:10,paddingHorizontal:o.textInset},text:{flex:1,minWidth:0,paddingVertical:11},restore:{justifyContent:"center"},name:{color:o.color.label,fontSize:o.font.row,fontWeight:"600",letterSpacing:o.tracking.row},meta:{color:o.color.labelSecondary,fontSize:o.font.footnote,marginTop:2,fontVariant:["tabular-nums"]},restored:{color:o.color.accent,fontSize:o.font.footnote,marginTop:2},armed:{color:o.color.accent,fontSize:o.font.footnote,marginTop:2},route:{color:o.color.labelTertiary,fontFamily:ht,fontSize:o.font.mono,marginTop:4},actionDisabled:{opacity:.4}});import{useEffect as ta}from"react";import{jsx as Qr,jsxs as Zr}from"react/jsx-runtime";var ra=8e3;function oa({name:e,at:t,onUndo:r,onExpire:i}){return ta(()=>{let n=setTimeout(i,ra);return()=>clearTimeout(n)},[t]),Zr(u,{style:_t.bar,testID:"time-machine-undo-bar",children:[Zr(d,{style:_t.text,numberOfLines:1,testID:"time-machine-undo-text",children:["Deleted \u201C",e,"\u201D"]}),Qr(P,{onPress:r,hitSlop:{top:10,bottom:10,left:10,right:10},accessibilityRole:"button",testID:"time-machine-undo-delete",children:Qr(d,{style:_t.undo,children:"Undo"})})]})}var _t=A.create({bar:{flexDirection:"row",alignItems:"center",gap:12,marginHorizontal:o.gutter,marginTop:12,minHeight:46,paddingHorizontal:o.textInset,backgroundColor:o.color.group,borderRadius:o.radius.group,borderWidth:1,borderColor:o.color.groupBorder},text:{flex:1,color:o.color.labelSecondary,fontSize:o.font.control,letterSpacing:o.tracking.control},undo:{color:o.color.accent,fontSize:o.font.control,fontWeight:"600",letterSpacing:o.tracking.control}});import{NightSwitch as na}from"@buoy-gg/shared-ui/web";import{jsx as le,jsxs as qt}from"react/jsx-runtime";var ia={storage:"Settings, sign-in and other things saved on the device",redux:"Data the whole app shares between screens",zustand:"Data the whole app shares between screens",jotai:"Small pieces of data screens share",query:"Data the app loaded from the server",route:"Which screen you were on"};function aa(e){return ia[e.id]??"App data"}function sa(e){return e.enabled?e.canRestore?null:{text:"Can be saved but not put back",tone:"warn"}:{text:"Off \xB7 left as it is",tone:"off"}}function la({source:e,onToggle:t}){let r=ji(e.id),i=aa(e),n=sa(e);return qt(u,{style:ue.row,testID:`time-machine-source-${e.id}`,accessibilityLabel:`${e.label}: ${i}${n?`. ${n.text}`:""}`,children:[le(u,{style:ue.disc,children:le(r,{size:22,bgColor:o.color.disc})}),qt(u,{style:ue.text,children:[le(d,{style:ue.label,numberOfLines:1,testID:`time-machine-source-${e.id}-label`,children:e.label}),le(d,{style:ue.description,numberOfLines:2,testID:`time-machine-source-${e.id}-description`,children:i}),n?le(d,{style:[ue.state,ue[`state_${n.tone}`]],numberOfLines:1,testID:n.tone==="off"?`time-machine-source-${e.id}-off`:`time-machine-source-${e.id}-detail`,children:n.text}):null]}),le(u,{testID:`time-machine-source-${e.id}-switch`,children:le(na,{value:e.enabled,disabled:!t,onValueChange:a=>t?.(e.id,a)})})]})}function ca({sources:e,onToggle:t}){let r=e.filter(i=>i.canCapture);return qt(ft,{children:[r.map(i=>le(la,{source:i,onToggle:t},i.id)),r.length===0?le(u,{style:ue.row,testID:"time-machine-sources-empty",children:le(d,{style:ue.description,children:"No state tools are set up in this app."})}):null]})}var ue=A.create({row:{flexDirection:"row",alignItems:"center",gap:12,minHeight:o.rowMinHeight,paddingHorizontal:o.textInset,paddingVertical:10},disc:{width:36,height:36,borderRadius:o.radius.pill,backgroundColor:o.color.disc,alignItems:"center",justifyContent:"center"},text:{flex:1,minWidth:0,gap:2},label:{color:o.color.label,fontSize:o.font.row,fontWeight:"500",letterSpacing:o.tracking.row},description:{fontSize:o.font.footnote,lineHeight:o.font.footnote*1.3,color:o.color.labelSecondary},state:{fontSize:o.font.mono,lineHeight:o.font.mono*1.3,fontWeight:"600",marginTop:1},state_off:{color:o.color.labelTertiary},state_warn:{color:o.color.warning}});import{jsx as eo}from"react/jsx-runtime";function da({disabled:e,onWipe:t}){return eo(P,{style:[Jt.row,e?Jt.disabled:null],onPress:t,disabled:e,accessibilityRole:"button",testID:"time-machine-wipe-all",children:eo(d,{style:Jt.label,children:"Wipe All App State\u2026"})})}var Jt=A.create({row:{minHeight:o.rowMinHeight,alignItems:"center",justifyContent:"center"},disabled:{opacity:.4},label:{color:o.color.danger,fontSize:o.font.row,letterSpacing:o.tracking.row}});import{memo as ua,useCallback as ke,useEffect as to,useMemo as bt,useRef as Ut,useState as Yt}from"react";import{ChevronUp as ro,AlertTriangle as pa,RefreshCw as ha,useSafeAreaInsets as ma}from"@buoy-gg/shared-ui/web";import{useToolHeader as fa,useToolHost as ga}from"@buoy-gg/core/web";import{night as wt}from"@buoy-gg/shared-ui/web";import{useToolHost as ya}from"@buoy-gg/core/web";import{night as Gt,scheduleReloadApp as ba}from"@buoy-gg/shared-ui/web";import{jsx as oo}from"react/jsx-runtime";function wa(){let e=()=>{try{ba({reason:"buoy time-machine reload app"})}catch{}};return oo(P,{style:no.chip,onPress:e,accessibilityLabel:"Reload app",accessibilityHint:"Reloads the JavaScript bundle without restoring anything",accessibilityRole:"button",testID:"time-machine-reload-app",children:oo(d,{style:no.label,children:"Reload app"})})}var no=A.create({chip:{height:32,paddingHorizontal:10,borderRadius:8,borderWidth:1,borderColor:Gt.color.border,backgroundColor:Gt.color.buttonSurface,alignItems:"center",justifyContent:"center"},label:{fontSize:11,fontWeight:"700",color:Gt.color.textSecondary}});import{useEffect as vt,useRef as va,useState as Se,useSyncExternalStore as io}from"react";import{Check as ao,ChevronDown as Sa,ChevronUp as xa,FloatingTool as Ia,NightSwitch as Ra,Plus as ka,TimeMachineIcon as Da,X as Ta,night as T,openFloatingTool as Ca,persistentStorage as za,registerPersistentFloatingTool as $a,useLimit as La}from"@buoy-gg/shared-ui/web";import{devToolsStorageKeys as Pa,persistentStorage as Xt}from"@buoy-gg/shared-ui/web";var Qt=Pa.timeMachine.armedPoint(),qe=null,so=false,Zt=null,er=new Set,lo=()=>er.forEach(e=>e());function St(){return qe}function co(e){return er.add(e),()=>{er.delete(e)}}function Ea(){return so?Promise.resolve():(Zt||(Zt=Xt.getItem(Qt).then(e=>{qe===null&&e&&(qe=e,lo())}).catch(()=>{}).finally(()=>{so=true})),Zt)}function tr(e){qe!==e&&(qe=e,lo(),(e===null?Xt.removeItem(Qt):Xt.setItem(Qt,e)).catch(()=>{}))}function uo(e,t){let r=e.filter(n=>!n.baseline&&!n.safety);if(r.length===0)return null;if(t){let n=r.find(a=>a.id===t);if(n)return n}let i=null;for(let n of r)n.lastRestoredAt!==void 0&&(!i||n.lastRestoredAt>(i.lastRestoredAt??0))&&(i=n);return i||r.reduce((n,a)=>a.createdAt>n.createdAt?a:n)}import{useEffect as Aa,useState as Oa}from"react";import{night as H}from"@buoy-gg/shared-ui/web";import{jsx as oe,jsxs as po}from"react/jsx-runtime";function Ha({visible:e,summary:t,onCapture:r,onCancel:i}){let[n,a]=Oa("");Aa(()=>{e&&a("")},[e]);let s=()=>r(n.trim());return oe($r,{visible:e,transparent:true,animationType:"fade",onRequestClose:i,statusBarTranslucent:true,children:oe(Rr,{behavior:it.OS==="ios"?"padding":void 0,style:Z.fill,children:oe(Lt,{style:Z.backdrop,onPress:i,accessibilityLabel:"Cancel",testID:"time-machine-bar-name-backdrop",children:po(Lt,{style:Z.card,onPress:h=>h.stopPropagation(),testID:"time-machine-bar-name-panel",accessible:false,children:[oe(d,{style:Z.title,children:"Name this restore point"}),t?oe(d,{style:Z.summary,testID:"time-machine-bar-name-summary",children:t}):null,oe(at,{testID:"time-machine-bar-name-input",accessibilityLabel:"Restore point name",value:n,onChangeText:a,onSubmitEditing:s,placeholder:"Screen and time, if left empty",placeholderTextColor:H.color.placeholder,autoFocus:true,autoCorrect:false,autoCapitalize:"none",returnKeyType:"done",style:Z.input}),oe(d,{style:Z.hint,children:"Captures the state the app is in right now and arms it on the bar."}),po(u,{style:Z.actions,children:[oe(P,{testID:"time-machine-bar-name-cancel",accessibilityRole:"button",onPress:i,style:Z.secondary,children:oe(d,{style:Z.secondaryText,children:"Cancel"})}),oe(P,{testID:"time-machine-bar-name-capture",accessibilityRole:"button",accessibilityLabel:"Capture and arm this restore point",onPress:s,style:Z.primary,children:oe(d,{style:Z.primaryText,children:"Capture"})})]})]})})})})}var Z=A.create({fill:{flex:1},backdrop:{flex:1,backgroundColor:"rgba(0, 0, 0, 0.55)",alignItems:"center",justifyContent:"center",padding:24},card:{width:"100%",maxWidth:360,borderRadius:H.radius.sheet,borderWidth:1,borderColor:H.color.separator,backgroundColor:H.color.surface,padding:18,gap:12,shadowColor:"#000",shadowOffset:{width:0,height:12},shadowOpacity:.4,shadowRadius:24,elevation:12},title:{color:H.color.text,fontSize:H.font.title,fontWeight:"600"},input:{minHeight:44,borderRadius:H.radius.input,borderWidth:1,borderColor:H.color.accentBorder,backgroundColor:H.color.surfaceElevated,color:H.color.text,fontSize:H.font.row,paddingHorizontal:12},summary:{color:H.color.textTertiary,fontSize:H.font.caption,marginTop:-6},hint:{color:H.color.textSecondary,fontSize:H.font.caption,lineHeight:18},actions:{flexDirection:"row",justifyContent:"flex-end",gap:10,marginTop:4},secondary:{minHeight:40,paddingHorizontal:14,borderRadius:H.radius.input,alignItems:"center",justifyContent:"center"},secondaryText:{color:H.color.textSecondary,fontSize:14,fontWeight:"600"},primary:{minHeight:40,paddingHorizontal:18,borderRadius:H.radius.input,backgroundColor:H.color.accent,alignItems:"center",justifyContent:"center"},primaryText:{color:H.color.onAccent,fontSize:14,fontWeight:"700"}});import{devToolsStorageKeys as Ba,persistentStorage as ho}from"@buoy-gg/shared-ui/web";var mo=Ba.timeMachine.barReloadMode(),Je=false,fo=false,rr=null,or=new Set,go=()=>or.forEach(e=>e());function yo(){return Je}function Wa(e){return or.add(e),()=>{or.delete(e)}}function ja(){return fo?Promise.resolve():(rr||(rr=ho.getItem(mo).then(e=>{!Je&&e==="1"&&(Je=true,go())}).catch(()=>{}).finally(()=>{fo=true})),rr)}function Na(e){e!==Je&&(Je=e,go(),ho.setItem(mo,e?"1":"0").catch(()=>{}))}import{Fragment as Ma,jsx as k,jsxs as F}from"react/jsx-runtime";var nr="time-machine-restore",xt=1e4,bo=900,ir=6,wo={id:nr,render:e=>k(Ka,{...e})},vo=false;function So(){vo||(vo=true,$a(wo,za))}typeof yr<"u"&&yr&&typeof navigator<"u"&&navigator.product==="ReactNative"&&So();function ar(e){e&&tr(e),Ca(wo)}function Va(e){let t=Object.values(e.results),r=t.filter(s=>!s.ok||s.skipped.length>0).length,i=t.length,n=e.route,a=n?.status==="failed"||n?.status==="unavailable";return r===0&&a?"Route did not restore":`${r} of ${i} source${i===1?"":"s"} failed`}function Fa(e){let t=[];for(let[i,n]of Object.entries(e.results)){if(n.ok&&n.skipped.length===0)continue;let a=n.skipped[0]?.reason??n.warnings[0]??"did not apply";t.push(`${i}: ${a}`)}let r=e.route;return(r?.status==="failed"||r?.status==="unavailable")&&t.push(`route: ${r.status}`),t}function xo(e){let[t,r]=Se(0);return vt(()=>{if(!t)return;let i=setTimeout(()=>r(0),e);return()=>clearTimeout(i)},[t,e]),[t>0,()=>r(i=>i+1)]}function Ka({id:e,revealToken:t,dismiss:r}){let{snapshots:i,hasLoaded:n,busy:a}=pt(),s=_r(),h=io(co,St,St),p=La("timeMachine.snapshots"),y=io(Wa,yo,yo),{width:c}=kr(),[I,L]=Se(null),[b,O]=Se(null),[W,j]=Se(),[w,U]=Se(false),[ee,Y]=xo(bo),[Le,te]=xo(bo),[K,z]=Se(null),[ne,he]=Se(null),[,De]=Se(0),ie=va(true);vt(()=>(ie.current=true,Ea(),ja(),S.ensureLoaded(),()=>{ie.current=false}),[]);let D=uo(i,h),Qe=D?.id,Pe=D?.lastRestoredAt,Ze=D?.createdAt;vt(()=>{if(Pe===void 0&&Ze===void 0&&!K&&ne===null)return;let f=setInterval(()=>De(V=>V+1),2500);return()=>clearInterval(f)},[Pe,Ze,K,ne]),vt(()=>{b&&b.snapshotId!==Qe&&(O(null),L(f=>f==="outcome"?null:f))},[Qe,b]);let Te=Date.now(),et=K!==null&&Te-K.at<xt&&i.some(f=>f.id===K.id),Ee=i.filter(f=>!f.safety).length>=p,l=!D||a!==null,v=a!==null,C=async(f,V)=>{if(!a){L(null),j(void 0);try{let X=await S.restore(f,y&&V.safetyCapture?"reload":"live",void 0,V);if(!ie.current)return;Jr(X)?(O(X),L("outcome")):(O(null),Y()),z(X.safetySnapshotId?{id:X.safetySnapshotId,at:Date.now()}:null),X.safetySnapshotId&&he(null)}catch(X){if(!ie.current)return;j(X instanceof Error?X.message:String(X)),L("error")}}},R=(f=false)=>{D&&C(D.id,{safetyCapture:true,...f?{restoreRoute:false}:{}})},_=()=>{K&&C(K.id,{safetyCapture:false,restoreRoute:false}).then(()=>{ie.current&&he(Date.now())})},re=()=>{if(!a){if(j(void 0),Ee){L("cap");return}L(null),U(true)}},G=async f=>{if(U(false),!a)try{let V=await S.capture(f);if(!ie.current)return;tr(V.id),z(null),te()}catch(V){if(!ie.current)return;j(V instanceof Error?V.message:String(V)),L("error")}},Ae=f=>{tr(f.id),L(null)},tt=D?.name??(n?"No restore points":"Loading\u2026"),q,Ce="normal",rt=false;if(a==="restore")q="Restoring\u2026";else if(a==="capture")q="Capturing\u2026";else if(W)q=W,Ce="danger";else if(b&&D&&b.snapshotId===D.id)q=Va(b),Ce="danger";else if(!D)q=n?"Capture one with +":"";else{rt=true;let f=D.lastRestoredAt===void 0?null:Te-D.lastRestoredAt,V=Te-D.createdAt;ne!==null&&Te-ne<xt?q="undone, state only":f!==null&&f<xt?q="restored just now":V<xt&&f===null?q="captured just now":D.lastRestoredAt!==void 0?q=`restored ${_e(D.lastRestoredAt)}`:q=`${Object.keys(D.sources).length} sources`,y&&(q+=" \xB7 reloads")}let ce=rt&&!et&&D&&D.route&&ut(D)?D.route.pathname:null,ze=i.filter(f=>!f.baseline&&!f.safety),ot=(()=>{let f=s.filter(mr=>mr.status().canCapture&&se(mr.id)).length,V=nt(),X=[`${f} source${f===1?"":"s"}`];return V&&X.push(V.pathname),X.join(" \xB7 ")})(),$;return I==="picker"?$=F(u,{style:x.menu,testID:"time-machine-bar-picker",children:[F(Pt,{style:x.pickerList,bounces:false,children:[ze.map(f=>{let V=f.id===D?.id;return F(P,{testID:`time-machine-bar-pick-${f.id}`,accessibilityRole:"button",accessibilityState:{selected:V},accessibilityLabel:`Arm ${f.name}`,onPress:()=>Ae(f),style:x.pickRow,children:[F(u,{style:x.pickText,children:[k(d,{numberOfLines:1,style:x.pickName,children:f.name}),F(d,{numberOfLines:1,style:x.pickDetail,children:[_e(f.createdAt),f.route?` \xB7 ${f.route.pathname}`:"",f.lastRestoredAt!==void 0?k(d,{style:x.pickRestored,children:` \xB7 restored ${_e(f.lastRestoredAt)}`}):null]})]}),V?k(ao,{size:14,color:T.color.accent}):null]},f.id)}),ze.length===0?k(d,{style:x.menuText,children:"No restore points yet."}):null]}),ze.length>ir?F(d,{style:x.pickerMore,children:["Scroll for ",ze.length-ir," more"]}):null,F(u,{style:x.settingRow,testID:"time-machine-bar-reload-mode",children:[F(u,{style:x.settingText,children:[k(d,{style:x.settingLabel,children:"Reload the app after restoring"}),k(d,{style:x.settingHint,children:"For screens that read their state from storage only when they open, like a cart kept in a React context."})]}),k(Ra,{value:y,onValueChange:Na})]})]}):I==="outcome"&&b?$=F(u,{style:x.menu,testID:"time-machine-bar-outcome",children:[Fa(b).map(f=>k(d,{style:x.menuDanger,children:f},f)),k(d,{style:x.menuText,children:"The full report is on Time Machine's outcome card."}),k(sr,{onPress:()=>L(null)})]}):I==="cap"?$=F(u,{style:x.menu,testID:"time-machine-bar-cap",children:[F(d,{style:x.menuText,children:["Free plan keeps ",p," restore point",p===1?"":"s",". Delete one in Time Machine, or upgrade to Pro for unlimited snapshots."]}),k(sr,{onPress:()=>L(null)})]}):I==="error"&&W&&($=F(u,{style:x.menu,testID:"time-machine-bar-error",children:[k(d,{accessibilityRole:"alert",style:x.menuDanger,children:W}),k(sr,{onPress:()=>{L(null),j(void 0)}})]})),F(Ma,{children:[k(Ha,{visible:w,summary:ot,onCapture:f=>void G(f),onCancel:()=>U(false)}),k(Ia,{id:e,revealToken:t,variant:"strip",dragFromSurface:true,defaultPlacement:"bottom",accessibilityLabel:`Move or hide the action bar. ${D?`${D.name} armed`:"Nothing armed"}`,accessory:$,handleAdornment:k(Da,{size:12,color:T.color.accent}),children:F(u,{style:[x.row,{width:Math.max(260,Math.min(320,c-64))}],children:[k(P,{testID:"time-machine-bar-restore",accessibilityRole:"button",accessibilityLabel:D?`Restore ${D.name}`:"Restore, nothing armed",accessibilityHint:ce?`Also returns to ${ce}. Long press to restore state only.`:void 0,accessibilityState:{disabled:l},disabled:l,onPress:()=>R(false),onLongPress:()=>R(true),style:[x.restoreButton,l&&x.disabled],children:a==="restore"?k(st,{size:"small",color:T.color.accent}):ee?k(d,{style:x.restoreText,testID:"time-machine-bar-restored",children:"Restored"}):k(d,{style:x.restoreText,children:"Restore"})}),F(u,{style:x.identity,children:[k(d,{testID:"time-machine-bar-name",accessibilityLabel:`Armed restore point: ${tt}`,numberOfLines:1,ellipsizeMode:"middle",style:x.name,children:tt}),F(u,{style:x.statusRow,children:[F(d,{testID:"time-machine-bar-status",numberOfLines:1,accessibilityLiveRegion:"polite",style:[x.status,Ce==="danger"&&x.danger],children:[q,ce?k(d,{style:x.destination,children:` \xB7 \u2192 ${ce}`}):null]}),et&&!a?k(P,{testID:"time-machine-bar-undo",accessibilityRole:"button",accessibilityLabel:"Undo the last restore",onPress:_,hitSlop:{top:8,bottom:8,left:6,right:6},children:k(d,{style:x.undo,children:"Undo"})}):null]})]}),k(P,{testID:"time-machine-bar-pick",accessibilityRole:"button",accessibilityLabel:"Choose another restore point",accessibilityState:{expanded:I==="picker"},onPress:()=>L(f=>f==="picker"?null:"picker"),style:x.smallButton,children:I==="picker"?k(xa,{size:14,color:T.color.textSecondary}):k(Sa,{size:14,color:T.color.textSecondary})}),k(P,{testID:"time-machine-bar-capture",accessibilityRole:"button",accessibilityLabel:"Capture a new restore point here and arm it",accessibilityState:{disabled:v},disabled:v,onPress:re,style:[x.smallButton,v&&x.disabled],children:a==="capture"?k(st,{size:"small",color:T.color.accent}):Le?k(u,{testID:"time-machine-bar-captured",children:k(ao,{size:18,color:T.color.accent})}):k(ka,{size:18,color:Ee?T.color.textTertiary:T.color.text})}),k(u,{style:x.separator}),k(P,{testID:"time-machine-bar-close",accessibilityRole:"button",accessibilityLabel:"Close the action bar",onPress:r,style:x.closeButton,children:k(Ta,{size:16,color:T.color.textSecondary})})]})})]})}function sr({onPress:e,label:t="Dismiss"}){return k(P,{testID:"time-machine-bar-dismiss",accessibilityRole:"button",onPress:e,style:x.dismiss,children:k(d,{style:x.dismissText,children:t})})}var x=A.create({row:{flexDirection:"row",alignItems:"center",gap:4,paddingVertical:4,minHeight:48},restoreButton:{height:32,minWidth:72,paddingHorizontal:12,borderRadius:8,borderWidth:1,borderColor:T.color.accentBorderStrong,backgroundColor:T.color.accentSoft,alignItems:"center",justifyContent:"center",marginLeft:2},restoreText:{color:T.color.accent,fontSize:12,fontWeight:"700"},smallButton:{width:32,minHeight:44,alignItems:"center",justifyContent:"center"},closeButton:{width:28,minHeight:44,alignItems:"center",justifyContent:"center"},identity:{flex:1,minHeight:44,justifyContent:"center",gap:1},name:{color:T.color.text,fontSize:13,fontWeight:"500"},statusRow:{flexDirection:"row",alignItems:"center",gap:8},status:{color:T.color.textSecondary,fontSize:10,lineHeight:14,flexShrink:1},destination:{color:T.color.textTertiary},danger:{color:T.color.danger},undo:{color:T.color.accent,fontSize:10,lineHeight:14,fontWeight:"700"},separator:{height:20,width:1,backgroundColor:T.color.separator,marginHorizontal:2},disabled:{opacity:.4},menu:{marginVertical:8,padding:6,borderRadius:T.radius.card,borderWidth:1,borderColor:T.color.separator,backgroundColor:T.color.surface,shadowColor:"#000",shadowOffset:{width:0,height:6},shadowOpacity:.25,shadowRadius:16,elevation:8},menuText:{color:T.color.textSecondary,fontSize:12,lineHeight:18,padding:10},menuDanger:{color:T.color.danger,fontSize:12,lineHeight:18,paddingHorizontal:10,paddingTop:6},pickerList:{maxHeight:ir*44},pickerMore:{color:T.color.textTertiary,fontSize:10,lineHeight:14,textAlign:"center",paddingVertical:4},pickRow:{flexDirection:"row",alignItems:"center",gap:8,minHeight:44,paddingHorizontal:10,borderRadius:T.radius.row},pickText:{flex:1},settingRow:{flexDirection:"row",alignItems:"center",gap:10,paddingHorizontal:10,paddingVertical:8,borderTopWidth:A.hairlineWidth,borderTopColor:T.color.separator,marginTop:4},settingText:{flex:1,gap:2},settingLabel:{color:T.color.text,fontSize:12,fontWeight:"500"},settingHint:{color:T.color.textTertiary,fontSize:10,lineHeight:13},pickName:{color:T.color.text,fontSize:13,fontWeight:"500"},pickDetail:{color:T.color.textSecondary,fontSize:10,lineHeight:14},pickRestored:{color:T.color.accent},dismiss:{alignSelf:"flex-end",paddingHorizontal:10,paddingVertical:8},dismissText:{color:T.color.accent,fontSize:12,fontWeight:"600"}});import{jsx as It,jsxs as Io}from"react/jsx-runtime";function _a({armId:e}){let t=ya(),r=()=>{ar(e),t.minimize()};return Io(P,{style:Rt.labeledChip,onPress:r,accessibilityLabel:"Open the floating action bar over the app",accessibilityRole:"button",testID:"time-machine-header-bar",children:[It(u,{style:Rt.glyph}),It(d,{style:Rt.label,children:"Action bar"})]})}function Ro({armId:e}){return Io(u,{style:Rt.row,children:[It(_a,{armId:e}),It(wa,{})]})}var Rt=A.create({row:{flexDirection:"row",alignItems:"center",gap:8},labeledChip:{height:32,flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:10,borderRadius:8,borderWidth:1,borderColor:wt.color.border,backgroundColor:wt.color.buttonSurface},glyph:{width:14,height:8,borderRadius:3,borderWidth:1.5,borderColor:wt.color.accent},label:{fontSize:11,fontWeight:"700",color:wt.color.accent}});import{useMemo as qa}from"react";import{ABSENT_VALUE as ko,ThemedSplitView as Ja,devToolsDefaultTheme as Ua,toDiffable as Do}from"@buoy-gg/shared-ui/web/dataViewer";import{jsx as Ya,jsxs as To}from"react/jsx-runtime";var Ga=[];function Xa({item:e,testID:t}){let{oldValue:r,newValue:i}=qa(()=>({oldValue:e.verdict==="added"?ko:Do(e.oldValue),newValue:e.verdict==="removed"?ko:Do(e.newValue)}),[e]);return To(u,{style:Co.panel,testID:t,children:[e.reason?To(d,{style:Co.reason,children:["\u26A0 ",e.reason]}):null,Ya(Ja,{oldValue:r,newValue:i,differences:Ga,theme:Ua,scrollEnabled:false})]})}var Co=A.create({panel:{paddingLeft:16,paddingRight:12,paddingTop:10,paddingBottom:14,gap:10,backgroundColor:o.color.group},reason:{color:o.color.warning,fontSize:o.font.footnote}});import{useEffect as Qa,useState as Za}from"react";import{jsx as zo,jsxs as es}from"react/jsx-runtime";function ts({name:e,onRename:t}){let[r,i]=Za(e);Qa(()=>i(e),[e]);let n=()=>{let a=r.trim();if(!a){i(e);return}a!==e&&t(a)};return es(u,{style:lr.row,children:[zo(d,{style:lr.label,children:"Name"}),zo(at,{style:lr.input,value:r,onChangeText:i,onSubmitEditing:n,onBlur:n,returnKeyType:"done",selectTextOnFocus:true,accessibilityLabel:"Restore point name",testID:"tm-preview-name"})]})}var lr=A.create({row:{flexDirection:"row",alignItems:"center",gap:14,minHeight:o.rowMinHeight,paddingHorizontal:o.textInset},label:{color:o.color.labelSecondary,fontSize:o.font.row,letterSpacing:o.tracking.row},input:{flex:1,minWidth:0,color:o.color.label,fontSize:o.font.row,fontWeight:"600",letterSpacing:o.tracking.row,textAlign:"right",padding:0,backgroundColor:"transparent"}});var Ue={added:{glyph:"+",color:o.color.accent,label:"added",applies:true},removed:{glyph:"\u2212",color:o.color.danger,label:"removed",applies:true},changed:{glyph:"\u2248",color:o.color.info,label:"changed",applies:true},"too-large":{glyph:"\u2248",color:o.color.warning,label:"changed (large)",applies:true},unchanged:{glyph:"=",color:o.color.labelTertiary,label:"unchanged",applies:false},"wont-apply":{glyph:"\u2298",color:o.color.warning,label:"won't apply",applies:false},recomputes:{glyph:"\u21BB",color:o.color.labelTertiary,label:"recomputes",applies:false}};import{Fragment as rs,jsx as m,jsxs as B}from"react/jsx-runtime";var $o={storage:"keys",redux:"slices",zustand:"stores",jotai:"atoms",query:"queries"},cr=new Set;function os(e,t){if(e.size!==t.size)return false;for(let r of e)if(!t.has(r))return false;return true}function pe(e,t){return`${e}::${t}`}function kt(e){if(e===void 0)return"\u2205";try{let t=typeof e=="string"?`"${e}"`:JSON.stringify(e);return t?t.length>46?`${t.slice(0,43)}\u2026`:t:String(e)}catch{return"[complex]"}}function Ye({position:e,children:t}){return B(u,{style:[g.cardRow,e.first?g.cardRowFirst:null,e.last?g.cardRowLast:null],children:[e.first?null:m(u,{style:g.cardSeparator}),t]})}function dr({glyph:e,count:t,color:r,testID:i}){return m(u,{style:[g.countPill,{backgroundColor:`${r}26`}],children:B(d,{style:[g.countPillText,{color:r}],testID:i,children:[e,t]})})}function ur({state:e}){return m(u,{style:[g.checkbox,e!=="none"&&g.checkboxChecked],children:e==="none"?null:m(d,{style:g.checkboxGlyph,children:e==="all"?"\u2713":"\u2212"})})}var ns=ua(function({row:e,expanded:t,onOpen:r,onToggle:i}){let n=Ue[e.item.verdict],a=!n.applies||e.excluded,s=e.item.verdict==="changed"||e.item.verdict==="added"||e.item.verdict==="removed",h=`tm-preview-item-${e.sourceId}-${e.item.key}`;return m(Ye,{position:e,children:B(u,{style:[g.itemRow,a&&g.dimmed],children:[m(P,{onPress:i,disabled:!n.applies,hitSlop:{top:10,bottom:10,left:8,right:8},testID:`tm-preview-toggle-${e.sourceId}-${e.item.key}`,accessibilityRole:"checkbox",accessibilityState:{checked:!(!n.applies||e.excluded)},accessibilityLabel:`Include ${e.item.label}`,children:m(ur,{state:!n.applies||e.excluded?"none":"all"})}),B(P,{style:g.itemBodyTouch,onPress:()=>s&&r(),disabled:!s,testID:h,children:[m(d,{style:[g.itemGlyph,{color:n.color}],children:n.glyph}),B(u,{style:g.itemBody,children:[m(d,{style:g.itemLabel,numberOfLines:1,testID:`${h}-label`,children:e.item.label}),e.item.verdict==="changed"&&B(d,{style:g.itemPreview,numberOfLines:1,testID:`${h}-values`,children:[kt(e.item.oldValue)," \u2192"," ",kt(e.item.newValue)]}),e.item.verdict==="added"&&m(d,{style:g.itemPreview,numberOfLines:1,testID:`${h}-values`,children:kt(e.item.newValue)}),e.item.verdict==="removed"&&m(d,{style:[g.itemPreview,g.itemPreviewRemoved],numberOfLines:1,testID:`${h}-values`,children:kt(e.item.oldValue)}),e.excluded?m(d,{style:g.itemExcluded,testID:`${h}-excluded`,children:"excluded \u2014 restore leaves this untouched"}):e.item.reason&&m(d,{style:g.itemReason,numberOfLines:2,testID:`${h}-reason`,children:e.item.reason})]}),s?t?m(ro,{size:16,color:o.color.labelTertiary}):m(qr,{}):null]})]})})});function is({preview:e,snapshots:t,busy:r,onBack:i,onRestore:n}){let a=ga(),s=a.instanceId!==void 0,h=ma({minBottom:16}),[p,y]=Yt({}),[c,I]=Yt(new Set),L=Ut(false),[b,O]=Yt(cr),W=ke(l=>{O(v=>{let C=new Set(v);return C.has(l)?C.delete(l):C.add(l),C})},[]),j=a.search,w=e.right==="current"?void 0:t.find(l=>l.id===e.right.snapshotId),U=Ut(w);U.current=w;let ee=ke(()=>{if(!U.current)return;let l=U.current;S.setRestoreRoute(l.id,!ut(l))},[]),Y=w?.baseline===true,Le=e.left==="current",te=bt(()=>w?w.excludedKeys?.length?new Set(w.excludedKeys):cr:null,[w]),K=!!w?.scope?.length&&!w?.excludedKeys?.length,z=bt(()=>{if(!K||!w?.scope)return cr;let l=new Set(w.scope),v=new Set;for(let C of e.sources)for(let R of C.items){let _=pe(C.id,R.key);Ue[R.verdict].applies&&!l.has(_)&&v.add(_)}return v},[K,w,e.sources]),ne=Ut(null);to(()=>{if(!w||e.building||!te||ne.current===w.id)return;ne.current=w.id,L.current=false;let l=te.size>0?te:z;l.size>0&&I(new Set(l)),K&&l.size>0&&S.setExclusions(w.id,Array.from(l))},[w,e.building,te,z,K]),to(()=>{if(!w||!te||!L.current||os(c,te))return;let l=Array.from(c);S.setExclusions(w.id,l.length?l:null)},[c,w,te]);let he=ke(l=>{L.current=true,I(v=>{let C=new Set(v);return C.has(l)?C.delete(l):C.add(l),C})},[]),De=ke((l,v)=>{L.current=true,I(C=>{let R=new Set(C);for(let _ of l.items){if(!Ue[_.verdict].applies)continue;let re=pe(l.id,_.key);v==="all"?R.add(re):R.delete(re)}return R})},[]),ie=ke((l,v)=>{y(C=>({...C,[l]:!v}))},[]),D=bt(()=>{let l=0,v=0,C=0,R=[];for(let _ of e.sources){let re=0;for(let G of _.items)Ue[G.verdict].applies?c.has(pe(_.id,G.key))?v+=1:(l+=1,re+=1):G.verdict==="wont-apply"&&(C+=1);re>0&&R.push(`${re} ${_.label.toLowerCase()}`)}return{applies:l,excludedCount:v,wontApply:C,perSource:R}},[e.sources,c]);fa(s?{title:"Restore Preview",subtitle:w?.name??"preview",onBack:i,actions:m(Ro,{armId:w?.id})}:null,[s,w?.name,w?.id]);let{rows:Qe,blockedSources:Pe}=bt(()=>{let l=j.trim().toLowerCase(),v=[],C=[];for(let R of e.sources){let _=R.items.some($=>$.verdict!=="unchanged");if(!_&&!R.error)continue;let re=_||R.notes.length>0||!!R.error,G=R.items.filter($=>Ue[$.verdict].applies),Ae=R.items.filter($=>$.verdict==="wont-apply").length;Ae>0&&C.push(R.label);let tt=R.items.length===1?($o[R.id]??"items").replace(/ies$/,"y").replace(/s$/,""):$o[R.id]??"items",q=`${R.items.length} ${tt} \xB7 `+(G.length>0?`${G.length} changed`:Ae>0?`${Ae} won't apply`:"no changes"),Ce=G.filter($=>c.has(pe(R.id,$.key))).length,rt=G.length===0||Ce===0?"all":Ce===G.length?"none":"some",ce={added:0,removed:0,changed:0};for(let $ of R.items)c.has(pe(R.id,$.key))||($.verdict==="added"?ce.added+=1:$.verdict==="removed"?ce.removed+=1:($.verdict==="changed"||$.verdict==="too-large")&&(ce.changed+=1));let ze=R.items.filter($=>!($.verdict==="unchanged"||l&&!$.label.toLowerCase().includes(l))),ot=re?p[R.id]??true:true;if(v.push({kind:"source",source:R,collapsed:ot,includeState:rt,applicableCount:G.length,counts:ce,expandable:re,summary:q,first:false,last:false}),!ot){for(let $ of R.notes)v.push({kind:"note",id:`${R.id}:${$}`,text:$,first:false,last:false});R.error&&v.push({kind:"note",id:`${R.id}:err`,text:`\u26A0 ${R.error}`,first:false,last:false});for(let $ of ze){let f=pe(R.id,$.key);v.push({kind:"item",sourceId:R.id,item:$,excluded:c.has(f),first:false,last:false}),b.has(f)&&v.push({kind:"diff",sourceId:R.id,item:$,first:false,last:false})}}}return w?.route&&v.push({kind:"route",href:w.route.href,on:ut(w),first:false,last:false}),v.length>0&&(v[0].first=true,v[v.length-1].last=true),{rows:v,blockedSources:C}},[e.sources,j,p,c,b,w]),Ze=ke(({item:l})=>{if(l.kind==="source"){let v=l.source,{counts:C}=l;return m(Ye,{position:l,children:B(u,{style:g.sourceCard,children:[m(P,{onPress:()=>De(v,l.includeState),disabled:l.applicableCount===0,hitSlop:{top:10,bottom:10,left:8,right:8},testID:`tm-preview-source-toggle-${v.id}`,children:m(ur,{state:l.applicableCount===0?"none":l.includeState})}),B(P,{style:g.sourceCardTouch,onPress:()=>l.expandable&&ie(v.id,l.collapsed),disabled:!l.expandable,testID:`tm-preview-source-${v.id}`,children:[B(u,{style:g.sourceNameBlock,children:[m(d,{style:g.sourceName,numberOfLines:1,testID:`tm-preview-source-${v.id}-name`,children:v.label}),m(d,{style:g.sourceSummary,numberOfLines:1,testID:`tm-preview-source-${v.id}-summary`,children:l.includeState==="none"&&l.applicableCount>0?`${l.summary} \xB7 excluded`:l.summary})]}),B(u,{style:g.sourceBadges,children:[C.removed>0?m(dr,{glyph:"\u2212",count:C.removed,color:o.color.danger,testID:`tm-preview-source-${v.id}-removed`}):null,C.added>0?m(dr,{glyph:"+",count:C.added,color:o.color.accent,testID:`tm-preview-source-${v.id}-added`}):null,C.changed>0?m(dr,{glyph:"\u2248",count:C.changed,color:o.color.info,testID:`tm-preview-source-${v.id}-changed`}):null]}),l.expandable?l.collapsed?m(qr,{}):m(ro,{size:16,color:o.color.labelTertiary}):null]})]})})}return l.kind==="note"?m(Ye,{position:l,children:m(d,{style:g.noteRow,testID:`tm-preview-note-${l.id}`,children:l.text})}):l.kind==="route"?m(Ye,{position:l,children:B(P,{style:g.routeRow,onPress:ee,accessibilityRole:"switch",accessibilityState:{checked:l.on},accessibilityLabel:`Also return to ${l.href}`,testID:"tm-preview-route",children:[m(ur,{state:l.on?"all":"none"}),B(u,{style:g.routeText,children:[m(d,{style:g.routeTitle,children:"Return to this screen"}),m(d,{style:g.routeHref,numberOfLines:1,testID:"tm-preview-route-href",children:l.href})]})]})}):l.kind==="diff"?m(Ye,{position:l,children:m(Xa,{item:l.item,testID:`tm-preview-diff-${l.sourceId}-${l.item.key}`})}):m(ns,{row:l,expanded:b.has(pe(l.sourceId,l.item.key)),onOpen:()=>W(pe(l.sourceId,l.item.key)),onToggle:()=>he(pe(l.sourceId,l.item.key))})},[b,W,ie,he,De,ee]),Te=ke(l=>l.kind==="source"?`s:${l.source.id}`:l.kind==="note"?`n:${l.id}`:l.kind==="route"?"route":l.kind==="diff"?`d:${l.sourceId}:${l.item.key}`:`i:${l.sourceId}:${l.item.key}`,[]),et=B(u,{children:[!s&&B(u,{style:g.fallbackHeader,children:[m(P,{onPress:i,hitSlop:as,testID:"tm-preview-back",children:m(d,{style:g.backText,children:"\u2039 Back"})}),m(d,{style:g.screenTitle,numberOfLines:1,children:"Restore Preview"})]}),w?B(rs,{children:[m(mt,{children:"Restore Point"}),m(ft,{children:m(ts,{name:w.name,onRename:l=>void S.rename(w.id,l)})})]}):null,m(mt,{children:"Changes to Restore"})]}),Ee=r||e.building||D.applies===0;return B(u,{style:g.container,children:[m(Ir,{testID:"tm-preview-list",data:Qe,renderItem:Ze,keyExtractor:Te,ListHeaderComponent:et,ListEmptyComponent:e.building?m(st,{style:g.buildingSpinner,size:"small",color:o.color.accent}):m(d,{style:g.emptyText,testID:"tm-preview-empty",children:j?"Nothing matches this filter.":"No changes \u2014 restoring would change nothing."}),ListFooterComponent:m(u,{children:D.wontApply>0?B(u,{style:g.warnNote,children:[m(pa,{size:12,color:o.color.warning}),B(d,{style:g.warnNoteText,testID:"tm-preview-wont-apply",children:[D.wontApply," item",D.wontApply===1?"":"s"," ","won't apply \u2014 expand"," ",Pe.length>0?Pe.join(" and "):"the source"," ","to see the reason."]})]}):null}),keyboardShouldPersistTaps:"handled",removeClippedSubviews:true,initialNumToRender:20,windowSize:7,contentContainerStyle:g.listContent}),Le&&w&&B(u,{style:[g.footer,{paddingBottom:h.bottom}],children:[B(P,{style:[g.cta,Y&&g.ctaDanger,Ee&&g.ctaDisabled],onPress:()=>n(Y?"reload":"live",Array.from(c)),disabled:Y?r||e.building:Ee,testID:"tm-preview-restore",children:[m(ha,{size:16,color:Y?o.color.onDanger:o.color.onAccent}),m(d,{style:[g.ctaText,Y?g.ctaTextDanger:null],children:Y?"Wipe & Reload":"Restore State"})]}),m(d,{style:g.ctaCaption,testID:"tm-preview-cta-caption",children:Y?"This wipes all app storage and reloads the app.":D.excludedCount>0?`Restores ${D.applies} of ${D.applies+D.excludedCount} change${D.applies+D.excludedCount===1?"":"s"} \u2014 everything else stays as it is.`:"This will replace the current state with the snapshot."})]})]})}var as={top:10,bottom:10,left:10,right:10},g=A.create({container:{flex:1,backgroundColor:"transparent"},fallbackHeader:{flexDirection:"row",alignItems:"center",paddingHorizontal:o.gutter,paddingVertical:10,gap:10},backText:{color:o.color.accent,fontSize:o.font.control},screenTitle:{color:o.color.label,fontSize:20,fontWeight:"700",letterSpacing:o.tracking.row,flex:1},dimmed:{opacity:.5},listContent:{paddingTop:14,paddingBottom:12},cardRow:{marginHorizontal:o.gutter,backgroundColor:o.color.group},cardRowFirst:{borderTopLeftRadius:o.radius.group,borderTopRightRadius:o.radius.group},cardRowLast:{borderBottomLeftRadius:o.radius.group,borderBottomRightRadius:o.radius.group,marginBottom:10},cardSeparator:{height:A.hairlineWidth,marginLeft:51,backgroundColor:o.color.separator},warnNote:{flexDirection:"row",alignItems:"flex-start",gap:6,paddingHorizontal:o.gutter+o.textInset,paddingTop:8},warnNoteText:{flex:1,color:o.color.labelSecondary,fontSize:o.font.footnote,lineHeight:o.font.footnote*1.35},countPill:{borderRadius:o.radius.pill,paddingHorizontal:9,paddingVertical:3},countPillText:{fontFamily:ht,fontSize:o.font.footnote,fontWeight:"600"},checkbox:{width:23,height:23,borderRadius:o.radius.pill,borderWidth:1.7,borderColor:o.color.labelTertiary,alignItems:"center",justifyContent:"center"},checkboxChecked:{borderColor:o.color.accent,backgroundColor:o.color.accent},checkboxGlyph:{color:o.color.onAccent,fontSize:13,fontWeight:"700",lineHeight:15},routeRow:{flexDirection:"row",alignItems:"center",minHeight:58,paddingHorizontal:o.textInset,paddingVertical:9,gap:12},routeText:{flex:1,minWidth:0,gap:2},routeTitle:{color:o.color.label,fontSize:o.font.row,fontWeight:"600",letterSpacing:o.tracking.row},routeHref:{color:o.color.labelSecondary,fontFamily:ht,fontSize:o.font.mono},sourceCard:{flexDirection:"row",alignItems:"center",minHeight:58,paddingHorizontal:o.textInset,paddingVertical:9,gap:12},sourceCardTouch:{flex:1,flexDirection:"row",alignItems:"center",gap:12,minWidth:0},sourceNameBlock:{flex:1,minWidth:0,gap:2},sourceName:{color:o.color.label,fontSize:o.font.row,fontWeight:"600",letterSpacing:o.tracking.row},sourceSummary:{color:o.color.labelSecondary,fontSize:o.font.footnote,fontVariant:["tabular-nums"]},sourceBadges:{flexDirection:"row",gap:6},noteRow:{color:o.color.labelTertiary,fontSize:o.font.footnote,lineHeight:o.font.footnote*1.35,paddingHorizontal:o.textInset,paddingVertical:9},itemRow:{flexDirection:"row",alignItems:"center",paddingLeft:o.textInset,paddingRight:o.textInset,paddingVertical:10,gap:12},itemBodyTouch:{flex:1,flexDirection:"row",alignItems:"center",gap:10,minWidth:0},itemGlyph:{fontSize:14,fontWeight:"700",width:14,textAlign:"center"},itemBody:{flex:1,minWidth:0},itemLabel:{color:o.color.label,fontSize:o.font.control,letterSpacing:o.tracking.control},itemPreview:{color:o.color.labelSecondary,fontFamily:ht,fontSize:o.font.mono,marginTop:3},itemPreviewRemoved:{textDecorationLine:"line-through"},itemReason:{color:o.color.warning,fontSize:o.font.mono,marginTop:3},itemExcluded:{color:o.color.labelTertiary,fontSize:o.font.mono,marginTop:3,fontStyle:"italic"},buildingSpinner:{marginTop:28},emptyText:{color:o.color.labelSecondary,fontSize:o.font.footnote,textAlign:"center",marginTop:28},footer:{paddingHorizontal:o.gutter,paddingTop:10,gap:8,borderTopColor:o.color.separator,borderTopWidth:A.hairlineWidth,backgroundColor:o.color.sheet},cta:{flexDirection:"row",alignItems:"center",justifyContent:"center",gap:8,height:50,backgroundColor:o.color.accent,borderRadius:o.radius.group},ctaDanger:{backgroundColor:o.color.danger},ctaTextDanger:{color:o.color.onDanger},ctaDisabled:{opacity:.4},ctaText:{color:o.color.onAccent,fontSize:o.font.row,fontWeight:"600",letterSpacing:o.tracking.row},ctaCaption:{color:o.color.labelSecondary,fontSize:o.font.footnote,lineHeight:o.font.footnote*1.35,textAlign:"center"}});import{jsx as ss}from"react/jsx-runtime";function ls(e,t){return e==="current"?void 0:t.find(r=>r.id===e.snapshotId)}function cs({preview:e,snapshots:t,busy:r,onClose:i}){let n=ls(e.right,t);return ss(is,{preview:e,snapshots:t,busy:r,onBack:i,onRestore:(a,s)=>{if(!(!n||r)){if(n.baseline){Mt("Restore fresh install?","This wipes all app storage and reloads the app.","Wipe & reload",()=>void S.restore(n.id,"reload"));return}S.restore(n.id,a,s).then(i)}}})}import{jsx as M,jsxs as Ge}from"react/jsx-runtime";var Lo=()=>Zn().some(e=>e.id===nr);function pr(){let[e,t]=Pr({kind:"list"}),{snapshots:r,busy:i,preview:n}=pt(),a=Ni(),s=()=>{S.clearPreview(),t({kind:"list"})};return e.kind==="preview"&&n?M(cs,{preview:n,snapshots:r,busy:i!==null,onClose:s}):M(ds,{sources:a,onOpenPreview:h=>{S.buildPreview({snapshotId:h.id}),t({kind:"preview"})}})}function ds({sources:e,onOpenPreview:t}){let{snapshots:r,hasLoaded:i,busy:n,lastOutcome:a,recentlyDeleted:s,remoteProviders:h}=pt(),p=Xn("timeMachine.snapshots"),y=ti(),c=Gn({minBottom:16}),I=Er(ei,Lo,Lo),L=Er(co,St,St),b=I?uo(r,L)?.id:void 0,O=Yn({}),[W,j]=Pr(null),w=z=>{j(null),ar(z),y.minimize()},U=y.search.trim().toLowerCase(),ee=U?r.filter(z=>z.name.toLowerCase().includes(U)):r,Y=r.filter(z=>!z.safety).length>=p,Le=n!==null||Y,te=z=>{if(n)return;if(z.baseline){Mt("Restore fresh install?","This wipes all app storage and reloads the app.","Wipe & reload",()=>void S.restore(z.id,"reload"));return}let ne=(O.current[z.id]??0)+1;O.current[z.id]=ne,ne>=2&&!I&&j(z.id),S.restore(z.id,"live").then(he=>{!Object.values(he.results).every(De=>De.ok)||he.willReload||y.minimize()})},K=W&&!I?r.find(z=>z.id===W)??null:null;return Ge(Pt,{style:Xe.fill,contentContainerStyle:[Xe.content,{paddingBottom:c.bottom}],testID:"time-machine-scroll",keyboardShouldPersistTaps:"handled",children:[a&&Jr(a)?M(Ui,{outcome:a}):null,s?M(oa,{name:s.stored.meta.name,at:s.at,onUndo:()=>void S.undoDelete(),onExpire:()=>S.clearRecentlyDeleted()}):null,M(u,{children:M(Ki,{disabled:Le,busy:n==="capture",onCapture:z=>void S.capture(z)})}),Y?Ge(Ve,{tone:"warning",testID:"time-machine-limit",children:["Free plan keeps ",p," restore point",p===1?"":"s",". Upgrade to Pro for unlimited snapshots."]}):null,M(mt,{children:"Sources"}),M(ca,{sources:e,onToggle:h?void 0:Vr}),h?null:M(Ve,{testID:"time-machine-sources-hint",children:"Switch a source off to leave it out of every capture and restore."}),M(mt,{children:"Restore Points"}),K?Ge(u,{style:Xe.barHint,testID:"time-machine-bar-hint",children:[Ge(Ve,{children:['Restoring "',K.name,'" a lot? Put it on the floating action bar and restore it with one tap.']}),M(P,{onPress:()=>w(K.id),accessibilityRole:"button",testID:"time-machine-bar-hint-pin",hitSlop:{top:6,bottom:6,left:6,right:6},children:M(d,{style:Xe.barHintAction,children:"Open the action bar"})})]}):null,Ge(ft,{children:[ee.map(z=>M(ea,{meta:z,busy:n!==null,armed:z.id===b,onOpen:()=>t(z),onRestore:()=>te(z),onDelete:()=>void S.delete(z.id),onDuplicate:()=>void S.duplicate(z.id),onArm:()=>w(z.id)},z.id)),ee.length===0?M(Qn,{testID:"time-machine-empty",...i?r.length>0?{otto:"sad",title:"No restore point matches that name.",message:`Clear the search to see all ${r.length}.`}:{otto:"rewind",title:"No restore points yet",message:"Set up the state you want to come back to, then capture it."}:{otto:"loading",title:"Loading restore points\u2026",message:"Reading the vault off disk."}}):null]}),ee.length>0?M(Ve,{testID:"time-machine-swipe-hint",children:"Swipe a restore point to copy or delete it."}):null,M(u,{style:Xe.spacer}),M(ft,{children:M(da,{disabled:n!==null,onWipe:()=>Mt("Wipe all app state?","This deletes all app storage and reloads the app \u2014 like a fresh install.","Wipe & reload",()=>void S.wipeAll())})}),M(Ve,{centered:true,children:"Deletes all app storage and reloads \u2014 like a fresh install."})]})}var Xe=A.create({barHint:{marginHorizontal:o.gutter,marginBottom:8},barHintAction:{color:o.color.accent,fontSize:o.font.footnote,fontWeight:"600",paddingHorizontal:o.textInset,paddingTop:2},fill:{flex:1,backgroundColor:"transparent"},content:{paddingTop:14},empty:{color:o.color.labelSecondary,fontSize:o.font.footnote,lineHeight:o.font.footnote*1.4,paddingHorizontal:o.textInset,paddingVertical:16},spacer:{height:24}});import{jsx as Po}from"react/jsx-runtime";var Dt={id:"time-machine",name:"TIME MACHINE",description:"Snapshot & restore app state (storage, stores, query cache)",slot:"both",icon:({size:e,color:t,slot:r})=>Po(Jn,{size:r==="dial"&&it.OS!=="web"?e*1.5:e,color:t||Un}),component:pr,modal:{subtitle:"snapshot & restore app state",searchable:true,searchPlaceholder:"Filter\u2026",headerActions:Po(Ro,{})}};function us(e={}){return{...Dt,name:e.name??Dt.name,description:e.description??Dt.description}}import{JsModal as ps}from"@buoy-gg/shared-ui/web";import{jsx as $e,jsxs as hs}from"react/jsx-runtime";function ms(){return hs(u,{style:hr.header,children:[$e(d,{style:hr.headerTitle,children:"Time Machine"}),$e(d,{style:hr.headerSubtitle,children:"Snapshot & restore app state"})]})}function fs({visible:e,onClose:t,onBack:r,onMinimize:i,persistenceKey:n}){return $e(ps,{visible:e,onClose:t,onMinimize:i,persistenceKey:n,header:{showToggleButton:true,customContent:$e(ms,{})},enablePersistence:true,initialMode:"bottomSheet",disableScrollWrapper:true,children:$e(pr,{})})}function gs(){return $e(pr,{})}var hr=A.create({header:{paddingHorizontal:4,gap:2},headerTitle:{color:o.color.label,fontSize:22,fontWeight:"700",letterSpacing:.3},headerSubtitle:{color:o.color.labelSecondary,fontSize:o.font.footnote}});import{getStateSnapshotProviders as ys,subscribeToStateSnapshotProviders as bs,superJsonDeserialize as ws}from"@buoy-gg/shared-ui/web";import{jsonLikelyLargerThan as Eo}from"@buoy-gg/shared-ui/web/dataViewer";function vs(){return ys().map(e=>{let t=e.status();return{id:e.id,label:e.label,canCapture:t.canCapture,canRestore:t.canRestore,detail:t.detail,enabled:se(e.id)}})}function Ao(){let{snapshots:e,busy:t,lastOutcome:r}=S.getState(),i=_o();return{snapshots:e,busy:t,lastOutcome:r,providers:vs(),route:{available:Oe(),enabled:se(je),...i?{current:i.href}:{}}}}var Ss={version:2,getSnapshot:()=>Ao(),subscribe:e=>{let t=S.subscribe(e),r=bs(e);return()=>{t(),r()}},actions:{list:()=>Ao(),capture:async e=>{let{name:t="",sourceIds:r}=e??{};return{captured:true,snapshot:await S.capture(t,r)}},captureBaseline:async()=>({captured:true,snapshot:await S.captureBaseline()}),wipeAll:async()=>await S.wipeAll(),restore:async e=>{let{id:t,mode:r="live",excludeKeys:i,restoreRoute:n}=e??{};if(!t)throw new Error("restore requires a snapshot `id`");return await S.restore(t,r,i,{restoreRoute:n})},delete:async e=>{let{id:t}=e??{};if(!t)throw new Error("delete requires a snapshot `id`");return await S.delete(t),{deleted:true,id:t}},rename:async e=>{let{id:t,name:r}=e??{};if(!t||!r)throw new Error("rename requires `id` and `name`");return await S.rename(t,r),{renamed:true,id:t,name:r}},setExclusions:async e=>{let{id:t,excludedKeys:r}=e??{};if(!t)throw new Error("setExclusions requires `id`");return await S.setExclusions(t,r??null),{id:t,excluded:r?.length??0}},setRestoreRoute:async e=>{let{id:t,restoreRoute:r}=e??{};if(!t)throw new Error("setRestoreRoute requires `id`");return await S.setRestoreRoute(t,r!==false),{id:t,restoreRoute:r!==false}},duplicate:async e=>{let{id:t}=e??{};if(!t)throw new Error("duplicate requires `id`");let r=await S.duplicate(t);if(!r)throw new Error(`No snapshot with id "${t}"`);return{snapshot:r}},setScope:async e=>{let{id:t,scope:r}=e??{};if(!t)throw new Error("setScope requires a snapshot `id`");return await S.setScope(t,r??null),{scoped:true,id:t,count:r?.length??0}},preview:async e=>{let{id:t,compareTo:r}=e??{};if(!t)throw new Error("preview requires a snapshot `id`");let i={snapshotId:t},n=r?{snapshotId:r}:"current";await S.buildPreview(i,n);let a=S.getState().preview;if(!a)throw new Error("preview build produced no result");let s=4*1024;return{left:n,right:i,builtAt:a.builtAt,sources:a.sources.map(h=>({...h,items:h.items.map(p=>{let y=p.oldValue!==void 0&&Eo(p.oldValue,s),c=p.newValue!==void 0&&Eo(p.newValue,s);return{...p,oldValue:y?void 0:p.oldValue,newValue:c?void 0:p.newValue,...y||c?{valueOmitted:true}:{}}})}))}},inspect:async e=>{let{id:t,sourceId:r}=e??{};if(!t||!r)throw new Error("inspect requires `id` and `sourceId`");let i=await fe(t);if(!i)throw new Error(`No snapshot with id "${t}"`);let n=i.data[r];if(!n)throw new Error(`Snapshot "${t}" has no "${r}" source`);return{id:t,sourceId:r,warnings:i.meta.sources[r]?.warnings??[],data:ws(n)}}}};vr();export{Ne as RESTORE_ORDER,jt as SAFETY_SNAPSHOT_NAME,nr as TIME_MACHINE_FLOATING_TOOL_ID,fs as TimeMachineModal,gs as TimeMachineToolView,vr as armPendingRouteRestore,Oe as canRestoreRoute,nt as captureCurrentRoute,us as createTimeMachineTool,se as isSourceEnabled,zt as navigateToRoute,ar as openTimeMachineFloatingTool,Ii as replaceTimeMachineFromSnapshot,xi as setRemoteTimeMachineHandler,Vr as setSourceEnabled,So as startTimeMachineFloatingToolPersistence,Nr as subscribeSourceSettings,S as timeMachineStore,Ss as timeMachineSyncAdapter,Dt as timeMachineToolPreset};
3
+ ${t}`)&&i();return}Or.alert(e,t,[{text:"Cancel",style:"cancel"},{text:r,style:"destructive",onPress:i}])}import{useState as Ui}from"react";import{jsx as _t,jsxs as Gi}from"react/jsx-runtime";function Yi({disabled:e,busy:t,onCapture:r}){let[i,n]=Ui(""),a=()=>{e||(r(i),n(""))};return Gi(h,{style:_e.bar,children:[_t(lt,{style:_e.input,value:i,onChangeText:n,placeholder:"Name this restore point\u2026",placeholderTextColor:o.color.labelTertiary,editable:!e,onSubmitEditing:a,returnKeyType:"done",testID:"time-machine-name-input"}),_t(E,{style:[_e.button,e?_e.buttonDisabled:null],onPress:a,disabled:e,accessibilityRole:"button",accessibilityLabel:"Capture restore point",testID:"time-machine-capture",children:_t(d,{style:_e.buttonText,children:t?"Capturing\u2026":"Capture"})})]})}var _e=P.create({bar:{flexDirection:"row",alignItems:"center",gap:8,marginHorizontal:o.gutter,backgroundColor:o.color.group,borderRadius:o.radius.group,borderWidth:1,borderColor:o.color.groupBorder,paddingLeft:o.textInset,padding:6},input:{flex:1,minWidth:0,color:o.color.label,fontSize:o.font.row,letterSpacing:o.tracking.row,padding:0,backgroundColor:"transparent"},button:{height:34,paddingHorizontal:16,borderRadius:o.radius.pill,backgroundColor:o.color.accent,alignItems:"center",justifyContent:"center"},buttonDisabled:{opacity:.4},buttonText:{color:o.color.onAccent,fontSize:o.font.control,fontWeight:"600",letterSpacing:o.tracking.control}});import{X as Qi}from"@buoy-gg/shared-ui/web";import{jsx as ye,jsxs as be}from"react/jsx-runtime";var Xi={top:10,bottom:10,left:10,right:10};function Qr(e){if(Object.values(e.results).some(r=>!r.ok||r.skipped.length>0))return true;let t=e.route;return t?.status==="failed"||t?.status==="unavailable"}function bt({glyph:e,text:t,ok:r,testID:i}){return be(d,{style:[we.line,{color:r?o.color.accent:o.color.warning}],numberOfLines:2,testID:i,children:[be(d,{style:we.glyph,children:[e," "]}),t]})}var qt="time-machine-outcome-route";function Zi({route:e}){return e.status==="navigated"?ye(bt,{glyph:"\u2713",ok:true,text:`route \u2014 ${e.href}`,testID:qt}):e.status==="deferred"?ye(bt,{glyph:"\u21BB",ok:true,text:`route \u2014 ${e.href} after reload`,testID:qt}):ye(bt,{glyph:"\u2715",ok:false,text:`route \u2014 ${e.error??e.status}`,testID:qt})}function ea({outcome:e}){let t=Object.entries(e.results),r=e.mode==="reload"||e.willReload;return be(h,{style:we.card,testID:"time-machine-outcome",children:[be(h,{style:we.headerRow,children:[be(d,{style:we.title,numberOfLines:1,testID:"time-machine-outcome-title",children:["Restored \u201C",e.snapshotName,"\u201D",r?" \xB7 reloading":""]}),ye(E,{onPress:()=>x.clearLastOutcome(),hitSlop:Xi,accessibilityRole:"button",accessibilityLabel:"Dismiss restore result",testID:"time-machine-outcome-dismiss",children:ye(Qi,{size:13,color:o.color.labelSecondary})})]}),t.length===0&&!e.route?ye(d,{style:we.empty,testID:"time-machine-outcome-empty",children:"No sources restored."}):null,e.route?ye(Zi,{route:e.route}):null,t.map(([i,n])=>be(h,{children:[ye(bt,{testID:`time-machine-outcome-${i}`,glyph:n.ok?"\u2713":"\u2715",ok:n.ok,text:`${i} \u2014 applied ${n.applied}${n.skipped.length>0?`, skipped ${n.skipped.length}`:""}`}),n.skipped.slice(0,3).map(a=>be(d,{style:we.detail,numberOfLines:2,children:[a.id,": ",a.reason]},a.id)),n.warnings.slice(0,3).map(a=>be(d,{style:we.detail,numberOfLines:2,children:["\u26A0 ",a]},a))]},i))]})}var we=P.create({card:{marginHorizontal:o.gutter,marginTop:12,backgroundColor:o.color.group,borderRadius:o.radius.group,borderWidth:1,borderColor:o.color.groupBorder,padding:14,gap:4},headerRow:{flexDirection:"row",alignItems:"center",gap:10,marginBottom:2},title:{flex:1,color:o.color.label,fontSize:15,fontWeight:"600",letterSpacing:o.tracking.control},line:{fontSize:o.font.footnote,lineHeight:o.font.footnote*1.4},glyph:{fontWeight:"700"},detail:{color:o.color.labelTertiary,fontSize:o.font.mono,lineHeight:o.font.mono*1.4,paddingLeft:14},empty:{color:o.color.labelSecondary,fontSize:o.font.footnote}});import{useEffect as ta,useRef as Xr}from"react";import{jsx as wt,jsxs as ra}from"react/jsx-runtime";var Zr=84,eo=8,ve=null;function oa(e,t){let r=false,i=a=>{r=a,a?(ve&&ve!==n&&ve(),ve=n):ve===n&&(ve=null),We.spring(e,{toValue:a?-t:0,useNativeDriver:true,bounciness:0,speed:18}).start()},n=()=>i(false);return{pan:kr.create({onMoveShouldSetPanResponder:(a,s)=>Math.abs(s.dx)>Math.abs(s.dy)*1.5?s.dx<-eo||r&&s.dx>eo:false,onPanResponderMove:(a,s)=>{let f=r?-t:0;e.setValue(Math.min(0,Math.max(-t,f+s.dx)))},onPanResponderRelease:(a,s)=>{let f=(r?-t:0)+s.dx;i(s.vx<-.5?true:s.vx>.5?false:f<-t/2)},onPanResponderTerminate:()=>i(r)}),close:n}}function na({children:e,actions:t,testID:r}){let i=Zr*t.length,n=Xr(new We.Value(0)).current,a=Xr(null);a.current===null&&(a.current=oa(n,i));let{pan:s,close:f}=a.current;ta(()=>()=>{ve===f&&(ve=null)},[f]);let u=n.interpolate({inputRange:[-24,0],outputRange:[1,0],extrapolate:"clamp"});return ra(h,{style:qe.clip,children:[wt(We.View,{style:[qe.actionLayer,{width:i,opacity:u}],children:t.map(g=>wt(E,{style:[qe.action,g.background?{backgroundColor:g.background}:null],onPress:()=>{f(),g.onPress()},accessibilityLabel:g.label,testID:g.testID??(r?`${r}-${g.label.toLowerCase()}`:void 0),children:wt(d,{style:[qe.actionText,g.color?{color:g.color}:null],numberOfLines:1,children:g.label})},g.label))}),wt(We.View,{style:[qe.content,{transform:[{translateX:n}]}],...s.panHandlers,children:e})]})}var qe=P.create({clip:{overflow:"hidden"},actionLayer:{position:"absolute",top:0,bottom:0,right:0,flexDirection:"row"},action:{width:Zr,height:"100%",backgroundColor:o.color.fillStrong,alignItems:"center",justifyContent:"center",paddingHorizontal:6},actionText:{color:o.color.label,fontSize:o.font.footnote,fontWeight:"600",letterSpacing:o.tracking.control},content:{backgroundColor:o.color.group}});function Je(e){let t=Math.max(0,Math.round((Date.now()-e)/1e3));if(t<60)return`${t}s ago`;let r=Math.round(t/60);if(r<60)return`${r}m ago`;let i=Math.round(r/60);return i<24?`${i}h ago`:`${Math.round(i/24)}d ago`}function ia(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}import{jsx as Re,jsxs as Jt}from"react/jsx-runtime";function to(e){if(e.baseline)return"Wipes to fresh install";let t=[Je(e.createdAt),ia(e.sizeBytes),`${Object.keys(e.sources).length} sources`];return e.excludedKeys?.length?t.push(`skips ${e.excludedKeys.length}`):e.scope?.length&&t.push(`scoped (${e.scope.length})`),e.safety&&t.unshift("safety copy"),t.join(" \xB7 ")}function aa({meta:e,busy:t,armed:r=false,onOpen:i,onRestore:n,onDelete:a,onDuplicate:s,onArm:f}){let u=`time-machine-snap-${e.id}`;return Re(na,{testID:u,actions:[{label:"Bar",onPress:f},{label:"Dup",onPress:s},{label:"Delete",onPress:a,background:o.color.danger,color:o.color.onDanger}],children:Jt(h,{style:de.row,children:[Jt(E,{style:de.text,onPress:i,activeOpacity:.7,accessibilityRole:"button",accessibilityLabel:`${e.name}. ${to(e)}. Open restore preview`,testID:u,children:[Re(d,{style:de.name,numberOfLines:1,testID:`${u}-name`,children:e.name}),r?Re(d,{style:de.armed,numberOfLines:1,testID:`${u}-armed`,children:"On the action bar"}):null,Re(d,{style:de.meta,numberOfLines:1,testID:`${u}-meta`,children:to(e)}),e.lastRestoredAt?Jt(d,{style:de.restored,numberOfLines:1,testID:`${u}-restored`,children:["Restored ",Je(e.lastRestoredAt)]}):null,e.route?Re(d,{style:de.route,numberOfLines:1,testID:`${u}-route`,children:e.route.href}):null]}),Re(E,{onPress:n,disabled:t,style:[de.restore,t?de.actionDisabled:null],accessibilityRole:"button",accessibilityLabel:e.baseline?"Wipe and reload":"Restore",testID:`${u}-restore`,children:Re(Oi,{testID:`${u}-restore-label`,label:e.baseline?"Wipe":"Restore",color:e.baseline?o.color.danger:o.color.accent,background:e.baseline?o.color.dangerSoft:o.color.accentSoft})})]})})}var de=P.create({row:{flexDirection:"row",alignItems:"center",gap:10,paddingHorizontal:o.textInset},text:{flex:1,minWidth:0,paddingVertical:11},restore:{justifyContent:"center"},name:{color:o.color.label,fontSize:o.font.row,fontWeight:"600",letterSpacing:o.tracking.row},meta:{color:o.color.labelSecondary,fontSize:o.font.footnote,marginTop:2,fontVariant:["tabular-nums"]},restored:{color:o.color.accent,fontSize:o.font.footnote,marginTop:2},armed:{color:o.color.accent,fontSize:o.font.footnote,marginTop:2},route:{color:o.color.labelTertiary,fontFamily:ft,fontSize:o.font.mono,marginTop:4},actionDisabled:{opacity:.4}});import{useEffect as sa}from"react";import{jsx as ro,jsxs as oo}from"react/jsx-runtime";var la=8e3;function ca({name:e,at:t,onUndo:r,onExpire:i}){return sa(()=>{let n=setTimeout(i,la);return()=>clearTimeout(n)},[t]),oo(h,{style:Ut.bar,testID:"time-machine-undo-bar",children:[oo(d,{style:Ut.text,numberOfLines:1,testID:"time-machine-undo-text",children:["Deleted \u201C",e,"\u201D"]}),ro(E,{onPress:r,hitSlop:{top:10,bottom:10,left:10,right:10},accessibilityRole:"button",testID:"time-machine-undo-delete",children:ro(d,{style:Ut.undo,children:"Undo"})})]})}var Ut=P.create({bar:{flexDirection:"row",alignItems:"center",gap:12,marginHorizontal:o.gutter,marginTop:12,minHeight:46,paddingHorizontal:o.textInset,backgroundColor:o.color.group,borderRadius:o.radius.group,borderWidth:1,borderColor:o.color.groupBorder},text:{flex:1,color:o.color.labelSecondary,fontSize:o.font.control,letterSpacing:o.tracking.control},undo:{color:o.color.accent,fontSize:o.font.control,fontWeight:"600",letterSpacing:o.tracking.control}});import{NightSwitch as da}from"@buoy-gg/shared-ui/web";import{jsx as le,jsxs as Gt}from"react/jsx-runtime";var ua={storage:"Settings, sign-in and other things saved on the device",redux:"Data the whole app shares between screens",zustand:"Data the whole app shares between screens",jotai:"Small pieces of data screens share",query:"Data the app loaded from the server",route:"Which screen you were on"};function ha(e){return ua[e.id]??"App data"}function pa(e){return e.enabled?e.canRestore?null:{text:"Can be saved but not put back",tone:"warn"}:{text:"Off \xB7 left as it is",tone:"off"}}function ma({source:e,onToggle:t}){let r=_i(e.id),i=ha(e),n=pa(e);return Gt(h,{style:ue.row,testID:`time-machine-source-${e.id}`,accessibilityLabel:`${e.label}: ${i}${n?`. ${n.text}`:""}`,children:[le(h,{style:ue.disc,children:le(r,{size:22,bgColor:o.color.disc})}),Gt(h,{style:ue.text,children:[le(d,{style:ue.label,numberOfLines:1,testID:`time-machine-source-${e.id}-label`,children:e.label}),le(d,{style:ue.description,numberOfLines:2,testID:`time-machine-source-${e.id}-description`,children:i}),n?le(d,{style:[ue.state,ue[`state_${n.tone}`]],numberOfLines:1,testID:n.tone==="off"?`time-machine-source-${e.id}-off`:`time-machine-source-${e.id}-detail`,children:n.text}):null]}),le(h,{testID:`time-machine-source-${e.id}-switch`,children:le(da,{value:e.enabled,disabled:!t,onValueChange:a=>t?.(e.id,a)})})]})}function fa({sources:e,onToggle:t}){let r=e.filter(i=>i.canCapture);return Gt(yt,{children:[r.map(i=>le(ma,{source:i,onToggle:t},i.id)),r.length===0?le(h,{style:ue.row,testID:"time-machine-sources-empty",children:le(d,{style:ue.description,children:"No state tools are set up in this app."})}):null]})}var ue=P.create({row:{flexDirection:"row",alignItems:"center",gap:12,minHeight:o.rowMinHeight,paddingHorizontal:o.textInset,paddingVertical:10},disc:{width:36,height:36,borderRadius:o.radius.pill,backgroundColor:o.color.disc,alignItems:"center",justifyContent:"center"},text:{flex:1,minWidth:0,gap:2},label:{color:o.color.label,fontSize:o.font.row,fontWeight:"500",letterSpacing:o.tracking.row},description:{fontSize:o.font.footnote,lineHeight:o.font.footnote*1.3,color:o.color.labelSecondary},state:{fontSize:o.font.mono,lineHeight:o.font.mono*1.3,fontWeight:"600",marginTop:1},state_off:{color:o.color.labelTertiary},state_warn:{color:o.color.warning}});import{jsx as no}from"react/jsx-runtime";function ga({disabled:e,onWipe:t}){return no(E,{style:[Yt.row,e?Yt.disabled:null],onPress:t,disabled:e,accessibilityRole:"button",testID:"time-machine-wipe-all",children:no(d,{style:Yt.label,children:"Wipe All App State\u2026"})})}var Yt=P.create({row:{minHeight:o.rowMinHeight,alignItems:"center",justifyContent:"center"},disabled:{opacity:.4},label:{color:o.color.danger,fontSize:o.font.row,letterSpacing:o.tracking.row}});import{memo as ya,useCallback as ke,useEffect as io,useMemo as vt,useRef as Qt,useState as Xt}from"react";import{ChevronUp as ao,AlertTriangle as ba,RefreshCw as wa,useSafeAreaInsets as va}from"@buoy-gg/shared-ui/web";import{useToolHeader as Sa,useToolHost as xa}from"@buoy-gg/core/web";import{night as St}from"@buoy-gg/shared-ui/web";import{useToolHost as Ia}from"@buoy-gg/core/web";import{night as Zt,scheduleReloadApp as Ra}from"@buoy-gg/shared-ui/web";import{jsx as so}from"react/jsx-runtime";function ka(){let e=()=>{try{Ra({reason:"buoy time-machine reload app"})}catch{}};return so(E,{style:lo.chip,onPress:e,accessibilityLabel:"Reload app",accessibilityHint:"Reloads the JavaScript bundle without restoring anything",accessibilityRole:"button",testID:"time-machine-reload-app",children:so(d,{style:lo.label,children:"Reload app"})})}var lo=P.create({chip:{height:32,paddingHorizontal:10,borderRadius:8,borderWidth:1,borderColor:Zt.color.border,backgroundColor:Zt.color.buttonSurface,alignItems:"center",justifyContent:"center"},label:{fontSize:11,fontWeight:"700",color:Zt.color.textSecondary}});import{useEffect as xt,useRef as Da,useState as Se,useSyncExternalStore as co}from"react";import{Check as uo,ChevronDown as Ta,ChevronUp as Ca,FloatingTool as za,NightSwitch as $a,Plus as La,TimeMachineIcon as Ea,X as Aa,night as T,openFloatingTool as Pa,persistentStorage as Oa,registerPersistentFloatingTool as Ha,useLimit as Ba}from"@buoy-gg/shared-ui/web";import{devToolsStorageKeys as ja,persistentStorage as er}from"@buoy-gg/shared-ui/web";var tr=ja.timeMachine.armedPoint(),Ue=null,ho=false,rr=null,or=new Set,po=()=>or.forEach(e=>e());function It(){return Ue}function mo(e){return or.add(e),()=>{or.delete(e)}}function Wa(){return ho?Promise.resolve():(rr||(rr=er.getItem(tr).then(e=>{Ue===null&&e&&(Ue=e,po())}).catch(()=>{}).finally(()=>{ho=true})),rr)}function nr(e){Ue!==e&&(Ue=e,po(),(e===null?er.removeItem(tr):er.setItem(tr,e)).catch(()=>{}))}function fo(e,t){let r=e.filter(n=>!n.baseline&&!n.safety);if(r.length===0)return null;if(t){let n=r.find(a=>a.id===t);if(n)return n}let i=null;for(let n of r)n.lastRestoredAt!==void 0&&(!i||n.lastRestoredAt>(i.lastRestoredAt??0))&&(i=n);return i||r.reduce((n,a)=>a.createdAt>n.createdAt?a:n)}import{useEffect as Na,useState as Ma}from"react";import{night as H}from"@buoy-gg/shared-ui/web";import{jsx as oe,jsxs as go}from"react/jsx-runtime";function Va({visible:e,summary:t,onCapture:r,onCancel:i}){let[n,a]=Ma("");Na(()=>{e&&a("")},[e]);let s=()=>r(n.trim());return oe(Pr,{visible:e,transparent:true,animationType:"fade",onRequestClose:i,statusBarTranslucent:true,children:oe(Tr,{behavior:st.OS==="ios"?"padding":void 0,style:Z.fill,children:oe(Pt,{style:Z.backdrop,onPress:i,accessibilityLabel:"Cancel",testID:"time-machine-bar-name-backdrop",children:go(Pt,{style:Z.card,onPress:f=>f.stopPropagation(),testID:"time-machine-bar-name-panel",accessible:false,children:[oe(d,{style:Z.title,children:"Name this restore point"}),t?oe(d,{style:Z.summary,testID:"time-machine-bar-name-summary",children:t}):null,oe(lt,{testID:"time-machine-bar-name-input",accessibilityLabel:"Restore point name",value:n,onChangeText:a,onSubmitEditing:s,placeholder:"Screen and time, if left empty",placeholderTextColor:H.color.placeholder,autoFocus:true,autoCorrect:false,autoCapitalize:"none",returnKeyType:"done",style:Z.input}),oe(d,{style:Z.hint,children:"Captures the state the app is in right now and arms it on the bar."}),go(h,{style:Z.actions,children:[oe(E,{testID:"time-machine-bar-name-cancel",accessibilityRole:"button",onPress:i,style:Z.secondary,children:oe(d,{style:Z.secondaryText,children:"Cancel"})}),oe(E,{testID:"time-machine-bar-name-capture",accessibilityRole:"button",accessibilityLabel:"Capture and arm this restore point",onPress:s,style:Z.primary,children:oe(d,{style:Z.primaryText,children:"Capture"})})]})]})})})})}var Z=P.create({fill:{flex:1},backdrop:{flex:1,backgroundColor:"rgba(0, 0, 0, 0.55)",alignItems:"center",justifyContent:"center",padding:24},card:{width:"100%",maxWidth:360,borderRadius:H.radius.sheet,borderWidth:1,borderColor:H.color.separator,backgroundColor:H.color.surface,padding:18,gap:12,shadowColor:"#000",shadowOffset:{width:0,height:12},shadowOpacity:.4,shadowRadius:24,elevation:12},title:{color:H.color.text,fontSize:H.font.title,fontWeight:"600"},input:{minHeight:44,borderRadius:H.radius.input,borderWidth:1,borderColor:H.color.accentBorder,backgroundColor:H.color.surfaceElevated,color:H.color.text,fontSize:H.font.row,paddingHorizontal:12},summary:{color:H.color.textTertiary,fontSize:H.font.caption,marginTop:-6},hint:{color:H.color.textSecondary,fontSize:H.font.caption,lineHeight:18},actions:{flexDirection:"row",justifyContent:"flex-end",gap:10,marginTop:4},secondary:{minHeight:40,paddingHorizontal:14,borderRadius:H.radius.input,alignItems:"center",justifyContent:"center"},secondaryText:{color:H.color.textSecondary,fontSize:14,fontWeight:"600"},primary:{minHeight:40,paddingHorizontal:18,borderRadius:H.radius.input,backgroundColor:H.color.accent,alignItems:"center",justifyContent:"center"},primaryText:{color:H.color.onAccent,fontSize:14,fontWeight:"700"}});import{devToolsStorageKeys as Fa,persistentStorage as yo}from"@buoy-gg/shared-ui/web";var bo=Fa.timeMachine.barReloadMode(),Ge=false,wo=false,ir=null,ar=new Set,vo=()=>ar.forEach(e=>e());function So(){return Ge}function Ka(e){return ar.add(e),()=>{ar.delete(e)}}function _a(){return wo?Promise.resolve():(ir||(ir=yo.getItem(bo).then(e=>{!Ge&&e==="1"&&(Ge=true,vo())}).catch(()=>{}).finally(()=>{wo=true})),ir)}function qa(e){e!==Ge&&(Ge=e,vo(),yo.setItem(bo,e?"1":"0").catch(()=>{}))}import{Fragment as Ja,jsx as k,jsxs as F}from"react/jsx-runtime";var sr="time-machine-restore",Rt=1e4,xo=900,lr=6,Io={id:sr,render:e=>k(Ya,{...e})},Ro=false;function ko(){Ro||(Ro=true,Ha(Io,Oa))}typeof vr<"u"&&vr&&typeof navigator<"u"&&navigator.product==="ReactNative"&&ko();function cr(e){e&&nr(e),Pa(Io)}function Ua(e){let t=Object.values(e.results),r=t.filter(s=>!s.ok||s.skipped.length>0).length,i=t.length,n=e.route,a=n?.status==="failed"||n?.status==="unavailable";return r===0&&a?"Route did not restore":`${r} of ${i} source${i===1?"":"s"} failed`}function Ga(e){let t=[];for(let[i,n]of Object.entries(e.results)){if(n.ok&&n.skipped.length===0)continue;let a=n.skipped[0]?.reason??n.warnings[0]??"did not apply";t.push(`${i}: ${a}`)}let r=e.route;return(r?.status==="failed"||r?.status==="unavailable")&&t.push(`route: ${r.status}`),t}function Do(e){let[t,r]=Se(0);return xt(()=>{if(!t)return;let i=setTimeout(()=>r(0),e);return()=>clearTimeout(i)},[t,e]),[t>0,()=>r(i=>i+1)]}function Ya({id:e,revealToken:t,dismiss:r}){let{snapshots:i,hasLoaded:n,busy:a}=mt(),s=Gr(),f=co(mo,It,It),u=Ba("timeMachine.snapshots"),g=co(Ka,So,So),{width:l}=Cr(),[p,z]=Se(null),[m,O]=Se(null),[j,W]=Se(),[v,U]=Se(false),[ee,G]=Do(xo),[Ae,te]=Do(xo),[K,$]=Se(null),[ne,pe]=Se(null),[,De]=Se(0),ie=Da(true);xt(()=>(ie.current=true,Wa(),_a(),x.ensureLoaded(),()=>{ie.current=false}),[]);let D=fo(i,f),et=D?.id,Pe=D?.lastRestoredAt,tt=D?.createdAt;xt(()=>{if(Pe===void 0&&tt===void 0&&!K&&ne===null)return;let b=setInterval(()=>De(V=>V+1),2500);return()=>clearInterval(b)},[Pe,tt,K,ne]),xt(()=>{m&&m.snapshotId!==et&&(O(null),z(b=>b==="outcome"?null:b))},[et,m]);let Te=Date.now(),rt=K!==null&&Te-K.at<Rt&&i.some(b=>b.id===K.id),Oe=i.filter(b=>!b.safety).length>=u,c=!D||a!==null,S=a!==null,C=async(b,V)=>{if(!a){z(null),W(void 0);try{let Q=await x.restore(b,g&&V.safetyCapture?"reload":"live",void 0,V);if(!ie.current)return;Qr(Q)?(O(Q),z("outcome")):(O(null),G()),$(Q.safetySnapshotId?{id:Q.safetySnapshotId,at:Date.now()}:null),Q.safetySnapshotId&&pe(null)}catch(Q){if(!ie.current)return;W(Q instanceof Error?Q.message:String(Q)),z("error")}}},R=(b=false)=>{D&&C(D.id,{safetyCapture:true,...b?{restoreRoute:false}:{}})},_=()=>{K&&C(K.id,{safetyCapture:false,restoreRoute:false}).then(()=>{ie.current&&pe(Date.now())})},re=()=>{if(!a){if(W(void 0),Oe){z("cap");return}z(null),U(true)}},Y=async b=>{if(U(false),!a)try{let V=await x.capture(b);if(!ie.current)return;nr(V.id),$(null),te()}catch(V){if(!ie.current)return;W(V instanceof Error?V.message:String(V)),z("error")}},He=b=>{nr(b.id),z(null)},ot=D?.name??(n?"No restore points":"Loading\u2026"),q,Ce="normal",nt=false;if(a==="restore")q="Restoring\u2026";else if(a==="capture")q="Capturing\u2026";else if(j)q=j,Ce="danger";else if(m&&D&&m.snapshotId===D.id)q=Ua(m),Ce="danger";else if(!D)q=n?"Capture one with +":"";else{nt=true;let b=D.lastRestoredAt===void 0?null:Te-D.lastRestoredAt,V=Te-D.createdAt;ne!==null&&Te-ne<Rt?q="undone, state only":b!==null&&b<Rt?q="restored just now":V<Rt&&b===null?q="captured just now":D.lastRestoredAt!==void 0?q=`restored ${Je(D.lastRestoredAt)}`:q=`${Object.keys(D.sources).length} sources`,g&&(q+=" \xB7 reloads")}let ce=nt&&!rt&&D&&D.route&&pt(D)?D.route.pathname:null,ze=i.filter(b=>!b.baseline&&!b.safety),it=(()=>{let b=s.filter(yr=>yr.status().canCapture&&se(yr.id)).length,V=at(),Q=[`${b} source${b===1?"":"s"}`];return V&&Q.push(V.pathname),Q.join(" \xB7 ")})(),L;return p==="picker"?L=F(h,{style:I.menu,testID:"time-machine-bar-picker",children:[F(Ot,{style:I.pickerList,bounces:false,children:[ze.map(b=>{let V=b.id===D?.id;return F(E,{testID:`time-machine-bar-pick-${b.id}`,accessibilityRole:"button",accessibilityState:{selected:V},accessibilityLabel:`Arm ${b.name}`,onPress:()=>He(b),style:I.pickRow,children:[F(h,{style:I.pickText,children:[k(d,{numberOfLines:1,style:I.pickName,children:b.name}),F(d,{numberOfLines:1,style:I.pickDetail,children:[Je(b.createdAt),b.route?` \xB7 ${b.route.pathname}`:"",b.lastRestoredAt!==void 0?k(d,{style:I.pickRestored,children:` \xB7 restored ${Je(b.lastRestoredAt)}`}):null]})]}),V?k(uo,{size:14,color:T.color.accent}):null]},b.id)}),ze.length===0?k(d,{style:I.menuText,children:"No restore points yet."}):null]}),ze.length>lr?F(d,{style:I.pickerMore,children:["Scroll for ",ze.length-lr," more"]}):null,F(h,{style:I.settingRow,testID:"time-machine-bar-reload-mode",children:[F(h,{style:I.settingText,children:[k(d,{style:I.settingLabel,children:"Reload the app after restoring"}),k(d,{style:I.settingHint,children:"For screens that read their state from storage only when they open, like a cart kept in a React context."})]}),k($a,{value:g,onValueChange:qa,testID:"time-machine-bar-reload-switch",accessibilityLabel:"Reload the app after restoring"})]})]}):p==="outcome"&&m?L=F(h,{style:I.menu,testID:"time-machine-bar-outcome",children:[Ga(m).map(b=>k(d,{style:I.menuDanger,children:b},b)),k(d,{style:I.menuText,children:"The full report is on Time Machine's outcome card."}),k(dr,{onPress:()=>z(null)})]}):p==="cap"?L=F(h,{style:I.menu,testID:"time-machine-bar-cap",children:[F(d,{style:I.menuText,children:["Free plan keeps ",u," restore point",u===1?"":"s",". Delete one in Time Machine, or upgrade to Pro for unlimited snapshots."]}),k(dr,{onPress:()=>z(null)})]}):p==="error"&&j&&(L=F(h,{style:I.menu,testID:"time-machine-bar-error",children:[k(d,{accessibilityRole:"alert",style:I.menuDanger,children:j}),k(dr,{onPress:()=>{z(null),W(void 0)}})]})),F(Ja,{children:[k(Va,{visible:v,summary:it,onCapture:b=>void Y(b),onCancel:()=>U(false)}),k(za,{id:e,revealToken:t,variant:"strip",dragFromSurface:true,defaultPlacement:"bottom",accessibilityLabel:`Move or hide the action bar. ${D?`${D.name} armed`:"Nothing armed"}`,accessory:L,handleAdornment:k(Ea,{size:12,color:T.color.accent}),children:F(h,{style:[I.row,{width:Math.max(260,Math.min(320,l-64))}],children:[k(E,{testID:"time-machine-bar-restore",accessibilityRole:"button",accessibilityLabel:D?`Restore ${D.name}`:"Restore, nothing armed",accessibilityHint:ce?`Also returns to ${ce}. Long press to restore state only.`:void 0,accessibilityState:{disabled:c},disabled:c,onPress:()=>R(false),onLongPress:()=>R(true),style:[I.restoreButton,c&&I.disabled],children:a==="restore"?k(ct,{size:"small",color:T.color.accent}):ee?k(d,{style:I.restoreText,testID:"time-machine-bar-restored",children:"Restored"}):k(d,{style:I.restoreText,children:"Restore"})}),F(h,{style:I.identity,children:[k(d,{testID:"time-machine-bar-name",accessibilityLabel:`Armed restore point: ${ot}`,numberOfLines:1,ellipsizeMode:"middle",style:I.name,children:ot}),F(h,{style:I.statusRow,children:[F(d,{testID:"time-machine-bar-status",numberOfLines:1,accessibilityLiveRegion:"polite",style:[I.status,Ce==="danger"&&I.danger],children:[q,ce?k(d,{style:I.destination,children:` \xB7 \u2192 ${ce}`}):null]}),rt&&!a?k(E,{testID:"time-machine-bar-undo",accessibilityRole:"button",accessibilityLabel:"Undo the last restore",onPress:_,hitSlop:{top:8,bottom:8,left:6,right:6},children:k(d,{style:I.undo,children:"Undo"})}):null]})]}),k(E,{testID:"time-machine-bar-pick",accessibilityRole:"button",accessibilityLabel:"Choose another restore point",accessibilityState:{expanded:p==="picker"},onPress:()=>z(b=>b==="picker"?null:"picker"),style:I.smallButton,children:p==="picker"?k(Ca,{size:14,color:T.color.textSecondary}):k(Ta,{size:14,color:T.color.textSecondary})}),k(E,{testID:"time-machine-bar-capture",accessibilityRole:"button",accessibilityLabel:"Capture a new restore point here and arm it",accessibilityState:{disabled:S},disabled:S,onPress:re,style:[I.smallButton,S&&I.disabled],children:a==="capture"?k(ct,{size:"small",color:T.color.accent}):Ae?k(h,{testID:"time-machine-bar-captured",children:k(uo,{size:18,color:T.color.accent})}):k(La,{size:18,color:Oe?T.color.textTertiary:T.color.text})}),k(h,{style:I.separator}),k(E,{testID:"time-machine-bar-close",accessibilityRole:"button",accessibilityLabel:"Close the action bar",onPress:r,style:I.closeButton,children:k(Aa,{size:16,color:T.color.textSecondary})})]})})]})}function dr({onPress:e,label:t="Dismiss"}){return k(E,{testID:"time-machine-bar-dismiss",accessibilityRole:"button",onPress:e,style:I.dismiss,children:k(d,{style:I.dismissText,children:t})})}var I=P.create({row:{flexDirection:"row",alignItems:"center",gap:4,paddingVertical:4,minHeight:48},restoreButton:{height:32,minWidth:72,paddingHorizontal:12,borderRadius:8,borderWidth:1,borderColor:T.color.accentBorderStrong,backgroundColor:T.color.accentSoft,alignItems:"center",justifyContent:"center",marginLeft:2},restoreText:{color:T.color.accent,fontSize:12,fontWeight:"700"},smallButton:{width:32,minHeight:44,alignItems:"center",justifyContent:"center"},closeButton:{width:28,minHeight:44,alignItems:"center",justifyContent:"center"},identity:{flex:1,minHeight:44,justifyContent:"center",gap:1},name:{color:T.color.text,fontSize:13,fontWeight:"500"},statusRow:{flexDirection:"row",alignItems:"center",gap:8},status:{color:T.color.textSecondary,fontSize:10,lineHeight:14,flexShrink:1},destination:{color:T.color.textTertiary},danger:{color:T.color.danger},undo:{color:T.color.accent,fontSize:10,lineHeight:14,fontWeight:"700"},separator:{height:20,width:1,backgroundColor:T.color.separator,marginHorizontal:2},disabled:{opacity:.4},menu:{marginVertical:8,padding:6,borderRadius:T.radius.card,borderWidth:1,borderColor:T.color.separator,backgroundColor:T.color.surface,shadowColor:"#000",shadowOffset:{width:0,height:6},shadowOpacity:.25,shadowRadius:16,elevation:8},menuText:{color:T.color.textSecondary,fontSize:12,lineHeight:18,padding:10},menuDanger:{color:T.color.danger,fontSize:12,lineHeight:18,paddingHorizontal:10,paddingTop:6},pickerList:{maxHeight:lr*44},pickerMore:{color:T.color.textTertiary,fontSize:10,lineHeight:14,textAlign:"center",paddingVertical:4},pickRow:{flexDirection:"row",alignItems:"center",gap:8,minHeight:44,paddingHorizontal:10,borderRadius:T.radius.row},pickText:{flex:1},settingRow:{flexDirection:"row",alignItems:"center",gap:10,paddingHorizontal:10,paddingVertical:8,borderTopWidth:P.hairlineWidth,borderTopColor:T.color.separator,marginTop:4},settingText:{flex:1,gap:2},settingLabel:{color:T.color.text,fontSize:12,fontWeight:"500"},settingHint:{color:T.color.textTertiary,fontSize:10,lineHeight:13},pickName:{color:T.color.text,fontSize:13,fontWeight:"500"},pickDetail:{color:T.color.textSecondary,fontSize:10,lineHeight:14},pickRestored:{color:T.color.accent},dismiss:{alignSelf:"flex-end",paddingHorizontal:10,paddingVertical:8},dismissText:{color:T.color.accent,fontSize:12,fontWeight:"600"}});import{jsx as kt,jsxs as To}from"react/jsx-runtime";function Qa({armId:e}){let t=Ia(),r=()=>{cr(e),t.minimize()};return To(E,{style:Dt.labeledChip,onPress:r,accessibilityLabel:"Open the floating action bar over the app",accessibilityRole:"button",testID:"time-machine-header-bar",children:[kt(h,{style:Dt.glyph}),kt(d,{style:Dt.label,children:"Action bar"})]})}function Co({armId:e}){return To(h,{style:Dt.row,children:[kt(Qa,{armId:e}),kt(ka,{})]})}var Dt=P.create({row:{flexDirection:"row",alignItems:"center",gap:8},labeledChip:{height:32,flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:10,borderRadius:8,borderWidth:1,borderColor:St.color.border,backgroundColor:St.color.buttonSurface},glyph:{width:14,height:8,borderRadius:3,borderWidth:1.5,borderColor:St.color.accent},label:{fontSize:11,fontWeight:"700",color:St.color.accent}});import{useMemo as Xa}from"react";import{ABSENT_VALUE as zo,ThemedSplitView as Za,devToolsDefaultTheme as es,toDiffable as $o}from"@buoy-gg/shared-ui/web/dataViewer";import{jsx as ts,jsxs as Lo}from"react/jsx-runtime";var rs=[];function os({item:e,testID:t}){let{oldValue:r,newValue:i}=Xa(()=>({oldValue:e.verdict==="added"?zo:$o(e.oldValue),newValue:e.verdict==="removed"?zo:$o(e.newValue)}),[e]);return Lo(h,{style:Eo.panel,testID:t,children:[e.reason?Lo(d,{style:Eo.reason,children:["\u26A0 ",e.reason]}):null,ts(Za,{oldValue:r,newValue:i,differences:rs,theme:es,scrollEnabled:false})]})}var Eo=P.create({panel:{paddingLeft:16,paddingRight:12,paddingTop:10,paddingBottom:14,gap:10,backgroundColor:o.color.group},reason:{color:o.color.warning,fontSize:o.font.footnote}});import{useEffect as ns,useState as is}from"react";import{jsx as Ao,jsxs as as}from"react/jsx-runtime";function ss({name:e,onRename:t}){let[r,i]=is(e);ns(()=>i(e),[e]);let n=()=>{let a=r.trim();if(!a){i(e);return}a!==e&&t(a)};return as(h,{style:ur.row,children:[Ao(d,{style:ur.label,children:"Name"}),Ao(lt,{style:ur.input,value:r,onChangeText:i,onSubmitEditing:n,onBlur:n,returnKeyType:"done",selectTextOnFocus:true,accessibilityLabel:"Restore point name",testID:"tm-preview-name"})]})}var ur=P.create({row:{flexDirection:"row",alignItems:"center",gap:14,minHeight:o.rowMinHeight,paddingHorizontal:o.textInset},label:{color:o.color.labelSecondary,fontSize:o.font.row,letterSpacing:o.tracking.row},input:{flex:1,minWidth:0,color:o.color.label,fontSize:o.font.row,fontWeight:"600",letterSpacing:o.tracking.row,textAlign:"right",padding:0,backgroundColor:"transparent"}});var Ye={added:{glyph:"+",color:o.color.accent,label:"added",applies:true},removed:{glyph:"\u2212",color:o.color.danger,label:"removed",applies:true},changed:{glyph:"\u2248",color:o.color.info,label:"changed",applies:true},"too-large":{glyph:"\u2248",color:o.color.warning,label:"changed (large)",applies:true},unchanged:{glyph:"=",color:o.color.labelTertiary,label:"unchanged",applies:false},"wont-apply":{glyph:"\u2298",color:o.color.warning,label:"won't apply",applies:false},recomputes:{glyph:"\u21BB",color:o.color.labelTertiary,label:"recomputes",applies:false}};import{Fragment as ls,jsx as y,jsxs as B}from"react/jsx-runtime";var Po={storage:"keys",redux:"slices",zustand:"stores",jotai:"atoms",query:"queries"},hr=new Set;function cs(e,t){if(e.size!==t.size)return false;for(let r of e)if(!t.has(r))return false;return true}function he(e,t){return`${e}::${t}`}function Tt(e){if(e===void 0)return"\u2205";try{let t=typeof e=="string"?`"${e}"`:JSON.stringify(e);return t?t.length>46?`${t.slice(0,43)}\u2026`:t:String(e)}catch{return"[complex]"}}function Qe({position:e,children:t}){return B(h,{style:[w.cardRow,e.first?w.cardRowFirst:null,e.last?w.cardRowLast:null],children:[e.first?null:y(h,{style:w.cardSeparator}),t]})}function pr({glyph:e,count:t,color:r,testID:i}){return y(h,{style:[w.countPill,{backgroundColor:`${r}26`}],children:B(d,{style:[w.countPillText,{color:r}],testID:i,children:[e,t]})})}function mr({state:e}){return y(h,{style:[w.checkbox,e!=="none"&&w.checkboxChecked],children:e==="none"?null:y(d,{style:w.checkboxGlyph,children:e==="all"?"\u2713":"\u2212"})})}var ds=ya(function({row:e,expanded:t,onOpen:r,onToggle:i}){let n=Ye[e.item.verdict],a=!n.applies||e.excluded,s=e.item.verdict==="changed"||e.item.verdict==="added"||e.item.verdict==="removed",f=`tm-preview-item-${e.sourceId}-${e.item.key}`;return y(Qe,{position:e,children:B(h,{style:[w.itemRow,a&&w.dimmed],children:[y(E,{onPress:i,disabled:!n.applies,hitSlop:{top:10,bottom:10,left:8,right:8},testID:`tm-preview-toggle-${e.sourceId}-${e.item.key}`,accessibilityRole:"checkbox",accessibilityState:{checked:!(!n.applies||e.excluded)},accessibilityLabel:`Include ${e.item.label}`,children:y(mr,{state:!n.applies||e.excluded?"none":"all"})}),B(E,{style:w.itemBodyTouch,onPress:()=>s&&r(),disabled:!s,testID:f,children:[y(d,{style:[w.itemGlyph,{color:n.color}],children:n.glyph}),B(h,{style:w.itemBody,children:[y(d,{style:w.itemLabel,numberOfLines:1,testID:`${f}-label`,children:e.item.label}),e.item.verdict==="changed"&&B(d,{style:w.itemPreview,numberOfLines:1,testID:`${f}-values`,children:[Tt(e.item.oldValue)," \u2192"," ",Tt(e.item.newValue)]}),e.item.verdict==="added"&&y(d,{style:w.itemPreview,numberOfLines:1,testID:`${f}-values`,children:Tt(e.item.newValue)}),e.item.verdict==="removed"&&y(d,{style:[w.itemPreview,w.itemPreviewRemoved],numberOfLines:1,testID:`${f}-values`,children:Tt(e.item.oldValue)}),e.excluded?y(d,{style:w.itemExcluded,testID:`${f}-excluded`,children:"excluded \u2014 restore leaves this untouched"}):e.item.reason&&y(d,{style:w.itemReason,numberOfLines:2,testID:`${f}-reason`,children:e.item.reason})]}),s?t?y(ao,{size:16,color:o.color.labelTertiary}):y(Yr,{}):null]})]})})});function us({preview:e,snapshots:t,busy:r,onBack:i,onRestore:n}){let a=xa(),s=a.instanceId!==void 0,f=va({minBottom:16}),[u,g]=Xt({}),[l,p]=Xt(new Set),z=Qt(false),[m,O]=Xt(hr),j=ke(c=>{O(S=>{let C=new Set(S);return C.has(c)?C.delete(c):C.add(c),C})},[]),W=a.search,v=e.right==="current"?void 0:t.find(c=>c.id===e.right.snapshotId),U=Qt(v);U.current=v;let ee=ke(()=>{if(!U.current)return;let c=U.current;x.setRestoreRoute(c.id,!pt(c))},[]),G=v?.baseline===true,Ae=e.left==="current",te=vt(()=>v?v.excludedKeys?.length?new Set(v.excludedKeys):hr:null,[v]),K=!!v?.scope?.length&&!v?.excludedKeys?.length,$=vt(()=>{if(!K||!v?.scope)return hr;let c=new Set(v.scope),S=new Set;for(let C of e.sources)for(let R of C.items){let _=he(C.id,R.key);Ye[R.verdict].applies&&!c.has(_)&&S.add(_)}return S},[K,v,e.sources]),ne=Qt(null);io(()=>{if(!v||e.building||!te||ne.current===v.id)return;ne.current=v.id,z.current=false;let c=te.size>0?te:$;c.size>0&&p(new Set(c)),K&&c.size>0&&x.setExclusions(v.id,Array.from(c))},[v,e.building,te,$,K]),io(()=>{if(!v||!te||!z.current||cs(l,te))return;let c=Array.from(l);x.setExclusions(v.id,c.length?c:null)},[l,v,te]);let pe=ke(c=>{z.current=true,p(S=>{let C=new Set(S);return C.has(c)?C.delete(c):C.add(c),C})},[]),De=ke((c,S)=>{z.current=true,p(C=>{let R=new Set(C);for(let _ of c.items){if(!Ye[_.verdict].applies)continue;let re=he(c.id,_.key);S==="all"?R.add(re):R.delete(re)}return R})},[]),ie=ke((c,S)=>{g(C=>({...C,[c]:!S}))},[]),D=vt(()=>{let c=0,S=0,C=0,R=[];for(let _ of e.sources){let re=0;for(let Y of _.items)Ye[Y.verdict].applies?l.has(he(_.id,Y.key))?S+=1:(c+=1,re+=1):Y.verdict==="wont-apply"&&(C+=1);re>0&&R.push(`${re} ${_.label.toLowerCase()}`)}return{applies:c,excludedCount:S,wontApply:C,perSource:R}},[e.sources,l]);Sa(s?{title:"Restore Preview",subtitle:v?.name??"preview",onBack:i,actions:y(Co,{armId:v?.id})}:null,[s,v?.name,v?.id]);let{rows:et,blockedSources:Pe}=vt(()=>{let c=W.trim().toLowerCase(),S=[],C=[];for(let R of e.sources){let _=R.items.some(L=>L.verdict!=="unchanged");if(!_&&!R.error)continue;let re=_||R.notes.length>0||!!R.error,Y=R.items.filter(L=>Ye[L.verdict].applies),He=R.items.filter(L=>L.verdict==="wont-apply").length;He>0&&C.push(R.label);let ot=R.items.length===1?(Po[R.id]??"items").replace(/ies$/,"y").replace(/s$/,""):Po[R.id]??"items",q=`${R.items.length} ${ot} \xB7 `+(Y.length>0?`${Y.length} changed`:He>0?`${He} won't apply`:"no changes"),Ce=Y.filter(L=>l.has(he(R.id,L.key))).length,nt=Y.length===0||Ce===0?"all":Ce===Y.length?"none":"some",ce={added:0,removed:0,changed:0};for(let L of R.items)l.has(he(R.id,L.key))||(L.verdict==="added"?ce.added+=1:L.verdict==="removed"?ce.removed+=1:(L.verdict==="changed"||L.verdict==="too-large")&&(ce.changed+=1));let ze=R.items.filter(L=>!(L.verdict==="unchanged"||c&&!L.label.toLowerCase().includes(c))),it=re?u[R.id]??true:true;if(S.push({kind:"source",source:R,collapsed:it,includeState:nt,applicableCount:Y.length,counts:ce,expandable:re,summary:q,first:false,last:false}),!it){for(let L of R.notes)S.push({kind:"note",id:`${R.id}:${L}`,text:L,first:false,last:false});R.error&&S.push({kind:"note",id:`${R.id}:err`,text:`\u26A0 ${R.error}`,first:false,last:false});for(let L of ze){let b=he(R.id,L.key);S.push({kind:"item",sourceId:R.id,item:L,excluded:l.has(b),first:false,last:false}),m.has(b)&&S.push({kind:"diff",sourceId:R.id,item:L,first:false,last:false})}}}return v?.route&&S.push({kind:"route",href:v.route.href,on:pt(v),first:false,last:false}),S.length>0&&(S[0].first=true,S[S.length-1].last=true),{rows:S,blockedSources:C}},[e.sources,W,u,l,m,v]),tt=ke(({item:c})=>{if(c.kind==="source"){let S=c.source,{counts:C}=c;return y(Qe,{position:c,children:B(h,{style:w.sourceCard,children:[y(E,{onPress:()=>De(S,c.includeState),disabled:c.applicableCount===0,hitSlop:{top:10,bottom:10,left:8,right:8},testID:`tm-preview-source-toggle-${S.id}`,children:y(mr,{state:c.applicableCount===0?"none":c.includeState})}),B(E,{style:w.sourceCardTouch,onPress:()=>c.expandable&&ie(S.id,c.collapsed),disabled:!c.expandable,testID:`tm-preview-source-${S.id}`,children:[B(h,{style:w.sourceNameBlock,children:[y(d,{style:w.sourceName,numberOfLines:1,testID:`tm-preview-source-${S.id}-name`,children:S.label}),y(d,{style:w.sourceSummary,numberOfLines:1,testID:`tm-preview-source-${S.id}-summary`,children:c.includeState==="none"&&c.applicableCount>0?`${c.summary} \xB7 excluded`:c.summary})]}),B(h,{style:w.sourceBadges,children:[C.removed>0?y(pr,{glyph:"\u2212",count:C.removed,color:o.color.danger,testID:`tm-preview-source-${S.id}-removed`}):null,C.added>0?y(pr,{glyph:"+",count:C.added,color:o.color.accent,testID:`tm-preview-source-${S.id}-added`}):null,C.changed>0?y(pr,{glyph:"\u2248",count:C.changed,color:o.color.info,testID:`tm-preview-source-${S.id}-changed`}):null]}),c.expandable?c.collapsed?y(Yr,{}):y(ao,{size:16,color:o.color.labelTertiary}):null]})]})})}return c.kind==="note"?y(Qe,{position:c,children:y(d,{style:w.noteRow,testID:`tm-preview-note-${c.id}`,children:c.text})}):c.kind==="route"?y(Qe,{position:c,children:B(E,{style:w.routeRow,onPress:ee,accessibilityRole:"switch",accessibilityState:{checked:c.on},accessibilityLabel:`Also return to ${c.href}`,testID:"tm-preview-route",children:[y(mr,{state:c.on?"all":"none"}),B(h,{style:w.routeText,children:[y(d,{style:w.routeTitle,children:"Return to this screen"}),y(d,{style:w.routeHref,numberOfLines:1,testID:"tm-preview-route-href",children:c.href})]})]})}):c.kind==="diff"?y(Qe,{position:c,children:y(os,{item:c.item,testID:`tm-preview-diff-${c.sourceId}-${c.item.key}`})}):y(ds,{row:c,expanded:m.has(he(c.sourceId,c.item.key)),onOpen:()=>j(he(c.sourceId,c.item.key)),onToggle:()=>pe(he(c.sourceId,c.item.key))})},[m,j,ie,pe,De,ee]),Te=ke(c=>c.kind==="source"?`s:${c.source.id}`:c.kind==="note"?`n:${c.id}`:c.kind==="route"?"route":c.kind==="diff"?`d:${c.sourceId}:${c.item.key}`:`i:${c.sourceId}:${c.item.key}`,[]),rt=B(h,{children:[!s&&B(h,{style:w.fallbackHeader,children:[y(E,{onPress:i,hitSlop:hs,testID:"tm-preview-back",children:y(d,{style:w.backText,children:"\u2039 Back"})}),y(d,{style:w.screenTitle,numberOfLines:1,children:"Restore Preview"})]}),v?B(ls,{children:[y(gt,{children:"Restore Point"}),y(yt,{children:y(ss,{name:v.name,onRename:c=>void x.rename(v.id,c)})})]}):null,y(gt,{children:"Changes to Restore"})]}),Oe=r||e.building||D.applies===0;return B(h,{style:w.container,children:[y(Dr,{testID:"tm-preview-list",data:et,renderItem:tt,keyExtractor:Te,ListHeaderComponent:rt,ListEmptyComponent:e.building?y(ct,{style:w.buildingSpinner,size:"small",color:o.color.accent}):y(d,{style:w.emptyText,testID:"tm-preview-empty",children:W?"Nothing matches this filter.":"No changes \u2014 restoring would change nothing."}),ListFooterComponent:y(h,{children:D.wontApply>0?B(h,{style:w.warnNote,children:[y(ba,{size:12,color:o.color.warning}),B(d,{style:w.warnNoteText,testID:"tm-preview-wont-apply",children:[D.wontApply," item",D.wontApply===1?"":"s"," ","won't apply \u2014 expand"," ",Pe.length>0?Pe.join(" and "):"the source"," ","to see the reason."]})]}):null}),keyboardShouldPersistTaps:"handled",removeClippedSubviews:true,initialNumToRender:20,windowSize:7,contentContainerStyle:w.listContent}),Ae&&v&&B(h,{style:[w.footer,{paddingBottom:f.bottom}],children:[B(E,{style:[w.cta,G&&w.ctaDanger,Oe&&w.ctaDisabled],onPress:()=>n(G?"reload":"live",Array.from(l)),disabled:G?r||e.building:Oe,testID:"tm-preview-restore",children:[y(wa,{size:16,color:G?o.color.onDanger:o.color.onAccent}),y(d,{style:[w.ctaText,G?w.ctaTextDanger:null],children:G?"Wipe & Reload":"Restore State"})]}),y(d,{style:w.ctaCaption,testID:"tm-preview-cta-caption",children:G?"This wipes all app storage and reloads the app.":D.excludedCount>0?`Restores ${D.applies} of ${D.applies+D.excludedCount} change${D.applies+D.excludedCount===1?"":"s"} \u2014 everything else stays as it is.`:"This will replace the current state with the snapshot."})]})]})}var hs={top:10,bottom:10,left:10,right:10},w=P.create({container:{flex:1,backgroundColor:"transparent"},fallbackHeader:{flexDirection:"row",alignItems:"center",paddingHorizontal:o.gutter,paddingVertical:10,gap:10},backText:{color:o.color.accent,fontSize:o.font.control},screenTitle:{color:o.color.label,fontSize:20,fontWeight:"700",letterSpacing:o.tracking.row,flex:1},dimmed:{opacity:.5},listContent:{paddingTop:14,paddingBottom:12},cardRow:{marginHorizontal:o.gutter,backgroundColor:o.color.group},cardRowFirst:{borderTopLeftRadius:o.radius.group,borderTopRightRadius:o.radius.group},cardRowLast:{borderBottomLeftRadius:o.radius.group,borderBottomRightRadius:o.radius.group,marginBottom:10},cardSeparator:{height:P.hairlineWidth,marginLeft:51,backgroundColor:o.color.separator},warnNote:{flexDirection:"row",alignItems:"flex-start",gap:6,paddingHorizontal:o.gutter+o.textInset,paddingTop:8},warnNoteText:{flex:1,color:o.color.labelSecondary,fontSize:o.font.footnote,lineHeight:o.font.footnote*1.35},countPill:{borderRadius:o.radius.pill,paddingHorizontal:9,paddingVertical:3},countPillText:{fontFamily:ft,fontSize:o.font.footnote,fontWeight:"600"},checkbox:{width:23,height:23,borderRadius:o.radius.pill,borderWidth:1.7,borderColor:o.color.labelTertiary,alignItems:"center",justifyContent:"center"},checkboxChecked:{borderColor:o.color.accent,backgroundColor:o.color.accent},checkboxGlyph:{color:o.color.onAccent,fontSize:13,fontWeight:"700",lineHeight:15},routeRow:{flexDirection:"row",alignItems:"center",minHeight:58,paddingHorizontal:o.textInset,paddingVertical:9,gap:12},routeText:{flex:1,minWidth:0,gap:2},routeTitle:{color:o.color.label,fontSize:o.font.row,fontWeight:"600",letterSpacing:o.tracking.row},routeHref:{color:o.color.labelSecondary,fontFamily:ft,fontSize:o.font.mono},sourceCard:{flexDirection:"row",alignItems:"center",minHeight:58,paddingHorizontal:o.textInset,paddingVertical:9,gap:12},sourceCardTouch:{flex:1,flexDirection:"row",alignItems:"center",gap:12,minWidth:0},sourceNameBlock:{flex:1,minWidth:0,gap:2},sourceName:{color:o.color.label,fontSize:o.font.row,fontWeight:"600",letterSpacing:o.tracking.row},sourceSummary:{color:o.color.labelSecondary,fontSize:o.font.footnote,fontVariant:["tabular-nums"]},sourceBadges:{flexDirection:"row",gap:6},noteRow:{color:o.color.labelTertiary,fontSize:o.font.footnote,lineHeight:o.font.footnote*1.35,paddingHorizontal:o.textInset,paddingVertical:9},itemRow:{flexDirection:"row",alignItems:"center",paddingLeft:o.textInset,paddingRight:o.textInset,paddingVertical:10,gap:12},itemBodyTouch:{flex:1,flexDirection:"row",alignItems:"center",gap:10,minWidth:0},itemGlyph:{fontSize:14,fontWeight:"700",width:14,textAlign:"center"},itemBody:{flex:1,minWidth:0},itemLabel:{color:o.color.label,fontSize:o.font.control,letterSpacing:o.tracking.control},itemPreview:{color:o.color.labelSecondary,fontFamily:ft,fontSize:o.font.mono,marginTop:3},itemPreviewRemoved:{textDecorationLine:"line-through"},itemReason:{color:o.color.warning,fontSize:o.font.mono,marginTop:3},itemExcluded:{color:o.color.labelTertiary,fontSize:o.font.mono,marginTop:3,fontStyle:"italic"},buildingSpinner:{marginTop:28},emptyText:{color:o.color.labelSecondary,fontSize:o.font.footnote,textAlign:"center",marginTop:28},footer:{paddingHorizontal:o.gutter,paddingTop:10,gap:8,borderTopColor:o.color.separator,borderTopWidth:P.hairlineWidth,backgroundColor:o.color.sheet},cta:{flexDirection:"row",alignItems:"center",justifyContent:"center",gap:8,height:50,backgroundColor:o.color.accent,borderRadius:o.radius.group},ctaDanger:{backgroundColor:o.color.danger},ctaTextDanger:{color:o.color.onDanger},ctaDisabled:{opacity:.4},ctaText:{color:o.color.onAccent,fontSize:o.font.row,fontWeight:"600",letterSpacing:o.tracking.row},ctaCaption:{color:o.color.labelSecondary,fontSize:o.font.footnote,lineHeight:o.font.footnote*1.35,textAlign:"center"}});import{jsx as ps}from"react/jsx-runtime";function ms(e,t){return e==="current"?void 0:t.find(r=>r.id===e.snapshotId)}function fs({preview:e,snapshots:t,busy:r,onClose:i}){let n=ms(e.right,t);return ps(us,{preview:e,snapshots:t,busy:r,onBack:i,onRestore:(a,s)=>{if(!(!n||r)){if(n.baseline){Kt("Restore fresh install?","This wipes all app storage and reloads the app.","Wipe & reload",()=>void x.restore(n.id,"reload"));return}x.restore(n.id,a,s).then(i)}}})}import{jsx as M,jsxs as Xe}from"react/jsx-runtime";var Oo=()=>ii().some(e=>e.id===sr);function fr(){let[e,t]=Hr({kind:"list"}),{snapshots:r,busy:i,preview:n}=mt(),a=qi(),s=()=>{x.clearPreview(),t({kind:"list"})};return e.kind==="preview"&&n?M(fs,{preview:n,snapshots:r,busy:i!==null,onClose:s}):M(gs,{sources:a,onOpenPreview:f=>{x.buildPreview({snapshotId:f.id}),t({kind:"preview"})}})}function gs({sources:e,onOpenPreview:t}){let{snapshots:r,hasLoaded:i,busy:n,lastOutcome:a,recentlyDeleted:s,remoteProviders:f}=mt(),u=oi("timeMachine.snapshots"),g=si(),l=ri({minBottom:16}),p=Br(ai,Oo,Oo),z=Br(mo,It,It),m=p?fo(r,z)?.id:void 0,O=ti({}),[j,W]=Hr(null),v=$=>{W(null),cr($),g.minimize()},U=g.search.trim().toLowerCase(),ee=U?r.filter($=>$.name.toLowerCase().includes(U)):r,G=r.filter($=>!$.safety).length>=u,Ae=n!==null||G,te=$=>{if(n)return;if($.baseline){Kt("Restore fresh install?","This wipes all app storage and reloads the app.","Wipe & reload",()=>void x.restore($.id,"reload"));return}let ne=(O.current[$.id]??0)+1;O.current[$.id]=ne,ne>=2&&!p&&W($.id),x.restore($.id,"live").then(pe=>{!Object.values(pe.results).every(De=>De.ok)||pe.willReload||g.minimize()})},K=j&&!p?r.find($=>$.id===j)??null:null;return Xe(Ot,{style:Ze.fill,contentContainerStyle:[Ze.content,{paddingBottom:l.bottom}],testID:"time-machine-scroll",keyboardShouldPersistTaps:"handled",children:[a&&Qr(a)?M(ea,{outcome:a}):null,s?M(ca,{name:s.stored.meta.name,at:s.at,onUndo:()=>void x.undoDelete(),onExpire:()=>x.clearRecentlyDeleted()}):null,M(h,{children:M(Yi,{disabled:Ae,busy:n==="capture",onCapture:$=>void x.capture($)})}),G?Xe(Ke,{tone:"warning",testID:"time-machine-limit",children:["Free plan keeps ",u," restore point",u===1?"":"s",". Upgrade to Pro for unlimited snapshots."]}):null,M(gt,{children:"Sources"}),M(fa,{sources:e,onToggle:f?void 0:qr}),f?null:M(Ke,{testID:"time-machine-sources-hint",children:"Switch a source off to leave it out of every capture and restore."}),M(gt,{children:"Restore Points"}),K?Xe(h,{style:Ze.barHint,testID:"time-machine-bar-hint",children:[Xe(Ke,{children:['Restoring "',K.name,'" a lot? Put it on the floating action bar and restore it with one tap.']}),M(E,{onPress:()=>v(K.id),accessibilityRole:"button",testID:"time-machine-bar-hint-pin",hitSlop:{top:6,bottom:6,left:6,right:6},children:M(d,{style:Ze.barHintAction,children:"Open the action bar"})})]}):null,Xe(yt,{children:[ee.map($=>M(aa,{meta:$,busy:n!==null,armed:$.id===m,onOpen:()=>t($),onRestore:()=>te($),onDelete:()=>void x.delete($.id),onDuplicate:()=>void x.duplicate($.id),onArm:()=>v($.id)},$.id)),ee.length===0?M(ni,{testID:"time-machine-empty",...i?r.length>0?{otto:"sad",title:"No restore point matches that name.",message:`Clear the search to see all ${r.length}.`}:{otto:"rewind",title:"No restore points yet",message:"Set up the state you want to come back to, then capture it."}:{otto:"loading",title:"Loading restore points\u2026",message:"Reading the vault off disk."}}):null]}),ee.length>0?M(Ke,{testID:"time-machine-swipe-hint",children:"Swipe a restore point to copy or delete it."}):null,M(h,{style:Ze.spacer}),M(yt,{children:M(ga,{disabled:n!==null,onWipe:()=>Kt("Wipe all app state?","This deletes all app storage and reloads the app \u2014 like a fresh install.","Wipe & reload",()=>void x.wipeAll())})}),M(Ke,{centered:true,children:"Deletes all app storage and reloads \u2014 like a fresh install."})]})}var Ze=P.create({barHint:{marginHorizontal:o.gutter,marginBottom:8},barHintAction:{color:o.color.accent,fontSize:o.font.footnote,fontWeight:"600",paddingHorizontal:o.textInset,paddingTop:2},fill:{flex:1,backgroundColor:"transparent"},content:{paddingTop:14},empty:{color:o.color.labelSecondary,fontSize:o.font.footnote,lineHeight:o.font.footnote*1.4,paddingHorizontal:o.textInset,paddingVertical:16},spacer:{height:24}});import{jsx as Ho}from"react/jsx-runtime";var Ct={id:"time-machine",name:"TIME MACHINE",description:"Snapshot & restore app state (storage, stores, query cache)",slot:"both",icon:({size:e,color:t,slot:r})=>Ho(Zn,{size:r==="dial"&&st.OS!=="web"?e*1.5:e,color:t||ei}),component:fr,modal:{subtitle:"snapshot & restore app state",searchable:true,searchPlaceholder:"Filter\u2026",headerActions:Ho(Co,{})}};function ys(e={}){return{...Ct,name:e.name??Ct.name,description:e.description??Ct.description}}import{JsModal as bs}from"@buoy-gg/shared-ui/web";import{jsx as Ee,jsxs as ws}from"react/jsx-runtime";function vs(){return ws(h,{style:gr.header,children:[Ee(d,{style:gr.headerTitle,children:"Time Machine"}),Ee(d,{style:gr.headerSubtitle,children:"Snapshot & restore app state"})]})}function Ss({visible:e,onClose:t,onBack:r,onMinimize:i,persistenceKey:n}){return Ee(bs,{visible:e,onClose:t,onMinimize:i,persistenceKey:n,header:{showToggleButton:true,customContent:Ee(vs,{})},enablePersistence:true,initialMode:"bottomSheet",disableScrollWrapper:true,children:Ee(fr,{})})}function xs(){return Ee(fr,{})}var gr=P.create({header:{paddingHorizontal:4,gap:2},headerTitle:{color:o.color.label,fontSize:22,fontWeight:"700",letterSpacing:.3},headerSubtitle:{color:o.color.labelSecondary,fontSize:o.font.footnote}});import{getStateSnapshotProviders as Is,subscribeToStateSnapshotProviders as Rs,superJsonDeserialize as ks}from"@buoy-gg/shared-ui/web";import{jsonLikelyLargerThan as Bo}from"@buoy-gg/shared-ui/web/dataViewer";function Ds(){return Is().map(e=>{let t=e.status();return{id:e.id,label:e.label,canCapture:t.canCapture,canRestore:t.canRestore,detail:t.detail,enabled:se(e.id)}})}function jo(){let{snapshots:e,busy:t,lastOutcome:r}=x.getState(),i=Go();return{snapshots:e,busy:t,lastOutcome:r,providers:Ds(),route:{available:Be(),enabled:se(Me),...i?{current:i.href}:{}}}}var Ts={version:2,getSnapshot:()=>jo(),subscribe:e=>{let t=x.subscribe(e),r=Rs(e);return()=>{t(),r()}},actions:{list:()=>jo(),capture:async e=>{let{name:t="",sourceIds:r}=e??{};return{captured:true,snapshot:await x.capture(t,r)}},captureBaseline:async()=>({captured:true,snapshot:await x.captureBaseline()}),wipeAll:async()=>await x.wipeAll(),restore:async e=>{let{id:t,mode:r="live",excludeKeys:i,restoreRoute:n}=e??{};if(!t)throw new Error("restore requires a snapshot `id`");return await x.restore(t,r,i,{restoreRoute:n})},delete:async e=>{let{id:t}=e??{};if(!t)throw new Error("delete requires a snapshot `id`");return await x.delete(t),{deleted:true,id:t}},rename:async e=>{let{id:t,name:r}=e??{};if(!t||!r)throw new Error("rename requires `id` and `name`");return await x.rename(t,r),{renamed:true,id:t,name:r}},setExclusions:async e=>{let{id:t,excludedKeys:r}=e??{};if(!t)throw new Error("setExclusions requires `id`");return await x.setExclusions(t,r??null),{id:t,excluded:r?.length??0}},setRestoreRoute:async e=>{let{id:t,restoreRoute:r}=e??{};if(!t)throw new Error("setRestoreRoute requires `id`");return await x.setRestoreRoute(t,r!==false),{id:t,restoreRoute:r!==false}},duplicate:async e=>{let{id:t}=e??{};if(!t)throw new Error("duplicate requires `id`");let r=await x.duplicate(t);if(!r)throw new Error(`No snapshot with id "${t}"`);return{snapshot:r}},setScope:async e=>{let{id:t,scope:r}=e??{};if(!t)throw new Error("setScope requires a snapshot `id`");return await x.setScope(t,r??null),{scoped:true,id:t,count:r?.length??0}},preview:async e=>{let{id:t,compareTo:r}=e??{};if(!t)throw new Error("preview requires a snapshot `id`");let i={snapshotId:t},n=r?{snapshotId:r}:"current";await x.buildPreview(i,n);let a=x.getState().preview;if(!a)throw new Error("preview build produced no result");let s=4*1024;return{left:n,right:i,builtAt:a.builtAt,sources:a.sources.map(f=>({...f,items:f.items.map(u=>{let g=u.oldValue!==void 0&&Bo(u.oldValue,s),l=u.newValue!==void 0&&Bo(u.newValue,s);return{...u,oldValue:g?void 0:u.oldValue,newValue:l?void 0:u.newValue,...g||l?{valueOmitted:true}:{}}})}))}},inspect:async e=>{let{id:t,sourceId:r}=e??{};if(!t||!r)throw new Error("inspect requires `id` and `sourceId`");let i=await fe(t);if(!i)throw new Error(`No snapshot with id "${t}"`);let n=i.data[r];if(!n)throw new Error(`Snapshot "${t}" has no "${r}" source`);return{id:t,sourceId:r,warnings:i.meta.sources[r]?.warnings??[],data:ks(n)}}}};Ir();export{Ve as RESTORE_ORDER,Vt as SAFETY_SNAPSHOT_NAME,sr as TIME_MACHINE_FLOATING_TOOL_ID,Ss as TimeMachineModal,xs as TimeMachineToolView,Ir as armPendingRouteRestore,Be as canRestoreRoute,at as captureCurrentRoute,ys as createTimeMachineTool,se as isSourceEnabled,Lt as navigateToRoute,cr as openTimeMachineFloatingTool,zi as replaceTimeMachineFromSnapshot,Ci as setRemoteTimeMachineHandler,qr as setSourceEnabled,ko as startTimeMachineFloatingToolPersistence,Kr as subscribeSourceSettings,x as timeMachineStore,Ts as timeMachineSyncAdapter,Ct as timeMachineToolPreset};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buoy-gg/time-machine",
3
- "version": "7.0.73",
3
+ "version": "7.0.75",
4
4
  "description": "Time Machine - snapshot & restore app state (storage, redux, zustand, jotai, react-query) for React Native DevTools",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -20,19 +20,19 @@
20
20
  "./lib/web/**/*.mjs"
21
21
  ],
22
22
  "dependencies": {
23
- "@buoy-gg/floating-tools-core": "^7.0.73",
24
- "@buoy-gg/shared-ui": "^7.0.73"
23
+ "@buoy-gg/shared-ui": "^7.0.75",
24
+ "@buoy-gg/floating-tools-core": "^7.0.75"
25
25
  },
26
26
  "peerDependencies": {
27
- "@buoy-gg/license": "7.0.73",
27
+ "@buoy-gg/license": "7.0.75",
28
28
  "react": "*"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/react": "^19.1.0",
32
32
  "@types/react-native": "^0.73.0",
33
33
  "typescript": "~5.8.3",
34
- "@buoy-gg/license": "^7.0.73",
35
- "@buoy-gg/core": "^7.0.73"
34
+ "@buoy-gg/license": "^7.0.75",
35
+ "@buoy-gg/core": "^7.0.75"
36
36
  },
37
37
  "react-native-builder-bob": {
38
38
  "source": "src",