@opengovsg/confetti 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,8 +66,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
66
66
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
67
67
  PERFORMANCE OF THIS SOFTWARE.
68
68
  ***************************************************************************** */
69
- function Mc(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r,i,a=n.call(e),o=[];try{for(;(t===void 0||t-->0)&&!(r=a.next()).done;)o.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(i)throw i.error}}return o}var Nc;(function(e){e[e.NotStarted=0]=`NotStarted`,e[e.Running=1]=`Running`,e[e.Stopped=2]=`Stopped`})(Nc||={});var Pc={type:`xstate.init`};function Fc(e){return e===void 0?[]:[].concat(e)}function Q(e){return{type:`xstate.assign`,assignment:e}}function Ic(e,t){return typeof(e=typeof e==`string`&&t&&t[e]?t[e]:e)==`string`?{type:e}:typeof e==`function`?{type:e.name,exec:e}:e}function Lc(e){return function(t){return e===t}}function Rc(e){return typeof e==`string`?{type:e}:e}function zc(e,t){return{value:e,context:t,actions:[],changed:!1,matches:Lc(e)}}function Bc(e,t,n){var r=t,i=!1;return[e.filter(function(e){if(e.type===`xstate.assign`){i=!0;var t=Object.assign({},r);return typeof e.assignment==`function`?t=e.assignment(r,n):Object.keys(e.assignment).forEach(function(i){t[i]=typeof e.assignment[i]==`function`?e.assignment[i](r,n):e.assignment[i]}),r=t,!1}return!0}),r,i]}function Vc(e,t){t===void 0&&(t={});var n=Mc(Bc(Fc(e.states[e.initial].entry).map(function(e){return Ic(e,t.actions)}),e.context,Pc),2),r=n[0],i=n[1],a={config:e,_options:t,initialState:{value:e.initial,actions:r,context:i,matches:Lc(e.initial)},transition:function(t,n){var r,i,o=typeof t==`string`?{value:t,context:e.context}:t,s=o.value,c=o.context,l=Rc(n),u=e.states[s];if(u.on){var d=Fc(u.on[l.type]);try{for(var f=function(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)}(d),p=f.next();!p.done;p=f.next()){var m=p.value;if(m===void 0)return zc(s,c);var h=typeof m==`string`?{target:m}:m,g=h.target,_=h.actions,v=_===void 0?[]:_,y=h.cond,ee=y===void 0?function(){return!0}:y,te=g===void 0,ne=g??s,re=e.states[ne];if(ee(c,l)){var b=Mc(Bc((te?Fc(v):[].concat(u.exit,v,re.entry).filter(function(e){return e})).map(function(e){return Ic(e,a._options.actions)}),c,l),3),ie=b[0],ae=b[1],x=b[2],oe=g??s;return{value:oe,context:ae,actions:ie,changed:g!==s||ie.length>0||x,matches:Lc(oe)}}}}catch(e){r={error:e}}finally{try{p&&!p.done&&(i=f.return)&&i.call(f)}finally{if(r)throw r.error}}}return zc(s,c)}};return a}var Hc=function(e,t){return e.actions.forEach(function(n){var r=n.exec;return r&&r(e.context,t)})};function Uc(e){var t=e.initialState,n=Nc.NotStarted,r=new Set,i={_machine:e,send:function(i){n===Nc.Running&&(t=e.transition(t,i),Hc(t,Rc(i)),r.forEach(function(e){return e(t)}))},subscribe:function(e){return r.add(e),e(t),{unsubscribe:function(){return r.delete(e)}}},start:function(r){if(r){var a=typeof r==`object`?r:{context:e.config.context,value:r};t={value:a.value,actions:[],context:a.context,matches:Lc(a.value)}}return n=Nc.Running,Hc(t,Pc),i},stop:function(){return n=Nc.Stopped,r.clear(),i},get state(){return t},get status(){return n}};return i}function Wc(e,t){for(let n=e.length-1;n>=0;n--){let r=e[n];if(r.type===q.Meta&&r.timestamp<=t)return e.slice(n)}return e}function Gc(e,{getCastFn:t,applyEventsSynchronously:n,emitter:r}){return Uc(Vc({id:`player`,context:e,initial:`paused`,states:{playing:{on:{PAUSE:{target:`paused`,actions:[`pause`]},CAST_EVENT:{target:`playing`,actions:`castEvent`},END:{target:`paused`,actions:[`resetLastPlayedEvent`,`pause`]},ADD_EVENT:{target:`playing`,actions:[`addEvent`]}}},paused:{on:{PLAY:{target:`playing`,actions:[`recordTimeOffset`,`play`]},CAST_EVENT:{target:`paused`,actions:`castEvent`},TO_LIVE:{target:`live`,actions:[`startLive`]},ADD_EVENT:{target:`paused`,actions:[`addEvent`]}}},live:{on:{ADD_EVENT:{target:`live`,actions:[`addEvent`]},CAST_EVENT:{target:`live`,actions:[`castEvent`]}}}}},{actions:{castEvent:Q({lastPlayedEvent:(e,t)=>t.type===`CAST_EVENT`?t.payload.event:e.lastPlayedEvent}),recordTimeOffset:Q((e,t)=>{let n=e.timeOffset;return`payload`in t&&`timeOffset`in t.payload&&(n=t.payload.timeOffset),{...e,timeOffset:n,baselineTime:e.events[0].timestamp+n}}),play(e){let{timer:i,events:a,baselineTime:o,lastPlayedEvent:s}=e;i.clear();for(let e of a)jc(e,o);let c=Wc(a,o),l=s?.timestamp;s?.type===q.IncrementalSnapshot&&s.data.source===J.MouseMove&&(l=s.timestamp+s.data.positions[0]?.timeOffset),o<(l||0)&&r.emit(X.PlayBack);let u=[];for(let e of c)if(!(l&&l<o&&(e.timestamp<=l||e===s)))if(e.timestamp<o)u.push(e);else{let n=t(e,!1);i.addAction({doAction:()=>{n()},delay:e.delay})}n(u),r.emit(X.Flush),i.start()},pause(e){e.timer.clear()},resetLastPlayedEvent:Q(e=>({...e,lastPlayedEvent:null})),startLive:Q({baselineTime:(e,t)=>(e.timer.start(),t.type===`TO_LIVE`&&t.payload.baselineTime?t.payload.baselineTime:Date.now())}),addEvent:Q((e,n)=>{let{baselineTime:r,timer:i,events:a}=e;if(n.type===`ADD_EVENT`){let{event:e}=n.payload;jc(e,r);let o=a.length-1;if(!a[o]||a[o].timestamp<=e.timestamp)a.push(e);else{let t=-1,n=0;for(;n<=o;){let t=Math.floor((n+o)/2);a[t].timestamp<=e.timestamp?n=t+1:o=t-1}t===-1&&(t=n),a.splice(t,0,e)}let s=e.timestamp<r,c=t(e,s);s?c():i.isActive()&&i.addAction({doAction:()=>{c()},delay:e.delay})}return{...e,events:a}})}}))}function Kc(e){return Uc(Vc({id:`speed`,context:e,initial:`normal`,states:{normal:{on:{FAST_FORWARD:{target:`skipping`,actions:[`recordSpeed`,`setSpeed`]},SET_SPEED:{target:`normal`,actions:[`setSpeed`]}}},skipping:{on:{BACK_TO_NORMAL:{target:`normal`,actions:[`restoreSpeed`]},SET_SPEED:{target:`normal`,actions:[`setSpeed`]}}}}},{actions:{setSpeed:(e,t)=>{`payload`in t&&e.timer.setSpeed(t.payload.speed)},recordSpeed:Q({normalSpeed:e=>e.timer.speed}),restoreSpeed:e=>{e.timer.setSpeed(e.normalSpeed)}}}))}const qc=e=>[`.${e} { background: currentColor }`,`noscript { display: none !important; }`],Jc=new Map;function Yc(e,t){let n=Jc.get(e);return n||(n=new Map,Jc.set(e,n)),n.has(t)||n.set(t,[]),n.get(t)}function $(e,t,n){return async r=>{if(r&&typeof r==`object`&&`rr_type`in r){if(n&&(n.isUnchanged=!1),r.rr_type===`ImageBitmap`&&`args`in r){let i=await $(e,t,n)(r.args);return await createImageBitmap.apply(null,i)}else if(`index`in r){if(n||t===null)return r;let{rr_type:e,index:i}=r;return Yc(t,e)[i]}else if(`args`in r){let{rr_type:i,args:a}=r,o=window[i];return new o(...await Promise.all(a.map($(e,t,n))))}else if(`base64`in r)return Ec(r.base64);else if(`src`in r){let t=e.get(r.src);if(t)return t;{let t=new Image;return t.src=r.src,e.set(r.src,t),t}}else if(`data`in r&&r.rr_type===`Blob`){let i=await Promise.all(r.data.map($(e,t,n)));return new Blob(i,{type:r.type})}}else if(Array.isArray(r))return await Promise.all(r.map($(e,t,n)));return r}}function Xc(e,t){try{return t===xc.WebGL?e.getContext(`webgl`)||e.getContext(`experimental-webgl`):e.getContext(`webgl2`)}catch{return null}}const Zc=[`WebGLActiveInfo`,`WebGLBuffer`,`WebGLFramebuffer`,`WebGLProgram`,`WebGLRenderbuffer`,`WebGLShader`,`WebGLShaderPrecisionFormat`,`WebGLTexture`,`WebGLUniformLocation`,`WebGLVertexArrayObject`];function Qc(e,t){if(!t?.constructor)return;let{name:n}=t.constructor;if(!Zc.includes(n))return;let r=Yc(e,n);r.includes(t)||r.push(t)}async function $c({mutation:e,target:t,type:n,imageMap:r,errorHandler:i}){try{let i=Xc(t,n);if(!i)return;if(e.setter){i[e.property]=e.args[0];return}let a=i[e.property],o=await Promise.all(e.args.map($(r,i)));Qc(i,a.apply(i,o))}catch(t){i(e,t)}}async function el({event:e,mutations:t,target:n,imageMap:r,errorHandler:i}){let a=n.getContext(`2d`);if(!a){i(t[0],Error(`Canvas context is null`));return}let o=t.map(async e=>Promise.all(e.args.map($(r,a))));(await Promise.all(o)).forEach((n,o)=>{let s=t[o];try{if(s.setter){a[s.property]=s.args[0];return}let t=a[s.property];s.property===`drawImage`&&typeof s.args[0]==`string`?(r.get(e),t.apply(a,s.args)):t.apply(a,n)}catch(e){i(s,e)}})}async function tl({event:e,mutation:t,target:n,imageMap:r,canvasEventMap:i,errorHandler:a}){try{let o=i.get(e)||t,s=`commands`in o?o.commands:[o];if([xc.WebGL,xc.WebGL2].includes(t.type)){for(let e=0;e<s.length;e++){let i=s[e];await $c({mutation:i,type:t.type,target:n,imageMap:r,errorHandler:a})}return}await el({event:e,mutations:s,target:n,imageMap:r,errorHandler:a})}catch(e){a(t,e)}}var nl=class{constructor(e){s(this,`mediaMap`,new Map),s(this,`warn`),s(this,`service`),s(this,`speedService`),s(this,`emitter`),s(this,`getCurrentTime`),s(this,`metadataCallbackMap`,new Map),this.warn=e.warn,this.service=e.service,this.speedService=e.speedService,this.emitter=e.emitter,this.getCurrentTime=e.getCurrentTime,this.emitter.on(X.Start,this.start.bind(this)),this.emitter.on(X.SkipStart,this.start.bind(this)),this.emitter.on(X.Pause,this.pause.bind(this)),this.emitter.on(X.Finish,this.pause.bind(this)),this.speedService.subscribe(()=>{this.syncAllMediaElements()})}syncAllMediaElements(e={pause:!1}){this.mediaMap.forEach((t,n)=>{this.syncTargetWithState(n),e.pause&&n.pause()})}start(){this.syncAllMediaElements()}pause(){this.syncAllMediaElements({pause:!0})}seekTo({time:e,target:t,mediaState:n}){if(n.isPlaying){let r=(e-n.lastInteractionTimeOffset)/1e3*n.playbackRate,i=`duration`in t&&t.duration;if(Number.isNaN(i)){this.waitForMetadata(t);return}let a=n.currentTimeAtLastInteraction+r;t.loop&&i!==!1&&(a%=i),t.currentTime=a}else t.pause(),t.currentTime=n.currentTimeAtLastInteraction}waitForMetadata(e){if(this.metadataCallbackMap.has(e)||!(`addEventListener`in e))return;let t=()=>{this.metadataCallbackMap.delete(e);let t=this.mediaMap.get(e);t&&this.seekTo({time:this.getCurrentTime(),target:e,mediaState:t})};this.metadataCallbackMap.set(e,t),e.addEventListener(`loadedmetadata`,t,{once:!0})}getMediaStateFromMutation({target:e,timeOffset:t,mutation:n}){let r=this.mediaMap.get(e),{type:i,playbackRate:a,currentTime:o,muted:s,volume:c,loop:l}=n;return{isPlaying:i===Sc.Play||i!==Sc.Pause&&(r?.isPlaying||e.getAttribute(`autoplay`)!==null),currentTimeAtLastInteraction:o??r?.currentTimeAtLastInteraction??0,lastInteractionTimeOffset:t,playbackRate:a??r?.playbackRate??1,volume:c??r?.volume??1,muted:s??r?.muted??e.getAttribute(`muted`)===null,loop:l??r?.loop??e.getAttribute(`loop`)===null}}syncTargetWithState(e){let t=this.mediaMap.get(e);if(!t)return;let{muted:n,loop:r,volume:i,isPlaying:a}=t,o=this.service.state.matches(`paused`),s=t.playbackRate*this.speedService.state.context.timer.speed;try{this.seekTo({time:this.getCurrentTime(),target:e,mediaState:t}),e.volume!==i&&(e.volume=i),e.muted=n,e.loop=r,e.playbackRate!==s&&(e.playbackRate=s),a&&!o?e.play():e.pause()}catch(e){this.warn(`Failed to replay media interactions: ${e.message||e}`)}}addMediaElements(e,t,n){if(![`AUDIO`,`VIDEO`].includes(e.nodeName))return;let r=e,i=n.getMeta(r);if(!i||!(`attributes`in i))return;let a=this.service.state.matches(`paused`),o=i.attributes,s=!1;s=o.rr_mediaState?o.rr_mediaState===`played`:r.getAttribute(`autoplay`)!==null,s&&a&&r.pause();let c=1;typeof o.rr_mediaPlaybackRate==`number`&&(c=o.rr_mediaPlaybackRate);let l=!1;l=typeof o.rr_mediaMuted==`boolean`?o.rr_mediaMuted:r.getAttribute(`muted`)!==null;let u=!1;u=typeof o.rr_mediaLoop==`boolean`?o.rr_mediaLoop:r.getAttribute(`loop`)!==null;let d=1;typeof o.rr_mediaVolume==`number`&&(d=o.rr_mediaVolume);let f=0;typeof o.rr_mediaCurrentTime==`number`&&(f=o.rr_mediaCurrentTime),this.mediaMap.set(r,{isPlaying:s,currentTimeAtLastInteraction:f,lastInteractionTimeOffset:t,playbackRate:c,volume:d,muted:l,loop:u}),this.syncTargetWithState(r)}mediaMutation({target:e,timeOffset:t,mutation:n}){this.mediaMap.set(e,this.getMediaStateFromMutation({target:e,timeOffset:t,mutation:n})),this.syncTargetWithState(e)}isSupportedMediaElement(e){return[`AUDIO`,`VIDEO`].includes(e.nodeName)}reset(){this.mediaMap.clear()}};function rl(e,t){if(e.nodeName!==`DIALOG`||e instanceof V)return;let n=e,r=n.open,i=r&&n.matches(`dialog:modal`),a=n.getAttribute(`rr_open_mode`),o=typeof t?.attributes.open==`string`||typeof n.getAttribute(`open`)==`string`,s=a===`modal`;if(!(r&&!(i&&a===`non-modal`||!i&&s))){if(!n.isConnected){console.warn(`dialog is not attached to the dom`,n);return}r&&n.close(),o&&(s?n.showModal():n.show())}}function il(e,t){if(e.nodeName!==`DIALOG`||e instanceof V)return;let n=e;if(!n.isConnected){console.warn(`dialog is not attached to the dom`,n);return}t.attributes.open===null&&(n.removeAttribute(`open`),n.removeAttribute(`rr_open_mode`))}const al=Dc||Oc,ol=`[replayer]`,sl={duration:500,lineCap:`round`,lineWidth:3,strokeStyle:`red`};function cl(e){return e.type==q.IncrementalSnapshot&&(e.data.source==J.TouchMove||e.data.source==J.MouseInteraction&&e.data.type==Y.TouchStart)}var ll=class{constructor(e,t){if(s(this,`wrapper`),s(this,`iframe`),s(this,`service`),s(this,`speedService`),s(this,`config`),s(this,`usingVirtualDom`,!1),s(this,`virtualDom`,new ws),s(this,`mouse`),s(this,`mouseTail`,null),s(this,`tailPositions`,[]),s(this,`emitter`,al()),s(this,`nextUserInteractionEvent`),s(this,`legacy_missingNodeRetryMap`,{}),s(this,`cache`,yr()),s(this,`imageMap`,new Map),s(this,`canvasEventMap`,new Map),s(this,`mirror`,m()),s(this,`styleMirror`,new bc),s(this,`mediaManager`),s(this,`firstFullSnapshot`,null),s(this,`newDocumentQueue`,[]),s(this,`mousePos`,null),s(this,`touchActive`,null),s(this,`lastMouseDownEvent`,null),s(this,`lastHoveredRootNode`),s(this,`lastSelectionData`,null),s(this,`constructedStyleMutations`,[]),s(this,`adoptedStyleSheets`,[]),s(this,`handleResize`,e=>{this.iframe.style.display=`inherit`;for(let t of[this.mouseTail,this.iframe])t&&(t.setAttribute(`width`,String(e.width)),t.setAttribute(`height`,String(e.height)))}),s(this,`applyEventsSynchronously`,e=>{for(let t of e){switch(t.type){case q.DomContentLoaded:case q.Load:case q.Custom:continue;case q.FullSnapshot:case q.Meta:case q.Plugin:case q.IncrementalSnapshot:break}this.getCastFn(t,!0)()}}),s(this,`getCastFn`,(e,t=!1)=>{let n;switch(e.type){case q.DomContentLoaded:case q.Load:break;case q.Custom:n=()=>{this.emitter.emit(X.CustomEvent,e)};break;case q.Meta:n=()=>this.emitter.emit(X.Resize,{width:e.data.width,height:e.data.height});break;case q.FullSnapshot:n=()=>{var n;if(this.firstFullSnapshot){if(this.firstFullSnapshot===e){this.firstFullSnapshot=!0;return}}else this.firstFullSnapshot=!0;this.mediaManager.reset(),this.styleMirror.reset(),this.rebuildFullSnapshot(e,t),(n=this.iframe.contentWindow)==null||n.scrollTo(e.data.initialOffset)};break;case q.IncrementalSnapshot:n=()=>{if(this.applyIncremental(e,t),!t&&(e===this.nextUserInteractionEvent&&(this.nextUserInteractionEvent=null,this.backToNormal()),this.config.skipInactive&&!this.nextUserInteractionEvent)){for(let t of this.service.state.context.events)if(!(t.timestamp<=e.timestamp)&&this.isUserInteraction(t)){t.delay-e.delay>this.config.inactivePeriodThreshold*this.speedService.state.context.timer.speed&&(this.nextUserInteractionEvent=t);break}if(this.nextUserInteractionEvent){let t=this.nextUserInteractionEvent.delay-e.delay,n={speed:Math.min(Math.round(t/5e3),this.config.maxSpeed)};this.speedService.send({type:`FAST_FORWARD`,payload:n}),this.emitter.emit(X.SkipStart,n)}}};break}return()=>{n&&n();for(let n of this.config.plugins||[])n.handler&&n.handler(e,t,{replayer:this});this.service.send({type:`CAST_EVENT`,payload:{event:e}});let r=this.service.state.context.events.length-1;if(!this.config.liveMode&&e===this.service.state.context.events[r]){let t=()=>{r<this.service.state.context.events.length-1||(this.backToNormal(),this.service.send(`END`),this.emitter.emit(X.Finish))},n=50;e.type===q.IncrementalSnapshot&&e.data.source===J.MouseMove&&e.data.positions.length&&(n+=Math.max(0,-e.data.positions[0].timeOffset)),setTimeout(t,n)}this.emitter.emit(X.EventCast,e)}}),!t?.liveMode&&e.length<2)throw Error(`Replayer need at least 2 events.`);let n={speed:1,maxSpeed:360,root:document.body,loadTimeout:0,skipInactive:!1,inactivePeriodThreshold:10*1e3,showWarning:!0,showDebug:!1,blockClass:`rr-block`,liveMode:!1,insertStyleRules:[],triggerFocus:!0,UNSAFE_replayCanvas:!1,pauseAnimation:!0,mouseTail:sl,useVirtualDom:!0,logger:console};this.config=Object.assign({},n,t),this.handleResize=this.handleResize.bind(this),this.getCastFn=this.getCastFn.bind(this),this.applyEventsSynchronously=this.applyEventsSynchronously.bind(this),this.emitter.on(X.Resize,this.handleResize),this.setupDom();for(let e of this.config.plugins||[])e.getMirror&&e.getMirror({nodeMirror:this.mirror});this.emitter.on(X.Flush,()=>{if(this.usingVirtualDom){let e={mirror:this.mirror,applyCanvas:(e,t,n)=>{tl({event:e,mutation:t,target:n,imageMap:this.imageMap,canvasEventMap:this.canvasEventMap,errorHandler:this.warnCanvasMutationFailed.bind(this)})},applyInput:this.applyInput.bind(this),applyScroll:this.applyScroll.bind(this),applyStyleSheetMutation:(e,t)=>{e.source===J.StyleSheetRule?this.applyStyleSheetRule(e,t):e.source===J.StyleDeclaration&&this.applyStyleDeclaration(e,t)},afterAppend:(e,t)=>{for(let n of this.config.plugins||[])n.onBuild&&n.onBuild(e,{id:t,replayer:this})}};if(this.iframe.contentDocument)try{_s(this.iframe.contentDocument,this.virtualDom,e,this.virtualDom.mirror)}catch(e){console.warn(e)}if(this.virtualDom.destroyTree(),this.usingVirtualDom=!1,Object.keys(this.legacy_missingNodeRetryMap).length)for(let t in this.legacy_missingNodeRetryMap)try{let n=this.legacy_missingNodeRetryMap[t],r=Ss(n.node,this.mirror,this.virtualDom.mirror);_s(r,n.node,e,this.virtualDom.mirror),n.node=r}catch(e){this.warn(e)}this.constructedStyleMutations.forEach(e=>{this.applyStyleSheetMutation(e)}),this.constructedStyleMutations=[],this.adoptedStyleSheets.forEach(e=>{this.applyAdoptedStyleSheet(e)}),this.adoptedStyleSheets=[]}if(this.mousePos&&=(this.moveAndHover(this.mousePos.x,this.mousePos.y,this.mousePos.id,!0,this.mousePos.debugData),null),this.touchActive===!0?this.mouse.classList.add(`touch-active`):this.touchActive===!1&&this.mouse.classList.remove(`touch-active`),this.touchActive=null,this.lastMouseDownEvent){let[e,t]=this.lastMouseDownEvent;e.dispatchEvent(t)}this.lastMouseDownEvent=null,this.lastSelectionData&&=(this.applySelection(this.lastSelectionData),null)}),this.emitter.on(X.PlayBack,()=>{this.firstFullSnapshot=null,this.mirror.reset(),this.styleMirror.reset(),this.mediaManager.reset()});let r=new Ac([],{speed:this.config.speed});this.service=Gc({events:e.map(e=>t&&t.unpackFn?t.unpackFn(e):e).sort((e,t)=>e.timestamp-t.timestamp),timer:r,timeOffset:0,baselineTime:0,lastPlayedEvent:null},{getCastFn:this.getCastFn,applyEventsSynchronously:this.applyEventsSynchronously,emitter:this.emitter}),this.service.start(),this.service.subscribe(e=>{this.emitter.emit(X.StateChange,{player:e})}),this.speedService=Kc({normalSpeed:-1,timer:r}),this.speedService.start(),this.speedService.subscribe(e=>{this.emitter.emit(X.StateChange,{speed:e})}),this.mediaManager=new nl({warn:this.warn.bind(this),service:this.service,speedService:this.speedService,emitter:this.emitter,getCurrentTime:this.getCurrentTime.bind(this)});let i=this.service.state.context.events.find(e=>e.type===q.Meta),a=this.service.state.context.events.find(e=>e.type===q.FullSnapshot);if(i){let{width:e,height:t}=i.data;setTimeout(()=>{this.emitter.emit(X.Resize,{width:e,height:t})},0)}a&&setTimeout(()=>{var e;this.firstFullSnapshot||(this.firstFullSnapshot=a,this.rebuildFullSnapshot(a),(e=this.iframe.contentWindow)==null||e.scrollTo(a.data.initialOffset))},1),this.service.state.context.events.find(cl)&&this.mouse.classList.add(`touch-device`)}get timer(){return this.service.state.context.timer}on(e,t){return this.emitter.on(e,t),this}off(e,t){return this.emitter.off(e,t),this}setConfig(e){Object.keys(e).forEach(t=>{e[t],this.config[t]=e[t]}),this.config.skipInactive||this.backToNormal(),e.speed!==void 0&&this.speedService.send({type:`SET_SPEED`,payload:{speed:e.speed}}),e.mouseTail!==void 0&&(e.mouseTail===!1?this.mouseTail&&(this.mouseTail.style.display=`none`):(this.mouseTail||(this.mouseTail=document.createElement(`canvas`),this.mouseTail.width=Number.parseFloat(this.iframe.width),this.mouseTail.height=Number.parseFloat(this.iframe.height),this.mouseTail.classList.add(`replayer-mouse-tail`),this.wrapper.insertBefore(this.mouseTail,this.iframe)),this.mouseTail.style.display=`inherit`))}getMetaData(){let e=this.service.state.context.events[0],t=this.service.state.context.events[this.service.state.context.events.length-1];return{startTime:e.timestamp,endTime:t.timestamp,totalTime:t.timestamp-e.timestamp}}getCurrentTime(){return this.timer.timeOffset+this.getTimeOffset()}getTimeOffset(){let{baselineTime:e,events:t}=this.service.state.context;return e-t[0].timestamp}getMirror(){return this.mirror}play(e=0){var t;this.service.state.matches(`paused`)||this.service.send({type:`PAUSE`}),this.service.send({type:`PLAY`,payload:{timeOffset:e}}),(t=this.iframe.contentDocument?.getElementsByTagName(`html`)[0])==null||t.classList.remove(`rrweb-paused`),this.emitter.emit(X.Start)}pause(e){var t;e===void 0&&this.service.state.matches(`playing`)&&this.service.send({type:`PAUSE`}),typeof e==`number`&&(this.play(e),this.service.send({type:`PAUSE`})),(t=this.iframe.contentDocument?.getElementsByTagName(`html`)[0])==null||t.classList.add(`rrweb-paused`),this.emitter.emit(X.Pause)}resume(e=0){this.warn(`The 'resume' was deprecated in 1.0. Please use 'play' method which has the same interface.`),this.play(e),this.emitter.emit(X.Resume)}destroy(){this.pause(),this.mirror.reset(),this.styleMirror.reset(),this.mediaManager.reset(),this.config.root.removeChild(this.wrapper),this.emitter.emit(X.Destroy)}startLive(e){this.service.send({type:`TO_LIVE`,payload:{baselineTime:e}})}addEvent(e){let t=this.config.unpackFn?this.config.unpackFn(e):e;cl(t)&&this.mouse.classList.add(`touch-device`),Promise.resolve().then(()=>this.service.send({type:`ADD_EVENT`,payload:{event:t}}))}enableInteract(){this.iframe.setAttribute(`scrolling`,`auto`),this.iframe.style.pointerEvents=`auto`}disableInteract(){this.iframe.setAttribute(`scrolling`,`no`),this.iframe.style.pointerEvents=`none`}resetCache(){this.cache=yr()}setupDom(){this.wrapper=document.createElement(`div`),this.wrapper.classList.add(`replayer-wrapper`),this.config.root.appendChild(this.wrapper),this.mouse=document.createElement(`div`),this.mouse.classList.add(`replayer-mouse`),this.wrapper.appendChild(this.mouse),this.config.mouseTail!==!1&&(this.mouseTail=document.createElement(`canvas`),this.mouseTail.classList.add(`replayer-mouse-tail`),this.mouseTail.style.display=`inherit`,this.wrapper.appendChild(this.mouseTail)),this.iframe=document.createElement(`iframe`);let e=[`allow-same-origin`];this.config.UNSAFE_replayCanvas&&e.push(`allow-scripts`),this.iframe.style.display=`none`,this.iframe.setAttribute(`sandbox`,e.join(` `)),this.disableInteract(),this.wrapper.appendChild(this.iframe),this.iframe.contentWindow&&this.iframe.contentDocument&&(kc(this.iframe.contentWindow,this.iframe.contentDocument),dc(this.iframe.contentWindow))}rebuildFullSnapshot(e,t=!1){if(!this.iframe.contentDocument)return this.warn(`Looks like your replayer has been destroyed.`);Object.keys(this.legacy_missingNodeRetryMap).length&&this.warn(`Found unresolved missing node map`,this.legacy_missingNodeRetryMap),this.legacy_missingNodeRetryMap={};let n=[],r=new Set,i=(t,i)=>{if(t.nodeName===`DIALOG`&&r.add(t),this.collectIframeAndAttachDocument(n,t),this.mediaManager.isSupportedMediaElement(t)){let{events:n}=this.service.state.context;this.mediaManager.addMediaElements(t,e.timestamp-n[0].timestamp,this.mirror)}for(let e of this.config.plugins||[])e.onBuild&&e.onBuild(t,{id:i,replayer:this})};this.usingVirtualDom&&=(this.virtualDom.destroyTree(),!1),this.mirror.reset(),Er(e.data.node,{doc:this.iframe.contentDocument,afterAppend:i,cache:this.cache,mirror:this.mirror}),i(this.iframe.contentDocument,e.data.node.id);for(let{mutationInQueue:e,builtNode:t}of n)this.attachDocumentToIframe(e,t),this.newDocumentQueue=this.newDocumentQueue.filter(t=>t!==e);let{documentElement:a,head:o}=this.iframe.contentDocument;this.insertStyleRules(a,o),r.forEach(e=>rl(e)),this.service.state.matches(`playing`)||this.iframe.contentDocument.getElementsByTagName(`html`)[0].classList.add(`rrweb-paused`),this.emitter.emit(X.FullsnapshotRebuilded,e),t||this.waitForStylesheetLoad(),this.config.UNSAFE_replayCanvas&&this.preloadAllImages()}insertStyleRules(e,t){var n;let r=qc(this.config.blockClass).concat(this.config.insertStyleRules);if(this.config.pauseAnimation&&r.push(`html.rrweb-paused *, html.rrweb-paused *:before, html.rrweb-paused *:after { animation-play-state: paused !important; }`),r.length)if(this.usingVirtualDom){let n=this.virtualDom.createElement(`style`);this.virtualDom.mirror.add(n,Bs(n,this.virtualDom.unserializedId)),e.insertBefore(n,t),n.rules.push({source:J.StyleSheetRule,adds:r.map((e,t)=>({rule:e,index:t}))})}else{let i=document.createElement(`style`);e.insertBefore(i,t);for(let e=0;e<r.length;e++)(n=i.sheet)==null||n.insertRule(r[e],e)}}attachDocumentToIframe(e,t){let n=this.usingVirtualDom?this.virtualDom.mirror:this.mirror,r=[],i=new Set,a=(e,a)=>{e.nodeName===`DIALOG`&&i.add(e),this.collectIframeAndAttachDocument(r,e);let o=n.getMeta(e);if(o?.type===Z.Element&&o?.tagName.toUpperCase()===`HTML`){let{documentElement:e,head:n}=t.contentDocument;this.insertStyleRules(e,n)}if(!this.usingVirtualDom)for(let t of this.config.plugins||[])t.onBuild&&t.onBuild(e,{id:a,replayer:this})};Cr(e.node,{doc:t.contentDocument,mirror:n,hackCss:!0,skipChild:!1,afterAppend:a,cache:this.cache}),a(t.contentDocument,e.node.id);for(let{mutationInQueue:e,builtNode:t}of r)this.attachDocumentToIframe(e,t),this.newDocumentQueue=this.newDocumentQueue.filter(t=>t!==e);i.forEach(e=>rl(e))}collectIframeAndAttachDocument(e,t){if(mc(t,this.mirror)){let n=this.newDocumentQueue.find(e=>e.parentId===this.mirror.getId(t));n&&e.push({mutationInQueue:n,builtNode:t})}}waitForStylesheetLoad(){let e=this.iframe.contentDocument?.head;if(e){let t=new Set,n,r=this.service.state,i=()=>{r=this.service.state};this.emitter.on(X.Start,i),this.emitter.on(X.Pause,i);let a=()=>{this.emitter.off(X.Start,i),this.emitter.off(X.Pause,i)};e.querySelectorAll(`link[rel="stylesheet"]`).forEach(e=>{e.sheet||(t.add(e),e.addEventListener(`load`,()=>{t.delete(e),t.size===0&&n!==-1&&(r.matches(`playing`)&&this.play(this.getCurrentTime()),this.emitter.emit(X.LoadStylesheetEnd),n&&clearTimeout(n),a())}))}),t.size>0&&(this.service.send({type:`PAUSE`}),this.emitter.emit(X.LoadStylesheetStart),n=setTimeout(()=>{r.matches(`playing`)&&this.play(this.getCurrentTime()),n=-1,a()},this.config.loadTimeout))}}async preloadAllImages(){let e=[];for(let t of this.service.state.context.events)t.type===q.IncrementalSnapshot&&t.data.source===J.CanvasMutation&&(e.push(this.deserializeAndPreloadCanvasEvents(t.data,t)),(`commands`in t.data?t.data.commands:[t.data]).forEach(e=>{this.preloadImages(e,t)}));return Promise.all(e)}preloadImages(e,t){if(e.property===`drawImage`&&typeof e.args[0]==`string`&&!this.imageMap.has(t)){let e=document.createElement(`canvas`),t=e.getContext(`2d`),n=t?.createImageData(e.width,e.height);t?.putImageData(n,0,0)}}async deserializeAndPreloadCanvasEvents(e,t){if(!this.canvasEventMap.has(t)){let n={isUnchanged:!0};if(`commands`in e){let r=await Promise.all(e.commands.map(async e=>{let t=await Promise.all(e.args.map($(this.imageMap,null,n)));return{...e,args:t}}));n.isUnchanged===!1&&this.canvasEventMap.set(t,{...e,commands:r})}else{let r=await Promise.all(e.args.map($(this.imageMap,null,n)));n.isUnchanged===!1&&this.canvasEventMap.set(t,{...e,args:r})}}}applyIncremental(e,t){var n,r;let{data:i}=e;switch(i.source){case J.Mutation:try{this.applyMutation(i,t)}catch(e){this.warn(`Exception in mutation ${e.message||e}`,i)}break;case J.Drag:case J.TouchMove:case J.MouseMove:if(t){let e=i.positions[i.positions.length-1];this.mousePos={x:e.x,y:e.y,id:e.id,debugData:i}}else i.positions.forEach(n=>{let r={doAction:()=>{this.moveAndHover(n.x,n.y,n.id,t,i)},delay:n.timeOffset+e.timestamp-this.service.state.context.baselineTime};this.timer.addAction(r)}),this.timer.addAction({doAction(){},delay:e.delay-i.positions[0]?.timeOffset});break;case J.MouseInteraction:{if(i.id===-1)break;let e=new Event(h(Y[i.type])),n=this.mirror.getNode(i.id);if(!n)return this.debugNodeNotFound(i,i.id);this.emitter.emit(X.MouseInteraction,{type:i.type,target:n});let{triggerFocus:r}=this.config;switch(i.type){case Y.Blur:`blur`in n&&n.blur();break;case Y.Focus:r&&n.focus&&n.focus({preventScroll:!0});break;case Y.Click:case Y.TouchStart:case Y.TouchEnd:case Y.MouseDown:case Y.MouseUp:t?(i.type===Y.TouchStart?this.touchActive=!0:i.type===Y.TouchEnd&&(this.touchActive=!1),i.type===Y.MouseDown?this.lastMouseDownEvent=[n,e]:i.type===Y.MouseUp&&(this.lastMouseDownEvent=null),this.mousePos={x:i.x||0,y:i.y||0,id:i.id,debugData:i}):(i.type===Y.TouchStart&&(this.tailPositions.length=0),this.moveAndHover(i.x||0,i.y||0,i.id,t,i),i.type===Y.Click?(this.mouse.classList.remove(`active`),this.mouse.offsetWidth,this.mouse.classList.add(`active`)):i.type===Y.TouchStart?(this.mouse.offsetWidth,this.mouse.classList.add(`touch-active`)):i.type===Y.TouchEnd?this.mouse.classList.remove(`touch-active`):n.dispatchEvent(e));break;case Y.TouchCancel:t?this.touchActive=!1:this.mouse.classList.remove(`touch-active`);break;default:n.dispatchEvent(e)}break}case J.Scroll:if(i.id===-1)break;if(this.usingVirtualDom){let e=this.virtualDom.mirror.getNode(i.id);if(!e)return this.debugNodeNotFound(i,i.id);e.scrollData=i;break}this.applyScroll(i,t);break;case J.ViewportResize:this.emitter.emit(X.Resize,{width:i.width,height:i.height});break;case J.Input:if(i.id===-1)break;if(this.usingVirtualDom){let e=this.virtualDom.mirror.getNode(i.id);if(!e)return this.debugNodeNotFound(i,i.id);e.inputData=i;break}this.applyInput(i);break;case J.MediaInteraction:{let t=this.usingVirtualDom?this.virtualDom.mirror.getNode(i.id):this.mirror.getNode(i.id);if(!t)return this.debugNodeNotFound(i,i.id);let n=t,{events:r}=this.service.state.context;this.mediaManager.mediaMutation({target:n,timeOffset:e.timestamp-r[0].timestamp,mutation:i});break}case J.StyleSheetRule:case J.StyleDeclaration:this.usingVirtualDom?i.styleId?this.constructedStyleMutations.push(i):i.id&&((n=this.virtualDom.mirror.getNode(i.id))==null||n.rules.push(i)):this.applyStyleSheetMutation(i);break;case J.CanvasMutation:if(!this.config.UNSAFE_replayCanvas)return;if(this.usingVirtualDom){let t=this.virtualDom.mirror.getNode(i.id);if(!t)return this.debugNodeNotFound(i,i.id);t.canvasMutations.push({event:e,mutation:i})}else{let t=this.mirror.getNode(i.id);if(!t)return this.debugNodeNotFound(i,i.id);tl({event:e,mutation:i,target:t,imageMap:this.imageMap,canvasEventMap:this.canvasEventMap,errorHandler:this.warnCanvasMutationFailed.bind(this)})}break;case J.Font:try{let e=new FontFace(i.family,i.buffer?new Uint8Array(JSON.parse(i.fontSource)):i.fontSource,i.descriptors);(r=this.iframe.contentDocument)==null||r.fonts.add(e)}catch(e){this.warn(e)}break;case J.Selection:if(t){this.lastSelectionData=i;break}this.applySelection(i);break;case J.AdoptedStyleSheet:this.usingVirtualDom?this.adoptedStyleSheets.push(i):this.applyAdoptedStyleSheet(i);break}}applyMutation(e,t){if(this.config.useVirtualDom&&!this.usingVirtualDom&&t&&(this.usingVirtualDom=!0,Ls(this.iframe.contentDocument,this.mirror,this.virtualDom),Object.keys(this.legacy_missingNodeRetryMap).length))for(let e in this.legacy_missingNodeRetryMap)try{let t=this.legacy_missingNodeRetryMap[e],n=Is(t.node,this.virtualDom,this.mirror);n&&(t.node=n)}catch(e){this.warn(e)}let n=this.usingVirtualDom?this.virtualDom.mirror:this.mirror;e.removes=e.removes.filter(t=>n.getNode(t.id)?!0:(this.warnNodeNotFound(e,t.id),!1)),e.removes.forEach(t=>{let r=n.getNode(t.id);if(!r)return;let i=n.getNode(t.parentId);if(!i)return this.warnNodeNotFound(e,t.parentId);if(t.isShadow&&gc(i)&&(i=i.shadowRoot),n.removeNodeFromMap(r),i)try{i.removeChild(r),this.usingVirtualDom&&r.nodeName===`#text`&&i.nodeName===`STYLE`&&i.rules?.length>0&&(i.rules=[])}catch(t){if(t instanceof DOMException)this.warn(`parent could not remove child in mutation`,i,r,e);else throw t}});let r={...this.legacy_missingNodeRetryMap},i=[],a=e=>{let t=null;return e.nextId&&(t=n.getNode(e.nextId)),e.nextId!==null&&e.nextId!==void 0&&e.nextId!==-1&&!t},o=e=>{if(!this.iframe.contentDocument)return this.warn(`Looks like your replayer has been destroyed.`);let t=n.getNode(e.parentId);if(!t)return e.node.type===Z.Document?this.newDocumentQueue.push(e):i.push(e);e.node.isShadow&&(gc(t)||t.attachShadow({mode:`open`}),t=t.shadowRoot);let o=null,s=null;if(e.previousId&&(o=n.getNode(e.previousId)),e.nextId&&(s=n.getNode(e.nextId)),a(e))return i.push(e);if(e.node.rootId&&!n.getNode(e.node.rootId))return;let c=e.node.rootId?n.getNode(e.node.rootId):this.usingVirtualDom?this.virtualDom:this.iframe.contentDocument;if(mc(t,n)){this.attachDocumentToIframe(e,t);return}let l=(e,t)=>{if(!this.usingVirtualDom){rl(e);for(let n of this.config.plugins||[])n.onBuild&&n.onBuild(e,{id:t,replayer:this})}},u=Cr(e.node,{doc:c,mirror:n,skipChild:!0,hackCss:!0,cache:this.cache,afterAppend:l});if(e.previousId===-1||e.nextId===-1){r[e.node.id]={node:u,mutation:e};return}let d=n.getMeta(t);if(d&&d.type===Z.Element&&e.node.type===Z.Text){let e=Array.isArray(t.childNodes)?t.childNodes:Array.from(t.childNodes);if(d.tagName===`textarea`)for(let n of e)n.nodeType===t.TEXT_NODE&&t.removeChild(n);else if(d.tagName===`style`&&e.length===1)for(let r of e)r.nodeType===t.TEXT_NODE&&!n.hasNode(r)&&(u.textContent=r.textContent,t.removeChild(r))}else if(d?.type===Z.Document){let n=t;e.node.type===Z.DocumentType&&n.childNodes[0]?.nodeType===Node.DOCUMENT_TYPE_NODE&&n.removeChild(n.childNodes[0]),u.nodeName===`HTML`&&n.documentElement&&n.removeChild(n.documentElement)}if(o&&o.nextSibling&&o.nextSibling.parentNode?t.insertBefore(u,o.nextSibling):s&&s.parentNode?t.contains(s)?t.insertBefore(u,s):t.insertBefore(u,null):t.appendChild(u),l(u,e.node.id),this.usingVirtualDom&&u.nodeName===`#text`&&t.nodeName===`STYLE`&&t.rules?.length>0&&(t.rules=[]),mc(u,this.mirror)){let e=this.mirror.getId(u),t=this.newDocumentQueue.find(t=>t.parentId===e);t&&(this.attachDocumentToIframe(t,u),this.newDocumentQueue=this.newDocumentQueue.filter(e=>e!==t))}(e.previousId||e.nextId)&&this.legacy_resolveMissingNode(r,t,u,e)};e.adds.forEach(e=>{o(e)});let s=Date.now();for(;i.length;){let e=fc(i);if(i.length=0,Date.now()-s>500){this.warn(`Timeout in the loop, please check the resolve tree data:`,e);break}for(let t of e)n.getNode(t.value.parentId)?pc(t,e=>{o(e)}):this.debug(`Drop resolve tree since there is no parent for the root node.`,t)}Object.keys(r).length&&Object.assign(this.legacy_missingNodeRetryMap,r),yc(e.texts).forEach(t=>{let r=n.getNode(t.id);if(!r)return e.removes.find(e=>e.id===t.id)?void 0:this.warnNodeNotFound(e,t.id);let i=r.parentElement;if(t.value&&i&&i.tagName===`STYLE`?r.textContent=vr(t.value,this.cache):r.textContent=t.value,this.usingVirtualDom){let e=r.parentNode;e?.rules?.length>0&&(e.rules=[])}}),e.attributes.forEach(t=>{let r=n.getNode(t.id);if(!r)return e.removes.find(e=>e.id===t.id)?void 0:this.warnNodeNotFound(e,t.id);for(let e in t.attributes)if(typeof e==`string`){let i=t.attributes[e];if(i===null)r.removeAttribute(e),e===`open`&&il(r,t);else if(typeof i==`string`)try{if(e===`_cssText`&&(r.nodeName===`LINK`||r.nodeName===`STYLE`))try{let e=n.getMeta(r),i=Cr({...e,attributes:{...e.attributes,...t.attributes}},{doc:r.ownerDocument,mirror:n,skipChild:!0,hackCss:!0,cache:this.cache});Object.assign(e.attributes,t.attributes);let a=r.nextSibling,o=r.parentNode;if(i&&o){o.removeChild(r),o.insertBefore(i,a),n.replace(t.id,i);break}}catch{}if(e===`value`&&r.nodeName===`TEXTAREA`){let e=r;e.childNodes.forEach(t=>e.removeChild(t));let t=r.ownerDocument?.createTextNode(i);t&&e.appendChild(t)}else r.setAttribute(e,i);e===`rr_open_mode`&&r.nodeName===`DIALOG`&&rl(r,t)}catch(e){this.warn(`An error occurred may due to the checkout feature.`,e)}else if(e===`style`){let e=i,t=r;for(let n in e)if(e[n]===!1)t.style.removeProperty(n);else if(e[n]instanceof Array){let r=e[n];t.style.setProperty(n,r[0],r[1])}else{let r=e[n];t.style.setProperty(n,r)}}}})}applyScroll(e,t){var n,r;let i=this.mirror.getNode(e.id);if(!i)return this.debugNodeNotFound(e,e.id);let a=this.mirror.getMeta(i);if(i===this.iframe.contentDocument)(n=this.iframe.contentWindow)==null||n.scrollTo({top:e.y,left:e.x,behavior:t?`auto`:`smooth`});else if(a?.type===Z.Document)(r=i.defaultView)==null||r.scrollTo({top:e.y,left:e.x,behavior:t?`auto`:`smooth`});else try{i.scrollTo({top:e.y,left:e.x,behavior:t?`auto`:`smooth`})}catch{}}applyInput(e){let t=this.mirror.getNode(e.id);if(!t)return this.debugNodeNotFound(e,e.id);try{t.checked=e.isChecked,t.value=e.text}catch{}}applySelection(e){try{let t=new Set,n=e.ranges.map(({start:e,startOffset:n,end:r,endOffset:i})=>{let a=this.mirror.getNode(e),o=this.mirror.getNode(r);if(!a||!o)return;let s=new Range;s.setStart(a,n),s.setEnd(o,i);let c=a.ownerDocument?.getSelection();return c&&t.add(c),{range:s,selection:c}});t.forEach(e=>e.removeAllRanges()),n.forEach(e=>e&&e.selection?.addRange(e.range))}catch{}}applyStyleSheetMutation(e){let t=null;e.styleId?t=this.styleMirror.getStyle(e.styleId):e.id&&(t=this.mirror.getNode(e.id)?.sheet||null),t&&(e.source===J.StyleSheetRule?this.applyStyleSheetRule(e,t):e.source===J.StyleDeclaration&&this.applyStyleDeclaration(e,t))}applyStyleSheetRule(e,t){var n,r,i,a;if((n=e.adds)==null||n.forEach(({rule:e,index:n})=>{try{if(Array.isArray(n)){let{positions:r,index:i}=vc(n);_c(t.cssRules,r).insertRule(e,i)}else{let r=n===void 0?void 0:Math.min(n,t.cssRules.length);t?.insertRule(e,r)}}catch{}}),(r=e.removes)==null||r.forEach(({index:e})=>{try{if(Array.isArray(e)){let{positions:n,index:r}=vc(e);_c(t.cssRules,n).deleteRule(r||0)}else t?.deleteRule(e)}catch{}}),e.replace)try{(i=t.replace)==null||i.call(t,e.replace)}catch{}if(e.replaceSync)try{(a=t.replaceSync)==null||a.call(t,e.replaceSync)}catch{}}applyStyleDeclaration(e,t){e.set&&_c(t.rules,e.index).style.setProperty(e.set.property,e.set.value,e.set.priority),e.remove&&_c(t.rules,e.index).style.removeProperty(e.remove.property)}applyAdoptedStyleSheet(e){var t;let n=this.mirror.getNode(e.id);if(!n)return;(t=e.styles)==null||t.forEach(e=>{let t=null,r=null;if(gc(n)?r=n.ownerDocument?.defaultView||null:n.nodeName===`#document`&&(r=n.defaultView),r)try{t=new r.CSSStyleSheet,this.styleMirror.add(t,e.styleId),this.applyStyleSheetRule({source:J.StyleSheetRule,adds:e.rules},t)}catch{}});let r=0,i=(e,t)=>{let n=t.map(e=>this.styleMirror.getStyle(e)).filter(e=>e!==null);gc(e)?e.shadowRoot.adoptedStyleSheets=n:e.nodeName===`#document`&&(e.adoptedStyleSheets=n),n.length!==t.length&&r<10&&(setTimeout(()=>i(e,t),0+100*r),r++)};i(n,e.styleIds)}legacy_resolveMissingNode(e,t,n,r){let{previousId:i,nextId:a}=r,o=i&&e[i],s=a&&e[a];if(o){let{node:r,mutation:i}=o;t.insertBefore(r,n),delete e[i.node.id],delete this.legacy_missingNodeRetryMap[i.node.id],(i.previousId||i.nextId)&&this.legacy_resolveMissingNode(e,t,r,i)}if(s){let{node:r,mutation:i}=s;t.insertBefore(r,n.nextSibling),delete e[i.node.id],delete this.legacy_missingNodeRetryMap[i.node.id],(i.previousId||i.nextId)&&this.legacy_resolveMissingNode(e,t,r,i)}}moveAndHover(e,t,n,r,i){let a=this.mirror.getNode(n);if(!a)return this.debugNodeNotFound(i,n);let o=hc(a,this.iframe),s=e*o.absoluteScale+o.x,c=t*o.absoluteScale+o.y;this.mouse.style.left=`${s}px`,this.mouse.style.top=`${c}px`,r||this.drawMouseTail({x:s,y:c}),this.hoverElements(a)}drawMouseTail(e){if(!this.mouseTail)return;let{lineCap:t,lineWidth:n,strokeStyle:r,duration:i}=this.config.mouseTail===!0?sl:Object.assign({},sl,this.config.mouseTail),a=()=>{if(!this.mouseTail)return;let e=this.mouseTail.getContext(`2d`);!e||!this.tailPositions.length||(e.clearRect(0,0,this.mouseTail.width,this.mouseTail.height),e.beginPath(),e.lineWidth=n,e.lineCap=t,e.strokeStyle=r,e.moveTo(this.tailPositions[0].x,this.tailPositions[0].y),this.tailPositions.forEach(t=>e.lineTo(t.x,t.y)),e.stroke())};this.tailPositions.push(e),a(),setTimeout(()=>{this.tailPositions=this.tailPositions.filter(t=>t!==e),a()},i/this.speedService.state.context.timer.speed)}hoverElements(e){var t;(t=this.lastHoveredRootNode||this.iframe.contentDocument)==null||t.querySelectorAll(`.\\:hover`).forEach(e=>{e.classList.remove(`:hover`)}),this.lastHoveredRootNode=e.getRootNode();let n=e;for(;n;)n.classList&&n.classList.add(`:hover`),n=n.parentElement}isUserInteraction(e){return e.type===q.IncrementalSnapshot&&e.data.source>J.Mutation&&e.data.source<=J.Input}backToNormal(){this.nextUserInteractionEvent=null,!this.speedService.state.matches(`normal`)&&(this.speedService.send({type:`BACK_TO_NORMAL`}),this.emitter.emit(X.SkipEnd,{speed:this.speedService.state.context.normalSpeed}))}warnNodeNotFound(e,t){this.warn(`Node with id '${t}' not found. `,e)}warnCanvasMutationFailed(e,t){this.warn(`Has error on canvas update`,t,`canvas mutation:`,e)}debugNodeNotFound(e,t){this.debug(`Node with id '${t}' not found. `,e)}warn(...e){this.config.showWarning&&this.config.logger.warn(ol,...e)}debug(...e){this.config.showDebug&&this.config.logger.log(ol,...e)}},ul=(e=>(e[e.DomContentLoaded=0]=`DomContentLoaded`,e[e.Load=1]=`Load`,e[e.FullSnapshot=2]=`FullSnapshot`,e[e.IncrementalSnapshot=3]=`IncrementalSnapshot`,e[e.Meta=4]=`Meta`,e[e.Custom=5]=`Custom`,e[e.Plugin=6]=`Plugin`,e))(ul||{});function dl({events:a}){let o=t(null),s=t(null),c=t(null),[l,u]=n(0),[d,f]=n(0);return e(()=>{if(!o.current||a.length===0)return;let e=o.current,t=e.offsetWidth,n=e.offsetHeight,r=a.find(e=>e.type===ul.Meta);if(!r)return;let{width:i,height:l}=r.data;if(s.current){try{s.current.destroy()}catch{}s.current=null}e.innerHTML=``;let d=new ll(a,{root:e,skipInactive:!0,showWarning:!1,showDebug:!1,triggerFocus:!1,mouseTail:{duration:500,lineCap:`round`,lineWidth:2}}),{totalTime:p}=d.getMetaData();f(p);let m=()=>{c.current&&clearInterval(c.current),c.current=setInterval(()=>{let e=d.getCurrentTime();u(p>0?e/p*100:0)},100)},h=t/i,g=n/l,_=Math.max(h,g);d.wrapper.style.width=`${i}px`,d.wrapper.style.height=`${l}px`,d.wrapper.style.position=`absolute`,d.wrapper.style.left=`50%`,d.wrapper.style.top=`50%`,d.wrapper.style.transform=`translate(-50%, -50%) scale(${_})`,d.wrapper.style.transformOrigin=`center center`;let v=document.createElement(`style`);return v.textContent=`
69
+ function Mc(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r,i,a=n.call(e),o=[];try{for(;(t===void 0||t-->0)&&!(r=a.next()).done;)o.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(i)throw i.error}}return o}var Nc;(function(e){e[e.NotStarted=0]=`NotStarted`,e[e.Running=1]=`Running`,e[e.Stopped=2]=`Stopped`})(Nc||={});var Pc={type:`xstate.init`};function Fc(e){return e===void 0?[]:[].concat(e)}function Q(e){return{type:`xstate.assign`,assignment:e}}function Ic(e,t){return typeof(e=typeof e==`string`&&t&&t[e]?t[e]:e)==`string`?{type:e}:typeof e==`function`?{type:e.name,exec:e}:e}function Lc(e){return function(t){return e===t}}function Rc(e){return typeof e==`string`?{type:e}:e}function zc(e,t){return{value:e,context:t,actions:[],changed:!1,matches:Lc(e)}}function Bc(e,t,n){var r=t,i=!1;return[e.filter(function(e){if(e.type===`xstate.assign`){i=!0;var t=Object.assign({},r);return typeof e.assignment==`function`?t=e.assignment(r,n):Object.keys(e.assignment).forEach(function(i){t[i]=typeof e.assignment[i]==`function`?e.assignment[i](r,n):e.assignment[i]}),r=t,!1}return!0}),r,i]}function Vc(e,t){t===void 0&&(t={});var n=Mc(Bc(Fc(e.states[e.initial].entry).map(function(e){return Ic(e,t.actions)}),e.context,Pc),2),r=n[0],i=n[1],a={config:e,_options:t,initialState:{value:e.initial,actions:r,context:i,matches:Lc(e.initial)},transition:function(t,n){var r,i,o=typeof t==`string`?{value:t,context:e.context}:t,s=o.value,c=o.context,l=Rc(n),u=e.states[s];if(u.on){var d=Fc(u.on[l.type]);try{for(var f=function(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)}(d),p=f.next();!p.done;p=f.next()){var m=p.value;if(m===void 0)return zc(s,c);var h=typeof m==`string`?{target:m}:m,g=h.target,_=h.actions,v=_===void 0?[]:_,y=h.cond,ee=y===void 0?function(){return!0}:y,te=g===void 0,ne=g??s,re=e.states[ne];if(ee(c,l)){var b=Mc(Bc((te?Fc(v):[].concat(u.exit,v,re.entry).filter(function(e){return e})).map(function(e){return Ic(e,a._options.actions)}),c,l),3),ie=b[0],ae=b[1],x=b[2],oe=g??s;return{value:oe,context:ae,actions:ie,changed:g!==s||ie.length>0||x,matches:Lc(oe)}}}}catch(e){r={error:e}}finally{try{p&&!p.done&&(i=f.return)&&i.call(f)}finally{if(r)throw r.error}}}return zc(s,c)}};return a}var Hc=function(e,t){return e.actions.forEach(function(n){var r=n.exec;return r&&r(e.context,t)})};function Uc(e){var t=e.initialState,n=Nc.NotStarted,r=new Set,i={_machine:e,send:function(i){n===Nc.Running&&(t=e.transition(t,i),Hc(t,Rc(i)),r.forEach(function(e){return e(t)}))},subscribe:function(e){return r.add(e),e(t),{unsubscribe:function(){return r.delete(e)}}},start:function(r){if(r){var a=typeof r==`object`?r:{context:e.config.context,value:r};t={value:a.value,actions:[],context:a.context,matches:Lc(a.value)}}return n=Nc.Running,Hc(t,Pc),i},stop:function(){return n=Nc.Stopped,r.clear(),i},get state(){return t},get status(){return n}};return i}function Wc(e,t){for(let n=e.length-1;n>=0;n--){let r=e[n];if(r.type===q.Meta&&r.timestamp<=t)return e.slice(n)}return e}function Gc(e,{getCastFn:t,applyEventsSynchronously:n,emitter:r}){return Uc(Vc({id:`player`,context:e,initial:`paused`,states:{playing:{on:{PAUSE:{target:`paused`,actions:[`pause`]},CAST_EVENT:{target:`playing`,actions:`castEvent`},END:{target:`paused`,actions:[`resetLastPlayedEvent`,`pause`]},ADD_EVENT:{target:`playing`,actions:[`addEvent`]}}},paused:{on:{PLAY:{target:`playing`,actions:[`recordTimeOffset`,`play`]},CAST_EVENT:{target:`paused`,actions:`castEvent`},TO_LIVE:{target:`live`,actions:[`startLive`]},ADD_EVENT:{target:`paused`,actions:[`addEvent`]}}},live:{on:{ADD_EVENT:{target:`live`,actions:[`addEvent`]},CAST_EVENT:{target:`live`,actions:[`castEvent`]}}}}},{actions:{castEvent:Q({lastPlayedEvent:(e,t)=>t.type===`CAST_EVENT`?t.payload.event:e.lastPlayedEvent}),recordTimeOffset:Q((e,t)=>{let n=e.timeOffset;return`payload`in t&&`timeOffset`in t.payload&&(n=t.payload.timeOffset),{...e,timeOffset:n,baselineTime:e.events[0].timestamp+n}}),play(e){let{timer:i,events:a,baselineTime:o,lastPlayedEvent:s}=e;i.clear();for(let e of a)jc(e,o);let c=Wc(a,o),l=s?.timestamp;s?.type===q.IncrementalSnapshot&&s.data.source===J.MouseMove&&(l=s.timestamp+s.data.positions[0]?.timeOffset),o<(l||0)&&r.emit(X.PlayBack);let u=[];for(let e of c)if(!(l&&l<o&&(e.timestamp<=l||e===s)))if(e.timestamp<o)u.push(e);else{let n=t(e,!1);i.addAction({doAction:()=>{n()},delay:e.delay})}n(u),r.emit(X.Flush),i.start()},pause(e){e.timer.clear()},resetLastPlayedEvent:Q(e=>({...e,lastPlayedEvent:null})),startLive:Q({baselineTime:(e,t)=>(e.timer.start(),t.type===`TO_LIVE`&&t.payload.baselineTime?t.payload.baselineTime:Date.now())}),addEvent:Q((e,n)=>{let{baselineTime:r,timer:i,events:a}=e;if(n.type===`ADD_EVENT`){let{event:e}=n.payload;jc(e,r);let o=a.length-1;if(!a[o]||a[o].timestamp<=e.timestamp)a.push(e);else{let t=-1,n=0;for(;n<=o;){let t=Math.floor((n+o)/2);a[t].timestamp<=e.timestamp?n=t+1:o=t-1}t===-1&&(t=n),a.splice(t,0,e)}let s=e.timestamp<r,c=t(e,s);s?c():i.isActive()&&i.addAction({doAction:()=>{c()},delay:e.delay})}return{...e,events:a}})}}))}function Kc(e){return Uc(Vc({id:`speed`,context:e,initial:`normal`,states:{normal:{on:{FAST_FORWARD:{target:`skipping`,actions:[`recordSpeed`,`setSpeed`]},SET_SPEED:{target:`normal`,actions:[`setSpeed`]}}},skipping:{on:{BACK_TO_NORMAL:{target:`normal`,actions:[`restoreSpeed`]},SET_SPEED:{target:`normal`,actions:[`setSpeed`]}}}}},{actions:{setSpeed:(e,t)=>{`payload`in t&&e.timer.setSpeed(t.payload.speed)},recordSpeed:Q({normalSpeed:e=>e.timer.speed}),restoreSpeed:e=>{e.timer.setSpeed(e.normalSpeed)}}}))}const qc=e=>[`.${e} { background: currentColor }`,`noscript { display: none !important; }`],Jc=new Map;function Yc(e,t){let n=Jc.get(e);return n||(n=new Map,Jc.set(e,n)),n.has(t)||n.set(t,[]),n.get(t)}function $(e,t,n){return async r=>{if(r&&typeof r==`object`&&`rr_type`in r){if(n&&(n.isUnchanged=!1),r.rr_type===`ImageBitmap`&&`args`in r){let i=await $(e,t,n)(r.args);return await createImageBitmap.apply(null,i)}else if(`index`in r){if(n||t===null)return r;let{rr_type:e,index:i}=r;return Yc(t,e)[i]}else if(`args`in r){let{rr_type:i,args:a}=r,o=window[i];return new o(...await Promise.all(a.map($(e,t,n))))}else if(`base64`in r)return Ec(r.base64);else if(`src`in r){let t=e.get(r.src);if(t)return t;{let t=new Image;return t.src=r.src,e.set(r.src,t),t}}else if(`data`in r&&r.rr_type===`Blob`){let i=await Promise.all(r.data.map($(e,t,n)));return new Blob(i,{type:r.type})}}else if(Array.isArray(r))return await Promise.all(r.map($(e,t,n)));return r}}function Xc(e,t){try{return t===xc.WebGL?e.getContext(`webgl`)||e.getContext(`experimental-webgl`):e.getContext(`webgl2`)}catch{return null}}const Zc=[`WebGLActiveInfo`,`WebGLBuffer`,`WebGLFramebuffer`,`WebGLProgram`,`WebGLRenderbuffer`,`WebGLShader`,`WebGLShaderPrecisionFormat`,`WebGLTexture`,`WebGLUniformLocation`,`WebGLVertexArrayObject`];function Qc(e,t){if(!t?.constructor)return;let{name:n}=t.constructor;if(!Zc.includes(n))return;let r=Yc(e,n);r.includes(t)||r.push(t)}async function $c({mutation:e,target:t,type:n,imageMap:r,errorHandler:i}){try{let i=Xc(t,n);if(!i)return;if(e.setter){i[e.property]=e.args[0];return}let a=i[e.property],o=await Promise.all(e.args.map($(r,i)));Qc(i,a.apply(i,o))}catch(t){i(e,t)}}async function el({event:e,mutations:t,target:n,imageMap:r,errorHandler:i}){let a=n.getContext(`2d`);if(!a){i(t[0],Error(`Canvas context is null`));return}let o=t.map(async e=>Promise.all(e.args.map($(r,a))));(await Promise.all(o)).forEach((n,o)=>{let s=t[o];try{if(s.setter){a[s.property]=s.args[0];return}let t=a[s.property];s.property===`drawImage`&&typeof s.args[0]==`string`?(r.get(e),t.apply(a,s.args)):t.apply(a,n)}catch(e){i(s,e)}})}async function tl({event:e,mutation:t,target:n,imageMap:r,canvasEventMap:i,errorHandler:a}){try{let o=i.get(e)||t,s=`commands`in o?o.commands:[o];if([xc.WebGL,xc.WebGL2].includes(t.type)){for(let e=0;e<s.length;e++){let i=s[e];await $c({mutation:i,type:t.type,target:n,imageMap:r,errorHandler:a})}return}await el({event:e,mutations:s,target:n,imageMap:r,errorHandler:a})}catch(e){a(t,e)}}var nl=class{constructor(e){s(this,`mediaMap`,new Map),s(this,`warn`),s(this,`service`),s(this,`speedService`),s(this,`emitter`),s(this,`getCurrentTime`),s(this,`metadataCallbackMap`,new Map),this.warn=e.warn,this.service=e.service,this.speedService=e.speedService,this.emitter=e.emitter,this.getCurrentTime=e.getCurrentTime,this.emitter.on(X.Start,this.start.bind(this)),this.emitter.on(X.SkipStart,this.start.bind(this)),this.emitter.on(X.Pause,this.pause.bind(this)),this.emitter.on(X.Finish,this.pause.bind(this)),this.speedService.subscribe(()=>{this.syncAllMediaElements()})}syncAllMediaElements(e={pause:!1}){this.mediaMap.forEach((t,n)=>{this.syncTargetWithState(n),e.pause&&n.pause()})}start(){this.syncAllMediaElements()}pause(){this.syncAllMediaElements({pause:!0})}seekTo({time:e,target:t,mediaState:n}){if(n.isPlaying){let r=(e-n.lastInteractionTimeOffset)/1e3*n.playbackRate,i=`duration`in t&&t.duration;if(Number.isNaN(i)){this.waitForMetadata(t);return}let a=n.currentTimeAtLastInteraction+r;t.loop&&i!==!1&&(a%=i),t.currentTime=a}else t.pause(),t.currentTime=n.currentTimeAtLastInteraction}waitForMetadata(e){if(this.metadataCallbackMap.has(e)||!(`addEventListener`in e))return;let t=()=>{this.metadataCallbackMap.delete(e);let t=this.mediaMap.get(e);t&&this.seekTo({time:this.getCurrentTime(),target:e,mediaState:t})};this.metadataCallbackMap.set(e,t),e.addEventListener(`loadedmetadata`,t,{once:!0})}getMediaStateFromMutation({target:e,timeOffset:t,mutation:n}){let r=this.mediaMap.get(e),{type:i,playbackRate:a,currentTime:o,muted:s,volume:c,loop:l}=n;return{isPlaying:i===Sc.Play||i!==Sc.Pause&&(r?.isPlaying||e.getAttribute(`autoplay`)!==null),currentTimeAtLastInteraction:o??r?.currentTimeAtLastInteraction??0,lastInteractionTimeOffset:t,playbackRate:a??r?.playbackRate??1,volume:c??r?.volume??1,muted:s??r?.muted??e.getAttribute(`muted`)===null,loop:l??r?.loop??e.getAttribute(`loop`)===null}}syncTargetWithState(e){let t=this.mediaMap.get(e);if(!t)return;let{muted:n,loop:r,volume:i,isPlaying:a}=t,o=this.service.state.matches(`paused`),s=t.playbackRate*this.speedService.state.context.timer.speed;try{this.seekTo({time:this.getCurrentTime(),target:e,mediaState:t}),e.volume!==i&&(e.volume=i),e.muted=n,e.loop=r,e.playbackRate!==s&&(e.playbackRate=s),a&&!o?e.play():e.pause()}catch(e){this.warn(`Failed to replay media interactions: ${e.message||e}`)}}addMediaElements(e,t,n){if(![`AUDIO`,`VIDEO`].includes(e.nodeName))return;let r=e,i=n.getMeta(r);if(!i||!(`attributes`in i))return;let a=this.service.state.matches(`paused`),o=i.attributes,s=!1;s=o.rr_mediaState?o.rr_mediaState===`played`:r.getAttribute(`autoplay`)!==null,s&&a&&r.pause();let c=1;typeof o.rr_mediaPlaybackRate==`number`&&(c=o.rr_mediaPlaybackRate);let l=!1;l=typeof o.rr_mediaMuted==`boolean`?o.rr_mediaMuted:r.getAttribute(`muted`)!==null;let u=!1;u=typeof o.rr_mediaLoop==`boolean`?o.rr_mediaLoop:r.getAttribute(`loop`)!==null;let d=1;typeof o.rr_mediaVolume==`number`&&(d=o.rr_mediaVolume);let f=0;typeof o.rr_mediaCurrentTime==`number`&&(f=o.rr_mediaCurrentTime),this.mediaMap.set(r,{isPlaying:s,currentTimeAtLastInteraction:f,lastInteractionTimeOffset:t,playbackRate:c,volume:d,muted:l,loop:u}),this.syncTargetWithState(r)}mediaMutation({target:e,timeOffset:t,mutation:n}){this.mediaMap.set(e,this.getMediaStateFromMutation({target:e,timeOffset:t,mutation:n})),this.syncTargetWithState(e)}isSupportedMediaElement(e){return[`AUDIO`,`VIDEO`].includes(e.nodeName)}reset(){this.mediaMap.clear()}};function rl(e,t){if(e.nodeName!==`DIALOG`||e instanceof V)return;let n=e,r=n.open,i=r&&n.matches(`dialog:modal`),a=n.getAttribute(`rr_open_mode`),o=typeof t?.attributes.open==`string`||typeof n.getAttribute(`open`)==`string`,s=a===`modal`;if(!(r&&!(i&&a===`non-modal`||!i&&s))){if(!n.isConnected){console.warn(`dialog is not attached to the dom`,n);return}r&&n.close(),o&&(s?n.showModal():n.show())}}function il(e,t){if(e.nodeName!==`DIALOG`||e instanceof V)return;let n=e;if(!n.isConnected){console.warn(`dialog is not attached to the dom`,n);return}t.attributes.open===null&&(n.removeAttribute(`open`),n.removeAttribute(`rr_open_mode`))}const al=Dc||Oc,ol=`[replayer]`,sl={duration:500,lineCap:`round`,lineWidth:3,strokeStyle:`red`};function cl(e){return e.type==q.IncrementalSnapshot&&(e.data.source==J.TouchMove||e.data.source==J.MouseInteraction&&e.data.type==Y.TouchStart)}var ll=class{constructor(e,t){if(s(this,`wrapper`),s(this,`iframe`),s(this,`service`),s(this,`speedService`),s(this,`config`),s(this,`usingVirtualDom`,!1),s(this,`virtualDom`,new ws),s(this,`mouse`),s(this,`mouseTail`,null),s(this,`tailPositions`,[]),s(this,`emitter`,al()),s(this,`nextUserInteractionEvent`),s(this,`legacy_missingNodeRetryMap`,{}),s(this,`cache`,yr()),s(this,`imageMap`,new Map),s(this,`canvasEventMap`,new Map),s(this,`mirror`,m()),s(this,`styleMirror`,new bc),s(this,`mediaManager`),s(this,`firstFullSnapshot`,null),s(this,`newDocumentQueue`,[]),s(this,`mousePos`,null),s(this,`touchActive`,null),s(this,`lastMouseDownEvent`,null),s(this,`lastHoveredRootNode`),s(this,`lastSelectionData`,null),s(this,`constructedStyleMutations`,[]),s(this,`adoptedStyleSheets`,[]),s(this,`handleResize`,e=>{this.iframe.style.display=`inherit`;for(let t of[this.mouseTail,this.iframe])t&&(t.setAttribute(`width`,String(e.width)),t.setAttribute(`height`,String(e.height)))}),s(this,`applyEventsSynchronously`,e=>{for(let t of e){switch(t.type){case q.DomContentLoaded:case q.Load:case q.Custom:continue;case q.FullSnapshot:case q.Meta:case q.Plugin:case q.IncrementalSnapshot:break}this.getCastFn(t,!0)()}}),s(this,`getCastFn`,(e,t=!1)=>{let n;switch(e.type){case q.DomContentLoaded:case q.Load:break;case q.Custom:n=()=>{this.emitter.emit(X.CustomEvent,e)};break;case q.Meta:n=()=>this.emitter.emit(X.Resize,{width:e.data.width,height:e.data.height});break;case q.FullSnapshot:n=()=>{var n;if(this.firstFullSnapshot){if(this.firstFullSnapshot===e){this.firstFullSnapshot=!0;return}}else this.firstFullSnapshot=!0;this.mediaManager.reset(),this.styleMirror.reset(),this.rebuildFullSnapshot(e,t),(n=this.iframe.contentWindow)==null||n.scrollTo(e.data.initialOffset)};break;case q.IncrementalSnapshot:n=()=>{if(this.applyIncremental(e,t),!t&&(e===this.nextUserInteractionEvent&&(this.nextUserInteractionEvent=null,this.backToNormal()),this.config.skipInactive&&!this.nextUserInteractionEvent)){for(let t of this.service.state.context.events)if(!(t.timestamp<=e.timestamp)&&this.isUserInteraction(t)){t.delay-e.delay>this.config.inactivePeriodThreshold*this.speedService.state.context.timer.speed&&(this.nextUserInteractionEvent=t);break}if(this.nextUserInteractionEvent){let t=this.nextUserInteractionEvent.delay-e.delay,n={speed:Math.min(Math.round(t/5e3),this.config.maxSpeed)};this.speedService.send({type:`FAST_FORWARD`,payload:n}),this.emitter.emit(X.SkipStart,n)}}};break}return()=>{n&&n();for(let n of this.config.plugins||[])n.handler&&n.handler(e,t,{replayer:this});this.service.send({type:`CAST_EVENT`,payload:{event:e}});let r=this.service.state.context.events.length-1;if(!this.config.liveMode&&e===this.service.state.context.events[r]){let t=()=>{r<this.service.state.context.events.length-1||(this.backToNormal(),this.service.send(`END`),this.emitter.emit(X.Finish))},n=50;e.type===q.IncrementalSnapshot&&e.data.source===J.MouseMove&&e.data.positions.length&&(n+=Math.max(0,-e.data.positions[0].timeOffset)),setTimeout(t,n)}this.emitter.emit(X.EventCast,e)}}),!t?.liveMode&&e.length<2)throw Error(`Replayer need at least 2 events.`);let n={speed:1,maxSpeed:360,root:document.body,loadTimeout:0,skipInactive:!1,inactivePeriodThreshold:10*1e3,showWarning:!0,showDebug:!1,blockClass:`rr-block`,liveMode:!1,insertStyleRules:[],triggerFocus:!0,UNSAFE_replayCanvas:!1,pauseAnimation:!0,mouseTail:sl,useVirtualDom:!0,logger:console};this.config=Object.assign({},n,t),this.handleResize=this.handleResize.bind(this),this.getCastFn=this.getCastFn.bind(this),this.applyEventsSynchronously=this.applyEventsSynchronously.bind(this),this.emitter.on(X.Resize,this.handleResize),this.setupDom();for(let e of this.config.plugins||[])e.getMirror&&e.getMirror({nodeMirror:this.mirror});this.emitter.on(X.Flush,()=>{if(this.usingVirtualDom){let e={mirror:this.mirror,applyCanvas:(e,t,n)=>{tl({event:e,mutation:t,target:n,imageMap:this.imageMap,canvasEventMap:this.canvasEventMap,errorHandler:this.warnCanvasMutationFailed.bind(this)})},applyInput:this.applyInput.bind(this),applyScroll:this.applyScroll.bind(this),applyStyleSheetMutation:(e,t)=>{e.source===J.StyleSheetRule?this.applyStyleSheetRule(e,t):e.source===J.StyleDeclaration&&this.applyStyleDeclaration(e,t)},afterAppend:(e,t)=>{for(let n of this.config.plugins||[])n.onBuild&&n.onBuild(e,{id:t,replayer:this})}};if(this.iframe.contentDocument)try{_s(this.iframe.contentDocument,this.virtualDom,e,this.virtualDom.mirror)}catch(e){console.warn(e)}if(this.virtualDom.destroyTree(),this.usingVirtualDom=!1,Object.keys(this.legacy_missingNodeRetryMap).length)for(let t in this.legacy_missingNodeRetryMap)try{let n=this.legacy_missingNodeRetryMap[t],r=Ss(n.node,this.mirror,this.virtualDom.mirror);_s(r,n.node,e,this.virtualDom.mirror),n.node=r}catch(e){this.warn(e)}this.constructedStyleMutations.forEach(e=>{this.applyStyleSheetMutation(e)}),this.constructedStyleMutations=[],this.adoptedStyleSheets.forEach(e=>{this.applyAdoptedStyleSheet(e)}),this.adoptedStyleSheets=[]}if(this.mousePos&&=(this.moveAndHover(this.mousePos.x,this.mousePos.y,this.mousePos.id,!0,this.mousePos.debugData),null),this.touchActive===!0?this.mouse.classList.add(`touch-active`):this.touchActive===!1&&this.mouse.classList.remove(`touch-active`),this.touchActive=null,this.lastMouseDownEvent){let[e,t]=this.lastMouseDownEvent;e.dispatchEvent(t)}this.lastMouseDownEvent=null,this.lastSelectionData&&=(this.applySelection(this.lastSelectionData),null)}),this.emitter.on(X.PlayBack,()=>{this.firstFullSnapshot=null,this.mirror.reset(),this.styleMirror.reset(),this.mediaManager.reset()});let r=new Ac([],{speed:this.config.speed});this.service=Gc({events:e.map(e=>t&&t.unpackFn?t.unpackFn(e):e).sort((e,t)=>e.timestamp-t.timestamp),timer:r,timeOffset:0,baselineTime:0,lastPlayedEvent:null},{getCastFn:this.getCastFn,applyEventsSynchronously:this.applyEventsSynchronously,emitter:this.emitter}),this.service.start(),this.service.subscribe(e=>{this.emitter.emit(X.StateChange,{player:e})}),this.speedService=Kc({normalSpeed:-1,timer:r}),this.speedService.start(),this.speedService.subscribe(e=>{this.emitter.emit(X.StateChange,{speed:e})}),this.mediaManager=new nl({warn:this.warn.bind(this),service:this.service,speedService:this.speedService,emitter:this.emitter,getCurrentTime:this.getCurrentTime.bind(this)});let i=this.service.state.context.events.find(e=>e.type===q.Meta),a=this.service.state.context.events.find(e=>e.type===q.FullSnapshot);if(i){let{width:e,height:t}=i.data;setTimeout(()=>{this.emitter.emit(X.Resize,{width:e,height:t})},0)}a&&setTimeout(()=>{var e;this.firstFullSnapshot||(this.firstFullSnapshot=a,this.rebuildFullSnapshot(a),(e=this.iframe.contentWindow)==null||e.scrollTo(a.data.initialOffset))},1),this.service.state.context.events.find(cl)&&this.mouse.classList.add(`touch-device`)}get timer(){return this.service.state.context.timer}on(e,t){return this.emitter.on(e,t),this}off(e,t){return this.emitter.off(e,t),this}setConfig(e){Object.keys(e).forEach(t=>{e[t],this.config[t]=e[t]}),this.config.skipInactive||this.backToNormal(),e.speed!==void 0&&this.speedService.send({type:`SET_SPEED`,payload:{speed:e.speed}}),e.mouseTail!==void 0&&(e.mouseTail===!1?this.mouseTail&&(this.mouseTail.style.display=`none`):(this.mouseTail||(this.mouseTail=document.createElement(`canvas`),this.mouseTail.width=Number.parseFloat(this.iframe.width),this.mouseTail.height=Number.parseFloat(this.iframe.height),this.mouseTail.classList.add(`replayer-mouse-tail`),this.wrapper.insertBefore(this.mouseTail,this.iframe)),this.mouseTail.style.display=`inherit`))}getMetaData(){let e=this.service.state.context.events[0],t=this.service.state.context.events[this.service.state.context.events.length-1];return{startTime:e.timestamp,endTime:t.timestamp,totalTime:t.timestamp-e.timestamp}}getCurrentTime(){return this.timer.timeOffset+this.getTimeOffset()}getTimeOffset(){let{baselineTime:e,events:t}=this.service.state.context;return e-t[0].timestamp}getMirror(){return this.mirror}play(e=0){var t;this.service.state.matches(`paused`)||this.service.send({type:`PAUSE`}),this.service.send({type:`PLAY`,payload:{timeOffset:e}}),(t=this.iframe.contentDocument?.getElementsByTagName(`html`)[0])==null||t.classList.remove(`rrweb-paused`),this.emitter.emit(X.Start)}pause(e){var t;e===void 0&&this.service.state.matches(`playing`)&&this.service.send({type:`PAUSE`}),typeof e==`number`&&(this.play(e),this.service.send({type:`PAUSE`})),(t=this.iframe.contentDocument?.getElementsByTagName(`html`)[0])==null||t.classList.add(`rrweb-paused`),this.emitter.emit(X.Pause)}resume(e=0){this.warn(`The 'resume' was deprecated in 1.0. Please use 'play' method which has the same interface.`),this.play(e),this.emitter.emit(X.Resume)}destroy(){this.pause(),this.mirror.reset(),this.styleMirror.reset(),this.mediaManager.reset(),this.config.root.removeChild(this.wrapper),this.emitter.emit(X.Destroy)}startLive(e){this.service.send({type:`TO_LIVE`,payload:{baselineTime:e}})}addEvent(e){let t=this.config.unpackFn?this.config.unpackFn(e):e;cl(t)&&this.mouse.classList.add(`touch-device`),Promise.resolve().then(()=>this.service.send({type:`ADD_EVENT`,payload:{event:t}}))}enableInteract(){this.iframe.setAttribute(`scrolling`,`auto`),this.iframe.style.pointerEvents=`auto`}disableInteract(){this.iframe.setAttribute(`scrolling`,`no`),this.iframe.style.pointerEvents=`none`}resetCache(){this.cache=yr()}setupDom(){this.wrapper=document.createElement(`div`),this.wrapper.classList.add(`replayer-wrapper`),this.config.root.appendChild(this.wrapper),this.mouse=document.createElement(`div`),this.mouse.classList.add(`replayer-mouse`),this.wrapper.appendChild(this.mouse),this.config.mouseTail!==!1&&(this.mouseTail=document.createElement(`canvas`),this.mouseTail.classList.add(`replayer-mouse-tail`),this.mouseTail.style.display=`inherit`,this.wrapper.appendChild(this.mouseTail)),this.iframe=document.createElement(`iframe`);let e=[`allow-same-origin`];this.config.UNSAFE_replayCanvas&&e.push(`allow-scripts`),this.iframe.style.display=`none`,this.iframe.setAttribute(`sandbox`,e.join(` `)),this.disableInteract(),this.wrapper.appendChild(this.iframe),this.iframe.contentWindow&&this.iframe.contentDocument&&(kc(this.iframe.contentWindow,this.iframe.contentDocument),dc(this.iframe.contentWindow))}rebuildFullSnapshot(e,t=!1){if(!this.iframe.contentDocument)return this.warn(`Looks like your replayer has been destroyed.`);Object.keys(this.legacy_missingNodeRetryMap).length&&this.warn(`Found unresolved missing node map`,this.legacy_missingNodeRetryMap),this.legacy_missingNodeRetryMap={};let n=[],r=new Set,i=(t,i)=>{if(t.nodeName===`DIALOG`&&r.add(t),this.collectIframeAndAttachDocument(n,t),this.mediaManager.isSupportedMediaElement(t)){let{events:n}=this.service.state.context;this.mediaManager.addMediaElements(t,e.timestamp-n[0].timestamp,this.mirror)}for(let e of this.config.plugins||[])e.onBuild&&e.onBuild(t,{id:i,replayer:this})};this.usingVirtualDom&&=(this.virtualDom.destroyTree(),!1),this.mirror.reset(),Er(e.data.node,{doc:this.iframe.contentDocument,afterAppend:i,cache:this.cache,mirror:this.mirror}),i(this.iframe.contentDocument,e.data.node.id);for(let{mutationInQueue:e,builtNode:t}of n)this.attachDocumentToIframe(e,t),this.newDocumentQueue=this.newDocumentQueue.filter(t=>t!==e);let{documentElement:a,head:o}=this.iframe.contentDocument;this.insertStyleRules(a,o),r.forEach(e=>rl(e)),this.service.state.matches(`playing`)||this.iframe.contentDocument.getElementsByTagName(`html`)[0].classList.add(`rrweb-paused`),this.emitter.emit(X.FullsnapshotRebuilded,e),t||this.waitForStylesheetLoad(),this.config.UNSAFE_replayCanvas&&this.preloadAllImages()}insertStyleRules(e,t){var n;let r=qc(this.config.blockClass).concat(this.config.insertStyleRules);if(this.config.pauseAnimation&&r.push(`html.rrweb-paused *, html.rrweb-paused *:before, html.rrweb-paused *:after { animation-play-state: paused !important; }`),r.length)if(this.usingVirtualDom){let n=this.virtualDom.createElement(`style`);this.virtualDom.mirror.add(n,Bs(n,this.virtualDom.unserializedId)),e.insertBefore(n,t),n.rules.push({source:J.StyleSheetRule,adds:r.map((e,t)=>({rule:e,index:t}))})}else{let i=document.createElement(`style`);e.insertBefore(i,t);for(let e=0;e<r.length;e++)(n=i.sheet)==null||n.insertRule(r[e],e)}}attachDocumentToIframe(e,t){let n=this.usingVirtualDom?this.virtualDom.mirror:this.mirror,r=[],i=new Set,a=(e,a)=>{e.nodeName===`DIALOG`&&i.add(e),this.collectIframeAndAttachDocument(r,e);let o=n.getMeta(e);if(o?.type===Z.Element&&o?.tagName.toUpperCase()===`HTML`){let{documentElement:e,head:n}=t.contentDocument;this.insertStyleRules(e,n)}if(!this.usingVirtualDom)for(let t of this.config.plugins||[])t.onBuild&&t.onBuild(e,{id:a,replayer:this})};Cr(e.node,{doc:t.contentDocument,mirror:n,hackCss:!0,skipChild:!1,afterAppend:a,cache:this.cache}),a(t.contentDocument,e.node.id);for(let{mutationInQueue:e,builtNode:t}of r)this.attachDocumentToIframe(e,t),this.newDocumentQueue=this.newDocumentQueue.filter(t=>t!==e);i.forEach(e=>rl(e))}collectIframeAndAttachDocument(e,t){if(mc(t,this.mirror)){let n=this.newDocumentQueue.find(e=>e.parentId===this.mirror.getId(t));n&&e.push({mutationInQueue:n,builtNode:t})}}waitForStylesheetLoad(){let e=this.iframe.contentDocument?.head;if(e){let t=new Set,n,r=this.service.state,i=()=>{r=this.service.state};this.emitter.on(X.Start,i),this.emitter.on(X.Pause,i);let a=()=>{this.emitter.off(X.Start,i),this.emitter.off(X.Pause,i)};e.querySelectorAll(`link[rel="stylesheet"]`).forEach(e=>{e.sheet||(t.add(e),e.addEventListener(`load`,()=>{t.delete(e),t.size===0&&n!==-1&&(r.matches(`playing`)&&this.play(this.getCurrentTime()),this.emitter.emit(X.LoadStylesheetEnd),n&&clearTimeout(n),a())}))}),t.size>0&&(this.service.send({type:`PAUSE`}),this.emitter.emit(X.LoadStylesheetStart),n=setTimeout(()=>{r.matches(`playing`)&&this.play(this.getCurrentTime()),n=-1,a()},this.config.loadTimeout))}}async preloadAllImages(){let e=[];for(let t of this.service.state.context.events)t.type===q.IncrementalSnapshot&&t.data.source===J.CanvasMutation&&(e.push(this.deserializeAndPreloadCanvasEvents(t.data,t)),(`commands`in t.data?t.data.commands:[t.data]).forEach(e=>{this.preloadImages(e,t)}));return Promise.all(e)}preloadImages(e,t){if(e.property===`drawImage`&&typeof e.args[0]==`string`&&!this.imageMap.has(t)){let e=document.createElement(`canvas`),t=e.getContext(`2d`),n=t?.createImageData(e.width,e.height);t?.putImageData(n,0,0)}}async deserializeAndPreloadCanvasEvents(e,t){if(!this.canvasEventMap.has(t)){let n={isUnchanged:!0};if(`commands`in e){let r=await Promise.all(e.commands.map(async e=>{let t=await Promise.all(e.args.map($(this.imageMap,null,n)));return{...e,args:t}}));n.isUnchanged===!1&&this.canvasEventMap.set(t,{...e,commands:r})}else{let r=await Promise.all(e.args.map($(this.imageMap,null,n)));n.isUnchanged===!1&&this.canvasEventMap.set(t,{...e,args:r})}}}applyIncremental(e,t){var n,r;let{data:i}=e;switch(i.source){case J.Mutation:try{this.applyMutation(i,t)}catch(e){this.warn(`Exception in mutation ${e.message||e}`,i)}break;case J.Drag:case J.TouchMove:case J.MouseMove:if(t){let e=i.positions[i.positions.length-1];this.mousePos={x:e.x,y:e.y,id:e.id,debugData:i}}else i.positions.forEach(n=>{let r={doAction:()=>{this.moveAndHover(n.x,n.y,n.id,t,i)},delay:n.timeOffset+e.timestamp-this.service.state.context.baselineTime};this.timer.addAction(r)}),this.timer.addAction({doAction(){},delay:e.delay-i.positions[0]?.timeOffset});break;case J.MouseInteraction:{if(i.id===-1)break;let e=new Event(h(Y[i.type])),n=this.mirror.getNode(i.id);if(!n)return this.debugNodeNotFound(i,i.id);this.emitter.emit(X.MouseInteraction,{type:i.type,target:n});let{triggerFocus:r}=this.config;switch(i.type){case Y.Blur:`blur`in n&&n.blur();break;case Y.Focus:r&&n.focus&&n.focus({preventScroll:!0});break;case Y.Click:case Y.TouchStart:case Y.TouchEnd:case Y.MouseDown:case Y.MouseUp:t?(i.type===Y.TouchStart?this.touchActive=!0:i.type===Y.TouchEnd&&(this.touchActive=!1),i.type===Y.MouseDown?this.lastMouseDownEvent=[n,e]:i.type===Y.MouseUp&&(this.lastMouseDownEvent=null),this.mousePos={x:i.x||0,y:i.y||0,id:i.id,debugData:i}):(i.type===Y.TouchStart&&(this.tailPositions.length=0),this.moveAndHover(i.x||0,i.y||0,i.id,t,i),i.type===Y.Click?(this.mouse.classList.remove(`active`),this.mouse.offsetWidth,this.mouse.classList.add(`active`)):i.type===Y.TouchStart?(this.mouse.offsetWidth,this.mouse.classList.add(`touch-active`)):i.type===Y.TouchEnd?this.mouse.classList.remove(`touch-active`):n.dispatchEvent(e));break;case Y.TouchCancel:t?this.touchActive=!1:this.mouse.classList.remove(`touch-active`);break;default:n.dispatchEvent(e)}break}case J.Scroll:if(i.id===-1)break;if(this.usingVirtualDom){let e=this.virtualDom.mirror.getNode(i.id);if(!e)return this.debugNodeNotFound(i,i.id);e.scrollData=i;break}this.applyScroll(i,t);break;case J.ViewportResize:this.emitter.emit(X.Resize,{width:i.width,height:i.height});break;case J.Input:if(i.id===-1)break;if(this.usingVirtualDom){let e=this.virtualDom.mirror.getNode(i.id);if(!e)return this.debugNodeNotFound(i,i.id);e.inputData=i;break}this.applyInput(i);break;case J.MediaInteraction:{let t=this.usingVirtualDom?this.virtualDom.mirror.getNode(i.id):this.mirror.getNode(i.id);if(!t)return this.debugNodeNotFound(i,i.id);let n=t,{events:r}=this.service.state.context;this.mediaManager.mediaMutation({target:n,timeOffset:e.timestamp-r[0].timestamp,mutation:i});break}case J.StyleSheetRule:case J.StyleDeclaration:this.usingVirtualDom?i.styleId?this.constructedStyleMutations.push(i):i.id&&((n=this.virtualDom.mirror.getNode(i.id))==null||n.rules.push(i)):this.applyStyleSheetMutation(i);break;case J.CanvasMutation:if(!this.config.UNSAFE_replayCanvas)return;if(this.usingVirtualDom){let t=this.virtualDom.mirror.getNode(i.id);if(!t)return this.debugNodeNotFound(i,i.id);t.canvasMutations.push({event:e,mutation:i})}else{let t=this.mirror.getNode(i.id);if(!t)return this.debugNodeNotFound(i,i.id);tl({event:e,mutation:i,target:t,imageMap:this.imageMap,canvasEventMap:this.canvasEventMap,errorHandler:this.warnCanvasMutationFailed.bind(this)})}break;case J.Font:try{let e=new FontFace(i.family,i.buffer?new Uint8Array(JSON.parse(i.fontSource)):i.fontSource,i.descriptors);(r=this.iframe.contentDocument)==null||r.fonts.add(e)}catch(e){this.warn(e)}break;case J.Selection:if(t){this.lastSelectionData=i;break}this.applySelection(i);break;case J.AdoptedStyleSheet:this.usingVirtualDom?this.adoptedStyleSheets.push(i):this.applyAdoptedStyleSheet(i);break}}applyMutation(e,t){if(this.config.useVirtualDom&&!this.usingVirtualDom&&t&&(this.usingVirtualDom=!0,Ls(this.iframe.contentDocument,this.mirror,this.virtualDom),Object.keys(this.legacy_missingNodeRetryMap).length))for(let e in this.legacy_missingNodeRetryMap)try{let t=this.legacy_missingNodeRetryMap[e],n=Is(t.node,this.virtualDom,this.mirror);n&&(t.node=n)}catch(e){this.warn(e)}let n=this.usingVirtualDom?this.virtualDom.mirror:this.mirror;e.removes=e.removes.filter(t=>n.getNode(t.id)?!0:(this.warnNodeNotFound(e,t.id),!1)),e.removes.forEach(t=>{let r=n.getNode(t.id);if(!r)return;let i=n.getNode(t.parentId);if(!i)return this.warnNodeNotFound(e,t.parentId);if(t.isShadow&&gc(i)&&(i=i.shadowRoot),n.removeNodeFromMap(r),i)try{i.removeChild(r),this.usingVirtualDom&&r.nodeName===`#text`&&i.nodeName===`STYLE`&&i.rules?.length>0&&(i.rules=[])}catch(t){if(t instanceof DOMException)this.warn(`parent could not remove child in mutation`,i,r,e);else throw t}});let r={...this.legacy_missingNodeRetryMap},i=[],a=e=>{let t=null;return e.nextId&&(t=n.getNode(e.nextId)),e.nextId!==null&&e.nextId!==void 0&&e.nextId!==-1&&!t},o=e=>{if(!this.iframe.contentDocument)return this.warn(`Looks like your replayer has been destroyed.`);let t=n.getNode(e.parentId);if(!t)return e.node.type===Z.Document?this.newDocumentQueue.push(e):i.push(e);e.node.isShadow&&(gc(t)||t.attachShadow({mode:`open`}),t=t.shadowRoot);let o=null,s=null;if(e.previousId&&(o=n.getNode(e.previousId)),e.nextId&&(s=n.getNode(e.nextId)),a(e))return i.push(e);if(e.node.rootId&&!n.getNode(e.node.rootId))return;let c=e.node.rootId?n.getNode(e.node.rootId):this.usingVirtualDom?this.virtualDom:this.iframe.contentDocument;if(mc(t,n)){this.attachDocumentToIframe(e,t);return}let l=(e,t)=>{if(!this.usingVirtualDom){rl(e);for(let n of this.config.plugins||[])n.onBuild&&n.onBuild(e,{id:t,replayer:this})}},u=Cr(e.node,{doc:c,mirror:n,skipChild:!0,hackCss:!0,cache:this.cache,afterAppend:l});if(e.previousId===-1||e.nextId===-1){r[e.node.id]={node:u,mutation:e};return}let d=n.getMeta(t);if(d&&d.type===Z.Element&&e.node.type===Z.Text){let e=Array.isArray(t.childNodes)?t.childNodes:Array.from(t.childNodes);if(d.tagName===`textarea`)for(let n of e)n.nodeType===t.TEXT_NODE&&t.removeChild(n);else if(d.tagName===`style`&&e.length===1)for(let r of e)r.nodeType===t.TEXT_NODE&&!n.hasNode(r)&&(u.textContent=r.textContent,t.removeChild(r))}else if(d?.type===Z.Document){let n=t;e.node.type===Z.DocumentType&&n.childNodes[0]?.nodeType===Node.DOCUMENT_TYPE_NODE&&n.removeChild(n.childNodes[0]),u.nodeName===`HTML`&&n.documentElement&&n.removeChild(n.documentElement)}if(o&&o.nextSibling&&o.nextSibling.parentNode?t.insertBefore(u,o.nextSibling):s&&s.parentNode?t.contains(s)?t.insertBefore(u,s):t.insertBefore(u,null):t.appendChild(u),l(u,e.node.id),this.usingVirtualDom&&u.nodeName===`#text`&&t.nodeName===`STYLE`&&t.rules?.length>0&&(t.rules=[]),mc(u,this.mirror)){let e=this.mirror.getId(u),t=this.newDocumentQueue.find(t=>t.parentId===e);t&&(this.attachDocumentToIframe(t,u),this.newDocumentQueue=this.newDocumentQueue.filter(e=>e!==t))}(e.previousId||e.nextId)&&this.legacy_resolveMissingNode(r,t,u,e)};e.adds.forEach(e=>{o(e)});let s=Date.now();for(;i.length;){let e=fc(i);if(i.length=0,Date.now()-s>500){this.warn(`Timeout in the loop, please check the resolve tree data:`,e);break}for(let t of e)n.getNode(t.value.parentId)?pc(t,e=>{o(e)}):this.debug(`Drop resolve tree since there is no parent for the root node.`,t)}Object.keys(r).length&&Object.assign(this.legacy_missingNodeRetryMap,r),yc(e.texts).forEach(t=>{let r=n.getNode(t.id);if(!r)return e.removes.find(e=>e.id===t.id)?void 0:this.warnNodeNotFound(e,t.id);let i=r.parentElement;if(t.value&&i&&i.tagName===`STYLE`?r.textContent=vr(t.value,this.cache):r.textContent=t.value,this.usingVirtualDom){let e=r.parentNode;e?.rules?.length>0&&(e.rules=[])}}),e.attributes.forEach(t=>{let r=n.getNode(t.id);if(!r)return e.removes.find(e=>e.id===t.id)?void 0:this.warnNodeNotFound(e,t.id);for(let e in t.attributes)if(typeof e==`string`){let i=t.attributes[e];if(i===null)r.removeAttribute(e),e===`open`&&il(r,t);else if(typeof i==`string`)try{if(e===`_cssText`&&(r.nodeName===`LINK`||r.nodeName===`STYLE`))try{let e=n.getMeta(r),i=Cr({...e,attributes:{...e.attributes,...t.attributes}},{doc:r.ownerDocument,mirror:n,skipChild:!0,hackCss:!0,cache:this.cache});Object.assign(e.attributes,t.attributes);let a=r.nextSibling,o=r.parentNode;if(i&&o){o.removeChild(r),o.insertBefore(i,a),n.replace(t.id,i);break}}catch{}if(e===`value`&&r.nodeName===`TEXTAREA`){let e=r;e.childNodes.forEach(t=>e.removeChild(t));let t=r.ownerDocument?.createTextNode(i);t&&e.appendChild(t)}else r.setAttribute(e,i);e===`rr_open_mode`&&r.nodeName===`DIALOG`&&rl(r,t)}catch(e){this.warn(`An error occurred may due to the checkout feature.`,e)}else if(e===`style`){let e=i,t=r;for(let n in e)if(e[n]===!1)t.style.removeProperty(n);else if(e[n]instanceof Array){let r=e[n];t.style.setProperty(n,r[0],r[1])}else{let r=e[n];t.style.setProperty(n,r)}}}})}applyScroll(e,t){var n,r;let i=this.mirror.getNode(e.id);if(!i)return this.debugNodeNotFound(e,e.id);let a=this.mirror.getMeta(i);if(i===this.iframe.contentDocument)(n=this.iframe.contentWindow)==null||n.scrollTo({top:e.y,left:e.x,behavior:t?`auto`:`smooth`});else if(a?.type===Z.Document)(r=i.defaultView)==null||r.scrollTo({top:e.y,left:e.x,behavior:t?`auto`:`smooth`});else try{i.scrollTo({top:e.y,left:e.x,behavior:t?`auto`:`smooth`})}catch{}}applyInput(e){let t=this.mirror.getNode(e.id);if(!t)return this.debugNodeNotFound(e,e.id);try{t.checked=e.isChecked,t.value=e.text}catch{}}applySelection(e){try{let t=new Set,n=e.ranges.map(({start:e,startOffset:n,end:r,endOffset:i})=>{let a=this.mirror.getNode(e),o=this.mirror.getNode(r);if(!a||!o)return;let s=new Range;s.setStart(a,n),s.setEnd(o,i);let c=a.ownerDocument?.getSelection();return c&&t.add(c),{range:s,selection:c}});t.forEach(e=>e.removeAllRanges()),n.forEach(e=>e&&e.selection?.addRange(e.range))}catch{}}applyStyleSheetMutation(e){let t=null;e.styleId?t=this.styleMirror.getStyle(e.styleId):e.id&&(t=this.mirror.getNode(e.id)?.sheet||null),t&&(e.source===J.StyleSheetRule?this.applyStyleSheetRule(e,t):e.source===J.StyleDeclaration&&this.applyStyleDeclaration(e,t))}applyStyleSheetRule(e,t){var n,r,i,a;if((n=e.adds)==null||n.forEach(({rule:e,index:n})=>{try{if(Array.isArray(n)){let{positions:r,index:i}=vc(n);_c(t.cssRules,r).insertRule(e,i)}else{let r=n===void 0?void 0:Math.min(n,t.cssRules.length);t?.insertRule(e,r)}}catch{}}),(r=e.removes)==null||r.forEach(({index:e})=>{try{if(Array.isArray(e)){let{positions:n,index:r}=vc(e);_c(t.cssRules,n).deleteRule(r||0)}else t?.deleteRule(e)}catch{}}),e.replace)try{(i=t.replace)==null||i.call(t,e.replace)}catch{}if(e.replaceSync)try{(a=t.replaceSync)==null||a.call(t,e.replaceSync)}catch{}}applyStyleDeclaration(e,t){e.set&&_c(t.rules,e.index).style.setProperty(e.set.property,e.set.value,e.set.priority),e.remove&&_c(t.rules,e.index).style.removeProperty(e.remove.property)}applyAdoptedStyleSheet(e){var t;let n=this.mirror.getNode(e.id);if(!n)return;(t=e.styles)==null||t.forEach(e=>{let t=null,r=null;if(gc(n)?r=n.ownerDocument?.defaultView||null:n.nodeName===`#document`&&(r=n.defaultView),r)try{t=new r.CSSStyleSheet,this.styleMirror.add(t,e.styleId),this.applyStyleSheetRule({source:J.StyleSheetRule,adds:e.rules},t)}catch{}});let r=0,i=(e,t)=>{let n=t.map(e=>this.styleMirror.getStyle(e)).filter(e=>e!==null);gc(e)?e.shadowRoot.adoptedStyleSheets=n:e.nodeName===`#document`&&(e.adoptedStyleSheets=n),n.length!==t.length&&r<10&&(setTimeout(()=>i(e,t),0+100*r),r++)};i(n,e.styleIds)}legacy_resolveMissingNode(e,t,n,r){let{previousId:i,nextId:a}=r,o=i&&e[i],s=a&&e[a];if(o){let{node:r,mutation:i}=o;t.insertBefore(r,n),delete e[i.node.id],delete this.legacy_missingNodeRetryMap[i.node.id],(i.previousId||i.nextId)&&this.legacy_resolveMissingNode(e,t,r,i)}if(s){let{node:r,mutation:i}=s;t.insertBefore(r,n.nextSibling),delete e[i.node.id],delete this.legacy_missingNodeRetryMap[i.node.id],(i.previousId||i.nextId)&&this.legacy_resolveMissingNode(e,t,r,i)}}moveAndHover(e,t,n,r,i){let a=this.mirror.getNode(n);if(!a)return this.debugNodeNotFound(i,n);let o=hc(a,this.iframe),s=e*o.absoluteScale+o.x,c=t*o.absoluteScale+o.y;this.mouse.style.left=`${s}px`,this.mouse.style.top=`${c}px`,r||this.drawMouseTail({x:s,y:c}),this.hoverElements(a)}drawMouseTail(e){if(!this.mouseTail)return;let{lineCap:t,lineWidth:n,strokeStyle:r,duration:i}=this.config.mouseTail===!0?sl:Object.assign({},sl,this.config.mouseTail),a=()=>{if(!this.mouseTail)return;let e=this.mouseTail.getContext(`2d`);!e||!this.tailPositions.length||(e.clearRect(0,0,this.mouseTail.width,this.mouseTail.height),e.beginPath(),e.lineWidth=n,e.lineCap=t,e.strokeStyle=r,e.moveTo(this.tailPositions[0].x,this.tailPositions[0].y),this.tailPositions.forEach(t=>e.lineTo(t.x,t.y)),e.stroke())};this.tailPositions.push(e),a(),setTimeout(()=>{this.tailPositions=this.tailPositions.filter(t=>t!==e),a()},i/this.speedService.state.context.timer.speed)}hoverElements(e){var t;(t=this.lastHoveredRootNode||this.iframe.contentDocument)==null||t.querySelectorAll(`.\\:hover`).forEach(e=>{e.classList.remove(`:hover`)}),this.lastHoveredRootNode=e.getRootNode();let n=e;for(;n;)n.classList&&n.classList.add(`:hover`),n=n.parentElement}isUserInteraction(e){return e.type===q.IncrementalSnapshot&&e.data.source>J.Mutation&&e.data.source<=J.Input}backToNormal(){this.nextUserInteractionEvent=null,!this.speedService.state.matches(`normal`)&&(this.speedService.send({type:`BACK_TO_NORMAL`}),this.emitter.emit(X.SkipEnd,{speed:this.speedService.state.context.normalSpeed}))}warnNodeNotFound(e,t){this.warn(`Node with id '${t}' not found. `,e)}warnCanvasMutationFailed(e,t){this.warn(`Has error on canvas update`,t,`canvas mutation:`,e)}debugNodeNotFound(e,t){this.debug(`Node with id '${t}' not found. `,e)}warn(...e){this.config.showWarning&&this.config.logger.warn(ol,...e)}debug(...e){this.config.showDebug&&this.config.logger.log(ol,...e)}},ul=(e=>(e[e.DomContentLoaded=0]=`DomContentLoaded`,e[e.Load=1]=`Load`,e[e.FullSnapshot=2]=`FullSnapshot`,e[e.IncrementalSnapshot=3]=`IncrementalSnapshot`,e[e.Meta=4]=`Meta`,e[e.Custom=5]=`Custom`,e[e.Plugin=6]=`Plugin`,e))(ul||{});function dl({events:a}){let o=t(null),s=t(null),c=t(null),[l,u]=n(0),[d,f]=n(0);return e(()=>{if(!o.current||a.length===0)return;let e=o.current,t=e.offsetWidth,n=e.offsetHeight,r=a.find(e=>e.type===ul.Meta);if(!r)return;let{width:i,height:l}=r.data;if(s.current){try{s.current.destroy()}catch{}s.current=null}e.innerHTML=``;let d=new ll(a,{root:e,skipInactive:!0,showWarning:!1,showDebug:!1,triggerFocus:!1,mouseTail:{duration:500,lineCap:`round`,lineWidth:2}}),{totalTime:p}=d.getMetaData();f(p);let m=t/i,h=n/l,g=Math.max(m,h);d.wrapper.style.width=`${i}px`,d.wrapper.style.height=`${l}px`,d.wrapper.style.position=`absolute`,d.wrapper.style.left=`50%`,d.wrapper.style.top=`50%`,d.wrapper.style.transform=`translate(-50%, -50%) scale(${g})`,d.wrapper.style.transformOrigin=`center center`;let _=document.createElement(`style`);return _.textContent=`
70
70
  .replayer-mouse-tail {
71
71
  position: absolute;
72
72
  }
73
- `,d.wrapper.appendChild(v),s.current=d,d.play(),m(),d.on(`finish`,()=>{u(0),d.play(0)}),()=>{if(c.current&&=(clearInterval(c.current),null),s.current){try{s.current.destroy()}catch{}s.current=null}}},[a]),i(`div`,{className:`cf-bug-report-player-container`,children:[r(`div`,{ref:o,className:`cf-bug-report-player`}),r(`div`,{className:`cf-bug-report-progress-bar`,style:{width:`${l}%`,transitionDuration:l===0?`0s`:`100ms`,transitionTimingFunction:`linear`}}),i(`div`,{className:`cf-bug-report-time`,children:[Math.floor(d/1e3),`s`]})]})}export{dl as default};
73
+ `,d.wrapper.appendChild(_),s.current=d,d.play(),c.current&&clearInterval(c.current),c.current=setInterval(()=>{let e=d.getCurrentTime();u(p>0?e/p*100:0)},100),d.on(`finish`,()=>{u(0),d.play(0)}),()=>{if(c.current&&=(clearInterval(c.current),null),s.current){try{s.current.destroy()}catch{}s.current=null}}},[a]),i(`div`,{className:`cf-bug-report-player-container`,children:[r(`div`,{ref:o,className:`cf-bug-report-player`}),r(`div`,{className:`cf-bug-report-progress-bar`,style:{width:`${l}%`,transitionDuration:l===0?`0s`:`100ms`,transitionTimingFunction:`linear`}}),i(`div`,{className:`cf-bug-report-time`,children:[Math.floor(d/1e3),`s`]})]})}export{dl as default};
@@ -1,2 +1,2 @@
1
- import { r as ModalContent } from "./ModalContainer-DnTgSV6A.js";
1
+ import { r as ModalContent } from "./ModalContainer-BX7AxPDq.js";
2
2
  export { ModalContent as UnstableModalContent };
