@kelet-ai/feedback-ui 0.7.0 → 1.0.0

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.
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var ae;function xe(){if(ae)return X;ae=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function n(r,o,u){var d=null;if(u!==void 0&&(d=""+u),o.key!==void 0&&(d=""+o.key),"key"in o){u={};for(var f in o)f!=="key"&&(u[f]=o[f])}else u=o;return o=u.ref,{$$typeof:t,type:r,key:d,ref:o!==void 0?o:null,props:u}}return X.Fragment=e,X.jsx=n,X.jsxs=n,X}var Z={};/**
9
+ */var ae;function xe(){if(ae)return X;ae=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function n(r,o,u){var p=null;if(u!==void 0&&(p=""+u),o.key!==void 0&&(p=""+o.key),"key"in o){u={};for(var f in o)f!=="key"&&(u[f]=o[f])}else u=o;return o=u.ref,{$$typeof:t,type:r,key:p,ref:o!==void 0?o:null,props:u}}return X.Fragment=e,X.jsx=n,X.jsxs=n,X}var Z={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,24 +14,24 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var le;function Ce(){return le||(le=1,process.env.NODE_ENV!=="production"&&function(){function t(a){if(a==null)return null;if(typeof a=="function")return a.$$typeof===s?null:a.displayName||a.name||null;if(typeof a=="string")return a;switch(a){case w:return"Fragment";case D:return"Profiler";case A:return"StrictMode";case O:return"Suspense";case N:return"SuspenseList";case l:return"Activity"}if(typeof a=="object")switch(typeof a.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),a.$$typeof){case h:return"Portal";case k:return(a.displayName||"Context")+".Provider";case v:return(a._context.displayName||"Context")+".Consumer";case E:var T=a.render;return a=a.displayName,a||(a=T.displayName||T.name||"",a=a!==""?"ForwardRef("+a+")":"ForwardRef"),a;case L:return T=a.displayName||null,T!==null?T:t(a.type)||"Memo";case i:T=a._payload,a=a._init;try{return t(a(T))}catch{}}return null}function e(a){return""+a}function n(a){try{e(a);var T=!1}catch{T=!0}if(T){T=console;var _=T.error,j=typeof Symbol=="function"&&Symbol.toStringTag&&a[Symbol.toStringTag]||a.constructor.name||"Object";return _.call(T,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",j),e(a)}}function r(a){if(a===w)return"<>";if(typeof a=="object"&&a!==null&&a.$$typeof===i)return"<...>";try{var T=t(a);return T?"<"+T+">":"<...>"}catch{return"<...>"}}function o(){var a=c.A;return a===null?null:a.getOwner()}function u(){return Error("react-stack-top-frame")}function d(a){if(b.call(a,"key")){var T=Object.getOwnPropertyDescriptor(a,"key").get;if(T&&T.isReactWarning)return!1}return a.key!==void 0}function f(a,T){function _(){K||(K=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",T))}_.isReactWarning=!0,Object.defineProperty(a,"key",{get:_,configurable:!0})}function p(){var a=t(this.type);return F[a]||(F[a]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),a=this.props.ref,a!==void 0?a:null}function y(a,T,_,j,z,Y,G,J){return _=Y.ref,a={$$typeof:x,type:a,key:T,props:Y,_owner:z},(_!==void 0?_:null)!==null?Object.defineProperty(a,"ref",{enumerable:!1,get:p}):Object.defineProperty(a,"ref",{enumerable:!1,value:null}),a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(a,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(a,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.defineProperty(a,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:J}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a}function m(a,T,_,j,z,Y,G,J){var I=T.children;if(I!==void 0)if(j)if(S(I)){for(j=0;j<I.length;j++)R(I[j]);Object.freeze&&Object.freeze(I)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else R(I);if(b.call(T,"key")){I=t(a);var H=Object.keys(T).filter(function(et){return et!=="key"});j=0<H.length?"{key: someKey, "+H.join(": ..., ")+": ...}":"{key: someKey}",re[I+j]||(H=0<H.length?"{"+H.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var le;function Ce(){return le||(le=1,process.env.NODE_ENV!=="production"&&function(){function t(a){if(a==null)return null;if(typeof a=="function")return a.$$typeof===s?null:a.displayName||a.name||null;if(typeof a=="string")return a;switch(a){case w:return"Fragment";case A:return"Profiler";case R:return"StrictMode";case x:return"Suspense";case N:return"SuspenseList";case l:return"Activity"}if(typeof a=="object")switch(typeof a.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),a.$$typeof){case h:return"Portal";case O:return(a.displayName||"Context")+".Provider";case b:return(a._context.displayName||"Context")+".Consumer";case E:var T=a.render;return a=a.displayName,a||(a=T.displayName||T.name||"",a=a!==""?"ForwardRef("+a+")":"ForwardRef"),a;case I:return T=a.displayName||null,T!==null?T:t(a.type)||"Memo";case i:T=a._payload,a=a._init;try{return t(a(T))}catch{}}return null}function e(a){return""+a}function n(a){try{e(a);var T=!1}catch{T=!0}if(T){T=console;var S=T.error,j=typeof Symbol=="function"&&Symbol.toStringTag&&a[Symbol.toStringTag]||a.constructor.name||"Object";return S.call(T,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",j),e(a)}}function r(a){if(a===w)return"<>";if(typeof a=="object"&&a!==null&&a.$$typeof===i)return"<...>";try{var T=t(a);return T?"<"+T+">":"<...>"}catch{return"<...>"}}function o(){var a=d.A;return a===null?null:a.getOwner()}function u(){return Error("react-stack-top-frame")}function p(a){if(v.call(a,"key")){var T=Object.getOwnPropertyDescriptor(a,"key").get;if(T&&T.isReactWarning)return!1}return a.key!==void 0}function f(a,T){function S(){K||(K=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",T))}S.isReactWarning=!0,Object.defineProperty(a,"key",{get:S,configurable:!0})}function c(){var a=t(this.type);return L[a]||(L[a]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),a=this.props.ref,a!==void 0?a:null}function y(a,T,S,j,z,Y,G,B){return S=Y.ref,a={$$typeof:P,type:a,key:T,props:Y,_owner:z},(S!==void 0?S:null)!==null?Object.defineProperty(a,"ref",{enumerable:!1,get:c}):Object.defineProperty(a,"ref",{enumerable:!1,value:null}),a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(a,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(a,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.defineProperty(a,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:B}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a}function m(a,T,S,j,z,Y,G,B){var F=T.children;if(F!==void 0)if(j)if(_(F)){for(j=0;j<F.length;j++)D(F[j]);Object.freeze&&Object.freeze(F)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else D(F);if(v.call(T,"key")){F=t(a);var H=Object.keys(T).filter(function(et){return et!=="key"});j=0<H.length?"{key: someKey, "+H.join(": ..., ")+": ...}":"{key: someKey}",re[F+j]||(H=0<H.length?"{"+H.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
18
  let props = %s;
19
19
  <%s {...props} />
20
20
  React keys must be passed directly to JSX without using spread:
21
21
  let props = %s;
22
- <%s key={someKey} {...props} />`,j,I,H,I),re[I+j]=!0)}if(I=null,_!==void 0&&(n(_),I=""+_),d(T)&&(n(T.key),I=""+T.key),"key"in T){_={};for(var se in T)se!=="key"&&(_[se]=T[se])}else _=T;return I&&f(_,typeof a=="function"?a.displayName||a.name||"Unknown":a),y(a,I,Y,z,o(),_,G,J)}function R(a){typeof a=="object"&&a!==null&&a.$$typeof===x&&a._store&&(a._store.validated=1)}var P=g,x=Symbol.for("react.transitional.element"),h=Symbol.for("react.portal"),w=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),D=Symbol.for("react.profiler"),v=Symbol.for("react.consumer"),k=Symbol.for("react.context"),E=Symbol.for("react.forward_ref"),O=Symbol.for("react.suspense"),N=Symbol.for("react.suspense_list"),L=Symbol.for("react.memo"),i=Symbol.for("react.lazy"),l=Symbol.for("react.activity"),s=Symbol.for("react.client.reference"),c=P.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,b=Object.prototype.hasOwnProperty,S=Array.isArray,C=console.createTask?console.createTask:function(){return null};P={react_stack_bottom_frame:function(a){return a()}};var K,F={},B=P.react_stack_bottom_frame.bind(P,u)(),V=C(r(u)),re={};Z.Fragment=w,Z.jsx=function(a,T,_,j,z){var Y=1e4>c.recentlyCreatedOwnerStacks++;return m(a,T,_,!1,j,z,Y?Error("react-stack-top-frame"):B,Y?C(r(a)):V)},Z.jsxs=function(a,T,_,j,z){var Y=1e4>c.recentlyCreatedOwnerStacks++;return m(a,T,_,!0,j,z,Y?Error("react-stack-top-frame"):B,Y?C(r(a)):V)}}()),Z}var ue;function Te(){return ue||(ue=1,process.env.NODE_ENV==="production"?ee.exports=xe():ee.exports=Ce()),ee.exports}var M=Te();const Q=g.createContext(null),Re="https://api.kelet.ai/api",Oe=()=>{const t=g.useContext(Q);if(!t)throw new Error("useKelet must be used within a KeletProvider");return t},oe=()=>{const t=g.useContext(Q);return t?t.feedback:(console.warn("No FeedbackHandler found: defaultFeedbackHandler is not possible since there's no KeletProvider wrapping this call, and handler not provided"),async()=>{})},De=({apiKey:t,project:e,children:n})=>{const r=g.useContext(Q),o=t||r?.api_key;if(!o)throw new Error("apiKey is required either directly or from a parent KeletProvider");const d={api_key:o,project:e,feedback:async f=>{const p=`${Re}/projects/${e}/feedback`,y={tx_id:f.tx_id,source:f.source||"EXPLICIT",vote:f.vote,explanation:f.explanation,correction:f.correction,selection:f.selection},m=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(y)});if(!m.ok)throw new Error(`Failed to submit feedback: ${m.statusText}`)}};return M.jsx(Q.Provider,{value:d,children:n})},q=(t,e)=>{const n={...e};for(const r in e){const o=t[r],u=e[r];/^on[A-Z]/.test(r)?o&&u?n[r]=(...f)=>{u(...f),o(...f)}:o&&(n[r]=o):r==="style"?n[r]={...o,...u}:r==="className"?n[r]=[o,u].filter(Boolean).join(" "):n[r]=u!==void 0?u:o}return{...t,...n}},ce=g.createContext(null),$=()=>{const t=g.useContext(ce);if(!t)throw new Error("VoteFeedback components must be used within VoteFeedback.Root");return t},Ae={Root:({children:t,onFeedback:e,defaultText:n="",tx_id:r,extra_metadata:o,trigger_name:u})=>{const d=typeof r=="function"?r():r,[f,p]=g.useState(!1),[y,m]=g.useState(n),[R,P]=g.useState(!1),[x,h]=g.useState(null),w=g.useRef(null),A=g.useRef(null),D=g.useId(),v=g.useId(),k=oe(),E=e||k;g.useEffect(()=>{p(!1),m(n),P(!1),h(null),setTimeout(()=>A.current?.focus(),0)},[d,n]);const O=g.useCallback(async()=>{h("upvote");const c={tx_id:d,vote:"upvote",...o&&{extra_metadata:o},...u&&{trigger_name:u}};try{P(!0),await E(c)}finally{P(!1)}},[E,d,o,u]),N=g.useCallback(async()=>{if(h("downvote"),E){const c={tx_id:d,vote:"downvote",...o&&{extra_metadata:o},...u&&{trigger_name:u}};try{P(!0),await E(c)}finally{P(!1)}}p(!0),setTimeout(()=>{w.current?.focus();const c=document.createElement("div");c.setAttribute("aria-live","polite"),c.setAttribute("aria-atomic","true"),c.className="sr-only",c.textContent="Feedback dialog opened. You can provide additional details about your downvote.",document.body.appendChild(c),setTimeout(()=>document.body.removeChild(c),1e3)},0)},[E,d,o,u]),L=g.useCallback(c=>{m(c.target.value)},[]),i=g.useCallback(async()=>{const c=y.trim().length>0;if(c){const b={tx_id:d,vote:"downvote",explanation:y,...o&&{extra_metadata:o},...u&&{trigger_name:u}};try{P(!0),await E(b)}finally{P(!1)}}if(p(!1),m(n),A.current?.focus(),c){const b=document.createElement("div");b.setAttribute("aria-live","polite"),b.className="sr-only",b.textContent="Feedback submitted successfully.",document.body.appendChild(b),setTimeout(()=>document.body.removeChild(b),1e3)}},[E,y,n,d,o,u]),l=g.useCallback(c=>{if(c.key==="Escape")p(!1),m(n),A.current?.focus();else if((c.metaKey||c.ctrlKey)&&c.key==="Enter")c.preventDefault(),i().then(b=>{});else if(c.key==="Tab"&&f){const b=document.getElementById(D);if(b){const S=b.querySelectorAll('button, textarea, input, select, a[href], [tabindex]:not([tabindex="-1"])'),C=S[0],K=S[S.length-1];c.shiftKey&&document.activeElement===C?(c.preventDefault(),K?.focus()):!c.shiftKey&&document.activeElement===K&&(c.preventDefault(),C?.focus())}}},[i,f,D,n]),s={onFeedback:E,showPopover:f,setShowPopover:p,feedbackText:y,setFeedbackText:m,isSubmitting:R,setIsSubmitting:P,vote:x,handleUpvote:O,handleDownvote:N,handleTextareaChange:L,handleSubmit:i,handleKeyDown:l,textareaRef:w,triggerRef:A,popoverId:D,triggerId:v,tx_id:d,extra_metadata:o,trigger_name:u};return M.jsx(ce.Provider,{value:s,children:t})},UpvoteButton:({asChild:t,children:e,onClick:n,...r})=>{const{handleUpvote:o,isSubmitting:u,vote:d}=$(),f=g.useCallback(m=>{o(),n?.(m)},[o,n]),p={...r,onClick:f,disabled:u||r.disabled,"aria-label":r["aria-label"]||"Upvote feedback",type:"button"},y=d==="upvote";if(t){const m=typeof e=="function"?e({isSelected:y}):e;if(g.isValidElement(m))return g.cloneElement(m,q(p,m.props))}return M.jsx("button",{...p,children:typeof e=="function"?e({isSelected:y}):e})},DownvoteButton:({asChild:t,children:e,onClick:n,...r})=>{const{handleDownvote:o,showPopover:u,isSubmitting:d,popoverId:f,triggerId:p,triggerRef:y,vote:m}=$(),R=g.useCallback(h=>{o(),n?.(h)},[o,n]),P={...r,ref:y,onClick:R,disabled:d||r.disabled,"aria-label":r["aria-label"]||"Downvote feedback","aria-expanded":u,"aria-controls":f,id:p,type:"button"},x=m==="downvote";if(t){const h=typeof e=="function"?e({isSelected:x}):e;if(g.isValidElement(h))return g.cloneElement(h,q(P,h.props));if(h)return h}return M.jsx("button",{...P,children:typeof e=="function"?e({isSelected:x}):e})},Popover:({asChild:t,children:e,...n})=>{const{showPopover:r,handleKeyDown:o,popoverId:u,triggerId:d}=$();if(!r)return null;const f={...n,role:"dialog","aria-labelledby":d,"aria-modal":!0,"aria-describedby":`${u}-description`,id:u,onKeyDown:o,tabIndex:-1};return t&&g.isValidElement(e)?M.jsxs(M.Fragment,{children:[g.cloneElement(e,q(f,e.props)),M.jsx("div",{id:`${u}-description`,className:"sr-only",children:"Provide additional feedback for your downvote"})]}):M.jsxs("div",{...f,children:[M.jsx("div",{id:`${u}-description`,className:"sr-only",children:"Provide additional feedback for your downvote"}),e]})},Textarea:({asChild:t,value:e,onChange:n,...r})=>{const{feedbackText:o,handleTextareaChange:u,textareaRef:d,handleKeyDown:f,popoverId:p}=$(),y={...r,ref:d,value:e!==void 0?e:o,onChange:n||u,onKeyDown:f,placeholder:r.placeholder||"What did we miss?","aria-label":r["aria-label"]||"Additional feedback","aria-describedby":`${p}-help`,rows:r.rows||3};return t&&g.isValidElement(r.children)?g.cloneElement(r.children,q(y,r.children.props)):M.jsx("textarea",{...y})},SubmitButton:({asChild:t,children:e,onClick:n,...r})=>{const{handleSubmit:o,isSubmitting:u,feedbackText:d}=$(),f=g.useCallback(R=>{o(),n?.(R)},[o,n]),p=d.trim().length>0,y=p?"Submit feedback":"Close without feedback",m={...r,onClick:f,disabled:u||r.disabled,type:"button","aria-label":r["aria-label"]||y,"aria-describedby":p?void 0:"submit-help"};return t&&g.isValidElement(e)?M.jsxs(M.Fragment,{children:[g.cloneElement(e,q(m,e.props)),!p&&M.jsx("span",{id:"submit-help",className:"sr-only",children:"This will close the dialog without submitting feedback"})]}):M.jsxs("button",{...m,children:[e,!p&&M.jsx("span",{id:"submit-help",className:"sr-only",children:"This will close the dialog without submitting feedback"})]})}};var te={exports:{}},Se=te.exports,fe;function _e(){return fe||(fe=1,function(t,e){(function(n,r){var o=r(n);t.exports=o})(Se,function(n){var r=["N","E","A","D"];function o(i,l){i.super_=l,i.prototype=Object.create(l.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}})}function u(i,l){Object.defineProperty(this,"kind",{value:i,enumerable:!0}),l&&l.length&&Object.defineProperty(this,"path",{value:l,enumerable:!0})}function d(i,l,s){d.super_.call(this,"E",i),Object.defineProperty(this,"lhs",{value:l,enumerable:!0}),Object.defineProperty(this,"rhs",{value:s,enumerable:!0})}o(d,u);function f(i,l){f.super_.call(this,"N",i),Object.defineProperty(this,"rhs",{value:l,enumerable:!0})}o(f,u);function p(i,l){p.super_.call(this,"D",i),Object.defineProperty(this,"lhs",{value:l,enumerable:!0})}o(p,u);function y(i,l,s){y.super_.call(this,"A",i),Object.defineProperty(this,"index",{value:l,enumerable:!0}),Object.defineProperty(this,"item",{value:s,enumerable:!0})}o(y,u);function m(i,l,s){var c=i.slice(l+1||i.length);return i.length=l<0?i.length+l:l,i.push.apply(i,c),i}function R(i){var l=typeof i;return l!=="object"?l:i===Math?"math":i===null?"null":Array.isArray(i)?"array":Object.prototype.toString.call(i)==="[object Date]"?"date":typeof i.toString=="function"&&/^\/.*\//.test(i.toString())?"regexp":"object"}function P(i){var l=0;if(i.length===0)return l;for(var s=0;s<i.length;s++){var c=i.charCodeAt(s);l=(l<<5)-l+c,l=l&l}return l}function x(i){var l=0,s=R(i);if(s==="array"){i.forEach(function(K){l+=x(K)});var c="[type: array, hash: "+l+"]";return l+P(c)}if(s==="object"){for(var b in i)if(i.hasOwnProperty(b)){var S="[ type: object, key: "+b+", value hash: "+x(i[b])+"]";l+=P(S)}return l}var C="[ type: "+s+" ; value: "+i+"]";return l+P(C)}function h(i,l,s,c,b,S,C,K){s=s||[],b=b||[],C=C||[];var F=b.slice(0);if(typeof S<"u"&&S!==null){if(c){if(typeof c=="function"&&c(F,S))return;if(typeof c=="object"){if(c.prefilter&&c.prefilter(F,S))return;if(c.normalize){var B=c.normalize(F,S,i,l);B&&(i=B[0],l=B[1])}}}F.push(S)}R(i)==="regexp"&&R(l)==="regexp"&&(i=i.toString(),l=l.toString());var V=typeof i,re=typeof l,a,T,_,j,z=V!=="undefined"||C&&C.length>0&&C[C.length-1].lhs&&Object.getOwnPropertyDescriptor(C[C.length-1].lhs,S),Y=re!=="undefined"||C&&C.length>0&&C[C.length-1].rhs&&Object.getOwnPropertyDescriptor(C[C.length-1].rhs,S);if(!z&&Y)s.push(new f(F,l));else if(!Y&&z)s.push(new p(F,i));else if(R(i)!==R(l))s.push(new d(F,i,l));else if(R(i)==="date"&&i-l!==0)s.push(new d(F,i,l));else if(V==="object"&&i!==null&&l!==null){for(a=C.length-1;a>-1;--a)if(C[a].lhs===i){j=!0;break}if(j)i!==l&&s.push(new d(F,i,l));else{if(C.push({lhs:i,rhs:l}),Array.isArray(i)){for(K&&(i.sort(function(I,H){return x(I)-x(H)}),l.sort(function(I,H){return x(I)-x(H)})),a=l.length-1,T=i.length-1;a>T;)s.push(new y(F,a,new f(void 0,l[a--])));for(;T>a;)s.push(new y(F,T,new p(void 0,i[T--])));for(;a>=0;--a)h(i[a],l[a],s,c,F,a,C,K)}else{var G=Object.keys(i),J=Object.keys(l);for(a=0;a<G.length;++a)_=G[a],j=J.indexOf(_),j>=0?(h(i[_],l[_],s,c,F,_,C,K),J[j]=null):h(i[_],void 0,s,c,F,_,C,K);for(a=0;a<J.length;++a)_=J[a],_&&h(void 0,l[_],s,c,F,_,C,K)}C.length=C.length-1}}else i!==l&&(V==="number"&&isNaN(i)&&isNaN(l)||s.push(new d(F,i,l)))}function w(i,l,s,c,b){var S=[];if(h(i,l,S,c,null,null,null,b),s)for(var C=0;C<S.length;++C)s(S[C]);return S}function A(i,l,s,c,b,S,C){return h(i,l,s,c,b,S,C,!0)}function D(i,l,s,c){var b=c?function(C){C&&c.push(C)}:void 0,S=w(i,l,b,s);return c||(S.length?S:void 0)}function v(i,l,s,c){var b=c?function(C){C&&c.push(C)}:void 0,S=w(i,l,b,s,!0);return c||(S.length?S:void 0)}function k(i,l,s){if(s.path&&s.path.length){var c=i[l],b,S=s.path.length-1;for(b=0;b<S;b++)c=c[s.path[b]];switch(s.kind){case"A":k(c[s.path[b]],s.index,s.item);break;case"D":delete c[s.path[b]];break;case"E":case"N":c[s.path[b]]=s.rhs;break}}else switch(s.kind){case"A":k(i[l],s.index,s.item);break;case"D":i=m(i,l);break;case"E":case"N":i[l]=s.rhs;break}return i}function E(i,l,s){if(typeof s>"u"&&l&&~r.indexOf(l.kind)&&(s=l),i&&s&&s.kind){for(var c=i,b=-1,S=s.path?s.path.length-1:0;++b<S;)typeof c[s.path[b]]>"u"&&(c[s.path[b]]=typeof s.path[b+1]<"u"&&typeof s.path[b+1]=="number"?[]:{}),c=c[s.path[b]];switch(s.kind){case"A":s.path&&typeof c[s.path[b]]>"u"&&(c[s.path[b]]=[]),k(s.path?c[s.path[b]]:c,s.index,s.item);break;case"D":delete c[s.path[b]];break;case"E":case"N":c[s.path[b]]=s.rhs;break}}}function O(i,l,s){if(s.path&&s.path.length){var c=i[l],b,S=s.path.length-1;for(b=0;b<S;b++)c=c[s.path[b]];switch(s.kind){case"A":O(c[s.path[b]],s.index,s.item);break;case"D":c[s.path[b]]=s.lhs;break;case"E":c[s.path[b]]=s.lhs;break;case"N":delete c[s.path[b]];break}}else switch(s.kind){case"A":O(i[l],s.index,s.item);break;case"D":i[l]=s.lhs;break;case"E":i[l]=s.lhs;break;case"N":i=m(i,l);break}return i}function N(i,l,s){if(i&&l&&s&&s.kind){var c=i,b,S;for(S=s.path.length-1,b=0;b<S;b++)typeof c[s.path[b]]>"u"&&(c[s.path[b]]={}),c=c[s.path[b]];switch(s.kind){case"A":O(c[s.path[b]],s.index,s.item);break;case"D":c[s.path[b]]=s.lhs;break;case"E":c[s.path[b]]=s.lhs;break;case"N":delete c[s.path[b]];break}}}function L(i,l,s){if(i&&l){var c=function(b){(!s||s(i,l,b))&&E(i,l,b)};w(i,l,c)}}return Object.defineProperties(D,{diff:{value:D,enumerable:!0},orderIndependentDiff:{value:v,enumerable:!0},observableDiff:{value:w,enumerable:!0},orderIndependentObservableDiff:{value:A,enumerable:!0},orderIndepHash:{value:x,enumerable:!0},applyDiff:{value:L,enumerable:!0},applyChange:{value:E,enumerable:!0},revertChange:{value:N,enumerable:!0},isConflict:{value:function(){return typeof $conflict<"u"},enumerable:!0}}),D.DeepDiff=D,n&&(n.DeepDiff=D),D})}(te)),te.exports}var de=_e(),ne={exports:{}};const U=new Uint32Array(65536),je=(t,e)=>{const n=t.length,r=e.length,o=1<<n-1;let u=-1,d=0,f=n,p=n;for(;p--;)U[t.charCodeAt(p)]|=1<<p;for(p=0;p<r;p++){let y=U[e.charCodeAt(p)];const m=y|d;y|=(y&u)+u^u,d|=~(y|u),u&=y,d&o&&f++,u&o&&f--,d=d<<1|1,u=u<<1|~(m|d),d&=m}for(p=n;p--;)U[t.charCodeAt(p)]=0;return f},Ne=(t,e)=>{const n=e.length,r=t.length,o=[],u=[],d=Math.ceil(n/32),f=Math.ceil(r/32);for(let h=0;h<d;h++)u[h]=-1,o[h]=0;let p=0;for(;p<f-1;p++){let h=0,w=-1;const A=p*32,D=Math.min(32,r)+A;for(let v=A;v<D;v++)U[t.charCodeAt(v)]|=1<<v;for(let v=0;v<n;v++){const k=U[e.charCodeAt(v)],E=u[v/32|0]>>>v&1,O=o[v/32|0]>>>v&1,N=k|h,L=((k|O)&w)+w^w|k|O;let i=h|~(L|w),l=w&L;i>>>31^E&&(u[v/32|0]^=1<<v),l>>>31^O&&(o[v/32|0]^=1<<v),i=i<<1|E,l=l<<1|O,w=l|~(N|i),h=i&N}for(let v=A;v<D;v++)U[t.charCodeAt(v)]=0}let y=0,m=-1;const R=p*32,P=Math.min(32,r-R)+R;for(let h=R;h<P;h++)U[t.charCodeAt(h)]|=1<<h;let x=r;for(let h=0;h<n;h++){const w=U[e.charCodeAt(h)],A=u[h/32|0]>>>h&1,D=o[h/32|0]>>>h&1,v=w|y,k=((w|D)&m)+m^m|w|D;let E=y|~(k|m),O=m&k;x+=E>>>r-1&1,x-=O>>>r-1&1,E>>>31^A&&(u[h/32|0]^=1<<h),O>>>31^D&&(o[h/32|0]^=1<<h),E=E<<1|A,O=O<<1|D,m=O|~(v|E),y=E&v}for(let h=R;h<P;h++)U[t.charCodeAt(h)]=0;return x},pe=(t,e)=>{if(t.length<e.length){const n=e;e=t,t=n}return e.length===0?t.length:t.length<=32?je(t,e):Ne(t,e)},Ie=Pe(Object.freeze(Object.defineProperty({__proto__:null,closest:(t,e)=>{let n=1/0,r=0;for(let o=0;o<e.length;o++){const u=pe(t,e[o]);u<n&&(n=u,r=o)}return e[r]},distance:pe},Symbol.toStringTag,{value:"Module"})));var he;function Fe(){return he||(he=1,function(t,e){(function(){var n;try{n=typeof Intl<"u"&&typeof Intl.Collator<"u"?Intl.Collator("generic",{sensitivity:"base"}):null}catch{console.log("Collator could not be initialized and wouldn't be used")}var r=Ie,o=[],u=[],d={get:function(f,p,y){var m=y&&n&&y.useCollator;if(m){var R=f.length,P=p.length;if(R===0)return P;if(P===0)return R;var x,h,w,A,D;for(w=0;w<P;++w)o[w]=w,u[w]=p.charCodeAt(w);o[P]=P;var v;for(w=0;w<R;++w){for(h=w+1,A=0;A<P;++A)x=h,v=n.compare(f.charAt(w),String.fromCharCode(u[A]))===0,h=o[A]+(v?0:1),D=x+1,h>D&&(h=D),D=o[A+1]+1,h>D&&(h=D),o[A]=x;o[A]=h}return h}return r.distance(f,p)}};t!==null&&t.exports===e?t.exports=d:typeof self<"u"&&typeof self.postMessage=="function"&&typeof self.importScripts=="function"?self.Levenshtein=d:typeof window<"u"&&window!==null&&(window.Levenshtein=d)})()}(ne,ne.exports)),ne.exports}var Le=Fe();const Me=Ee(Le);class We{diff(e,n,r={}){let o;typeof r=="function"?(o=r,r={}):"callback"in r&&(o=r.callback);const u=this.castInput(e,r),d=this.castInput(n,r),f=this.removeEmpty(this.tokenize(u,r)),p=this.removeEmpty(this.tokenize(d,r));return this.diffWithOptionsObj(f,p,r,o)}diffWithOptionsObj(e,n,r,o){var u;const d=v=>{if(v=this.postProcess(v,r),o){setTimeout(function(){o(v)},0);return}else return v},f=n.length,p=e.length;let y=1,m=f+p;r.maxEditLength!=null&&(m=Math.min(m,r.maxEditLength));const R=(u=r.timeout)!==null&&u!==void 0?u:1/0,P=Date.now()+R,x=[{oldPos:-1,lastComponent:void 0}];let h=this.extractCommon(x[0],n,e,0,r);if(x[0].oldPos+1>=p&&h+1>=f)return d(this.buildValues(x[0].lastComponent,n,e));let w=-1/0,A=1/0;const D=()=>{for(let v=Math.max(w,-y);v<=Math.min(A,y);v+=2){let k;const E=x[v-1],O=x[v+1];E&&(x[v-1]=void 0);let N=!1;if(O){const i=O.oldPos-v;N=O&&0<=i&&i<f}const L=E&&E.oldPos+1<p;if(!N&&!L){x[v]=void 0;continue}if(!L||N&&E.oldPos<O.oldPos?k=this.addToPath(O,!0,!1,0,r):k=this.addToPath(E,!1,!0,1,r),h=this.extractCommon(k,n,e,v,r),k.oldPos+1>=p&&h+1>=f)return d(this.buildValues(k.lastComponent,n,e))||!0;x[v]=k,k.oldPos+1>=p&&(A=Math.min(A,v-1)),h+1>=f&&(w=Math.max(w,v+1))}y++};if(o)(function v(){setTimeout(function(){if(y>m||Date.now()>P)return o(void 0);D()||v()},0)})();else for(;y<=m&&Date.now()<=P;){const v=D();if(v)return v}}addToPath(e,n,r,o,u){const d=e.lastComponent;return d&&!u.oneChangePerToken&&d.added===n&&d.removed===r?{oldPos:e.oldPos+o,lastComponent:{count:d.count+1,added:n,removed:r,previousComponent:d.previousComponent}}:{oldPos:e.oldPos+o,lastComponent:{count:1,added:n,removed:r,previousComponent:d}}}extractCommon(e,n,r,o,u){const d=n.length,f=r.length;let p=e.oldPos,y=p-o,m=0;for(;y+1<d&&p+1<f&&this.equals(r[p+1],n[y+1],u);)y++,p++,m++,u.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return m&&!u.oneChangePerToken&&(e.lastComponent={count:m,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=p,y}equals(e,n,r){return r.comparator?r.comparator(e,n):e===n||!!r.ignoreCase&&e.toLowerCase()===n.toLowerCase()}removeEmpty(e){const n=[];for(let r=0;r<e.length;r++)e[r]&&n.push(e[r]);return n}castInput(e,n){return e}tokenize(e,n){return Array.from(e)}join(e){return e.join("")}postProcess(e,n){return e}get useLongestToken(){return!1}buildValues(e,n,r){const o=[];let u;for(;e;)o.push(e),u=e.previousComponent,delete e.previousComponent,e=u;o.reverse();const d=o.length;let f=0,p=0,y=0;for(;f<d;f++){const m=o[f];if(m.removed)m.value=this.join(r.slice(y,y+m.count)),y+=m.count;else{if(!m.added&&this.useLongestToken){let R=n.slice(p,p+m.count);R=R.map(function(P,x){const h=r[y+x];return h.length>P.length?h:P}),m.value=this.join(R)}else m.value=this.join(n.slice(p,p+m.count));p+=m.count,m.added||(y+=m.count)}}return o}}class Ke extends We{constructor(){super(...arguments),this.tokenize=ze}equals(e,n,r){return r.ignoreWhitespace?((!r.newlineIsToken||!e.includes(`
22
+ <%s key={someKey} {...props} />`,j,F,H,F),re[F+j]=!0)}if(F=null,S!==void 0&&(n(S),F=""+S),p(T)&&(n(T.key),F=""+T.key),"key"in T){S={};for(var se in T)se!=="key"&&(S[se]=T[se])}else S=T;return F&&f(S,typeof a=="function"?a.displayName||a.name||"Unknown":a),y(a,F,Y,z,o(),S,G,B)}function D(a){typeof a=="object"&&a!==null&&a.$$typeof===P&&a._store&&(a._store.validated=1)}var k=g,P=Symbol.for("react.transitional.element"),h=Symbol.for("react.portal"),w=Symbol.for("react.fragment"),R=Symbol.for("react.strict_mode"),A=Symbol.for("react.profiler"),b=Symbol.for("react.consumer"),O=Symbol.for("react.context"),E=Symbol.for("react.forward_ref"),x=Symbol.for("react.suspense"),N=Symbol.for("react.suspense_list"),I=Symbol.for("react.memo"),i=Symbol.for("react.lazy"),l=Symbol.for("react.activity"),s=Symbol.for("react.client.reference"),d=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,v=Object.prototype.hasOwnProperty,_=Array.isArray,C=console.createTask?console.createTask:function(){return null};k={react_stack_bottom_frame:function(a){return a()}};var K,L={},J=k.react_stack_bottom_frame.bind(k,u)(),V=C(r(u)),re={};Z.Fragment=w,Z.jsx=function(a,T,S,j,z){var Y=1e4>d.recentlyCreatedOwnerStacks++;return m(a,T,S,!1,j,z,Y?Error("react-stack-top-frame"):J,Y?C(r(a)):V)},Z.jsxs=function(a,T,S,j,z){var Y=1e4>d.recentlyCreatedOwnerStacks++;return m(a,T,S,!0,j,z,Y?Error("react-stack-top-frame"):J,Y?C(r(a)):V)}}()),Z}var ue;function Te(){return ue||(ue=1,process.env.NODE_ENV==="production"?ee.exports=xe():ee.exports=Ce()),ee.exports}var M=Te();const Q=g.createContext(null),Re="https://api.kelet.ai/api",Oe=()=>{const t=g.useContext(Q);if(!t)throw new Error("useKelet must be used within a KeletProvider");return t},oe=()=>{const t=g.useContext(Q);return t?t.feedback:(console.warn("No FeedbackHandler found: defaultFeedbackHandler is not possible since there's no KeletProvider wrapping this call, and handler not provided"),async()=>{})},De=({apiKey:t,project:e,baseUrl:n,children:r})=>{const o=g.useContext(Q),u=t||o?.api_key;if(!u)throw new Error("apiKey is required either directly or from a parent KeletProvider");const f={api_key:u,project:e,feedback:async c=>{const m=`${n||Re}/projects/${e}/feedback`,D={tx_id:c.tx_id,source:c.source||"EXPLICIT",vote:c.vote,explanation:c.explanation,correction:c.correction,selection:c.selection},k=await fetch(m,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${u}`},body:JSON.stringify(D)});if(!k.ok)throw new Error(`Failed to submit feedback: ${k.statusText}`)}};return M.jsx(Q.Provider,{value:f,children:r})},q=(t,e)=>{const n={...e};for(const r in e){const o=t[r],u=e[r];/^on[A-Z]/.test(r)?o&&u?n[r]=(...f)=>{u(...f),o(...f)}:o&&(n[r]=o):r==="style"?n[r]={...o,...u}:r==="className"?n[r]=[o,u].filter(Boolean).join(" "):n[r]=u!==void 0?u:o}return{...t,...n}},fe=g.createContext(null),$=()=>{const t=g.useContext(fe);if(!t)throw new Error("VoteFeedback components must be used within VoteFeedback.Root");return t},Ae={Root:({children:t,onFeedback:e,defaultText:n="",tx_id:r,extra_metadata:o,trigger_name:u})=>{const p=typeof r=="function"?r():r,[f,c]=g.useState(!1),[y,m]=g.useState(n),[D,k]=g.useState(!1),[P,h]=g.useState(null),w=g.useRef(null),R=g.useRef(null),A=g.useId(),b=g.useId(),O=oe(),E=e||O;g.useEffect(()=>{c(!1),m(n),k(!1),h(null),setTimeout(()=>R.current?.focus(),0)},[p,n]);const x=g.useCallback(async()=>{h("upvote");const d={tx_id:p,vote:"upvote",...o&&{extra_metadata:o},...u&&{trigger_name:u}};try{k(!0),await E(d)}finally{k(!1)}},[E,p,o,u]),N=g.useCallback(async()=>{if(h("downvote"),E){const d={tx_id:p,vote:"downvote",...o&&{extra_metadata:o},...u&&{trigger_name:u}};try{k(!0),await E(d)}finally{k(!1)}}c(!0),setTimeout(()=>{w.current?.focus();const d=document.createElement("div");d.setAttribute("aria-live","polite"),d.setAttribute("aria-atomic","true"),d.className="sr-only",d.textContent="Feedback dialog opened. You can provide additional details about your downvote.",document.body.appendChild(d),setTimeout(()=>document.body.removeChild(d),1e3)},0)},[E,p,o,u]),I=g.useCallback(d=>{m(d.target.value)},[]),i=g.useCallback(async()=>{const d=y.trim().length>0;if(d){const v={tx_id:p,vote:"downvote",explanation:y,...o&&{extra_metadata:o},...u&&{trigger_name:u}};try{k(!0),await E(v)}finally{k(!1)}}if(c(!1),m(n),R.current?.focus(),d){const v=document.createElement("div");v.setAttribute("aria-live","polite"),v.className="sr-only",v.textContent="Feedback submitted successfully.",document.body.appendChild(v),setTimeout(()=>document.body.removeChild(v),1e3)}},[E,y,n,p,o,u]),l=g.useCallback(d=>{if(d.key==="Escape")c(!1),m(n),R.current?.focus();else if((d.metaKey||d.ctrlKey)&&d.key==="Enter")d.preventDefault(),i().then(v=>{});else if(d.key==="Tab"&&f){const v=document.getElementById(A);if(v){const _=v.querySelectorAll('button, textarea, input, select, a[href], [tabindex]:not([tabindex="-1"])'),C=_[0],K=_[_.length-1];d.shiftKey&&document.activeElement===C?(d.preventDefault(),K?.focus()):!d.shiftKey&&document.activeElement===K&&(d.preventDefault(),C?.focus())}}},[i,f,A,n]),s={onFeedback:E,showPopover:f,setShowPopover:c,feedbackText:y,setFeedbackText:m,isSubmitting:D,setIsSubmitting:k,vote:P,handleUpvote:x,handleDownvote:N,handleTextareaChange:I,handleSubmit:i,handleKeyDown:l,textareaRef:w,triggerRef:R,popoverId:A,triggerId:b,tx_id:p,extra_metadata:o,trigger_name:u};return M.jsx(fe.Provider,{value:s,children:t})},UpvoteButton:({asChild:t,children:e,onClick:n,...r})=>{const{handleUpvote:o,isSubmitting:u,vote:p}=$(),f=g.useCallback(m=>{o(),n?.(m)},[o,n]),c={...r,onClick:f,disabled:u||r.disabled,"aria-label":r["aria-label"]||"Upvote feedback",type:"button"},y=p==="upvote";if(t){const m=typeof e=="function"?e({isSelected:y}):e;if(g.isValidElement(m))return g.cloneElement(m,q(c,m.props))}return M.jsx("button",{...c,children:typeof e=="function"?e({isSelected:y}):e})},DownvoteButton:({asChild:t,children:e,onClick:n,...r})=>{const{handleDownvote:o,showPopover:u,isSubmitting:p,popoverId:f,triggerId:c,triggerRef:y,vote:m}=$(),D=g.useCallback(h=>{o(),n?.(h)},[o,n]),k={...r,ref:y,onClick:D,disabled:p||r.disabled,"aria-label":r["aria-label"]||"Downvote feedback","aria-expanded":u,"aria-controls":f,id:c,type:"button"},P=m==="downvote";if(t){const h=typeof e=="function"?e({isSelected:P}):e;if(g.isValidElement(h))return g.cloneElement(h,q(k,h.props));if(h)return h}return M.jsx("button",{...k,children:typeof e=="function"?e({isSelected:P}):e})},Popover:({asChild:t,children:e,...n})=>{const{showPopover:r,handleKeyDown:o,popoverId:u,triggerId:p}=$();if(!r)return null;const f={...n,role:"dialog","aria-labelledby":p,"aria-modal":!0,"aria-describedby":`${u}-description`,id:u,onKeyDown:o,tabIndex:-1};return t&&g.isValidElement(e)?M.jsxs(M.Fragment,{children:[g.cloneElement(e,q(f,e.props)),M.jsx("div",{id:`${u}-description`,className:"sr-only",children:"Provide additional feedback for your downvote"})]}):M.jsxs("div",{...f,children:[M.jsx("div",{id:`${u}-description`,className:"sr-only",children:"Provide additional feedback for your downvote"}),e]})},Textarea:({asChild:t,value:e,onChange:n,...r})=>{const{feedbackText:o,handleTextareaChange:u,textareaRef:p,handleKeyDown:f,popoverId:c}=$(),y={...r,ref:p,value:e!==void 0?e:o,onChange:n||u,onKeyDown:f,placeholder:r.placeholder||"What did we miss?","aria-label":r["aria-label"]||"Additional feedback","aria-describedby":`${c}-help`,rows:r.rows||3};return t&&g.isValidElement(r.children)?g.cloneElement(r.children,q(y,r.children.props)):M.jsx("textarea",{...y})},SubmitButton:({asChild:t,children:e,onClick:n,...r})=>{const{handleSubmit:o,isSubmitting:u,feedbackText:p}=$(),f=g.useCallback(D=>{o(),n?.(D)},[o,n]),c=p.trim().length>0,y=c?"Submit feedback":"Close without feedback",m={...r,onClick:f,disabled:u||r.disabled,type:"button","aria-label":r["aria-label"]||y,"aria-describedby":c?void 0:"submit-help"};return t&&g.isValidElement(e)?M.jsxs(M.Fragment,{children:[g.cloneElement(e,q(m,e.props)),!c&&M.jsx("span",{id:"submit-help",className:"sr-only",children:"This will close the dialog without submitting feedback"})]}):M.jsxs("button",{...m,children:[e,!c&&M.jsx("span",{id:"submit-help",className:"sr-only",children:"This will close the dialog without submitting feedback"})]})}};var te={exports:{}},_e=te.exports,ce;function Se(){return ce||(ce=1,function(t,e){(function(n,r){var o=r(n);t.exports=o})(_e,function(n){var r=["N","E","A","D"];function o(i,l){i.super_=l,i.prototype=Object.create(l.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}})}function u(i,l){Object.defineProperty(this,"kind",{value:i,enumerable:!0}),l&&l.length&&Object.defineProperty(this,"path",{value:l,enumerable:!0})}function p(i,l,s){p.super_.call(this,"E",i),Object.defineProperty(this,"lhs",{value:l,enumerable:!0}),Object.defineProperty(this,"rhs",{value:s,enumerable:!0})}o(p,u);function f(i,l){f.super_.call(this,"N",i),Object.defineProperty(this,"rhs",{value:l,enumerable:!0})}o(f,u);function c(i,l){c.super_.call(this,"D",i),Object.defineProperty(this,"lhs",{value:l,enumerable:!0})}o(c,u);function y(i,l,s){y.super_.call(this,"A",i),Object.defineProperty(this,"index",{value:l,enumerable:!0}),Object.defineProperty(this,"item",{value:s,enumerable:!0})}o(y,u);function m(i,l,s){var d=i.slice(l+1||i.length);return i.length=l<0?i.length+l:l,i.push.apply(i,d),i}function D(i){var l=typeof i;return l!=="object"?l:i===Math?"math":i===null?"null":Array.isArray(i)?"array":Object.prototype.toString.call(i)==="[object Date]"?"date":typeof i.toString=="function"&&/^\/.*\//.test(i.toString())?"regexp":"object"}function k(i){var l=0;if(i.length===0)return l;for(var s=0;s<i.length;s++){var d=i.charCodeAt(s);l=(l<<5)-l+d,l=l&l}return l}function P(i){var l=0,s=D(i);if(s==="array"){i.forEach(function(K){l+=P(K)});var d="[type: array, hash: "+l+"]";return l+k(d)}if(s==="object"){for(var v in i)if(i.hasOwnProperty(v)){var _="[ type: object, key: "+v+", value hash: "+P(i[v])+"]";l+=k(_)}return l}var C="[ type: "+s+" ; value: "+i+"]";return l+k(C)}function h(i,l,s,d,v,_,C,K){s=s||[],v=v||[],C=C||[];var L=v.slice(0);if(typeof _<"u"&&_!==null){if(d){if(typeof d=="function"&&d(L,_))return;if(typeof d=="object"){if(d.prefilter&&d.prefilter(L,_))return;if(d.normalize){var J=d.normalize(L,_,i,l);J&&(i=J[0],l=J[1])}}}L.push(_)}D(i)==="regexp"&&D(l)==="regexp"&&(i=i.toString(),l=l.toString());var V=typeof i,re=typeof l,a,T,S,j,z=V!=="undefined"||C&&C.length>0&&C[C.length-1].lhs&&Object.getOwnPropertyDescriptor(C[C.length-1].lhs,_),Y=re!=="undefined"||C&&C.length>0&&C[C.length-1].rhs&&Object.getOwnPropertyDescriptor(C[C.length-1].rhs,_);if(!z&&Y)s.push(new f(L,l));else if(!Y&&z)s.push(new c(L,i));else if(D(i)!==D(l))s.push(new p(L,i,l));else if(D(i)==="date"&&i-l!==0)s.push(new p(L,i,l));else if(V==="object"&&i!==null&&l!==null){for(a=C.length-1;a>-1;--a)if(C[a].lhs===i){j=!0;break}if(j)i!==l&&s.push(new p(L,i,l));else{if(C.push({lhs:i,rhs:l}),Array.isArray(i)){for(K&&(i.sort(function(F,H){return P(F)-P(H)}),l.sort(function(F,H){return P(F)-P(H)})),a=l.length-1,T=i.length-1;a>T;)s.push(new y(L,a,new f(void 0,l[a--])));for(;T>a;)s.push(new y(L,T,new c(void 0,i[T--])));for(;a>=0;--a)h(i[a],l[a],s,d,L,a,C,K)}else{var G=Object.keys(i),B=Object.keys(l);for(a=0;a<G.length;++a)S=G[a],j=B.indexOf(S),j>=0?(h(i[S],l[S],s,d,L,S,C,K),B[j]=null):h(i[S],void 0,s,d,L,S,C,K);for(a=0;a<B.length;++a)S=B[a],S&&h(void 0,l[S],s,d,L,S,C,K)}C.length=C.length-1}}else i!==l&&(V==="number"&&isNaN(i)&&isNaN(l)||s.push(new p(L,i,l)))}function w(i,l,s,d,v){var _=[];if(h(i,l,_,d,null,null,null,v),s)for(var C=0;C<_.length;++C)s(_[C]);return _}function R(i,l,s,d,v,_,C){return h(i,l,s,d,v,_,C,!0)}function A(i,l,s,d){var v=d?function(C){C&&d.push(C)}:void 0,_=w(i,l,v,s);return d||(_.length?_:void 0)}function b(i,l,s,d){var v=d?function(C){C&&d.push(C)}:void 0,_=w(i,l,v,s,!0);return d||(_.length?_:void 0)}function O(i,l,s){if(s.path&&s.path.length){var d=i[l],v,_=s.path.length-1;for(v=0;v<_;v++)d=d[s.path[v]];switch(s.kind){case"A":O(d[s.path[v]],s.index,s.item);break;case"D":delete d[s.path[v]];break;case"E":case"N":d[s.path[v]]=s.rhs;break}}else switch(s.kind){case"A":O(i[l],s.index,s.item);break;case"D":i=m(i,l);break;case"E":case"N":i[l]=s.rhs;break}return i}function E(i,l,s){if(typeof s>"u"&&l&&~r.indexOf(l.kind)&&(s=l),i&&s&&s.kind){for(var d=i,v=-1,_=s.path?s.path.length-1:0;++v<_;)typeof d[s.path[v]]>"u"&&(d[s.path[v]]=typeof s.path[v+1]<"u"&&typeof s.path[v+1]=="number"?[]:{}),d=d[s.path[v]];switch(s.kind){case"A":s.path&&typeof d[s.path[v]]>"u"&&(d[s.path[v]]=[]),O(s.path?d[s.path[v]]:d,s.index,s.item);break;case"D":delete d[s.path[v]];break;case"E":case"N":d[s.path[v]]=s.rhs;break}}}function x(i,l,s){if(s.path&&s.path.length){var d=i[l],v,_=s.path.length-1;for(v=0;v<_;v++)d=d[s.path[v]];switch(s.kind){case"A":x(d[s.path[v]],s.index,s.item);break;case"D":d[s.path[v]]=s.lhs;break;case"E":d[s.path[v]]=s.lhs;break;case"N":delete d[s.path[v]];break}}else switch(s.kind){case"A":x(i[l],s.index,s.item);break;case"D":i[l]=s.lhs;break;case"E":i[l]=s.lhs;break;case"N":i=m(i,l);break}return i}function N(i,l,s){if(i&&l&&s&&s.kind){var d=i,v,_;for(_=s.path.length-1,v=0;v<_;v++)typeof d[s.path[v]]>"u"&&(d[s.path[v]]={}),d=d[s.path[v]];switch(s.kind){case"A":x(d[s.path[v]],s.index,s.item);break;case"D":d[s.path[v]]=s.lhs;break;case"E":d[s.path[v]]=s.lhs;break;case"N":delete d[s.path[v]];break}}}function I(i,l,s){if(i&&l){var d=function(v){(!s||s(i,l,v))&&E(i,l,v)};w(i,l,d)}}return Object.defineProperties(A,{diff:{value:A,enumerable:!0},orderIndependentDiff:{value:b,enumerable:!0},observableDiff:{value:w,enumerable:!0},orderIndependentObservableDiff:{value:R,enumerable:!0},orderIndepHash:{value:P,enumerable:!0},applyDiff:{value:I,enumerable:!0},applyChange:{value:E,enumerable:!0},revertChange:{value:N,enumerable:!0},isConflict:{value:function(){return typeof $conflict<"u"},enumerable:!0}}),A.DeepDiff=A,n&&(n.DeepDiff=A),A})}(te)),te.exports}var de=Se(),ne={exports:{}};const U=new Uint32Array(65536),je=(t,e)=>{const n=t.length,r=e.length,o=1<<n-1;let u=-1,p=0,f=n,c=n;for(;c--;)U[t.charCodeAt(c)]|=1<<c;for(c=0;c<r;c++){let y=U[e.charCodeAt(c)];const m=y|p;y|=(y&u)+u^u,p|=~(y|u),u&=y,p&o&&f++,u&o&&f--,p=p<<1|1,u=u<<1|~(m|p),p&=m}for(c=n;c--;)U[t.charCodeAt(c)]=0;return f},Ne=(t,e)=>{const n=e.length,r=t.length,o=[],u=[],p=Math.ceil(n/32),f=Math.ceil(r/32);for(let h=0;h<p;h++)u[h]=-1,o[h]=0;let c=0;for(;c<f-1;c++){let h=0,w=-1;const R=c*32,A=Math.min(32,r)+R;for(let b=R;b<A;b++)U[t.charCodeAt(b)]|=1<<b;for(let b=0;b<n;b++){const O=U[e.charCodeAt(b)],E=u[b/32|0]>>>b&1,x=o[b/32|0]>>>b&1,N=O|h,I=((O|x)&w)+w^w|O|x;let i=h|~(I|w),l=w&I;i>>>31^E&&(u[b/32|0]^=1<<b),l>>>31^x&&(o[b/32|0]^=1<<b),i=i<<1|E,l=l<<1|x,w=l|~(N|i),h=i&N}for(let b=R;b<A;b++)U[t.charCodeAt(b)]=0}let y=0,m=-1;const D=c*32,k=Math.min(32,r-D)+D;for(let h=D;h<k;h++)U[t.charCodeAt(h)]|=1<<h;let P=r;for(let h=0;h<n;h++){const w=U[e.charCodeAt(h)],R=u[h/32|0]>>>h&1,A=o[h/32|0]>>>h&1,b=w|y,O=((w|A)&m)+m^m|w|A;let E=y|~(O|m),x=m&O;P+=E>>>r-1&1,P-=x>>>r-1&1,E>>>31^R&&(u[h/32|0]^=1<<h),x>>>31^A&&(o[h/32|0]^=1<<h),E=E<<1|R,x=x<<1|A,m=x|~(b|E),y=E&b}for(let h=D;h<k;h++)U[t.charCodeAt(h)]=0;return P},pe=(t,e)=>{if(t.length<e.length){const n=e;e=t,t=n}return e.length===0?t.length:t.length<=32?je(t,e):Ne(t,e)},Ie=Pe(Object.freeze(Object.defineProperty({__proto__:null,closest:(t,e)=>{let n=1/0,r=0;for(let o=0;o<e.length;o++){const u=pe(t,e[o]);u<n&&(n=u,r=o)}return e[r]},distance:pe},Symbol.toStringTag,{value:"Module"})));var he;function Fe(){return he||(he=1,function(t,e){(function(){var n;try{n=typeof Intl<"u"&&typeof Intl.Collator<"u"?Intl.Collator("generic",{sensitivity:"base"}):null}catch{console.log("Collator could not be initialized and wouldn't be used")}var r=Ie,o=[],u=[],p={get:function(f,c,y){var m=y&&n&&y.useCollator;if(m){var D=f.length,k=c.length;if(D===0)return k;if(k===0)return D;var P,h,w,R,A;for(w=0;w<k;++w)o[w]=w,u[w]=c.charCodeAt(w);o[k]=k;var b;for(w=0;w<D;++w){for(h=w+1,R=0;R<k;++R)P=h,b=n.compare(f.charAt(w),String.fromCharCode(u[R]))===0,h=o[R]+(b?0:1),A=P+1,h>A&&(h=A),A=o[R+1]+1,h>A&&(h=A),o[R]=P;o[R]=h}return h}return r.distance(f,c)}};t!==null&&t.exports===e?t.exports=p:typeof self<"u"&&typeof self.postMessage=="function"&&typeof self.importScripts=="function"?self.Levenshtein=p:typeof window<"u"&&window!==null&&(window.Levenshtein=p)})()}(ne,ne.exports)),ne.exports}var Le=Fe();const Me=Ee(Le);class We{diff(e,n,r={}){let o;typeof r=="function"?(o=r,r={}):"callback"in r&&(o=r.callback);const u=this.castInput(e,r),p=this.castInput(n,r),f=this.removeEmpty(this.tokenize(u,r)),c=this.removeEmpty(this.tokenize(p,r));return this.diffWithOptionsObj(f,c,r,o)}diffWithOptionsObj(e,n,r,o){var u;const p=b=>{if(b=this.postProcess(b,r),o){setTimeout(function(){o(b)},0);return}else return b},f=n.length,c=e.length;let y=1,m=f+c;r.maxEditLength!=null&&(m=Math.min(m,r.maxEditLength));const D=(u=r.timeout)!==null&&u!==void 0?u:1/0,k=Date.now()+D,P=[{oldPos:-1,lastComponent:void 0}];let h=this.extractCommon(P[0],n,e,0,r);if(P[0].oldPos+1>=c&&h+1>=f)return p(this.buildValues(P[0].lastComponent,n,e));let w=-1/0,R=1/0;const A=()=>{for(let b=Math.max(w,-y);b<=Math.min(R,y);b+=2){let O;const E=P[b-1],x=P[b+1];E&&(P[b-1]=void 0);let N=!1;if(x){const i=x.oldPos-b;N=x&&0<=i&&i<f}const I=E&&E.oldPos+1<c;if(!N&&!I){P[b]=void 0;continue}if(!I||N&&E.oldPos<x.oldPos?O=this.addToPath(x,!0,!1,0,r):O=this.addToPath(E,!1,!0,1,r),h=this.extractCommon(O,n,e,b,r),O.oldPos+1>=c&&h+1>=f)return p(this.buildValues(O.lastComponent,n,e))||!0;P[b]=O,O.oldPos+1>=c&&(R=Math.min(R,b-1)),h+1>=f&&(w=Math.max(w,b+1))}y++};if(o)(function b(){setTimeout(function(){if(y>m||Date.now()>k)return o(void 0);A()||b()},0)})();else for(;y<=m&&Date.now()<=k;){const b=A();if(b)return b}}addToPath(e,n,r,o,u){const p=e.lastComponent;return p&&!u.oneChangePerToken&&p.added===n&&p.removed===r?{oldPos:e.oldPos+o,lastComponent:{count:p.count+1,added:n,removed:r,previousComponent:p.previousComponent}}:{oldPos:e.oldPos+o,lastComponent:{count:1,added:n,removed:r,previousComponent:p}}}extractCommon(e,n,r,o,u){const p=n.length,f=r.length;let c=e.oldPos,y=c-o,m=0;for(;y+1<p&&c+1<f&&this.equals(r[c+1],n[y+1],u);)y++,c++,m++,u.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return m&&!u.oneChangePerToken&&(e.lastComponent={count:m,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=c,y}equals(e,n,r){return r.comparator?r.comparator(e,n):e===n||!!r.ignoreCase&&e.toLowerCase()===n.toLowerCase()}removeEmpty(e){const n=[];for(let r=0;r<e.length;r++)e[r]&&n.push(e[r]);return n}castInput(e,n){return e}tokenize(e,n){return Array.from(e)}join(e){return e.join("")}postProcess(e,n){return e}get useLongestToken(){return!1}buildValues(e,n,r){const o=[];let u;for(;e;)o.push(e),u=e.previousComponent,delete e.previousComponent,e=u;o.reverse();const p=o.length;let f=0,c=0,y=0;for(;f<p;f++){const m=o[f];if(m.removed)m.value=this.join(r.slice(y,y+m.count)),y+=m.count;else{if(!m.added&&this.useLongestToken){let D=n.slice(c,c+m.count);D=D.map(function(k,P){const h=r[y+P];return h.length>k.length?h:k}),m.value=this.join(D)}else m.value=this.join(n.slice(c,c+m.count));c+=m.count,m.added||(y+=m.count)}}return o}}class Ke extends We{constructor(){super(...arguments),this.tokenize=ze}equals(e,n,r){return r.ignoreWhitespace?((!r.newlineIsToken||!e.includes(`
23
23
  `))&&(e=e.trim()),(!r.newlineIsToken||!n.includes(`
24
24
  `))&&(n=n.trim())):r.ignoreNewlineAtEof&&!r.newlineIsToken&&(e.endsWith(`
25
25
  `)&&(e=e.slice(0,-1)),n.endsWith(`
26
26
  `)&&(n=n.slice(0,-1))),super.equals(e,n,r)}}const Ye=new Ke;function me(t,e,n){return Ye.diff(t,e,n)}function ze(t,e){e.stripTrailingCr&&(t=t.replace(/\r\n/g,`
27
- `));const n=[],r=t.split(/(\n|\r\n)/);r[r.length-1]||r.pop();for(let o=0;o<r.length;o++){const u=r[o];o%2&&!e.newlineIsToken?n[n.length-1]+=u:n.push(u)}return n}function be(t,e,n,r,o,u,d){let f;d?typeof d=="function"?f={callback:d}:f=d:f={},typeof f.context>"u"&&(f.context=4);const p=f.context;if(f.newlineIsToken)throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");if(f.callback){const{callback:m}=f;me(n,r,Object.assign(Object.assign({},f),{callback:R=>{const P=y(R);m(P)}}))}else return y(me(n,r,f));function y(m){if(!m)return;m.push({value:"",lines:[]});function R(v){return v.map(function(k){return" "+k})}const P=[];let x=0,h=0,w=[],A=1,D=1;for(let v=0;v<m.length;v++){const k=m[v],E=k.lines||Ue(k.value);if(k.lines=E,k.added||k.removed){if(!x){const O=m[v-1];x=A,h=D,O&&(w=p>0?R(O.lines.slice(-p)):[],x-=w.length,h-=w.length)}for(const O of E)w.push((k.added?"+":"-")+O);k.added?D+=E.length:A+=E.length}else{if(x)if(E.length<=p*2&&v<m.length-2)for(const O of R(E))w.push(O);else{const O=Math.min(E.length,p);for(const L of R(E.slice(0,O)))w.push(L);const N={oldStart:x,oldLines:A-x+O,newStart:h,newLines:D-h+O,lines:w};P.push(N),x=0,h=0,w=[]}A+=E.length,D+=E.length}}for(const v of P)for(let k=0;k<v.lines.length;k++)v.lines[k].endsWith(`
28
- `)?v.lines[k]=v.lines[k].slice(0,-1):(v.lines.splice(k+1,0,"\"),k++);return{oldFileName:t,newFileName:e,oldHeader:o,newHeader:u,hunks:P}}}function ie(t){if(Array.isArray(t))return t.map(ie).join(`
27
+ `));const n=[],r=t.split(/(\n|\r\n)/);r[r.length-1]||r.pop();for(let o=0;o<r.length;o++){const u=r[o];o%2&&!e.newlineIsToken?n[n.length-1]+=u:n.push(u)}return n}function be(t,e,n,r,o,u,p){let f;p?typeof p=="function"?f={callback:p}:f=p:f={},typeof f.context>"u"&&(f.context=4);const c=f.context;if(f.newlineIsToken)throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");if(f.callback){const{callback:m}=f;me(n,r,Object.assign(Object.assign({},f),{callback:D=>{const k=y(D);m(k)}}))}else return y(me(n,r,f));function y(m){if(!m)return;m.push({value:"",lines:[]});function D(b){return b.map(function(O){return" "+O})}const k=[];let P=0,h=0,w=[],R=1,A=1;for(let b=0;b<m.length;b++){const O=m[b],E=O.lines||Ue(O.value);if(O.lines=E,O.added||O.removed){if(!P){const x=m[b-1];P=R,h=A,x&&(w=c>0?D(x.lines.slice(-c)):[],P-=w.length,h-=w.length)}for(const x of E)w.push((O.added?"+":"-")+x);O.added?A+=E.length:R+=E.length}else{if(P)if(E.length<=c*2&&b<m.length-2)for(const x of D(E))w.push(x);else{const x=Math.min(E.length,c);for(const I of D(E.slice(0,x)))w.push(I);const N={oldStart:P,oldLines:R-P+x,newStart:h,newLines:A-h+x,lines:w};k.push(N),P=0,h=0,w=[]}R+=E.length,A+=E.length}}for(const b of k)for(let O=0;O<b.lines.length;O++)b.lines[O].endsWith(`
28
+ `)?b.lines[O]=b.lines[O].slice(0,-1):(b.lines.splice(O+1,0,"\"),O++);return{oldFileName:t,newFileName:e,oldHeader:o,newHeader:u,hunks:k}}}function ie(t){if(Array.isArray(t))return t.map(ie).join(`
29
29
  `);const e=[];t.oldFileName==t.newFileName&&e.push("Index: "+t.oldFileName),e.push("==================================================================="),e.push("--- "+t.oldFileName+(typeof t.oldHeader>"u"?"":" "+t.oldHeader)),e.push("+++ "+t.newFileName+(typeof t.newHeader>"u"?"":" "+t.newHeader));for(let n=0;n<t.hunks.length;n++){const r=t.hunks[n];r.oldLines===0&&(r.oldStart-=1),r.newLines===0&&(r.newStart-=1),e.push("@@ -"+r.oldStart+","+r.oldLines+" +"+r.newStart+","+r.newLines+" @@");for(const o of r.lines)e.push(o)}return e.join(`
30
30
  `)+`
31
- `}function He(t,e,n,r,o,u,d){if(typeof d=="function"&&(d={callback:d}),d?.callback){const{callback:f}=d;be(t,e,n,r,o,u,Object.assign(Object.assign({},d),{callback:p=>{f(p?ie(p):void 0)}}))}else{const f=be(t,e,n,r,o,u,d);return f?ie(f):void 0}}function Ue(t){const e=t.endsWith(`
31
+ `}function He(t,e,n,r,o,u,p){if(typeof p=="function"&&(p={callback:p}),p?.callback){const{callback:f}=p;be(t,e,n,r,o,u,Object.assign(Object.assign({},p),{callback:c=>{f(c?ie(c):void 0)}}))}else{const f=be(t,e,n,r,o,u,p);return f?ie(f):void 0}}function Ue(t){const e=t.endsWith(`
32
32
  `),n=t.split(`
33
33
  `).map(r=>r+`
34
- `);return e?n.pop():n.push(n.pop().slice(0,-1)),n}function Je(t,e,n="git",r=3){switch(n){case"git":return ve(t,e,r);case"object":return Be(t,e);case"json":return Ve(t,e);default:return ve(t,e,r)}}function ve(t,e,n=3){const r=ke(t),o=ke(e);return He("","",r,o,"","",{context:n}).split(`
35
- `).slice(2).join(`
36
- `)}function Be(t,e){const n=de.diff(t,e)||[];return JSON.stringify(n,null,2)}function Ve(t,e){return JSON.stringify({before:t,after:e},null,2)}function Ge(t,e){return typeof t=="string"&&typeof e=="string"?ye(t,e):typeof t=="number"&&typeof e=="number"?we(t,e):Xe(t,e)}function ye(t,e){if(t===e)return 0;if(t.length===0||e.length===0)return 1;const n=Me.get(t,e),r=Math.max(t.length,e.length);return n/r}function we(t,e){if(t===e)return 0;if(t===0)return 1;const n=Math.abs(e-t),r=Math.max(Math.abs(t),Math.abs(e));return Math.min(n/r,1)}function Xe(t,e){if(t===e)return 0;const n=de.diff(t,e)||[];if(n.length===0)return 0;const r=ge(t),o=ge(e),u=Math.max(r,o);if(u===0)return 0;let d=0;for(const f of n)switch(f.kind){case"N":d+=1;break;case"D":d+=1;break;case"E":if(typeof f.lhs=="string"&&typeof f.rhs=="string"){const p=ye(f.lhs,f.rhs);d+=p}else if(typeof f.lhs=="number"&&typeof f.rhs=="number"){const p=we(f.lhs,f.rhs);d+=p}else d+=1;break;case"A":d+=.5;break}return Math.min(d/u,1)}function ge(t){if(t==null)return 0;if(typeof t!="object")return 1;if(Array.isArray(t))return t.length;let e=0;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e+=1);return e}function ke(t){try{return JSON.stringify(t,(e,n)=>typeof n=="function"?"[Function]":n===void 0?"[undefined]":n===1/0?"[Infinity]":Number.isNaN(n)?"[NaN]":n,2)}catch{return String(t)}}function Ze(t,e,n){const r=oe(),o=n?.onFeedback||r,u=n?.debounceMs??1500,d=n?.diffType??"git",f=n?.compareWith,p=n?.default_trigger_name??"auto_state_change",y=n?.ignoreInitialNullish??!0,m=g.useRef(t),R=g.useRef(t),P=g.useRef(!0),x=g.useRef(t),h=g.useRef(t!=null),w=g.useRef(null),A=g.useRef(void 0),D=g.useCallback((k,E,O)=>{const N=Ge(k,E),L=Je(k,E,d);let i;n?.vote?typeof n.vote=="function"?i=n.vote(k,E,N):i=n.vote:i=N>.5?"downvote":"upvote";const l=typeof e=="function"?e(E):e;o({tx_id:l,vote:i,explanation:`State change with diff percentage: ${(N*100).toFixed(1)}%`,correction:L,source:"IMPLICIT",extra_metadata:n?.metadata,trigger_name:O})},[n,e,d,o]),v=g.useCallback(k=>{const E=k||p;if(w.current&&A.current&&A.current!==E){clearTimeout(w.current);const O=R.current;D(O,t,A.current),w.current=null}A.current=E},[t,p,D]);return g.useEffect(()=>{if(P.current){P.current=!1,m.current=t,R.current=t;return}const k=m.current;if(!(f?f(k,t):JSON.stringify(k)===JSON.stringify(t))){const O=y&&x.current==null&&!h.current&&t!=null;if(t!=null&&(h.current=!0),O){m.current=t,R.current=t;return}w.current||(R.current=k),w.current&&clearTimeout(w.current),m.current=t,w.current=setTimeout(()=>{const N=R.current,L=t;D(N,L,A.current||p),R.current=L,w.current=null},u)}return()=>{w.current&&clearTimeout(w.current)}},[t,e,n,o,d,u,f,p,y,D]),{notifyChange:v}}function Qe(t,e,n){const[r,o]=g.useState(t),{notifyChange:u}=Ze(r,e,n),d=g.useCallback((f,p)=>{u(p),o(y=>typeof f=="function"?f(y):f)},[u]);return[r,d]}let qe=()=>{try{return require("@opentelemetry/api")}catch{throw new Error("OpenTelemetry is not available. Install @opentelemetry/api to use trace ID extraction.")}};function $e(){const{trace:t,context:e}=qe();try{const n=t.getSpanContext(e.active());if(n?.traceId)return n.traceId;const r=t.getSpan(e.active());if(r){const o=r.spanContext();if(o.traceId)return o.traceId}}catch(n){throw new Error(`Failed to extract OpenTelemetry trace ID: ${n instanceof Error?n.message:"Unknown error"}`)}throw new Error("OpenTelemetry trace ID not available. Ensure XHR/Fetch instrumentation is active and a request is in progress.")}W.KeletContext=Q,W.KeletProvider=De,W.VoteFeedback=Ae,W.getOtelTraceId=$e,W.useDefaultFeedbackHandler=oe,W.useFeedbackState=Qe,W.useKelet=Oe,Object.defineProperty(W,Symbol.toStringTag,{value:"Module"})});
34
+ `);return e?n.pop():n.push(n.pop().slice(0,-1)),n}function Be(t,e,n="git",r=1){switch(n){case"git":return ve(t,e,r);case"object":return Je(t,e);case"json":return Ve(t,e);default:return ve(t,e,r)}}function ve(t,e,n=1){const r=ke(t),o=ke(e),f=He("","",r,o,"","",{context:n}).split(`
35
+ `).filter(c=>!c||c==="\"||c.startsWith("@@")||c.startsWith("---")||c.startsWith("+++")||c.startsWith(" ")?!1:!!(c.startsWith("+")||c.startsWith("-")));for(;f.length&&f[0].trim()==="";)f.shift();for(;f.length&&f[f.length-1].trim()==="";)f.pop();return f.join(`
36
+ `)}function Je(t,e){const n=de.diff(t,e)||[];return JSON.stringify(n,null,2)}function Ve(t,e){return JSON.stringify({before:t,after:e},null,2)}function Ge(t,e){return typeof t=="string"&&typeof e=="string"?ye(t,e):typeof t=="number"&&typeof e=="number"?we(t,e):Xe(t,e)}function ye(t,e){if(t===e)return 0;if(t.length===0||e.length===0)return 1;const n=Me.get(t,e),r=Math.max(t.length,e.length);return n/r}function we(t,e){if(t===e)return 0;if(t===0)return 1;const n=Math.abs(e-t),r=Math.max(Math.abs(t),Math.abs(e));return Math.min(n/r,1)}function Xe(t,e){if(t===e)return 0;const n=de.diff(t,e)||[];if(n.length===0)return 0;const r=ge(t),o=ge(e),u=Math.max(r,o);if(u===0)return 0;let p=0;for(const f of n)switch(f.kind){case"N":p+=1;break;case"D":p+=1;break;case"E":if(typeof f.lhs=="string"&&typeof f.rhs=="string"){const c=ye(f.lhs,f.rhs);p+=c}else if(typeof f.lhs=="number"&&typeof f.rhs=="number"){const c=we(f.lhs,f.rhs);p+=c}else p+=1;break;case"A":p+=.5;break}return Math.min(p/u,1)}function ge(t){if(t==null)return 0;if(typeof t!="object")return 1;if(Array.isArray(t))return t.length;let e=0;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e+=1);return e}function ke(t){try{return JSON.stringify(t,(e,n)=>typeof n=="function"?"[Function]":n===void 0?"[undefined]":n===1/0?"[Infinity]":Number.isNaN(n)?"[NaN]":n,2)}catch{return String(t)}}function Ze(t,e,n){const r=oe(),o=n?.onFeedback||r,u=n?.debounceMs??3e3,p=n?.diffType??"git",f=n?.compareWith,c=n?.default_trigger_name??"auto_state_change",y=n?.ignoreInitialNullish??!0,m=g.useRef(t),D=g.useRef(!0),k=g.useRef(t),P=g.useRef(t==null),h=g.useRef(t!=null),w=g.useRef(!(y&&t==null)),R=g.useRef(null),A=g.useRef(void 0),b=g.useCallback((E,x,N)=>{const I=Ge(E,x),i=Be(E,x,p);let l;n?.vote?typeof n.vote=="function"?l=n.vote(E,x,I):l=n.vote:l=I>.5?"downvote":"upvote";const s=typeof e=="function"?e(x):e;o({tx_id:s,vote:l,explanation:`State change with diff percentage: ${(I*100).toFixed(1)}%`,correction:i,source:"IMPLICIT",extra_metadata:n?.metadata,trigger_name:N})},[n,e,p,o]),O=g.useCallback(E=>{const x=E||c;if(R.current&&A.current&&A.current!==x){clearTimeout(R.current);const N=k.current;b(N,t,A.current),R.current=null}A.current=x},[t,c,b]);return g.useEffect(()=>{if(D.current){D.current=!1,m.current=t,(!y||t!=null)&&(k.current=t,w.current=!0);return}const E=m.current;if(!(f?f(E,t):JSON.stringify(E)===JSON.stringify(t))){const N=y&&P.current&&!h.current&&t!=null;if(t!=null&&(h.current=!0),N){k.current=t,w.current=!0,m.current=t;return}R.current&&clearTimeout(R.current),m.current=t,R.current=setTimeout(()=>{const I=k.current,i=t;w.current&&b(I,i,A.current||c),R.current=null},u)}return()=>{R.current&&clearTimeout(R.current)}},[t,e,n,o,p,u,f,c,y,b]),{notifyChange:O}}function Qe(t,e,n){const[r,o]=g.useState(t),{notifyChange:u}=Ze(r,e,n),p=g.useCallback((f,c)=>{u(c),o(y=>typeof f=="function"?f(y):f)},[u]);return[r,p]}let qe=()=>{try{return require("@opentelemetry/api")}catch{throw new Error("OpenTelemetry is not available. Install @opentelemetry/api to use trace ID extraction.")}};function $e(){const{trace:t,context:e}=qe();try{const n=t.getSpanContext(e.active());if(n?.traceId)return n.traceId;const r=t.getSpan(e.active());if(r){const o=r.spanContext();if(o.traceId)return o.traceId}}catch(n){throw new Error(`Failed to extract OpenTelemetry trace ID: ${n instanceof Error?n.message:"Unknown error"}`)}throw new Error("OpenTelemetry trace ID not available. Ensure XHR/Fetch instrumentation is active and a request is in progress.")}W.KeletContext=Q,W.KeletProvider=De,W.VoteFeedback=Ae,W.getOtelTraceId=$e,W.useDefaultFeedbackHandler=oe,W.useFeedbackState=Qe,W.useKelet=Oe,Object.defineProperty(W,Symbol.toStringTag,{value:"Module"})});
37
37
  //# sourceMappingURL=feedback-ui.umd.min.js.map