From d9cc36469360e17f03081693161b7b7fad2d341e Mon Sep 17 00:00:00 2001 From: Lukas Oppermann Date: Sat, 24 Oct 2026 07:58:10 +0200 Subject: [PATCH] fix(canvas): keep comments available with Pick & polish Restore both review toolbars and coordinate their active sidebars, pins, and target selection without changing stored review data. Protect pending captures and open drafts when switching workflows. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 37c4f329-df0b-44b5-9600-2c9c3f3a42de --- .../renderer-improvement-notes-prototype.js | 2 +- ...er-prototype-canvas-improvement-threads.js | 4 +- .../replica-prototype/assets/renderer.js | 10 +- .../replica-prototype/marketplace.test.mjs | 2 +- .../extensions/replica-prototype/plugin.json | 2 +- .../application/prototype-canvas/index.tsx | 17 +- .../application/prototype-canvas/stories.tsx | 67 +++- .../tests/commenting-and-polish.test.tsx | 370 ++++++++++++++++++ .../prototype-canvas-hub-panel/index.tsx | 120 +++--- .../index.tsx | 26 +- .../use-preview-selection/index.ts | 26 +- .../index.tsx | 4 + .../types.ts | 1 + hub/docs/prototype-canvas.md | 2 + 14 files changed, 583 insertions(+), 70 deletions(-) create mode 100644 hub/app/javascript/application/prototype-canvas/tests/commenting-and-polish.test.tsx diff --git a/.github/extensions/replica-prototype/assets/renderer-improvement-notes-prototype.js b/.github/extensions/replica-prototype/assets/renderer-improvement-notes-prototype.js index 6adc6023..78819747 100644 --- a/.github/extensions/replica-prototype/assets/renderer-improvement-notes-prototype.js +++ b/.github/extensions/replica-prototype/assets/renderer-improvement-notes-prototype.js @@ -1 +1 @@ -import{n as e,r as t}from"./renderer-rolldown-runtime.js";import{K as n,M as r,X as i,Y as a,q as o}from"./renderer-vendor.js";import{a as s,c,m as l,o as u,p as d,s as f}from"./renderer.js";import{t as p}from"./renderer-prototype-canvas-improvement-threads.js";var m=t(i(),1),h=a(),g=n(),_={title:`Pick & polish`,localAuthor:`Local author`,bridgeUnavailable:`Annotation needs the updated Replica preview bridge. Reconnect or reload the preview after updating the canvas.`,sourceUnavailable:`You can still save this improvement locally, but it cannot sync without a captured source.`,annotate:`Pick & polish`,openNotes:e=>`Open improvement notes (${e})`,notes:`Pick & polish`,selectHint:`Click an element or drag a rectangle. For a keyboard region, focus the preview, press Shift+Enter, then use arrows and Enter to choose two corners. Escape exits annotation mode.`,regionSmall:`Choose a larger region, at least 8 preview pixels wide and high.`,add:`Add improvement note`,label:`What should change?`,placeholder:`Describe the improvement you want Copilot to make...`,save:`Save note`,cancel:`Cancel`,discard:`Discard draft`,keep:`Keep writing`,discardTitle:`Discard your unsaved note?`,discardBody:`Your saved notes will stay unchanged.`,editAction:`Edit`,previewUnavailable:`The preview selection is unavailable. Try selecting the target again.`,saved:`Note added.`,storageLoading:`Loading your notes...`,branchChanged:`The prototype branch changed. Close this draft and select the target again.`,workChanged:`The open improvements changed while syncing. Review them and select Fix all again.`,closeComposer:`Close note composer`,closeDiscard:`Close discard confirmation`};function v(e,t){let n=[e.thread.originalStatus,...e.thread.messages.filter(e=>e.role===`author`).map(e=>e.status)];return{id:e.id,revision:e.revision,body:e.body,author:e.thread.originalAuthor?`@${e.thread.originalAuthor.login}`:e.author===`local`?_.localAuthor:`@${e.author}`,avatarUrl:e.thread.originalAuthor?.avatarUrl,target:e.target,path:e.route,status:e.status,originalPending:e.thread.originalStatus===`open`,...n.includes(`sent`)?{retryStatus:`sent`}:n.includes(`blocked`)?{retryStatus:`blocked`}:{},messages:e.thread.messages.map(e=>({...e,...e.role===`author`&&e.author?{author:`@${e.author.login}`,avatarUrl:e.author.avatarUrl}:{author:void 0},pending:e.role===`author`&&e.status===`open`})),...t&&(t.status===`resolved`||t.status===`moved`)?{point:t.point}:{}}}function y(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function b({frameRef:e,prototypeUrl:t,previewUrl:n,notes:r,annotating:i,composing:a,onSelect:o,onRoute:s,onCancel:l,onProblem:d}){let p=n??t,[h,g]=(0,m.useState)(null),[v,b]=(0,m.useState)(new Map),x=JSON.stringify(r.filter(e=>e.anchor).map(e=>({id:e.id,anchor:e.anchor}))),S=(0,m.useEffectEvent)(e=>{if(!i||a)return;let t=f.safeParse(e);t.success?o(t.data):(l(),d(_.previewUnavailable))}),C=(0,m.useCallback)((t,n={})=>{p&&h&&e?.current?.contentWindow&&e.current.contentWindow.postMessage({type:t,nonce:h.nonce,...n},new URL(p).origin)},[h,e,p]);return(0,m.useEffect)(()=>{let t=e?.current;if(!t||!p)return;let n=new URL(p).origin,r=crypto.randomUUID(),i=Date.now(),a=JSON.parse(x);function o(){t?.contentWindow?.postMessage({type:`replica:canvas:request-ready`,nonce:r},n),t?.contentWindow?.postMessage({type:`replica:canvas:resolve`,nonce:r,anchors:a},n)}function f(){r=crypto.randomUUID(),i=Date.now(),g({nonce:r,ready:!1}),b(new Map),l(),o()}function m(e){let a=e.data;if(e.source===t?.contentWindow&&e.origin===n&&y(a)&&a.nonce===r){if(a.type===`replica:canvas:ready`){let e=c.safeParse(a.route);if(a.protocolVersion!==1||a.improvementSelection!==!0||!e.success){g({nonce:r,ready:!1}),d(_.bridgeUnavailable);return}i=Date.now(),g(e=>e?.nonce===r&&e.ready?e:{nonce:r,ready:!0}),s(e.data.pathname+e.data.search+e.data.hash)}else if(a.type===`replica:canvas:selected`)S(a.anchor);else if(a.type===`replica:canvas:resolved`&&Array.isArray(a.results)){let e=new Map;for(let t of a.results){if(!y(t))continue;let n=u.safeParse({commentId:t.id,status:`resolved`,point:{x:t.x,y:t.y},rect:t.rect??{x:t.x,y:t.y,width:1,height:1}});n.success&&e.set(n.data.commentId,n.data)}b(e)}else a.type===`replica:canvas:selection-failed`||a.type===`replica:canvas:bridge-error`?(l(),d(a.reason===`area-too-small`?_.regionSmall:_.bridgeUnavailable)):a.type===`replica:canvas:selection-cancelled`?a.reason!==`command`&&l():a.type===`replica:canvas:conversation-dismiss-requested`&&window.dispatchEvent(new Event(`replica:review-dismiss`))}}t.addEventListener(`load`,f),window.addEventListener(`message`,m),g({nonce:r,ready:!1}),o();let h=window.setInterval(()=>{Date.now()-i>2e4&&(g({nonce:r,ready:!1}),b(new Map),l(),d(_.bridgeUnavailable)),o()},2e3);return()=>{t.removeEventListener(`load`,f),window.removeEventListener(`message`,m),window.clearInterval(h),t.contentWindow?.postMessage({type:`replica:canvas:cancel-selection`,nonce:r},n),t.contentWindow?.postMessage({type:`replica:canvas:clear-selection`,nonce:r},n)}},[x,e,p,l,d,s]),(0,m.useEffect)(()=>{h?.ready&&(i&&!a?C(`replica:canvas:select`,{mode:`improvement`}):C(`replica:canvas:cancel-selection`),a||C(`replica:canvas:clear-selection`))},[i,a,h?.ready,C]),{ready:h?.ready===!0,resolutions:v}}function x(e){let[t,n]=(0,m.useState)(null),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),u=(0,m.useRef)(null),d=(0,m.useRef)(!1),f=(0,m.useRef)(null),p=(0,m.useRef)(!1),h=(0,m.useRef)(0);function g(e){p.current&&(u.current=e,n(e))}(0,m.useEffect)(()=>{if(!e)return;p.current=!0;let t=!1,r=!1,a=0;async function c(){if(d.current||r)return;r=!0;let c=h.current;try{let n=await s(`/api/improvement-notes`,e);if(d.current||c!==h.current||t)return;if(g(n),Date.now()-a>15e3){a=Date.now();let r=s(`/api/improvement-notes/sync`,e,{method:`POST`,body:JSON.stringify({identity:n.identity,revision:n.revision})}).then(e=>{t||g(e)});f.current=r;try{await r}finally{f.current===r&&(f.current=null)}}t||o(``)}catch(e){t||(e instanceof Error&&`statusCode`in e&&e.statusCode===403&&(u.current=null,n(null),i(``)),o(e instanceof Error?e.message:String(e)))}finally{r=!1}}c();let l=window.setInterval(()=>void c(),3e3);return()=>{p.current=!1,t=!0,window.clearInterval(l)}},[e]);async function v(t,n={}){if(!e||!u.current||d.current)return!1;let r=u.current.identity,a=u.current.notes.filter(e=>e.status===`open`).map(e=>`${e.id}:${e.revision}`).sort().join(`,`);d.current=!0,h.current++,l(!0),i(``);try{if(await f.current,!p.current)return!1;if(!u.current||u.current.identity!==r)throw Error(_.branchChanged);if(t===`fix`&&u.current.notes.filter(e=>e.status===`open`).map(e=>`${e.id}:${e.revision}`).sort().join(`,`)!==a)throw Error(_.workChanged);return g(await s(t===`fix`?`/api/improvement-notes/fix`:`/api/improvement-notes`,e,{method:`POST`,body:JSON.stringify({identity:u.current.identity,revision:u.current.revision,operation:t,...n})})),!0}catch(e){return p.current&&i(e instanceof Error?e.message:String(e)),!1}finally{d.current=!1,p.current&&l(!1)}}async function y(){if(!e)return null;i(``);try{return await s(`/api/improvement-notes/capture`,e,{method:`POST`})}catch(e){return i(`${e instanceof Error?e.message:String(e)} ${_.sourceUnavailable}`),null}}return{state:t,error:r||a,busy:c,change:v,capture:y}}var S=e({ImprovementNotesPrototype:()=>w}),C=o();function w({canvas:e}){let t=x(e.token),n=t.state?.notes??[],[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(!1),[c,u]=(0,m.useState)(!1),[f,y]=(0,m.useState)(null),[S,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(``),[D,O]=(0,m.useState)(!1),[k,A]=(0,m.useState)(!0),[j,M]=(0,m.useState)(``),N=(0,m.useRef)(0),P=(0,m.useRef)(null),F=(0,m.useRef)(null),I=(0,m.useRef)(null),L=S!==null&&S.identity!==t.state?.identity,R=S!==null&&!D&&t.state!==null,z=n.filter(e=>e.status!==`resolved`).length,B=t.state?.syncError===`Notes are saved locally until Hub discovers this branch.`?null:t.state?.syncError,V=(0,m.useCallback)(e=>{w({identity:f?.identity??t.state?.identity,sourceId:f?.sourceId,anchor:e}),E(``)},[t.state?.identity,f]),H=(0,m.useCallback)(()=>{N.current++,u(!1),P.current?.getAttribute(`aria-pressed`)===`true`&&P.current.focus(),s(!1)},[]),U=b({frameRef:e.frameRef,prototypeUrl:e.prototypeUrl,previewUrl:e.previewUrl,notes:n,annotating:o,composing:S!==null,onSelect:V,onRoute:a,onCancel:H,onProblem:M});(0,m.useLayoutEffect)(()=>{R&&F.current?.focus()},[R]);function W(){A(!0),e.onOpenNotes()}async function G(){let e=++N.current;u(!0);let n=await t.capture();e===N.current&&(u(!1),y(n),s(!0),A(!1),M(_.selectHint))}function K(){T===``?(w(null),H()):O(!0)}async function q(){S&&T.trim()&&!t.busy&&!L&&await t.change(`create`,{identity:S.identity,sourceId:S.sourceId,body:T.trim(),anchor:S.anchor})&&(W(),H(),w(null),M(_.saved))}return(0,C.jsxs)(`section`,{"aria-label":_.title,className:`improvement-demo`,onKeyDown:e=>{e.key===`Escape`&&!e.defaultPrevented&&!S&&H()},children:[e.toolbarTarget&&(0,h.createPortal)((0,C.jsxs)(`div`,{role:`group`,"aria-label":_.title,className:`improvement-demo__split`,children:[(0,C.jsx)(g.Button,{ref:P,size:`small`,variant:`secondary`,className:`canvas-toolbar-compact-button`,title:_.annotate,leadingVisual:(0,C.jsx)(r,{}),"aria-pressed":o,disabled:c||!U.ready||!t.state,onClick:()=>{o?H():G()},children:(0,C.jsx)(`span`,{className:`canvas-toolbar-button-label`,children:_.annotate})}),(0,C.jsx)(g.Button,{ref:I,size:`small`,variant:`secondary`,"aria-label":_.openNotes(z),"aria-expanded":k&&!e.hubOpen,onClick:W,children:(0,C.jsx)(d,{children:z})})]}),e.toolbarTarget),(0,C.jsx)(p,{identity:t.state?.identity??``,controls:!1,returnFocusRef:I,open:k&&!e.hubOpen&&!S,active:(k||o)&&!e.hubOpen&&!S,onOpen:W,onClose:()=>{A(!1),I.current?.focus()},threads:n.map(e=>v(e,U.resolutions.get(e.id))),busy:t.busy||!t.state,activeBatch:!!t.state?.activeBatch,error:t.error||B||t.state?.profileError||(t.state?U.ready?``:_.bridgeUnavailable:_.storageLoading),onSelect:t=>{let r=n.find(e=>e.id===t);r&&r.route!==i&&e.onNavigate(new URL(r.route,e.prototypeUrl).href)},onFollowUp:(e,n)=>t.change(`follow-up`,{id:e.id,expectedNoteRevision:e.revision,body:n}),onResolve:e=>t.change(`status`,{id:e.id,expectedNoteRevision:e.revision,status:`resolved`}),onDelete:e=>t.change(`delete`,{id:e.id,expectedNoteRevision:e.revision}),onFix:()=>t.change(`fix`),onRetry:e=>t.change(`status`,{id:e.id,expectedNoteRevision:e.revision,status:`open`})}),(0,C.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:j}),R?(0,C.jsxs)(l,{title:_.add,closeLabel:_.closeComposer,returnFocusRef:P,onClose:K,className:`improvement-demo__composer`,children:[t.error?(0,C.jsx)(`p`,{role:`alert`,className:`improvement-demo__notice`,children:t.error}):null,L?(0,C.jsx)(`p`,{role:`alert`,className:`improvement-demo__notice`,children:_.branchChanged}):null,(0,C.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),q()},children:[(0,C.jsxs)(g.FormControl,{fullWidth:!0,children:[(0,C.jsx)(g.FormControl.Label,{children:_.label}),(0,C.jsx)(g.Textarea,{ref:F,value:T,maxLength:1e4,rows:4,placeholder:_.placeholder,onChange:e=>E(e.target.value),required:!0})]}),(0,C.jsx)(`div`,{className:`improvement-demo__dialog-actions`,children:(0,C.jsx)(g.Button,{type:`submit`,size:`small`,variant:`primary`,disabled:!T.trim()||t.busy||L,children:_.save})})]})]}):null,D&&t.state?(0,C.jsxs)(l,{title:_.discardTitle,closeLabel:_.closeDiscard,returnFocusRef:P,onClose:()=>O(!1),children:[(0,C.jsx)(`p`,{children:_.discardBody}),(0,C.jsxs)(`div`,{className:`improvement-demo__dialog-actions`,children:[(0,C.jsx)(g.Button,{size:`small`,variant:`secondary`,onClick:()=>O(!1),children:_.keep}),(0,C.jsx)(g.Button,{size:`small`,variant:`primary`,onClick:()=>{O(!1),w(null),E(``),H()},children:_.discard})]})]}):null]})}export{S as t}; \ No newline at end of file +import{n as e,r as t}from"./renderer-rolldown-runtime.js";import{K as n,M as r,X as i,Y as a,q as o}from"./renderer-vendor.js";import{a as s,c,m as l,o as u,p as d,s as f}from"./renderer.js";import{t as p}from"./renderer-prototype-canvas-improvement-threads.js";var m=t(i(),1),h=a(),g=n(),_={title:`Pick & polish`,localAuthor:`Local author`,bridgeUnavailable:`Annotation needs the updated Replica preview bridge. Reconnect or reload the preview after updating the canvas.`,sourceUnavailable:`You can still save this improvement locally, but it cannot sync without a captured source.`,annotate:`Pick & polish`,openNotes:e=>`Open improvement notes (${e})`,notes:`Pick & polish`,selectHint:`Click an element or drag a rectangle. For a keyboard region, focus the preview, press Shift+Enter, then use arrows and Enter to choose two corners. Escape exits annotation mode.`,regionSmall:`Choose a larger region, at least 8 preview pixels wide and high.`,add:`Add improvement note`,label:`What should change?`,placeholder:`Describe the improvement you want Copilot to make...`,save:`Save note`,cancel:`Cancel`,discard:`Discard draft`,keep:`Keep writing`,discardTitle:`Discard your unsaved note?`,discardBody:`Your saved notes will stay unchanged.`,editAction:`Edit`,previewUnavailable:`The preview selection is unavailable. Try selecting the target again.`,saved:`Note added.`,storageLoading:`Loading your notes...`,branchChanged:`The prototype branch changed. Close this draft and select the target again.`,workChanged:`The open improvements changed while syncing. Review them and select Fix all again.`,closeComposer:`Close note composer`,closeDiscard:`Close discard confirmation`};function v(e,t){let n=[e.thread.originalStatus,...e.thread.messages.filter(e=>e.role===`author`).map(e=>e.status)];return{id:e.id,revision:e.revision,body:e.body,author:e.thread.originalAuthor?`@${e.thread.originalAuthor.login}`:e.author===`local`?_.localAuthor:`@${e.author}`,avatarUrl:e.thread.originalAuthor?.avatarUrl,target:e.target,path:e.route,status:e.status,originalPending:e.thread.originalStatus===`open`,...n.includes(`sent`)?{retryStatus:`sent`}:n.includes(`blocked`)?{retryStatus:`blocked`}:{},messages:e.thread.messages.map(e=>({...e,...e.role===`author`&&e.author?{author:`@${e.author.login}`,avatarUrl:e.author.avatarUrl}:{author:void 0},pending:e.role===`author`&&e.status===`open`})),...t&&(t.status===`resolved`||t.status===`moved`)?{point:t.point}:{}}}function y(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function b({frameRef:e,prototypeUrl:t,previewUrl:n,notes:r,active:i=!0,annotating:a,composing:o,onSelect:s,onRoute:l,onCancel:d,onProblem:p}){let h=n??t,[g,v]=(0,m.useState)(null),[b,x]=(0,m.useState)(new Map),S=JSON.stringify(i?r.filter(e=>e.anchor).map(e=>({id:e.id,anchor:e.anchor})):[]),C=(0,m.useEffectEvent)(e=>{if(!i||!a||o)return;let t=f.safeParse(e);t.success?s(t.data):(d(),p(_.previewUnavailable))}),w=(0,m.useCallback)((t,n={})=>{h&&g&&e?.current?.contentWindow&&e.current.contentWindow.postMessage({type:t,nonce:g.nonce,...n},new URL(h).origin)},[g,e,h]);return(0,m.useEffect)(()=>{let t=e?.current;if(!t||!h)return;let n=new URL(h).origin,r=crypto.randomUUID(),a=Date.now(),o=JSON.parse(S);function s(){t?.contentWindow?.postMessage({type:`replica:canvas:request-ready`,nonce:r},n),i&&t?.contentWindow?.postMessage({type:`replica:canvas:resolve`,nonce:r,anchors:o},n)}function f(){r=crypto.randomUUID(),a=Date.now(),v({nonce:r,ready:!1}),x(new Map),d(),s()}function m(e){let i=e.data;if(e.source===t?.contentWindow&&e.origin===n&&y(i)&&i.nonce===r){if(i.type===`replica:canvas:ready`){let e=c.safeParse(i.route);if(i.protocolVersion!==1||i.improvementSelection!==!0||!e.success){v({nonce:r,ready:!1}),p(_.bridgeUnavailable);return}a=Date.now(),v(e=>e?.nonce===r&&e.ready?e:{nonce:r,ready:!0}),l(e.data.pathname+e.data.search+e.data.hash)}else if(i.type===`replica:canvas:selected`)C(i.anchor);else if(i.type===`replica:canvas:resolved`&&Array.isArray(i.results)){let e=new Map;for(let t of i.results){if(!y(t))continue;let n=u.safeParse({commentId:t.id,status:`resolved`,point:{x:t.x,y:t.y},rect:t.rect??{x:t.x,y:t.y,width:1,height:1}});n.success&&e.set(n.data.commentId,n.data)}x(e)}else i.type===`replica:canvas:selection-failed`||i.type===`replica:canvas:bridge-error`?(d(),p(i.reason===`area-too-small`?_.regionSmall:_.bridgeUnavailable)):i.type===`replica:canvas:selection-cancelled`?i.reason!==`command`&&d():i.type===`replica:canvas:conversation-dismiss-requested`&&window.dispatchEvent(new Event(`replica:review-dismiss`))}}t.addEventListener(`load`,f),window.addEventListener(`message`,m),v({nonce:r,ready:!1}),s();let g=window.setInterval(()=>{Date.now()-a>2e4&&(v({nonce:r,ready:!1}),x(new Map),d(),p(_.bridgeUnavailable)),s()},2e3);return()=>{t.removeEventListener(`load`,f),window.removeEventListener(`message`,m),window.clearInterval(g),i&&(t.contentWindow?.postMessage({type:`replica:canvas:cancel-selection`,nonce:r},n),t.contentWindow?.postMessage({type:`replica:canvas:clear-selection`,nonce:r},n))}},[i,S,e,h,d,p,l]),(0,m.useEffect)(()=>{i&&g?.ready&&(a&&!o?w(`replica:canvas:select`,{mode:`improvement`}):w(`replica:canvas:cancel-selection`),o||w(`replica:canvas:clear-selection`))},[i,a,o,g?.ready,w]),{ready:g?.ready===!0,resolutions:b}}function x(e){let[t,n]=(0,m.useState)(null),[r,i]=(0,m.useState)(``),[a,o]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),u=(0,m.useRef)(null),d=(0,m.useRef)(!1),f=(0,m.useRef)(null),p=(0,m.useRef)(!1),h=(0,m.useRef)(0);function g(e){p.current&&(u.current=e,n(e))}(0,m.useEffect)(()=>{if(!e)return;p.current=!0;let t=!1,r=!1,a=0;async function c(){if(d.current||r)return;r=!0;let c=h.current;try{let n=await s(`/api/improvement-notes`,e);if(d.current||c!==h.current||t)return;if(g(n),Date.now()-a>15e3){a=Date.now();let r=s(`/api/improvement-notes/sync`,e,{method:`POST`,body:JSON.stringify({identity:n.identity,revision:n.revision})}).then(e=>{t||g(e)});f.current=r;try{await r}finally{f.current===r&&(f.current=null)}}t||o(``)}catch(e){t||(e instanceof Error&&`statusCode`in e&&e.statusCode===403&&(u.current=null,n(null),i(``)),o(e instanceof Error?e.message:String(e)))}finally{r=!1}}c();let l=window.setInterval(()=>void c(),3e3);return()=>{p.current=!1,t=!0,window.clearInterval(l)}},[e]);async function v(t,n={}){if(!e||!u.current||d.current)return!1;let r=u.current.identity,a=u.current.notes.filter(e=>e.status===`open`).map(e=>`${e.id}:${e.revision}`).sort().join(`,`);d.current=!0,h.current++,l(!0),i(``);try{if(await f.current,!p.current)return!1;if(!u.current||u.current.identity!==r)throw Error(_.branchChanged);if(t===`fix`&&u.current.notes.filter(e=>e.status===`open`).map(e=>`${e.id}:${e.revision}`).sort().join(`,`)!==a)throw Error(_.workChanged);return g(await s(t===`fix`?`/api/improvement-notes/fix`:`/api/improvement-notes`,e,{method:`POST`,body:JSON.stringify({identity:u.current.identity,revision:u.current.revision,operation:t,...n})})),!0}catch(e){return p.current&&i(e instanceof Error?e.message:String(e)),!1}finally{d.current=!1,p.current&&l(!1)}}async function y(){if(!e)return null;i(``);try{return await s(`/api/improvement-notes/capture`,e,{method:`POST`})}catch(e){return i(`${e instanceof Error?e.message:String(e)} ${_.sourceUnavailable}`),null}}return{state:t,error:r||a,busy:c,change:v,capture:y}}var S=e({ImprovementNotesPrototype:()=>w}),C=o();function w({canvas:e}){let t=x(e.token),n=t.state?.notes??[],[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(!1),[c,u]=(0,m.useState)(!1),[f,y]=(0,m.useState)(null),[S,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(``),[D,O]=(0,m.useState)(!1),[k,A]=(0,m.useState)(!0),[j,M]=(0,m.useState)(``),[N,P]=(0,m.useState)(!1),F=(0,m.useRef)(0),I=(0,m.useRef)(null),L=(0,m.useRef)(null),R=(0,m.useRef)(null),z=S!==null&&S.identity!==t.state?.identity,B=S!==null&&!D&&t.state!==null,V=n.filter(e=>e.status!==`resolved`).length,H=t.state?.syncError===`Notes are saved locally until Hub discovers this branch.`?null:t.state?.syncError,U=e.active!==!1,W=e.onInteractionChange;(0,m.useLayoutEffect)(()=>{W?.(c||o||S!==null||N)},[W,c,o,S,N]);let G=(0,m.useCallback)(e=>{w({identity:f?.identity??t.state?.identity,sourceId:f?.sourceId,anchor:e}),E(``)},[t.state?.identity,f]),K=(0,m.useCallback)(()=>{F.current++,u(!1),I.current?.getAttribute(`aria-pressed`)===`true`&&I.current.focus(),s(!1)},[]),q=b({frameRef:e.frameRef,prototypeUrl:e.prototypeUrl,previewUrl:e.previewUrl,notes:n,active:U,annotating:o,composing:S!==null,onSelect:G,onRoute:a,onCancel:K,onProblem:M});(0,m.useLayoutEffect)(()=>{B&&L.current?.focus()},[B]);function J(){e.selectionDisabled||(A(!0),e.onOpenNotes())}async function Y(){if(e.selectionDisabled)return;e.onOpenNotes();let n=++F.current;u(!0);let r=await t.capture();n===F.current&&(u(!1),y(r),s(!0),A(!1),M(_.selectHint))}function X(){T===``?(w(null),K()):O(!0)}async function Z(){S&&T.trim()&&!t.busy&&!z&&await t.change(`create`,{identity:S.identity,sourceId:S.sourceId,body:T.trim(),anchor:S.anchor})&&(J(),K(),w(null),M(_.saved))}return(0,C.jsxs)(`section`,{"aria-label":_.title,className:`improvement-demo`,onKeyDown:e=>{e.key===`Escape`&&!e.defaultPrevented&&!S&&K()},children:[e.toolbarTarget&&(0,h.createPortal)((0,C.jsxs)(`div`,{role:`group`,"aria-label":_.title,className:`improvement-demo__split`,children:[(0,C.jsx)(g.Button,{ref:I,size:`small`,variant:`secondary`,className:`canvas-toolbar-compact-button`,title:_.annotate,leadingVisual:(0,C.jsx)(r,{}),"aria-pressed":o,disabled:e.selectionDisabled||c||!q.ready||!t.state,onClick:()=>{o?K():Y()},children:(0,C.jsx)(`span`,{className:`canvas-toolbar-button-label`,children:_.annotate})}),(0,C.jsx)(g.Button,{ref:R,size:`small`,variant:`secondary`,"aria-label":_.openNotes(V),"aria-expanded":k&&U&&!e.hubOpen,disabled:e.selectionDisabled,onClick:J,children:(0,C.jsx)(d,{children:V})})]}),e.toolbarTarget),(0,C.jsx)(p,{identity:t.state?.identity??``,controls:!1,returnFocusRef:R,open:k&&U&&!e.hubOpen&&!S,active:U&&(k||o)&&!e.hubOpen&&!S,onInteractionChange:P,onOpen:J,onClose:()=>{A(!1),R.current?.focus()},threads:n.map(e=>v(e,q.resolutions.get(e.id))),busy:t.busy||!t.state,activeBatch:!!t.state?.activeBatch,error:t.error||H||t.state?.profileError||(t.state?q.ready?``:_.bridgeUnavailable:_.storageLoading),onSelect:t=>{let r=n.find(e=>e.id===t);r&&r.route!==i&&e.onNavigate(new URL(r.route,e.prototypeUrl).href)},onFollowUp:(e,n)=>t.change(`follow-up`,{id:e.id,expectedNoteRevision:e.revision,body:n}),onResolve:e=>t.change(`status`,{id:e.id,expectedNoteRevision:e.revision,status:`resolved`}),onDelete:e=>t.change(`delete`,{id:e.id,expectedNoteRevision:e.revision}),onFix:()=>t.change(`fix`),onRetry:e=>t.change(`status`,{id:e.id,expectedNoteRevision:e.revision,status:`open`})}),(0,C.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:j}),B?(0,C.jsxs)(l,{title:_.add,closeLabel:_.closeComposer,returnFocusRef:I,onClose:X,className:`improvement-demo__composer`,children:[t.error?(0,C.jsx)(`p`,{role:`alert`,className:`improvement-demo__notice`,children:t.error}):null,z?(0,C.jsx)(`p`,{role:`alert`,className:`improvement-demo__notice`,children:_.branchChanged}):null,(0,C.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),Z()},children:[(0,C.jsxs)(g.FormControl,{fullWidth:!0,children:[(0,C.jsx)(g.FormControl.Label,{children:_.label}),(0,C.jsx)(g.Textarea,{ref:L,value:T,maxLength:1e4,rows:4,placeholder:_.placeholder,onChange:e=>E(e.target.value),required:!0})]}),(0,C.jsx)(`div`,{className:`improvement-demo__dialog-actions`,children:(0,C.jsx)(g.Button,{type:`submit`,size:`small`,variant:`primary`,disabled:!T.trim()||t.busy||z,children:_.save})})]})]}):null,D&&t.state?(0,C.jsxs)(l,{title:_.discardTitle,closeLabel:_.closeDiscard,returnFocusRef:I,onClose:()=>O(!1),children:[(0,C.jsx)(`p`,{children:_.discardBody}),(0,C.jsxs)(`div`,{className:`improvement-demo__dialog-actions`,children:[(0,C.jsx)(g.Button,{size:`small`,variant:`secondary`,onClick:()=>O(!1),children:_.keep}),(0,C.jsx)(g.Button,{size:`small`,variant:`primary`,onClick:()=>{O(!1),w(null),E(``),K()},children:_.discard})]})]}):null]})}export{S as t}; \ No newline at end of file diff --git a/.github/extensions/replica-prototype/assets/renderer-prototype-canvas-improvement-threads.js b/.github/extensions/replica-prototype/assets/renderer-prototype-canvas-improvement-threads.js index ff572225..a94b3a55 100644 --- a/.github/extensions/replica-prototype/assets/renderer-prototype-canvas-improvement-threads.js +++ b/.github/extensions/replica-prototype/assets/renderer-prototype-canvas-improvement-threads.js @@ -1,5 +1,5 @@ -import{r as e}from"./renderer-rolldown-runtime.js";import{E as t,K as n,M as ee,P as r,X as te,Y as i,b as ne,f as re,g as ie,q as ae,u as oe,z as se}from"./renderer-vendor.js";import{d as a,f as ce,h as le,i as ue,l as o,m as de,n as s,p as fe,r as pe,t as me,u as he}from"./renderer.js";import{t as c}from"./renderer-improvement-notes-vendor.js";var l=e(te(),1),u=i(),d=n(),ge=c(),f={title:`Pick & polish`,point:e=>`Open improvement ${e}`,close:`Close improvements`,open:`Open improvements`,conversation:`Improvement`,back:`Close improvement`,copilot:`Copilot`,markResolved:`Mark as resolved`,retry:`Retry`,returnToActive:`Return to active`,followUps:e=>`${e} ${e===1?`follow-up`:`follow-ups`}`,actions:`Improvement actions`,ready:`Ready to review`,openStatus:`Open`,changedIdentity:`The prototype branch or author changed. Close this dialog and reload before making changes.`,targetUnavailable:`The saved target is not visible on this page. The conversation is shown beside the preview.`,removed:`This improvement is no longer available. Close this dialog to return to the remaining improvements.`,workStatus:e=>({open:`Open`,sent:`In progress`,ready:`Ready to review`,blocked:`Blocked`,resolved:`Resolved`})[e]??e,filter:`Filter improvement notes`,allActive:`Active notes`,empty:`No improvements in this view.`,resolved:`Resolved`,resolve:`Resolved`,fix:`Fix all`,simulate:e=>`Fix all, ${e} pending ${e===1?`request`:`requests`}`,added:`Follow-up added.`,delete:`Delete improvement`,deleteTitle:`Delete this improvement?`,comments:{...o,replyLabel:`Follow-up`,replyPlaceholder:`Request a follow-up change`,replySubmitLabel:`Add follow-up`,replySubmitTooltipMacLabel:`Add follow-up (⌘Enter)`,replySubmitTooltipOtherLabel:`Add follow-up (Ctrl+Enter)`,replyErrorLabel:`The follow-up could not be added.`,threadDiscardPromptLabel:`Your unsaved follow-up will be lost.`}},_e=` +import{r as e}from"./renderer-rolldown-runtime.js";import{E as t,K as n,M as ee,P as r,X as i,Y as a,b as te,f as ne,g as re,q as ie,u as ae,z as o}from"./renderer-vendor.js";import{d as s,f as oe,h as se,i as ce,l as c,m as le,n as l,p as ue,r as de,t as fe,u as pe}from"./renderer.js";import{t as u}from"./renderer-improvement-notes-vendor.js";var d=e(i(),1),me=a(),f=n(),he=u(),p={title:`Pick & polish`,point:e=>`Open improvement ${e}`,close:`Close improvements`,open:`Open improvements`,conversation:`Improvement`,back:`Close improvement`,copilot:`Copilot`,markResolved:`Mark as resolved`,retry:`Retry`,returnToActive:`Return to active`,followUps:e=>`${e} ${e===1?`follow-up`:`follow-ups`}`,actions:`Improvement actions`,ready:`Ready to review`,openStatus:`Open`,changedIdentity:`The prototype branch or author changed. Close this dialog and reload before making changes.`,targetUnavailable:`The saved target is not visible on this page. The conversation is shown beside the preview.`,removed:`This improvement is no longer available. Close this dialog to return to the remaining improvements.`,workStatus:e=>({open:`Open`,sent:`In progress`,ready:`Ready to review`,blocked:`Blocked`,resolved:`Resolved`})[e]??e,filter:`Filter improvement notes`,allActive:`Active notes`,empty:`No improvements in this view.`,resolved:`Resolved`,resolve:`Resolved`,fix:`Fix all`,simulate:e=>`Fix all, ${e} pending ${e===1?`request`:`requests`}`,added:`Follow-up added.`,delete:`Delete improvement`,deleteTitle:`Delete this improvement?`,comments:{...c,replyLabel:`Follow-up`,replyPlaceholder:`Request a follow-up change`,replySubmitLabel:`Add follow-up`,replySubmitTooltipMacLabel:`Add follow-up (⌘Enter)`,replySubmitTooltipOtherLabel:`Add follow-up (Ctrl+Enter)`,replyErrorLabel:`The follow-up could not be added.`,threadDiscardPromptLabel:`Your unsaved follow-up will be lost.`}},ge=` -`,p=ae(),m=`data:image/svg+xml,${encodeURIComponent(_e)}`,ve=`data:image/svg+xml,${encodeURIComponent((0,ge.renderToStaticMarkup)((0,p.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`16`,height:`16`,viewBox:`0 0 16 16`,children:(0,p.jsx)(r,{size:16,fill:`white`})})))}`;function h({threads:e,open:n,active:r=n,onOpen:te,onClose:i,onFollowUp:ae,onResolve:o,onDelete:c,onFix:ge,onSelect:_e,onRetry:h,identity:g,busy:_=!1,activeBatch:ye=!1,error:v=``,returnFocusRef:be,controls:xe=!0}){let[y,b]=(0,l.useState)(null),[x,S]=(0,l.useState)(null),[C,w]=(0,l.useState)(``),[T,E]=(0,l.useState)(!1),[D,O]=(0,l.useState)(!1),[k,A]=(0,l.useState)(null),[j,M]=(0,l.useState)(g),[Se,Ce]=(0,l.useState)(``),[N,we]=(0,l.useState)(`active`),[P,Te]=(0,l.useState)(null),[F]=(0,l.useState)(()=>document.querySelector(`#canvas-improvement-controls`)),I=(0,l.useRef)(null),L=be??I,R=(0,l.useRef)(null),z=(0,l.useRef)(null),B=(0,l.useRef)(new Map),V=(0,l.useRef)(null),H=(0,l.useRef)(!1),Ee=e.find(e=>e.id===y),U=(y!==null||k!==null)&&g!==j,W=g===j?Ee??x:x,G=y!==null&&!Ee,K=k!==null&&!e.some(e=>e.id===k.id),{cardRef:q,position:De}=ue({anchorPoint:{x:12,y:12},anchorSelector:y===null?void 0:`[data-improvement-thread-id="${y}"]`,layoutKey:`${y}:${D}:${W?.messages.length}:${W?.status}`}),J=e.reduce((e,t)=>e+Number(t.originalPending)+t.messages.filter(e=>e.pending).length,0),Y=new TextEncoder().encode(C).length>1e4,Oe=[{value:`active`,label:f.allActive},{value:`ready`,label:f.ready},{value:`resolved`,label:f.resolved}],ke=Oe.find(e=>e.value===N).label,X=e.filter(e=>N===`resolved`?e.status===`resolved`:N===`ready`?e.status===`ready`:e.status!==`resolved`);(0,l.useLayoutEffect)(()=>{y===null?V.current!==null&&((R.current?.isConnected?R.current:B.current.get(V.current)??L.current)?.focus(),V.current=null):D?q.current?.querySelector(`.review-confirmation-panel button`)?.focus():U||G?q.current?.querySelector(`.thread-sample__close`)?.focus():q.current?.querySelector(`textarea`)?.focus()},[y,D,q,L,U,G]);let Z=(0,l.useCallback)(()=>{V.current=y,b(null),S(null),w(``),O(!1),H.current&&=(i(),L.current?.focus(),!1)},[y,i,L]),Q=(0,l.useCallback)(()=>{C.trim()?O(!0):y===null?(i(),L.current?.focus()):Z()},[C,y,Z,i,L]);(0,l.useEffect)(()=>{if(y===null)return;function e(){document.querySelector(`[role="menu"]`)||k||(D?(H.current=!1,O(!1)):Q())}function t(t){t.key!==`Escape`||t.defaultPrevented||t.isComposing||t.target instanceof Element&&t.target.closest(`[role="menu"], dialog`)||(t.preventDefault(),e())}return document.addEventListener(`keydown`,t),window.addEventListener(`replica:review-dismiss`,e),()=>{document.removeEventListener(`keydown`,t),window.removeEventListener(`replica:review-dismiss`,e)}},[y,D,k,Q]);function Ae(t,n){C.trim()||D||(R.current=n,M(g),S(e.find(e=>e.id===t)??null),b(t),_e?.(t))}async function je(){if(!W||!C.trim()||Y||U||G||_||T)return;let e=C.trim();E(!0);try{if(!await ae(W,e))return;w(t=>t.trim()===e?``:t),Ce(f.added)}finally{E(!1)}}async function Me(e){if(z.current?.identity!==g||z.current.id!==e.id||z.current.revision!==e.revision||e.status!==`ready`||_||C.trim()||D)return;let t=R.current;await o(e)&&!t?.isConnected&&L.current?.focus()}async function Ne(e){z.current?.identity!==g||z.current.id!==e.id||z.current.revision!==e.revision||!h||!e.retryStatus||_||C.trim()||D||await h(e)}let $=(0,p.jsx)(d.Button,{ref:I,size:`small`,variant:`secondary`,className:`canvas-toolbar-compact-button`,leadingVisual:(0,p.jsx)(ee,{size:16}),"aria-label":f.open,title:f.open,"aria-expanded":n,onClick:te,children:(0,p.jsx)(`span`,{className:`canvas-toolbar-button-label`,children:f.title})});return(0,p.jsxs)(p.Fragment,{children:[xe?F?(0,u.createPortal)($,F):$:null,(0,p.jsxs)(ce,{title:f.title,open:n,closeLabel:f.close,onClose:()=>{y===null?(i(),L.current?.focus()):(H.current=!0,Q())},closeDisabled:D,className:`thread-sample`,contentClassName:`thread-sample__content`,children:[v?(0,p.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:v}):null,(0,p.jsx)(`div`,{className:`thread-sample__toolbar`,children:(0,p.jsxs)(`div`,{className:`thread-sample__filters`,children:[(0,p.jsxs)(d.ActionMenu,{size:`small`,selectionVariant:`single`,menuAlignment:`start`,onSelect:we,children:[(0,p.jsx)(d.ActionMenu.Button,{size:`small`,variant:`secondary`,"aria-label":`${f.filter}: ${ke}`,children:ke}),(0,p.jsx)(d.ActionMenu.Overlay,{"aria-label":f.filter,children:Oe.map(e=>(0,p.jsx)(d.ActionMenu.Item,{value:e.value,selected:N===e.value,role:`menuitemradio`,onKeyDownCapture:e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.click())},children:e.label},e.value))})]}),N===`active`?(0,p.jsx)(d.Button,{size:`small`,variant:`primary`,className:`thread-sample__fix-all`,leadingVisual:(0,p.jsx)(ie,{size:16}),disabled:!J||!!C.trim()||D||_||ye,"aria-busy":_,"aria-label":f.simulate(J),onClick:()=>{ge()},children:(0,p.jsxs)(`span`,{className:`thread-sample__fix-label`,children:[f.fix,(0,p.jsx)(fe,{"aria-hidden":`true`,children:J})]})}):null]})}),W&&P?(0,u.createPortal)((0,p.jsx)(me,{ref:q,"aria-label":f.conversation,anchored:!0,position:De,className:`thread-sample__conversation`,onKeyDown:e=>{e.key===`Escape`&&!e.defaultPrevented&&!e.nativeEvent.isComposing&&!(e.target instanceof Element&&e.target.closest(`[role="menu"]`))&&(e.preventDefault(),D?(H.current=!1,O(!1)):Q())},children:(0,p.jsxs)(`div`,{className:`review-thread-conversation__layout`,children:[(0,p.jsxs)(`header`,{className:`review-thread-conversation__header`,children:[(0,p.jsx)(d.Heading,{as:`h3`,size:`6`,children:f.conversation}),W.status===`ready`?(0,p.jsx)(d.Button,{size:`small`,variant:`secondary`,className:`thread-sample__resolve`,disabled:!!C.trim()||_||U||G,leadingVisual:(0,p.jsx)(se,{size:16}),onClick:()=>{o(W)},children:f.resolve}):null,(0,p.jsx)(le,{icon:oe,size:`small`,variant:`invisible`,"aria-label":f.back,className:`thread-sample__close`,onClick:Q})]}),U?(0,p.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:f.changedIdentity}):null,G?(0,p.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:f.removed}):null,v?(0,p.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:v}):null,W.point?null:(0,p.jsx)(`p`,{role:`status`,className:`thread-sample__target-status`,children:f.targetUnavailable}),(0,p.jsxs)(`div`,{className:`review-thread-conversation__messages`,children:[(0,p.jsxs)(`article`,{className:`review-thread-message`,children:[(0,p.jsx)(s,{visual:(0,p.jsx)(a,{src:W.avatarUrl??m,size:28}),author:W.author}),(0,p.jsx)(`p`,{className:`review-thread-message__body`,children:W.body})]}),W.messages.map(e=>(0,p.jsxs)(`article`,{className:`review-thread-message`,children:[(0,p.jsx)(s,{visual:e.role===`copilot`?(0,p.jsx)(a,{src:ve,size:28,className:`thread-sample__copilot-avatar`}):(0,p.jsx)(a,{src:e.author?e.avatarUrl??m:W.avatarUrl??m,size:28}),author:e.role===`copilot`?f.copilot:e.author??W.author,metadata:e.role===`author`&&e.status&&e.status!==`ready`?(0,p.jsx)(`span`,{children:f.workStatus(e.status)}):void 0}),(0,p.jsx)(`p`,{className:`review-thread-message__body`,children:e.body})]},e.id))]}),(0,p.jsx)(`div`,{className:`review-thread-conversation__footer`,children:(0,p.jsx)(pe,{blockedLabel:null,confirmingDiscard:D,replyDraft:C,replyBodyTooLong:Y,replyFailed:!1,replyDisabled:U||G,replying:T,submitDisabled:_,copy:f.comments,onKeepDraft:()=>{H.current=!1,O(!1)},onDiscardDraft:Z,onSubmit:()=>{je()},onDraftChange:w})})]})}),P):null,(0,p.jsxs)(`div`,{className:`thread-sample__list`,children:[X.length===0?(0,p.jsx)(`p`,{className:`thread-sample__empty`,children:f.empty}):null,X.map(e=>{let n=e.messages.filter(e=>e.role===`author`).length;return(0,p.jsxs)(`article`,{className:`review-comment-row thread-sample__card${e.status===`resolved`?` thread-sample__card--resolved`:``}`,children:[(0,p.jsx)(`button`,{ref:t=>{t?B.current.set(e.id,t):B.current.delete(e.id)},className:`review-comment-row__button thread-sample__card-button`,"aria-label":`Open improvement: ${e.body}`,"aria-expanded":y===e.id,disabled:!!C.trim()||D,onClick:t=>Ae(e.id,t.currentTarget),children:(0,p.jsxs)(`span`,{className:`review-comment-row__layout`,children:[(0,p.jsx)(a,{src:e.avatarUrl??m,size:20}),(0,p.jsx)(`span`,{className:`review-comment-row__content`,children:(0,p.jsxs)(`span`,{className:`review-comment-row__copy`,children:[(0,p.jsxs)(`span`,{className:`thread-sample__heading`,children:[(0,p.jsx)(`strong`,{className:`review-comment-row__author`,children:e.author}),e.status===`open`?null:(0,p.jsx)(`span`,{className:`thread-sample__status${e.status===`ready`?` thread-sample__status--ready`:``}`,children:f.workStatus(e.status)})]}),(0,p.jsx)(`span`,{className:`review-comment-row__body`,children:e.body})]})})]})}),(0,p.jsxs)(`div`,{className:`thread-sample__metadata`,children:[(0,p.jsx)(`span`,{children:e.target}),(0,p.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,p.jsx)(`code`,{children:e.path})]}),n>0?(0,p.jsxs)(`span`,{className:`thread-sample__follow-ups`,children:[(0,p.jsx)(ne,{size:12,"aria-hidden":`true`}),f.followUps(n)]}):null,(0,p.jsx)(`div`,{className:`thread-sample__menu`,children:(0,p.jsxs)(d.ActionMenu,{selectionVariant:`none`,size:`small`,menuAlignment:`end`,disabled:!!C.trim()||D,children:[(0,p.jsx)(d.ActionMenu.IconButton,{icon:t,"aria-label":`${f.actions}: ${e.id}`,variant:`invisible`,onClick:t=>{R.current=t.currentTarget,z.current={identity:g,id:e.id,revision:e.revision}}}),(0,p.jsxs)(d.ActionMenu.Overlay,{"aria-label":`${f.actions}: ${e.id}`,children:[h&&e.retryStatus?(0,p.jsx)(d.ActionMenu.Item,{value:`retry`,disabled:_,className:`thread-sample__menu-item`,onClick:()=>{Ne(e)},children:e.retryStatus===`sent`?f.returnToActive:f.retry}):null,e.status===`ready`?(0,p.jsx)(d.ActionMenu.Item,{value:`resolve`,className:`thread-sample__menu-item`,disabled:_,leadingVisual:(0,p.jsx)(se,{size:16}),onClick:()=>{Me(e)},children:f.markResolved}):null,(0,p.jsx)(d.ActionMenu.Item,{value:`delete`,className:`thread-sample__menu-item thread-sample__delete`,disabled:_,leadingVisual:(0,p.jsx)(re,{size:16}),onClick:()=>{_||C.trim()||D||(M(g),A(e))},children:f.delete})]})]})})]},e.id)})]})]}),(0,p.jsx)(`div`,{ref:Te,className:`canvas-conversation-shell thread-sample__surface`,hidden:!r}),(0,p.jsx)(`div`,{className:`canvas-conversation-shell thread-sample__markers`,hidden:!r,children:e.filter(e=>e.id===y||X.includes(e)).filter(e=>e.point).map(e=>(0,p.jsx)(`button`,{type:`button`,className:`review-comment-marker thread-sample__marker${y===e.id?` review-comment-marker--selected`:``}`,"data-improvement-thread-id":e.id,"aria-label":f.point(e.id),"aria-expanded":y===e.id,disabled:!!C.trim()||D,style:{left:e.point.x,top:e.point.y},onClick:t=>Ae(e.id,t.currentTarget),children:(0,p.jsx)(he,{participants:[{login:e.author,name:null,avatarUrl:e.avatarUrl??m}],size:`small`})},e.id))}),(0,p.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:Se}),k?(0,p.jsxs)(de,{title:f.deleteTitle,closeLabel:f.comments.cancelEditLabel,onClose:()=>A(null),returnFocusRef:R,children:[U?(0,p.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:f.changedIdentity}):null,K?(0,p.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:f.removed}):null,v?(0,p.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:v}):null,(0,p.jsx)(`blockquote`,{className:`thread-sample__quote`,children:k.body}),(0,p.jsxs)(`div`,{className:`thread-sample__delete-actions`,children:[(0,p.jsx)(d.Button,{size:`small`,variant:`secondary`,onClick:()=>A(null),children:f.comments.cancelEditLabel}),(0,p.jsx)(d.Button,{size:`small`,variant:`primary`,className:`thread-sample__delete-confirm`,disabled:_||U||K,onClick:async()=>{if(!(_||U||K)&&await c(k)){let e=X.find(e=>e.id!==k.id);R.current=(e?B.current.get(e.id):null)??L.current,y===k.id&&Z(),A(null)}},children:f.delete})]})]}):null]})}export{f as n,h as t}; \ No newline at end of file +`,m=ie(),h=`data:image/svg+xml,${encodeURIComponent(ge)}`,_e=`data:image/svg+xml,${encodeURIComponent((0,he.renderToStaticMarkup)((0,m.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`16`,height:`16`,viewBox:`0 0 16 16`,children:(0,m.jsx)(r,{size:16,fill:`white`})})))}`;function g({threads:e,open:n,active:r=n,onOpen:i,onClose:a,onFollowUp:ie,onResolve:c,onDelete:u,onFix:he,onSelect:ge,onInteractionChange:g,onRetry:_,identity:v,busy:y=!1,activeBatch:ve=!1,error:b=``,returnFocusRef:ye,controls:be=!0}){let[x,S]=(0,d.useState)(null),[C,w]=(0,d.useState)(null),[T,E]=(0,d.useState)(``),[D,O]=(0,d.useState)(!1),[k,A]=(0,d.useState)(!1),[j,M]=(0,d.useState)(null);(0,d.useLayoutEffect)(()=>{g?.(x!==null||j!==null)},[x,j,g]);let[N,P]=(0,d.useState)(v),[xe,Se]=(0,d.useState)(``),[F,Ce]=(0,d.useState)(`active`),[I,we]=(0,d.useState)(null),[L]=(0,d.useState)(()=>document.querySelector(`#canvas-improvement-controls`)),R=(0,d.useRef)(null),z=ye??R,B=(0,d.useRef)(null),V=(0,d.useRef)(null),H=(0,d.useRef)(new Map),U=(0,d.useRef)(null),W=(0,d.useRef)(!1),Te=e.find(e=>e.id===x),G=(x!==null||j!==null)&&v!==N,K=v===N?Te??C:C,q=x!==null&&!Te,J=j!==null&&!e.some(e=>e.id===j.id),{cardRef:Y,position:Ee}=ce({anchorPoint:{x:12,y:12},anchorSelector:x===null?void 0:`[data-improvement-thread-id="${x}"]`,layoutKey:`${x}:${k}:${K?.messages.length}:${K?.status}`}),X=e.reduce((e,t)=>e+Number(t.originalPending)+t.messages.filter(e=>e.pending).length,0),De=new TextEncoder().encode(T).length>1e4,Oe=[{value:`active`,label:p.allActive},{value:`ready`,label:p.ready},{value:`resolved`,label:p.resolved}],ke=Oe.find(e=>e.value===F).label,Z=e.filter(e=>F===`resolved`?e.status===`resolved`:F===`ready`?e.status===`ready`:e.status!==`resolved`);(0,d.useLayoutEffect)(()=>{x===null?U.current!==null&&((B.current?.isConnected?B.current:H.current.get(U.current)??z.current)?.focus(),U.current=null):k?Y.current?.querySelector(`.review-confirmation-panel button`)?.focus():G||q?Y.current?.querySelector(`.thread-sample__close`)?.focus():Y.current?.querySelector(`textarea`)?.focus()},[x,k,Y,z,G,q]);let Q=(0,d.useCallback)(()=>{U.current=x,S(null),w(null),E(``),A(!1),W.current&&=(a(),z.current?.focus(),!1)},[x,a,z]),$=(0,d.useCallback)(()=>{T.trim()?A(!0):x===null?(a(),z.current?.focus()):Q()},[T,x,Q,a,z]);(0,d.useEffect)(()=>{if(x===null)return;function e(){document.querySelector(`[role="menu"]`)||j||(k?(W.current=!1,A(!1)):$())}function t(t){t.key!==`Escape`||t.defaultPrevented||t.isComposing||t.target instanceof Element&&t.target.closest(`[role="menu"], dialog`)||(t.preventDefault(),e())}return document.addEventListener(`keydown`,t),window.addEventListener(`replica:review-dismiss`,e),()=>{document.removeEventListener(`keydown`,t),window.removeEventListener(`replica:review-dismiss`,e)}},[x,k,j,$]);function Ae(t,n){T.trim()||k||(B.current=n,P(v),w(e.find(e=>e.id===t)??null),S(t),ge?.(t))}async function je(){if(!K||!T.trim()||De||G||q||y||D)return;let e=T.trim();O(!0);try{if(!await ie(K,e))return;E(t=>t.trim()===e?``:t),Se(p.added)}finally{O(!1)}}async function Me(e){if(V.current?.identity!==v||V.current.id!==e.id||V.current.revision!==e.revision||e.status!==`ready`||y||T.trim()||k)return;let t=B.current;await c(e)&&!t?.isConnected&&z.current?.focus()}async function Ne(e){V.current?.identity!==v||V.current.id!==e.id||V.current.revision!==e.revision||!_||!e.retryStatus||y||T.trim()||k||await _(e)}let Pe=(0,m.jsx)(f.Button,{ref:R,size:`small`,variant:`secondary`,className:`canvas-toolbar-compact-button`,leadingVisual:(0,m.jsx)(ee,{size:16}),"aria-label":p.open,title:p.open,"aria-expanded":n,onClick:i,children:(0,m.jsx)(`span`,{className:`canvas-toolbar-button-label`,children:p.title})});return(0,m.jsxs)(m.Fragment,{children:[be?L?(0,me.createPortal)(Pe,L):Pe:null,(0,m.jsxs)(oe,{title:p.title,open:n,closeLabel:p.close,onClose:()=>{x===null?(a(),z.current?.focus()):(W.current=!0,$())},closeDisabled:k,className:`thread-sample`,contentClassName:`thread-sample__content`,children:[b?(0,m.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:b}):null,(0,m.jsx)(`div`,{className:`thread-sample__toolbar`,children:(0,m.jsxs)(`div`,{className:`thread-sample__filters`,children:[(0,m.jsxs)(f.ActionMenu,{size:`small`,selectionVariant:`single`,menuAlignment:`start`,onSelect:Ce,children:[(0,m.jsx)(f.ActionMenu.Button,{size:`small`,variant:`secondary`,"aria-label":`${p.filter}: ${ke}`,children:ke}),(0,m.jsx)(f.ActionMenu.Overlay,{"aria-label":p.filter,children:Oe.map(e=>(0,m.jsx)(f.ActionMenu.Item,{value:e.value,selected:F===e.value,role:`menuitemradio`,onKeyDownCapture:e=>{(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.click())},children:e.label},e.value))})]}),F===`active`?(0,m.jsx)(f.Button,{size:`small`,variant:`primary`,className:`thread-sample__fix-all`,leadingVisual:(0,m.jsx)(re,{size:16}),disabled:!X||!!T.trim()||k||y||ve,"aria-busy":y,"aria-label":p.simulate(X),onClick:()=>{he()},children:(0,m.jsxs)(`span`,{className:`thread-sample__fix-label`,children:[p.fix,(0,m.jsx)(ue,{"aria-hidden":`true`,children:X})]})}):null]})}),K&&I?(0,me.createPortal)((0,m.jsx)(fe,{ref:Y,"aria-label":p.conversation,anchored:!0,position:Ee,className:`thread-sample__conversation`,onKeyDown:e=>{e.key===`Escape`&&!e.defaultPrevented&&!e.nativeEvent.isComposing&&!(e.target instanceof Element&&e.target.closest(`[role="menu"]`))&&(e.preventDefault(),k?(W.current=!1,A(!1)):$())},children:(0,m.jsxs)(`div`,{className:`review-thread-conversation__layout`,children:[(0,m.jsxs)(`header`,{className:`review-thread-conversation__header`,children:[(0,m.jsx)(f.Heading,{as:`h3`,size:`6`,children:p.conversation}),K.status===`ready`?(0,m.jsx)(f.Button,{size:`small`,variant:`secondary`,className:`thread-sample__resolve`,disabled:!!T.trim()||y||G||q,leadingVisual:(0,m.jsx)(o,{size:16}),onClick:()=>{c(K)},children:p.resolve}):null,(0,m.jsx)(se,{icon:ae,size:`small`,variant:`invisible`,"aria-label":p.back,className:`thread-sample__close`,onClick:$})]}),G?(0,m.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:p.changedIdentity}):null,q?(0,m.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:p.removed}):null,b?(0,m.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:b}):null,K.point?null:(0,m.jsx)(`p`,{role:`status`,className:`thread-sample__target-status`,children:p.targetUnavailable}),(0,m.jsxs)(`div`,{className:`review-thread-conversation__messages`,children:[(0,m.jsxs)(`article`,{className:`review-thread-message`,children:[(0,m.jsx)(l,{visual:(0,m.jsx)(s,{src:K.avatarUrl??h,size:28}),author:K.author}),(0,m.jsx)(`p`,{className:`review-thread-message__body`,children:K.body})]}),K.messages.map(e=>(0,m.jsxs)(`article`,{className:`review-thread-message`,children:[(0,m.jsx)(l,{visual:e.role===`copilot`?(0,m.jsx)(s,{src:_e,size:28,className:`thread-sample__copilot-avatar`}):(0,m.jsx)(s,{src:e.author?e.avatarUrl??h:K.avatarUrl??h,size:28}),author:e.role===`copilot`?p.copilot:e.author??K.author,metadata:e.role===`author`&&e.status&&e.status!==`ready`?(0,m.jsx)(`span`,{children:p.workStatus(e.status)}):void 0}),(0,m.jsx)(`p`,{className:`review-thread-message__body`,children:e.body})]},e.id))]}),(0,m.jsx)(`div`,{className:`review-thread-conversation__footer`,children:(0,m.jsx)(de,{blockedLabel:null,confirmingDiscard:k,replyDraft:T,replyBodyTooLong:De,replyFailed:!1,replyDisabled:G||q,replying:D,submitDisabled:y,copy:p.comments,onKeepDraft:()=>{W.current=!1,A(!1)},onDiscardDraft:Q,onSubmit:()=>{je()},onDraftChange:E})})]})}),I):null,(0,m.jsxs)(`div`,{className:`thread-sample__list`,children:[Z.length===0?(0,m.jsx)(`p`,{className:`thread-sample__empty`,children:p.empty}):null,Z.map(e=>{let n=e.messages.filter(e=>e.role===`author`).length;return(0,m.jsxs)(`article`,{className:`review-comment-row thread-sample__card${e.status===`resolved`?` thread-sample__card--resolved`:``}`,children:[(0,m.jsx)(`button`,{ref:t=>{t?H.current.set(e.id,t):H.current.delete(e.id)},className:`review-comment-row__button thread-sample__card-button`,"aria-label":`Open improvement: ${e.body}`,"aria-expanded":x===e.id,disabled:!!T.trim()||k,onClick:t=>Ae(e.id,t.currentTarget),children:(0,m.jsxs)(`span`,{className:`review-comment-row__layout`,children:[(0,m.jsx)(s,{src:e.avatarUrl??h,size:20}),(0,m.jsx)(`span`,{className:`review-comment-row__content`,children:(0,m.jsxs)(`span`,{className:`review-comment-row__copy`,children:[(0,m.jsxs)(`span`,{className:`thread-sample__heading`,children:[(0,m.jsx)(`strong`,{className:`review-comment-row__author`,children:e.author}),e.status===`open`?null:(0,m.jsx)(`span`,{className:`thread-sample__status${e.status===`ready`?` thread-sample__status--ready`:``}`,children:p.workStatus(e.status)})]}),(0,m.jsx)(`span`,{className:`review-comment-row__body`,children:e.body})]})})]})}),(0,m.jsxs)(`div`,{className:`thread-sample__metadata`,children:[(0,m.jsx)(`span`,{children:e.target}),(0,m.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,m.jsx)(`code`,{children:e.path})]}),n>0?(0,m.jsxs)(`span`,{className:`thread-sample__follow-ups`,children:[(0,m.jsx)(te,{size:12,"aria-hidden":`true`}),p.followUps(n)]}):null,(0,m.jsx)(`div`,{className:`thread-sample__menu`,children:(0,m.jsxs)(f.ActionMenu,{selectionVariant:`none`,size:`small`,menuAlignment:`end`,disabled:!!T.trim()||k,children:[(0,m.jsx)(f.ActionMenu.IconButton,{icon:t,"aria-label":`${p.actions}: ${e.id}`,variant:`invisible`,onClick:t=>{B.current=t.currentTarget,V.current={identity:v,id:e.id,revision:e.revision}}}),(0,m.jsxs)(f.ActionMenu.Overlay,{"aria-label":`${p.actions}: ${e.id}`,children:[_&&e.retryStatus?(0,m.jsx)(f.ActionMenu.Item,{value:`retry`,disabled:y,className:`thread-sample__menu-item`,onClick:()=>{Ne(e)},children:e.retryStatus===`sent`?p.returnToActive:p.retry}):null,e.status===`ready`?(0,m.jsx)(f.ActionMenu.Item,{value:`resolve`,className:`thread-sample__menu-item`,disabled:y,leadingVisual:(0,m.jsx)(o,{size:16}),onClick:()=>{Me(e)},children:p.markResolved}):null,(0,m.jsx)(f.ActionMenu.Item,{value:`delete`,className:`thread-sample__menu-item thread-sample__delete`,disabled:y,leadingVisual:(0,m.jsx)(ne,{size:16}),onClick:()=>{y||T.trim()||k||(P(v),M(e))},children:p.delete})]})]})})]},e.id)})]})]}),(0,m.jsx)(`div`,{ref:we,className:`canvas-conversation-shell thread-sample__surface`,hidden:!r}),(0,m.jsx)(`div`,{className:`canvas-conversation-shell thread-sample__markers`,hidden:!r,children:e.filter(e=>e.id===x||Z.includes(e)).filter(e=>e.point).map(e=>(0,m.jsx)(`button`,{type:`button`,className:`review-comment-marker thread-sample__marker${x===e.id?` review-comment-marker--selected`:``}`,"data-improvement-thread-id":e.id,"aria-label":p.point(e.id),"aria-expanded":x===e.id,disabled:!!T.trim()||k,style:{left:e.point.x,top:e.point.y},onClick:t=>Ae(e.id,t.currentTarget),children:(0,m.jsx)(pe,{participants:[{login:e.author,name:null,avatarUrl:e.avatarUrl??h}],size:`small`})},e.id))}),(0,m.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:xe}),j?(0,m.jsxs)(le,{title:p.deleteTitle,closeLabel:p.comments.cancelEditLabel,onClose:()=>M(null),returnFocusRef:B,children:[G?(0,m.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:p.changedIdentity}):null,J?(0,m.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:p.removed}):null,b?(0,m.jsx)(`p`,{role:`alert`,className:`thread-sample__error`,children:b}):null,(0,m.jsx)(`blockquote`,{className:`thread-sample__quote`,children:j.body}),(0,m.jsxs)(`div`,{className:`thread-sample__delete-actions`,children:[(0,m.jsx)(f.Button,{size:`small`,variant:`secondary`,onClick:()=>M(null),children:p.comments.cancelEditLabel}),(0,m.jsx)(f.Button,{size:`small`,variant:`primary`,className:`thread-sample__delete-confirm`,disabled:y||G||J,onClick:async()=>{if(!(y||G||J)&&await u(j)){let e=Z.find(e=>e.id!==j.id);B.current=(e?H.current.get(e.id):null)??z.current,x===j.id&&Q(),M(null)}},children:p.delete})]})]}):null]})}export{p as n,g as t}; \ No newline at end of file diff --git a/.github/extensions/replica-prototype/assets/renderer.js b/.github/extensions/replica-prototype/assets/renderer.js index 5775b13e..7acaef95 100644 --- a/.github/extensions/replica-prototype/assets/renderer.js +++ b/.github/extensions/replica-prototype/assets/renderer.js @@ -1,8 +1,8 @@ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["renderer-improvement-notes-prototype.js","renderer-rolldown-runtime.js","renderer-vendor.js","renderer-prototype-canvas-improvement-threads.js","renderer-improvement-notes-vendor.js","renderer-prototype-canvas-thread-sample.js"])))=>i.map(i=>d[i]); -import{r as e,t}from"./renderer-rolldown-runtime.js";import{A as n,B as r,C as i,D as a,E as o,F as s,G as c,H as l,I as u,J as d,K as f,L as p,N as m,O as h,R as g,S as _,T as v,U as y,V as b,W as x,X as S,Y as C,_ as w,a as T,c as E,d as D,f as O,g as k,h as A,i as j,j as M,k as N,l as P,m as F,n as ee,o as I,p as L,q as te,r as ne,s as R,t as re,u as z,v as ie,w as ae,x as oe,y as B,z as se}from"./renderer-vendor.js";var V=e(S(),1),ce=d(),H=f(),U=te();function le({size:e=`medium`,className:t,label:n}){return(0,U.jsx)(`span`,{role:n?`status`:void 0,"aria-label":n,"aria-hidden":!n||void 0,className:`hub-spinner hub-spinner--${e}${t?` ${t}`:``}`})}function W({className:e,...t}){return(0,U.jsx)(`span`,{...t,className:`hub-visually-hidden${e?` ${e}`:``}`})}function G(e){let t=(0,V.useId)(),{as:n,href:r,ref:i,icon:a,description:o,loading:s=!1,size:c=`medium`,variant:l=`default`,className:u,...d}=e,f=`hub-icon-button${c===`small`?` hub-icon-button--small`:``}${l===`invisible`?` hub-icon-button--invisible`:``}${l===`danger`?` hub-icon-button--danger`:``}${u?` ${u}`:``}`,p=l===`invisible`?`subtle`:`secondary`,m=!(!o||d.title||d[`aria-describedby`]||`disabled`in d&&d.disabled),h=[d[`aria-describedby`],o&&!m?t:void 0].filter(Boolean).join(` `)||void 0,g=d.title??(m?void 0:o??d[`aria-label`]),_=o&&!m?(0,U.jsx)(W,{id:t,children:o}):null,v=s?(0,U.jsx)(le,{decorative:!0,size:`small`}):(0,U.jsx)(a,{size:16}),y=s?!0:d[`aria-busy`];if(n===`a`){let e=i,t=(0,U.jsx)(H.Button,{...d,ref:e,as:`a`,href:r,leadingVisual:v,variant:p,size:c,className:f,"aria-busy":y,"aria-describedby":h,title:g,children:_});return m&&o?(0,U.jsx)(H.Tooltip,{ref:i,text:o,type:`description`,children:t}):t}let b=(0,U.jsx)(H.Button,{...d,ref:i,type:d.type??`button`,leadingVisual:v,variant:p,size:c,className:f,"aria-busy":y,"aria-describedby":h,title:g,children:_});return m&&o?(0,U.jsx)(H.Tooltip,{ref:i,text:o,type:`description`,children:b}):b}function ue({title:e,closeLabel:t,onClose:n,returnFocusRef:r,descriptionId:i,className:a,children:o}){let s=(0,V.useRef)(null),c=(0,V.useId)();return(0,V.useLayoutEffect)(()=>{let e=s.current,t=r?.current??(document.activeElement instanceof HTMLElement?document.activeElement:null);return e?.showModal(),()=>{e?.close(),(r?.current??t)?.focus()}},[r]),(0,U.jsxs)(`dialog`,{ref:s,"aria-labelledby":c,"aria-describedby":i,className:a?`canvas-dialog ${a}`:`canvas-dialog`,onCancel:e=>{e.preventDefault(),n()},onClick:e=>{if(e.target!==e.currentTarget)return;let{left:t,right:r,top:i,bottom:a}=e.currentTarget.getBoundingClientRect();(e.clientXr||e.clientYa)&&n()},children:[(0,U.jsxs)(`header`,{className:`canvas-dialog-header`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`5`,id:c,children:e}),(0,U.jsx)(G,{variant:`default`,size:`small`,icon:z,"aria-label":t,onClick:n})]}),o]})}var K={improvementNotesLoading:`Loading improvement notes...`,localCommentsSaved:`Comments stay on this device until a Build with matching content is published and the canvas syncs them to Hub.`,commentPreparationFailed:`Hub could not prepare this comment.`,commentRefreshFailed:e=>`The comment was saved, but Hub could not be refreshed: ${e}`,commentLiveUpdatesPaused:`Live updates paused; checking every 30 seconds.`,mentionSuggestions:`Mention suggestions`,mentionSuggestionsError:`Mention suggestions are unavailable. Try again.`,mentionSuggestionsLoading:`Loading people...`,mentionSuggestionsEmpty:`No matching people. You can type a GitHub login to check it when sending.`,mentionLimit:`Each message can mention at most 10 distinct people.`,controls:`Controls`,controlsMove:`Move controls`,controlsMoveHint:`Drag to move. Use arrow keys, or Shift and arrow keys for smaller steps.`,controlsCollapse:`Collapse controls`,controlsExpand:`Expand controls`,controlsCollapseGroup:e=>`Collapse ${e}`,controlsExpandGroup:e=>`Expand ${e}`,controlsDescription:`Settings stay in this prototype's URL. The app may paint before Controls apply declared defaults.`,controlsConnecting:`Connecting controls...`,controlsEmpty:`No active controls. This prototype may have no declaration or this route may not mount controls.`,controlsLearnMore:`Learn more`,controlsMissingRuntime:`No supported controls runtime found.`,controlsLocalMissingRuntime:`Local controls couldn't connect.`,controlsLocalConnectionFailed:`The preview has not responded to controls. Retry the connection or ask Copilot to diagnose the cause.`,controlsLocalStorageFailed:`Controls could not be saved in the prototype URL. Changes remain in memory.`,controlsDiagnose:`Diagnose with Copilot`,controlsFix:`Fix with Copilot`,controlsDiagnostics:`Technical details`,controlsUnavailable:e=>`${e} is unavailable`,controlsNotApplied:e=>`${e} could not be applied`,controlsDiagnosisRequested:`Requested in chat`,controlsDiagnosisFailed:`Could not request a diagnosis. Try again.`,controlsUnsupportedRuntime:`This controls runtime version is unsupported. Upgrade only after an approved release.`,controlsInvalid:`The Controls definitions are invalid. Fix controls.replica.json and reload.`,controlsScopeError:(e,t)=>`Controls scope "${e}" did not connect. ${t}`,controlsRetry:`Retry connection`,controlsRetryStorage:`Retry saving`,controlsResetAll:`Reset all controls`,controlsRegion:`Prototype controls`,controlsActionBusy:` - Working...`,controlsActionUnavailable:`No mounted action handler.`,controlsValueNotApplied:`This value was not applied.`,browserNavigation:`Prototype navigation`,browserBack:`Back`,browserForward:`Forward`,browserReload:`Reload preview`,browserAddress:`Prototype address`,browserAddressInvalid:`Enter a valid URL or route.`,browserAddressOrigin:`The address must stay on this prototype's origin.`,browserOpenTab:`Open preview in browser`,browserAppearance:`Preview appearance`,browserLight:`Light appearance`,browserDark:`Dark appearance`,commentingUnavailable:`Commenting needs attention`,commentingDescription:`The canvas could not connect to the preview's commenting bridge.`,closeCommentingDialog:`Close commenting dialog`,commentingFix:`Fix with Copilot`,commentingFixRequested:`Requested in chat`,commentingDismiss:`Dismiss`,commentingMissing:`The preview has not responded through its local proxy. Check that the selected server is running, then reopen the canvas. Script or framing policies, certificate errors, and origin-dependent apps can prevent connection. A Vite plugin or server restart is not required to connect.`,commentingIncompatible:`The preview responded with an incompatible commenting protocol. Update the installed Replica extension and reopen the canvas, or use Fix with Copilot to check the preview connection.`,connectToHub:`Connect to the Hub`,closeConnectionDialog:`Close connection dialog`,connectionDescription:`Connecting to the hub lets you share the prototype with others and enables commenting.`,connectionBeforePublishing:`Connect to the hub before publishing this prototype.`,connectionRepositoryRequired:`Open a repository with a GitHub origin before connecting.`,connectionHubRequired:`Enter and save a Hub URL before connecting.`,connectionOpeningBrowser:`Opening browser...`,connectionApproval:`Browser approval`,connectionWaiting:`Make sure your browser shows the same code`,connectionApprovalExpired:`The approval expired or was declined. Connect again to retry.`,connectionBrowserFailed:e=>`Could not open your browser. Open or copy the approval link below. ${e}`,hubUrl:`Hub URL`,editHubUrl:`Edit Hub URL`,saveHub:`Save Hub`,disconnectFailed:(e,t)=>`Could not disconnect from ${e}: ${t} The previous connection may still be active. Save another Hub URL to switch this canvas locally, or retry Disconnect Hub.`,resetHubUrl:`Reset to repository Hub URL`,resetHubUnavailable:`No repository Hub URL is available. Enter a URL manually or retry reset.`,hubHttpsHint:`Remote Hubs require HTTPS`,copyApprovalLink:`Copy Hub approval link`,approvalLinkCopied:`Approval link copied`,approvalCopyFailed:`Could not copy the link. Copy the Connect to the hub link manually.`,invalidResponse:`The extension returned an invalid response.`,startPage:`Start page`,prototypeFrameTitle:e=>`${e} prototype`,startPageOrigin:`Hub returned a start page outside the prototype.`,hubStatusUnavailable:e=>`Hub status unavailable: ${e}`,hubBuildImported:`Hub imported this Build.`,hubBuildMissing:`Hub has not imported a successful registered Build.`,hubPublicationUnavailable:`Connect to Hub to verify publication.`,editDetails:`Edit details`,improveContext:`Improve context`,improveContextDescription:`Run a skill to improve repository context from user feedback.`,feedbackReviewFailed:e=>`Could not request a feedback review: ${e}`,moreActions:`More actions`,startPageHint:`Paste a prototype URL or route. Leave blank to start at /.`,requestFailed:`The request failed.`,statusUnavailable:`Publish status unavailable.`,publishRequestPending:`Waiting for the current commit to run through the publish workflow.`,waitingForHubImport:`The workflow completed. Waiting for Hub to import this Build.`,workingTreeChanged:`Uncommitted changes`,workingTreeClean:`Working tree clean`,buildDetails:`Build details`,latestBuild:`Latest Build`,buildTitle:e=>`Build #${e}`,buildCommit:`Commit`,unknownCommitAuthor:`Unknown`,showBuildHistory:`Show build history`,closeBuildDetails:`Close build details`,branch:`Branch`,sessionId:`Session ID`,comparison:`Branch comparison`,comparisonNeedsRefresh:`Branch comparison unavailable until Git stats refresh.`,upToDate:`Up to date`,commitsBehind:e=>`${e} ${e===1?`commit`:`commits`} behind`,copyBranch:`Copy branch`,copySessionId:`Copy session ID`,branchCopied:`Branch copied`,sessionIdCopied:`Session ID copied`,buildDetailsCopyFailed:e=>`${e} could not be copied. Select it and copy it manually.`,unavailable:`Unavailable`,publishLabels:{succeeded:`Awaiting Hub`,failed:`Retry`,in_progress:`Publishing`,not_published:`Publish`,published:`Published`,requested:`Requested`,unavailable:`Publish`}};function de({onClose:e,state:t,titleButtonRef:n}){let[i,a]=(0,V.useState)(null),[o,s]=(0,V.useState)(null),c=t.stats.branchError?void 0:t.stats.branch,l=t.sessionId,u=t.stats.comparison;async function d(e,t){try{await navigator.clipboard.writeText(e),a(t),s(null)}catch{a(null),s(t===`branch`?K.branch:K.sessionId)}}function f(e,t){if(!e)return null;let n=t===`branch`?K.copyBranch:K.copySessionId,a=t===`branch`?K.branchCopied:K.sessionIdCopied;return(0,U.jsx)(H.Button,{type:`button`,className:`canvas-icon-button`,variant:`subtle`,size:`small`,leadingVisual:i===t?(0,U.jsx)(r,{size:16}):(0,U.jsx)(m,{size:16}),"aria-label":i===t?a:n,title:i===t?a:n,onClick:()=>void d(e,t),children:(0,U.jsx)(`span`,{className:`visually-hidden`,children:n})})}return(0,U.jsxs)(ue,{title:K.buildDetails,closeLabel:K.closeBuildDetails,className:`build-details-dialog`,returnFocusRef:n,onClose:e,children:[(0,U.jsxs)(`dl`,{className:`build-details-list`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`dt`,{children:K.branch}),(0,U.jsxs)(`dd`,{children:[(0,U.jsx)(N,{size:16,"aria-hidden":`true`}),(0,U.jsx)(`code`,{children:c||t.stats.branchError||K.unavailable}),f(c,`branch`)]})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`dt`,{children:K.sessionId}),(0,U.jsxs)(`dd`,{children:[(0,U.jsx)(`code`,{children:l||K.unavailable}),f(l,`sessionId`)]})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`dt`,{children:u?.branch?`Behind ${u.branch}${u.source===`local`?` (local)`:``}`:K.comparison}),(0,U.jsx)(`dd`,{children:u?.error||(u?.behind===0?K.upToDate:u?.behind==null?K.unavailable:K.commitsBehind(u.behind))})]})]}),(0,U.jsx)(`span`,{role:`status`,"aria-live":`polite`,className:`visually-hidden`,children:i===`branch`?`${K.branchCopied}.`:i===`sessionId`?`${K.sessionIdCopied}.`:``}),o?(0,U.jsx)(`span`,{role:`alert`,className:`build-details-copy-error`,children:K.buildDetailsCopyFailed(o)}):null]})}function fe({pairing:e}){let[t,n]=(0,V.useState)(`idle`),i=(0,V.useRef)(null);(0,V.useEffect)(()=>{i.current?.querySelector(`a`)?.focus()},[]);async function a(){try{await navigator.clipboard.writeText(e.verificationUrl),n(`copied`)}catch{n(`failed`)}}return(0,U.jsxs)(`section`,{className:`hub-connection-approval`,"aria-label":K.connectionApproval,children:[(0,U.jsxs)(`p`,{role:`status`,children:[K.connectionWaiting,` `,(0,U.jsx)(`strong`,{children:e.userCode}),`.`]}),(0,U.jsxs)(`div`,{ref:i,className:`hub-connection-approval-actions`,role:`group`,"aria-label":K.connectionApproval,children:[(0,U.jsx)(H.Button,{as:`a`,variant:`primary`,size:`medium`,href:e.verificationUrl,target:`_blank`,rel:`noopener noreferrer`,children:K.connectToHub}),(0,U.jsx)(G,{icon:t===`copied`?r:m,size:`medium`,className:`hub-connection-approval-copy`,"aria-label":t===`copied`?K.approvalLinkCopied:K.copyApprovalLink,onClick:()=>void a()})]}),(0,U.jsx)(W,{role:`status`,children:t===`copied`?K.approvalLinkCopied:``}),t===`failed`?(0,U.jsx)(`p`,{role:`alert`,children:K.approvalCopyFailed}):null]})}function pe({status:e,pairing:t,connecting:n,error:r,onConnect:i,onSelectHub:a,onResetHub:o,onClose:s,hubButtonRef:c}){let l=(0,V.useId)(),[u,d]=(0,V.useState)(null),[f,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(!1),[v,y]=(0,V.useState)(!1),[b,x]=(0,V.useState)(``),S=(0,V.useRef)(null),C=(0,V.useRef)(null),w=f||!e?.hubOrigin||u!==null&&!m,T=(0,V.useRef)(w),E=u??e?.hubOrigin??``,D=n||g||v,O=!!t||n;(0,V.useEffect)(()=>{w&&!O?S.current?.focus():T.current&&!O&&C.current?.focus(),T.current=w},[w,O]),(0,V.useEffect)(()=>{if(f||u===null||!m||!e?.hubOrigin)return;let t=window.setTimeout(()=>d(null),0);return()=>window.clearTimeout(t)},[u,f,m,e?.hubOrigin]);async function k(){if(!D){_(!0),x(``);try{await a(E),d(null),p(!1)}catch(e){x(e instanceof Error?e.message:String(e))}finally{_(!1)}}}async function A(){if(!D&&o){y(!0),x(``);try{d(await o()),p(!!e?.hubOrigin)}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(!1)}}}return(0,U.jsxs)(ue,{title:K.connectToHub,closeLabel:K.closeConnectionDialog,onClose:s,returnFocusRef:c,children:[(0,U.jsx)(`p`,{children:K.connectionDescription}),b||r?(0,U.jsx)(`p`,{role:`alert`,children:b||r}):null,(0,U.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),!D&&(!O&&w&&(f||e?.hubOrigin)?k():(x(``),e?.hubOrigin||h(!0),i(e?.hubOrigin?void 0:E)))},children:[!O&&(w?(0,U.jsxs)(`div`,{className:`hub-connection-origin-field`,children:[(0,U.jsx)(`label`,{htmlFor:l,children:K.hubUrl}),(0,U.jsxs)(`div`,{className:`hub-connection-origin-input`,children:[(0,U.jsx)(H.TextInput,{ref:S,id:l,type:`url`,value:E,onChange:e=>{h(!1),d(e.target.value)},required:!0,fullWidth:!0,disabled:D,placeholder:`https://hub.example.com`}),o?(0,U.jsx)(G,{icon:L,variant:`invisible`,size:`small`,"aria-label":K.resetHubUrl,disabled:D,"aria-busy":v,onClick:()=>void A()}):null]}),f||e?.hubOrigin?(0,U.jsx)(H.Button,{type:`submit`,variant:`subtle`,size:`small`,disabled:D,children:K.saveHub}):null]}):(0,U.jsxs)(`div`,{className:`hub-connection-origin`,children:[(0,U.jsx)(`a`,{href:e?.hubOrigin&&new URL(e.hubOrigin).origin,target:`_blank`,rel:`noopener noreferrer`,children:e?.hubOrigin}),(0,U.jsx)(G,{ref:C,icon:oe,variant:`invisible`,size:`small`,"aria-label":K.editHubUrl,disabled:D,onClick:()=>{x(``),p(!0),d(e?.hubOrigin??``)}})]})),t?(0,U.jsx)(fe,{pairing:t},t.verificationUrl):null,t?null:(0,U.jsx)(H.Button,{type:`submit`,variant:`primary`,disabled:D||!e?.repository||!O&&w&&(f||!!e?.hubOrigin),children:n?K.connectionOpeningBrowser:K.connectToHub})]})]})}function me({title:e,description:t,children:n,action:r,variant:i,layout:o,onDismiss:s,dismissLabel:l,className:u,...d}){let f=i===`critical`?A:i===`success`?se:i===`info`?a:c;return(0,U.jsxs)(`div`,{...d,role:i===`critical`||i===`warning`?`alert`:`status`,className:`hub-alert hub-alert--${i}${o===`compact`?` hub-alert--compact`:``}${u?` ${u}`:``}`,children:[(0,U.jsx)(f,{className:`hub-alert__icon`,size:20,"aria-hidden":`true`}),(0,U.jsxs)(`div`,{className:`hub-alert__content`,children:[(0,U.jsxs)(H.Text,{as:`p`,size:`100`,className:`hub-alert__message`,children:[(0,U.jsx)(`strong`,{className:`hub-alert__title`,children:e}),t?(0,U.jsx)(`span`,{className:`hub-alert__description`,children:t}):null]}),n]}),r||s?(0,U.jsxs)(`div`,{className:`hub-alert__action`,children:[r,s&&l?(0,U.jsx)(G,{icon:z,"aria-label":l,title:l,variant:`invisible`,size:`small`,onClick:s}):null]}):null]})}var q={title:`Publish uncommitted changes?`,description:`Do you want to commit changes before publishing? Publishing the committed version only excludes your local uncommitted edits.`,checkFailedTitle:`Could not check local changes`,checkFailed:`Git could not check local changes.`,retryCheck:`Retry check`,commit:`Commit changes & publish`,committed:`Publish committed version only`,close:`Close publishing dialog`,changedFiles:`Uncommitted changes`,moreChanges:e=>`${e} more`,localSkills:e=>`${e} local agent skill ${e===1?`file stays`:`files stay`} uncommitted.`,selection:`Copilot commits only changes related to this prototype task and asks if it cannot tell which changes belong.`,remember:`Always commit changes before publishing for this prototype`,settings:`Settings`,alwaysCommit:`Always commit changes before publishing`,retrySettings:`Retry settings`,preferenceTargetChanged:`The checkout changed. Refresh Settings and try again.`,invalidPreference:`Publishing settings returned an invalid response. Retry settings.`};function he({busy:e,error:t,changes:n,checkError:r,remembered:i,returnFocusRef:a,onClose:o,onChoose:s,onRetry:c}){let[l,u]=(0,V.useState)(i),d=(0,V.useId)(),f=(0,V.useId)();return(0,U.jsx)(ue,{title:r?q.checkFailedTitle:q.title,closeLabel:q.close,descriptionId:r?void 0:d,returnFocusRef:a,onClose:()=>{e||o()},className:`publish-changes-dialog`,children:(0,U.jsxs)(H.Stack,{gap:`normal`,padding:`none`,children:[r?null:(0,U.jsx)(`p`,{id:d,children:q.description}),r?(0,U.jsx)(me,{title:r,variant:`critical`,layout:`compact`}):null,n?.files.total?(0,U.jsx)(`section`,{"aria-label":q.changedFiles,children:(0,U.jsxs)(`ul`,{className:`publish-changes-dialog__files`,children:[n.files.paths.map(e=>(0,U.jsx)(`li`,{children:(0,U.jsx)(`code`,{children:e})},e)),n.files.total>n.files.paths.length?(0,U.jsx)(`li`,{children:q.moreChanges(n.files.total-n.files.paths.length)}):null]})}):null,r?null:(0,U.jsxs)(`p`,{children:[n?.localSkills.total?`${q.localSkills(n.localSkills.total)} `:null,q.selection]}),r?null:(0,U.jsxs)(H.FormControl,{id:f,fullWidth:!0,children:[(0,U.jsx)(H.Checkbox,{checked:l,disabled:e,onChange:e=>u(e.target.checked)}),(0,U.jsx)(H.FormControl.Label,{children:q.remember})]}),t?(0,U.jsx)(me,{title:t,variant:`critical`,layout:`compact`}):null,(0,U.jsxs)(`footer`,{className:`publish-changes-dialog__actions`,children:[r?(0,U.jsx)(H.Button,{variant:`primary`,size:`small`,disabled:e,"aria-busy":e,onClick:c,children:q.retryCheck}):null,r?null:(0,U.jsx)(H.Button,{variant:`primary`,size:`small`,disabled:e,"aria-busy":e,onClick:()=>s(`commit-changes`,l),children:q.commit}),(0,U.jsx)(H.Button,{size:`small`,disabled:e,onClick:()=>s(`committed-only`,!1),children:q.committed})]})]})})}function ge({value:e,label:t,copyLabel:n,copiedLabel:r,copyErrorLabel:i,compact:a=!1}){let[o,s]=(0,V.useState)(null),c=o?.value===e?o.status:null,l=c===`copied`?r:n;async function u(){try{await navigator.clipboard.writeText(e),s({value:e,status:`copied`})}catch{s({value:e,status:`failed`})}}return(0,U.jsxs)(`div`,{className:`copyable-text-input${a?` copyable-text-input--compact`:``}`,children:[(0,U.jsxs)(`div`,{className:`copyable-text-input__control`,children:[a?(0,U.jsx)(`input`,{type:`text`,value:e,"aria-label":t,readOnly:!0,className:`copyable-text-input__input`}):(0,U.jsx)(H.TextInput,{value:e,"aria-label":t,readOnly:!0,fullWidth:!0,className:`copyable-text-input__input`}),(0,U.jsx)(G,{icon:m,"aria-label":l,description:a?l:void 0,title:a?void 0:l,variant:`invisible`,size:`small`,className:`copyable-text-input__button`,onClick:()=>void u()})]}),(0,U.jsx)(W,{"aria-live":`polite`,"aria-atomic":`true`,children:c===`copied`?r:``}),c===`failed`?(0,U.jsx)(`span`,{role:`alert`,className:`copyable-text-input__error`,children:i}):null]})}function _e({children:e}){return(0,U.jsx)(`div`,{className:`prototype-workspace__body`,children:e})}function ve({title:e,description:t,trailing:n,headingAs:r=`h2`,headingRef:i}){return(0,U.jsxs)(`header`,{className:`hub-content-page-header`,children:[(0,U.jsxs)(`div`,{className:`hub-content-page-header__top`,children:[(0,U.jsx)(H.Heading,{as:r,size:`4`,ref:i,tabIndex:i?-1:void 0,children:e}),n]}),t?(0,U.jsx)(H.Text,{as:`p`,className:`hub-content-page-header__description`,children:t}):null]})}function ye({labels:e,headingRef:t,headingTrailing:n,feedback:r,form:i,formUnavailable:a,links:o,hasLinks:s,showEmpty:c=!0,listRef:l,listBusy:u,beforeLinks:d,afterLinks:f}){return(0,U.jsxs)(H.Stack,{gap:`normal`,children:[(0,U.jsx)(ve,{title:e.heading,description:e.description,headingRef:t,trailing:n}),r,i||(a===void 0?(0,U.jsxs)(`section`,{className:`share-links__empty`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`5`,children:e.noBuildHeading}),(0,U.jsx)(H.Text,{as:`p`,className:`share-links__empty-description`,children:e.noBuildLabel})]}):a),d,s?(0,U.jsx)(`ul`,{className:`share-links__list`,ref:l,"aria-busy":u,children:o}):c?(0,U.jsxs)(`section`,{className:`share-links__empty`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`5`,children:e.emptyHeading}),(0,U.jsx)(H.Text,{as:`p`,className:`share-links__empty-description`,children:e.emptyLabel})]}):null,f]})}function be({shareLink:e,className:t,copiedLabel:n,copyErrorLabel:r,copyLabel:i,urlLabel:a,unavailableLabel:o,highlighted:s,children:c}){return(0,U.jsx)(`li`,{"data-share-id":e.id,className:`share-link-item${s?` share-link-item--created`:``}${t?` ${t}`:``}`,children:(0,U.jsxs)(`div`,{className:`share-link-item__layout`,children:[(0,U.jsxs)(`div`,{className:`share-link-item__details`,children:[(0,U.jsx)(`h3`,{children:e.label}),(0,U.jsxs)(`span`,{className:`share-link-item__metadata`,children:[e.buildLabel,e.createdLabel?(0,U.jsxs)(U.Fragment,{children:[` · `,(0,U.jsx)(`time`,{dateTime:e.createdAt,children:e.createdLabel})]}):null,` · `,e.expiresAt?(0,U.jsx)(`time`,{dateTime:e.expiresAt,children:e.expiresLabel}):e.expiresLabel]})]}),(0,U.jsxs)(`div`,{className:`share-link-item__actions`,children:[o?(0,U.jsx)(`p`,{children:o}):(0,U.jsx)(ge,{value:e.url,label:a||e.label,copyLabel:i,copiedLabel:n,copyErrorLabel:r}),c]})]})})}function xe({data:e,action:t,hiddenFields:n,details:r,afterFields:i,onSubmit:a,label:o,onLabelChange:s,expiration:c,onExpirationChange:l,disabled:u,fieldsDisabled:d,busy:f,error:p}){let m=(0,V.useId)(),h=(0,V.useId)();return(0,U.jsxs)(`div`,{className:`share-links-form`,children:[e.buildLabel?(0,U.jsx)(H.Heading,{as:`h2`,size:`5`,children:e.buildLabel}):null,r,(0,U.jsxs)(`form`,{action:t,method:`post`,onSubmit:a,"aria-busy":f,className:`share-links__form`,children:[n,(0,U.jsxs)(`div`,{className:`share-links__form-row`,children:[(0,U.jsxs)(H.FormControl,{id:m,required:!0,fullWidth:!0,className:`share-links__field`,children:[(0,U.jsx)(H.FormControl.Label,{children:e.labelLabel}),(0,U.jsx)(H.TextInput,{"aria-label":e.labelLabel,"aria-invalid":!!p,name:`share_link[label]`,placeholder:e.labelPlaceholder,maxLength:e.labelMaximumBytes,value:o,onChange:s,disabled:d,fullWidth:!0}),p?(0,U.jsx)(H.FormControl.Validation,{validationStatus:`error`,className:`share-links__validation`,children:p}):null]}),p?(0,U.jsx)(W,{role:`alert`,children:p}):null,(0,U.jsxs)(H.FormControl,{id:h,fullWidth:!0,className:`share-links__field`,children:[(0,U.jsx)(H.FormControl.Label,{children:e.expirationLabel}),(0,U.jsx)(H.Select,{"aria-label":e.expirationLabel,name:`share_link[expiration]`,defaultValue:c===void 0?e.expirationOptions.find(e=>e.value===`seven_days`)?.value??e.expirationOptions[0]?.value:void 0,value:c,onChange:l,disabled:d,fullWidth:!0,children:e.expirationOptions.map(e=>(0,U.jsx)(H.Select.Option,{value:e.value,children:e.label},e.value))})]}),(0,U.jsx)(`div`,{className:`share-links__form-actions`,children:(0,U.jsx)(H.Button,{type:`submit`,variant:`primary`,leadingVisual:v,disabled:u,children:e.submitLabel})})]}),i?(0,U.jsx)(`div`,{className:`share-links__form-options`,children:i}):null]})]})}var J={title:`Share prototype`,internal:`Internal prototype link`,internalDescription:`Requires GitHub sign-in and repository access.`,internalUnavailable:`Internal prototype link unavailable.`,internalCopy:`Copy internal prototype link`,internalOpen:`Open internal prototype link`,public:`Public share links`,permissionUnknown:`Hub has not confirmed permission to manage public share links.`,group:`Publish and share`,back:`Back to preview`,warning:`Anyone with a link can view its Build without signing in. The prototype may expose sensitive or customer information. Check its content before sharing. Local and uncommitted changes are not included.`,target:`New links share this published Build:`,oldBuild:`This is the last published Build, not the current local preview.`,includeControlSettings:`Include current control settings`,controlSettingsDescription:`Adds settings for all configured pages to the links you copy or open. Saved share links stay unchanged.`,controlSettingsWarning:`Settings for controls that have not been published will not take effect for shared links.`,controlSettingsWarningTitle:`Local changes are not in the shared Build`,label:`Label`,labelPlaceholder:`Usability review`,labelInvalid:`Enter a label containing no more than 100 UTF-8 bytes.`,expiry:`Expires after`,expirations:[{value:`one_day`,label:`1 day`},{value:`seven_days`,label:`7 days`},{value:`thirty_days`,label:`30 days`},{value:`never`,label:`Never`}],create:`Create share link`,creating:`Working...`,active:`Active share links`,empty:`Create a link when someone needs signed-out access.`,emptyHeading:`No active share links`,loading:`Loading share links...`,refresh:`Refresh links`,authorize:`Verify with GitHub`,authorizationRetry:`Complete authorization in your browser, then refresh links and submit the action again. No action is replayed automatically.`,paginationFailed:`Hub returned a repeated share-link page. Refresh links to try again.`,noBuild:`A successful published Build is required before creating a share link.`,noBuildHeading:`No successful Build`,build:e=>`Build ${e}`,buildDetails:(e,t,n)=>`Commit: ${e}\nAuthor: @${t}\nPublished: ${n}`,denied:`Managing public share links requires repository admin access or authorship of any successful Build for this Prototype, with current read access. Write access alone is not sufficient.`,disabled:`Public sharing is disabled for this Hub. A Hub administrator must explicitly enable it. Previously revoked links never return.`,disconnected:`Connect to Hub before managing share links.`,connect:`Connect to Hub`,unavailable:`Hub is unavailable. Restore the connection and reopen Share prototype.`,branch:`Open a named prototype branch discovered by Hub before sharing.`,stale:`Hub or checkout changed. Return to preview and reopen Share prototype.`,deleted:`Share link deleted. Its public URL no longer works.`,never:`Never expires`,expires:e=>`Expires ${e}`,createdBy:(e,t)=>`Created by @${e} ${t}`,copy:(e,t)=>`Copy ${e}, Build #${t}`,copied:`Link copied`,copyError:`Could not copy the link. Select the URL and copy it manually.`,open:(e,t)=>`Open ${e}, Build #${t}`,delete:(e,t)=>`Delete ${e}, Build #${t}`,deletePrompt:e=>`Delete "${e}"? Anyone with this link will lose access to its Build.`,deletedError:`Could not delete the link.`,failed:`The sharing request failed.`,unknown:`The sharing request may have completed. Refresh active links before trying again. A matching label does not prove which request created a link.`,expired:`This link has expired. Refresh links.`};function Se({included:e,onChange:t,publishedVersionDiffers:n,disabled:r=!1,error:i,copy:a}){let o=(0,V.useId)(),s=e&&n;return(0,U.jsxs)(`div`,{className:`share-control-settings`,children:[(0,U.jsxs)(H.FormControl,{id:o,fullWidth:!0,children:[(0,U.jsx)(H.Checkbox,{checked:e,onChange:e=>t(e.target.checked),disabled:r}),(0,U.jsx)(H.FormControl.Label,{children:a?.label??J.includeControlSettings}),(0,U.jsx)(H.FormControl.Hint,{className:`share-control-settings__hint`,children:(0,U.jsx)(`span`,{className:`share-control-settings__description`,children:a?.description??J.controlSettingsDescription})})]}),i?(0,U.jsx)(me,{title:i,variant:`critical`,layout:`compact`}):null,s?(0,U.jsx)(me,{title:J.controlSettingsWarningTitle,description:J.controlSettingsWarning,variant:`warning`,layout:`compact`,className:`share-control-settings__warning`}):null]})}function Ce(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.entries(e).every(([e,t])=>/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(e)&&(typeof t==`string`||typeof t==`boolean`||typeof t==`number`&&Number.isFinite(t)||Array.isArray(t)&&t.length<=100&&t.every(e=>typeof e==`string`)))}var we=`replica:controls:url`,Te=/^rc\.([a-zA-Z][a-zA-Z0-9_-]{0,63})\.([a-zA-Z][a-zA-Z0-9_-]{0,63})$/;function Ee(e){let t=new URLSearchParams;for(let n of Object.keys(e).sort()){let r=e[n];if(!Ce(r))throw Error(`Invalid control settings.`);for(let e of Object.keys(r).sort()){let i=`rc.${n}.${e}`;if(!Te.test(i))throw Error(`Invalid control settings identifier.`);t.set(i,JSON.stringify(r[e]))}}let n=t.toString();if(new Blob([n]).size>8192)throw Error(`Control settings exceed the 8 KB URL limit. Reduce the settings before sharing.`);return n}function De(e){let t=new URLSearchParams(e),n=[...t].filter(([e])=>e.startsWith(`rc.`));if(new Blob([new URLSearchParams(n).toString()]).size>8192)return{scopes:{},notice:`Control settings in this URL exceed 8 KB. Defaults were used.`};let r=new Map,i=!1;for(let[e,a]of n){let n=Te.exec(e);if(!n||t.getAll(e).length!==1){i=!0;continue}let o=n[1],s=n[2],c;try{c=JSON.parse(a)}catch{c=a}if(!Ce({[s]:c})){i=!0;continue}let l=r.get(o)??new Map;l.set(s,c),r.set(o,l)}let a=Object.fromEntries([...r].map(([e,t])=>[e,Object.fromEntries(t)]));try{Ee(a)}catch{return{scopes:{},notice:`Control settings in this URL exceed 8 KB. Defaults were used.`}}return{scopes:a,notice:i?`Some URL control settings were invalid. Defaults were used instead.`:``}}function Oe(e,t){let n=new URL(e,window.location.href),r=De(t);if(r.notice)throw Error(r.notice);for(let e of[...n.searchParams.keys()])e.startsWith(`rc.`)&&n.searchParams.delete(e);for(let[e,t]of new URLSearchParams(Ee(r.scopes)))n.searchParams.set(e,t);return n.toString()}function ke({state:e,buildDetails:t,currentCommit:n,hasLocalChanges:r=!1,shareButtonRef:i,onClose:a,onConnect:o,onRefresh:s,onCreate:c,onDelete:l,onOpen:u,controlSettings:d,onAuthorize:f}){let[p,m]=(0,V.useState)(``),[h,g]=(0,V.useState)(`seven_days`),[_,v]=(0,V.useState)(``),[y,b]=(0,V.useState)(Date.now),x=(0,V.useRef)(null),S=(0,V.useRef)(null),C=(0,V.useRef)(null),w=e.context?.prototype,T=J.expirations.filter(e=>!w?.shareLinkExpirationOptions||w.shareLinkExpirationOptions.includes(e.value)),E=T.some(e=>e.value===h)?h:T.find(e=>e.value===`seven_days`)?.value??T[0]?.value??``,D=w?.published?w.build:null,k=D?.url,A=k&&URL.canParse(k)?new URL(k):null,j=A&&A.origin===e.context?.hubOrigin&&[`http:`,`https:`].includes(A.protocol)&&!A.username&&!A.password?k:null,M=!!(D&&n&&n!==D.commitSha)||r,N=w?.canManageShareLinks===!0,P=!e.sharingDisabled&&w?.publicSharingEnabled!==!1,F=e.busy||e.loading||e.stale||!N||!P,ee=d?.included?d.query??``:``,I=!!d?.blocked;function L(e){return Oe(e,ee)}let te=P&&e.stale&&!e.loading&&e.created&&!e.links.some(t=>t.id===e.created?.id)?e.created:null;(0,V.useEffect)(()=>{let e=i.current;S.current?.focus();let t=window.setInterval(()=>b(Date.now()),1e4);return()=>{window.clearInterval(t),e?.focus()}},[i]),(0,V.useEffect)(()=>{if(e.busy||!C.current)return;let t=C.current;C.current=null,(t.map(e=>x.current?.querySelector(`[data-share-id="${e}"] button`)).find(e=>e&&!e.disabled)||S.current)?.focus()},[e.busy,e.links]);async function ne(t,n){if(!window.confirm(J.deletePrompt(n)))return;let r=e.links.findIndex(e=>e.id===t),i=[...e.links.slice(r+1),...e.links.slice(0,r).reverse()].map(e=>e.id);await l(t)&&(C.current=i,(i.map(e=>x.current?.querySelector(`[data-share-id="${e}"] button`)).find(e=>e&&!e.disabled)||S.current)?.focus())}function R(e){return new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e))}return(0,U.jsx)(`main`,{className:`canvas-share-page`,"aria-label":J.title,children:(0,U.jsx)(_e,{children:(0,U.jsx)(ye,{labels:{heading:J.title,noBuildHeading:J.noBuildHeading,noBuildLabel:J.noBuild,emptyHeading:J.emptyHeading,emptyLabel:J.empty},headingRef:S,headingTrailing:(0,U.jsx)(`div`,{className:`canvas-share-close`,children:(0,U.jsx)(G,{icon:z,variant:`invisible`,"aria-label":J.back,description:J.back,onClick:a})}),feedback:(0,U.jsxs)(U.Fragment,{children:[d?(0,U.jsx)(Se,{included:d.included,onChange:d.onChange,publishedVersionDiffers:M,disabled:e.busy||d.pending,error:d.error}):null,(0,U.jsxs)(`section`,{className:`canvas-share-internal`,"aria-label":J.internal,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`6`,children:J.internal}),(0,U.jsx)(`p`,{children:J.internalDescription}),j&&!I?(0,U.jsxs)(`div`,{className:`share-link-item__actions canvas-share-internal-actions`,children:[(0,U.jsx)(ge,{value:L(j),label:J.internal,copyLabel:J.internalCopy,copiedLabel:J.copied,copyErrorLabel:J.copyError}),(0,U.jsx)(G,{as:`a`,href:L(j),target:`_blank`,rel:`noopener`,icon:ae,"aria-label":J.internalOpen,description:J.internalOpen})]}):j?null:(0,U.jsx)(`p`,{role:`status`,children:J.internalUnavailable})]}),(0,U.jsxs)(`div`,{className:`canvas-share-public-header`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`6`,children:J.public}),(0,U.jsx)(`p`,{children:J.warning})]}),w&&!N?(0,U.jsx)(`p`,{role:`status`,children:w.canManageShareLinks===!1?J.denied:J.permissionUnknown}):null,P?null:(0,U.jsx)(`p`,{role:`status`,children:J.disabled}),e.error?(0,U.jsx)(me,{title:e.error,variant:`critical`,layout:`compact`}):null,e.authorization&&f?(0,U.jsx)(H.Button,{variant:`secondary`,size:`small`,onClick:f,disabled:e.busy,children:J.authorize}):null,o&&!e.context?(0,U.jsx)(H.Button,{variant:`secondary`,size:`small`,onClick:o,children:J.connect}):null]}),form:D&&N&&P?(0,U.jsx)(xe,{data:{buildLabel:null,labelLabel:J.label,labelPlaceholder:J.labelPlaceholder,labelMaximumBytes:100,expirationLabel:J.expiry,expirationOptions:T,submitLabel:e.busy?J.creating:J.create},label:p,onLabelChange:e=>{m(e.target.value),v(``)},expiration:E,onExpirationChange:e=>g(e.target.value),onSubmit:e=>{e.preventDefault(),!p.trim()||new TextEncoder().encode(p.trim()).length>100?v(J.labelInvalid):(v(``),c(p,E))},disabled:F,fieldsDisabled:e.busy,busy:e.busy,error:_,details:(0,U.jsxs)(`div`,{className:`canvas-share-build-details`,children:[(0,U.jsxs)(`p`,{children:[J.target,` `,(0,U.jsx)(`strong`,{children:J.build(D.number)}),` - `,(0,U.jsx)(`code`,{children:D.commitSha.slice(0,7)}),` - `,(0,U.jsx)(`time`,{dateTime:D.publishedAt,children:R(D.publishedAt)})]}),M?(0,U.jsx)(`p`,{children:J.oldBuild}):null]})}):null,formUnavailable:N&&P&&!D?void 0:null,beforeLinks:(0,U.jsxs)(U.Fragment,{children:[e.notice?(0,U.jsx)(`p`,{role:`status`,children:e.notice}):null,te&&!I?(0,U.jsx)(ge,{value:L(te.url),label:te.label,copyLabel:J.copy(te.label,te.buildNumber),copiedLabel:J.copied,copyErrorLabel:J.copyError}):null,e.loading?(0,U.jsx)(`p`,{role:`status`,children:J.loading}):null]}),hasLinks:N&&P&&!I&&e.links.length>0,showEmpty:N&&P&&!I&&!e.loading&&!e.stale,listRef:x,listBusy:e.loading,links:(!N||!P||I?[]:e.links).map(e=>{let n=e.expiresAt!==null&&Date.parse(e.expiresAt)<=y,r=t?.[e.buildNumber];return(0,U.jsxs)(be,{className:D&&e.buildNumberee?u(e.id,ee):u(e.id)}),(0,U.jsx)(G,{icon:O,variant:`danger`,"aria-label":J.delete(e.label,e.buildNumber),description:J.delete(e.label,e.buildNumber),disabled:F||n,onClick:()=>void ne(e.id,e.label)})]},e.id)}),afterLinks:(0,U.jsx)(`div`,{className:`canvas-share-list-actions`,children:N||!e.context&&!o?(0,U.jsx)(H.Button,{size:`small`,variant:`subtle`,onClick:s,disabled:e.busy||e.loading,children:J.refresh}):null})})})})}var Y={checking:`Checking sharing readiness`,checkingDetail:`Checking Hub for a successful published Build and repository access.`,connect:`Connect before sharing`,connectDetail:`Connect to Hub before sharing this prototype.`,connectAction:`Connect to Hub`,publish:`Publish before sharing`,publishDetail:`To create a share link, publish this prototype to Hub first. Your local preview stays private.`,publishPermissionUnverified:`This Hub has not confirmed publishing permission. Copilot will check access when publishing and report any permission errors.`,preparing:`Preparing your prototype`,ready:`Ready to share`,readyDetail:`Your prototype is ready to share.`,manage:`Share prototype`,unavailable:`Sharing status unavailable`,unavailableDetail:`Hub could not verify sharing readiness. Retry before continuing.`,permissionUnknown:`This Hub cannot verify sharing or publishing permission. Update Hub and retry.`,restricted:`Sharing unavailable`,publishDenied:`Publishing requires repository write access. Ask a prototype author to publish a Build.`,local:`Local development prototypes cannot create public share links.`,changed:`Sharing target changed`,changedDetail:`The repository, branch, or Hub changed. Close this dialog and reopen Share for the intended prototype.`,boundary:`Internal review requires repository access. Public share links let anyone view a published Build, not your local preview.`,close:`Close sharing readiness`},Ae=`Branch not eligible for Hub registration`,X={heading:`Branch publication`,checking:`Checking...`,retry:`Retry status`,retryPublish:`Retry publish`,requested:`Requested`,awaitingCopilot:`Waiting for Copilot`,publishBranch:`Publish`,publishChanges:`Publish changes`,registration:`Publishing`,registrationFailed:`Publication delayed`,published:`Published`,alreadyPublished:`Latest changes already published`,queued:`Build queued`,building:`Building`,awaitingHub:`Awaiting Hub`,awaitingBuild:`Awaiting build`,connect:`Connect to the hub`,workflowLink:`View workflow run`,initial:`Checking branch publication.`,checkingRemote:`Checking the exact branch on the origin repository.`,detached:`Open a named branch before publishing.`,changed:`The checkout changed. Refresh publication status.`,unknown:e=>`Remote branch status is unknown. ${e||`Check GitHub access and retry.`}`,pending:`Copilot received the publish request in chat and has not pushed this branch yet. Follow its progress in chat.`,checkingHub:`Checking the Hub connection.`,disconnected:`Connect to the hub before publishing this prototype.`,hubUnavailable:`Hub verification is unavailable. Restore access and retry.`,hubUnavailableTitle:`Hub verification unavailable`,staleHub:`The Hub status belongs to a different checkout. Refresh to continue.`,workflowMissing:`This checkout has no .github/workflows/replica.yml. Set up the repository's Replica build workflow before publishing.`,dispatchFailed:`Copilot could not receive the publish request.`,absent:`This branch won't appear in the hub until you publish.`,needsPush:`The remote branch points to a different commit. Publish pushes this branch without force.`,localChanges:`Local changes are not in the published prototype. Choose how to publish them.`,needsRegistration:`Hub imported this commit. The canvas is publishing it automatically.`,registrationDenied:`Hub could not register this branch. Check repository access and branch eligibility.`,registrationErrorTitle:`Hub registration failed`,registrationReasons:new Map([[`write_access_required`,{title:Ae,description:`You lack write access to this repository.`}],[`branch_not_reviewable`,{title:Ae,description:`Default, reserved, and internal branches cannot be registered in Hub.`}],[`remote_branch_missing`,{title:Ae,description:`The branch no longer exists on the remote repository.`}],[`branch_authorship_required`,{title:Ae,description:`You have not authored a commit unique to this branch.`}],[`repository_mismatch`,{title:Ae,description:`The branch belongs to a different repository.`}],[`already_registered`,{title:`Branch already registered in Hub`,description:`This branch is already registered in Hub. Refresh its status.`}],[`successful_build_required`,{title:`Hub registration delayed`,description:`Hub has not imported this checkout's successful Build yet.`}]]),ready:`Hub imported this commit and the prototype is registered.`,importFailed:`Hub could not import or build this commit. Pushing this unchanged commit does not rerun the failed work. Inspect the Build failure in Hub and repair the cause before publishing again.`,workflowUnavailable:`Workflow status is unavailable. Check GitHub access and retry.`,staleWorkflow:`Workflow status belongs to a different branch or commit.`,workflowQueued:`The Replica workflow for this commit is queued or waiting.`,workflowBuilding:`The Replica workflow is building this commit.`,workflowFailed:e=>`The Replica workflow finished with ${e||`an unsuccessful result`}. Pushing this unchanged commit does not rerun the failed work. Inspect the run and repair the cause before publishing again.`,importing:`The workflow succeeded. Waiting for Hub discovery and artifact import; this is not published yet.`,noBuild:`The exact branch and commit are on GitHub, but no matching Replica workflow run has appeared yet.`};function je({publication:e,busy:t,onPublish:n,onRetry:r}){if(e.kind===`ready`)return null;let i=e.kind===`requested`,a=t||i;return(0,U.jsxs)(`section`,{className:`canvas-branch-publication`,"aria-label":X.heading,children:[e.error?(0,U.jsx)(me,{variant:`critical`,layout:`compact`,title:e.error.title,description:e.error.description}):(0,U.jsx)(`p`,{role:`status`,children:e.detail}),e.runUrl?(0,U.jsx)(`p`,{children:(0,U.jsx)(H.InlineLink,{className:`canvas-branch-publication__workflow-link`,href:e.runUrl,target:`_blank`,rel:`noopener noreferrer`,children:X.workflowLink})}):null,(e.action!==`none`||i)&&e.kind!==`disconnected`?(0,U.jsx)(`div`,{className:`canvas-branch-publication__actions`,children:(0,U.jsx)(H.Button,{variant:`primary`,size:`small`,disabled:a,"aria-busy":a,leadingVisual:a?(0,U.jsx)(L,{size:16}):void 0,onClick:e.action===`retry`?r:n,children:e.label})}):null]})}function Me({readiness:e,busy:t,shareButtonRef:n,onClose:r,onConnect:i,onPublish:a,onRetry:o,onManage:s}){let c=(0,V.useId)();return(0,U.jsxs)(ue,{title:e.title,closeLabel:Y.close,onClose:r,returnFocusRef:n,descriptionId:c,children:[(0,U.jsx)(`p`,{id:c,role:`status`,children:e.detail}),[`connect`,`publish`,`ready`].includes(e.kind)?(0,U.jsx)(`p`,{children:Y.boundary}):null,e.publication?(0,U.jsx)(je,{publication:e.publication,dirty:!1,busy:t,onPublish:a,onRetry:o}):null,[`connect`,`ready`,`retry`].includes(e.kind)?(0,U.jsx)(H.Button,{variant:`primary`,size:`small`,disabled:t,"aria-busy":t,onClick:e.kind===`connect`?i:e.kind===`ready`?s:o,children:e.kind===`connect`?Y.connectAction:e.kind===`ready`?Y.manage:X.retry}):null]})}function Ne({hub:e,connection:t,publication:n,sharing:r,shareIntent:i,controlSettings:a,readiness:o,state:s,hubOpen:c,buildDetailsOpen:l,onCloseBuildDetails:u,shareButtonRef:d,hubButtonRef:f,connectionButtonRef:p,publishButtonRef:m,titleButtonRef:h}){let{intent:g,targetChanged:_}=i,v=n.presentedState;return(0,U.jsxs)(U.Fragment,{children:[t.open&&(!g||g.connecting&&!_)?(0,U.jsx)(pe,{status:e.status,pairing:t.pairing,connecting:t.connecting,error:t.error,onConnect:t.connect,onSelectHub:e.select,onResetHub:e.reset,onClose:()=>{t.close(),i.setConnecting(!1)},hubButtonRef:g?d:c?p:f}):null,g&&!n.publishDialog&&(_||!g.connecting||!t.open)?(0,U.jsx)(Me,{readiness:_?{kind:`restricted`,title:Y.changed,detail:Y.changedDetail}:o,busy:n.busy,shareButtonRef:d,onClose:()=>{i.close(),t.close()},onConnect:()=>{_||o.kind!==`connect`||(i.setConnecting(!0),t.showAndConnect())},onPublish:()=>{!_&&o.kind===`publish`&&n.publish()},onRetry:()=>void n.retry(),onManage:()=>{_||o.kind!==`ready`||(i.close(),r.open())}}):null,n.publishDialog?(0,U.jsx)(he,{busy:n.busy,error:n.publishDialogError,changes:n.publishDialog.preparation.changes,checkError:n.publishDialog.preparation.workingTree===`unavailable`?n.publishDialog.preparation.workingTreeError||q.checkFailed:void 0,remembered:n.publishDialog.preparation.remember,returnFocusRef:g?d:m,onClose:n.closePublishDialog,onChoose:(e,t)=>void n.choosePublish(e,t),onRetry:()=>void n.retryPublishCheck()},n.publishDialog.preparation.workingTree===`unavailable`?`unchecked`:`checked`):null,r.state.open?(0,U.jsx)(ke,{state:r.state,currentCommit:s?.stats.commitSha,hasLocalChanges:s?.stats.workingTree===`changed`,shareButtonRef:d,onClose:r.close,onConnect:!e.status||[`disconnected`,`pairing`,`unconfigured`].includes(e.status.state)?()=>{r.close(),t.show()}:void 0,onRefresh:()=>void r.refresh(),onCreate:r.create,onDelete:r.remove,onOpen:(e,t)=>void r.openLink(e,t),controlSettings:a,onAuthorize:()=>void r.authorize()}):null,l&&v?(0,U.jsx)(de,{state:v,titleButtonRef:h,onClose:u}):null]})}function Pe({address:e,addressRef:t,canGoBack:n,canGoForward:r,appearance:a,onAppearanceChange:o,onBack:s,onForward:c,onNavigate:l,onOpenTab:u,onReload:d}){let[f,p]=(0,V.useState)(null),m=f?.address===e?f.value:e,h=f?.address===e?f.error:``;function g(t){t.preventDefault();try{let t=new URL(m.trim(),e);if(![`http:`,`https:`].includes(t.protocol)||t.origin!==new URL(e).origin||t.username||t.password){p({address:e,value:m,error:K.browserAddressOrigin});return}p(null),l(t.href)}catch{p({address:e,value:m,error:K.browserAddressInvalid})}}return(0,U.jsx)(H.ThemeProvider,{colorMode:`auto`,className:`canvas-browser-theme`,children:(0,U.jsxs)(`nav`,{className:`canvas-browser-bar`,"aria-label":K.browserNavigation,children:[(0,U.jsxs)(`div`,{className:`canvas-browser-bar__navigation`,children:[(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserBack,disabled:!n,onClick:s,children:(0,U.jsx)(x,{size:16})}),(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserForward,disabled:!r,onClick:c,children:(0,U.jsx)(y,{size:16})}),(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserReload,onClick:d,children:(0,U.jsx)(L,{size:16})})]}),(0,U.jsxs)(`form`,{className:`canvas-browser-bar__address`,onSubmit:g,children:[(0,U.jsx)(`input`,{ref:t,"aria-label":K.browserAddress,"aria-invalid":!!h,"aria-describedby":h?`canvas-browser-address-error`:void 0,spellCheck:!1,value:m,onChange:t=>{p({address:e,value:t.target.value,error:``})},onFocus:e=>e.currentTarget.select(),onKeyDown:e=>{e.key===`Escape`&&(p(null),e.currentTarget.blur())}}),h?(0,U.jsx)(`span`,{id:`canvas-browser-address-error`,className:`canvas-browser-bar__error`,role:`alert`,children:h}):null]}),(0,U.jsxs)(`div`,{className:`canvas-browser-bar__tools`,children:[(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserOpenTab,title:K.browserOpenTab,onClick:()=>{u().catch(t=>{p({address:e,value:m,error:t instanceof Error?t.message:String(t)})})},children:(0,U.jsx)(ae,{size:16})}),(0,U.jsxs)(`div`,{className:`canvas-browser-bar__appearance`,role:`group`,"aria-label":K.browserAppearance,children:[(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserLight,"aria-pressed":a===`light`,onClick:()=>o(`light`),children:(0,U.jsx)(F,{size:16})}),(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserDark,"aria-pressed":a===`dark`,onClick:()=>o(`dark`),children:(0,U.jsx)(i,{size:16})})]})]})]})})}var Z=e(t((e=>{var t=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),n=t((e=>{Object.defineProperty(e,"__esModule",{value:!0});function t(e){let t=e.length,n=0,r=0,i;for(;r=55296&&i<=56319&&r{t.exports=function e(t,n){if(t===n)return!0;if(t&&n&&typeof t==`object`&&typeof n==`object`){if(t.constructor!==n.constructor)return!1;var r,i,a;if(Array.isArray(t)){if(r=t.length,r!=n.length)return!1;for(i=r;i--!==0;)if(!e(t[i],n[i]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if(a=Object.keys(t),r=a.length,r!==Object.keys(n).length)return!1;for(i=r;i--!==0;)if(!Object.prototype.hasOwnProperty.call(n,a[i]))return!1;for(i=r;i--!==0;){var o=a[i];if(!e(t[o],n[o]))return!1}return!0}return t!==t&&n!==n}})),i=t((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=r();t.code=`require("ajv/dist/runtime/equal").default`,e.default=t}));e.validateShape=P;var a={type:`object`,additionalProperties:!1,required:[`version`,`scope`,`controls`],properties:{$schema:{type:`string`},version:{const:1},scope:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},role:{enum:[`shared`,`page`]},container:{$ref:`#/$defs/selector`},panel:{type:`object`,additionalProperties:!1,required:[`width`],properties:{width:{type:`integer`,minimum:160,maximum:4096}}},groups:{type:`array`,maxItems:100,items:{type:`object`,additionalProperties:!1,required:[`id`,`label`],properties:{id:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},when:{$ref:`#/$defs/condition`}}}},controls:{type:`array`,maxItems:500,items:{oneOf:[{$ref:`#/$defs/boolean`},{$ref:`#/$defs/number`},{$ref:`#/$defs/slider`},{$ref:`#/$defs/choice`},{$ref:`#/$defs/checkboxGroup`},{$ref:`#/$defs/text`},{$ref:`#/$defs/color`},{$ref:`#/$defs/button`}]}}}},o=Object.prototype.hasOwnProperty,s=n().default,c=RegExp(`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`,`u`),l={type:[`string`,`number`,`boolean`]},u=i().default,d={validate:f};function f(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0,s=o,p=!1,m=null,h=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.control===void 0){let e={instancePath:t,schemaPath:`#/oneOf/0/required`,keyword:`required`,params:{missingProperty:`control`},message:`must have required property 'control'`};a===null?a=[e]:a.push(e),o++}if(e.equals===void 0){let e={instancePath:t,schemaPath:`#/oneOf/0/required`,keyword:`required`,params:{missingProperty:`equals`},message:`must have required property 'equals'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`control`&&n!==`equals`){let e={instancePath:t,schemaPath:`#/oneOf/0/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.control!==void 0){let n=e.control;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.equals!==void 0){let n=e.equals;if(typeof n!=`string`&&!(typeof n==`number`&&isFinite(n))&&typeof n!=`boolean`){let e={instancePath:t+`/equals`,schemaPath:`#/$defs/scalar/type`,keyword:`type`,params:{type:l.type},message:`must be string,number,boolean`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/0/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var g=h===o;g&&(p=!0,m=0);let _=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.control===void 0){let e={instancePath:t,schemaPath:`#/oneOf/1/required`,keyword:`required`,params:{missingProperty:`control`},message:`must have required property 'control'`};a===null?a=[e]:a.push(e),o++}if(e.in===void 0){let e={instancePath:t,schemaPath:`#/oneOf/1/required`,keyword:`required`,params:{missingProperty:`in`},message:`must have required property 'in'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`control`&&n!==`in`){let e={instancePath:t,schemaPath:`#/oneOf/1/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.control!==void 0){let n=e.control;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.in!==void 0){let n=e.in;if(Array.isArray(n)){if(n.length>20){let e={instancePath:t+`/in`,schemaPath:`#/oneOf/1/properties/in/maxItems`,keyword:`maxItems`,params:{limit:20},message:`must NOT have more than 20 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/in`,schemaPath:`#/oneOf/1/properties/in/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r1){outer0:for(;r--;)for(i=r;i--;)if(u(n[r],n[i])){let e={instancePath:t+`/in`,schemaPath:`#/oneOf/1/properties/in/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[e]:a.push(e),o++;break outer0}}}else{let e={instancePath:t+`/in`,schemaPath:`#/oneOf/1/properties/in/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/1/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var g=_===o;if(g&&p)p=!1,m=[m,1];else{g&&(p=!0,m=1);let n=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.control===void 0){let e={instancePath:t,schemaPath:`#/oneOf/2/required`,keyword:`required`,params:{missingProperty:`control`},message:`must have required property 'control'`};a===null?a=[e]:a.push(e),o++}if(e.includes===void 0){let e={instancePath:t,schemaPath:`#/oneOf/2/required`,keyword:`required`,params:{missingProperty:`includes`},message:`must have required property 'includes'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`control`&&n!==`includes`){let e={instancePath:t,schemaPath:`#/oneOf/2/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.control!==void 0){let n=e.control;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.includes!==void 0&&typeof e.includes!=`string`){let e={instancePath:t+`/includes`,schemaPath:`#/oneOf/2/properties/includes/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t,schemaPath:`#/oneOf/2/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var g=n===o;if(g&&p)p=!1,m=[m,2];else{g&&(p=!0,m=2);let n=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.all===void 0){let e={instancePath:t,schemaPath:`#/oneOf/3/required`,keyword:`required`,params:{missingProperty:`all`},message:`must have required property 'all'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`all`){let e={instancePath:t,schemaPath:`#/oneOf/3/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.all!==void 0){let n=e.all;if(Array.isArray(n)){if(n.length>10){let e={instancePath:t+`/all`,schemaPath:`#/oneOf/3/properties/all/maxItems`,keyword:`maxItems`,params:{limit:10},message:`must NOT have more than 10 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/all`,schemaPath:`#/oneOf/3/properties/all/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r10){let e={instancePath:t+`/any`,schemaPath:`#/oneOf/4/properties/any/maxItems`,keyword:`maxItems`,params:{limit:10},message:`must NOT have more than 10 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/any`,schemaPath:`#/oneOf/4/properties/any/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r512){let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/maxLength`,keyword:`maxLength`,params:{limit:512},message:`must NOT have more than 512 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/0/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var f=d===o;f&&(l=!0,u=0);let v=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.type===void 0){let e={instancePath:t,schemaPath:`#/oneOf/1/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.selector===void 0){let e={instancePath:t,schemaPath:`#/oneOf/1/required`,keyword:`required`,params:{missingProperty:`selector`},message:`must have required property 'selector'`};a===null?a=[e]:a.push(e),o++}if(e.property===void 0){let e={instancePath:t,schemaPath:`#/oneOf/1/required`,keyword:`required`,params:{missingProperty:`property`},message:`must have required property 'property'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`type`&&n!==`selector`&&n!==`property`){let e={instancePath:t,schemaPath:`#/oneOf/1/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.type!==void 0&&e.type!==`style`){let e={instancePath:t+`/type`,schemaPath:`#/oneOf/1/properties/type/const`,keyword:`const`,params:{allowedValue:`style`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.selector!==void 0){let n=e.selector;if(typeof n==`string`){if(s(n)>512){let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/maxLength`,keyword:`maxLength`,params:{limit:512},message:`must NOT have more than 512 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.property!==void 0){let n=e.property;if(typeof n==`string`){if(s(n)>100){let e={instancePath:t+`/property`,schemaPath:`#/oneOf/1/properties/property/maxLength`,keyword:`maxLength`,params:{limit:100},message:`must NOT have more than 100 characters`};a===null?a=[e]:a.push(e),o++}if(!m.test(n)){let e={instancePath:t+`/property`,schemaPath:`#/oneOf/1/properties/property/pattern`,keyword:`pattern`,params:{pattern:`^(--[a-zA-Z0-9_-]+|[a-z][a-z-]*)$`},message:`must match pattern "^(--[a-zA-Z0-9_-]+|[a-z][a-z-]*)$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/property`,schemaPath:`#/oneOf/1/properties/property/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/1/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var f=v===o;if(f&&l)l=!1,u=[u,1];else{f&&(l=!0,u=1);let n=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.type===void 0){let e={instancePath:t,schemaPath:`#/oneOf/2/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.key===void 0){let e={instancePath:t,schemaPath:`#/oneOf/2/required`,keyword:`required`,params:{missingProperty:`key`},message:`must have required property 'key'`};a===null?a=[e]:a.push(e),o++}if(e.mode===void 0){let e={instancePath:t,schemaPath:`#/oneOf/2/required`,keyword:`required`,params:{missingProperty:`mode`},message:`must have required property 'mode'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`type`&&n!==`key`&&n!==`mode`){let e={instancePath:t,schemaPath:`#/oneOf/2/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.type!==void 0&&e.type!==`query`){let e={instancePath:t+`/type`,schemaPath:`#/oneOf/2/properties/type/const`,keyword:`const`,params:{allowedValue:`query`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.key!==void 0){let n=e.key;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/key`,schemaPath:`#/oneOf/2/properties/key/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/key`,schemaPath:`#/oneOf/2/properties/key/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/key`,schemaPath:`#/oneOf/2/properties/key/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.mode!==void 0){let n=e.mode;if(n!==`in-place`&&n!==`navigate`){let e={instancePath:t+`/mode`,schemaPath:`#/oneOf/2/properties/mode/enum`,keyword:`enum`,params:{allowedValues:p.oneOf[2].properties.mode.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/2/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var f=n===o;if(f&&l)l=!1,u=[u,2];else{f&&(l=!0,u=2);let n=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.type===void 0){let e={instancePath:t,schemaPath:`#/oneOf/3/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.mode===void 0){let e={instancePath:t,schemaPath:`#/oneOf/3/required`,keyword:`required`,params:{missingProperty:`mode`},message:`must have required property 'mode'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`type`&&n!==`mode`){let e={instancePath:t,schemaPath:`#/oneOf/3/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.type!==void 0&&e.type!==`hash`){let e={instancePath:t+`/type`,schemaPath:`#/oneOf/3/properties/type/const`,keyword:`const`,params:{allowedValue:`hash`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.mode!==void 0){let n=e.mode;if(n!==`in-place`&&n!==`navigate`){let e={instancePath:t+`/mode`,schemaPath:`#/oneOf/3/properties/mode/enum`,keyword:`enum`,params:{allowedValues:p.oneOf[3].properties.mode.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/3/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var f=n===o;if(f&&l)l=!1,u=[u,3];else{f&&(l=!0,u=3);let n=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.type===void 0){let e={instancePath:t,schemaPath:`#/oneOf/4/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.object===void 0){let e={instancePath:t,schemaPath:`#/oneOf/4/required`,keyword:`required`,params:{missingProperty:`object`},message:`must have required property 'object'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`type`&&n!==`object`&&n!==`read`&&n!==`write`&&n!==`action`&&n!==`subscribe`&&n!==`pollMs`){let e={instancePath:t,schemaPath:`#/oneOf/4/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.type!==void 0&&e.type!==`api`){let e={instancePath:t+`/type`,schemaPath:`#/oneOf/4/properties/type/const`,keyword:`const`,params:{allowedValue:`api`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.object!==void 0){let n=e.object;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/object`,schemaPath:`#/oneOf/4/properties/object/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(!h.test(n)){let e={instancePath:t+`/object`,schemaPath:`#/oneOf/4/properties/object/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z_$][a-zA-Z0-9_$]*)*$`},message:`must match pattern "^[a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z_$][a-zA-Z0-9_$]*)*$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/object`,schemaPath:`#/oneOf/4/properties/object/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.read!==void 0){let n=e.read;if(typeof n==`string`){if(s(n)>64){let e={instancePath:t+`/read`,schemaPath:`#/$defs/method/maxLength`,keyword:`maxLength`,params:{limit:64},message:`must NOT have more than 64 characters`};a===null?a=[e]:a.push(e),o++}if(!g.test(n)){let e={instancePath:t+`/read`,schemaPath:`#/$defs/method/pattern`,keyword:`pattern`,params:{pattern:`^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$`},message:`must match pattern "^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/read`,schemaPath:`#/$defs/method/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.write!==void 0){let n=e.write;if(typeof n==`string`){if(s(n)>64){let e={instancePath:t+`/write`,schemaPath:`#/$defs/method/maxLength`,keyword:`maxLength`,params:{limit:64},message:`must NOT have more than 64 characters`};a===null?a=[e]:a.push(e),o++}if(!g.test(n)){let e={instancePath:t+`/write`,schemaPath:`#/$defs/method/pattern`,keyword:`pattern`,params:{pattern:`^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$`},message:`must match pattern "^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/write`,schemaPath:`#/$defs/method/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.action!==void 0){let n=e.action;if(typeof n==`string`){if(s(n)>64){let e={instancePath:t+`/action`,schemaPath:`#/$defs/method/maxLength`,keyword:`maxLength`,params:{limit:64},message:`must NOT have more than 64 characters`};a===null?a=[e]:a.push(e),o++}if(!g.test(n)){let e={instancePath:t+`/action`,schemaPath:`#/$defs/method/pattern`,keyword:`pattern`,params:{pattern:`^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$`},message:`must match pattern "^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/action`,schemaPath:`#/$defs/method/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.subscribe!==void 0){let n=e.subscribe;if(typeof n==`string`){if(s(n)>64){let e={instancePath:t+`/subscribe`,schemaPath:`#/$defs/method/maxLength`,keyword:`maxLength`,params:{limit:64},message:`must NOT have more than 64 characters`};a===null?a=[e]:a.push(e),o++}if(!g.test(n)){let e={instancePath:t+`/subscribe`,schemaPath:`#/$defs/method/pattern`,keyword:`pattern`,params:{pattern:`^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$`},message:`must match pattern "^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/subscribe`,schemaPath:`#/$defs/method/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.pollMs!==void 0){let n=e.pollMs;if(typeof n!=`number`||n%1||isNaN(n)||!isFinite(n)){let e={instancePath:t+`/pollMs`,schemaPath:`#/oneOf/4/properties/pollMs/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};a===null?a=[e]:a.push(e),o++}if(typeof n==`number`&&isFinite(n)){if(n>6e4||isNaN(n)){let e={instancePath:t+`/pollMs`,schemaPath:`#/oneOf/4/properties/pollMs/maximum`,keyword:`maximum`,params:{comparison:`<=`,limit:6e4},message:`must be <= 60000`};a===null?a=[e]:a.push(e),o++}if(n<100||isNaN(n)){let e={instancePath:t+`/pollMs`,schemaPath:`#/oneOf/4/properties/pollMs/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:100},message:`must be >= 100`};a===null?a=[e]:a.push(e),o++}}}}else{let e={instancePath:t,schemaPath:`#/oneOf/4/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var f=n===o;f&&l?(l=!1,u=[u,4]):f&&(l=!0,u=4)}}}if(l)o=c,a!==null&&(c?a.length=c:a=null);else{let e={instancePath:t,schemaPath:`#/oneOf`,keyword:`oneOf`,params:{passingSchemas:u},message:`must match exactly one schema in oneOf`};a===null?a=[e]:a.push(e),o++}return _.errors=a,o===0}function v(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!=="default"&&n!==`binding`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`boolean`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`boolean`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.default!==void 0&&typeof e.default!=`boolean`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`boolean`},message:`must be boolean`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return v.errors=a,o===0}var y={type:`object`,additionalProperties:!1,required:[`id`,`label`,`type`,`default`,`min`,`max`],properties:{id:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},type:{const:`number`},default:{type:`number`},binding:{$ref:`#/$defs/binding`},min:{type:`number`},max:{type:`number`},step:{type:`number`,exclusiveMinimum:0},group:{$ref:`#/$defs/id`},when:{$ref:`#/$defs/condition`}}};function b(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}if(e.min===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`min`},message:`must have required property 'min'`};a===null?a=[e]:a.push(e),l++}if(e.max===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`max`},message:`must have required property 'max'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(y.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0&&e.type!==`number`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`number`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),l++}if(e.default!==void 0){let n=e.default;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.min!==void 0){let n=e.min;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/min`,schemaPath:`#/properties/min/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.max!==void 0){let n=e.max;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/max`,schemaPath:`#/properties/max/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.step!==void 0){let n=e.step;if(typeof n==`number`&&isFinite(n)){if(n<=0||isNaN(n)){let e={instancePath:t+`/step`,schemaPath:`#/properties/step/exclusiveMinimum`,keyword:`exclusiveMinimum`,params:{comparison:`>`,limit:0},message:`must be > 0`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/step`,schemaPath:`#/properties/step/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return b.errors=a,l===0}var x={type:`object`,additionalProperties:!1,required:[`id`,`label`,`type`,`default`,`min`,`max`],properties:{id:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},type:{const:`slider`},default:{type:`number`},binding:{$ref:`#/$defs/binding`},min:{type:`number`},max:{type:`number`},step:{type:`number`,exclusiveMinimum:0},group:{$ref:`#/$defs/id`},when:{$ref:`#/$defs/condition`}}};function S(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}if(e.min===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`min`},message:`must have required property 'min'`};a===null?a=[e]:a.push(e),l++}if(e.max===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`max`},message:`must have required property 'max'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(x.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0&&e.type!==`slider`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`slider`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),l++}if(e.default!==void 0){let n=e.default;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.min!==void 0){let n=e.min;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/min`,schemaPath:`#/properties/min/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.max!==void 0){let n=e.max;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/max`,schemaPath:`#/properties/max/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.step!==void 0){let n=e.step;if(typeof n==`number`&&isFinite(n)){if(n<=0||isNaN(n)){let e={instancePath:t+`/step`,schemaPath:`#/properties/step/exclusiveMinimum`,keyword:`exclusiveMinimum`,params:{comparison:`>`,limit:0},message:`must be > 0`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/step`,schemaPath:`#/properties/step/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return S.errors=a,l===0}var C={type:`object`,additionalProperties:!1,required:[`id`,`label`,`type`,`default`,`options`],properties:{id:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},type:{enum:[`select`,`radio`,`segmented`]},default:{type:`string`},binding:{$ref:`#/$defs/binding`},options:{$ref:`#/$defs/options`},group:{$ref:`#/$defs/id`},when:{$ref:`#/$defs/condition`}}};function w(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}if(e.options===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`options`},message:`must have required property 'options'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!=="default"&&n!==`binding`&&n!==`options`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0){let n=e.type;if(n!==`select`&&n!==`radio`&&n!==`segmented`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/enum`,keyword:`enum`,params:{allowedValues:C.properties.type.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),o++}}if(e.default!==void 0&&typeof e.default!=`string`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.options!==void 0){let n=e.options;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(e)<1){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}let r=n.length,i;if(r>1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/options`,schemaPath:`#/$defs/options/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return w.errors=a,o===0}function T(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}if(e.options===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`options`},message:`must have required property 'options'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!==`binding`&&n!=="default"&&n!==`options`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`checkboxGroup`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`checkboxGroup`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.default!==void 0){let n=e.default;if(Array.isArray(n)){let e=n.length;for(let r=0;r1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/default`,schemaPath:`#/properties/default/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.options!==void 0){let n=e.options;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(e)<1){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}let r=n.length,i;if(r>1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/options`,schemaPath:`#/$defs/options/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return T.errors=a,o===0}var E={type:`object`,additionalProperties:!1,required:[`id`,`label`,`type`,`default`],properties:{id:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},type:{enum:[`text`,`textarea`]},default:{type:`string`},binding:{$ref:`#/$defs/binding`},minLength:{type:`integer`,minimum:0},maxLength:{type:`integer`,minimum:0},group:{$ref:`#/$defs/id`},when:{$ref:`#/$defs/condition`}}};function D(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(E.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0){let n=e.type;if(n!==`text`&&n!==`textarea`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/enum`,keyword:`enum`,params:{allowedValues:E.properties.type.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),l++}}if(e.default!==void 0&&typeof e.default!=`string`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.minLength!==void 0){let n=e.minLength;if(typeof n!=`number`||n%1||isNaN(n)||!isFinite(n)){let e={instancePath:t+`/minLength`,schemaPath:`#/properties/minLength/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};a===null?a=[e]:a.push(e),l++}if(typeof n==`number`&&isFinite(n)&&(n<0||isNaN(n))){let e={instancePath:t+`/minLength`,schemaPath:`#/properties/minLength/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:0},message:`must be >= 0`};a===null?a=[e]:a.push(e),l++}}if(e.maxLength!==void 0){let n=e.maxLength;if(typeof n!=`number`||n%1||isNaN(n)||!isFinite(n)){let e={instancePath:t+`/maxLength`,schemaPath:`#/properties/maxLength/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};a===null?a=[e]:a.push(e),l++}if(typeof n==`number`&&isFinite(n)&&(n<0||isNaN(n))){let e={instancePath:t+`/maxLength`,schemaPath:`#/properties/maxLength/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:0},message:`must be >= 0`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return D.errors=a,l===0}var O=RegExp(`^#[0-9a-fA-F]{6}$`,`u`);function k(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!=="default"&&n!==`binding`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`color`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`color`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.default!==void 0){let n=e.default;if(typeof n==`string`){if(!O.test(n)){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/pattern`,keyword:`pattern`,params:{pattern:`^#[0-9a-fA-F]{6}$`},message:`must match pattern "^#[0-9a-fA-F]{6}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return k.errors=a,o===0}function A(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!==`binding`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`button`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`button`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return A.errors=a,o===0}function j(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let l=null,u=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.version===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`version`},message:`must have required property 'version'`};l===null?l=[e]:l.push(e),u++}if(e.scope===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`scope`},message:`must have required property 'scope'`};l===null?l=[e]:l.push(e),u++}if(e.controls===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`controls`},message:`must have required property 'controls'`};l===null?l=[e]:l.push(e),u++}for(let n in e)if(!o.call(a.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};l===null?l=[e]:l.push(e),u++}if(e.$schema!==void 0&&typeof e.$schema!=`string`){let e={instancePath:t+`/$schema`,schemaPath:`#/properties/%24schema/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}if(e.version!==void 0&&e.version!==1){let e={instancePath:t+`/version`,schemaPath:`#/properties/version/const`,keyword:`const`,params:{allowedValue:1},message:`must be equal to constant`};l===null?l=[e]:l.push(e),u++}if(e.scope!==void 0){let n=e.scope;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/scope`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/scope`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}if(e.role!==void 0){let n=e.role;if(n!==`shared`&&n!==`page`){let e={instancePath:t+`/role`,schemaPath:`#/properties/role/enum`,keyword:`enum`,params:{allowedValues:a.properties.role.enum},message:`must be equal to one of the allowed values`};l===null?l=[e]:l.push(e),u++}}if(e.container!==void 0){let n=e.container;if(typeof n==`string`){if(s(n)>512){let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/maxLength`,keyword:`maxLength`,params:{limit:512},message:`must NOT have more than 512 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}if(e.panel!==void 0){let n=e.panel;if(n&&typeof n==`object`&&!Array.isArray(n)){if(n.width===void 0){let e={instancePath:t+`/panel`,schemaPath:`#/properties/panel/required`,keyword:`required`,params:{missingProperty:`width`},message:`must have required property 'width'`};l===null?l=[e]:l.push(e),u++}for(let e in n)if(e!==`width`){let n={instancePath:t+`/panel`,schemaPath:`#/properties/panel/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:e},message:`must NOT have additional properties`};l===null?l=[n]:l.push(n),u++}if(n.width!==void 0){let e=n.width;if(typeof e!=`number`||e%1||isNaN(e)||!isFinite(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};l===null?l=[e]:l.push(e),u++}if(typeof e==`number`&&isFinite(e)){if(e>4096||isNaN(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/maximum`,keyword:`maximum`,params:{comparison:`<=`,limit:4096},message:`must be <= 4096`};l===null?l=[e]:l.push(e),u++}if(e<160||isNaN(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:160},message:`must be >= 160`};l===null?l=[e]:l.push(e),u++}}}}else{let e={instancePath:t+`/panel`,schemaPath:`#/properties/panel/type`,keyword:`type`,params:{type:`object`},message:`must be object`};l===null?l=[e]:l.push(e),u++}}if(e.groups!==void 0){let n=e.groups;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/groups`,schemaPath:`#/properties/groups/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};l===null?l=[e]:l.push(e),u++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/groups/`+r+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(l=l===null?f.errors:l.concat(f.errors),u=l.length))}else{let e={instancePath:t+`/groups/`+r,schemaPath:`#/properties/groups/items/type`,keyword:`type`,params:{type:`object`},message:`must be object`};l===null?l=[e]:l.push(e),u++}}}else{let e={instancePath:t+`/groups`,schemaPath:`#/properties/groups/type`,keyword:`type`,params:{type:`array`},message:`must be array`};l===null?l=[e]:l.push(e),u++}}if(e.controls!==void 0){let n=e.controls;if(Array.isArray(n)){if(n.length>500){let e={instancePath:t+`/controls`,schemaPath:`#/properties/controls/maxItems`,keyword:`maxItems`,params:{limit:500},message:`must NOT have more than 500 items`};l===null?l=[e]:l.push(e),u++}let e=n.length;for(let r=0;r100){let e={instancePath:t+`/sets`,schemaPath:`#/properties/sets/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/sets`,schemaPath:`#/properties/sets/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}if(e.role!==void 0){let n=e.role;if(n!==`shared`&&n!==`page`){let e={instancePath:t+`/role`,schemaPath:`#/properties/role/enum`,keyword:`enum`,params:{allowedValues:a.properties.role.enum},message:`must be equal to one of the allowed values`};l===null?l=[e]:l.push(e),u++}}if(e.container!==void 0){let n=e.container;if(typeof n==`string`){if(s(n)>512){let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/maxLength`,keyword:`maxLength`,params:{limit:512},message:`must NOT have more than 512 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}if(e.panel!==void 0){let n=e.panel;if(n&&typeof n==`object`&&!Array.isArray(n)){if(n.width===void 0){let e={instancePath:t+`/panel`,schemaPath:`#/properties/panel/required`,keyword:`required`,params:{missingProperty:`width`},message:`must have required property 'width'`};l===null?l=[e]:l.push(e),u++}for(let e in n)if(e!==`width`){let n={instancePath:t+`/panel`,schemaPath:`#/properties/panel/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:e},message:`must NOT have additional properties`};l===null?l=[n]:l.push(n),u++}if(n.width!==void 0){let e=n.width;if(typeof e!=`number`||e%1||isNaN(e)||!isFinite(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};l===null?l=[e]:l.push(e),u++}if(typeof e==`number`&&isFinite(e)){if(e>4096||isNaN(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/maximum`,keyword:`maximum`,params:{comparison:`<=`,limit:4096},message:`must be <= 4096`};l===null?l=[e]:l.push(e),u++}if(e<160||isNaN(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:160},message:`must be >= 160`};l===null?l=[e]:l.push(e),u++}}}}else{let e={instancePath:t+`/panel`,schemaPath:`#/properties/panel/type`,keyword:`type`,params:{type:`object`},message:`must be object`};l===null?l=[e]:l.push(e),u++}}if(e.groups!==void 0){let n=e.groups;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/groups`,schemaPath:`#/properties/groups/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};l===null?l=[e]:l.push(e),u++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/groups/`+r+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(l=l===null?f.errors:l.concat(f.errors),u=l.length))}else{let e={instancePath:t+`/groups/`+r,schemaPath:`#/properties/groups/items/type`,keyword:`type`,params:{type:`object`},message:`must be object`};l===null?l=[e]:l.push(e),u++}}}else{let e={instancePath:t+`/groups`,schemaPath:`#/properties/groups/type`,keyword:`type`,params:{type:`array`},message:`must be array`};l===null?l=[e]:l.push(e),u++}}if(e.controls!==void 0){let n=e.controls;if(Array.isArray(n)){if(n.length>500){let e={instancePath:t+`/controls`,schemaPath:`#/properties/controls/maxItems`,keyword:`maxItems`,params:{limit:500},message:`must NOT have more than 500 items`};l===null?l=[e]:l.push(e),u++}let e=n.length;for(let r=0;r100){let e={instancePath:t+`/sets`,schemaPath:`#/properties/sets/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/sets`,schemaPath:`#/properties/sets/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`boolean`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`boolean`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.default!==void 0&&typeof e.default!=`boolean`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`boolean`},message:`must be boolean`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return I.errors=a,o===0}e.number=L;function L(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}if(e.min===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`min`},message:`must have required property 'min'`};a===null?a=[e]:a.push(e),l++}if(e.max===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`max`},message:`must have required property 'max'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(y.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0&&e.type!==`number`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`number`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),l++}if(e.default!==void 0){let n=e.default;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.min!==void 0){let n=e.min;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/min`,schemaPath:`#/properties/min/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.max!==void 0){let n=e.max;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/max`,schemaPath:`#/properties/max/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.step!==void 0){let n=e.step;if(typeof n==`number`&&isFinite(n)){if(n<=0||isNaN(n)){let e={instancePath:t+`/step`,schemaPath:`#/properties/step/exclusiveMinimum`,keyword:`exclusiveMinimum`,params:{comparison:`>`,limit:0},message:`must be > 0`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/step`,schemaPath:`#/properties/step/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return L.errors=a,l===0}e.slider=te;function te(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}if(e.min===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`min`},message:`must have required property 'min'`};a===null?a=[e]:a.push(e),l++}if(e.max===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`max`},message:`must have required property 'max'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(x.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0&&e.type!==`slider`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`slider`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),l++}if(e.default!==void 0){let n=e.default;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.min!==void 0){let n=e.min;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/min`,schemaPath:`#/properties/min/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.max!==void 0){let n=e.max;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/max`,schemaPath:`#/properties/max/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.step!==void 0){let n=e.step;if(typeof n==`number`&&isFinite(n)){if(n<=0||isNaN(n)){let e={instancePath:t+`/step`,schemaPath:`#/properties/step/exclusiveMinimum`,keyword:`exclusiveMinimum`,params:{comparison:`>`,limit:0},message:`must be > 0`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/step`,schemaPath:`#/properties/step/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return te.errors=a,l===0}e.choice=ne;function ne(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}if(e.options===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`options`},message:`must have required property 'options'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!=="default"&&n!==`binding`&&n!==`options`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0){let n=e.type;if(n!==`select`&&n!==`radio`&&n!==`segmented`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/enum`,keyword:`enum`,params:{allowedValues:C.properties.type.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),o++}}if(e.default!==void 0&&typeof e.default!=`string`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.options!==void 0){let n=e.options;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(e)<1){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}let r=n.length,i;if(r>1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/options`,schemaPath:`#/$defs/options/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return ne.errors=a,o===0}e.checkboxGroup=R;function R(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}if(e.options===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`options`},message:`must have required property 'options'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!==`binding`&&n!=="default"&&n!==`options`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`checkboxGroup`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`checkboxGroup`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.default!==void 0){let n=e.default;if(Array.isArray(n)){let e=n.length;for(let r=0;r1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/default`,schemaPath:`#/properties/default/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.options!==void 0){let n=e.options;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(e)<1){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}let r=n.length,i;if(r>1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/options`,schemaPath:`#/$defs/options/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return R.errors=a,o===0}e.text=re;function re(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(E.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0){let n=e.type;if(n!==`text`&&n!==`textarea`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/enum`,keyword:`enum`,params:{allowedValues:E.properties.type.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),l++}}if(e.default!==void 0&&typeof e.default!=`string`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.minLength!==void 0){let n=e.minLength;if(typeof n!=`number`||n%1||isNaN(n)||!isFinite(n)){let e={instancePath:t+`/minLength`,schemaPath:`#/properties/minLength/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};a===null?a=[e]:a.push(e),l++}if(typeof n==`number`&&isFinite(n)&&(n<0||isNaN(n))){let e={instancePath:t+`/minLength`,schemaPath:`#/properties/minLength/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:0},message:`must be >= 0`};a===null?a=[e]:a.push(e),l++}}if(e.maxLength!==void 0){let n=e.maxLength;if(typeof n!=`number`||n%1||isNaN(n)||!isFinite(n)){let e={instancePath:t+`/maxLength`,schemaPath:`#/properties/maxLength/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};a===null?a=[e]:a.push(e),l++}if(typeof n==`number`&&isFinite(n)&&(n<0||isNaN(n))){let e={instancePath:t+`/maxLength`,schemaPath:`#/properties/maxLength/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:0},message:`must be >= 0`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return re.errors=a,l===0}e.color=z;function z(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!=="default"&&n!==`binding`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`color`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`color`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.default!==void 0){let n=e.default;if(typeof n==`string`){if(!O.test(n)){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/pattern`,keyword:`pattern`,params:{pattern:`^#[0-9a-fA-F]{6}$`},message:`must match pattern "^#[0-9a-fA-F]{6}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return z.errors=a,o===0}e.button=ie;function ie(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!==`binding`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`button`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`button`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return ie.errors=a,o===0}}))(),1),{validateDocumentShape:Fe,validateDeclaration:Ie}=Z.default,Le={boolean:`boolean`,number:`number`,slider:`slider`,select:`choice`,radio:`choice`,segmented:`choice`,checkboxGroup:`checkboxGroup`,text:`text`,textarea:`text`,color:`color`,button:`button`};function Re(e){let t=[...Ie.errors].filter(e=>!/^\/controls\/\d+(?:\/|$)/.test(e.instancePath)).map(e=>({...e}));return Array.isArray(e?.controls)&&e.controls.forEach((e,n)=>{let r=Object.hasOwn(Le,e?.type)?Le[e.type]:void 0,i=r&&Z.default[r];i?i(e)||t.push(...i.errors.map(e=>({...e,instancePath:`/controls/${n}${e.instancePath}`}))):t.push({instancePath:`/controls/${n}/type`,message:`must name a supported control type`})}),t.map(e=>({path:e.instancePath,message:e.keyword===`additionalProperties`?`${e.message}: "${e.params.additionalProperty}"`:e.message,keyword:e.keyword,params:e.params}))}var ze=class extends Error{constructor(e){super(`Invalid controls.replica.json:\n${e.map(e=>` ${e.path||`/`}: ${e.message}`).join(` -`)}`),this.name=`ControlsValidationError`,this.issues=e}};function Be(e,t){switch(e.type){case`boolean`:return typeof t==`boolean`?null:`must be a boolean`;case`number`:case`slider`:{if(typeof t!=`number`||!Number.isFinite(t))return`must be a finite number`;if(e.min!==void 0&&t= min`;if(e.max!==void 0&&t>e.max)return`must be <= max`;let n=(t-e.min)/(e.step??1);return!Number.isFinite(n)||Math.abs(n-Math.round(n))>1e-8?`must align with step (anchored at min)`:null}case`select`:case`radio`:case`segmented`:return e.options.includes(t)?null:`must be a declared option`;case`checkboxGroup`:return Array.isArray(t)&&new Set(t).size===t.length&&t.every(t=>e.options.includes(t))?null:`must be unique declared options`;case`text`:case`textarea`:return typeof t==`string`?e.minLength!==void 0&&[...t].lengthe.maxLength?`longer than maxLength`:null:`must be a string`;case`color`:return typeof t==`string`&&/^#[0-9a-fA-F]{6}$/.test(t)?null:`must be a six-digit hex color`;default:return`button controls have no value`}}function Ve(e){return e?e.control?[e.control]:(e.all??e.any).flatMap(Ve):[]}function He(e){let t=new Map((e.groups??[]).map(e=>[e.id,e])),n=new Map(e.controls.map(e=>[e.id,e])),r=new Set,i=new Set,a=[];function o(e){if(r.has(e))return;if(i.has(e))throw new ze([{path:`/controls/${e}/when`,message:`conditional dependency cycle (including groups)`}]);i.add(e);let s=n.get(e);for(let e of[...Ve(s.when),...Ve(t.get(s.group)?.when)])o(e);i.delete(e),r.add(e),a.push(e)}for(let e of n.keys())o(e);return a}function Ue(e){let t=new Set;function n(e,r=0){if(r>24)throw new ze([{path:`/`,message:`document nesting exceeds 24`}]);if(typeof e==`number`&&!Number.isFinite(e))throw new ze([{path:`/`,message:`numbers must be finite`}]);if(![`string`,`number`,`boolean`,`object`].includes(typeof e))throw new ze([{path:`/`,message:`must contain only JSON values`}]);if(e&&typeof e==`object`){if(!Array.isArray(e)&&Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw new ze([{path:`/`,message:`must contain only JSON objects`}]);if(t.has(e))throw new ze([{path:`/`,message:`must be an acyclic JSON document`}]);t.add(e);for(let t of Object.values(e))n(t,r+1);t.delete(e)}}n(e)}function We(e){if(Ue(e),!Ie(e))throw new ze(Re(e));let t=[];function n(e,n){t.push({path:e,message:n})}let r=new Set,i=new Map((e.groups??[]).map(e=>[e.id,e])),a=new Map(e.controls.map(e=>[e.id,e]));for(let[t,i]of[[`groups`,e.groups??[]],[`controls`,e.controls]])i.forEach((e,i)=>{r.has(e.id)&&n(`/${t}/${i}/id`,`duplicate ID ${e.id}`),r.add(e.id)});function o(e,t,r=0){if(!e)return;if(r>4){n(t,`conditions support at most five levels`);return}if(e.all||e.any){let n=e.all?`all`:`any`;e[n].forEach((e,i)=>o(e,`${t}/${n}/${i}`,r+1));return}let i=a.get(e.control);if(!i||i.type===`button`)n(t,`condition must reference a value control`);else if(`includes`in e)(i.type!==`checkboxGroup`||!i.options.includes(e.includes))&&n(t,`includes requires a declared checkboxGroup option`);else if(i.type===`checkboxGroup`)n(t,`checkboxGroup conditions must use includes`);else for(let r of`in`in e?e.in:[e.equals]){let e=Be(i,r);e&&n(t,`invalid condition for ${i.id}: ${e}`)}}if(e.controls.forEach((e,t)=>{let r=`/controls/${t}`;if(e.group&&!i.has(e.group)&&n(`${r}/group`,`unknown group`),e.min!==void 0&&e.max!==void 0&&e.min>e.max&&n(r,`min must not exceed max`),e.minLength!==void 0&&e.maxLength!==void 0&&e.minLength>e.maxLength&&n(r,`minLength must not exceed maxLength`),e.type===`segmented`&&e.options.length>3&&n(`${r}/options`,`segmented supports at most three options`),e.type!==`button`){let t=Be(e,e.default);t&&n(`${r}/default`,t)}o(e.when,`${r}/when`)}),(e.groups??[]).forEach((e,t)=>o(e.when,`/groups/${t}/when`)),t.length)throw new ze(t);return He(e),e}function Ge(e,t){let[n,r]=(0,V.useState)(e),[i,a]=(0,V.useState)(null),o=(0,V.useRef)(e),s=(0,V.useRef)(e),c=(0,V.useRef)(0),l=(0,V.useRef)(!1);(0,V.useLayoutEffect)(()=>{s.current=e,l.current||(o.current=e,r(e))},[e]),(0,V.useLayoutEffect)(()=>()=>{c.current++},[]);function u(e){c.current++,l.current=!0,o.current=e,r(e),a(null)}function d(){c.current++,l.current=!1,o.current=s.current,r(s.current),a(null)}function f(e,n=e){u(e);let i=c.current;Promise.resolve().then(()=>t(n)).then(e=>{c.current===i&&(l.current=!1,o.current=e&&`value`in e?e.value:s.current,r(o.current))}).catch(()=>{c.current===i&&(d(),a(K.controlsValueNotApplied))})}return{draft:n,error:i,current:()=>o.current,stage:u,commit:f,reset:d}}function Ke(e){let t=e.step??1,n=Math.max(...[e.min,e.max,t].map(e=>{let[t=``,n=`0`]=String(e).split(`e`);return Math.max(0,(t.split(`.`)[1]?.length??0)-Number(n))})),r=Math.max(...[e.min,e.max].map(e=>n<=100?e.toFixed(n).length:String(e).length),String(e.default).length,String(t).length);return e.type===`slider`?`calc(${r}ch + var(--hub-space-8) * 2)`:`calc(${r}ch + var(--hub-space-8) * 2 + 1.25rem)`}function qe({id:e,control:t,value:n,disabled:r,message:i,onCommit:a}){let o=Ge(n,a),[s,c]=(0,V.useState)(null);function l(e){let n=e.target.value,r=t.type===`number`||t.type===`slider`?n===``?NaN:Number(n):n,i=Be(t,r);c(i),i?o.stage(n):o.commit(n,r)}let u=s||o.error,d=t.type===`number`||t.type===`slider`,f=t.type===`slider`?{"--controls-slider-progress":`${t.min===t.max?100:(Number(n)-t.min)/(t.max-t.min)*100}%`}:void 0,p=[i?`${e}-hint`:void 0,u?`${e}-validation`:void 0].filter(Boolean).join(` `)||void 0,m={id:e,disabled:r,value:String(o.draft),onChange:l,"aria-invalid":u?!0:void 0,"aria-describedby":p,onBlur:()=>{s&&(o.reset(),c(null))}},h;return h=t.type===`textarea`?(0,U.jsx)(H.Textarea,{...m,rows:2,resize:`vertical`}):d?(0,U.jsx)(H.TextInput,{...m,className:t.type===`slider`?`controls-number-input controls-number-input--slider`:`controls-number-input`,type:`number`,min:t.min,max:t.max,step:t.step??1,validationStatus:u?`error`:void 0,"aria-labelledby":`${e}-label`,style:{width:Ke(t)}}):t.type===`color`?(0,U.jsx)(`input`,{...m,className:`controls-native-color`,type:`color`}):(0,U.jsx)(H.TextInput,{...m,type:`text`}),(0,U.jsxs)(H.FormControl,{id:e,className:d?`controls-field controls-field--${t.type}`:`controls-field`,fullWidth:!d||t.type===`slider`,validationStatus:u?`error`:void 0,children:[d?(0,U.jsxs)(`div`,{className:`controls-field-heading`,children:[(0,U.jsx)(H.FormControl.Label,{id:`${e}-label`,htmlFor:e,className:`controls-field-label`,children:t.label}),t.type===`slider`?(0,U.jsxs)(`div`,{className:`controls-slider-row`,children:[(0,U.jsx)(`input`,{...m,id:`${e}-slider`,value:String(n),className:`controls-native-slider`,type:`range`,style:f,min:t.min,max:t.max,step:t.step??1,"aria-labelledby":`${e}-label`}),h]}):h]}):(0,U.jsx)(H.FormControl.Label,{className:`controls-field-label`,children:t.label}),d?null:h,i?(0,U.jsx)(H.FormControl.Hint,{children:(0,U.jsx)(`span`,{role:`status`,children:i})}):null,u?(0,U.jsx)(H.FormControl.Validation,{className:`controls-field-validation`,"aria-live":`polite`,children:u}):null]})}function Je({id:e,control:t,value:n,disabled:r,message:i,onCommit:a}){let o=Ge(n,a),s=[i?`${e}-unavailable`:void 0,o.error?`${e}-validation`:void 0].filter(Boolean).join(` `)||void 0;if(t.type===`boolean`||t.type===`select`)return(0,U.jsxs)(H.FormControl,{id:e,className:t.type===`boolean`?`controls-field controls-choice-row`:`controls-field controls-field--select`,fullWidth:t.type===`boolean`,validationStatus:o.error?`error`:void 0,children:[t.type===`select`?(0,U.jsx)(H.FormControl.Label,{className:`controls-field-label`,children:t.label}):null,t.type===`boolean`?(0,U.jsx)(H.Checkbox,{className:`controls-choice-mark`,disabled:r,"aria-describedby":s,checked:o.draft===!0,onChange:e=>o.commit(e.target.checked)}):(0,U.jsx)(H.Select,{className:`controls-select-input`,disabled:r,"aria-describedby":s,value:o.draft,onChange:e=>o.commit(e.target.value),children:t.options.map(e=>(0,U.jsx)(H.Select.Option,{value:e,children:e},e))}),t.type===`boolean`?(0,U.jsx)(H.FormControl.Label,{className:`controls-choice-label`,children:t.label}):null,i?(0,U.jsx)(H.FormControl.Hint,{children:(0,U.jsx)(`span`,{role:`status`,children:i})}):null,o.error?(0,U.jsx)(H.FormControl.Validation,{className:`controls-field-validation`,"aria-live":`polite`,children:o.error}):null]});let c=t.type===`checkboxGroup`,l=t.type===`segmented`,u=c?H.CheckboxGroup:H.RadioGroup,d=c?H.Checkbox:H.Radio;return(0,U.jsxs)(u,{id:e,className:`controls-field`,"aria-disabled":r||void 0,"aria-describedby":s,children:[(0,U.jsx)(u.Label,{className:`controls-choice-group-label`,children:t.label}),(0,U.jsx)(`div`,{className:l?`controls-segments`:`controls-options`,children:t.options.map((t,n)=>{let i=`${e}-${n}`,a=c?o.draft.includes(t):o.draft===t,u=(0,U.jsx)(d,{className:c?`controls-choice-mark`:`controls-choice-mark controls-choice-mark--radio`,id:i,name:e,value:t,checked:a,disabled:r,"aria-describedby":s,onChange:e=>{let n=o.current();o.commit(c?e.target.checked?[...n,t]:n.filter(e=>e!==t):t)}});return l?(0,U.jsxs)(`label`,{htmlFor:i,className:`controls-segment`,title:t,children:[(0,U.jsx)(W,{children:u}),(0,U.jsx)(H.Text,{as:`span`,size:`100`,weight:`medium`,children:t})]},t):(0,U.jsxs)(H.FormControl,{id:i,className:`controls-field controls-choice-row`,children:[u,(0,U.jsx)(H.FormControl.Label,{className:`controls-choice-label`,children:t})]},t)})}),i?(0,U.jsx)(H.Text,{as:`span`,id:`${e}-unavailable`,size:`100`,variant:`muted`,role:`status`,children:i}):null,o.error?(0,U.jsx)(u.Validation,{variant:`error`,role:`status`,children:o.error}):null]})}function Ye(e,t){let n=e.snapshot.bindings?.[t.id],r=e.snapshot.actions[t.id];return{scope:e.declaration.scope,id:t.id,visible:e.snapshot.visible[t.id]===!0,available:(t.type!==`button`||r?.available===!0)&&(!n?.error||n.available===!0),busy:n?.busy===!0||r?.busy===!0,error:n?.error||(t.type===`button`&&!r?.available?K.controlsActionUnavailable:``)}}function Xe({scopes:e,disabled:t=!1,onCommand:n,collapsedGroups:r,onGroupCollapse:i}){let a=(0,V.useId)(),o=(0,V.useRef)(null),s=(0,V.useRef)(null),[c,l]=(0,V.useState)({});(0,V.useLayoutEffect)(()=>{s.current&&!s.current.isConnected&&(document.activeElement===document.body&&o.current?.focus(),s.current=null)},[e]);function u(e,r){if(!e.snapshot.visible[r.id])return null;let i=`${a}-${e.declaration.scope}-${r.id}`,o=e.snapshot.values[r.id];function s(t){return n(`update`,e.declaration.scope,r.id,t)}let c=e.snapshot.bindings?.[r.id],l=Ye(e,r),u={id:i,message:l.error?l.available?K.controlsNotApplied(r.label):K.controlsUnavailable(r.label):void 0,disabled:t||!!c?.error&&c?.available!==!0||c?.busy===!0};switch(r.type){case`button`:{let t=e.snapshot.actions[r.id];return(0,U.jsx)(`div`,{className:`controls-field controls-action-field`,children:(0,U.jsxs)(H.Button,{type:`button`,size:`small`,variant:`secondary`,className:`controls-action-button`,disabled:u.disabled||!t?.available||t.busy,"aria-describedby":u.message?`${i}-unavailable`:void 0,"aria-busy":t?.busy,onClick:()=>{n(`action`,e.declaration.scope,r.id)},children:[r.label,t?.busy?K.controlsActionBusy:``]})},r.id)}case`boolean`:case`select`:case`radio`:case`segmented`:case`checkboxGroup`:return(0,U.jsx)(Je,{...u,control:r,value:o,onCommit:s},r.id);case`number`:case`slider`:case`text`:case`textarea`:case`color`:return(0,U.jsx)(qe,{...u,control:r,value:o,onCommit:s},r.id)}}function d(e,t){if(!e.snapshot.visible[t.id])return null;let n=Ye(e,t);return(0,U.jsxs)(V.Fragment,{children:[u(e,t),t.type===`button`&&n.error?(0,U.jsx)(H.Text,{as:`p`,id:`${a}-${e.declaration.scope}-${t.id}-unavailable`,size:`100`,variant:`muted`,role:`status`,children:n.available?K.controlsNotApplied(t.label):K.controlsUnavailable(t.label)}):null]},t.id)}let f=[...e.filter(e=>e.declaration.role===`shared`),...e.filter(e=>e.declaration.role!==`shared`)].filter(e=>e.declaration.controls.some(t=>t.group?e.snapshot.groups[t.group]:e.snapshot.visible[t.id]));return(0,U.jsx)(`div`,{ref:o,tabIndex:-1,role:`region`,"aria-label":K.controlsRegion,className:`controls-fields`,onFocusCapture:e=>{s.current=e.target},children:f.map((e,t)=>{let n=new Set;return(0,U.jsxs)(`section`,{className:`controls-scope`,"aria-label":e.declaration.label??e.declaration.scope,children:[t>0?(0,U.jsx)(`hr`,{className:`controls-scope-divider`}):null,e.declaration.controls.map(t=>{if(!t.group)return d(e,t);if(n.has(t.group))return null;n.add(t.group);let o=e.declaration.groups?.find(e=>e.id===t.group);if(!o||!e.snapshot.groups[o.id])return null;let s=`${e.declaration.scope}/${o.id}`,u=(r??c)[s]===!0,f=`${a}-${e.declaration.scope}-${o.id}-group`;return(0,U.jsxs)(`fieldset`,{className:`controls-group`,"aria-label":o.label,children:[(0,U.jsx)(`legend`,{children:(0,U.jsx)(H.Button,{size:`small`,variant:`subtle`,type:`button`,block:!0,className:`controls-group-toggle controls-ghost-button`,"aria-label":u?K.controlsExpandGroup(o.label):K.controlsCollapseGroup(o.label),"aria-controls":f,"aria-expanded":!u,trailingVisual:u?(0,U.jsx)(p,{size:16}):(0,U.jsx)(g,{size:16}),onClick:t=>{t.currentTarget.focus(),i?i(e.declaration.scope,o.id,!u):l(e=>({...e,[s]:!u}))},children:(0,U.jsx)(H.Text,{as:`span`,size:`100`,weight:`bold`,variant:`muted`,className:`controls-group-label`,children:o.label})})}),(0,U.jsx)(`div`,{id:f,className:`controls-group-body`,hidden:u,children:e.declaration.controls.filter(e=>e.group===o.id).map(t=>d(e,t))})]},o.id)})]},e.declaration.scope)})})}function Ze(e){return Object.fromEntries(e.declaration.controls.filter(t=>t.type!==`button`&&e.snapshot.visible[t.id]&&JSON.stringify(e.snapshot.values[t.id])!==JSON.stringify(t.default)).map(t=>[t.id,e.snapshot.values[t.id]]))}function Qe(e,t){let n=(0,V.useRef)(null),r=(0,V.useRef)(null),i=(0,V.useRef)(null),a=(0,V.useRef)({position:e,onChange:t}),o=(0,V.useRef)(null),[s,c]=(0,V.useState)(!1);(0,V.useLayoutEffect)(()=>{a.current={position:e,onChange:t}});let l=(0,V.useCallback)(e=>{let t=n.current?.getBoundingClientRect(),i=r.current?.getBoundingClientRect();if(!t||!i||!t.width||!t.height)return;let o={x:Math.max(0,Math.min(e.x,Math.max(0,t.width-i.width))),y:Math.max(0,Math.min(e.y,Math.max(0,t.height-i.height)))};(a.current.position?.x!==o.x||a.current.position?.y!==o.y)&&a.current.onChange(o)},[]);(0,V.useLayoutEffect)(()=>{let e=n.current,t=r.current;if(!e||!t)return;function i(){let n=e?.getBoundingClientRect(),r=t?.getBoundingClientRect();if(!n||!r||!n.width||!n.height)return;let i=r.left-n.left,a=r.top-n.top;(i<0||a<0||i>Math.max(0,n.width-r.width)||a>Math.max(0,n.height-r.height))&&l({x:i,y:a})}let a=new ResizeObserver(i);return a.observe(e),a.observe(t),window.addEventListener(`resize`,i),i(),()=>{a.disconnect(),window.removeEventListener(`resize`,i)}},[l]);function u(e=!1){let t=o.current;o.current=null,c(!1),t&&(e&&l(t.origin),i.current?.hasPointerCapture(t.pointerId)&&i.current.releasePointerCapture(t.pointerId))}return{boundsRef:n,panelRef:r,handleRef:i,dragging:s,onPointerDown:e=>{if(e.button!==0||o.current)return;let t=n.current?.getBoundingClientRect(),i=r.current?.getBoundingClientRect();t&&i&&(o.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY,origin:{x:i.left-t.left,y:i.top-t.top}},e.currentTarget.setPointerCapture(e.pointerId),e.currentTarget.focus(),e.preventDefault(),c(!0))},onPointerMove:e=>{let t=o.current;t&&t.pointerId===e.pointerId&&l({x:t.origin.x+e.clientX-t.x,y:t.origin.y+e.clientY-t.y})},onPointerUp:e=>{o.current?.pointerId===e.pointerId&&u()},onPointerCancel:e=>{o.current?.pointerId===e.pointerId&&u(!0)},onLostPointerCapture:()=>{o.current&&u()},onKeyDown:e=>{if(e.key===`Escape`&&o.current){e.preventDefault(),u(!0);return}if(![`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`].includes(e.key))return;let t=n.current?.getBoundingClientRect(),i=r.current?.getBoundingClientRect();if(!t||!i)return;e.preventDefault();let a=e.shiftKey?1:10;l({x:i.left-t.left+(e.key===`ArrowLeft`?-a:e.key===`ArrowRight`?a:0),y:i.top-t.top+(e.key===`ArrowUp`?-a:e.key===`ArrowDown`?a:0)})}}}function $e(e){let t=e.filter(e=>e.declaration.role!==`shared`),n=t.length?t:e;return n.length?Math.max(...n.map(e=>e.declaration.panel?.width??288)):288}function et({state:e,connection:t,layout:n,onLayoutChange:r,onDiagnose:i,diagnosisTarget:a=``}){let o=e.loading?[]:e.scopes.flatMap(e=>e.declaration.controls.flatMap(t=>{let n=Ye(e,t);return n.visible&&n.error?[{...n,label:t.label}]:[]})),s=!!(i&&!e.loading&&(!e.runtimeAvailable&&e.error||e.storageError||o.length||e.reconnectRequired||e.status===`missing-runtime`||e.status===`unsupported-runtime`||e.status===`invalid-config`)),c=s?JSON.stringify([a,e.status,e.runtimeAvailable,e.reconnectRequired,e.error,e.storageError,o.map(({scope:e,id:t,error:n})=>[e,t,n])]):``,[l,d]=(0,V.useState)(()=>({episode:c,identity:{},busy:!1,requested:!1,error:``}));l.episode!==c&&d({episode:c,identity:{},busy:!1,requested:!1,error:``});async function f(){if(!i||!s||l.busy||l.requested)return;let e=l.identity;d(t=>t.identity===e?{...t,busy:!0,error:``}:t);try{await i(),d(t=>t.identity===e?{...t,requested:!0}:t)}catch(t){d(n=>n.identity===e?{...n,error:t instanceof Error?t.message:K.controlsDiagnosisFailed}:n)}finally{d(t=>t.identity===e?{...t,busy:!1}:t)}}let p=(0,V.useId)(),m=(0,V.useId)(),_=(0,V.useRef)(null),{boundsRef:v,panelRef:y,handleRef:b,dragging:x,onPointerDown:S,onPointerMove:C,onPointerUp:w,onPointerCancel:T,onLostPointerCapture:E,onKeyDown:D}=Qe(n.position,e=>r(t=>({...t,position:e})));(0,V.useEffect)(()=>{b.current?.focus()},[b]),(0,V.useLayoutEffect)(()=>{_.current&&!_.current.isConnected&&(document.activeElement===document.body&&b.current?.focus(),_.current=null)},[e,b]);let O=e.loading?K.controlsConnecting:e.status===`no-controls`?K.controlsEmpty:e.status===`missing-runtime`?i?K.controlsLocalMissingRuntime:K.controlsMissingRuntime:e.status===`unsupported-runtime`?K.controlsUnsupportedRuntime:e.status===`invalid-config`?K.controlsInvalid:``,k=!e.loading&&(e.storageError||e.reconnectRequired||!e.runtimeAvailable&&e.error),A=!e.loading&&e.status===`no-controls`&&!e.error&&!e.storageError&&!e.reconnectRequired&&!e.scopeErrors?.length&&!e.scopes.length;return(0,U.jsx)(`div`,{ref:v,className:`canvas-controls-layer`,children:(0,U.jsxs)(`aside`,{ref:y,className:`canvas-controls-panel`,"aria-label":K.controls,onFocusCapture:e=>{e.target instanceof HTMLElement&&(_.current=e.target)},"data-collapsed":n.collapsed,"data-dragging":x||void 0,style:{left:n.position?.x,top:n.position?.y,width:`min(${$e(e.scopes)}px, calc(100% - var(--hub-space-16) * 2))`},children:[(0,U.jsxs)(`header`,{className:`canvas-controls-header`,children:[(0,U.jsx)(G,{icon:h,ref:b,size:`small`,variant:`invisible`,className:`canvas-controls-grab controls-ghost-button`,"aria-label":K.controlsMove,"aria-describedby":m,title:``,onPointerDown:S,onPointerMove:C,onPointerUp:w,onPointerCancel:T,onLostPointerCapture:E,onKeyDown:D}),(0,U.jsx)(W,{id:m,children:K.controlsMoveHint}),(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:`subtle`,block:!0,className:`canvas-controls-title controls-ghost-button`,"aria-label":n.collapsed?K.controlsExpand:K.controlsCollapse,"aria-expanded":!n.collapsed,"aria-controls":p,trailingVisual:n.collapsed?(0,U.jsx)(g,{size:16}):(0,U.jsx)(u,{size:16}),onClick:()=>r(e=>({...e,collapsed:!e.collapsed})),children:K.controls}),(0,U.jsx)(G,{icon:L,size:`small`,variant:`invisible`,className:`controls-ghost-button`,"aria-label":K.controlsResetAll,disabled:!e.runtimeAvailable||e.reconnectRequired||e.loading||e.resetting||!e.storageError&&!e.hasResettableValues&&!e.scopes.some(e=>Object.keys(Ze(e)).length>0)||e.scopes.some(e=>Object.values(e.snapshot.actions).some(e=>e.busy))||e.status!==`ready`&&e.status!==`no-controls`&&!e.storageError,onClick:()=>{t.resetAll()}})]}),(0,U.jsxs)(`div`,{id:p,className:`canvas-controls-body`,hidden:n.collapsed,children:[(0,U.jsxs)(`div`,{className:`canvas-controls-content`,children:[O||e.notice?(0,U.jsx)(`div`,{role:`status`,"aria-live":`polite`,children:(0,U.jsx)(H.Text,{as:`p`,size:`100`,variant:`muted`,children:[O,e.notice].filter(Boolean).join(` `)})}):null,!e.loading&&e.error?(0,U.jsx)(H.Text,{as:`p`,size:`100`,role:`alert`,children:e.error}):null,!e.loading&&e.scopeErrors?.map(e=>(0,U.jsx)(H.Text,{as:`p`,size:`100`,role:`alert`,children:K.controlsScopeError(e.scope,e.error)},e.scope)),!e.loading&&e.storageError?(0,U.jsx)(H.Text,{as:`p`,size:`100`,role:`alert`,children:e.storageError}):null,l.error?(0,U.jsx)(H.Text,{as:`p`,size:`100`,role:`alert`,children:l.error}):null,(0,U.jsx)(Xe,{scopes:e.loading?[]:e.scopes,disabled:e.resetting||e.reconnectRequired,collapsedGroups:n.collapsedGroups,onGroupCollapse:(e,t,n)=>r(r=>({...r,collapsedGroups:{...r.collapsedGroups,[`${e}/${t}`]:n}})),onCommand:(e,n,r,i)=>t.command(e,n,r,i)}),o.length?(0,U.jsxs)(H.Accordion,{className:`canvas-controls-diagnostics`,disableAnimation:!0,children:[(0,U.jsx)(H.Accordion.Heading,{children:K.controlsDiagnostics}),(0,U.jsx)(H.Accordion.Content,{children:o.map(({scope:e,id:t,label:n,error:r})=>(0,U.jsxs)(H.Text,{as:`p`,size:`100`,children:[n,`: `,r]},`${e}/${t}`))})]}):null]}),s||k||A?(0,U.jsxs)(`footer`,{className:`canvas-controls-footer`,children:[A?(0,U.jsxs)(H.InlineLink,{className:`canvas-controls-learn-more`,href:`https://github.com/github/replica/blob/main/starter/README.md#prototype-controls`,target:`_blank`,rel:`noopener noreferrer`,children:[K.controlsLearnMore,(0,U.jsx)(ae,{size:16,"aria-hidden":`true`})]}):null,s?(0,U.jsx)(H.Button,{size:`small`,variant:`secondary`,type:`button`,disabled:l.busy||l.requested||e.resetting,onClick:()=>void f(),children:l.requested?K.controlsDiagnosisRequested:o.length?K.controlsFix:K.controlsDiagnose}):null,k?(0,U.jsx)(H.Button,{size:`small`,variant:`secondary`,type:`button`,disabled:e.resetting,onClick:()=>t.retry(),children:e.storageError?K.controlsRetryStorage:K.controlsRetry}):null]}):null]})]})})}var tt=C();function nt({children:e,className:t,...n}){return(0,U.jsx)(`span`,{...n,className:`hub-counter${t?` ${t}`:``}`,children:e})}var rt=(0,V.createContext)(null);function it({source:e,children:t}){return(0,U.jsx)(rt,{value:e,children:t})}function at({title:e,label:t=e,open:n,closeLabel:r,closeDisabled:i=!1,closeShortcut:a,closeRef:o,onClose:s,headerAccessory:c,className:l,contentClassName:u,children:d}){return(0,U.jsxs)(`aside`,{className:`hub-sidebar${l?` ${l}`:``}`,"aria-label":t,"aria-hidden":!n,"data-open":n,inert:!n,children:[(0,U.jsxs)(`header`,{className:`hub-sidebar__header`,children:[(0,U.jsxs)(`div`,{className:`hub-sidebar__heading`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`subhead-medium`,weight:`normal`,children:e}),c]}),(0,U.jsx)(G,{ref:o,icon:z,"aria-label":r,"aria-keyshortcuts":a,title:r,description:r,variant:`invisible`,size:`small`,className:`hub-sidebar__close`,disabled:i,onClick:s})]}),(0,U.jsx)(`div`,{className:`hub-sidebar__content${u?` ${u}`:``}`,children:d})]})}function ot({src:e,size:t=32,className:n}){return(0,U.jsx)(H.Avatar,{src:e||`/avatar-placeholder.svg`,alt:``,size:32,className:`hub-user-avatar hub-user-avatar--${t}${n?` ${n}`:``}`,onError:e=>{let t=e.currentTarget;t.getAttribute(`src`)!==`/avatar-placeholder.svg`&&(t.src=`/avatar-placeholder.svg`)}})}function st({participants:e,size:t}){let n=e.slice(0,4),r=e.length-3;return(0,U.jsxs)(`span`,{className:`review-participant-stack review-participant-stack--${t}`,"data-avatar-count":n.length,"data-participant-count":e.length,"aria-hidden":`true`,children:[(r>1?n.slice(0,3):n).map(e=>(0,U.jsx)(`span`,{className:`review-participant-stack__avatar`,children:(0,U.jsx)(ot,{src:e.avatarUrl,size:24})},e.login)),r>1?(0,U.jsxs)(`span`,{className:`review-participant-stack__avatar review-participant-stack__avatar--overflow`,children:[`+`,r]}):null]})}function ct(e,t){let n=e.path.map(e=>({x:t.x+e.x*t.width,y:t.y+e.y*t.height})),r={x:t.x+t.width,y:t.y};return{path:n,point:n.reduce((e,t)=>{let n=(t.x-r.x)**2+(t.y-r.y)**2;return n{let e=c.current;if(!e)return;function t(){let t=e?.clientWidth??0;if(t)for(let e of l.current.values()){let n=Number.parseFloat(e.style.left),r=e.offsetWidth;if(!Number.isFinite(n)||!r)continue;let i=n-16,a=Math.max(0,Math.min(i,t-r))-i;e.style.setProperty(`--review-marker-offset-x`,`${a}px`)}}t();let n=typeof ResizeObserver>`u`?null:new ResizeObserver(t);n?.observe(e);for(let e of l.current.values())n?.observe(e);return window.addEventListener(`resize`,t),()=>{n?.disconnect(),window.removeEventListener(`resize`,t)}},[t,e]),(0,V.useEffect)(()=>{!i||n===null||u!==`resolved`&&u!==`moved`||l.current.get(n)?.focus({preventScroll:!0})},[i,u,n]),(0,U.jsx)(`div`,{ref:c,className:`review-comment-markers`,role:`group`,"aria-label":o.heading,children:e.map(e=>{let{root:i}=e,c=t.get(i.id);if(!c||c.status!==`resolved`&&c.status!==`moved`)return null;let u=e.replies.length>0,d=(e.unread?u?o.unreadMarkerWithRepliesLabel:o.unreadMarkerLabel:u?o.markerWithRepliesLabel:o.markerLabel).replace(`%{author}`,`@${i.author.login}`).replace(`%{count}`,(e.replies.length+1).toString()),f=i.anchor.kind===`area`?ct(i.anchor,c.rect):null,p=e.participants.slice(3),m=p.length>1?p.map(({login:e})=>`@${e}`).join(`, `):d;return(0,U.jsxs)(V.Fragment,{children:[f&&(!a||n===i.id)?(0,U.jsx)(`svg`,{className:`review-comment-area`,"aria-hidden":`true`,width:`100%`,height:`100%`,children:(0,U.jsx)(`polyline`,{className:n===i.id?`review-comment-area__path review-comment-area__path--selected`:`review-comment-area__path`,points:f.path.map(e=>`${e.x},${e.y}`).join(` `),vectorEffect:`non-scaling-stroke`})}):null,(0,U.jsx)(H.Tooltip,{text:m,type:`description`,ref:e=>{e instanceof HTMLButtonElement?l.current.set(i.id,e):l.current.delete(i.id)},children:(0,U.jsx)(`button`,{type:`button`,"data-review-thread-id":i.id,className:`review-comment-marker${n===i.id?` review-comment-marker--selected`:``}${i.resolvedAt?` review-comment-marker--resolved`:``}${e.unread?` review-comment-marker--unread`:``}${r&&n!==i.id?` review-comment-marker--blocked`:``}`,style:{left:f?.point.x??c.point.x,top:f?.point.y??c.point.y},"aria-label":d,disabled:r&&n!==i.id,onClick:()=>s(e),children:(0,U.jsx)(st,{participants:e.participants,size:`small`})})})]},i.id)})})}function ut({checked:e,onChange:t,size:n=`medium`,className:r,...i}){let{value:a,...o}=i;return(0,U.jsxs)(`label`,{className:`hub-switch hub-switch--${n}${r?` ${r}`:``}`,"data-disabled":i.disabled||void 0,children:[(0,U.jsx)(`span`,{className:`hub-switch__native-control`,children:(0,U.jsx)(H.Checkbox,{...o,value:a===void 0?void 0:String(a),role:`switch`,checked:e,onChange:e=>{i.disabled||t(e.currentTarget.checked)}})}),(0,U.jsx)(`span`,{className:`hub-switch__track`,"data-checked":e,"aria-hidden":`true`,children:(0,U.jsx)(`span`,{className:`hub-switch__thumb`})})]})}function dt(e){(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.click())}function ft({compact:e=!1,filters:t,participants:r,showPins:i,copy:a,onFiltersChange:o,onShowPinsChange:s}){let[c,l]=(0,V.useState)(!1),u=t.currentBuildOnly||t.currentPageOnly||t.showResolved||!t.showRead||t.onlyMine||t.participant!==null||!i,d=r.find(e=>e.login===t.participant),f=t.participant===null?a.allParticipantsLabel:d?.name?`${d.name} (@${d.login})`:`@${t.participant}`;return(0,U.jsxs)(`div`,{className:`review-comment-filter-controls${e?` review-comment-filter-controls--compact`:``}`,children:[(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__search`,children:[(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__search-field`,children:[e?null:(0,U.jsx)(B,{className:`review-comment-filter-controls__search-icon`,size:16,"aria-hidden":`true`}),(0,U.jsx)(`input`,{type:`search`,className:`review-comment-filter-controls__input`,"aria-label":a.searchLabel,placeholder:a.searchPlaceholder,value:t.search,onChange:e=>o({...t,search:e.target.value})})]}),(0,U.jsx)(G,{icon:n,"aria-label":a.filterLabel,description:a.filterLabel,"aria-expanded":c,variant:e?`default`:`invisible`,className:`review-comment-filter-controls__button${c||u?` review-comment-filter-controls__button--active`:``}`,onClick:()=>l(e=>!e)})]}),c?(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__filters`,children:[(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__participant`,children:[(0,U.jsx)(`span`,{children:a.participantFilterLabel}),(0,U.jsxs)(H.ActionMenu,{size:`small`,selectionVariant:`single`,menuAlignment:`end`,onSelect:e=>o({...t,participant:e===``?null:e}),children:[(0,U.jsx)(H.ActionMenu.Button,{className:`review-comment-filter-controls__participant-trigger`,variant:`secondary`,size:`small`,"aria-label":`${a.participantFilterLabel}: ${f}`,children:(0,U.jsx)(`span`,{className:`review-comment-filter-controls__participant-name`,children:f})}),(0,U.jsxs)(H.ActionMenu.Overlay,{"aria-label":a.participantFilterLabel,children:[(0,U.jsx)(H.ActionMenu.Item,{value:``,selected:t.participant===null,role:`menuitemradio`,onKeyDownCapture:dt,children:a.allParticipantsLabel}),r.map(e=>(0,U.jsx)(H.ActionMenu.Item,{value:e.login,selected:t.participant===e.login,role:`menuitemradio`,onKeyDownCapture:dt,children:e.name?`${e.name} (@${e.login})`:`@${e.login}`},e.login))]})]})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-current-build`,children:a.currentBuildFilterLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-current-build`,checked:t.currentBuildOnly,size:`small`,onChange:e=>o({...t,currentBuildOnly:e})})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-current-page`,children:a.currentPageFilterLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-current-page`,checked:t.currentPageOnly,size:`small`,onChange:e=>o({...t,currentPageOnly:e})})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-show-resolved`,children:a.showResolvedLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-show-resolved`,checked:t.showResolved,size:`small`,onChange:e=>o({...t,showResolved:e})})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-unread-only`,children:a.unreadOnlyLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-unread-only`,checked:!t.showRead,size:`small`,onChange:e=>o({...t,showRead:!e})})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-only-mine`,children:a.onlyMineLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-only-mine`,checked:t.onlyMine,size:`small`,onChange:e=>o({...t,onlyMine:e})})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-show-pins`,children:a.showPinsLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-show-pins`,checked:i,size:`small`,onChange:s})]})]}):null]})}var pt=[[31536e3,`y`],[2592e3,`mo`],[604800,`w`],[86400,`d`],[3600,`h`],[60,`m`]];function mt(e){let t=window.setInterval(e,6e4);return()=>window.clearInterval(t)}function ht(){return Math.floor(Date.now()/6e4)*6e4}function gt(){return null}function _t({value:e,showTitle:t=!0}){let n=Date.parse(e),r=Number.isNaN(n)?e:new Date(n).toUTCString(),i=(0,V.useSyncExternalStore)(mt,ht,gt),a=r;if(i!==null&&!Number.isNaN(n)){let e=Math.round((i-n)/1e3),t=pt.find(([t])=>Math.abs(e)>=t);a=t?`${e<0?`in `:``}${Math.round(Math.abs(e)/t[0])}${t[1]}${e<0?``:` ago`}`:`just now`}return(0,U.jsx)(`time`,{dateTime:e,title:t?r:void 0,"aria-label":r,children:a})}function vt({thread:e,currentBuildNumber:t,resolution:n,anchorStatusLabel:r,selected:i,selectionBlocked:a,copy:o,onSelect:s,buildHref:c}){let l=(0,V.useId)(),{root:u}=e,d=u.author.name||`@${u.author.login}`,f=a&&!i,p=o.buildLabel.replace(`%{number}`,u.buildNumber?.toString()??``),m=u.buildNumber!==null&&u.buildPath!==null&&u.buildNumber!==t,h=e.replies.length===1?o.replyCountOneLabel:o.replyCountOtherLabel.replace(`%{count}`,e.replies.length.toString()),g=o.missingAnchorLabel;return u.resolvedAt?g=o.resolvedLabel:r===void 0?n?n.status===`resolved`?g=null:n.status===`moved`?g=o.movedAnchorLabel:n.status===`changed`?g=o.changedAnchorLabel:n.status===`route-mismatch`&&(g=o.routeMismatchLabel):g=null:g=r,(0,U.jsx)(`article`,{className:`review-comment-row${i?` review-comment-row--selected`:``}${e.unread?` review-comment-row--unread`:``}`,onClick:t=>{f||t.target instanceof Element&&t.target.closest(`a`)||s(e)},children:(0,U.jsx)(`div`,{className:`review-comment-row__layout`,children:(0,U.jsxs)(`div`,{className:`review-comment-row__content`,children:[(0,U.jsxs)(`div`,{className:`review-comment-row__copy`,children:[(0,U.jsxs)(`div`,{className:`review-comment-row__metadata`,children:[(0,U.jsxs)(`span`,{className:`review-comment-row__author-and-build`,children:[(0,U.jsx)(ot,{src:u.author.avatarUrl,size:20,className:`review-comment-row__avatar`}),(0,U.jsx)(`span`,{id:`${l}-author`,className:`review-comment-row__author`,children:d}),m?(0,U.jsxs)(`span`,{className:`review-comment-row__build`,children:[`(`,(0,U.jsx)(`a`,{href:c||u.buildPath||void 0,target:c?`_blank`:void 0,rel:c?`noopener noreferrer`:void 0,children:p}),`)`]}):null]}),(0,U.jsx)(_t,{value:e.lastActivityAt})]}),(0,U.jsx)(`button`,{type:`button`,className:`review-comment-row__button`,"aria-labelledby":`${l}-author ${l}-body${e.unread?` ${l}-unread`:``}`,"aria-pressed":i,disabled:f,title:f?o.selectionBlockedLabel:void 0,children:(0,U.jsxs)(`span`,{className:`review-comment-row__body-container`,children:[e.unread?(0,U.jsx)(`span`,{role:`img`,id:`${l}-unread`,"aria-label":o.unreadLabel,title:o.unreadLabel,className:`review-comment-row__unread`}):null,(0,U.jsx)(`span`,{id:`${l}-body`,className:`review-comment-row__body`,children:u.body??o.deletedCommentLabel})]})})]}),g||e.replies.length>0?(0,U.jsxs)(`div`,{className:`review-comment-row__context`,children:[e.replies.length>0?(0,U.jsx)(`span`,{className:`review-comment-row__replies`,children:h}):null,g?(0,U.jsx)(H.Label,{size:`small`,className:`review-comment-row__status`,children:g}):null]}):null]})})})}function yt({frame:e,threads:t,currentBuildNumber:n,buildLinkOrigin:r,totalCount:i,hasThreads:a,filters:o,participants:s,resolutions:c,selectedThreadId:l,selectionBlocked:u,closeBlocked:d,showPins:f,loading:p,loadFailed:m,notice:h,copy:g,onClose:_,onFiltersChange:v,onShowPinsChange:y,onRetry:b,onSelect:x}){let S=a?g.noMatchesLabel:g.emptyLabel,C=(0,U.jsxs)(U.Fragment,{children:[h,(0,U.jsx)(ft,{compact:!e,filters:o,participants:s,showPins:f,copy:g,onFiltersChange:v,onShowPinsChange:y}),(0,U.jsxs)(`div`,{className:`review-comments-sidebar__body`,"aria-live":`polite`,children:[m?(0,U.jsxs)(`div`,{className:`review-comments-sidebar__state`,role:`alert`,children:[(0,U.jsx)(`span`,{children:g.loadErrorLabel}),(0,U.jsx)(H.Button,{size:`small`,onClick:b,children:g.retryLabel})]}):t.length===0&&!p?(0,U.jsx)(`div`,{className:`review-comments-sidebar__state`,children:S}):(0,U.jsx)(`div`,{className:`review-comments-sidebar__threads`,children:t.map(e=>(0,U.jsx)(vt,{thread:e,currentBuildNumber:n,buildHref:r&&e.root.buildPath?new URL(e.root.buildPath,r).href:void 0,resolution:c.get(e.root.id),selected:l===e.root.id,selectionBlocked:u,copy:g,onSelect:x},e.root.id))}),p?(0,U.jsxs)(`div`,{className:`review-comments-sidebar__loading`,children:[(0,U.jsx)(le,{decorative:!0,size:`small`}),(0,U.jsx)(`span`,{children:g.loadingLabel})]}):null]})]});return e?(0,U.jsx)(at,{...e,title:g.heading,closeLabel:g.closeLabel,closeDisabled:d,closeShortcut:`Shift+C`,onClose:_,headerAccessory:(0,U.jsx)(nt,{children:i}),children:C}):(0,U.jsxs)(`aside`,{className:`review-comments-sidebar`,"aria-label":g.heading,children:[(0,U.jsxs)(`header`,{className:`review-comments-sidebar__header`,children:[(0,U.jsxs)(`span`,{className:`review-comments-sidebar__heading`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`6`,children:g.heading}),(0,U.jsx)(nt,{children:i})]}),(0,U.jsx)(G,{icon:z,"aria-label":g.closeLabel,"aria-keyshortcuts":`Shift+C`,description:g.closeLabel,size:`small`,variant:`invisible`,className:`review-comments-sidebar__close`,disabled:d,onClick:_})]}),C]})}function bt({bridgeReady:e,copy:t,selectionBlocked:n,selecting:r,onCancelSelection:i,onStartAreaSelection:a,onStartElementSelection:o}){let c=(0,V.useId)(),l=!e||n,u=e?n?t.selectionBlockedLabel:t.commentMenuLabel:t.bridgeUnavailableLabel;if(r)return(0,U.jsx)(G,{icon:z,"aria-label":t.cancelSelectionLabel,description:t.cancelSelectionLabel,"aria-pressed":!0,size:`small`,variant:`default`,className:`review-comment-control__trigger`,onClick:i});let d=(0,U.jsxs)(H.ActionMenu,{selectionVariant:`none`,size:`small`,menuAlignment:`start`,disabled:l,children:[(0,U.jsx)(H.ActionMenu.Button,{className:`review-comment-control__trigger`,variant:`secondary`,"aria-label":t.commentMenuLabel,"aria-describedby":c,leadingVisual:(0,U.jsx)(b,{size:16}),onClick:e=>{let t=e.currentTarget,n=t.closest(`.repository-workspace__content`)?.getBoundingClientRect(),r=Math.min(window.innerHeight,n?.bottom??window.innerHeight),i=Math.max(0,r-t.getBoundingClientRect().bottom-8);t.closest(`[data-testid="ActionMenu"]`)?.style.setProperty(`--review-comment-control-menu-height`,`${i}px`)},children:``}),(0,U.jsxs)(H.ActionMenu.Overlay,{"aria-label":t.commentMenuLabel,children:[(0,U.jsx)(H.ActionMenu.Item,{className:`review-comment-control__menu-item`,value:`element`,leadingVisual:(0,U.jsx)(s,{size:16}),"aria-keyshortcuts":`C`,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},children:t.commentOnElementLabel}),(0,U.jsx)(H.ActionMenu.Item,{className:`review-comment-control__menu-item`,value:`area`,leadingVisual:(0,U.jsx)(_,{size:16}),"aria-keyshortcuts":`H`,onClick:a,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a())},children:t.highlightRegionLabel})]})]});return l?(0,U.jsxs)(`div`,{title:u,children:[d,(0,U.jsx)(W,{id:c,children:u})]}):(0,U.jsx)(H.Tooltip,{id:c,text:u,type:`description`,children:(0,U.jsx)(`div`,{children:d})})}var xt={search:``,currentBuildOnly:!1,currentPageOnly:!1,showResolved:!1,showRead:!0,onlyMine:!1,participant:null},St={heading:`Comments`,closeLabel:`Close comments`,commentMenuLabel:`Add a comment`,commentOnElementLabel:`Comment on element`,highlightRegionLabel:`Highlight a region`,cancelSelectionLabel:`Cancel selection`,bridgeUnavailableLabel:`Adding comments needs the review bridge.`,selectionBlockedLabel:`Close or submit the open draft.`,selectionFailedLabel:`Hub could not anchor a comment to that element.`,areaTooSmallLabel:`Draw a larger region to add a comment.`,areaUnavailableLabel:`Hub could not save that region.`,searchLabel:`Search comments`,searchPlaceholder:`Search comments`,filterLabel:`Filters`,currentBuildFilterLabel:`Current build only`,currentPageFilterLabel:`Current page only`,participantFilterLabel:`Participant`,allParticipantsLabel:`All participants`,showResolvedLabel:`Show resolved`,unreadOnlyLabel:`Unread only`,onlyMineLabel:`Only your threads`,showPinsLabel:`Show pins`,sidebarShortcutLabel:`Shift+C`,loadingLabel:`Loading comments`,loadErrorLabel:`Comments could not be loaded.`,retryLabel:`Retry`,emptyLabel:`No comments have been added.`,noMatchesLabel:`No comments match these filters.`,buildLabel:`build %{number}`,movedAnchorLabel:`Moved`,changedAnchorLabel:`Context changed`,missingAnchorLabel:`Not found`,routeMismatchLabel:`Saved on another page`,resolvedLabel:`Resolved`,markerLabel:`Thread started by %{author}`,markerWithRepliesLabel:`Thread started by %{author}, %{count} comments`,unreadLabel:`Unread`,unreadMarkerLabel:`Unread thread started by %{author}`,unreadMarkerWithRepliesLabel:`Unread thread started by %{author}, %{count} comments`,replyCountOneLabel:`1 reply`,replyCountOtherLabel:`%{count} replies`,threadHeading:`Conversation`,backToCommentsLabel:`Back to comments`,resolvedByLabel:`Resolved by %{author}. Reopen this thread to reply.`,editedLabel:`Edited`,deletedCommentLabel:`Comment deleted`,addReactionLabel:`Add reaction`,reactionCountOneLabel:`%{reaction}, 1 reaction`,reactionCountOtherLabel:`%{reaction}, %{count} reactions`,reactionErrorLabel:`The reaction could not be changed.`,readErrorLabel:`Hub could not mark this conversation as read.`,markUnreadLabel:`Mark as unread`,markUnreadErrorLabel:`Hub could not mark this conversation as unread. Try again.`,reactionLabels:{"+1":`Thumbs up`,"-1":`Thumbs down`,laugh:`Laugh`,hooray:`Hooray`,confused:`Confused`,heart:`Heart`,rocket:`Rocket`,eyes:`Eyes`},commentActionsLabel:`Actions for comment by %{author}`,editLabel:`Edit`,deleteLabel:`Delete`,editCommentLabel:`Edit comment`,saveEditLabel:`Save`,savingEditLabel:`Saving comment`,cancelEditLabel:`Cancel`,editErrorLabel:`The comment could not be updated.`,deleteHeading:`Delete this comment?`,deletePromptLabel:`Deleted comment text cannot be recovered.`,confirmDeleteLabel:`Delete`,deletingLabel:`Deleting comment`,deleteErrorLabel:`The comment could not be deleted.`,replyLabel:`Reply`,replyPlaceholder:`Reply to this conversation`,replySubmitLabel:`Reply`,replySubmitTooltipMacLabel:`Reply (Cmd+Return)`,replySubmitTooltipOtherLabel:`Reply (Ctrl+Enter)`,replyingLabel:`Saving reply`,replyErrorLabel:`The reply could not be saved.`,resolveLabel:`Resolve`,resolvingLabel:`Resolving thread`,reopenLabel:`Reopen`,reopeningLabel:`Reopening thread`,resolutionErrorLabel:`The thread state could not be changed.`,resolvedReplyBlockedLabel:`Reopen this thread to reply.`,deletedReplyBlockedLabel:`Replies are closed.`,threadDiscardPromptLabel:`Your reply or edit has not been saved.`,composerHeading:`New comment`,composerLabel:`Comment`,composerPlaceholder:`Leave a review comment`,submitLabel:`Comment`,submitTooltipMacLabel:`Comment (Cmd+Return)`,submitTooltipOtherLabel:`Comment (Ctrl+Enter)`,submittingLabel:`Saving comment`,closeComposerLabel:`Cancel`,discardHeading:`Keep this draft?`,discardPromptLabel:`This comment has not been submitted.`,keepLabel:`Keep`,discardButtonLabel:`Discard`,bodyTooLongLabel:`Comments must be 10000 UTF-8 bytes or fewer.`,createErrorLabel:`The comment could not be saved.`};function Ct(e,t){let n=new Map;n.set(e.login.toLowerCase(),e);for(let e of t.toReversed()){let t=e.login.toLowerCase();n.has(t)||n.set(t,e)}return Array.from(n.values())}function wt(e){let t=new Map,n=new Map;for(let r of e){if(r.kind===`root`){t.set(r.id,r);continue}let e=n.get(r.rootId)??[];e.push(r),n.set(r.rootId,e)}return Array.from(t.values()).flatMap(e=>{let t=(n.get(e.id)??[]).filter(e=>e.deletedAt===null).sort((e,t)=>Date.parse(e.createdAt)-Date.parse(t.createdAt)||e.id-t.id);return e.deletedAt!==null&&t.length===0?[]:[{root:e,replies:t,participants:Ct(e.author,t.map(e=>e.author)),lastActivityAt:t.at(-1)?.createdAt??e.createdAt,unread:e.viewerLastSeenActivityVersion===null||e.viewerLastSeenActivityVersionDate.parse(t.lastActivityAt)-Date.parse(e.lastActivityAt)||t.root.id-e.root.id)}var Tt=new TextEncoder;function Et(e,{prefix:t,required:n=!1}={}){return P().refine(r=>(!n||r!==``)&&(!t||r===``||r.startsWith(t))&&Tt.encode(r).length<=e)}var Dt=16384,Q=2048,Ot=2048,kt=1024,At=4096,jt=1e3,Mt=2e3,Nt=1e6,Pt=1e5,Ft=new TextEncoder,It=R().min(0).max(Nt),Lt=R().min(-Nt).max(Nt),Rt=R().min(0).max(Nt),zt=E({x:R().min(0).max(1),y:R().min(0).max(1)}).strict(),Bt=E({pathname:Et(Q,{prefix:`/`,required:!0}),search:Et(Ot,{prefix:`?`}),hash:Et(kt,{prefix:`#`})}).strict(),Vt=E({x:It,y:It,width:Rt,height:Rt}).strict();E({x:Lt,y:Lt}).strict();var Ht=E({width:R().min(1).max(Pt),height:R().min(1).max(Pt),scrollX:It,scrollY:It}).strict(),Ut=E({schemaVersion:I(1),kind:I(`element`),route:Bt,selector:Et(At,{required:!0}),accessibleName:Et(jt),tagName:Et(64,{required:!0}).regex(/^[a-z][a-z0-9-]*$/),selectedText:Et(Mt),rect:Vt,viewport:Ht,elementOffset:zt}).strict().refine(e=>Ft.encode(JSON.stringify(e)).length<=Dt),Wt=E({selector:Et(At,{required:!0}),accessibleName:Et(jt),tagName:Et(64,{required:!0}).regex(/^[a-z][a-z0-9-]*$/),role:Et(64),textExcerpt:Et(500),rect:Vt}).strict(),Gt=E({schemaVersion:I(1),kind:I(`area`),route:Bt,path:ne(zt).min(2).max(160),rect:Vt,viewport:Ht,elements:ne(Wt).max(8)}).strict().refine(e=>Math.hypot(e.rect.width,e.rect.height)>=8).refine(e=>Ft.encode(JSON.stringify(e)).length<=Dt),Kt=T(`kind`,[Ut,Gt]),qt=T(`status`,[E({commentId:R().int().positive().max(2**53-1),status:re([`resolved`,`moved`]),rect:E({x:Lt,y:Lt,width:Rt,height:Rt}).strict(),point:E({x:Lt,y:Lt}).strict()}).strict(),E({commentId:R().int().positive().max(2**53-1),status:re([`changed`,`missing`,`route-mismatch`])}).strict()]),Jt=R().int().positive().max(2**53-1),Yt=P().refine(e=>!Number.isNaN(Date.parse(e))),Xt=Yt.nullable(),Zt=E({login:P().min(1),name:P().nullable(),avatarUrl:P().nullable()}),Qt=re([`+1`,`-1`,`laugh`,`hooray`,`confused`,`heart`,`rocket`,`eyes`]),$t=E({content:Qt,count:Jt,viewerHasReacted:j()}),en={id:Jt,body:P().nullable(),mentions:ne(E({login:P().min(1),githubId:Jt})).optional(),createdAt:Yt,updatedAt:Yt,editedAt:Xt,deletedAt:Xt,author:Zt,viewerCanEdit:j(),viewerCanDelete:j(),reactions:ne($t)},tn=E({...en,kind:I(`root`),buildNumber:Jt.nullable(),buildPath:P().startsWith(`/`).nullable(),draftRevisionId:Jt.nullable().optional(),anchor:Kt,resolvedAt:Xt,resolvedBy:Zt.nullable(),activityVersion:Jt,viewerLastSeenActivityVersion:Jt.nullable()}),nn=E({...en,kind:I(`reply`),rootId:Jt}),rn=T(`kind`,[tn,nn]),an=E({comments:ne(rn),nextCursor:ee(),hasMore:I(!1)}),on=E({comments:ne(rn).min(1).max(2)});function sn(e,t){let{root:n}=e,{filters:r}=t;if(!r.showResolved&&n.resolvedAt!==null||!r.showRead&&!e.unread||r.onlyMine&&![n,...e.replies].some(e=>e.author.login.toLowerCase()===t.viewerLogin.toLowerCase())||r.currentBuildOnly&&(t.selectedDraftRevisionId==null?n.buildNumber!==t.selectedBuildNumber:n.draftRevisionId!==t.selectedDraftRevisionId)||r.participant!==null&&!e.participants.some(e=>e.login.toLowerCase()===r.participant?.toLowerCase())||r.currentPageOnly&&t.route!==null&&(n.anchor.route.pathname!==t.route.pathname||n.anchor.route.search!==t.route.search||n.anchor.route.hash!==t.route.hash))return!1;let i=r.search.trim().toLowerCase();if(!i)return!0;let a=n.anchor.kind===`element`?[n.anchor.accessibleName,n.anchor.selectedText,n.anchor.tagName]:n.anchor.elements.flatMap(e=>[e.accessibleName,e.textExcerpt,e.tagName,e.role]);return[n.body??``,n.author.login,n.author.name??``,n.buildNumber?.toString()??``,...e.replies.flatMap(e=>[e.body??``,e.author.login,e.author.name??``]),...a].join(` -`).toLowerCase().includes(i)}var cn=E({candidates:ne(E({githubId:R().int().positive().max(2**53-1),login:P().min(1).max(39),avatarUrl:P().nullable()}))});async function $(e,t,n={}){let r=await fetch(e,{...n,headers:{"Content-Type":`application/json`,"X-Replica-Canvas-Token":t,...n.headers}}),i=await r.json().catch(()=>({error:K.invalidResponse}));if(!r.ok)throw Object.assign(Error(i.error||K.requestFailed),{code:i.code,statusCode:r.status,authorization:i.authorization});return i}function ln({error:e,busy:t,requested:n,onFix:r,onDismiss:i}){let a=(0,V.useId)();return(0,U.jsxs)(ue,{title:K.commentingUnavailable,descriptionId:a,closeLabel:K.closeCommentingDialog,onClose:i,children:[(0,U.jsx)(`p`,{id:a,children:K.commentingDescription}),e?(0,U.jsx)(`p`,{role:`alert`,children:e}):null,(0,U.jsxs)(`div`,{className:`canvas-commenting-recovery__actions`,children:[(0,U.jsx)(H.Button,{variant:`primary`,disabled:t||n,onClick:r,children:n?K.commentingFixRequested:K.commentingFix}),(0,U.jsx)(H.Button,{variant:`subtle`,onClick:i,children:K.commentingDismiss})]})]})}function un({identity:e,enabled:t,ready:n,bridgeProblem:r,token:i}){let[a,o]=(0,V.useState)(``),[s,c]=(0,V.useState)(!1),[l,u]=(0,V.useState)(!1),[d,f]=(0,V.useState)(!1),p=(0,V.useRef)(e);(0,V.useLayoutEffect)(()=>(p.current=e,()=>{p.current=``}),[e]),(0,V.useEffect)(()=>{let e=window.setTimeout(()=>{o(``),c(!1),u(!1),f(!1)},0);return()=>{window.clearTimeout(e)}},[e,t]);async function m(){let t=e;o(``),c(!0);try{await $(`/api/commenting/fix`,i,{method:`POST`}),p.current===t&&f(!0)}catch(e){p.current===t&&o(e instanceof Error?e.message:String(e))}finally{p.current===t&&c(!1)}}return{visible:t&&!n&&!l&&!!r,error:a,busy:s,requested:d,onFix:()=>void m(),onDismiss:()=>u(!0)}}function dn({cancelLabel:e,confirmLabel:t,description:n,errorLabel:r,heading:i,loading:a=!1,loadingAnnouncement:o,compact:s=!1,condensed:c=!1,onCancel:l,onConfirm:u}){let d=(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:c?`primary`:void 0,className:`review-confirmation-panel__cancel`,onClick:l,children:e}),f=(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:c?`secondary`:`primary`,className:c?void 0:`review-confirmation-panel__danger`,disabled:a,"aria-busy":a,onClick:u,children:t});return(0,U.jsxs)(`div`,{className:`review-confirmation-panel${s||c?` review-confirmation-panel--compact`:``}${c?` review-confirmation-panel--condensed`:``}`,role:`alert`,children:[(0,U.jsxs)(`div`,{className:`review-confirmation-panel__copy`,children:[(0,U.jsx)(`strong`,{children:i}),c?(0,U.jsx)(W,{children:n}):(0,U.jsx)(`span`,{children:n})]}),r?(0,U.jsx)(`span`,{className:`review-confirmation-panel__error`,children:r}):null,(0,U.jsxs)(`div`,{className:`review-confirmation-panel__actions`,children:[c?f:d,c?d:f,a&&o?(0,U.jsx)(W,{role:`status`,children:o}):null]})]})}function fn(){return(0,V.useContext)(rt)}function pn(e){let t=e.matchAll(/(?e[1]?[e[1].toLowerCase()]:[])))}function mn({value:e,onValueChange:t,onKeyDown:n,ref:r,...i}){let a=fn(),o=(0,V.useRef)(null),s=(0,V.useRef)(null),c=(0,V.useRef)(null),l=(0,V.useId)(),[u,d]=(0,V.useState)(e.length),[f,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(null),[g,_]=(0,V.useState)(!1),[v,y]=(0,V.useState)(0),[b,x]=(0,V.useState)(0),[S,C]=(0,V.useState)({left:0,top:0,width:0}),w=e.slice(0,u).match(/(?:^|[\s(])@([a-zA-Z0-9-]*)$/)?.[1]?.toLowerCase(),T=a!==null&&w!==void 0&&!f&&!i.disabled,E=pn(e).length>10,D=m?.source===a&&m?.failed,O=g||m?.source!==a,k=(m?.source===a?m.candidates:[]).filter(e=>e.login.toLowerCase().includes(w??``)).slice(0,8),A=Math.min(b,Math.max(0,k.length-1));(0,V.useEffect)(()=>{o.current?.setCustomValidity(E?a?.copy.limit??``:``)},[a?.copy.limit,E]),(0,V.useEffect)(()=>{if(!T||!a)return;let e=!0,t=window.setTimeout(()=>{_(!0),a.load().then(t=>{e&&h({source:a,candidates:t,failed:!1})},()=>{e&&h({source:a,candidates:[],failed:!0})}).finally(()=>{e&&_(!1)})},150);return()=>{e=!1,window.clearTimeout(t)}},[T,v,a]),(0,V.useLayoutEffect)(()=>{if(!T)return;function e(){let e=o.current?.getBoundingClientRect();e&&C({left:e.left,width:e.width,top:Math.max(4,window.innerHeight-e.bottom<224?e.top-224:e.bottom)})}return e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[T]);function j(n){if(w===void 0)return;let r=u-w.length-1,i=`@${n.login} `;t(e.slice(0,r)+i+e.slice(u)),p(!0);let a=r+i.length;window.requestAnimationFrame(()=>{o.current?.focus(),o.current?.setSelectionRange(a,a),d(a)})}function M(e,t){o.current=e,typeof t==`function`?t(e):t&&(t.current=e)}return(0,U.jsxs)(`div`,{className:`mention-input`,children:[(0,U.jsx)(`textarea`,{...i,ref:e=>M(e,r),value:e,"aria-autocomplete":a?`list`:void 0,"aria-controls":T?l:void 0,"aria-activedescendant":T&&k.length?`${l}-${A}`:void 0,onChange:e=>{d(e.currentTarget.selectionStart),p(!1),x(0),t(e.currentTarget.value)},onSelect:e=>d(e.currentTarget.selectionStart),onBlur:e=>{s.current?.contains(e.relatedTarget)||p(!0)},onKeyDown:e=>{if(T&&e.key===`Escape`)e.preventDefault(),e.stopPropagation(),p(!0);else if(T&&D&&!O&&e.key===`Tab`&&!e.shiftKey)e.preventDefault(),c.current?.focus();else{if(T&&!O&&!D&&k.length){if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),x((A+(e.key===`ArrowDown`?1:-1)+k.length)%k.length);return}if((e.key===`Enter`||e.key===`Tab`)&&!e.nativeEvent.isComposing&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey){e.preventDefault();let t=k[A];t&&j(t);return}}n?.(e)}}}),E&&a?.copy.limit?(0,U.jsx)(`span`,{role:`alert`,children:a.copy.limit}):null,T&&a?(0,tt.createPortal)((0,U.jsx)(`div`,{ref:s,id:l,className:`mention-input__suggestions`,style:S,onBlur:e=>{e.relatedTarget!==o.current&&!e.currentTarget.contains(e.relatedTarget)&&p(!0)},onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),p(!0),o.current?.focus()):e.key===`Tab`&&e.shiftKey&&(e.preventDefault(),o.current?.focus())},children:O?(0,U.jsx)(`span`,{role:`status`,children:a.copy.loading}):D?(0,U.jsxs)(`div`,{role:`alert`,children:[a.copy.error,` `,(0,U.jsx)(`button`,{ref:c,type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{y(v+1),o.current?.focus()},children:a.copy.retry})]}):(0,U.jsxs)(`ul`,{role:`listbox`,"aria-label":a.copy.suggestions,children:[k.map((e,t)=>(0,U.jsx)(`li`,{id:`${l}-${t}`,role:`option`,"aria-selected":t===A,children:(0,U.jsxs)(`button`,{type:`button`,tabIndex:-1,onMouseDown:e=>e.preventDefault(),onClick:()=>j(e),children:[`@`,e.login]})},e.githubId)),k.length?null:(0,U.jsx)(`li`,{role:`presentation`,children:a.copy.empty})]})}),document.body):null]})}function hn({anchorPoint:e,anchorRectangle:t,anchorSelector:n,layoutKey:r,preserveVerticalSide:i=!1}){let a=(0,V.useRef)(null),o=(0,V.useRef)(null),[s,c]=(0,V.useState)({left:e.x+12,top:e.y+12}),l=(0,V.useCallback)(()=>{let r=a.current,s=r?.parentElement;if(!r||!s)return;let l=r.offsetWidth,u=r.offsetHeight,d=s.clientWidth-l-8,f=s.clientHeight-u-8,p,m,h=(n?s.querySelector(n)??s.parentElement?.querySelector(n):null)?.getBoundingClientRect(),g=s.getBoundingClientRect(),_=h?{x:h.left-g.left,y:h.top-g.top,width:h.height,height:h.height}:t;if(_){let e=_.x+_.width+12,t=_.x-12-l,n=e+l<=s.clientWidth-8,r=t>=8,i=s.clientWidth-8-_.x-_.width,a=_.x-8;p=n?e:r?t:i>=a?e:t,m=_.y}else{let t=e.x+12,n=e.y+12;p=t+l<=s.clientWidth-8?t:e.x-12-l;let r=o.current,a=i&&r?.x===e.x&&r.y===e.y?r.side:n+u<=s.clientHeight-8?`below`:`above`;i&&(o.current={x:e.x,y:e.y,side:a}),m=a===`below`?n:e.y-12-u}let v={left:Math.max(8,Math.min(p,d)),top:Math.max(8,Math.min(m,f))};c(e=>e.left===v.left&&e.top===v.top?e:v)},[e,t,n,i]);return(0,V.useLayoutEffect)(()=>{l();let e=a.current,t=e?.parentElement;if(!e||!t||typeof ResizeObserver!=`function`)return;let r=new ResizeObserver(l);r.observe(e),r.observe(t);let i=n?t.querySelector(n)??t.parentElement?.querySelector(n):null;return i&&r.observe(i),window.addEventListener(`resize`,l),()=>{r.disconnect(),window.removeEventListener(`resize`,l)}},[n,r,l]),{cardRef:a,position:s}}function gn(){return typeof navigator<`u`&&/Mac/i.test(navigator.platform)}function _n(e,{allowPlainEnter:t=!1}={}){let n=e.isComposing||e.keyCode===229,r=gn()?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey,i=t&&!e.metaKey&&!e.ctrlKey;return e.key===`Enter`&&!e.shiftKey&&!e.altKey&&!n&&!e.repeat&&(r||i)}var vn=new TextEncoder;function yn({anchorPoint:e,bodyMaximumBytes:t,copy:n,creating:r,submitError:i,onSubmit:a,onDiscard:o}){let s=(0,V.useId)(),[c,l]=(0,V.useState)(``),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(!1),m=(0,V.useRef)(!1),{cardRef:h,position:g}=hn({anchorPoint:e,layoutKey:`${u}:${f}:${i??``}`,preserveVerticalSide:!0}),_=vn.encode(c).length>t,v=c.trim()!==``&&!_&&!r&&!u,y=gn()?n.submitTooltipMacLabel:n.submitTooltipOtherLabel;(0,V.useEffect)(()=>{u?h.current?.querySelector(`.review-confirmation-panel__cancel`)?.focus({preventScroll:!0}):m.current&&h.current?.querySelector(`textarea`)?.focus({preventScroll:!0}),m.current=u},[h,u]);function b(){r||(c.trim()===``?o():d(!0))}async function x(e){e.preventDefault(),v&&(await a(c)||p(!0))}return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-hidden":`true`,className:`review-comment-composer-backdrop`,onClick:b}),(0,U.jsx)(`section`,{ref:h,role:`dialog`,"aria-labelledby":s,className:`review-comment-composer`,style:{left:g.left,top:g.top},children:(0,U.jsxs)(`form`,{className:`review-comment-composer__form`,onSubmit:e=>{x(e)},onKeyDown:e=>{e.key!==`Escape`||e.defaultPrevented||(e.preventDefault(),u?d(!1):b())},children:[(0,U.jsxs)(`header`,{className:`review-comment-composer__header`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`6`,id:s,children:n.composerHeading}),(0,U.jsx)(G,{icon:z,"aria-label":n.closeComposerLabel,description:n.closeComposerLabel,variant:`invisible`,type:`button`,disabled:r,onClick:b})]}),(0,U.jsx)(mn,{autoFocus:!0,"aria-label":n.composerLabel,placeholder:n.composerPlaceholder,value:c,rows:4,onValueChange:e=>{l(e),d(!1),p(!1)},onKeyDown:e=>{v&&_n(e.nativeEvent)&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())}}),_?(0,U.jsx)(`span`,{role:`alert`,className:`review-comment-composer__error`,children:n.bodyTooLongLabel}):null,f?(0,U.jsx)(me,{variant:`critical`,title:n.createErrorLabel,description:i,className:`review-comment-composer__banner`}):null,u?(0,U.jsx)(dn,{heading:n.discardHeading,description:n.discardPromptLabel,cancelLabel:n.keepLabel,confirmLabel:n.discardButtonLabel,condensed:!0,onCancel:()=>d(!1),onConfirm:o}):(0,U.jsxs)(`footer`,{className:`review-comment-composer__actions`,children:[(0,U.jsx)(H.Button,{type:`button`,size:`small`,disabled:r,onClick:b,children:n.closeComposerLabel}),(0,U.jsx)(H.Tooltip,{text:y,type:`description`,children:(0,U.jsx)(H.Button,{type:`submit`,size:`small`,variant:`primary`,disabled:!v,"aria-busy":r,children:n.submitLabel})}),r?(0,U.jsx)(W,{role:`status`,children:n.submittingLabel}):null]})]})})]})}function bn({blockedLabel:e,confirmingDiscard:t,replyDraft:n,replyBodyTooLong:r,replyFailed:i,replyDisabled:a,replying:o,submitDisabled:s=!1,copy:c,onKeepDraft:u,onDiscardDraft:d,onSubmit:f,onDraftChange:p}){let m=(0,V.useRef)(null),h=n.trim()!==``&&!r&&!a&&!o&&!s&&!t&&!e,g=gn()?c.replySubmitTooltipMacLabel:c.replySubmitTooltipOtherLabel;return(0,V.useLayoutEffect)(()=>{m.current&&(m.current.style.height=`auto`,m.current.style.height=n?`${Math.min(m.current.scrollHeight,120)}px`:`2.5rem`)},[n]),t?(0,U.jsx)(dn,{heading:c.discardHeading,description:c.threadDiscardPromptLabel,cancelLabel:c.keepLabel,confirmLabel:c.discardButtonLabel,compact:!0,onCancel:u,onConfirm:d}):e?(0,U.jsx)(`span`,{className:`review-thread-reply-form__blocked`,children:e}):(0,U.jsxs)(`form`,{className:`review-thread-reply-form`,onSubmit:e=>{e.preventDefault(),h&&f()},children:[(0,U.jsxs)(`div`,{className:`review-thread-reply-form__composer`,children:[(0,U.jsx)(mn,{ref:m,"aria-label":c.replyLabel,placeholder:c.replyPlaceholder,value:n,rows:1,disabled:a,onValueChange:p,onKeyDown:e=>{h&&_n(e.nativeEvent,{allowPlainEnter:!0})&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())}}),(0,U.jsx)(H.Tooltip,{text:g,type:`description`,children:(0,U.jsx)(`button`,{type:`submit`,className:`review-thread-reply-form__submit`,disabled:!h,"aria-label":c.replySubmitLabel,"aria-busy":o,children:(0,U.jsx)(l,{size:16})})})]}),r?(0,U.jsx)(`span`,{role:`alert`,className:`review-thread-reply-form__error`,children:c.bodyTooLongLabel}):null,i?(0,U.jsx)(`span`,{role:`alert`,className:`review-thread-reply-form__error`,children:c.replyErrorLabel}):null,o?(0,U.jsx)(W,{role:`status`,children:c.replyingLabel}):null]})}function xn({comment:e}){let t=e.body??``,n=new Set(e.mentions?.map(e=>e.login.toLowerCase())??[]),r=t.matchAll(/(?({content:e,emoji:wn(e)}));function En(e,t=0,n=0){if(t!==0||n!==0)return{x:t,y:n};let r=e.getBoundingClientRect();return{x:r.left+r.width/2,y:r.top+r.height/2}}function Dn({comment:e,mutation:t,actionsDisabled:n,controlsHidden:r=!1,copy:i,onAdd:a,onRemove:o,onBurst:s}){let c=(0,V.useId)(),[l,u]=(0,V.useState)(!1),[d,f]=(0,V.useState)(!1),p=(0,V.useRef)(!1),[m,h]=(0,V.useState)(null),[g,_]=(0,V.useState)(`outside-bottom`),v=t!==null&&(t.kind===`add-reaction`||t.kind===`remove-reaction`)&&t.commentId===e.id,y=e.reactions.flatMap(e=>{if(!m||e.content!==m.content)return[e];let t=e.count+Number(m.viewerHasReacted)-Number(e.viewerHasReacted);return t>0?[{...e,count:t,viewerHasReacted:m.viewerHasReacted}]:[]});m?.viewerHasReacted&&!e.reactions.some(({content:e})=>e===m.content)&&y.push({content:m.content,count:1,viewerHasReacted:!0});async function b(r,i){if(n||t!==null||p.current)return;let c=e.reactions.find(e=>e.content===r)?.viewerHasReacted??!1;p.current=!0,u(!1),h({content:r,viewerHasReacted:!c});try{if(!c){let e=Tn.find(e=>e.content===r);e&&s(e.emoji,i.x,i.y)}let e=c?await o(r):await a(r);u(!e)}catch{u(!0)}finally{p.current=!1,h(null)}}function x(e,t){b(e,En(t.currentTarget,t.clientX,t.clientY))}let S=(0,U.jsxs)(H.ActionMenu,{selectionVariant:`none`,size:`small`,menuAlignment:`end`,menuSide:g,disabled:n,children:[(0,U.jsx)(H.ActionMenu.Button,{className:`review-comment-reactions__menu-trigger`,variant:`subtle`,"aria-label":i.addReactionLabel,"aria-describedby":c,"aria-busy":v||m!==null,leadingVisual:(0,U.jsx)(w,{size:16}),onClick:e=>{f(!0);let t=e.currentTarget.getBoundingClientRect(),n=e.currentTarget.closest(`.review-shell`)?.getBoundingClientRect(),r=Math.min(window.innerHeight,n?.bottom??1/0)-t.bottom,i=t.top-Math.max(0,n?.top??0),a=Tn.length*36+16;_(rr?`outside-top`:`outside-bottom`)},children:``}),(0,U.jsx)(H.ActionMenu.Overlay,{"aria-label":i.addReactionLabel,children:Tn.map(e=>(0,U.jsx)(H.ActionMenu.Item,{value:e.content,leadingVisual:(0,U.jsx)(`span`,{className:`review-comment-reactions__picker-emoji`,children:e.emoji}),onClick:t=>x(e.content,t),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),b(e.content,En(t.currentTarget)))},children:i.reactionLabels[e.content]},e.content))})]});return r&&!l?null:(0,U.jsxs)(`div`,{className:`review-comment-reactions__layout`,children:[r?null:(0,U.jsxs)(`div`,{className:`review-comment-reactions`,children:[y.map(e=>{let r=Tn.find(({content:t})=>t===e.content);if(!r)return null;let a=(e.count===1?i.reactionCountOneLabel:i.reactionCountOtherLabel).replace(`%{reaction}`,i.reactionLabels[e.content]).replace(`%{count}`,e.count.toString());return(0,U.jsxs)(H.Button,{size:`small`,"aria-label":a,title:a,"aria-pressed":e.viewerHasReacted,disabled:n,"aria-busy":m?.content===e.content||v&&`content`in t&&t.content===e.content,className:e.viewerHasReacted?`review-comment-reaction--selected`:void 0,onClick:t=>x(e.content,t),children:[(0,U.jsx)(`span`,{"aria-hidden":`true`,children:r.emoji}),(0,U.jsx)(nt,{"aria-hidden":`true`,children:e.count})]},e.content)}),n?(0,U.jsxs)(`div`,{title:i.addReactionLabel,children:[S,(0,U.jsx)(W,{id:c,children:i.addReactionLabel})]}):(0,U.jsx)(H.Tooltip,{id:c,text:i.addReactionLabel,type:`description`,className:`review-comment-reactions__tooltip${d?` review-comment-reactions__tooltip--suppressed`:``}`,children:(0,U.jsx)(`div`,{onMouseEnter:e=>{e.currentTarget.querySelector(`[aria-expanded="true"]`)||f(!1)},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||f(!1)},children:S})})]}),l?(0,U.jsx)(`span`,{role:`alert`,className:`review-comment-reactions__error`,children:i.reactionErrorLabel}):null]})}function On({comment:e,mutation:t,copy:n,editing:r,editDraft:i,editBodyTooLong:a,editFailed:s,confirmingEditDiscard:c,saving:l,confirmingDelete:u,deleting:d,deleteFailed:f,actionsDisabled:p,onStartEdit:m,onEditDraftChange:h,onSaveEdit:g,onCancelEdit:_,onKeepEdit:v,onDiscardEdit:y,onRequestDelete:b,onCancelDelete:x,onDelete:S,onAddReaction:C,onRemoveReaction:w,onBurstReaction:T,onMarkUnread:E,markUnreadDisabled:D=!1}){let k=(0,V.useId)(),A=(0,V.useRef)(null),j=(0,V.useRef)(!1),[N,P]=(0,V.useState)(`outside-bottom`),F=e.author.name||`@${e.author.login}`,ee=n.commentActionsLabel.replace(`%{author}`,`@${e.author.login}`),I=p&&(!E||D),L=!!(e.body&&e.viewerCanEdit),te=!!(e.body&&e.viewerCanDelete);return(0,V.useEffect)(()=>{c?A.current?.querySelector(`.review-confirmation-panel button`)?.focus({preventScroll:!0}):j.current&&A.current?.querySelector(`textarea`)?.focus({preventScroll:!0}),j.current=c},[c]),(0,U.jsxs)(`article`,{className:`review-thread-message`,"data-review-message-id":e.id,children:[(0,U.jsx)(Sn,{visual:(0,U.jsx)(ot,{src:e.author.avatarUrl,size:28}),author:F,metadata:(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(_t,{value:e.createdAt}),e.editedAt?(0,U.jsx)(`span`,{children:n.editedLabel}):null]}),children:E||L||te?I?(0,U.jsxs)(`div`,{title:ee,children:[(0,U.jsx)(H.ActionMenu,{selectionVariant:`none`,size:`small`,menuAlignment:`end`,disabled:!0,children:(0,U.jsx)(H.ActionMenu.Button,{className:`review-thread-message__menu-trigger`,variant:`subtle`,"aria-label":ee,"aria-describedby":k,leadingVisual:(0,U.jsx)(o,{size:16}),children:``})}),(0,U.jsx)(W,{id:k,children:ee})]}):(0,U.jsx)(H.Tooltip,{id:k,text:ee,type:`description`,children:(0,U.jsx)(`div`,{children:(0,U.jsxs)(H.ActionMenu,{selectionVariant:`none`,size:`small`,menuAlignment:`end`,menuSide:N,children:[(0,U.jsx)(H.ActionMenu.Button,{className:`review-thread-message__menu-trigger`,variant:`subtle`,"aria-label":ee,"aria-describedby":k,leadingVisual:(0,U.jsx)(o,{size:16}),onClick:e=>{let t=e.currentTarget.getBoundingClientRect(),n=e.currentTarget.closest(`.review-shell`)?.getBoundingClientRect(),r=Math.min(window.innerHeight,n?.bottom??1/0)-t.bottom,i=t.top-Math.max(0,n?.top??0);P(r<(E?128:88)&&i>r?`outside-top`:`outside-bottom`)},children:``}),(0,U.jsxs)(H.ActionMenu.Overlay,{"aria-label":ee,children:[E?(0,U.jsx)(H.ActionMenu.Item,{value:`mark-unread`,disabled:D,leadingVisual:(0,U.jsx)(M,{size:16}),onClick:()=>{D||E()},onKeyDown:e=>{!D&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),E())},children:n.markUnreadLabel}):null,L?(0,U.jsx)(H.ActionMenu.Item,{value:`edit`,disabled:p,leadingVisual:(0,U.jsx)(oe,{size:16}),onClick:m,onKeyDown:e=>{!p&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m())},children:n.editLabel}):null,te&&(E||L)?(0,U.jsx)(`li`,{role:`separator`,className:`review-thread-message__menu-divider`}):null,te?(0,U.jsx)(H.ActionMenu.Item,{value:`delete`,disabled:p||t!==null,className:`review-thread-message__delete-item`,leadingVisual:(0,U.jsx)(O,{size:16}),onClick:b,onKeyDown:e=>{!p&&t===null&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),b())},children:n.deleteLabel}):null]})]})})}):null}),r?(0,U.jsxs)(`form`,{ref:A,className:`review-thread-message__edit`,onSubmit:e=>{e.preventDefault(),c||g()},children:[(0,U.jsx)(mn,{autoFocus:!0,"aria-label":n.editCommentLabel,value:i,rows:3,onValueChange:h}),a?(0,U.jsx)(`span`,{role:`alert`,className:`review-thread-message__error`,children:n.bodyTooLongLabel}):null,s?(0,U.jsx)(`span`,{role:`alert`,className:`review-thread-message__error`,children:n.editErrorLabel}):null,c?(0,U.jsx)(dn,{heading:n.discardHeading,description:n.threadDiscardPromptLabel,cancelLabel:n.keepLabel,confirmLabel:n.discardButtonLabel,compact:!0,onCancel:v,onConfirm:y}):(0,U.jsxs)(`div`,{className:`review-thread-message__actions`,children:[(0,U.jsx)(H.Button,{type:`button`,size:`small`,disabled:l,onClick:_,children:n.cancelEditLabel}),(0,U.jsx)(H.Button,{type:`submit`,size:`small`,variant:`primary`,disabled:i.trim()===``||a||t!==null||l,"aria-busy":l,children:n.saveEditLabel}),l?(0,U.jsx)(W,{role:`status`,children:n.savingEditLabel}):null]})]}):u?(0,U.jsx)(dn,{heading:n.deleteHeading,description:n.deletePromptLabel,errorLabel:f?n.deleteErrorLabel:void 0,cancelLabel:n.cancelEditLabel,confirmLabel:n.confirmDeleteLabel,loading:d,loadingAnnouncement:n.deletingLabel,compact:!0,onCancel:x,onConfirm:S}):(0,U.jsx)(`p`,{className:e.body?`review-thread-message__body`:`review-thread-message__body review-thread-message__body--deleted`,children:e.body?(0,U.jsx)(xn,{comment:e}):n.deletedCommentLabel}),e.body&&(e.kind!==`root`||e.buildNumber!==null)?(0,U.jsx)(Dn,{comment:e,mutation:t,actionsDisabled:p,controlsHidden:r||u,copy:n,onAdd:C,onRemove:w,onBurst:T}):null]})}function kn({position:e,anchored:t,className:n,style:r,...i}){return(0,U.jsx)(`section`,{...i,role:`dialog`,className:`review-thread-conversation review-thread-conversation--${t?`anchored`:`docked`}${n?` ${n}`:``}`,style:{"--review-thread-left":`${e.left}px`,"--review-thread-top":`${e.top}px`,...r}})}function An(){let e=(0,V.useRef)(null),t=(0,V.useRef)([]),n=(0,V.useRef)(new Map),[r,i]=(0,V.useState)(!1),a=(0,V.useCallback)((e,n,r)=>{if(window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches)return;let a=4+Math.floor(Math.random()*5),o=performance.now();for(let i=0;i{if(!r)return;let a=e.current,o=a?.getContext(`2d`);if(!a||!o){console.error(`Emoji reaction burst could not create a canvas context.`),t.current=[];let e=requestAnimationFrame(()=>i(!1));return()=>cancelAnimationFrame(e)}let s=a,c=o,l;function u(){let e=window.devicePixelRatio||1;s.width=Math.round(window.innerWidth*e),s.height=Math.round(window.innerHeight*e),c.setTransform(e,0,0,e,0,0)}function d(e,t){let r=Math.round(t),i=`${e}_${r}`;if(n.current.has(i))return n.current.get(i)??null;let a=document.createElement(`canvas`);a.width=r*2,a.height=r*2;let o=a.getContext(`2d`);return o?(o.font=`${r}px serif`,o.textAlign=`center`,o.textBaseline=`middle`,o.fillText(e,r,r),n.current.set(i,a),a):(console.error(`Emoji reaction burst could not draw an emoji.`),n.current.set(i,null),null)}function f(e){c.clearRect(0,0,window.innerWidth,window.innerHeight);let n=[];for(let r of t.current){if(e10&&(r.opacity-=.04),r.opacity<=0)continue;let t=d(r.emoji,r.size);t&&(c.globalAlpha=r.opacity,c.drawImage(t,r.x-t.width/2,r.y-t.height/2)),n.push(r)}c.globalAlpha=1,t.current=n,n.length>0?l=requestAnimationFrame(f):i(!1)}return u(),window.addEventListener(`resize`,u),l=requestAnimationFrame(f),()=>{cancelAnimationFrame(l),window.removeEventListener(`resize`,u)}},[r]),{burst:a,canvas:r?(0,tt.createPortal)((0,U.jsx)(`canvas`,{ref:e,className:`review-emoji-burst`,"aria-hidden":`true`}),document.body):null}}var jn=new TextEncoder;function Mn({thread:e,bodyMaximumBytes:t,mutation:n,onClose:r,onDraftStateChange:i,onReply:a,onEdit:o,onDelete:s,onResolve:c,onReopen:l}){let[u,d]=(0,V.useState)(``),[f,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(null),[g,_]=(0,V.useState)(``),[v,y]=(0,V.useState)(``),[b,x]=(0,V.useState)(!1),[S,C]=(0,V.useState)(!1),[w,T]=(0,V.useState)(null),[E,D]=(0,V.useState)(!1),[O,k]=(0,V.useState)(!1),[A,j]=(0,V.useState)(!1),M=u.trim()!==``||m!==null,N=jn.encode(u).length>t,P=jn.encode(g).length>t,F=e.root.resolvedAt!==null,ee=e.root.deletedAt!==null||F;(0,V.useEffect)(()=>(i(M),()=>i(!1)),[M,i]);function I(){n||(u.trim()===``&&g===v?r():(C(!1),j(!0)))}function L(){d(``),h(null),_(``),y(``),C(!1),j(!1),i(!1),r()}async function te(){u.trim()===``||N||n||(await a(u)?(d(``),p(!1)):p(!0))}function ne(e){d(e),p(!1),j(!1)}function R(e){e.body&&(h(e.id),_(e.body),y(e.body),x(!1),T(null),D(!1))}function re(e){_(e),x(!1),C(!1),j(!1)}async function z(e){g.trim()===``||P||n||(await o(e,g)?(h(null),_(``),y(``),C(!1),x(!1)):x(!0))}function ie(){g===v?ae():C(!0)}function ae(){h(null),_(``),y(``),x(!1),C(!1),j(!1)}function oe(e){T(e),D(!1)}function B(){T(null),D(!1)}async function se(e){n||(await s(e)?B():D(!0))}async function ce(){if(n||M)return;let e=F?await l():await c();k(!e)}return{state:{replyDraft:u,replyFailed:f,editingCommentId:m,editDraft:g,editFailed:b,confirmingEditDiscard:S,confirmingDeleteId:w,deleteFailed:E,resolutionFailed:O,confirmingDiscard:A,draftActive:M,replyBodyTooLong:N,editBodyTooLong:P,resolved:F,replyBlocked:ee},actions:{requestDismissal:I,discardAndClose:L,keepDraft:()=>j(!1),submitReply:te,changeReplyDraft:ne,startEdit:R,changeEditDraft:re,saveEdit:z,cancelEdit:ie,keepEdit:()=>C(!1),discardEdit:ae,requestDelete:oe,cancelDelete:B,deleteComment:se,changeResolution:ce}}}function Nn(e){let t=e.closest(`[data-testid="ActionMenu"]`);if(!t)return;let n=e.getBoundingClientRect(),r=e.closest(`.review-shell`)?.getBoundingClientRect(),i=Math.max(0,r?.top??0),a=Math.min(window.innerHeight,r?.bottom??window.innerHeight);t.style.setProperty(`--review-thread-menu-room-top`,`${Math.max(0,n.top-i-8)}px`),t.style.setProperty(`--review-thread-menu-room-bottom`,`${Math.max(0,a-n.bottom-8)}px`)}function Pn({thread:e,anchorPoint:t,bodyMaximumBytes:n,mutation:r,copy:i,onClose:a,onDraftStateChange:o,onReply:s,onEdit:c,onDelete:l,onResolve:u,onReopen:d,onAddReaction:f,onRemoveReaction:p,onMarkRead:m,onMarkUnread:h}){let g=(0,V.useId)(),_=(0,V.useRef)(null),v=(0,V.useRef)(0),y=(0,V.useRef)(e.root.activityVersion),b=(0,V.useRef)(null),x=(0,V.useRef)(!1),S=(0,V.useRef)(!1),C=(0,V.useRef)(!1),[w,T]=(0,V.useState)(!1),[E,D]=(0,V.useState)(!1),[O,k]=(0,V.useState)(!1),[A,j]=(0,V.useState)(!1),{burst:M,canvas:N}=An(),{state:P,actions:F}=Mn({thread:e,bodyMaximumBytes:n,mutation:r,onClose:a,onDraftStateChange:o,onReply:s,onEdit:c,onDelete:l,onResolve:u,onReopen:d}),ee={x:12,y:12},I=[e.root,...e.replies],{cardRef:L,position:te}=hn({anchorPoint:t??ee,...t?{anchorSelector:`[data-review-thread-id="${e.root.id}"]`,anchorRectangle:{x:t.x-16,y:t.y-16,width:32,height:32}}:{},layoutKey:[P.confirmingDiscard,P.confirmingEditDiscard,P.replyFailed,P.editFailed,P.deleteFailed,P.resolutionFailed,P.editingCommentId,P.confirmingDeleteId,P.resolved,w,O,e.replies.length,e.participants.length,I.map(e=>e.reactions.length).join(`,`)].join(`:`)}),ne=P.replyBlocked?e.root.deletedAt?i.deletedReplyBlockedLabel:e.root.resolvedBy?i.resolvedByLabel.replace(`%{author}`,e.root.resolvedBy.name||`@${e.root.resolvedBy.login}`):i.resolvedReplyBlockedLabel:null,R=(0,V.useCallback)(()=>{L.current?.querySelector(`.review-thread-conversation__close`)?.focus({preventScroll:!0})},[L]);(0,V.useEffect)(()=>{if(P.confirmingDiscard)L.current?.querySelector(`.review-thread-conversation__footer button`)?.focus({preventScroll:!0});else if(C.current){let e=P.editingCommentId===null?`.review-thread-reply-form textarea`:`.review-thread-message__edit textarea`;L.current?.querySelector(e)?.focus({preventScroll:!0})}C.current=P.confirmingDiscard},[L,P.confirmingDiscard,P.editingCommentId]),(0,V.useEffect)(()=>{let e=document.activeElement;return _.current=e instanceof HTMLElement?e:null,R(),()=>{_.current?.isConnected&&_.current.focus()}},[R]),(0,V.useEffect)(()=>{let t=y.current;e.unread&&b.current!==t&&(b.current=t,x.current=!0,D(!0),m(t).then(e=>T(!e)).catch(()=>T(!0)).finally(()=>{x.current=!1,D(!1)}))},[m,e.unread]);async function re(){if(!(x.current||S.current||r!==null)){b.current=y.current,S.current=!0,j(!0),k(!1);try{let e=await h();k(!e),e&&T(!1)}catch{k(!0)}finally{S.current=!1,j(!1)}}}return(0,V.useEffect)(()=>{function e(){P.confirmingDiscard?F.keepDraft():P.confirmingEditDiscard?F.keepEdit():F.requestDismissal()}function t(t){t.key!==`Escape`||t.defaultPrevented||t.isComposing||L.current?.querySelector(`[role="menu"]`)||t.target instanceof Element&&t.target.closest(`[role="menu"], [role="dialog"], dialog`)||(t.preventDefault(),e())}function n(){let t=document.activeElement;L.current?.querySelector(`[role="menu"]`)||t instanceof Element&&(t.closest(`[role="menu"]`)||t.closest(`[role="dialog"], dialog`)&&!L.current?.contains(t))||e()}return document.addEventListener(`keydown`,t),window.addEventListener(`replica:review-dismiss`,n),()=>{document.removeEventListener(`keydown`,t),window.removeEventListener(`replica:review-dismiss`,n)}},[F,L,P.confirmingDiscard,P.confirmingEditDiscard]),(0,U.jsxs)(kn,{ref:L,"aria-labelledby":g,anchored:!!t,position:te,onKeyDown:e=>{e.key!==`Escape`||e.defaultPrevented||e.nativeEvent.isComposing||e.target instanceof Element&&e.target.closest(`[role="menu"]`)||(e.preventDefault(),P.confirmingDiscard?F.keepDraft():P.confirmingEditDiscard?F.keepEdit():F.requestDismissal())},children:[(0,U.jsxs)(`div`,{className:`review-thread-conversation__layout`,children:[(0,U.jsxs)(`header`,{className:`review-thread-conversation__header`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`6`,id:g,children:i.threadHeading}),e.root.buildNumber===null?null:(0,U.jsx)(H.Button,{size:`small`,disabled:P.draftActive||r!==null,"aria-busy":r!==null&&`commentId`in r&&r.commentId===e.root.id&&(r.kind===`resolve`||r.kind===`reopen`),onClick:()=>{F.changeResolution()},children:P.resolved?i.reopenLabel:i.resolveLabel}),r&&`commentId`in r&&r.commentId===e.root.id&&(r.kind===`resolve`||r.kind===`reopen`)?(0,U.jsx)(W,{role:`status`,children:P.resolved?i.reopeningLabel:i.resolvingLabel}):null,(0,U.jsx)(G,{icon:z,"aria-label":i.backToCommentsLabel,title:i.backToCommentsLabel,variant:`invisible`,className:`review-thread-conversation__close`,onClick:F.requestDismissal})]}),P.resolutionFailed?(0,U.jsx)(me,{variant:`critical`,title:i.resolutionErrorLabel,className:`review-thread-conversation__banner`}):null,w?(0,U.jsx)(me,{variant:`critical`,title:i.readErrorLabel,className:`review-thread-conversation__banner`}):null,O?(0,U.jsx)(me,{variant:`critical`,title:i.markUnreadErrorLabel,className:`review-thread-conversation__banner`}):null,(0,U.jsx)(`div`,{className:`review-thread-conversation__messages`,onClickCapture:e=>{if(!(e.target instanceof Element))return;let t=e.target.closest(`button[data-testid="ActionMenu-button"]`);t&&e.currentTarget.contains(t)&&(v.current=e.currentTarget.scrollTop,Nn(t))},onScroll:e=>{let t=e.currentTarget.scrollTop,n=t-v.current;if(v.current=t,n===0)return;let r=e.currentTarget.getBoundingClientRect();e.currentTarget.querySelectorAll(`[role="menu"]`).forEach(e=>{let t=e.closest(`[data-testid="ActionMenu"]`)?.querySelector(`button[data-testid="ActionMenu-button"]`);if(!t)return;let i=t.getBoundingClientRect();if(r.height>0&&(i.bottom<=r.top||i.top>=r.bottom)){let n=e.contains(document.activeElement);t.click(),n&&R();return}let a=Number.parseFloat(e.style.top);Number.isFinite(a)&&(e.style.top=`${a-n}px`),Nn(t)})},children:I.map(t=>(0,U.jsx)(On,{comment:t,mutation:r,copy:i,editing:P.editingCommentId===t.id,editDraft:P.editingCommentId===t.id?P.editDraft:``,editBodyTooLong:P.editingCommentId===t.id&&P.editBodyTooLong,editFailed:P.editingCommentId===t.id&&P.editFailed,confirmingEditDiscard:P.editingCommentId===t.id&&P.confirmingEditDiscard,saving:r?.kind===`edit`&&r.commentId===t.id,confirmingDelete:P.confirmingDeleteId===t.id,deleting:r?.kind===`delete`&&r.commentId===t.id,deleteFailed:P.confirmingDeleteId===t.id&&P.deleteFailed,actionsDisabled:r!==null&&r.kind!==`add-reaction`&&r.kind!==`remove-reaction`||P.confirmingDiscard||P.confirmingDeleteId!==null||P.replyDraft.trim()!==``||P.editingCommentId!==null&&P.editingCommentId!==t.id,onStartEdit:()=>F.startEdit(t),onEditDraftChange:F.changeEditDraft,onSaveEdit:()=>{F.saveEdit(t.id)},onCancelEdit:F.cancelEdit,onKeepEdit:F.keepEdit,onDiscardEdit:F.discardEdit,onRequestDelete:()=>F.requestDelete(t.id),onCancelDelete:F.cancelDelete,onDelete:()=>{F.deleteComment(t.id)},onAddReaction:e=>f(t.id,e),onRemoveReaction:e=>p(t.id,e),onBurstReaction:M,onMarkUnread:t.kind===`root`&&e.root.buildNumber!==null?()=>void re():void 0,markUnreadDisabled:E||A||r!==null},t.id))}),e.root.buildNumber!==null||P.confirmingDiscard?(0,U.jsx)(`div`,{className:`review-thread-conversation__footer${ne&&!P.confirmingDiscard?` review-thread-conversation__footer--blocked`:``}`,children:(0,U.jsx)(bn,{blockedLabel:ne,confirmingDiscard:P.confirmingDiscard,replyDraft:P.replyDraft,replyBodyTooLong:P.replyBodyTooLong,replyFailed:P.replyFailed,replyDisabled:r!==null||P.editingCommentId!==null,replying:r?.kind===`reply`&&r.commentId===e.root.id,copy:i,onKeepDraft:F.keepDraft,onDiscardDraft:F.discardAndClose,onSubmit:()=>{F.submitReply()},onDraftChange:F.changeReplyDraft})}):null]}),N]})}function Fn({selectionNotice:e,rateLimitNotice:t,composer:n,conversation:r}){return(0,U.jsxs)(U.Fragment,{children:[e||t?(0,U.jsxs)(`div`,{className:`canvas-selection-notice`,role:`alert`,children:[e?(0,U.jsx)(`div`,{children:e}):null,t?(0,U.jsx)(`div`,{children:t}):null]}):null,n?(0,U.jsx)(`div`,{className:`canvas-composer-shell`,children:(0,U.jsx)(yn,{...n})}):null,r?(0,U.jsx)(`div`,{className:`canvas-conversation-shell`,children:(0,U.jsx)(Pn,{...r},r.thread.root.id)}):null]})}function In({preference:e,disabled:t=!1}){let n=(0,V.useId)(),r=(0,V.useId)(),i=(0,V.useId)(),a=(0,V.useId)();return(0,U.jsxs)(`section`,{className:`canvas-hub-section`,"aria-labelledby":n,children:[(0,U.jsx)(H.Heading,{as:`h3`,size:`subhead-medium`,id:n,children:q.settings}),(0,U.jsxs)(`div`,{className:`canvas-publish-settings__option`,children:[(0,U.jsx)(`label`,{id:r,htmlFor:i,children:q.alwaysCommit}),(0,U.jsx)(ut,{className:`canvas-publish-settings__toggle`,id:i,"aria-labelledby":r,"aria-describedby":e.error?a:void 0,checked:e.remember===!0,disabled:e.loading||e.remember===null,"aria-disabled":e.saving||t||void 0,onChange:n=>{!e.saving&&!t&&e.save(n)},size:`small`})]}),e.error?(0,U.jsxs)(`div`,{id:a,className:`canvas-publish-settings__error`,children:[(0,U.jsx)(me,{title:e.error,variant:`critical`,layout:`compact`}),(0,U.jsx)(H.Button,{size:`small`,disabled:e.loading||e.saving,onClick:()=>void e.retry(),children:q.retrySettings})]}):null]})}function Ln(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Rn(e){return!Ln(e)||typeof e.pathname!=`string`||typeof e.search!=`string`||typeof e.hash!=`string`?null:{pathname:e.pathname,search:e.search,hash:e.hash}}function zn({config:e,frameRef:t,onRouteChange:n,status:r,onStatusChange:i,onSelectHub:a,onConnect:o,onDisconnected:s,connectionButtonRef:c,connecting:l=!1,publication:u,publicationBusy:d=!1,dirty:f=!1,onPublish:p,onRetryPublication:m,publishPreference:h,open:g,onClose:_}){let[v,y]=(0,V.useState)({identity:``,items:[]}),b=r?.prototype?.repositoryId,x=r?.prototype?.id,S=r?.state===`connected`,C=r?.hubOrigin,w=(0,V.useMemo)(()=>({load:async()=>{if(!S||!C)throw Error(K.mentionSuggestionsError);return cn.parse(await $(`/api/hub/mention-candidates?repositoryId=${b}&prototypeId=${x}`,e.token)).candidates},copy:{suggestions:K.mentionSuggestions,error:K.mentionSuggestionsError,loading:K.mentionSuggestionsLoading,empty:K.mentionSuggestionsEmpty,retry:St.retryLabel,limit:K.mentionLimit}}),[e.token,S,C,b,x]),[T,E]=(0,V.useState)(!1),[D,O]=(0,V.useState)(xt),[k,A]=(0,V.useState)(!0),[j,M]=(0,V.useState)(null),[P,F]=(0,V.useState)(null),[ee,I]=(0,V.useState)(``),[te,ne]=(0,V.useState)(``),[R,re]=(0,V.useState)(``),[z,ie]=(0,V.useState)(``),[ae,oe]=(0,V.useState)(!1),[B,se]=(0,V.useState)(!1),[ce,le]=(0,V.useState)(!1),[W,G]=(0,V.useState)(r?.discovery?.mismatch&&r.discovery.origin||r?.hubOrigin||``),[ue,de]=(0,V.useState)(!1),[fe,pe]=(0,V.useState)(!1),[q,he]=(0,V.useState)(``),[ge,_e]=(0,V.useState)(``),[ve,ye]=(0,V.useState)(``),[be,xe]=(0,V.useState)(!1),[J,Se]=(0,V.useState)(null),[Ce,we]=(0,V.useState)(!1),[Te,Ee]=(0,V.useState)(new Map),[De,Oe]=(0,V.useState)(!1),[ke,Y]=(0,V.useState)(``),[Ae,Me]=(0,V.useState)(null),[Ne,Pe]=(0,V.useState)(!1),[Z,Fe]=(0,V.useState)(null),[Ie,Le]=(0,V.useState)(null),[Re,ze]=(0,V.useState)(!1),[Be,Ve]=(0,V.useState)(null),He=(0,V.useRef)(!1),Ue=(0,V.useRef)(0),We=(0,V.useRef)(!1),Ge=(0,V.useRef)(0),Ke=(0,V.useRef)(``),qe=(0,V.useRef)(``),Je=(0,V.useRef)(void 0),Ye=(0,V.useRef)(0),Xe=(0,V.useRef)(null),Ze=(0,V.useRef)(null),Qe=(0,V.useRef)(!1),$e=(0,V.useRef)(``),et=(0,V.useRef)(g),rt=(0,V.useRef)(void 0),ot=`${r?.hubOrigin??``}/${r?.repository??``}/${r?.branch??``}/${r?.state===`connected`?r.prototype?.id??``:``}`,st=r?.reviewRevision,ut=st?.id,dt=`${ot}/revision/${ut??``}`,ft=r?r.discovery?.mismatch&&r.discovery.origin||r.hubOrigin||``:null,pt=(0,V.useRef)(ft),mt=r?.state,ht=mt===`unavailable`||mt===`denied`,gt=(0,V.useRef)(mt);(0,V.useEffect)(()=>{if(ft===null||pt.current===ft)return;let e=window.setTimeout(()=>{G(ft),pt.current=ft},0);return()=>window.clearTimeout(e)},[ft]),(0,V.useEffect)(()=>{if(!mt||gt.current===mt)return;if(mt!==`connected`&&mt!==`undiscovered`){gt.current=mt;return}let e=window.setTimeout(()=>{le(!1),gt.current=mt},0);return()=>window.clearTimeout(e)},[mt]);let _t=un({identity:ot,enabled:r?.repositoryAuthorized===!0,ready:De,bridgeProblem:ke,token:e.token}),vt=(0,V.useMemo)(()=>v.identity===dt?v.items:[],[v,dt]),Ct=(0,V.useMemo)(()=>wt(vt),[vt]),Tt=(0,V.useMemo)(()=>{let e=new Map(Ct.flatMap(e=>e.participants.map(e=>[e.login.toLowerCase(),e])));return Array.from(e.values()).sort((e,t)=>(e.name||e.login).localeCompare(t.name||t.login))},[Ct]),Et=(0,V.useMemo)(()=>{let e=new Map;for(let t of Ct){let n=t.root.id,r=Te.get(n);if(r)e.set(n,{commentId:n,status:`resolved`,point:r,rect:r.rect});else if(De){let r=t.root.anchor.route;e.set(n,{commentId:n,status:j&&(r.pathname!==j.pathname||r.search!==j.search||r.hash!==j.hash)?`route-mismatch`:`missing`})}}return e},[De,Te,j,Ct]),Dt=Ct.find(e=>e.root.id===P),Q=r?.state===`connected`?r.prototype:null,Ot=r?.state===`disconnected`||r?.state===`pairing`||r?.state===`unconfigured`,kt=Q?.build?.author.login,At=kt&&/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}(?:\[bot\])?$/i.test(kt)?`https://github.com/${encodeURIComponent(kt)}`:null,jt=Q?.build?.author.name?.trim()||(At?kt:null)||K.unknownCommitAuthor,Mt=Q?.canEdit&&Q.registered,Nt=Q?.id,Pt=Q?.build??null,Ft=Q?.viewerLogin||r?.viewerLogin,It=(0,V.useMemo)(()=>Ft?Ct.filter(e=>sn(e,{filters:D,viewerLogin:Ft,selectedBuildNumber:ut?null:Pt?.number,selectedDraftRevisionId:ut,route:j})):Ct,[Pt?.number,ut,D,j,Ft,Ct]),Lt=It.length,Rt=It.some(e=>e.unread),zt=!(!st||r?.reviewError),Bt=!!(r?.repositoryAuthorized&&r.branch&&r.viewerLogin)||!!Q,Vt=Z!==null||Ce||Be!==null||Ne,Ht=g&&!T,Ut=typeof document>`u`?null:document.getElementById(`canvas-review-controls`),Wt=Z?Z.kind===`element`?{x:Z.rect.x-Z.viewport.scrollX+Z.rect.width*Z.elementOffset.x,y:Z.rect.y-Z.viewport.scrollY+Z.rect.height*Z.elementOffset.y}:ct(Z,{x:Z.rect.x-Z.viewport.scrollX,y:Z.rect.y-Z.viewport.scrollY,width:Z.rect.width,height:Z.rect.height}).point:null;(0,V.useLayoutEffect)(()=>($e.current=ot,Ye.current+=1,Qe.current=!1,()=>window.clearTimeout(rt.current)),[ot]),(0,V.useLayoutEffect)(()=>{Ke.current=dt,Ge.current+=1},[dt]),(0,V.useLayoutEffect)(()=>{g&&Xe.current?.focus({preventScroll:!0})},[g]),(0,V.useLayoutEffect)(()=>{!Z&&!Be&&!Ce&&Qe.current&&(Qe.current=!1,Ze.current?.focus({preventScroll:!0}))},[Z,Be,Ce]),(0,V.useEffect)(()=>{let e=et.current;if(et.current=g,!g||e||!T)return;if(Ce){_();return}let t=window.setTimeout(()=>{E(!1),F(null)},0);return()=>window.clearTimeout(t)},[T,Ce,_,g]),(0,V.useEffect)(()=>{if(!g)return;function e(e){e.key!==`Escape`||e.defaultPrevented||e.target instanceof Element&&e.target.closest(`[role="dialog"], dialog, [role="menu"]`)||(e.preventDefault(),_())}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[g,_]);let Gt=be&&J===ot,qt=JSON.stringify(e.pickAndPolish?[]:Ct.map(({root:e})=>({id:e.id,anchor:e.anchor}))),Jt=(0,V.useCallback)(async()=>{if(!Bt||We.current||Ke.current!==dt)return;let t=dt,n=++Ge.current,r=Ue.current;oe(!0),se(!1);try{let i=an.parse(await $(`/api/hub/comments${ut?`?${new URLSearchParams({local_revision_id:String(ut)})}`:``}`,e.token));if(Ke.current!==t||Ge.current!==n||Ue.current!==r)return;y({identity:t,items:i.comments}),se(!1),I(``)}catch(e){Ke.current===t&&Ge.current===n&&Ue.current===r&&(se(!0),I(e instanceof Error?e.message:String(e)))}finally{Ke.current===t&&Ge.current===n&&Ue.current===r&&oe(!1)}},[e.token,ut,Bt,dt]),Yt=(0,V.useRef)(Jt);(0,V.useLayoutEffect)(()=>{Yt.current=Jt},[Jt]),(0,V.useEffect)(()=>{let e=window.setTimeout(()=>{y({identity:Ke.current,items:[]}),E(!1),O(xt),A(!0),M(null),F(null),we(!1),xe(!1),Se(null),he(``),_e(``),Ve(null),He.current=!1,We.current=!1,Ue.current+=1,Ee(new Map),Oe(!1),Me(null),Pe(!1),Fe(null),Le(null),ne(``),re(``),se(!1)},0);return()=>window.clearTimeout(e)},[ot]),(0,V.useEffect)(()=>{if(!Bt)return;let e=window.setTimeout(()=>void Jt(),0);return()=>window.clearTimeout(e)},[Bt,Jt]),(0,V.useEffect)(()=>{if(!Bt)return;let e=window.setInterval(()=>void Jt(),3e4);return()=>window.clearInterval(e)},[Bt,Jt]),(0,V.useEffect)(()=>{if(!Nt)return;let t=new AbortController,n,r=5e3;async function i(){let a=Date.now();try{let n=await fetch(`/api/hub/events`,{headers:{"X-Replica-Canvas-Token":e.token},signal:t.signal});if(!n.ok||!n.body)throw Error(`Live review connection unavailable.`);ze(!1);let r=n.body.getReader(),i=new TextDecoder,a=``;for(;!t.signal.aborted;){let{value:e,done:t}=await r.read();if(t)throw Error(`Live review connection closed.`);a+=i.decode(e,{stream:!0});let n=a.split(` +import{r as e,t}from"./renderer-rolldown-runtime.js";import{A as n,B as r,C as i,D as a,E as o,F as s,G as c,H as l,I as u,J as d,K as f,L as p,N as m,O as h,R as g,S as _,T as v,U as y,V as b,W as x,X as S,Y as C,_ as w,a as T,c as E,d as D,f as O,g as k,h as A,i as j,j as M,k as N,l as P,m as F,n as I,o as L,p as R,q as z,r as ee,s as B,t as te,u as ne,v as re,w as ie,x as ae,y as oe,z as se}from"./renderer-vendor.js";var V=e(S(),1),ce=d(),H=f(),U=z();function le({size:e=`medium`,className:t,label:n}){return(0,U.jsx)(`span`,{role:n?`status`:void 0,"aria-label":n,"aria-hidden":!n||void 0,className:`hub-spinner hub-spinner--${e}${t?` ${t}`:``}`})}function ue({className:e,...t}){return(0,U.jsx)(`span`,{...t,className:`hub-visually-hidden${e?` ${e}`:``}`})}function W(e){let t=(0,V.useId)(),{as:n,href:r,ref:i,icon:a,description:o,loading:s=!1,size:c=`medium`,variant:l=`default`,className:u,...d}=e,f=`hub-icon-button${c===`small`?` hub-icon-button--small`:``}${l===`invisible`?` hub-icon-button--invisible`:``}${l===`danger`?` hub-icon-button--danger`:``}${u?` ${u}`:``}`,p=l===`invisible`?`subtle`:`secondary`,m=!(!o||d.title||d[`aria-describedby`]||`disabled`in d&&d.disabled),h=[d[`aria-describedby`],o&&!m?t:void 0].filter(Boolean).join(` `)||void 0,g=d.title??(m?void 0:o??d[`aria-label`]),_=o&&!m?(0,U.jsx)(ue,{id:t,children:o}):null,v=s?(0,U.jsx)(le,{decorative:!0,size:`small`}):(0,U.jsx)(a,{size:16}),y=s?!0:d[`aria-busy`];if(n===`a`){let e=i,t=(0,U.jsx)(H.Button,{...d,ref:e,as:`a`,href:r,leadingVisual:v,variant:p,size:c,className:f,"aria-busy":y,"aria-describedby":h,title:g,children:_});return m&&o?(0,U.jsx)(H.Tooltip,{ref:i,text:o,type:`description`,children:t}):t}let b=(0,U.jsx)(H.Button,{...d,ref:i,type:d.type??`button`,leadingVisual:v,variant:p,size:c,className:f,"aria-busy":y,"aria-describedby":h,title:g,children:_});return m&&o?(0,U.jsx)(H.Tooltip,{ref:i,text:o,type:`description`,children:b}):b}function G({title:e,closeLabel:t,onClose:n,returnFocusRef:r,descriptionId:i,className:a,children:o}){let s=(0,V.useRef)(null),c=(0,V.useId)();return(0,V.useLayoutEffect)(()=>{let e=s.current,t=r?.current??(document.activeElement instanceof HTMLElement?document.activeElement:null);return e?.showModal(),()=>{e?.close(),(r?.current??t)?.focus()}},[r]),(0,U.jsxs)(`dialog`,{ref:s,"aria-labelledby":c,"aria-describedby":i,className:a?`canvas-dialog ${a}`:`canvas-dialog`,onCancel:e=>{e.preventDefault(),n()},onClick:e=>{if(e.target!==e.currentTarget)return;let{left:t,right:r,top:i,bottom:a}=e.currentTarget.getBoundingClientRect();(e.clientXr||e.clientYa)&&n()},children:[(0,U.jsxs)(`header`,{className:`canvas-dialog-header`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`5`,id:c,children:e}),(0,U.jsx)(W,{variant:`default`,size:`small`,icon:ne,"aria-label":t,onClick:n})]}),o]})}var K={improvementNotesLoading:`Loading improvement notes...`,localCommentsSaved:`Comments stay on this device until a Build with matching content is published and the canvas syncs them to Hub.`,commentPreparationFailed:`Hub could not prepare this comment.`,commentRefreshFailed:e=>`The comment was saved, but Hub could not be refreshed: ${e}`,commentLiveUpdatesPaused:`Live updates paused; checking every 30 seconds.`,mentionSuggestions:`Mention suggestions`,mentionSuggestionsError:`Mention suggestions are unavailable. Try again.`,mentionSuggestionsLoading:`Loading people...`,mentionSuggestionsEmpty:`No matching people. You can type a GitHub login to check it when sending.`,mentionLimit:`Each message can mention at most 10 distinct people.`,controls:`Controls`,controlsMove:`Move controls`,controlsMoveHint:`Drag to move. Use arrow keys, or Shift and arrow keys for smaller steps.`,controlsCollapse:`Collapse controls`,controlsExpand:`Expand controls`,controlsCollapseGroup:e=>`Collapse ${e}`,controlsExpandGroup:e=>`Expand ${e}`,controlsDescription:`Settings stay in this prototype's URL. The app may paint before Controls apply declared defaults.`,controlsConnecting:`Connecting controls...`,controlsEmpty:`No active controls. This prototype may have no declaration or this route may not mount controls.`,controlsLearnMore:`Learn more`,controlsMissingRuntime:`No supported controls runtime found.`,controlsLocalMissingRuntime:`Local controls couldn't connect.`,controlsLocalConnectionFailed:`The preview has not responded to controls. Retry the connection or ask Copilot to diagnose the cause.`,controlsLocalStorageFailed:`Controls could not be saved in the prototype URL. Changes remain in memory.`,controlsDiagnose:`Diagnose with Copilot`,controlsFix:`Fix with Copilot`,controlsDiagnostics:`Technical details`,controlsUnavailable:e=>`${e} is unavailable`,controlsNotApplied:e=>`${e} could not be applied`,controlsDiagnosisRequested:`Requested in chat`,controlsDiagnosisFailed:`Could not request a diagnosis. Try again.`,controlsUnsupportedRuntime:`This controls runtime version is unsupported. Upgrade only after an approved release.`,controlsInvalid:`The Controls definitions are invalid. Fix controls.replica.json and reload.`,controlsScopeError:(e,t)=>`Controls scope "${e}" did not connect. ${t}`,controlsRetry:`Retry connection`,controlsRetryStorage:`Retry saving`,controlsResetAll:`Reset all controls`,controlsRegion:`Prototype controls`,controlsActionBusy:` - Working...`,controlsActionUnavailable:`No mounted action handler.`,controlsValueNotApplied:`This value was not applied.`,browserNavigation:`Prototype navigation`,browserBack:`Back`,browserForward:`Forward`,browserReload:`Reload preview`,browserAddress:`Prototype address`,browserAddressInvalid:`Enter a valid URL or route.`,browserAddressOrigin:`The address must stay on this prototype's origin.`,browserOpenTab:`Open preview in browser`,browserAppearance:`Preview appearance`,browserLight:`Light appearance`,browserDark:`Dark appearance`,commentingUnavailable:`Commenting needs attention`,commentingDescription:`The canvas could not connect to the preview's commenting bridge.`,closeCommentingDialog:`Close commenting dialog`,commentingFix:`Fix with Copilot`,commentingFixRequested:`Requested in chat`,commentingDismiss:`Dismiss`,commentingMissing:`The preview has not responded through its local proxy. Check that the selected server is running, then reopen the canvas. Script or framing policies, certificate errors, and origin-dependent apps can prevent connection. A Vite plugin or server restart is not required to connect.`,commentingIncompatible:`The preview responded with an incompatible commenting protocol. Update the installed Replica extension and reopen the canvas, or use Fix with Copilot to check the preview connection.`,connectToHub:`Connect to the Hub`,closeConnectionDialog:`Close connection dialog`,connectionDescription:`Connecting to the hub lets you share the prototype with others and enables commenting.`,connectionBeforePublishing:`Connect to the hub before publishing this prototype.`,connectionRepositoryRequired:`Open a repository with a GitHub origin before connecting.`,connectionHubRequired:`Enter and save a Hub URL before connecting.`,connectionOpeningBrowser:`Opening browser...`,connectionApproval:`Browser approval`,connectionWaiting:`Make sure your browser shows the same code`,connectionApprovalExpired:`The approval expired or was declined. Connect again to retry.`,connectionBrowserFailed:e=>`Could not open your browser. Open or copy the approval link below. ${e}`,hubUrl:`Hub URL`,editHubUrl:`Edit Hub URL`,saveHub:`Save Hub`,disconnectFailed:(e,t)=>`Could not disconnect from ${e}: ${t} The previous connection may still be active. Save another Hub URL to switch this canvas locally, or retry Disconnect Hub.`,resetHubUrl:`Reset to repository Hub URL`,resetHubUnavailable:`No repository Hub URL is available. Enter a URL manually or retry reset.`,hubHttpsHint:`Remote Hubs require HTTPS`,copyApprovalLink:`Copy Hub approval link`,approvalLinkCopied:`Approval link copied`,approvalCopyFailed:`Could not copy the link. Copy the Connect to the hub link manually.`,invalidResponse:`The extension returned an invalid response.`,startPage:`Start page`,prototypeFrameTitle:e=>`${e} prototype`,startPageOrigin:`Hub returned a start page outside the prototype.`,hubStatusUnavailable:e=>`Hub status unavailable: ${e}`,hubBuildImported:`Hub imported this Build.`,hubBuildMissing:`Hub has not imported a successful registered Build.`,hubPublicationUnavailable:`Connect to Hub to verify publication.`,editDetails:`Edit details`,improveContext:`Improve context`,improveContextDescription:`Run a skill to improve repository context from user feedback.`,feedbackReviewFailed:e=>`Could not request a feedback review: ${e}`,moreActions:`More actions`,startPageHint:`Paste a prototype URL or route. Leave blank to start at /.`,requestFailed:`The request failed.`,statusUnavailable:`Publish status unavailable.`,publishRequestPending:`Waiting for the current commit to run through the publish workflow.`,waitingForHubImport:`The workflow completed. Waiting for Hub to import this Build.`,workingTreeChanged:`Uncommitted changes`,workingTreeClean:`Working tree clean`,buildDetails:`Build details`,latestBuild:`Latest Build`,buildTitle:e=>`Build #${e}`,buildCommit:`Commit`,unknownCommitAuthor:`Unknown`,showBuildHistory:`Show build history`,closeBuildDetails:`Close build details`,branch:`Branch`,sessionId:`Session ID`,comparison:`Branch comparison`,comparisonNeedsRefresh:`Branch comparison unavailable until Git stats refresh.`,upToDate:`Up to date`,commitsBehind:e=>`${e} ${e===1?`commit`:`commits`} behind`,copyBranch:`Copy branch`,copySessionId:`Copy session ID`,branchCopied:`Branch copied`,sessionIdCopied:`Session ID copied`,buildDetailsCopyFailed:e=>`${e} could not be copied. Select it and copy it manually.`,unavailable:`Unavailable`,publishLabels:{succeeded:`Awaiting Hub`,failed:`Retry`,in_progress:`Publishing`,not_published:`Publish`,published:`Published`,requested:`Requested`,unavailable:`Publish`}};function de({onClose:e,state:t,titleButtonRef:n}){let[i,a]=(0,V.useState)(null),[o,s]=(0,V.useState)(null),c=t.stats.branchError?void 0:t.stats.branch,l=t.sessionId,u=t.stats.comparison;async function d(e,t){try{await navigator.clipboard.writeText(e),a(t),s(null)}catch{a(null),s(t===`branch`?K.branch:K.sessionId)}}function f(e,t){if(!e)return null;let n=t===`branch`?K.copyBranch:K.copySessionId,a=t===`branch`?K.branchCopied:K.sessionIdCopied;return(0,U.jsx)(H.Button,{type:`button`,className:`canvas-icon-button`,variant:`subtle`,size:`small`,leadingVisual:i===t?(0,U.jsx)(r,{size:16}):(0,U.jsx)(m,{size:16}),"aria-label":i===t?a:n,title:i===t?a:n,onClick:()=>void d(e,t),children:(0,U.jsx)(`span`,{className:`visually-hidden`,children:n})})}return(0,U.jsxs)(G,{title:K.buildDetails,closeLabel:K.closeBuildDetails,className:`build-details-dialog`,returnFocusRef:n,onClose:e,children:[(0,U.jsxs)(`dl`,{className:`build-details-list`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`dt`,{children:K.branch}),(0,U.jsxs)(`dd`,{children:[(0,U.jsx)(N,{size:16,"aria-hidden":`true`}),(0,U.jsx)(`code`,{children:c||t.stats.branchError||K.unavailable}),f(c,`branch`)]})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`dt`,{children:K.sessionId}),(0,U.jsxs)(`dd`,{children:[(0,U.jsx)(`code`,{children:l||K.unavailable}),f(l,`sessionId`)]})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`dt`,{children:u?.branch?`Behind ${u.branch}${u.source===`local`?` (local)`:``}`:K.comparison}),(0,U.jsx)(`dd`,{children:u?.error||(u?.behind===0?K.upToDate:u?.behind==null?K.unavailable:K.commitsBehind(u.behind))})]})]}),(0,U.jsx)(`span`,{role:`status`,"aria-live":`polite`,className:`visually-hidden`,children:i===`branch`?`${K.branchCopied}.`:i===`sessionId`?`${K.sessionIdCopied}.`:``}),o?(0,U.jsx)(`span`,{role:`alert`,className:`build-details-copy-error`,children:K.buildDetailsCopyFailed(o)}):null]})}function fe({pairing:e}){let[t,n]=(0,V.useState)(`idle`),i=(0,V.useRef)(null);(0,V.useEffect)(()=>{i.current?.querySelector(`a`)?.focus()},[]);async function a(){try{await navigator.clipboard.writeText(e.verificationUrl),n(`copied`)}catch{n(`failed`)}}return(0,U.jsxs)(`section`,{className:`hub-connection-approval`,"aria-label":K.connectionApproval,children:[(0,U.jsxs)(`p`,{role:`status`,children:[K.connectionWaiting,` `,(0,U.jsx)(`strong`,{children:e.userCode}),`.`]}),(0,U.jsxs)(`div`,{ref:i,className:`hub-connection-approval-actions`,role:`group`,"aria-label":K.connectionApproval,children:[(0,U.jsx)(H.Button,{as:`a`,variant:`primary`,size:`medium`,href:e.verificationUrl,target:`_blank`,rel:`noopener noreferrer`,children:K.connectToHub}),(0,U.jsx)(W,{icon:t===`copied`?r:m,size:`medium`,className:`hub-connection-approval-copy`,"aria-label":t===`copied`?K.approvalLinkCopied:K.copyApprovalLink,onClick:()=>void a()})]}),(0,U.jsx)(ue,{role:`status`,children:t===`copied`?K.approvalLinkCopied:``}),t===`failed`?(0,U.jsx)(`p`,{role:`alert`,children:K.approvalCopyFailed}):null]})}function pe({status:e,pairing:t,connecting:n,error:r,onConnect:i,onSelectHub:a,onResetHub:o,onClose:s,hubButtonRef:c}){let l=(0,V.useId)(),[u,d]=(0,V.useState)(null),[f,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(!1),[v,y]=(0,V.useState)(!1),[b,x]=(0,V.useState)(``),S=(0,V.useRef)(null),C=(0,V.useRef)(null),w=f||!e?.hubOrigin||u!==null&&!m,T=(0,V.useRef)(w),E=u??e?.hubOrigin??``,D=n||g||v,O=!!t||n;(0,V.useEffect)(()=>{w&&!O?S.current?.focus():T.current&&!O&&C.current?.focus(),T.current=w},[w,O]),(0,V.useEffect)(()=>{if(f||u===null||!m||!e?.hubOrigin)return;let t=window.setTimeout(()=>d(null),0);return()=>window.clearTimeout(t)},[u,f,m,e?.hubOrigin]);async function k(){if(!D){_(!0),x(``);try{await a(E),d(null),p(!1)}catch(e){x(e instanceof Error?e.message:String(e))}finally{_(!1)}}}async function A(){if(!D&&o){y(!0),x(``);try{d(await o()),p(!!e?.hubOrigin)}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(!1)}}}return(0,U.jsxs)(G,{title:K.connectToHub,closeLabel:K.closeConnectionDialog,onClose:s,returnFocusRef:c,children:[(0,U.jsx)(`p`,{children:K.connectionDescription}),b||r?(0,U.jsx)(`p`,{role:`alert`,children:b||r}):null,(0,U.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),!D&&(!O&&w&&(f||e?.hubOrigin)?k():(x(``),e?.hubOrigin||h(!0),i(e?.hubOrigin?void 0:E)))},children:[!O&&(w?(0,U.jsxs)(`div`,{className:`hub-connection-origin-field`,children:[(0,U.jsx)(`label`,{htmlFor:l,children:K.hubUrl}),(0,U.jsxs)(`div`,{className:`hub-connection-origin-input`,children:[(0,U.jsx)(H.TextInput,{ref:S,id:l,type:`url`,value:E,onChange:e=>{h(!1),d(e.target.value)},required:!0,fullWidth:!0,disabled:D,placeholder:`https://hub.example.com`}),o?(0,U.jsx)(W,{icon:R,variant:`invisible`,size:`small`,"aria-label":K.resetHubUrl,disabled:D,"aria-busy":v,onClick:()=>void A()}):null]}),f||e?.hubOrigin?(0,U.jsx)(H.Button,{type:`submit`,variant:`subtle`,size:`small`,disabled:D,children:K.saveHub}):null]}):(0,U.jsxs)(`div`,{className:`hub-connection-origin`,children:[(0,U.jsx)(`a`,{href:e?.hubOrigin&&new URL(e.hubOrigin).origin,target:`_blank`,rel:`noopener noreferrer`,children:e?.hubOrigin}),(0,U.jsx)(W,{ref:C,icon:ae,variant:`invisible`,size:`small`,"aria-label":K.editHubUrl,disabled:D,onClick:()=>{x(``),p(!0),d(e?.hubOrigin??``)}})]})),t?(0,U.jsx)(fe,{pairing:t},t.verificationUrl):null,t?null:(0,U.jsx)(H.Button,{type:`submit`,variant:`primary`,disabled:D||!e?.repository||!O&&w&&(f||!!e?.hubOrigin),children:n?K.connectionOpeningBrowser:K.connectToHub})]})]})}function me({title:e,description:t,children:n,action:r,variant:i,layout:o,onDismiss:s,dismissLabel:l,className:u,...d}){let f=i===`critical`?A:i===`success`?se:i===`info`?a:c;return(0,U.jsxs)(`div`,{...d,role:i===`critical`||i===`warning`?`alert`:`status`,className:`hub-alert hub-alert--${i}${o===`compact`?` hub-alert--compact`:``}${u?` ${u}`:``}`,children:[(0,U.jsx)(f,{className:`hub-alert__icon`,size:20,"aria-hidden":`true`}),(0,U.jsxs)(`div`,{className:`hub-alert__content`,children:[(0,U.jsxs)(H.Text,{as:`p`,size:`100`,className:`hub-alert__message`,children:[(0,U.jsx)(`strong`,{className:`hub-alert__title`,children:e}),t?(0,U.jsx)(`span`,{className:`hub-alert__description`,children:t}):null]}),n]}),r||s?(0,U.jsxs)(`div`,{className:`hub-alert__action`,children:[r,s&&l?(0,U.jsx)(W,{icon:ne,"aria-label":l,title:l,variant:`invisible`,size:`small`,onClick:s}):null]}):null]})}var q={title:`Publish uncommitted changes?`,description:`Do you want to commit changes before publishing? Publishing the committed version only excludes your local uncommitted edits.`,checkFailedTitle:`Could not check local changes`,checkFailed:`Git could not check local changes.`,retryCheck:`Retry check`,commit:`Commit changes & publish`,committed:`Publish committed version only`,close:`Close publishing dialog`,changedFiles:`Uncommitted changes`,moreChanges:e=>`${e} more`,localSkills:e=>`${e} local agent skill ${e===1?`file stays`:`files stay`} uncommitted.`,selection:`Copilot commits only changes related to this prototype task and asks if it cannot tell which changes belong.`,remember:`Always commit changes before publishing for this prototype`,settings:`Settings`,alwaysCommit:`Always commit changes before publishing`,retrySettings:`Retry settings`,preferenceTargetChanged:`The checkout changed. Refresh Settings and try again.`,invalidPreference:`Publishing settings returned an invalid response. Retry settings.`};function he({busy:e,error:t,changes:n,checkError:r,remembered:i,returnFocusRef:a,onClose:o,onChoose:s,onRetry:c}){let[l,u]=(0,V.useState)(i),d=(0,V.useId)(),f=(0,V.useId)();return(0,U.jsx)(G,{title:r?q.checkFailedTitle:q.title,closeLabel:q.close,descriptionId:r?void 0:d,returnFocusRef:a,onClose:()=>{e||o()},className:`publish-changes-dialog`,children:(0,U.jsxs)(H.Stack,{gap:`normal`,padding:`none`,children:[r?null:(0,U.jsx)(`p`,{id:d,children:q.description}),r?(0,U.jsx)(me,{title:r,variant:`critical`,layout:`compact`}):null,n?.files.total?(0,U.jsx)(`section`,{"aria-label":q.changedFiles,children:(0,U.jsxs)(`ul`,{className:`publish-changes-dialog__files`,children:[n.files.paths.map(e=>(0,U.jsx)(`li`,{children:(0,U.jsx)(`code`,{children:e})},e)),n.files.total>n.files.paths.length?(0,U.jsx)(`li`,{children:q.moreChanges(n.files.total-n.files.paths.length)}):null]})}):null,r?null:(0,U.jsxs)(`p`,{children:[n?.localSkills.total?`${q.localSkills(n.localSkills.total)} `:null,q.selection]}),r?null:(0,U.jsxs)(H.FormControl,{id:f,fullWidth:!0,children:[(0,U.jsx)(H.Checkbox,{checked:l,disabled:e,onChange:e=>u(e.target.checked)}),(0,U.jsx)(H.FormControl.Label,{children:q.remember})]}),t?(0,U.jsx)(me,{title:t,variant:`critical`,layout:`compact`}):null,(0,U.jsxs)(`footer`,{className:`publish-changes-dialog__actions`,children:[r?(0,U.jsx)(H.Button,{variant:`primary`,size:`small`,disabled:e,"aria-busy":e,onClick:c,children:q.retryCheck}):null,r?null:(0,U.jsx)(H.Button,{variant:`primary`,size:`small`,disabled:e,"aria-busy":e,onClick:()=>s(`commit-changes`,l),children:q.commit}),(0,U.jsx)(H.Button,{size:`small`,disabled:e,onClick:()=>s(`committed-only`,!1),children:q.committed})]})]})})}function ge({value:e,label:t,copyLabel:n,copiedLabel:r,copyErrorLabel:i,compact:a=!1}){let[o,s]=(0,V.useState)(null),c=o?.value===e?o.status:null,l=c===`copied`?r:n;async function u(){try{await navigator.clipboard.writeText(e),s({value:e,status:`copied`})}catch{s({value:e,status:`failed`})}}return(0,U.jsxs)(`div`,{className:`copyable-text-input${a?` copyable-text-input--compact`:``}`,children:[(0,U.jsxs)(`div`,{className:`copyable-text-input__control`,children:[a?(0,U.jsx)(`input`,{type:`text`,value:e,"aria-label":t,readOnly:!0,className:`copyable-text-input__input`}):(0,U.jsx)(H.TextInput,{value:e,"aria-label":t,readOnly:!0,fullWidth:!0,className:`copyable-text-input__input`}),(0,U.jsx)(W,{icon:m,"aria-label":l,description:a?l:void 0,title:a?void 0:l,variant:`invisible`,size:`small`,className:`copyable-text-input__button`,onClick:()=>void u()})]}),(0,U.jsx)(ue,{"aria-live":`polite`,"aria-atomic":`true`,children:c===`copied`?r:``}),c===`failed`?(0,U.jsx)(`span`,{role:`alert`,className:`copyable-text-input__error`,children:i}):null]})}function _e({children:e}){return(0,U.jsx)(`div`,{className:`prototype-workspace__body`,children:e})}function ve({title:e,description:t,trailing:n,headingAs:r=`h2`,headingRef:i}){return(0,U.jsxs)(`header`,{className:`hub-content-page-header`,children:[(0,U.jsxs)(`div`,{className:`hub-content-page-header__top`,children:[(0,U.jsx)(H.Heading,{as:r,size:`4`,ref:i,tabIndex:i?-1:void 0,children:e}),n]}),t?(0,U.jsx)(H.Text,{as:`p`,className:`hub-content-page-header__description`,children:t}):null]})}function ye({labels:e,headingRef:t,headingTrailing:n,feedback:r,form:i,formUnavailable:a,links:o,hasLinks:s,showEmpty:c=!0,listRef:l,listBusy:u,beforeLinks:d,afterLinks:f}){return(0,U.jsxs)(H.Stack,{gap:`normal`,children:[(0,U.jsx)(ve,{title:e.heading,description:e.description,headingRef:t,trailing:n}),r,i||(a===void 0?(0,U.jsxs)(`section`,{className:`share-links__empty`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`5`,children:e.noBuildHeading}),(0,U.jsx)(H.Text,{as:`p`,className:`share-links__empty-description`,children:e.noBuildLabel})]}):a),d,s?(0,U.jsx)(`ul`,{className:`share-links__list`,ref:l,"aria-busy":u,children:o}):c?(0,U.jsxs)(`section`,{className:`share-links__empty`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`5`,children:e.emptyHeading}),(0,U.jsx)(H.Text,{as:`p`,className:`share-links__empty-description`,children:e.emptyLabel})]}):null,f]})}function be({shareLink:e,className:t,copiedLabel:n,copyErrorLabel:r,copyLabel:i,urlLabel:a,unavailableLabel:o,highlighted:s,children:c}){return(0,U.jsx)(`li`,{"data-share-id":e.id,className:`share-link-item${s?` share-link-item--created`:``}${t?` ${t}`:``}`,children:(0,U.jsxs)(`div`,{className:`share-link-item__layout`,children:[(0,U.jsxs)(`div`,{className:`share-link-item__details`,children:[(0,U.jsx)(`h3`,{children:e.label}),(0,U.jsxs)(`span`,{className:`share-link-item__metadata`,children:[e.buildLabel,e.createdLabel?(0,U.jsxs)(U.Fragment,{children:[` · `,(0,U.jsx)(`time`,{dateTime:e.createdAt,children:e.createdLabel})]}):null,` · `,e.expiresAt?(0,U.jsx)(`time`,{dateTime:e.expiresAt,children:e.expiresLabel}):e.expiresLabel]})]}),(0,U.jsxs)(`div`,{className:`share-link-item__actions`,children:[o?(0,U.jsx)(`p`,{children:o}):(0,U.jsx)(ge,{value:e.url,label:a||e.label,copyLabel:i,copiedLabel:n,copyErrorLabel:r}),c]})]})})}function xe({data:e,action:t,hiddenFields:n,details:r,afterFields:i,onSubmit:a,label:o,onLabelChange:s,expiration:c,onExpirationChange:l,disabled:u,fieldsDisabled:d,busy:f,error:p}){let m=(0,V.useId)(),h=(0,V.useId)();return(0,U.jsxs)(`div`,{className:`share-links-form`,children:[e.buildLabel?(0,U.jsx)(H.Heading,{as:`h2`,size:`5`,children:e.buildLabel}):null,r,(0,U.jsxs)(`form`,{action:t,method:`post`,onSubmit:a,"aria-busy":f,className:`share-links__form`,children:[n,(0,U.jsxs)(`div`,{className:`share-links__form-row`,children:[(0,U.jsxs)(H.FormControl,{id:m,required:!0,fullWidth:!0,className:`share-links__field`,children:[(0,U.jsx)(H.FormControl.Label,{children:e.labelLabel}),(0,U.jsx)(H.TextInput,{"aria-label":e.labelLabel,"aria-invalid":!!p,name:`share_link[label]`,placeholder:e.labelPlaceholder,maxLength:e.labelMaximumBytes,value:o,onChange:s,disabled:d,fullWidth:!0}),p?(0,U.jsx)(H.FormControl.Validation,{validationStatus:`error`,className:`share-links__validation`,children:p}):null]}),p?(0,U.jsx)(ue,{role:`alert`,children:p}):null,(0,U.jsxs)(H.FormControl,{id:h,fullWidth:!0,className:`share-links__field`,children:[(0,U.jsx)(H.FormControl.Label,{children:e.expirationLabel}),(0,U.jsx)(H.Select,{"aria-label":e.expirationLabel,name:`share_link[expiration]`,defaultValue:c===void 0?e.expirationOptions.find(e=>e.value===`seven_days`)?.value??e.expirationOptions[0]?.value:void 0,value:c,onChange:l,disabled:d,fullWidth:!0,children:e.expirationOptions.map(e=>(0,U.jsx)(H.Select.Option,{value:e.value,children:e.label},e.value))})]}),(0,U.jsx)(`div`,{className:`share-links__form-actions`,children:(0,U.jsx)(H.Button,{type:`submit`,variant:`primary`,leadingVisual:v,disabled:u,children:e.submitLabel})})]}),i?(0,U.jsx)(`div`,{className:`share-links__form-options`,children:i}):null]})]})}var J={title:`Share prototype`,internal:`Internal prototype link`,internalDescription:`Requires GitHub sign-in and repository access.`,internalUnavailable:`Internal prototype link unavailable.`,internalCopy:`Copy internal prototype link`,internalOpen:`Open internal prototype link`,public:`Public share links`,permissionUnknown:`Hub has not confirmed permission to manage public share links.`,group:`Publish and share`,back:`Back to preview`,warning:`Anyone with a link can view its Build without signing in. The prototype may expose sensitive or customer information. Check its content before sharing. Local and uncommitted changes are not included.`,target:`New links share this published Build:`,oldBuild:`This is the last published Build, not the current local preview.`,includeControlSettings:`Include current control settings`,controlSettingsDescription:`Adds settings for all configured pages to the links you copy or open. Saved share links stay unchanged.`,controlSettingsWarning:`Settings for controls that have not been published will not take effect for shared links.`,controlSettingsWarningTitle:`Local changes are not in the shared Build`,label:`Label`,labelPlaceholder:`Usability review`,labelInvalid:`Enter a label containing no more than 100 UTF-8 bytes.`,expiry:`Expires after`,expirations:[{value:`one_day`,label:`1 day`},{value:`seven_days`,label:`7 days`},{value:`thirty_days`,label:`30 days`},{value:`never`,label:`Never`}],create:`Create share link`,creating:`Working...`,active:`Active share links`,empty:`Create a link when someone needs signed-out access.`,emptyHeading:`No active share links`,loading:`Loading share links...`,refresh:`Refresh links`,authorize:`Verify with GitHub`,authorizationRetry:`Complete authorization in your browser, then refresh links and submit the action again. No action is replayed automatically.`,paginationFailed:`Hub returned a repeated share-link page. Refresh links to try again.`,noBuild:`A successful published Build is required before creating a share link.`,noBuildHeading:`No successful Build`,build:e=>`Build ${e}`,buildDetails:(e,t,n)=>`Commit: ${e}\nAuthor: @${t}\nPublished: ${n}`,denied:`Managing public share links requires repository admin access or authorship of any successful Build for this Prototype, with current read access. Write access alone is not sufficient.`,disabled:`Public sharing is disabled for this Hub. A Hub administrator must explicitly enable it. Previously revoked links never return.`,disconnected:`Connect to Hub before managing share links.`,connect:`Connect to Hub`,unavailable:`Hub is unavailable. Restore the connection and reopen Share prototype.`,branch:`Open a named prototype branch discovered by Hub before sharing.`,stale:`Hub or checkout changed. Return to preview and reopen Share prototype.`,deleted:`Share link deleted. Its public URL no longer works.`,never:`Never expires`,expires:e=>`Expires ${e}`,createdBy:(e,t)=>`Created by @${e} ${t}`,copy:(e,t)=>`Copy ${e}, Build #${t}`,copied:`Link copied`,copyError:`Could not copy the link. Select the URL and copy it manually.`,open:(e,t)=>`Open ${e}, Build #${t}`,delete:(e,t)=>`Delete ${e}, Build #${t}`,deletePrompt:e=>`Delete "${e}"? Anyone with this link will lose access to its Build.`,deletedError:`Could not delete the link.`,failed:`The sharing request failed.`,unknown:`The sharing request may have completed. Refresh active links before trying again. A matching label does not prove which request created a link.`,expired:`This link has expired. Refresh links.`};function Se({included:e,onChange:t,publishedVersionDiffers:n,disabled:r=!1,error:i,copy:a}){let o=(0,V.useId)(),s=e&&n;return(0,U.jsxs)(`div`,{className:`share-control-settings`,children:[(0,U.jsxs)(H.FormControl,{id:o,fullWidth:!0,children:[(0,U.jsx)(H.Checkbox,{checked:e,onChange:e=>t(e.target.checked),disabled:r}),(0,U.jsx)(H.FormControl.Label,{children:a?.label??J.includeControlSettings}),(0,U.jsx)(H.FormControl.Hint,{className:`share-control-settings__hint`,children:(0,U.jsx)(`span`,{className:`share-control-settings__description`,children:a?.description??J.controlSettingsDescription})})]}),i?(0,U.jsx)(me,{title:i,variant:`critical`,layout:`compact`}):null,s?(0,U.jsx)(me,{title:J.controlSettingsWarningTitle,description:J.controlSettingsWarning,variant:`warning`,layout:`compact`,className:`share-control-settings__warning`}):null]})}function Ce(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.entries(e).every(([e,t])=>/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(e)&&(typeof t==`string`||typeof t==`boolean`||typeof t==`number`&&Number.isFinite(t)||Array.isArray(t)&&t.length<=100&&t.every(e=>typeof e==`string`)))}var we=`replica:controls:url`,Te=/^rc\.([a-zA-Z][a-zA-Z0-9_-]{0,63})\.([a-zA-Z][a-zA-Z0-9_-]{0,63})$/;function Ee(e){let t=new URLSearchParams;for(let n of Object.keys(e).sort()){let r=e[n];if(!Ce(r))throw Error(`Invalid control settings.`);for(let e of Object.keys(r).sort()){let i=`rc.${n}.${e}`;if(!Te.test(i))throw Error(`Invalid control settings identifier.`);t.set(i,JSON.stringify(r[e]))}}let n=t.toString();if(new Blob([n]).size>8192)throw Error(`Control settings exceed the 8 KB URL limit. Reduce the settings before sharing.`);return n}function De(e){let t=new URLSearchParams(e),n=[...t].filter(([e])=>e.startsWith(`rc.`));if(new Blob([new URLSearchParams(n).toString()]).size>8192)return{scopes:{},notice:`Control settings in this URL exceed 8 KB. Defaults were used.`};let r=new Map,i=!1;for(let[e,a]of n){let n=Te.exec(e);if(!n||t.getAll(e).length!==1){i=!0;continue}let o=n[1],s=n[2],c;try{c=JSON.parse(a)}catch{c=a}if(!Ce({[s]:c})){i=!0;continue}let l=r.get(o)??new Map;l.set(s,c),r.set(o,l)}let a=Object.fromEntries([...r].map(([e,t])=>[e,Object.fromEntries(t)]));try{Ee(a)}catch{return{scopes:{},notice:`Control settings in this URL exceed 8 KB. Defaults were used.`}}return{scopes:a,notice:i?`Some URL control settings were invalid. Defaults were used instead.`:``}}function Oe(e,t){let n=new URL(e,window.location.href),r=De(t);if(r.notice)throw Error(r.notice);for(let e of[...n.searchParams.keys()])e.startsWith(`rc.`)&&n.searchParams.delete(e);for(let[e,t]of new URLSearchParams(Ee(r.scopes)))n.searchParams.set(e,t);return n.toString()}function ke({state:e,buildDetails:t,currentCommit:n,hasLocalChanges:r=!1,shareButtonRef:i,onClose:a,onConnect:o,onRefresh:s,onCreate:c,onDelete:l,onOpen:u,controlSettings:d,onAuthorize:f}){let[p,m]=(0,V.useState)(``),[h,g]=(0,V.useState)(`seven_days`),[_,v]=(0,V.useState)(``),[y,b]=(0,V.useState)(Date.now),x=(0,V.useRef)(null),S=(0,V.useRef)(null),C=(0,V.useRef)(null),w=e.context?.prototype,T=J.expirations.filter(e=>!w?.shareLinkExpirationOptions||w.shareLinkExpirationOptions.includes(e.value)),E=T.some(e=>e.value===h)?h:T.find(e=>e.value===`seven_days`)?.value??T[0]?.value??``,D=w?.published?w.build:null,k=D?.url,A=k&&URL.canParse(k)?new URL(k):null,j=A&&A.origin===e.context?.hubOrigin&&[`http:`,`https:`].includes(A.protocol)&&!A.username&&!A.password?k:null,M=!!(D&&n&&n!==D.commitSha)||r,N=w?.canManageShareLinks===!0,P=!e.sharingDisabled&&w?.publicSharingEnabled!==!1,F=e.busy||e.loading||e.stale||!N||!P,I=d?.included?d.query??``:``,L=!!d?.blocked;function R(e){return Oe(e,I)}let z=P&&e.stale&&!e.loading&&e.created&&!e.links.some(t=>t.id===e.created?.id)?e.created:null;(0,V.useEffect)(()=>{let e=i.current;S.current?.focus();let t=window.setInterval(()=>b(Date.now()),1e4);return()=>{window.clearInterval(t),e?.focus()}},[i]),(0,V.useEffect)(()=>{if(e.busy||!C.current)return;let t=C.current;C.current=null,(t.map(e=>x.current?.querySelector(`[data-share-id="${e}"] button`)).find(e=>e&&!e.disabled)||S.current)?.focus()},[e.busy,e.links]);async function ee(t,n){if(!window.confirm(J.deletePrompt(n)))return;let r=e.links.findIndex(e=>e.id===t),i=[...e.links.slice(r+1),...e.links.slice(0,r).reverse()].map(e=>e.id);await l(t)&&(C.current=i,(i.map(e=>x.current?.querySelector(`[data-share-id="${e}"] button`)).find(e=>e&&!e.disabled)||S.current)?.focus())}function B(e){return new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e))}return(0,U.jsx)(`main`,{className:`canvas-share-page`,"aria-label":J.title,children:(0,U.jsx)(_e,{children:(0,U.jsx)(ye,{labels:{heading:J.title,noBuildHeading:J.noBuildHeading,noBuildLabel:J.noBuild,emptyHeading:J.emptyHeading,emptyLabel:J.empty},headingRef:S,headingTrailing:(0,U.jsx)(`div`,{className:`canvas-share-close`,children:(0,U.jsx)(W,{icon:ne,variant:`invisible`,"aria-label":J.back,description:J.back,onClick:a})}),feedback:(0,U.jsxs)(U.Fragment,{children:[d?(0,U.jsx)(Se,{included:d.included,onChange:d.onChange,publishedVersionDiffers:M,disabled:e.busy||d.pending,error:d.error}):null,(0,U.jsxs)(`section`,{className:`canvas-share-internal`,"aria-label":J.internal,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`6`,children:J.internal}),(0,U.jsx)(`p`,{children:J.internalDescription}),j&&!L?(0,U.jsxs)(`div`,{className:`share-link-item__actions canvas-share-internal-actions`,children:[(0,U.jsx)(ge,{value:R(j),label:J.internal,copyLabel:J.internalCopy,copiedLabel:J.copied,copyErrorLabel:J.copyError}),(0,U.jsx)(W,{as:`a`,href:R(j),target:`_blank`,rel:`noopener`,icon:ie,"aria-label":J.internalOpen,description:J.internalOpen})]}):j?null:(0,U.jsx)(`p`,{role:`status`,children:J.internalUnavailable})]}),(0,U.jsxs)(`div`,{className:`canvas-share-public-header`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`6`,children:J.public}),(0,U.jsx)(`p`,{children:J.warning})]}),w&&!N?(0,U.jsx)(`p`,{role:`status`,children:w.canManageShareLinks===!1?J.denied:J.permissionUnknown}):null,P?null:(0,U.jsx)(`p`,{role:`status`,children:J.disabled}),e.error?(0,U.jsx)(me,{title:e.error,variant:`critical`,layout:`compact`}):null,e.authorization&&f?(0,U.jsx)(H.Button,{variant:`secondary`,size:`small`,onClick:f,disabled:e.busy,children:J.authorize}):null,o&&!e.context?(0,U.jsx)(H.Button,{variant:`secondary`,size:`small`,onClick:o,children:J.connect}):null]}),form:D&&N&&P?(0,U.jsx)(xe,{data:{buildLabel:null,labelLabel:J.label,labelPlaceholder:J.labelPlaceholder,labelMaximumBytes:100,expirationLabel:J.expiry,expirationOptions:T,submitLabel:e.busy?J.creating:J.create},label:p,onLabelChange:e=>{m(e.target.value),v(``)},expiration:E,onExpirationChange:e=>g(e.target.value),onSubmit:e=>{e.preventDefault(),!p.trim()||new TextEncoder().encode(p.trim()).length>100?v(J.labelInvalid):(v(``),c(p,E))},disabled:F,fieldsDisabled:e.busy,busy:e.busy,error:_,details:(0,U.jsxs)(`div`,{className:`canvas-share-build-details`,children:[(0,U.jsxs)(`p`,{children:[J.target,` `,(0,U.jsx)(`strong`,{children:J.build(D.number)}),` - `,(0,U.jsx)(`code`,{children:D.commitSha.slice(0,7)}),` - `,(0,U.jsx)(`time`,{dateTime:D.publishedAt,children:B(D.publishedAt)})]}),M?(0,U.jsx)(`p`,{children:J.oldBuild}):null]})}):null,formUnavailable:N&&P&&!D?void 0:null,beforeLinks:(0,U.jsxs)(U.Fragment,{children:[e.notice?(0,U.jsx)(`p`,{role:`status`,children:e.notice}):null,z&&!L?(0,U.jsx)(ge,{value:R(z.url),label:z.label,copyLabel:J.copy(z.label,z.buildNumber),copiedLabel:J.copied,copyErrorLabel:J.copyError}):null,e.loading?(0,U.jsx)(`p`,{role:`status`,children:J.loading}):null]}),hasLinks:N&&P&&!L&&e.links.length>0,showEmpty:N&&P&&!L&&!e.loading&&!e.stale,listRef:x,listBusy:e.loading,links:(!N||!P||L?[]:e.links).map(e=>{let n=e.expiresAt!==null&&Date.parse(e.expiresAt)<=y,r=t?.[e.buildNumber];return(0,U.jsxs)(be,{className:D&&e.buildNumberI?u(e.id,I):u(e.id)}),(0,U.jsx)(W,{icon:O,variant:`danger`,"aria-label":J.delete(e.label,e.buildNumber),description:J.delete(e.label,e.buildNumber),disabled:F||n,onClick:()=>void ee(e.id,e.label)})]},e.id)}),afterLinks:(0,U.jsx)(`div`,{className:`canvas-share-list-actions`,children:N||!e.context&&!o?(0,U.jsx)(H.Button,{size:`small`,variant:`subtle`,onClick:s,disabled:e.busy||e.loading,children:J.refresh}):null})})})})}var Y={checking:`Checking sharing readiness`,checkingDetail:`Checking Hub for a successful published Build and repository access.`,connect:`Connect before sharing`,connectDetail:`Connect to Hub before sharing this prototype.`,connectAction:`Connect to Hub`,publish:`Publish before sharing`,publishDetail:`To create a share link, publish this prototype to Hub first. Your local preview stays private.`,publishPermissionUnverified:`This Hub has not confirmed publishing permission. Copilot will check access when publishing and report any permission errors.`,preparing:`Preparing your prototype`,ready:`Ready to share`,readyDetail:`Your prototype is ready to share.`,manage:`Share prototype`,unavailable:`Sharing status unavailable`,unavailableDetail:`Hub could not verify sharing readiness. Retry before continuing.`,permissionUnknown:`This Hub cannot verify sharing or publishing permission. Update Hub and retry.`,restricted:`Sharing unavailable`,publishDenied:`Publishing requires repository write access. Ask a prototype author to publish a Build.`,local:`Local development prototypes cannot create public share links.`,changed:`Sharing target changed`,changedDetail:`The repository, branch, or Hub changed. Close this dialog and reopen Share for the intended prototype.`,boundary:`Internal review requires repository access. Public share links let anyone view a published Build, not your local preview.`,close:`Close sharing readiness`},Ae=`Branch not eligible for Hub registration`,X={heading:`Branch publication`,checking:`Checking...`,retry:`Retry status`,retryPublish:`Retry publish`,requested:`Requested`,awaitingCopilot:`Waiting for Copilot`,publishBranch:`Publish`,publishChanges:`Publish changes`,registration:`Publishing`,registrationFailed:`Publication delayed`,published:`Published`,alreadyPublished:`Latest changes already published`,queued:`Build queued`,building:`Building`,awaitingHub:`Awaiting Hub`,awaitingBuild:`Awaiting build`,connect:`Connect to the hub`,workflowLink:`View workflow run`,initial:`Checking branch publication.`,checkingRemote:`Checking the exact branch on the origin repository.`,detached:`Open a named branch before publishing.`,changed:`The checkout changed. Refresh publication status.`,unknown:e=>`Remote branch status is unknown. ${e||`Check GitHub access and retry.`}`,pending:`Copilot received the publish request in chat and has not pushed this branch yet. Follow its progress in chat.`,checkingHub:`Checking the Hub connection.`,disconnected:`Connect to the hub before publishing this prototype.`,hubUnavailable:`Hub verification is unavailable. Restore access and retry.`,hubUnavailableTitle:`Hub verification unavailable`,staleHub:`The Hub status belongs to a different checkout. Refresh to continue.`,workflowMissing:`This checkout has no .github/workflows/replica.yml. Set up the repository's Replica build workflow before publishing.`,dispatchFailed:`Copilot could not receive the publish request.`,absent:`This branch won't appear in the hub until you publish.`,needsPush:`The remote branch points to a different commit. Publish pushes this branch without force.`,localChanges:`Local changes are not in the published prototype. Choose how to publish them.`,needsRegistration:`Hub imported this commit. The canvas is publishing it automatically.`,registrationDenied:`Hub could not register this branch. Check repository access and branch eligibility.`,registrationErrorTitle:`Hub registration failed`,registrationReasons:new Map([[`write_access_required`,{title:Ae,description:`You lack write access to this repository.`}],[`branch_not_reviewable`,{title:Ae,description:`Default, reserved, and internal branches cannot be registered in Hub.`}],[`remote_branch_missing`,{title:Ae,description:`The branch no longer exists on the remote repository.`}],[`branch_authorship_required`,{title:Ae,description:`You have not authored a commit unique to this branch.`}],[`repository_mismatch`,{title:Ae,description:`The branch belongs to a different repository.`}],[`already_registered`,{title:`Branch already registered in Hub`,description:`This branch is already registered in Hub. Refresh its status.`}],[`successful_build_required`,{title:`Hub registration delayed`,description:`Hub has not imported this checkout's successful Build yet.`}]]),ready:`Hub imported this commit and the prototype is registered.`,importFailed:`Hub could not import or build this commit. Pushing this unchanged commit does not rerun the failed work. Inspect the Build failure in Hub and repair the cause before publishing again.`,workflowUnavailable:`Workflow status is unavailable. Check GitHub access and retry.`,staleWorkflow:`Workflow status belongs to a different branch or commit.`,workflowQueued:`The Replica workflow for this commit is queued or waiting.`,workflowBuilding:`The Replica workflow is building this commit.`,workflowFailed:e=>`The Replica workflow finished with ${e||`an unsuccessful result`}. Pushing this unchanged commit does not rerun the failed work. Inspect the run and repair the cause before publishing again.`,importing:`The workflow succeeded. Waiting for Hub discovery and artifact import; this is not published yet.`,noBuild:`The exact branch and commit are on GitHub, but no matching Replica workflow run has appeared yet.`};function je({publication:e,busy:t,onPublish:n,onRetry:r}){if(e.kind===`ready`)return null;let i=e.kind===`requested`,a=t||i;return(0,U.jsxs)(`section`,{className:`canvas-branch-publication`,"aria-label":X.heading,children:[e.error?(0,U.jsx)(me,{variant:`critical`,layout:`compact`,title:e.error.title,description:e.error.description}):(0,U.jsx)(`p`,{role:`status`,children:e.detail}),e.runUrl?(0,U.jsx)(`p`,{children:(0,U.jsx)(H.InlineLink,{className:`canvas-branch-publication__workflow-link`,href:e.runUrl,target:`_blank`,rel:`noopener noreferrer`,children:X.workflowLink})}):null,(e.action!==`none`||i)&&e.kind!==`disconnected`?(0,U.jsx)(`div`,{className:`canvas-branch-publication__actions`,children:(0,U.jsx)(H.Button,{variant:`primary`,size:`small`,disabled:a,"aria-busy":a,leadingVisual:a?(0,U.jsx)(R,{size:16}):void 0,onClick:e.action===`retry`?r:n,children:e.label})}):null]})}function Me({readiness:e,busy:t,shareButtonRef:n,onClose:r,onConnect:i,onPublish:a,onRetry:o,onManage:s}){let c=(0,V.useId)();return(0,U.jsxs)(G,{title:e.title,closeLabel:Y.close,onClose:r,returnFocusRef:n,descriptionId:c,children:[(0,U.jsx)(`p`,{id:c,role:`status`,children:e.detail}),[`connect`,`publish`,`ready`].includes(e.kind)?(0,U.jsx)(`p`,{children:Y.boundary}):null,e.publication?(0,U.jsx)(je,{publication:e.publication,dirty:!1,busy:t,onPublish:a,onRetry:o}):null,[`connect`,`ready`,`retry`].includes(e.kind)?(0,U.jsx)(H.Button,{variant:`primary`,size:`small`,disabled:t,"aria-busy":t,onClick:e.kind===`connect`?i:e.kind===`ready`?s:o,children:e.kind===`connect`?Y.connectAction:e.kind===`ready`?Y.manage:X.retry}):null]})}function Ne({hub:e,connection:t,publication:n,sharing:r,shareIntent:i,controlSettings:a,readiness:o,state:s,hubOpen:c,buildDetailsOpen:l,onCloseBuildDetails:u,shareButtonRef:d,hubButtonRef:f,connectionButtonRef:p,publishButtonRef:m,titleButtonRef:h}){let{intent:g,targetChanged:_}=i,v=n.presentedState;return(0,U.jsxs)(U.Fragment,{children:[t.open&&(!g||g.connecting&&!_)?(0,U.jsx)(pe,{status:e.status,pairing:t.pairing,connecting:t.connecting,error:t.error,onConnect:t.connect,onSelectHub:e.select,onResetHub:e.reset,onClose:()=>{t.close(),i.setConnecting(!1)},hubButtonRef:g?d:c?p:f}):null,g&&!n.publishDialog&&(_||!g.connecting||!t.open)?(0,U.jsx)(Me,{readiness:_?{kind:`restricted`,title:Y.changed,detail:Y.changedDetail}:o,busy:n.busy,shareButtonRef:d,onClose:()=>{i.close(),t.close()},onConnect:()=>{_||o.kind!==`connect`||(i.setConnecting(!0),t.showAndConnect())},onPublish:()=>{!_&&o.kind===`publish`&&n.publish()},onRetry:()=>void n.retry(),onManage:()=>{_||o.kind!==`ready`||(i.close(),r.open())}}):null,n.publishDialog?(0,U.jsx)(he,{busy:n.busy,error:n.publishDialogError,changes:n.publishDialog.preparation.changes,checkError:n.publishDialog.preparation.workingTree===`unavailable`?n.publishDialog.preparation.workingTreeError||q.checkFailed:void 0,remembered:n.publishDialog.preparation.remember,returnFocusRef:g?d:m,onClose:n.closePublishDialog,onChoose:(e,t)=>void n.choosePublish(e,t),onRetry:()=>void n.retryPublishCheck()},n.publishDialog.preparation.workingTree===`unavailable`?`unchecked`:`checked`):null,r.state.open?(0,U.jsx)(ke,{state:r.state,currentCommit:s?.stats.commitSha,hasLocalChanges:s?.stats.workingTree===`changed`,shareButtonRef:d,onClose:r.close,onConnect:!e.status||[`disconnected`,`pairing`,`unconfigured`].includes(e.status.state)?()=>{r.close(),t.show()}:void 0,onRefresh:()=>void r.refresh(),onCreate:r.create,onDelete:r.remove,onOpen:(e,t)=>void r.openLink(e,t),controlSettings:a,onAuthorize:()=>void r.authorize()}):null,l&&v?(0,U.jsx)(de,{state:v,titleButtonRef:h,onClose:u}):null]})}function Pe({address:e,addressRef:t,canGoBack:n,canGoForward:r,appearance:a,onAppearanceChange:o,onBack:s,onForward:c,onNavigate:l,onOpenTab:u,onReload:d}){let[f,p]=(0,V.useState)(null),m=f?.address===e?f.value:e,h=f?.address===e?f.error:``;function g(t){t.preventDefault();try{let t=new URL(m.trim(),e);if(![`http:`,`https:`].includes(t.protocol)||t.origin!==new URL(e).origin||t.username||t.password){p({address:e,value:m,error:K.browserAddressOrigin});return}p(null),l(t.href)}catch{p({address:e,value:m,error:K.browserAddressInvalid})}}return(0,U.jsx)(H.ThemeProvider,{colorMode:`auto`,className:`canvas-browser-theme`,children:(0,U.jsxs)(`nav`,{className:`canvas-browser-bar`,"aria-label":K.browserNavigation,children:[(0,U.jsxs)(`div`,{className:`canvas-browser-bar__navigation`,children:[(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserBack,disabled:!n,onClick:s,children:(0,U.jsx)(x,{size:16})}),(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserForward,disabled:!r,onClick:c,children:(0,U.jsx)(y,{size:16})}),(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserReload,onClick:d,children:(0,U.jsx)(R,{size:16})})]}),(0,U.jsxs)(`form`,{className:`canvas-browser-bar__address`,onSubmit:g,children:[(0,U.jsx)(`input`,{ref:t,"aria-label":K.browserAddress,"aria-invalid":!!h,"aria-describedby":h?`canvas-browser-address-error`:void 0,spellCheck:!1,value:m,onChange:t=>{p({address:e,value:t.target.value,error:``})},onFocus:e=>e.currentTarget.select(),onKeyDown:e=>{e.key===`Escape`&&(p(null),e.currentTarget.blur())}}),h?(0,U.jsx)(`span`,{id:`canvas-browser-address-error`,className:`canvas-browser-bar__error`,role:`alert`,children:h}):null]}),(0,U.jsxs)(`div`,{className:`canvas-browser-bar__tools`,children:[(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserOpenTab,title:K.browserOpenTab,onClick:()=>{u().catch(t=>{p({address:e,value:m,error:t instanceof Error?t.message:String(t)})})},children:(0,U.jsx)(ie,{size:16})}),(0,U.jsxs)(`div`,{className:`canvas-browser-bar__appearance`,role:`group`,"aria-label":K.browserAppearance,children:[(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserLight,"aria-pressed":a===`light`,onClick:()=>o(`light`),children:(0,U.jsx)(F,{size:16})}),(0,U.jsx)(`button`,{type:`button`,"aria-label":K.browserDark,"aria-pressed":a===`dark`,onClick:()=>o(`dark`),children:(0,U.jsx)(i,{size:16})})]})]})]})})}var Fe=e(t((e=>{var t=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),n=t((e=>{Object.defineProperty(e,"__esModule",{value:!0});function t(e){let t=e.length,n=0,r=0,i;for(;r=55296&&i<=56319&&r{t.exports=function e(t,n){if(t===n)return!0;if(t&&n&&typeof t==`object`&&typeof n==`object`){if(t.constructor!==n.constructor)return!1;var r,i,a;if(Array.isArray(t)){if(r=t.length,r!=n.length)return!1;for(i=r;i--!==0;)if(!e(t[i],n[i]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if(a=Object.keys(t),r=a.length,r!==Object.keys(n).length)return!1;for(i=r;i--!==0;)if(!Object.prototype.hasOwnProperty.call(n,a[i]))return!1;for(i=r;i--!==0;){var o=a[i];if(!e(t[o],n[o]))return!1}return!0}return t!==t&&n!==n}})),i=t((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=r();t.code=`require("ajv/dist/runtime/equal").default`,e.default=t}));e.validateShape=P;var a={type:`object`,additionalProperties:!1,required:[`version`,`scope`,`controls`],properties:{$schema:{type:`string`},version:{const:1},scope:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},role:{enum:[`shared`,`page`]},container:{$ref:`#/$defs/selector`},panel:{type:`object`,additionalProperties:!1,required:[`width`],properties:{width:{type:`integer`,minimum:160,maximum:4096}}},groups:{type:`array`,maxItems:100,items:{type:`object`,additionalProperties:!1,required:[`id`,`label`],properties:{id:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},when:{$ref:`#/$defs/condition`}}}},controls:{type:`array`,maxItems:500,items:{oneOf:[{$ref:`#/$defs/boolean`},{$ref:`#/$defs/number`},{$ref:`#/$defs/slider`},{$ref:`#/$defs/choice`},{$ref:`#/$defs/checkboxGroup`},{$ref:`#/$defs/text`},{$ref:`#/$defs/color`},{$ref:`#/$defs/button`}]}}}},o=Object.prototype.hasOwnProperty,s=n().default,c=RegExp(`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`,`u`),l={type:[`string`,`number`,`boolean`]},u=i().default,d={validate:f};function f(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0,s=o,p=!1,m=null,h=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.control===void 0){let e={instancePath:t,schemaPath:`#/oneOf/0/required`,keyword:`required`,params:{missingProperty:`control`},message:`must have required property 'control'`};a===null?a=[e]:a.push(e),o++}if(e.equals===void 0){let e={instancePath:t,schemaPath:`#/oneOf/0/required`,keyword:`required`,params:{missingProperty:`equals`},message:`must have required property 'equals'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`control`&&n!==`equals`){let e={instancePath:t,schemaPath:`#/oneOf/0/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.control!==void 0){let n=e.control;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.equals!==void 0){let n=e.equals;if(typeof n!=`string`&&!(typeof n==`number`&&isFinite(n))&&typeof n!=`boolean`){let e={instancePath:t+`/equals`,schemaPath:`#/$defs/scalar/type`,keyword:`type`,params:{type:l.type},message:`must be string,number,boolean`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/0/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var g=h===o;g&&(p=!0,m=0);let _=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.control===void 0){let e={instancePath:t,schemaPath:`#/oneOf/1/required`,keyword:`required`,params:{missingProperty:`control`},message:`must have required property 'control'`};a===null?a=[e]:a.push(e),o++}if(e.in===void 0){let e={instancePath:t,schemaPath:`#/oneOf/1/required`,keyword:`required`,params:{missingProperty:`in`},message:`must have required property 'in'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`control`&&n!==`in`){let e={instancePath:t,schemaPath:`#/oneOf/1/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.control!==void 0){let n=e.control;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.in!==void 0){let n=e.in;if(Array.isArray(n)){if(n.length>20){let e={instancePath:t+`/in`,schemaPath:`#/oneOf/1/properties/in/maxItems`,keyword:`maxItems`,params:{limit:20},message:`must NOT have more than 20 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/in`,schemaPath:`#/oneOf/1/properties/in/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r1){outer0:for(;r--;)for(i=r;i--;)if(u(n[r],n[i])){let e={instancePath:t+`/in`,schemaPath:`#/oneOf/1/properties/in/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[e]:a.push(e),o++;break outer0}}}else{let e={instancePath:t+`/in`,schemaPath:`#/oneOf/1/properties/in/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/1/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var g=_===o;if(g&&p)p=!1,m=[m,1];else{g&&(p=!0,m=1);let n=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.control===void 0){let e={instancePath:t,schemaPath:`#/oneOf/2/required`,keyword:`required`,params:{missingProperty:`control`},message:`must have required property 'control'`};a===null?a=[e]:a.push(e),o++}if(e.includes===void 0){let e={instancePath:t,schemaPath:`#/oneOf/2/required`,keyword:`required`,params:{missingProperty:`includes`},message:`must have required property 'includes'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`control`&&n!==`includes`){let e={instancePath:t,schemaPath:`#/oneOf/2/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.control!==void 0){let n=e.control;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/control`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.includes!==void 0&&typeof e.includes!=`string`){let e={instancePath:t+`/includes`,schemaPath:`#/oneOf/2/properties/includes/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t,schemaPath:`#/oneOf/2/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var g=n===o;if(g&&p)p=!1,m=[m,2];else{g&&(p=!0,m=2);let n=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.all===void 0){let e={instancePath:t,schemaPath:`#/oneOf/3/required`,keyword:`required`,params:{missingProperty:`all`},message:`must have required property 'all'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`all`){let e={instancePath:t,schemaPath:`#/oneOf/3/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.all!==void 0){let n=e.all;if(Array.isArray(n)){if(n.length>10){let e={instancePath:t+`/all`,schemaPath:`#/oneOf/3/properties/all/maxItems`,keyword:`maxItems`,params:{limit:10},message:`must NOT have more than 10 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/all`,schemaPath:`#/oneOf/3/properties/all/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r10){let e={instancePath:t+`/any`,schemaPath:`#/oneOf/4/properties/any/maxItems`,keyword:`maxItems`,params:{limit:10},message:`must NOT have more than 10 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/any`,schemaPath:`#/oneOf/4/properties/any/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r512){let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/maxLength`,keyword:`maxLength`,params:{limit:512},message:`must NOT have more than 512 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/0/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var f=d===o;f&&(l=!0,u=0);let v=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.type===void 0){let e={instancePath:t,schemaPath:`#/oneOf/1/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.selector===void 0){let e={instancePath:t,schemaPath:`#/oneOf/1/required`,keyword:`required`,params:{missingProperty:`selector`},message:`must have required property 'selector'`};a===null?a=[e]:a.push(e),o++}if(e.property===void 0){let e={instancePath:t,schemaPath:`#/oneOf/1/required`,keyword:`required`,params:{missingProperty:`property`},message:`must have required property 'property'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`type`&&n!==`selector`&&n!==`property`){let e={instancePath:t,schemaPath:`#/oneOf/1/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.type!==void 0&&e.type!==`style`){let e={instancePath:t+`/type`,schemaPath:`#/oneOf/1/properties/type/const`,keyword:`const`,params:{allowedValue:`style`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.selector!==void 0){let n=e.selector;if(typeof n==`string`){if(s(n)>512){let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/maxLength`,keyword:`maxLength`,params:{limit:512},message:`must NOT have more than 512 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/selector`,schemaPath:`#/$defs/selector/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.property!==void 0){let n=e.property;if(typeof n==`string`){if(s(n)>100){let e={instancePath:t+`/property`,schemaPath:`#/oneOf/1/properties/property/maxLength`,keyword:`maxLength`,params:{limit:100},message:`must NOT have more than 100 characters`};a===null?a=[e]:a.push(e),o++}if(!m.test(n)){let e={instancePath:t+`/property`,schemaPath:`#/oneOf/1/properties/property/pattern`,keyword:`pattern`,params:{pattern:`^(--[a-zA-Z0-9_-]+|[a-z][a-z-]*)$`},message:`must match pattern "^(--[a-zA-Z0-9_-]+|[a-z][a-z-]*)$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/property`,schemaPath:`#/oneOf/1/properties/property/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/1/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var f=v===o;if(f&&l)l=!1,u=[u,1];else{f&&(l=!0,u=1);let n=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.type===void 0){let e={instancePath:t,schemaPath:`#/oneOf/2/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.key===void 0){let e={instancePath:t,schemaPath:`#/oneOf/2/required`,keyword:`required`,params:{missingProperty:`key`},message:`must have required property 'key'`};a===null?a=[e]:a.push(e),o++}if(e.mode===void 0){let e={instancePath:t,schemaPath:`#/oneOf/2/required`,keyword:`required`,params:{missingProperty:`mode`},message:`must have required property 'mode'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`type`&&n!==`key`&&n!==`mode`){let e={instancePath:t,schemaPath:`#/oneOf/2/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.type!==void 0&&e.type!==`query`){let e={instancePath:t+`/type`,schemaPath:`#/oneOf/2/properties/type/const`,keyword:`const`,params:{allowedValue:`query`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.key!==void 0){let n=e.key;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/key`,schemaPath:`#/oneOf/2/properties/key/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/key`,schemaPath:`#/oneOf/2/properties/key/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/key`,schemaPath:`#/oneOf/2/properties/key/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.mode!==void 0){let n=e.mode;if(n!==`in-place`&&n!==`navigate`){let e={instancePath:t+`/mode`,schemaPath:`#/oneOf/2/properties/mode/enum`,keyword:`enum`,params:{allowedValues:p.oneOf[2].properties.mode.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/2/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var f=n===o;if(f&&l)l=!1,u=[u,2];else{f&&(l=!0,u=2);let n=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.type===void 0){let e={instancePath:t,schemaPath:`#/oneOf/3/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.mode===void 0){let e={instancePath:t,schemaPath:`#/oneOf/3/required`,keyword:`required`,params:{missingProperty:`mode`},message:`must have required property 'mode'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`type`&&n!==`mode`){let e={instancePath:t,schemaPath:`#/oneOf/3/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.type!==void 0&&e.type!==`hash`){let e={instancePath:t+`/type`,schemaPath:`#/oneOf/3/properties/type/const`,keyword:`const`,params:{allowedValue:`hash`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.mode!==void 0){let n=e.mode;if(n!==`in-place`&&n!==`navigate`){let e={instancePath:t+`/mode`,schemaPath:`#/oneOf/3/properties/mode/enum`,keyword:`enum`,params:{allowedValues:p.oneOf[3].properties.mode.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),o++}}}else{let e={instancePath:t,schemaPath:`#/oneOf/3/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var f=n===o;if(f&&l)l=!1,u=[u,3];else{f&&(l=!0,u=3);let n=o;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.type===void 0){let e={instancePath:t,schemaPath:`#/oneOf/4/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.object===void 0){let e={instancePath:t,schemaPath:`#/oneOf/4/required`,keyword:`required`,params:{missingProperty:`object`},message:`must have required property 'object'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`type`&&n!==`object`&&n!==`read`&&n!==`write`&&n!==`action`&&n!==`subscribe`&&n!==`pollMs`){let e={instancePath:t,schemaPath:`#/oneOf/4/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.type!==void 0&&e.type!==`api`){let e={instancePath:t+`/type`,schemaPath:`#/oneOf/4/properties/type/const`,keyword:`const`,params:{allowedValue:`api`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.object!==void 0){let n=e.object;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/object`,schemaPath:`#/oneOf/4/properties/object/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(!h.test(n)){let e={instancePath:t+`/object`,schemaPath:`#/oneOf/4/properties/object/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z_$][a-zA-Z0-9_$]*)*$`},message:`must match pattern "^[a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z_$][a-zA-Z0-9_$]*)*$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/object`,schemaPath:`#/oneOf/4/properties/object/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.read!==void 0){let n=e.read;if(typeof n==`string`){if(s(n)>64){let e={instancePath:t+`/read`,schemaPath:`#/$defs/method/maxLength`,keyword:`maxLength`,params:{limit:64},message:`must NOT have more than 64 characters`};a===null?a=[e]:a.push(e),o++}if(!g.test(n)){let e={instancePath:t+`/read`,schemaPath:`#/$defs/method/pattern`,keyword:`pattern`,params:{pattern:`^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$`},message:`must match pattern "^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/read`,schemaPath:`#/$defs/method/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.write!==void 0){let n=e.write;if(typeof n==`string`){if(s(n)>64){let e={instancePath:t+`/write`,schemaPath:`#/$defs/method/maxLength`,keyword:`maxLength`,params:{limit:64},message:`must NOT have more than 64 characters`};a===null?a=[e]:a.push(e),o++}if(!g.test(n)){let e={instancePath:t+`/write`,schemaPath:`#/$defs/method/pattern`,keyword:`pattern`,params:{pattern:`^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$`},message:`must match pattern "^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/write`,schemaPath:`#/$defs/method/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.action!==void 0){let n=e.action;if(typeof n==`string`){if(s(n)>64){let e={instancePath:t+`/action`,schemaPath:`#/$defs/method/maxLength`,keyword:`maxLength`,params:{limit:64},message:`must NOT have more than 64 characters`};a===null?a=[e]:a.push(e),o++}if(!g.test(n)){let e={instancePath:t+`/action`,schemaPath:`#/$defs/method/pattern`,keyword:`pattern`,params:{pattern:`^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$`},message:`must match pattern "^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/action`,schemaPath:`#/$defs/method/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.subscribe!==void 0){let n=e.subscribe;if(typeof n==`string`){if(s(n)>64){let e={instancePath:t+`/subscribe`,schemaPath:`#/$defs/method/maxLength`,keyword:`maxLength`,params:{limit:64},message:`must NOT have more than 64 characters`};a===null?a=[e]:a.push(e),o++}if(!g.test(n)){let e={instancePath:t+`/subscribe`,schemaPath:`#/$defs/method/pattern`,keyword:`pattern`,params:{pattern:`^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$`},message:`must match pattern "^(?!constructor$|prototype$|__proto__$)[a-zA-Z_$][a-zA-Z0-9_$]*$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/subscribe`,schemaPath:`#/$defs/method/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.pollMs!==void 0){let n=e.pollMs;if(typeof n!=`number`||n%1||isNaN(n)||!isFinite(n)){let e={instancePath:t+`/pollMs`,schemaPath:`#/oneOf/4/properties/pollMs/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};a===null?a=[e]:a.push(e),o++}if(typeof n==`number`&&isFinite(n)){if(n>6e4||isNaN(n)){let e={instancePath:t+`/pollMs`,schemaPath:`#/oneOf/4/properties/pollMs/maximum`,keyword:`maximum`,params:{comparison:`<=`,limit:6e4},message:`must be <= 60000`};a===null?a=[e]:a.push(e),o++}if(n<100||isNaN(n)){let e={instancePath:t+`/pollMs`,schemaPath:`#/oneOf/4/properties/pollMs/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:100},message:`must be >= 100`};a===null?a=[e]:a.push(e),o++}}}}else{let e={instancePath:t,schemaPath:`#/oneOf/4/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}var f=n===o;f&&l?(l=!1,u=[u,4]):f&&(l=!0,u=4)}}}if(l)o=c,a!==null&&(c?a.length=c:a=null);else{let e={instancePath:t,schemaPath:`#/oneOf`,keyword:`oneOf`,params:{passingSchemas:u},message:`must match exactly one schema in oneOf`};a===null?a=[e]:a.push(e),o++}return _.errors=a,o===0}function v(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!=="default"&&n!==`binding`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`boolean`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`boolean`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.default!==void 0&&typeof e.default!=`boolean`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`boolean`},message:`must be boolean`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return v.errors=a,o===0}var y={type:`object`,additionalProperties:!1,required:[`id`,`label`,`type`,`default`,`min`,`max`],properties:{id:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},type:{const:`number`},default:{type:`number`},binding:{$ref:`#/$defs/binding`},min:{type:`number`},max:{type:`number`},step:{type:`number`,exclusiveMinimum:0},group:{$ref:`#/$defs/id`},when:{$ref:`#/$defs/condition`}}};function b(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}if(e.min===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`min`},message:`must have required property 'min'`};a===null?a=[e]:a.push(e),l++}if(e.max===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`max`},message:`must have required property 'max'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(y.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0&&e.type!==`number`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`number`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),l++}if(e.default!==void 0){let n=e.default;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.min!==void 0){let n=e.min;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/min`,schemaPath:`#/properties/min/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.max!==void 0){let n=e.max;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/max`,schemaPath:`#/properties/max/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.step!==void 0){let n=e.step;if(typeof n==`number`&&isFinite(n)){if(n<=0||isNaN(n)){let e={instancePath:t+`/step`,schemaPath:`#/properties/step/exclusiveMinimum`,keyword:`exclusiveMinimum`,params:{comparison:`>`,limit:0},message:`must be > 0`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/step`,schemaPath:`#/properties/step/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return b.errors=a,l===0}var x={type:`object`,additionalProperties:!1,required:[`id`,`label`,`type`,`default`,`min`,`max`],properties:{id:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},type:{const:`slider`},default:{type:`number`},binding:{$ref:`#/$defs/binding`},min:{type:`number`},max:{type:`number`},step:{type:`number`,exclusiveMinimum:0},group:{$ref:`#/$defs/id`},when:{$ref:`#/$defs/condition`}}};function S(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}if(e.min===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`min`},message:`must have required property 'min'`};a===null?a=[e]:a.push(e),l++}if(e.max===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`max`},message:`must have required property 'max'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(x.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0&&e.type!==`slider`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`slider`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),l++}if(e.default!==void 0){let n=e.default;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.min!==void 0){let n=e.min;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/min`,schemaPath:`#/properties/min/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.max!==void 0){let n=e.max;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/max`,schemaPath:`#/properties/max/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.step!==void 0){let n=e.step;if(typeof n==`number`&&isFinite(n)){if(n<=0||isNaN(n)){let e={instancePath:t+`/step`,schemaPath:`#/properties/step/exclusiveMinimum`,keyword:`exclusiveMinimum`,params:{comparison:`>`,limit:0},message:`must be > 0`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/step`,schemaPath:`#/properties/step/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return S.errors=a,l===0}var C={type:`object`,additionalProperties:!1,required:[`id`,`label`,`type`,`default`,`options`],properties:{id:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},type:{enum:[`select`,`radio`,`segmented`]},default:{type:`string`},binding:{$ref:`#/$defs/binding`},options:{$ref:`#/$defs/options`},group:{$ref:`#/$defs/id`},when:{$ref:`#/$defs/condition`}}};function w(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}if(e.options===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`options`},message:`must have required property 'options'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!=="default"&&n!==`binding`&&n!==`options`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0){let n=e.type;if(n!==`select`&&n!==`radio`&&n!==`segmented`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/enum`,keyword:`enum`,params:{allowedValues:C.properties.type.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),o++}}if(e.default!==void 0&&typeof e.default!=`string`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.options!==void 0){let n=e.options;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(e)<1){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}let r=n.length,i;if(r>1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/options`,schemaPath:`#/$defs/options/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return w.errors=a,o===0}function T(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}if(e.options===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`options`},message:`must have required property 'options'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!==`binding`&&n!=="default"&&n!==`options`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`checkboxGroup`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`checkboxGroup`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.default!==void 0){let n=e.default;if(Array.isArray(n)){let e=n.length;for(let r=0;r1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/default`,schemaPath:`#/properties/default/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.options!==void 0){let n=e.options;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(e)<1){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}let r=n.length,i;if(r>1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/options`,schemaPath:`#/$defs/options/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return T.errors=a,o===0}var E={type:`object`,additionalProperties:!1,required:[`id`,`label`,`type`,`default`],properties:{id:{$ref:`#/$defs/id`},label:{$ref:`#/$defs/label`},type:{enum:[`text`,`textarea`]},default:{type:`string`},binding:{$ref:`#/$defs/binding`},minLength:{type:`integer`,minimum:0},maxLength:{type:`integer`,minimum:0},group:{$ref:`#/$defs/id`},when:{$ref:`#/$defs/condition`}}};function D(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(E.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0){let n=e.type;if(n!==`text`&&n!==`textarea`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/enum`,keyword:`enum`,params:{allowedValues:E.properties.type.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),l++}}if(e.default!==void 0&&typeof e.default!=`string`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.minLength!==void 0){let n=e.minLength;if(typeof n!=`number`||n%1||isNaN(n)||!isFinite(n)){let e={instancePath:t+`/minLength`,schemaPath:`#/properties/minLength/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};a===null?a=[e]:a.push(e),l++}if(typeof n==`number`&&isFinite(n)&&(n<0||isNaN(n))){let e={instancePath:t+`/minLength`,schemaPath:`#/properties/minLength/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:0},message:`must be >= 0`};a===null?a=[e]:a.push(e),l++}}if(e.maxLength!==void 0){let n=e.maxLength;if(typeof n!=`number`||n%1||isNaN(n)||!isFinite(n)){let e={instancePath:t+`/maxLength`,schemaPath:`#/properties/maxLength/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};a===null?a=[e]:a.push(e),l++}if(typeof n==`number`&&isFinite(n)&&(n<0||isNaN(n))){let e={instancePath:t+`/maxLength`,schemaPath:`#/properties/maxLength/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:0},message:`must be >= 0`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return D.errors=a,l===0}var O=RegExp(`^#[0-9a-fA-F]{6}$`,`u`);function k(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!=="default"&&n!==`binding`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`color`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`color`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.default!==void 0){let n=e.default;if(typeof n==`string`){if(!O.test(n)){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/pattern`,keyword:`pattern`,params:{pattern:`^#[0-9a-fA-F]{6}$`},message:`must match pattern "^#[0-9a-fA-F]{6}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return k.errors=a,o===0}function A(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!==`binding`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`button`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`button`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return A.errors=a,o===0}function j(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let l=null,u=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.version===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`version`},message:`must have required property 'version'`};l===null?l=[e]:l.push(e),u++}if(e.scope===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`scope`},message:`must have required property 'scope'`};l===null?l=[e]:l.push(e),u++}if(e.controls===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`controls`},message:`must have required property 'controls'`};l===null?l=[e]:l.push(e),u++}for(let n in e)if(!o.call(a.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};l===null?l=[e]:l.push(e),u++}if(e.$schema!==void 0&&typeof e.$schema!=`string`){let e={instancePath:t+`/$schema`,schemaPath:`#/properties/%24schema/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}if(e.version!==void 0&&e.version!==1){let e={instancePath:t+`/version`,schemaPath:`#/properties/version/const`,keyword:`const`,params:{allowedValue:1},message:`must be equal to constant`};l===null?l=[e]:l.push(e),u++}if(e.scope!==void 0){let n=e.scope;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/scope`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/scope`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}if(e.role!==void 0){let n=e.role;if(n!==`shared`&&n!==`page`){let e={instancePath:t+`/role`,schemaPath:`#/properties/role/enum`,keyword:`enum`,params:{allowedValues:a.properties.role.enum},message:`must be equal to one of the allowed values`};l===null?l=[e]:l.push(e),u++}}if(e.container!==void 0){let n=e.container;if(typeof n==`string`){if(s(n)>512){let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/maxLength`,keyword:`maxLength`,params:{limit:512},message:`must NOT have more than 512 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}if(e.panel!==void 0){let n=e.panel;if(n&&typeof n==`object`&&!Array.isArray(n)){if(n.width===void 0){let e={instancePath:t+`/panel`,schemaPath:`#/properties/panel/required`,keyword:`required`,params:{missingProperty:`width`},message:`must have required property 'width'`};l===null?l=[e]:l.push(e),u++}for(let e in n)if(e!==`width`){let n={instancePath:t+`/panel`,schemaPath:`#/properties/panel/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:e},message:`must NOT have additional properties`};l===null?l=[n]:l.push(n),u++}if(n.width!==void 0){let e=n.width;if(typeof e!=`number`||e%1||isNaN(e)||!isFinite(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};l===null?l=[e]:l.push(e),u++}if(typeof e==`number`&&isFinite(e)){if(e>4096||isNaN(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/maximum`,keyword:`maximum`,params:{comparison:`<=`,limit:4096},message:`must be <= 4096`};l===null?l=[e]:l.push(e),u++}if(e<160||isNaN(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:160},message:`must be >= 160`};l===null?l=[e]:l.push(e),u++}}}}else{let e={instancePath:t+`/panel`,schemaPath:`#/properties/panel/type`,keyword:`type`,params:{type:`object`},message:`must be object`};l===null?l=[e]:l.push(e),u++}}if(e.groups!==void 0){let n=e.groups;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/groups`,schemaPath:`#/properties/groups/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};l===null?l=[e]:l.push(e),u++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/groups/`+r+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(l=l===null?f.errors:l.concat(f.errors),u=l.length))}else{let e={instancePath:t+`/groups/`+r,schemaPath:`#/properties/groups/items/type`,keyword:`type`,params:{type:`object`},message:`must be object`};l===null?l=[e]:l.push(e),u++}}}else{let e={instancePath:t+`/groups`,schemaPath:`#/properties/groups/type`,keyword:`type`,params:{type:`array`},message:`must be array`};l===null?l=[e]:l.push(e),u++}}if(e.controls!==void 0){let n=e.controls;if(Array.isArray(n)){if(n.length>500){let e={instancePath:t+`/controls`,schemaPath:`#/properties/controls/maxItems`,keyword:`maxItems`,params:{limit:500},message:`must NOT have more than 500 items`};l===null?l=[e]:l.push(e),u++}let e=n.length;for(let r=0;r100){let e={instancePath:t+`/sets`,schemaPath:`#/properties/sets/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/sets`,schemaPath:`#/properties/sets/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}if(e.role!==void 0){let n=e.role;if(n!==`shared`&&n!==`page`){let e={instancePath:t+`/role`,schemaPath:`#/properties/role/enum`,keyword:`enum`,params:{allowedValues:a.properties.role.enum},message:`must be equal to one of the allowed values`};l===null?l=[e]:l.push(e),u++}}if(e.container!==void 0){let n=e.container;if(typeof n==`string`){if(s(n)>512){let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/maxLength`,keyword:`maxLength`,params:{limit:512},message:`must NOT have more than 512 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/container`,schemaPath:`#/$defs/selector/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}if(e.panel!==void 0){let n=e.panel;if(n&&typeof n==`object`&&!Array.isArray(n)){if(n.width===void 0){let e={instancePath:t+`/panel`,schemaPath:`#/properties/panel/required`,keyword:`required`,params:{missingProperty:`width`},message:`must have required property 'width'`};l===null?l=[e]:l.push(e),u++}for(let e in n)if(e!==`width`){let n={instancePath:t+`/panel`,schemaPath:`#/properties/panel/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:e},message:`must NOT have additional properties`};l===null?l=[n]:l.push(n),u++}if(n.width!==void 0){let e=n.width;if(typeof e!=`number`||e%1||isNaN(e)||!isFinite(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};l===null?l=[e]:l.push(e),u++}if(typeof e==`number`&&isFinite(e)){if(e>4096||isNaN(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/maximum`,keyword:`maximum`,params:{comparison:`<=`,limit:4096},message:`must be <= 4096`};l===null?l=[e]:l.push(e),u++}if(e<160||isNaN(e)){let e={instancePath:t+`/panel/width`,schemaPath:`#/properties/panel/properties/width/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:160},message:`must be >= 160`};l===null?l=[e]:l.push(e),u++}}}}else{let e={instancePath:t+`/panel`,schemaPath:`#/properties/panel/type`,keyword:`type`,params:{type:`object`},message:`must be object`};l===null?l=[e]:l.push(e),u++}}if(e.groups!==void 0){let n=e.groups;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/groups`,schemaPath:`#/properties/groups/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};l===null?l=[e]:l.push(e),u++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};l===null?l=[e]:l.push(e),u++}if(s(n)<1){let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};l===null?l=[e]:l.push(e),u++}}else{let e={instancePath:t+`/groups/`+r+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};l===null?l=[e]:l.push(e),u++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/groups/`+r+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(l=l===null?f.errors:l.concat(f.errors),u=l.length))}else{let e={instancePath:t+`/groups/`+r,schemaPath:`#/properties/groups/items/type`,keyword:`type`,params:{type:`object`},message:`must be object`};l===null?l=[e]:l.push(e),u++}}}else{let e={instancePath:t+`/groups`,schemaPath:`#/properties/groups/type`,keyword:`type`,params:{type:`array`},message:`must be array`};l===null?l=[e]:l.push(e),u++}}if(e.controls!==void 0){let n=e.controls;if(Array.isArray(n)){if(n.length>500){let e={instancePath:t+`/controls`,schemaPath:`#/properties/controls/maxItems`,keyword:`maxItems`,params:{limit:500},message:`must NOT have more than 500 items`};l===null?l=[e]:l.push(e),u++}let e=n.length;for(let r=0;r100){let e={instancePath:t+`/sets`,schemaPath:`#/properties/sets/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/sets`,schemaPath:`#/properties/sets/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`boolean`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`boolean`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.default!==void 0&&typeof e.default!=`boolean`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`boolean`},message:`must be boolean`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return L.errors=a,o===0}e.number=R;function R(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}if(e.min===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`min`},message:`must have required property 'min'`};a===null?a=[e]:a.push(e),l++}if(e.max===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`max`},message:`must have required property 'max'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(y.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0&&e.type!==`number`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`number`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),l++}if(e.default!==void 0){let n=e.default;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.min!==void 0){let n=e.min;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/min`,schemaPath:`#/properties/min/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.max!==void 0){let n=e.max;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/max`,schemaPath:`#/properties/max/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.step!==void 0){let n=e.step;if(typeof n==`number`&&isFinite(n)){if(n<=0||isNaN(n)){let e={instancePath:t+`/step`,schemaPath:`#/properties/step/exclusiveMinimum`,keyword:`exclusiveMinimum`,params:{comparison:`>`,limit:0},message:`must be > 0`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/step`,schemaPath:`#/properties/step/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return R.errors=a,l===0}e.slider=z;function z(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}if(e.min===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`min`},message:`must have required property 'min'`};a===null?a=[e]:a.push(e),l++}if(e.max===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`max`},message:`must have required property 'max'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(x.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0&&e.type!==`slider`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`slider`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),l++}if(e.default!==void 0){let n=e.default;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.min!==void 0){let n=e.min;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/min`,schemaPath:`#/properties/min/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.max!==void 0){let n=e.max;if(!(typeof n==`number`&&isFinite(n))){let e={instancePath:t+`/max`,schemaPath:`#/properties/max/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.step!==void 0){let n=e.step;if(typeof n==`number`&&isFinite(n)){if(n<=0||isNaN(n)){let e={instancePath:t+`/step`,schemaPath:`#/properties/step/exclusiveMinimum`,keyword:`exclusiveMinimum`,params:{comparison:`>`,limit:0},message:`must be > 0`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/step`,schemaPath:`#/properties/step/type`,keyword:`type`,params:{type:`number`},message:`must be number`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return z.errors=a,l===0}e.choice=ee;function ee(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}if(e.options===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`options`},message:`must have required property 'options'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!=="default"&&n!==`binding`&&n!==`options`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0){let n=e.type;if(n!==`select`&&n!==`radio`&&n!==`segmented`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/enum`,keyword:`enum`,params:{allowedValues:C.properties.type.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),o++}}if(e.default!==void 0&&typeof e.default!=`string`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.options!==void 0){let n=e.options;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(e)<1){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}let r=n.length,i;if(r>1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/options`,schemaPath:`#/$defs/options/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return ee.errors=a,o===0}e.checkboxGroup=B;function B(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}if(e.options===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`options`},message:`must have required property 'options'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!==`binding`&&n!=="default"&&n!==`options`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`checkboxGroup`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`checkboxGroup`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.default!==void 0){let n=e.default;if(Array.isArray(n)){let e=n.length;for(let r=0;r1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/default`,schemaPath:`#/properties/default/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.options!==void 0){let n=e.options;if(Array.isArray(n)){if(n.length>100){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/maxItems`,keyword:`maxItems`,params:{limit:100},message:`must NOT have more than 100 items`};a===null?a=[e]:a.push(e),o++}if(n.length<1){let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/minItems`,keyword:`minItems`,params:{limit:1},message:`must NOT have fewer than 1 items`};a===null?a=[e]:a.push(e),o++}let e=n.length;for(let r=0;r200){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(e)<1){let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/options/`+r,schemaPath:`#/$defs/options/items/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}let r=n.length,i;if(r>1){let e={};for(;r--;){let s=n[r];if(typeof s==`string`){if(typeof e[s]==`number`){i=e[s];let n={instancePath:t+`/options`,schemaPath:`#/$defs/options/uniqueItems`,keyword:`uniqueItems`,params:{i:r,j:i},message:`must NOT have duplicate items (items ## `+i+` and `+r+` are identical)`};a===null?a=[n]:a.push(n),o++;break}e[s]=r}}}}else{let e={instancePath:t+`/options`,schemaPath:`#/$defs/options/type`,keyword:`type`,params:{type:`array`},message:`must be array`};a===null?a=[e]:a.push(e),o++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return B.errors=a,o===0}e.text=te;function te(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,l=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),l++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),l++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),l++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),l++}for(let n in e)if(!o.call(E.properties,n)){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),l++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),l++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}if(e.type!==void 0){let n=e.type;if(n!==`text`&&n!==`textarea`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/enum`,keyword:`enum`,params:{allowedValues:E.properties.type.enum},message:`must be equal to one of the allowed values`};a===null?a=[e]:a.push(e),l++}}if(e.default!==void 0&&typeof e.default!=`string`){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),l=a.length)),e.minLength!==void 0){let n=e.minLength;if(typeof n!=`number`||n%1||isNaN(n)||!isFinite(n)){let e={instancePath:t+`/minLength`,schemaPath:`#/properties/minLength/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};a===null?a=[e]:a.push(e),l++}if(typeof n==`number`&&isFinite(n)&&(n<0||isNaN(n))){let e={instancePath:t+`/minLength`,schemaPath:`#/properties/minLength/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:0},message:`must be >= 0`};a===null?a=[e]:a.push(e),l++}}if(e.maxLength!==void 0){let n=e.maxLength;if(typeof n!=`number`||n%1||isNaN(n)||!isFinite(n)){let e={instancePath:t+`/maxLength`,schemaPath:`#/properties/maxLength/type`,keyword:`type`,params:{type:`integer`},message:`must be integer`};a===null?a=[e]:a.push(e),l++}if(typeof n==`number`&&isFinite(n)&&(n<0||isNaN(n))){let e={instancePath:t+`/maxLength`,schemaPath:`#/properties/maxLength/minimum`,keyword:`minimum`,params:{comparison:`>=`,limit:0},message:`must be >= 0`};a===null?a=[e]:a.push(e),l++}}if(e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),l++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),l++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),l=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),l++}return te.errors=a,l===0}e.color=ne;function ne(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}if(e.default===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`default`},message:`must have required property 'default'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!=="default"&&n!==`binding`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`color`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`color`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.default!==void 0){let n=e.default;if(typeof n==`string`){if(!O.test(n)){let e={instancePath:t+`/default`,schemaPath:`#/properties/default/pattern`,keyword:`pattern`,params:{pattern:`^#[0-9a-fA-F]{6}$`},message:`must match pattern "^#[0-9a-fA-F]{6}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/default`,schemaPath:`#/properties/default/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return ne.errors=a,o===0}e.button=re;function re(e,{instancePath:t=``,parentData:n,parentDataProperty:r,rootData:i=e}={}){let a=null,o=0;if(e&&typeof e==`object`&&!Array.isArray(e)){if(e.id===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`id`},message:`must have required property 'id'`};a===null?a=[e]:a.push(e),o++}if(e.label===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`label`},message:`must have required property 'label'`};a===null?a=[e]:a.push(e),o++}if(e.type===void 0){let e={instancePath:t,schemaPath:`#/required`,keyword:`required`,params:{missingProperty:`type`},message:`must have required property 'type'`};a===null?a=[e]:a.push(e),o++}for(let n in e)if(n!==`id`&&n!==`label`&&n!==`type`&&n!==`binding`&&n!==`group`&&n!==`when`){let e={instancePath:t,schemaPath:`#/additionalProperties`,keyword:`additionalProperties`,params:{additionalProperty:n},message:`must NOT have additional properties`};a===null?a=[e]:a.push(e),o++}if(e.id!==void 0){let n=e.id;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/id`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.label!==void 0){let n=e.label;if(typeof n==`string`){if(s(n)>200){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/maxLength`,keyword:`maxLength`,params:{limit:200},message:`must NOT have more than 200 characters`};a===null?a=[e]:a.push(e),o++}if(s(n)<1){let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/minLength`,keyword:`minLength`,params:{limit:1},message:`must NOT have fewer than 1 characters`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/label`,schemaPath:`#/$defs/label/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}if(e.type!==void 0&&e.type!==`button`){let e={instancePath:t+`/type`,schemaPath:`#/properties/type/const`,keyword:`const`,params:{allowedValue:`button`},message:`must be equal to constant`};a===null?a=[e]:a.push(e),o++}if(e.binding!==void 0&&(_(e.binding,{instancePath:t+`/binding`,parentData:e,parentDataProperty:`binding`,rootData:i})||(a=a===null?_.errors:a.concat(_.errors),o=a.length)),e.group!==void 0){let n=e.group;if(typeof n==`string`){if(!c.test(n)){let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/pattern`,keyword:`pattern`,params:{pattern:`^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`},message:`must match pattern "^[a-zA-Z][a-zA-Z0-9_-]{0,63}$"`};a===null?a=[e]:a.push(e),o++}}else{let e={instancePath:t+`/group`,schemaPath:`#/$defs/id/type`,keyword:`type`,params:{type:`string`},message:`must be string`};a===null?a=[e]:a.push(e),o++}}e.when!==void 0&&(f(e.when,{instancePath:t+`/when`,parentData:e,parentDataProperty:`when`,rootData:i})||(a=a===null?f.errors:a.concat(f.errors),o=a.length))}else{let e={instancePath:t,schemaPath:`#/type`,keyword:`type`,params:{type:`object`},message:`must be object`};a===null?a=[e]:a.push(e),o++}return re.errors=a,o===0}}))(),1),{validateDocumentShape:Ie,validateDeclaration:Le}=Fe.default,Re={boolean:`boolean`,number:`number`,slider:`slider`,select:`choice`,radio:`choice`,segmented:`choice`,checkboxGroup:`checkboxGroup`,text:`text`,textarea:`text`,color:`color`,button:`button`};function Z(e){let t=[...Le.errors].filter(e=>!/^\/controls\/\d+(?:\/|$)/.test(e.instancePath)).map(e=>({...e}));return Array.isArray(e?.controls)&&e.controls.forEach((e,n)=>{let r=Object.hasOwn(Re,e?.type)?Re[e.type]:void 0,i=r&&Fe.default[r];i?i(e)||t.push(...i.errors.map(e=>({...e,instancePath:`/controls/${n}${e.instancePath}`}))):t.push({instancePath:`/controls/${n}/type`,message:`must name a supported control type`})}),t.map(e=>({path:e.instancePath,message:e.keyword===`additionalProperties`?`${e.message}: "${e.params.additionalProperty}"`:e.message,keyword:e.keyword,params:e.params}))}var ze=class extends Error{constructor(e){super(`Invalid controls.replica.json:\n${e.map(e=>` ${e.path||`/`}: ${e.message}`).join(` +`)}`),this.name=`ControlsValidationError`,this.issues=e}};function Be(e,t){switch(e.type){case`boolean`:return typeof t==`boolean`?null:`must be a boolean`;case`number`:case`slider`:{if(typeof t!=`number`||!Number.isFinite(t))return`must be a finite number`;if(e.min!==void 0&&t= min`;if(e.max!==void 0&&t>e.max)return`must be <= max`;let n=(t-e.min)/(e.step??1);return!Number.isFinite(n)||Math.abs(n-Math.round(n))>1e-8?`must align with step (anchored at min)`:null}case`select`:case`radio`:case`segmented`:return e.options.includes(t)?null:`must be a declared option`;case`checkboxGroup`:return Array.isArray(t)&&new Set(t).size===t.length&&t.every(t=>e.options.includes(t))?null:`must be unique declared options`;case`text`:case`textarea`:return typeof t==`string`?e.minLength!==void 0&&[...t].lengthe.maxLength?`longer than maxLength`:null:`must be a string`;case`color`:return typeof t==`string`&&/^#[0-9a-fA-F]{6}$/.test(t)?null:`must be a six-digit hex color`;default:return`button controls have no value`}}function Ve(e){return e?e.control?[e.control]:(e.all??e.any).flatMap(Ve):[]}function He(e){let t=new Map((e.groups??[]).map(e=>[e.id,e])),n=new Map(e.controls.map(e=>[e.id,e])),r=new Set,i=new Set,a=[];function o(e){if(r.has(e))return;if(i.has(e))throw new ze([{path:`/controls/${e}/when`,message:`conditional dependency cycle (including groups)`}]);i.add(e);let s=n.get(e);for(let e of[...Ve(s.when),...Ve(t.get(s.group)?.when)])o(e);i.delete(e),r.add(e),a.push(e)}for(let e of n.keys())o(e);return a}function Ue(e){let t=new Set;function n(e,r=0){if(r>24)throw new ze([{path:`/`,message:`document nesting exceeds 24`}]);if(typeof e==`number`&&!Number.isFinite(e))throw new ze([{path:`/`,message:`numbers must be finite`}]);if(![`string`,`number`,`boolean`,`object`].includes(typeof e))throw new ze([{path:`/`,message:`must contain only JSON values`}]);if(e&&typeof e==`object`){if(!Array.isArray(e)&&Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw new ze([{path:`/`,message:`must contain only JSON objects`}]);if(t.has(e))throw new ze([{path:`/`,message:`must be an acyclic JSON document`}]);t.add(e);for(let t of Object.values(e))n(t,r+1);t.delete(e)}}n(e)}function We(e){if(Ue(e),!Le(e))throw new ze(Z(e));let t=[];function n(e,n){t.push({path:e,message:n})}let r=new Set,i=new Map((e.groups??[]).map(e=>[e.id,e])),a=new Map(e.controls.map(e=>[e.id,e]));for(let[t,i]of[[`groups`,e.groups??[]],[`controls`,e.controls]])i.forEach((e,i)=>{r.has(e.id)&&n(`/${t}/${i}/id`,`duplicate ID ${e.id}`),r.add(e.id)});function o(e,t,r=0){if(!e)return;if(r>4){n(t,`conditions support at most five levels`);return}if(e.all||e.any){let n=e.all?`all`:`any`;e[n].forEach((e,i)=>o(e,`${t}/${n}/${i}`,r+1));return}let i=a.get(e.control);if(!i||i.type===`button`)n(t,`condition must reference a value control`);else if(`includes`in e)(i.type!==`checkboxGroup`||!i.options.includes(e.includes))&&n(t,`includes requires a declared checkboxGroup option`);else if(i.type===`checkboxGroup`)n(t,`checkboxGroup conditions must use includes`);else for(let r of`in`in e?e.in:[e.equals]){let e=Be(i,r);e&&n(t,`invalid condition for ${i.id}: ${e}`)}}if(e.controls.forEach((e,t)=>{let r=`/controls/${t}`;if(e.group&&!i.has(e.group)&&n(`${r}/group`,`unknown group`),e.min!==void 0&&e.max!==void 0&&e.min>e.max&&n(r,`min must not exceed max`),e.minLength!==void 0&&e.maxLength!==void 0&&e.minLength>e.maxLength&&n(r,`minLength must not exceed maxLength`),e.type===`segmented`&&e.options.length>3&&n(`${r}/options`,`segmented supports at most three options`),e.type!==`button`){let t=Be(e,e.default);t&&n(`${r}/default`,t)}o(e.when,`${r}/when`)}),(e.groups??[]).forEach((e,t)=>o(e.when,`/groups/${t}/when`)),t.length)throw new ze(t);return He(e),e}function Ge(e,t){let[n,r]=(0,V.useState)(e),[i,a]=(0,V.useState)(null),o=(0,V.useRef)(e),s=(0,V.useRef)(e),c=(0,V.useRef)(0),l=(0,V.useRef)(!1);(0,V.useLayoutEffect)(()=>{s.current=e,l.current||(o.current=e,r(e))},[e]),(0,V.useLayoutEffect)(()=>()=>{c.current++},[]);function u(e){c.current++,l.current=!0,o.current=e,r(e),a(null)}function d(){c.current++,l.current=!1,o.current=s.current,r(s.current),a(null)}function f(e,n=e){u(e);let i=c.current;Promise.resolve().then(()=>t(n)).then(e=>{c.current===i&&(l.current=!1,o.current=e&&`value`in e?e.value:s.current,r(o.current))}).catch(()=>{c.current===i&&(d(),a(K.controlsValueNotApplied))})}return{draft:n,error:i,current:()=>o.current,stage:u,commit:f,reset:d}}function Ke(e){let t=e.step??1,n=Math.max(...[e.min,e.max,t].map(e=>{let[t=``,n=`0`]=String(e).split(`e`);return Math.max(0,(t.split(`.`)[1]?.length??0)-Number(n))})),r=Math.max(...[e.min,e.max].map(e=>n<=100?e.toFixed(n).length:String(e).length),String(e.default).length,String(t).length);return e.type===`slider`?`calc(${r}ch + var(--hub-space-8) * 2)`:`calc(${r}ch + var(--hub-space-8) * 2 + 1.25rem)`}function qe({id:e,control:t,value:n,disabled:r,message:i,onCommit:a}){let o=Ge(n,a),[s,c]=(0,V.useState)(null);function l(e){let n=e.target.value,r=t.type===`number`||t.type===`slider`?n===``?NaN:Number(n):n,i=Be(t,r);c(i),i?o.stage(n):o.commit(n,r)}let u=s||o.error,d=t.type===`number`||t.type===`slider`,f=t.type===`slider`?{"--controls-slider-progress":`${t.min===t.max?100:(Number(n)-t.min)/(t.max-t.min)*100}%`}:void 0,p=[i?`${e}-hint`:void 0,u?`${e}-validation`:void 0].filter(Boolean).join(` `)||void 0,m={id:e,disabled:r,value:String(o.draft),onChange:l,"aria-invalid":u?!0:void 0,"aria-describedby":p,onBlur:()=>{s&&(o.reset(),c(null))}},h;return h=t.type===`textarea`?(0,U.jsx)(H.Textarea,{...m,rows:2,resize:`vertical`}):d?(0,U.jsx)(H.TextInput,{...m,className:t.type===`slider`?`controls-number-input controls-number-input--slider`:`controls-number-input`,type:`number`,min:t.min,max:t.max,step:t.step??1,validationStatus:u?`error`:void 0,"aria-labelledby":`${e}-label`,style:{width:Ke(t)}}):t.type===`color`?(0,U.jsx)(`input`,{...m,className:`controls-native-color`,type:`color`}):(0,U.jsx)(H.TextInput,{...m,type:`text`}),(0,U.jsxs)(H.FormControl,{id:e,className:d?`controls-field controls-field--${t.type}`:`controls-field`,fullWidth:!d||t.type===`slider`,validationStatus:u?`error`:void 0,children:[d?(0,U.jsxs)(`div`,{className:`controls-field-heading`,children:[(0,U.jsx)(H.FormControl.Label,{id:`${e}-label`,htmlFor:e,className:`controls-field-label`,children:t.label}),t.type===`slider`?(0,U.jsxs)(`div`,{className:`controls-slider-row`,children:[(0,U.jsx)(`input`,{...m,id:`${e}-slider`,value:String(n),className:`controls-native-slider`,type:`range`,style:f,min:t.min,max:t.max,step:t.step??1,"aria-labelledby":`${e}-label`}),h]}):h]}):(0,U.jsx)(H.FormControl.Label,{className:`controls-field-label`,children:t.label}),d?null:h,i?(0,U.jsx)(H.FormControl.Hint,{children:(0,U.jsx)(`span`,{role:`status`,children:i})}):null,u?(0,U.jsx)(H.FormControl.Validation,{className:`controls-field-validation`,"aria-live":`polite`,children:u}):null]})}function Je({id:e,control:t,value:n,disabled:r,message:i,onCommit:a}){let o=Ge(n,a),s=[i?`${e}-unavailable`:void 0,o.error?`${e}-validation`:void 0].filter(Boolean).join(` `)||void 0;if(t.type===`boolean`||t.type===`select`)return(0,U.jsxs)(H.FormControl,{id:e,className:t.type===`boolean`?`controls-field controls-choice-row`:`controls-field controls-field--select`,fullWidth:t.type===`boolean`,validationStatus:o.error?`error`:void 0,children:[t.type===`select`?(0,U.jsx)(H.FormControl.Label,{className:`controls-field-label`,children:t.label}):null,t.type===`boolean`?(0,U.jsx)(H.Checkbox,{className:`controls-choice-mark`,disabled:r,"aria-describedby":s,checked:o.draft===!0,onChange:e=>o.commit(e.target.checked)}):(0,U.jsx)(H.Select,{className:`controls-select-input`,disabled:r,"aria-describedby":s,value:o.draft,onChange:e=>o.commit(e.target.value),children:t.options.map(e=>(0,U.jsx)(H.Select.Option,{value:e,children:e},e))}),t.type===`boolean`?(0,U.jsx)(H.FormControl.Label,{className:`controls-choice-label`,children:t.label}):null,i?(0,U.jsx)(H.FormControl.Hint,{children:(0,U.jsx)(`span`,{role:`status`,children:i})}):null,o.error?(0,U.jsx)(H.FormControl.Validation,{className:`controls-field-validation`,"aria-live":`polite`,children:o.error}):null]});let c=t.type===`checkboxGroup`,l=t.type===`segmented`,u=c?H.CheckboxGroup:H.RadioGroup,d=c?H.Checkbox:H.Radio;return(0,U.jsxs)(u,{id:e,className:`controls-field`,"aria-disabled":r||void 0,"aria-describedby":s,children:[(0,U.jsx)(u.Label,{className:`controls-choice-group-label`,children:t.label}),(0,U.jsx)(`div`,{className:l?`controls-segments`:`controls-options`,children:t.options.map((t,n)=>{let i=`${e}-${n}`,a=c?o.draft.includes(t):o.draft===t,u=(0,U.jsx)(d,{className:c?`controls-choice-mark`:`controls-choice-mark controls-choice-mark--radio`,id:i,name:e,value:t,checked:a,disabled:r,"aria-describedby":s,onChange:e=>{let n=o.current();o.commit(c?e.target.checked?[...n,t]:n.filter(e=>e!==t):t)}});return l?(0,U.jsxs)(`label`,{htmlFor:i,className:`controls-segment`,title:t,children:[(0,U.jsx)(ue,{children:u}),(0,U.jsx)(H.Text,{as:`span`,size:`100`,weight:`medium`,children:t})]},t):(0,U.jsxs)(H.FormControl,{id:i,className:`controls-field controls-choice-row`,children:[u,(0,U.jsx)(H.FormControl.Label,{className:`controls-choice-label`,children:t})]},t)})}),i?(0,U.jsx)(H.Text,{as:`span`,id:`${e}-unavailable`,size:`100`,variant:`muted`,role:`status`,children:i}):null,o.error?(0,U.jsx)(u.Validation,{variant:`error`,role:`status`,children:o.error}):null]})}function Ye(e,t){let n=e.snapshot.bindings?.[t.id],r=e.snapshot.actions[t.id];return{scope:e.declaration.scope,id:t.id,visible:e.snapshot.visible[t.id]===!0,available:(t.type!==`button`||r?.available===!0)&&(!n?.error||n.available===!0),busy:n?.busy===!0||r?.busy===!0,error:n?.error||(t.type===`button`&&!r?.available?K.controlsActionUnavailable:``)}}function Xe({scopes:e,disabled:t=!1,onCommand:n,collapsedGroups:r,onGroupCollapse:i}){let a=(0,V.useId)(),o=(0,V.useRef)(null),s=(0,V.useRef)(null),[c,l]=(0,V.useState)({});(0,V.useLayoutEffect)(()=>{s.current&&!s.current.isConnected&&(document.activeElement===document.body&&o.current?.focus(),s.current=null)},[e]);function u(e,r){if(!e.snapshot.visible[r.id])return null;let i=`${a}-${e.declaration.scope}-${r.id}`,o=e.snapshot.values[r.id];function s(t){return n(`update`,e.declaration.scope,r.id,t)}let c=e.snapshot.bindings?.[r.id],l=Ye(e,r),u={id:i,message:l.error?l.available?K.controlsNotApplied(r.label):K.controlsUnavailable(r.label):void 0,disabled:t||!!c?.error&&c?.available!==!0||c?.busy===!0};switch(r.type){case`button`:{let t=e.snapshot.actions[r.id];return(0,U.jsx)(`div`,{className:`controls-field controls-action-field`,children:(0,U.jsxs)(H.Button,{type:`button`,size:`small`,variant:`secondary`,className:`controls-action-button`,disabled:u.disabled||!t?.available||t.busy,"aria-describedby":u.message?`${i}-unavailable`:void 0,"aria-busy":t?.busy,onClick:()=>{n(`action`,e.declaration.scope,r.id)},children:[r.label,t?.busy?K.controlsActionBusy:``]})},r.id)}case`boolean`:case`select`:case`radio`:case`segmented`:case`checkboxGroup`:return(0,U.jsx)(Je,{...u,control:r,value:o,onCommit:s},r.id);case`number`:case`slider`:case`text`:case`textarea`:case`color`:return(0,U.jsx)(qe,{...u,control:r,value:o,onCommit:s},r.id)}}function d(e,t){if(!e.snapshot.visible[t.id])return null;let n=Ye(e,t);return(0,U.jsxs)(V.Fragment,{children:[u(e,t),t.type===`button`&&n.error?(0,U.jsx)(H.Text,{as:`p`,id:`${a}-${e.declaration.scope}-${t.id}-unavailable`,size:`100`,variant:`muted`,role:`status`,children:n.available?K.controlsNotApplied(t.label):K.controlsUnavailable(t.label)}):null]},t.id)}let f=[...e.filter(e=>e.declaration.role===`shared`),...e.filter(e=>e.declaration.role!==`shared`)].filter(e=>e.declaration.controls.some(t=>t.group?e.snapshot.groups[t.group]:e.snapshot.visible[t.id]));return(0,U.jsx)(`div`,{ref:o,tabIndex:-1,role:`region`,"aria-label":K.controlsRegion,className:`controls-fields`,onFocusCapture:e=>{s.current=e.target},children:f.map((e,t)=>{let n=new Set;return(0,U.jsxs)(`section`,{className:`controls-scope`,"aria-label":e.declaration.label??e.declaration.scope,children:[t>0?(0,U.jsx)(`hr`,{className:`controls-scope-divider`}):null,e.declaration.controls.map(t=>{if(!t.group)return d(e,t);if(n.has(t.group))return null;n.add(t.group);let o=e.declaration.groups?.find(e=>e.id===t.group);if(!o||!e.snapshot.groups[o.id])return null;let s=`${e.declaration.scope}/${o.id}`,u=(r??c)[s]===!0,f=`${a}-${e.declaration.scope}-${o.id}-group`;return(0,U.jsxs)(`fieldset`,{className:`controls-group`,"aria-label":o.label,children:[(0,U.jsx)(`legend`,{children:(0,U.jsx)(H.Button,{size:`small`,variant:`subtle`,type:`button`,block:!0,className:`controls-group-toggle controls-ghost-button`,"aria-label":u?K.controlsExpandGroup(o.label):K.controlsCollapseGroup(o.label),"aria-controls":f,"aria-expanded":!u,trailingVisual:u?(0,U.jsx)(p,{size:16}):(0,U.jsx)(g,{size:16}),onClick:t=>{t.currentTarget.focus(),i?i(e.declaration.scope,o.id,!u):l(e=>({...e,[s]:!u}))},children:(0,U.jsx)(H.Text,{as:`span`,size:`100`,weight:`bold`,variant:`muted`,className:`controls-group-label`,children:o.label})})}),(0,U.jsx)(`div`,{id:f,className:`controls-group-body`,hidden:u,children:e.declaration.controls.filter(e=>e.group===o.id).map(t=>d(e,t))})]},o.id)})]},e.declaration.scope)})})}function Ze(e){return Object.fromEntries(e.declaration.controls.filter(t=>t.type!==`button`&&e.snapshot.visible[t.id]&&JSON.stringify(e.snapshot.values[t.id])!==JSON.stringify(t.default)).map(t=>[t.id,e.snapshot.values[t.id]]))}function Qe(e,t){let n=(0,V.useRef)(null),r=(0,V.useRef)(null),i=(0,V.useRef)(null),a=(0,V.useRef)({position:e,onChange:t}),o=(0,V.useRef)(null),[s,c]=(0,V.useState)(!1);(0,V.useLayoutEffect)(()=>{a.current={position:e,onChange:t}});let l=(0,V.useCallback)(e=>{let t=n.current?.getBoundingClientRect(),i=r.current?.getBoundingClientRect();if(!t||!i||!t.width||!t.height)return;let o={x:Math.max(0,Math.min(e.x,Math.max(0,t.width-i.width))),y:Math.max(0,Math.min(e.y,Math.max(0,t.height-i.height)))};(a.current.position?.x!==o.x||a.current.position?.y!==o.y)&&a.current.onChange(o)},[]);(0,V.useLayoutEffect)(()=>{let e=n.current,t=r.current;if(!e||!t)return;function i(){let n=e?.getBoundingClientRect(),r=t?.getBoundingClientRect();if(!n||!r||!n.width||!n.height)return;let i=r.left-n.left,a=r.top-n.top;(i<0||a<0||i>Math.max(0,n.width-r.width)||a>Math.max(0,n.height-r.height))&&l({x:i,y:a})}let a=new ResizeObserver(i);return a.observe(e),a.observe(t),window.addEventListener(`resize`,i),i(),()=>{a.disconnect(),window.removeEventListener(`resize`,i)}},[l]);function u(e=!1){let t=o.current;o.current=null,c(!1),t&&(e&&l(t.origin),i.current?.hasPointerCapture(t.pointerId)&&i.current.releasePointerCapture(t.pointerId))}return{boundsRef:n,panelRef:r,handleRef:i,dragging:s,onPointerDown:e=>{if(e.button!==0||o.current)return;let t=n.current?.getBoundingClientRect(),i=r.current?.getBoundingClientRect();t&&i&&(o.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY,origin:{x:i.left-t.left,y:i.top-t.top}},e.currentTarget.setPointerCapture(e.pointerId),e.currentTarget.focus(),e.preventDefault(),c(!0))},onPointerMove:e=>{let t=o.current;t&&t.pointerId===e.pointerId&&l({x:t.origin.x+e.clientX-t.x,y:t.origin.y+e.clientY-t.y})},onPointerUp:e=>{o.current?.pointerId===e.pointerId&&u()},onPointerCancel:e=>{o.current?.pointerId===e.pointerId&&u(!0)},onLostPointerCapture:()=>{o.current&&u()},onKeyDown:e=>{if(e.key===`Escape`&&o.current){e.preventDefault(),u(!0);return}if(![`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`].includes(e.key))return;let t=n.current?.getBoundingClientRect(),i=r.current?.getBoundingClientRect();if(!t||!i)return;e.preventDefault();let a=e.shiftKey?1:10;l({x:i.left-t.left+(e.key===`ArrowLeft`?-a:e.key===`ArrowRight`?a:0),y:i.top-t.top+(e.key===`ArrowUp`?-a:e.key===`ArrowDown`?a:0)})}}}function $e(e){let t=e.filter(e=>e.declaration.role!==`shared`),n=t.length?t:e;return n.length?Math.max(...n.map(e=>e.declaration.panel?.width??288)):288}function et({state:e,connection:t,layout:n,onLayoutChange:r,onDiagnose:i,diagnosisTarget:a=``}){let o=e.loading?[]:e.scopes.flatMap(e=>e.declaration.controls.flatMap(t=>{let n=Ye(e,t);return n.visible&&n.error?[{...n,label:t.label}]:[]})),s=!!(i&&!e.loading&&(!e.runtimeAvailable&&e.error||e.storageError||o.length||e.reconnectRequired||e.status===`missing-runtime`||e.status===`unsupported-runtime`||e.status===`invalid-config`)),c=s?JSON.stringify([a,e.status,e.runtimeAvailable,e.reconnectRequired,e.error,e.storageError,o.map(({scope:e,id:t,error:n})=>[e,t,n])]):``,[l,d]=(0,V.useState)(()=>({episode:c,identity:{},busy:!1,requested:!1,error:``}));l.episode!==c&&d({episode:c,identity:{},busy:!1,requested:!1,error:``});async function f(){if(!i||!s||l.busy||l.requested)return;let e=l.identity;d(t=>t.identity===e?{...t,busy:!0,error:``}:t);try{await i(),d(t=>t.identity===e?{...t,requested:!0}:t)}catch(t){d(n=>n.identity===e?{...n,error:t instanceof Error?t.message:K.controlsDiagnosisFailed}:n)}finally{d(t=>t.identity===e?{...t,busy:!1}:t)}}let p=(0,V.useId)(),m=(0,V.useId)(),_=(0,V.useRef)(null),{boundsRef:v,panelRef:y,handleRef:b,dragging:x,onPointerDown:S,onPointerMove:C,onPointerUp:w,onPointerCancel:T,onLostPointerCapture:E,onKeyDown:D}=Qe(n.position,e=>r(t=>({...t,position:e})));(0,V.useEffect)(()=>{b.current?.focus()},[b]),(0,V.useLayoutEffect)(()=>{_.current&&!_.current.isConnected&&(document.activeElement===document.body&&b.current?.focus(),_.current=null)},[e,b]);let O=e.loading?K.controlsConnecting:e.status===`no-controls`?K.controlsEmpty:e.status===`missing-runtime`?i?K.controlsLocalMissingRuntime:K.controlsMissingRuntime:e.status===`unsupported-runtime`?K.controlsUnsupportedRuntime:e.status===`invalid-config`?K.controlsInvalid:``,k=!e.loading&&(e.storageError||e.reconnectRequired||!e.runtimeAvailable&&e.error),A=!e.loading&&e.status===`no-controls`&&!e.error&&!e.storageError&&!e.reconnectRequired&&!e.scopeErrors?.length&&!e.scopes.length;return(0,U.jsx)(`div`,{ref:v,className:`canvas-controls-layer`,children:(0,U.jsxs)(`aside`,{ref:y,className:`canvas-controls-panel`,"aria-label":K.controls,onFocusCapture:e=>{e.target instanceof HTMLElement&&(_.current=e.target)},"data-collapsed":n.collapsed,"data-dragging":x||void 0,style:{left:n.position?.x,top:n.position?.y,width:`min(${$e(e.scopes)}px, calc(100% - var(--hub-space-16) * 2))`},children:[(0,U.jsxs)(`header`,{className:`canvas-controls-header`,children:[(0,U.jsx)(W,{icon:h,ref:b,size:`small`,variant:`invisible`,className:`canvas-controls-grab controls-ghost-button`,"aria-label":K.controlsMove,"aria-describedby":m,title:``,onPointerDown:S,onPointerMove:C,onPointerUp:w,onPointerCancel:T,onLostPointerCapture:E,onKeyDown:D}),(0,U.jsx)(ue,{id:m,children:K.controlsMoveHint}),(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:`subtle`,block:!0,className:`canvas-controls-title controls-ghost-button`,"aria-label":n.collapsed?K.controlsExpand:K.controlsCollapse,"aria-expanded":!n.collapsed,"aria-controls":p,trailingVisual:n.collapsed?(0,U.jsx)(g,{size:16}):(0,U.jsx)(u,{size:16}),onClick:()=>r(e=>({...e,collapsed:!e.collapsed})),children:K.controls}),(0,U.jsx)(W,{icon:R,size:`small`,variant:`invisible`,className:`controls-ghost-button`,"aria-label":K.controlsResetAll,disabled:!e.runtimeAvailable||e.reconnectRequired||e.loading||e.resetting||!e.storageError&&!e.hasResettableValues&&!e.scopes.some(e=>Object.keys(Ze(e)).length>0)||e.scopes.some(e=>Object.values(e.snapshot.actions).some(e=>e.busy))||e.status!==`ready`&&e.status!==`no-controls`&&!e.storageError,onClick:()=>{t.resetAll()}})]}),(0,U.jsxs)(`div`,{id:p,className:`canvas-controls-body`,hidden:n.collapsed,children:[(0,U.jsxs)(`div`,{className:`canvas-controls-content`,children:[O||e.notice?(0,U.jsx)(`div`,{role:`status`,"aria-live":`polite`,children:(0,U.jsx)(H.Text,{as:`p`,size:`100`,variant:`muted`,children:[O,e.notice].filter(Boolean).join(` `)})}):null,!e.loading&&e.error?(0,U.jsx)(H.Text,{as:`p`,size:`100`,role:`alert`,children:e.error}):null,!e.loading&&e.scopeErrors?.map(e=>(0,U.jsx)(H.Text,{as:`p`,size:`100`,role:`alert`,children:K.controlsScopeError(e.scope,e.error)},e.scope)),!e.loading&&e.storageError?(0,U.jsx)(H.Text,{as:`p`,size:`100`,role:`alert`,children:e.storageError}):null,l.error?(0,U.jsx)(H.Text,{as:`p`,size:`100`,role:`alert`,children:l.error}):null,(0,U.jsx)(Xe,{scopes:e.loading?[]:e.scopes,disabled:e.resetting||e.reconnectRequired,collapsedGroups:n.collapsedGroups,onGroupCollapse:(e,t,n)=>r(r=>({...r,collapsedGroups:{...r.collapsedGroups,[`${e}/${t}`]:n}})),onCommand:(e,n,r,i)=>t.command(e,n,r,i)}),o.length?(0,U.jsxs)(H.Accordion,{className:`canvas-controls-diagnostics`,disableAnimation:!0,children:[(0,U.jsx)(H.Accordion.Heading,{children:K.controlsDiagnostics}),(0,U.jsx)(H.Accordion.Content,{children:o.map(({scope:e,id:t,label:n,error:r})=>(0,U.jsxs)(H.Text,{as:`p`,size:`100`,children:[n,`: `,r]},`${e}/${t}`))})]}):null]}),s||k||A?(0,U.jsxs)(`footer`,{className:`canvas-controls-footer`,children:[A?(0,U.jsxs)(H.InlineLink,{className:`canvas-controls-learn-more`,href:`https://github.com/github/replica/blob/main/starter/README.md#prototype-controls`,target:`_blank`,rel:`noopener noreferrer`,children:[K.controlsLearnMore,(0,U.jsx)(ie,{size:16,"aria-hidden":`true`})]}):null,s?(0,U.jsx)(H.Button,{size:`small`,variant:`secondary`,type:`button`,disabled:l.busy||l.requested||e.resetting,onClick:()=>void f(),children:l.requested?K.controlsDiagnosisRequested:o.length?K.controlsFix:K.controlsDiagnose}):null,k?(0,U.jsx)(H.Button,{size:`small`,variant:`secondary`,type:`button`,disabled:e.resetting,onClick:()=>t.retry(),children:e.storageError?K.controlsRetryStorage:K.controlsRetry}):null]}):null]})]})})}var tt=C();function nt({children:e,className:t,...n}){return(0,U.jsx)(`span`,{...n,className:`hub-counter${t?` ${t}`:``}`,children:e})}var rt=(0,V.createContext)(null);function it({source:e,children:t}){return(0,U.jsx)(rt,{value:e,children:t})}function at({title:e,label:t=e,open:n,closeLabel:r,closeDisabled:i=!1,closeShortcut:a,closeRef:o,onClose:s,headerAccessory:c,className:l,contentClassName:u,children:d}){return(0,U.jsxs)(`aside`,{className:`hub-sidebar${l?` ${l}`:``}`,"aria-label":t,"aria-hidden":!n,"data-open":n,inert:!n,children:[(0,U.jsxs)(`header`,{className:`hub-sidebar__header`,children:[(0,U.jsxs)(`div`,{className:`hub-sidebar__heading`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`subhead-medium`,weight:`normal`,children:e}),c]}),(0,U.jsx)(W,{ref:o,icon:ne,"aria-label":r,"aria-keyshortcuts":a,title:r,description:r,variant:`invisible`,size:`small`,className:`hub-sidebar__close`,disabled:i,onClick:s})]}),(0,U.jsx)(`div`,{className:`hub-sidebar__content${u?` ${u}`:``}`,children:d})]})}function ot({src:e,size:t=32,className:n}){return(0,U.jsx)(H.Avatar,{src:e||`/avatar-placeholder.svg`,alt:``,size:32,className:`hub-user-avatar hub-user-avatar--${t}${n?` ${n}`:``}`,onError:e=>{let t=e.currentTarget;t.getAttribute(`src`)!==`/avatar-placeholder.svg`&&(t.src=`/avatar-placeholder.svg`)}})}function st({participants:e,size:t}){let n=e.slice(0,4),r=e.length-3;return(0,U.jsxs)(`span`,{className:`review-participant-stack review-participant-stack--${t}`,"data-avatar-count":n.length,"data-participant-count":e.length,"aria-hidden":`true`,children:[(r>1?n.slice(0,3):n).map(e=>(0,U.jsx)(`span`,{className:`review-participant-stack__avatar`,children:(0,U.jsx)(ot,{src:e.avatarUrl,size:24})},e.login)),r>1?(0,U.jsxs)(`span`,{className:`review-participant-stack__avatar review-participant-stack__avatar--overflow`,children:[`+`,r]}):null]})}function ct(e,t){let n=e.path.map(e=>({x:t.x+e.x*t.width,y:t.y+e.y*t.height})),r={x:t.x+t.width,y:t.y};return{path:n,point:n.reduce((e,t)=>{let n=(t.x-r.x)**2+(t.y-r.y)**2;return n{let e=c.current;if(!e)return;function t(){let t=e?.clientWidth??0;if(t)for(let e of l.current.values()){let n=Number.parseFloat(e.style.left),r=e.offsetWidth;if(!Number.isFinite(n)||!r)continue;let i=n-16,a=Math.max(0,Math.min(i,t-r))-i;e.style.setProperty(`--review-marker-offset-x`,`${a}px`)}}t();let n=typeof ResizeObserver>`u`?null:new ResizeObserver(t);n?.observe(e);for(let e of l.current.values())n?.observe(e);return window.addEventListener(`resize`,t),()=>{n?.disconnect(),window.removeEventListener(`resize`,t)}},[t,e]),(0,V.useEffect)(()=>{!i||n===null||u!==`resolved`&&u!==`moved`||l.current.get(n)?.focus({preventScroll:!0})},[i,u,n]),(0,U.jsx)(`div`,{ref:c,className:`review-comment-markers`,role:`group`,"aria-label":o.heading,children:e.map(e=>{let{root:i}=e,c=t.get(i.id);if(!c||c.status!==`resolved`&&c.status!==`moved`)return null;let u=e.replies.length>0,d=(e.unread?u?o.unreadMarkerWithRepliesLabel:o.unreadMarkerLabel:u?o.markerWithRepliesLabel:o.markerLabel).replace(`%{author}`,`@${i.author.login}`).replace(`%{count}`,(e.replies.length+1).toString()),f=i.anchor.kind===`area`?ct(i.anchor,c.rect):null,p=e.participants.slice(3),m=p.length>1?p.map(({login:e})=>`@${e}`).join(`, `):d;return(0,U.jsxs)(V.Fragment,{children:[f&&(!a||n===i.id)?(0,U.jsx)(`svg`,{className:`review-comment-area`,"aria-hidden":`true`,width:`100%`,height:`100%`,children:(0,U.jsx)(`polyline`,{className:n===i.id?`review-comment-area__path review-comment-area__path--selected`:`review-comment-area__path`,points:f.path.map(e=>`${e.x},${e.y}`).join(` `),vectorEffect:`non-scaling-stroke`})}):null,(0,U.jsx)(H.Tooltip,{text:m,type:`description`,ref:e=>{e instanceof HTMLButtonElement?l.current.set(i.id,e):l.current.delete(i.id)},children:(0,U.jsx)(`button`,{type:`button`,"data-review-thread-id":i.id,className:`review-comment-marker${n===i.id?` review-comment-marker--selected`:``}${i.resolvedAt?` review-comment-marker--resolved`:``}${e.unread?` review-comment-marker--unread`:``}${r&&n!==i.id?` review-comment-marker--blocked`:``}`,style:{left:f?.point.x??c.point.x,top:f?.point.y??c.point.y},"aria-label":d,disabled:r&&n!==i.id,onClick:()=>s(e),children:(0,U.jsx)(st,{participants:e.participants,size:`small`})})})]},i.id)})})}function ut({checked:e,onChange:t,size:n=`medium`,className:r,...i}){let{value:a,...o}=i;return(0,U.jsxs)(`label`,{className:`hub-switch hub-switch--${n}${r?` ${r}`:``}`,"data-disabled":i.disabled||void 0,children:[(0,U.jsx)(`span`,{className:`hub-switch__native-control`,children:(0,U.jsx)(H.Checkbox,{...o,value:a===void 0?void 0:String(a),role:`switch`,checked:e,onChange:e=>{i.disabled||t(e.currentTarget.checked)}})}),(0,U.jsx)(`span`,{className:`hub-switch__track`,"data-checked":e,"aria-hidden":`true`,children:(0,U.jsx)(`span`,{className:`hub-switch__thumb`})})]})}function dt(e){(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.click())}function ft({compact:e=!1,filters:t,participants:r,showPins:i,copy:a,onFiltersChange:o,onShowPinsChange:s}){let[c,l]=(0,V.useState)(!1),u=t.currentBuildOnly||t.currentPageOnly||t.showResolved||!t.showRead||t.onlyMine||t.participant!==null||!i,d=r.find(e=>e.login===t.participant),f=t.participant===null?a.allParticipantsLabel:d?.name?`${d.name} (@${d.login})`:`@${t.participant}`;return(0,U.jsxs)(`div`,{className:`review-comment-filter-controls${e?` review-comment-filter-controls--compact`:``}`,children:[(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__search`,children:[(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__search-field`,children:[e?null:(0,U.jsx)(oe,{className:`review-comment-filter-controls__search-icon`,size:16,"aria-hidden":`true`}),(0,U.jsx)(`input`,{type:`search`,className:`review-comment-filter-controls__input`,"aria-label":a.searchLabel,placeholder:a.searchPlaceholder,value:t.search,onChange:e=>o({...t,search:e.target.value})})]}),(0,U.jsx)(W,{icon:n,"aria-label":a.filterLabel,description:a.filterLabel,"aria-expanded":c,variant:e?`default`:`invisible`,className:`review-comment-filter-controls__button${c||u?` review-comment-filter-controls__button--active`:``}`,onClick:()=>l(e=>!e)})]}),c?(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__filters`,children:[(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__participant`,children:[(0,U.jsx)(`span`,{children:a.participantFilterLabel}),(0,U.jsxs)(H.ActionMenu,{size:`small`,selectionVariant:`single`,menuAlignment:`end`,onSelect:e=>o({...t,participant:e===``?null:e}),children:[(0,U.jsx)(H.ActionMenu.Button,{className:`review-comment-filter-controls__participant-trigger`,variant:`secondary`,size:`small`,"aria-label":`${a.participantFilterLabel}: ${f}`,children:(0,U.jsx)(`span`,{className:`review-comment-filter-controls__participant-name`,children:f})}),(0,U.jsxs)(H.ActionMenu.Overlay,{"aria-label":a.participantFilterLabel,children:[(0,U.jsx)(H.ActionMenu.Item,{value:``,selected:t.participant===null,role:`menuitemradio`,onKeyDownCapture:dt,children:a.allParticipantsLabel}),r.map(e=>(0,U.jsx)(H.ActionMenu.Item,{value:e.login,selected:t.participant===e.login,role:`menuitemradio`,onKeyDownCapture:dt,children:e.name?`${e.name} (@${e.login})`:`@${e.login}`},e.login))]})]})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-current-build`,children:a.currentBuildFilterLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-current-build`,checked:t.currentBuildOnly,size:`small`,onChange:e=>o({...t,currentBuildOnly:e})})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-current-page`,children:a.currentPageFilterLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-current-page`,checked:t.currentPageOnly,size:`small`,onChange:e=>o({...t,currentPageOnly:e})})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-show-resolved`,children:a.showResolvedLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-show-resolved`,checked:t.showResolved,size:`small`,onChange:e=>o({...t,showResolved:e})})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-unread-only`,children:a.unreadOnlyLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-unread-only`,checked:!t.showRead,size:`small`,onChange:e=>o({...t,showRead:!e})})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-only-mine`,children:a.onlyMineLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-only-mine`,checked:t.onlyMine,size:`small`,onChange:e=>o({...t,onlyMine:e})})]}),(0,U.jsxs)(`div`,{className:`review-comment-filter-controls__toggle`,children:[(0,U.jsx)(`span`,{id:`review-comments-show-pins`,children:a.showPinsLabel}),(0,U.jsx)(ut,{"aria-labelledby":`review-comments-show-pins`,checked:i,size:`small`,onChange:s})]})]}):null]})}var pt=[[31536e3,`y`],[2592e3,`mo`],[604800,`w`],[86400,`d`],[3600,`h`],[60,`m`]];function mt(e){let t=window.setInterval(e,6e4);return()=>window.clearInterval(t)}function ht(){return Math.floor(Date.now()/6e4)*6e4}function gt(){return null}function _t({value:e,showTitle:t=!0}){let n=Date.parse(e),r=Number.isNaN(n)?e:new Date(n).toUTCString(),i=(0,V.useSyncExternalStore)(mt,ht,gt),a=r;if(i!==null&&!Number.isNaN(n)){let e=Math.round((i-n)/1e3),t=pt.find(([t])=>Math.abs(e)>=t);a=t?`${e<0?`in `:``}${Math.round(Math.abs(e)/t[0])}${t[1]}${e<0?``:` ago`}`:`just now`}return(0,U.jsx)(`time`,{dateTime:e,title:t?r:void 0,"aria-label":r,children:a})}function vt({thread:e,currentBuildNumber:t,resolution:n,anchorStatusLabel:r,selected:i,selectionBlocked:a,copy:o,onSelect:s,buildHref:c}){let l=(0,V.useId)(),{root:u}=e,d=u.author.name||`@${u.author.login}`,f=a&&!i,p=o.buildLabel.replace(`%{number}`,u.buildNumber?.toString()??``),m=u.buildNumber!==null&&u.buildPath!==null&&u.buildNumber!==t,h=e.replies.length===1?o.replyCountOneLabel:o.replyCountOtherLabel.replace(`%{count}`,e.replies.length.toString()),g=o.missingAnchorLabel;return u.resolvedAt?g=o.resolvedLabel:r===void 0?n?n.status===`resolved`?g=null:n.status===`moved`?g=o.movedAnchorLabel:n.status===`changed`?g=o.changedAnchorLabel:n.status===`route-mismatch`&&(g=o.routeMismatchLabel):g=null:g=r,(0,U.jsx)(`article`,{className:`review-comment-row${i?` review-comment-row--selected`:``}${e.unread?` review-comment-row--unread`:``}`,onClick:t=>{f||t.target instanceof Element&&t.target.closest(`a`)||s(e)},children:(0,U.jsx)(`div`,{className:`review-comment-row__layout`,children:(0,U.jsxs)(`div`,{className:`review-comment-row__content`,children:[(0,U.jsxs)(`div`,{className:`review-comment-row__copy`,children:[(0,U.jsxs)(`div`,{className:`review-comment-row__metadata`,children:[(0,U.jsxs)(`span`,{className:`review-comment-row__author-and-build`,children:[(0,U.jsx)(ot,{src:u.author.avatarUrl,size:20,className:`review-comment-row__avatar`}),(0,U.jsx)(`span`,{id:`${l}-author`,className:`review-comment-row__author`,children:d}),m?(0,U.jsxs)(`span`,{className:`review-comment-row__build`,children:[`(`,(0,U.jsx)(`a`,{href:c||u.buildPath||void 0,target:c?`_blank`:void 0,rel:c?`noopener noreferrer`:void 0,children:p}),`)`]}):null]}),(0,U.jsx)(_t,{value:e.lastActivityAt})]}),(0,U.jsx)(`button`,{type:`button`,className:`review-comment-row__button`,"aria-labelledby":`${l}-author ${l}-body${e.unread?` ${l}-unread`:``}`,"aria-pressed":i,disabled:f,title:f?o.selectionBlockedLabel:void 0,children:(0,U.jsxs)(`span`,{className:`review-comment-row__body-container`,children:[e.unread?(0,U.jsx)(`span`,{role:`img`,id:`${l}-unread`,"aria-label":o.unreadLabel,title:o.unreadLabel,className:`review-comment-row__unread`}):null,(0,U.jsx)(`span`,{id:`${l}-body`,className:`review-comment-row__body`,children:u.body??o.deletedCommentLabel})]})})]}),g||e.replies.length>0?(0,U.jsxs)(`div`,{className:`review-comment-row__context`,children:[e.replies.length>0?(0,U.jsx)(`span`,{className:`review-comment-row__replies`,children:h}):null,g?(0,U.jsx)(H.Label,{size:`small`,className:`review-comment-row__status`,children:g}):null]}):null]})})})}function yt({frame:e,threads:t,currentBuildNumber:n,buildLinkOrigin:r,totalCount:i,hasThreads:a,filters:o,participants:s,resolutions:c,selectedThreadId:l,selectionBlocked:u,closeBlocked:d,showPins:f,loading:p,loadFailed:m,notice:h,copy:g,onClose:_,onFiltersChange:v,onShowPinsChange:y,onRetry:b,onSelect:x}){let S=a?g.noMatchesLabel:g.emptyLabel,C=(0,U.jsxs)(U.Fragment,{children:[h,(0,U.jsx)(ft,{compact:!e,filters:o,participants:s,showPins:f,copy:g,onFiltersChange:v,onShowPinsChange:y}),(0,U.jsxs)(`div`,{className:`review-comments-sidebar__body`,"aria-live":`polite`,children:[m?(0,U.jsxs)(`div`,{className:`review-comments-sidebar__state`,role:`alert`,children:[(0,U.jsx)(`span`,{children:g.loadErrorLabel}),(0,U.jsx)(H.Button,{size:`small`,onClick:b,children:g.retryLabel})]}):t.length===0&&!p?(0,U.jsx)(`div`,{className:`review-comments-sidebar__state`,children:S}):(0,U.jsx)(`div`,{className:`review-comments-sidebar__threads`,children:t.map(e=>(0,U.jsx)(vt,{thread:e,currentBuildNumber:n,buildHref:r&&e.root.buildPath?new URL(e.root.buildPath,r).href:void 0,resolution:c.get(e.root.id),selected:l===e.root.id,selectionBlocked:u,copy:g,onSelect:x},e.root.id))}),p?(0,U.jsxs)(`div`,{className:`review-comments-sidebar__loading`,children:[(0,U.jsx)(le,{decorative:!0,size:`small`}),(0,U.jsx)(`span`,{children:g.loadingLabel})]}):null]})]});return e?(0,U.jsx)(at,{...e,title:g.heading,closeLabel:g.closeLabel,closeDisabled:d,closeShortcut:`Shift+C`,onClose:_,headerAccessory:(0,U.jsx)(nt,{children:i}),children:C}):(0,U.jsxs)(`aside`,{className:`review-comments-sidebar`,"aria-label":g.heading,children:[(0,U.jsxs)(`header`,{className:`review-comments-sidebar__header`,children:[(0,U.jsxs)(`span`,{className:`review-comments-sidebar__heading`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`6`,children:g.heading}),(0,U.jsx)(nt,{children:i})]}),(0,U.jsx)(W,{icon:ne,"aria-label":g.closeLabel,"aria-keyshortcuts":`Shift+C`,description:g.closeLabel,size:`small`,variant:`invisible`,className:`review-comments-sidebar__close`,disabled:d,onClick:_})]}),C]})}function bt({bridgeReady:e,copy:t,selectionBlocked:n,selecting:r,onCancelSelection:i,onStartAreaSelection:a,onStartElementSelection:o}){let c=(0,V.useId)(),l=!e||n,u=e?n?t.selectionBlockedLabel:t.commentMenuLabel:t.bridgeUnavailableLabel;if(r)return(0,U.jsx)(W,{icon:ne,"aria-label":t.cancelSelectionLabel,description:t.cancelSelectionLabel,"aria-pressed":!0,size:`small`,variant:`default`,className:`review-comment-control__trigger`,onClick:i});let d=(0,U.jsxs)(H.ActionMenu,{selectionVariant:`none`,size:`small`,menuAlignment:`start`,disabled:l,children:[(0,U.jsx)(H.ActionMenu.Button,{className:`review-comment-control__trigger`,variant:`secondary`,"aria-label":t.commentMenuLabel,"aria-describedby":c,leadingVisual:(0,U.jsx)(b,{size:16}),onClick:e=>{let t=e.currentTarget,n=t.closest(`.repository-workspace__content`)?.getBoundingClientRect(),r=Math.min(window.innerHeight,n?.bottom??window.innerHeight),i=Math.max(0,r-t.getBoundingClientRect().bottom-8);t.closest(`[data-testid="ActionMenu"]`)?.style.setProperty(`--review-comment-control-menu-height`,`${i}px`)},children:``}),(0,U.jsxs)(H.ActionMenu.Overlay,{"aria-label":t.commentMenuLabel,children:[(0,U.jsx)(H.ActionMenu.Item,{className:`review-comment-control__menu-item`,value:`element`,leadingVisual:(0,U.jsx)(s,{size:16}),"aria-keyshortcuts":`C`,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())},children:t.commentOnElementLabel}),(0,U.jsx)(H.ActionMenu.Item,{className:`review-comment-control__menu-item`,value:`area`,leadingVisual:(0,U.jsx)(_,{size:16}),"aria-keyshortcuts":`H`,onClick:a,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a())},children:t.highlightRegionLabel})]})]});return l?(0,U.jsxs)(`div`,{title:u,children:[d,(0,U.jsx)(ue,{id:c,children:u})]}):(0,U.jsx)(H.Tooltip,{id:c,text:u,type:`description`,children:(0,U.jsx)(`div`,{children:d})})}var xt={search:``,currentBuildOnly:!1,currentPageOnly:!1,showResolved:!1,showRead:!0,onlyMine:!1,participant:null},St={heading:`Comments`,closeLabel:`Close comments`,commentMenuLabel:`Add a comment`,commentOnElementLabel:`Comment on element`,highlightRegionLabel:`Highlight a region`,cancelSelectionLabel:`Cancel selection`,bridgeUnavailableLabel:`Adding comments needs the review bridge.`,selectionBlockedLabel:`Close or submit the open draft.`,selectionFailedLabel:`Hub could not anchor a comment to that element.`,areaTooSmallLabel:`Draw a larger region to add a comment.`,areaUnavailableLabel:`Hub could not save that region.`,searchLabel:`Search comments`,searchPlaceholder:`Search comments`,filterLabel:`Filters`,currentBuildFilterLabel:`Current build only`,currentPageFilterLabel:`Current page only`,participantFilterLabel:`Participant`,allParticipantsLabel:`All participants`,showResolvedLabel:`Show resolved`,unreadOnlyLabel:`Unread only`,onlyMineLabel:`Only your threads`,showPinsLabel:`Show pins`,sidebarShortcutLabel:`Shift+C`,loadingLabel:`Loading comments`,loadErrorLabel:`Comments could not be loaded.`,retryLabel:`Retry`,emptyLabel:`No comments have been added.`,noMatchesLabel:`No comments match these filters.`,buildLabel:`build %{number}`,movedAnchorLabel:`Moved`,changedAnchorLabel:`Context changed`,missingAnchorLabel:`Not found`,routeMismatchLabel:`Saved on another page`,resolvedLabel:`Resolved`,markerLabel:`Thread started by %{author}`,markerWithRepliesLabel:`Thread started by %{author}, %{count} comments`,unreadLabel:`Unread`,unreadMarkerLabel:`Unread thread started by %{author}`,unreadMarkerWithRepliesLabel:`Unread thread started by %{author}, %{count} comments`,replyCountOneLabel:`1 reply`,replyCountOtherLabel:`%{count} replies`,threadHeading:`Conversation`,backToCommentsLabel:`Back to comments`,resolvedByLabel:`Resolved by %{author}. Reopen this thread to reply.`,editedLabel:`Edited`,deletedCommentLabel:`Comment deleted`,addReactionLabel:`Add reaction`,reactionCountOneLabel:`%{reaction}, 1 reaction`,reactionCountOtherLabel:`%{reaction}, %{count} reactions`,reactionErrorLabel:`The reaction could not be changed.`,readErrorLabel:`Hub could not mark this conversation as read.`,markUnreadLabel:`Mark as unread`,markUnreadErrorLabel:`Hub could not mark this conversation as unread. Try again.`,reactionLabels:{"+1":`Thumbs up`,"-1":`Thumbs down`,laugh:`Laugh`,hooray:`Hooray`,confused:`Confused`,heart:`Heart`,rocket:`Rocket`,eyes:`Eyes`},commentActionsLabel:`Actions for comment by %{author}`,editLabel:`Edit`,deleteLabel:`Delete`,editCommentLabel:`Edit comment`,saveEditLabel:`Save`,savingEditLabel:`Saving comment`,cancelEditLabel:`Cancel`,editErrorLabel:`The comment could not be updated.`,deleteHeading:`Delete this comment?`,deletePromptLabel:`Deleted comment text cannot be recovered.`,confirmDeleteLabel:`Delete`,deletingLabel:`Deleting comment`,deleteErrorLabel:`The comment could not be deleted.`,replyLabel:`Reply`,replyPlaceholder:`Reply to this conversation`,replySubmitLabel:`Reply`,replySubmitTooltipMacLabel:`Reply (Cmd+Return)`,replySubmitTooltipOtherLabel:`Reply (Ctrl+Enter)`,replyingLabel:`Saving reply`,replyErrorLabel:`The reply could not be saved.`,resolveLabel:`Resolve`,resolvingLabel:`Resolving thread`,reopenLabel:`Reopen`,reopeningLabel:`Reopening thread`,resolutionErrorLabel:`The thread state could not be changed.`,resolvedReplyBlockedLabel:`Reopen this thread to reply.`,deletedReplyBlockedLabel:`Replies are closed.`,threadDiscardPromptLabel:`Your reply or edit has not been saved.`,composerHeading:`New comment`,composerLabel:`Comment`,composerPlaceholder:`Leave a review comment`,submitLabel:`Comment`,submitTooltipMacLabel:`Comment (Cmd+Return)`,submitTooltipOtherLabel:`Comment (Ctrl+Enter)`,submittingLabel:`Saving comment`,closeComposerLabel:`Cancel`,discardHeading:`Keep this draft?`,discardPromptLabel:`This comment has not been submitted.`,keepLabel:`Keep`,discardButtonLabel:`Discard`,bodyTooLongLabel:`Comments must be 10000 UTF-8 bytes or fewer.`,createErrorLabel:`The comment could not be saved.`};function Ct(e,t){let n=new Map;n.set(e.login.toLowerCase(),e);for(let e of t.toReversed()){let t=e.login.toLowerCase();n.has(t)||n.set(t,e)}return Array.from(n.values())}function wt(e){let t=new Map,n=new Map;for(let r of e){if(r.kind===`root`){t.set(r.id,r);continue}let e=n.get(r.rootId)??[];e.push(r),n.set(r.rootId,e)}return Array.from(t.values()).flatMap(e=>{let t=(n.get(e.id)??[]).filter(e=>e.deletedAt===null).sort((e,t)=>Date.parse(e.createdAt)-Date.parse(t.createdAt)||e.id-t.id);return e.deletedAt!==null&&t.length===0?[]:[{root:e,replies:t,participants:Ct(e.author,t.map(e=>e.author)),lastActivityAt:t.at(-1)?.createdAt??e.createdAt,unread:e.viewerLastSeenActivityVersion===null||e.viewerLastSeenActivityVersionDate.parse(t.lastActivityAt)-Date.parse(e.lastActivityAt)||t.root.id-e.root.id)}var Tt=new TextEncoder;function Et(e,{prefix:t,required:n=!1}={}){return P().refine(r=>(!n||r!==``)&&(!t||r===``||r.startsWith(t))&&Tt.encode(r).length<=e)}var Dt=16384,Ot=2048,kt=2048,At=1024,jt=4096,Q=1e3,Mt=2e3,Nt=1e6,Pt=1e5,Ft=new TextEncoder,It=B().min(0).max(Nt),Lt=B().min(-Nt).max(Nt),Rt=B().min(0).max(Nt),zt=E({x:B().min(0).max(1),y:B().min(0).max(1)}).strict(),Bt=E({pathname:Et(Ot,{prefix:`/`,required:!0}),search:Et(kt,{prefix:`?`}),hash:Et(At,{prefix:`#`})}).strict(),Vt=E({x:It,y:It,width:Rt,height:Rt}).strict();E({x:Lt,y:Lt}).strict();var Ht=E({width:B().min(1).max(Pt),height:B().min(1).max(Pt),scrollX:It,scrollY:It}).strict(),Ut=E({schemaVersion:L(1),kind:L(`element`),route:Bt,selector:Et(jt,{required:!0}),accessibleName:Et(Q),tagName:Et(64,{required:!0}).regex(/^[a-z][a-z0-9-]*$/),selectedText:Et(Mt),rect:Vt,viewport:Ht,elementOffset:zt}).strict().refine(e=>Ft.encode(JSON.stringify(e)).length<=Dt),Wt=E({selector:Et(jt,{required:!0}),accessibleName:Et(Q),tagName:Et(64,{required:!0}).regex(/^[a-z][a-z0-9-]*$/),role:Et(64),textExcerpt:Et(500),rect:Vt}).strict(),Gt=E({schemaVersion:L(1),kind:L(`area`),route:Bt,path:ee(zt).min(2).max(160),rect:Vt,viewport:Ht,elements:ee(Wt).max(8)}).strict().refine(e=>Math.hypot(e.rect.width,e.rect.height)>=8).refine(e=>Ft.encode(JSON.stringify(e)).length<=Dt),Kt=T(`kind`,[Ut,Gt]),qt=T(`status`,[E({commentId:B().int().positive().max(2**53-1),status:te([`resolved`,`moved`]),rect:E({x:Lt,y:Lt,width:Rt,height:Rt}).strict(),point:E({x:Lt,y:Lt}).strict()}).strict(),E({commentId:B().int().positive().max(2**53-1),status:te([`changed`,`missing`,`route-mismatch`])}).strict()]),Jt=B().int().positive().max(2**53-1),Yt=P().refine(e=>!Number.isNaN(Date.parse(e))),Xt=Yt.nullable(),Zt=E({login:P().min(1),name:P().nullable(),avatarUrl:P().nullable()}),Qt=te([`+1`,`-1`,`laugh`,`hooray`,`confused`,`heart`,`rocket`,`eyes`]),$t=E({content:Qt,count:Jt,viewerHasReacted:j()}),en={id:Jt,body:P().nullable(),mentions:ee(E({login:P().min(1),githubId:Jt})).optional(),createdAt:Yt,updatedAt:Yt,editedAt:Xt,deletedAt:Xt,author:Zt,viewerCanEdit:j(),viewerCanDelete:j(),reactions:ee($t)},tn=E({...en,kind:L(`root`),buildNumber:Jt.nullable(),buildPath:P().startsWith(`/`).nullable(),draftRevisionId:Jt.nullable().optional(),anchor:Kt,resolvedAt:Xt,resolvedBy:Zt.nullable(),activityVersion:Jt,viewerLastSeenActivityVersion:Jt.nullable()}),nn=E({...en,kind:L(`reply`),rootId:Jt}),rn=T(`kind`,[tn,nn]),an=E({comments:ee(rn),nextCursor:I(),hasMore:L(!1)}),on=E({comments:ee(rn).min(1).max(2)});function sn(e,t){let{root:n}=e,{filters:r}=t;if(!r.showResolved&&n.resolvedAt!==null||!r.showRead&&!e.unread||r.onlyMine&&![n,...e.replies].some(e=>e.author.login.toLowerCase()===t.viewerLogin.toLowerCase())||r.currentBuildOnly&&(t.selectedDraftRevisionId==null?n.buildNumber!==t.selectedBuildNumber:n.draftRevisionId!==t.selectedDraftRevisionId)||r.participant!==null&&!e.participants.some(e=>e.login.toLowerCase()===r.participant?.toLowerCase())||r.currentPageOnly&&t.route!==null&&(n.anchor.route.pathname!==t.route.pathname||n.anchor.route.search!==t.route.search||n.anchor.route.hash!==t.route.hash))return!1;let i=r.search.trim().toLowerCase();if(!i)return!0;let a=n.anchor.kind===`element`?[n.anchor.accessibleName,n.anchor.selectedText,n.anchor.tagName]:n.anchor.elements.flatMap(e=>[e.accessibleName,e.textExcerpt,e.tagName,e.role]);return[n.body??``,n.author.login,n.author.name??``,n.buildNumber?.toString()??``,...e.replies.flatMap(e=>[e.body??``,e.author.login,e.author.name??``]),...a].join(` +`).toLowerCase().includes(i)}var cn=E({candidates:ee(E({githubId:B().int().positive().max(2**53-1),login:P().min(1).max(39),avatarUrl:P().nullable()}))});async function $(e,t,n={}){let r=await fetch(e,{...n,headers:{"Content-Type":`application/json`,"X-Replica-Canvas-Token":t,...n.headers}}),i=await r.json().catch(()=>({error:K.invalidResponse}));if(!r.ok)throw Object.assign(Error(i.error||K.requestFailed),{code:i.code,statusCode:r.status,authorization:i.authorization});return i}function ln({error:e,busy:t,requested:n,onFix:r,onDismiss:i}){let a=(0,V.useId)();return(0,U.jsxs)(G,{title:K.commentingUnavailable,descriptionId:a,closeLabel:K.closeCommentingDialog,onClose:i,children:[(0,U.jsx)(`p`,{id:a,children:K.commentingDescription}),e?(0,U.jsx)(`p`,{role:`alert`,children:e}):null,(0,U.jsxs)(`div`,{className:`canvas-commenting-recovery__actions`,children:[(0,U.jsx)(H.Button,{variant:`primary`,disabled:t||n,onClick:r,children:n?K.commentingFixRequested:K.commentingFix}),(0,U.jsx)(H.Button,{variant:`subtle`,onClick:i,children:K.commentingDismiss})]})]})}function un({identity:e,enabled:t,ready:n,bridgeProblem:r,token:i}){let[a,o]=(0,V.useState)(``),[s,c]=(0,V.useState)(!1),[l,u]=(0,V.useState)(!1),[d,f]=(0,V.useState)(!1),p=(0,V.useRef)(e);(0,V.useLayoutEffect)(()=>(p.current=e,()=>{p.current=``}),[e]),(0,V.useEffect)(()=>{let e=window.setTimeout(()=>{o(``),c(!1),u(!1),f(!1)},0);return()=>{window.clearTimeout(e)}},[e,t]);async function m(){let t=e;o(``),c(!0);try{await $(`/api/commenting/fix`,i,{method:`POST`}),p.current===t&&f(!0)}catch(e){p.current===t&&o(e instanceof Error?e.message:String(e))}finally{p.current===t&&c(!1)}}return{visible:t&&!n&&!l&&!!r,error:a,busy:s,requested:d,onFix:()=>void m(),onDismiss:()=>u(!0)}}function dn({cancelLabel:e,confirmLabel:t,description:n,errorLabel:r,heading:i,loading:a=!1,loadingAnnouncement:o,compact:s=!1,condensed:c=!1,onCancel:l,onConfirm:u}){let d=(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:c?`primary`:void 0,className:`review-confirmation-panel__cancel`,onClick:l,children:e}),f=(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:c?`secondary`:`primary`,className:c?void 0:`review-confirmation-panel__danger`,disabled:a,"aria-busy":a,onClick:u,children:t});return(0,U.jsxs)(`div`,{className:`review-confirmation-panel${s||c?` review-confirmation-panel--compact`:``}${c?` review-confirmation-panel--condensed`:``}`,role:`alert`,children:[(0,U.jsxs)(`div`,{className:`review-confirmation-panel__copy`,children:[(0,U.jsx)(`strong`,{children:i}),c?(0,U.jsx)(ue,{children:n}):(0,U.jsx)(`span`,{children:n})]}),r?(0,U.jsx)(`span`,{className:`review-confirmation-panel__error`,children:r}):null,(0,U.jsxs)(`div`,{className:`review-confirmation-panel__actions`,children:[c?f:d,c?d:f,a&&o?(0,U.jsx)(ue,{role:`status`,children:o}):null]})]})}function fn(){return(0,V.useContext)(rt)}function pn(e){let t=e.matchAll(/(?e[1]?[e[1].toLowerCase()]:[])))}function mn({value:e,onValueChange:t,onKeyDown:n,ref:r,...i}){let a=fn(),o=(0,V.useRef)(null),s=(0,V.useRef)(null),c=(0,V.useRef)(null),l=(0,V.useId)(),[u,d]=(0,V.useState)(e.length),[f,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(null),[g,_]=(0,V.useState)(!1),[v,y]=(0,V.useState)(0),[b,x]=(0,V.useState)(0),[S,C]=(0,V.useState)({left:0,top:0,width:0}),w=e.slice(0,u).match(/(?:^|[\s(])@([a-zA-Z0-9-]*)$/)?.[1]?.toLowerCase(),T=a!==null&&w!==void 0&&!f&&!i.disabled,E=pn(e).length>10,D=m?.source===a&&m?.failed,O=g||m?.source!==a,k=(m?.source===a?m.candidates:[]).filter(e=>e.login.toLowerCase().includes(w??``)).slice(0,8),A=Math.min(b,Math.max(0,k.length-1));(0,V.useEffect)(()=>{o.current?.setCustomValidity(E?a?.copy.limit??``:``)},[a?.copy.limit,E]),(0,V.useEffect)(()=>{if(!T||!a)return;let e=!0,t=window.setTimeout(()=>{_(!0),a.load().then(t=>{e&&h({source:a,candidates:t,failed:!1})},()=>{e&&h({source:a,candidates:[],failed:!0})}).finally(()=>{e&&_(!1)})},150);return()=>{e=!1,window.clearTimeout(t)}},[T,v,a]),(0,V.useLayoutEffect)(()=>{if(!T)return;function e(){let e=o.current?.getBoundingClientRect();e&&C({left:e.left,width:e.width,top:Math.max(4,window.innerHeight-e.bottom<224?e.top-224:e.bottom)})}return e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[T]);function j(n){if(w===void 0)return;let r=u-w.length-1,i=`@${n.login} `;t(e.slice(0,r)+i+e.slice(u)),p(!0);let a=r+i.length;window.requestAnimationFrame(()=>{o.current?.focus(),o.current?.setSelectionRange(a,a),d(a)})}function M(e,t){o.current=e,typeof t==`function`?t(e):t&&(t.current=e)}return(0,U.jsxs)(`div`,{className:`mention-input`,children:[(0,U.jsx)(`textarea`,{...i,ref:e=>M(e,r),value:e,"aria-autocomplete":a?`list`:void 0,"aria-controls":T?l:void 0,"aria-activedescendant":T&&k.length?`${l}-${A}`:void 0,onChange:e=>{d(e.currentTarget.selectionStart),p(!1),x(0),t(e.currentTarget.value)},onSelect:e=>d(e.currentTarget.selectionStart),onBlur:e=>{s.current?.contains(e.relatedTarget)||p(!0)},onKeyDown:e=>{if(T&&e.key===`Escape`)e.preventDefault(),e.stopPropagation(),p(!0);else if(T&&D&&!O&&e.key===`Tab`&&!e.shiftKey)e.preventDefault(),c.current?.focus();else{if(T&&!O&&!D&&k.length){if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),x((A+(e.key===`ArrowDown`?1:-1)+k.length)%k.length);return}if((e.key===`Enter`||e.key===`Tab`)&&!e.nativeEvent.isComposing&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey){e.preventDefault();let t=k[A];t&&j(t);return}}n?.(e)}}}),E&&a?.copy.limit?(0,U.jsx)(`span`,{role:`alert`,children:a.copy.limit}):null,T&&a?(0,tt.createPortal)((0,U.jsx)(`div`,{ref:s,id:l,className:`mention-input__suggestions`,style:S,onBlur:e=>{e.relatedTarget!==o.current&&!e.currentTarget.contains(e.relatedTarget)&&p(!0)},onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),p(!0),o.current?.focus()):e.key===`Tab`&&e.shiftKey&&(e.preventDefault(),o.current?.focus())},children:O?(0,U.jsx)(`span`,{role:`status`,children:a.copy.loading}):D?(0,U.jsxs)(`div`,{role:`alert`,children:[a.copy.error,` `,(0,U.jsx)(`button`,{ref:c,type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{y(v+1),o.current?.focus()},children:a.copy.retry})]}):(0,U.jsxs)(`ul`,{role:`listbox`,"aria-label":a.copy.suggestions,children:[k.map((e,t)=>(0,U.jsx)(`li`,{id:`${l}-${t}`,role:`option`,"aria-selected":t===A,children:(0,U.jsxs)(`button`,{type:`button`,tabIndex:-1,onMouseDown:e=>e.preventDefault(),onClick:()=>j(e),children:[`@`,e.login]})},e.githubId)),k.length?null:(0,U.jsx)(`li`,{role:`presentation`,children:a.copy.empty})]})}),document.body):null]})}function hn({anchorPoint:e,anchorRectangle:t,anchorSelector:n,layoutKey:r,preserveVerticalSide:i=!1}){let a=(0,V.useRef)(null),o=(0,V.useRef)(null),[s,c]=(0,V.useState)({left:e.x+12,top:e.y+12}),l=(0,V.useCallback)(()=>{let r=a.current,s=r?.parentElement;if(!r||!s)return;let l=r.offsetWidth,u=r.offsetHeight,d=s.clientWidth-l-8,f=s.clientHeight-u-8,p,m,h=(n?s.querySelector(n)??s.parentElement?.querySelector(n):null)?.getBoundingClientRect(),g=s.getBoundingClientRect(),_=h?{x:h.left-g.left,y:h.top-g.top,width:h.height,height:h.height}:t;if(_){let e=_.x+_.width+12,t=_.x-12-l,n=e+l<=s.clientWidth-8,r=t>=8,i=s.clientWidth-8-_.x-_.width,a=_.x-8;p=n?e:r?t:i>=a?e:t,m=_.y}else{let t=e.x+12,n=e.y+12;p=t+l<=s.clientWidth-8?t:e.x-12-l;let r=o.current,a=i&&r?.x===e.x&&r.y===e.y?r.side:n+u<=s.clientHeight-8?`below`:`above`;i&&(o.current={x:e.x,y:e.y,side:a}),m=a===`below`?n:e.y-12-u}let v={left:Math.max(8,Math.min(p,d)),top:Math.max(8,Math.min(m,f))};c(e=>e.left===v.left&&e.top===v.top?e:v)},[e,t,n,i]);return(0,V.useLayoutEffect)(()=>{l();let e=a.current,t=e?.parentElement;if(!e||!t||typeof ResizeObserver!=`function`)return;let r=new ResizeObserver(l);r.observe(e),r.observe(t);let i=n?t.querySelector(n)??t.parentElement?.querySelector(n):null;return i&&r.observe(i),window.addEventListener(`resize`,l),()=>{r.disconnect(),window.removeEventListener(`resize`,l)}},[n,r,l]),{cardRef:a,position:s}}function gn(){return typeof navigator<`u`&&/Mac/i.test(navigator.platform)}function _n(e,{allowPlainEnter:t=!1}={}){let n=e.isComposing||e.keyCode===229,r=gn()?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey,i=t&&!e.metaKey&&!e.ctrlKey;return e.key===`Enter`&&!e.shiftKey&&!e.altKey&&!n&&!e.repeat&&(r||i)}var vn=new TextEncoder;function yn({anchorPoint:e,bodyMaximumBytes:t,copy:n,creating:r,submitError:i,onSubmit:a,onDiscard:o}){let s=(0,V.useId)(),[c,l]=(0,V.useState)(``),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(!1),m=(0,V.useRef)(!1),{cardRef:h,position:g}=hn({anchorPoint:e,layoutKey:`${u}:${f}:${i??``}`,preserveVerticalSide:!0}),_=vn.encode(c).length>t,v=c.trim()!==``&&!_&&!r&&!u,y=gn()?n.submitTooltipMacLabel:n.submitTooltipOtherLabel;(0,V.useEffect)(()=>{u?h.current?.querySelector(`.review-confirmation-panel__cancel`)?.focus({preventScroll:!0}):m.current&&h.current?.querySelector(`textarea`)?.focus({preventScroll:!0}),m.current=u},[h,u]);function b(){r||(c.trim()===``?o():d(!0))}async function x(e){e.preventDefault(),v&&(await a(c)||p(!0))}return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-hidden":`true`,className:`review-comment-composer-backdrop`,onClick:b}),(0,U.jsx)(`section`,{ref:h,role:`dialog`,"aria-labelledby":s,className:`review-comment-composer`,style:{left:g.left,top:g.top},children:(0,U.jsxs)(`form`,{className:`review-comment-composer__form`,onSubmit:e=>{x(e)},onKeyDown:e=>{e.key!==`Escape`||e.defaultPrevented||(e.preventDefault(),u?d(!1):b())},children:[(0,U.jsxs)(`header`,{className:`review-comment-composer__header`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`6`,id:s,children:n.composerHeading}),(0,U.jsx)(W,{icon:ne,"aria-label":n.closeComposerLabel,description:n.closeComposerLabel,variant:`invisible`,type:`button`,disabled:r,onClick:b})]}),(0,U.jsx)(mn,{autoFocus:!0,"aria-label":n.composerLabel,placeholder:n.composerPlaceholder,value:c,rows:4,onValueChange:e=>{l(e),d(!1),p(!1)},onKeyDown:e=>{v&&_n(e.nativeEvent)&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())}}),_?(0,U.jsx)(`span`,{role:`alert`,className:`review-comment-composer__error`,children:n.bodyTooLongLabel}):null,f?(0,U.jsx)(me,{variant:`critical`,title:n.createErrorLabel,description:i,className:`review-comment-composer__banner`}):null,u?(0,U.jsx)(dn,{heading:n.discardHeading,description:n.discardPromptLabel,cancelLabel:n.keepLabel,confirmLabel:n.discardButtonLabel,condensed:!0,onCancel:()=>d(!1),onConfirm:o}):(0,U.jsxs)(`footer`,{className:`review-comment-composer__actions`,children:[(0,U.jsx)(H.Button,{type:`button`,size:`small`,disabled:r,onClick:b,children:n.closeComposerLabel}),(0,U.jsx)(H.Tooltip,{text:y,type:`description`,children:(0,U.jsx)(H.Button,{type:`submit`,size:`small`,variant:`primary`,disabled:!v,"aria-busy":r,children:n.submitLabel})}),r?(0,U.jsx)(ue,{role:`status`,children:n.submittingLabel}):null]})]})})]})}function bn({blockedLabel:e,confirmingDiscard:t,replyDraft:n,replyBodyTooLong:r,replyFailed:i,replyDisabled:a,replying:o,submitDisabled:s=!1,copy:c,onKeepDraft:u,onDiscardDraft:d,onSubmit:f,onDraftChange:p}){let m=(0,V.useRef)(null),h=n.trim()!==``&&!r&&!a&&!o&&!s&&!t&&!e,g=gn()?c.replySubmitTooltipMacLabel:c.replySubmitTooltipOtherLabel;return(0,V.useLayoutEffect)(()=>{m.current&&(m.current.style.height=`auto`,m.current.style.height=n?`${Math.min(m.current.scrollHeight,120)}px`:`2.5rem`)},[n]),t?(0,U.jsx)(dn,{heading:c.discardHeading,description:c.threadDiscardPromptLabel,cancelLabel:c.keepLabel,confirmLabel:c.discardButtonLabel,compact:!0,onCancel:u,onConfirm:d}):e?(0,U.jsx)(`span`,{className:`review-thread-reply-form__blocked`,children:e}):(0,U.jsxs)(`form`,{className:`review-thread-reply-form`,onSubmit:e=>{e.preventDefault(),h&&f()},children:[(0,U.jsxs)(`div`,{className:`review-thread-reply-form__composer`,children:[(0,U.jsx)(mn,{ref:m,"aria-label":c.replyLabel,placeholder:c.replyPlaceholder,value:n,rows:1,disabled:a,onValueChange:p,onKeyDown:e=>{h&&_n(e.nativeEvent,{allowPlainEnter:!0})&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())}}),(0,U.jsx)(H.Tooltip,{text:g,type:`description`,children:(0,U.jsx)(`button`,{type:`submit`,className:`review-thread-reply-form__submit`,disabled:!h,"aria-label":c.replySubmitLabel,"aria-busy":o,children:(0,U.jsx)(l,{size:16})})})]}),r?(0,U.jsx)(`span`,{role:`alert`,className:`review-thread-reply-form__error`,children:c.bodyTooLongLabel}):null,i?(0,U.jsx)(`span`,{role:`alert`,className:`review-thread-reply-form__error`,children:c.replyErrorLabel}):null,o?(0,U.jsx)(ue,{role:`status`,children:c.replyingLabel}):null]})}function xn({comment:e}){let t=e.body??``,n=new Set(e.mentions?.map(e=>e.login.toLowerCase())??[]),r=t.matchAll(/(?({content:e,emoji:wn(e)}));function En(e,t=0,n=0){if(t!==0||n!==0)return{x:t,y:n};let r=e.getBoundingClientRect();return{x:r.left+r.width/2,y:r.top+r.height/2}}function Dn({comment:e,mutation:t,actionsDisabled:n,controlsHidden:r=!1,copy:i,onAdd:a,onRemove:o,onBurst:s}){let c=(0,V.useId)(),[l,u]=(0,V.useState)(!1),[d,f]=(0,V.useState)(!1),p=(0,V.useRef)(!1),[m,h]=(0,V.useState)(null),[g,_]=(0,V.useState)(`outside-bottom`),v=t!==null&&(t.kind===`add-reaction`||t.kind===`remove-reaction`)&&t.commentId===e.id,y=e.reactions.flatMap(e=>{if(!m||e.content!==m.content)return[e];let t=e.count+Number(m.viewerHasReacted)-Number(e.viewerHasReacted);return t>0?[{...e,count:t,viewerHasReacted:m.viewerHasReacted}]:[]});m?.viewerHasReacted&&!e.reactions.some(({content:e})=>e===m.content)&&y.push({content:m.content,count:1,viewerHasReacted:!0});async function b(r,i){if(n||t!==null||p.current)return;let c=e.reactions.find(e=>e.content===r)?.viewerHasReacted??!1;p.current=!0,u(!1),h({content:r,viewerHasReacted:!c});try{if(!c){let e=Tn.find(e=>e.content===r);e&&s(e.emoji,i.x,i.y)}let e=c?await o(r):await a(r);u(!e)}catch{u(!0)}finally{p.current=!1,h(null)}}function x(e,t){b(e,En(t.currentTarget,t.clientX,t.clientY))}let S=(0,U.jsxs)(H.ActionMenu,{selectionVariant:`none`,size:`small`,menuAlignment:`end`,menuSide:g,disabled:n,children:[(0,U.jsx)(H.ActionMenu.Button,{className:`review-comment-reactions__menu-trigger`,variant:`subtle`,"aria-label":i.addReactionLabel,"aria-describedby":c,"aria-busy":v||m!==null,leadingVisual:(0,U.jsx)(w,{size:16}),onClick:e=>{f(!0);let t=e.currentTarget.getBoundingClientRect(),n=e.currentTarget.closest(`.review-shell`)?.getBoundingClientRect(),r=Math.min(window.innerHeight,n?.bottom??1/0)-t.bottom,i=t.top-Math.max(0,n?.top??0),a=Tn.length*36+16;_(rr?`outside-top`:`outside-bottom`)},children:``}),(0,U.jsx)(H.ActionMenu.Overlay,{"aria-label":i.addReactionLabel,children:Tn.map(e=>(0,U.jsx)(H.ActionMenu.Item,{value:e.content,leadingVisual:(0,U.jsx)(`span`,{className:`review-comment-reactions__picker-emoji`,children:e.emoji}),onClick:t=>x(e.content,t),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),b(e.content,En(t.currentTarget)))},children:i.reactionLabels[e.content]},e.content))})]});return r&&!l?null:(0,U.jsxs)(`div`,{className:`review-comment-reactions__layout`,children:[r?null:(0,U.jsxs)(`div`,{className:`review-comment-reactions`,children:[y.map(e=>{let r=Tn.find(({content:t})=>t===e.content);if(!r)return null;let a=(e.count===1?i.reactionCountOneLabel:i.reactionCountOtherLabel).replace(`%{reaction}`,i.reactionLabels[e.content]).replace(`%{count}`,e.count.toString());return(0,U.jsxs)(H.Button,{size:`small`,"aria-label":a,title:a,"aria-pressed":e.viewerHasReacted,disabled:n,"aria-busy":m?.content===e.content||v&&`content`in t&&t.content===e.content,className:e.viewerHasReacted?`review-comment-reaction--selected`:void 0,onClick:t=>x(e.content,t),children:[(0,U.jsx)(`span`,{"aria-hidden":`true`,children:r.emoji}),(0,U.jsx)(nt,{"aria-hidden":`true`,children:e.count})]},e.content)}),n?(0,U.jsxs)(`div`,{title:i.addReactionLabel,children:[S,(0,U.jsx)(ue,{id:c,children:i.addReactionLabel})]}):(0,U.jsx)(H.Tooltip,{id:c,text:i.addReactionLabel,type:`description`,className:`review-comment-reactions__tooltip${d?` review-comment-reactions__tooltip--suppressed`:``}`,children:(0,U.jsx)(`div`,{onMouseEnter:e=>{e.currentTarget.querySelector(`[aria-expanded="true"]`)||f(!1)},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||f(!1)},children:S})})]}),l?(0,U.jsx)(`span`,{role:`alert`,className:`review-comment-reactions__error`,children:i.reactionErrorLabel}):null]})}function On({comment:e,mutation:t,copy:n,editing:r,editDraft:i,editBodyTooLong:a,editFailed:s,confirmingEditDiscard:c,saving:l,confirmingDelete:u,deleting:d,deleteFailed:f,actionsDisabled:p,onStartEdit:m,onEditDraftChange:h,onSaveEdit:g,onCancelEdit:_,onKeepEdit:v,onDiscardEdit:y,onRequestDelete:b,onCancelDelete:x,onDelete:S,onAddReaction:C,onRemoveReaction:w,onBurstReaction:T,onMarkUnread:E,markUnreadDisabled:D=!1}){let k=(0,V.useId)(),A=(0,V.useRef)(null),j=(0,V.useRef)(!1),[N,P]=(0,V.useState)(`outside-bottom`),F=e.author.name||`@${e.author.login}`,I=n.commentActionsLabel.replace(`%{author}`,`@${e.author.login}`),L=p&&(!E||D),R=!!(e.body&&e.viewerCanEdit),z=!!(e.body&&e.viewerCanDelete);return(0,V.useEffect)(()=>{c?A.current?.querySelector(`.review-confirmation-panel button`)?.focus({preventScroll:!0}):j.current&&A.current?.querySelector(`textarea`)?.focus({preventScroll:!0}),j.current=c},[c]),(0,U.jsxs)(`article`,{className:`review-thread-message`,"data-review-message-id":e.id,children:[(0,U.jsx)(Sn,{visual:(0,U.jsx)(ot,{src:e.author.avatarUrl,size:28}),author:F,metadata:(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(_t,{value:e.createdAt}),e.editedAt?(0,U.jsx)(`span`,{children:n.editedLabel}):null]}),children:E||R||z?L?(0,U.jsxs)(`div`,{title:I,children:[(0,U.jsx)(H.ActionMenu,{selectionVariant:`none`,size:`small`,menuAlignment:`end`,disabled:!0,children:(0,U.jsx)(H.ActionMenu.Button,{className:`review-thread-message__menu-trigger`,variant:`subtle`,"aria-label":I,"aria-describedby":k,leadingVisual:(0,U.jsx)(o,{size:16}),children:``})}),(0,U.jsx)(ue,{id:k,children:I})]}):(0,U.jsx)(H.Tooltip,{id:k,text:I,type:`description`,children:(0,U.jsx)(`div`,{children:(0,U.jsxs)(H.ActionMenu,{selectionVariant:`none`,size:`small`,menuAlignment:`end`,menuSide:N,children:[(0,U.jsx)(H.ActionMenu.Button,{className:`review-thread-message__menu-trigger`,variant:`subtle`,"aria-label":I,"aria-describedby":k,leadingVisual:(0,U.jsx)(o,{size:16}),onClick:e=>{let t=e.currentTarget.getBoundingClientRect(),n=e.currentTarget.closest(`.review-shell`)?.getBoundingClientRect(),r=Math.min(window.innerHeight,n?.bottom??1/0)-t.bottom,i=t.top-Math.max(0,n?.top??0);P(r<(E?128:88)&&i>r?`outside-top`:`outside-bottom`)},children:``}),(0,U.jsxs)(H.ActionMenu.Overlay,{"aria-label":I,children:[E?(0,U.jsx)(H.ActionMenu.Item,{value:`mark-unread`,disabled:D,leadingVisual:(0,U.jsx)(M,{size:16}),onClick:()=>{D||E()},onKeyDown:e=>{!D&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),E())},children:n.markUnreadLabel}):null,R?(0,U.jsx)(H.ActionMenu.Item,{value:`edit`,disabled:p,leadingVisual:(0,U.jsx)(ae,{size:16}),onClick:m,onKeyDown:e=>{!p&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),m())},children:n.editLabel}):null,z&&(E||R)?(0,U.jsx)(`li`,{role:`separator`,className:`review-thread-message__menu-divider`}):null,z?(0,U.jsx)(H.ActionMenu.Item,{value:`delete`,disabled:p||t!==null,className:`review-thread-message__delete-item`,leadingVisual:(0,U.jsx)(O,{size:16}),onClick:b,onKeyDown:e=>{!p&&t===null&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),b())},children:n.deleteLabel}):null]})]})})}):null}),r?(0,U.jsxs)(`form`,{ref:A,className:`review-thread-message__edit`,onSubmit:e=>{e.preventDefault(),c||g()},children:[(0,U.jsx)(mn,{autoFocus:!0,"aria-label":n.editCommentLabel,value:i,rows:3,onValueChange:h}),a?(0,U.jsx)(`span`,{role:`alert`,className:`review-thread-message__error`,children:n.bodyTooLongLabel}):null,s?(0,U.jsx)(`span`,{role:`alert`,className:`review-thread-message__error`,children:n.editErrorLabel}):null,c?(0,U.jsx)(dn,{heading:n.discardHeading,description:n.threadDiscardPromptLabel,cancelLabel:n.keepLabel,confirmLabel:n.discardButtonLabel,compact:!0,onCancel:v,onConfirm:y}):(0,U.jsxs)(`div`,{className:`review-thread-message__actions`,children:[(0,U.jsx)(H.Button,{type:`button`,size:`small`,disabled:l,onClick:_,children:n.cancelEditLabel}),(0,U.jsx)(H.Button,{type:`submit`,size:`small`,variant:`primary`,disabled:i.trim()===``||a||t!==null||l,"aria-busy":l,children:n.saveEditLabel}),l?(0,U.jsx)(ue,{role:`status`,children:n.savingEditLabel}):null]})]}):u?(0,U.jsx)(dn,{heading:n.deleteHeading,description:n.deletePromptLabel,errorLabel:f?n.deleteErrorLabel:void 0,cancelLabel:n.cancelEditLabel,confirmLabel:n.confirmDeleteLabel,loading:d,loadingAnnouncement:n.deletingLabel,compact:!0,onCancel:x,onConfirm:S}):(0,U.jsx)(`p`,{className:e.body?`review-thread-message__body`:`review-thread-message__body review-thread-message__body--deleted`,children:e.body?(0,U.jsx)(xn,{comment:e}):n.deletedCommentLabel}),e.body&&(e.kind!==`root`||e.buildNumber!==null)?(0,U.jsx)(Dn,{comment:e,mutation:t,actionsDisabled:p,controlsHidden:r||u,copy:n,onAdd:C,onRemove:w,onBurst:T}):null]})}function kn({position:e,anchored:t,className:n,style:r,...i}){return(0,U.jsx)(`section`,{...i,role:`dialog`,className:`review-thread-conversation review-thread-conversation--${t?`anchored`:`docked`}${n?` ${n}`:``}`,style:{"--review-thread-left":`${e.left}px`,"--review-thread-top":`${e.top}px`,...r}})}function An(){let e=(0,V.useRef)(null),t=(0,V.useRef)([]),n=(0,V.useRef)(new Map),[r,i]=(0,V.useState)(!1),a=(0,V.useCallback)((e,n,r)=>{if(window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches)return;let a=4+Math.floor(Math.random()*5),o=performance.now();for(let i=0;i{if(!r)return;let a=e.current,o=a?.getContext(`2d`);if(!a||!o){console.error(`Emoji reaction burst could not create a canvas context.`),t.current=[];let e=requestAnimationFrame(()=>i(!1));return()=>cancelAnimationFrame(e)}let s=a,c=o,l;function u(){let e=window.devicePixelRatio||1;s.width=Math.round(window.innerWidth*e),s.height=Math.round(window.innerHeight*e),c.setTransform(e,0,0,e,0,0)}function d(e,t){let r=Math.round(t),i=`${e}_${r}`;if(n.current.has(i))return n.current.get(i)??null;let a=document.createElement(`canvas`);a.width=r*2,a.height=r*2;let o=a.getContext(`2d`);return o?(o.font=`${r}px serif`,o.textAlign=`center`,o.textBaseline=`middle`,o.fillText(e,r,r),n.current.set(i,a),a):(console.error(`Emoji reaction burst could not draw an emoji.`),n.current.set(i,null),null)}function f(e){c.clearRect(0,0,window.innerWidth,window.innerHeight);let n=[];for(let r of t.current){if(e10&&(r.opacity-=.04),r.opacity<=0)continue;let t=d(r.emoji,r.size);t&&(c.globalAlpha=r.opacity,c.drawImage(t,r.x-t.width/2,r.y-t.height/2)),n.push(r)}c.globalAlpha=1,t.current=n,n.length>0?l=requestAnimationFrame(f):i(!1)}return u(),window.addEventListener(`resize`,u),l=requestAnimationFrame(f),()=>{cancelAnimationFrame(l),window.removeEventListener(`resize`,u)}},[r]),{burst:a,canvas:r?(0,tt.createPortal)((0,U.jsx)(`canvas`,{ref:e,className:`review-emoji-burst`,"aria-hidden":`true`}),document.body):null}}var jn=new TextEncoder;function Mn({thread:e,bodyMaximumBytes:t,mutation:n,onClose:r,onDraftStateChange:i,onReply:a,onEdit:o,onDelete:s,onResolve:c,onReopen:l}){let[u,d]=(0,V.useState)(``),[f,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(null),[g,_]=(0,V.useState)(``),[v,y]=(0,V.useState)(``),[b,x]=(0,V.useState)(!1),[S,C]=(0,V.useState)(!1),[w,T]=(0,V.useState)(null),[E,D]=(0,V.useState)(!1),[O,k]=(0,V.useState)(!1),[A,j]=(0,V.useState)(!1),M=u.trim()!==``||m!==null,N=jn.encode(u).length>t,P=jn.encode(g).length>t,F=e.root.resolvedAt!==null,I=e.root.deletedAt!==null||F;(0,V.useEffect)(()=>(i(M),()=>i(!1)),[M,i]);function L(){n||(u.trim()===``&&g===v?r():(C(!1),j(!0)))}function R(){d(``),h(null),_(``),y(``),C(!1),j(!1),i(!1),r()}async function z(){u.trim()===``||N||n||(await a(u)?(d(``),p(!1)):p(!0))}function ee(e){d(e),p(!1),j(!1)}function B(e){e.body&&(h(e.id),_(e.body),y(e.body),x(!1),T(null),D(!1))}function te(e){_(e),x(!1),C(!1),j(!1)}async function ne(e){g.trim()===``||P||n||(await o(e,g)?(h(null),_(``),y(``),C(!1),x(!1)):x(!0))}function re(){g===v?ie():C(!0)}function ie(){h(null),_(``),y(``),x(!1),C(!1),j(!1)}function ae(e){T(e),D(!1)}function oe(){T(null),D(!1)}async function se(e){n||(await s(e)?oe():D(!0))}async function ce(){if(n||M)return;let e=F?await l():await c();k(!e)}return{state:{replyDraft:u,replyFailed:f,editingCommentId:m,editDraft:g,editFailed:b,confirmingEditDiscard:S,confirmingDeleteId:w,deleteFailed:E,resolutionFailed:O,confirmingDiscard:A,draftActive:M,replyBodyTooLong:N,editBodyTooLong:P,resolved:F,replyBlocked:I},actions:{requestDismissal:L,discardAndClose:R,keepDraft:()=>j(!1),submitReply:z,changeReplyDraft:ee,startEdit:B,changeEditDraft:te,saveEdit:ne,cancelEdit:re,keepEdit:()=>C(!1),discardEdit:ie,requestDelete:ae,cancelDelete:oe,deleteComment:se,changeResolution:ce}}}function Nn(e){let t=e.closest(`[data-testid="ActionMenu"]`);if(!t)return;let n=e.getBoundingClientRect(),r=e.closest(`.review-shell`)?.getBoundingClientRect(),i=Math.max(0,r?.top??0),a=Math.min(window.innerHeight,r?.bottom??window.innerHeight);t.style.setProperty(`--review-thread-menu-room-top`,`${Math.max(0,n.top-i-8)}px`),t.style.setProperty(`--review-thread-menu-room-bottom`,`${Math.max(0,a-n.bottom-8)}px`)}function Pn({thread:e,anchorPoint:t,bodyMaximumBytes:n,mutation:r,copy:i,onClose:a,onDraftStateChange:o,onReply:s,onEdit:c,onDelete:l,onResolve:u,onReopen:d,onAddReaction:f,onRemoveReaction:p,onMarkRead:m,onMarkUnread:h}){let g=(0,V.useId)(),_=(0,V.useRef)(null),v=(0,V.useRef)(0),y=(0,V.useRef)(e.root.activityVersion),b=(0,V.useRef)(null),x=(0,V.useRef)(!1),S=(0,V.useRef)(!1),C=(0,V.useRef)(!1),[w,T]=(0,V.useState)(!1),[E,D]=(0,V.useState)(!1),[O,k]=(0,V.useState)(!1),[A,j]=(0,V.useState)(!1),{burst:M,canvas:N}=An(),{state:P,actions:F}=Mn({thread:e,bodyMaximumBytes:n,mutation:r,onClose:a,onDraftStateChange:o,onReply:s,onEdit:c,onDelete:l,onResolve:u,onReopen:d}),I={x:12,y:12},L=[e.root,...e.replies],{cardRef:R,position:z}=hn({anchorPoint:t??I,...t?{anchorSelector:`[data-review-thread-id="${e.root.id}"]`,anchorRectangle:{x:t.x-16,y:t.y-16,width:32,height:32}}:{},layoutKey:[P.confirmingDiscard,P.confirmingEditDiscard,P.replyFailed,P.editFailed,P.deleteFailed,P.resolutionFailed,P.editingCommentId,P.confirmingDeleteId,P.resolved,w,O,e.replies.length,e.participants.length,L.map(e=>e.reactions.length).join(`,`)].join(`:`)}),ee=P.replyBlocked?e.root.deletedAt?i.deletedReplyBlockedLabel:e.root.resolvedBy?i.resolvedByLabel.replace(`%{author}`,e.root.resolvedBy.name||`@${e.root.resolvedBy.login}`):i.resolvedReplyBlockedLabel:null,B=(0,V.useCallback)(()=>{R.current?.querySelector(`.review-thread-conversation__close`)?.focus({preventScroll:!0})},[R]);(0,V.useEffect)(()=>{if(P.confirmingDiscard)R.current?.querySelector(`.review-thread-conversation__footer button`)?.focus({preventScroll:!0});else if(C.current){let e=P.editingCommentId===null?`.review-thread-reply-form textarea`:`.review-thread-message__edit textarea`;R.current?.querySelector(e)?.focus({preventScroll:!0})}C.current=P.confirmingDiscard},[R,P.confirmingDiscard,P.editingCommentId]),(0,V.useEffect)(()=>{let e=document.activeElement;return _.current=e instanceof HTMLElement?e:null,B(),()=>{_.current?.isConnected&&_.current.focus()}},[B]),(0,V.useEffect)(()=>{let t=y.current;e.unread&&b.current!==t&&(b.current=t,x.current=!0,D(!0),m(t).then(e=>T(!e)).catch(()=>T(!0)).finally(()=>{x.current=!1,D(!1)}))},[m,e.unread]);async function te(){if(!(x.current||S.current||r!==null)){b.current=y.current,S.current=!0,j(!0),k(!1);try{let e=await h();k(!e),e&&T(!1)}catch{k(!0)}finally{S.current=!1,j(!1)}}}return(0,V.useEffect)(()=>{function e(){P.confirmingDiscard?F.keepDraft():P.confirmingEditDiscard?F.keepEdit():F.requestDismissal()}function t(t){t.key!==`Escape`||t.defaultPrevented||t.isComposing||R.current?.querySelector(`[role="menu"]`)||t.target instanceof Element&&t.target.closest(`[role="menu"], [role="dialog"], dialog`)||(t.preventDefault(),e())}function n(){let t=document.activeElement;R.current?.querySelector(`[role="menu"]`)||t instanceof Element&&(t.closest(`[role="menu"]`)||t.closest(`[role="dialog"], dialog`)&&!R.current?.contains(t))||e()}return document.addEventListener(`keydown`,t),window.addEventListener(`replica:review-dismiss`,n),()=>{document.removeEventListener(`keydown`,t),window.removeEventListener(`replica:review-dismiss`,n)}},[F,R,P.confirmingDiscard,P.confirmingEditDiscard]),(0,U.jsxs)(kn,{ref:R,"aria-labelledby":g,anchored:!!t,position:z,onKeyDown:e=>{e.key!==`Escape`||e.defaultPrevented||e.nativeEvent.isComposing||e.target instanceof Element&&e.target.closest(`[role="menu"]`)||(e.preventDefault(),P.confirmingDiscard?F.keepDraft():P.confirmingEditDiscard?F.keepEdit():F.requestDismissal())},children:[(0,U.jsxs)(`div`,{className:`review-thread-conversation__layout`,children:[(0,U.jsxs)(`header`,{className:`review-thread-conversation__header`,children:[(0,U.jsx)(H.Heading,{as:`h2`,size:`6`,id:g,children:i.threadHeading}),e.root.buildNumber===null?null:(0,U.jsx)(H.Button,{size:`small`,disabled:P.draftActive||r!==null,"aria-busy":r!==null&&`commentId`in r&&r.commentId===e.root.id&&(r.kind===`resolve`||r.kind===`reopen`),onClick:()=>{F.changeResolution()},children:P.resolved?i.reopenLabel:i.resolveLabel}),r&&`commentId`in r&&r.commentId===e.root.id&&(r.kind===`resolve`||r.kind===`reopen`)?(0,U.jsx)(ue,{role:`status`,children:P.resolved?i.reopeningLabel:i.resolvingLabel}):null,(0,U.jsx)(W,{icon:ne,"aria-label":i.backToCommentsLabel,title:i.backToCommentsLabel,variant:`invisible`,className:`review-thread-conversation__close`,onClick:F.requestDismissal})]}),P.resolutionFailed?(0,U.jsx)(me,{variant:`critical`,title:i.resolutionErrorLabel,className:`review-thread-conversation__banner`}):null,w?(0,U.jsx)(me,{variant:`critical`,title:i.readErrorLabel,className:`review-thread-conversation__banner`}):null,O?(0,U.jsx)(me,{variant:`critical`,title:i.markUnreadErrorLabel,className:`review-thread-conversation__banner`}):null,(0,U.jsx)(`div`,{className:`review-thread-conversation__messages`,onClickCapture:e=>{if(!(e.target instanceof Element))return;let t=e.target.closest(`button[data-testid="ActionMenu-button"]`);t&&e.currentTarget.contains(t)&&(v.current=e.currentTarget.scrollTop,Nn(t))},onScroll:e=>{let t=e.currentTarget.scrollTop,n=t-v.current;if(v.current=t,n===0)return;let r=e.currentTarget.getBoundingClientRect();e.currentTarget.querySelectorAll(`[role="menu"]`).forEach(e=>{let t=e.closest(`[data-testid="ActionMenu"]`)?.querySelector(`button[data-testid="ActionMenu-button"]`);if(!t)return;let i=t.getBoundingClientRect();if(r.height>0&&(i.bottom<=r.top||i.top>=r.bottom)){let n=e.contains(document.activeElement);t.click(),n&&B();return}let a=Number.parseFloat(e.style.top);Number.isFinite(a)&&(e.style.top=`${a-n}px`),Nn(t)})},children:L.map(t=>(0,U.jsx)(On,{comment:t,mutation:r,copy:i,editing:P.editingCommentId===t.id,editDraft:P.editingCommentId===t.id?P.editDraft:``,editBodyTooLong:P.editingCommentId===t.id&&P.editBodyTooLong,editFailed:P.editingCommentId===t.id&&P.editFailed,confirmingEditDiscard:P.editingCommentId===t.id&&P.confirmingEditDiscard,saving:r?.kind===`edit`&&r.commentId===t.id,confirmingDelete:P.confirmingDeleteId===t.id,deleting:r?.kind===`delete`&&r.commentId===t.id,deleteFailed:P.confirmingDeleteId===t.id&&P.deleteFailed,actionsDisabled:r!==null&&r.kind!==`add-reaction`&&r.kind!==`remove-reaction`||P.confirmingDiscard||P.confirmingDeleteId!==null||P.replyDraft.trim()!==``||P.editingCommentId!==null&&P.editingCommentId!==t.id,onStartEdit:()=>F.startEdit(t),onEditDraftChange:F.changeEditDraft,onSaveEdit:()=>{F.saveEdit(t.id)},onCancelEdit:F.cancelEdit,onKeepEdit:F.keepEdit,onDiscardEdit:F.discardEdit,onRequestDelete:()=>F.requestDelete(t.id),onCancelDelete:F.cancelDelete,onDelete:()=>{F.deleteComment(t.id)},onAddReaction:e=>f(t.id,e),onRemoveReaction:e=>p(t.id,e),onBurstReaction:M,onMarkUnread:t.kind===`root`&&e.root.buildNumber!==null?()=>void te():void 0,markUnreadDisabled:E||A||r!==null},t.id))}),e.root.buildNumber!==null||P.confirmingDiscard?(0,U.jsx)(`div`,{className:`review-thread-conversation__footer${ee&&!P.confirmingDiscard?` review-thread-conversation__footer--blocked`:``}`,children:(0,U.jsx)(bn,{blockedLabel:ee,confirmingDiscard:P.confirmingDiscard,replyDraft:P.replyDraft,replyBodyTooLong:P.replyBodyTooLong,replyFailed:P.replyFailed,replyDisabled:r!==null||P.editingCommentId!==null,replying:r?.kind===`reply`&&r.commentId===e.root.id,copy:i,onKeepDraft:F.keepDraft,onDiscardDraft:F.discardAndClose,onSubmit:()=>{F.submitReply()},onDraftChange:F.changeReplyDraft})}):null]}),N]})}function Fn({selectionNotice:e,rateLimitNotice:t,composer:n,conversation:r}){return(0,U.jsxs)(U.Fragment,{children:[e||t?(0,U.jsxs)(`div`,{className:`canvas-selection-notice`,role:`alert`,children:[e?(0,U.jsx)(`div`,{children:e}):null,t?(0,U.jsx)(`div`,{children:t}):null]}):null,n?(0,U.jsx)(`div`,{className:`canvas-composer-shell`,children:(0,U.jsx)(yn,{...n})}):null,r?(0,U.jsx)(`div`,{className:`canvas-conversation-shell`,children:(0,U.jsx)(Pn,{...r},r.thread.root.id)}):null]})}function In({preference:e,disabled:t=!1}){let n=(0,V.useId)(),r=(0,V.useId)(),i=(0,V.useId)(),a=(0,V.useId)();return(0,U.jsxs)(`section`,{className:`canvas-hub-section`,"aria-labelledby":n,children:[(0,U.jsx)(H.Heading,{as:`h3`,size:`subhead-medium`,id:n,children:q.settings}),(0,U.jsxs)(`div`,{className:`canvas-publish-settings__option`,children:[(0,U.jsx)(`label`,{id:r,htmlFor:i,children:q.alwaysCommit}),(0,U.jsx)(ut,{className:`canvas-publish-settings__toggle`,id:i,"aria-labelledby":r,"aria-describedby":e.error?a:void 0,checked:e.remember===!0,disabled:e.loading||e.remember===null,"aria-disabled":e.saving||t||void 0,onChange:n=>{!e.saving&&!t&&e.save(n)},size:`small`})]}),e.error?(0,U.jsxs)(`div`,{id:a,className:`canvas-publish-settings__error`,children:[(0,U.jsx)(me,{title:e.error,variant:`critical`,layout:`compact`}),(0,U.jsx)(H.Button,{size:`small`,disabled:e.loading||e.saving,onClick:()=>void e.retry(),children:q.retrySettings})]}):null]})}function Ln(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Rn(e){return!Ln(e)||typeof e.pathname!=`string`||typeof e.search!=`string`||typeof e.hash!=`string`?null:{pathname:e.pathname,search:e.search,hash:e.hash}}function zn({config:e,active:t=!0,onActivate:n,selectionDisabled:r=!1,onInteractionChange:i,frameRef:a,onRouteChange:o,status:s,onStatusChange:c,onSelectHub:l,onConnect:u,onDisconnected:d,connectionButtonRef:f,connecting:p=!1,publication:m,publicationBusy:h=!1,dirty:g=!1,onPublish:_,onRetryPublication:v,publishPreference:y,open:b,onClose:x}){let[S,C]=(0,V.useState)({identity:``,items:[]}),w=s?.prototype?.repositoryId,T=s?.prototype?.id,E=s?.state===`connected`,D=s?.hubOrigin,O=(0,V.useMemo)(()=>({load:async()=>{if(!E||!D)throw Error(K.mentionSuggestionsError);return cn.parse(await $(`/api/hub/mention-candidates?repositoryId=${w}&prototypeId=${T}`,e.token)).candidates},copy:{suggestions:K.mentionSuggestions,error:K.mentionSuggestionsError,loading:K.mentionSuggestionsLoading,empty:K.mentionSuggestionsEmpty,retry:St.retryLabel,limit:K.mentionLimit}}),[e.token,E,D,w,T]),[k,A]=(0,V.useState)(!1),[j,M]=(0,V.useState)(xt),[P,F]=(0,V.useState)(!0),[I,L]=(0,V.useState)(null),[z,ee]=(0,V.useState)(null),[B,te]=(0,V.useState)(``),[ne,re]=(0,V.useState)(``),[ie,ae]=(0,V.useState)(``),[oe,se]=(0,V.useState)(``),[ce,le]=(0,V.useState)(!1),[ue,W]=(0,V.useState)(!1),[G,de]=(0,V.useState)(!1),[fe,pe]=(0,V.useState)(s?.discovery?.mismatch&&s.discovery.origin||s?.hubOrigin||``),[q,he]=(0,V.useState)(!1),[ge,_e]=(0,V.useState)(!1),[ve,ye]=(0,V.useState)(``),[be,xe]=(0,V.useState)(``),[J,Se]=(0,V.useState)(``),[Ce,we]=(0,V.useState)(!1),[Te,Ee]=(0,V.useState)(null),[De,Oe]=(0,V.useState)(!1),[ke,Y]=(0,V.useState)(new Map),[Ae,Me]=(0,V.useState)(!1),[Ne,Pe]=(0,V.useState)(``),[Fe,Ie]=(0,V.useState)(null),[Le,Re]=(0,V.useState)(!1),[Z,ze]=(0,V.useState)(null),[Be,Ve]=(0,V.useState)(null),[He,Ue]=(0,V.useState)(!1),[We,Ge]=(0,V.useState)(null),Ke=(0,V.useRef)(!1),qe=(0,V.useRef)(0),Je=(0,V.useRef)(!1),Ye=(0,V.useRef)(0),Xe=(0,V.useRef)(``),Ze=(0,V.useRef)(``),Qe=(0,V.useRef)(void 0),$e=(0,V.useRef)(0),et=(0,V.useRef)(null),rt=(0,V.useRef)(null),ot=(0,V.useRef)(!1),st=(0,V.useRef)(``),ut=(0,V.useRef)(b),dt=(0,V.useRef)(void 0),ft=`${s?.hubOrigin??``}/${s?.repository??``}/${s?.branch??``}/${s?.state===`connected`?s.prototype?.id??``:``}`,pt=s?.reviewRevision,mt=pt?.id,ht=`${ft}/revision/${mt??``}`,gt=s?s.discovery?.mismatch&&s.discovery.origin||s.hubOrigin||``:null,_t=(0,V.useRef)(gt),vt=s?.state,Ct=vt===`unavailable`||vt===`denied`,Tt=(0,V.useRef)(vt);(0,V.useEffect)(()=>{if(gt===null||_t.current===gt)return;let e=window.setTimeout(()=>{pe(gt),_t.current=gt},0);return()=>window.clearTimeout(e)},[gt]),(0,V.useEffect)(()=>{if(!vt||Tt.current===vt)return;if(vt!==`connected`&&vt!==`undiscovered`){Tt.current=vt;return}let e=window.setTimeout(()=>{de(!1),Tt.current=vt},0);return()=>window.clearTimeout(e)},[vt]);let Et=un({identity:ft,enabled:s?.repositoryAuthorized===!0,ready:Ae,bridgeProblem:Ne,token:e.token}),Dt=(0,V.useMemo)(()=>S.identity===ht?S.items:[],[S,ht]),Ot=(0,V.useMemo)(()=>wt(Dt),[Dt]),kt=(0,V.useMemo)(()=>{let e=new Map(Ot.flatMap(e=>e.participants.map(e=>[e.login.toLowerCase(),e])));return Array.from(e.values()).sort((e,t)=>(e.name||e.login).localeCompare(t.name||t.login))},[Ot]),At=(0,V.useMemo)(()=>{let e=new Map;for(let t of Ot){let n=t.root.id,r=ke.get(n);if(r)e.set(n,{commentId:n,status:`resolved`,point:r,rect:r.rect});else if(Ae){let r=t.root.anchor.route;e.set(n,{commentId:n,status:I&&(r.pathname!==I.pathname||r.search!==I.search||r.hash!==I.hash)?`route-mismatch`:`missing`})}}return e},[Ae,ke,I,Ot]),jt=Ot.find(e=>e.root.id===z),Q=s?.state===`connected`?s.prototype:null,Mt=s?.state===`disconnected`||s?.state===`pairing`||s?.state===`unconfigured`,Nt=Q?.build?.author.login,Pt=Nt&&/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}(?:\[bot\])?$/i.test(Nt)?`https://github.com/${encodeURIComponent(Nt)}`:null,Ft=Q?.build?.author.name?.trim()||(Pt?Nt:null)||K.unknownCommitAuthor,It=Q?.canEdit&&Q.registered,Lt=Q?.id,Rt=Q?.build??null,zt=Q?.viewerLogin||s?.viewerLogin,Bt=(0,V.useMemo)(()=>zt?Ot.filter(e=>sn(e,{filters:j,viewerLogin:zt,selectedBuildNumber:mt?null:Rt?.number,selectedDraftRevisionId:mt,route:I})):Ot,[Rt?.number,mt,j,I,zt,Ot]),Vt=Bt.length,Ht=Bt.some(e=>e.unread),Ut=!(!pt||s?.reviewError),Wt=!!(s?.repositoryAuthorized&&s.branch&&s.viewerLogin)||!!Q,Gt=Z!==null||De||We!==null||Le||r;(0,V.useLayoutEffect)(()=>{i?.(Z!==null||De||We!==null||Le||Fe!==null||z!==null)},[Z,De,We,Le,Fe,z,i]);let qt=b&&!k,Jt=typeof document>`u`?null:document.getElementById(`canvas-review-controls`),Yt=Z?Z.kind===`element`?{x:Z.rect.x-Z.viewport.scrollX+Z.rect.width*Z.elementOffset.x,y:Z.rect.y-Z.viewport.scrollY+Z.rect.height*Z.elementOffset.y}:ct(Z,{x:Z.rect.x-Z.viewport.scrollX,y:Z.rect.y-Z.viewport.scrollY,width:Z.rect.width,height:Z.rect.height}).point:null;(0,V.useLayoutEffect)(()=>(st.current=ft,$e.current+=1,ot.current=!1,()=>window.clearTimeout(dt.current)),[ft]),(0,V.useLayoutEffect)(()=>{Xe.current=ht,Ye.current+=1},[ht]),(0,V.useLayoutEffect)(()=>{b&&et.current?.focus({preventScroll:!0})},[b]),(0,V.useLayoutEffect)(()=>{!Z&&!We&&!De&&ot.current&&(ot.current=!1,rt.current?.focus({preventScroll:!0}))},[Z,We,De]),(0,V.useEffect)(()=>{let e=ut.current;if(ut.current=b,!b||e||!k)return;if(De){x();return}let t=window.setTimeout(()=>{A(!1),ee(null)},0);return()=>window.clearTimeout(t)},[k,De,x,b]),(0,V.useEffect)(()=>{if(!b)return;function e(e){e.key!==`Escape`||e.defaultPrevented||e.target instanceof Element&&e.target.closest(`[role="dialog"], dialog, [role="menu"]`)||(e.preventDefault(),x())}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[b,x]);let Xt=Ce&&Te===ft,Zt=JSON.stringify(t?Ot.map(({root:e})=>({id:e.id,anchor:e.anchor})):[]),Qt=(0,V.useCallback)(async()=>{if(!Wt||Je.current||Xe.current!==ht)return;let t=ht,n=++Ye.current,r=qe.current;le(!0),W(!1);try{let i=an.parse(await $(`/api/hub/comments${mt?`?${new URLSearchParams({local_revision_id:String(mt)})}`:``}`,e.token));if(Xe.current!==t||Ye.current!==n||qe.current!==r)return;C({identity:t,items:i.comments}),W(!1),te(``)}catch(e){Xe.current===t&&Ye.current===n&&qe.current===r&&(W(!0),te(e instanceof Error?e.message:String(e)))}finally{Xe.current===t&&Ye.current===n&&qe.current===r&&le(!1)}},[e.token,mt,Wt,ht]),$t=(0,V.useRef)(Qt);(0,V.useLayoutEffect)(()=>{$t.current=Qt},[Qt]),(0,V.useEffect)(()=>{let e=window.setTimeout(()=>{C({identity:Xe.current,items:[]}),A(!1),M(xt),F(!0),L(null),ee(null),Oe(!1),we(!1),Ee(null),ye(``),xe(``),Ge(null),Ke.current=!1,Je.current=!1,qe.current+=1,Y(new Map),Me(!1),Ie(null),Re(!1),ze(null),Ve(null),re(``),ae(``),W(!1)},0);return()=>window.clearTimeout(e)},[ft]),(0,V.useEffect)(()=>{if(!Wt)return;let e=window.setTimeout(()=>void Qt(),0);return()=>window.clearTimeout(e)},[Wt,Qt]),(0,V.useEffect)(()=>{if(!Wt)return;let e=window.setInterval(()=>void Qt(),3e4);return()=>window.clearInterval(e)},[Wt,Qt]),(0,V.useEffect)(()=>{if(!Lt)return;let t=new AbortController,n,r=5e3;async function i(){let a=Date.now();try{let n=await fetch(`/api/hub/events`,{headers:{"X-Replica-Canvas-Token":e.token},signal:t.signal});if(!n.ok||!n.body)throw Error(`Live review connection unavailable.`);Ue(!1);let r=n.body.getReader(),i=new TextDecoder,a=``;for(;!t.signal.aborted;){let{value:e,done:t}=await r.read();if(t)throw Error(`Live review connection closed.`);a+=i.decode(e,{stream:!0});let n=a.split(` `);a=n.pop()||``;for(let e of n)if(e.startsWith(`event: comments -`)&&Jt(),e.startsWith(`event: error -`))throw Error(`Live review connection failed.`)}}catch{t.signal.aborted||ze(!0)}t.signal.aborted||(Date.now()-a>=3e4&&(r=5e3),n=window.setTimeout(()=>void i(),r),r=Math.min(r*2,6e4))}return i(),()=>{t.abort(),window.clearTimeout(n)}},[ot,Nt,e.token,Jt]);let Xt=(0,V.useCallback)((n,r={})=>{let i=t.current;return!i?.contentWindow||!qe.current?!1:(i.contentWindow.postMessage({type:n,nonce:qe.current,...r},new URL(e.previewUrl??e.prototypeUrl).origin),!0)},[e.prototypeUrl,e.previewUrl,t]),Zt=(0,V.useCallback)(async t=>{if(e.pickAndPolish||!De||!zt||Vt)return;let n=ot,i=++Ye.current;Je.current=void 0,Pe(!0),ne(``),F(null),Le(null),Me(t),_();try{let a=await $(`/api/hub/status`,e.token);if($e.current!==n||Ye.current!==i)return;if(!a.repositoryAuthorized&&a.state!==`connected`||a.prototype?.id!==Nt||a.hubOrigin!==r?.hubOrigin||a.repository!==r?.repository||a.branch!==r?.branch||!a.reviewRevision)throw Error(a.reviewError||K.commentPreparationFailed);Je.current=a.reviewRevision,Xt(`replica:canvas:select`,{mode:t})}catch(e){$e.current===n&&Ye.current===i&&(Me(null),ne(e instanceof Error?e.message:String(e)))}finally{Ye.current===i&&Pe(!1)}},[e.pickAndPolish,De,zt,e.token,ot,_,Nt,Vt,Xt,r]),Qt=(0,V.useCallback)(()=>{Ae&&(Ye.current+=1,Je.current=void 0,Pe(!1),Xt(`replica:canvas:cancel-selection`),Me(null))},[Ae,Xt]),$t=(0,V.useCallback)(()=>{Ye.current+=1,Je.current=void 0,Xt(`replica:canvas:clear-selection`),Fe(null),Le(null),ne(``)},[Xt]);(0,V.useEffect)(()=>{let r=t.current;if(!r){Ee(new Map),Oe(!1);return}let i=new URL(e.previewUrl??e.prototypeUrl).origin,a=JSON.parse(qt),o=new Set(a.map(({id:e})=>e)),s=Date.now(),c=!1;function l(){qe.current=crypto.randomUUID(),s=Date.now(),c=!1,Oe(!1),Y(``),Ee(new Map),r?.contentWindow?.postMessage({type:`replica:canvas:request-ready`,nonce:qe.current},i),u()}function u(){a.length&&r?.contentWindow?.postMessage({type:`replica:canvas:resolve`,nonce:qe.current,anchors:a},i)}function d(t){let a=t.data;if(t.source===r?.contentWindow&&t.origin===i&&Ln(a)&&a.nonce===qe.current){if(a.type===`replica:canvas:bridge-error`)Oe(!1),Y(K.commentingMissing);else if(a.type===`replica:canvas:ready`){if(a.protocolVersion!==1){c=!0,Oe(!1),Y(K.commentingIncompatible);return}if(!Rn(a.route))return;s=Date.now(),c=!1,Oe(!0),Y(``),M(Rn(a.route)),n?.(Rn(a.route),a.replaceRoute===!0)}else if(!c){if(a.type===`replica:canvas:conversation-dismiss-requested`)window.dispatchEvent(new Event(`replica:review-dismiss`));else if(a.type===`replica:canvas:resolved`){if(a.protocolVersion!==1||!Rn(a.route)||!Array.isArray(a.results))return;s=Date.now(),Oe(!0),Y(``),M(Rn(a.route)),n?.(Rn(a.route),a.replaceRoute===!0);let e=new Map;for(let t of a.results){if(!Ln(t)||typeof t.id!=`number`||typeof t.x!=`number`||typeof t.y!=`number`||!o.has(t.id)||!Number.isFinite(t.x)||!Number.isFinite(t.y)||t.x<0||t.y<0||t.x>r.clientWidth||t.y>r.clientHeight)continue;let n=Ln(t.rect)&&typeof t.rect.x==`number`&&typeof t.rect.y==`number`&&typeof t.rect.width==`number`&&typeof t.rect.height==`number`&&Number.isFinite(t.rect.x)&&Number.isFinite(t.rect.y)&&Number.isFinite(t.rect.width)&&Number.isFinite(t.rect.height)&&t.rect.width>=0&&t.rect.height>=0?{x:t.rect.x,y:t.rect.y,width:t.rect.width,height:t.rect.height}:{x:t.x,y:t.y,width:0,height:0};e.set(t.id,{x:t.x,y:t.y,rect:n})}Ee(e)}else if(a.type===`replica:canvas:selected`){if(e.pickAndPolish)return;let t=Kt.safeParse(a.anchor);if(!t.success){Xt(`replica:canvas:cancel-selection`),Xt(`replica:canvas:clear-selection`),Me(null),Le(Ln(a.anchor)&&a.anchor.kind===`area`?`area-unavailable`:`element-unavailable`);return}Fe(t.data),Me(null),Le(null)}else a.type===`replica:canvas:selection-failed`&&(a.reason===`element-unavailable`||a.reason===`area-too-small`||a.reason===`area-unavailable`)?(Me(null),Le(a.reason)):a.type===`replica:canvas:selection-cancelled`&&Me(null)}}}function f(){Ye.current+=1,Pe(!1),Me(null),Le(null),l()}r.addEventListener(`load`,f),window.addEventListener(`message`,d),l();let p=window.setInterval(()=>{Date.now()-s>=2e4&&(Oe(!1),Ee(new Map),Y(c?K.commentingIncompatible:K.commentingMissing)),r.contentWindow?.postMessage({type:`replica:canvas:request-ready`,nonce:qe.current},i),u()},2e3);return()=>{r.removeEventListener(`load`,f),window.removeEventListener(`message`,d),window.clearInterval(p)}},[ot,qt,e.prototypeUrl,e.pickAndPolish,e.previewUrl,t,n,Xt]);async function en(t,n,r,i){let a=ot,o=dt,s=i?.kind===`add-reaction`||i?.kind===`remove-reaction`||i?.kind===`mark-unread`;if(i){if(He.current)return!1;He.current=!0,Ve(i)}s&&(We.current=!0,Ue.current+=1),re(``);try{let i=await $(`/api/hub/comments/${t}`,e.token,{method:n,...r?{body:JSON.stringify(r)}:{}});if($e.current!==a)return!1;if(s){let e=on.parse(i);y(t=>{if(t.identity!==o)return t;let n=new Map(t.items.map(e=>[e.id,e]));for(let t of e.comments)n.set(t.id,t);return{identity:o,items:[...n.values()]}})}return s||(rt.current=window.setTimeout(()=>void Yt.current(),0)),!0}catch(e){return $e.current===a&&(I(e instanceof Error?e.message:String(e)),e instanceof Error&&`statusCode`in e&&e.statusCode===429&&re(e.message)),!1}finally{i&&$e.current===a&&(s&&(We.current=!1,Ue.current+=1,rt.current=window.setTimeout(()=>void Yt.current(),0)),He.current=!1,Ve(null))}}async function tn(t){let n=Je.current;if(!n||!Z||He.current)return!1;let r=ot,a=dt;He.current=!0,Ve({kind:`create`}),re(``),ne(``);try{let o=on.parse(await $(`/api/hub/comments`,e.token,{method:`POST`,body:JSON.stringify({review_revision:n,review_comment:{body:t,anchor:Z}})}));if($e.current!==r)return!1;let s=o.comments.find(e=>e.kind===`root`);if(!s)return!1;let c=s.buildNumber!==null||s.draftRevisionId===ut;c&&y(e=>{if(e.identity!==a)return e;let t=new Map(e.items.map(e=>[e.id,e]));for(let e of o.comments)t.set(e.id,e);return{identity:a,items:[...t.values()]}});let l=c&&Ke.current===a;return Qe.current=!l,$t(),l&&F(s.id),i().then(()=>{if($e.current===r)return Yt.current()}).catch(e=>{if($e.current===r){let t=e instanceof Error?e.message:String(e);I(K.commentRefreshFailed(t))}}),!0}catch(e){if($e.current===r){let t=e instanceof Error?e.message:String(e);I(t),ne(t),e instanceof Error&&`statusCode`in e&&e.statusCode===429&&re(e.message)}return!1}finally{$e.current===r&&(He.current=!1,Ve(null))}}function nn(){Vt||(T?(F(null),E(!1)):(E(!0),g&&_()))}let rn=r?.repository&&r.branch?`https://github.com/${r.repository.split(`/`).map(e=>encodeURIComponent(e)).join(`/`)}/tree/${encodeURIComponent(r.branch)}`:null,dn=r?.branch&&rn?(0,U.jsxs)(`a`,{className:`canvas-hub-publication__branch`,href:rn,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`Open ${r.branch} on GitHub`,children:[(0,U.jsx)(N,{size:16,"aria-hidden":`true`}),(0,U.jsx)(`span`,{children:r.branch})]}):r?.branch?(0,U.jsxs)(`span`,{className:`canvas-hub-publication__branch`,children:[(0,U.jsx)(N,{size:16,"aria-hidden":`true`}),(0,U.jsx)(`span`,{children:r.branch})]}):null,fn=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(H.Heading,{as:`h3`,size:`subhead-medium`,id:`canvas-hub-origin-title`,children:`Hub`}),r&&r.state!==`unconfigured`?(0,U.jsx)(`div`,{className:`canvas-hub-origin`,children:r.hubOrigin?(0,U.jsx)(`a`,{href:Q?new URL(`/repositories/${Q.repositoryId}/prototypes/${Q.id}`,r.hubOrigin).href:r.hubOrigin,target:`_blank`,rel:`noopener noreferrer`,children:r.hubOrigin}):(0,U.jsx)(`span`,{children:`URL unavailable`})}):null,ce||r?.state===`disconnected`||r?.state===`unconfigured`?(0,U.jsxs)(`form`,{className:`canvas-hub-origin-form`,onSubmit:e=>{e.preventDefault(),!(ue||fe)&&(de(!0),le(!0),I(``),a(W).then(()=>{le(!1)}).catch(e=>I(e.message)).finally(()=>de(!1)))},children:[(0,U.jsxs)(`div`,{className:`canvas-hub-origin-field`,children:[(0,U.jsxs)(`label`,{children:[K.hubUrl,(0,U.jsx)(`input`,{type:`url`,required:!0,value:W,placeholder:`https://hub.example.com`,disabled:ue||fe,onChange:e=>G(e.target.value)})]}),(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:`subtle`,className:`canvas-icon-button`,leadingVisual:(0,U.jsx)(L,{size:16}),"aria-label":K.resetHubUrl,title:K.resetHubUrl,disabled:ue||fe,"aria-busy":fe,onClick:()=>{pe(!0),I(``),$(`/api/hub/discovery`,e.token,{method:`POST`,body:`{}`}).then(async e=>{if(e.discovery?.state!==`valid`||!e.discovery.origin)throw Error(e.discovery?.message||K.resetHubUnavailable);G(e.discovery.origin),await i()}).catch(e=>I(e.message)).finally(()=>pe(!1))},children:(0,U.jsx)(`span`,{className:`visually-hidden`,children:K.resetHubUrl})})]}),(0,U.jsx)(`p`,{children:K.hubHttpsHint}),(0,U.jsxs)(`div`,{className:`canvas-hub-form-actions`,children:[(0,U.jsx)(H.Button,{type:`submit`,size:`small`,disabled:ue||fe,children:`Save Hub`}),ce&&r?.state!==`unconfigured`&&r?.state!==`disconnected`?(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:`subtle`,disabled:ue||fe,onClick:()=>le(!1),children:`Cancel`}):null]})]}):null]});return(0,U.jsxs)(it,{source:w,children:[_t.visible?(0,U.jsx)(ln,{..._t}):null,Bt&&Ut&&!e.pickAndPolish?(0,tt.createPortal)((0,U.jsxs)(`div`,{className:`canvas-review-controls review-shell__comment-actions`,role:`group`,"aria-label":St.heading,children:[(0,U.jsx)(bt,{bridgeReady:De&&zt,copy:St,selectionBlocked:Vt,selecting:Ae!==null,onCancelSelection:Qt,onStartAreaSelection:()=>void Zt(`area`),onStartElementSelection:()=>void Zt(`element`)}),(0,U.jsx)(H.Tooltip,{ref:Ze,text:Vt?St.selectionBlockedLabel:`${St.heading} (${St.sidebarShortcutLabel})`,type:`description`,children:(0,U.jsxs)(H.Button,{className:`canvas-comments-toggle review-shell__comments-toggle`,variant:`secondary`,size:`small`,"aria-label":`${St.heading}, ${Lt}${Rt?`, ${St.unreadLabel}`:``}`,"aria-expanded":T,"aria-keyshortcuts":`Shift+C`,disabled:Vt,onClick:nn,children:[(0,U.jsx)(nt,{children:Lt}),Rt?(0,U.jsx)(`span`,{className:`canvas-comments-unread-badge review-shell__unread-badge`,"aria-hidden":`true`}):null]})})]}),Ut):null,k&&It.length&&De&&!Ae?(0,U.jsx)(`div`,{className:`canvas-marker-layer`,children:(0,U.jsx)(lt,{threads:It,resolutions:Et,selectedThreadId:P,selectionBlocked:Ce,focusSelectedMarker:!1,showAreaHighlightsOnlyWhenSelected:!0,copy:St,onSelect:e=>F(e.root.id)})}):null,(0,U.jsxs)(at,{className:`canvas-hub-panel`,contentClassName:`canvas-hub-content`,title:`Replica Hub`,label:`Hub`,open:Ht,closeLabel:`Close Hub`,closeRef:Xe,onClose:_,children:[ee?(0,U.jsx)(`p`,{role:`alert`,children:ee}):null,z?(0,U.jsx)(`p`,{role:`alert`,children:z}):null,r?null:(0,U.jsx)(`p`,{children:`Checking Hub connection…`}),!Ot&&!ht&&r?.message?(0,U.jsx)(`p`,{role:`status`,children:r.message}):null,ht?(0,U.jsxs)(`div`,{className:`canvas-hub-status`,children:[(0,U.jsx)(me,{variant:`warning`,layout:`compact`,title:r?.message||X.hubUnavailable}),(0,U.jsx)(H.Button,{variant:`primary`,size:`small`,disabled:d,"aria-busy":d,leadingVisual:d?(0,U.jsx)(L,{size:16}):void 0,onClick:m||(()=>void i()),children:X.retry})]}):null,!Ot&&!ht&&u&&p&&m?(0,U.jsx)(je,{publication:u,busy:d,dirty:f,onPublish:p,onRetry:m}):null,Ot?(0,U.jsxs)(`section`,{className:`canvas-hub-connection`,children:[(0,U.jsx)(`p`,{children:K.connectionBeforePublishing}),(0,U.jsx)(H.Button,{ref:c,variant:`primary`,onClick:o,disabled:l,children:l?K.connectionOpeningBrowser:K.connectToHub})]}):null,!Ot&&(!ce&&(r?.discovery?.mismatch||[`invalid`,`unreachable`].includes(r?.discovery?.state||``))||r?.state===`unconfigured`)?(0,U.jsxs)(`div`,{className:`canvas-hub-settings`,children:[!ce&&r?.discovery?.mismatch?(0,U.jsx)(`p`,{role:`alert`,children:`The repository configuration differs from your selected Hub. Your connection has not changed. Disconnect Hub before selecting another URL.`}):null,!ce&&[`invalid`,`unreachable`].includes(r?.discovery?.state||``)?(0,U.jsx)(`p`,{role:`alert`,children:r?.discovery?.message}):null,r?.state===`unconfigured`?(0,U.jsx)(`p`,{children:`Enter your Hub URL to connect.`}):null]}):null,r?.state===`undiscovered`&&!u?(0,U.jsxs)(`p`,{children:[`Connected to `,r.repository,`. Hub has not discovered`,` `,r.branch||`a prototype branch`,`. Your repository connection is ready. Push a named branch to make its Builds and reviews available.`]}):null,Q?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`section`,{className:u&&u.kind!==`ready`&&p&&m?`canvas-hub-publication canvas-hub-publication--after-status`:`canvas-hub-publication`,"aria-label":`Prototype`,children:Mt&&Gt?(0,U.jsxs)(`form`,{className:`canvas-hub-publication__form`,onSubmit:t=>{t.preventDefault(),$(`/api/hub/metadata`,e.token,{method:`PATCH`,body:JSON.stringify({name:q,description:ge,startPage:ve})}).then(async()=>{xe(!1),await i()}).catch(e=>I(e.message))},children:[(0,U.jsxs)(`div`,{className:`canvas-hub-publication__title`,children:[(0,U.jsxs)(`label`,{className:`canvas-hub-publication__name-field`,children:[(0,U.jsx)(`span`,{className:`visually-hidden`,children:`Name`}),(0,U.jsx)(`input`,{required:!0,maxLength:255,value:q,onChange:e=>he(e.target.value)})]}),(0,U.jsx)(`span`,{className:`canvas-hub-publication__status`,children:Q.published?`Published`:Q.registered?`Registered`:`Not registered`})]}),dn,(0,U.jsxs)(`label`,{className:`canvas-hub-publication__description-field`,children:[(0,U.jsx)(`span`,{className:`visually-hidden`,children:`Description`}),(0,U.jsx)(`textarea`,{value:ge,placeholder:`Add a description`,onChange:e=>_e(e.target.value)})]}),(0,U.jsxs)(`label`,{className:`canvas-hub-publication__start-page-field`,children:[K.startPage,(0,U.jsx)(`input`,{value:ve,placeholder:`/`,"aria-describedby":`canvas-start-page-hint`,onChange:e=>ye(e.target.value)})]}),(0,U.jsx)(`p`,{id:`canvas-start-page-hint`,className:`canvas-hub-publication__hint`,children:K.startPageHint}),(0,U.jsxs)(`div`,{className:`canvas-hub-form-actions`,children:[(0,U.jsx)(H.Button,{type:`submit`,size:`small`,children:`Save metadata`}),(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:`subtle`,onClick:()=>xe(!1),children:`Cancel`})]})]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`canvas-hub-publication__title`,children:[(0,U.jsx)(H.Heading,{as:`h3`,size:`subhead-large`,children:Q.name||r?.branch}),(0,U.jsx)(`span`,{className:`canvas-hub-publication__status`,children:Q.published?`Published`:Q.registered?`Registered`:`Not registered`})]}),dn,Q.description?(0,U.jsx)(`p`,{className:`canvas-hub-publication__description`,children:Q.description}):null,(0,U.jsxs)(`p`,{className:`canvas-hub-publication__description canvas-hub-publication__start-page`,children:[K.startPage,`: `,(0,U.jsx)(`code`,{children:Q.startPage||`/`})]}),Mt?(0,U.jsx)(H.Button,{size:`small`,variant:`subtle`,onClick:()=>{he(Q.name||``),_e(Q.description||``),ye(Q.startPage||``),Se(ot),xe(!0)},children:K.editDetails}):null]})}),(0,U.jsxs)(`section`,{className:`canvas-hub-section`,"aria-labelledby":`canvas-hub-build-title`,children:[(0,U.jsx)(H.Heading,{as:`h3`,size:`subhead-medium`,id:`canvas-hub-build-title`,children:K.latestBuild}),Q.build?(0,U.jsxs)(`div`,{className:`canvas-hub-build`,children:[(0,U.jsxs)(`div`,{className:`canvas-hub-build__identity`,children:[(0,U.jsx)(`a`,{href:Q.build.url,target:`_blank`,rel:`noopener noreferrer`,children:K.buildTitle(Q.build.number)}),(0,U.jsx)(`code`,{title:Q.build.commitSha,"aria-label":`${K.buildCommit} ${Q.build.commitSha}`,children:Q.build.commitSha.slice(0,7)})]}),(0,U.jsx)(`p`,{children:At?(0,U.jsx)(`a`,{className:`canvas-hub-build__author`,href:At,target:`_blank`,rel:`noopener noreferrer`,children:jt}):(0,U.jsx)(`span`,{children:jt})}),r?.commitSha&&r.commitSha!==Q.build.commitSha?(0,U.jsx)(`p`,{className:`canvas-hub-build__notice`,children:`Local checkout differs from this Build`}):null]}):(0,U.jsxs)(`p`,{children:[`No successful imported Build yet. Current Build: `,Q.buildState||`none`,`.`]}),Q.build&&r?.hubOrigin?(0,U.jsx)(`a`,{className:`canvas-hub-build__history`,href:new URL(`/repositories/${Q.repositoryId}/prototypes/${Q.id}/builds`,r.hubOrigin).href,target:`_blank`,rel:`noopener noreferrer`,children:K.showBuildHistory}):null]})]}):null,Ot?null:(0,U.jsxs)(`section`,{className:`canvas-hub-section`,"aria-labelledby":`canvas-hub-origin-title`,children:[fn,r?.hubOrigin&&[`connected`,`undiscovered`,`pairing`,`denied`,`unavailable`].includes(r.state)?(0,U.jsx)(`div`,{className:`canvas-hub-disconnect`,children:(0,U.jsx)(H.Button,{size:`small`,variant:`subtle`,onClick:()=>{ie(``),$(`/api/hub/disconnect`,e.token,{method:`POST`,body:`{}`}).then(async()=>{G(r.discovery?.mismatch&&r.discovery.origin||r.hubOrigin||``),le(!0),await i(),s?.()}).catch(e=>{ie(K.disconnectFailed(r.hubOrigin||``,e.message)),G(r.discovery?.mismatch&&r.discovery.origin||r.hubOrigin||``),le(!0)})},children:`Disconnect Hub`})}):null]}),Q?.registered&&Q.build&&h?(0,U.jsx)(In,{preference:h,disabled:d}):null]}),Bt?(0,U.jsx)(yt,{frame:{open:T,className:`canvas-comments-sidebar-shell`,contentClassName:`canvas-comments-sidebar-content`},threads:It,currentBuildNumber:Pt?.number||0,buildLinkOrigin:r?.hubOrigin,totalCount:It.length,hasThreads:Ct.length>0,filters:D,participants:Tt,resolutions:Et,selectedThreadId:P,selectionBlocked:Vt,closeBlocked:Ce,showPins:k,loading:ae,loadFailed:B,notice:Re||r?.reviewError||r?.localCommentsError||ut?(0,U.jsxs)(`div`,{className:`canvas-comments-live-notices`,children:[Re?(0,U.jsx)(`p`,{className:`canvas-comments-live-status`,role:`status`,children:K.commentLiveUpdatesPaused}):null,r?.reviewError?(0,U.jsx)(`p`,{className:`canvas-comments-live-status`,children:r.reviewError}):null,r?.localCommentsError?(0,U.jsx)(`p`,{className:`canvas-comments-live-status`,role:`alert`,children:r.localCommentsError}):null,ut?(0,U.jsx)(`p`,{className:`canvas-comments-live-status`,children:K.localCommentsSaved}):null]}):null,copy:St,onClose:nn,onFiltersChange:O,onShowPinsChange:A,onRetry:()=>void Jt(),onSelect:e=>F(e.root.id)}):null,(0,U.jsx)(Fn,{selectionNotice:Ie?Ie===`area-too-small`?St.areaTooSmallLabel:Ie===`area-unavailable`?St.areaUnavailableLabel:St.selectionFailedLabel:null,rateLimitNotice:Ht?null:R||!Z&&te||null,composer:Z&&Wt?{anchorPoint:Wt,bodyMaximumBytes:1e4,copy:St,creating:Be?.kind===`create`,submitError:te,onSubmit:tn,onDiscard:$t}:null,conversation:Dt?{thread:Dt,anchorPoint:Te.get(Dt.root.id)??null,bodyMaximumBytes:1e4,mutation:Be,copy:St,onClose:()=>F(null),onDraftStateChange:we,onReply:e=>en(`${Dt.root.id}/replies`,`POST`,{review_comment:{body:e}},{kind:`reply`,commentId:Dt.root.id}),onEdit:(e,t)=>en(`${e}`,`PATCH`,{review_comment:{body:t}},{kind:`edit`,commentId:e}),onDelete:e=>en(`${e}`,`DELETE`,void 0,{kind:`delete`,commentId:e}),onResolve:()=>en(`${Dt.root.id}/resolution`,`POST`,void 0,{kind:`resolve`,commentId:Dt.root.id}),onReopen:()=>en(`${Dt.root.id}/resolution`,`DELETE`,void 0,{kind:`reopen`,commentId:Dt.root.id}),onAddReaction:(e,t)=>en(`${e}/reactions`,`POST`,{review_comment_reaction:{content:t,activity_version:Dt.root.activityVersion}},{kind:`add-reaction`,commentId:e,content:t}),onRemoveReaction:(e,t)=>en(`${e}/reactions/${encodeURIComponent(t)}`,`DELETE`,{review_comment_reaction:{activity_version:Dt.root.activityVersion}},{kind:`remove-reaction`,commentId:e,content:t}),onMarkRead:e=>en(`${Dt.root.id}/read`,`POST`,{review_thread_read:{activity_version:e}}),onMarkUnread:()=>en(`${Dt.root.id}/read`,`DELETE`,void 0,{kind:`mark-unread`,commentId:Dt.root.id})}:null})]})}function Bn(e,t,n){function r(e,t,n){return{kind:e,title:t,detail:n}}if(!e||!t)return n.kind===`unknown`?r(`retry`,Y.unavailable,n.detail):r(`checking`,Y.checking,Y.checkingDetail);if(!e.stats.branch)return r(`restricted`,Y.restricted,n.detail);if(t.repository&&t.repository!==e.stats.repository||t.branch&&t.branch!==e.stats.branch)return r(`retry`,Y.unavailable,Y.changedDetail);if(t.discovery?.state===`local`||e.stats.repository?.startsWith(`local/`))return r(`restricted`,Y.restricted,Y.local);if(t.registrationReason===`branch_not_reviewable`||e.stats.branch===t.discovery?.defaultBranch)return r(`restricted`,Y.restricted,X.registrationReasons.get(`branch_not_reviewable`).description);if([`disconnected`,`pairing`,`unconfigured`].includes(t.state))return r(`connect`,Y.connect,Y.connectDetail);if([`denied`,`unavailable`].includes(t.state))return r(`retry`,Y.unavailable,t.message||Y.unavailableDetail);if(t.repository!==e.stats.repository||t.branch!==e.stats.branch)return r(`retry`,Y.unavailable,Y.unavailableDetail);let i=t.prototype;if(t.state===`connected`&&i?.branch===e.stats.branch&&i.registered&&i.published&&i.build&&Number.isSafeInteger(i.build.number)&&i.build.number>0)return r(`ready`,Y.ready,Y.readyDetail);if(t.state===`connected`&&(!i||i.branch!==e.stats.branch||typeof i.published!=`boolean`||i.published))return r(`retry`,Y.unavailable,Y.unavailableDetail);let a=t.state===`connected`?i?.canEdit:t.canPublish;if(a===!1)return r(`restricted`,Y.restricted,Y.publishDenied);let o=e.stats.remoteBranch,s=t.state===`undiscovered`&&t.repositoryAuthorized===!0&&!i&&(!t.commitSha||t.commitSha===e.stats.commitSha)&&o?.repository===e.stats.repository&&o?.branch===e.stats.branch&&o?.commitSha===e.stats.commitSha&&(o?.state===`absent`||o?.state===`present`&&e.publishRequest?.commitSha===e.stats.commitSha&&([`requested`,`in_progress`].includes(e.publishRequest?.state??``)||e.publishRequest?.state===`idle`&&e.publishRequest.remoteState===`absent`))&&![`loading`,`unknown`,`detached`,`workflow_missing`].includes(n.kind),c=a===void 0&&s;if(a!==!0&&!c)return r(`retry`,Y.unavailable,Y.permissionUnknown);let l=t.registrationReason||i?.registrationReason;if(n.error&&(l!==`remote_branch_missing`||!s)){let e=[`successful_build_required`,`already_registered`].includes(l||``),t=[`write_access_required`,`repository_mismatch`,`branch_not_reviewable`,`remote_branch_missing`,`branch_authorship_required`].includes(l||``);return{...r(e?`progress`:t?`restricted`:`retry`,n.error.title,n.error.description),...e?{publication:{...n,action:`retry`,label:X.retry}}:{}}}if(n.kind===`detached`)return r(`restricted`,Y.restricted,n.detail);if(n.action===`retry`)return r(`retry`,Y.unavailable,n.detail);if(n.kind===`loading`)return r(`checking`,Y.checking,n.detail);let u=c?`${Y.publishDetail} ${Y.publishPermissionUnverified}`:Y.publishDetail,d=s&&l===`remote_branch_missing`?{...n,error:void 0}:n;return n.action===`publish`?{...r(`publish`,Y.publish,u),publication:d}:{...r(`progress`,Y.preparing,u),publication:d}}function Vn({open:e,onToggle:t,buttonRef:n}){return(0,U.jsx)(G,{icon:ie,"aria-label":K.controls,description:K.controls,ref:n,size:`small`,variant:`default`,className:`canvas-controls-toggle`,"aria-expanded":e,onClick:t})}function Hn({toolbarRef:e,improvementControlsRef:t,config:n,onPublish:r,publishButtonRef:i,hubButtonRef:a,titleButtonRef:s,onBuildDetails:c,publishing:l,state:u,prototypeName:d,hubOpen:f,onHub:p,publication:m,onControls:h,controlsOpen:g,controlsButtonRef:_,onShare:y,shareButtonRef:b,onImproveContext:x,improvingContext:S=!1,feedbackMessage:C}){let w=u?.publishStatus??{state:`unavailable`,detail:K.statusUnavailable},T=d?.trim()||u?.stats.branch||u?.name||n.name,E=u?[T,u.stats.repository,u.stats.commitSha?.slice(0,7),u.stats.workingTree===`changed`?K.workingTreeChanged:K.workingTreeClean,u.stats.urlHost].filter(Boolean).join(` · `):T,D=l||(m?m.action===`none`:w.state===`requested`||w.state===`in_progress`||w.state===`published`),O=l||(m?m.kind===`requested`||m.kind===`queued`||m.kind===`building`||m.kind===`importing`||m.kind===`awaiting_build`||m.kind===`registration`:w.state===`requested`||w.state===`in_progress`),A=!O&&(m?m.kind===`ready`:w.state===`published`),j=(0,U.jsx)(H.Button,{type:`button`,ref:i,className:`canvas-publish-button`,variant:`secondary`,size:`small`,leadingVisual:O?(0,U.jsx)(L,{size:16}):Wn(w.state),disabled:D&&!A,"aria-busy":O,title:A?void 0:m?.detail||w.detail,onClick:D||A?void 0:r,children:m?.label||K.publishLabels[w.state]});return(0,U.jsxs)(`header`,{ref:e,className:`canvas-toolbar`,children:[(0,U.jsx)(H.Button,{type:`button`,className:`canvas-title`,ref:s,variant:`subtle`,size:`small`,title:E,disabled:!u,onClick:c,children:T}),(0,U.jsx)(`div`,{id:`canvas-review-controls`,className:`canvas-review-controls-slot`}),n.pickAndPolish?(0,U.jsx)(`div`,{ref:t,id:`canvas-improvement-controls`}):null,h?(0,U.jsx)(Vn,{buttonRef:_,open:g,onToggle:h}):null,p?(0,U.jsx)(H.Button,{type:`button`,ref:a,size:`small`,variant:`secondary`,className:`canvas-toolbar-compact-button`,leadingVisual:(0,U.jsx)(oe,{size:16}),"aria-label":K.editDetails,title:K.editDetails,"aria-expanded":f,onClick:p,children:(0,U.jsx)(`span`,{className:`canvas-toolbar-button-label`,children:K.editDetails})}):null,(0,U.jsxs)(`div`,{className:`canvas-publish-share`,role:`group`,"aria-label":J.group,children:[A?(0,U.jsx)(H.Tooltip,{ref:i,text:X.alreadyPublished,type:`description`,children:j}):j,y?(0,U.jsx)(G,{ref:b,icon:v,size:`small`,"aria-label":J.title,description:J.title,onClick:y}):null]}),x?(0,U.jsxs)(H.ActionMenu,{size:`small`,selectionVariant:`none`,menuAlignment:`end`,disabled:S,children:[(0,U.jsx)(H.ActionMenu.IconButton,{icon:o,variant:`secondary`,"aria-label":K.moreActions,"aria-busy":S}),(0,U.jsx)(H.ActionMenu.Overlay,{"aria-label":K.moreActions,children:(0,U.jsx)(Un,{className:`canvas-more-action`,leadingVisual:(0,U.jsx)(k,{size:16}),onClick:x,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),x()),e.key===` `&&(e.preventDefault(),e.currentTarget.click())},children:K.improveContext})})]}):null,C?(0,U.jsx)(`p`,{className:`canvas-feedback-message`,role:`alert`,children:C.message}):null]})}function Un(e){return(0,U.jsx)(H.Tooltip,{text:K.improveContextDescription,type:`description`,direction:`w`,children:(0,U.jsx)(H.ActionMenu.Item,{...e})})}function Wn(e){return e===`published`?(0,U.jsx)(se,{size:16}):e===`failed`||e===`in_progress`||e===`requested`?(0,U.jsx)(L,{size:16}):(0,U.jsx)(D,{size:16})}function Gn(e,t,n){return{status:t?`pending`:e.status,url:n,error:t?``:e.error??``,controls:t?[]:e.scopes.flatMap(e=>e.declaration.controls.map(t=>Ye(e,t)))}}var Kn={bridgeUnavailable:`The prototype bridge is not ready on this page.`,routeChanged:`The prototype route changed. Inspect the live canvas again.`,reloaded:`The prototype reloaded before confirming the click. Inspect the live canvas and retry.`,unconfirmed:`The prototype did not confirm the click. Check its bridge and retry.`,clickFailed:`The target could not be clicked.`,addressUnavailable:`The canvas address field is unavailable.`,unknownAction:`Unknown canvas action.`,replyRejected:`The live canvas rejected the action reply. Check its transport diagnostics.`,actionInterrupted:`The canvas changed before the action could run. Inspect the live canvas and retry.`,statusInterrupted:`The canvas changed while collecting Controls status. Inspect the live canvas and retry.`};function qn(e){let{token:t,prototypeUrl:n,previewUrl:r,cancelClick:i}=e,a=(0,V.useRef)(e),o=(0,V.useRef)(null);(0,V.useLayoutEffect)(()=>{a.current=e}),(0,V.useEffect)(()=>{o.current??=crypto.randomUUID();let e={"X-Replica-Renderer-Id":o.current},s=!1,c=!1,l=new AbortController,u=new URL(r??n).origin;async function d(e){let t=a.current.frameRef.current,n=a.current.liveRoute;if(!t?.contentWindow||!n)throw Error(Kn.bridgeUnavailable);if(e.route.pathname!==n.pathname||e.route.search!==n.search||e.route.hash!==n.hash)throw Error(Kn.routeChanged);let r=crypto.randomUUID();return await new Promise((n,a)=>{function o(){window.clearTimeout(c),window.removeEventListener(`message`,l),i.current===s&&(i.current=null)}function s(){o(),a(Error(Kn.reloaded))}let c=window.setTimeout(()=>{o(),a(Error(Kn.unconfirmed))},2e3);function l(i){let s=i.data;i.source===t?.contentWindow&&i.origin===u&&s&&typeof s==`object`&&`type`in s&&s.type===`replica:canvas:click-result`&&`nonce`in s&&s.nonce===r&&(o(),`clicked`in s&&s.clicked===!0?n({clicked:!0,route:e.route}):a(Error(Kn.clickFailed)))}i.current=s,window.addEventListener(`message`,l),t.contentWindow.postMessage({type:`replica:canvas:click`,nonce:r,...e},u)})}async function f(e){let t=a.current.frameRef.current,r=crypto.randomUUID(),i=Date.now()+e,o=await new Promise((n,o)=>{function s(){window.clearTimeout(d),window.removeEventListener(`message`,p),t?.removeEventListener(`load`,m),l.signal.removeEventListener(`abort`,c)}function c(){s(),o(Error(Kn.statusInterrupted))}let d=window.setTimeout(()=>{if(s(),a.current.liveRoute)o(Error(Kn.bridgeUnavailable));else{let e=new URL(a.current.navigation.entries[a.current.navigation.index]);e.protocol=new URL(u).protocol,e.host=new URL(u).host,n({status:`pending`,url:e.href,error:``,controls:[]})}},e+1500),f=!1;function p(e){let i=e.data;e.source===t?.contentWindow&&t===a.current.frameRef.current&&e.origin===u&&i&&typeof i==`object`&&`type`in i&&(i.type===`replica:canvas:ready`&&!f&&(f=!0,m()),i.type===`replica:controls:status-result`&&`nonce`in i&&i.nonce===r&&`value`in i&&(s(),n(i.value)))}function m(){t===a.current.frameRef.current&&t?.contentWindow?.postMessage({type:`replica:controls:status`,nonce:r,timeoutMs:Math.max(0,i-Date.now())},u)}window.addEventListener(`message`,p),t?.addEventListener(`load`,m),l.signal.addEventListener(`abort`,c),m()});if(!o||typeof o!=`object`||!(`url`in o)||typeof o.url!=`string`||!(`status`in o)||typeof o.status!=`string`||!(`error`in o)||typeof o.error!=`string`||!(`controls`in o)||!Array.isArray(o.controls))throw Error(Kn.bridgeUnavailable);let s=new URL(o.url);if(s.origin!==u)throw Error(Kn.routeChanged);let c=new URL(n);s.protocol=c.protocol,s.host=c.host;let d=await p(i);return!d&&a.current.controlsConnection===void 0?{...o,url:s.href}:{...d?Gn(d,d.loading,s.href):{status:`pending`,url:s.href,error:``,controls:[]},runtime:{status:o.status,error:o.error,controls:o.controls}}}function p(e){let t=a.current.controlsConnection;if(!t)return Promise.resolve(null);let n=t.getSnapshot,r=t.subscribe,i=n();return!i.loading||e<=Date.now()?Promise.resolve(i):new Promise(t=>{let i={};function a(e){window.clearTimeout(c),i.unsubscribe?.(),l.signal.removeEventListener(`abort`,s),t(e)}function o(){let e=n();e.loading||a(e)}function s(){a(null)}let c=window.setTimeout(()=>a(n()),e-Date.now());i.unsubscribe=r(o),l.signal.addEventListener(`abort`,s,{once:!0}),o()})}async function m(){if(!(s||c)){s=!0;try{let{command:r,prototypeUrl:i}=await $(`/api/agent/next`,t,{headers:{...e,"X-Replica-Prototype-Url":n}});if(!c&&i&&i!==n){window.location.reload();return}if(!r)return;let o;try{if(await $(`/api/agent/progress`,t,{method:`POST`,headers:e,body:JSON.stringify({id:r.id,stage:`handler started`})}),c)throw Error(Kn.actionInterrupted);let n;if(r.type===`inspect`){let{appearance:e,navigation:t,liveRoute:r,addressRef:i}=a.current,o=i.current?.value;if(o===void 0)throw Error(Kn.addressUnavailable);n={address:t.entries[t.index],addressDraft:o,appearance:e,canGoBack:t.index>0,canGoForward:t.indexvoid m(),300);return()=>{c=!0,l.abort(),window.clearInterval(h),i.current?.()}},[n,r,t,i])}function Jn(e,t,n){let r=t?.repository===e?.stats.repository&&t?.branch===e?.stats.branch,i=!e?.stats.branch&&!!e?.stats.branchError,a=i?void 0:t?.branch,o=!!(e&&!i&&(t?.repository&&t.repository!==e.stats.repository||t?.branch&&t.branch!==e.stats.branch||t?.commitSha&&t.commitSha!==e.stats.commitSha)),s=!!(n.kind===`ready`&&r&&t?.state===`connected`&&t.prototype?.published&&t.prototype.build?.commitSha===e?.stats.commitSha);return{state:e&&{...e,publishStatus:!s&&[`requested`,`in_progress`].includes(e.publishStatus?.state??``)||t?.state===`connected`&&!r?e.publishStatus:s&&t?.prototype?.build?{state:`published`,detail:K.hubBuildImported,versionCount:t.prototype.versionCount,lastUpdatedAt:t.prototype.build.publishedAt,run:{url:t.prototype.build.url,actor:t.prototype.build.author.login||t.prototype.build.author.name?{login:t.prototype.build.author.login||void 0,name:t.prototype.build.author.name||void 0,avatarUrl:t.prototype.build.author.avatarUrl||void 0}:null}}:{state:t?.state===`connected`?`not_published`:`unavailable`,detail:t?.state===`connected`?K.hubBuildMissing:K.hubPublicationUnavailable},stats:{...e.stats,branch:a||e.stats.branch,branchError:a&&a!==e.stats.branch?null:e.stats.branchError,repository:t?.repository||e.stats.repository,commitSha:e.stats.commitSha,comparison:o?{branch:null,source:null,behind:null,error:K.comparisonNeedsRefresh}:e.stats.comparison,publishedUrl:s?t?.prototype?.build?.url:void 0}},hubPublished:s,comparisonOutdated:o}}function Yn(e,t){let n;function r(e,t,r,i=`none`){return{kind:e,detail:t,label:r,action:i,...n?{error:n}:{}}}if(!e)return r(`loading`,X.initial,X.checking);let{stats:i}=e,a=i.remoteBranch;if(!a||a.state===`loading`)return r(`loading`,X.checkingRemote,X.checking);if(!i.branch||a.state===`detached`)return r(`detached`,X.detached,X.retry,`retry`);if(a.repository!==i.repository||a.branch!==i.branch||a.commitSha!==i.commitSha)return r(`unknown`,X.changed,X.retry,`retry`);if(a.state===`unknown`)return r(`unknown`,X.unknown(a.error),X.retry,`retry`);let o=t?.state===`connected`?t.prototype:void 0,s=o?.build?.commitSha===i.commitSha&&o?.branch===i.branch,c=e.publishRequest,l=t?.state===`connected`&&t.repository===i.repository&&t.branch===i.branch&&(!t.commitSha||t.commitSha===i.commitSha)&&t.prototype?.branch===i.branch&&t.prototype.build?.commitSha===i.commitSha?t.prototype.build:null,u=!!(l&&(c?.commitSha!==i.commitSha||c.buildNumber===void 0||typeof c.buildNumber==`number`&&l.number>c.buildNumber)),d=u&&o?.registered&&o.published,f=t!==null&&t.repository===i.repository&&(!t.branch||t.branch===i.branch)&&(!t.commitSha||t.commitSha===i.commitSha);if(t&&f&&(t.state===`connected`||t.state===`undiscovered`)&&!o?.registered&&(!o||o.branch===i.branch)){let e=t.registrationReason||o?.registrationReason,r=i.branch===t.discovery?.defaultBranch;if(e||t.registrationError||o?.canRegister===!1||r){let i=e||(r?`branch_not_reviewable`:o?.canEdit===!1?`write_access_required`:o?.canRegister===!1&&a.state===`absent`?`remote_branch_missing`:void 0);n=i&&X.registrationReasons.get(i)||{title:X.registrationErrorTitle,description:t.registrationError||X.registrationDenied}}}if(c?.state===`requested`&&(!c.commitSha||c.commitSha===i.commitSha)&&(a.state===`absent`||a.remoteSha!==i.commitSha)&&!u){let e=Date.now()-Date.parse(c.requestedAt||``);if(Number.isFinite(e)&&e<6e5)return r(`requested`,X.pending,X.awaitingCopilot)}if(!t)return r(`loading`,X.checkingHub,X.checking);if(t.state===`disconnected`||t.state===`pairing`||t.state===`unconfigured`)return r(`disconnected`,t.message||X.disconnected,X.connect);if(t.state===`denied`||t.state===`unavailable`)return{...r(`unknown`,t.message||X.hubUnavailable,X.retry,`retry`),error:{title:X.hubUnavailableTitle,description:t.message||X.hubUnavailable}};if(!f)return r(`unknown`,X.staleHub,X.retry,`retry`);if(!i.replicaWorkflowExists)return r(`workflow_missing`,X.workflowMissing,X.retry,`retry`);if(c?.state===`failed`&&!d&&(!c.commitSha||c.commitSha===i.commitSha))return r(`failed`,c.error||X.dispatchFailed,X.retryPublish,`publish`);if(a.state===`absent`)return r(`unpublished`,X.absent,X.publishBranch,`publish`);if(a.remoteSha!==i.commitSha)return r(`needs_push`,X.needsPush,X.publishChanges,`publish`);if(s){if(!o.registered)return r(`registration`,t.registrationError||(o.canEdit&&o.canRegister?X.needsRegistration:X.registrationDenied),t.registrationError?X.registrationFailed:X.registration);if(o.published&&u)return r(`ready`,X.ready,X.published)}if(o?.currentBuild?.commitSha===i.commitSha&&o.branch===i.branch&&o.currentBuild.state===`failed`)return r(`failed`,X.importFailed,X.retryPublish,`publish`);let p=i.workflow;if(!p||p.state===`unavailable`)return r(`unknown`,p?.detail||X.workflowUnavailable,X.retry,`retry`);let m=p.run;if(m&&(m.headSha!==i.commitSha||m.headBranch!==i.branch))return r(`unknown`,X.staleWorkflow,X.retry,`retry`);if(c?.commitSha===i.commitSha&&c.workflowRunId!=null&&m?.databaseId===c.workflowRunId&&!u)return r(`awaiting_build`,X.noBuild,X.awaitingBuild);let h;if(p.state===`in_progress`&&m){let e=[`queued`,`waiting`,`pending`,`requested`].includes(m.status||``);h=r(e?`queued`:`building`,e?X.workflowQueued:X.workflowBuilding,e?X.queued:X.building)}else h=p.state===`failed`&&m?r(`failed`,X.workflowFailed(m.conclusion),X.retryPublish,`publish`):p.state===`succeeded`&&m?r(`importing`,X.importing,X.awaitingHub):r(`awaiting_build`,X.noBuild,X.awaitingBuild);return m?.url?.startsWith(`https://github.com/`)&&(h.runUrl=m.url),h}function Xn({token:e,state:t,hubStatus:n,error:r,setError:i,refresh:a,refreshHub:o,preferenceSaving:s=!1}){let[c,l]=(0,V.useState)(``),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(null),m=(0,V.useRef)(!1),[h,g]=(0,V.useState)(null),[_,v]=(0,V.useState)(``),[y,b]=(0,V.useState)(!1),x=!t&&r?{kind:`unknown`,action:`retry`,label:X.retry,detail:r}:Yn(t,n),S=`${t?.stats.repository}/${t?.stats.branch}/${t?.stats.commitSha}`,C=f?.identity===S&&x.action===`publish`?{...x,kind:`failed`,detail:f.message,label:X.retryPublish}:x.kind===`ready`&&t?.stats.workingTree===`changed`?{...x,kind:`needs_push`,action:`publish`,label:X.publishChanges,detail:X.localChanges}:x,w=Jn(t,n,x);(0,V.useEffect)(()=>{w.comparisonOutdated&&a(!0)},[w.comparisonOutdated,n?.branch,n?.commitSha,n?.repository,a]);async function T(){if(!y){b(!0);try{await Promise.all([a(!0),o()])}finally{b(!1)}}}async function E(){s||(C.action===`retry`?await T():C.action===`none`||m.current||h||await D())}async function D(){if(!(s||m.current)){m.current=!0,d(!0),i(``),v(``);try{let t=await $(`/api/publish/prepare`,e,{method:`POST`,body:`{}`});t.workingTree===`unavailable`||t.workingTree===`changed`&&!t.remember?g({preparation:t}):(g(null),await O(t,t.workingTree===`changed`?`commit-changes`:`committed-only`))}catch(e){let t=e instanceof Error?e.message:String(e);i(t),v(t)}finally{m.current=!1,d(!1)}}}async function O(r,s,c){if(s===`committed-only`&&n?.state===`connected`&&n.repository===r.target.repository&&n.branch===r.target.branch&&n.prototype?.registered&&n.prototype.published&&n.prototype.build?.commitSha===r.target.commitSha&&t?.stats.remoteBranch?.state===`present`&&t.stats.remoteBranch.remoteSha===r.target.commitSha)g(null);else{p(null),v(``),i(``);try{let t=await $(`/api/publish`,e,{method:`POST`,body:JSON.stringify({target:r.target,workingTree:r.workingTree,mode:s,remember:c})});g(null),l(t.message),await o(),await a(!1)}catch(e){let t=e instanceof Error?e.message:String(e);p({message:t,identity:S}),i(t),v(t)}}}async function k(e,t){if(!(s||!h||m.current)){if(h.preparation.workingTree===`unavailable`&&e!==`committed-only`)v(q.checkFailed);else{m.current=!0,d(!0);try{await O(h.preparation,e,t)}finally{m.current=!1,d(!1)}}}}return{publication:C,presentedState:w.state,busy:u||y||s,notice:c,publishDialog:h,publishDialogError:_,closePublishDialog:()=>g(null),choosePublish:k,retryPublishCheck:D,publish:E,retry:T}}var Zn=`replica:controls`;function Qn(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;try{let n=JSON.stringify(e);if(!(typeof n==`string`&&new Blob([n]).size<=512e3&&Object.keys(e).every(e=>[`protocol`,`version`,`epoch`,`requestId`,`type`,`sequence`,`state`,`error`,`command`,`controlQuery`,`fromFrameUrl`].includes(e))&&(t.error===void 0||typeof t.error==`string`&&t.error.length<=1e3)&&(t.controlQuery===void 0||[`hello`,`snapshot`,`reply`].includes(t.type)&&typeof t.controlQuery==`string`&&new Blob([t.controlQuery]).size<=8192)&&(t.fromFrameUrl===void 0||t.type===`hello`&&typeof t.fromFrameUrl==`boolean`)&&t.protocol===`replica:controls`&&t.version===1&&typeof t.epoch==`string`&&/^[a-zA-Z0-9-]{1,100}$/.test(t.epoch)&&typeof t.requestId==`string`&&/^[a-zA-Z0-9-]{1,100}$/.test(t.requestId)&&[`hello`,`snapshot`,`command`,`reply`].includes(t.type)))return!1;if(t.type!==`command`)return t.command===void 0;let r=t.command;if(!r||typeof r!=`object`||Array.isArray(r))return!1;if(r.operation===`url`)return Object.keys(r).every(e=>[`operation`,`query`,`scope`].includes(e))&&(r.scope===void 0||typeof r.scope==`string`&&/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(r.scope))&&typeof r.query==`string`&&new Blob([r.query]).size<=8192&&[...new URLSearchParams(r.query).keys()].every(e=>/^rc\.[a-zA-Z][a-zA-Z0-9_-]{0,63}\.[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(e));if(r.operation===`reset-all`)return Object.keys(r).every(e=>[`operation`,`contexts`].includes(e))&&Array.isArray(r.contexts)&&r.contexts.length<=100&&new Set(r.contexts.map(e=>e?.scope)).size===r.contexts.length&&r.contexts.every(e=>typeof e==`object`&&!!e&&Object.keys(e).length===3&&typeof e.scope==`string`&&/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(e.scope)&&typeof e.fingerprint==`string`&&Number.isSafeInteger(e.revision)&&e.revision>=0);let i=[`operation`,`scope`,`fingerprint`,`revision`];return typeof r.scope!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(r.scope)||typeof r.fingerprint!=`string`||!Number.isSafeInteger(r.revision)||r.revision===void 0||r.revision<0?!1:r.operation===`restore`?Object.keys(r).every(e=>[...i,`values`].includes(e))&&Ce(r.values):r.operation===`reset`?Object.keys(r).every(e=>i.includes(e)):r.operation!==`action`&&r.operation!==`update`||typeof r.id!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(r.id)?!1:Object.keys(r).every(e=>[...i,`id`,...r.operation===`update`?[`value`]:[]].includes(e))&&(r.operation===`action`||Ce({[r.id]:r.value}))}catch{return!1}}function $n(e){return Array.isArray(e)&&e.length<=100&&e.every(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`scope`in e&&typeof e.scope==`string`&&e.scope.length>0&&e.scope.length<=64&&`error`in e&&typeof e.error==`string`&&e.error.length>0&&e.error.length<=500)}function er(e){if(!e||typeof e!=`object`)return!1;let t=e;if(typeof t.runtimeAvailable!=`boolean`||t.reconnectRequired!==void 0&&typeof t.reconnectRequired!=`boolean`||t.status===`ready`&&(!t.runtimeAvailable||!t.scopes?.length)||t.error!==void 0&&(typeof t.error!=`string`||t.error.length>1e3)||t.scopeErrors!==void 0&&!$n(t.scopeErrors)||![`ready`,`no-controls`,`missing-runtime`,`unsupported-runtime`,`invalid-config`].includes(t.status)||!Array.isArray(t.scopes)||t.scopes.length>100||t.status!==`ready`&&t.scopes.length>0)return!1;try{let e=new Set;for(let n of t.scopes){if(We(n.declaration),e.has(n.declaration.scope)||(e.add(n.declaration.scope),n.fingerprint!==JSON.stringify(n.declaration)||!Number.isSafeInteger(n.snapshot.revision)||n.snapshot.revision<0))return!1;let t=n.snapshot;if(!t.values||!t.visible||!t.groups||!t.actions)return!1;function r(e,t){return typeof e==`object`&&!Array.isArray(e)&&Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))}if(!r(t.values,n.declaration.controls.filter(e=>e.type!==`button`).map(e=>e.id))||!r(t.visible,n.declaration.controls.map(e=>e.id))||!r(t.groups,(n.declaration.groups??[]).map(e=>e.id))||!r(t.actions,n.declaration.controls.filter(e=>e.type===`button`).map(e=>e.id))||Object.values(t.groups).some(e=>typeof e!=`boolean`))return!1;if(t.bindings!==void 0){if(!t.bindings||typeof t.bindings!=`object`||Array.isArray(t.bindings))return!1;for(let[e,r]of Object.entries(t.bindings))if(!n.declaration.controls.some(t=>t.id===e)||!r||typeof r.error!=`string`||r.error.length>500||typeof r.busy!=`boolean`||r.available!==void 0&&typeof r.available!=`boolean`)return!1}for(let e of n.declaration.controls){if(typeof t.visible[e.id]!=`boolean`)return!1;if(e.type===`button`){let n=t.actions[e.id];if(!n||typeof n.available!=`boolean`||typeof n.busy!=`boolean`)return!1}else if(Be(e,t.values[e.id]))return!1}}return!0}catch{return!1}}function tr(){return{runtimeAvailable:!1,status:`missing-runtime`,scopes:[],scopeErrors:[],loading:!0,notice:``,error:``,storageError:``,resetting:!1}}var nr=class{frame;origin;api;surface;epoch=``;sequence=-1;state=tr();listeners=new Set;pending=new Map;saved;storageReady=!1;restored=new Set;preparing=new Set;persisted=new Map;cachedScopes=new Map;retryState;resetForIdentity=!1;fromFrameUrl=!1;requests=new AbortController;poll;deadline;saveQueue=Promise.resolve();editQueue=Promise.resolve();stopped=!0;constructor(e,t,n,r=`canvas`){this.frame=e,this.origin=t,this.api=n,this.surface=r}getSnapshot=()=>this.state;getControlValues=()=>{let e=structuredClone(this.saved?.scopes??{}),t=new Map(this.cachedScopes);for(let e of this.state.scopes)t.set(e.declaration.scope,e);for(let[n,r]of t)e[n]=Ze(r);return e};subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});publish(e){this.state={...this.state,...e},this.state.hasResettableValues=Object.values(this.getControlValues()).some(e=>Object.keys(e).length>0);for(let e of[...this.listeners])e()}hasBindingError(e,t){return this.state.scopes.some(n=>(!e||n.declaration.scope===e)&&Object.entries(n.snapshot.bindings??{}).some(([e,n])=>(!t||e===t)&&!!n.error))}checkSaved(e){let t=e,n=/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/;if(!t||typeof t!=`object`||typeof t.identity!=`string`||!t.identity||t.identity.length>128||!t.scopes||typeof t.scopes!=`object`||Array.isArray(t.scopes)||t.storageError!==void 0&&(typeof t.storageError!=`string`||t.storageError.length>1e3)||t.notice!==void 0&&(typeof t.notice!=`string`||t.notice.length>1e3)||new Blob([JSON.stringify(t)]).size>27e4)throw Error(`Invalid controls storage response.`);for(let[e,r]of Object.entries(t.scopes)){if(!n.test(e)||!r||typeof r!=`object`||Array.isArray(r))throw Error(`Invalid controls storage scope.`);for(let[e,t]of Object.entries(r))if(!n.test(e)||!(typeof t==`string`||typeof t==`boolean`||typeof t==`number`&&Number.isFinite(t)||Array.isArray(t)&&t.length<=100&&t.every(e=>typeof e==`string`)))throw Error(`Invalid saved control value.`)}}start=e=>{this.fromFrameUrl=e?.type===`load`&&this.sequence>=0;let t=[...this.pending.values()].some(e=>e.action);this.stop(),this.requests=new AbortController,this.stopped=!1,this.epoch=crypto.randomUUID(),this.sequence=-1,this.saved=void 0,this.storageReady=!1,this.restored.clear(),this.preparing.clear(),this.persisted.clear(),this.editQueue=Promise.resolve(),this.cachedScopes.clear(),this.retryState=void 0,this.resetForIdentity=!1,this.state=tr(),t&&(this.state.notice=`The preview reconnected during an action. Its outcome is unknown; it was not replayed.`),this.publish({});let n=this.epoch;window.addEventListener(`message`,this.receive),this.frame.addEventListener(`load`,this.start);let r=()=>{this.storageReady&&(this.surface===`canvas`&&this.frame.contentWindow?.postMessage({type:`replica:canvas:request-ready`,nonce:n},this.origin),this.send(`hello`).catch(()=>{}))};r(),this.poll=setInterval(()=>{this.state.status===`missing-runtime`&&r()},1e3),this.deadline=setTimeout(()=>{this.state.loading&&this.publish({loading:!1,error:this.surface===`build`?`Build Controls did not connect. Reload the preview or check its definitions.`:K.controlsLocalConnectionFailed})},6e3),this.api().then(e=>{if(!(this.epoch!==n||this.stopped)){if(this.checkSaved(e),this.saved=e,this.retryState?.identity===e.identity)for(let[e,t]of this.retryState.scopes)this.restored.add(`${e}:${t.fingerprint}`),this.cachedScopes.set(e,t);else this.retryState?.identity&&(this.resetForIdentity=!0,this.publish({notice:`The checkout identity changed. Controls will use this branch's saved values or defaults.`}));this.retryState=void 0,this.storageReady=!0,this.publish({storageError:e.storageError||``,notice:e.notice||this.state.notice}),this.prepare(this.state),r()}}).catch(e=>{this.epoch!==n||this.stopped||(this.storageReady=!0,this.publish({storageError:this.surface===`build`?e instanceof Error?e.message:`Control settings could not be read from the URL.`:K.controlsLocalStorageFailed}),this.prepare(this.state),r())})};retry=()=>{let e={identity:this.saved?.identity,scopes:new Map(this.cachedScopes)};this.start(),this.retryState=e};stop=()=>{this.stopped=!0,this.requests.abort(),clearInterval(this.poll),clearTimeout(this.deadline),window.removeEventListener(`message`,this.receive),this.frame.removeEventListener(`load`,this.start);for(let e of this.pending.values())clearTimeout(e.timer),e.reject(Error(`The preview navigated. The command outcome is unknown; it will not be replayed.`));this.pending.clear()};receive=e=>{if(this.stopped||e.source!==this.frame.contentWindow||e.origin!==this.origin||!Qn(e.data))return;let t=e.data;if(t.epoch!==this.epoch||!er(t.state)||!Number.isSafeInteger(t.sequence)||(t.sequence??-1)<0||t.type!==`snapshot`&&t.type!==`reply`)return;let n=this.pending.get(t.requestId);if(t.type!==`reply`||n){if((t.sequence??-1)>this.sequence){if(t.type===`snapshot`&&t.controlQuery!==void 0&&this.saved){let e=De(t.controlQuery),n=this.saved.identity,r=this.epoch;this.stop();let i=new AbortController;this.requests=i,this.publish({loading:!0}),this.api({method:`POST`,signal:i.signal,body:JSON.stringify({identity:n,replace:!0,scopes:e.scopes})}).then(()=>{this.epoch!==r||i.signal.aborted||(this.start(),e.notice&&this.publish({notice:e.notice}))}).catch(e=>{this.epoch!==r||i.signal.aborted||this.publish({loading:!1,storageError:e instanceof Error?e.message:`Controls history could not be restored.`})});return}if(t.controlQuery!==void 0&&this.saved){let e=this.epoch,n=this.requests,r=De(t.controlQuery);this.saved.scopes=r.scopes,this.restored.clear(),this.persisted.clear(),this.cachedScopes.clear(),this.publish({notice:r.notice,loading:!0}),this.api({method:`POST`,signal:n.signal,body:JSON.stringify({identity:this.saved.identity,replace:!0,scopes:r.scopes})}).catch(t=>{this.epoch!==e||this.stopped||n.signal.aborted||this.publish({storageError:t instanceof Error?t.message:`Controls history could not be restored.`})})}this.sequence=t.sequence;let e=t.state.status;this.publish({...t.state,scopeErrors:t.state.scopeErrors??[],reconnectRequired:t.state.reconnectRequired===!0,status:e,error:t.state.error||(this.state.status===`missing-runtime`&&t.state.status!==`missing-runtime`?``:this.state.error),loading:!this.storageReady||this.state.resetting||this.preparing.size>0||this.state.loading&&e===`missing-runtime`}),this.prepare(this.state)}n&&(this.pending.delete(t.requestId),clearTimeout(n.timer),t.error?n.reject(Error(t.error)):n.resolve(this.state))}};send(e,t){let n=crypto.randomUUID(),r={protocol:Zn,version:1,epoch:this.epoch,requestId:n,type:e,...t?{command:t}:{},...e===`hello`?{controlQuery:Ee(this.saved?.scopes??{}),fromFrameUrl:this.fromFrameUrl}:{}};return Qn(r)?new Promise((i,a)=>{let o=setTimeout(()=>{this.pending.delete(n),a(Error(`The command timed out. Its outcome is unknown; it will not be retried automatically.`))},e===`hello`?1200:3e4);this.pending.set(n,{resolve:i,reject:a,timer:o,action:t?.operation===`action`}),this.frame.contentWindow?.postMessage(r,this.origin)}):Promise.reject(Error(`The controls command is invalid or exceeds the size limit.`))}async prepare(e){if(!this.saved&&!this.state.storageError||this.state.resetting||e.reconnectRequired)return;let t=this.epoch;if(this.resetForIdentity&&(e.status===`ready`||e.status===`no-controls`)){this.resetForIdentity=!1,this.publish({loading:!0,resetting:!0});try{await this.send(`command`,{operation:`reset-all`,contexts:e.scopes.map(e=>({scope:e.declaration.scope,fingerprint:e.fingerprint,revision:e.snapshot.revision}))})}catch{this.epoch===t&&this.publish({error:`The checkout changed, but runtime defaults could not be restored. Reload the preview before saving.`,storageError:`Saving is paused until the new checkout's runtime reconnects.`,loading:!1});return}finally{this.epoch===t&&this.publish({resetting:!1})}return this.epoch!==t||this.stopped?void 0:this.prepare(this.state)}for(let n of e.scopes){let e=n.declaration.scope,r=`${e}:${n.fingerprint}`;if(!this.preparing.has(r)){if(!this.restored.has(r)){this.preparing.add(r),this.publish({loading:!0});try{let i=this.saved?.scopes&&Object.hasOwn(this.saved.scopes,e)?this.saved.scopes[e]:{},a=Object.fromEntries(n.declaration.controls.filter(e=>e.type!==`button`).map(e=>[e.id,structuredClone(e.default)])),o=!1;for(let[e,t]of Object.entries(i)){let r=n.declaration.controls.find(t=>t.id===e);!r||Be(r,t)?o=!0:a[e]=t}if(Object.keys(a).length&&await this.send(`command`,{operation:`restore`,scope:e,fingerprint:n.fingerprint,revision:this.state.scopes.find(e=>e.fingerprint===n.fingerprint)?.snapshot.revision,values:a}),this.stopped||this.epoch!==t)return;this.restored.add(r),o&&this.publish({notice:this.surface===`build`?`Some URL control settings no longer match this page. Defaults were used.`:`Some saved controls no longer match this declaration and were discarded.`})}catch(n){if(this.epoch!==t||this.stopped)return;this.hasBindingError(e)||this.publish({error:n instanceof Error?n.message:`Saved controls could not be restored.`}),this.restored.add(r)}finally{this.epoch===t&&this.preparing.delete(r)}}if(this.epoch===t&&!this.stopped){let t=this.state.scopes.find(t=>t.declaration.scope===e);t&&(this.cachedScopes.set(e,t),this.persist(t))}}}this.epoch===t&&!this.stopped&&this.state.status!==`missing-runtime`&&this.publish({loading:this.preparing.size>0})}persist(e){if(!this.saved||this.state.storageError)return;let t=Ze(e),n=JSON.stringify(t);if(this.persisted.get(e.declaration.scope)===n)return;this.persisted.set(e.declaration.scope,n);let r=this.saved.identity,i=this.epoch,a=this.requests.signal;this.saveQueue=this.saveQueue.catch(()=>{}).then(async()=>{if(!(this.epoch!==i||this.stopped))try{if(await this.api({method:`POST`,signal:a,body:JSON.stringify({identity:r,scope:e.declaration.scope,values:t})}),this.epoch===i&&!this.stopped){let t=await this.api();if(this.checkSaved(t),this.epoch!==i||this.stopped)return;this.saved=t,await this.send(`command`,{operation:`url`,scope:e.declaration.scope,query:Ee(t.scopes)})}}catch(e){this.epoch===i&&!this.stopped&&this.publish({storageError:this.surface===`build`&&e instanceof Error?`${e.message} Changes remain in memory and are not in the URL.`:`Controls could not be saved. Changes remain in memory; use Retry to reconnect storage.`})}})}async command(e,t,n,r){if(this.state.loading||this.state.resetting||this.stopped)return;let i=this.epoch,a=this.state.scopes.find(e=>e.declaration.scope===t);if(!a){this.publish({error:`This controls scope is no longer active.`});return}let o=()=>this.applyCommand(e,t,a.fingerprint,i,n,r);if(e!==`update`)return o();let s=this.editQueue.catch(()=>{}).then(o);return this.editQueue=s.then(()=>{}),s}async applyCommand(e,t,n,r,i,a){if(this.epoch!==r||this.stopped||this.state.resetting)return;let o=this.state.scopes.find(e=>e.declaration.scope===t);if(!o||o.fingerprint!==n)this.publish({error:`The controls scope or declaration changed. The command was not applied.`});else{this.publish({error:``});try{if(this.state.reconnectRequired)throw Error(`Reconnect controls before sending more commands.`);if(e===`update`||e===`action`){let t=o.declaration.controls.find(e=>e.id===i);if(!t||!o.snapshot.visible[t.id])throw Error(`This control is unknown or hidden.`);if(e===`update`){let e=Be(t,a);if(e)throw Error(`Control "${t.id}": ${e}`)}else if(t.type!==`button`||!o.snapshot.actions[t.id]?.available||o.snapshot.actions[t.id]?.busy)throw Error(`This action is unavailable or busy.`)}let n=await this.send(`command`,{operation:e,scope:t,fingerprint:o.fingerprint,revision:o.snapshot.revision,...i?{id:i}:{},...e===`update`?{value:a}:{}});if(e===`update`&&i)return{value:n.scopes.find(e=>e.declaration.scope===t)?.snapshot.values[i]}}catch(e){!this.stopped&&this.epoch===r&&!this.hasBindingError(t,i)&&this.publish({error:e instanceof Error?e.message:`Controls command failed.`})}}}async resetAll(){if(this.state.resetting||this.stopped)return;let e=this.epoch;this.publish({resetting:!0});try{let t=``;await this.editQueue.catch(()=>{});let n=this.state.runtimeAvailable&&(this.state.status===`ready`||this.state.status===`no-controls`);if(n)try{await this.send(`command`,{operation:`reset-all`,contexts:this.state.scopes.map(e=>({scope:e.declaration.scope,fingerprint:e.fingerprint,revision:e.snapshot.revision}))})}catch(e){t=e instanceof Error?e.message:`Some app defaults could not be restored.`}if(this.epoch!==e||this.stopped)return;if(!this.saved){let e=await this.api();this.checkSaved(e),this.saved=e}await this.saveQueue.catch(()=>{}),await this.api({method:`POST`,signal:this.requests.signal,body:JSON.stringify({identity:this.saved.identity,reset:!0})}),this.saved.scopes={},await this.send(`command`,{operation:`url`,query:``}),this.cachedScopes.clear(),this.persisted.clear(),this.publish({storageError:``,error:this.hasBindingError()?``:t,notice:n?``:`Saved controls were cleared. Runtime defaults could not be restored until the preview reconnects.`})}catch(t){this.epoch===e&&this.publish({storageError:t instanceof Error?t.message:`Reset could not be saved.`})}finally{this.epoch===e&&this.publish({resetting:!1,loading:!1})}}};function rr(e,t=()=>window.location.href,n=e=>{window.history.replaceState(window.history.state,``,e),window.dispatchEvent(new Event(we))}){return r=>Promise.resolve().then(()=>{r?.signal?.throwIfAborted();let i=De(new URL(t()).search);if(!r)return{identity:e,...i};if(r.method!==`POST`||typeof r.body!=`string`)throw Error(`Invalid URL controls request.`);let a=JSON.parse(r.body);if(!a||typeof a!=`object`||!(`identity`in a)||a.identity!==e)throw Error(`The controls URL identity changed.`);let o=i.scopes;if(`reset`in a&&a.reset===!0)o={};else if(`replace`in a&&a.replace===!0&&`scopes`in a){if(!a.scopes||typeof a.scopes!=`object`||Array.isArray(a.scopes))throw Error(`Invalid controls history settings.`);let e={};for(let[t,n]of Object.entries(a.scopes)){if(!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(t)||!Ce(n))throw Error(`Invalid controls history settings.`);e[t]=n}o=De(Ee(e)).scopes}else{if(!(`scope`in a)||typeof a.scope!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(a.scope)||!(`values`in a)||!Ce(a.values))throw Error(`Invalid URL control settings.`);o={...o,[a.scope]:a.values}}let s=Oe(t(),Ee(o));s!==t()&&n(s)})}function ir({frameRef:e,prototypeUrl:t,previewUrl:n,address:r,replaceAddress:i}){let[a,o]=(0,V.useState)(null),[s,c]=(0,V.useState)(null),l=(0,V.useRef)({address:r,replaceAddress:i});return(0,V.useLayoutEffect)(()=>{l.current={address:r,replaceAddress:i}},[r,i]),(0,V.useEffect)(()=>{if(!e.current)return;let r=new nr(e.current,new URL(n??t).origin,rr(`prototype:${new URL(t).origin}`,()=>l.current.address,e=>{l.current.address=e,l.current.replaceAddress(e)}));o(r);let i=r.subscribe(()=>c(r.getSnapshot()));return r.start(),()=>{i(),r.stop()}},[t,n,e]),{connection:a,state:s}}function ar({token:e,status:t,onStatusChange:n,onSelectHub:r}){let[i,a]=(0,V.useState)(!1),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(``),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(null),m=(0,V.useRef)(!1),h=(0,V.useRef)(!1),g=t?.state===`connected`||t?.state===`undiscovered`,_=t?.state===`disconnected`||t?.state===`pairing`||t?.state===`unconfigured`,v=g?null:t?.pairing||(f?.repository===t?.repository&&f?.hubOrigin===t?.hubOrigin?f?.pairing:null),y=v?.verificationUrl;(0,V.useEffect)(()=>{let e=window.setTimeout(()=>{g?(a(!1),p(null),l(``)):_&&t?.repository&&!m.current&&(m.current=!0,a(!0))},0);return()=>window.clearTimeout(e)},[g,_,t?.repository]),(0,V.useEffect)(()=>{if(!y||u)return;let t=!1,r=!1;async function i(){if(!r){r=!0;try{let r=await $(`/api/hub/poll`,e,{method:`POST`,body:`{}`});if(t)return;r.status!==`pending`&&(p(null),r.status!==`approved`&&l(K.connectionApprovalExpired),await n())}catch(e){t||(l(e instanceof Error?e.message:String(e)),d(!0))}finally{r=!1}}}let a=window.setInterval(()=>void i(),3e3);return()=>{t=!0,window.clearInterval(a)}},[y,u,e,n,t?.repository,t?.hubOrigin]);async function b(i){if(m.current=!0,!h.current){if(!t?.repository)l(K.connectionRepositoryRequired);else if(!t.hubOrigin&&!i)l(K.connectionHubRequired);else{h.current=!0,s(!0),l(``),d(!1);try{!t.hubOrigin&&i&&await r(i);let a=await $(`/api/hub/connect`,e,{method:`POST`,body:`{}`});p({repository:t.repository,hubOrigin:new URL(a.verificationUrl).origin,pairing:a}),a.browserError&&l(K.connectionBrowserFailed(a.browserError)),await n()}catch(e){l(e instanceof Error?e.message:String(e))}finally{h.current=!1,s(!1)}}}}function x(){a(!0),t?.hubOrigin&&b()}return{open:i,close:()=>a(!1),show:()=>a(!0),showAndConnect:x,connect:b,connecting:o,error:c,pairing:v}}function or({token:e,onStatus:t,onError:n}){let[r,i]=(0,V.useState)(null),a=(0,V.useRef)(0),o=(0,V.useRef)(0),s=(0,V.useRef)(!1),c=(0,V.useCallback)(async(r,c=!1)=>{if(s.current||c&&o.current>0)return;o.current+=1;let l=++a.current;try{let o=r===`open`||r===`interaction`,c=await $(o?r===`open`?`/api/hub/open`:`/api/hub/activity`:`/api/hub/status`,e,o?{method:`POST`,body:`{}`}:{});if(l!==a.current||s.current)return;i(c);let u=c.prototype?.startPageImportError||c.localStartPageError;u&&n(u),t(c)}catch(e){if(l!==a.current||s.current)return;let t=e instanceof Error?e.message:String(e);i(e=>({state:`unavailable`,repository:e?.repository,branch:e?.branch,hubOrigin:e?.hubOrigin,message:K.hubStatusUnavailable(t)})),n(t)}finally{--o.current}},[e,t,n]),l=(0,V.useCallback)(async t=>{s.current=!0,a.current+=1,i(null);try{await $(`/api/hub/origin`,e,{method:`POST`,body:JSON.stringify({origin:t})})}finally{s.current=!1,await c()}},[e,c]);(0,V.useEffect)(()=>{let e=window.setTimeout(()=>void c(`open`),0),t=window.setInterval(()=>void c(void 0,!0),15e3);function n(){c(`interaction`)}return window.addEventListener(`focus`,n),()=>{a.current+=1,window.clearTimeout(e),window.clearInterval(t),window.removeEventListener(`focus`,n)}},[c]);async function u(){let t=await $(`/api/hub/discovery`,e,{method:`POST`,body:`{}`});if(t.discovery?.state!==`valid`||!t.discovery.origin)throw Error(t.discovery?.message||K.resetHubUnavailable);return await c(),t.discovery.origin}return{status:r,refresh:c,select:l,reset:u}}function sr({prototypeUrl:e,previewUrl:t,shellRef:n,cancelClick:r}){let[{key:i,ref:a},o]=(0,V.useState)(()=>({key:0,ref:(0,V.createRef)()})),[s,c]=(0,V.useState)({input:e,url:e}),[l,u]=(0,V.useState)({input:e,entries:[e],index:0}),[d,f]=(0,V.useState)(()=>window.matchMedia?.(`(prefers-color-scheme: dark)`)?.matches?`dark`:`light`),[p,m]=(0,V.useState)(null),h=(0,V.useRef)(null),g=l.input===e?l:{input:e,entries:[e],index:0},_=g.entries[g.index],v=(0,V.useCallback)(()=>r.current?.(),[r]),y=(0,V.useCallback)(t=>{if(new URL(t).origin!==new URL(e).origin)throw Error(K.startPageOrigin);u(e=>{let n=[...e.entries];return n[e.index]=t,{...e,entries:n}})},[e]),b=(0,V.useCallback)(t=>{if(h.current===e)return;h.current=e;let n=new URL(e),r=t.state===`connected`&&(t.prototype?.startPageSet??t.prototype?.startPage!==void 0)?t.prototype?.startPage:t.localStartPage;if(n.pathname!==`/`||n.search||n.hash||!r)return;let i=new URL(r,n);if(i.origin!==n.origin)throw Error(K.startPageOrigin);c({input:e,url:i.href}),u({input:e,entries:[i.href],index:0})},[e]);function x(){v(),m(null),c({input:e,url:_}),o(e=>({key:e.key+1,ref:(0,V.createRef)()}))}function S(t){t===_?x():(u(n=>{let r=n.input===e?n:g;return{...r,entries:[...r.entries.slice(0,r.index+1),t],index:r.index+1}}),c({input:e,url:t}))}function C(t){let n=g.entries[t];n&&(u({...g,index:t}),c({input:e,url:n}))}let w=(0,V.useCallback)((t,n=!1)=>{m(t);let r=new URL(e);r.pathname=t.pathname,r.search=t.search,r.hash=t.hash,u(t=>{let i=t.input===e?t:{input:e,entries:[e],index:0},a=new URL(i.entries[i.index]),o=[...a.searchParams].filter(([e])=>e.startsWith(`rc.`));for(let e of[r,a])for(let t of[...e.searchParams.keys()])(t===`rc`||t.startsWith(`rc.`))&&e.searchParams.delete(t);if(a.pathname===r.pathname&&a.searchParams.toString()===r.searchParams.toString()&&a.hash===r.hash)return i;for(let[e,t]of o)r.searchParams.append(e,t);let s=r.href;if(n){let e=[...i.entries];return e[i.index]=s,{...i,entries:e}}return{...i,entries:[...i.entries.slice(0,i.index+1),s],index:i.index+1}})},[e]);(0,V.useEffect)(()=>{let e=a.current;if(!e)return;function t(){v(),m(null)}return e.addEventListener(`load`,t),()=>{v(),e.removeEventListener(`load`,t)}},[v,a]),(0,V.useEffect)(()=>{let r=a.current;if(!r)return;let i=new URL(t??e).origin,o=crypto.randomUUID();function s(){let e=n.current?.closest(`.canvas-base`);e&&r?.contentWindow?.postMessage({type:`replica:canvas:theme`,nonce:o,accent:window.getComputedStyle(e).getPropertyValue(`--hub-accent`).trim()},i)}function c(e){e.source===r?.contentWindow&&e.origin===i&&e.data?.type===`replica:canvas:ready`&&s()}return r.addEventListener(`load`,s),window.addEventListener(`message`,c),s(),()=>{r.removeEventListener(`load`,s),window.removeEventListener(`message`,c)}},[d,e,t,a,n]);let T=new URL(s.input===e?s.url:e);if(t){let e=new URL(t);T.protocol=e.protocol,T.host=e.host}return{frameRef:a,frameKey:i,source:T.href,navigation:g,address:_,replaceAddress:y,appearance:d,setAppearance:f,liveRoute:p,initialize:b,reportRoute:w,reload:x,navigate:S,travel:C}}function cr(e){let[t,n]=(0,V.useState)(null),[r,i]=(0,V.useState)(``),a=(0,V.useRef)(null),o=(0,V.useRef)(0),s=(0,V.useRef)(0),c=(0,V.useCallback)(async(t,r=!1)=>{if(r&&s.current>0)return;s.current+=1;let c=++o.current;try{let r=await $(t?`/api/refresh`:`/api/state`,e,t?{method:`POST`,body:`{}`}:{});if(c!==o.current)return;a.current=r,n(r),i(``)}catch(e){if(c!==o.current)return;n(t=>t&&{...t,stats:{...t.stats,remoteBranch:{state:`unknown`,repository:t.stats.repository||null,branch:t.stats.branch||null,commitSha:t.stats.commitSha||null,error:lr(e)}}}),i(lr(e))}finally{--s.current}},[e]);return(0,V.useEffect)(()=>{let e=window.setTimeout(()=>void c(!0),0),t=window.setInterval(()=>{let e=a.current?.publishStatus?.state,t=a.current?.publishRequest,n=e===`requested`||e===`in_progress`||t?.state===`requested`||!!t?.requestedAt&&(e===`not_published`||e===`unavailable`);c(n,!0)},15e3);function n(){c(!0)}return window.addEventListener(`focus`,n),()=>{o.current+=1,window.clearTimeout(e),window.clearInterval(t),window.removeEventListener(`focus`,n)}},[c]),{state:t,error:r,setError:i,refresh:c}}function lr(e){return e instanceof Error?e.message:String(e)}function ur({token:e,enabled:t,repository:n,branch:r,commitSha:i,publicationRevision:a}){let o=`${n}/${r}/${i}/${a}`,[s,c]=(0,V.useState)(null),[l,u]=(0,V.useState)(!1),[d,f]=(0,V.useState)(!1),p=(0,V.useRef)(null),m=(0,V.useRef)(0),h=t&&s?.identity===o?s:null,g=(0,V.useCallback)(async()=>{if(!t)return;let i=++m.current;u(!0);try{if(await p.current,i!==m.current)return;let t=await $(`/api/publish/prepare`,e,{method:`POST`,body:`{}`});if(i!==m.current)return;if(t.target.repository!==n||t.target.branch!==r)throw Error(q.preferenceTargetChanged);if(typeof t.remember!=`boolean`)throw Error(q.invalidPreference);c({identity:o,preparation:t,error:``})}catch(e){i===m.current&&c({identity:o,preparation:null,error:e instanceof Error?e.message:String(e)})}finally{i===m.current&&u(!1)}},[t,e,n,r,o]);(0,V.useEffect)(()=>{let e=window.setTimeout(()=>void g(),0);return()=>{m.current+=1,window.clearTimeout(e)}},[g]);async function _(n){if(!t||!h?.preparation||l||p.current)return;f(!0);let r=m.current,i=h.preparation,a=(async()=>{try{if((await $(`/api/publish/preference`,e,{method:`POST`,body:JSON.stringify({target:i.target,remember:n})})).remember!==n)throw Error(q.invalidPreference);r===m.current&&c({identity:o,preparation:{...i,remember:n},error:``})}catch(e){r===m.current&&c({identity:o,preparation:i,error:e instanceof Error?e.message:String(e)})}})();p.current=a;try{await a}finally{p.current=null,f(!1)}}return{remember:h?.preparation?.remember??null,loading:l||!h,saving:d,error:h?.error||``,save:_,retry:g}}function dr(e,t,n){let r=n?.included,i=n?.error,a=n?.revision,o=(0,V.useMemo)(()=>{if(r!==void 0)return{identity:e,revision:a,included:r,error:i??``,pending:!1};let t=!1,n=``;if(e)try{let n=localStorage.getItem(`replica:share-controls:v1:${e}`);if(n!==null&&n!==`true`&&n!==`false`)throw Error(`Invalid saved share preference.`);t=n===`true`}catch{n=`The share preference could not be read. Control settings are off by default.`}return{identity:e,revision:a,included:t,error:n,pending:!1}},[e,a,r,i]),[s,c]=(0,V.useState)(o),l=s.identity===e&&s.revision===a?s:o,u=``,d=``;if(l.included)try{u=Ee(t)}catch(e){d=e instanceof Error?e.message:`Control settings could not be shared.`}return{included:l.included,query:u,error:d||l.error,blocked:!!d,...n?{pending:l.pending}:{},onChange:t=>{if(n){c({identity:e,revision:a,included:t,error:``,pending:!0});function r(n){c(r=>r.identity===e&&r.revision===a&&r.included===t?{...r,error:n,pending:!1}:r)}n.onChange(t).then(()=>r(``),e=>r(e instanceof Error?e.message:`This preference could not be saved. It will only apply while this page is open.`));return}let r=``;if(e)try{localStorage.setItem(`replica:share-controls:v1:${e}`,String(t))}catch{r=`This preference could not be saved. It will only apply while this page is open.`}c({identity:e,revision:a,included:t,error:r,pending:!1})}}}function fr({token:e,state:t,hubStatus:n}){let[r,i]=(0,V.useState)(null),a=!!(r&&(r.stale||r.repository!==void 0&&r.repository!==t?.stats.repository||r.branch!==void 0&&r.branch!==t?.stats.branch||n?.hubOrigin!==void 0&&r.hubOrigin!==void 0&&r.hubOrigin!==n.hubOrigin||r.token!==e));(0,V.useEffect)(()=>{if(!r||r.stale)return;let e=r.repository??t?.stats.repository,o=r.branch??t?.stats.branch,s=r.hubOrigin??n?.hubOrigin;if(!a&&e===r.repository&&o===r.branch&&s===r.hubOrigin)return;let c=window.setTimeout(()=>{i(t=>t&&{...t,repository:e,branch:o,hubOrigin:s,stale:a,connecting:!a&&t.connecting})},0);return()=>window.clearTimeout(c)},[r,a,t?.stats.repository,t?.stats.branch,n?.hubOrigin]);function o(){i({repository:t?.stats.repository,branch:t?.stats.branch,hubOrigin:n?.hubOrigin,token:e,connecting:!1,stale:!1})}function s(e){i(t=>t&&{...t,connecting:e})}return{intent:r,targetChanged:a,begin:o,close:()=>i(null),setConnecting:s}}var pr={open:!1,context:null,links:[],loading:!1,busy:!1,stale:!0,error:``,notice:``,created:null};function mr({token:e,hubStatus:t,prototypeState:n}){let[r,i]=(0,V.useState)(pr),a=(0,V.useRef)(r);a.current=r;let o=(0,V.useRef)(0),s=(0,V.useRef)(!1),c=(0,V.useRef)(!1),l=(0,V.useRef)(!1),u=(0,V.useRef)(!1),d=(0,V.useRef)(null),f=`${t?.hubOrigin}/${t?.repository}/${t?.branch}/${t?.state}`,p=(0,V.useRef)(f);p.current=f;let m=(0,V.useCallback)(()=>{!u.current||s.current||c.current||l.current||!d.current||(u.current=!1,d.current())},[]);(0,V.useLayoutEffect)(()=>{o.current+=1,i(e=>e.open?{...pr,open:!0,error:J.stale}:pr)},[f,e]),(0,V.useEffect)(()=>()=>{o.current+=1,u.current=!1},[]),(0,V.useEffect)(()=>{let e=t?.prototype;e&&e.canManageShareLinks!==!0&&a.current.context?.prototype.canManageShareLinks===!0&&(o.current+=1,i(t=>t.open&&t.context?.prototype.id===e.id?{...pr,open:!0,stale:!1,context:{...t.context,prototype:{...t.context.prototype,canManageShareLinks:e.canManageShareLinks}}}:t))},[t?.prototype]),(0,V.useEffect)(()=>{t?.prototype?.publicSharingEnabled===!1&&(o.current+=1,i(e=>e.open?{...pr,open:!0,sharingDisabled:!0,error:J.disabled,context:e.context?{...e.context,prototype:{...e.context.prototype,publicSharingEnabled:!1}}:null}:pr))},[t?.prototype?.publicSharingEnabled]);let h=(0,V.useCallback)((t,n)=>$(`/api/hub/share-links/${t}`,e,{method:`POST`,body:JSON.stringify(n)}),[e]),g=(0,V.useCallback)(e=>{e instanceof Error&&`code`in e&&(e.code===`public_sharing_disabled`||e.code===`public_sharing_changed`||e.code===`creator_access_changed`)&&(o.current+=1,i(t=>({...t,busy:!1,loading:!1,stale:!0,sharingDisabled:e.code===`public_sharing_disabled`,links:[],created:null,authorization:void 0})))},[]),_=(0,V.useCallback)(async(e=a.current.context)=>{if(!e||!e.prototype.canManageShareLinks||e.prototype.publicSharingEnabled===!1||c.current)return;c.current=!0;let t=o.current,n=p.current;i(e=>({...e,loading:!0,stale:!0,error:``}));try{let r=new Map,a=new Set,s=null;do{let i=await h(`list`,{target:e.target,...s?{cursor:s}:{}});if(t!==o.current||n!==p.current)return;for(let e of i.shareLinks)r.set(e.id,e);if(s=i.nextCursor,s){if(a.has(s))throw Error(J.paginationFailed);a.add(s)}}while(s);i(e=>({...e,links:[...r.values()],created:e.created?r.get(e.created.id)??null:null,loading:u.current,stale:u.current,sharingDisabled:!1}))}catch(e){t===o.current&&n===p.current&&(i(t=>({...t,loading:!1,stale:!0,error:e instanceof Error?e.message:J.failed})),g(e))}finally{c.current=!1,m()}},[h,m,g]),v=(0,V.useCallback)(async()=>{if(s.current||l.current||c.current){u.current=!0,i(e=>({...e,open:!0,stale:!0,loading:!0}));return}l.current=!0;let e=++o.current,r=p.current;i({...pr,open:!0,loading:!0});let a=t?.repository===n?.stats.repository&&t?.branch===n?.stats.branch,d=``;if(!t||[`disconnected`,`pairing`,`unconfigured`].includes(t.state)?d=J.disconnected:[`unavailable`,`denied`].includes(t.state)?d=J.unavailable:(t.state!==`connected`||!a)&&(d=J.branch),d)i({...pr,open:!0,error:d}),l.current=!1;else try{let t=await h(`context`,{});if(e!==o.current||r!==p.current)return;i(e=>({...e,context:t,loading:!1,stale:t.prototype.canManageShareLinks===!0})),await _(t)}catch(t){e===o.current&&r===p.current&&i(e=>({...e,loading:!1,error:t instanceof Error?t.message:J.failed}))}finally{l.current=!1,m()}},[t,n,_,h,m]);d.current=v;let y=(0,V.useCallback)(async(e,t)=>{let n=a.current;if(s.current||l.current||c.current||u.current||n.stale||!n.context||n.context.prototype.canManageShareLinks!==!0||n.sharingDisabled||n.context.prototype.publicSharingEnabled===!1)return!1;s.current=!0;let r=o.current;i(e=>({...e,busy:!0,error:``,notice:``}));try{let a=await h(e,{target:n.context.target,...t});return r===o.current&&(i(n=>({...n,notice:e===`delete`?J.deleted:``,authorization:void 0,created:`id`in a?a:e===`delete`&&`id`in t&&n.created?.id===t.id?null:n.created,links:e===`delete`&&`id`in t?n.links.filter(e=>e.id!==t.id):n.links})),await _(n.context),!0)}catch(e){if(r!==o.current)return!1;let t=e instanceof Error&&`code`in e&&e.code===`fresh_authorization_required`&&`authorization`in e&&e.authorization&&typeof e.authorization==`object`&&`url`in e.authorization&&typeof e.authorization.url==`string`&&`expiresAt`in e.authorization&&typeof e.authorization.expiresAt==`string`?{url:e.authorization.url,expiresAt:e.authorization.expiresAt}:void 0,n=e instanceof Error&&(!(`statusCode`in e)||`code`in e&&e.code===`share_delivery_unknown`);return i(r=>({...r,stale:!0,authorization:t,error:n?J.unknown:e instanceof Error?e.message:J.failed})),g(e),!1}finally{s.current=!1,r===o.current&&i(e=>({...e,busy:!1})),m()}},[_,h,m,g]),b=(0,V.useCallback)(async e=>{let t=a.current;if(!t.context||l.current||c.current||u.current)throw Error(J.stale);let n=o.current,r=await h(`controls-preference`,{target:t.context.target,included:e});if(n!==o.current)throw Error(J.stale);if(r.included!==e)throw Error(`The share preference could not be saved.`)},[h]),x=(0,V.useCallback)(async(e,t)=>{let n=a.current;if(!n.context||n.stale||l.current||c.current||u.current)return;let r=o.current;try{await h(`open`,{target:n.context.target,id:e,...t?{controlsQuery:t}:{}})}catch(e){r===o.current&&(i(t=>({...t,error:e instanceof Error?e.message:J.failed})),g(e))}},[h,g]),S=(0,V.useCallback)(async()=>{let e=a.current;if(!e.context||!e.authorization||e.busy)return;let t=o.current;try{await h(`authorize`,{target:e.context.target}),t===o.current&&i(e=>({...e,notice:J.authorizationRetry}))}catch(e){t===o.current&&(i(t=>({...t,error:e instanceof Error?e.message:J.failed})),g(e))}},[h,g]);return(0,V.useEffect)(()=>{if(!r.open||!r.context)return;function e(){s.current||_()}let t=window.setInterval(e,3e4);return window.addEventListener(`focus`,e),()=>{window.clearInterval(t),window.removeEventListener(`focus`,e)}},[r.open,r.context,_]),{state:r,open:v,close:()=>{u.current=!1,i(e=>({...e,open:!1}))},refresh:()=>r.context&&!r.sharingDisabled&&r.context.prototype.publicSharingEnabled!==!1?_():v(),create:(e,t)=>y(`create`,{label:e,expiration:t,buildNumber:r.context?.prototype.build?.number}),remove:e=>y(`delete`,{id:e}),openLink:x,setControlPreference:b,authorize:S}}var hr=`modulepreload`,gr=function(e){return`/assets/`+e},_r={},vr=function(e){return e.pathname.endsWith(`.css`)},yr=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},br=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=gr(t,n);let r=s(t),i=vr(r);return yr(_r,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:hr,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},xr=(0,V.lazy)(()=>br(()=>import(`./renderer-improvement-notes-prototype.js`).then(e=>e.t).then(e=>({default:e.ImprovementNotesPrototype})),__vite__mapDeps([0,1,2,3,4]))),Sr=(0,V.lazy)(()=>br(()=>import(`./renderer-prototype-canvas-thread-sample.js`).then(e=>({default:e.PrototypeCanvasThreadSample})),__vite__mapDeps([5,1,2,3,4])));function Cr({config:e}){let t=(0,V.useRef)(null),n=(0,V.useRef)(null),r=(0,V.useRef)(null),i=(0,V.useRef)(null),a=(0,V.useRef)(null),o=(0,V.useRef)(null),s=(0,V.useRef)(null),c=(0,V.useRef)(null),l=(0,V.useRef)(null),u=(0,V.useRef)(null),[d,f]=(0,V.useState)(!1),[p,m]=(0,V.useState)({position:null,collapsed:!1,collapsedGroups:{}}),[h,g]=(0,V.useState)(!1),[_,v]=(0,V.useState)(null),[y,b]=(0,V.useState)(!1),x=(0,V.useRef)(!1),[S,C]=(0,V.useState)(!1),[w,T]=(0,V.useState)(null),E=(0,V.useCallback)(()=>{g(!1),o.current?.focus()},[]),{frameRef:D,frameKey:O,source:k,navigation:A,address:j,replaceAddress:M,appearance:N,setAppearance:P,liveRoute:F,initialize:ee,reportRoute:I,reload:L,navigate:te,travel:ne}=sr({prototypeUrl:e.prototypeUrl,previewUrl:e.previewUrl,shellRef:t,cancelClick:u}),R=ir({...e,frameRef:D,address:j,replaceAddress:M}),re=R.state;qn({...e,frameRef:D,addressRef:r,appearance:N,navigation:A,liveRoute:F,cancelClick:u,reload:L,controlsConnection:R.connection});let{state:z,error:ie,setError:ae,refresh:oe}=cr(e.token),B=or({token:e.token,onStatus:ee,onError:ae}),se=ar({token:e.token,status:B.status,onStatusChange:B.refresh,onSelectHub:B.select}),ce=JSON.stringify([B.status?.hubOrigin,B.status?.repository,B.status?.branch]),le=B.status?.repositoryAuthorized===!0&&(B.status.state===`connected`||B.status.state===`undiscovered`)&&!!(B.status.repository&&B.status.branch&&B.status.hubOrigin),W=mr({token:e.token,hubStatus:B.status,prototypeState:z}),G=fr({token:e.token,state:z,hubStatus:B.status}),ue=ur({token:e.token,enabled:h&&B.status?.state===`connected`&&B.status.prototype?.registered===!0&&!!B.status.prototype.build&&B.status.repository===z?.stats.repository&&B.status.branch===z?.stats.branch,repository:z?.stats.repository,branch:z?.stats.branch,commitSha:z?.stats.commitSha,publicationRevision:z?.publishRequest?.requestedAt}),de=Xn({token:e.token,state:z,hubStatus:B.status,error:ie,setError:ae,refresh:oe,refreshHub:B.refresh,preferenceSaving:ue.saving}),fe=Bn(z,B.status,de.publication),pe=W.state.context,me=dr(pe?`${pe.hubOrigin}:${pe.prototype.repositoryId}:${pe.prototype.id}`:void 0,R.connection?.getControlValues()??{},{included:pe?.controlSettingsIncluded??!1,error:pe?.controlSettingsError,revision:pe?.target,onChange:W.setControlPreference});(0,V.useLayoutEffect)(()=>{document.body.classList.remove(`renderer-loading`);let e=t.current,r=n.current;if(!e||!r)return;function i(){let t=r?.getBoundingClientRect().height;t&&e?.style.setProperty(`--canvas-toolbar-height`,`${t}px`)}let a=new ResizeObserver(i);return a.observe(r),i(),()=>a.disconnect()},[]);function q(){se.close(),fe.kind===`ready`?W.open():G.begin()}async function he(){if(le&&!x.current){x.current=!0,C(!0),T(null);try{if((await $(`/api/hub/feedback-review`,e.token,{method:`POST`,body:JSON.stringify({repository:B.status?.repository,branch:B.status?.branch,hubOrigin:B.status?.hubOrigin})})).requested!==!0)throw Error(K.invalidResponse)}catch(e){T({target:ce,message:K.feedbackReviewFailed(e instanceof Error?e.message:String(e))}),await B.refresh()}finally{x.current=!1,C(!1)}}}return(0,U.jsxs)(H.ThemeProvider,{colorMode:N,className:`canvas-base`,children:[(0,U.jsxs)(`main`,{ref:t,className:`canvas-shell${W.state.open?` canvas-shell--inactive`:``}`,inert:W.state.open,"aria-hidden":W.state.open?!0:void 0,children:[(0,U.jsx)(Pe,{address:j,addressRef:r,canGoBack:A.index>0,canGoForward:A.indexne(A.index-1),onForward:()=>ne(A.index+1),onNavigate:te,onOpenTab:async()=>{await $(`/api/prototype/open`,e.token,{method:`POST`,body:JSON.stringify({url:j})})},onReload:L}),(0,U.jsx)(Hn,{toolbarRef:n,improvementControlsRef:v,config:e,state:de.presentedState,prototypeName:B.status?.state===`connected`&&B.status.prototype?.name||void 0,publishing:de.busy,publication:de.publication,publishButtonRef:i,hubButtonRef:o,titleButtonRef:c,onBuildDetails:()=>b(!0),controlsButtonRef:l,controlsOpen:d,onControls:()=>f(!d),onPublish:()=>void de.publish(),onShare:q,onImproveContext:le?()=>void he():void 0,improvingContext:S,feedbackMessage:w?.target===ce?w:void 0,shareButtonRef:a,hubOpen:h,onHub:()=>{g(!h),B.refresh(`interaction`)}}),(0,U.jsx)(`iframe`,{ref:D,className:`prototype-frame`,title:K.prototypeFrameTitle(e.name),src:k,style:{colorScheme:N,backgroundColor:`var(--hub-canvas-default)`}},O),(0,U.jsx)(zn,{config:e,frameRef:D,onRouteChange:I,status:B.status,onStatusChange:B.refresh,onSelectHub:B.select,onConnect:se.showAndConnect,onDisconnected:se.show,connectionButtonRef:s,connecting:se.connecting,publication:de.publication,publicationBusy:de.busy,dirty:z?.stats.workingTree===`changed`,onPublish:()=>void de.publish(),onRetryPublication:()=>void de.retry(),publishPreference:ue,open:h,onClose:E}),e.improvementThreadsSample?(0,U.jsx)(V.Suspense,{fallback:(0,U.jsx)(`p`,{role:`status`,children:K.improvementNotesLoading}),children:(0,U.jsx)(Sr,{})}):e.pickAndPolish?(0,U.jsx)(V.Suspense,{fallback:(0,U.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:K.improvementNotesLoading}),children:(0,U.jsx)(xr,{canvas:{token:e.token,frameRef:D,toolbarTarget:_,prototypeUrl:e.prototypeUrl,previewUrl:e.previewUrl,hubOpen:h,onOpenNotes:()=>g(!1),onNavigate:te}})}):null,d&&R.connection&&re?(0,U.jsx)(et,{state:re,connection:R.connection,layout:p,onLayoutChange:m,diagnosisTarget:j,onDiagnose:()=>$(`/api/controls/diagnose`,e.token,{method:`POST`,body:JSON.stringify({status:re.status,runtimeAvailable:re.runtimeAvailable,reconnectRequired:re.reconnectRequired===!0,hasError:!!re.error||Gn(re,re.loading,j).controls.some(e=>e.visible&&!!e.error),hasStorageError:!!re.storageError,previewUrl:j})})}):null]}),(0,U.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`visually-hidden`,children:ie||de.notice}),(0,U.jsx)(Ne,{hub:B,connection:se,publication:de,sharing:W,shareIntent:G,controlSettings:me,readiness:fe,state:z,hubOpen:h,buildDetailsOpen:y,onCloseBuildDetails:()=>b(!1),shareButtonRef:a,hubButtonRef:o,connectionButtonRef:s,publishButtonRef:i,titleButtonRef:c})]})}var wr=document.querySelector(`#root`);if(!wr)throw Error(`Replica prototype renderer root is missing.`);(0,ce.createRoot)(wr).render((0,U.jsx)(Cr,{config:window.__REPLICA_CANVAS__}));export{$ as a,Bt as c,ot as d,at as f,G as h,hn as i,St as l,ue as m,Sn as n,qt as o,nt as p,bn as r,Kt as s,kn as t,st as u}; \ No newline at end of file +`)&&Qt(),e.startsWith(`event: error +`))throw Error(`Live review connection failed.`)}}catch{t.signal.aborted||Ue(!0)}t.signal.aborted||(Date.now()-a>=3e4&&(r=5e3),n=window.setTimeout(()=>void i(),r),r=Math.min(r*2,6e4))}return i(),()=>{t.abort(),window.clearTimeout(n)}},[ft,Lt,e.token,Qt]);let en=(0,V.useCallback)((t,n={})=>{let r=a.current;return!r?.contentWindow||!Ze.current?!1:(r.contentWindow.postMessage({type:t,nonce:Ze.current,...n},new URL(e.previewUrl??e.prototypeUrl).origin),!0)},[e.prototypeUrl,e.previewUrl,a]),tn=(0,V.useCallback)(async t=>{if(!Ae||!Ut||Gt)return;n?.();let r=ft,i=++$e.current;Qe.current=void 0,Re(!0),re(``),ee(null),Ve(null),Ie(t),x();try{let n=await $(`/api/hub/status`,e.token);if(st.current!==r||$e.current!==i)return;if(!n.repositoryAuthorized&&n.state!==`connected`||n.prototype?.id!==Lt||n.hubOrigin!==s?.hubOrigin||n.repository!==s?.repository||n.branch!==s?.branch||!n.reviewRevision)throw Error(n.reviewError||K.commentPreparationFailed);Qe.current=n.reviewRevision,en(`replica:canvas:select`,{mode:t})}catch(e){st.current===r&&$e.current===i&&(Ie(null),re(e instanceof Error?e.message:String(e)))}finally{$e.current===i&&Re(!1)}},[n,Ae,Ut,e.token,ft,x,Lt,Gt,en,s]),nn=(0,V.useCallback)(()=>{Fe&&($e.current+=1,Qe.current=void 0,Re(!1),en(`replica:canvas:cancel-selection`),Ie(null))},[Fe,en]),rn=(0,V.useCallback)(()=>{$e.current+=1,Qe.current=void 0,en(`replica:canvas:clear-selection`),ze(null),Ve(null),re(``)},[en]),dn=(0,V.useEffectEvent)(e=>{if(t&&Fe&&!Le){if(e.type===`replica:canvas:selected`){let t=Kt.safeParse(e.anchor);if(!t.success){en(`replica:canvas:cancel-selection`),en(`replica:canvas:clear-selection`),Ie(null),Ve(Ln(e.anchor)&&e.anchor.kind===`area`?`area-unavailable`:`element-unavailable`);return}ze(t.data),Ie(null),Ve(null)}else e.type===`replica:canvas:selection-failed`&&(e.reason===`element-unavailable`||e.reason===`area-too-small`||e.reason===`area-unavailable`)?(Ie(null),Ve(e.reason)):e.type===`replica:canvas:selection-cancelled`&&Ie(null)}});(0,V.useEffect)(()=>{let n=a.current;if(!n){Y(new Map),Me(!1);return}let r=new URL(e.previewUrl??e.prototypeUrl).origin,i=JSON.parse(Zt),s=new Set(i.map(({id:e})=>e)),c=Date.now(),l=!1;function u(){Ze.current=crypto.randomUUID(),c=Date.now(),l=!1,Me(!1),Pe(``),Y(new Map),n?.contentWindow?.postMessage({type:`replica:canvas:request-ready`,nonce:Ze.current},r),d()}function d(){t&&i.length&&n?.contentWindow?.postMessage({type:`replica:canvas:resolve`,nonce:Ze.current,anchors:i},r)}function f(e){let t=e.data;if(e.source===n?.contentWindow&&e.origin===r&&Ln(t)&&t.nonce===Ze.current){if(t.type===`replica:canvas:bridge-error`)Me(!1),Pe(K.commentingMissing);else if(t.type===`replica:canvas:ready`){if(t.protocolVersion!==1){l=!0,Me(!1),Pe(K.commentingIncompatible);return}if(!Rn(t.route))return;c=Date.now(),l=!1,Me(!0),Pe(``),L(Rn(t.route)),o?.(Rn(t.route),t.replaceRoute===!0)}else if(!l){if(t.type===`replica:canvas:conversation-dismiss-requested`)window.dispatchEvent(new Event(`replica:review-dismiss`));else if(t.type===`replica:canvas:resolved`){if(t.protocolVersion!==1||!Rn(t.route)||!Array.isArray(t.results))return;c=Date.now(),Me(!0),Pe(``),L(Rn(t.route)),o?.(Rn(t.route),t.replaceRoute===!0);let e=new Map;for(let r of t.results){if(!Ln(r)||typeof r.id!=`number`||typeof r.x!=`number`||typeof r.y!=`number`||!s.has(r.id)||!Number.isFinite(r.x)||!Number.isFinite(r.y)||r.x<0||r.y<0||r.x>n.clientWidth||r.y>n.clientHeight)continue;let t=Ln(r.rect)&&typeof r.rect.x==`number`&&typeof r.rect.y==`number`&&typeof r.rect.width==`number`&&typeof r.rect.height==`number`&&Number.isFinite(r.rect.x)&&Number.isFinite(r.rect.y)&&Number.isFinite(r.rect.width)&&Number.isFinite(r.rect.height)&&r.rect.width>=0&&r.rect.height>=0?{x:r.rect.x,y:r.rect.y,width:r.rect.width,height:r.rect.height}:{x:r.x,y:r.y,width:0,height:0};e.set(r.id,{x:r.x,y:r.y,rect:t})}Y(e)}else dn(t)}}}function p(){$e.current+=1,Re(!1),Ie(null),Ve(null),u()}n.addEventListener(`load`,p),window.addEventListener(`message`,f),u();let m=window.setInterval(()=>{Date.now()-c>=2e4&&(Me(!1),Y(new Map),Pe(l?K.commentingIncompatible:K.commentingMissing)),n.contentWindow?.postMessage({type:`replica:canvas:request-ready`,nonce:Ze.current},r),d()},2e3);return()=>{n.removeEventListener(`load`,p),window.removeEventListener(`message`,f),window.clearInterval(m)}},[ft,Zt,e.prototypeUrl,t,e.previewUrl,a,o,en]);async function fn(t,n,r,i){let a=ft,o=ht,s=i?.kind===`add-reaction`||i?.kind===`remove-reaction`||i?.kind===`mark-unread`;if(i){if(Ke.current)return!1;Ke.current=!0,Ge(i)}s&&(Je.current=!0,qe.current+=1),ae(``);try{let i=await $(`/api/hub/comments/${t}`,e.token,{method:n,...r?{body:JSON.stringify(r)}:{}});if(st.current!==a)return!1;if(s){let e=on.parse(i);C(t=>{if(t.identity!==o)return t;let n=new Map(t.items.map(e=>[e.id,e]));for(let t of e.comments)n.set(t.id,t);return{identity:o,items:[...n.values()]}})}return s||(dt.current=window.setTimeout(()=>void $t.current(),0)),!0}catch(e){return st.current===a&&(te(e instanceof Error?e.message:String(e)),e instanceof Error&&`statusCode`in e&&e.statusCode===429&&ae(e.message)),!1}finally{i&&st.current===a&&(s&&(Je.current=!1,qe.current+=1,dt.current=window.setTimeout(()=>void $t.current(),0)),Ke.current=!1,Ge(null))}}async function pn(t){let n=Qe.current;if(!n||!Z||Ke.current)return!1;let r=ft,i=ht;Ke.current=!0,Ge({kind:`create`}),ae(``),re(``);try{let a=on.parse(await $(`/api/hub/comments`,e.token,{method:`POST`,body:JSON.stringify({review_revision:n,review_comment:{body:t,anchor:Z}})}));if(st.current!==r)return!1;let o=a.comments.find(e=>e.kind===`root`);if(!o)return!1;let s=o.buildNumber!==null||o.draftRevisionId===mt;s&&C(e=>{if(e.identity!==i)return e;let t=new Map(e.items.map(e=>[e.id,e]));for(let e of a.comments)t.set(e.id,e);return{identity:i,items:[...t.values()]}});let l=s&&Xe.current===i;return ot.current=!l,rn(),l&&ee(o.id),c().then(()=>{if(st.current===r)return $t.current()}).catch(e=>{if(st.current===r){let t=e instanceof Error?e.message:String(e);te(K.commentRefreshFailed(t))}}),!0}catch(e){if(st.current===r){let t=e instanceof Error?e.message:String(e);te(t),re(t),e instanceof Error&&`statusCode`in e&&e.statusCode===429&&ae(e.message)}return!1}finally{st.current===r&&(Ke.current=!1,Ge(null))}}function mn(){Gt||(k&&t?(ee(null),A(!1)):(n?.(),A(!0),b&&x()))}let hn=s?.repository&&s.branch?`https://github.com/${s.repository.split(`/`).map(e=>encodeURIComponent(e)).join(`/`)}/tree/${encodeURIComponent(s.branch)}`:null,gn=s?.branch&&hn?(0,U.jsxs)(`a`,{className:`canvas-hub-publication__branch`,href:hn,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`Open ${s.branch} on GitHub`,children:[(0,U.jsx)(N,{size:16,"aria-hidden":`true`}),(0,U.jsx)(`span`,{children:s.branch})]}):s?.branch?(0,U.jsxs)(`span`,{className:`canvas-hub-publication__branch`,children:[(0,U.jsx)(N,{size:16,"aria-hidden":`true`}),(0,U.jsx)(`span`,{children:s.branch})]}):null,_n=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(H.Heading,{as:`h3`,size:`subhead-medium`,id:`canvas-hub-origin-title`,children:`Hub`}),s&&s.state!==`unconfigured`?(0,U.jsx)(`div`,{className:`canvas-hub-origin`,children:s.hubOrigin?(0,U.jsx)(`a`,{href:Q?new URL(`/repositories/${Q.repositoryId}/prototypes/${Q.id}`,s.hubOrigin).href:s.hubOrigin,target:`_blank`,rel:`noopener noreferrer`,children:s.hubOrigin}):(0,U.jsx)(`span`,{children:`URL unavailable`})}):null,G||s?.state===`disconnected`||s?.state===`unconfigured`?(0,U.jsxs)(`form`,{className:`canvas-hub-origin-form`,onSubmit:e=>{e.preventDefault(),!(q||ge)&&(he(!0),de(!0),te(``),l(fe).then(()=>{de(!1)}).catch(e=>te(e.message)).finally(()=>he(!1)))},children:[(0,U.jsxs)(`div`,{className:`canvas-hub-origin-field`,children:[(0,U.jsxs)(`label`,{children:[K.hubUrl,(0,U.jsx)(`input`,{type:`url`,required:!0,value:fe,placeholder:`https://hub.example.com`,disabled:q||ge,onChange:e=>pe(e.target.value)})]}),(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:`subtle`,className:`canvas-icon-button`,leadingVisual:(0,U.jsx)(R,{size:16}),"aria-label":K.resetHubUrl,title:K.resetHubUrl,disabled:q||ge,"aria-busy":ge,onClick:()=>{_e(!0),te(``),$(`/api/hub/discovery`,e.token,{method:`POST`,body:`{}`}).then(async e=>{if(e.discovery?.state!==`valid`||!e.discovery.origin)throw Error(e.discovery?.message||K.resetHubUnavailable);pe(e.discovery.origin),await c()}).catch(e=>te(e.message)).finally(()=>_e(!1))},children:(0,U.jsx)(`span`,{className:`visually-hidden`,children:K.resetHubUrl})})]}),(0,U.jsx)(`p`,{children:K.hubHttpsHint}),(0,U.jsxs)(`div`,{className:`canvas-hub-form-actions`,children:[(0,U.jsx)(H.Button,{type:`submit`,size:`small`,disabled:q||ge,children:`Save Hub`}),G&&s?.state!==`unconfigured`&&s?.state!==`disconnected`?(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:`subtle`,disabled:q||ge,onClick:()=>de(!1),children:`Cancel`}):null]})]}):null]});return(0,U.jsxs)(it,{source:O,children:[Et.visible?(0,U.jsx)(ln,{...Et}):null,Wt&&Jt?(0,tt.createPortal)((0,U.jsxs)(`div`,{className:`canvas-review-controls review-shell__comment-actions`,role:`group`,"aria-label":St.heading,children:[(0,U.jsx)(bt,{bridgeReady:Ae&&Ut,copy:St,selectionBlocked:Gt,selecting:Fe!==null,onCancelSelection:nn,onStartAreaSelection:()=>void tn(`area`),onStartElementSelection:()=>void tn(`element`)}),(0,U.jsx)(H.Tooltip,{ref:rt,text:Gt?St.selectionBlockedLabel:`${St.heading} (${St.sidebarShortcutLabel})`,type:`description`,children:(0,U.jsxs)(H.Button,{className:`canvas-comments-toggle review-shell__comments-toggle`,variant:`secondary`,size:`small`,"aria-label":`${St.heading}, ${Vt}${Ht?`, ${St.unreadLabel}`:``}`,"aria-expanded":k&&t,"aria-keyshortcuts":`Shift+C`,disabled:Gt,onClick:mn,children:[(0,U.jsx)(nt,{children:Vt}),Ht?(0,U.jsx)(`span`,{className:`canvas-comments-unread-badge review-shell__unread-badge`,"aria-hidden":`true`}):null]})})]}),Jt):null,t&&P&&Bt.length&&Ae&&!Fe?(0,U.jsx)(`div`,{className:`canvas-marker-layer`,children:(0,U.jsx)(lt,{threads:Bt,resolutions:At,selectedThreadId:z,selectionBlocked:De,focusSelectedMarker:!1,showAreaHighlightsOnlyWhenSelected:!0,copy:St,onSelect:e=>ee(e.root.id)})}):null,(0,U.jsxs)(at,{className:`canvas-hub-panel`,contentClassName:`canvas-hub-content`,title:`Replica Hub`,label:`Hub`,open:qt,closeLabel:`Close Hub`,closeRef:et,onClose:x,children:[B?(0,U.jsx)(`p`,{role:`alert`,children:B}):null,oe?(0,U.jsx)(`p`,{role:`alert`,children:oe}):null,s?null:(0,U.jsx)(`p`,{children:`Checking Hub connection…`}),!Mt&&!Ct&&s?.message?(0,U.jsx)(`p`,{role:`status`,children:s.message}):null,Ct?(0,U.jsxs)(`div`,{className:`canvas-hub-status`,children:[(0,U.jsx)(me,{variant:`warning`,layout:`compact`,title:s?.message||X.hubUnavailable}),(0,U.jsx)(H.Button,{variant:`primary`,size:`small`,disabled:h,"aria-busy":h,leadingVisual:h?(0,U.jsx)(R,{size:16}):void 0,onClick:v||(()=>void c()),children:X.retry})]}):null,!Mt&&!Ct&&m&&_&&v?(0,U.jsx)(je,{publication:m,busy:h,dirty:g,onPublish:_,onRetry:v}):null,Mt?(0,U.jsxs)(`section`,{className:`canvas-hub-connection`,children:[(0,U.jsx)(`p`,{children:K.connectionBeforePublishing}),(0,U.jsx)(H.Button,{ref:f,variant:`primary`,onClick:u,disabled:p,children:p?K.connectionOpeningBrowser:K.connectToHub})]}):null,!Mt&&(!G&&(s?.discovery?.mismatch||[`invalid`,`unreachable`].includes(s?.discovery?.state||``))||s?.state===`unconfigured`)?(0,U.jsxs)(`div`,{className:`canvas-hub-settings`,children:[!G&&s?.discovery?.mismatch?(0,U.jsx)(`p`,{role:`alert`,children:`The repository configuration differs from your selected Hub. Your connection has not changed. Disconnect Hub before selecting another URL.`}):null,!G&&[`invalid`,`unreachable`].includes(s?.discovery?.state||``)?(0,U.jsx)(`p`,{role:`alert`,children:s?.discovery?.message}):null,s?.state===`unconfigured`?(0,U.jsx)(`p`,{children:`Enter your Hub URL to connect.`}):null]}):null,s?.state===`undiscovered`&&!m?(0,U.jsxs)(`p`,{children:[`Connected to `,s.repository,`. Hub has not discovered`,` `,s.branch||`a prototype branch`,`. Your repository connection is ready. Push a named branch to make its Builds and reviews available.`]}):null,Q?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`section`,{className:m&&m.kind!==`ready`&&_&&v?`canvas-hub-publication canvas-hub-publication--after-status`:`canvas-hub-publication`,"aria-label":`Prototype`,children:It&&Xt?(0,U.jsxs)(`form`,{className:`canvas-hub-publication__form`,onSubmit:t=>{t.preventDefault(),$(`/api/hub/metadata`,e.token,{method:`PATCH`,body:JSON.stringify({name:ve,description:be,startPage:J})}).then(async()=>{we(!1),await c()}).catch(e=>te(e.message))},children:[(0,U.jsxs)(`div`,{className:`canvas-hub-publication__title`,children:[(0,U.jsxs)(`label`,{className:`canvas-hub-publication__name-field`,children:[(0,U.jsx)(`span`,{className:`visually-hidden`,children:`Name`}),(0,U.jsx)(`input`,{required:!0,maxLength:255,value:ve,onChange:e=>ye(e.target.value)})]}),(0,U.jsx)(`span`,{className:`canvas-hub-publication__status`,children:Q.published?`Published`:Q.registered?`Registered`:`Not registered`})]}),gn,(0,U.jsxs)(`label`,{className:`canvas-hub-publication__description-field`,children:[(0,U.jsx)(`span`,{className:`visually-hidden`,children:`Description`}),(0,U.jsx)(`textarea`,{value:be,placeholder:`Add a description`,onChange:e=>xe(e.target.value)})]}),(0,U.jsxs)(`label`,{className:`canvas-hub-publication__start-page-field`,children:[K.startPage,(0,U.jsx)(`input`,{value:J,placeholder:`/`,"aria-describedby":`canvas-start-page-hint`,onChange:e=>Se(e.target.value)})]}),(0,U.jsx)(`p`,{id:`canvas-start-page-hint`,className:`canvas-hub-publication__hint`,children:K.startPageHint}),(0,U.jsxs)(`div`,{className:`canvas-hub-form-actions`,children:[(0,U.jsx)(H.Button,{type:`submit`,size:`small`,children:`Save metadata`}),(0,U.jsx)(H.Button,{type:`button`,size:`small`,variant:`subtle`,onClick:()=>we(!1),children:`Cancel`})]})]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`canvas-hub-publication__title`,children:[(0,U.jsx)(H.Heading,{as:`h3`,size:`subhead-large`,children:Q.name||s?.branch}),(0,U.jsx)(`span`,{className:`canvas-hub-publication__status`,children:Q.published?`Published`:Q.registered?`Registered`:`Not registered`})]}),gn,Q.description?(0,U.jsx)(`p`,{className:`canvas-hub-publication__description`,children:Q.description}):null,(0,U.jsxs)(`p`,{className:`canvas-hub-publication__description canvas-hub-publication__start-page`,children:[K.startPage,`: `,(0,U.jsx)(`code`,{children:Q.startPage||`/`})]}),It?(0,U.jsx)(H.Button,{size:`small`,variant:`subtle`,onClick:()=>{ye(Q.name||``),xe(Q.description||``),Se(Q.startPage||``),Ee(ft),we(!0)},children:K.editDetails}):null]})}),(0,U.jsxs)(`section`,{className:`canvas-hub-section`,"aria-labelledby":`canvas-hub-build-title`,children:[(0,U.jsx)(H.Heading,{as:`h3`,size:`subhead-medium`,id:`canvas-hub-build-title`,children:K.latestBuild}),Q.build?(0,U.jsxs)(`div`,{className:`canvas-hub-build`,children:[(0,U.jsxs)(`div`,{className:`canvas-hub-build__identity`,children:[(0,U.jsx)(`a`,{href:Q.build.url,target:`_blank`,rel:`noopener noreferrer`,children:K.buildTitle(Q.build.number)}),(0,U.jsx)(`code`,{title:Q.build.commitSha,"aria-label":`${K.buildCommit} ${Q.build.commitSha}`,children:Q.build.commitSha.slice(0,7)})]}),(0,U.jsx)(`p`,{children:Pt?(0,U.jsx)(`a`,{className:`canvas-hub-build__author`,href:Pt,target:`_blank`,rel:`noopener noreferrer`,children:Ft}):(0,U.jsx)(`span`,{children:Ft})}),s?.commitSha&&s.commitSha!==Q.build.commitSha?(0,U.jsx)(`p`,{className:`canvas-hub-build__notice`,children:`Local checkout differs from this Build`}):null]}):(0,U.jsxs)(`p`,{children:[`No successful imported Build yet. Current Build: `,Q.buildState||`none`,`.`]}),Q.build&&s?.hubOrigin?(0,U.jsx)(`a`,{className:`canvas-hub-build__history`,href:new URL(`/repositories/${Q.repositoryId}/prototypes/${Q.id}/builds`,s.hubOrigin).href,target:`_blank`,rel:`noopener noreferrer`,children:K.showBuildHistory}):null]})]}):null,Mt?null:(0,U.jsxs)(`section`,{className:`canvas-hub-section`,"aria-labelledby":`canvas-hub-origin-title`,children:[_n,s?.hubOrigin&&[`connected`,`undiscovered`,`pairing`,`denied`,`unavailable`].includes(s.state)?(0,U.jsx)(`div`,{className:`canvas-hub-disconnect`,children:(0,U.jsx)(H.Button,{size:`small`,variant:`subtle`,onClick:()=>{se(``),$(`/api/hub/disconnect`,e.token,{method:`POST`,body:`{}`}).then(async()=>{pe(s.discovery?.mismatch&&s.discovery.origin||s.hubOrigin||``),de(!0),await c(),d?.()}).catch(e=>{se(K.disconnectFailed(s.hubOrigin||``,e.message)),pe(s.discovery?.mismatch&&s.discovery.origin||s.hubOrigin||``),de(!0)})},children:`Disconnect Hub`})}):null]}),Q?.registered&&Q.build&&y?(0,U.jsx)(In,{preference:y,disabled:h}):null]}),Wt?(0,U.jsx)(yt,{frame:{open:k&&t,className:`canvas-comments-sidebar-shell`,contentClassName:`canvas-comments-sidebar-content`},threads:Bt,currentBuildNumber:Rt?.number||0,buildLinkOrigin:s?.hubOrigin,totalCount:Bt.length,hasThreads:Ot.length>0,filters:j,participants:kt,resolutions:At,selectedThreadId:z,selectionBlocked:Gt,closeBlocked:De,showPins:P,loading:ce,loadFailed:ue,notice:He||s?.reviewError||s?.localCommentsError||mt?(0,U.jsxs)(`div`,{className:`canvas-comments-live-notices`,children:[He?(0,U.jsx)(`p`,{className:`canvas-comments-live-status`,role:`status`,children:K.commentLiveUpdatesPaused}):null,s?.reviewError?(0,U.jsx)(`p`,{className:`canvas-comments-live-status`,children:s.reviewError}):null,s?.localCommentsError?(0,U.jsx)(`p`,{className:`canvas-comments-live-status`,role:`alert`,children:s.localCommentsError}):null,mt?(0,U.jsx)(`p`,{className:`canvas-comments-live-status`,children:K.localCommentsSaved}):null]}):null,copy:St,onClose:mn,onFiltersChange:M,onShowPinsChange:F,onRetry:()=>void Qt(),onSelect:e=>ee(e.root.id)}):null,(0,U.jsx)(Fn,{selectionNotice:Be?Be===`area-too-small`?St.areaTooSmallLabel:Be===`area-unavailable`?St.areaUnavailableLabel:St.selectionFailedLabel:null,rateLimitNotice:qt?null:ie||!Z&&ne||null,composer:Z&&Yt?{anchorPoint:Yt,bodyMaximumBytes:1e4,copy:St,creating:We?.kind===`create`,submitError:ne,onSubmit:pn,onDiscard:rn}:null,conversation:jt?{thread:jt,anchorPoint:ke.get(jt.root.id)??null,bodyMaximumBytes:1e4,mutation:We,copy:St,onClose:()=>ee(null),onDraftStateChange:Oe,onReply:e=>fn(`${jt.root.id}/replies`,`POST`,{review_comment:{body:e}},{kind:`reply`,commentId:jt.root.id}),onEdit:(e,t)=>fn(`${e}`,`PATCH`,{review_comment:{body:t}},{kind:`edit`,commentId:e}),onDelete:e=>fn(`${e}`,`DELETE`,void 0,{kind:`delete`,commentId:e}),onResolve:()=>fn(`${jt.root.id}/resolution`,`POST`,void 0,{kind:`resolve`,commentId:jt.root.id}),onReopen:()=>fn(`${jt.root.id}/resolution`,`DELETE`,void 0,{kind:`reopen`,commentId:jt.root.id}),onAddReaction:(e,t)=>fn(`${e}/reactions`,`POST`,{review_comment_reaction:{content:t,activity_version:jt.root.activityVersion}},{kind:`add-reaction`,commentId:e,content:t}),onRemoveReaction:(e,t)=>fn(`${e}/reactions/${encodeURIComponent(t)}`,`DELETE`,{review_comment_reaction:{activity_version:jt.root.activityVersion}},{kind:`remove-reaction`,commentId:e,content:t}),onMarkRead:e=>fn(`${jt.root.id}/read`,`POST`,{review_thread_read:{activity_version:e}}),onMarkUnread:()=>fn(`${jt.root.id}/read`,`DELETE`,void 0,{kind:`mark-unread`,commentId:jt.root.id})}:null})]})}function Bn(e,t,n){function r(e,t,n){return{kind:e,title:t,detail:n}}if(!e||!t)return n.kind===`unknown`?r(`retry`,Y.unavailable,n.detail):r(`checking`,Y.checking,Y.checkingDetail);if(!e.stats.branch)return r(`restricted`,Y.restricted,n.detail);if(t.repository&&t.repository!==e.stats.repository||t.branch&&t.branch!==e.stats.branch)return r(`retry`,Y.unavailable,Y.changedDetail);if(t.discovery?.state===`local`||e.stats.repository?.startsWith(`local/`))return r(`restricted`,Y.restricted,Y.local);if(t.registrationReason===`branch_not_reviewable`||e.stats.branch===t.discovery?.defaultBranch)return r(`restricted`,Y.restricted,X.registrationReasons.get(`branch_not_reviewable`).description);if([`disconnected`,`pairing`,`unconfigured`].includes(t.state))return r(`connect`,Y.connect,Y.connectDetail);if([`denied`,`unavailable`].includes(t.state))return r(`retry`,Y.unavailable,t.message||Y.unavailableDetail);if(t.repository!==e.stats.repository||t.branch!==e.stats.branch)return r(`retry`,Y.unavailable,Y.unavailableDetail);let i=t.prototype;if(t.state===`connected`&&i?.branch===e.stats.branch&&i.registered&&i.published&&i.build&&Number.isSafeInteger(i.build.number)&&i.build.number>0)return r(`ready`,Y.ready,Y.readyDetail);if(t.state===`connected`&&(!i||i.branch!==e.stats.branch||typeof i.published!=`boolean`||i.published))return r(`retry`,Y.unavailable,Y.unavailableDetail);let a=t.state===`connected`?i?.canEdit:t.canPublish;if(a===!1)return r(`restricted`,Y.restricted,Y.publishDenied);let o=e.stats.remoteBranch,s=t.state===`undiscovered`&&t.repositoryAuthorized===!0&&!i&&(!t.commitSha||t.commitSha===e.stats.commitSha)&&o?.repository===e.stats.repository&&o?.branch===e.stats.branch&&o?.commitSha===e.stats.commitSha&&(o?.state===`absent`||o?.state===`present`&&e.publishRequest?.commitSha===e.stats.commitSha&&([`requested`,`in_progress`].includes(e.publishRequest?.state??``)||e.publishRequest?.state===`idle`&&e.publishRequest.remoteState===`absent`))&&![`loading`,`unknown`,`detached`,`workflow_missing`].includes(n.kind),c=a===void 0&&s;if(a!==!0&&!c)return r(`retry`,Y.unavailable,Y.permissionUnknown);let l=t.registrationReason||i?.registrationReason;if(n.error&&(l!==`remote_branch_missing`||!s)){let e=[`successful_build_required`,`already_registered`].includes(l||``),t=[`write_access_required`,`repository_mismatch`,`branch_not_reviewable`,`remote_branch_missing`,`branch_authorship_required`].includes(l||``);return{...r(e?`progress`:t?`restricted`:`retry`,n.error.title,n.error.description),...e?{publication:{...n,action:`retry`,label:X.retry}}:{}}}if(n.kind===`detached`)return r(`restricted`,Y.restricted,n.detail);if(n.action===`retry`)return r(`retry`,Y.unavailable,n.detail);if(n.kind===`loading`)return r(`checking`,Y.checking,n.detail);let u=c?`${Y.publishDetail} ${Y.publishPermissionUnverified}`:Y.publishDetail,d=s&&l===`remote_branch_missing`?{...n,error:void 0}:n;return n.action===`publish`?{...r(`publish`,Y.publish,u),publication:d}:{...r(`progress`,Y.preparing,u),publication:d}}function Vn({open:e,onToggle:t,buttonRef:n}){return(0,U.jsx)(W,{icon:re,"aria-label":K.controls,description:K.controls,ref:n,size:`small`,variant:`default`,className:`canvas-controls-toggle`,"aria-expanded":e,onClick:t})}function Hn({toolbarRef:e,improvementControlsRef:t,config:n,onPublish:r,publishButtonRef:i,hubButtonRef:a,titleButtonRef:s,onBuildDetails:c,publishing:l,state:u,prototypeName:d,hubOpen:f,onHub:p,publication:m,onControls:h,controlsOpen:g,controlsButtonRef:_,onShare:y,shareButtonRef:b,onImproveContext:x,improvingContext:S=!1,feedbackMessage:C}){let w=u?.publishStatus??{state:`unavailable`,detail:K.statusUnavailable},T=d?.trim()||u?.stats.branch||u?.name||n.name,E=u?[T,u.stats.repository,u.stats.commitSha?.slice(0,7),u.stats.workingTree===`changed`?K.workingTreeChanged:K.workingTreeClean,u.stats.urlHost].filter(Boolean).join(` · `):T,D=l||(m?m.action===`none`:w.state===`requested`||w.state===`in_progress`||w.state===`published`),O=l||(m?m.kind===`requested`||m.kind===`queued`||m.kind===`building`||m.kind===`importing`||m.kind===`awaiting_build`||m.kind===`registration`:w.state===`requested`||w.state===`in_progress`),A=!O&&(m?m.kind===`ready`:w.state===`published`),j=(0,U.jsx)(H.Button,{type:`button`,ref:i,className:`canvas-publish-button`,variant:`secondary`,size:`small`,leadingVisual:O?(0,U.jsx)(R,{size:16}):Wn(w.state),disabled:D&&!A,"aria-busy":O,title:A?void 0:m?.detail||w.detail,onClick:D||A?void 0:r,children:m?.label||K.publishLabels[w.state]});return(0,U.jsxs)(`header`,{ref:e,className:`canvas-toolbar`,children:[(0,U.jsx)(H.Button,{type:`button`,className:`canvas-title`,ref:s,variant:`subtle`,size:`small`,title:E,disabled:!u,onClick:c,children:T}),(0,U.jsx)(`div`,{id:`canvas-review-controls`,className:`canvas-review-controls-slot`}),n.pickAndPolish?(0,U.jsx)(`div`,{ref:t,id:`canvas-improvement-controls`}):null,h?(0,U.jsx)(Vn,{buttonRef:_,open:g,onToggle:h}):null,p?(0,U.jsx)(H.Button,{type:`button`,ref:a,size:`small`,variant:`secondary`,className:`canvas-toolbar-compact-button`,leadingVisual:(0,U.jsx)(ae,{size:16}),"aria-label":K.editDetails,title:K.editDetails,"aria-expanded":f,onClick:p,children:(0,U.jsx)(`span`,{className:`canvas-toolbar-button-label`,children:K.editDetails})}):null,(0,U.jsxs)(`div`,{className:`canvas-publish-share`,role:`group`,"aria-label":J.group,children:[A?(0,U.jsx)(H.Tooltip,{ref:i,text:X.alreadyPublished,type:`description`,children:j}):j,y?(0,U.jsx)(W,{ref:b,icon:v,size:`small`,"aria-label":J.title,description:J.title,onClick:y}):null]}),x?(0,U.jsxs)(H.ActionMenu,{size:`small`,selectionVariant:`none`,menuAlignment:`end`,disabled:S,children:[(0,U.jsx)(H.ActionMenu.IconButton,{icon:o,variant:`secondary`,"aria-label":K.moreActions,"aria-busy":S}),(0,U.jsx)(H.ActionMenu.Overlay,{"aria-label":K.moreActions,children:(0,U.jsx)(Un,{className:`canvas-more-action`,leadingVisual:(0,U.jsx)(k,{size:16}),onClick:x,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),x()),e.key===` `&&(e.preventDefault(),e.currentTarget.click())},children:K.improveContext})})]}):null,C?(0,U.jsx)(`p`,{className:`canvas-feedback-message`,role:`alert`,children:C.message}):null]})}function Un(e){return(0,U.jsx)(H.Tooltip,{text:K.improveContextDescription,type:`description`,direction:`w`,children:(0,U.jsx)(H.ActionMenu.Item,{...e})})}function Wn(e){return e===`published`?(0,U.jsx)(se,{size:16}):e===`failed`||e===`in_progress`||e===`requested`?(0,U.jsx)(R,{size:16}):(0,U.jsx)(D,{size:16})}function Gn(e,t,n){return{status:t?`pending`:e.status,url:n,error:t?``:e.error??``,controls:t?[]:e.scopes.flatMap(e=>e.declaration.controls.map(t=>Ye(e,t)))}}var Kn={bridgeUnavailable:`The prototype bridge is not ready on this page.`,routeChanged:`The prototype route changed. Inspect the live canvas again.`,reloaded:`The prototype reloaded before confirming the click. Inspect the live canvas and retry.`,unconfirmed:`The prototype did not confirm the click. Check its bridge and retry.`,clickFailed:`The target could not be clicked.`,addressUnavailable:`The canvas address field is unavailable.`,unknownAction:`Unknown canvas action.`,replyRejected:`The live canvas rejected the action reply. Check its transport diagnostics.`,actionInterrupted:`The canvas changed before the action could run. Inspect the live canvas and retry.`,statusInterrupted:`The canvas changed while collecting Controls status. Inspect the live canvas and retry.`};function qn(e){let{token:t,prototypeUrl:n,previewUrl:r,cancelClick:i}=e,a=(0,V.useRef)(e),o=(0,V.useRef)(null);(0,V.useLayoutEffect)(()=>{a.current=e}),(0,V.useEffect)(()=>{o.current??=crypto.randomUUID();let e={"X-Replica-Renderer-Id":o.current},s=!1,c=!1,l=new AbortController,u=new URL(r??n).origin;async function d(e){let t=a.current.frameRef.current,n=a.current.liveRoute;if(!t?.contentWindow||!n)throw Error(Kn.bridgeUnavailable);if(e.route.pathname!==n.pathname||e.route.search!==n.search||e.route.hash!==n.hash)throw Error(Kn.routeChanged);let r=crypto.randomUUID();return await new Promise((n,a)=>{function o(){window.clearTimeout(c),window.removeEventListener(`message`,l),i.current===s&&(i.current=null)}function s(){o(),a(Error(Kn.reloaded))}let c=window.setTimeout(()=>{o(),a(Error(Kn.unconfirmed))},2e3);function l(i){let s=i.data;i.source===t?.contentWindow&&i.origin===u&&s&&typeof s==`object`&&`type`in s&&s.type===`replica:canvas:click-result`&&`nonce`in s&&s.nonce===r&&(o(),`clicked`in s&&s.clicked===!0?n({clicked:!0,route:e.route}):a(Error(Kn.clickFailed)))}i.current=s,window.addEventListener(`message`,l),t.contentWindow.postMessage({type:`replica:canvas:click`,nonce:r,...e},u)})}async function f(e){let t=a.current.frameRef.current,r=crypto.randomUUID(),i=Date.now()+e,o=await new Promise((n,o)=>{function s(){window.clearTimeout(d),window.removeEventListener(`message`,p),t?.removeEventListener(`load`,m),l.signal.removeEventListener(`abort`,c)}function c(){s(),o(Error(Kn.statusInterrupted))}let d=window.setTimeout(()=>{if(s(),a.current.liveRoute)o(Error(Kn.bridgeUnavailable));else{let e=new URL(a.current.navigation.entries[a.current.navigation.index]);e.protocol=new URL(u).protocol,e.host=new URL(u).host,n({status:`pending`,url:e.href,error:``,controls:[]})}},e+1500),f=!1;function p(e){let i=e.data;e.source===t?.contentWindow&&t===a.current.frameRef.current&&e.origin===u&&i&&typeof i==`object`&&`type`in i&&(i.type===`replica:canvas:ready`&&!f&&(f=!0,m()),i.type===`replica:controls:status-result`&&`nonce`in i&&i.nonce===r&&`value`in i&&(s(),n(i.value)))}function m(){t===a.current.frameRef.current&&t?.contentWindow?.postMessage({type:`replica:controls:status`,nonce:r,timeoutMs:Math.max(0,i-Date.now())},u)}window.addEventListener(`message`,p),t?.addEventListener(`load`,m),l.signal.addEventListener(`abort`,c),m()});if(!o||typeof o!=`object`||!(`url`in o)||typeof o.url!=`string`||!(`status`in o)||typeof o.status!=`string`||!(`error`in o)||typeof o.error!=`string`||!(`controls`in o)||!Array.isArray(o.controls))throw Error(Kn.bridgeUnavailable);let s=new URL(o.url);if(s.origin!==u)throw Error(Kn.routeChanged);let c=new URL(n);s.protocol=c.protocol,s.host=c.host;let d=await p(i);return!d&&a.current.controlsConnection===void 0?{...o,url:s.href}:{...d?Gn(d,d.loading,s.href):{status:`pending`,url:s.href,error:``,controls:[]},runtime:{status:o.status,error:o.error,controls:o.controls}}}function p(e){let t=a.current.controlsConnection;if(!t)return Promise.resolve(null);let n=t.getSnapshot,r=t.subscribe,i=n();return!i.loading||e<=Date.now()?Promise.resolve(i):new Promise(t=>{let i={};function a(e){window.clearTimeout(c),i.unsubscribe?.(),l.signal.removeEventListener(`abort`,s),t(e)}function o(){let e=n();e.loading||a(e)}function s(){a(null)}let c=window.setTimeout(()=>a(n()),e-Date.now());i.unsubscribe=r(o),l.signal.addEventListener(`abort`,s,{once:!0}),o()})}async function m(){if(!(s||c)){s=!0;try{let{command:r,prototypeUrl:i}=await $(`/api/agent/next`,t,{headers:{...e,"X-Replica-Prototype-Url":n}});if(!c&&i&&i!==n){window.location.reload();return}if(!r)return;let o;try{if(await $(`/api/agent/progress`,t,{method:`POST`,headers:e,body:JSON.stringify({id:r.id,stage:`handler started`})}),c)throw Error(Kn.actionInterrupted);let n;if(r.type===`inspect`){let{appearance:e,navigation:t,liveRoute:r,addressRef:i}=a.current,o=i.current?.value;if(o===void 0)throw Error(Kn.addressUnavailable);n={address:t.entries[t.index],addressDraft:o,appearance:e,canGoBack:t.index>0,canGoForward:t.indexvoid m(),300);return()=>{c=!0,l.abort(),window.clearInterval(h),i.current?.()}},[n,r,t,i])}function Jn(e,t,n){let r=t?.repository===e?.stats.repository&&t?.branch===e?.stats.branch,i=!e?.stats.branch&&!!e?.stats.branchError,a=i?void 0:t?.branch,o=!!(e&&!i&&(t?.repository&&t.repository!==e.stats.repository||t?.branch&&t.branch!==e.stats.branch||t?.commitSha&&t.commitSha!==e.stats.commitSha)),s=!!(n.kind===`ready`&&r&&t?.state===`connected`&&t.prototype?.published&&t.prototype.build?.commitSha===e?.stats.commitSha);return{state:e&&{...e,publishStatus:!s&&[`requested`,`in_progress`].includes(e.publishStatus?.state??``)||t?.state===`connected`&&!r?e.publishStatus:s&&t?.prototype?.build?{state:`published`,detail:K.hubBuildImported,versionCount:t.prototype.versionCount,lastUpdatedAt:t.prototype.build.publishedAt,run:{url:t.prototype.build.url,actor:t.prototype.build.author.login||t.prototype.build.author.name?{login:t.prototype.build.author.login||void 0,name:t.prototype.build.author.name||void 0,avatarUrl:t.prototype.build.author.avatarUrl||void 0}:null}}:{state:t?.state===`connected`?`not_published`:`unavailable`,detail:t?.state===`connected`?K.hubBuildMissing:K.hubPublicationUnavailable},stats:{...e.stats,branch:a||e.stats.branch,branchError:a&&a!==e.stats.branch?null:e.stats.branchError,repository:t?.repository||e.stats.repository,commitSha:e.stats.commitSha,comparison:o?{branch:null,source:null,behind:null,error:K.comparisonNeedsRefresh}:e.stats.comparison,publishedUrl:s?t?.prototype?.build?.url:void 0}},hubPublished:s,comparisonOutdated:o}}function Yn(e,t){let n;function r(e,t,r,i=`none`){return{kind:e,detail:t,label:r,action:i,...n?{error:n}:{}}}if(!e)return r(`loading`,X.initial,X.checking);let{stats:i}=e,a=i.remoteBranch;if(!a||a.state===`loading`)return r(`loading`,X.checkingRemote,X.checking);if(!i.branch||a.state===`detached`)return r(`detached`,X.detached,X.retry,`retry`);if(a.repository!==i.repository||a.branch!==i.branch||a.commitSha!==i.commitSha)return r(`unknown`,X.changed,X.retry,`retry`);if(a.state===`unknown`)return r(`unknown`,X.unknown(a.error),X.retry,`retry`);let o=t?.state===`connected`?t.prototype:void 0,s=o?.build?.commitSha===i.commitSha&&o?.branch===i.branch,c=e.publishRequest,l=t?.state===`connected`&&t.repository===i.repository&&t.branch===i.branch&&(!t.commitSha||t.commitSha===i.commitSha)&&t.prototype?.branch===i.branch&&t.prototype.build?.commitSha===i.commitSha?t.prototype.build:null,u=!!(l&&(c?.commitSha!==i.commitSha||c.buildNumber===void 0||typeof c.buildNumber==`number`&&l.number>c.buildNumber)),d=u&&o?.registered&&o.published,f=t!==null&&t.repository===i.repository&&(!t.branch||t.branch===i.branch)&&(!t.commitSha||t.commitSha===i.commitSha);if(t&&f&&(t.state===`connected`||t.state===`undiscovered`)&&!o?.registered&&(!o||o.branch===i.branch)){let e=t.registrationReason||o?.registrationReason,r=i.branch===t.discovery?.defaultBranch;if(e||t.registrationError||o?.canRegister===!1||r){let i=e||(r?`branch_not_reviewable`:o?.canEdit===!1?`write_access_required`:o?.canRegister===!1&&a.state===`absent`?`remote_branch_missing`:void 0);n=i&&X.registrationReasons.get(i)||{title:X.registrationErrorTitle,description:t.registrationError||X.registrationDenied}}}if(c?.state===`requested`&&(!c.commitSha||c.commitSha===i.commitSha)&&(a.state===`absent`||a.remoteSha!==i.commitSha)&&!u){let e=Date.now()-Date.parse(c.requestedAt||``);if(Number.isFinite(e)&&e<6e5)return r(`requested`,X.pending,X.awaitingCopilot)}if(!t)return r(`loading`,X.checkingHub,X.checking);if(t.state===`disconnected`||t.state===`pairing`||t.state===`unconfigured`)return r(`disconnected`,t.message||X.disconnected,X.connect);if(t.state===`denied`||t.state===`unavailable`)return{...r(`unknown`,t.message||X.hubUnavailable,X.retry,`retry`),error:{title:X.hubUnavailableTitle,description:t.message||X.hubUnavailable}};if(!f)return r(`unknown`,X.staleHub,X.retry,`retry`);if(!i.replicaWorkflowExists)return r(`workflow_missing`,X.workflowMissing,X.retry,`retry`);if(c?.state===`failed`&&!d&&(!c.commitSha||c.commitSha===i.commitSha))return r(`failed`,c.error||X.dispatchFailed,X.retryPublish,`publish`);if(a.state===`absent`)return r(`unpublished`,X.absent,X.publishBranch,`publish`);if(a.remoteSha!==i.commitSha)return r(`needs_push`,X.needsPush,X.publishChanges,`publish`);if(s){if(!o.registered)return r(`registration`,t.registrationError||(o.canEdit&&o.canRegister?X.needsRegistration:X.registrationDenied),t.registrationError?X.registrationFailed:X.registration);if(o.published&&u)return r(`ready`,X.ready,X.published)}if(o?.currentBuild?.commitSha===i.commitSha&&o.branch===i.branch&&o.currentBuild.state===`failed`)return r(`failed`,X.importFailed,X.retryPublish,`publish`);let p=i.workflow;if(!p||p.state===`unavailable`)return r(`unknown`,p?.detail||X.workflowUnavailable,X.retry,`retry`);let m=p.run;if(m&&(m.headSha!==i.commitSha||m.headBranch!==i.branch))return r(`unknown`,X.staleWorkflow,X.retry,`retry`);if(c?.commitSha===i.commitSha&&c.workflowRunId!=null&&m?.databaseId===c.workflowRunId&&!u)return r(`awaiting_build`,X.noBuild,X.awaitingBuild);let h;if(p.state===`in_progress`&&m){let e=[`queued`,`waiting`,`pending`,`requested`].includes(m.status||``);h=r(e?`queued`:`building`,e?X.workflowQueued:X.workflowBuilding,e?X.queued:X.building)}else h=p.state===`failed`&&m?r(`failed`,X.workflowFailed(m.conclusion),X.retryPublish,`publish`):p.state===`succeeded`&&m?r(`importing`,X.importing,X.awaitingHub):r(`awaiting_build`,X.noBuild,X.awaitingBuild);return m?.url?.startsWith(`https://github.com/`)&&(h.runUrl=m.url),h}function Xn({token:e,state:t,hubStatus:n,error:r,setError:i,refresh:a,refreshHub:o,preferenceSaving:s=!1}){let[c,l]=(0,V.useState)(``),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(null),m=(0,V.useRef)(!1),[h,g]=(0,V.useState)(null),[_,v]=(0,V.useState)(``),[y,b]=(0,V.useState)(!1),x=!t&&r?{kind:`unknown`,action:`retry`,label:X.retry,detail:r}:Yn(t,n),S=`${t?.stats.repository}/${t?.stats.branch}/${t?.stats.commitSha}`,C=f?.identity===S&&x.action===`publish`?{...x,kind:`failed`,detail:f.message,label:X.retryPublish}:x.kind===`ready`&&t?.stats.workingTree===`changed`?{...x,kind:`needs_push`,action:`publish`,label:X.publishChanges,detail:X.localChanges}:x,w=Jn(t,n,x);(0,V.useEffect)(()=>{w.comparisonOutdated&&a(!0)},[w.comparisonOutdated,n?.branch,n?.commitSha,n?.repository,a]);async function T(){if(!y){b(!0);try{await Promise.all([a(!0),o()])}finally{b(!1)}}}async function E(){s||(C.action===`retry`?await T():C.action===`none`||m.current||h||await D())}async function D(){if(!(s||m.current)){m.current=!0,d(!0),i(``),v(``);try{let t=await $(`/api/publish/prepare`,e,{method:`POST`,body:`{}`});t.workingTree===`unavailable`||t.workingTree===`changed`&&!t.remember?g({preparation:t}):(g(null),await O(t,t.workingTree===`changed`?`commit-changes`:`committed-only`))}catch(e){let t=e instanceof Error?e.message:String(e);i(t),v(t)}finally{m.current=!1,d(!1)}}}async function O(r,s,c){if(s===`committed-only`&&n?.state===`connected`&&n.repository===r.target.repository&&n.branch===r.target.branch&&n.prototype?.registered&&n.prototype.published&&n.prototype.build?.commitSha===r.target.commitSha&&t?.stats.remoteBranch?.state===`present`&&t.stats.remoteBranch.remoteSha===r.target.commitSha)g(null);else{p(null),v(``),i(``);try{let t=await $(`/api/publish`,e,{method:`POST`,body:JSON.stringify({target:r.target,workingTree:r.workingTree,mode:s,remember:c})});g(null),l(t.message),await o(),await a(!1)}catch(e){let t=e instanceof Error?e.message:String(e);p({message:t,identity:S}),i(t),v(t)}}}async function k(e,t){if(!(s||!h||m.current)){if(h.preparation.workingTree===`unavailable`&&e!==`committed-only`)v(q.checkFailed);else{m.current=!0,d(!0);try{await O(h.preparation,e,t)}finally{m.current=!1,d(!1)}}}}return{publication:C,presentedState:w.state,busy:u||y||s,notice:c,publishDialog:h,publishDialogError:_,closePublishDialog:()=>g(null),choosePublish:k,retryPublishCheck:D,publish:E,retry:T}}var Zn=`replica:controls`;function Qn(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;try{let n=JSON.stringify(e);if(!(typeof n==`string`&&new Blob([n]).size<=512e3&&Object.keys(e).every(e=>[`protocol`,`version`,`epoch`,`requestId`,`type`,`sequence`,`state`,`error`,`command`,`controlQuery`,`fromFrameUrl`].includes(e))&&(t.error===void 0||typeof t.error==`string`&&t.error.length<=1e3)&&(t.controlQuery===void 0||[`hello`,`snapshot`,`reply`].includes(t.type)&&typeof t.controlQuery==`string`&&new Blob([t.controlQuery]).size<=8192)&&(t.fromFrameUrl===void 0||t.type===`hello`&&typeof t.fromFrameUrl==`boolean`)&&t.protocol===`replica:controls`&&t.version===1&&typeof t.epoch==`string`&&/^[a-zA-Z0-9-]{1,100}$/.test(t.epoch)&&typeof t.requestId==`string`&&/^[a-zA-Z0-9-]{1,100}$/.test(t.requestId)&&[`hello`,`snapshot`,`command`,`reply`].includes(t.type)))return!1;if(t.type!==`command`)return t.command===void 0;let r=t.command;if(!r||typeof r!=`object`||Array.isArray(r))return!1;if(r.operation===`url`)return Object.keys(r).every(e=>[`operation`,`query`,`scope`].includes(e))&&(r.scope===void 0||typeof r.scope==`string`&&/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(r.scope))&&typeof r.query==`string`&&new Blob([r.query]).size<=8192&&[...new URLSearchParams(r.query).keys()].every(e=>/^rc\.[a-zA-Z][a-zA-Z0-9_-]{0,63}\.[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(e));if(r.operation===`reset-all`)return Object.keys(r).every(e=>[`operation`,`contexts`].includes(e))&&Array.isArray(r.contexts)&&r.contexts.length<=100&&new Set(r.contexts.map(e=>e?.scope)).size===r.contexts.length&&r.contexts.every(e=>typeof e==`object`&&!!e&&Object.keys(e).length===3&&typeof e.scope==`string`&&/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(e.scope)&&typeof e.fingerprint==`string`&&Number.isSafeInteger(e.revision)&&e.revision>=0);let i=[`operation`,`scope`,`fingerprint`,`revision`];return typeof r.scope!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(r.scope)||typeof r.fingerprint!=`string`||!Number.isSafeInteger(r.revision)||r.revision===void 0||r.revision<0?!1:r.operation===`restore`?Object.keys(r).every(e=>[...i,`values`].includes(e))&&Ce(r.values):r.operation===`reset`?Object.keys(r).every(e=>i.includes(e)):r.operation!==`action`&&r.operation!==`update`||typeof r.id!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(r.id)?!1:Object.keys(r).every(e=>[...i,`id`,...r.operation===`update`?[`value`]:[]].includes(e))&&(r.operation===`action`||Ce({[r.id]:r.value}))}catch{return!1}}function $n(e){return Array.isArray(e)&&e.length<=100&&e.every(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`scope`in e&&typeof e.scope==`string`&&e.scope.length>0&&e.scope.length<=64&&`error`in e&&typeof e.error==`string`&&e.error.length>0&&e.error.length<=500)}function er(e){if(!e||typeof e!=`object`)return!1;let t=e;if(typeof t.runtimeAvailable!=`boolean`||t.reconnectRequired!==void 0&&typeof t.reconnectRequired!=`boolean`||t.status===`ready`&&(!t.runtimeAvailable||!t.scopes?.length)||t.error!==void 0&&(typeof t.error!=`string`||t.error.length>1e3)||t.scopeErrors!==void 0&&!$n(t.scopeErrors)||![`ready`,`no-controls`,`missing-runtime`,`unsupported-runtime`,`invalid-config`].includes(t.status)||!Array.isArray(t.scopes)||t.scopes.length>100||t.status!==`ready`&&t.scopes.length>0)return!1;try{let e=new Set;for(let n of t.scopes){if(We(n.declaration),e.has(n.declaration.scope)||(e.add(n.declaration.scope),n.fingerprint!==JSON.stringify(n.declaration)||!Number.isSafeInteger(n.snapshot.revision)||n.snapshot.revision<0))return!1;let t=n.snapshot;if(!t.values||!t.visible||!t.groups||!t.actions)return!1;function r(e,t){return typeof e==`object`&&!Array.isArray(e)&&Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))}if(!r(t.values,n.declaration.controls.filter(e=>e.type!==`button`).map(e=>e.id))||!r(t.visible,n.declaration.controls.map(e=>e.id))||!r(t.groups,(n.declaration.groups??[]).map(e=>e.id))||!r(t.actions,n.declaration.controls.filter(e=>e.type===`button`).map(e=>e.id))||Object.values(t.groups).some(e=>typeof e!=`boolean`))return!1;if(t.bindings!==void 0){if(!t.bindings||typeof t.bindings!=`object`||Array.isArray(t.bindings))return!1;for(let[e,r]of Object.entries(t.bindings))if(!n.declaration.controls.some(t=>t.id===e)||!r||typeof r.error!=`string`||r.error.length>500||typeof r.busy!=`boolean`||r.available!==void 0&&typeof r.available!=`boolean`)return!1}for(let e of n.declaration.controls){if(typeof t.visible[e.id]!=`boolean`)return!1;if(e.type===`button`){let n=t.actions[e.id];if(!n||typeof n.available!=`boolean`||typeof n.busy!=`boolean`)return!1}else if(Be(e,t.values[e.id]))return!1}}return!0}catch{return!1}}function tr(){return{runtimeAvailable:!1,status:`missing-runtime`,scopes:[],scopeErrors:[],loading:!0,notice:``,error:``,storageError:``,resetting:!1}}var nr=class{frame;origin;api;surface;epoch=``;sequence=-1;state=tr();listeners=new Set;pending=new Map;saved;storageReady=!1;restored=new Set;preparing=new Set;persisted=new Map;cachedScopes=new Map;retryState;resetForIdentity=!1;fromFrameUrl=!1;requests=new AbortController;poll;deadline;saveQueue=Promise.resolve();editQueue=Promise.resolve();stopped=!0;constructor(e,t,n,r=`canvas`){this.frame=e,this.origin=t,this.api=n,this.surface=r}getSnapshot=()=>this.state;getControlValues=()=>{let e=structuredClone(this.saved?.scopes??{}),t=new Map(this.cachedScopes);for(let e of this.state.scopes)t.set(e.declaration.scope,e);for(let[n,r]of t)e[n]=Ze(r);return e};subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});publish(e){this.state={...this.state,...e},this.state.hasResettableValues=Object.values(this.getControlValues()).some(e=>Object.keys(e).length>0);for(let e of[...this.listeners])e()}hasBindingError(e,t){return this.state.scopes.some(n=>(!e||n.declaration.scope===e)&&Object.entries(n.snapshot.bindings??{}).some(([e,n])=>(!t||e===t)&&!!n.error))}checkSaved(e){let t=e,n=/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/;if(!t||typeof t!=`object`||typeof t.identity!=`string`||!t.identity||t.identity.length>128||!t.scopes||typeof t.scopes!=`object`||Array.isArray(t.scopes)||t.storageError!==void 0&&(typeof t.storageError!=`string`||t.storageError.length>1e3)||t.notice!==void 0&&(typeof t.notice!=`string`||t.notice.length>1e3)||new Blob([JSON.stringify(t)]).size>27e4)throw Error(`Invalid controls storage response.`);for(let[e,r]of Object.entries(t.scopes)){if(!n.test(e)||!r||typeof r!=`object`||Array.isArray(r))throw Error(`Invalid controls storage scope.`);for(let[e,t]of Object.entries(r))if(!n.test(e)||!(typeof t==`string`||typeof t==`boolean`||typeof t==`number`&&Number.isFinite(t)||Array.isArray(t)&&t.length<=100&&t.every(e=>typeof e==`string`)))throw Error(`Invalid saved control value.`)}}start=e=>{this.fromFrameUrl=e?.type===`load`&&this.sequence>=0;let t=[...this.pending.values()].some(e=>e.action);this.stop(),this.requests=new AbortController,this.stopped=!1,this.epoch=crypto.randomUUID(),this.sequence=-1,this.saved=void 0,this.storageReady=!1,this.restored.clear(),this.preparing.clear(),this.persisted.clear(),this.editQueue=Promise.resolve(),this.cachedScopes.clear(),this.retryState=void 0,this.resetForIdentity=!1,this.state=tr(),t&&(this.state.notice=`The preview reconnected during an action. Its outcome is unknown; it was not replayed.`),this.publish({});let n=this.epoch;window.addEventListener(`message`,this.receive),this.frame.addEventListener(`load`,this.start);let r=()=>{this.storageReady&&(this.surface===`canvas`&&this.frame.contentWindow?.postMessage({type:`replica:canvas:request-ready`,nonce:n},this.origin),this.send(`hello`).catch(()=>{}))};r(),this.poll=setInterval(()=>{this.state.status===`missing-runtime`&&r()},1e3),this.deadline=setTimeout(()=>{this.state.loading&&this.publish({loading:!1,error:this.surface===`build`?`Build Controls did not connect. Reload the preview or check its definitions.`:K.controlsLocalConnectionFailed})},6e3),this.api().then(e=>{if(!(this.epoch!==n||this.stopped)){if(this.checkSaved(e),this.saved=e,this.retryState?.identity===e.identity)for(let[e,t]of this.retryState.scopes)this.restored.add(`${e}:${t.fingerprint}`),this.cachedScopes.set(e,t);else this.retryState?.identity&&(this.resetForIdentity=!0,this.publish({notice:`The checkout identity changed. Controls will use this branch's saved values or defaults.`}));this.retryState=void 0,this.storageReady=!0,this.publish({storageError:e.storageError||``,notice:e.notice||this.state.notice}),this.prepare(this.state),r()}}).catch(e=>{this.epoch!==n||this.stopped||(this.storageReady=!0,this.publish({storageError:this.surface===`build`?e instanceof Error?e.message:`Control settings could not be read from the URL.`:K.controlsLocalStorageFailed}),this.prepare(this.state),r())})};retry=()=>{let e={identity:this.saved?.identity,scopes:new Map(this.cachedScopes)};this.start(),this.retryState=e};stop=()=>{this.stopped=!0,this.requests.abort(),clearInterval(this.poll),clearTimeout(this.deadline),window.removeEventListener(`message`,this.receive),this.frame.removeEventListener(`load`,this.start);for(let e of this.pending.values())clearTimeout(e.timer),e.reject(Error(`The preview navigated. The command outcome is unknown; it will not be replayed.`));this.pending.clear()};receive=e=>{if(this.stopped||e.source!==this.frame.contentWindow||e.origin!==this.origin||!Qn(e.data))return;let t=e.data;if(t.epoch!==this.epoch||!er(t.state)||!Number.isSafeInteger(t.sequence)||(t.sequence??-1)<0||t.type!==`snapshot`&&t.type!==`reply`)return;let n=this.pending.get(t.requestId);if(t.type!==`reply`||n){if((t.sequence??-1)>this.sequence){if(t.type===`snapshot`&&t.controlQuery!==void 0&&this.saved){let e=De(t.controlQuery),n=this.saved.identity,r=this.epoch;this.stop();let i=new AbortController;this.requests=i,this.publish({loading:!0}),this.api({method:`POST`,signal:i.signal,body:JSON.stringify({identity:n,replace:!0,scopes:e.scopes})}).then(()=>{this.epoch!==r||i.signal.aborted||(this.start(),e.notice&&this.publish({notice:e.notice}))}).catch(e=>{this.epoch!==r||i.signal.aborted||this.publish({loading:!1,storageError:e instanceof Error?e.message:`Controls history could not be restored.`})});return}if(t.controlQuery!==void 0&&this.saved){let e=this.epoch,n=this.requests,r=De(t.controlQuery);this.saved.scopes=r.scopes,this.restored.clear(),this.persisted.clear(),this.cachedScopes.clear(),this.publish({notice:r.notice,loading:!0}),this.api({method:`POST`,signal:n.signal,body:JSON.stringify({identity:this.saved.identity,replace:!0,scopes:r.scopes})}).catch(t=>{this.epoch!==e||this.stopped||n.signal.aborted||this.publish({storageError:t instanceof Error?t.message:`Controls history could not be restored.`})})}this.sequence=t.sequence;let e=t.state.status;this.publish({...t.state,scopeErrors:t.state.scopeErrors??[],reconnectRequired:t.state.reconnectRequired===!0,status:e,error:t.state.error||(this.state.status===`missing-runtime`&&t.state.status!==`missing-runtime`?``:this.state.error),loading:!this.storageReady||this.state.resetting||this.preparing.size>0||this.state.loading&&e===`missing-runtime`}),this.prepare(this.state)}n&&(this.pending.delete(t.requestId),clearTimeout(n.timer),t.error?n.reject(Error(t.error)):n.resolve(this.state))}};send(e,t){let n=crypto.randomUUID(),r={protocol:Zn,version:1,epoch:this.epoch,requestId:n,type:e,...t?{command:t}:{},...e===`hello`?{controlQuery:Ee(this.saved?.scopes??{}),fromFrameUrl:this.fromFrameUrl}:{}};return Qn(r)?new Promise((i,a)=>{let o=setTimeout(()=>{this.pending.delete(n),a(Error(`The command timed out. Its outcome is unknown; it will not be retried automatically.`))},e===`hello`?1200:3e4);this.pending.set(n,{resolve:i,reject:a,timer:o,action:t?.operation===`action`}),this.frame.contentWindow?.postMessage(r,this.origin)}):Promise.reject(Error(`The controls command is invalid or exceeds the size limit.`))}async prepare(e){if(!this.saved&&!this.state.storageError||this.state.resetting||e.reconnectRequired)return;let t=this.epoch;if(this.resetForIdentity&&(e.status===`ready`||e.status===`no-controls`)){this.resetForIdentity=!1,this.publish({loading:!0,resetting:!0});try{await this.send(`command`,{operation:`reset-all`,contexts:e.scopes.map(e=>({scope:e.declaration.scope,fingerprint:e.fingerprint,revision:e.snapshot.revision}))})}catch{this.epoch===t&&this.publish({error:`The checkout changed, but runtime defaults could not be restored. Reload the preview before saving.`,storageError:`Saving is paused until the new checkout's runtime reconnects.`,loading:!1});return}finally{this.epoch===t&&this.publish({resetting:!1})}return this.epoch!==t||this.stopped?void 0:this.prepare(this.state)}for(let n of e.scopes){let e=n.declaration.scope,r=`${e}:${n.fingerprint}`;if(!this.preparing.has(r)){if(!this.restored.has(r)){this.preparing.add(r),this.publish({loading:!0});try{let i=this.saved?.scopes&&Object.hasOwn(this.saved.scopes,e)?this.saved.scopes[e]:{},a=Object.fromEntries(n.declaration.controls.filter(e=>e.type!==`button`).map(e=>[e.id,structuredClone(e.default)])),o=!1;for(let[e,t]of Object.entries(i)){let r=n.declaration.controls.find(t=>t.id===e);!r||Be(r,t)?o=!0:a[e]=t}if(Object.keys(a).length&&await this.send(`command`,{operation:`restore`,scope:e,fingerprint:n.fingerprint,revision:this.state.scopes.find(e=>e.fingerprint===n.fingerprint)?.snapshot.revision,values:a}),this.stopped||this.epoch!==t)return;this.restored.add(r),o&&this.publish({notice:this.surface===`build`?`Some URL control settings no longer match this page. Defaults were used.`:`Some saved controls no longer match this declaration and were discarded.`})}catch(n){if(this.epoch!==t||this.stopped)return;this.hasBindingError(e)||this.publish({error:n instanceof Error?n.message:`Saved controls could not be restored.`}),this.restored.add(r)}finally{this.epoch===t&&this.preparing.delete(r)}}if(this.epoch===t&&!this.stopped){let t=this.state.scopes.find(t=>t.declaration.scope===e);t&&(this.cachedScopes.set(e,t),this.persist(t))}}}this.epoch===t&&!this.stopped&&this.state.status!==`missing-runtime`&&this.publish({loading:this.preparing.size>0})}persist(e){if(!this.saved||this.state.storageError)return;let t=Ze(e),n=JSON.stringify(t);if(this.persisted.get(e.declaration.scope)===n)return;this.persisted.set(e.declaration.scope,n);let r=this.saved.identity,i=this.epoch,a=this.requests.signal;this.saveQueue=this.saveQueue.catch(()=>{}).then(async()=>{if(!(this.epoch!==i||this.stopped))try{if(await this.api({method:`POST`,signal:a,body:JSON.stringify({identity:r,scope:e.declaration.scope,values:t})}),this.epoch===i&&!this.stopped){let t=await this.api();if(this.checkSaved(t),this.epoch!==i||this.stopped)return;this.saved=t,await this.send(`command`,{operation:`url`,scope:e.declaration.scope,query:Ee(t.scopes)})}}catch(e){this.epoch===i&&!this.stopped&&this.publish({storageError:this.surface===`build`&&e instanceof Error?`${e.message} Changes remain in memory and are not in the URL.`:`Controls could not be saved. Changes remain in memory; use Retry to reconnect storage.`})}})}async command(e,t,n,r){if(this.state.loading||this.state.resetting||this.stopped)return;let i=this.epoch,a=this.state.scopes.find(e=>e.declaration.scope===t);if(!a){this.publish({error:`This controls scope is no longer active.`});return}let o=()=>this.applyCommand(e,t,a.fingerprint,i,n,r);if(e!==`update`)return o();let s=this.editQueue.catch(()=>{}).then(o);return this.editQueue=s.then(()=>{}),s}async applyCommand(e,t,n,r,i,a){if(this.epoch!==r||this.stopped||this.state.resetting)return;let o=this.state.scopes.find(e=>e.declaration.scope===t);if(!o||o.fingerprint!==n)this.publish({error:`The controls scope or declaration changed. The command was not applied.`});else{this.publish({error:``});try{if(this.state.reconnectRequired)throw Error(`Reconnect controls before sending more commands.`);if(e===`update`||e===`action`){let t=o.declaration.controls.find(e=>e.id===i);if(!t||!o.snapshot.visible[t.id])throw Error(`This control is unknown or hidden.`);if(e===`update`){let e=Be(t,a);if(e)throw Error(`Control "${t.id}": ${e}`)}else if(t.type!==`button`||!o.snapshot.actions[t.id]?.available||o.snapshot.actions[t.id]?.busy)throw Error(`This action is unavailable or busy.`)}let n=await this.send(`command`,{operation:e,scope:t,fingerprint:o.fingerprint,revision:o.snapshot.revision,...i?{id:i}:{},...e===`update`?{value:a}:{}});if(e===`update`&&i)return{value:n.scopes.find(e=>e.declaration.scope===t)?.snapshot.values[i]}}catch(e){!this.stopped&&this.epoch===r&&!this.hasBindingError(t,i)&&this.publish({error:e instanceof Error?e.message:`Controls command failed.`})}}}async resetAll(){if(this.state.resetting||this.stopped)return;let e=this.epoch;this.publish({resetting:!0});try{let t=``;await this.editQueue.catch(()=>{});let n=this.state.runtimeAvailable&&(this.state.status===`ready`||this.state.status===`no-controls`);if(n)try{await this.send(`command`,{operation:`reset-all`,contexts:this.state.scopes.map(e=>({scope:e.declaration.scope,fingerprint:e.fingerprint,revision:e.snapshot.revision}))})}catch(e){t=e instanceof Error?e.message:`Some app defaults could not be restored.`}if(this.epoch!==e||this.stopped)return;if(!this.saved){let e=await this.api();this.checkSaved(e),this.saved=e}await this.saveQueue.catch(()=>{}),await this.api({method:`POST`,signal:this.requests.signal,body:JSON.stringify({identity:this.saved.identity,reset:!0})}),this.saved.scopes={},await this.send(`command`,{operation:`url`,query:``}),this.cachedScopes.clear(),this.persisted.clear(),this.publish({storageError:``,error:this.hasBindingError()?``:t,notice:n?``:`Saved controls were cleared. Runtime defaults could not be restored until the preview reconnects.`})}catch(t){this.epoch===e&&this.publish({storageError:t instanceof Error?t.message:`Reset could not be saved.`})}finally{this.epoch===e&&this.publish({resetting:!1,loading:!1})}}};function rr(e,t=()=>window.location.href,n=e=>{window.history.replaceState(window.history.state,``,e),window.dispatchEvent(new Event(we))}){return r=>Promise.resolve().then(()=>{r?.signal?.throwIfAborted();let i=De(new URL(t()).search);if(!r)return{identity:e,...i};if(r.method!==`POST`||typeof r.body!=`string`)throw Error(`Invalid URL controls request.`);let a=JSON.parse(r.body);if(!a||typeof a!=`object`||!(`identity`in a)||a.identity!==e)throw Error(`The controls URL identity changed.`);let o=i.scopes;if(`reset`in a&&a.reset===!0)o={};else if(`replace`in a&&a.replace===!0&&`scopes`in a){if(!a.scopes||typeof a.scopes!=`object`||Array.isArray(a.scopes))throw Error(`Invalid controls history settings.`);let e={};for(let[t,n]of Object.entries(a.scopes)){if(!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(t)||!Ce(n))throw Error(`Invalid controls history settings.`);e[t]=n}o=De(Ee(e)).scopes}else{if(!(`scope`in a)||typeof a.scope!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(a.scope)||!(`values`in a)||!Ce(a.values))throw Error(`Invalid URL control settings.`);o={...o,[a.scope]:a.values}}let s=Oe(t(),Ee(o));s!==t()&&n(s)})}function ir({frameRef:e,prototypeUrl:t,previewUrl:n,address:r,replaceAddress:i}){let[a,o]=(0,V.useState)(null),[s,c]=(0,V.useState)(null),l=(0,V.useRef)({address:r,replaceAddress:i});return(0,V.useLayoutEffect)(()=>{l.current={address:r,replaceAddress:i}},[r,i]),(0,V.useEffect)(()=>{if(!e.current)return;let r=new nr(e.current,new URL(n??t).origin,rr(`prototype:${new URL(t).origin}`,()=>l.current.address,e=>{l.current.address=e,l.current.replaceAddress(e)}));o(r);let i=r.subscribe(()=>c(r.getSnapshot()));return r.start(),()=>{i(),r.stop()}},[t,n,e]),{connection:a,state:s}}function ar({token:e,status:t,onStatusChange:n,onSelectHub:r}){let[i,a]=(0,V.useState)(!1),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(``),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(null),m=(0,V.useRef)(!1),h=(0,V.useRef)(!1),g=t?.state===`connected`||t?.state===`undiscovered`,_=t?.state===`disconnected`||t?.state===`pairing`||t?.state===`unconfigured`,v=g?null:t?.pairing||(f?.repository===t?.repository&&f?.hubOrigin===t?.hubOrigin?f?.pairing:null),y=v?.verificationUrl;(0,V.useEffect)(()=>{let e=window.setTimeout(()=>{g?(a(!1),p(null),l(``)):_&&t?.repository&&!m.current&&(m.current=!0,a(!0))},0);return()=>window.clearTimeout(e)},[g,_,t?.repository]),(0,V.useEffect)(()=>{if(!y||u)return;let t=!1,r=!1;async function i(){if(!r){r=!0;try{let r=await $(`/api/hub/poll`,e,{method:`POST`,body:`{}`});if(t)return;r.status!==`pending`&&(p(null),r.status!==`approved`&&l(K.connectionApprovalExpired),await n())}catch(e){t||(l(e instanceof Error?e.message:String(e)),d(!0))}finally{r=!1}}}let a=window.setInterval(()=>void i(),3e3);return()=>{t=!0,window.clearInterval(a)}},[y,u,e,n,t?.repository,t?.hubOrigin]);async function b(i){if(m.current=!0,!h.current){if(!t?.repository)l(K.connectionRepositoryRequired);else if(!t.hubOrigin&&!i)l(K.connectionHubRequired);else{h.current=!0,s(!0),l(``),d(!1);try{!t.hubOrigin&&i&&await r(i);let a=await $(`/api/hub/connect`,e,{method:`POST`,body:`{}`});p({repository:t.repository,hubOrigin:new URL(a.verificationUrl).origin,pairing:a}),a.browserError&&l(K.connectionBrowserFailed(a.browserError)),await n()}catch(e){l(e instanceof Error?e.message:String(e))}finally{h.current=!1,s(!1)}}}}function x(){a(!0),t?.hubOrigin&&b()}return{open:i,close:()=>a(!1),show:()=>a(!0),showAndConnect:x,connect:b,connecting:o,error:c,pairing:v}}function or({token:e,onStatus:t,onError:n}){let[r,i]=(0,V.useState)(null),a=(0,V.useRef)(0),o=(0,V.useRef)(0),s=(0,V.useRef)(!1),c=(0,V.useCallback)(async(r,c=!1)=>{if(s.current||c&&o.current>0)return;o.current+=1;let l=++a.current;try{let o=r===`open`||r===`interaction`,c=await $(o?r===`open`?`/api/hub/open`:`/api/hub/activity`:`/api/hub/status`,e,o?{method:`POST`,body:`{}`}:{});if(l!==a.current||s.current)return;i(c);let u=c.prototype?.startPageImportError||c.localStartPageError;u&&n(u),t(c)}catch(e){if(l!==a.current||s.current)return;let t=e instanceof Error?e.message:String(e);i(e=>({state:`unavailable`,repository:e?.repository,branch:e?.branch,hubOrigin:e?.hubOrigin,message:K.hubStatusUnavailable(t)})),n(t)}finally{--o.current}},[e,t,n]),l=(0,V.useCallback)(async t=>{s.current=!0,a.current+=1,i(null);try{await $(`/api/hub/origin`,e,{method:`POST`,body:JSON.stringify({origin:t})})}finally{s.current=!1,await c()}},[e,c]);(0,V.useEffect)(()=>{let e=window.setTimeout(()=>void c(`open`),0),t=window.setInterval(()=>void c(void 0,!0),15e3);function n(){c(`interaction`)}return window.addEventListener(`focus`,n),()=>{a.current+=1,window.clearTimeout(e),window.clearInterval(t),window.removeEventListener(`focus`,n)}},[c]);async function u(){let t=await $(`/api/hub/discovery`,e,{method:`POST`,body:`{}`});if(t.discovery?.state!==`valid`||!t.discovery.origin)throw Error(t.discovery?.message||K.resetHubUnavailable);return await c(),t.discovery.origin}return{status:r,refresh:c,select:l,reset:u}}function sr({prototypeUrl:e,previewUrl:t,shellRef:n,cancelClick:r}){let[{key:i,ref:a},o]=(0,V.useState)(()=>({key:0,ref:(0,V.createRef)()})),[s,c]=(0,V.useState)({input:e,url:e}),[l,u]=(0,V.useState)({input:e,entries:[e],index:0}),[d,f]=(0,V.useState)(()=>window.matchMedia?.(`(prefers-color-scheme: dark)`)?.matches?`dark`:`light`),[p,m]=(0,V.useState)(null),h=(0,V.useRef)(null),g=l.input===e?l:{input:e,entries:[e],index:0},_=g.entries[g.index],v=(0,V.useCallback)(()=>r.current?.(),[r]),y=(0,V.useCallback)(t=>{if(new URL(t).origin!==new URL(e).origin)throw Error(K.startPageOrigin);u(e=>{let n=[...e.entries];return n[e.index]=t,{...e,entries:n}})},[e]),b=(0,V.useCallback)(t=>{if(h.current===e)return;h.current=e;let n=new URL(e),r=t.state===`connected`&&(t.prototype?.startPageSet??t.prototype?.startPage!==void 0)?t.prototype?.startPage:t.localStartPage;if(n.pathname!==`/`||n.search||n.hash||!r)return;let i=new URL(r,n);if(i.origin!==n.origin)throw Error(K.startPageOrigin);c({input:e,url:i.href}),u({input:e,entries:[i.href],index:0})},[e]);function x(){v(),m(null),c({input:e,url:_}),o(e=>({key:e.key+1,ref:(0,V.createRef)()}))}function S(t){t===_?x():(u(n=>{let r=n.input===e?n:g;return{...r,entries:[...r.entries.slice(0,r.index+1),t],index:r.index+1}}),c({input:e,url:t}))}function C(t){let n=g.entries[t];n&&(u({...g,index:t}),c({input:e,url:n}))}let w=(0,V.useCallback)((t,n=!1)=>{m(t);let r=new URL(e);r.pathname=t.pathname,r.search=t.search,r.hash=t.hash,u(t=>{let i=t.input===e?t:{input:e,entries:[e],index:0},a=new URL(i.entries[i.index]),o=[...a.searchParams].filter(([e])=>e.startsWith(`rc.`));for(let e of[r,a])for(let t of[...e.searchParams.keys()])(t===`rc`||t.startsWith(`rc.`))&&e.searchParams.delete(t);if(a.pathname===r.pathname&&a.searchParams.toString()===r.searchParams.toString()&&a.hash===r.hash)return i;for(let[e,t]of o)r.searchParams.append(e,t);let s=r.href;if(n){let e=[...i.entries];return e[i.index]=s,{...i,entries:e}}return{...i,entries:[...i.entries.slice(0,i.index+1),s],index:i.index+1}})},[e]);(0,V.useEffect)(()=>{let e=a.current;if(!e)return;function t(){v(),m(null)}return e.addEventListener(`load`,t),()=>{v(),e.removeEventListener(`load`,t)}},[v,a]),(0,V.useEffect)(()=>{let r=a.current;if(!r)return;let i=new URL(t??e).origin,o=crypto.randomUUID();function s(){let e=n.current?.closest(`.canvas-base`);e&&r?.contentWindow?.postMessage({type:`replica:canvas:theme`,nonce:o,accent:window.getComputedStyle(e).getPropertyValue(`--hub-accent`).trim()},i)}function c(e){e.source===r?.contentWindow&&e.origin===i&&e.data?.type===`replica:canvas:ready`&&s()}return r.addEventListener(`load`,s),window.addEventListener(`message`,c),s(),()=>{r.removeEventListener(`load`,s),window.removeEventListener(`message`,c)}},[d,e,t,a,n]);let T=new URL(s.input===e?s.url:e);if(t){let e=new URL(t);T.protocol=e.protocol,T.host=e.host}return{frameRef:a,frameKey:i,source:T.href,navigation:g,address:_,replaceAddress:y,appearance:d,setAppearance:f,liveRoute:p,initialize:b,reportRoute:w,reload:x,navigate:S,travel:C}}function cr(e){let[t,n]=(0,V.useState)(null),[r,i]=(0,V.useState)(``),a=(0,V.useRef)(null),o=(0,V.useRef)(0),s=(0,V.useRef)(0),c=(0,V.useCallback)(async(t,r=!1)=>{if(r&&s.current>0)return;s.current+=1;let c=++o.current;try{let r=await $(t?`/api/refresh`:`/api/state`,e,t?{method:`POST`,body:`{}`}:{});if(c!==o.current)return;a.current=r,n(r),i(``)}catch(e){if(c!==o.current)return;n(t=>t&&{...t,stats:{...t.stats,remoteBranch:{state:`unknown`,repository:t.stats.repository||null,branch:t.stats.branch||null,commitSha:t.stats.commitSha||null,error:lr(e)}}}),i(lr(e))}finally{--s.current}},[e]);return(0,V.useEffect)(()=>{let e=window.setTimeout(()=>void c(!0),0),t=window.setInterval(()=>{let e=a.current?.publishStatus?.state,t=a.current?.publishRequest,n=e===`requested`||e===`in_progress`||t?.state===`requested`||!!t?.requestedAt&&(e===`not_published`||e===`unavailable`);c(n,!0)},15e3);function n(){c(!0)}return window.addEventListener(`focus`,n),()=>{o.current+=1,window.clearTimeout(e),window.clearInterval(t),window.removeEventListener(`focus`,n)}},[c]),{state:t,error:r,setError:i,refresh:c}}function lr(e){return e instanceof Error?e.message:String(e)}function ur({token:e,enabled:t,repository:n,branch:r,commitSha:i,publicationRevision:a}){let o=`${n}/${r}/${i}/${a}`,[s,c]=(0,V.useState)(null),[l,u]=(0,V.useState)(!1),[d,f]=(0,V.useState)(!1),p=(0,V.useRef)(null),m=(0,V.useRef)(0),h=t&&s?.identity===o?s:null,g=(0,V.useCallback)(async()=>{if(!t)return;let i=++m.current;u(!0);try{if(await p.current,i!==m.current)return;let t=await $(`/api/publish/prepare`,e,{method:`POST`,body:`{}`});if(i!==m.current)return;if(t.target.repository!==n||t.target.branch!==r)throw Error(q.preferenceTargetChanged);if(typeof t.remember!=`boolean`)throw Error(q.invalidPreference);c({identity:o,preparation:t,error:``})}catch(e){i===m.current&&c({identity:o,preparation:null,error:e instanceof Error?e.message:String(e)})}finally{i===m.current&&u(!1)}},[t,e,n,r,o]);(0,V.useEffect)(()=>{let e=window.setTimeout(()=>void g(),0);return()=>{m.current+=1,window.clearTimeout(e)}},[g]);async function _(n){if(!t||!h?.preparation||l||p.current)return;f(!0);let r=m.current,i=h.preparation,a=(async()=>{try{if((await $(`/api/publish/preference`,e,{method:`POST`,body:JSON.stringify({target:i.target,remember:n})})).remember!==n)throw Error(q.invalidPreference);r===m.current&&c({identity:o,preparation:{...i,remember:n},error:``})}catch(e){r===m.current&&c({identity:o,preparation:i,error:e instanceof Error?e.message:String(e)})}})();p.current=a;try{await a}finally{p.current=null,f(!1)}}return{remember:h?.preparation?.remember??null,loading:l||!h,saving:d,error:h?.error||``,save:_,retry:g}}function dr(e,t,n){let r=n?.included,i=n?.error,a=n?.revision,o=(0,V.useMemo)(()=>{if(r!==void 0)return{identity:e,revision:a,included:r,error:i??``,pending:!1};let t=!1,n=``;if(e)try{let n=localStorage.getItem(`replica:share-controls:v1:${e}`);if(n!==null&&n!==`true`&&n!==`false`)throw Error(`Invalid saved share preference.`);t=n===`true`}catch{n=`The share preference could not be read. Control settings are off by default.`}return{identity:e,revision:a,included:t,error:n,pending:!1}},[e,a,r,i]),[s,c]=(0,V.useState)(o),l=s.identity===e&&s.revision===a?s:o,u=``,d=``;if(l.included)try{u=Ee(t)}catch(e){d=e instanceof Error?e.message:`Control settings could not be shared.`}return{included:l.included,query:u,error:d||l.error,blocked:!!d,...n?{pending:l.pending}:{},onChange:t=>{if(n){c({identity:e,revision:a,included:t,error:``,pending:!0});function r(n){c(r=>r.identity===e&&r.revision===a&&r.included===t?{...r,error:n,pending:!1}:r)}n.onChange(t).then(()=>r(``),e=>r(e instanceof Error?e.message:`This preference could not be saved. It will only apply while this page is open.`));return}let r=``;if(e)try{localStorage.setItem(`replica:share-controls:v1:${e}`,String(t))}catch{r=`This preference could not be saved. It will only apply while this page is open.`}c({identity:e,revision:a,included:t,error:r,pending:!1})}}}function fr({token:e,state:t,hubStatus:n}){let[r,i]=(0,V.useState)(null),a=!!(r&&(r.stale||r.repository!==void 0&&r.repository!==t?.stats.repository||r.branch!==void 0&&r.branch!==t?.stats.branch||n?.hubOrigin!==void 0&&r.hubOrigin!==void 0&&r.hubOrigin!==n.hubOrigin||r.token!==e));(0,V.useEffect)(()=>{if(!r||r.stale)return;let e=r.repository??t?.stats.repository,o=r.branch??t?.stats.branch,s=r.hubOrigin??n?.hubOrigin;if(!a&&e===r.repository&&o===r.branch&&s===r.hubOrigin)return;let c=window.setTimeout(()=>{i(t=>t&&{...t,repository:e,branch:o,hubOrigin:s,stale:a,connecting:!a&&t.connecting})},0);return()=>window.clearTimeout(c)},[r,a,t?.stats.repository,t?.stats.branch,n?.hubOrigin]);function o(){i({repository:t?.stats.repository,branch:t?.stats.branch,hubOrigin:n?.hubOrigin,token:e,connecting:!1,stale:!1})}function s(e){i(t=>t&&{...t,connecting:e})}return{intent:r,targetChanged:a,begin:o,close:()=>i(null),setConnecting:s}}var pr={open:!1,context:null,links:[],loading:!1,busy:!1,stale:!0,error:``,notice:``,created:null};function mr({token:e,hubStatus:t,prototypeState:n}){let[r,i]=(0,V.useState)(pr),a=(0,V.useRef)(r);a.current=r;let o=(0,V.useRef)(0),s=(0,V.useRef)(!1),c=(0,V.useRef)(!1),l=(0,V.useRef)(!1),u=(0,V.useRef)(!1),d=(0,V.useRef)(null),f=`${t?.hubOrigin}/${t?.repository}/${t?.branch}/${t?.state}`,p=(0,V.useRef)(f);p.current=f;let m=(0,V.useCallback)(()=>{!u.current||s.current||c.current||l.current||!d.current||(u.current=!1,d.current())},[]);(0,V.useLayoutEffect)(()=>{o.current+=1,i(e=>e.open?{...pr,open:!0,error:J.stale}:pr)},[f,e]),(0,V.useEffect)(()=>()=>{o.current+=1,u.current=!1},[]),(0,V.useEffect)(()=>{let e=t?.prototype;e&&e.canManageShareLinks!==!0&&a.current.context?.prototype.canManageShareLinks===!0&&(o.current+=1,i(t=>t.open&&t.context?.prototype.id===e.id?{...pr,open:!0,stale:!1,context:{...t.context,prototype:{...t.context.prototype,canManageShareLinks:e.canManageShareLinks}}}:t))},[t?.prototype]),(0,V.useEffect)(()=>{t?.prototype?.publicSharingEnabled===!1&&(o.current+=1,i(e=>e.open?{...pr,open:!0,sharingDisabled:!0,error:J.disabled,context:e.context?{...e.context,prototype:{...e.context.prototype,publicSharingEnabled:!1}}:null}:pr))},[t?.prototype?.publicSharingEnabled]);let h=(0,V.useCallback)((t,n)=>$(`/api/hub/share-links/${t}`,e,{method:`POST`,body:JSON.stringify(n)}),[e]),g=(0,V.useCallback)(e=>{e instanceof Error&&`code`in e&&(e.code===`public_sharing_disabled`||e.code===`public_sharing_changed`||e.code===`creator_access_changed`)&&(o.current+=1,i(t=>({...t,busy:!1,loading:!1,stale:!0,sharingDisabled:e.code===`public_sharing_disabled`,links:[],created:null,authorization:void 0})))},[]),_=(0,V.useCallback)(async(e=a.current.context)=>{if(!e||!e.prototype.canManageShareLinks||e.prototype.publicSharingEnabled===!1||c.current)return;c.current=!0;let t=o.current,n=p.current;i(e=>({...e,loading:!0,stale:!0,error:``}));try{let r=new Map,a=new Set,s=null;do{let i=await h(`list`,{target:e.target,...s?{cursor:s}:{}});if(t!==o.current||n!==p.current)return;for(let e of i.shareLinks)r.set(e.id,e);if(s=i.nextCursor,s){if(a.has(s))throw Error(J.paginationFailed);a.add(s)}}while(s);i(e=>({...e,links:[...r.values()],created:e.created?r.get(e.created.id)??null:null,loading:u.current,stale:u.current,sharingDisabled:!1}))}catch(e){t===o.current&&n===p.current&&(i(t=>({...t,loading:!1,stale:!0,error:e instanceof Error?e.message:J.failed})),g(e))}finally{c.current=!1,m()}},[h,m,g]),v=(0,V.useCallback)(async()=>{if(s.current||l.current||c.current){u.current=!0,i(e=>({...e,open:!0,stale:!0,loading:!0}));return}l.current=!0;let e=++o.current,r=p.current;i({...pr,open:!0,loading:!0});let a=t?.repository===n?.stats.repository&&t?.branch===n?.stats.branch,d=``;if(!t||[`disconnected`,`pairing`,`unconfigured`].includes(t.state)?d=J.disconnected:[`unavailable`,`denied`].includes(t.state)?d=J.unavailable:(t.state!==`connected`||!a)&&(d=J.branch),d)i({...pr,open:!0,error:d}),l.current=!1;else try{let t=await h(`context`,{});if(e!==o.current||r!==p.current)return;i(e=>({...e,context:t,loading:!1,stale:t.prototype.canManageShareLinks===!0})),await _(t)}catch(t){e===o.current&&r===p.current&&i(e=>({...e,loading:!1,error:t instanceof Error?t.message:J.failed}))}finally{l.current=!1,m()}},[t,n,_,h,m]);d.current=v;let y=(0,V.useCallback)(async(e,t)=>{let n=a.current;if(s.current||l.current||c.current||u.current||n.stale||!n.context||n.context.prototype.canManageShareLinks!==!0||n.sharingDisabled||n.context.prototype.publicSharingEnabled===!1)return!1;s.current=!0;let r=o.current;i(e=>({...e,busy:!0,error:``,notice:``}));try{let a=await h(e,{target:n.context.target,...t});return r===o.current&&(i(n=>({...n,notice:e===`delete`?J.deleted:``,authorization:void 0,created:`id`in a?a:e===`delete`&&`id`in t&&n.created?.id===t.id?null:n.created,links:e===`delete`&&`id`in t?n.links.filter(e=>e.id!==t.id):n.links})),await _(n.context),!0)}catch(e){if(r!==o.current)return!1;let t=e instanceof Error&&`code`in e&&e.code===`fresh_authorization_required`&&`authorization`in e&&e.authorization&&typeof e.authorization==`object`&&`url`in e.authorization&&typeof e.authorization.url==`string`&&`expiresAt`in e.authorization&&typeof e.authorization.expiresAt==`string`?{url:e.authorization.url,expiresAt:e.authorization.expiresAt}:void 0,n=e instanceof Error&&(!(`statusCode`in e)||`code`in e&&e.code===`share_delivery_unknown`);return i(r=>({...r,stale:!0,authorization:t,error:n?J.unknown:e instanceof Error?e.message:J.failed})),g(e),!1}finally{s.current=!1,r===o.current&&i(e=>({...e,busy:!1})),m()}},[_,h,m,g]),b=(0,V.useCallback)(async e=>{let t=a.current;if(!t.context||l.current||c.current||u.current)throw Error(J.stale);let n=o.current,r=await h(`controls-preference`,{target:t.context.target,included:e});if(n!==o.current)throw Error(J.stale);if(r.included!==e)throw Error(`The share preference could not be saved.`)},[h]),x=(0,V.useCallback)(async(e,t)=>{let n=a.current;if(!n.context||n.stale||l.current||c.current||u.current)return;let r=o.current;try{await h(`open`,{target:n.context.target,id:e,...t?{controlsQuery:t}:{}})}catch(e){r===o.current&&(i(t=>({...t,error:e instanceof Error?e.message:J.failed})),g(e))}},[h,g]),S=(0,V.useCallback)(async()=>{let e=a.current;if(!e.context||!e.authorization||e.busy)return;let t=o.current;try{await h(`authorize`,{target:e.context.target}),t===o.current&&i(e=>({...e,notice:J.authorizationRetry}))}catch(e){t===o.current&&(i(t=>({...t,error:e instanceof Error?e.message:J.failed})),g(e))}},[h,g]);return(0,V.useEffect)(()=>{if(!r.open||!r.context)return;function e(){s.current||_()}let t=window.setInterval(e,3e4);return window.addEventListener(`focus`,e),()=>{window.clearInterval(t),window.removeEventListener(`focus`,e)}},[r.open,r.context,_]),{state:r,open:v,close:()=>{u.current=!1,i(e=>({...e,open:!1}))},refresh:()=>r.context&&!r.sharingDisabled&&r.context.prototype.publicSharingEnabled!==!1?_():v(),create:(e,t)=>y(`create`,{label:e,expiration:t,buildNumber:r.context?.prototype.build?.number}),remove:e=>y(`delete`,{id:e}),openLink:x,setControlPreference:b,authorize:S}}var hr=`modulepreload`,gr=function(e){return`/assets/`+e},_r={},vr=function(e){return e.pathname.endsWith(`.css`)},yr=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},br=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=gr(t,n);let r=s(t),i=vr(r);return yr(_r,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:hr,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},xr=(0,V.lazy)(()=>br(()=>import(`./renderer-improvement-notes-prototype.js`).then(e=>e.t).then(e=>({default:e.ImprovementNotesPrototype})),__vite__mapDeps([0,1,2,3,4]))),Sr=(0,V.lazy)(()=>br(()=>import(`./renderer-prototype-canvas-thread-sample.js`).then(e=>({default:e.PrototypeCanvasThreadSample})),__vite__mapDeps([5,1,2,3,4])));function Cr({config:e}){let t=(0,V.useRef)(null),n=(0,V.useRef)(null),r=(0,V.useRef)(null),i=(0,V.useRef)(null),a=(0,V.useRef)(null),o=(0,V.useRef)(null),s=(0,V.useRef)(null),c=(0,V.useRef)(null),l=(0,V.useRef)(null),u=(0,V.useRef)(null),[d,f]=(0,V.useState)(!1),[p,m]=(0,V.useState)({position:null,collapsed:!1,collapsedGroups:{}}),[h,g]=(0,V.useState)(!1),[_,v]=(0,V.useState)(e.pickAndPolish?`improvements`:`comments`),[y,b]=(0,V.useState)(!1),[x,S]=(0,V.useState)(!1),[C,w]=(0,V.useState)(null),[T,E]=(0,V.useState)(!1),D=(0,V.useRef)(!1),[O,k]=(0,V.useState)(!1),[A,j]=(0,V.useState)(null),M=(0,V.useCallback)(()=>{g(!1),o.current?.focus()},[]),{frameRef:N,frameKey:P,source:F,navigation:I,address:L,replaceAddress:R,appearance:z,setAppearance:ee,liveRoute:B,initialize:te,reportRoute:ne,reload:re,navigate:ie,travel:ae}=sr({prototypeUrl:e.prototypeUrl,previewUrl:e.previewUrl,shellRef:t,cancelClick:u}),oe=ir({...e,frameRef:N,address:L,replaceAddress:R}),se=oe.state;qn({...e,frameRef:N,addressRef:r,appearance:z,navigation:I,liveRoute:B,cancelClick:u,reload:re,controlsConnection:oe.connection});let{state:ce,error:le,setError:ue,refresh:W}=cr(e.token),G=or({token:e.token,onStatus:te,onError:ue}),de=ar({token:e.token,status:G.status,onStatusChange:G.refresh,onSelectHub:G.select}),fe=JSON.stringify([G.status?.hubOrigin,G.status?.repository,G.status?.branch]),pe=G.status?.repositoryAuthorized===!0&&(G.status.state===`connected`||G.status.state===`undiscovered`)&&!!(G.status.repository&&G.status.branch&&G.status.hubOrigin),me=mr({token:e.token,hubStatus:G.status,prototypeState:ce}),q=fr({token:e.token,state:ce,hubStatus:G.status}),he=ur({token:e.token,enabled:h&&G.status?.state===`connected`&&G.status.prototype?.registered===!0&&!!G.status.prototype.build&&G.status.repository===ce?.stats.repository&&G.status.branch===ce?.stats.branch,repository:ce?.stats.repository,branch:ce?.stats.branch,commitSha:ce?.stats.commitSha,publicationRevision:ce?.publishRequest?.requestedAt}),ge=Xn({token:e.token,state:ce,hubStatus:G.status,error:le,setError:ue,refresh:W,refreshHub:G.refresh,preferenceSaving:he.saving}),_e=Bn(ce,G.status,ge.publication),ve=me.state.context,ye=dr(ve?`${ve.hubOrigin}:${ve.prototype.repositoryId}:${ve.prototype.id}`:void 0,oe.connection?.getControlValues()??{},{included:ve?.controlSettingsIncluded??!1,error:ve?.controlSettingsError,revision:ve?.target,onChange:me.setControlPreference});(0,V.useLayoutEffect)(()=>{document.body.classList.remove(`renderer-loading`);let e=t.current,r=n.current;if(!e||!r)return;function i(){let t=r?.getBoundingClientRect().height;t&&e?.style.setProperty(`--canvas-toolbar-height`,`${t}px`)}let a=new ResizeObserver(i);return a.observe(r),i(),()=>a.disconnect()},[]);function be(){de.close(),_e.kind===`ready`?me.open():q.begin()}async function xe(){if(pe&&!D.current){D.current=!0,k(!0),j(null);try{if((await $(`/api/hub/feedback-review`,e.token,{method:`POST`,body:JSON.stringify({repository:G.status?.repository,branch:G.status?.branch,hubOrigin:G.status?.hubOrigin})})).requested!==!0)throw Error(K.invalidResponse)}catch(e){j({target:fe,message:K.feedbackReviewFailed(e instanceof Error?e.message:String(e))}),await G.refresh()}finally{D.current=!1,k(!1)}}}return(0,U.jsxs)(H.ThemeProvider,{colorMode:z,className:`canvas-base`,children:[(0,U.jsxs)(`main`,{ref:t,className:`canvas-shell${me.state.open?` canvas-shell--inactive`:``}`,inert:me.state.open,"aria-hidden":me.state.open?!0:void 0,children:[(0,U.jsx)(Pe,{address:L,addressRef:r,canGoBack:I.index>0,canGoForward:I.indexae(I.index-1),onForward:()=>ae(I.index+1),onNavigate:ie,onOpenTab:async()=>{await $(`/api/prototype/open`,e.token,{method:`POST`,body:JSON.stringify({url:L})})},onReload:re}),(0,U.jsx)(Hn,{toolbarRef:n,improvementControlsRef:w,config:e,state:ge.presentedState,prototypeName:G.status?.state===`connected`&&G.status.prototype?.name||void 0,publishing:ge.busy,publication:ge.publication,publishButtonRef:i,hubButtonRef:o,titleButtonRef:c,onBuildDetails:()=>E(!0),controlsButtonRef:l,controlsOpen:d,onControls:()=>f(!d),onPublish:()=>void ge.publish(),onShare:be,onImproveContext:pe?()=>void xe():void 0,improvingContext:O,feedbackMessage:A?.target===fe?A:void 0,shareButtonRef:a,hubOpen:h,onHub:()=>{g(!h),G.refresh(`interaction`)}}),(0,U.jsx)(`iframe`,{ref:N,className:`prototype-frame`,title:K.prototypeFrameTitle(e.name),src:F,style:{colorScheme:z,backgroundColor:`var(--hub-canvas-default)`}},P),(0,U.jsx)(zn,{config:e,active:_===`comments`,onActivate:()=>v(`comments`),selectionDisabled:x,onInteractionChange:b,frameRef:N,onRouteChange:ne,status:G.status,onStatusChange:G.refresh,onSelectHub:G.select,onConnect:de.showAndConnect,onDisconnected:de.show,connectionButtonRef:s,connecting:de.connecting,publication:ge.publication,publicationBusy:ge.busy,dirty:ce?.stats.workingTree===`changed`,onPublish:()=>void ge.publish(),onRetryPublication:()=>void ge.retry(),publishPreference:he,open:h,onClose:M}),e.improvementThreadsSample?(0,U.jsx)(V.Suspense,{fallback:(0,U.jsx)(`p`,{role:`status`,children:K.improvementNotesLoading}),children:(0,U.jsx)(Sr,{})}):e.pickAndPolish?(0,U.jsx)(V.Suspense,{fallback:(0,U.jsx)(`p`,{className:`visually-hidden`,role:`status`,children:K.improvementNotesLoading}),children:(0,U.jsx)(xr,{canvas:{token:e.token,frameRef:N,toolbarTarget:C,prototypeUrl:e.prototypeUrl,previewUrl:e.previewUrl,hubOpen:h,active:_===`improvements`,selectionDisabled:y,onInteractionChange:S,onOpenNotes:()=>{g(!1),v(`improvements`)},onNavigate:ie}})}):null,d&&oe.connection&&se?(0,U.jsx)(et,{state:se,connection:oe.connection,layout:p,onLayoutChange:m,diagnosisTarget:L,onDiagnose:()=>$(`/api/controls/diagnose`,e.token,{method:`POST`,body:JSON.stringify({status:se.status,runtimeAvailable:se.runtimeAvailable,reconnectRequired:se.reconnectRequired===!0,hasError:!!se.error||Gn(se,se.loading,L).controls.some(e=>e.visible&&!!e.error),hasStorageError:!!se.storageError,previewUrl:L})})}):null]}),(0,U.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`visually-hidden`,children:le||ge.notice}),(0,U.jsx)(Ne,{hub:G,connection:de,publication:ge,sharing:me,shareIntent:q,controlSettings:ye,readiness:_e,state:ce,hubOpen:h,buildDetailsOpen:T,onCloseBuildDetails:()=>E(!1),shareButtonRef:a,hubButtonRef:o,connectionButtonRef:s,publishButtonRef:i,titleButtonRef:c})]})}var wr=document.querySelector(`#root`);if(!wr)throw Error(`Replica prototype renderer root is missing.`);(0,ce.createRoot)(wr).render((0,U.jsx)(Cr,{config:window.__REPLICA_CANVAS__}));export{$ as a,Bt as c,ot as d,at as f,W as h,hn as i,St as l,G as m,Sn as n,qt as o,nt as p,bn as r,Kt as s,kn as t,st as u}; \ No newline at end of file diff --git a/.github/extensions/replica-prototype/marketplace.test.mjs b/.github/extensions/replica-prototype/marketplace.test.mjs index 743f3c23..52e0a4ed 100644 --- a/.github/extensions/replica-prototype/marketplace.test.mjs +++ b/.github/extensions/replica-prototype/marketplace.test.mjs @@ -16,7 +16,7 @@ it("resolves the marketplace's relative source to the shipped plugin", async () ) const manifest = JSON.parse(await readFile(new URL(`${plugin.source}/plugin.json`, root))) assert.equal(manifest.name, plugin.name) - assert.equal(manifest.version, "1.5.0") + assert.equal(manifest.version, "1.5.1") const skill = await readFile( new URL(`${plugin.source}/skills/replica-publish-prototype/SKILL.md`, root), "utf8", diff --git a/.github/extensions/replica-prototype/plugin.json b/.github/extensions/replica-prototype/plugin.json index 65c4b738..6ed4b45c 100644 --- a/.github/extensions/replica-prototype/plugin.json +++ b/.github/extensions/replica-prototype/plugin.json @@ -2,7 +2,7 @@ "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", "name": "replica-prototype", "description": "Wrap a running prototype with Replica publish controls and repository status.", - "version": "1.5.0", + "version": "1.5.1", "author": { "name": "GitHub" }, diff --git a/hub/app/javascript/application/prototype-canvas/index.tsx b/hub/app/javascript/application/prototype-canvas/index.tsx index 2ecb3fb5..fb24225b 100644 --- a/hub/app/javascript/application/prototype-canvas/index.tsx +++ b/hub/app/javascript/application/prototype-canvas/index.tsx @@ -59,6 +59,11 @@ export function App({ config }: Props) { collapsedGroups: {}, }) const [hubOpen, setHubOpen] = useState(false) + const [reviewSurface, setReviewSurface] = useState<"comments" | "improvements">( + config.pickAndPolish ? "improvements" : "comments", + ) + const [commentInteraction, setCommentInteraction] = useState(false) + const [improvementInteraction, setImprovementInteraction] = useState(false) const [improvementControls, setImprovementControls] = useState(null) const [buildDetailsOpen, setBuildDetailsOpen] = useState(false) const feedbackInFlight = useRef(false) @@ -300,6 +305,10 @@ export function App({ config }: Props) { setReviewSurface("comments")} + selectionDisabled={improvementInteraction} + onInteractionChange={setCommentInteraction} frameRef={frameRef} onRouteChange={reportRoute} status={hub.status} @@ -339,7 +348,13 @@ export function App({ config }: Props) { prototypeUrl: config.prototypeUrl, previewUrl: config.previewUrl, hubOpen, - onOpenNotes: () => setHubOpen(false), + active: reviewSurface === "improvements", + selectionDisabled: commentInteraction, + onInteractionChange: setImprovementInteraction, + onOpenNotes: () => { + setHubOpen(false) + setReviewSurface("improvements") + }, onNavigate: navigate, }} /> diff --git a/hub/app/javascript/application/prototype-canvas/stories.tsx b/hub/app/javascript/application/prototype-canvas/stories.tsx index bd841572..ce0247a1 100644 --- a/hub/app/javascript/application/prototype-canvas/stories.tsx +++ b/hub/app/javascript/application/prototype-canvas/stories.tsx @@ -16,12 +16,14 @@ function PublicationDemo({ prototypeUrl, withShareLinks = false, withComments = false, + withPickAndPolish = false, onImproveContext, }: { scenario: string prototypeUrl: string withShareLinks?: boolean withComments?: boolean + withPickAndPolish?: boolean onImproveContext?: () => void }) { const [ready, setReady] = useState(false) @@ -191,6 +193,34 @@ function PublicationDemo({ hasMore: false, nextCursor: null, } + else if ( + withPickAndPolish && + (path === "/api/improvement-notes" || path === "/api/improvement-notes/sync") + ) + data = { + identity: "storybook-notes", + revision: 1, + syncError: null, + activeBatch: null, + notes: [ + { + id: 1, + localId: "storybook-save-action", + kind: "improvement_note", + author: "local", + body: "Keep the save action visible while editing project details.", + thread: { originalStatus: "open", messages: [] }, + anchor: repliedReviewThread.root.anchor, + status: "open", + sync: "local", + revision: 1, + route: "/", + target: "Save", + selector: "#save", + rect: { x: 64, y: 180, width: 88, height: 44 }, + }, + ], + } else if (withComments && /^\/api\/hub\/comments\/\d+\/read$/.test(path)) { const id = Number(path.split("/").at(-2)) const root = comments.find((comment) => comment.id === id && comment.kind === "root") @@ -228,12 +258,19 @@ function PublicationDemo({ window.clearTimeout(timer) window.fetch = originalFetch } - }, [scenario, withShareLinks, withComments, onImproveContext]) + }, [scenario, withShareLinks, withComments, withPickAndPolish, onImproveContext]) return (
{ready ? ( - + ) : null}
@@ -263,7 +300,7 @@ const meta = { argTypes: { scenario: { control: "select", options: Object.keys(publicationExamples) } }, render: (args) => ( ), @@ -407,6 +444,30 @@ export const CommentsSidebar: Story = { throw new Error("The compact avatar must align above the unread dot beside the author.") }, } + +export const CommentsAndPickAndPolish: Story = { + args: { + scenario: "Published", + withComments: true, + withPickAndPolish: true, + }, + render: (args) => ( + + ), +} + +export const CommentsWithPickAndPolishSidebar: Story = { + ...CommentsAndPickAndPolish, + play: async ({ canvas, userEvent }) => { + await userEvent.click( + await canvas.findByRole("button", { name: /^Comments, 3/ }, { timeout: 5_000 }), + ) + await canvas.findByRole("complementary", { name: "Comments" }) + }, +} export const ShareManagement: Story = { args: { scenario: "Published", diff --git a/hub/app/javascript/application/prototype-canvas/tests/commenting-and-polish.test.tsx b/hub/app/javascript/application/prototype-canvas/tests/commenting-and-polish.test.tsx new file mode 100644 index 00000000..e7756b30 --- /dev/null +++ b/hub/app/javascript/application/prototype-canvas/tests/commenting-and-polish.test.tsx @@ -0,0 +1,370 @@ +import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react" +import { describe, expect, it, vi } from "vitest" +import { z } from "zod" + +import { octocatRootComment } from "@/storybook/fixtures/review/comments" +import { copy as notesCopy } from "@features/prototype-canvas-improvement-notes/en" +import type { Note } from "@features/prototype-canvas-improvement-notes/types" +import { copy as threadsCopy } from "@features/prototype-canvas-improvement-threads/en" +import { REVIEW_ANCHOR_SCHEMA } from "@utils/review-anchor/schemas" +import { reviewCommentsCopy as commentsCopy } from "@utils/review-comment/en" +import { importedPrototype, publicationHub } from "@utils/resolve-prototype-publication/fixtures" + +import { App } from ".." +import { sharingFixture } from "./sharing-fixture" + +function reviewFixture() { + const { fetch } = sharingFixture(undefined, { + ...publicationHub, + state: "connected", + repositoryAuthorized: true, + viewerLogin: "octocat", + prototype: importedPrototype, + }) + const original = fetch.getMockImplementation()! + const comment = structuredClone(octocatRootComment) + comment.anchor = REVIEW_ANCHOR_SCHEMA.parse({ ...comment.anchor, selector: "#comment-target" }) + const note: Note = { + id: comment.id, + localId: "saved-note", + kind: "improvement_note", + author: "local", + body: "Make the primary action clearer.", + route: "/", + target: "Save", + selector: "#note-target", + rect: comment.anchor.rect, + anchor: REVIEW_ANCHOR_SCHEMA.parse({ ...comment.anchor, selector: "#note-target" }), + thread: { originalStatus: "open", messages: [] }, + status: "open", + sync: "local", + revision: 1, + } + const saved = { + identity: "review-notes", + revision: 1, + notes: [note], + syncError: null, + activeBatch: null, + } + fetch.mockImplementation(async (path, options) => { + if (path === "/api/hub/comments") + return Response.json({ comments: [comment], hasMore: false, nextCursor: null }) + if (path === "/api/improvement-notes/capture") + return Response.json({ identity: saved.identity, sourceId: "selected-source" }) + if (path === "/api/improvement-notes" || path === "/api/improvement-notes/sync") + return Response.json(saved) + return original(path, options) + }) + return { fetch, comment, note, saved } +} + +function previewBridge() { + const element = screen.getByTitle("Demo prototype") + if (!(element instanceof HTMLIFrameElement)) throw new Error("Expected the prototype iframe.") + const frame: HTMLIFrameElement = element + Object.defineProperties(frame, { + clientWidth: { configurable: true, value: 960 }, + clientHeight: { configurable: true, value: 560 }, + }) + const post = vi.spyOn(frame.contentWindow!, "postMessage") + const messageSchema = z.object({ + type: z.string(), + nonce: z.string(), + mode: z.string().optional(), + anchors: z.array(z.object({ id: z.number(), anchor: REVIEW_ANCHOR_SCHEMA })).optional(), + }) + function messages() { + return post.mock.calls.flatMap(([data]) => { + const parsed = messageSchema.safeParse(data) + return parsed.success ? [parsed.data] : [] + }) + } + function receive(nonce: string, data: Record) { + act(() => { + window.dispatchEvent( + new MessageEvent("message", { + source: frame.contentWindow, + origin: new URL(frame.src).origin, + data: { nonce, ...data }, + }), + ) + }) + } + function ready() { + for (const data of messages()) { + if (data.type === "replica:canvas:request-ready") + receive(data.nonce, { + type: "replica:canvas:ready", + protocolVersion: 1, + improvementSelection: true, + route: { pathname: "/", search: "", hash: "" }, + }) + } + } + function resolveNonce(selector: string) { + const request = messages() + .reverse() + .find( + (data) => + data.type === "replica:canvas:resolve" && + data.anchors?.some( + ({ anchor }) => anchor.kind === "element" && anchor.selector === selector, + ), + ) + if (!request) throw new Error(`Expected an anchor resolution request for ${selector}.`) + return String(request.nonce) + } + function resolve(nonce: string) { + receive(nonce, { + type: "replica:canvas:resolved", + protocolVersion: 1, + route: { pathname: "/", search: "", hash: "" }, + results: [{ id: 1, x: 180, y: 180, rect: { x: 120, y: 160, width: 120, height: 40 } }], + }) + } + fireEvent.load(frame) + ready() + return { post, messages, ready, receive, resolve, resolveNonce } +} + +describe("App()", () => { + it("keeps both review surfaces available and resolves only the active surface's saved pins", async () => { + const { fetch, note, saved } = reviewFixture() + const view = render( + , + ) + const comments = await screen.findByRole("button", { name: /^Comments, 1/ }) + const improvements = await screen.findByRole("button", { name: notesCopy.openNotes(1) }) + expect(screen.getByRole("button", { name: commentsCopy.commentMenuLabel })).toBeVisible() + expect(screen.getByRole("button", { name: notesCopy.annotate })).toBeVisible() + const bridge = previewBridge() + fireEvent.click(improvements) + bridge.ready() + expect(await screen.findByRole("complementary", { name: notesCopy.notes })).toBeVisible() + expect(screen.getByRole("button", { name: `Open improvement: ${note.body}` })).toBeVisible() + const noteNonce = bridge.resolveNonce("#note-target") + bridge.resolve(noteNonce) + expect(screen.getByRole("button", { name: threadsCopy.point(1) })).toBeVisible() + fireEvent.click(screen.getByRole("button", { name: `Open improvement: ${note.body}` })) + const conversation = screen.getByRole("dialog", { name: threadsCopy.conversation }) + const reply = within(conversation).getByRole("textbox", { + name: threadsCopy.comments.replyLabel, + }) + fireEvent.change(reply, { target: { value: "Keep this follow-up draft." } }) + expect(comments).toBeDisabled() + fireEvent.click(comments) + expect(conversation).toBeVisible() + expect(reply).toHaveValue("Keep this follow-up draft.") + fireEvent.change(reply, { target: { value: "" } }) + fireEvent.click(within(conversation).getByRole("button", { name: threadsCopy.back })) + + bridge.post.mockClear() + fireEvent.click(comments) + bridge.ready() + expect(await screen.findByRole("searchbox", { name: commentsCopy.searchLabel })).toBeVisible() + expect(screen.getByRole("button", { name: /Please align this control/ })).toBeVisible() + expect(screen.queryByRole("complementary", { name: notesCopy.notes })).not.toBeInTheDocument() + expect(screen.queryByRole("button", { name: threadsCopy.point(1) })).not.toBeInTheDocument() + const commentNonce = bridge.resolveNonce("#comment-target") + expect(commentNonce).not.toBe(noteNonce) + expect( + bridge + .messages() + .some( + (data) => + data.type === "replica:canvas:resolve" && + data.anchors?.some( + ({ anchor }) => anchor.kind === "element" && anchor.selector === "#note-target", + ), + ), + ).toBe(false) + bridge.resolve(noteNonce) + expect( + screen.queryByRole("button", { name: "Unread thread started by @octocat" }), + ).not.toBeInTheDocument() + bridge.resolve(commentNonce) + expect(screen.getByRole("button", { name: "Unread thread started by @octocat" })).toBeVisible() + + bridge.post.mockClear() + fireEvent.click(improvements) + bridge.ready() + expect(await screen.findByRole("complementary", { name: notesCopy.notes })).toBeVisible() + expect(screen.getByRole("button", { name: `Open improvement: ${note.body}` })).toBeVisible() + expect( + screen.queryByRole("searchbox", { name: commentsCopy.searchLabel }), + ).not.toBeInTheDocument() + expect( + screen.queryByRole("button", { name: "Unread thread started by @octocat" }), + ).not.toBeInTheDocument() + bridge.resolve(bridge.resolveNonce("#note-target")) + expect(screen.getByRole("button", { name: threadsCopy.point(1) })).toBeVisible() + expect(saved.notes).toEqual([note]) + expect( + fetch.mock.calls.filter( + ([path, options]) => + options?.method === "POST" && + (path.startsWith("/api/hub/comments") || path.startsWith("/api/improvement-notes")) && + path !== "/api/improvement-notes/sync", + ), + ).toEqual([]) + view.unmount() + }) + + it.each(["element", "area"] as const)( + "opens only the selected %s comment composer or improvement composer and protects its draft", + async (mode) => { + const { comment } = reviewFixture() + const view = render( + , + ) + const comments = await screen.findByRole("button", { name: /^Comments, 1/ }) + const improvements = await screen.findByRole("button", { name: notesCopy.openNotes(1) }) + const bridge = previewBridge() + const noteNonce = bridge.resolveNonce("#note-target") + if (mode === "area") { + fireEvent.click(comments) + bridge.ready() + } + fireEvent.click(screen.getByRole("button", { name: commentsCopy.commentMenuLabel })) + fireEvent.click( + screen.getByRole("menuitem", { + name: + mode === "element" + ? commentsCopy.commentOnElementLabel + : commentsCopy.highlightRegionLabel, + }), + ) + bridge.ready() + const commentNonce = bridge.resolveNonce("#comment-target") + await waitFor(() => + expect(bridge.post).toHaveBeenCalledWith( + { type: "replica:canvas:select", nonce: commentNonce, mode }, + "http://localhost:4321", + ), + ) + fireEvent.click(screen.getByRole("button", { name: notesCopy.annotate })) + expect(improvements).toBeDisabled() + const anchor = + mode === "element" + ? comment.anchor + : { + schemaVersion: 1, + kind: "area", + route: comment.anchor.route, + rect: comment.anchor.rect, + viewport: comment.anchor.viewport, + path: [ + { x: 0, y: 0 }, + { x: 1, y: 1 }, + ], + elements: [], + } + bridge.receive(noteNonce, { type: "replica:canvas:selected", anchor }) + expect(screen.queryByRole("dialog")).not.toBeInTheDocument() + bridge.receive(commentNonce, { type: "replica:canvas:selected", anchor }) + const composer = screen.getByRole("dialog", { name: commentsCopy.composerHeading }) + expect(screen.getAllByRole("dialog")).toEqual([composer]) + const draft = within(composer).getByRole("textbox", { name: commentsCopy.composerLabel }) + fireEvent.change(draft, { target: { value: "Keep this comment draft." } }) + fireEvent.click(improvements) + expect(composer).toBeVisible() + expect(draft).toHaveValue("Keep this comment draft.") + fireEvent.keyDown(draft, { key: "Escape" }) + fireEvent.click(screen.getByRole("button", { name: commentsCopy.discardButtonLabel })) + await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument()) + + fireEvent.click(screen.getByRole("button", { name: notesCopy.annotate })) + bridge.ready() + const currentNoteNonce = bridge.resolveNonce("#note-target") + await waitFor(() => + expect(bridge.post).toHaveBeenCalledWith( + { type: "replica:canvas:select", nonce: currentNoteNonce, mode: "improvement" }, + "http://localhost:4321", + ), + ) + bridge.receive(commentNonce, { type: "replica:canvas:selected", anchor }) + expect(screen.queryByRole("dialog")).not.toBeInTheDocument() + bridge.receive(currentNoteNonce, { type: "replica:canvas:selected", anchor }) + const noteComposer = screen.getByRole("dialog", { name: notesCopy.add }) + expect(screen.getAllByRole("dialog")).toEqual([noteComposer]) + const noteDraft = within(noteComposer).getByRole("textbox", { name: notesCopy.label }) + fireEvent.change(noteDraft, { target: { value: "Keep this improvement draft." } }) + fireEvent.click(comments) + expect(noteComposer).toBeVisible() + expect(noteDraft).toHaveValue("Keep this improvement draft.") + expect(screen.getByRole("button", { name: commentsCopy.commentMenuLabel })).toBeDisabled() + view.unmount() + }, + ) + + it("does not let comments cross-start while an improvement source capture is pending", async () => { + const { fetch } = reviewFixture() + const original = fetch.getMockImplementation()! + let completeCapture!: (response: Response) => void + fetch.mockImplementation((path, options) => + path === "/api/improvement-notes/capture" + ? new Promise((resolve) => { + completeCapture = resolve + }) + : original(path, options), + ) + const view = render( + , + ) + const comments = await screen.findByRole("button", { name: /^Comments, 1/ }) + await screen.findByRole("button", { name: notesCopy.openNotes(1) }) + const bridge = previewBridge() + fireEvent.click(screen.getByRole("button", { name: notesCopy.annotate })) + await waitFor(() => expect(completeCapture).toBeTypeOf("function")) + expect(comments).toBeDisabled() + const addComment = screen.getByRole("button", { name: commentsCopy.commentMenuLabel }) + expect(addComment).toBeDisabled() + fireEvent.click(comments) + fireEvent.click(addComment) + expect(screen.queryByRole("menuitem")).not.toBeInTheDocument() + expect( + screen.queryByRole("searchbox", { name: commentsCopy.searchLabel }), + ).not.toBeInTheDocument() + act(() => { + completeCapture(Response.json({ identity: "review-notes", sourceId: "selected-source" })) + }) + await waitFor(() => + expect(bridge.post).toHaveBeenCalledWith( + { + type: "replica:canvas:select", + nonce: bridge.resolveNonce("#note-target"), + mode: "improvement", + }, + "http://localhost:4321", + ), + ) + const modes = bridge + .messages() + .filter((data) => data.type === "replica:canvas:select") + .map((data) => data.mode) + expect(modes).toEqual(["improvement"]) + view.unmount() + }) +}) diff --git a/hub/app/javascript/features/prototype-canvas-hub-panel/index.tsx b/hub/app/javascript/features/prototype-canvas-hub-panel/index.tsx index b5b3ab97..09e85ab0 100644 --- a/hub/app/javascript/features/prototype-canvas-hub-panel/index.tsx +++ b/hub/app/javascript/features/prototype-canvas-hub-panel/index.tsx @@ -3,6 +3,7 @@ import { Button, Heading, Tooltip } from "@primer/react-brand" import { useCallback, useEffect, + useEffectEvent, useLayoutEffect, useMemo, useRef, @@ -49,6 +50,10 @@ import "./styles.css" type Props = { config: CanvasConfig + active?: boolean + onActivate?: () => void + selectionDisabled?: boolean + onInteractionChange?: (blocked: boolean) => void frameRef: RefObject onRouteChange?: (route: ReviewRoute, replace?: boolean) => void status: HubStatus | null @@ -85,6 +90,10 @@ function reviewRoute(value: unknown): ReviewRoute | null { export function PrototypeCanvasHubPanel({ config, + active: reviewActive = true, + onActivate, + selectionDisabled = false, + onInteractionChange, frameRef, onRouteChange, status, @@ -315,7 +324,29 @@ export function PrototypeCanvasHubPanel({ Boolean(status?.repositoryAuthorized && status.branch && status.viewerLogin) || Boolean(prototype) const selectionBlocked = - selectedAnchor !== null || draftActive || mutation !== null || preparingSelection + selectedAnchor !== null || + draftActive || + mutation !== null || + preparingSelection || + selectionDisabled + useLayoutEffect(() => { + onInteractionChange?.( + selectedAnchor !== null || + draftActive || + mutation !== null || + preparingSelection || + selectionMode !== null || + selected !== null, + ) + }, [ + selectedAnchor, + draftActive, + mutation, + preparingSelection, + selectionMode, + selected, + onInteractionChange, + ]) const hubVisible = open && !commentsOpen const reviewControlsTarget = typeof document === "undefined" ? null : document.getElementById("canvas-review-controls") @@ -389,7 +420,7 @@ export function PrototypeCanvasHubPanel({ }, [open, onClose]) const editingCurrent = editing && draftIdentity === identity const anchorKey = JSON.stringify( - config.pickAndPolish ? [] : threads.map(({ root }) => ({ id: root.id, anchor: root.anchor })), + reviewActive ? threads.map(({ root }) => ({ id: root.id, anchor: root.anchor })) : [], ) const loadComments = useCallback(async () => { @@ -550,7 +581,8 @@ export function PrototypeCanvasHubPanel({ const startSelection = useCallback( async (mode: "element" | "area") => { - if (config.pickAndPolish || !bridgeReady || !canCreateComment || selectionBlocked) return + if (!bridgeReady || !canCreateComment || selectionBlocked) return + onActivate?.() const requestedIdentity = identity const selectionRequest = ++selectionRequestRef.current selectionRevisionRef.current = undefined @@ -591,7 +623,7 @@ export function PrototypeCanvasHubPanel({ } }, [ - config.pickAndPolish, + onActivate, bridgeReady, canCreateComment, config.token, @@ -622,6 +654,37 @@ export function PrototypeCanvasHubPanel({ setCreateError("") }, [sendBridge]) + const receiveSelection = useEffectEvent((data: Record) => { + if (!reviewActive || !selectionMode || preparingSelection) return + if (data.type === "replica:canvas:selected") { + const parsed = REVIEW_ANCHOR_SCHEMA.safeParse(data.anchor) + if (!parsed.success) { + sendBridge("replica:canvas:cancel-selection") + sendBridge("replica:canvas:clear-selection") + setSelectionMode(null) + setSelectionFailure( + isRecord(data.anchor) && data.anchor.kind === "area" + ? "area-unavailable" + : "element-unavailable", + ) + return + } + setSelectedAnchor(parsed.data) + setSelectionMode(null) + setSelectionFailure(null) + } else if ( + data.type === "replica:canvas:selection-failed" && + (data.reason === "element-unavailable" || + data.reason === "area-too-small" || + data.reason === "area-unavailable") + ) { + setSelectionMode(null) + setSelectionFailure(data.reason) + } else if (data.type === "replica:canvas:selection-cancelled") { + setSelectionMode(null) + } + }) + useEffect(() => { const frame = frameRef.current if (!frame) { @@ -648,7 +711,7 @@ export function PrototypeCanvasHubPanel({ resolveAnchors() } function resolveAnchors() { - if (anchors.length) + if (reviewActive && anchors.length) frame?.contentWindow?.postMessage( { type: "replica:canvas:resolve", @@ -748,39 +811,7 @@ export function PrototypeCanvasHubPanel({ setMarkers(next) return } - if (data.type === "replica:canvas:selected") { - if (config.pickAndPolish) return - const parsed = REVIEW_ANCHOR_SCHEMA.safeParse(data.anchor) - if (!parsed.success) { - sendBridge("replica:canvas:cancel-selection") - sendBridge("replica:canvas:clear-selection") - setSelectionMode(null) - setSelectionFailure( - isRecord(data.anchor) && data.anchor.kind === "area" - ? "area-unavailable" - : "element-unavailable", - ) - return - } - setSelectedAnchor(parsed.data) - setSelectionMode(null) - setSelectionFailure(null) - return - } - if ( - data.type === "replica:canvas:selection-failed" && - (data.reason === "element-unavailable" || - data.reason === "area-too-small" || - data.reason === "area-unavailable") - ) { - setSelectionMode(null) - setSelectionFailure(data.reason) - return - } - if (data.type === "replica:canvas:selection-cancelled") { - setSelectionMode(null) - return - } + receiveSelection(data) } function onFrameLoad() { selectionRequestRef.current += 1 @@ -813,7 +844,7 @@ export function PrototypeCanvasHubPanel({ identity, anchorKey, config.prototypeUrl, - config.pickAndPolish, + reviewActive, config.previewUrl, frameRef, onRouteChange, @@ -949,11 +980,12 @@ export function PrototypeCanvasHubPanel({ function toggleComments() { if (selectionBlocked) return - if (commentsOpen) { + if (commentsOpen && reviewActive) { setSelected(null) setCommentsOpen(false) return } + onActivate?.() setCommentsOpen(true) if (open) onClose() } @@ -1097,7 +1129,7 @@ export function PrototypeCanvasHubPanel({ return ( {commentingRecovery.visible ? : null} - {canLoadComments && reviewControlsTarget && !config.pickAndPolish + {canLoadComments && reviewControlsTarget ? createPortal(
void onOpenNotes: () => void onNavigate: (url: string) => void } @@ -41,6 +44,7 @@ export function ImprovementNotesPrototype({ canvas }: Props) { const [discarding, setDiscarding] = useState(false) const [panelOpen, setPanelOpen] = useState(true) const [message, setMessage] = useState("") + const [threadInteraction, setThreadInteraction] = useState(false) const captureGeneration = useRef(0) const annotateRef = useRef(null) const draftRef = useRef(null) @@ -52,6 +56,12 @@ export function ImprovementNotesPrototype({ canvas }: Props) { saved.state?.syncError === "Notes are saved locally until Hub discovers this branch." ? null : saved.state?.syncError + const active = canvas.active !== false + const onInteractionChange = canvas.onInteractionChange + + useLayoutEffect(() => { + onInteractionChange?.(capturingSource || annotating || selection !== null || threadInteraction) + }, [onInteractionChange, capturingSource, annotating, selection, threadInteraction]) const receiveSelection = useCallback( (anchor: ReviewAnchor) => { @@ -75,6 +85,7 @@ export function ImprovementNotesPrototype({ canvas }: Props) { prototypeUrl: canvas.prototypeUrl, previewUrl: canvas.previewUrl, notes, + active, annotating, composing: selection !== null, onSelect: receiveSelection, @@ -88,11 +99,14 @@ export function ImprovementNotesPrototype({ canvas }: Props) { }, [composerOpen]) function openNotes() { + if (canvas.selectionDisabled) return setPanelOpen(true) canvas.onOpenNotes() } async function beginSelection() { + if (canvas.selectionDisabled) return + canvas.onOpenNotes() const generation = ++captureGeneration.current setCapturingSource(true) const source = await saved.capture() @@ -150,7 +164,9 @@ export function ImprovementNotesPrototype({ canvas }: Props) { title={copy.annotate} leadingVisual={} aria-pressed={annotating} - disabled={capturingSource || !preview.ready || !saved.state} + disabled={ + canvas.selectionDisabled || capturingSource || !preview.ready || !saved.state + } onClick={() => { if (annotating) cancelPreviewSelection() else void beginSelection() @@ -163,7 +179,8 @@ export function ImprovementNotesPrototype({ canvas }: Props) { size="small" variant="secondary" aria-label={copy.openNotes(notesCount)} - aria-expanded={panelOpen && !canvas.hubOpen} + aria-expanded={panelOpen && active && !canvas.hubOpen} + disabled={canvas.selectionDisabled} onClick={openNotes} > {notesCount} @@ -175,8 +192,9 @@ export function ImprovementNotesPrototype({ canvas }: Props) { identity={saved.state?.identity ?? ""} controls={false} returnFocusRef={notesToggleRef} - open={panelOpen && !canvas.hubOpen && !selection} - active={(panelOpen || annotating) && !canvas.hubOpen && !selection} + open={panelOpen && active && !canvas.hubOpen && !selection} + active={active && (panelOpen || annotating) && !canvas.hubOpen && !selection} + onInteractionChange={setThreadInteraction} onOpen={openNotes} onClose={() => { setPanelOpen(false) diff --git a/hub/app/javascript/features/prototype-canvas-improvement-notes/use-preview-selection/index.ts b/hub/app/javascript/features/prototype-canvas-improvement-notes/use-preview-selection/index.ts index 9fe5f8d1..34e15da5 100644 --- a/hub/app/javascript/features/prototype-canvas-improvement-notes/use-preview-selection/index.ts +++ b/hub/app/javascript/features/prototype-canvas-improvement-notes/use-preview-selection/index.ts @@ -14,6 +14,7 @@ type Props = { prototypeUrl?: string previewUrl?: string notes: Note[] + active?: boolean annotating: boolean composing: boolean onSelect: (anchor: ReviewAnchor) => void @@ -31,6 +32,7 @@ export function usePreviewSelection({ prototypeUrl, previewUrl, notes, + active = true, annotating, composing, onSelect, @@ -42,10 +44,12 @@ export function usePreviewSelection({ const [connection, setConnection] = useState<{ nonce: string; ready: boolean } | null>(null) const [resolutions, setResolutions] = useState>(new Map()) const anchorKey = JSON.stringify( - notes.filter((note) => note.anchor).map((note) => ({ id: note.id, anchor: note.anchor })), + active + ? notes.filter((note) => note.anchor).map((note) => ({ id: note.id, anchor: note.anchor })) + : [], ) const receiveSelection = useEffectEvent((value: unknown) => { - if (!annotating || composing) return + if (!active || !annotating || composing) return const anchor = REVIEW_ANCHOR_SCHEMA.safeParse(value) if (anchor.success) { onSelect(anchor.data) @@ -74,7 +78,11 @@ export function usePreviewSelection({ const anchors: unknown = JSON.parse(anchorKey) function requestState() { frame?.contentWindow?.postMessage({ type: "replica:canvas:request-ready", nonce }, origin) - frame?.contentWindow?.postMessage({ type: "replica:canvas:resolve", nonce, anchors }, origin) + if (active) + frame?.contentWindow?.postMessage( + { type: "replica:canvas:resolve", nonce, anchors }, + origin, + ) } function loaded() { nonce = crypto.randomUUID() @@ -149,17 +157,19 @@ export function usePreviewSelection({ frame.removeEventListener("load", loaded) window.removeEventListener("message", receive) window.clearInterval(interval) - frame.contentWindow?.postMessage({ type: "replica:canvas:cancel-selection", nonce }, origin) - frame.contentWindow?.postMessage({ type: "replica:canvas:clear-selection", nonce }, origin) + if (active) { + frame.contentWindow?.postMessage({ type: "replica:canvas:cancel-selection", nonce }, origin) + frame.contentWindow?.postMessage({ type: "replica:canvas:clear-selection", nonce }, origin) + } } - }, [anchorKey, frameRef, frameUrl, onCancel, onProblem, onRoute]) + }, [active, anchorKey, frameRef, frameUrl, onCancel, onProblem, onRoute]) useEffect(() => { - if (!connection?.ready) return + if (!active || !connection?.ready) return if (annotating && !composing) send("replica:canvas:select", { mode: "improvement" }) else send("replica:canvas:cancel-selection") if (!composing) send("replica:canvas:clear-selection") - }, [annotating, composing, connection?.ready, send]) + }, [active, annotating, composing, connection?.ready, send]) return { ready: connection?.ready === true, resolutions } } diff --git a/hub/app/javascript/features/prototype-canvas-improvement-threads/index.tsx b/hub/app/javascript/features/prototype-canvas-improvement-threads/index.tsx index 302eb8ba..1dbc538c 100644 --- a/hub/app/javascript/features/prototype-canvas-improvement-threads/index.tsx +++ b/hub/app/javascript/features/prototype-canvas-improvement-threads/index.tsx @@ -54,6 +54,7 @@ export function ImprovementThreads({ onDelete, onFix, onSelect, + onInteractionChange, onRetry, identity, busy = false, @@ -68,6 +69,9 @@ export function ImprovementThreads({ const [submitting, setSubmitting] = useState(false) const [discarding, setDiscarding] = useState(false) const [deleting, setDeleting] = useState(null) + useLayoutEffect(() => { + onInteractionChange?.(selected !== null || deleting !== null) + }, [selected, deleting, onInteractionChange]) const [openedIdentity, setOpenedIdentity] = useState(identity) const [message, setMessage] = useState("") const [filter, setFilter] = useState("active") diff --git a/hub/app/javascript/features/prototype-canvas-improvement-threads/types.ts b/hub/app/javascript/features/prototype-canvas-improvement-threads/types.ts index 2229b6b9..06d56954 100644 --- a/hub/app/javascript/features/prototype-canvas-improvement-threads/types.ts +++ b/hub/app/javascript/features/prototype-canvas-improvement-threads/types.ts @@ -36,6 +36,7 @@ export type ImprovementThreadsProps = { onOpen: () => void onClose: () => void onSelect?: (id: number) => void + onInteractionChange?: (blocked: boolean) => void onFollowUp: (thread: ImprovementThread, body: string) => Promise onResolve: (thread: ImprovementThread) => Promise onDelete: (thread: ImprovementThread) => Promise diff --git a/hub/docs/prototype-canvas.md b/hub/docs/prototype-canvas.md index 0b116d6f..38cfba2e 100644 --- a/hub/docs/prototype-canvas.md +++ b/hub/docs/prototype-canvas.md @@ -4,6 +4,8 @@ The Replica prototype canvas provides **Pick & polish** by default. The updated extension assets and extension-owned preview bridge must be loaded; an older or unavailable bridge leaves selection disabled with an explanation. +Ordinary **Comments** remain available beside **Pick & polish** in the toolbar. Each counter opens its own sidebar and pins without replacing or converting the other collection. Starting either selection mode activates that surface; only that surface resolves pins and receives selections. Finish or cancel a selection, composer, or open conversation before switching surfaces so unsaved work stays intact. Comments retain their existing Hub connection and permission requirements; Pick & polish retains its local storage and synchronization behavior. + The toolbar contains a crosshair button and an adjoining counter-only button for non-resolved notes. Clicking the counter opens the existing sidebar, titled **Pick & polish**. Selection closes the sidebar so the author can click an element or drag a rectangle directly in the live preview. Saved pins remain visible while selection mode is active, even with the sidebar closed; clicking a pin opens only its conversation. Pins still follow the current filter and available route anchors, and hide when neither selection mode nor the sidebar is active. Keyboard activation picks focused elements; Shift+Enter in the preview starts a two-corner region selected with arrow keys and Enter. Escape or an interrupted gesture cancels selection. Rectangle targets require at least eight viewport pixels in each dimension. Primer Brand ActionMenu selects Active notes, Ready to review, or Resolved. **Fix all** sits beside the filter in Active notes, counts open original requests and human follow-ups, and disappears in the other views. Existing publishing, sharing, controls, and Hub connection behavior remain separate. Notes retain validated route, selector or region geometry, viewport, and nearby-element metadata. Selecting a note navigates to its saved path, query, and hash on the same prototype origin. Bridge messages are verified against the extension-owned preview origin; saved routes retain the original prototype address. Pins resolve through the existing bridge on the current screen and reuse ordinary comments' circular avatar presentation. The sidebar covers pins beneath it; clicking a sidebar note still opens its conversation above both layers, anchored to the real target and clamped to the complete canvas viewport. If the target cannot be resolved, the conversation remains available beside the preview with an explicit explanation, not a guessed anchor. Notes do not capture or store screenshots: DOM rasterization cannot reliably reproduce the live preview, and the installed canvas SDK exposes no native screenshot API for extension panels. The composer shows the labeled note field and Save note button, with an X close control in its header; target metadata is stored with the note rather than displayed in the composer. Saving errors and branch-change warnings remain visible, and closing an unsaved draft still requires confirmation.