@@ -1 +1 @@
1
- import{n as e}from"./ModalContainer-DlskMgoM.js";export{e as UnstableModalContent};
1
+ import{n as e}from"./ModalContainer-DcF9hn27.js";export{e as UnstableModalContent};
@@ -1,6 +1,6 @@
1
- import { d as SingleSelectQuestionProperties, f as StatementQuestionProperties, l as MultiSelectQuestionProperties, p as TextQuestionProperties, r as Locale, u as RatingQuestionProperties } from "./index-DLqC_qk3.js";
2
- import { n as ModalContainerProps, t as ModalContainer } from "./ModalContainer-DnTgSV6A.js";
3
- import { C as ConfettiState, _ as useSurvey, a as BaseFieldProps, b as Answer, c as ConfettiProviderProps, d as RespondentVisibilityProviderProps, g as SurveyProviderProps, h as SurveyProvider, i as BugReportOptions, k as Question, l as RespondentVisibilityContext, m as SurveyContext, n as Confetti, o as Question$1, p as useRespondentVisibility, r as ConfettiProps, s as ConfettiProvider, t as BaseConfettiProps, u as RespondentVisibilityProvider, v as ConfettiController, y as ConfettiControllerProps } from "./Confetti-Ch8bCyn_.js";
1
+ import { d as SingleSelectQuestionProperties, f as StatementQuestionProperties, l as MultiSelectQuestionProperties, p as TextQuestionProperties, r as Locale, u as RatingQuestionProperties } from "./index-C6cGD5WB.js";
2
+ import { n as ModalContainerProps, t as ModalContainer } from "./ModalContainer-BX7AxPDq.js";
3
+ import { C as ConfettiState, _ as useSurvey, a as BaseFieldProps, b as Answer, c as ConfettiProviderProps, d as RespondentVisibilityProviderProps, g as SurveyProviderProps, h as SurveyProvider, i as BugReportOptions, k as Question, l as RespondentVisibilityContext, m as SurveyContext, n as Confetti, o as Question$1, p as useRespondentVisibility, r as ConfettiProps, s as ConfettiProvider, t as BaseConfettiProps, u as RespondentVisibilityProvider, v as ConfettiController, y as ConfettiControllerProps } from "./Confetti-DSoOgKU5.js";
4
4
  import { HTMLAttributes, JSX, PropsWithChildren, SVGProps } from "react";
