rintReceived(getCommonAndChangedSubstrings(diffs,DIFF_INSERT,hasCommonDiff2));return`${expectedLine} ${receivedLine}`}let clonedExpected=deepClone(expected,{forceWritable:!0}),clonedReceived=deepClone(received,{forceWritable:!0}),{replacedExpected,replacedActual}=replaceAsymmetricMatcher(clonedExpected,clonedReceived);return diff(replacedExpected,replacedActual,options)}function replaceAsymmetricMatcher(actual,expected,actualReplaced=new WeakSet,expectedReplaced=new WeakSet){return isReplaceable(actual,expected)?actualReplaced.has(actual)||expectedReplaced.has(expected)?{replacedActual:actual,replacedExpected:expected}:(actualReplaced.add(actual),expectedReplaced.add(expected),getOwnProperties(expected).forEach(key=>{let expectedValue=expected[key],actualValue=actual[key];if(isAsymmetricMatcher(expectedValue))expectedValue.asymmetricMatch(actualValue)&&(actual[key]=expectedValue);else if(isAsymmetricMatcher(actualValue))actualValue.asymmetricMatch(expectedValue)&&(expected[key]=actualValue);else if(isReplaceable(actualValue,expectedValue)){let replaced=replaceAsymmetricMatcher(actualValue,expectedValue,actualReplaced,expectedReplaced);actual[key]=replaced.replacedActual,expected[key]=replaced.replacedExpected}}),{replacedActual:actual,replacedExpected:expected}):{replacedActual:actual,replacedExpected:expected}}function getLabelPrinter(...strings){let maxLength=strings.reduce((max,string)=>string.length>max?string.length:max,0);return string=>`${string}: ${" ".repeat(maxLength-string.length)}`}var SPACE_SYMBOL="\xB7";function replaceTrailingSpaces(text){return text.replace(/\s+$/gm,spaces=>SPACE_SYMBOL.repeat(spaces.length))}function printReceived(object){return p2.red(replaceTrailingSpaces(stringify(object)))}function printExpected(value){return p2.green(replaceTrailingSpaces(stringify(value)))}function getCommonAndChangedSubstrings(diffs,op,hasCommonDiff2){return diffs.reduce((reduced,diff2)=>reduced+(diff2[0]===DIFF_EQUAL?diff2[1]:diff2[0]===op?hasCommonDiff2?p2.inverse(diff2[1]):diff2[1]:""),"")}var IS_RECORD_SYMBOL="@@__IMMUTABLE_RECORD__@@",IS_COLLECTION_SYMBOL="@@__IMMUTABLE_ITERABLE__@@";function isImmutable(v){return v&&(v[IS_COLLECTION_SYMBOL]||v[IS_RECORD_SYMBOL])}var OBJECT_PROTO=Object.getPrototypeOf({});function getUnserializableMessage(err){return err instanceof Error?`: ${err.message}`:typeof err=="string"?`: ${err}`:""}function serializeValue(val,seen=new WeakMap){if(!val||typeof val=="string")return val;if(typeof val=="function")return`Function<${val.name||"anonymous"}>`;if(typeof val=="symbol")return val.toString();if(typeof val!="object")return val;if(isImmutable(val))return serializeValue(val.toJSON(),seen);if(val instanceof Promise||val.constructor&&val.constructor.prototype==="AsyncFunction")return"Promise";if(typeof Element<"u"&&val instanceof Element)return val.tagName;if(typeof val.asymmetricMatch=="function")return`${val.toString()} ${format2(val.sample)}`;if(typeof val.toJSON=="function")return serializeValue(val.toJSON(),seen);if(seen.has(val))return seen.get(val);if(Array.isArray(val)){let clone2=new Array(val.length);return seen.set(val,clone2),val.forEach((e,i)=>{try{clone2[i]=serializeValue(e,seen)}catch(err){clone2[i]=getUnserializableMessage(err)}}),clone2}else{let clone2=Object.create(null);seen.set(val,clone2);let obj=val;for(;obj&&obj!==OBJECT_PROTO;)Object.getOwnPropertyNames(obj).forEach(key=>{if(!(key in clone2))try{clone2[key]=serializeValue(val[key],seen)}catch(err){delete clone2[key],clone2[key]=getUnserializableMessage(err)}}),obj=Object.getPrototypeOf(obj);return clone2}}function normalizeErrorMessage(message){return message.replace(/__(vite_ssr_import|vi_import)_\d+__\./g,"")}function processError(_err,diffOptions,seen=new WeakSet){if(!_err||typeof _err!="object")return{message:String(_err)};let err=_err;err.stack&&(err.stackStr=String(err.stack)),err.name&&(err.nameStr=String(err.name)),(err.showDiff||err.showDiff===void 0&&err.expected!==void 0&&err.actual!==void 0)&&(err.diff=printDiffOrStringify(err.actual,err.expected,{...diffOptions,...err.diffOptions})),typeof err.expected!="string"&&(err.expected=stringify(err.expected,10)),typeof err.actual!="string"&&(err.actual=stringify(err.actual,10));try{typeof err.message=="string"&&(err.message=normalizeErrorMessage(err.message))}catch{}try{!seen.has(err)&&typeof err.cause=="object"&&(seen.add(err),err.cause=processError(err.cause,diffOptions,seen))}catch{}try{return serializeValue(err)}catch(e){return serializeValue(new Error(`Failed to fully serialize error: ${e?.message} Inner error message: ${err?.message}`))}}var CallStates=(CallStates2=>(CallStates2.DONE="done",CallStates2.ERROR="error",CallStates2.ACTIVE="active",CallStates2.WAITING="waiting",CallStates2))(CallStates||{});var EVENTS={CALL:"storybook/instrumenter/call",SYNC:"storybook/instrumenter/sync",START:"storybook/instrumenter/start",BACK:"storybook/instrumenter/back",GOTO:"storybook/instrumenter/goto",NEXT:"storybook/instrumenter/next",END:"storybook/instrumenter/end"},controlsDisabled={start:!1,back:!1,goto:!1,next:!1,end:!1},alreadyCompletedException=new Error("This function ran after the play function completed. Did you forget to `await` it?"),isObject=o=>Object.prototype.toString.call(o)==="[object Object]",isModule=o=>Object.prototype.toString.call(o)==="[object Module]",isInstrumentable=o=>{if(!isObject(o)&&!isModule(o))return!1;if(o.constructor===void 0)return!0;let proto=o.constructor.prototype;return!!isObject(proto)},construct=obj=>{try{return new obj.constructor}catch{return{}}},getInitialState=()=>({renderPhase:void 0,isDebugging:!1,isPlaying:!1,isLocked:!1,cursor:0,calls:[],shadowCalls:[],callRefsByResult:new Map,chainedCallIds:new Set,ancestors:[],playUntil:void 0,resolvers:{},syncTimeout:void 0}),getRetainedState=(state,isDebugging=!1)=>{let calls=(isDebugging?state.shadowCalls:state.calls).filter(call=>call.retain);if(!calls.length)return;let callRefsByResult=new Map(Array.from(state.callRefsByResult.entries()).filter(([,ref])=>ref.retain));return{cursor:calls.length,calls,callRefsByResult}},Instrumenter=class{constructor(){this.initialized=!1;this.channel=import_preview_api.addons.getChannel(),this.state=import_global.global.window?.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__||{};let resetState=({storyId,isPlaying=!0,isDebugging=!1})=>{let state=this.getState(storyId);this.setState(storyId,{...getInitialState(),...getRetainedState(state,isDebugging),shadowCalls:isDebugging?state.shadowCalls:[],chainedCallIds:isDebugging?state.chainedCallIds:new Set,playUntil:isDebugging?state.playUntil:void 0,isPlaying,isDebugging}),this.sync(storyId)};this.channel.on(import_core_events.FORCE_REMOUNT,resetState),this.channel.on(import_core_events.STORY_RENDER_PHASE_CHANGED,({storyId,newPhase})=>{let{isDebugging}=this.getState(storyId);this.setState(storyId,{renderPhase:newPhase}),newPhase==="preparing"&&isDebugging&&resetState({storyId}),newPhase==="playing"&&resetState({storyId,isDebugging}),newPhase==="played"&&this.setState(storyId,{isLocked:!1,isPlaying:!1,isDebugging:!1}),newPhase==="errored"&&this.setState(storyId,{isLocked:!1,isPlaying:!1})}),this.channel.on(import_core_events.SET_CURRENT_STORY,()=>{this.initialized?this.cleanup():this.initialized=!0});let start=({storyId,playUntil})=>{this.getState(storyId).isDebugging||this.setState(storyId,({calls})=>({calls:[],shadowCalls:calls.map(call=>({...call,status:"waiting"})),isDebugging:!0}));let log=this.getLog(storyId);this.setState(storyId,({shadowCalls})=>{if(playUntil||!log.length)return{playUntil};let firstRowIndex=shadowCalls.findIndex(call=>call.id===log[0].callId);return{playUntil:shadowCalls.slice(0,firstRowIndex).filter(call=>call.interceptable&&!call.ancestors?.length).slice(-1)[0]?.id}}),this.channel.emit(import_core_events.FORCE_REMOUNT,{storyId,isDebugging:!0})},back=({storyId})=>{let log=this.getLog(storyId).filter(call=>!call.ancestors?.length),last=log.reduceRight((res,item,index)=>res>=0||item.status==="waiting"?res:index,-1);start({storyId,playUntil:log[last-1]?.callId})},goto=({storyId,callId})=>{let{calls,shadowCalls,resolvers}=this.getState(storyId),call=calls.find(({id})=>id===callId),shadowCall=shadowCalls.find(({id})=>id===callId);if(!call&&shadowCall&&Object.values(resolvers).length>0){let nextId=this.getLog(storyId).find(c=>c.status==="waiting")?.callId;shadowCall.id!==nextId&&this.setState(storyId,{playUntil:shadowCall.id}),Object.values(resolvers).forEach(resolve=>resolve())}else start({storyId,playUntil:callId})},next=({storyId})=>{let{resolvers}=this.getState(storyId);if(Object.values(resolvers).length>0)Object.values(resolvers).forEach(resolve=>resolve());else{let nextId=this.getLog(storyId).find(c=>c.status==="waiting")?.callId;nextId?start({storyId,playUntil:nextId}):end({storyId})}},end=({storyId})=>{this.setState(storyId,{playUntil:void 0,isDebugging:!1}),Object.values(this.getState(storyId).resolvers).forEach(resolve=>resolve())};this.channel.on(EVENTS.START,start),this.channel.on(EVENTS.BACK,back),this.channel.on(EVENTS.GOTO,goto),this.channel.on(EVENTS.NEXT,next),this.channel.on(EVENTS.END,end)}getState(storyId){return this.state[storyId]||getInitialState()}setState(storyId,update){let state=this.getState(storyId),patch=typeof update=="function"?update(state):update;this.state={...this.state,[storyId]:{...state,...patch}},import_global.global.window?.parent&&(import_global.global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__=this.state)}cleanup(){this.state=Object.entries(this.state).reduce((acc,[storyId,state])=>{let retainedState=getRetainedState(state);return retainedState&&(acc[storyId]=Object.assign(getInitialState(),retainedState)),acc},{});let payload={controlStates:controlsDisabled,logItems:[]};this.channel.emit(EVENTS.SYNC,payload),import_global.global.window?.parent&&(import_global.global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__=this.state)}getLog(storyId){let{calls,shadowCalls}=this.getState(storyId),merged=[...shadowCalls];calls.forEach((call,index)=>{merged[index]=call});let seen=new Set;return merged.reduceRight((acc,call)=>(call.args.forEach(arg=>{arg?.__callId__&&seen.add(arg.__callId__)}),call.path.forEach(node=>{node.__callId__&&seen.add(node.__callId__)}),(call.interceptable||call.exception)&&!seen.has(call.id)&&(acc.unshift({callId:call.id,status:call.status,ancestors:call.ancestors}),seen.add(call.id)),acc),[])}instrument(obj,options,depth=0){if(!isInstrumentable(obj))return obj;let{mutate=!1,path=[]}=options,keys=options.getKeys?options.getKeys(obj,depth):Object.keys(obj);return depth+=1,keys.reduce((acc,key)=>{let descriptor=getPropertyDescriptor(obj,key);if(typeof descriptor?.get=="function"){let getter=()=>descriptor?.get?.bind(obj)?.();return Object.defineProperty(acc,key,{get:()=>this.instrument(getter(),{...options,path:path.concat(key)},depth)}),acc}let value=obj[key];return typeof value!="function"?(acc[key]=this.instrument(value,{...options,path:path.concat(key)},depth),acc):"__originalFn__"in value&&typeof value.__originalFn__=="function"?(acc[key]=value,acc):(acc[key]=(...args)=>this.track(key,value,obj,args,options),acc[key].__originalFn__=value,Object.defineProperty(acc[key],"name",{value:key,writable:!1}),Object.keys(value).length>0&&Object.assign(acc[key],this.instrument({...value},{...options,path:path.concat(key)},depth)),acc)},mutate?obj:construct(obj))}track(method,fn,object,args,options){let storyId=args?.[0]?.__storyId__||import_global.global.__STORYBOOK_PREVIEW__?.selectionStore?.selection?.storyId,{cursor,ancestors}=this.getState(storyId);this.setState(storyId,{cursor:cursor+1});let id=`${ancestors.slice(-1)[0]||storyId} [${cursor}] ${method}`,{path=[],intercept=!1,retain=!1}=options,interceptable=typeof intercept=="function"?intercept(method,path):intercept,call={id,cursor,storyId,ancestors,path,method,args,interceptable,retain},result=(interceptable&&!ancestors.length?this.intercept:this.invoke).call(this,fn,object,call,options);return this.instrument(result,{...options,mutate:!0,path:[{__callId__:call.id}]})}intercept(fn,object,call,options){let{chainedCallIds,isDebugging,playUntil}=this.getState(call.storyId),isChainedUpon=chainedCallIds.has(call.id);return!isDebugging||isChainedUpon||playUntil?(playUntil===call.id&&this.setState(call.storyId,{playUntil:void 0}),this.invoke(fn,object,call,options)):new Promise(resolve=>{this.setState(call.storyId,({resolvers})=>({isLocked:!1,resolvers:{...resolvers,[call.id]:resolve}}))}).then(()=>(this.setState(call.storyId,state=>{let{[call.id]:_,...resolvers}=state.resolvers;return{isLocked:!0,resolvers}}),this.invoke(fn,object,call,options)))}invoke(fn,object,call,options){let{callRefsByResult,renderPhase}=this.getState(call.storyId),maximumDepth=25,serializeValues=(value,depth,seen)=>{if(seen.includes(value))return"[Circular]";if(seen=[...seen,value],depth>maximumDepth)return"...";if(callRefsByResult.has(value))return callRefsByResult.get(value);if(value instanceof Array)return value.map(it=>serializeValues(it,++depth,seen));if(value instanceof Date)return{__date__:{value:value.toISOString()}};if(value instanceof Error){let{name,message,stack}=value;return{__error__:{name,message,stack}}}if(value instanceof RegExp){let{flags,source}=value;return{__regexp__:{flags,source}}}if(value instanceof import_global.global.window?.HTMLElement){let{prefix,localName,id,classList,innerText}=value,classNames=Array.from(classList);return{__element__:{prefix,localName,id,classNames,innerText}}}return typeof value=="function"?{__function__:{name:"getMockName"in value?value.getMockName():value.name}}:typeof value=="symbol"?{__symbol__:{description:value.description}}:typeof value=="object"&&value?.constructor?.name&&value?.constructor?.name!=="Object"?{__class__:{name:value.constructor.name}}:Object.prototype.toString.call(value)==="[object Object]"?Object.fromEntries(Object.entries(value).map(([key,val])=>[key,serializeValues(val,++depth,seen)])):value},info={...call,args:call.args.map(arg=>serializeValues(arg,0,[]))};call.path.forEach(ref=>{ref?.__callId__&&this.setState(call.storyId,({chainedCallIds})=>({chainedCallIds:new Set(Array.from(chainedCallIds).concat(ref.__callId__))}))});let handleException=e=>{if(e instanceof Error){let{name,message,stack,callId=call.id}=e,{showDiff=void 0,diff:diff2=void 0,actual=void 0,expected=void 0}=e.name==="AssertionError"?processError(e):e,exception={name,message,stack,callId,showDiff,diff:diff2,actual,expected};if(this.update({...info,status:"error",exception}),this.setState(call.storyId,state=>({callRefsByResult:new Map([...Array.from(state.callRefsByResult.entries()),[e,{__callId__:call.id,retain:call.retain}]])})),call.ancestors?.length)throw Object.prototype.hasOwnProperty.call(e,"callId")||Object.defineProperty(e,"callId",{value:call.id}),e}throw e};try{if(renderPhase==="played"&&!call.retain)throw alreadyCompletedException;let finalArgs=(options.getArgs?options.getArgs(call,this.getState(call.storyId)):call.args).map(arg=>typeof arg!="function"||Object.keys(arg).length?arg:(...args)=>{let{cursor,ancestors}=this.getState(call.storyId);this.setState(call.storyId,{cursor:0,ancestors:[...ancestors,call.id]});let restore=()=>this.setState(call.storyId,{cursor,ancestors}),willRestore=!1;try{let res=arg(...args);return res instanceof Promise?(willRestore=!0,res.finally(restore)):res}finally{willRestore||restore()}}),result=fn.apply(object,finalArgs);return result&&["object","function","symbol"].includes(typeof result)&&this.setState(call.storyId,state=>({callRefsByResult:new Map([...Array.from(state.callRefsByResult.entries()),[result,{__callId__:call.id,retain:call.retain}]])})),this.update({...info,status:result instanceof Promise?"active":"done"}),result instanceof Promise?result.then(value=>(this.update({...info,status:"done"}),value),handleException):result}catch(e){return handleException(e)}}update(call){this.channel.emit(EVENTS.CALL,call),this.setState(call.storyId,({calls})=>{let callsById=calls.concat(call).reduce((a2,c)=>Object.assign(a2,{[c.id]:c}),{});return{calls:Object.values(callsById).sort((a2,b)=>a2.id.localeCompare(b.id,void 0,{numeric:!0}))}}),this.sync(call.storyId)}sync(storyId){let synchronize=()=>{let{isLocked,isPlaying}=this.getState(storyId),logItems=this.getLog(storyId),pausedAt=logItems.filter(({ancestors})=>!ancestors.length).find(item=>item.status==="waiting")?.callId,hasActive=logItems.some(item=>item.status==="active");if(isLocked||hasActive||logItems.length===0){let payload2={controlStates:controlsDisabled,logItems};this.channel.emit(EVENTS.SYNC,payload2);return}let hasPrevious=logItems.some(item=>item.status==="done"||item.status==="error"),payload={controlStates:{start:hasPrevious,back:hasPrevious,goto:!0,next:isPlaying,end:isPlaying},logItems,pausedAt};this.channel.emit(EVENTS.SYNC,payload)};this.setState(storyId,({syncTimeout})=>(clearTimeout(syncTimeout),{syncTimeout:setTimeout(synchronize,0)}))}};function instrument(obj,options={}){try{let forceInstrument=!1,skipInstrument=!1;return import_global.global.window?.location?.search?.includes("instrument=true")?forceInstrument=!0:import_global.global.window?.location?.search?.includes("instrument=false")&&(skipInstrument=!0),import_global.global.window?.parent===import_global.global.window&&!forceInstrument||skipInstrument?obj:(import_global.global.window&&!import_global.global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__&&(import_global.global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__=new Instrumenter),(import_global.global.window?.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__).instrument(obj,options))}catch(e){return import_client_logger.once.warn(e),obj}}function getPropertyDescriptor(obj,propName){let target=obj;for(;target!=null;){let descriptor=Object.getOwnPropertyDescriptor(target,propName);if(descriptor)return descriptor;target=Object.getPrototypeOf(target)}}0&&(module.exports={CallStates,EVENTS,instrument});