5
5
 
6
6
  //#region src/components/container/PopoverContainer.d.ts
@@ -1 +1 @@
1
- import{n as e,t}from"./DefaultConfettiTrigger-qiD0c65-.js";import{d as n,f as r,p as i,r as a,t as o}from"./ModalContainer-DlskMgoM.js";import{a as s,c,d as l,f as u,h as d,i as f,l as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x}from"./Embed-B37tSunS.js";import{ErrorBoundary as S}from"react-error-boundary";import{Fragment as C,jsx as w}from"react/jsx-runtime";const T=({children:e,respondent:t,isSurveyVisible:n,...i})=>{let{respondent:a}=m();return w(r,{...i,respondent:a,children:e})},E=({children:e,...t})=>w(_,{...t,children:w(T,{...t,children:e})}),D=({children:e,onFinished:t,shouldAutoSubmit:n,...r})=>w(S,{fallback:w(C,{}),children:w(E,{...r,children:w(d,{shouldAutoSubmit:n,onFinished:t,children:e})})});export{v as BackButton,a as CloseButton,D as Confetti,d as ConfettiController,E as ConfettiProvider,e as ConfettiTriggerIcon,t as DefaultConfettiTrigger,b as Embed,h as Flow,x as FreeText,o as ModalContainer,p as MultiChoice,l as PopoverContainer,c as Rating,u as RespondentVisibilityContext,_ as RespondentVisibilityProvider,y as SingleChoice,g as Statement,n as SurveyContext,r as SurveyProvider,s as SurveyQuestionFactory,f as ThankYouMessage,m as useRespondentVisibility,i as useSurvey};
1
+ import{n as e,t}from"./DefaultConfettiTrigger-B0_iX1RM.js";import{d as n,f as r,p as i,r as a,t as o}from"./ModalContainer-DcF9hn27.js";import{a as s,c,d as l,f as u,h as d,i as f,l as p,m,n as h,o as g,p as _,r as v,s as y,t as b,u as x}from"./Embed-BJcGr0sB.js";import{ErrorBoundary as S}from"react-error-boundary";import{Fragment as C,jsx as w}from"react/jsx-runtime";const T=({children:e,respondent:t,isSurveyVisible:n,...i})=>{let{respondent:a}=m();return w(r,{...i,respondent:a,children:e})},E=({children:e,...t})=>w(_,{...t,children:w(T,{...t,children:e})}),D=({children:e,onFinished:t,shouldAutoSubmit:n,...r})=>w(S,{fallback:w(C,{}),children:w(E,{...r,children:w(d,{shouldAutoSubmit:n,onFinished:t,children:e})})});export{v as BackButton,a as CloseButton,D as Confetti,d as ConfettiController,E as ConfettiProvider,e as ConfettiTriggerIcon,t as DefaultConfettiTrigger,b as Embed,h as Flow,x as FreeText,o as ModalContainer,p as MultiChoice,l as PopoverContainer,c as Rating,u as RespondentVisibilityContext,_ as RespondentVisibilityProvider,y as SingleChoice,g as Statement,n as SurveyContext,r as SurveyProvider,s as SurveyQuestionFactory,f as ThankYouMessage,m as useRespondentVisibility,i as useSurvey};
@@ -108,25 +108,15 @@ declare const ratingAnswerSchemaFactory: ({
108
108
  required
109
109
  }: {
110
110
  required: boolean;
111
- }) => z.ZodNumber | z.ZodOptional<z.ZodNumber>;
111
+ }) => z.ZodOptional<z.ZodPreprocess<z.ZodNumber>> | z.ZodPreprocess<z.ZodNumber>;
112
112
  type RatingAnswer = z.infer<ReturnType<typeof ratingAnswerSchemaFactory>>;
113
- declare const singleSelectAnswerSchemaFactory: ({
114
- maxLength
115
- }: {
116
- maxLength?: number;
117
- }, {
113
+ declare const singleSelectAnswerSchemaFactory: (properties: Pick<SingleSelectQuestionProperties, 'options' | 'editable'>, {
118
114
  required
119
115
  }: {
120
116
  required: boolean;
121
117
  }) => z.ZodOptional<z.ZodString> | z.ZodString;
122
118
  type SingleSelectAnswer = z.infer<ReturnType<typeof singleSelectAnswerSchemaFactory>>;
123
- declare const multiSelectAnswerSchemaFactory: ({
124
- maxSelected,
125
- maxLength
126
- }: {
127
- maxSelected?: number;
128
- maxLength?: number;
129
- }, {
119
+ declare const multiSelectAnswerSchemaFactory: (properties: Pick<MultiSelectQuestionProperties, 'options' | 'editable' | 'max'>, {
130
120
  required
131
121
  }: {
132
122
  required: boolean;
package/build/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { r as Locale } from "./index-DLqC_qk3.js";
2
- import { D as OptionallyDismissable, E as Finishable, O as Proxyable, S as ConfettiContainer, T as Dismissable, t as BaseConfettiProps, w as Containable, x as Closable } from "./Confetti-Ch8bCyn_.js";
1
+ import { r as Locale } from "./index-C6cGD5WB.js";
2
+ import { D as OptionallyDismissable, E as Finishable, O as Proxyable, S as ConfettiContainer, T as Dismissable, t as BaseConfettiProps, w as Containable, x as Closable } from "./Confetti-DSoOgKU5.js";
3
3
 
4
4
  //#region src/contracts/api.d.ts
5
5
  type Template = 'TriggerPopover' | 'Popover' | 'Modal' | 'Embedded' | 'Stepper';
package/build/index.js CHANGED
@@ -1 +1 @@
1
- import{a as e,i as t,o as n,r,s as i,t as a}from"./DefaultConfettiTrigger-qiD0c65-.js";import{Z as o}from"./Button-B2r-VRNX.js";import{a as s}from"./src-xi3Tt2Zs.js";import{useCallback as c,useEffect as l,useMemo as u,useRef as d,useState as f}from"react";import{ErrorBoundary as p}from"react-error-boundary";import{useLocalStorage as m,useSessionStorage as h}from"usehooks-ts";import{Fragment as g,jsx as _,jsxs as v}from"react/jsx-runtime";const y=`confetti:ready`,b=`https://confetti.gov.sg`,x={promise:null,channel:null,url:null};function S(){x.promise=null,x.channel=null,x.url=null}function C(){x.promise=null}function w(e){return new URL(``,e).href}function T(e,t,n){let r=new URL(e);return r.pathname.endsWith(`/`)||(r.pathname+=`/`),new URL(`widget/v1/${t}.${n}`,r).href}function E(e=`stable`,t=b){if(typeof window>`u`)return Promise.reject(Error(`[confetti] No window found, SSR environments are not supported`));let n;try{n=w(t)}catch{return Promise.reject(Error(`[confetti] Invalid URL: ${t}`))}if(x.promise)return x.channel===e?x.url===n?x.promise:Promise.reject(Error(`[confetti] Cannot switch baseUrl from ${String(x.url)} to ${n} on the same page`)):Promise.reject(Error(`[confetti] Cannot switch channel from ${String(x.channel)} to ${e} on the same page`));let r=window.__confetti;if(r){let t=String(r.channel);return t===e?x.url!==null&&x.url!==n?Promise.reject(Error(`[confetti] Cannot switch URL from ${x.url} to ${n} on the same page`)):j(r):Promise.reject(Error(`[confetti] Cannot switch channel from ${t} to ${e} on the same page`))}let i=O(n,e);return x.channel=e,x.url=n,x.promise=i,i}function D(e=`stable`,t=b){if(typeof window>`u`)return Promise.resolve();let n;try{n=w(t)}catch{return Promise.reject(Error(`[confetti] Invalid URL: ${t}`))}return k(n,e)}async function O(e,t){let n=!!document.querySelector(`link[data-confetti-loader]`),r,i=new Promise((e,t)=>{r=setTimeout(()=>t(Error(`[confetti] Script load timeout`)),1e4)});try{let[,n]=await Promise.race([i,Promise.all([k(e,t),A(e,t)])]);return clearTimeout(r),C(),n}catch(e){throw clearTimeout(r),n||document.querySelector(`link[data-confetti-loader]`)?.remove(),document.querySelector(`script[data-confetti-loader]`)?.remove(),S(),e}}function k(e,t){return new Promise((n,r)=>{if(document.querySelector(`link[data-confetti-loader]`)){n();return}let i=document.createElement(`link`);i.rel=`stylesheet`,i.href=T(e,t,`css`),i.crossOrigin=`anonymous`,i.dataset.confettiLoader=``,i.onload=()=>n(),i.onerror=e=>{i.remove(),console.error(`[confetti] Stylesheet load failed. If your site uses a Content-Security-Policy, ensure style-src includes https://confetti.gov.sg (and script-src for the bundle).`),r(Error(`[confetti] Stylesheet load failed (check CSP allowlist for confetti.gov.sg)`,{cause:e}))},document.head.appendChild(i)})}function A(e,t){return new Promise((n,r)=>{let i=()=>{let e=window.__confetti;if(!e){r(Error(`[confetti] Ready event fired but global state is missing`));return}j(e).then(n,r)};if(window.addEventListener(y,i,{once:!0}),document.querySelector(`script[data-confetti-loader]`))return;let a=document.createElement(`script`);a.src=T(e,t,`js`),a.async=!0,a.crossOrigin=`anonymous`,a.dataset.confettiLoader=``,a.onerror=e=>{window.removeEventListener(y,i),console.error(`[confetti] Script load failed. If your site uses a Content-Security-Policy, ensure script-src includes https://confetti.gov.sg (and style-src for the CSS).`),r(Error(`[confetti] Script load failed (check CSP allowlist for confetti.gov.sg)`,{cause:e}))},document.head.appendChild(a)})}function j(e){let t=Number(e.protocolVersion);return Number.isFinite(t)?t===1?Promise.resolve(e):Promise.reject(Error(`[confetti] Wire protocol v${t} does not match expected v1`)):Promise.reject(Error(`[confetti] Wire protocol value is not a number (got ${typeof e.protocolVersion})`))}function M(e){let t=d(null),n=d(null),r=d(e.props),i=e.channel??`stable`,a=e.scriptBaseUrl??`https://confetti.gov.sg`;r.current=e.props,l(()=>{if(!e.element)return;let o=!1;return E(i,a).then(i=>{o||!e.element||(n.current=i,t.current=i.mount({template:e.template,element:e.element,props:r.current}))}).catch(t=>e.onError?.(t instanceof Error?t:Error(String(t)))),()=>{o=!0,t.current&&n.current&&n.current.unmount(t.current),t.current=null,n.current=null}},[i,a,e.element,e.template]),l(()=>{t.current&&n.current&&n.current.update(t.current,e.props)},[e.props])}function N(e){let[t,n]=f(null);return M({...e,element:t}),_(p,{fallback:_(g,{}),children:_(`div`,{ref:n,"data-confetti-mount":!0})})}function P(a){let s=e({surveyId:a.surveyId,override:a.respondent}),c=o({publishableKey:a.publishableKey,apiBaseUrl:a.proxyUrl}),{isAvailable:l,isSettled:d}=r({client:c,surveyId:a.surveyId}),{state:m,isSettled:h}=t({client:c,surveyId:a.surveyId,respondent:s,enabled:i(a.isSurveyVisible)}),v=n(m,a.isSurveyVisible),[y,b]=f(!1),x=d&&l&&h&&v&&!y,S=a.onFinished,C=a.onClose,w=u(()=>({surveyId:a.surveyId,publishableKey:a.publishableKey,respondent:s,locale:a.locale,metadata:a.metadata,autoInjectAnalyticsMetadata:a.autoInjectAnalyticsMetadata,apiBaseUrl:a.proxyUrl,telemetry:{version:`0.9.2`},onFinished:S,onClose:()=>{b(!0),C?.()},options:a.options}),[a.surveyId,a.publishableKey,s,a.locale,a.metadata,a.autoInjectAnalyticsMetadata,a.proxyUrl,a.options,S,C]);if(!x)return null;let T=_(N,{template:`Embedded`,channel:a.channel,scriptBaseUrl:a.proxyUrl,onError:a.onError,props:w});return _(p,{fallback:_(g,{}),children:a.container?a.container({survey:T}):T})}function F(a){let s=e({surveyId:a.surveyId,override:a.respondent}),c=o({publishableKey:a.publishableKey,apiBaseUrl:a.proxyUrl}),{isAvailable:l,isSettled:d}=r({client:c,surveyId:a.surveyId}),{state:m,isSettled:h}=t({client:c,surveyId:a.surveyId,respondent:s,enabled:i(a.isSurveyVisible)}),v=n(m,a.isSurveyVisible),[y,b]=f(!1),x=d&&l&&h&&v&&!y,S=a.onFinished,C=a.onDismiss,w=a.onClose,T=u(()=>({surveyId:a.surveyId,publishableKey:a.publishableKey,respondent:s,locale:a.locale,metadata:a.metadata,autoInjectAnalyticsMetadata:a.autoInjectAnalyticsMetadata,apiBaseUrl:a.proxyUrl,telemetry:{version:`0.9.2`},closeOnFinishMs:a.closeOnFinishMs,isDismissable:a.isDismissable,onFinished:S,onClose:()=>{b(!0),w?.()},onDismiss:()=>{C?.()},options:a.options}),[a.surveyId,a.publishableKey,s,a.locale,a.metadata,a.autoInjectAnalyticsMetadata,a.proxyUrl,a.closeOnFinishMs,a.isDismissable,a.options,S,C,w]);return x?_(p,{fallback:_(g,{}),children:_(N,{template:`Modal`,channel:a.channel,scriptBaseUrl:a.proxyUrl,onError:a.onError,props:T})}):null}function I(a){let s=e({surveyId:a.surveyId,override:a.respondent}),c=o({publishableKey:a.publishableKey,apiBaseUrl:a.proxyUrl}),{isAvailable:l,isSettled:d}=r({client:c,surveyId:a.surveyId}),{state:m,isSettled:h}=t({client:c,surveyId:a.surveyId,respondent:s,enabled:i(a.isSurveyVisible)}),v=n(m,a.isSurveyVisible),[y,b]=f(!1),x=d&&l&&h&&v&&!y,S=a.onFinished,C=a.onDismiss,w=a.onClose,T=u(()=>({surveyId:a.surveyId,publishableKey:a.publishableKey,respondent:s,locale:a.locale,metadata:a.metadata,autoInjectAnalyticsMetadata:a.autoInjectAnalyticsMetadata,apiBaseUrl:a.proxyUrl,telemetry:{version:`0.9.2`},closeOnFinishMs:a.closeOnFinishMs,onFinished:S,onClose:()=>{b(!0),w?.()},onDismiss:()=>{C?.()},options:a.options}),[a.surveyId,a.publishableKey,s,a.locale,a.metadata,a.autoInjectAnalyticsMetadata,a.proxyUrl,a.closeOnFinishMs,a.options,S,C,w]);return x?_(p,{fallback:_(g,{}),children:_(N,{template:`Popover`,channel:a.channel,scriptBaseUrl:a.proxyUrl,onError:a.onError,props:T})}):null}function L(a){let s=e({surveyId:a.surveyId,override:a.respondent}),c=o({publishableKey:a.publishableKey,apiBaseUrl:a.proxyUrl}),{isAvailable:l,isSettled:d}=r({client:c,surveyId:a.surveyId}),{state:m,isSettled:h}=t({client:c,surveyId:a.surveyId,respondent:s,enabled:i(a.isSurveyVisible)}),v=n(m,a.isSurveyVisible),[y,b]=f(!1),x=d&&l&&h&&v&&!y,S=a.onFinished,C=a.onClose,w=u(()=>({surveyId:a.surveyId,publishableKey:a.publishableKey,respondent:s,locale:a.locale,metadata:a.metadata,autoInjectAnalyticsMetadata:a.autoInjectAnalyticsMetadata,apiBaseUrl:a.proxyUrl,telemetry:{version:`0.9.2`},onFinished:S,onClose:()=>{b(!0),C?.()},options:a.options}),[a.surveyId,a.publishableKey,s,a.locale,a.metadata,a.autoInjectAnalyticsMetadata,a.proxyUrl,a.options,S,C]);if(!x)return null;let T=_(N,{template:`Stepper`,channel:a.channel,scriptBaseUrl:a.proxyUrl,onError:a.onError,props:w});return _(p,{fallback:_(g,{}),children:a.container?a.container({survey:T}):T})}function R(s){let m=e({surveyId:s.surveyId,override:s.respondent}),h=o({publishableKey:s.publishableKey,apiBaseUrl:s.proxyUrl}),{isAvailable:y,isSettled:b}=r({client:h,surveyId:s.surveyId}),{state:x,isSettled:S}=t({client:h,surveyId:s.surveyId,respondent:m,enabled:i(s.isSurveyVisible)}),[C,w]=f(!1),T=b&&y&&S&&C&&n(x,s.isSurveyVisible),[E,O]=f(!1),[k,A]=f(!1),{onError:j,channel:M,proxyUrl:P}=s,F=d(j);l(()=>{F.current=j},[j]),l(()=>{if(!(b&&y))return;let e=!1;return D(M,P).then(()=>{e||w(!0)}).catch(e=>F.current?.(e instanceof Error?e:Error(String(e)))),()=>{e=!0}},[b,y,M,P]);let I=T&&E,L=c(()=>O(!0),[]),R=s.onFinished,z=u(()=>({surveyId:s.surveyId,publishableKey:s.publishableKey,respondent:m,locale:s.locale,metadata:s.metadata,autoInjectAnalyticsMetadata:s.autoInjectAnalyticsMetadata,apiBaseUrl:s.proxyUrl,telemetry:{version:`0.9.2`},isOpen:E,onFinished:e=>{A(!0),R?.(e)},onClose:()=>{O(!1)},onDismiss:()=>{O(!1)},options:s.options}),[s.surveyId,s.publishableKey,m,s.locale,s.metadata,s.autoInjectAnalyticsMetadata,s.proxyUrl,s.options,E,R]);return T?v(p,{fallback:_(g,{}),children:[s.trigger?s.trigger({onClick:L,isOpen:E,isSubmitted:k}):_(a,{onClick:L,isWidgetOpen:E}),I?_(N,{template:`TriggerPopover`,channel:s.channel,scriptBaseUrl:s.proxyUrl,onError:s.onError,props:z}):null]}):null}function z(e){return e.trim().split(`-`)[0]?.toLowerCase()??``}function B(e){return e.split(`,`).map(e=>{let[t,...n]=e.split(`;`),r=n.map(e=>e.trim()).find(e=>e.startsWith(`q=`)),i=r?Number(r.slice(2)):1;return{tag:z(t??``),quality:i}}).filter(({quality:e})=>e>0).sort((e,t)=>t.quality-e.quality)}function V(e,t){for(let{tag:n}of B(e)){let e=t.find(e=>e===n);if(e)return e}}function H({preferred:e,explicit:t,available:n=s,base:r=`en`}={}){let i=t??e;return(i?V(i,n):void 0)??r}function U(){if(!(typeof navigator>`u`))return navigator.languages.length>0?navigator.languages.join(`,`):navigator.language}const W=({preferred:e,explicit:t}={})=>H({preferred:e??U(),explicit:t,available:s,base:`en`});function G({surveyId:e,publishableKey:n,respondent:i,proxyUrl:a}){let s=o({publishableKey:n,apiBaseUrl:a}),{isAvailable:c,isSettled:l}=r({client:s,surveyId:e}),{state:u,isSettled:d}=t({client:s,surveyId:e,respondent:i});if(!i)return null;if(!(!l||!d))return c?{lastRespondedAt:u.lastRespondedAt?new Date(u.lastRespondedAt):null,lastDismissedAt:u.lastDismissedAt?new Date(u.lastDismissedAt):null}:null}const K=({delay:e})=>{let[t,n]=f(!1),r=u(()=>e,[]);return l(()=>{let e=setTimeout(()=>{n(!0)},r);return()=>clearTimeout(e)},[]),{isVisible:t}},q=({visits:e,respondent:t})=>{let[n,r]=m(`cfti:${u(()=>window.location.pathname,[])}:visits:${t??``}`,0);return l(()=>{r(e=>e+1)},[r]),{isVisible:n>=e,reset:c(()=>r(0),[r])}},J=({visits:e,respondent:t})=>{let[n,r]=h(`cfti:${u(()=>window.location.pathname,[])}:visits:${t??``}`,0);return l(()=>{r(e=>e+1)},[r]),{isVisible:n>=e,reset:c(()=>r(0),[r])}},Y=({threshold:e})=>{let[t,n]=f(!1);return l(()=>{let t=()=>{window.scrollY>=e&&n(!0)};return t(),window.addEventListener(`scroll`,t,{passive:!0}),()=>window.removeEventListener(`scroll`,t)},[e]),{isVisible:t}};export{P as EmbeddedConfetti,F as ModalConfetti,I as PopoverConfetti,L as StepperConfetti,R as TriggerPopoverConfetti,W as useResolveLocale,G as useRespondentState,K as useVisibleAfterDelay,q as useVisibleAfterPageVisits,Y as useVisibleAfterScroll,J as useVisibleAfterSessionPageVisits};
1
+ import{a as e,i as t,o as n,r,s as i,t as a}from"./DefaultConfettiTrigger-B0_iX1RM.js";import{Z as o}from"./Button-CKL29na5.js";import{a as s}from"./src-DvVD5FzZ.js";import{useCallback as c,useEffect as l,useMemo as u,useRef as d,useState as f}from"react";import{ErrorBoundary as p}from"react-error-boundary";import{useLocalStorage as m,useSessionStorage as h}from"usehooks-ts";import{Fragment as g,jsx as _,jsxs as v}from"react/jsx-runtime";const y=`confetti:ready`,b=`https://confetti.gov.sg`,x={promise:null,channel:null,url:null};function S(){x.promise=null,x.channel=null,x.url=null}function C(){x.promise=null}function w(e){return new URL(``,e).href}function T(e,t,n){let r=new URL(e);return r.pathname.endsWith(`/`)||(r.pathname+=`/`),new URL(`widget/v1/${t}.${n}`,r).href}function E(e=`stable`,t=b){if(typeof window>`u`)return Promise.reject(Error(`[confetti] No window found, SSR environments are not supported`));let n;try{n=w(t)}catch{return Promise.reject(Error(`[confetti] Invalid URL: ${t}`))}if(x.promise)return x.channel===e?x.url===n?x.promise:Promise.reject(Error(`[confetti] Cannot switch baseUrl from ${String(x.url)} to ${n} on the same page`)):Promise.reject(Error(`[confetti] Cannot switch channel from ${String(x.channel)} to ${e} on the same page`));let r=window.__confetti;if(r){let t=String(r.channel);return t===e?x.url!==null&&x.url!==n?Promise.reject(Error(`[confetti] Cannot switch URL from ${x.url} to ${n} on the same page`)):j(r):Promise.reject(Error(`[confetti] Cannot switch channel from ${t} to ${e} on the same page`))}let i=O(n,e);return x.channel=e,x.url=n,x.promise=i,i}function D(e=`stable`,t=b){if(typeof window>`u`)return Promise.resolve();let n;try{n=w(t)}catch{return Promise.reject(Error(`[confetti] Invalid URL: ${t}`))}return k(n,e)}async function O(e,t){let n=!!document.querySelector(`link[data-confetti-loader]`),r,i=new Promise((e,t)=>{r=setTimeout(()=>t(Error(`[confetti] Script load timeout`)),1e4)});try{let[,n]=await Promise.race([i,Promise.all([k(e,t),A(e,t)])]);return clearTimeout(r),C(),n}catch(e){throw clearTimeout(r),n||document.querySelector(`link[data-confetti-loader]`)?.remove(),document.querySelector(`script[data-confetti-loader]`)?.remove(),S(),e}}function k(e,t){return new Promise((n,r)=>{if(document.querySelector(`link[data-confetti-loader]`)){n();return}let i=document.createElement(`link`);i.rel=`stylesheet`,i.href=T(e,t,`css`),i.crossOrigin=`anonymous`,i.dataset.confettiLoader=``,i.onload=()=>n(),i.onerror=e=>{i.remove(),console.error(`[confetti] Stylesheet load failed. If your site uses a Content-Security-Policy, ensure style-src includes https://confetti.gov.sg (and script-src for the bundle).`),r(Error(`[confetti] Stylesheet load failed (check CSP allowlist for confetti.gov.sg)`,{cause:e}))},document.head.appendChild(i)})}function A(e,t){return new Promise((n,r)=>{let i=()=>{let e=window.__confetti;if(!e){r(Error(`[confetti] Ready event fired but global state is missing`));return}j(e).then(n,r)};if(window.addEventListener(y,i,{once:!0}),document.querySelector(`script[data-confetti-loader]`))return;let a=document.createElement(`script`);a.src=T(e,t,`js`),a.async=!0,a.crossOrigin=`anonymous`,a.dataset.confettiLoader=``,a.onerror=e=>{window.removeEventListener(y,i),console.error(`[confetti] Script load failed. If your site uses a Content-Security-Policy, ensure script-src includes https://confetti.gov.sg (and style-src for the CSS).`),r(Error(`[confetti] Script load failed (check CSP allowlist for confetti.gov.sg)`,{cause:e}))},document.head.appendChild(a)})}function j(e){let t=Number(e.protocolVersion);return Number.isFinite(t)?t===1?Promise.resolve(e):Promise.reject(Error(`[confetti] Wire protocol v${t} does not match expected v1`)):Promise.reject(Error(`[confetti] Wire protocol value is not a number (got ${typeof e.protocolVersion})`))}function M(e){let t=d(null),n=d(null),r=d(e.props),i=e.channel??`stable`,a=e.scriptBaseUrl??`https://confetti.gov.sg`;r.current=e.props,l(()=>{if(!e.element)return;let o=!1;return E(i,a).then(i=>{o||!e.element||(n.current=i,t.current=i.mount({template:e.template,element:e.element,props:r.current}))}).catch(t=>e.onError?.(t instanceof Error?t:Error(String(t)))),()=>{o=!0,t.current&&n.current&&n.current.unmount(t.current),t.current=null,n.current=null}},[i,a,e.element,e.template]),l(()=>{t.current&&n.current&&n.current.update(t.current,e.props)},[e.props])}function N(e){let[t,n]=f(null);return M({...e,element:t}),_(p,{fallback:_(g,{}),children:_(`div`,{ref:n,"data-confetti-mount":!0})})}function P(a){let s=e({surveyId:a.surveyId,override:a.respondent}),c=o({publishableKey:a.publishableKey,apiBaseUrl:a.proxyUrl}),{isAvailable:l,isSettled:d}=r({client:c,surveyId:a.surveyId}),{state:m,isSettled:h}=t({client:c,surveyId:a.surveyId,respondent:s,enabled:i(a.isSurveyVisible)}),v=n(m,a.isSurveyVisible),[y,b]=f(!1),x=d&&l&&h&&v&&!y,S=a.onFinished,C=a.onClose,w=u(()=>({surveyId:a.surveyId,publishableKey:a.publishableKey,respondent:s,locale:a.locale,metadata:a.metadata,autoInjectAnalyticsMetadata:a.autoInjectAnalyticsMetadata,apiBaseUrl:a.proxyUrl,telemetry:{version:`0.9.4`},onFinished:S,onClose:()=>{b(!0),C?.()},options:a.options}),[a.surveyId,a.publishableKey,s,a.locale,a.metadata,a.autoInjectAnalyticsMetadata,a.proxyUrl,a.options,S,C]);if(!x)return null;let T=_(N,{template:`Embedded`,channel:a.channel,scriptBaseUrl:a.proxyUrl,onError:a.onError,props:w});return _(p,{fallback:_(g,{}),children:a.container?a.container({survey:T}):T})}function F(a){let s=e({surveyId:a.surveyId,override:a.respondent}),c=o({publishableKey:a.publishableKey,apiBaseUrl:a.proxyUrl}),{isAvailable:l,isSettled:d}=r({client:c,surveyId:a.surveyId}),{state:m,isSettled:h}=t({client:c,surveyId:a.surveyId,respondent:s,enabled:i(a.isSurveyVisible)}),v=n(m,a.isSurveyVisible),[y,b]=f(!1),x=d&&l&&h&&v&&!y,S=a.onFinished,C=a.onDismiss,w=a.onClose,T=u(()=>({surveyId:a.surveyId,publishableKey:a.publishableKey,respondent:s,locale:a.locale,metadata:a.metadata,autoInjectAnalyticsMetadata:a.autoInjectAnalyticsMetadata,apiBaseUrl:a.proxyUrl,telemetry:{version:`0.9.4`},closeOnFinishMs:a.closeOnFinishMs,isDismissable:a.isDismissable,onFinished:S,onClose:()=>{b(!0),w?.()},onDismiss:()=>{C?.()},options:a.options}),[a.surveyId,a.publishableKey,s,a.locale,a.metadata,a.autoInjectAnalyticsMetadata,a.proxyUrl,a.closeOnFinishMs,a.isDismissable,a.options,S,C,w]);return x?_(p,{fallback:_(g,{}),children:_(N,{template:`Modal`,channel:a.channel,scriptBaseUrl:a.proxyUrl,onError:a.onError,props:T})}):null}function I(a){let s=e({surveyId:a.surveyId,override:a.respondent}),c=o({publishableKey:a.publishableKey,apiBaseUrl:a.proxyUrl}),{isAvailable:l,isSettled:d}=r({client:c,surveyId:a.surveyId}),{state:m,isSettled:h}=t({client:c,surveyId:a.surveyId,respondent:s,enabled:i(a.isSurveyVisible)}),v=n(m,a.isSurveyVisible),[y,b]=f(!1),x=d&&l&&h&&v&&!y,S=a.onFinished,C=a.onDismiss,w=a.onClose,T=u(()=>({surveyId:a.surveyId,publishableKey:a.publishableKey,respondent:s,locale:a.locale,metadata:a.metadata,autoInjectAnalyticsMetadata:a.autoInjectAnalyticsMetadata,apiBaseUrl:a.proxyUrl,telemetry:{version:`0.9.4`},closeOnFinishMs:a.closeOnFinishMs,onFinished:S,onClose:()=>{b(!0),w?.()},onDismiss:()=>{C?.()},options:a.options}),[a.surveyId,a.publishableKey,s,a.locale,a.metadata,a.autoInjectAnalyticsMetadata,a.proxyUrl,a.closeOnFinishMs,a.options,S,C,w]);return x?_(p,{fallback:_(g,{}),children:_(N,{template:`Popover`,channel:a.channel,scriptBaseUrl:a.proxyUrl,onError:a.onError,props:T})}):null}function L(a){let s=e({surveyId:a.surveyId,override:a.respondent}),c=o({publishableKey:a.publishableKey,apiBaseUrl:a.proxyUrl}),{isAvailable:l,isSettled:d}=r({client:c,surveyId:a.surveyId}),{state:m,isSettled:h}=t({client:c,surveyId:a.surveyId,respondent:s,enabled:i(a.isSurveyVisible)}),v=n(m,a.isSurveyVisible),[y,b]=f(!1),x=d&&l&&h&&v&&!y,S=a.onFinished,C=a.onClose,w=u(()=>({surveyId:a.surveyId,publishableKey:a.publishableKey,respondent:s,locale:a.locale,metadata:a.metadata,autoInjectAnalyticsMetadata:a.autoInjectAnalyticsMetadata,apiBaseUrl:a.proxyUrl,telemetry:{version:`0.9.4`},onFinished:S,onClose:()=>{b(!0),C?.()},options:a.options}),[a.surveyId,a.publishableKey,s,a.locale,a.metadata,a.autoInjectAnalyticsMetadata,a.proxyUrl,a.options,S,C]);if(!x)return null;let T=_(N,{template:`Stepper`,channel:a.channel,scriptBaseUrl:a.proxyUrl,onError:a.onError,props:w});return _(p,{fallback:_(g,{}),children:a.container?a.container({survey:T}):T})}function R(s){let m=e({surveyId:s.surveyId,override:s.respondent}),h=o({publishableKey:s.publishableKey,apiBaseUrl:s.proxyUrl}),{isAvailable:y,isSettled:b}=r({client:h,surveyId:s.surveyId}),{state:x,isSettled:S}=t({client:h,surveyId:s.surveyId,respondent:m,enabled:i(s.isSurveyVisible)}),[C,w]=f(!1),T=b&&y&&S&&C&&n(x,s.isSurveyVisible),[E,O]=f(!1),[k,A]=f(!1),{onError:j,channel:M,proxyUrl:P}=s,F=d(j);l(()=>{F.current=j},[j]),l(()=>{if(!(b&&y))return;let e=!1;return D(M,P).then(()=>{e||w(!0)}).catch(e=>F.current?.(e instanceof Error?e:Error(String(e)))),()=>{e=!0}},[b,y,M,P]);let I=T&&E,L=c(()=>O(!0),[]),R=s.onFinished,z=u(()=>({surveyId:s.surveyId,publishableKey:s.publishableKey,respondent:m,locale:s.locale,metadata:s.metadata,autoInjectAnalyticsMetadata:s.autoInjectAnalyticsMetadata,apiBaseUrl:s.proxyUrl,telemetry:{version:`0.9.4`},isOpen:E,onFinished:e=>{A(!0),R?.(e)},onClose:()=>{O(!1)},onDismiss:()=>{O(!1)},options:s.options}),[s.surveyId,s.publishableKey,m,s.locale,s.metadata,s.autoInjectAnalyticsMetadata,s.proxyUrl,s.options,E,R]);return T?v(p,{fallback:_(g,{}),children:[s.trigger?s.trigger({onClick:L,isOpen:E,isSubmitted:k}):_(a,{onClick:L,isWidgetOpen:E}),I?_(N,{template:`TriggerPopover`,channel:s.channel,scriptBaseUrl:s.proxyUrl,onError:s.onError,props:z}):null]}):null}function z(e){return e.trim().split(`-`)[0]?.toLowerCase()??``}function B(e){return e.split(`,`).map(e=>{let[t,...n]=e.split(`;`),r=n.map(e=>e.trim()).find(e=>e.startsWith(`q=`)),i=r?Number(r.slice(2)):1;return{tag:z(t??``),quality:i}}).filter(({quality:e})=>e>0).sort((e,t)=>t.quality-e.quality)}function V(e,t){for(let{tag:n}of B(e)){let e=t.find(e=>e===n);if(e)return e}}function H({preferred:e,explicit:t,available:n=s,base:r=`en`}={}){let i=t??e;return(i?V(i,n):void 0)??r}function U(){if(!(typeof navigator>`u`))return navigator.languages.length>0?navigator.languages.join(`,`):navigator.language}const W=({preferred:e,explicit:t}={})=>H({preferred:e??U(),explicit:t});function G({surveyId:e,publishableKey:n,respondent:i,proxyUrl:a}){let s=o({publishableKey:n,apiBaseUrl:a}),{isAvailable:c,isSettled:l}=r({client:s,surveyId:e}),{state:u,isSettled:d}=t({client:s,surveyId:e,respondent:i});if(!i)return null;if(!(!l||!d))return c?{lastRespondedAt:u.lastRespondedAt?new Date(u.lastRespondedAt):null,lastDismissedAt:u.lastDismissedAt?new Date(u.lastDismissedAt):null}:null}const K=({delay:e})=>{let[t,n]=f(!1);return l(()=>{let t=setTimeout(()=>{n(!0)},e);return()=>clearTimeout(t)},[]),{isVisible:t}},q=({visits:e,respondent:t})=>{let[n,r]=m(`cfti:${u(()=>window.location.pathname,[])}:visits:${t??``}`,0);return l(()=>{r(e=>e+1)},[r]),{isVisible:n>=e,reset:c(()=>r(0),[r])}},J=({visits:e,respondent:t})=>{let[n,r]=h(`cfti:${u(()=>window.location.pathname,[])}:visits:${t??``}`,0);return l(()=>{r(e=>e+1)},[r]),{isVisible:n>=e,reset:c(()=>r(0),[r])}},Y=({threshold:e})=>{let[t,n]=f(!1);return l(()=>{let t=()=>{window.scrollY>=e&&n(!0)};return t(),window.addEventListener(`scroll`,t,{passive:!0}),()=>window.removeEventListener(`scroll`,t)},[e]),{isVisible:t}};export{P as EmbeddedConfetti,F as ModalConfetti,I as PopoverConfetti,L as StepperConfetti,R as TriggerPopoverConfetti,W as useResolveLocale,G as useRespondentState,K as useVisibleAfterDelay,q as useVisibleAfterPageVisits,Y as useVisibleAfterScroll,J as useVisibleAfterSessionPageVisits};
@@ -0,0 +1 @@
1
+ import"./src-DvVD5FzZ.js";import{z as e}from"zod";const t=({answer:e,condition:t})=>{let n=t.value.value;switch(t.operator){case`equal`:return e===n;case`not-equal`:return e!==n;case`greater`:return typeof e==`number`&&typeof n==`number`&&e>n;case`greater-or-equal`:return typeof e==`number`&&typeof n==`number`&&e>=n;case`less`:return typeof e==`number`&&typeof n==`number`&&e<n;case`less-or-equal`:return typeof e==`number`&&typeof n==`number`&&e<=n;case`contains`:return Array.isArray(e)&&typeof n==`string`&&e.includes(n);case`not-contains`:return Array.isArray(e)&&typeof n==`string`&&!e.includes(n)}},n=({position:e,value:t})=>{switch(t.type){case`next`:return e+1;case`jump`:return t.target;case`end`:return null}},r=e=>e==null||Array.isArray(e)&&e.length===0,i=({position:e,question:i,answer:a})=>{let o=i.routingLogic;if(o.type===`always`)return n({position:e,value:o.target});if(r(a)&&i.required)return null;let s=r(a)?void 0:o.cases.find(e=>t({answer:a,condition:e}));return n({position:e,value:s?.target??o.default})},a=(e,t,{forceReachableIds:n}={})=>{let r=[...e].sort((e,t)=>e.position-t.position),a=new Set,o=new Set(n);for(let e=0;e<r.length;e++){let n=r[e];if(n){if(e===0||o.has(n.id)){a.add(n.id);continue}for(let o=0;o<e;o++){let s=r[o];if(!(!s||!a.has(s.id))&&i({position:o,question:s,answer:t[s.id]})===e){a.add(n.id);break}}}}return a},o=t,s=`cfti-mask`,c=`cfti-block`,l=`__confetti_bug_report_recording_event`,u=e.object({detail:e.object({isRecording:e.boolean()})});export{o as a,u as i,s as n,a as o,l as r,c as t};
@@ -1,4 +1,4 @@
1
- import { i as RoutableAnswer, m as BinaryOperatorCondition } from "./index-DLqC_qk3.js";
1
+ import { i as RoutableAnswer, m as BinaryOperatorCondition } from "./index-C6cGD5WB.js";
2
2
  import { z } from "zod";
3
3
 
4
4
  //#region src/core/logic/routing.d.ts
@@ -1 +1 @@
1
- import{a as e,i as t,n,r,t as i}from"./internals-Cx8YbMEK.js";export{i as BUG_REPORT_BLOCK_CLASS,n as BUG_REPORT_MASK_CLASS,r as __INTERNAL_BUG_REPORT_RECORDING_EVENT,t as internalBugReportRecordingEventSchema,e as unstableInternalConfettiEvaluateCondition};
1
+ import{a as e,i as t,n,r,t as i}from"./internals-BCQiNSvA.js";export{i as BUG_REPORT_BLOCK_CLASS,n as BUG_REPORT_MASK_CLASS,r as __INTERNAL_BUG_REPORT_RECORDING_EVENT,t as internalBugReportRecordingEventSchema,e as unstableInternalConfettiEvaluateCondition};
@@ -0,0 +1 @@
1
+ import{z as e}from"zod";const t=e.object({type:e.literal(`next`)}),n=e.object({type:e.literal(`end`)}),r=e.object({type:e.literal(`jump`),target:e.number({error:`Target question is required`})}),i=e.discriminatedUnion(`type`,[t,r,n]),a=e.object({type:e.literal(`value`),value:e.union([e.string().check(e.trim(),e.minLength(1,{error:`Value is required`}),e.maxLength(2048)),e.number({error:`Value is required`})])}),o=e.object({type:e.literal(`binary-operator`),operator:e.union([e.literal(`equal`),e.literal(`not-equal`),e.literal(`greater`),e.literal(`greater-or-equal`),e.literal(`less`),e.literal(`less-or-equal`),e.literal(`contains`),e.literal(`not-contains`)]),value:a,target:i}),s=e.object({type:e.literal(`switch`),cases:e.array(o),default:i}),c=e.object({type:e.literal(`always`),target:i}),ee=e.discriminatedUnion(`type`,[c,s]),l=e.string().check(e.trim(),e.maxLength(2048),e.url({protocol:/^(https|mailto)/,error:`Link must start with https:// or mailto:`})),u=e.optional(e.string().check(e.trim(),e.maxLength(50))),te=e.object({value:e.string().check(e.trim(),e.minLength(1,{error:`Value is required`}),e.maxLength(200)),label:e.optional(e.string().max(200)),description:e.optional(e.string().check(e.trim(),e.maxLength(200))),translationId:e.optional(e.cuid2().max(200))}),d=e.array(te).max(100).check(e.superRefine((e,t)=>{let n=new Set;for(let r of e)if(r.translationId!==void 0){if(n.has(r.translationId)){t.addIssue({code:`custom`,message:`Option translation ids must be unique within a question`});return}n.add(r.translationId)}})),f=e.nullable(e.object({label:e.string().check(e.trim(),e.minLength(1,{error:`Value is required`}),e.maxLength(200)),max:e.number().max(2e3),description:e.optional(e.string().check(e.trim(),e.maxLength(200)))})),p=e.optional(e.boolean()),ne=e.object({type:e.literal(`rating`),buttonLabel:u,shouldAutoProgress:p,scale:e.number().check(e.gte(2),e.lte(10)),labels:e.optional(e.object({lower:e.optional(e.pipe(e.string().check(e.trim(),e.maxLength(100)),e.transform(e=>e===``?void 0:e))),upper:e.optional(e.pipe(e.string().check(e.trim(),e.maxLength(100)),e.transform(e=>e===``?void 0:e)))})),display:e.optional(e.literal([`star`,`emoji`,`number`]))}),re=e.object({type:e.literal(`open-ended`),placeholder:e.optional(e.string().max(200)),buttonLabel:u,max:e.number().max(2e3)}),ie=e.object({type:e.literal(`single-select`),shouldAutoProgress:p,options:d,buttonLabel:u,editable:f}),ae=e.object({type:e.literal(`multi-select`),buttonLabel:u,options:d,editable:f,max:e.optional(e.number()),display:e.optional(e.literal([`checkbox`,`tag`]))}),m=e.object({type:e.literal(`statement`),buttonLabel:u,buttonUrl:e.optional(l)}),h=e.object({type:e.literal(`bug-report`),placeholder:e.optional(e.string().max(200)),buttonLabel:u,enableScreenshot:e.boolean(),enableRecording:e.boolean(),detailsLabel:e.string().check(e.trim(),e.minLength(1,{error:`Label is required`}),e.maxLength(128)),detailsPlaceholder:e.optional(e.string().max(200)),redactClasses:e.optional(e.array(e.string().max(128)).max(100))}),g=e.discriminatedUnion(`type`,[ne,ie,re,ae,m,h]),oe=e=>e.trim()===``?void 0:e,_=t=>e.string().max(t).transform(oe),v=_(50).optional(),se=_(128).optional(),y=e.object({label:_(200).optional(),description:_(200).optional()}),b=e.optional(e.object({label:_(200).optional(),description:_(200).optional()})),ce=e.object({type:e.literal(`rating`),buttonLabel:v,labels:e.optional(e.object({lower:_(100).optional(),upper:_(100).optional()}))}),le=e.object({type:e.literal(`open-ended`),placeholder:_(200).optional(),buttonLabel:v}),ue=e.object({type:e.literal(`single-select`),buttonLabel:v,options:e.optional(e.record(e.string(),y)),editable:b}),de=e.object({type:e.literal(`multi-select`),buttonLabel:v,options:e.optional(e.record(e.string(),y)),editable:b}),fe=e.object({type:e.literal(`statement`),buttonLabel:v}),pe=e.object({type:e.literal(`bug-report`),placeholder:_(200).optional(),buttonLabel:v,detailsLabel:se,detailsPlaceholder:_(200).optional()}),me=e.discriminatedUnion(`type`,[ce,le,ue,de,fe,pe]),x=`__CONFETTI_CHECKBOX_Others`,S=`__CONFETTI_RADIO_Others`,he=e.url({protocol:/^https$/,hostname:/^(?:app\.datadoghq\.(?:com|eu)|(?:app\.)?(?:us3|us5|ap1|ap2|uk1)\.datadoghq\.com|app\.ddog-gov\.com|(?:app\.)?us2\.ddog-gov\.com)$/}).max(2048),ge=e.optional(e.looseObject({userAgent:e.string().check(e.trim(),e.maxLength(1e3)),screenResolution:e.string().check(e.trim(),e.maxLength(100)),viewportSize:e.string().check(e.trim(),e.maxLength(100)),pageUrl:e.string().max(2048),pageTitle:e.string().check(e.trim(),e.maxLength(1e3)),referrer:e.string().max(2048),datadogTraceId:e.optional(e.string().max(128)),datadogSessionId:e.optional(e.string().max(128)),datadogSessionReplayLink:e.catch(e.optional(he),void 0)}).partial().catchall(e.optional(e.string().max(1e3))));e.cuid2().max(200);const C=e.looseObject({type:e.literal([0,1,2,3,4,5,6]),data:e.unknown(),timestamp:e.number(),delay:e.optional(e.number())});e.array(C);const w=e.array(C),T=e.string().max(10485760,{abort:!0}).check(e.refine(e=>{try{return w.safeParse(JSON.parse(e)).success}catch{return!1}},{error:`Invalid recording events`})),E=e.string().max(10485760,{abort:!0}).check(e.regex(/^data:image\/(png|jpeg|jpg|webp|gif);base64,[A-Za-z0-9+/]+=*$/,{error:`Invalid image data URL`})),D=t=>e.object({title:e.string().check(e.trim(),...t?[e.minLength(1,{error:`Title is required`})]:[],e.maxLength(256)),description:e.optional(e.string().check(e.trim(),e.maxLength(4096))),screenshotDataUrl:e.optional(E),recordingEventsJson:e.optional(T),metadata:ge});D(!0);const O=D(!1),k=(e,{required:t})=>D(t),A=e=>{if(!e)return!1;try{let t=JSON.parse(e);return Array.isArray(t)&&t.length>0}catch{return!1}},j=e=>!e.title.trim()&&!e.description?.trim()&&!e.screenshotDataUrl&&!A(e.recordingEventsJson),M=t=>e.preprocess(e=>typeof e==`string`&&/^(10|[1-9])$/.test(e)?Number(e):e,e.number({error:`Please select a rating`}).check(e.int(),e.gte(1),e.lte(t))),N=({scale:t},{required:n})=>{let r=M(t);return n?r:e.optional(r)},P=({maxLength:t},{required:n})=>e.string().check(e.trim(),...n?[e.minLength(1,{error:`This field is required`})]:[],e.maxLength(t??2e3,{error:({maximum:e})=>`Please enter less than ${e} characters`})),F=({options:t,editable:n},r)=>{let i=new Set(t.map(e=>e.value));return e.string({error:`Please select an option`}).check(e.trim(),e.superRefine((e,t)=>{if(i.has(e))return;let a=n?!e||e===r?`Please fill out the free text field`:e.length>n.max?`Please enter less than ${n.max} characters`:void 0:`Please select an option`;a&&t.addIssue({code:`custom`,message:a})}))},I=(t,{required:n})=>{let r=F(t,S);return n?r:e.optional(r)},L=(t,{required:n})=>{let{options:r,editable:i,max:a}=t,o=new Set(r.map(e=>e.value));return e.array(F(t,x)).check(...n?[e.minLength(1,{error:`Please select at least one option`})]:[],e.maxLength(a??r.length+ +!!i,{error:({maximum:e})=>`Please select less than ${e} options`}),e.refine(e=>e.filter(e=>!o.has(e)).length<=1,{error:`Please select an option`}))},_e=()=>e.optional(e.string().max(2048)),ve=(t,n)=>{switch(t.type){case`rating`:return N({scale:t.scale},n);case`open-ended`:return P({maxLength:t.max},n);case`single-select`:return I(t,n);case`multi-select`:return L(t,n);case`statement`:return _e();case`bug-report`:return k({},n);default:return e.never()}},R=[`en`,`zh`,`ms`,`ta`],z=e.enum(R),B=e.cuid2().max(200),ye=e.object({title:e.string().check(e.trim(),e.maxLength(500)),description:e.string().check(e.trim(),e.maxLength(1e3)),buttonText:e.string().check(e.trim(),e.maxLength(100))}),V=e.object({id:e.string(),title:e.string(),description:e.nullable(e.string()),position:e.number(),required:e.boolean(),properties:g,routingLogic:ee}),be=e.object({title:_(200).optional(),description:_(1e3).optional(),backButtonLabel:v,confirmation:e.optional(e.object({title:_(500).optional(),description:_(1e3).optional(),buttonText:_(100).optional()}))});e.partialRecord(z,be);const xe=e.object({title:_(500).optional(),description:_(1e3).optional(),properties:e.optional(me)});e.partialRecord(z,xe);const Se=e.object({title:e.string(),description:e.nullable(e.string()),questions:e.array(V),confirmation:ye,isBackNavigationAllowed:e.boolean(),backButtonLabel:e.nullable(e.string().check(e.trim(),e.maxLength(50)))});e.object({locale:e.optional(z)}),e.object({cursor:e.optional(e.string().check(e.minLength(1),e.maxLength(100))),limit:e.optional(e.number().check(e.int(),e.gte(1),e.lte(100)))});const H=e.object({id:e.string(),title:e.string(),description:e.nullable(e.string()),status:e.enum([`active`,`inactive`]),createdAt:e.date(),updatedAt:e.date()});e.object({data:e.array(H),nextCursor:e.nullable(e.string()),limit:e.number(),links:e.object({self:e.string(),next:e.nullable(e.string())})}),e.object({surveyId:B});const Ce=V;e.object({data:e.object({...H.shape,questions:e.array(Ce)})}),e.object({surveyId:B,responseId:e.union([e.cuid2().max(200),e.uuid()])});const we=e.catch(e.object({type:e.enum([`embedded`,`popover`,`modal`]),version:e.string().check(e.trim(),e.minLength(1),e.maxLength(50)),build:e.string().check(e.trim(),e.minLength(1),e.maxLength(50))}).partial(),{}),U=e.record(e.string().trim().min(1).max(200),e.union([e.string().check(e.trim(),e.maxLength(2e3)),e.number(),e.array(e.string().check(e.trim(),e.maxLength(2e3))).check(e.maxLength(1024)),O])),W=1e3,G=e.string().check(e.trim(),e.maxLength(W)),Te=e.record(G,G),K=e.string().trim().min(1).max(W),q=e.discriminatedUnion(`code`,[e.object({code:e.literal(`metadata_value_truncated`),key:K}).strict(),e.object({code:e.literal(`metadata_value_invalid`),key:K}).strict(),e.object({code:e.literal(`metadata_key_invalid`),position:e.number().int().positive().max(2**53-1)}).strict(),e.object({code:e.literal(`metadata_key_duplicate`),key:K}).strict(),e.object({code:e.literal(`metadata_entry_limit`),droppedCount:e.number().int().positive().max(2**53-1)}).strict(),e.object({code:e.literal(`metadata_container_invalid`)}).strict(),e.object({code:e.literal(`metadata_warning_details_omitted`),count:e.number().int().positive().max(2**53-1)}).strict(),e.object({code:e.literal(`metadata_warning_report_invalid`)}).strict()]),Ee=e.object({metadata:e.array(q).min(1).max(20)}).strict(),De=e.object({metadata:e.array(q).min(1)}).strict(),J=(e,t)=>Math.min(2**53-1,e+t),Y=e=>{let t=[],n=0;for(let r of e)r.code===`metadata_warning_details_omitted`?n=J(n,r.count):t.push(r);let r=n>0||t.length>20?19:20,i=t.slice(0,r);return n=J(n,t.length-i.length),n>0?[...i,{code:`metadata_warning_details_omitted`,count:n}]:i},Oe=e=>{let t=Y(e);return t.length>0?{metadata:t}:void 0},ke=e=>{if(e===void 0)return[];let t=De.safeParse(e);return t.success?Y(t.data.metadata):[{code:`metadata_warning_report_invalid`}]},Ae=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Reflect.getPrototypeOf(e);return t===Object.prototype||t===null},je=e=>{if(e===void 0)return{metadata:{},warnings:[]};if(!Ae(e))return{metadata:{},warnings:[{code:`metadata_container_invalid`}]};let t=new Map,n=[],r=0;for(let[i,[a,o]]of Object.entries(e).entries()){let e=a.trim();if(e.length===0||e.length>1e3){n.push({code:`metadata_key_invalid`,position:i+1});continue}if(typeof o!=`string`){n.push({code:`metadata_value_invalid`,key:e});continue}if(t.has(e)){n.push({code:`metadata_key_duplicate`,key:e});continue}if(t.size>=20){r+=1;continue}let s=o.trim(),c=s.length>1e3?`${s.slice(0,W-11)}[truncated]`:s;c!==s&&n.push({code:`metadata_value_truncated`,key:e}),t.set(e,c)}return r>0&&n.push({code:`metadata_entry_limit`,droppedCount:r}),{metadata:Object.fromEntries(t),warnings:Y(n)}},X=({metadata:e,warnings:t})=>{let n=je(e);return{metadata:n.metadata,warnings:Oe([...n.warnings,...ke(t)])}};Te.check(e.refine(e=>Object.keys(e).length<=20,`At most 20 metadata entries are allowed.`)),e.object({respondent:e.string().check(e.trim(),e.minLength(1),e.maxLength(200)),data:U,metadata:e.unknown().optional(),warnings:e.unknown().optional(),telemetry:e.optional(we)}).transform(e=>{let{metadata:t,warnings:n,...r}=e,{metadata:i,warnings:a}=X({metadata:t,warnings:n});return{...r,metadata:i,...a&&{warnings:a}}});const Me=e.object({id:e.string(),createdAt:e.date(),warnings:e.optional(Ee)});e.object({surveyId:B,respondent:e.string().check(e.trim(),e.minLength(1),e.maxLength(200))}),e.object({surveyId:B,respondent:e.string().check(e.trim(),e.minLength(1),e.maxLength(200))}),e.object({surveyId:B});const Z=e.object({lastRespondedAt:e.nullable(e.union([e.iso.datetime(),e.date()])),lastViewedAt:e.nullable(e.union([e.iso.datetime(),e.date()])),lastDismissedAt:e.nullable(e.union([e.iso.datetime(),e.date()]))});e.object({type:e.enum([`view`,`dismiss`])}),e.object({}),e.object({surveyId:B}),e.object({respondent:e.optional(e.string().check(e.trim(),e.minLength(1),e.maxLength(200))),after:e.optional(e.iso.datetime({offset:!0,local:!0})),before:e.optional(e.iso.datetime({offset:!0,local:!0})),cursor:e.optional(e.string().check(e.minLength(1),e.maxLength(100))),limit:e.optional(e.number().check(e.int(),e.gte(1),e.lte(100)))});const Ne=e.object({id:e.string(),respondent:e.string(),data:U,clientMetadata:e.record(e.string(),e.string()),createdAt:e.date()});e.object({data:e.array(Ne),nextCursor:e.nullable(e.string()),limit:e.number(),links:e.object({self:e.string(),next:e.nullable(e.string())})});const Q=e.number().check(e.int(),e.gte(0));e.object({data:e.object({totalViews:Q,uniqueViewers:Q,totalDismissals:Q,uniqueDismissers:Q,totalResponses:Q,uniqueResponders:Q})}),e.object({questionIds:e.array(e.string().max(200)).check(e.minLength(1)),timeRange:e.union([e.enum([`last-7-days`,`last-30-days`]),e.string().check(e.regex(/^q[1-4]-\d{4}$/)),e.string().check(e.regex(/^custom_\d{4}-\d{2}-\d{2}_\d{4}-\d{2}-\d{2}$/))])});const $=e.record(e.string(),e.record(e.string(),e.number()));e.object({data:e.object({current:$,previousQuarter:e.nullable($)})});export{R as a,x as c,Se as i,S as l,Me as n,ve as o,X as r,j as s,Z as t,l as u};
package/build/static.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { r as Locale, t as PublicPutResponseOutput } from "./index-DLqC_qk3.js";
2
- import { A as WithProxyable, D as OptionallyDismissable, S as ConfettiContainer, T as Dismissable, d as RespondentVisibilityProviderProps, f as WithVisibilityControl, t as BaseConfettiProps, w as Containable, x as Closable } from "./Confetti-Ch8bCyn_.js";
1
+ import { r as Locale, t as PublicPutResponseOutput } from "./index-C6cGD5WB.js";
2
+ import { A as WithProxyable, D as OptionallyDismissable, S as ConfettiContainer, T as Dismissable, d as RespondentVisibilityProviderProps, f as WithVisibilityControl, t as BaseConfettiProps, w as Containable, x as Closable } from "./Confetti-DSoOgKU5.js";
3
3
 
4
4
  //#region src/templates/EmbeddedConfettiContent.d.ts
5
5
  interface EmbeddedConfettiContentProps extends Omit<BaseConfettiProps, 'isSurveyVisible'>, Closable {
package/build/static.js CHANGED
@@ -1 +1 @@
1
- import{t as e}from"./DefaultConfettiTrigger-qiD0c65-.js";import{f as t,m as n,t as r}from"./ModalContainer-DlskMgoM.js";import{a as i,d as a,h as o,i as s,m as c,n as l,p as u,r as d,t as f}from"./Embed-B37tSunS.js";import{useState as p}from"react";import{ErrorBoundary as m}from"react-error-boundary";import{Fragment as h,jsx as g,jsxs as _}from"react/jsx-runtime";const v=({onClose:e,locale:r,...a})=>g(m,{fallback:g(h,{}),children:g(n,{type:`embedded`,children:g(t,{...a,locale:r,children:g(o,{...a,shouldAutoSubmit:!1,locale:r,children:({questions:t,update:n,submit:o,isSubmitted:c,errors:l,answers:u})=>c?g(s,{onClose:e,locale:r}):g(f,{onSubmit:o,locale:r,children:t.filter(({visible:e})=>!!e).map(e=>g(i,{question:e,defaultAnswer:u[e.id]??void 0,error:l[e.id]||``,maskAllInputs:a.options?.bugReport?.maskAllInputs,locale:r,onChange:t=>n({question:e.position,answer:t})},e.id))})})})})}),y=e=>{let{respondent:t}=c();return g(v,{...e,respondent:t})};function b(e){let[t,n]=p(!1),{respondent:r,isSurveyVisible:i,proxyUrl:a,container:o,...s}=e;if(t)return null;let c=g(y,{...s,apiBaseUrl:a,onClose:()=>{n(!0),s.onClose?.()}});return g(u,{surveyId:s.surveyId,publishableKey:s.publishableKey,apiBaseUrl:a,respondent:r,isSurveyVisible:i,children:o?o({survey:c}):c})}const x=({onDismiss:e,onClose:a,onFinished:c,closeOnFinishMs:l,isDismissable:u,locale:d,...p})=>g(m,{fallback:g(h,{}),children:g(n,{type:`modal`,children:g(t,{...p,locale:d,children:g(r,{onDismiss:e,onClose:a,closeOnFinishMs:l,isDismissable:u,locale:d,children:({setIsSubmitted:e,setIsFinished:t})=>g(o,{...p,shouldAutoSubmit:!1,locale:d,onSubmitted:()=>e(),onFinished:e=>{t(),c?.(e)},children:({questions:e,update:t,errors:n,submit:r,isSubmitted:o,answers:c})=>o?g(s,{onClose:a,locale:d}):g(f,{onSubmit:r,locale:d,children:e.filter(({visible:e})=>!!e).map(e=>g(i,{question:e,defaultAnswer:c[e.id]??void 0,error:n[e.id]||``,maskAllInputs:p.options?.bugReport?.maskAllInputs,locale:d,onChange:n=>t({question:e.position,answer:n})},e.id))})})})})})}),S=e=>{let{respondent:t}=c();return g(x,{...e,respondent:t})};function C(e){let[t,n]=p(!1),{respondent:r,isSurveyVisible:i,proxyUrl:a,...o}=e;return t?null:g(u,{surveyId:o.surveyId,publishableKey:o.publishableKey,apiBaseUrl:a,respondent:r,isSurveyVisible:i,children:g(S,{...o,apiBaseUrl:a,onClose:()=>{n(!0),o.onClose?.()}})})}const w=({onDismiss:e,onClose:r,onFinished:c,closeOnFinishMs:u,locale:f,...p})=>g(m,{fallback:g(h,{}),children:g(n,{type:`popover`,children:g(t,{...p,locale:f,children:g(a,{onDismiss:e,onClose:r,closeOnFinishMs:u,locale:f,children:({setIsSubmitted:e,setIsFinished:t})=>g(o,{...p,shouldAutoSubmit:!0,locale:f,onSubmitted:()=>e(),onFinished:e=>{t(),c?.(e)},children:({current:e,questions:t,answers:n,update:a,back:o,canGoBack:c,backButtonLabel:u,saveAnswer:m,isSubmitted:_})=>{let v=e===t.length-1;if(_)return g(s,{onClose:r,locale:f});let y=t[e];return y?g(l,{isLastQuestion:v,question:y,defaultAnswer:n[y.id]??void 0,backButton:c?g(d,{onPress:o,locale:f,children:u}):void 0,locale:f,saveAnswer:e=>m(y.id,e),onSubmit:t=>a({question:e,answer:t}),children:e=>g(i,{maskAllInputs:p.options?.bugReport?.maskAllInputs,locale:f,...e})},y.id):g(h,{})}})})})})}),T=e=>{let{respondent:t}=c();return g(w,{...e,respondent:t})};function E(e){let[t,n]=p(!1),{respondent:r,isSurveyVisible:i,proxyUrl:a,...o}=e;return t?null:g(u,{surveyId:o.surveyId,publishableKey:o.publishableKey,apiBaseUrl:a,respondent:r,isSurveyVisible:i,children:g(T,{...o,apiBaseUrl:a,onClose:()=>{n(!0),o.onClose?.()}})})}const D=({onClose:e,locale:n,...r})=>g(m,{fallback:g(h,{}),children:g(t,{...r,locale:n,children:g(o,{...r,shouldAutoSubmit:!0,locale:n,children:({current:t,questions:a,answers:o,update:c,back:u,canGoBack:f,backButtonLabel:p,saveAnswer:m,isSubmitted:_})=>{let v=t===a.length-1;if(_)return g(s,{onClose:e,locale:n});let y=a[t];return y?g(l,{isLastQuestion:v,question:y,defaultAnswer:o[y.id]??void 0,backButton:f?g(d,{onPress:u,locale:n,children:p}):void 0,locale:n,saveAnswer:e=>m(y.id,e),onSubmit:e=>c({question:t,answer:e}),children:e=>g(i,{maskAllInputs:r.options?.bugReport?.maskAllInputs,locale:n,...e})},y.id):g(h,{})}})})}),O=e=>{let{respondent:t}=c();return g(D,{...e,respondent:t})};function k(e){let[t,n]=p(!1),{respondent:r,isSurveyVisible:i,proxyUrl:a,container:o,...s}=e;if(t)return null;let c=g(O,{...s,apiBaseUrl:a,onClose:()=>{n(!0),s.onClose?.()}});return g(u,{surveyId:s.surveyId,publishableKey:s.publishableKey,apiBaseUrl:a,respondent:r,isSurveyVisible:i,children:o?o({survey:c}):c})}const A=({trigger:e,children:t,onFinished:n,...r})=>{let[i,a]=p(!1),[o,s]=p(!1);return _(h,{children:[e({onClick:()=>a(!0),isWidgetOpen:i,hasSubmitted:o}),i&&t({...r,onDismiss:()=>a(!1),onFinished:e=>{s(!0),n?.(e)},onClose:()=>a(!1)})]})},j=({trigger:t=t=>g(e,{...t}),children:n,metadata:r,autoInjectAnalyticsMetadata:i,options:a,onFinished:o,proxyUrl:s,...c})=>g(m,{fallback:g(h,{}),children:g(u,{...c,apiBaseUrl:s,children:g(A,{trigger:t,surveyId:c.surveyId,publishableKey:c.publishableKey,proxyUrl:s,metadata:r,autoInjectAnalyticsMetadata:i,options:a,onFinished:o,children:n})})});export{j as ConfettiTrigger,b as EmbeddedConfetti,C as ModalConfetti,E as PopoverConfetti,k as StepperConfetti};
1
+ import{t as e}from"./DefaultConfettiTrigger-B0_iX1RM.js";import{f as t,m as n,t as r}from"./ModalContainer-DcF9hn27.js";import{a as i,d as a,h as o,i as s,m as c,n as l,p as u,r as d,t as f}from"./Embed-BJcGr0sB.js";import{useState as p}from"react";import{ErrorBoundary as m}from"react-error-boundary";import{Fragment as h,jsx as g,jsxs as _}from"react/jsx-runtime";const v=({onClose:e,locale:r,...a})=>g(m,{fallback:g(h,{}),children:g(n,{type:`embedded`,children:g(t,{...a,locale:r,children:g(o,{...a,shouldAutoSubmit:!1,locale:r,children:({questions:t,update:n,submit:o,isSubmitted:c,errors:l,answers:u})=>c?g(s,{onClose:e,locale:r}):g(f,{onSubmit:o,locale:r,children:t.filter(({visible:e})=>!!e).map(e=>g(i,{question:e,defaultAnswer:u[e.id]??void 0,error:l[e.id]||``,maskAllInputs:a.options?.bugReport?.maskAllInputs,locale:r,onChange:t=>n({question:e.position,answer:t})},e.id))})})})})}),y=e=>{let{respondent:t}=c();return g(v,{...e,respondent:t})};function b(e){let[t,n]=p(!1),{respondent:r,isSurveyVisible:i,proxyUrl:a,container:o,...s}=e;if(t)return null;let c=g(y,{...s,apiBaseUrl:a,onClose:()=>{n(!0),s.onClose?.()}});return g(u,{surveyId:s.surveyId,publishableKey:s.publishableKey,apiBaseUrl:a,respondent:r,isSurveyVisible:i,children:o?o({survey:c}):c})}const x=({onDismiss:e,onClose:a,onFinished:c,closeOnFinishMs:l,isDismissable:u,locale:d,...p})=>g(m,{fallback:g(h,{}),children:g(n,{type:`modal`,children:g(t,{...p,locale:d,children:g(r,{onDismiss:e,onClose:a,closeOnFinishMs:l,isDismissable:u,locale:d,children:({setIsSubmitted:e,setIsFinished:t})=>g(o,{...p,shouldAutoSubmit:!1,locale:d,onSubmitted:()=>e(),onFinished:e=>{t(),c?.(e)},children:({questions:e,update:t,errors:n,submit:r,isSubmitted:o,answers:c})=>o?g(s,{onClose:a,locale:d}):g(f,{onSubmit:r,locale:d,children:e.filter(({visible:e})=>!!e).map(e=>g(i,{question:e,defaultAnswer:c[e.id]??void 0,error:n[e.id]||``,maskAllInputs:p.options?.bugReport?.maskAllInputs,locale:d,onChange:n=>t({question:e.position,answer:n})},e.id))})})})})})}),S=e=>{let{respondent:t}=c();return g(x,{...e,respondent:t})};function C(e){let[t,n]=p(!1),{respondent:r,isSurveyVisible:i,proxyUrl:a,...o}=e;return t?null:g(u,{surveyId:o.surveyId,publishableKey:o.publishableKey,apiBaseUrl:a,respondent:r,isSurveyVisible:i,children:g(S,{...o,apiBaseUrl:a,onClose:()=>{n(!0),o.onClose?.()}})})}const w=({onDismiss:e,onClose:r,onFinished:c,closeOnFinishMs:u,locale:f,...p})=>g(m,{fallback:g(h,{}),children:g(n,{type:`popover`,children:g(t,{...p,locale:f,children:g(a,{onDismiss:e,onClose:r,closeOnFinishMs:u,locale:f,children:({setIsSubmitted:e,setIsFinished:t})=>g(o,{...p,shouldAutoSubmit:!0,locale:f,onSubmitted:()=>e(),onFinished:e=>{t(),c?.(e)},children:({current:e,questions:t,answers:n,update:a,back:o,canGoBack:c,backButtonLabel:u,saveAnswer:m,isSubmitted:_})=>{let v=e===t.length-1;if(_)return g(s,{onClose:r,locale:f});let y=t[e];return y?g(l,{isLastQuestion:v,question:y,defaultAnswer:n[y.id]??void 0,backButton:c?g(d,{onPress:o,locale:f,children:u}):void 0,locale:f,saveAnswer:e=>m(y.id,e),onSubmit:t=>a({question:e,answer:t}),children:e=>g(i,{maskAllInputs:p.options?.bugReport?.maskAllInputs,locale:f,...e})},y.id):g(h,{})}})})})})}),T=e=>{let{respondent:t}=c();return g(w,{...e,respondent:t})};function E(e){let[t,n]=p(!1),{respondent:r,isSurveyVisible:i,proxyUrl:a,...o}=e;return t?null:g(u,{surveyId:o.surveyId,publishableKey:o.publishableKey,apiBaseUrl:a,respondent:r,isSurveyVisible:i,children:g(T,{...o,apiBaseUrl:a,onClose:()=>{n(!0),o.onClose?.()}})})}const D=({onClose:e,locale:n,...r})=>g(m,{fallback:g(h,{}),children:g(t,{...r,locale:n,children:g(o,{...r,shouldAutoSubmit:!0,locale:n,children:({current:t,questions:a,answers:o,update:c,back:u,canGoBack:f,backButtonLabel:p,saveAnswer:m,isSubmitted:_})=>{let v=t===a.length-1;if(_)return g(s,{onClose:e,locale:n});let y=a[t];return y?g(l,{isLastQuestion:v,question:y,defaultAnswer:o[y.id]??void 0,backButton:f?g(d,{onPress:u,locale:n,children:p}):void 0,locale:n,saveAnswer:e=>m(y.id,e),onSubmit:e=>c({question:t,answer:e}),children:e=>g(i,{maskAllInputs:r.options?.bugReport?.maskAllInputs,locale:n,...e})},y.id):g(h,{})}})})}),O=e=>{let{respondent:t}=c();return g(D,{...e,respondent:t})};function k(e){let[t,n]=p(!1),{respondent:r,isSurveyVisible:i,proxyUrl:a,container:o,...s}=e;if(t)return null;let c=g(O,{...s,apiBaseUrl:a,onClose:()=>{n(!0),s.onClose?.()}});return g(u,{surveyId:s.surveyId,publishableKey:s.publishableKey,apiBaseUrl:a,respondent:r,isSurveyVisible:i,children:o?o({survey:c}):c})}const A=({trigger:e,children:t,onFinished:n,...r})=>{let[i,a]=p(!1),[o,s]=p(!1);return _(h,{children:[e({onClick:()=>a(!0),isWidgetOpen:i,hasSubmitted:o}),i&&t({...r,onDismiss:()=>a(!1),onFinished:e=>{s(!0),n?.(e)},onClose:()=>a(!1)})]})},j=({trigger:t=t=>g(e,{...t}),children:n,metadata:r,autoInjectAnalyticsMetadata:i,options:a,onFinished:o,proxyUrl:s,...c})=>g(m,{fallback:g(h,{}),children:g(u,{...c,apiBaseUrl:s,children:g(A,{trigger:t,surveyId:c.surveyId,publishableKey:c.publishableKey,proxyUrl:s,metadata:r,autoInjectAnalyticsMetadata:i,options:a,onFinished:o,children:n})})});export{j as ConfettiTrigger,b as EmbeddedConfetti,C as ModalConfetti,E as PopoverConfetti,k as StepperConfetti};
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@opengovsg/confetti",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "sideEffects": false,
5
5
  "description": "Widgets for Confetti",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
7
7
  "type": "module",
8
- "repository": "https://github.com/opengovsg/confetti",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/opengovsg/confetti"
11
+ },
9
12
  "homepage": "https://github.com/opengovsg/confetti",
10
13
  "main": "./build/index.js",
11
14
  "types": "./build/index.d.ts",
@@ -79,6 +82,9 @@
79
82
  "react-dom": "^18.2.0 || ^19.0.0"
80
83
  },
81
84
  "devDependencies": {
85
+ "@confetti/common": "0.0.0",
86
+ "@confetti/tsconfig": "0.0.0",
87
+ "@confetti/validators": "0.0.0",
82
88
  "@csstools/postcss-minify": "^3.0.0",
83
89
  "@rrweb/types": "2.0.0-alpha.20",
84
90
  "@types/node": "24.10.8",
@@ -92,10 +98,7 @@
92
98
  "postcss-preset-env": "^11.5.2",
93
99
  "react-aria-components": "1.21.1",
94
100
  "tsdown": "0.22.1",
95
- "typescript": "^7.0.2",
96
- "@confetti/common": "0.0.0",
97
- "@confetti/validators": "0.0.0",
98
- "@confetti/tsconfig": "0.0.0"
101
+ "typescript": "^7.0.2"
99
102
  },
100
103
  "scripts": {
101
104
  "build:css": "postcss ./src/confetti.css -o ./build/confetti.css",
@@ -1,7 +0,0 @@
1
- import e,{createContext as t,forwardRef as n,useCallback as r,useContext as i,useEffect as a,useMemo as o,useRef as s,useState as c}from"react";import l from"ky";import u from"clsx";import"react-dom";const d=l.create({prefixUrl:`https://confetti.gov.sg`,retry:{limit:3,methods:[`get`,`head`]},timeout:6e4});function f({publishableKey:e,apiBaseUrl:t}){return o(()=>{let n={headers:{"x-cfti-pk":e}};return t&&(n.prefixUrl=t),d.extend(n)},[t,e])}function p(...e){return(...t)=>{for(let n of e)typeof n==`function`&&n(...t)}}const m=typeof document<`u`?e.useLayoutEffect:()=>{},h={prefix:String(Math.round(Math.random()*1e10)),current:0},g=e.createContext(h),_=e.createContext(!1);typeof window<`u`&&window.document&&window.document.createElement;let v=new WeakMap;function y(t=!1){let n=i(g),r=s(null);if(r.current===null&&!t){let t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentOwner?.current;if(t){let e=v.get(t);e==null?v.set(t,{id:n.current,state:t.memoizedState}):t.memoizedState!==e.state&&(n.current=e.id,v.delete(t))}r.current=++n.current}return r.current}function b(e){let t=i(g),n=y(!!e),r=`react-aria${t.prefix}`;return e||`${r}-${n}`}function ee(t){let n=e.useId(),[r]=c(T()),i=r?`react-aria`:`react-aria${h.prefix}`;return t||`${i}-${n}`}const x=typeof e.useId==`function`?ee:b;function S(){return!1}function C(){return!0}function w(e){return()=>{}}function T(){return typeof e.useSyncExternalStore==`function`?e.useSyncExternalStore(w,S,C):i(_)}function E(e){let[t,n]=c(e),i=s(t),a=s(null),o=s(()=>{if(!a.current)return;let e=a.current.next();if(e.done){a.current=null;return}i.current===e.value?o.current():n(e.value)});return m(()=>{i.current=t,a.current&&o.current()}),[t,r(e=>{a.current=e(i.current),o.current()},[o])]}let D=!!(typeof window<`u`&&window.document&&window.document.createElement),O=new Map,k;typeof FinalizationRegistry<`u`&&(k=new FinalizationRegistry(e=>{O.delete(e)}));let A=new WeakMap;function j(e){let[t,n]=c(e),r=s(null),i=x(t),o=s(null),l=A.get(o);if(k&&l!==i&&(l!=null&&k.unregister(o),k.register(o,i,o),A.set(o,i)),D){let e=O.get(i);e&&!e.includes(r)?e.push(r):O.set(i,[r])}return m(()=>{let e=i;return()=>{k&&(k.unregister(o),A.delete(o)),O.delete(e)}},[i]),a(()=>{let e=r.current;return e&&n(e),()=>{e&&(r.current=null)}}),i}function te(e,t){if(e===t)return e;let n=O.get(e);if(n)return n.forEach(e=>e.current=t),t;let r=O.get(t);return r?(r.forEach(t=>t.current=e),e):t}function ne(e=[]){let t=j(),[n,i]=E(t),a=r(()=>{i(function*(){yield t,yield document.getElementById(t)?t:void 0})},[t,i]);return m(a,[t,a,...e]),n}function M(...e){return e.length===1&&e[0]?e[0]:t=>{let n=!1,r=e.map(e=>{let r=re(e,t);return n||=typeof r==`function`,r});if(n)return()=>{r.forEach((t,n)=>{typeof t==`function`?t():re(e[n],null)})}}}function re(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}function N(...e){let t={...e[0]};for(let n=1;n<e.length;n++){let r=e[n];for(let e in r){let n=t[e],i=r[e];typeof n==`function`&&typeof i==`function`&&e[0]===`o`&&e[1]===`n`&&e.charCodeAt(2)>=65&&e.charCodeAt(2)<=90?t[e]=p(n,i):(e===`className`||e===`UNSAFE_className`)&&typeof n==`string`&&typeof i==`string`?t[e]=u(n,i):e===`id`&&n&&i?t.id=te(n,i):e===`ref`&&n&&i?t.ref=M(n,i):t[e]=i===void 0?n:i}}return t}function ie(e){let t=s(null),n=s(void 0),i=r(t=>{if(typeof e==`function`){let n=e,r=n(t);return()=>{typeof r==`function`?r():n(null)}}else if(e)return e.current=t,()=>{e.current=null}},[e]);return o(()=>({get current(){return t.current},set current(e){t.current=e,n.current&&=(n.current(),void 0),e!=null&&(n.current=i(e))}}),[i])}const ae=Symbol(`default`);function oe({values:t,children:n}){for(let[r,i]of t)n=e.createElement(r.Provider,{value:i},n);return n}function se(e){let{className:t,style:n,children:r,defaultClassName:i,defaultChildren:a,defaultStyle:s,values:c,render:l}=e;return o(()=>{let e,o,u;return e=typeof t==`function`?t({...c,defaultClassName:i}):t,o=typeof n==`function`?n({...c,defaultStyle:s||{}}):n,u=typeof r==`function`?r({...c,defaultChildren:a}):r??a,{className:e??i,style:o||s?{...s,...o}:void 0,children:u??a,"data-rac":``,render:l?e=>l(e,c):void 0}},[t,n,r,i,a,s,c,l])}function ce(e,t){return n=>t(typeof e==`function`?e(n):e,n)}function le(e,t){let n=i(e);if(t===null)return null;if(n&&typeof n==`object`&&`slots`in n&&n.slots){let e=t||ae;if(!n.slots[e]){let e=new Intl.ListFormat().format(Object.keys(n.slots).map(e=>`"${e}"`)),r=t?`Invalid slot "${t}".`:`A slot prop is required.`;throw Error(`${r} Valid slot names are ${e}.`)}return n.slots[e]}return n}function ue(e,t,n){let{ref:r,...i}=le(n,e.slot)||{},a=ie(o(()=>M(t,r),[t,r])),s=N(i,e);return`style`in i&&i.style&&`style`in e&&e.style&&(typeof i.style==`function`||typeof e.style==`function`?s.style=t=>{let n=typeof i.style==`function`?i.style(t):i.style,r={...t.defaultStyle,...n},a=typeof e.style==`function`?e.style({...t,defaultStyle:r}):e.style;return{...r,...a}}:s.style={...i.style,...e.style}),[s,a]}function de(e=!0){let[t,n]=c(e),i=s(!1),a=r(e=>{i.current=!0,n(!!e)},[]);return m(()=>{i.current||n(!1)},[]),[a,t]}function fe(e){let t=/^(data-.*)$/,n={};for(let r in e)t.test(r)||(n[r]=e[r]);return n}function pe(t,n,r){let{render:i,...a}=n,c=s(null),l=o(()=>M(r,c),[r,c]);m(()=>{},[t,i]);let u={...a,ref:l};return i?i(u,void 0):e.createElement(t,u)}const me={},he=new Proxy({},{get(e,t){if(typeof t!=`string`)return;let r=me[t];return r||(r=n(pe.bind(null,t)),me[t]=r),r}}),P=e=>_e(e)?e.document:ve(e)?e:e?.ownerDocument??(typeof document<`u`?document:void 0),F=e=>P(e)?.defaultView??(typeof window<`u`?window:void 0);function ge(e){return typeof e==`object`&&!!e&&`nodeType`in e&&typeof e.nodeType==`number`}function _e(e){return typeof e==`object`&&!!e&&`window`in e&&e.window===e}function ve(e){return ge(e)&&e.nodeType===9}function ye(e){return ge(e)&&e.nodeType===11&&`host`in e}function be(e,t,n,r){if(n==null||e==null)return()=>{};let i=Array.isArray(e)?e:[e];for(let e of i)e.addEventListener(t,n,r);return()=>{for(let e of i)e.removeEventListener(t,n,r)}}function xe(e,t,n,r){if(e==null)return()=>{};let i=[],a=Array.isArray(e)?e:[e];for(let e of a){let a=e.style.getPropertyValue(t),o=e.style.getPropertyPriority(t);e.style.setProperty(t,n,r),i.unshift(()=>{a?e.style.setProperty(t,a,o):e.style.removeProperty(t)})}return()=>{for(let e of i)e()}}function Se(){return!1}function I(e,t){if(!Se())return t&&e?e.contains(t):!1;if(!e||!t)return!1;let n=t;for(;n!==null;){if(n===e)return!0;n=typeof n.assignedElements!=`function`&&n.assignedSlot?.parentNode?n.assignedSlot.parentNode:ye(n)?n.host:n.parentNode}return!1}const L=(e=document)=>{if(!Se())return e.activeElement;let t=e.activeElement;for(;t&&`shadowRoot`in t&&t.shadowRoot?.activeElement;)t=t.shadowRoot.activeElement;return t};function R(e){if(Se()&&e.target instanceof Element&&e.target.shadowRoot){if(`composedPath`in e)return e.composedPath()[0]??null;if(`composedPath`in e.nativeEvent)return e.nativeEvent.composedPath()[0]??null}return e.target}function Ce(e){if(!e)return!1;let t=e.getRootNode(),n=F(e);if(!(t instanceof n.Document||t instanceof n.ShadowRoot))return!1;let r=t.activeElement;return r!=null&&e.contains(r)}function z(e){if(Te())e.focus({preventScroll:!0});else{let t=Ee(e);e.focus(),De(t)}}let we=null;function Te(){if(we==null){we=!1;try{document.createElement(`div`).focus({get preventScroll(){return we=!0,!0}})}catch{}}return we}function Ee(e){let t=e.parentNode,n=[],r=document.scrollingElement||document.documentElement;for(;t instanceof HTMLElement&&t!==r;)(t.offsetHeight<t.scrollHeight||t.offsetWidth<t.scrollWidth)&&n.push({element:t,scrollTop:t.scrollTop,scrollLeft:t.scrollLeft}),t=t.parentNode;return r instanceof HTMLElement&&n.push({element:r,scrollTop:r.scrollTop,scrollLeft:r.scrollLeft}),n}function De(e){for(let{element:t,scrollTop:n,scrollLeft:r}of e)t.scrollTop=n,t.scrollLeft=r}const Oe=typeof Element<`u`&&`checkVisibility`in Element.prototype;function ke(e){let t=F(e);if(!(e instanceof t.HTMLElement)&&!(e instanceof t.SVGElement))return!1;let{display:n,visibility:r}=e.style,i=n!==`none`&&r!==`hidden`&&r!==`collapse`;if(i){let{getComputedStyle:t}=F(e),{display:n,visibility:r}=t(e);i=n!==`none`&&r!==`hidden`&&r!==`collapse`}return i}function Ae(e,t){return!e.hasAttribute(`hidden`)&&!e.hasAttribute(`data-react-aria-prevent-focus`)&&(e.nodeName===`DETAILS`&&t&&t.nodeName!==`SUMMARY`?e.hasAttribute(`open`):!0)}function je(e,t){return Oe?e.checkVisibility({visibilityProperty:!0})&&!e.closest(`[data-react-aria-prevent-focus]`):e.nodeName!==`#comment`&&ke(e)&&Ae(e,t)&&(!e.parentElement||je(e.parentElement,e))}const Me=[`input:not([disabled]):not([type=hidden])`,`select:not([disabled])`,`textarea:not([disabled])`,`button:not([disabled])`,`a[href]`,`area[href]`,`summary`,`iframe`,`object`,`embed`,`audio[controls]`,`video[controls]`,`[contenteditable]:not([contenteditable^="false"])`,`permission`],Ne=Me.join(`:not([hidden]),`)+`,[tabindex]:not([disabled]):not([hidden])`;Me.push(`[tabindex]:not([tabindex="-1"]):not([disabled])`);const Pe=Me.join(`:not([hidden]):not([tabindex="-1"]),`);function Fe(e,t){return e.matches(Ne)&&!Le(e)&&(t?.skipVisibilityCheck||je(e))}function Ie(e){return e.matches(Pe)&&je(e)&&!Le(e)}function Le(e){let t=e;for(;t!=null;){if(t instanceof F(t).HTMLElement&&t.inert)return!0;t=t.parentElement}return!1}function Re(e){let t=e;return t.nativeEvent=e,t.isDefaultPrevented=()=>t.defaultPrevented,t.isPropagationStopped=()=>t.cancelBubble,t.persist=()=>{},t}function ze(e,t){Object.defineProperty(e,"target",{value:t}),Object.defineProperty(e,"currentTarget",{value:t})}function Be(e){let t=s({isFocused:!1,observer:null});return m(()=>{let e=t.current;return()=>{e.observer&&=(e.observer.disconnect(),null)}},[]),r(n=>{let r=R(n);if(r instanceof HTMLButtonElement||r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement||r instanceof HTMLSelectElement){t.current.isFocused=!0;let n=r;n.addEventListener(`focusout`,r=>{if(t.current.isFocused=!1,n.disabled){let t=Re(r);e?.(t)}t.current.observer&&(t.current.observer.disconnect(),t.current.observer=null)},{once:!0}),t.current.observer=new MutationObserver(()=>{if(t.current.isFocused&&n.disabled){t.current.observer?.disconnect();let e=n===L()?null:L();n.dispatchEvent(new FocusEvent(`blur`,{relatedTarget:e})),n.dispatchEvent(new FocusEvent(`focusout`,{bubbles:!0,relatedTarget:e}))}}),t.current.observer.observe(n,{attributes:!0,attributeFilter:[`disabled`]})}},[e])}let B=!1;function Ve(e){for(;e&&!Fe(e,{skipVisibilityCheck:!0});)e=e.parentElement;let t=L(F(e).document);if(!t||t===e)return;let n=e?.getRootNode(),r=n!=null&&ye(n)?n:F(e),i=t=>t===e||t!=null&&I(e,t),a=e=>e===t||t!=null&&e!=null&&I(t,e);B=!0;let o=!1,s=e=>{(a(R(e))||o)&&e.stopImmediatePropagation()},c=n=>{(a(R(n))||o)&&(n.stopImmediatePropagation(),!e&&!o&&(o=!0,z(t),d()))},l=e=>{(i(R(e))||o)&&e.stopImmediatePropagation()},u=e=>{(i(R(e))||o)&&(e.stopImmediatePropagation(),o||(o=!0,z(t),d()))};r.addEventListener(`blur`,s,!0),r.addEventListener(`focusout`,c,!0),r.addEventListener(`focusin`,u,!0),r.addEventListener(`focus`,l,!0);let d=()=>{cancelAnimationFrame(f),r.removeEventListener(`blur`,s,!0),r.removeEventListener(`focusout`,c,!0),r.removeEventListener(`focusin`,u,!0),r.removeEventListener(`focus`,l,!0),B=!1,o=!1},f=requestAnimationFrame(d);return d}function He(e){if(typeof window>`u`||window.navigator==null)return!1;let t=window.navigator.userAgentData?.brands;return Array.isArray(t)&&t.some(t=>e.test(t.brand))||e.test(window.navigator.userAgent)}function Ue(e){return typeof window<`u`&&window.navigator!=null&&e.test(window.navigator.userAgentData?.platform||window.navigator.platform)}function V(e){let t=null;return()=>(t??=e(),t)}const H=V(function(){return Ue(/^Mac/i)}),We=V(function(){return Ue(/^iPhone/i)}),Ge=V(function(){return Ue(/^iPad/i)||H()&&navigator.maxTouchPoints>1}),U=V(function(){return We()||Ge()}),W=V(function(){return He(/AppleWebKit/i)&&(U()||!Ke())}),Ke=V(function(){return He(/Chrome|CriOS|CrMo/i)}),qe=V(function(){return He(/Android/i)}),Je=V(function(){return He(/(Firefox|FxiOS)/i)});function Ye(e){return e.pointerType===``&&e.isTrusted?!0:qe()&&e.pointerType?e.type===`click`&&e.buttons===1:e.detail===0&&!e.pointerType}function Xe(e){return!qe()&&e.width===0&&e.height===0||qe()&&e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType===`mouse`}function G(e,t,n=!0){let{metaKey:r,ctrlKey:i,altKey:a,shiftKey:o}=t;!W()&&Je()&&window.event?.type?.startsWith(`key`)&&e.target===`_blank`&&(H()?r=!0:i=!0);let s=W()&&H()&&!Ge()?new KeyboardEvent(`keydown`,{keyIdentifier:`Enter`,metaKey:r,ctrlKey:i,altKey:a,shiftKey:o}):new MouseEvent(`click`,{metaKey:r,ctrlKey:i,altKey:a,shiftKey:o,detail:1,bubbles:!0,cancelable:!0});G.isOpening=n,z(e),e.dispatchEvent(s),G.isOpening=!1}G.isOpening=!1;let K=null;const Ze=new Set;let q=new Map,J=!1,Qe=!1;const $e={Tab:!0,Escape:!0};function et(e,t){for(let n of Ze)n(e,t)}function tt(e){return!(e.metaKey||!H()&&e.altKey||e.ctrlKey||e.key===`Control`||e.key===`Shift`||e.key===`Meta`)}function nt(e){J=!0,!G.isOpening&&tt(e)&&(K=`keyboard`,et(`keyboard`,e))}function Y(e){K=`pointer`,`pointerType`in e&&e.pointerType,(e.type===`mousedown`||e.type===`pointerdown`)&&(J=!0,et(`pointer`,e))}function rt(e){!G.isOpening&&Ye(e)&&(J=!0,K=`virtual`)}function it(e){if(B)return;let t=R(e),n=F(t),r=P(t);if(t===n){Qe=!0;return}t===r||!e.isTrusted||(!J&&!Qe&&(K=`virtual`,et(`virtual`,e)),J=!1,Qe=!1)}function at(){B||(J=!1,Qe=!0)}function ot(e){if(typeof window>`u`||typeof document>`u`)return;let t=F(e),n=P(e);if(q.get(t))return;let r=t.HTMLElement.prototype.focus;Reflect.defineProperty(t.HTMLElement.prototype,"focus",{configurable:!0,writable:!0,value:function(){J=!0,r.apply(this,arguments)}}),n.addEventListener(`keydown`,nt,!0),n.addEventListener(`keyup`,nt,!0),n.addEventListener(`click`,rt,!0),t.addEventListener(`focus`,it,!0),t.addEventListener(`blur`,at,!1),typeof PointerEvent<`u`&&(n.addEventListener(`pointerdown`,Y,!0),n.addEventListener(`pointermove`,Y,!0),n.addEventListener(`pointerup`,Y,!0)),t.addEventListener(`beforeunload`,()=>{st(e)},{once:!0}),q.set(t,{focus:r})}const st=(e,t)=>{let n=F(e),r=P(e);t&&r.removeEventListener(`DOMContentLoaded`,t),q.has(n)&&(Reflect.defineProperty(n.HTMLElement.prototype,"focus",{configurable:!0,writable:!0,value:q.get(n).focus}),r.removeEventListener(`keydown`,nt,!0),r.removeEventListener(`keyup`,nt,!0),r.removeEventListener(`click`,rt,!0),n.removeEventListener(`focus`,it,!0),n.removeEventListener(`blur`,at,!1),typeof PointerEvent<`u`&&(r.removeEventListener(`pointerdown`,Y,!0),r.removeEventListener(`pointermove`,Y,!0),r.removeEventListener(`pointerup`,Y,!0)),q.delete(n))};function ct(e){let t=P(e),n;return t.readyState===`loading`?(n=()=>{ot(e)},t.addEventListener(`DOMContentLoaded`,n)):ot(e),()=>st(e,n)}typeof document<`u`&&ct();function lt(){return K!==`pointer`}function ut(){return K}function dt(e){K=e,et(e,null)}const ft=new Set([`checkbox`,`radio`,`range`,`color`,`file`,`image`,`button`,`submit`,`reset`]);function pt(e,t,n){let r=n?R(n):void 0,i=P(r),a=F(r),o=a===void 0?HTMLInputElement:a.HTMLInputElement,s=a===void 0?HTMLTextAreaElement:a.HTMLTextAreaElement,c=a===void 0?HTMLElement:a.HTMLElement,l=a===void 0?KeyboardEvent:a.KeyboardEvent,u=L(i);return e=e||u instanceof o&&!ft.has(u.type)||u instanceof s||u instanceof c&&u.isContentEditable,!(e&&t===`keyboard`&&n instanceof l&&!$e[n.key])}function mt(e,t,n){ot(),a(()=>{if(n?.enabled===!1)return;let t=(t,r)=>{pt(!!n?.isTextInput,t,r)&&e(lt())};return Ze.add(t),()=>{Ze.delete(t)}},t)}const ht=e.useInsertionEffect??m;function gt(e){let t=s(null);return ht(()=>{t.current=e},[e]),r((...e)=>{let n=t.current;return n?.(...e)},[])}let X=new Map,_t=new Set;function vt(){if(typeof window>`u`)return;function e(e){return`propertyName`in e}let t=t=>{let r=R(t);if(!e(t)||!r)return;let i=X.get(r);i||(i=new Set,X.set(r,i),r.addEventListener(`transitioncancel`,n,{once:!0})),i.add(t.propertyName)},n=t=>{let r=R(t);if(!e(t)||!r)return;let i=X.get(r);if(i&&(i.delete(t.propertyName),i.size===0&&(r.removeEventListener(`transitioncancel`,n),X.delete(r)),X.size===0)){for(let e of _t)e();_t.clear()}};document.body.addEventListener(`transitionrun`,t),document.body.addEventListener(`transitionend`,n)}typeof document<`u`&&(document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,vt):vt());function yt(){for(let[e]of X)`isConnected`in e&&!e.isConnected&&X.delete(e)}function bt(e){requestAnimationFrame(()=>{yt(),X.size===0?e():_t.add(e)})}function xt(e){if(!e.isConnected)return;let t=P(e);if(ut()===`virtual`){let n=L(t);bt(()=>{let r=L(t);(r===n||r===t.body)&&e.isConnected&&z(e)})}else z(e)}function St(e){let{isDisabled:t,onFocus:n,onBlur:i,onFocusChange:a}=e,o=r(e=>{if(R(e)===e.currentTarget)return i&&i(e),a&&a(!1),!0},[i,a]),s=Be(o),c=r(e=>{let t=R(e),r=P(t),i=r?L(r):L();t===e.currentTarget&&t===i&&(n&&n(e),a&&a(!0),s(e))},[a,n,s]);return{focusProps:{onFocus:!t&&(n||a||i)?c:void 0,onBlur:!t&&(i||a)?o:void 0}}}function Ct(e){if(e)return t=>{let n=!0;e({...t,preventDefault(){t.preventDefault()},isDefaultPrevented(){return t.isDefaultPrevented()},stopPropagation(){n=!0},continuePropagation(){n=!1,typeof t.continuePropagation==`function`&&t.continuePropagation()},isPropagationStopped(){return n}}),n&&!(typeof t.isPropagationStopped==`function`&&t.isPropagationStopped())&&t.stopPropagation()}}const wt=new Set([`shift`,`alt`,`control`,`meta`,`mod`]),Tt=[`Alt`,`Control`,`Meta`,`Shift`];function Et(e){let t=new Set;return e.alt&&t.add(`Alt`),e.shift&&t.add(`Shift`),e.ctrl&&t.add(`Control`),e.meta&&t.add(`Meta`),e.mod&&t.add(H()?`Meta`:`Control`),t}function Dt(e){let t=new Set;return e.altKey&&t.add(`Alt`),e.ctrlKey&&t.add(`Control`),e.metaKey&&t.add(`Meta`),e.shiftKey&&t.add(`Shift`),t}function Ot(e){return Tt.filter(t=>e.has(t))}function kt(e){let t=e.split(`+`).reduce((e,t)=>{let n=t.toLowerCase();return wt.has(n)?n===`shift`?e.shift=!0:n===`alt`?e.alt=!0:n===`control`?e.ctrl=!0:n===`meta`?e.meta=!0:n===`mod`&&(e.mod=!0):e.key=t,e},{shift:!1,alt:!1,ctrl:!1,meta:!1,mod:!1,key:``});if(t.key===``)throw Error(`Invalid keyboard shortcut: "${e}". Must include exactly one non-modifier key (e.g. "a", "Enter", "ArrowDown"). Combine any of Shift, Alt, Ctrl, Meta, and Mod.`);return t}function At(e){return e.toLowerCase()}const jt={space:` `,esc:`escape`,del:`delete`,ins:`insert`,left:`arrowleft`,right:`arrowright`,up:`arrowup`,down:`arrowdown`,pageup:`pageup`,pagedown:`pagedown`};function Mt(e){let t=At(e);return jt[t]??t}function Nt(e){let t=Ot(Et(e)),n=Mt(e.key);return t.length>0?`${t.join(`+`)}+${n}`:n}function Pt(e){let t=Ot(Dt(e)),n=At(e.key);return(t.length>0?`${t.join(`+`)}+`:``)+n}function Ft(e){let t=new Map;for(let[n,r]of Object.entries(e)){let e=kt(n);t.set(Nt(e),r)}return e=>{let n=Pt(e),r=t.get(n),i=r?.(e);i===void 0&&r!==void 0?i={shouldContinuePropagation:!1,shouldPreventDefault:!0}:typeof i==`boolean`&&(i={shouldContinuePropagation:!i,shouldPreventDefault:i}),i?.shouldPreventDefault&&e.preventDefault(),(!r||i?.shouldContinuePropagation)&&e.continuePropagation()}}function It(e){let{shortcuts:t,allowRepeats:n=!1,allowComposing:r=!1}=e,i,a;if(t){let o=Ft(t),s=Ct(e=>{if(!I(e.currentTarget,R(e))){e.continuePropagation();return}if(e.nativeEvent?.repeat&&!n||e.nativeEvent?.isComposing&&!r){e.continuePropagation();return}o(e)}),c=Ct(e=>{if(!I(e.currentTarget,R(e))){e.continuePropagation();return}if(e.nativeEvent?.repeat&&!n||e.nativeEvent?.isComposing&&!r){e.continuePropagation();return}e.continuePropagation()});i=e.onKeyDown?p(e.onKeyDown,s):s,a=e.onKeyUp?p(e.onKeyUp,c):c}else i=Ct(e.onKeyDown),a=Ct(e.onKeyUp);return{keyboardProps:e.isDisabled?{}:{onKeyDown:i,onKeyUp:a}}}function Lt(e,t){m(()=>{if(e&&e.ref&&t)return e.ref.current=t.current,()=>{e.ref&&(e.ref.current=null)}})}let Rt=e.createContext(null);function zt(e){let t=i(Rt)||{};Lt(t,e);let{ref:n,...r}=t;return r}function Bt(e,t){let{focusProps:n}=St(e),{keyboardProps:r}=It(e),i=N(n,r),o=zt(t),c=e.isDisabled?{}:o,l=s(e.autoFocus);a(()=>{l.current&&t.current&&xt(t.current),l.current=!1},[t]);let u=e.excludeFromTabOrder?-1:0;return e.isDisabled&&(u=void 0),{focusableProps:N({...i,tabIndex:u},c)}}typeof HTMLTemplateElement<`u`&&(Object.defineProperty(HTMLTemplateElement.prototype,"firstChild",{configurable:!0,enumerable:!0,get:function(){return this.content.firstChild}}),Object.defineProperty(HTMLTemplateElement.prototype,"appendChild",{configurable:!0,enumerable:!0,value:function(e){return this.content.appendChild(e)}}),Object.defineProperty(HTMLTemplateElement.prototype,"removeChild",{configurable:!0,enumerable:!0,value:function(e){return this.content.removeChild(e)}}),Object.defineProperty(HTMLTemplateElement.prototype,"insertBefore",{configurable:!0,enumerable:!0,value:function(e,t){return this.content.insertBefore(e,t)}}));const Vt=t(!1);function Ht(e){let t=(t,n)=>i(Vt)?null:e(t,n);return t.displayName=e.displayName||e.name,n(t)}const Ut=new Set([`id`]),Wt=new Set([`aria-label`,`aria-labelledby`,`aria-describedby`,`aria-details`]),Gt=new Set([`href`,`hrefLang`,`target`,`rel`,`download`,`ping`,`referrerPolicy`]),Kt=new Set([`dir`,`lang`,`hidden`,`inert`,`translate`]),qt=new Set(`onClick.onAuxClick.onContextMenu.onDoubleClick.onMouseDown.onMouseEnter.onMouseLeave.onMouseMove.onMouseOut.onMouseOver.onMouseUp.onTouchCancel.onTouchEnd.onTouchMove.onTouchStart.onPointerDown.onPointerMove.onPointerUp.onPointerCancel.onPointerEnter.onPointerLeave.onPointerOver.onPointerOut.onGotPointerCapture.onLostPointerCapture.onScroll.onWheel.onAnimationStart.onAnimationEnd.onAnimationIteration.onTransitionCancel.onTransitionEnd.onTransitionRun.onTransitionStart`.split(`.`)),Jt=/^(data-.*)$/;function Yt(e,t={}){let{labelable:n,isLink:r,global:i,events:a=i,propNames:o}=t,s={};for(let t in e)Object.prototype.hasOwnProperty.call(e,t)&&(Ut.has(t)||n&&Wt.has(t)||r&&Gt.has(t)||i&&Kt.has(t)||a&&(qt.has(t)||t.endsWith(`Capture`)&&qt.has(t.slice(0,-7)))||o?.has(t)||Jt.test(t))&&(s[t]=e[t]);return s}let Z=`default`,Xt=``,Zt=new WeakMap;function Qt(e){if(U()&&W()){if(Z==="default"){let t=P(e);Xt=t.documentElement.style.webkitUserSelect,t.documentElement.style.webkitUserSelect=`none`}Z=`disabled`}else if(e instanceof HTMLElement||e instanceof SVGElement){let t=`userSelect`in e.style?`userSelect`:`webkitUserSelect`;Zt.set(e,e.style[t]),e.style[t]=`none`}}function $t(e){if(U()&&W()){if(Z!==`disabled`)return;Z=`restoring`,setTimeout(()=>{bt(()=>{if(Z===`restoring`){let t=P(e);t.documentElement.style.webkitUserSelect===`none`&&(t.documentElement.style.webkitUserSelect=Xt||``),Xt=``,Z=`default`}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&Zt.has(e)){let t=Zt.get(e),n=`userSelect`in e.style?`userSelect`:`webkitUserSelect`;e.style[n]===`none`&&(e.style[n]=t),e.getAttribute(`style`)===``&&e.removeAttribute(`style`),Zt.delete(e)}}function en(e,t){let n=F(t),r=P(t);if(r==null||n==null)return;let i,a=`meta[name="${CSS.escape(e)}"], meta[property="${CSS.escape(e)}"]`,o=r.querySelector(a);return o&&o instanceof n.HTMLMetaElement&&(e===`csp-nonce`&&o.nonce&&(i??=o.nonce||void 0),o.content&&(i??=o.content||void 0)),e===`csp-nonce`&&(i??=n.__webpack_nonce__||globalThis.__webpack_nonce__||void 0),i}let tn=new WeakMap;function nn(e){let t=P(e),n=tn.get(t);return n??=en(`csp-nonce`,t),n!==void 0&&tn.set(t,n),n}const rn=e.createContext({register:()=>{}});rn.displayName=`PressResponderContext`;function an(){let e=s(new Map),t=r((t,n,r,i)=>{let a=i?.once?(...t)=>{e.current.delete(r),r(...t)}:r;e.current.set(r,{type:n,eventTarget:t,fn:a,options:i}),t.addEventListener(n,a,i)},[]),n=r((t,n,r,i)=>{let a=e.current.get(r)?.fn||r;t.removeEventListener(n,a,i),e.current.delete(r)},[]),i=r(()=>{e.current.forEach((e,t)=>{n(e.eventTarget,e.type,t,e.options)})},[n]);return a(()=>i,[i]),{addGlobalListener:t,removeGlobalListener:n,removeAllGlobalListeners:i}}function on(e){let t=i(rn);if(t){let{register:n,ref:r,...i}=t;e=N(i,e),n()}return Lt(t,e.ref),e}var sn=class{#e;constructor(e,t,n,r){this.#e=!0;let i=(r?.target??n.currentTarget)?.getBoundingClientRect(),a,o=0,s,c=null;n.clientX!=null&&n.clientY!=null&&(s=n.clientX,c=n.clientY),i&&(s!=null&&c!=null?(a=s-i.left,o=c-i.top):(a=i.width/2,o=i.height/2)),this.type=e,this.pointerType=t,this.target=n.currentTarget,this.shiftKey=n.shiftKey,this.metaKey=n.metaKey,this.ctrlKey=n.ctrlKey,this.altKey=n.altKey,this.x=a,this.y=o,this.key=n.key}continuePropagation(){this.#e=!1}get shouldStopPropagation(){return this.#e}};const cn=Symbol(`linkClicked`),ln=`react-aria-pressable-style`,un=`data-react-aria-pressable`;function dn(e){let{onPress:t,onPressChange:n,onPressStart:i,onPressEnd:l,onPressUp:u,onClick:d,isDisabled:f,isPressed:m,preventFocusOnPress:h,shouldCancelOnPointerExit:g,allowTextSelectionOnPress:_,ref:v,...y}=on(e),[b,ee]=c(!1),x=s({isPressed:!1,ignoreEmulatedMouseEvents:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null,disposables:[]}),{addGlobalListener:S,removeAllGlobalListeners:C}=an(),w=r((e,t)=>{let r=x.current;if(f||r.didFirePressStart)return!1;let a=!0;if(r.isTriggeringEvent=!0,i){let n=new sn(`pressstart`,t,e);i(n),a=n.shouldStopPropagation}return n&&n(!0),r.isTriggeringEvent=!1,r.didFirePressStart=!0,ee(!0),a},[f,i,n]),T=r((e,r,i=!0)=>{let a=x.current;if(!a.didFirePressStart)return!1;a.didFirePressStart=!1,a.isTriggeringEvent=!0;let o=!0;if(l){let t=new sn(`pressend`,r,e);l(t),o=t.shouldStopPropagation}if(n&&n(!1),ee(!1),t&&i&&!f){let n=new sn(`press`,r,e);t(n),o&&=n.shouldStopPropagation}return a.isTriggeringEvent=!1,o},[f,l,n,t]),E=gt(T),D=gt(r((e,t)=>{let n=x.current;if(f)return!1;if(u){n.isTriggeringEvent=!0;let r=new sn(`pressup`,t,e);return u(r),n.isTriggeringEvent=!1,r.shouldStopPropagation}return!0},[f,u])),O=r(e=>{let t=x.current;if(t.isPressed&&t.target){t.didFirePressStart&&t.pointerType!=null&&T(Q(t.target,e),t.pointerType,!1),t.isPressed=!1,t.isOverTarget=!1,t.activePointerId=null,t.pointerType=null,C(),_||$t(t.target);for(let e of t.disposables)e();t.disposables=[]}},[_,C,T]),k=gt(O);a(()=>{f&&x.current.isPressed&&k({currentTarget:x.current.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})},[f]);let A=r(e=>{g&&O(e)},[g,O]),j=r(e=>{f||d?.(e)},[f,d]),te=r((e,t)=>{if(!f&&d){let n=new MouseEvent(`click`,e);ze(n,t),d(Re(n))}},[f,d]),ne=o(()=>{let e=x.current,t={onKeyDown(t){if(pn(t.nativeEvent,t.currentTarget)&&I(t.currentTarget,R(t))){hn(R(t),t.key)&&t.preventDefault();let r=!0;!e.isPressed&&!t.repeat&&(e.target=t.currentTarget,e.isPressed=!0,e.pointerType=`keyboard`,r=w(t,`keyboard`));let i=t.currentTarget;S(P(t.currentTarget),`keyup`,p(t=>{pn(t,i)&&!t.repeat&&I(i,R(t))&&e.target&&D(Q(e.target,t),`keyboard`)},n),!0),r&&t.stopPropagation(),t.metaKey&&H()&&e.metaKeyEvents?.set(t.key,t.nativeEvent)}else t.key===`Meta`&&(e.metaKeyEvents=new Map)},onClick(t){if(!(t&&!I(t.currentTarget,R(t)))&&t&&t.button===0&&!e.isTriggeringEvent&&!G.isOpening){let n=!0;if(f&&t.preventDefault(),!e.ignoreEmulatedMouseEvents&&!e.isPressed&&(e.pointerType===`virtual`||Ye(t.nativeEvent))){let e=w(t,`virtual`),r=D(t,`virtual`),i=E(t,`virtual`);j(t),n=e&&r&&i}else if(e.isPressed&&e.pointerType!==`keyboard`){let r=e.pointerType||t.nativeEvent.pointerType||`virtual`,i=D(Q(t.currentTarget,t),r),a=E(Q(t.currentTarget,t),r,!0);n=i&&a,e.isOverTarget=!1,j(t),k(t)}e.ignoreEmulatedMouseEvents=!1,n&&t.stopPropagation()}}},n=t=>{if(e.isPressed&&e.target&&pn(t,e.target)){hn(R(t),t.key)&&t.preventDefault();let n=R(t),r=I(e.target,n);E(Q(e.target,t),`keyboard`,r),r&&te(t,e.target),C(),t.key!==`Enter`&&fn(e.target)&&I(e.target,n)&&!t[cn]&&(t[cn]=!0,G(e.target,t,!1)),e.isPressed=!1,e.metaKeyEvents?.delete(t.key)}else if(t.key===`Meta`&&e.metaKeyEvents?.size){let t=e.metaKeyEvents;e.metaKeyEvents=void 0;for(let n of t.values())e.target?.dispatchEvent(new KeyboardEvent(`keyup`,n))}};if(typeof PointerEvent<`u`){t.onPointerDown=t=>{if(t.button!==0||!I(t.currentTarget,R(t)))return;if(Xe(t.nativeEvent)){e.pointerType=`virtual`;return}e.pointerType=t.pointerType;let i=!0;if(!e.isPressed){e.isPressed=!0,e.isOverTarget=!0,e.activePointerId=t.pointerId,e.target=t.currentTarget,_||Qt(e.target),i=w(t,e.pointerType);let a=R(t);`releasePointerCapture`in a&&(`hasPointerCapture`in a?a.hasPointerCapture(t.pointerId)&&a.releasePointerCapture(t.pointerId):a.releasePointerCapture(t.pointerId)),S(P(t.currentTarget),`pointerup`,n,!1),S(P(t.currentTarget),`pointercancel`,r,!1)}i&&t.stopPropagation()},t.onMouseDown=t=>{if(I(t.currentTarget,R(t))&&t.button===0){if(h){let n=Ve(t.target);n&&e.disposables.push(n)}t.stopPropagation()}},t.onPointerUp=t=>{!I(t.currentTarget,R(t))||e.pointerType===`virtual`||t.button===0&&!e.isPressed&&D(t,e.pointerType||t.pointerType)},t.onPointerEnter=t=>{t.pointerId===e.activePointerId&&e.target&&!e.isOverTarget&&e.pointerType!=null&&(e.isOverTarget=!0,w(Q(e.target,t),e.pointerType))},t.onPointerLeave=t=>{t.pointerId===e.activePointerId&&e.target&&e.isOverTarget&&e.pointerType!=null&&(e.isOverTarget=!1,E(Q(e.target,t),e.pointerType,!1),A(t))};let n=t=>{if(t.pointerId===e.activePointerId&&e.isPressed&&t.button===0&&e.target){if(I(e.target,R(t))&&e.pointerType!=null){let n=!1,r=setTimeout(()=>{e.isPressed&&e.target instanceof HTMLElement&&(n?k(t):(z(e.target),e.target.click()))},80);S(t.currentTarget,`click`,()=>n=!0,!0),e.disposables.push(()=>clearTimeout(r))}else k(t);e.isOverTarget=!1}},r=e=>{k(e)};t.onDragStart=e=>{I(e.currentTarget,R(e))&&k(e)}}return t},[S,f,h,C,_,A,w,j,te]);return a(()=>{if(!v)return;let e=P(v.current);if(!e||!e.head||e.getElementById(ln))return;let t=e.createElement(`style`);t.id=ln;let n=nn(e);n&&(t.nonce=n),t.textContent=`
2
- @layer {
3
- [${un}] {
4
- touch-action: pan-x pan-y pinch-zoom;
5
- }
6
- }
7
- `.trim(),e.head.prepend(t)},[v]),a(()=>{let e=x.current;return()=>{_||$t(e.target??void 0);for(let t of e.disposables)t();e.disposables=[]}},[_]),{isPressed:m||b,pressProps:N(y,ne,{[un]:!0})}}function fn(e){return e.tagName===`A`&&e.hasAttribute(`href`)}function pn(e,t){let{key:n,code:r}=e,i=t,a=i.getAttribute(`role`);return(n===`Enter`||n===` `||n===`Spacebar`||r===`Space`)&&!(i instanceof F(i).HTMLInputElement&&!_n(i,n)||i instanceof F(i).HTMLTextAreaElement||i.isContentEditable)&&!((a===`link`||!a&&fn(i))&&n!==`Enter`)}function Q(e,t){let n=t.clientX,r=t.clientY;return{currentTarget:e,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,clientX:n,clientY:r,key:t.key}}function mn(e){return e instanceof HTMLInputElement?!1:e instanceof HTMLButtonElement?e.type!==`submit`&&e.type!==`reset`:!fn(e)}function hn(e,t){return H()&&t===`Enter`?!1:e instanceof HTMLInputElement?t===`Enter`&&(e.type===`checkbox`||e.type===`radio`)?!1:!_n(e,t):mn(e)}const gn=new Set([`checkbox`,`radio`,`range`,`color`,`file`,`image`,`button`,`submit`,`reset`]);function _n(e,t){return e.type===`checkbox`||e.type===`radio`?t===` `:gn.has(e.type)}function vn(e){let{isDisabled:t,onBlurWithin:n,onFocusWithin:i,onFocusWithinChange:a}=e,o=s({isFocusWithin:!1}),{addGlobalListener:c,removeAllGlobalListeners:l}=an(),u=r(e=>{I(e.currentTarget,R(e))&&o.current.isFocusWithin&&!I(e.currentTarget,e.relatedTarget)&&(o.current.isFocusWithin=!1,l(),n&&n(e),a&&a(!1))},[n,a,o,l]),d=Be(u),f=r(e=>{if(!I(e.currentTarget,R(e)))return;let t=R(e),n=P(t),r=L(n);if(!o.current.isFocusWithin&&r===t){i&&i(e),a&&a(!0),o.current.isFocusWithin=!0,d(e);let t=e.currentTarget;c(n,`focus`,e=>{let r=R(e);if(o.current.isFocusWithin&&!I(t,r)){let e=new n.defaultView.FocusEvent(`blur`,{relatedTarget:r});ze(e,t);let i=Re(e);u(i)}},{capture:!0})}},[i,a,d,c,u]);return t?{focusWithinProps:{onFocus:void 0,onBlur:void 0}}:{focusWithinProps:{onFocus:f,onBlur:u}}}function yn(e={}){let{autoFocus:t=!1,isTextInput:n,within:i}=e,a=s({isFocused:!1,isFocusVisible:t||lt()}),[o,l]=c(!1),[u,d]=c(()=>a.current.isFocused&&a.current.isFocusVisible),f=r(()=>d(a.current.isFocused&&a.current.isFocusVisible),[]),p=r(e=>{a.current.isFocused=e,a.current.isFocusVisible=lt(),l(e),f()},[f]);mt(e=>{a.current.isFocusVisible=e,f()},[n,o],{enabled:o,isTextInput:n});let{focusProps:m}=St({isDisabled:i,onFocusChange:p}),{focusWithinProps:h}=vn({isDisabled:!i,onFocusWithinChange:p});return{isFocused:o,isFocusVisible:u,focusProps:i?h:m}}let bn=!1,xn=0;function Sn(){bn=!0,setTimeout(()=>{bn=!1},500)}function Cn(e){e.pointerType===`touch`&&Sn()}function wn(){let e=P(null);if(e!==void 0)return xn===0&&typeof PointerEvent<`u`&&e.addEventListener(`pointerup`,Cn),xn++,()=>{xn--,!(xn>0)&&typeof PointerEvent<`u`&&e.removeEventListener(`pointerup`,Cn)}}function Tn(e){let{onHoverStart:t,onHoverChange:n,onHoverEnd:r,isDisabled:i}=e,[l,u]=c(!1),d=s({isHovered:!1,ignoreEmulatedMouseEvents:!1,pointerType:``,target:null}).current;a(wn,[]);let{addGlobalListener:f,removeAllGlobalListeners:p}=an(),{hoverProps:m,triggerHoverEnd:h}=o(()=>{let e=(e,r)=>{if(d.pointerType=r,i||r===`touch`||d.isHovered||!I(e.currentTarget,R(e)))return;d.isHovered=!0;let o=e.currentTarget;d.target=o,f(P(R(e)),`pointerover`,e=>{d.isHovered&&d.target&&!I(d.target,R(e))&&a(e,e.pointerType)},{capture:!0}),t&&t({type:`hoverstart`,target:o,pointerType:r}),n&&n(!0),u(!0)},a=(e,t)=>{let i=d.target;d.pointerType=``,d.target=null,!(t===`touch`||!d.isHovered||!i)&&(d.isHovered=!1,p(),r&&r({type:`hoverend`,target:i,pointerType:t}),n&&n(!1),u(!1))},o={};return typeof PointerEvent<`u`&&(o.onPointerEnter=t=>{bn&&t.pointerType===`mouse`||e(t,t.pointerType)},o.onPointerLeave=e=>{!i&&I(e.currentTarget,R(e))&&a(e,e.pointerType)}),{hoverProps:o,triggerHoverEnd:a}},[t,n,r,i,d,f,p]);return a(()=>{i&&h({currentTarget:d.target},d.pointerType)},[i]),{hoverProps:m,isHovered:l}}const En=t(null),Dn=7e3;let $=null;function On(e,t=`assertive`,n=Dn){$?$.announce(e,t,n):($=new kn,(typeof IS_REACT_ACT_ENVIRONMENT==`boolean`?IS_REACT_ACT_ENVIRONMENT:typeof jest<`u`)?$.announce(e,t,n):setTimeout(()=>{$?.isAttached()&&$?.announce(e,t,n)},100))}var kn=class{constructor(){this.node=null,this.assertiveLog=null,this.politeLog=null,typeof document<`u`&&(this.node=document.createElement(`div`),this.node.dataset.liveAnnouncer=`true`,Object.assign(this.node.style,{border:0,clip:`rect(0 0 0 0)`,clipPath:`inset(50%)`,height:`1px`,margin:`-1px`,overflow:`hidden`,padding:0,position:`absolute`,width:`1px`,whiteSpace:`nowrap`}),this.assertiveLog=this.createLog(`assertive`),this.node.appendChild(this.assertiveLog),this.politeLog=this.createLog(`polite`),this.node.appendChild(this.politeLog),document.body.prepend(this.node))}isAttached(){return this.node?.isConnected}createLog(e){let t=document.createElement(`div`);return t.setAttribute(`role`,`log`),t.setAttribute(`aria-live`,e),t.setAttribute(`aria-relevant`,`additions`),t}destroy(){this.node&&=(document.body.removeChild(this.node),null)}announce(e,t=`assertive`,n=Dn){if(!this.node)return;let r=document.createElement(`div`);typeof e==`object`?(r.setAttribute(`role`,`img`),r.setAttribute(`aria-labelledby`,e[`aria-labelledby`])):r.textContent=e,t===`assertive`?this.assertiveLog?.appendChild(r):this.politeLog?.appendChild(r),e!==``&&setTimeout(()=>{r.remove()},n)}clear(e){this.node&&((!e||e===`assertive`)&&this.assertiveLog&&(this.assertiveLog.innerHTML=``),(!e||e===`polite`)&&this.politeLog&&(this.politeLog.innerHTML=``))}};function An(e,t){let{elementType:n=`button`,isDisabled:r,onPress:i,onPressStart:a,onPressEnd:o,onPressUp:s,onPressChange:c,preventFocusOnPress:l,allowFocusWhenDisabled:u,onClick:d,href:f,target:p,rel:m,type:h=`button`}=e,g;g=n===`button`?{type:h,disabled:r,form:e.form,formAction:e.formAction,formEncType:e.formEncType,formMethod:e.formMethod,formNoValidate:e.formNoValidate,formTarget:e.formTarget,name:e.name,value:e.value}:{role:`button`,href:n===`a`&&!r?f:void 0,target:n===`a`?p:void 0,type:n===`input`?h:void 0,disabled:n===`input`?r:void 0,"aria-disabled":!r||n===`input`?void 0:r,rel:n===`a`?m:void 0};let{pressProps:_,isPressed:v}=dn({onPressStart:a,onPressEnd:o,onPressChange:c,onPress:i,onPressUp:s,onClick:d,isDisabled:r,preventFocusOnPress:l,ref:t}),{focusableProps:y}=Bt(e,t);u&&(y.tabIndex=r?-1:y.tabIndex);let b=N(y,_,Yt(e,{labelable:!0}));return{isPressed:v,buttonProps:N(g,b,{"aria-haspopup":e[`aria-haspopup`],"aria-expanded":e[`aria-expanded`],"aria-controls":e[`aria-controls`],"aria-pressed":e[`aria-pressed`],"aria-current":e[`aria-current`],"aria-disabled":e[`aria-disabled`]})}}const jn=t({}),Mn=Ht(function(t,n){[t,n]=ue(t,n,jn);let r=t,{isPending:i}=r,{buttonProps:o,isPressed:c}=An(t,n);o=Pn(o,i);let{focusProps:l,isFocused:u,isFocusVisible:d}=yn(t),{hoverProps:f,isHovered:p}=Tn({...t,isDisabled:t.isDisabled||i}),m={isHovered:p,isPressed:(r.isPressed||c)&&!i,isFocused:u,isFocusVisible:d,isDisabled:t.isDisabled||!1,isPending:i??!1},h=se({...t,values:m,defaultClassName:`react-aria-Button`}),g=j(o.id),_=j(),v=o[`aria-labelledby`];i&&(v?v=`${v} ${_}`:o[`aria-label`]&&(v=`${g} ${_}`));let y=s(i);a(()=>{let e={"aria-labelledby":v||g};(!y.current&&u&&i||y.current&&u&&!i)&&On(e,`assertive`),y.current=i},[i,u,v,g]);let b=Yt(t,{global:!0});return delete b.onClick,e.createElement(he.button,{...N(b,h,o,l,f),type:o.type===`submit`&&i?`button`:o.type,id:g,ref:n,"aria-labelledby":v,slot:t.slot||void 0,"aria-disabled":i?`true`:o[`aria-disabled`],"data-disabled":t.isDisabled||void 0,"data-pressed":m.isPressed||void 0,"data-hovered":p||void 0,"data-focused":u||void 0,"data-pending":i||void 0,"data-focus-visible":d||void 0},e.createElement(En.Provider,{value:{id:_}},h.children))}),Nn=/Focus|Blur|Hover|Pointer(Enter|Leave|Over|Out)|Mouse(Enter|Leave|Over|Out)/;function Pn(e,t){if(t){for(let t in e)t.startsWith(`on`)&&!Nn.test(t)&&(e[t]=void 0);e.href=void 0,e.target=void 0}return e}export{ye as A,he as B,Ie as C,R as D,L as E,ue as F,M as G,le as H,se as I,T as J,ne as K,de as L,F as M,be as N,Se as O,oe as P,ce as R,Fe as S,Ce as T,ie as U,fe as V,N as W,p as X,m as Y,f as Z,dt as _,vn as a,qe as b,nn as c,Bt as d,Rt as f,ut as g,gt as h,yn as i,P as j,xe as k,Yt as l,xt as m,Mn as n,dn as o,It as p,j as q,Tn as r,rn as s,jn as t,Ht as u,Ke as v,I as w,U as x,W as y,ae as z};